UNPKG

dynamodb-toolbox

Version:

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

18 lines (17 loc) 822 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.itemZodFormatter = void 0; const zod_1 = require("zod"); const schema_js_1 = require("./schema.js"); const utils_js_1 = require("./utils.js"); const itemZodFormatter = (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_1.withAttributeNameDecoding)(schema, options, zod_1.z.object(Object.fromEntries(displayedAttrEntries.map(([attributeName, attribute]) => [ attributeName, (0, schema_js_1.schemaZodFormatter)(attribute, { ...options, defined: false }) ])))); }; exports.itemZodFormatter = itemZodFormatter;