dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
36 lines (35 loc) • 3.1 kB
TypeScript
import type { DynamoDBDocumentClient, TransactGetCommandInput, TransactGetCommandOutput } from '@aws-sdk/lib-dynamodb';
import type { EntityPaths } from '../../../entity/actions/parsePaths/index.js';
import type { FormattedItem } from '../../../entity/index.js';
import type { CapacityOption } from '../../../options/capacity.js';
import type { DocumentClientOptions } from '../../../types/documentClientOptions.js';
import { $options } from './getTransaction/constants.js';
import { GetTransaction } from './getTransaction/getTransaction.js';
type GetTransactionProps = Pick<GetTransaction, 'entity' | $options | 'params'>;
export interface ExecuteTransactGetOptions extends DocumentClientOptions {
documentClient?: DynamoDBDocumentClient;
capacity?: CapacityOption;
}
export type ExecuteTransactGetInput = GetTransactionProps[] | [ExecuteTransactGetOptions, ...GetTransactionProps[]];
type ExecuteTransactGet = <TRANSACTIONS extends ExecuteTransactGetInput>(..._transactions: TRANSACTIONS) => Promise<ExecuteTransactGetResponses<TRANSACTIONS>>;
export type ExecuteTransactGetResponses<TRANSACTIONS extends ExecuteTransactGetInput> = TRANSACTIONS extends GetTransactionProps[] ? ExecuteTransactGetResponse<TRANSACTIONS> : TRANSACTIONS extends [ExecuteTransactGetOptions, ...infer TRANSACTIONS_TAIL] ? TRANSACTIONS_TAIL extends GetTransactionProps[] ? ExecuteTransactGetResponse<TRANSACTIONS_TAIL> : never : never;
type ExecuteTransactGetResponse<TRANSACTIONS extends GetTransactionProps[]> = Omit<TransactGetCommandOutput, 'Responses'> & {
Responses?: TransactGetResponses<TRANSACTIONS>;
};
type TransactGetResponses<TRANSACTIONS extends GetTransactionProps[], RESPONSES extends unknown[] = []> = TRANSACTIONS extends [infer TRANSACTIONS_HEAD, ...infer TRANSACTIONS_TAIL] ? TRANSACTIONS_HEAD extends GetTransactionProps ? TRANSACTIONS_TAIL extends GetTransactionProps[] ? TransactGetResponses<TRANSACTIONS_TAIL, [
...RESPONSES,
TransactGetResponse<TRANSACTIONS_HEAD>
]> : never : never : number extends TRANSACTIONS['length'] ? [
...RESPONSES,
...(TRANSACTIONS[number] extends infer TRANSACTION ? TRANSACTION extends GetTransactionProps ? TransactGetResponse<TRANSACTION> : never : never)[]
] : RESPONSES extends [] ? (FormattedItem | undefined)[] : RESPONSES;
type TransactGetResponse<TRANSACTION extends GetTransactionProps> = {
Item?: TRANSACTION[$options]['attributes'] extends EntityPaths<TRANSACTION['entity']>[] ? FormattedItem<TRANSACTION['entity'], {
attributes: TRANSACTION[$options]['attributes'][number];
}> : FormattedItem<TRANSACTION['entity']>;
};
type TransactGetResponseFormatter = <TRANSACTIONS extends GetTransactionProps[]>(responses: NonNullable<TransactGetCommandOutput['Responses']>, ...transactions: TRANSACTIONS) => TransactGetResponses<TRANSACTIONS> | undefined;
export declare const formatResponses: TransactGetResponseFormatter;
export declare const execute: ExecuteTransactGet;
export declare const getCommandInput: (transactions: GetTransactionProps[], options?: ExecuteTransactGetOptions) => TransactGetCommandInput;
export {};