@nxtedition/nxt-undici 6.0.4 → 6.0.6
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/lib/index.js +1 -2
- package/lib/interceptor/cache.js +14 -8
- package/package.json +3 -4
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import undici from '@nxtedition/undici'
|
|
2
2
|
import { parseHeaders } from './utils.js'
|
|
3
3
|
import { request as _request } from './request.js'
|
|
4
|
-
import { cacheStores } from 'undici'
|
|
5
4
|
|
|
6
5
|
const dispatcherCache = new WeakMap()
|
|
7
6
|
|
|
@@ -20,7 +19,7 @@ export const interceptors = {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export const cache = {
|
|
23
|
-
SqliteCacheStore: cacheStores.SqliteCacheStore,
|
|
22
|
+
SqliteCacheStore: undici.cacheStores.SqliteCacheStore,
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
export { parseHeaders } from './utils.js'
|
package/lib/interceptor/cache.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import undici from '@nxtedition/undici'
|
|
2
2
|
import { DecoratorHandler, parseCacheControl } from '../utils.js'
|
|
3
3
|
|
|
4
|
-
const DEFAULT_STORE = new cacheStores.SqliteCacheStore({ location: ':memory:' })
|
|
4
|
+
const DEFAULT_STORE = new undici.cacheStores.SqliteCacheStore({ location: ':memory:' })
|
|
5
5
|
const MAX_ENTRY_SIZE = 128 * 1024
|
|
6
6
|
|
|
7
7
|
class CacheHandler extends DecoratorHandler {
|
|
8
|
+
#key
|
|
8
9
|
#value
|
|
9
|
-
#opts
|
|
10
10
|
#store
|
|
11
11
|
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(key, { store, handler }) {
|
|
13
|
+
undici.util.cache.assertCacheKey(key)
|
|
14
|
+
|
|
13
15
|
super(handler)
|
|
14
16
|
|
|
15
|
-
this.#
|
|
17
|
+
this.#key = key
|
|
18
|
+
this.#value = null
|
|
16
19
|
this.#store = store
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -61,7 +64,7 @@ class CacheHandler extends DecoratorHandler {
|
|
|
61
64
|
for (const key of [headers.vary]
|
|
62
65
|
.flat()
|
|
63
66
|
.flatMap((vary) => vary.split(',').map((key) => key.trim().toLowerCase()))) {
|
|
64
|
-
const val = this.#
|
|
67
|
+
const val = this.#key.headers[key]
|
|
65
68
|
if (!val) {
|
|
66
69
|
// Expect vary headers to be present...
|
|
67
70
|
return super.onHeaders(statusCode, headers, resume)
|
|
@@ -115,7 +118,7 @@ class CacheHandler extends DecoratorHandler {
|
|
|
115
118
|
|
|
116
119
|
onComplete(trailers) {
|
|
117
120
|
if (this.#value && (!trailers || Object.keys(trailers).length === 0)) {
|
|
118
|
-
this.#store.set(this.#
|
|
121
|
+
this.#store.set(this.#key, this.#value)
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
super.onComplete(trailers)
|
|
@@ -150,7 +153,10 @@ export default () => (dispatch) => (opts, handler) => {
|
|
|
150
153
|
const store = opts.cache.store ?? DEFAULT_STORE
|
|
151
154
|
const entry = store.get(opts)
|
|
152
155
|
if (!entry) {
|
|
153
|
-
return dispatch(
|
|
156
|
+
return dispatch(
|
|
157
|
+
opts,
|
|
158
|
+
new CacheHandler(undici.util.cache.makeCacheKey(opts), { store, handler }),
|
|
159
|
+
)
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
let aborted = false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/nxt-undici",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
"lib/*"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@nxtedition/undici": "^10.
|
|
12
|
+
"@nxtedition/undici": "^10.1.2",
|
|
13
13
|
"cache-control-parser": "^2.0.6",
|
|
14
|
-
"http-errors": "^2.0.0"
|
|
15
|
-
"undici": "^7.3.0"
|
|
14
|
+
"http-errors": "^2.0.0"
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|
|
18
17
|
"@types/node": "^22.10.7",
|