@daiso-tech/core 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -45
- package/dist/async/_module-exports.d.ts +1 -1
- package/dist/async/_module-exports.js +1 -1
- package/dist/async/_module-exports.js.map +1 -1
- package/dist/async/async.errors.d.ts +27 -19
- package/dist/async/async.errors.js +33 -20
- package/dist/async/async.errors.js.map +1 -1
- package/dist/async/backof-policies/_shared.d.ts +6 -2
- package/dist/async/backof-policies/_shared.js +1 -0
- package/dist/async/backof-policies/_shared.js.map +1 -1
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.js +1 -1
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js +1 -1
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js +1 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +1 -1
- package/dist/async/middlewares/_module.d.ts +8 -0
- package/dist/async/middlewares/_module.js +9 -0
- package/dist/async/middlewares/_module.js.map +1 -0
- package/dist/async/middlewares/_shared.d.ts +10 -0
- package/dist/async/middlewares/_shared.js +5 -0
- package/dist/async/middlewares/_shared.js.map +1 -0
- package/dist/async/middlewares/bulkhead/_module.d.ts +1 -0
- package/dist/async/middlewares/bulkhead/_module.js +2 -0
- package/dist/async/middlewares/bulkhead/_module.js.map +1 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +80 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +46 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +1 -0
- package/dist/async/middlewares/dynamic/_module.d.ts +1 -0
- package/dist/async/middlewares/dynamic/_module.js +2 -0
- package/dist/async/middlewares/dynamic/_module.js.map +1 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.d.ts +34 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.js +36 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.js.map +1 -0
- package/dist/async/middlewares/fallback/_module.d.ts +1 -0
- package/dist/async/middlewares/fallback/_module.js +2 -0
- package/dist/async/middlewares/fallback/_module.js.map +1 -0
- package/dist/async/middlewares/fallback/fallback.middleware.d.ts +78 -0
- package/dist/async/middlewares/fallback/fallback.middleware.js +52 -0
- package/dist/async/middlewares/fallback/fallback.middleware.js.map +1 -0
- package/dist/async/middlewares/hedging/_module.d.ts +2 -0
- package/dist/async/middlewares/hedging/_module.js +3 -0
- package/dist/async/middlewares/hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/_shared.d.ts +93 -0
- package/dist/async/middlewares/hedging/_shared.js +5 -0
- package/dist/async/middlewares/hedging/_shared.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js +138 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js +104 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/observe/_module.d.ts +1 -0
- package/dist/async/middlewares/observe/_module.js +2 -0
- package/dist/async/middlewares/observe/_module.js.map +1 -0
- package/dist/async/middlewares/observe/observe.middleware.d.ts +130 -0
- package/dist/async/middlewares/observe/observe.middleware.js +80 -0
- package/dist/async/middlewares/observe/observe.middleware.js.map +1 -0
- package/dist/async/middlewares/retry/_module.d.ts +1 -0
- package/dist/async/middlewares/retry/_module.js +2 -0
- package/dist/async/middlewares/retry/_module.js.map +1 -0
- package/dist/async/middlewares/retry/retry.middleware.d.ts +117 -0
- package/dist/async/middlewares/retry/retry.middleware.js +82 -0
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -0
- package/dist/async/middlewares/timeout/_module.d.ts +1 -0
- package/dist/async/middlewares/timeout/_module.js +2 -0
- package/dist/async/middlewares/timeout/_module.js.map +1 -0
- package/dist/async/middlewares/timeout/timeout.middleware.d.ts +83 -0
- package/dist/async/middlewares/timeout/timeout.middleware.js +60 -0
- package/dist/async/middlewares/timeout/timeout.middleware.js.map +1 -0
- package/dist/async/utilities/_module.d.ts +3 -4
- package/dist/async/utilities/_module.js +3 -4
- package/dist/async/utilities/_module.js.map +1 -1
- package/dist/async/utilities/abort-and-fail/_module.d.ts +1 -0
- package/dist/async/utilities/abort-and-fail/_module.js +2 -0
- package/dist/async/utilities/abort-and-fail/_module.js.map +1 -0
- package/dist/async/utilities/abort-and-fail/abort-and-fail.d.ts +7 -0
- package/dist/async/utilities/{abort → abort-and-fail}/abort-and-fail.js +6 -6
- package/dist/async/utilities/abort-and-fail/abort-and-fail.js.map +1 -0
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +37 -194
- package/dist/async/utilities/lazy-promise/lazy-promise.js +62 -359
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/async/utilities/promise-queue/_module.d.ts +1 -0
- package/dist/async/utilities/promise-queue/_module.js +2 -0
- package/dist/async/utilities/promise-queue/_module.js.map +1 -0
- package/dist/async/utilities/promise-queue/promise-queue.d.ts +32 -0
- package/dist/async/utilities/promise-queue/promise-queue.js +107 -0
- package/dist/async/utilities/promise-queue/promise-queue.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.d.ts +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.js +2 -0
- package/dist/async/utilities/timeout-and-fail/_module.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.d.ts +7 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js +19 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -0
- package/dist/cache/contracts/cache-adapter.contract.d.ts +14 -14
- package/dist/cache/contracts/cache-factory.contract.d.ts +3 -3
- package/dist/cache/contracts/cache.contract.d.ts +73 -73
- package/dist/cache/contracts/cache.errors.d.ts +7 -7
- package/dist/cache/contracts/cache.errors.js +7 -7
- package/dist/cache/contracts/cache.events.d.ts +54 -58
- package/dist/cache/contracts/cache.events.js +6 -104
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +16 -16
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +3 -9
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +3 -9
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +4 -4
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +3 -3
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +2 -2
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +2 -2
- package/dist/cache/implementations/derivables/cache/cache.d.ts +26 -27
- package/dist/cache/implementations/derivables/cache/cache.js +102 -91
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +5 -4
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +2 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +2 -2
- package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +140 -149
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +2 -2
- package/dist/collection/contracts/_shared/compartor.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/cross-join-result.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/ensure-map.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/ensure-record.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/foreach.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/map.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/modifier.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/predicate.type.d.ts +7 -7
- package/dist/collection/contracts/_shared/reduce.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/tap.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/transform.type.d.ts +2 -2
- package/dist/collection/contracts/async-collection.contract.d.ts +109 -198
- package/dist/collection/contracts/collection.contract.d.ts +103 -103
- package/dist/collection/contracts/collection.errors.d.ts +11 -11
- package/dist/collection/contracts/collection.errors.js +11 -11
- package/dist/collection/implementations/_shared.d.ts +8 -8
- package/dist/collection/implementations/_shared.js +8 -8
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.d.ts +0 -4
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js +0 -4
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js +21 -19
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +15 -19
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +15 -30
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.d.ts +3 -3
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js +18 -20
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +11 -12
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +11 -12
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +11 -11
- package/dist/collection/implementations/list-collection/list-collection.js +24 -30
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_module-exports.d.ts +0 -1
- package/dist/event-bus/contracts/_module-exports.js +0 -1
- package/dist/event-bus/contracts/_module-exports.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +13 -8
- package/dist/event-bus/contracts/event-bus-factory.contract.d.ts +6 -7
- package/dist/event-bus/contracts/event-bus-factory.contract.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.contract.d.ts +30 -41
- package/dist/event-bus/contracts/event-bus.errors.d.ts +8 -8
- package/dist/event-bus/contracts/event-bus.errors.js +8 -8
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +3 -3
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +2 -2
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +2 -2
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +2 -2
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +15 -15
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +32 -32
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +17 -10
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +13 -6
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +3 -5
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +15 -22
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.d.ts +3 -5
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +189 -209
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +9 -9
- package/dist/lock/contracts/lock-adapter.contract.d.ts +7 -7
- package/dist/lock/contracts/lock-provider-factory.contract.d.ts +4 -4
- package/dist/lock/contracts/lock-provider.contract.d.ts +14 -14
- package/dist/lock/contracts/lock.contract.d.ts +22 -22
- package/dist/lock/contracts/lock.errors.d.ts +10 -10
- package/dist/lock/contracts/lock.errors.js +10 -10
- package/dist/lock/contracts/lock.events.d.ts +45 -54
- package/dist/lock/contracts/lock.events.js +9 -91
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +3 -3
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +3 -3
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +2 -2
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +2 -2
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +3 -3
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +3 -3
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +4 -4
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +33 -33
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +30 -30
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +3 -3
- package/dist/lock/implementations/derivables/lock-provider/lock.js +77 -58
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +5 -4
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +2 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +2 -2
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +2 -2
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +214 -214
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/contracts/deserializer.contract.d.ts +2 -2
- package/dist/serde/contracts/flexible-serde-adapter.contract.d.ts +4 -4
- package/dist/serde/contracts/flexible-serde.contract.d.ts +8 -19
- package/dist/serde/contracts/serde.contract.d.ts +2 -2
- package/dist/serde/contracts/serde.errors.d.ts +4 -4
- package/dist/serde/contracts/serde.errors.js +4 -4
- package/dist/serde/contracts/serializable.contract.d.ts +2 -2
- package/dist/serde/contracts/serializer.contract.d.ts +2 -2
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +2 -2
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +2 -2
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.d.ts +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +4 -35
- package/dist/serde/implementations/derivables/serde.js +2 -47
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.d.ts +3 -3
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +2 -2
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +3 -3
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +2 -2
- package/dist/utilities/classes/_module.d.ts +1 -1
- package/dist/utilities/classes/_module.js +1 -1
- package/dist/utilities/classes/_module.js.map +1 -1
- package/dist/utilities/classes/hooks/_module.d.ts +3 -0
- package/dist/utilities/classes/hooks/_module.js +4 -0
- package/dist/utilities/classes/hooks/_module.js.map +1 -0
- package/dist/utilities/classes/hooks/async-hooks.d.ts +209 -0
- package/dist/utilities/classes/hooks/async-hooks.js +145 -0
- package/dist/utilities/classes/hooks/async-hooks.js.map +1 -0
- package/dist/utilities/classes/hooks/hooks.d.ts +139 -0
- package/dist/utilities/classes/hooks/hooks.js +116 -0
- package/dist/utilities/classes/hooks/hooks.js.map +1 -0
- package/dist/utilities/classes/hooks/types.d.ts +9 -0
- package/dist/utilities/classes/hooks/types.js +5 -0
- package/dist/utilities/classes/hooks/types.js.map +1 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.d.ts +3 -3
- package/dist/utilities/classes/key-prefixer/key-prefixer.js +4 -4
- package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -1
- package/dist/utilities/classes/time-span/time-span.d.ts +5 -5
- package/dist/utilities/classes/time-span/time-span.js +5 -5
- package/dist/utilities/contracts/_module.d.ts +0 -1
- package/dist/utilities/contracts/_module.js +0 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/contracts/deinitizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/initizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/prunable.contract.d.ts +1 -1
- package/dist/utilities/contracts/serialized-error.contract.d.ts +1 -1
- package/dist/utilities/contracts/sqlite-database.contract.d.ts +2 -2
- package/dist/utilities/errors.d.ts +5 -5
- package/dist/utilities/errors.js +5 -5
- package/dist/utilities/functions/factory.js +3 -3
- package/dist/utilities/functions/factory.js.map +1 -1
- package/dist/utilities/functions/invokable.d.ts +9 -5
- package/dist/utilities/functions/invokable.js +12 -2
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/dist/utilities/functions/lazy.d.ts +5 -0
- package/dist/utilities/functions/lazy.js +12 -3
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/types/async-iterable-value.type.d.ts +1 -1
- package/dist/utilities/types/at-least-one.type.d.ts +1 -1
- package/dist/utilities/types/factory.type.d.ts +8 -8
- package/dist/utilities/types/invokable.type.d.ts +3 -3
- package/dist/utilities/types/items.type.d.ts +1 -1
- package/dist/utilities/types/lazy.type.d.ts +5 -5
- package/dist/utilities/types/none-func.type.d.ts +1 -1
- package/dist/utilities/types/one-or-more.type.d.ts +1 -1
- package/dist/utilities/types/promiseable.type.d.ts +1 -1
- package/dist/utilities/types/result.type.d.ts +1 -1
- package/package.json +22 -2
- package/dist/async/async.events.d.ts +0 -105
- package/dist/async/async.events.js +0 -82
- package/dist/async/async.events.js.map +0 -1
- package/dist/async/utilities/abort/_module.d.ts +0 -2
- package/dist/async/utilities/abort/_module.js +0 -3
- package/dist/async/utilities/abort/_module.js.map +0 -1
- package/dist/async/utilities/abort/abort-and-fail.d.ts +0 -4
- package/dist/async/utilities/abort/abort-and-fail.js.map +0 -1
- package/dist/async/utilities/abort/abort.d.ts +0 -9
- package/dist/async/utilities/abort/abort.js +0 -18
- package/dist/async/utilities/abort/abort.js.map +0 -1
- package/dist/async/utilities/delay/_module.d.ts +0 -1
- package/dist/async/utilities/delay/_module.js +0 -2
- package/dist/async/utilities/delay/_module.js.map +0 -1
- package/dist/async/utilities/delay/delay.d.ts +0 -10
- package/dist/async/utilities/delay/delay.js +0 -34
- package/dist/async/utilities/delay/delay.js.map +0 -1
- package/dist/async/utilities/retry/_module.d.ts +0 -2
- package/dist/async/utilities/retry/_module.js +0 -3
- package/dist/async/utilities/retry/_module.js.map +0 -1
- package/dist/async/utilities/retry/retry-or-fail.d.ts +0 -29
- package/dist/async/utilities/retry/retry-or-fail.js +0 -39
- package/dist/async/utilities/retry/retry-or-fail.js.map +0 -1
- package/dist/async/utilities/retry/retry.d.ts +0 -10
- package/dist/async/utilities/retry/retry.js +0 -21
- package/dist/async/utilities/retry/retry.js.map +0 -1
- package/dist/async/utilities/timeout/_module.d.ts +0 -2
- package/dist/async/utilities/timeout/_module.js +0 -3
- package/dist/async/utilities/timeout/_module.js.map +0 -1
- package/dist/async/utilities/timeout/timeout-and-fail.d.ts +0 -5
- package/dist/async/utilities/timeout/timeout-and-fail.js +0 -28
- package/dist/async/utilities/timeout/timeout-and-fail.js.map +0 -1
- package/dist/async/utilities/timeout/timeout.d.ts +0 -10
- package/dist/async/utilities/timeout/timeout.js +0 -21
- package/dist/async/utilities/timeout/timeout.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js +0 -30
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.js +0 -36
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.d.ts +0 -9
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.js +0 -39
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.js +0 -52
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.js.map +0 -1
- package/dist/event-bus/contracts/_shared.d.ts +0 -12
- package/dist/event-bus/contracts/_shared.js +0 -15
- package/dist/event-bus/contracts/_shared.js.map +0 -1
- package/dist/utilities/classes/sync-event-bus/_module.d.ts +0 -1
- package/dist/utilities/classes/sync-event-bus/_module.js +0 -2
- package/dist/utilities/classes/sync-event-bus/_module.js.map +0 -1
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.d.ts +0 -16
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js +0 -53
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js.map +0 -1
- package/dist/utilities/contracts/sync-event-bus-listenable.d.ts +0 -13
- package/dist/utilities/contracts/sync-event-bus-listenable.js +0 -5
- package/dist/utilities/contracts/sync-event-bus-listenable.js.map +0 -1
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* @module Cache
|
|
3
3
|
*/
|
|
4
4
|
import {} from "vitest";
|
|
5
|
-
import {
|
|
5
|
+
import { KeyNotFoundCacheError, TypeCacheError, CACHE_EVENTS, } from "../../../cache/contracts/_module-exports.js";
|
|
6
6
|
import {} from "../../../utilities/_module-exports.js";
|
|
7
7
|
import { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
8
8
|
import { LazyPromise } from "../../../async/_module-exports.js";
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
10
|
+
* The `cacheTestSuite` function simplifies the process of testing your custom implementation of {@link ICache | `ICache`} with `vitest`.
|
|
11
11
|
*
|
|
12
|
-
* IMPORT_PATH:
|
|
12
|
+
* IMPORT_PATH: `"@daiso-tech/core/cache/test-utilities"`
|
|
13
13
|
* @group TestUtilities
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
@@ -460,113 +460,105 @@ export function cacheTestSuite(settings) {
|
|
|
460
460
|
});
|
|
461
461
|
describe("Event tests:", () => {
|
|
462
462
|
describe("method: exists", () => {
|
|
463
|
-
test("Should dispatch
|
|
463
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
464
464
|
let event_ = null;
|
|
465
|
-
const unsubscribe = await cache.subscribe(
|
|
465
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
466
466
|
event_ = event;
|
|
467
467
|
});
|
|
468
468
|
await cache.exists("a");
|
|
469
469
|
await LazyPromise.delay(DELAY_TIME);
|
|
470
|
-
expect(event_).
|
|
471
|
-
expect(event_?.fields.key).toBe("a");
|
|
470
|
+
expect(event_?.key).toBe("a");
|
|
472
471
|
await unsubscribe();
|
|
473
472
|
});
|
|
474
|
-
test("Should dispatch
|
|
473
|
+
test("Should dispatch FoundCacheEventt when key exists", async () => {
|
|
475
474
|
let event_ = null;
|
|
476
|
-
const unsubscribe = await cache.subscribe(
|
|
475
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.FOUND, (event) => {
|
|
477
476
|
event_ = event;
|
|
478
477
|
});
|
|
479
478
|
await cache.add("a", 1);
|
|
480
479
|
await cache.exists("a");
|
|
481
480
|
await LazyPromise.delay(DELAY_TIME);
|
|
482
|
-
expect(event_).
|
|
483
|
-
expect(event_?.
|
|
484
|
-
expect(event_?.fields.value).toBe(1);
|
|
481
|
+
expect(event_?.key).toBe("a");
|
|
482
|
+
expect(event_?.value).toBe(1);
|
|
485
483
|
await unsubscribe();
|
|
486
484
|
});
|
|
487
485
|
});
|
|
488
486
|
describe("method: missing", () => {
|
|
489
|
-
test("Should dispatch
|
|
487
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
490
488
|
let event_ = null;
|
|
491
|
-
const unsubscribe = await cache.subscribe(
|
|
489
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
492
490
|
event_ = event;
|
|
493
491
|
});
|
|
494
492
|
await cache.missing("a");
|
|
495
493
|
await LazyPromise.delay(DELAY_TIME);
|
|
496
|
-
expect(event_).
|
|
497
|
-
expect(event_?.fields.key).toBe("a");
|
|
494
|
+
expect(event_?.key).toBe("a");
|
|
498
495
|
await unsubscribe();
|
|
499
496
|
});
|
|
500
|
-
test("Should dispatch
|
|
497
|
+
test("Should dispatch FoundCacheEventt when key exists", async () => {
|
|
501
498
|
let event_ = null;
|
|
502
|
-
const unsubscribe = await cache.subscribe(
|
|
499
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.FOUND, (event) => {
|
|
503
500
|
event_ = event;
|
|
504
501
|
});
|
|
505
502
|
await cache.add("a", 1);
|
|
506
503
|
await cache.missing("a");
|
|
507
504
|
await LazyPromise.delay(DELAY_TIME);
|
|
508
|
-
expect(event_).
|
|
509
|
-
expect(event_?.
|
|
510
|
-
expect(event_?.fields.value).toBe(1);
|
|
505
|
+
expect(event_?.key).toBe("a");
|
|
506
|
+
expect(event_?.value).toBe(1);
|
|
511
507
|
await unsubscribe();
|
|
512
508
|
});
|
|
513
509
|
});
|
|
514
510
|
describe("method: get", () => {
|
|
515
|
-
test("Should dispatch
|
|
511
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
516
512
|
let event_ = null;
|
|
517
|
-
const unsubscribe = await cache.subscribe(
|
|
513
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
518
514
|
event_ = event;
|
|
519
515
|
});
|
|
520
516
|
await cache.get("a");
|
|
521
517
|
await LazyPromise.delay(DELAY_TIME);
|
|
522
|
-
expect(event_).
|
|
523
|
-
expect(event_?.fields.key).toBe("a");
|
|
518
|
+
expect(event_?.key).toBe("a");
|
|
524
519
|
await unsubscribe();
|
|
525
520
|
});
|
|
526
|
-
test("Should dispatch
|
|
521
|
+
test("Should dispatch FoundCacheEventt when key exists", async () => {
|
|
527
522
|
let event_ = null;
|
|
528
|
-
const unsubscribe = await cache.subscribe(
|
|
523
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.FOUND, (event) => {
|
|
529
524
|
event_ = event;
|
|
530
525
|
});
|
|
531
526
|
await cache.add("a", 1);
|
|
532
527
|
await cache.get("a");
|
|
533
528
|
await LazyPromise.delay(DELAY_TIME);
|
|
534
|
-
expect(event_).
|
|
535
|
-
expect(event_?.
|
|
536
|
-
expect(event_?.fields.value).toBe(1);
|
|
529
|
+
expect(event_?.key).toBe("a");
|
|
530
|
+
expect(event_?.value).toBe(1);
|
|
537
531
|
await unsubscribe();
|
|
538
532
|
});
|
|
539
533
|
});
|
|
540
534
|
describe("method: getOr", () => {
|
|
541
|
-
test("Should dispatch
|
|
535
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
542
536
|
let event_ = null;
|
|
543
|
-
const unsubscribe = await cache.subscribe(
|
|
537
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
544
538
|
event_ = event;
|
|
545
539
|
});
|
|
546
540
|
await cache.getOr("a", 1);
|
|
547
541
|
await LazyPromise.delay(DELAY_TIME);
|
|
548
|
-
expect(event_).
|
|
549
|
-
expect(event_?.fields.key).toBe("a");
|
|
542
|
+
expect(event_?.key).toBe("a");
|
|
550
543
|
await unsubscribe();
|
|
551
544
|
});
|
|
552
|
-
test("Should dispatch
|
|
545
|
+
test("Should dispatch FoundCacheEventt when key exists", async () => {
|
|
553
546
|
let event_ = null;
|
|
554
|
-
const unsubscribe = await cache.subscribe(
|
|
547
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.FOUND, (event) => {
|
|
555
548
|
event_ = event;
|
|
556
549
|
});
|
|
557
550
|
await cache.add("a", 1);
|
|
558
551
|
await cache.getOr("a", 1);
|
|
559
552
|
await LazyPromise.delay(DELAY_TIME);
|
|
560
|
-
expect(event_).
|
|
561
|
-
expect(event_?.
|
|
562
|
-
expect(event_?.fields.value).toBe(1);
|
|
553
|
+
expect(event_?.key).toBe("a");
|
|
554
|
+
expect(event_?.value).toBe(1);
|
|
563
555
|
await unsubscribe();
|
|
564
556
|
});
|
|
565
557
|
});
|
|
566
558
|
describe("method: getOrFail", () => {
|
|
567
|
-
test("Should dispatch
|
|
559
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
568
560
|
let event_ = null;
|
|
569
|
-
const unsubscribe = await cache.subscribe(
|
|
561
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
570
562
|
event_ = event;
|
|
571
563
|
});
|
|
572
564
|
try {
|
|
@@ -576,279 +568,278 @@ export function cacheTestSuite(settings) {
|
|
|
576
568
|
/* Empty */
|
|
577
569
|
}
|
|
578
570
|
await LazyPromise.delay(DELAY_TIME);
|
|
579
|
-
expect(event_).
|
|
580
|
-
expect(event_?.fields.key).toBe("a");
|
|
571
|
+
expect(event_?.key).toBe("a");
|
|
581
572
|
await unsubscribe();
|
|
582
573
|
});
|
|
583
|
-
test("Should dispatch
|
|
574
|
+
test("Should dispatch FoundCacheEventt when key exists", async () => {
|
|
584
575
|
let event_ = null;
|
|
585
|
-
const unsubscribe = await cache.subscribe(
|
|
576
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.FOUND, (event) => {
|
|
586
577
|
event_ = event;
|
|
587
578
|
});
|
|
588
579
|
await cache.add("a", 1);
|
|
589
580
|
await cache.getOrFail("a");
|
|
590
581
|
await LazyPromise.delay(DELAY_TIME);
|
|
591
|
-
expect(event_).
|
|
592
|
-
expect(event_?.
|
|
593
|
-
expect(event_?.fields.value).toBe(1);
|
|
582
|
+
expect(event_?.key).toBe("a");
|
|
583
|
+
expect(event_?.value).toBe(1);
|
|
594
584
|
await unsubscribe();
|
|
595
585
|
});
|
|
596
586
|
});
|
|
597
587
|
describe("method: add", () => {
|
|
598
|
-
test("Should dispatch
|
|
588
|
+
test("Should dispatch AddedCacheEvent when key doesnt exists", async () => {
|
|
599
589
|
let event_ = null;
|
|
600
|
-
const unsubscribe = await cache.subscribe(
|
|
601
|
-
|
|
590
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
591
|
+
if (event.type === "added") {
|
|
592
|
+
event_ = event;
|
|
593
|
+
}
|
|
602
594
|
});
|
|
603
595
|
const ttl = TimeSpan.fromMilliseconds(20);
|
|
604
596
|
await cache.add("a", 1, ttl);
|
|
605
597
|
await LazyPromise.delay(DELAY_TIME);
|
|
606
|
-
expect(event_).
|
|
607
|
-
expect(event_?.
|
|
608
|
-
expect(event_?.
|
|
609
|
-
expect(event_?.fields.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
598
|
+
expect(event_?.key).toBe("a");
|
|
599
|
+
expect(event_?.value).toBe(1);
|
|
600
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
610
601
|
await unsubscribe();
|
|
611
602
|
});
|
|
612
603
|
});
|
|
613
604
|
describe("method: update", () => {
|
|
614
|
-
test("Should dispatch
|
|
605
|
+
test("Should dispatch UpdatedCacheEvent when key exists", async () => {
|
|
615
606
|
let event_ = null;
|
|
616
|
-
const unsubscribe = await cache.subscribe(
|
|
617
|
-
|
|
607
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
608
|
+
if (event.type === "updated") {
|
|
609
|
+
event_ = event;
|
|
610
|
+
}
|
|
618
611
|
});
|
|
619
612
|
await cache.add("a", 1);
|
|
620
613
|
await cache.update("a", 2);
|
|
621
614
|
await LazyPromise.delay(DELAY_TIME);
|
|
622
|
-
expect(event_).
|
|
623
|
-
expect(event_?.
|
|
624
|
-
expect(event_?.fields.value).toBe(2);
|
|
615
|
+
expect(event_?.key).toBe("a");
|
|
616
|
+
expect(event_?.value).toBe(2);
|
|
625
617
|
await unsubscribe();
|
|
626
618
|
});
|
|
627
|
-
test("Should dispatch
|
|
619
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
628
620
|
let event_ = null;
|
|
629
|
-
const unsubscribe = await cache.subscribe(
|
|
621
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
630
622
|
event_ = event;
|
|
631
623
|
});
|
|
632
624
|
await cache.update("a", 2);
|
|
633
625
|
await LazyPromise.delay(DELAY_TIME);
|
|
634
|
-
expect(event_).
|
|
635
|
-
expect(event_?.fields.key).toBe("a");
|
|
626
|
+
expect(event_?.key).toBe("a");
|
|
636
627
|
await unsubscribe();
|
|
637
628
|
});
|
|
638
629
|
});
|
|
639
630
|
describe("method: put", () => {
|
|
640
|
-
test("Should dispatch
|
|
631
|
+
test("Should dispatch AddedCacheEvent when key doesnt exists", async () => {
|
|
641
632
|
let event_ = null;
|
|
642
|
-
const unsubscribe = await cache.subscribe(
|
|
643
|
-
|
|
633
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
634
|
+
if (event.type === "added") {
|
|
635
|
+
event_ = event;
|
|
636
|
+
}
|
|
644
637
|
});
|
|
645
638
|
const ttl = TimeSpan.fromMilliseconds(20);
|
|
646
639
|
await cache.put("a", 1, ttl);
|
|
647
640
|
await LazyPromise.delay(DELAY_TIME);
|
|
648
|
-
expect(event_).
|
|
649
|
-
expect(event_?.
|
|
650
|
-
expect(event_?.
|
|
651
|
-
expect(event_?.fields.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
641
|
+
expect(event_?.key).toBe("a");
|
|
642
|
+
expect(event_?.value).toBe(1);
|
|
643
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
652
644
|
await unsubscribe();
|
|
653
645
|
});
|
|
654
|
-
test("Should dispatch
|
|
646
|
+
test("Should dispatch UpdatedCacheEvent when key exists", async () => {
|
|
655
647
|
let event_ = null;
|
|
656
|
-
const unsubscribe = await cache.subscribe(
|
|
657
|
-
|
|
648
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
649
|
+
if (event.type === "updated") {
|
|
650
|
+
event_ = event;
|
|
651
|
+
}
|
|
658
652
|
});
|
|
659
653
|
await cache.put("a", 1);
|
|
660
654
|
await cache.put("a", 2);
|
|
661
655
|
await LazyPromise.delay(DELAY_TIME);
|
|
662
|
-
expect(event_).
|
|
663
|
-
expect(event_?.
|
|
664
|
-
expect(event_?.fields.value).toBe(2);
|
|
656
|
+
expect(event_?.key).toBe("a");
|
|
657
|
+
expect(event_?.value).toBe(2);
|
|
665
658
|
await unsubscribe();
|
|
666
659
|
});
|
|
667
660
|
});
|
|
668
661
|
describe("method: remove", () => {
|
|
669
|
-
test("Should dispatch
|
|
662
|
+
test("Should dispatch RemovedCacheEvent when key exists", async () => {
|
|
670
663
|
let event_ = null;
|
|
671
|
-
const unsubscribe = await cache.subscribe(
|
|
672
|
-
|
|
664
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
665
|
+
if (event.type === "removed") {
|
|
666
|
+
event_ = event;
|
|
667
|
+
}
|
|
673
668
|
});
|
|
674
669
|
await cache.add("a", 1);
|
|
675
670
|
await cache.remove("a");
|
|
676
671
|
await LazyPromise.delay(DELAY_TIME);
|
|
677
|
-
expect(event_).
|
|
678
|
-
expect(event_?.fields.key).toBe("a");
|
|
672
|
+
expect(event_?.key).toBe("a");
|
|
679
673
|
await unsubscribe();
|
|
680
674
|
});
|
|
681
|
-
test("Should dispatch
|
|
675
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
682
676
|
let event_ = null;
|
|
683
|
-
const unsubscribe = await cache.subscribe(
|
|
677
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
684
678
|
event_ = event;
|
|
685
679
|
});
|
|
686
680
|
await cache.remove("a");
|
|
687
681
|
await LazyPromise.delay(DELAY_TIME);
|
|
688
|
-
expect(event_).
|
|
689
|
-
expect(event_?.fields.key).toBe("a");
|
|
682
|
+
expect(event_?.key).toBe("a");
|
|
690
683
|
await unsubscribe();
|
|
691
684
|
});
|
|
692
685
|
});
|
|
693
686
|
describe("method: removeMany", () => {
|
|
694
|
-
test("Should dispatch
|
|
687
|
+
test("Should dispatch RemovedCacheEvent when key doesnt exists", async () => {
|
|
695
688
|
let event_ = null;
|
|
696
|
-
const unsubscribe = await cache.subscribe(
|
|
697
|
-
|
|
689
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
690
|
+
if (event.type === "removed") {
|
|
691
|
+
event_ = event;
|
|
692
|
+
}
|
|
698
693
|
});
|
|
699
694
|
await cache.add("a", 1);
|
|
700
695
|
await cache.removeMany(["a"]);
|
|
701
696
|
await LazyPromise.delay(DELAY_TIME);
|
|
702
|
-
expect(event_).
|
|
703
|
-
expect(event_?.fields.key).toBe("a");
|
|
697
|
+
expect(event_?.key).toBe("a");
|
|
704
698
|
await unsubscribe();
|
|
705
699
|
});
|
|
706
|
-
test("Should dispatch
|
|
700
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
707
701
|
let event_ = null;
|
|
708
|
-
const unsubscribe = await cache.subscribe(
|
|
702
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
709
703
|
event_ = event;
|
|
710
704
|
});
|
|
711
705
|
await cache.removeMany(["a"]);
|
|
712
706
|
await LazyPromise.delay(DELAY_TIME);
|
|
713
|
-
expect(event_).
|
|
714
|
-
expect(event_?.fields.key).toBe("a");
|
|
707
|
+
expect(event_?.key).toBe("a");
|
|
715
708
|
await unsubscribe();
|
|
716
709
|
});
|
|
717
710
|
});
|
|
718
711
|
describe("method: getAndRemove", () => {
|
|
719
|
-
test("Should dispatch
|
|
712
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
720
713
|
let event_ = null;
|
|
721
|
-
const unsubscribe = await cache.subscribe(
|
|
714
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
722
715
|
event_ = event;
|
|
723
716
|
});
|
|
724
717
|
await cache.getAndRemove("a");
|
|
725
718
|
await LazyPromise.delay(DELAY_TIME);
|
|
726
|
-
expect(event_).
|
|
727
|
-
expect(event_?.fields.key).toBe("a");
|
|
719
|
+
expect(event_?.key).toBe("a");
|
|
728
720
|
await unsubscribe();
|
|
729
721
|
});
|
|
730
|
-
test("Should dispatch
|
|
722
|
+
test("Should dispatch FoundCacheEventt when key exists", async () => {
|
|
731
723
|
let event_ = null;
|
|
732
|
-
const unsubscribe = await cache.subscribe(
|
|
724
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.FOUND, (event) => {
|
|
733
725
|
event_ = event;
|
|
734
726
|
});
|
|
735
727
|
await cache.add("a", 1);
|
|
736
728
|
await cache.getAndRemove("a");
|
|
737
729
|
await LazyPromise.delay(DELAY_TIME);
|
|
738
|
-
expect(event_).
|
|
739
|
-
expect(event_?.
|
|
740
|
-
expect(event_?.fields.value).toBe(1);
|
|
730
|
+
expect(event_?.key).toBe("a");
|
|
731
|
+
expect(event_?.value).toBe(1);
|
|
741
732
|
await unsubscribe();
|
|
742
733
|
});
|
|
743
|
-
test("Should dispatch
|
|
734
|
+
test("Should dispatch RemovedCacheEvent when key exists", async () => {
|
|
744
735
|
let event_ = null;
|
|
745
|
-
const unsubscribe = await cache.subscribe(
|
|
746
|
-
|
|
736
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
737
|
+
if (event.type === "removed") {
|
|
738
|
+
event_ = event;
|
|
739
|
+
}
|
|
747
740
|
});
|
|
748
741
|
await cache.add("a", 1);
|
|
749
742
|
await cache.getAndRemove("a");
|
|
750
743
|
await LazyPromise.delay(DELAY_TIME);
|
|
751
|
-
expect(event_).
|
|
752
|
-
expect(event_?.fields.key).toBe("a");
|
|
744
|
+
expect(event_?.key).toBe("a");
|
|
753
745
|
await unsubscribe();
|
|
754
746
|
});
|
|
755
747
|
});
|
|
756
748
|
describe("method: getOrAdd", () => {
|
|
757
|
-
test("Should dispatch
|
|
749
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
758
750
|
let event_ = null;
|
|
759
|
-
const unsubscribe = await cache.subscribe(
|
|
751
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
760
752
|
event_ = event;
|
|
761
753
|
});
|
|
762
754
|
await cache.getOrAdd("a", 1);
|
|
763
755
|
await LazyPromise.delay(DELAY_TIME);
|
|
764
|
-
expect(event_).
|
|
765
|
-
expect(event_?.fields.key).toBe("a");
|
|
756
|
+
expect(event_?.key).toBe("a");
|
|
766
757
|
await unsubscribe();
|
|
767
758
|
});
|
|
768
|
-
test("Should dispatch
|
|
759
|
+
test("Should dispatch FoundCacheEventt when key exists", async () => {
|
|
769
760
|
let event_ = null;
|
|
770
|
-
const unsubscribe = await cache.subscribe(
|
|
761
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.FOUND, (event) => {
|
|
771
762
|
event_ = event;
|
|
772
763
|
});
|
|
773
764
|
await cache.add("a", 1);
|
|
774
765
|
await cache.getOrAdd("a", 1);
|
|
775
766
|
await LazyPromise.delay(DELAY_TIME);
|
|
776
|
-
expect(event_).
|
|
777
|
-
expect(event_?.
|
|
778
|
-
expect(event_?.fields.value).toBe(1);
|
|
767
|
+
expect(event_?.key).toBe("a");
|
|
768
|
+
expect(event_?.value).toBe(1);
|
|
779
769
|
await unsubscribe();
|
|
780
770
|
});
|
|
781
|
-
test("Should dispatch
|
|
771
|
+
test("Should dispatch AddedCacheEvent when key exists", async () => {
|
|
782
772
|
let event_ = null;
|
|
783
|
-
const unsubscribe = await cache.subscribe(
|
|
784
|
-
|
|
773
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
774
|
+
if (event.type === "added") {
|
|
775
|
+
event_ = event;
|
|
776
|
+
}
|
|
785
777
|
});
|
|
786
778
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
787
779
|
await cache.getOrAdd("a", 1, ttl);
|
|
788
780
|
await LazyPromise.delay(DELAY_TIME);
|
|
789
|
-
expect(event_).
|
|
790
|
-
expect(event_?.
|
|
791
|
-
expect(event_?.
|
|
792
|
-
expect(event_?.fields.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
781
|
+
expect(event_?.key).toBe("a");
|
|
782
|
+
expect(event_?.value).toBe(1);
|
|
783
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
793
784
|
await unsubscribe();
|
|
794
785
|
});
|
|
795
786
|
});
|
|
796
787
|
describe("method: increment", () => {
|
|
797
|
-
test("Should dispatch
|
|
788
|
+
test("Should dispatch IncrementedCacheEvent when key exists", async () => {
|
|
798
789
|
let event_ = null;
|
|
799
|
-
const unsubscribe = await cache.subscribe(
|
|
800
|
-
|
|
790
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
791
|
+
if (event.type === "incremented") {
|
|
792
|
+
event_ = event;
|
|
793
|
+
}
|
|
801
794
|
});
|
|
802
795
|
await cache.add("a", 1);
|
|
803
796
|
await cache.increment("a", 1);
|
|
804
797
|
await LazyPromise.delay(DELAY_TIME);
|
|
805
|
-
expect(event_).
|
|
806
|
-
expect(event_?.
|
|
807
|
-
expect(event_?.fields.value).toBe(1);
|
|
798
|
+
expect(event_?.key).toBe("a");
|
|
799
|
+
expect(event_?.value).toBe(1);
|
|
808
800
|
await unsubscribe();
|
|
809
801
|
});
|
|
810
|
-
test("Should dispatch
|
|
802
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
811
803
|
let event_ = null;
|
|
812
|
-
const unsubscribe = await cache.subscribe(
|
|
804
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
813
805
|
event_ = event;
|
|
814
806
|
});
|
|
815
807
|
await cache.increment("a", 1);
|
|
816
808
|
await LazyPromise.delay(DELAY_TIME);
|
|
817
|
-
expect(event_).
|
|
818
|
-
expect(event_?.fields.key).toBe("a");
|
|
809
|
+
expect(event_?.key).toBe("a");
|
|
819
810
|
await unsubscribe();
|
|
820
811
|
});
|
|
821
812
|
});
|
|
822
813
|
describe("method: decrement", () => {
|
|
823
|
-
test("Should dispatch
|
|
814
|
+
test("Should dispatch DecrementedCacheEvent when key exists", async () => {
|
|
824
815
|
let event_ = null;
|
|
825
|
-
const unsubscribe = await cache.subscribe(
|
|
826
|
-
|
|
816
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.WRITTEN, (event) => {
|
|
817
|
+
if (event.type === "decremented") {
|
|
818
|
+
event_ = event;
|
|
819
|
+
}
|
|
827
820
|
});
|
|
828
821
|
await cache.add("a", 1);
|
|
829
822
|
await cache.decrement("a", 1);
|
|
830
823
|
await LazyPromise.delay(DELAY_TIME);
|
|
831
|
-
expect(event_).
|
|
832
|
-
expect(event_?.
|
|
833
|
-
expect(event_?.fields.value).toBe(1);
|
|
824
|
+
expect(event_?.key).toBe("a");
|
|
825
|
+
expect(event_?.value).toBe(1);
|
|
834
826
|
await unsubscribe();
|
|
835
827
|
});
|
|
836
|
-
test("Should dispatch
|
|
828
|
+
test("Should dispatch NotFoundCacheEvent when key doesnt exists", async () => {
|
|
837
829
|
let event_ = null;
|
|
838
|
-
const unsubscribe = await cache.subscribe(
|
|
830
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.NOT_FOUND, (event) => {
|
|
839
831
|
event_ = event;
|
|
840
832
|
});
|
|
841
833
|
await cache.decrement("a", 1);
|
|
842
834
|
await LazyPromise.delay(DELAY_TIME);
|
|
843
|
-
expect(event_).
|
|
844
|
-
expect(event_?.fields.key).toBe("a");
|
|
835
|
+
expect(event_?.key).toBe("a");
|
|
845
836
|
await unsubscribe();
|
|
846
837
|
});
|
|
847
838
|
});
|
|
848
839
|
describe("method: clear", () => {
|
|
849
|
-
test("Should dispatch
|
|
840
|
+
test("Should dispatch ClearedCacheEvent when key doesnt exists", async () => {
|
|
850
841
|
let event_ = null;
|
|
851
|
-
const unsubscribe = await cache.subscribe(
|
|
842
|
+
const unsubscribe = await cache.subscribe(CACHE_EVENTS.CLEARED, (event) => {
|
|
852
843
|
event_ = event;
|
|
853
844
|
});
|
|
854
845
|
await cache.add("a", 1);
|
|
@@ -856,8 +847,8 @@ export function cacheTestSuite(settings) {
|
|
|
856
847
|
await cache.add("c", 3);
|
|
857
848
|
await cache.clear();
|
|
858
849
|
await LazyPromise.delay(DELAY_TIME);
|
|
859
|
-
expect(event_).toBeInstanceOf(KeysClearedCacheEvent);
|
|
860
850
|
await unsubscribe();
|
|
851
|
+
expect(event_).toStrictEqual({});
|
|
861
852
|
});
|
|
862
853
|
});
|
|
863
854
|
});
|