UNPKG

dynamodb-toolbox

Version:

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

27 lines (26 loc) 991 B
import { $SET } from '../../../../../entity/actions/update/symbols/index.js'; import { Parser } from '../../../../../schema/actions/parse/index.js'; import { isArray } from '../../../../../utils/validation/isArray.js'; export const parseTupleExtension = (schema, input, { transform = true, valuePath } = {}) => { if (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 }; };