@karmaniverous/entity-manager 6.0.1 → 6.1.0-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.
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
4
+ var conditionalize = require('./conditionalize.js');
5
+ var typed = require('../node_modules/radash/dist/esm/typed.js');
6
+
7
+ var _EntityManagerClient_options;
8
+ /**
9
+ * EntityManagerClient base class.
10
+ *
11
+ * @category Client
12
+ */
13
+ class EntityManagerClient {
14
+ constructor({ batchSize = 25, delayIncrement = 100, maxRetries = 5, throttle = 10, logger = console, logInternals = false, ...childOptions }) {
15
+ _EntityManagerClient_options.set(this, void 0);
16
+ if (!typed.isFunction(logger.debug))
17
+ throw new Error('logger must support debug method');
18
+ if (!typed.isFunction(logger.error))
19
+ throw new Error('logger must support error method');
20
+ tslib_es6.__classPrivateFieldSet(this, _EntityManagerClient_options, {
21
+ batchSize,
22
+ delayIncrement,
23
+ maxRetries,
24
+ throttle,
25
+ logInternals,
26
+ logger: {
27
+ ...logger,
28
+ debug: conditionalize.conditionalize(logger.debug, logInternals),
29
+ },
30
+ ...childOptions,
31
+ }, "f");
32
+ }
33
+ /**
34
+ * Returns the options used to create the EntityManagerClient instance.
35
+ */
36
+ get options() {
37
+ return tslib_es6.__classPrivateFieldGet(this, _EntityManagerClient_options, "f");
38
+ }
39
+ }
40
+ _EntityManagerClient_options = new WeakMap();
41
+
42
+ exports.EntityManagerClient = EntityManagerClient;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Transforms a function such that it only executes when `condition` is truthy.
5
+ *
6
+ * @param fn - The function to conditionally execute.
7
+ * @param condition - The condition to check before executing `fn`.
8
+ *
9
+ * @typeParam F - The type of the function to conditionally execute.
10
+ *
11
+ * @returns The conditionalized function with the same signature as `fn`.
12
+ *
13
+ */
14
+ function conditionalize(fn, condition) {
15
+ return (...args) => {
16
+ if (condition) {
17
+ return fn(...args);
18
+ }
19
+ else {
20
+ return undefined;
21
+ }
22
+ };
23
+ }
24
+
25
+ exports.conditionalize = conditionalize;
@@ -1,7 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var conditionalize = require('./conditionalize.js');
3
4
  var EntityManager = require('./EntityManager.js');
5
+ var EntityManagerClient = require('./EntityManagerClient.js');
4
6
 
5
7
 
6
8
 
9
+ exports.conditionalize = conditionalize.conditionalize;
7
10
  exports.EntityManager = EntityManager.EntityManager;
11
+ exports.EntityManagerClient = EntityManagerClient.EntityManagerClient;
package/dist/index.d.cts CHANGED
@@ -2,6 +2,19 @@ import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodablePropertie
2
2
  export { DefaultTranscodeMap, Entity, PropertiesOfType, SortOrder, TranscodableProperties, TranscodeMap, Transcodes, defaultTranscodes } from '@karmaniverous/entity-tools';
3
3
  import { z } from 'zod';
4
4
 
5
+ /**
6
+ * Transforms a function such that it only executes when `condition` is truthy.
7
+ *
8
+ * @param fn - The function to conditionally execute.
9
+ * @param condition - The condition to check before executing `fn`.
10
+ *
11
+ * @typeParam F - The type of the function to conditionally execute.
12
+ *
13
+ * @returns The conditionalized function with the same signature as `fn`.
14
+ *
15
+ */
16
+ declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
17
+
5
18
  /**
6
19
  * The base EntityMap type. All EntityMaps should extend this type.
7
20
  *
@@ -823,4 +836,65 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
823
836
  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>>;
824
837
  }
825
838
 
826
- export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigKeys, type ConfigTranscodes, EntityManager, type EntityMap, type ExclusiveKey, type ItemMap, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryResult, type Unwrap };
839
+ /**
840
+ * Options for EntityManager client methods that support batch operations.
841
+ */
842
+ interface EntityManagerClientBatchOptions {
843
+ /** Batch size. */
844
+ batchSize?: number;
845
+ /** Delay increment in ms for retry operations. Doubles on each retry. */
846
+ delayIncrement?: number;
847
+ /** Max retries for retry operations. */
848
+ maxRetries?: number;
849
+ /** Throttle for parallel operations. */
850
+ throttle?: number;
851
+ }
852
+
853
+ /**
854
+ * Generic logger endpoint type.
855
+ *
856
+ * @category Logger
857
+ */
858
+ type LoggerEndpoint = (...args: unknown[]) => void;
859
+ /**
860
+ * Logger interface.
861
+ *
862
+ * @category Logger
863
+ */
864
+ interface Logger {
865
+ debug: LoggerEndpoint;
866
+ error: LoggerEndpoint;
867
+ }
868
+ /**
869
+ * Logger options.
870
+ *
871
+ * @category Logger
872
+ */
873
+ interface LoggerOptions {
874
+ /** Logger to use for internal logging. Must support the `debug` & `error` methods. Defaults to `console`. */
875
+ logger?: Logger;
876
+ /** Enables internal logging when `true`. */
877
+ logInternals?: boolean;
878
+ }
879
+
880
+ /**
881
+ * EntityManagerClient base class options.
882
+ *
883
+ * @category Client
884
+ */
885
+ type EntityManagerClientOptions = EntityManagerClientBatchOptions & LoggerOptions;
886
+ /**
887
+ * EntityManagerClient base class.
888
+ *
889
+ * @category Client
890
+ */
891
+ declare abstract class EntityManagerClient<O extends EntityManagerClientOptions> {
892
+ #private;
893
+ constructor({ batchSize, delayIncrement, maxRetries, throttle, logger, logInternals, ...childOptions }: O);
894
+ /**
895
+ * Returns the options used to create the EntityManagerClient instance.
896
+ */
897
+ get options(): Required<O>;
898
+ }
899
+
900
+ 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 ShardQueryResult, type Unwrap, conditionalize };
package/dist/index.d.mts CHANGED
@@ -2,6 +2,19 @@ import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodablePropertie
2
2
  export { DefaultTranscodeMap, Entity, PropertiesOfType, SortOrder, TranscodableProperties, TranscodeMap, Transcodes, defaultTranscodes } from '@karmaniverous/entity-tools';
3
3
  import { z } from 'zod';
4
4
 
5
+ /**
6
+ * Transforms a function such that it only executes when `condition` is truthy.
7
+ *
8
+ * @param fn - The function to conditionally execute.
9
+ * @param condition - The condition to check before executing `fn`.
10
+ *
11
+ * @typeParam F - The type of the function to conditionally execute.
12
+ *
13
+ * @returns The conditionalized function with the same signature as `fn`.
14
+ *
15
+ */
16
+ declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
17
+
5
18
  /**
6
19
  * The base EntityMap type. All EntityMaps should extend this type.
7
20
  *
@@ -823,4 +836,65 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
823
836
  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>>;
824
837
  }
825
838
 
826
- export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigKeys, type ConfigTranscodes, EntityManager, type EntityMap, type ExclusiveKey, type ItemMap, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryResult, type Unwrap };
839
+ /**
840
+ * Options for EntityManager client methods that support batch operations.
841
+ */
842
+ interface EntityManagerClientBatchOptions {
843
+ /** Batch size. */
844
+ batchSize?: number;
845
+ /** Delay increment in ms for retry operations. Doubles on each retry. */
846
+ delayIncrement?: number;
847
+ /** Max retries for retry operations. */
848
+ maxRetries?: number;
849
+ /** Throttle for parallel operations. */
850
+ throttle?: number;
851
+ }
852
+
853
+ /**
854
+ * Generic logger endpoint type.
855
+ *
856
+ * @category Logger
857
+ */
858
+ type LoggerEndpoint = (...args: unknown[]) => void;
859
+ /**
860
+ * Logger interface.
861
+ *
862
+ * @category Logger
863
+ */
864
+ interface Logger {
865
+ debug: LoggerEndpoint;
866
+ error: LoggerEndpoint;
867
+ }
868
+ /**
869
+ * Logger options.
870
+ *
871
+ * @category Logger
872
+ */
873
+ interface LoggerOptions {
874
+ /** Logger to use for internal logging. Must support the `debug` & `error` methods. Defaults to `console`. */
875
+ logger?: Logger;
876
+ /** Enables internal logging when `true`. */
877
+ logInternals?: boolean;
878
+ }
879
+
880
+ /**
881
+ * EntityManagerClient base class options.
882
+ *
883
+ * @category Client
884
+ */
885
+ type EntityManagerClientOptions = EntityManagerClientBatchOptions & LoggerOptions;
886
+ /**
887
+ * EntityManagerClient base class.
888
+ *
889
+ * @category Client
890
+ */
891
+ declare abstract class EntityManagerClient<O extends EntityManagerClientOptions> {
892
+ #private;
893
+ constructor({ batchSize, delayIncrement, maxRetries, throttle, logger, logInternals, ...childOptions }: O);
894
+ /**
895
+ * Returns the options used to create the EntityManagerClient instance.
896
+ */
897
+ get options(): Required<O>;
898
+ }
899
+
900
+ 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 ShardQueryResult, type Unwrap, conditionalize };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,19 @@ import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodablePropertie
2
2
  export { DefaultTranscodeMap, Entity, PropertiesOfType, SortOrder, TranscodableProperties, TranscodeMap, Transcodes, defaultTranscodes } from '@karmaniverous/entity-tools';
3
3
  import { z } from 'zod';
4
4
 
5
+ /**
6
+ * Transforms a function such that it only executes when `condition` is truthy.
7
+ *
8
+ * @param fn - The function to conditionally execute.
9
+ * @param condition - The condition to check before executing `fn`.
10
+ *
11
+ * @typeParam F - The type of the function to conditionally execute.
12
+ *
13
+ * @returns The conditionalized function with the same signature as `fn`.
14
+ *
15
+ */
16
+ declare function conditionalize<F extends (...args: Parameters<F>) => ReturnType<F>>(fn: F, condition?: unknown): (...args: Parameters<F>) => ReturnType<F> | undefined;
17
+
5
18
  /**
6
19
  * The base EntityMap type. All EntityMaps should extend this type.
7
20
  *
@@ -823,4 +836,65 @@ declare class EntityManager<M extends EntityMap, HashKey extends string, RangeKe
823
836
  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>>;
824
837
  }
825
838
 
826
- export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigKeys, type ConfigTranscodes, EntityManager, type EntityMap, type ExclusiveKey, type ItemMap, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryResult, type Unwrap };
839
+ /**
840
+ * Options for EntityManager client methods that support batch operations.
841
+ */
842
+ interface EntityManagerClientBatchOptions {
843
+ /** Batch size. */
844
+ batchSize?: number;
845
+ /** Delay increment in ms for retry operations. Doubles on each retry. */
846
+ delayIncrement?: number;
847
+ /** Max retries for retry operations. */
848
+ maxRetries?: number;
849
+ /** Throttle for parallel operations. */
850
+ throttle?: number;
851
+ }
852
+
853
+ /**
854
+ * Generic logger endpoint type.
855
+ *
856
+ * @category Logger
857
+ */
858
+ type LoggerEndpoint = (...args: unknown[]) => void;
859
+ /**
860
+ * Logger interface.
861
+ *
862
+ * @category Logger
863
+ */
864
+ interface Logger {
865
+ debug: LoggerEndpoint;
866
+ error: LoggerEndpoint;
867
+ }
868
+ /**
869
+ * Logger options.
870
+ *
871
+ * @category Logger
872
+ */
873
+ interface LoggerOptions {
874
+ /** Logger to use for internal logging. Must support the `debug` & `error` methods. Defaults to `console`. */
875
+ logger?: Logger;
876
+ /** Enables internal logging when `true`. */
877
+ logInternals?: boolean;
878
+ }
879
+
880
+ /**
881
+ * EntityManagerClient base class options.
882
+ *
883
+ * @category Client
884
+ */
885
+ type EntityManagerClientOptions = EntityManagerClientBatchOptions & LoggerOptions;
886
+ /**
887
+ * EntityManagerClient base class.
888
+ *
889
+ * @category Client
890
+ */
891
+ declare abstract class EntityManagerClient<O extends EntityManagerClientOptions> {
892
+ #private;
893
+ constructor({ batchSize, delayIncrement, maxRetries, throttle, logger, logInternals, ...childOptions }: O);
894
+ /**
895
+ * Returns the options used to create the EntityManagerClient instance.
896
+ */
897
+ get options(): Required<O>;
898
+ }
899
+
900
+ 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 ShardQueryResult, type Unwrap, conditionalize };
@@ -0,0 +1,40 @@
1
+ import { __classPrivateFieldSet, __classPrivateFieldGet } from '../node_modules/tslib/tslib.es6.js';
2
+ import { conditionalize } from './conditionalize.js';
3
+ import { isFunction } from '../node_modules/radash/dist/esm/typed.js';
4
+
5
+ var _EntityManagerClient_options;
6
+ /**
7
+ * EntityManagerClient base class.
8
+ *
9
+ * @category Client
10
+ */
11
+ class EntityManagerClient {
12
+ constructor({ batchSize = 25, delayIncrement = 100, maxRetries = 5, throttle = 10, logger = console, logInternals = false, ...childOptions }) {
13
+ _EntityManagerClient_options.set(this, void 0);
14
+ if (!isFunction(logger.debug))
15
+ throw new Error('logger must support debug method');
16
+ if (!isFunction(logger.error))
17
+ throw new Error('logger must support error method');
18
+ __classPrivateFieldSet(this, _EntityManagerClient_options, {
19
+ batchSize,
20
+ delayIncrement,
21
+ maxRetries,
22
+ throttle,
23
+ logInternals,
24
+ logger: {
25
+ ...logger,
26
+ debug: conditionalize(logger.debug, logInternals),
27
+ },
28
+ ...childOptions,
29
+ }, "f");
30
+ }
31
+ /**
32
+ * Returns the options used to create the EntityManagerClient instance.
33
+ */
34
+ get options() {
35
+ return __classPrivateFieldGet(this, _EntityManagerClient_options, "f");
36
+ }
37
+ }
38
+ _EntityManagerClient_options = new WeakMap();
39
+
40
+ export { EntityManagerClient };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Transforms a function such that it only executes when `condition` is truthy.
3
+ *
4
+ * @param fn - The function to conditionally execute.
5
+ * @param condition - The condition to check before executing `fn`.
6
+ *
7
+ * @typeParam F - The type of the function to conditionally execute.
8
+ *
9
+ * @returns The conditionalized function with the same signature as `fn`.
10
+ *
11
+ */
12
+ function conditionalize(fn, condition) {
13
+ return (...args) => {
14
+ if (condition) {
15
+ return fn(...args);
16
+ }
17
+ else {
18
+ return undefined;
19
+ }
20
+ };
21
+ }
22
+
23
+ export { conditionalize };
@@ -1 +1,3 @@
1
+ export { conditionalize } from './conditionalize.js';
1
2
  export { EntityManager } from './EntityManager.js';
3
+ export { EntityManagerClient } from './EntityManagerClient.js';
package/package.json CHANGED
@@ -132,5 +132,5 @@
132
132
  },
133
133
  "type": "module",
134
134
  "types": "dist/index.d.ts",
135
- "version": "6.0.1"
135
+ "version": "6.1.0-1"
136
136
  }