dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
50 lines (49 loc) • 3.27 kB
TypeScript
import type { ScanCommandInput, ScanCommandOutput } from '@aws-sdk/lib-dynamodb';
import type { EntityPaths } from '../../../entity/actions/parsePaths/index.js';
import type { FormattedItem } from '../../../entity/index.js';
import type { Entity } from '../../../entity/index.js';
import type { EntityAttrObjectOptions, EntityAttrOptionValue } from '../../../entity/utils/index.js';
import type { CountSelectOption } from '../../../options/select.js';
import { $sentArgs } from '../../../table/constants.js';
import { TableAction } from '../../../table/index.js';
import type { Table, TableSendableAction } from '../../../table/table.js';
import type { DocumentClientOptions } from '../../../types/documentClientOptions.js';
import type { Merge } from '../../../types/merge.js';
import { $options } from './constants.js';
import type { ScanOptions } from './options.js';
type ReturnedItems<TABLE extends Table, ENTITIES extends Entity[], OPTIONS extends ScanOptions<TABLE, ENTITIES>> = OPTIONS['select'] extends CountSelectOption ? undefined : (Entity[] extends ENTITIES ? FormattedItem : ENTITIES[number] extends infer ENTITY ? ENTITY extends Entity ? [ENTITY, OPTIONS] extends [
{
entityAttribute: true | EntityAttrObjectOptions;
},
{
showEntityAttr: true;
}
] ? Merge<FormattedItem<ENTITY, {
attributes: OPTIONS extends {
attributes: string[];
} ? Extract<OPTIONS['attributes'][number], EntityPaths<ENTITY>> : undefined;
}>, {
[KEY in EntityAttrOptionValue<ENTITY['entityAttribute'], 'name'>]: ENTITY['entityName'];
}> : FormattedItem<ENTITY, {
attributes: OPTIONS extends {
attributes: string[];
} ? Extract<OPTIONS['attributes'][number], EntityPaths<ENTITY>> : undefined;
}> : never : never)[];
export type ScanResponse<TABLE extends Table, ENTITIES extends Entity[], OPTIONS extends ScanOptions<TABLE, ENTITIES>> = Merge<Omit<ScanCommandOutput, 'Items' | '$metadata'>, {
Items?: ReturnedItems<TABLE, ENTITIES, OPTIONS>;
$metadata?: ScanCommandOutput['$metadata'];
}>;
export declare class IScanCommand<TABLE extends Table = Table, ENTITIES extends Entity[] = Entity[], OPTIONS extends ScanOptions<TABLE, ENTITIES> = ScanOptions<TABLE, ENTITIES>> extends TableAction<TABLE, ENTITIES> implements TableSendableAction<TABLE> {
static actionName: "scan";
[$options]: OPTIONS;
constructor(table: TABLE, entities?: ENTITIES, options?: OPTIONS);
[$sentArgs](): [Entity[], ScanOptions<TABLE, Entity[]>];
params(): ScanCommandInput;
send(documentClientOptions?: DocumentClientOptions): Promise<ScanResponse<TABLE, ENTITIES, OPTIONS>>;
}
export declare class ScanCommand<TABLE extends Table = Table, ENTITIES extends Entity[] = Entity[], OPTIONS extends ScanOptions<TABLE, ENTITIES> = ScanOptions<TABLE, ENTITIES>> extends IScanCommand<TABLE, ENTITIES, OPTIONS> {
constructor(table: TABLE, entities?: ENTITIES, options?: OPTIONS);
entities<NEXT_ENTITIES extends Entity[]>(...nextEntities: NEXT_ENTITIES): ScanCommand<TABLE, NEXT_ENTITIES, ScanOptions<TABLE, NEXT_ENTITIES>>;
options<NEXT_OPTIONS extends ScanOptions<TABLE, ENTITIES>>(nextOptions: NEXT_OPTIONS | ((prevOptions: OPTIONS) => NEXT_OPTIONS)): ScanCommand<TABLE, ENTITIES, NEXT_OPTIONS>;
}
export {};