import AWS = require('aws-sdk'); import { TypeShape, Value } from '@punchcard/shape'; import { Compact } from 'typelevel-ts'; import { DSL } from './dsl'; import { Mapper } from './mapper'; export interface BaseClientProps> { /** * Record typr of the table's properties. */ data: T; /** * Key of the Table. */ key: K; /** * DynamoDB Table Name. */ tableName: string; /** * Name of the DynamoDB Index. * * @default - no index */ indexName?: string; /** * Configured AWS DynamoDB Client. * * @default - one using the default environment configuration is created for you. */ client?: AWS.DynamoDB; } export declare class BaseClient, K extends DDB.KeyOf> { readonly client: AWS.DynamoDB; readonly mapper: Mapper; readonly tableName: string; readonly indexName?: string; readonly hashKeyMapper: Mapper>; readonly sortKeyMapper: Mapper>; readonly readKey: (key: AWS.DynamoDB.Key) => DDB.KeyValue; readonly writeKey: (key: DDB.KeyValue) => any; protected readonly dsl: DSL.Root; readonly type: T; readonly key: K; constructor(config: BaseClientProps); scan(): Promise[]>; query(condition: DDB.QueryCondition, props?: DDB.QueryProps): Promise>; } export interface TableClientProps> extends Omit, 'indexName'> { } export declare class TableClient> extends BaseClient { constructor(config: TableClientProps); get(key: DDB.KeyValue): Promise | undefined>; batchGet(keys: DDB.KeyValue[]): Promise[]>; put(item: Value.Of, props?: { if?: DDB.Condition; }): Promise>; /** * Put a batch of records * * @param batch * @returns failed PutRequests */ batchPut(batch: Value.Of[]): Promise; update(key: DDB.KeyValue, props: DDB.Update): Promise>; } export interface IndexClientProps, K extends DDB.KeyOf> extends TableClientProps { /** * Name of the DynamoDB Index. * Required for the IndexClient. */ indexName: string; } /** * Client to Query and Scan a DynamoDB Index. */ export declare class IndexClient> extends BaseClient { constructor(config: IndexClientProps); } export declare namespace DDB { type _QueryOutput, K extends KeyOf> = Compact & { Items?: Value.Of[]; LastEvaluatedKey?: KeyValue; }>; export interface QueryOutput, K extends KeyOf> extends _QueryOutput { } export type HashKey = keyof T; export type SortKey = [keyof T, keyof T]; export interface KeyOf { partition: keyof T['Members']; sort?: keyof T['Members'] | undefined; } export type KeyNames, K extends KeyOf> = K extends { partition: infer PK; sort?: undefined; } ? PK : K extends { partition: infer PK; sort: infer SK; } ? PK | SK : never; export type KeyValue, K extends KeyOf> = { [k in KeyNames]: Value.Of; }; export type HashKeyName = K extends { partition: infer H; } ? H : never; export type HashKeyValue, K extends KeyOf> = Value.Of>; export type HashKeyShape, K extends KeyOf> = T['Members'][HashKeyName]; export type SortKeyName = K extends { sort?: infer S; } ? S : undefined; export type SortKeyValue, K extends KeyOf> = Value.Of>; export type SortKeyShape, K extends KeyOf> = T['Members'][SortKeyName]; export type QueryCondition, K extends KeyOf> = SortKeyName extends undefined ? { [k in HashKeyName]: HashKeyValue; } : { [k in HashKeyName]: HashKeyValue; } & { [k in SortKeyName]?: (i: DSL.Of>) => DSL.Bool; }; export interface QueryProps, K extends KeyOf> { filter?: DDB.Condition; Limit?: number; ExclusiveStartKey?: DDB.KeyValue; ContinuationToken?: string; ScanIndexForward?: boolean; } export type Condition> = (item: DSL.Root) => DSL.Bool; export interface Update> { actions: (item: DSL.Root) => DSL.Action[]; if?: DDB.Condition; } export {}; } //# sourceMappingURL=client.d.ts.map