@nxtedition/lib 15.1.3 → 15.1.5
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 +4 -0
- package/http.js +26 -29
- package/package.json +1 -1
package/couch.js
CHANGED
|
@@ -340,7 +340,11 @@ module.exports = function (opts) {
|
|
|
340
340
|
|
|
341
341
|
if (seq) {
|
|
342
342
|
params.since = seq
|
|
343
|
+
if (results.length > 0 && !results.at(-1)?.seq) {
|
|
344
|
+
results.at(-1).seq = seq
|
|
345
|
+
}
|
|
343
346
|
}
|
|
347
|
+
|
|
344
348
|
remaining -= results.length
|
|
345
349
|
|
|
346
350
|
if (!live && results.length === 0) {
|
package/http.js
CHANGED
|
@@ -23,24 +23,11 @@ function genReqId() {
|
|
|
23
23
|
return `req-${nextReqId.toString(36)}`
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function onTimeout() {
|
|
27
|
-
this.destroy(new createError.RequestTimeout())
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function onRequestError(err) {
|
|
31
|
-
this.log.error({ err }, 'request error')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function onRequestEnd() {
|
|
35
|
-
this.log.debug('request end')
|
|
36
|
-
}
|
|
37
|
-
|
|
38
26
|
module.exports.request = async function request(ctx, next) {
|
|
39
27
|
const { req, res, logger } = ctx
|
|
40
28
|
const startTime = performance.now()
|
|
41
29
|
|
|
42
30
|
const ac = new AbortController()
|
|
43
|
-
const signal = ac.signal
|
|
44
31
|
|
|
45
32
|
let reqLogger = logger
|
|
46
33
|
try {
|
|
@@ -51,7 +38,7 @@ module.exports.request = async function request(ctx, next) {
|
|
|
51
38
|
|
|
52
39
|
ctx.id = req.id = req.headers['request-id'] || genReqId()
|
|
53
40
|
ctx.logger = req.log = res.log = logger.child({ req: { id: req.id, url: req.url } })
|
|
54
|
-
ctx.signal = signal
|
|
41
|
+
ctx.signal = ac.signal
|
|
55
42
|
ctx.method = req.method
|
|
56
43
|
ctx.query = ctx.url.search.length > 1 ? querystring.parse(ctx.url.search.slice(1)) : {}
|
|
57
44
|
|
|
@@ -63,7 +50,7 @@ module.exports.request = async function request(ctx, next) {
|
|
|
63
50
|
|
|
64
51
|
const isHealthcheck = ctx.url.pathname === '/healthcheck'
|
|
65
52
|
|
|
66
|
-
reqLogger =
|
|
53
|
+
reqLogger = logger.child({ req })
|
|
67
54
|
if (!isHealthcheck) {
|
|
68
55
|
reqLogger.debug('request started')
|
|
69
56
|
} else {
|
|
@@ -72,26 +59,33 @@ module.exports.request = async function request(ctx, next) {
|
|
|
72
59
|
|
|
73
60
|
next()?.catch((err) => res.destroy(err))
|
|
74
61
|
|
|
75
|
-
await new Promise((resolve
|
|
76
|
-
req
|
|
62
|
+
await new Promise((resolve) => {
|
|
63
|
+
req
|
|
64
|
+
.on('timeout', function () {
|
|
65
|
+
this.destroy(new createError.RequestTimeout())
|
|
66
|
+
})
|
|
67
|
+
.on('error', function (err) {
|
|
68
|
+
this.log.error({ err }, 'request error')
|
|
69
|
+
})
|
|
70
|
+
.on('end', function () {
|
|
71
|
+
this.log.debug('request end')
|
|
72
|
+
})
|
|
73
|
+
.on('close', function () {
|
|
74
|
+
this.log.debug('request close')
|
|
75
|
+
})
|
|
77
76
|
res
|
|
78
|
-
.on('timeout',
|
|
77
|
+
.on('timeout', function () {
|
|
78
|
+
this.destroy(new createError.RequestTimeout())
|
|
79
|
+
})
|
|
79
80
|
.on('error', function (err) {
|
|
80
81
|
this.log.error({ err }, 'response error')
|
|
81
|
-
ac.abort(err)
|
|
82
|
-
reject(err)
|
|
83
82
|
})
|
|
84
83
|
.on('finish', function () {
|
|
85
84
|
this.log.debug('response finish')
|
|
86
|
-
ac.abort()
|
|
87
|
-
resolve(null)
|
|
88
85
|
})
|
|
89
|
-
// TODO (fix): Remove this once we can trust that
|
|
90
|
-
// node always emits error or finish.
|
|
91
86
|
.on('close', function () {
|
|
92
87
|
this.log.debug('response close')
|
|
93
|
-
|
|
94
|
-
resolve(null)
|
|
88
|
+
resolve(this.errored ? Promise.reject(this.errored) : null)
|
|
95
89
|
})
|
|
96
90
|
})
|
|
97
91
|
|
|
@@ -108,8 +102,9 @@ module.exports.request = async function request(ctx, next) {
|
|
|
108
102
|
} else {
|
|
109
103
|
reqLogger.trace({ res, responseTime }, 'request completed')
|
|
110
104
|
}
|
|
105
|
+
|
|
106
|
+
ac.abort()
|
|
111
107
|
} catch (err) {
|
|
112
|
-
const reason = ac.signal.reason
|
|
113
108
|
const responseTime = Math.round(performance.now() - startTime)
|
|
114
109
|
|
|
115
110
|
req.on('error', (err) => {
|
|
@@ -150,7 +145,7 @@ module.exports.request = async function request(ctx, next) {
|
|
|
150
145
|
res.write(JSON.stringify(err.body))
|
|
151
146
|
}
|
|
152
147
|
|
|
153
|
-
reqLogger = reqLogger.child({ res, err,
|
|
148
|
+
reqLogger = reqLogger.child({ res, err, responseTime })
|
|
154
149
|
|
|
155
150
|
if (res.statusCode < 500) {
|
|
156
151
|
reqLogger.warn('request failed')
|
|
@@ -162,7 +157,7 @@ module.exports.request = async function request(ctx, next) {
|
|
|
162
157
|
|
|
163
158
|
res.end()
|
|
164
159
|
} else {
|
|
165
|
-
reqLogger = reqLogger.child({ res, err,
|
|
160
|
+
reqLogger = reqLogger.child({ res, err, responseTime })
|
|
166
161
|
|
|
167
162
|
if (req.aborted || !res.writableEnded || err.name === 'AbortError') {
|
|
168
163
|
reqLogger.debug('request aborted')
|
|
@@ -179,6 +174,8 @@ module.exports.request = async function request(ctx, next) {
|
|
|
179
174
|
res.destroy()
|
|
180
175
|
}
|
|
181
176
|
}
|
|
177
|
+
|
|
178
|
+
ac.abort(err)
|
|
182
179
|
}
|
|
183
180
|
}
|
|
184
181
|
|