@nxtedition/lib 19.8.2 → 19.8.4

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 +48 -39
  2. package/package.json +8 -9
package/couch.js CHANGED
@@ -8,7 +8,6 @@ import { defaultDelay as delay } from './http.js'
8
8
  import urljoin from 'url-join'
9
9
  import undici, { util as undiciUtil } from 'undici'
10
10
  import { AbortError } from './errors.js'
11
- import split2 from 'split2'
12
11
  import { interceptors } from '@nxtedition/nxt-undici'
13
12
 
14
13
  // https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js
@@ -265,11 +264,7 @@ export function makeCouch(opts) {
265
264
  })
266
265
  }
267
266
 
268
- src = stream.pipeline(
269
- ures.body,
270
- split2('\n', { writableHighWaterMark: highWaterMark ?? 256 * 1024 }),
271
- () => {},
272
- )
267
+ src = ures.body
273
268
 
274
269
  const changes = []
275
270
 
@@ -297,42 +292,59 @@ export function makeCouch(opts) {
297
292
  })
298
293
  .on('close', maybeResume)
299
294
 
295
+ let str = ''
300
296
  while (true) {
301
- const line = src.read()
302
- if (line) {
303
- if (live) {
304
- const data = JSON.parse(line)
305
- if (data.last_seq) {
306
- params.since = data.last_seq
307
- } else {
308
- params.since = data.seq || params.since
309
- changes.push(data)
310
- }
311
- } else {
312
- // NOTE: This makes some assumptions about the format of the JSON.
313
- if (state === 0) {
314
- if (line.endsWith('[')) {
315
- state = 1
297
+ const chunk = src.read()
298
+
299
+ if (chunk !== null) {
300
+ const lines = (str + chunk).split(/\r?\n/)
301
+ str = lines.pop() ?? ''
302
+
303
+ for (const line of lines) {
304
+ if (line === '') {
305
+ // hearbeat
306
+ yield batched ? [] : null
307
+ } else if (line === ',') {
308
+ // Do nothing. Couch sometimes insert new line between
309
+ // json body and comma.
310
+ } else if (live) {
311
+ const data = JSON.parse(line)
312
+ if (data.last_seq) {
313
+ params.since = data.last_seq
316
314
  } else {
317
- assert(false, 'invalid head: ' + line)
315
+ params.since = data.seq || params.since
316
+ changes.push(data)
318
317
  }
319
- } else if (state === 1) {
320
- if (line.startsWith(']')) {
321
- state = 2
322
- } else {
323
- const idx = line.lastIndexOf('}') + 1
324
- assert(idx > 0, 'invalid row: ' + line)
325
- const change = JSON.parse(line.slice(0, idx))
326
- params.since = change.seq || params.since
327
- changes.push(change)
318
+ } else {
319
+ // NOTE: This makes some assumptions about the format of the JSON.
320
+ if (state === 0) {
321
+ if (line.endsWith('[')) {
322
+ state = 1
323
+ } else {
324
+ assert(false, 'invalid head: ' + line)
325
+ }
326
+ } else if (state === 1) {
327
+ if (line.startsWith(']')) {
328
+ state = 2
329
+ } else {
330
+ const idx = line.lastIndexOf('}') + 1
331
+ try {
332
+ assert(idx >= 0, 'invalid row: ' + idx + ' ' + line)
333
+ const change = JSON.parse(line.slice(0, idx))
334
+ params.since = change.seq || params.since
335
+ changes.push(change)
336
+ } catch (err) {
337
+ throw Object.assign(err, { data: line })
338
+ }
339
+ }
340
+ } else if (state === 2) {
341
+ state = 3
342
+ params.since = JSON.parse('{' + line).last_seq
343
+ assert(params.since, 'invalid trailer: ' + line)
328
344
  }
329
- } else if (state === 2) {
330
- state = 3
331
- params.since = JSON.parse('{' + line).last_seq
332
- assert(params.since, 'invalid trailer: ' + line)
333
345
  }
334
346
  }
335
- } else if (changes.length || line === '') {
347
+ } else if (changes.length) {
336
348
  remaining -= changes.length
337
349
  assert(remaining >= 0, 'invalid remaining: ' + remaining)
338
350
 
@@ -1124,9 +1136,6 @@ export function request(
1124
1136
  interceptors.requestId,
1125
1137
  interceptors.responseRetry,
1126
1138
  interceptors.responseVerify,
1127
- interceptors.redirect,
1128
- interceptors.cache,
1129
- interceptors.proxy,
1130
1139
  )
1131
1140
  dispatcherCache.set(dispatcher, wrappedDispatcher)
1132
1141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.8.2",
3
+ "version": "19.8.4",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -79,10 +79,10 @@
79
79
  "**/*.d.ts"
80
80
  ],
81
81
  "dependencies": {
82
- "@aws-sdk/client-s3": "^3.596.0",
83
- "@elastic/elasticsearch": "^8.13.1",
84
- "@elastic/transport": "^8.6.0",
85
- "@nxtedition/nxt-undici": "^2.2.5",
82
+ "@aws-sdk/client-s3": "^3.600.0",
83
+ "@elastic/elasticsearch": "^8.14.0",
84
+ "@elastic/transport": "^8.6.1",
85
+ "@nxtedition/nxt-undici": "^3.0.3",
86
86
  "content-type": "^1.0.5",
87
87
  "date-fns": "^3.6.0",
88
88
  "fast-querystring": "^1.1.1",
@@ -100,17 +100,16 @@
100
100
  "pino": "^9.2.0",
101
101
  "qs": "^6.12.1",
102
102
  "request-target": "^1.0.2",
103
- "smpte-timecode": "^1.3.5",
103
+ "smpte-timecode": "^1.3.6",
104
104
  "split-string": "^6.0.0",
105
- "split2": "^4.2.0",
106
105
  "toobusy-js": "^0.5.1",
107
- "undici": "^6.18.2",
106
+ "undici": "^6.19.2",
108
107
  "url-join": "^5.0.0"
109
108
  },
110
109
  "devDependencies": {
111
110
  "@nxtedition/deepstream.io-client-js": ">=24.2.4",
112
111
  "@types/lodash": "^4.17.5",
113
- "@types/node": "^20.14.2",
112
+ "@types/node": "^20.14.8",
114
113
  "eslint": "^8.0.0",
115
114
  "eslint-config-prettier": "^9.1.0",
116
115
  "eslint-config-standard": "^17.0.0",