import { ConverterSet, ConverterType } from '../domain.js'; export const fieldMask: ConverterSet = { types: ['google.protobuf.FieldMask'], [ConverterType.TO_JSON]: { transform: (val: string[]) => val.join(','), /** * This one handles cases where we have a repeated google.protobuf.FieldMask type, * so it will look like: [['foo', 'bar'], ['qux']]. * * The problem is that the serializer detects it as an array with actual fields (strings), * while in practice it is an array of multiple google.protobuf.FieldMask. * * We should determine if the items are actual fields (so each item is a string), * or arrays of google.protobuf.FieldMask (so each item is array that has items with fields). * * Another approach could be marking on the schama itseld each field if it's a repeatable or not, * it's not a good appraoch, but as long as google.protobuf.FieldMask is our only issue, it's * not _that_ bad solution. */ checkRepetable: (val: string[] | string[][]) => { return val.some((v: string | string[]) => Array.isArray(v)); }, }, [ConverterType.FROM_JSON]: { transform: (val: string | { paths: string[] }) => { /** * Support Scala FW JSON mapping bug, for more details see: * * https://github.com/wix-private/server-infra/issues/17953 */ if (typeof val === 'object') { return val.paths; } return val.split(','); }, }, };