Feature: Path and FieldMask operations
The utility class Path and PathBuilder from https://github.com/bufbuild/protobuf-es/pull/1092 looks very useful.
But some helper functions for intersect and exclude some paths is missing.
The merge, mergeFromBinary, toBinary could accept the Path and/or FieldMask to include only the selected fields in the operation.
Example intersect:
const allAllowedPath = parsePath('active,locations')
const wantedPath = parsePath('first_name,locations[0]')
const applyPath = intersectPaths(allAllowedPath, wantedPath)
Example exclude:
const excludedPath = parsePath('first_name,last_name')
const wantedPaths = parsePath('first_name,locations[0]')
const applyPath = excludePath(wantedPath, excludedPath)
This is currently the simplest conversion from Path to FieldMask
const path:Path
const updateMask = create(FieldMaskSchema)
for(const m of path) {
updateMask.paths.push(pathToString([m]))
}
FieldMasks have a few additional restrictions. Namely:
A repeated field is not allowed except at the last position of a paths string.
Meaning you cannot specify indices of repeated fields in the paths, or anything after a repeated field.
I only use path to fieldmask for now to get some validation. But still some complient functions to Merge messages and/or validate the update mask would be very helpful.