@venizia/ignis-helpers 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/constants/duration.d.ts +4 -1
- package/dist/cjs/common/constants/duration.d.ts.map +1 -1
- package/dist/cjs/common/constants/duration.js +13 -8
- package/dist/cjs/common/constants/duration.js.map +1 -1
- package/dist/cjs/common/redact.js +1 -1
- package/dist/cjs/common/redact.js.map +1 -1
- package/dist/cjs/modules/base.js +1 -1
- package/dist/cjs/modules/base.js.map +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/cjs/modules/env/app-env.d.ts.map +1 -1
- package/dist/cjs/modules/env/app-env.js +1 -1
- package/dist/cjs/modules/env/app-env.js.map +1 -1
- package/dist/cjs/modules/logger/common/constants.js +1 -1
- package/dist/cjs/modules/logger/common/constants.js.map +1 -1
- package/dist/cjs/modules/logger/factory.js +1 -1
- package/dist/cjs/modules/logger/factory.js.map +1 -1
- package/dist/cjs/modules/logger/formatting/deep-splat.js +1 -1
- package/dist/cjs/modules/logger/formatting/deep-splat.js.map +1 -1
- package/dist/cjs/modules/logger/formatting/error-prettier.js +4 -4
- package/dist/cjs/modules/logger/formatting/error-prettier.js.map +1 -1
- package/dist/cjs/modules/logger/hf/flusher.js +3 -3
- package/dist/cjs/modules/logger/hf/flusher.js.map +1 -1
- package/dist/cjs/modules/logger/hf/logger.d.ts.map +1 -1
- package/dist/cjs/modules/logger/hf/logger.js +3 -1
- package/dist/cjs/modules/logger/hf/logger.js.map +1 -1
- package/dist/cjs/modules/logger/resolver.js +3 -3
- package/dist/cjs/modules/logger/resolver.js.map +1 -1
- package/dist/cjs/modules/logger/winston/formatters/deep-splat.js +1 -1
- package/dist/cjs/modules/logger/winston/formatters/deep-splat.js.map +1 -1
- package/dist/cjs/modules/logger/winston/logger-factory.js +1 -1
- package/dist/cjs/modules/logger/winston/logger-factory.js.map +1 -1
- package/dist/cjs/modules/logger/winston/transports/dgram.transport.js +2 -2
- package/dist/cjs/modules/logger/winston/transports/dgram.transport.js.map +1 -1
- package/dist/cjs/modules/network/http-request/fetcher/axios-fetcher.js +1 -1
- package/dist/cjs/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
- package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.d.ts +17 -14
- package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.d.ts.map +1 -1
- package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.js +3 -0
- package/dist/cjs/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
- package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.d.ts +13 -4
- package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
- package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.js +34 -11
- package/dist/cjs/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-client.helper.js +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js +7 -6
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/cjs/modules/network/udp-socket/network-udp-client.helper.js +1 -1
- package/dist/cjs/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
- package/dist/cjs/modules/network/utilities/query-string.d.ts +27 -2
- package/dist/cjs/modules/network/utilities/query-string.d.ts.map +1 -1
- package/dist/cjs/modules/network/utilities/query-string.js +34 -2
- package/dist/cjs/modules/network/utilities/query-string.js.map +1 -1
- package/dist/cjs/modules/network/utilities/url-safety/ingest.js +1 -1
- package/dist/cjs/modules/network/utilities/url-safety/ingest.js.map +1 -1
- package/dist/cjs/modules/network/utilities/url-safety/policy.js +1 -1
- package/dist/cjs/modules/network/utilities/url-safety/policy.js.map +1 -1
- package/dist/cjs/modules/pool/abstract.js +4 -4
- package/dist/cjs/modules/pool/abstract.js.map +1 -1
- package/dist/cjs/modules/queue/bullmq/helper.js +2 -2
- package/dist/cjs/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/cjs/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +1 -1
- package/dist/cjs/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +1 -1
- package/dist/cjs/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +1 -1
- package/dist/cjs/modules/queue/kafka/consumer.js +2 -2
- package/dist/cjs/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/cjs/modules/queue/mqtt/helper.js +4 -4
- package/dist/cjs/modules/queue/mqtt/helper.js.map +1 -1
- package/dist/cjs/modules/redis/base/abstract.helper.js +4 -4
- package/dist/cjs/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/cjs/modules/redis/cluster/cluster.helper.js +1 -1
- package/dist/cjs/modules/redis/cluster/cluster.helper.js.map +1 -1
- package/dist/cjs/modules/redis/sentinel/sentinel.helper.js +1 -1
- package/dist/cjs/modules/redis/sentinel/sentinel.helper.js.map +1 -1
- package/dist/cjs/modules/secrets/base/abstract.helper.d.ts.map +1 -1
- package/dist/cjs/modules/secrets/base/abstract.helper.js +7 -3
- package/dist/cjs/modules/secrets/base/abstract.helper.js.map +1 -1
- package/dist/cjs/modules/secrets/hashicorp/hashicorp.helper.js +2 -2
- package/dist/cjs/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
- package/dist/cjs/modules/socket/socket-io/browser.d.ts +5 -0
- package/dist/cjs/modules/socket/socket-io/browser.d.ts.map +1 -0
- package/dist/cjs/modules/socket/socket-io/browser.js +21 -0
- package/dist/cjs/modules/socket/socket-io/browser.js.map +1 -0
- package/dist/cjs/modules/socket/socket-io/client/browser-helper.d.ts +61 -0
- package/dist/cjs/modules/socket/socket-io/client/browser-helper.d.ts.map +1 -0
- package/dist/cjs/modules/socket/socket-io/client/browser-helper.js +250 -0
- package/dist/cjs/modules/socket/socket-io/client/browser-helper.js.map +1 -0
- package/dist/cjs/modules/socket/socket-io/client/helper.d.ts +8 -51
- package/dist/cjs/modules/socket/socket-io/client/helper.d.ts.map +1 -1
- package/dist/cjs/modules/socket/socket-io/client/helper.js +12 -230
- package/dist/cjs/modules/socket/socket-io/client/helper.js.map +1 -1
- package/dist/cjs/modules/socket/socket-io/server/helper.js +5 -5
- package/dist/cjs/modules/socket/socket-io/server/helper.js.map +1 -1
- package/dist/cjs/modules/socket/websocket/server/delivery.js +2 -2
- package/dist/cjs/modules/socket/websocket/server/delivery.js.map +1 -1
- package/dist/cjs/modules/socket/websocket/server/helper.js +4 -4
- package/dist/cjs/modules/socket/websocket/server/helper.js.map +1 -1
- package/dist/cjs/modules/storage/base.js +3 -3
- package/dist/cjs/modules/storage/base.js.map +1 -1
- package/dist/cjs/modules/storage/bun-s3/helper.js +1 -1
- package/dist/cjs/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/cjs/modules/storage/bun-s3/utility.js +6 -6
- package/dist/cjs/modules/storage/bun-s3/utility.js.map +1 -1
- package/dist/cjs/modules/storage/common/errors.js +1 -1
- package/dist/cjs/modules/storage/common/errors.js.map +1 -1
- package/dist/cjs/modules/storage/minio/helper.js +4 -4
- package/dist/cjs/modules/storage/minio/helper.js.map +1 -1
- package/dist/cjs/modules/temporal/abstract.js +5 -5
- package/dist/cjs/modules/temporal/abstract.js.map +1 -1
- package/dist/cjs/modules/temporal/adapters/intl.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/adapters/intl.js +3 -1
- package/dist/cjs/modules/temporal/adapters/intl.js.map +1 -1
- package/dist/cjs/modules/temporal/locale/locale.js +4 -4
- package/dist/cjs/modules/temporal/locale/locale.js.map +1 -1
- package/dist/cjs/modules/tree/builder.js +2 -2
- package/dist/cjs/modules/tree/builder.js.map +1 -1
- package/dist/cjs/modules/uid/opaque.js +2 -2
- package/dist/cjs/modules/uid/opaque.js.map +1 -1
- package/dist/cjs/modules/uid/uuid/v5.js +1 -1
- package/dist/cjs/modules/uid/uuid/v5.js.map +1 -1
- package/dist/cjs/modules/worker-thread/bus/base.js +4 -4
- package/dist/cjs/modules/worker-thread/bus/base.js.map +1 -1
- package/dist/cjs/modules/worker-thread/thread/base.js +2 -2
- package/dist/cjs/modules/worker-thread/thread/base.js.map +1 -1
- package/dist/cjs/modules/worker-thread/worker/base.js +4 -4
- package/dist/cjs/modules/worker-thread/worker/base.js.map +1 -1
- package/dist/cjs/utilities/parse.utility.js +4 -4
- package/dist/cjs/utilities/parse.utility.js.map +1 -1
- package/dist/cjs/utilities/promise.utility.js +1 -1
- package/dist/cjs/utilities/promise.utility.js.map +1 -1
- package/dist/cjs/utilities/request.utility.js +1 -1
- package/dist/cjs/utilities/request.utility.js.map +1 -1
- package/dist/cjs/utilities/sleep.utility.js +1 -1
- package/dist/cjs/utilities/sleep.utility.js.map +1 -1
- package/dist/esm/common/constants/duration.d.ts +4 -1
- package/dist/esm/common/constants/duration.d.ts.map +1 -1
- package/dist/esm/common/constants/duration.js +13 -8
- package/dist/esm/common/constants/duration.js.map +1 -1
- package/dist/esm/common/redact.js +1 -1
- package/dist/esm/common/redact.js.map +1 -1
- package/dist/esm/modules/base.js +1 -1
- package/dist/esm/modules/base.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.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 +1 -1
- package/dist/esm/modules/env/app-env.js.map +1 -1
- package/dist/esm/modules/logger/common/constants.js +1 -1
- package/dist/esm/modules/logger/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/factory.js +1 -1
- package/dist/esm/modules/logger/factory.js.map +1 -1
- package/dist/esm/modules/logger/formatting/deep-splat.js +1 -1
- package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
- package/dist/esm/modules/logger/formatting/error-prettier.js +4 -4
- package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
- package/dist/esm/modules/logger/hf/flusher.js +3 -3
- package/dist/esm/modules/logger/hf/flusher.js.map +1 -1
- package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
- package/dist/esm/modules/logger/hf/logger.js +3 -1
- package/dist/esm/modules/logger/hf/logger.js.map +1 -1
- package/dist/esm/modules/logger/resolver.js +3 -3
- package/dist/esm/modules/logger/resolver.js.map +1 -1
- package/dist/esm/modules/logger/winston/formatters/deep-splat.js +1 -1
- package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +1 -1
- package/dist/esm/modules/logger/winston/logger-factory.js +1 -1
- package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
- package/dist/esm/modules/logger/winston/transports/dgram.transport.js +2 -2
- package/dist/esm/modules/logger/winston/transports/dgram.transport.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts +17 -14
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js +3 -0
- package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts +13 -4
- 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 +36 -13
- 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 +1 -1
- 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.d.ts.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +7 -6
- 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 +1 -1
- 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 +27 -2
- package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/query-string.js +31 -1
- package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.js +1 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/policy.js +1 -1
- package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
- package/dist/esm/modules/pool/abstract.js +4 -4
- package/dist/esm/modules/pool/abstract.js.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.js +2 -2
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +1 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.js +2 -2
- package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/esm/modules/queue/mqtt/helper.js +4 -4
- package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
- package/dist/esm/modules/redis/base/abstract.helper.js +4 -4
- package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.js +1 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js +1 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
- package/dist/esm/modules/secrets/base/abstract.helper.d.ts.map +1 -1
- package/dist/esm/modules/secrets/base/abstract.helper.js +7 -3
- package/dist/esm/modules/secrets/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +2 -2
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/browser.d.ts +5 -0
- package/dist/esm/modules/socket/socket-io/browser.d.ts.map +1 -0
- package/dist/esm/modules/socket/socket-io/browser.js +5 -0
- package/dist/esm/modules/socket/socket-io/browser.js.map +1 -0
- package/dist/esm/modules/socket/socket-io/client/browser-helper.d.ts +61 -0
- package/dist/esm/modules/socket/socket-io/client/browser-helper.d.ts.map +1 -0
- package/dist/esm/modules/socket/socket-io/client/browser-helper.js +246 -0
- package/dist/esm/modules/socket/socket-io/client/browser-helper.js.map +1 -0
- package/dist/esm/modules/socket/socket-io/client/helper.d.ts +8 -51
- package/dist/esm/modules/socket/socket-io/client/helper.d.ts.map +1 -1
- package/dist/esm/modules/socket/socket-io/client/helper.js +12 -230
- package/dist/esm/modules/socket/socket-io/client/helper.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/server/helper.js +5 -5
- package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
- package/dist/esm/modules/socket/websocket/server/delivery.js +2 -2
- package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
- package/dist/esm/modules/socket/websocket/server/helper.js +4 -4
- package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
- package/dist/esm/modules/storage/base.js +3 -3
- package/dist/esm/modules/storage/base.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.js +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/utility.js +6 -6
- package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
- package/dist/esm/modules/storage/common/errors.js +1 -1
- package/dist/esm/modules/storage/common/errors.js.map +1 -1
- package/dist/esm/modules/storage/minio/helper.js +4 -4
- package/dist/esm/modules/storage/minio/helper.js.map +1 -1
- package/dist/esm/modules/temporal/abstract.js +5 -5
- package/dist/esm/modules/temporal/abstract.js.map +1 -1
- package/dist/esm/modules/temporal/adapters/intl.d.ts.map +1 -1
- package/dist/esm/modules/temporal/adapters/intl.js +3 -1
- package/dist/esm/modules/temporal/adapters/intl.js.map +1 -1
- package/dist/esm/modules/temporal/locale/locale.js +4 -4
- package/dist/esm/modules/temporal/locale/locale.js.map +1 -1
- package/dist/esm/modules/tree/builder.js +2 -2
- package/dist/esm/modules/tree/builder.js.map +1 -1
- package/dist/esm/modules/uid/opaque.js +2 -2
- package/dist/esm/modules/uid/opaque.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v5.js +1 -1
- package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
- package/dist/esm/modules/worker-thread/bus/base.js +4 -4
- package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/thread/base.js +2 -2
- package/dist/esm/modules/worker-thread/thread/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/worker/base.js +4 -4
- package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
- package/dist/esm/utilities/parse.utility.js +4 -4
- package/dist/esm/utilities/parse.utility.js.map +1 -1
- package/dist/esm/utilities/promise.utility.js +1 -1
- package/dist/esm/utilities/promise.utility.js.map +1 -1
- package/dist/esm/utilities/request.utility.js +1 -1
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/dist/esm/utilities/sleep.utility.js +1 -1
- package/dist/esm/utilities/sleep.utility.js.map +1 -1
- package/package.json +10 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyObject } from '../../../common/types';
|
|
1
|
+
import { type AnyObject, type TConstValue } from '../../../common/types';
|
|
2
2
|
/** The punctuation of a query string, named so a reader sees the role rather than the character. */
|
|
3
3
|
export declare class QueryStringSeparators {
|
|
4
4
|
/** Between the path and the first pair. */
|
|
@@ -8,6 +8,27 @@ export declare class QueryStringSeparators {
|
|
|
8
8
|
/** Between a name and its value. */
|
|
9
9
|
static readonly ASSIGN = "=";
|
|
10
10
|
}
|
|
11
|
+
/** What a `null` or `undefined` value becomes. */
|
|
12
|
+
export declare class QueryStringNullishModes {
|
|
13
|
+
/** An empty value (`a=`): what `node:querystring` does. */
|
|
14
|
+
static readonly EMPTY = "empty";
|
|
15
|
+
/** The pair is left out. */
|
|
16
|
+
static readonly SKIP = "skip";
|
|
17
|
+
}
|
|
18
|
+
export type TQueryStringNullishMode = TConstValue<typeof QueryStringNullishModes>;
|
|
19
|
+
/** What an object or an array value becomes. */
|
|
20
|
+
export declare class QueryStringNestedModes {
|
|
21
|
+
/** An empty value (an array repeats its key instead): what `node:querystring` does. */
|
|
22
|
+
static readonly DROP = "drop";
|
|
23
|
+
/** One JSON-encoded parameter (`ids=[1,2]`, `filter={"where":{}}`), the shape a JSON filter travels in. */
|
|
24
|
+
static readonly JSON = "json";
|
|
25
|
+
}
|
|
26
|
+
export type TQueryStringNestedMode = TConstValue<typeof QueryStringNestedModes>;
|
|
27
|
+
/** How {@link toQueryString} treats the values `node:querystring` has no answer for. Both default to its behavior. */
|
|
28
|
+
export interface IQueryStringOptions {
|
|
29
|
+
nullish?: TQueryStringNullishMode;
|
|
30
|
+
nested?: TQueryStringNestedMode;
|
|
31
|
+
}
|
|
11
32
|
/**
|
|
12
33
|
* `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
|
|
13
34
|
* that one import is what kept the whole network layer out of a browser bundle.
|
|
@@ -19,8 +40,12 @@ export declare class QueryStringSeparators {
|
|
|
19
40
|
* reading "undefined".
|
|
20
41
|
*
|
|
21
42
|
* Diffed against `node:querystring` across 22 shapes with zero mismatches.
|
|
43
|
+
*
|
|
44
|
+
* `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
|
|
45
|
+
* array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
|
|
46
|
+
* the trip. The defaults keep the behavior above.
|
|
22
47
|
*/
|
|
23
48
|
export declare const toQueryString: (opts: {
|
|
24
49
|
params: AnyObject;
|
|
25
|
-
}) => string;
|
|
50
|
+
} & IQueryStringOptions) => string;
|
|
26
51
|
//# sourceMappingURL=query-string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-string.d.ts","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"query-string.d.ts","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElE,oGAAoG;AACpG,qBAAa,qBAAqB;IAChC,2CAA2C;IAC3C,MAAM,CAAC,QAAQ,CAAC,KAAK,OAAO;IAC5B,yBAAyB;IACzB,MAAM,CAAC,QAAQ,CAAC,IAAI,OAAO;IAC3B,oCAAoC;IACpC,MAAM,CAAC,QAAQ,CAAC,MAAM,OAAO;CAC9B;AAED,kDAAkD;AAClD,qBAAa,uBAAuB;IAClC,2DAA2D;IAC3D,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;IAChC,4BAA4B;IAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;CAC/B;AACD,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAElF,gDAAgD;AAChD,qBAAa,sBAAsB;IACjC,uFAAuF;IACvF,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,2GAA2G;IAC3G,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;CAC/B;AACD,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEhF,sHAAsH;AACtH,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,MAAM,CAAC,EAAE,sBAAsB,CAAC;CACjC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GAAG,mBAAmB,KAAG,MAkDjF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toQueryString = exports.QueryStringSeparators = void 0;
|
|
3
|
+
exports.toQueryString = exports.QueryStringNestedModes = exports.QueryStringNullishModes = exports.QueryStringSeparators = void 0;
|
|
4
4
|
/** The punctuation of a query string, named so a reader sees the role rather than the character. */
|
|
5
5
|
class QueryStringSeparators {
|
|
6
6
|
/** Between the path and the first pair. */
|
|
@@ -11,6 +11,22 @@ class QueryStringSeparators {
|
|
|
11
11
|
static { this.ASSIGN = '='; }
|
|
12
12
|
}
|
|
13
13
|
exports.QueryStringSeparators = QueryStringSeparators;
|
|
14
|
+
/** What a `null` or `undefined` value becomes. */
|
|
15
|
+
class QueryStringNullishModes {
|
|
16
|
+
/** An empty value (`a=`): what `node:querystring` does. */
|
|
17
|
+
static { this.EMPTY = 'empty'; }
|
|
18
|
+
/** The pair is left out. */
|
|
19
|
+
static { this.SKIP = 'skip'; }
|
|
20
|
+
}
|
|
21
|
+
exports.QueryStringNullishModes = QueryStringNullishModes;
|
|
22
|
+
/** What an object or an array value becomes. */
|
|
23
|
+
class QueryStringNestedModes {
|
|
24
|
+
/** An empty value (an array repeats its key instead): what `node:querystring` does. */
|
|
25
|
+
static { this.DROP = 'drop'; }
|
|
26
|
+
/** One JSON-encoded parameter (`ids=[1,2]`, `filter={"where":{}}`), the shape a JSON filter travels in. */
|
|
27
|
+
static { this.JSON = 'json'; }
|
|
28
|
+
}
|
|
29
|
+
exports.QueryStringNestedModes = QueryStringNestedModes;
|
|
14
30
|
/**
|
|
15
31
|
* `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
|
|
16
32
|
* that one import is what kept the whole network layer out of a browser bundle.
|
|
@@ -22,10 +38,16 @@ exports.QueryStringSeparators = QueryStringSeparators;
|
|
|
22
38
|
* reading "undefined".
|
|
23
39
|
*
|
|
24
40
|
* Diffed against `node:querystring` across 22 shapes with zero mismatches.
|
|
41
|
+
*
|
|
42
|
+
* `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
|
|
43
|
+
* array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
|
|
44
|
+
* the trip. The defaults keep the behavior above.
|
|
25
45
|
*/
|
|
26
46
|
const toQueryString = (opts) => {
|
|
27
|
-
const { params } = opts;
|
|
47
|
+
const { params, nullish = QueryStringNullishModes.EMPTY, nested = QueryStringNestedModes.DROP, } = opts;
|
|
28
48
|
const parts = [];
|
|
49
|
+
const isSkipped = (value) => nullish === QueryStringNullishModes.SKIP && (value === null || value === undefined);
|
|
50
|
+
const isJson = nested === QueryStringNestedModes.JSON;
|
|
29
51
|
// A primitive only. `querystring` drops an object or a nested array to an empty value rather than
|
|
30
52
|
// stringifying it, and a caller that passed one meant something this format cannot carry anyway.
|
|
31
53
|
const encode = (value) => value === null || value === undefined || typeof value === 'object'
|
|
@@ -34,9 +56,19 @@ const toQueryString = (opts) => {
|
|
|
34
56
|
const entries = Object.entries(params);
|
|
35
57
|
for (const [key, value] of entries) {
|
|
36
58
|
const name = encodeURIComponent(key);
|
|
59
|
+
if (isSkipped(value)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (isJson && typeof value === 'object' && value !== null) {
|
|
63
|
+
parts.push(`${name}${QueryStringSeparators.ASSIGN}${encodeURIComponent(JSON.stringify(value))}`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
37
66
|
// An array repeats the key, which is what a server reading a list expects.
|
|
38
67
|
if (Array.isArray(value)) {
|
|
39
68
|
for (const entry of value) {
|
|
69
|
+
if (isSkipped(entry)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
40
72
|
parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(entry)}`);
|
|
41
73
|
}
|
|
42
74
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-string.js","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":";;;AAEA,oGAAoG;AACpG,MAAa,qBAAqB;IAChC,2CAA2C;aAC3B,UAAK,GAAG,GAAG,CAAC;IAC5B,yBAAyB;aACT,SAAI,GAAG,GAAG,CAAC;IAC3B,oCAAoC;aACpB,WAAM,GAAG,GAAG,CAAC;;AAN/B,sDAOC;AAED
|
|
1
|
+
{"version":3,"file":"query-string.js","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":";;;AAEA,oGAAoG;AACpG,MAAa,qBAAqB;IAChC,2CAA2C;aAC3B,UAAK,GAAG,GAAG,CAAC;IAC5B,yBAAyB;aACT,SAAI,GAAG,GAAG,CAAC;IAC3B,oCAAoC;aACpB,WAAM,GAAG,GAAG,CAAC;;AAN/B,sDAOC;AAED,kDAAkD;AAClD,MAAa,uBAAuB;IAClC,2DAA2D;aAC3C,UAAK,GAAG,OAAO,CAAC;IAChC,4BAA4B;aACZ,SAAI,GAAG,MAAM,CAAC;;AAJhC,0DAKC;AAGD,gDAAgD;AAChD,MAAa,sBAAsB;IACjC,uFAAuF;aACvE,SAAI,GAAG,MAAM,CAAC;IAC9B,2GAA2G;aAC3F,SAAI,GAAG,MAAM,CAAC;;AAJhC,wDAKC;AASD;;;;;;;;;;;;;;;GAeG;AACI,MAAM,aAAa,GAAG,CAAC,IAAiD,EAAU,EAAE;IACzF,MAAM,EACJ,MAAM,EACN,OAAO,GAAG,uBAAuB,CAAC,KAAK,EACvC,MAAM,GAAG,sBAAsB,CAAC,IAAI,GACrC,GAAG,IAAI,CAAC;IACT,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,S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C,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACvE,CAAC;YAED,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC,CAAC;AAlDW,QAAA,aAAa,iBAkDxB","sourcesContent":["import { type AnyObject, type TConstValue } from '@/common/types';\n\n/** The punctuation of a query string, named so a reader sees the role rather than the character. */\nexport class QueryStringSeparators {\n /** Between the path and the first pair. */\n static readonly START = '?';\n /** Between two pairs. */\n static readonly PAIR = '&';\n /** Between a name and its value. */\n static readonly ASSIGN = '=';\n}\n\n/** What a `null` or `undefined` value becomes. */\nexport class QueryStringNullishModes {\n /** An empty value (`a=`): what `node:querystring` does. */\n static readonly EMPTY = 'empty';\n /** The pair is left out. */\n static readonly SKIP = 'skip';\n}\nexport type TQueryStringNullishMode = TConstValue<typeof QueryStringNullishModes>;\n\n/** What an object or an array value becomes. */\nexport class QueryStringNestedModes {\n /** An empty value (an array repeats its key instead): what `node:querystring` does. */\n static readonly DROP = 'drop';\n /** One JSON-encoded parameter (`ids=[1,2]`, `filter={\"where\":{}}`), the shape a JSON filter travels in. */\n static readonly JSON = 'json';\n}\nexport type TQueryStringNestedMode = TConstValue<typeof QueryStringNestedModes>;\n\n/** How {@link toQueryString} treats the values `node:querystring` has no answer for. Both default to its behavior. */\nexport interface IQueryStringOptions {\n nullish?: TQueryStringNullishMode;\n nested?: TQueryStringNestedMode;\n}\n\n/**\n * `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -\n * that one import is what kept the whole network layer out of a browser bundle.\n *\n * Not `new URLSearchParams(params).toString()`, which differs on four counts measured against the\n * original: an array becomes `a=1%2C2` instead of `a=1&a=2`, `undefined` and `null` become the\n * STRINGS \"undefined\" and \"null\" instead of an empty value, and a space encodes as `+` rather than\n * `%20`. The first changes what a server parses; the second is the same coercion that sends a header\n * reading \"undefined\".\n *\n * Diffed against `node:querystring` across 22 shapes with zero mismatches.\n *\n * `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an\n * array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives\n * the trip. The defaults keep the behavior above.\n */\nexport const toQueryString = (opts: { params: AnyObject } & IQueryStringOptions): string => {\n const {\n params,\n nullish = QueryStringNullishModes.EMPTY,\n nested = QueryStringNestedModes.DROP,\n } = opts;\n const parts: string[] = [];\n const isSkipped = (value: unknown) =>\n nullish === QueryStringNullishModes.SKIP && (value === null || value === undefined);\n const isJson = nested === QueryStringNestedModes.JSON;\n\n // A primitive only. `querystring` drops an object or a nested array to an empty value rather than\n // stringifying it, and a caller that passed one meant something this format cannot carry anyway.\n const encode = (value: unknown) =>\n value === null || value === undefined || typeof value === 'object'\n ? ''\n : encodeURIComponent(String(value));\n\n const entries = Object.entries(params);\n for (const [key, value] of entries) {\n const name = encodeURIComponent(key);\n\n if (isSkipped(value)) {\n continue;\n }\n\n if (isJson && typeof value === 'object' && value !== null) {\n parts.push(\n `${name}${QueryStringSeparators.ASSIGN}${encodeURIComponent(JSON.stringify(value))}`,\n );\n continue;\n }\n\n // An array repeats the key, which is what a server reading a list expects.\n if (Array.isArray(value)) {\n for (const entry of value) {\n if (isSkipped(entry)) {\n continue;\n }\n\n parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(entry)}`);\n }\n\n continue;\n }\n\n parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(value)}`);\n }\n\n return parts.join(QueryStringSeparators.PAIR);\n};\n"]}
|
|
@@ -34,7 +34,7 @@ class UrlIngest {
|
|
|
34
34
|
message: `[assertPublicHost] Host resolves to nothing | host: ${hostname}`,
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
const offender = addresses.find(entry => policy_1.UrlPolicy.isNonPublicAddress({ address: entry.address }));
|
|
37
|
+
const offender = addresses.find((entry) => policy_1.UrlPolicy.isNonPublicAddress({ address: entry.address }));
|
|
38
38
|
if (offender) {
|
|
39
39
|
throw (0, error_1.getError)({
|
|
40
40
|
error: errors_1.UrlSafetyErrors.URL_REFUSED,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/ingest.ts"],"names":[],"mappings":";AAAA,gGAAgG;AAChG,yCAAyC;;;AAEzC,0DAAkE;AAClE,2CAA2C;AAC3C,gDAA2C;AAC3C,kDAAuD;AACvD,4CAAkD;AAElD,qCAAqC;AAErC,6EAA6E;AAC7E,MAAa,SAAS;IACpB;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAG7B;QACC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAElC,IAAI,MAAM,EAAE,mBAAmB,IAAI,6BAAiB,CAAC,qBAAqB,EAAE,CAAC;YAC3E,OAAO;QACT,CAAC;QAED,+FAA+F;QAC/F,gGAAgG;QAChG,MAAM,OAAO,GAAG,kBAAS,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACxD,MAAM,SAAS,GAAG,MAAM,IAAA,iBAAM,EAAC,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QAEvD,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,IAAA,gBAAQ,EAAC;gBACb,KAAK,EAAE,wBAAe,CAAC,WAAW;gBAClC,OAAO,EAAE,uDAAuD,QAAQ,EAAE;aAC3E,CAAC,CAAC;QACL,CAAC;QAED,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CACtC,kBAAS,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,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9B,+FAA+F;YAC/F,+FAA+F;YAC/F,MAAM,IAAA,gBAAQ,EAAC;gBACb,KAAK,EAAE,wBAAe,CAAC,WAAW;gBAClC,OAAO,EAAE,qDAAqD,cAAc,WAAW,QAAQ,EAAE;aAClG,CAAC,CAAC;QACL,CAAC;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAA,gBAAQ,EAAC,EAAE,OAAO,EAAE,2CAA2C,EAAE,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,IAAI,QAAQ,GAAG,CAAC,CAAC;QAEjB,SAAS,CAAC;YACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM;YACR,CAAC;YAED,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC;YACzB,IAAI,QAAQ,GAAG,QAAQ,EAAE,CAAC;gBACxB,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;gBACtB,MAAM,IAAA,gBAAQ,EAAC;oBACb,KAAK,EAAE,wBAAe,CAAC,WAAW;oBAClC,OAAO,EAAE,qDAAqD,QAAQ,WAAW,QAAQ,EAAE;iBAC5F,CAAC,CAAC;YACL,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF;AAvMD,8BAuMC","sourcesContent":["// The half `policy.ts` cannot do: resolving a hostname needs `node:dns`, so nothing here may be\n// re-exported from the `./core` subpath.\n\nimport { DurationMultipliers } from '@/common/constants/duration';\nimport { getError } from '@/modules/error';\nimport { lookup } from 'node:dns/promises';\nimport { UrlSafetyDefaults } from './common/constants';\nimport { UrlSafetyErrors } from './common/errors';\nimport type { IUrlSafetyPolicy } from './common/types';\nimport { UrlPolicy } from './policy';\n\n/** Fetching an untrusted url without letting it reach inside the network. */\nexport class UrlIngest {\n /**\n * Rejects when ANY resolved address is non-public. Checking only the first walks straight into a\n * host that publishes one public A record beside an internal one.\n *\n * A rebinding window remains: the address can change between this check and the connect. Closing\n * it means connecting to the resolved address and setting `Host` by hand, which no fetch API\n * exposes.\n */\n static async assertPublicHost(opts: {\n hostname: string;\n policy?: IUrlSafetyPolicy;\n }): Promise<void> {\n const { hostname, policy } = opts;\n\n if (policy?.allowPrivateAddress ?? UrlSafetyDefaults.ALLOW_PRIVATE_ADDRESS) {\n return;\n }\n\n // `URL.hostname` keeps the brackets on an IPv6 literal; `lookup` does not accept them, and the\n // ENOTFOUND that follows reads as a transient DNS failure rather than the refusal it should be.\n const address = UrlPolicy.readHostAddress({ hostname });\n const addresses = await lookup(address, { all: true });\n\n if (!addresses.length) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertPublicHost] Host resolves to nothing | host: ${hostname}`,\n });\n }\n\n const offender = addresses.find(entry =>\n UrlPolicy.isNonPublicAddress({ address: entry.address }),\n );\n\n if (offender) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertPublicHost] Host resolves to a non-public address | host: ${hostname} | address: ${offender.address}`,\n });\n }\n }\n\n /** Both halves, in the order they must run: shape first, then the network. */\n static async assertReachableUrl(opts: { url: string; policy?: IUrlSafetyPolicy }): Promise<URL> {\n const parsed = UrlPolicy.assertSafeUrl(opts);\n await UrlIngest.assertPublicHost({ hostname: parsed.hostname, policy: opts.policy });\n return parsed;\n }\n\n private static readTimeoutMilliseconds(opts: { policy?: IUrlSafetyPolicy }): number {\n const { timeout } = opts.policy ?? {};\n const milliseconds = timeout ? DurationMultipliers.toMilliseconds(timeout) : null;\n return milliseconds ?? UrlSafetyDefaults.TIMEOUT_MILLISECONDS;\n }\n\n /**\n * A GET that an untrusted url cannot steer inside the network. Redirects are followed by hand so\n * every hop is re-checked - `redirect: 'follow'` would land on an internal host with no second\n * look.\n *\n * The body is returned unread: the caller decides whether to stream it onward or cap it with\n * {@link UrlIngest.readCappedBody}. Nothing is buffered here.\n */\n static async fetchGuarded(opts: {\n url: string;\n policy?: IUrlSafetyPolicy;\n headers?: Record<string, string>;\n }): Promise<Response> {\n const { url, policy, headers } = opts;\n const maxRedirects = policy?.maxRedirects ?? UrlSafetyDefaults.MAX_REDIRECTS;\n const timeoutMilliseconds = UrlIngest.readTimeoutMilliseconds({ policy });\n\n let target = await UrlIngest.assertReachableUrl({ url, policy });\n\n for (let hop = 0; hop <= maxRedirects; hop += 1) {\n const response = await fetch(target, {\n redirect: 'manual',\n signal: AbortSignal.timeout(timeoutMilliseconds),\n ...(headers ? { headers } : {}),\n });\n\n if (response.status < 300 || response.status > 399) {\n if (!response.ok) {\n // Cancelled, or the socket stays open on every 4xx and 5xx.\n await response.body?.cancel();\n throw getError({\n message: `[fetchGuarded] Request failed | status: ${response.status} | url: ${url}`,\n });\n }\n\n return response;\n }\n\n const location = response.headers.get('location');\n await response.body?.cancel();\n\n if (!location) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[fetchGuarded] Redirect carried no location | url: ${url}`,\n });\n }\n\n target = await UrlIngest.assertReachableUrl({\n url: new URL(location, target).toString(),\n policy,\n });\n }\n\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[fetchGuarded] Too many redirects | max: ${maxRedirects} | url: ${url}`,\n });\n }\n\n /**\n * Enforces `maxBytes` on a stream nothing reads into this process - the shape a caller wants when\n * the body is piped onward rather than held. Without it a `maxBytes` policy is inert on that path.\n */\n static capStream(opts: {\n source: ReadableStream<Uint8Array>;\n policy?: IUrlSafetyPolicy;\n }): ReadableStream<Uint8Array> {\n const { source } = opts;\n const maxBytes = opts.policy?.maxBytes ?? UrlSafetyDefaults.MAX_BYTES;\n let received = 0;\n\n return source.pipeThrough(\n new TransformStream<Uint8Array, Uint8Array>({\n transform(chunk, controller) {\n received += chunk.byteLength;\n\n if (received > maxBytes) {\n controller.error(\n getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[capStream] Body exceeds the cap | received: ${received} | max: ${maxBytes}`,\n }),\n );\n return;\n }\n\n controller.enqueue(chunk);\n },\n }),\n );\n }\n\n /**\n * Reads a body that must not exceed `maxBytes`, cancelling the moment it does. `content-length` is\n * checked first because it is free, and counted anyway because it may be absent or lie.\n */\n static async readCappedBody(opts: {\n response: Response;\n policy?: IUrlSafetyPolicy;\n }): Promise<Buffer> {\n const { response, policy } = opts;\n const maxBytes = policy?.maxBytes ?? UrlSafetyDefaults.MAX_BYTES;\n\n const declaredLength = Number(response.headers.get('content-length') ?? 0);\n if (declaredLength > maxBytes) {\n await response.body?.cancel();\n // The same fact as the streaming branch below, so the same verdict: a caller must not retry an\n // oversized body when the server sends `content-length` and drop it when the server omits one.\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[readCappedBody] Body exceeds the cap | declared: ${declaredLength} | max: ${maxBytes}`,\n });\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw getError({ message: '[readCappedBody] Response carried no body' });\n }\n\n const chunks: Uint8Array[] = [];\n let received = 0;\n\n for (;;) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n received += value.length;\n if (received > maxBytes) {\n await reader.cancel();\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[readCappedBody] Body exceeds the cap | received: ${received} | max: ${maxBytes}`,\n });\n }\n\n chunks.push(value);\n }\n\n return Buffer.concat(chunks);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/ingest.ts"],"names":[],"mappings":";AAAA,gGAAgG;AAChG,yCAAyC;;;AAEzC,0DAAkE;AAClE,2CAA2C;AAC3C,gDAA2C;AAC3C,kDAAuD;AACvD,4CAAkD;AAElD,qCAAqC;AAErC,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AG,CAAC,CAAC;QAEjB,SAAS,CAAC;YACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM;YACR,CAAC;YAED,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC;YACzB,IAAI,QAAQ,GAAG,QAAQ,EAAE,CAAC;gBACxB,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;gBACtB,MAAM,IAAA,gBAAQ,EAAC;oBACb,KAAK,EAAE,wBAAe,CAAC,WAAW;oBAClC,OAAO,EAAE,qDAAqD,QAAQ,WAAW,QAAQ,EAAE;iBAC5F,CAAC,CAAC;YACL,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF;AAvMD,8BAuMC","sourcesContent":["// The half `policy.ts` cannot do: resolving a hostname needs `node:dns`, so nothing here may be\n// re-exported from the `./core` subpath.\n\nimport { DurationMultipliers } from '@/common/constants/duration';\nimport { getError } from '@/modules/error';\nimport { lookup } from 'node:dns/promises';\nimport { UrlSafetyDefaults } from './common/constants';\nimport { UrlSafetyErrors } from './common/errors';\nimport type { IUrlSafetyPolicy } from './common/types';\nimport { UrlPolicy } from './policy';\n\n/** Fetching an untrusted url without letting it reach inside the network. */\nexport class UrlIngest {\n /**\n * Rejects when ANY resolved address is non-public. Checking only the first walks straight into a\n * host that publishes one public A record beside an internal one.\n *\n * A rebinding window remains: the address can change between this check and the connect. Closing\n * it means connecting to the resolved address and setting `Host` by hand, which no fetch API\n * exposes.\n */\n static async assertPublicHost(opts: {\n hostname: string;\n policy?: IUrlSafetyPolicy;\n }): Promise<void> {\n const { hostname, policy } = opts;\n\n if (policy?.allowPrivateAddress ?? UrlSafetyDefaults.ALLOW_PRIVATE_ADDRESS) {\n return;\n }\n\n // `URL.hostname` keeps the brackets on an IPv6 literal; `lookup` does not accept them, and the\n // ENOTFOUND that follows reads as a transient DNS failure rather than the refusal it should be.\n const address = UrlPolicy.readHostAddress({ hostname });\n const addresses = await lookup(address, { all: true });\n\n if (!addresses.length) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertPublicHost] Host resolves to nothing | host: ${hostname}`,\n });\n }\n\n const offender = addresses.find((entry) =>\n UrlPolicy.isNonPublicAddress({ address: entry.address }),\n );\n\n if (offender) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertPublicHost] Host resolves to a non-public address | host: ${hostname} | address: ${offender.address}`,\n });\n }\n }\n\n /** Both halves, in the order they must run: shape first, then the network. */\n static async assertReachableUrl(opts: { url: string; policy?: IUrlSafetyPolicy }): Promise<URL> {\n const parsed = UrlPolicy.assertSafeUrl(opts);\n await UrlIngest.assertPublicHost({ hostname: parsed.hostname, policy: opts.policy });\n return parsed;\n }\n\n private static readTimeoutMilliseconds(opts: { policy?: IUrlSafetyPolicy }): number {\n const { timeout } = opts.policy ?? {};\n const milliseconds = timeout ? DurationMultipliers.toMilliseconds(timeout) : null;\n return milliseconds ?? UrlSafetyDefaults.TIMEOUT_MILLISECONDS;\n }\n\n /**\n * A GET that an untrusted url cannot steer inside the network. Redirects are followed by hand so\n * every hop is re-checked - `redirect: 'follow'` would land on an internal host with no second\n * look.\n *\n * The body is returned unread: the caller decides whether to stream it onward or cap it with\n * {@link UrlIngest.readCappedBody}. Nothing is buffered here.\n */\n static async fetchGuarded(opts: {\n url: string;\n policy?: IUrlSafetyPolicy;\n headers?: Record<string, string>;\n }): Promise<Response> {\n const { url, policy, headers } = opts;\n const maxRedirects = policy?.maxRedirects ?? UrlSafetyDefaults.MAX_REDIRECTS;\n const timeoutMilliseconds = UrlIngest.readTimeoutMilliseconds({ policy });\n\n let target = await UrlIngest.assertReachableUrl({ url, policy });\n\n for (let hop = 0; hop <= maxRedirects; hop += 1) {\n const response = await fetch(target, {\n redirect: 'manual',\n signal: AbortSignal.timeout(timeoutMilliseconds),\n ...(headers ? { headers } : {}),\n });\n\n if (response.status < 300 || response.status > 399) {\n if (!response.ok) {\n // Cancelled, or the socket stays open on every 4xx and 5xx.\n await response.body?.cancel();\n throw getError({\n message: `[fetchGuarded] Request failed | status: ${response.status} | url: ${url}`,\n });\n }\n\n return response;\n }\n\n const location = response.headers.get('location');\n await response.body?.cancel();\n\n if (!location) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[fetchGuarded] Redirect carried no location | url: ${url}`,\n });\n }\n\n target = await UrlIngest.assertReachableUrl({\n url: new URL(location, target).toString(),\n policy,\n });\n }\n\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[fetchGuarded] Too many redirects | max: ${maxRedirects} | url: ${url}`,\n });\n }\n\n /**\n * Enforces `maxBytes` on a stream nothing reads into this process - the shape a caller wants when\n * the body is piped onward rather than held. Without it a `maxBytes` policy is inert on that path.\n */\n static capStream(opts: {\n source: ReadableStream<Uint8Array>;\n policy?: IUrlSafetyPolicy;\n }): ReadableStream<Uint8Array> {\n const { source } = opts;\n const maxBytes = opts.policy?.maxBytes ?? UrlSafetyDefaults.MAX_BYTES;\n let received = 0;\n\n return source.pipeThrough(\n new TransformStream<Uint8Array, Uint8Array>({\n transform(chunk, controller) {\n received += chunk.byteLength;\n\n if (received > maxBytes) {\n controller.error(\n getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[capStream] Body exceeds the cap | received: ${received} | max: ${maxBytes}`,\n }),\n );\n return;\n }\n\n controller.enqueue(chunk);\n },\n }),\n );\n }\n\n /**\n * Reads a body that must not exceed `maxBytes`, cancelling the moment it does. `content-length` is\n * checked first because it is free, and counted anyway because it may be absent or lie.\n */\n static async readCappedBody(opts: {\n response: Response;\n policy?: IUrlSafetyPolicy;\n }): Promise<Buffer> {\n const { response, policy } = opts;\n const maxBytes = policy?.maxBytes ?? UrlSafetyDefaults.MAX_BYTES;\n\n const declaredLength = Number(response.headers.get('content-length') ?? 0);\n if (declaredLength > maxBytes) {\n await response.body?.cancel();\n // The same fact as the streaming branch below, so the same verdict: a caller must not retry an\n // oversized body when the server sends `content-length` and drop it when the server omits one.\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[readCappedBody] Body exceeds the cap | declared: ${declaredLength} | max: ${maxBytes}`,\n });\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw getError({ message: '[readCappedBody] Response carried no body' });\n }\n\n const chunks: Uint8Array[] = [];\n let received = 0;\n\n for (;;) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n received += value.length;\n if (received > maxBytes) {\n await reader.cancel();\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[readCappedBody] Body exceeds the cap | received: ${received} | max: ${maxBytes}`,\n });\n }\n\n chunks.push(value);\n }\n\n return Buffer.concat(chunks);\n }\n}\n"]}
|
|
@@ -16,7 +16,7 @@ class UrlPolicy {
|
|
|
16
16
|
static isNonPublicIPv4(opts) {
|
|
17
17
|
const parts = opts.address.split('.').map(Number);
|
|
18
18
|
if (parts.length !== 4 ||
|
|
19
|
-
parts.some(part => !Number.isInteger(part) || part < 0 || part > 255)) {
|
|
19
|
+
parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
22
|
const [first, second] = parts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/policy.ts"],"names":[],"mappings":";AAAA,8FAA8F;AAC9F,gGAAgG;AAChG,gGAAgG;AAChG,iBAAiB;;;AAEjB,2CAA2C;AAC3C,kDAAmE;AA+H1D,kGA/HA,6BAAiB,OA+HA;AAAE,2FA/HA,sBAAU,OA+HA;AA9HtC,4CAAkD;AAGlD,+EAA+E;AAC/E,MAAa,SAAS;IACpB,4GAA4G;IACpG,MAAM,CAAC,eAAe,CAAC,IAAyB;QACtD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAElD,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/policy.ts"],"names":[],"mappings":";AAAA,8FAA8F;AAC9F,gGAAgG;AAChG,gGAAgG;AAChG,iBAAiB;;;AAEjB,2CAA2C;AAC3C,kDAAmE;AA+H1D,kGA/HA,6BAAiB,OA+HA;AAAE,2FA/HA,sBAAU,OA+HA;AA9HtC,4CAAkD;AAGlD,+EAA+E;AAC/E,MAAa,SAAS;IACpB,4GAA4G;IACpG,MAAM,CAAC,eAAe,CAAC,IAAyB;QACtD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAElD,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,GAAG,CAAC,EACvE,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;QAE9B,OAAO,CACL,KAAK,KAAK,CAAC,IAAI,YAAY;YAC3B,KAAK,KAAK,EAAE,IAAI,UAAU;YAC1B,KAAK,KAAK,GAAG,IAAI,WAAW;YAC5B,CAAC,KAAK,KAAK,GAAG,IAAI,MAAM,IAAI,EAAE,IAAI,MAAM,IAAI,GAAG,CAAC,IAAI,oBAAoB;YACxE,CAAC,KAAK,KAAK,GAAG,IAAI,MAAM,KAAK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ACb,KAAK,EAAE,wBAAe,CAAC,WAAW;gBAClC,OAAO,EAAE,iEAAiE,OAAO,EAAE;aACpF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxHD,8BAwHC","sourcesContent":["// The browser-pure half of the guard: a url and a literal address are decided with string and\n// number work alone. Resolving a hostname needs `node:dns` and lives in `ingest.ts`, which this\n// file must never import - `policy.ts` is re-exported from the `./core` subpath and is gated by\n// `make purity`.\n\nimport { getError } from '@/modules/error';\nimport { UrlSafetyDefaults, UrlSchemes } from './common/constants';\nimport { UrlSafetyErrors } from './common/errors';\nimport type { IUrlSafetyPolicy } from './common/types';\n\n/** Everything about a url that can be decided without touching the network. */\nexport class UrlPolicy {\n /** A dotted-quad that is not routable on the public internet. An unparseable input counts as non-public. */\n private static isNonPublicIPv4(opts: { address: string }): boolean {\n const parts = opts.address.split('.').map(Number);\n\n if (\n parts.length !== 4 ||\n parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)\n ) {\n return true;\n }\n\n const [first, second] = parts;\n\n return (\n first === 0 || // this host\n first === 10 || // private\n first === 127 || // loopback\n (first === 100 && second >= 64 && second <= 127) || // carrier-grade NAT\n (first === 169 && second === 254) || // link-local, and the cloud metadata address\n (first === 172 && second >= 16 && second <= 31) || // private\n (first === 192 && second === 0) || // IETF protocol assignments\n (first === 192 && second === 168) || // private\n (first === 198 && (second === 18 || second === 19)) || // benchmarking\n first >= 224 // multicast and reserved\n );\n }\n\n /**\n * An address that must never be reached with an untrusted url. Anything unrecognised answers\n * `true`: a guard that fails open on a string it cannot parse is not a guard.\n */\n static isNonPublicAddress(opts: { address: string }): boolean {\n const normalized = opts.address.toLowerCase().split('%')[0];\n\n if (!normalized.includes(':')) {\n return UrlPolicy.isNonPublicIPv4({ address: normalized });\n }\n\n // An IPv4 address wearing an IPv6 coat walks past every naive v6 check. Both spellings must be\n // unwrapped: `new URL` rewrites `::ffff:169.254.169.254` into the hex form `::ffff:a9fe:a9fe`,\n // so a dotted-quad-only check is green on a value the parser never actually produces.\n const dottedMapped = /^::ffff:(\\d+\\.\\d+\\.\\d+\\.\\d+)$/.exec(normalized)?.[1];\n if (dottedMapped) {\n return UrlPolicy.isNonPublicIPv4({ address: dottedMapped });\n }\n\n const hexMapped = /^::ffff:([\\da-f]{1,4}):([\\da-f]{1,4})$/.exec(normalized);\n if (hexMapped) {\n const high = Number.parseInt(hexMapped[1], 16);\n const low = Number.parseInt(hexMapped[2], 16);\n const dotted = [high >> 8, high & 0xff, low >> 8, low & 0xff].join('.');\n\n return UrlPolicy.isNonPublicIPv4({ address: dotted });\n }\n\n return (\n normalized === '::' ||\n normalized === '::1' ||\n normalized.startsWith('fc') || // unique local\n normalized.startsWith('fd') ||\n normalized.startsWith('fe8') || // link-local\n normalized.startsWith('fe9') ||\n normalized.startsWith('fea') ||\n normalized.startsWith('feb')\n );\n }\n\n /** A bracketed IPv6 literal arrives as `[::1]`; the brackets are not part of the address. */\n static readHostAddress(opts: { hostname: string }): string {\n const { hostname } = opts;\n return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;\n }\n\n /**\n * A hostname that RESOLVES to a private address passes here on purpose - `UrlIngest` catches that,\n * and this half runs where `node:dns` does not exist.\n */\n static assertSafeUrl(opts: { url: string; policy?: IUrlSafetyPolicy }): URL {\n const { url, policy } = opts;\n const allowedSchemes = policy?.allowedSchemes ?? UrlSafetyDefaults.ALLOWED_SCHEMES;\n const allowPrivateAddress =\n policy?.allowPrivateAddress ?? UrlSafetyDefaults.ALLOW_PRIVATE_ADDRESS;\n\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Malformed url | url: ${url}`,\n });\n }\n\n if (!allowedSchemes.includes(parsed.protocol)) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Disallowed scheme | scheme: ${parsed.protocol} | allowed: ${allowedSchemes.join(', ')}`,\n });\n }\n\n if (policy?.allowedHosts && !policy.allowedHosts.includes(parsed.hostname)) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Host is not in the allow-list | host: ${parsed.hostname}`,\n });\n }\n\n const address = UrlPolicy.readHostAddress({ hostname: parsed.hostname });\n const isLiteralAddress = /^[\\d.]+$/.test(address) || address.includes(':');\n\n if (!allowPrivateAddress && isLiteralAddress && UrlPolicy.isNonPublicAddress({ address })) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Url points at a non-public address | address: ${address}`,\n });\n }\n\n return parsed;\n }\n}\n\nexport { UrlSafetyDefaults, UrlSchemes };\nexport type { IUrlSafetyPolicy };\n"]}
|
|
@@ -76,7 +76,7 @@ class AbstractPoolHelper extends base_1.BaseHelper {
|
|
|
76
76
|
}
|
|
77
77
|
this.borrowed.delete(resource);
|
|
78
78
|
if (this.isDestroyed) {
|
|
79
|
-
this.destroyResource({ resource }).catch(error => {
|
|
79
|
+
this.destroyResource({ resource }).catch((error) => {
|
|
80
80
|
logger.warn('destroyResource error on release: %s', error);
|
|
81
81
|
});
|
|
82
82
|
return;
|
|
@@ -128,7 +128,7 @@ class AbstractPoolHelper extends base_1.BaseHelper {
|
|
|
128
128
|
waiter.reject(error);
|
|
129
129
|
}
|
|
130
130
|
const toDestroy = this.idle.splice(0);
|
|
131
|
-
await Promise.all(toDestroy.map(resource => this.destroyResource({ resource })));
|
|
131
|
+
await Promise.all(toDestroy.map((resource) => this.destroyResource({ resource })));
|
|
132
132
|
}
|
|
133
133
|
// ----------------------------------------------------------------------------------------------------------
|
|
134
134
|
async createResource() {
|
|
@@ -157,7 +157,7 @@ class AbstractPoolHelper extends base_1.BaseHelper {
|
|
|
157
157
|
// ----------------------------------------------------------------------------------------------------------
|
|
158
158
|
/** Fire-and-forget dispatch with logged rejection; shared by all dispatch call sites. */
|
|
159
159
|
safeDispatch(opts) {
|
|
160
|
-
this.dispatch().catch(error => {
|
|
160
|
+
this.dispatch().catch((error) => {
|
|
161
161
|
this.logger
|
|
162
162
|
.for(this.dispatch.name)
|
|
163
163
|
.warn('dispatch error | action: %s | Error: %s', opts.action, error);
|
|
@@ -243,7 +243,7 @@ class AbstractPoolHelper extends base_1.BaseHelper {
|
|
|
243
243
|
const { resource } = opts;
|
|
244
244
|
// `destroy()` tears down what it can SEE - the waiter queue and the idle list. A resource whose create() was still in flight is in neither, so parking it in idle now would leave it alive with nothing left to reclaim it.
|
|
245
245
|
if (this.isDestroyed) {
|
|
246
|
-
this.destroyResource({ resource }).catch(error => {
|
|
246
|
+
this.destroyResource({ resource }).catch((error) => {
|
|
247
247
|
this.logger
|
|
248
248
|
.for(this.handToWaiter.name)
|
|
249
249
|
.warn('destroyResource error on a resource created after destroy(): %s', error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../src/modules/pool/abstract.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,2CAA2C;AAC3C,oDAA4D;AAG5D,4SAA4S;AAC5S,MAAsB,kBAAsB,SAAQ,iBAAU;IAa5D,YAAY,IAAyB;QACnC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,gBAAgB,EAAE,CAAC,CAAC;QATlC,SAAI,GAAQ,EAAE,CAAC;QACf,aAAQ,GAAG,IAAI,GAAG,EAAK,CAAC;QACxB,gBAAW,GAAG,IAAI,kBAAa,EAAkB,CAAC;QAE3D,UAAK,GAAG,CAAC,CAAC,CAAC,kCAAkC;QAC7C,kBAAa,GAAG,KAAK,CAAC;QACtB,gBAAW,GAAG,KAAK,CAAC;QAI1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAC9C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC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;qBAC3B,IAAI,CAAC,iEAAiE,EAAE,KAAK,CAAC,CAAC;YACpF,CAAC,CAAC,CAAC;YACH,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5B,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sGAAsG;IAC9F,cAAc;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,gBAAgB,CAAC,IAAgC;QACvD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;CACF;AAvUD,gDAuUC","sourcesContent":["import { type TNullable, type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { HfQueueHelper } from '@/modules/queue/internal/hf';\nimport { type IPool, type IPoolControlOptions, type IPoolStats, type IPoolWaiter } from './common';\n\n/** Single-borrower pool skeleton: subclasses override {@link create} (required) and optionally validateResource/resetResource/onDestroyResource. All resource-waiter pairing flows through ONE re-entrancy-guarded `dispatch()` loop; the waiter queue is {@link HfQueueHelper} - O(1), no shift/splice. */\nexport abstract class AbstractPoolHelper<T> extends BaseHelper implements IPool<T> {\n protected readonly size: number;\n protected readonly acquireTimeoutMs?: number;\n protected readonly maxWaitingClients?: number;\n\n private readonly idle: T[] = [];\n private readonly borrowed = new Set<T>();\n private readonly waiterQueue = new HfQueueHelper<IPoolWaiter<T>>();\n\n private total = 0; // live or being-created resources\n private isDispatching = false;\n private isDestroyed = false;\n\n constructor(opts: IPoolControlOptions) {\n super({ scope: opts.scope ?? 'BasePoolHelper' });\n this.size = opts.size;\n this.acquireTimeoutMs = opts.acquireTimeoutMs;\n this.maxWaitingClients = opts.maxWaitingClients;\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n /** Create one resource. Required. */\n protected abstract create(): ValueOrPromise<T>;\n\n /** Validate an idle resource just before hand-out; false → destroyed + replaced. Default: always valid. */\n protected validateResource(_opts: { resource: T }): ValueOrPromise<boolean> {\n return true;\n }\n\n /** Reset an idle resource before hand-out (e.g. clear state). Throw → resource discarded. Default: no-op. */\n protected resetResource(_opts: { resource: T }): ValueOrPromise<void> {\n return undefined;\n }\n\n /** Tear down a resource being removed from the pool. Default: no-op. */\n protected onDestroyResource(_opts: { resource: T }): ValueOrPromise<void> {\n return undefined;\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n getStats(): IPoolStats {\n return {\n size: this.size,\n available: this.idle.length,\n borrowed: this.borrowed.size,\n pending: this.waiterQueue.size,\n };\n }\n\n async acquire(): Promise<T> {\n if (this.isDestroyed) {\n throw getError({ message: '[acquire] Pool has been destroyed.' });\n }\n\n if (this.maxWaitingClients !== undefined && this.maxWaitingClients >= 0) {\n // Only reject when this acquire would actually have to WAIT: no idle resource and the pool at capacity. With a free/creatable resource the caller is served, so maxWaitingClients:0 means \"serve if available, never queue\" rather than \"reject everything\".\n const isWaitRequired = !this.idle.length && this.total >= this.size;\n\n if (isWaitRequired && this.waiterQueue.size >= this.maxWaitingClients) {\n throw getError({\n message: `[acquire] Too many waiting clients (>= ${this.maxWaitingClients}).`,\n });\n }\n }\n\n const promise = new Promise<T>((resolve, reject) => {\n const waiter: IPoolWaiter<T> = { resolve, reject, timer: null };\n const node = this.waiterQueue.enqueue({ value: waiter });\n\n if (this.acquireTimeoutMs !== undefined && this.acquireTimeoutMs >= 0) {\n waiter.timer = setTimeout(() => {\n this.waiterQueue.cancel({ node }); // O(1) — dispatch skips it when reached\n\n reject(\n getError({\n message: `[acquire] Acquire timed out after ${this.acquireTimeoutMs}ms.`,\n }),\n );\n }, this.acquireTimeoutMs);\n }\n });\n\n this.safeDispatch({ action: 'acquire' });\n return promise;\n }\n\n release(opts: { resource: T }): void {\n const { resource } = opts;\n const logger = this.logger.for(this.release.name);\n\n if (!this.borrowed.has(resource)) {\n logger.warn('Called with a foreign/already-released resource; ignoring.');\n return;\n }\n this.borrowed.delete(resource);\n\n if (this.isDestroyed) {\n this.destroyResource({ resource }).catch(error => {\n logger.warn('destroyResource error on release: %s', error);\n });\n return;\n }\n\n this.idle.push(resource);\n this.safeDispatch({ action: 'release' });\n }\n\n async warmup(): Promise<void> {\n if (this.isDestroyed) {\n throw getError({ message: '[warmup] Pool has been destroyed.' });\n }\n\n // Create sequentially, re-checking the live `total` before each create so the `size` cap holds under concurrent warmup()/acquire(); createResource() bumps `total` synchronously, before its await, so a re-check observes in-flight creations from other callers - no overshoot.\n while (this.total < this.size) {\n const resource = await this.createResource();\n this.idle.push(resource);\n }\n\n this.safeDispatch({ action: 'warmup' });\n }\n\n async use<R>(opts: { execution: (resource: T) => ValueOrPromise<R> }): Promise<R> {\n const resource = await this.acquire();\n\n try {\n const result = await opts.execution(resource);\n this.release({ resource });\n return result;\n } catch (error) {\n this.logger\n .for(this.use.name)\n .error('execution threw → release skipped, force DISCARD | Error: %s', error);\n await this.discard({ resource });\n throw error;\n }\n }\n\n async discard(opts: { resource: T }): Promise<void> {\n const { resource } = opts;\n\n if (!this.borrowed.delete(resource)) {\n this.logger.for(this.discard.name).warn('Called with a non-borrowed resource; ignoring.');\n return;\n }\n\n await this.destroyResource({ resource });\n this.safeDispatch({ action: 'discard' });\n }\n\n async destroy(): Promise<void> {\n this.isDestroyed = true;\n\n const error = getError({ message: '[destroy] Pool destroyed while awaiting a resource.' });\n const draineds = this.waiterQueue.drain();\n for (const waiter of draineds) {\n this.clearWaiterTimer({ waiter });\n waiter.reject(error);\n }\n\n const toDestroy = this.idle.splice(0);\n await Promise.all(toDestroy.map(resource => this.destroyResource({ resource })));\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n private async createResource(): Promise<T> {\n this.total += 1; // bump BEFORE await so concurrent dispatch/warmup see the in-flight create (no overshoot)\n\n try {\n const resource = await this.create();\n return resource;\n } catch (error) {\n this.total -= 1;\n this.logger\n .for(this.createResource.name)\n .error('Error creating pool resource | Error: %s', error);\n throw error;\n }\n }\n\n private async destroyResource(opts: { resource: T }): Promise<void> {\n this.total -= 1;\n\n try {\n await this.onDestroyResource(opts);\n } catch (error) {\n this.logger.for(this.destroyResource.name).warn('destroy hook threw: %s', error);\n }\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n /** Fire-and-forget dispatch with logged rejection; shared by all dispatch call sites. */\n private safeDispatch(opts: { action: string }): void {\n this.dispatch().catch(error => {\n this.logger\n .for(this.dispatch.name)\n .warn('dispatch error | action: %s | Error: %s', opts.action, error);\n });\n }\n\n /** Pair servable resources with waiting acquirers until the queue drains or the pool is exhausted. Re-entrancy-guarded so only one loop runs at a time. */\n private async dispatch() {\n if (this.isDispatching) {\n return;\n }\n\n this.isDispatching = true;\n\n try {\n while (this.waiterQueue.size > 0) {\n // Prefer a warm idle resource (LIFO) over creating a new one.\n if (this.idle.length > 0) {\n const resource = await this.takeIdleResource();\n if (resource === null) {\n continue; // bad idle resource was discarded → try the next one\n }\n\n if (!this.handToWaiter({ resource })) {\n return;\n }\n continue;\n }\n\n if (this.total < this.size) {\n await this.createAndHand();\n continue;\n }\n\n return;\n }\n } catch (error) {\n this.logger\n .for(this.dispatch.name)\n .error('[dispatch] Error while dispatching pool element | Error: %s', error);\n } finally {\n this.isDispatching = false;\n }\n }\n\n /** Pop an idle resource and validate+reset it; on ANY failure destroy it and return null (caller retries). */\n private async takeIdleResource(): Promise<T | null> {\n const resource = this.idle.pop() as T;\n const logger = this.logger.for(this.takeIdleResource.name);\n\n let isValid: boolean;\n try {\n isValid = await this.validateResource({ resource });\n } catch (error) {\n // A throwing validate must NOT leak the popped candidate (it would corrupt `total` and can permanently starve the pool); treat it like an invalid resource - discard and retry.\n logger.warn('validate hook threw; discarding resource: %s', error);\n await this.destroyResource({ resource });\n return null;\n }\n\n if (!isValid) {\n await this.destroyResource({ resource });\n return null;\n }\n\n try {\n await this.resetResource({ resource });\n } catch (error) {\n logger.warn('reset hook threw; discarding resource: %s', error);\n await this.destroyResource({ resource });\n return null;\n }\n\n return resource;\n }\n\n /** Create a fresh resource and hand it to the next waiter; on create failure, reject that waiter. */\n private async createAndHand(): Promise<void> {\n let resource: T;\n try {\n resource = await this.createResource();\n } catch (error) {\n this.takeNextWaiter()?.reject(error);\n return;\n }\n\n this.handToWaiter({ resource });\n }\n\n /** Give a ready resource to the next live waiter; returns false and parks it in idle if the waiter raced away (e.g. timed out during an await). */\n private handToWaiter(opts: { resource: T }): boolean {\n const { resource } = opts;\n\n // `destroy()` tears down what it can SEE - the waiter queue and the idle list. A resource whose create() was still in flight is in neither, so parking it in idle now would leave it alive with nothing left to reclaim it.\n if (this.isDestroyed) {\n this.destroyResource({ resource }).catch(error => {\n this.logger\n .for(this.handToWaiter.name)\n .warn('destroyResource error on a resource created after destroy(): %s', error);\n });\n return false;\n }\n\n const waiter = this.takeNextWaiter();\n if (!waiter) {\n this.idle.push(resource);\n return false;\n }\n\n this.borrowed.add(resource);\n waiter.resolve(resource);\n return true;\n }\n\n /** Dequeue the next live waiter and disarm its acquire-timeout so it cannot fire after settlement. */\n private takeNextWaiter(): TNullable<IPoolWaiter<T>> {\n const waiter = this.waiterQueue.dequeue();\n if (waiter) {\n this.clearWaiterTimer({ waiter });\n }\n return waiter;\n }\n\n private clearWaiterTimer(opts: { waiter: IPoolWaiter<T> }): void {\n const { waiter } = opts;\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n waiter.timer = null;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../src/modules/pool/abstract.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,2CAA2C;AAC3C,oDAA4D;AAG5D,4SAA4S;AAC5S,MAAsB,kBAAsB,SAAQ,iBAAU;IAa5D,YAAY,IAAyB;QACnC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,gBAAgB,EAAE,CAAC,CAAC;QATlC,SAAI,GAAQ,EAAE,CAAC;QACf,aAAQ,GAAG,IAAI,GAAG,EAAK,CAAC;QACxB,gBAAW,GAAG,IAAI,kBAAa,EAAkB,CAAC;QAE3D,UAAK,GAAG,CAAC,CAAC,CAAC,kCAAkC;QAC7C,kBAAa,GAAG,KAAK,CAAC;QACtB,gBAAW,GAAG,KAAK,CAAC;QAI1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAC9C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;IAClD,CAAC;IAOD,2GAA2G;IACjG,gBAAgB,CAAC,KAAsB;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6GAA6G;IACnG,aAAa,CAAC,KAAsB;QAC5C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,wEAAwE;IAC9D,iBAAiB,CAAC,KAAsB;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,6GAA6G;IAE7G,QAAQ;QACN,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YAC3B,QAAQ,EAAE,I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MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sGAAsG;IAC9F,cAAc;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,gBAAgB,CAAC,IAAgC;QACvD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;CACF;AAvUD,gDAuUC","sourcesContent":["import { type TNullable, type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { HfQueueHelper } from '@/modules/queue/internal/hf';\nimport { type IPool, type IPoolControlOptions, type IPoolStats, type IPoolWaiter } from './common';\n\n/** Single-borrower pool skeleton: subclasses override {@link create} (required) and optionally validateResource/resetResource/onDestroyResource. All resource-waiter pairing flows through ONE re-entrancy-guarded `dispatch()` loop; the waiter queue is {@link HfQueueHelper} - O(1), no shift/splice. */\nexport abstract class AbstractPoolHelper<T> extends BaseHelper implements IPool<T> {\n protected readonly size: number;\n protected readonly acquireTimeoutMs?: number;\n protected readonly maxWaitingClients?: number;\n\n private readonly idle: T[] = [];\n private readonly borrowed = new Set<T>();\n private readonly waiterQueue = new HfQueueHelper<IPoolWaiter<T>>();\n\n private total = 0; // live or being-created resources\n private isDispatching = false;\n private isDestroyed = false;\n\n constructor(opts: IPoolControlOptions) {\n super({ scope: opts.scope ?? 'BasePoolHelper' });\n this.size = opts.size;\n this.acquireTimeoutMs = opts.acquireTimeoutMs;\n this.maxWaitingClients = opts.maxWaitingClients;\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n /** Create one resource. Required. */\n protected abstract create(): ValueOrPromise<T>;\n\n /** Validate an idle resource just before hand-out; false → destroyed + replaced. Default: always valid. */\n protected validateResource(_opts: { resource: T }): ValueOrPromise<boolean> {\n return true;\n }\n\n /** Reset an idle resource before hand-out (e.g. clear state). Throw → resource discarded. Default: no-op. */\n protected resetResource(_opts: { resource: T }): ValueOrPromise<void> {\n return undefined;\n }\n\n /** Tear down a resource being removed from the pool. Default: no-op. */\n protected onDestroyResource(_opts: { resource: T }): ValueOrPromise<void> {\n return undefined;\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n getStats(): IPoolStats {\n return {\n size: this.size,\n available: this.idle.length,\n borrowed: this.borrowed.size,\n pending: this.waiterQueue.size,\n };\n }\n\n async acquire(): Promise<T> {\n if (this.isDestroyed) {\n throw getError({ message: '[acquire] Pool has been destroyed.' });\n }\n\n if (this.maxWaitingClients !== undefined && this.maxWaitingClients >= 0) {\n // Only reject when this acquire would actually have to WAIT: no idle resource and the pool at capacity. With a free/creatable resource the caller is served, so maxWaitingClients:0 means \"serve if available, never queue\" rather than \"reject everything\".\n const isWaitRequired = !this.idle.length && this.total >= this.size;\n\n if (isWaitRequired && this.waiterQueue.size >= this.maxWaitingClients) {\n throw getError({\n message: `[acquire] Too many waiting clients (>= ${this.maxWaitingClients}).`,\n });\n }\n }\n\n const promise = new Promise<T>((resolve, reject) => {\n const waiter: IPoolWaiter<T> = { resolve, reject, timer: null };\n const node = this.waiterQueue.enqueue({ value: waiter });\n\n if (this.acquireTimeoutMs !== undefined && this.acquireTimeoutMs >= 0) {\n waiter.timer = setTimeout(() => {\n this.waiterQueue.cancel({ node }); // O(1) — dispatch skips it when reached\n\n reject(\n getError({\n message: `[acquire] Acquire timed out after ${this.acquireTimeoutMs}ms.`,\n }),\n );\n }, this.acquireTimeoutMs);\n }\n });\n\n this.safeDispatch({ action: 'acquire' });\n return promise;\n }\n\n release(opts: { resource: T }): void {\n const { resource } = opts;\n const logger = this.logger.for(this.release.name);\n\n if (!this.borrowed.has(resource)) {\n logger.warn('Called with a foreign/already-released resource; ignoring.');\n return;\n }\n this.borrowed.delete(resource);\n\n if (this.isDestroyed) {\n this.destroyResource({ resource }).catch((error) => {\n logger.warn('destroyResource error on release: %s', error);\n });\n return;\n }\n\n this.idle.push(resource);\n this.safeDispatch({ action: 'release' });\n }\n\n async warmup(): Promise<void> {\n if (this.isDestroyed) {\n throw getError({ message: '[warmup] Pool has been destroyed.' });\n }\n\n // Create sequentially, re-checking the live `total` before each create so the `size` cap holds under concurrent warmup()/acquire(); createResource() bumps `total` synchronously, before its await, so a re-check observes in-flight creations from other callers - no overshoot.\n while (this.total < this.size) {\n const resource = await this.createResource();\n this.idle.push(resource);\n }\n\n this.safeDispatch({ action: 'warmup' });\n }\n\n async use<R>(opts: { execution: (resource: T) => ValueOrPromise<R> }): Promise<R> {\n const resource = await this.acquire();\n\n try {\n const result = await opts.execution(resource);\n this.release({ resource });\n return result;\n } catch (error) {\n this.logger\n .for(this.use.name)\n .error('execution threw → release skipped, force DISCARD | Error: %s', error);\n await this.discard({ resource });\n throw error;\n }\n }\n\n async discard(opts: { resource: T }): Promise<void> {\n const { resource } = opts;\n\n if (!this.borrowed.delete(resource)) {\n this.logger.for(this.discard.name).warn('Called with a non-borrowed resource; ignoring.');\n return;\n }\n\n await this.destroyResource({ resource });\n this.safeDispatch({ action: 'discard' });\n }\n\n async destroy(): Promise<void> {\n this.isDestroyed = true;\n\n const error = getError({ message: '[destroy] Pool destroyed while awaiting a resource.' });\n const draineds = this.waiterQueue.drain();\n for (const waiter of draineds) {\n this.clearWaiterTimer({ waiter });\n waiter.reject(error);\n }\n\n const toDestroy = this.idle.splice(0);\n await Promise.all(toDestroy.map((resource) => this.destroyResource({ resource })));\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n private async createResource(): Promise<T> {\n this.total += 1; // bump BEFORE await so concurrent dispatch/warmup see the in-flight create (no overshoot)\n\n try {\n const resource = await this.create();\n return resource;\n } catch (error) {\n this.total -= 1;\n this.logger\n .for(this.createResource.name)\n .error('Error creating pool resource | Error: %s', error);\n throw error;\n }\n }\n\n private async destroyResource(opts: { resource: T }): Promise<void> {\n this.total -= 1;\n\n try {\n await this.onDestroyResource(opts);\n } catch (error) {\n this.logger.for(this.destroyResource.name).warn('destroy hook threw: %s', error);\n }\n }\n\n // ----------------------------------------------------------------------------------------------------------\n\n /** Fire-and-forget dispatch with logged rejection; shared by all dispatch call sites. */\n private safeDispatch(opts: { action: string }): void {\n this.dispatch().catch((error) => {\n this.logger\n .for(this.dispatch.name)\n .warn('dispatch error | action: %s | Error: %s', opts.action, error);\n });\n }\n\n /** Pair servable resources with waiting acquirers until the queue drains or the pool is exhausted. Re-entrancy-guarded so only one loop runs at a time. */\n private async dispatch() {\n if (this.isDispatching) {\n return;\n }\n\n this.isDispatching = true;\n\n try {\n while (this.waiterQueue.size > 0) {\n // Prefer a warm idle resource (LIFO) over creating a new one.\n if (this.idle.length > 0) {\n const resource = await this.takeIdleResource();\n if (resource === null) {\n continue; // bad idle resource was discarded → try the next one\n }\n\n if (!this.handToWaiter({ resource })) {\n return;\n }\n continue;\n }\n\n if (this.total < this.size) {\n await this.createAndHand();\n continue;\n }\n\n return;\n }\n } catch (error) {\n this.logger\n .for(this.dispatch.name)\n .error('[dispatch] Error while dispatching pool element | Error: %s', error);\n } finally {\n this.isDispatching = false;\n }\n }\n\n /** Pop an idle resource and validate+reset it; on ANY failure destroy it and return null (caller retries). */\n private async takeIdleResource(): Promise<T | null> {\n const resource = this.idle.pop() as T;\n const logger = this.logger.for(this.takeIdleResource.name);\n\n let isValid: boolean;\n try {\n isValid = await this.validateResource({ resource });\n } catch (error) {\n // A throwing validate must NOT leak the popped candidate (it would corrupt `total` and can permanently starve the pool); treat it like an invalid resource - discard and retry.\n logger.warn('validate hook threw; discarding resource: %s', error);\n await this.destroyResource({ resource });\n return null;\n }\n\n if (!isValid) {\n await this.destroyResource({ resource });\n return null;\n }\n\n try {\n await this.resetResource({ resource });\n } catch (error) {\n logger.warn('reset hook threw; discarding resource: %s', error);\n await this.destroyResource({ resource });\n return null;\n }\n\n return resource;\n }\n\n /** Create a fresh resource and hand it to the next waiter; on create failure, reject that waiter. */\n private async createAndHand(): Promise<void> {\n let resource: T;\n try {\n resource = await this.createResource();\n } catch (error) {\n this.takeNextWaiter()?.reject(error);\n return;\n }\n\n this.handToWaiter({ resource });\n }\n\n /** Give a ready resource to the next live waiter; returns false and parks it in idle if the waiter raced away (e.g. timed out during an await). */\n private handToWaiter(opts: { resource: T }): boolean {\n const { resource } = opts;\n\n // `destroy()` tears down what it can SEE - the waiter queue and the idle list. A resource whose create() was still in flight is in neither, so parking it in idle now would leave it alive with nothing left to reclaim it.\n if (this.isDestroyed) {\n this.destroyResource({ resource }).catch((error) => {\n this.logger\n .for(this.handToWaiter.name)\n .warn('destroyResource error on a resource created after destroy(): %s', error);\n });\n return false;\n }\n\n const waiter = this.takeNextWaiter();\n if (!waiter) {\n this.idle.push(resource);\n return false;\n }\n\n this.borrowed.add(resource);\n waiter.resolve(resource);\n return true;\n }\n\n /** Dequeue the next live waiter and disarm its acquire-timeout so it cannot fire after settlement. */\n private takeNextWaiter(): TNullable<IPoolWaiter<T>> {\n const waiter = this.waiterQueue.dequeue();\n if (waiter) {\n this.clearWaiterTimer({ waiter });\n }\n return waiter;\n }\n\n private clearWaiterTimer(opts: { waiter: IPoolWaiter<T> }): void {\n const { waiter } = opts;\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n waiter.timer = null;\n }\n }\n}\n"]}
|
|
@@ -52,7 +52,7 @@ class BullMQHelper extends base_1.BaseHelper {
|
|
|
52
52
|
const queueName = this.resolveQueueName();
|
|
53
53
|
this.queue = this.buildQueue({ queueName });
|
|
54
54
|
// An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.
|
|
55
|
-
this.queue.on('error', error => {
|
|
55
|
+
this.queue.on('error', (error) => {
|
|
56
56
|
this.logger
|
|
57
57
|
.for('queue-error')
|
|
58
58
|
.error('queue: %s | Queue error! Error: %s | ID: %s', this.queueName, error, this.identifier);
|
|
@@ -135,7 +135,7 @@ class BullMQHelper extends base_1.BaseHelper {
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
// An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.
|
|
138
|
-
this.worker.on('error', error => {
|
|
138
|
+
this.worker.on('error', (error) => {
|
|
139
139
|
this.logger
|
|
140
140
|
.for('worker-error')
|
|
141
141
|
.error('queue: %s | Worker error! Error: %s | ID: %s', this.queueName, error, this.identifier);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/queue/bullmq/helper.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,2CAA2C;AAE3C,iEAAsD;AACtD,+DAA2D;AAE3D,sCAA4D;AA2B5D,MAAa,YAAsD,SAAQ,iBAAU;IA0BnF,YAAY,OAAoD;QAC9D,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAnB5D,mBAAc,GAAG,CAAC,CAAC;QACnB,iBAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAmBtC,MAAM,EACJ,SAAS,EACT,eAAe,EACf,IAAI,EACJ,cAAc,GAAG,CAAC,EAClB,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAC7B,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,MAAM,GACP,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;QAE3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;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CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAA,gBAAQ,EAAC;gBACb,OAAO,EAAE,WAAW,IAAI,CAAC,UAAU,6CAA6C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;aACvG,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;aACpB,IAAI,CAAC,4CAA4C,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;CACF;AA/RD,oCA+RC","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper } from '@/modules/redis';\nimport { toError } from '@/utilities/promise.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { invokeHook, type TBullQueueRole } from '../common';\n\nexport interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {\n queueName: string;\n identifier: string;\n role: TBullQueueRole;\n redisConnection: IRedisHelper;\n\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. Omitted, it is loaded when a queue or worker is built. */\n module?: typeof import('bullmq');\n\n numberOfWorker?: number;\n lockDuration?: number;\n\n /** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */\n queueOptions?: Omit<QueueOptions, 'connection'>;\n /** Merged under the fields the helper owns (`connection`, `concurrency`, `lockDuration`) - see `workerOptionsFor`. */\n workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: any) => Promise<void>;\n onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n}\n\nexport class BullMQHelper<TQueueElement = any, TQueueResult = any> extends BaseHelper {\n protected queueName: string;\n protected role: TBullQueueRole;\n protected redisConnection: IRedisHelper;\n\n queue: Queue<TQueueElement, TQueueResult>;\n worker: Worker<TQueueElement, TQueueResult>;\n\n protected numberOfWorker = 1;\n protected lockDuration = 90 * 60 * 1000;\n\n protected queueOptions?: Omit<QueueOptions, 'connection'>;\n protected workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n protected onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: any,\n ) => Promise<void>;\n protected onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n\n private readonly bullmqModule?: typeof import('bullmq');\n\n constructor(options: IBullMQOptions<TQueueElement, TQueueResult>) {\n super({ scope: BullMQHelper.name, identifier: options.identifier });\n const {\n queueName,\n redisConnection,\n role,\n numberOfWorker = 1,\n lockDuration = 90 * 60 * 1000,\n queueOptions,\n workerOptions,\n onWorkerData,\n onWorkerDataCompleted,\n onWorkerDataFail,\n module,\n } = options;\n\n this.bullmqModule = module;\n\n this.queueName = queueName;\n this.role = role;\n this.redisConnection = redisConnection;\n\n this.numberOfWorker = numberOfWorker;\n this.lockDuration = lockDuration;\n\n this.queueOptions = queueOptions;\n this.workerOptions = workerOptions;\n\n this.onWorkerData = onWorkerData;\n this.onWorkerDataCompleted = onWorkerDataCompleted;\n this.onWorkerDataFail = onWorkerDataFail;\n\n this.configure();\n }\n\n static newInstance<T = any, R = any>(opts: IBullMQOptions<T, R>) {\n return new BullMQHelper<T, R>(opts);\n }\n\n /** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */\n protected isClusterClient(): boolean {\n const client = Object(this.redisConnection.getClient());\n\n if (Reflect.get(client, 'isCluster') === true) {\n return true;\n }\n\n return typeof Reflect.get(client, 'nodes') === 'function';\n }\n\n protected resolveQueueName(): string {\n if (this.isClusterClient() && !this.queueName.startsWith('{')) {\n return `{${this.queueName}}`;\n }\n\n return this.queueName;\n }\n\n configureQueue() {\n if (!this.queueName) {\n this.logger\n .for(this.configureQueue.name)\n .error('Invalid queue name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.queue = this.buildQueue({ queueName });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.queue.on('error', error => {\n this.logger\n .for('queue-error')\n .error(\n 'queue: %s | Queue error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n /** Full `Queue` options: framework defaults, then `this.queueOptions`, then the connection the helper owns - in that precedence order. */\n protected queueOptionsFor(opts: { queueName: string }): QueueOptions {\n this.logger\n .for(this.queueOptionsFor.name)\n .debug('Building queue options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n defaultJobOptions: {\n removeOnComplete: true,\n removeOnFail: true,\n },\n ...this.queueOptions,\n connection: this.redisConnection.duplicateClient(),\n };\n }\n\n /** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */\n protected workerOptionsFor(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): WorkerOptions {\n this.logger\n .for(this.workerOptionsFor.name)\n .debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n ...this.workerOptions,\n connection: this.redisConnection.duplicateClient(),\n concurrency: this.numberOfWorker,\n lockDuration: this.lockDuration,\n };\n }\n\n /** `bullmq` is an optional peer: loaded when a queue or worker is built, not when this module is. */\n private loadBullMQ(): typeof import('bullmq') {\n return (\n this.bullmqModule ?? ModuleUtility.loadSync<typeof import('bullmq')>({ module: 'bullmq' })\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildQueue(opts: { queueName: string }): Queue<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Queue<TQueueElement, TQueueResult>(\n opts.queueName,\n this.queueOptionsFor(opts),\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildWorker(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): Worker<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Worker<TQueueElement, TQueueResult>(\n opts.queueName,\n opts.processor,\n this.workerOptionsFor(opts),\n );\n }\n\n configureWorker() {\n if (!this.queueName) {\n this.logger\n .for(this.configureWorker.name)\n .error('Invalid worker name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.worker = this.buildWorker({\n queueName,\n processor: async job => {\n if (this.onWorkerData) {\n const result = await this.onWorkerData(job);\n return result;\n }\n\n const { id, name, data } = job;\n this.logger\n .for('onWorkerData')\n .info(\n 'queue: %s | id: %s | name: %s | data: %j | ID: %s',\n this.queueName,\n id,\n name,\n data,\n this.identifier,\n );\n\n return undefined as TQueueResult;\n },\n });\n\n this.worker.on('completed', (job, result) => {\n invokeHook({\n logger: this.logger,\n scope: 'worker-completed',\n execution: () => this.onWorkerDataCompleted?.(job, result),\n });\n });\n\n this.worker.on('failed', (job, reason) => {\n invokeHook({\n logger: this.logger,\n scope: 'worker-failed',\n execution: () => this.onWorkerDataFail?.(job, reason),\n });\n });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.worker.on('error', error => {\n this.logger\n .for('worker-error')\n .error(\n 'queue: %s | Worker error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n configure() {\n if (!this.role) {\n this.logger\n .for(this.configure.name)\n .error(\n 'Invalid client role to configure | Valid roles: [queue|worker] | ID: %s',\n this.identifier,\n );\n return;\n }\n\n switch (this.role) {\n case 'queue': {\n this.configureQueue();\n break;\n }\n case 'worker': {\n this.configureWorker();\n break;\n }\n }\n }\n\n async close() {\n const failures: string[] = [];\n\n // Both connections must be released even when the first close fails - otherwise a failing worker close silently leaks the queue's Redis connection forever.\n try {\n await this.worker?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ worker: %s | ID: %s', error, this.identifier);\n failures.push(toError(error).message);\n }\n\n try {\n await this.queue?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);\n failures.push(toError(error).message);\n }\n\n if (failures.length) {\n throw getError({\n message: `[close][${this.identifier}] Failed to close BullMQ helper | Errors: ${failures.join(' | ')}`,\n });\n }\n\n this.logger\n .for(this.close.name)\n .info('BullMQ helper closed successfully | ID: %s', this.identifier);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/queue/bullmq/helper.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,2CAA2C;AAE3C,iEAAsD;AACtD,+DAA2D;AAE3D,sCAA4D;AA2B5D,MAAa,YAAsD,SAAQ,iBAAU;IA0BnF,YAAY,OAAoD;QAC9D,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAnB5D,mBAAc,GAAG,CAAC,CAAC;QACnB,iBAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAmBtC,MAAM,EACJ,SAAS,EACT,eAAe,EACf,IAAI,EACJ,cAAc,GAAG,CAAC,EAClB,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAC7B,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,MAAM,GACP,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;QAE3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAE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,EAAE,CAAC;YACpB,MAAM,IAAA,gBAAQ,EAAC;gBACb,OAAO,EAAE,WAAW,IAAI,CAAC,UAAU,6CAA6C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;aACvG,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;aACpB,IAAI,CAAC,4CAA4C,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;CACF;AA/RD,oCA+RC","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper } from '@/modules/redis';\nimport { toError } from '@/utilities/promise.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { invokeHook, type TBullQueueRole } from '../common';\n\nexport interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {\n queueName: string;\n identifier: string;\n role: TBullQueueRole;\n redisConnection: IRedisHelper;\n\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. Omitted, it is loaded when a queue or worker is built. */\n module?: typeof import('bullmq');\n\n numberOfWorker?: number;\n lockDuration?: number;\n\n /** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */\n queueOptions?: Omit<QueueOptions, 'connection'>;\n /** Merged under the fields the helper owns (`connection`, `concurrency`, `lockDuration`) - see `workerOptionsFor`. */\n workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: any) => Promise<void>;\n onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n}\n\nexport class BullMQHelper<TQueueElement = any, TQueueResult = any> extends BaseHelper {\n protected queueName: string;\n protected role: TBullQueueRole;\n protected redisConnection: IRedisHelper;\n\n queue: Queue<TQueueElement, TQueueResult>;\n worker: Worker<TQueueElement, TQueueResult>;\n\n protected numberOfWorker = 1;\n protected lockDuration = 90 * 60 * 1000;\n\n protected queueOptions?: Omit<QueueOptions, 'connection'>;\n protected workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n protected onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: any,\n ) => Promise<void>;\n protected onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n\n private readonly bullmqModule?: typeof import('bullmq');\n\n constructor(options: IBullMQOptions<TQueueElement, TQueueResult>) {\n super({ scope: BullMQHelper.name, identifier: options.identifier });\n const {\n queueName,\n redisConnection,\n role,\n numberOfWorker = 1,\n lockDuration = 90 * 60 * 1000,\n queueOptions,\n workerOptions,\n onWorkerData,\n onWorkerDataCompleted,\n onWorkerDataFail,\n module,\n } = options;\n\n this.bullmqModule = module;\n\n this.queueName = queueName;\n this.role = role;\n this.redisConnection = redisConnection;\n\n this.numberOfWorker = numberOfWorker;\n this.lockDuration = lockDuration;\n\n this.queueOptions = queueOptions;\n this.workerOptions = workerOptions;\n\n this.onWorkerData = onWorkerData;\n this.onWorkerDataCompleted = onWorkerDataCompleted;\n this.onWorkerDataFail = onWorkerDataFail;\n\n this.configure();\n }\n\n static newInstance<T = any, R = any>(opts: IBullMQOptions<T, R>) {\n return new BullMQHelper<T, R>(opts);\n }\n\n /** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */\n protected isClusterClient(): boolean {\n const client = Object(this.redisConnection.getClient());\n\n if (Reflect.get(client, 'isCluster') === true) {\n return true;\n }\n\n return typeof Reflect.get(client, 'nodes') === 'function';\n }\n\n protected resolveQueueName(): string {\n if (this.isClusterClient() && !this.queueName.startsWith('{')) {\n return `{${this.queueName}}`;\n }\n\n return this.queueName;\n }\n\n configureQueue() {\n if (!this.queueName) {\n this.logger\n .for(this.configureQueue.name)\n .error('Invalid queue name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.queue = this.buildQueue({ queueName });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.queue.on('error', (error) => {\n this.logger\n .for('queue-error')\n .error(\n 'queue: %s | Queue error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n /** Full `Queue` options: framework defaults, then `this.queueOptions`, then the connection the helper owns - in that precedence order. */\n protected queueOptionsFor(opts: { queueName: string }): QueueOptions {\n this.logger\n .for(this.queueOptionsFor.name)\n .debug('Building queue options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n defaultJobOptions: {\n removeOnComplete: true,\n removeOnFail: true,\n },\n ...this.queueOptions,\n connection: this.redisConnection.duplicateClient(),\n };\n }\n\n /** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */\n protected workerOptionsFor(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): WorkerOptions {\n this.logger\n .for(this.workerOptionsFor.name)\n .debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n ...this.workerOptions,\n connection: this.redisConnection.duplicateClient(),\n concurrency: this.numberOfWorker,\n lockDuration: this.lockDuration,\n };\n }\n\n /** `bullmq` is an optional peer: loaded when a queue or worker is built, not when this module is. */\n private loadBullMQ(): typeof import('bullmq') {\n return (\n this.bullmqModule ?? ModuleUtility.loadSync<typeof import('bullmq')>({ module: 'bullmq' })\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildQueue(opts: { queueName: string }): Queue<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Queue<TQueueElement, TQueueResult>(\n opts.queueName,\n this.queueOptionsFor(opts),\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildWorker(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): Worker<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Worker<TQueueElement, TQueueResult>(\n opts.queueName,\n opts.processor,\n this.workerOptionsFor(opts),\n );\n }\n\n configureWorker() {\n if (!this.queueName) {\n this.logger\n .for(this.configureWorker.name)\n .error('Invalid worker name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.worker = this.buildWorker({\n queueName,\n processor: async (job) => {\n if (this.onWorkerData) {\n const result = await this.onWorkerData(job);\n return result;\n }\n\n const { id, name, data } = job;\n this.logger\n .for('onWorkerData')\n .info(\n 'queue: %s | id: %s | name: %s | data: %j | ID: %s',\n this.queueName,\n id,\n name,\n data,\n this.identifier,\n );\n\n return undefined as TQueueResult;\n },\n });\n\n this.worker.on('completed', (job, result) => {\n invokeHook({\n logger: this.logger,\n scope: 'worker-completed',\n execution: () => this.onWorkerDataCompleted?.(job, result),\n });\n });\n\n this.worker.on('failed', (job, reason) => {\n invokeHook({\n logger: this.logger,\n scope: 'worker-failed',\n execution: () => this.onWorkerDataFail?.(job, reason),\n });\n });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.worker.on('error', (error) => {\n this.logger\n .for('worker-error')\n .error(\n 'queue: %s | Worker error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n configure() {\n if (!this.role) {\n this.logger\n .for(this.configure.name)\n .error(\n 'Invalid client role to configure | Valid roles: [queue|worker] | ID: %s',\n this.identifier,\n );\n return;\n }\n\n switch (this.role) {\n case 'queue': {\n this.configureQueue();\n break;\n }\n case 'worker': {\n this.configureWorker();\n break;\n }\n }\n }\n\n async close() {\n const failures: string[] = [];\n\n // Both connections must be released even when the first close fails - otherwise a failing worker close silently leaks the queue's Redis connection forever.\n try {\n await this.worker?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ worker: %s | ID: %s', error, this.identifier);\n failures.push(toError(error).message);\n }\n\n try {\n await this.queue?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);\n failures.push(toError(error).message);\n }\n\n if (failures.length) {\n throw getError({\n message: `[close][${this.identifier}] Failed to close BullMQ helper | Errors: ${failures.join(' | ')}`,\n });\n }\n\n this.logger\n .for(this.close.name)\n .info('BullMQ helper closed successfully | ID: %s', this.identifier);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformatic-require.plugin.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-require.plugin.ts"],"names":[],"mappings":";;;AACA,qCAAkF;AAElF,waAAwa;AACja,MAAM,yBAAyB,GAAG,GAAc,EAAE,CAAC,CAAC;IACzD,IAAI,EAAE,gCAAuB,CAAC,oBAAoB;IAClD,KAAK,CAAC,KAAK;QACT,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,sCAA6B,CAAC,aAAa,EAAE,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"platformatic-require.plugin.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-require.plugin.ts"],"names":[],"mappings":";;;AACA,qCAAkF;AAElF,waAAwa;AACja,MAAM,yBAAyB,GAAG,GAAc,EAAE,CAAC,CAAC;IACzD,IAAI,EAAE,gCAAuB,CAAC,oBAAoB;IAClD,KAAK,CAAC,KAAK;QACT,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,sCAA6B,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACnF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;YAChD,MAAM,OAAO,GAAa,EAAE,CAAC;YAE7B,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAC7B,sCAA6B,CAAC,eAAe,EAC7C,CAAC,OAAO,EAAE,OAAe,EAAE,MAAc,EAAE,SAAiB,EAAE,EAAE;gBAC9D,IAAI,sCAA6B,CAAC,kBAAkB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;oBACzE,OAAO,OAAO,CAAC;gBACjB,CAAC;gBAED,MAAM,KAAK,GAAG,GAAG,sCAA6B,CAAC,mBAAmB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;gBACtF,OAAO,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBAEnE,uFAAuF;gBACvF,wFAAwF;gBACxF,8EAA8E;gBAC9E,OAAO,SAAS,OAAO,MAAM,KAAK,GAAG,CAAC;YACxC,CAAC,CACF,CAAC;YAEF,kFAAkF;YAClF,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAhCU,QAAA,yBAAyB,6BAgCnC","sourcesContent":["import type { BunPlugin } from 'bun';\nimport { KafkaBundlerPluginNames, PlatformaticRequireSpecifiers } from './common';\n\n/** `@platformatic/kafka` 2.8-2.9 resolves some dependencies through `createRequire(import.meta.url)` at module scope; `bun build --compile` cannot see through that, so the specifier stays unresolved and the binary dies with \"Cannot find package\" before boot - this plugin hoists those calls to static imports at bundle time. 2.10 removed the module-scope require(), so on >= 2.10 the plugin matches nothing and is inert. */\nexport const platformaticRequirePlugin = (): BunPlugin => ({\n name: KafkaBundlerPluginNames.PLATFORMATIC_REQUIRE,\n setup(build) {\n build.onLoad({ filter: PlatformaticRequireSpecifiers.MODULE_FILTER }, async (args) => {\n const source = await Bun.file(args.path).text();\n const imports: string[] = [];\n\n const contents = source.replace(\n PlatformaticRequireSpecifiers.REQUIRE_PATTERN,\n (matched, binding: string, _quote: string, specifier: string) => {\n if (PlatformaticRequireSpecifiers.SKIPPED_SPECIFIERS.includes(specifier)) {\n return matched;\n }\n\n const alias = `${PlatformaticRequireSpecifiers.IMPORT_ALIAS_PREFIX}${imports.length}`;\n imports.push(`import ${alias} from ${JSON.stringify(specifier)};`);\n\n // No `?.default` unwrap: a default import already yields `module.exports` for CJS, and\n // unwrapping would break JSON payloads carrying their own top-level `default` key - the\n // draft-06 meta schema has one, so unwrapping silently replaces it with `{}`.\n return `const ${binding} = ${alias};`;\n },\n );\n\n // No match is not an error: upstream fixing this makes the plugin an inert no-op.\n if (!imports.length) {\n return undefined;\n }\n\n return { contents: `${imports.join('\\n')}\\n${contents}`, loader: 'js' };\n });\n },\n});\n"]}
|
|
@@ -8,7 +8,7 @@ const common_1 = require("./common");
|
|
|
8
8
|
const platformaticWasmPlugin = () => ({
|
|
9
9
|
name: common_1.KafkaBundlerPluginNames.PLATFORMATIC_WASM,
|
|
10
10
|
setup(build) {
|
|
11
|
-
build.onResolve({ filter: common_1.PlatformaticWasmSpecifiers.ENTRYPOINT_FILTER }, args => {
|
|
11
|
+
build.onResolve({ filter: common_1.PlatformaticWasmSpecifiers.ENTRYPOINT_FILTER }, (args) => {
|
|
12
12
|
try {
|
|
13
13
|
return {
|
|
14
14
|
path: Bun.resolveSync(common_1.PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT, (0, node_path_1.dirname)(args.importer)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformatic-wasm.plugin.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-wasm.plugin.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE3C,yCAAoC;AACpC,qCAA+E;AAE/E,8RAA8R;AACvR,MAAM,sBAAsB,GAAG,GAAc,EAAE,CAAC,CAAC;IACtD,IAAI,EAAE,gCAAuB,CAAC,iBAAiB;IAC/C,KAAK,CAAC,KAAK;QACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,mCAA0B,CAAC,iBAAiB,EAAE,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"platformatic-wasm.plugin.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-wasm.plugin.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE3C,yCAAoC;AACpC,qCAA+E;AAE/E,8RAA8R;AACvR,MAAM,sBAAsB,GAAG,GAAc,EAAE,CAAC,CAAC;IACtD,IAAI,EAAE,gCAAuB,CAAC,iBAAiB;IAC/C,KAAK,CAAC,KAAK;QACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,mCAA0B,CAAC,iBAAiB,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;YACjF,IAAI,CAAC;gBACH,OAAO;oBACL,IAAI,EAAE,GAAG,CAAC,WAAW,CACnB,mCAA0B,CAAC,kBAAkB,EAC7C,IAAA,mBAAO,EAAC,IAAI,CAAC,QAAQ,CAAC,CACvB;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAA,gBAAQ,EAAC;oBACb,OAAO,EAAE;wBACP,8CAA8C,mCAA0B,CAAC,kBAAkB,EAAE;wBAC7F,QAAQ,IAAI,CAAC,QAAQ,EAAE;wBACvB,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;qBACrE,CAAC,IAAI,CAAC,GAAG,CAAC;iBACZ,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAtBU,QAAA,sBAAsB,0BAsBhC","sourcesContent":["import { getError } from '@/modules/error';\nimport type { BunPlugin } from 'bun';\nimport { dirname } from 'node:path';\nimport { KafkaBundlerPluginNames, PlatformaticWasmSpecifiers } from './common';\n\n/** `@platformatic/wasm-utils`'s default entrypoint reads `native.wasm` from disk at module load and `bun build --compile` embeds JS only, so it resolves against `/$bunfs` and the binary dies with ENOENT - this plugin redirects the import to the `/bundled` entrypoint (wasm inlined). */\nexport const platformaticWasmPlugin = (): BunPlugin => ({\n name: KafkaBundlerPluginNames.PLATFORMATIC_WASM,\n setup(build) {\n build.onResolve({ filter: PlatformaticWasmSpecifiers.ENTRYPOINT_FILTER }, (args) => {\n try {\n return {\n path: Bun.resolveSync(\n PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT,\n dirname(args.importer),\n ),\n };\n } catch (error) {\n throw getError({\n message: [\n `[platformaticWasmPlugin] Failed to resolve ${PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT}`,\n `from ${args.importer}`,\n `| Error: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n });\n },\n});\n"]}
|
|
@@ -329,7 +329,7 @@ class KafkaConsumerHelper extends base_1.BaseKafkaHelper {
|
|
|
329
329
|
this.logger.warn('[rebuildClient] Failed to restart lag monitoring on new client | Error: %s', (0, promise_utility_1.toError)(error).message);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
this.closeOldClient(oldClient).catch(error => {
|
|
332
|
+
this.closeOldClient(oldClient).catch((error) => {
|
|
333
333
|
this.logger.warn('[rebuildClient] background close of old client failed (ignored) | Error: %s', (0, promise_utility_1.toError)(error).message);
|
|
334
334
|
});
|
|
335
335
|
}
|
|
@@ -347,7 +347,7 @@ class KafkaConsumerHelper extends base_1.BaseKafkaHelper {
|
|
|
347
347
|
}
|
|
348
348
|
});
|
|
349
349
|
}),
|
|
350
|
-
new Promise(resolve => {
|
|
350
|
+
new Promise((resolve) => {
|
|
351
351
|
timeoutHandle = setTimeout(resolve, this.shutdownTimeout);
|
|
352
352
|
}),
|
|
353
353
|
]);
|