@karmaniverous/entity-manager 6.7.2 → 6.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseEntityClient.js +21 -0
- package/dist/cjs/BaseShardQueryMapBuilder.js +8 -6
- package/dist/cjs/index.js +2 -0
- package/dist/index.d.ts +176 -123
- package/dist/mjs/BaseEntityClient.js +19 -0
- package/dist/mjs/BaseShardQueryMapBuilder.js +8 -6
- package/dist/mjs/index.js +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
|
|
5
|
+
*
|
|
6
|
+
* @category EntityClient
|
|
7
|
+
*/
|
|
8
|
+
class BaseEntityClient {
|
|
9
|
+
/**
|
|
10
|
+
* DynamoDB EntityClient constructor.
|
|
11
|
+
*
|
|
12
|
+
* @param options - {@link EntityClientOptions | `EntityClientOptions`} object.
|
|
13
|
+
*/
|
|
14
|
+
constructor(options) {
|
|
15
|
+
const { batchProcessOptions = {}, logger = console } = options;
|
|
16
|
+
this.batchProcessOptions = batchProcessOptions;
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.BaseEntityClient = BaseEntityClient;
|
|
@@ -9,17 +9,19 @@ var radash = require('radash');
|
|
|
9
9
|
*/
|
|
10
10
|
class BaseShardQueryMapBuilder {
|
|
11
11
|
/** BaseShardQueryMapBuilder constructor. */
|
|
12
|
-
constructor(
|
|
13
|
-
this.entityManager = entityManager;
|
|
14
|
-
this.entityToken = entityToken;
|
|
15
|
-
this.hashKeyToken = hashKeyToken;
|
|
16
|
-
this.pageKeyMap = pageKeyMap;
|
|
12
|
+
constructor(options) {
|
|
17
13
|
/**
|
|
18
|
-
* Maps `indexToken` values to database platform-specific parameters.
|
|
14
|
+
* Maps `indexToken` values to database platform-specific query parameters.
|
|
19
15
|
*
|
|
20
16
|
* @protected
|
|
21
17
|
*/
|
|
22
18
|
this.indexParamsMap = {};
|
|
19
|
+
const { entityClient, entityManager, entityToken, hashKeyToken, pageKeyMap, } = options;
|
|
20
|
+
this.entityClient = entityClient;
|
|
21
|
+
this.entityManager = entityManager;
|
|
22
|
+
this.entityToken = entityToken;
|
|
23
|
+
this.hashKeyToken = hashKeyToken;
|
|
24
|
+
this.pageKeyMap = pageKeyMap;
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var BaseEntityClient = require('./BaseEntityClient.js');
|
|
3
4
|
var BaseShardQueryMapBuilder = require('./BaseShardQueryMapBuilder.js');
|
|
4
5
|
var conditionalize = require('./conditionalize.js');
|
|
5
6
|
var EntityManager = require('./EntityManager.js');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
10
|
+
exports.BaseEntityClient = BaseEntityClient.BaseEntityClient;
|
|
9
11
|
exports.BaseShardQueryMapBuilder = BaseShardQueryMapBuilder.BaseShardQueryMapBuilder;
|
|
10
12
|
exports.conditionalize = conditionalize.conditionalize;
|
|
11
13
|
exports.EntityManager = EntityManager.EntityManager;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
|
+
import { BatchProcessOptions } from '@karmaniverous/batch-process';
|
|
1
2
|
import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodableProperties, Transcodes, DefaultTranscodeMap, SortOrder } from '@karmaniverous/entity-tools';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Base EntityClient options.
|
|
7
|
+
*
|
|
8
|
+
* @category EntityClient
|
|
9
|
+
*/
|
|
10
|
+
interface BaseEntityClientOptions {
|
|
11
|
+
/** Default batch process options. */
|
|
12
|
+
batchProcessOptions?: Omit<BatchProcessOptions<unknown, unknown>, 'batchHandler' | 'unprocessedItemExtractor'>;
|
|
13
|
+
/** Injected logger object. Must support `debug` and `error` methods. Default: `console` */
|
|
14
|
+
logger?: Pick<Console, 'debug' | 'error'>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
|
|
19
|
+
*
|
|
20
|
+
* @category EntityClient
|
|
21
|
+
*/
|
|
22
|
+
declare abstract class BaseEntityClient {
|
|
23
|
+
readonly batchProcessOptions: NonNullable<BaseEntityClientOptions['batchProcessOptions']>;
|
|
24
|
+
readonly logger: NonNullable<BaseEntityClientOptions['logger']>;
|
|
25
|
+
/**
|
|
26
|
+
* DynamoDB EntityClient constructor.
|
|
27
|
+
*
|
|
28
|
+
* @param options - {@link EntityClientOptions | `EntityClientOptions`} object.
|
|
29
|
+
*/
|
|
30
|
+
constructor(options: BaseEntityClientOptions);
|
|
31
|
+
}
|
|
32
|
+
|
|
4
33
|
/**
|
|
5
34
|
* The base EntityMap type. All EntityMaps should extend this type.
|
|
6
35
|
*
|
|
@@ -381,119 +410,6 @@ interface QueryResult<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], E
|
|
|
381
410
|
pageKeyMap: string;
|
|
382
411
|
}
|
|
383
412
|
|
|
384
|
-
/**
|
|
385
|
-
* A result returned by a {@link ShardQueryFunction | `ShardQueryFunction`} querying an individual shard.
|
|
386
|
-
*
|
|
387
|
-
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
388
|
-
|
|
389
|
-
* @category Query
|
|
390
|
-
*/
|
|
391
|
-
interface ShardQueryResult<Item extends Entity> {
|
|
392
|
-
/** The number of records returned. */
|
|
393
|
-
count: number;
|
|
394
|
-
/** The returned records. */
|
|
395
|
-
items: Item[];
|
|
396
|
-
/** The page key for the next query on this shard. */
|
|
397
|
-
pageKey?: Partial<Item>;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* A query function that returns a single page of results from an individual
|
|
402
|
-
* shard. This function will typically be composed dynamically to express a
|
|
403
|
-
* specific query index & logic. The arguments to this function will be
|
|
404
|
-
* provided by the {@link EntityManager.query | `EntityManager.query`} method, which assembles many returned
|
|
405
|
-
* pages queried across multiple shards into a single query result.
|
|
406
|
-
*
|
|
407
|
-
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
408
|
-
|
|
409
|
-
* @param hashKey - The hash key value of the shard being queried.
|
|
410
|
-
* @param pageKey - The page key returned by the previous query on this shard.
|
|
411
|
-
* @param pageSize - The maximum number of items to return from this query.
|
|
412
|
-
*
|
|
413
|
-
* @category Query
|
|
414
|
-
*/
|
|
415
|
-
type ShardQueryFunction<Item extends Entity> = (hashKey: string, pageKey?: Partial<Item>, pageSize?: number) => Promise<ShardQueryResult<Item>>;
|
|
416
|
-
|
|
417
|
-
type ShardQueryMap<Item extends Entity> = Record<string, ShardQueryFunction<Item>>;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Options passed to the {@link query | `query`} function.
|
|
421
|
-
*
|
|
422
|
-
* @category Query
|
|
423
|
-
*/
|
|
424
|
-
interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string> {
|
|
425
|
-
/** Identifies the entity to be queried. Key of {@link Config | `EntityManager.config.entities`}. */
|
|
426
|
-
entityToken: EntityToken;
|
|
427
|
-
/**
|
|
428
|
-
* Partial item object sufficiently populated to generate index hash keys.
|
|
429
|
-
*/
|
|
430
|
-
item: Partial<Item>;
|
|
431
|
-
/**
|
|
432
|
-
* The target maximum number of records to be returned by the query across
|
|
433
|
-
* all shards.
|
|
434
|
-
*
|
|
435
|
-
* The actual number of records returned will be a product of {@link QueryOptions.pageSize | `pageSize`} and the
|
|
436
|
-
* number of shards queried, unless limited by available records in a given
|
|
437
|
-
* shard.
|
|
438
|
-
*/
|
|
439
|
-
limit?: number;
|
|
440
|
-
/**
|
|
441
|
-
* {@link QueryResult.pageKeyMap | `pageKeyMap`} returned by the previous iteration of this query.
|
|
442
|
-
*/
|
|
443
|
-
pageKeyMap?: string;
|
|
444
|
-
/**
|
|
445
|
-
* The maximum number of records to be returned by each individual query to a
|
|
446
|
-
* single shard (i.e. {@link ShardQueryFunction | `ShardQueryFunction`} execution).
|
|
447
|
-
*
|
|
448
|
-
* Note that, within a given {@link EntityManager.query | `query`} method execution, these queries will be
|
|
449
|
-
* repeated until either available data is exhausted or the {@link QueryOptions.limit | `limit`} value is
|
|
450
|
-
* reached.
|
|
451
|
-
*/
|
|
452
|
-
pageSize?: number;
|
|
453
|
-
/**
|
|
454
|
-
* Each key in this object is a valid entity index token. Each value is a valid
|
|
455
|
-
* {@link ShardQueryFunction | 'ShardQueryFunction'} that specifies the query of a single page of data on a
|
|
456
|
-
* single shard for the mapped index.
|
|
457
|
-
*
|
|
458
|
-
* This allows simultaneous queries on multiple sort keys to share a single
|
|
459
|
-
* page key, e.g. to match the same string against `firstName` and `lastName`
|
|
460
|
-
* properties without performing a table scan for either.
|
|
461
|
-
*/
|
|
462
|
-
shardQueryMap: ShardQueryMap<Item>;
|
|
463
|
-
/**
|
|
464
|
-
* A {@link SortOrder | `SortOrder`} object specifying the sort order of the result set. Defaults to `[]`.
|
|
465
|
-
*/
|
|
466
|
-
sortOrder?: SortOrder<Item>;
|
|
467
|
-
/**
|
|
468
|
-
* Lower limit to query shard space.
|
|
469
|
-
*
|
|
470
|
-
* Only valid if the query is constrained along the dimension used by the
|
|
471
|
-
* {@link Config | `EntityManager.config.entities.<entityToken>.sharding.timestamptokens.timestamp`}
|
|
472
|
-
* function to generate `shardKey`.
|
|
473
|
-
*
|
|
474
|
-
* @defaultValue `0`
|
|
475
|
-
*/
|
|
476
|
-
timestampFrom?: number;
|
|
477
|
-
/**
|
|
478
|
-
* Upper limit to query shard space.
|
|
479
|
-
*
|
|
480
|
-
* Only valid if the query is constrained along the dimension used by the
|
|
481
|
-
* {@link Config | `EntityManager.config.entities.<entityToken>.sharding.timestamptokens.timestamp`}
|
|
482
|
-
* function to generate `shardKey`.
|
|
483
|
-
*
|
|
484
|
-
* @defaultValue `Date.now()`
|
|
485
|
-
*/
|
|
486
|
-
timestampTo?: number;
|
|
487
|
-
/**
|
|
488
|
-
* The maximum number of shards to query in parallel. Overrides options `throttle`.
|
|
489
|
-
*
|
|
490
|
-
* @defaultValue `options.throttle`
|
|
491
|
-
*/
|
|
492
|
-
throttle?: number;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
type BuilderQueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string> = Omit<QueryOptions<Item, EntityToken, M, HashKey, RangeKey>, 'entityToken' | 'pageKeyMap' | 'shardQueryMap'>;
|
|
496
|
-
|
|
497
413
|
declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
498
414
|
entities: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
|
|
499
415
|
defaultLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -666,6 +582,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
666
582
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
667
583
|
}>>>>;
|
|
668
584
|
}, "strict", z.ZodTypeAny, {
|
|
585
|
+
throttle: number;
|
|
669
586
|
hashKey: string;
|
|
670
587
|
rangeKey: string;
|
|
671
588
|
entities: Record<string, {
|
|
@@ -693,12 +610,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
693
610
|
generatedKeyDelimiter: string;
|
|
694
611
|
generatedValueDelimiter: string;
|
|
695
612
|
shardKeyDelimiter: string;
|
|
696
|
-
throttle: number;
|
|
697
613
|
transcodes: Record<string, {
|
|
698
614
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
699
615
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
700
616
|
}>;
|
|
701
617
|
}, {
|
|
618
|
+
throttle?: number | undefined;
|
|
702
619
|
hashKey?: string | undefined;
|
|
703
620
|
rangeKey?: string | undefined;
|
|
704
621
|
entities?: Record<string, {
|
|
@@ -726,12 +643,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
726
643
|
generatedKeyDelimiter?: string | undefined;
|
|
727
644
|
generatedValueDelimiter?: string | undefined;
|
|
728
645
|
shardKeyDelimiter?: string | undefined;
|
|
729
|
-
throttle?: number | undefined;
|
|
730
646
|
transcodes?: Record<string, {
|
|
731
647
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
732
648
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
733
649
|
}> | undefined;
|
|
734
650
|
}>, {
|
|
651
|
+
throttle: number;
|
|
735
652
|
hashKey: string;
|
|
736
653
|
rangeKey: string;
|
|
737
654
|
entities: Record<string, {
|
|
@@ -759,12 +676,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
759
676
|
generatedKeyDelimiter: string;
|
|
760
677
|
generatedValueDelimiter: string;
|
|
761
678
|
shardKeyDelimiter: string;
|
|
762
|
-
throttle: number;
|
|
763
679
|
transcodes: Record<string, {
|
|
764
680
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
765
681
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
766
682
|
}>;
|
|
767
683
|
}, {
|
|
684
|
+
throttle?: number | undefined;
|
|
768
685
|
hashKey?: string | undefined;
|
|
769
686
|
rangeKey?: string | undefined;
|
|
770
687
|
entities?: Record<string, {
|
|
@@ -792,7 +709,6 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
792
709
|
generatedKeyDelimiter?: string | undefined;
|
|
793
710
|
generatedValueDelimiter?: string | undefined;
|
|
794
711
|
shardKeyDelimiter?: string | undefined;
|
|
795
|
-
throttle?: number | undefined;
|
|
796
712
|
transcodes?: Record<string, {
|
|
797
713
|
encode: (args_0: any, ...args: unknown[]) => string;
|
|
798
714
|
decode: (args_0: string, ...args: unknown[]) => any;
|
|
@@ -805,6 +721,117 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
805
721
|
*/
|
|
806
722
|
type ParsedConfig = z.infer<typeof configSchema>;
|
|
807
723
|
|
|
724
|
+
/**
|
|
725
|
+
* A result returned by a {@link ShardQueryFunction | `ShardQueryFunction`} querying an individual shard.
|
|
726
|
+
*
|
|
727
|
+
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
728
|
+
|
|
729
|
+
* @category Query
|
|
730
|
+
*/
|
|
731
|
+
interface ShardQueryResult<Item extends Entity> {
|
|
732
|
+
/** The number of records returned. */
|
|
733
|
+
count: number;
|
|
734
|
+
/** The returned records. */
|
|
735
|
+
items: Item[];
|
|
736
|
+
/** The page key for the next query on this shard. */
|
|
737
|
+
pageKey?: Partial<Item>;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* A query function that returns a single page of results from an individual
|
|
742
|
+
* shard. This function will typically be composed dynamically to express a
|
|
743
|
+
* specific query index & logic. The arguments to this function will be
|
|
744
|
+
* provided by the {@link EntityManager.query | `EntityManager.query`} method, which assembles many returned
|
|
745
|
+
* pages queried across multiple shards into a single query result.
|
|
746
|
+
*
|
|
747
|
+
* @typeParam Item - The {@link Item | `Item`} type being queried.
|
|
748
|
+
|
|
749
|
+
* @param hashKey - The hash key value of the shard being queried.
|
|
750
|
+
* @param pageKey - The page key returned by the previous query on this shard.
|
|
751
|
+
* @param pageSize - The maximum number of items to return from this query.
|
|
752
|
+
*
|
|
753
|
+
* @category Query
|
|
754
|
+
*/
|
|
755
|
+
type ShardQueryFunction<Item extends Entity> = (hashKey: string, pageKey?: Partial<Item>, pageSize?: number) => Promise<ShardQueryResult<Item>>;
|
|
756
|
+
|
|
757
|
+
type ShardQueryMap<Item extends Entity> = Record<string, ShardQueryFunction<Item>>;
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Options passed to the {@link query | `query`} function.
|
|
761
|
+
*
|
|
762
|
+
* @category Query
|
|
763
|
+
*/
|
|
764
|
+
interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string> {
|
|
765
|
+
/** Identifies the entity to be queried. Key of {@link Config | `EntityManager.config.entities`}. */
|
|
766
|
+
entityToken: EntityToken;
|
|
767
|
+
/**
|
|
768
|
+
* Partial item object sufficiently populated to generate index hash keys.
|
|
769
|
+
*/
|
|
770
|
+
item: Partial<Item>;
|
|
771
|
+
/**
|
|
772
|
+
* The target maximum number of records to be returned by the query across
|
|
773
|
+
* all shards.
|
|
774
|
+
*
|
|
775
|
+
* The actual number of records returned will be a product of {@link QueryOptions.pageSize | `pageSize`} and the
|
|
776
|
+
* number of shards queried, unless limited by available records in a given
|
|
777
|
+
* shard.
|
|
778
|
+
*/
|
|
779
|
+
limit?: number;
|
|
780
|
+
/**
|
|
781
|
+
* {@link QueryResult.pageKeyMap | `pageKeyMap`} returned by the previous iteration of this query.
|
|
782
|
+
*/
|
|
783
|
+
pageKeyMap?: string;
|
|
784
|
+
/**
|
|
785
|
+
* The maximum number of records to be returned by each individual query to a
|
|
786
|
+
* single shard (i.e. {@link ShardQueryFunction | `ShardQueryFunction`} execution).
|
|
787
|
+
*
|
|
788
|
+
* Note that, within a given {@link EntityManager.query | `query`} method execution, these queries will be
|
|
789
|
+
* repeated until either available data is exhausted or the {@link QueryOptions.limit | `limit`} value is
|
|
790
|
+
* reached.
|
|
791
|
+
*/
|
|
792
|
+
pageSize?: number;
|
|
793
|
+
/**
|
|
794
|
+
* Each key in this object is a valid entity index token. Each value is a valid
|
|
795
|
+
* {@link ShardQueryFunction | 'ShardQueryFunction'} that specifies the query of a single page of data on a
|
|
796
|
+
* single shard for the mapped index.
|
|
797
|
+
*
|
|
798
|
+
* This allows simultaneous queries on multiple sort keys to share a single
|
|
799
|
+
* page key, e.g. to match the same string against `firstName` and `lastName`
|
|
800
|
+
* properties without performing a table scan for either.
|
|
801
|
+
*/
|
|
802
|
+
shardQueryMap: ShardQueryMap<Item>;
|
|
803
|
+
/**
|
|
804
|
+
* A {@link SortOrder | `SortOrder`} object specifying the sort order of the result set. Defaults to `[]`.
|
|
805
|
+
*/
|
|
806
|
+
sortOrder?: SortOrder<Item>;
|
|
807
|
+
/**
|
|
808
|
+
* Lower limit to query shard space.
|
|
809
|
+
*
|
|
810
|
+
* Only valid if the query is constrained along the dimension used by the
|
|
811
|
+
* {@link Config | `EntityManager.config.entities.<entityToken>.sharding.timestamptokens.timestamp`}
|
|
812
|
+
* function to generate `shardKey`.
|
|
813
|
+
*
|
|
814
|
+
* @defaultValue `0`
|
|
815
|
+
*/
|
|
816
|
+
timestampFrom?: number;
|
|
817
|
+
/**
|
|
818
|
+
* Upper limit to query shard space.
|
|
819
|
+
*
|
|
820
|
+
* Only valid if the query is constrained along the dimension used by the
|
|
821
|
+
* {@link Config | `EntityManager.config.entities.<entityToken>.sharding.timestamptokens.timestamp`}
|
|
822
|
+
* function to generate `shardKey`.
|
|
823
|
+
*
|
|
824
|
+
* @defaultValue `Date.now()`
|
|
825
|
+
*/
|
|
826
|
+
timestampTo?: number;
|
|
827
|
+
/**
|
|
828
|
+
* The maximum number of shards to query in parallel. Overrides options `throttle`.
|
|
829
|
+
*
|
|
830
|
+
* @defaultValue `options.throttle`
|
|
831
|
+
*/
|
|
832
|
+
throttle?: number;
|
|
833
|
+
}
|
|
834
|
+
|
|
808
835
|
/**
|
|
809
836
|
* The EntityManager class applies a configuration-driven sharded data model &
|
|
810
837
|
* query strategy to NoSql data.
|
|
@@ -877,24 +904,50 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
|
|
|
877
904
|
query<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string>(options: QueryOptions<Item, EntityToken, M, HashKey, RangeKey>): Promise<QueryResult<Item, EntityToken, M, HashKey, RangeKey>>;
|
|
878
905
|
}
|
|
879
906
|
|
|
907
|
+
/**
|
|
908
|
+
* Constructor options for {@link BaseShardQueryMapBuilder | `BaseShardQueryMapBuilder`}.
|
|
909
|
+
*
|
|
910
|
+
* @category ShardQueryMapBuilder
|
|
911
|
+
*/
|
|
912
|
+
interface BaseShardQueryMapBuilderOptions<EntityClient extends BaseEntityClient, EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> {
|
|
913
|
+
/** {@link BaseEntityClient | `EntityClient`} instance. */
|
|
914
|
+
entityClient: EntityClient;
|
|
915
|
+
/** {@link EntityManager | `EntityManager`} instance. */
|
|
916
|
+
entityManager: EntityManager<M, HashKey, RangeKey, T>;
|
|
917
|
+
/** Entity token. */
|
|
918
|
+
entityToken: EntityToken;
|
|
919
|
+
/** Hash key token. */
|
|
920
|
+
hashKeyToken: PropertiesOfType<M[EntityToken], never> | HashKey;
|
|
921
|
+
/** Dehydrated page key map. */
|
|
922
|
+
pageKeyMap?: string;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
type ShardQueryMapBuilderQueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string> = Omit<QueryOptions<Item, EntityToken, M, HashKey, RangeKey>, 'entityToken' | 'pageKeyMap' | 'shardQueryMap'>;
|
|
926
|
+
|
|
880
927
|
/**
|
|
881
928
|
* Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
|
|
882
929
|
*
|
|
883
930
|
* @category ShardQueryMapBuilder
|
|
884
931
|
*/
|
|
885
|
-
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> {
|
|
932
|
+
declare abstract class BaseShardQueryMapBuilder<IndexParams, EntityClient extends BaseEntityClient, 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> {
|
|
933
|
+
/** {@link BaseEntityClient | `EntityClient`} instance. */
|
|
934
|
+
readonly entityClient: EntityClient;
|
|
935
|
+
/** {@link EntityManager | `EntityManager`} instance. */
|
|
886
936
|
readonly entityManager: EntityManager<M, HashKey, RangeKey, T>;
|
|
937
|
+
/** Entity token. */
|
|
887
938
|
readonly entityToken: EntityToken;
|
|
939
|
+
/** Hash key token. */
|
|
888
940
|
readonly hashKeyToken: PropertiesOfType<M[EntityToken], never> | HashKey;
|
|
889
|
-
|
|
941
|
+
/** Dehydrated page key map. */
|
|
942
|
+
readonly pageKeyMap?: string;
|
|
890
943
|
/**
|
|
891
|
-
* Maps `indexToken` values to database platform-specific parameters.
|
|
944
|
+
* Maps `indexToken` values to database platform-specific query parameters.
|
|
892
945
|
*
|
|
893
946
|
* @protected
|
|
894
947
|
*/
|
|
895
948
|
readonly indexParamsMap: Record<string, IndexParams>;
|
|
896
949
|
/** BaseShardQueryMapBuilder constructor. */
|
|
897
|
-
constructor(
|
|
950
|
+
constructor(options: BaseShardQueryMapBuilderOptions<EntityClient, EntityToken, M, HashKey, RangeKey, T>);
|
|
898
951
|
protected abstract getShardQueryFunction(indexToken: string): ShardQueryFunction<Item>;
|
|
899
952
|
/**
|
|
900
953
|
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
@@ -902,7 +955,7 @@ declare abstract class BaseShardQueryMapBuilder<IndexParams, Item extends ItemMa
|
|
|
902
955
|
* @returns - The {@link ShardQueryMap | `ShardQueryMap`} object.
|
|
903
956
|
*/
|
|
904
957
|
build(): ShardQueryMap<Item>;
|
|
905
|
-
query(options:
|
|
958
|
+
query(options: ShardQueryMapBuilderQueryOptions<Item, EntityToken, M, HashKey, RangeKey>): Promise<QueryResult<Item, EntityToken, M, HashKey, RangeKey>>;
|
|
906
959
|
}
|
|
907
960
|
|
|
908
961
|
/**
|
|
@@ -918,4 +971,4 @@ declare abstract class BaseShardQueryMapBuilder<IndexParams, Item extends ItemMa
|
|
|
918
971
|
*/
|
|
919
972
|
declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
|
|
920
973
|
|
|
921
|
-
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 };
|
|
974
|
+
export { BaseEntityClient, type BaseEntityClientOptions, BaseShardQueryMapBuilder, type BaseShardQueryMapBuilderOptions, 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 ShardQueryMapBuilderQueryOptions, type ShardQueryResult, type Unwrap, conditionalize };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
|
|
3
|
+
*
|
|
4
|
+
* @category EntityClient
|
|
5
|
+
*/
|
|
6
|
+
class BaseEntityClient {
|
|
7
|
+
/**
|
|
8
|
+
* DynamoDB EntityClient constructor.
|
|
9
|
+
*
|
|
10
|
+
* @param options - {@link EntityClientOptions | `EntityClientOptions`} object.
|
|
11
|
+
*/
|
|
12
|
+
constructor(options) {
|
|
13
|
+
const { batchProcessOptions = {}, logger = console } = options;
|
|
14
|
+
this.batchProcessOptions = batchProcessOptions;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { BaseEntityClient };
|
|
@@ -7,17 +7,19 @@ import { mapValues } from 'radash';
|
|
|
7
7
|
*/
|
|
8
8
|
class BaseShardQueryMapBuilder {
|
|
9
9
|
/** BaseShardQueryMapBuilder constructor. */
|
|
10
|
-
constructor(
|
|
11
|
-
this.entityManager = entityManager;
|
|
12
|
-
this.entityToken = entityToken;
|
|
13
|
-
this.hashKeyToken = hashKeyToken;
|
|
14
|
-
this.pageKeyMap = pageKeyMap;
|
|
10
|
+
constructor(options) {
|
|
15
11
|
/**
|
|
16
|
-
* Maps `indexToken` values to database platform-specific parameters.
|
|
12
|
+
* Maps `indexToken` values to database platform-specific query parameters.
|
|
17
13
|
*
|
|
18
14
|
* @protected
|
|
19
15
|
*/
|
|
20
16
|
this.indexParamsMap = {};
|
|
17
|
+
const { entityClient, entityManager, entityToken, hashKeyToken, pageKeyMap, } = options;
|
|
18
|
+
this.entityClient = entityClient;
|
|
19
|
+
this.entityManager = entityManager;
|
|
20
|
+
this.entityToken = entityToken;
|
|
21
|
+
this.hashKeyToken = hashKeyToken;
|
|
22
|
+
this.pageKeyMap = pageKeyMap;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
|
package/dist/mjs/index.js
CHANGED
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"url": "https://github.com/karmaniverous/entity-manager/issues"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"@karmaniverous/batch-process": "^0.1.0",
|
|
7
8
|
"@karmaniverous/entity-tools": "^0.4.4",
|
|
8
9
|
"@karmaniverous/string-utilities": "^0.2.1",
|
|
9
10
|
"lz-string": "^1.5.0",
|
|
@@ -131,5 +132,5 @@
|
|
|
131
132
|
},
|
|
132
133
|
"type": "module",
|
|
133
134
|
"types": "dist/index.d.ts",
|
|
134
|
-
"version": "6.7.
|
|
135
|
+
"version": "6.7.4"
|
|
135
136
|
}
|