@nxtedition/lib 19.7.2 → 19.8.1
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 +48 -1
- package/package.json +1 -1
package/couch.js
CHANGED
|
@@ -1029,6 +1029,12 @@ class StreamOutput extends stream.Readable {
|
|
|
1029
1029
|
#state
|
|
1030
1030
|
#decoder
|
|
1031
1031
|
#headers
|
|
1032
|
+
#startTime = performance.now()
|
|
1033
|
+
#stats = {
|
|
1034
|
+
connect: -1,
|
|
1035
|
+
headers: -1,
|
|
1036
|
+
ttfb: -1,
|
|
1037
|
+
}
|
|
1032
1038
|
|
|
1033
1039
|
constructor({ highWaterMark = 256 }) {
|
|
1034
1040
|
super({ objectMode: true, highWaterMark })
|
|
@@ -1038,6 +1044,10 @@ class StreamOutput extends stream.Readable {
|
|
|
1038
1044
|
return this.#headers
|
|
1039
1045
|
}
|
|
1040
1046
|
|
|
1047
|
+
get stats() {
|
|
1048
|
+
return this.#stats
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1041
1051
|
_read() {
|
|
1042
1052
|
this.#resume?.()
|
|
1043
1053
|
}
|
|
@@ -1048,6 +1058,8 @@ class StreamOutput extends stream.Readable {
|
|
|
1048
1058
|
}
|
|
1049
1059
|
|
|
1050
1060
|
onConnect(abort) {
|
|
1061
|
+
this.#stats.connect = performance.now() - this.#startTime
|
|
1062
|
+
|
|
1051
1063
|
if (this.destroyed) {
|
|
1052
1064
|
abort(this.errored)
|
|
1053
1065
|
} else if (this.#state) {
|
|
@@ -1061,6 +1073,10 @@ class StreamOutput extends stream.Readable {
|
|
|
1061
1073
|
}
|
|
1062
1074
|
|
|
1063
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
|
+
|
|
1064
1080
|
if (statusCode >= 300 || statusCode < 200) {
|
|
1065
1081
|
throw new Error('invalid status code: ' + statusCode)
|
|
1066
1082
|
}
|
|
@@ -1070,6 +1086,10 @@ class StreamOutput extends stream.Readable {
|
|
|
1070
1086
|
}
|
|
1071
1087
|
|
|
1072
1088
|
onData(data) {
|
|
1089
|
+
if (this.#stats.ttfb === -1) {
|
|
1090
|
+
this.#stats.ttfb = performance.now() - this.#startTime - this.#stats.headers
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1073
1093
|
const lines = this.#decoder.decode(data, { stream: true }).split(/\r?\n+/)
|
|
1074
1094
|
lines[0] = this.#str + lines[0]
|
|
1075
1095
|
this.#str = lines.pop() ?? ''
|
|
@@ -1115,6 +1135,14 @@ class PromiseOutput {
|
|
|
1115
1135
|
#str
|
|
1116
1136
|
#decoder
|
|
1117
1137
|
#headers
|
|
1138
|
+
#startTime = performance.now()
|
|
1139
|
+
#stats = {
|
|
1140
|
+
connect: -1,
|
|
1141
|
+
headers: -1,
|
|
1142
|
+
data: -1,
|
|
1143
|
+
complete: -1,
|
|
1144
|
+
error: -1,
|
|
1145
|
+
}
|
|
1118
1146
|
|
|
1119
1147
|
constructor({ resolve, reject }) {
|
|
1120
1148
|
this.#resolve = resolve
|
|
@@ -1122,11 +1150,16 @@ class PromiseOutput {
|
|
|
1122
1150
|
}
|
|
1123
1151
|
|
|
1124
1152
|
onConnect() {
|
|
1153
|
+
this.#stats.connect = performance.now() - this.#startTime
|
|
1125
1154
|
this.#decoder = new TextDecoder()
|
|
1126
1155
|
this.#str = ''
|
|
1127
1156
|
}
|
|
1128
1157
|
|
|
1129
1158
|
onHeaders(statusCode, rawHeaders, resume, statusText) {
|
|
1159
|
+
if (this.#stats.headers === -1) {
|
|
1160
|
+
this.#stats.headers = performance.now() - this.#startTime - this.#stats.connect
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1130
1163
|
if (statusCode >= 300 || statusCode < 200) {
|
|
1131
1164
|
throw new Error('invalid status code: ' + statusCode)
|
|
1132
1165
|
}
|
|
@@ -1134,16 +1167,30 @@ class PromiseOutput {
|
|
|
1134
1167
|
}
|
|
1135
1168
|
|
|
1136
1169
|
onData(data) {
|
|
1170
|
+
if (this.#stats.data === -1) {
|
|
1171
|
+
this.#stats.data = performance.now() - this.#startTime - this.#stats.headers
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1137
1174
|
this.#str += this.#decoder.decode(data, { stream: true })
|
|
1138
1175
|
}
|
|
1139
1176
|
|
|
1140
1177
|
onComplete() {
|
|
1178
|
+
if (this.#stats.complete === -1) {
|
|
1179
|
+
this.#stats.complete = performance.now() - this.#startTime - this.#stats.data
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1141
1182
|
this.#str += this.#decoder.decode(undefined, { stream: false })
|
|
1142
1183
|
|
|
1143
|
-
this.#resolve(
|
|
1184
|
+
this.#resolve(
|
|
1185
|
+
Object.assign(JSON.parse(this.#str), { headers: this.#headers, stats: this.#stats }),
|
|
1186
|
+
)
|
|
1144
1187
|
}
|
|
1145
1188
|
|
|
1146
1189
|
onError(err) {
|
|
1190
|
+
if (this.#stats.error === -1) {
|
|
1191
|
+
this.#stats.error = performance.now() - this.#startTime - this.#stats.data
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1147
1194
|
this.#reject(err)
|
|
1148
1195
|
}
|
|
1149
1196
|
}
|