@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.
- package/README.md +50 -41
- package/dist/cache/contracts/cache.errors.d.ts +3 -3
- package/dist/cache/contracts/cache.errors.js +1 -1
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/contracts/cache.events.d.ts +8 -8
- package/dist/cache/contracts/cache.events.js +1 -1
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +10 -48
- package/dist/cache/contracts/database-cache-adapter.contract.js +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.js.map +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +24 -19
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +138 -134
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +2 -8
- package/dist/cache/implementations/derivables/cache/cache.js +3 -8
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +3 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +49 -64
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js +5 -10
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +2 -2
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +2 -4
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +240 -238
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +141 -36
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.d.ts +0 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +215 -630
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.d.ts +3 -3
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.d.ts +11 -8
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js +3 -8
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.d.ts +4 -4
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js +2 -4
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js +2 -4
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +2 -8
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +3 -8
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +2 -2
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +2 -4
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/lock/contracts/lock.errors.d.ts +4 -4
- package/dist/lock/contracts/lock.errors.js +1 -1
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +11 -8
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +3 -8
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +4 -4
- package/dist/lock/implementations/derivables/lock-provider/lock.js +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +2 -4
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/namespace/contracts/_module-exports.d.ts +1 -0
- package/dist/namespace/contracts/_module-exports.js +2 -0
- package/dist/namespace/contracts/_module-exports.js.map +1 -0
- package/dist/namespace/contracts/_module.d.ts +1 -0
- package/dist/namespace/contracts/_module.js +2 -0
- package/dist/namespace/contracts/_module.js.map +1 -0
- package/dist/namespace/contracts/namespace.contract.d.ts +17 -0
- package/dist/namespace/contracts/namespace.contract.js +5 -0
- package/dist/namespace/contracts/namespace.contract.js.map +1 -0
- package/dist/namespace/implementations/_module-exports.d.ts +2 -0
- package/dist/namespace/implementations/_module-exports.js +3 -0
- package/dist/namespace/implementations/_module-exports.js.map +1 -0
- package/dist/namespace/implementations/_module.d.ts +2 -0
- package/dist/namespace/implementations/_module.js +3 -0
- package/dist/namespace/implementations/_module.js.map +1 -0
- package/dist/namespace/{namespace.d.ts → implementations/namespace.d.ts} +18 -33
- package/dist/namespace/{namespace.js → implementations/namespace.js} +20 -4
- package/dist/namespace/implementations/namespace.js.map +1 -0
- package/dist/namespace/implementations/no-op-namespace.d.ts +14 -0
- package/dist/namespace/implementations/no-op-namespace.js +34 -0
- package/dist/namespace/implementations/no-op-namespace.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.d.ts +21 -9
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js +30 -10
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.d.ts +38 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.js +75 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.d.ts +21 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js +25 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.d.ts +2 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js +2 -4
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.d.ts +2 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js +2 -4
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.errors.d.ts +4 -4
- package/dist/semaphore/contracts/semaphore.errors.js +1 -1
- package/dist/semaphore/contracts/semaphore.errors.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.d.ts +11 -8
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js +3 -8
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.d.ts +2 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.d.ts +4 -4
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.d.ts +2 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js +2 -4
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.errors.d.ts +7 -7
- package/dist/shared-lock/contracts/shared-lock.errors.js +1 -1
- package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.d.ts +11 -8
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js +3 -8
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.d.ts +2 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.d.ts +4 -4
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.d.ts +2 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js +2 -4
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +1 -1
- package/dist/task/implementations/task.d.ts +1 -1
- package/dist/task/implementations/task.js +1 -1
- package/dist/task/implementations/task.js.map +1 -1
- package/dist/time-span/implementations/time-span.d.ts +17 -0
- package/dist/time-span/implementations/time-span.js +27 -1
- package/dist/time-span/implementations/time-span.js.map +1 -1
- package/dist/utilities/functions/error-policy.d.ts +1 -1
- package/dist/utilities/functions/error-policy.js +1 -2
- package/dist/utilities/functions/error-policy.js.map +1 -1
- package/package.json +48 -65
- package/dist/namespace/_module-exports.d.ts +0 -1
- package/dist/namespace/_module-exports.js +0 -2
- package/dist/namespace/_module-exports.js.map +0 -1
- package/dist/namespace/_module.d.ts +0 -1
- package/dist/namespace/_module.js +0 -2
- package/dist/namespace/_module.js.map +0 -1
- package/dist/namespace/namespace.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,61 +1,70 @@
|
|
|
1
|
+
# @daiso-tech/core
|
|
2
|
+
|
|
1
3
|
[](https://www.npmjs.com/package/@daiso-tech/core)
|
|
2
4
|

|
|
3
|
-

|
|
4
6
|
[](https://nodejs.org/api/esm.html)
|
|
5
7
|
[](LICENSE)
|
|
6
8
|
|
|
7
|
-
|
|
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
|
-
- **
|
|
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
|
-
|
|
26
|
-
@daiso-tech/core leverages modern JavaScript primitives, including ES modules
|
|
13
|
+
---
|
|
27
14
|
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
+
---
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
Speed up your applications by storing slowly changing data in a cache store.
|
|
25
|
+
## 🛠 Quick Start
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
```bash
|
|
28
|
+
npm install @daiso-tech/core
|
|
29
|
+
```
|
|
40
30
|
|
|
41
|
-
|
|
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
|
-
-
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
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:
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.errors.js","sourceRoot":"","sources":["../../../src/cache/contracts/cache.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"cache.errors.js","sourceRoot":"","sources":["../../../src/cache/contracts/cache.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAa,MAAM,kCAAkC,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC5C,MAAM,CAAC,MAAM,CAAC,GAAS,EAAE,KAAe;QACpC,OAAO,IAAI,qBAAqB,CAC5B,QAAQ,GAAG,CAAC,GAAG,EAAE,gBAAgB,EACjC,KAAK,CACR,CAAC;IACN,CAAC;IAED;;;;OAIG;IACH,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;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC1C,MAAM,CAAC,MAAM,CAAC,GAAS,EAAE,KAAe;QACpC,OAAO,IAAI,mBAAmB,CAC1B,QAAQ,GAAG,CAAC,GAAG,EAAE,kBAAkB,EACnC,KAAK,CACR,CAAC;IACN,CAAC;IAED;;;;OAIG;IACH,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC;IACzC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,WAAW,EAAE,qBAAqB;CAC5B,CAAC;AASX;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACvC,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Cache
|
|
3
3
|
*/
|
|
4
|
-
import { type
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
72
|
+
key: IKey;
|
|
73
73
|
value: number;
|
|
74
74
|
};
|
|
75
75
|
/**
|
|
@@ -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,
|
|
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
|
|
19
|
-
|
|
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
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 +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
|
|
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
|
|
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
|
|
25
|
-
cache:
|
|
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<
|
|
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
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
}
|