UNPKG

ddb-table

Version:

Strongly typed library for querying and modeling DynamoDB documents.

47 lines (46 loc) 6.37 kB
import { UpdateExpression as UpdateExpressionStr } from '../DocumentClient'; import ExpressionAttributeNames from './ExpressionAttributeNames'; import ExpressionAttributeValues from './ExpressionAttributeValues'; import UpdateValueExpression from './UpdateValueExpression'; export type AddValue<T> = [T] extends [ Set<any> | number | undefined ] ? T : never; export type DeleteValue<T> = [T] extends [ Set<any> | undefined ] ? T : never; export type SetValue<T, V> = V | ((exp: UpdateValueExpression<T, V>) => string); export default class UpdateExpression<T> { private names; private values; private sets; private removes; private adds; private deletes; constructor(names: ExpressionAttributeNames<T>, values: ExpressionAttributeValues, init?: UpdateExpressionStr); set<K1 extends keyof T>(path: K1 | [K1], value: SetValue<T, T[K1]>): this; set<K1 extends keyof T, K2 extends keyof T[K1]>(path: [K1, K2], value: SetValue<T, T[K1][K2]>): this; set<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(path: [K1, K2, K3], value: SetValue<T, T[K1][K2][K3]>): this; set<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(path: [K1, K2, K3, K4], value: SetValue<T, T[K1][K2][K3][K4]>): this; set<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5], value: SetValue<T, T[K1][K2][K3][K4][K5]>): this; set<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5]>(path: [K1, K2, K3, K4, K5, K6], value: SetValue<T, T[K1][K2][K3][K4][K5][K6]>): this; set<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], K7 extends keyof T[K1][K2][K3][K4][K5][K6]>(path: [K1, K2, K3, K4, K5, K6, K7], value: SetValue<T, T[K1][K2][K3][K4][K5][K6][K7]>): this; set<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], K7 extends keyof T[K1][K2][K3][K4][K5][K6], K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7]>(path: [K1, K2, K3, K4, K5, K6, K7, K8], value: SetValue<T, T[K1][K2][K3][K4][K5][K6][K7][K8]>): this; remove<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], K7 extends keyof T[K1][K2][K3][K4][K5][K6], K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7]>(...path: [K1, K2?, K3?, K4?, K5?, K6?, K7?, K8?, ...(string | number)[]]): this; add<K1 extends keyof T>(path: K1 | [K1], value: AddValue<T[K1]>): this; add<K1 extends keyof T, K2 extends keyof T[K1]>(path: [K1, K2], value: AddValue<T[K1][K2]>): this; add<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(path: [K1, K2, K3], value: AddValue<T[K1][K2][K3]>): this; add<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(path: [K1, K2, K3, K4], value: AddValue<T[K1][K2][K3][K4]>): this; add<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5], value: AddValue<T[K1][K2][K3][K4][K5]>): this; add<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5]>(path: [K1, K2, K3, K4, K5, K6], value: AddValue<T[K1][K2][K3][K4][K5][K6]>): this; add<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], K7 extends keyof T[K1][K2][K3][K4][K5][K6]>(path: [K1, K2, K3, K4, K5, K6, K7], value: AddValue<T[K1][K2][K3][K4][K5][K6][K7]>): this; add<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], K7 extends keyof T[K1][K2][K3][K4][K5][K6], K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7]>(path: [K1, K2, K3, K4, K5, K6, K7, K8], value: AddValue<T[K1][K2][K3][K4][K5][K6][K7][K8]>): this; delete<K1 extends keyof T>(path: K1 | [K1], value: DeleteValue<T[K1]>): this; delete<K1 extends keyof T, K2 extends keyof T[K1]>(path: [K1, K2], value: DeleteValue<T[K1][K2]>): this; delete<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(path: [K1, K2, K3], value: DeleteValue<T[K1][K2][K3]>): this; delete<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(path: [K1, K2, K3, K4], value: DeleteValue<T[K1][K2][K3][K4]>): this; delete<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5], value: DeleteValue<T[K1][K2][K3][K4][K5]>): this; delete<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5]>(path: [K1, K2, K3, K4, K5, K6], value: DeleteValue<T[K1][K2][K3][K4][K5][K6]>): this; delete<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], K7 extends keyof T[K1][K2][K3][K4][K5][K6]>(path: [K1, K2, K3, K4, K5, K6, K7], value: DeleteValue<T[K1][K2][K3][K4][K5][K6][K7]>): this; delete<K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], K5 extends keyof T[K1][K2][K3][K4], K6 extends keyof T[K1][K2][K3][K4][K5], K7 extends keyof T[K1][K2][K3][K4][K5][K6], K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7]>(path: [K1, K2, K3, K4, K5, K6, K7, K8], value: DeleteValue<T[K1][K2][K3][K4][K5][K6][K7][K8]>): this; serialize(): UpdateExpressionStr | undefined; }