UNPKG

dynamodb-toolbox

Version:

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

18 lines (17 loc) 810 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.itemZodParser = void 0; const zod_1 = require("zod"); const schema_js_1 = require("./schema.js"); const utils_js_1 = require("./utils.js"); const itemZodParser = (schema, options = {}) => { const { mode = 'put' } = options; const displayedAttrEntries = mode === 'key' ? Object.entries(schema.attributes).filter(([, { props }]) => props.key) : Object.entries(schema.attributes); return (0, utils_js_1.withAttributeNameEncoding)(schema, options, zod_1.z.object(Object.fromEntries(displayedAttrEntries.map(([attributeName, attribute]) => [ attributeName, (0, schema_js_1.schemaZodParser)(attribute, { ...options, defined: false }) ])))); }; exports.itemZodParser = itemZodParser;