@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.
Files changed (289) hide show
  1. package/README.md +13 -3
  2. package/dist/async/utilities/delay/delay.d.ts +1 -12
  3. package/dist/async/utilities/delay/delay.js +1 -12
  4. package/dist/async/utilities/delay/delay.js.map +1 -1
  5. package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +143 -71
  6. package/dist/async/utilities/lazy-promise/lazy-promise.js +223 -142
  7. package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
  8. package/dist/async/utilities/retry/retry-or-fail.d.ts +2 -0
  9. package/dist/async/utilities/retry/retry-or-fail.js.map +1 -1
  10. package/dist/cache/contracts/_module-exports.d.ts +1 -0
  11. package/dist/cache/contracts/_module-exports.js +1 -0
  12. package/dist/cache/contracts/_module-exports.js.map +1 -1
  13. package/dist/cache/contracts/cache-adapter.contract.d.ts +19 -21
  14. package/dist/cache/contracts/cache-adapter.contract.js +1 -4
  15. package/dist/cache/contracts/cache-adapter.contract.js.map +1 -1
  16. package/dist/cache/contracts/cache-factory.contract.d.ts +1 -1
  17. package/dist/cache/contracts/cache.contract.d.ts +144 -96
  18. package/dist/cache/contracts/cache.contract.js +1 -2
  19. package/dist/cache/contracts/cache.contract.js.map +1 -1
  20. package/dist/cache/contracts/cache.errors.js +2 -5
  21. package/dist/cache/contracts/cache.errors.js.map +1 -1
  22. package/dist/cache/contracts/cache.events.d.ts +10 -10
  23. package/dist/cache/contracts/cache.events.js +2 -5
  24. package/dist/cache/contracts/cache.events.js.map +1 -1
  25. package/dist/cache/contracts/database-cache-adapter.contract.d.ts +89 -0
  26. package/dist/cache/contracts/database-cache-adapter.contract.js +5 -0
  27. package/dist/cache/contracts/database-cache-adapter.contract.js.map +1 -0
  28. package/dist/cache/implementations/adapters/{kysely-sqlite-cache-adapter → kysely-cache-adapter}/_module.d.ts +1 -1
  29. package/dist/cache/implementations/adapters/kysely-cache-adapter/_module.js +2 -0
  30. package/dist/cache/implementations/adapters/kysely-cache-adapter/_module.js.map +1 -0
  31. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +73 -0
  32. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +224 -0
  33. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -0
  34. package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.d.ts +29 -39
  35. package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +45 -54
  36. package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js.map +1 -1
  37. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +17 -33
  38. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +43 -52
  39. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
  40. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.d.ts +13 -0
  41. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.js +38 -0
  42. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.js.map +1 -0
  43. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +27 -33
  44. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +145 -197
  45. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
  46. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +14 -13
  47. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +19 -17
  48. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -1
  49. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.d.ts +13 -0
  50. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.js +39 -0
  51. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.js.map +1 -0
  52. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +16 -22
  53. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +51 -132
  54. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
  55. package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.d.ts +13 -0
  56. package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js +69 -0
  57. package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js.map +1 -0
  58. package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +29 -41
  59. package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +46 -55
  60. package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js.map +1 -1
  61. package/dist/cache/implementations/derivables/_module-exports.d.ts +1 -1
  62. package/dist/cache/implementations/derivables/_module-exports.js +1 -1
  63. package/dist/cache/implementations/derivables/_module-exports.js.map +1 -1
  64. package/dist/cache/implementations/derivables/cache/_module.d.ts +1 -0
  65. package/dist/cache/implementations/derivables/cache/_module.js +1 -0
  66. package/dist/cache/implementations/derivables/cache/_module.js.map +1 -1
  67. package/dist/cache/implementations/derivables/cache/cache.d.ts +269 -507
  68. package/dist/cache/implementations/derivables/cache/cache.js +538 -822
  69. package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
  70. package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +21 -0
  71. package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +110 -0
  72. package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -0
  73. package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.d.ts +9 -0
  74. package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js +20 -0
  75. package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js.map +1 -0
  76. package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +69 -105
  77. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +117 -87
  78. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
  79. package/dist/cache/implementations/test-utilities/_module-exports.d.ts +1 -0
  80. package/dist/cache/implementations/test-utilities/_module-exports.js +1 -0
  81. package/dist/cache/implementations/test-utilities/_module-exports.js.map +1 -1
  82. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +9 -11
  83. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +246 -247
  84. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
  85. package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +16 -30
  86. package/dist/cache/implementations/test-utilities/cache.test-suite.js +271 -996
  87. package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
  88. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.d.ts +60 -0
  89. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +698 -0
  90. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -0
  91. package/dist/collection/contracts/async-collection.contract.d.ts +2 -3
  92. package/dist/collection/contracts/async-collection.contract.js +1 -12
  93. package/dist/collection/contracts/async-collection.contract.js.map +1 -1
  94. package/dist/collection/contracts/collection.contract.d.ts +1 -1
  95. package/dist/collection/contracts/collection.errors.d.ts +1 -1
  96. package/dist/collection/contracts/collection.errors.js +3 -6
  97. package/dist/collection/contracts/collection.errors.js.map +1 -1
  98. package/dist/collection/implementations/_shared.d.ts +4 -4
  99. package/dist/collection/implementations/_shared.js +6 -9
  100. package/dist/collection/implementations/_shared.js.map +1 -1
  101. package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js +2 -2
  102. package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js.map +1 -1
  103. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +5 -21
  104. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +12 -8
  105. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
  106. package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +1 -1
  107. package/dist/collection/implementations/iterable-collection/iterable-collection.js +1 -1
  108. package/dist/collection/implementations/list-collection/list-collection.d.ts +1 -1
  109. package/dist/collection/implementations/list-collection/list-collection.js +1 -1
  110. package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +0 -9
  111. package/dist/event-bus/contracts/event-bus.contract.d.ts +5 -5
  112. package/dist/event-bus/contracts/event-bus.contract.js.map +1 -1
  113. package/dist/event-bus/contracts/event-bus.errors.js +2 -5
  114. package/dist/event-bus/contracts/event-bus.errors.js.map +1 -1
  115. package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +9 -29
  116. package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +14 -35
  117. package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js.map +1 -1
  118. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +2 -4
  119. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +2 -8
  120. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js.map +1 -1
  121. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +8 -15
  122. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +15 -34
  123. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
  124. package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +85 -289
  125. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +128 -325
  126. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
  127. package/dist/event-bus/implementations/derivables/event-bus/listener-store.d.ts +13 -0
  128. package/dist/event-bus/implementations/derivables/event-bus/listener-store.js +42 -0
  129. package/dist/event-bus/implementations/derivables/event-bus/listener-store.js.map +1 -0
  130. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +103 -86
  131. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +135 -77
  132. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
  133. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +2 -48
  134. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +31 -122
  135. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
  136. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.d.ts +2 -50
  137. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +41 -89
  138. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
  139. package/dist/lock/contracts/database-lock-adapter.contract.d.ts +0 -9
  140. package/dist/lock/contracts/lock-adapter.contract.d.ts +0 -9
  141. package/dist/lock/contracts/lock-provider.contract.d.ts +20 -6
  142. package/dist/lock/contracts/lock.contract.d.ts +37 -8
  143. package/dist/lock/contracts/lock.errors.js +2 -5
  144. package/dist/lock/contracts/lock.errors.js.map +1 -1
  145. package/dist/lock/contracts/lock.events.js +2 -5
  146. package/dist/lock/contracts/lock.events.js.map +1 -1
  147. package/dist/lock/implementations/adapters/_module-exports.d.ts +1 -0
  148. package/dist/lock/implementations/adapters/_module-exports.js +1 -0
  149. package/dist/lock/implementations/adapters/_module-exports.js.map +1 -1
  150. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +0 -5
  151. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +2 -21
  152. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
  153. package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +11 -16
  154. package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +11 -20
  155. package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js.map +1 -1
  156. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +7 -26
  157. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +7 -35
  158. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
  159. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +13 -20
  160. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +13 -37
  161. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
  162. package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.d.ts +1 -0
  163. package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js +2 -0
  164. package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js.map +1 -0
  165. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +17 -0
  166. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +24 -0
  167. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -0
  168. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +4 -22
  169. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +4 -31
  170. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
  171. package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +14 -20
  172. package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +12 -21
  173. package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
  174. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +0 -2
  175. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +2 -8
  176. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
  177. package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js +1 -5
  178. package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +1 -1
  179. package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +181 -369
  180. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +259 -407
  181. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
  182. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +15 -17
  183. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +42 -40
  184. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
  185. package/dist/lock/implementations/derivables/lock-provider/lock-state.d.ts +3 -3
  186. package/dist/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -1
  187. package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +194 -680
  188. package/dist/lock/implementations/derivables/lock-provider/lock.js +284 -744
  189. package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
  190. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +106 -143
  191. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +173 -101
  192. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
  193. package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +4 -5
  194. package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +172 -247
  195. package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
  196. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +5 -8
  197. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +93 -98
  198. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
  199. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +15 -20
  200. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +295 -145
  201. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
  202. package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js +1 -2
  203. package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js.map +1 -1
  204. package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +3 -2
  205. package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +2 -1
  206. package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js.map +1 -1
  207. package/dist/serde/implementations/adapters/redis-serde/redis-serde.js +1 -2
  208. package/dist/serde/implementations/adapters/redis-serde/redis-serde.js.map +1 -1
  209. package/dist/serde/implementations/adapters/sql-serde/sql-serde.js +1 -2
  210. package/dist/serde/implementations/adapters/sql-serde/sql-serde.js.map +1 -1
  211. package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.d.ts +2 -2
  212. package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +2 -2
  213. package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js.map +1 -1
  214. package/dist/serde/implementations/derivables/serde.d.ts +14 -14
  215. package/dist/serde/implementations/derivables/serde.js +14 -15
  216. package/dist/serde/implementations/derivables/serde.js.map +1 -1
  217. package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.d.ts +4 -4
  218. package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +3 -3
  219. package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +5 -5
  220. package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +4 -4
  221. package/dist/utilities/_module-exports.d.ts +2 -3
  222. package/dist/utilities/_module-exports.js +2 -3
  223. package/dist/utilities/_module-exports.js.map +1 -1
  224. package/dist/utilities/classes/_module.d.ts +4 -0
  225. package/dist/utilities/classes/_module.js +5 -0
  226. package/dist/utilities/classes/_module.js.map +1 -0
  227. package/dist/utilities/classes/key-prefixer/_module.d.ts +2 -0
  228. package/dist/utilities/classes/key-prefixer/_module.js +3 -0
  229. package/dist/utilities/classes/key-prefixer/_module.js.map +1 -0
  230. package/dist/utilities/classes/key-prefixer/key-prefixer.contract.d.ts +28 -0
  231. package/dist/utilities/classes/key-prefixer/key-prefixer.contract.js +5 -0
  232. package/dist/utilities/classes/key-prefixer/key-prefixer.contract.js.map +1 -0
  233. package/dist/utilities/classes/key-prefixer/key-prefixer.d.ts +73 -0
  234. package/dist/utilities/classes/key-prefixer/key-prefixer.js +135 -0
  235. package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -0
  236. package/dist/utilities/classes/kysely-table-name-transformer-plugin/_module.d.ts +1 -0
  237. package/dist/utilities/classes/kysely-table-name-transformer-plugin/_module.js +2 -0
  238. package/dist/utilities/classes/kysely-table-name-transformer-plugin/_module.js.map +1 -0
  239. package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js.map +1 -0
  240. package/dist/utilities/classes/pipeline/_module.d.ts +1 -0
  241. package/dist/utilities/classes/pipeline/_module.js +2 -0
  242. package/dist/utilities/classes/pipeline/_module.js.map +1 -0
  243. package/dist/utilities/{pipeline → classes/pipeline}/pipeline.d.ts +3 -2
  244. package/dist/utilities/{pipeline → classes/pipeline}/pipeline.js +3 -2
  245. package/dist/utilities/classes/pipeline/pipeline.js.map +1 -0
  246. package/dist/utilities/classes/time-span/_module.d.ts +1 -0
  247. package/dist/utilities/classes/time-span/_module.js +2 -0
  248. package/dist/utilities/classes/time-span/_module.js.map +1 -0
  249. package/dist/utilities/{time-span → classes/time-span}/time-span.d.ts +2 -1
  250. package/dist/utilities/{time-span → classes/time-span}/time-span.js +1 -0
  251. package/dist/utilities/classes/time-span/time-span.js.map +1 -0
  252. package/dist/utilities/{_constants.d.ts → constants.d.ts} +0 -3
  253. package/dist/utilities/constants.js +5 -0
  254. package/dist/utilities/constants.js.map +1 -0
  255. package/dist/utilities/contracts/_module.d.ts +3 -1
  256. package/dist/utilities/contracts/_module.js +3 -1
  257. package/dist/utilities/contracts/_module.js.map +1 -1
  258. package/dist/utilities/contracts/prunable.contract.d.ts +11 -0
  259. package/dist/utilities/contracts/prunable.contract.js +5 -0
  260. package/dist/utilities/contracts/prunable.contract.js.map +1 -0
  261. package/dist/utilities/contracts/sqlite-database.contract.d.ts +26 -0
  262. package/dist/utilities/contracts/sqlite-database.contract.js +5 -0
  263. package/dist/utilities/contracts/sqlite-database.contract.js.map +1 -0
  264. package/dist/utilities/functions.d.ts +34 -2
  265. package/dist/utilities/functions.js +72 -4
  266. package/dist/utilities/functions.js.map +1 -1
  267. package/dist/utilities/types.d.ts +49 -16
  268. package/package.json +14 -13
  269. package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/_module.js +0 -2
  270. package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/_module.js.map +0 -1
  271. package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.d.ts +0 -61
  272. package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js +0 -318
  273. package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js.map +0 -1
  274. package/dist/utilities/_constants.js +0 -8
  275. package/dist/utilities/_constants.js.map +0 -1
  276. package/dist/utilities/kysely/_module.d.ts +0 -1
  277. package/dist/utilities/kysely/_module.js +0 -2
  278. package/dist/utilities/kysely/_module.js.map +0 -1
  279. package/dist/utilities/kysely/kysely-table-name-transformer-plugin.js.map +0 -1
  280. package/dist/utilities/pipeline/_module.d.ts +0 -1
  281. package/dist/utilities/pipeline/_module.js +0 -2
  282. package/dist/utilities/pipeline/_module.js.map +0 -1
  283. package/dist/utilities/pipeline/pipeline.js.map +0 -1
  284. package/dist/utilities/time-span/_module.d.ts +0 -1
  285. package/dist/utilities/time-span/_module.js +0 -2
  286. package/dist/utilities/time-span/_module.js.map +0 -1
  287. package/dist/utilities/time-span/time-span.js.map +0 -1
  288. /package/dist/utilities/{kysely → classes/kysely-table-name-transformer-plugin}/kysely-table-name-transformer-plugin.d.ts +0 -0
  289. /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, WithTtlValue } from "../../../../cache/contracts/_module-exports.js";
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 { AsyncLazyable, GetOrAddValue, Invokable, OneOrMore } from "../../../../utilities/_module-exports.js";
8
- import type { TimeSpan } from "../../../../utilities/_module-exports.js";
9
- import type { BackoffPolicy, RetryPolicy } from "../../../../async/_module-exports.js";
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/implementations/derivables"```
15
+ * IMPORT_PATH: ```"@daiso-tech/core/cache"```
15
16
  * @group Derivables
16
17
  */
17
- export type CacheSettings = {
18
- adapter: ICacheAdapter<any>;
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
- * adapter: new MemoryEventBusAdapter({
24
- * rootGroup: "@global"
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/implementations/derivables"```
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 adapter;
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 timeout;
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
96
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
97
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
98
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
99
- * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
100
- * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
101
- *
102
- * const cache: IGroupableCache = new Cache({
103
- * adapter: new MemoryCacheAdapter({
104
- * rootGroup: "@global"
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 listener: Invokable<CacheEvents> = event => {
109
- * console.log(event);
110
- * };
111
- * await cache.addListener(KeyAddedCacheEvent, listener);
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
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
124
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
125
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
126
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
127
- * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
128
- * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
129
- * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
130
- *
131
- * const cache: IGroupableCache = new Cache({
132
- * adapter: new MemoryCacheAdapter({
133
- * rootGroup: "@global"
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
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
153
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
154
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
155
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
156
- * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
157
- * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
158
- *
159
- * const cache: IGroupableCache = new Cache({
160
- * adapter: new MemoryCacheAdapter({
161
- * rootGroup: "@global"
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
- removeListener<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
166
+ constructor(settings: CacheSettings);
174
167
  /**
175
- * You can listen to different events of <i>Cache</i> class instance.
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
- removeListenerMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
171
+ addListener<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
203
172
  /**
204
- * You can listen to different events of <i>Cache</i> class instance.
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
- listenOnce<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
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 different events of <i>Cache</i> class instance.
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
- subscribe<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
181
+ removeListener<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
261
182
  /**
262
- * You can listen to different events of <i>Cache</i> class instance.
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
- subscribeMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
186
+ removeListenerMany<TEventClassArr extends EventClass<CacheEvents<TType>>[]>(events: [...TEventClassArr], listener: Invokable<EventInstance<Items<TEventClassArr>>>): LazyPromise<void>;
290
187
  /**
291
- * @example
292
- * ```ts
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
- withGroup(group: OneOrMore<string>): ICache<TType>;
191
+ listenOnce<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
314
192
  /**
315
- * @example
316
- * ```ts
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
- getGroup(): string;
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
- * @default null
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
- ttl?: TimeSpan | null): LazyPromise<boolean>;
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
- * @default null
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
- ttl?: TimeSpan | null): LazyPromise<boolean>;
345
- remove(key: string): LazyPromise<boolean>;
346
- increment(key: string, value?: Extract<TType, number>): LazyPromise<boolean>;
347
- clear(): LazyPromise<void>;
348
- exists(key: string): LazyPromise<boolean>;
349
- existsMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
350
- missing(key: string): LazyPromise<boolean>;
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
357
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
358
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
359
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
360
- *
361
- * const cache: IGroupableCache = new Cache({
362
- * adapter: new MemoryCacheAdapter({
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 result = await cache.getOr("a", -1);
368
- * // -1
369
- * console.log(result);
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 function as default value.
231
+ * You can also pass in a function
373
232
  * @example
374
233
  * ```ts
375
- * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
376
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
377
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
378
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
379
- *
380
- * const cache: IGroupableCache = new Cache({
381
- * adapter: new MemoryCacheAdapter({
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 result = await cache.getOr("a", () => -1);
387
- * // -1
388
- * console.log(result);
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 as default value.
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
395
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
396
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
397
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
398
- *
399
- * const cache: IGroupableCache = new Cache({
400
- * adapter: new MemoryCacheAdapter({
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 result = await cache.getOr("a", async () => -1);
406
- * // -1
407
- * console.log(result);
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> as default value.
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
414
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
415
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
416
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
417
- *
418
- * const cache: IGroupableCache = new Cache({
419
- * adapter: new MemoryCacheAdapter({
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 result = await cache.getOr("a", new LazyPromise(async () => -1));
425
- * // -1
426
- * console.log(result);
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, defaultValue: AsyncLazyable<TType>): LazyPromise<TType>;
285
+ getOr(key: OneOrMore<string>, defaultValue: AsyncLazyable<NoneFunction<TType>>): LazyPromise<TType>;
430
286
  /**
431
287
  * @example
432
288
  * ```ts
433
- * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
434
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
435
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
436
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
437
- *
438
- * const cache: IGroupableCache = new Cache({
439
- * adapter: new MemoryCacheAdapter({
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 result = await cache.getOrMany({ a: -1 });
445
- * // { a: -1 }
446
- * console.log(result);
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 function as default value.
304
+ * You can also pass in a function
450
305
  * @example
451
306
  * ```ts
452
- * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
453
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
454
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
455
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
456
- *
457
- * const cache: IGroupableCache = new Cache({
458
- * adapter: new MemoryCacheAdapter({
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 result = await cache.getOrMany({ a: () => -1 });
464
- * // { a: -1 }
465
- * console.log(result);
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 as default value.
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
472
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
473
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
474
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
475
- *
476
- * const cache: IGroupableCache = new Cache({
477
- * adapter: new MemoryCacheAdapter({
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 result = await cache.getOrMany({ a: async () => -1 });
483
- * // { a: -1 }
484
- * console.log(result);
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> as default value.
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
491
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
492
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
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 result = await cache.getOrMany({ a: new LazyPromise(async () => - 1) });
502
- * // { a: -1 }
503
- * console.log(result);
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.add("a", 1);
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
- * await cache.remove("a");
528
- *
529
- * // Will throw an error
530
- * await cache.getOrFail("a");
354
+ * // Will be 1
355
+ * console.log(value);
531
356
  * ```
532
357
  */
533
- getOrFail(key: string): LazyPromise<TType>;
534
- addMany<TKeys extends string>(values: Record<TKeys, WithTtlValue<TType>>): LazyPromise<Record<TKeys, boolean>>;
535
- updateMany<TKeys extends string>(values: Record<TKeys, TType>): LazyPromise<Record<TKeys, boolean>>;
536
- putMany<TKeys extends string>(values: Record<TKeys, WithTtlValue<TType>>): LazyPromise<Record<TKeys, boolean>>;
537
- removeMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
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 type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
542
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
543
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
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 result1 = await cache.getAndRemove("a");
553
- * // Will print null
554
- * console.log(result1);
374
+ * const cache = new Cache({
375
+ * adapter: new MemoryCacheAdapter(),
376
+ * keyPrefixer: new KeyPrefixer("cache")
377
+ * });
555
378
  *
556
- * await cache.add("a", 2)
379
+ * // Will log null because the cache is not in a group
380
+ * console.log(cache.getGroup());
557
381
  *
558
- * const result2 = await cache.getAndRemove("a");
559
- * // Will print 2
560
- * console.log(result2);
382
+ * const groupedCache = cache.withGroup("group-a");
561
383
  *
562
- * const result3 = await cache.get("a");
563
- * // Will print null
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
- getAndRemove(key: string): LazyPromise<TType | null>;
388
+ getGroup(): string | null;
568
389
  /**
569
390
  * @example
570
391
  * ```ts
571
- * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
572
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
573
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
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
- * You can pass function as default value.
588
- * @example
589
- * ```ts
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 result = await cache.getOrAdd("a", () => -1);
602
- * // -1
603
- * console.log(result);
604
- * ```
401
+ * const groupedCache = cache.withGroup("group-a");
402
+ * await groupedCache.add("a", 1);
605
403
  *
606
- * You can pass async function as default value.
607
- * @example
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
- * const result = await cache.getOrAdd("a", async () => -1);
621
- * // -1
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
- getOrAdd(key: string, valueToAdd: AsyncLazyable<GetOrAddValue<TType>>,
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
  }