UNPKG

@moicky/dynamodb

Version:

Contains a collection of convenience functions for working with AWS DynamoDB

49 lines (48 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withDefaults = exports.getDefaultArguments = exports.initDefaultArguments = void 0; let defaultArguments = {}; /** * Initializes the default arguments to use for all operations. * @param args - The new default arguments to use for all operations {@link OperationArguments} * @returns void * @example * Enable consistent reads for all operations which support it: * ```javascript * initDefaultArguments({ * getItem: { ConsistentRead: true }, * getAllItems: { ConsistentRead: true }, * * itemExists: { ConsistentRead: true }, * * query: { ConsistentRead: true }, * queryItems: { ConsistentRead: true }, * queryAllItems: { ConsistentRead: true }, * queryPaginatedItems: { ConsistentRead: true, pageSize: 100 }, * }); * ``` */ const initDefaultArguments = (args) => { defaultArguments = args; }; exports.initDefaultArguments = initDefaultArguments; /** * Returns the current default arguments used for all operations. * @returns The current default arguments {@link OperationArguments} */ const getDefaultArguments = () => defaultArguments; exports.getDefaultArguments = getDefaultArguments; /** * Returns the current default arguments used for all operations. * @param args - The arguments to override the default arguments with * @param operation - The operation to get the default arguments for * @returns The merged arguments * @private */ const withDefaults = (args, operation) => { return { ...defaultArguments[operation], ...args, }; }; exports.withDefaults = withDefaults;