UNPKG

dynamodb-toolbox

Version:

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

19 lines (18 loc) 946 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapZodFormatter = void 0; const zod_1 = require("zod"); const utils_js_1 = require("../utils.js"); const schema_js_1 = require("./schema.js"); const utils_js_2 = require("./utils.js"); const mapZodFormatter = (schema, options = {}) => { const { format = true } = options; const displayedAttrEntries = format ? Object.entries(schema.attributes).filter(([, { props }]) => !props.hidden) : Object.entries(schema.attributes); return (0, utils_js_2.withAttributeNameDecoding)(schema, options, (0, utils_js_2.withOptional)(schema, options, (0, utils_js_1.withValidate)(schema, zod_1.z.object(Object.fromEntries(displayedAttrEntries.map(([attributeName, attribute]) => [ attributeName, (0, schema_js_1.schemaZodFormatter)(attribute, { ...options, defined: false }) ])))))); }; exports.mapZodFormatter = mapZodFormatter;