@karmaniverous/entity-manager 6.2.4 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/EntityManager.js +1 -1
- package/dist/cjs/{ShardQueryFunctionBuilder.js → ShardQueryMapBuilder.js} +2 -2
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/query.js +4 -4
- package/dist/index.d.ts +11 -11
- package/dist/mjs/EntityManager.js +1 -1
- package/dist/mjs/{ShardQueryFunctionBuilder.js → ShardQueryMapBuilder.js} +2 -2
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/query.js +4 -4
- package/package.json +1 -1
|
@@ -82,7 +82,7 @@ class EntityManager {
|
|
|
82
82
|
*
|
|
83
83
|
* @returns {@link QueryResult} object.
|
|
84
84
|
*
|
|
85
|
-
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.
|
|
85
|
+
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
86
86
|
*/
|
|
87
87
|
async query(options) {
|
|
88
88
|
return await query.query(this, options);
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @category Query
|
|
7
7
|
*/
|
|
8
|
-
class
|
|
8
|
+
class ShardQueryMapBuilder {
|
|
9
9
|
constructor(options) {
|
|
10
10
|
this.options = options;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
exports.
|
|
14
|
+
exports.ShardQueryMapBuilder = ShardQueryMapBuilder;
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
var conditionalize = require('./conditionalize.js');
|
|
4
4
|
var EntityManager = require('./EntityManager.js');
|
|
5
5
|
var EntityManagerClient = require('./EntityManagerClient.js');
|
|
6
|
-
var
|
|
6
|
+
var ShardQueryMapBuilder = require('./ShardQueryMapBuilder.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
exports.conditionalize = conditionalize.conditionalize;
|
|
11
11
|
exports.EntityManager = EntityManager.EntityManager;
|
|
12
12
|
exports.EntityManagerClient = EntityManagerClient.EntityManagerClient;
|
|
13
|
-
exports.
|
|
13
|
+
exports.ShardQueryMapBuilder = ShardQueryMapBuilder.ShardQueryMapBuilder;
|
package/dist/cjs/query.js
CHANGED
|
@@ -25,9 +25,9 @@ const { compressToEncodedURIComponent, decompressFromEncodedURIComponent } = lzS
|
|
|
25
25
|
*
|
|
26
26
|
* @returns {@link QueryResult} object.
|
|
27
27
|
*
|
|
28
|
-
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.
|
|
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, hashKey, limit, pageKeyMap, pageSize,
|
|
30
|
+
async function query(entityManager, { entityToken, hashKey, 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];
|
|
@@ -42,7 +42,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
42
42
|
// Rehydrate pageKeyMap.
|
|
43
43
|
const rehydratedPageKeyMap = rehydratePageKeyMap.rehydratePageKeyMap(entityManager, pageKeyMap
|
|
44
44
|
? JSON.parse(decompressFromEncodedURIComponent(pageKeyMap))
|
|
45
|
-
: undefined, entityToken, Object.keys(
|
|
45
|
+
: undefined, entityToken, Object.keys(shardQueryMap), timestampFrom, timestampTo);
|
|
46
46
|
// Shortcut if pageKeyMap is empty.
|
|
47
47
|
if (!Object.keys(rehydratedPageKeyMap).length)
|
|
48
48
|
return {
|
|
@@ -67,7 +67,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
67
67
|
pageKey,
|
|
68
68
|
])), async ([index, hashKey, pageKey]) => ({
|
|
69
69
|
index,
|
|
70
|
-
queryResult: await
|
|
70
|
+
queryResult: await shardQueryMap[index](hashKey, pageKey, pageSize),
|
|
71
71
|
hashKey,
|
|
72
72
|
}));
|
|
73
73
|
// Reduce shardQueryResults & updateworkingRresult.
|
package/dist/index.d.ts
CHANGED
|
@@ -664,6 +664,8 @@ interface ShardQueryResult<Item extends ItemMap<M, HashKey, RangeKey>[EntityToke
|
|
|
664
664
|
*/
|
|
665
665
|
type ShardQueryFunction<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string = 'hashKey', RangeKey extends string = 'rangeKey', T extends TranscodeMap = DefaultTranscodeMap> = (hashKey: string, pageKey?: PartialTranscodable<Item, T>, pageSize?: number) => Promise<ShardQueryResult<Item, EntityToken, M, HashKey, RangeKey, T>>;
|
|
666
666
|
|
|
667
|
+
type ShardQueryMap<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> = Record<string, ShardQueryFunction<Item, EntityToken, M, HashKey, RangeKey, T>>;
|
|
668
|
+
|
|
667
669
|
/**
|
|
668
670
|
* Options passed to the {@link EntityManager.query | `EntityManager.query`} method.
|
|
669
671
|
*
|
|
@@ -708,7 +710,7 @@ interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken],
|
|
|
708
710
|
* page key, e.g. to match the same string against `firstName` and `lastName`
|
|
709
711
|
* properties without performing a table scan for either.
|
|
710
712
|
*/
|
|
711
|
-
|
|
713
|
+
shardQueryMap: ShardQueryMap<Item, EntityToken, M, HashKey, RangeKey, T>;
|
|
712
714
|
/**
|
|
713
715
|
* A {@link SortOrder | `SortOrder`} object specifying the sort order of the result set. Defaults to `[]`.
|
|
714
716
|
*/
|
|
@@ -796,7 +798,7 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
796
798
|
*
|
|
797
799
|
* @throws `Error` if `entityToken` is invalid.
|
|
798
800
|
*/
|
|
799
|
-
addKeys<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string>(item: Item
|
|
801
|
+
addKeys<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string>(item: Partial<Item>, entityToken: EntityToken, overwrite?: boolean): Partial<Item>;
|
|
800
802
|
/**
|
|
801
803
|
* Strips generated properties, hash key, and range key from an {@link ItemMap | `ItemMap`} object. Mutates `item`.
|
|
802
804
|
*
|
|
@@ -807,7 +809,7 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
807
809
|
*
|
|
808
810
|
* @throws `Error` if `entityToken` is invalid.
|
|
809
811
|
*/
|
|
810
|
-
removeKeys<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string>(item: Item
|
|
812
|
+
removeKeys<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string>(item: Partial<Item>, entityToken: EntityToken): Partial<Item>;
|
|
811
813
|
/**
|
|
812
814
|
* Query a database entity across shards in a provider-generic fashion.
|
|
813
815
|
*
|
|
@@ -824,7 +826,7 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
824
826
|
*
|
|
825
827
|
* @returns {@link QueryResult} object.
|
|
826
828
|
*
|
|
827
|
-
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.
|
|
829
|
+
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
828
830
|
*/
|
|
829
831
|
query<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string>(options: QueryOptions<Item, EntityToken, M, HashKey, RangeKey, T>): Promise<QueryResult<Item, EntityToken, M, HashKey, RangeKey>>;
|
|
830
832
|
}
|
|
@@ -911,19 +913,17 @@ declare abstract class EntityManagerClient<Options extends EntityManagerClientOp
|
|
|
911
913
|
}
|
|
912
914
|
|
|
913
915
|
/**
|
|
914
|
-
* {@link
|
|
916
|
+
* {@link ShardQueryMapBuilder | `ShardQueryMapBuilder`} options.
|
|
915
917
|
*
|
|
916
918
|
* @category Query
|
|
917
919
|
*/
|
|
918
|
-
interface
|
|
920
|
+
interface ShardQueryMapBuilderOptions<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> {
|
|
919
921
|
/** {@link EntityManager | `EntityManager`} instance. */
|
|
920
922
|
entityManager: EntityManager<M, HashKey, RangeKey, T>;
|
|
921
923
|
/** `entityManager.config.entities` key. */
|
|
922
924
|
entityToken: EntityToken;
|
|
923
925
|
/** Either the designated entity hash key or a generated property with `sharded === true`. */
|
|
924
926
|
hashKeyToken: HashKey | (PropertiesOfType<M[EntityToken], void> & string);
|
|
925
|
-
/** `entityManager.config.entities.<entityToken>.indexes` key. */
|
|
926
|
-
indexToken: string;
|
|
927
927
|
/** A partial `Item` sufficiently populated to generate the query hash key & index values. */
|
|
928
928
|
item: Partial<Item>;
|
|
929
929
|
/** Dehydrated page key from the previous query data page. */
|
|
@@ -935,10 +935,10 @@ interface ShardQueryFunctionBuilderOptions<Item extends ItemMap<M, HashKey, Rang
|
|
|
935
935
|
*
|
|
936
936
|
* @category Query
|
|
937
937
|
*/
|
|
938
|
-
declare abstract class
|
|
938
|
+
declare abstract class ShardQueryMapBuilder<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, Options extends ShardQueryMapBuilderOptions<Item, EntityToken, M, HashKey, RangeKey, T>> {
|
|
939
939
|
protected readonly options: Options;
|
|
940
940
|
constructor(options: Options);
|
|
941
|
-
abstract
|
|
941
|
+
abstract getShardQueryMap(): ShardQueryMap<Item, EntityToken, M, HashKey, RangeKey, T>;
|
|
942
942
|
}
|
|
943
943
|
|
|
944
944
|
/**
|
|
@@ -951,4 +951,4 @@ type WithRequiredAndNonNullable<T, K extends keyof T> = T & {
|
|
|
951
951
|
[P in K]-?: NonNullable<T[P]>;
|
|
952
952
|
};
|
|
953
953
|
|
|
954
|
-
export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigKeys, type ConfigTranscodes, EntityManager, EntityManagerClient, type EntityManagerClientBatchOptions, type EntityManagerClientOptions, type EntityMap, type ExclusiveKey, type ItemMap, type Logger, type LoggerEndpoint, type LoggerOptions, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction,
|
|
954
|
+
export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigKeys, type ConfigTranscodes, EntityManager, EntityManagerClient, type EntityManagerClientBatchOptions, type EntityManagerClientOptions, type EntityMap, type ExclusiveKey, type ItemMap, type Logger, type LoggerEndpoint, type LoggerOptions, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, ShardQueryMapBuilder, type ShardQueryMapBuilderOptions, type ShardQueryResult, type Unwrap, type WithRequiredAndNonNullable, conditionalize };
|
|
@@ -80,7 +80,7 @@ class EntityManager {
|
|
|
80
80
|
*
|
|
81
81
|
* @returns {@link QueryResult} object.
|
|
82
82
|
*
|
|
83
|
-
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.
|
|
83
|
+
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.shardQueryMap | `shardQueryMap`} keys.
|
|
84
84
|
*/
|
|
85
85
|
async query(options) {
|
|
86
86
|
return await query(this, options);
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { conditionalize } from './conditionalize.js';
|
|
2
2
|
export { EntityManager } from './EntityManager.js';
|
|
3
3
|
export { EntityManagerClient } from './EntityManagerClient.js';
|
|
4
|
-
export {
|
|
4
|
+
export { ShardQueryMapBuilder } from './ShardQueryMapBuilder.js';
|
package/dist/mjs/query.js
CHANGED
|
@@ -23,9 +23,9 @@ const { compressToEncodedURIComponent, decompressFromEncodedURIComponent } = lzS
|
|
|
23
23
|
*
|
|
24
24
|
* @returns {@link QueryResult} object.
|
|
25
25
|
*
|
|
26
|
-
* @throws Error if {@link QueryOptions.pageKeyMap | `pageKeyMap`} keys do not match {@link QueryOptions.
|
|
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, hashKey, limit, pageKeyMap, pageSize,
|
|
28
|
+
async function query(entityManager, { entityToken, hashKey, 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];
|
|
@@ -40,7 +40,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
40
40
|
// Rehydrate pageKeyMap.
|
|
41
41
|
const rehydratedPageKeyMap = rehydratePageKeyMap(entityManager, pageKeyMap
|
|
42
42
|
? JSON.parse(decompressFromEncodedURIComponent(pageKeyMap))
|
|
43
|
-
: undefined, entityToken, Object.keys(
|
|
43
|
+
: undefined, entityToken, Object.keys(shardQueryMap), timestampFrom, timestampTo);
|
|
44
44
|
// Shortcut if pageKeyMap is empty.
|
|
45
45
|
if (!Object.keys(rehydratedPageKeyMap).length)
|
|
46
46
|
return {
|
|
@@ -65,7 +65,7 @@ async function query(entityManager, { entityToken, hashKey, limit, pageKeyMap, p
|
|
|
65
65
|
pageKey,
|
|
66
66
|
])), async ([index, hashKey, pageKey]) => ({
|
|
67
67
|
index,
|
|
68
|
-
queryResult: await
|
|
68
|
+
queryResult: await shardQueryMap[index](hashKey, pageKey, pageSize),
|
|
69
69
|
hashKey,
|
|
70
70
|
}));
|
|
71
71
|
// Reduce shardQueryResults & updateworkingRresult.
|
package/package.json
CHANGED