@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,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { resolveOneOrMore, TimeSpan, } from "../../../../utilities/_module-exports.js";
|
|
5
|
+
import { KeyPrefixer, resolveFactoryable, } from "../../../../utilities/_module-exports.js";
|
|
5
6
|
import {} from "../../../../lock/contracts/_module-exports.js";
|
|
6
|
-
import {
|
|
7
|
+
import { LazyPromise, } from "../../../../async/_module-exports.js";
|
|
8
|
+
import { isDatabaseLockAdapter } from "../../../../lock/implementations/derivables/lock-provider/is-database-lock-adapter.js";
|
|
9
|
+
import { DatabaseLockAdapter } from "../../../../lock/implementations/derivables/lock-provider/database-lock-adapter.js";
|
|
7
10
|
import { EventBus } from "../../../../event-bus/implementations/derivables/_module-exports.js";
|
|
8
11
|
import { MemoryEventBusAdapter } from "../../../../event-bus/implementations/adapters/_module-exports.js";
|
|
9
12
|
import { v4 } from "uuid";
|
|
10
|
-
import {
|
|
13
|
+
import { Lock } from "../../../../lock/implementations/derivables/lock-provider/lock.js";
|
|
14
|
+
import { LockState, } from "../../../../lock/implementations/derivables/lock-provider/lock-state.js";
|
|
11
15
|
import { LockSerdeTransformer } from "../../../../lock/implementations/derivables/lock-provider/lock-serde-transformer.js";
|
|
12
16
|
/**
|
|
13
17
|
* <i>LockProvider</i> class can be derived from any <i>{@link ILockAdapter}</i> or <i>{@link IDatabaseLockAdapter}</i>.
|
|
@@ -16,524 +20,262 @@ import { LockSerdeTransformer } from "../../../../lock/implementations/derivable
|
|
|
16
20
|
* allowing them to be seamlessly transferred across different servers, processes, and databases.
|
|
17
21
|
* This can be done directly using <i>{@link IFlexibleSerde}</i> or indirectly through components that rely on <i>{@link IFlexibleSerde}</i> internally.
|
|
18
22
|
*
|
|
19
|
-
* IMPORT_PATH: ```"@daiso-tech/core/lock
|
|
23
|
+
* IMPORT_PATH: ```"@daiso-tech/core/lock"```
|
|
20
24
|
* @group Derivables
|
|
21
25
|
*/
|
|
22
26
|
export class LockProvider {
|
|
23
|
-
static
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
adapter_["init"].length === 0 &&
|
|
29
|
-
typeof adapter_["deInit"] === "function" &&
|
|
30
|
-
adapter_["deInit"].length === 0 &&
|
|
31
|
-
typeof adapter_["insert"] === "function" &&
|
|
32
|
-
adapter_["insert"].length === 3 &&
|
|
33
|
-
typeof adapter_["update"] === "function" &&
|
|
34
|
-
adapter_["update"].length === 3 &&
|
|
35
|
-
typeof adapter_["remove"] === "function" &&
|
|
36
|
-
adapter_["remove"].length === 2 &&
|
|
37
|
-
typeof adapter_["refresh"] === "function" &&
|
|
38
|
-
adapter_["refresh"].length === 3 &&
|
|
39
|
-
typeof adapter_["find"] === "function" &&
|
|
40
|
-
adapter_["find"].length === 1 &&
|
|
41
|
-
typeof adapter_["getGroup"] === "function" &&
|
|
42
|
-
adapter_["getGroup"].length === 0 &&
|
|
43
|
-
typeof adapter_["withGroup"] === "function" &&
|
|
44
|
-
adapter_["withGroup"].length === 1);
|
|
27
|
+
static resolveLockAdapter(adapter) {
|
|
28
|
+
if (isDatabaseLockAdapter(adapter)) {
|
|
29
|
+
return new DatabaseLockAdapter(adapter);
|
|
30
|
+
}
|
|
31
|
+
return adapter;
|
|
45
32
|
}
|
|
46
|
-
|
|
33
|
+
static async resolveLockAdapterFactoryable(factoryable, settings) {
|
|
34
|
+
const { serde, lockStore, keyPrefixer, createLazyPromise, defaultBlockingInterval, defaultBlockingTime, defaultRefreshTime, groupableEventBus, } = settings;
|
|
35
|
+
const adapter = await resolveFactoryable(factoryable, keyPrefixer.keyPrefix);
|
|
36
|
+
const resolvedAdapter = LockProvider.resolveLockAdapter(adapter);
|
|
37
|
+
const transformer = new LockSerdeTransformer({
|
|
38
|
+
keyPrefixer,
|
|
39
|
+
adapter: resolvedAdapter,
|
|
40
|
+
createLazyPromise,
|
|
41
|
+
lockStore,
|
|
42
|
+
defaultBlockingInterval,
|
|
43
|
+
defaultBlockingTime,
|
|
44
|
+
defaultRefreshTime,
|
|
45
|
+
groupableEventBus,
|
|
46
|
+
});
|
|
47
|
+
for (const serde_ of resolveOneOrMore(serde)) {
|
|
48
|
+
serde_.registerCustom(transformer);
|
|
49
|
+
}
|
|
50
|
+
return resolvedAdapter;
|
|
51
|
+
}
|
|
52
|
+
lockStore = {};
|
|
53
|
+
groupableEventBus;
|
|
54
|
+
eventBus;
|
|
55
|
+
adapterFactoryable;
|
|
56
|
+
adapterPromise;
|
|
57
|
+
retryAttempts;
|
|
58
|
+
backoffPolicy;
|
|
59
|
+
retryPolicy;
|
|
60
|
+
timeout;
|
|
61
|
+
keyPrefixer;
|
|
47
62
|
createOwnerId;
|
|
48
|
-
adapter;
|
|
49
63
|
defaultTtl;
|
|
50
64
|
defaultBlockingInterval;
|
|
51
65
|
defaultBlockingTime;
|
|
52
66
|
defaultRefreshTime;
|
|
53
|
-
|
|
54
|
-
backoffPolicy;
|
|
55
|
-
retryPolicy;
|
|
56
|
-
timeout;
|
|
57
|
-
eventBus;
|
|
58
|
-
lockProviderEventBus;
|
|
59
|
-
stateRecord = {};
|
|
67
|
+
serde;
|
|
60
68
|
/**
|
|
61
69
|
* @example
|
|
62
70
|
* ```ts
|
|
63
|
-
* import
|
|
64
|
-
* import { LockProvider } from "@daiso-tech/core/lock
|
|
65
|
-
* import {
|
|
66
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
67
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
68
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
69
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
71
|
+
* import { SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
72
|
+
* import { LockProvider } from "@daiso-tech/core/lock";
|
|
73
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
70
74
|
*
|
|
71
|
-
* const
|
|
72
|
-
*
|
|
75
|
+
* const database = new Sqlite("local.db");
|
|
76
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
77
|
+
* database,
|
|
73
78
|
* });
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* eventBus,
|
|
79
|
+
* // You need initialize the adapter once before using it.
|
|
80
|
+
* await lockAdapter.init();
|
|
81
|
+
*
|
|
82
|
+
* const lockProvider = new LockProvider({
|
|
83
|
+
* keyPrefixer: new KeyPrefixer("lock"),
|
|
84
|
+
* adapter: lockAdapter,
|
|
81
85
|
* });
|
|
82
86
|
* ```
|
|
83
|
-
*/
|
|
84
|
-
constructor(settings) {
|
|
85
|
-
const { createOwnerId = () => v4(), adapter, defaultTtl = LockProvider.DEFAULT_TTL, defaultBlockingInterval = TimeSpan.fromSeconds(1), defaultBlockingTime = TimeSpan.fromMinutes(1), defaultRefreshTime = LockProvider.DEFAULT_REFRESH_TIME, retryAttempts = null, backoffPolicy = null, retryPolicy = null, timeout = null, eventBus = new EventBus({
|
|
86
|
-
adapter: new MemoryEventBusAdapter({
|
|
87
|
-
rootGroup: "@global",
|
|
88
|
-
}),
|
|
89
|
-
}), serde, } = settings;
|
|
90
|
-
this.createOwnerId = createOwnerId;
|
|
91
|
-
if (LockProvider.isDatabaseAdapter(adapter)) {
|
|
92
|
-
this.adapter = new DatabaseLockAdapter(adapter);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this.adapter = adapter;
|
|
96
|
-
}
|
|
97
|
-
this.serde = serde;
|
|
98
|
-
this.defaultTtl = defaultTtl ?? LockProvider.DEFAULT_TTL;
|
|
99
|
-
this.defaultBlockingInterval = defaultBlockingInterval;
|
|
100
|
-
this.defaultBlockingTime = defaultBlockingTime;
|
|
101
|
-
this.defaultRefreshTime = defaultRefreshTime;
|
|
102
|
-
this.retryAttempts = retryAttempts;
|
|
103
|
-
this.backoffPolicy = backoffPolicy;
|
|
104
|
-
this.retryPolicy = retryPolicy;
|
|
105
|
-
this.timeout = timeout;
|
|
106
|
-
this.eventBus = eventBus;
|
|
107
|
-
this.lockProviderEventBus = eventBus.withGroup(adapter.getGroup());
|
|
108
|
-
this.registerToSerde();
|
|
109
|
-
}
|
|
110
|
-
registerToSerde() {
|
|
111
|
-
const transformer = new LockSerdeTransformer({
|
|
112
|
-
defaultBlockingInterval: this.defaultBlockingInterval,
|
|
113
|
-
defaultBlockingTime: this.defaultBlockingTime,
|
|
114
|
-
adapter: this.adapter,
|
|
115
|
-
backoffPolicy: this.backoffPolicy,
|
|
116
|
-
defaultRefreshTime: this.defaultRefreshTime,
|
|
117
|
-
eventBus: this.eventBus,
|
|
118
|
-
retryAttempts: this.retryAttempts,
|
|
119
|
-
retryPolicy: this.retryPolicy,
|
|
120
|
-
timeout: this.timeout,
|
|
121
|
-
});
|
|
122
|
-
let serde = this.serde;
|
|
123
|
-
if (!Array.isArray(serde)) {
|
|
124
|
-
serde = [serde];
|
|
125
|
-
}
|
|
126
|
-
for (const serde_ of serde) {
|
|
127
|
-
serde_.registerCustom(transformer, CORE);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
132
87
|
*
|
|
133
|
-
*
|
|
134
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
88
|
+
* You can pass factory function that will create an adapter for every group.
|
|
135
89
|
* @example
|
|
136
90
|
* ```ts
|
|
137
|
-
* import {
|
|
138
|
-
* import { LockProvider } from "@daiso-tech/core/lock
|
|
139
|
-
* import {
|
|
140
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
141
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
142
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
143
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
144
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
91
|
+
* import { SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
92
|
+
* import { LockProvider } from "@daiso-tech/core/lock";
|
|
93
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
145
94
|
*
|
|
146
|
-
* const
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
150
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
151
|
-
* serde,
|
|
152
|
-
* adapter: new MemoryLockAdapter({
|
|
153
|
-
* rootGroup: "@global"
|
|
154
|
-
* }),
|
|
155
|
-
* eventBus,
|
|
95
|
+
* const database = new Sqlite("local.db");
|
|
96
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
97
|
+
* database,
|
|
156
98
|
* });
|
|
99
|
+
* // You need initialize the adapter once before using it.
|
|
100
|
+
* await lockAdapter.init();
|
|
157
101
|
*
|
|
158
|
-
* const
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* await lockProvider.removeListener(KeyAcquiredLockEvent, listener);
|
|
163
|
-
* await lockProvider.create("a").acquire();
|
|
102
|
+
* const lockProvider = new LockProvider({
|
|
103
|
+
* keyPrefixer: new KeyPrefixer("lock"),
|
|
104
|
+
* adapter: lockAdapter,
|
|
105
|
+
* });
|
|
164
106
|
* ```
|
|
165
|
-
*/
|
|
166
|
-
addListener(event, listener) {
|
|
167
|
-
return this.lockProviderEventBus.addListener(event, listener);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
171
107
|
*
|
|
172
|
-
*
|
|
173
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
108
|
+
* You can also pass factory object that implements <i>{@link IFactoryObject}</i> contract. This useful for depedency injection libraries.
|
|
174
109
|
* @example
|
|
175
110
|
* ```ts
|
|
176
|
-
* import {
|
|
177
|
-
* import {
|
|
178
|
-
* import {
|
|
179
|
-
* import type
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* adapter: new MemoryLockAdapter({
|
|
192
|
-
* rootGroup: "@global"
|
|
193
|
-
* }),
|
|
194
|
-
* eventBus,
|
|
195
|
-
* });
|
|
196
|
-
*
|
|
197
|
-
* const listener: Invokable<LockEvents> = event => {
|
|
198
|
-
* console.log(event);
|
|
111
|
+
* import { SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
112
|
+
* import type { ILockAdapter } from "@daiso-tech/core/lock/contracts";
|
|
113
|
+
* import { LockProvider } from "@daiso-tech/core/lock";
|
|
114
|
+
* import { KeyPrefixer, type Promiseable } from "@daiso-tech/core/utilities";
|
|
115
|
+
*
|
|
116
|
+
* async function lockAdapterFactory(prefix: string): Promiseable<ILockAdapter> {
|
|
117
|
+
* const database = new Sqlite("local.db");
|
|
118
|
+
* const database = new Sqlite("local.db");
|
|
119
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
120
|
+
* database,
|
|
121
|
+
* tableName: `lock_${prefix}`,
|
|
122
|
+
* });
|
|
123
|
+
* // You need initialize the adapter once before using it.
|
|
124
|
+
* await lockAdapter.init();
|
|
125
|
+
* return lockAdapter;
|
|
199
126
|
* }
|
|
200
|
-
* await lockProvider.addListenerMany([KeyAcquiredLockEvent], listener);
|
|
201
|
-
* await lockProvider.removeListenerMany([KeyAcquiredLockEvent], listener);
|
|
202
|
-
* await lockProvider.create("a").acquire();
|
|
203
|
-
* ```
|
|
204
|
-
*/
|
|
205
|
-
addListenerMany(events, listener) {
|
|
206
|
-
return this.lockProviderEventBus.addListenerMany(events, listener);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
210
127
|
*
|
|
211
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
212
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
213
|
-
* @example
|
|
214
|
-
* ```ts
|
|
215
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
216
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
217
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
218
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
219
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
220
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
221
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
222
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
223
128
|
*
|
|
224
|
-
* const
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
228
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
229
|
-
* serde,
|
|
230
|
-
* adapter: new MemoryLockAdapter({
|
|
231
|
-
* rootGroup: "@global"
|
|
232
|
-
* }),
|
|
233
|
-
* eventBus,
|
|
129
|
+
* const lockProvider = new LockProvider({
|
|
130
|
+
* keyPrefixer: new KeyPrefixer("lock"),
|
|
131
|
+
* adapter: lockAdapterFactory,
|
|
234
132
|
* });
|
|
235
|
-
*
|
|
236
|
-
* const listener: Invokable<LockEvents> = event => {
|
|
237
|
-
* console.log(event);
|
|
238
|
-
* }
|
|
239
|
-
* await lockProvider.addListener(KeyAcquiredLockEvent, listener);
|
|
240
|
-
* await lockProvider.removeListener(KeyAcquiredLockEvent, listener);
|
|
241
|
-
* await lockProvider.create("a").acquire();
|
|
242
133
|
* ```
|
|
243
|
-
*/
|
|
244
|
-
removeListener(event, listener) {
|
|
245
|
-
return this.lockProviderEventBus.removeListener(event, listener);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
249
134
|
*
|
|
250
|
-
*
|
|
251
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
135
|
+
* You can pass factory function that will create an adapter for every group.
|
|
252
136
|
* @example
|
|
253
137
|
* ```ts
|
|
254
|
-
* import {
|
|
255
|
-
* import {
|
|
256
|
-
* import {
|
|
257
|
-
* import type
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
138
|
+
* import { SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
139
|
+
* import type { ILockAdapter } from "@daiso-tech/core/lock/contracts";
|
|
140
|
+
* import { LockProvider } from "@daiso-tech/core/lock";
|
|
141
|
+
* import { KeyPrefixer, type IFactoryObject, type Promiseable } from "@daiso-tech/core/utilities";
|
|
142
|
+
*
|
|
143
|
+
* class LockAdapterFactory implementations IFactoryObject<string, ILockAdapter> {
|
|
144
|
+
* async use(prefix: string): Promiseable<ILockAdapter> {
|
|
145
|
+
* const database = new Sqlite("local.db");
|
|
146
|
+
* const database = new Sqlite("local.db");
|
|
147
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
148
|
+
* database,
|
|
149
|
+
* tableName: `lock_${prefix}`,
|
|
150
|
+
* });
|
|
151
|
+
* // You need initialize the adapter once before using it.
|
|
152
|
+
* await lockAdapter.init();
|
|
153
|
+
* return lockAdapter;
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
262
156
|
*
|
|
263
|
-
* const
|
|
264
|
-
*
|
|
157
|
+
* const lockProvider = new LockProvider({
|
|
158
|
+
* keyPrefixer: new KeyPrefixer("lock"),
|
|
159
|
+
* adapter: new LockAdapterFactory(),
|
|
265
160
|
* });
|
|
266
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
267
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
268
|
-
* serde,
|
|
269
|
-
* adapter: new MemoryLockAdapter({
|
|
270
|
-
* rootGroup: "@global"
|
|
271
|
-
* }),
|
|
272
|
-
* eventBus,
|
|
273
|
-
* });
|
|
274
|
-
*
|
|
275
|
-
* const listener: Invokable<LockEvents> = event => {
|
|
276
|
-
* console.log(event);
|
|
277
|
-
* }
|
|
278
|
-
* await lockProvider.addListenerMany(KeyAcquiredLockEvent, listener);
|
|
279
|
-
* await lockProvider.removeListenerMany([KeyAcquiredLockEvent], listener);
|
|
280
|
-
* await lockProvider.create("a").acquire();
|
|
281
161
|
* ```
|
|
282
162
|
*/
|
|
163
|
+
constructor(settings) {
|
|
164
|
+
const { defaultTtl = TimeSpan.fromMinutes(5), defaultBlockingInterval = TimeSpan.fromSeconds(1), defaultBlockingTime = TimeSpan.fromMinutes(1), defaultRefreshTime = TimeSpan.fromMinutes(5), createOwnerId = () => v4(), serde, keyPrefixer, adapter, eventBus: groupableEventBus = new EventBus({
|
|
165
|
+
keyPrefixer: new KeyPrefixer("events"),
|
|
166
|
+
adapter: new MemoryEventBusAdapter(),
|
|
167
|
+
}), retryAttempts = null, backoffPolicy = null, retryPolicy = null, timeout = null, } = settings;
|
|
168
|
+
this.serde = serde;
|
|
169
|
+
this.defaultBlockingInterval = defaultBlockingInterval;
|
|
170
|
+
this.defaultBlockingTime = defaultBlockingTime;
|
|
171
|
+
this.defaultRefreshTime = defaultRefreshTime;
|
|
172
|
+
this.createOwnerId = createOwnerId;
|
|
173
|
+
this.keyPrefixer = keyPrefixer;
|
|
174
|
+
this.groupableEventBus = groupableEventBus;
|
|
175
|
+
this.adapterFactoryable = adapter;
|
|
176
|
+
this.defaultTtl = defaultTtl;
|
|
177
|
+
this.retryAttempts = retryAttempts;
|
|
178
|
+
this.backoffPolicy = backoffPolicy;
|
|
179
|
+
this.retryPolicy = retryPolicy;
|
|
180
|
+
this.timeout = timeout;
|
|
181
|
+
this.eventBus = this.eventBus = this.groupableEventBus.withGroup(this.keyPrefixer.resolvedRootPrefix);
|
|
182
|
+
if (this.keyPrefixer.resolvedGroup) {
|
|
183
|
+
this.eventBus = this.groupableEventBus.withGroup([
|
|
184
|
+
this.keyPrefixer.resolvedRootPrefix,
|
|
185
|
+
this.keyPrefixer.resolvedGroup,
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
this.adapterPromise = new LazyPromise(async () => LockProvider.resolveLockAdapterFactoryable(this.adapterFactoryable, {
|
|
189
|
+
serde,
|
|
190
|
+
lockStore: this.lockStore,
|
|
191
|
+
keyPrefixer,
|
|
192
|
+
createLazyPromise: this.createLazyPromise.bind(this),
|
|
193
|
+
defaultBlockingInterval,
|
|
194
|
+
defaultBlockingTime,
|
|
195
|
+
defaultRefreshTime,
|
|
196
|
+
groupableEventBus,
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
addListener(event, listener) {
|
|
200
|
+
return this.eventBus.addListener(event, listener);
|
|
201
|
+
}
|
|
202
|
+
addListenerMany(events, listener) {
|
|
203
|
+
return this.eventBus.addListenerMany(events, listener);
|
|
204
|
+
}
|
|
205
|
+
removeListener(event, listener) {
|
|
206
|
+
return this.eventBus.removeListener(event, listener);
|
|
207
|
+
}
|
|
283
208
|
removeListenerMany(events, listener) {
|
|
284
|
-
return this.
|
|
209
|
+
return this.eventBus.removeListenerMany(events, listener);
|
|
285
210
|
}
|
|
286
|
-
/**
|
|
287
|
-
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
288
|
-
*
|
|
289
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
290
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
291
|
-
* @example
|
|
292
|
-
* ```ts
|
|
293
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
294
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
295
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
296
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
297
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
298
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
299
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
300
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
301
|
-
*
|
|
302
|
-
* const eventBus = new EventBus({
|
|
303
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
304
|
-
* });
|
|
305
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
306
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
307
|
-
* serde,
|
|
308
|
-
* adapter: new MemoryLockAdapter({
|
|
309
|
-
* rootGroup: "@global"
|
|
310
|
-
* }),
|
|
311
|
-
* eventBus,
|
|
312
|
-
* });
|
|
313
|
-
*
|
|
314
|
-
* const listener: Invokable<LockEvents> = event => {
|
|
315
|
-
* console.log(event);
|
|
316
|
-
* }
|
|
317
|
-
* await lockProvider.listenOnce(KeyAcquiredLockEvent, listener);
|
|
318
|
-
* await lockProvider.create("a").acquire();
|
|
319
|
-
* ```
|
|
320
|
-
*/
|
|
321
211
|
listenOnce(event, listener) {
|
|
322
|
-
return this.
|
|
212
|
+
return this.eventBus.listenOnce(event, listener);
|
|
323
213
|
}
|
|
324
214
|
asPromise(event) {
|
|
325
|
-
return this.
|
|
215
|
+
return this.eventBus.asPromise(event);
|
|
326
216
|
}
|
|
327
|
-
/**
|
|
328
|
-
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
329
|
-
*
|
|
330
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
331
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
332
|
-
* @example
|
|
333
|
-
* ```ts
|
|
334
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
335
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
336
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
337
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
338
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
339
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
340
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
341
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
342
|
-
*
|
|
343
|
-
* const eventBus = new EventBus({
|
|
344
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
345
|
-
* });
|
|
346
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
347
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
348
|
-
* serde,
|
|
349
|
-
* adapter: new MemoryLockAdapter({
|
|
350
|
-
* rootGroup: "@global"
|
|
351
|
-
* }),
|
|
352
|
-
* eventBus,
|
|
353
|
-
* });
|
|
354
|
-
*
|
|
355
|
-
* const listener: Invokable<LockEvents> = event => {
|
|
356
|
-
* console.log(event);
|
|
357
|
-
* }
|
|
358
|
-
* const unsubscribe = await lockProvider.subscribe(KeyAcquiredLockEvent, listener);
|
|
359
|
-
* await lockProvider.create("a").acquire();
|
|
360
|
-
* await unsubscribe();
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
217
|
subscribe(event, listener) {
|
|
364
|
-
return this.
|
|
218
|
+
return this.eventBus.subscribe(event, listener);
|
|
365
219
|
}
|
|
366
|
-
/**
|
|
367
|
-
* You can listen to different events of all locks created by <i>LockProvider</i> class instance.
|
|
368
|
-
*
|
|
369
|
-
* Refer to <i>{@link LockEvents}</i>, to se all events dispatched by <i>LockProvider</i> class instance.
|
|
370
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
371
|
-
* @example
|
|
372
|
-
* ```ts
|
|
373
|
-
* import { type IGroupableLockProvider, type LockEvents, KeyAcquiredLockEvent } from "@daiso-tech/core/lock/contracts";
|
|
374
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
375
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
376
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
377
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
378
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
379
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
380
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
381
|
-
*
|
|
382
|
-
* const eventBus = new EventBus({
|
|
383
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
384
|
-
* });
|
|
385
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
386
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
387
|
-
* serde,
|
|
388
|
-
* adapter: new MemoryLockAdapter({
|
|
389
|
-
* rootGroup: "@global"
|
|
390
|
-
* }),
|
|
391
|
-
* eventBus,
|
|
392
|
-
* });
|
|
393
|
-
*
|
|
394
|
-
* const listener: Invokable<LockEvents> = event => {
|
|
395
|
-
* console.log(event);
|
|
396
|
-
* }
|
|
397
|
-
* const unsubscribe = await lockProvider.subscribeMany([KeyAcquiredLockEvent], listener);
|
|
398
|
-
* await lockProvider.create("a").acquire();
|
|
399
|
-
* await unsubscribe();
|
|
400
|
-
* ```
|
|
401
|
-
*/
|
|
402
220
|
subscribeMany(events, listener) {
|
|
403
|
-
return this.
|
|
221
|
+
return this.eventBus.subscribeMany(events, listener);
|
|
222
|
+
}
|
|
223
|
+
createLazyPromise(asyncFn) {
|
|
224
|
+
return new LazyPromise(asyncFn, {
|
|
225
|
+
retryAttempts: this.retryAttempts,
|
|
226
|
+
backoffPolicy: this.backoffPolicy,
|
|
227
|
+
retryPolicy: this.retryPolicy,
|
|
228
|
+
timeout: this.timeout,
|
|
229
|
+
});
|
|
404
230
|
}
|
|
405
|
-
/**
|
|
406
|
-
* ```ts
|
|
407
|
-
* import type { IGroupableLockProvider } from "@daiso-tech/core/lock/contracts";
|
|
408
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
409
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
410
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
411
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
412
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
413
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
414
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
415
|
-
*
|
|
416
|
-
* const eventBus = new EventBus({
|
|
417
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
418
|
-
* });
|
|
419
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
420
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
421
|
-
* serde,
|
|
422
|
-
* adapter: new MemoryLockAdapter({
|
|
423
|
-
* rootGroup: "@global"
|
|
424
|
-
* }),
|
|
425
|
-
* eventBus,
|
|
426
|
-
* });
|
|
427
|
-
*
|
|
428
|
-
* // You can use the lock
|
|
429
|
-
* const lockA = lockProvider.create("a");
|
|
430
|
-
*
|
|
431
|
-
* // You can provide ttl
|
|
432
|
-
* const lockB = lockProvider.create("b", {
|
|
433
|
-
* ttl: TimeSpan.fromMinutes(2),
|
|
434
|
-
* });
|
|
435
|
-
*
|
|
436
|
-
* // You can provide a custom owner. By default the owner will be unique random value.
|
|
437
|
-
* const lockC = lockProvider.create("b", {
|
|
438
|
-
* owner: "user-1"
|
|
439
|
-
* });
|
|
440
|
-
* ```
|
|
441
|
-
*/
|
|
442
231
|
create(key, settings = {}) {
|
|
443
232
|
const { ttl = this.defaultTtl, owner = this.createOwnerId() } = settings;
|
|
233
|
+
const keyObj = this.keyPrefixer.create(key);
|
|
234
|
+
let lockEventBus = this.groupableEventBus.withGroup([
|
|
235
|
+
this.keyPrefixer.resolvedRootPrefix,
|
|
236
|
+
keyObj.resolved,
|
|
237
|
+
]);
|
|
238
|
+
if (this.keyPrefixer.resolvedGroup) {
|
|
239
|
+
lockEventBus = this.groupableEventBus.withGroup([
|
|
240
|
+
this.keyPrefixer.resolvedRootPrefix,
|
|
241
|
+
this.keyPrefixer.resolvedGroup,
|
|
242
|
+
keyObj.resolved,
|
|
243
|
+
]);
|
|
244
|
+
}
|
|
444
245
|
return new Lock({
|
|
246
|
+
adapterPromise: this.adapterPromise,
|
|
247
|
+
group: this.keyPrefixer.resolvedGroup,
|
|
248
|
+
createLazyPromise: this.createLazyPromise.bind(this),
|
|
249
|
+
lockState: new LockState(this.lockStore, keyObj.prefixed),
|
|
250
|
+
lockEventBus: lockEventBus,
|
|
251
|
+
lockProviderEventDispatcher: this.eventBus,
|
|
252
|
+
key: keyObj,
|
|
253
|
+
owner,
|
|
254
|
+
ttl,
|
|
255
|
+
expirationInMs: null,
|
|
445
256
|
defaultBlockingInterval: this.defaultBlockingInterval,
|
|
446
257
|
defaultBlockingTime: this.defaultBlockingTime,
|
|
447
|
-
lockProviderEventDispatcher: this.lockProviderEventBus,
|
|
448
|
-
lockEventBus: this.eventBus,
|
|
449
|
-
adapter: this.adapter,
|
|
450
258
|
defaultRefreshTime: this.defaultRefreshTime,
|
|
451
|
-
key: resolveOneOrMoreStr(key),
|
|
452
|
-
owner: resolveOneOrMoreStr(owner),
|
|
453
|
-
ttl,
|
|
454
|
-
lazyPromiseSettings: {
|
|
455
|
-
backoffPolicy: this.backoffPolicy,
|
|
456
|
-
retryAttempts: this.retryAttempts,
|
|
457
|
-
retryPolicy: this.retryPolicy,
|
|
458
|
-
timeout: this.timeout,
|
|
459
|
-
},
|
|
460
|
-
stateRecord: this.stateRecord,
|
|
461
|
-
expirationInMs: null,
|
|
462
259
|
});
|
|
463
260
|
}
|
|
464
|
-
/**
|
|
465
|
-
* @example
|
|
466
|
-
* ```ts
|
|
467
|
-
* import type { IGroupableLockProvider } from "@daiso-tech/core/lock/contracts";
|
|
468
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
469
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
470
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
471
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
472
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
473
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
474
|
-
*
|
|
475
|
-
* const eventBus = new EventBus({
|
|
476
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
477
|
-
* });
|
|
478
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
479
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
480
|
-
* serde,
|
|
481
|
-
* adapter: new MemoryLockAdapter({
|
|
482
|
-
* rootGroup: "@global"
|
|
483
|
-
* }),
|
|
484
|
-
* eventBus,
|
|
485
|
-
* });
|
|
486
|
-
*
|
|
487
|
-
* // Will print "@global"
|
|
488
|
-
* console.log(lockProvider.getGroup());
|
|
489
|
-
* ```
|
|
490
|
-
*/
|
|
491
261
|
getGroup() {
|
|
492
|
-
return this.
|
|
262
|
+
return this.keyPrefixer.resolvedGroup;
|
|
493
263
|
}
|
|
494
|
-
/**
|
|
495
|
-
* @example
|
|
496
|
-
* ```ts
|
|
497
|
-
* import type { IGroupableLockProvider, ILockProvider } from "@daiso-tech/core/lock/contracts";
|
|
498
|
-
* import { LockProvider } from "@daiso-tech/core/lock/implementations/derivables";
|
|
499
|
-
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/implementations/adapters";
|
|
500
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
501
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
502
|
-
* import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
|
|
503
|
-
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
|
|
504
|
-
*
|
|
505
|
-
* const eventBus = new EventBus({
|
|
506
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
507
|
-
* });
|
|
508
|
-
* const serde = new Serde(SuperJsonSerdeAdapter);
|
|
509
|
-
* const lockProvider: IGroupableLockProvider = new LockProvider({
|
|
510
|
-
* serde,
|
|
511
|
-
* adapter: new MemoryLockAdapter({
|
|
512
|
-
* rootGroup: "@global"
|
|
513
|
-
* }),
|
|
514
|
-
* eventBus,
|
|
515
|
-
* });
|
|
516
|
-
*
|
|
517
|
-
* // Will print "@global"
|
|
518
|
-
* console.log(lockProvider.getGroup());
|
|
519
|
-
*
|
|
520
|
-
* const groupedLockProvider: ILockProvider = lockProvider.withGroup("company-1");
|
|
521
|
-
*
|
|
522
|
-
* // Will print "@global/company-1"
|
|
523
|
-
* console.log(groupedLockProvider.getGroup());
|
|
524
|
-
* ```
|
|
525
|
-
*/
|
|
526
264
|
withGroup(group) {
|
|
527
265
|
return new LockProvider({
|
|
528
|
-
adapter: this.
|
|
529
|
-
|
|
266
|
+
adapter: this.adapterFactoryable,
|
|
267
|
+
keyPrefixer: this.keyPrefixer.withGroup(group),
|
|
268
|
+
serde: this.serde,
|
|
269
|
+
createOwnerId: this.createOwnerId,
|
|
270
|
+
eventBus: this.groupableEventBus,
|
|
530
271
|
defaultTtl: this.defaultTtl,
|
|
272
|
+
defaultBlockingInterval: this.defaultBlockingInterval,
|
|
273
|
+
defaultBlockingTime: this.defaultBlockingTime,
|
|
531
274
|
defaultRefreshTime: this.defaultRefreshTime,
|
|
532
275
|
retryAttempts: this.retryAttempts,
|
|
533
276
|
backoffPolicy: this.backoffPolicy,
|
|
534
277
|
retryPolicy: this.retryPolicy,
|
|
535
278
|
timeout: this.timeout,
|
|
536
|
-
serde: this.serde,
|
|
537
279
|
});
|
|
538
280
|
}
|
|
539
281
|
}
|