@venizia/ignis-helpers 0.4.8-0 → 0.4.8-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/README.md +1 -0
- package/dist/esm/common/constants/app.d.ts +15 -0
- package/dist/esm/common/constants/app.js +14 -0
- package/dist/esm/common/constants/app.js.map +1 -1
- package/dist/esm/common/constants/duration.d.ts +2 -0
- package/dist/esm/common/constants/duration.js.map +1 -1
- package/dist/esm/common/constants/grpc.d.ts +3 -0
- package/dist/esm/common/constants/grpc.js +1 -0
- package/dist/esm/common/constants/grpc.js.map +1 -1
- package/dist/esm/common/constants/http.d.ts +4 -0
- package/dist/esm/common/constants/http.js +1 -0
- package/dist/esm/common/constants/http.js.map +1 -1
- package/dist/esm/common/constants/mime.d.ts +4 -0
- package/dist/esm/common/constants/mime.js +1 -0
- package/dist/esm/common/constants/mime.js.map +1 -1
- package/dist/esm/common/redact.d.ts +2 -0
- package/dist/esm/common/redact.js +2 -0
- package/dist/esm/common/redact.js.map +1 -1
- package/dist/esm/common/resolvers.d.ts +1 -0
- package/dist/esm/common/resolvers.js +1 -0
- package/dist/esm/common/resolvers.js.map +1 -1
- package/dist/esm/common/types/class.d.ts +6 -0
- package/dist/esm/common/types/class.js.map +1 -1
- package/dist/esm/common/types/const-value.d.ts +3 -0
- package/dist/esm/common/types/const-value.js.map +1 -1
- package/dist/esm/common/types/field-mapping.d.ts +3 -0
- package/dist/esm/common/types/field-mapping.js.map +1 -1
- package/dist/esm/common/types/injection.d.ts +2 -0
- package/dist/esm/common/types/injection.js.map +1 -1
- package/dist/esm/common/types/utility.d.ts +9 -0
- package/dist/esm/common/types/utility.js.map +1 -1
- package/dist/esm/modules/base.d.ts +1 -0
- package/dist/esm/modules/base.js +1 -0
- package/dist/esm/modules/base.js.map +1 -1
- package/dist/esm/modules/cron/helper.d.ts +7 -0
- package/dist/esm/modules/cron/helper.js +1 -0
- package/dist/esm/modules/cron/helper.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts +2 -0
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/base.algorithm.d.ts +1 -0
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js +1 -0
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts +12 -4
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js +4 -4
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts +3 -0
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts +1 -0
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/common/constants.d.ts +12 -1
- package/dist/esm/modules/crypto/common/constants.js +9 -1
- package/dist/esm/modules/crypto/common/constants.js.map +1 -1
- package/dist/esm/modules/crypto/common/types.d.ts +1 -0
- package/dist/esm/modules/crypto/common/types.js.map +1 -1
- package/dist/esm/modules/env/app-env.d.ts +3 -0
- package/dist/esm/modules/env/app-env.js +3 -0
- package/dist/esm/modules/env/app-env.js.map +1 -1
- package/dist/esm/modules/env/common/types.d.ts +1 -0
- package/dist/esm/modules/env/common/types.js.map +1 -1
- package/dist/esm/modules/logger/common/constants.d.ts +3 -0
- package/dist/esm/modules/logger/common/constants.js +2 -0
- package/dist/esm/modules/logger/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/common/types.d.ts +2 -0
- package/dist/esm/modules/logger/common/types.js +1 -0
- package/dist/esm/modules/logger/common/types.js.map +1 -1
- package/dist/esm/modules/logger/formatting/deep-splat.d.ts +1 -0
- package/dist/esm/modules/logger/formatting/deep-splat.js +1 -0
- package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
- package/dist/esm/modules/logger/hf/common/types.d.ts +7 -2
- package/dist/esm/modules/logger/hf/common/types.js.map +1 -1
- package/dist/esm/modules/logger/winston/common/types.d.ts +31 -3
- package/dist/esm/modules/logger/winston/common/types.js.map +1 -1
- package/dist/esm/modules/logger/winston/define.d.ts +1 -0
- package/dist/esm/modules/logger/winston/define.js +1 -0
- package/dist/esm/modules/logger/winston/define.js.map +1 -1
- package/dist/esm/modules/logger/winston/logger.d.ts +1 -0
- package/dist/esm/modules/logger/winston/logger.js +1 -0
- package/dist/esm/modules/logger/winston/logger.js.map +1 -1
- package/dist/esm/modules/logger/winston/transports/dgram.transport.d.ts +1 -0
- package/dist/esm/modules/logger/winston/transports/dgram.transport.js +1 -0
- package/dist/esm/modules/logger/winston/transports/dgram.transport.js.map +1 -1
- package/dist/esm/modules/network/http-request/base-network-request.helper.d.ts +1 -0
- package/dist/esm/modules/network/http-request/base-network-request.helper.js +1 -0
- package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts +8 -8
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +2 -0
- 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 +2 -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 +5 -1
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +2 -0
- 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.d.ts +11 -0
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +1 -0
- 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 +3 -0
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +1 -0
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.d.ts +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.js +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.d.ts +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.js +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.d.ts +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.js +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.d.ts +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.js +1 -0
- package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/network/udp-socket/network-udp-client.helper.d.ts +4 -0
- package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +4 -0
- 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 +13 -2
- package/dist/esm/modules/network/utilities/query-string.js +2 -1
- package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts +2 -1
- package/dist/esm/modules/network/utilities/url-safety/common/constants.js +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/constants.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/types.d.ts +18 -5
- package/dist/esm/modules/network/utilities/url-safety/common/types.js.map +1 -1
- package/dist/esm/modules/pool/common/types.d.ts +5 -1
- package/dist/esm/modules/pool/common/types.js.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.d.ts +13 -0
- package/dist/esm/modules/queue/bullmq/helper.js +4 -0
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/queue/common/hook.d.ts +1 -0
- package/dist/esm/modules/queue/common/hook.js +1 -0
- package/dist/esm/modules/queue/common/hook.js.map +1 -1
- package/dist/esm/modules/queue/internal/sequential/common/types.d.ts +8 -0
- package/dist/esm/modules/queue/internal/sequential/common/types.js +1 -0
- package/dist/esm/modules/queue/internal/sequential/common/types.js.map +1 -1
- package/dist/esm/modules/queue/internal/sequential/helper.d.ts +4 -0
- package/dist/esm/modules/queue/internal/sequential/helper.js +4 -0
- package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
- package/dist/esm/modules/queue/kafka/base.d.ts +5 -0
- package/dist/esm/modules/queue/kafka/base.js.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/common/constants.d.ts +3 -0
- package/dist/esm/modules/queue/kafka/bundler/common/constants.js +3 -0
- package/dist/esm/modules/queue/kafka/bundler/common/constants.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.d.ts +8 -0
- package/dist/esm/modules/queue/kafka/common/constants.js +5 -0
- package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/types/admin.d.ts +1 -0
- package/dist/esm/modules/queue/kafka/common/types/admin.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/types/callbacks.d.ts +12 -0
- package/dist/esm/modules/queue/kafka/common/types/callbacks.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/types/connection.d.ts +2 -0
- package/dist/esm/modules/queue/kafka/common/types/connection.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/types/consumer.d.ts +62 -0
- package/dist/esm/modules/queue/kafka/common/types/consumer.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/types/producer.d.ts +1 -0
- package/dist/esm/modules/queue/kafka/common/types/producer.js.map +1 -1
- package/dist/esm/modules/queue/mqtt/helper.d.ts +2 -0
- package/dist/esm/modules/queue/mqtt/helper.js +1 -0
- package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
- package/dist/esm/modules/redis/base/abstract.helper.d.ts +2 -0
- package/dist/esm/modules/redis/base/abstract.helper.js +2 -0
- package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.d.ts +1 -0
- package/dist/esm/modules/redis/cluster/cluster.helper.js +1 -0
- package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
- package/dist/esm/modules/redis/common/constants.d.ts +4 -0
- package/dist/esm/modules/redis/common/constants.js +2 -0
- package/dist/esm/modules/redis/common/constants.js.map +1 -1
- package/dist/esm/modules/redis/common/interfaces.d.ts +12 -0
- package/dist/esm/modules/redis/common/interfaces.js.map +1 -1
- package/dist/esm/modules/redis/common/types.d.ts +21 -1
- package/dist/esm/modules/redis/common/types.js.map +1 -1
- package/dist/esm/modules/redis/factory.d.ts +2 -0
- package/dist/esm/modules/redis/factory.js +1 -0
- package/dist/esm/modules/redis/factory.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.d.ts +1 -0
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js +1 -0
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
- package/dist/esm/modules/redis/single/single.helper.d.ts +1 -0
- package/dist/esm/modules/redis/single/single.helper.js +1 -0
- package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
- package/dist/esm/modules/redis/utility.d.ts +1 -0
- package/dist/esm/modules/redis/utility.js +1 -0
- package/dist/esm/modules/redis/utility.js.map +1 -1
- package/dist/esm/modules/retry/common/constants.d.ts +4 -0
- package/dist/esm/modules/retry/common/constants.js +2 -0
- package/dist/esm/modules/retry/common/constants.js.map +1 -1
- package/dist/esm/modules/retry/common/types.d.ts +19 -5
- package/dist/esm/modules/retry/common/types.js.map +1 -1
- package/dist/esm/modules/retry/helper.d.ts +4 -4
- package/dist/esm/modules/retry/helper.js.map +1 -1
- package/dist/esm/modules/secrets/base/abstract.helper.d.ts +1 -0
- package/dist/esm/modules/secrets/base/abstract.helper.js +1 -0
- package/dist/esm/modules/secrets/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/secrets/common/constants.d.ts +4 -0
- package/dist/esm/modules/secrets/common/constants.js +2 -0
- package/dist/esm/modules/secrets/common/constants.js.map +1 -1
- package/dist/esm/modules/secrets/common/types/helper.d.ts +13 -0
- package/dist/esm/modules/secrets/common/types/helper.js.map +1 -1
- package/dist/esm/modules/secrets/common/types/lease.d.ts +2 -0
- package/dist/esm/modules/secrets/common/types/lease.js.map +1 -1
- package/dist/esm/modules/secrets/common/types/registration.d.ts +13 -2
- package/dist/esm/modules/secrets/common/types/registration.js.map +1 -1
- package/dist/esm/modules/secrets/common/types/timer.d.ts +1 -0
- package/dist/esm/modules/secrets/common/types/timer.js.map +1 -1
- package/dist/esm/modules/secrets/dotenv/dotenv.helper.d.ts +8 -0
- package/dist/esm/modules/secrets/dotenv/dotenv.helper.js +1 -0
- package/dist/esm/modules/secrets/dotenv/dotenv.helper.js.map +1 -1
- package/dist/esm/modules/secrets/factory.d.ts +1 -0
- package/dist/esm/modules/secrets/factory.js +1 -0
- package/dist/esm/modules/secrets/factory.js.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/auth.d.ts +2 -0
- package/dist/esm/modules/secrets/hashicorp/auth.js +1 -0
- package/dist/esm/modules/secrets/hashicorp/auth.js.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts +2 -0
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +1 -0
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
- package/dist/esm/modules/secrets/system-envs/system-envs.helper.d.ts +1 -0
- package/dist/esm/modules/secrets/system-envs/system-envs.helper.js +1 -0
- package/dist/esm/modules/secrets/system-envs/system-envs.helper.js.map +1 -1
- package/dist/esm/modules/slug/common/constants.d.ts +1 -0
- package/dist/esm/modules/slug/common/constants.js +1 -0
- package/dist/esm/modules/slug/common/constants.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/common/constants.d.ts +2 -0
- package/dist/esm/modules/socket/socket-io/common/constants.js +2 -0
- package/dist/esm/modules/socket/socket-io/common/constants.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/common/types/client.d.ts +5 -0
- package/dist/esm/modules/socket/socket-io/common/types/client.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/common/types/hooks.d.ts +4 -0
- package/dist/esm/modules/socket/socket-io/common/types/hooks.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/common/types/server.d.ts +6 -0
- package/dist/esm/modules/socket/socket-io/common/types/server.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/server/helper.d.ts +1 -0
- package/dist/esm/modules/socket/socket-io/server/helper.js +1 -0
- package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
- package/dist/esm/modules/socket/websocket/common/constants.d.ts +7 -0
- package/dist/esm/modules/socket/websocket/common/constants.js +5 -0
- package/dist/esm/modules/socket/websocket/common/constants.js.map +1 -1
- package/dist/esm/modules/socket/websocket/common/types/client.d.ts +4 -0
- package/dist/esm/modules/socket/websocket/common/types/client.js.map +1 -1
- package/dist/esm/modules/socket/websocket/common/types/hooks.d.ts +7 -0
- package/dist/esm/modules/socket/websocket/common/types/hooks.js.map +1 -1
- package/dist/esm/modules/socket/websocket/common/types/server.d.ts +30 -0
- package/dist/esm/modules/socket/websocket/common/types/server.js.map +1 -1
- package/dist/esm/modules/socket/websocket/emitter/helper.d.ts +1 -0
- package/dist/esm/modules/socket/websocket/emitter/helper.js +1 -0
- package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
- package/dist/esm/modules/socket/websocket/server/helper.d.ts +1 -0
- package/dist/esm/modules/socket/websocket/server/helper.js +1 -0
- package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
- package/dist/esm/modules/storage/base.d.ts +6 -1
- package/dist/esm/modules/storage/base.js +1 -0
- package/dist/esm/modules/storage/base.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.d.ts +9 -1
- package/dist/esm/modules/storage/bun-s3/helper.js +2 -1
- package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/esm/modules/storage/common/constants.d.ts +1 -0
- package/dist/esm/modules/storage/common/constants.js.map +1 -1
- package/dist/esm/modules/storage/common/types.d.ts +17 -1
- package/dist/esm/modules/storage/common/types.js.map +1 -1
- package/dist/esm/modules/storage/common/utility.d.ts +1 -0
- package/dist/esm/modules/storage/common/utility.js +1 -0
- package/dist/esm/modules/storage/common/utility.js.map +1 -1
- package/dist/esm/modules/storage/disk/helper.d.ts +2 -0
- package/dist/esm/modules/storage/disk/helper.js +1 -0
- package/dist/esm/modules/storage/disk/helper.js.map +1 -1
- package/dist/esm/modules/temporal/abstract.d.ts +5 -0
- package/dist/esm/modules/temporal/abstract.js +2 -1
- package/dist/esm/modules/temporal/abstract.js.map +1 -1
- package/dist/esm/modules/temporal/common/constants.d.ts +3 -0
- package/dist/esm/modules/temporal/common/constants.js.map +1 -1
- package/dist/esm/modules/tree/common/types.d.ts +6 -0
- package/dist/esm/modules/tree/common/types.js.map +1 -1
- package/dist/esm/modules/uid/common/constants.d.ts +1 -0
- package/dist/esm/modules/uid/common/constants.js.map +1 -1
- package/dist/esm/modules/uid/common/types.d.ts +28 -7
- package/dist/esm/modules/uid/common/types.js.map +1 -1
- package/dist/esm/modules/uid/helper.d.ts +12 -0
- package/dist/esm/modules/uid/helper.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v4.d.ts +1 -0
- package/dist/esm/modules/uid/uuid/v4.js +1 -0
- package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v5.d.ts +1 -0
- package/dist/esm/modules/uid/uuid/v5.js +1 -0
- package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v7.d.ts +1 -0
- package/dist/esm/modules/uid/uuid/v7.js +1 -0
- package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
- package/dist/esm/modules/worker-thread/bus/abstract.d.ts +1 -0
- package/dist/esm/modules/worker-thread/bus/abstract.js +1 -0
- package/dist/esm/modules/worker-thread/bus/abstract.js.map +1 -1
- package/dist/esm/modules/worker-thread/bus/base.d.ts +1 -0
- package/dist/esm/modules/worker-thread/bus/base.js +1 -0
- package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/bus/handler/abstract.d.ts +1 -0
- package/dist/esm/modules/worker-thread/bus/handler/abstract.js +1 -0
- package/dist/esm/modules/worker-thread/bus/handler/abstract.js.map +1 -1
- package/dist/esm/modules/worker-thread/bus/handler/base.d.ts +1 -0
- package/dist/esm/modules/worker-thread/bus/handler/base.js +1 -0
- package/dist/esm/modules/worker-thread/bus/handler/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/common/types.d.ts +4 -0
- package/dist/esm/modules/worker-thread/common/types.js.map +1 -1
- package/dist/esm/modules/worker-thread/thread/abstract.d.ts +1 -0
- package/dist/esm/modules/worker-thread/thread/abstract.js +1 -0
- package/dist/esm/modules/worker-thread/thread/abstract.js.map +1 -1
- package/dist/esm/modules/worker-thread/thread/base.d.ts +1 -0
- package/dist/esm/modules/worker-thread/thread/base.js +1 -0
- package/dist/esm/modules/worker-thread/thread/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/worker/abstract.d.ts +1 -0
- package/dist/esm/modules/worker-thread/worker/abstract.js +1 -0
- package/dist/esm/modules/worker-thread/worker/abstract.js.map +1 -1
- package/dist/esm/modules/worker-thread/worker/base.d.ts +1 -0
- package/dist/esm/modules/worker-thread/worker/base.js +1 -0
- package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/worker-pool.d.ts +1 -0
- package/dist/esm/modules/worker-thread/worker-pool.js +1 -0
- package/dist/esm/modules/worker-thread/worker-pool.js.map +1 -1
- package/dist/esm/utilities/error.utility.d.ts +1 -0
- package/dist/esm/utilities/error.utility.js +1 -0
- package/dist/esm/utilities/error.utility.js.map +1 -1
- package/dist/esm/utilities/form-body.utility.d.ts +1 -0
- package/dist/esm/utilities/form-body.utility.js +1 -0
- package/dist/esm/utilities/form-body.utility.js.map +1 -1
- package/dist/esm/utilities/hr-time.utility.d.ts +1 -0
- package/dist/esm/utilities/hr-time.utility.js +1 -0
- package/dist/esm/utilities/hr-time.utility.js.map +1 -1
- package/dist/esm/utilities/performance.utility.d.ts +1 -0
- package/dist/esm/utilities/performance.utility.js +1 -0
- package/dist/esm/utilities/performance.utility.js.map +1 -1
- package/dist/esm/utilities/promise.utility.d.ts +1 -0
- package/dist/esm/utilities/promise.utility.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +2 -0
- package/dist/esm/utilities/request.utility.js +1 -0
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ConnectionOptions, type TLSSocket } from 'node:tls';
|
|
2
2
|
import { BaseNetworkTcpClient, type INetworkTcpClientProps } from './base-tcp-client.helper.js';
|
|
3
|
+
/** TLS TCP client (`node:tls` `connect`) on top of the shared base client; `options` are `tls.ConnectionOptions`. */
|
|
3
4
|
export declare class NetworkTlsTcpClient extends BaseNetworkTcpClient<ConnectionOptions, TLSSocket> {
|
|
4
5
|
constructor(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>);
|
|
5
6
|
static newInstance(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>): NetworkTlsTcpClient;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { connect } from 'node:tls';
|
|
2
2
|
import { BaseNetworkTcpClient } from './base-tcp-client.helper.js';
|
|
3
|
+
/** TLS TCP client (`node:tls` `connect`) on top of the shared base client; `options` are `tls.ConnectionOptions`. */
|
|
3
4
|
export class NetworkTlsTcpClient extends BaseNetworkTcpClient {
|
|
4
5
|
constructor(opts) {
|
|
5
6
|
super({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-tls-tcp-client.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/network-tls-tcp-client.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA0C,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAA+B,MAAM,0BAA0B,CAAC;AAE7F,MAAM,OAAO,mBAAoB,SAAQ,oBAAkD;IACzF,YAAY,IAAkF;QAC5F,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,mBAAmB,CAAC,IAAI;YAC/B,cAAc,EAAE,OAAO;SACxB,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,WAAW,CAChB,IAAkF;QAElF,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { connect, type ConnectionOptions, type TLSSocket } from 'node:tls';\nimport { BaseNetworkTcpClient, type INetworkTcpClientProps } from './base-tcp-client.helper';\n\nexport class NetworkTlsTcpClient extends BaseNetworkTcpClient<ConnectionOptions, TLSSocket> {\n constructor(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>) {\n super({\n ...opts,\n scope: NetworkTlsTcpClient.name,\n createClientFn: connect,\n });\n this.options = opts.options;\n }\n\n static newInstance(\n opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>,\n ) {\n return new NetworkTlsTcpClient(opts);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"network-tls-tcp-client.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/network-tls-tcp-client.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA0C,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAA+B,MAAM,0BAA0B,CAAC;AAE7F,qHAAqH;AACrH,MAAM,OAAO,mBAAoB,SAAQ,oBAAkD;IACzF,YAAY,IAAkF;QAC5F,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,mBAAmB,CAAC,IAAI;YAC/B,cAAc,EAAE,OAAO;SACxB,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,WAAW,CAChB,IAAkF;QAElF,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { connect, type ConnectionOptions, type TLSSocket } from 'node:tls';\nimport { BaseNetworkTcpClient, type INetworkTcpClientProps } from './base-tcp-client.helper';\n\n/** TLS TCP client (`node:tls` `connect`) on top of the shared base client; `options` are `tls.ConnectionOptions`. */\nexport class NetworkTlsTcpClient extends BaseNetworkTcpClient<ConnectionOptions, TLSSocket> {\n constructor(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>) {\n super({\n ...opts,\n scope: NetworkTlsTcpClient.name,\n createClientFn: connect,\n });\n this.options = opts.options;\n }\n\n static newInstance(\n opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>,\n ) {\n return new NetworkTlsTcpClient(opts);\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Server, type TLSSocket as SocketClient, type TlsOptions } from 'node:tls';
|
|
2
2
|
import { BaseNetworkTcpServer, type ITcpSocketServerOptions } from './base-tcp-server.helper.js';
|
|
3
3
|
type TTlsTcpServerOptions = Omit<ITcpSocketServerOptions<TlsOptions, Server, SocketClient>, 'createServerFn'>;
|
|
4
|
+
/** TLS TCP server (`node:tls`) on top of the shared base server; `serverOptions` are `tls.TlsOptions`. */
|
|
4
5
|
export declare class NetworkTlsTcpServer extends BaseNetworkTcpServer<TlsOptions, Server, SocketClient> {
|
|
5
6
|
constructor(opts: TTlsTcpServerOptions);
|
|
6
7
|
static newInstance(opts: TTlsTcpServerOptions): NetworkTlsTcpServer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createServer, } from 'node:tls';
|
|
2
2
|
import { BaseNetworkTcpServer } from './base-tcp-server.helper.js';
|
|
3
|
+
/** TLS TCP server (`node:tls`) on top of the shared base server; `serverOptions` are `tls.TlsOptions`. */
|
|
3
4
|
export class NetworkTlsTcpServer extends BaseNetworkTcpServer {
|
|
4
5
|
constructor(opts) {
|
|
5
6
|
super({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-tls-tcp-server.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/network-tls-tcp-server.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAgC,MAAM,0BAA0B,CAAC;AAO9F,MAAM,OAAO,mBAAoB,SAAQ,oBAAsD;IAC7F,YAAY,IAA0B;QACpC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,mBAAmB,CAAC,IAAI;YAC/B,cAAc,EAAE,YAAY;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAA0B;QAC3C,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import {\n createServer,\n type Server,\n type TLSSocket as SocketClient,\n type TlsOptions,\n} from 'node:tls';\nimport { BaseNetworkTcpServer, type ITcpSocketServerOptions } from './base-tcp-server.helper';\n\ntype TTlsTcpServerOptions = Omit<\n ITcpSocketServerOptions<TlsOptions, Server, SocketClient>,\n 'createServerFn'\n>;\n\nexport class NetworkTlsTcpServer extends BaseNetworkTcpServer<TlsOptions, Server, SocketClient> {\n constructor(opts: TTlsTcpServerOptions) {\n super({\n ...opts,\n scope: NetworkTlsTcpServer.name,\n createServerFn: createServer,\n });\n }\n\n static newInstance(opts: TTlsTcpServerOptions) {\n return new NetworkTlsTcpServer(opts);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"network-tls-tcp-server.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/network-tls-tcp-server.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAgC,MAAM,0BAA0B,CAAC;AAO9F,0GAA0G;AAC1G,MAAM,OAAO,mBAAoB,SAAQ,oBAAsD;IAC7F,YAAY,IAA0B;QACpC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,mBAAmB,CAAC,IAAI;YAC/B,cAAc,EAAE,YAAY;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAA0B;QAC3C,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import {\n createServer,\n type Server,\n type TLSSocket as SocketClient,\n type TlsOptions,\n} from 'node:tls';\nimport { BaseNetworkTcpServer, type ITcpSocketServerOptions } from './base-tcp-server.helper';\n\ntype TTlsTcpServerOptions = Omit<\n ITcpSocketServerOptions<TlsOptions, Server, SocketClient>,\n 'createServerFn'\n>;\n\n/** TLS TCP server (`node:tls`) on top of the shared base server; `serverOptions` are `tls.TlsOptions`. */\nexport class NetworkTlsTcpServer extends BaseNetworkTcpServer<TlsOptions, Server, SocketClient> {\n constructor(opts: TTlsTcpServerOptions) {\n super({\n ...opts,\n scope: NetworkTlsTcpServer.name,\n createServerFn: createServer,\n });\n }\n\n static newInstance(opts: TTlsTcpServerOptions) {\n return new NetworkTlsTcpServer(opts);\n }\n}\n"]}
|
|
@@ -43,6 +43,10 @@ interface INetworkUdpClientProps {
|
|
|
43
43
|
};
|
|
44
44
|
}) => ValueOrPromise<void>;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* UDP (`udp4`) socket that binds to `host`/`port` and optionally joins multicast groups.
|
|
48
|
+
* Port `0` asks the OS for a port; a negative or non-integer port is logged and ignored. Without `onConnected`/`onData`/`onClosed`/`onError`, the built-in handlers log.
|
|
49
|
+
*/
|
|
46
50
|
export declare class NetworkUdpClient extends BaseHelper {
|
|
47
51
|
private host?;
|
|
48
52
|
private port;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { BaseHelper } from '../../base.js';
|
|
2
2
|
import { PromiseUtility } from '../../../utilities/promise.utility.js';
|
|
3
3
|
import dgram from 'node:dgram';
|
|
4
|
+
/**
|
|
5
|
+
* UDP (`udp4`) socket that binds to `host`/`port` and optionally joins multicast groups.
|
|
6
|
+
* Port `0` asks the OS for a port; a negative or non-integer port is logged and ignored. Without `onConnected`/`onData`/`onClosed`/`onError`, the built-in handlers log.
|
|
7
|
+
*/
|
|
4
8
|
export class NetworkUdpClient extends BaseHelper {
|
|
5
9
|
constructor(opts) {
|
|
6
10
|
super({ scope: NetworkUdpClient.name, identifier: opts.identifier });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-udp-client.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/udp-socket/network-udp-client.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,MAAM,YAAY,CAAC;AAgC/B,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAoC9C,YAAY,IAA4B;QACtC,KAAK,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAErE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,SA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EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAElC,IAAI,CAAC;YACH,SAAS,EAAE,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;iBACzB,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAEnE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QAErB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kCAAkC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAClG,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common';\nimport { BaseHelper } from '@/modules/base';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport dgram from 'node:dgram';\n\ninterface INetworkUdpClientProps {\n identifier: string;\n\n host?: string;\n port: number;\n reuseAddr?: boolean;\n\n multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n onConnected?: (opts: { identifier: string; host?: string; port: number }) => void;\n onData?: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n onError?: (opts: { identifier: string; host?: string; port: number; error: Error }) => void;\n onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n}\n\nexport class NetworkUdpClient extends BaseHelper {\n private host?: string;\n private port: number;\n private reuseAddr?: boolean;\n\n private multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n private onConnected: (opts: { identifier: string; host?: string; port: number }) => void;\n private onData: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n\n private onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n private onError?: (opts: {\n identifier: string;\n host?: string;\n port: number;\n error: Error;\n }) => void;\n\n private onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n\n private client?: dgram.Socket | null;\n\n constructor(opts: INetworkUdpClientProps) {\n super({ scope: NetworkUdpClient.name, identifier: opts.identifier });\n\n this.host = opts.host;\n this.port = opts.port;\n this.reuseAddr = opts.reuseAddr;\n this.multicastAddress = opts.multicastAddress;\n\n this.onConnected = opts?.onConnected ?? this.handleConnected;\n this.onData = opts?.onData ?? this.handleData;\n this.onClosed = opts?.onClosed ?? this.handleClosed;\n this.onError = opts?.onError ?? this.handleError;\n this.onBind = opts?.onBind;\n }\n\n static newInstance(opts: INetworkUdpClientProps) {\n return new NetworkUdpClient(opts);\n }\n\n getClient() {\n return this.client;\n }\n\n handleConnected() {\n this.logger\n .for(this.handleConnected.name)\n .info('[%s] Successfully bind connection | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleData(opts: { identifier: string; message: string | Buffer; remoteInfo: dgram.RemoteInfo }) {\n this.logger\n .for(this.handleData.name)\n .info('[%s][%s:%d][<==] Raw: %s', this.identifier, this.host, this.port, {\n message: opts.message,\n remoteInfo: opts.remoteInfo,\n });\n }\n\n handleClosed() {\n this.logger\n .for(this.handleClosed.name)\n .info('[%s] Closed connection UDP Server | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleError(opts: { identifier: string; error: Error }) {\n this.logger.for(this.handleError.name).error(\n '[%s] Connection error | Options: %j | Error: %s',\n this.identifier,\n {\n host: this.host,\n port: this.port,\n },\n opts.error,\n );\n }\n\n connect() {\n if (this.client) {\n this.logger\n .for(this.connect.name)\n .info('[%s] UdpClient is already initialized!', this.identifier);\n\n return;\n }\n\n // Port 0 is a VALID request for an OS assigned port - only a missing / negative port is invalid.\n if (!Number.isInteger(this.port) || this.port < 0) {\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] Cannot init UDP Client with invalid port | Port: %s',\n this.identifier,\n this.port,\n );\n\n return;\n }\n\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] New network udp client | Host: %s | Port: %s | multicastAddress: %j',\n this.identifier,\n this.host,\n this.port,\n this.multicastAddress,\n );\n\n this.client = dgram.createSocket({ type: 'udp4', reuseAddr: this.reuseAddr });\n this.client.on('close', () => {\n this.invokeHook({\n scope: this.handleClosed.name,\n execution: () => {\n this.onClosed?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('error', (error) => {\n this.invokeHook({\n scope: this.handleError.name,\n execution: () => {\n this.onError?.({ identifier: this.identifier, host: this.host, port: this.port, error });\n },\n });\n });\n\n this.client.on('listening', () => {\n this.invokeHook({\n scope: this.handleConnected.name,\n execution: () => {\n this.onConnected?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('message', (message: string | Buffer, remoteInfo: dgram.RemoteInfo) => {\n this.invokeHook({\n scope: this.handleData.name,\n execution: () => {\n this.onData?.({ identifier: this.identifier, message, remoteInfo });\n },\n });\n });\n\n this.client.bind({ port: this.port, address: this.host }, () => {\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: 'bind',\n // The async wrapper turns a SYNCHRONOUS throw from onBind into a rejection; calling it bare would throw out of the dgram listening listener as an uncaught exception.\n execution: (async () =>\n this.onBind?.({\n identifier: this.identifier,\n socket: this.client!,\n host: this.host,\n port: this.port,\n reuseAddr: this.reuseAddr,\n multicastAddress: this.multicastAddress,\n }))(),\n });\n });\n }\n\n // Hooks run inside dgram event listeners: a synchronous throw there is an uncaught exception.\n private invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n disconnect() {\n if (!this.client) {\n this.logger\n .for(this.disconnect.name)\n .info('[%s] UdpClient is not initialized yet!', this.identifier);\n\n return;\n }\n\n this.client?.close();\n\n this.client = null;\n this.logger.for(this.disconnect.name).info('UdpClient is destroyed! | ID: %s', this.identifier);\n }\n\n isConnected() {\n return this.client;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"network-udp-client.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/udp-socket/network-udp-client.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,MAAM,YAAY,CAAC;AAgC/B;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAoC9C,YAAY,IAA4B;QACtC,KAAK,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAErE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAE9C,IAAI,CAAC,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KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;iBACzB,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAEnE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QAErB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kCAAkC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAClG,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common';\nimport { BaseHelper } from '@/modules/base';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport dgram from 'node:dgram';\n\ninterface INetworkUdpClientProps {\n identifier: string;\n\n host?: string;\n port: number;\n reuseAddr?: boolean;\n\n multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n onConnected?: (opts: { identifier: string; host?: string; port: number }) => void;\n onData?: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n onError?: (opts: { identifier: string; host?: string; port: number; error: Error }) => void;\n onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n}\n\n/**\n * UDP (`udp4`) socket that binds to `host`/`port` and optionally joins multicast groups.\n * Port `0` asks the OS for a port; a negative or non-integer port is logged and ignored. Without `onConnected`/`onData`/`onClosed`/`onError`, the built-in handlers log.\n */\nexport class NetworkUdpClient extends BaseHelper {\n private host?: string;\n private port: number;\n private reuseAddr?: boolean;\n\n private multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n private onConnected: (opts: { identifier: string; host?: string; port: number }) => void;\n private onData: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n\n private onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n private onError?: (opts: {\n identifier: string;\n host?: string;\n port: number;\n error: Error;\n }) => void;\n\n private onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n\n private client?: dgram.Socket | null;\n\n constructor(opts: INetworkUdpClientProps) {\n super({ scope: NetworkUdpClient.name, identifier: opts.identifier });\n\n this.host = opts.host;\n this.port = opts.port;\n this.reuseAddr = opts.reuseAddr;\n this.multicastAddress = opts.multicastAddress;\n\n this.onConnected = opts?.onConnected ?? this.handleConnected;\n this.onData = opts?.onData ?? this.handleData;\n this.onClosed = opts?.onClosed ?? this.handleClosed;\n this.onError = opts?.onError ?? this.handleError;\n this.onBind = opts?.onBind;\n }\n\n static newInstance(opts: INetworkUdpClientProps) {\n return new NetworkUdpClient(opts);\n }\n\n getClient() {\n return this.client;\n }\n\n handleConnected() {\n this.logger\n .for(this.handleConnected.name)\n .info('[%s] Successfully bind connection | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleData(opts: { identifier: string; message: string | Buffer; remoteInfo: dgram.RemoteInfo }) {\n this.logger\n .for(this.handleData.name)\n .info('[%s][%s:%d][<==] Raw: %s', this.identifier, this.host, this.port, {\n message: opts.message,\n remoteInfo: opts.remoteInfo,\n });\n }\n\n handleClosed() {\n this.logger\n .for(this.handleClosed.name)\n .info('[%s] Closed connection UDP Server | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleError(opts: { identifier: string; error: Error }) {\n this.logger.for(this.handleError.name).error(\n '[%s] Connection error | Options: %j | Error: %s',\n this.identifier,\n {\n host: this.host,\n port: this.port,\n },\n opts.error,\n );\n }\n\n connect() {\n if (this.client) {\n this.logger\n .for(this.connect.name)\n .info('[%s] UdpClient is already initialized!', this.identifier);\n\n return;\n }\n\n // Port 0 is a VALID request for an OS assigned port - only a missing / negative port is invalid.\n if (!Number.isInteger(this.port) || this.port < 0) {\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] Cannot init UDP Client with invalid port | Port: %s',\n this.identifier,\n this.port,\n );\n\n return;\n }\n\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] New network udp client | Host: %s | Port: %s | multicastAddress: %j',\n this.identifier,\n this.host,\n this.port,\n this.multicastAddress,\n );\n\n this.client = dgram.createSocket({ type: 'udp4', reuseAddr: this.reuseAddr });\n this.client.on('close', () => {\n this.invokeHook({\n scope: this.handleClosed.name,\n execution: () => {\n this.onClosed?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('error', (error) => {\n this.invokeHook({\n scope: this.handleError.name,\n execution: () => {\n this.onError?.({ identifier: this.identifier, host: this.host, port: this.port, error });\n },\n });\n });\n\n this.client.on('listening', () => {\n this.invokeHook({\n scope: this.handleConnected.name,\n execution: () => {\n this.onConnected?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('message', (message: string | Buffer, remoteInfo: dgram.RemoteInfo) => {\n this.invokeHook({\n scope: this.handleData.name,\n execution: () => {\n this.onData?.({ identifier: this.identifier, message, remoteInfo });\n },\n });\n });\n\n this.client.bind({ port: this.port, address: this.host }, () => {\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: 'bind',\n // The async wrapper turns a SYNCHRONOUS throw from onBind into a rejection; calling it bare would throw out of the dgram listening listener as an uncaught exception.\n execution: (async () =>\n this.onBind?.({\n identifier: this.identifier,\n socket: this.client!,\n host: this.host,\n port: this.port,\n reuseAddr: this.reuseAddr,\n multicastAddress: this.multicastAddress,\n }))(),\n });\n });\n }\n\n // Hooks run inside dgram event listeners: a synchronous throw there is an uncaught exception.\n private invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n disconnect() {\n if (!this.client) {\n this.logger\n .for(this.disconnect.name)\n .info('[%s] UdpClient is not initialized yet!', this.identifier);\n\n return;\n }\n\n this.client?.close();\n\n this.client = null;\n this.logger.for(this.disconnect.name).info('UdpClient is destroyed! | ID: %s', this.identifier);\n }\n\n isConnected() {\n return this.client;\n }\n}\n"]}
|
|
@@ -15,6 +15,7 @@ export declare class QueryStringNullishModes {
|
|
|
15
15
|
/** The pair is left out. */
|
|
16
16
|
static readonly SKIP = "skip";
|
|
17
17
|
}
|
|
18
|
+
/** What {@link QueryStringNullishModes} selects: `empty` or `skip`. */
|
|
18
19
|
export type TQueryStringNullishMode = TConstValue<typeof QueryStringNullishModes>;
|
|
19
20
|
/** What an object or an array value becomes. */
|
|
20
21
|
export declare class QueryStringNestedModes {
|
|
@@ -23,12 +24,22 @@ export declare class QueryStringNestedModes {
|
|
|
23
24
|
/** One JSON-encoded parameter (`ids=[1,2]`, `filter={"where":{}}`), the shape a JSON filter travels in. */
|
|
24
25
|
static readonly JSON = "json";
|
|
25
26
|
}
|
|
27
|
+
/** What {@link QueryStringNestedModes} selects: `drop` or `json`. */
|
|
26
28
|
export type TQueryStringNestedMode = TConstValue<typeof QueryStringNestedModes>;
|
|
27
|
-
/** How {@link QueryStringUtility.toQueryString} treats the values `node:querystring` has no answer for.
|
|
29
|
+
/** How {@link QueryStringUtility.toQueryString} treats the values `node:querystring` has no answer for. */
|
|
28
30
|
export interface IQueryStringOptions {
|
|
31
|
+
/**
|
|
32
|
+
* What a `null` or `undefined` value becomes.
|
|
33
|
+
* @default QueryStringNullishModes.EMPTY
|
|
34
|
+
*/
|
|
29
35
|
nullish?: TQueryStringNullishMode;
|
|
36
|
+
/**
|
|
37
|
+
* What an object or an array value becomes.
|
|
38
|
+
* @default QueryStringNestedModes.DROP
|
|
39
|
+
*/
|
|
30
40
|
nested?: TQueryStringNestedMode;
|
|
31
41
|
}
|
|
42
|
+
/** Builds a query string without a node builtin, so the network layer stays browser-safe. */
|
|
32
43
|
export declare class QueryStringUtility {
|
|
33
44
|
/**
|
|
34
45
|
* `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
|
|
@@ -44,7 +55,7 @@ export declare class QueryStringUtility {
|
|
|
44
55
|
*
|
|
45
56
|
* `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
|
|
46
57
|
* array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
|
|
47
|
-
* the trip.
|
|
58
|
+
* the trip. Without them the behavior is the one above.
|
|
48
59
|
*/
|
|
49
60
|
static toQueryString(opts: {
|
|
50
61
|
params: AnyObject;
|
|
@@ -21,6 +21,7 @@ export class QueryStringNestedModes {
|
|
|
21
21
|
/** One JSON-encoded parameter (`ids=[1,2]`, `filter={"where":{}}`), the shape a JSON filter travels in. */
|
|
22
22
|
static { this.JSON = 'json'; }
|
|
23
23
|
}
|
|
24
|
+
/** Builds a query string without a node builtin, so the network layer stays browser-safe. */
|
|
24
25
|
export class QueryStringUtility {
|
|
25
26
|
/**
|
|
26
27
|
* `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
|
|
@@ -36,7 +37,7 @@ export class QueryStringUtility {
|
|
|
36
37
|
*
|
|
37
38
|
* `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
|
|
38
39
|
* array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
|
|
39
|
-
* the trip.
|
|
40
|
+
* the trip. Without them the behavior is the one above.
|
|
40
41
|
*/
|
|
41
42
|
static toQueryString(opts) {
|
|
42
43
|
const { params, nullish = QueryStringNullishModes.EMPTY, nested = QueryStringNestedModes.DROP, } = opts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-string.js","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAEA,oGAAoG;AACpG,MAAM,OAAO,qBAAqB;IAChC,2CAA2C;aAC3B,UAAK,GAAG,GAAG,CAAC;IAC5B,yBAAyB;aACT,SAAI,GAAG,GAAG,CAAC;IAC3B,oCAAoC;aACpB,WAAM,GAAG,GAAG,CAAC;;AAG/B,kDAAkD;AAClD,MAAM,OAAO,uBAAuB;IAClC,2DAA2D;aAC3C,UAAK,GAAG,OAAO,CAAC;IAChC,4BAA4B;aACZ,SAAI,GAAG,MAAM,CAAC;;
|
|
1
|
+
{"version":3,"file":"query-string.js","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAEA,oGAAoG;AACpG,MAAM,OAAO,qBAAqB;IAChC,2CAA2C;aAC3B,UAAK,GAAG,GAAG,CAAC;IAC5B,yBAAyB;aACT,SAAI,GAAG,GAAG,CAAC;IAC3B,oCAAoC;aACpB,WAAM,GAAG,GAAG,CAAC;;AAG/B,kDAAkD;AAClD,MAAM,OAAO,uBAAuB;IAClC,2DAA2D;aAC3C,UAAK,GAAG,OAAO,CAAC;IAChC,4BAA4B;aACZ,SAAI,GAAG,MAAM,CAAC;;AAKhC,gDAAgD;AAChD,MAAM,OAAO,sBAAsB;IACjC,uFAAuF;aACvE,SAAI,GAAG,MAAM,CAAC;IAC9B,2GAA2G;aAC3F,SAAI,GAAG,MAAM,CAAC;;AAmBhC,6FAA6F;AAC7F,MAAM,OAAO,kBAAkB;IAC7B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,aAAa,C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CAAC;gBACzB,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;oBAC1B,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;wBACrB,SAAS;oBACX,CAAC;oBAED,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACvE,CAAC;gBAED,SAAS;YACX,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;CACF","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}\n/** What {@link QueryStringNullishModes} selects: `empty` or `skip`. */\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}\n/** What {@link QueryStringNestedModes} selects: `drop` or `json`. */\nexport type TQueryStringNestedMode = TConstValue<typeof QueryStringNestedModes>;\n\n/** How {@link QueryStringUtility.toQueryString} treats the values `node:querystring` has no answer for. */\nexport interface IQueryStringOptions {\n /**\n * What a `null` or `undefined` value becomes.\n * @default QueryStringNullishModes.EMPTY\n */\n nullish?: TQueryStringNullishMode;\n /**\n * What an object or an array value becomes.\n * @default QueryStringNestedModes.DROP\n */\n nested?: TQueryStringNestedMode;\n}\n\n/** Builds a query string without a node builtin, so the network layer stays browser-safe. */\nexport class QueryStringUtility {\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. Without them the behavior is the one above.\n */\n static 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\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}\n"]}
|
|
@@ -6,8 +6,9 @@ export declare class UrlSchemes {
|
|
|
6
6
|
static readonly SCHEME_SET: Set<string>;
|
|
7
7
|
static isValid(value: string): boolean;
|
|
8
8
|
}
|
|
9
|
+
/** A scheme a guarded fetch accepts: `http:` or `https:`. */
|
|
9
10
|
export type TUrlScheme = TConstValue<typeof UrlSchemes>;
|
|
10
|
-
/**
|
|
11
|
+
/** The values `IUrlSafetyPolicy` uses for a field the caller leaves unset; each is the safe choice. */
|
|
11
12
|
export declare class UrlSafetyDefaults {
|
|
12
13
|
static readonly ALLOWED_SCHEMES: string[];
|
|
13
14
|
static readonly ALLOW_PRIVATE_ADDRESS = false;
|
|
@@ -7,7 +7,7 @@ export class UrlSchemes {
|
|
|
7
7
|
return this.SCHEME_SET.has(value);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/** The values `IUrlSafetyPolicy` uses for a field the caller leaves unset; each is the safe choice. */
|
|
11
11
|
export class UrlSafetyDefaults {
|
|
12
12
|
static { this.ALLOWED_SCHEMES = [UrlSchemes.HTTPS]; }
|
|
13
13
|
static { this.ALLOW_PRIVATE_ADDRESS = false; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/constants.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,MAAM,OAAO,UAAU;aACL,SAAI,GAAG,OAAO,CAAC;aACf,UAAK,GAAG,QAAQ,CAAC;aAEjB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEtE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/constants.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,MAAM,OAAO,UAAU;aACL,SAAI,GAAG,OAAO,CAAC;aACf,UAAK,GAAG,QAAQ,CAAC;aAEjB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEtE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,uGAAuG;AACvG,MAAM,OAAO,iBAAiB;aACZ,oBAAe,GAAa,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAC/C,0BAAqB,GAAG,KAAK,CAAC;aAC9B,kBAAa,GAAG,CAAC,CAAC;aAClB,yBAAoB,GAAG,MAAM,CAAC;aAC9B,cAAS,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC","sourcesContent":["import { type TConstValue } from '@/common/types';\n\n/** The only schemes a guarded fetch will speak. `file:` and `gopher:` are the classic SSRF pivots. */\nexport class UrlSchemes {\n static readonly HTTP = 'http:';\n static readonly HTTPS = 'https:';\n\n static readonly SCHEME_SET = new Set<string>([this.HTTP, this.HTTPS]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** A scheme a guarded fetch accepts: `http:` or `https:`. */\nexport type TUrlScheme = TConstValue<typeof UrlSchemes>;\n\n/** The values `IUrlSafetyPolicy` uses for a field the caller leaves unset; each is the safe choice. */\nexport class UrlSafetyDefaults {\n static readonly ALLOWED_SCHEMES: string[] = [UrlSchemes.HTTPS];\n static readonly ALLOW_PRIVATE_ADDRESS = false;\n static readonly MAX_REDIRECTS = 3;\n static readonly TIMEOUT_MILLISECONDS = 10_000;\n static readonly MAX_BYTES = 10 * 1024 * 1024;\n}\n"]}
|
|
@@ -4,21 +4,34 @@ import type { IDuration } from '../../../../../common/constants/duration.js';
|
|
|
4
4
|
* plain `http` says so at the call site rather than weakening a build-time constant for everyone.
|
|
5
5
|
*/
|
|
6
6
|
export interface IUrlSafetyPolicy {
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The schemes a url may use.
|
|
9
|
+
* @default ['https:']
|
|
10
|
+
*/
|
|
8
11
|
allowedSchemes?: string[];
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* Whether a url may resolve to a private address. Turning it on in a path that takes urls from user input re-opens the
|
|
11
14
|
* server-side request forgery this guard exists to close - a request can then be steered at
|
|
12
15
|
* `169.254.169.254` and the cloud credentials behind it.
|
|
16
|
+
* @default false
|
|
13
17
|
*/
|
|
14
18
|
allowPrivateAddress?: boolean;
|
|
15
19
|
/** When set, nothing outside the list passes, whatever it resolves to. */
|
|
16
20
|
allowedHosts?: string[];
|
|
17
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Redirects followed. Each hop is re-checked, so a public host cannot bounce into a private one.
|
|
23
|
+
* @default 3
|
|
24
|
+
*/
|
|
18
25
|
maxRedirects?: number;
|
|
19
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* How long a request may take. A slow host holds a worker slot for exactly this long.
|
|
28
|
+
* @default UrlSafetyDefaults.TIMEOUT_MILLISECONDS
|
|
29
|
+
*/
|
|
20
30
|
timeout?: IDuration;
|
|
21
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Largest body, in bytes. The read stops and cancels the moment the body crosses it.
|
|
33
|
+
* @default UrlSafetyDefaults.MAX_BYTES
|
|
34
|
+
*/
|
|
22
35
|
maxBytes?: number;
|
|
23
36
|
}
|
|
24
37
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IDuration } from '@/common/constants/duration';\n\n/**\n * What a caller will accept from an untrusted url. Every field is per call: an app that must reach\n * plain `http` says so at the call site rather than weakening a build-time constant for everyone.\n */\nexport interface IUrlSafetyPolicy {\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IDuration } from '@/common/constants/duration';\n\n/**\n * What a caller will accept from an untrusted url. Every field is per call: an app that must reach\n * plain `http` says so at the call site rather than weakening a build-time constant for everyone.\n */\nexport interface IUrlSafetyPolicy {\n /**\n * The schemes a url may use.\n * @default ['https:']\n */\n allowedSchemes?: string[];\n\n /**\n * Whether a url may resolve to a private address. Turning it on in a path that takes urls from user input re-opens the\n * server-side request forgery this guard exists to close - a request can then be steered at\n * `169.254.169.254` and the cloud credentials behind it.\n * @default false\n */\n allowPrivateAddress?: boolean;\n\n /** When set, nothing outside the list passes, whatever it resolves to. */\n allowedHosts?: string[];\n\n /**\n * Redirects followed. Each hop is re-checked, so a public host cannot bounce into a private one.\n * @default 3\n */\n maxRedirects?: number;\n\n /**\n * How long a request may take. A slow host holds a worker slot for exactly this long.\n * @default UrlSafetyDefaults.TIMEOUT_MILLISECONDS\n */\n timeout?: IDuration;\n\n /**\n * Largest body, in bytes. The read stops and cancels the moment the body crosses it.\n * @default UrlSafetyDefaults.MAX_BYTES\n */\n maxBytes?: number;\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TNullable, type ValueOrPromise } from '../../../common/types/index.js';
|
|
2
|
+
/** Snapshot of a pool: `size` is its configured cap, `available` counts idle resources, `borrowed` those handed out, `pending` the queued acquirers. */
|
|
2
3
|
export interface IPoolStats {
|
|
3
4
|
size: number;
|
|
4
5
|
available: number;
|
|
@@ -35,7 +36,10 @@ export interface IPoolControlOptions {
|
|
|
35
36
|
acquireTimeoutMs?: number;
|
|
36
37
|
/** Max queued acquirers; omitted → unlimited. Exceeded → acquire() rejects (load-shed). */
|
|
37
38
|
maxWaitingClients?: number;
|
|
38
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Logger scope.
|
|
41
|
+
* @default 'BasePoolHelper'
|
|
42
|
+
*/
|
|
39
43
|
scope?: string;
|
|
40
44
|
}
|
|
41
45
|
/** Options for the callback-configured {@link BasePoolHelper}: control knobs plus resource lifecycle as callbacks (AbstractPoolHelper subclasses may instead override the protected hooks directly). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/pool/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import { type TNullable, type ValueOrPromise } from '@/common/types';\n\nexport interface IPoolStats {\n size: number;\n available: number;\n borrowed: number;\n pending: number;\n}\n\n/** Public contract of an object pool (implemented by AbstractPoolHelper). */\nexport interface IPool<T> {\n /** Borrow a resource (creating/waiting as needed). Single-borrower until released/discarded. */\n acquire(): Promise<T>;\n\n /** Return a borrowed resource to the pool (or destroy it if the pool is being torn down). */\n release(opts: { resource: T }): void;\n\n /** acquire → run execution → release on success; on ANY error DISCARD (destroy) the resource + rethrow. */\n use<R>(opts: { execution: (resource: T) => ValueOrPromise<R> }): Promise<R>;\n\n /** Remove a borrowed resource from the pool and destroy it. */\n discard(opts: { resource: T }): Promise<void>;\n\n /** Pre-create resources up to `size` and place them idle. */\n warmup(): Promise<void>;\n\n /** Drain the pool: reject waiters, destroy idle resources, block new acquires. */\n destroy(): Promise<void>;\n getStats(): IPoolStats;\n}\n\n/** Sizing/timeout knobs shared by every pool (no resource-lifecycle callbacks). */\nexport interface IPoolControlOptions {\n /** Max number of resources the pool will hold/create. */\n size: number;\n /** Max ms to wait for a free resource; omitted → wait forever. */\n acquireTimeoutMs?: number;\n /** Max queued acquirers; omitted → unlimited. Exceeded → acquire() rejects (load-shed). */\n maxWaitingClients?: number;\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/pool/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import { type TNullable, type ValueOrPromise } from '@/common/types';\n\n/** Snapshot of a pool: `size` is its configured cap, `available` counts idle resources, `borrowed` those handed out, `pending` the queued acquirers. */\nexport interface IPoolStats {\n size: number;\n available: number;\n borrowed: number;\n pending: number;\n}\n\n/** Public contract of an object pool (implemented by AbstractPoolHelper). */\nexport interface IPool<T> {\n /** Borrow a resource (creating/waiting as needed). Single-borrower until released/discarded. */\n acquire(): Promise<T>;\n\n /** Return a borrowed resource to the pool (or destroy it if the pool is being torn down). */\n release(opts: { resource: T }): void;\n\n /** acquire → run execution → release on success; on ANY error DISCARD (destroy) the resource + rethrow. */\n use<R>(opts: { execution: (resource: T) => ValueOrPromise<R> }): Promise<R>;\n\n /** Remove a borrowed resource from the pool and destroy it. */\n discard(opts: { resource: T }): Promise<void>;\n\n /** Pre-create resources up to `size` and place them idle. */\n warmup(): Promise<void>;\n\n /** Drain the pool: reject waiters, destroy idle resources, block new acquires. */\n destroy(): Promise<void>;\n getStats(): IPoolStats;\n}\n\n/** Sizing/timeout knobs shared by every pool (no resource-lifecycle callbacks). */\nexport interface IPoolControlOptions {\n /** Max number of resources the pool will hold/create. */\n size: number;\n /** Max ms to wait for a free resource; omitted → wait forever. */\n acquireTimeoutMs?: number;\n /** Max queued acquirers; omitted → unlimited. Exceeded → acquire() rejects (load-shed). */\n maxWaitingClients?: number;\n /**\n * Logger scope.\n * @default 'BasePoolHelper'\n */\n scope?: string;\n}\n\n/** Options for the callback-configured {@link BasePoolHelper}: control knobs plus resource lifecycle as callbacks (AbstractPoolHelper subclasses may instead override the protected hooks directly). */\nexport interface IPoolOptions<T> extends IPoolControlOptions {\n /** Factory to create one resource. */\n create: () => ValueOrPromise<T>;\n\n /** Teardown on destroy()/discard()/validate-fail/reset-fail. */\n destroy?: (resource: T) => ValueOrPromise<void>;\n\n /** Checked when an idle resource is about to be handed out; false → destroyed + replaced. */\n validate?: (resource: T) => ValueOrPromise<boolean>;\n\n /** Run on an idle resource just before hand-out (e.g. clear state). Throw → resource discarded. */\n reset?: (resource: T) => ValueOrPromise<void>;\n}\n\n/** One queued acquirer. Cancellation/skip is owned by the FifoQueue; this only carries the settlers. */\nexport interface IPoolWaiter<T> {\n resolve: (resource: T) => void;\n reject: (error: unknown) => void;\n timer: TNullable<ReturnType<typeof setTimeout>>;\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { BaseHelper } from '../../base.js';
|
|
|
2
2
|
import { type IRedisHelper } from '../../redis/index.js';
|
|
3
3
|
import type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';
|
|
4
4
|
import { type TBullQueueRole } from '../common/index.js';
|
|
5
|
+
/** Options for {@link BullMQHelper}. `role` decides whether a `Queue` or a `Worker` is built. */
|
|
5
6
|
export interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {
|
|
6
7
|
queueName: string;
|
|
7
8
|
identifier: string;
|
|
@@ -9,7 +10,15 @@ export interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {
|
|
|
9
10
|
redisConnection: IRedisHelper;
|
|
10
11
|
/** `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. */
|
|
11
12
|
module?: typeof import('bullmq');
|
|
13
|
+
/**
|
|
14
|
+
* Worker concurrency.
|
|
15
|
+
* @default 1
|
|
16
|
+
*/
|
|
12
17
|
numberOfWorker?: number;
|
|
18
|
+
/**
|
|
19
|
+
* How long a worker holds a job's lock, in milliseconds.
|
|
20
|
+
* @default 90 * 60 * 1000
|
|
21
|
+
*/
|
|
13
22
|
lockDuration?: number;
|
|
14
23
|
/** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */
|
|
15
24
|
queueOptions?: Omit<QueueOptions, 'connection'>;
|
|
@@ -19,6 +28,10 @@ export interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {
|
|
|
19
28
|
onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: any) => Promise<void>;
|
|
20
29
|
onWorkerDataFail?: (job: Job<TQueueElement, TQueueResult> | undefined, error: Error) => Promise<void>;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Wraps a BullMQ `Queue` or `Worker` (per `role`) on one Redis connection.
|
|
33
|
+
* Worker concurrency is `numberOfWorker`; `lockDuration` is in milliseconds.
|
|
34
|
+
*/
|
|
22
35
|
export declare class BullMQHelper<TQueueElement = any, TQueueResult = any> extends BaseHelper {
|
|
23
36
|
protected queueName: string;
|
|
24
37
|
protected role: TBullQueueRole;
|
|
@@ -3,6 +3,10 @@ import { getError } from '../../error/index.js';
|
|
|
3
3
|
import { ErrorUtility } from '../../../utilities/error.utility.js';
|
|
4
4
|
import { ModuleUtility } from '../../../utilities/module.utility.js';
|
|
5
5
|
import { HookUtility } from '../common/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Wraps a BullMQ `Queue` or `Worker` (per `role`) on one Redis connection.
|
|
8
|
+
* Worker concurrency is `numberOfWorker`; `lockDuration` is in milliseconds.
|
|
9
|
+
*/
|
|
6
10
|
export class BullMQHelper extends BaseHelper {
|
|
7
11
|
constructor(options) {
|
|
8
12
|
super({ scope: BullMQHelper.name, identifier: options.identifier });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/queue/bullmq/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MA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,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QAC7B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;iBACpB,KAAK,CAAC,0CAA0C,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC7E,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;iBACpB,KAAK,CAAC,yCAAyC,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC5E,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,QAAQ,CAAC;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","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper } from '@/modules/redis';\nimport { ErrorUtility } from '@/utilities/error.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { HookUtility, 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\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\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\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\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\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\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 HookUtility.invoke({\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 HookUtility.invoke({\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\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(ErrorUtility.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(ErrorUtility.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":"","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AC,KAAK,CAAC,IAAI,CAAC;aACpB,IAAI,CAAC,4CAA4C,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper } from '@/modules/redis';\nimport { ErrorUtility } from '@/utilities/error.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { HookUtility, type TBullQueueRole } from '../common';\n\n/** Options for {@link BullMQHelper}. `role` decides whether a `Queue` or a `Worker` is built. */\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 /**\n * Worker concurrency.\n * @default 1\n */\n numberOfWorker?: number;\n /**\n * How long a worker holds a job's lock, in milliseconds.\n * @default 90 * 60 * 1000\n */\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\n/**\n * Wraps a BullMQ `Queue` or `Worker` (per `role`) on one Redis connection.\n * Worker concurrency is `numberOfWorker`; `lockDuration` is in milliseconds.\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\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\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\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\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\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\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 HookUtility.invoke({\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 HookUtility.invoke({\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\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(ErrorUtility.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(ErrorUtility.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,5 +1,6 @@
|
|
|
1
1
|
import { type ValueOrPromise } from '../../../common/types/index.js';
|
|
2
2
|
import type { ILogger } from '../../logger/index.js';
|
|
3
|
+
/** Runs user-supplied hooks so a throw or rejection is logged and never breaks the caller. */
|
|
3
4
|
export declare class HookUtility {
|
|
4
5
|
/** Fire-and-forget a hook from inside an event listener. Takes a thunk because `PromiseUtility.voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */
|
|
5
6
|
static invoke(opts: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PromiseUtility } from '../../../utilities/promise.utility.js';
|
|
2
|
+
/** Runs user-supplied hooks so a throw or rejection is logged and never breaks the caller. */
|
|
2
3
|
export class HookUtility {
|
|
3
4
|
/** Fire-and-forget a hook from inside an event listener. Takes a thunk because `PromiseUtility.voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */
|
|
4
5
|
static invoke(opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/hook.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,MAAM,OAAO,WAAW;IACtB,0QAA0Q;IAC1Q,MAAM,CAAC,MAAM,CAAC,IAIb;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,CAAC;YACH,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,oHAAoH;IACpH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAIpB;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,CAAC;YACH,MAAM,SAAS,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\n\nexport class HookUtility {\n /** Fire-and-forget a hook from inside an event listener. Takes a thunk because `PromiseUtility.voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */\n static invoke(opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n }): void {\n const { logger, scope, execution } = opts;\n\n try {\n PromiseUtility.voidExecution({ logger, scope, execution: execution() });\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n /** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */\n static async execute(opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n }): Promise<void> {\n const { logger, scope, execution } = opts;\n\n try {\n await execution();\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/hook.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,8FAA8F;AAC9F,MAAM,OAAO,WAAW;IACtB,0QAA0Q;IAC1Q,MAAM,CAAC,MAAM,CAAC,IAIb;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,CAAC;YACH,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,oHAAoH;IACpH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAIpB;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,CAAC;YACH,MAAM,SAAS,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\n\n/** Runs user-supplied hooks so a throw or rejection is logged and never breaks the caller. */\nexport class HookUtility {\n /** Fire-and-forget a hook from inside an event listener. Takes a thunk because `PromiseUtility.voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */\n static invoke(opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n }): void {\n const { logger, scope, execution } = opts;\n\n try {\n PromiseUtility.voidExecution({ logger, scope, execution: execution() });\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n /** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */\n static async execute(opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n }): Promise<void> {\n const { logger, scope, execution } = opts;\n\n try {\n await execution();\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ValueOf, type ValueOrPromise } from '../../../../../common/types/index.js';
|
|
2
|
+
/** Lifecycle states of a sequential queue; the numeric prefix orders them. */
|
|
2
3
|
export declare class QueueStatuses {
|
|
3
4
|
static readonly WAITING = "000_WAITING";
|
|
4
5
|
static readonly PROCESSING = "100_PROCESSING";
|
|
@@ -7,12 +8,19 @@ export declare class QueueStatuses {
|
|
|
7
8
|
static readonly SCHEME_SET: Set<string>;
|
|
8
9
|
static isValid(scheme: string): boolean;
|
|
9
10
|
}
|
|
11
|
+
/** A {@link QueueStatuses} value. */
|
|
10
12
|
export type TQueueStatus = ValueOf<Omit<typeof QueueStatuses, 'isValid' | 'SCHEME_SET'>>;
|
|
13
|
+
/** One queued item: `payload`, plus `isLocked` while a handler holds it. */
|
|
11
14
|
export type TQueueElement<T> = {
|
|
12
15
|
isLocked: boolean;
|
|
13
16
|
payload: T;
|
|
14
17
|
};
|
|
18
|
+
/** Hooks of a sequential queue. */
|
|
15
19
|
export interface IQueueCallback<TElementPayload> {
|
|
20
|
+
/**
|
|
21
|
+
* Whether {@link SequentialQueueHelper} dispatches an element on its own.
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
16
24
|
autoDispatch?: boolean;
|
|
17
25
|
onMessage?: (opts: {
|
|
18
26
|
identifier: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/modules/queue/internal/sequential/common/types.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,aAAa;aACR,YAAO,GAAG,aAAa,CAAC;aACxB,eAAU,GAAG,gBAAgB,CAAC;aAC9B,WAAM,GAAG,YAAY,CAAC;aACtB,YAAO,GAAG,aAAa,CAAC;aAExB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAEjG,MAAM,CAAC,OAAO,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC","sourcesContent":["import { type ValueOf, type ValueOrPromise } from '@/common/types';\n\nexport class QueueStatuses {\n static readonly WAITING = '000_WAITING';\n static readonly PROCESSING = '100_PROCESSING';\n static readonly LOCKED = '200_LOCKED';\n static readonly SETTLED = '300_SETTLED';\n\n static readonly SCHEME_SET = new Set([this.WAITING, this.PROCESSING, this.LOCKED, this.SETTLED]);\n\n static isValid(scheme: string): boolean {\n return this.SCHEME_SET.has(scheme);\n }\n}\n\nexport type TQueueStatus = ValueOf<Omit<typeof QueueStatuses, 'isValid' | 'SCHEME_SET'>>;\nexport type TQueueElement<T> = { isLocked: boolean; payload: T };\n\nexport interface IQueueCallback<TElementPayload> {\n autoDispatch?: boolean;\n\n onMessage?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n onDataEnqueue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n onDataDequeue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n onStateChange?: (opts: {\n identifier: string;\n from: TQueueStatus;\n to: TQueueStatus;\n }) => ValueOrPromise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/modules/queue/internal/sequential/common/types.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,MAAM,OAAO,aAAa;aACR,YAAO,GAAG,aAAa,CAAC;aACxB,eAAU,GAAG,gBAAgB,CAAC;aAC9B,WAAM,GAAG,YAAY,CAAC;aACtB,YAAO,GAAG,aAAa,CAAC;aAExB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAEjG,MAAM,CAAC,OAAO,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC","sourcesContent":["import { type ValueOf, type ValueOrPromise } from '@/common/types';\n\n/** Lifecycle states of a sequential queue; the numeric prefix orders them. */\nexport class QueueStatuses {\n static readonly WAITING = '000_WAITING';\n static readonly PROCESSING = '100_PROCESSING';\n static readonly LOCKED = '200_LOCKED';\n static readonly SETTLED = '300_SETTLED';\n\n static readonly SCHEME_SET = new Set([this.WAITING, this.PROCESSING, this.LOCKED, this.SETTLED]);\n\n static isValid(scheme: string): boolean {\n return this.SCHEME_SET.has(scheme);\n }\n}\n\n/** A {@link QueueStatuses} value. */\nexport type TQueueStatus = ValueOf<Omit<typeof QueueStatuses, 'isValid' | 'SCHEME_SET'>>;\n/** One queued item: `payload`, plus `isLocked` while a handler holds it. */\nexport type TQueueElement<T> = { isLocked: boolean; payload: T };\n\n/** Hooks of a sequential queue. */\nexport interface IQueueCallback<TElementPayload> {\n /**\n * Whether {@link SequentialQueueHelper} dispatches an element on its own.\n * @default true\n */\n autoDispatch?: boolean;\n\n onMessage?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n onDataEnqueue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n onDataDequeue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n onStateChange?: (opts: {\n identifier: string;\n from: TQueueStatus;\n to: TQueueStatus;\n }) => ValueOrPromise<void>;\n}\n"]}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { BaseHelper } from '../../../base.js';
|
|
2
2
|
import { type IQueueCallback, type TQueueElement, type TQueueStatus } from './common/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* In-memory FIFO queue that hands one element at a time to `onMessage`.
|
|
5
|
+
* A throwing handler is logged and its element dropped, so the queue keeps moving.
|
|
6
|
+
*/
|
|
3
7
|
export declare class SequentialQueueHelper<TElementPayload> extends BaseHelper {
|
|
4
8
|
storage: Array<TQueueElement<TElementPayload>>;
|
|
5
9
|
protected processingEvents: Set<TQueueElement<TElementPayload>>;
|
|
@@ -2,6 +2,10 @@ import { ObjectUtility } from '@venizia/ignis-inversion';
|
|
|
2
2
|
import { BaseHelper } from '../../../base.js';
|
|
3
3
|
import { HookUtility } from '../../common/index.js';
|
|
4
4
|
import { QueueStatuses, } from './common/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* In-memory FIFO queue that hands one element at a time to `onMessage`.
|
|
7
|
+
* A throwing handler is logged and its element dropped, so the queue keeps moving.
|
|
8
|
+
*/
|
|
5
9
|
export class SequentialQueueHelper extends BaseHelper {
|
|
6
10
|
constructor(opts) {
|
|
7
11
|
super({
|