@nxtedition/lib 28.0.29 → 28.0.31

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
@@ -63,11 +63,12 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
63
63
 
64
64
  if (typeof onTerminateOrMeta === 'function') {
65
65
  meta = metaOrNull
66
+ onTerminate = onTerminateOrMeta
66
67
  } else {
67
68
  meta = onTerminateOrMeta ?? metaOrNull
68
69
  }
69
70
 
70
- if (onTerminate != null && typeof onTerminateOrMeta !== 'function') {
71
+ if (onTerminate != null && typeof onTerminate !== 'function') {
71
72
  throw new Error('onTerminate must be a function or null')
72
73
  }
73
74
 
@@ -187,7 +188,7 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
187
188
  }
188
189
 
189
190
  globalThis.__nxt_undici_global_headers = {
190
- ...(globalThis.__nxt_undici_global_headers ?? {}),
191
+ ...globalThis.__nxt_undici_global_headers,
191
192
  'nxt-module': serviceModule,
192
193
  'nxt-instance-id': serviceInstanceId,
193
194
  'nxt-worker-id': String(serviceWorkerId),
package/errors.d.ts CHANGED
@@ -42,6 +42,7 @@ export interface MessageOptions {
42
42
  }
43
43
 
44
44
  export function makeMessages(
45
+ // oxlint-disable-next-line typescript/no-redundant-type-constituents
45
46
  error: MessageError | MessageError[],
46
47
  options?: MessageOptions,
47
48
  ): Message[]
package/fixed-queue.js CHANGED
@@ -75,7 +75,9 @@ class FixedCircularBuffer {
75
75
 
76
76
  shift() {
77
77
  const nextItem = this.list[this.bottom]
78
- if (nextItem === undefined) return null
78
+ if (nextItem === undefined) {
79
+ return null
80
+ }
79
81
  this.list[this.bottom] = undefined
80
82
  this.bottom = (this.bottom + 1) & kMask
81
83
  return nextItem
package/http.js CHANGED
@@ -48,7 +48,8 @@ export class Context {
48
48
  #ac
49
49
  #logger
50
50
  #query
51
- #target;
51
+ #target
52
+ #priority;
52
53
 
53
54
  [kPendingIndex] = -1
54
55
 
@@ -60,6 +61,23 @@ export class Context {
60
61
  this.#req = req
61
62
  this.#res = res
62
63
  this.#logger = logger.child({ rid: this.#id })
64
+
65
+ const p = req.headers['nxt-priority']
66
+ if (!p) {
67
+ this.#priority = 1
68
+ } else if (p === '0' || p === 'low') {
69
+ this.#priority = 0
70
+ } else if (p === '1' || p === 'normal') {
71
+ this.#priority = 1
72
+ } else if (p === '2' || p === 'high') {
73
+ this.#priority = 2
74
+ } else {
75
+ throw new Error('Invalid nxt-priority header')
76
+ }
77
+ }
78
+
79
+ get priority() {
80
+ return this.#priority
63
81
  }
64
82
 
65
83
  get id() {
@@ -1225,7 +1243,9 @@ export const compose = (...middleware) => {
1225
1243
  const funcs = middleware.flat()
1226
1244
 
1227
1245
  for (const fn of funcs) {
1228
- if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')
1246
+ if (typeof fn !== 'function') {
1247
+ throw new TypeError('Middleware must be composed of functions!')
1248
+ }
1229
1249
  }
1230
1250
 
1231
1251
  if (process.env.NODE_ENV === 'production') {
@@ -1235,12 +1255,16 @@ export const compose = (...middleware) => {
1235
1255
  return async (ctx, next) => {
1236
1256
  const dispatch = async (i) => {
1237
1257
  const fn = i === funcs.length ? next : funcs[i]
1238
- if (!fn) return
1258
+ if (!fn) {
1259
+ return
1260
+ }
1239
1261
 
1240
1262
  let nextCalled = false
1241
1263
  let nextResolved = false
1242
1264
  const nextProxy = async () => {
1243
- if (nextCalled) throw Error('next() called multiple times')
1265
+ if (nextCalled) {
1266
+ throw Error('next() called multiple times')
1267
+ }
1244
1268
  nextCalled = true
1245
1269
  try {
1246
1270
  return await dispatch(i + 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "28.0.29",
3
+ "version": "28.0.31",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -45,16 +45,17 @@
45
45
  ],
46
46
  "scripts": {
47
47
  "test": "node --test-timeout 60000 --test",
48
- "test:types": "tsd"
48
+ "test:types": "tsd",
49
+ "test:ci": "node --test && tsd"
49
50
  },
50
51
  "dependencies": {
51
52
  "@elastic/elasticsearch": "^8.17.1",
52
53
  "@elastic/transport": "^8.9.3",
53
54
  "@nxtedition/nxt-undici": "^7.1.9",
54
55
  "@nxtedition/sched": "^1.0.2",
55
- "@nxtedition/template": "^1.0.11",
56
- "@nxtedition/weak-cache": "^1.0.2",
57
- "@nxtedition/yield": "^1.0.2",
56
+ "@nxtedition/template": "^1.0.12",
57
+ "@nxtedition/weak-cache": "^1.0.3",
58
+ "@nxtedition/yield": "^1.0.3",
58
59
  "diff": "5.2.0",
59
60
  "fast-querystring": "^1.1.2",
60
61
  "flamegraph-middleware": "^1.0.0",
@@ -92,5 +93,5 @@
92
93
  "canvas": "^3.1.0",
93
94
  "rxjs": "^7.0.0"
94
95
  },
95
- "gitHead": "9a796e26b5fd7bf119919c756967597722decd67"
96
+ "gitHead": "b764a06e9dc3fcdce6d4e136086dc378e0acc772"
96
97
  }
package/time.js CHANGED
@@ -15,8 +15,14 @@ export function isTimeBetween(date, startTime, endTime) {
15
15
  const currentMinutes = date.getMinutes()
16
16
 
17
17
  // Validate and parse start and end times
18
- if (!startTime) startTime = '00:00' // Default start at midnight
19
- if (!endTime) endTime = '23:59' // Default end at 23:59
18
+ if (!startTime) {
19
+ // Default start at midnight
20
+ startTime = '00:00'
21
+ }
22
+ if (!endTime) {
23
+ // Default end at 23:59
24
+ endTime = '23:59'
25
+ }
20
26
 
21
27
  const [startHours, startMinutes] = startTime.split(':').map(Number)
22
28
  const [endHours, endMinutes] = endTime.split(':').map(Number)