@nxtedition/lib 19.0.0 → 19.0.2
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 +15 -11
- package/package.json +1 -1
package/couch.js
CHANGED
|
@@ -6,6 +6,7 @@ import { defaultDelay as delay } from './http.js'
|
|
|
6
6
|
import querystring from 'querystring'
|
|
7
7
|
import urljoin from 'url-join'
|
|
8
8
|
import undici from 'undici'
|
|
9
|
+
import { AbortError } from './errors.js'
|
|
9
10
|
|
|
10
11
|
// https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js
|
|
11
12
|
// 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8).
|
|
@@ -114,7 +115,6 @@ export function makeCouch(opts) {
|
|
|
114
115
|
return createError(res.status, {
|
|
115
116
|
reason,
|
|
116
117
|
error,
|
|
117
|
-
body: req.body ? JSON.stringify(req.body).slice(0, 4096) : null,
|
|
118
118
|
data: {
|
|
119
119
|
req: {
|
|
120
120
|
origin: dbOrigin,
|
|
@@ -216,13 +216,13 @@ export function makeCouch(opts) {
|
|
|
216
216
|
|
|
217
217
|
if (signal) {
|
|
218
218
|
if (signal.aborted) {
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
throw signal.reason ?? new AbortError()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (signal.on) {
|
|
223
|
+
signal.on('abort', onAbort)
|
|
224
|
+
} else if (signal.addEventListener) {
|
|
225
|
+
signal.addEventListener('abort', onAbort)
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -251,7 +251,6 @@ export function makeCouch(opts) {
|
|
|
251
251
|
'request-id': genReqId(),
|
|
252
252
|
...(body ? { 'content-type': 'application/json' } : {}),
|
|
253
253
|
},
|
|
254
|
-
throwOnError: true,
|
|
255
254
|
highWaterMark: 256 * 1024, // TODO (fix): Needs support in undici...
|
|
256
255
|
bodyTimeout: 2 * (params.heartbeat || 60e3),
|
|
257
256
|
}
|
|
@@ -290,8 +289,8 @@ export function makeCouch(opts) {
|
|
|
290
289
|
if (live) {
|
|
291
290
|
const data = JSON.parse(line)
|
|
292
291
|
if (data.last_seq) {
|
|
292
|
+
assert(data.last_seq, 'invalid last_seq: ' + data.last_seq)
|
|
293
293
|
params.since = data.last_seq
|
|
294
|
-
assert(params.since, 'invalid last_seq: ' + params.since)
|
|
295
294
|
} else {
|
|
296
295
|
params.since = data.seq || params.since
|
|
297
296
|
changes.push(data)
|
|
@@ -351,7 +350,12 @@ export function makeCouch(opts) {
|
|
|
351
350
|
throw err
|
|
352
351
|
} else if (typeof retry === 'function') {
|
|
353
352
|
const retryState = { since: params.since }
|
|
354
|
-
Object.assign(
|
|
353
|
+
Object.assign(
|
|
354
|
+
retryState,
|
|
355
|
+
await retry(err, retryCount++, retryState, { signal }, () =>
|
|
356
|
+
delay(err, retryCount, { signal }),
|
|
357
|
+
),
|
|
358
|
+
)
|
|
355
359
|
params.since = retryState.since ?? 0
|
|
356
360
|
} else {
|
|
357
361
|
await delay(err, retryCount, { signal })
|