@markwharton/liquidplanner 1.11.0 → 2.0.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 +65 -1
- package/dist/client.d.ts +74 -45
- package/dist/client.js +285 -105
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +5 -6
- package/dist/index.d.ts +9 -5
- package/dist/index.js +9 -4
- package/dist/tree.d.ts +32 -0
- package/dist/tree.js +86 -0
- package/dist/types.d.ts +89 -38
- package/dist/utils.d.ts +31 -5
- package/dist/utils.js +56 -5
- package/dist/workflows.js +8 -6
- package/package.json +2 -2
- package/dist/cache.d.ts +0 -43
- package/dist/cache.js +0 -78
package/dist/cache.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple in-memory TTL cache with request coalescing
|
|
3
|
-
*
|
|
4
|
-
* Provides per-instance memoization for LPClient API responses.
|
|
5
|
-
* In serverless environments (Azure Functions, Static Web Apps),
|
|
6
|
-
* module-level state persists across warm invocations within the
|
|
7
|
-
* same instance — this cache leverages that behavior.
|
|
8
|
-
*
|
|
9
|
-
* Request coalescing: when multiple concurrent callers request the
|
|
10
|
-
* same expired key, only one factory call is made. All callers
|
|
11
|
-
* receive the same resolved value (or the same rejection).
|
|
12
|
-
*
|
|
13
|
-
* Not a distributed cache: each instance has its own cache.
|
|
14
|
-
* Cold starts and instance recycling naturally clear stale data.
|
|
15
|
-
*/
|
|
16
|
-
export class TTLCache {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.store = new Map();
|
|
19
|
-
this.inflight = new Map();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get a cached value, or call the factory to populate it.
|
|
23
|
-
*
|
|
24
|
-
* If a factory call is already in progress for this key,
|
|
25
|
-
* returns the existing promise instead of starting a duplicate.
|
|
26
|
-
*
|
|
27
|
-
* @param key - Cache key
|
|
28
|
-
* @param ttlMs - Time-to-live in milliseconds
|
|
29
|
-
* @param factory - Async function to produce the value on cache miss
|
|
30
|
-
*/
|
|
31
|
-
async get(key, ttlMs, factory) {
|
|
32
|
-
const existing = this.store.get(key);
|
|
33
|
-
if (existing && existing.expiresAt > Date.now()) {
|
|
34
|
-
return existing.data;
|
|
35
|
-
}
|
|
36
|
-
const pending = this.inflight.get(key);
|
|
37
|
-
if (pending) {
|
|
38
|
-
return pending;
|
|
39
|
-
}
|
|
40
|
-
const promise = factory().then((data) => {
|
|
41
|
-
this.store.set(key, { data, expiresAt: Date.now() + ttlMs });
|
|
42
|
-
this.inflight.delete(key);
|
|
43
|
-
return data;
|
|
44
|
-
}, (err) => {
|
|
45
|
-
this.inflight.delete(key);
|
|
46
|
-
throw err;
|
|
47
|
-
});
|
|
48
|
-
this.inflight.set(key, promise);
|
|
49
|
-
return promise;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Invalidate cache entries matching a key prefix.
|
|
53
|
-
*
|
|
54
|
-
* Also cancels any in-flight requests for matching keys,
|
|
55
|
-
* so subsequent calls will start fresh factory invocations.
|
|
56
|
-
*
|
|
57
|
-
* Example: invalidate('timesheet:') clears all timesheet entries.
|
|
58
|
-
*/
|
|
59
|
-
invalidate(prefix) {
|
|
60
|
-
for (const key of this.store.keys()) {
|
|
61
|
-
if (key.startsWith(prefix)) {
|
|
62
|
-
this.store.delete(key);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
for (const key of this.inflight.keys()) {
|
|
66
|
-
if (key.startsWith(prefix)) {
|
|
67
|
-
this.inflight.delete(key);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Clear all cached data and in-flight requests.
|
|
73
|
-
*/
|
|
74
|
-
clear() {
|
|
75
|
-
this.store.clear();
|
|
76
|
-
this.inflight.clear();
|
|
77
|
-
}
|
|
78
|
-
}
|