UNPKG

dynamodb-toolbox

Version:

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

55 lines (54 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseSetExtension = void 0; const index_js_1 = require("../../../../../schema/actions/parse/index.js"); const index_js_2 = require("../../symbols/index.js"); const parseSetExtension = (schema, input, { transform = true, valuePath } = {}) => { if ((0, index_js_2.isAddition)(input) && input[index_js_2.$ADD] !== undefined) { return { isExtension: true, *extensionParser() { const parser = new index_js_1.Parser(schema).start(input[index_js_2.$ADD], { fill: false, transform, valuePath: [...(valuePath !== null && valuePath !== void 0 ? valuePath : []), '$ADD'] }); const parsedValue = { [index_js_2.$ADD]: parser.next().value }; if (transform) { yield parsedValue; } else { return parsedValue; } const transformedValue = { [index_js_2.$ADD]: parser.next().value }; return transformedValue; } }; } if ((0, index_js_2.isDeletion)(input) && input[index_js_2.$DELETE] !== undefined) { return { isExtension: true, *extensionParser() { const parser = new index_js_1.Parser(schema).start(input[index_js_2.$DELETE], { fill: false, transform, valuePath: [...(valuePath !== null && valuePath !== void 0 ? valuePath : []), '$DELETE'] }); const parsedValue = { [index_js_2.$DELETE]: parser.next().value }; if (transform) { yield parsedValue; } else { return parsedValue; } const transformedValue = { [index_js_2.$DELETE]: parser.next().value }; return transformedValue; } }; } return { isExtension: false, unextendedInput: input }; }; exports.parseSetExtension = parseSetExtension;