UNPKG

dynamodb-toolbox

Version:

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

47 lines (46 loc) 2.62 kB
import type { ItemSchema, ValidValue } from '../schema/index.js'; import type { PrimaryKey } from '../table/actions/parsePrimaryKey/index.js'; import type { Table } from '../table/index.js'; import type { DocumentClientOptions } from '../types/documentClientOptions.js'; import type { If } from '../types/if.js'; import { $interceptor, $sentArgs } from './constants.js'; import type { EntityMetadata } from './types/index.js'; import type { BuildEntitySchema, EntityAttrDefaultOptions, EntityAttrOptions, EntityAttributes, NarrowOptions, NeedsKeyCompute, SchemaOf, TimestampsDefaultOptions, TimestampsOptions } from './utils/index.js'; export declare class Entity<NAME extends string = string, TABLE extends Table = Table, ATTRIBUTES extends EntityAttributes = EntityAttributes, ENTITY_ATTR_OPTIONS extends EntityAttrOptions = string extends NAME ? EntityAttrOptions : EntityAttrDefaultOptions, TIMESTAMPS_OPTIONS extends TimestampsOptions = string extends NAME ? TimestampsOptions : TimestampsDefaultOptions> { readonly type: 'entity'; readonly entityName: NAME; readonly table: TABLE; readonly attributes: ATTRIBUTES; readonly schema: BuildEntitySchema<ATTRIBUTES, TABLE, NAME, ENTITY_ATTR_OPTIONS, TIMESTAMPS_OPTIONS>; readonly entityAttribute: ENTITY_ATTR_OPTIONS; readonly timestamps: TIMESTAMPS_OPTIONS; readonly computeKey?: (keyInput: EntityAttributes extends ATTRIBUTES ? any : ValidValue<ItemSchema<ATTRIBUTES>, { mode: 'key'; }>) => PrimaryKey<TABLE>; [$interceptor]?: (action: EntitySendableAction) => any; meta: EntityMetadata; constructor({ name, table, schema, computeKey, entityAttribute, timestamps, meta }: { name: NAME; table: TABLE; schema: SchemaOf<ATTRIBUTES>; entityAttribute?: NarrowOptions<ENTITY_ATTR_OPTIONS>; timestamps?: NarrowOptions<TIMESTAMPS_OPTIONS>; meta?: EntityMetadata; } & If<NeedsKeyCompute<ATTRIBUTES, TABLE>, { computeKey: (keyInput: ValidValue<ItemSchema<ATTRIBUTES>, { mode: 'key'; }>) => PrimaryKey<TABLE>; }, { computeKey?: undefined; }>); build<ACTION extends EntityAction<this> = EntityAction<this>>(Action: new (entity: this) => ACTION): ACTION; } export declare class EntityAction<ENTITY extends Entity = Entity> { readonly entity: ENTITY; static actionName: string; constructor(entity: ENTITY); } export interface EntitySendableAction<ENTITY extends Entity = Entity> extends EntityAction<ENTITY> { [$sentArgs](): any[]; send(documentClientOptions?: DocumentClientOptions): Promise<any>; }