@daiso-tech/core 0.33.0 → 0.35.0
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 +66 -45
- package/dist/async/_module-exports.d.ts +1 -1
- package/dist/async/_module-exports.js +1 -1
- package/dist/async/_module-exports.js.map +1 -1
- package/dist/async/async.errors.d.ts +27 -19
- package/dist/async/async.errors.js +33 -20
- package/dist/async/async.errors.js.map +1 -1
- package/dist/async/backof-policies/_shared.d.ts +6 -2
- package/dist/async/backof-policies/_shared.js +1 -0
- package/dist/async/backof-policies/_shared.js.map +1 -1
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.js +1 -1
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js +1 -1
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js +1 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +1 -1
- package/dist/async/middlewares/_module.d.ts +8 -0
- package/dist/async/middlewares/_module.js +9 -0
- package/dist/async/middlewares/_module.js.map +1 -0
- package/dist/async/middlewares/_shared.d.ts +10 -0
- package/dist/async/middlewares/_shared.js +5 -0
- package/dist/async/middlewares/_shared.js.map +1 -0
- package/dist/async/middlewares/bulkhead/_module.d.ts +1 -0
- package/dist/async/middlewares/bulkhead/_module.js +2 -0
- package/dist/async/middlewares/bulkhead/_module.js.map +1 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +80 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +46 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +1 -0
- package/dist/async/middlewares/dynamic/_module.d.ts +1 -0
- package/dist/async/middlewares/dynamic/_module.js +2 -0
- package/dist/async/middlewares/dynamic/_module.js.map +1 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.d.ts +34 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.js +36 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.js.map +1 -0
- package/dist/async/middlewares/fallback/_module.d.ts +1 -0
- package/dist/async/middlewares/fallback/_module.js +2 -0
- package/dist/async/middlewares/fallback/_module.js.map +1 -0
- package/dist/async/middlewares/fallback/fallback.middleware.d.ts +78 -0
- package/dist/async/middlewares/fallback/fallback.middleware.js +52 -0
- package/dist/async/middlewares/fallback/fallback.middleware.js.map +1 -0
- package/dist/async/middlewares/hedging/_module.d.ts +2 -0
- package/dist/async/middlewares/hedging/_module.js +3 -0
- package/dist/async/middlewares/hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/_shared.d.ts +93 -0
- package/dist/async/middlewares/hedging/_shared.js +5 -0
- package/dist/async/middlewares/hedging/_shared.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js +138 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js +104 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/observe/_module.d.ts +1 -0
- package/dist/async/middlewares/observe/_module.js +2 -0
- package/dist/async/middlewares/observe/_module.js.map +1 -0
- package/dist/async/middlewares/observe/observe.middleware.d.ts +130 -0
- package/dist/async/middlewares/observe/observe.middleware.js +80 -0
- package/dist/async/middlewares/observe/observe.middleware.js.map +1 -0
- package/dist/async/middlewares/retry/_module.d.ts +1 -0
- package/dist/async/middlewares/retry/_module.js +2 -0
- package/dist/async/middlewares/retry/_module.js.map +1 -0
- package/dist/async/middlewares/retry/retry.middleware.d.ts +117 -0
- package/dist/async/middlewares/retry/retry.middleware.js +82 -0
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -0
- package/dist/async/middlewares/timeout/_module.d.ts +1 -0
- package/dist/async/middlewares/timeout/_module.js +2 -0
- package/dist/async/middlewares/timeout/_module.js.map +1 -0
- package/dist/async/middlewares/timeout/timeout.middleware.d.ts +83 -0
- package/dist/async/middlewares/timeout/timeout.middleware.js +60 -0
- package/dist/async/middlewares/timeout/timeout.middleware.js.map +1 -0
- package/dist/async/utilities/_module.d.ts +3 -4
- package/dist/async/utilities/_module.js +3 -4
- package/dist/async/utilities/_module.js.map +1 -1
- package/dist/async/utilities/abort-and-fail/_module.d.ts +1 -0
- package/dist/async/utilities/abort-and-fail/_module.js +2 -0
- package/dist/async/utilities/abort-and-fail/_module.js.map +1 -0
- package/dist/async/utilities/abort-and-fail/abort-and-fail.d.ts +7 -0
- package/dist/async/utilities/{abort → abort-and-fail}/abort-and-fail.js +6 -6
- package/dist/async/utilities/abort-and-fail/abort-and-fail.js.map +1 -0
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +37 -194
- package/dist/async/utilities/lazy-promise/lazy-promise.js +62 -359
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/async/utilities/promise-queue/_module.d.ts +1 -0
- package/dist/async/utilities/promise-queue/_module.js +2 -0
- package/dist/async/utilities/promise-queue/_module.js.map +1 -0
- package/dist/async/utilities/promise-queue/promise-queue.d.ts +32 -0
- package/dist/async/utilities/promise-queue/promise-queue.js +107 -0
- package/dist/async/utilities/promise-queue/promise-queue.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.d.ts +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.js +2 -0
- package/dist/async/utilities/timeout-and-fail/_module.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.d.ts +7 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js +19 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -0
- package/dist/cache/contracts/cache-adapter.contract.d.ts +14 -14
- package/dist/cache/contracts/cache-factory.contract.d.ts +3 -3
- package/dist/cache/contracts/cache.contract.d.ts +73 -73
- package/dist/cache/contracts/cache.errors.d.ts +7 -7
- package/dist/cache/contracts/cache.errors.js +7 -7
- package/dist/cache/contracts/cache.events.d.ts +54 -58
- package/dist/cache/contracts/cache.events.js +6 -104
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +16 -16
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +3 -9
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +3 -9
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +4 -4
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +3 -3
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +2 -2
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +2 -2
- package/dist/cache/implementations/derivables/cache/cache.d.ts +26 -27
- package/dist/cache/implementations/derivables/cache/cache.js +102 -91
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +5 -4
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +2 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +2 -2
- package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +140 -149
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +2 -2
- package/dist/collection/contracts/_shared/compartor.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/cross-join-result.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/ensure-map.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/ensure-record.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/foreach.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/map.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/modifier.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/predicate.type.d.ts +7 -7
- package/dist/collection/contracts/_shared/reduce.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/tap.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/transform.type.d.ts +2 -2
- package/dist/collection/contracts/async-collection.contract.d.ts +109 -198
- package/dist/collection/contracts/collection.contract.d.ts +103 -103
- package/dist/collection/contracts/collection.errors.d.ts +11 -11
- package/dist/collection/contracts/collection.errors.js +11 -11
- package/dist/collection/implementations/_shared.d.ts +8 -8
- package/dist/collection/implementations/_shared.js +8 -8
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.d.ts +0 -4
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js +0 -4
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js +21 -19
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +15 -19
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +15 -30
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.d.ts +3 -3
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js +18 -20
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +11 -12
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +11 -12
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +11 -11
- package/dist/collection/implementations/list-collection/list-collection.js +24 -30
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_module-exports.d.ts +0 -1
- package/dist/event-bus/contracts/_module-exports.js +0 -1
- package/dist/event-bus/contracts/_module-exports.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +13 -8
- package/dist/event-bus/contracts/event-bus-factory.contract.d.ts +6 -7
- package/dist/event-bus/contracts/event-bus-factory.contract.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.contract.d.ts +30 -41
- package/dist/event-bus/contracts/event-bus.errors.d.ts +8 -8
- package/dist/event-bus/contracts/event-bus.errors.js +8 -8
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +3 -3
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +2 -2
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +2 -2
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +2 -2
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +15 -15
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +32 -32
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +17 -10
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +13 -6
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +3 -5
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +15 -22
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.d.ts +3 -5
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +189 -209
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +9 -9
- package/dist/lock/contracts/lock-adapter.contract.d.ts +7 -7
- package/dist/lock/contracts/lock-provider-factory.contract.d.ts +4 -4
- package/dist/lock/contracts/lock-provider.contract.d.ts +14 -14
- package/dist/lock/contracts/lock.contract.d.ts +22 -22
- package/dist/lock/contracts/lock.errors.d.ts +10 -10
- package/dist/lock/contracts/lock.errors.js +10 -10
- package/dist/lock/contracts/lock.events.d.ts +45 -54
- package/dist/lock/contracts/lock.events.js +9 -91
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +3 -3
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +3 -3
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +2 -2
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +2 -2
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +3 -3
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +3 -3
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +4 -4
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +33 -33
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +30 -30
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +3 -3
- package/dist/lock/implementations/derivables/lock-provider/lock.js +77 -58
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +5 -4
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +2 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +2 -2
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +2 -2
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +214 -214
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/contracts/deserializer.contract.d.ts +2 -2
- package/dist/serde/contracts/flexible-serde-adapter.contract.d.ts +4 -4
- package/dist/serde/contracts/flexible-serde.contract.d.ts +8 -19
- package/dist/serde/contracts/serde.contract.d.ts +2 -2
- package/dist/serde/contracts/serde.errors.d.ts +4 -4
- package/dist/serde/contracts/serde.errors.js +4 -4
- package/dist/serde/contracts/serializable.contract.d.ts +2 -2
- package/dist/serde/contracts/serializer.contract.d.ts +2 -2
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +2 -2
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +2 -2
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.d.ts +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +4 -35
- package/dist/serde/implementations/derivables/serde.js +2 -47
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.d.ts +3 -3
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +2 -2
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +3 -3
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +2 -2
- package/dist/utilities/classes/_module.d.ts +1 -1
- package/dist/utilities/classes/_module.js +1 -1
- package/dist/utilities/classes/_module.js.map +1 -1
- package/dist/utilities/classes/hooks/_module.d.ts +3 -0
- package/dist/utilities/classes/hooks/_module.js +4 -0
- package/dist/utilities/classes/hooks/_module.js.map +1 -0
- package/dist/utilities/classes/hooks/async-hooks.d.ts +209 -0
- package/dist/utilities/classes/hooks/async-hooks.js +145 -0
- package/dist/utilities/classes/hooks/async-hooks.js.map +1 -0
- package/dist/utilities/classes/hooks/hooks.d.ts +139 -0
- package/dist/utilities/classes/hooks/hooks.js +116 -0
- package/dist/utilities/classes/hooks/hooks.js.map +1 -0
- package/dist/utilities/classes/hooks/types.d.ts +9 -0
- package/dist/utilities/classes/hooks/types.js +5 -0
- package/dist/utilities/classes/hooks/types.js.map +1 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.d.ts +3 -3
- package/dist/utilities/classes/key-prefixer/key-prefixer.js +4 -4
- package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -1
- package/dist/utilities/classes/time-span/time-span.d.ts +5 -5
- package/dist/utilities/classes/time-span/time-span.js +5 -5
- package/dist/utilities/contracts/_module.d.ts +0 -1
- package/dist/utilities/contracts/_module.js +0 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/contracts/deinitizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/initizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/prunable.contract.d.ts +1 -1
- package/dist/utilities/contracts/serialized-error.contract.d.ts +1 -1
- package/dist/utilities/contracts/sqlite-database.contract.d.ts +2 -2
- package/dist/utilities/errors.d.ts +5 -5
- package/dist/utilities/errors.js +5 -5
- package/dist/utilities/functions/factory.js +3 -3
- package/dist/utilities/functions/factory.js.map +1 -1
- package/dist/utilities/functions/invokable.d.ts +9 -5
- package/dist/utilities/functions/invokable.js +12 -2
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/dist/utilities/functions/lazy.d.ts +5 -0
- package/dist/utilities/functions/lazy.js +12 -3
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/types/async-iterable-value.type.d.ts +1 -1
- package/dist/utilities/types/at-least-one.type.d.ts +1 -1
- package/dist/utilities/types/factory.type.d.ts +8 -8
- package/dist/utilities/types/invokable.type.d.ts +3 -3
- package/dist/utilities/types/items.type.d.ts +1 -1
- package/dist/utilities/types/lazy.type.d.ts +5 -5
- package/dist/utilities/types/none-func.type.d.ts +1 -1
- package/dist/utilities/types/one-or-more.type.d.ts +1 -1
- package/dist/utilities/types/promiseable.type.d.ts +1 -1
- package/dist/utilities/types/result.type.d.ts +1 -1
- package/package.json +22 -2
- package/dist/async/async.events.d.ts +0 -105
- package/dist/async/async.events.js +0 -82
- package/dist/async/async.events.js.map +0 -1
- package/dist/async/utilities/abort/_module.d.ts +0 -2
- package/dist/async/utilities/abort/_module.js +0 -3
- package/dist/async/utilities/abort/_module.js.map +0 -1
- package/dist/async/utilities/abort/abort-and-fail.d.ts +0 -4
- package/dist/async/utilities/abort/abort-and-fail.js.map +0 -1
- package/dist/async/utilities/abort/abort.d.ts +0 -9
- package/dist/async/utilities/abort/abort.js +0 -18
- package/dist/async/utilities/abort/abort.js.map +0 -1
- package/dist/async/utilities/delay/_module.d.ts +0 -1
- package/dist/async/utilities/delay/_module.js +0 -2
- package/dist/async/utilities/delay/_module.js.map +0 -1
- package/dist/async/utilities/delay/delay.d.ts +0 -10
- package/dist/async/utilities/delay/delay.js +0 -34
- package/dist/async/utilities/delay/delay.js.map +0 -1
- package/dist/async/utilities/retry/_module.d.ts +0 -2
- package/dist/async/utilities/retry/_module.js +0 -3
- package/dist/async/utilities/retry/_module.js.map +0 -1
- package/dist/async/utilities/retry/retry-or-fail.d.ts +0 -29
- package/dist/async/utilities/retry/retry-or-fail.js +0 -39
- package/dist/async/utilities/retry/retry-or-fail.js.map +0 -1
- package/dist/async/utilities/retry/retry.d.ts +0 -10
- package/dist/async/utilities/retry/retry.js +0 -21
- package/dist/async/utilities/retry/retry.js.map +0 -1
- package/dist/async/utilities/timeout/_module.d.ts +0 -2
- package/dist/async/utilities/timeout/_module.js +0 -3
- package/dist/async/utilities/timeout/_module.js.map +0 -1
- package/dist/async/utilities/timeout/timeout-and-fail.d.ts +0 -5
- package/dist/async/utilities/timeout/timeout-and-fail.js +0 -28
- package/dist/async/utilities/timeout/timeout-and-fail.js.map +0 -1
- package/dist/async/utilities/timeout/timeout.d.ts +0 -10
- package/dist/async/utilities/timeout/timeout.js +0 -21
- package/dist/async/utilities/timeout/timeout.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js +0 -30
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.js +0 -36
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.d.ts +0 -9
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.js +0 -39
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.js +0 -52
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.js.map +0 -1
- package/dist/event-bus/contracts/_shared.d.ts +0 -12
- package/dist/event-bus/contracts/_shared.js +0 -15
- package/dist/event-bus/contracts/_shared.js.map +0 -1
- package/dist/utilities/classes/sync-event-bus/_module.d.ts +0 -1
- package/dist/utilities/classes/sync-event-bus/_module.js +0 -2
- package/dist/utilities/classes/sync-event-bus/_module.js.map +0 -1
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.d.ts +0 -16
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js +0 -53
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js.map +0 -1
- package/dist/utilities/contracts/sync-event-bus-listenable.d.ts +0 -13
- package/dist/utilities/contracts/sync-event-bus-listenable.js +0 -5
- package/dist/utilities/contracts/sync-event-bus-listenable.js.map +0 -1
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @module Serde
|
|
3
3
|
*/
|
|
4
4
|
import type { OneOrMore } from "../../../utilities/_module-exports.js";
|
|
5
|
-
import type { IFlexibleSerde, IFlexibleSerdeAdapter, ISerdeTransformer, SerializableClass
|
|
5
|
+
import type { IFlexibleSerde, IFlexibleSerdeAdapter, ISerdeTransformer, SerializableClass } from "../../../serde/contracts/_module-exports.js";
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
|
-
* IMPORT_PATH:
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/deriavables"`
|
|
9
9
|
* @group Derivables
|
|
10
10
|
*/
|
|
11
11
|
export type SerdeSettings = {
|
|
@@ -99,9 +99,9 @@ export type SerdeSettings = {
|
|
|
99
99
|
shouldHandleURLSearchParams?: boolean;
|
|
100
100
|
};
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* `Serde` class can be derived from any {@link IFlexibleSerdeAdapter | `IFlexibleSerdeAdapter`}.
|
|
103
103
|
*
|
|
104
|
-
* IMPORT_PATH:
|
|
104
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/deriavables"`
|
|
105
105
|
* @group Derivables
|
|
106
106
|
*/
|
|
107
107
|
export declare class Serde<TSerializedValue> implements IFlexibleSerde<TSerializedValue> {
|
|
@@ -154,37 +154,6 @@ export declare class Serde<TSerializedValue> implements IFlexibleSerde<TSerializ
|
|
|
154
154
|
* ```
|
|
155
155
|
*/
|
|
156
156
|
deserialize<TValue>(serializedValue: TSerializedValue): TValue;
|
|
157
|
-
/**
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* import type { IFlexibleSerde } from "@daiso-tech/core/serde/contracts";
|
|
161
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
|
|
162
|
-
* import { Serde } from "@daiso-tech/core/serde";
|
|
163
|
-
* import { BaseEvent } from "@daiso-tech/core/event-bus/contracts";
|
|
164
|
-
*
|
|
165
|
-
* const serde: IFlexibleSerde = new Serde(new SuperJsonSerdeAdapter());
|
|
166
|
-
*
|
|
167
|
-
* class AddEvent extends BaseEvent<{ a: number; b: number }> {}
|
|
168
|
-
*
|
|
169
|
-
* serde.registerEvent(AddEvent);
|
|
170
|
-
*
|
|
171
|
-
* const event = new AddEvent({ a: 1, b: 2 });
|
|
172
|
-
* const deserializedEvent = serde.deserialize<AddEvent>(serde.serialize(event));
|
|
173
|
-
*
|
|
174
|
-
* // Will print 1
|
|
175
|
-
* console.log(deserializedEvent.fields.a);
|
|
176
|
-
*
|
|
177
|
-
* // Will print 2
|
|
178
|
-
* console.log(deserializedEvent.fields.b);
|
|
179
|
-
*
|
|
180
|
-
* // Will print true
|
|
181
|
-
* console.log(deserializedEvent instanceof AddEvent);
|
|
182
|
-
*
|
|
183
|
-
* // Will print false
|
|
184
|
-
* console.log(event === deserializedEvent);
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
registerEvent<TFields extends Record<string, unknown>>(eventClass: SerializableEventClass<TFields>, prefix?: OneOrMore<string>): this;
|
|
188
157
|
/**
|
|
189
158
|
* @example
|
|
190
159
|
* ```ts
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* @module Serde
|
|
3
3
|
*/
|
|
4
4
|
import { getConstructorName, resolveOneOrMoreStr, } from "../../../utilities/_module-exports.js";
|
|
5
|
-
import { BaseEvent } from "../../../event-bus/contracts/_module-exports.js";
|
|
6
5
|
import { ArrayBufferSerdeTransformer, BufferSerdeTransformer, Uint8ArraySerdeTransformer, Int8ArraySerdeTransformer, Uint16ArraySerdeTransformer, Int16ArraySerdeTransformer, Uint32ArraySerdeTransformer, Int32ArraySerdeTransformer, BigUint64ArraySerdeTransformer, BigInt64ArraySerdeTransformer, Float32ArraySerdeTransformer, Float64ArraySerdeTransformer, MapSerdeTransformer, SetSerdeTransformer, BigIntSerdeTransformer, NaNSerdeTransformer, InfinitySerdeTransformer, UndefinedSerdeTransformer, RegExpSerdeTransformer, DateSerdeTransformer, URLSerdeTransformer, URLSearchParamsSerdeTransformer, } from "../../../serde/implementations/derivables/serde-transformers.js";
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
7
|
+
* `Serde` class can be derived from any {@link IFlexibleSerdeAdapter | `IFlexibleSerdeAdapter`}.
|
|
9
8
|
*
|
|
10
|
-
* IMPORT_PATH:
|
|
9
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/deriavables"`
|
|
11
10
|
* @group Derivables
|
|
12
11
|
*/
|
|
13
12
|
export class Serde {
|
|
@@ -133,50 +132,6 @@ export class Serde {
|
|
|
133
132
|
deserialize(serializedValue) {
|
|
134
133
|
return this.serdeAdapter.deserialize(serializedValue);
|
|
135
134
|
}
|
|
136
|
-
/**
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* import type { IFlexibleSerde } from "@daiso-tech/core/serde/contracts";
|
|
140
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
|
|
141
|
-
* import { Serde } from "@daiso-tech/core/serde";
|
|
142
|
-
* import { BaseEvent } from "@daiso-tech/core/event-bus/contracts";
|
|
143
|
-
*
|
|
144
|
-
* const serde: IFlexibleSerde = new Serde(new SuperJsonSerdeAdapter());
|
|
145
|
-
*
|
|
146
|
-
* class AddEvent extends BaseEvent<{ a: number; b: number }> {}
|
|
147
|
-
*
|
|
148
|
-
* serde.registerEvent(AddEvent);
|
|
149
|
-
*
|
|
150
|
-
* const event = new AddEvent({ a: 1, b: 2 });
|
|
151
|
-
* const deserializedEvent = serde.deserialize<AddEvent>(serde.serialize(event));
|
|
152
|
-
*
|
|
153
|
-
* // Will print 1
|
|
154
|
-
* console.log(deserializedEvent.fields.a);
|
|
155
|
-
*
|
|
156
|
-
* // Will print 2
|
|
157
|
-
* console.log(deserializedEvent.fields.b);
|
|
158
|
-
*
|
|
159
|
-
* // Will print true
|
|
160
|
-
* console.log(deserializedEvent instanceof AddEvent);
|
|
161
|
-
*
|
|
162
|
-
* // Will print false
|
|
163
|
-
* console.log(event === deserializedEvent);
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
registerEvent(eventClass, prefix) {
|
|
167
|
-
return this.registerCustom({
|
|
168
|
-
name: eventClass.name,
|
|
169
|
-
isApplicable(value) {
|
|
170
|
-
return value instanceof BaseEvent;
|
|
171
|
-
},
|
|
172
|
-
serialize(deserializedValue) {
|
|
173
|
-
return deserializedValue.fields;
|
|
174
|
-
},
|
|
175
|
-
deserialize(serializedValue) {
|
|
176
|
-
return new eventClass(serializedValue);
|
|
177
|
-
},
|
|
178
|
-
}, prefix);
|
|
179
|
-
}
|
|
180
135
|
/**
|
|
181
136
|
* @example
|
|
182
137
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serde.js","sourceRoot":"","sources":["../../../../src/serde/implementations/derivables/serde.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACH,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"serde.js","sourceRoot":"","sources":["../../../../src/serde/implementations/derivables/serde.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACH,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,gCAAgC,C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;SACzD,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -5,7 +5,7 @@ import { type TestAPI, type ExpectStatic } from "vitest";
|
|
|
5
5
|
import type { IFlexibleSerdeAdapter } from "../../../serde/contracts/_module-exports.js";
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
|
-
* IMPORT_PATH:
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/test-utilities"`
|
|
9
9
|
* @group TestUtilities
|
|
10
10
|
*/
|
|
11
11
|
export type FlexibleSerdeAdapterSuiteSettings = {
|
|
@@ -14,9 +14,9 @@ export type FlexibleSerdeAdapterSuiteSettings = {
|
|
|
14
14
|
createAdapter: () => IFlexibleSerdeAdapter;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* The
|
|
17
|
+
* The `flexibleSerdeAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link IFlexibleSerdeAdapter | `IFlexibleSerdeAdapter`} with `vitest`.
|
|
18
18
|
*
|
|
19
|
-
* IMPORT_PATH:
|
|
19
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/test-utilities"`
|
|
20
20
|
* @group TestUtilities
|
|
21
21
|
* @example
|
|
22
22
|
* ```ts
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { beforeEach } from "vitest";
|
|
5
5
|
/**
|
|
6
|
-
* The
|
|
6
|
+
* The `flexibleSerdeAdapterTestSuite` function simplifies the process of testing your custom implementation of {@link IFlexibleSerdeAdapter | `IFlexibleSerdeAdapter`} with `vitest`.
|
|
7
7
|
*
|
|
8
|
-
* IMPORT_PATH:
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/test-utilities"`
|
|
9
9
|
* @group TestUtilities
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -5,7 +5,7 @@ import { type TestAPI, type ExpectStatic } from "vitest";
|
|
|
5
5
|
import type { IFlexibleSerde } from "../../../serde/contracts/_module-exports.js";
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
|
-
* IMPORT_PATH:
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/test-utilities"`
|
|
9
9
|
* @group TestUtilities
|
|
10
10
|
*/
|
|
11
11
|
export type FlexibleSerdeSuiteSettings = {
|
|
@@ -14,9 +14,9 @@ export type FlexibleSerdeSuiteSettings = {
|
|
|
14
14
|
createSerde: () => IFlexibleSerde;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* The
|
|
17
|
+
* The `flexibleSerdeTestSuite` function simplifies the process of testing your custom implementation of {@link IFlexibleSerde | `IFlexibleSerde`} with `vitest`.
|
|
18
18
|
*
|
|
19
|
-
* IMPORT_PATH:
|
|
19
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/test-utilities"`
|
|
20
20
|
* @group TestUtilities
|
|
21
21
|
* @example
|
|
22
22
|
* ```ts
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { beforeEach } from "vitest";
|
|
5
5
|
/**
|
|
6
|
-
* The
|
|
6
|
+
* The `flexibleSerdeTestSuite` function simplifies the process of testing your custom implementation of {@link IFlexibleSerde | `IFlexibleSerde`} with `vitest`.
|
|
7
7
|
*
|
|
8
|
-
* IMPORT_PATH:
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/serde/test-utilities"`
|
|
9
9
|
* @group TestUtilities
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from "../../utilities/classes/key-prefixer/_module.js";
|
|
2
2
|
export * from "../../utilities/classes/kysely-table-name-transformer-plugin/_module.js";
|
|
3
|
-
export * from "../../utilities/classes/
|
|
3
|
+
export * from "../../utilities/classes/hooks/_module.js";
|
|
4
4
|
export * from "../../utilities/classes/time-span/_module.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "../../utilities/classes/key-prefixer/_module.js";
|
|
2
2
|
export * from "../../utilities/classes/kysely-table-name-transformer-plugin/_module.js";
|
|
3
|
-
export * from "../../utilities/classes/
|
|
3
|
+
export * from "../../utilities/classes/hooks/_module.js";
|
|
4
4
|
export * from "../../utilities/classes/time-span/_module.js";
|
|
5
5
|
//# sourceMappingURL=_module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/utilities/classes/_module.ts"],"names":[],"mappings":"AAAA,cAAc,6CAA6C,CAAC;AAC5D,cAAc,qEAAqE,CAAC;AACpF,cAAc
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/utilities/classes/_module.ts"],"names":[],"mappings":"AAAA,cAAc,6CAA6C,CAAC;AAC5D,cAAc,qEAAqE,CAAC;AACpF,cAAc,sCAAsC,CAAC;AACrD,cAAc,0CAA0C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/utilities/classes/hooks/_module.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Utilities
|
|
3
|
+
*/
|
|
4
|
+
import { type IInvokableObject, type Invokable, type InvokableFn, type OneOrMore, type Promisable } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import type { HookContext } from "../../../utilities/classes/hooks/types.js";
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
9
|
+
* @group Hooks
|
|
10
|
+
*/
|
|
11
|
+
export type GetSignal<TParameters extends unknown[] = unknown[]> = Invokable<[
|
|
12
|
+
arguments_: TParameters
|
|
13
|
+
], AbortSignal | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
17
|
+
* @group Hooks
|
|
18
|
+
*/
|
|
19
|
+
export type ForwardSignal<TParameters> = Invokable<[
|
|
20
|
+
arguments_: TParameters,
|
|
21
|
+
signal: AbortSignal
|
|
22
|
+
], void>;
|
|
23
|
+
/**
|
|
24
|
+
* With {@link AbortSignalBinder | `AbortSignalBinder`}, you can bind an {@link AbortSignal | `AbortSignal`} to the middleware, enabling two-way abortion control.
|
|
25
|
+
* This means the middleware can abort the function, or the function can abort the middleware if the input function supports an {@link AbortSignal | `AbortSignal`}.
|
|
26
|
+
*
|
|
27
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
28
|
+
* @group Hooks
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { AsyncHooks } from "@daiso-tech/core/utilities";
|
|
33
|
+
*
|
|
34
|
+
* const abortController = new AbortController();
|
|
35
|
+
*
|
|
36
|
+
* // You can abort the function based on by your on criteria
|
|
37
|
+
* abortController.abort("Aborted") // Remove this code if you want the function to aborted after 2 seconds by the middleware.
|
|
38
|
+
*
|
|
39
|
+
* const data = await new AsyncHooks(async (url: string, signal?: AbortSignal): Promise<unknown> => {
|
|
40
|
+
* const response = await fetch(url, { signal });
|
|
41
|
+
* return await response.json();
|
|
42
|
+
* }, [
|
|
43
|
+
* (args, next, { abort, signal }) => {
|
|
44
|
+
* // We abort the function when it execdes 2 seconds.
|
|
45
|
+
* const id = setTimeout(() => abort("Timed out"), 2000);
|
|
46
|
+
* // We remove the timeout if function is aborted before it execdes 2 seconds.
|
|
47
|
+
* signal.addEventListener("abort", () => clearTimeout(id), { once: true });
|
|
48
|
+
* return next(...args);
|
|
49
|
+
* }
|
|
50
|
+
* ], {
|
|
51
|
+
* signalBinder: {
|
|
52
|
+
* getSignal: (args) => args[1],
|
|
53
|
+
* forwardSignal: (args, signal) => {
|
|
54
|
+
* args[1] = signal;
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* })
|
|
58
|
+
* .invoke("url", abortController.signal);
|
|
59
|
+
*
|
|
60
|
+
* console.log("DATA:", data)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export type AbortSignalBinder<TParameters extends unknown[] = unknown[]> = {
|
|
64
|
+
getSignal: GetSignal<TParameters>;
|
|
65
|
+
forwardSignal: ForwardSignal<TParameters>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
70
|
+
* @group Hooks
|
|
71
|
+
*/
|
|
72
|
+
export type AsyncNextFunc<TParameters extends unknown[] = unknown[], TReturn = unknown> = InvokableFn<TParameters, PromiseLike<TReturn>>;
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
76
|
+
* @group Hooks
|
|
77
|
+
*/
|
|
78
|
+
export type AsyncContext<TContext extends HookContext = HookContext> = {
|
|
79
|
+
name: string;
|
|
80
|
+
context: TContext;
|
|
81
|
+
abort: (error: unknown) => void;
|
|
82
|
+
signal: AbortSignal;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
87
|
+
* @group Hooks
|
|
88
|
+
*/
|
|
89
|
+
export type AsyncMiddlewareFn<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = InvokableFn<[
|
|
90
|
+
arguments_: TParameters,
|
|
91
|
+
next: AsyncNextFunc<TParameters, TReturn>,
|
|
92
|
+
settings: AsyncContext<TContext>
|
|
93
|
+
], Promisable<TReturn>>;
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
97
|
+
* @group Hooks
|
|
98
|
+
*/
|
|
99
|
+
export type IAsyncMiddlewareObject<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = IInvokableObject<[
|
|
100
|
+
arguments_: TParameters,
|
|
101
|
+
next: AsyncNextFunc<TParameters, TReturn>,
|
|
102
|
+
settings: AsyncContext<TContext>
|
|
103
|
+
], Promisable<TReturn>>;
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
107
|
+
* @group Hooks
|
|
108
|
+
*/
|
|
109
|
+
export type AsyncMiddleware<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = IAsyncMiddlewareObject<TParameters, TReturn, TContext> | AsyncMiddlewareFn<TParameters, TReturn, TContext>;
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
113
|
+
* @group Hooks
|
|
114
|
+
*/
|
|
115
|
+
export type AsyncHooksSettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
116
|
+
/**
|
|
117
|
+
* The name of the function which can be used for logging inside the middleware.
|
|
118
|
+
* By default, it takes the function or method name. If an anonymous function is provided, the name defaults to "func".
|
|
119
|
+
*/
|
|
120
|
+
name?: string;
|
|
121
|
+
/**
|
|
122
|
+
* If the input function accepts an {@link AbortSignal | `AbortSignal`}, you can bind it to the middleware by providing an {@link AbortSignalBinder | `AbortSignalBinder`}.
|
|
123
|
+
* This enables two-way abortion control: you can either abort the function from within the middleware, or abort the middleware from the function itself.
|
|
124
|
+
*/
|
|
125
|
+
signalBinder?: AbortSignalBinder<TParameters>;
|
|
126
|
+
/**
|
|
127
|
+
* You can provide addtional context that can be used in the middleware.
|
|
128
|
+
*/
|
|
129
|
+
context?: TContext;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The `AsyncHooks` class provides a convenient way to change and inspect arguments and return value of both async and sync functions.
|
|
133
|
+
* For example `AsyncHooks` class can be used to log function arguments and return values. Note this class will always return promise and is immutable.
|
|
134
|
+
*
|
|
135
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
136
|
+
* @group Hooks
|
|
137
|
+
*/
|
|
138
|
+
export declare class AsyncHooks<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> implements IInvokableObject<TParameters, Promise<TReturn>> {
|
|
139
|
+
private readonly invokable;
|
|
140
|
+
private readonly middlewares;
|
|
141
|
+
private readonly settings;
|
|
142
|
+
private static defaultAbortSignalBinder;
|
|
143
|
+
private static resolveSignalBinder;
|
|
144
|
+
private static init;
|
|
145
|
+
private readonly func;
|
|
146
|
+
/**
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { AsyncHooks, type AsyncMiddlewareFn } from "@daiso-tech/core/utilities";
|
|
150
|
+
*
|
|
151
|
+
* function log<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn> {
|
|
152
|
+
* return async (args, next, { name: funcName }) => {
|
|
153
|
+
* console.log("FUNCTION_NAME:", funcName);
|
|
154
|
+
* console.log("ARGUMENTS:", args);
|
|
155
|
+
* const value = await next(...args);
|
|
156
|
+
* console.log("RETURN:", value);
|
|
157
|
+
* return value;
|
|
158
|
+
* }
|
|
159
|
+
* }
|
|
160
|
+
*
|
|
161
|
+
* function time<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn> {
|
|
162
|
+
* return async (args, next) => {
|
|
163
|
+
* const start = performance.now();
|
|
164
|
+
* const value = await next(...args);
|
|
165
|
+
* const end = performance.now();
|
|
166
|
+
* const time = end - start;
|
|
167
|
+
* console.log("TIME:", `${String(time)}ms`);
|
|
168
|
+
* return value;
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
*
|
|
172
|
+
* function add(a: number, b: number): number {
|
|
173
|
+
* return a + b;
|
|
174
|
+
* }
|
|
175
|
+
*
|
|
176
|
+
* const enhancedAdd = new AsyncHooks(add, [
|
|
177
|
+
* log(),
|
|
178
|
+
* time()
|
|
179
|
+
* ], {
|
|
180
|
+
* // You can provide addtional data to be used the middleware.
|
|
181
|
+
* context: {},
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* // Will log the function name, arguments and return value.
|
|
185
|
+
* // Will also log the execution time.
|
|
186
|
+
* const result = await enhancedAdd.invoke(1, 2);
|
|
187
|
+
*
|
|
188
|
+
* // Will be 3.
|
|
189
|
+
* console.log(result);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
constructor(invokable: Invokable<TParameters, Promisable<TReturn>>, middlewares: NoInfer<OneOrMore<AsyncMiddleware<TParameters, TReturn, TContext>>>, settings?: AsyncHooksSettings<TParameters, TContext>);
|
|
193
|
+
/**
|
|
194
|
+
* The `pipe` method returns a new `AsyncHooks` instance with the additional `middlewares` applied.
|
|
195
|
+
*/
|
|
196
|
+
pipe(middlewares: OneOrMore<AsyncMiddleware<TParameters, TReturn, TContext>>): AsyncHooks<TParameters, TReturn, TContext>;
|
|
197
|
+
/**
|
|
198
|
+
* The `pipeWhen` method conditionally applies additional `middlewares`, returning a new `AsyncHooks` instance only if the specified condition is met.
|
|
199
|
+
*/
|
|
200
|
+
pipeWhen(condition: boolean, middlewares: OneOrMore<AsyncMiddleware<TParameters, TReturn, TContext>>): AsyncHooks<TParameters, TReturn, TContext>;
|
|
201
|
+
/**
|
|
202
|
+
* The `toFunc` will return the function with all middlewares applied.
|
|
203
|
+
*/
|
|
204
|
+
toFunc(): InvokableFn<TParameters, PromiseLike<TReturn>>;
|
|
205
|
+
/**
|
|
206
|
+
* The `invoke` method executes the constructor's input function, applying all middlewares.
|
|
207
|
+
*/
|
|
208
|
+
invoke(...arguments_: TParameters): Promise<TReturn>;
|
|
209
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Utilities
|
|
3
|
+
*/
|
|
4
|
+
import { callInvokable, getInvokableName, resolveInvokable, resolveOneOrMore, } from "../../../utilities/_module-exports.js";
|
|
5
|
+
/**
|
|
6
|
+
* The `AsyncHooks` class provides a convenient way to change and inspect arguments and return value of both async and sync functions.
|
|
7
|
+
* For example `AsyncHooks` class can be used to log function arguments and return values. Note this class will always return promise and is immutable.
|
|
8
|
+
*
|
|
9
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
10
|
+
* @group Hooks
|
|
11
|
+
*/
|
|
12
|
+
export class AsyncHooks {
|
|
13
|
+
invokable;
|
|
14
|
+
middlewares;
|
|
15
|
+
settings;
|
|
16
|
+
static defaultAbortSignalBinder() {
|
|
17
|
+
return {
|
|
18
|
+
forwardSignal: (args) => args,
|
|
19
|
+
getSignal: () => new AbortController().signal,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static resolveSignalBinder(signalBinder, args) {
|
|
23
|
+
const outerSignal = callInvokable(signalBinder.getSignal, args) ??
|
|
24
|
+
new AbortController().signal;
|
|
25
|
+
const abortController = new AbortController();
|
|
26
|
+
const abort = (reason) => {
|
|
27
|
+
abortController.abort(reason);
|
|
28
|
+
};
|
|
29
|
+
const mergedSignal = AbortSignal.any([
|
|
30
|
+
outerSignal,
|
|
31
|
+
abortController.signal,
|
|
32
|
+
]);
|
|
33
|
+
callInvokable(signalBinder.forwardSignal, args, mergedSignal);
|
|
34
|
+
return {
|
|
35
|
+
abort,
|
|
36
|
+
changedArgs: args,
|
|
37
|
+
signal: mergedSignal,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static init(invokable, middlewares, { name = getInvokableName(invokable), signalBinder = AsyncHooks.defaultAbortSignalBinder(), context = {}, }) {
|
|
41
|
+
let func = resolveInvokable(invokable);
|
|
42
|
+
for (const hook of resolveOneOrMore(middlewares)
|
|
43
|
+
.map(resolveInvokable)
|
|
44
|
+
.reverse()) {
|
|
45
|
+
const prevFunc = func;
|
|
46
|
+
const next = async (...arguments_) => await prevFunc(...arguments_);
|
|
47
|
+
func = async (...arguments_) => {
|
|
48
|
+
const resolvedSignalBinder = AsyncHooks.resolveSignalBinder(signalBinder, arguments_);
|
|
49
|
+
return await hook(resolvedSignalBinder.changedArgs, next, {
|
|
50
|
+
name,
|
|
51
|
+
abort: (error) => {
|
|
52
|
+
resolvedSignalBinder.abort(error);
|
|
53
|
+
},
|
|
54
|
+
signal: resolvedSignalBinder.signal,
|
|
55
|
+
context,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return func;
|
|
60
|
+
}
|
|
61
|
+
func;
|
|
62
|
+
/**
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { AsyncHooks, type AsyncMiddlewareFn } from "@daiso-tech/core/utilities";
|
|
66
|
+
*
|
|
67
|
+
* function log<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn> {
|
|
68
|
+
* return async (args, next, { name: funcName }) => {
|
|
69
|
+
* console.log("FUNCTION_NAME:", funcName);
|
|
70
|
+
* console.log("ARGUMENTS:", args);
|
|
71
|
+
* const value = await next(...args);
|
|
72
|
+
* console.log("RETURN:", value);
|
|
73
|
+
* return value;
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* function time<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn> {
|
|
78
|
+
* return async (args, next) => {
|
|
79
|
+
* const start = performance.now();
|
|
80
|
+
* const value = await next(...args);
|
|
81
|
+
* const end = performance.now();
|
|
82
|
+
* const time = end - start;
|
|
83
|
+
* console.log("TIME:", `${String(time)}ms`);
|
|
84
|
+
* return value;
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* function add(a: number, b: number): number {
|
|
89
|
+
* return a + b;
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* const enhancedAdd = new AsyncHooks(add, [
|
|
93
|
+
* log(),
|
|
94
|
+
* time()
|
|
95
|
+
* ], {
|
|
96
|
+
* // You can provide addtional data to be used the middleware.
|
|
97
|
+
* context: {},
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Will log the function name, arguments and return value.
|
|
101
|
+
* // Will also log the execution time.
|
|
102
|
+
* const result = await enhancedAdd.invoke(1, 2);
|
|
103
|
+
*
|
|
104
|
+
* // Will be 3.
|
|
105
|
+
* console.log(result);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
constructor(invokable, middlewares, settings = {}) {
|
|
109
|
+
this.invokable = invokable;
|
|
110
|
+
this.middlewares = middlewares;
|
|
111
|
+
this.settings = settings;
|
|
112
|
+
this.func = AsyncHooks.init(invokable, middlewares, this.settings);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The `pipe` method returns a new `AsyncHooks` instance with the additional `middlewares` applied.
|
|
116
|
+
*/
|
|
117
|
+
pipe(middlewares) {
|
|
118
|
+
return new AsyncHooks(this.invokable, [
|
|
119
|
+
...resolveOneOrMore(this.middlewares),
|
|
120
|
+
...resolveOneOrMore(middlewares),
|
|
121
|
+
], this.settings);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The `pipeWhen` method conditionally applies additional `middlewares`, returning a new `AsyncHooks` instance only if the specified condition is met.
|
|
125
|
+
*/
|
|
126
|
+
pipeWhen(condition, middlewares) {
|
|
127
|
+
if (condition) {
|
|
128
|
+
return this.pipe(middlewares);
|
|
129
|
+
}
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The `toFunc` will return the function with all middlewares applied.
|
|
134
|
+
*/
|
|
135
|
+
toFunc() {
|
|
136
|
+
return (...args) => this.invoke(...args);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The `invoke` method executes the constructor's input function, applying all middlewares.
|
|
140
|
+
*/
|
|
141
|
+
async invoke(...arguments_) {
|
|
142
|
+
return await this.func(...arguments_);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=async-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-hooks.js","sourceRoot":"","sources":["../../../../src/utilities/classes/hooks/async-hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GAMnB,MAAM,gCAAgC,CAAC;AAsKxC;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IA6HE;IACA;IAGA;IA3Hb,MAAM,CAAC,wBAAwB;QAGnC,OAAO;YACH,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI;YAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC,MAAM;SAChD,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAC9B,YAA4C,EAC5C,IAAiB;QAEjB,MAAM,WAAW,GACb,aAAa,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC;YAC3C,IAAI,eAAe,EAAE,CAAC,MAAM,CAAC;QACjC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,CAAC,MAAe,EAAQ,EAAE;YACpC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC,CAAC;QACF,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC;YACjC,WAAW;YACX,eAAe,CAAC,MAAM;SACzB,CAAC,CAAC;QACH,aAAa,CAAC,YAAY,CAAC,aAAa,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QAC9D,OAAO;YACH,KAAK;YACL,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,YAAY;SACvB,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,IAAI,CAKf,SAAsD,EACtD,WAAuE,EACvE,EACI,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,EAClC,YAAY,GAAG,UAAU,CAAC,wBAAwB,EAAE,EACpD,OAAO,GAAG,EAAc,GACgB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