dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
28 lines (27 loc) • 2.47 kB
TypeScript
import type { BatchGetCommandInput } from '@aws-sdk/lib-dynamodb';
import type { BatchGetRequest } from '../../../entity/actions/batchGet/index.js';
import type { EntityPathsUnion } from '../../../entity/actions/parsePaths/index.js';
import type { Entity } from '../../../entity/index.js';
import type { Table } from '../../../table/index.js';
import { TableAction } from '../../../table/index.js';
import type { ListOf } from '../../../types/listOf.js';
import { $options, $requests } from './constants.js';
export type IBatchGetRequest = Pick<BatchGetRequest, 'entity' | 'params'>;
export type BatchGetCommandOptions<ENTITIES extends Entity[] = Entity[]> = {
consistent?: boolean;
tableName?: string;
} & ({
attributes?: undefined;
} | {
attributes: Entity[] extends ENTITIES ? string[] : EntityPathsUnion<ENTITIES>[];
});
export type RequestEntities<REQUESTS extends IBatchGetRequest[], RESULTS extends Entity[] = []> = number extends REQUESTS['length'] ? ListOf<REQUESTS[number]> extends IBatchGetRequest[] ? RequestEntities<ListOf<REQUESTS[number]>> : never : REQUESTS extends [infer REQUESTS_HEAD, ...infer REQUESTS_TAIL] ? REQUESTS_HEAD extends IBatchGetRequest ? REQUESTS_TAIL extends IBatchGetRequest[] ? REQUESTS_HEAD['entity']['entityName'] extends RESULTS[number]['entityName'] ? RequestEntities<REQUESTS_TAIL, RESULTS> : RequestEntities<REQUESTS_TAIL, [...RESULTS, REQUESTS_HEAD['entity']]> : never : never : RESULTS;
export declare class BatchGetCommand<TABLE extends Table = Table, ENTITIES extends Entity[] = Entity[], REQUESTS extends IBatchGetRequest[] = IBatchGetRequest[], OPTIONS extends BatchGetCommandOptions<ENTITIES> = BatchGetCommandOptions<ENTITIES>> extends TableAction<TABLE, ENTITIES> {
static actionName: "batchGet";
[$requests]?: REQUESTS;
[$options]: OPTIONS;
constructor(table: TABLE, entities?: ENTITIES, requests?: REQUESTS, options?: OPTIONS);
requests<NEXT_REQUESTS extends IBatchGetRequest[]>(...requests: NEXT_REQUESTS): BatchGetCommand<TABLE, RequestEntities<NEXT_REQUESTS>, NEXT_REQUESTS, OPTIONS extends BatchGetCommandOptions<RequestEntities<NEXT_REQUESTS>> ? OPTIONS : BatchGetCommandOptions<RequestEntities<NEXT_REQUESTS>>>;
options<NEXT_OPTIONS extends BatchGetCommandOptions<ENTITIES>>(nextOptions: NEXT_OPTIONS | ((prevOptions: OPTIONS) => NEXT_OPTIONS)): BatchGetCommand<TABLE, ENTITIES, REQUESTS, NEXT_OPTIONS>;
params(): NonNullable<BatchGetCommandInput['RequestItems']>;
}