electrodb 2.1.2 → 2.2.1

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/.travis.yml CHANGED
@@ -12,4 +12,4 @@ node_js:
12
12
  - '16'
13
13
 
14
14
  script:
15
- - npm run coverage-coveralls-local
15
+ - npm run coverage:local:coveralls
package/README.md CHANGED
@@ -132,6 +132,9 @@ tasks
132
132
  - [CreatedAt and UpdatedAt Attributes](#createdat-and-updatedat-attributes)
133
133
  - [Attribute Validation](#attribute-validation)
134
134
  * [Indexes](#indexes)
135
+ + [Index Types](#index-types)
136
+ - [Isolated Indexes](#isolated-indexes)
137
+ - [Clustered Indexes](#clustered-indexes)
135
138
  + [Indexes Without Sort Keys](#indexes-without-sort-keys)
136
139
  + [Indexes With Sort Keys](#indexes-with-sort-keys)
137
140
  + [Numeric Keys](#numeric-keys)
@@ -287,7 +290,8 @@ tasks
287
290
  - [Electro CLI](#electro-cli)
288
291
  - [Version 2 Migration](#version-2-migration)
289
292
  * [New response format for all query methods.](#new-response-format-for-all-query-methods)
290
- * [Unified Pagination APIs](#unified-pagination-apis)
293
+ * [Unified pagination APIs](#unified-pagination-apis)
294
+ * [Pagination with a string cursor](#pagination-with-a-string-cursor)
291
295
  - [Version 1 Migration](#version-1-migration)
292
296
  * [New schema format/breaking key format change](#new-schema-format-breaking-key-format-change)
293
297
  * [The renaming of index property Facets to Composite and Template](#the-renaming-of-index-property-facets-to-composite-and-template)
@@ -333,7 +337,7 @@ If you're looking to get started right away with ElectroDB, checkout code exampl
333
337
 
334
338
  # Entities
335
339
 
336
- In ***ElectroDB*** an `Entity` is represents a single business object. For example, in a simple task tracking application, one Entity could represent an Employee and or a Task that is assigned to an employee.
340
+ In ***ElectroDB*** an `Entity` represents a single business object. For example, in a simple task tracking application, one Entity could represent an Employee and or a Task that is assigned to an employee.
337
341
 
338
342
  Require or import `Entity` from `electrodb`:
339
343
  ```javascript
@@ -1032,7 +1036,7 @@ signature | behavior
1032
1036
  `(value: T) => void` | A void or `undefined` value is returned, will be treated as successful, in this scenario you can throw an Error yourself to interrupt the query
1033
1037
 
1034
1038
  ## Indexes
1035
- When using ElectroDB, indexes are referenced by their `AccessPatternName`. This allows you to maintain generic index names on your DynamoDB table, but reference domain specific names while using your ElectroDB Entity. These will often be referenced as _"Access Patterns"_.
1039
+ When using ElectroDB, indexes are referenced by their `AccessPatternName`. This allows you to maintain generic index names on your DynamoDB table, but reference domain specific names while using your ElectroDB Entity. These will be referenced as _"Access Patterns"_.
1036
1040
 
1037
1041
  All DynamoDB table start with at least a PartitionKey with an optional SortKey, this can be referred to as the _"Table Index"_. The `indexes` object requires at least the definition of this _Table Index_ **Partition Key** and (if applicable) **Sort Key**.
1038
1042
 
@@ -1045,8 +1049,11 @@ Within these _AccessPatterns_, you define the PartitionKey and (optionally) Sort
1045
1049
  ```typescript
1046
1050
  indexes: {
1047
1051
  [AccessPatternName]: {
1052
+ index?: string;
1053
+ collection?: string | string[];
1054
+ type?: 'isolated' | 'clustered';
1048
1055
  pk: {
1049
- field: string;
1056
+ field: string;
1050
1057
  composite: AttributeName[];
1051
1058
  template?: string;
1052
1059
  },
@@ -1055,14 +1062,15 @@ indexes: {
1055
1062
  composite: AttributesName[];
1056
1063
  template?: string;
1057
1064
  },
1058
- index?: string
1059
- collection?: string | string[]
1060
1065
  }
1061
1066
  }
1062
1067
  ```
1063
1068
 
1064
1069
  | Property | Type | Required | Description |
1065
1070
  | -------------- | :------------------------------------: | :------: | ----------- |
1071
+ | `index` | `string` | no | Required when the `Index` defined is a *Global/Local Secondary Index*; but is omitted for the table's primary index.
1072
+ | `collection` | `string`, `string[]` | no | Used when models are joined to a `Service`. When two entities share a `collection` on the same `index`, they can be queried with one request to DynamoDB. The name of the collection should represent what the query would return as a pseudo `Entity`. (see [Collections](#collections) below for more on this functionality).
1073
+ | `type` | `isolated`, `clustered` | no | Allows you to optimize your index for either [entity isolation](#isolated-indexes) (high volume of records per partition) or (entity relationships)[#clustered-indexes] (high relationship density per partition). When omitted, ElectroDB defaults to `isolation`.
1066
1074
  | `pk` | `object` | yes | Configuration for the pk of that index or table
1067
1075
  | `pk.composite` | `string[]` | yes | An array that represents the order in which attributes are concatenated to composite attributes the key (see [Composite Attributes](#composite-attributes) below for more on this functionality).
1068
1076
  | `pk.template` | `string` | no | A string that represents the template in which attributes composed to form a key (see [Composite Attribute Templates](#composite-attribute-templates) below for more on this functionality).
@@ -1073,8 +1081,26 @@ indexes: {
1073
1081
  | `sk.template` | `string` | no | A string that represents the template in which attributes composed to form a key (see [Composite Attribute Templates](#composite-attribute-templates) below for more on this functionality).
1074
1082
  | `sk.field` | `string` | yes | The name of the index Sort Key field as it exists in DynamoDB, if named differently in the schema attributes.
1075
1083
  | `pk.casing` | `default`, `upper`, `lower`, `none`, | no | Choose a case for ElectroDB to convert your keys to, to avoid casing pitfalls when querying data. Default: `lower`.
1076
- | `index` | `string` | no | Required when the `Index` defined is a *Global/Local Secondary Index*; but is omitted for the table's primary index.
1077
- | `collection` | `string`, `string[]` | no | Used when models are joined to a `Service`. When two entities share a `collection` on the same `index`, they can be queried with one request to DynamoDB. The name of the collection should represent what the query would return as a pseudo `Entity`. (see [Collections](#collections) below for more on this functionality).
1084
+
1085
+
1086
+ ### Index Types
1087
+ ElectroDB helps manage your key structure, and works to abstract out the details of how your keys are created/formatted. Depending on your unique data set, you may need ElectroDB to optimize your index for either [entity isolation](#isolated-indexes) (i.e. high volume of records per partition) or (entity relationships)[#clustered-indexes] (i.e. high relationship density per partition).
1088
+
1089
+ This option changes how ElectroDB formats your keys for storage, so it is an important consideration to make early in your modeling phase. As a result, this choice cannot be simply walked back without requiring a migration. The choice between `clustered` and `isolated` depends wholly on your unique dataset and access patterns.
1090
+
1091
+ > _NOTE: You can use [Collections](#collections) with both `isolated` and `clustered` indexes. Isolated indexes are limited to only querying across the partition key while Clustered indexes can also leverage the Sort Key_
1092
+
1093
+ #### Isolated Indexes
1094
+ By default, and when omitted, ElectroDB will create your index as an `isolated` index. Isolated indexes optimizes your index structure for faster and more efficient retrieval of items within an individual Entity.
1095
+
1096
+ *Choose* `isolated` if you have strong access pattern requirements to retrieve only records for only your entity on that index. While an `isolated` index is more limited in its ability to be used in a [collection](#collections), it can perform better than a `clustered` index if a collection contains a highly unequal distribution of entities within a collection.
1097
+ *Don't choose* `isolated` if the primary use-cases for your index is to query across entities -- this index type does limit the extent to which indexes can be leveraged to improve query efficiency.
1098
+
1099
+ #### Clustered Indexes
1100
+ When your index type is defined as `clustered`, ElectroDB will optimize your index for relationships within a partition. Clustered indexes optimize your index structure for more homogenous partitions, which allows for more efficient queries across multiple entities.
1101
+
1102
+ *Choose* `clustered` if you have a high degree of grouped or similar data that needs to be frequently accessed together. This index works best in [collections](#collections) when member entities are more evenly distributed within a partition.
1103
+ *Don't choose* `clustered` if your need to query across entities is secondary to its primary purpose -- this index type limits the efficiency of querying your individual entity.
1078
1104
 
1079
1105
  ### Indexes Without Sort Keys
1080
1106
  When using indexes without Sort Keys, that should be expressed as an index *without* an `sk` property at all. Indexes without an `sk` cannot have a collection, see [Collections](#collections) for more detail.
@@ -1661,7 +1687,7 @@ await TaskApp.collections
1661
1687
 
1662
1688
  ### Collection Queries vs Entity Queries
1663
1689
 
1664
- To query across entities, collection queries make use of ElectroDB's Sort Key structure, which prefixes Sort Key fields with the collection name. Unlike an Entity Query, Collection Queries only leverage [Composite Attributes](#composite-attributes) from an access pattern's Partition Key.
1690
+ To query across entities, collection queries make use of ElectroDB's Sort Key structure, which prefixes Sort Key fields with the collection name. Unlike an Entity Query, Collection queries for [isolated indexes](#isolated-indexes) only leverage [Composite Attributes](#composite-attributes) from an access pattern's Partition Key, while Collection queries for [clustered indexes](#clustered-indexes) allow you to query on both Partition and Sort Keys.
1665
1691
 
1666
1692
  To better explain how Collection Queries are formed, here is a juxtaposition of an Entity Query's parameters vs a Collection Query's parameters:
1667
1693
 
@@ -1740,7 +1766,9 @@ Because the Tasks and Employee Entities both associated their index (`gsi2`) wit
1740
1766
 
1741
1767
  ## Sub-Collections
1742
1768
 
1743
- Sub-Collections are an extension of [Collection](#collections) functionality that allow you to model more advanced access patterns. Collections and Sub-Collections are defined on [Indexes](#indexes) via a property called `collection`, as either a string or string array respectively.
1769
+ Sub-Collections are an extension of [Collection](#collections) functionality that allow you to model more advanced access patterns. Collections and Sub-Collections are defined on [Indexes](#indexes) via a property called `collection`, as either a string or string array respectively.
1770
+
1771
+ > _NOTE: Sub-Collections are only supported on ["isolated" index](#isolated-indexes) types _
1744
1772
 
1745
1773
  The following is an example of functionally identical collections, implemented as a string (referred to as a "collection") and then as a string array (referred to as sub-collections):
1746
1774
 
@@ -3624,7 +3652,7 @@ Equivalent DocClient Parameters:
3624
3652
  ### Patch Record
3625
3653
 
3626
3654
  ```javascript
3627
- await entity.update({ attr1: "value1", attr2: "value2" })
3655
+ await entity.patch({ attr1: "value1", attr2: "value2" })
3628
3656
  .set({ attr4: "value4" })
3629
3657
  .go();
3630
3658
  ```
@@ -3668,7 +3696,7 @@ For more detail on how to use the `patch()` method, see the section [Update Reco
3668
3696
 
3669
3697
  ### Create Record
3670
3698
 
3671
- In DynamoDB, `put` operations by default will overwrite a record if record being updated does not exist. In **_ElectroDB_**, the `patch` method will utilize the `attribute_not_exists()` parameter dynamically to ensure records are only "created" and not overwritten when inserting new records into the table.
3699
+ In DynamoDB, `put` operations by default will overwrite a record if record being updated does not exist. In **_ElectroDB_**, the `create` method will utilize the `attribute_not_exists()` parameter dynamically to ensure records are only "created" and not overwritten when inserting new records into the table.
3672
3700
 
3673
3701
  A Put operation will trigger the `default`, and `set` attribute callbacks when writing to DynamoDB. By default, after writing to DynamoDB, ElectroDB will format and return the record through the same process as a Get/Query, which will invoke the `get` callback on all included attributes. If this behaviour is not desired, use the [Query Option](#query-options) `response:"none"` to return a null value.
3674
3702
 
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
@@ -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> = {