electrodb 2.1.1 → 2.2.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
@@ -24,6 +24,34 @@ export type AllCollectionNames<E extends {[name: string]: Entity<any, any, any,
24
24
  : never
25
25
  }[keyof E];
26
26
 
27
+ export type ClusteredCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
28
+ [Name in keyof E]:
29
+ E[Name] extends Entity<infer A, infer F, infer C, infer S>
30
+ ? {
31
+ [Collection in keyof ClusteredEntityCollections<A,F,C,S>]: Collection
32
+ }[keyof ClusteredEntityCollections<A,F,C,S>]
33
+ : never
34
+ }[keyof E];
35
+
36
+ export type IsolatedCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
37
+ [Name in keyof E]:
38
+ E[Name] extends Entity<infer A, infer F, infer C, infer S>
39
+ ? {
40
+ [Collection in keyof IsolatedEntityCollections<A,F,C,S>]: Collection
41
+ }[keyof IsolatedEntityCollections<A,F,C,S>]
42
+ : never
43
+ }[keyof E];
44
+
45
+ export type IsolatedCollectionAssociations<E extends {[name: string]: Entity<any, any, any, any>}> = {
46
+ [Collection in IsolatedCollectionNames<E>]: {
47
+ [Name in keyof E]: E[Name] extends Entity<infer A, infer F, infer C, infer S>
48
+ ? Collection extends keyof IsolatedEntityCollections<A,F,C,S>
49
+ ? Name
50
+ : never
51
+ : never
52
+ }[keyof E];
53
+ }
54
+
27
55
  export type AllEntityAttributeNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
28
56
  [Name in keyof E]: {
29
57
  [A in keyof E[Name]["schema"]["attributes"]]: A
@@ -48,6 +76,16 @@ export type CollectionAssociations<E extends {[name: string]: Entity<any, any, a
48
76
  }[keyof E];
49
77
  }
50
78
 
79
+ export type ClusteredCollectionAssociations<E extends {[name: string]: Entity<any, any, any, any>}> = {
80
+ [Collection in ClusteredCollectionNames<E>]: {
81
+ [Name in keyof E]: E[Name] extends Entity<infer A, infer F, infer C, infer S>
82
+ ? Collection extends keyof ClusteredEntityCollections<A,F,C,S>
83
+ ? Name
84
+ : never
85
+ : never
86
+ }[keyof E];
87
+ }
88
+
51
89
  export type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
52
90
  [Collection in keyof Collections]: {
53
91
  [EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
@@ -58,6 +96,26 @@ export type CollectionAttributes<E extends {[name: string]: Entity<any, any, any
58
96
  }[keyof E]
59
97
  }
60
98
 
99
+ export type ClusteredCollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<E>> = {
100
+ [Collection in keyof Collections]: {
101
+ [EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
102
+ ? EntityName extends Collections[Collection]
103
+ ? keyof S["attributes"]
104
+ : never
105
+ : never
106
+ }[keyof E]
107
+ }
108
+
109
+ export type IsolatedCollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends IsolatedCollectionAssociations<E>> = {
110
+ [Collection in keyof Collections]: {
111
+ [EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
112
+ ? EntityName extends Collections[Collection]
113
+ ? keyof S["attributes"]
114
+ : never
115
+ : never
116
+ }[keyof E]
117
+ }
118
+
61
119
  export interface CollectionWhereOperations {
62
120
  eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
63
121
  ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
@@ -98,6 +156,28 @@ export type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, an
98
156
  }[Collections[Collection]]
99
157
  }
100
158
 
159
+ export type ClusteredCollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<Entities>> = {
160
+ [Collection in keyof Collections]: {
161
+ [EntityResultName in Collections[Collection]]:
162
+ EntityResultName extends keyof Entities
163
+ ? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
164
+ ? keyof TableIndexCompositeAttributes<A, F, C, S>
165
+ : never
166
+ : never
167
+ }[Collections[Collection]]
168
+ }
169
+
170
+ export type IsolatedCollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends IsolatedCollectionAssociations<Entities>> = {
171
+ [Collection in keyof Collections]: {
172
+ [EntityResultName in Collections[Collection]]:
173
+ EntityResultName extends keyof Entities
174
+ ? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
175
+ ? keyof TableIndexCompositeAttributes<A, F, C, S>
176
+ : never
177
+ : never
178
+ }[Collections[Collection]]
179
+ }
180
+
101
181
  export type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
102
182
  [Collection in keyof Collections]: {
103
183
  [EntityResultName in Collections[Collection]]:
@@ -113,6 +193,36 @@ export type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any
113
193
  }[Collections[Collection]]
114
194
  }
115
195
 
196
+ export type ClusteredCollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<Entities>> = {
197
+ [Collection in keyof Collections]: {
198
+ [EntityResultName in Collections[Collection]]:
199
+ EntityResultName extends keyof Entities
200
+ ? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
201
+ ? keyof Parameters<Entities[EntityResultName]["query"][
202
+ Collection extends keyof ClusteredEntityCollections<A,F,C,S>
203
+ ? ClusteredEntityCollections<A,F,C,S>[Collection]
204
+ : never
205
+ ]>[0]
206
+ : never
207
+ : never
208
+ }[Collections[Collection]]
209
+ }
210
+
211
+ export type IsolatedCollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends IsolatedCollectionAssociations<Entities>> = {
212
+ [Collection in keyof Collections]: {
213
+ [EntityResultName in Collections[Collection]]:
214
+ EntityResultName extends keyof Entities
215
+ ? Entities[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
216
+ ? keyof Parameters<Entities[EntityResultName]["query"][
217
+ Collection extends keyof IsolatedEntityCollections<A,F,C,S>
218
+ ? IsolatedEntityCollections<A,F,C,S>[Collection]
219
+ : never
220
+ ]>[0]
221
+ : never
222
+ : never
223
+ }[Collections[Collection]]
224
+ }
225
+
116
226
  export type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
117
227
  [Collection in keyof CollectionIndexKeys<Entities, Collections>]: {
118
228
  [key in CollectionIndexKeys<Entities, Collections>[Collection]]:
@@ -122,6 +232,24 @@ export type CollectionIndexAttributes<Entities extends {[name: string]: Entity<a
122
232
  }
123
233
  }
124
234
 
235
+ export type ClusteredCollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<Entities>> = {
236
+ [Collection in keyof ClusteredCollectionIndexKeys<Entities, Collections>]: {
237
+ [Key in ClusteredCollectionIndexKeys<Entities, Collections>[Collection]]:
238
+ Key extends keyof AllEntityAttributes<Entities>
239
+ ? AllEntityAttributes<Entities>[Key]
240
+ : never
241
+ }
242
+ }
243
+
244
+ export type IsolatedCollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends IsolatedCollectionAssociations<Entities>> = {
245
+ [Collection in keyof IsolatedCollectionIndexKeys<Entities, Collections>]: {
246
+ [Key in IsolatedCollectionIndexKeys<Entities, Collections>[Collection]]:
247
+ Key extends keyof AllEntityAttributes<Entities>
248
+ ? AllEntityAttributes<Entities>[Key]
249
+ : never
250
+ }
251
+ }
252
+
125
253
  export type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
126
254
  [Collection in keyof CollectionPageKeys<Entities, Collections>]: {
127
255
  [key in CollectionPageKeys<Entities, Collections>[Collection]]:
@@ -131,6 +259,24 @@ export type CollectionPageAttributes<Entities extends {[name: string]: Entity<an
131
259
  }
132
260
  }
133
261
 
262
+ export type ClusteredCollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<Entities>> = {
263
+ [Collection in keyof ClusteredCollectionPageKeys<Entities, Collections>]: {
264
+ [key in ClusteredCollectionPageKeys<Entities, Collections>[Collection]]:
265
+ key extends keyof AllEntityAttributes<Entities>
266
+ ? AllEntityAttributes<Entities>[key]
267
+ : never
268
+ }
269
+ }
270
+
271
+ export type IsolatedCollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends IsolatedCollectionAssociations<Entities>> = {
272
+ [Collection in keyof IsolatedCollectionPageKeys<Entities, Collections>]: {
273
+ [key in IsolatedCollectionPageKeys<Entities, Collections>[Collection]]:
274
+ key extends keyof AllEntityAttributes<Entities>
275
+ ? AllEntityAttributes<Entities>[key]
276
+ : never
277
+ }
278
+ }
279
+
134
280
  export type OptionalPropertyNames<T> =
135
281
  { [K in keyof T]: undefined extends T[K] ? K : never }[keyof T];
136
282
 
@@ -215,6 +361,165 @@ export type CollectionQueries<E extends {[name: string]: Entity<any, any, any, a
215
361
  }[keyof E];
216
362
  }
217
363
 
364
+ type ClusteredCollectionOperations<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<E>, Collection extends keyof Collections, EntityName extends keyof E> =
365
+ EntityName extends Collections[Collection] ? {
366
+ go: ServiceQueryRecordsGo<{
367
+ [EntityResultName in Collections[Collection]]:
368
+ EntityResultName extends keyof E
369
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
370
+ ? ResponseItem<A,F,C,S>[]
371
+ : never
372
+ : never
373
+ }>;
374
+ params: ParamRecord;
375
+ where: {
376
+ [EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
377
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
378
+ ? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, ClusteredCollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
379
+ ? CollectionWhereClause<E,A,F,C,S,
380
+ Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, ClusteredCollectionAttributes<E,Collections>[Collection]>>,
381
+ ServiceWhereRecordsActionOptions<E,A,F,C,S,
382
+ Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, ClusteredCollectionAttributes<E,Collections>[Collection]>>,
383
+ {
384
+ [EntityResultName in Collections[Collection]]:
385
+ EntityResultName extends keyof E
386
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
387
+ ? ResponseItem<A,F,C,S>[]
388
+ : never
389
+ : never
390
+ },
391
+ Partial<
392
+ Spread<
393
+ Collection extends keyof ClusteredCollectionPageAttributes<E, Collections>
394
+ ? ClusteredCollectionPageAttributes<E, Collections>[Collection]
395
+ : {},
396
+ Collection extends keyof ClusteredCollectionIndexAttributes<E, Collections>
397
+ ? ClusteredCollectionIndexAttributes<E, Collections>[Collection]
398
+ : {}
399
+ >
400
+ >
401
+ >>
402
+ : never
403
+ : never
404
+ : never
405
+ }[Collections[Collection]];
406
+ } : never
407
+
408
+ type ClusteredCompositeAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<E>, Collection extends keyof Collections, EntityName extends keyof E> =
409
+ EntityName extends Collections[Collection]
410
+ ? Parameters<
411
+ E[EntityName]["query"][
412
+ E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
413
+ ? Collection extends keyof ClusteredEntityCollections<A,F,C,S>
414
+ ? ClusteredEntityCollections<A,F,C,S>[Collection]
415
+ : never
416
+ : never
417
+ ]
418
+ >[0]
419
+ : never
420
+
421
+ type ClusteredCollectionQueryOperations<Param, Result> = {
422
+ between(skCompositeAttributesStart: Param, skCompositeAttributesEnd: Param): Result;
423
+ gt(skCompositeAttributes: Param): Result;
424
+ gte(skCompositeAttributes: Param): Result;
425
+ lt(skCompositeAttributes: Param): Result;
426
+ lte(skCompositeAttributes: Param): Result;
427
+ begins(skCompositeAttributes: Param): Result;
428
+ }
429
+
430
+ type OptionalPropertyOf<T extends object> = Exclude<{
431
+ [K in keyof T]: T extends Record<K, T[K]>
432
+ ? never
433
+ : K
434
+ }[keyof T], undefined>
435
+
436
+ type ClusteredCollectionQueryParams<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<E>> = {
437
+ [Collection in keyof Collections as Collections[Collection] extends keyof E ? Collection : never]: {
438
+ [EntityName in keyof E]:
439
+ EntityName extends Collections[Collection]
440
+ ? ClusteredCompositeAttributes<E, Collections, Collection, EntityName>
441
+ : never
442
+ }[keyof E];
443
+ }
444
+
445
+ export type ClusteredCollectionQueries<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends ClusteredCollectionAssociations<E>> = {
446
+ [Collection in keyof Collections as Collections[Collection] extends keyof E ? Collection : never]: {
447
+ [EntityName in keyof E]:
448
+ EntityName extends Collections[Collection]
449
+ ? (
450
+ params: ClusteredCompositeAttributes<E, Collections, Collection, EntityName>
451
+ ) =>
452
+ ClusteredCollectionOperations<E, Collections, Collection, EntityName> &
453
+ ClusteredCollectionQueryOperations<
454
+ Pick<ClusteredCompositeAttributes<E, Collections, Collection, EntityName>, OptionalPropertyOf<ClusteredCompositeAttributes<E, Collections, Collection, EntityName>>>,
455
+ ClusteredCollectionOperations<E, Collections, Collection, EntityName>
456
+ >
457
+ : never
458
+ }[keyof E];
459
+ }
460
+
461
+ export type IsolatedCollectionQueries<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends IsolatedCollectionAssociations<E>> = {
462
+ [Collection in keyof Collections]: {
463
+ [EntityName in keyof E]:
464
+ EntityName extends Collections[Collection]
465
+ ? (params:
466
+ RequiredProperties<
467
+ Parameters<
468
+ E[EntityName]["query"][
469
+ E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
470
+ ? Collection extends keyof IsolatedEntityCollections<A,F,C,S>
471
+ ? IsolatedEntityCollections<A,F,C,S>[Collection]
472
+ : never
473
+ : never
474
+ ]
475
+ >[0]
476
+ >
477
+ ) => {
478
+ go: ServiceQueryRecordsGo<{
479
+ [EntityResultName in Collections[Collection]]:
480
+ EntityResultName extends keyof E
481
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
482
+ ? ResponseItem<A,F,C,S>[]
483
+ : never
484
+ : never
485
+ }>;
486
+ params: ParamRecord;
487
+ where: {
488
+ [EntityResultName in Collections[Collection]]: EntityResultName extends keyof E
489
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
490
+ ? Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, IsolatedCollectionAttributes<E,Collections>[Collection]>> extends Partial<AllEntityAttributes<E>>
491
+ ? CollectionWhereClause<E,A,F,C,S,
492
+ Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, IsolatedCollectionAttributes<E,Collections>[Collection]>>,
493
+ ServiceWhereRecordsActionOptions<E,A,F,C,S,
494
+ Pick<AllEntityAttributes<E>, Extract<AllEntityAttributeNames<E>, IsolatedCollectionAttributes<E,Collections>[Collection]>>,
495
+ {
496
+ [EntityResultName in Collections[Collection]]:
497
+ EntityResultName extends keyof E
498
+ ? E[EntityResultName] extends Entity<infer A, infer F, infer C, infer S>
499
+ ? ResponseItem<A,F,C,S>[]
500
+ : never
501
+ : never
502
+ },
503
+ Partial<
504
+ Spread<
505
+ Collection extends keyof IsolatedCollectionPageAttributes<E, Collections>
506
+ ? IsolatedCollectionPageAttributes<E, Collections>[Collection]
507
+ : {},
508
+ Collection extends keyof IsolatedCollectionIndexAttributes<E, Collections>
509
+ ? IsolatedCollectionIndexAttributes<E, Collections>[Collection]
510
+ : {}
511
+ >
512
+ >
513
+ >>
514
+ : never
515
+ : never
516
+ : never
517
+ }[Collections[Collection]];
518
+ }
519
+ : never
520
+ }[keyof E];
521
+ }
522
+
218
523
  export type ElectroDBMethodTypes = "put" | "get" | "query" | "scan" | "update" | "delete" | "remove" | "patch" | "create" | "batchGet" | "batchWrite";
219
524
 
220
525
  export interface ElectroQueryEvent<P extends any = any> {
@@ -494,9 +799,9 @@ export interface QueryOptions {
494
799
  logger?: ElectroEventListener;
495
800
  data?: 'raw' | 'includeKeys' | 'attributes';
496
801
 
497
- /** @depricated use 'data=raw' instead */
802
+ /** @depricated use 'data=raw' instead */
498
803
  raw?: boolean;
499
- /** @depricated use 'data=includeKeys' instead */
804
+ /** @depricated use 'data=includeKeys' instead */
500
805
  includeKeys?: boolean;
501
806
  order?: 'asc' | 'desc';
502
807
  }
@@ -552,7 +857,7 @@ interface GoBatchGetTerminalOptions<Attributes> {
552
857
  raw?: boolean;
553
858
  /** @depricated use 'data=raw' instead */
554
859
  includeKeys?: boolean;
555
-
860
+
556
861
  table?: string;
557
862
  limit?: number;
558
863
  params?: object;
@@ -649,7 +954,7 @@ type GoGetTerminal<A extends string, F extends string, C extends string, S exten
649
954
 
650
955
  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) =>
651
956
  Options extends GoQueryTerminalOptions<infer Attr>
652
- ? Promise<{
957
+ ? Promise<{
653
958
  data: Array<{
654
959
  [
655
960
  Name in keyof Item as Name extends Attr
@@ -698,7 +1003,7 @@ export type BatchWriteGo<ResponseType> = <O extends BulkOptions>(options?: O) =>
698
1003
 
699
1004
  export type ParamRecord<Options = ParamOptions> = <P>(options?: Options) => P;
700
1005
 
701
- export interface ElectroError extends Error {
1006
+ export class ElectroError extends Error {
702
1007
  readonly name: 'ElectroError';
703
1008
  readonly code: number;
704
1009
  readonly date: number;
@@ -733,7 +1038,7 @@ export interface ElectroValidationErrorFieldReference<T extends Error = Error> {
733
1038
  readonly cause: T | undefined;
734
1039
  }
735
1040
 
736
- export interface ElectroValidationError<T extends Error = Error> extends ElectroError {
1041
+ export class ElectroValidationError<T extends Error = Error> extends ElectroError {
737
1042
  readonly fields: ReadonlyArray<ElectroValidationErrorFieldReference<T>>;
738
1043
  }
739
1044
 
@@ -1148,7 +1453,9 @@ type StaticAttribute = {
1148
1453
  type CustomAttribute<T extends any = any> = {
1149
1454
  readonly type: "custom";
1150
1455
  readonly [CustomAttributeSymbol]: T;
1456
+ readonly required?: boolean;
1151
1457
  readonly hidden?: boolean;
1458
+ readonly readOnly?: boolean;
1152
1459
  readonly get?: (val: T, item: any) => T | undefined | void;
1153
1460
  readonly set?: (val?: T, item?: any) => T | undefined | void;
1154
1461
  readonly default?: T | (() => T);
@@ -1212,6 +1519,7 @@ export interface Schema<A extends string, F extends string, C extends string> {
1212
1519
  readonly indexes: {
1213
1520
  [accessPattern: string]: {
1214
1521
  readonly index?: string;
1522
+ readonly type?: 'clustered' | 'isolated';
1215
1523
  readonly collection?: AccessPatternCollection<C>;
1216
1524
  readonly pk: {
1217
1525
  readonly casing?: "upper" | "lower" | "none" | "default";
@@ -1238,6 +1546,33 @@ export type IndexCollections<A extends string, F extends string, C extends strin
1238
1546
  : never
1239
1547
  }[keyof S["indexes"]];
1240
1548
 
1549
+ export type IndexCollectionsMap<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1550
+ [i in keyof S["indexes"]]: S["indexes"][i]["collection"] extends
1551
+ AccessPatternCollection<infer Name>
1552
+ ? Name
1553
+ : never
1554
+ };
1555
+
1556
+ type ClusteredIndexNameMap<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1557
+ [I in keyof S["indexes"] as S['indexes'][I] extends { type: 'clustered' } ? I : never]: S["indexes"][I]["collection"] extends
1558
+ AccessPatternCollection<infer Name>
1559
+ ? Name
1560
+ : never
1561
+ }
1562
+
1563
+ type ThingValues<T> = T[keyof T];
1564
+
1565
+ type IsolatedIndexNameMap<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1566
+ [I in keyof S["indexes"] as S['indexes'][I] extends { type: 'clustered' } ? never : I]: S["indexes"][I]["collection"] extends
1567
+ AccessPatternCollection<infer Name>
1568
+ ? Name
1569
+ : never
1570
+ }
1571
+
1572
+ export type ClusteredIndexCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ThingValues<ClusteredIndexNameMap<A,F,C,S>>;
1573
+
1574
+ export type IsolatedIndexCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = ThingValues<IsolatedIndexNameMap<A,F,C,S>>;
1575
+
1241
1576
  export type EntityCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1242
1577
  [N in IndexCollections<A,F,C,S>]: {
1243
1578
  [i in keyof S["indexes"]]: S["indexes"][i]["collection"] extends AccessPatternCollection<infer Name>
@@ -1248,6 +1583,26 @@ export type EntityCollections<A extends string, F extends string, C extends stri
1248
1583
  }[keyof S["indexes"]];
1249
1584
  }
1250
1585
 
1586
+ export type ClusteredEntityCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1587
+ [N in ClusteredIndexCollections<A,F,C,S>]: {
1588
+ [I in keyof S["indexes"]]: S["indexes"][I]["collection"] extends AccessPatternCollection<infer Name>
1589
+ ? Name extends N
1590
+ ? I
1591
+ : never
1592
+ : never
1593
+ }[keyof S["indexes"]];
1594
+ }
1595
+
1596
+ export type IsolatedEntityCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
1597
+ [N in IsolatedIndexCollections<A,F,C,S>]: {
1598
+ [I in keyof S["indexes"]]: S["indexes"][I]["collection"] extends AccessPatternCollection<infer Name>
1599
+ ? Name extends N
1600
+ ? I
1601
+ : never
1602
+ : never
1603
+ }[keyof S["indexes"]];
1604
+ }
1605
+
1251
1606
  declare const SkipSymbol: unique symbol;
1252
1607
  type SkipValue = typeof SkipSymbol;
1253
1608
 
@@ -1893,7 +2248,6 @@ export class Entity<A extends string, F extends string, C extends string, S exte
1893
2248
  data: DataUpdateMethodRecord<A,F,C,S, Item<A,F,C,S,S["attributes"]>, TableIndexCompositeAttributes<A,F,C,S>, ResponseItem<A,F,C,S>>;
1894
2249
  };
1895
2250
 
1896
-
1897
2251
  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>>;
1898
2252
 
1899
2253
  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>>;
@@ -1924,6 +2278,9 @@ export class Entity<A extends string, F extends string, C extends string, S exte
1924
2278
  }>, cursor: string | null }
1925
2279
  : { data: Array<ResponseItem<A,F,C,S>>, cursor: string | null }
1926
2280
  setIdentifier(type: "entity" | "version", value: string): void;
2281
+ setTableName(tableName: string): void;
2282
+ getTableName(): string | undefined;
2283
+ setClient(client: DocumentClient): void;
1927
2284
  client: any;
1928
2285
  }
1929
2286
 
@@ -1936,8 +2293,14 @@ export type ServiceConfiguration = {
1936
2293
 
1937
2294
  export class Service<E extends {[name: string]: Entity<any, any, any, any>}> {
1938
2295
  entities: E;
1939
- collections: CollectionQueries<E, CollectionAssociations<E>>
2296
+ collections:
2297
+ ClusteredCollectionQueries<E, ClusteredCollectionAssociations<E>>
2298
+ & IsolatedCollectionQueries<E, IsolatedCollectionAssociations<E>>
1940
2299
  constructor(entities: E, config?: ServiceConfiguration);
2300
+
2301
+ setTableName(tableName: string): void;
2302
+ getTableName(): string | undefined;
2303
+ setClient(client: DocumentClient): void;
1941
2304
  }
1942
2305
 
1943
2306
  type CustomAttributeDefinition<T> = {
package/index.js CHANGED
@@ -1,5 +1,12 @@
1
1
  const { Entity } = require("./src/entity");
2
2
  const { Service } = require("./src/service");
3
3
  const { createCustomAttribute } = require('./src/schema');
4
+ const { ElectroError, ElectroValidationError, ElectroUserValidationError, ElectroAttributeValidationError } = require('./src/errors');
4
5
 
5
- module.exports = { Entity, Service, createCustomAttribute };
6
+ module.exports = {
7
+ Entity,
8
+ Service,
9
+ createCustomAttribute,
10
+ ElectroError,
11
+ ElectroValidationError,
12
+ };