@nxtedition/lib 20.3.5 → 20.3.7

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 +18 -58
  2. package/package.json +12 -12
package/couch.js CHANGED
@@ -14,19 +14,6 @@ import {
14
14
  request as undiciRequest,
15
15
  } from '@nxtedition/nxt-undici'
16
16
 
17
- // https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js
18
- // 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8).
19
- // With this upper bound, if you'll be generating 1k ids/sec, you're going to hit it in ~25 days.
20
- // This is very likely to happen in real-world applications, hence the limit is enforced.
21
- // Growing beyond this value will make the id generation slower and cause a deopt.
22
- // In the worst cases, it will become a float, losing accuracy.
23
- const maxInt = 2147483647
24
- let nextReqId = Math.floor(Math.random() * maxInt)
25
- function genReqId() {
26
- nextReqId = (nextReqId + 1) & maxInt
27
- return `req-${nextReqId.toString(36)}`
28
- }
29
-
30
17
  export function makeCouch(opts) {
31
18
  let config
32
19
  if (typeof opts === 'string') {
@@ -228,36 +215,16 @@ export function makeCouch(opts) {
228
215
  return next()
229
216
  })
230
217
 
231
- const limit = options.limit
232
-
233
218
  try {
234
- // Limit request duration to allow server to load balance.
235
- const socketCount = 64 * 1024
236
- let remaining = Number(limit) || Infinity
237
- while (remaining > 0) {
238
- let count = 0
239
- const limit = Math.min(remaining, socketCount)
240
- for await (const changes of _changes({
241
- live,
242
- retry,
243
- limit,
244
- params,
245
- method,
246
- body,
247
- signal: ac.signal,
248
- client,
249
- })) {
250
- yield changes
251
- if (changes != null) {
252
- count += changes.length
253
- remaining -= changes.length
254
- }
255
- }
256
- assert(remaining >= 0)
257
- if (!live && count < socketCount) {
258
- return
259
- }
260
- }
219
+ yield* _changes({
220
+ method,
221
+ live,
222
+ retry,
223
+ params,
224
+ body,
225
+ signal: ac.signal,
226
+ client,
227
+ })
261
228
  } finally {
262
229
  ac.abort()
263
230
  if (signal) {
@@ -273,39 +240,35 @@ export function makeCouch(opts) {
273
240
  async function* _changes({
274
241
  live,
275
242
  retry,
276
- limit,
277
243
  params,
278
244
  method,
279
245
  body,
280
246
  signal,
281
247
  client,
282
- blocking = live || !limit || limit > 256,
248
+ blocking = live || !params.limit || params.limit > 256,
283
249
  }) {
284
250
  let retryCount = 0
285
- let remaining = Number(limit) || Infinity
286
251
  while (true) {
287
252
  let src
288
253
  try {
289
254
  const query = { ...params, feed: live ? 'continuous' : 'normal' }
290
255
 
291
- if (Number.isFinite(remaining)) {
292
- query.limit = remaining
293
- }
294
-
295
256
  const ureq = {
296
257
  path: `${dbPathname}/_changes`,
297
258
  origin: dbOrigin,
298
259
  query,
299
- idempotent: false,
260
+ headers: body
261
+ ? {
262
+ 'content-type': 'application/json',
263
+ }
264
+ : null,
300
265
  blocking,
301
266
  method,
302
267
  body: JSON.stringify(body),
268
+ retry: false,
269
+ idempotent: false,
303
270
  signal,
304
- headers: {
305
- 'user-agent': userAgent,
306
- 'request-id': genReqId(),
307
- ...(body ? { 'content-type': 'application/json' } : {}),
308
- },
271
+ headersTimeout: 2 * 60e3,
309
272
  bodyTimeout: 2 * (params.heartbeat || 60e3),
310
273
  highWaterMark: 256 * 1024,
311
274
  dispatcher: client,
@@ -404,9 +367,6 @@ export function makeCouch(opts) {
404
367
  }
405
368
  }
406
369
  } else if (changes.length) {
407
- remaining -= changes.length
408
- assert(remaining >= 0, 'invalid remaining: ' + remaining)
409
-
410
370
  const ret = changes.splice(0)
411
371
  ret.lastSeq = params.since
412
372
  yield ret
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "20.3.5",
3
+ "version": "20.3.7",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -54,10 +54,10 @@
54
54
  "singleQuote": true
55
55
  },
56
56
  "dependencies": {
57
- "@aws-sdk/client-s3": "^3.627.0",
58
- "@elastic/elasticsearch": "^8.14.0",
59
- "@elastic/transport": "^8.7.0",
60
- "@nxtedition/nxt-undici": "^4.2.5",
57
+ "@aws-sdk/client-s3": "^3.637.0",
58
+ "@elastic/elasticsearch": "^8.15.0",
59
+ "@elastic/transport": "^8.7.1",
60
+ "@nxtedition/nxt-undici": "^4.2.13",
61
61
  "content-type": "^1.0.5",
62
62
  "date-fns": "^3.6.0",
63
63
  "fast-querystring": "^1.1.1",
@@ -78,7 +78,7 @@
78
78
  "request-target": "^1.0.2",
79
79
  "smpte-timecode": "^1.3.6",
80
80
  "split-string": "^6.0.0",
81
- "undici": "^6.19.7",
81
+ "undici": "^6.19.8",
82
82
  "url-join": "^5.0.0",
83
83
  "xuid": "^4.1.3",
84
84
  "yocto-queue": "^1.1.1"
@@ -86,22 +86,22 @@
86
86
  "devDependencies": {
87
87
  "@nxtedition/deepstream.io-client-js": ">=25.6.3",
88
88
  "@types/lodash": "^4.17.7",
89
- "@types/node": "^22.2.0",
90
- "eslint": "^9.9.0",
89
+ "@types/node": "^22.5.2",
90
+ "eslint": "^9.9.1",
91
91
  "eslint-config-prettier": "^9.1.0",
92
92
  "eslint-config-standard": "^17.0.0",
93
93
  "eslint-plugin-import": "^2.29.1",
94
94
  "eslint-plugin-n": "^17.10.2",
95
95
  "eslint-plugin-node": "^11.1.0",
96
96
  "eslint-plugin-promise": "^7.1.0",
97
- "husky": "^9.1.4",
98
- "lint-staged": "^15.2.8",
97
+ "husky": "^9.1.5",
98
+ "lint-staged": "^15.2.10",
99
99
  "pinst": "^3.0.0",
100
100
  "prettier": "^3.3.3",
101
101
  "rxjs": "^7.5.6",
102
102
  "send": "^0.18.0",
103
- "tap": "^21.0.0",
104
- "typescript-eslint": "^8.0.1"
103
+ "tap": "^21.0.1",
104
+ "typescript-eslint": "^8.3.0"
105
105
  },
106
106
  "peerDependencies": {
107
107
  "@elastic/elasticsearch": "^8.6.0",