@nxtedition/lib 23.15.2 → 23.15.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
@@ -391,6 +391,7 @@ export function makeApp(appConfig, onTerminate) {
391
391
  {
392
392
  userAgent,
393
393
  url: isProduction ? 'ws://deepstream:6020/deepstream' : 'ws://127.0.0.1:6020/deepstream',
394
+ schedule: (fn) => setImmediate(fn),
394
395
  },
395
396
  appConfig.deepstream,
396
397
  config.deepstream,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.15.2",
3
+ "version": "23.15.4",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -27,6 +27,7 @@ export function makeTemplateCompiler({ ds, proxify, logger = console }) {
27
27
  },
28
28
  }
29
29
  },
30
+ schedule: (fn) => setTimeout(fn, 0),
30
31
  },
31
32
  })
32
33
  }
@@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'
3
3
  import { initSync } from '@swc/wasm-web'
4
4
  import { makeTemplateCompiler as commonMakeTemplateCompiler } from './index-common.js'
5
5
  import { hashSync } from 'hasha'
6
- import { request, Agent } from '@nxtedition/nxt-undici'
6
+ import { request } from '@nxtedition/nxt-undici'
7
7
 
8
8
  export * from './index-common.js'
9
9
 
@@ -13,13 +13,9 @@ const wasmBuffer = readFileSync(wasmPath)
13
13
 
14
14
  initSync({ module: wasmBuffer })
15
15
 
16
- const defaultFetchClient = new Agent({
17
- connections: 128,
18
- })
19
-
20
16
  export function makeTemplateCompiler({
21
17
  logger = globalThis.__nxt_lib_app?.logger,
22
- dispatcher = defaultFetchClient,
18
+ dispatcher,
23
19
  platform,
24
20
  ...args
25
21
  }) {
@@ -30,8 +26,9 @@ export function makeTemplateCompiler({
30
26
  platform: {
31
27
  hasha: hashSync,
32
28
  fetch: (resource, options) =>
33
- request(resource, options ? { dispatcher, ...options } : defaultOptions),
29
+ request(resource, options && dispatcher ? { dispatcher, ...options } : defaultOptions),
34
30
  ...platform,
31
+ schedule: (fn) => setImmediate(fn),
35
32
  },
36
33
  })
37
34
  }
@@ -22,3 +22,15 @@ test('nexpression', async () => {
22
22
 
23
23
  assert.strictEqual(await compiler.resolveTemplate('{{ foo }}', { foo: 'bar' }), 'bar')
24
24
  })
25
+
26
+ test('pipe short-circuit', async () => {
27
+ const compiler = makeTemplateCompiler({
28
+ ds: {},
29
+ logger: console,
30
+ })
31
+
32
+ assert.strictEqual(
33
+ await compiler.resolveTemplate('{{#js _($.id, x => x + "ASD") }}', { foo: 'bar' }),
34
+ undefined,
35
+ )
36
+ })
@@ -223,6 +223,8 @@ function makeWrapper(expression) {
223
223
  }
224
224
 
225
225
  export default function ({ ds, proxify, compiler, logger, platform }) {
226
+ const schedule = platform?.schedule ?? ((fn) => queueMicrotask(fn))
227
+
226
228
  class Expression {
227
229
  constructor(script, expression, args, observer) {
228
230
  this._expression = expression
@@ -242,6 +244,15 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
242
244
  this._wrap = null
243
245
  this._suspended = false
244
246
  this._errored = false
247
+ this._globalThis = {
248
+ fp: null,
249
+ moment: null,
250
+ Timecode: null,
251
+ datefns: null,
252
+ JSON5: null,
253
+ $: null,
254
+ nxt: null,
255
+ }
245
256
 
246
257
  if (rxjs.isObservable(args)) {
247
258
  this._subscription = args.subscribe({
@@ -359,15 +370,13 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
359
370
  throw new Error('expression is already suspended')
360
371
  }
361
372
 
362
- const savedThis = {
363
- fp: globalThis.fp,
364
- moment: globalThis.moment,
365
- Timecode: globalThis.Timecode,
366
- datefns: globalThis.datefns,
367
- JSON5: globalThis.JSON5,
368
- $: globalThis.$,
369
- nxt: globalThis.nxt,
370
- }
373
+ this._globalThis.fp = globalThis.fp
374
+ this._globalThis.moment = globalThis.moment
375
+ this._globalThis.Timecode = globalThis.Timecode
376
+ this._globalThis.datefns = globalThis.datefns
377
+ this._globalThis.JSON5 = globalThis.JSON5
378
+ this._globalThis.$ = globalThis.$
379
+ this._globalThis.nxt = globalThis.nxt
371
380
 
372
381
  let value
373
382
  try {
@@ -385,14 +394,13 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
385
394
  // - Use https://github.com/tc39/proposal-shadowrealm?
386
395
  value = this._script()
387
396
  } finally {
388
- globalThis.fp = savedThis.fp
389
- globalThis._ = savedThis._
390
- globalThis.moment = savedThis.moment
391
- globalThis.Timecode = savedThis.Timecode
392
- globalThis.datefns = savedThis.datefns
393
- globalThis.JSON5 = savedThis.JSON5
394
- globalThis.$ = savedThis.$
395
- globalThis.nxt = savedThis.nxt
397
+ globalThis.fp = this._globalThis.fp
398
+ globalThis.moment = this._globalThis.moment
399
+ globalThis.Timecode = this._globalThis.Timecode
400
+ globalThis.datefns = this._globalThis.datefns
401
+ globalThis.JSON5 = this._globalThis.JSON5
402
+ globalThis.$ = this._globalThis.$
403
+ globalThis.nxt = this._globalThis.nxt
396
404
  }
397
405
 
398
406
  this._errored = false
@@ -453,7 +461,7 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
453
461
  }
454
462
 
455
463
  this._refreshing = true
456
- setImmediate(this._refreshImpl)
464
+ schedule(this._refreshImpl)
457
465
  }
458
466
 
459
467
  _getEntry(key, Entry, opaque) {
@@ -622,10 +630,12 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
622
630
  script = new Function(
623
631
  transform(`
624
632
  const _ = (value, ...fns) => {
625
- for (const fn of fns) {
626
- value = fn(value)
627
- if (value == null) {
628
- return value
633
+ if (value != null) {
634
+ for (const fn of fns) {
635
+ value = fn(value)
636
+ if (value == null) {
637
+ return value
638
+ }
629
639
  }
630
640
  }
631
641
  return value