@nxtedition/lib 19.4.6 → 19.4.8

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/errors.js CHANGED
@@ -142,15 +142,16 @@ function _serializeError(error, { depth }) {
142
142
 
143
143
  // TODO (fix): Recursion guard?
144
144
  export function makeMessages(error, options) {
145
- if (!error) {
145
+ if (!error || error.length === 0) {
146
146
  return []
147
147
  }
148
148
 
149
149
  if (Array.isArray(error)) {
150
150
  return fp.pipe(
151
151
  fp.flattenDeep,
152
+ fp.filter(Boolean),
152
153
  fp.flatMap((x) => makeMessages(x, options)),
153
- fp.uniqBy(fp.isEqual),
154
+ fp.uniqBy('id'),
154
155
  )(error)
155
156
  } else if (Array.isArray(error.messages)) {
156
157
  return makeMessages(error.messages, options)
@@ -209,13 +210,11 @@ export function makeMessages(error, options) {
209
210
 
210
211
  return [
211
212
  err,
212
- ...makeMessages([
213
- error.cause,
214
- error.error,
215
- error.errors,
216
- error.messages,
217
- error.status?.messages,
218
- ]),
213
+ ...makeMessages(
214
+ [error.cause, error.error, error.errors, error.messages, error.status?.messages].filter(
215
+ Boolean,
216
+ ),
217
+ ),
219
218
  ]
220
219
  } else {
221
220
  return []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.4.6",
3
+ "version": "19.4.8",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -164,7 +164,7 @@ class PromiseEntry {
164
164
  }
165
165
  }
166
166
 
167
- function pipe(value, ...fns) {
167
+ function pipe(value, fns) {
168
168
  for (const fn of fns) {
169
169
  value = fn(value)
170
170
  if (value == null) {
@@ -233,6 +233,7 @@ export default function ({ ds, proxify, compiler }) {
233
233
  this._wrap = null
234
234
  this._suspended = false
235
235
  this._errored = false
236
+ this._refreshImpl = this._refreshImpl.bind(this)
236
237
 
237
238
  if (rxjs.isObservable(args)) {
238
239
  this._subscription = args.subscribe({
@@ -250,7 +251,7 @@ export default function ({ ds, proxify, compiler }) {
250
251
  })
251
252
  } else {
252
253
  this._args = proxify ? this.wrap(args) : args
253
- this._refreshNT(this)
254
+ this._refreshImpl()
254
255
  }
255
256
  }
256
257
 
@@ -325,78 +326,78 @@ export default function ({ ds, proxify, compiler }) {
325
326
  }
326
327
  }
327
328
 
328
- _refreshNT(self) {
329
- self._refreshing = false
329
+ _refreshImpl() {
330
+ this._refreshing = false
330
331
 
331
- if (self._destroyed || self._disposing || self._args === kEmpty) {
332
+ if (this._destroyed || this._disposing || this._args === kEmpty) {
332
333
  return
333
334
  }
334
335
 
335
- self._counter = (self._counter + 1) & maxInt
336
+ this._counter = (this._counter + 1) & maxInt
336
337
 
337
338
  // TODO (fix): freeze?
338
- self._context.$ = self._args
339
- self._context.nxt = self
339
+ this._context.$ = this._args
340
+ this._context.nxt = this
340
341
 
341
342
  const previous = compiler.current
342
- compiler.current = self
343
+ compiler.current = this
343
344
 
344
345
  try {
345
- assert(self._suspended === false)
346
- const value = self._script.runInContext(self._context)
347
- self._errored = false
348
- if (self._suspended) {
346
+ assert(this._suspended === false)
347
+ const value = this._script.runInContext(this._context)
348
+ this._errored = false
349
+ if (this._suspended) {
349
350
  return
350
351
  }
351
352
 
352
- if (value !== self._value) {
353
- self._value = value
354
- self._observer.next(value)
353
+ if (value !== this._value) {
354
+ this._value = value
355
+ this._observer.next(value)
355
356
  }
356
357
  } catch (err) {
357
358
  if (err === kSuspend) {
358
359
  return
359
360
  }
360
361
 
361
- self._errored = true
362
+ this._errored = true
362
363
 
363
364
  const error = Object.assign(new Error('expression failed'), {
364
365
  cause: err,
365
- data: self._expression,
366
+ data: this._expression,
366
367
  })
367
368
 
368
- if (self._suspended) {
369
+ if (this._suspended) {
369
370
  process.emitWarning(error)
370
371
  } else {
371
- self._observer.error(error)
372
+ this._observer.error(error)
372
373
  }
373
374
  } finally {
374
375
  compiler.current = previous
375
376
 
376
- self._context.$ = null
377
- self._context.nxt = null
377
+ this._context.$ = null
378
+ this._context.nxt = null
378
379
 
379
- self._suspended = false
380
- self._disposing = true
380
+ this._suspended = false
381
+ this._disposing = true
381
382
 
382
- if (self._entries) {
383
- for (const entry of self._entries.values()) {
384
- if (entry.counter !== self._counter) {
383
+ if (this._entries) {
384
+ for (const entry of this._entries.values()) {
385
+ if (entry.counter !== this._counter) {
385
386
  entry.dispose()
386
- self._entries.delete(entry.key)
387
+ this._entries.delete(entry.key)
387
388
  }
388
389
  }
389
- if (self._entries.size === 0) {
390
- self._entries = null
390
+ if (this._entries.size === 0) {
391
+ this._entries = null
391
392
  }
392
393
  }
393
394
 
394
395
  // TODO (perf): Make this work.
395
- // if (!self._entries) {
396
- // self._args = null
396
+ // if (!this._entries) {
397
+ // this._args = null
397
398
  // }
398
399
 
399
- self._disposing = false
400
+ this._disposing = false
400
401
  }
401
402
  }
402
403
 
@@ -406,7 +407,7 @@ export default function ({ ds, proxify, compiler }) {
406
407
  }
407
408
 
408
409
  this._refreshing = true
409
- process.nextTick(this._refreshNT, this)
410
+ queueMicrotask(this._refreshImpl)
410
411
  }
411
412
 
412
413
  _getEntry(key, Entry, opaque) {
@@ -569,7 +570,7 @@ export default function ({ ds, proxify, compiler }) {
569
570
  script = new vm.Script(`
570
571
  "use strict";
571
572
  {
572
- const _ = (...args) => pipe(...args);
573
+ const _ = (...args) => pipe(args);
573
574
  _.asset = (type, state, throws) => (id) => nxt._asset(id, type, state, throws);
574
575
  _.ds = (postfix, state, throws) => (id) => nxt._ds(id, postfix, state, throws);
575
576
  _.timer = (dueTime) => (dueValue) => nxt.timer(dueTime, dueValue);