UNPKG

dynamodb-toolbox

Version:

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

30 lines (29 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anySchemaParser = anySchemaParser; const cloneDeep_js_1 = require("../../../utils/cloneDeep.js"); const utils_js_1 = require("./utils.js"); function* anySchemaParser(schema, inputValue, options = {}) { const { fill = true, transform = true } = options; let linkedValue = undefined; if (fill) { const defaultedValue = (0, cloneDeep_js_1.cloneDeep)(inputValue); yield defaultedValue; linkedValue = defaultedValue; yield linkedValue; } const parsedValue = linkedValue !== null && linkedValue !== void 0 ? linkedValue : (0, cloneDeep_js_1.cloneDeep)(inputValue); if (parsedValue !== undefined) { (0, utils_js_1.applyCustomValidation)(schema, parsedValue, options); } if (transform) { yield parsedValue; } else { return parsedValue; } const transformedValue = schema.props.transform !== undefined ? schema.props.transform.encode(parsedValue) : parsedValue; return transformedValue; }