dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
30 lines (29 loc) • 1.09 kB
JavaScript
import { Parser } from '../../../../../schema/actions/parse/index.js';
import { $SET, isSetting } from '../../symbols/index.js';
export const parseMapExtension = (schema, input, { transform = true, valuePath } = {}) => {
if (isSetting(input) && input[$SET] !== undefined) {
return {
isExtension: true,
*extensionParser() {
const parser = new Parser(schema).start(input[$SET], {
fill: false,
transform,
valuePath: [...(valuePath !== null && valuePath !== void 0 ? valuePath : []), '$SET']
});
const parsedValue = { [$SET]: parser.next().value };
if (transform) {
yield parsedValue;
}
else {
return parsedValue;
}
const transformedValue = { [$SET]: parser.next().value };
return transformedValue;
}
};
}
return {
isExtension: false,
unextendedInput: input
};
};