dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
52 lines (51 loc) • 3.9 kB
TypeScript
import type { QueryCommandInput, QueryCommandOutput } from '@aws-sdk/lib-dynamodb';
import type { EntityPaths } from '../../../entity/actions/parsePaths/index.js';
import type { Entity, FormattedItem } 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, $query } from './constants.js';
import type { QueryOptions } from './options.js';
import type { Query } from './types.js';
type ReturnedItems<TABLE extends Table, QUERY extends Query<TABLE>, ENTITIES extends Entity[], OPTIONS extends QueryOptions<TABLE, ENTITIES, QUERY>> = 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 QueryResponse<TABLE extends Table, QUERY extends Query<TABLE>, ENTITIES extends Entity[], OPTIONS extends QueryOptions<TABLE, ENTITIES, QUERY>> = Merge<Omit<QueryCommandOutput, 'Items' | '$metadata'>, {
Items?: ReturnedItems<TABLE, QUERY, ENTITIES, OPTIONS>;
$metadata?: QueryCommandOutput['$metadata'];
}>;
export declare class IQueryCommand<TABLE extends Table = Table, ENTITIES extends Entity[] = Entity[], QUERY extends Query<TABLE> = Query<TABLE>, OPTIONS extends QueryOptions<TABLE, ENTITIES, QUERY> = QueryOptions<TABLE, ENTITIES, QUERY>> extends TableAction<TABLE, ENTITIES> implements TableSendableAction<TABLE> {
static actionName: "query";
[$query]?: QUERY;
[$options]: OPTIONS;
constructor(table: TABLE, entities?: ENTITIES, query?: QUERY, options?: OPTIONS);
[$sentArgs](): [Entity[], Query<TABLE>, QueryOptions<TABLE, Entity[], Query<TABLE>>];
params: () => QueryCommandInput;
send(documentClientOptions?: DocumentClientOptions): Promise<QueryResponse<TABLE, QUERY, ENTITIES, OPTIONS>>;
}
export declare class QueryCommand<TABLE extends Table = Table, ENTITIES extends Entity[] = Entity[], QUERY extends Query<TABLE> = Query<TABLE>, OPTIONS extends QueryOptions<TABLE, ENTITIES, QUERY> = QueryOptions<TABLE, ENTITIES, QUERY>> extends IQueryCommand<TABLE, ENTITIES, QUERY, OPTIONS> {
constructor(table: TABLE, entities?: ENTITIES, query?: QUERY, options?: OPTIONS);
entities<NEXT_ENTITIES extends Entity[]>(...nextEntities: NEXT_ENTITIES): QueryCommand<TABLE, NEXT_ENTITIES, QUERY, OPTIONS extends QueryOptions<TABLE, NEXT_ENTITIES, QUERY> ? OPTIONS : QueryOptions<TABLE, NEXT_ENTITIES, QUERY>>;
query<NEXT_QUERY extends Query<TABLE>>(nextQuery: NEXT_QUERY): QueryCommand<TABLE, ENTITIES, NEXT_QUERY, OPTIONS extends QueryOptions<TABLE, ENTITIES, NEXT_QUERY> ? OPTIONS : QueryOptions<TABLE, ENTITIES, NEXT_QUERY>>;
options<NEXT_OPTIONS extends QueryOptions<TABLE, ENTITIES, QUERY>>(nextOptions: NEXT_OPTIONS | ((prevOptions: OPTIONS) => NEXT_OPTIONS)): QueryCommand<TABLE, ENTITIES, QUERY, NEXT_OPTIONS>;
}
export {};