@nxtedition/lib 21.0.2 → 21.0.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.
package/app.js CHANGED
@@ -441,6 +441,16 @@ export function makeApp(appConfig, onTerminate) {
441
441
  stats$ = rxjs.timer(0, 10e3).pipe(rx.map(() => ({})))
442
442
  }
443
443
 
444
+ const memoryUsageBC = new BroadcastChannel('nxt:memoryUsage')
445
+
446
+ let memoryUsageMap
447
+ if (isMainThread) {
448
+ memoryUsageMap = new Map()
449
+ memoryUsageBC.onmessage = ({ data, id }) => {
450
+ memoryUsageMap.set(id, data)
451
+ }
452
+ }
453
+
444
454
  const startTime = Date.now()
445
455
  stats$ = stats$.pipe(
446
456
  rx.map((x) => ({
@@ -453,15 +463,40 @@ export function makeApp(appConfig, onTerminate) {
453
463
  rxjs.timer(0, 1e3).pipe(
454
464
  rx.map(() => performance.eventLoopUtilization?.()),
455
465
  rx.pairwise(),
456
- rx.map(([elu1, elu2]) => ({
457
- ds: ds?.stats,
458
- couch: couch?.stats,
459
- lag: toobusy?.lag(),
460
- version: process.version,
461
- memory: process.memoryUsage(),
462
- utilization: performance.eventLoopUtilization?.(elu2, elu1),
463
- heap: v8.getHeapStatistics(),
464
- })),
466
+ rx.map(([elu1, elu2]) => {
467
+ const memory = process.memoryUsage()
468
+
469
+ memoryUsageBC.postMessage({ data: memory, id: threadId })
470
+
471
+ let totalMemory
472
+ if (memoryUsageMap) {
473
+ totalMemory = {
474
+ rss: 0,
475
+ heapTotal: 0,
476
+ heapUsed: 0,
477
+ external: 0,
478
+ arrayBuffers: 0,
479
+ }
480
+ for (const memoryUsage of memoryUsageMap.values()) {
481
+ totalMemory.rss += memoryUsage.rss
482
+ totalMemory.heapTotal += memoryUsage.heapTotal
483
+ totalMemory.heapUsed += memoryUsage.heapUsed
484
+ totalMemory.external += memoryUsage.external
485
+ totalMemory.arrayBuffers += memoryUsage.arrayBuffers
486
+ }
487
+ }
488
+
489
+ return {
490
+ ds: ds?.stats,
491
+ couch: couch?.stats,
492
+ lag: toobusy?.lag(),
493
+ version: process.version,
494
+ memory,
495
+ totalMemory,
496
+ utilization: performance.eventLoopUtilization?.(elu2, elu1),
497
+ heap: v8.getHeapStatistics(),
498
+ }
499
+ }),
465
500
  ),
466
501
  ),
467
502
  rx.map(([serviceStats, appStats]) => ({
package/couch.js CHANGED
@@ -988,7 +988,6 @@ class PromiseOutput {
988
988
  #reject
989
989
  #str
990
990
  #decoder
991
- #headers
992
991
  #signal
993
992
  #abort
994
993
 
@@ -1010,12 +1009,10 @@ class PromiseOutput {
1010
1009
  }
1011
1010
  }
1012
1011
 
1013
- onHeaders(statusCode, rawHeaders, resume, statusText, headers = parseHeaders(rawHeaders)) {
1012
+ onHeaders(statusCode, rawHeaders, resume, statusText) {
1014
1013
  if (statusCode >= 300 || statusCode < 200) {
1015
1014
  throw new Error('invalid status code: ' + statusCode)
1016
1015
  }
1017
-
1018
- this.#headers = headers
1019
1016
  }
1020
1017
 
1021
1018
  onData(data) {
@@ -1024,9 +1021,11 @@ class PromiseOutput {
1024
1021
 
1025
1022
  onComplete() {
1026
1023
  this.#str += this.#decoder.decode(undefined, { stream: false })
1027
-
1028
- const val = Object.assign(JSON.parse(this.#str), { headers: this.#headers })
1029
- this.#onDone(null, val)
1024
+ try {
1025
+ this.#onDone(null, JSON.parse(this.#str))
1026
+ } catch (err) {
1027
+ this.#onDone(Object.assign(new Error('invalid json'), { data: this.#str, cause: err }))
1028
+ }
1030
1029
  }
1031
1030
 
1032
1031
  onError(err) {
package/deepstream.js CHANGED
@@ -49,6 +49,7 @@ function provide(ds, domain, callback, options) {
49
49
  return ds.record.provide(
50
50
  `${idExpr}(?:${domain})(?:[?].*)${options.strict ? '' : '?'}$`,
51
51
  (key) => {
52
+ // TODO (fix): More strict pattern matching...
52
53
  const [id, options] = parseKey(key)
53
54
  return callback(id, options, key)
54
55
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "21.0.2",
3
+ "version": "21.0.4",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",