@karmaniverous/entity-manager 6.8.0 → 6.9.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 +1 -1
- package/dist/cjs/BaseQueryBuilder.js +4 -0
- package/dist/cjs/EntityManager.js +10 -1
- package/dist/cjs/encodeGeneratedProperty.js +1 -4
- package/dist/cjs/index.js +0 -2
- package/dist/index.d.ts +132 -42
- package/dist/mjs/BaseQueryBuilder.js +4 -0
- package/dist/mjs/EntityManager.js +10 -1
- package/dist/mjs/encodeGeneratedProperty.js +1 -4
- package/dist/mjs/index.js +0 -1
- package/package.json +3 -3
- package/dist/cjs/conditionalize.js +0 -25
- package/dist/mjs/conditionalize.js +0 -23
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
**EntityManager implements rational indexing & cross-shard querying at scale in your NoSQL database so you can focus on your application logic.**
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
> The Typescript refactor is still in flux, but stabilizing! Still fleshing out the [demo](https://github.com/karmaniverous/entity-manager-demo) & [documentation](https://karmanivero.us/projects/entity-manager/intro/).
|
|
12
12
|
|
|
13
13
|
If you have any questions, please [start a discussion](https://github.com/karmaniverous/entity-manager/discussions). Otherwise stay tuned!
|
|
14
14
|
|
|
@@ -5,6 +5,10 @@ var radash = require('radash');
|
|
|
5
5
|
/**
|
|
6
6
|
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
7
7
|
*
|
|
8
|
+
* @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`}.
|
|
9
|
+
* @typeParam EntityClient - {@link BaseEntityClient | `BaseEntityClient`} derived class instance.
|
|
10
|
+
* @typeParam IndexParams - Database platform-specific, index-specific query parameters.
|
|
11
|
+
*
|
|
8
12
|
* @category QueryBuilder
|
|
9
13
|
*/
|
|
10
14
|
class BaseQueryBuilder {
|
|
@@ -11,7 +11,12 @@ var _EntityManager_config;
|
|
|
11
11
|
* The EntityManager class applies a configuration-driven sharded data model &
|
|
12
12
|
* query strategy to NoSql data.
|
|
13
13
|
*
|
|
14
|
-
* @
|
|
14
|
+
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines the configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* 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.
|
|
18
|
+
*
|
|
19
|
+
* @category EntityManager
|
|
15
20
|
*/
|
|
16
21
|
class EntityManager {
|
|
17
22
|
/**
|
|
@@ -80,11 +85,15 @@ class EntityManager {
|
|
|
80
85
|
*
|
|
81
86
|
* Unsharded query results should sort & page as expected.
|
|
82
87
|
*
|
|
88
|
+
* **Normally this method should not be called directly!** It is used by a platform-specific {@link BaseQueryBuilder.query | `QueryBuilder.query`} method to provide a fluent query API.
|
|
89
|
+
*
|
|
83
90
|
* @param options - {@link QueryOptions | `QueryOptions`} object.
|
|
84
91
|
*
|
|
85
92
|
* @returns {@link QueryResult} object.
|
|
86
93
|
*
|
|
87
94
|
* @throws Error if `options` {@link QueryOptions.pageKeyMap | `pageKeyMap`} `pageKeyMap` keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
95
|
+
*
|
|
96
|
+
* @protected
|
|
88
97
|
*/
|
|
89
98
|
async query(options) {
|
|
90
99
|
return await query.query(this, options);
|
|
@@ -21,10 +21,7 @@ function encodeGeneratedProperty(entityManager, property, item) {
|
|
|
21
21
|
const sharded = property in entityManager.config.generatedProperties.sharded;
|
|
22
22
|
const elements = entityManager.config.generatedProperties[sharded ? 'sharded' : 'unsharded'][property];
|
|
23
23
|
// Map elements to [element, value] pairs.
|
|
24
|
-
const elementMap = elements.map((element) => [
|
|
25
|
-
element,
|
|
26
|
-
item[element],
|
|
27
|
-
]);
|
|
24
|
+
const elementMap = elements.map((element) => [element, item[element]]);
|
|
28
25
|
// Return undefined if sharded & atomicity requirement fails.
|
|
29
26
|
if (sharded && elementMap.some(([, value]) => entityTools.isNil(value)))
|
|
30
27
|
return;
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var BaseEntityClient = require('./BaseEntityClient.js');
|
|
4
4
|
var BaseQueryBuilder = require('./BaseQueryBuilder.js');
|
|
5
|
-
var conditionalize = require('./conditionalize.js');
|
|
6
5
|
var EntityManager = require('./EntityManager.js');
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
exports.BaseEntityClient = BaseEntityClient.BaseEntityClient;
|
|
11
10
|
exports.BaseQueryBuilder = BaseQueryBuilder.BaseQueryBuilder;
|
|
12
|
-
exports.conditionalize = conditionalize.conditionalize;
|
|
13
11
|
exports.EntityManager = EntityManager.EntityManager;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { EntityMap, TranscodeMap, FlattenEntityMap, Exactify, PropertiesOfType, TranscodableProperties, Transcodes, SortOrder } from '@karmaniverous/entity-tools';
|
|
1
|
+
import { EntityMap, TranscodeMap, FlattenEntityMap, ConditionalProperty, Exactify, PropertiesOfType, TranscodableProperties, Transcodes, SortOrder, MutuallyExclusive, NotNever, DefaultTranscodeMap } from '@karmaniverous/entity-tools';
|
|
2
2
|
import { BatchProcessOptions } from '@karmaniverous/batch-process';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Default type parameter for {@link ConfigMap | `ConfigMap`}.
|
|
7
|
+
*
|
|
8
|
+
* @category EntityManager
|
|
9
|
+
*/
|
|
5
10
|
interface BaseConfigMap {
|
|
6
11
|
EntityMap: EntityMap;
|
|
7
12
|
HashKey: string;
|
|
@@ -43,15 +48,20 @@ declare abstract class BaseEntityClient {
|
|
|
43
48
|
/**
|
|
44
49
|
* Extracts a database-facing partial item type from a {@link BaseConfigMap | `ConfigMap`}.
|
|
45
50
|
*
|
|
46
|
-
* @
|
|
51
|
+
* @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`}.
|
|
52
|
+
*
|
|
53
|
+
* @category EntityManager
|
|
54
|
+
* @protected
|
|
47
55
|
*/
|
|
48
56
|
type EntityItem<C extends BaseConfigMap> = Partial<FlattenEntityMap<C['EntityMap']> & Record<C['HashKey'] | C['RangeKey'] | C['ShardedKeys'] | C['UnshardedKeys'], string>> & Record<string, unknown>;
|
|
49
57
|
|
|
50
58
|
/**
|
|
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`}.
|
|
59
|
+
* A result returned by a query across multiple shards, where each shard may receive multiple page queries via a dynamically-generated {@link ShardQueryFunction | `ShardQueryFunction`}.
|
|
53
60
|
*
|
|
54
|
-
* @
|
|
61
|
+
* @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`}.
|
|
62
|
+
*
|
|
63
|
+
* @category EntityManager
|
|
64
|
+
* @protected
|
|
55
65
|
*/
|
|
56
66
|
interface QueryResult<C extends BaseConfigMap> {
|
|
57
67
|
/** Total number of records returned across all shards. */
|
|
@@ -65,21 +75,10 @@ interface QueryResult<C extends BaseConfigMap> {
|
|
|
65
75
|
pageKeyMap: string;
|
|
66
76
|
}
|
|
67
77
|
|
|
68
|
-
/**
|
|
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.
|
|
70
|
-
*
|
|
71
|
-
* @typeParam K - The property key.
|
|
72
|
-
* @typeParam C - The condition to check.
|
|
73
|
-
* @typeParam O - The type of the property.
|
|
74
|
-
*/
|
|
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
|
-
|
|
79
78
|
/**
|
|
80
79
|
* Defines a single time period in an entity sharding strategy.
|
|
81
80
|
*
|
|
82
|
-
* @category
|
|
81
|
+
* @category EntityManager
|
|
83
82
|
* @protected
|
|
84
83
|
*/
|
|
85
84
|
interface ShardBump {
|
|
@@ -104,7 +103,14 @@ interface ShardBump {
|
|
|
104
103
|
chars: number;
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Configuration object for an {@link EntityManager | `EntityManager`} instance.
|
|
108
|
+
*
|
|
109
|
+
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines the configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
110
|
+
*
|
|
111
|
+
* @category EntityManager
|
|
112
|
+
*/
|
|
113
|
+
type Config<C extends BaseConfigMap = BaseConfigMap> = ConditionalProperty<'entities', keyof Exactify<C['EntityMap']>, {
|
|
108
114
|
[E in keyof Exactify<C['EntityMap']>]: {
|
|
109
115
|
defaultLimit?: number;
|
|
110
116
|
defaultPageSize?: number;
|
|
@@ -128,6 +134,14 @@ type Config<C extends BaseConfigMap> = ConditionalProperty<'entities', keyof Exa
|
|
|
128
134
|
throttle?: number;
|
|
129
135
|
};
|
|
130
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Extracts entity tokens from a {@link ConfigMap | `ConfigMap`}.
|
|
139
|
+
*
|
|
140
|
+
* @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`}.
|
|
141
|
+
*
|
|
142
|
+
* @category EntityManager
|
|
143
|
+
* @protected
|
|
144
|
+
*/
|
|
131
145
|
type EntityToken<C extends BaseConfigMap> = keyof Exactify<C['EntityMap']> & string;
|
|
132
146
|
|
|
133
147
|
declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
@@ -235,6 +249,8 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
235
249
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
236
250
|
}>>>>;
|
|
237
251
|
}, "strict", z.ZodTypeAny, {
|
|
252
|
+
hashKey: string;
|
|
253
|
+
rangeKey: string;
|
|
238
254
|
throttle: number;
|
|
239
255
|
entities: Record<string, {
|
|
240
256
|
defaultLimit: number;
|
|
@@ -251,8 +267,6 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
251
267
|
sharded: Record<string, [string, ...string[]]>;
|
|
252
268
|
unsharded: Record<string, [string, ...string[]]>;
|
|
253
269
|
};
|
|
254
|
-
hashKey: string;
|
|
255
|
-
rangeKey: string;
|
|
256
270
|
indexes: Record<string, {
|
|
257
271
|
hashKey: string;
|
|
258
272
|
rangeKey: string;
|
|
@@ -299,6 +313,8 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
299
313
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
300
314
|
}> | undefined;
|
|
301
315
|
}>, {
|
|
316
|
+
hashKey: string;
|
|
317
|
+
rangeKey: string;
|
|
302
318
|
throttle: number;
|
|
303
319
|
entities: Record<string, {
|
|
304
320
|
defaultLimit: number;
|
|
@@ -315,8 +331,6 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
315
331
|
sharded: Record<string, [string, ...string[]]>;
|
|
316
332
|
unsharded: Record<string, [string, ...string[]]>;
|
|
317
333
|
};
|
|
318
|
-
hashKey: string;
|
|
319
|
-
rangeKey: string;
|
|
320
334
|
indexes: Record<string, {
|
|
321
335
|
hashKey: string;
|
|
322
336
|
rangeKey: string;
|
|
@@ -366,14 +380,17 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
366
380
|
/**
|
|
367
381
|
* Simplified type taken on by a {@link Config | `Config`} object after parsing in the {@link EntityManager | `EntityManager`} constructor.
|
|
368
382
|
*
|
|
369
|
-
* @category
|
|
383
|
+
* @category EntityManager
|
|
370
384
|
*/
|
|
371
385
|
type ParsedConfig = z.infer<typeof configSchema>;
|
|
372
386
|
|
|
373
387
|
/**
|
|
374
388
|
* A result returned by a {@link ShardQueryFunction | `ShardQueryFunction`} querying an individual shard.
|
|
375
389
|
*
|
|
376
|
-
* @
|
|
390
|
+
* @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`}.
|
|
391
|
+
*
|
|
392
|
+
* @category EntityManager
|
|
393
|
+
* @protected
|
|
377
394
|
*/
|
|
378
395
|
interface ShardQueryResult<C extends BaseConfigMap> {
|
|
379
396
|
/** The number of records returned. */
|
|
@@ -385,28 +402,38 @@ interface ShardQueryResult<C extends BaseConfigMap> {
|
|
|
385
402
|
}
|
|
386
403
|
|
|
387
404
|
/**
|
|
388
|
-
* A query function that returns a single page of results from an individual
|
|
389
|
-
*
|
|
390
|
-
* specific query index & logic. The arguments to this function will be
|
|
391
|
-
* provided by the {@link EntityManager.query | `EntityManager.query`} method, which assembles many returned
|
|
392
|
-
* pages queried across multiple shards into a single query result.
|
|
405
|
+
* A query function that returns a single page of results from an individual shard.
|
|
406
|
+
*
|
|
407
|
+
* 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.
|
|
393
408
|
*
|
|
394
|
-
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
395
|
-
|
|
396
409
|
* @param hashKey - The hash key value of the shard being queried.
|
|
397
410
|
* @param pageKey - The page key returned by the previous query on this shard.
|
|
398
411
|
* @param pageSize - The maximum number of items to return from this query.
|
|
399
412
|
*
|
|
400
|
-
* @
|
|
413
|
+
* @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`}.
|
|
414
|
+
*
|
|
415
|
+
* @category EntityManager
|
|
416
|
+
* @protected
|
|
401
417
|
*/
|
|
402
418
|
type ShardQueryFunction<C extends BaseConfigMap> = (hashKey: string, pageKey?: EntityItem<C>, pageSize?: number) => Promise<ShardQueryResult<C>>;
|
|
403
419
|
|
|
420
|
+
/**
|
|
421
|
+
* Relates a specific index token to a {@link ShardQueryFunction | `ShardQueryFunction`} to be performed on that index.
|
|
422
|
+
*
|
|
423
|
+
* @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`}.
|
|
424
|
+
*
|
|
425
|
+
* @category EntityManager
|
|
426
|
+
* @protected
|
|
427
|
+
*/
|
|
404
428
|
type ShardQueryMap<C extends BaseConfigMap> = Record<string, ShardQueryFunction<C>>;
|
|
405
429
|
|
|
406
430
|
/**
|
|
407
431
|
* Options passed to the {@link EntityManager.query | `EntityManager.query`} method.
|
|
408
432
|
*
|
|
409
|
-
* @
|
|
433
|
+
* @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`}.
|
|
434
|
+
*
|
|
435
|
+
* @category EntityManager
|
|
436
|
+
* @protected
|
|
410
437
|
*/
|
|
411
438
|
interface QueryOptions<C extends BaseConfigMap> {
|
|
412
439
|
/** Identifies the entity to be queried. Key of {@link Config | `Config`} `entities`. */
|
|
@@ -483,9 +510,14 @@ interface QueryOptions<C extends BaseConfigMap> {
|
|
|
483
510
|
* The EntityManager class applies a configuration-driven sharded data model &
|
|
484
511
|
* query strategy to NoSql data.
|
|
485
512
|
*
|
|
486
|
-
* @
|
|
513
|
+
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines the configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
514
|
+
*
|
|
515
|
+
* @remarks
|
|
516
|
+
* 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.
|
|
517
|
+
*
|
|
518
|
+
* @category EntityManager
|
|
487
519
|
*/
|
|
488
|
-
declare class EntityManager<C extends BaseConfigMap> {
|
|
520
|
+
declare class EntityManager<C extends BaseConfigMap = BaseConfigMap> {
|
|
489
521
|
#private;
|
|
490
522
|
readonly logger: Pick<Console, 'debug' | 'error'>;
|
|
491
523
|
/**
|
|
@@ -542,11 +574,15 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
542
574
|
*
|
|
543
575
|
* Unsharded query results should sort & page as expected.
|
|
544
576
|
*
|
|
577
|
+
* **Normally this method should not be called directly!** It is used by a platform-specific {@link BaseQueryBuilder.query | `QueryBuilder.query`} method to provide a fluent query API.
|
|
578
|
+
*
|
|
545
579
|
* @param options - {@link QueryOptions | `QueryOptions`} object.
|
|
546
580
|
*
|
|
547
581
|
* @returns {@link QueryResult} object.
|
|
548
582
|
*
|
|
549
583
|
* @throws Error if `options` {@link QueryOptions.pageKeyMap | `pageKeyMap`} `pageKeyMap` keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
584
|
+
*
|
|
585
|
+
* @protected
|
|
550
586
|
*/
|
|
551
587
|
query(options: QueryOptions<C>): Promise<QueryResult<C>>;
|
|
552
588
|
}
|
|
@@ -554,6 +590,9 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
554
590
|
/**
|
|
555
591
|
* Constructor options for {@link BaseQueryBuilder | `BaseQueryBuilder`}.
|
|
556
592
|
*
|
|
593
|
+
* @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`}.
|
|
594
|
+
* @typeParam EntityClient - {@link BaseEntityClient | `BaseEntityClient`} derived class instance.
|
|
595
|
+
*
|
|
557
596
|
* @category QueryBuilder
|
|
558
597
|
*/
|
|
559
598
|
interface BaseQueryBuilderOptions<C extends BaseConfigMap, EntityClient extends BaseEntityClient> {
|
|
@@ -569,11 +608,24 @@ interface BaseQueryBuilderOptions<C extends BaseConfigMap, EntityClient extends
|
|
|
569
608
|
pageKeyMap?: string;
|
|
570
609
|
}
|
|
571
610
|
|
|
611
|
+
/**
|
|
612
|
+
* Options for {@link BaseQueryBuilder.query | `query`} method on all derived classes.
|
|
613
|
+
*
|
|
614
|
+
* Same as {@link QueryOptions | `QueryOptions`} for {@link EntityManager.query | `EntityManager.query`}, excluding `entityToken`, `pageKeyMap`, and `shardQueryMap`.
|
|
615
|
+
*
|
|
616
|
+
* @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`}.
|
|
617
|
+
*
|
|
618
|
+
* @category QueryBuilder
|
|
619
|
+
*/
|
|
572
620
|
type QueryBuilderQueryOptions<C extends BaseConfigMap> = Omit<QueryOptions<C>, 'entityToken' | 'pageKeyMap' | 'shardQueryMap'>;
|
|
573
621
|
|
|
574
622
|
/**
|
|
575
623
|
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
576
624
|
*
|
|
625
|
+
* @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`}.
|
|
626
|
+
* @typeParam EntityClient - {@link BaseEntityClient | `BaseEntityClient`} derived class instance.
|
|
627
|
+
* @typeParam IndexParams - Database platform-specific, index-specific query parameters.
|
|
628
|
+
*
|
|
577
629
|
* @category QueryBuilder
|
|
578
630
|
*/
|
|
579
631
|
declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient extends BaseEntityClient, IndexParams> {
|
|
@@ -606,16 +658,54 @@ declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient ex
|
|
|
606
658
|
}
|
|
607
659
|
|
|
608
660
|
/**
|
|
609
|
-
*
|
|
661
|
+
* 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.
|
|
662
|
+
*
|
|
663
|
+
* @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`}.
|
|
664
|
+
*
|
|
665
|
+
* @category EntityManager
|
|
666
|
+
* @protected
|
|
667
|
+
*/
|
|
668
|
+
type ValidateConfigMap<C extends BaseConfigMap> = MutuallyExclusive<[
|
|
669
|
+
C['HashKey'],
|
|
670
|
+
C['RangeKey'],
|
|
671
|
+
C['ShardedKeys'],
|
|
672
|
+
C['UnshardedKeys'],
|
|
673
|
+
keyof FlattenEntityMap<C['EntityMap']>
|
|
674
|
+
]> extends true ? NotNever<C, ['HashKey' | 'RangeKey']> extends true ? C : Exclude<NotNever<C, ['HashKey' | 'RangeKey']>, true> : Exclude<MutuallyExclusive<[
|
|
675
|
+
C['HashKey'],
|
|
676
|
+
C['RangeKey'],
|
|
677
|
+
C['ShardedKeys'],
|
|
678
|
+
C['UnshardedKeys'],
|
|
679
|
+
keyof FlattenEntityMap<C['EntityMap']>
|
|
680
|
+
]>, true>;
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Generates & validates the map defining defines an {@link EntityManager | `EntityManager`} configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}.
|
|
684
|
+
*
|
|
685
|
+
* Unspecified properties will default to those defined in {@link BaseConfigMap | `BaseConfigMap`}.
|
|
610
686
|
*
|
|
611
|
-
* @
|
|
612
|
-
* @param condition - The condition to check before executing `fn`.
|
|
687
|
+
* @typeParam M - {@link BaseConfigMap | `BaseConfigMap`} extension. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
613
688
|
*
|
|
614
|
-
* @
|
|
689
|
+
* @category EntityManager
|
|
690
|
+
*/
|
|
691
|
+
type ConfigMap<M extends Partial<BaseConfigMap> = Partial<BaseConfigMap>> = ValidateConfigMap<{
|
|
692
|
+
EntityMap: 'EntityMap' extends keyof M ? NonNullable<M['EntityMap']> : Record<string, never>;
|
|
693
|
+
HashKey: 'HashKey' extends keyof M ? NonNullable<M['HashKey']> : 'hashKey';
|
|
694
|
+
RangeKey: 'RangeKey' extends keyof M ? NonNullable<M['RangeKey']> : 'rangeKey';
|
|
695
|
+
ShardedKeys: 'ShardedKeys' extends keyof M ? NonNullable<M['ShardedKeys']> : never;
|
|
696
|
+
UnshardedKeys: 'UnshardedKeys' extends keyof M ? NonNullable<M['UnshardedKeys']> : never;
|
|
697
|
+
TranscodedProperties: 'TranscodedProperties' extends keyof M ? NonNullable<M['TranscodedProperties']> : never;
|
|
698
|
+
TranscodeMap: 'TranscodeMap' extends keyof M ? NonNullable<M['TranscodeMap']> : DefaultTranscodeMap;
|
|
699
|
+
}>;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* A partial {@link EntityItem | `EntityItem`} restricted to keys defined in `C`.
|
|
615
703
|
*
|
|
616
|
-
* @
|
|
704
|
+
* @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`}.
|
|
617
705
|
*
|
|
706
|
+
* @category QueryBuilder
|
|
707
|
+
* @protected
|
|
618
708
|
*/
|
|
619
|
-
|
|
709
|
+
type PageKey<C extends BaseConfigMap> = Pick<EntityItem<C>, C['HashKey'] | C['RangeKey'] | C['ShardedKeys'] | C['UnshardedKeys'] | C['TranscodedProperties']>;
|
|
620
710
|
|
|
621
|
-
export { type BaseConfigMap, BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type
|
|
711
|
+
export { type BaseConfigMap, BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type Config, type ConfigMap, type EntityItem, EntityManager, type EntityToken, type PageKey, type ParsedConfig, type QueryBuilderQueryOptions, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type ValidateConfigMap };
|
|
@@ -3,6 +3,10 @@ import { mapValues } from 'radash';
|
|
|
3
3
|
/**
|
|
4
4
|
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
5
5
|
*
|
|
6
|
+
* @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`}.
|
|
7
|
+
* @typeParam EntityClient - {@link BaseEntityClient | `BaseEntityClient`} derived class instance.
|
|
8
|
+
* @typeParam IndexParams - Database platform-specific, index-specific query parameters.
|
|
9
|
+
*
|
|
6
10
|
* @category QueryBuilder
|
|
7
11
|
*/
|
|
8
12
|
class BaseQueryBuilder {
|
|
@@ -9,7 +9,12 @@ var _EntityManager_config;
|
|
|
9
9
|
* The EntityManager class applies a configuration-driven sharded data model &
|
|
10
10
|
* query strategy to NoSql data.
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
12
|
+
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines the configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* 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.
|
|
16
|
+
*
|
|
17
|
+
* @category EntityManager
|
|
13
18
|
*/
|
|
14
19
|
class EntityManager {
|
|
15
20
|
/**
|
|
@@ -78,11 +83,15 @@ class EntityManager {
|
|
|
78
83
|
*
|
|
79
84
|
* Unsharded query results should sort & page as expected.
|
|
80
85
|
*
|
|
86
|
+
* **Normally this method should not be called directly!** It is used by a platform-specific {@link BaseQueryBuilder.query | `QueryBuilder.query`} method to provide a fluent query API.
|
|
87
|
+
*
|
|
81
88
|
* @param options - {@link QueryOptions | `QueryOptions`} object.
|
|
82
89
|
*
|
|
83
90
|
* @returns {@link QueryResult} object.
|
|
84
91
|
*
|
|
85
92
|
* @throws Error if `options` {@link QueryOptions.pageKeyMap | `pageKeyMap`} `pageKeyMap` keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
93
|
+
*
|
|
94
|
+
* @protected
|
|
86
95
|
*/
|
|
87
96
|
async query(options) {
|
|
88
97
|
return await query(this, options);
|
|
@@ -19,10 +19,7 @@ function encodeGeneratedProperty(entityManager, property, item) {
|
|
|
19
19
|
const sharded = property in entityManager.config.generatedProperties.sharded;
|
|
20
20
|
const elements = entityManager.config.generatedProperties[sharded ? 'sharded' : 'unsharded'][property];
|
|
21
21
|
// Map elements to [element, value] pairs.
|
|
22
|
-
const elementMap = elements.map((element) => [
|
|
23
|
-
element,
|
|
24
|
-
item[element],
|
|
25
|
-
]);
|
|
22
|
+
const elementMap = elements.map((element) => [element, item[element]]);
|
|
26
23
|
// Return undefined if sharded & atomicity requirement fails.
|
|
27
24
|
if (sharded && elementMap.some(([, value]) => isNil(value)))
|
|
28
25
|
return;
|
package/dist/mjs/index.js
CHANGED
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@karmaniverous/batch-process": "^0.1.0",
|
|
8
|
-
"@karmaniverous/entity-tools": "^0.
|
|
8
|
+
"@karmaniverous/entity-tools": "^0.6.1",
|
|
9
9
|
"@karmaniverous/string-utilities": "^0.2.1",
|
|
10
10
|
"lz-string": "^1.5.0",
|
|
11
11
|
"radash": "^12.1.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
40
40
|
"eslint-plugin-tsdoc": "^0.3.0",
|
|
41
41
|
"jsdom-global": "^3.0.2",
|
|
42
|
-
"knip": "^5.36.
|
|
42
|
+
"knip": "^5.36.5",
|
|
43
43
|
"lefthook": "^1.8.2",
|
|
44
44
|
"mocha": "^10.8.2",
|
|
45
45
|
"nyc": "^17.1.0",
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
},
|
|
133
133
|
"type": "module",
|
|
134
134
|
"types": "dist/index.d.ts",
|
|
135
|
-
"version": "6.
|
|
135
|
+
"version": "6.9.0"
|
|
136
136
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Transforms a function such that it only executes when `condition` is truthy.
|
|
5
|
-
*
|
|
6
|
-
* @param fn - The function to conditionally execute.
|
|
7
|
-
* @param condition - The condition to check before executing `fn`.
|
|
8
|
-
*
|
|
9
|
-
* @typeParam F - The type of the function to conditionally execute.
|
|
10
|
-
*
|
|
11
|
-
* @returns The conditionalized function with the same signature as `fn`.
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
function conditionalize(fn, condition) {
|
|
15
|
-
return (...args) => {
|
|
16
|
-
if (condition) {
|
|
17
|
-
return fn(...args);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.conditionalize = conditionalize;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transforms a function such that it only executes when `condition` is truthy.
|
|
3
|
-
*
|
|
4
|
-
* @param fn - The function to conditionally execute.
|
|
5
|
-
* @param condition - The condition to check before executing `fn`.
|
|
6
|
-
*
|
|
7
|
-
* @typeParam F - The type of the function to conditionally execute.
|
|
8
|
-
*
|
|
9
|
-
* @returns The conditionalized function with the same signature as `fn`.
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
function conditionalize(fn, condition) {
|
|
13
|
-
return (...args) => {
|
|
14
|
-
if (condition) {
|
|
15
|
-
return fn(...args);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { conditionalize };
|