@zajno/common 2.8.8 → 2.8.10
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 +1 -1
- package/cjs/functions/safe.js +16 -0
- package/cjs/functions/safe.js.map +1 -1
- package/cjs/lazy/lazy.js +6 -10
- package/cjs/lazy/lazy.js.map +1 -1
- package/cjs/lazy/light.js +4 -1
- package/cjs/lazy/light.js.map +1 -1
- package/cjs/lazy/promise.js +26 -14
- package/cjs/lazy/promise.js.map +1 -1
- package/cjs/structures/promiseCache/cache.js +112 -26
- package/cjs/structures/promiseCache/cache.js.map +1 -1
- package/cjs/structures/promiseCache/core.js +82 -8
- package/cjs/structures/promiseCache/core.js.map +1 -1
- package/cjs/structures/promiseCache/types.js +2 -2
- package/cjs/structures/promiseCache/types.js.map +1 -1
- package/esm/functions/safe.js +15 -0
- package/esm/functions/safe.js.map +1 -1
- package/esm/lazy/lazy.js +6 -10
- package/esm/lazy/lazy.js.map +1 -1
- package/esm/lazy/light.js +4 -1
- package/esm/lazy/light.js.map +1 -1
- package/esm/lazy/promise.js +26 -14
- package/esm/lazy/promise.js.map +1 -1
- package/esm/structures/promiseCache/cache.js +112 -26
- package/esm/structures/promiseCache/cache.js.map +1 -1
- package/esm/structures/promiseCache/core.js +82 -8
- package/esm/structures/promiseCache/core.js.map +1 -1
- package/esm/structures/promiseCache/types.js +2 -2
- package/esm/structures/promiseCache/types.js.map +1 -1
- package/package.json +1 -1
- package/types/functions/safe.d.ts +7 -0
- package/types/lazy/lazy.d.ts +3 -2
- package/types/lazy/promise.d.ts +5 -4
- package/types/lazy/types.d.ts +20 -8
- package/types/structures/promiseCache/cache.d.ts +56 -16
- package/types/structures/promiseCache/core.d.ts +71 -18
- package/types/structures/promiseCache/types.d.ts +26 -7
- package/types/structures/tempoCache.d.ts +1 -1
|
@@ -16,6 +16,7 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
16
16
|
_batch = null;
|
|
17
17
|
_invalidationConfig = null;
|
|
18
18
|
_onError = null;
|
|
19
|
+
_initialValueFactory = null;
|
|
19
20
|
/**
|
|
20
21
|
* Creates an instance of PromiseCache.
|
|
21
22
|
* @param fetcher Function to fetch data by key.
|
|
@@ -44,10 +45,12 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
44
45
|
* This is a convenience wrapper around {@link useInvalidation}.
|
|
45
46
|
*
|
|
46
47
|
* @param ms Time in milliseconds after which the item will be considered invalid. If null, auto-invalidation is disabled.
|
|
47
|
-
*
|
|
48
|
+
*
|
|
49
|
+
* @deprecated The `keepInstance` parameter is deprecated and ignored — stale values are now always kept during invalidation.
|
|
50
|
+
* Use `invalidate()` followed by `get()` if you need to clear the stale value before re-fetching.
|
|
48
51
|
*/
|
|
49
|
-
useInvalidationTime(ms,
|
|
50
|
-
return this.useInvalidation(ms != null ? { expirationMs: ms
|
|
52
|
+
useInvalidationTime(ms, _keepInstance) {
|
|
53
|
+
return this.useInvalidation(ms != null ? { expirationMs: ms } : null);
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
53
56
|
* Configures advanced invalidation policy.
|
|
@@ -70,6 +73,25 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
70
73
|
this._onError = callback;
|
|
71
74
|
return this;
|
|
72
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Sets a default/initial value returned before the fetch completes or on error when no stale value exists.
|
|
78
|
+
*
|
|
79
|
+
* Accepts either a static value or a per-key factory function `(key: K) => TInitial`.
|
|
80
|
+
* The value is **not** stored in the cache — it's a synthetic default (same as `LazyPromise`'s initial value).
|
|
81
|
+
*
|
|
82
|
+
* **Note:** Functions are always interpreted as factories. If `T` is a function type,
|
|
83
|
+
* wrap it: `useInitialValue((key) => myFallbackFn)`.
|
|
84
|
+
*
|
|
85
|
+
* @param initial A value (non-function) or `(key: K) => TInitial` factory.
|
|
86
|
+
* @returns `this` for chaining.
|
|
87
|
+
*/
|
|
88
|
+
useInitialValue(initial) {
|
|
89
|
+
const self = this;
|
|
90
|
+
self._initialValueFactory = typeof initial === 'function'
|
|
91
|
+
? initial
|
|
92
|
+
: (_key) => initial;
|
|
93
|
+
return self;
|
|
94
|
+
}
|
|
73
95
|
// ─── Core implementation ─────────────────────────────────────────────
|
|
74
96
|
/**
|
|
75
97
|
* Returns a promise that resolves to the cached value of the item if loaded already, otherwise starts fetching and the promise will be resolved to the final value.
|
|
@@ -83,16 +105,37 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
83
105
|
const { item, key, isInvalid } = this._getCurrent(id);
|
|
84
106
|
// return cached item if it's not invalidated
|
|
85
107
|
if (item !== undefined && !isInvalid) {
|
|
86
|
-
this.logger.log(key, 'get: item resolved to', item
|
|
108
|
+
this.logger.log(key, 'get: item resolved to', item);
|
|
87
109
|
return Promise.resolve(item);
|
|
88
110
|
}
|
|
111
|
+
// Join an existing in-flight fetch/refresh if one exists
|
|
89
112
|
let promise = this._fetchCache.get(key);
|
|
90
113
|
if (promise != null) {
|
|
91
114
|
this.logger.log(key, 'get: item resolved to <promise>');
|
|
92
115
|
return promise;
|
|
93
116
|
}
|
|
94
117
|
this.setStatus(key, true);
|
|
95
|
-
promise = this._doFetchAsync(id, key);
|
|
118
|
+
promise = this._doFetchAsync(id, key, false);
|
|
119
|
+
this.setPromise(key, promise);
|
|
120
|
+
return promise;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Re-fetches the value for the specified key while keeping the stale cached value available.
|
|
124
|
+
*
|
|
125
|
+
* Does not change the loading status — consumers reading `getCurrent()` / `getLazy().value`
|
|
126
|
+
* continue to see the stale value as if nothing happened.
|
|
127
|
+
*
|
|
128
|
+
* Implements "latest wins" concurrency: if multiple refreshes are called concurrently,
|
|
129
|
+
* all promises resolve to the value from the latest refresh.
|
|
130
|
+
*
|
|
131
|
+
* On error, the stale value is preserved and the error is stored.
|
|
132
|
+
*
|
|
133
|
+
* @param id The key of the item to refresh.
|
|
134
|
+
* @returns A promise resolving to the refreshed value, or the stale value on error.
|
|
135
|
+
*/
|
|
136
|
+
refresh(id) {
|
|
137
|
+
const key = this._pk(id);
|
|
138
|
+
const promise = this._doFetchAsync(id, key, true);
|
|
96
139
|
this.setPromise(key, promise);
|
|
97
140
|
return promise;
|
|
98
141
|
}
|
|
@@ -102,17 +145,21 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
102
145
|
super.clear();
|
|
103
146
|
}
|
|
104
147
|
// ─── Protected overrides ─────────────────────────────────────────────
|
|
148
|
+
_getInitialValue(id) {
|
|
149
|
+
return this._initialValueFactory ? this._initialValueFactory(id) : undefined;
|
|
150
|
+
}
|
|
105
151
|
_getCurrent(id) {
|
|
106
152
|
const key = this._pk(id);
|
|
107
153
|
const isInvalid = this.getIsInvalidated(key);
|
|
108
154
|
// make sure current item is hooked here from the cache (required by observers)
|
|
109
155
|
const item = this._itemsCache.get(key);
|
|
110
|
-
const keepInstance = !!this._invalidationConfig?.keepInstance;
|
|
111
156
|
if (isInvalid) {
|
|
112
157
|
this.logger.log(key, 'item is invalidated');
|
|
113
158
|
}
|
|
114
159
|
return {
|
|
115
|
-
|
|
160
|
+
// Always keep the stale value visible — stale-while-revalidate by default.
|
|
161
|
+
// Use `invalidate()` + `get()` to clear the stale value before re-fetching.
|
|
162
|
+
item,
|
|
116
163
|
key,
|
|
117
164
|
isInvalid,
|
|
118
165
|
};
|
|
@@ -146,53 +193,87 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
146
193
|
}
|
|
147
194
|
// ─── Private ─────────────────────────────────────────────────────────
|
|
148
195
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
196
|
+
* Unified fetch method with "latest wins" semantics.
|
|
197
|
+
*
|
|
198
|
+
* - Tracks the active factory promise per key via `_activeFetchPromises`.
|
|
199
|
+
* - If superseded by a newer fetch, delegates to the newer promise.
|
|
200
|
+
* - On error, preserves the stale cached value.
|
|
201
|
+
*
|
|
202
|
+
* @param id The original key.
|
|
203
|
+
* @param key The string cache key.
|
|
204
|
+
* @returns A promise resolving to the fetched/refreshed value, or the stale value on error.
|
|
153
205
|
*/
|
|
154
|
-
async _doFetchAsync(id, key) {
|
|
206
|
+
async _doFetchAsync(id, key, refreshing) {
|
|
155
207
|
let isInSameVersion = true;
|
|
208
|
+
let isLatest = false;
|
|
156
209
|
try {
|
|
157
210
|
this.onBeforeFetch(key);
|
|
158
211
|
const v = this._version;
|
|
212
|
+
// Create the factory promise and mark it as the active one for this key (latest wins)
|
|
213
|
+
const factoryPromise = this.tryFetchInBatch(id, refreshing);
|
|
214
|
+
this._activeFetchPromises.set(key, factoryPromise);
|
|
159
215
|
let res;
|
|
160
216
|
let fetchFailed = false;
|
|
161
217
|
try {
|
|
162
|
-
res = await
|
|
218
|
+
res = await factoryPromise;
|
|
163
219
|
}
|
|
164
220
|
catch (err) {
|
|
165
221
|
this._handleError(id, err);
|
|
166
222
|
fetchFailed = true;
|
|
167
|
-
res =
|
|
223
|
+
res = undefined;
|
|
168
224
|
}
|
|
169
225
|
if (v !== this._version) {
|
|
170
226
|
isInSameVersion = false;
|
|
227
|
+
this._activeFetchPromises.delete(key);
|
|
171
228
|
// resolve with actual result but don't store it
|
|
172
|
-
return res;
|
|
229
|
+
return res ?? this._getInitialValue(id);
|
|
230
|
+
}
|
|
231
|
+
// Check if this is still the active (latest) fetch for this key
|
|
232
|
+
isLatest = this._activeFetchPromises.get(key) === factoryPromise;
|
|
233
|
+
if (!isLatest) {
|
|
234
|
+
// Superseded by a newer refresh/fetch — delegate to the latest public promise.
|
|
235
|
+
// This ensures anyone awaiting this old promise gets the fresh value,
|
|
236
|
+
// mirroring LazyPromise's "latest wins" behavior.
|
|
237
|
+
const newerPromise = this._fetchCache.get(key);
|
|
238
|
+
if (newerPromise) {
|
|
239
|
+
// Catch errors from the newer promise — if it fails, fall back to stale/initial value.
|
|
240
|
+
return newerPromise.catch(() => this._itemsCache.get(key) ?? this._getInitialValue(id));
|
|
241
|
+
}
|
|
242
|
+
// Fallback: return current cached value or initial
|
|
243
|
+
return this._itemsCache.get(key) ?? this._getInitialValue(id);
|
|
173
244
|
}
|
|
174
|
-
|
|
245
|
+
// We are the latest — clean up tracking
|
|
246
|
+
this._activeFetchPromises.delete(key);
|
|
247
|
+
if (!fetchFailed && res !== undefined) {
|
|
175
248
|
this.logger.log(key, 'item\'s <promise> resolved to', res);
|
|
176
249
|
res = this.prepareResult(res);
|
|
177
|
-
|
|
178
|
-
this.storeResult(key, res);
|
|
179
|
-
}
|
|
250
|
+
this.storeResult(key, res);
|
|
180
251
|
}
|
|
181
|
-
|
|
252
|
+
else if (fetchFailed) {
|
|
253
|
+
// Keep stale value — return whatever is in cache, or initial value
|
|
254
|
+
return this._itemsCache.get(key) ?? this._getInitialValue(id);
|
|
255
|
+
}
|
|
256
|
+
return res ?? this._getInitialValue(id);
|
|
182
257
|
}
|
|
183
258
|
finally {
|
|
184
|
-
if (isInSameVersion) {
|
|
259
|
+
if (!isInSameVersion) {
|
|
260
|
+
this.logger.log(key, 'skipping item\'s resolve due to version change ("clear()" has been called)');
|
|
261
|
+
}
|
|
262
|
+
else if (isLatest) {
|
|
263
|
+
// Only the latest fetch should clean up the fetch state.
|
|
264
|
+
// Superseded fetches delegate to the latest and should not
|
|
265
|
+
// prematurely clear the fetch cache or loading status.
|
|
185
266
|
this.onFetchComplete(key);
|
|
186
267
|
}
|
|
187
268
|
else {
|
|
188
|
-
this.
|
|
269
|
+
this.onFetchSuperseded(key);
|
|
189
270
|
}
|
|
190
271
|
}
|
|
191
272
|
}
|
|
192
273
|
/** Performs a fetch operation in batch mode if available, otherwise uses the regular fetch. Throws on error. */
|
|
193
|
-
async tryFetchInBatch(id) {
|
|
274
|
+
async tryFetchInBatch(id, refreshing) {
|
|
194
275
|
if (!this._batch) {
|
|
195
|
-
return this.fetcher(id);
|
|
276
|
+
return this.fetcher(id, refreshing);
|
|
196
277
|
}
|
|
197
278
|
const res = await this._batch.push(id)
|
|
198
279
|
.catch(err => {
|
|
@@ -201,7 +282,7 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
201
282
|
});
|
|
202
283
|
if (!res || !res.result || res.result[res.index] === undefined) {
|
|
203
284
|
// batch call failed or returned no result — fallback to the direct fetcher
|
|
204
|
-
return this.fetcher(id);
|
|
285
|
+
return this.fetcher(id, refreshing);
|
|
205
286
|
}
|
|
206
287
|
return res.result[res.index];
|
|
207
288
|
}
|
|
@@ -221,9 +302,12 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
221
302
|
}
|
|
222
303
|
/**
|
|
223
304
|
* Enforces the max items limit by removing items to make room.
|
|
224
|
-
* Strategy: first removes invalid items, then oldest valid items.
|
|
305
|
+
* Strategy: first removes invalid items, then oldest valid items by timestamp.
|
|
225
306
|
* Items currently being fetched (in-flight) are not evicted.
|
|
226
307
|
*
|
|
308
|
+
* Note: Phase 2 scans all timestamps linearly (O(n) per eviction).
|
|
309
|
+
* This is acceptable for typical `maxItems` values (up to ~1000).
|
|
310
|
+
*
|
|
227
311
|
* @param incomingKey The key of the item about to be stored (excluded from eviction).
|
|
228
312
|
*/
|
|
229
313
|
_enforceMaxItems(incomingKey) {
|
|
@@ -248,6 +332,7 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
248
332
|
this._set(key, undefined, undefined, undefined);
|
|
249
333
|
this._errorsMap.delete(key);
|
|
250
334
|
this._timestamps.delete(key);
|
|
335
|
+
this._activeFetchPromises.delete(key);
|
|
251
336
|
if (this._itemsCache.size < maxItems) {
|
|
252
337
|
return;
|
|
253
338
|
}
|
|
@@ -271,6 +356,7 @@ export class PromiseCache extends PromiseCacheCore {
|
|
|
271
356
|
this._set(oldestKey, undefined, undefined, undefined);
|
|
272
357
|
this._timestamps.delete(oldestKey);
|
|
273
358
|
this._errorsMap.delete(oldestKey);
|
|
359
|
+
this._activeFetchPromises.delete(oldestKey);
|
|
274
360
|
}
|
|
275
361
|
else {
|
|
276
362
|
// No evictable items found (all are in-flight or incoming)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../../src/structures/promiseCache/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;;;;;;;;EASE;AACF,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../../src/structures/promiseCache/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;;;;;;;;EASE;AACF,MAAM,OAAO,YAAwE,SAAQ,gBAAgC;IAcpG;IAZb,MAAM,GAAqC,IAAI,CAAC;IAChD,mBAAmB,GAAiC,IAAI,CAAC;IACzD,QAAQ,GAA4B,IAAI,CAAC;IACzC,oBAAoB,GAAkC,IAAI,CAAC;IAEnE;;;;;OAKG;IACH,YACqB,OAAkC,EACnD,UAAsC,EACtC,SAAoC;QAEpC,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAJZ,YAAO,GAAP,OAAO,CAA2B;IAKvD,CAAC;IAED,wEAAwE;IAExE;;;;;;MAME;IACF,WAAW,CAAC,OAAmC,EAAE,KAAK,GAAG,cAAc;QACnE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;;;;;MASE;IACF,mBAAmB,CAAC,EAAiB,EAAE,aAAuB;QAC1D,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,E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,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;gBACjD,gEAAgE;gBAChE,IAAI,GAAG,KAAK,WAAW;oBAAE,SAAS;gBAClC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,SAAS;gBAExC,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC;oBAChB,QAAQ,GAAG,EAAE,CAAC;oBACd,SAAS,GAAG,GAAG,CAAC;gBACpB,CAAC;YACL,CAAC;YAED,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;gBACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;gBACtD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBACnC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAClC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACJ,2DAA2D;gBAC3D,MAAM;YACV,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatError } from '../../functions/safe.js';
|
|
1
2
|
import { Loggable } from '../../logger/loggable.js';
|
|
2
3
|
import { Model } from '../../models/Model.js';
|
|
3
4
|
/**
|
|
@@ -9,7 +10,7 @@ import { Model } from '../../models/Model.js';
|
|
|
9
10
|
* - promise caching
|
|
10
11
|
* - error storage
|
|
11
12
|
* - timestamps for cached items
|
|
12
|
-
* - direct cache manipulation (invalidate,
|
|
13
|
+
* - direct cache manipulation (invalidate, set, clear)
|
|
13
14
|
* - keys iteration
|
|
14
15
|
*
|
|
15
16
|
* Subclasses are expected to implement fetching logic, invalidation policies, etc.
|
|
@@ -29,6 +30,11 @@ export class PromiseCacheCore extends Loggable {
|
|
|
29
30
|
_errorsMap;
|
|
30
31
|
/** Stores items resolve timestamps (for expiration) in map by id. */
|
|
31
32
|
_timestamps = new Map();
|
|
33
|
+
/**
|
|
34
|
+
* Tracks the latest in-flight factory promise per key for "latest wins" refresh semantics.
|
|
35
|
+
* Separate from `_fetchCache` (which stores the public-facing promise returned to callers).
|
|
36
|
+
*/
|
|
37
|
+
_activeFetchPromises = new Map();
|
|
32
38
|
_version = 0;
|
|
33
39
|
constructor(keyAdapter, keyParser) {
|
|
34
40
|
super();
|
|
@@ -41,7 +47,14 @@ export class PromiseCacheCore extends Loggable {
|
|
|
41
47
|
this._errorsMap = this.pure_createErrorsMap();
|
|
42
48
|
}
|
|
43
49
|
// ─── Counts ──────────────────────────────────────────────────────────
|
|
44
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Returns the number of items currently being fetched (includes background refreshes).
|
|
52
|
+
*
|
|
53
|
+
* Note: `loadingCount` includes background refreshes started via `refresh()`,
|
|
54
|
+
* but `getIsLoading(key)` does **not** reflect background refreshes — it only
|
|
55
|
+
* tracks the per-key status set by `get()`. Use `loadingCount` for global
|
|
56
|
+
* "something is loading" indicators.
|
|
57
|
+
*/
|
|
45
58
|
get loadingCount() { return this._loadingCount.value; }
|
|
46
59
|
/** Returns the number of cached items (resolved values). */
|
|
47
60
|
get cachedCount() { return this._itemsCache.size; }
|
|
@@ -120,10 +133,50 @@ export class PromiseCacheCore extends Loggable {
|
|
|
120
133
|
return `[PromiseCache:${name || '?'}]`;
|
|
121
134
|
}
|
|
122
135
|
// ─── Public API: reading ─────────────────────────────────────────────
|
|
136
|
+
/**
|
|
137
|
+
* Returns an {@link ILazyPromise} handle for a specified cache key.
|
|
138
|
+
*
|
|
139
|
+
* The returned object implements the same interface as a standalone `LazyPromise`,
|
|
140
|
+
* allowing consumers to use a single `ILazyPromise<T>` interface regardless of whether
|
|
141
|
+
* the data comes from a single lazy value or a keyed cache.
|
|
142
|
+
*
|
|
143
|
+
* - `value` / `promise` trigger a fetch if not started.
|
|
144
|
+
* - `currentValue` reads without triggering.
|
|
145
|
+
* - `refresh()` re-fetches while keeping the stale value available.
|
|
146
|
+
*/
|
|
147
|
+
getLazy(key) {
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
149
|
+
const self = this;
|
|
150
|
+
return {
|
|
151
|
+
get value() { return self.getCurrent(key); },
|
|
152
|
+
get currentValue() { return self.getCurrent(key, false); },
|
|
153
|
+
get hasValue() {
|
|
154
|
+
const k = self._pk(key);
|
|
155
|
+
return self._itemsCache.has(k);
|
|
156
|
+
},
|
|
157
|
+
get error() { return self.getLastError(key); },
|
|
158
|
+
/** @deprecated Use {@link error} instead. */
|
|
159
|
+
get errorMessage() {
|
|
160
|
+
const err = self.getLastError(key);
|
|
161
|
+
return err != null ? formatError(err) : null;
|
|
162
|
+
},
|
|
163
|
+
get isLoading() {
|
|
164
|
+
const v = self.getIsLoading(key);
|
|
165
|
+
return v === undefined ? null : v;
|
|
166
|
+
},
|
|
167
|
+
get promise() { return self.get(key); },
|
|
168
|
+
refresh() {
|
|
169
|
+
return self.refresh(key);
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
123
173
|
/**
|
|
124
174
|
* Returns a {@link DeferredGetter} object for a specified key.
|
|
125
175
|
*
|
|
126
176
|
* This can be used to access the current value, promise, loading state, and last error of the item.
|
|
177
|
+
*
|
|
178
|
+
* @deprecated Use {@link getLazy} instead — it returns an `ILazyPromise<T>` which is the standard
|
|
179
|
+
* interface shared with standalone `LazyPromise` instances.
|
|
127
180
|
*/
|
|
128
181
|
getDeferred(key) {
|
|
129
182
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -138,7 +191,11 @@ export class PromiseCacheCore extends Loggable {
|
|
|
138
191
|
/**
|
|
139
192
|
* Returns the loading state of an item.
|
|
140
193
|
*
|
|
141
|
-
*
|
|
194
|
+
* Note: background refreshes via `refresh()` do **not** update per-key loading status.
|
|
195
|
+
* This method only reflects fetches initiated by `get()`. Use `loadingCount` for
|
|
196
|
+
* a global indicator that includes background refreshes.
|
|
197
|
+
*
|
|
198
|
+
* @returns true if loading, false if loading completed, undefined if loading was not started yet (or invalidated).
|
|
142
199
|
*/
|
|
143
200
|
getIsLoading(id) {
|
|
144
201
|
const key = this._pk(id);
|
|
@@ -170,14 +227,15 @@ export class PromiseCacheCore extends Loggable {
|
|
|
170
227
|
const key = this._pk(id);
|
|
171
228
|
return this._errorsMap.get(key) ?? null;
|
|
172
229
|
}
|
|
173
|
-
/** Returns the current cached value, optionally triggering a fetch. */
|
|
230
|
+
/** Returns the current cached value, optionally triggering a fetch. Falls back to the initial value if configured. */
|
|
174
231
|
getCurrent(id, initiateFetch = true) {
|
|
175
232
|
const { item, key } = this._getCurrent(id);
|
|
176
233
|
if (initiateFetch) {
|
|
177
234
|
this.get(id);
|
|
178
235
|
}
|
|
179
|
-
|
|
180
|
-
|
|
236
|
+
const result = item ?? this._getInitialValue(id);
|
|
237
|
+
this.logger.log(key, 'getCurrent: returns', result);
|
|
238
|
+
return result;
|
|
181
239
|
}
|
|
182
240
|
/** Returns true if the item is cached or fetching was initiated. Does not initiate fetching. */
|
|
183
241
|
hasKey(id) {
|
|
@@ -212,11 +270,21 @@ export class PromiseCacheCore extends Loggable {
|
|
|
212
270
|
this._set(key, undefined, undefined, undefined);
|
|
213
271
|
this._errorsMap.delete(key);
|
|
214
272
|
this._timestamps.delete(key);
|
|
273
|
+
this._activeFetchPromises.delete(key);
|
|
215
274
|
}
|
|
216
|
-
/**
|
|
217
|
-
|
|
275
|
+
/** Injects a value into the cache for the specified key, as if it had been fetched. Sets the timestamp and clears any previous error. Cancels any in-flight fetch for this key. */
|
|
276
|
+
set(id, value) {
|
|
218
277
|
const key = this._pk(id);
|
|
219
278
|
this._set(key, value, undefined, undefined);
|
|
279
|
+
this._timestamps.set(key, Date.now());
|
|
280
|
+
this._errorsMap.delete(key);
|
|
281
|
+
this._activeFetchPromises.delete(key);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* @deprecated Use {@link set} instead.
|
|
285
|
+
*/
|
|
286
|
+
updateValueDirectly(id, value) {
|
|
287
|
+
return this.set(id, value);
|
|
220
288
|
}
|
|
221
289
|
/**
|
|
222
290
|
* Iterates over all cached items and removes those that are invalid (expired).
|
|
@@ -235,6 +303,7 @@ export class PromiseCacheCore extends Loggable {
|
|
|
235
303
|
this._set(key, undefined, undefined, undefined);
|
|
236
304
|
this._errorsMap.delete(key);
|
|
237
305
|
this._timestamps.delete(key);
|
|
306
|
+
this._activeFetchPromises.delete(key);
|
|
238
307
|
removed++;
|
|
239
308
|
}
|
|
240
309
|
return removed;
|
|
@@ -248,6 +317,7 @@ export class PromiseCacheCore extends Loggable {
|
|
|
248
317
|
this._fetchCache.clear();
|
|
249
318
|
this._errorsMap.clear();
|
|
250
319
|
this._timestamps.clear();
|
|
320
|
+
this._activeFetchPromises.clear();
|
|
251
321
|
}
|
|
252
322
|
/** @internal updates all caches states at once. */
|
|
253
323
|
_set(key, item, promise, isLoading) {
|
|
@@ -280,6 +350,10 @@ export class PromiseCacheCore extends Loggable {
|
|
|
280
350
|
this._fetchCache.delete(key);
|
|
281
351
|
this._itemsStatus.set(key, false);
|
|
282
352
|
}
|
|
353
|
+
/** Hooks into the superseded fetch cleanup. Only decrements loading count — does not touch fetch cache or status. */
|
|
354
|
+
onFetchSuperseded(_key) {
|
|
355
|
+
this._loadingCount.value = this._loadingCount.value - 1;
|
|
356
|
+
}
|
|
283
357
|
/** Hooks into the result preparation process, before it's stored into the cache. */
|
|
284
358
|
prepareResult(res) {
|
|
285
359
|
return res;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../src/structures/promiseCache/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../src/structures/promiseCache/core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAA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AG,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,qHAAqH;IAC3G,iBAAiB,CAAC,IAAY;QACpC,IAAI,CAAC,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,GAAG,CAAC,CAAC;IAC5D,CAAC;IAED,oFAAoF;IAC1E,aAAa,CAAC,GAAM;QAC1B,OAAO,GAAG,CAAC;IACf,CAAC;IAED,0DAA0D;IAChD,MAAM,CAAC,QAAQ,CAAI,GAAW,EAAE,GAAyB,EAAE,GAAM;QACvE,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACpB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACtB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export var DeferredGetter;
|
|
2
2
|
(function (DeferredGetter) {
|
|
3
|
-
const _resolvedPromise = Promise.resolve(
|
|
3
|
+
const _resolvedPromise = Promise.resolve(undefined);
|
|
4
4
|
/** Empty resolved value. */
|
|
5
5
|
DeferredGetter.Empty = {
|
|
6
|
-
get current() { return
|
|
6
|
+
get current() { return undefined; },
|
|
7
7
|
get promise() { return _resolvedPromise; },
|
|
8
8
|
get isLoading() { return false; },
|
|
9
9
|
get error() { return null; },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/structures/promiseCache/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/structures/promiseCache/types.ts"],"names":[],"mappings":"AAmBA,MAAM,KAAW,cAAc,CAU9B;AAVD,WAAiB,cAAc;IAC3B,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAY,SAAS,CAAC,CAAC;IAE/D,4BAA4B;IACf,oBAAK,GAAG;QACjB,IAAI,OAAO,KAAgB,OAAO,SAAS,CAAC,CAAC,CAAC;QAC9C,IAAI,OAAO,KAAyB,OAAO,gBAAgB,CAAC,CAAC,CAAC;QAC9D,IAAI,SAAS,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;KACC,CAAC;AACtC,CAAC,EAVgB,cAAc,KAAd,cAAc,QAU9B"}
|
package/package.json
CHANGED
|
@@ -2,4 +2,11 @@ import type { Nullable } from '../types/index.js';
|
|
|
2
2
|
type LaxPromise<T> = Promise<T> | T | void;
|
|
3
3
|
export declare function catchPromise(promise: LaxPromise<any>, errorCb?: (err: any) => void): void;
|
|
4
4
|
export declare function wrapAsync<T, TArgs extends any[]>(fn: Nullable<(...args: TArgs) => LaxPromise<T>>, errorCb?: (err: any) => void): (...args: TArgs) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Formats an unknown caught value into a human-readable string.
|
|
7
|
+
*
|
|
8
|
+
* Useful at presentation boundaries where a display string is needed.
|
|
9
|
+
* Prefer keeping the raw error for programmatic handling (instanceof checks, .cause, etc.).
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatError(err: unknown): string;
|
|
5
12
|
export {};
|
package/types/lazy/lazy.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ export declare class Lazy<T> implements ILazy<T>, IDisposable, IResettableModel
|
|
|
16
16
|
get hasValue(): boolean;
|
|
17
17
|
get value(): T;
|
|
18
18
|
get currentValue(): T | undefined;
|
|
19
|
-
get error():
|
|
19
|
+
get error(): unknown;
|
|
20
|
+
/** @deprecated Use {@link error} instead. */
|
|
21
|
+
get errorMessage(): string | null;
|
|
20
22
|
/** Override me: additional way to make sure instance is valid */
|
|
21
23
|
protected get isValid(): boolean;
|
|
22
24
|
/** Provides custom cleanup logic when the instance is reset or disposed. */
|
|
@@ -30,5 +32,4 @@ export declare class Lazy<T> implements ILazy<T>, IDisposable, IResettableModel
|
|
|
30
32
|
reset(): void;
|
|
31
33
|
dispose(): void;
|
|
32
34
|
private ensureInstance;
|
|
33
|
-
protected parseError(err: unknown): string;
|
|
34
35
|
}
|
package/types/lazy/promise.d.ts
CHANGED
|
@@ -23,8 +23,10 @@ export declare class LazyPromise<T, TInitial extends T | undefined = undefined>
|
|
|
23
23
|
/** Current loading state: true = loading, false = loaded, null = not started */
|
|
24
24
|
get isLoading(): boolean | null;
|
|
25
25
|
get hasValue(): boolean;
|
|
26
|
-
get error():
|
|
27
|
-
|
|
26
|
+
get error(): unknown;
|
|
27
|
+
/** @deprecated Use {@link error} instead. */
|
|
28
|
+
get errorMessage(): string | null;
|
|
29
|
+
get promise(): Promise<T | TInitial>;
|
|
28
30
|
get value(): T | TInitial;
|
|
29
31
|
/** Returns current value without triggering loading. */
|
|
30
32
|
get currentValue(): T | TInitial;
|
|
@@ -77,7 +79,7 @@ export declare class LazyPromise<T, TInitial extends T | undefined = undefined>
|
|
|
77
79
|
*
|
|
78
80
|
* @returns Promise resolving to the refreshed value
|
|
79
81
|
*/
|
|
80
|
-
refresh(): Promise<T>;
|
|
82
|
+
refresh(): Promise<T | TInitial>;
|
|
81
83
|
reset(): void;
|
|
82
84
|
dispose(): void;
|
|
83
85
|
private ensureInstanceLoading;
|
|
@@ -86,5 +88,4 @@ export declare class LazyPromise<T, TInitial extends T | undefined = undefined>
|
|
|
86
88
|
protected updateState(isLoading: boolean | null): void;
|
|
87
89
|
protected setError(err: unknown): void;
|
|
88
90
|
protected clearError(): void;
|
|
89
|
-
protected parseError(err: unknown): string;
|
|
90
91
|
}
|