@nxtedition/lib 19.9.4 → 19.10.0

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.0",
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,77 @@ const compareRevBufferString = (a, b) => {
197
197
  return lenA - lenB
198
198
  }
199
199
 
200
+ export function compareRevSliceSlice(a, b) {
201
+ if (a === b) {
202
+ return 0
203
+ }
204
+
205
+ let indexA = a.byteOffset
206
+ const endA = a.byteOffset + a.byteLength
207
+ let lenA = endA
208
+ a = a.buffer
209
+
210
+ let indexB = b.byteOffset
211
+ const endB = b.byteOffset + b.byteLength
212
+ let lenB = endB
213
+ b = b.buffer
214
+
215
+ // Handle INF-XXXXXXXX
216
+ {
217
+ const isInfA = a[indexA] === ordI
218
+ const isInfB = b[indexB] === ordI
219
+ if (isInfA !== isInfB) {
220
+ return isInfB ? -1 : 1
221
+ }
222
+ }
223
+
224
+ // Skip leading zeroes
225
+ while (a[indexA] === ordZero) {
226
+ ++indexA
227
+ --lenA
228
+ }
229
+ while (b[indexB] === ordZero) {
230
+ ++indexB
231
+ --lenB
232
+ }
233
+
234
+ // Compare the revision number
235
+ let result = 0
236
+ while (indexA < endA && indexB < endB) {
237
+ const ac = a[indexA++]
238
+ const bc = b[indexB++]
239
+
240
+ const isDashA = ac === ordDash
241
+ const isDashB = bc === ordDash
242
+ if (isDashA) {
243
+ if (isDashB) {
244
+ break
245
+ }
246
+ return -1
247
+ } else if (isDashB) {
248
+ return 1
249
+ }
250
+
251
+ result ||= ac - bc
252
+ }
253
+
254
+ if (result) {
255
+ return result
256
+ }
257
+
258
+ // Compare the rest
259
+ while (indexA < endA && indexB < endB) {
260
+ const ac = a[indexA++]
261
+ const bc = b[indexB++]
262
+ result = ac - bc
263
+ if (result) {
264
+ return result
265
+ }
266
+ }
267
+
268
+ return lenA - lenB
269
+ }
270
+
200
271
  export default function compareRev(a, b) {
201
272
  // Handle null and undefined
202
273
  if (!a || !a.length) {