import 'reflect-metadata'; import { AttributeValue, DynamoDBClient } from '@aws-sdk/client-dynamodb'; import { BaseDto, BaseItem, ListParameters } from '../../job/model/Base/Base'; /** * Generic abstract class for representing repositories interacting with DynamoDB. * @export * @abstract * @class Repository * @template T The entity definition. * @template U The corresponding DB record attributes for the entity. */ export declare abstract class Repository> { protected dynamoDbClient: DynamoDBClient; protected tableName: string; protected pk: string; constructor(dynamoDbClient: DynamoDBClient, tableName: string, pk: string); /** * Save item into database. * @abstract * @param {*} input The item to store. * @returns {Promise} The item stored. * @memberof Repository */ create(input: T): Promise; /** * Get one record from database. * @abstract * @param {string} sk The sort key used to identify the record. * @returns {Promise} The retrieved record. * @memberof Repository */ findOne(sk: SK): Promise; /** * Get list of records from database. * @abstract * @returns {Promise>} The retrieved records. * @memberof Repository */ list(parameters?: ListParameters): Promise>; /** * Update record in database. * @param {string} sk The sort key used to identify the record. * @param {Partial} input The (partial) record to update (properties used in the SK cannot be updated). * @returns {Promise} The updated record. * @memberof Repository */ update(sk: SK, input: Partial>): Promise; /** * Delete record from database. * @abstract * @param {string} sk The sort key used to identify the record. * @returns {void} * @memberof Repository */ delete(sk: T | SK): Promise; batchDelete(sk: Array): Promise<{ unprocessedItems: Array; }>; /** * Convert the DynanomDB attributes of the entity into a DynamoDB item. * @abstract * @param {T} item The DynamoDB item attributes to convert. * @returns {Record} The DynamoDB record. * @memberof Repository */ protected abstract convertToDynamoDbItem(item: T): Record; /** * Convert DynamoDB item to entity. * @abstract * @param {Record} record The record to convert. * @returns {T} The converted entity. * @memberof Repository */ protected abstract convertToItem(record: U): T; /** * Converts a sort key to a string for querying/putting in Dynamo. * @param {SK} sk * @return {string} * @protected */ protected abstract buildSk(sk: T | SK): string; }