@nxtedition/nxt-undici 6.2.11 → 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.
@@ -1,6 +1,6 @@
1
1
  import undici from '@nxtedition/undici'
2
2
  import { DecoratorHandler, parseCacheControl, parseContentRange } from '../utils.js'
3
- import { SqliteCacheStore, assertCacheKey } from '../sqlite-cache-store.js'
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, headers: {} }
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
  }
@@ -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
- logger?.debug({ dns: { hostname } }, 'lookup started')
39
- promise = new Promise((resolve) =>
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
@@ -338,6 +338,7 @@ async function retryFn(err, retryCount, opts) {
338
338
  'EHOSTDOWN',
339
339
  'EHOSTUNREACH',
340
340
  'EPIPE',
341
+ 'ENODATA',
341
342
  'UND_ERR_CONNECT_TIMEOUT',
342
343
  ].includes(err.code)
343
344
  ) {
@@ -410,7 +410,7 @@ function makeResult(value) {
410
410
  /**
411
411
  * @param {any} key
412
412
  */
413
- export function assertCacheKey(key) {
413
+ function assertCacheKey(key) {
414
414
  if (typeof key !== 'object') {
415
415
  throw new TypeError(`expected key to be object, got ${typeof key}`)
416
416
  }
@@ -429,7 +429,7 @@ export function assertCacheKey(key) {
429
429
  /**
430
430
  * @param {any} value
431
431
  */
432
- export function assertCacheValue(value) {
432
+ function assertCacheValue(value) {
433
433
  if (typeof value !== 'object') {
434
434
  throw new TypeError(`expected value to be object, got ${typeof value}`)
435
435
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.2.11",
3
+ "version": "6.2.12",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",