@nxtedition/lib 19.0.14 → 19.0.16

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.
Files changed (2) hide show
  1. package/couch.js +38 -45
  2. package/package.json +1 -1
package/couch.js CHANGED
@@ -72,10 +72,9 @@ export function makeCouch(opts) {
72
72
  keepAliveTimeout: 2 * 60e3,
73
73
  headersTimeout: 10 * 60e3,
74
74
  bodyTimeout: 2 * 60e3,
75
- connections: 256,
76
75
  }
77
76
 
78
- const userAgent = config.userAgent
77
+ const userAgent = config.userAgent || globalThis.userAgent
79
78
  const defaultClient = new undici.Pool(dbOrigin, defaultClientOpts)
80
79
 
81
80
  const getClient =
@@ -177,7 +176,7 @@ export function makeCouch(opts) {
177
176
  }
178
177
 
179
178
  if (options.heartbeat != null) {
180
- params.heartbeat = options.heartbeat
179
+ params.heartbeat = Number(options.heartbeat)
181
180
  } else {
182
181
  params.heartbeat = 10e3
183
182
  }
@@ -228,55 +227,49 @@ export function makeCouch(opts) {
228
227
  }
229
228
  }
230
229
 
231
- async function parse(live, params) {
232
- const req = {
233
- path: `${dbPathname}/_changes?${new URLSearchParams(params)}`,
234
- idempotent: false,
235
- blocking: true,
236
- method,
237
- body: JSON.stringify(body),
238
- signal: ac.signal,
239
- headers: {
240
- 'user-agent': userAgent,
241
- 'request-id': genReqId(),
242
- ...(body ? { 'content-type': 'application/json' } : {}),
243
- },
244
- highWaterMark: 256 * 1024, // TODO (fix): Needs support in undici...
245
- bodyTimeout: 2 * (params.heartbeat || 60e3),
246
- }
247
-
248
- const res = await client.request(req)
249
-
250
- if (res.statusCode < 200 || res.statusCode >= 300) {
251
- throw makeError(req, {
252
- status: res.statusCode,
253
- headers: res.headers,
254
- data: await res.body.text(),
255
- })
256
- }
257
-
258
- return stream.pipeline(
259
- res.body,
260
- split2('\n', { writableHighWaterMark: highWaterMark ?? 128 * 1024 }),
261
- () => {},
262
- )
263
- }
264
-
265
230
  let remaining = Number(options.limit) || Infinity
266
231
  try {
267
232
  while (true) {
268
233
  try {
269
- const params2 = {
270
- ...params,
271
- ...options.query,
272
- feed: live ? 'continuous' : 'normal',
273
- }
234
+ const query = { ...params, feed: live ? 'continuous' : 'normal' }
274
235
 
275
236
  if (Number.isFinite(remaining)) {
276
- params.limit = remaining
237
+ query.limit = remaining
277
238
  }
278
239
 
279
- const src = await parse(live, params2)
240
+ const req = {
241
+ path: `${dbPathname}/_changes`,
242
+ query,
243
+ idempotent: false,
244
+ blocking: true,
245
+ method,
246
+ body: JSON.stringify(body),
247
+ signal: ac.signal,
248
+ headers: {
249
+ 'user-agent': userAgent,
250
+ 'request-id': genReqId(),
251
+ ...(body ? { 'content-type': 'application/json' } : {}),
252
+ },
253
+ highWaterMark: 256 * 1024, // TODO (fix): Needs support in undici...
254
+ bodyTimeout: 2 * (params.heartbeat || 60e3),
255
+ }
256
+
257
+ const res = await client.request(req)
258
+
259
+ if (res.statusCode < 200 || res.statusCode >= 300) {
260
+ throw makeError(req, {
261
+ status: res.statusCode,
262
+ headers: res.headers,
263
+ data: await res.body.text(),
264
+ })
265
+ }
266
+
267
+ const src = stream.pipeline(
268
+ res.body,
269
+ split2('\n', { writableHighWaterMark: highWaterMark ?? 256 * 1024 }),
270
+ () => {},
271
+ )
272
+
280
273
  const changes = []
281
274
 
282
275
  let resume = null
@@ -312,7 +305,7 @@ export function makeCouch(opts) {
312
305
  params.since = data.last_seq
313
306
  } else {
314
307
  params.since = data.seq || params.since
315
- this.push(data)
308
+ changes.push(data)
316
309
  }
317
310
  } else {
318
311
  // NOTE: This makes some assumptions about the format of the JSON.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.0.14",
3
+ "version": "19.0.16",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",