@daiso-tech/core 0.40.0 → 0.41.1
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 +8 -1
- package/dist/backoff-policies/_module-exports.d.ts +5 -0
- package/dist/backoff-policies/_module-exports.js +6 -0
- package/dist/backoff-policies/_module-exports.js.map +1 -0
- package/dist/{async/backof-policies → backoff-policies}/_shared.d.ts +6 -7
- package/dist/{async/backof-policies → backoff-policies}/_shared.js +1 -1
- package/dist/backoff-policies/_shared.js.map +1 -0
- package/dist/backoff-policies/constant-backoff-policy/_module.d.ts +1 -0
- package/dist/backoff-policies/constant-backoff-policy/_module.js +2 -0
- package/dist/backoff-policies/constant-backoff-policy/_module.js.map +1 -0
- package/dist/{async/backof-policies → backoff-policies}/constant-backoff-policy/constant-backoff-policy.d.ts +6 -8
- package/dist/{async/backof-policies → backoff-policies}/constant-backoff-policy/constant-backoff-policy.js +8 -10
- package/dist/backoff-policies/constant-backoff-policy/constant-backoff-policy.js.map +1 -0
- package/dist/backoff-policies/exponential-backoff-policy/_module.d.ts +1 -0
- package/dist/backoff-policies/exponential-backoff-policy/_module.js +2 -0
- package/dist/backoff-policies/exponential-backoff-policy/_module.js.map +1 -0
- package/dist/{async/backof-policies → backoff-policies}/exponential-backoff-policy/exponential-backoff-policy.d.ts +7 -9
- package/dist/backoff-policies/exponential-backoff-policy/exponential-backoff-policy.js +30 -0
- package/dist/backoff-policies/exponential-backoff-policy/exponential-backoff-policy.js.map +1 -0
- package/dist/backoff-policies/linear-backoff-policy/_module.d.ts +1 -0
- package/dist/backoff-policies/linear-backoff-policy/_module.js +2 -0
- package/dist/backoff-policies/linear-backoff-policy/_module.js.map +1 -0
- package/dist/{async/backof-policies → backoff-policies}/linear-backoff-policy/linear-backoff-policy.d.ts +7 -9
- package/dist/backoff-policies/linear-backoff-policy/linear-backoff-policy.js +30 -0
- package/dist/backoff-policies/linear-backoff-policy/linear-backoff-policy.js.map +1 -0
- package/dist/backoff-policies/polynomial-backoff-policy/_module.d.ts +1 -0
- package/dist/backoff-policies/polynomial-backoff-policy/_module.js +2 -0
- package/dist/backoff-policies/polynomial-backoff-policy/_module.js.map +1 -0
- package/dist/{async/backof-policies → backoff-policies}/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +7 -9
- package/dist/backoff-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +30 -0
- package/dist/backoff-policies/polynomial-backoff-policy/polynomial-backoff-policy.js.map +1 -0
- package/dist/cache/contracts/cache-adapter.contract.d.ts +3 -3
- package/dist/cache/contracts/cache.contract.d.ts +22 -22
- package/dist/cache/contracts/cache.errors.d.ts +7 -14
- package/dist/cache/contracts/cache.errors.js +12 -24
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/contracts/cache.events.d.ts +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +4 -4
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +2 -2
- 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 +3 -2
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +3 -3
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +38 -43
- package/dist/cache/implementations/derivables/cache/cache.js +106 -101
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +3 -3
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +6 -8
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +5 -15
- 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 +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +48 -48
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +107 -107
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +2 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
- package/dist/collection/contracts/async-collection.contract.d.ts +43 -43
- package/dist/collection/contracts/collection.contract.d.ts +15 -1
- package/dist/collection/contracts/collection.contract.js +1 -3
- package/dist/collection/contracts/collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.errors.d.ts +4 -13
- package/dist/collection/contracts/collection.errors.js +4 -16
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.d.ts +6 -0
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js +3 -0
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +40 -51
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +31 -37
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.d.ts +3 -0
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js +6 -0
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +3 -3
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +5 -2
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +3 -3
- package/dist/collection/implementations/list-collection/list-collection.js +5 -2
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.contract.d.ts +10 -10
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +3 -6
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +7 -9
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +17 -24
- 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 +1 -3
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +4 -8
- 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.js +34 -32
- 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.js +195 -190
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/hooks/_module-exports.d.ts +3 -0
- package/dist/hooks/_module-exports.js +4 -0
- package/dist/hooks/_module-exports.js.map +1 -0
- package/dist/{utilities/classes/hooks → hooks}/async-hooks.d.ts +15 -26
- package/dist/{utilities/classes/hooks → hooks}/async-hooks.js +4 -6
- package/dist/hooks/async-hooks.js.map +1 -0
- package/dist/{utilities/classes/hooks → hooks}/hooks.d.ts +11 -18
- package/dist/{utilities/classes/hooks → hooks}/hooks.js +4 -5
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/{utilities/classes/hooks → hooks}/types.d.ts +2 -3
- package/dist/hooks/types.js +5 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/lock/contracts/_module-exports.d.ts +4 -2
- package/dist/lock/contracts/_module-exports.js +4 -2
- package/dist/lock/contracts/_module-exports.js.map +1 -1
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +24 -17
- package/dist/lock/contracts/lock-adapter.contract.d.ts +15 -24
- package/dist/lock/contracts/lock-adapter.contract.js +1 -10
- package/dist/lock/contracts/lock-adapter.contract.js.map +1 -1
- package/dist/lock/contracts/lock-provider.contract.d.ts +5 -5
- package/dist/lock/contracts/lock-state.contract.d.ts +52 -0
- package/dist/lock/contracts/lock-state.contract.js +14 -0
- package/dist/lock/contracts/lock-state.contract.js.map +1 -0
- package/dist/lock/contracts/lock.contract.d.ts +64 -55
- package/dist/lock/contracts/lock.errors.d.ts +13 -20
- package/dist/lock/contracts/lock.errors.js +19 -26
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/contracts/lock.events.d.ts +21 -49
- package/dist/lock/contracts/lock.events.js +2 -3
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/contracts/types.d.ts +11 -0
- package/dist/lock/contracts/types.js +5 -0
- package/dist/lock/contracts/types.js.map +1 -0
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +21 -19
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +92 -61
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +8 -5
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +33 -13
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +7 -8
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +33 -20
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +6 -5
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +7 -5
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +26 -8
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +61 -28
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +6 -5
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +33 -33
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js +4 -6
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +29 -39
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +31 -35
- 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 +5 -8
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +27 -23
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +38 -34
- package/dist/lock/implementations/derivables/lock-provider/lock.js +182 -257
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.d.ts +9 -0
- package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.js +12 -0
- package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.js.map +1 -0
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +12 -13
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +7 -16
- 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.js +310 -207
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +376 -292
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +15 -5
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +3285 -2976
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/namespace/_module-exports.d.ts +1 -0
- package/dist/namespace/_module-exports.js +2 -0
- package/dist/namespace/_module-exports.js.map +1 -0
- package/dist/namespace/namespace.d.ts +87 -0
- package/dist/namespace/namespace.js +117 -0
- package/dist/namespace/namespace.js.map +1 -0
- package/dist/resilience/_module-exports.d.ts +2 -0
- package/dist/resilience/_module-exports.js +3 -0
- package/dist/resilience/_module-exports.js.map +1 -0
- package/dist/resilience/middlewares/_module.d.ts +5 -0
- package/dist/resilience/middlewares/_module.js +6 -0
- package/dist/resilience/middlewares/_module.js.map +1 -0
- package/dist/resilience/middlewares/dynamic/_module.d.ts +1 -0
- package/dist/resilience/middlewares/dynamic/_module.js +2 -0
- package/dist/resilience/middlewares/dynamic/_module.js.map +1 -0
- package/dist/{async → resilience}/middlewares/dynamic/dynamic.middleware.d.ts +6 -6
- package/dist/{async → resilience}/middlewares/dynamic/dynamic.middleware.js +5 -5
- package/dist/resilience/middlewares/dynamic/dynamic.middleware.js.map +1 -0
- package/dist/resilience/middlewares/fallback/_module.d.ts +2 -0
- package/dist/resilience/middlewares/fallback/_module.js +3 -0
- package/dist/resilience/middlewares/fallback/_module.js.map +1 -0
- package/dist/{async → resilience}/middlewares/fallback/fallback.middleware.d.ts +9 -9
- package/dist/{async → resilience}/middlewares/fallback/fallback.middleware.js +7 -6
- package/dist/resilience/middlewares/fallback/fallback.middleware.js.map +1 -0
- package/dist/{async → resilience}/middlewares/fallback/fallback.types.d.ts +7 -6
- package/dist/{async → resilience}/middlewares/fallback/fallback.types.js +1 -1
- package/dist/resilience/middlewares/fallback/fallback.types.js.map +1 -0
- package/dist/resilience/middlewares/observe/_module.d.ts +2 -0
- package/dist/resilience/middlewares/observe/_module.js +3 -0
- package/dist/resilience/middlewares/observe/_module.js.map +1 -0
- package/dist/{async → resilience}/middlewares/observe/observe.middleware.d.ts +13 -11
- package/dist/{async → resilience}/middlewares/observe/observe.middleware.js +14 -10
- package/dist/resilience/middlewares/observe/observe.middleware.js.map +1 -0
- package/dist/{async → resilience}/middlewares/observe/observe.types.d.ts +13 -12
- package/dist/resilience/middlewares/observe/observe.types.js +5 -0
- package/dist/resilience/middlewares/observe/observe.types.js.map +1 -0
- package/dist/resilience/middlewares/retry/_module.d.ts +2 -0
- package/dist/resilience/middlewares/retry/_module.js +3 -0
- package/dist/resilience/middlewares/retry/_module.js.map +1 -0
- package/dist/{async → resilience}/middlewares/retry/retry.middleware.d.ts +12 -9
- package/dist/{async → resilience}/middlewares/retry/retry.middleware.js +19 -15
- package/dist/resilience/middlewares/retry/retry.middleware.js.map +1 -0
- package/dist/{async → resilience}/middlewares/retry/retry.types.d.ts +14 -12
- package/dist/resilience/middlewares/retry/retry.types.js +7 -0
- package/dist/resilience/middlewares/retry/retry.types.js.map +1 -0
- package/dist/resilience/middlewares/timeout/_module.d.ts +2 -0
- package/dist/resilience/middlewares/timeout/_module.js +3 -0
- package/dist/resilience/middlewares/timeout/_module.js.map +1 -0
- package/dist/{async → resilience}/middlewares/timeout/timeout.middleware.d.ts +9 -7
- package/dist/{async → resilience}/middlewares/timeout/timeout.middleware.js +12 -11
- package/dist/resilience/middlewares/timeout/timeout.middleware.js.map +1 -0
- package/dist/{async → resilience}/middlewares/timeout/timeout.type.d.ts +10 -9
- package/dist/resilience/middlewares/timeout/timeout.type.js +5 -0
- package/dist/resilience/middlewares/timeout/timeout.type.js.map +1 -0
- package/dist/resilience/resilience.errors.d.ts +40 -0
- package/dist/resilience/resilience.errors.js +48 -0
- package/dist/resilience/resilience.errors.js.map +1 -0
- package/dist/resilience/utilities/_module.d.ts +2 -0
- package/dist/resilience/utilities/_module.js +3 -0
- package/dist/resilience/utilities/_module.js.map +1 -0
- package/dist/resilience/utilities/abort-and-fail/_module.d.ts +1 -0
- package/dist/resilience/utilities/abort-and-fail/_module.js +2 -0
- package/dist/resilience/utilities/abort-and-fail/_module.js.map +1 -0
- package/dist/resilience/utilities/abort-and-fail/abort-and-fail.d.ts +7 -0
- package/dist/resilience/utilities/abort-and-fail/abort-and-fail.js +51 -0
- package/dist/resilience/utilities/abort-and-fail/abort-and-fail.js.map +1 -0
- package/dist/resilience/utilities/timeout-and-fail/_module.d.ts +1 -0
- package/dist/resilience/utilities/timeout-and-fail/_module.js +2 -0
- package/dist/resilience/utilities/timeout-and-fail/_module.js.map +1 -0
- package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.d.ts +7 -0
- package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.js +23 -0
- package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -0
- package/dist/semaphore/contracts/_module-exports.d.ts +9 -0
- package/dist/semaphore/contracts/_module-exports.js +10 -0
- package/dist/semaphore/contracts/_module-exports.js.map +1 -0
- package/dist/semaphore/contracts/database-semaphore-adapter.contract.d.ts +90 -0
- package/dist/semaphore/contracts/database-semaphore-adapter.contract.js +5 -0
- package/dist/semaphore/contracts/database-semaphore-adapter.contract.js.map +1 -0
- package/dist/semaphore/contracts/semaphore-adapter.contract.d.ts +61 -0
- package/dist/semaphore/contracts/semaphore-adapter.contract.js +5 -0
- package/dist/semaphore/contracts/semaphore-adapter.contract.js.map +1 -0
- package/dist/semaphore/contracts/semaphore-provider-factory.contract.d.ts +19 -0
- package/dist/semaphore/contracts/semaphore-provider-factory.contract.js +9 -0
- package/dist/semaphore/contracts/semaphore-provider-factory.contract.js.map +1 -0
- package/dist/semaphore/contracts/semaphore-provider.contract.d.ts +50 -0
- package/dist/semaphore/contracts/semaphore-provider.contract.js +5 -0
- package/dist/semaphore/contracts/semaphore-provider.contract.js.map +1 -0
- package/dist/semaphore/contracts/semaphore-state.contract.d.ts +70 -0
- package/dist/semaphore/contracts/semaphore-state.contract.js +15 -0
- package/dist/semaphore/contracts/semaphore-state.contract.js.map +1 -0
- package/dist/semaphore/contracts/semaphore.contract.d.ts +127 -0
- package/dist/semaphore/contracts/semaphore.contract.js +5 -0
- package/dist/semaphore/contracts/semaphore.contract.js.map +1 -0
- package/dist/semaphore/contracts/semaphore.errors.d.ts +52 -0
- package/dist/semaphore/contracts/semaphore.errors.js +63 -0
- package/dist/semaphore/contracts/semaphore.errors.js.map +1 -0
- package/dist/semaphore/contracts/semaphore.events.d.ts +101 -0
- package/dist/semaphore/contracts/semaphore.events.js +19 -0
- package/dist/semaphore/contracts/semaphore.events.js.map +1 -0
- package/dist/semaphore/contracts/types.d.ts +11 -0
- package/dist/semaphore/contracts/types.js +5 -0
- package/dist/semaphore/contracts/types.js.map +1 -0
- package/dist/semaphore/implementations/adapters/_module-exports.d.ts +5 -0
- package/dist/semaphore/implementations/adapters/_module-exports.js +6 -0
- package/dist/semaphore/implementations/adapters/_module-exports.js.map +1 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.d.ts +97 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js +313 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.d.ts +49 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js +141 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.d.ts +80 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.js +390 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.d.ts +18 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js +30 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.d.ts +48 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.js +338 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/_module-exports.d.ts +2 -0
- package/dist/semaphore/implementations/derivables/_module-exports.js +3 -0
- package/dist/semaphore/implementations/derivables/_module-exports.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/_module.d.ts +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/_module.js +2 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/_module.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.d.ts +17 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.js +74 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.d.ts +8 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.js +15 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.d.ts +8 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.js +15 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.d.ts +149 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js +135 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.d.ts +41 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js +77 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.d.ts +83 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js +336 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.d.ts +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.js +2 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.d.ts +40 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js +67 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +1 -0
- package/dist/semaphore/implementations/test-utilities/_module-exports.d.ts +3 -0
- package/dist/semaphore/implementations/test-utilities/_module-exports.js +4 -0
- package/dist/semaphore/implementations/test-utilities/_module-exports.js.map +1 -0
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.d.ts +59 -0
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js +536 -0
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js.map +1 -0
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.d.ts +59 -0
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js +961 -0
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js.map +1 -0
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.d.ts +67 -0
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js +4981 -0
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js.map +1 -0
- package/dist/serde/contracts/_module-exports.d.ts +0 -1
- package/dist/serde/contracts/_module-exports.js +0 -1
- package/dist/serde/contracts/_module-exports.js.map +1 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +21 -5
- package/dist/serde/contracts/serde.errors.d.ts +14 -11
- package/dist/serde/contracts/serde.errors.js +15 -14
- package/dist/serde/contracts/serde.errors.js.map +1 -1
- package/dist/serde/implementations/adapters/_module-exports.d.ts +0 -3
- package/dist/serde/implementations/adapters/_module-exports.js +0 -3
- package/dist/serde/implementations/adapters/_module-exports.js.map +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +6 -0
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js.map +1 -1
- package/dist/serde/implementations/derivables/serde-transformers.d.ts +38 -30
- package/dist/serde/implementations/derivables/serde-transformers.js +62 -20
- package/dist/serde/implementations/derivables/serde-transformers.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +12 -3
- package/dist/serde/implementations/derivables/serde.js +5 -2
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +85 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +85 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js.map +1 -1
- package/dist/shared-lock/contracts/_module-exports.d.ts +10 -0
- package/dist/shared-lock/contracts/_module-exports.js +11 -0
- package/dist/shared-lock/contracts/_module-exports.js.map +1 -0
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.d.ts +145 -0
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.js +5 -0
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.d.ts +96 -0
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.js +5 -0
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.d.ts +19 -0
- package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.js +9 -0
- package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock-provider.contract.d.ts +53 -0
- package/dist/shared-lock/contracts/shared-lock-provider.contract.js +5 -0
- package/dist/shared-lock/contracts/shared-lock-provider.contract.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock-state.contract.d.ts +133 -0
- package/dist/shared-lock/contracts/shared-lock-state.contract.js +33 -0
- package/dist/shared-lock/contracts/shared-lock-state.contract.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock.contract.d.ts +222 -0
- package/dist/shared-lock/contracts/shared-lock.contract.js +13 -0
- package/dist/shared-lock/contracts/shared-lock.contract.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock.errors.d.ts +124 -0
- package/dist/shared-lock/contracts/shared-lock.errors.js +136 -0
- package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock.events.d.ts +205 -0
- package/dist/shared-lock/contracts/shared-lock.events.js +43 -0
- package/dist/shared-lock/contracts/shared-lock.events.js.map +1 -0
- package/dist/shared-lock/contracts/types.d.ts +10 -0
- package/dist/shared-lock/contracts/types.js +5 -0
- package/dist/shared-lock/contracts/types.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/_module-exports.d.ts +5 -0
- package/dist/shared-lock/implementations/adapters/_module-exports.js +6 -0
- package/dist/shared-lock/implementations/adapters/_module-exports.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.d.ts +114 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js +496 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.d.ts +79 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js +347 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.d.ts +112 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.js +805 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.d.ts +23 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js +42 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.d.ts +79 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.js +630 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/_module-exports.d.ts +2 -0
- package/dist/shared-lock/implementations/derivables/_module-exports.js +3 -0
- package/dist/shared-lock/implementations/derivables/_module-exports.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/_module.js +2 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/_module.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.d.ts +27 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.js +208 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.d.ts +8 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.js +12 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.d.ts +8 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.js +15 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.d.ts +190 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js +177 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.d.ts +41 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js +77 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.d.ts +95 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js +542 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/_module.js +2 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/_module.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.d.ts +97 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js +128 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +1 -0
- package/dist/shared-lock/implementations/test-utilities/_module-exports.d.ts +3 -0
- package/dist/shared-lock/implementations/test-utilities/_module-exports.js +4 -0
- package/dist/shared-lock/implementations/test-utilities/_module-exports.js.map +1 -0
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.d.ts +59 -0
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js +944 -0
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js.map +1 -0
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.d.ts +59 -0
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js +1921 -0
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js.map +1 -0
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.d.ts +67 -0
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js +9833 -0
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js.map +1 -0
- package/dist/task/_module-exports.d.ts +1 -0
- package/dist/task/_module-exports.js +2 -0
- package/dist/task/_module-exports.js.map +1 -0
- package/dist/{async/utilities/abort-and-fail → task}/abort-and-fail.d.ts +1 -1
- package/dist/{async/utilities/abort-and-fail → task}/abort-and-fail.js +1 -1
- package/dist/task/abort-and-fail.js.map +1 -0
- package/dist/task/task.d.ts +194 -0
- package/dist/task/task.js +212 -0
- package/dist/task/task.js.map +1 -0
- package/dist/time-span/contracts/_module-exports.d.ts +1 -0
- package/dist/time-span/contracts/_module-exports.js +2 -0
- package/dist/time-span/contracts/_module-exports.js.map +1 -0
- package/dist/time-span/contracts/time-span.contract.d.ts +19 -0
- package/dist/time-span/contracts/time-span.contract.js +10 -0
- package/dist/time-span/contracts/time-span.contract.js.map +1 -0
- package/dist/time-span/implementations/_module-exports.d.ts +1 -0
- package/dist/time-span/implementations/_module-exports.js +2 -0
- package/dist/time-span/implementations/_module-exports.js.map +1 -0
- package/dist/{utilities/classes/time-span → time-span/implementations}/time-span.d.ts +49 -11
- package/dist/{utilities/classes/time-span → time-span/implementations}/time-span.js +33 -11
- package/dist/time-span/implementations/time-span.js.map +1 -0
- package/dist/utilities/classes/_module.d.ts +0 -3
- package/dist/utilities/classes/_module.js +0 -3
- package/dist/utilities/classes/_module.js.map +1 -1
- package/dist/utilities/contracts/_module.d.ts +1 -1
- package/dist/utilities/contracts/_module.js +1 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/contracts/comparable.contract.d.ts +49 -0
- package/dist/utilities/contracts/comparable.contract.js +5 -0
- package/dist/utilities/contracts/comparable.contract.js.map +1 -0
- package/dist/utilities/functions/is-standard-schema.d.ts +6 -0
- package/dist/utilities/functions/is-standard-schema.js +6 -0
- package/dist/utilities/functions/is-standard-schema.js.map +1 -1
- package/dist/utilities/functions/lazy.d.ts +3 -3
- package/dist/utilities/functions/lazy.js +3 -3
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/functions/option.d.ts +3 -0
- package/dist/utilities/functions/option.js +3 -0
- package/dist/utilities/functions/option.js.map +1 -1
- package/dist/utilities/functions/validate.d.ts +5 -0
- package/dist/utilities/functions/validate.js +5 -0
- package/dist/utilities/functions/validate.js.map +1 -1
- package/dist/utilities/types/any-class.type.d.ts +6 -0
- package/dist/utilities/types/any-class.type.js +3 -0
- package/dist/utilities/types/any-class.type.js.map +1 -1
- package/package.json +67 -5
- package/dist/async/_module-exports.d.ts +0 -4
- package/dist/async/_module-exports.js +0 -5
- package/dist/async/_module-exports.js.map +0 -1
- package/dist/async/async.errors.d.ts +0 -47
- package/dist/async/async.errors.js +0 -61
- package/dist/async/async.errors.js.map +0 -1
- package/dist/async/backof-policies/_module.d.ts +0 -5
- package/dist/async/backof-policies/_module.js +0 -6
- package/dist/async/backof-policies/_module.js.map +0 -1
- package/dist/async/backof-policies/_shared.js.map +0 -1
- package/dist/async/backof-policies/constant-backoff-policy/_module.d.ts +0 -1
- package/dist/async/backof-policies/constant-backoff-policy/_module.js +0 -2
- package/dist/async/backof-policies/constant-backoff-policy/_module.js.map +0 -1
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.js.map +0 -1
- package/dist/async/backof-policies/exponential-backoff-policy/_module.d.ts +0 -1
- package/dist/async/backof-policies/exponential-backoff-policy/_module.js +0 -2
- package/dist/async/backof-policies/exponential-backoff-policy/_module.js.map +0 -1
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js +0 -35
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js.map +0 -1
- package/dist/async/backof-policies/linear-backoff-policy/_module.d.ts +0 -1
- package/dist/async/backof-policies/linear-backoff-policy/_module.js +0 -2
- package/dist/async/backof-policies/linear-backoff-policy/_module.js.map +0 -1
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js +0 -35
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js.map +0 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/_module.d.ts +0 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/_module.js +0 -2
- package/dist/async/backof-policies/polynomial-backoff-policy/_module.js.map +0 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +0 -35
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js.map +0 -1
- package/dist/async/middlewares/_module.d.ts +0 -7
- package/dist/async/middlewares/_module.js +0 -8
- package/dist/async/middlewares/_module.js.map +0 -1
- package/dist/async/middlewares/bulkhead/_module.d.ts +0 -1
- package/dist/async/middlewares/bulkhead/_module.js +0 -2
- package/dist/async/middlewares/bulkhead/_module.js.map +0 -1
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +0 -80
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +0 -46
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +0 -1
- package/dist/async/middlewares/dynamic/_module.d.ts +0 -1
- package/dist/async/middlewares/dynamic/_module.js +0 -2
- package/dist/async/middlewares/dynamic/_module.js.map +0 -1
- package/dist/async/middlewares/dynamic/dynamic.middleware.js.map +0 -1
- package/dist/async/middlewares/fallback/_module.d.ts +0 -2
- package/dist/async/middlewares/fallback/_module.js +0 -3
- package/dist/async/middlewares/fallback/_module.js.map +0 -1
- package/dist/async/middlewares/fallback/fallback.middleware.js.map +0 -1
- package/dist/async/middlewares/fallback/fallback.types.js.map +0 -1
- package/dist/async/middlewares/hedging/_module.d.ts +0 -2
- package/dist/async/middlewares/hedging/_module.js +0 -3
- package/dist/async/middlewares/hedging/_module.js.map +0 -1
- package/dist/async/middlewares/hedging/hedging.types.d.ts +0 -121
- package/dist/async/middlewares/hedging/hedging.types.js +0 -6
- package/dist/async/middlewares/hedging/hedging.types.js.map +0 -1
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.d.ts +0 -51
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js +0 -133
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js.map +0 -1
- package/dist/async/middlewares/observe/_module.d.ts +0 -2
- package/dist/async/middlewares/observe/_module.js +0 -3
- package/dist/async/middlewares/observe/_module.js.map +0 -1
- package/dist/async/middlewares/observe/observe.middleware.js.map +0 -1
- package/dist/async/middlewares/observe/observe.types.js +0 -6
- package/dist/async/middlewares/observe/observe.types.js.map +0 -1
- package/dist/async/middlewares/retry/_module.d.ts +0 -2
- package/dist/async/middlewares/retry/_module.js +0 -3
- package/dist/async/middlewares/retry/_module.js.map +0 -1
- package/dist/async/middlewares/retry/retry.middleware.js.map +0 -1
- package/dist/async/middlewares/retry/retry.types.js +0 -7
- package/dist/async/middlewares/retry/retry.types.js.map +0 -1
- package/dist/async/middlewares/timeout/_module.d.ts +0 -2
- package/dist/async/middlewares/timeout/_module.js +0 -3
- package/dist/async/middlewares/timeout/_module.js.map +0 -1
- package/dist/async/middlewares/timeout/timeout.middleware.js.map +0 -1
- package/dist/async/middlewares/timeout/timeout.type.js +0 -6
- package/dist/async/middlewares/timeout/timeout.type.js.map +0 -1
- package/dist/async/utilities/_module.d.ts +0 -4
- package/dist/async/utilities/_module.js +0 -5
- package/dist/async/utilities/_module.js.map +0 -1
- package/dist/async/utilities/abort-and-fail/_module.d.ts +0 -1
- package/dist/async/utilities/abort-and-fail/_module.js +0 -2
- package/dist/async/utilities/abort-and-fail/_module.js.map +0 -1
- package/dist/async/utilities/abort-and-fail/abort-and-fail.js.map +0 -1
- package/dist/async/utilities/lazy-promise/_module.d.ts +0 -1
- package/dist/async/utilities/lazy-promise/_module.js +0 -2
- package/dist/async/utilities/lazy-promise/_module.js.map +0 -1
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +0 -153
- package/dist/async/utilities/lazy-promise/lazy-promise.js +0 -176
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +0 -1
- package/dist/async/utilities/promise-queue/_module.d.ts +0 -1
- package/dist/async/utilities/promise-queue/_module.js +0 -2
- package/dist/async/utilities/promise-queue/_module.js.map +0 -1
- package/dist/async/utilities/promise-queue/promise-queue.d.ts +0 -32
- package/dist/async/utilities/promise-queue/promise-queue.js +0 -118
- package/dist/async/utilities/promise-queue/promise-queue.js.map +0 -1
- package/dist/async/utilities/timeout-and-fail/_module.d.ts +0 -1
- package/dist/async/utilities/timeout-and-fail/_module.js +0 -2
- package/dist/async/utilities/timeout-and-fail/_module.js.map +0 -1
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.d.ts +0 -7
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js +0 -22
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-state.d.ts +0 -40
- package/dist/lock/implementations/derivables/lock-provider/lock-state.js +0 -60
- package/dist/lock/implementations/derivables/lock-provider/lock-state.js.map +0 -1
- package/dist/serde/contracts/serializable.contract.d.ts +0 -12
- package/dist/serde/contracts/serializable.contract.js +0 -5
- package/dist/serde/contracts/serializable.contract.js.map +0 -1
- package/dist/serde/implementations/adapters/mongodb-serde/_module.d.ts +0 -1
- package/dist/serde/implementations/adapters/mongodb-serde/_module.js +0 -2
- package/dist/serde/implementations/adapters/mongodb-serde/_module.js.map +0 -1
- package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.d.ts +0 -13
- package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js +0 -38
- package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js.map +0 -1
- package/dist/serde/implementations/adapters/redis-serde/_module.d.ts +0 -1
- package/dist/serde/implementations/adapters/redis-serde/_module.js +0 -2
- package/dist/serde/implementations/adapters/redis-serde/_module.js.map +0 -1
- package/dist/serde/implementations/adapters/redis-serde/redis-serde.d.ts +0 -13
- package/dist/serde/implementations/adapters/redis-serde/redis-serde.js +0 -39
- package/dist/serde/implementations/adapters/redis-serde/redis-serde.js.map +0 -1
- package/dist/serde/implementations/adapters/sql-serde/_module.d.ts +0 -1
- package/dist/serde/implementations/adapters/sql-serde/_module.js +0 -2
- package/dist/serde/implementations/adapters/sql-serde/_module.js.map +0 -1
- package/dist/serde/implementations/adapters/sql-serde/sql-serde.d.ts +0 -13
- package/dist/serde/implementations/adapters/sql-serde/sql-serde.js +0 -39
- package/dist/serde/implementations/adapters/sql-serde/sql-serde.js.map +0 -1
- package/dist/utilities/classes/hooks/_module.d.ts +0 -3
- package/dist/utilities/classes/hooks/_module.js +0 -4
- package/dist/utilities/classes/hooks/_module.js.map +0 -1
- package/dist/utilities/classes/hooks/async-hooks.js.map +0 -1
- package/dist/utilities/classes/hooks/hooks.js.map +0 -1
- package/dist/utilities/classes/hooks/types.js +0 -5
- package/dist/utilities/classes/hooks/types.js.map +0 -1
- package/dist/utilities/classes/namespace/_module.d.ts +0 -1
- package/dist/utilities/classes/namespace/_module.js +0 -2
- package/dist/utilities/classes/namespace/_module.js.map +0 -1
- package/dist/utilities/classes/namespace/namespace.d.ts +0 -85
- package/dist/utilities/classes/namespace/namespace.js +0 -125
- package/dist/utilities/classes/namespace/namespace.js.map +0 -1
- package/dist/utilities/classes/time-span/_module.d.ts +0 -1
- package/dist/utilities/classes/time-span/_module.js +0 -2
- package/dist/utilities/classes/time-span/_module.js.map +0 -1
- package/dist/utilities/classes/time-span/time-span.js.map +0 -1
- package/dist/utilities/contracts/serialized-error.contract.d.ts +0 -13
- package/dist/utilities/contracts/serialized-error.contract.js +0 -5
- package/dist/utilities/contracts/serialized-error.contract.js.map +0 -1
package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Semaphore
|
|
3
|
+
*/
|
|
4
|
+
import { TimeSpan } from "../../../../time-span/implementations/_module-exports.js";
|
|
5
|
+
import {} from "../../../../utilities/_module-exports.js";
|
|
6
|
+
import { MysqlAdapter } from "kysely";
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
class DatabaseSemaphoreTransaction {
|
|
11
|
+
kysely;
|
|
12
|
+
isMysql;
|
|
13
|
+
constructor(kysely) {
|
|
14
|
+
this.kysely = kysely;
|
|
15
|
+
this.isMysql =
|
|
16
|
+
this.kysely.getExecutor().adapter instanceof MysqlAdapter;
|
|
17
|
+
}
|
|
18
|
+
async findSlots(key) {
|
|
19
|
+
const rows = await this.kysely
|
|
20
|
+
.selectFrom("semaphoreSlot")
|
|
21
|
+
.where("semaphoreSlot.key", "=", key)
|
|
22
|
+
.select(["semaphoreSlot.id", "semaphoreSlot.expiration"])
|
|
23
|
+
.execute();
|
|
24
|
+
return rows.map((row) => {
|
|
25
|
+
if (row.expiration === null) {
|
|
26
|
+
return {
|
|
27
|
+
id: row.id,
|
|
28
|
+
expiration: null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
id: row.id,
|
|
33
|
+
expiration: new Date(Number(row.expiration)),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async findSemaphore(key) {
|
|
38
|
+
const row = await this.kysely
|
|
39
|
+
.selectFrom("semaphore")
|
|
40
|
+
.where("semaphore.key", "=", key)
|
|
41
|
+
.select("limit")
|
|
42
|
+
.executeTakeFirst();
|
|
43
|
+
if (row === undefined) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return row;
|
|
47
|
+
}
|
|
48
|
+
async upsertSemaphore(key, limit) {
|
|
49
|
+
await this.kysely
|
|
50
|
+
.insertInto("semaphore")
|
|
51
|
+
.values({ key, limit })
|
|
52
|
+
.$if(!this.isMysql, (eb) => eb.onConflict((eb) => eb.column("key").doUpdateSet({
|
|
53
|
+
key,
|
|
54
|
+
limit,
|
|
55
|
+
})))
|
|
56
|
+
.$if(this.isMysql, (eb) => eb.onDuplicateKeyUpdate({
|
|
57
|
+
key,
|
|
58
|
+
limit,
|
|
59
|
+
}))
|
|
60
|
+
.execute();
|
|
61
|
+
}
|
|
62
|
+
async upsertSlot(key, slotId, expiration) {
|
|
63
|
+
const expirationAsMs = expiration?.getTime() ?? null;
|
|
64
|
+
await this.kysely
|
|
65
|
+
.insertInto("semaphoreSlot")
|
|
66
|
+
.values({
|
|
67
|
+
key,
|
|
68
|
+
id: slotId,
|
|
69
|
+
expiration: expirationAsMs,
|
|
70
|
+
})
|
|
71
|
+
.$if(!this.isMysql, (eb) => eb.onConflict((eb) => eb.column("id").doUpdateSet({
|
|
72
|
+
key,
|
|
73
|
+
id: slotId,
|
|
74
|
+
expiration: expirationAsMs,
|
|
75
|
+
})))
|
|
76
|
+
.$if(this.isMysql, (eb) => eb.onDuplicateKeyUpdate({
|
|
77
|
+
key,
|
|
78
|
+
id: slotId,
|
|
79
|
+
expiration: expirationAsMs,
|
|
80
|
+
}))
|
|
81
|
+
.execute();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* To utilize the `KyselySemaphoreAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
|
|
86
|
+
*
|
|
87
|
+
* Note in order to use `KyselySemaphoreAdapter` correctly, ensure you use a single, consistent database across all server instances.
|
|
88
|
+
* The adapter have been tested with `sqlite`, `postgres` and `mysql` databases.
|
|
89
|
+
*
|
|
90
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
91
|
+
* @group Adapters
|
|
92
|
+
*/
|
|
93
|
+
export class KyselySemaphoreAdapter {
|
|
94
|
+
kysely;
|
|
95
|
+
expiredKeysRemovalInterval;
|
|
96
|
+
shouldRemoveExpiredKeys;
|
|
97
|
+
intervalId = null;
|
|
98
|
+
isMysql;
|
|
99
|
+
/**
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { KyselySemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
|
|
103
|
+
* import Sqlite from "better-sqlite3";
|
|
104
|
+
*
|
|
105
|
+
* const semaphoreAdapter = new KyselySemaphoreAdapter({
|
|
106
|
+
* kysely: new Kysely({
|
|
107
|
+
* dialect: new SqliteDialect({
|
|
108
|
+
* database: new Sqlite("local.db"),
|
|
109
|
+
* }),
|
|
110
|
+
* }),
|
|
111
|
+
* });
|
|
112
|
+
* // You need initialize the adapter once before using it.
|
|
113
|
+
* await semaphoreAdapter.init();
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
constructor(settings) {
|
|
117
|
+
const { kysely, expiredKeysRemovalInterval = TimeSpan.fromMinutes(1), shouldRemoveExpiredKeys = true, } = settings;
|
|
118
|
+
this.expiredKeysRemovalInterval = expiredKeysRemovalInterval;
|
|
119
|
+
this.shouldRemoveExpiredKeys = shouldRemoveExpiredKeys;
|
|
120
|
+
this.kysely = kysely;
|
|
121
|
+
this.isMysql =
|
|
122
|
+
this.kysely.getExecutor().adapter instanceof MysqlAdapter;
|
|
123
|
+
}
|
|
124
|
+
async init() {
|
|
125
|
+
// Should throw if the table already exists thats why the try catch is used.
|
|
126
|
+
try {
|
|
127
|
+
await this.kysely.schema
|
|
128
|
+
.createTable("semaphore")
|
|
129
|
+
.addColumn("key", "varchar(255)", (col) => col.notNull().primaryKey())
|
|
130
|
+
.addColumn("limit", "integer", (col) => col.notNull())
|
|
131
|
+
.execute();
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
/* EMPTY */
|
|
135
|
+
}
|
|
136
|
+
// Should throw if the table already exists thats why the try catch is used.
|
|
137
|
+
try {
|
|
138
|
+
await this.kysely.schema
|
|
139
|
+
.createTable("semaphoreSlot")
|
|
140
|
+
.addColumn("id", "varchar(255)", (col) => col.notNull().primaryKey())
|
|
141
|
+
.addColumn("key", "varchar(255)", (col) => col.notNull())
|
|
142
|
+
.addColumn("expiration", "bigint")
|
|
143
|
+
.addForeignKeyConstraint("semaphoreSlot_key", ["key"], "semaphore", ["key"], (eb) => eb.onDelete("cascade"))
|
|
144
|
+
.execute();
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
/* EMPTY */
|
|
148
|
+
}
|
|
149
|
+
// Should throw if the index already exists thats why the try catch is used.
|
|
150
|
+
try {
|
|
151
|
+
await this.kysely.schema
|
|
152
|
+
.createIndex("semaphoreSlot_expiration_index")
|
|
153
|
+
.on("semaphoreSlot")
|
|
154
|
+
.columns(["key", "expiresAt"])
|
|
155
|
+
.execute();
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
/* EMPTY */
|
|
159
|
+
}
|
|
160
|
+
if (this.shouldRemoveExpiredKeys) {
|
|
161
|
+
this.intervalId = setInterval(() => {
|
|
162
|
+
void this.removeAllExpired();
|
|
163
|
+
}, this.expiredKeysRemovalInterval.toMilliseconds());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async deInit() {
|
|
167
|
+
if (this.shouldRemoveExpiredKeys && this.intervalId !== null) {
|
|
168
|
+
clearInterval(this.intervalId);
|
|
169
|
+
}
|
|
170
|
+
// Should throw if the index does not exists thats why the try catch is used.
|
|
171
|
+
try {
|
|
172
|
+
await this.kysely.schema
|
|
173
|
+
.dropIndex("semaphoreSlot_expiration_index")
|
|
174
|
+
.on("semaphoreSlot")
|
|
175
|
+
.execute();
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
/* EMPTY */
|
|
179
|
+
}
|
|
180
|
+
// Should throw if the table does not exists thats why the try catch is used.
|
|
181
|
+
try {
|
|
182
|
+
await this.kysely.schema.dropTable("semaphoreSlot").execute();
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
/* EMPTY */
|
|
186
|
+
}
|
|
187
|
+
// Should throw if the table does not exists thats why the try catch is used.
|
|
188
|
+
try {
|
|
189
|
+
await this.kysely.schema.dropTable("semaphore").execute();
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
/* EMPTY */
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async removeAllExpired() {
|
|
196
|
+
await this.kysely
|
|
197
|
+
.deleteFrom("semaphore")
|
|
198
|
+
.where((eb) => {
|
|
199
|
+
const hasUnexpiredSlots = eb
|
|
200
|
+
.selectFrom("semaphoreSlot")
|
|
201
|
+
.select(eb.val(1).as("value"))
|
|
202
|
+
.where("semaphoreSlot.key", "=", eb.ref("semaphore.key"))
|
|
203
|
+
.where((eb) => eb.and([
|
|
204
|
+
eb("semaphoreSlot.expiration", "is not", null),
|
|
205
|
+
eb("semaphoreSlot.expiration", ">", Date.now()),
|
|
206
|
+
]));
|
|
207
|
+
return eb.not(eb.exists(hasUnexpiredSlots));
|
|
208
|
+
})
|
|
209
|
+
.execute();
|
|
210
|
+
}
|
|
211
|
+
async transaction(fn) {
|
|
212
|
+
return await this.kysely
|
|
213
|
+
.transaction()
|
|
214
|
+
.setIsolationLevel("serializable")
|
|
215
|
+
.execute(async (trx) => {
|
|
216
|
+
return await fn(new DatabaseSemaphoreTransaction(trx));
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
async removeSlot(key, slotId) {
|
|
220
|
+
let row;
|
|
221
|
+
if (this.isMysql) {
|
|
222
|
+
row = await this.kysely
|
|
223
|
+
.transaction()
|
|
224
|
+
.setIsolationLevel("serializable")
|
|
225
|
+
.execute(async (trx) => {
|
|
226
|
+
const row = await trx
|
|
227
|
+
.selectFrom("semaphoreSlot")
|
|
228
|
+
.select("semaphoreSlot.expiration")
|
|
229
|
+
.where("semaphoreSlot.key", "=", key)
|
|
230
|
+
.where("semaphoreSlot.id", "=", slotId)
|
|
231
|
+
.executeTakeFirst();
|
|
232
|
+
await trx
|
|
233
|
+
.deleteFrom("semaphoreSlot")
|
|
234
|
+
.where("semaphoreSlot.key", "=", key)
|
|
235
|
+
.where("semaphoreSlot.id", "=", slotId)
|
|
236
|
+
.executeTakeFirst();
|
|
237
|
+
return row;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
row = await this.kysely
|
|
242
|
+
.deleteFrom("semaphoreSlot")
|
|
243
|
+
.where("semaphoreSlot.key", "=", key)
|
|
244
|
+
.where("semaphoreSlot.id", "=", slotId)
|
|
245
|
+
.returning("semaphoreSlot.expiration")
|
|
246
|
+
.executeTakeFirst();
|
|
247
|
+
}
|
|
248
|
+
if (row === undefined) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
if (row.expiration === null) {
|
|
252
|
+
return {
|
|
253
|
+
expiration: null,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
expiration: new Date(Number(row.expiration)),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
async removeAllSlots(key) {
|
|
261
|
+
let rows;
|
|
262
|
+
if (this.isMysql) {
|
|
263
|
+
rows = await this.kysely
|
|
264
|
+
.transaction()
|
|
265
|
+
.setIsolationLevel("serializable")
|
|
266
|
+
.execute(async (trx) => {
|
|
267
|
+
const rows = trx
|
|
268
|
+
.selectFrom("semaphoreSlot")
|
|
269
|
+
.where("semaphoreSlot.key", "=", key)
|
|
270
|
+
.select("semaphoreSlot.expiration")
|
|
271
|
+
.execute();
|
|
272
|
+
await trx
|
|
273
|
+
.deleteFrom("semaphoreSlot")
|
|
274
|
+
.where("semaphoreSlot.key", "=", key)
|
|
275
|
+
.execute();
|
|
276
|
+
return rows;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
rows = await this.kysely
|
|
281
|
+
.deleteFrom("semaphoreSlot")
|
|
282
|
+
.where("semaphoreSlot.key", "=", key)
|
|
283
|
+
.returning("semaphoreSlot.expiration")
|
|
284
|
+
.execute();
|
|
285
|
+
}
|
|
286
|
+
return rows.map((row) => {
|
|
287
|
+
if (row.expiration === null) {
|
|
288
|
+
return {
|
|
289
|
+
expiration: null,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
expiration: new Date(Number(row.expiration)),
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
async updateExpiration(key, slotId, expiration) {
|
|
298
|
+
const result = await this.kysely
|
|
299
|
+
.updateTable("semaphoreSlot")
|
|
300
|
+
.where("semaphoreSlot.key", "=", key)
|
|
301
|
+
.where("semaphoreSlot.id", "=", slotId)
|
|
302
|
+
.where((eb) => eb.and([
|
|
303
|
+
eb("semaphoreSlot.expiration", "is not", null),
|
|
304
|
+
eb("semaphoreSlot.expiration", ">", Date.now()),
|
|
305
|
+
]))
|
|
306
|
+
.set({
|
|
307
|
+
expiration: expiration.getTime(),
|
|
308
|
+
})
|
|
309
|
+
.executeTakeFirst();
|
|
310
|
+
return Number(result.numUpdatedRows);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=kysely-semaphore-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely-semaphore-adapter.js","sourceRoot":"","sources":["../../../../../src/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAC1E,OAAO,EA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C,OAAO,EAAE,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACpB,IAAI,GAAG,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;gBAC1B,OAAO;oBACH,UAAU,EAAE,IAAI;iBACnB,CAAC;YACN,CAAC;YACD,OAAO;gBACH,UAAU,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;aAC/C,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,gBAAgB,CAClB,GAAW,EACX,MAAc,EACd,UAAgB;QAEhB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM;aAC3B,WAAW,CAAC,eAAe,CAAC;aAC5B,KAAK,CAAC,mBAAmB,EAAE,GAAG,EAAE,GAAG,CAAC;aACpC,KAAK,CAAC,kBAAkB,EAAE,GAAG,EAAE,MAAM,CAAC;aACtC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CACV,EAAE,CAAC,GAAG,CAAC;YACH,EAAE,CAAC,0BAA0B,EAAE,QAAQ,EAAE,IAAI,CAAC;YAC9C,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;SAClD,CAAC,CACL;aACA,GAAG,CAAC;YACD,UAAU,EAAE,UAAU,CAAC,OAAO,EAAE;SACnC,CAAC;aACD,gBAAgB,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../../../semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../../src/semaphore/implementations/adapters/memory-semaphore-adapter/_module.ts"],"names":[],"mappings":"AAAA,cAAc,2FAA2F,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Semaphore
|
|
3
|
+
*/
|
|
4
|
+
import type { ISemaphoreAdapter, ISemaphoreAdapterState, SemaphoreAcquireSettings } from "../../../../semaphore/contracts/_module-exports.js";
|
|
5
|
+
import type { TimeSpan } from "../../../../time-span/implementations/_module-exports.js";
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
9
|
+
* @group Adapters
|
|
10
|
+
*/
|
|
11
|
+
export type MemorySemaphoreAdapterData = {
|
|
12
|
+
limit: number;
|
|
13
|
+
slots: Map<string, {
|
|
14
|
+
timeoutId: string | number | NodeJS.Timeout | null;
|
|
15
|
+
expiration: Date | null;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Note the `MemorySemaphoreAdapter` is limited to single process usage and cannot be shared across multiple servers or different processes.
|
|
20
|
+
* This adapter is meant to be used for testing.
|
|
21
|
+
*
|
|
22
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
23
|
+
* @group Adapters
|
|
24
|
+
*/
|
|
25
|
+
export declare class MemorySemaphoreAdapter implements ISemaphoreAdapter {
|
|
26
|
+
private readonly map;
|
|
27
|
+
/**
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { MemorySemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
|
|
31
|
+
*
|
|
32
|
+
* const semaphoreAdapter = new MemorySemaphoreAdapter();
|
|
33
|
+
* ```
|
|
34
|
+
* You can also provide an `Map`.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { MemorySemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
|
|
38
|
+
*
|
|
39
|
+
* const map = new Map<any, any>();
|
|
40
|
+
* const semaphoreAdapter = new MemorySemaphoreAdapter(map);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(map?: Map<string, MemorySemaphoreAdapterData>);
|
|
44
|
+
acquire(settings: SemaphoreAcquireSettings): Promise<boolean>;
|
|
45
|
+
release(key: string, slotId: string): Promise<boolean>;
|
|
46
|
+
forceReleaseAll(key: string): Promise<boolean>;
|
|
47
|
+
refresh(key: string, slotId: string, ttl: TimeSpan): Promise<boolean>;
|
|
48
|
+
getState(key: string): Promise<ISemaphoreAdapterState | null>;
|
|
49
|
+
}
|
package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Semaphore
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Note the `MemorySemaphoreAdapter` is limited to single process usage and cannot be shared across multiple servers or different processes.
|
|
6
|
+
* This adapter is meant to be used for testing.
|
|
7
|
+
*
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
9
|
+
* @group Adapters
|
|
10
|
+
*/
|
|
11
|
+
export class MemorySemaphoreAdapter {
|
|
12
|
+
map;
|
|
13
|
+
/**
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { MemorySemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
|
|
17
|
+
*
|
|
18
|
+
* const semaphoreAdapter = new MemorySemaphoreAdapter();
|
|
19
|
+
* ```
|
|
20
|
+
* You can also provide an `Map`.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { MemorySemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
|
|
24
|
+
*
|
|
25
|
+
* const map = new Map<any, any>();
|
|
26
|
+
* const semaphoreAdapter = new MemorySemaphoreAdapter(map);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
constructor(map = new Map()) {
|
|
30
|
+
this.map = map;
|
|
31
|
+
}
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
33
|
+
async acquire(settings) {
|
|
34
|
+
const { key, slotId, limit, ttl } = settings;
|
|
35
|
+
let semaphore = this.map.get(key);
|
|
36
|
+
if (semaphore === undefined) {
|
|
37
|
+
semaphore = {
|
|
38
|
+
limit,
|
|
39
|
+
slots: new Map(),
|
|
40
|
+
};
|
|
41
|
+
this.map.set(key, semaphore);
|
|
42
|
+
}
|
|
43
|
+
if (semaphore.slots.size >= semaphore.limit) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (semaphore.slots.has(slotId)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (ttl === null) {
|
|
50
|
+
semaphore.slots.set(slotId, {
|
|
51
|
+
timeoutId: null,
|
|
52
|
+
expiration: null,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const timeoutId = setTimeout(() => {
|
|
57
|
+
semaphore.slots.delete(slotId);
|
|
58
|
+
}, ttl.toMilliseconds());
|
|
59
|
+
semaphore.slots.set(slotId, {
|
|
60
|
+
timeoutId,
|
|
61
|
+
expiration: ttl.toEndDate(),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
this.map.set(key, semaphore);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
68
|
+
async release(key, slotId) {
|
|
69
|
+
const semaphore = this.map.get(key);
|
|
70
|
+
if (!semaphore) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const slot = semaphore.slots.get(slotId);
|
|
74
|
+
if (slot === undefined) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (slot.timeoutId !== null) {
|
|
78
|
+
clearTimeout(slot.timeoutId);
|
|
79
|
+
}
|
|
80
|
+
semaphore.slots.delete(slotId);
|
|
81
|
+
this.map.set(key, semaphore);
|
|
82
|
+
if (semaphore.slots.size === 0) {
|
|
83
|
+
this.map.delete(key);
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
88
|
+
async forceReleaseAll(key) {
|
|
89
|
+
const semaphore = this.map.get(key);
|
|
90
|
+
if (semaphore === undefined) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const hasSlots = semaphore.slots.size > 0;
|
|
94
|
+
for (const [slotId, { timeoutId }] of semaphore.slots) {
|
|
95
|
+
clearTimeout(timeoutId ?? undefined);
|
|
96
|
+
semaphore.slots.delete(slotId);
|
|
97
|
+
}
|
|
98
|
+
this.map.delete(key);
|
|
99
|
+
return hasSlots;
|
|
100
|
+
}
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
102
|
+
async refresh(key, slotId, ttl) {
|
|
103
|
+
const semaphore = this.map.get(key);
|
|
104
|
+
if (!semaphore) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const slot = semaphore.slots.get(slotId);
|
|
108
|
+
if (slot === undefined) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (slot.timeoutId === null) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
clearTimeout(slot.timeoutId);
|
|
115
|
+
const timeoutId = setTimeout(() => {
|
|
116
|
+
semaphore.slots.delete(slotId);
|
|
117
|
+
this.map.set(key, semaphore);
|
|
118
|
+
}, ttl.toMilliseconds());
|
|
119
|
+
semaphore.slots.set(slotId, {
|
|
120
|
+
timeoutId,
|
|
121
|
+
expiration: ttl.toEndDate(),
|
|
122
|
+
});
|
|
123
|
+
this.map.set(key, semaphore);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
127
|
+
async getState(key) {
|
|
128
|
+
const semaphore = this.map.get(key);
|
|
129
|
+
if (semaphore === undefined) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (semaphore.slots.size === 0) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
limit: semaphore.limit,
|
|
137
|
+
acquiredSlots: new Map([...semaphore.slots.entries()].map(([key, value]) => [key, value.expiration])),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=memory-semaphore-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-semaphore-adapter.js","sourceRoot":"","sources":["../../../../../src/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAyBH;;;;;;GAMG;AACH,MAAM,OAAO,sBAAsB;IAkBV;IAjBrB;;;;;;;;;;;;;;;OAeG;IACH,YACqB,MAAM,IAAI,GAAG,EAAsC;QAAnD,QAAG,GAAH,GAAG,CAAgD;IACrE,CAAC;IAEJ,4DAA4D;IAC5D,KAAK,CAAC,OAAO,CAAC,QAAkC;QAC5C,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAC;QAC7C,IAAI,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1B,SAAS,GAAG;gBACR,KAAK;gBACL,KAAK,EAAE,IAAI,GAAG,EAAE;aACnB,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,GAA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{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../../src/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.ts"],"names":[],"mappings":"AAAA,cAAc,6FAA6F,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Semaphore
|
|
3
|
+
*/
|
|
4
|
+
import { type IDeinitizable, type IInitizable } from "../../../../utilities/_module-exports.js";
|
|
5
|
+
import type { ISemaphoreAdapter, ISemaphoreAdapterState, SemaphoreAcquireSettings } from "../../../../semaphore/contracts/_module-exports.js";
|
|
6
|
+
import type { ObjectId } from "mongodb";
|
|
7
|
+
import { type CollectionOptions, type Db } from "mongodb";
|
|
8
|
+
import { TimeSpan } from "../../../../time-span/implementations/_module-exports.js";
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
12
|
+
* @group Adapters
|
|
13
|
+
*/
|
|
14
|
+
export type MongodbSemaphoreSlotSubDocument = {
|
|
15
|
+
id: string;
|
|
16
|
+
expiration: Date | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
21
|
+
* @group Adapters
|
|
22
|
+
*/
|
|
23
|
+
export type MongodbSemaphoreDocument = {
|
|
24
|
+
_id: ObjectId;
|
|
25
|
+
key: string;
|
|
26
|
+
limit: number;
|
|
27
|
+
slots: Array<MongodbSemaphoreSlotSubDocument>;
|
|
28
|
+
expiration: Date | null;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
33
|
+
* @group Adapters
|
|
34
|
+
*/
|
|
35
|
+
export type MongodbSemaphoreAdapterSettings = {
|
|
36
|
+
database: Db;
|
|
37
|
+
/**
|
|
38
|
+
* @default "semaphore"
|
|
39
|
+
*/
|
|
40
|
+
collectionName?: string;
|
|
41
|
+
collectionSettings?: CollectionOptions;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* To utilize the `MongodbSemaphoreAdapter`, you must install the `"mongodb"` package.
|
|
45
|
+
*
|
|
46
|
+
* Note in order to use `MongodbSemaphoreAdapter` correctly, ensure you use a single, consistent database across all server instances.
|
|
47
|
+
*
|
|
48
|
+
* IMPORT_PATH: `"@daiso-tech/core/semaphore/adapters"`
|
|
49
|
+
* @group Adapters
|
|
50
|
+
*/
|
|
51
|
+
export declare class MongodbSemaphoreAdapter implements ISemaphoreAdapter, IDeinitizable, IInitizable {
|
|
52
|
+
private static isSlotNotExpired;
|
|
53
|
+
private readonly collection;
|
|
54
|
+
/**
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { MongodbSemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
|
|
58
|
+
* import { MongoClient } from "mongodb";
|
|
59
|
+
*
|
|
60
|
+
* const client = await MongoClient.connect("YOUR_MONGODB_CONNECTION_STRING");
|
|
61
|
+
* const database = client.db("database");
|
|
62
|
+
* const semaphoreAdapter = new MongodbSemaphoreAdapter({
|
|
63
|
+
* database
|
|
64
|
+
* });
|
|
65
|
+
* // You need initialize the adapter once before using it.
|
|
66
|
+
* await semaphoreAdapter.init()
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
constructor(settings: MongodbSemaphoreAdapterSettings);
|
|
70
|
+
init(): Promise<void>;
|
|
71
|
+
deInit(): Promise<void>;
|
|
72
|
+
private initSemaphoreIfNotExistsStage;
|
|
73
|
+
private removeExpiredSlotsStage;
|
|
74
|
+
private updateSemaphoreExpiration;
|
|
75
|
+
acquire(settings: SemaphoreAcquireSettings): Promise<boolean>;
|
|
76
|
+
release(key: string, slotId: string): Promise<boolean>;
|
|
77
|
+
forceReleaseAll(key: string): Promise<boolean>;
|
|
78
|
+
refresh(key: string, slotId: string, ttl: TimeSpan): Promise<boolean>;
|
|
79
|
+
getState(key: string): Promise<ISemaphoreAdapterState | null>;
|
|
80
|
+
}
|