/*! * @file ExternalizedDynamoDbRepository.ts * @description This file contains the ExternalizedDynamoDbRepository class, which is used to store and retrieve externalized items from DynamoDB and S3. * @author Dean Heffernan * @copyright 2025 Squiz */ import { AbstractDynamoDbRepository, EntityDefinition, QueryOptions } from '../dynamodb/AbstractDynamoDbRepository'; import { DynamoDbManager, Transaction } from '../dynamodb/DynamoDbManager'; import { S3ExternalStorage, S3StorageLocation } from '../s3/S3ExternalStorage'; /** * The ExternalizedDynamoDbRepository class is used to store and retrieve externalized items from DynamoDB and S3. * @class ExternalizedDynamoDbRepository * @extends {AbstractDynamoDbRepository} * @param {string} tableName - The name of the DynamoDB table to use for storing externalized items. * @param {ContentDynamodbDbManager} dbManager - The DynamoDB database manager to use for storing externalized items. * @param {string} entityName - The name of the entity to store externalized items for. * @param {EntityDefinition} entityDefinition - The entity definition to use for storing externalized items. * @param {DATA_CLASS} classRef - The class to use for storing externalized items. * @param {S3ExternalStorage} storage - The S3 storage to use for storing externalized items. * @returns {ExternalizedDynamoDbRepository} A new instance of the ExternalizedDynamoDbRepository class. */ export declare abstract class ExternalizedDynamoDbRepository extends AbstractDynamoDbRepository { private readonly storage; /** * Creates a new instance of the ExternalizedDynamoDbRepository class. * @constructor * @param {string} tableName - The name of the DynamoDB table to use for storing externalized items. * @param {DynamoDbManager} dbManager - The DynamoDB database manager to use for storing externalized items. * @param {string} entityName - The name of the entity to store externalized items for. * @param {EntityDefinition} entityDefinition - The entity definition to use for storing externalized items. * @param {DATA_CLASS} classRef - The class to use for storing externalized items. * @param {S3ExternalStorage} storage - The S3 storage to use for storing externalized items. * @returns {ExternalizedDynamoDbRepository} A new instance of the ExternalizedDynamoDbRepository class. */ constructor(tableName: string, dbManager: DynamoDbManager, entityName: string, entityDefinition: EntityDefinition, classRef: { new (data?: Record): DATA_CLASS; }, storage: S3ExternalStorage); /** * Removes storageLocation from the response. * storageLocation is an internal S3 storage implementation detail that should never be exposed to API consumers. * @param {DATA_CLASS} item - The item to process. * @returns {DATA_CLASS} The item without storageLocation. */ private removeStorageLocationFromResponse; /** * Creates a new item in the repository. * If the item exceeds DynamoDB's size limit, it will automatically externalize the content to S3. * @param {DATA_CLASS} value - The value to create the item for. * @param {Transaction} transaction - The transaction to use for creating the item. * @param {Partial} additionalValue - Additional value to use for creating the item. * @param {Object} options - The options to use for creating the item. * @returns {Promise} A promise that resolves to the created item. */ createItem(value: DATA_CLASS, transaction?: Transaction, additionalValue?: Partial, options?: { overrideExisting?: boolean; }): Promise; /** * Internal method to create an item in the repository. * @param {DATA_CLASS} value - The value to create the item for. * @param {Transaction} transaction - The transaction to use for creating the item. * @param {Partial} additionalValue - Additional value to use for creating the item. * @param {Object} options - The options to use for creating the item. * @returns {Promise} A promise that resolves to the created item. */ private createItemInternal; /** * Updates an item in the repository. * If the item exceeds DynamoDB's size limit, it will automatically externalize the content to S3. * @param {Partial} value - The value to update the item with. * @returns {Promise} A promise that resolves to the updated item. */ updateItem(value: Partial): Promise; /** * Internal method to update an item in the repository. * @param {Partial} value - The value to update the item with. * @returns {Promise} A promise that resolves to the updated item. */ private updateItemInternal; /** * Gets an item from the repository. * @param {Partial} item - The item to get. * @returns {Promise} A promise that resolves to the item. */ getItem(item: Partial): Promise; /** * Gets items from the repository. * @param {Partial[]} items - The items to get. * @returns {Promise} A promise that resolves to the items. */ getItems(items: Partial[]): Promise; /** * Queries items from the repository. * @param {Partial} item - The item to query. * @param {QueryOptions} options - The options to use for querying the items. * @returns {Promise} A promise that resolves to the items. */ queryItems(item: Partial, options?: QueryOptions): Promise; /** * Deletes an item from the repository. * @param {Partial} partialItem - The item to delete. * @param {Transaction} transaction - The transaction to use for deleting the item. * @returns {Promise} A promise that resolves to the number of items deleted. */ deleteItem(partialItem: Partial, transaction?: Transaction): Promise; /** * Deletes items from the repository. * @param {Partial[]} items - The items to delete. * @returns {Promise} A promise that resolves when the items are deleted. */ deleteItems(items: Partial[]): Promise; /** * Prepares a value for storage by externalizing large content to S3. * @param {DATA_CLASS} value - The value to prepare for storage. * @returns {Promise} A promise that resolves to the prepared value for DynamoDB. * @throws {Error} If S3 storage is not configured or if saving to S3 fails. */ prepareValueForStorage(value: DATA_CLASS): Promise; /** * Extracts only the key field values from an object based on the entity definition. * Large content fields (defined in fieldsAsJsonString) are set to empty values. * All other fields (key fields and small metadata) are preserved. * * @param {Record} obj - The source object to extract key fields from. * @returns {Record} An object containing only the key field values. */ protected getKeyFieldsValues(obj: Record): Record; /** * Override parent's hydrateItem to preserve storageLocation * The parent's hydrateItem creates a new instance which strips storageLocation */ protected hydrateItem(item: Record): DATA_CLASS; /** * Checks if content is actually stored in S3 by examining if large content fields are empty. * When content is externalized to S3, fieldsAsJsonString fields are set to empty objects/arrays. * @param {DATA_CLASS} item - The item to check. * @returns {boolean} True if content is in S3, false if content is in DynamoDB. */ private isContentInS3; /** * Hydrates a record from external storage. * @param {DATA_CLASS} record - The record to hydrate. * @returns {Promise} A promise that resolves to the hydrated record (without storageLocation). */ private hydrateFromExternalStorage; /** * Fetches the stored location of an item. * @param {Partial} partialItem - The item to fetch the stored location for. * @returns {Promise} A promise that resolves to the stored location. */ private fetchStoredLocation; /** * Check if the error is due to DynamoDB item size limit being exceeded. * @param {unknown} error - The error to check. * @returns {boolean} True if the error is due to DynamoDB item size limit being exceeded, false otherwise. */ protected isDynamoItemSizeLimitError(error: unknown): boolean; /** * Check if the message contains the DynamoDB size keyword. * @param {string} message - The message to check. * @returns {boolean} True if the message contains the DynamoDB size keyword, false otherwise. */ private hasDynamoSizeKeyword; } //# sourceMappingURL=ExternalizedDynamoDbRepository.d.ts.map