electrodb 1.10.1 → 1.10.2

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