UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

51 lines (50 loc) 1.91 kB
import { Parser } from '../../../../../schema/actions/parse/index.js'; import { $ADD, $DELETE, isAddition, isDeletion } from '../../symbols/index.js'; export const parseSetExtension = (schema, input, { transform = true, valuePath } = {}) => { if (isAddition(input) && input[$ADD] !== undefined) { return { isExtension: true, *extensionParser() { const parser = new Parser(schema).start(input[$ADD], { fill: false, transform, valuePath: [...(valuePath !== null && valuePath !== void 0 ? valuePath : []), '$ADD'] }); const parsedValue = { [$ADD]: parser.next().value }; if (transform) { yield parsedValue; } else { return parsedValue; } const transformedValue = { [$ADD]: parser.next().value }; return transformedValue; } }; } if (isDeletion(input) && input[$DELETE] !== undefined) { return { isExtension: true, *extensionParser() { const parser = new Parser(schema).start(input[$DELETE], { fill: false, transform, valuePath: [...(valuePath !== null && valuePath !== void 0 ? valuePath : []), '$DELETE'] }); const parsedValue = { [$DELETE]: parser.next().value }; if (transform) { yield parsedValue; } else { return parsedValue; } const transformedValue = { [$DELETE]: parser.next().value }; return transformedValue; } }; } return { isExtension: false, unextendedInput: input }; };