@nxtedition/lib 21.8.4 → 21.9.0

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.
Files changed (3) hide show
  1. package/couch.js +12 -6
  2. package/http.js +3 -4
  3. package/package.json +1 -1
package/couch.js CHANGED
@@ -999,11 +999,13 @@ class PromiseOutput {
999
999
  #decoder
1000
1000
  #signal
1001
1001
  #abort
1002
+ #parse
1002
1003
 
1003
- constructor({ resolve, reject, signal }) {
1004
+ constructor({ resolve, reject, signal, parse }) {
1004
1005
  this.#resolve = resolve
1005
1006
  this.#reject = reject
1006
1007
  this.#signal = signal
1008
+ this.#parse = parse ?? true
1007
1009
  }
1008
1010
 
1009
1011
  onConnect(abort) {
@@ -1030,10 +1032,14 @@ class PromiseOutput {
1030
1032
 
1031
1033
  onComplete() {
1032
1034
  this.#str += this.#decoder.decode(undefined, { stream: false })
1033
- try {
1034
- this.#onDone(null, JSON.parse(this.#str))
1035
- } catch (err) {
1036
- this.#onDone(Object.assign(new Error('invalid json'), { data: this.#str, cause: err }))
1035
+ if (this.#parse) {
1036
+ try {
1037
+ this.#onDone(null, JSON.parse(this.#str))
1038
+ } catch (err) {
1039
+ this.#onDone(Object.assign(new Error('invalid json'), { data: this.#str, cause: err }))
1040
+ }
1041
+ } else {
1042
+ this.#onDone(null, this.#str)
1037
1043
  }
1038
1044
  }
1039
1045
 
@@ -1097,7 +1103,7 @@ export function request(url, opts) {
1097
1103
  return handler
1098
1104
  } else {
1099
1105
  return new Promise((resolve, reject) => {
1100
- const handler = new PromiseOutput({ resolve, reject, signal })
1106
+ const handler = new PromiseOutput({ resolve, reject, signal, parse: opts.parse })
1101
1107
  dispatch(dispatcher, ureq, handler)
1102
1108
  })
1103
1109
  }
package/http.js CHANGED
@@ -414,7 +414,7 @@ export class ServerResponse extends http.ServerResponse {
414
414
  }
415
415
 
416
416
  if (this.#timing.headers === -1) {
417
- this.#timing.headers = this.#timing.data
417
+ this.#timing.headers = this.#timing.end
418
418
  }
419
419
  }
420
420
 
@@ -484,7 +484,7 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
484
484
  }
485
485
 
486
486
  if (this.#timing.headers === -1) {
487
- this.#timing.headers = this.#timing.data
487
+ this.#timing.headers = this.#timing.end
488
488
  }
489
489
  }
490
490
 
@@ -494,8 +494,7 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
494
494
  destroy(err) {
495
495
  if (!this.destroyed) {
496
496
  if (this.#timing.end === -1) {
497
- this.#timing.end = performance.now() - this.#now
498
- this.#now += this.#timing.end
497
+ this.#timing.end = performance.now() - this.#created
499
498
  }
500
499
  }
501
500
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "21.8.4",
3
+ "version": "21.9.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",