@nxtedition/lib 19.7.1 → 19.8.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 +47 -1
- package/package.json +1 -1
package/couch.js
CHANGED
|
@@ -1028,11 +1028,26 @@ class StreamOutput extends stream.Readable {
|
|
|
1028
1028
|
#abort
|
|
1029
1029
|
#state
|
|
1030
1030
|
#decoder
|
|
1031
|
+
#headers
|
|
1032
|
+
#startTime = performance.now()
|
|
1033
|
+
#stats = {
|
|
1034
|
+
connect: -1,
|
|
1035
|
+
headers: -1,
|
|
1036
|
+
ttfb: -1,
|
|
1037
|
+
}
|
|
1031
1038
|
|
|
1032
1039
|
constructor({ highWaterMark = 256 }) {
|
|
1033
1040
|
super({ objectMode: true, highWaterMark })
|
|
1034
1041
|
}
|
|
1035
1042
|
|
|
1043
|
+
get headers() {
|
|
1044
|
+
return this.#headers
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
get stats() {
|
|
1048
|
+
return this.#stats
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1036
1051
|
_read() {
|
|
1037
1052
|
this.#resume?.()
|
|
1038
1053
|
}
|
|
@@ -1043,6 +1058,8 @@ class StreamOutput extends stream.Readable {
|
|
|
1043
1058
|
}
|
|
1044
1059
|
|
|
1045
1060
|
onConnect(abort) {
|
|
1061
|
+
this.#stats.connect = performance.now() - this.#startTime
|
|
1062
|
+
|
|
1046
1063
|
if (this.destroyed) {
|
|
1047
1064
|
abort(this.errored)
|
|
1048
1065
|
} else if (this.#state) {
|
|
@@ -1056,14 +1073,23 @@ class StreamOutput extends stream.Readable {
|
|
|
1056
1073
|
}
|
|
1057
1074
|
|
|
1058
1075
|
onHeaders(statusCode, rawHeaders, resume, statusText) {
|
|
1076
|
+
if (this.#stats.headers === -1) {
|
|
1077
|
+
this.#stats.headers = performance.now() - this.#startTime - this.#stats.connect
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1059
1080
|
if (statusCode >= 300 || statusCode < 200) {
|
|
1060
1081
|
throw new Error('invalid status code: ' + statusCode)
|
|
1061
1082
|
}
|
|
1062
1083
|
|
|
1084
|
+
this.#headers = Array.isArray(rawHeaders) ? undiciUtil.parseHeaders(rawHeaders) : rawHeaders
|
|
1063
1085
|
this.#resume = resume
|
|
1064
1086
|
}
|
|
1065
1087
|
|
|
1066
1088
|
onData(data) {
|
|
1089
|
+
if (this.#stats.ttfb === -1) {
|
|
1090
|
+
this.#stats.ttfb = performance.now() - this.#startTime - this.#stats.headers
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1067
1093
|
const lines = this.#decoder.decode(data, { stream: true }).split(/\r?\n+/)
|
|
1068
1094
|
lines[0] = this.#str + lines[0]
|
|
1069
1095
|
this.#str = lines.pop() ?? ''
|
|
@@ -1108,6 +1134,13 @@ class PromiseOutput {
|
|
|
1108
1134
|
#reject
|
|
1109
1135
|
#str
|
|
1110
1136
|
#decoder
|
|
1137
|
+
#headers
|
|
1138
|
+
#startTime = performance.now()
|
|
1139
|
+
#stats = {
|
|
1140
|
+
connect: -1,
|
|
1141
|
+
headers: -1,
|
|
1142
|
+
ttfb: -1,
|
|
1143
|
+
}
|
|
1111
1144
|
|
|
1112
1145
|
constructor({ resolve, reject }) {
|
|
1113
1146
|
this.#resolve = resolve
|
|
@@ -1115,23 +1148,36 @@ class PromiseOutput {
|
|
|
1115
1148
|
}
|
|
1116
1149
|
|
|
1117
1150
|
onConnect() {
|
|
1151
|
+
this.#stats.connect = performance.now() - this.#startTime
|
|
1118
1152
|
this.#decoder = new TextDecoder()
|
|
1119
1153
|
this.#str = ''
|
|
1120
1154
|
}
|
|
1121
1155
|
|
|
1122
1156
|
onHeaders(statusCode, rawHeaders, resume, statusText) {
|
|
1157
|
+
if (this.#stats.headers === -1) {
|
|
1158
|
+
this.#stats.headers = performance.now() - this.#startTime - this.#stats.connect
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1123
1161
|
if (statusCode >= 300 || statusCode < 200) {
|
|
1124
1162
|
throw new Error('invalid status code: ' + statusCode)
|
|
1125
1163
|
}
|
|
1164
|
+
this.#headers = Array.isArray(rawHeaders) ? undiciUtil.parseHeaders(rawHeaders) : rawHeaders
|
|
1126
1165
|
}
|
|
1127
1166
|
|
|
1128
1167
|
onData(data) {
|
|
1168
|
+
if (this.#stats.ttfb === -1) {
|
|
1169
|
+
this.#stats.ttfb = performance.now() - this.#startTime - this.#stats.headers
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1129
1172
|
this.#str += this.#decoder.decode(data, { stream: true })
|
|
1130
1173
|
}
|
|
1131
1174
|
|
|
1132
1175
|
onComplete() {
|
|
1133
1176
|
this.#str += this.#decoder.decode(undefined, { stream: false })
|
|
1134
|
-
|
|
1177
|
+
|
|
1178
|
+
this.#resolve(
|
|
1179
|
+
Object.assign(JSON.parse(this.#str), { headers: this.#headers, stats: this.#stats }),
|
|
1180
|
+
)
|
|
1135
1181
|
}
|
|
1136
1182
|
|
|
1137
1183
|
onError(err) {
|