UNPKG

@altostra/core

Version:

Core library for shared types and logic

65 lines (64 loc) 2.84 kB
import { DocumentClient } from 'aws-sdk/clients/dynamodb'; import type { NaturalNumber } from "../../../CustomTypes/Numerics"; import type { Logger } from "../../../Logging"; declare type BatchGetResponseMap = DocumentClient.BatchGetResponseMap; declare type MillisecondsDuration = NaturalNumber; export declare type Delay = (retriesCount: NaturalNumber | 0) => MillisecondsDuration; export declare function exponentialDelay(factor?: NaturalNumber): Delay; export interface BatchOperationParams { /** The document-client instance to use */ documentClient?: DocumentClient; /** * An optional function to calculate delays between requests of unprocessed * requests */ nextDelay?: Delay; /** * An optional value that determines how many retries would * be performed if some items cannot be processed */ maxRetriesCount?: NaturalNumber | 0; logger?: Logger; } export interface BatchReadParams extends BatchOperationParams { /** The batch read parameters */ batchRead: DocumentClient.BatchGetItemInput; } /** * Perform a batch get while continuously trying to get unprocessed keys * @returns A promise that is resolved with all the items specified by the batch-read request */ export declare function batchRead({ documentClient, batchRead, nextDelay, maxRetriesCount, logger, }: BatchReadParams): Promise<BatchGetResponseMap>; export interface BatchWriteParams extends BatchOperationParams { /** The batch write parameters */ batchWrite: DocumentClient.BatchWriteItemInput; } /** * Perform a batch write while continuously trying to write unprocessed items * @returns A promise that is resolved when all items have been written to the table */ export declare function batchWrite({ documentClient, batchWrite, nextDelay, maxRetriesCount, logger, }: BatchWriteParams): Promise<void>; export interface QueryAndDeleteParams<QueryKey extends string> extends BatchOperationParams { /** The name of the DynamoDB table to query and delete items from */ tableName: string; /** * A query which is an object containing a single key: the table's PK and an array * of values to match */ query: { [K in QueryKey]: any[]; }; /** An index to use when querying */ indexName?: string; /** The PK name if it is different than the query key */ pk?: string; /** The name of the sort key attribute of the table */ sk?: string; } /** * Perform queries using specified key, values and optional index, then delete the * selected records * @returns A promise that is resolved with the count of deleted records */ export declare function queryAndDelete<QueryKey extends string>({ tableName, query, indexName, pk, sk, documentClient, logger, ...options }: QueryAndDeleteParams<QueryKey>): Promise<number>; export {};