@nxtedition/lib 21.8.5 → 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.
- package/couch.js +12 -6
- 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
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
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
|
}
|