@daiso-tech/core 0.38.0 → 0.40.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 (152) hide show
  1. package/README.md +5 -1
  2. package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.d.ts +1 -1
  3. package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +2 -2
  4. package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.d.ts +1 -1
  5. package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +2 -2
  6. package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +2 -2
  7. package/dist/async/middlewares/hedging/sequential-hedging.middleware.js +2 -2
  8. package/dist/async/middlewares/hedging/sequential-hedging.middleware.js.map +1 -1
  9. package/dist/async/middlewares/retry/retry.middleware.js +2 -2
  10. package/dist/async/middlewares/retry/retry.middleware.js.map +1 -1
  11. package/dist/async/middlewares/retry/retry.types.d.ts +1 -1
  12. package/dist/cache/contracts/cache-adapter.contract.d.ts +9 -9
  13. package/dist/cache/contracts/cache.contract.d.ts +7 -7
  14. package/dist/cache/contracts/cache.errors.d.ts +3 -26
  15. package/dist/cache/contracts/cache.errors.js +0 -47
  16. package/dist/cache/contracts/cache.errors.js.map +1 -1
  17. package/dist/cache/contracts/database-cache-adapter.contract.d.ts +10 -10
  18. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +6 -5
  19. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +17 -13
  20. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
  21. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +15 -3
  22. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +25 -9
  23. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
  24. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +9 -9
  25. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -1
  26. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +1 -1
  27. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +1 -1
  28. package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js +2 -1
  29. package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js.map +1 -1
  30. package/dist/cache/implementations/derivables/cache/cache.d.ts +2 -2
  31. package/dist/cache/implementations/derivables/cache/cache.js +1 -1
  32. package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
  33. package/dist/collection/contracts/async-collection.contract.d.ts +0 -1
  34. package/dist/collection/contracts/async-collection.contract.js +3 -1
  35. package/dist/collection/contracts/async-collection.contract.js.map +1 -1
  36. package/dist/collection/contracts/collection.contract.d.ts +0 -1
  37. package/dist/collection/contracts/collection.contract.js +3 -1
  38. package/dist/collection/contracts/collection.contract.js.map +1 -1
  39. package/dist/collection/contracts/collection.errors.d.ts +1 -26
  40. package/dist/collection/contracts/collection.errors.js +0 -55
  41. package/dist/collection/contracts/collection.errors.js.map +1 -1
  42. package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js +1 -1
  43. package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js.map +1 -1
  44. package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js +1 -1
  45. package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js.map +1 -1
  46. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +9 -6
  47. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
  48. package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js +1 -1
  49. package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js.map +1 -1
  50. package/dist/collection/implementations/iterable-collection/_shared/zip-iterable.js +1 -1
  51. package/dist/collection/implementations/iterable-collection/_shared/zip-iterable.js.map +1 -1
  52. package/dist/collection/implementations/iterable-collection/iterable-collection.js +9 -6
  53. package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
  54. package/dist/collection/implementations/list-collection/list-collection.js +12 -9
  55. package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
  56. package/dist/event-bus/contracts/_module-exports.d.ts +0 -1
  57. package/dist/event-bus/contracts/_module-exports.js +0 -1
  58. package/dist/event-bus/contracts/_module-exports.js.map +1 -1
  59. package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +3 -3
  60. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +3 -3
  61. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +2 -2
  62. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +3 -2
  63. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
  64. package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +2 -1
  65. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +26 -26
  66. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
  67. package/dist/event-bus/implementations/derivables/event-bus/listener-store.d.ts +11 -4
  68. package/dist/event-bus/implementations/derivables/event-bus/listener-store.js +17 -12
  69. package/dist/event-bus/implementations/derivables/event-bus/listener-store.js.map +1 -1
  70. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +17 -20
  71. package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
  72. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +159 -752
  73. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
  74. package/dist/lock/contracts/database-lock-adapter.contract.d.ts +56 -16
  75. package/dist/lock/contracts/lock-adapter.contract.d.ts +32 -9
  76. package/dist/lock/contracts/lock-adapter.contract.js +10 -1
  77. package/dist/lock/contracts/lock-adapter.contract.js.map +1 -1
  78. package/dist/lock/contracts/lock.contract.d.ts +30 -25
  79. package/dist/lock/contracts/lock.errors.d.ts +11 -28
  80. package/dist/lock/contracts/lock.errors.js +10 -74
  81. package/dist/lock/contracts/lock.errors.js.map +1 -1
  82. package/dist/lock/contracts/lock.events.d.ts +15 -3
  83. package/dist/lock/contracts/lock.events.js +2 -1
  84. package/dist/lock/contracts/lock.events.js.map +1 -1
  85. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +40 -10
  86. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +135 -37
  87. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
  88. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +20 -7
  89. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +59 -35
  90. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
  91. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +23 -12
  92. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +152 -87
  93. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
  94. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +5 -5
  95. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +3 -2
  96. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -1
  97. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +6 -6
  98. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +46 -24
  99. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
  100. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +4 -4
  101. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +45 -12
  102. package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
  103. package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js +7 -5
  104. package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +1 -1
  105. package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +3 -3
  106. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +2 -3
  107. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
  108. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +1 -1
  109. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +4 -3
  110. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
  111. package/dist/lock/implementations/derivables/lock-provider/lock-state.d.ts +8 -11
  112. package/dist/lock/implementations/derivables/lock-provider/lock-state.js +9 -26
  113. package/dist/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -1
  114. package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +14 -16
  115. package/dist/lock/implementations/derivables/lock-provider/lock.js +106 -63
  116. package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
  117. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +2 -2
  118. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
  119. package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +184 -166
  120. package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
  121. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +240 -41
  122. package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
  123. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +2704 -1514
  124. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
  125. package/dist/serde/implementations/derivables/serde.d.ts +22 -22
  126. package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js +2 -1
  127. package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js.map +1 -1
  128. package/dist/utilities/classes/namespace/namespace.d.ts +3 -3
  129. package/dist/utilities/classes/namespace/namespace.js +2 -2
  130. package/dist/utilities/classes/namespace/namespace.js.map +1 -1
  131. package/dist/utilities/classes/time-span/time-span.d.ts +10 -2
  132. package/dist/utilities/classes/time-span/time-span.js +10 -2
  133. package/dist/utilities/classes/time-span/time-span.js.map +1 -1
  134. package/dist/utilities/contracts/deinitizable.contract.d.ts +1 -1
  135. package/dist/utilities/contracts/initizable.contract.d.ts +1 -1
  136. package/dist/utilities/contracts/prunable.contract.d.ts +1 -1
  137. package/dist/utilities/errors.d.ts +8 -0
  138. package/dist/utilities/errors.js +11 -0
  139. package/dist/utilities/errors.js.map +1 -1
  140. package/dist/utilities/functions/_module.d.ts +1 -0
  141. package/dist/utilities/functions/_module.js +1 -0
  142. package/dist/utilities/functions/_module.js.map +1 -1
  143. package/dist/utilities/functions/is-class.d.ts +4 -0
  144. package/dist/utilities/functions/is-class.js +4 -0
  145. package/dist/utilities/functions/is-class.js.map +1 -1
  146. package/dist/utilities/functions/is-positive-nbr.d.ts +8 -0
  147. package/dist/utilities/functions/is-positive-nbr.js +19 -0
  148. package/dist/utilities/functions/is-positive-nbr.js.map +1 -0
  149. package/package.json +1 -1
  150. package/dist/event-bus/contracts/event-bus.errors.d.ts +0 -40
  151. package/dist/event-bus/contracts/event-bus.errors.js +0 -62
  152. package/dist/event-bus/contracts/event-bus.errors.js.map +0 -1
package/README.md CHANGED
@@ -17,7 +17,11 @@
17
17
  @daiso-tech/core leverages modern JavaScript primitives, including ES modules
18
18
 
19
19
  - **Easily testable:**
20
- @daiso-tech/core includes built-in vitest helpers for custom adapters and in-memory adapters for all components, enabling testing without Docker.
20
+ @daiso-tech/core includes built-in [vitest](https://vitest.dev/) helpers for custom adapters and in-memory adapters for all components, enabling testing without Docker.
21
+
22
+ - **Supports standard schema:**
23
+ Integrated seamlessly with [standard schema](https://standardschema.dev/) allowing you to use libraries like zod to ensure both compile time and runtimte typesafety.
24
+
21
25
 
22
26
  ## A growing collection of officially maintained components
23
27
 
@@ -14,7 +14,7 @@ export type ConstantBackoffPolicySettings = {
14
14
  */
15
15
  delay?: TimeSpan;
16
16
  /**
17
- * @default {0.5}
17
+ * @default 0.5
18
18
  */
19
19
  jitter?: number;
20
20
  /**
@@ -18,11 +18,11 @@ export type ExponentialBackoffPolicySettings = {
18
18
  */
19
19
  minDelay?: TimeSpan;
20
20
  /**
21
- * @default {2}
21
+ * @default 2
22
22
  */
23
23
  multiplier?: number;
24
24
  /**
25
- * @default {0.5}
25
+ * @default 0.5
26
26
  */
27
27
  jitter?: number;
28
28
  /**
@@ -18,7 +18,7 @@ export type LinearBackoffPolicySettings = {
18
18
  */
19
19
  minDelay?: TimeSpan;
20
20
  /**
21
- * @default {0.5}
21
+ * @default 0.5
22
22
  */
23
23
  jitter?: number;
24
24
  /**
@@ -18,11 +18,11 @@ export type PolynomialBackoffPolicySettings = {
18
18
  */
19
19
  minDelay?: TimeSpan;
20
20
  /**
21
- * @default {2}
21
+ * @default 2
22
22
  */
23
23
  degree?: number;
24
24
  /**
25
- * @default {0.5}
25
+ * @default 0.5
26
26
  */
27
27
  jitter?: number;
28
28
  /**
@@ -34,14 +34,14 @@ export type BulkheadSettings<TParameters extends unknown[] = unknown[], TContext
34
34
  /**
35
35
  * The maximum number of promises allowed to run concurrently. If this limit is exceeded, additional promises will be queued until a slot becomes available.
36
36
  *
37
- * @default {25}
37
+ * @default 25
38
38
  */
39
39
  maxConcurrency?: number;
40
40
  /**
41
41
  * The maximum capacity of the promise queue. If null, the queue can grow indefinitely.
42
42
  * If a number is provided and the queue exceeds this limit, an error will be thrown, and no further promises will be enqueued.
43
43
  *
44
- * @default {null}
44
+ * @default null
45
45
  */
46
46
  maxCapacity?: number | null;
47
47
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Async
3
3
  */
4
- import { AsyncHooks, callErrorPolicyOnThrow, callErrorPolicyOnValue, callInvokable, isInvokable, optionNone, optionSome, resolveOneOrMore, } from "../../../utilities/_module-exports.js";
4
+ import { AsyncHooks, callErrorPolicyOnThrow, callErrorPolicyOnValue, callInvokable, isInvokable, optionNone, optionSome, resolveOneOrMore, UnexpectedError, } from "../../../utilities/_module-exports.js";
5
5
  import {} from "../../../async/middlewares/hedging/hedging.types.js";
6
6
  /**
7
7
  * @internal
@@ -125,7 +125,7 @@ export function sequentialHedging(settings) {
125
125
  }
126
126
  }
127
127
  if (lastError.type === "none") {
128
- throw new Error("!!__MESSAGE__!!");
128
+ throw new UnexpectedError("!!__MESSAGE__!!");
129
129
  }
130
130
  throw lastError.value;
131
131
  };
@@ -1 +1 @@
1
- {"version":3,"file":"sequential-hedging.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/sequential-hedging.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,UAAU,EACV,UAAU,EACV,gBAAgB,GAQnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAIN,MAAM,8CAA8C,CAAC;AAEtD;;GAEG;AACH,SAAS,gBAAgB,CACrB,SAAyC,EACzC,SAEC,EACD,WAA6D,EAC7D,YAA4C;IAE5C,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,GAAG,CAEvD,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,OAAO;gBACH,IAAI,EAAE,YAAY,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE;gBACrC,SAA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I,CAAC,CAAC;gBAEjD,+CAA+C;gBAC/C,IAAI,CAAC,CAAC,MAAM,sBAAsB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;oBACtD,OAAO,KAAK,CAAC;gBACjB,CAAC;gBAED,4FAA4F;gBAC5F,MAAM,aAAa,GAAG,KAAsB,CAAC;gBAE7C,aAAa,CAAC,cAAc,EAAE;oBAC1B,IAAI;oBACJ,OAAO;oBACP,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,IAAI;iBACP,CAAC,CAAC;gBACH,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAE5C,uCAAuC;YAC3C,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACtB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACjB,MAAM;gBACV,CAAC;gBAED,IAAI,MAAM,sBAAsB,CAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;oBACxD,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;gBAClC,CAAC;qBAAM,CAAC;oBACJ,MAAM,KAAK,CAAC;gBAChB,CAAC;gBAED,aAAa,CAAC,cAAc,EAAE;oBAC1B,IAAI;oBACJ,OAAO;oBACP,KAAK;oBACL,IAAI;iBACP,CAAC,CAAC;gBACH,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;QACL,CAAC;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACvC,CAAC;QAED,MAAM,SAAS,CAAC,KAAK,CAAC;IAC1B,CAAC,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"sequential-hedging.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/sequential-hedging.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,UAAU,EACV,sBAAsB,EACtB,sBAAs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BACJ,OAAO;oBACP,KAAK;oBACL,IAAI;iBACP,CAAC,CAAC;gBACH,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;QACL,CAAC;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,MAAM,IAAI,eAAe,CAAC,iBAAiB,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,SAAS,CAAC,KAAK,CAAC;IAC1B,CAAC,CAAC;AACN,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Async
3
3
  */
4
- import { callInvokable, optionNone, optionSome, OPTION, } from "../../../utilities/_module-exports.js";
4
+ import { callInvokable, optionNone, optionSome, OPTION, UnexpectedError, } from "../../../utilities/_module-exports.js";
5
5
  import { exponentialBackoffPolicy } from "../../../async/backof-policies/_module.js";
6
6
  import { callErrorPolicyOnThrow, callErrorPolicyOnValue, } from "../../../utilities/_module-exports.js";
7
7
  import { LazyPromise } from "../../../async/utilities/lazy-promise/_module.js";
@@ -124,7 +124,7 @@ export function retry(settings = {}) {
124
124
  if (result.type === OPTION.SOME) {
125
125
  return result.value;
126
126
  }
127
- throw new Error("!!__MESSAGE__!!");
127
+ throw new UnexpectedError("!!__MESSAGE__!!");
128
128
  };
129
129
  }
130
130
  //# sourceMappingURL=retry.middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"retry.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/retry/retry.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAGH,aAAa,EACb,UAAU,EACV,UAAU,EACV,MAAM,GACT,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EACH,sBAAsB,EACtB,sBAAsB,GACzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;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P,IAAI;oBACJ,OAAO;iBACV,CAAC,CAAC;gBACH,MAAM,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;gBAE1C,wCAAwC;YAC5C,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACtB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACjB,MAAM;gBACV,CAAC;gBAED,IAAI,MAAM,sBAAsB,CAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;oBACxD,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;gBAC/B,CAAC;qBAAM,CAAC;oBACJ,MAAM,KAAK,CAAC;gBAChB,CAAC;gBAED,MAAM,QAAQ,GAAG,aAAa,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBAE9D,aAAa,CAAC,YAAY,EAAE;oBACxB,KAAK,EAAE,KAAK;oBACZ,QAAQ;oBACR,OAAO;oBACP,IAAI;oBACJ,OAAO;iBACV,CAAC,CAAC;gBACH,MAAM,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC9C,CAAC;QACL,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9B,MAAM,MAAM,CAAC,KAAK,CAAC;QACvB,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC,KAAK,CAAC;QACxB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"retry.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/retry/retry.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAGH,aAAa,EACb,UAAU,EACV,UAAU,EACV,MAAM,EACN,eAAe,GAClB,MAAM,gCAAgC,CAAC;AACxC,OA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 +62,7 @@ export type RetryCallbacks<TParameters extends unknown[] = unknown[], TContext e
62
62
  export type RetrySettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext, TReturn = unknown> = RetryCallbacks<TParameters, TContext> & ErrorPolicySettings<InferResultError<TReturn>> & {
63
63
  /**
64
64
  * You can decide maximal times you can retry.
65
- * @default {4}
65
+ * @default 4
66
66
  */
67
67
  maxAttempts?: number;
68
68
  /**
@@ -12,43 +12,43 @@ export type ICacheAdapter<TType = unknown> = {
12
12
  /**
13
13
  * The `get` method returns the value when `key` is found otherwise null will be returned.
14
14
  */
15
- get(key: string): PromiseLike<TType | null>;
15
+ get(key: string): Promise<TType | null>;
16
16
  /**
17
17
  * The `getAndRemove` method returns the value when `key` is found otherwise null will be returned.
18
18
  * The key will be removed after it is returned.
19
19
  */
20
- getAndRemove(key: string): PromiseLike<TType | null>;
20
+ getAndRemove(key: string): Promise<TType | null>;
21
21
  /**
22
22
  * The `add` method adds a `key` with given `value` when key doesn't exists. Returns true when key doesn't exists otherwise false will be returned.
23
23
  * You can provide a `ttl` value. If null is passed, the item will not expire.
24
24
  */
25
- add(key: string, value: TType, ttl: TimeSpan | null): PromiseLike<boolean>;
25
+ add(key: string, value: TType, ttl: TimeSpan | null): Promise<boolean>;
26
26
  /**
27
27
  * The `put` method replaces th given `key` with the given `value` and `ttl` if the `key` exists othwerwise it will add the given `value` and `ttl`.
28
28
  * Returns true if the `key` where replaced otherwise false is returned.
29
29
  */
30
- put(key: string, value: TType, ttl: TimeSpan | null): PromiseLike<boolean>;
30
+ put(key: string, value: TType, ttl: TimeSpan | null): Promise<boolean>;
31
31
  /**
32
32
  * The `update` method updates the given `key` with given `value`. Returns true if the `key` where updated otherwise false will be returned.
33
33
  */
34
- update(key: string, value: TType): PromiseLike<boolean>;
34
+ update(key: string, value: TType): Promise<boolean>;
35
35
  /**
36
36
  * The `increment` method increments the given `key` with given `value`. Returns true if the `key` where incremented otherwise false will be returned.
37
37
  * If `values` is not defined then it will increment the key with 1.
38
38
  * An error will thrown if the key is not a number.
39
39
  * @throws {TypeCacheError} {@link TypeCacheError}
40
40
  */
41
- increment(key: string, value: number): PromiseLike<boolean>;
41
+ increment(key: string, value: number): Promise<boolean>;
42
42
  /**
43
43
  * The `removeMany` method removes many keys. Returns true if one of the keys where deleted otherwise false is returned.
44
44
  */
45
- removeMany(keys: string[]): PromiseLike<boolean>;
45
+ removeMany(keys: string[]): Promise<boolean>;
46
46
  /**
47
47
  * The `removeAll` method removes all keys from the cache.
48
48
  */
49
- removeAll(): PromiseLike<void>;
49
+ removeAll(): Promise<void>;
50
50
  /**
51
51
  * The `removeByKeyPrefix` method removes all the keys in the cache that starts with the given `prefix`.
52
52
  */
53
- removeByKeyPrefix(prefix: string): PromiseLike<void>;
53
+ removeByKeyPrefix(prefix: string): Promise<void>;
54
54
  };
@@ -92,7 +92,7 @@ export type ICacheBase<TType = unknown> = {
92
92
  *
93
93
  * @param ttl - If null is passed, the item will not expire.
94
94
  *
95
- * @returns true when key doesn't exists otherwise false will be returned.
95
+ * @returns Returns true when key doesn't exists otherwise false will be returned.
96
96
  */
97
97
  add(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
98
98
  /**
@@ -105,7 +105,7 @@ export type ICacheBase<TType = unknown> = {
105
105
  *
106
106
  * @param ttl - If null is passed, the item will not expire.
107
107
  *
108
- * @returns true if the `key` where replaced otherwise false is returned.
108
+ * @returns Returns true if the `key` where replaced otherwise false is returned.
109
109
  */
110
110
  put(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
111
111
  /**
@@ -115,7 +115,7 @@ export type ICacheBase<TType = unknown> = {
115
115
  * If it's an `Iterable`, it will be joined into a single string.
116
116
  * Think of an `Iterable` as representing a path.
117
117
  *
118
- * @returns true if the `key` where updated otherwise false will be returned.
118
+ * @returns Returns true if the `key` where updated otherwise false will be returned.
119
119
  */
120
120
  update(key: OneOrMore<string>, value: TType): LazyPromise<boolean>;
121
121
  /**
@@ -128,7 +128,7 @@ export type ICacheBase<TType = unknown> = {
128
128
  *
129
129
  * @param value - If not defined then it will be defaulted to 1.
130
130
  *
131
- * @returns true if the `key` where incremented otherwise false will be returned.
131
+ * @returns Returns true if the `key` where incremented otherwise false will be returned.
132
132
  *
133
133
  * @throws {TypeCacheError} {@link TypeCacheError}
134
134
  */
@@ -143,7 +143,7 @@ export type ICacheBase<TType = unknown> = {
143
143
  *
144
144
  * @param value - If not defined then it will be defaulted to 1.
145
145
  *
146
- * @returns true if the `key` where decremented otherwise false will be returned.
146
+ * @returns Returns true if the `key` where decremented otherwise false will be returned.
147
147
  *
148
148
  * @throws {TypeCacheError} {@link TypeCacheError}
149
149
  */
@@ -155,7 +155,7 @@ export type ICacheBase<TType = unknown> = {
155
155
  * If it's an `Iterable`, it will be joined into a single string.
156
156
  * Think of an `Iterable` as representing a path.
157
157
  *
158
- * @returns true if the key is found otherwise false is returned.
158
+ * @returns Returns true if the key is found otherwise false is returned.
159
159
  */
160
160
  remove(key: OneOrMore<string>): LazyPromise<boolean>;
161
161
  /**
@@ -165,7 +165,7 @@ export type ICacheBase<TType = unknown> = {
165
165
  * If the param items are an `Iterable`, it will be joined into a single string.
166
166
  * Think of an `Iterable` as representing a path.
167
167
  *
168
- * @returns true if one of the keys where deleted otherwise false is returned.
168
+ * @returns Returns true if one of the keys where deleted otherwise false is returned.
169
169
  */
170
170
  removeMany(keys: Iterable<OneOrMore<string>>): LazyPromise<boolean>;
171
171
  /**
@@ -1,25 +1,12 @@
1
1
  /**
2
2
  * @module Cache
3
3
  */
4
- import type { ISerderRegister, ISerializable } from "../../serde/contracts/_module-exports.js";
5
- import { type ISerializedError, type OneOrMore } from "../../utilities/_module-exports.js";
6
4
  /**
7
5
  *
8
6
  * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
9
7
  * @group Errors
10
8
  */
11
- export declare class CacheError extends Error implements ISerializable<ISerializedError> {
12
- static deserialize(deserializedValue: ISerializedError): CacheError;
13
- constructor(message: string, cause?: unknown);
14
- serialize(): ISerializedError;
15
- }
16
- /**
17
- *
18
- * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
19
- * @group Errors
20
- */
21
- export declare class UnexpectedCacheError extends CacheError implements ISerializable<ISerializedError> {
22
- static deserialize(deserializedValue: ISerializedError): CacheError;
9
+ export declare class CacheError extends Error {
23
10
  constructor(message: string, cause?: unknown);
24
11
  }
25
12
  /**
@@ -28,8 +15,7 @@ export declare class UnexpectedCacheError extends CacheError implements ISeriali
28
15
  * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
29
16
  * @group Errors
30
17
  */
31
- export declare class TypeCacheError extends CacheError implements ISerializable<ISerializedError> {
32
- static deserialize(deserializedValue: ISerializedError): CacheError;
18
+ export declare class TypeCacheError extends CacheError {
33
19
  constructor(message: string, cause?: unknown);
34
20
  }
35
21
  /**
@@ -38,8 +24,7 @@ export declare class TypeCacheError extends CacheError implements ISerializable<
38
24
  * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
39
25
  * @group Errors
40
26
  */
41
- export declare class KeyNotFoundCacheError extends CacheError implements ISerializable<ISerializedError> {
42
- static deserialize(deserializedValue: ISerializedError): CacheError;
27
+ export declare class KeyNotFoundCacheError extends CacheError {
43
28
  constructor(message: string, cause?: unknown);
44
29
  }
45
30
  /**
@@ -49,14 +34,6 @@ export declare class KeyNotFoundCacheError extends CacheError implements ISerial
49
34
  */
50
35
  export declare const CACHE_ERRORS: {
51
36
  readonly Base: typeof CacheError;
52
- readonly Unexpected: typeof UnexpectedCacheError;
53
37
  readonly Type: typeof TypeCacheError;
54
38
  readonly KeyNotFound: typeof KeyNotFoundCacheError;
55
39
  };
56
- /**
57
- * The `registerCacheErrorsToSerde` function registers all {@link ICache | `ICache`} related errors with `ISerderRegister`, ensuring they will properly be serialized and deserialized.
58
- *
59
- * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
60
- * @group Errors
61
- */
62
- export declare function registerCacheErrorsToSerde(serde: OneOrMore<ISerderRegister>): void;
@@ -1,41 +1,16 @@
1
1
  /**
2
2
  * @module Cache
3
3
  */
4
- import { CORE, resolveOneOrMore, } from "../../utilities/_module-exports.js";
5
4
  /**
6
5
  *
7
6
  * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
8
7
  * @group Errors
9
8
  */
10
9
  export class CacheError extends Error {
11
- static deserialize(deserializedValue) {
12
- return new CacheError(deserializedValue.message, deserializedValue.cause);
13
- }
14
10
  constructor(message, cause) {
15
11
  super(message, { cause });
16
12
  this.name = CacheError.name;
17
13
  }
18
- serialize() {
19
- return {
20
- name: this.name,
21
- message: this.message,
22
- cause: this.cause,
23
- };
24
- }
25
- }
26
- /**
27
- *
28
- * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
29
- * @group Errors
30
- */
31
- export class UnexpectedCacheError extends CacheError {
32
- static deserialize(deserializedValue) {
33
- return new UnexpectedCacheError(deserializedValue.message, deserializedValue.cause);
34
- }
35
- constructor(message, cause) {
36
- super(message, { cause });
37
- this.name = UnexpectedCacheError.name;
38
- }
39
14
  }
40
15
  /**
41
16
  * The error is thrown when attempting to increment or decrement a key that is not of number type.
@@ -44,9 +19,6 @@ export class UnexpectedCacheError extends CacheError {
44
19
  * @group Errors
45
20
  */
46
21
  export class TypeCacheError extends CacheError {
47
- static deserialize(deserializedValue) {
48
- return new TypeCacheError(deserializedValue.message, deserializedValue.cause);
49
- }
50
22
  constructor(message, cause) {
51
23
  super(message, { cause });
52
24
  this.name = TypeCacheError.name;
@@ -59,9 +31,6 @@ export class TypeCacheError extends CacheError {
59
31
  * @group Errors
60
32
  */
61
33
  export class KeyNotFoundCacheError extends CacheError {
62
- static deserialize(deserializedValue) {
63
- return new KeyNotFoundCacheError(deserializedValue.message, deserializedValue.cause);
64
- }
65
34
  constructor(message, cause) {
66
35
  super(message, { cause });
67
36
  this.name = KeyNotFoundCacheError.name;
@@ -74,23 +43,7 @@ export class KeyNotFoundCacheError extends CacheError {
74
43
  */
75
44
  export const CACHE_ERRORS = {
76
45
  Base: CacheError,
77
- Unexpected: UnexpectedCacheError,
78
46
  Type: TypeCacheError,
79
47
  KeyNotFound: KeyNotFoundCacheError,
80
48
  };
81
- /**
82
- * The `registerCacheErrorsToSerde` function registers all {@link ICache | `ICache`} related errors with `ISerderRegister`, ensuring they will properly be serialized and deserialized.
83
- *
84
- * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
85
- * @group Errors
86
- */
87
- export function registerCacheErrorsToSerde(serde) {
88
- for (const serde_ of resolveOneOrMore(serde)) {
89
- serde_
90
- .registerClass(CacheError, CORE)
91
- .registerClass(UnexpectedCacheError, CORE)
92
- .registerClass(TypeCacheError, CORE)
93
- .registerClass(KeyNotFoundCacheError, CORE);
94
- }
95
- }
96
49
  //# sourceMappingURL=cache.errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache.errors.js","sourceRoot":"","sources":["../../../src/cache/contracts/cache.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EACH,IAAI,EACJ,gBAAgB,GAGnB,MAAM,gCAAgC,CAAC;AAExC;;;;GAIG;AACH,MAAM,OAAO,UACT,SAAQ,KAAK;IAGb,MAAM,CAAC,WAAW,CAAC,iBAAmC;QAClD,OAAO,IAAI,UAAU,CACjB,iBAAiB,CAAC,OAAO,EACzB,iBAAiB,CAAC,KAAK,CAC1B,CAAC;IACN,CAAC;IAED,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,SAAS;QACL,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SACpB,CAAC;IACN,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,oBACT,SAAQ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U,0BAA0B,CACtC,KAAiC;IAEjC,KAAK,MAAM,MAAM,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,MAAM;aACD,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC;aAC/B,aAAa,CAAC,oBAAoB,EAAE,IAAI,CAAC;aACzC,aAAa,CAAC,cAAc,EAAE,IAAI,CAAC;aACnC,aAAa,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"cache.errors.js","sourceRoot":"","sources":["../../../src/cache/contracts/cache.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC1C,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC;IACpC,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACjD,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC;IAC3C,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,qBAAqB;CAC5B,CAAC"}
@@ -48,42 +48,42 @@ export type IDatabaseCacheAdapter<TType = unknown> = {
48
48
  /**
49
49
  * The `find` method returns the the `key` data which includs {@link ICacheData | `ICacheData.value`} and {@link ICacheData | `ICacheData.expiration`}.
50
50
  */
51
- find(key: string): PromiseLike<ICacheData<TType> | null>;
51
+ find(key: string): Promise<ICacheData<TType> | null>;
52
52
  /**
53
53
  * The `insert` method inserts the given cache `data`.
54
54
  */
55
- insert(data: ICacheInsert<TType>): PromiseLike<void>;
55
+ insert(data: ICacheInsert<TType>): Promise<void>;
56
56
  /**
57
57
  * The `upsert` method inserts a key and if the key already exists then key will be updated with new `data.value` and `data.expiration`.
58
58
  * The method always returns the old cache data if it exists otherwise null will be returned.
59
59
  */
60
- upsert(data: ICacheInsert<TType>): PromiseLike<ICacheDataExpiration | null>;
60
+ upsert(data: ICacheInsert<TType>): Promise<ICacheDataExpiration | null>;
61
61
  /**
62
62
  * The `removeExpiredMany` method updates a expired `key`.
63
63
  */
64
- updateExpired(data: ICacheInsert<TType>): PromiseLike<number>;
64
+ updateExpired(data: ICacheInsert<TType>): Promise<number>;
65
65
  /**
66
66
  * The `removeExpiredMany` method updates a unexpired `key`.
67
67
  */
68
- updateUnexpired(data: ICacheUpdate<TType>): PromiseLike<number>;
68
+ updateUnexpired(data: ICacheUpdate<TType>): Promise<number>;
69
69
  /**
70
70
  * The `incrementUnexpired` should always throw an error if the existing item is not a number type.
71
71
  */
72
- incrementUnexpired(data: ICacheUpdate<number>): PromiseLike<number>;
72
+ incrementUnexpired(data: ICacheUpdate<number>): Promise<number>;
73
73
  /**
74
74
  * The `removeExpiredMany` method removes multiple expired `keys`.
75
75
  */
76
- removeExpiredMany(keys: string[]): PromiseLike<number>;
76
+ removeExpiredMany(keys: string[]): Promise<number>;
77
77
  /**
78
78
  * The `removeExpiredMany` method removes multiple unexpired `keys`.
79
79
  */
80
- removeUnexpiredMany(keys: string[]): PromiseLike<number>;
80
+ removeUnexpiredMany(keys: string[]): Promise<number>;
81
81
  /**
82
82
  * The `removeAll` method removes all keys from the cache.
83
83
  */
84
- removeAll(): PromiseLike<void>;
84
+ removeAll(): Promise<void>;
85
85
  /**
86
86
  * The `removeByKeyPrefix` method removes all the keys in the cache that starts with the given `prefix`.
87
87
  */
88
- removeByKeyPrefix(prefix: string): PromiseLike<void>;
88
+ removeByKeyPrefix(prefix: string): Promise<void>;
89
89
  };
@@ -11,7 +11,7 @@ import type { Kysely } from "kysely";
11
11
  * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"`
12
12
  * @group Adapters
13
13
  */
14
- type KyselyCacheAdapterTable = {
14
+ export type KyselyCacheAdapterTable = {
15
15
  key: string;
16
16
  value: string;
17
17
  expiration: number | string | null;
@@ -21,7 +21,7 @@ type KyselyCacheAdapterTable = {
21
21
  * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"`
22
22
  * @group Adapters
23
23
  */
24
- type KyselyCacheAdapterTables = {
24
+ export type KyselyCacheAdapterTables = {
25
25
  cache: KyselyCacheAdapterTable;
26
26
  };
27
27
  /**
@@ -29,7 +29,7 @@ type KyselyCacheAdapterTables = {
29
29
  * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"`
30
30
  * @group Adapters
31
31
  */
32
- type KyselyCacheAdapterSettings = {
32
+ export type KyselyCacheAdapterSettings = {
33
33
  kysely: Kysely<KyselyCacheAdapterTables>;
34
34
  serde: ISerde<string>;
35
35
  /**
@@ -40,11 +40,13 @@ type KyselyCacheAdapterSettings = {
40
40
  */
41
41
  expiredKeysRemovalInterval?: TimeSpan;
42
42
  /**
43
- * @default {true}
43
+ * @default true
44
44
  */
45
45
  shouldRemoveExpiredKeys?: boolean;
46
46
  };
47
47
  /**
48
+ * To utilize the `KyselyCacheAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
49
+ * The adapter have been tested with `sqlite`, `postgres` and `mysql` databases.
48
50
  *
49
51
  * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"`
50
52
  * @group Adapters
@@ -95,4 +97,3 @@ export declare class KyselyCacheAdapter<TType = unknown> implements IDatabaseCac
95
97
  removeAll(): Promise<void>;
96
98
  removeByKeyPrefix(prefix: string): Promise<void>;
97
99
  }
98
- export {};
@@ -5,6 +5,8 @@ import { TypeCacheError, } from "../../../../cache/contracts/_module-exports.js"
5
5
  import { MysqlAdapter, Transaction } from "kysely";
6
6
  import { TimeSpan } from "../../../../utilities/_module-exports.js";
7
7
  /**
8
+ * To utilize the `KyselyCacheAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
9
+ * The adapter have been tested with `sqlite`, `postgres` and `mysql` databases.
8
10
  *
9
11
  * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"`
10
12
  * @group Adapters
@@ -14,7 +16,7 @@ export class KyselyCacheAdapter {
14
16
  return (eb) => {
15
17
  const hasNoExpiration = eb("cache.expiration", "is", null);
16
18
  const hasExpiration = eb("cache.expiration", "is not", null);
17
- const hasNotExpired = eb("cache.expiration", ">", new Date().getTime());
19
+ const hasNotExpired = eb("cache.expiration", ">", Date.now());
18
20
  const keysMatch = eb("cache.key", "in", keys);
19
21
  return eb.and([
20
22
  keysMatch,
@@ -29,7 +31,7 @@ export class KyselyCacheAdapter {
29
31
  return (eb) => {
30
32
  const keysMatch = eb("cache.key", "in", keys);
31
33
  const hasExpiration = eb("cache.expiration", "is not", null);
32
- const hasExpired = eb("cache.expiration", "<=", new Date().getTime());
34
+ const hasExpired = eb("cache.expiration", "<=", Date.now());
33
35
  return eb.and([keysMatch, hasExpiration, hasExpired]);
34
36
  };
35
37
  }
@@ -71,24 +73,23 @@ export class KyselyCacheAdapter {
71
73
  async removeAllExpired() {
72
74
  await this.kysely
73
75
  .deleteFrom("cache")
74
- .where("cache.expiration", "<=", new Date().getTime())
76
+ .where("cache.expiration", "<=", Date.now())
75
77
  .execute();
76
78
  }
77
79
  async init() {
78
- // Should not throw if the table already exists thats why the try catch is used.
80
+ // Should throw if the table already exists thats why the try catch is used.
79
81
  try {
80
82
  await this.kysely.schema
81
83
  .createTable("cache")
82
- .ifNotExists()
83
84
  .addColumn("key", "varchar(255)", (col) => col.primaryKey())
84
- .addColumn("value", "varchar(255)")
85
+ .addColumn("value", "varchar(255)", (col) => col.notNull())
85
86
  .addColumn("expiration", "bigint")
86
87
  .execute();
87
88
  }
88
89
  catch {
89
90
  /* EMPTY */
90
91
  }
91
- // Should not throw if the index already exists thats why the try catch is used.
92
+ // Should throw if the index already exists thats why the try catch is used.
92
93
  try {
93
94
  await this.kysely.schema
94
95
  .createIndex("cache_expiration")
@@ -100,7 +101,7 @@ export class KyselyCacheAdapter {
100
101
  /* EMPTY */
101
102
  }
102
103
  if (this.shouldRemoveExpiredKeys && this.timeoutId === null) {
103
- this.timeoutId = setTimeout(() => {
104
+ this.timeoutId = setInterval(() => {
104
105
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
105
106
  this.removeAllExpired();
106
107
  }, this.expiredKeysRemovalInterval.toMilliseconds());
@@ -110,7 +111,7 @@ export class KyselyCacheAdapter {
110
111
  if (this.shouldRemoveExpiredKeys && this.timeoutId !== null) {
111
112
  clearTimeout(this.timeoutId);
112
113
  }
113
- // Should not throw if the index does not exists thats why the try catch is used.
114
+ // Should throw if the index does not exists thats why the try catch is used.
114
115
  try {
115
116
  await this.kysely.schema
116
117
  .dropIndex("cache_expiration")
@@ -120,7 +121,7 @@ export class KyselyCacheAdapter {
120
121
  catch {
121
122
  /* EMPTY */
122
123
  }
123
- // Should not throw if the table does not exists thats why the try catch is used.
124
+ // Should throw if the table does not exists thats why the try catch is used.
124
125
  try {
125
126
  await this.kysely.schema.dropTable("cache").execute();
126
127
  }
@@ -139,7 +140,7 @@ export class KyselyCacheAdapter {
139
140
  }
140
141
  return {
141
142
  value: this.serde.deserialize(row.value),
142
- expiration: row.expiration
143
+ expiration: row.expiration !== null
143
144
  ? new Date(Number(row.expiration))
144
145
  : null,
145
146
  };
@@ -158,7 +159,10 @@ export class KyselyCacheAdapter {
158
159
  if (this.disableTransaction) {
159
160
  return fn(this.kysely);
160
161
  }
161
- return await this.kysely.transaction().execute(fn);
162
+ return await this.kysely
163
+ .transaction()
164
+ .setIsolationLevel("serializable")
165
+ .execute(fn);
162
166
  }
163
167
  async upsert(data) {
164
168
  const expiration = data.expiration?.getTime() ?? null;
@@ -190,7 +194,7 @@ export class KyselyCacheAdapter {
190
194
  }
191
195
  return {
192
196
  value: this.serde.deserialize(prevRow.value),
193
- expiration: prevRow.expiration
197
+ expiration: prevRow.expiration !== null
194
198
  ? new Date(Number(prevRow.expiration))
195
199
  : null,
196
200
  };