@nxtedition/lib 26.0.10 → 26.0.12
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 +29 -9
- package/package.json +1 -1
- package/util/template/javascript.js +5 -2
package/cache.js
CHANGED
|
@@ -80,9 +80,9 @@ export class AsyncCache {
|
|
|
80
80
|
this.#lru =
|
|
81
81
|
opts?.lru === false || opts?.lru === null ? null : new LRUCache({ max: 4096, ...opts?.lru })
|
|
82
82
|
|
|
83
|
-
for (let n = 0; true; n
|
|
83
|
+
for (let n = 0; true; n++) {
|
|
84
84
|
try {
|
|
85
|
-
this.#db
|
|
85
|
+
this.#db ??= new DatabaseSync(location, { timeout: 20, ...opts?.db })
|
|
86
86
|
|
|
87
87
|
this.#db.exec(`
|
|
88
88
|
PRAGMA journal_mode = WAL;
|
|
@@ -104,14 +104,17 @@ export class AsyncCache {
|
|
|
104
104
|
)
|
|
105
105
|
this.#delQuery = this.#db.prepare(`DELETE FROM cache WHERE key = ?`)
|
|
106
106
|
} catch (err) {
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
if (n >= 8) {
|
|
108
|
+
this.#db?.close()
|
|
109
|
+
this.#db = null
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
this.#getQuery = null
|
|
112
|
+
this.#setQuery = null
|
|
113
|
+
this.#delQuery = null
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
process.emitWarning(err)
|
|
116
|
+
break
|
|
117
|
+
}
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
}
|
|
@@ -125,6 +128,23 @@ export class AsyncCache {
|
|
|
125
128
|
* @returns {{ value: V|Promise<V>, async: boolean }}
|
|
126
129
|
*/
|
|
127
130
|
get(...args) {
|
|
131
|
+
return this.#load(args, true)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {...any} args
|
|
136
|
+
* @returns {{ value: V|Promise<V>, async: boolean }}
|
|
137
|
+
*/
|
|
138
|
+
peek(...args) {
|
|
139
|
+
return this.#load(args, false)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {any[]} args
|
|
144
|
+
* @param {boolean} refresh
|
|
145
|
+
* @returns {{ value: V|Promise<V>, async: boolean }}
|
|
146
|
+
*/
|
|
147
|
+
#load(args, refresh) {
|
|
128
148
|
const key = this.#keySelector(...args)
|
|
129
149
|
|
|
130
150
|
if (typeof key !== 'string' || key.length === 0) {
|
|
@@ -170,7 +190,7 @@ export class AsyncCache {
|
|
|
170
190
|
}
|
|
171
191
|
|
|
172
192
|
let promise
|
|
173
|
-
if (this.#valueSelector) {
|
|
193
|
+
if (this.#valueSelector && refresh) {
|
|
174
194
|
promise = this.#dedupe.get(key)
|
|
175
195
|
if (promise === undefined) {
|
|
176
196
|
promise = this.#valueSelector(...args).then(
|
package/package.json
CHANGED
|
@@ -71,12 +71,15 @@ class FetchEntry {
|
|
|
71
71
|
})
|
|
72
72
|
.catch((err) => {
|
|
73
73
|
if (this.refresh) {
|
|
74
|
-
this.error = Object.assign(
|
|
74
|
+
this.error = Object.assign(new Error('fetch failed'), {
|
|
75
|
+
data: { resource },
|
|
76
|
+
cause: err,
|
|
77
|
+
})
|
|
75
78
|
this.refresh()
|
|
76
79
|
}
|
|
77
80
|
})
|
|
78
81
|
} catch (err) {
|
|
79
|
-
this.error = Object.assign(
|
|
82
|
+
this.error = Object.assign(new Error('fetch failed'), { data: { resource }, cause: err })
|
|
80
83
|
this.refresh()
|
|
81
84
|
}
|
|
82
85
|
}
|