UNPKG

@nerdware/ddb-single-table

Version:

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

46 lines 2.85 kB
import type { BatchRequestFunction, SomeBatchRequestObject, BatchConfigs } from "./types/index.js"; /** * This DynamoDB batch-requests handler invokes the provided `submitBatchRequest` function with * chunks of `batchRequestObjects` of size `chunkSize`. If the `submitBatchRequest` function * returns any `UnprocessedItems`/`UnprocessedKeys`, or if it results in a retryable error, * the batch request will be retried with any remaining unprocessed request objects using the * exponential-backoff strategy described below, the behavior of which can be customized via the * {@link BatchConfigs|`batchConfigs`} parameter. * * ### **Chunk Size:** * * The `chunkSize` is determined automatically based on whether the `batchRequestObjects` are * `GetRequest` (100) or `WriteRequest` (25), since these are the maximum limits set by AWS for * the `BatchGetItem` and `BatchWriteItem` operations, respectively. If you need to override * this value for any reason, you can do so by providing a `chunkSize` property in the * {@link BatchConfigs|`batchConfigs`} parameter. * * ### **Exponential Backoff Strategy:** * * 1. First request: no delay * 2. Second request: delay `initialDelay` milliseconds (default: 100) * 3. All subsequent request delays are equal to the previous delay multiplied by the * `timeMultiplier` (default: 2), until either: * - The `maxRetries` limit is reached (default: 10), or * - The `maxDelay` limit is reached (default: 3500, or 3.5 seconds) * * Ergo, the base `delay` calculation can be summarized as follows: * > `initialDelay * timeMultiplier^attemptNumber milliseconds` * * If `useJitter` is true (default: false), the `delay` is randomized by applying the following * to the base `delay`: `Math.round(Math.random() * delay)`. Note that the determination as to * whether the delay exceeds the `maxDelay` is made BEFORE the jitter is applied. * * @param submitBatchRequest A function which submits a DDB batch operation, and returns any `UnprocessedItems`/`UnprocessedKeys`. * @param batchRequestObjects The array of request objects to submit via the batch operation. * @param batchConfigs {@link BatchConfigs} for customizing batch-operation handling/behavior. */ export declare const handleBatchRequests: <BatchRequestObj extends SomeBatchRequestObject, BatchFn extends BatchRequestFunction<BatchRequestObj> = BatchRequestFunction<BatchRequestObj>>(submitBatchRequest: BatchFn, batchRequestObjects: Array<BatchRequestObj>, { chunkSize: chunkSizeOverride, retryConfigs }?: BatchConfigs) => Promise<Array<BatchRequestObj> | undefined>; /** * The maximum chunk sizes for DDB batch operations. */ export declare const MAX_CHUNK_SIZE: { readonly GetRequest: 100; readonly WriteRequest: 25; }; //# sourceMappingURL=handleBatchRequests.d.ts.map