UNPKG

dynamodb-toolbox

Version:

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

14 lines (13 loc) 648 B
import { z } from 'zod'; import { schemaZodFormatter } from './schema.js'; import { withAttributeNameDecoding } from './utils.js'; export const itemZodFormatter = (schema, options = {}) => { const { format = true } = options; const displayedAttrEntries = format ? Object.entries(schema.attributes).filter(([, { props }]) => !props.hidden) : Object.entries(schema.attributes); return withAttributeNameDecoding(schema, options, z.object(Object.fromEntries(displayedAttrEntries.map(([attributeName, attribute]) => [ attributeName, schemaZodFormatter(attribute, { ...options, defined: false }) ])))); };