@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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Async
|
|
3
|
+
*/
|
|
4
|
+
import { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { type AsyncMiddlewareFn, type HookContext } from "../../../utilities/_module-exports.js";
|
|
6
|
+
import { type Invokable } from "../../../utilities/_module-exports.js";
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
10
|
+
* @group Middleware
|
|
11
|
+
*/
|
|
12
|
+
export type OnTimeoutData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
13
|
+
waitTime: TimeSpan;
|
|
14
|
+
args: TParameters;
|
|
15
|
+
context: TContext;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
20
|
+
* @group Middleware
|
|
21
|
+
*/
|
|
22
|
+
export type OnTimeout<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnTimeoutData<TParameters, TContext>]>;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
26
|
+
* @group Middleware
|
|
27
|
+
*/
|
|
28
|
+
export type TimeoutCallbacks<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
29
|
+
/**
|
|
30
|
+
* Callback function that will be called when the timeout occurs.
|
|
31
|
+
*/
|
|
32
|
+
onTimeout?: OnTimeout<TParameters, TContext>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
37
|
+
* @group Middleware
|
|
38
|
+
*/
|
|
39
|
+
export type TimeoutSettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = TimeoutCallbacks<TParameters, TContext> & {
|
|
40
|
+
/**
|
|
41
|
+
* The maximum time to wait before automatically aborting the executing function.
|
|
42
|
+
*
|
|
43
|
+
* @default
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
46
|
+
*
|
|
47
|
+
* TimeSpan.fromSeconds(2)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
waitTime?: TimeSpan;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The `timeout` middleware automatically cancels functions after a specified time period, throwing an error when aborted.
|
|
54
|
+
* Note the original function continues executing (even if the promise fails), you'll need to provide a settings.signalBinder to forward the `AbortSignal`.
|
|
55
|
+
*
|
|
56
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
57
|
+
* @group Middleware
|
|
58
|
+
* @throws {TimeoutAsyncError} {@link TimeoutAsyncError}
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { timeout } from "@daiso-tech/core/async";
|
|
63
|
+
* import { AsyncHooks, TimeSpan } from "@daiso-tech/core/utilities";
|
|
64
|
+
*
|
|
65
|
+
* const data = await new AsyncHooks(
|
|
66
|
+
* async (url: string, signal?: AbortSignal): Promise<unknown> => {
|
|
67
|
+
* const response = await fetch(url, { signal });
|
|
68
|
+
* return await response.json();
|
|
69
|
+
* },
|
|
70
|
+
* [timeout({ waitTime: TimeSpan.fromSeconds(2) })],
|
|
71
|
+
* {
|
|
72
|
+
* signalBinder: {
|
|
73
|
+
* getSignal: (args) => args[1],
|
|
74
|
+
* forwardSignal: (args, signal) => {
|
|
75
|
+
* args[1] = signal;
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* )
|
|
80
|
+
* .invoke("URL");
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function timeout<TParameters extends unknown[], TReturn, TContext extends HookContext>(settings?: NoInfer<TimeoutSettings<TParameters, TContext>>): AsyncMiddlewareFn<TParameters, TReturn, TContext>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Async
|
|
3
|
+
*/
|
|
4
|
+
import { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import {} from "../../../utilities/_module-exports.js";
|
|
6
|
+
import { callInvokable } from "../../../utilities/_module-exports.js";
|
|
7
|
+
import { TimeoutAsyncError } from "../../../async/async.errors.js";
|
|
8
|
+
import { timeoutAndFail } from "../../../async/utilities/_module.js";
|
|
9
|
+
/**
|
|
10
|
+
* The `timeout` middleware automatically cancels functions after a specified time period, throwing an error when aborted.
|
|
11
|
+
* Note the original function continues executing (even if the promise fails), you'll need to provide a settings.signalBinder to forward the `AbortSignal`.
|
|
12
|
+
*
|
|
13
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
14
|
+
* @group Middleware
|
|
15
|
+
* @throws {TimeoutAsyncError} {@link TimeoutAsyncError}
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { timeout } from "@daiso-tech/core/async";
|
|
20
|
+
* import { AsyncHooks, TimeSpan } from "@daiso-tech/core/utilities";
|
|
21
|
+
*
|
|
22
|
+
* const data = await new AsyncHooks(
|
|
23
|
+
* async (url: string, signal?: AbortSignal): Promise<unknown> => {
|
|
24
|
+
* const response = await fetch(url, { signal });
|
|
25
|
+
* return await response.json();
|
|
26
|
+
* },
|
|
27
|
+
* [timeout({ waitTime: TimeSpan.fromSeconds(2) })],
|
|
28
|
+
* {
|
|
29
|
+
* signalBinder: {
|
|
30
|
+
* getSignal: (args) => args[1],
|
|
31
|
+
* forwardSignal: (args, signal) => {
|
|
32
|
+
* args[1] = signal;
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* )
|
|
37
|
+
* .invoke("URL");
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function timeout(settings = {}) {
|
|
41
|
+
const { waitTime = TimeSpan.fromSeconds(2), onTimeout = () => { } } = settings;
|
|
42
|
+
return async (args, next, { context, abort, signal }) => {
|
|
43
|
+
try {
|
|
44
|
+
return await timeoutAndFail(next(...args), waitTime, (error) => {
|
|
45
|
+
abort(error);
|
|
46
|
+
}, signal);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof TimeoutAsyncError) {
|
|
50
|
+
callInvokable(onTimeout, {
|
|
51
|
+
args,
|
|
52
|
+
context,
|
|
53
|
+
waitTime,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=timeout.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/timeout/timeout.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAGN,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,EAAkB,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AA+D9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,OAAO,CAKnB,WAA4D,EAAE;IAE9D,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,GAAG,EAAE,GAAE,CAAC,EAAE,GAC9D,QAAQ,CAAC;IACb,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;QACpD,IAAI,CAAC;YACD,OAAO,MAAM,cAAc,CACvB,IAAI,CAAC,GAAG,IAAI,CAAC,EACb,QAAQ,EACR,CAAC,KAAc,EAAE,EAAE;gBACf,KAAK,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,EACD,MAAM,CACT,CAAC;QACN,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,IAAI,KAAK,YAAY,iBAAiB,EAAE,CAAC;gBACrC,aAAa,CAAC,SAAS,EAAE;oBACrB,IAAI;oBACJ,OAAO;oBACP,QAAQ;iBACX,CAAC,CAAC;YACP,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export * from "../../async/utilities/abort/_module.js";
|
|
2
|
-
export * from "../../async/utilities/delay/_module.js";
|
|
1
|
+
export * from "../../async/utilities/abort-and-fail/_module.js";
|
|
3
2
|
export * from "../../async/utilities/lazy-promise/_module.js";
|
|
4
|
-
export * from "../../async/utilities/
|
|
5
|
-
export * from "../../async/utilities/timeout/_module.js";
|
|
3
|
+
export * from "../../async/utilities/promise-queue/_module.js";
|
|
4
|
+
export * from "../../async/utilities/timeout-and-fail/_module.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from "../../async/utilities/abort/_module.js";
|
|
2
|
-
export * from "../../async/utilities/delay/_module.js";
|
|
1
|
+
export * from "../../async/utilities/abort-and-fail/_module.js";
|
|
3
2
|
export * from "../../async/utilities/lazy-promise/_module.js";
|
|
4
|
-
export * from "../../async/utilities/
|
|
5
|
-
export * from "../../async/utilities/timeout/_module.js";
|
|
3
|
+
export * from "../../async/utilities/promise-queue/_module.js";
|
|
4
|
+
export * from "../../async/utilities/timeout-and-fail/_module.js";
|
|
6
5
|
//# sourceMappingURL=_module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/async/utilities/_module.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/async/utilities/_module.ts"],"names":[],"mappings":"AAAA,cAAc,6CAA6C,CAAC;AAC5D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,+CAA+C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../../async/utilities/abort-and-fail/abort-and-fail.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/utilities/abort-and-fail/_module.ts"],"names":[],"mappings":"AAAA,cAAc,oDAAoD,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import { AbortAsyncError } from "../../../async/async.errors.js";
|
|
5
4
|
/**
|
|
6
5
|
* @internal
|
|
7
6
|
*/
|
|
@@ -11,11 +10,12 @@ function abortSignalToPromise(abortSignal) {
|
|
|
11
10
|
if (reject_ === null) {
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
|
-
reject_(
|
|
13
|
+
reject_(abortSignal.reason);
|
|
15
14
|
}
|
|
16
15
|
if (abortSignal.aborted) {
|
|
17
16
|
return {
|
|
18
|
-
promise
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
18
|
+
promise: Promise.reject(abortSignal.reason),
|
|
19
19
|
abort,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -36,13 +36,13 @@ function abortSignalToPromise(abortSignal) {
|
|
|
36
36
|
/**
|
|
37
37
|
* @internal
|
|
38
38
|
*/
|
|
39
|
-
export async function abortAndFail(
|
|
39
|
+
export async function abortAndFail(promise, abortSignal) {
|
|
40
40
|
if (abortSignal.aborted) {
|
|
41
|
-
throw
|
|
41
|
+
throw abortSignal.reason;
|
|
42
42
|
}
|
|
43
43
|
const { promise: abortSignalPromise, abort } = abortSignalToPromise(abortSignal);
|
|
44
44
|
try {
|
|
45
|
-
return await Promise.race([
|
|
45
|
+
return await Promise.race([promise, abortSignalPromise]);
|
|
46
46
|
}
|
|
47
47
|
finally {
|
|
48
48
|
abortSignal.removeEventListener("abort", abort);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort-and-fail.js","sourceRoot":"","sources":["../../../../src/async/utilities/abort-and-fail/abort-and-fail.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,SAAS,oBAAoB,CACzB,WAAwB;IAKxB,IAAI,OAAO,GAAsC,IAAI,CAAC;IACtD,SAAS,KAAK;QACV,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACX,CAAC;QACD,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;QACtB,OAAO;YACH,2EAA2E;YAC3E,OAAO,EAAE,OAAO,CAAC,MAAM,CAAS,WAAW,CAAC,MAAM,CAAC;YACnD,KAAK;SACR,CAAC;IACN,CAAC;IAED,OAAO;QACH,OAAO,EAAE,IAAI,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;YACtC,OAAO,GAAG,MAAM,CAAC;YACjB,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;gBACtB,KAAK,EAAE,CAAC;gBACR,OAAO;YACX,CAAC;YACD,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE;gBACzC,IAAI,EAAE,IAAI;aACb,CAAC,CAAC;QACP,CAAC,CAAC;QACF,KAAK;KACR,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAC9B,OAA4B,EAC5B,WAAwB;IAExB,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,WAAW,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,GACxC,oBAAoB,CAAS,WAAW,CAAC,CAAC;IAC9C,IAAI,CAAC;QACD,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAC7D,CAAC;YAAS,CAAC;QACP,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;AACL,CAAC"}
|
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
5
|
-
import type { AsyncLazy, Invokable, InvokableFn, ISyncEventListenable, Promisable, TimeSpan } from "../../../utilities/_module-exports.js";
|
|
6
|
-
import type { RetryPolicy } from "../../../async/utilities/retry/_module.js";
|
|
7
|
-
import { type AsyncEvents } from "../../../async/async.events.js";
|
|
8
|
-
import type { EventClass, EventListener, EventInstance } from "../../../event-bus/contracts/event-bus.contract.js";
|
|
4
|
+
import { type AsyncLazy, type AsyncMiddleware, type Invokable, type InvokableFn, type OneOrMore, type Promisable, type TimeSpan } from "../../../utilities/_module-exports.js";
|
|
9
5
|
/**
|
|
10
6
|
*
|
|
11
|
-
* IMPORT_PATH:
|
|
12
|
-
* @group Utilities
|
|
13
|
-
*/
|
|
14
|
-
export type LazyPromiseSettings = {
|
|
15
|
-
backoffPolicy?: BackoffPolicy | null;
|
|
16
|
-
retryAttempts?: number | null;
|
|
17
|
-
retryPolicy?: RetryPolicy | null;
|
|
18
|
-
retryTimeout?: TimeSpan | null;
|
|
19
|
-
totalTimeout?: TimeSpan | null;
|
|
20
|
-
abortSignal?: AbortSignal | null;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* IMPORT_PATH: ```"@daiso-tech/core/async"```
|
|
7
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
25
8
|
* @group Utilities
|
|
26
9
|
*/
|
|
27
10
|
export type LazyPromiseResolve<TValue> = InvokableFn<[
|
|
@@ -29,13 +12,13 @@ export type LazyPromiseResolve<TValue> = InvokableFn<[
|
|
|
29
12
|
], void>;
|
|
30
13
|
/**
|
|
31
14
|
*
|
|
32
|
-
* IMPORT_PATH:
|
|
15
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
33
16
|
* @group Utilities
|
|
34
17
|
*/
|
|
35
18
|
export type LazyPromiseReject = InvokableFn<[error: unknown], void>;
|
|
36
19
|
/**
|
|
37
20
|
*
|
|
38
|
-
* IMPORT_PATH:
|
|
21
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
39
22
|
* @group Utilities
|
|
40
23
|
*/
|
|
41
24
|
export type LazyPromiseCallback<TValue> = InvokableFn<[
|
|
@@ -43,49 +26,30 @@ export type LazyPromiseCallback<TValue> = InvokableFn<[
|
|
|
43
26
|
reject: LazyPromiseReject
|
|
44
27
|
], Promisable<void>>;
|
|
45
28
|
/**
|
|
46
|
-
* The
|
|
47
|
-
*
|
|
48
|
-
* - <i>defer</i>
|
|
49
|
-
* - <i>setRetryTimeout</i>
|
|
50
|
-
* - <i>setRetryPolicy</i>
|
|
51
|
-
* - <i>setBackoffPolicy</i>
|
|
52
|
-
* - <i>setRetryAttempts</i>
|
|
53
|
-
* - <i>setTotalTimeout</i>
|
|
54
|
-
* - <i>setAbortSignal</i>
|
|
55
|
-
*
|
|
56
|
-
* The order in which these methods are called does not have any affect. Internally, the following execution order is applied:
|
|
57
|
-
* 1. <i>setRetryTimeout</i>
|
|
58
|
-
* 2. <i>setRetryPolicy</i>
|
|
59
|
-
* 3. <i>setBackoffPolicy</i>
|
|
60
|
-
* 4. <i>setRetryAttempts</i>
|
|
61
|
-
* 5. <i>setTotalTimeout</i>
|
|
62
|
-
* 6. <i>setAbortSignal</i>
|
|
29
|
+
* The `LazyPromise` class is used for creating lazy {@link PromiseLike | `PromiseLike`} object that will only execute when awaited or when `then` method is called.
|
|
30
|
+
* Note the class is immutable.
|
|
63
31
|
*
|
|
64
|
-
* IMPORT_PATH:
|
|
32
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
65
33
|
* @group Utilities
|
|
66
34
|
*/
|
|
67
|
-
export declare class LazyPromise<TValue> implements PromiseLike<TValue
|
|
35
|
+
export declare class LazyPromise<TValue> implements PromiseLike<TValue> {
|
|
68
36
|
/**
|
|
69
|
-
* The
|
|
37
|
+
* The `wrapFn` is convience method used for wrapping async {@link Invokable | `Invokable`} with a `LazyPromise`.
|
|
70
38
|
* @example
|
|
71
39
|
* ```ts
|
|
72
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
40
|
+
* import { LazyPromise, retry } from "@daiso-tech/core/async";
|
|
73
41
|
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
74
42
|
* import { readFile as readFileNodeJs } from "node:fs/promises";
|
|
75
43
|
*
|
|
76
44
|
* const readFile = LazyPromise.wrapFn(readFileNodeJs);
|
|
77
45
|
*
|
|
78
|
-
* const file = await readFile("none_existing_file.txt")
|
|
79
|
-
* .setRetryAttempts(4)
|
|
80
|
-
* .setRetryTimeout(TimeSpan.fromMinutes(1));
|
|
46
|
+
* const file = await readFile("none_existing_file.txt");
|
|
81
47
|
* ```
|
|
82
48
|
*/
|
|
83
|
-
static wrapFn<TArgs extends unknown[], TReturn>(fn: Invokable<TArgs, Promisable<TReturn
|
|
49
|
+
static wrapFn<TArgs extends unknown[], TReturn>(fn: Invokable<TArgs, Promisable<TReturn>>): InvokableFn<TArgs, LazyPromise<TReturn>>;
|
|
84
50
|
/**
|
|
85
|
-
* The
|
|
51
|
+
* The `delay` method creates a {@link LazyPromise | `LazyPromise`} that will be fulfilled after given `time`.
|
|
86
52
|
*
|
|
87
|
-
* @throws {AsyncError} {@link AsyncError}
|
|
88
|
-
* @throws {AbortAsyncError} {@link AbortAsyncError}
|
|
89
53
|
* @example
|
|
90
54
|
* ```ts
|
|
91
55
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -96,25 +60,25 @@ export declare class LazyPromise<TValue> implements PromiseLike<TValue>, ISyncEv
|
|
|
96
60
|
* console.log("b");
|
|
97
61
|
* ```
|
|
98
62
|
*/
|
|
99
|
-
static delay(time: TimeSpan): LazyPromise<void>;
|
|
63
|
+
static delay(time: TimeSpan, abortSignal?: AbortSignal): LazyPromise<void>;
|
|
100
64
|
/**
|
|
101
|
-
* The
|
|
65
|
+
* The `all` method works similarly to {@link Promise.all | `Promise.all`} with the key distinction that it operates lazily.
|
|
102
66
|
*/
|
|
103
|
-
static all<TValue>(promises: LazyPromise<TValue>[]
|
|
67
|
+
static all<TValue>(promises: LazyPromise<TValue>[]): LazyPromise<TValue[]>;
|
|
104
68
|
/**
|
|
105
|
-
* The
|
|
69
|
+
* The `allSettled` method works similarly to {@link Promise.allSettled | `Promise.allSettled`} with the key distinction that it operates lazily.
|
|
106
70
|
*/
|
|
107
|
-
static allSettled<TValue>(promises: LazyPromise<TValue>[]
|
|
71
|
+
static allSettled<TValue>(promises: LazyPromise<TValue>[]): LazyPromise<PromiseSettledResult<TValue>[]>;
|
|
108
72
|
/**
|
|
109
|
-
* The
|
|
73
|
+
* The `race` method works similarly to {@link Promise.race | `Promise.race`} with the key distinction that it operates lazily.
|
|
110
74
|
*/
|
|
111
|
-
static race<TValue>(promises: LazyPromise<TValue>[]
|
|
75
|
+
static race<TValue>(promises: LazyPromise<TValue>[]): LazyPromise<TValue>;
|
|
112
76
|
/**
|
|
113
|
-
* The
|
|
77
|
+
* The `any` method works similarly to {@link Promise.any | `Promise.any`} with the key distinction that it operates lazily.
|
|
114
78
|
*/
|
|
115
|
-
static any<TValue>(promises: LazyPromise<TValue>[]
|
|
79
|
+
static any<TValue>(promises: LazyPromise<TValue>[]): LazyPromise<TValue>;
|
|
116
80
|
/**
|
|
117
|
-
* The
|
|
81
|
+
* The `fromCallback` is convience method used for wrapping Node js callback functions with a `LazyPromise`.
|
|
118
82
|
* @example
|
|
119
83
|
* ```ts
|
|
120
84
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -133,160 +97,39 @@ export declare class LazyPromise<TValue> implements PromiseLike<TValue>, ISyncEv
|
|
|
133
97
|
* console.log(file);
|
|
134
98
|
* ```
|
|
135
99
|
*/
|
|
136
|
-
static fromCallback<TValue>(callback: LazyPromiseCallback<TValue
|
|
100
|
+
static fromCallback<TValue>(callback: LazyPromiseCallback<TValue>): LazyPromise<TValue>;
|
|
137
101
|
private promise;
|
|
138
|
-
private
|
|
139
|
-
private readonly settings;
|
|
140
|
-
private readonly eventBus;
|
|
102
|
+
private readonly invokable;
|
|
141
103
|
/**
|
|
142
104
|
* @example
|
|
143
105
|
* ```ts
|
|
144
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
106
|
+
* import { LazyPromise, retryMiddleware } from "@daiso-tech/core/async";
|
|
145
107
|
*
|
|
146
108
|
* const promise = new LazyPromise(async () => {
|
|
147
109
|
* console.log("I am lazy");
|
|
148
|
-
* }
|
|
110
|
+
* },
|
|
111
|
+
* // You can also pass in one AsyncMiddleware or multiple (as an Array).
|
|
112
|
+
* retry()
|
|
113
|
+
* );
|
|
149
114
|
*
|
|
150
115
|
* // "I am lazy" will only logged when awaited or then method i called.
|
|
151
116
|
* await promise;
|
|
152
117
|
* ```
|
|
153
118
|
*
|
|
154
|
-
* You can pass sync or async
|
|
155
|
-
*/
|
|
156
|
-
constructor(invokable: AsyncLazy<TValue>, settings?: LazyPromiseSettings);
|
|
157
|
-
addListener<TEventClass extends EventClass<AsyncEvents<TValue>>>(event: TEventClass, listener: EventListener<EventInstance<TEventClass>>): void;
|
|
158
|
-
removeListener<TEventClass extends EventClass<AsyncEvents<TValue>>>(event: TEventClass, listener: EventListener<EventInstance<TEventClass>>): void;
|
|
159
|
-
private applyRetryTimeout;
|
|
160
|
-
private applyRetry;
|
|
161
|
-
private applyTotalTimeout;
|
|
162
|
-
private applyAbort;
|
|
163
|
-
private applySettings;
|
|
164
|
-
/**
|
|
165
|
-
* The <i>setBackoffPolicy</i> method is used for setting a custom <i>{@link BackoffPolicy}</i>.
|
|
166
|
-
* ```ts
|
|
167
|
-
* import { LazyPromise, linearBackoffPolicy } from "@daiso-tech/core/async";
|
|
168
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
169
|
-
*
|
|
170
|
-
* const promise =
|
|
171
|
-
* new LazyPromise(async () => {
|
|
172
|
-
* console.log("A");
|
|
173
|
-
* throw new Error("Error occured!");
|
|
174
|
-
* })
|
|
175
|
-
* .setRetryAttempts(3)
|
|
176
|
-
* .setBackoffPolicy(linearBackoffPolicy())
|
|
177
|
-
*
|
|
178
|
-
* // Will log "A" 3 times and then retry error will be thrown.
|
|
179
|
-
* await promise;
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
setBackoffPolicy(policy: BackoffPolicy | null): LazyPromise<TValue>;
|
|
183
|
-
/**
|
|
184
|
-
* The <i>setRetryAttempts</i> method is used for setting max retry attempts.
|
|
185
|
-
* @example
|
|
186
|
-
* ```ts
|
|
187
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
188
|
-
*
|
|
189
|
-
* const promise =
|
|
190
|
-
* new LazyPromise(async () => {
|
|
191
|
-
* console.log("A");
|
|
192
|
-
* throw new Error("Error occured!");
|
|
193
|
-
* })
|
|
194
|
-
* .setRetryAttempts(3)
|
|
195
|
-
*
|
|
196
|
-
* // Will log "A" 3 times and then retry error will be thrown.
|
|
197
|
-
* await promise;
|
|
198
|
-
* ```
|
|
119
|
+
* You can pass sync or async {@link Invokable | `Invokable`}.
|
|
199
120
|
*/
|
|
200
|
-
|
|
121
|
+
constructor(invokable: AsyncLazy<TValue>, middlewares?: OneOrMore<AsyncMiddleware<[], TValue>>);
|
|
201
122
|
/**
|
|
202
|
-
* The
|
|
203
|
-
* @example
|
|
204
|
-
* ```ts
|
|
205
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
206
|
-
*
|
|
207
|
-
* class ErrorA extends Error {}
|
|
208
|
-
*
|
|
209
|
-
* const promise =
|
|
210
|
-
* new LazyPromise(async () => {
|
|
211
|
-
* console.log("A");
|
|
212
|
-
* throw new Error("Error occured!");
|
|
213
|
-
* })
|
|
214
|
-
* .setRetryAttempts(3)
|
|
215
|
-
* // Will only retry an error that is instance ErrorA
|
|
216
|
-
* .setRetryPolicy(error => error instanceof ErrorA)
|
|
217
|
-
*
|
|
218
|
-
* // Will log "A" 1 time and then error will be thrown.
|
|
219
|
-
* await promise;
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
setRetryPolicy(policy: RetryPolicy | null): LazyPromise<TValue>;
|
|
223
|
-
/**
|
|
224
|
-
* The <i>setRetryTimeout</i> method aborts the each retry if it exceeds the given <i>time</i>.
|
|
225
|
-
* @example
|
|
226
|
-
* ```ts
|
|
227
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
228
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
229
|
-
*
|
|
230
|
-
* const promise =
|
|
231
|
-
* new LazyPromise(async () => {
|
|
232
|
-
* await LazyPromise.delay(TimeSpan.fromMinutes(1));
|
|
233
|
-
* })
|
|
234
|
-
* .setRetryTimeout(TimeSpan.fromSeconds(1));
|
|
235
|
-
*
|
|
236
|
-
* // An timeout error will be thrown.
|
|
237
|
-
* await promise;
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
setRetryTimeout(time: TimeSpan | null): LazyPromise<TValue>;
|
|
241
|
-
/**
|
|
242
|
-
* The <i>setTotalTimeout</i> method aborts the <i>LazyPromise</i> if it exceeds the given <i>time</i> by throwning an error.
|
|
243
|
-
* @example
|
|
244
|
-
* ```ts
|
|
245
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
246
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
247
|
-
*
|
|
248
|
-
* const promise =
|
|
249
|
-
* new LazyPromise(async () => {
|
|
250
|
-
* await LazyPromise.delay(TimeSpan.fromMinutes(1));
|
|
251
|
-
* })
|
|
252
|
-
* .setRetryTimeout(TimeSpan.fromSeconds(1));
|
|
253
|
-
*
|
|
254
|
-
* // An timeout error will be thrown.
|
|
255
|
-
* await promise;
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
setTotalTimeout(time: TimeSpan | null): LazyPromise<TValue>;
|
|
259
|
-
/**
|
|
260
|
-
* The <i>setAbortSignal</i> method aborts the <i>LazyPromise</i> by the passed in <i>abortSignal</i>.
|
|
261
|
-
* @example
|
|
262
|
-
* ```ts
|
|
263
|
-
* import { LazyPromise } from "@daiso-tech/core";
|
|
264
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
265
|
-
*
|
|
266
|
-
* const abortController = new AbortController();
|
|
267
|
-
* const promise =
|
|
268
|
-
* new LazyPromise(async () => {
|
|
269
|
-
* await LazyPromise.delay(TimeSpan.fromMinutes(1));
|
|
270
|
-
* })
|
|
271
|
-
* .setAbortSignal(abortController.signal);
|
|
272
|
-
*
|
|
273
|
-
* setTimeout(() => {
|
|
274
|
-
* abortController.abort();
|
|
275
|
-
* }, 1000);
|
|
276
|
-
*
|
|
277
|
-
* // An timeout error will be thrown.
|
|
278
|
-
* await promise;
|
|
279
|
-
* ```
|
|
123
|
+
* The `pipe` method returns a new `LazyPromise` instance with the additional `middlewares` applied.
|
|
280
124
|
*/
|
|
281
|
-
|
|
125
|
+
pipe(middlewares: OneOrMore<AsyncMiddleware<[], TValue>>): LazyPromise<TValue>;
|
|
282
126
|
/**
|
|
283
|
-
*
|
|
284
|
-
* @throws {TimeoutAsyncError} {@link TimeoutAsyncError}
|
|
285
|
-
* @throws {RetryAsyncError} {@link RetryAsyncError}
|
|
127
|
+
* The `pipeWhen` method conditionally applies additional `middlewares`, returning a new `LazyPromise` instance only if the specified condition is met.
|
|
286
128
|
*/
|
|
129
|
+
pipeWhen(condition: boolean, middlewares: OneOrMore<AsyncMiddleware<[], TValue>>): LazyPromise<TValue>;
|
|
287
130
|
then<TResult1 = TValue, TResult2 = never>(onfulfilled?: ((value: TValue) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
288
131
|
/**
|
|
289
|
-
* The
|
|
132
|
+
* The `defer` method executes the `LazyPromise` without awaiting it.
|
|
290
133
|
* @example
|
|
291
134
|
* ```ts
|
|
292
135
|
* import { LazyPromise } from "@daiso-tech/core/async";
|