import { StringToAnyObjectMap, SyncOrAsyncIterable, WriteType } from './constants'; import { BatchGetOptions, CreateTableOptions, DataMapperConfiguration, DeleteOptions, DeleteParameters, ExecuteUpdateExpressionOptions, GetOptions, GetParameters, ParallelScanOptions, ParallelScanParameters, ParallelScanWorkerOptions, ParallelScanWorkerParameters, PutOptions, PutParameters, QueryOptions, QueryParameters, ScanOptions, ScanParameters, UpdateOptions, UpdateParameters } from './namedParameters'; import { ParallelScanIterator } from './ParallelScanIterator'; import { QueryIterator } from './QueryIterator'; import { ScanIterator } from './ScanIterator'; import { ZeroArgumentsConstructor } from '@awslabs-community-fork/dynamodb-data-marshaller'; import { ConditionExpression, ConditionExpressionPredicate, UpdateExpression } from '@awslabs-community-fork/dynamodb-expressions'; /** * Object mapper for domain object interaction with DynamoDB. * * To use, define a schema that describes how an item is represented in a * DynamoDB table. This schema will be used to marshall a native JavaScript * object into its desired persisted form. Attributes present on the object * but not in the schema will be ignored. */ export declare class DataMapper { private readonly client; private readonly readConsistency; private readonly skipVersionCheck; private readonly tableNamePrefix; constructor({ client, readConsistency, skipVersionCheck, tableNamePrefix }: DataMapperConfiguration); /** * Deletes items from DynamoDB in batches of 25 or fewer via one or more * BatchWriteItem operations. The items may be from any number of tables; * tables and schemas for each item are determined using the * {DynamoDbSchema} property and the {DynamoDbTable} property on defined on * each item supplied. * * This method will automatically retry any delete requests returned by * DynamoDB as unprocessed. Exponential backoff on unprocessed items is * employed on a per-table basis. * * @param items A synchronous or asynchronous iterable of items to delete. */ batchDelete(items: SyncOrAsyncIterable): AsyncGenerator; /** * Retrieves items from DynamoDB in batches of 100 or fewer via one or more * BatchGetItem operations. The items may be from any number of tables; * tables and schemas for each item are determined using the * {DynamoDbSchema} property and the {DynamoDbTable} property on defined on * each item supplied. * * This method will automatically retry any get requests returned by * DynamoDB as unprocessed. Exponential backoff on unprocessed items is * employed on a per-table basis. * * @param items A synchronous or asynchronous iterable of items to get. */ batchGet(items: SyncOrAsyncIterable, { readConsistency, perTableOptions }?: BatchGetOptions): AsyncGenerator; /** * Puts items into DynamoDB in batches of 25 or fewer via one or more * BatchWriteItem operations. The items may be from any number of tables; * tables and schemas for each item are determined using the * {DynamoDbSchema} property and the {DynamoDbTable} property on defined on * each item supplied. * * This method will automatically retry any put requests returned by * DynamoDB as unprocessed. Exponential backoff on unprocessed items is * employed on a per-table basis. * * @param items A synchronous or asynchronous iterable of items to put. */ batchPut(items: SyncOrAsyncIterable): AsyncGenerator; /** * Puts or deletes items from DynamoDB in batches of 25 or fewer via one or * more BatchWriteItem operations. The items may belong to any number of * tables; tables and schemas for each item are determined using the * {DynamoDbSchema} property and the {DynamoDbTable} property on defined on * each item supplied. * * This method will automatically retry any write requests returned by * DynamoDB as unprocessed. Exponential backoff on unprocessed items is * employed on a per-table basis. * * @param items A synchronous or asynchronous iterable of tuples of the * string 'put'|'delete' and the item on which to perform the specified * write action. */ batchWrite(items: SyncOrAsyncIterable<[WriteType, T]>): AsyncIterableIterator<[WriteType, T]>; /** * Perform a CreateTable operation using the schema accessible via the * {DynamoDbSchema} property and the table name accessible via the * {DynamoDbTable} property on the prototype of the constructor supplied. * * The promise returned by this method will not resolve until the table is * active and ready for use. * * @param valueConstructor The constructor used for values in the table. * @param options Options to configure the CreateTable operation */ createTable(valueConstructor: ZeroArgumentsConstructor, options: CreateTableOptions): Promise; /** * Perform a UpdateTable operation using the schema accessible via the * {DynamoDbSchema} property, the table name accessible via the * {DynamoDbTable} property on the prototype of the constructor supplied, * and the specified global secondary index name. * * The promise returned by this method will not resolve until the table is * active and ready for use. * * @param valueConstructor The constructor used for values in the table. * @param options Options to configure the UpdateTable operation */ createGlobalSecondaryIndex(valueConstructor: ZeroArgumentsConstructor, indexName: string, { indexOptions, }: CreateTableOptions): Promise; /** * If the index does not already exist, perform a UpdateTable operation * using the schema accessible via the {DynamoDbSchema} property, the * table name accessible via the {DynamoDbTable} property on the prototype * of the constructor supplied, and the index name. * * The promise returned by this method will not resolve until the table is * active and ready for use. Note that the index will not be usable for queries * until it has finished backfilling * * @param valueConstructor The constructor used for values in the table. * @param options Options to configure the UpdateTable operation */ ensureGlobalSecondaryIndexExists(valueConstructor: ZeroArgumentsConstructor, indexName: string, options: CreateTableOptions): Promise; /** * Perform a DeleteItem operation using the schema accessible via the * {DynamoDbSchema} property and the table name accessible via the * {DynamoDbTable} property on the item supplied. * * @param item The item to delete * @param options Options to configure the DeleteItem operation */ delete(item: T, options?: DeleteOptions): Promise; /** * @deprecated */ delete(parameters: DeleteParameters): Promise; /** * Perform a DeleteTable operation using the schema accessible via the * {DynamoDbSchema} property and the table name accessible via the * {DynamoDbTable} property on the prototype of the constructor supplied. * * The promise returned by this method will not resolve until the table is * deleted and can no longer be used. * * @param valueConstructor The constructor used for values in the table. */ deleteTable(valueConstructor: ZeroArgumentsConstructor): Promise; /** * If the table does not already exist, perform a CreateTable operation * using the schema accessible via the {DynamoDbSchema} property and the * table name accessible via the {DynamoDbTable} property on the prototype * of the constructor supplied. * * The promise returned by this method will not resolve until the table is * active and ready for use. * * @param valueConstructor The constructor used for values in the table. * @param options Options to configure the CreateTable operation */ ensureTableExists(valueConstructor: ZeroArgumentsConstructor, options: CreateTableOptions): Promise; /** * If the table exists, perform a DeleteTable operation using the schema * accessible via the {DynamoDbSchema} property and the table name * accessible via the {DynamoDbTable} property on the prototype of the * constructor supplied. * * The promise returned by this method will not resolve until the table is * deleted and can no longer be used. * * @param valueConstructor The constructor used for values in the table. */ ensureTableNotExists(valueConstructor: ZeroArgumentsConstructor): Promise; /** * Perform a GetItem operation using the schema accessible via the * {DynamoDbSchema} method and the table name accessible via the * {DynamoDbTable} method on the item supplied. * * @param item The item to get * @param options Options to configure the GetItem operation */ get(item: T, options?: GetOptions): Promise; /** * @deprecated */ get(parameters: GetParameters): Promise; /** * Perform a Scan operation using the schema accessible via the * {DynamoDbSchema} method and the table name accessible via the * {DynamoDbTable} method on the prototype of the constructor supplied. * * This scan will be performed by multiple parallel workers, each of which * will perform a sequential scan of a segment of the table or index. Use * the `segments` parameter to specify the number of workers to be used. * * @param valueConstructor The constructor to be used for each item * returned by the scan * @param segments The number of parallel workers to use to perform * the scan * @param options Options to configure the Scan operation * * @return An asynchronous iterator that yields scan results. Intended * to be consumed with a `for await ... of` loop. */ parallelScan(valueConstructor: ZeroArgumentsConstructor, segments: number, options?: ParallelScanOptions): ParallelScanIterator; /** * @deprecated */ parallelScan(parameters: ParallelScanParameters): ParallelScanIterator; /** * Perform a PutItem operation using the schema accessible via the * {DynamoDbSchema} method and the table name accessible via the * {DynamoDbTable} method on the item supplied. * * @param item The item to save to DynamoDB * @param options Options to configure the PutItem operation */ put(item: T, options?: PutOptions): Promise; /** * @deprecated */ put(parameters: PutParameters): Promise; /** * Perform a Query operation using the schema accessible via the * {DynamoDbSchema} method and the table name accessible via the * {DynamoDbTable} method on the prototype of the constructor supplied. * * @param valueConstructor The constructor to use for each query result. * @param keyCondition A condition identifying a particular hash key * value. * @param options Additional options for customizing the Query * operation * * @return An asynchronous iterator that yields query results. Intended * to be consumed with a `for await ... of` loop. */ query(valueConstructor: ZeroArgumentsConstructor, keyCondition: ConditionExpression | { [propertyName: string]: ConditionExpressionPredicate | any; }, options?: QueryOptions): QueryIterator; /** * @deprecated * * @param parameters Named parameter object */ query(parameters: QueryParameters): QueryIterator; /** * Perform a Scan operation using the schema accessible via the * {DynamoDbSchema} method and the table name accessible via the * {DynamoDbTable} method on the prototype of the constructor supplied. * * @param valueConstructor The constructor to use for each item returned by * the Scan operation. * @param options Additional options for customizing the Scan * operation * * @return An asynchronous iterator that yields scan results. Intended * to be consumed with a `for await ... of` loop. */ scan(valueConstructor: ZeroArgumentsConstructor, options?: ScanOptions | ParallelScanWorkerOptions): ScanIterator; /** * @deprecated */ scan(parameters: ScanParameters | ParallelScanWorkerParameters): ScanIterator; /** * Perform an UpdateItem operation using the schema accessible via the * {DynamoDbSchema} method and the table name accessible via the * {DynamoDbTable} method on the item supplied. * * @param item The item to save to DynamoDB * @param options Options to configure the UpdateItem operation */ update(item: T, options?: UpdateOptions): Promise; /** * @deprecated */ update(parameters: UpdateParameters): Promise; /** * Execute a custom update expression using the schema and table name * defined on the provided `valueConstructor`. * * This method does not support automatic version checking, as the current * state of a table's version attribute cannot be inferred from an update * expression object. To perform a version check manually, add a condition * expression: * * ```typescript * const currentVersion = 1; * updateExpression.set('nameOfVersionAttribute', currentVersion + 1); * const condition = { * type: 'Equals', * subject: 'nameOfVersionAttribute', * object: currentVersion * }; * * const updated = await mapper.executeUpdateExpression( * updateExpression, * itemKey, * constructor, * {condition} * ); * ``` * * **NB:** Property names and attribute paths in the update expression * should reflect the names used in the schema. * * @param expression The update expression to execute. * @param key The full key to identify the object being * updated. * @param valueConstructor The constructor with which to map the result to * a domain object. * @param options Options with which to customize the UpdateItem * request. * * @returns The updated item. */ executeUpdateExpression(expression: UpdateExpression, key: { [propertyName: string]: any; }, valueConstructor: ZeroArgumentsConstructor, options?: ExecuteUpdateExpressionOptions): Promise; private doExecuteUpdateExpression; private getTableName; private mapGetBatch; private mapWriteBatch; }