@daiso-tech/core 0.26.1 → 0.28.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 +13 -3
- 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 +143 -71
- package/dist/async/utilities/lazy-promise/lazy-promise.js +223 -142
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/async/utilities/retry/retry-or-fail.d.ts +2 -0
- package/dist/async/utilities/retry/retry-or-fail.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 +144 -96
- 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/{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/no-op-cache-adapter/no-op-cache-adapter.d.ts +14 -13
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +19 -17
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-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 -41
- 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 +269 -507
- package/dist/cache/implementations/derivables/cache/cache.js +538 -822
- 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 +69 -105
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +117 -87
- 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 +5 -21
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +12 -8
- 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 +2 -4
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +2 -8
- 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 +85 -289
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +128 -325
- 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 +103 -86
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +135 -77
- 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 +20 -6
- package/dist/lock/contracts/lock.contract.d.ts +37 -8
- 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/_module-exports.d.ts +1 -0
- package/dist/lock/implementations/adapters/_module-exports.js +1 -0
- package/dist/lock/implementations/adapters/_module-exports.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/no-op-lock-adapter/_module.d.ts +1 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js +2 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js.map +1 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +17 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +24 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -0
- 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 +14 -20
- 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 +181 -369
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +259 -407
- 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 +194 -680
- package/dist/lock/implementations/derivables/lock-provider/lock.js +284 -744
- 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 +106 -143
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +173 -101
- 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 +295 -145
- 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 +3 -2
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +2 -1
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js.map +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 +2 -3
- package/dist/utilities/_module-exports.js +2 -3
- 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/{_constants.d.ts → constants.d.ts} +0 -3
- package/dist/utilities/constants.js +5 -0
- package/dist/utilities/constants.js.map +1 -0
- package/dist/utilities/contracts/_module.d.ts +3 -1
- package/dist/utilities/contracts/_module.js +3 -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/contracts/sqlite-database.contract.d.ts +26 -0
- package/dist/utilities/contracts/sqlite-database.contract.js +5 -0
- package/dist/utilities/contracts/sqlite-database.contract.js.map +1 -0
- package/dist/utilities/functions.d.ts +34 -2
- package/dist/utilities/functions.js +72 -4
- package/dist/utilities/functions.js.map +1 -1
- package/dist/utilities/types.d.ts +49 -16
- 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/utilities/_constants.js +0 -8
- package/dist/utilities/_constants.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,28 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Cache
|
|
3
3
|
*/
|
|
4
|
-
import type { CacheEvents,
|
|
4
|
+
import type { CacheEvents, IDatabaseCacheAdapter } from "../../../../cache/contracts/_module-exports.js";
|
|
5
5
|
import { type ICache, type ICacheAdapter } from "../../../../cache/contracts/_module-exports.js";
|
|
6
6
|
import { type IGroupableCache } from "../../../../cache/contracts/_module-exports.js";
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
9
|
-
import type {
|
|
7
|
+
import { type AsyncLazyable, type Invokable, type OneOrMore } from "../../../../utilities/_module-exports.js";
|
|
8
|
+
import { type NoneFunction, type TimeSpan, type Factoryable } from "../../../../utilities/_module-exports.js";
|
|
9
|
+
import type { LazyPromiseSettingsBase } from "../../../../async/_module-exports.js";
|
|
10
10
|
import { LazyPromise } from "../../../../async/_module-exports.js";
|
|
11
11
|
import type { IGroupableEventBus, Unsubscribe, EventClass, EventInstance } from "../../../../event-bus/contracts/_module-exports.js";
|
|
12
|
+
import type { IKeyPrefixer, Items } from "../../../../utilities/_module-exports.js";
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
14
|
-
* IMPORT_PATH: ```"@daiso-tech/core/cache
|
|
15
|
+
* IMPORT_PATH: ```"@daiso-tech/core/cache"```
|
|
15
16
|
* @group Derivables
|
|
16
17
|
*/
|
|
17
|
-
export type
|
|
18
|
-
|
|
18
|
+
export type CacheSettingsBase = LazyPromiseSettingsBase & {
|
|
19
|
+
keyPrefixer: IKeyPrefixer;
|
|
19
20
|
/**
|
|
20
21
|
* @default
|
|
21
22
|
* ```ts
|
|
23
|
+
* import { EventBus } from "@daiso-tech/core/event-bus";
|
|
24
|
+
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/adapters";
|
|
25
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
26
|
+
*
|
|
22
27
|
* new EventBus({
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* })
|
|
28
|
+
* keyPrefixer: new KeyPrefixer("event-bus"),
|
|
29
|
+
* adapter: new MemoryEventBusAdapter()
|
|
26
30
|
* })
|
|
27
31
|
* ```
|
|
28
32
|
*/
|
|
@@ -32,619 +36,377 @@ export type CacheSettings = {
|
|
|
32
36
|
* @default {null}
|
|
33
37
|
*/
|
|
34
38
|
defaultTtl?: TimeSpan | null;
|
|
35
|
-
/**
|
|
36
|
-
* The default retry attempt to use in the returned <i>LazyPromise</i>.
|
|
37
|
-
* @default {null}
|
|
38
|
-
*/
|
|
39
|
-
retryAttempts?: number | null;
|
|
40
|
-
/**
|
|
41
|
-
* The default backof policy to use in the returned <i>LazyPromise</i>.
|
|
42
|
-
* @default {null}
|
|
43
|
-
*/
|
|
44
|
-
backoffPolicy?: BackoffPolicy | null;
|
|
45
|
-
/**
|
|
46
|
-
* The default retry policy to use in the returned <i>LazyPromise</i>.
|
|
47
|
-
* @default {null}
|
|
48
|
-
*/
|
|
49
|
-
retryPolicy?: RetryPolicy | null;
|
|
50
|
-
/**
|
|
51
|
-
* The default timeout to use in the returned <i>LazyPromise</i>.
|
|
52
|
-
* @default {null}
|
|
53
|
-
*/
|
|
54
|
-
timeout?: TimeSpan | null;
|
|
55
39
|
};
|
|
56
40
|
/**
|
|
57
|
-
* <i>Cache</i> class can be derived from any <i>{@link ICacheAdapter}</i>.
|
|
58
41
|
*
|
|
59
|
-
* IMPORT_PATH: ```"@daiso-tech/core/cache
|
|
42
|
+
* IMPORT_PATH: ```"@daiso-tech/core/cache"```
|
|
43
|
+
* @group Derivables
|
|
44
|
+
*/
|
|
45
|
+
export type CacheAdapterFactoryable<TType> = Factoryable<string, ICacheAdapter<TType> | IDatabaseCacheAdapter<TType>>;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* IMPORT_PATH: ```"@daiso-tech/core/cache"```
|
|
49
|
+
* @group Derivables
|
|
50
|
+
*/
|
|
51
|
+
export type CacheSettings = CacheSettingsBase & {
|
|
52
|
+
adapter: CacheAdapterFactoryable<any>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* IMPORT_PATH: ```"@daiso-tech/core/cache"```
|
|
60
57
|
* @group Derivables
|
|
61
58
|
*/
|
|
62
59
|
export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
|
|
60
|
+
private static resolveCacheAdapter;
|
|
61
|
+
private static resolveCacheAdapterFactoryable;
|
|
63
62
|
private static defaultRetryPolicy;
|
|
64
63
|
private readonly groupdEventBus;
|
|
65
64
|
private readonly eventBus;
|
|
66
|
-
private readonly
|
|
65
|
+
private readonly adapterFactoryable;
|
|
66
|
+
private readonly adapterPromise;
|
|
67
67
|
private readonly defaultTtl;
|
|
68
68
|
private readonly retryAttempts;
|
|
69
69
|
private readonly backoffPolicy;
|
|
70
70
|
private readonly retryPolicy;
|
|
71
|
-
private readonly
|
|
71
|
+
private readonly retryTimeout;
|
|
72
|
+
private readonly totalTimeout;
|
|
73
|
+
private readonly keyPrefixer;
|
|
72
74
|
/**
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
76
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
77
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
78
|
-
*
|
|
79
|
-
* const cache: IGroupableCache = new Cache({
|
|
80
|
-
* adapter: new MemoryCacheAdapter({
|
|
81
|
-
* rootGroup: "@global"
|
|
82
|
-
* }),
|
|
83
|
-
* });
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
constructor(settings: CacheSettings);
|
|
87
|
-
private createLayPromise;
|
|
88
|
-
/**
|
|
89
|
-
* You can listen to different events of <i>Cache</i> class instance.
|
|
90
75
|
*
|
|
91
|
-
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
92
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
93
76
|
* @example
|
|
94
77
|
* ```ts
|
|
95
|
-
* import
|
|
96
|
-
* import
|
|
97
|
-
* import {
|
|
98
|
-
* import
|
|
99
|
-
* import
|
|
100
|
-
* import {
|
|
101
|
-
*
|
|
102
|
-
* const
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
78
|
+
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
79
|
+
* import { Serde } from "@daiso-tech/core/serde";
|
|
80
|
+
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
81
|
+
* import Sqlite from "better-sqlite3";
|
|
82
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
83
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
84
|
+
*
|
|
85
|
+
* const database = new Sqlite("local.db");
|
|
86
|
+
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
87
|
+
* const cacheAdapter = new SqliteCacheAdapter({
|
|
88
|
+
* database,
|
|
89
|
+
* serde,
|
|
106
90
|
* });
|
|
91
|
+
* // You need initialize the adapter once before using it.
|
|
92
|
+
* await cacheAdapter.init();
|
|
107
93
|
*
|
|
108
|
-
* const
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* await cache.add("a", 1);
|
|
94
|
+
* const cache = new Cache({
|
|
95
|
+
* keyPrefixer: new KeyPrefixer("cache"),
|
|
96
|
+
* adapter: cacheAdapter,
|
|
97
|
+
* });
|
|
113
98
|
* ```
|
|
114
|
-
*/
|
|
115
|
-
addListener<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* You can listen to different events of <i>Cache</i> class instance.
|
|
118
99
|
*
|
|
119
|
-
*
|
|
120
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
100
|
+
* You can pass factory function that will create an adapter for every group.
|
|
121
101
|
* @example
|
|
122
102
|
* ```ts
|
|
123
|
-
* import
|
|
124
|
-
* import type {
|
|
125
|
-
* import {
|
|
126
|
-
* import {
|
|
127
|
-
* import
|
|
128
|
-
* import
|
|
129
|
-
* import {
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
103
|
+
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
104
|
+
* import type { ICacheAdapter } from "@daiso-tech/core/cache/contracts";
|
|
105
|
+
* import { Serde } from "@daiso-tech/core/serde";
|
|
106
|
+
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
107
|
+
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
108
|
+
* import Sqlite from "better-sqlite3";
|
|
109
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
110
|
+
* import { KeyPrefixer, type ISqliteDatabase, type FactoryFn } from "@daiso-tech/core/utilities";
|
|
111
|
+
*
|
|
112
|
+
* function cahceAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): FactoryFn<string, ICacheAdapter> {
|
|
113
|
+
* return async (prefix) => {
|
|
114
|
+
* const cacheAdapter = new SqliteCacheAdapter({
|
|
115
|
+
* database,
|
|
116
|
+
* serde,
|
|
117
|
+
* tableName: `cache_${prefix}`
|
|
118
|
+
* });
|
|
119
|
+
* await cacheAdapter.init();
|
|
120
|
+
* return cacheAdapter;
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* const database = new Sqlite("local.db");
|
|
125
|
+
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
126
|
+
* const cache = new Cache({
|
|
127
|
+
* keyPrefixer: new KeyPrefixer("cache"),
|
|
128
|
+
* adapter: cahceAdapterFactory(database, serde),
|
|
135
129
|
* });
|
|
136
|
-
*
|
|
137
|
-
* const listener: Invokable<CacheEvents> = event => {
|
|
138
|
-
* console.log(event);
|
|
139
|
-
* };
|
|
140
|
-
* await cache.addListenerMany([KeyAddedCacheEvent], listener);
|
|
141
|
-
* await cache.add("a", 1);
|
|
142
130
|
* ```
|
|
143
|
-
*/
|
|
144
|
-
addListenerMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
145
|
-
/**
|
|
146
|
-
* You can listen to different events of <i>Cache</i> class instance.
|
|
147
131
|
*
|
|
148
|
-
*
|
|
149
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
132
|
+
* You can also pass factory object that implements <i>{@link IFactoryObject}</i> contract. This useful for depedency injection libraries.
|
|
150
133
|
* @example
|
|
151
134
|
* ```ts
|
|
152
|
-
* import
|
|
153
|
-
* import type {
|
|
154
|
-
* import {
|
|
155
|
-
* import {
|
|
156
|
-
* import
|
|
157
|
-
* import
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* }
|
|
135
|
+
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
136
|
+
* import type { ICacheAdapter } from "@daiso-tech/core/cache/contracts";
|
|
137
|
+
* import { Serde } from "@daiso-tech/core/serde";
|
|
138
|
+
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
139
|
+
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
140
|
+
* import Sqlite from "better-sqlite3";
|
|
141
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
142
|
+
* import { KeyPrefixer, type ISqliteDatabase, type IFactoryObject, type Promiseable } from "@daiso-tech/core/utilities";
|
|
143
|
+
*
|
|
144
|
+
* class CahceAdapterFactory implements IFactoryObject<string, ICacheAdapter> {
|
|
145
|
+
* constructor(private readonly database: ISqliteDatabase, private readonly serde: ISerde<string>) {}
|
|
146
|
+
*
|
|
147
|
+
* async use(prefix: string): Promiseable<ICacheAdapter> {
|
|
148
|
+
* const cacheAdapter = new SqliteCacheAdapter({
|
|
149
|
+
* database: this.database,
|
|
150
|
+
* serde: this.serde,
|
|
151
|
+
* tableName: `cache_${prefix}`
|
|
152
|
+
* });
|
|
153
|
+
* await cacheAdapter.init();
|
|
154
|
+
* return cacheAdapter;
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
*
|
|
158
|
+
* const database = new Sqlite("local.db");
|
|
159
|
+
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
160
|
+
* const cache = new Cache({
|
|
161
|
+
* keyPrefixer: new KeyPrefixer("cache"),
|
|
162
|
+
* adapter: new CahceAdapterFactory(database, serde),
|
|
163
163
|
* });
|
|
164
|
-
*
|
|
165
|
-
* const listener: Invokable<CacheEvents> = event => {
|
|
166
|
-
* console.log(event);
|
|
167
|
-
* };
|
|
168
|
-
* await cache.addListener(KeyAddedCacheEvent, listener);
|
|
169
|
-
* await cache.removeListener(KeyAddedCacheEvent, listener);
|
|
170
|
-
* await cache.add("a", 1);
|
|
171
164
|
* ```
|
|
172
165
|
*/
|
|
173
|
-
|
|
166
|
+
constructor(settings: CacheSettings);
|
|
174
167
|
/**
|
|
175
|
-
* You can listen to
|
|
176
|
-
*
|
|
177
|
-
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
178
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
182
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
183
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
184
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
185
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
186
|
-
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
187
|
-
*
|
|
188
|
-
* const cache: IGroupableCache = new Cache({
|
|
189
|
-
* adapter: new MemoryCacheAdapter({
|
|
190
|
-
* rootGroup: "@global"
|
|
191
|
-
* }),
|
|
192
|
-
* });
|
|
193
|
-
*
|
|
194
|
-
* const listener: Invokable<CacheEvents> = event => {
|
|
195
|
-
* console.log(event);
|
|
196
|
-
* };
|
|
197
|
-
* await cache.addListenerMany([KeyAddedCacheEvent], listener);
|
|
198
|
-
* await cache.removeListenerMany(KeyAddedCacheEvent, listener);
|
|
199
|
-
* await cache.add("a", 1);
|
|
200
|
-
* ```
|
|
168
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
169
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
201
170
|
*/
|
|
202
|
-
|
|
171
|
+
addListener<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
203
172
|
/**
|
|
204
|
-
* You can listen to
|
|
205
|
-
*
|
|
206
|
-
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
207
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
211
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
212
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
213
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
214
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
215
|
-
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
216
|
-
*
|
|
217
|
-
* const cache: IGroupableCache = new Cache({
|
|
218
|
-
* adapter: new MemoryCacheAdapter({
|
|
219
|
-
* rootGroup: "@global"
|
|
220
|
-
* }),
|
|
221
|
-
* });
|
|
222
|
-
*
|
|
223
|
-
* const listener: Invokable<CacheEvents> = event => {
|
|
224
|
-
* console.log(event);
|
|
225
|
-
* };
|
|
226
|
-
* await cache.listenOnce(KeyAddedCacheEvent, listener);
|
|
227
|
-
* await cache.add("a", 1);
|
|
228
|
-
* ```
|
|
173
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
174
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
229
175
|
*/
|
|
230
|
-
|
|
231
|
-
asPromise<TEventClass extends EventClass<CacheEvents>>(event: TEventClass): LazyPromise<EventInstance<TEventClass>>;
|
|
176
|
+
addListenerMany<TEventClassArr extends EventClass<CacheEvents<TType>>[]>(events: [...TEventClassArr], listener: Invokable<EventInstance<Items<TEventClassArr>>>): LazyPromise<void>;
|
|
232
177
|
/**
|
|
233
|
-
* You can listen to
|
|
234
|
-
*
|
|
235
|
-
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
236
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
240
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
241
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
242
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
243
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
244
|
-
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
245
|
-
*
|
|
246
|
-
* const cache: IGroupableCache = new Cache({
|
|
247
|
-
* adapter: new MemoryCacheAdapter({
|
|
248
|
-
* rootGroup: "@global"
|
|
249
|
-
* }),
|
|
250
|
-
* });
|
|
251
|
-
*
|
|
252
|
-
* const listener: Invokable<CacheEvents> = event => {
|
|
253
|
-
* console.log(event);
|
|
254
|
-
* };
|
|
255
|
-
* const unsubscribe = await cache.subscribe(KeyAddedCacheEvent, listener);
|
|
256
|
-
* await cache.add("a", 1);
|
|
257
|
-
* await unsubscribe();
|
|
258
|
-
* ```
|
|
178
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
179
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
259
180
|
*/
|
|
260
|
-
|
|
181
|
+
removeListener<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
261
182
|
/**
|
|
262
|
-
* You can listen to
|
|
263
|
-
*
|
|
264
|
-
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
265
|
-
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
266
|
-
* @example
|
|
267
|
-
* ```ts
|
|
268
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
269
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
270
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
271
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
272
|
-
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
273
|
-
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
274
|
-
*
|
|
275
|
-
* const cache: IGroupableCache = new Cache({
|
|
276
|
-
* adapter: new MemoryCacheAdapter({
|
|
277
|
-
* rootGroup: "@global"
|
|
278
|
-
* }),
|
|
279
|
-
* });
|
|
280
|
-
*
|
|
281
|
-
* const listener: Invokable<CacheEvents> = event => {
|
|
282
|
-
* console.log(event);
|
|
283
|
-
* };
|
|
284
|
-
* const unsubscribe = await cache.subscribeMany([KeyAddedCacheEvent], listener);
|
|
285
|
-
* await cache.add("a", 1);
|
|
286
|
-
* await unsubscribe();
|
|
287
|
-
* ```
|
|
183
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
184
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
288
185
|
*/
|
|
289
|
-
|
|
186
|
+
removeListenerMany<TEventClassArr extends EventClass<CacheEvents<TType>>[]>(events: [...TEventClassArr], listener: Invokable<EventInstance<Items<TEventClassArr>>>): LazyPromise<void>;
|
|
290
187
|
/**
|
|
291
|
-
* @
|
|
292
|
-
*
|
|
293
|
-
* import type { IGroupableCache, ICache } from "@daiso-tech/core/cache/contracts";
|
|
294
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
295
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
296
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
297
|
-
*
|
|
298
|
-
* const cache: IGroupableCache = new Cache({
|
|
299
|
-
* adapter: new MemoryCacheAdapter({
|
|
300
|
-
* rootGroup: "@global"
|
|
301
|
-
* }),
|
|
302
|
-
* });
|
|
303
|
-
*
|
|
304
|
-
* // Will print "@global"
|
|
305
|
-
* console.log(cache.getGroup());
|
|
306
|
-
*
|
|
307
|
-
* const groupedCache: ICache = cache.withGroup("company-1");
|
|
308
|
-
*
|
|
309
|
-
* // Will print "@global/company-1"
|
|
310
|
-
* console.log(groupedCache.getGroup());
|
|
311
|
-
* ```
|
|
188
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
189
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
312
190
|
*/
|
|
313
|
-
|
|
191
|
+
listenOnce<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
314
192
|
/**
|
|
315
|
-
* @
|
|
316
|
-
*
|
|
317
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
318
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
319
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
320
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
321
|
-
*
|
|
322
|
-
* const cache: IGroupableCache = new Cache({
|
|
323
|
-
* adapter: new MemoryCacheAdapter({
|
|
324
|
-
* rootGroup: "@global"
|
|
325
|
-
* }),
|
|
326
|
-
* });
|
|
327
|
-
*
|
|
328
|
-
* // Will print "@global"
|
|
329
|
-
* console.log(cache.getGroup());
|
|
330
|
-
* ```
|
|
193
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
194
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
331
195
|
*/
|
|
332
|
-
|
|
333
|
-
get(key: string): LazyPromise<TType | null>;
|
|
334
|
-
add(key: string, value: TType,
|
|
196
|
+
asPromise<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass): LazyPromise<EventInstance<TEventClass>>;
|
|
335
197
|
/**
|
|
336
|
-
* @
|
|
198
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
199
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
337
200
|
*/
|
|
338
|
-
|
|
339
|
-
update(key: string, value: TType): LazyPromise<boolean>;
|
|
340
|
-
put(key: string, value: TType,
|
|
201
|
+
subscribe<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
|
|
341
202
|
/**
|
|
342
|
-
* @
|
|
203
|
+
* You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
|
|
204
|
+
* To understand how this method works, refer to <i>{@link IEventListenable}</i>.
|
|
343
205
|
*/
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
missingMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
|
|
352
|
-
getMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, TType | null>>;
|
|
206
|
+
subscribeMany<TEventClassArr extends EventClass<CacheEvents<TType>>[]>(events: [...TEventClassArr], listener: Invokable<EventInstance<Items<TEventClassArr>>>): LazyPromise<Unsubscribe>;
|
|
207
|
+
private createLazyPromise;
|
|
208
|
+
exists(key: OneOrMore<string>): LazyPromise<boolean>;
|
|
209
|
+
missing(key: OneOrMore<string>): LazyPromise<boolean>;
|
|
210
|
+
get(key: OneOrMore<string>): LazyPromise<TType | null>;
|
|
211
|
+
getOrFail(key: OneOrMore<string>): LazyPromise<TType>;
|
|
212
|
+
getAndRemove(key: OneOrMore<string>): LazyPromise<TType | null>;
|
|
353
213
|
/**
|
|
354
214
|
* @example
|
|
355
215
|
* ```ts
|
|
356
|
-
* import
|
|
357
|
-
* import
|
|
358
|
-
* import {
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
* rootGroup: "@global"
|
|
364
|
-
* }),
|
|
216
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
217
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
218
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
219
|
+
*
|
|
220
|
+
* const cache = new Cache({
|
|
221
|
+
* adapter: new MemoryCacheAdapter(),
|
|
222
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
365
223
|
* });
|
|
366
224
|
*
|
|
367
|
-
* const
|
|
368
|
-
*
|
|
369
|
-
*
|
|
225
|
+
* const value = await cache.getOr("a", 1);
|
|
226
|
+
*
|
|
227
|
+
* // Will be 1
|
|
228
|
+
* console.log(value);
|
|
370
229
|
* ```
|
|
371
230
|
*
|
|
372
|
-
* You can pass
|
|
231
|
+
* You can also pass in a function
|
|
373
232
|
* @example
|
|
374
233
|
* ```ts
|
|
375
|
-
* import
|
|
376
|
-
* import
|
|
377
|
-
* import {
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
* rootGroup: "@global"
|
|
383
|
-
* }),
|
|
234
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
235
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
236
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
237
|
+
*
|
|
238
|
+
* const cache = new Cache({
|
|
239
|
+
* adapter: new MemoryCacheAdapter(),
|
|
240
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
384
241
|
* });
|
|
385
242
|
*
|
|
386
|
-
* const
|
|
387
|
-
*
|
|
388
|
-
*
|
|
243
|
+
* const value = await cache.getOr("a", () => 1);
|
|
244
|
+
*
|
|
245
|
+
* // Will be 1
|
|
246
|
+
* console.log(value);
|
|
389
247
|
* ```
|
|
390
248
|
*
|
|
391
|
-
* You can pass async function
|
|
249
|
+
* You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
|
|
392
250
|
* @example
|
|
393
251
|
* ```ts
|
|
394
|
-
* import
|
|
395
|
-
* import
|
|
396
|
-
* import {
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
* rootGroup: "@global"
|
|
402
|
-
* }),
|
|
252
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
253
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
254
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
255
|
+
*
|
|
256
|
+
* const cache = new Cache({
|
|
257
|
+
* adapter: new MemoryCacheAdapter(),
|
|
258
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
403
259
|
* });
|
|
404
260
|
*
|
|
405
|
-
* const
|
|
406
|
-
*
|
|
407
|
-
*
|
|
261
|
+
* const value = await cache.getOr("a", async () => 1);
|
|
262
|
+
*
|
|
263
|
+
* // Will be 1
|
|
264
|
+
* console.log(value);
|
|
408
265
|
* ```
|
|
409
266
|
*
|
|
410
|
-
* You can pass <i>{@link LazyPromise}</i
|
|
267
|
+
* You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
|
|
411
268
|
* @example
|
|
412
269
|
* ```ts
|
|
413
|
-
* import
|
|
414
|
-
* import
|
|
415
|
-
* import {
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* rootGroup: "@global"
|
|
421
|
-
* }),
|
|
270
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
271
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
272
|
+
* import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
|
|
273
|
+
*
|
|
274
|
+
* const cache = new Cache({
|
|
275
|
+
* adapter: new MemoryCacheAdapter(),
|
|
276
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
422
277
|
* });
|
|
423
278
|
*
|
|
424
|
-
* const
|
|
425
|
-
*
|
|
426
|
-
*
|
|
279
|
+
* const value = await cache.getOr("a", new LazyPromise(async () => 1));
|
|
280
|
+
*
|
|
281
|
+
* // Will be 1
|
|
282
|
+
* console.log(value);
|
|
427
283
|
* ```
|
|
428
284
|
*/
|
|
429
|
-
getOr(key: string
|
|
285
|
+
getOr(key: OneOrMore<string>, defaultValue: AsyncLazyable<NoneFunction<TType>>): LazyPromise<TType>;
|
|
430
286
|
/**
|
|
431
287
|
* @example
|
|
432
288
|
* ```ts
|
|
433
|
-
* import
|
|
434
|
-
* import
|
|
435
|
-
* import {
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
* rootGroup: "@global"
|
|
441
|
-
* }),
|
|
289
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
290
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
291
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
292
|
+
*
|
|
293
|
+
* const cache = new Cache({
|
|
294
|
+
* adapter: new MemoryCacheAdapter(),
|
|
295
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
442
296
|
* });
|
|
443
297
|
*
|
|
444
|
-
* const
|
|
445
|
-
*
|
|
446
|
-
*
|
|
298
|
+
* const value = await cache.getOrAdd("a", 1);
|
|
299
|
+
*
|
|
300
|
+
* // Will be 1
|
|
301
|
+
* console.log(value);
|
|
447
302
|
* ```
|
|
448
303
|
*
|
|
449
|
-
* You can pass
|
|
304
|
+
* You can also pass in a function
|
|
450
305
|
* @example
|
|
451
306
|
* ```ts
|
|
452
|
-
* import
|
|
453
|
-
* import
|
|
454
|
-
* import {
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
* rootGroup: "@global"
|
|
460
|
-
* }),
|
|
307
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
308
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
309
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
310
|
+
*
|
|
311
|
+
* const cache = new Cache({
|
|
312
|
+
* adapter: new MemoryCacheAdapter(),
|
|
313
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
461
314
|
* });
|
|
462
315
|
*
|
|
463
|
-
* const
|
|
464
|
-
*
|
|
465
|
-
*
|
|
316
|
+
* const value = await cache.getOrAdd("a", () => 1);
|
|
317
|
+
*
|
|
318
|
+
* // Will be 1
|
|
319
|
+
* console.log(value);
|
|
466
320
|
* ```
|
|
467
321
|
*
|
|
468
|
-
* You can pass async function
|
|
322
|
+
* You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
|
|
469
323
|
* @example
|
|
470
324
|
* ```ts
|
|
471
|
-
* import
|
|
472
|
-
* import
|
|
473
|
-
* import {
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
* rootGroup: "@global"
|
|
479
|
-
* }),
|
|
325
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
326
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
327
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
328
|
+
*
|
|
329
|
+
* const cache = new Cache({
|
|
330
|
+
* adapter: new MemoryCacheAdapter(),
|
|
331
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
480
332
|
* });
|
|
481
333
|
*
|
|
482
|
-
* const
|
|
483
|
-
*
|
|
484
|
-
*
|
|
334
|
+
* const value = await cache.getOrAdd("a", async () => 1);
|
|
335
|
+
*
|
|
336
|
+
* // Will be 1
|
|
337
|
+
* console.log(value);
|
|
485
338
|
* ```
|
|
486
339
|
*
|
|
487
|
-
* You can pass <i>{@link LazyPromise}</i
|
|
340
|
+
* You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
|
|
488
341
|
* @example
|
|
489
342
|
* ```ts
|
|
490
|
-
* import
|
|
491
|
-
* import
|
|
492
|
-
* import {
|
|
493
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
494
|
-
*
|
|
495
|
-
* const cache: IGroupableCache = new Cache({
|
|
496
|
-
* adapter: new MemoryCacheAdapter({
|
|
497
|
-
* rootGroup: "@global"
|
|
498
|
-
* }),
|
|
499
|
-
* });
|
|
343
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
344
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
345
|
+
* import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
|
|
500
346
|
*
|
|
501
|
-
* const
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* ```
|
|
505
|
-
*/
|
|
506
|
-
getOrMany<TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TType>>): LazyPromise<Record<TKeys, TType>>;
|
|
507
|
-
/**
|
|
508
|
-
* @example
|
|
509
|
-
* ```ts
|
|
510
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
511
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
512
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
513
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
514
|
-
*
|
|
515
|
-
* const cache: IGroupableCache = new Cache({
|
|
516
|
-
* adapter: new MemoryCacheAdapter({
|
|
517
|
-
* rootGroup: "@global"
|
|
518
|
-
* }),
|
|
347
|
+
* const cache = new Cache({
|
|
348
|
+
* adapter: new MemoryCacheAdapter(),
|
|
349
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
519
350
|
* });
|
|
520
351
|
*
|
|
521
|
-
* await cache.
|
|
522
|
-
*
|
|
523
|
-
* const result1 = await cache.getOrFail("a");
|
|
524
|
-
* // Will print 1
|
|
525
|
-
* console.log(result1);
|
|
352
|
+
* const value = await cache.getOrAdd("a", new LazyPromise(async () => 1));
|
|
526
353
|
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* // Will throw an error
|
|
530
|
-
* await cache.getOrFail("a");
|
|
354
|
+
* // Will be 1
|
|
355
|
+
* console.log(value);
|
|
531
356
|
* ```
|
|
532
357
|
*/
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
358
|
+
getOrAdd(key: OneOrMore<string>, valueToAdd: AsyncLazyable<NoneFunction<TType>>, ttl?: TimeSpan | null): LazyPromise<TType>;
|
|
359
|
+
add(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
|
|
360
|
+
put(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
|
|
361
|
+
update(key: OneOrMore<string>, value: TType): LazyPromise<boolean>;
|
|
362
|
+
increment(key: OneOrMore<string>, value?: Extract<TType, number>): LazyPromise<boolean>;
|
|
363
|
+
decrement(key: OneOrMore<string>, value?: Extract<TType, number>): LazyPromise<boolean>;
|
|
364
|
+
remove(key: OneOrMore<string>): LazyPromise<boolean>;
|
|
365
|
+
removeMany(keys: Iterable<OneOrMore<string>>): LazyPromise<boolean>;
|
|
366
|
+
clear(): LazyPromise<void>;
|
|
538
367
|
/**
|
|
539
368
|
* @example
|
|
540
369
|
* ```ts
|
|
541
|
-
* import
|
|
542
|
-
* import
|
|
543
|
-
* import {
|
|
544
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
545
|
-
*
|
|
546
|
-
* const cache: IGroupableCache = new Cache({
|
|
547
|
-
* adapter: new MemoryCacheAdapter({
|
|
548
|
-
* rootGroup: "@global"
|
|
549
|
-
* }),
|
|
550
|
-
* });
|
|
370
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
371
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
372
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
551
373
|
*
|
|
552
|
-
* const
|
|
553
|
-
*
|
|
554
|
-
*
|
|
374
|
+
* const cache = new Cache({
|
|
375
|
+
* adapter: new MemoryCacheAdapter(),
|
|
376
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
377
|
+
* });
|
|
555
378
|
*
|
|
556
|
-
*
|
|
379
|
+
* // Will log null because the cache is not in a group
|
|
380
|
+
* console.log(cache.getGroup());
|
|
557
381
|
*
|
|
558
|
-
* const
|
|
559
|
-
* // Will print 2
|
|
560
|
-
* console.log(result2);
|
|
382
|
+
* const groupedCache = cache.withGroup("group-a");
|
|
561
383
|
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
* console.log(result3);
|
|
384
|
+
* // Will log "group-a" because the groupedCache is in a group
|
|
385
|
+
* console.log(groupedCache.getGroup());
|
|
565
386
|
* ```
|
|
566
387
|
*/
|
|
567
|
-
|
|
388
|
+
getGroup(): string | null;
|
|
568
389
|
/**
|
|
569
390
|
* @example
|
|
570
391
|
* ```ts
|
|
571
|
-
* import
|
|
572
|
-
* import
|
|
573
|
-
* import {
|
|
574
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
575
|
-
*
|
|
576
|
-
* const cache: IGroupableCache = new Cache({
|
|
577
|
-
* adapter: new MemoryCacheAdapter({
|
|
578
|
-
* rootGroup: "@global"
|
|
579
|
-
* }),
|
|
580
|
-
* });
|
|
581
|
-
*
|
|
582
|
-
* const result = await cache.getOrAdd("a", -1);
|
|
583
|
-
* // -1
|
|
584
|
-
* console.log(result);
|
|
585
|
-
* ```
|
|
392
|
+
* import { Cache } from "@daiso-tech/core/cache";
|
|
393
|
+
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
394
|
+
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
586
395
|
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
591
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
592
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
593
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
594
|
-
*
|
|
595
|
-
* const cache: IGroupableCache = new Cache({
|
|
596
|
-
* adapter: new MemoryCacheAdapter({
|
|
597
|
-
* rootGroup: "@global"
|
|
598
|
-
* }),
|
|
396
|
+
* const cache = new Cache({
|
|
397
|
+
* adapter: new MemoryCacheAdapter(),
|
|
398
|
+
* keyPrefixer: new KeyPrefixer("cache")
|
|
599
399
|
* });
|
|
600
400
|
*
|
|
601
|
-
* const
|
|
602
|
-
*
|
|
603
|
-
* console.log(result);
|
|
604
|
-
* ```
|
|
401
|
+
* const groupedCache = cache.withGroup("group-a");
|
|
402
|
+
* await groupedCache.add("a", 1);
|
|
605
403
|
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* ```ts
|
|
609
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
610
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
611
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
612
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
613
|
-
*
|
|
614
|
-
* const cache: IGroupableCache = new Cache({
|
|
615
|
-
* adapter: new MemoryCacheAdapter({
|
|
616
|
-
* rootGroup: "@global"
|
|
617
|
-
* }),
|
|
618
|
-
* });
|
|
404
|
+
* // Will log "a".
|
|
405
|
+
* console.log(await groupedCache.get("a"));
|
|
619
406
|
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
* console.log(result);
|
|
623
|
-
* ```
|
|
624
|
-
*
|
|
625
|
-
* You can pass <i>{@link LazyPromise}</i> as default value.
|
|
626
|
-
* @example
|
|
627
|
-
* ```ts
|
|
628
|
-
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
629
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
630
|
-
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
631
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
632
|
-
*
|
|
633
|
-
* const cache: IGroupableCache = new Cache({
|
|
634
|
-
* adapter: new MemoryCacheAdapter({
|
|
635
|
-
* rootGroup: "@global"
|
|
636
|
-
* }),
|
|
637
|
-
* });
|
|
638
|
-
*
|
|
639
|
-
* const result = await cache.getOrAdd("a", new LazyPromise(async () => -1));
|
|
640
|
-
* // -1
|
|
641
|
-
* console.log(result);
|
|
407
|
+
* // Will log null because the caches are in different groups.
|
|
408
|
+
* console.log(await cache.get("a"));
|
|
642
409
|
* ```
|
|
643
410
|
*/
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* @default {null}
|
|
647
|
-
*/
|
|
648
|
-
ttl?: TimeSpan): LazyPromise<TType>;
|
|
649
|
-
decrement(key: string, value?: Extract<TType, number>): LazyPromise<boolean>;
|
|
411
|
+
withGroup(group: OneOrMore<string>): ICache<TType>;
|
|
650
412
|
}
|