@karmaniverous/entity-manager 6.14.3 → 7.0.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/README.md +171 -268
- package/dist/cjs/BaseEntityClient/BaseEntityClient.js +1 -1
- package/dist/cjs/BaseQueryBuilder/BaseQueryBuilder.js +3 -2
- package/dist/cjs/EntityManager/EntityManager.js +1 -1
- package/dist/cjs/EntityManager/createEntityManager.js +42 -0
- package/dist/cjs/EntityManager/decodeGeneratedProperty.js +4 -2
- package/dist/cjs/EntityManager/dehydratePageKeyMap.js +5 -4
- package/dist/cjs/EntityManager/getIndexComponents.js +6 -1
- package/dist/cjs/EntityManager/query.js +26 -11
- package/dist/cjs/EntityManager/rehydratePageKeyMap.js +6 -3
- package/dist/cjs/index.js +2 -0
- package/dist/index.d.ts +318 -117
- package/dist/mjs/BaseEntityClient/BaseEntityClient.js +1 -1
- package/dist/mjs/BaseQueryBuilder/BaseQueryBuilder.js +3 -2
- package/dist/mjs/EntityManager/EntityManager.js +1 -1
- package/dist/mjs/EntityManager/createEntityManager.js +40 -0
- package/dist/mjs/EntityManager/decodeGeneratedProperty.js +4 -2
- package/dist/mjs/EntityManager/dehydratePageKeyMap.js +5 -4
- package/dist/mjs/EntityManager/getIndexComponents.js +6 -1
- package/dist/mjs/EntityManager/query.js +26 -11
- package/dist/mjs/EntityManager/rehydratePageKeyMap.js +6 -3
- package/dist/mjs/index.js +1 -0
- package/package.json +132 -135
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EntityMap,
|
|
2
|
-
import { z } from 'zod';
|
|
1
|
+
import { EntityMap, TranscodeRegistry, ConditionalProperty, Exactify, PropertiesOfType, TranscodableProperties, FlattenEntityMap, Transcodes, MutuallyExclusive, NotNever, DefaultTranscodeRegistry, SortOrder } from '@karmaniverous/entity-tools';
|
|
2
|
+
import { z, ZodType, infer } from 'zod';
|
|
3
3
|
import { BatchProcessOptions } from '@karmaniverous/batch-process';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -14,7 +14,7 @@ interface BaseConfigMap {
|
|
|
14
14
|
ShardedKeys: string;
|
|
15
15
|
UnshardedKeys: string;
|
|
16
16
|
TranscodedProperties: string;
|
|
17
|
-
|
|
17
|
+
TranscodeRegistry: TranscodeRegistry;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -48,7 +48,7 @@ interface ShardBump {
|
|
|
48
48
|
/**
|
|
49
49
|
* Configuration object for an {@link EntityManager | `EntityManager`} instance.
|
|
50
50
|
*
|
|
51
|
-
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines the configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link
|
|
51
|
+
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines the configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
52
52
|
*
|
|
53
53
|
* @category EntityManager
|
|
54
54
|
*/
|
|
@@ -57,18 +57,18 @@ type Config<C extends BaseConfigMap = BaseConfigMap> = ConditionalProperty<'enti
|
|
|
57
57
|
defaultLimit?: number;
|
|
58
58
|
defaultPageSize?: number;
|
|
59
59
|
shardBumps?: ShardBump[];
|
|
60
|
-
timestampProperty: C['TranscodedProperties'] & PropertiesOfType<C['EntityMap'][E], number> & TranscodableProperties<C['EntityMap'], C['
|
|
61
|
-
uniqueProperty: C['TranscodedProperties'] & keyof C['EntityMap'][E] & TranscodableProperties<C['EntityMap'], C['
|
|
60
|
+
timestampProperty: C['TranscodedProperties'] & PropertiesOfType<C['EntityMap'][E], number> & TranscodableProperties<C['EntityMap'], C['TranscodeRegistry']>;
|
|
61
|
+
uniqueProperty: C['TranscodedProperties'] & keyof C['EntityMap'][E] & TranscodableProperties<C['EntityMap'], C['TranscodeRegistry']>;
|
|
62
62
|
};
|
|
63
|
-
}> & ConditionalProperty<'generatedProperties', C['ShardedKeys'] | C['UnshardedKeys'], ConditionalProperty<'sharded', C['ShardedKeys'], Record<C['ShardedKeys'], (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['
|
|
64
|
-
[P in C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['
|
|
65
|
-
}> & ConditionalProperty<'transcodes', keyof C['
|
|
63
|
+
}> & ConditionalProperty<'generatedProperties', C['ShardedKeys'] | C['UnshardedKeys'], ConditionalProperty<'sharded', C['ShardedKeys'], Record<C['ShardedKeys'], (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeRegistry']>)[]>> & ConditionalProperty<'unsharded', C['UnshardedKeys'], Record<C['UnshardedKeys'], (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeRegistry']>)[]>>> & ConditionalProperty<'propertyTranscodes', C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeRegistry']>, {
|
|
64
|
+
[P in C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeRegistry']>]: PropertiesOfType<C['TranscodeRegistry'], FlattenEntityMap<C['EntityMap']>[P]>;
|
|
65
|
+
}> & ConditionalProperty<'transcodes', keyof C['TranscodeRegistry'], Transcodes<C['TranscodeRegistry']>> & {
|
|
66
66
|
generatedKeyDelimiter?: string;
|
|
67
67
|
generatedValueDelimiter?: string;
|
|
68
68
|
hashKey: C['HashKey'];
|
|
69
69
|
indexes?: Record<string, {
|
|
70
70
|
hashKey: C['HashKey'] | C['ShardedKeys'];
|
|
71
|
-
rangeKey: C['RangeKey'] | C['UnshardedKeys'] | (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['
|
|
71
|
+
rangeKey: C['RangeKey'] | C['UnshardedKeys'] | (C['TranscodedProperties'] & TranscodableProperties<C['EntityMap'], C['TranscodeRegistry']>);
|
|
72
72
|
projections?: string[];
|
|
73
73
|
}>;
|
|
74
74
|
rangeKey: C['RangeKey'];
|
|
@@ -79,27 +79,27 @@ type Config<C extends BaseConfigMap = BaseConfigMap> = ConditionalProperty<'enti
|
|
|
79
79
|
/**
|
|
80
80
|
* Validates a type derived from {@link BaseConfigMap | `BaseConfigMap`} to ensure HashKey and RangeKey are both defined and that all sets of special keys are mutually exclusive.
|
|
81
81
|
*
|
|
82
|
-
* @typeParam
|
|
82
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
83
83
|
*
|
|
84
84
|
* @category EntityManager
|
|
85
85
|
* @protected
|
|
86
86
|
*/
|
|
87
|
-
type ValidateConfigMap<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
keyof FlattenEntityMap<
|
|
93
|
-
]> extends true ? NotNever<
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
keyof FlattenEntityMap<
|
|
87
|
+
type ValidateConfigMap<CC extends BaseConfigMap> = MutuallyExclusive<[
|
|
88
|
+
CC['HashKey'],
|
|
89
|
+
CC['RangeKey'],
|
|
90
|
+
CC['ShardedKeys'],
|
|
91
|
+
CC['UnshardedKeys'],
|
|
92
|
+
keyof FlattenEntityMap<CC['EntityMap']>
|
|
93
|
+
]> extends true ? NotNever<CC, ['HashKey' | 'RangeKey']> extends true ? CC : Exclude<NotNever<CC, ['HashKey' | 'RangeKey']>, true> : Exclude<MutuallyExclusive<[
|
|
94
|
+
CC['HashKey'],
|
|
95
|
+
CC['RangeKey'],
|
|
96
|
+
CC['ShardedKeys'],
|
|
97
|
+
CC['UnshardedKeys'],
|
|
98
|
+
keyof FlattenEntityMap<CC['EntityMap']>
|
|
99
99
|
]>, true>;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* Generates & validates the map defining defines an {@link EntityManager | `EntityManager`} configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link
|
|
102
|
+
* Generates & validates the map defining defines an {@link EntityManager | `EntityManager`} configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}.
|
|
103
103
|
*
|
|
104
104
|
* Unspecified properties will default to those defined in {@link BaseConfigMap | `BaseConfigMap`}.
|
|
105
105
|
*
|
|
@@ -114,48 +114,38 @@ type ConfigMap<M extends Partial<BaseConfigMap> = Partial<BaseConfigMap>> = Vali
|
|
|
114
114
|
ShardedKeys: 'ShardedKeys' extends keyof M ? NonNullable<M['ShardedKeys']> : never;
|
|
115
115
|
UnshardedKeys: 'UnshardedKeys' extends keyof M ? NonNullable<M['UnshardedKeys']> : never;
|
|
116
116
|
TranscodedProperties: 'TranscodedProperties' extends keyof M ? NonNullable<M['TranscodedProperties']> : never;
|
|
117
|
-
|
|
117
|
+
TranscodeRegistry: 'TranscodeRegistry' extends keyof M ? NonNullable<M['TranscodeRegistry']> : DefaultTranscodeRegistry;
|
|
118
118
|
}>;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* Extracts a database-facing partial item type from a {@link BaseConfigMap | `ConfigMap`}.
|
|
122
122
|
*
|
|
123
|
-
* @typeParam
|
|
123
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
124
124
|
*
|
|
125
125
|
* @category EntityManager
|
|
126
126
|
* @protected
|
|
127
127
|
*/
|
|
128
|
-
type EntityItem<
|
|
128
|
+
type EntityItem<CC extends BaseConfigMap> = Partial<FlattenEntityMap<CC['EntityMap']> & Record<CC['HashKey'] | CC['RangeKey'] | CC['ShardedKeys'] | CC['UnshardedKeys'], string>> & Record<string, unknown>;
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* Database-facing record key type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
|
|
132
132
|
*
|
|
133
|
-
* @typeParam
|
|
133
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
134
134
|
*
|
|
135
135
|
* @category EntityClient
|
|
136
136
|
* @protected
|
|
137
137
|
*/
|
|
138
|
-
type EntityKey<
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Database-facing record type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
|
|
142
|
-
*
|
|
143
|
-
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
144
|
-
*
|
|
145
|
-
* @category EntityManager
|
|
146
|
-
* @protected
|
|
147
|
-
*/
|
|
148
|
-
type EntityRecord<C extends BaseConfigMap> = EntityItem<C> & EntityKey<C>;
|
|
138
|
+
type EntityKey<CC extends BaseConfigMap> = Record<CC['HashKey'] | CC['RangeKey'], string>;
|
|
149
139
|
|
|
150
140
|
/**
|
|
151
141
|
* Extracts entity tokens from a {@link ConfigMap | `ConfigMap`}.
|
|
152
142
|
*
|
|
153
|
-
* @typeParam
|
|
143
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
154
144
|
*
|
|
155
145
|
* @category EntityManager
|
|
156
146
|
* @protected
|
|
157
147
|
*/
|
|
158
|
-
type EntityToken<
|
|
148
|
+
type EntityToken<CC extends BaseConfigMap> = keyof Exactify<CC['EntityMap']> & string;
|
|
159
149
|
|
|
160
150
|
declare const configSchema: z.ZodObject<{
|
|
161
151
|
entities: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
@@ -208,28 +198,82 @@ type ParsedConfig = z.infer<typeof configSchema>;
|
|
|
208
198
|
/**
|
|
209
199
|
* A partial {@link EntityItem | `EntityItem`} restricted to keys defined in `C`.
|
|
210
200
|
*
|
|
211
|
-
* @typeParam
|
|
201
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
212
202
|
*
|
|
213
203
|
* @category QueryBuilder
|
|
214
204
|
* @protected
|
|
215
205
|
*/
|
|
216
|
-
type PageKey<
|
|
206
|
+
type PageKey<CC extends BaseConfigMap> = Pick<EntityItem<CC>, CC['HashKey'] | CC['RangeKey'] | CC['ShardedKeys'] | CC['UnshardedKeys'] | CC['TranscodedProperties']>;
|
|
207
|
+
/**
|
|
208
|
+
* Internal helpers to safely derive index component tokens for an index IT.
|
|
209
|
+
*
|
|
210
|
+
* These helpers avoid direct generic indexing into `CF['indexes'][IT]` which can
|
|
211
|
+
* trigger TS2536. They guard presence and key membership before extracting
|
|
212
|
+
* literal types when available.
|
|
213
|
+
*/
|
|
214
|
+
type IndexHashKeyOf<CF, IT extends string> = CF extends {
|
|
215
|
+
indexes?: infer I;
|
|
216
|
+
} ? I extends Record<string, unknown> ? IT extends keyof I ? I[IT] extends {
|
|
217
|
+
hashKey: infer HK;
|
|
218
|
+
} ? HK & string : never : never : never : never;
|
|
219
|
+
type IndexRangeKeyOf<CF, IT extends string> = CF extends {
|
|
220
|
+
indexes?: infer I;
|
|
221
|
+
} ? I extends Record<string, unknown> ? IT extends keyof I ? I[IT] extends {
|
|
222
|
+
rangeKey: infer RK;
|
|
223
|
+
} ? RK & string : never : never : never : never;
|
|
224
|
+
/**
|
|
225
|
+
* Derive the union of index token names from a values-first config literal.
|
|
226
|
+
*
|
|
227
|
+
* When CF carries an `indexes` object with preserved literal keys (prefer `as const`),
|
|
228
|
+
* this helper captures the index token union. Falls back to `string` if absent.
|
|
229
|
+
*/
|
|
230
|
+
type IndexTokensOf<CF> = CF extends {
|
|
231
|
+
indexes?: infer I;
|
|
232
|
+
} ? I extends Record<string, unknown> ? keyof I & string : string : string;
|
|
233
|
+
type HasIndexFor<CF, IT extends string> = CF extends {
|
|
234
|
+
indexes?: infer I;
|
|
235
|
+
} ? I extends Record<string, unknown> ? IT extends keyof I ? true : false : false : false;
|
|
236
|
+
type IndexComponentTokens<CC extends BaseConfigMap, CF, IT extends string> = HasIndexFor<CF, IT> extends true ? CC['HashKey'] | CC['RangeKey'] | IndexHashKeyOf<CF, IT> | IndexRangeKeyOf<CF, IT> : CC['HashKey'] | CC['RangeKey'] | CC['ShardedKeys'] | CC['UnshardedKeys'] | CC['TranscodedProperties'];
|
|
237
|
+
/**
|
|
238
|
+
* Page key typed for a specific index token.
|
|
239
|
+
*
|
|
240
|
+
* - With CF (values-first config literal) present and carrying `indexes`, the
|
|
241
|
+
* shape narrows to exactly the component tokens of IT.
|
|
242
|
+
* - Without CF, falls back to the broad PageKey<CC> shape.
|
|
243
|
+
*/
|
|
244
|
+
type PageKeyByIndex<CC extends BaseConfigMap, ET extends EntityToken<CC>, IT extends string = string, CF = unknown> = Pick<EntityItem<CC>, IndexComponentTokens<CC, CF, IT>>;
|
|
245
|
+
|
|
246
|
+
/** EntityOfToken — resolves the concrete entity shape for a specific entity token. */
|
|
247
|
+
type EntityOfToken<CC extends BaseConfigMap, ET extends EntityToken<CC>> = Exactify<CC['EntityMap']>[ET];
|
|
248
|
+
/**
|
|
249
|
+
* EntityItemByToken — database-facing partial item narrowed to a specific entity token.
|
|
250
|
+
* Mirrors `EntityItem<CC>` with the entity surface restricted to `EntityOfToken<CC, ET>`.
|
|
251
|
+
*
|
|
252
|
+
* Note: If using createEntityManager with entitiesSchema, the schema must declare
|
|
253
|
+
* only base (non-generated) properties. Generated keys/tokens are layered by EntityManager.
|
|
254
|
+
*/
|
|
255
|
+
type EntityItemByToken<CC extends BaseConfigMap, ET extends EntityToken<CC>> = Partial<EntityOfToken<CC, ET> & Record<CC['HashKey'] | CC['RangeKey'] | CC['ShardedKeys'] | CC['UnshardedKeys'], string>> & Record<string, unknown>;
|
|
256
|
+
/** EntityRecordByToken — database-facing record (keys required) narrowed to a specific entity token. */
|
|
257
|
+
type EntityRecordByToken<CC extends BaseConfigMap, ET extends EntityToken<CC>> = EntityItemByToken<CC, ET> & EntityKey<CC>;
|
|
217
258
|
|
|
218
259
|
/**
|
|
219
260
|
* A result returned by a {@link ShardQueryFunction | `ShardQueryFunction`} querying an individual shard.
|
|
220
261
|
*
|
|
221
|
-
* @typeParam
|
|
262
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`}.
|
|
263
|
+
* @typeParam ET - Entity token narrowing the item type.
|
|
264
|
+
* @typeParam IT - Index token (for page key typing).
|
|
265
|
+
* @typeParam CF - Optional values-first config literal type for narrowing.
|
|
222
266
|
*
|
|
223
267
|
* @category EntityManager
|
|
224
268
|
* @protected
|
|
225
269
|
*/
|
|
226
|
-
interface ShardQueryResult<
|
|
270
|
+
interface ShardQueryResult<CC extends BaseConfigMap, ET extends EntityToken<CC>, IT extends string, CF = unknown> {
|
|
227
271
|
/** The number of records returned. */
|
|
228
272
|
count: number;
|
|
229
273
|
/** The returned records. */
|
|
230
|
-
items:
|
|
274
|
+
items: EntityItemByToken<CC, ET>[];
|
|
231
275
|
/** The page key for the next query on this shard. */
|
|
232
|
-
pageKey?:
|
|
276
|
+
pageKey?: PageKeyByIndex<CC, ET, IT, CF>;
|
|
233
277
|
}
|
|
234
278
|
|
|
235
279
|
/**
|
|
@@ -238,41 +282,81 @@ interface ShardQueryResult<C extends BaseConfigMap> {
|
|
|
238
282
|
* This function will typically be composed dynamically to express a specific query index & logic. The arguments to this function will be provided by the {@link EntityManager.query | `EntityManager.query`} method, which assembles many returned pages queried across multiple shards into a single query result.
|
|
239
283
|
*
|
|
240
284
|
* @param hashKey - The hash key value of the shard being queried.
|
|
241
|
-
* @param pageKey - The
|
|
285
|
+
* @param pageKey - The typed page key for the index being queried.
|
|
242
286
|
* @param pageSize - The maximum number of items to return from this query.
|
|
243
287
|
*
|
|
244
|
-
* @typeParam
|
|
288
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`}.
|
|
289
|
+
* @typeParam ET - Entity token narrowing the item/record types.
|
|
290
|
+
* @typeParam IT - Index token (inferred from shardQueryMap keys).
|
|
291
|
+
* @typeParam CF - Optional values-first config literal type for narrowing.
|
|
245
292
|
*
|
|
246
293
|
* @category EntityManager
|
|
247
294
|
* @protected
|
|
248
295
|
*/
|
|
249
|
-
type ShardQueryFunction<
|
|
296
|
+
type ShardQueryFunction<CC extends BaseConfigMap, ET extends EntityToken<CC>, IT extends string, CF = unknown> = CF extends {
|
|
297
|
+
indexes?: infer I;
|
|
298
|
+
} ? I extends Record<string, unknown> ? IT extends keyof I & string ? (hashKey: string, pageKey?: PageKeyByIndex<CC, ET, IT, CF>, pageSize?: number) => Promise<ShardQueryResult<CC, ET, IT, CF>> : never : (hashKey: string, pageKey?: PageKeyByIndex<CC, ET, IT, CF>, pageSize?: number) => Promise<ShardQueryResult<CC, ET, IT, CF>> : (hashKey: string, pageKey?: PageKeyByIndex<CC, ET, IT, CF>, pageSize?: number) => Promise<ShardQueryResult<CC, ET, IT, CF>>;
|
|
250
299
|
|
|
251
300
|
/**
|
|
252
301
|
* Relates a specific index token to a {@link ShardQueryFunction | `ShardQueryFunction`} to be performed on that index.
|
|
253
302
|
*
|
|
254
|
-
* @typeParam
|
|
303
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`}.
|
|
304
|
+
* @typeParam ET - Entity token narrowing the function item types.
|
|
305
|
+
* @typeParam ITS - Index token subset (inferred from object keys).
|
|
306
|
+
* @typeParam CF - Optional values-first config literal type for narrowing. When
|
|
307
|
+
* provided and it carries an `indexes` object with preserved
|
|
308
|
+
* literal keys (prefer `as const` at call sites), the map keys
|
|
309
|
+
* are constrained to that set. Excess keys are rejected by
|
|
310
|
+
* excess property checks on object literals.
|
|
255
311
|
*
|
|
256
312
|
* @category EntityManager
|
|
257
313
|
* @protected
|
|
258
314
|
*/
|
|
259
|
-
type ShardQueryMap<
|
|
315
|
+
type ShardQueryMap<CC extends BaseConfigMap, ET extends EntityToken<CC>, ITS extends string, CF = unknown> = CF extends {
|
|
316
|
+
indexes?: infer I;
|
|
317
|
+
} ? I extends Record<string, unknown> ? Record<ITS & (keyof I & string), ShardQueryFunction<CC, ET, ITS & (keyof I & string), CF>> : Record<ITS, ShardQueryFunction<CC, ET, ITS, CF>> : Record<ITS, ShardQueryFunction<CC, ET, ITS, CF>>;
|
|
318
|
+
/**
|
|
319
|
+
* Convenience alias for ShardQueryMap that derives ITS (index token subset)
|
|
320
|
+
* from a values-first captured config CC (e.g., your config literal type).
|
|
321
|
+
*
|
|
322
|
+
* - If CC has `indexes`, ITS becomes the union of its keys.
|
|
323
|
+
* - Otherwise, ITS defaults to `string`.
|
|
324
|
+
*
|
|
325
|
+
* It also passes CC through the CF channel so per-index page-key narrowing
|
|
326
|
+
* applies consistently.
|
|
327
|
+
*
|
|
328
|
+
* This is optional DX sugar; it does not change runtime behavior.
|
|
329
|
+
*/
|
|
330
|
+
type ShardQueryMapByCC<CC extends BaseConfigMap, ET extends EntityToken<CC>, CCLit = unknown> = ShardQueryMap<CC, ET, IndexTokensFrom<CCLit>, CCLit>;
|
|
331
|
+
/**
|
|
332
|
+
* Convenience alias for ShardQueryMap that derives ITS (index token subset)
|
|
333
|
+
* directly from a values-first config literal CF when it carries `indexes`.
|
|
334
|
+
*
|
|
335
|
+
* - If CF has `indexes`, ITS becomes the union of its keys.
|
|
336
|
+
* - Otherwise, ITS defaults to `string`.
|
|
337
|
+
*
|
|
338
|
+
* This is optional DX sugar; it does not change runtime behavior.
|
|
339
|
+
*/
|
|
340
|
+
type ShardQueryMapByCF<CC extends BaseConfigMap, ET extends EntityToken<CC>, CF = unknown> = ShardQueryMap<CC, ET, IndexTokensOf<CF>, CF>;
|
|
260
341
|
|
|
261
342
|
/**
|
|
262
343
|
* Options passed to the {@link EntityManager.query | `EntityManager.query`} method.
|
|
263
344
|
*
|
|
264
|
-
* @typeParam
|
|
345
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
346
|
+
* @typeParam ET - Entity token narrowing the item types.
|
|
347
|
+
* @typeParam ITS - Index token subset (inferred from shardQueryMap keys).
|
|
348
|
+
* @typeParam CF - Optional values-first config literal type used for index-aware narrowing.
|
|
265
349
|
*
|
|
266
350
|
* @category EntityManager
|
|
267
351
|
* @protected
|
|
268
352
|
*/
|
|
269
|
-
interface QueryOptions<
|
|
353
|
+
interface QueryOptions<CC extends BaseConfigMap, ET extends EntityToken<CC> = EntityToken<CC>, ITS extends string = string, CF = unknown> {
|
|
270
354
|
/** Identifies the entity to be queried. Key of {@link Config | `Config`} `entities`. */
|
|
271
|
-
entityToken:
|
|
355
|
+
entityToken: ET;
|
|
272
356
|
/**
|
|
273
357
|
* Partial item object sufficiently populated to generate index hash keys.
|
|
274
358
|
*/
|
|
275
|
-
item:
|
|
359
|
+
item: EntityItemByToken<CC, ET>;
|
|
276
360
|
/**
|
|
277
361
|
* The target maximum number of records to be returned by the query across
|
|
278
362
|
* all shards.
|
|
@@ -304,11 +388,11 @@ interface QueryOptions<C extends BaseConfigMap> {
|
|
|
304
388
|
* page key, e.g. to match the same string against `firstName` and `lastName`
|
|
305
389
|
* properties without performing a table scan for either.
|
|
306
390
|
*/
|
|
307
|
-
shardQueryMap: ShardQueryMap<
|
|
391
|
+
shardQueryMap: ShardQueryMap<CC, ET, ITS, CF>;
|
|
308
392
|
/**
|
|
309
393
|
* A {@link SortOrder | `SortOrder`} object specifying the sort order of the result set. Defaults to `[]`.
|
|
310
394
|
*/
|
|
311
|
-
sortOrder?: SortOrder<
|
|
395
|
+
sortOrder?: SortOrder<EntityItemByToken<CC, ET>>;
|
|
312
396
|
/**
|
|
313
397
|
* Lower limit to query shard space.
|
|
314
398
|
*
|
|
@@ -336,20 +420,45 @@ interface QueryOptions<C extends BaseConfigMap> {
|
|
|
336
420
|
*/
|
|
337
421
|
throttle?: number;
|
|
338
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* Convenience alias for QueryOptions that derives ITS (index token subset)
|
|
425
|
+
* directly from a values-first config literal CF when it carries `indexes`.
|
|
426
|
+
*
|
|
427
|
+
* - If CF has `indexes`, ITS becomes the union of its keys.
|
|
428
|
+
* - Otherwise, ITS defaults to `string`.
|
|
429
|
+
*
|
|
430
|
+
* This is optional DX sugar; it does not change runtime behavior.
|
|
431
|
+
*/
|
|
432
|
+
type QueryOptionsByCF<CC extends BaseConfigMap, ET extends EntityToken<CC> = EntityToken<CC>, CF = unknown> = QueryOptions<CC, ET, IndexTokensOf<CF>, CF>;
|
|
433
|
+
/**
|
|
434
|
+
* Convenience alias for QueryOptions that derives ITS (index token subset)
|
|
435
|
+
* from a values-first captured config CC (e.g., your config literal type).
|
|
436
|
+
*
|
|
437
|
+
* - If CC has `indexes`, ITS becomes the union of its keys.
|
|
438
|
+
* - Otherwise, ITS defaults to `string`.
|
|
439
|
+
*
|
|
440
|
+
* It also passes CC through the CF channel so page-key narrowing and other
|
|
441
|
+
* CF-aware typing applies consistently.
|
|
442
|
+
*
|
|
443
|
+
* This is optional DX sugar; it does not change runtime behavior.
|
|
444
|
+
*/
|
|
445
|
+
type QueryOptionsByCC<CCMap extends BaseConfigMap, ET extends EntityToken<CCMap> = EntityToken<CCMap>, CC = unknown> = QueryOptions<CCMap, ET, IndexTokensFrom<CC>, CC>;
|
|
339
446
|
|
|
340
447
|
/**
|
|
341
448
|
* A result returned by a query across multiple shards, where each shard may receive multiple page queries via a dynamically-generated {@link ShardQueryFunction | `ShardQueryFunction`}.
|
|
342
449
|
*
|
|
343
|
-
* @typeParam
|
|
450
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`}.
|
|
451
|
+
* @typeParam ET - Entity token narrowing the result item type.
|
|
452
|
+
* @typeParam ITS - Index token subset (carried for symmetry; not represented in the shape).
|
|
344
453
|
*
|
|
345
454
|
* @category EntityManager
|
|
346
455
|
* @protected
|
|
347
456
|
*/
|
|
348
|
-
interface QueryResult<
|
|
457
|
+
interface QueryResult<CC extends BaseConfigMap, ET extends EntityToken<CC>, ITS extends string> {
|
|
349
458
|
/** Total number of records returned across all shards. */
|
|
350
459
|
count: number;
|
|
351
460
|
/** The returned records. */
|
|
352
|
-
items:
|
|
461
|
+
items: EntityItemByToken<CC, ET>[];
|
|
353
462
|
/**
|
|
354
463
|
* A compressed, two-layer map of page keys, used to query the next page of
|
|
355
464
|
* data for a given sort key on each shard of a given hash key.
|
|
@@ -361,14 +470,14 @@ interface QueryResult<C extends BaseConfigMap> {
|
|
|
361
470
|
* The EntityManager class applies a configuration-driven sharded data model &
|
|
362
471
|
* query strategy to NoSql data.
|
|
363
472
|
*
|
|
364
|
-
* @typeParam
|
|
473
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines the configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
365
474
|
*
|
|
366
475
|
* @remarks
|
|
367
476
|
* While the {@link EntityManager.query | `query`} method is `public`, normally it should not be called directly. The `query` method is used by a platform-specific {@link BaseQueryBuilder.query | `QueryBuilder.query`} method to provide a fluent query API.
|
|
368
477
|
*
|
|
369
478
|
* @category EntityManager
|
|
370
479
|
*/
|
|
371
|
-
declare class EntityManager<
|
|
480
|
+
declare class EntityManager<CC extends BaseConfigMap> {
|
|
372
481
|
#private;
|
|
373
482
|
/** Logger object (defaults to `console`, must support `debug` & `error` methods). */
|
|
374
483
|
readonly logger: Pick<Console, 'debug' | 'error'>;
|
|
@@ -378,7 +487,7 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
378
487
|
* @param config - EntityManager {@link Config | `Config`} object.
|
|
379
488
|
* @param logger - Logger object (defaults to `console`, must support `debug` & `error` methods).
|
|
380
489
|
*/
|
|
381
|
-
constructor(config: Config<
|
|
490
|
+
constructor(config: Config<CC>, logger?: Pick<Console, 'debug' | 'error'>);
|
|
382
491
|
/**
|
|
383
492
|
* Get the current EntityManager {@link Config | `Config`} object.
|
|
384
493
|
*
|
|
@@ -401,7 +510,7 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
401
510
|
*
|
|
402
511
|
* @throws `Error` if `property` is not a {@link Config | Config} `generatedProperties` key.
|
|
403
512
|
*/
|
|
404
|
-
encodeGeneratedProperty
|
|
513
|
+
encodeGeneratedProperty(property: CC['ShardedKeys'] | CC['UnshardedKeys'], item: EntityItem<CC>): string | undefined;
|
|
405
514
|
/**
|
|
406
515
|
* Update generated properties, hash key, and range key on an {@link EntityItem | `EntityItem`} object.
|
|
407
516
|
*
|
|
@@ -415,21 +524,11 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
415
524
|
*
|
|
416
525
|
* @overload
|
|
417
526
|
*/
|
|
418
|
-
addKeys(entityToken:
|
|
527
|
+
addKeys<ET extends EntityToken<CC>>(entityToken: ET, item: EntityItemByToken<CC, ET>, overwrite?: boolean): EntityRecordByToken<CC, ET>;
|
|
419
528
|
/**
|
|
420
|
-
* Update generated properties, hash key, and range key on an array of {@link EntityItem | `EntityItem`} objects.
|
|
421
|
-
*
|
|
422
|
-
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
423
|
-
* @param item - Array of {@link EntityItem | `EntityItem`} objects.
|
|
424
|
-
* @param overwrite - Overwrite existing properties (default `false`).
|
|
425
|
-
*
|
|
426
|
-
* @returns An array of {@link EntityRecord | `EntityRecord`} objects with updated properties.
|
|
427
|
-
*
|
|
428
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
429
|
-
*
|
|
430
529
|
* @overload
|
|
431
530
|
*/
|
|
432
|
-
addKeys(entityToken:
|
|
531
|
+
addKeys<ET extends EntityToken<CC>>(entityToken: ET, item: EntityItemByToken<CC, ET>[], overwrite?: boolean): EntityRecordByToken<CC, ET>[];
|
|
433
532
|
/**
|
|
434
533
|
* Convert one or more {@link EntityItem | `EntityItem`} objects into an array of {@link EntityKey | `EntityKey`} values.
|
|
435
534
|
*
|
|
@@ -442,8 +541,11 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
442
541
|
*
|
|
443
542
|
* @throws `Error` if `entityToken` is invalid.
|
|
444
543
|
*/
|
|
445
|
-
getPrimaryKey(entityToken:
|
|
446
|
-
|
|
544
|
+
getPrimaryKey<ET extends EntityToken<CC>>(entityToken: ET, item: EntityItemByToken<CC, ET>, overwrite?: boolean): EntityKey<CC>[];
|
|
545
|
+
/**
|
|
546
|
+
* @overload
|
|
547
|
+
*/
|
|
548
|
+
getPrimaryKey<ET extends EntityToken<CC>>(entityToken: ET, items: EntityItemByToken<CC, ET>[], overwrite?: boolean): EntityKey<CC>[];
|
|
447
549
|
/**
|
|
448
550
|
* Strips generated properties, hash key, and range key from an {@link EntityRecord | `EntityRecord`} object.
|
|
449
551
|
*
|
|
@@ -456,20 +558,11 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
456
558
|
*
|
|
457
559
|
* @overload
|
|
458
560
|
*/
|
|
459
|
-
removeKeys(entityToken:
|
|
561
|
+
removeKeys<ET extends EntityToken<CC>>(entityToken: ET, item: EntityRecordByToken<CC, ET>): EntityItemByToken<CC, ET>;
|
|
460
562
|
/**
|
|
461
|
-
* Strips generated properties, hash key, and range key from an array of {@link EntityRecord | `EntityRecord`} objects.
|
|
462
|
-
*
|
|
463
|
-
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
464
|
-
* @param items - Array of {@link EntityRecord | `EntityRecord`} objects.
|
|
465
|
-
*
|
|
466
|
-
* @returns Array of {@link EntityItem | `EntityItem`} objects with generated properties, hash key & range key removed.
|
|
467
|
-
*
|
|
468
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
469
|
-
*
|
|
470
563
|
* @overload
|
|
471
564
|
*/
|
|
472
|
-
removeKeys(entityToken:
|
|
565
|
+
removeKeys<ET extends EntityToken<CC>>(entityToken: ET, items: EntityRecordByToken<CC, ET>[]): EntityItemByToken<CC, ET>[];
|
|
473
566
|
/**
|
|
474
567
|
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
475
568
|
*
|
|
@@ -504,21 +597,128 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
504
597
|
*
|
|
505
598
|
* @protected
|
|
506
599
|
*/
|
|
507
|
-
query(options: QueryOptions<
|
|
600
|
+
query<ET extends EntityToken<CC>, ITS extends string, CF = unknown>(options: QueryOptions<CC, ET, ITS, CF>): Promise<QueryResult<CC, ET, ITS>>;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Values-first config input used to capture literal tokens from the provided
|
|
605
|
+
* configuration value. This does not enforce full Config shape at compile
|
|
606
|
+
* time; runtime validation still occurs via Zod in the EntityManager.
|
|
607
|
+
*
|
|
608
|
+
* Keep this intentionally permissive to maximize inference from `as const`.
|
|
609
|
+
*/
|
|
610
|
+
interface ConfigInput {
|
|
611
|
+
hashKey: string;
|
|
612
|
+
rangeKey: string;
|
|
613
|
+
generatedProperties?: {
|
|
614
|
+
sharded?: Record<string, readonly string[]>;
|
|
615
|
+
unsharded?: Record<string, readonly string[]>;
|
|
616
|
+
};
|
|
617
|
+
propertyTranscodes?: Record<string, string>;
|
|
618
|
+
indexes?: Record<string, {
|
|
619
|
+
hashKey: string;
|
|
620
|
+
rangeKey: string;
|
|
621
|
+
projections?: string[];
|
|
622
|
+
}>;
|
|
623
|
+
entities?: Record<string, unknown>;
|
|
624
|
+
/**
|
|
625
|
+
* Optional Zod schemas for per-entity domain shapes (non-generated fields only).
|
|
626
|
+
*
|
|
627
|
+
* Important: Schemas MUST declare only base (non-generated) properties. Do not include
|
|
628
|
+
* global keys (hashKey/rangeKey) or any generated tokens (sharded/unsharded).
|
|
629
|
+
*/
|
|
630
|
+
entitiesSchema?: Record<string, ZodType>;
|
|
631
|
+
generatedKeyDelimiter?: string;
|
|
632
|
+
generatedValueDelimiter?: string;
|
|
633
|
+
shardKeyDelimiter?: string;
|
|
634
|
+
transcodes?: unknown;
|
|
635
|
+
throttle?: number;
|
|
508
636
|
}
|
|
637
|
+
type HashKeyFrom<CC> = CC extends {
|
|
638
|
+
hashKey: infer H;
|
|
639
|
+
} ? H & string : 'hashKey';
|
|
640
|
+
type RangeKeyFrom<CC> = CC extends {
|
|
641
|
+
rangeKey: infer R;
|
|
642
|
+
} ? R & string : 'rangeKey';
|
|
643
|
+
type ShardedKeysFrom<CC> = CC extends {
|
|
644
|
+
generatedProperties?: infer GP;
|
|
645
|
+
} ? GP extends {
|
|
646
|
+
sharded?: infer S;
|
|
647
|
+
} ? keyof S & string : never : never;
|
|
648
|
+
type UnshardedKeysFrom<CC> = CC extends {
|
|
649
|
+
generatedProperties?: infer GP;
|
|
650
|
+
} ? GP extends {
|
|
651
|
+
unsharded?: infer U;
|
|
652
|
+
} ? keyof U & string : never : never;
|
|
653
|
+
type TranscodedPropertiesFrom<CC> = CC extends {
|
|
654
|
+
propertyTranscodes?: infer PT;
|
|
655
|
+
} ? keyof PT & string : never;
|
|
656
|
+
/**
|
|
657
|
+
* Derive an EntityMap from CC.entitiesSchema when provided (values-first, no generics).
|
|
658
|
+
* Fallback to broad EntityMap if schemas are absent.
|
|
659
|
+
*/
|
|
660
|
+
type EntitiesFromSchema<CC> = CC extends {
|
|
661
|
+
entitiesSchema?: infer S;
|
|
662
|
+
} ? S extends Record<string, ZodType> ? {
|
|
663
|
+
[K in keyof S & string]: infer<S[K]>;
|
|
664
|
+
} & EntityMap : EntityMap : EntityMap;
|
|
665
|
+
/**
|
|
666
|
+
* Derive the union of index token names from a values-first config input.
|
|
667
|
+
*
|
|
668
|
+
* When the provided config literal carries an `indexes` object with preserved
|
|
669
|
+
* literal keys (prefer `as const` at call sites), this helper captures the
|
|
670
|
+
* index token union. Falls back to `string` if absent.
|
|
671
|
+
*/
|
|
672
|
+
type IndexTokensFrom<CC> = CC extends {
|
|
673
|
+
indexes?: infer I;
|
|
674
|
+
} ? keyof I & string : string;
|
|
675
|
+
/**
|
|
676
|
+
* Captures a BaseConfigMap-compatible type from a literal ConfigInput value
|
|
677
|
+
* and an EntityMap (defaults to MinimalEntityMapFrom<CC>).
|
|
678
|
+
*/
|
|
679
|
+
type CapturedConfigMapFrom<CC, EM extends EntityMap> = {
|
|
680
|
+
EntityMap: EM;
|
|
681
|
+
HashKey: HashKeyFrom<CC>;
|
|
682
|
+
RangeKey: RangeKeyFrom<CC>;
|
|
683
|
+
ShardedKeys: ShardedKeysFrom<CC>;
|
|
684
|
+
UnshardedKeys: UnshardedKeysFrom<CC>;
|
|
685
|
+
TranscodedProperties: TranscodedPropertiesFrom<CC>;
|
|
686
|
+
TranscodeRegistry: DefaultTranscodeRegistry;
|
|
687
|
+
} & BaseConfigMap;
|
|
688
|
+
/**
|
|
689
|
+
* Values-first factory that captures literal tokens and index names directly
|
|
690
|
+
* from the provided config value. Runtime config parsing/validation is
|
|
691
|
+
* unchanged (performed in the EntityManager constructor).
|
|
692
|
+
*
|
|
693
|
+
* @typeParam CC - Captured config input (values-first). Prefer `as const` and
|
|
694
|
+
* `satisfies` at call sites to preserve literal keys.
|
|
695
|
+
* @typeParam EM - EntityMap for the manager. Defaults to a minimal derived map
|
|
696
|
+
* from `CC.entitiesSchema` when present; otherwise falls back to EntityMap.
|
|
697
|
+
*/
|
|
698
|
+
declare function createEntityManager<const CC extends ConfigInput, EM extends EntityMap = EntitiesFromSchema<CC>>(config: CC, logger?: Pick<Console, 'debug' | 'error'>): EntityManager<CapturedConfigMapFrom<CC, EM>>;
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Database-facing record type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
|
|
702
|
+
*
|
|
703
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
704
|
+
*
|
|
705
|
+
* @category EntityManager
|
|
706
|
+
* @protected
|
|
707
|
+
*/
|
|
708
|
+
type EntityRecord<CC extends BaseConfigMap> = EntityItem<CC> & EntityKey<CC>;
|
|
509
709
|
|
|
510
710
|
/**
|
|
511
711
|
* Base EntityClient options.
|
|
512
712
|
*
|
|
513
|
-
* @typeParam
|
|
713
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
514
714
|
*
|
|
515
715
|
* @category EntityClient
|
|
516
716
|
*/
|
|
517
|
-
interface BaseEntityClientOptions<
|
|
717
|
+
interface BaseEntityClientOptions<CC extends BaseConfigMap> {
|
|
518
718
|
/** Default batch process options. */
|
|
519
719
|
batchProcessOptions?: Omit<BatchProcessOptions<unknown, unknown>, 'batchHandler' | 'unprocessedItemExtractor'>;
|
|
520
720
|
/** {@link EntityManager | `EntityManager`} instance. */
|
|
521
|
-
entityManager: EntityManager<
|
|
721
|
+
entityManager: EntityManager<CC>;
|
|
522
722
|
/** Injected logger object. Must support `debug` and `error` methods. Default: `console` */
|
|
523
723
|
logger?: Pick<Console, 'debug' | 'error'>;
|
|
524
724
|
}
|
|
@@ -526,40 +726,40 @@ interface BaseEntityClientOptions<C extends BaseConfigMap> {
|
|
|
526
726
|
/**
|
|
527
727
|
* Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
|
|
528
728
|
*
|
|
529
|
-
* @typeParam
|
|
729
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
530
730
|
*
|
|
531
731
|
* @category EntityClient
|
|
532
732
|
*/
|
|
533
|
-
declare abstract class BaseEntityClient<
|
|
733
|
+
declare abstract class BaseEntityClient<CC extends BaseConfigMap> {
|
|
534
734
|
/** Default batch process options. */
|
|
535
|
-
readonly batchProcessOptions: NonNullable<BaseEntityClientOptions<
|
|
735
|
+
readonly batchProcessOptions: NonNullable<BaseEntityClientOptions<CC>['batchProcessOptions']>;
|
|
536
736
|
/** {@link EntityManager | `EntityManager`} instance. */
|
|
537
|
-
readonly entityManager: EntityManager<
|
|
737
|
+
readonly entityManager: EntityManager<CC>;
|
|
538
738
|
/** Injected logger object. Must support `debug` and `error` methods. Default: `console` */
|
|
539
|
-
readonly logger: NonNullable<BaseEntityClientOptions<
|
|
739
|
+
readonly logger: NonNullable<BaseEntityClientOptions<CC>['logger']>;
|
|
540
740
|
/**
|
|
541
741
|
* DynamoDB EntityClient constructor.
|
|
542
742
|
*
|
|
543
743
|
* @param options - {@link BaseEntityClientOptions | `BaseEntityClientOptions`} object.
|
|
544
744
|
*/
|
|
545
|
-
constructor(options: BaseEntityClientOptions<
|
|
745
|
+
constructor(options: BaseEntityClientOptions<CC>);
|
|
546
746
|
}
|
|
547
747
|
|
|
548
748
|
/**
|
|
549
749
|
* Constructor options for {@link BaseQueryBuilder | `BaseQueryBuilder`}.
|
|
550
750
|
*
|
|
551
|
-
* @typeParam
|
|
751
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
552
752
|
* @typeParam EntityClient - {@link BaseEntityClient | `BaseEntityClient`} derived class instance.
|
|
553
753
|
*
|
|
554
754
|
* @category QueryBuilder
|
|
555
755
|
*/
|
|
556
|
-
interface BaseQueryBuilderOptions<
|
|
756
|
+
interface BaseQueryBuilderOptions<CC extends BaseConfigMap, EntityClient extends BaseEntityClient<CC>> {
|
|
557
757
|
/** {@link BaseEntityClient | `EntityClient`} instance. */
|
|
558
758
|
entityClient: EntityClient;
|
|
559
759
|
/** Entity token. */
|
|
560
|
-
entityToken: EntityToken<
|
|
760
|
+
entityToken: EntityToken<CC>;
|
|
561
761
|
/** Hash key token. */
|
|
562
|
-
hashKeyToken:
|
|
762
|
+
hashKeyToken: CC['HashKey'] | CC['ShardedKeys'];
|
|
563
763
|
/** Dehydrated page key map. */
|
|
564
764
|
pageKeyMap?: string;
|
|
565
765
|
}
|
|
@@ -569,28 +769,29 @@ interface BaseQueryBuilderOptions<C extends BaseConfigMap, EntityClient extends
|
|
|
569
769
|
*
|
|
570
770
|
* Same as {@link QueryOptions | `QueryOptions`} for {@link EntityManager.query | `EntityManager.query`}, excluding `entityToken`, `pageKeyMap`, and `shardQueryMap`.
|
|
571
771
|
*
|
|
572
|
-
* @typeParam
|
|
772
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
573
773
|
*
|
|
574
774
|
* @category QueryBuilder
|
|
575
775
|
*/
|
|
576
|
-
type QueryBuilderQueryOptions<
|
|
776
|
+
type QueryBuilderQueryOptions<CC extends BaseConfigMap, CF = unknown> = Omit<QueryOptions<CC, never, string, CF>, 'entityToken' | 'pageKeyMap' | 'shardQueryMap'>;
|
|
577
777
|
|
|
578
778
|
/**
|
|
579
779
|
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
580
780
|
*
|
|
581
|
-
* @typeParam
|
|
781
|
+
* @typeParam CC - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeRegistry | `TranscodeRegistry`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
582
782
|
* @typeParam EntityClient - {@link BaseEntityClient | `BaseEntityClient`} derived class instance.
|
|
583
783
|
* @typeParam IndexParams - Database platform-specific, index-specific query parameters.
|
|
784
|
+
* @typeParam CF - Optional values-first config literal type for page key narrowing.
|
|
584
785
|
*
|
|
585
786
|
* @category QueryBuilder
|
|
586
787
|
*/
|
|
587
|
-
declare abstract class BaseQueryBuilder<
|
|
788
|
+
declare abstract class BaseQueryBuilder<CC extends BaseConfigMap, EntityClient extends BaseEntityClient<CC>, IndexParams, ET extends EntityToken<CC> = EntityToken<CC>, ITS extends string = string, CF = unknown> {
|
|
588
789
|
/** {@link BaseEntityClient | `EntityClient`} instance. */
|
|
589
790
|
readonly entityClient: EntityClient;
|
|
590
791
|
/** Entity token. */
|
|
591
|
-
readonly entityToken: EntityToken<
|
|
792
|
+
readonly entityToken: EntityToken<CC>;
|
|
592
793
|
/** Hash key token. */
|
|
593
|
-
readonly hashKeyToken:
|
|
794
|
+
readonly hashKeyToken: CC['HashKey'] | CC['ShardedKeys'];
|
|
594
795
|
/** Dehydrated page key map. */
|
|
595
796
|
readonly pageKeyMap?: string;
|
|
596
797
|
/**
|
|
@@ -598,18 +799,18 @@ declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient ex
|
|
|
598
799
|
*
|
|
599
800
|
* @protected
|
|
600
801
|
*/
|
|
601
|
-
readonly indexParamsMap: Record<
|
|
802
|
+
readonly indexParamsMap: Record<ITS, IndexParams>;
|
|
602
803
|
/** BaseQueryBuilder constructor. */
|
|
603
|
-
constructor(options: BaseQueryBuilderOptions<
|
|
604
|
-
protected abstract getShardQueryFunction(indexToken:
|
|
804
|
+
constructor(options: BaseQueryBuilderOptions<CC, EntityClient>);
|
|
805
|
+
protected abstract getShardQueryFunction(indexToken: ITS): ShardQueryFunction<CC, ET, ITS, CF>;
|
|
605
806
|
/**
|
|
606
807
|
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
607
808
|
*
|
|
608
809
|
* @returns - The {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
609
810
|
*/
|
|
610
|
-
build(): ShardQueryMap<
|
|
611
|
-
query(options: QueryBuilderQueryOptions<
|
|
811
|
+
build(): ShardQueryMap<CC, ET, ITS, CF>;
|
|
812
|
+
query(options: QueryBuilderQueryOptions<CC, CF>): Promise<QueryResult<CC, ET, ITS>>;
|
|
612
813
|
}
|
|
613
814
|
|
|
614
|
-
export { BaseEntityClient, BaseQueryBuilder, EntityManager, configSchema };
|
|
615
|
-
export type { BaseConfigMap, BaseEntityClientOptions, BaseQueryBuilderOptions, Config, ConfigMap, EntityItem, EntityKey, EntityRecord, EntityToken, PageKey, ParsedConfig, QueryBuilderQueryOptions, QueryOptions, QueryResult, ShardBump, ShardQueryFunction, ShardQueryMap, ShardQueryResult, ValidateConfigMap };
|
|
815
|
+
export { BaseEntityClient, BaseQueryBuilder, EntityManager, configSchema, createEntityManager };
|
|
816
|
+
export type { BaseConfigMap, BaseEntityClientOptions, BaseQueryBuilderOptions, CapturedConfigMapFrom, Config, ConfigInput, ConfigMap, EntitiesFromSchema, EntityItem, EntityItemByToken, EntityKey, EntityOfToken, EntityRecord, EntityRecordByToken, EntityToken, HasIndexFor, HashKeyFrom, IndexComponentTokens, IndexHashKeyOf, IndexRangeKeyOf, IndexTokensFrom, IndexTokensOf, PageKey, PageKeyByIndex, ParsedConfig, QueryBuilderQueryOptions, QueryOptions, QueryOptionsByCC, QueryOptionsByCF, QueryResult, RangeKeyFrom, ShardBump, ShardQueryFunction, ShardQueryMap, ShardQueryMapByCC, ShardQueryMapByCF, ShardQueryResult, ShardedKeysFrom, TranscodedPropertiesFrom, UnshardedKeysFrom, ValidateConfigMap };
|