UNPKG

@moicky/dynamodb

Version:

Contains a collection of convenience functions for working with AWS DynamoDB

68 lines (67 loc) 2.86 kB
import { QueryCommandInput, ScanCommandInput } from "@aws-sdk/client-dynamodb"; import { marshall, marshallOptions, unmarshall, unmarshallOptions } from "@aws-sdk/util-dynamodb"; import { DynamoDBItem } from "../types"; /** * DynamoDBFixes is a collection of fixes for DynamoDB. * @property disableConsistantReadWhenUsingIndexes - Disables ConsistentRead when using indexes. * @property marshallOptions - Options to pass to the [marshall](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/interfaces/_aws_sdk_util_dynamodb.marshallOptions.html) function. * @property unmarshallOptions - Options to pass to the [unmarshall](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/interfaces/_aws_sdk_util_dynamodb.unmarshallOptions.html) function. * @example * ```javascript * initFixes({ * disableConsistantReadWhenUsingIndexes: { * enabled: true, // default, * * // Won't disable ConsistantRead if IndexName is specified here. * stillUseOnLocalIndexes: ["localIndexName1", "localIndexName1"], * }, * }); * ``` */ export declare interface DynamoDBFixes { disableConsistantReadWhenUsingIndexes?: { enabled: boolean; stillUseOnLocalIndexes?: string[]; }; marshallOptions?: marshallOptions; unmarshallOptions?: unmarshallOptions; } /** * Initializes the {@link DynamoDBFixes} to use for all operations. * @param fixesConfig - The new {@link DynamoDBFixes} to use * @returns void */ export declare const initFixes: (fixesConfig: DynamoDBFixes) => void; /** * Returns the current {@link DynamoDBFixes} used for all operations. * @returns The current {@link DynamoDBFixes} * @private */ export declare const getFixes: () => DynamoDBFixes; /** * Applies fixes in arguments for Query/Scan operations. * @param args - The arguments to override the default arguments with * @returns The merged arguments * @private */ export declare const withFixes: (args: Partial<QueryCommandInput> | Partial<ScanCommandInput>) => Partial<QueryCommandInput> | Partial<ScanCommandInput>; /** * Returns the default {@link DynamoDBFixes} used for all operations. * @returns The current {@link DynamoDBFixes} * @private */ export declare const getDefaultFixes: () => DynamoDBFixes; /** * Marshalls the input using {@link marshall} with the global options. * @param input - The input to marshall * @returns The marshalled input * @private */ export declare const marshallWithOptions: (input: Parameters<typeof marshall>[0]) => Record<string, import("@aws-sdk/client-dynamodb").AttributeValue>; /** * Unmarshalls the input using {@link unmarshall} with the global options. * @param input - The input to unmarshall * @returns The unmarshalled input * @private */ export declare const unmarshallWithOptions: <T extends DynamoDBItem = DynamoDBItem>(input: Parameters<typeof unmarshall>[0]) => T;