@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
@@ -0,0 +1,698 @@
1
+ /**
2
+ * @module Cache
3
+ */
4
+ import {} from "vitest";
5
+ import {} from "../../../cache/contracts/_module-exports.js";
6
+ import { TimeSpan } from "../../../utilities/_module-exports.js";
7
+ /**
8
+ * The <i>databaseCacheAdapterTestSuite</i> function simplifies the process of testing your custom implementation of <i>{@link IDatabaseCacheAdapter}</i> with <i>vitest</i>.
9
+ *
10
+ * IMPORT_PATH: ```"@daiso-tech/core/cache/test-utilities"```
11
+ * @group Test utilities
12
+ * @example
13
+ * ```ts
14
+ * import { afterEach, beforeEach, describe, expect, test } from "vitest";
15
+ * import Sqlite, { type Database } from "better-sqlite3";
16
+ * import { databaseCacheAdapterTestSuite } from "@daiso-tech/core/cache/test-utilities";
17
+ * import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
18
+ * import { Serde } from "@daiso-tech/core/serde";
19
+ * import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
20
+ *
21
+ * describe("class: SqliteCacheAdapter", () => {
22
+ * let database: Database;
23
+ * beforeEach(() => {
24
+ * database = new Sqlite(":memory:");
25
+ * });
26
+ * afterEach(() => {
27
+ * database.close();
28
+ * });
29
+ * databaseCacheAdapterTestSuite({
30
+ * createAdapter: async () => {
31
+ * const adapter = new SqliteCacheAdapter({
32
+ * database: database,
33
+ * tableName: "custom_table",
34
+ * shouldRemoveExpiredKeys: false,
35
+ * serde: new Serde(new SuperJsonSerdeAdapter()),
36
+ * });
37
+ * await adapter.init();
38
+ * return adapter;
39
+ * },
40
+ * test,
41
+ * beforeEach,
42
+ * expect,
43
+ * describe,
44
+ * });
45
+ * });
46
+ * ```
47
+ */
48
+ export function databaseCacheAdapterTestSuite(settings) {
49
+ const { expect, test, createAdapter, describe, beforeEach } = settings;
50
+ let adapter;
51
+ beforeEach(async () => {
52
+ adapter = await createAdapter();
53
+ });
54
+ describe("method: find", () => {
55
+ test("Should return null when key doesnt exists", async () => {
56
+ const findData = await adapter.find("a");
57
+ expect(findData).toBeNull();
58
+ });
59
+ test("Should return the value when key exists", async () => {
60
+ const insertData = {
61
+ key: "a",
62
+ value: 1,
63
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
64
+ };
65
+ await adapter.insert(insertData);
66
+ const findData = await adapter.find(insertData.key);
67
+ const result = {
68
+ expiration: insertData.expiration,
69
+ value: insertData.value,
70
+ };
71
+ expect(findData).toStrictEqual(result);
72
+ });
73
+ });
74
+ describe("method: insert", () => {
75
+ test("Should throw an error when key exists", async () => {
76
+ const insertData = {
77
+ key: "a",
78
+ value: 1,
79
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
80
+ };
81
+ await adapter.insert(insertData);
82
+ const promise = adapter.insert(insertData);
83
+ await expect(promise).rejects.toBeDefined();
84
+ });
85
+ });
86
+ describe("method: upsert", () => {
87
+ test("Should return null when key doesnt exist", async () => {
88
+ const upsertData = {
89
+ key: "a",
90
+ value: 1,
91
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
92
+ };
93
+ const prevData = await adapter.upsert(upsertData);
94
+ expect(prevData).toBeNull();
95
+ });
96
+ test("Should return previous key expiration when key exist", async () => {
97
+ const upsertData1 = {
98
+ key: "a",
99
+ value: 1,
100
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
101
+ };
102
+ await adapter.upsert(upsertData1);
103
+ const upsertData2 = {
104
+ key: "a",
105
+ value: 2,
106
+ expiration: TimeSpan.fromMilliseconds(50).toEndDate(),
107
+ };
108
+ const prevData = await adapter.upsert(upsertData2);
109
+ const result = {
110
+ expiration: upsertData1.expiration,
111
+ };
112
+ expect({ expiration: prevData?.expiration }).toStrictEqual(result);
113
+ });
114
+ test("Should persist insertion when key doesnt exist", async () => {
115
+ const upsertData = {
116
+ key: "a",
117
+ value: 1,
118
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
119
+ };
120
+ await adapter.upsert(upsertData);
121
+ const findData = await adapter.find(upsertData.key);
122
+ const result = {
123
+ value: upsertData.value,
124
+ expiration: upsertData.expiration,
125
+ };
126
+ expect(findData).toStrictEqual(result);
127
+ });
128
+ test("Should persist update when key exist", async () => {
129
+ const upsertData1 = {
130
+ key: "a",
131
+ value: 1,
132
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
133
+ };
134
+ await adapter.upsert(upsertData1);
135
+ const upsertData2 = {
136
+ key: "a",
137
+ value: 2,
138
+ expiration: TimeSpan.fromMilliseconds(50).toEndDate(),
139
+ };
140
+ await adapter.upsert(upsertData2);
141
+ const findData = await adapter.find(upsertData2.key);
142
+ const result = {
143
+ value: upsertData2.value,
144
+ expiration: upsertData2.expiration,
145
+ };
146
+ expect(findData).toStrictEqual(result);
147
+ });
148
+ });
149
+ describe("method: updateExpired", () => {
150
+ test("Should not persist update when key has no expiration", async () => {
151
+ const insertData = {
152
+ key: "a",
153
+ value: 1,
154
+ expiration: null,
155
+ };
156
+ await adapter.insert(insertData);
157
+ const updateData = {
158
+ key: "a",
159
+ value: 2,
160
+ expiration: null,
161
+ };
162
+ await adapter.updateExpired(updateData);
163
+ const findData = await adapter.find(updateData.key);
164
+ const result = {
165
+ value: insertData.value,
166
+ expiration: insertData.expiration,
167
+ };
168
+ expect(findData).toStrictEqual(result);
169
+ });
170
+ test("Should return 0 when key has no expiration", async () => {
171
+ const insertData = {
172
+ key: "a",
173
+ value: 1,
174
+ expiration: null,
175
+ };
176
+ await adapter.insert(insertData);
177
+ const updateData = {
178
+ key: "a",
179
+ value: 2,
180
+ expiration: null,
181
+ };
182
+ const result = await adapter.updateExpired(updateData);
183
+ expect(result).toBe(0);
184
+ });
185
+ test("Should not persist update when key has expiration but not expired", async () => {
186
+ const insertData = {
187
+ key: "a",
188
+ value: 1,
189
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
190
+ };
191
+ await adapter.insert(insertData);
192
+ const updateData = {
193
+ key: "a",
194
+ value: 2,
195
+ expiration: null,
196
+ };
197
+ await adapter.updateExpired(updateData);
198
+ const findData = await adapter.find(updateData.key);
199
+ const result = {
200
+ value: insertData.value,
201
+ expiration: insertData.expiration,
202
+ };
203
+ expect(findData).toStrictEqual(result);
204
+ });
205
+ test("Should return 0 update when key has expiration but not expired", async () => {
206
+ const insertData = {
207
+ key: "a",
208
+ value: 1,
209
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
210
+ };
211
+ await adapter.insert(insertData);
212
+ const updateData = {
213
+ key: "a",
214
+ value: 2,
215
+ expiration: null,
216
+ };
217
+ const result = await adapter.updateExpired(updateData);
218
+ expect(result).toBe(0);
219
+ });
220
+ test("Should persist update when key has expiration and expired", async () => {
221
+ const insertData = {
222
+ key: "a",
223
+ value: 1,
224
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
225
+ };
226
+ await adapter.insert(insertData);
227
+ const updateData = {
228
+ key: "a",
229
+ value: 2,
230
+ expiration: null,
231
+ };
232
+ await adapter.updateExpired(updateData);
233
+ const findData = await adapter.find(updateData.key);
234
+ const result = {
235
+ value: updateData.value,
236
+ expiration: updateData.expiration,
237
+ };
238
+ expect(findData).toStrictEqual(result);
239
+ });
240
+ test("Should return 1 update when key has expiration and expired", async () => {
241
+ const insertData = {
242
+ key: "a",
243
+ value: 1,
244
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
245
+ };
246
+ await adapter.insert(insertData);
247
+ const updateData = {
248
+ key: "a",
249
+ value: 2,
250
+ expiration: null,
251
+ };
252
+ const result = await adapter.updateExpired(updateData);
253
+ expect(result).toBe(1);
254
+ });
255
+ });
256
+ describe("method: updateUnexpired", () => {
257
+ test("Should persist update when key has no expiration", async () => {
258
+ const insertData = {
259
+ key: "a",
260
+ value: 1,
261
+ expiration: null,
262
+ };
263
+ await adapter.insert(insertData);
264
+ const updateData = {
265
+ key: "a",
266
+ value: 2,
267
+ };
268
+ await adapter.updateUnexpired(updateData);
269
+ const findData = await adapter.find(updateData.key);
270
+ const result = {
271
+ value: updateData.value,
272
+ expiration: insertData.expiration,
273
+ };
274
+ expect(findData).toStrictEqual(result);
275
+ });
276
+ test("Should return 1 when key has no expiration", async () => {
277
+ const insertData = {
278
+ key: "a",
279
+ value: 1,
280
+ expiration: null,
281
+ };
282
+ await adapter.insert(insertData);
283
+ const updateData = {
284
+ key: "a",
285
+ value: 2,
286
+ };
287
+ const result = await adapter.updateUnexpired(updateData);
288
+ expect(result).toBe(1);
289
+ });
290
+ test("Should persist update when key has expiration but not expired", async () => {
291
+ const insertData = {
292
+ key: "a",
293
+ value: 1,
294
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
295
+ };
296
+ await adapter.insert(insertData);
297
+ const updateData = {
298
+ key: "a",
299
+ value: 2,
300
+ };
301
+ await adapter.updateUnexpired(updateData);
302
+ const findData = await adapter.find(updateData.key);
303
+ const result = {
304
+ value: updateData.value,
305
+ expiration: insertData.expiration,
306
+ };
307
+ expect(findData).toStrictEqual(result);
308
+ });
309
+ test("Should return 1 update when key has expiration but not expired", async () => {
310
+ const insertData = {
311
+ key: "a",
312
+ value: 1,
313
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
314
+ };
315
+ await adapter.insert(insertData);
316
+ const updateData = {
317
+ key: "a",
318
+ value: 2,
319
+ };
320
+ const result = await adapter.updateUnexpired(updateData);
321
+ expect(result).toBe(1);
322
+ });
323
+ test("Should not persist update when key has expiration and expired", async () => {
324
+ const insertData = {
325
+ key: "a",
326
+ value: 1,
327
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
328
+ };
329
+ await adapter.insert(insertData);
330
+ const updateData = {
331
+ key: "a",
332
+ value: 2,
333
+ };
334
+ await adapter.updateUnexpired(updateData);
335
+ const findData = await adapter.find(updateData.key);
336
+ const result = {
337
+ value: insertData.value,
338
+ expiration: insertData.expiration,
339
+ };
340
+ expect(findData).toStrictEqual(result);
341
+ });
342
+ test("Should return 0 update when key has expiration and expired", async () => {
343
+ const insertData = {
344
+ key: "a",
345
+ value: 1,
346
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
347
+ };
348
+ await adapter.insert(insertData);
349
+ const updateData = {
350
+ key: "a",
351
+ value: 2,
352
+ };
353
+ const result = await adapter.updateUnexpired(updateData);
354
+ expect(result).toBe(0);
355
+ });
356
+ });
357
+ describe("method: incrementUnexpired", () => {
358
+ test("Should persist update when key has no expiration", async () => {
359
+ const insertData = {
360
+ key: "a",
361
+ value: 1,
362
+ expiration: null,
363
+ };
364
+ await adapter.insert(insertData);
365
+ const updateData = {
366
+ key: "a",
367
+ value: 2,
368
+ };
369
+ await adapter.incrementUnexpired(updateData);
370
+ const findData = await adapter.find(updateData.key);
371
+ const result = {
372
+ value: insertData.value + updateData.value,
373
+ expiration: insertData.expiration,
374
+ };
375
+ expect(findData).toStrictEqual(result);
376
+ });
377
+ test("Should return 1 when key has no expiration", async () => {
378
+ const insertData = {
379
+ key: "a",
380
+ value: 1,
381
+ expiration: null,
382
+ };
383
+ await adapter.insert(insertData);
384
+ const updateData = {
385
+ key: "a",
386
+ value: 2,
387
+ };
388
+ const result = await adapter.incrementUnexpired(updateData);
389
+ expect(result).toBe(1);
390
+ });
391
+ test("Should persist update when key has expiration but not expired", async () => {
392
+ const insertData = {
393
+ key: "a",
394
+ value: 1,
395
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
396
+ };
397
+ await adapter.insert(insertData);
398
+ const updateData = {
399
+ key: "a",
400
+ value: 2,
401
+ };
402
+ await adapter.incrementUnexpired(updateData);
403
+ const findData = await adapter.find(updateData.key);
404
+ const result = {
405
+ value: insertData.value + updateData.value,
406
+ expiration: insertData.expiration,
407
+ };
408
+ expect(findData).toStrictEqual(result);
409
+ });
410
+ test("Should return 1 update when key has expiration but not expired", async () => {
411
+ const insertData = {
412
+ key: "a",
413
+ value: 1,
414
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
415
+ };
416
+ await adapter.insert(insertData);
417
+ const updateData = {
418
+ key: "a",
419
+ value: 2,
420
+ };
421
+ const result = await adapter.incrementUnexpired(updateData);
422
+ expect(result).toBe(1);
423
+ });
424
+ test("Should not persist update when key has expiration and expired", async () => {
425
+ const insertData = {
426
+ key: "a",
427
+ value: 1,
428
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
429
+ };
430
+ await adapter.insert(insertData);
431
+ const updateData = {
432
+ key: "a",
433
+ value: 2,
434
+ };
435
+ await adapter.incrementUnexpired(updateData);
436
+ const findData = await adapter.find(updateData.key);
437
+ const result = {
438
+ value: insertData.value,
439
+ expiration: insertData.expiration,
440
+ };
441
+ expect(findData).toStrictEqual(result);
442
+ });
443
+ test("Should return 0 update when key has expiration and expired", async () => {
444
+ const insertData = {
445
+ key: "a",
446
+ value: 1,
447
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
448
+ };
449
+ await adapter.insert(insertData);
450
+ const updateData = {
451
+ key: "a",
452
+ value: 2,
453
+ };
454
+ const result = await adapter.incrementUnexpired(updateData);
455
+ expect(result).toBe(0);
456
+ });
457
+ test("Should throw an error when incrementing a number error", async () => {
458
+ await adapter.insert({
459
+ key: "a",
460
+ value: "A",
461
+ expiration: null,
462
+ });
463
+ const promise = adapter.incrementUnexpired({
464
+ key: "a",
465
+ value: 2,
466
+ });
467
+ await expect(promise).rejects.toBeDefined();
468
+ });
469
+ });
470
+ describe("method: removeExpiredMany", () => {
471
+ test("Should not persist removal when key has no expiration", async () => {
472
+ const insertData = {
473
+ key: "a",
474
+ value: 1,
475
+ expiration: null,
476
+ };
477
+ await adapter.insert(insertData);
478
+ await adapter.removeExpiredMany([insertData.key]);
479
+ const findData = await adapter.find(insertData.key);
480
+ const result = {
481
+ value: insertData.value,
482
+ expiration: insertData.expiration,
483
+ };
484
+ expect(findData).toStrictEqual(result);
485
+ });
486
+ test("Should return 0 when key has no expiration", async () => {
487
+ const insertData = {
488
+ key: "a",
489
+ value: 1,
490
+ expiration: null,
491
+ };
492
+ await adapter.insert(insertData);
493
+ const result = await adapter.removeExpiredMany([insertData.key]);
494
+ expect(result).toBe(0);
495
+ });
496
+ test("Should not persist removal when key has expiration but not expired", async () => {
497
+ const insertData = {
498
+ key: "a",
499
+ value: 1,
500
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
501
+ };
502
+ await adapter.insert(insertData);
503
+ await adapter.removeExpiredMany([insertData.key]);
504
+ const findData = await adapter.find(insertData.key);
505
+ const result = {
506
+ value: insertData.value,
507
+ expiration: insertData.expiration,
508
+ };
509
+ expect(findData).toStrictEqual(result);
510
+ });
511
+ test("Should return 0 removal when key has expiration but not expired", async () => {
512
+ const insertData = {
513
+ key: "a",
514
+ value: 1,
515
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
516
+ };
517
+ await adapter.insert(insertData);
518
+ const result = await adapter.removeExpiredMany([insertData.key]);
519
+ expect(result).toBe(0);
520
+ });
521
+ test("Should persist removal when key has expiration and expired", async () => {
522
+ const insertData = {
523
+ key: "a",
524
+ value: 1,
525
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
526
+ };
527
+ await adapter.insert(insertData);
528
+ await adapter.removeExpiredMany([insertData.key]);
529
+ const findData = await adapter.find(insertData.key);
530
+ expect(findData).toBeNull();
531
+ });
532
+ test("Should return number of removed keys when all keys has expiration and are expired", async () => {
533
+ const insertData1 = {
534
+ key: "a",
535
+ value: 1,
536
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
537
+ };
538
+ const insertData2 = {
539
+ key: "b",
540
+ value: 1,
541
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
542
+ };
543
+ await adapter.insert(insertData1);
544
+ await adapter.insert(insertData2);
545
+ const result = await adapter.removeExpiredMany([
546
+ insertData1.key,
547
+ insertData2.key,
548
+ ]);
549
+ expect(result).toBe(2);
550
+ });
551
+ });
552
+ describe("method: removeUnexpiredMany", () => {
553
+ test("Should persist removal when key has no expiration", async () => {
554
+ const insertData = {
555
+ key: "a",
556
+ value: 1,
557
+ expiration: null,
558
+ };
559
+ await adapter.insert(insertData);
560
+ await adapter.removeUnexpiredMany([insertData.key]);
561
+ const findData = await adapter.find(insertData.key);
562
+ expect(findData).toBeNull();
563
+ });
564
+ test("Should return number of removed keys when all keys has no expiration", async () => {
565
+ const insertData1 = {
566
+ key: "a",
567
+ value: 1,
568
+ expiration: null,
569
+ };
570
+ const insertData2 = {
571
+ key: "b",
572
+ value: 1,
573
+ expiration: null,
574
+ };
575
+ await adapter.insert(insertData1);
576
+ await adapter.insert(insertData2);
577
+ const result = await adapter.removeUnexpiredMany([
578
+ insertData1.key,
579
+ insertData2.key,
580
+ ]);
581
+ expect(result).toBe(2);
582
+ });
583
+ test("Should persist removal when key has expiration but not expired", async () => {
584
+ const insertData = {
585
+ key: "a",
586
+ value: 1,
587
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
588
+ };
589
+ await adapter.insert(insertData);
590
+ await adapter.removeUnexpiredMany([insertData.key]);
591
+ const findData = await adapter.find(insertData.key);
592
+ expect(findData).toBeNull();
593
+ });
594
+ test("Should return number of removed keys when all key has expiration but not expired", async () => {
595
+ const insertData1 = {
596
+ key: "a",
597
+ value: 1,
598
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
599
+ };
600
+ const insertData2 = {
601
+ key: "b",
602
+ value: 1,
603
+ expiration: TimeSpan.fromMilliseconds(25).toEndDate(),
604
+ };
605
+ await adapter.insert(insertData1);
606
+ await adapter.insert(insertData2);
607
+ const result = await adapter.removeUnexpiredMany([
608
+ insertData1.key,
609
+ insertData2.key,
610
+ ]);
611
+ expect(result).toBe(2);
612
+ });
613
+ test("Should not persist removal when key has expiration and expired", async () => {
614
+ const insertData = {
615
+ key: "a",
616
+ value: 1,
617
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
618
+ };
619
+ await adapter.insert(insertData);
620
+ await adapter.removeUnexpiredMany([insertData.key]);
621
+ const findData = await adapter.find(insertData.key);
622
+ const result = {
623
+ expiration: insertData.expiration,
624
+ value: insertData.value,
625
+ };
626
+ expect(findData).toStrictEqual(result);
627
+ });
628
+ test("Should return 0 removal when key has expiration and expired", async () => {
629
+ const insertData = {
630
+ key: "a",
631
+ value: 1,
632
+ expiration: TimeSpan.fromMilliseconds(25).toStartDate(),
633
+ };
634
+ await adapter.insert(insertData);
635
+ const result = await adapter.removeUnexpiredMany([insertData.key]);
636
+ expect(result).toBe(0);
637
+ });
638
+ });
639
+ describe("method: removeAll", () => {
640
+ test("Should remove all keys", async () => {
641
+ await adapter.insert({
642
+ key: "cache/a",
643
+ value: 1,
644
+ expiration: null,
645
+ });
646
+ await adapter.insert({
647
+ key: "cache/b",
648
+ value: 2,
649
+ expiration: null,
650
+ });
651
+ await adapter.insert({
652
+ key: "c",
653
+ value: 3,
654
+ expiration: null,
655
+ });
656
+ await adapter.removeAll();
657
+ expect([
658
+ await adapter.find("cache/a"),
659
+ await adapter.find("cache/b"),
660
+ await adapter.find("c"),
661
+ ]).toEqual([null, null, null]);
662
+ });
663
+ });
664
+ describe("method: removeByKeyPrefix", () => {
665
+ test("Should remove the keys that mathc the prefix", async () => {
666
+ await adapter.insert({
667
+ key: "cache/a",
668
+ value: 1,
669
+ expiration: null,
670
+ });
671
+ await adapter.insert({
672
+ key: "cache/b",
673
+ value: 2,
674
+ expiration: null,
675
+ });
676
+ await adapter.insert({
677
+ key: "c",
678
+ value: 3,
679
+ expiration: null,
680
+ });
681
+ await adapter.removeByKeyPrefix("cache");
682
+ const result = [
683
+ await adapter.find("cache/a"),
684
+ await adapter.find("cache/b"),
685
+ await adapter.find("c"),
686
+ ];
687
+ expect(result).toStrictEqual([
688
+ null,
689
+ null,
690
+ {
691
+ value: 3,
692
+ expiration: null,
693
+ },
694
+ ]);
695
+ });
696
+ });
697
+ }
698
+ //# sourceMappingURL=database-cache-dapter.test-suite.js.map