@karmaniverous/entity-manager 6.7.2 → 6.7.3

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.
@@ -9,17 +9,18 @@ var radash = require('radash');
9
9
  */
10
10
  class BaseShardQueryMapBuilder {
11
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;
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 { entityManager, entityToken, hashKeyToken, pageKeyMap } = options;
20
+ this.entityManager = entityManager;
21
+ this.entityToken = entityToken;
22
+ this.hashKeyToken = hashKeyToken;
23
+ this.pageKeyMap = pageKeyMap;
23
24
  }
24
25
  /**
25
26
  * Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
package/dist/index.d.ts CHANGED
@@ -381,119 +381,6 @@ interface QueryResult<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], E
381
381
  pageKeyMap: string;
382
382
  }
383
383
 
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
384
  declare const configSchema: z.ZodEffects<z.ZodObject<{
498
385
  entities: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
499
386
  defaultLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
@@ -805,6 +692,117 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
805
692
  */
806
693
  type ParsedConfig = z.infer<typeof configSchema>;
807
694
 
695
+ /**
696
+ * A result returned by a {@link ShardQueryFunction | `ShardQueryFunction`} querying an individual shard.
697
+ *
698
+ * @typeParam Item - The {@link Item | `Item`} type being queried.
699
+
700
+ * @category Query
701
+ */
702
+ interface ShardQueryResult<Item extends Entity> {
703
+ /** The number of records returned. */
704
+ count: number;
705
+ /** The returned records. */
706
+ items: Item[];
707
+ /** The page key for the next query on this shard. */
708
+ pageKey?: Partial<Item>;
709
+ }
710
+
711
+ /**
712
+ * A query function that returns a single page of results from an individual
713
+ * shard. This function will typically be composed dynamically to express a
714
+ * specific query index & logic. The arguments to this function will be
715
+ * provided by the {@link EntityManager.query | `EntityManager.query`} method, which assembles many returned
716
+ * pages queried across multiple shards into a single query result.
717
+ *
718
+ * @typeParam Item - The {@link Item | `Item`} type being queried.
719
+
720
+ * @param hashKey - The hash key value of the shard being queried.
721
+ * @param pageKey - The page key returned by the previous query on this shard.
722
+ * @param pageSize - The maximum number of items to return from this query.
723
+ *
724
+ * @category Query
725
+ */
726
+ type ShardQueryFunction<Item extends Entity> = (hashKey: string, pageKey?: Partial<Item>, pageSize?: number) => Promise<ShardQueryResult<Item>>;
727
+
728
+ type ShardQueryMap<Item extends Entity> = Record<string, ShardQueryFunction<Item>>;
729
+
730
+ /**
731
+ * Options passed to the {@link query | `query`} function.
732
+ *
733
+ * @category Query
734
+ */
735
+ interface QueryOptions<Item extends ItemMap<M, HashKey, RangeKey>[EntityToken], EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string> {
736
+ /** Identifies the entity to be queried. Key of {@link Config | `EntityManager.config.entities`}. */
737
+ entityToken: EntityToken;
738
+ /**
739
+ * Partial item object sufficiently populated to generate index hash keys.
740
+ */
741
+ item: Partial<Item>;
742
+ /**
743
+ * The target maximum number of records to be returned by the query across
744
+ * all shards.
745
+ *
746
+ * The actual number of records returned will be a product of {@link QueryOptions.pageSize | `pageSize`} and the
747
+ * number of shards queried, unless limited by available records in a given
748
+ * shard.
749
+ */
750
+ limit?: number;
751
+ /**
752
+ * {@link QueryResult.pageKeyMap | `pageKeyMap`} returned by the previous iteration of this query.
753
+ */
754
+ pageKeyMap?: string;
755
+ /**
756
+ * The maximum number of records to be returned by each individual query to a
757
+ * single shard (i.e. {@link ShardQueryFunction | `ShardQueryFunction`} execution).
758
+ *
759
+ * Note that, within a given {@link EntityManager.query | `query`} method execution, these queries will be
760
+ * repeated until either available data is exhausted or the {@link QueryOptions.limit | `limit`} value is
761
+ * reached.
762
+ */
763
+ pageSize?: number;
764
+ /**
765
+ * Each key in this object is a valid entity index token. Each value is a valid
766
+ * {@link ShardQueryFunction | 'ShardQueryFunction'} that specifies the query of a single page of data on a
767
+ * single shard for the mapped index.
768
+ *
769
+ * This allows simultaneous queries on multiple sort keys to share a single
770
+ * page key, e.g. to match the same string against `firstName` and `lastName`
771
+ * properties without performing a table scan for either.
772
+ */
773
+ shardQueryMap: ShardQueryMap<Item>;
774
+ /**
775
+ * A {@link SortOrder | `SortOrder`} object specifying the sort order of the result set. Defaults to `[]`.
776
+ */
777
+ sortOrder?: SortOrder<Item>;
778
+ /**
779
+ * Lower limit to query shard space.
780
+ *
781
+ * Only valid if the query is constrained along the dimension used by the
782
+ * {@link Config | `EntityManager.config.entities.<entityToken>.sharding.timestamptokens.timestamp`}
783
+ * function to generate `shardKey`.
784
+ *
785
+ * @defaultValue `0`
786
+ */
787
+ timestampFrom?: number;
788
+ /**
789
+ * Upper limit to query shard space.
790
+ *
791
+ * Only valid if the query is constrained along the dimension used by the
792
+ * {@link Config | `EntityManager.config.entities.<entityToken>.sharding.timestamptokens.timestamp`}
793
+ * function to generate `shardKey`.
794
+ *
795
+ * @defaultValue `Date.now()`
796
+ */
797
+ timestampTo?: number;
798
+ /**
799
+ * The maximum number of shards to query in parallel. Overrides options `throttle`.
800
+ *
801
+ * @defaultValue `options.throttle`
802
+ */
803
+ throttle?: number;
804
+ }
805
+
808
806
  /**
809
807
  * The EntityManager class applies a configuration-driven sharded data model &
810
808
  * query strategy to NoSql data.
@@ -877,24 +875,44 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
877
875
  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
876
  }
879
877
 
878
+ /**
879
+ * Constructor options for {@link BaseShardQueryMapBuilder | `BaseShardQueryMapBuilder`}.
880
+ */
881
+ interface BaseShardQueryMapBuilderOptions<EntityToken extends keyof Exactify<M> & string, M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> {
882
+ /** {@link EntityManager | `EntityManager`} instance. */
883
+ entityManager: EntityManager<M, HashKey, RangeKey, T>;
884
+ /** Entity token. */
885
+ entityToken: EntityToken;
886
+ /** Hash key token. */
887
+ hashKeyToken: PropertiesOfType<M[EntityToken], never> | HashKey;
888
+ /** Dehydrated page key map. */
889
+ pageKeyMap?: string;
890
+ }
891
+
892
+ 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'>;
893
+
880
894
  /**
881
895
  * Abstract base class supporting a fluent API for building a {@link ShardQueryMap | `ShardQueryMap`} using a database client.
882
896
  *
883
897
  * @category ShardQueryMapBuilder
884
898
  */
885
899
  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> {
900
+ /** {@link EntityManager | `EntityManager`} instance. */
886
901
  readonly entityManager: EntityManager<M, HashKey, RangeKey, T>;
902
+ /** Entity token. */
887
903
  readonly entityToken: EntityToken;
904
+ /** Hash key token. */
888
905
  readonly hashKeyToken: PropertiesOfType<M[EntityToken], never> | HashKey;
889
- readonly pageKeyMap?: string | undefined;
906
+ /** Dehydrated page key map. */
907
+ readonly pageKeyMap?: string;
890
908
  /**
891
- * Maps `indexToken` values to database platform-specific parameters.
909
+ * Maps `indexToken` values to database platform-specific query parameters.
892
910
  *
893
911
  * @protected
894
912
  */
895
913
  readonly indexParamsMap: Record<string, IndexParams>;
896
914
  /** BaseShardQueryMapBuilder constructor. */
897
- constructor(entityManager: EntityManager<M, HashKey, RangeKey, T>, entityToken: EntityToken, hashKeyToken: PropertiesOfType<M[EntityToken], never> | HashKey, pageKeyMap?: string | undefined);
915
+ constructor(options: BaseShardQueryMapBuilderOptions<EntityToken, M, HashKey, RangeKey, T>);
898
916
  protected abstract getShardQueryFunction(indexToken: string): ShardQueryFunction<Item>;
899
917
  /**
900
918
  * Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
@@ -902,7 +920,7 @@ declare abstract class BaseShardQueryMapBuilder<IndexParams, Item extends ItemMa
902
920
  * @returns - The {@link ShardQueryMap | `ShardQueryMap`} object.
903
921
  */
904
922
  build(): ShardQueryMap<Item>;
905
- query(options: BuilderQueryOptions<Item, EntityToken, M, HashKey, RangeKey>): Promise<QueryResult<Item, EntityToken, M, HashKey, RangeKey>>;
923
+ query(options: ShardQueryMapBuilderQueryOptions<Item, EntityToken, M, HashKey, RangeKey>): Promise<QueryResult<Item, EntityToken, M, HashKey, RangeKey>>;
906
924
  }
907
925
 
908
926
  /**
@@ -918,4 +936,4 @@ declare abstract class BaseShardQueryMapBuilder<IndexParams, Item extends ItemMa
918
936
  */
919
937
  declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
920
938
 
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 };
939
+ export { 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 };
@@ -7,17 +7,18 @@ import { mapValues } from 'radash';
7
7
  */
8
8
  class BaseShardQueryMapBuilder {
9
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;
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 { entityManager, entityToken, hashKeyToken, pageKeyMap } = options;
18
+ this.entityManager = entityManager;
19
+ this.entityToken = entityToken;
20
+ this.hashKeyToken = hashKeyToken;
21
+ this.pageKeyMap = pageKeyMap;
21
22
  }
22
23
  /**
23
24
  * Builds a {@link ShardQueryMap | `ShardQueryMap`} object.
package/package.json CHANGED
@@ -131,5 +131,5 @@
131
131
  },
132
132
  "type": "module",
133
133
  "types": "dist/index.d.ts",
134
- "version": "6.7.2"
134
+ "version": "6.7.3"
135
135
  }