@daiso-tech/core 0.26.0 → 0.27.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 +10 -0
- package/dist/async/utilities/delay/delay.d.ts +1 -12
- package/dist/async/utilities/delay/delay.js +1 -12
- package/dist/async/utilities/delay/delay.js.map +1 -1
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +99 -65
- package/dist/async/utilities/lazy-promise/lazy-promise.js +151 -111
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/cache/contracts/_module-exports.d.ts +1 -0
- package/dist/cache/contracts/_module-exports.js +1 -0
- package/dist/cache/contracts/_module-exports.js.map +1 -1
- package/dist/cache/contracts/cache-adapter.contract.d.ts +19 -21
- package/dist/cache/contracts/cache-adapter.contract.js +1 -4
- package/dist/cache/contracts/cache-adapter.contract.js.map +1 -1
- package/dist/cache/contracts/cache-factory.contract.d.ts +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +52 -88
- package/dist/cache/contracts/cache.contract.js +1 -2
- package/dist/cache/contracts/cache.contract.js.map +1 -1
- package/dist/cache/contracts/cache.errors.js +2 -5
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/contracts/cache.events.d.ts +10 -10
- package/dist/cache/contracts/cache.events.js +2 -5
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +89 -0
- package/dist/cache/contracts/database-cache-adapter.contract.js +5 -0
- package/dist/cache/contracts/database-cache-adapter.contract.js.map +1 -0
- package/dist/cache/implementations/adapters/_module-exports.d.ts +0 -1
- package/dist/cache/implementations/adapters/_module-exports.js +0 -1
- package/dist/cache/implementations/adapters/_module-exports.js.map +1 -1
- package/dist/cache/implementations/adapters/{kysely-sqlite-cache-adapter → kysely-cache-adapter}/_module.d.ts +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/_module.js +2 -0
- package/dist/cache/implementations/adapters/kysely-cache-adapter/_module.js.map +1 -0
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +73 -0
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +224 -0
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -0
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.d.ts +29 -39
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +45 -54
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +17 -33
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +43 -52
- 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-serde.d.ts +13 -0
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.js +38 -0
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.js.map +1 -0
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +27 -33
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +145 -197
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.d.ts +13 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.js +39 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.js.map +1 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +16 -22
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +51 -132
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.d.ts +13 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js +69 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js.map +1 -0
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +29 -40
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +46 -55
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/_module-exports.d.ts +1 -1
- package/dist/cache/implementations/derivables/_module-exports.js +1 -1
- package/dist/cache/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/_module.d.ts +1 -0
- package/dist/cache/implementations/derivables/cache/_module.js +1 -0
- package/dist/cache/implementations/derivables/cache/_module.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +122 -565
- package/dist/cache/implementations/derivables/cache/cache.js +342 -854
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +21 -0
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +110 -0
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -0
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.d.ts +9 -0
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js +20 -0
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js.map +1 -0
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +65 -104
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +101 -85
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/_module-exports.d.ts +1 -0
- package/dist/cache/implementations/test-utilities/_module-exports.js +1 -0
- package/dist/cache/implementations/test-utilities/_module-exports.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +9 -11
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +246 -247
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +16 -30
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +271 -996
- 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 +60 -0
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +698 -0
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -0
- package/dist/collection/contracts/async-collection.contract.d.ts +2 -3
- package/dist/collection/contracts/async-collection.contract.js +1 -12
- package/dist/collection/contracts/async-collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.contract.d.ts +1 -1
- package/dist/collection/contracts/collection.errors.d.ts +1 -1
- package/dist/collection/contracts/collection.errors.js +3 -6
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/collection/implementations/_shared.d.ts +4 -4
- package/dist/collection/implementations/_shared.js +6 -9
- package/dist/collection/implementations/_shared.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +6 -5
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +1 -1
- package/dist/collection/implementations/list-collection/list-collection.js +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +0 -9
- package/dist/event-bus/contracts/event-bus.contract.d.ts +5 -5
- package/dist/event-bus/contracts/event-bus.contract.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.errors.js +2 -5
- package/dist/event-bus/contracts/event-bus.errors.js.map +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +9 -29
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +14 -35
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +1 -3
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +1 -7
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +8 -15
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +15 -34
- 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 +78 -267
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +119 -323
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.d.ts +13 -0
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.js +42 -0
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.js.map +1 -0
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +70 -96
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +100 -90
- 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 +2 -48
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +31 -122
- 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 +2 -50
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +41 -89
- 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 +0 -9
- package/dist/lock/contracts/lock-adapter.contract.d.ts +0 -9
- package/dist/lock/contracts/lock-provider.contract.d.ts +1 -1
- package/dist/lock/contracts/lock.errors.js +2 -5
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/contracts/lock.events.js +2 -5
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +0 -5
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +2 -21
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +11 -16
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +11 -20
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +7 -26
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +7 -35
- 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 +13 -20
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +13 -37
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +4 -22
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +4 -31
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +12 -17
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +12 -21
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +0 -2
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +2 -8
- 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 +9 -0
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js +17 -0
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +1 -0
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +115 -372
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +197 -455
- 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 +15 -17
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +42 -40
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-state.d.ts +3 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +30 -754
- package/dist/lock/implementations/derivables/lock-provider/lock.js +94 -812
- 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 +58 -161
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +116 -122
- 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 +4 -5
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +172 -247
- 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 +5 -8
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +93 -98
- 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 -20
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +133 -137
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js +1 -2
- package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js.map +1 -1
- 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 +1 -1
- package/dist/serde/implementations/adapters/redis-serde/redis-serde.js +1 -2
- package/dist/serde/implementations/adapters/redis-serde/redis-serde.js.map +1 -1
- package/dist/serde/implementations/adapters/sql-serde/sql-serde.js +1 -2
- package/dist/serde/implementations/adapters/sql-serde/sql-serde.js.map +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.d.ts +2 -2
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +2 -2
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +14 -14
- package/dist/serde/implementations/derivables/serde.js +14 -15
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.d.ts +4 -4
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +3 -3
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +5 -5
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +4 -4
- package/dist/utilities/_module-exports.d.ts +1 -2
- package/dist/utilities/_module-exports.js +1 -2
- package/dist/utilities/_module-exports.js.map +1 -1
- package/dist/utilities/classes/_module.d.ts +4 -0
- package/dist/utilities/classes/_module.js +5 -0
- package/dist/utilities/classes/_module.js.map +1 -0
- package/dist/utilities/classes/key-prefixer/_module.d.ts +2 -0
- package/dist/utilities/classes/key-prefixer/_module.js +3 -0
- package/dist/utilities/classes/key-prefixer/_module.js.map +1 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.contract.d.ts +28 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.contract.js +5 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.contract.js.map +1 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.d.ts +73 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.js +135 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -0
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/_module.d.ts +1 -0
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/_module.js +2 -0
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/_module.js.map +1 -0
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js.map +1 -0
- package/dist/utilities/classes/pipeline/_module.d.ts +1 -0
- package/dist/utilities/classes/pipeline/_module.js +2 -0
- package/dist/utilities/classes/pipeline/_module.js.map +1 -0
- package/dist/utilities/{pipeline → classes/pipeline}/pipeline.d.ts +3 -2
- package/dist/utilities/{pipeline → classes/pipeline}/pipeline.js +3 -2
- package/dist/utilities/classes/pipeline/pipeline.js.map +1 -0
- package/dist/utilities/classes/time-span/_module.d.ts +1 -0
- package/dist/utilities/classes/time-span/_module.js +2 -0
- package/dist/utilities/classes/time-span/_module.js.map +1 -0
- package/dist/utilities/{time-span → classes/time-span}/time-span.d.ts +2 -1
- package/dist/utilities/{time-span → classes/time-span}/time-span.js +1 -0
- package/dist/utilities/classes/time-span/time-span.js.map +1 -0
- package/dist/utilities/contracts/_module.d.ts +2 -1
- package/dist/utilities/contracts/_module.js +2 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/contracts/prunable.contract.d.ts +11 -0
- package/dist/utilities/contracts/prunable.contract.js +5 -0
- package/dist/utilities/contracts/prunable.contract.js.map +1 -0
- package/dist/utilities/functions.d.ts +30 -2
- package/dist/utilities/functions.js +66 -4
- package/dist/utilities/functions.js.map +1 -1
- package/dist/utilities/types.d.ts +47 -14
- package/package.json +14 -13
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/_module.js +0 -2
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/_module.js.map +0 -1
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.d.ts +0 -61
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js +0 -318
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js.map +0 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.d.ts +0 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js +0 -2
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js.map +0 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +0 -22
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +0 -39
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +0 -1
- package/dist/utilities/kysely/_module.d.ts +0 -1
- package/dist/utilities/kysely/_module.js +0 -2
- package/dist/utilities/kysely/_module.js.map +0 -1
- package/dist/utilities/kysely/kysely-table-name-transformer-plugin.js.map +0 -1
- package/dist/utilities/pipeline/_module.d.ts +0 -1
- package/dist/utilities/pipeline/_module.js +0 -2
- package/dist/utilities/pipeline/_module.js.map +0 -1
- package/dist/utilities/pipeline/pipeline.js.map +0 -1
- package/dist/utilities/time-span/_module.d.ts +0 -1
- package/dist/utilities/time-span/_module.js +0 -2
- package/dist/utilities/time-span/_module.js.map +0 -1
- package/dist/utilities/time-span/time-span.js.map +0 -1
- /package/dist/utilities/{kysely → classes/kysely-table-name-transformer-plugin}/kysely-table-name-transformer-plugin.d.ts +0 -0
- /package/dist/utilities/{kysely → classes/kysely-table-name-transformer-plugin}/kysely-table-name-transformer-plugin.js +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import {} from "../../../../utilities/_module-exports.js";
|
|
5
|
+
import { resolveOneOrMoreStr } from "../../../../utilities/_module-exports.js";
|
|
6
|
+
import { KeyAcquiredLockEvent, KeyAlreadyAcquiredLockError, KeyAlreadyAcquiredLockEvent, KeyForceReleasedLockEvent, KeyRefreshedLockEvent, KeyReleasedLockEvent, UnableToAquireLockError, UnexpectedErrorLockEvent, UnownedRefreshLockError, UnownedRefreshLockEvent, UnownedReleaseLockError, UnownedReleaseLockEvent, } from "../../../../lock/contracts/_module-exports.js";
|
|
7
|
+
import {} from "../../../../lock/contracts/_module-exports.js";
|
|
8
|
+
import { LazyPromise } from "../../../../async/_module-exports.js";
|
|
7
9
|
/**
|
|
8
10
|
* IMPORTANT: This class is not intended to be instantiated directly, instead it should be created by the <i>LockProvider</i> class instance.
|
|
9
11
|
* @group Derivables
|
|
@@ -14,149 +16,70 @@ export class Lock {
|
|
|
14
16
|
*/
|
|
15
17
|
static serialize(deserializedValue) {
|
|
16
18
|
return {
|
|
17
|
-
group: deserializedValue.
|
|
18
|
-
key: deserializedValue.key,
|
|
19
|
+
group: deserializedValue.group,
|
|
20
|
+
key: deserializedValue.key.resolved,
|
|
19
21
|
owner: deserializedValue.owner,
|
|
20
22
|
ttlInMs: deserializedValue.ttl?.toMilliseconds() ?? null,
|
|
21
|
-
expirationInMs: deserializedValue.
|
|
23
|
+
expirationInMs: deserializedValue.lockState.get()?.getTime() ?? null,
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
createLazyPromise;
|
|
27
|
+
adapterPromise;
|
|
28
|
+
lockState;
|
|
25
29
|
lockEventBus;
|
|
26
|
-
|
|
30
|
+
lockProviderEventDispatcher;
|
|
27
31
|
key;
|
|
28
32
|
owner;
|
|
29
33
|
ttl;
|
|
30
34
|
defaultBlockingInterval;
|
|
31
35
|
defaultBlockingTime;
|
|
32
36
|
defaultRefreshTime;
|
|
33
|
-
|
|
34
|
-
state;
|
|
37
|
+
group;
|
|
35
38
|
/**
|
|
36
39
|
* @internal
|
|
37
40
|
*/
|
|
38
41
|
constructor(settings) {
|
|
39
|
-
const {
|
|
42
|
+
const { group, createLazyPromise, adapterPromise, lockState, lockEventBus, lockProviderEventDispatcher, key, owner, ttl, expirationInMs, defaultBlockingInterval, defaultBlockingTime, defaultRefreshTime, } = settings;
|
|
43
|
+
this.group = group;
|
|
44
|
+
this.createLazyPromise = createLazyPromise;
|
|
45
|
+
this.adapterPromise = adapterPromise;
|
|
46
|
+
this.lockState = lockState;
|
|
47
|
+
this.lockState.set(expirationInMs);
|
|
48
|
+
this.lockEventBus = lockEventBus;
|
|
40
49
|
this.lockProviderEventDispatcher = lockProviderEventDispatcher;
|
|
41
|
-
this.
|
|
50
|
+
this.key = key;
|
|
51
|
+
this.owner = resolveOneOrMoreStr(owner);
|
|
52
|
+
this.ttl = ttl;
|
|
42
53
|
this.defaultBlockingInterval = defaultBlockingInterval;
|
|
43
54
|
this.defaultBlockingTime = defaultBlockingTime;
|
|
44
55
|
this.defaultRefreshTime = defaultRefreshTime;
|
|
45
|
-
this.adapter = adapter;
|
|
46
|
-
this.key = key;
|
|
47
|
-
this.owner = owner;
|
|
48
|
-
this.ttl = ttl;
|
|
49
|
-
this.lazyPromiseSettings = lazyPromiseSettings;
|
|
50
|
-
this.state = new LockState(stateRecord, key);
|
|
51
|
-
this.state.set(expirationInMs);
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
addListener(event, listener) {
|
|
58
|
+
return this.lockEventBus.addListener(event, listener);
|
|
59
|
+
}
|
|
60
|
+
addListenerMany(events, listener) {
|
|
61
|
+
return this.lockEventBus.addListenerMany(events, listener);
|
|
62
|
+
}
|
|
63
|
+
removeListener(event, listener) {
|
|
64
|
+
return this.lockEventBus.removeListener(event, listener);
|
|
65
|
+
}
|
|
66
|
+
removeListenerMany(events, listener) {
|
|
67
|
+
return this.lockEventBus.removeListenerMany(events, listener);
|
|
68
|
+
}
|
|
69
|
+
listenOnce(event, listener) {
|
|
70
|
+
return this.lockEventBus.listenOnce(event, listener);
|
|
71
|
+
}
|
|
72
|
+
asPromise(event) {
|
|
73
|
+
return this.lockEventBus.asPromise(event);
|
|
74
|
+
}
|
|
75
|
+
subscribe(event, listener) {
|
|
76
|
+
return this.lockEventBus.subscribe(event, listener);
|
|
77
|
+
}
|
|
78
|
+
subscribeMany(events, listener) {
|
|
79
|
+
return this.lockEventBus.subscribeMany(events, listener);
|
|
59
80
|
}
|
|
60
|
-
/**
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
64
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
65
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
66
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
67
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
68
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
69
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
70
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
71
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
72
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
73
|
-
*
|
|
74
|
-
* const eventBus = new EventBus({
|
|
75
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
76
|
-
* });
|
|
77
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
78
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
79
|
-
* serde,
|
|
80
|
-
* adapter: new MemoryLockAdapter({
|
|
81
|
-
* rootGroup: "@global"
|
|
82
|
-
* }),
|
|
83
|
-
* eventBus,
|
|
84
|
-
* });
|
|
85
|
-
*
|
|
86
|
-
* const lock = lockProvider.create("a");
|
|
87
|
-
*
|
|
88
|
-
* async function fn(): Promise<void> {
|
|
89
|
-
* await lock.run(async () => {
|
|
90
|
-
* console.log("START: ", 1);
|
|
91
|
-
* // Let’s pretend we’re doing async database work.
|
|
92
|
-
* await delay(TimeSpan.fromSeconds(2));
|
|
93
|
-
* console.log("END: ", 2);
|
|
94
|
-
* });
|
|
95
|
-
* }
|
|
96
|
-
*
|
|
97
|
-
* await Promise.allSettled([
|
|
98
|
-
* fn(),
|
|
99
|
-
* fn(),
|
|
100
|
-
* fn(),
|
|
101
|
-
* fn(),
|
|
102
|
-
* ]);
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* You can also pass an <i>{@link LazyPromise}</i> instead of async function.
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
109
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
110
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
111
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
112
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
113
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
114
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
115
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
116
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
117
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
118
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
119
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
120
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
121
|
-
*
|
|
122
|
-
* const eventBus = new EventBus({
|
|
123
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
124
|
-
* });
|
|
125
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
126
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
127
|
-
* serde,
|
|
128
|
-
* adapter: new MemoryLockAdapter({
|
|
129
|
-
* rootGroup: "@global"
|
|
130
|
-
* }),
|
|
131
|
-
* eventBus,
|
|
132
|
-
* });
|
|
133
|
-
*
|
|
134
|
-
* const cache: IGroupableCache = new Cache({
|
|
135
|
-
* // Let's pretend when the cache adapter increments a key it will occur in 2 async, get the value, increment the value in memory and update the key.
|
|
136
|
-
* adapter: new MemoryCacheAdapter({
|
|
137
|
-
* rootGroup: "@global"
|
|
138
|
-
* }),
|
|
139
|
-
* eventBus,
|
|
140
|
-
* });
|
|
141
|
-
* await cache.put("a", 0);
|
|
142
|
-
*
|
|
143
|
-
* const lock = lockProvider.create("a");
|
|
144
|
-
*
|
|
145
|
-
* async function fn(): Promise<void> {
|
|
146
|
-
* // The lock will ensure the key will be incremented correctly
|
|
147
|
-
* await lock.run(cache.increment("a", 1));
|
|
148
|
-
* }
|
|
149
|
-
*
|
|
150
|
-
* await Promise.allSettled([
|
|
151
|
-
* fn(),
|
|
152
|
-
* fn(),
|
|
153
|
-
* fn(),
|
|
154
|
-
* fn(),
|
|
155
|
-
* ]);
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
81
|
run(asyncFn) {
|
|
159
|
-
return this.
|
|
82
|
+
return this.createLazyPromise(async () => {
|
|
160
83
|
if (typeof asyncFn === "function") {
|
|
161
84
|
asyncFn = new LazyPromise(asyncFn);
|
|
162
85
|
}
|
|
@@ -165,7 +88,7 @@ export class Lock {
|
|
|
165
88
|
if (!hasAquired) {
|
|
166
89
|
return [
|
|
167
90
|
null,
|
|
168
|
-
new KeyAlreadyAcquiredLockError(`Key "${this.key}" already acquired`),
|
|
91
|
+
new KeyAlreadyAcquiredLockError(`Key "${this.key.resolved}" already acquired`),
|
|
169
92
|
];
|
|
170
93
|
}
|
|
171
94
|
return [await asyncFn, null];
|
|
@@ -175,111 +98,8 @@ export class Lock {
|
|
|
175
98
|
}
|
|
176
99
|
}).setRetryPolicy((error) => error instanceof UnableToAquireLockError);
|
|
177
100
|
}
|
|
178
|
-
/**
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
182
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
183
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
184
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
185
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
186
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
187
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
188
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
189
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
190
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
191
|
-
*
|
|
192
|
-
* const eventBus = new EventBus({
|
|
193
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
194
|
-
* });
|
|
195
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
196
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
197
|
-
* serde,
|
|
198
|
-
* adapter: new MemoryLockAdapter({
|
|
199
|
-
* rootGroup: "@global"
|
|
200
|
-
* }),
|
|
201
|
-
* eventBus,
|
|
202
|
-
* });
|
|
203
|
-
*
|
|
204
|
-
* const lock = lockProvider.create("a");
|
|
205
|
-
*
|
|
206
|
-
* async function fn(): Promise<void> {
|
|
207
|
-
* await lock.runOrFail(async () => {
|
|
208
|
-
* console.log("START: ", 1);
|
|
209
|
-
* // Let’s pretend we’re doing async database work.
|
|
210
|
-
* await delay(TimeSpan.fromSeconds(2));
|
|
211
|
-
* console.log("END: ", 2);
|
|
212
|
-
* })
|
|
213
|
-
* // Retries 4 times to acquire the lock, then throws an error.
|
|
214
|
-
* .setRetryAttempts(4);
|
|
215
|
-
* }
|
|
216
|
-
*
|
|
217
|
-
* await Promise.allSettled([
|
|
218
|
-
* fn(),
|
|
219
|
-
* fn(),
|
|
220
|
-
* fn(),
|
|
221
|
-
* fn(),
|
|
222
|
-
* ]);
|
|
223
|
-
* ```
|
|
224
|
-
*
|
|
225
|
-
* You can also pass an <i>{@link LazyPromise}</i> instead of async function.
|
|
226
|
-
* @example
|
|
227
|
-
* ```ts
|
|
228
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
229
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
230
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
231
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
232
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
233
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
234
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
235
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
236
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
237
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
238
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
239
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
240
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
241
|
-
*
|
|
242
|
-
* const eventBus = new EventBus({
|
|
243
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
244
|
-
* });
|
|
245
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
246
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
247
|
-
* serde,
|
|
248
|
-
* adapter: new MemoryLockAdapter({
|
|
249
|
-
* rootGroup: "@global"
|
|
250
|
-
* }),
|
|
251
|
-
* eventBus,
|
|
252
|
-
* });
|
|
253
|
-
*
|
|
254
|
-
* const cache: IGroupableCache = new Cache({
|
|
255
|
-
* // Let's pretend when the cache adapter increments a key it will occur in 2 async, get the value, increment the value in memory and update the key.
|
|
256
|
-
* adapter: new MemoryCacheAdapter({
|
|
257
|
-
* rootGroup: "@global"
|
|
258
|
-
* }),
|
|
259
|
-
* eventBus,
|
|
260
|
-
* });
|
|
261
|
-
* await cache.put("a", 0);
|
|
262
|
-
*
|
|
263
|
-
* const lock = lockProvider.create("a");
|
|
264
|
-
*
|
|
265
|
-
* async function fn(): Promise<void> {
|
|
266
|
-
* await lock
|
|
267
|
-
* // The lock will ensure the key will be incremented correctly
|
|
268
|
-
* .runOrFail(cache.increment("a", 1));
|
|
269
|
-
* // Retries 4 times to acquire the lock, then throws an error.
|
|
270
|
-
* .setRetryAttempts(4);
|
|
271
|
-
* }
|
|
272
|
-
*
|
|
273
|
-
* await Promise.allSettled([
|
|
274
|
-
* fn(),
|
|
275
|
-
* fn(),
|
|
276
|
-
* fn(),
|
|
277
|
-
* fn(),
|
|
278
|
-
* ]);
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
101
|
runOrFail(asyncFn) {
|
|
282
|
-
return this.
|
|
102
|
+
return this.createLazyPromise(async () => {
|
|
283
103
|
try {
|
|
284
104
|
if (typeof asyncFn === "function") {
|
|
285
105
|
asyncFn = new LazyPromise(asyncFn);
|
|
@@ -293,106 +113,8 @@ export class Lock {
|
|
|
293
113
|
}).setRetryPolicy((error) => error instanceof UnableToAquireLockError ||
|
|
294
114
|
error instanceof KeyAlreadyAcquiredLockError);
|
|
295
115
|
}
|
|
296
|
-
/**
|
|
297
|
-
* @example
|
|
298
|
-
* ```ts
|
|
299
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
300
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
301
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
302
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
303
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
304
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
305
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
306
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
307
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
308
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
309
|
-
*
|
|
310
|
-
* const eventBus = new EventBus({
|
|
311
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
312
|
-
* });
|
|
313
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
314
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
315
|
-
* serde,
|
|
316
|
-
* adapter: new MemoryLockAdapter({
|
|
317
|
-
* rootGroup: "@global"
|
|
318
|
-
* }),
|
|
319
|
-
* eventBus,
|
|
320
|
-
* });
|
|
321
|
-
*
|
|
322
|
-
* const lock = lockProvider.create("a");
|
|
323
|
-
*
|
|
324
|
-
* async function fn(): Promise<void> {
|
|
325
|
-
* await lock.runBlocking(async () => {
|
|
326
|
-
* console.log("START: ", 1);
|
|
327
|
-
* // Let’s pretend we’re doing async database work.
|
|
328
|
-
* await delay(TimeSpan.fromSeconds(2));
|
|
329
|
-
* console.log("END: ", 2);
|
|
330
|
-
* });
|
|
331
|
-
* }
|
|
332
|
-
*
|
|
333
|
-
* await Promise.allSettled([
|
|
334
|
-
* fn(),
|
|
335
|
-
* fn(),
|
|
336
|
-
* fn(),
|
|
337
|
-
* fn(),
|
|
338
|
-
* ]);
|
|
339
|
-
* ```
|
|
340
|
-
*
|
|
341
|
-
* You can also pass an <i>{@link LazyPromise}</i> instead of async function.
|
|
342
|
-
* @example
|
|
343
|
-
* ```ts
|
|
344
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
345
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
346
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
347
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
348
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
349
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
350
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
351
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
352
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
353
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
354
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
355
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
356
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
357
|
-
*
|
|
358
|
-
* const eventBus = new EventBus({
|
|
359
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
360
|
-
* });
|
|
361
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
362
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
363
|
-
* serde,
|
|
364
|
-
* adapter: new MemoryLockAdapter({
|
|
365
|
-
* rootGroup: "@global"
|
|
366
|
-
* }),
|
|
367
|
-
* eventBus,
|
|
368
|
-
* });
|
|
369
|
-
*
|
|
370
|
-
* const cache: IGroupableCache = new Cache({
|
|
371
|
-
* // Let's pretend when the cache adapter increments a key it will occur in 2 async, get the value, increment the value in memory and update the key.
|
|
372
|
-
* adapter: new MemoryCacheAdapter({
|
|
373
|
-
* rootGroup: "@global"
|
|
374
|
-
* }),
|
|
375
|
-
* eventBus,
|
|
376
|
-
* });
|
|
377
|
-
* await cache.put("a", 0);
|
|
378
|
-
*
|
|
379
|
-
* const lock = lockProvider.create("a");
|
|
380
|
-
*
|
|
381
|
-
* async function fn(): Promise<void> {
|
|
382
|
-
* // The lock will ensure the key will be incremented correctly
|
|
383
|
-
* await lock.runBlocking(cache.increment("a", 1));
|
|
384
|
-
* }
|
|
385
|
-
*
|
|
386
|
-
* await Promise.allSettled([
|
|
387
|
-
* fn(),
|
|
388
|
-
* fn(),
|
|
389
|
-
* fn(),
|
|
390
|
-
* fn(),
|
|
391
|
-
* ]);
|
|
392
|
-
* ```
|
|
393
|
-
*/
|
|
394
116
|
runBlocking(asyncFn, settings) {
|
|
395
|
-
return this.
|
|
117
|
+
return this.createLazyPromise(async () => {
|
|
396
118
|
if (typeof asyncFn === "function") {
|
|
397
119
|
asyncFn = new LazyPromise(asyncFn);
|
|
398
120
|
}
|
|
@@ -401,7 +123,7 @@ export class Lock {
|
|
|
401
123
|
if (!hasAquired) {
|
|
402
124
|
return [
|
|
403
125
|
null,
|
|
404
|
-
new KeyAlreadyAcquiredLockError(`Key "${this.key}" already acquired`),
|
|
126
|
+
new KeyAlreadyAcquiredLockError(`Key "${this.key.resolved}" already acquired`),
|
|
405
127
|
];
|
|
406
128
|
}
|
|
407
129
|
return [await asyncFn, null];
|
|
@@ -411,68 +133,16 @@ export class Lock {
|
|
|
411
133
|
}
|
|
412
134
|
}).setRetryPolicy((error) => error instanceof UnableToAquireLockError);
|
|
413
135
|
}
|
|
414
|
-
/**
|
|
415
|
-
* @example
|
|
416
|
-
* ```ts
|
|
417
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
418
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
419
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
420
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
421
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
422
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
423
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
424
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
425
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
426
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
427
|
-
*
|
|
428
|
-
* const eventBus = new EventBus({
|
|
429
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
430
|
-
* });
|
|
431
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
432
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
433
|
-
* serde,
|
|
434
|
-
* adapter: new MemoryLockAdapter({
|
|
435
|
-
* rootGroup: "@global"
|
|
436
|
-
* }),
|
|
437
|
-
* eventBus,
|
|
438
|
-
* });
|
|
439
|
-
*
|
|
440
|
-
* const lock = lockProvider.create("a");
|
|
441
|
-
*
|
|
442
|
-
* async function fn(): Promise<void> {
|
|
443
|
-
* // Use try-finally when acquiring a lock to ensure it’s released if an error happens.
|
|
444
|
-
* try {
|
|
445
|
-
* const hasAquired = await lock.acquire();
|
|
446
|
-
* if (!hasAquired) {
|
|
447
|
-
* return;
|
|
448
|
-
* }
|
|
449
|
-
* console.log("START: ", 1);
|
|
450
|
-
* // Let’s pretend we’re doing async database work.
|
|
451
|
-
* await delay(TimeSpan.fromSeconds(2));
|
|
452
|
-
* console.log("END: ", 2);
|
|
453
|
-
* }
|
|
454
|
-
* finally {
|
|
455
|
-
* await lock.release();
|
|
456
|
-
* }
|
|
457
|
-
* }
|
|
458
|
-
*
|
|
459
|
-
* await Promise.allSettled([
|
|
460
|
-
* fn(),
|
|
461
|
-
* fn(),
|
|
462
|
-
* fn(),
|
|
463
|
-
* fn(),
|
|
464
|
-
* ]);
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
136
|
acquire() {
|
|
468
|
-
return this.
|
|
137
|
+
return this.createLazyPromise(async () => {
|
|
469
138
|
try {
|
|
470
|
-
this.
|
|
471
|
-
|
|
139
|
+
const adapter = await this.adapterPromise;
|
|
140
|
+
this.lockState.remove();
|
|
141
|
+
const hasAquired = await adapter.acquire(this.key.prefixed, this.owner, this.ttl);
|
|
472
142
|
if (hasAquired) {
|
|
473
|
-
this.
|
|
143
|
+
this.lockState.set(this.ttl);
|
|
474
144
|
const event = new KeyAcquiredLockEvent({
|
|
475
|
-
key: this.key,
|
|
145
|
+
key: this.key.resolved,
|
|
476
146
|
owner: this.owner,
|
|
477
147
|
ttl: this.ttl,
|
|
478
148
|
});
|
|
@@ -481,7 +151,7 @@ export class Lock {
|
|
|
481
151
|
}
|
|
482
152
|
else {
|
|
483
153
|
const event = new KeyAlreadyAcquiredLockEvent({
|
|
484
|
-
key: this.key,
|
|
154
|
+
key: this.key.resolved,
|
|
485
155
|
owner: this.owner,
|
|
486
156
|
});
|
|
487
157
|
this.lockEventBus.dispatch(event).defer();
|
|
@@ -491,7 +161,7 @@ export class Lock {
|
|
|
491
161
|
}
|
|
492
162
|
catch (error) {
|
|
493
163
|
const event = new UnexpectedErrorLockEvent({
|
|
494
|
-
key: this.key,
|
|
164
|
+
key: this.key.resolved,
|
|
495
165
|
owner: this.owner,
|
|
496
166
|
ttl: this.ttl,
|
|
497
167
|
error,
|
|
@@ -502,140 +172,37 @@ export class Lock {
|
|
|
502
172
|
}
|
|
503
173
|
});
|
|
504
174
|
}
|
|
505
|
-
/**
|
|
506
|
-
* @example
|
|
507
|
-
* ```ts
|
|
508
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
509
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
510
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
511
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
512
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
513
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
514
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
515
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
516
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
517
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
518
|
-
*
|
|
519
|
-
* const eventBus = new EventBus({
|
|
520
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
521
|
-
* });
|
|
522
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
523
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
524
|
-
* serde,
|
|
525
|
-
* adapter: new MemoryLockAdapter({
|
|
526
|
-
* rootGroup: "@global"
|
|
527
|
-
* }),
|
|
528
|
-
* eventBus,
|
|
529
|
-
* });
|
|
530
|
-
*
|
|
531
|
-
* const lock = lockProvider.create("a");
|
|
532
|
-
*
|
|
533
|
-
* async function fn(): Promise<void> {
|
|
534
|
-
* // Use try-finally when acquiring a lock to ensure it’s released if an error happens.
|
|
535
|
-
* try {
|
|
536
|
-
* // Retries 4 times to acquire the lock, then throws an error.
|
|
537
|
-
* await lock.acquireOrFail().setRetryAttempts(4);
|
|
538
|
-
* console.log("START: ", 1);
|
|
539
|
-
* // Let’s pretend we’re doing async database work.
|
|
540
|
-
* await delay(TimeSpan.fromSeconds(2));
|
|
541
|
-
* console.log("END: ", 2);
|
|
542
|
-
* }
|
|
543
|
-
* finally {
|
|
544
|
-
* await lock.release();
|
|
545
|
-
* }
|
|
546
|
-
* }
|
|
547
|
-
*
|
|
548
|
-
* await Promise.allSettled([
|
|
549
|
-
* fn(),
|
|
550
|
-
* fn(),
|
|
551
|
-
* fn(),
|
|
552
|
-
* fn(),
|
|
553
|
-
* ]);
|
|
554
|
-
* ```
|
|
555
|
-
*/
|
|
556
175
|
acquireOrFail() {
|
|
557
|
-
return this.
|
|
176
|
+
return this.createLazyPromise(async () => {
|
|
558
177
|
const hasAquired = await this.acquire();
|
|
559
178
|
if (!hasAquired) {
|
|
560
|
-
throw new KeyAlreadyAcquiredLockError(`Key "${this.key}" already acquired`);
|
|
179
|
+
throw new KeyAlreadyAcquiredLockError(`Key "${this.key.resolved}" already acquired`);
|
|
561
180
|
}
|
|
562
181
|
});
|
|
563
182
|
}
|
|
564
|
-
/**
|
|
565
|
-
* @example
|
|
566
|
-
* ```ts
|
|
567
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
568
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
569
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
570
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
571
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
572
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
573
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
574
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
575
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
576
|
-
* import { delay } from "@daiso-tech/core/async";
|
|
577
|
-
*
|
|
578
|
-
* const eventBus = new EventBus({
|
|
579
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
580
|
-
* });
|
|
581
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
582
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
583
|
-
* serde,
|
|
584
|
-
* adapter: new MemoryLockAdapter({
|
|
585
|
-
* rootGroup: "@global"
|
|
586
|
-
* }),
|
|
587
|
-
* eventBus,
|
|
588
|
-
* });
|
|
589
|
-
*
|
|
590
|
-
* const lock = lockProvider.create("a");
|
|
591
|
-
*
|
|
592
|
-
* async function fn(): Promise<void> {
|
|
593
|
-
* // Use try-finally when acquiring a lock to ensure it’s released if an error happens.
|
|
594
|
-
* try {
|
|
595
|
-
* const hasAquired = await lock.acquireBlocking();
|
|
596
|
-
* if (!hasAquired) {
|
|
597
|
-
* return;
|
|
598
|
-
* }
|
|
599
|
-
* console.log("START: ", 1);
|
|
600
|
-
* // Let’s pretend we’re doing async database work.
|
|
601
|
-
* await delay(TimeSpan.fromSeconds(2));
|
|
602
|
-
* console.log("END: ", 2);
|
|
603
|
-
* }
|
|
604
|
-
* finally {
|
|
605
|
-
* await lock.release();
|
|
606
|
-
* }
|
|
607
|
-
* }
|
|
608
|
-
*
|
|
609
|
-
* await Promise.allSettled([
|
|
610
|
-
* fn(),
|
|
611
|
-
* fn(),
|
|
612
|
-
* fn(),
|
|
613
|
-
* fn(),
|
|
614
|
-
* ]);
|
|
615
|
-
* ```
|
|
616
|
-
*/
|
|
617
183
|
acquireBlocking(settings = {}) {
|
|
618
184
|
return new LazyPromise(async () => {
|
|
619
|
-
const { time = this.
|
|
185
|
+
const { time = this.defaultBlockingTime, interval = this.defaultBlockingInterval, } = settings;
|
|
620
186
|
const endDate = time.toEndDate();
|
|
621
187
|
while (endDate.getTime() > new Date().getTime()) {
|
|
622
188
|
const hasAquired = await this.acquire();
|
|
623
189
|
if (hasAquired) {
|
|
624
190
|
return true;
|
|
625
191
|
}
|
|
626
|
-
await delay(interval);
|
|
192
|
+
await LazyPromise.delay(interval);
|
|
627
193
|
}
|
|
628
194
|
return false;
|
|
629
195
|
});
|
|
630
196
|
}
|
|
631
197
|
release() {
|
|
632
|
-
return this.
|
|
198
|
+
return this.createLazyPromise(async () => {
|
|
633
199
|
try {
|
|
634
|
-
const
|
|
200
|
+
const adapter = await this.adapterPromise;
|
|
201
|
+
const hasReleased = await adapter.release(this.key.prefixed, this.owner);
|
|
635
202
|
if (hasReleased) {
|
|
636
|
-
this.
|
|
203
|
+
this.lockState.remove();
|
|
637
204
|
const event = new KeyReleasedLockEvent({
|
|
638
|
-
key: this.key,
|
|
205
|
+
key: this.key.resolved,
|
|
639
206
|
owner: this.owner,
|
|
640
207
|
});
|
|
641
208
|
this.lockEventBus.dispatch(event).defer();
|
|
@@ -643,7 +210,7 @@ export class Lock {
|
|
|
643
210
|
}
|
|
644
211
|
else {
|
|
645
212
|
const event = new UnownedReleaseLockEvent({
|
|
646
|
-
key: this.key,
|
|
213
|
+
key: this.key.resolved,
|
|
647
214
|
owner: this.owner,
|
|
648
215
|
});
|
|
649
216
|
this.lockEventBus.dispatch(event).defer();
|
|
@@ -653,7 +220,7 @@ export class Lock {
|
|
|
653
220
|
}
|
|
654
221
|
catch (error) {
|
|
655
222
|
const event = new UnexpectedErrorLockEvent({
|
|
656
|
-
key: this.key,
|
|
223
|
+
key: this.key.resolved,
|
|
657
224
|
owner: this.owner,
|
|
658
225
|
ttl: this.ttl,
|
|
659
226
|
error,
|
|
@@ -665,27 +232,28 @@ export class Lock {
|
|
|
665
232
|
});
|
|
666
233
|
}
|
|
667
234
|
releaseOrFail() {
|
|
668
|
-
return this.
|
|
235
|
+
return this.createLazyPromise(async () => {
|
|
669
236
|
const hasRelased = await this.release();
|
|
670
237
|
if (!hasRelased) {
|
|
671
|
-
throw new UnownedReleaseLockError(`Unonwed release on key "${this.key}" by owner "${this.owner}"`);
|
|
238
|
+
throw new UnownedReleaseLockError(`Unonwed release on key "${this.key.resolved}" by owner "${this.owner}"`);
|
|
672
239
|
}
|
|
673
240
|
});
|
|
674
241
|
}
|
|
675
242
|
forceRelease() {
|
|
676
|
-
return this.
|
|
243
|
+
return this.createLazyPromise(async () => {
|
|
677
244
|
try {
|
|
678
|
-
await this.
|
|
679
|
-
this.
|
|
245
|
+
const adapter = await this.adapterPromise;
|
|
246
|
+
await adapter.forceRelease(this.key.prefixed);
|
|
247
|
+
this.lockState.remove();
|
|
680
248
|
const event = new KeyForceReleasedLockEvent({
|
|
681
|
-
key: this.key,
|
|
249
|
+
key: this.key.resolved,
|
|
682
250
|
});
|
|
683
251
|
this.lockEventBus.dispatch(event).defer();
|
|
684
252
|
this.lockProviderEventDispatcher.dispatch(event).defer();
|
|
685
253
|
}
|
|
686
254
|
catch (error) {
|
|
687
255
|
const event = new UnexpectedErrorLockEvent({
|
|
688
|
-
key: this.key,
|
|
256
|
+
key: this.key.resolved,
|
|
689
257
|
owner: this.owner,
|
|
690
258
|
ttl: this.ttl,
|
|
691
259
|
error,
|
|
@@ -698,13 +266,13 @@ export class Lock {
|
|
|
698
266
|
}
|
|
699
267
|
isExpired() {
|
|
700
268
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
701
|
-
return this.
|
|
269
|
+
return this.createLazyPromise(async () => {
|
|
702
270
|
try {
|
|
703
|
-
return this.
|
|
271
|
+
return this.lockState.isExpired();
|
|
704
272
|
}
|
|
705
273
|
catch (error) {
|
|
706
274
|
const event = new UnexpectedErrorLockEvent({
|
|
707
|
-
key: this.key,
|
|
275
|
+
key: this.key.resolved,
|
|
708
276
|
owner: this.owner,
|
|
709
277
|
ttl: this.ttl,
|
|
710
278
|
error,
|
|
@@ -716,28 +284,29 @@ export class Lock {
|
|
|
716
284
|
});
|
|
717
285
|
}
|
|
718
286
|
isLocked() {
|
|
719
|
-
return this.
|
|
287
|
+
return this.createLazyPromise(async () => {
|
|
720
288
|
const isExpired = await this.isExpired();
|
|
721
289
|
return !isExpired;
|
|
722
290
|
});
|
|
723
291
|
}
|
|
724
292
|
refresh(ttl = this.defaultRefreshTime) {
|
|
725
|
-
return this.
|
|
293
|
+
return this.createLazyPromise(async () => {
|
|
726
294
|
try {
|
|
727
|
-
const
|
|
295
|
+
const adapter = await this.adapterPromise;
|
|
296
|
+
const hasRefreshed = await adapter.refresh(this.key.prefixed, this.owner, ttl);
|
|
728
297
|
if (hasRefreshed) {
|
|
729
298
|
const event = new KeyRefreshedLockEvent({
|
|
730
|
-
key: this.key,
|
|
299
|
+
key: this.key.resolved,
|
|
731
300
|
owner: this.owner,
|
|
732
301
|
ttl,
|
|
733
302
|
});
|
|
734
|
-
this.
|
|
303
|
+
this.lockState.set(ttl);
|
|
735
304
|
this.lockEventBus.dispatch(event).defer();
|
|
736
305
|
this.lockProviderEventDispatcher.dispatch(event).defer();
|
|
737
306
|
}
|
|
738
307
|
else {
|
|
739
308
|
const event = new UnownedRefreshLockEvent({
|
|
740
|
-
key: this.key,
|
|
309
|
+
key: this.key.resolved,
|
|
741
310
|
owner: this.owner,
|
|
742
311
|
});
|
|
743
312
|
this.lockEventBus.dispatch(event).defer();
|
|
@@ -747,7 +316,7 @@ export class Lock {
|
|
|
747
316
|
}
|
|
748
317
|
catch (error) {
|
|
749
318
|
const event = new UnexpectedErrorLockEvent({
|
|
750
|
-
key: this.key,
|
|
319
|
+
key: this.key.resolved,
|
|
751
320
|
owner: this.owner,
|
|
752
321
|
ttl: this.ttl,
|
|
753
322
|
error,
|
|
@@ -759,311 +328,24 @@ export class Lock {
|
|
|
759
328
|
});
|
|
760
329
|
}
|
|
761
330
|
refreshOrFail(ttl) {
|
|
762
|
-
return this.
|
|
331
|
+
return this.createLazyPromise(async () => {
|
|
763
332
|
const hasRefreshed = await this.refresh(ttl);
|
|
764
333
|
if (!hasRefreshed) {
|
|
765
|
-
throw new UnownedRefreshLockError(`Unonwed refresh on key "${this.key}" by owner "${this.owner}"`);
|
|
334
|
+
throw new UnownedRefreshLockError(`Unonwed refresh on key "${this.key.resolved}" by owner "${this.owner}"`);
|
|
766
335
|
}
|
|
767
336
|
});
|
|
768
337
|
}
|
|
769
338
|
getRemainingTime() {
|
|
770
339
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
771
|
-
return this.
|
|
772
|
-
return this.
|
|
340
|
+
return this.createLazyPromise(async () => {
|
|
341
|
+
return this.lockState.getRemainingTime();
|
|
773
342
|
});
|
|
774
343
|
}
|
|
775
344
|
getOwner() {
|
|
776
345
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
777
|
-
return this.
|
|
346
|
+
return this.createLazyPromise(async () => {
|
|
778
347
|
return this.owner;
|
|
779
348
|
});
|
|
780
349
|
}
|
|
781
|
-
/**
|
|
782
|
-
* You can listen to different events of the current <i>Lock</i> class instance.
|
|
783
|
-
*
|
|
784
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
785
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
786
|
-
* @example
|
|
787
|
-
* ```ts
|
|
788
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
789
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
790
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
791
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
792
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
793
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
794
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
795
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
796
|
-
*
|
|
797
|
-
* const eventBus = new EventBus({
|
|
798
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
799
|
-
* });
|
|
800
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
801
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
802
|
-
* serde,
|
|
803
|
-
* adapter: new MemoryLockAdapter({
|
|
804
|
-
* rootGroup: "@global"
|
|
805
|
-
* }),
|
|
806
|
-
* eventBus,
|
|
807
|
-
* });
|
|
808
|
-
*
|
|
809
|
-
* const lock = lockProvider.create("a");
|
|
810
|
-
*
|
|
811
|
-
* const listener: Invokable <LockEvents> = event => {
|
|
812
|
-
* console.log(event);
|
|
813
|
-
* }
|
|
814
|
-
* await lock.addListener(KeyAcquiredLockEvent, listener);
|
|
815
|
-
* await lock.acquire();
|
|
816
|
-
* ```
|
|
817
|
-
*/
|
|
818
|
-
addListener(event, listener) {
|
|
819
|
-
return this.lockEventBus.addListener(event, listener);
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* You can listen to different events of the current <i>Lock</i> class instance.
|
|
823
|
-
*
|
|
824
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
825
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
826
|
-
* @example
|
|
827
|
-
* ```ts
|
|
828
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
829
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
830
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
831
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
832
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
833
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
834
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
835
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
836
|
-
*
|
|
837
|
-
* const eventBus = new EventBus({
|
|
838
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
839
|
-
* });
|
|
840
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
841
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
842
|
-
* serde,
|
|
843
|
-
* adapter: new MemoryLockAdapter({
|
|
844
|
-
* rootGroup: "@global"
|
|
845
|
-
* }),
|
|
846
|
-
* eventBus,
|
|
847
|
-
* });
|
|
848
|
-
*
|
|
849
|
-
* const lock = lockProvider.create("a");
|
|
850
|
-
*
|
|
851
|
-
* const listener: Invokable <LockEvents> = event => {
|
|
852
|
-
* console.log(event);
|
|
853
|
-
* }
|
|
854
|
-
* await lock.addListenerMany([KeyAcquiredLockEvent], listener);
|
|
855
|
-
* await lock.acquire();
|
|
856
|
-
* ```
|
|
857
|
-
*/
|
|
858
|
-
addListenerMany(events, listener) {
|
|
859
|
-
return this.lockEventBus.addListenerMany(events, listener);
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* You can listen to different events of the current <i>Lock</i> class instance.
|
|
863
|
-
*
|
|
864
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
865
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
866
|
-
* @example
|
|
867
|
-
* ```ts
|
|
868
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
869
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
870
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
871
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
872
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
873
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
874
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
875
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
876
|
-
*
|
|
877
|
-
* const eventBus = new EventBus({
|
|
878
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
879
|
-
* });
|
|
880
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
881
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
882
|
-
* serde,
|
|
883
|
-
* adapter: new MemoryLockAdapter({
|
|
884
|
-
* rootGroup: "@global"
|
|
885
|
-
* }),
|
|
886
|
-
* eventBus,
|
|
887
|
-
* });
|
|
888
|
-
*
|
|
889
|
-
* const lock = lockProvider.create("a");
|
|
890
|
-
*
|
|
891
|
-
* const listener: Invokable <LockEvents> = event => {
|
|
892
|
-
* console.log(event);
|
|
893
|
-
* }
|
|
894
|
-
* await lock.addListener(KeyAcquiredLockEvent, listener);
|
|
895
|
-
* await lock.removeListener(KeyAcquiredLockEvent, listener);
|
|
896
|
-
* await lock.acquire();
|
|
897
|
-
* ```
|
|
898
|
-
*/
|
|
899
|
-
removeListener(event, listener) {
|
|
900
|
-
return this.lockEventBus.removeListener(event, listener);
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* You can listen to different events of the current <i>Lock</i> class instance.
|
|
904
|
-
*
|
|
905
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
906
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
907
|
-
* @example
|
|
908
|
-
* ```ts
|
|
909
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
910
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
911
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
912
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
913
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
914
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
915
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
916
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
917
|
-
*
|
|
918
|
-
* const eventBus = new EventBus({
|
|
919
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
920
|
-
* });
|
|
921
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
922
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
923
|
-
* serde,
|
|
924
|
-
* adapter: new MemoryLockAdapter({
|
|
925
|
-
* rootGroup: "@global"
|
|
926
|
-
* }),
|
|
927
|
-
* eventBus,
|
|
928
|
-
* });
|
|
929
|
-
*
|
|
930
|
-
* const lock = lockProvider.create("a");
|
|
931
|
-
*
|
|
932
|
-
* const listener: Invokable <LockEvents> = event => {
|
|
933
|
-
* console.log(event);
|
|
934
|
-
* }
|
|
935
|
-
* await lock.addListenerMany([KeyAcquiredLockEvent], listener);
|
|
936
|
-
* await lock.removeListenerMany([KeyAcquiredLockEvent], listener);
|
|
937
|
-
* await lock.acquire();
|
|
938
|
-
* ```
|
|
939
|
-
*/
|
|
940
|
-
removeListenerMany(events, listener) {
|
|
941
|
-
return this.lockEventBus.removeListenerMany(events, listener);
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* You can listen to different events of the current <i>Lock</i> class instance.
|
|
945
|
-
*
|
|
946
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
947
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
948
|
-
* @example
|
|
949
|
-
* ```ts
|
|
950
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
951
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
952
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
953
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
954
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
955
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
956
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
957
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
958
|
-
*
|
|
959
|
-
* const eventBus = new EventBus({
|
|
960
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
961
|
-
* });
|
|
962
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
963
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
964
|
-
* serde,
|
|
965
|
-
* adapter: new MemoryLockAdapter({
|
|
966
|
-
* rootGroup: "@global"
|
|
967
|
-
* }),
|
|
968
|
-
* eventBus,
|
|
969
|
-
* });
|
|
970
|
-
*
|
|
971
|
-
* const lock = lockProvider.create("a");
|
|
972
|
-
*
|
|
973
|
-
* const listener: Invokable <LockEvents> = event => {
|
|
974
|
-
* console.log(event);
|
|
975
|
-
* }
|
|
976
|
-
* await lock.listenOnce(KeyAcquiredLockEvent, listener);
|
|
977
|
-
* await lock.acquire();
|
|
978
|
-
* ```
|
|
979
|
-
*/
|
|
980
|
-
listenOnce(event, listener) {
|
|
981
|
-
return this.lockEventBus.listenOnce(event, listener);
|
|
982
|
-
}
|
|
983
|
-
asPromise(event) {
|
|
984
|
-
return this.lockEventBus.asPromise(event);
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* You can listen to different events of the current <i>Lock</i> class instance.
|
|
988
|
-
*
|
|
989
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
990
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
991
|
-
* @example
|
|
992
|
-
* ```ts
|
|
993
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
994
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
995
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
996
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
997
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
998
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
999
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
1000
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
1001
|
-
*
|
|
1002
|
-
* const eventBus = new EventBus({
|
|
1003
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
1004
|
-
* });
|
|
1005
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
1006
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
1007
|
-
* serde,
|
|
1008
|
-
* adapter: new MemoryLockAdapter({
|
|
1009
|
-
* rootGroup: "@global"
|
|
1010
|
-
* }),
|
|
1011
|
-
* eventBus,
|
|
1012
|
-
* });
|
|
1013
|
-
*
|
|
1014
|
-
* const lock = lockProvider.create("a");
|
|
1015
|
-
*
|
|
1016
|
-
* const listener: Invokable <LockEvents> = event => {
|
|
1017
|
-
* console.log(event);
|
|
1018
|
-
* }
|
|
1019
|
-
* const unsubscribe = await lock.subscribe(KeyAcquiredLockEvent, listener);
|
|
1020
|
-
* await lock.acquire();
|
|
1021
|
-
* await unsubscribe();
|
|
1022
|
-
* ```
|
|
1023
|
-
*/
|
|
1024
|
-
subscribe(event, listener) {
|
|
1025
|
-
return this.lockEventBus.subscribe(event, listener);
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* You can listen to different events of the current <i>Lock</i> class instance.
|
|
1029
|
-
*
|
|
1030
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
1031
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
1032
|
-
* @example
|
|
1033
|
-
* ```ts
|
|
1034
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
1035
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
1036
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
1037
|
-
* import type { Invokable } from "@daiso-tech/core/event-bus/contracts";
|
|
1038
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
1039
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
1040
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
1041
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
1042
|
-
*
|
|
1043
|
-
* const eventBus = new EventBus({
|
|
1044
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
1045
|
-
* });
|
|
1046
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
1047
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
1048
|
-
* serde,
|
|
1049
|
-
* adapter: new MemoryLockAdapter({
|
|
1050
|
-
* rootGroup: "@global"
|
|
1051
|
-
* }),
|
|
1052
|
-
* eventBus,
|
|
1053
|
-
* });
|
|
1054
|
-
*
|
|
1055
|
-
* const lock = lockProvider.create("a");
|
|
1056
|
-
*
|
|
1057
|
-
* const listener: Invokable <LockEvents> = event => {
|
|
1058
|
-
* console.log(event);
|
|
1059
|
-
* }
|
|
1060
|
-
* const unsubscribe = await lock.subscribeMany([KeyAcquiredLockEvent], listener);
|
|
1061
|
-
* await lock.acquire();
|
|
1062
|
-
* await unsubscribe();
|
|
1063
|
-
* ```
|
|
1064
|
-
*/
|
|
1065
|
-
subscribeMany(events, listener) {
|
|
1066
|
-
return this.lockEventBus.subscribeMany(events, listener);
|
|
1067
|
-
}
|
|
1068
350
|
}
|
|
1069
351
|
//# sourceMappingURL=lock.js.map
|