import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb'; import { Transaction, DynamoDbManager } from './DynamoDbManager'; export type QueryFilterTypeBeginsWith = { type: 'begins_with'; keyword: string; }; export type QueryOptions = { useSortKey?: boolean; index?: keyof TableIndexes; limit?: number; order?: 'desc' | 'asc'; filter?: QueryFilterTypeBeginsWith; }; interface Reader { queryItems(partialItem: Partial, options?: QueryOptions): Promise; getItem(id: string | Partial): Promise; getItems(partialItem: Partial[]): Promise; } interface Writer { createItem(item: Partial): Promise; updateItem(partialItem: Partial): Promise; deleteItem(partialItem: Partial): Promise; deleteItems(partialItem: Partial[]): Promise; } type Repository = Reader & Writer; type Repositories = Record>; export type TableKeys = { pk: { attributeName: string; format: string; }; sk: { attributeName: string; format: string; }; }; export type TableIndexes = Record; export type KeysFormat = Record; export type EntityDefinition = { keys: TableKeys; indexes: TableIndexes; fieldsAsJsonString: string[]; optionalIndexes?: (keyof TableIndexes)[]; }; export declare abstract class AbstractDynamoDbRepository implements Reader, Writer { protected tableName: string; protected dbManager: DynamoDbManager; protected entityName: string; protected entityDefinition: EntityDefinition; protected classRef: { new (data?: Record): DATA_CLASS; }; protected client: DynamoDBDocument; protected keys: TableKeys; protected indexes: TableIndexes; protected keysFormat: KeysFormat; protected optionalIndexes: (keyof TableIndexes)[]; protected fieldsAsJsonString: string[]; constructor(tableName: string, dbManager: DynamoDbManager, entityName: string, entityDefinition: EntityDefinition, classRef: { new (data?: Record): DATA_CLASS; }); /** * Get the single item matching the key fields value in the given * partial item. Will throw MissingKeyValuesError if key field values * are missing * * @param item * * @throws MissingKeyValuesError */ getItem(item: Partial): Promise; /** * Get the single item each matching the key fields value in the given * partial items. Will throw MissingKeyValuesError if key field values * are missing * Uses batchGet() to request 100 items in a batch * * @param item * * @throws MissingKeyValuesError */ getItems(items: Partial[]): Promise; /** * Returns the batch items from the items primary key * * @param items * @returns */ private getBatchItems; /** * Delete items in a batch * Uses batchWrite() with 25 items * * @param item * * @throws MissingKeyValuesError */ deleteItems(items: Partial[]): Promise; private deleteBatchItems; private getItemsKeys; /** * Finds all the items matching the partition key or * the gsi key (when gsi index name is specified) * * @param item * @param options * @throws MissingKeyValuesError */ queryItems(item: Partial, options?: QueryOptions): Promise; /** * Evaluate filter condition for sort key * @param filter * @returns string */ private getFilterKeyConditionExpression; /** * Get the list of objects by given params, paginating until all results are returned for a full partition. * @param params - The DynamoDB query params. * @param limit - The maximum number of items to return. * @returns Promise of array of items. */ private queryFullPartition; /** * Update the existing item matching the key fields value * in the passed newValue * @param newValue * @param transaction * * @returns Promise * @throws MissingKeyValuesError */ updateItem(newValue: Partial, transaction?: Transaction): Promise; /** * Adds new item to the table * * @param value * @param transaction * @param additionalValue Additional item properties that are not part of the DATA_CLASS * * @returns Promise * @throws DuplicateItemError * @throws MissingKeyValuesError */ createItem(value: DATA_CLASS, transaction?: Transaction, additionalValue?: Partial, options?: { overrideExisting?: boolean; }): Promise; /** * Deletes an item from the table * * @param partialItem * @param transaction * @returns number * @throw MissingKeyValuesError */ deleteItem(partialItem: Partial, transaction?: Transaction): Promise; /** * Return repo model object from the db value * @param item * @returns */ protected hydrateItem(item: Record): DATA_CLASS; protected convertSelectedValuesToJsonString(item: Record): void; /** * Evaluate the partition key value from the partial item * @param item * @returns string * @throw MissingKeyValuesError */ protected getPk(item: Partial): string; /** * Evaluate the sort key value from the partial item * @param item * @returns string * * @throw MissingKeyValuesError */ protected getSk(item: Partial): string; /** * Evaluate the key value from the * * Example 1: * Input: * - item: {id: foo, name: 'some-name' } * - attributeName: pk * - this.keysFormat = { pk: 'item#{id}', 'sk': '#meta', ... } * Output: * - 'item#foo' * * Example 2: * Input: * - item: {id: foo, name: 'some-name', itemType: 'A' } * - attributeName: sk * - this.keysFormat = { pk: 'item#{id}', 'sk': 'type#{itemType}', ... } * Output: * - 'type#A' * * Example 3: * Input: * - item: {id: foo, name: 'some-name' } * - attributeName: sk * - this.keysFormat = { pk: 'item#{id}', 'sk': 'name-type#{itemType}{name}', ... } * Output: * - Error: "Key field "itemType" must be specified in the input item" * * @param item * @param attributeName * * @returns string * @throw MissingKeyValuesError */ protected getKey(item: Partial, attributeName: keyof KeysFormat): string; /** * Validate the data matches with "DATA_MODEL" * @param value * @return void */ private assertValueMatchesModel; } export {}; //# sourceMappingURL=AbstractDynamoDbRepository.d.ts.map