@nxtedition/nxt-undici 2.0.12 → 2.0.14

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 CHANGED
@@ -278,6 +278,7 @@ export async function request(url, opts) {
278
278
  this.abort(createError(statusCode, { headers }))
279
279
  } else {
280
280
  this.resolve({ headers, socket })
281
+ this.resolve = null
281
282
  }
282
283
  },
283
284
  onBodySent(chunk) {},
@@ -128,6 +128,7 @@ class Handler {
128
128
  count: this.count,
129
129
  }),
130
130
  )
131
+ this.handler = null
131
132
  } else {
132
133
  return this.handler.onComplete(trailers)
133
134
  }
@@ -1,61 +1,19 @@
1
- class Handler {
2
- constructor(opts, { handler, dispatch }) {
3
- this.handler = handler
4
- this.dispatch = dispatch
5
- this.ac = new AbortController()
6
-
7
- const signal = opts.signal ? AbortSignal.any([this.ac.signal, opts.signal]) : this.ac.signal
8
-
9
- const body = opts.body({ signal })
10
-
11
- if (typeof body.then === 'function') {
12
- body.then(
13
- (body) => this.dispatch({ ...opts, body }, handler),
14
- (err) => this.handler.onError(err),
15
- )
16
- } else {
17
- this.dispatch({ ...opts, body }, handler)
18
- }
19
- }
20
-
21
- onConnect(abort) {
22
- this.abort = (err) => {
23
- this.ac.abort(err)
24
- abort(err)
25
- }
26
- return this.handler.onConnect(abort)
27
- }
28
-
29
- onUpgrade(statusCode, rawHeaders, socket) {
30
- return this.handler.onUpgrade(statusCode, rawHeaders, socket)
31
- }
32
-
33
- onBodySent(chunk) {
34
- return this.handler.onBodySent(chunk)
35
- }
36
-
37
- onRequestSent() {
38
- return this.handler.onRequestSent()
39
- }
40
-
41
- onHeaders(statusCode, rawHeaders, resume, statusMessage) {
42
- return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
1
+ export default (dispatch) => (opts, handler) => {
2
+ if (typeof opts.body !== 'function') {
3
+ return dispatch(opts, handler)
43
4
  }
44
5
 
45
- onData(chunk) {
46
- return this.handler.onData(chunk)
47
- }
6
+ // TODO (fix): Can we do signal in a better way using
7
+ // a handler?
48
8
 
49
- onComplete(rawTrailers) {
50
- return this.handler.onComplete(rawTrailers)
51
- }
9
+ const body = opts.body({ signal: opts.signal })
52
10
 
53
- onError(err) {
54
- return this.handler.onError(err)
11
+ if (typeof body.then === 'function') {
12
+ body.then(
13
+ (body) => dispatch({ ...opts, body }, handler),
14
+ (err) => handler.onError(err),
15
+ )
16
+ } else {
17
+ dispatch({ ...opts, body }, handler)
55
18
  }
56
19
  }
57
-
58
- export default (dispatch) => (opts, handler) =>
59
- typeof opts.body === 'function'
60
- ? dispatch(opts, new Handler(opts, { handler, dispatch }))
61
- : dispatch(opts, handler)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",