@karmaniverous/entity-manager 6.6.0 → 6.7.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/BaseShardQueryMapBuilder.js +34 -0
- package/dist/cjs/EntityManager.js +12 -3
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/query.js +4 -4
- package/dist/index.d.ts +91 -75
- package/dist/mjs/BaseShardQueryMapBuilder.js +32 -0
- package/dist/mjs/EntityManager.js +12 -3
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/query.js +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var radash = require('radash');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
7
|
+
*
|
|
8
|
+
* @category ShardQueryMapBuilder
|
|
9
|
+
*/
|
|
10
|
+
class BaseShardQueryMapBuilder {
|
|
11
|
+
/** BaseShardQueryMapBuilder constructor. */
|
|
12
|
+
constructor(entityManager, entityToken, hashKeyToken, pageKeyMap) {
|
|
13
|
+
this.entityManager = entityManager;
|
|
14
|
+
this.entityToken = entityToken;
|
|
15
|
+
this.hashKeyToken = hashKeyToken;
|
|
16
|
+
this.pageKeyMap = pageKeyMap;
|
|
17
|
+
/**
|
|
18
|
+
* Maps `indexToken` values to database platform-specific parameters.
|
|
19
|
+
*
|
|
20
|
+
* @protected
|
|
21
|
+
*/
|
|
22
|
+
this.indexParamsMap = {};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
26
|
+
*
|
|
27
|
+
* @returns - The {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
28
|
+
*/
|
|
29
|
+
build() {
|
|
30
|
+
return radash.mapValues(this.indexParamsMap, (indexConfig, indexToken) => this.getShardQueryFunction(indexToken));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.BaseShardQueryMapBuilder = BaseShardQueryMapBuilder;
|
|
@@ -72,7 +72,7 @@ class EntityManager {
|
|
|
72
72
|
* Query a database entity across shards in a provider-generic fashion.
|
|
73
73
|
*
|
|
74
74
|
* @remarks
|
|
75
|
-
* The provided
|
|
75
|
+
* The provided `shardQueryMap` performs the actual query of individual data pages on individual index/shard combinations.
|
|
76
76
|
*
|
|
77
77
|
* Individual shard query results will be combined, deduped by {@link ConfigEntity.uniqueProperty} property value, and sorted by {@link QueryOptions.sortOrder | `sortOrder`}.
|
|
78
78
|
*
|
|
@@ -84,10 +84,19 @@ class EntityManager {
|
|
|
84
84
|
*
|
|
85
85
|
* @returns {@link QueryResult} object.
|
|
86
86
|
*
|
|
87
|
-
* @throws Error if {@link QueryOptions.
|
|
87
|
+
* @throws Error if {@link QueryOptions.shardQueryMapBuilder | `shardQueryMapBuilder`} `pageKeyMap` keys do not match its `shardQueryMap` keys.
|
|
88
88
|
*/
|
|
89
89
|
async query(options) {
|
|
90
|
-
|
|
90
|
+
const { shardQueryMapBuilder, ...baseOptions } = options;
|
|
91
|
+
const { entityToken, hashKeyToken, pageKeyMap } = shardQueryMapBuilder;
|
|
92
|
+
const shardQueryMap = shardQueryMapBuilder.build();
|
|
93
|
+
return await query.query(this, {
|
|
94
|
+
entityToken,
|
|
95
|
+
hashKeyToken,
|
|
96
|
+
pageKeyMap,
|
|
97
|
+
shardQueryMap,
|
|
98
|
+
...baseOptions,
|
|
99
|
+
});
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
_EntityManager_config = new WeakMap();
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var BaseShardQueryMapBuilder = require('./BaseShardQueryMapBuilder.js');
|
|
3
4
|
var conditionalize = require('./conditionalize.js');
|
|
4
5
|
var EntityManager = require('./EntityManager.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
exports.BaseShardQueryMapBuilder = BaseShardQueryMapBuilder.BaseShardQueryMapBuilder;
|
|
8
10
|
exports.conditionalize = conditionalize.conditionalize;
|
|
9
11
|
exports.EntityManager = EntityManager.EntityManager;
|
package/dist/cjs/query.js
CHANGED
|
@@ -27,14 +27,14 @@ const { compressToEncodedURIComponent, decompressFromEncodedURIComponent } = lzS
|
|
|
27
27
|
*
|
|
28
28
|
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
29
29
|
*/
|
|
30
|
-
async function query(entityManager, { entityToken,
|
|
30
|
+
async function query(entityManager, { entityToken, hashKeyToken, limit, pageKeyMap, pageSize, shardQueryMap, sortOrder = [], timestampFrom = 0, timestampTo = Date.now(), throttle = entityManager.config.throttle, }) {
|
|
31
31
|
try {
|
|
32
32
|
// Get defaults.
|
|
33
33
|
const { defaultLimit, defaultPageSize } = entityManager.config.entities[entityToken];
|
|
34
34
|
limit ?? (limit = defaultLimit);
|
|
35
35
|
pageSize ?? (pageSize = defaultPageSize);
|
|
36
36
|
// Validate params.
|
|
37
|
-
validateEntityGeneratedProperty.validateEntityGeneratedProperty(entityManager, entityToken,
|
|
37
|
+
validateEntityGeneratedProperty.validateEntityGeneratedProperty(entityManager, entityToken, hashKeyToken, true);
|
|
38
38
|
if (!(limit === Infinity || (radash.isInt(limit) && limit >= 1)))
|
|
39
39
|
throw new Error('limit must be a positive integer or Infinity.');
|
|
40
40
|
if (!(radash.isInt(pageSize) && pageSize >= 1))
|
|
@@ -94,7 +94,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
94
94
|
};
|
|
95
95
|
entityManager.logger.debug('queried entityToken across shards', {
|
|
96
96
|
entityToken,
|
|
97
|
-
|
|
97
|
+
hashKeyToken,
|
|
98
98
|
limit,
|
|
99
99
|
pageKeyMap,
|
|
100
100
|
pageSize,
|
|
@@ -112,7 +112,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
112
112
|
if (error instanceof Error)
|
|
113
113
|
entityManager.logger.error(error.message, {
|
|
114
114
|
entityToken,
|
|
115
|
-
|
|
115
|
+
hashKeyToken,
|
|
116
116
|
limit,
|
|
117
117
|
pageKeyMap,
|
|
118
118
|
pageSize,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodableProperties, Transcodes, DefaultTranscodeMap, SortOrder } from '@karmaniverous/entity-tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Transforms a function such that it only executes when `condition` is truthy.
|
|
6
|
-
*
|
|
7
|
-
* @param fn - The function to conditionally execute.
|
|
8
|
-
* @param condition - The condition to check before executing `fn`.
|
|
9
|
-
*
|
|
10
|
-
* @typeParam F - The type of the function to conditionally execute.
|
|
11
|
-
*
|
|
12
|
-
* @returns The conditionalized function with the same signature as `fn`.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
16
|
-
|
|
17
4
|
/**
|
|
18
5
|
* The base EntityMap type. All EntityMaps should extend this type.
|
|
19
6
|
*
|
|
@@ -688,53 +675,11 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
688
675
|
type ParsedConfig = z.infer<typeof configSchema>;
|
|
689
676
|
|
|
690
677
|
/**
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
694
|
-
|
|
695
|
-
* @category Query
|
|
696
|
-
*/
|
|
697
|
-
interface ShardQueryResult<Item extends Entity> {
|
|
698
|
-
/** The number of records returned. */
|
|
699
|
-
count: number;
|
|
700
|
-
/** The returned records. */
|
|
701
|
-
items: Item[];
|
|
702
|
-
/** The page key for the next query on this shard. */
|
|
703
|
-
pageKey?: Partial<Item>;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* A query function that returns a single page of results from an individual
|
|
708
|
-
* shard. This function will typically be composed dynamically to express a
|
|
709
|
-
* specific query index & logic. The arguments to this function will be
|
|
710
|
-
* provided by the {@link EntityManager.query | `EntityManager.query`} method, which assembles many returned
|
|
711
|
-
* pages queried across multiple shards into a single query result.
|
|
712
|
-
*
|
|
713
|
-
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
714
|
-
|
|
715
|
-
* @param hashKey - The hash key value of the shard being queried.
|
|
716
|
-
* @param pageKey - The page key returned by the previous query on this shard.
|
|
717
|
-
* @param pageSize - The maximum number of items to return from this query.
|
|
718
|
-
*
|
|
719
|
-
* @category Query
|
|
720
|
-
*/
|
|
721
|
-
type ShardQueryFunction<Item extends Entity> = (hashKey: string, pageKey?: Partial<Item>, pageSize?: number) => Promise<ShardQueryResult<Item>>;
|
|
722
|
-
|
|
723
|
-
type ShardQueryMap<Item extends Entity> = Record<string, ShardQueryFunction<Item>>;
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* Options passed to the {@link EntityManager.query | `EntityManager.query`} method.
|
|
678
|
+
* Base type of options passed to the {@link EntityManager.query | `EntityManager.query`} method.
|
|
727
679
|
*
|
|
728
680
|
* @category Query
|
|
729
681
|
*/
|
|
730
|
-
interface
|
|
731
|
-
/** Identifies the entity to be queried. Key of {@link Config | `EntityManager.config.entities`}. */
|
|
732
|
-
entityToken: EntityToken;
|
|
733
|
-
/**
|
|
734
|
-
* Identifies the entity key across which the query will be sharded. Key of
|
|
735
|
-
* {@link Config | `EntityManager.config.entities.<entityToken>.keys`}.
|
|
736
|
-
*/
|
|
737
|
-
hashKey: string;
|
|
682
|
+
interface BaseQueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string> {
|
|
738
683
|
/**
|
|
739
684
|
* The target maximum number of records to be returned by the query across
|
|
740
685
|
* all shards.
|
|
@@ -744,10 +689,6 @@ interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken],
|
|
|
744
689
|
* shard.
|
|
745
690
|
*/
|
|
746
691
|
limit?: number;
|
|
747
|
-
/**
|
|
748
|
-
* {@link QueryResult.pageKeyMap | `pageKeyMap`} returned by the previous iteration of this query.
|
|
749
|
-
*/
|
|
750
|
-
pageKeyMap?: string;
|
|
751
692
|
/**
|
|
752
693
|
* The maximum number of records to be returned by each individual query to a
|
|
753
694
|
* single shard (i.e. {@link ShardQueryFunction | `ShardQueryFunction`} execution).
|
|
@@ -757,16 +698,6 @@ interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken],
|
|
|
757
698
|
* reached.
|
|
758
699
|
*/
|
|
759
700
|
pageSize?: number;
|
|
760
|
-
/**
|
|
761
|
-
* Each key in this object is a valid entity index token. Each value is a valid
|
|
762
|
-
* {@link ShardQueryFunction | 'ShardQueryFunction'} that specifies the query of a single page of data on a
|
|
763
|
-
* single shard for the mapped index.
|
|
764
|
-
*
|
|
765
|
-
* This allows simultaneous queries on multiple sort keys to share a single
|
|
766
|
-
* page key, e.g. to match the same string against `firstName` and `lastName`
|
|
767
|
-
* properties without performing a table scan for either.
|
|
768
|
-
*/
|
|
769
|
-
shardQueryMap: ShardQueryMap<Item>;
|
|
770
701
|
/**
|
|
771
702
|
* A {@link SortOrder | `SortOrder`} object specifying the sort order of the result set. Defaults to `[]`.
|
|
772
703
|
*/
|
|
@@ -799,6 +730,16 @@ interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken],
|
|
|
799
730
|
throttle?: number;
|
|
800
731
|
}
|
|
801
732
|
|
|
733
|
+
/**
|
|
734
|
+
* Options passed to the {@link EntityManager.query | `EntityManager.query`} method.
|
|
735
|
+
*
|
|
736
|
+
* @category Query
|
|
737
|
+
*/
|
|
738
|
+
interface QueryOptions<IndexParams, Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> extends BaseQueryOptions<Item, EntityToken, M, HashKey, RangeKey> {
|
|
739
|
+
/** Instance of class extending {@link BaseShardQueryMapBuilder | `BaseShardQueryMapBuilder`}. */
|
|
740
|
+
shardQueryMapBuilder: BaseShardQueryMapBuilder<IndexParams, Item, EntityToken, M, HashKey, RangeKey, T>;
|
|
741
|
+
}
|
|
742
|
+
|
|
802
743
|
/**
|
|
803
744
|
* A result returned by a query across multiple shards, where each shard may
|
|
804
745
|
* receive multiple page queries via a dynamically-generated {@link ShardQueryFunction | `ShardQueryFunction`}.
|
|
@@ -872,7 +813,7 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
872
813
|
* Query a database entity across shards in a provider-generic fashion.
|
|
873
814
|
*
|
|
874
815
|
* @remarks
|
|
875
|
-
* The provided
|
|
816
|
+
* The provided `shardQueryMap` performs the actual query of individual data pages on individual index/shard combinations.
|
|
876
817
|
*
|
|
877
818
|
* Individual shard query results will be combined, deduped by {@link ConfigEntity.uniqueProperty} property value, and sorted by {@link QueryOptions.sortOrder | `sortOrder`}.
|
|
878
819
|
*
|
|
@@ -884,9 +825,84 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
884
825
|
*
|
|
885
826
|
* @returns {@link QueryResult} object.
|
|
886
827
|
*
|
|
887
|
-
* @throws Error if {@link QueryOptions.
|
|
828
|
+
* @throws Error if {@link QueryOptions.shardQueryMapBuilder | `shardQueryMapBuilder`} `pageKeyMap` keys do not match its `shardQueryMap` keys.
|
|
829
|
+
*/
|
|
830
|
+
query<IndexParams, Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string>(options: QueryOptions<IndexParams, Item, EntityToken, M, HashKey, RangeKey, T>): Promise<QueryResult<Item, EntityToken, M, HashKey, RangeKey>>;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* A result returned by a {@link ShardQueryFunction | `ShardQueryFunction`} querying an individual shard.
|
|
835
|
+
*
|
|
836
|
+
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
837
|
+
|
|
838
|
+
* @category Query
|
|
839
|
+
*/
|
|
840
|
+
interface ShardQueryResult<Item extends Entity> {
|
|
841
|
+
/** The number of records returned. */
|
|
842
|
+
count: number;
|
|
843
|
+
/** The returned records. */
|
|
844
|
+
items: Item[];
|
|
845
|
+
/** The page key for the next query on this shard. */
|
|
846
|
+
pageKey?: Partial<Item>;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* A query function that returns a single page of results from an individual
|
|
851
|
+
* shard. This function will typically be composed dynamically to express a
|
|
852
|
+
* specific query index & logic. The arguments to this function will be
|
|
853
|
+
* provided by the {@link EntityManager.query | `EntityManager.query`} method, which assembles many returned
|
|
854
|
+
* pages queried across multiple shards into a single query result.
|
|
855
|
+
*
|
|
856
|
+
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
857
|
+
|
|
858
|
+
* @param hashKey - The hash key value of the shard being queried.
|
|
859
|
+
* @param pageKey - The page key returned by the previous query on this shard.
|
|
860
|
+
* @param pageSize - The maximum number of items to return from this query.
|
|
861
|
+
*
|
|
862
|
+
* @category Query
|
|
863
|
+
*/
|
|
864
|
+
type ShardQueryFunction<Item extends Entity> = (hashKey: string, pageKey?: Partial<Item>, pageSize?: number) => Promise<ShardQueryResult<Item>>;
|
|
865
|
+
|
|
866
|
+
type ShardQueryMap<Item extends Entity> = Record<string, ShardQueryFunction<Item>>;
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
870
|
+
*
|
|
871
|
+
* @category ShardQueryMapBuilder
|
|
872
|
+
*/
|
|
873
|
+
declare abstract class BaseShardQueryMapBuilder<IndexParams, Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> {
|
|
874
|
+
readonly entityManager: EntityManager<M, HashKey, RangeKey, T>;
|
|
875
|
+
readonly entityToken: EntityToken;
|
|
876
|
+
readonly hashKeyToken: PropertiesOfType<M[EntityToken], never> | HashKey;
|
|
877
|
+
readonly pageKeyMap?: string | undefined;
|
|
878
|
+
/**
|
|
879
|
+
* Maps `indexToken` values to database platform-specific parameters.
|
|
880
|
+
*
|
|
881
|
+
* @protected
|
|
888
882
|
*/
|
|
889
|
-
|
|
883
|
+
readonly indexParamsMap: Record<string, IndexParams>;
|
|
884
|
+
/** BaseShardQueryMapBuilder constructor. */
|
|
885
|
+
constructor(entityManager: EntityManager<M, HashKey, RangeKey, T>, entityToken: EntityToken, hashKeyToken: PropertiesOfType<M[EntityToken], never> | HashKey, pageKeyMap?: string | undefined);
|
|
886
|
+
protected abstract getShardQueryFunction(indexToken: string): ShardQueryFunction<Item>;
|
|
887
|
+
/**
|
|
888
|
+
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
889
|
+
*
|
|
890
|
+
* @returns - The {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
891
|
+
*/
|
|
892
|
+
build(): ShardQueryMap<Item>;
|
|
890
893
|
}
|
|
891
894
|
|
|
892
|
-
|
|
895
|
+
/**
|
|
896
|
+
* Transforms a function such that it only executes when `condition` is truthy.
|
|
897
|
+
*
|
|
898
|
+
* @param fn - The function to conditionally execute.
|
|
899
|
+
* @param condition - The condition to check before executing `fn`.
|
|
900
|
+
*
|
|
901
|
+
* @typeParam F - The type of the function to conditionally execute.
|
|
902
|
+
*
|
|
903
|
+
* @returns The conditionalized function with the same signature as `fn`.
|
|
904
|
+
*
|
|
905
|
+
*/
|
|
906
|
+
declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
907
|
+
|
|
908
|
+
export { BaseShardQueryMapBuilder, type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigEntityIndexComponent, type ConfigKeys, type ConfigTranscodes, EntityManager, type EntityMap, type ExclusiveKey, type ItemMap, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type Unwrap, conditionalize };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { mapValues } from 'radash';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
5
|
+
*
|
|
6
|
+
* @category ShardQueryMapBuilder
|
|
7
|
+
*/
|
|
8
|
+
class BaseShardQueryMapBuilder {
|
|
9
|
+
/** BaseShardQueryMapBuilder constructor. */
|
|
10
|
+
constructor(entityManager, entityToken, hashKeyToken, pageKeyMap) {
|
|
11
|
+
this.entityManager = entityManager;
|
|
12
|
+
this.entityToken = entityToken;
|
|
13
|
+
this.hashKeyToken = hashKeyToken;
|
|
14
|
+
this.pageKeyMap = pageKeyMap;
|
|
15
|
+
/**
|
|
16
|
+
* Maps `indexToken` values to database platform-specific parameters.
|
|
17
|
+
*
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
this.indexParamsMap = {};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
24
|
+
*
|
|
25
|
+
* @returns - The {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
26
|
+
*/
|
|
27
|
+
build() {
|
|
28
|
+
return mapValues(this.indexParamsMap, (indexConfig, indexToken) => this.getShardQueryFunction(indexToken));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { BaseShardQueryMapBuilder };
|
|
@@ -70,7 +70,7 @@ class EntityManager {
|
|
|
70
70
|
* Query a database entity across shards in a provider-generic fashion.
|
|
71
71
|
*
|
|
72
72
|
* @remarks
|
|
73
|
-
* The provided
|
|
73
|
+
* The provided `shardQueryMap` performs the actual query of individual data pages on individual index/shard combinations.
|
|
74
74
|
*
|
|
75
75
|
* Individual shard query results will be combined, deduped by {@link ConfigEntity.uniqueProperty} property value, and sorted by {@link QueryOptions.sortOrder | `sortOrder`}.
|
|
76
76
|
*
|
|
@@ -82,10 +82,19 @@ class EntityManager {
|
|
|
82
82
|
*
|
|
83
83
|
* @returns {@link QueryResult} object.
|
|
84
84
|
*
|
|
85
|
-
* @throws Error if {@link QueryOptions.
|
|
85
|
+
* @throws Error if {@link QueryOptions.shardQueryMapBuilder | `shardQueryMapBuilder`} `pageKeyMap` keys do not match its `shardQueryMap` keys.
|
|
86
86
|
*/
|
|
87
87
|
async query(options) {
|
|
88
|
-
|
|
88
|
+
const { shardQueryMapBuilder, ...baseOptions } = options;
|
|
89
|
+
const { entityToken, hashKeyToken, pageKeyMap } = shardQueryMapBuilder;
|
|
90
|
+
const shardQueryMap = shardQueryMapBuilder.build();
|
|
91
|
+
return await query(this, {
|
|
92
|
+
entityToken,
|
|
93
|
+
hashKeyToken,
|
|
94
|
+
pageKeyMap,
|
|
95
|
+
shardQueryMap,
|
|
96
|
+
...baseOptions,
|
|
97
|
+
});
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
100
|
_EntityManager_config = new WeakMap();
|
package/dist/mjs/index.js
CHANGED
package/dist/mjs/query.js
CHANGED
|
@@ -25,14 +25,14 @@ const { compressToEncodedURIComponent, decompressFromEncodedURIComponent } = lzS
|
|
|
25
25
|
*
|
|
26
26
|
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
27
27
|
*/
|
|
28
|
-
async function query(entityManager, { entityToken,
|
|
28
|
+
async function query(entityManager, { entityToken, hashKeyToken, limit, pageKeyMap, pageSize, shardQueryMap, sortOrder = [], timestampFrom = 0, timestampTo = Date.now(), throttle = entityManager.config.throttle, }) {
|
|
29
29
|
try {
|
|
30
30
|
// Get defaults.
|
|
31
31
|
const { defaultLimit, defaultPageSize } = entityManager.config.entities[entityToken];
|
|
32
32
|
limit ?? (limit = defaultLimit);
|
|
33
33
|
pageSize ?? (pageSize = defaultPageSize);
|
|
34
34
|
// Validate params.
|
|
35
|
-
validateEntityGeneratedProperty(entityManager, entityToken,
|
|
35
|
+
validateEntityGeneratedProperty(entityManager, entityToken, hashKeyToken, true);
|
|
36
36
|
if (!(limit === Infinity || (isInt(limit) && limit >= 1)))
|
|
37
37
|
throw new Error('limit must be a positive integer or Infinity.');
|
|
38
38
|
if (!(isInt(pageSize) && pageSize >= 1))
|
|
@@ -92,7 +92,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
92
92
|
};
|
|
93
93
|
entityManager.logger.debug('queried entityToken across shards', {
|
|
94
94
|
entityToken,
|
|
95
|
-
|
|
95
|
+
hashKeyToken,
|
|
96
96
|
limit,
|
|
97
97
|
pageKeyMap,
|
|
98
98
|
pageSize,
|
|
@@ -110,7 +110,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
110
110
|
if (error instanceof Error)
|
|
111
111
|
entityManager.logger.error(error.message, {
|
|
112
112
|
entityToken,
|
|
113
|
-
|
|
113
|
+
hashKeyToken,
|
|
114
114
|
limit,
|
|
115
115
|
pageKeyMap,
|
|
116
116
|
pageSize,
|
package/package.json
CHANGED