UNPKG

@moicky/dynamodb

Version:

Contains a collection of convenience functions for working with AWS DynamoDB

69 lines (68 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unmarshallWithOptions = exports.marshallWithOptions = exports.getDefaultFixes = exports.withFixes = exports.getFixes = exports.initFixes = void 0; const util_dynamodb_1 = require("@aws-sdk/util-dynamodb"); const defaults = Object.freeze({ disableConsistantReadWhenUsingIndexes: { enabled: true, }, }); let fixes = defaults; /** * Initializes the {@link DynamoDBFixes} to use for all operations. * @param fixesConfig - The new {@link DynamoDBFixes} to use * @returns void */ const initFixes = (fixesConfig) => { fixes = fixesConfig; }; exports.initFixes = initFixes; /** * Returns the current {@link DynamoDBFixes} used for all operations. * @returns The current {@link DynamoDBFixes} * @private */ const getFixes = () => fixes; exports.getFixes = getFixes; const handleIndex = (args) => { if (fixes?.disableConsistantReadWhenUsingIndexes?.enabled && args?.IndexName && args?.ConsistentRead && !fixes?.disableConsistantReadWhenUsingIndexes?.stillUseOnLocalIndexes?.includes(args?.IndexName)) { args.ConsistentRead = false; } }; /** * Applies fixes in arguments for Query/Scan operations. * @param args - The arguments to override the default arguments with * @returns The merged arguments * @private */ const withFixes = (args) => { handleIndex(args); return args; }; exports.withFixes = withFixes; /** * Returns the default {@link DynamoDBFixes} used for all operations. * @returns The current {@link DynamoDBFixes} * @private */ const getDefaultFixes = () => defaults; exports.getDefaultFixes = getDefaultFixes; /** * Marshalls the input using {@link marshall} with the global options. * @param input - The input to marshall * @returns The marshalled input * @private */ const marshallWithOptions = (input) => (0, util_dynamodb_1.marshall)(input, fixes.marshallOptions); exports.marshallWithOptions = marshallWithOptions; /** * Unmarshalls the input using {@link unmarshall} with the global options. * @param input - The input to unmarshall * @returns The unmarshalled input * @private */ const unmarshallWithOptions = (input) => (0, util_dynamodb_1.unmarshall)(input, fixes.unmarshallOptions); exports.unmarshallWithOptions = unmarshallWithOptions;