@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
|
@@ -1,64 +1,35 @@
|
|
|
1
|
-
import { retryOrFail } from "../../../async/utilities/retry/_module.js";
|
|
2
|
-
import { timeoutAndFail } from "../../../async/utilities/timeout/_module.js";
|
|
3
|
-
import { abortAndFail } from "../../../async/utilities/abort/_module.js";
|
|
4
|
-
import {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
TimeoutAsyncError, } from "../../../async/async.errors.js";
|
|
7
|
-
import {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
-
RetryAsyncError, } from "../../../async/async.errors.js";
|
|
10
|
-
import {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
AbortAsyncError, } from "../../../async/async.errors.js";
|
|
13
|
-
import { removeUndefinedProperties, resolveAsyncLazyable, resolveInvokable, SyncEventBus, } from "../../../utilities/_module-exports.js";
|
|
14
|
-
import { delay } from "../../../async/utilities/_module.js";
|
|
15
|
-
import { AbortAsyncEvent, FailureAsyncEvent, FinallyAsyncEvent, RetryAttemptAsyncEvent, RetryFailureAsyncEvent, RetryTimeoutAsyncEvent, SuccessAsyncEvent, TotalTimeoutFailureAsyncEvent, } from "../../../async/async.events.js";
|
|
16
1
|
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* - <i>setTotalTimeout</i>
|
|
25
|
-
* - <i>setAbortSignal</i>
|
|
26
|
-
*
|
|
27
|
-
* The order in which these methods are called does not have any affect. Internally, the following execution order is applied:
|
|
28
|
-
* 1. <i>setRetryTimeout</i>
|
|
29
|
-
* 2. <i>setRetryPolicy</i>
|
|
30
|
-
* 3. <i>setBackoffPolicy</i>
|
|
31
|
-
* 4. <i>setRetryAttempts</i>
|
|
32
|
-
* 5. <i>setTotalTimeout</i>
|
|
33
|
-
* 6. <i>setAbortSignal</i>
|
|
2
|
+
* @module Async
|
|
3
|
+
*/
|
|
4
|
+
import { AsyncHooks, callInvokable, resolveAsyncLazyable, } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { abortAndFail } from "../../../async/utilities/abort-and-fail/_module.js";
|
|
6
|
+
/**
|
|
7
|
+
* The `LazyPromise` class is used for creating lazy {@link PromiseLike | `PromiseLike`} object that will only execute when awaited or when `then` method is called.
|
|
8
|
+
* Note the class is immutable.
|
|
34
9
|
*
|
|
35
|
-
* IMPORT_PATH:
|
|
10
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
36
11
|
* @group Utilities
|
|
37
12
|
*/
|
|
38
13
|
export class LazyPromise {
|
|
39
14
|
/**
|
|
40
|
-
* The
|
|
15
|
+
* The `wrapFn` is convience method used for wrapping async {@link Invokable | `Invokable`} with a `LazyPromise`.
|
|
41
16
|
* @example
|
|
42
17
|
* ```ts
|
|
43
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
18
|
+
* import { LazyPromise, retry } from "@daiso-tech/core/async";
|
|
44
19
|
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
45
20
|
* import { readFile as readFileNodeJs } from "node:fs/promises";
|
|
46
21
|
*
|
|
47
22
|
* const readFile = LazyPromise.wrapFn(readFileNodeJs);
|
|
48
23
|
*
|
|
49
|
-
* const file = await readFile("none_existing_file.txt")
|
|
50
|
-
* .setRetryAttempts(4)
|
|
51
|
-
* .setRetryTimeout(TimeSpan.fromMinutes(1));
|
|
24
|
+
* const file = await readFile("none_existing_file.txt");
|
|
52
25
|
* ```
|
|
53
26
|
*/
|
|
54
|
-
static wrapFn(fn
|
|
55
|
-
return (...parameters) => new LazyPromise(() =>
|
|
27
|
+
static wrapFn(fn) {
|
|
28
|
+
return (...parameters) => new LazyPromise(() => callInvokable(fn, ...parameters));
|
|
56
29
|
}
|
|
57
30
|
/**
|
|
58
|
-
* The
|
|
31
|
+
* The `delay` method creates a {@link LazyPromise | `LazyPromise`} that will be fulfilled after given `time`.
|
|
59
32
|
*
|
|
60
|
-
* @throws {AsyncError} {@link AsyncError}
|
|
61
|
-
* @throws {AbortAsyncError} {@link AbortAsyncError}
|
|
62
33
|
* @example
|
|
63
34
|
* ```ts
|
|
64
35
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -69,37 +40,49 @@ export class LazyPromise {
|
|
|
69
40
|
* console.log("b");
|
|
70
41
|
* ```
|
|
71
42
|
*/
|
|
72
|
-
static delay(time) {
|
|
43
|
+
static delay(time, abortSignal = new AbortController().signal) {
|
|
73
44
|
return new LazyPromise(async () => {
|
|
74
|
-
|
|
45
|
+
let timeoutId = null;
|
|
46
|
+
try {
|
|
47
|
+
await abortAndFail(new Promise((resolve) => {
|
|
48
|
+
timeoutId = setTimeout(() => {
|
|
49
|
+
resolve();
|
|
50
|
+
}, time.toMilliseconds());
|
|
51
|
+
}), abortSignal);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
if (timeoutId !== null) {
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
75
58
|
});
|
|
76
59
|
}
|
|
77
60
|
/**
|
|
78
|
-
* The
|
|
61
|
+
* The `all` method works similarly to {@link Promise.all | `Promise.all`} with the key distinction that it operates lazily.
|
|
79
62
|
*/
|
|
80
|
-
static all(promises
|
|
81
|
-
return new LazyPromise(async () => Promise.all(promises)
|
|
63
|
+
static all(promises) {
|
|
64
|
+
return new LazyPromise(async () => Promise.all(promises));
|
|
82
65
|
}
|
|
83
66
|
/**
|
|
84
|
-
* The
|
|
67
|
+
* The `allSettled` method works similarly to {@link Promise.allSettled | `Promise.allSettled`} with the key distinction that it operates lazily.
|
|
85
68
|
*/
|
|
86
|
-
static allSettled(promises
|
|
87
|
-
return new LazyPromise(async () => Promise.allSettled(promises)
|
|
69
|
+
static allSettled(promises) {
|
|
70
|
+
return new LazyPromise(async () => Promise.allSettled(promises));
|
|
88
71
|
}
|
|
89
72
|
/**
|
|
90
|
-
* The
|
|
73
|
+
* The `race` method works similarly to {@link Promise.race | `Promise.race`} with the key distinction that it operates lazily.
|
|
91
74
|
*/
|
|
92
|
-
static race(promises
|
|
93
|
-
return new LazyPromise(async () => Promise.race(promises)
|
|
75
|
+
static race(promises) {
|
|
76
|
+
return new LazyPromise(async () => Promise.race(promises));
|
|
94
77
|
}
|
|
95
78
|
/**
|
|
96
|
-
* The
|
|
79
|
+
* The `any` method works similarly to {@link Promise.any | `Promise.any`} with the key distinction that it operates lazily.
|
|
97
80
|
*/
|
|
98
|
-
static any(promises
|
|
99
|
-
return new LazyPromise(async () => Promise.any(promises)
|
|
81
|
+
static any(promises) {
|
|
82
|
+
return new LazyPromise(async () => Promise.any(promises));
|
|
100
83
|
}
|
|
101
84
|
/**
|
|
102
|
-
* The
|
|
85
|
+
* The `fromCallback` is convience method used for wrapping Node js callback functions with a `LazyPromise`.
|
|
103
86
|
* @example
|
|
104
87
|
* ```ts
|
|
105
88
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -118,321 +101,55 @@ export class LazyPromise {
|
|
|
118
101
|
* console.log(file);
|
|
119
102
|
* ```
|
|
120
103
|
*/
|
|
121
|
-
static fromCallback(callback
|
|
104
|
+
static fromCallback(callback) {
|
|
122
105
|
return new LazyPromise(() => new Promise((resolve, reject) => {
|
|
123
106
|
callback(resolve, reject);
|
|
124
|
-
})
|
|
107
|
+
}));
|
|
125
108
|
}
|
|
126
109
|
promise = null;
|
|
127
|
-
|
|
128
|
-
settings;
|
|
129
|
-
eventBus = new SyncEventBus();
|
|
110
|
+
invokable;
|
|
130
111
|
/**
|
|
131
112
|
* @example
|
|
132
113
|
* ```ts
|
|
133
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
114
|
+
* import { LazyPromise, retryMiddleware } from "@daiso-tech/core/async";
|
|
134
115
|
*
|
|
135
116
|
* const promise = new LazyPromise(async () => {
|
|
136
117
|
* console.log("I am lazy");
|
|
137
|
-
* }
|
|
118
|
+
* },
|
|
119
|
+
* // You can also pass in one AsyncMiddleware or multiple (as an Array).
|
|
120
|
+
* retry()
|
|
121
|
+
* );
|
|
138
122
|
*
|
|
139
123
|
* // "I am lazy" will only logged when awaited or then method i called.
|
|
140
124
|
* await promise;
|
|
141
125
|
* ```
|
|
142
126
|
*
|
|
143
|
-
* You can pass sync or async
|
|
127
|
+
* You can pass sync or async {@link Invokable | `Invokable`}.
|
|
144
128
|
*/
|
|
145
|
-
constructor(invokable,
|
|
146
|
-
this.
|
|
147
|
-
this.settings = removeUndefinedProperties({
|
|
148
|
-
retryAttempts: null,
|
|
149
|
-
backoffPolicy: null,
|
|
150
|
-
retryPolicy: null,
|
|
151
|
-
retryTimeout: null,
|
|
152
|
-
totalTimeout: null,
|
|
153
|
-
abortSignal: null,
|
|
154
|
-
onFinally: () => { },
|
|
155
|
-
onSuccess: (_value) => { },
|
|
156
|
-
onError: () => { },
|
|
157
|
-
...settings,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
addListener(event, listener) {
|
|
161
|
-
this.eventBus.addListener(event, listener);
|
|
162
|
-
}
|
|
163
|
-
removeListener(event, listener) {
|
|
164
|
-
this.eventBus.removeListener(event, listener);
|
|
165
|
-
}
|
|
166
|
-
applyRetryTimeout() {
|
|
167
|
-
if (this.settings.retryTimeout === null) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const oldAsyncFn = this.asyncFn;
|
|
171
|
-
const newAsyncFn = async () => {
|
|
172
|
-
try {
|
|
173
|
-
if (this.settings.retryTimeout === null) {
|
|
174
|
-
throw new Error(`LazyPromise["time"] field is null`);
|
|
175
|
-
}
|
|
176
|
-
return await timeoutAndFail(oldAsyncFn, this.settings.retryTimeout);
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
if (error instanceof TimeoutAsyncError) {
|
|
180
|
-
this.eventBus.dispatch(new RetryTimeoutAsyncEvent({ error }));
|
|
181
|
-
}
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
this.asyncFn = newAsyncFn;
|
|
186
|
-
}
|
|
187
|
-
applyRetry() {
|
|
188
|
-
if (this.settings.retryAttempts === null) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
this.applyRetryTimeout();
|
|
192
|
-
const oldAsyncFn = this.asyncFn;
|
|
193
|
-
const newAsyncFn = async () => {
|
|
194
|
-
try {
|
|
195
|
-
if (this.settings.retryAttempts === null) {
|
|
196
|
-
throw new Error(`LazyPromise["attempts"] field is null`);
|
|
197
|
-
}
|
|
198
|
-
return await retryOrFail(async (attempt) => {
|
|
199
|
-
try {
|
|
200
|
-
return await oldAsyncFn();
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
this.eventBus.dispatch(new RetryAttemptAsyncEvent({
|
|
204
|
-
attempt,
|
|
205
|
-
error,
|
|
206
|
-
}));
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
}, {
|
|
210
|
-
backoffPolicy: this.settings.backoffPolicy ?? undefined,
|
|
211
|
-
retryPolicy: this.settings.retryPolicy ?? undefined,
|
|
212
|
-
maxAttempts: this.settings.retryAttempts,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
if (error instanceof RetryAsyncError) {
|
|
217
|
-
this.eventBus.dispatch(new RetryFailureAsyncEvent({ error }));
|
|
218
|
-
}
|
|
219
|
-
throw error;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
this.asyncFn = newAsyncFn;
|
|
223
|
-
}
|
|
224
|
-
applyTotalTimeout() {
|
|
225
|
-
if (this.settings.totalTimeout === null) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const oldAsyncFn = this.asyncFn;
|
|
229
|
-
const newAsyncFn = () => {
|
|
230
|
-
try {
|
|
231
|
-
if (this.settings.totalTimeout === null) {
|
|
232
|
-
throw new Error(`LazyPromise["time"] field is null`);
|
|
233
|
-
}
|
|
234
|
-
return timeoutAndFail(oldAsyncFn, this.settings.totalTimeout);
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
if (error instanceof TimeoutAsyncError) {
|
|
238
|
-
this.eventBus.dispatch(new TotalTimeoutFailureAsyncEvent({ error }));
|
|
239
|
-
}
|
|
240
|
-
throw error;
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
this.asyncFn = newAsyncFn;
|
|
244
|
-
}
|
|
245
|
-
applyAbort() {
|
|
246
|
-
if (this.settings.abortSignal === null) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const oldAsyncFn = this.asyncFn;
|
|
250
|
-
const newAsyncFn = async () => {
|
|
251
|
-
try {
|
|
252
|
-
if (this.settings.abortSignal === null) {
|
|
253
|
-
throw new Error(`LazyPromise["abortSignal"] field is null`);
|
|
254
|
-
}
|
|
255
|
-
return await abortAndFail(oldAsyncFn, this.settings.abortSignal);
|
|
256
|
-
}
|
|
257
|
-
catch (error) {
|
|
258
|
-
if (error instanceof AbortAsyncError) {
|
|
259
|
-
this.eventBus.dispatch(new AbortAsyncEvent({ error }));
|
|
260
|
-
}
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
this.asyncFn = newAsyncFn;
|
|
265
|
-
}
|
|
266
|
-
applySettings() {
|
|
267
|
-
this.applyRetry();
|
|
268
|
-
this.applyTotalTimeout();
|
|
269
|
-
this.applyAbort();
|
|
129
|
+
constructor(invokable, middlewares = []) {
|
|
130
|
+
this.invokable = new AsyncHooks(() => resolveAsyncLazyable(invokable), middlewares);
|
|
270
131
|
}
|
|
271
132
|
/**
|
|
272
|
-
* The
|
|
273
|
-
* ```ts
|
|
274
|
-
* import { LazyPromise, linearBackoffPolicy } from "@daiso-tech/core/async";
|
|
275
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
276
|
-
*
|
|
277
|
-
* const promise =
|
|
278
|
-
* new LazyPromise(async () => {
|
|
279
|
-
* console.log("A");
|
|
280
|
-
* throw new Error("Error occured!");
|
|
281
|
-
* })
|
|
282
|
-
* .setRetryAttempts(3)
|
|
283
|
-
* .setBackoffPolicy(linearBackoffPolicy())
|
|
284
|
-
*
|
|
285
|
-
* // Will log "A" 3 times and then retry error will be thrown.
|
|
286
|
-
* await promise;
|
|
287
|
-
* ```
|
|
133
|
+
* The `pipe` method returns a new `LazyPromise` instance with the additional `middlewares` applied.
|
|
288
134
|
*/
|
|
289
|
-
|
|
290
|
-
return new LazyPromise(this.
|
|
291
|
-
...this.settings,
|
|
292
|
-
backoffPolicy: policy,
|
|
293
|
-
});
|
|
135
|
+
pipe(middlewares) {
|
|
136
|
+
return new LazyPromise(this.invokable.pipe(middlewares));
|
|
294
137
|
}
|
|
295
138
|
/**
|
|
296
|
-
* The
|
|
297
|
-
* @example
|
|
298
|
-
* ```ts
|
|
299
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
300
|
-
*
|
|
301
|
-
* const promise =
|
|
302
|
-
* new LazyPromise(async () => {
|
|
303
|
-
* console.log("A");
|
|
304
|
-
* throw new Error("Error occured!");
|
|
305
|
-
* })
|
|
306
|
-
* .setRetryAttempts(3)
|
|
307
|
-
*
|
|
308
|
-
* // Will log "A" 3 times and then retry error will be thrown.
|
|
309
|
-
* await promise;
|
|
310
|
-
* ```
|
|
139
|
+
* The `pipeWhen` method conditionally applies additional `middlewares`, returning a new `LazyPromise` instance only if the specified condition is met.
|
|
311
140
|
*/
|
|
312
|
-
|
|
313
|
-
return new LazyPromise(this.
|
|
314
|
-
...this.settings,
|
|
315
|
-
retryAttempts: attempts,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* The <i>setRetryPolicy</i> method is used for setting a custom <i>{@link BackoffPolicy}</i>.
|
|
320
|
-
* @example
|
|
321
|
-
* ```ts
|
|
322
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
323
|
-
*
|
|
324
|
-
* class ErrorA extends Error {}
|
|
325
|
-
*
|
|
326
|
-
* const promise =
|
|
327
|
-
* new LazyPromise(async () => {
|
|
328
|
-
* console.log("A");
|
|
329
|
-
* throw new Error("Error occured!");
|
|
330
|
-
* })
|
|
331
|
-
* .setRetryAttempts(3)
|
|
332
|
-
* // Will only retry an error that is instance ErrorA
|
|
333
|
-
* .setRetryPolicy(error => error instanceof ErrorA)
|
|
334
|
-
*
|
|
335
|
-
* // Will log "A" 1 time and then error will be thrown.
|
|
336
|
-
* await promise;
|
|
337
|
-
* ```
|
|
338
|
-
*/
|
|
339
|
-
setRetryPolicy(policy) {
|
|
340
|
-
return new LazyPromise(this.asyncFn, {
|
|
341
|
-
...this.settings,
|
|
342
|
-
retryPolicy: policy,
|
|
343
|
-
});
|
|
141
|
+
pipeWhen(condition, middlewares) {
|
|
142
|
+
return new LazyPromise(this.invokable.pipeWhen(condition, middlewares));
|
|
344
143
|
}
|
|
345
|
-
|
|
346
|
-
* The <i>setRetryTimeout</i> method aborts the each retry if it exceeds the given <i>time</i>.
|
|
347
|
-
* @example
|
|
348
|
-
* ```ts
|
|
349
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
350
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
351
|
-
*
|
|
352
|
-
* const promise =
|
|
353
|
-
* new LazyPromise(async () => {
|
|
354
|
-
* await LazyPromise.delay(TimeSpan.fromMinutes(1));
|
|
355
|
-
* })
|
|
356
|
-
* .setRetryTimeout(TimeSpan.fromSeconds(1));
|
|
357
|
-
*
|
|
358
|
-
* // An timeout error will be thrown.
|
|
359
|
-
* await promise;
|
|
360
|
-
* ```
|
|
361
|
-
*/
|
|
362
|
-
setRetryTimeout(time) {
|
|
363
|
-
return new LazyPromise(this.asyncFn, {
|
|
364
|
-
...this.settings,
|
|
365
|
-
retryTimeout: time,
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* The <i>setTotalTimeout</i> method aborts the <i>LazyPromise</i> if it exceeds the given <i>time</i> by throwning an error.
|
|
370
|
-
* @example
|
|
371
|
-
* ```ts
|
|
372
|
-
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
373
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
374
|
-
*
|
|
375
|
-
* const promise =
|
|
376
|
-
* new LazyPromise(async () => {
|
|
377
|
-
* await LazyPromise.delay(TimeSpan.fromMinutes(1));
|
|
378
|
-
* })
|
|
379
|
-
* .setRetryTimeout(TimeSpan.fromSeconds(1));
|
|
380
|
-
*
|
|
381
|
-
* // An timeout error will be thrown.
|
|
382
|
-
* await promise;
|
|
383
|
-
* ```
|
|
384
|
-
*/
|
|
385
|
-
setTotalTimeout(time) {
|
|
386
|
-
return new LazyPromise(this.asyncFn, {
|
|
387
|
-
...this.settings,
|
|
388
|
-
totalTimeout: time,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* The <i>setAbortSignal</i> method aborts the <i>LazyPromise</i> by the passed in <i>abortSignal</i>.
|
|
393
|
-
* @example
|
|
394
|
-
* ```ts
|
|
395
|
-
* import { LazyPromise } from "@daiso-tech/core";
|
|
396
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
397
|
-
*
|
|
398
|
-
* const abortController = new AbortController();
|
|
399
|
-
* const promise =
|
|
400
|
-
* new LazyPromise(async () => {
|
|
401
|
-
* await LazyPromise.delay(TimeSpan.fromMinutes(1));
|
|
402
|
-
* })
|
|
403
|
-
* .setAbortSignal(abortController.signal);
|
|
404
|
-
*
|
|
405
|
-
* setTimeout(() => {
|
|
406
|
-
* abortController.abort();
|
|
407
|
-
* }, 1000);
|
|
408
|
-
*
|
|
409
|
-
* // An timeout error will be thrown.
|
|
410
|
-
* await promise;
|
|
411
|
-
* ```
|
|
412
|
-
*/
|
|
413
|
-
setAbortSignal(abortSignal) {
|
|
414
|
-
return new LazyPromise(this.asyncFn, {
|
|
415
|
-
...this.settings,
|
|
416
|
-
abortSignal,
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* @throws {AbortAsyncError} {@link AbortAsyncError}
|
|
421
|
-
* @throws {TimeoutAsyncError} {@link TimeoutAsyncError}
|
|
422
|
-
* @throws {RetryAsyncError} {@link RetryAsyncError}
|
|
423
|
-
*/
|
|
424
|
-
then(onfulfilled,
|
|
425
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
426
|
-
onrejected) {
|
|
427
|
-
this.applySettings();
|
|
144
|
+
then(onfulfilled, onrejected) {
|
|
428
145
|
if (this.promise === null) {
|
|
429
|
-
this.promise = this.
|
|
146
|
+
this.promise = this.invokable.invoke();
|
|
430
147
|
}
|
|
431
148
|
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
|
|
432
149
|
return this.promise.then(onfulfilled, onrejected);
|
|
433
150
|
}
|
|
434
151
|
/**
|
|
435
|
-
* The
|
|
152
|
+
* The `defer` method executes the `LazyPromise` without awaiting it.
|
|
436
153
|
* @example
|
|
437
154
|
* ```ts
|
|
438
155
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -453,21 +170,7 @@ export class LazyPromise {
|
|
|
453
170
|
* ```
|
|
454
171
|
*/
|
|
455
172
|
defer() {
|
|
456
|
-
|
|
457
|
-
this.eventBus.dispatch(new FinallyAsyncEvent({}));
|
|
458
|
-
this.eventBus.clear();
|
|
459
|
-
};
|
|
460
|
-
const onSuccess = (value) => {
|
|
461
|
-
this.eventBus.dispatch(new SuccessAsyncEvent({ value }));
|
|
462
|
-
onFinally();
|
|
463
|
-
return value;
|
|
464
|
-
};
|
|
465
|
-
const onFailure = (error) => {
|
|
466
|
-
this.eventBus.dispatch(new FailureAsyncEvent({ error }));
|
|
467
|
-
onFinally();
|
|
468
|
-
return error;
|
|
469
|
-
};
|
|
470
|
-
this.then(onSuccess, onFailure);
|
|
173
|
+
this.then(() => { });
|
|
471
174
|
}
|
|
472
175
|
}
|
|
473
176
|
//# sourceMappingURL=lazy-promise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-promise.js","sourceRoot":"","sources":["../../../../src/async/utilities/lazy-promise/lazy-promise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lazy-promise.js","sourceRoot":"","sources":["../../../../src/async/utilities/lazy-promise/lazy-promise.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../../async/utilities/promise-queue/promise-queue.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/utilities/promise-queue/_module.ts"],"names":[],"mappings":"AAAA,cAAc,kDAAkD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Async
|
|
3
|
+
*/
|
|
4
|
+
import type { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { type InvokableFn, type Promisable } from "../../../utilities/_module-exports.js";
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export type PromiseQueueSettings = {
|
|
10
|
+
maxConcurrency: number;
|
|
11
|
+
maxCapacity: number | null;
|
|
12
|
+
interval: TimeSpan;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare class PromiseQueue {
|
|
18
|
+
private readonly settings;
|
|
19
|
+
private readonly queue;
|
|
20
|
+
private readonly listeners;
|
|
21
|
+
constructor(settings: PromiseQueueSettings);
|
|
22
|
+
private start;
|
|
23
|
+
private getItems;
|
|
24
|
+
private process;
|
|
25
|
+
private enqueue;
|
|
26
|
+
private listenOnce;
|
|
27
|
+
private asPromise;
|
|
28
|
+
/**
|
|
29
|
+
* @throws {CapacityFullAsyncError} {@link CapacityFullAsyncError}
|
|
30
|
+
*/
|
|
31
|
+
add<TValue>(func: InvokableFn<[signal: AbortSignal], Promisable<TValue>>, signal: AbortSignal): Promise<TValue>;
|
|
32
|
+
}
|