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