@venizia/ignis-helpers 0.4.6 → 0.4.7-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/LICENSE.md +1 -3
- package/README.md +4 -5
- package/dist/esm/common/redact.d.ts +25 -17
- package/dist/esm/common/redact.d.ts.map +1 -1
- package/dist/esm/common/redact.js +50 -46
- package/dist/esm/common/redact.js.map +1 -1
- package/dist/esm/common/resolvers.d.ts +7 -5
- package/dist/esm/common/resolvers.d.ts.map +1 -1
- package/dist/esm/common/resolvers.js +11 -9
- package/dist/esm/common/resolvers.js.map +1 -1
- package/dist/esm/core.d.ts +6 -3
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +6 -3
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/base.js +4 -4
- package/dist/esm/modules/base.js.map +1 -1
- package/dist/esm/modules/cron/helper.js +4 -4
- package/dist/esm/modules/cron/helper.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +3 -3
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +5 -5
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js +3 -3
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
- package/dist/esm/modules/env/app-env.d.ts.map +1 -1
- package/dist/esm/modules/env/app-env.js +2 -2
- package/dist/esm/modules/env/app-env.js.map +1 -1
- package/dist/esm/modules/logger/common/constants.d.ts +23 -21
- package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/logger/common/constants.js +45 -42
- package/dist/esm/modules/logger/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/factory.d.ts +5 -3
- package/dist/esm/modules/logger/factory.d.ts.map +1 -1
- package/dist/esm/modules/logger/factory.js +5 -3
- package/dist/esm/modules/logger/factory.js.map +1 -1
- package/dist/esm/modules/logger/formatting/deep-splat.d.ts +10 -6
- package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +1 -1
- package/dist/esm/modules/logger/formatting/deep-splat.js +73 -62
- package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
- package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +1 -1
- package/dist/esm/modules/logger/formatting/error-prettier.js +8 -6
- package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
- package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
- package/dist/esm/modules/logger/hf/logger.js +2 -2
- package/dist/esm/modules/logger/hf/logger.js.map +1 -1
- package/dist/esm/modules/logger/pino/backing.d.ts +0 -9
- package/dist/esm/modules/logger/pino/backing.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/backing.js +3 -8
- package/dist/esm/modules/logger/pino/backing.js.map +1 -1
- package/dist/esm/modules/logger/pino/destination.d.ts +6 -9
- package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/destination.js +12 -13
- package/dist/esm/modules/logger/pino/destination.js.map +1 -1
- package/dist/esm/modules/logger/pino/logger.js +2 -2
- package/dist/esm/modules/logger/pino/logger.js.map +1 -1
- package/dist/esm/modules/logger/resolver.js +2 -2
- package/dist/esm/modules/logger/resolver.js.map +1 -1
- package/dist/esm/modules/logger/slot.d.ts +39 -18
- package/dist/esm/modules/logger/slot.d.ts.map +1 -1
- package/dist/esm/modules/logger/slot.js +117 -110
- package/dist/esm/modules/logger/slot.js.map +1 -1
- package/dist/esm/modules/logger/winston/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/common/constants.js +7 -6
- package/dist/esm/modules/logger/winston/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/winston/define.d.ts +0 -7
- package/dist/esm/modules/logger/winston/define.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/define.js +0 -5
- package/dist/esm/modules/logger/winston/define.js.map +1 -1
- package/dist/esm/modules/logger/winston/formats.d.ts +2 -0
- package/dist/esm/modules/logger/winston/formats.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/formats.js +17 -4
- package/dist/esm/modules/logger/winston/formats.js.map +1 -1
- package/dist/esm/modules/logger/winston/index.d.ts +3 -2
- package/dist/esm/modules/logger/winston/index.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/index.js +3 -2
- package/dist/esm/modules/logger/winston/index.js.map +1 -1
- package/dist/esm/modules/logger/winston/logger-factory.js +4 -4
- package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
- package/dist/esm/modules/network/http-request/base-network-request.helper.js +2 -2
- package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/index.d.ts +0 -1
- package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/common/index.js +0 -1
- package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +4 -2
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +6 -4
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +4 -4
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +4 -4
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +2 -2
- package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
- package/dist/esm/modules/network/utilities/query-string.d.ts +22 -20
- package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/query-string.js +48 -46
- package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +0 -10
- package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/errors.js +0 -11
- package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.js +2 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +10 -0
- package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/policy.js +11 -0
- package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
- package/dist/esm/modules/pool/abstract.d.ts.map +1 -1
- package/dist/esm/modules/pool/abstract.js +4 -2
- package/dist/esm/modules/pool/abstract.js.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.d.ts.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.js +6 -6
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/queue/common/hook.d.ts +14 -12
- package/dist/esm/modules/queue/common/hook.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/hook.js +21 -19
- package/dist/esm/modules/queue/common/hook.js.map +1 -1
- package/dist/esm/modules/queue/common/index.d.ts +0 -1
- package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/index.js +0 -1
- package/dist/esm/modules/queue/common/index.js.map +1 -1
- package/dist/esm/modules/queue/internal/sequential/helper.js +8 -8
- package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
- package/dist/esm/modules/queue/kafka/base.js +3 -3
- package/dist/esm/modules/queue/kafka/base.js.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/index.d.ts +0 -2
- package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/index.js +0 -2
- package/dist/esm/modules/queue/kafka/bundler/index.js.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts +8 -2
- package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/plugins.js +64 -7
- package/dist/esm/modules/queue/kafka/bundler/plugins.js.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.js +26 -24
- package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/esm/modules/queue/mqtt/helper.js +10 -10
- package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
- package/dist/esm/modules/redis/base/abstract.helper.js +8 -8
- package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.js +2 -2
- package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
- package/dist/esm/modules/redis/factory.d.ts +13 -9
- package/dist/esm/modules/redis/factory.d.ts.map +1 -1
- package/dist/esm/modules/redis/factory.js +15 -13
- package/dist/esm/modules/redis/factory.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js +2 -2
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
- package/dist/esm/modules/redis/single/single.helper.js +2 -2
- package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
- package/dist/esm/modules/redis/utility.d.ts +13 -11
- package/dist/esm/modules/redis/utility.d.ts.map +1 -1
- package/dist/esm/modules/redis/utility.js +46 -44
- package/dist/esm/modules/redis/utility.js.map +1 -1
- package/dist/esm/modules/retry/helper.d.ts.map +1 -1
- package/dist/esm/modules/retry/helper.js +6 -4
- package/dist/esm/modules/retry/helper.js.map +1 -1
- package/dist/esm/modules/secrets/factory.d.ts +5 -3
- package/dist/esm/modules/secrets/factory.d.ts.map +1 -1
- package/dist/esm/modules/secrets/factory.js +36 -34
- package/dist/esm/modules/secrets/factory.js.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +4 -2
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +1 -1
- package/dist/esm/modules/socket/socket-io/server/helper.js +11 -11
- package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
- package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +1 -1
- package/dist/esm/modules/socket/websocket/emitter/helper.js +3 -3
- package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
- package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +1 -1
- package/dist/esm/modules/socket/websocket/server/delivery.js +5 -6
- package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
- package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +1 -1
- package/dist/esm/modules/socket/websocket/server/helper.js +7 -7
- package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
- package/dist/esm/modules/storage/base.d.ts.map +1 -1
- package/dist/esm/modules/storage/base.js +9 -8
- package/dist/esm/modules/storage/base.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.js +25 -18
- package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/utility.d.ts +95 -77
- package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +1 -1
- package/dist/esm/modules/storage/bun-s3/utility.js +261 -244
- package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
- package/dist/esm/modules/storage/common/errors.d.ts +0 -4
- package/dist/esm/modules/storage/common/errors.d.ts.map +1 -1
- package/dist/esm/modules/storage/common/errors.js +0 -10
- package/dist/esm/modules/storage/common/errors.js.map +1 -1
- package/dist/esm/modules/storage/common/utility.d.ts +11 -5
- package/dist/esm/modules/storage/common/utility.d.ts.map +1 -1
- package/dist/esm/modules/storage/common/utility.js +30 -17
- package/dist/esm/modules/storage/common/utility.js.map +1 -1
- package/dist/esm/modules/storage/disk/helper.d.ts.map +1 -1
- package/dist/esm/modules/storage/disk/helper.js +18 -9
- package/dist/esm/modules/storage/disk/helper.js.map +1 -1
- package/dist/esm/modules/tree/builder.d.ts.map +1 -1
- package/dist/esm/modules/tree/builder.js +2 -1
- package/dist/esm/modules/tree/builder.js.map +1 -1
- package/dist/esm/modules/uid/opaque.d.ts.map +1 -1
- package/dist/esm/modules/uid/opaque.js +4 -2
- package/dist/esm/modules/uid/opaque.js.map +1 -1
- package/dist/esm/modules/uid/uuid/helper.d.ts +1 -1
- package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/helper.js +7 -7
- package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v4.d.ts +11 -8
- package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/v4.js +51 -46
- package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v5.d.ts +17 -14
- package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/v5.js +83 -78
- package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v7.d.ts +15 -10
- package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/v7.js +88 -79
- package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
- package/dist/esm/modules/worker-thread/bus/base.js +2 -2
- package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/worker/base.d.ts.map +1 -1
- package/dist/esm/modules/worker-thread/worker/base.js +4 -3
- package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
- package/dist/esm/utilities/error.utility.d.ts +7 -0
- package/dist/esm/utilities/error.utility.d.ts.map +1 -0
- package/dist/esm/utilities/error.utility.js +9 -0
- package/dist/esm/utilities/error.utility.js.map +1 -0
- package/dist/esm/utilities/form-body.utility.d.ts +12 -10
- package/dist/esm/utilities/form-body.utility.d.ts.map +1 -1
- package/dist/esm/utilities/form-body.utility.js +19 -16
- package/dist/esm/utilities/form-body.utility.js.map +1 -1
- package/dist/esm/utilities/hr-time.utility.d.ts +7 -5
- package/dist/esm/utilities/hr-time.utility.d.ts.map +1 -1
- package/dist/esm/utilities/hr-time.utility.js +11 -9
- package/dist/esm/utilities/hr-time.utility.js.map +1 -1
- package/dist/esm/utilities/index.d.ts +2 -2
- package/dist/esm/utilities/index.d.ts.map +1 -1
- package/dist/esm/utilities/index.js +2 -2
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/module.utility.d.ts.map +1 -1
- package/dist/esm/utilities/module.utility.js +4 -2
- package/dist/esm/utilities/module.utility.js.map +1 -1
- package/dist/esm/utilities/parse.utility.d.ts +89 -43
- package/dist/esm/utilities/parse.utility.d.ts.map +1 -1
- package/dist/esm/utilities/parse.utility.js +173 -141
- package/dist/esm/utilities/parse.utility.js.map +1 -1
- package/dist/esm/utilities/performance.utility.d.ts +15 -13
- package/dist/esm/utilities/performance.utility.d.ts.map +1 -1
- package/dist/esm/utilities/performance.utility.js +34 -29
- package/dist/esm/utilities/performance.utility.js.map +1 -1
- package/dist/esm/utilities/promise.utility.d.ts +20 -18
- package/dist/esm/utilities/promise.utility.d.ts.map +1 -1
- package/dist/esm/utilities/promise.utility.js +41 -51
- package/dist/esm/utilities/promise.utility.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +35 -29
- package/dist/esm/utilities/request.utility.d.ts.map +1 -1
- package/dist/esm/utilities/request.utility.js +117 -115
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +4 -15
- package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts +0 -4
- package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts.map +0 -1
- package/dist/esm/modules/logger/winston/formatters/deep-splat.js +0 -14
- package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +0 -1
- package/dist/esm/modules/logger/winston/formatters/index.d.ts +0 -2
- package/dist/esm/modules/logger/winston/formatters/index.d.ts.map +0 -1
- package/dist/esm/modules/logger/winston/formatters/index.js +0 -2
- package/dist/esm/modules/logger/winston/formatters/index.js.map +0 -1
- package/dist/esm/modules/network/http-request/common/types.d.ts +0 -2
- package/dist/esm/modules/network/http-request/common/types.d.ts.map +0 -1
- package/dist/esm/modules/network/http-request/common/types.js +0 -2
- package/dist/esm/modules/network/http-request/common/types.js.map +0 -1
- package/dist/esm/modules/queue/common/types.d.ts +0 -2
- package/dist/esm/modules/queue/common/types.d.ts.map +0 -1
- package/dist/esm/modules/queue/common/types.js +0 -2
- package/dist/esm/modules/queue/common/types.js.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts +0 -4
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js +0 -28
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts +0 -4
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +0 -26
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +0 -1
- package/dist/esm/modules/storage/minio/helper.d.ts +0 -55
- package/dist/esm/modules/storage/minio/helper.d.ts.map +0 -1
- package/dist/esm/modules/storage/minio/helper.js +0 -176
- package/dist/esm/modules/storage/minio/helper.js.map +0 -1
- package/dist/esm/modules/storage/minio/index.d.ts +0 -2
- package/dist/esm/modules/storage/minio/index.d.ts.map +0 -1
- package/dist/esm/modules/storage/minio/index.js +0 -2
- package/dist/esm/modules/storage/minio/index.js.map +0 -1
- package/dist/esm/utilities/sleep.utility.d.ts +0 -2
- package/dist/esm/utilities/sleep.utility.d.ts.map +0 -1
- package/dist/esm/utilities/sleep.utility.js +0 -4
- package/dist/esm/utilities/sleep.utility.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AbstractRedisHelper } from './base/index.js';
|
|
1
2
|
import { RedisClusterHelper } from './cluster/index.js';
|
|
2
3
|
import { RedisModes } from './common/index.js';
|
|
3
4
|
import type { IRedisClusterHelperOptions, IRedisSentinelHelperOptions, IRedisSingleHelperOptions } from './common/index.js';
|
|
@@ -10,13 +11,16 @@ export type TCreateRedisHelperOptions = ({
|
|
|
10
11
|
} & IRedisClusterHelperOptions) | ({
|
|
11
12
|
mode: typeof RedisModes.SENTINEL;
|
|
12
13
|
} & IRedisSentinelHelperOptions);
|
|
13
|
-
export declare
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
export declare class RedisHelperFactory {
|
|
15
|
+
static create(opts: {
|
|
16
|
+
mode: typeof RedisModes.SINGLE;
|
|
17
|
+
} & IRedisSingleHelperOptions): RedisSingleHelper;
|
|
18
|
+
static create(opts: {
|
|
19
|
+
mode: typeof RedisModes.CLUSTER;
|
|
20
|
+
} & IRedisClusterHelperOptions): RedisClusterHelper;
|
|
21
|
+
static create(opts: {
|
|
22
|
+
mode: typeof RedisModes.SENTINEL;
|
|
23
|
+
} & IRedisSentinelHelperOptions): RedisSentinelHelper;
|
|
24
|
+
static create(opts: TCreateRedisHelperOptions): AbstractRedisHelper;
|
|
25
|
+
}
|
|
22
26
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/modules/redis/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/modules/redis/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,MAAM,yBAAyB,GACjC,CAAC;IAAE,IAAI,EAAE,OAAO,UAAU,CAAC,MAAM,CAAA;CAAE,GAAG,yBAAyB,CAAC,GAChE,CAAC;IAAE,IAAI,EAAE,OAAO,UAAU,CAAC,OAAO,CAAA;CAAE,GAAG,0BAA0B,CAAC,GAClE,CAAC;IAAE,IAAI,EAAE,OAAO,UAAU,CAAC,QAAQ,CAAA;CAAE,GAAG,2BAA2B,CAAC,CAAC;AAEzE,qBAAa,kBAAkB;IAC7B,MAAM,CAAC,MAAM,CACX,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,UAAU,CAAC,MAAM,CAAA;KAAE,GAAG,yBAAyB,GACnE,iBAAiB;IAEpB,MAAM,CAAC,MAAM,CACX,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,UAAU,CAAC,OAAO,CAAA;KAAE,GAAG,0BAA0B,GACrE,kBAAkB;IAErB,MAAM,CAAC,MAAM,CACX,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,UAAU,CAAC,QAAQ,CAAA;KAAE,GAAG,2BAA2B,GACvE,mBAAmB;IAEtB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,yBAAyB,GAAG,mBAAmB;CAkBpE"}
|
|
@@ -3,19 +3,21 @@ import { RedisClusterHelper } from './cluster/index.js';
|
|
|
3
3
|
import { RedisModes } from './common/index.js';
|
|
4
4
|
import { RedisSentinelHelper } from './sentinel/index.js';
|
|
5
5
|
import { RedisSingleHelper } from './single/index.js';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
export class RedisHelperFactory {
|
|
7
|
+
static create(opts) {
|
|
8
|
+
switch (opts.mode) {
|
|
9
|
+
case RedisModes.SINGLE: {
|
|
10
|
+
return new RedisSingleHelper(opts);
|
|
11
|
+
}
|
|
12
|
+
case RedisModes.CLUSTER: {
|
|
13
|
+
return new RedisClusterHelper(opts);
|
|
14
|
+
}
|
|
15
|
+
case RedisModes.SENTINEL: {
|
|
16
|
+
return new RedisSentinelHelper(opts);
|
|
17
|
+
}
|
|
18
|
+
default: {
|
|
19
|
+
throw getError({ message: '[RedisHelperFactory.create] Unsupported redis mode!' });
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/redis/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAMtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/redis/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAMtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAO7C,MAAM,OAAO,kBAAkB;IAe7B,MAAM,CAAC,MAAM,CAAC,IAA+B;QAC3C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;gBACvB,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YACD,KAAK,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;gBACxB,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC;YACD,KAAK,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;YACvC,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,qDAAqD,EAAE,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import { getError } from '@/modules/error';\nimport { type AbstractRedisHelper } from './base';\nimport { RedisClusterHelper } from './cluster';\nimport { RedisModes } from './common';\nimport type {\n IRedisClusterHelperOptions,\n IRedisSentinelHelperOptions,\n IRedisSingleHelperOptions,\n} from './common';\nimport { RedisSentinelHelper } from './sentinel';\nimport { RedisSingleHelper } from './single';\n\nexport type TCreateRedisHelperOptions =\n | ({ mode: typeof RedisModes.SINGLE } & IRedisSingleHelperOptions)\n | ({ mode: typeof RedisModes.CLUSTER } & IRedisClusterHelperOptions)\n | ({ mode: typeof RedisModes.SENTINEL } & IRedisSentinelHelperOptions);\n\nexport class RedisHelperFactory {\n static create(\n opts: { mode: typeof RedisModes.SINGLE } & IRedisSingleHelperOptions,\n ): RedisSingleHelper;\n\n static create(\n opts: { mode: typeof RedisModes.CLUSTER } & IRedisClusterHelperOptions,\n ): RedisClusterHelper;\n\n static create(\n opts: { mode: typeof RedisModes.SENTINEL } & IRedisSentinelHelperOptions,\n ): RedisSentinelHelper;\n\n static create(opts: TCreateRedisHelperOptions): AbstractRedisHelper;\n\n static create(opts: TCreateRedisHelperOptions): AbstractRedisHelper {\n switch (opts.mode) {\n case RedisModes.SINGLE: {\n return new RedisSingleHelper(opts);\n }\n case RedisModes.CLUSTER: {\n return new RedisClusterHelper(opts);\n }\n case RedisModes.SENTINEL: {\n return new RedisSentinelHelper(opts);\n }\n default: {\n throw getError({ message: '[RedisHelperFactory.create] Unsupported redis mode!' });\n }\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ModuleUtility } from '../../../utilities/module.utility.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ParseUtility } from '../../../utilities/parse.utility.js';
|
|
3
3
|
import { AbstractRedisHelper } from './../base/index.js';
|
|
4
4
|
import { RedisSentinelRoles } from './../common/index.js';
|
|
5
5
|
export class RedisSentinelHelper extends AbstractRedisHelper {
|
|
@@ -7,7 +7,7 @@ export class RedisSentinelHelper extends AbstractRedisHelper {
|
|
|
7
7
|
const { name, sentinels, masterName, role = RedisSentinelRoles.MASTER, password, sentinelPassword, sentinelUsername, database = 0, autoConnect = true, maxRetry = 0, redisOptions = {}, } = opts;
|
|
8
8
|
const normalizedSentinels = sentinels.map((sentinel) => ({
|
|
9
9
|
host: sentinel.host,
|
|
10
|
-
port:
|
|
10
|
+
port: ParseUtility.toInt({ input: sentinel.port ?? 26379 }),
|
|
11
11
|
}));
|
|
12
12
|
const ioredis = opts.module ?? ModuleUtility.loadSync({ module: 'ioredis' });
|
|
13
13
|
super({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentinel.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/sentinel/sentinel.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sentinel.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/sentinel/sentinel.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAoC,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnF,MAAM,OAAO,mBAAoB,SAAQ,mBAA0B;IACjE,YAAY,IAAiC;QAC3C,MAAM,EACJ,IAAI,EACJ,SAAS,EACT,UAAU,EACV,IAAI,GAAG,kBAAkB,CAAC,MAAM,EAChC,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,EAAE,GAClB,GAAG,IAAI,CAAC;QAET,MAAM,mBAAmB,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACvD,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,IAAI,KAAK,EAAE,CAAC;SAC5D,CAAC,CAAC,CAAC;QAEJ,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,mBAAmB,CAAC,IAAI;YAC/B,UAAU,EAAE,IAAI;YAChB,gPAAgP;YAChP,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC;gBACrD,GAAG,YAAY;gBACf,SAAS,EAAE,mBAAmB;gBAC9B,IAAI,EAAE,UAAU;gBAChB,IAAI;gBACJ,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;gBAC/C,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;gBAC/D,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;aAChE,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { type IRedisSentinelHelperOptions, RedisSentinelRoles } from './../common';\n\nexport class RedisSentinelHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSentinelHelperOptions) {\n const {\n name,\n sentinels,\n masterName,\n role = RedisSentinelRoles.MASTER,\n password,\n sentinelPassword,\n sentinelUsername,\n database = 0,\n autoConnect = true,\n maxRetry = 0,\n redisOptions = {},\n } = opts;\n\n const normalizedSentinels = sentinels.map((sentinel) => ({\n host: sentinel.host,\n port: ParseUtility.toInt({ input: sentinel.port ?? 26379 }),\n }));\n\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSentinelHelper.name,\n identifier: name,\n // Precedence (low -> high): framework defaults, the redisOptions escape hatch, then first-class fields. Optional auth fields are spread ONLY when provided, so a value set via redisOptions is not clobbered by an undefined first-class field.\n client: new ioredis.Redis({\n ...AbstractRedisHelper.buildDefaultOpts({ maxRetry }),\n ...redisOptions,\n sentinels: normalizedSentinels,\n name: masterName,\n role,\n db: database,\n lazyConnect: !autoConnect,\n ...(password === undefined ? {} : { password }),\n ...(sentinelPassword === undefined ? {} : { sentinelPassword }),\n ...(sentinelUsername === undefined ? {} : { sentinelUsername }),\n }),\n });\n }\n\n override getClient() {\n return this.client as Redis;\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ModuleUtility } from '../../../utilities/module.utility.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ParseUtility } from '../../../utilities/parse.utility.js';
|
|
3
3
|
import { AbstractRedisHelper } from './../base/index.js';
|
|
4
4
|
export class RedisSingleHelper extends AbstractRedisHelper {
|
|
5
5
|
constructor(opts) {
|
|
@@ -13,7 +13,7 @@ export class RedisSingleHelper extends AbstractRedisHelper {
|
|
|
13
13
|
client: new ioredis.Redis({
|
|
14
14
|
name,
|
|
15
15
|
host,
|
|
16
|
-
port:
|
|
16
|
+
port: ParseUtility.toInt({ input: port }),
|
|
17
17
|
password,
|
|
18
18
|
db: database,
|
|
19
19
|
lazyConnect: !autoConnect,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/single/single.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"single.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/single/single.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGhD,MAAM,OAAO,iBAAkB,SAAQ,mBAA0B;IAC/D,YAAY,IAA+B;QACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAG,CAAC,EAAE,WAAW,GAAG,IAAI,EAAE,QAAQ,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;QAE5F,0FAA0F;QAC1F,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,iBAAiB,CAAC,IAAI;YAC7B,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBACzC,QAAQ;gBACR,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC;aACtD,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { type IRedisSingleHelperOptions } from './../common';\n\nexport class RedisSingleHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSingleHelperOptions) {\n const { name, host, port, password, database = 0, autoConnect = true, maxRetry = 0 } = opts;\n\n // Optional peer, loaded when a client is built: an app with no Redis installs no ioredis.\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSingleHelper.name,\n identifier: name,\n client: new ioredis.Redis({\n name,\n host,\n port: ParseUtility.toInt({ input: port }),\n password,\n db: database,\n lazyConnect: !autoConnect,\n ...AbstractRedisHelper.buildDefaultOpts({ maxRetry }),\n }),\n });\n }\n\n override getClient() {\n return this.client as Redis;\n }\n}\n"]}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { ILogger } from '../logger/index.js';
|
|
2
2
|
import type { TRedisClient } from './common/index.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
export declare class RedisUtility {
|
|
4
|
+
/** Resolves once the client reaches `ready`; rejects on the first client error or when `timeoutMs` elapses. */
|
|
5
|
+
static waitForReady(opts: {
|
|
6
|
+
client: TRedisClient;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
/** Kicks off connection for clients still parked in `wait` - duplicated clients inherit `lazyConnect` from their parent and never dial on their own. */
|
|
10
|
+
static ensureConnecting(opts: {
|
|
11
|
+
clients: TRedisClient[];
|
|
12
|
+
logger?: ILogger;
|
|
13
|
+
scope: string;
|
|
14
|
+
}): void;
|
|
15
|
+
}
|
|
14
16
|
//# sourceMappingURL=utility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../../../src/modules/redis/utility.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI7C,+GAA+G;
|
|
1
|
+
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../../../src/modules/redis/utility.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI7C,qBAAa,YAAY;IACvB,+GAA+G;IAC/G,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkDtF,wJAAwJ;IACxJ,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;QAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;QACxB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,IAAI;CAWT"}
|
|
@@ -1,51 +1,53 @@
|
|
|
1
1
|
import { HTTP } from '../../common/index.js';
|
|
2
2
|
import { getError } from '../error/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PromiseUtility } from '../../utilities/promise.utility.js';
|
|
4
4
|
const REDIS_READY_TIMEOUT = 30_000;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
cleanup
|
|
5
|
+
export class RedisUtility {
|
|
6
|
+
/** Resolves once the client reaches `ready`; rejects on the first client error or when `timeoutMs` elapses. */
|
|
7
|
+
static waitForReady(opts) {
|
|
8
|
+
const { client, timeoutMs = REDIS_READY_TIMEOUT } = opts;
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
if (client.status === 'ready') {
|
|
11
|
+
resolve();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const emitter = client;
|
|
15
|
+
/** Run by every terminal branch: clients are long-lived and re-`configure()`d, so an unbound listener leaks (EventEmitter warns) and could fire on an already-settled promise. */
|
|
16
|
+
const cleanups = [];
|
|
17
|
+
const detach = () => {
|
|
18
|
+
for (const cleanup of cleanups) {
|
|
19
|
+
cleanup();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const onReady = () => {
|
|
23
|
+
detach();
|
|
24
|
+
resolve();
|
|
25
|
+
};
|
|
26
|
+
const onError = (error) => {
|
|
27
|
+
detach();
|
|
28
|
+
reject(error);
|
|
29
|
+
};
|
|
30
|
+
const timer = setTimeout(() => {
|
|
31
|
+
detach();
|
|
32
|
+
reject(getError({
|
|
33
|
+
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
34
|
+
message: `Redis client did not become ready within ${timeoutMs}ms (status: ${client.status})`,
|
|
35
|
+
}));
|
|
36
|
+
}, timeoutMs);
|
|
37
|
+
cleanups.push(() => clearTimeout(timer), () => emitter.removeListener('ready', onReady), () => emitter.removeListener('error', onError));
|
|
38
|
+
emitter.once('ready', onReady);
|
|
39
|
+
emitter.once('error', onError);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Kicks off connection for clients still parked in `wait` - duplicated clients inherit `lazyConnect` from their parent and never dial on their own. */
|
|
43
|
+
static ensureConnecting(opts) {
|
|
44
|
+
const { clients, logger, scope } = opts;
|
|
45
|
+
for (const client of clients) {
|
|
46
|
+
if (client.status !== 'wait') {
|
|
47
|
+
continue;
|
|
19
48
|
}
|
|
20
|
-
|
|
21
|
-
const onReady = () => {
|
|
22
|
-
detach();
|
|
23
|
-
resolve();
|
|
24
|
-
};
|
|
25
|
-
const onError = (error) => {
|
|
26
|
-
detach();
|
|
27
|
-
reject(error);
|
|
28
|
-
};
|
|
29
|
-
const timer = setTimeout(() => {
|
|
30
|
-
detach();
|
|
31
|
-
reject(getError({
|
|
32
|
-
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
33
|
-
message: `Redis client did not become ready within ${timeoutMs}ms (status: ${client.status})`,
|
|
34
|
-
}));
|
|
35
|
-
}, timeoutMs);
|
|
36
|
-
cleanups.push(() => clearTimeout(timer), () => emitter.removeListener('ready', onReady), () => emitter.removeListener('error', onError));
|
|
37
|
-
emitter.once('ready', onReady);
|
|
38
|
-
emitter.once('error', onError);
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
/** Kicks off connection for clients still parked in `wait` - duplicated clients inherit `lazyConnect` from their parent and never dial on their own. */
|
|
42
|
-
export const ensureRedisClientsConnecting = (opts) => {
|
|
43
|
-
const { clients, logger, scope } = opts;
|
|
44
|
-
for (const client of clients) {
|
|
45
|
-
if (client.status !== 'wait') {
|
|
46
|
-
continue;
|
|
49
|
+
PromiseUtility.voidExecution({ logger, scope, execution: client.connect() });
|
|
47
50
|
}
|
|
48
|
-
voidExecution({ logger, scope, execution: client.connect() });
|
|
49
51
|
}
|
|
50
|
-
}
|
|
52
|
+
}
|
|
51
53
|
//# sourceMappingURL=utility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../src/modules/redis/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../src/modules/redis/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI7D,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEnC,MAAM,OAAO,YAAY;IACvB,+GAA+G;IAC/G,MAAM,CAAC,YAAY,CAAC,IAAkD;QACpE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,m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AE,OAAO,CAAC,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,wJAAwJ;IACxJ,MAAM,CAAC,gBAAgB,CAAC,IAIvB;QACC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAExC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;gBAC7B,SAAS;YACX,CAAC;YAED,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common';\nimport { getError } from '@/modules/error';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { type EventEmitter } from 'node:events';\nimport type { TRedisClient } from './common';\n\nconst REDIS_READY_TIMEOUT = 30_000;\n\nexport class RedisUtility {\n /** Resolves once the client reaches `ready`; rejects on the first client error or when `timeoutMs` elapses. */\n static waitForReady(opts: { client: TRedisClient; timeoutMs?: number }): Promise<void> {\n const { client, timeoutMs = REDIS_READY_TIMEOUT } = opts;\n\n return new Promise<void>((resolve, reject) => {\n if (client.status === 'ready') {\n resolve();\n return;\n }\n\n const emitter = client as EventEmitter;\n\n /** Run by every terminal branch: clients are long-lived and re-`configure()`d, so an unbound listener leaks (EventEmitter warns) and could fire on an already-settled promise. */\n const cleanups: Array<() => void> = [];\n const detach = () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n };\n\n const onReady = () => {\n detach();\n resolve();\n };\n\n const onError = (error: Error) => {\n detach();\n reject(error);\n };\n\n const timer = setTimeout(() => {\n detach();\n reject(\n getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `Redis client did not become ready within ${timeoutMs}ms (status: ${client.status})`,\n }),\n );\n }, timeoutMs);\n\n cleanups.push(\n () => clearTimeout(timer),\n () => emitter.removeListener('ready', onReady),\n () => emitter.removeListener('error', onError),\n );\n\n emitter.once('ready', onReady);\n emitter.once('error', onError);\n });\n }\n\n /** Kicks off connection for clients still parked in `wait` - duplicated clients inherit `lazyConnect` from their parent and never dial on their own. */\n static ensureConnecting(opts: {\n clients: TRedisClient[];\n logger?: ILogger;\n scope: string;\n }): void {\n const { clients, logger, scope } = opts;\n\n for (const client of clients) {\n if (client.status !== 'wait') {\n continue;\n }\n\n PromiseUtility.voidExecution({ logger, scope, execution: client.connect() });\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../src/modules/retry/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM5C;;;GAGG;AACH,qBAAa,WAAY,SAAQ,UAAU;IACzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAsD;IAElG,gGAAgG;IAChG,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAInD,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC,OAAO,CAAC,MAAM,CAAC,cAAc;IAQ7B,+EAA+E;mBAC1D,eAAe;IAsCpC,yMAAyM;WAC5L,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE;QACnC,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,cAAc,CAAC,CAAC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
import {
|
|
2
|
+
import { PromiseUtility } from '../../utilities/promise.utility.js';
|
|
3
3
|
import { RetryBackoffStrategies, RetryJitterModes } from './common/constants.js';
|
|
4
4
|
import { BaseHelper } from '../base.js';
|
|
5
5
|
/**
|
|
@@ -30,7 +30,7 @@ export class RetryHelper extends BaseHelper {
|
|
|
30
30
|
static async sleepWithSignal(opts) {
|
|
31
31
|
const { ms, operation, signal } = opts;
|
|
32
32
|
if (!signal) {
|
|
33
|
-
await sleep(ms);
|
|
33
|
+
await PromiseUtility.sleep({ ms });
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
RetryHelper.throwIfAborted({ operation, signal });
|
|
@@ -66,7 +66,8 @@ export class RetryHelper extends BaseHelper {
|
|
|
66
66
|
}, timeoutMs);
|
|
67
67
|
});
|
|
68
68
|
try {
|
|
69
|
-
|
|
69
|
+
const result = await Promise.race([Promise.resolve().then(execution), timeoutPromise]);
|
|
70
|
+
return result;
|
|
70
71
|
}
|
|
71
72
|
finally {
|
|
72
73
|
clearTimeout(timer);
|
|
@@ -230,7 +231,8 @@ export class RetryHelper extends BaseHelper {
|
|
|
230
231
|
let lastResult;
|
|
231
232
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
232
233
|
RetryHelper.throwIfAborted({ operation, signal });
|
|
233
|
-
|
|
234
|
+
const result2 = await execution({ attempt, signal });
|
|
235
|
+
lastResult = result2;
|
|
234
236
|
if (until(lastResult)) {
|
|
235
237
|
return lastResult;
|
|
236
238
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/modules/retry/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE9E,OAAO,EAAE,UAAU,E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AAE,CAAC,CAAC;YAC5E,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;gBACpB,MAAM,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;YAC5E,CAAC;QACH,CAAC;QAED,MAAM;YACJ,EAAE,GAAG,CAAC,uBAAuB,CAAC;aAC7B,IAAI,CAAC,wDAAwD,EAAE,SAAS,CAAC,CAAC;QAC7E,OAAO,UAAe,CAAC;IACzB,CAAC","sourcesContent":["import type { ValueOrPromise } from '@/common';\nimport { getError } from '@/modules/error';\nimport type { ILogger } from '@/modules/logger';\nimport { sleep } from '@/utilities/sleep.utility';\nimport { RetryBackoffStrategies, RetryJitterModes } from './common/constants';\nimport type { IRetryBackoffOptions, IRetryContext } from './common/types';\nimport { BaseHelper } from '@/modules/base';\n\ntype TRetryAttemptOutcome<T> =\n | { isResolved: true; value: T }\n | { isResolved: false; error: unknown; isRetryAllowed: boolean };\n\n/**\n * Static members call each other through the class name (`RetryHelper.xxx`), never `this` - a\n * detached static method loses its `this` binding.\n */\nexport class RetryHelper extends BaseHelper {\n private static readonly RETRY_TIMEOUT_MARKER = Symbol.for('@venizia/ignis-helpers:retry-timeout');\n\n /** True when `error` is a per-attempt timeout raised by `runWithTimeout`/`executeWithRetry`. */\n static isRetryTimeoutError(error: unknown): boolean {\n return typeof error === 'object' && error !== null && RetryHelper.RETRY_TIMEOUT_MARKER in error;\n }\n\n private static buildTimeoutError(opts: { operation: string; timeoutMs: number }) {\n const error = getError({\n message: `[runWithTimeout][${opts.operation}] Timed out after ${opts.timeoutMs}ms`,\n });\n Object.defineProperty(error, RetryHelper.RETRY_TIMEOUT_MARKER, { value: true });\n return error;\n }\n\n private static throwIfAborted(opts: { operation: string; signal?: AbortSignal }) {\n if (opts.signal?.aborted) {\n throw getError({\n message: `[executeWithRetry][${opts.operation}] Aborted | Reason: ${String(opts.signal.reason ?? 'unknown')}`,\n });\n }\n }\n\n /** `sleep` that wakes up early (and rejects) when `signal` aborts mid-wait. */\n private static async sleepWithSignal(opts: {\n ms: number;\n operation: string;\n signal?: AbortSignal;\n }) {\n const { ms, operation, signal } = opts;\n\n if (!signal) {\n await sleep(ms);\n return;\n }\n\n RetryHelper.throwIfAborted({ operation, signal });\n\n // The listener is removed in `finally` rather than by the timer callback - the two would otherwise have to reference each other, and a leaked listener on a long-lived signal accumulates across retries.\n let removeAbortListener = () => {};\n\n try {\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(resolve, ms);\n\n const onAbort = () => {\n clearTimeout(timer);\n reject(\n getError({\n message: `[executeWithRetry][${operation}] Aborted during backoff | Reason: ${String(signal.reason ?? 'unknown')}`,\n }),\n );\n };\n\n removeAbortListener = () => signal.removeEventListener('abort', onAbort);\n signal.addEventListener('abort', onAbort, { once: true });\n });\n } finally {\n removeAbortListener();\n }\n }\n\n /** Races `execution` against `timeoutMs` (`<= 0`/omitted = no timeout). The losing execution keeps running - JS promises cannot be cancelled - so pass `signal` through for cooperative cancellation. */\n static async runWithTimeout<T>(opts: {\n operation: string;\n timeoutMs?: number;\n execution: () => ValueOrPromise<T>;\n }): Promise<T> {\n const { operation, timeoutMs, execution } = opts;\n\n if (!timeoutMs || timeoutMs <= 0) {\n return execution();\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeoutPromise = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n reject(RetryHelper.buildTimeoutError({ operation, timeoutMs }));\n }, timeoutMs);\n });\n\n try {\n return await Promise.race([Promise.resolve().then(execution), timeoutPromise]);\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** The pre-jitter delay for `attempt` (1-based, i.e. the delay AFTER attempt N failed). */\n static computeBackoffDelayMs(opts: { attempt: number; backoff?: IRetryBackoffOptions }): number {\n const { attempt } = opts;\n const {\n strategy = RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs = 250,\n multiplier = 2,\n maxDelayMs = 30_000,\n scheduleMs,\n jitter = RetryJitterModes.FULL,\n } = opts.backoff ?? {};\n\n let delayMs: number;\n switch (strategy) {\n case RetryBackoffStrategies.FIXED: {\n delayMs = initialDelayMs;\n break;\n }\n case RetryBackoffStrategies.LINEAR: {\n delayMs = initialDelayMs * attempt;\n break;\n }\n case RetryBackoffStrategies.EXPONENTIAL: {\n delayMs = initialDelayMs * Math.pow(multiplier, attempt - 1);\n break;\n }\n case RetryBackoffStrategies.SCHEDULE: {\n if (!scheduleMs?.length) {\n throw getError({\n message:\n '[computeBackoffDelayMs] strategy SCHEDULE requires a non-empty backoff.scheduleMs',\n });\n }\n delayMs = scheduleMs[Math.min(attempt - 1, scheduleMs.length - 1)];\n break;\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown backoff strategy '${strategy}' | Expected one of: ${[...RetryBackoffStrategies.SCHEME_SET].join(', ')}`,\n });\n }\n }\n\n delayMs = Math.min(delayMs, maxDelayMs);\n\n if (delayMs <= 0) {\n return 0;\n }\n\n switch (jitter) {\n case RetryJitterModes.NONE: {\n return delayMs;\n }\n case RetryJitterModes.FULL: {\n return Math.floor(Math.random() * delayMs);\n }\n case RetryJitterModes.EQUAL: {\n const half = delayMs / 2;\n return Math.floor(half + Math.random() * half);\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown jitter mode '${jitter}' | Expected one of: ${[...RetryJitterModes.SCHEME_SET].join(', ')}`,\n });\n }\n }\n }\n\n /** One `executeWithRetry` attempt and everything that follows a failure: `shouldRetry` refusing rethrows, otherwise the bounds are checked and - when another attempt is allowed - the retry is logged, `onRetry` awaited and the backoff slept, all before returning. */\n private static async runRetryAttempt<T>(opts: {\n attempt: number;\n attemptTimeoutMs?: number;\n startedAt: number;\n deadline?: number;\n maxAttempts: number;\n operation: string;\n signal?: AbortSignal;\n logger?: ILogger;\n backoff?: IRetryBackoffOptions;\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n shouldRetry?: (context: IRetryContext) => boolean;\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<TRetryAttemptOutcome<T>> {\n const {\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n } = opts;\n\n try {\n const value = await RetryHelper.runWithTimeout({\n operation,\n timeoutMs: attemptTimeoutMs,\n execution: () => execution({ attempt, signal }),\n });\n return { isResolved: true, value };\n } catch (error) {\n const elapsedMs = Date.now() - startedAt;\n\n if (shouldRetry && !shouldRetry({ attempt, error, elapsedMs })) {\n throw error;\n }\n\n if (attempt >= maxAttempts) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n if (deadline && Date.now() + nextDelayMs >= deadline) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n logger\n ?.for('executeWithRetry')\n .debug(\n '[%s] Attempt %d/%d failed - retrying in %dms | Error: %s',\n operation,\n attempt,\n maxAttempts,\n nextDelayMs,\n error,\n );\n\n await onRetry?.({ attempt, error, elapsedMs, nextDelayMs });\n\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n\n return { isResolved: false, error, isRetryAllowed: true };\n }\n }\n\n /** Retries `execution` with backoff, bounded by `maxAttempts`/`maxTotalMs`. JS cannot cancel a running promise - `signal` only stops between attempts/sleeps, so a timed-out execution keeps running unless it honors the signal itself. */\n static async executeWithRetry<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** Default 3. */\n maxAttempts?: number;\n\n /** Total budget across attempts AND sleeps. Default: unlimited. */\n maxTotalMs?: number;\n\n /** Per-attempt race. Default: no per-attempt timeout. */\n perAttemptTimeoutMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Return `false` to stop retrying and rethrow `context.error` immediately. */\n shouldRetry?: (context: IRetryContext) => boolean;\n\n /** Observability hook, awaited before the backoff sleep. */\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<T> {\n const {\n operation,\n execution,\n maxAttempts = 3,\n maxTotalMs,\n perAttemptTimeoutMs,\n backoff,\n shouldRetry,\n onRetry,\n signal,\n logger,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetry][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n const startedAt = Date.now();\n // `!== undefined`, never truthiness: a budget of 0 - or a negative one, which is what `deadline - Date.now()` yields under load - means NO time left, not unlimited time.\n const deadline = maxTotalMs !== undefined ? startedAt + maxTotalMs : undefined;\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n const remainingMs = deadline ? deadline - Date.now() : undefined;\n if (remainingMs !== undefined && remainingMs <= 0) {\n break;\n }\n\n let attemptTimeoutMs = perAttemptTimeoutMs;\n if (remainingMs !== undefined) {\n attemptTimeoutMs = attemptTimeoutMs ? Math.min(attemptTimeoutMs, remainingMs) : remainingMs;\n }\n\n const outcome = await RetryHelper.runRetryAttempt({\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n });\n\n if (outcome.isResolved) {\n return outcome.value;\n }\n\n lastError = outcome.error;\n if (!outcome.isRetryAllowed) {\n break;\n }\n }\n\n const elapsedMs = Date.now() - startedAt;\n\n // The budget can run out BEFORE the first attempt (an expired `maxTotalMs`), leaving no error to rethrow; `throw undefined` would detonate inside the caller's own handler on `error.message`.\n if (lastError === undefined) {\n throw getError({\n message: `[executeWithRetry][${operation}] Time budget exhausted before any attempt ran | maxTotalMs: ${maxTotalMs}`,\n });\n }\n\n logger\n ?.for('executeWithRetry')\n .warn('[%s] Exhausted retries | Elapsed: %dms | Error: %s', operation, elapsedMs, lastError);\n\n throw lastError;\n }\n\n /** Retries `execution` while `until(result)` returns false - for read-after-write staleness behind a replicated pool. Never worse than a single un-retried call: on exhaustion the LAST result is returned rather than an error, and a thrown error propagates immediately instead of being retried. Only wrap idempotent operations. */\n static async executeWithRetryUntil<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** Default 3. */\n maxAttempts?: number;\n\n /** Bounds when a NEW attempt may start; it never interrupts an attempt already in flight, so the first execution always runs to completion - a budget of 0 just means \"no retries\". */\n maxTotalMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Retry while this returns false. */\n until: (result: T) => boolean;\n }): Promise<T> {\n const {\n signal,\n logger,\n operation,\n maxAttempts = 3,\n maxTotalMs,\n backoff,\n execution,\n until,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetryUntil][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n // Surfaced before the first execution - a misconfigured backoff discovered mid-loop would discard an already-fetched result.\n RetryHelper.computeBackoffDelayMs({ attempt: 1, backoff });\n\n const startedAt = Date.now();\n let lastResult: T | undefined;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n lastResult = await execution({ attempt, signal });\n if (until(lastResult)) {\n return lastResult;\n }\n\n const elapsedMs = Date.now() - startedAt;\n if (attempt >= maxAttempts || (maxTotalMs !== undefined && elapsedMs >= maxTotalMs)) {\n break;\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .debug('[%s] until condition not met | Attempt: %d', operation, attempt);\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .warn('[%s] Exhausted retries - returning last (stale) result', operation);\n return lastResult as T;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/modules/retry/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM5C;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU;aACjB,yBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAElG,gGAAgG;IAChG,MAAM,CAAC,mBAAmB,CAAC,KAAc;QACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,WAAW,CAAC,oBAAoB,IAAI,KAAK,CAAC;IAClG,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAAC,IAA8C;QAC7E,MAAM,KAAK,GAAG,QAAQ,CAAC;YACrB,OAAO,EAAE,oBAAoB,IAAI,CAAC,SAAS,qBAAqB,IAAI,CAAC,SAAS,IAAI;SACnF,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAChF,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,IAAiD;QAC7E,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YACzB,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,sBAAsB,IAAI,CAAC,SAAS,uBAAuB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,SAAS,CAAC,EAAE;aAC9G,CAAC,CAAC;Q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,CAAC,EAAE,CAAC;gBACtB,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YACzC,IAAI,OAAO,IAAI,WAAW,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,SAAS,IAAI,UAAU,CAAC,EAAE,CAAC;gBACpF,MAAM;YACR,CAAC;YAED,MAAM;gBACJ,EAAE,GAAG,CAAC,uBAAuB,CAAC;iBAC7B,KAAK,CAAC,4CAA4C,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAE3E,MAAM,WAAW,GAAG,WAAW,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5E,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;gBACpB,MAAM,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;YAC5E,CAAC;QACH,CAAC;QAED,MAAM;YACJ,EAAE,GAAG,CAAC,uBAAuB,CAAC;aAC7B,IAAI,CAAC,wDAAwD,EAAE,SAAS,CAAC,CAAC;QAC7E,OAAO,UAAe,CAAC;IACzB,CAAC","sourcesContent":["import type { ValueOrPromise } from '@/common';\nimport { getError } from '@/modules/error';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { RetryBackoffStrategies, RetryJitterModes } from './common/constants';\nimport type { IRetryBackoffOptions, IRetryContext } from './common/types';\nimport { BaseHelper } from '@/modules/base';\n\ntype TRetryAttemptOutcome<T> =\n | { isResolved: true; value: T }\n | { isResolved: false; error: unknown; isRetryAllowed: boolean };\n\n/**\n * Static members call each other through the class name (`RetryHelper.xxx`), never `this` - a\n * detached static method loses its `this` binding.\n */\nexport class RetryHelper extends BaseHelper {\n private static readonly RETRY_TIMEOUT_MARKER = Symbol.for('@venizia/ignis-helpers:retry-timeout');\n\n /** True when `error` is a per-attempt timeout raised by `runWithTimeout`/`executeWithRetry`. */\n static isRetryTimeoutError(error: unknown): boolean {\n return typeof error === 'object' && error !== null && RetryHelper.RETRY_TIMEOUT_MARKER in error;\n }\n\n private static buildTimeoutError(opts: { operation: string; timeoutMs: number }) {\n const error = getError({\n message: `[runWithTimeout][${opts.operation}] Timed out after ${opts.timeoutMs}ms`,\n });\n Object.defineProperty(error, RetryHelper.RETRY_TIMEOUT_MARKER, { value: true });\n return error;\n }\n\n private static throwIfAborted(opts: { operation: string; signal?: AbortSignal }) {\n if (opts.signal?.aborted) {\n throw getError({\n message: `[executeWithRetry][${opts.operation}] Aborted | Reason: ${String(opts.signal.reason ?? 'unknown')}`,\n });\n }\n }\n\n /** `sleep` that wakes up early (and rejects) when `signal` aborts mid-wait. */\n private static async sleepWithSignal(opts: {\n ms: number;\n operation: string;\n signal?: AbortSignal;\n }) {\n const { ms, operation, signal } = opts;\n\n if (!signal) {\n await PromiseUtility.sleep({ ms });\n return;\n }\n\n RetryHelper.throwIfAborted({ operation, signal });\n\n // The listener is removed in `finally` rather than by the timer callback - the two would otherwise have to reference each other, and a leaked listener on a long-lived signal accumulates across retries.\n let removeAbortListener = () => {};\n\n try {\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(resolve, ms);\n\n const onAbort = () => {\n clearTimeout(timer);\n reject(\n getError({\n message: `[executeWithRetry][${operation}] Aborted during backoff | Reason: ${String(signal.reason ?? 'unknown')}`,\n }),\n );\n };\n\n removeAbortListener = () => signal.removeEventListener('abort', onAbort);\n signal.addEventListener('abort', onAbort, { once: true });\n });\n } finally {\n removeAbortListener();\n }\n }\n\n /** Races `execution` against `timeoutMs` (`<= 0`/omitted = no timeout). The losing execution keeps running - JS promises cannot be cancelled - so pass `signal` through for cooperative cancellation. */\n static async runWithTimeout<T>(opts: {\n operation: string;\n timeoutMs?: number;\n execution: () => ValueOrPromise<T>;\n }): Promise<T> {\n const { operation, timeoutMs, execution } = opts;\n\n if (!timeoutMs || timeoutMs <= 0) {\n return execution();\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeoutPromise = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n reject(RetryHelper.buildTimeoutError({ operation, timeoutMs }));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([Promise.resolve().then(execution), timeoutPromise]);\n return result;\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** The pre-jitter delay for `attempt` (1-based, i.e. the delay AFTER attempt N failed). */\n static computeBackoffDelayMs(opts: { attempt: number; backoff?: IRetryBackoffOptions }): number {\n const { attempt } = opts;\n const {\n strategy = RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs = 250,\n multiplier = 2,\n maxDelayMs = 30_000,\n scheduleMs,\n jitter = RetryJitterModes.FULL,\n } = opts.backoff ?? {};\n\n let delayMs: number;\n switch (strategy) {\n case RetryBackoffStrategies.FIXED: {\n delayMs = initialDelayMs;\n break;\n }\n case RetryBackoffStrategies.LINEAR: {\n delayMs = initialDelayMs * attempt;\n break;\n }\n case RetryBackoffStrategies.EXPONENTIAL: {\n delayMs = initialDelayMs * Math.pow(multiplier, attempt - 1);\n break;\n }\n case RetryBackoffStrategies.SCHEDULE: {\n if (!scheduleMs?.length) {\n throw getError({\n message:\n '[computeBackoffDelayMs] strategy SCHEDULE requires a non-empty backoff.scheduleMs',\n });\n }\n delayMs = scheduleMs[Math.min(attempt - 1, scheduleMs.length - 1)];\n break;\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown backoff strategy '${strategy}' | Expected one of: ${[...RetryBackoffStrategies.SCHEME_SET].join(', ')}`,\n });\n }\n }\n\n delayMs = Math.min(delayMs, maxDelayMs);\n\n if (delayMs <= 0) {\n return 0;\n }\n\n switch (jitter) {\n case RetryJitterModes.NONE: {\n return delayMs;\n }\n case RetryJitterModes.FULL: {\n return Math.floor(Math.random() * delayMs);\n }\n case RetryJitterModes.EQUAL: {\n const half = delayMs / 2;\n return Math.floor(half + Math.random() * half);\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown jitter mode '${jitter}' | Expected one of: ${[...RetryJitterModes.SCHEME_SET].join(', ')}`,\n });\n }\n }\n }\n\n /** One `executeWithRetry` attempt and everything that follows a failure: `shouldRetry` refusing rethrows, otherwise the bounds are checked and - when another attempt is allowed - the retry is logged, `onRetry` awaited and the backoff slept, all before returning. */\n private static async runRetryAttempt<T>(opts: {\n attempt: number;\n attemptTimeoutMs?: number;\n startedAt: number;\n deadline?: number;\n maxAttempts: number;\n operation: string;\n signal?: AbortSignal;\n logger?: ILogger;\n backoff?: IRetryBackoffOptions;\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n shouldRetry?: (context: IRetryContext) => boolean;\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<TRetryAttemptOutcome<T>> {\n const {\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n } = opts;\n\n try {\n const value = await RetryHelper.runWithTimeout({\n operation,\n timeoutMs: attemptTimeoutMs,\n execution: () => execution({ attempt, signal }),\n });\n return { isResolved: true, value };\n } catch (error) {\n const elapsedMs = Date.now() - startedAt;\n\n if (shouldRetry && !shouldRetry({ attempt, error, elapsedMs })) {\n throw error;\n }\n\n if (attempt >= maxAttempts) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n if (deadline && Date.now() + nextDelayMs >= deadline) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n logger\n ?.for('executeWithRetry')\n .debug(\n '[%s] Attempt %d/%d failed - retrying in %dms | Error: %s',\n operation,\n attempt,\n maxAttempts,\n nextDelayMs,\n error,\n );\n\n await onRetry?.({ attempt, error, elapsedMs, nextDelayMs });\n\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n\n return { isResolved: false, error, isRetryAllowed: true };\n }\n }\n\n /** Retries `execution` with backoff, bounded by `maxAttempts`/`maxTotalMs`. JS cannot cancel a running promise - `signal` only stops between attempts/sleeps, so a timed-out execution keeps running unless it honors the signal itself. */\n static async executeWithRetry<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** Default 3. */\n maxAttempts?: number;\n\n /** Total budget across attempts AND sleeps. Default: unlimited. */\n maxTotalMs?: number;\n\n /** Per-attempt race. Default: no per-attempt timeout. */\n perAttemptTimeoutMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Return `false` to stop retrying and rethrow `context.error` immediately. */\n shouldRetry?: (context: IRetryContext) => boolean;\n\n /** Observability hook, awaited before the backoff sleep. */\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<T> {\n const {\n operation,\n execution,\n maxAttempts = 3,\n maxTotalMs,\n perAttemptTimeoutMs,\n backoff,\n shouldRetry,\n onRetry,\n signal,\n logger,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetry][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n const startedAt = Date.now();\n // `!== undefined`, never truthiness: a budget of 0 - or a negative one, which is what `deadline - Date.now()` yields under load - means NO time left, not unlimited time.\n const deadline = maxTotalMs !== undefined ? startedAt + maxTotalMs : undefined;\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n const remainingMs = deadline ? deadline - Date.now() : undefined;\n if (remainingMs !== undefined && remainingMs <= 0) {\n break;\n }\n\n let attemptTimeoutMs = perAttemptTimeoutMs;\n if (remainingMs !== undefined) {\n attemptTimeoutMs = attemptTimeoutMs ? Math.min(attemptTimeoutMs, remainingMs) : remainingMs;\n }\n\n const outcome = await RetryHelper.runRetryAttempt({\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n });\n\n if (outcome.isResolved) {\n return outcome.value;\n }\n\n lastError = outcome.error;\n if (!outcome.isRetryAllowed) {\n break;\n }\n }\n\n const elapsedMs = Date.now() - startedAt;\n\n // The budget can run out BEFORE the first attempt (an expired `maxTotalMs`), leaving no error to rethrow; `throw undefined` would detonate inside the caller's own handler on `error.message`.\n if (lastError === undefined) {\n throw getError({\n message: `[executeWithRetry][${operation}] Time budget exhausted before any attempt ran | maxTotalMs: ${maxTotalMs}`,\n });\n }\n\n logger\n ?.for('executeWithRetry')\n .warn('[%s] Exhausted retries | Elapsed: %dms | Error: %s', operation, elapsedMs, lastError);\n\n throw lastError;\n }\n\n /** Retries `execution` while `until(result)` returns false - for read-after-write staleness behind a replicated pool. Never worse than a single un-retried call: on exhaustion the LAST result is returned rather than an error, and a thrown error propagates immediately instead of being retried. Only wrap idempotent operations. */\n static async executeWithRetryUntil<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** Default 3. */\n maxAttempts?: number;\n\n /** Bounds when a NEW attempt may start; it never interrupts an attempt already in flight, so the first execution always runs to completion - a budget of 0 just means \"no retries\". */\n maxTotalMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Retry while this returns false. */\n until: (result: T) => boolean;\n }): Promise<T> {\n const {\n signal,\n logger,\n operation,\n maxAttempts = 3,\n maxTotalMs,\n backoff,\n execution,\n until,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetryUntil][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n // Surfaced before the first execution - a misconfigured backoff discovered mid-loop would discard an already-fetched result.\n RetryHelper.computeBackoffDelayMs({ attempt: 1, backoff });\n\n const startedAt = Date.now();\n let lastResult: T | undefined;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n const result2 = await execution({ attempt, signal });\n lastResult = result2;\n if (until(lastResult)) {\n return lastResult;\n }\n\n const elapsedMs = Date.now() - startedAt;\n if (attempt >= maxAttempts || (maxTotalMs !== undefined && elapsedMs >= maxTotalMs)) {\n break;\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .debug('[%s] until condition not met | Attempt: %d', operation, attempt);\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .warn('[%s] Exhausted retries - returning last (stale) result', operation);\n return lastResult as T;\n }\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ISecretsHelper, type ISecretsRegistration } from './common/index.js';
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare class SecretsHelperFactory {
|
|
3
|
+
static create(opts: ISecretsRegistration & {
|
|
4
|
+
identifier?: string;
|
|
5
|
+
}): Promise<ISecretsHelper>;
|
|
6
|
+
}
|
|
5
7
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/modules/secrets/factory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAO3F,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/modules/secrets/factory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAO3F,qBAAa,oBAAoB;WAClB,MAAM,CACjB,IAAI,EAAE,oBAAoB,GAAG;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GACnD,OAAO,CAAC,cAAc,CAAC;CA0C3B"}
|
|
@@ -6,43 +6,45 @@ import { HashiCorpVaultHelper } from './hashicorp/index.js';
|
|
|
6
6
|
import { SystemEnvsHelper } from './system-envs/index.js';
|
|
7
7
|
// node-vault / @dotenvx/dotenvx are optional peers reached only via `ModuleUtility.load`: never eagerly loaded, invisible to bundlers. Compiled apps that use a provider must ship the peer in node_modules, inject the client via options, or register it with `ModuleUtility.register`.
|
|
8
8
|
// The providers are imported statically on purpose: a dynamic `import('./x')` of our own module makes bun wrap every module it reaches in a lazy initializer, and the root barrel then exports `undefined` for them.
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
case SecretProviders.HASHICORP_VAULT: {
|
|
21
|
-
// `client` is the injected escape: the helper never reaches for the peer, so demanding it here would defeat the escape.
|
|
22
|
-
if (!config?.client) {
|
|
23
|
-
ModuleUtility.assertInstalled({
|
|
24
|
-
scope: 'HashiCorpVaultHelper',
|
|
25
|
-
modules: ['node-vault'],
|
|
26
|
-
allowRegistered: true,
|
|
27
|
-
});
|
|
9
|
+
export class SecretsHelperFactory {
|
|
10
|
+
static async create(opts) {
|
|
11
|
+
const shared = {
|
|
12
|
+
identifier: opts.identifier,
|
|
13
|
+
cacheTtlSeconds: opts.cacheTtlSeconds,
|
|
14
|
+
renewBeforeRatio: opts.renewBeforeRatio,
|
|
15
|
+
};
|
|
16
|
+
const config = opts.config;
|
|
17
|
+
switch (opts.provider) {
|
|
18
|
+
case SecretProviders.SYSTEM_ENVS: {
|
|
19
|
+
return new SystemEnvsHelper({ identifier: opts.identifier });
|
|
28
20
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
case SecretProviders.HASHICORP_VAULT: {
|
|
22
|
+
// `client` is the injected escape: the helper never reaches for the peer, so demanding it here would defeat the escape.
|
|
23
|
+
if (!config?.client) {
|
|
24
|
+
ModuleUtility.assertInstalled({
|
|
25
|
+
scope: 'HashiCorpVaultHelper',
|
|
26
|
+
modules: ['node-vault'],
|
|
27
|
+
allowRegistered: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return new HashiCorpVaultHelper({ ...config, ...shared });
|
|
31
|
+
}
|
|
32
|
+
case SecretProviders.DOTENV_VAULT: {
|
|
33
|
+
// `decode` is the injected escape - same reasoning as `client` above.
|
|
34
|
+
if (!config?.decode) {
|
|
35
|
+
ModuleUtility.assertInstalled({
|
|
36
|
+
scope: 'DotenvVaultHelper',
|
|
37
|
+
modules: ['@dotenvx/dotenvx'],
|
|
38
|
+
allowRegistered: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return new DotenvVaultHelper({ ...config, ...shared });
|
|
42
|
+
}
|
|
43
|
+
default: {
|
|
44
|
+
throw getError({
|
|
45
|
+
message: `[createSecretsHelper] Unsupported secret provider: ${opts.provider}`,
|
|
38
46
|
});
|
|
39
47
|
}
|
|
40
|
-
return new DotenvVaultHelper({ ...config, ...shared });
|
|
41
|
-
}
|
|
42
|
-
default: {
|
|
43
|
-
throw getError({
|
|
44
|
-
message: `[createSecretsHelper] Unsupported secret provider: ${opts.provider}`,
|
|
45
|
-
});
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
}
|