@nxtedition/lib 23.5.6 → 23.5.8
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/cache.js +2 -9
- package/package.json +1 -1
- package/util/template/index.d.ts +17 -2
package/cache.js
CHANGED
|
@@ -2,7 +2,6 @@ import { LRUCache } from 'lru-cache'
|
|
|
2
2
|
|
|
3
3
|
export class AsyncCache {
|
|
4
4
|
#lru
|
|
5
|
-
#prefix
|
|
6
5
|
#valueSelector
|
|
7
6
|
#keySelector
|
|
8
7
|
#dedupe = new Map()
|
|
@@ -10,10 +9,10 @@ export class AsyncCache {
|
|
|
10
9
|
#stale
|
|
11
10
|
|
|
12
11
|
constructor(location, valueSelector, keySelector, opts) {
|
|
13
|
-
this.#lru = new LRUCache({ max:
|
|
12
|
+
this.#lru = new LRUCache({ max: 4096 })
|
|
14
13
|
|
|
15
14
|
if (typeof location === 'string') {
|
|
16
|
-
|
|
15
|
+
// Do nothing...
|
|
17
16
|
} else {
|
|
18
17
|
throw new TypeError('location must be undefined or a string')
|
|
19
18
|
}
|
|
@@ -58,11 +57,6 @@ export class AsyncCache {
|
|
|
58
57
|
|
|
59
58
|
let cached = this.#lru.get(key)
|
|
60
59
|
|
|
61
|
-
if (!cached) {
|
|
62
|
-
const raw = globalThis.localStorage.getItem(this.#prefix + key)
|
|
63
|
-
cached = raw ? JSON.parse(raw) : null
|
|
64
|
-
}
|
|
65
|
-
|
|
66
60
|
if (cached) {
|
|
67
61
|
if (Date.now() < cached.expire) {
|
|
68
62
|
return cached.value
|
|
@@ -108,7 +102,6 @@ export class AsyncCache {
|
|
|
108
102
|
value,
|
|
109
103
|
}
|
|
110
104
|
|
|
111
|
-
globalThis.localStorage.setItem(this.#prefix + key, JSON.stringify(cached))
|
|
112
105
|
this.#lru.set(key, cached)
|
|
113
106
|
}
|
|
114
107
|
|
package/package.json
CHANGED
package/util/template/index.d.ts
CHANGED
|
@@ -10,12 +10,12 @@ export interface TemplateCompiler {
|
|
|
10
10
|
template: Nxtpression<ReturnValue, Context> | string,
|
|
11
11
|
args$?: Context | rx.Observable<Context>,
|
|
12
12
|
options?: FirstValueFromConfig,
|
|
13
|
-
) => Promise<ReturnValue
|
|
13
|
+
) => Promise<ResolveNxtpressionDeep<Nxtpression<ReturnValue, Context>>>
|
|
14
14
|
|
|
15
15
|
onResolveTemplate: <ReturnValue, Context>(
|
|
16
16
|
template: Nxtpression<ReturnValue, Context> | string,
|
|
17
17
|
args$?: Context | rx.Observable<Context>,
|
|
18
|
-
) => rx.Observable<ReturnValue
|
|
18
|
+
) => rx.Observable<ResolveNxtpressionDeep<Nxtpression<ReturnValue, Context>>>
|
|
19
19
|
|
|
20
20
|
compileTemplate: <ReturnValue, Context>(
|
|
21
21
|
template: Nxtpression<ReturnValue, Context> | string,
|
|
@@ -41,3 +41,18 @@ export type Nxtpression<ReturnValue = string, Context extends object = object> =
|
|
|
41
41
|
})
|
|
42
42
|
| string
|
|
43
43
|
| ReturnValue
|
|
44
|
+
|
|
45
|
+
export type ResolveNxtpressionDeep<T> =
|
|
46
|
+
ExtractReturn<T> extends never
|
|
47
|
+
? T extends Array<infer U>
|
|
48
|
+
? ResolveNxtpressionDeep<U>
|
|
49
|
+
: T extends object
|
|
50
|
+
? {
|
|
51
|
+
[K in keyof T]: ResolveNxtpressionDeep<T[K]>
|
|
52
|
+
}
|
|
53
|
+
: T
|
|
54
|
+
: ExtractReturn<T>
|
|
55
|
+
type TypeWithReturn<X> = {
|
|
56
|
+
__returnValue: X
|
|
57
|
+
}
|
|
58
|
+
type ExtractReturn<Type> = Type extends TypeWithReturn<infer X> ? X : never
|