@nxtedition/lib 23.17.12 → 23.17.14

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
@@ -902,7 +902,7 @@ export function makeApp(appConfig, onTerminate) {
902
902
  )
903
903
 
904
904
  const loggerSubscription = status$
905
- .pipe(rx.pluck('messages'), rx.startWith([]), rx.pairwise())
905
+ .pipe(rx.auditTime(1e3), rx.pluck('messages'), rx.startWith([]), rx.pairwise())
906
906
  .subscribe(([prev, next]) => {
907
907
  for (const { level, msg: status, ...message } of fp.differenceBy('id', next, prev)) {
908
908
  if (level >= 50) {
package/http.js CHANGED
@@ -232,7 +232,7 @@ export async function requestMiddleware(ctx, next) {
232
232
  }
233
233
 
234
234
  if (!isHealthcheck) {
235
- ctx.logger?.debug('request started')
235
+ ctx.logger?.debug({ req }, 'request started')
236
236
  }
237
237
 
238
238
  if (ctx.id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.17.12",
3
+ "version": "23.17.14",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -34,3 +34,19 @@ test('pipe short-circuit', async () => {
34
34
  undefined,
35
35
  )
36
36
  })
37
+
38
+ test('return function', async () => {
39
+ const compiler = makeTemplateCompiler({
40
+ ds: {},
41
+ logger: console,
42
+ })
43
+
44
+ assert.strictEqual(
45
+ (
46
+ await compiler.resolveTemplate(`{{#js (input) => fp.toUpper($.foo + input) }}`, {
47
+ foo: 'bar',
48
+ })
49
+ )('baz'),
50
+ 'BARBAZ',
51
+ )
52
+ })
@@ -644,6 +644,15 @@ export default function ({ ds, proxify, compiler, logger, platform }) {
644
644
 
645
645
  return value
646
646
  };
647
+
648
+ const fp = globalThis.fp
649
+ const moment = globalThis.moment
650
+ const Timecode = globalThis.Timecode
651
+ const datefns = globalThis.datefns
652
+ const JSON5 = globalThis.JSON5
653
+ const $ = globalThis.$
654
+ const nxt = globalThis.nxt
655
+
647
656
  _.asset = (type, state, suspend) => (name) => nxt._asset(name, type, state, suspend);
648
657
  _.ds = (postfix, state, suspend) => (name) => nxt._ds(name, postfix, state, suspend);
649
658
  _.get = (postfix, path, state, suspend) => (name) => nxt._get(name, postfix, path, state, suspend);
package/yield.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import { FixedQueue } from './fixed-queue.js'
2
+ import * as timers from './timers.js'
2
3
 
3
- const yieldQueue = new FixedQueue()
4
+ export const YIELD_PRIORITY_HIGH = 0
5
+ export const YIELD_PRIORITY_NORMAL = 1
6
+ export const YIELD_PRIORITY_LOW = 2
7
+ export const YIELD_PRIORITY_COUNT = 3
8
+
9
+ const yieldQueue = new Array(YIELD_PRIORITY_COUNT).fill(null).map(() => new FixedQueue())
4
10
  const yieldSchedule = globalThis.setImmediate ?? ((fn) => setTimeout(fn, 0))
5
11
 
6
12
  let yieldTimeout = 40
@@ -8,6 +14,8 @@ let yieldActive = false
8
14
  let yieldScheduled = false
9
15
  let yieldTime = performance.now()
10
16
 
17
+ const POOL = []
18
+
11
19
  export function setYieldTimeout(timeout) {
12
20
  if (typeof timeout !== 'number' || timeout < 0) {
13
21
  throw new TypeError('timeout must be a positive number')
@@ -15,6 +23,26 @@ export function setYieldTimeout(timeout) {
15
23
  yieldTimeout = timeout
16
24
  }
17
25
 
26
+ export function setTimeout(callback, timeout, opaque, priority) {
27
+ if (typeof callback !== 'function') {
28
+ throw new TypeError('callback must be a function')
29
+ }
30
+ if (typeof timeout !== 'number' || timeout < 0) {
31
+ throw new TypeError('timeout must be a positive number')
32
+ }
33
+
34
+ return timers.setTimeout((opaque) => maybeYield(callback, opaque, priority), timeout, opaque)
35
+ }
36
+
37
+ export function clearTimeout(timeout) {
38
+ timers.clearTimeout(timeout)
39
+ }
40
+
41
+ // TODO (fix): Return a handle?
42
+ export function setImmediate(callback, opaque, priority) {
43
+ maybeYield(callback, opaque, priority)
44
+ }
45
+
18
46
  export function shouldYield() {
19
47
  if (!yieldActive && performance.now() - yieldTime >= yieldTimeout) {
20
48
  yieldActive = true
@@ -22,54 +50,99 @@ export function shouldYield() {
22
50
  return yieldActive
23
51
  }
24
52
 
25
- export function maybeYield(callback) {
53
+ export function maybeYield(callback, opaque, priority) {
26
54
  if (callback != null && typeof callback !== 'function') {
27
55
  throw new TypeError('callback must be a function')
28
56
  }
29
57
 
30
58
  if (shouldYield()) {
31
- return doYield(callback)
59
+ return doYield(callback, opaque, priority)
32
60
  }
33
61
 
34
62
  if (callback != null) {
35
- callback(null)
63
+ callback(opaque)
36
64
  }
37
65
 
38
66
  return null
39
67
  }
40
68
 
41
- export function doYield(callback) {
69
+ export function doYield(callback, opaque, priority) {
42
70
  if (callback != null && typeof callback !== 'function') {
43
71
  throw new TypeError('callback must be a function')
44
72
  }
45
73
 
74
+ if (priority === undefined) {
75
+ priority = YIELD_PRIORITY_NORMAL
76
+ }
77
+
78
+ if (priority < 0 || priority >= YIELD_PRIORITY_COUNT) {
79
+ throw new RangeError('invalid priority')
80
+ }
81
+
46
82
  if (!yieldScheduled) {
47
83
  yieldScheduled = true
48
84
  yieldSchedule(dispatchYield)
49
85
  }
50
86
 
51
87
  if (callback != null) {
52
- yieldQueue.push(callback)
88
+ if (opaque !== undefined) {
89
+ const arr = POOL.pop() ?? [null, null]
90
+ arr[0] = callback
91
+ arr[1] = opaque
92
+ yieldQueue[priority].push(arr)
93
+ } else {
94
+ yieldQueue[priority].push(callback)
95
+ }
53
96
  return null
54
97
  }
55
98
 
56
99
  return new Promise((resolve) => {
57
- yieldQueue.push(resolve)
100
+ if (opaque !== undefined) {
101
+ const arr = POOL.pop() ?? [null, null]
102
+ arr[0] = resolve
103
+ arr[1] = opaque
104
+ yieldQueue[priority].push(arr)
105
+ } else {
106
+ yieldQueue[priority].push(callback)
107
+ }
58
108
  })
59
109
  }
60
110
 
111
+ function dispatchItem(item) {
112
+ if (item == null) {
113
+ return
114
+ }
115
+
116
+ let callback
117
+ let opaque = null
118
+
119
+ if (Array.isArray(item)) {
120
+ callback = item[0]
121
+ opaque = item[1]
122
+ if (POOL.length < 4096) {
123
+ item[0] = null
124
+ item[1] = null
125
+ POOL.push(item)
126
+ }
127
+ } else {
128
+ callback = item
129
+ }
130
+
131
+ callback(opaque)
132
+ }
133
+
61
134
  function dispatchYield() {
62
135
  yieldTime = performance.now()
63
136
  yieldActive = false
64
137
 
65
- while (!yieldQueue.isEmpty()) {
66
- const resolve = yieldQueue.shift()
67
-
68
- resolve(null)
69
-
70
- if (shouldYield()) {
71
- yieldSchedule(dispatchYield)
72
- return
138
+ for (let i = 0; i < YIELD_PRIORITY_COUNT; i++) {
139
+ const queue = yieldQueue[i]
140
+ while (!queue.isEmpty()) {
141
+ if (shouldYield()) {
142
+ yieldSchedule(dispatchYield)
143
+ return
144
+ }
145
+ dispatchItem(queue.shift())
73
146
  }
74
147
  }
75
148