@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
@@ -2,50 +2,36 @@
2
2
  * @module Cache
3
3
  */
4
4
  import {} from "vitest";
5
- import { KeyNotFoundCacheError, KeyNotFoundCacheEvent, KeyFoundCacheEvent, TypeCacheError, KeyAddedCacheEvent, KeyUpdatedCacheEvent, KeyRemovedCacheEvent, KeysClearedCacheEvent, KeyIncrementedCacheEvent, KeyDecrementedCacheEvent, } from "../../../cache/contracts/_module-exports.js";
5
+ import { TypeCacheError, KeyNotFoundCacheError, KeyNotFoundCacheEvent, KeyAddedCacheEvent, KeyDecrementedCacheEvent, KeyFoundCacheEvent, KeyIncrementedCacheEvent, KeyRemovedCacheEvent, KeysClearedCacheEvent, KeyUpdatedCacheEvent, } from "../../../cache/contracts/_module-exports.js";
6
6
  import {} from "../../../utilities/_module-exports.js";
7
7
  import { TimeSpan } from "../../../utilities/_module-exports.js";
8
- import { delay, LazyPromise } from "../../../async/_module-exports.js";
8
+ import { LazyPromise } from "../../../async/_module-exports.js";
9
9
  /**
10
10
  * The <i>cacheTestSuite</i> function simplifies the process of testing your custom implementation of <i>{@link ICache}</i> with <i>vitest</i>.
11
11
  *
12
- * IMPORT_PATH: ```"@daiso-tech/core/cache/implementations/test-utilities"```
12
+ * IMPORT_PATH: ```"@daiso-tech/core/cache/test-utilities"```
13
13
  * @group Test utilities
14
14
  * @example
15
15
  * ```ts
16
16
  * import { beforeEach, describe, expect, test } from "vitest";
17
- * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
18
- * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
19
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
20
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
21
- * import { cacheTestSuite } from "@daiso-tech/core/cache/implementations/test-utilities";
17
+ * import { cacheTestSuite } from "@daiso-tech/core/cache/test-utilities";
18
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
19
+ * import { Cache } from "@daiso-tech/core/cache";
20
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
22
21
  *
23
22
  * describe("class: Cache", () => {
24
- * const eventBus = new EventBus<any>({
25
- * adapter: new MemoryEventBusAdapter({
26
- * rootGroup: "@global",
27
- * }),
28
- * });
29
- * let map: Map<string, unknown>;
30
- * beforeEach(() => {
31
- * map = new Map();
32
- * });
33
23
  * cacheTestSuite({
34
- * createCache: () =>
35
- * new Cache({
36
- * adapter: new MemoryCacheAdapter({
37
- * rootGroup: "@a",
38
- * map,
39
- * }),
40
- * eventBus,
41
- * }),
42
- * beforeEach,
43
- * describe,
44
- * expect,
45
- * test,
46
- * });
24
+ * createCache: () =>
25
+ * new Cache({
26
+ * keyPrefixer: new KeyPrefixer("cache"),
27
+ * adapter: new MemoryCacheAdapter(),
28
+ * }),
29
+ * test,
30
+ * beforeEach,
31
+ * expect,
32
+ * describe,
33
+ * });
47
34
  * });
48
- *
49
35
  * ```
50
36
  */
51
37
  export function cacheTestSuite(settings) {
@@ -57,142 +43,67 @@ export function cacheTestSuite(settings) {
57
43
  cacheA = cache;
58
44
  cacheB = cache.withGroup("b");
59
45
  });
46
+ const TTL = TimeSpan.fromMilliseconds(50);
47
+ const DELAY_TIME = TimeSpan.fromMilliseconds(50);
60
48
  describe("Api tests:", () => {
61
- const TTL = TimeSpan.fromMilliseconds(50);
62
49
  describe("method: exists", () => {
63
50
  test("Should return true when key exists", async () => {
64
- await cacheA.add("a", 1);
51
+ await cacheA.add("a", 1, null);
52
+ await LazyPromise.delay(TTL.divide(4));
65
53
  expect(await cacheA.exists("a")).toBe(true);
66
54
  });
67
- test("Should return false when key doesnt exists", async () => {
55
+ test("Should return false when keys doesnt exists", async () => {
68
56
  expect(await cacheA.exists("a")).toBe(false);
69
57
  });
70
- test("Should return false when key is expired", async () => {
58
+ test("Should return false when key is experied", async () => {
71
59
  await cacheA.add("a", 1, TTL);
72
- await delay(TTL);
60
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
73
61
  expect(await cacheA.exists("a")).toBe(false);
74
62
  });
75
63
  });
76
- describe("method: existsMany", () => {
77
- test("Should return only true when all keys exists", async () => {
78
- await cacheA.addMany({
79
- a: { value: 1 },
80
- b: { value: 1 },
81
- });
82
- expect(await cacheA.existsMany(["a", "b"])).toEqual({
83
- a: true,
84
- b: true,
85
- });
86
- });
87
- test("Should return only false when all keys doesnt exists", async () => {
88
- expect(await cacheA.existsMany(["a", "b"])).toEqual({
89
- a: false,
90
- b: false,
91
- });
92
- });
93
- test("Should return true and false when some keys exists", async () => {
94
- await cacheA.add("a", 1);
95
- expect(await cacheA.existsMany(["a", "b"])).toEqual({
96
- a: true,
97
- b: false,
98
- });
99
- });
100
- test("Should return false when key is expired", async () => {
101
- await cacheA.add("a", 1, TTL);
102
- await delay(TTL);
103
- expect(await cacheA.existsMany(["a"])).toEqual({
104
- a: false,
105
- });
106
- });
107
- });
108
64
  describe("method: missing", () => {
109
65
  test("Should return false when key exists", async () => {
110
- await cacheA.add("a", 1);
66
+ await cacheA.add("a", 1, null);
67
+ await LazyPromise.delay(TTL.divide(4));
111
68
  expect(await cacheA.missing("a")).toBe(false);
112
69
  });
113
- test("Should return true when key doesnt exists", async () => {
70
+ test("Should return true when keys doesnt exists", async () => {
114
71
  expect(await cacheA.missing("a")).toBe(true);
115
72
  });
116
- test("Should return true when key is expired", async () => {
73
+ test("Should return true when key is experied", async () => {
117
74
  await cacheA.add("a", 1, TTL);
118
- await delay(TTL);
75
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
119
76
  expect(await cacheA.missing("a")).toBe(true);
120
77
  });
121
78
  });
122
- describe("method: missingMany", () => {
123
- test("Should return only false when all keys exists", async () => {
124
- await cacheA.addMany({
125
- a: { value: 1 },
126
- b: { value: 1 },
127
- });
128
- expect(await cacheA.missingMany(["a", "b"])).toEqual({
129
- a: false,
130
- b: false,
131
- });
132
- });
133
- test("Should return only true when all keys doesnt exists", async () => {
134
- expect(await cacheA.missingMany(["a", "b"])).toEqual({
135
- a: true,
136
- b: true,
137
- });
138
- });
139
- test("Should return true and false when some keys exists", async () => {
140
- await cacheA.add("a", 1);
141
- expect(await cacheA.missingMany(["a", "b"])).toEqual({
142
- a: false,
143
- b: true,
144
- });
145
- });
146
- test("Should return true when key is expired", async () => {
147
- await cacheA.add("a", 1, TTL);
148
- await delay(TTL);
149
- expect(await cacheA.missingMany(["a"])).toEqual({
150
- a: true,
151
- });
152
- });
153
- });
154
79
  describe("method: get", () => {
155
- test("Should return value when key exists", async () => {
156
- await cacheA.add("a", 1);
80
+ test("Should return the value when key exists", async () => {
81
+ await cacheA.add("a", 1, null);
82
+ await LazyPromise.delay(TTL.divide(4));
157
83
  expect(await cacheA.get("a")).toBe(1);
158
84
  });
159
- test("Should return null when key doesnt exists", async () => {
85
+ test("Should return null when keys doesnt exists", async () => {
160
86
  expect(await cacheA.get("a")).toBeNull();
161
87
  });
162
- test("Should return null when key is expired", async () => {
88
+ test("Should return null when key is experied", async () => {
163
89
  await cacheA.add("a", 1, TTL);
164
- await delay(TTL);
90
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
165
91
  expect(await cacheA.get("a")).toBeNull();
166
92
  });
167
93
  });
168
- describe("method: getMany", () => {
169
- test("Should return only values when all keys exists", async () => {
170
- await cacheA.addMany({
171
- a: { value: 1 },
172
- b: { value: 1 },
173
- });
174
- expect(await cacheA.getMany(["a", "b"])).toEqual({
175
- a: 1,
176
- b: 1,
177
- });
178
- });
179
- test("Should return only null when all keys doesnt exists", async () => {
180
- expect(await cacheA.getMany(["a", "b"])).toEqual({
181
- a: null,
182
- b: null,
183
- });
94
+ describe("method: getOrFail", () => {
95
+ test("Should return the value when key exists", async () => {
96
+ await cacheA.add("a", 1, null);
97
+ await LazyPromise.delay(TTL.divide(4));
98
+ expect(await cacheA.getOrFail("a")).toBe(1);
184
99
  });
185
- test("Should return values and null when some keys exists", async () => {
186
- await cacheA.add("a", 1);
187
- expect(await cacheA.getMany(["a", "b"])).toEqual({
188
- a: 1,
189
- b: null,
190
- });
100
+ test("Should throw an KeyNotFoundCacheError when keys doesnt exists", async () => {
101
+ await expect(cacheA.getOrFail("a")).rejects.toBeInstanceOf(KeyNotFoundCacheError);
191
102
  });
192
- test("Should return null when key is expired", async () => {
103
+ test("Should throw an KeyNotFoundCacheError when key is experied", async () => {
193
104
  await cacheA.add("a", 1, TTL);
194
- await delay(TTL);
195
- expect(await cacheA.getMany(["a"])).toEqual({ a: null });
105
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
106
+ await expect(cacheA.getOrFail("a")).rejects.toBeInstanceOf(KeyNotFoundCacheError);
196
107
  });
197
108
  });
198
109
  describe("method: getOr", () => {
@@ -217,595 +128,220 @@ export function cacheTestSuite(settings) {
217
128
  describe("Should return default value when key is expired", () => {
218
129
  test("Value", async () => {
219
130
  await cacheA.add("a", 1, TTL);
220
- await delay(TTL);
131
+ await LazyPromise.delay(TTL);
221
132
  expect(await cacheA.getOr("a", -1)).toBe(-1);
222
133
  });
223
134
  test("Function", async () => {
224
135
  await cacheA.add("a", 1, TTL);
225
- await delay(TTL);
136
+ await LazyPromise.delay(TTL);
226
137
  expect(await cacheA.getOr("a", () => -1)).toBe(-1);
227
138
  });
228
139
  test("Async function", async () => {
229
140
  await cacheA.add("a", 1, TTL);
230
- await delay(TTL);
141
+ await LazyPromise.delay(TTL);
231
142
  expect(await cacheA.getOr("a", () => Promise.resolve(-1))).toBe(-1);
232
143
  });
233
144
  test("LazyPromise", async () => {
234
145
  await cacheA.add("a", 1, TTL);
235
- await delay(TTL);
146
+ await LazyPromise.delay(TTL);
236
147
  expect(await cacheA.getOr("a", new LazyPromise(() => Promise.resolve(-1)))).toBe(-1);
237
148
  });
238
149
  });
239
150
  });
240
- describe("method: getOrFail", () => {
151
+ describe("method: getAndRemove", () => {
241
152
  test("Should return value when key exists", async () => {
242
- await cacheA.add("a", 1);
243
- expect(await cacheA.getOrFail("a")).toBe(1);
153
+ await cacheA.add("a", 1, null);
154
+ await LazyPromise.delay(TTL.divide(4));
155
+ expect(await cacheA.getAndRemove("a")).toBe(1);
244
156
  });
245
- test("Should throw KeyNotFoundCacheError value when key doesnt exists", async () => {
246
- await expect(cacheA.getOrFail("a")).rejects.toBeInstanceOf(KeyNotFoundCacheError);
157
+ test("Should return null when key doesnt exists", async () => {
158
+ expect(await cacheA.getAndRemove("a")).toBeNull();
247
159
  });
248
- test("Should throw KeyNotFoundCacheError value when key is expired exists", async () => {
160
+ test("Should return null when key is expired", async () => {
249
161
  await cacheA.add("a", 1, TTL);
250
- await delay(TTL);
251
- await expect(cacheA.getOrFail("a")).rejects.toBeInstanceOf(KeyNotFoundCacheError);
162
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
163
+ expect(await cacheA.getAndRemove("a")).toBeNull();
164
+ });
165
+ test("Should persist removal when key exists", async () => {
166
+ await cacheA.add("a", 1, null);
167
+ await LazyPromise.delay(TTL.divide(4));
168
+ await cacheA.getAndRemove("a");
169
+ await LazyPromise.delay(TTL.divide(4));
170
+ expect(await cacheA.get("a")).toBeNull();
252
171
  });
253
172
  });
254
- describe("method: getOrMany", () => {
255
- test("Should return only values when all keys exists", async () => {
256
- await cacheA.addMany({
257
- a: { value: 1 },
258
- b: { value: 1 },
259
- });
260
- expect(await cacheA.getOrMany({ a: -1, b: -1 })).toEqual({
261
- a: 1,
262
- b: 1,
263
- });
173
+ describe("method: getOrAdd", () => {
174
+ test("Should return value when key exists", async () => {
175
+ await cacheA.add("a", 1);
176
+ expect(await cacheA.getOrAdd("a", -1)).toBe(1);
264
177
  });
265
- describe("Should return only default values when all keys doesnt exists", () => {
178
+ describe("Should persist insertion when key doesnt exists", () => {
266
179
  test("Value", async () => {
267
- expect(await cacheA.getOrMany({ a: -1, b: -1 })).toEqual({
268
- a: -1,
269
- b: -1,
270
- });
180
+ await cacheA.getOrAdd("a", -1);
181
+ expect(await cacheA.get("a")).toBe(-1);
271
182
  });
272
183
  test("Function", async () => {
273
- expect(await cacheA.getOrMany({ a: () => -1, b: () => -1 })).toEqual({
274
- a: -1,
275
- b: -1,
276
- });
184
+ await cacheA.getOrAdd("a", () => -1);
185
+ expect(await cacheA.get("a")).toBe(-1);
277
186
  });
278
187
  test("Async function", async () => {
279
- expect(await cacheA.getOrMany({
280
- a: () => Promise.resolve(-1),
281
- b: () => Promise.resolve(-1),
282
- })).toEqual({
283
- a: -1,
284
- b: -1,
285
- });
188
+ await cacheA.getOrAdd("a", () => Promise.resolve(-1));
189
+ expect(await cacheA.get("a")).toBe(-1);
286
190
  });
287
191
  test("LazyPromise", async () => {
288
- expect(await cacheA.getOrMany({
289
- a: new LazyPromise(() => Promise.resolve(-1)),
290
- b: new LazyPromise(() => Promise.resolve(-1)),
291
- })).toEqual({
292
- a: -1,
293
- b: -1,
294
- });
192
+ await cacheA.getOrAdd("a", new LazyPromise(() => Promise.resolve(-1)));
193
+ expect(await cacheA.get("a")).toBe(-1);
295
194
  });
296
195
  });
297
- describe("Should return default value when key is expired", () => {
196
+ describe("Should persist insertion when key is expired", () => {
298
197
  test("Value", async () => {
299
198
  await cacheA.add("a", 1, TTL);
300
- await delay(TTL);
301
- expect(await cacheA.getOrMany({
302
- a: -1,
303
- })).toEqual({
304
- a: -1,
305
- });
199
+ await LazyPromise.delay(TTL);
200
+ await cacheA.getOrAdd("a", -1);
201
+ expect(await cacheA.get("a")).toBe(-1);
306
202
  });
307
203
  test("Function", async () => {
308
204
  await cacheA.add("a", 1, TTL);
309
- await delay(TTL);
310
- expect(await cacheA.getOrMany({
311
- a: () => -1,
312
- })).toEqual({
313
- a: -1,
314
- });
205
+ await LazyPromise.delay(TTL);
206
+ await cacheA.getOrAdd("a", () => -1);
207
+ expect(await cacheA.get("a")).toBe(-1);
315
208
  });
316
209
  test("Async function", async () => {
317
210
  await cacheA.add("a", 1, TTL);
318
- await delay(TTL);
319
- expect(await cacheA.getOrMany({
320
- a: () => Promise.resolve(-1),
321
- })).toEqual({
322
- a: -1,
323
- });
211
+ await LazyPromise.delay(TTL);
212
+ await cacheA.getOrAdd("a", () => Promise.resolve(-1));
213
+ expect(await cacheA.get("a")).toBe(-1);
324
214
  });
325
215
  test("LazyPromise", async () => {
326
216
  await cacheA.add("a", 1, TTL);
327
- await delay(TTL);
328
- expect(await cacheA.getOrMany({
329
- a: new LazyPromise(() => Promise.resolve(-1)),
330
- })).toEqual({
331
- a: -1,
332
- });
333
- });
334
- });
335
- test("Should return values and default values when some keys exists", async () => {
336
- await cacheA.add("a", 1);
337
- expect(await cacheA.getOrMany({ a: -1, b: -1 })).toEqual({
338
- a: 1,
339
- b: -1,
217
+ await LazyPromise.delay(TTL);
218
+ await cacheA.getOrAdd("a", new LazyPromise(() => Promise.resolve(-1)));
219
+ expect(await cacheA.get("a")).toBe(-1);
340
220
  });
341
221
  });
342
222
  });
343
223
  describe("method: add", () => {
344
- test("Should return true when key doesnt exist", async () => {
345
- expect(await cacheA.add("a", 1)).toBe(true);
224
+ test("Should return true when key doesnt exists", async () => {
225
+ const result = await cacheA.add("a", 1, null);
226
+ await LazyPromise.delay(TTL.divide(4));
227
+ expect(result).toBe(true);
346
228
  });
347
229
  test("Should return true when key is expired", async () => {
348
230
  await cacheA.add("a", 1, TTL);
349
- await delay(TTL);
350
- expect(await cacheA.add("a", 1)).toBe(true);
231
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
232
+ expect(await cacheA.add("a", 1, null)).toBe(true);
351
233
  });
352
- test("Should persist value when key doesnt exist", async () => {
353
- await cacheA.add("a", 1);
234
+ test("Should persist values when key doesnt exist", async () => {
235
+ await cacheA.add("a", 1, null);
236
+ await LazyPromise.delay(TTL.divide(4));
354
237
  expect(await cacheA.get("a")).toBe(1);
355
238
  });
356
- test("Should persist value when key is expired", async () => {
357
- await cacheA.add("a", 1, TTL);
358
- await delay(TTL);
359
- await cacheA.add("a", 1);
239
+ test("Should persist values when key is expired", async () => {
240
+ await cacheA.add("a", -1, TTL);
241
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
242
+ await cacheA.add("a", 1, null);
360
243
  expect(await cacheA.get("a")).toBe(1);
361
244
  });
362
- test("Should return false when key exist", async () => {
363
- await cacheA.add("a", 1);
364
- expect(await cacheA.add("a", 1)).toBe(false);
245
+ test("Should return false when key exists", async () => {
246
+ await cacheA.add("a", 1, null);
247
+ await LazyPromise.delay(TTL.divide(4));
248
+ expect(await cacheA.add("a", 1, null)).toBe(false);
365
249
  });
366
250
  test("Should not persist value when key exist", async () => {
367
- await cacheA.add("a", 1);
368
- await cacheA.add("a", 2);
251
+ await cacheA.add("a", 1, null);
252
+ await LazyPromise.delay(TTL.divide(4));
253
+ await cacheA.add("a", 2, null);
254
+ await LazyPromise.delay(TTL.divide(4));
369
255
  expect(await cacheA.get("a")).toBe(1);
370
256
  });
371
257
  });
372
- describe("method: addMany", () => {
373
- test("Should return only true when all keys doesnt exists", async () => {
374
- expect(await cacheA.addMany({
375
- a: { value: 1 },
376
- b: { value: 1 },
377
- })).toEqual({
378
- a: true,
379
- b: true,
380
- });
381
- });
382
- test("Should return true when key is expired", async () => {
383
- await cacheA.add("a", 1, TTL);
384
- await delay(TTL);
385
- expect(await cacheA.addMany({ a: { value: 1 } })).toEqual({
386
- a: true,
387
- });
388
- });
389
- test("Should persist values when all keys doesnt exist", async () => {
390
- await cacheA.addMany({
391
- a: { value: 1 },
392
- b: { value: 1 },
393
- });
394
- expect(await cacheA.getMany(["a", "b"])).toEqual({
395
- a: 1,
396
- b: 1,
397
- });
398
- });
399
- test("Should persist value when key is expired", async () => {
400
- await cacheA.add("a", -1, TTL);
401
- await delay(TTL);
402
- await cacheA.addMany({ a: { value: 1 } });
403
- expect(await cacheA.get("a")).toBe(1);
404
- });
405
- test("Should return only false when all keys exists", async () => {
406
- await cacheA.addMany({
407
- a: { value: 1 },
408
- b: { value: 1 },
409
- });
410
- expect(await cacheA.addMany({
411
- a: { value: 1 },
412
- b: { value: 1 },
413
- })).toEqual({
414
- a: false,
415
- b: false,
416
- });
417
- });
418
- test("Should not persist values when key exist", async () => {
419
- await cacheA.addMany({
420
- a: { value: 1 },
421
- b: { value: 1 },
422
- });
423
- await cacheA.addMany({
424
- a: { value: 1 },
425
- b: { value: 1 },
426
- });
427
- expect(await cacheA.getMany(["a", "b"])).toEqual({
428
- a: 1,
429
- b: 1,
430
- });
431
- });
432
- test("Should return true and false when some keys exists", async () => {
433
- await cacheA.add("a", 1);
434
- expect(await cacheA.addMany({
435
- a: { value: 1 },
436
- b: { value: 1 },
437
- })).toEqual({
438
- a: false,
439
- b: true,
440
- });
441
- });
442
- test("Should persist and not persist values when some keys exists", async () => {
443
- await cacheA.addMany({
444
- a: { value: 1 },
445
- });
446
- await cacheA.addMany({
447
- a: { value: 1 },
448
- b: { value: 2 },
449
- });
450
- expect(await cacheA.getMany(["a", "b"])).toEqual({
451
- a: 1,
452
- b: 2,
453
- });
454
- });
455
- });
456
- describe("method: update", () => {
457
- test("Should return true when key exists", async () => {
458
- await cacheA.add("a", 1);
459
- expect(await cacheA.update("a", -1)).toBe(true);
460
- });
461
- test("Should persist update when key exists", async () => {
462
- await cacheA.add("a", 1);
463
- await cacheA.update("a", -1);
464
- expect(await cacheA.get("a")).toBe(-1);
465
- });
466
- test("Should return false when key doesnt exists", async () => {
467
- expect(await cacheA.update("a", -1)).toBe(false);
468
- });
469
- test("Should return false when key is expired", async () => {
470
- await cacheA.add("a", 1, TTL);
471
- await delay(TTL);
472
- expect(await cacheA.update("a", -1)).toBe(false);
473
- });
474
- test("Should not persist update when key doesnt exists", async () => {
475
- await cacheA.update("a", -1);
476
- expect(await cacheA.get("a")).toBeNull();
477
- });
478
- test("Should not persist update when key is expired", async () => {
479
- await cacheA.add("a", 1, TTL);
480
- await delay(TTL);
481
- await cacheA.update("a", -1);
482
- expect(await cacheA.get("a")).toBeNull();
483
- });
484
- });
485
- describe("method: updateMany", () => {
486
- test("Should return only true when all keys exists", async () => {
487
- await cacheA.addMany({
488
- a: { value: 1 },
489
- b: { value: 1 },
490
- });
491
- expect(await cacheA.updateMany({ a: -1, b: -1 })).toEqual({
492
- a: true,
493
- b: true,
494
- });
495
- });
496
- test("Should persist values when all keys exist", async () => {
497
- await cacheA.addMany({
498
- a: { value: 1 },
499
- b: { value: 1 },
500
- });
501
- await cacheA.updateMany({ a: -1, b: -1 });
502
- expect(await cacheA.getMany(["a", "b"])).toEqual({
503
- a: -1,
504
- b: -1,
505
- });
506
- });
507
- test("Should return only false when all keys doesnt exists", async () => {
508
- expect(await cacheA.updateMany({ a: -1, b: -1 })).toEqual({
509
- a: false,
510
- b: false,
511
- });
512
- });
513
- test("Should return false when key is expired", async () => {
514
- await cacheA.add("a", 1, TTL);
515
- await delay(TTL);
516
- expect(await cacheA.updateMany({ a: -1 })).toEqual({
517
- a: false,
518
- });
519
- });
520
- test("Should not persist values when all keys doesnt exist", async () => {
521
- await cacheA.updateMany({ a: -1, b: -1 });
522
- expect(await cacheA.getMany(["a", "b"])).toEqual({
523
- a: null,
524
- b: null,
525
- });
526
- });
527
- test("Should not persist update when key is expired", async () => {
528
- await cacheA.add("a", 1, TTL);
529
- await delay(TTL);
530
- await cacheA.updateMany({ a: -1 });
531
- expect(await cacheA.get("a")).toBeNull();
532
- });
533
- test("Should return true and false when some keys exists", async () => {
534
- await cacheA.add("a", 1);
535
- expect(await cacheA.updateMany({ a: -1, b: -1 })).toEqual({
536
- a: true,
537
- b: false,
538
- });
539
- });
540
- test("Should persist and not persist values when some keys exists", async () => {
541
- await cacheA.add("a", 1);
542
- await cacheA.updateMany({ a: -1, b: -1 });
543
- expect(await cacheA.getMany(["a", "b"])).toEqual({
544
- a: -1,
545
- b: null,
546
- });
547
- });
548
- });
549
258
  describe("method: put", () => {
550
259
  test("Should return true when key exists", async () => {
551
- await cacheA.add("a", 1);
552
- expect(await cacheA.put("a", -1)).toBe(true);
553
- });
554
- test("Should persist update when key exists", async () => {
555
- await cacheA.add("a", 1);
556
- await cacheA.put("a", -1);
260
+ await cacheA.add("a", 1, null);
261
+ await LazyPromise.delay(TTL.divide(4));
262
+ expect(await cacheA.put("a", -1, null)).toBe(true);
263
+ });
264
+ test("Should persist value when key exist", async () => {
265
+ await cacheA.add("a", 1, null);
266
+ await LazyPromise.delay(TTL.divide(4));
267
+ await cacheA.put("a", -1, null);
268
+ await LazyPromise.delay(TTL.divide(4));
557
269
  expect(await cacheA.get("a")).toBe(-1);
558
270
  });
559
271
  test("Should return false when key doesnt exists", async () => {
560
- expect(await cacheA.put("a", -1)).toBe(false);
272
+ expect(await cacheA.put("a", -1, null)).toBe(false);
561
273
  });
562
274
  test("Should return false when key is expired", async () => {
563
275
  await cacheA.add("a", 1, TTL);
564
- await delay(TTL);
565
- expect(await cacheA.put("a", -1)).toBe(false);
276
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
277
+ expect(await cacheA.put("a", -1, null)).toBe(false);
566
278
  });
567
- test("Should persist insertion when key doesnt exists", async () => {
568
- await cacheA.put("a", -1);
279
+ test("Should persist values when key doesnt exist", async () => {
280
+ await cacheA.put("a", -1, null);
281
+ await LazyPromise.delay(TTL.divide(4));
569
282
  expect(await cacheA.get("a")).toBe(-1);
570
283
  });
571
- test("Should persist insertion when key is expired", async () => {
284
+ test("Should persist values when key is expired", async () => {
572
285
  await cacheA.add("a", 1, TTL);
573
- await delay(TTL);
574
- await cacheA.put("a", -1);
286
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
287
+ await cacheA.put("a", -1, null);
288
+ await LazyPromise.delay(TTL.divide(4));
575
289
  expect(await cacheA.get("a")).toBe(-1);
576
290
  });
577
291
  test("Should replace the ttl value", async () => {
578
292
  const ttlA = TimeSpan.fromMilliseconds(100);
579
293
  await cacheA.add("a", 1, ttlA);
294
+ await LazyPromise.delay(TTL.divide(4));
580
295
  const ttlB = TimeSpan.fromMilliseconds(50);
581
296
  await cacheA.put("a", -1, ttlB);
582
- await delay(ttlB);
297
+ await LazyPromise.delay(ttlB);
583
298
  expect(await cacheA.get("a")).toBeNull();
584
299
  });
585
300
  });
586
- describe("method: putMany", () => {
587
- test("Should return only true when all keys exists", async () => {
588
- await cacheA.addMany({
589
- a: { value: 1 },
590
- b: { value: 1 },
591
- });
592
- expect(await cacheA.putMany({
593
- a: { value: -1 },
594
- b: { value: -1 },
595
- })).toEqual({
596
- a: true,
597
- b: true,
598
- });
599
- });
600
- test("Should persist values when all keys exist", async () => {
601
- await cacheA.addMany({
602
- a: { value: 1 },
603
- b: { value: 1 },
604
- });
605
- await cacheA.putMany({ a: { value: -1 }, b: { value: -1 } });
606
- expect(await cacheA.getMany(["a", "b"])).toEqual({
607
- a: -1,
608
- b: -1,
609
- });
610
- });
611
- test("Should return only false when all keys doesnt exists", async () => {
612
- expect(await cacheA.putMany({
613
- a: { value: -1 },
614
- b: { value: -1 },
615
- })).toEqual({
616
- a: false,
617
- b: false,
618
- });
619
- });
620
- test("Should return false when key is expired", async () => {
621
- await cacheA.add("a", 1, TTL);
622
- await delay(TTL);
623
- expect(await cacheA.putMany({ a: { value: -1 } })).toEqual({
624
- a: false,
625
- });
626
- });
627
- test("Should persist values when all keys doesnt exist", async () => {
628
- await cacheA.putMany({ a: { value: -1 }, b: { value: -1 } });
629
- expect(await cacheA.getMany(["a", "b"])).toEqual({
630
- a: -1,
631
- b: -1,
632
- });
633
- });
634
- test("Should persist insertion when key is expired", async () => {
635
- await cacheA.add("a", 1, TTL);
636
- await delay(TTL);
637
- await cacheA.putMany({ a: { value: -1 } });
638
- expect(await cacheA.get("a")).toBe(-1);
639
- });
640
- test("Should return true and false when some keys exists", async () => {
641
- await cacheA.add("a", 1);
642
- expect(await cacheA.putMany({
643
- a: { value: -1 },
644
- b: { value: -1 },
645
- })).toEqual({
646
- a: true,
647
- b: false,
648
- });
649
- });
650
- test("Should persist all values when some keys exists", async () => {
651
- await cacheA.add("a", 1);
652
- await cacheA.putMany({ a: { value: -1 }, b: { value: -1 } });
653
- expect(await cacheA.getMany(["a", "b"])).toEqual({
654
- a: -1,
655
- b: -1,
656
- });
657
- });
658
- test("Should replace the ttl value", async () => {
659
- const ttlA = TimeSpan.fromMilliseconds(100);
660
- await cacheA.add("a", 1, ttlA);
661
- const ttlB = TimeSpan.fromMilliseconds(50);
662
- await cacheA.putMany({
663
- a: {
664
- value: -1,
665
- ttl: ttlB,
666
- },
667
- });
668
- await delay(ttlB);
669
- expect(await cacheA.get("a")).toBeNull();
670
- });
671
- });
672
- describe("method: remove", () => {
301
+ describe("method: update", () => {
673
302
  test("Should return true when key exists", async () => {
674
- await cacheA.add("a", 1);
675
- expect(await cacheA.remove("a")).toBe(true);
303
+ await cacheA.add("a", 1, null);
304
+ await LazyPromise.delay(TTL.divide(4));
305
+ expect(await cacheA.update("a", -1)).toBe(true);
676
306
  });
677
- test("Should persist removal when key exists", async () => {
678
- await cacheA.add("a", 1);
679
- await cacheA.remove("a");
680
- expect(await cacheA.get("a")).toBeNull();
307
+ test("Should persist value when key exist", async () => {
308
+ await cacheA.add("a", 1, null);
309
+ await LazyPromise.delay(TTL.divide(4));
310
+ await cacheA.update("a", -1);
311
+ await LazyPromise.delay(TTL.divide(4));
312
+ expect(await cacheA.get("a")).toBe(-1);
681
313
  });
682
314
  test("Should return false when key doesnt exists", async () => {
683
- expect(await cacheA.remove("a")).toBe(false);
684
- });
685
- test("Should return false when key is expired", async () => {
686
- await cacheA.add("a", 1, TTL);
687
- await delay(TTL);
688
- expect(await cacheA.remove("a")).toBe(false);
689
- });
690
- });
691
- describe("method: removeMany", () => {
692
- test("Should return only true when all keys exists", async () => {
693
- await cacheA.addMany({
694
- a: { value: 1 },
695
- b: { value: 1 },
696
- });
697
- expect(await cacheA.removeMany(["a", "b"])).toEqual({
698
- a: true,
699
- b: true,
700
- });
701
- });
702
- test("Should persist values when all keys exist", async () => {
703
- await cacheA.addMany({
704
- a: { value: 1 },
705
- b: { value: 1 },
706
- });
707
- await cacheA.removeMany(["a", "b"]);
708
- expect(await cacheA.getMany(["a", "b"])).toEqual({
709
- a: null,
710
- b: null,
711
- });
712
- });
713
- test("Should return only false when all keys doesnt exists", async () => {
714
- expect(await cacheA.removeMany(["a", "b"])).toEqual({
715
- a: false,
716
- b: false,
717
- });
315
+ expect(await cacheA.update("a", -1)).toBe(false);
718
316
  });
719
317
  test("Should return false when key is expired", async () => {
720
318
  await cacheA.add("a", 1, TTL);
721
- await delay(TTL);
722
- expect(await cacheA.removeMany(["a"])).toEqual({ a: false });
723
- });
724
- test("Should return true and false when some keys exists", async () => {
725
- await cacheA.add("a", 1);
726
- expect(await cacheA.removeMany(["a", "b"])).toEqual({
727
- a: true,
728
- b: false,
729
- });
730
- });
731
- });
732
- describe("method: getAndRemove", () => {
733
- test("Should return value when key exists", async () => {
734
- await cacheA.add("a", 1);
735
- expect(await cacheA.getAndRemove("a")).toBe(1);
319
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
320
+ expect(await cacheA.update("a", -1)).toBe(false);
736
321
  });
737
- test("Should return null when key doesnt exists", async () => {
738
- expect(await cacheA.getAndRemove("a")).toBeNull();
322
+ test("Should not persist value when key doesnt exist", async () => {
323
+ await cacheA.update("a", -1);
324
+ await LazyPromise.delay(TTL.divide(4));
325
+ expect(await cacheA.get("a")).toBeNull();
739
326
  });
740
- test("Should return null when key is expired", async () => {
327
+ test("Should not persist value when key is expired", async () => {
741
328
  await cacheA.add("a", 1, TTL);
742
- await delay(TTL);
743
- expect(await cacheA.getAndRemove("a")).toBeNull();
744
- });
745
- test("Should persist removal when key exists", async () => {
746
- await cacheA.add("a", 1);
747
- await cacheA.getAndRemove("a");
329
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
330
+ await cacheA.update("a", -1);
748
331
  expect(await cacheA.get("a")).toBeNull();
749
332
  });
750
333
  });
751
- describe("method: getOrAdd", () => {
752
- test("Should return value when key exists", async () => {
753
- await cacheA.add("a", 1);
754
- expect(await cacheA.getOrAdd("a", -1)).toBe(1);
755
- });
756
- describe("Should persist insertion when key doesnt exists", () => {
757
- test("Value", async () => {
758
- await cacheA.getOrAdd("a", -1);
759
- expect(await cacheA.get("a")).toBe(-1);
760
- });
761
- test("Function", async () => {
762
- await cacheA.getOrAdd("a", () => -1);
763
- expect(await cacheA.get("a")).toBe(-1);
764
- });
765
- test("Async function", async () => {
766
- await cacheA.getOrAdd("a", () => Promise.resolve(-1));
767
- expect(await cacheA.get("a")).toBe(-1);
768
- });
769
- test("LazyPromise", async () => {
770
- await cacheA.getOrAdd("a", new LazyPromise(() => Promise.resolve(-1)));
771
- expect(await cacheA.get("a")).toBe(-1);
772
- });
773
- });
774
- describe("Should persist insertion when key is expired", () => {
775
- test("Value", async () => {
776
- await cacheA.add("a", 1, TTL);
777
- await delay(TTL);
778
- await cacheA.getOrAdd("a", -1);
779
- expect(await cacheA.get("a")).toBe(-1);
780
- });
781
- test("Function", async () => {
782
- await cacheA.add("a", 1, TTL);
783
- await delay(TTL);
784
- await cacheA.getOrAdd("a", () => -1);
785
- expect(await cacheA.get("a")).toBe(-1);
786
- });
787
- test("Async function", async () => {
788
- await cacheA.add("a", 1, TTL);
789
- await delay(TTL);
790
- await cacheA.getOrAdd("a", () => Promise.resolve(-1));
791
- expect(await cacheA.get("a")).toBe(-1);
792
- });
793
- test("LazyPromise", async () => {
794
- await cacheA.add("a", 1, TTL);
795
- await delay(TTL);
796
- await cacheA.getOrAdd("a", new LazyPromise(() => Promise.resolve(-1)));
797
- expect(await cacheA.get("a")).toBe(-1);
798
- });
799
- });
800
- });
801
334
  describe("method: increment", () => {
802
335
  test("Should return true when key exists", async () => {
803
- await cacheA.add("a", 1);
336
+ await cacheA.add("a", 1, null);
337
+ await LazyPromise.delay(TTL.divide(4));
804
338
  expect(await cacheA.increment("a", 1)).toBe(true);
805
339
  });
806
340
  test("Should persist increment when key exists", async () => {
807
- await cacheA.add("a", 1);
341
+ await cacheA.add("a", 1, null);
342
+ await LazyPromise.delay(TTL.divide(4));
808
343
  await cacheA.increment("a", 1);
344
+ await LazyPromise.delay(TTL.divide(4));
809
345
  expect(await cacheA.get("a")).toBe(2);
810
346
  });
811
347
  test("Should return false when key doesnt exists", async () => {
@@ -813,32 +349,37 @@ export function cacheTestSuite(settings) {
813
349
  });
814
350
  test("Should return false when key is expired", async () => {
815
351
  await cacheA.add("a", 1, TTL);
816
- await delay(TTL);
352
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
817
353
  expect(await cacheA.increment("a", 1)).toBe(false);
818
354
  });
819
355
  test("Should not persist increment when key doesnt exists", async () => {
820
356
  await cacheA.increment("a", 1);
357
+ await LazyPromise.delay(TTL.divide(4));
821
358
  expect(await cacheA.get("a")).toBeNull();
822
359
  });
823
360
  test("Should not persist increment when key is expired", async () => {
824
361
  await cacheA.add("a", 1, TTL);
825
- await delay(TTL);
362
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
826
363
  await cacheA.increment("a", 1);
827
364
  expect(await cacheA.get("a")).toBeNull();
828
365
  });
829
366
  test("Should throw TypeCacheError key value is not number type", async () => {
830
- await cacheA.add("a", "str");
367
+ await cacheA.add("a", "str", null);
368
+ await LazyPromise.delay(TTL.divide(4));
831
369
  await expect(cacheA.increment("a", 1)).rejects.toBeInstanceOf(TypeCacheError);
832
370
  });
833
371
  });
834
372
  describe("method: decrement", () => {
835
373
  test("Should return true when key exists", async () => {
836
- await cacheA.add("a", 1);
374
+ await cacheA.add("a", 1, null);
375
+ await LazyPromise.delay(TTL.divide(4));
837
376
  expect(await cacheA.decrement("a", 1)).toBe(true);
838
377
  });
839
378
  test("Should persist decrement when key exists", async () => {
840
- await cacheA.add("a", 1);
379
+ await cacheA.add("a", 1, null);
380
+ await LazyPromise.delay(TTL.divide(4));
841
381
  await cacheA.decrement("a", 1);
382
+ await LazyPromise.delay(TTL.divide(4));
842
383
  expect(await cacheA.get("a")).toBe(0);
843
384
  });
844
385
  test("Should return false when key doesnt exists", async () => {
@@ -846,48 +387,81 @@ export function cacheTestSuite(settings) {
846
387
  });
847
388
  test("Should return false when key is expired", async () => {
848
389
  await cacheA.add("a", 1, TTL);
849
- await delay(TTL);
390
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
850
391
  expect(await cacheA.decrement("a", 1)).toBe(false);
851
392
  });
852
393
  test("Should not persist decrement when key doesnt exists", async () => {
853
394
  await cacheA.decrement("a", 1);
395
+ await LazyPromise.delay(TTL.divide(4));
854
396
  expect(await cacheA.get("a")).toBeNull();
855
397
  });
856
398
  test("Should not persist decrement when key is expired", async () => {
857
399
  await cacheA.add("a", 1, TTL);
858
- await delay(TTL);
400
+ await LazyPromise.delay(TTL.addTimeSpan(TTL.divide(4)));
859
401
  await cacheA.decrement("a", 1);
860
402
  expect(await cacheA.get("a")).toBeNull();
861
403
  });
862
404
  test("Should throw TypeCacheError key value is not number type", async () => {
863
- await cacheA.add("a", "str");
405
+ await cacheA.add("a", "str", null);
406
+ await LazyPromise.delay(TTL.divide(4));
864
407
  await expect(cacheA.decrement("a", 1)).rejects.toBeInstanceOf(TypeCacheError);
865
408
  });
866
409
  });
410
+ describe("method: remove", () => {
411
+ test("Should return true when key exists", async () => {
412
+ await cacheA.add("a", 1, null);
413
+ await LazyPromise.delay(TTL.divide(4));
414
+ const result = await cacheA.remove("a");
415
+ expect(result).toBe(true);
416
+ });
417
+ test("Should persist the key removal when key exists", async () => {
418
+ await cacheA.add("a", 1, null);
419
+ await LazyPromise.delay(TTL.divide(4));
420
+ await cacheA.remove("a");
421
+ await LazyPromise.delay(TTL.divide(4));
422
+ expect(await cacheA.get("a")).toEqual(null);
423
+ });
424
+ });
425
+ describe("method: removeMany", () => {
426
+ test("Should return true when one key exists", async () => {
427
+ await cacheA.add("a", 1, null);
428
+ await LazyPromise.delay(TTL.divide(4));
429
+ const result = await cacheA.removeMany(["a", "b", "c"]);
430
+ expect(result).toBe(true);
431
+ });
432
+ test("Should persist removal of the keys that exists", async () => {
433
+ await cacheA.add("a", 1, null);
434
+ await cacheA.add("b", 2, null);
435
+ await cacheA.add("c", 3, null);
436
+ await LazyPromise.delay(TTL.divide(4));
437
+ await cacheA.removeMany(["a", "b"]);
438
+ await LazyPromise.delay(TTL.divide(4));
439
+ const result = [
440
+ await cacheA.get("a"),
441
+ await cacheA.get("b"),
442
+ await cacheA.get("c"),
443
+ ];
444
+ expect(result).toEqual([null, null, 3]);
445
+ });
446
+ });
867
447
  describe("method: clear", () => {
868
448
  test("Should remove all keys", async () => {
869
- await cacheA.addMany({
870
- a: { value: 1 },
871
- b: { value: 2 },
872
- c: { value: 3 },
873
- d: { value: 4 },
874
- e: { value: 5 },
875
- f: { value: 6 },
876
- });
449
+ await cacheA.add("a", 1);
450
+ await cacheA.add("b", 2);
451
+ await cacheA.add("c", 3);
452
+ await cacheA.add("d", 4);
877
453
  await cacheA.clear();
878
- expect(await cacheA.getMany(["a", "b", "c", "d", "e", "f"])).toEqual({
879
- a: null,
880
- b: null,
881
- c: null,
882
- d: null,
883
- e: null,
884
- f: null,
885
- });
454
+ const result = [
455
+ await cacheA.get("a"),
456
+ await cacheA.get("b"),
457
+ await cacheA.get("c"),
458
+ await cacheA.get("d"),
459
+ ];
460
+ expect(result).toStrictEqual([null, null, null, null]);
886
461
  });
887
462
  });
888
463
  });
889
464
  describe("Event tests:", () => {
890
- const delayTime = TimeSpan.fromMilliseconds(50);
891
465
  describe("method: exists", () => {
892
466
  test("Should dispatch KeyNotFoundCacheEvent when key doesnt exists", async () => {
893
467
  let event_ = null;
@@ -895,7 +469,7 @@ export function cacheTestSuite(settings) {
895
469
  event_ = event;
896
470
  });
897
471
  await cacheA.exists("a");
898
- await delay(delayTime);
472
+ await LazyPromise.delay(DELAY_TIME);
899
473
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
900
474
  expect(event_?.fields.key).toBe("a");
901
475
  await unsubscribe();
@@ -907,33 +481,7 @@ export function cacheTestSuite(settings) {
907
481
  });
908
482
  await cacheA.add("a", 1);
909
483
  await cacheA.exists("a");
910
- await delay(delayTime);
911
- expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
912
- expect(event_?.fields.key).toBe("a");
913
- expect(event_?.fields.value).toBe(1);
914
- await unsubscribe();
915
- });
916
- });
917
- describe("method: existsMany", () => {
918
- test("Should dispatch KeyNotFoundCacheEvent when key doesnt exists", async () => {
919
- let event_ = null;
920
- const unsubscribe = await cacheA.subscribe(KeyNotFoundCacheEvent, (event) => {
921
- event_ = event;
922
- });
923
- await cacheA.existsMany(["a"]);
924
- await delay(delayTime);
925
- expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
926
- expect(event_?.fields.key).toBe("a");
927
- await unsubscribe();
928
- });
929
- test("Should dispatch KeyFoundCacheEvent when key exists", async () => {
930
- let event_ = null;
931
- const unsubscribe = await cacheA.subscribe(KeyFoundCacheEvent, (event) => {
932
- event_ = event;
933
- });
934
- await cacheA.add("a", 1);
935
- await cacheA.existsMany(["a"]);
936
- await delay(delayTime);
484
+ await LazyPromise.delay(DELAY_TIME);
937
485
  expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
938
486
  expect(event_?.fields.key).toBe("a");
939
487
  expect(event_?.fields.value).toBe(1);
@@ -947,7 +495,7 @@ export function cacheTestSuite(settings) {
947
495
  event_ = event;
948
496
  });
949
497
  await cacheA.missing("a");
950
- await delay(delayTime);
498
+ await LazyPromise.delay(DELAY_TIME);
951
499
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
952
500
  expect(event_?.fields.key).toBe("a");
953
501
  await unsubscribe();
@@ -959,33 +507,7 @@ export function cacheTestSuite(settings) {
959
507
  });
960
508
  await cacheA.add("a", 1);
961
509
  await cacheA.missing("a");
962
- await delay(delayTime);
963
- expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
964
- expect(event_?.fields.key).toBe("a");
965
- expect(event_?.fields.value).toBe(1);
966
- await unsubscribe();
967
- });
968
- });
969
- describe("method: missingMany", () => {
970
- test("Should dispatch KeyNotFoundCacheEvent when key doesnt exists", async () => {
971
- let event_ = null;
972
- const unsubscribe = await cacheA.subscribe(KeyNotFoundCacheEvent, (event) => {
973
- event_ = event;
974
- });
975
- await cacheA.missingMany(["a"]);
976
- await delay(delayTime);
977
- expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
978
- expect(event_?.fields.key).toBe("a");
979
- await unsubscribe();
980
- });
981
- test("Should dispatch KeyFoundCacheEvent when key exists", async () => {
982
- let event_ = null;
983
- const unsubscribe = await cacheA.subscribe(KeyFoundCacheEvent, (event) => {
984
- event_ = event;
985
- });
986
- await cacheA.add("a", 1);
987
- await cacheA.missingMany(["a"]);
988
- await delay(delayTime);
510
+ await LazyPromise.delay(DELAY_TIME);
989
511
  expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
990
512
  expect(event_?.fields.key).toBe("a");
991
513
  expect(event_?.fields.value).toBe(1);
@@ -999,7 +521,7 @@ export function cacheTestSuite(settings) {
999
521
  event_ = event;
1000
522
  });
1001
523
  await cacheA.get("a");
1002
- await delay(delayTime);
524
+ await LazyPromise.delay(DELAY_TIME);
1003
525
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1004
526
  expect(event_?.fields.key).toBe("a");
1005
527
  await unsubscribe();
@@ -1011,33 +533,7 @@ export function cacheTestSuite(settings) {
1011
533
  });
1012
534
  await cacheA.add("a", 1);
1013
535
  await cacheA.get("a");
1014
- await delay(delayTime);
1015
- expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
1016
- expect(event_?.fields.key).toBe("a");
1017
- expect(event_?.fields.value).toBe(1);
1018
- await unsubscribe();
1019
- });
1020
- });
1021
- describe("method: getMany", () => {
1022
- test("Should dispatch KeyNotFoundCacheEvent when key doesnt exists", async () => {
1023
- let event_ = null;
1024
- const unsubscribe = await cacheA.subscribe(KeyNotFoundCacheEvent, (event) => {
1025
- event_ = event;
1026
- });
1027
- await cacheA.getMany(["a"]);
1028
- await delay(delayTime);
1029
- expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1030
- expect(event_?.fields.key).toBe("a");
1031
- await unsubscribe();
1032
- });
1033
- test("Should dispatch KeyFoundCacheEvent when key exists", async () => {
1034
- let event_ = null;
1035
- const unsubscribe = await cacheA.subscribe(KeyFoundCacheEvent, (event) => {
1036
- event_ = event;
1037
- });
1038
- await cacheA.add("a", 1);
1039
- await cacheA.getMany(["a"]);
1040
- await delay(delayTime);
536
+ await LazyPromise.delay(DELAY_TIME);
1041
537
  expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
1042
538
  expect(event_?.fields.key).toBe("a");
1043
539
  expect(event_?.fields.value).toBe(1);
@@ -1051,7 +547,7 @@ export function cacheTestSuite(settings) {
1051
547
  event_ = event;
1052
548
  });
1053
549
  await cacheA.getOr("a", 1);
1054
- await delay(delayTime);
550
+ await LazyPromise.delay(DELAY_TIME);
1055
551
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1056
552
  expect(event_?.fields.key).toBe("a");
1057
553
  await unsubscribe();
@@ -1063,33 +559,7 @@ export function cacheTestSuite(settings) {
1063
559
  });
1064
560
  await cacheA.add("a", 1);
1065
561
  await cacheA.getOr("a", 1);
1066
- await delay(delayTime);
1067
- expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
1068
- expect(event_?.fields.key).toBe("a");
1069
- expect(event_?.fields.value).toBe(1);
1070
- await unsubscribe();
1071
- });
1072
- });
1073
- describe("method: getOrMany", () => {
1074
- test("Should dispatch KeyNotFoundCacheEvent when key doesnt exists", async () => {
1075
- let event_ = null;
1076
- const unsubscribe = await cacheA.subscribe(KeyNotFoundCacheEvent, (event) => {
1077
- event_ = event;
1078
- });
1079
- await cacheA.getOrMany({ a: 1 });
1080
- await delay(delayTime);
1081
- expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1082
- expect(event_?.fields.key).toBe("a");
1083
- await unsubscribe();
1084
- });
1085
- test("Should dispatch KeyFoundCacheEvent when key exists", async () => {
1086
- let event_ = null;
1087
- const unsubscribe = await cacheA.subscribe(KeyFoundCacheEvent, (event) => {
1088
- event_ = event;
1089
- });
1090
- await cacheA.add("a", 1);
1091
- await cacheA.getOrMany({ a: 1 });
1092
- await delay(delayTime);
562
+ await LazyPromise.delay(DELAY_TIME);
1093
563
  expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
1094
564
  expect(event_?.fields.key).toBe("a");
1095
565
  expect(event_?.fields.value).toBe(1);
@@ -1108,7 +578,7 @@ export function cacheTestSuite(settings) {
1108
578
  catch {
1109
579
  /* Empty */
1110
580
  }
1111
- await delay(delayTime);
581
+ await LazyPromise.delay(DELAY_TIME);
1112
582
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1113
583
  expect(event_?.fields.key).toBe("a");
1114
584
  await unsubscribe();
@@ -1120,7 +590,7 @@ export function cacheTestSuite(settings) {
1120
590
  });
1121
591
  await cacheA.add("a", 1);
1122
592
  await cacheA.getOrFail("a");
1123
- await delay(delayTime);
593
+ await LazyPromise.delay(DELAY_TIME);
1124
594
  expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
1125
595
  expect(event_?.fields.key).toBe("a");
1126
596
  expect(event_?.fields.value).toBe(1);
@@ -1135,23 +605,7 @@ export function cacheTestSuite(settings) {
1135
605
  });
1136
606
  const ttl = TimeSpan.fromMilliseconds(20);
1137
607
  await cacheA.add("a", 1, ttl);
1138
- await delay(delayTime);
1139
- expect(event_).toBeInstanceOf(KeyAddedCacheEvent);
1140
- expect(event_?.fields.key).toBe("a");
1141
- expect(event_?.fields.value).toBe(1);
1142
- expect(event_?.fields.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
1143
- await unsubscribe();
1144
- });
1145
- });
1146
- describe("method: addMany", () => {
1147
- test("Should dispatch KeyAddedCacheEvent when key doesnt exists", async () => {
1148
- let event_ = null;
1149
- const unsubscribe = await cacheA.subscribe(KeyAddedCacheEvent, (event) => {
1150
- event_ = event;
1151
- });
1152
- const ttl = TimeSpan.fromMilliseconds(20);
1153
- await cacheA.addMany({ a: { value: 1, ttl } });
1154
- await delay(delayTime);
608
+ await LazyPromise.delay(DELAY_TIME);
1155
609
  expect(event_).toBeInstanceOf(KeyAddedCacheEvent);
1156
610
  expect(event_?.fields.key).toBe("a");
1157
611
  expect(event_?.fields.value).toBe(1);
@@ -1167,7 +621,7 @@ export function cacheTestSuite(settings) {
1167
621
  });
1168
622
  await cacheA.add("a", 1);
1169
623
  await cacheA.update("a", 2);
1170
- await delay(delayTime);
624
+ await LazyPromise.delay(DELAY_TIME);
1171
625
  expect(event_).toBeInstanceOf(KeyUpdatedCacheEvent);
1172
626
  expect(event_?.fields.key).toBe("a");
1173
627
  expect(event_?.fields.value).toBe(2);
@@ -1179,33 +633,7 @@ export function cacheTestSuite(settings) {
1179
633
  event_ = event;
1180
634
  });
1181
635
  await cacheA.update("a", 2);
1182
- await delay(delayTime);
1183
- expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1184
- expect(event_?.fields.key).toBe("a");
1185
- await unsubscribe();
1186
- });
1187
- });
1188
- describe("method: updateMany", () => {
1189
- test("Should dispatch KeyUpdatedCacheEvent when key exists", async () => {
1190
- let event_ = null;
1191
- const unsubscribe = await cacheA.subscribe(KeyUpdatedCacheEvent, (event) => {
1192
- event_ = event;
1193
- });
1194
- await cacheA.add("a", 1);
1195
- await cacheA.updateMany({ a: 2 });
1196
- await delay(delayTime);
1197
- expect(event_).toBeInstanceOf(KeyUpdatedCacheEvent);
1198
- expect(event_?.fields.key).toBe("a");
1199
- expect(event_?.fields.value).toBe(2);
1200
- await unsubscribe();
1201
- });
1202
- test("Should dispatch KeyNotFoundCacheEvent when key doesnt exists", async () => {
1203
- let event_ = null;
1204
- const unsubscribe = await cacheA.subscribe(KeyNotFoundCacheEvent, (event) => {
1205
- event_ = event;
1206
- });
1207
- await cacheA.updateMany({ a: 2 });
1208
- await delay(delayTime);
636
+ await LazyPromise.delay(DELAY_TIME);
1209
637
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1210
638
  expect(event_?.fields.key).toBe("a");
1211
639
  await unsubscribe();
@@ -1219,7 +647,7 @@ export function cacheTestSuite(settings) {
1219
647
  });
1220
648
  const ttl = TimeSpan.fromMilliseconds(20);
1221
649
  await cacheA.put("a", 1, ttl);
1222
- await delay(delayTime);
650
+ await LazyPromise.delay(DELAY_TIME);
1223
651
  expect(event_).toBeInstanceOf(KeyAddedCacheEvent);
1224
652
  expect(event_?.fields.key).toBe("a");
1225
653
  expect(event_?.fields.value).toBe(1);
@@ -1233,37 +661,7 @@ export function cacheTestSuite(settings) {
1233
661
  });
1234
662
  await cacheA.put("a", 1);
1235
663
  await cacheA.put("a", 2);
1236
- await delay(delayTime);
1237
- expect(event_).toBeInstanceOf(KeyUpdatedCacheEvent);
1238
- expect(event_?.fields.key).toBe("a");
1239
- expect(event_?.fields.value).toBe(2);
1240
- await unsubscribe();
1241
- });
1242
- });
1243
- describe("method: putMany", () => {
1244
- test("Should dispatch KeyAddedCacheEvent when key exists", async () => {
1245
- let event_ = null;
1246
- const unsubscribe = await cacheA.subscribe(KeyAddedCacheEvent, (event) => {
1247
- event_ = event;
1248
- });
1249
- const ttl = TimeSpan.fromMilliseconds(20);
1250
- await cacheA.putMany({ a: { value: 1, ttl } });
1251
- await delay(delayTime);
1252
- expect(event_).toBeInstanceOf(KeyAddedCacheEvent);
1253
- expect(event_?.fields.key).toBe("a");
1254
- expect(event_?.fields.value).toBe(1);
1255
- expect(event_?.fields.ttl?.toMilliseconds()).toBe(ttl.toMilliseconds());
1256
- await unsubscribe();
1257
- });
1258
- test("Should dispatch KeyUpdatedCacheEvent when key exists", async () => {
1259
- let event_ = null;
1260
- const unsubscribe = await cacheA.subscribe(KeyUpdatedCacheEvent, (event) => {
1261
- event_ = event;
1262
- });
1263
- const ttl = TimeSpan.fromMilliseconds(20);
1264
- await cacheA.putMany({ a: { value: 1, ttl } });
1265
- await cacheA.putMany({ a: { value: 2, ttl } });
1266
- await delay(delayTime);
664
+ await LazyPromise.delay(DELAY_TIME);
1267
665
  expect(event_).toBeInstanceOf(KeyUpdatedCacheEvent);
1268
666
  expect(event_?.fields.key).toBe("a");
1269
667
  expect(event_?.fields.value).toBe(2);
@@ -1278,7 +676,7 @@ export function cacheTestSuite(settings) {
1278
676
  });
1279
677
  await cacheA.add("a", 1);
1280
678
  await cacheA.remove("a");
1281
- await delay(delayTime);
679
+ await LazyPromise.delay(DELAY_TIME);
1282
680
  expect(event_).toBeInstanceOf(KeyRemovedCacheEvent);
1283
681
  expect(event_?.fields.key).toBe("a");
1284
682
  await unsubscribe();
@@ -1289,7 +687,7 @@ export function cacheTestSuite(settings) {
1289
687
  event_ = event;
1290
688
  });
1291
689
  await cacheA.remove("a");
1292
- await delay(delayTime);
690
+ await LazyPromise.delay(DELAY_TIME);
1293
691
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1294
692
  expect(event_?.fields.key).toBe("a");
1295
693
  await unsubscribe();
@@ -1303,7 +701,7 @@ export function cacheTestSuite(settings) {
1303
701
  });
1304
702
  await cacheA.add("a", 1);
1305
703
  await cacheA.removeMany(["a"]);
1306
- await delay(delayTime);
704
+ await LazyPromise.delay(DELAY_TIME);
1307
705
  expect(event_).toBeInstanceOf(KeyRemovedCacheEvent);
1308
706
  expect(event_?.fields.key).toBe("a");
1309
707
  await unsubscribe();
@@ -1314,7 +712,7 @@ export function cacheTestSuite(settings) {
1314
712
  event_ = event;
1315
713
  });
1316
714
  await cacheA.removeMany(["a"]);
1317
- await delay(delayTime);
715
+ await LazyPromise.delay(DELAY_TIME);
1318
716
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1319
717
  expect(event_?.fields.key).toBe("a");
1320
718
  await unsubscribe();
@@ -1327,7 +725,7 @@ export function cacheTestSuite(settings) {
1327
725
  event_ = event;
1328
726
  });
1329
727
  await cacheA.getAndRemove("a");
1330
- await delay(delayTime);
728
+ await LazyPromise.delay(DELAY_TIME);
1331
729
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1332
730
  expect(event_?.fields.key).toBe("a");
1333
731
  await unsubscribe();
@@ -1339,7 +737,7 @@ export function cacheTestSuite(settings) {
1339
737
  });
1340
738
  await cacheA.add("a", 1);
1341
739
  await cacheA.getAndRemove("a");
1342
- await delay(delayTime);
740
+ await LazyPromise.delay(DELAY_TIME);
1343
741
  expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
1344
742
  expect(event_?.fields.key).toBe("a");
1345
743
  expect(event_?.fields.value).toBe(1);
@@ -1352,7 +750,7 @@ export function cacheTestSuite(settings) {
1352
750
  });
1353
751
  await cacheA.add("a", 1);
1354
752
  await cacheA.getAndRemove("a");
1355
- await delay(delayTime);
753
+ await LazyPromise.delay(DELAY_TIME);
1356
754
  expect(event_).toBeInstanceOf(KeyRemovedCacheEvent);
1357
755
  expect(event_?.fields.key).toBe("a");
1358
756
  await unsubscribe();
@@ -1365,7 +763,7 @@ export function cacheTestSuite(settings) {
1365
763
  event_ = event;
1366
764
  });
1367
765
  await cacheA.getOrAdd("a", 1);
1368
- await delay(delayTime);
766
+ await LazyPromise.delay(DELAY_TIME);
1369
767
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1370
768
  expect(event_?.fields.key).toBe("a");
1371
769
  await unsubscribe();
@@ -1377,7 +775,7 @@ export function cacheTestSuite(settings) {
1377
775
  });
1378
776
  await cacheA.add("a", 1);
1379
777
  await cacheA.getOrAdd("a", 1);
1380
- await delay(delayTime);
778
+ await LazyPromise.delay(DELAY_TIME);
1381
779
  expect(event_).toBeInstanceOf(KeyFoundCacheEvent);
1382
780
  expect(event_?.fields.key).toBe("a");
1383
781
  expect(event_?.fields.value).toBe(1);
@@ -1390,7 +788,7 @@ export function cacheTestSuite(settings) {
1390
788
  });
1391
789
  const ttl = TimeSpan.fromMilliseconds(50);
1392
790
  await cacheA.getOrAdd("a", 1, ttl);
1393
- await delay(delayTime);
791
+ await LazyPromise.delay(DELAY_TIME);
1394
792
  expect(event_).toBeInstanceOf(KeyAddedCacheEvent);
1395
793
  expect(event_?.fields.key).toBe("a");
1396
794
  expect(event_?.fields.value).toBe(1);
@@ -1406,7 +804,7 @@ export function cacheTestSuite(settings) {
1406
804
  });
1407
805
  await cacheA.add("a", 1);
1408
806
  await cacheA.increment("a", 1);
1409
- await delay(delayTime);
807
+ await LazyPromise.delay(DELAY_TIME);
1410
808
  expect(event_).toBeInstanceOf(KeyIncrementedCacheEvent);
1411
809
  expect(event_?.fields.key).toBe("a");
1412
810
  expect(event_?.fields.value).toBe(1);
@@ -1418,7 +816,7 @@ export function cacheTestSuite(settings) {
1418
816
  event_ = event;
1419
817
  });
1420
818
  await cacheA.increment("a", 1);
1421
- await delay(delayTime);
819
+ await LazyPromise.delay(DELAY_TIME);
1422
820
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1423
821
  expect(event_?.fields.key).toBe("a");
1424
822
  await unsubscribe();
@@ -1432,7 +830,7 @@ export function cacheTestSuite(settings) {
1432
830
  });
1433
831
  await cacheA.add("a", 1);
1434
832
  await cacheA.decrement("a", 1);
1435
- await delay(delayTime);
833
+ await LazyPromise.delay(DELAY_TIME);
1436
834
  expect(event_).toBeInstanceOf(KeyDecrementedCacheEvent);
1437
835
  expect(event_?.fields.key).toBe("a");
1438
836
  expect(event_?.fields.value).toBe(1);
@@ -1444,7 +842,7 @@ export function cacheTestSuite(settings) {
1444
842
  event_ = event;
1445
843
  });
1446
844
  await cacheA.decrement("a", 1);
1447
- await delay(delayTime);
845
+ await LazyPromise.delay(DELAY_TIME);
1448
846
  expect(event_).toBeInstanceOf(KeyNotFoundCacheEvent);
1449
847
  expect(event_?.fields.key).toBe("a");
1450
848
  await unsubscribe();
@@ -1456,13 +854,11 @@ export function cacheTestSuite(settings) {
1456
854
  const unsubscribe = await cacheA.subscribe(KeysClearedCacheEvent, (event) => {
1457
855
  event_ = event;
1458
856
  });
1459
- await cacheA.addMany({
1460
- a: { value: 1 },
1461
- b: { value: 2 },
1462
- c: { value: 3 },
1463
- });
857
+ await cacheA.add("a", 1);
858
+ await cacheA.add("b", 2);
859
+ await cacheA.add("c", 3);
1464
860
  await cacheA.clear();
1465
- await delay(delayTime);
861
+ await LazyPromise.delay(DELAY_TIME);
1466
862
  expect(event_).toBeInstanceOf(KeysClearedCacheEvent);
1467
863
  await unsubscribe();
1468
864
  });
@@ -1474,83 +870,21 @@ export function cacheTestSuite(settings) {
1474
870
  expect(await cacheA.exists("a")).toBe(true);
1475
871
  expect(await cacheB.exists("a")).toBe(false);
1476
872
  });
1477
- test("method: existsMany", async () => {
1478
- await cacheA.putMany({
1479
- a: { value: 1 },
1480
- b: { value: 1 },
1481
- });
1482
- expect(await cacheA.existsMany(["a", "b"])).toEqual({
1483
- a: true,
1484
- b: true,
1485
- });
1486
- expect(await cacheB.existsMany(["a", "b"])).toEqual({
1487
- a: false,
1488
- b: false,
1489
- });
1490
- });
1491
873
  test("method: missing", async () => {
1492
874
  await cacheA.put("a", 1);
1493
875
  expect(await cacheA.missing("a")).toBe(false);
1494
876
  expect(await cacheB.missing("a")).toBe(true);
1495
877
  });
1496
- test("method: missingMany", async () => {
1497
- await cacheA.putMany({
1498
- a: { value: 1 },
1499
- b: { value: 1 },
1500
- });
1501
- expect(await cacheA.missingMany(["a", "b"])).toEqual({
1502
- a: false,
1503
- b: false,
1504
- });
1505
- expect(await cacheB.missingMany(["a", "b"])).toEqual({
1506
- a: true,
1507
- b: true,
1508
- });
1509
- });
1510
878
  test("method: get", async () => {
1511
879
  await cacheA.put("a", 1);
1512
880
  expect(await cacheA.get("a")).toBe(1);
1513
881
  expect(await cacheB.get("a")).toBeNull();
1514
882
  });
1515
- test("method: getMany", async () => {
1516
- await cacheA.putMany({
1517
- a: { value: 1 },
1518
- b: { value: 1 },
1519
- });
1520
- expect(await cacheA.getMany(["a", "b"])).toEqual({
1521
- a: 1,
1522
- b: 1,
1523
- });
1524
- expect(await cacheB.getMany(["a", "b"])).toEqual({
1525
- a: null,
1526
- b: null,
1527
- });
1528
- });
1529
883
  test("method: getOr", async () => {
1530
884
  await cacheA.put("a", 1);
1531
885
  expect(await cacheA.getOr("a", -1)).toBe(1);
1532
886
  expect(await cacheB.getOr("a", -1)).toBe(-1);
1533
887
  });
1534
- test("method: getOrMany", async () => {
1535
- await cacheA.putMany({
1536
- a: { value: 1 },
1537
- b: { value: 1 },
1538
- });
1539
- expect(await cacheA.getOrMany({
1540
- a: -1,
1541
- b: -1,
1542
- })).toEqual({
1543
- a: 1,
1544
- b: 1,
1545
- });
1546
- expect(await cacheB.getOrMany({
1547
- a: -1,
1548
- b: -1,
1549
- })).toEqual({
1550
- a: -1,
1551
- b: -1,
1552
- });
1553
- });
1554
888
  test("method: getOrFail", async () => {
1555
889
  await cacheA.put("a", 1);
1556
890
  expect(await cacheA.getOrFail("a")).toBe(1);
@@ -1562,18 +896,6 @@ export function cacheTestSuite(settings) {
1562
896
  expect(await cacheA.get("a")).toBe(1);
1563
897
  expect(await cacheB.get("a")).toBe(2);
1564
898
  });
1565
- test("method: addMany", async () => {
1566
- await cacheA.addMany({
1567
- a: { value: 1 },
1568
- b: { value: 1 },
1569
- });
1570
- await cacheB.addMany({
1571
- a: { value: 2 },
1572
- b: { value: 2 },
1573
- });
1574
- expect(await cacheA.getMany(["a", "b"])).toEqual({ a: 1, b: 1 });
1575
- expect(await cacheB.getMany(["a", "b"])).toEqual({ a: 2, b: 2 });
1576
- });
1577
899
  test("method: update", async () => {
1578
900
  await cacheA.add("a", 1);
1579
901
  await cacheB.add("a", 1);
@@ -1582,44 +904,12 @@ export function cacheTestSuite(settings) {
1582
904
  expect(await cacheA.get("a")).toBe(2);
1583
905
  expect(await cacheB.get("a")).toBe(3);
1584
906
  });
1585
- test("method: updateMany", async () => {
1586
- await cacheA.addMany({
1587
- a: { value: 1 },
1588
- b: { value: 1 },
1589
- });
1590
- await cacheB.addMany({
1591
- a: { value: 1 },
1592
- b: { value: 1 },
1593
- });
1594
- await cacheA.updateMany({
1595
- a: 2,
1596
- b: 2,
1597
- });
1598
- await cacheB.updateMany({
1599
- a: 3,
1600
- b: 3,
1601
- });
1602
- expect(await cacheA.getMany(["a", "b"])).toEqual({ a: 2, b: 2 });
1603
- expect(await cacheB.getMany(["a", "b"])).toEqual({ a: 3, b: 3 });
1604
- });
1605
907
  test("method: put", async () => {
1606
908
  await cacheA.put("a", 2);
1607
909
  await cacheB.put("a", 3);
1608
910
  expect(await cacheA.get("a")).toBe(2);
1609
911
  expect(await cacheB.get("a")).toBe(3);
1610
912
  });
1611
- test("method: putMany", async () => {
1612
- await cacheA.putMany({
1613
- a: { value: 2 },
1614
- b: { value: 2 },
1615
- });
1616
- await cacheB.putMany({
1617
- a: { value: 3 },
1618
- b: { value: 3 },
1619
- });
1620
- expect(await cacheA.getMany(["a", "b"])).toEqual({ a: 2, b: 2 });
1621
- expect(await cacheB.getMany(["a", "b"])).toEqual({ a: 3, b: 3 });
1622
- });
1623
913
  test("method: remove", async () => {
1624
914
  await cacheA.add("a", 1);
1625
915
  await cacheB.add("a", 1);
@@ -1627,22 +917,6 @@ export function cacheTestSuite(settings) {
1627
917
  expect(await cacheA.get("a")).toBeNull();
1628
918
  expect(await cacheB.get("a")).toBe(1);
1629
919
  });
1630
- test("method: removeMany", async () => {
1631
- await cacheA.addMany({
1632
- a: { value: 1 },
1633
- b: { value: 1 },
1634
- });
1635
- await cacheB.addMany({
1636
- a: { value: 1 },
1637
- b: { value: 1 },
1638
- });
1639
- await cacheA.removeMany(["a", "b"]);
1640
- expect(await cacheA.getMany(["a", "b"])).toEqual({
1641
- a: null,
1642
- b: null,
1643
- });
1644
- expect(await cacheB.getMany(["a", "b"])).toEqual({ a: 1, b: 1 });
1645
- });
1646
920
  test("method: getAndRemove", async () => {
1647
921
  await cacheA.add("a", 1);
1648
922
  await cacheB.add("a", 2);
@@ -1671,23 +945,18 @@ export function cacheTestSuite(settings) {
1671
945
  expect(await cacheB.get("a")).toBe(1);
1672
946
  });
1673
947
  test("method: clear", async () => {
1674
- await cacheA.addMany({
1675
- a: { value: 1 },
1676
- b: { value: 2 },
1677
- });
1678
- await cacheB.addMany({
1679
- a: { value: 1 },
1680
- b: { value: 2 },
1681
- });
948
+ await cacheA.add("a", 1);
949
+ await cacheA.add("b", 2);
950
+ await cacheB.add("a", 3);
951
+ await cacheB.add("b", 4);
1682
952
  await cacheA.clear();
1683
- expect(await cacheA.getMany(["a", "b"])).toEqual({
1684
- a: null,
1685
- b: null,
1686
- });
1687
- expect(await cacheB.getMany(["a", "b"])).toEqual({
1688
- a: 1,
1689
- b: 2,
1690
- });
953
+ const resultA = [
954
+ await cacheA.get("a"),
955
+ await cacheA.get("b"),
956
+ await cacheB.get("a"),
957
+ await cacheB.get("b"),
958
+ ];
959
+ expect(resultA).toEqual([null, null, 3, 4]);
1691
960
  });
1692
961
  test("method: addListener / dispatch", async () => {
1693
962
  let result_a = null;
@@ -1699,6 +968,7 @@ export function cacheTestSuite(settings) {
1699
968
  result_b = event;
1700
969
  });
1701
970
  await cacheA.add("a", 1);
971
+ await LazyPromise.delay(DELAY_TIME);
1702
972
  expect(result_a).toBeInstanceOf(KeyAddedCacheEvent);
1703
973
  expect(result_b).toBeNull();
1704
974
  });
@@ -1712,6 +982,7 @@ export function cacheTestSuite(settings) {
1712
982
  result_b = event;
1713
983
  });
1714
984
  await cacheA.add("a", 1);
985
+ await LazyPromise.delay(DELAY_TIME);
1715
986
  expect(result_a).toBeInstanceOf(KeyAddedCacheEvent);
1716
987
  expect(result_b).toBeNull();
1717
988
  });
@@ -1728,6 +999,7 @@ export function cacheTestSuite(settings) {
1728
999
  await cacheB.removeListener(KeyAddedCacheEvent, listenerB);
1729
1000
  await cacheA.add("a", 1);
1730
1001
  await cacheB.add("a", 1);
1002
+ await LazyPromise.delay(DELAY_TIME);
1731
1003
  expect(result_a).toBeInstanceOf(KeyAddedCacheEvent);
1732
1004
  expect(result_b).toBeNull();
1733
1005
  });
@@ -1744,6 +1016,7 @@ export function cacheTestSuite(settings) {
1744
1016
  await cacheB.removeListenerMany([KeyAddedCacheEvent], listenerB);
1745
1017
  await cacheA.add("a", 1);
1746
1018
  await cacheB.add("a", 1);
1019
+ await LazyPromise.delay(DELAY_TIME);
1747
1020
  expect(result_a).toBeInstanceOf(KeyAddedCacheEvent);
1748
1021
  expect(result_b).toBeNull();
1749
1022
  });
@@ -1760,6 +1033,7 @@ export function cacheTestSuite(settings) {
1760
1033
  await unsubscribe();
1761
1034
  await cacheA.add("a", 1);
1762
1035
  await cacheB.add("a", 1);
1036
+ await LazyPromise.delay(DELAY_TIME);
1763
1037
  expect(result_a).toBeInstanceOf(KeyAddedCacheEvent);
1764
1038
  expect(result_b).toBeNull();
1765
1039
  });
@@ -1776,6 +1050,7 @@ export function cacheTestSuite(settings) {
1776
1050
  await unsubscribe();
1777
1051
  await cacheA.add("a", 1);
1778
1052
  await cacheB.add("a", 1);
1053
+ await LazyPromise.delay(DELAY_TIME);
1779
1054
  expect(result_a).toBeInstanceOf(KeyAddedCacheEvent);
1780
1055
  expect(result_b).toBeNull();
1781
1056
  });