@daiso-tech/core 0.45.0 → 0.47.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 -44
- package/dist/cache/contracts/cache-adapter.contract.d.ts +1 -1
- package/dist/cache/contracts/cache.events.d.ts +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 +34 -20
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +143 -139
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.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/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/database-cache-dapter.test-suite.d.ts +0 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +219 -630
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.d.ts +11 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.js +13 -3
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.d.ts +6 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.js +14 -2
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.js.map +1 -1
- package/dist/circuit-breaker/implementations/policies/sampling-breaker/sampling-breaker.d.ts +1 -1
- package/dist/collection/contracts/async-collection.contract.d.ts +1 -1
- package/dist/collection/contracts/collection.contract.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-while-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-partion-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/chunk-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/chunk-while-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/partion-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +1 -1
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/hooks/async-hooks.d.ts +9 -11
- package/dist/hooks/hooks.d.ts +5 -5
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +11 -0
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +18 -14
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/namespace/implementations/namespace.d.ts +1 -1
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/kysely-rate-limiter-storage-adapter.d.ts +11 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/kysely-rate-limiter-storage-adapter.js +13 -3
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/kysely-rate-limiter-storage-adapter.js.map +1 -1
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.d.ts +6 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.js +14 -2
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.js.map +1 -1
- package/dist/resilience/middlewares/dynamic/dynamic.middleware.d.ts +1 -1
- package/dist/resilience/middlewares/fallback/fallback.middleware.d.ts +1 -1
- package/dist/resilience/middlewares/fallback/fallback.types.d.ts +4 -4
- package/dist/resilience/middlewares/observe/observe.middleware.d.ts +1 -1
- package/dist/resilience/middlewares/observe/observe.types.d.ts +7 -7
- package/dist/resilience/middlewares/retry/retry.middleware.d.ts +1 -1
- package/dist/resilience/middlewares/retry/retry.middleware.js.map +1 -1
- package/dist/resilience/middlewares/retry/retry.types.d.ts +6 -6
- package/dist/resilience/middlewares/timeout/timeout.middleware.d.ts +1 -1
- package/dist/resilience/middlewares/timeout/timeout.type.d.ts +4 -4
- package/dist/resilience/resilience.errors.d.ts +1 -1
- package/dist/resilience/resilience.errors.js.map +1 -1
- package/dist/semaphore/contracts/database-semaphore-adapter.contract.d.ts +2 -2
- package/dist/semaphore/contracts/semaphore-state.contract.d.ts +3 -3
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.d.ts +12 -1
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js +18 -14
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js.map +1 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +1 -1
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.d.ts +2 -2
- package/dist/shared-lock/contracts/shared-lock-state.contract.d.ts +3 -3
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.d.ts +11 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js +16 -6
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js.map +1 -1
- package/dist/task/implementations/task.d.ts +9 -9
- package/dist/task/implementations/task.js.map +1 -1
- package/dist/utilities/contracts/sqlite-database.contract.d.ts +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/dist/utilities/functions/invokable.d.ts +9 -9
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/dist/utilities/functions/resolve-one-or-more.d.ts +1 -1
- package/dist/utilities/types/any-class.type.d.ts +1 -1
- package/dist/utilities/types/none-func.type.d.ts +1 -1
- package/package.json +38 -56
package/README.md
CHANGED
|
@@ -1,64 +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.
|
|
21
|
-
|
|
22
|
-
- **Type safe:**
|
|
23
|
-
We pay a closer look at type-safety, seamless intellisense, and support for auto imports when designing library APIs.
|
|
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.
|
|
24
10
|
|
|
25
|
-
- **
|
|
26
|
-
@daiso-tech/core leverages modern JavaScript primitives, including ES modules
|
|
11
|
+
[**Explore the Docs**](https://daiso-core.vercel.app/docs/Installation) | [**NPM Package**](https://www.npmjs.com/package/@daiso-tech/core)
|
|
27
12
|
|
|
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.
|
|
13
|
+
---
|
|
30
14
|
|
|
31
|
-
|
|
15
|
+
## 🚀 Key Features
|
|
32
16
|
|
|
33
|
-
|
|
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.
|
|
34
22
|
|
|
35
|
-
|
|
36
|
-
Speed up your applications by storing slowly changing data in a cache store.
|
|
23
|
+
---
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
Easily send events accross different applications or in-memory.
|
|
25
|
+
## 🛠 Quick Start
|
|
40
26
|
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
```bash
|
|
28
|
+
npm install @daiso-tech/core
|
|
29
|
+
```
|
|
43
30
|
|
|
44
|
-
|
|
45
|
-
A Rate-limiter is a resilience primitive used to control the rate of traffic sent or received by a network interface or a service.
|
|
31
|
+
## 📦 Core Components
|
|
46
32
|
|
|
47
|
-
-
|
|
48
|
-
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:
|
|
49
34
|
|
|
50
|
-
|
|
51
|
-
|
|
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. |
|
|
52
43
|
|
|
53
|
-
|
|
54
|
-
|
|
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. |
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
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). |
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
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
|
+
---
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
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
|
|
64
67
|
|
|
68
|
+
```bash
|
|
69
|
+
npm install @daiso-tech/core
|
|
70
|
+
```
|
|
@@ -42,7 +42,7 @@ export type ICacheAdapter<TType = unknown> = {
|
|
|
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
|
|
45
|
+
removeMany(keys: Array<string>): Promise<boolean>;
|
|
46
46
|
/**
|
|
47
47
|
* The `removeAll` method removes all keys from the cache.
|
|
48
48
|
*/
|
|
@@ -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: Array<string>): Promise<Array<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
|
|
@@ -45,7 +42,27 @@ export type KyselyCacheAdapterSettings = {
|
|
|
45
42
|
* @default true
|
|
46
43
|
*/
|
|
47
44
|
shouldRemoveExpiredKeys?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* @default
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { Transaction } from "kysely"
|
|
49
|
+
*
|
|
50
|
+
* !(settings.kysely instanceof Transaction)
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
enableTransactions?: boolean;
|
|
48
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare class DatabaseCacheTransaction<TType> implements IDatabaseCacheTransaction<TType> {
|
|
59
|
+
private readonly kysely;
|
|
60
|
+
private readonly serde;
|
|
61
|
+
private readonly isMysql;
|
|
62
|
+
constructor(kysely: Kysely<KyselyCacheTables>, serde: ISerde<string>);
|
|
63
|
+
find(key: string): Promise<ICacheData<TType> | null>;
|
|
64
|
+
upsert(key: string, value: TType, expiration?: Date | null): Promise<void>;
|
|
65
|
+
}
|
|
49
66
|
/**
|
|
50
67
|
* To utilize the `KyselyCacheAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
|
|
51
68
|
* The adapter have been tested with `sqlite`, `postgres` and `mysql` databases.
|
|
@@ -54,14 +71,13 @@ export type KyselyCacheAdapterSettings = {
|
|
|
54
71
|
* @group Adapters
|
|
55
72
|
*/
|
|
56
73
|
export declare class KyselyCacheAdapter<TType = unknown> implements IDatabaseCacheAdapter<TType>, IInitizable, IDeinitizable, IPrunable {
|
|
57
|
-
private
|
|
58
|
-
private static filterExpiredKeys;
|
|
74
|
+
private readonly isMysql;
|
|
59
75
|
private readonly serde;
|
|
60
76
|
private readonly kysely;
|
|
61
77
|
private readonly shouldRemoveExpiredKeys;
|
|
62
78
|
private readonly expiredKeysRemovalInterval;
|
|
63
79
|
private timeoutId;
|
|
64
|
-
private readonly
|
|
80
|
+
private readonly enableTransactions;
|
|
65
81
|
/**
|
|
66
82
|
* @example
|
|
67
83
|
* ```ts
|
|
@@ -93,14 +109,12 @@ export declare class KyselyCacheAdapter<TType = unknown> implements IDatabaseCac
|
|
|
93
109
|
*/
|
|
94
110
|
deInit(): Promise<void>;
|
|
95
111
|
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>;
|
|
112
|
+
private _transaction;
|
|
113
|
+
transaction<TValue>(trxFn: InvokableFn<[
|
|
114
|
+
trx: IDatabaseCacheTransaction<TType>
|
|
115
|
+
], Promise<TValue>>): Promise<TValue>;
|
|
116
|
+
update(key: string, value: TType): Promise<ICacheDataExpiration | null>;
|
|
117
|
+
removeMany(keys: Array<string>): Promise<Array<ICacheDataExpiration>>;
|
|
104
118
|
removeAll(): Promise<void>;
|
|
105
119
|
removeByKeyPrefix(prefix: string): Promise<void>;
|
|
106
120
|
}
|