electrodb 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,3 +1,1824 @@
1
- export { Entity } from './src/entity';
2
- export { Service } from './src/service';
3
- export * from './src/types';
1
+ export type DocumentClientMethod = (parameters: any) => {promise: () => Promise<any>};
2
+
3
+ export type DocumentClient = {
4
+ get: DocumentClientMethod;
5
+ put: DocumentClientMethod;
6
+ delete: DocumentClientMethod;
7
+ update: DocumentClientMethod;
8
+ batchWrite: DocumentClientMethod;
9
+ batchGet: DocumentClientMethod;
10
+ scan: DocumentClientMethod;
11
+ transactGet: DocumentClientMethod;
12
+ transactWrite: DocumentClientMethod;
13
+ } | {
14
+ send: (command: any) => Promise<any>;
15
+ }
16
+
17
+ export type AllCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
18
+ [Name in keyof E]:
19
+ E[Name] extends Entity<infer A, infer F, infer C, infer S>
20
+ ? {
21
+ [Collection in keyof EntityCollections<A,F,C,S>]: Collection
22
+ }[keyof EntityCollections<A,F,C,S>]
23
+ : never
24
+ }[keyof E];
25
+
26
+ export type AllEntityAttributeNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
27
+ [Name in keyof E]: {
28
+ [A in keyof E[Name]["schema"]["attributes"]]: A
29
+ }[keyof E[Name]["schema"]["attributes"]]
30
+ }[keyof E];
31
+
32
+ export type AllEntityAttributes<E extends {[name: string]: Entity<any, any, any, any>}> = {
33
+ [Attr in AllEntityAttributeNames<E>]: {
34
+ [Name in keyof E]: Attr extends keyof E[Name]["schema"]["attributes"]
35
+ ? ItemAttribute<E[Name]["schema"]["attributes"][Attr]>
36
+ : never
37
+ }[keyof E];
38
+ };
39
+
40
+ export type CollectionAssociations<E extends {[name: string]: Entity<any, any, any, any>}> = {
41
+ [Collection in AllCollectionNames<E>]: {
42
+ [Name in keyof E]: E[Name] extends Entity<infer A, infer F, infer C, infer S>
43
+ ? Collection extends keyof EntityCollections<A,F,C,S>
44
+ ? Name
45
+ : never
46
+ : never
47
+ }[keyof E];
48
+ }
49
+
50
+ export type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
51
+ [Collection in keyof Collections]: {
52
+ [EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
53
+ ? EntityName extends Collections[Collection]
54
+ ? keyof S["attributes"]
55
+ : never
56
+ : never
57
+ }[keyof E]
58
+ }
59
+
60
+ export interface CollectionWhereOperations {
61
+ eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
62
+ ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
63
+ gt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
64
+ lt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
65
+ gte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
66
+ lte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
67
+ between: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T, value2: T) => string;
68
+ begins: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
69
+ exists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
70
+ notExists: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
71
+ contains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
72
+ notContains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
73
+ value: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
74
+ name: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
75
+ }
76
+
77
+ export type CollectionWhereCallback<E extends {[name: string]: Entity<any, any, any, any>}, I extends Partial<AllEntityAttributes<E>>> =
78
+ <W extends {[A in keyof I]: WhereAttributeSymbol<I[A]>}>(attributes: W, operations: CollectionWhereOperations) => string;
79
+
80
+ export type CollectionWhereClause<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, T> = (where: CollectionWhereCallback<E, I>) => T;
81
+
82
+
83
+ export interface WhereRecordsActionOptions<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, Items, IndexCompositeAttributes> {
84
+ go: GoRecord<Items>;
85
+ params: ParamRecord;
86
+ page: PageRecord<Items,IndexCompositeAttributes>;
87
+ where: CollectionWhereClause<E,A,F,C,S,I, WhereRecordsActionOptions<E,A,F,C,S,I,Items,IndexCompositeAttributes>>;
88
+ }
89
+
90
+ export type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
91
+ [Collection in keyof Collections]: {
92
+ [EntityResultName in Collections[Collection]]:
93
+ EntityResultName extends keyof Entities
94
+ ? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
95
+ ? keyof TableIndexCompositeAttributes<A, F, C, S>
96
+ : never
97
+ : never
98
+ }[Collections[Collection]]
99
+ }
100
+
101
+ export type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
102
+ [Collection in keyof Collections]: {
103
+ [EntityResultName in Collections[Collection]]:
104
+ EntityResultName extends keyof Entities
105
+ ? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
106
+ ? keyof Parameters<Entities[EntityResultName]["query"][
107
+ Collection extends keyof EntityCollections<A,F,C,S>
108
+ ? EntityCollections<A,F,C,S>[Collection]
109
+ : never
110
+ ]>[0]
111
+ : never
112
+ : never
113
+ }[Collections[Collection]]
114
+ }
115
+
116
+ export type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
117
+ [Collection in keyof CollectionIndexKeys<Entities, Collections>]: {
118
+ [key in CollectionIndexKeys<Entities, Collections>[Collection]]:
119
+ key extends keyof AllEntityAttributes<Entities>
120
+ ? AllEntityAttributes<Entities>[key]
121
+ : never
122
+ }
123
+ }
124
+
125
+ export type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
126
+ [Collection in keyof CollectionPageKeys<Entities, Collections>]: {
127
+ [key in CollectionPageKeys<Entities, Collections>[Collection]]:
128
+ key extends keyof AllEntityAttributes<Entities>
129
+ ? AllEntityAttributes<Entities>[key]
130
+ : never
131
+ }
132
+ }
133
+
134
+ export type OptionalPropertyNames<T> =
135
+ { [K in keyof T]: undefined extends T[K] ? K : never }[keyof T];
136
+
137
+ // Common properties from L and R with undefined in R[K] replaced by type in L[K]
138
+ export type SpreadProperties<L, R, K extends keyof L & keyof R> =
139
+ { [P in K]: L[P] | Exclude<R[P], undefined> };
140
+
141
+ export type Id<T> = {[K in keyof T]: T[K]} // see note at bottom*
142
+
143
+ // Type of { ...L, ...R }
144
+ export type Spread<L, R> = Id<
145
+ // Properties in L that don't exist in R
146
+ & Pick<L, Exclude<keyof L, keyof R>>
147
+ // Properties in R with types that exclude undefined
148
+ & Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>>
149
+ // Properties in R, with types that include undefined, that don't exist in L
150
+ & Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>>
151
+ // Properties in R, with types that include undefined, that exist in L
152
+ & SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
153
+ >;
154
+
155
+ export type RequiredProperties<T> = Pick<T, {[K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T]>
156
+
157
+ export type CollectionQueries<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
158
+ [Collection in keyof Collections]: {
159
+ [EntityName in keyof E]:
160
+ EntityName extends Collections[Collection]
161
+ ? (params:
162
+ RequiredProperties<
163
+ Parameters<
164
+ E[EntityName]["query"][
165
+ E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
166
+ ? Collection extends keyof EntityCollections<A,F,C,S>
167
+ ? EntityCollections<A,F,C,S>[Collection]
168
+ : never
169
+ : never
170
+ ]
171
+ >[0]
172
+ >) => {
173
+ go: GoRecord<{
174
+ [EntityResultName in Collections[Collection]]:
175
+ EntityResultName extends keyof E
176
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
177
+ ? ResponseItem<A,F,C,S>[]
178
+ : never
179
+ : never
180
+ }>;
181
+ params: ParamRecord;
182
+ page: {
183
+ [EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
184
+ ? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
185
+ ?
186
+ PageRecord<
187
+ {
188
+ [EntityResultName in Collections[Collection]]:
189
+ EntityResultName extends keyof E
190
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
191
+ ? ResponseItem<A,F,C,S>[]
192
+ : never
193
+ : never
194
+ },
195
+ Partial<
196
+ Spread<
197
+ Collection extends keyof CollectionPageAttributes<E, Collections>
198
+ ? CollectionPageAttributes<E, Collections>[Collection]
199
+ : {},
200
+ Collection extends keyof CollectionIndexAttributes<E, Collections>
201
+ ? CollectionIndexAttributes<E, Collections>[Collection]
202
+ : {}
203
+ >
204
+ >
205
+ >
206
+ : never
207
+ : never
208
+ }[Collections[Collection]];
209
+ where: {
210
+ [EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
211
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
212
+ ? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
213
+ ? CollectionWhereClause<E,A,F,C,S,
214
+ Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
215
+ WhereRecordsActionOptions<E,A,F,C,S,
216
+ Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, CollectionAttributes<E,Collections>[Collection]>>,
217
+ {
218
+ [EntityResultName in Collections[Collection]]:
219
+ EntityResultName extends keyof E
220
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
221
+ ? ResponseItem<A,F,C,S>[]
222
+ : never
223
+ : never
224
+ },
225
+ Partial<
226
+ Spread<
227
+ Collection extends keyof CollectionPageAttributes<E, Collections>
228
+ ? CollectionPageAttributes<E, Collections>[Collection]
229
+ : {},
230
+ Collection extends keyof CollectionIndexAttributes<E, Collections>
231
+ ? CollectionIndexAttributes<E, Collections>[Collection]
232
+ : {}
233
+ >
234
+ >
235
+ >>
236
+ : never
237
+ : never
238
+ : never
239
+ }[Collections[Collection]];
240
+ }
241
+ : never
242
+ }[keyof E];
243
+ }
244
+
245
+ export type ElectroDBMethodTypes = "put" | "get" | "query" | "scan" | "update" | "delete" | "remove" | "patch" | "create" | "batchGet" | "batchWrite";
246
+
247
+ export interface ElectroQueryEvent<P extends any = any> {
248
+ type: 'query';
249
+ method: ElectroDBMethodTypes;
250
+ config: any;
251
+ params: P;
252
+ }
253
+
254
+ export interface ElectroResultsEvent<R extends any = any> {
255
+ type: 'results';
256
+ method: ElectroDBMethodTypes;
257
+ config: any;
258
+ results: R;
259
+ success: boolean;
260
+ }
261
+
262
+ export type ElectroEvent =
263
+ ElectroQueryEvent
264
+ | ElectroResultsEvent;
265
+
266
+ export type ElectroEventType = Pick<ElectroEvent, 'type'>;
267
+
268
+ export type ElectroEventListener = (event: ElectroEvent) => void;
269
+
270
+ // todo: coming soon, more events!
271
+ // | {
272
+ // name: "error";
273
+ // type: "configuration_error" | "invalid_query" | "dynamodb_client";
274
+ // message: string;
275
+ // details: ElectroError;
276
+ // } | {
277
+ // name: "error";
278
+ // type: "user_defined";
279
+ // message: string;
280
+ // details: ElectroValidationError;
281
+ // } | {
282
+ // name: "warn";
283
+ // type: "deprecation_warning" | "optimization_suggestion";
284
+ // message: string;
285
+ // details: any;
286
+ // } | {
287
+ // name: "info";
288
+ // type: "client_updated" | "table_overwritten";
289
+ // message: string;
290
+ // details: any;
291
+ // };
292
+
293
+ export type EntityItem<E extends Entity<any, any, any, any>> =
294
+ E extends Entity<infer A, infer F, infer C, infer S>
295
+ ? ResponseItem<A, F, C, S>
296
+ : never;
297
+
298
+ export type CreateEntityItem<E extends Entity<any, any, any, any>> =
299
+ E extends Entity<infer A, infer F, infer C, infer S>
300
+ ? PutItem<A, F, C, S>
301
+ : never;
302
+
303
+ export type UpdateEntityItem<E extends Entity<any, any, any, any>> =
304
+ E extends Entity<infer A, infer F, infer C, infer S>
305
+ ? Partial<ResponseItem<A,F,C,S>>
306
+ : never;
307
+
308
+ export type UpdateAddEntityItem<E extends Entity<any, any, any, any>> =
309
+ E extends Entity<infer A, infer F, infer C, infer S>
310
+ ? AddItem<A, F, C, S>
311
+ : never;
312
+
313
+ export type UpdateSubtractEntityItem<E extends Entity<any, any, any, any>> =
314
+ E extends Entity<infer A, infer F, infer C, infer S>
315
+ ? SubtractItem<A, F, C, S>
316
+ : never;
317
+
318
+ export type UpdateAppendEntityItem<E extends Entity<any, any, any, any>> =
319
+ E extends Entity<infer A, infer F, infer C, infer S>
320
+ ? AppendItem<A, F, C, S>
321
+ : never;
322
+
323
+ export type UpdateRemoveEntityItem<E extends Entity<any, any, any, any>> =
324
+ E extends Entity<infer A, infer F, infer C, infer S>
325
+ ? RemoveItem<A, F, C, S>
326
+ : never;
327
+
328
+ export type UpdateDeleteEntityItem<E extends Entity<any, any, any, any>> =
329
+ E extends Entity<infer A, infer F, infer C, infer S>
330
+ ? DeleteItem<A, F, C, S>
331
+ : never;
332
+
333
+ export type EntityRecord<E extends Entity<any, any, any, any>> =
334
+ E extends Entity<infer A, infer F, infer C, infer S>
335
+ ? Item<A,F,C,S,S["attributes"]>
336
+ : never;
337
+
338
+ export type CollectionItem<SERVICE extends Service<any>, COLLECTION extends keyof SERVICE["collections"]> =
339
+ SERVICE extends Service<infer E>
340
+ ? Pick<{
341
+ [EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
342
+ ? COLLECTION extends keyof CollectionAssociations<E>
343
+ ? EntityName extends CollectionAssociations<E>[COLLECTION]
344
+ ? ResponseItem<A,F,C,S>[]
345
+ : never
346
+ : never
347
+ : never
348
+ }, COLLECTION extends keyof CollectionAssociations<E>
349
+ ? CollectionAssociations<E>[COLLECTION]
350
+ : never>
351
+ : never
352
+
353
+ export interface QueryBranches<A extends string,
354
+ F extends string, C extends string, S extends Schema<A,F,C>, ResponseItem, IndexCompositeAttributes> {
355
+ go: GoQueryTerminal<A,F,C,S,ResponseItem>;
356
+ params: ParamTerminal<A,F,C,S,ResponseItem>;
357
+ page: PageQueryTerminal<A,F,C,S,ResponseItem,IndexCompositeAttributes>;
358
+ where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,QueryBranches<A,F,C,S,ResponseItem,IndexCompositeAttributes>>
359
+ }
360
+
361
+ export interface RecordsActionOptions<A extends string,
362
+ F extends string, C extends string, S extends Schema<A,F,C>, Items, IndexCompositeAttributes> {
363
+ go: GoRecord<Items>;
364
+ params: ParamRecord;
365
+ page: PageRecord<Items,IndexCompositeAttributes>;
366
+ where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,RecordsActionOptions<A,F,C,S,Items,IndexCompositeAttributes>>;
367
+ }
368
+
369
+ export interface SingleRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
370
+ go: GoGetTerminal<A,F,C,S, ResponseType>;
371
+ params: ParamTerminal<A,F,C,S,ResponseType>;
372
+ where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,SingleRecordOperationOptions<A,F,C,S,ResponseType>>;
373
+ }
374
+
375
+ export interface BatchGetRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
376
+ go: GoBatchGetTerminal<A,F,C,S,ResponseType>
377
+ params: ParamTerminal<A,F,C,S,ResponseType>;
378
+ }
379
+
380
+ export interface PutRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
381
+ go: GoRecord<ResponseType, PutQueryOptions>;
382
+ params: ParamRecord<PutQueryOptions>;
383
+ where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
384
+ }
385
+
386
+ export interface UpdateRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
387
+ go: GoRecord<ResponseType, UpdateQueryOptions>;
388
+ params: ParamRecord<UpdateQueryParams>;
389
+ where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
390
+ }
391
+
392
+ export interface DeleteRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
393
+ go: GoRecord<ResponseType, DeleteQueryOptions>;
394
+ params: ParamRecord<DeleteQueryOptions>;
395
+ where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,DeleteRecordOperationOptions<A,F,C,S,ResponseType>>;
396
+ }
397
+
398
+ export interface BulkRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType, AlternateResponseType> {
399
+ go: BatchGoRecord<ResponseType, AlternateResponseType>;
400
+ params: ParamRecord<BulkOptions>;
401
+ }
402
+
403
+ export interface SetRecordActionOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr,IndexCompositeAttributes,TableItem> {
404
+ go: GoRecord<Partial<TableItem>, UpdateQueryOptions>;
405
+ params: ParamRecord<UpdateQueryParams>;
406
+ set: SetRecord<A,F,C,S, SetItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
407
+ remove: SetRecord<A,F,C,S, Array<keyof SetItem<A,F,C,S>>,IndexCompositeAttributes,TableItem>;
408
+ add: SetRecord<A,F,C,S, AddItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
409
+ subtract: SetRecord<A,F,C,S, SubtractItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
410
+ append: SetRecord<A,F,C,S, AppendItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
411
+ delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
412
+ data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>,IndexCompositeAttributes,TableItem>;
413
+ where: WhereClause<A,F,C,S, Item<A,F,C,S,S["attributes"]>,SetRecordActionOptions<A,F,C,S,SetAttr,IndexCompositeAttributes,TableItem>>;
414
+ }
415
+
416
+ export type SetRecord<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr, IndexCompositeAttributes, TableItem> = (properties: SetAttr) => SetRecordActionOptions<A,F,C,S, SetAttr, IndexCompositeAttributes, TableItem>;
417
+ export type RemoveRecord<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, RemoveAttr, IndexCompositeAttributes, TableItem> = (properties: RemoveAttr) => SetRecordActionOptions<A,F,C,S, RemoveAttr, IndexCompositeAttributes, TableItem>;
418
+
419
+ export type DataUpdateMethodRecord<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr, IndexCompositeAttributes, TableItem> =
420
+ DataUpdateMethod<A,F,C,S, UpdateData<A,F,C,S>, SetRecordActionOptions<A,F,C,S, SetAttr, IndexCompositeAttributes, TableItem>>
421
+
422
+ interface QueryOperations<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, CompositeAttributes, ResponseItem, IndexCompositeAttributes> {
423
+ between: (skCompositeAttributesStart: CompositeAttributes, skCompositeAttributesEnd: CompositeAttributes) => QueryBranches<A,F,C,S, ResponseItem, IndexCompositeAttributes>;
424
+ gt: (skCompositeAttributes: CompositeAttributes) => QueryBranches<A,F,C,S, ResponseItem,IndexCompositeAttributes>;
425
+ gte: (skCompositeAttributes: CompositeAttributes) => QueryBranches<A,F,C,S, ResponseItem,IndexCompositeAttributes>;
426
+ lt: (skCompositeAttributes: CompositeAttributes) => QueryBranches<A,F,C,S, ResponseItem,IndexCompositeAttributes>;
427
+ lte: (skCompositeAttributes: CompositeAttributes) => QueryBranches<A,F,C,S, ResponseItem,IndexCompositeAttributes>;
428
+ begins: (skCompositeAttributes: CompositeAttributes) => QueryBranches<A,F,C,S, ResponseItem,IndexCompositeAttributes>;
429
+ go: GoQueryTerminal<A,F,C,S,ResponseItem>;
430
+ params: ParamTerminal<A,F,C,S,ResponseItem>;
431
+ page: PageQueryTerminal<A,F,C,S,ResponseItem,IndexCompositeAttributes>;
432
+ where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,QueryBranches<A,F,C,S,ResponseItem,IndexCompositeAttributes>>
433
+ }
434
+
435
+ export type Queries<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
436
+ [I in keyof S["indexes"]]: <CompositeAttributes extends IndexCompositeAttributes<A,F,C,S,I>>(composite: CompositeAttributes) =>
437
+ IndexSKAttributes<A,F,C,S,I> extends infer SK
438
+ // If there is no SK, dont show query operations (when an empty array is provided)
439
+ ? [keyof SK] extends [never]
440
+ ? QueryBranches<A,F,C,S, ResponseItem<A,F,C,S>, AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes>>
441
+ // If there is no SK, dont show query operations (When no PK is specified)
442
+ : S["indexes"][I] extends IndexWithSortKey
443
+ ? QueryOperations<
444
+ A,F,C,S,
445
+ // Omit the composite attributes already provided
446
+ Omit<Partial<IndexSKAttributes<A,F,C,S,I>>, keyof CompositeAttributes>,
447
+ ResponseItem<A,F,C,S>,
448
+ AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK
449
+ >
450
+ : QueryBranches<A,F,C,S, ResponseItem<A,F,C,S>, AllTableIndexCompositeAttributes<A,F,C,S> & Required<CompositeAttributes> & SK>
451
+ : never
452
+ }
453
+
454
+ export type ParseSingleInput = {
455
+ Item?: {[key: string]: any}
456
+ } | {
457
+ Attributes?: {[key: string]: any}
458
+ } | null;
459
+
460
+ export type ParseMultiInput = {
461
+ Items?: {[key: string]: any}[]
462
+ }
463
+
464
+ export type ReturnValues = "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
465
+
466
+ export interface QueryOptions {
467
+ raw?: boolean;
468
+ table?: string;
469
+ limit?: number;
470
+ params?: object;
471
+ includeKeys?: boolean;
472
+ originalErr?: boolean;
473
+ ignoreOwnership?: boolean;
474
+ pages?: number;
475
+ listeners?: Array<ElectroEventListener>;
476
+ logger?: ElectroEventListener;
477
+ }
478
+
479
+ // subset of QueryOptions
480
+ export interface ParseOptions<Attributes> {
481
+ attributes?: ReadonlyArray<Attributes>;
482
+ ignoreOwnership?: boolean;
483
+ }
484
+
485
+ export interface UpdateQueryOptions extends QueryOptions {
486
+ response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
487
+ }
488
+
489
+ export interface UpdateQueryParams {
490
+ response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
491
+ table?: string;
492
+ params?: object;
493
+ originalErr?: boolean;
494
+ }
495
+
496
+ export interface DeleteQueryOptions extends QueryOptions {
497
+ response?: "default" | "none" | 'all_old';
498
+ }
499
+
500
+ export interface PutQueryOptions extends QueryOptions {
501
+ response?: "default" | "none" | 'all_old';
502
+ }
503
+
504
+ export interface ParamOptions {
505
+ params?: object;
506
+ table?: string;
507
+ limit?: number;
508
+ response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
509
+ }
510
+
511
+ export interface PaginationOptions extends QueryOptions {
512
+ pager?: "raw" | "item" | "named";
513
+ limit?: number;
514
+ }
515
+
516
+ export interface BulkOptions extends QueryOptions {
517
+ unprocessed?: "raw" | "item";
518
+ concurrency?: number;
519
+ preserveBatchOrder?: boolean;
520
+ }
521
+
522
+ export type OptionalDefaultEntityIdentifiers = {
523
+ __edb_e__?: string;
524
+ __edb_v__?: string;
525
+ }
526
+
527
+ interface GoBatchGetTerminalOptions<Attributes> {
528
+ raw?: boolean;
529
+ table?: string;
530
+ limit?: number;
531
+ params?: object;
532
+ includeKeys?: boolean;
533
+ originalErr?: boolean;
534
+ ignoreOwnership?: boolean;
535
+ pages?: number;
536
+ attributes?: ReadonlyArray<Attributes>;
537
+ unprocessed?: "raw" | "item";
538
+ concurrency?: number;
539
+ preserveBatchOrder?: boolean;
540
+ listeners?: Array<ElectroEventListener>;
541
+ logger?: ElectroEventListener;
542
+ }
543
+
544
+ interface GoQueryTerminalOptions<Attributes> {
545
+ raw?: boolean;
546
+ table?: string;
547
+ limit?: number;
548
+ params?: object;
549
+ includeKeys?: boolean;
550
+ originalErr?: boolean;
551
+ ignoreOwnership?: boolean;
552
+ pages?: number;
553
+ attributes?: ReadonlyArray<Attributes>;
554
+ listeners?: Array<ElectroEventListener>;
555
+ logger?: ElectroEventListener;
556
+ }
557
+
558
+ interface PageQueryTerminalOptions<Attributes> extends GoQueryTerminalOptions<Attributes> {
559
+ pager?: "raw" | "item" | "named";
560
+ raw?: boolean;
561
+ table?: string;
562
+ limit?: number;
563
+ includeKeys?: boolean;
564
+ originalErr?: boolean;
565
+ ignoreOwnership?: boolean;
566
+ attributes?: ReadonlyArray<Attributes>;
567
+ listeners?: Array<ElectroEventListener>;
568
+ logger?: ElectroEventListener;
569
+ }
570
+
571
+ export interface ParamTerminalOptions<Attributes> {
572
+ table?: string;
573
+ limit?: number;
574
+ params?: object;
575
+ originalErr?: boolean;
576
+ attributes?: ReadonlyArray<Attributes>;
577
+ response?: "default" | "none" | 'all_old' | 'updated_old' | 'all_new' | 'updated_new';
578
+ }
579
+
580
+ type GoBatchGetTerminal<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseItem> = <Options extends GoBatchGetTerminalOptions<keyof ResponseItem>>(options?: Options) =>
581
+ Options extends GoBatchGetTerminalOptions<infer Attr>
582
+ ? 'preserveBatchOrder' extends keyof Options
583
+ ? Options['preserveBatchOrder'] extends true
584
+ ? Promise<[
585
+ Array<Resolve<{
586
+ [
587
+ Name in keyof ResponseItem as Name extends Attr
588
+ ? Name
589
+ : never
590
+ ]: ResponseItem[Name]
591
+ } | null>>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>
592
+ ]>
593
+ : Promise<[
594
+ Array<Resolve<{
595
+ [
596
+ Name in keyof ResponseItem as Name extends Attr
597
+ ? Name
598
+ : never
599
+ ]: ResponseItem[Name]
600
+ }>>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>
601
+ ]>
602
+ : Promise<[
603
+ Array<Resolve<{
604
+ [
605
+ Name in keyof ResponseItem as Name extends Attr
606
+ ? Name
607
+ : never
608
+ ]: ResponseItem[Name]
609
+ }>>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>
610
+ ]>
611
+ : 'preserveBatchOrder' extends keyof Options
612
+ ? Options['preserveBatchOrder'] extends true
613
+ ? [Array<Resolve<ResponseItem | null>>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>]
614
+ : [Array<Resolve<ResponseItem>>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>]
615
+ : [Array<Resolve<ResponseItem>>, Array<Resolve<AllTableIndexCompositeAttributes<A,F,C,S>>>]
616
+
617
+ type GoGetTerminal<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseItem> = <Options extends GoQueryTerminalOptions<keyof ResponseItem>>(options?: Options) =>
618
+ Options extends GoQueryTerminalOptions<infer Attr>
619
+ ? Promise<{
620
+ [
621
+ Name in keyof ResponseItem as Name extends Attr
622
+ ? Name
623
+ : never
624
+ ]: ResponseItem[Name]
625
+ } | null>
626
+ : Promise<ResponseItem | null>
627
+
628
+ export type GoQueryTerminal<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, Item> = <Options extends GoQueryTerminalOptions<keyof Item>>(options?: Options) =>
629
+ Options extends GoQueryTerminalOptions<infer Attr>
630
+ ? Promise<Array<{
631
+ [
632
+ Name in keyof Item as Name extends Attr
633
+ ? Name
634
+ : never
635
+ ]: Item[Name]
636
+ }>>
637
+ : Promise<Array<Item>>
638
+
639
+ export type EntityParseSingleItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseItem> =
640
+ <Options extends ParseOptions<keyof ResponseItem>>(item: ParseSingleInput, options?: Options) =>
641
+ Options extends ParseOptions<infer Attr>
642
+ ? {
643
+ [
644
+ Name in keyof ResponseItem as Name extends Attr
645
+ ? Name
646
+ : never
647
+ ]: ResponseItem[Name]
648
+ } | null
649
+ : ResponseItem | null
650
+
651
+ export type EntityParseMultipleItems<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseItem> =
652
+ <Options extends ParseOptions<keyof ResponseItem>>(item: ParseMultiInput, options?: Options) =>
653
+ Options extends ParseOptions<infer Attr>
654
+ ? Array<{
655
+ [
656
+ Name in keyof ResponseItem as Name extends Attr
657
+ ? Name
658
+ : never
659
+ ]: ResponseItem[Name]
660
+ }>
661
+ : Array<ResponseItem>
662
+
663
+
664
+ export type PageQueryTerminal<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, Item, CompositeAttributes> = <Options extends PageQueryTerminalOptions<keyof Item>>(page?: (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null, options?: Options) =>
665
+ Options extends GoQueryTerminalOptions<infer Attr>
666
+ ? Promise<[
667
+ (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null,
668
+ Array<{
669
+ [
670
+ Name in keyof Item as Name extends Attr
671
+ ? Name
672
+ : never
673
+ ]: Item[Name]
674
+ }>
675
+ ]>
676
+ : Promise<[
677
+ (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null,
678
+ Array<ResponseType>
679
+ ]>;
680
+
681
+ export type ParamTerminal<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseItem> = <P extends any = any, Options extends ParamTerminalOptions<keyof ResponseItem> = ParamTerminalOptions<keyof ResponseItem>>(options?: Options) => P;
682
+
683
+ export type GoRecord<ResponseType, Options = QueryOptions> = <T = ResponseType>(options?: Options) => Promise<T>;
684
+
685
+ export type BatchGoRecord<ResponseType, AlternateResponseType> = <O extends BulkOptions>(options?: O) =>
686
+ O extends infer Options
687
+ ? 'preserveBatchOrder' extends keyof Options
688
+ ? Options['preserveBatchOrder'] extends true
689
+ ? Promise<AlternateResponseType>
690
+ : Promise<ResponseType>
691
+ : Promise<ResponseType>
692
+ : never
693
+
694
+ export type PageRecord<ResponseType, CompositeAttributes> = (page?: (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null, options?: PaginationOptions) => Promise<[
695
+ (CompositeAttributes & OptionalDefaultEntityIdentifiers) | null,
696
+ ResponseType
697
+ ]>;
698
+
699
+ export type ParamRecord<Options = ParamOptions> = <P>(options?: Options) => P;
700
+
701
+ export interface ElectroError extends Error {
702
+ readonly name: 'ElectroError';
703
+ readonly code: number;
704
+ readonly date: number;
705
+ readonly isElectroError: boolean;
706
+ ref: {
707
+ readonly code: number;
708
+ readonly section: string;
709
+ readonly name: string;
710
+ readonly sym: unique symbol;
711
+ }
712
+ }
713
+
714
+ export interface ElectroValidationErrorFieldReference<T extends Error = Error> {
715
+ /**
716
+ * The json path to the attribute that had a validation error
717
+ */
718
+ readonly field: string;
719
+
720
+ /**
721
+ * A description of the validation error for that attribute
722
+ */
723
+ readonly reason: string;
724
+
725
+ /**
726
+ * Index of the value passed (present only in List attribute validation errors)
727
+ */
728
+ readonly index: number | undefined;
729
+
730
+ /**
731
+ * The error thrown from the attribute's validate callback (if applicable)
732
+ */
733
+ readonly cause: T | undefined;
734
+ }
735
+
736
+ export interface ElectroValidationError<T extends Error = Error> extends ElectroError {
737
+ readonly fields: ReadonlyArray<ElectroValidationErrorFieldReference<T>>;
738
+ }
739
+
740
+ export interface ReadOnlyAttribute {
741
+ readonly readOnly: true;
742
+ }
743
+
744
+ export interface RequiredAttribute {
745
+ required: true;
746
+ }
747
+
748
+ export interface HiddenAttribute {
749
+ readonly hidden: true;
750
+ }
751
+
752
+ export interface DefaultedAttribute {
753
+ readonly default: any;
754
+ }
755
+
756
+ export interface SecondaryIndex {
757
+ readonly index: string;
758
+ }
759
+
760
+ export interface NestedBooleanAttribute {
761
+ readonly type: "boolean";
762
+ readonly required?: boolean;
763
+ readonly hidden?: boolean;
764
+ readonly readOnly?: boolean;
765
+ readonly get?: (val: boolean, item: any) => boolean | undefined | void;
766
+ readonly set?: (val?: boolean, item?: any) => boolean | undefined | void;
767
+ readonly default?: boolean | (() => boolean);
768
+ readonly validate?: ((val: boolean) => boolean) | ((val: boolean) => void) | ((val: boolean) => string | void);
769
+ readonly field?: string;
770
+ }
771
+
772
+ export interface BooleanAttribute {
773
+ readonly type: "boolean";
774
+ readonly required?: boolean;
775
+ readonly hidden?: boolean;
776
+ readonly readOnly?: boolean;
777
+ readonly get?: (val: boolean, item: any) => boolean | undefined | void;
778
+ readonly set?: (val?: boolean, item?: any) => boolean | undefined | void;
779
+ readonly default?: boolean | (() => boolean);
780
+ readonly validate?: ((val: boolean) => boolean) | ((val: boolean) => void) | ((val: boolean) => string | void);
781
+ readonly field?: string;
782
+ readonly label?: string;
783
+ readonly watch?: ReadonlyArray<string> | "*";
784
+ }
785
+
786
+ export interface NestedNumberAttribute {
787
+ readonly type: "number";
788
+ readonly required?: boolean;
789
+ readonly hidden?: boolean;
790
+ readonly readOnly?: boolean;
791
+ readonly get?: (val: number, item: any) => number | undefined | void;
792
+ readonly set?: (val?: number, item?: any) => number | undefined | void;
793
+ readonly default?: number | (() => number);
794
+ readonly validate?: ((val: number) => boolean) | ((val: number) => void) | ((val: number) => string | void);
795
+ readonly field?: string;
796
+ }
797
+
798
+ export interface NumberAttribute {
799
+ readonly type: "number";
800
+ readonly required?: boolean;
801
+ readonly hidden?: boolean;
802
+ readonly readOnly?: boolean;
803
+ readonly get?: (val: number, item: any) => number | undefined | void;
804
+ readonly set?: (val?: number, item?: any) => number | undefined | void;
805
+ readonly default?: number | (() => number);
806
+ readonly validate?: ((val: number) => boolean) | ((val: number) => void) | ((val: number) => string | void);
807
+ readonly field?: string;
808
+ readonly label?: string;
809
+ readonly watch?: ReadonlyArray<string> | "*";
810
+ }
811
+
812
+ export interface NestedStringAttribute {
813
+ readonly type: "string";
814
+ readonly required?: boolean;
815
+ readonly hidden?: boolean;
816
+ readonly readOnly?: boolean;
817
+ readonly get?: (val: string, item: any) => string | undefined | void;
818
+ readonly set?: (val?: string, item?: any) => string | undefined | void;
819
+ readonly default?: string | (() => string);
820
+ readonly validate?: ((val: string) => boolean) | ((val: string) => void) | ((val: string) => string | void) | RegExp;
821
+ readonly field?: string;
822
+ }
823
+
824
+ export interface StringAttribute {
825
+ readonly type: "string";
826
+ readonly required?: boolean;
827
+ readonly hidden?: boolean;
828
+ readonly readOnly?: boolean;
829
+ readonly get?: (val: string, item: any) => string | undefined | void;
830
+ readonly set?: (val?: string, item?: any) => string | undefined | void;
831
+ readonly default?: string | (() => string);
832
+ readonly validate?: ((val: string) => boolean) | ((val: string) => void) | ((val: string) => string | void) | RegExp;
833
+ readonly field?: string;
834
+ readonly label?: string;
835
+ readonly watch?: ReadonlyArray<string> | "*";
836
+ }
837
+
838
+ export interface NestedEnumAttribute {
839
+ readonly type: ReadonlyArray<string>;
840
+ readonly required?: boolean;
841
+ readonly hidden?: boolean;
842
+ readonly readOnly?: boolean;
843
+ readonly get?: (val: any, item: any) => any | undefined | void;
844
+ readonly set?: (val?: any, item?: any) => any | undefined | void;
845
+ readonly default?: string | (() => string);
846
+ readonly validate?: ((val: any) => boolean) | ((val: any) => void) | ((val: any) => string | void);
847
+ readonly field?: string;
848
+ readonly label?: string;
849
+ }
850
+
851
+
852
+ export interface EnumAttribute {
853
+ readonly type: ReadonlyArray<string>;
854
+ readonly required?: boolean;
855
+ readonly hidden?: boolean;
856
+ readonly readOnly?: boolean;
857
+ readonly get?: (val: any, item: any) => any | undefined | void;
858
+ readonly set?: (val?: any, item?: any) => any | undefined | void;
859
+ readonly default?: string | (() => string);
860
+ readonly validate?: ((val: any) => boolean) | ((val: any) => void) | ((val: any) => string | void);
861
+ readonly field?: string;
862
+ readonly label?: string;
863
+ readonly watch?: ReadonlyArray<string> | "*";
864
+ }
865
+
866
+ export interface NestedAnyAttribute {
867
+ readonly type: "any";
868
+ readonly required?: boolean;
869
+ readonly hidden?: boolean;
870
+ readonly readOnly?: boolean;
871
+ readonly get?: (val: any, item: any) => any | undefined | void;
872
+ readonly set?: (val?: any, item?: any) => any | undefined | void;
873
+ readonly default?: any | (() => any);
874
+ readonly validate?: ((val: any) => boolean) | ((val: any) => void) | ((val: any) => string | void);
875
+ readonly field?: string;
876
+ }
877
+
878
+ export interface AnyAttribute {
879
+ readonly type: "any";
880
+ readonly required?: boolean;
881
+ readonly hidden?: boolean;
882
+ readonly readOnly?: boolean;
883
+ readonly get?: (val: any, item: any) => any | undefined | void;
884
+ readonly set?: (val?: any, item?: any) => any | undefined | void;
885
+ readonly default?: any | (() => any);
886
+ readonly validate?: ((val: any) => boolean) | ((val: any) => void) | ((val: any) => string | void);
887
+ readonly field?: string;
888
+ readonly label?: string;
889
+ readonly watch?: ReadonlyArray<string> | "*";
890
+ }
891
+
892
+ export interface NestedMapAttribute {
893
+ readonly type: "map";
894
+ readonly properties: {
895
+ readonly [name: string]: NestedAttributes;
896
+ };
897
+ readonly required?: boolean;
898
+ readonly hidden?: boolean;
899
+ readonly readOnly?: boolean;
900
+ readonly get?: (val: Record<string, any>, item: any) => Record<string, any> | undefined | void;
901
+ readonly set?: (val?: Record<string, any>, item?: any) => Record<string, any> | undefined | void;
902
+ readonly default?: Record<string, any> | (() => Record<string, any>);
903
+ readonly validate?: ((val: Record<string, any>) => boolean) | ((val: Record<string, any>) => void) | ((val: Record<string, any>) => string | void);
904
+ readonly field?: string;
905
+ }
906
+
907
+ export interface MapAttribute {
908
+ readonly type: "map";
909
+ readonly properties: {
910
+ readonly [name: string]: NestedAttributes;
911
+ };
912
+ readonly required?: boolean;
913
+ readonly hidden?: boolean;
914
+ readonly readOnly?: boolean;
915
+ readonly get?: (val: Record<string, any>, item: any) => Record<string, any> | undefined | void;
916
+ readonly set?: (val?: Record<string, any>, item?: any) => Record<string, any> | undefined | void;
917
+ readonly default?: Record<string, any> | (() => Record<string, any>);
918
+ readonly validate?: ((val: Record<string, any>) => boolean) | ((val: Record<string, any>) => void) | ((val: Record<string, any>) => string | void);
919
+ readonly field?: string;
920
+ readonly watch?: ReadonlyArray<string> | "*";
921
+ }
922
+
923
+ export interface NestedStringListAttribute {
924
+ readonly type: "list";
925
+ readonly items: {
926
+ readonly type: "string";
927
+ readonly required?: boolean;
928
+ readonly hidden?: boolean;
929
+ readonly readOnly?: boolean;
930
+ readonly get?: (val: string, item: any) => string | undefined | void;
931
+ readonly set?: (val?: string, item?: any) => string | undefined | void;
932
+ readonly default?: string | (() => string);
933
+ readonly validate?: ((val: string) => boolean) | ((val: string) => void) | ((val: string) => string | void) | RegExp;
934
+ readonly field?: string;
935
+ };
936
+ readonly required?: boolean;
937
+ readonly hidden?: boolean;
938
+ readonly readOnly?: boolean;
939
+ readonly get?: (val: Array<string>, item: any) => Array<string> | undefined | void;
940
+ readonly set?: (val?: Array<string>, item?: any) => Array<string> | undefined | void;
941
+ readonly default?: Array<string> | (() => Array<string>);
942
+ readonly validate?: ((val: Array<string>) => boolean) | ((val: Array<string>) => void) | ((val: Array<string>) => string | void);
943
+ }
944
+
945
+ export interface StringListAttribute {
946
+ readonly type: "list";
947
+ readonly items: {
948
+ readonly type: "string";
949
+ readonly required?: boolean;
950
+ readonly hidden?: boolean;
951
+ readonly readOnly?: boolean;
952
+ readonly get?: (val: string, item: any) => string | undefined | void;
953
+ readonly set?: (val?: string, item?: any) => string | undefined | void;
954
+ readonly default?: string | (() => string);
955
+ readonly validate?: ((val: string) => boolean) | ((val: string) => void) | ((val: string) => string | void) | RegExp;
956
+ readonly field?: string;
957
+ }
958
+ readonly required?: boolean;
959
+ readonly hidden?: boolean;
960
+ readonly readOnly?: boolean;
961
+ readonly get?: (val: Array<string>, item: any) => Array<string> | undefined | void;
962
+ readonly set?: (val?: Array<string>, item?: any) => Array<string> | undefined | void;
963
+ readonly default?: Array<string> | (() => Array<string>);
964
+ readonly validate?: ((val: Array<string>) => boolean) | ((val: Array<string>) => void) | ((val: Array<string>) => string | void);
965
+ readonly watch?: ReadonlyArray<string> | "*";
966
+ }
967
+
968
+ export interface NestedNumberListAttribute {
969
+ readonly type: "list";
970
+ readonly items: NestedNumberAttribute;
971
+ readonly required?: boolean;
972
+ readonly hidden?: boolean;
973
+ readonly readOnly?: boolean;
974
+ readonly get?: (val: Array<number>, item: any) => Array<number> | undefined | void;
975
+ readonly set?: (val?: Array<number>, item?: any) => Array<number> | undefined | void;
976
+ readonly default?: Array<number> | (() => Array<number>);
977
+ readonly validate?: ((val: Array<number>) => boolean) | ((val: Array<number>) => void) | ((val: Array<number>) => string | void);
978
+ readonly field?: string;
979
+ }
980
+
981
+ export interface NumberListAttribute {
982
+ readonly type: "list";
983
+ readonly items: NestedNumberAttribute;
984
+ readonly required?: boolean;
985
+ readonly hidden?: boolean;
986
+ readonly readOnly?: boolean;
987
+ readonly get?: (val: Array<number>, item: any) => Array<number> | undefined | void;
988
+ readonly set?: (val?: Array<number>, item?: any) => Array<number> | undefined | void;
989
+ readonly default?: Array<number> | (() => Array<number>);
990
+ readonly validate?: ((val: Array<number>) => boolean) | ((val: Array<number>) => void) | ((val: Array<number>) => string | void);
991
+ readonly field?: string;
992
+ readonly watch?: ReadonlyArray<string> | "*";
993
+ }
994
+
995
+ export interface NestedMapListAttribute {
996
+ readonly type: "list";
997
+ readonly items: NestedMapAttribute;
998
+ readonly required?: boolean;
999
+ readonly hidden?: boolean;
1000
+ readonly readOnly?: boolean;
1001
+ readonly get?: (val: Record<string, any>[], item: any) => Record<string, any>[] | undefined | void;
1002
+ readonly set?: (val?: Record<string, any>[], item?: any) => Record<string, any>[] | undefined | void;
1003
+ readonly default?: Record<string, any>[] | (() => Record<string, any>[]);
1004
+ readonly validate?: ((val: Record<string, any>[]) => boolean) | ((val: Record<string, any>[]) => void) | ((val: Record<string, any>[]) => string | void);
1005
+ readonly field?: string;
1006
+ }
1007
+
1008
+ export interface MapListAttribute {
1009
+ readonly type: "list";
1010
+ readonly items: NestedMapAttribute;
1011
+ readonly required?: boolean;
1012
+ readonly hidden?: boolean;
1013
+ readonly readOnly?: boolean;
1014
+ readonly get?: (val: Record<string, any>[], item: any) => Record<string, any>[] | undefined | void;
1015
+ readonly set?: (val?: Record<string, any>[], item?: any) => Record<string, any>[] | undefined | void;
1016
+ readonly default?: Record<string, any>[] | (() => Record<string, any>[]);
1017
+ readonly validate?: ((val: Record<string, any>[]) => boolean) | ((val: Record<string, any>[]) => void) | ((val: Record<string, any>[]) => string | void);
1018
+ readonly field?: string;
1019
+ readonly watch?: ReadonlyArray<string> | "*";
1020
+ }
1021
+
1022
+ export interface NestedStringSetAttribute {
1023
+ readonly type: "set";
1024
+ readonly items: "string";
1025
+ readonly required?: boolean;
1026
+ readonly hidden?: boolean;
1027
+ readonly readOnly?: boolean;
1028
+ readonly get?: (val: Array<string>, item: any) => Array<string> | undefined | void;
1029
+ readonly set?: (val?: Array<string>, item?: any) => Array<string> | undefined | void;
1030
+ readonly default?: Array<string> | (() => Array<string>);
1031
+ readonly validate?: ((val: Array<string>) => boolean) | ((val: Array<string>) => void) | ((val: Array<string>) => string | void) | RegExp;
1032
+ readonly field?: string;
1033
+ }
1034
+
1035
+ export interface StringSetAttribute {
1036
+ readonly type: "set";
1037
+ readonly items: "string";
1038
+ readonly required?: boolean;
1039
+ readonly hidden?: boolean;
1040
+ readonly readOnly?: boolean;
1041
+ readonly get?: (val: Array<string>, item: any) => Array<string> | undefined | void;
1042
+ readonly set?: (val?: Array<string>, item?: any) => Array<string> | undefined | void;
1043
+ readonly default?: Array<string> | (() => Array<string>);
1044
+ readonly validate?: ((val: Array<string>) => boolean) | ((val: Array<string>) => void) | ((val: Array<string>) => string | void) | RegExp;
1045
+ readonly field?: string;
1046
+ readonly watch?: ReadonlyArray<string> | "*";
1047
+ }
1048
+
1049
+ export interface NestedNumberSetAttribute {
1050
+ readonly type: "set";
1051
+ readonly items: "number";
1052
+ readonly required?: boolean;
1053
+ readonly hidden?: boolean;
1054
+ readonly readOnly?: boolean;
1055
+ readonly get?: (val: Array<number>, item: any) => Array<number> | undefined | void;
1056
+ readonly set?: (val?: Array<number>, item?: any) => Array<number> | undefined | void;
1057
+ readonly default?: Array<number> | (() => Array<number>);
1058
+ readonly validate?: ((val: Array<number>) => boolean) | ((val: Array<number>) => void) | ((val: Array<number>) => string | void);
1059
+ readonly field?: string;
1060
+ }
1061
+
1062
+ export interface NumberSetAttribute {
1063
+ readonly type: "set";
1064
+ readonly items: "number";
1065
+ readonly required?: boolean;
1066
+ readonly hidden?: boolean;
1067
+ readonly readOnly?: boolean;
1068
+ readonly get?: (val: Array<number>, item: any) => Array<number> | undefined | void;
1069
+ readonly set?: (val?: Array<number>, item?: any) => Array<number> | undefined | void;
1070
+ readonly default?: Array<number> | (() => Array<number>);
1071
+ readonly validate?: ((val: Array<number>) => boolean) | ((val: Array<number>) => void) | ((val: Array<number>) => string | void);
1072
+ readonly field?: string;
1073
+ readonly watch?: ReadonlyArray<string> | "*";
1074
+ }
1075
+
1076
+ export type Attribute =
1077
+ BooleanAttribute
1078
+ | NumberAttribute
1079
+ | StringAttribute
1080
+ | EnumAttribute
1081
+ | AnyAttribute
1082
+ | MapAttribute
1083
+ | StringSetAttribute
1084
+ | NumberSetAttribute
1085
+ | StringListAttribute
1086
+ | NumberListAttribute
1087
+ | MapListAttribute;
1088
+
1089
+ export type NestedAttributes =
1090
+ NestedBooleanAttribute
1091
+ | NestedNumberAttribute
1092
+ | NestedStringAttribute
1093
+ | NestedAnyAttribute
1094
+ | NestedMapAttribute
1095
+ | NestedStringListAttribute
1096
+ | NestedNumberListAttribute
1097
+ | NestedMapListAttribute
1098
+ | NestedStringSetAttribute
1099
+ | NestedNumberSetAttribute
1100
+ | NestedEnumAttribute;
1101
+
1102
+ export interface IndexWithSortKey {
1103
+ readonly sk: {
1104
+ readonly field: string;
1105
+ readonly composite: ReadonlyArray<string>;
1106
+ readonly template?: string;
1107
+ }
1108
+ }
1109
+
1110
+ export type AccessPatternCollection<C extends string> = C | ReadonlyArray<C>;
1111
+
1112
+ export interface Schema<A extends string, F extends string, C extends string> {
1113
+ readonly model: {
1114
+ readonly entity: string;
1115
+ readonly service: string;
1116
+ readonly version: string;
1117
+ }
1118
+ readonly attributes: {
1119
+ readonly [a in A]: Attribute
1120
+ };
1121
+ readonly indexes: {
1122
+ [accessPattern: string]: {
1123
+ readonly index?: string;
1124
+ readonly collection?: AccessPatternCollection<C>;
1125
+ readonly pk: {
1126
+ readonly casing?: "upper" | "lower" | "none" | "default";
1127
+ readonly field: string;
1128
+ readonly composite: ReadonlyArray<F>;
1129
+ readonly template?: string;
1130
+ }
1131
+ readonly sk?: {
1132
+ readonly casing?: "upper" | "lower" | "none" | "default";
1133
+ readonly field: string;
1134
+ readonly composite: ReadonlyArray<F>;
1135
+ readonly template?: string;
1136
+ }
1137
+ }
1138
+ }
1139
+ }
1140
+
1141
+ export type Attributes<A extends string> = Record<A, Attribute>
1142
+
1143
+ export type IndexCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1144
+ [i in keyof S["indexes"]]: S["indexes"][i]["collection"] extends
1145
+ AccessPatternCollection<infer Name>
1146
+ ? Name
1147
+ : never
1148
+ }[keyof S["indexes"]];
1149
+
1150
+ export type EntityCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1151
+ [N in IndexCollections<A,F,C,S>]: {
1152
+ [i in keyof S["indexes"]]: S["indexes"][i]["collection"] extends AccessPatternCollection<infer Name>
1153
+ ? Name extends N
1154
+ ? i
1155
+ : never
1156
+ : never
1157
+ }[keyof S["indexes"]];
1158
+ }
1159
+
1160
+ declare const SkipSymbol: unique symbol;
1161
+ type SkipValue = typeof SkipSymbol;
1162
+
1163
+ type PartialDefinedKeys<T> = {
1164
+ [P in keyof T as
1165
+ [undefined] extends [T[P]]
1166
+ ? never
1167
+ : SkipValue extends T[P]
1168
+ ? never
1169
+ : P
1170
+ ]?: T[P] | undefined;
1171
+ }
1172
+
1173
+ export type ItemAttribute<A extends Attribute> =
1174
+ A["type"] extends infer R
1175
+ ? R extends "string" ? string
1176
+ : R extends "number" ? number
1177
+ : R extends "boolean" ? boolean
1178
+ : R extends ReadonlyArray<infer E> ? E
1179
+ : R extends "map"
1180
+ ? "properties" extends keyof A
1181
+ ? {
1182
+ [P in keyof A["properties"]]:
1183
+ A["properties"][P] extends infer M
1184
+ ? M extends Attribute
1185
+ ? ItemAttribute<M>
1186
+ : never
1187
+ : never
1188
+ }
1189
+ : never
1190
+ : R extends "list"
1191
+ ? "items" extends keyof A
1192
+ ? A["items"] extends infer I
1193
+ ? I extends Attribute
1194
+ ? Array<ItemAttribute<I>>
1195
+ : never
1196
+ : never
1197
+ : never
1198
+ : R extends "set"
1199
+ ? "items" extends keyof A
1200
+ ? A["items"] extends infer I
1201
+ ? I extends "string" ? string[]
1202
+ : I extends "number" ? number[]
1203
+ : never
1204
+ : never
1205
+ : never
1206
+ : R extends "any" ? any
1207
+ : never
1208
+ : never
1209
+
1210
+ export type ReturnedAttribute<A extends Attribute> =
1211
+ A["type"] extends infer R
1212
+ ? R extends "string" ? string
1213
+ : R extends "number" ? number
1214
+ : R extends "boolean" ? boolean
1215
+ : R extends ReadonlyArray<infer E> ? E
1216
+ : R extends "map"
1217
+ ? "properties" extends keyof A
1218
+ ?
1219
+ {
1220
+ [
1221
+ P in keyof A["properties"] as A["properties"][P] extends RequiredAttribute
1222
+ ? P
1223
+ : never
1224
+ ]: A["properties"][P] extends infer M
1225
+ ? M extends Attribute
1226
+ ? ReturnedAttribute<M>
1227
+ : never
1228
+ : never
1229
+ } & {
1230
+ [
1231
+ P in keyof A["properties"] as A["properties"][P] extends HiddenAttribute | RequiredAttribute
1232
+ ? never
1233
+ : P
1234
+ ]?: A["properties"][P] extends infer M
1235
+ ? M extends Attribute
1236
+ ? ReturnedAttribute<M> | undefined
1237
+ : never
1238
+ : never
1239
+ }
1240
+ : never
1241
+ : R extends "list"
1242
+ ? "items" extends keyof A
1243
+ ? A["items"] extends infer I
1244
+ ? I extends Attribute
1245
+ ? ReturnedAttribute<I>[]
1246
+ : never
1247
+ : never
1248
+ : never
1249
+ : R extends "set"
1250
+ ? "items" extends keyof A
1251
+ ? A["items"] extends infer I
1252
+ ? I extends "string" ? string[]
1253
+ : I extends "number" ? number[]
1254
+ : never
1255
+ : never
1256
+ : never
1257
+ : R extends "any" ? any
1258
+ : never
1259
+ : never
1260
+
1261
+ export type CreatedAttribute<A extends Attribute> =
1262
+ A["type"] extends infer R
1263
+ ? R extends "string" ? string
1264
+ : R extends "number" ? number
1265
+ : R extends "boolean" ? boolean
1266
+ : R extends ReadonlyArray<infer E> ? E
1267
+ : R extends "map"
1268
+ ? "properties" extends keyof A
1269
+ ? {
1270
+ [
1271
+ P in keyof A["properties"] as A["properties"][P] extends RequiredAttribute
1272
+ ? A["properties"][P] extends DefaultedAttribute
1273
+ ? never
1274
+ : P
1275
+ : never
1276
+ ]: A["properties"][P] extends infer M
1277
+ ? M extends Attribute
1278
+ ? CreatedAttribute<M>
1279
+ : never
1280
+ : never
1281
+ } & {
1282
+ [P in keyof A["properties"] as A["properties"][P] extends HiddenAttribute
1283
+ ? never
1284
+ : P
1285
+ ]?: A["properties"][P] extends infer M
1286
+ ? M extends Attribute
1287
+ ? CreatedAttribute<M> | undefined
1288
+ : never
1289
+ : never
1290
+ }
1291
+ : never
1292
+ : R extends "list"
1293
+ ? "items" extends keyof A
1294
+ ? A["items"] extends infer I
1295
+ ? I extends Attribute
1296
+ ? CreatedAttribute<I>[]
1297
+ : never
1298
+ : never
1299
+ : never
1300
+ : R extends "set"
1301
+ ? "items" extends keyof A
1302
+ ? A["items"] extends infer I
1303
+ ? I extends "string" ? string[]
1304
+ : I extends "number" ? number[]
1305
+ : never
1306
+ : never
1307
+ : never
1308
+ : R extends "any" ? any
1309
+ : never
1310
+ : never
1311
+
1312
+ export type ReturnedItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>,Attr extends S["attributes"]> = {
1313
+ [a in keyof Attr]: ReturnedAttribute<Attr[a]>
1314
+ }
1315
+
1316
+ export type CreatedItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>,Attr extends S["attributes"]> = {
1317
+ [a in keyof Attr]: CreatedAttribute<Attr[a]>
1318
+ }
1319
+
1320
+ export type EditableItemAttribute<A extends Attribute> =
1321
+ A extends ReadOnlyAttribute
1322
+ ? never
1323
+ : A["type"] extends infer R
1324
+ ? R extends "string" ? string
1325
+ : R extends "number" ? number
1326
+ : R extends "boolean" ? boolean
1327
+ : R extends ReadonlyArray<infer E> ? E
1328
+ : R extends "map"
1329
+ ? "properties" extends keyof A
1330
+ ? {
1331
+ [
1332
+ P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute
1333
+ ? never
1334
+ : P
1335
+ ]:
1336
+ A["properties"][P] extends infer M
1337
+ ? M extends Attribute
1338
+ ? EditableItemAttribute<M>
1339
+ : never
1340
+ : never
1341
+ }
1342
+ : never
1343
+ : R extends "list"
1344
+ ? "items" extends keyof A
1345
+ ? A["items"] extends infer I
1346
+ ? I extends Attribute
1347
+ ? Array<EditableItemAttribute<I>>
1348
+ : never
1349
+ : never
1350
+ : never
1351
+ : R extends "set"
1352
+ ? "items" extends keyof A
1353
+ ? A["items"] extends infer I
1354
+ ? I extends "string" ? string[]
1355
+ : I extends "number" ? number[]
1356
+ : never
1357
+ : never
1358
+ : never
1359
+ : R extends "any" ? any
1360
+ : never
1361
+ : never
1362
+
1363
+ export type UpdatableItemAttribute<A extends Attribute> =
1364
+ A extends ReadOnlyAttribute
1365
+ ? never
1366
+ : A["type"] extends infer R
1367
+ ? R extends "string" ? string
1368
+ : R extends "number" ? number
1369
+ : R extends "boolean" ? boolean
1370
+ : R extends ReadonlyArray<infer E> ? E
1371
+ : R extends "map"
1372
+ ? "properties" extends keyof A
1373
+ ? {
1374
+ [
1375
+ P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute
1376
+ ? never
1377
+ : A["properties"][P] extends RequiredAttribute
1378
+ ? P
1379
+ : never
1380
+ ]:
1381
+ A["properties"][P] extends infer M
1382
+ ? M extends Attribute
1383
+ ? UpdatableItemAttribute<M>
1384
+ : never
1385
+ : never
1386
+ } & {
1387
+ [
1388
+ P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute
1389
+ ? never
1390
+ : A["properties"][P] extends RequiredAttribute
1391
+ ? never
1392
+ : P
1393
+ ]?:
1394
+ A["properties"][P] extends infer M
1395
+ ? M extends Attribute
1396
+ ? UpdatableItemAttribute<M>
1397
+ : never
1398
+ : never
1399
+ }
1400
+ : never
1401
+ : R extends "list"
1402
+ ? "items" extends keyof A
1403
+ ? A["items"] extends infer I
1404
+ ? I extends Attribute
1405
+ ? Array<UpdatableItemAttribute<I>>
1406
+ : never
1407
+ : never
1408
+ : never
1409
+ : R extends "set"
1410
+ ? "items" extends keyof A
1411
+ ? A["items"] extends infer I
1412
+ ? I extends "string" ? string[]
1413
+ : I extends "number" ? number[]
1414
+ : never
1415
+ : never
1416
+ : never
1417
+ : R extends "any" ? any
1418
+ : never
1419
+ : never
1420
+
1421
+ export type RemovableItemAttribute<A extends Attribute> =
1422
+ A extends ReadOnlyAttribute | RequiredAttribute
1423
+ ? never
1424
+ : A["type"] extends infer R
1425
+ ? R extends "string" ? string
1426
+ : R extends "number" ? number
1427
+ : R extends "boolean" ? boolean
1428
+ : R extends ReadonlyArray<infer E> ? E
1429
+ : R extends "map"
1430
+ ? "properties" extends keyof A
1431
+ ? {
1432
+ [
1433
+ P in keyof A["properties"] as A["properties"][P] extends ReadOnlyAttribute | RequiredAttribute
1434
+ ? never
1435
+ : P
1436
+ ]?:
1437
+ A["properties"][P] extends infer M
1438
+ ? M extends Attribute
1439
+ ? UpdatableItemAttribute<M>
1440
+ : never
1441
+ : never
1442
+ }
1443
+ : never
1444
+ : R extends "list"
1445
+ ? "items" extends keyof A
1446
+ ? A["items"] extends infer I
1447
+ ? I extends Attribute
1448
+ ? Array<UpdatableItemAttribute<I>>
1449
+ : never
1450
+ : never
1451
+ : never
1452
+ : R extends "set"
1453
+ ? "items" extends keyof A
1454
+ ? A["items"] extends infer I
1455
+ ? I extends "string" ? string[]
1456
+ : I extends "number" ? number[]
1457
+ : never
1458
+ : never
1459
+ : never
1460
+ : R extends "any" ? any
1461
+ : never
1462
+ : never
1463
+
1464
+ export type Item<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, Attr extends Attributes<A>> = {
1465
+ [a in keyof Attr]: ItemAttribute<Attr[a]>
1466
+ }
1467
+
1468
+ export type ItemTypeDescription<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1469
+ [a in keyof S["attributes"]]: S["attributes"][a]["type"] extends infer R
1470
+ ? R
1471
+ : never
1472
+ }
1473
+
1474
+ export type RequiredAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<{
1475
+ [a in keyof S["attributes"]]: S["attributes"][a] extends RequiredAttribute
1476
+ ? true
1477
+ : false
1478
+ }, true>
1479
+
1480
+ export type HiddenAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<{
1481
+ [a in keyof S["attributes"]]: S["attributes"][a] extends HiddenAttribute
1482
+ ? true
1483
+ : false
1484
+ }, true>
1485
+
1486
+ export type ReadOnlyAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<{
1487
+ [a in keyof S["attributes"]]: S["attributes"][a] extends ReadOnlyAttribute
1488
+ ? true
1489
+ : false
1490
+ }, true>
1491
+
1492
+ type ExtractKeysOfValueType<T, K> = {
1493
+ [I in keyof T]: T[I] extends K ? I : never
1494
+ }[keyof T];
1495
+
1496
+ export type TableIndexes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1497
+ [i in keyof S["indexes"]]: S["indexes"][i] extends SecondaryIndex
1498
+ ? "secondary"
1499
+ : "table"
1500
+ };
1501
+
1502
+ export type TableIndexName<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ExtractKeysOfValueType<TableIndexes<A,F,C,S>, "table">;
1503
+
1504
+ export type PKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1505
+ [i in keyof S["indexes"]]: S["indexes"][i]["pk"]["composite"] extends ReadonlyArray<infer Composite>
1506
+ ? Composite
1507
+ : never
1508
+ }
1509
+
1510
+ export type SKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1511
+ [i in keyof S["indexes"]]: S["indexes"][i] extends IndexWithSortKey
1512
+ ? S["indexes"][i]["sk"]["composite"] extends ReadonlyArray<infer Composite>
1513
+ ? Composite
1514
+ : never
1515
+ : never;
1516
+ }
1517
+
1518
+ export type TableIndexPKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = Pick<PKCompositeAttributes<A,F,C,S>, TableIndexName<A,F,C,S>>;
1519
+
1520
+ export type TableIndexSKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = Pick<SKCompositeAttributes<A,F,C,S>, TableIndexName<A,F,C,S>>;
1521
+
1522
+ export type IndexPKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<PKCompositeAttributes<A,F,C,S>,I>;
1523
+
1524
+ export type IndexSKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<SKCompositeAttributes<A,F,C,S>,I>;
1525
+
1526
+ export type TableIndexPKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1527
+ TableIndexName<A,F,C,S> extends keyof TableIndexPKCompositeAttributes<A,F,C,S>
1528
+ ? TableIndexPKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>] extends keyof Item<A,F,C,S,S["attributes"]>
1529
+ ? Pick<Item<A,F,C,S,S["attributes"]>, TableIndexPKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>]>
1530
+ : never
1531
+ : never
1532
+
1533
+ export type TableIndexSKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = TableIndexSKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>] extends keyof S["attributes"]
1534
+ ? Pick<Item<A,F,C,S,S["attributes"]>, TableIndexSKCompositeAttributes<A,F,C,S>[TableIndexName<A,F,C,S>]>
1535
+ : Item<A,F,C,S,S["attributes"]>;
1536
+
1537
+ export type IndexPKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> =
1538
+ I extends keyof IndexPKCompositeAttributes<A,F,C,S,I>
1539
+ ? IndexPKCompositeAttributes<A,F,C,S,I>[I] extends keyof Item<A,F,C,S,S["attributes"]>
1540
+ ? Pick<Item<A,F,C,S,S["attributes"]>, IndexPKCompositeAttributes<A,F,C,S,I>[I]>
1541
+ : never
1542
+ : never;
1543
+
1544
+ export type IndexSKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = IndexSKCompositeAttributes<A,F,C,S,I>[I] extends keyof S["attributes"]
1545
+ ? Pick<Item<A,F,C,S,S["attributes"]>, IndexSKCompositeAttributes<A,F,C,S,I>[I]>
1546
+ : Item<A,F,C,S,S["attributes"]>;
1547
+
1548
+ export type TableIndexCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = TableIndexPKAttributes<A,F,C,S> & Partial<TableIndexSKAttributes<A,F,C,S>>;
1549
+
1550
+ export type AllTableIndexCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = TableIndexPKAttributes<A,F,C,S> & TableIndexSKAttributes<A,F,C,S>;
1551
+
1552
+ export type IndexCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = IndexPKAttributes<A,F,C,S,I> & Partial<IndexSKAttributes<A,F,C,S,I>>;
1553
+
1554
+ export type TableItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1555
+ AllTableIndexCompositeAttributes<A,F,C,S> &
1556
+ Pick<ReturnedItem<A,F,C,S,S["attributes"]>, RequiredAttributes<A,F,C,S>> &
1557
+ Partial<Omit<ReturnedItem<A,F,C,S,S["attributes"]>, RequiredAttributes<A,F,C,S>>>
1558
+
1559
+ export type ResponseItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1560
+ Omit<TableItem<A,F,C,S>, HiddenAttributes<A,F,C,S>>
1561
+
1562
+ export type RequiredPutItems<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1563
+ [Attribute in keyof S["attributes"]]:
1564
+ "default" extends keyof S["attributes"][Attribute]
1565
+ ? false
1566
+ : "required" extends keyof S["attributes"][Attribute]
1567
+ ? true extends S["attributes"][Attribute]["required"]
1568
+ ? true
1569
+ : Attribute extends keyof TableIndexCompositeAttributes<A,F,C,S>
1570
+ ? true
1571
+ : false
1572
+ : Attribute extends keyof TableIndexCompositeAttributes<A,F,C,S>
1573
+ ? true
1574
+ : false
1575
+ }
1576
+
1577
+ export type PutItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1578
+ Pick<CreatedItem<A,F,C,S,S["attributes"]>, ExtractKeysOfValueType<RequiredPutItems<A,F,C,S>,true>>
1579
+ & Partial<CreatedItem<A,F,C,S,S["attributes"]>>
1580
+
1581
+ export type UpdateData<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1582
+ Omit<{
1583
+ [Attr in keyof S["attributes"]]: EditableItemAttribute<S["attributes"][Attr]>
1584
+ }, keyof AllTableIndexCompositeAttributes<A,F,C,S> | ReadOnlyAttributes<A,F,C,S>>
1585
+
1586
+ export type SetItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1587
+ // UpdatableItemAttribute
1588
+ Omit<{
1589
+ [Attr in keyof S["attributes"]]?: UpdatableItemAttribute<S["attributes"][Attr]>
1590
+ }, keyof AllTableIndexCompositeAttributes<A,F,C,S> | ReadOnlyAttributes<A,F,C,S>>
1591
+
1592
+ // type RemoveItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1593
+ // Array<keyof SetItem<A,F,C,S>>
1594
+ export type RemoveItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1595
+ Array< keyof Omit<{
1596
+ [Attr in keyof S["attributes"]]?: RemovableItemAttribute<S["attributes"][Attr]>
1597
+ }, keyof AllTableIndexCompositeAttributes<A,F,C,S> | ReadOnlyAttributes<A,F,C,S> | RequiredAttributes<A,F,C,S>>>
1598
+
1599
+ export type AppendItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1600
+ {
1601
+ [
1602
+ P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends 'list' | 'any'
1603
+ ? P
1604
+ : never
1605
+ ]?: P extends keyof SetItem<A,F,C,S>
1606
+ ? SetItem<A,F,C,S>[P] | undefined
1607
+ : never
1608
+ }
1609
+
1610
+ export type AddItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1611
+ {
1612
+ [
1613
+ P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends "number" | "any" | "set"
1614
+ ? P
1615
+ : never
1616
+ ]?: P extends keyof SetItem<A,F,C,S>
1617
+ ? SetItem<A,F,C,S>[P] | undefined
1618
+ : never
1619
+ }
1620
+
1621
+ export type SubtractItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1622
+ {
1623
+ [
1624
+ P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends "number" | "any"
1625
+ ? P
1626
+ : never
1627
+ ]?: P extends keyof SetItem<A,F,C,S>
1628
+ ? SetItem<A,F,C,S>[P] | undefined
1629
+ : never
1630
+ }
1631
+
1632
+ export type DeleteItem<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
1633
+ {
1634
+ [
1635
+ P in keyof ItemTypeDescription<A,F,C,S> as ItemTypeDescription<A,F,C,S>[P] extends "any" | "set"
1636
+ ? P
1637
+ : never
1638
+ ]?: P extends keyof SetItem<A,F,C,S>
1639
+ ? SetItem<A,F,C,S>[P] | undefined
1640
+ : never
1641
+ }
1642
+
1643
+ export declare const WhereSymbol: unique symbol;
1644
+ export declare const UpdateDataSymbol: unique symbol;
1645
+
1646
+ export type WhereAttributeSymbol<T extends any> =
1647
+ { [WhereSymbol]: void }
1648
+ & T extends string ? T
1649
+ : T extends number ? T
1650
+ : T extends boolean ? T
1651
+ : T extends {[key: string]: any}
1652
+ ? {[key in keyof T]: WhereAttributeSymbol<T[key]>}
1653
+ : T extends ReadonlyArray<infer A>
1654
+ ? ReadonlyArray<WhereAttributeSymbol<A>>
1655
+ : T extends Array<infer I>
1656
+ ? Array<WhereAttributeSymbol<I>>
1657
+ : T
1658
+
1659
+ export type WhereAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> = {
1660
+ [Attr in keyof I]: WhereAttributeSymbol<I[Attr]>
1661
+ }
1662
+
1663
+ export type DataUpdateAttributeSymbol<T extends any> =
1664
+ { [UpdateDataSymbol]: void }
1665
+ & T extends string ? T
1666
+ : T extends number ? T
1667
+ : T extends boolean ? T
1668
+ : T extends {[key: string]: any}
1669
+ ? {[key in keyof T]: DataUpdateAttributeSymbol<T[key]>}
1670
+ : T extends ReadonlyArray<infer A>
1671
+ ? ReadonlyArray<DataUpdateAttributeSymbol<A>>
1672
+ : T extends Array<infer I>
1673
+ ? Array<DataUpdateAttributeSymbol<I>>
1674
+ : [T] extends [never]
1675
+ ? never
1676
+ : T
1677
+
1678
+ export type DataUpdateAttributeValues<A extends DataUpdateAttributeSymbol<any>> =
1679
+ A extends DataUpdateAttributeSymbol<infer T>
1680
+ ? T extends string ? T
1681
+ : T extends number ? T
1682
+ : T extends boolean ? T
1683
+ : T extends {[key: string]: any}
1684
+ ? {[key in keyof T]?: DataUpdateAttributeValues<T[key]>}
1685
+ : T extends ReadonlyArray<infer A> ? ReadonlyArray<DataUpdateAttributeValues<A>>
1686
+ : T extends Array<infer I> ? Array<DataUpdateAttributeValues<I>>
1687
+ : [T] extends [never]
1688
+ ? never
1689
+ : T
1690
+ : never
1691
+
1692
+ export type DataUpdateAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>> = {
1693
+ [Attr in keyof I]: DataUpdateAttributeSymbol<I[Attr]>
1694
+ }
1695
+
1696
+ export interface WhereOperations<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> {
1697
+ eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1698
+ ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1699
+ gt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1700
+ lt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1701
+ gte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1702
+ lte: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1703
+ between: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T, value2: T) => string;
1704
+ begins: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1705
+ exists: <A extends WhereAttributeSymbol<any>>(attr: A) => string;
1706
+ notExists: <A extends WhereAttributeSymbol<any>>(attr: A) => string;
1707
+ contains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1708
+ notContains: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
1709
+ value: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: A extends WhereAttributeSymbol<infer V> ? V : never) => A extends WhereAttributeSymbol<infer V> ? V : never;
1710
+ name: <A extends WhereAttributeSymbol<any>>(attr: A) => string;
1711
+ }
1712
+
1713
+ export interface DataUpdateOperations<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>> {
1714
+ set: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => any;
1715
+ remove: <T, A extends DataUpdateAttributeSymbol<T>>(attr: [T] extends [never] ? never : A) => any;
1716
+ append: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A> extends Array<any> ? DataUpdateAttributeValues<A> : never) => any;
1717
+ add: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends number | Array<any> ? V : [V] extends [any] ? V : never : never ) => any;
1718
+ subtract: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends number ? V : [V] extends [any] ? V : never : never ) => any;
1719
+ delete: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends Array<any> ? V : [V] extends [any] ? V : never : never ) => any;
1720
+ del: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: A extends DataUpdateAttributeSymbol<infer V> ? V extends Array<any> ? V : never : never ) => any;
1721
+ value: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => Required<DataUpdateAttributeValues<A>>;
1722
+ name: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A) => any;
1723
+ ifNotExists: <T, A extends DataUpdateAttributeSymbol<T>>(attr: A, value: DataUpdateAttributeValues<A>) => any;
1724
+ }
1725
+
1726
+ export type WhereCallback<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>> =
1727
+ <W extends WhereAttributes<A,F,C,S,I>>(attributes: W, operations: WhereOperations<A,F,C,S,I>) => string;
1728
+
1729
+ export type DataUpdateCallback<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>> =
1730
+ <W extends DataUpdateAttributes<A,F,C,S,I>>(attributes: W, operations: DataUpdateOperations<A,F,C,S,I>) => any;
1731
+
1732
+ export type WhereClause<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Item<A,F,C,S,S["attributes"]>, T> = (where: WhereCallback<A,F,C,S,I>) => T;
1733
+
1734
+ export type DataUpdateMethod<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends UpdateData<A,F,C,S>, T> = (update: DataUpdateCallback<A,F,C,S,I>) => T;
1735
+
1736
+ type Resolve<T> = T extends Function | string | number | boolean
1737
+ ? T : {[Key in keyof T]: Resolve<T[Key]>}
1738
+
1739
+ export type EntityConfiguration = {
1740
+ table?: string;
1741
+ client?: DocumentClient;
1742
+ listeners?: Array<ElectroEventListener>;
1743
+ logger?: ElectroEventListener;
1744
+ };
1745
+
1746
+ export class Entity<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> {
1747
+ readonly schema: S;
1748
+ private config?: EntityConfiguration;
1749
+ constructor(schema: S, config?: EntityConfiguration);
1750
+
1751
+ get(key: AllTableIndexCompositeAttributes<A,F,C,S>): SingleRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>;
1752
+ get(key: AllTableIndexCompositeAttributes<A,F,C,S>[]): BatchGetRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>;
1753
+ delete(key: AllTableIndexCompositeAttributes<A,F,C,S>): DeleteRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>;
1754
+ delete(key: AllTableIndexCompositeAttributes<A,F,C,S>[]): BulkRecordOperationOptions<A,F,C,S, AllTableIndexCompositeAttributes<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>[]>;
1755
+
1756
+ put(record: PutItem<A,F,C,S>): PutRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>;
1757
+ put(record: PutItem<A,F,C,S>[]): BulkRecordOperationOptions<A,F,C,S, AllTableIndexCompositeAttributes<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>[]>;
1758
+
1759
+ remove(key: AllTableIndexCompositeAttributes<A,F,C,S>): DeleteRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>
1760
+ update(key: AllTableIndexCompositeAttributes<A,F,C,S>): {
1761
+ set: SetRecord<A,F,C,S, SetItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1762
+ remove: RemoveRecord<A,F,C,S, RemoveItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1763
+ add: SetRecord<A,F,C,S, AddItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1764
+ subtract: SetRecord<A,F,C,S, SubtractItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1765
+ append: SetRecord<A,F,C,S, AppendItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1766
+ delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1767
+ data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1768
+ };
1769
+
1770
+ patch(key: AllTableIndexCompositeAttributes<A,F,C,S>): {
1771
+ set: SetRecord<A,F,C,S, SetItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1772
+ remove: RemoveRecord<A,F,C,S, RemoveItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1773
+ add: SetRecord<A,F,C,S, AddItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1774
+ subtract: SetRecord<A,F,C,S, SubtractItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1775
+ append: SetRecord<A,F,C,S, AppendItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1776
+ delete: SetRecord<A,F,C,S, DeleteItem<A,F,C,S>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1777
+ data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1778
+ };
1779
+
1780
+ create(record: PutItem<A,F,C,S>): PutRecordOperationOptions<A,F,C,S, ResponseItem<A,F,C,S>>
1781
+
1782
+ find(record: Partial<Item<A,F,C,S,S["attributes"]>>): RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>>;
1783
+
1784
+ match(record: Partial<Item<A,F,C,S,S["attributes"]>>): RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], AllTableIndexCompositeAttributes<A,F,C,S>>;
1785
+
1786
+ scan: RecordsActionOptions<A,F,C,S, ResponseItem<A,F,C,S>[], TableIndexCompositeAttributes<A,F,C,S>>;
1787
+ query: Queries<A,F,C,S>;
1788
+
1789
+ parse<Options extends ParseOptions<keyof ResponseItem<A,F,C,S>>>(item: ParseSingleInput, options?: Options):
1790
+ Options extends ParseOptions<infer Attr>
1791
+ ? {
1792
+ [
1793
+ Name in keyof ResponseItem<A,F,C,S> as Name extends Attr
1794
+ ? Name
1795
+ : never
1796
+ ]: ResponseItem<A,F,C,S>[Name]
1797
+ } | null
1798
+ : ResponseItem<A,F,C,S> | null
1799
+ parse<Options extends ParseOptions<keyof ResponseItem<A,F,C,S>>>(item: ParseMultiInput, options?: Options):
1800
+ Options extends ParseOptions<infer Attr>
1801
+ ? Array<{
1802
+ [
1803
+ Name in keyof ResponseItem<A,F,C,S> as Name extends Attr
1804
+ ? Name
1805
+ : never
1806
+ ]: ResponseItem<A,F,C,S>[Name]
1807
+ }>
1808
+ : Array<ResponseItem<A,F,C,S>>
1809
+ setIdentifier(type: "entity" | "version", value: string): void;
1810
+ client: any;
1811
+ }
1812
+
1813
+ export type ServiceConfiguration = {
1814
+ table?: string;
1815
+ client?: DocumentClient;
1816
+ listeners?: Array<ElectroEventListener>;
1817
+ logger?: ElectroEventListener;
1818
+ };
1819
+
1820
+ export class Service<E extends {[name: string]: Entity<any, any, any, any>}> {
1821
+ entities: E;
1822
+ collections: CollectionQueries<E, CollectionAssociations<E>>
1823
+ constructor(entities: E, config?: ServiceConfiguration);
1824
+ }