UNPKG

dynamodb-toolbox

Version:

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

27 lines (26 loc) 923 B
import { cloneDeep } from '../../../utils/cloneDeep.js'; import { applyCustomValidation } from './utils.js'; export function* anySchemaParser(schema, inputValue, options = {}) { const { fill = true, transform = true } = options; let linkedValue = undefined; if (fill) { const defaultedValue = cloneDeep(inputValue); yield defaultedValue; linkedValue = defaultedValue; yield linkedValue; } const parsedValue = linkedValue !== null && linkedValue !== void 0 ? linkedValue : cloneDeep(inputValue); if (parsedValue !== undefined) { 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; }