@daiso-tech/core 0.39.0 → 0.41.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 (679) hide show
  1. package/dist/backoff-policies/_module-exports.d.ts +5 -0
  2. package/dist/backoff-policies/_module-exports.js +6 -0
  3. package/dist/backoff-policies/_module-exports.js.map +1 -0
  4. package/dist/{async/backof-policies → backoff-policies}/_shared.d.ts +6 -7
  5. package/dist/{async/backof-policies → backoff-policies}/_shared.js +1 -1
  6. package/dist/backoff-policies/_shared.js.map +1 -0
  7. package/dist/backoff-policies/constant-backoff-policy/_module.d.ts +1 -0
  8. package/dist/backoff-policies/constant-backoff-policy/_module.js +2 -0
  9. package/dist/backoff-policies/constant-backoff-policy/_module.js.map +1 -0
  10. package/dist/{async/backof-policies → backoff-policies}/constant-backoff-policy/constant-backoff-policy.d.ts +6 -8
  11. package/dist/{async/backof-policies → backoff-policies}/constant-backoff-policy/constant-backoff-policy.js +8 -10
  12. package/dist/backoff-policies/constant-backoff-policy/constant-backoff-policy.js.map +1 -0
  13. package/dist/backoff-policies/exponential-backoff-policy/_module.d.ts +1 -0
  14. package/dist/backoff-policies/exponential-backoff-policy/_module.js +2 -0
  15. package/dist/backoff-policies/exponential-backoff-policy/_module.js.map +1 -0
  16. package/dist/{async/backof-policies → backoff-policies}/exponential-backoff-policy/exponential-backoff-policy.d.ts +7 -9
  17. package/dist/backoff-policies/exponential-backoff-policy/exponential-backoff-policy.js +30 -0
  18. package/dist/backoff-policies/exponential-backoff-policy/exponential-backoff-policy.js.map +1 -0
  19. package/dist/backoff-policies/linear-backoff-policy/_module.d.ts +1 -0
  20. package/dist/backoff-policies/linear-backoff-policy/_module.js +2 -0
  21. package/dist/backoff-policies/linear-backoff-policy/_module.js.map +1 -0
  22. package/dist/{async/backof-policies → backoff-policies}/linear-backoff-policy/linear-backoff-policy.d.ts +7 -9
  23. package/dist/backoff-policies/linear-backoff-policy/linear-backoff-policy.js +30 -0
  24. package/dist/backoff-policies/linear-backoff-policy/linear-backoff-policy.js.map +1 -0
  25. package/dist/backoff-policies/polynomial-backoff-policy/_module.d.ts +1 -0
  26. package/dist/backoff-policies/polynomial-backoff-policy/_module.js +2 -0
  27. package/dist/backoff-policies/polynomial-backoff-policy/_module.js.map +1 -0
  28. package/dist/{async/backof-policies → backoff-policies}/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +7 -9
  29. package/dist/backoff-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +30 -0
  30. package/dist/backoff-policies/polynomial-backoff-policy/polynomial-backoff-policy.js.map +1 -0
  31. package/dist/cache/contracts/cache-adapter.contract.d.ts +12 -12
  32. package/dist/cache/contracts/cache.contract.d.ts +22 -22
  33. package/dist/cache/contracts/cache.errors.d.ts +7 -14
  34. package/dist/cache/contracts/cache.errors.js +12 -24
  35. package/dist/cache/contracts/cache.errors.js.map +1 -1
  36. package/dist/cache/contracts/cache.events.d.ts +1 -1
  37. package/dist/cache/contracts/database-cache-adapter.contract.d.ts +10 -10
  38. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +1 -1
  39. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +4 -4
  40. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
  41. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +1 -1
  42. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +2 -2
  43. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
  44. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +3 -2
  45. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +3 -3
  46. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
  47. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +10 -10
  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.d.ts +1 -1
  50. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +2 -2
  51. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
  52. package/dist/cache/implementations/derivables/cache/cache.d.ts +38 -43
  53. package/dist/cache/implementations/derivables/cache/cache.js +106 -101
  54. package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
  55. package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +1 -1
  56. package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +3 -3
  57. package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -1
  58. package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +6 -8
  59. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +5 -15
  60. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
  61. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +1 -1
  62. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +48 -48
  63. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
  64. package/dist/cache/implementations/test-utilities/cache.test-suite.js +107 -107
  65. package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
  66. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +2 -1
  67. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
  68. package/dist/collection/contracts/async-collection.contract.d.ts +43 -43
  69. package/dist/collection/contracts/collection.contract.d.ts +15 -1
  70. package/dist/collection/contracts/collection.contract.js +1 -3
  71. package/dist/collection/contracts/collection.contract.js.map +1 -1
  72. package/dist/collection/contracts/collection.errors.d.ts +4 -13
  73. package/dist/collection/contracts/collection.errors.js +4 -16
  74. package/dist/collection/contracts/collection.errors.js.map +1 -1
  75. package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.d.ts +6 -0
  76. package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js +3 -0
  77. package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js.map +1 -1
  78. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +40 -51
  79. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +31 -37
  80. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
  81. package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.d.ts +3 -0
  82. package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js +6 -0
  83. package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js.map +1 -1
  84. package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +3 -3
  85. package/dist/collection/implementations/iterable-collection/iterable-collection.js +5 -2
  86. package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
  87. package/dist/collection/implementations/list-collection/list-collection.d.ts +3 -3
  88. package/dist/collection/implementations/list-collection/list-collection.js +5 -2
  89. package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
  90. package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +3 -3
  91. package/dist/event-bus/contracts/event-bus.contract.d.ts +10 -10
  92. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +3 -3
  93. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +3 -6
  94. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +7 -9
  95. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
  96. package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +18 -24
  97. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +51 -51
  98. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
  99. package/dist/event-bus/implementations/derivables/event-bus/listener-store.d.ts +11 -4
  100. package/dist/event-bus/implementations/derivables/event-bus/listener-store.js +17 -12
  101. package/dist/event-bus/implementations/derivables/event-bus/listener-store.js.map +1 -1
  102. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +1 -3
  103. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +4 -8
  104. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
  105. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +36 -37
  106. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
  107. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +86 -674
  108. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
  109. package/dist/hooks/_module-exports.d.ts +3 -0
  110. package/dist/hooks/_module-exports.js +4 -0
  111. package/dist/hooks/_module-exports.js.map +1 -0
  112. package/dist/{utilities/classes/hooks → hooks}/async-hooks.d.ts +15 -26
  113. package/dist/{utilities/classes/hooks → hooks}/async-hooks.js +4 -6
  114. package/dist/hooks/async-hooks.js.map +1 -0
  115. package/dist/{utilities/classes/hooks → hooks}/hooks.d.ts +11 -18
  116. package/dist/{utilities/classes/hooks → hooks}/hooks.js +4 -5
  117. package/dist/hooks/hooks.js.map +1 -0
  118. package/dist/{utilities/classes/hooks → hooks}/types.d.ts +2 -3
  119. package/dist/hooks/types.js +5 -0
  120. package/dist/hooks/types.js.map +1 -0
  121. package/dist/lock/contracts/_module-exports.d.ts +4 -2
  122. package/dist/lock/contracts/_module-exports.js +4 -2
  123. package/dist/lock/contracts/_module-exports.js.map +1 -1
  124. package/dist/lock/contracts/database-lock-adapter.contract.d.ts +59 -14
  125. package/dist/lock/contracts/lock-adapter.contract.d.ts +22 -10
  126. package/dist/lock/contracts/lock-provider.contract.d.ts +5 -5
  127. package/dist/lock/contracts/lock-state.contract.d.ts +52 -0
  128. package/dist/lock/contracts/lock-state.contract.js +14 -0
  129. package/dist/lock/contracts/lock-state.contract.js.map +1 -0
  130. package/dist/lock/contracts/lock.contract.d.ts +72 -58
  131. package/dist/lock/contracts/lock.errors.d.ts +18 -15
  132. package/dist/lock/contracts/lock.errors.js +22 -17
  133. package/dist/lock/contracts/lock.errors.js.map +1 -1
  134. package/dist/lock/contracts/lock.events.d.ts +21 -37
  135. package/dist/lock/contracts/lock.events.js +2 -2
  136. package/dist/lock/contracts/lock.events.js.map +1 -1
  137. package/dist/lock/contracts/types.d.ts +11 -0
  138. package/dist/lock/contracts/types.js +5 -0
  139. package/dist/lock/contracts/types.js.map +1 -0
  140. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +33 -13
  141. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +182 -56
  142. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
  143. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +25 -9
  144. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +80 -36
  145. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
  146. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +11 -12
  147. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +164 -79
  148. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
  149. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +7 -6
  150. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +7 -4
  151. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -1
  152. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +27 -9
  153. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +87 -32
  154. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
  155. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +7 -6
  156. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +56 -24
  157. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
  158. package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.d.ts +2 -2
  159. package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js +7 -7
  160. package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +1 -1
  161. package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +29 -39
  162. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +31 -35
  163. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
  164. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +5 -8
  165. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +27 -23
  166. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
  167. package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +38 -33
  168. package/dist/lock/implementations/derivables/lock-provider/lock.js +178 -234
  169. package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
  170. package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.d.ts +9 -0
  171. package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.js +12 -0
  172. package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.js.map +1 -0
  173. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +12 -13
  174. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +7 -16
  175. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
  176. package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +312 -191
  177. package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
  178. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +1 -1
  179. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +378 -95
  180. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
  181. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +15 -5
  182. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +3110 -1611
  183. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
  184. package/dist/namespace/_module-exports.d.ts +1 -0
  185. package/dist/namespace/_module-exports.js +2 -0
  186. package/dist/namespace/_module-exports.js.map +1 -0
  187. package/dist/namespace/namespace.d.ts +87 -0
  188. package/dist/namespace/namespace.js +117 -0
  189. package/dist/namespace/namespace.js.map +1 -0
  190. package/dist/resilience/_module-exports.d.ts +2 -0
  191. package/dist/resilience/_module-exports.js +3 -0
  192. package/dist/resilience/_module-exports.js.map +1 -0
  193. package/dist/resilience/middlewares/_module.d.ts +5 -0
  194. package/dist/resilience/middlewares/_module.js +6 -0
  195. package/dist/resilience/middlewares/_module.js.map +1 -0
  196. package/dist/resilience/middlewares/dynamic/_module.d.ts +1 -0
  197. package/dist/resilience/middlewares/dynamic/_module.js +2 -0
  198. package/dist/resilience/middlewares/dynamic/_module.js.map +1 -0
  199. package/dist/{async → resilience}/middlewares/dynamic/dynamic.middleware.d.ts +6 -6
  200. package/dist/{async → resilience}/middlewares/dynamic/dynamic.middleware.js +5 -5
  201. package/dist/resilience/middlewares/dynamic/dynamic.middleware.js.map +1 -0
  202. package/dist/resilience/middlewares/fallback/_module.d.ts +2 -0
  203. package/dist/resilience/middlewares/fallback/_module.js +3 -0
  204. package/dist/resilience/middlewares/fallback/_module.js.map +1 -0
  205. package/dist/{async → resilience}/middlewares/fallback/fallback.middleware.d.ts +9 -9
  206. package/dist/{async → resilience}/middlewares/fallback/fallback.middleware.js +7 -6
  207. package/dist/resilience/middlewares/fallback/fallback.middleware.js.map +1 -0
  208. package/dist/{async → resilience}/middlewares/fallback/fallback.types.d.ts +7 -6
  209. package/dist/{async → resilience}/middlewares/fallback/fallback.types.js +1 -1
  210. package/dist/resilience/middlewares/fallback/fallback.types.js.map +1 -0
  211. package/dist/resilience/middlewares/observe/_module.d.ts +2 -0
  212. package/dist/resilience/middlewares/observe/_module.js +3 -0
  213. package/dist/resilience/middlewares/observe/_module.js.map +1 -0
  214. package/dist/{async → resilience}/middlewares/observe/observe.middleware.d.ts +13 -11
  215. package/dist/{async → resilience}/middlewares/observe/observe.middleware.js +14 -10
  216. package/dist/resilience/middlewares/observe/observe.middleware.js.map +1 -0
  217. package/dist/{async → resilience}/middlewares/observe/observe.types.d.ts +13 -12
  218. package/dist/resilience/middlewares/observe/observe.types.js +5 -0
  219. package/dist/resilience/middlewares/observe/observe.types.js.map +1 -0
  220. package/dist/resilience/middlewares/retry/_module.d.ts +2 -0
  221. package/dist/resilience/middlewares/retry/_module.js +3 -0
  222. package/dist/resilience/middlewares/retry/_module.js.map +1 -0
  223. package/dist/{async → resilience}/middlewares/retry/retry.middleware.d.ts +12 -9
  224. package/dist/{async → resilience}/middlewares/retry/retry.middleware.js +19 -15
  225. package/dist/resilience/middlewares/retry/retry.middleware.js.map +1 -0
  226. package/dist/{async → resilience}/middlewares/retry/retry.types.d.ts +14 -12
  227. package/dist/resilience/middlewares/retry/retry.types.js +7 -0
  228. package/dist/resilience/middlewares/retry/retry.types.js.map +1 -0
  229. package/dist/resilience/middlewares/timeout/_module.d.ts +2 -0
  230. package/dist/resilience/middlewares/timeout/_module.js +3 -0
  231. package/dist/resilience/middlewares/timeout/_module.js.map +1 -0
  232. package/dist/{async → resilience}/middlewares/timeout/timeout.middleware.d.ts +9 -7
  233. package/dist/{async → resilience}/middlewares/timeout/timeout.middleware.js +12 -11
  234. package/dist/resilience/middlewares/timeout/timeout.middleware.js.map +1 -0
  235. package/dist/{async → resilience}/middlewares/timeout/timeout.type.d.ts +10 -9
  236. package/dist/resilience/middlewares/timeout/timeout.type.js +5 -0
  237. package/dist/resilience/middlewares/timeout/timeout.type.js.map +1 -0
  238. package/dist/resilience/resilience.errors.d.ts +40 -0
  239. package/dist/resilience/resilience.errors.js +48 -0
  240. package/dist/resilience/resilience.errors.js.map +1 -0
  241. package/dist/resilience/utilities/_module.d.ts +2 -0
  242. package/dist/resilience/utilities/_module.js +3 -0
  243. package/dist/resilience/utilities/_module.js.map +1 -0
  244. package/dist/resilience/utilities/abort-and-fail/_module.d.ts +1 -0
  245. package/dist/resilience/utilities/abort-and-fail/_module.js +2 -0
  246. package/dist/resilience/utilities/abort-and-fail/_module.js.map +1 -0
  247. package/dist/resilience/utilities/abort-and-fail/abort-and-fail.d.ts +7 -0
  248. package/dist/resilience/utilities/abort-and-fail/abort-and-fail.js +51 -0
  249. package/dist/resilience/utilities/abort-and-fail/abort-and-fail.js.map +1 -0
  250. package/dist/resilience/utilities/timeout-and-fail/_module.d.ts +1 -0
  251. package/dist/resilience/utilities/timeout-and-fail/_module.js +2 -0
  252. package/dist/resilience/utilities/timeout-and-fail/_module.js.map +1 -0
  253. package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.d.ts +7 -0
  254. package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.js +23 -0
  255. package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -0
  256. package/dist/semaphore/contracts/_module-exports.d.ts +9 -0
  257. package/dist/semaphore/contracts/_module-exports.js +10 -0
  258. package/dist/semaphore/contracts/_module-exports.js.map +1 -0
  259. package/dist/semaphore/contracts/database-semaphore-adapter.contract.d.ts +90 -0
  260. package/dist/semaphore/contracts/database-semaphore-adapter.contract.js +5 -0
  261. package/dist/semaphore/contracts/database-semaphore-adapter.contract.js.map +1 -0
  262. package/dist/semaphore/contracts/semaphore-adapter.contract.d.ts +61 -0
  263. package/dist/semaphore/contracts/semaphore-adapter.contract.js +5 -0
  264. package/dist/semaphore/contracts/semaphore-adapter.contract.js.map +1 -0
  265. package/dist/semaphore/contracts/semaphore-provider-factory.contract.d.ts +19 -0
  266. package/dist/semaphore/contracts/semaphore-provider-factory.contract.js +9 -0
  267. package/dist/semaphore/contracts/semaphore-provider-factory.contract.js.map +1 -0
  268. package/dist/semaphore/contracts/semaphore-provider.contract.d.ts +50 -0
  269. package/dist/semaphore/contracts/semaphore-provider.contract.js +5 -0
  270. package/dist/semaphore/contracts/semaphore-provider.contract.js.map +1 -0
  271. package/dist/semaphore/contracts/semaphore-state.contract.d.ts +70 -0
  272. package/dist/semaphore/contracts/semaphore-state.contract.js +15 -0
  273. package/dist/semaphore/contracts/semaphore-state.contract.js.map +1 -0
  274. package/dist/semaphore/contracts/semaphore.contract.d.ts +127 -0
  275. package/dist/semaphore/contracts/semaphore.contract.js +5 -0
  276. package/dist/semaphore/contracts/semaphore.contract.js.map +1 -0
  277. package/dist/semaphore/contracts/semaphore.errors.d.ts +52 -0
  278. package/dist/semaphore/contracts/semaphore.errors.js +63 -0
  279. package/dist/semaphore/contracts/semaphore.errors.js.map +1 -0
  280. package/dist/semaphore/contracts/semaphore.events.d.ts +101 -0
  281. package/dist/semaphore/contracts/semaphore.events.js +19 -0
  282. package/dist/semaphore/contracts/semaphore.events.js.map +1 -0
  283. package/dist/semaphore/contracts/types.d.ts +11 -0
  284. package/dist/semaphore/contracts/types.js +5 -0
  285. package/dist/semaphore/contracts/types.js.map +1 -0
  286. package/dist/semaphore/implementations/adapters/_module-exports.d.ts +5 -0
  287. package/dist/semaphore/implementations/adapters/_module-exports.js +6 -0
  288. package/dist/semaphore/implementations/adapters/_module-exports.js.map +1 -0
  289. package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.d.ts +1 -0
  290. package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.js +2 -0
  291. package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.js.map +1 -0
  292. package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.d.ts +97 -0
  293. package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js +313 -0
  294. package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js.map +1 -0
  295. package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.d.ts +1 -0
  296. package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.js +2 -0
  297. package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.js.map +1 -0
  298. package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.d.ts +49 -0
  299. package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js +141 -0
  300. package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js.map +1 -0
  301. package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.d.ts +1 -0
  302. package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.js +2 -0
  303. package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.js.map +1 -0
  304. package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.d.ts +80 -0
  305. package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.js +390 -0
  306. package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.js.map +1 -0
  307. package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.d.ts +1 -0
  308. package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.js +2 -0
  309. package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.js.map +1 -0
  310. package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.d.ts +18 -0
  311. package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js +30 -0
  312. package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js.map +1 -0
  313. package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.d.ts +1 -0
  314. package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.js +2 -0
  315. package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.js.map +1 -0
  316. package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.d.ts +48 -0
  317. package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.js +338 -0
  318. package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.js.map +1 -0
  319. package/dist/semaphore/implementations/derivables/_module-exports.d.ts +2 -0
  320. package/dist/semaphore/implementations/derivables/_module-exports.js +3 -0
  321. package/dist/semaphore/implementations/derivables/_module-exports.js.map +1 -0
  322. package/dist/semaphore/implementations/derivables/semaphore-provider/_module.d.ts +1 -0
  323. package/dist/semaphore/implementations/derivables/semaphore-provider/_module.js +2 -0
  324. package/dist/semaphore/implementations/derivables/semaphore-provider/_module.js.map +1 -0
  325. package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.d.ts +17 -0
  326. package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.js +74 -0
  327. package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.js.map +1 -0
  328. package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.d.ts +8 -0
  329. package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.js +15 -0
  330. package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.js.map +1 -0
  331. package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.d.ts +8 -0
  332. package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.js +15 -0
  333. package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.js.map +1 -0
  334. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.d.ts +149 -0
  335. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js +135 -0
  336. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +1 -0
  337. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.d.ts +41 -0
  338. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js +77 -0
  339. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +1 -0
  340. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.d.ts +83 -0
  341. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js +336 -0
  342. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +1 -0
  343. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.d.ts +1 -0
  344. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.js +2 -0
  345. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.js.map +1 -0
  346. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.d.ts +40 -0
  347. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js +67 -0
  348. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +1 -0
  349. package/dist/semaphore/implementations/test-utilities/_module-exports.d.ts +3 -0
  350. package/dist/semaphore/implementations/test-utilities/_module-exports.js +4 -0
  351. package/dist/semaphore/implementations/test-utilities/_module-exports.js.map +1 -0
  352. package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.d.ts +59 -0
  353. package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js +536 -0
  354. package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js.map +1 -0
  355. package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.d.ts +59 -0
  356. package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js +961 -0
  357. package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js.map +1 -0
  358. package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.d.ts +67 -0
  359. package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js +4981 -0
  360. package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js.map +1 -0
  361. package/dist/serde/contracts/_module-exports.d.ts +0 -1
  362. package/dist/serde/contracts/_module-exports.js +0 -1
  363. package/dist/serde/contracts/_module-exports.js.map +1 -1
  364. package/dist/serde/contracts/flexible-serde.contract.d.ts +21 -5
  365. package/dist/serde/contracts/serde.errors.d.ts +14 -11
  366. package/dist/serde/contracts/serde.errors.js +15 -14
  367. package/dist/serde/contracts/serde.errors.js.map +1 -1
  368. package/dist/serde/implementations/adapters/_module-exports.d.ts +0 -3
  369. package/dist/serde/implementations/adapters/_module-exports.js +0 -3
  370. package/dist/serde/implementations/adapters/_module-exports.js.map +1 -1
  371. package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +6 -0
  372. package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js.map +1 -1
  373. package/dist/serde/implementations/derivables/serde-transformers.d.ts +38 -30
  374. package/dist/serde/implementations/derivables/serde-transformers.js +62 -20
  375. package/dist/serde/implementations/derivables/serde-transformers.js.map +1 -1
  376. package/dist/serde/implementations/derivables/serde.d.ts +12 -3
  377. package/dist/serde/implementations/derivables/serde.js +5 -2
  378. package/dist/serde/implementations/derivables/serde.js.map +1 -1
  379. package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +85 -1
  380. package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js.map +1 -1
  381. package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +85 -1
  382. package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js.map +1 -1
  383. package/dist/shared-lock/contracts/_module-exports.d.ts +10 -0
  384. package/dist/shared-lock/contracts/_module-exports.js +11 -0
  385. package/dist/shared-lock/contracts/_module-exports.js.map +1 -0
  386. package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.d.ts +145 -0
  387. package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.js +5 -0
  388. package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.js.map +1 -0
  389. package/dist/shared-lock/contracts/shared-lock-adapter.contract.d.ts +96 -0
  390. package/dist/shared-lock/contracts/shared-lock-adapter.contract.js +5 -0
  391. package/dist/shared-lock/contracts/shared-lock-adapter.contract.js.map +1 -0
  392. package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.d.ts +19 -0
  393. package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.js +9 -0
  394. package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.js.map +1 -0
  395. package/dist/shared-lock/contracts/shared-lock-provider.contract.d.ts +53 -0
  396. package/dist/shared-lock/contracts/shared-lock-provider.contract.js +5 -0
  397. package/dist/shared-lock/contracts/shared-lock-provider.contract.js.map +1 -0
  398. package/dist/shared-lock/contracts/shared-lock-state.contract.d.ts +133 -0
  399. package/dist/shared-lock/contracts/shared-lock-state.contract.js +33 -0
  400. package/dist/shared-lock/contracts/shared-lock-state.contract.js.map +1 -0
  401. package/dist/shared-lock/contracts/shared-lock.contract.d.ts +222 -0
  402. package/dist/shared-lock/contracts/shared-lock.contract.js +13 -0
  403. package/dist/shared-lock/contracts/shared-lock.contract.js.map +1 -0
  404. package/dist/shared-lock/contracts/shared-lock.errors.d.ts +124 -0
  405. package/dist/shared-lock/contracts/shared-lock.errors.js +136 -0
  406. package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -0
  407. package/dist/shared-lock/contracts/shared-lock.events.d.ts +205 -0
  408. package/dist/shared-lock/contracts/shared-lock.events.js +43 -0
  409. package/dist/shared-lock/contracts/shared-lock.events.js.map +1 -0
  410. package/dist/shared-lock/contracts/types.d.ts +10 -0
  411. package/dist/shared-lock/contracts/types.js +5 -0
  412. package/dist/shared-lock/contracts/types.js.map +1 -0
  413. package/dist/shared-lock/implementations/adapters/_module-exports.d.ts +5 -0
  414. package/dist/shared-lock/implementations/adapters/_module-exports.js +6 -0
  415. package/dist/shared-lock/implementations/adapters/_module-exports.js.map +1 -0
  416. package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.d.ts +1 -0
  417. package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.js +2 -0
  418. package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.js.map +1 -0
  419. package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.d.ts +114 -0
  420. package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js +496 -0
  421. package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js.map +1 -0
  422. package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.d.ts +1 -0
  423. package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.js +2 -0
  424. package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.js.map +1 -0
  425. package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.d.ts +79 -0
  426. package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js +347 -0
  427. package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js.map +1 -0
  428. package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.d.ts +1 -0
  429. package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.js +2 -0
  430. package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.js.map +1 -0
  431. package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.d.ts +112 -0
  432. package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.js +805 -0
  433. package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.js.map +1 -0
  434. package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.d.ts +1 -0
  435. package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.js +2 -0
  436. package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.js.map +1 -0
  437. package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.d.ts +23 -0
  438. package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js +42 -0
  439. package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js.map +1 -0
  440. package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.d.ts +1 -0
  441. package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.js +2 -0
  442. package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.js.map +1 -0
  443. package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.d.ts +79 -0
  444. package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.js +630 -0
  445. package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.js.map +1 -0
  446. package/dist/shared-lock/implementations/derivables/_module-exports.d.ts +2 -0
  447. package/dist/shared-lock/implementations/derivables/_module-exports.js +3 -0
  448. package/dist/shared-lock/implementations/derivables/_module-exports.js.map +1 -0
  449. package/dist/shared-lock/implementations/derivables/shared-lock-provider/_module.d.ts +1 -0
  450. package/dist/shared-lock/implementations/derivables/shared-lock-provider/_module.js +2 -0
  451. package/dist/shared-lock/implementations/derivables/shared-lock-provider/_module.js.map +1 -0
  452. package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.d.ts +27 -0
  453. package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.js +208 -0
  454. package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.js.map +1 -0
  455. package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.d.ts +8 -0
  456. package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.js +12 -0
  457. package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.js.map +1 -0
  458. package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.d.ts +8 -0
  459. package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.js +15 -0
  460. package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.js.map +1 -0
  461. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.d.ts +190 -0
  462. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js +177 -0
  463. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +1 -0
  464. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.d.ts +41 -0
  465. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js +77 -0
  466. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +1 -0
  467. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.d.ts +95 -0
  468. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js +542 -0
  469. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +1 -0
  470. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/_module.d.ts +1 -0
  471. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/_module.js +2 -0
  472. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/_module.js.map +1 -0
  473. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.d.ts +97 -0
  474. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js +128 -0
  475. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +1 -0
  476. package/dist/shared-lock/implementations/test-utilities/_module-exports.d.ts +3 -0
  477. package/dist/shared-lock/implementations/test-utilities/_module-exports.js +4 -0
  478. package/dist/shared-lock/implementations/test-utilities/_module-exports.js.map +1 -0
  479. package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.d.ts +59 -0
  480. package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js +944 -0
  481. package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js.map +1 -0
  482. package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.d.ts +59 -0
  483. package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js +1921 -0
  484. package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js.map +1 -0
  485. package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.d.ts +67 -0
  486. package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js +9833 -0
  487. package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js.map +1 -0
  488. package/dist/task/_module-exports.d.ts +1 -0
  489. package/dist/task/_module-exports.js +2 -0
  490. package/dist/task/_module-exports.js.map +1 -0
  491. package/dist/{async/utilities/abort-and-fail → task}/abort-and-fail.d.ts +1 -1
  492. package/dist/{async/utilities/abort-and-fail → task}/abort-and-fail.js +1 -1
  493. package/dist/task/abort-and-fail.js.map +1 -0
  494. package/dist/task/task.d.ts +194 -0
  495. package/dist/task/task.js +212 -0
  496. package/dist/task/task.js.map +1 -0
  497. package/dist/time-span/contracts/_module-exports.d.ts +1 -0
  498. package/dist/time-span/contracts/_module-exports.js +2 -0
  499. package/dist/time-span/contracts/_module-exports.js.map +1 -0
  500. package/dist/time-span/contracts/time-span.contract.d.ts +19 -0
  501. package/dist/time-span/contracts/time-span.contract.js +10 -0
  502. package/dist/time-span/contracts/time-span.contract.js.map +1 -0
  503. package/dist/time-span/implementations/_module-exports.d.ts +1 -0
  504. package/dist/time-span/implementations/_module-exports.js +2 -0
  505. package/dist/time-span/implementations/_module-exports.js.map +1 -0
  506. package/dist/{utilities/classes/time-span → time-span/implementations}/time-span.d.ts +49 -11
  507. package/dist/{utilities/classes/time-span → time-span/implementations}/time-span.js +33 -11
  508. package/dist/time-span/implementations/time-span.js.map +1 -0
  509. package/dist/utilities/classes/_module.d.ts +0 -3
  510. package/dist/utilities/classes/_module.js +0 -3
  511. package/dist/utilities/classes/_module.js.map +1 -1
  512. package/dist/utilities/contracts/_module.d.ts +1 -1
  513. package/dist/utilities/contracts/_module.js +1 -1
  514. package/dist/utilities/contracts/_module.js.map +1 -1
  515. package/dist/utilities/contracts/comparable.contract.d.ts +49 -0
  516. package/dist/utilities/contracts/comparable.contract.js +5 -0
  517. package/dist/utilities/contracts/comparable.contract.js.map +1 -0
  518. package/dist/utilities/contracts/deinitizable.contract.d.ts +1 -1
  519. package/dist/utilities/contracts/initizable.contract.d.ts +1 -1
  520. package/dist/utilities/contracts/prunable.contract.d.ts +1 -1
  521. package/dist/utilities/functions/is-standard-schema.d.ts +6 -0
  522. package/dist/utilities/functions/is-standard-schema.js +6 -0
  523. package/dist/utilities/functions/is-standard-schema.js.map +1 -1
  524. package/dist/utilities/functions/lazy.d.ts +3 -3
  525. package/dist/utilities/functions/lazy.js +3 -3
  526. package/dist/utilities/functions/lazy.js.map +1 -1
  527. package/dist/utilities/functions/option.d.ts +3 -0
  528. package/dist/utilities/functions/option.js +3 -0
  529. package/dist/utilities/functions/option.js.map +1 -1
  530. package/dist/utilities/functions/validate.d.ts +5 -0
  531. package/dist/utilities/functions/validate.js +5 -0
  532. package/dist/utilities/functions/validate.js.map +1 -1
  533. package/dist/utilities/types/any-class.type.d.ts +6 -0
  534. package/dist/utilities/types/any-class.type.js +3 -0
  535. package/dist/utilities/types/any-class.type.js.map +1 -1
  536. package/package.json +67 -5
  537. package/dist/async/_module-exports.d.ts +0 -4
  538. package/dist/async/_module-exports.js +0 -5
  539. package/dist/async/_module-exports.js.map +0 -1
  540. package/dist/async/async.errors.d.ts +0 -47
  541. package/dist/async/async.errors.js +0 -61
  542. package/dist/async/async.errors.js.map +0 -1
  543. package/dist/async/backof-policies/_module.d.ts +0 -5
  544. package/dist/async/backof-policies/_module.js +0 -6
  545. package/dist/async/backof-policies/_module.js.map +0 -1
  546. package/dist/async/backof-policies/_shared.js.map +0 -1
  547. package/dist/async/backof-policies/constant-backoff-policy/_module.d.ts +0 -1
  548. package/dist/async/backof-policies/constant-backoff-policy/_module.js +0 -2
  549. package/dist/async/backof-policies/constant-backoff-policy/_module.js.map +0 -1
  550. package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.js.map +0 -1
  551. package/dist/async/backof-policies/exponential-backoff-policy/_module.d.ts +0 -1
  552. package/dist/async/backof-policies/exponential-backoff-policy/_module.js +0 -2
  553. package/dist/async/backof-policies/exponential-backoff-policy/_module.js.map +0 -1
  554. package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js +0 -35
  555. package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js.map +0 -1
  556. package/dist/async/backof-policies/linear-backoff-policy/_module.d.ts +0 -1
  557. package/dist/async/backof-policies/linear-backoff-policy/_module.js +0 -2
  558. package/dist/async/backof-policies/linear-backoff-policy/_module.js.map +0 -1
  559. package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js +0 -35
  560. package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js.map +0 -1
  561. package/dist/async/backof-policies/polynomial-backoff-policy/_module.d.ts +0 -1
  562. package/dist/async/backof-policies/polynomial-backoff-policy/_module.js +0 -2
  563. package/dist/async/backof-policies/polynomial-backoff-policy/_module.js.map +0 -1
  564. package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +0 -35
  565. package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js.map +0 -1
  566. package/dist/async/middlewares/_module.d.ts +0 -7
  567. package/dist/async/middlewares/_module.js +0 -8
  568. package/dist/async/middlewares/_module.js.map +0 -1
  569. package/dist/async/middlewares/bulkhead/_module.d.ts +0 -1
  570. package/dist/async/middlewares/bulkhead/_module.js +0 -2
  571. package/dist/async/middlewares/bulkhead/_module.js.map +0 -1
  572. package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +0 -80
  573. package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +0 -46
  574. package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +0 -1
  575. package/dist/async/middlewares/dynamic/_module.d.ts +0 -1
  576. package/dist/async/middlewares/dynamic/_module.js +0 -2
  577. package/dist/async/middlewares/dynamic/_module.js.map +0 -1
  578. package/dist/async/middlewares/dynamic/dynamic.middleware.js.map +0 -1
  579. package/dist/async/middlewares/fallback/_module.d.ts +0 -2
  580. package/dist/async/middlewares/fallback/_module.js +0 -3
  581. package/dist/async/middlewares/fallback/_module.js.map +0 -1
  582. package/dist/async/middlewares/fallback/fallback.middleware.js.map +0 -1
  583. package/dist/async/middlewares/fallback/fallback.types.js.map +0 -1
  584. package/dist/async/middlewares/hedging/_module.d.ts +0 -2
  585. package/dist/async/middlewares/hedging/_module.js +0 -3
  586. package/dist/async/middlewares/hedging/_module.js.map +0 -1
  587. package/dist/async/middlewares/hedging/hedging.types.d.ts +0 -121
  588. package/dist/async/middlewares/hedging/hedging.types.js +0 -6
  589. package/dist/async/middlewares/hedging/hedging.types.js.map +0 -1
  590. package/dist/async/middlewares/hedging/sequential-hedging.middleware.d.ts +0 -51
  591. package/dist/async/middlewares/hedging/sequential-hedging.middleware.js +0 -133
  592. package/dist/async/middlewares/hedging/sequential-hedging.middleware.js.map +0 -1
  593. package/dist/async/middlewares/observe/_module.d.ts +0 -2
  594. package/dist/async/middlewares/observe/_module.js +0 -3
  595. package/dist/async/middlewares/observe/_module.js.map +0 -1
  596. package/dist/async/middlewares/observe/observe.middleware.js.map +0 -1
  597. package/dist/async/middlewares/observe/observe.types.js +0 -6
  598. package/dist/async/middlewares/observe/observe.types.js.map +0 -1
  599. package/dist/async/middlewares/retry/_module.d.ts +0 -2
  600. package/dist/async/middlewares/retry/_module.js +0 -3
  601. package/dist/async/middlewares/retry/_module.js.map +0 -1
  602. package/dist/async/middlewares/retry/retry.middleware.js.map +0 -1
  603. package/dist/async/middlewares/retry/retry.types.js +0 -7
  604. package/dist/async/middlewares/retry/retry.types.js.map +0 -1
  605. package/dist/async/middlewares/timeout/_module.d.ts +0 -2
  606. package/dist/async/middlewares/timeout/_module.js +0 -3
  607. package/dist/async/middlewares/timeout/_module.js.map +0 -1
  608. package/dist/async/middlewares/timeout/timeout.middleware.js.map +0 -1
  609. package/dist/async/middlewares/timeout/timeout.type.js +0 -6
  610. package/dist/async/middlewares/timeout/timeout.type.js.map +0 -1
  611. package/dist/async/utilities/_module.d.ts +0 -4
  612. package/dist/async/utilities/_module.js +0 -5
  613. package/dist/async/utilities/_module.js.map +0 -1
  614. package/dist/async/utilities/abort-and-fail/_module.d.ts +0 -1
  615. package/dist/async/utilities/abort-and-fail/_module.js +0 -2
  616. package/dist/async/utilities/abort-and-fail/_module.js.map +0 -1
  617. package/dist/async/utilities/abort-and-fail/abort-and-fail.js.map +0 -1
  618. package/dist/async/utilities/lazy-promise/_module.d.ts +0 -1
  619. package/dist/async/utilities/lazy-promise/_module.js +0 -2
  620. package/dist/async/utilities/lazy-promise/_module.js.map +0 -1
  621. package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +0 -153
  622. package/dist/async/utilities/lazy-promise/lazy-promise.js +0 -176
  623. package/dist/async/utilities/lazy-promise/lazy-promise.js.map +0 -1
  624. package/dist/async/utilities/promise-queue/_module.d.ts +0 -1
  625. package/dist/async/utilities/promise-queue/_module.js +0 -2
  626. package/dist/async/utilities/promise-queue/_module.js.map +0 -1
  627. package/dist/async/utilities/promise-queue/promise-queue.d.ts +0 -32
  628. package/dist/async/utilities/promise-queue/promise-queue.js +0 -118
  629. package/dist/async/utilities/promise-queue/promise-queue.js.map +0 -1
  630. package/dist/async/utilities/timeout-and-fail/_module.d.ts +0 -1
  631. package/dist/async/utilities/timeout-and-fail/_module.js +0 -2
  632. package/dist/async/utilities/timeout-and-fail/_module.js.map +0 -1
  633. package/dist/async/utilities/timeout-and-fail/timeout-and-fail.d.ts +0 -7
  634. package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js +0 -22
  635. package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js.map +0 -1
  636. package/dist/lock/implementations/derivables/lock-provider/lock-state.d.ts +0 -40
  637. package/dist/lock/implementations/derivables/lock-provider/lock-state.js +0 -60
  638. package/dist/lock/implementations/derivables/lock-provider/lock-state.js.map +0 -1
  639. package/dist/serde/contracts/serializable.contract.d.ts +0 -12
  640. package/dist/serde/contracts/serializable.contract.js +0 -5
  641. package/dist/serde/contracts/serializable.contract.js.map +0 -1
  642. package/dist/serde/implementations/adapters/mongodb-serde/_module.d.ts +0 -1
  643. package/dist/serde/implementations/adapters/mongodb-serde/_module.js +0 -2
  644. package/dist/serde/implementations/adapters/mongodb-serde/_module.js.map +0 -1
  645. package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.d.ts +0 -13
  646. package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js +0 -38
  647. package/dist/serde/implementations/adapters/mongodb-serde/mongodb-serde.js.map +0 -1
  648. package/dist/serde/implementations/adapters/redis-serde/_module.d.ts +0 -1
  649. package/dist/serde/implementations/adapters/redis-serde/_module.js +0 -2
  650. package/dist/serde/implementations/adapters/redis-serde/_module.js.map +0 -1
  651. package/dist/serde/implementations/adapters/redis-serde/redis-serde.d.ts +0 -13
  652. package/dist/serde/implementations/adapters/redis-serde/redis-serde.js +0 -39
  653. package/dist/serde/implementations/adapters/redis-serde/redis-serde.js.map +0 -1
  654. package/dist/serde/implementations/adapters/sql-serde/_module.d.ts +0 -1
  655. package/dist/serde/implementations/adapters/sql-serde/_module.js +0 -2
  656. package/dist/serde/implementations/adapters/sql-serde/_module.js.map +0 -1
  657. package/dist/serde/implementations/adapters/sql-serde/sql-serde.d.ts +0 -13
  658. package/dist/serde/implementations/adapters/sql-serde/sql-serde.js +0 -39
  659. package/dist/serde/implementations/adapters/sql-serde/sql-serde.js.map +0 -1
  660. package/dist/utilities/classes/hooks/_module.d.ts +0 -3
  661. package/dist/utilities/classes/hooks/_module.js +0 -4
  662. package/dist/utilities/classes/hooks/_module.js.map +0 -1
  663. package/dist/utilities/classes/hooks/async-hooks.js.map +0 -1
  664. package/dist/utilities/classes/hooks/hooks.js.map +0 -1
  665. package/dist/utilities/classes/hooks/types.js +0 -5
  666. package/dist/utilities/classes/hooks/types.js.map +0 -1
  667. package/dist/utilities/classes/namespace/_module.d.ts +0 -1
  668. package/dist/utilities/classes/namespace/_module.js +0 -2
  669. package/dist/utilities/classes/namespace/_module.js.map +0 -1
  670. package/dist/utilities/classes/namespace/namespace.d.ts +0 -85
  671. package/dist/utilities/classes/namespace/namespace.js +0 -125
  672. package/dist/utilities/classes/namespace/namespace.js.map +0 -1
  673. package/dist/utilities/classes/time-span/_module.d.ts +0 -1
  674. package/dist/utilities/classes/time-span/_module.js +0 -2
  675. package/dist/utilities/classes/time-span/_module.js.map +0 -1
  676. package/dist/utilities/classes/time-span/time-span.js.map +0 -1
  677. package/dist/utilities/contracts/serialized-error.contract.d.ts +0 -13
  678. package/dist/utilities/contracts/serialized-error.contract.js +0 -5
  679. package/dist/utilities/contracts/serialized-error.contract.js.map +0 -1
@@ -1,26 +1,27 @@
1
1
  /**
2
2
  * @module Lock
3
3
  */
4
- import type { IDatabaseLockAdapter, ILockData } from "../../../../lock/contracts/_module-exports.js";
5
- import type { Kysely } from "kysely";
6
- import { type IDeinitizable, type IInitizable, type IPrunable, TimeSpan } from "../../../../utilities/_module-exports.js";
4
+ import type { IDatabaseLockAdapter, IDatabaseLockTransaction, ILockData, ILockExpirationData } from "../../../../lock/contracts/_module-exports.js";
5
+ import { type Kysely } from "kysely";
6
+ import { type IDeinitizable, type IInitizable, type InvokableFn, type IPrunable } from "../../../../utilities/_module-exports.js";
7
+ import { TimeSpan } from "../../../../time-span/implementations/_module-exports.js";
7
8
  /**
8
9
  *
9
10
  * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
10
11
  * @group Adapters
11
12
  */
12
- export type KyselyLockAdapterTable = {
13
+ export type KyselyLockTable = {
13
14
  key: string;
14
15
  owner: string;
15
- expiresAt: number | string | null;
16
+ expiration: number | bigint | string | null;
16
17
  };
17
18
  /**
18
19
  *
19
20
  * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
20
21
  * @group Adapters
21
22
  */
22
- export type KyselyLockAdapterTables = {
23
- lock: KyselyLockAdapterTable;
23
+ export type KyselyLockTables = {
24
+ lock: KyselyLockTable;
24
25
  };
25
26
  /**
26
27
  *
@@ -28,7 +29,7 @@ export type KyselyLockAdapterTables = {
28
29
  * @group Adapters
29
30
  */
30
31
  export type KyselyLockAdapterSettings = {
31
- kysely: Kysely<KyselyLockAdapterTables>;
32
+ kysely: Kysely<KyselyLockTables>;
32
33
  /**
33
34
  * @default
34
35
  * ```ts
@@ -40,6 +41,13 @@ export type KyselyLockAdapterSettings = {
40
41
  * @default true
41
42
  */
42
43
  shouldRemoveExpiredKeys?: boolean;
44
+ /**
45
+ * @default
46
+ * ```ts
47
+ * () => new Date()
48
+ * ```
49
+ */
50
+ currentDate?: () => Date;
43
51
  };
44
52
  /**
45
53
  * To utilize the `KyselyLockAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
@@ -54,7 +62,9 @@ export declare class KyselyLockAdapter implements IDatabaseLockAdapter, IDeiniti
54
62
  private readonly kysely;
55
63
  private readonly expiredKeysRemovalInterval;
56
64
  private readonly shouldRemoveExpiredKeys;
57
- private timeoutId;
65
+ private intervalId;
66
+ private readonly currentDate;
67
+ private readonly isMysql;
58
68
  /**
59
69
  * @example
60
70
  * ```ts
@@ -73,12 +83,22 @@ export declare class KyselyLockAdapter implements IDatabaseLockAdapter, IDeiniti
73
83
  * ```
74
84
  */
75
85
  constructor(settings: KyselyLockAdapterSettings);
86
+ /**
87
+ * Removes all related lock tables and their rows.
88
+ * Note all lock data will be removed.
89
+ */
76
90
  deInit(): Promise<void>;
91
+ /**
92
+ * Creates all related tables and indexes.
93
+ * Note the `init` method needs to be called once before using the adapter.
94
+ */
77
95
  init(): Promise<void>;
78
96
  removeAllExpired(): Promise<void>;
79
- insert(key: string, owner: string, expiration: Date | null): Promise<void>;
80
- update(key: string, owner: string, expiration: Date | null): Promise<number>;
81
- remove(key: string, owner: string | null): Promise<void>;
82
- refresh(key: string, owner: string, expiration: Date): Promise<number>;
97
+ transaction<TReturn>(fn: InvokableFn<[
98
+ transaction: IDatabaseLockTransaction
99
+ ], Promise<TReturn>>): Promise<TReturn>;
100
+ remove(key: string): Promise<ILockExpirationData | null>;
101
+ removeIfOwner(key: string, lockId: string): Promise<ILockData | null>;
102
+ updateExpiration(key: string, lockId: string, expiration: Date): Promise<number>;
83
103
  find(key: string): Promise<ILockData | null>;
84
104
  }
@@ -1,7 +1,65 @@
1
1
  /**
2
2
  * @module Lock
3
3
  */
4
- import { TimeSpan, } from "../../../../utilities/_module-exports.js";
4
+ import { MysqlAdapter } from "kysely";
5
+ import {} from "../../../../utilities/_module-exports.js";
6
+ import { TimeSpan } from "../../../../time-span/implementations/_module-exports.js";
7
+ async function find(kysely, key) {
8
+ const row = await kysely
9
+ .selectFrom("lock")
10
+ .where("lock.key", "=", key)
11
+ .select(["lock.owner", "lock.expiration"])
12
+ .executeTakeFirst();
13
+ if (row === undefined) {
14
+ return null;
15
+ }
16
+ if (row.expiration === null) {
17
+ return {
18
+ owner: row.owner,
19
+ expiration: null,
20
+ };
21
+ }
22
+ return {
23
+ owner: row.owner,
24
+ expiration: new Date(Number(row.expiration)),
25
+ };
26
+ }
27
+ /**
28
+ * @internal
29
+ */
30
+ class DatabaseLockTransaction {
31
+ kysely;
32
+ isMysql;
33
+ constructor(kysely) {
34
+ this.kysely = kysely;
35
+ this.isMysql =
36
+ this.kysely.getExecutor().adapter instanceof MysqlAdapter;
37
+ }
38
+ async find(key) {
39
+ return await find(this.kysely, key);
40
+ }
41
+ async upsert(key, lockId, expiration) {
42
+ const expirationAsMs = expiration?.getTime() ?? null;
43
+ await this.kysely
44
+ .insertInto("lock")
45
+ .values({
46
+ key,
47
+ owner: lockId,
48
+ expiration: expirationAsMs,
49
+ })
50
+ .$if(!this.isMysql, (eb) => eb.onConflict((eb) => eb.column("key").doUpdateSet({
51
+ key,
52
+ owner: lockId,
53
+ expiration: expirationAsMs,
54
+ })))
55
+ .$if(this.isMysql, (eb) => eb.onDuplicateKeyUpdate({
56
+ key,
57
+ owner: lockId,
58
+ expiration: expirationAsMs,
59
+ }))
60
+ .execute();
61
+ }
62
+ }
5
63
  /**
6
64
  * To utilize the `KyselyLockAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
7
65
  *
@@ -15,7 +73,9 @@ export class KyselyLockAdapter {
15
73
  kysely;
16
74
  expiredKeysRemovalInterval;
17
75
  shouldRemoveExpiredKeys;
18
- timeoutId = null;
76
+ intervalId = null;
77
+ currentDate;
78
+ isMysql;
19
79
  /**
20
80
  * @example
21
81
  * ```ts
@@ -34,19 +94,26 @@ export class KyselyLockAdapter {
34
94
  * ```
35
95
  */
36
96
  constructor(settings) {
37
- const { kysely, expiredKeysRemovalInterval = TimeSpan.fromMinutes(1), shouldRemoveExpiredKeys = true, } = settings;
97
+ const { kysely, expiredKeysRemovalInterval = TimeSpan.fromMinutes(1), shouldRemoveExpiredKeys = true, currentDate = () => new Date(), } = settings;
38
98
  this.expiredKeysRemovalInterval = expiredKeysRemovalInterval;
39
99
  this.shouldRemoveExpiredKeys = shouldRemoveExpiredKeys;
40
100
  this.kysely = kysely;
101
+ this.isMysql =
102
+ this.kysely.getExecutor().adapter instanceof MysqlAdapter;
103
+ this.currentDate = currentDate;
41
104
  }
105
+ /**
106
+ * Removes all related lock tables and their rows.
107
+ * Note all lock data will be removed.
108
+ */
42
109
  async deInit() {
43
- if (this.shouldRemoveExpiredKeys && this.timeoutId !== null) {
44
- clearTimeout(this.timeoutId);
110
+ if (this.shouldRemoveExpiredKeys && this.intervalId !== null) {
111
+ clearInterval(this.intervalId);
45
112
  }
46
113
  // Should throw if the index does not exists thats why the try catch is used.
47
114
  try {
48
115
  await this.kysely.schema
49
- .dropIndex("lock_expiresAt")
116
+ .dropIndex("lock_expiration")
50
117
  .on("lock")
51
118
  .execute();
52
119
  }
@@ -61,14 +128,18 @@ export class KyselyLockAdapter {
61
128
  /* EMPTY */
62
129
  }
63
130
  }
131
+ /**
132
+ * Creates all related tables and indexes.
133
+ * Note the `init` method needs to be called once before using the adapter.
134
+ */
64
135
  async init() {
65
136
  // Should throw if the table already exists thats why the try catch is used.
66
137
  try {
67
138
  await this.kysely.schema
68
139
  .createTable("lock")
69
- .addColumn("key", "varchar(255)", (col) => col.primaryKey())
140
+ .addColumn("key", "varchar(255)", (col) => col.primaryKey().notNull())
70
141
  .addColumn("owner", "varchar(255)", (col) => col.notNull())
71
- .addColumn("expiresAt", "bigint")
142
+ .addColumn("expiration", "bigint")
72
143
  .execute();
73
144
  }
74
145
  catch {
@@ -77,16 +148,16 @@ export class KyselyLockAdapter {
77
148
  // Should throw if the index already exists thats why the try catch is used.
78
149
  try {
79
150
  await this.kysely.schema
80
- .createIndex("lock_expiresAt")
151
+ .createIndex("lock_expiration")
81
152
  .on("lock")
82
- .columns(["expiresAt"])
153
+ .column("expiration")
83
154
  .execute();
84
155
  }
85
156
  catch {
86
157
  /* EMPTY */
87
158
  }
88
159
  if (this.shouldRemoveExpiredKeys) {
89
- this.timeoutId = setInterval(() => {
160
+ this.intervalId = setInterval(() => {
90
161
  void this.removeAllExpired();
91
162
  }, this.expiredKeysRemovalInterval.toMilliseconds());
92
163
  }
@@ -94,61 +165,116 @@ export class KyselyLockAdapter {
94
165
  async removeAllExpired() {
95
166
  await this.kysely
96
167
  .deleteFrom("lock")
97
- .where("lock.expiresAt", "<=", new Date().getTime())
168
+ .where("lock.expiration", "<=", this.currentDate().getTime())
98
169
  .execute();
99
170
  }
100
- async insert(key, owner, expiration) {
101
- await this.kysely
102
- .insertInto("lock")
103
- .values({
104
- key,
105
- owner,
106
- expiresAt: expiration?.getTime() ?? null,
107
- })
108
- .execute();
171
+ async transaction(fn) {
172
+ return await this.kysely
173
+ .transaction()
174
+ .setIsolationLevel("serializable")
175
+ .execute(async (trx) => {
176
+ return await fn(new DatabaseLockTransaction(trx));
177
+ });
109
178
  }
110
- async update(key, owner, expiration) {
111
- const updateResult = await this.kysely
112
- .updateTable("lock")
113
- .where("lock.key", "=", key)
114
- // Has expired
115
- .where((eb) => eb.and([
116
- eb("lock.expiresAt", "is not", null),
117
- eb("lock.expiresAt", "<=", Date.now()),
118
- ]))
119
- .set({ owner, expiresAt: expiration?.getTime() ?? null })
120
- .executeTakeFirst();
121
- return Number(updateResult.numUpdatedRows); // > 0;
122
- }
123
- async remove(key, owner) {
124
- await this.kysely
125
- .deleteFrom("lock")
126
- .where("lock.key", "=", key)
127
- .$if(owner !== null, (query) => query.where("lock.owner", "=", owner))
128
- .execute();
129
- }
130
- async refresh(key, owner, expiration) {
131
- const updateResult = await this.kysely
132
- .updateTable("lock")
133
- .where("lock.key", "=", key)
134
- .where("lock.owner", "=", owner)
135
- .set({ expiresAt: expiration.getTime() })
136
- .executeTakeFirst();
137
- return Number(updateResult.numUpdatedRows); // > 0;
179
+ async remove(key) {
180
+ let result;
181
+ if (this.isMysql) {
182
+ result = await this.kysely
183
+ .transaction()
184
+ .setIsolationLevel("serializable")
185
+ .execute(async (trx) => {
186
+ const row = await trx
187
+ .selectFrom("lock")
188
+ .where("lock.key", "=", key)
189
+ .select("lock.expiration")
190
+ .executeTakeFirst();
191
+ await trx
192
+ .deleteFrom("lock")
193
+ .where("lock.key", "=", key)
194
+ .executeTakeFirst();
195
+ return row;
196
+ });
197
+ }
198
+ else {
199
+ result = await this.kysely
200
+ .deleteFrom("lock")
201
+ .where("lock.key", "=", key)
202
+ .returning(["lock.expiration"])
203
+ .executeTakeFirst();
204
+ }
205
+ if (result === undefined) {
206
+ return null;
207
+ }
208
+ if (result.expiration === null) {
209
+ return {
210
+ expiration: null,
211
+ };
212
+ }
213
+ return {
214
+ expiration: new Date(Number(result.expiration)),
215
+ };
138
216
  }
139
- async find(key) {
140
- const row = await this.kysely
141
- .selectFrom("lock")
142
- .where("lock.key", "=", key)
143
- .select(["lock.owner", "lock.expiresAt"])
144
- .executeTakeFirst();
217
+ async removeIfOwner(key, lockId) {
218
+ let row;
219
+ if (this.isMysql) {
220
+ row = await this.kysely
221
+ .transaction()
222
+ .setIsolationLevel("serializable")
223
+ .execute(async (trx) => {
224
+ const row = await trx
225
+ .selectFrom("lock")
226
+ .where("lock.key", "=", key)
227
+ .where("lock.owner", "=", lockId)
228
+ .select(["lock.expiration", "lock.owner"])
229
+ .executeTakeFirst();
230
+ await trx
231
+ .deleteFrom("lock")
232
+ .where("lock.key", "=", key)
233
+ .where("lock.owner", "=", lockId)
234
+ .execute();
235
+ return row;
236
+ });
237
+ }
238
+ else {
239
+ row = await this.kysely
240
+ .deleteFrom("lock")
241
+ .where("lock.key", "=", key)
242
+ .where("lock.owner", "=", lockId)
243
+ .returning(["lock.expiration", "lock.owner"])
244
+ .executeTakeFirst();
245
+ }
145
246
  if (row === undefined) {
146
247
  return null;
147
248
  }
249
+ const { expiration } = row;
250
+ if (expiration === null) {
251
+ return {
252
+ owner: row.owner,
253
+ expiration: null,
254
+ };
255
+ }
148
256
  return {
149
- expiration: row.expiresAt !== null ? new Date(Number(row.expiresAt)) : null,
150
257
  owner: row.owner,
258
+ expiration: new Date(Number(expiration)),
151
259
  };
152
260
  }
261
+ async updateExpiration(key, lockId, expiration) {
262
+ const result = await this.kysely
263
+ .updateTable("lock")
264
+ .where("lock.key", "=", key)
265
+ .where("lock.owner", "=", lockId)
266
+ .where((eb) => eb.and([
267
+ eb("lock.expiration", "is not", null),
268
+ eb("lock.expiration", ">", Date.now()),
269
+ ]))
270
+ .set({
271
+ expiration: expiration.getTime(),
272
+ })
273
+ .executeTakeFirst();
274
+ return Number(result.numUpdatedRows);
275
+ }
276
+ async find(key) {
277
+ return await find(this.kysely, key);
278
+ }
153
279
  }
154
280
  //# sourceMappingURL=kysely-lock-adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kysely-lock-adapter.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAIH,QAAQ,GACX,MAAM,gCAAgC,CAAC;AA8CxC;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAiB;IAGT,MAAM,CAAkC;IACxC,0BAA0B,CAAW;IACrC,uBAAuB,CAAU;IAC1C,SAAS,GACb,IAAI,CAAC;IAET;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,QAAmC;QAC3C,MAAM,EACF,MAAM,EACN,0BAA0B,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EACpD,uBAAuB,GAAG,IAAI,GACjC,GAAG,QAAQ,CAAC;QACb,IAAI,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;QAC7D,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,MAAM;QACR,IAAI,IAAI,CAAC,uBAAuB,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC1D,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAED,6EAA6E;QAC7E,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,MAAM,CAAC,MAA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1
+ {"version":3,"file":"kysely-lock-adapter.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAE,YAAY,EAAe,MAAM,QAAQ,CAAC;AACnD,OAAO,EAKN,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAuD1E,KAAK,UAAU,IAAI,CACf,MAAgC,EAChC,GAAW;IAEX,MAAM,GAAG,GAAG,MAAM,MAAM;SACnB,UAAU,CAAC,MAAM,CAAC;SAClB,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,GAAG,CAAC;SAC3B,MAAM,CAAC,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;SACzC,gBAAgB,EAAE,CAAC;IACxB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,GAAG,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO;YACH,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,UAAU,EAAE,IAAI;SACnB,CAAC;IACN,CAAC;IACD,OAAO;QACH,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,UAAU,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;KAC/C,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,uBAAuB;IAGI;IAFZ,OAAO,CAAU;IAElC,YAA6B,MAAgC;QAAhC,WAAM,GAAN,MAAM,CAA0B;QACzD,IAAI,CAAC,OAAO;YACR,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,YAAY,YAAY,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAW;QAClB,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;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EACd,UAAgB;QAEhB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM;aAC3B,WAAW,CAAC,MAAM,CAAC;aACnB,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,GAAG,CAAC;aAC3B,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC;aAChC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CACV,EAAE,CAAC,GAAG,CAAC;YACH,EAAE,CAAC,iBAAiB,EAAE,QAAQ,EAAE,IAAI,CAAC;YACrC,EAAE,CAAC,iBAAiB,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;SACzC,CAAC,CACL;aACA,GAAG,CAAC;YACD,UAAU,EAAE,UAAU,CAAC,OAAO,EAAE;SACnC,CAAC;aACD,gBAAgB,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAW;QAClB,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;CACJ"}
@@ -1,8 +1,23 @@
1
1
  /**
2
2
  * @module Lock
3
3
  */
4
- import type { TimeSpan } from "../../../../utilities/_module-exports.js";
5
- import type { ILockAdapter, ILockData } from "../../../../lock/contracts/_module-exports.js";
4
+ import type { IDeinitizable } from "../../../../utilities/_module-exports.js";
5
+ import type { ILockAdapter, ILockAdapterState } from "../../../../lock/contracts/_module-exports.js";
6
+ import type { TimeSpan } from "../../../../time-span/implementations/_module-exports.js";
7
+ /**
8
+ *
9
+ * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
10
+ * @group Adapters
11
+ */
12
+ export type MemoryLockData = {
13
+ owner: string;
14
+ hasExpiration: true;
15
+ timeoutId: string | number | NodeJS.Timeout;
16
+ expiration: Date;
17
+ } | {
18
+ owner: string;
19
+ hasExpiration: false;
20
+ };
6
21
  /**
7
22
  * Note the `MemoryLockAdapter` is limited to single process usage and cannot be shared across multiple servers or different processes.
8
23
  * This adapter is meant to be used for testing.
@@ -10,9 +25,8 @@ import type { ILockAdapter, ILockData } from "../../../../lock/contracts/_module
10
25
  * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
11
26
  * @group Adapters
12
27
  */
13
- export declare class MemoryLockAdapter implements ILockAdapter {
28
+ export declare class MemoryLockAdapter implements ILockAdapter, IDeinitizable {
14
29
  private readonly map;
15
- private readonly timeoutMap;
16
30
  /**
17
31
  * @example
18
32
  * ```ts
@@ -29,9 +43,11 @@ export declare class MemoryLockAdapter implements ILockAdapter {
29
43
  * const lockAdapter = new MemoryLockAdapter(map);
30
44
  * ```
31
45
  */
32
- constructor(map?: Map<string, ILockData>);
33
- acquire(key: string, owner: string, ttl: TimeSpan | null): Promise<boolean>;
34
- release(key: string, owner: string): Promise<boolean>;
35
- forceRelease(key: string): Promise<void>;
36
- refresh(key: string, owner: string, time: TimeSpan): Promise<boolean>;
46
+ constructor(map?: Map<string, MemoryLockData>);
47
+ deInit(): Promise<void>;
48
+ acquire(key: string, lockId: string, ttl: TimeSpan | null): Promise<boolean>;
49
+ release(key: string, lockId: string): Promise<boolean>;
50
+ forceRelease(key: string): Promise<boolean>;
51
+ refresh(key: string, lockId: string, ttl: TimeSpan): Promise<boolean>;
52
+ getState(key: string): Promise<ILockAdapterState | null>;
37
53
  }
@@ -10,7 +10,6 @@
10
10
  */
11
11
  export class MemoryLockAdapter {
12
12
  map;
13
- timeoutMap = new Map();
14
13
  /**
15
14
  * @example
16
15
  * ```ts
@@ -31,64 +30,109 @@ export class MemoryLockAdapter {
31
30
  this.map = map;
32
31
  }
33
32
  // eslint-disable-next-line @typescript-eslint/require-await
34
- async acquire(key, owner, ttl) {
35
- const hasNotKey = !this.map.has(key);
36
- if (hasNotKey) {
37
- this.map.set(key, {
38
- owner,
39
- expiration: ttl?.toEndDate() ?? null,
40
- });
33
+ async deInit() {
34
+ for (const [key, lockData] of this.map) {
35
+ if (lockData.hasExpiration) {
36
+ clearTimeout(lockData.timeoutId);
37
+ }
38
+ this.map.delete(key);
39
+ }
40
+ }
41
+ // eslint-disable-next-line @typescript-eslint/require-await
42
+ async acquire(key, lockId, ttl) {
43
+ let lock = this.map.get(key);
44
+ if (lock !== undefined) {
45
+ return lock.owner === lockId;
46
+ }
47
+ if (ttl === null) {
48
+ lock = {
49
+ owner: lockId,
50
+ hasExpiration: false,
51
+ };
52
+ this.map.set(key, lock);
41
53
  }
42
- if (hasNotKey && ttl !== null) {
43
- this.timeoutMap.set(key, setTimeout(() => {
54
+ else {
55
+ const timeoutId = setTimeout(() => {
44
56
  this.map.delete(key);
45
- this.timeoutMap.delete(key);
46
- }, ttl.toMilliseconds()));
57
+ }, ttl.toMilliseconds());
58
+ lock = {
59
+ owner: lockId,
60
+ hasExpiration: true,
61
+ timeoutId,
62
+ expiration: ttl.toEndDate(),
63
+ };
64
+ this.map.set(key, lock);
47
65
  }
48
- return hasNotKey;
66
+ return true;
49
67
  }
50
68
  // eslint-disable-next-line @typescript-eslint/require-await
51
- async release(key, owner) {
52
- const data = this.map.get(key);
53
- if (data === undefined) {
54
- return true;
69
+ async release(key, lockId) {
70
+ const lock = this.map.get(key);
71
+ if (lock === undefined) {
72
+ return false;
55
73
  }
56
- if (data.owner !== owner) {
74
+ if (lock.owner !== lockId) {
57
75
  return false;
58
76
  }
59
- clearTimeout(this.timeoutMap.get(key));
60
- this.timeoutMap.delete(key);
77
+ if (lock.hasExpiration) {
78
+ clearTimeout(lock.timeoutId);
79
+ }
61
80
  this.map.delete(key);
62
81
  return true;
63
82
  }
64
83
  // eslint-disable-next-line @typescript-eslint/require-await
65
84
  async forceRelease(key) {
66
- clearTimeout(this.timeoutMap.get(key));
67
- this.timeoutMap.delete(key);
85
+ const lock = this.map.get(key);
86
+ if (lock === undefined) {
87
+ return false;
88
+ }
89
+ if (lock.hasExpiration) {
90
+ clearTimeout(lock.timeoutId);
91
+ }
68
92
  this.map.delete(key);
93
+ return true;
69
94
  }
70
95
  // eslint-disable-next-line @typescript-eslint/require-await
71
- async refresh(key, owner, time) {
72
- const data = this.map.get(key);
73
- if (data === undefined) {
74
- return true;
96
+ async refresh(key, lockId, ttl) {
97
+ const lock = this.map.get(key);
98
+ if (lock === undefined) {
99
+ return false;
75
100
  }
76
- if (data.owner !== owner) {
101
+ if (lock.owner !== lockId) {
77
102
  return false;
78
103
  }
79
- if (data.expiration === null) {
80
- return true;
104
+ if (!lock.hasExpiration) {
105
+ return false;
81
106
  }
107
+ clearTimeout(lock.timeoutId);
108
+ const timeoutId = setTimeout(() => {
109
+ this.map.delete(key);
110
+ }, ttl.toMilliseconds());
82
111
  this.map.set(key, {
83
- ...data,
84
- expiration: time.toEndDate(),
112
+ ...lock,
113
+ timeoutId,
85
114
  });
86
- clearTimeout(this.timeoutMap.get(key));
87
- this.timeoutMap.set(key, setTimeout(() => {
88
- this.timeoutMap.delete(key);
89
- this.map.delete(key);
90
- }, time.toMilliseconds()));
91
115
  return true;
92
116
  }
117
+ // eslint-disable-next-line @typescript-eslint/require-await
118
+ async getState(key) {
119
+ const lockData = this.map.get(key);
120
+ if (lockData === undefined) {
121
+ return null;
122
+ }
123
+ if (!lockData.hasExpiration) {
124
+ return {
125
+ owner: lockData.owner,
126
+ expiration: null,
127
+ };
128
+ }
129
+ if (lockData.expiration <= new Date()) {
130
+ return null;
131
+ }
132
+ return {
133
+ owner: lockData.owner,
134
+ expiration: lockData.expiration,
135
+ };
136
+ }
93
137
  }
94
138
  //# sourceMappingURL=memory-lock-adapter.js.map