@nxtedition/lib 20.0.1 → 20.0.3

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 +22 -10
  2. package/package.json +1 -1
package/couch.js CHANGED
@@ -120,6 +120,17 @@ export function makeCouch(opts) {
120
120
  })
121
121
  }
122
122
 
123
+ /**
124
+ * Fetches changes from the CouchDB changes feed.
125
+ *
126
+ * @param {Object} [options={}] - The options for fetching changes.
127
+ * @param {AbortSignal} [options.signal=null] - The signal to abort the request.
128
+ * @param {boolean} [options.descending=false] - Whether to return changes in descending order.
129
+ * @param {boolean} [options.include_docs=false] - Whether to include the document with each change.
130
+ * @param {number} [options.seq_interval=null] - The interval at which to return sequence numbers.
131
+ * @param {string} [options.since=null] - The sequence number to start from.
132
+ * @yields {Object} The changes from the CouchDB changes feed.
133
+ */
123
134
  async function* changes({ client = defaultClient, signal = null, ...options } = {}) {
124
135
  const params = {}
125
136
 
@@ -208,7 +219,6 @@ export function makeCouch(opts) {
208
219
  }
209
220
  }
210
221
 
211
- const batched = options.batched || false
212
222
  const live = options.live == null || !!options.live
213
223
  const retry = options.retry
214
224
  const limit = options.limit
@@ -220,7 +230,6 @@ export function makeCouch(opts) {
220
230
  while (remaining > 0) {
221
231
  let count = 0
222
232
  for await (const changes of _changes({
223
- batched,
224
233
  live,
225
234
  retry,
226
235
  limit: Math.min(remaining, socketCount),
@@ -253,7 +262,7 @@ export function makeCouch(opts) {
253
262
  }
254
263
  }
255
264
 
256
- async function* _changes({ batched, live, retry, limit, params, method, body, signal, client }) {
265
+ async function* _changes({ live, retry, limit, params, method, body, signal, client }) {
257
266
  let retryCount = 0
258
267
  let remaining = Number(limit) || Infinity
259
268
  while (true) {
@@ -333,7 +342,9 @@ export function makeCouch(opts) {
333
342
  for (const line of lines) {
334
343
  if (line === '') {
335
344
  // hearbeat
336
- yield batched ? [] : {}
345
+ const ret = []
346
+ ret.lastSeq = params.since
347
+ yield ret
337
348
  } else if (line === ',') {
338
349
  // Do nothing. Couch sometimes insert new line between
339
350
  // json body and comma.
@@ -378,11 +389,9 @@ export function makeCouch(opts) {
378
389
  remaining -= changes.length
379
390
  assert(remaining >= 0, 'invalid remaining: ' + remaining)
380
391
 
381
- if (batched) {
382
- yield changes.splice(0)
383
- } else {
384
- yield* changes.splice(0)
385
- }
392
+ const ret = changes.splice(0)
393
+ ret.lastSeq = params.since
394
+ yield ret
386
395
  } else if (error) {
387
396
  throw error
388
397
  } else if (!ended) {
@@ -390,7 +399,10 @@ export function makeCouch(opts) {
390
399
  resume = resolve
391
400
  })
392
401
  } else {
393
- yield batched ? [{ seq: params.since }] : { seq: params.since }
402
+ const ret = []
403
+ ret.lastSeq = params.since
404
+ yield ret
405
+
394
406
  return
395
407
  }
396
408
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "20.0.1",
3
+ "version": "20.0.3",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",