@nxtedition/lib 14.0.23 → 14.0.25
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/ass.js +1 -2
- package/couch.js +49 -42
- package/errors.js +24 -1
- package/package.json +1 -1
package/ass.js
CHANGED
package/couch.js
CHANGED
|
@@ -246,33 +246,38 @@ module.exports = function (opts) {
|
|
|
246
246
|
bodyTimeout: 2 * (params.heartbeat || 60e3),
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
retryCount = 0
|
|
249
|
+
try {
|
|
250
|
+
const res = await client.request(req)
|
|
252
251
|
|
|
253
|
-
|
|
254
|
-
for await (const chunk of res.body) {
|
|
255
|
-
const lines = (str + chunk).split('\n')
|
|
256
|
-
str = lines.pop() ?? ''
|
|
252
|
+
retryCount = 0
|
|
257
253
|
|
|
258
|
-
|
|
259
|
-
for (const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
254
|
+
let str = ''
|
|
255
|
+
for await (const chunk of res.body) {
|
|
256
|
+
const lines = (str + chunk).split('\n')
|
|
257
|
+
str = lines.pop() ?? ''
|
|
258
|
+
|
|
259
|
+
const results = batched ? [] : null
|
|
260
|
+
for (const line of lines) {
|
|
261
|
+
if (line) {
|
|
262
|
+
const change = JSON.parse(line)
|
|
263
|
+
if (change.seq) {
|
|
264
|
+
params.since = change.seq
|
|
265
|
+
}
|
|
266
|
+
if (results) {
|
|
267
|
+
results.push(change)
|
|
268
|
+
} else {
|
|
269
|
+
yield change
|
|
270
|
+
}
|
|
269
271
|
}
|
|
270
272
|
}
|
|
271
|
-
}
|
|
272
273
|
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
if (results?.length) {
|
|
275
|
+
yield results
|
|
276
|
+
}
|
|
275
277
|
}
|
|
278
|
+
} catch (err) {
|
|
279
|
+
Object.assign(err, { data: req })
|
|
280
|
+
throw err
|
|
276
281
|
}
|
|
277
282
|
}
|
|
278
283
|
|
|
@@ -282,28 +287,29 @@ module.exports = function (opts) {
|
|
|
282
287
|
let remaining = parseInt(options.limit) || Infinity
|
|
283
288
|
|
|
284
289
|
const next = async () => {
|
|
290
|
+
const req = {
|
|
291
|
+
path:
|
|
292
|
+
dbPathname +
|
|
293
|
+
'/_changes' +
|
|
294
|
+
`?${new URLSearchParams({
|
|
295
|
+
...params,
|
|
296
|
+
...options.query,
|
|
297
|
+
limit: Math.min(remaining, batchSize),
|
|
298
|
+
feed: live ? 'longpoll' : 'normal',
|
|
299
|
+
})}`,
|
|
300
|
+
idempotent: true,
|
|
301
|
+
blocking: live,
|
|
302
|
+
method,
|
|
303
|
+
body: JSON.stringify(body),
|
|
304
|
+
signal: ac.signal,
|
|
305
|
+
headers: {
|
|
306
|
+
'user-agent': userAgent,
|
|
307
|
+
'request-id': genReqId(),
|
|
308
|
+
...(body ? { 'content-type': 'application/json' } : {}),
|
|
309
|
+
},
|
|
310
|
+
}
|
|
311
|
+
|
|
285
312
|
try {
|
|
286
|
-
const req = {
|
|
287
|
-
path:
|
|
288
|
-
dbPathname +
|
|
289
|
-
'/_changes' +
|
|
290
|
-
`?${new URLSearchParams({
|
|
291
|
-
...params,
|
|
292
|
-
...options.query,
|
|
293
|
-
limit: Math.min(remaining, batchSize),
|
|
294
|
-
feed: live ? 'longpoll' : 'normal',
|
|
295
|
-
})}`,
|
|
296
|
-
idempotent: true,
|
|
297
|
-
blocking: live,
|
|
298
|
-
method,
|
|
299
|
-
body: JSON.stringify(body),
|
|
300
|
-
signal: ac.signal,
|
|
301
|
-
headers: {
|
|
302
|
-
'user-agent': userAgent,
|
|
303
|
-
'request-id': genReqId(),
|
|
304
|
-
...(body ? { 'content-type': 'application/json' } : {}),
|
|
305
|
-
},
|
|
306
|
-
}
|
|
307
313
|
const res = await client.request(req)
|
|
308
314
|
|
|
309
315
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
@@ -316,6 +322,7 @@ module.exports = function (opts) {
|
|
|
316
322
|
|
|
317
323
|
return await res.body.json()
|
|
318
324
|
} catch (err) {
|
|
325
|
+
Object.assign(err, { data: req })
|
|
319
326
|
return { err }
|
|
320
327
|
}
|
|
321
328
|
}
|
package/errors.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const objectHash = require('object-hash')
|
|
2
2
|
const fp = require('lodash/fp.js')
|
|
3
|
+
const { toString } = Object.prototype
|
|
3
4
|
|
|
4
5
|
module.exports.AbortError = class AbortError extends Error {
|
|
5
6
|
constructor() {
|
|
@@ -37,6 +38,8 @@ module.exports.parseError = function parseError(error) {
|
|
|
37
38
|
)
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
const kSeen = Symbol('kSeen')
|
|
42
|
+
|
|
40
43
|
module.exports.serializeError = function serializeError(error) {
|
|
41
44
|
if (!error) {
|
|
42
45
|
return null
|
|
@@ -51,6 +54,24 @@ module.exports.serializeError = function serializeError(error) {
|
|
|
51
54
|
return errors.length === 0 ? null : errors.length === 1 ? errors[0] : errors
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(error, kSeen)) {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
error[kSeen] = undefined
|
|
62
|
+
|
|
63
|
+
const type =
|
|
64
|
+
toString.call(error.constructor) === '[object Function]' ? error.constructor.name : error.name
|
|
65
|
+
|
|
66
|
+
let data = error.data || error.body
|
|
67
|
+
if (typeof data === 'string') {
|
|
68
|
+
try {
|
|
69
|
+
data = JSON.parse(data)
|
|
70
|
+
} catch {
|
|
71
|
+
// Do nothing...
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
54
75
|
let {
|
|
55
76
|
msg,
|
|
56
77
|
message = msg,
|
|
@@ -61,17 +82,19 @@ module.exports.serializeError = function serializeError(error) {
|
|
|
61
82
|
statusCode,
|
|
62
83
|
status = statusCode,
|
|
63
84
|
headers,
|
|
64
|
-
data = body,
|
|
65
85
|
...properties
|
|
66
86
|
} = error
|
|
67
87
|
|
|
68
88
|
errors = Array.isArray(errors) ? errors.map(serializeError) : undefined
|
|
69
89
|
cause = cause ? serializeError(cause) : undefined
|
|
70
90
|
|
|
91
|
+
delete error[kSeen]
|
|
92
|
+
|
|
71
93
|
return JSON.parse(
|
|
72
94
|
JSON.stringify({
|
|
73
95
|
...properties,
|
|
74
96
|
message,
|
|
97
|
+
type,
|
|
75
98
|
code,
|
|
76
99
|
status,
|
|
77
100
|
headers,
|