@karmaniverous/entity-manager 6.7.5 → 6.8.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/dist/cjs/BaseEntityClient.js +1 -1
- package/dist/cjs/BaseQueryBuilder.js +1 -1
- package/dist/cjs/EntityManager.js +8 -8
- package/dist/cjs/ParsedConfig.js +143 -113
- package/dist/cjs/addKeys.js +6 -6
- package/dist/{mjs/decodeEntityElement.js → cjs/decodeElement.js} +10 -12
- package/dist/cjs/decodeGeneratedProperty.js +6 -10
- package/dist/cjs/dehydrateIndexItem.js +12 -11
- package/dist/cjs/dehydratePageKeyMap.js +10 -7
- package/dist/{mjs/encodeEntityElement.js → cjs/encodeElement.js} +8 -10
- package/dist/cjs/encodeGeneratedProperty.js +13 -14
- package/dist/cjs/getHashKeySpace.js +6 -6
- package/dist/cjs/getIndexComponents.js +6 -8
- package/dist/cjs/getShardBump.js +1 -1
- package/dist/cjs/query.js +1 -1
- package/dist/cjs/rehydrateIndexItem.js +12 -10
- package/dist/cjs/rehydratePageKeyMap.js +18 -11
- package/dist/cjs/removeKeys.js +3 -2
- package/dist/cjs/unwrapIndex.js +25 -11
- package/dist/cjs/updateItemHashKey.js +5 -3
- package/dist/cjs/updateItemRangeKey.js +6 -4
- package/dist/cjs/validateGeneratedProperty.js +23 -0
- package/dist/cjs/validateIndexToken.js +16 -0
- package/dist/cjs/validateTranscodedProperty.js +16 -0
- package/dist/index.d.ts +176 -529
- package/dist/mjs/BaseEntityClient.js +1 -1
- package/dist/mjs/BaseQueryBuilder.js +1 -1
- package/dist/mjs/EntityManager.js +8 -8
- package/dist/mjs/ParsedConfig.js +143 -113
- package/dist/mjs/addKeys.js +6 -6
- package/dist/{cjs/decodeEntityElement.js → mjs/decodeElement.js} +8 -14
- package/dist/mjs/decodeGeneratedProperty.js +6 -10
- package/dist/mjs/dehydrateIndexItem.js +12 -11
- package/dist/mjs/dehydratePageKeyMap.js +10 -7
- package/dist/{cjs/encodeEntityElement.js → mjs/encodeElement.js} +7 -13
- package/dist/mjs/encodeGeneratedProperty.js +13 -14
- package/dist/mjs/getHashKeySpace.js +6 -6
- package/dist/mjs/getIndexComponents.js +6 -8
- package/dist/mjs/getShardBump.js +1 -1
- package/dist/mjs/query.js +1 -1
- package/dist/mjs/rehydrateIndexItem.js +12 -10
- package/dist/mjs/rehydratePageKeyMap.js +18 -11
- package/dist/mjs/removeKeys.js +3 -2
- package/dist/mjs/unwrapIndex.js +26 -12
- package/dist/mjs/updateItemHashKey.js +5 -3
- package/dist/mjs/updateItemRangeKey.js +6 -4
- package/dist/mjs/validateGeneratedProperty.js +21 -0
- package/dist/mjs/validateIndexToken.js +14 -0
- package/dist/mjs/validateTranscodedProperty.js +14 -0
- package/package.json +5 -5
- package/dist/cjs/validateEntityGeneratedProperty.js +0 -29
- package/dist/cjs/validateEntityIndexToken.js +0 -22
- package/dist/mjs/validateEntityGeneratedProperty.js +0 -27
- package/dist/mjs/validateEntityIndexToken.js +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { EntityMap, TranscodeMap, FlattenEntityMap, Exactify, PropertiesOfType, TranscodableProperties, Transcodes, SortOrder } from '@karmaniverous/entity-tools';
|
|
1
2
|
import { BatchProcessOptions } from '@karmaniverous/batch-process';
|
|
2
|
-
import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodableProperties, Transcodes, DefaultTranscodeMap, SortOrder } from '@karmaniverous/entity-tools';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
interface BaseConfigMap {
|
|
6
|
+
EntityMap: EntityMap;
|
|
7
|
+
HashKey: string;
|
|
8
|
+
RangeKey: string;
|
|
9
|
+
ShardedKeys: string;
|
|
10
|
+
UnshardedKeys: string;
|
|
11
|
+
TranscodedProperties: string;
|
|
12
|
+
TranscodeMap: TranscodeMap;
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
/**
|
|
6
16
|
* Base EntityClient options.
|
|
7
17
|
*
|
|
@@ -25,52 +35,49 @@ declare abstract class BaseEntityClient {
|
|
|
25
35
|
/**
|
|
26
36
|
* DynamoDB EntityClient constructor.
|
|
27
37
|
*
|
|
28
|
-
* @param options - {@link
|
|
38
|
+
* @param options - {@link BaseEntityClientOptions | `BaseEntityClientOptions`} object.
|
|
29
39
|
*/
|
|
30
40
|
constructor(options: BaseEntityClientOptions);
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
/**
|
|
34
|
-
*
|
|
44
|
+
* Extracts a database-facing partial item type from a {@link BaseConfigMap | `ConfigMap`}.
|
|
35
45
|
*
|
|
36
46
|
* @category Entities
|
|
37
47
|
*/
|
|
38
|
-
type
|
|
48
|
+
type EntityItem<C extends BaseConfigMap> = Partial<FlattenEntityMap<C['EntityMap']> & Record<C['HashKey'] | C['RangeKey'] | C['ShardedKeys'] | C['UnshardedKeys'], string>> & Record<string, unknown>;
|
|
49
|
+
|
|
39
50
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* @typeParam K - The string literal type to test.
|
|
43
|
-
* @typeParam M - The {@link EntityMap | `EntityMap`}.
|
|
44
|
-
* @typeParam R - The reserved set of string literal types.
|
|
45
|
-
*
|
|
46
|
-
* @returns `K` if `K` is exclusive or `never` otherwise.
|
|
51
|
+
* A result returned by a query across multiple shards, where each shard may
|
|
52
|
+
* receive multiple page queries via a dynamically-generated {@link ShardQueryFunction | `ShardQueryFunction`}.
|
|
47
53
|
*
|
|
48
|
-
* @category
|
|
49
|
-
* @protected
|
|
54
|
+
* @category Query
|
|
50
55
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
interface QueryResult<C extends BaseConfigMap> {
|
|
57
|
+
/** Total number of records returned across all shards. */
|
|
58
|
+
count: number;
|
|
59
|
+
/** The returned records. */
|
|
60
|
+
items: EntityItem<C>[];
|
|
61
|
+
/**
|
|
62
|
+
* A compressed, two-layer map of page keys, used to query the next page of
|
|
63
|
+
* data for a given sort key on each shard of a given hash key.
|
|
64
|
+
*/
|
|
65
|
+
pageKeyMap: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
54
68
|
/**
|
|
55
|
-
*
|
|
69
|
+
* Return a type with required property K of type O if C is not `never`, otherwise return a type where K is optional or accepts an empty object.
|
|
56
70
|
*
|
|
57
|
-
* @typeParam
|
|
58
|
-
* @typeParam
|
|
59
|
-
* @typeParam
|
|
60
|
-
*
|
|
61
|
-
* @remarks
|
|
62
|
-
* All Entity properties of type `never` must be represented, and no extra properties are allowed.
|
|
63
|
-
*
|
|
64
|
-
* @category Config
|
|
65
|
-
* @protected
|
|
71
|
+
* @typeParam K - The property key.
|
|
72
|
+
* @typeParam C - The condition to check.
|
|
73
|
+
* @typeParam O - The type of the property.
|
|
66
74
|
*/
|
|
67
|
-
type
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}>) | ([PropertiesOfType<M[EntityToken], never>] extends [never] ? Record<string, never> : never);
|
|
75
|
+
type ConditionalProperty<K extends PropertyKey, C, O extends object> = [
|
|
76
|
+
C
|
|
77
|
+
] extends [never] ? Record<K, never> | Partial<Record<K, Record<PropertyKey, never>>> : Record<K, O>;
|
|
78
|
+
|
|
72
79
|
/**
|
|
73
|
-
* Defines a single time period in an
|
|
80
|
+
* Defines a single time period in an entity sharding strategy.
|
|
74
81
|
*
|
|
75
82
|
* @category Config
|
|
76
83
|
* @protected
|
|
@@ -79,7 +86,7 @@ interface ShardBump {
|
|
|
79
86
|
/**
|
|
80
87
|
* The timestamp marking the beginning of the time period. Must be a non-negative integer.
|
|
81
88
|
*
|
|
82
|
-
* This value must be unique across all {@link ShardBump | `ShardBumps`} for the
|
|
89
|
+
* This value must be unique across all {@link ShardBump | `ShardBumps`} for the entity.
|
|
83
90
|
*/
|
|
84
91
|
timestamp: number;
|
|
85
92
|
/**
|
|
@@ -96,351 +103,37 @@ interface ShardBump {
|
|
|
96
103
|
*/
|
|
97
104
|
chars: number;
|
|
98
105
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns a Config entity index component type.
|
|
101
|
-
*
|
|
102
|
-
* @typeParam EntityToken - The {@link Entity | `Entity`} token.
|
|
103
|
-
* @typeParam M - The {@link EntityMap | `EntityMap`}.
|
|
104
|
-
* @typeParam HashKey - The property used across the configuration to store an {@link Entity | `Entity`}'s sharded hash key. Should be configured as the table hash key. Must not conflict with any {@link Entity | `Entity`} property.
|
|
105
|
-
* @typeParam RangeKey - The property used across the configuration to store an {@link Entity | `Entity`}'s range key. Should be configured as the table range key. Must not conflict with any {@link Entity | `Entity`} property.
|
|
106
|
-
* @typeParam T - The {@link TranscodeMap | `TranscodeMap`} identifying transcodable property types. Only {@link Entity | `Entity`} properties of these types can be components of an {@link ConfigEntity.indexes | index} or a {@link ConfigEntityGenerated | generated property}.
|
|
107
|
-
|
|
108
|
-
* @category Config
|
|
109
|
-
* @protected
|
|
110
|
-
*/
|
|
111
|
-
type ConfigEntityIndexComponent<EntityToken extends keyof Exactify<M>, M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> = TranscodableProperties<M[EntityToken], T> | PropertiesOfType<M[EntityToken], never> | HashKey | RangeKey;
|
|
112
|
-
/**
|
|
113
|
-
* Returns a Config entity type.
|
|
114
|
-
*
|
|
115
|
-
* @typeParam EntityToken - The {@link Entity | `Entity`} token.
|
|
116
|
-
* @typeParam M - The {@link EntityMap | `EntityMap`}.
|
|
117
|
-
* @typeParam HashKey - The property used across the configuration to store an {@link Entity | `Entity`}'s sharded hash key. Should be configured as the table hash key. Must not conflict with any {@link Entity | `Entity`} property.
|
|
118
|
-
* @typeParam RangeKey - The property used across the configuration to store an {@link Entity | `Entity`}'s range key. Should be configured as the table range key. Must not conflict with any {@link Entity | `Entity`} property.
|
|
119
|
-
* @typeParam T - The {@link TranscodeMap | `TranscodeMap`} identifying transcodable property types. Only {@link Entity | `Entity`} properties of these types can be components of an {@link ConfigEntity.indexes | index} or a {@link ConfigEntityGenerated | generated property}.
|
|
120
|
-
|
|
121
|
-
* @remarks
|
|
122
|
-
* `generated` is optional if `E` has no properties of type `never`.
|
|
123
|
-
*
|
|
124
|
-
* @category Config
|
|
125
|
-
* @protected
|
|
126
|
-
*/
|
|
127
|
-
type ConfigEntity<EntityToken extends keyof Exactify<M>, M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> = {
|
|
128
|
-
/**
|
|
129
|
-
* The default maximum number of records to return from a query.
|
|
130
|
-
*
|
|
131
|
-
* @defaultValue `10`
|
|
132
|
-
*
|
|
133
|
-
* @remarks
|
|
134
|
-
* Can be overridden at {@link QueryOptions.limit | `QueryOptions.limit`}.
|
|
135
|
-
*
|
|
136
|
-
* In cross-shard queries, the actual number of records returned is heavily influenced by {@link QueryOptions.pageSize | query pageSize} and the number of shards queried. Actual results may significantly exceed this limit.
|
|
137
|
-
*/
|
|
138
|
-
defaultLimit?: number;
|
|
139
|
-
/**
|
|
140
|
-
* The default maximum number of records to return per data page on an individual shard query.
|
|
141
|
-
*
|
|
142
|
-
* @defaultValue `10`
|
|
143
|
-
*
|
|
144
|
-
* @remarks
|
|
145
|
-
* Shard queries will be repeated internally until either the shard is exhausted or the number of records returned exceeds the {@link QueryOptions.limit | query limit}.
|
|
146
|
-
*
|
|
147
|
-
* Can be overridden at {@link QueryOptions.pageSize | `QueryOptions.pageSize`}.
|
|
148
|
-
*/
|
|
149
|
-
defaultPageSize?: number;
|
|
150
|
-
/**
|
|
151
|
-
* This object assigns transcodes to {@link Entity | `Entity`} generated property & ungenerated index elements.
|
|
152
|
-
*
|
|
153
|
-
* These transcodes are used to encode and decode generated property values & pageKeys.
|
|
154
|
-
*
|
|
155
|
-
* The keys of this object must be transcodable properties of the {@link Entity | `Entity`}.
|
|
156
|
-
*
|
|
157
|
-
* The values of this object must be one of the keys of the {@link Config | `Config`} `T` type parameter (the config's {@link TranscodeMap | `TranscodeMap`}).
|
|
158
|
-
*
|
|
159
|
-
* The types of the related {@link Entity | `Entity`} and {@link TranscodeMap | `TranscodeMap`} properties should match.
|
|
160
|
-
*
|
|
161
|
-
* If any entity generated property element or ungenerated index element is not included here, the {@link Config | `Config`} object will fail to parse.
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```
|
|
165
|
-
* // Default transcodable types.
|
|
166
|
-
* interface DefaultTranscodeMap extends TranscodeMap {
|
|
167
|
-
* string: string;
|
|
168
|
-
* number: number;
|
|
169
|
-
* boolean: boolean;
|
|
170
|
-
* bigint: bigint;
|
|
171
|
-
* }
|
|
172
|
-
*
|
|
173
|
-
* interface MyEntityMap extends EntityMap {
|
|
174
|
-
* user: {
|
|
175
|
-
* created: number;
|
|
176
|
-
* data?: Json; // Not a Stringifiable type
|
|
177
|
-
* userId: string;
|
|
178
|
-
* };
|
|
179
|
-
* }
|
|
180
|
-
*
|
|
181
|
-
* // T type param defaults to DefaultTranscodeMap.
|
|
182
|
-
* const config: Config<MyEntityMap> = {
|
|
183
|
-
* entities: {
|
|
184
|
-
* user: {
|
|
185
|
-
* ...,
|
|
186
|
-
* types: { // All Stringafiable properties required!
|
|
187
|
-
* created: 'number',
|
|
188
|
-
* userId: 'string',
|
|
189
|
-
* // 'data' not allowed: not a Stringifiable type
|
|
190
|
-
* }
|
|
191
|
-
* }
|
|
192
|
-
* },
|
|
193
|
-
* ...
|
|
194
|
-
* };
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
elementTranscodes?: ([TranscodableProperties<M[EntityToken], T>] extends [never] ? never : {
|
|
198
|
-
[P in TranscodableProperties<M[EntityToken], T>]?: PropertiesOfType<T, M[EntityToken][P]>;
|
|
199
|
-
}) | ([TranscodableProperties<M[EntityToken], T>] extends [never] ? Record<string, never> : never);
|
|
200
|
-
/**
|
|
201
|
-
* Indexes defined for the {@link Entity | `Entity`}. Should reflect the underlying database table indexes.
|
|
202
|
-
*
|
|
203
|
-
* Each key is the name of an index, and each value defines the hash key, range key, and projected properties of the index.
|
|
204
|
-
*
|
|
205
|
-
* hashKey and rangeKey types must align with the {@link Config | `Config`} `T` type parameter. Note that all {@link ConfigEntityGenerated | generated property} types are transcodable by definition.
|
|
206
|
-
*/
|
|
207
|
-
indexes?: Record<string, {
|
|
208
|
-
hashKey: ConfigEntityIndexComponent<EntityToken, M, HashKey, RangeKey, T>;
|
|
209
|
-
rangeKey: ConfigEntityIndexComponent<EntityToken, M, HashKey, RangeKey, T>;
|
|
210
|
-
projections?: (keyof M[EntityToken])[];
|
|
211
|
-
}>;
|
|
212
|
-
/**
|
|
213
|
-
* An array of {@link ShardBump | `ShardBump`} objects representing the {@link Entity | `Entity`}'s sharding strategy.
|
|
214
|
-
*
|
|
215
|
-
* If omitted, or if configured without a zero-{@link ShardBump.timestamp | `timestamp`} {@link ShardBump | `ShardBump`}, this array will be initialized with the following {@link ShardBump | `ShardBump`} as its first member:
|
|
216
|
-
*
|
|
217
|
-
* ```
|
|
218
|
-
* { timestamp: 0, charBits: 0, chars: 1 }
|
|
219
|
-
* ```
|
|
220
|
-
*
|
|
221
|
-
* Members must be unique by {@link ShardBump.timestamp | `timestamp`}.
|
|
222
|
-
*
|
|
223
|
-
* {@link ShardBump.chars | `chars`} must increase monotonically with {@link ShardBump.timestamp | `timestamp`}
|
|
224
|
-
*
|
|
225
|
-
* Array will be sorted in ascending order by {@link ShardBump.timestamp | `timestamp`} on initialization.
|
|
226
|
-
*
|
|
227
|
-
* Future {@link ShardBump | `ShardBumps`} can be changed as required, but past {@link ShardBump | `ShardBumps`} should not be modified or data integrity will be compromised!
|
|
228
|
-
*/
|
|
229
|
-
shardBumps?: ShardBump[];
|
|
230
|
-
/**
|
|
231
|
-
* Identifies the {@link Entity | `Entity`} property used as the timestamp for shard key calculations.
|
|
232
|
-
*
|
|
233
|
-
* This property must be of type `number`. Its value should not change over the life of the record. A `created` timestamp is ideal.
|
|
234
|
-
*
|
|
235
|
-
* Once in production, this configuration property should not be changed or data integrity will be compromised!
|
|
236
|
-
*/
|
|
237
|
-
timestampProperty: PropertiesOfType<M[EntityToken], number>;
|
|
238
|
-
/**
|
|
239
|
-
* Identifies the {@link Entity | `Entity`} used as the basis for both shard key calculations and the table's {@link ConfigKeys.rangeKey | range key}.
|
|
240
|
-
*
|
|
241
|
-
* This property must be of type `string` or `number`. Its value should be a unique record identifier and should not change over the life of the record.
|
|
242
|
-
*
|
|
243
|
-
* Once in production, this configuration property should not be changed or data integrity will be compromised!
|
|
244
|
-
*/
|
|
245
|
-
uniqueProperty: PropertiesOfType<M[EntityToken], number | string>;
|
|
246
|
-
} & ([PropertiesOfType<M[EntityToken], never>] extends [never] ? {
|
|
247
|
-
generated?: ConfigEntityGenerated<EntityToken, M, T>;
|
|
248
|
-
} : {
|
|
249
|
-
/**
|
|
250
|
-
* {@link Entity | `Entity`} properties whose values will be generated by EntityManager.
|
|
251
|
-
*
|
|
252
|
-
* These properties should be indicated by a `never` type in the {@link Config | `Config`} `EntityMap` type parameter.
|
|
253
|
-
*
|
|
254
|
-
* All such properties must be accounted for in the `generated` object, and no additional properties are permitted..
|
|
255
|
-
*/
|
|
256
|
-
generated: ConfigEntityGenerated<EntityToken, M, T>;
|
|
257
|
-
});
|
|
258
|
-
/**
|
|
259
|
-
* Returns the `entities` property of the {@link Config | `Config`} tyoe.
|
|
260
|
-
*
|
|
261
|
-
* @typeParam M - The {@link EntityMap | `EntityMap`} type that identitfies the {@link Entity | `Entity`} & related property types to be managed by EntityManager.
|
|
262
|
-
* @typeParam HashKey - The property used across the configuration to store an {@link Entity | `Entity`}'s sharded hash key. Should be configured as the table hash key. Must not conflict with any {@link Entity | `Entity`} property.
|
|
263
|
-
* @typeParam RangeKey - The property used across the configuration to store an {@link Entity | `Entity`}'s range key. Should be configured as the table range key. Must not conflict with any {@link Entity | `Entity`} property.
|
|
264
|
-
* @typeParam T - The {@link TranscodeMap | `TranscodeMap`} identifying transcodable property types. Only {@link Entity | `Entity`} properties of these types can be components of an {@link ConfigEntity.indexes | index} or a {@link ConfigEntityGenerated | generated property}.
|
|
265
|
-
*
|
|
266
|
-
* @remarks
|
|
267
|
-
* All properties of `M` must be represented, and no extra properties are allowed.
|
|
268
|
-
*
|
|
269
|
-
* @category Config
|
|
270
|
-
* @protected
|
|
271
|
-
*/
|
|
272
|
-
type ConfigEntities<M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> = ([keyof Exactify<M>] extends [never] ? never : {
|
|
273
|
-
[E in keyof Exactify<M>]: ConfigEntity<E, M, HashKey, RangeKey, T>;
|
|
274
|
-
}) | Record<string, never>;
|
|
275
|
-
/**
|
|
276
|
-
* Returns variably-optional properties of the {@link Config | `Config`} type as optional.
|
|
277
106
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
*
|
|
290
|
-
* The properties of this object must exactly match the keys of the {@link Config | `Config`} `EntityMap` type parameter.
|
|
291
|
-
*/
|
|
292
|
-
entities?: ConfigEntities<M, HashKey, RangeKey, T>;
|
|
293
|
-
/**
|
|
294
|
-
* The property used across the configuration to store an {@link Entity | `Entity`}'s sharded hash key. Should be configured as the table hash key.
|
|
295
|
-
*
|
|
296
|
-
* This value must exactly match the {@link Config | `Config`} `HashKey` type parameter, and must not conflict with any {@link Entity | `Entity`} property.
|
|
297
|
-
*
|
|
298
|
-
* @defaultValue `'hashKey'`
|
|
299
|
-
*
|
|
300
|
-
* @category Config
|
|
301
|
-
* @protected
|
|
302
|
-
*/
|
|
303
|
-
hashKey?: ExclusiveKey<HashKey, M, RangeKey>;
|
|
304
|
-
/**
|
|
305
|
-
* The property used across the configuration to store an {@link Entity | `Entity`}'s range key. Should be configured as the table range key.
|
|
306
|
-
*
|
|
307
|
-
* This value must exactly match the {@link Config | `Config`} `RangeKey` type parameter, and must not conflict with any {@link Entity | `Entity`} property.
|
|
308
|
-
*
|
|
309
|
-
* @defaultValue `'rangeKey'`
|
|
310
|
-
*/
|
|
311
|
-
rangeKey?: ExclusiveKey<RangeKey, M, HashKey>;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* @category Config
|
|
315
|
-
* @protected
|
|
316
|
-
*/
|
|
317
|
-
type ConfigTranscodes<T extends TranscodeMap> = ([keyof Exactify<T>] extends [never] ? never : Transcodes<T>) | ([keyof Exactify<T>] extends [never] ? Record<string, never> : never);
|
|
318
|
-
/**
|
|
319
|
-
* EntityManager Config type.
|
|
320
|
-
*
|
|
321
|
-
* @typeParam M - The {@link EntityMap | `EntityMap`} type that identitfies the {@link Entity | `Entity`} & related property types to be managed by EntityManager.
|
|
322
|
-
* @typeParam HashKey - The property used across the configuration to store an {@link Entity | `Entity`}'s sharded hash key. Should be configured as the table hash key. Must not conflict with any {@link Entity | `Entity`} property. Defaults to `'hashKey'`.
|
|
323
|
-
* @typeParam RangeKey - The property used across the configuration to store an {@link Entity | `Entity`}'s range key. Should be configured as the table range key. Must not conflict with any {@link Entity | `Entity`} property. Defaults to `'rangeKey'`.
|
|
324
|
-
* @typeParam T - The {@link TranscodeMap | `TranscodeMap`} identifying transcodable property types. Only {@link Entity | `Entity`} properties of these types can be components of an {@link ConfigEntity.indexes | index} or a {@link ConfigEntityGenerated | generated property}. Defaults to {@link DefaultTranscodeMap | `DefaultTranscodeMap`}.
|
|
325
|
-
*
|
|
326
|
-
* @remarks
|
|
327
|
-
* `entities` is optional if `M` is empty.
|
|
328
|
-
*
|
|
329
|
-
* @category Config
|
|
330
|
-
*/
|
|
331
|
-
type Config<M extends EntityMap = Record<string, never>, HashKey extends string = 'hashKey', RangeKey extends string = 'rangeKey', T extends TranscodeMap = DefaultTranscodeMap> = ([keyof Exactify<M>] extends [never] ? ConfigKeys<M, HashKey, RangeKey, T> : Required<ConfigKeys<M, HashKey, RangeKey, T>>) & {
|
|
332
|
-
/**
|
|
333
|
-
* Defines the delimiter used to separate key-value pairs in a generated property value.
|
|
334
|
-
*
|
|
335
|
-
* Must consist of one or more non-word characters, and must not intersect with {@link Config.generatedValueDelimiter | `generatedValueDelimiter`} or {@link Config.shardKeyDelimiter | `shardKeyDelimiter`}.
|
|
336
|
-
*
|
|
337
|
-
* @defaultValue `'|'`
|
|
338
|
-
*/
|
|
107
|
+
type Config<C extends BaseConfigMap> = ConditionalProperty<'entities', keyof Exactify<C['EntityMap']>, {
|
|
108
|
+
[E in keyof Exactify<C['EntityMap']>]: {
|
|
109
|
+
defaultLimit?: number;
|
|
110
|
+
defaultPageSize?: number;
|
|
111
|
+
shardBumps?: ShardBump[];
|
|
112
|
+
timestampProperty: C['TranscodedProperties'] & PropertiesOfType<C['EntityMap'][E], number> & TranscodableProperties<C['EntityMap'], C['TranscodeMap']>;
|
|
113
|
+
uniqueProperty: C['TranscodedProperties'] & keyof C['EntityMap'][E] & TranscodableProperties<C['EntityMap'], C['TranscodeMap']>;
|
|
114
|
+
};
|
|
115
|
+
}> & ConditionalProperty<'generatedProperties', C['ShardedKeys'] | C['UnshardedKeys'], ConditionalProperty<'sharded', C['ShardedKeys'], Record<C['ShardedKeys'], (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeMap']>)[]>> & ConditionalProperty<'unsharded', C['UnshardedKeys'], Record<C['UnshardedKeys'], (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeMap']>)[]>>> & ConditionalProperty<'propertyTranscodes', C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeMap']>, {
|
|
116
|
+
[P in C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeMap']>]: PropertiesOfType<C['TranscodeMap'], FlattenEntityMap<C['EntityMap']>[P]>;
|
|
117
|
+
}> & ConditionalProperty<'transcodes', keyof C['TranscodeMap'], Transcodes<C['TranscodeMap']>> & {
|
|
339
118
|
generatedKeyDelimiter?: string;
|
|
340
|
-
/**
|
|
341
|
-
* Defines the delimiter used to separate keys & values in a generated property value.
|
|
342
|
-
*
|
|
343
|
-
* Must consist of one or more non-word characters, and must not intersect with {@link Config.generatedKeyDelimiter | `generatedKeyDelimiter`} or {@link Config.shardKeyDelimiter | `shardKeyDelimiter`}.
|
|
344
|
-
*
|
|
345
|
-
* @defaultValue `'#'`
|
|
346
|
-
*/
|
|
347
119
|
generatedValueDelimiter?: string;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
120
|
+
hashKey: C['HashKey'];
|
|
121
|
+
indexes?: Record<string, {
|
|
122
|
+
hashKey: C['HashKey'] | C['ShardedKeys'];
|
|
123
|
+
rangeKey: C['RangeKey'] | C['UnshardedKeys'] | (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeMap']>);
|
|
124
|
+
projections?: string[];
|
|
125
|
+
}>;
|
|
126
|
+
rangeKey: C['RangeKey'];
|
|
355
127
|
shardKeyDelimiter?: string;
|
|
356
|
-
/**
|
|
357
|
-
* The default maximum number of shards to query in parallel. Can be overridden at {@link QueryOptions.throttle | `QueryOptions.throttle`}.
|
|
358
|
-
*
|
|
359
|
-
* @defaultValue `10`
|
|
360
|
-
*/
|
|
361
128
|
throttle?: number;
|
|
362
|
-
} & ([keyof Exactify<T>] extends [never] ? {
|
|
363
|
-
transcodes?: ConfigTranscodes<T>;
|
|
364
|
-
} : DefaultTranscodeMap extends T ? {
|
|
365
|
-
transcodes?: ConfigTranscodes<T>;
|
|
366
|
-
} : {
|
|
367
|
-
transcodes: ConfigTranscodes<T>;
|
|
368
|
-
});
|
|
369
|
-
/**
|
|
370
|
-
* Flattens the top layer of logic in a type.
|
|
371
|
-
*
|
|
372
|
-
* @category Utility
|
|
373
|
-
* @protected
|
|
374
|
-
*/
|
|
375
|
-
type Unwrap<T> = {
|
|
376
|
-
[P in keyof T]: T[P];
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* Extracts a map of {@link Entity | `Entity`} item types decorated with {@link ConfigKeys.hashKey | hashKey}, {@link ConfigKeys.rangeKey | rangeKey}, and {@link ConfigEntityGenerated | generated properties}.
|
|
380
|
-
*
|
|
381
|
-
* @typeParam M - The {@link EntityMap | `EntityMap`} type that identitfies the {@link Entity | `Entity`} & related property types to be managed by EntityManager.
|
|
382
|
-
* @typeParam HashKey - The property used across the configuration to store an {@link Entity | `Entity`}'s sharded hash key. Should be configured as the table hash key. Must not conflict with any {@link Entity | `Entity`} property. Defaults to `'hashKey'`.
|
|
383
|
-
* @typeParam RangeKey - The property used across the configuration to store an {@link Entity | `Entity`}'s range key. Should be configured as the table range key. Must not conflict with any {@link Entity | `Entity`} property. Defaults to `'rangeKey'`.
|
|
384
|
-
*
|
|
385
|
-
* @category Entities
|
|
386
|
-
*/
|
|
387
|
-
type ItemMap<M extends EntityMap, HashKey extends string = 'hashKey', RangeKey extends string = 'rangeKey'> = {
|
|
388
|
-
[EntityToken in keyof Exactify<M>]: Unwrap<{
|
|
389
|
-
[P in keyof Exactify<M[EntityToken]>]: [
|
|
390
|
-
NonNullable<M[EntityToken][P]>
|
|
391
|
-
] extends [never] ? string : M[EntityToken][P];
|
|
392
|
-
} & Partial<Record<HashKey | RangeKey, string>>>;
|
|
393
129
|
};
|
|
394
130
|
|
|
395
|
-
|
|
396
|
-
* A result returned by a query across multiple shards, where each shard may
|
|
397
|
-
* receive multiple page queries via a dynamically-generated {@link ShardQueryFunction | `ShardQueryFunction`}.
|
|
398
|
-
*
|
|
399
|
-
* @category Query
|
|
400
|
-
*/
|
|
401
|
-
interface QueryResult<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string> {
|
|
402
|
-
/** Total number of records returned across all shards. */
|
|
403
|
-
count: number;
|
|
404
|
-
/** The returned records. */
|
|
405
|
-
items: Item[];
|
|
406
|
-
/**
|
|
407
|
-
* A compressed, two-layer map of page keys, used to query the next page of
|
|
408
|
-
* data for a given sort key on each shard of a given hash key.
|
|
409
|
-
*/
|
|
410
|
-
pageKeyMap: string;
|
|
411
|
-
}
|
|
131
|
+
type EntityToken<C extends BaseConfigMap> = keyof Exactify<C['EntityMap']> & string;
|
|
412
132
|
|
|
413
133
|
declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
414
|
-
entities: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
134
|
+
entities: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
415
135
|
defaultLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
416
136
|
defaultPageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
417
|
-
generated: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodObject<{
|
|
418
|
-
atomic: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
419
|
-
elements: z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>;
|
|
420
|
-
sharded: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
421
|
-
}, "strip", z.ZodTypeAny, {
|
|
422
|
-
atomic: boolean;
|
|
423
|
-
elements: [string, ...string[]];
|
|
424
|
-
sharded: boolean;
|
|
425
|
-
}, {
|
|
426
|
-
elements: [string, ...string[]];
|
|
427
|
-
atomic?: boolean | undefined;
|
|
428
|
-
sharded?: boolean | undefined;
|
|
429
|
-
}>>>>>;
|
|
430
|
-
elementTranscodes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
431
|
-
indexes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
432
|
-
hashKey: z.ZodString;
|
|
433
|
-
rangeKey: z.ZodString;
|
|
434
|
-
projections: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>;
|
|
435
|
-
}, "strip", z.ZodTypeAny, {
|
|
436
|
-
hashKey: string;
|
|
437
|
-
rangeKey: string;
|
|
438
|
-
projections?: [string, ...string[]] | undefined;
|
|
439
|
-
}, {
|
|
440
|
-
hashKey: string;
|
|
441
|
-
rangeKey: string;
|
|
442
|
-
projections?: [string, ...string[]] | undefined;
|
|
443
|
-
}>>>>;
|
|
444
137
|
shardBumps: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
445
138
|
timestamp: z.ZodNumber;
|
|
446
139
|
charBits: z.ZodNumber;
|
|
@@ -483,12 +176,6 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
483
176
|
}, "strict", z.ZodTypeAny, {
|
|
484
177
|
defaultLimit: number;
|
|
485
178
|
defaultPageSize: number;
|
|
486
|
-
elementTranscodes: Record<string, string>;
|
|
487
|
-
indexes: Record<string, {
|
|
488
|
-
hashKey: string;
|
|
489
|
-
rangeKey: string;
|
|
490
|
-
projections?: [string, ...string[]] | undefined;
|
|
491
|
-
}>;
|
|
492
179
|
shardBumps: {
|
|
493
180
|
timestamp: number;
|
|
494
181
|
charBits: number;
|
|
@@ -496,80 +183,46 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
496
183
|
}[];
|
|
497
184
|
timestampProperty: string;
|
|
498
185
|
uniqueProperty: string;
|
|
499
|
-
generated: Record<string, {
|
|
500
|
-
atomic: boolean;
|
|
501
|
-
elements: [string, ...string[]];
|
|
502
|
-
sharded: boolean;
|
|
503
|
-
} | undefined>;
|
|
504
186
|
}, {
|
|
505
187
|
timestampProperty: string;
|
|
506
188
|
uniqueProperty: string;
|
|
507
189
|
defaultLimit?: number | undefined;
|
|
508
190
|
defaultPageSize?: number | undefined;
|
|
509
|
-
elementTranscodes?: Record<string, string> | undefined;
|
|
510
|
-
indexes?: Record<string, {
|
|
511
|
-
hashKey: string;
|
|
512
|
-
rangeKey: string;
|
|
513
|
-
projections?: [string, ...string[]] | undefined;
|
|
514
|
-
}> | undefined;
|
|
515
191
|
shardBumps?: {
|
|
516
192
|
timestamp: number;
|
|
517
193
|
charBits: number;
|
|
518
194
|
chars: number;
|
|
519
195
|
}[] | undefined;
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
defaultPageSize: number;
|
|
528
|
-
elementTranscodes: Record<string, string>;
|
|
529
|
-
indexes: Record<string, {
|
|
530
|
-
hashKey: string;
|
|
531
|
-
rangeKey: string;
|
|
532
|
-
projections?: [string, ...string[]] | undefined;
|
|
533
|
-
}>;
|
|
534
|
-
shardBumps: {
|
|
535
|
-
timestamp: number;
|
|
536
|
-
charBits: number;
|
|
537
|
-
chars: number;
|
|
538
|
-
}[];
|
|
539
|
-
timestampProperty: string;
|
|
540
|
-
uniqueProperty: string;
|
|
541
|
-
generated: Record<string, {
|
|
542
|
-
atomic: boolean;
|
|
543
|
-
elements: [string, ...string[]];
|
|
544
|
-
sharded: boolean;
|
|
545
|
-
} | undefined>;
|
|
196
|
+
}>>>>;
|
|
197
|
+
generatedProperties: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
198
|
+
sharded: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>>>;
|
|
199
|
+
unsharded: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>>>;
|
|
200
|
+
}, "strip", z.ZodTypeAny, {
|
|
201
|
+
sharded: Record<string, [string, ...string[]]>;
|
|
202
|
+
unsharded: Record<string, [string, ...string[]]>;
|
|
546
203
|
}, {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
elements: [string, ...string[]];
|
|
564
|
-
atomic?: boolean | undefined;
|
|
565
|
-
sharded?: boolean | undefined;
|
|
566
|
-
} | undefined> | undefined;
|
|
204
|
+
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
205
|
+
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
206
|
+
}>>>;
|
|
207
|
+
hashKey: z.ZodString;
|
|
208
|
+
indexes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
209
|
+
hashKey: z.ZodString;
|
|
210
|
+
rangeKey: z.ZodString;
|
|
211
|
+
projections: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>;
|
|
212
|
+
}, "strip", z.ZodTypeAny, {
|
|
213
|
+
hashKey: string;
|
|
214
|
+
rangeKey: string;
|
|
215
|
+
projections?: [string, ...string[]] | undefined;
|
|
216
|
+
}, {
|
|
217
|
+
hashKey: string;
|
|
218
|
+
rangeKey: string;
|
|
219
|
+
projections?: [string, ...string[]] | undefined;
|
|
567
220
|
}>>>>;
|
|
568
221
|
generatedKeyDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
569
222
|
generatedValueDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
223
|
+
propertyTranscodes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
224
|
+
rangeKey: z.ZodString;
|
|
570
225
|
shardKeyDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
571
|
-
hashKey: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
572
|
-
rangeKey: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
573
226
|
throttle: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
574
227
|
transcodes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
575
228
|
encode: z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodString>;
|
|
@@ -583,17 +236,9 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
583
236
|
}>>>>;
|
|
584
237
|
}, "strict", z.ZodTypeAny, {
|
|
585
238
|
throttle: number;
|
|
586
|
-
hashKey: string;
|
|
587
|
-
rangeKey: string;
|
|
588
239
|
entities: Record<string, {
|
|
589
240
|
defaultLimit: number;
|
|
590
241
|
defaultPageSize: number;
|
|
591
|
-
elementTranscodes: Record<string, string>;
|
|
592
|
-
indexes: Record<string, {
|
|
593
|
-
hashKey: string;
|
|
594
|
-
rangeKey: string;
|
|
595
|
-
projections?: [string, ...string[]] | undefined;
|
|
596
|
-
}>;
|
|
597
242
|
shardBumps: {
|
|
598
243
|
timestamp: number;
|
|
599
244
|
charBits: number;
|
|
@@ -601,47 +246,53 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
601
246
|
}[];
|
|
602
247
|
timestampProperty: string;
|
|
603
248
|
uniqueProperty: string;
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
249
|
+
}>;
|
|
250
|
+
generatedProperties: {
|
|
251
|
+
sharded: Record<string, [string, ...string[]]>;
|
|
252
|
+
unsharded: Record<string, [string, ...string[]]>;
|
|
253
|
+
};
|
|
254
|
+
hashKey: string;
|
|
255
|
+
rangeKey: string;
|
|
256
|
+
indexes: Record<string, {
|
|
257
|
+
hashKey: string;
|
|
258
|
+
rangeKey: string;
|
|
259
|
+
projections?: [string, ...string[]] | undefined;
|
|
609
260
|
}>;
|
|
610
261
|
generatedKeyDelimiter: string;
|
|
611
262
|
generatedValueDelimiter: string;
|
|
263
|
+
propertyTranscodes: Record<string, string>;
|
|
612
264
|
shardKeyDelimiter: string;
|
|
613
265
|
transcodes: Record<string, {
|
|
614
266
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
615
267
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
616
268
|
}>;
|
|
617
269
|
}, {
|
|
270
|
+
hashKey: string;
|
|
271
|
+
rangeKey: string;
|
|
618
272
|
throttle?: number | undefined;
|
|
619
|
-
hashKey?: string | undefined;
|
|
620
|
-
rangeKey?: string | undefined;
|
|
621
273
|
entities?: Record<string, {
|
|
622
274
|
timestampProperty: string;
|
|
623
275
|
uniqueProperty: string;
|
|
624
276
|
defaultLimit?: number | undefined;
|
|
625
277
|
defaultPageSize?: number | undefined;
|
|
626
|
-
elementTranscodes?: Record<string, string> | undefined;
|
|
627
|
-
indexes?: Record<string, {
|
|
628
|
-
hashKey: string;
|
|
629
|
-
rangeKey: string;
|
|
630
|
-
projections?: [string, ...string[]] | undefined;
|
|
631
|
-
}> | undefined;
|
|
632
278
|
shardBumps?: {
|
|
633
279
|
timestamp: number;
|
|
634
280
|
charBits: number;
|
|
635
281
|
chars: number;
|
|
636
282
|
}[] | undefined;
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
283
|
+
}> | undefined;
|
|
284
|
+
generatedProperties?: {
|
|
285
|
+
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
286
|
+
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
287
|
+
} | undefined;
|
|
288
|
+
indexes?: Record<string, {
|
|
289
|
+
hashKey: string;
|
|
290
|
+
rangeKey: string;
|
|
291
|
+
projections?: [string, ...string[]] | undefined;
|
|
642
292
|
}> | undefined;
|
|
643
293
|
generatedKeyDelimiter?: string | undefined;
|
|
644
294
|
generatedValueDelimiter?: string | undefined;
|
|
295
|
+
propertyTranscodes?: Record<string, string> | undefined;
|
|
645
296
|
shardKeyDelimiter?: string | undefined;
|
|
646
297
|
transcodes?: Record<string, {
|
|
647
298
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
@@ -649,17 +300,9 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
649
300
|
}> | undefined;
|
|
650
301
|
}>, {
|
|
651
302
|
throttle: number;
|
|
652
|
-
hashKey: string;
|
|
653
|
-
rangeKey: string;
|
|
654
303
|
entities: Record<string, {
|
|
655
304
|
defaultLimit: number;
|
|
656
305
|
defaultPageSize: number;
|
|
657
|
-
elementTranscodes: Record<string, string>;
|
|
658
|
-
indexes: Record<string, {
|
|
659
|
-
hashKey: string;
|
|
660
|
-
rangeKey: string;
|
|
661
|
-
projections?: [string, ...string[]] | undefined;
|
|
662
|
-
}>;
|
|
663
306
|
shardBumps: {
|
|
664
307
|
timestamp: number;
|
|
665
308
|
charBits: number;
|
|
@@ -667,47 +310,53 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
667
310
|
}[];
|
|
668
311
|
timestampProperty: string;
|
|
669
312
|
uniqueProperty: string;
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
313
|
+
}>;
|
|
314
|
+
generatedProperties: {
|
|
315
|
+
sharded: Record<string, [string, ...string[]]>;
|
|
316
|
+
unsharded: Record<string, [string, ...string[]]>;
|
|
317
|
+
};
|
|
318
|
+
hashKey: string;
|
|
319
|
+
rangeKey: string;
|
|
320
|
+
indexes: Record<string, {
|
|
321
|
+
hashKey: string;
|
|
322
|
+
rangeKey: string;
|
|
323
|
+
projections?: [string, ...string[]] | undefined;
|
|
675
324
|
}>;
|
|
676
325
|
generatedKeyDelimiter: string;
|
|
677
326
|
generatedValueDelimiter: string;
|
|
327
|
+
propertyTranscodes: Record<string, string>;
|
|
678
328
|
shardKeyDelimiter: string;
|
|
679
329
|
transcodes: Record<string, {
|
|
680
330
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
681
331
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
682
332
|
}>;
|
|
683
333
|
}, {
|
|
334
|
+
hashKey: string;
|
|
335
|
+
rangeKey: string;
|
|
684
336
|
throttle?: number | undefined;
|
|
685
|
-
hashKey?: string | undefined;
|
|
686
|
-
rangeKey?: string | undefined;
|
|
687
337
|
entities?: Record<string, {
|
|
688
338
|
timestampProperty: string;
|
|
689
339
|
uniqueProperty: string;
|
|
690
340
|
defaultLimit?: number | undefined;
|
|
691
341
|
defaultPageSize?: number | undefined;
|
|
692
|
-
elementTranscodes?: Record<string, string> | undefined;
|
|
693
|
-
indexes?: Record<string, {
|
|
694
|
-
hashKey: string;
|
|
695
|
-
rangeKey: string;
|
|
696
|
-
projections?: [string, ...string[]] | undefined;
|
|
697
|
-
}> | undefined;
|
|
698
342
|
shardBumps?: {
|
|
699
343
|
timestamp: number;
|
|
700
344
|
charBits: number;
|
|
701
345
|
chars: number;
|
|
702
346
|
}[] | undefined;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
347
|
+
}> | undefined;
|
|
348
|
+
generatedProperties?: {
|
|
349
|
+
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
350
|
+
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
351
|
+
} | undefined;
|
|
352
|
+
indexes?: Record<string, {
|
|
353
|
+
hashKey: string;
|
|
354
|
+
rangeKey: string;
|
|
355
|
+
projections?: [string, ...string[]] | undefined;
|
|
708
356
|
}> | undefined;
|
|
709
357
|
generatedKeyDelimiter?: string | undefined;
|
|
710
358
|
generatedValueDelimiter?: string | undefined;
|
|
359
|
+
propertyTranscodes?: Record<string, string> | undefined;
|
|
711
360
|
shardKeyDelimiter?: string | undefined;
|
|
712
361
|
transcodes?: Record<string, {
|
|
713
362
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
@@ -724,17 +373,15 @@ type ParsedConfig = z.infer<typeof configSchema>;
|
|
|
724
373
|
/**
|
|
725
374
|
* A result returned by a {@link ShardQueryFunction | `ShardQueryFunction`} querying an individual shard.
|
|
726
375
|
*
|
|
727
|
-
* @
|
|
728
|
-
|
|
729
|
-
* @category Query
|
|
376
|
+
* @category Query
|
|
730
377
|
*/
|
|
731
|
-
interface ShardQueryResult<
|
|
378
|
+
interface ShardQueryResult<C extends BaseConfigMap> {
|
|
732
379
|
/** The number of records returned. */
|
|
733
380
|
count: number;
|
|
734
381
|
/** The returned records. */
|
|
735
|
-
items:
|
|
382
|
+
items: EntityItem<C>[];
|
|
736
383
|
/** The page key for the next query on this shard. */
|
|
737
|
-
pageKey?:
|
|
384
|
+
pageKey?: EntityItem<C>;
|
|
738
385
|
}
|
|
739
386
|
|
|
740
387
|
/**
|
|
@@ -752,22 +399,22 @@ interface ShardQueryResult<Item extends Entity> {
|
|
|
752
399
|
*
|
|
753
400
|
* @category Query
|
|
754
401
|
*/
|
|
755
|
-
type ShardQueryFunction<
|
|
402
|
+
type ShardQueryFunction<C extends BaseConfigMap> = (hashKey: string, pageKey?: EntityItem<C>, pageSize?: number) => Promise<ShardQueryResult<C>>;
|
|
756
403
|
|
|
757
|
-
type ShardQueryMap<
|
|
404
|
+
type ShardQueryMap<C extends BaseConfigMap> = Record<string, ShardQueryFunction<C>>;
|
|
758
405
|
|
|
759
406
|
/**
|
|
760
|
-
* Options passed to the {@link query | `query`}
|
|
407
|
+
* Options passed to the {@link EntityManager.query | `EntityManager.query`} method.
|
|
761
408
|
*
|
|
762
409
|
* @category Query
|
|
763
410
|
*/
|
|
764
|
-
interface QueryOptions<
|
|
765
|
-
/** Identifies the entity to be queried. Key of {@link Config | `
|
|
766
|
-
entityToken: EntityToken
|
|
411
|
+
interface QueryOptions<C extends BaseConfigMap> {
|
|
412
|
+
/** Identifies the entity to be queried. Key of {@link Config | `Config`} `entities`. */
|
|
413
|
+
entityToken: EntityToken<C>;
|
|
767
414
|
/**
|
|
768
415
|
* Partial item object sufficiently populated to generate index hash keys.
|
|
769
416
|
*/
|
|
770
|
-
item:
|
|
417
|
+
item: EntityItem<C>;
|
|
771
418
|
/**
|
|
772
419
|
* The target maximum number of records to be returned by the query across
|
|
773
420
|
* all shards.
|
|
@@ -799,11 +446,11 @@ interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken],
|
|
|
799
446
|
* page key, e.g. to match the same string against `firstName` and `lastName`
|
|
800
447
|
* properties without performing a table scan for either.
|
|
801
448
|
*/
|
|
802
|
-
shardQueryMap: ShardQueryMap<
|
|
449
|
+
shardQueryMap: ShardQueryMap<C>;
|
|
803
450
|
/**
|
|
804
451
|
* A {@link SortOrder | `SortOrder`} object specifying the sort order of the result set. Defaults to `[]`.
|
|
805
452
|
*/
|
|
806
|
-
sortOrder?: SortOrder<
|
|
453
|
+
sortOrder?: SortOrder<EntityItem<C>>;
|
|
807
454
|
/**
|
|
808
455
|
* Lower limit to query shard space.
|
|
809
456
|
*
|
|
@@ -838,16 +485,16 @@ interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken],
|
|
|
838
485
|
*
|
|
839
486
|
* @category Entity Manager
|
|
840
487
|
*/
|
|
841
|
-
declare class EntityManager<
|
|
488
|
+
declare class EntityManager<C extends BaseConfigMap> {
|
|
842
489
|
#private;
|
|
843
|
-
logger: Pick<Console, 'debug' | 'error'>;
|
|
490
|
+
readonly logger: Pick<Console, 'debug' | 'error'>;
|
|
844
491
|
/**
|
|
845
492
|
* Create an EntityManager instance.
|
|
846
493
|
*
|
|
847
494
|
* @param config - EntityManager {@link Config | `Config`} object.
|
|
848
495
|
* @param logger - Logger object (defaults to `console`, must support `debug` & `error` methods).
|
|
849
496
|
*/
|
|
850
|
-
constructor(config: Config<
|
|
497
|
+
constructor(config: Config<C>, logger?: Pick<Console, 'debug' | 'error'>);
|
|
851
498
|
/**
|
|
852
499
|
* Get the current EntityManager {@link Config | `Config`} object.
|
|
853
500
|
*
|
|
@@ -861,35 +508,35 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
861
508
|
*/
|
|
862
509
|
set config(value: ParsedConfig);
|
|
863
510
|
/**
|
|
864
|
-
* Update generated properties, hash key, and range key on an {@link
|
|
511
|
+
* Update generated properties, hash key, and range key on an {@link EntityItem | `EntityItem`} object.
|
|
865
512
|
*
|
|
866
|
-
* @param entityToken - {@link
|
|
867
|
-
* @param item - {@link
|
|
513
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
514
|
+
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
868
515
|
* @param overwrite - Overwrite existing properties (default `false`).
|
|
869
516
|
*
|
|
870
517
|
* @returns Shallow clone of `item` with updated properties.
|
|
871
518
|
*
|
|
872
519
|
* @throws `Error` if `entityToken` is invalid.
|
|
873
520
|
*/
|
|
874
|
-
addKeys
|
|
521
|
+
addKeys(entityToken: EntityToken<C>, item: EntityItem<C>, overwrite?: boolean): EntityItem<C>;
|
|
875
522
|
/**
|
|
876
|
-
* Strips generated properties, hash key, and range key from an {@link
|
|
523
|
+
* Strips generated properties, hash key, and range key from an {@link EntityItem | `EntityItem`} object.
|
|
877
524
|
*
|
|
878
|
-
* @param entityToken - {@link
|
|
879
|
-
* @param item - {@link
|
|
525
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
526
|
+
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
880
527
|
*
|
|
881
528
|
* @returns Shallow clone of `item` without generated properties, hash key or range key.
|
|
882
529
|
*
|
|
883
530
|
* @throws `Error` if `entityToken` is invalid.
|
|
884
531
|
*/
|
|
885
|
-
removeKeys
|
|
532
|
+
removeKeys(entityToken: EntityToken<C>, item: EntityItem<C>): EntityItem<C>;
|
|
886
533
|
/**
|
|
887
534
|
* Query a database entity across shards in a provider-generic fashion.
|
|
888
535
|
*
|
|
889
536
|
* @remarks
|
|
890
537
|
* The provided `shardQueryMap` performs the actual query of individual data pages on individual index/shard combinations.
|
|
891
538
|
*
|
|
892
|
-
* Individual shard query results will be combined, deduped by {@link
|
|
539
|
+
* Individual shard query results will be combined, deduped by {@link Config | `Config`} `uniqueProperty` value, and sorted by {@link QueryOptions.sortOrder | `sortOrder`}.
|
|
893
540
|
*
|
|
894
541
|
* In queries on sharded data, expect the leading and trailing edges of returned data pages to interleave somewhat with preceding & following pages.
|
|
895
542
|
*
|
|
@@ -899,45 +546,45 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
899
546
|
*
|
|
900
547
|
* @returns {@link QueryResult} object.
|
|
901
548
|
*
|
|
902
|
-
* @throws Error if {@link QueryOptions.
|
|
549
|
+
* @throws Error if `options` {@link QueryOptions.pageKeyMap | `pageKeyMap`} `pageKeyMap` keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
903
550
|
*/
|
|
904
|
-
query
|
|
551
|
+
query(options: QueryOptions<C>): Promise<QueryResult<C>>;
|
|
905
552
|
}
|
|
906
553
|
|
|
907
554
|
/**
|
|
908
555
|
* Constructor options for {@link BaseQueryBuilder | `BaseQueryBuilder`}.
|
|
909
556
|
*
|
|
910
|
-
* @category
|
|
557
|
+
* @category QueryBuilder
|
|
911
558
|
*/
|
|
912
|
-
interface BaseQueryBuilderOptions<
|
|
559
|
+
interface BaseQueryBuilderOptions<C extends BaseConfigMap, EntityClient extends BaseEntityClient> {
|
|
913
560
|
/** {@link BaseEntityClient | `EntityClient`} instance. */
|
|
914
561
|
entityClient: EntityClient;
|
|
915
562
|
/** {@link EntityManager | `EntityManager`} instance. */
|
|
916
|
-
entityManager: EntityManager<
|
|
563
|
+
entityManager: EntityManager<C>;
|
|
917
564
|
/** Entity token. */
|
|
918
|
-
entityToken: EntityToken
|
|
565
|
+
entityToken: EntityToken<C>;
|
|
919
566
|
/** Hash key token. */
|
|
920
|
-
hashKeyToken:
|
|
567
|
+
hashKeyToken: C['HashKey'] | C['ShardedKeys'];
|
|
921
568
|
/** Dehydrated page key map. */
|
|
922
569
|
pageKeyMap?: string;
|
|
923
570
|
}
|
|
924
571
|
|
|
925
|
-
type QueryBuilderQueryOptions<
|
|
572
|
+
type QueryBuilderQueryOptions<C extends BaseConfigMap> = Omit<QueryOptions<C>, 'entityToken' | 'pageKeyMap' | 'shardQueryMap'>;
|
|
926
573
|
|
|
927
574
|
/**
|
|
928
575
|
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
929
576
|
*
|
|
930
|
-
* @category
|
|
577
|
+
* @category QueryBuilder
|
|
931
578
|
*/
|
|
932
|
-
declare abstract class BaseQueryBuilder<
|
|
579
|
+
declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient extends BaseEntityClient, IndexParams> {
|
|
933
580
|
/** {@link BaseEntityClient | `EntityClient`} instance. */
|
|
934
581
|
readonly entityClient: EntityClient;
|
|
935
582
|
/** {@link EntityManager | `EntityManager`} instance. */
|
|
936
|
-
readonly entityManager: EntityManager<
|
|
583
|
+
readonly entityManager: EntityManager<C>;
|
|
937
584
|
/** Entity token. */
|
|
938
|
-
readonly entityToken: EntityToken
|
|
585
|
+
readonly entityToken: EntityToken<C>;
|
|
939
586
|
/** Hash key token. */
|
|
940
|
-
readonly hashKeyToken:
|
|
587
|
+
readonly hashKeyToken: C['HashKey'] | C['ShardedKeys'];
|
|
941
588
|
/** Dehydrated page key map. */
|
|
942
589
|
readonly pageKeyMap?: string;
|
|
943
590
|
/**
|
|
@@ -947,15 +594,15 @@ declare abstract class BaseQueryBuilder<IndexParams, EntityClient extends BaseEn
|
|
|
947
594
|
*/
|
|
948
595
|
readonly indexParamsMap: Record<string, IndexParams>;
|
|
949
596
|
/** BaseQueryBuilder constructor. */
|
|
950
|
-
constructor(options: BaseQueryBuilderOptions<
|
|
951
|
-
protected abstract getShardQueryFunction(indexToken: string): ShardQueryFunction<
|
|
597
|
+
constructor(options: BaseQueryBuilderOptions<C, EntityClient>);
|
|
598
|
+
protected abstract getShardQueryFunction(indexToken: string): ShardQueryFunction<C>;
|
|
952
599
|
/**
|
|
953
600
|
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
954
601
|
*
|
|
955
602
|
* @returns - The {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
956
603
|
*/
|
|
957
|
-
build(): ShardQueryMap<
|
|
958
|
-
query(options: QueryBuilderQueryOptions<
|
|
604
|
+
build(): ShardQueryMap<C>;
|
|
605
|
+
query(options: QueryBuilderQueryOptions<C>): Promise<QueryResult<C>>;
|
|
959
606
|
}
|
|
960
607
|
|
|
961
608
|
/**
|
|
@@ -971,4 +618,4 @@ declare abstract class BaseQueryBuilder<IndexParams, EntityClient extends BaseEn
|
|
|
971
618
|
*/
|
|
972
619
|
declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
973
620
|
|
|
974
|
-
export { BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type
|
|
621
|
+
export { type BaseConfigMap, BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type ConditionalProperty, type Config, type EntityItem, EntityManager, type EntityToken, type ParsedConfig, type QueryBuilderQueryOptions, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, conditionalize };
|