@karmaniverous/entity-manager 6.10.0 → 6.10.2

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.
@@ -3,6 +3,8 @@
3
3
  /**
4
4
  * Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
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
+ *
6
8
  * @category EntityClient
7
9
  */
8
10
  class BaseEntityClient {
@@ -11,7 +13,8 @@ class BaseEntityClient {
11
13
  *
12
14
  * @param options - {@link BaseEntityClientOptions | `BaseEntityClientOptions`} object.
13
15
  */
14
- constructor(options) {
16
+ constructor(entityManager, options = {}) {
17
+ this.entityManager = entityManager;
15
18
  const { batchProcessOptions = {}, logger = console } = options;
16
19
  this.batchProcessOptions = batchProcessOptions;
17
20
  this.logger = logger;
@@ -20,9 +20,8 @@ class BaseQueryBuilder {
20
20
  * @protected
21
21
  */
22
22
  this.indexParamsMap = {};
23
- const { entityClient, entityManager, entityToken, hashKeyToken, pageKeyMap, } = options;
23
+ const { entityClient, entityToken, hashKeyToken, pageKeyMap } = options;
24
24
  this.entityClient = entityClient;
25
- this.entityManager = entityManager;
26
25
  this.entityToken = entityToken;
27
26
  this.hashKeyToken = hashKeyToken;
28
27
  this.pageKeyMap = pageKeyMap;
@@ -36,7 +35,7 @@ class BaseQueryBuilder {
36
35
  return radash.mapValues(this.indexParamsMap, (indexConfig, indexToken) => this.getShardQueryFunction(indexToken));
37
36
  }
38
37
  async query(options) {
39
- const { entityManager, entityToken, pageKeyMap } = this;
38
+ const { entityClient: { entityManager }, entityToken, pageKeyMap, } = this;
40
39
  const shardQueryMap = this.build();
41
40
  return await entityManager.query({
42
41
  ...options,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EntityMap, TranscodeMap, FlattenEntityMap, ConditionalProperty, Exactify, PropertiesOfType, TranscodableProperties, Transcodes, SortOrder, MutuallyExclusive, NotNever, DefaultTranscodeMap } from '@karmaniverous/entity-tools';
1
+ import { EntityMap, TranscodeMap, ConditionalProperty, Exactify, PropertiesOfType, TranscodableProperties, FlattenEntityMap, 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
 
@@ -20,6 +20,8 @@ interface BaseConfigMap {
20
20
  /**
21
21
  * Base EntityClient options.
22
22
  *
23
+ * @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`}.
24
+ *
23
25
  * @category EntityClient
24
26
  */
25
27
  interface BaseEntityClientOptions {
@@ -29,52 +31,6 @@ interface BaseEntityClientOptions {
29
31
  logger?: Pick<Console, 'debug' | 'error'>;
30
32
  }
31
33
 
32
- /**
33
- * Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
34
- *
35
- * @category EntityClient
36
- */
37
- declare abstract class BaseEntityClient {
38
- readonly batchProcessOptions: NonNullable<BaseEntityClientOptions['batchProcessOptions']>;
39
- readonly logger: NonNullable<BaseEntityClientOptions['logger']>;
40
- /**
41
- * DynamoDB EntityClient constructor.
42
- *
43
- * @param options - {@link BaseEntityClientOptions | `BaseEntityClientOptions`} object.
44
- */
45
- constructor(options: BaseEntityClientOptions);
46
- }
47
-
48
- /**
49
- * Extracts a database-facing partial item type from a {@link BaseConfigMap | `ConfigMap`}.
50
- *
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
55
- */
56
- type EntityItem<C extends BaseConfigMap> = Partial<FlattenEntityMap<C['EntityMap']> & Record<C['HashKey'] | C['RangeKey'] | C['ShardedKeys'] | C['UnshardedKeys'], string>> & Record<string, unknown>;
57
-
58
- /**
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`}.
60
- *
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
65
- */
66
- interface QueryResult<C extends BaseConfigMap> {
67
- /** Total number of records returned across all shards. */
68
- count: number;
69
- /** The returned records. */
70
- items: EntityItem<C>[];
71
- /**
72
- * A compressed, two-layer map of page keys, used to query the next page of
73
- * data for a given sort key on each shard of a given hash key.
74
- */
75
- pageKeyMap: string;
76
- }
77
-
78
34
  /**
79
35
  * Defines a single time period in an entity sharding strategy.
80
36
  *
@@ -134,6 +90,16 @@ type Config<C extends BaseConfigMap = BaseConfigMap> = ConditionalProperty<'enti
134
90
  throttle?: number;
135
91
  };
136
92
 
93
+ /**
94
+ * Extracts a database-facing partial item type from a {@link BaseConfigMap | `ConfigMap`}.
95
+ *
96
+ * @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`}.
97
+ *
98
+ * @category EntityManager
99
+ * @protected
100
+ */
101
+ type EntityItem<C extends BaseConfigMap> = Partial<FlattenEntityMap<C['EntityMap']> & Record<C['HashKey'] | C['RangeKey'] | C['ShardedKeys'] | C['UnshardedKeys'], string>> & Record<string, unknown>;
102
+
137
103
  /**
138
104
  * Extracts entity tokens from a {@link ConfigMap | `ConfigMap`}.
139
105
  *
@@ -516,6 +482,26 @@ interface QueryOptions<C extends BaseConfigMap> {
516
482
  throttle?: number;
517
483
  }
518
484
 
485
+ /**
486
+ * A result returned by a query across multiple shards, where each shard may receive multiple page queries via a dynamically-generated {@link ShardQueryFunction | `ShardQueryFunction`}.
487
+ *
488
+ * @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`}.
489
+ *
490
+ * @category EntityManager
491
+ * @protected
492
+ */
493
+ interface QueryResult<C extends BaseConfigMap> {
494
+ /** Total number of records returned across all shards. */
495
+ count: number;
496
+ /** The returned records. */
497
+ items: EntityItem<C>[];
498
+ /**
499
+ * A compressed, two-layer map of page keys, used to query the next page of
500
+ * data for a given sort key on each shard of a given hash key.
501
+ */
502
+ pageKeyMap: string;
503
+ }
504
+
519
505
  /**
520
506
  * The EntityManager class applies a configuration-driven sharded data model &
521
507
  * query strategy to NoSql data.
@@ -597,6 +583,25 @@ declare class EntityManager<C extends BaseConfigMap> {
597
583
  query(options: QueryOptions<C>): Promise<QueryResult<C>>;
598
584
  }
599
585
 
586
+ /**
587
+ * Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
588
+ *
589
+ * @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`}.
590
+ *
591
+ * @category EntityClient
592
+ */
593
+ declare abstract class BaseEntityClient<C extends BaseConfigMap> {
594
+ readonly entityManager: EntityManager<C>;
595
+ readonly batchProcessOptions: NonNullable<BaseEntityClientOptions['batchProcessOptions']>;
596
+ readonly logger: NonNullable<BaseEntityClientOptions['logger']>;
597
+ /**
598
+ * DynamoDB EntityClient constructor.
599
+ *
600
+ * @param options - {@link BaseEntityClientOptions | `BaseEntityClientOptions`} object.
601
+ */
602
+ constructor(entityManager: EntityManager<C>, options?: BaseEntityClientOptions);
603
+ }
604
+
600
605
  /**
601
606
  * Constructor options for {@link BaseQueryBuilder | `BaseQueryBuilder`}.
602
607
  *
@@ -605,11 +610,9 @@ declare class EntityManager<C extends BaseConfigMap> {
605
610
  *
606
611
  * @category QueryBuilder
607
612
  */
608
- interface BaseQueryBuilderOptions<C extends BaseConfigMap, EntityClient extends BaseEntityClient> {
613
+ interface BaseQueryBuilderOptions<C extends BaseConfigMap, EntityClient extends BaseEntityClient<C>> {
609
614
  /** {@link BaseEntityClient | `EntityClient`} instance. */
610
615
  entityClient: EntityClient;
611
- /** {@link EntityManager | `EntityManager`} instance. */
612
- entityManager: EntityManager<C>;
613
616
  /** Entity token. */
614
617
  entityToken: EntityToken<C>;
615
618
  /** Hash key token. */
@@ -638,11 +641,9 @@ type QueryBuilderQueryOptions<C extends BaseConfigMap> = Omit<QueryOptions<C>, '
638
641
  *
639
642
  * @category QueryBuilder
640
643
  */
641
- declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient extends BaseEntityClient, IndexParams> {
644
+ declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient extends BaseEntityClient<C>, IndexParams> {
642
645
  /** {@link BaseEntityClient | `EntityClient`} instance. */
643
646
  readonly entityClient: EntityClient;
644
- /** {@link EntityManager | `EntityManager`} instance. */
645
- readonly entityManager: EntityManager<C>;
646
647
  /** Entity token. */
647
648
  readonly entityToken: EntityToken<C>;
648
649
  /** Hash key token. */
@@ -709,17 +710,23 @@ type ConfigMap<M extends Partial<BaseConfigMap> = Partial<BaseConfigMap>> = Vali
709
710
  }>;
710
711
 
711
712
  /**
712
- * Replaces a the type of a key `K` in an `object` `T` with an {@link EntityItem | `EntityItem`}.
713
+ * Database-facing record key type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
713
714
  *
714
715
  * @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`}.
715
- * @typeParam T - The `object` type to modify.
716
- * @typeParam K - The key to replace with an {@link EntityItem | `EntityItem`}.
717
716
  *
718
717
  * @category EntityClient
719
718
  * @protected
720
719
  */
721
- type EntityItemize<C extends BaseConfigMap, T extends object, K extends string> = {
722
- [P in keyof T]: P extends K ? EntityItem<C> : T[P];
723
- };
720
+ type EntityKey<C extends BaseConfigMap> = Record<C['HashKey'] | C['RangeKey'], string>;
721
+
722
+ /**
723
+ * Database-facing record type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
724
+ *
725
+ * @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`}.
726
+ *
727
+ * @category EntityManager
728
+ * @protected
729
+ */
730
+ type EntityRecord<C extends BaseConfigMap> = EntityItem<C> & EntityKey<C>;
724
731
 
725
- export { type BaseConfigMap, BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type Config, type ConfigMap, type EntityItem, type EntityItemize, EntityManager, type EntityToken, type PageKey, type ParsedConfig, type QueryBuilderQueryOptions, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type ValidateConfigMap };
732
+ export { type BaseConfigMap, BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type Config, type ConfigMap, type EntityItem, type EntityKey, EntityManager, type EntityRecord, type EntityToken, type PageKey, type ParsedConfig, type QueryBuilderQueryOptions, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type ValidateConfigMap };
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Base EntityClient class. Integrates {@link EntityManager | `EntityManager`} with injected logging & enhanced batch processing.
3
3
  *
4
+ * @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`}.
5
+ *
4
6
  * @category EntityClient
5
7
  */
6
8
  class BaseEntityClient {
@@ -9,7 +11,8 @@ class BaseEntityClient {
9
11
  *
10
12
  * @param options - {@link BaseEntityClientOptions | `BaseEntityClientOptions`} object.
11
13
  */
12
- constructor(options) {
14
+ constructor(entityManager, options = {}) {
15
+ this.entityManager = entityManager;
13
16
  const { batchProcessOptions = {}, logger = console } = options;
14
17
  this.batchProcessOptions = batchProcessOptions;
15
18
  this.logger = logger;
@@ -18,9 +18,8 @@ class BaseQueryBuilder {
18
18
  * @protected
19
19
  */
20
20
  this.indexParamsMap = {};
21
- const { entityClient, entityManager, entityToken, hashKeyToken, pageKeyMap, } = options;
21
+ const { entityClient, entityToken, hashKeyToken, pageKeyMap } = options;
22
22
  this.entityClient = entityClient;
23
- this.entityManager = entityManager;
24
23
  this.entityToken = entityToken;
25
24
  this.hashKeyToken = hashKeyToken;
26
25
  this.pageKeyMap = pageKeyMap;
@@ -34,7 +33,7 @@ class BaseQueryBuilder {
34
33
  return mapValues(this.indexParamsMap, (indexConfig, indexToken) => this.getShardQueryFunction(indexToken));
35
34
  }
36
35
  async query(options) {
37
- const { entityManager, entityToken, pageKeyMap } = this;
36
+ const { entityClient: { entityManager }, entityToken, pageKeyMap, } = this;
38
37
  const shardQueryMap = this.build();
39
38
  return await entityManager.query({
40
39
  ...options,
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.6.1",
8
+ "@karmaniverous/entity-tools": "^0.6.2",
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.5",
42
+ "knip": "^5.36.7",
43
43
  "lefthook": "^1.8.2",
44
44
  "mocha": "^10.8.2",
45
45
  "nyc": "^17.1.0",
@@ -56,7 +56,7 @@
56
56
  "typedoc-plugin-replace-text": "^4.0.0",
57
57
  "typedoc-plugin-zod": "^1.2.1",
58
58
  "typescript": "^5.6.3",
59
- "typescript-eslint": "^8.13.0"
59
+ "typescript-eslint": "^8.14.0"
60
60
  },
61
61
  "exports": {
62
62
  ".": {
@@ -132,5 +132,5 @@
132
132
  },
133
133
  "type": "module",
134
134
  "types": "dist/index.d.ts",
135
- "version": "6.10.0"
135
+ "version": "6.10.2"
136
136
  }