@nxtedition/lib 28.0.23 → 28.0.25

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 (3) hide show
  1. package/app.js +10 -20
  2. package/package.json +2 -2
  3. package/slice.js +48 -20
package/app.js CHANGED
@@ -823,13 +823,12 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
823
823
  }
824
824
  }
825
825
  }
826
- return { messages }
826
+ return messages
827
827
  }),
828
828
  ),
829
829
  status$.pipe(
830
- rxjs.filter(Boolean),
831
- rxjs.map((xs) => (Array.isArray(xs) ? { messages: xs } : xs)),
832
- makeStatusPipe('stats'),
830
+ rxjs.map((xs) => [xs, xs?.messages].find(Array.isArray) ?? []),
831
+ makeStatusPipe('status'),
833
832
  ),
834
833
  monitorProviders.stats$?.pipe(
835
834
  rxjs.map(({ memory, heap, utilization, undici, http }) => {
@@ -1021,17 +1020,8 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
1021
1020
  ])
1022
1021
  .pipe(
1023
1022
  rxjs.auditTime(1e3),
1024
- rxjs.map(([status, lag, couch, ds]) => {
1025
- const messages = [
1026
- lag,
1027
- couch,
1028
- ds,
1029
- [
1030
- status?.messages,
1031
- fp.map((x) => (fp.isString(x) ? { msg: x, level: 40 } : x), status?.warnings),
1032
- status,
1033
- ].find((x) => fp.isArray(x) && !fp.isEmpty(x)) ?? [],
1034
- ]
1023
+ rxjs.map((xs) => {
1024
+ const messages = xs
1035
1025
  .flat()
1036
1026
  .filter((x) => fp.isPlainObject(x) && !fp.isEmpty(x))
1037
1027
  .map((message) =>
@@ -1054,18 +1044,18 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
1054
1044
  },
1055
1045
  )
1056
1046
 
1057
- return { ...status, messages, timestamp: Date.now() }
1047
+ return { messages, timestamp: Date.now() }
1058
1048
  }),
1059
1049
  makeStatusPipe('status'),
1060
1050
  )
1061
1051
  .subscribe(monitorProviders.status$),
1062
1052
  )
1063
1053
 
1064
- const statussBC = new BroadcastChannel('nxt:app:stats').unref()
1054
+ const statusBC = new BroadcastChannel('nxt:app:stats').unref()
1065
1055
 
1066
1056
  if (isMainThread) {
1067
1057
  statusMap = new Map()
1068
- statussBC.onmessage = ({ data: { data, id } }) => {
1058
+ statusBC.onmessage = ({ data: { data, id } }) => {
1069
1059
  if (data != null) {
1070
1060
  statusMap.set(id, data)
1071
1061
  } else {
@@ -1077,10 +1067,10 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
1077
1067
  appDestroyers.unshift(
1078
1068
  monitorProviders.status$
1079
1069
  .subscribe((stats) => {
1080
- statussBC.postMessage({ id: threadId, data: stats })
1070
+ statusBC.postMessage({ id: threadId, data: stats })
1081
1071
  })
1082
1072
  .add(() => {
1083
- statussBC.postMessage({ id: threadId, data: undefined })
1073
+ statusBC.postMessage({ id: threadId, data: undefined })
1084
1074
  }),
1085
1075
  )
1086
1076
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "28.0.23",
3
+ "version": "28.0.25",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -92,5 +92,5 @@
92
92
  "canvas": "^3.1.0",
93
93
  "rxjs": "^7.0.0"
94
94
  },
95
- "gitHead": "2fbd54c297b3887f26f8c8f4384e1b0fa8fe1345"
95
+ "gitHead": "48c8835b26082e9c7f427a1dca71c4f9fa3e2091"
96
96
  }
package/slice.js CHANGED
@@ -3,15 +3,22 @@ import util from 'node:util'
3
3
  const EMPTY_BUF = Buffer.alloc(0)
4
4
 
5
5
  export class Slice {
6
- buffer
6
+ /** @type {Buffer} */
7
+ buffer = EMPTY_BUF
8
+
9
+ /** @type {number} */
7
10
  byteOffset = 0
11
+
12
+ /** @type {number} */
8
13
  byteLength = 0
14
+
15
+ /** @type {number} */
9
16
  maxByteLength = 0
10
17
 
18
+ /** @type {Buffer} */
11
19
  static EMPTY_BUF = EMPTY_BUF
12
20
 
13
21
  /**
14
- *
15
22
  * @param {Buffer} [buffer]
16
23
  * @param {number} [byteOffset]
17
24
  * @param {number} [byteLength]
@@ -49,6 +56,9 @@ export class Slice {
49
56
  this.maxByteLength = maxByteLength
50
57
  }
51
58
 
59
+ /**
60
+ * @returns {void}
61
+ */
52
62
  reset() {
53
63
  this.buffer = Slice.EMPTY_BUF
54
64
  this.byteOffset = 0
@@ -56,12 +66,15 @@ export class Slice {
56
66
  this.maxByteLength = 0
57
67
  }
58
68
 
69
+ /**
70
+ * @returns {number}
71
+ */
59
72
  get length() {
60
73
  return this.byteLength
61
74
  }
62
75
 
63
76
  /**
64
- * @param {Buffer|Slice} target
77
+ * @param {Uint8Array} target
65
78
  * @param {number} [targetStart = 0]
66
79
  * @param {number} [sourceStart = 0]
67
80
  * @param {number} [sourceEnd = this.byteOffset]
@@ -94,12 +107,12 @@ export class Slice {
94
107
  }
95
108
 
96
109
  /**
97
- * @param {Buffer|Slice} target
110
+ * @param {Uint8Array} target
98
111
  * @param {number} [targetStart = 0]
99
112
  * @param {number} [targetEnd = target.byteOffset]
100
113
  * @param {number} [sourceStart = 0]
101
114
  * @param {number} [sourceEnd = this.byteOffset]
102
- * @returns
115
+ * @returns {-1 | 0 | 1}
103
116
  */
104
117
  compare(target, targetStart, targetEnd, sourceStart, sourceEnd) {
105
118
  if (target instanceof Slice) {
@@ -134,7 +147,6 @@ export class Slice {
134
147
  }
135
148
 
136
149
  /**
137
- *
138
150
  * @param {string} string
139
151
  * @param {number} [offset=0]
140
152
  * @param {number} [length=this.byteLength - offset]
@@ -155,8 +167,13 @@ export class Slice {
155
167
  return this.buffer.write(string, offset, length, encoding)
156
168
  }
157
169
 
158
- set(array, offset) {
159
- if (array == null) {
170
+ /**
171
+ * @param {Buffer|Slice} source
172
+ * @param {number} offset
173
+ * @returns
174
+ */
175
+ set(source, offset) {
176
+ if (source == null) {
160
177
  return
161
178
  }
162
179
 
@@ -166,31 +183,28 @@ export class Slice {
166
183
  offset += this.byteOffset
167
184
  }
168
185
 
169
- array?.copy(this.buffer, offset)
186
+ source.copy(this.buffer, offset)
170
187
  }
171
188
 
189
+ /**
190
+ * @param {number} index
191
+ * @returns {number}
192
+ */
172
193
  at(index) {
173
194
  return index >= 0
174
195
  ? this.buffer[this.byteOffset + index]
175
196
  : this.buffer[this.byteOffset + this.byteLength + index]
176
197
  }
177
198
 
199
+ /**
200
+ * @param {{ test: (Buffer: buffer, byteOffset: number, byteLength: number) => boolean }} expr
201
+ * @returns
202
+ */
178
203
  test(expr) {
179
204
  return expr.test(this.buffer, this.byteOffset, this.byteLength)
180
205
  }
181
206
 
182
- readBigUInt64BE(offset = 0) {
183
- if (offset === undefined) {
184
- offset = this.byteOffset
185
- } else {
186
- offset += this.byteOffset
187
- }
188
-
189
- return this.buffer.readBigUInt64BE(offset)
190
- }
191
-
192
207
  /**
193
- *
194
208
  * @param {BufferEncoding} [encoding='utf8']
195
209
  * @param {number} [start=0]
196
210
  * @param {number} [end=this.byteLength]
@@ -212,6 +226,11 @@ export class Slice {
212
226
  return this.buffer.toString(encoding, start, end)
213
227
  }
214
228
 
229
+ /**
230
+ * @param {number} [start=0]
231
+ * @param {number} [end=this.byteLength]
232
+ * @returns {Buffer}
233
+ */
215
234
  toBuffer(start, end) {
216
235
  if (start === undefined) {
217
236
  start = this.byteOffset
@@ -228,10 +247,19 @@ export class Slice {
228
247
  return this.buffer.subarray(start, end)
229
248
  }
230
249
 
250
+ /**
251
+ * @returns {string}
252
+ */
231
253
  [Symbol.toStringTag]() {
232
254
  return this.toString()
233
255
  }
234
256
 
257
+ /**
258
+ * @param {*} depth
259
+ * @param {*} options
260
+ * @param {*} inspect
261
+ * @returns {string}
262
+ */
235
263
  [util.inspect.custom](depth, options, inspect) {
236
264
  const bytes = []
237
265
  for (let i = 0; i < this.byteLength; i++) {