UNPKG

@nerdware/ddb-single-table

Version:

A schema-based DynamoDB modeling tool, high-level API, and type-generator built to supercharge single-table designs!⚡

82 lines 5.12 kB
import { DdbClientWrapper } from "../DdbClientWrapper/index.js"; import { Model } from "../Model/Model.js"; import type { TableConstructorParameters, TableKeysAndIndexes, TableLogFn } from "./types/index.js"; import type { TableKeysSchemaType, ModelSchemaType, ModelSchemaOptions, MergeModelAndTableKeysSchema } from "../Schema/types/index.js"; import type { UnknownItem, ItemCreationParameters, ItemTypeFromSchema } from "../types/index.js"; /** * `Table` provides an easy-to-use API for managing your DynamoDB table and the * {@link Model|Models} that use it. It is the primary entry point for DDBST. */ export declare class Table<const TKSchema extends TableKeysSchemaType> implements TableKeysAndIndexes { static readonly DEFAULT_MARSHALLING_CONFIGS: { readonly marshallOptions: { readonly convertEmptyValues: false; readonly removeUndefinedValues: true; readonly convertClassInstanceToMap: true; readonly convertTopLevelContainer: false; readonly allowImpreciseNumbers: false; }; readonly unmarshallOptions: { readonly wrapNumbers: false; readonly convertWithoutMapWrapper: false; }; }; readonly tableName: TableConstructorParameters<TKSchema>["tableName"]; readonly tableKeysSchema: TKSchema; readonly tableHashKey: TableKeysAndIndexes["tableHashKey"]; readonly tableRangeKey?: TableKeysAndIndexes["tableRangeKey"]; readonly indexes?: TableKeysAndIndexes["indexes"]; /** A wrapper-class around the DynamoDB client instance which greatly simplifies DDB operations. */ readonly ddb: DdbClientWrapper; readonly logger: TableLogFn; isTableActive: boolean; constructor({ tableName, tableKeysSchema, ddbClient, marshallingConfigs, logger, }: TableConstructorParameters<TKSchema>); readonly createTable: <const TableKeysSchema extends TableKeysSchemaType>(this: import("./types/TableInstance.js").TableInstance<TableKeysSchema>, createTableArgs?: import("./types/CreateTableParameters.js").CreateTableParameters) => Promise<import("@aws-sdk/client-dynamodb").CreateTableCommandOutput>; readonly ensureTableIsActive: <const TableKeysSchema extends TableKeysSchemaType>(this: import("./types/TableInstance.js").TableInstance<TableKeysSchema>, { timeout: timeoutSeconds, frequency: frequencySeconds, maxRetries, createIfNotExists, }?: import("./types/EnsureTableIsActiveParameters.js").EnsureTableIsActiveParameters) => Promise<void>; /** A `DescribeTable` wrapper for Table instances which call the method with their `tableName`. */ readonly describeTable: () => Promise<import("@aws-sdk/client-dynamodb").DescribeTableCommandOutput>; /** * Returns a validated ModelSchema with the TableKeysSchema merged in. Use this method to create a * ModelSchema which can be provided to the `ItemTypeFromSchema` generic type-gen util to produce * a complete Model-item type, even if the ModelSchema does not specify the table's keys. */ readonly getModelSchema: <const ModelSchema extends ModelSchemaType<TKSchema>>(modelSchema: ModelSchema) => MergeModelAndTableKeysSchema<TKSchema, ModelSchema>; /** * Returns a new Model instance. This method simply offers a more concise alternative to invoking * the bare Model constructor, i.e., the two examples below are equivalent: * ```ts * // A Table instance for both examples: * const table = new Table({ ... table constructor args ... }); * * // Example 1 using this method: * const fooModel_1 = table.createModel( * "FooModel", * fooModelSchema, * { * // Optional ModelSchemaOptions * allowUnknownAttributes: true * // Using the createModel method, there's no need to provide * // Model properties which are provided by the table, like * // `"tableName"`, `"tableHashKey"`, `"tableRangeKey"`, etc. * } * ); * * // Example 2 does the same as above, only with the bare Model constructor: * const fooModel_2 = new Model( * "FooModel", * fooModelSchema, * { * // Same ModelSchemaOptions as above * allowUnknownAttributes: true, * ...table * // When using the bare Model constructor, table properties like * // `"tableName"`, `"tableHashKey"`, `"tableRangeKey"`, etc., must * // be explicitly provided. An easy way to do this is to simply * // spread a table instance object as shown here. * } * ); * ``` */ readonly createModel: <const ModelSchema extends ModelSchemaType<TKSchema>, const ItemType extends UnknownItem = ItemTypeFromSchema<MergeModelAndTableKeysSchema<TKSchema, ModelSchema>>, const ItemCreationParams extends UnknownItem = ItemCreationParameters<MergeModelAndTableKeysSchema<TKSchema, ModelSchema>>>(modelName: string, modelSchema: ModelSchema, modelSchemaOptions?: ModelSchemaOptions) => Model<MergeModelAndTableKeysSchema<TKSchema, ModelSchema>, ItemType, ItemCreationParams>; } //# sourceMappingURL=Table.d.ts.map