@nxtedition/nxt-undici 6.2.10 → 6.2.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/lib/interceptor/cache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import undici from '@nxtedition/undici'
|
|
2
2
|
import { DecoratorHandler, parseCacheControl, parseContentRange } from '../utils.js'
|
|
3
|
-
import { SqliteCacheStore
|
|
3
|
+
import { SqliteCacheStore } from '../sqlite-cache-store.js'
|
|
4
4
|
|
|
5
5
|
const DEFAULT_STORE = new SqliteCacheStore({ location: ':memory:' })
|
|
6
6
|
const DEFAULT_MAX_ENTRY_SIZE = 128 * 1024
|
|
@@ -13,8 +13,6 @@ class CacheHandler extends DecoratorHandler {
|
|
|
13
13
|
#maxEntrySize
|
|
14
14
|
|
|
15
15
|
constructor(key, { store, handler, maxEntrySize }) {
|
|
16
|
-
assertCacheKey(key)
|
|
17
|
-
|
|
18
16
|
super(handler)
|
|
19
17
|
|
|
20
18
|
this.#key = key
|
|
@@ -211,7 +209,7 @@ export default () => (dispatch) => (opts, handler) => {
|
|
|
211
209
|
)
|
|
212
210
|
}
|
|
213
211
|
|
|
214
|
-
const { statusCode, headers, body } = entry ?? { statusCode: 504
|
|
212
|
+
const { statusCode, headers, trailers, body } = entry ?? { statusCode: 504 }
|
|
215
213
|
|
|
216
214
|
let aborted = false
|
|
217
215
|
const abort = (reason) => {
|
|
@@ -230,7 +228,7 @@ export default () => (dispatch) => (opts, handler) => {
|
|
|
230
228
|
return
|
|
231
229
|
}
|
|
232
230
|
|
|
233
|
-
handler.onHeaders(statusCode, headers, NOOP)
|
|
231
|
+
handler.onHeaders(statusCode, headers ?? {}, NOOP)
|
|
234
232
|
if (aborted) {
|
|
235
233
|
return
|
|
236
234
|
}
|
|
@@ -242,7 +240,7 @@ export default () => (dispatch) => (opts, handler) => {
|
|
|
242
240
|
}
|
|
243
241
|
}
|
|
244
242
|
|
|
245
|
-
handler.onComplete({})
|
|
243
|
+
handler.onComplete(trailers ?? {})
|
|
246
244
|
} catch (err) {
|
|
247
245
|
abort(err)
|
|
248
246
|
}
|
package/lib/interceptor/dns.js
CHANGED
|
@@ -35,8 +35,8 @@ export default () => (dispatch) => {
|
|
|
35
35
|
function resolve(hostname, { logger }) {
|
|
36
36
|
let promise = promises.get(hostname)
|
|
37
37
|
if (!promise) {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
promise = new Promise((resolve) => {
|
|
39
|
+
logger?.debug({ dns: { hostname } }, 'lookup started')
|
|
40
40
|
dns.resolve4(hostname, { ttl: true }, (err, records) => {
|
|
41
41
|
promises.delete(hostname)
|
|
42
42
|
|
|
@@ -59,8 +59,8 @@ export default () => (dispatch) => {
|
|
|
59
59
|
|
|
60
60
|
resolve([null, val])
|
|
61
61
|
}
|
|
62
|
-
})
|
|
63
|
-
)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
64
|
promises.set(hostname, promise)
|
|
65
65
|
}
|
|
66
66
|
return promise
|
|
@@ -2,7 +2,7 @@ import { DatabaseSync } from 'node:sqlite'
|
|
|
2
2
|
import assert from 'node:assert'
|
|
3
3
|
import { parseRangeHeader } from './utils.js'
|
|
4
4
|
|
|
5
|
-
const VERSION =
|
|
5
|
+
const VERSION = 6
|
|
6
6
|
|
|
7
7
|
// 2gb
|
|
8
8
|
const MAX_ENTRY_SIZE = 2 * 1000 * 1000 * 1000
|
|
@@ -133,7 +133,6 @@ export class SqliteCacheStore {
|
|
|
133
133
|
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${VERSION}_method ON cacheInterceptorV${VERSION}(method);
|
|
134
134
|
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${VERSION}_deleteAt ON cacheInterceptorV${VERSION}(deleteAt);
|
|
135
135
|
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${VERSION}_start ON cacheInterceptorV${VERSION}(start);
|
|
136
|
-
CREATE INDEX IF NOT EXISTS idx_cacheInterceptorV${VERSION}_end ON cacheInterceptorV${VERSION}(end);
|
|
137
136
|
`)
|
|
138
137
|
|
|
139
138
|
this.#getValuesQuery = this.#db.prepare(`
|
|
@@ -154,7 +153,6 @@ export class SqliteCacheStore {
|
|
|
154
153
|
url = ?
|
|
155
154
|
AND method = ?
|
|
156
155
|
AND start <= ?
|
|
157
|
-
AND end >= ?
|
|
158
156
|
ORDER BY
|
|
159
157
|
deleteAt ASC
|
|
160
158
|
`)
|
|
@@ -318,12 +316,7 @@ export class SqliteCacheStore {
|
|
|
318
316
|
/**
|
|
319
317
|
* @type {SqliteStoreValue[]}
|
|
320
318
|
*/
|
|
321
|
-
const values = this.#getValuesQuery.all(
|
|
322
|
-
makeValueUrl(key),
|
|
323
|
-
method,
|
|
324
|
-
range?.start ?? 0,
|
|
325
|
-
range?.end ?? Number.MAX_SAFE_INTEGER,
|
|
326
|
-
)
|
|
319
|
+
const values = this.#getValuesQuery.all(makeValueUrl(key), method, range?.start ?? 0)
|
|
327
320
|
|
|
328
321
|
if (values.length === 0) {
|
|
329
322
|
return undefined
|
|
@@ -417,7 +410,7 @@ function makeResult(value) {
|
|
|
417
410
|
/**
|
|
418
411
|
* @param {any} key
|
|
419
412
|
*/
|
|
420
|
-
|
|
413
|
+
function assertCacheKey(key) {
|
|
421
414
|
if (typeof key !== 'object') {
|
|
422
415
|
throw new TypeError(`expected key to be object, got ${typeof key}`)
|
|
423
416
|
}
|
|
@@ -436,7 +429,7 @@ export function assertCacheKey(key) {
|
|
|
436
429
|
/**
|
|
437
430
|
* @param {any} value
|
|
438
431
|
*/
|
|
439
|
-
|
|
432
|
+
function assertCacheValue(value) {
|
|
440
433
|
if (typeof value !== 'object') {
|
|
441
434
|
throw new TypeError(`expected value to be object, got ${typeof value}`)
|
|
442
435
|
}
|