@daiso-tech/core 0.44.0 → 0.46.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 (153) hide show
  1. package/README.md +50 -41
  2. package/dist/cache/contracts/cache.errors.d.ts +3 -3
  3. package/dist/cache/contracts/cache.errors.js +1 -1
  4. package/dist/cache/contracts/cache.errors.js.map +1 -1
  5. package/dist/cache/contracts/cache.events.d.ts +8 -8
  6. package/dist/cache/contracts/cache.events.js +1 -1
  7. package/dist/cache/contracts/cache.events.js.map +1 -1
  8. package/dist/cache/contracts/database-cache-adapter.contract.d.ts +10 -48
  9. package/dist/cache/contracts/database-cache-adapter.contract.js +1 -1
  10. package/dist/cache/contracts/database-cache-adapter.contract.js.map +1 -1
  11. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +24 -19
  12. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +138 -134
  13. package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
  14. package/dist/cache/implementations/derivables/cache/cache.d.ts +2 -8
  15. package/dist/cache/implementations/derivables/cache/cache.js +3 -8
  16. package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
  17. package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +3 -1
  18. package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +49 -64
  19. package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -1
  20. package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js +5 -10
  21. package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js.map +1 -1
  22. package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +2 -2
  23. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +2 -4
  24. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
  25. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +240 -238
  26. package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
  27. package/dist/cache/implementations/test-utilities/cache.test-suite.js +141 -36
  28. package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
  29. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.d.ts +0 -1
  30. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +215 -630
  31. package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
  32. package/dist/circuit-breaker/contracts/circuit-breaker.errors.d.ts +3 -3
  33. package/dist/circuit-breaker/contracts/circuit-breaker.errors.js +1 -1
  34. package/dist/circuit-breaker/contracts/circuit-breaker.errors.js.map +1 -1
  35. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.d.ts +11 -8
  36. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js +3 -8
  37. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js.map +1 -1
  38. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.d.ts +2 -2
  39. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js +1 -1
  40. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js.map +1 -1
  41. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.d.ts +4 -4
  42. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js +1 -1
  43. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js.map +1 -1
  44. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.d.ts +2 -2
  45. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js +2 -4
  46. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js.map +1 -1
  47. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.d.ts +2 -2
  48. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js +2 -4
  49. package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js.map +1 -1
  50. package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +2 -8
  51. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +3 -8
  52. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
  53. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +2 -2
  54. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +2 -4
  55. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
  56. package/dist/lock/contracts/lock.errors.d.ts +4 -4
  57. package/dist/lock/contracts/lock.errors.js +1 -1
  58. package/dist/lock/contracts/lock.errors.js.map +1 -1
  59. package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +11 -8
  60. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +3 -8
  61. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
  62. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +2 -2
  63. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +1 -1
  64. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
  65. package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +4 -4
  66. package/dist/lock/implementations/derivables/lock-provider/lock.js +1 -1
  67. package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
  68. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +2 -2
  69. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +2 -4
  70. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
  71. package/dist/namespace/contracts/_module-exports.d.ts +1 -0
  72. package/dist/namespace/contracts/_module-exports.js +2 -0
  73. package/dist/namespace/contracts/_module-exports.js.map +1 -0
  74. package/dist/namespace/contracts/_module.d.ts +1 -0
  75. package/dist/namespace/contracts/_module.js +2 -0
  76. package/dist/namespace/contracts/_module.js.map +1 -0
  77. package/dist/namespace/contracts/namespace.contract.d.ts +17 -0
  78. package/dist/namespace/contracts/namespace.contract.js +5 -0
  79. package/dist/namespace/contracts/namespace.contract.js.map +1 -0
  80. package/dist/namespace/implementations/_module-exports.d.ts +2 -0
  81. package/dist/namespace/implementations/_module-exports.js +3 -0
  82. package/dist/namespace/implementations/_module-exports.js.map +1 -0
  83. package/dist/namespace/implementations/_module.d.ts +2 -0
  84. package/dist/namespace/implementations/_module.js +3 -0
  85. package/dist/namespace/implementations/_module.js.map +1 -0
  86. package/dist/namespace/{namespace.d.ts → implementations/namespace.d.ts} +18 -33
  87. package/dist/namespace/{namespace.js → implementations/namespace.js} +20 -4
  88. package/dist/namespace/implementations/namespace.js.map +1 -0
  89. package/dist/namespace/implementations/no-op-namespace.d.ts +14 -0
  90. package/dist/namespace/implementations/no-op-namespace.js +34 -0
  91. package/dist/namespace/implementations/no-op-namespace.js.map +1 -0
  92. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.d.ts +21 -9
  93. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js +30 -10
  94. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js.map +1 -1
  95. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.d.ts +38 -0
  96. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.js +75 -0
  97. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.js.map +1 -0
  98. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.d.ts +21 -2
  99. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js +25 -2
  100. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js.map +1 -1
  101. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.d.ts +2 -2
  102. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js +2 -4
  103. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js.map +1 -1
  104. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.d.ts +2 -2
  105. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js +2 -4
  106. package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js.map +1 -1
  107. package/dist/semaphore/contracts/semaphore.errors.d.ts +4 -4
  108. package/dist/semaphore/contracts/semaphore.errors.js +1 -1
  109. package/dist/semaphore/contracts/semaphore.errors.js.map +1 -1
  110. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.d.ts +11 -8
  111. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js +3 -8
  112. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +1 -1
  113. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.d.ts +2 -2
  114. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js +1 -1
  115. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +1 -1
  116. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.d.ts +4 -4
  117. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js +1 -1
  118. package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +1 -1
  119. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.d.ts +2 -2
  120. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js +2 -4
  121. package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +1 -1
  122. package/dist/shared-lock/contracts/shared-lock.errors.d.ts +7 -7
  123. package/dist/shared-lock/contracts/shared-lock.errors.js +1 -1
  124. package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -1
  125. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.d.ts +11 -8
  126. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js +3 -8
  127. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +1 -1
  128. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.d.ts +2 -2
  129. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js +1 -1
  130. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +1 -1
  131. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.d.ts +4 -4
  132. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js +1 -1
  133. package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +1 -1
  134. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.d.ts +2 -2
  135. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js +2 -4
  136. package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +1 -1
  137. package/dist/task/implementations/task.d.ts +1 -1
  138. package/dist/task/implementations/task.js +1 -1
  139. package/dist/task/implementations/task.js.map +1 -1
  140. package/dist/time-span/implementations/time-span.d.ts +17 -0
  141. package/dist/time-span/implementations/time-span.js +27 -1
  142. package/dist/time-span/implementations/time-span.js.map +1 -1
  143. package/dist/utilities/functions/error-policy.d.ts +1 -1
  144. package/dist/utilities/functions/error-policy.js +1 -2
  145. package/dist/utilities/functions/error-policy.js.map +1 -1
  146. package/package.json +48 -65
  147. package/dist/namespace/_module-exports.d.ts +0 -1
  148. package/dist/namespace/_module-exports.js +0 -2
  149. package/dist/namespace/_module-exports.js.map +0 -1
  150. package/dist/namespace/_module.d.ts +0 -1
  151. package/dist/namespace/_module.js +0 -2
  152. package/dist/namespace/_module.js.map +0 -1
  153. package/dist/namespace/namespace.js.map +0 -1
package/README.md CHANGED
@@ -1,61 +1,70 @@
1
+ # @daiso-tech/core
2
+
1
3
  [![npm version](https://img.shields.io/npm/v/@daiso-tech/core)](https://www.npmjs.com/package/@daiso-tech/core)
2
4
  ![NPM Downloads](https://img.shields.io/npm/dy/@daiso-tech/core)
3
- ![Static Badge](https://img.shields.io/badge/TypeScript-3178C6?logo=TypeScript&logoColor=white)
5
+ ![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=TypeScript&logoColor=white)
4
6
  [![ES Modules](https://img.shields.io/badge/module%20type-ESM-blue)](https://nodejs.org/api/esm.html)
5
7
  [![License](https://img.shields.io/npm/l/@daiso-tech/core)](LICENSE)
6
8
 
7
- # @daiso-tech/core
8
-
9
- `@daiso-tech/core` is a TypeScript-first backend library for building web apps and API servers. It includes an ecosystem of official packages designed to work seamlessly together.
10
-
11
- **@daiso-tech/core** is a library of backend server components designed for maximum flexibility. While each component is fully functional on its own, they are written to work seamlessly together to build robust server-side logic.
12
-
13
- Key Features:
14
- - **Framework Agnostic:** Built without a dependency injection (DI) container, the library integrates effortlessly into any framework / library. Whether you use Express.js, backend frameworks like AdonisJS or NestJS, or full-stack frameworks like Next.js, Nuxt, or TanStack Start, these components "just work."
15
-
16
- - **Runtime Portability:** By leveraging the Adapter Pattern, the library remains decoupled from specific runtimes. Easily implement custom adapters, such as Cloudflare Durable Objects or Amazon DynamoDB, for better serverless integration with cloudflare workers or aws lambda.
17
-
18
- - **Test Friendly:** Testing is simple because every component comes with an "in-memory" adapter. This means you can run your tests instantly without needing to connect to a real database or server.
19
-
20
- - **Developer Friendly:** Save time with high-quality documentation and a readable, well-documented codebase. Clear comments and a logical structure make it easy to understand and extend system functionality.
9
+ `@daiso-tech/core` is a **TypeScript-first backend toolkit** designed for building resilient web applications and API servers. It provides a suite of decoupled, high-performance components that work seamlessly across any JavaScript runtime.
21
10
 
22
- - **Type safe:**
23
- We pay a closer look at type-safety, seamless intellisense, and support for auto imports when designing library APIs.
11
+ [**Explore the Docs**](https://daiso-core.vercel.app/docs/Installation) | [**NPM Package**](https://www.npmjs.com/package/@daiso-tech/core)
24
12
 
25
- - **ESM ready:**
26
- @daiso-tech/core leverages modern JavaScript primitives, including ES modules
13
+ ---
27
14
 
28
- - **Supports standard schema:**
29
- Integrated seamlessly with [standard schema](https://standardschema.dev/) allowing you to use libraries like zod to ensure both compile time and runtime typesafety.
15
+ ## 🚀 Key Features
30
16
 
31
- [Get started now](https://daiso-core.vercel.app/docs/Installation)
17
+ * **Framework Agnostic** No Dependency Injection (DI) containers required. Effortlessly integrate with Express, NestJS, AdonisJS, or full-stack frameworks like Next.js, Nuxt, and TanStack Start.
18
+ * **Runtime Portability** Leverages the **Adapter Pattern** to decouple your logic from the runtime. Switch between Node.js, Cloudflare Workers (Durable Objects), or AWS Lambda without rewriting core logic.
19
+ * **Test-Driven Excellence** Every component includes a built-in **"in-memory" adapter**. Run unit tests instantly without spinning up databases or external infrastructure.
20
+ * **Type Safety & DX** Deep IntelliSense support and strict type-safety. Designed for auto-imports and modern developer workflows.
21
+ * **Standard Schema Support** Native integration with [Standard Schema](https://standardschema.dev/), allowing you to use **Zod**, **Valibot**, or **ArkType** for unified runtime validation.
32
22
 
33
- ## A growing collection of officially maintained components
23
+ ---
34
24
 
35
- - **Cache:**
36
- Speed up your applications by storing slowly changing data in a cache store.
25
+ ## 🛠 Quick Start
37
26
 
38
- - **EventBus:**
39
- Easily send events accross different applications or in-memory.
27
+ ```bash
28
+ npm install @daiso-tech/core
29
+ ```
40
30
 
41
- - **Circuit-breaker:**
42
- A circuit-breaker is a resilience primitive preventing cascading failures from external services by stopping calls to a failing service.
31
+ ## 📦 Core Components
43
32
 
44
- - **Lock:**
45
- Synchronize the access to a shared resource to prevents several processes, or concurrent code, from executing a section of code at the same time.
33
+ The `@daiso-tech/core` ecosystem provides a growing collection of officially maintained primitives for building robust systems:
46
34
 
47
- - **Semaphore:**
48
- A semaphore is a concurrency control primitive used to limit the number of processes or systems that can access a shared resource of code concurrently.
35
+ ### Resilience
36
+ | | |
37
+ | :--- | :--- |
38
+ | **Circuit Breaker** | Prevents cascading failures by stopping calls to failing external services. |
39
+ | **Rate Limiter** | Controls traffic flow to protect your network interfaces and services. |
40
+ | **Retry** | Retry middleware with support for different backoffs with jitter. |
41
+ | **Timeout** | Timeout middleware that prevents resource exhaustion by killing long-running tasks. |
42
+ | **Fallback** | Fallback middleware that ensures graceful degradation by returning default values. |
49
43
 
50
- - **Shared-lock:**
51
- A shared-lock (a.k.a reader writer lock) is a concurrency primitive offering better concurrency than a lock by coordinating a reader semaphore for concurrent access and an writer lock for mutual exclusion, strictly preventing conflicting simultaneous access and maintaining data consistency.
44
+ ### Concurrency
45
+ | | |
46
+ | :--- | :--- |
47
+ | **Lock** | Ensures mutual exclusion for shared resources across servers or procceses. |
48
+ | **Semaphore** | Limits the number of concurrent servers or procceses accessing a specific resource. |
49
+ | **Shared Lock** | Reader-writer lock coordinating concurrent reads and exclusive writes. |
52
50
 
53
- - **Serde:**
54
- Add custom serialization and deserialization logic that seamlessly integrates with all other components.
51
+ ### Misc
52
+ | | |
53
+ | :--- | :--- |
54
+ | **Cache** | High-performance caching with support for multiple store adapters. |
55
+ | **EventBus** | Decoupled event-driven communication (In-memory or Distributed via redis). |
55
56
 
56
- - **Collection:**
57
- Effortlessly work with Arrays, Iterables, and AsyncIterables. Filter and transform with precision.
57
+ ### Utilities
58
+ | | |
59
+ | :--- | :--- |
60
+ | **Hooks** | Agnostic sync/async middleware that integrates with all components. |
61
+ | **Serde** | Custom serialization/deserialization logic that integrates with all components. |
62
+ | **Collection** | Precision filtering and transformation for Arrays, Iterables, AsyncIterables and ArrayLike objects. |
63
+ | **TimeSpan** | A duration class offering seamless time manipulation while integrating with all components. |
64
+ ---
58
65
 
59
- - **Hooks:**
60
- Extend any sync and async function with agnostic hooks.@daiso-tech/core includes predefined retry, fallback, timeout and hedging hooks to easily allow handling transient failures.
66
+ ## 🛠 Quick Start
61
67
 
68
+ ```bash
69
+ npm install @daiso-tech/core
70
+ ```
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Cache
3
3
  */
4
- import { type Key } from "../../namespace/_module.js";
4
+ import { type IKey } from "../../namespace/contracts/_module.js";
5
5
  /**
6
6
  * The error is thrown when a key is not found
7
7
  *
@@ -9,7 +9,7 @@ import { type Key } from "../../namespace/_module.js";
9
9
  * @group Errors
10
10
  */
11
11
  export declare class KeyNotFoundCacheError extends Error {
12
- static create(key: Key, cause?: unknown): KeyNotFoundCacheError;
12
+ static create(key: IKey, cause?: unknown): KeyNotFoundCacheError;
13
13
  /**
14
14
  * Note: Do not instantiate `KeyNotFoundCacheError` directly via the constructor. Use the static `create()` factory method instead.
15
15
  * The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors.
@@ -24,7 +24,7 @@ export declare class KeyNotFoundCacheError extends Error {
24
24
  * @group Errors
25
25
  */
26
26
  export declare class KeyExistsCacheError extends Error {
27
- static create(key: Key, cause?: unknown): KeyExistsCacheError;
27
+ static create(key: IKey, cause?: unknown): KeyExistsCacheError;
28
28
  /**
29
29
  * Note: Do not instantiate `KeyExistsCacheError` directly via the constructor. Use the static `create()` factory method instead.
30
30
  * The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Cache
3
3
  */
4
- import {} from "../../namespace/_module.js";
4
+ import {} from "../../namespace/contracts/_module.js";
5
5
  /**
6
6
  * The error is thrown when a key is not found
7
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cache.errors.js","sourceRoot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ACjB,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Cache
3
3
  */
4
- import { type Key } from "../../namespace/_module.js";
4
+ import { type IKey } from "../../namespace/contracts/_module.js";
5
5
  import { type TimeSpan } from "../../time-span/implementations/_module.js";
6
6
  /**
7
7
  * The event is dispatched when key is found.
@@ -10,7 +10,7 @@ import { type TimeSpan } from "../../time-span/implementations/_module.js";
10
10
  * @group Events
11
11
  */
12
12
  export type FoundCacheEvent<TType = unknown> = {
13
- key: Key;
13
+ key: IKey;
14
14
  value: TType;
15
15
  };
16
16
  /**
@@ -20,7 +20,7 @@ export type FoundCacheEvent<TType = unknown> = {
20
20
  * @group Events
21
21
  */
22
22
  export type NotFoundCacheEvent = {
23
- key: Key;
23
+ key: IKey;
24
24
  };
25
25
  /**
26
26
  * The event is dispatched when key is added.
@@ -29,7 +29,7 @@ export type NotFoundCacheEvent = {
29
29
  * @group Events
30
30
  */
31
31
  export type AddedCacheEvent<TType = unknown> = {
32
- key: Key;
32
+ key: IKey;
33
33
  value: TType;
34
34
  ttl: TimeSpan | null;
35
35
  };
@@ -40,7 +40,7 @@ export type AddedCacheEvent<TType = unknown> = {
40
40
  * @group Events
41
41
  */
42
42
  export type UpdatedCacheEvent<TType = unknown> = {
43
- key: Key;
43
+ key: IKey;
44
44
  value: TType;
45
45
  };
46
46
  /**
@@ -50,7 +50,7 @@ export type UpdatedCacheEvent<TType = unknown> = {
50
50
  * @group Events
51
51
  */
52
52
  export type RemovedCacheEvent = {
53
- key: Key;
53
+ key: IKey;
54
54
  };
55
55
  /**
56
56
  * The event is dispatched when key is incremented.
@@ -59,7 +59,7 @@ export type RemovedCacheEvent = {
59
59
  * @group Events
60
60
  */
61
61
  export type IncrementedCacheEvent = {
62
- key: Key;
62
+ key: IKey;
63
63
  value: number;
64
64
  };
65
65
  /**
@@ -69,7 +69,7 @@ export type IncrementedCacheEvent = {
69
69
  * @group Events
70
70
  */
71
71
  export type DecrementedCacheEvent = {
72
- key: Key;
72
+ key: IKey;
73
73
  value: number;
74
74
  };
75
75
  /**
@@ -2,7 +2,7 @@
2
2
  * @module Cache
3
3
  */
4
4
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
- import {} from "../../namespace/_module.js";
5
+ import {} from "../../namespace/contracts/_module.js";
6
6
  import {} from "../../time-span/implementations/_module.js";
7
7
  /**
8
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cache.events.js","sourceRoot":"","sources":["../../../src/cache/contracts/cache.events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,6DAA6D;AAC7D,OAAO,EAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAiB,MAAM,wCAAwC,CAAC;AAmGvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;IAClB,gBAAgB,EAAE,kBAAkB;CAC9B,CAAC"}
1
+ {"version":3,"file":"cache.events.js","sourceRoot":"","sources":["../../../src/cache/contracts/cache.events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,6DAA6D;AAC7D,OAAO,EAAa,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAiB,MAAM,wCAAwC,CAAC;AAmGvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;IAClB,gBAAgB,EAAE,kBAAkB;CAC9B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @module Cache
3
3
  */
4
+ import { type InvokableFn } from "../../utilities/_module.js";
4
5
  /**
5
6
  *
6
7
  * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
@@ -11,32 +12,20 @@ export type ICacheData<TType = unknown> = {
11
12
  expiration: Date | null;
12
13
  };
13
14
  /**
14
- *
15
15
  * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
16
16
  * @group Contracts
17
17
  */
18
- export type ICacheDataExpiration = {
19
- expiration: Date | null;
18
+ export type IDatabaseCacheTransaction<TType = unknown> = {
19
+ find(key: string): Promise<ICacheData<TType> | null>;
20
+ upsert(key: string, value: TType, expiration?: Date | null): Promise<void>;
20
21
  };
21
22
  /**
22
- *
23
23
  * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
24
24
  * @group Contracts
25
25
  */
26
- export type ICacheInsert<TType = unknown> = {
27
- key: string;
28
- value: TType;
26
+ export type ICacheDataExpiration = {
29
27
  expiration: Date | null;
30
28
  };
31
- /**
32
- *
33
- * IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
34
- * @group Contracts
35
- */
36
- export type ICacheUpdate<TType = unknown> = {
37
- key: string;
38
- value: TType;
39
- };
40
29
  /**
41
30
  * The `IDatabaseCacheAdapter` contract defines a way for as key-value pairs independent of data storage.
42
31
  * This contract simplifies the implementation of cache adapters with CRUD-based databases, such as SQL databases and ORMs like TypeOrm and MikroOrm.
@@ -45,39 +34,12 @@ export type ICacheUpdate<TType = unknown> = {
45
34
  * @group Contracts
46
35
  */
47
36
  export type IDatabaseCacheAdapter<TType = unknown> = {
48
- /**
49
- * The `find` method returns the the `key` data which includs {@link ICacheData | `ICacheData.value`} and {@link ICacheData | `ICacheData.expiration`}.
50
- */
51
37
  find(key: string): Promise<ICacheData<TType> | null>;
52
- /**
53
- * The `insert` method inserts the given cache `data`.
54
- */
55
- insert(data: ICacheInsert<TType>): Promise<void>;
56
- /**
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
- * The method always returns the old cache data if it exists otherwise null will be returned.
59
- */
60
- upsert(data: ICacheInsert<TType>): Promise<ICacheDataExpiration | null>;
61
- /**
62
- * The `removeExpiredMany` method updates a expired `key`.
63
- */
64
- updateExpired(data: ICacheInsert<TType>): Promise<number>;
65
- /**
66
- * The `removeExpiredMany` method updates a unexpired `key`.
67
- */
68
- updateUnexpired(data: ICacheUpdate<TType>): Promise<number>;
69
- /**
70
- * The `incrementUnexpired` should always throw an error if the existing item is not a number type.
71
- */
72
- incrementUnexpired(data: ICacheUpdate<number>): Promise<number>;
73
- /**
74
- * The `removeExpiredMany` method removes multiple expired `keys`.
75
- */
76
- removeExpiredMany(keys: string[]): Promise<number>;
77
- /**
78
- * The `removeExpiredMany` method removes multiple unexpired `keys`.
79
- */
80
- removeUnexpiredMany(keys: string[]): Promise<number>;
38
+ transaction<TValue>(trxFn: InvokableFn<[
39
+ trx: IDatabaseCacheTransaction<TType>
40
+ ], Promise<TValue>>): Promise<TValue>;
41
+ update(key: string, value: TType): Promise<ICacheDataExpiration | null>;
42
+ removeMany(keys: string[]): Promise<ICacheDataExpiration[]>;
81
43
  /**
82
44
  * The `removeAll` method removes all keys from the cache.
83
45
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * @module Cache
3
3
  */
4
- export {};
4
+ import {} from "../../utilities/_module.js";
5
5
  //# sourceMappingURL=database-cache-adapter.contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"database-cache-adapter.contract.js","sourceRoot":"","sources":["../../../src/cache/contracts/database-cache-adapter.contract.ts"],"names":[],"mappings":"AAAA;;GAEG"}
1
+ {"version":3,"file":"database-cache-adapter.contract.js","sourceRoot":"","sources":["../../../src/cache/contracts/database-cache-adapter.contract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,MAAM,wBAAwB,CAAC"}
@@ -2,35 +2,32 @@
2
2
  * @module Cache
3
3
  */
4
4
  import { type Kysely } from "kysely";
5
- import { type ICacheData, type ICacheInsert, type ICacheUpdate, type IDatabaseCacheAdapter } from "../../../../cache/contracts/_module.js";
5
+ import { type ICacheData, type ICacheDataExpiration, type IDatabaseCacheAdapter, type IDatabaseCacheTransaction } from "../../../../cache/contracts/_module.js";
6
6
  import { type ISerde } from "../../../../serde/contracts/_module.js";
7
7
  import { type ITimeSpan } from "../../../../time-span/contracts/_module.js";
8
- import { type IDeinitizable, type IInitizable, type IPrunable } from "../../../../utilities/_module.js";
8
+ import { type IDeinitizable, type IInitizable, type InvokableFn, type IPrunable } from "../../../../utilities/_module.js";
9
9
  /**
10
- *
11
10
  * IMPORT_PATH: `"@daiso-tech/core/cache/kysely-cache-adapter"`
12
11
  * @group Adapters
13
12
  */
14
- export type KyselyCacheAdapterTable = {
13
+ export type KyselyCacheTable = {
15
14
  key: string;
16
15
  value: string;
17
16
  expiration: number | string | null;
18
17
  };
19
18
  /**
20
- *
21
19
  * IMPORT_PATH: `"@daiso-tech/core/cache/kysely-cache-adapter"`
22
20
  * @group Adapters
23
21
  */
24
- export type KyselyCacheAdapterTables = {
25
- cache: KyselyCacheAdapterTable;
22
+ export type KyselyCacheTables = {
23
+ cache: KyselyCacheTable;
26
24
  };
27
25
  /**
28
- *
29
26
  * IMPORT_PATH: `"@daiso-tech/core/cache/kysely-cache-adapter"`
30
27
  * @group Adapters
31
28
  */
32
29
  export type KyselyCacheAdapterSettings = {
33
- kysely: Kysely<KyselyCacheAdapterTables>;
30
+ kysely: Kysely<KyselyCacheTables>;
34
31
  serde: ISerde<string>;
35
32
  /**
36
33
  * @default
@@ -46,6 +43,17 @@ export type KyselyCacheAdapterSettings = {
46
43
  */
47
44
  shouldRemoveExpiredKeys?: boolean;
48
45
  };
46
+ /**
47
+ * @internal
48
+ */
49
+ export declare class DatabaseCacheTransaction<TType> implements IDatabaseCacheTransaction<TType> {
50
+ private readonly kysely;
51
+ private readonly serde;
52
+ private readonly isMysql;
53
+ constructor(kysely: Kysely<KyselyCacheTables>, serde: ISerde<string>);
54
+ find(key: string): Promise<ICacheData<TType> | null>;
55
+ upsert(key: string, value: TType, expiration?: Date | null): Promise<void>;
56
+ }
49
57
  /**
50
58
  * To utilize the `KyselyCacheAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
51
59
  * The adapter have been tested with `sqlite`, `postgres` and `mysql` databases.
@@ -54,8 +62,7 @@ export type KyselyCacheAdapterSettings = {
54
62
  * @group Adapters
55
63
  */
56
64
  export declare class KyselyCacheAdapter<TType = unknown> implements IDatabaseCacheAdapter<TType>, IInitizable, IDeinitizable, IPrunable {
57
- private static filterUnexpiredKeys;
58
- private static filterExpiredKeys;
65
+ private readonly isMysql;
59
66
  private readonly serde;
60
67
  private readonly kysely;
61
68
  private readonly shouldRemoveExpiredKeys;
@@ -93,14 +100,12 @@ export declare class KyselyCacheAdapter<TType = unknown> implements IDatabaseCac
93
100
  */
94
101
  deInit(): Promise<void>;
95
102
  find(key: string): Promise<ICacheData<TType> | null>;
96
- insert(data: ICacheInsert<TType>): Promise<void>;
97
- private transaction;
98
- upsert(data: ICacheInsert<TType>): Promise<ICacheData<TType> | null>;
99
- updateExpired(data: ICacheInsert<TType>): Promise<number>;
100
- updateUnexpired(data: ICacheUpdate<TType>): Promise<number>;
101
- incrementUnexpired(data: ICacheUpdate<number>): Promise<number>;
102
- removeExpiredMany(keys: string[]): Promise<number>;
103
- removeUnexpiredMany(keys: string[]): Promise<number>;
103
+ private _transaction;
104
+ transaction<TValue>(trxFn: InvokableFn<[
105
+ trx: IDatabaseCacheTransaction<TType>
106
+ ], Promise<TValue>>): Promise<TValue>;
107
+ update(key: string, value: TType): Promise<ICacheDataExpiration | null>;
108
+ removeMany(keys: string[]): Promise<ICacheDataExpiration[]>;
104
109
  removeAll(): Promise<void>;
105
110
  removeByKeyPrefix(prefix: string): Promise<void>;
106
111
  }