@daiso-tech/core 0.30.0 → 0.31.1
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/dist/async/utilities/lazy-promise/lazy-promise.d.ts +16 -12
- package/dist/async/utilities/lazy-promise/lazy-promise.js +16 -12
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +2 -2
- package/dist/cache/implementations/derivables/cache/cache.d.ts +7 -151
- package/dist/cache/implementations/derivables/cache/cache.js +7 -151
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +8 -10
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +8 -10
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +5 -5
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +5 -5
- package/dist/collection/implementations/_shared.d.ts +2 -0
- package/dist/collection/implementations/_shared.js +2 -0
- package/dist/collection/implementations/_shared.js.map +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +5 -5
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +5 -5
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +5 -5
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +5 -5
- 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 +6 -6
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +6 -6
- package/dist/lock/contracts/lock.contract.d.ts +4 -4
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +1 -2
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +1 -2
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +33 -16
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +33 -16
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +0 -204
- package/dist/lock/implementations/derivables/lock-provider/lock.js +0 -204
- 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 +8 -12
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +8 -12
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +1 -2
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +1 -2
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +0 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +0 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +1 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +7 -7
- package/dist/serde/implementations/derivables/serde.js +7 -7
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +0 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +0 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
4
|
import type { BackoffPolicy } from "../../../async/backof-policies/_module.js";
|
|
5
|
-
import type { AsyncLazy, Promisable, TimeSpan } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import type { AsyncLazy, Invokable, InvokableFn, Promisable, TimeSpan } from "../../../utilities/_module-exports.js";
|
|
6
6
|
import type { RetryPolicy } from "../../../async/utilities/retry/_module.js";
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
@@ -56,16 +56,18 @@ export type LazyPromiseSettings<TValue = unknown> = LazyPromiseCallbacks<TValue>
|
|
|
56
56
|
* The <i>LazyPromise</i> class is used for creating lazy <i>{@link PromiseLike}<i> object that will only execute when awaited or when then method is called.
|
|
57
57
|
* The class includes helpful methods
|
|
58
58
|
* - <i>defer</i>
|
|
59
|
-
* - <i>
|
|
60
|
-
* - <i>
|
|
59
|
+
* - <i>setRetryAttempts</i>
|
|
60
|
+
* - <i>setRetryTimeout</i>
|
|
61
|
+
* - <i>setRetryPolicy</i>
|
|
61
62
|
* - <i>backoffPolicy</i>
|
|
62
|
-
* - <i>
|
|
63
|
-
* - <i>
|
|
63
|
+
* - <i>setTotalTimeout</i>
|
|
64
|
+
* - <i>setAbortSignal</i>
|
|
64
65
|
*
|
|
65
66
|
* The order in which these methods are called does not affect their methodality. Internally, the following execution order is applied:
|
|
66
|
-
* 1. <i>
|
|
67
|
-
* 2. <i>
|
|
68
|
-
* 3. <i>
|
|
67
|
+
* 1. <i>setRetryTimeout</i>
|
|
68
|
+
* 2. <i>setRetryAttempts</i>
|
|
69
|
+
* 3. <i>setTotalTimeout</i>
|
|
70
|
+
* 4. <i>setAbortSignal</i>
|
|
69
71
|
*
|
|
70
72
|
* This means that combining all methods ensures the <i>retryAttempts</i> method will continue retrying even if the timeout is triggered,
|
|
71
73
|
* while the <i>abort</i> method takes priority to cancel all operations if activated.
|
|
@@ -75,7 +77,7 @@ export type LazyPromiseSettings<TValue = unknown> = LazyPromiseCallbacks<TValue>
|
|
|
75
77
|
*/
|
|
76
78
|
export declare class LazyPromise<TValue> implements PromiseLike<TValue> {
|
|
77
79
|
/**
|
|
78
|
-
* The <i>wrapFn</i> is convience method used for wrapping
|
|
80
|
+
* The <i>wrapFn</i> is convience method used for wrapping async <i>{@link Invokable}</i> with a <i>LazyPromise</i>.
|
|
79
81
|
* @example
|
|
80
82
|
* ```ts
|
|
81
83
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -86,10 +88,10 @@ export declare class LazyPromise<TValue> implements PromiseLike<TValue> {
|
|
|
86
88
|
*
|
|
87
89
|
* const file = await readFile("none_existing_file.txt")
|
|
88
90
|
* .setRetryAttempts(4)
|
|
89
|
-
* .
|
|
91
|
+
* .setRetryTimeout(TimeSpan.fromMinutes(1));
|
|
90
92
|
* ```
|
|
91
93
|
*/
|
|
92
|
-
static wrapFn<TArgs extends unknown[], TReturn>(fn:
|
|
94
|
+
static wrapFn<TArgs extends unknown[], TReturn>(fn: Invokable<TArgs, Promisable<TReturn>>, settings?: LazyPromiseSettings<TReturn>): InvokableFn<TArgs, LazyPromise<TReturn>>;
|
|
93
95
|
/**
|
|
94
96
|
* The <i>delay</i> method creates a <i>{@link LazyPromise}</i> that will be fulfilled after given <i>time</i>.
|
|
95
97
|
*
|
|
@@ -103,6 +105,7 @@ export declare class LazyPromise<TValue> implements PromiseLike<TValue> {
|
|
|
103
105
|
* console.log("a");
|
|
104
106
|
* await LazyPromise.delay(TimeSpan.fromSeconds(2));
|
|
105
107
|
* console.log("b");
|
|
108
|
+
* ```
|
|
106
109
|
*/
|
|
107
110
|
static delay(time: TimeSpan): LazyPromise<void>;
|
|
108
111
|
/**
|
|
@@ -135,6 +138,7 @@ export declare class LazyPromise<TValue> implements PromiseLike<TValue> {
|
|
|
135
138
|
*
|
|
136
139
|
* // "I am lazy" will only logged when awaited or then method i called.
|
|
137
140
|
* await promise;
|
|
141
|
+
* ```
|
|
138
142
|
*/
|
|
139
143
|
constructor(asyncFn: AsyncLazy<TValue>, settings?: LazyPromiseSettings<TValue>);
|
|
140
144
|
private applyRetryTimeout;
|
|
@@ -273,7 +277,7 @@ export declare class LazyPromise<TValue> implements PromiseLike<TValue> {
|
|
|
273
277
|
* The <i>defer</i> method executes the <i>LazyPromise</i> without awaiting it.
|
|
274
278
|
* @example
|
|
275
279
|
* ```ts
|
|
276
|
-
* import { LazyPromise } from "@daiso-tech/core";
|
|
280
|
+
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
277
281
|
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
278
282
|
*
|
|
279
283
|
* const promise =
|
|
@@ -11,22 +11,24 @@ AbortAsyncError,
|
|
|
11
11
|
TimeoutAsyncError,
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
13
|
RetryAsyncError, } from "../../../async/async.errors.js";
|
|
14
|
-
import { removeUndefinedProperties, resolveAsyncLazyable, } from "../../../utilities/_module-exports.js";
|
|
14
|
+
import { removeUndefinedProperties, resolveAsyncLazyable, resolveInvokable, } from "../../../utilities/_module-exports.js";
|
|
15
15
|
import { delay } from "../../../async/utilities/_module.js";
|
|
16
16
|
/**
|
|
17
17
|
* The <i>LazyPromise</i> class is used for creating lazy <i>{@link PromiseLike}<i> object that will only execute when awaited or when then method is called.
|
|
18
18
|
* The class includes helpful methods
|
|
19
19
|
* - <i>defer</i>
|
|
20
|
-
* - <i>
|
|
21
|
-
* - <i>
|
|
20
|
+
* - <i>setRetryAttempts</i>
|
|
21
|
+
* - <i>setRetryTimeout</i>
|
|
22
|
+
* - <i>setRetryPolicy</i>
|
|
22
23
|
* - <i>backoffPolicy</i>
|
|
23
|
-
* - <i>
|
|
24
|
-
* - <i>
|
|
24
|
+
* - <i>setTotalTimeout</i>
|
|
25
|
+
* - <i>setAbortSignal</i>
|
|
25
26
|
*
|
|
26
27
|
* The order in which these methods are called does not affect their methodality. Internally, the following execution order is applied:
|
|
27
|
-
* 1. <i>
|
|
28
|
-
* 2. <i>
|
|
29
|
-
* 3. <i>
|
|
28
|
+
* 1. <i>setRetryTimeout</i>
|
|
29
|
+
* 2. <i>setRetryAttempts</i>
|
|
30
|
+
* 3. <i>setTotalTimeout</i>
|
|
31
|
+
* 4. <i>setAbortSignal</i>
|
|
30
32
|
*
|
|
31
33
|
* This means that combining all methods ensures the <i>retryAttempts</i> method will continue retrying even if the timeout is triggered,
|
|
32
34
|
* while the <i>abort</i> method takes priority to cancel all operations if activated.
|
|
@@ -36,7 +38,7 @@ import { delay } from "../../../async/utilities/_module.js";
|
|
|
36
38
|
*/
|
|
37
39
|
export class LazyPromise {
|
|
38
40
|
/**
|
|
39
|
-
* The <i>wrapFn</i> is convience method used for wrapping
|
|
41
|
+
* The <i>wrapFn</i> is convience method used for wrapping async <i>{@link Invokable}</i> with a <i>LazyPromise</i>.
|
|
40
42
|
* @example
|
|
41
43
|
* ```ts
|
|
42
44
|
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
@@ -47,11 +49,11 @@ export class LazyPromise {
|
|
|
47
49
|
*
|
|
48
50
|
* const file = await readFile("none_existing_file.txt")
|
|
49
51
|
* .setRetryAttempts(4)
|
|
50
|
-
* .
|
|
52
|
+
* .setRetryTimeout(TimeSpan.fromMinutes(1));
|
|
51
53
|
* ```
|
|
52
54
|
*/
|
|
53
55
|
static wrapFn(fn, settings) {
|
|
54
|
-
return (...parameters) => new LazyPromise(() => fn(...parameters), settings);
|
|
56
|
+
return (...parameters) => new LazyPromise(() => resolveInvokable(fn)(...parameters), settings);
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
59
|
* The <i>delay</i> method creates a <i>{@link LazyPromise}</i> that will be fulfilled after given <i>time</i>.
|
|
@@ -66,6 +68,7 @@ export class LazyPromise {
|
|
|
66
68
|
* console.log("a");
|
|
67
69
|
* await LazyPromise.delay(TimeSpan.fromSeconds(2));
|
|
68
70
|
* console.log("b");
|
|
71
|
+
* ```
|
|
69
72
|
*/
|
|
70
73
|
static delay(time) {
|
|
71
74
|
return new LazyPromise(async () => {
|
|
@@ -110,6 +113,7 @@ export class LazyPromise {
|
|
|
110
113
|
*
|
|
111
114
|
* // "I am lazy" will only logged when awaited or then method i called.
|
|
112
115
|
* await promise;
|
|
116
|
+
* ```
|
|
113
117
|
*/
|
|
114
118
|
constructor(asyncFn, settings = {}) {
|
|
115
119
|
this.asyncFn = () => resolveAsyncLazyable(asyncFn);
|
|
@@ -373,7 +377,7 @@ export class LazyPromise {
|
|
|
373
377
|
* The <i>defer</i> method executes the <i>LazyPromise</i> without awaiting it.
|
|
374
378
|
* @example
|
|
375
379
|
* ```ts
|
|
376
|
-
* import { LazyPromise } from "@daiso-tech/core";
|
|
380
|
+
* import { LazyPromise } from "@daiso-tech/core/async";
|
|
377
381
|
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
378
382
|
*
|
|
379
383
|
* const promise =
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-promise.js","sourceRoot":"","sources":["../../../../src/async/utilities/lazy-promise/lazy-promise.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"lazy-promise.js","sourceRoot":"","sources":["../../../../src/async/utilities/lazy-promise/lazy-promise.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO;AACH,6DAA6D;AAC7D,eAAe;AACf,6DAA6D;AAC7D,iBAAiB;AACjB,6DAA6D;AAC7D,eAAe,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,yBAAyB,EACzB,oBAAoB,EACpB,gBAAgB,GACnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AA0DrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,WAAW;IACpB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,MAAM,CACT,EAAyC,EACzC,Q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Ac,EAAoB,EAAE;YAC9D,IAAI,CAAC;gBACD,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBACnC,OAAO,KAAK,CAAC;YACjB,CAAC;oBAAS,CAAC;gBACP,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;YACpC,CAAC;QACL,CAAC,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;IAC/C,CAAC;CACJ"}
|
|
@@ -70,7 +70,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
70
70
|
* If it's an <i>Iterable</i>, it will be joined into a single string.
|
|
71
71
|
* Think of an <i>Iterable</i> as representing a path.
|
|
72
72
|
*
|
|
73
|
-
* @param defaultValue - can be
|
|
73
|
+
* @param defaultValue - can be regular value, sync or async <i>{@link Invokable}</i> value and <i>{@link LazyPromise}</i> value.
|
|
74
74
|
*/
|
|
75
75
|
getOr(key: OneOrMore<string>, defaultValue: AsyncLazyable<NoneFunc<TType>>): LazyPromise<TType>;
|
|
76
76
|
/**
|
|
@@ -80,7 +80,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
80
80
|
* If it's an <i>Iterable</i>, it will be joined into a single string.
|
|
81
81
|
* Think of an <i>Iterable</i> as representing a path.
|
|
82
82
|
*
|
|
83
|
-
* @param valueToAdd - can be
|
|
83
|
+
* @param valueToAdd - can be regular value, sync or async <i>{@link Invokable}</i> value and <i>{@link LazyPromise}</i> value.
|
|
84
84
|
*/
|
|
85
85
|
getOrAdd(key: OneOrMore<string>, valueToAdd: AsyncLazyable<NoneFunc<TType>>, ttl?: TimeSpan | null): LazyPromise<TType>;
|
|
86
86
|
/**
|
|
@@ -101,15 +101,15 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
|
|
|
101
101
|
* @example
|
|
102
102
|
* ```ts
|
|
103
103
|
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
104
|
-
* import type {
|
|
104
|
+
* import type { IDatabaseCacheAdapter } from "@daiso-tech/core/cache/contracts";
|
|
105
105
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
106
106
|
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
107
107
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
108
108
|
* import Sqlite from "better-sqlite3";
|
|
109
109
|
* import { Cache } from "@daiso-tech/core/cache";
|
|
110
|
-
* import { KeyPrefixer, type ISqliteDatabase, type
|
|
110
|
+
* import { KeyPrefixer, type ISqliteDatabase, type AsyncFactoryFn } from "@daiso-tech/core/utilities";
|
|
111
111
|
*
|
|
112
|
-
* function cahceAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>):
|
|
112
|
+
* function cahceAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): AsyncFactoryFn<string, IDatabaseCacheAdapter> {
|
|
113
113
|
* return async (prefix) => {
|
|
114
114
|
* const cacheAdapter = new SqliteCacheAdapter({
|
|
115
115
|
* database,
|
|
@@ -133,18 +133,18 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
|
|
|
133
133
|
* @example
|
|
134
134
|
* ```ts
|
|
135
135
|
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
136
|
-
* import type {
|
|
136
|
+
* import type { IDatabaseCacheAdapter } from "@daiso-tech/core/cache/contracts";
|
|
137
137
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
138
138
|
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
139
139
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
140
140
|
* import Sqlite from "better-sqlite3";
|
|
141
141
|
* import { Cache } from "@daiso-tech/core/cache";
|
|
142
|
-
* import { KeyPrefixer, type ISqliteDatabase, type
|
|
142
|
+
* import { KeyPrefixer, type ISqliteDatabase, type IAsyncFactoryObject } from "@daiso-tech/core/utilities";
|
|
143
143
|
*
|
|
144
|
-
* class CahceAdapterFactory implements
|
|
144
|
+
* class CahceAdapterFactory implements IAsyncFactoryObject<string, IDatabaseCacheAdapter> {
|
|
145
145
|
* constructor(private readonly database: ISqliteDatabase, private readonly serde: ISerde<string>) {}
|
|
146
146
|
*
|
|
147
|
-
* async use(prefix: string):
|
|
147
|
+
* async use(prefix: string): Promise<IDatabaseCacheAdapter> {
|
|
148
148
|
* const cacheAdapter = new SqliteCacheAdapter({
|
|
149
149
|
* database: this.database,
|
|
150
150
|
* serde: this.serde,
|
|
@@ -215,151 +215,7 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
|
|
|
215
215
|
get(key: OneOrMore<string>): LazyPromise<TType | null>;
|
|
216
216
|
getOrFail(key: OneOrMore<string>): LazyPromise<TType>;
|
|
217
217
|
getAndRemove(key: OneOrMore<string>): LazyPromise<TType | null>;
|
|
218
|
-
/**
|
|
219
|
-
* @example
|
|
220
|
-
* ```ts
|
|
221
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
222
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
223
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
224
|
-
*
|
|
225
|
-
* const cache = new Cache({
|
|
226
|
-
* adapter: new MemoryCacheAdapter(),
|
|
227
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
228
|
-
* });
|
|
229
|
-
*
|
|
230
|
-
* const value = await cache.getOr("a", 1);
|
|
231
|
-
*
|
|
232
|
-
* // Will be 1
|
|
233
|
-
* console.log(value);
|
|
234
|
-
* ```
|
|
235
|
-
*
|
|
236
|
-
* You can also pass in a function
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
240
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
241
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
242
|
-
*
|
|
243
|
-
* const cache = new Cache({
|
|
244
|
-
* adapter: new MemoryCacheAdapter(),
|
|
245
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
246
|
-
* });
|
|
247
|
-
*
|
|
248
|
-
* const value = await cache.getOr("a", () => 1);
|
|
249
|
-
*
|
|
250
|
-
* // Will be 1
|
|
251
|
-
* console.log(value);
|
|
252
|
-
* ```
|
|
253
|
-
*
|
|
254
|
-
* You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
|
|
255
|
-
* @example
|
|
256
|
-
* ```ts
|
|
257
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
258
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
259
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
260
|
-
*
|
|
261
|
-
* const cache = new Cache({
|
|
262
|
-
* adapter: new MemoryCacheAdapter(),
|
|
263
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
264
|
-
* });
|
|
265
|
-
*
|
|
266
|
-
* const value = await cache.getOr("a", async () => 1);
|
|
267
|
-
*
|
|
268
|
-
* // Will be 1
|
|
269
|
-
* console.log(value);
|
|
270
|
-
* ```
|
|
271
|
-
*
|
|
272
|
-
* You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
|
|
273
|
-
* @example
|
|
274
|
-
* ```ts
|
|
275
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
276
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
277
|
-
* import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
|
|
278
|
-
*
|
|
279
|
-
* const cache = new Cache({
|
|
280
|
-
* adapter: new MemoryCacheAdapter(),
|
|
281
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
282
|
-
* });
|
|
283
|
-
*
|
|
284
|
-
* const value = await cache.getOr("a", new LazyPromise(async () => 1));
|
|
285
|
-
*
|
|
286
|
-
* // Will be 1
|
|
287
|
-
* console.log(value);
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
218
|
getOr(key: OneOrMore<string>, defaultValue: AsyncLazyable<NoneFunc<TType>>): LazyPromise<TType>;
|
|
291
|
-
/**
|
|
292
|
-
* @example
|
|
293
|
-
* ```ts
|
|
294
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
295
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
296
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
297
|
-
*
|
|
298
|
-
* const cache = new Cache({
|
|
299
|
-
* adapter: new MemoryCacheAdapter(),
|
|
300
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
301
|
-
* });
|
|
302
|
-
*
|
|
303
|
-
* const value = await cache.getOrAdd("a", 1);
|
|
304
|
-
*
|
|
305
|
-
* // Will be 1
|
|
306
|
-
* console.log(value);
|
|
307
|
-
* ```
|
|
308
|
-
*
|
|
309
|
-
* You can also pass in a function
|
|
310
|
-
* @example
|
|
311
|
-
* ```ts
|
|
312
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
313
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
314
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
315
|
-
*
|
|
316
|
-
* const cache = new Cache({
|
|
317
|
-
* adapter: new MemoryCacheAdapter(),
|
|
318
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
319
|
-
* });
|
|
320
|
-
*
|
|
321
|
-
* const value = await cache.getOrAdd("a", () => 1);
|
|
322
|
-
*
|
|
323
|
-
* // Will be 1
|
|
324
|
-
* console.log(value);
|
|
325
|
-
* ```
|
|
326
|
-
*
|
|
327
|
-
* You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
|
|
328
|
-
* @example
|
|
329
|
-
* ```ts
|
|
330
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
331
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
332
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
333
|
-
*
|
|
334
|
-
* const cache = new Cache({
|
|
335
|
-
* adapter: new MemoryCacheAdapter(),
|
|
336
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
337
|
-
* });
|
|
338
|
-
*
|
|
339
|
-
* const value = await cache.getOrAdd("a", async () => 1);
|
|
340
|
-
*
|
|
341
|
-
* // Will be 1
|
|
342
|
-
* console.log(value);
|
|
343
|
-
* ```
|
|
344
|
-
*
|
|
345
|
-
* You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
|
|
346
|
-
* @example
|
|
347
|
-
* ```ts
|
|
348
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
349
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
350
|
-
* import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
|
|
351
|
-
*
|
|
352
|
-
* const cache = new Cache({
|
|
353
|
-
* adapter: new MemoryCacheAdapter(),
|
|
354
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
355
|
-
* });
|
|
356
|
-
*
|
|
357
|
-
* const value = await cache.getOrAdd("a", new LazyPromise(async () => 1));
|
|
358
|
-
*
|
|
359
|
-
* // Will be 1
|
|
360
|
-
* console.log(value);
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
219
|
getOrAdd(key: OneOrMore<string>, valueToAdd: AsyncLazyable<NoneFunc<TType>>, ttl?: TimeSpan | null): LazyPromise<TType>;
|
|
364
220
|
add(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
|
|
365
221
|
put(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
|
|
@@ -73,15 +73,15 @@ export class Cache {
|
|
|
73
73
|
* @example
|
|
74
74
|
* ```ts
|
|
75
75
|
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
76
|
-
* import type {
|
|
76
|
+
* import type { IDatabaseCacheAdapter } from "@daiso-tech/core/cache/contracts";
|
|
77
77
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
78
78
|
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
79
79
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
80
80
|
* import Sqlite from "better-sqlite3";
|
|
81
81
|
* import { Cache } from "@daiso-tech/core/cache";
|
|
82
|
-
* import { KeyPrefixer, type ISqliteDatabase, type
|
|
82
|
+
* import { KeyPrefixer, type ISqliteDatabase, type AsyncFactoryFn } from "@daiso-tech/core/utilities";
|
|
83
83
|
*
|
|
84
|
-
* function cahceAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>):
|
|
84
|
+
* function cahceAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): AsyncFactoryFn<string, IDatabaseCacheAdapter> {
|
|
85
85
|
* return async (prefix) => {
|
|
86
86
|
* const cacheAdapter = new SqliteCacheAdapter({
|
|
87
87
|
* database,
|
|
@@ -105,18 +105,18 @@ export class Cache {
|
|
|
105
105
|
* @example
|
|
106
106
|
* ```ts
|
|
107
107
|
* import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
108
|
-
* import type {
|
|
108
|
+
* import type { IDatabaseCacheAdapter } from "@daiso-tech/core/cache/contracts";
|
|
109
109
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
110
110
|
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
111
111
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
112
112
|
* import Sqlite from "better-sqlite3";
|
|
113
113
|
* import { Cache } from "@daiso-tech/core/cache";
|
|
114
|
-
* import { KeyPrefixer, type ISqliteDatabase, type
|
|
114
|
+
* import { KeyPrefixer, type ISqliteDatabase, type IAsyncFactoryObject } from "@daiso-tech/core/utilities";
|
|
115
115
|
*
|
|
116
|
-
* class CahceAdapterFactory implements
|
|
116
|
+
* class CahceAdapterFactory implements IAsyncFactoryObject<string, IDatabaseCacheAdapter> {
|
|
117
117
|
* constructor(private readonly database: ISqliteDatabase, private readonly serde: ISerde<string>) {}
|
|
118
118
|
*
|
|
119
|
-
* async use(prefix: string):
|
|
119
|
+
* async use(prefix: string): Promise<IDatabaseCacheAdapter> {
|
|
120
120
|
* const cacheAdapter = new SqliteCacheAdapter({
|
|
121
121
|
* database: this.database,
|
|
122
122
|
* serde: this.serde,
|
|
@@ -333,78 +333,6 @@ export class Cache {
|
|
|
333
333
|
}
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
|
-
/**
|
|
337
|
-
* @example
|
|
338
|
-
* ```ts
|
|
339
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
340
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
341
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
342
|
-
*
|
|
343
|
-
* const cache = new Cache({
|
|
344
|
-
* adapter: new MemoryCacheAdapter(),
|
|
345
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
346
|
-
* });
|
|
347
|
-
*
|
|
348
|
-
* const value = await cache.getOr("a", 1);
|
|
349
|
-
*
|
|
350
|
-
* // Will be 1
|
|
351
|
-
* console.log(value);
|
|
352
|
-
* ```
|
|
353
|
-
*
|
|
354
|
-
* You can also pass in a function
|
|
355
|
-
* @example
|
|
356
|
-
* ```ts
|
|
357
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
358
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
359
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
360
|
-
*
|
|
361
|
-
* const cache = new Cache({
|
|
362
|
-
* adapter: new MemoryCacheAdapter(),
|
|
363
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
364
|
-
* });
|
|
365
|
-
*
|
|
366
|
-
* const value = await cache.getOr("a", () => 1);
|
|
367
|
-
*
|
|
368
|
-
* // Will be 1
|
|
369
|
-
* console.log(value);
|
|
370
|
-
* ```
|
|
371
|
-
*
|
|
372
|
-
* You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
|
|
373
|
-
* @example
|
|
374
|
-
* ```ts
|
|
375
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
376
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
377
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
378
|
-
*
|
|
379
|
-
* const cache = new Cache({
|
|
380
|
-
* adapter: new MemoryCacheAdapter(),
|
|
381
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
382
|
-
* });
|
|
383
|
-
*
|
|
384
|
-
* const value = await cache.getOr("a", async () => 1);
|
|
385
|
-
*
|
|
386
|
-
* // Will be 1
|
|
387
|
-
* console.log(value);
|
|
388
|
-
* ```
|
|
389
|
-
*
|
|
390
|
-
* You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
|
|
391
|
-
* @example
|
|
392
|
-
* ```ts
|
|
393
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
394
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
395
|
-
* import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
|
|
396
|
-
*
|
|
397
|
-
* const cache = new Cache({
|
|
398
|
-
* adapter: new MemoryCacheAdapter(),
|
|
399
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
400
|
-
* });
|
|
401
|
-
*
|
|
402
|
-
* const value = await cache.getOr("a", new LazyPromise(async () => 1));
|
|
403
|
-
*
|
|
404
|
-
* // Will be 1
|
|
405
|
-
* console.log(value);
|
|
406
|
-
* ```
|
|
407
|
-
*/
|
|
408
336
|
getOr(key, defaultValue) {
|
|
409
337
|
return this.createLazyPromise(async () => {
|
|
410
338
|
const value = await this.get(key);
|
|
@@ -415,78 +343,6 @@ export class Cache {
|
|
|
415
343
|
return value;
|
|
416
344
|
});
|
|
417
345
|
}
|
|
418
|
-
/**
|
|
419
|
-
* @example
|
|
420
|
-
* ```ts
|
|
421
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
422
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
423
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
424
|
-
*
|
|
425
|
-
* const cache = new Cache({
|
|
426
|
-
* adapter: new MemoryCacheAdapter(),
|
|
427
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
428
|
-
* });
|
|
429
|
-
*
|
|
430
|
-
* const value = await cache.getOrAdd("a", 1);
|
|
431
|
-
*
|
|
432
|
-
* // Will be 1
|
|
433
|
-
* console.log(value);
|
|
434
|
-
* ```
|
|
435
|
-
*
|
|
436
|
-
* You can also pass in a function
|
|
437
|
-
* @example
|
|
438
|
-
* ```ts
|
|
439
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
440
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
441
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
442
|
-
*
|
|
443
|
-
* const cache = new Cache({
|
|
444
|
-
* adapter: new MemoryCacheAdapter(),
|
|
445
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
446
|
-
* });
|
|
447
|
-
*
|
|
448
|
-
* const value = await cache.getOrAdd("a", () => 1);
|
|
449
|
-
*
|
|
450
|
-
* // Will be 1
|
|
451
|
-
* console.log(value);
|
|
452
|
-
* ```
|
|
453
|
-
*
|
|
454
|
-
* You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
|
|
455
|
-
* @example
|
|
456
|
-
* ```ts
|
|
457
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
458
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
459
|
-
* import { KeyPrefixer } from "@daiso-tech/core/utilities";
|
|
460
|
-
*
|
|
461
|
-
* const cache = new Cache({
|
|
462
|
-
* adapter: new MemoryCacheAdapter(),
|
|
463
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
464
|
-
* });
|
|
465
|
-
*
|
|
466
|
-
* const value = await cache.getOrAdd("a", async () => 1);
|
|
467
|
-
*
|
|
468
|
-
* // Will be 1
|
|
469
|
-
* console.log(value);
|
|
470
|
-
* ```
|
|
471
|
-
*
|
|
472
|
-
* You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
|
|
473
|
-
* @example
|
|
474
|
-
* ```ts
|
|
475
|
-
* import { Cache } from "@daiso-tech/core/cache";
|
|
476
|
-
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
|
|
477
|
-
* import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
|
|
478
|
-
*
|
|
479
|
-
* const cache = new Cache({
|
|
480
|
-
* adapter: new MemoryCacheAdapter(),
|
|
481
|
-
* keyPrefixer: new KeyPrefixer("cache")
|
|
482
|
-
* });
|
|
483
|
-
*
|
|
484
|
-
* const value = await cache.getOrAdd("a", new LazyPromise(async () => 1));
|
|
485
|
-
*
|
|
486
|
-
* // Will be 1
|
|
487
|
-
* console.log(value);
|
|
488
|
-
* ```
|
|
489
|
-
*/
|
|
490
346
|
getOrAdd(key, valueToAdd, ttl) {
|
|
491
347
|
return this.createLazyPromise(async () => {
|
|
492
348
|
const value = await this.get(key);
|