dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
44 lines (43 loc) • 2.23 kB
TypeScript
import type { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import type { Entity } from '../entity/index.js';
import type { DocumentClientOptions } from '../types/documentClientOptions.js';
import type { NarrowObject, NarrowObjectRec } from '../types/narrowObject.js';
import { $entities, $interceptor, $sentArgs } from './constants.js';
import type { Index, Key, TableMetadata } from './types/index.js';
export declare class Table<PARTITION_KEY extends Key = Key, SORT_KEY extends Key = Key, INDEXES extends Record<string, Index> = Key extends PARTITION_KEY ? Record<string, Index> : {}, ENTITY_ATTRIBUTE_SAVED_AS extends string = Key extends PARTITION_KEY ? string : '_et'> {
documentClient?: DynamoDBDocumentClient;
tableName?: string | (() => string);
readonly partitionKey: PARTITION_KEY;
readonly sortKey?: SORT_KEY;
readonly indexes: INDEXES;
readonly entityAttributeSavedAs: ENTITY_ATTRIBUTE_SAVED_AS;
[$interceptor]?: (action: TableSendableAction) => any;
[$entities]: Entity[];
meta: TableMetadata;
constructor({ documentClient,
/**
* @debt v3 "To rename tableName"
*/
name, partitionKey, sortKey, indexes, entityAttributeSavedAs, meta }: {
documentClient?: DynamoDBDocumentClient;
name?: string | (() => string);
partitionKey: NarrowObject<PARTITION_KEY>;
sortKey?: NarrowObject<SORT_KEY>;
indexes?: NarrowObjectRec<INDEXES>;
entityAttributeSavedAs?: ENTITY_ATTRIBUTE_SAVED_AS;
meta?: TableMetadata;
});
getName(): string;
getDocumentClient: () => DynamoDBDocumentClient;
build<ACTION extends TableAction<this, this[$entities]> = TableAction<this, this[$entities]>>(Action: new (table: this, entities?: this[$entities]) => ACTION): ACTION;
}
export declare class TableAction<TABLE extends Table = Table, ENTITIES extends Entity[] = Entity[]> {
readonly table: TABLE;
static actionName: string;
[$entities]: ENTITIES;
constructor(table: TABLE, entities?: ENTITIES);
}
export interface TableSendableAction<TABLE extends Table = Table> extends TableAction<TABLE> {
[$sentArgs](): any[];
send(documentClientOptions?: DocumentClientOptions): Promise<any>;
}