UNPKG

dynamodb-toolbox

Version:

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

33 lines (32 loc) 1.99 kB
import type { SchemaAction } from '../../schema/index.js'; import type { ResetLinks } from '../../schema/utils/resetLinks.js'; import type { NarrowObject, Overwrite } from '../../types/index.js'; import type { Light, LightObj } from '../utils/light.js'; import { ItemSchema } from './schema.js'; import type { ItemAttributes, ItemSchemaProps } from './types.js'; type ItemSchemer = <ATTRIBUTES extends ItemAttributes>(attributes: NarrowObject<ATTRIBUTES>) => ItemSchema_<LightObj<ATTRIBUTES>, {}>; /** * Define a new item schema * * @param attributes Dictionary of attributes */ export declare const item: ItemSchemer; export declare class ItemSchema_<ATTRIBUTES extends ItemAttributes = ItemAttributes, PROPS extends ItemSchemaProps = ItemSchemaProps> extends ItemSchema<ATTRIBUTES, PROPS> { /** * Reject additional (undeclared) attributes when parsing input values */ strict<NEXT_STRICT extends boolean = true>(nextStrict?: NEXT_STRICT): ItemSchema_<ATTRIBUTES, Overwrite<PROPS, { strict: NEXT_STRICT; }>>; pick<ATTRIBUTE_NAMES extends (keyof ATTRIBUTES)[]>(...attributeNames: ATTRIBUTE_NAMES): ItemSchema_<{ [KEY in ATTRIBUTE_NAMES[number]]: ResetLinks<ATTRIBUTES[KEY]>; }, PROPS>; omit<ATTRIBUTE_NAMES extends (keyof ATTRIBUTES)[]>(...attributeNames: ATTRIBUTE_NAMES): ItemSchema_<{ [KEY in Exclude<keyof ATTRIBUTES, ATTRIBUTE_NAMES[number]>]: ResetLinks<ATTRIBUTES[KEY]>; }, PROPS>; and<ADDITIONAL_ATTRIBUTES extends ItemAttributes = ItemAttributes>(additionalAttr: NarrowObject<ADDITIONAL_ATTRIBUTES> | ((schema: this) => NarrowObject<ADDITIONAL_ATTRIBUTES>)): ItemSchema_<{ [KEY in keyof ATTRIBUTES | keyof ADDITIONAL_ATTRIBUTES]: KEY extends keyof ADDITIONAL_ATTRIBUTES ? Light<ADDITIONAL_ATTRIBUTES[KEY]> : KEY extends keyof ATTRIBUTES ? ATTRIBUTES[KEY] : never; }, PROPS>; build<ACTION extends SchemaAction<this> = SchemaAction<this>>(Action: new (schema: this) => ACTION): ACTION; } export {};