UNPKG

dynamodb-toolbox

Version:

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

28 lines (27 loc) 1.08 kB
import { $SET } from '../../../../../entity/actions/update/symbols/index.js'; import { Parser } from '../../../../../schema/actions/parse/index.js'; import { isArray } from '../../../../../utils/validation/isArray.js'; import { isObject } from '../../../../../utils/validation/isObject.js'; export const parseAnyExtension = (schema, input, { transform = true, valuePath } = {}) => { if (isObject(input) || isArray(input)) { return { isExtension: true, *extensionParser() { const parser = new Parser(schema).start(input, { fill: false, transform, valuePath }); 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 }; };