@nxtedition/lib 22.2.0 → 23.0.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.
Files changed (4) hide show
  1. package/app.js +28 -16
  2. package/http.js +0 -17
  3. package/package.json +12 -12
  4. package/serializers.js +2 -2
package/app.js CHANGED
@@ -34,6 +34,7 @@ import { monitorEventLoopDelay } from 'node:perf_hooks'
34
34
  import { LRUCache } from 'lru-cache'
35
35
  import xuid from 'xuid'
36
36
  import undici from 'undici'
37
+ import { isTimeBetween } from './time.js'
37
38
 
38
39
  export function makeApp(appConfig, onTerminate) {
39
40
  let ds
@@ -76,6 +77,24 @@ export function makeApp(appConfig, onTerminate) {
76
77
  logger?.warn({ err }, 'warning')
77
78
  })
78
79
 
80
+ const dailyOffpeakTime = config.dailyOffpeakTime ?? '00:00-04:00'
81
+
82
+ if (dailyOffpeakTime) {
83
+ const [start, end] = dailyOffpeakTime.split('-')
84
+
85
+ let wasOffpeak = null
86
+ setInterval(() => {
87
+ if (isTimeBetween(new Date(), start, end)) {
88
+ if (!wasOffpeak && global.gc) {
89
+ global.gc()
90
+ }
91
+ wasOffpeak = true
92
+ } else {
93
+ wasOffpeak = false
94
+ }
95
+ }, 60e3).unref()
96
+ }
97
+
79
98
  const cleanAppConfig = ({
80
99
  status,
81
100
  stats,
@@ -269,6 +288,7 @@ export function makeApp(appConfig, onTerminate) {
269
288
  const lagMap = new LRUCache({ ttl: 10e3, max: 1024 })
270
289
 
271
290
  const lagBC = new BroadcastChannel('nxt:lag')
291
+ lagBC.unref()
272
292
 
273
293
  lagBC.onmessage = ({ data }) => {
274
294
  lagMap.set(data.id, data.currentLag)
@@ -280,7 +300,7 @@ export function makeApp(appConfig, onTerminate) {
280
300
  }
281
301
  })
282
302
 
283
- const lagInterval = setInterval(() => {
303
+ setInterval(() => {
284
304
  let currentLag = Math.max(0, histogram.mean / 1e6 - resolution)
285
305
  if (Number.isNaN(currentLag)) {
286
306
  currentLag = 0
@@ -302,12 +322,7 @@ export function makeApp(appConfig, onTerminate) {
302
322
  appLag = Math.max(appLag, lag ?? 0)
303
323
  }
304
324
  appLag$.next(appLag)
305
- }, interval)
306
-
307
- destroyers.unshift(() => {
308
- clearInterval(lagInterval)
309
- lagBC.close()
310
- })
325
+ }, interval).unref()
311
326
 
312
327
  toobusy = () => currentLag$.value > maxLag
313
328
  toobusy.lag = () => currentLag$.value
@@ -459,6 +474,7 @@ export function makeApp(appConfig, onTerminate) {
459
474
  }
460
475
 
461
476
  const memoryUsageBC = new BroadcastChannel('nxt:memoryUsage')
477
+ memoryUsageBC.unref()
462
478
 
463
479
  let memoryUsageMap
464
480
  if (isMainThread) {
@@ -468,14 +484,9 @@ export function makeApp(appConfig, onTerminate) {
468
484
  }
469
485
  }
470
486
 
471
- const memoryUsageInterval = setInterval(() => {
487
+ setInterval(() => {
472
488
  memoryUsageBC.postMessage({ data: process.memoryUsage(), id: serviceWorkerId })
473
- }, 1e3)
474
-
475
- destroyers.unshift(() => {
476
- clearInterval(memoryUsageInterval)
477
- memoryUsageBC.close()
478
- })
489
+ }, 1e3).unref()
479
490
 
480
491
  const startTime = Date.now()
481
492
  stats$ = stats$.pipe(
@@ -812,6 +823,8 @@ export function makeApp(appConfig, onTerminate) {
812
823
  // TODO (fix): What about cluster?
813
824
 
814
825
  const inspectBC = new BroadcastChannel('nxt:inspect')
826
+ inspectBC.unref()
827
+
815
828
  let inspectOpen = false
816
829
 
817
830
  if (!isMainThread) {
@@ -954,8 +967,7 @@ export function makeApp(appConfig, onTerminate) {
954
967
  // TODO (fix): What about cluster?
955
968
 
956
969
  const utilsBC = new BroadcastChannel('nxt:utils')
957
-
958
- destroyers.unshift(() => utilsBC.close())
970
+ utilsBC.unref()
959
971
 
960
972
  utilsBC.onmessage = ({ data }) => {
961
973
  const { type } = data
package/http.js CHANGED
@@ -683,20 +683,3 @@ export async function retry(fn, options) {
683
683
  }
684
684
  }
685
685
  }
686
-
687
- export function parseHeaders(rawHeaders, obj = {}) {
688
- for (let i = 0; i < rawHeaders.length; i += 2) {
689
- const key = rawHeaders[i].toString().toLowerCase()
690
- let val = obj[key]
691
- if (!val) {
692
- obj[key] = rawHeaders[i + 1].toString()
693
- } else {
694
- if (!Array.isArray(val)) {
695
- val = [val]
696
- obj[key] = val
697
- }
698
- val.push(rawHeaders[i + 1].toString())
699
- }
700
- }
701
- return obj
702
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "22.2.0",
3
+ "version": "23.0.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -59,10 +59,10 @@
59
59
  "singleQuote": true
60
60
  },
61
61
  "dependencies": {
62
- "@aws-sdk/client-s3": "^3.696.0",
62
+ "@aws-sdk/client-s3": "^3.723.0",
63
63
  "@elastic/elasticsearch": "^8.16.1",
64
64
  "@elastic/transport": "^8.9.1",
65
- "@nxtedition/nxt-undici": "^4.2.26",
65
+ "@nxtedition/nxt-undici": "^5.1.8",
66
66
  "@swc/wasm-web": "^1.10.1",
67
67
  "content-type": "^1.0.5",
68
68
  "date-fns": "^3.6.0",
@@ -73,42 +73,42 @@
73
73
  "koa-compose": "^4.1.0",
74
74
  "lodash": "^4.17.21",
75
75
  "lru-cache": "^11.0.2",
76
- "mime": "^4.0.4",
77
- "mitata": "^1.0.11",
76
+ "mime": "^4.0.6",
77
+ "mitata": "^1.0.26",
78
78
  "moment-timezone": "^0.5.46",
79
79
  "nconf": "^0.12.1",
80
80
  "nested-error-stacks": "^2.1.1",
81
81
  "object-hash": "^3.0.0",
82
82
  "p-queue": "^8.0.1",
83
- "pino": "^9.5.0",
83
+ "pino": "^9.6.0",
84
84
  "qs": "^6.13.1",
85
85
  "request-target": "^1.0.2",
86
86
  "smpte-timecode": "^1.3.6",
87
87
  "split-string": "^6.0.0",
88
- "undici": "^6.21.0",
88
+ "undici": "^7.2.0",
89
89
  "url-join": "^5.0.0",
90
90
  "xuid": "^4.1.3",
91
91
  "yocto-queue": "^1.1.1"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@nxtedition/deepstream.io-client-js": ">=25.6.3",
95
- "@types/lodash": "^4.17.13",
96
- "@types/node": "^22.9.1",
95
+ "@types/lodash": "^4.17.14",
96
+ "@types/node": "^22.10.5",
97
97
  "eslint": "^9.15.0",
98
98
  "eslint-config-prettier": "^9.1.0",
99
99
  "eslint-config-standard": "^17.0.0",
100
100
  "eslint-plugin-import": "^2.31.0",
101
- "eslint-plugin-n": "^17.13.2",
101
+ "eslint-plugin-n": "^17.15.1",
102
102
  "eslint-plugin-node": "^11.1.0",
103
103
  "eslint-plugin-promise": "^7.2.1",
104
104
  "husky": "^9.1.7",
105
- "lint-staged": "^15.2.11",
105
+ "lint-staged": "^15.3.0",
106
106
  "pinst": "^3.0.0",
107
107
  "prettier": "^3.4.2",
108
108
  "rxjs": "^7.5.6",
109
109
  "send": "^0.18.0",
110
110
  "tap": "^21.0.1",
111
- "typescript-eslint": "^8.15.0"
111
+ "typescript-eslint": "^8.19.1"
112
112
  },
113
113
  "peerDependencies": {
114
114
  "@elastic/elasticsearch": "^8.6.0",
package/serializers.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SIGNALS } from './platform.js'
2
- import { util } from 'undici'
2
+ import { parseHeaders } from '@nxtedition/nxt-undici'
3
3
 
4
4
  function getHeader(obj, key) {
5
5
  return obj?.headers?.get?.(key) || obj?.getHeader?.(key) || obj?.headers?.[key]
@@ -11,7 +11,7 @@ function getHeaders(obj) {
11
11
  }
12
12
 
13
13
  if (Array.isArray(obj.headers)) {
14
- return util.parseHeaders(obj.headers)
14
+ return parseHeaders(obj.headers)
15
15
  }
16
16
 
17
17
  return (