@nxtedition/lib 19.9.4 → 19.10.1

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/app.js CHANGED
@@ -142,8 +142,8 @@ export function makeApp(appConfig, onTerminate) {
142
142
  },
143
143
  })
144
144
 
145
- appDestroyers.push(
146
- () =>
145
+ appDestroyers.unshift(
146
+ (logger) =>
147
147
  new Promise((resolve, reject) => {
148
148
  try {
149
149
  logger.flush((err) => (err ? reject(err) : resolve(null)))
@@ -174,8 +174,26 @@ export function makeApp(appConfig, onTerminate) {
174
174
  }
175
175
  }
176
176
 
177
+ const destroy = (value) => {
178
+ if (value == null) {
179
+ return null
180
+ } else if (typeof value === 'function') {
181
+ return value(logger)
182
+ } else if (typeof value[Symbol.dispose] === 'function') {
183
+ return value[Symbol.dispose]()
184
+ } else if (typeof value[Symbol.asyncDispose] === 'function') {
185
+ return value[Symbol.asyncDispose]()
186
+ } else if (typeof value.unsubscribe === 'function') {
187
+ value.unsubscribe()
188
+ return null
189
+ } else {
190
+ logger.error('invalid destroyer')
191
+ return null
192
+ }
193
+ }
194
+
177
195
  for (const { reason: err } of await Promise.allSettled(
178
- destroyers.filter(Boolean).map((fn) => fn(logger)),
196
+ destroyers.filter(Boolean).map((fn) => destroy(fn)),
179
197
  )) {
180
198
  if (err) {
181
199
  logger.error({ err }, 'shutdown error')
@@ -183,7 +201,7 @@ export function makeApp(appConfig, onTerminate) {
183
201
  }
184
202
 
185
203
  for (const { reason: err } of await Promise.allSettled(
186
- appDestroyers.filter(Boolean).map((fn) => fn(logger)),
204
+ appDestroyers.filter(Boolean).map((fn) => destroy(fn)),
187
205
  )) {
188
206
  if (err) {
189
207
  logger.error({ err }, 'shutdown error')
@@ -297,7 +315,7 @@ export function makeApp(appConfig, onTerminate) {
297
315
 
298
316
  if (couchConfig.url) {
299
317
  couch = makeCouch(couchConfig)
300
- appDestroyers.push(() => couch.close())
318
+ appDestroyers.unshift(() => couch.close())
301
319
  } else {
302
320
  throw new Error('invalid couch config')
303
321
  }
@@ -388,7 +406,7 @@ export function makeApp(appConfig, onTerminate) {
388
406
 
389
407
  globalThis.ds = ds
390
408
 
391
- appDestroyers.push(() => ds.close())
409
+ appDestroyers.unshift(() => ds.close())
392
410
  }
393
411
 
394
412
  if (appConfig.compiler) {
@@ -454,9 +472,7 @@ export function makeApp(appConfig, onTerminate) {
454
472
  }
455
473
  })
456
474
 
457
- appDestroyers.push(() => {
458
- subscription.unsubscribe()
459
- })
475
+ appDestroyers.unshift(subscription)
460
476
  }
461
477
 
462
478
  let status$
@@ -687,9 +703,7 @@ export function makeApp(appConfig, onTerminate) {
687
703
 
688
704
  monitorProviders.status$ = status$
689
705
 
690
- appDestroyers.push(() => {
691
- loggerSubscription.unsubscribe()
692
- })
706
+ appDestroyers.unshift(loggerSubscription)
693
707
  }
694
708
 
695
709
  if (ds && Object.keys(monitorProviders).length && appConfig.monitor !== false) {
@@ -706,12 +720,7 @@ export function makeApp(appConfig, onTerminate) {
706
720
  return monitorProviders[prop + '$']
707
721
  }
708
722
  })
709
-
710
- appDestroyers.unshift(() => {
711
- if (unprovide) {
712
- unprovide()
713
- }
714
- })
723
+ appDestroyers.unshift(unprovide)
715
724
  }
716
725
  }
717
726
 
@@ -738,7 +747,7 @@ export function makeApp(appConfig, onTerminate) {
738
747
  }
739
748
 
740
749
  inspectBC.postMessage({ type: 'inspect:register', id: serviceWorkerId })
741
- destroyers.push(() => {
750
+ destroyers.unshift(() => {
742
751
  inspector.close()
743
752
  inspectBC.postMessage({ type: 'inspect:unregister', id: serviceWorkerId })
744
753
  })
@@ -754,7 +763,7 @@ export function makeApp(appConfig, onTerminate) {
754
763
  }
755
764
  }
756
765
 
757
- destroyers.push(() => inspectBC.close())
766
+ destroyers.unshift(() => inspectBC.close())
758
767
 
759
768
  if (appConfig.http) {
760
769
  const httpConfig = { ...appConfig.http, ...config.http }
@@ -830,7 +839,7 @@ export function makeApp(appConfig, onTerminate) {
830
839
 
831
840
  server.listen(port)
832
841
 
833
- appDestroyers.push(() => new Promise((resolve) => server.close(resolve)))
842
+ appDestroyers.unshift(() => new Promise((resolve) => server.close(resolve)))
834
843
  }
835
844
  }
836
845
 
package/couch.js CHANGED
@@ -120,12 +120,7 @@ export function makeCouch(opts) {
120
120
  })
121
121
  }
122
122
 
123
- async function* changes({
124
- client = defaultClient,
125
- signal = null,
126
- highWaterMark = 128 * 1024,
127
- ...options
128
- } = {}) {
123
+ async function* changes({ client = defaultClient, signal = null, ...options } = {}) {
129
124
  const params = {}
130
125
 
131
126
  let body
package/http.js CHANGED
@@ -68,7 +68,7 @@ export async function request(ctx, next) {
68
68
  this.destroy((reqTimeoutError ??= new createError.RequestTimeout()))
69
69
  })
70
70
  .on('error', function (err) {
71
- this.log.error({ err }, 'request error')
71
+ reqLogger.error({ err }, 'request error')
72
72
  })
73
73
  res
74
74
  .on('timeout', function () {
@@ -80,7 +80,7 @@ export async function request(ctx, next) {
80
80
  // TODO (fix): Use 'end' once we can trust that
81
81
  // 'end' or 'error' will always be emitted.
82
82
  .on('close', function () {
83
- this.log.debug('request closed')
83
+ reqLogger.debug('request closed')
84
84
  resolve(null)
85
85
  ac.abort()
86
86
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.9.4",
3
+ "version": "19.10.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -2,7 +2,7 @@ const ordI = 'I'.charCodeAt(0)
2
2
  const ordZero = '0'.charCodeAt(0)
3
3
  const ordDash = '-'.charCodeAt(0)
4
4
 
5
- const compareRevStringString = (a, b) => {
5
+ export function compareRevStringString(a, b) {
6
6
  // Handle INF-XXXXXXXX
7
7
  {
8
8
  const isInfA = a[0] === 'I'
@@ -64,7 +64,7 @@ const compareRevStringString = (a, b) => {
64
64
  return lenA - lenB
65
65
  }
66
66
 
67
- const compareRevBufferBuffer = (a, b) => {
67
+ export function compareRevBufferBuffer(a, b) {
68
68
  if (a === b) {
69
69
  return 0
70
70
  }
@@ -133,7 +133,7 @@ const compareRevBufferBuffer = (a, b) => {
133
133
  return lenA - lenB
134
134
  }
135
135
 
136
- const compareRevBufferString = (a, b) => {
136
+ export function compareRevBufferString(a, b) {
137
137
  // Handle INF-XXXXXXXX
138
138
  {
139
139
  const isInfA = a[0] === ordI
@@ -197,6 +197,84 @@ const compareRevBufferString = (a, b) => {
197
197
  return lenA - lenB
198
198
  }
199
199
 
200
+ export function compareRevSliceSlice(a, b) {
201
+ // Handle null and undefined
202
+ if (!a || !a.byteLength) {
203
+ return !b || !b.byteLength ? 0 : -1
204
+ } else if (!b || !b.byteLength) {
205
+ return 1
206
+ }
207
+
208
+ if (a === b) {
209
+ return 0
210
+ }
211
+
212
+ let indexA = a.byteOffset
213
+ const endA = a.byteOffset + a.byteLength
214
+ let lenA = endA
215
+ a = a.buffer
216
+
217
+ let indexB = b.byteOffset
218
+ const endB = b.byteOffset + b.byteLength
219
+ let lenB = endB
220
+ b = b.buffer
221
+
222
+ // Handle INF-XXXXXXXX
223
+ {
224
+ const isInfA = a[indexA] === ordI
225
+ const isInfB = b[indexB] === ordI
226
+ if (isInfA !== isInfB) {
227
+ return isInfB ? -1 : 1
228
+ }
229
+ }
230
+
231
+ // Skip leading zeroes
232
+ while (a[indexA] === ordZero) {
233
+ ++indexA
234
+ --lenA
235
+ }
236
+ while (b[indexB] === ordZero) {
237
+ ++indexB
238
+ --lenB
239
+ }
240
+
241
+ // Compare the revision number
242
+ let result = 0
243
+ while (indexA < endA && indexB < endB) {
244
+ const ac = a[indexA++]
245
+ const bc = b[indexB++]
246
+
247
+ const isDashA = ac === ordDash
248
+ const isDashB = bc === ordDash
249
+ if (isDashA) {
250
+ if (isDashB) {
251
+ break
252
+ }
253
+ return -1
254
+ } else if (isDashB) {
255
+ return 1
256
+ }
257
+
258
+ result ||= ac - bc
259
+ }
260
+
261
+ if (result) {
262
+ return result
263
+ }
264
+
265
+ // Compare the rest
266
+ while (indexA < endA && indexB < endB) {
267
+ const ac = a[indexA++]
268
+ const bc = b[indexB++]
269
+ result = ac - bc
270
+ if (result) {
271
+ return result
272
+ }
273
+ }
274
+
275
+ return lenA - lenB
276
+ }
277
+
200
278
  export default function compareRev(a, b) {
201
279
  // Handle null and undefined
202
280
  if (!a || !a.length) {