@nxtedition/nxt-undici 7.3.4 → 7.3.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.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface BodyReadable extends Readable {
17
17
  json(): Promise<unknown>
18
18
  arrayBuffer(): Promise<ArrayBuffer>
19
19
  blob(): Promise<Blob>
20
+ dump(): Promise<void>
20
21
  }
21
22
 
22
23
  export type URLLike = string | URL | URLObject
@@ -19,6 +19,9 @@ class Handler extends DecoratorHandler {
19
19
  #statusCode
20
20
  #headers
21
21
 
22
+ #globalIndex = -1
23
+ #globalArray = (globalThis.__undici_requests ??= [])
24
+
22
25
  constructor(logOpts, opts, { handler }) {
23
26
  super(handler)
24
27
 
@@ -31,6 +34,8 @@ class Handler extends DecoratorHandler {
31
34
 
32
35
  this.#logger.debug('upstream request started')
33
36
  this.#timing.created = this.#created + performance.timeOrigin
37
+
38
+ this.#globalIndex = this.#globalArray.push(this) - 1
34
39
  }
35
40
 
36
41
  onConnect(abort) {
@@ -110,6 +115,8 @@ class Handler extends DecoratorHandler {
110
115
  this.#logger.debug(data, 'upstream request completed')
111
116
  }
112
117
 
118
+ this.onDone()
119
+
113
120
  super.onComplete()
114
121
  }
115
122
 
@@ -137,8 +144,21 @@ class Handler extends DecoratorHandler {
137
144
  this.#logger.error(data, 'upstream request failed')
138
145
  }
139
146
 
147
+ this.onDone()
148
+
140
149
  super.onError(err)
141
150
  }
151
+
152
+ onDone() {
153
+ if (this.#globalIndex !== -1) {
154
+ const tmp = this.#globalArray.pop()
155
+ if (tmp !== this) {
156
+ this.#globalArray[this.#globalIndex] = tmp
157
+ tmp.#globalIndex = this.#globalIndex
158
+ }
159
+ this.#globalIndex = -1
160
+ }
161
+ }
142
162
  }
143
163
 
144
164
  export default (logOpts) => (dispatch) => (opts, handler) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "7.3.4",
3
+ "version": "7.3.6",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",