@nxtedition/lib 15.1.7 → 16.0.0
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 +39 -113
- package/ass.js +3 -5
- package/couch.js +5 -5
- package/deepstream.js +8 -8
- package/docker-secrets.js +6 -12
- package/elasticsearch.js +3 -3
- package/errors.js +15 -14
- package/hash.js +1 -1
- package/http.js +17 -22
- package/logger.js +4 -4
- package/merge-ranges.js +1 -1
- package/mime.js +3 -10
- package/package.json +15 -13
- package/platform.js +1 -1
- package/rxjs/auditMap.js +6 -4
- package/rxjs/combineMap.js +6 -4
- package/rxjs/firstValueFrom.js +3 -3
- package/rxjs/lastValueFrom.js +4 -4
- package/rxjs/withAbortSignal.js +7 -5
- package/serializers.js +9 -9
- package/stream.js +3 -9
- package/subtract-ranges.js +1 -1
- package/timeline.js +5 -11
- package/trace.js +2 -2
- package/util/cached.js +2 -2
- package/util/compare-rev.js +3 -3
- package/util/template/index.js +12 -12
- package/util/template/javascript.js +15 -15
- package/util/template/nextpressions.js +35 -34
- package/weakCache.js +1 -1
- package/worker.js +4 -4
- package/rxjs/index.js +0 -7
- package/util/index.js +0 -5
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"files": [
|
|
7
8
|
"hash.js",
|
|
8
9
|
"ass.js",
|
|
@@ -72,10 +73,12 @@
|
|
|
72
73
|
"/__tests__"
|
|
73
74
|
],
|
|
74
75
|
"dependencies": {
|
|
75
|
-
"@
|
|
76
|
+
"@elastic/elasticsearch": "^8.10.0",
|
|
77
|
+
"@elastic/transport": "^8.3.4",
|
|
78
|
+
"@nxtedition/nxt-undici": "^1.4.4",
|
|
76
79
|
"date-fns": "^2.29.3",
|
|
77
80
|
"fast-querystring": "^1.1.1",
|
|
78
|
-
"hasha": "^
|
|
81
|
+
"hasha": "^6.0.0",
|
|
79
82
|
"http-errors": "^2.0.0",
|
|
80
83
|
"json5": "^2.2.3",
|
|
81
84
|
"koa-compose": "^4.1.0",
|
|
@@ -90,26 +93,29 @@
|
|
|
90
93
|
"request-target": "^1.0.2",
|
|
91
94
|
"smpte-timecode": "^1.3.3",
|
|
92
95
|
"split-string": "^6.0.0",
|
|
96
|
+
"split2": "^4.2.0",
|
|
93
97
|
"toobusy-js": "^0.5.1",
|
|
94
98
|
"undici": "^5.27.2",
|
|
95
|
-
"url-join": "^
|
|
99
|
+
"url-join": "^5.0.0"
|
|
96
100
|
},
|
|
97
101
|
"devDependencies": {
|
|
98
|
-
"@
|
|
102
|
+
"@nxtedition/deepstream.io-client-js": ">=14.1.0",
|
|
103
|
+
"@types/lodash": "^4.14.201",
|
|
104
|
+
"@types/node": "^20.9.0",
|
|
99
105
|
"eslint": "^8.53.0",
|
|
100
106
|
"eslint-config-prettier": "^9.0.0",
|
|
101
107
|
"eslint-config-standard": "^17.0.0",
|
|
102
108
|
"eslint-plugin-import": "^2.29.0",
|
|
103
|
-
"eslint-plugin-n": "^16.3.
|
|
109
|
+
"eslint-plugin-n": "^16.3.1",
|
|
104
110
|
"eslint-plugin-node": "^11.1.0",
|
|
105
111
|
"eslint-plugin-promise": "^6.0.0",
|
|
106
112
|
"husky": "^8.0.3",
|
|
107
|
-
"lint-staged": "^15.0
|
|
113
|
+
"lint-staged": "^15.1.0",
|
|
108
114
|
"pinst": "^3.0.0",
|
|
109
|
-
"prettier": "^3.0
|
|
115
|
+
"prettier": "^3.1.0",
|
|
110
116
|
"rxjs": "^7.5.6",
|
|
111
117
|
"send": "^0.18.0",
|
|
112
|
-
"tap": "^18.5.
|
|
118
|
+
"tap": "^18.5.8"
|
|
113
119
|
},
|
|
114
120
|
"peerDependencies": {
|
|
115
121
|
"@elastic/elasticsearch": "^8.6.0",
|
|
@@ -117,9 +123,5 @@
|
|
|
117
123
|
"@nxtedition/deepstream.io-client-js": ">=14.1.0",
|
|
118
124
|
"pino": ">=7.0.0",
|
|
119
125
|
"rxjs": ">=6.0.0"
|
|
120
|
-
},
|
|
121
|
-
"optionalDependencies": {
|
|
122
|
-
"linux-perf": "^0.3.1",
|
|
123
|
-
"nice-napi": ">=1.0.0"
|
|
124
126
|
}
|
|
125
127
|
}
|
package/platform.js
CHANGED
package/rxjs/auditMap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import rxjs from 'rxjs'
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function auditMapImpl(project) {
|
|
4
4
|
return new rxjs.Observable((o) => {
|
|
5
5
|
let pendingValue = null
|
|
6
6
|
let hasPendingValue = false
|
|
@@ -78,6 +78,8 @@ function auditMap(project) {
|
|
|
78
78
|
})
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
rxjs.Observable.prototype.auditMap =
|
|
81
|
+
rxjs.Observable.prototype.auditMap = auditMapImpl
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
export default function auditMap(project) {
|
|
84
|
+
return (o) => auditMapImpl.call(o, project)
|
|
85
|
+
}
|
package/rxjs/combineMap.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import rxjs from 'rxjs'
|
|
2
2
|
|
|
3
3
|
const EMPTY = Object.freeze([])
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function combineMapImpl(project, equals = (a, b) => a === b) {
|
|
6
6
|
const self = this
|
|
7
7
|
return new rxjs.Observable((o) => {
|
|
8
8
|
let curr = EMPTY
|
|
@@ -146,6 +146,8 @@ function combineMap(project, equals = (a, b) => a === b) {
|
|
|
146
146
|
})
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
rxjs.Observable.prototype.combineMap =
|
|
149
|
+
rxjs.Observable.prototype.combineMap = combineMapImpl
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
export default function combineMap(project, equals) {
|
|
152
|
+
return (o) => combineMapImpl.call(o, project, equals)
|
|
153
|
+
}
|
package/rxjs/firstValueFrom.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import rx from 'rxjs/operators'
|
|
2
|
+
import withAbortSignal from './withAbortSignal.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export default function firstValueFrom(x$, config) {
|
|
5
5
|
const hasConfig = config && typeof config === 'object'
|
|
6
6
|
const signal = hasConfig ? config.signal : undefined
|
|
7
7
|
const timeout = hasConfig ? config.timeout : undefined
|
package/rxjs/lastValueFrom.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import rxjs from 'rxjs'
|
|
2
|
+
import rx from 'rxjs/operators'
|
|
3
|
+
import { AbortError } from '../errors'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export default function lastValueFrom(x$, config) {
|
|
6
6
|
const hasConfig = config && typeof config === 'object'
|
|
7
7
|
const signal = hasConfig ? config.signal : undefined
|
|
8
8
|
|
package/rxjs/withAbortSignal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import rxjs from 'rxjs'
|
|
2
|
+
import { AbortError } from '../errors.js'
|
|
3
3
|
|
|
4
|
-
function
|
|
4
|
+
function withAbortSignalImpl(signal) {
|
|
5
5
|
return new rxjs.Observable((o) => {
|
|
6
6
|
o.add(this.subscribe(o))
|
|
7
7
|
|
|
@@ -24,6 +24,8 @@ function withAbortSignal(signal) {
|
|
|
24
24
|
})
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
rxjs.Observable.prototype.withAbortSignal =
|
|
27
|
+
rxjs.Observable.prototype.withAbortSignal = withAbortSignalImpl
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
export default function withAbortSignal(signal) {
|
|
30
|
+
return (o) => withAbortSignalImpl.call(o, signal)
|
|
31
|
+
}
|
package/serializers.js
CHANGED
|
@@ -28,7 +28,7 @@ function getHeaders(obj) {
|
|
|
28
28
|
)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
export default {
|
|
32
32
|
err: (err) => {
|
|
33
33
|
// TODO (fix): Merge with errors/serializeError?
|
|
34
34
|
|
|
@@ -108,14 +108,14 @@ module.exports = {
|
|
|
108
108
|
const url = ureq.url?.href
|
|
109
109
|
? ureq.url.href
|
|
110
110
|
: typeof ureq.url === 'string'
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
? ureq.url
|
|
112
|
+
: ureq.origin
|
|
113
|
+
? `${ureq.origin}${ureq.path || ''}`
|
|
114
|
+
: ureq.hostname
|
|
115
|
+
? `${ureq.protocol || 'http:'}//${ureq.hostname}:${
|
|
116
|
+
ureq.port || { 'http:': 80, 'https:': 443 }[ureq.protocol]
|
|
117
|
+
}${ureq.path || ''}`
|
|
118
|
+
: ureq.path || ureq.pathname
|
|
119
119
|
|
|
120
120
|
return {
|
|
121
121
|
id: ureq.id || getHeader(ureq, 'request-id'),
|
package/stream.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function isReadableNodeStream(obj, strict = false) {
|
|
1
|
+
export function isReadableNodeStream(obj, strict = false) {
|
|
2
2
|
return !!(
|
|
3
3
|
(
|
|
4
4
|
obj &&
|
|
@@ -11,13 +11,13 @@ function isReadableNodeStream(obj, strict = false) {
|
|
|
11
11
|
)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function isStream(obj) {
|
|
14
|
+
export function isStream(obj) {
|
|
15
15
|
return (
|
|
16
16
|
obj && typeof obj === 'object' && typeof obj.pipe === 'function' && typeof obj.on === 'function'
|
|
17
17
|
)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function readableStreamLength(stream) {
|
|
20
|
+
export function readableStreamLength(stream) {
|
|
21
21
|
if (!isReadableNodeStream(stream)) {
|
|
22
22
|
return null
|
|
23
23
|
}
|
|
@@ -29,9 +29,3 @@ function readableStreamLength(stream) {
|
|
|
29
29
|
const state = stream._readableState
|
|
30
30
|
return state && state.ended === true && Number.isFinite(state.length) ? state.length : null
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
34
|
-
isStream,
|
|
35
|
-
isReadableNodeStream,
|
|
36
|
-
readableStreamLength,
|
|
37
|
-
}
|
package/subtract-ranges.js
CHANGED
package/timeline.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import fp from 'lodash/fp.js'
|
|
2
2
|
|
|
3
3
|
const STOP_TIME = 5
|
|
4
4
|
const PRELOAD_TIME = 5
|
|
5
5
|
|
|
6
6
|
// Events must have start/end/source/data, and should be sorted by start
|
|
7
|
-
function eventsToTimeline(events) {
|
|
7
|
+
export function eventsToTimeline(events) {
|
|
8
8
|
const timeline = []
|
|
9
9
|
events = [...events]
|
|
10
10
|
let active = []
|
|
@@ -52,7 +52,7 @@ function eventsToTimeline(events) {
|
|
|
52
52
|
return timeline
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function timelineToCommands(timeline) {
|
|
55
|
+
export function timelineToCommands(timeline) {
|
|
56
56
|
const commands = []
|
|
57
57
|
let current = { time: -Infinity }
|
|
58
58
|
for (let i = 0; i < timeline.length; i++) {
|
|
@@ -70,7 +70,7 @@ function timelineToCommands(timeline) {
|
|
|
70
70
|
{
|
|
71
71
|
command: 'play',
|
|
72
72
|
...fp.omit(['source', 'data'], next),
|
|
73
|
-
}
|
|
73
|
+
},
|
|
74
74
|
)
|
|
75
75
|
} else if (next.source) {
|
|
76
76
|
if (next.source !== current.source || !current.data) {
|
|
@@ -96,7 +96,7 @@ function timelineToCommands(timeline) {
|
|
|
96
96
|
return commands
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
function pickLayer(source, min = 11, max = 99999) {
|
|
99
|
+
export function pickLayer(source, min = 11, max = 99999) {
|
|
100
100
|
if (!source) {
|
|
101
101
|
return min
|
|
102
102
|
}
|
|
@@ -113,9 +113,3 @@ function pickLayer(source, min = 11, max = 99999) {
|
|
|
113
113
|
|
|
114
114
|
return min + (hash % (max - min + 1))
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
module.exports = {
|
|
118
|
-
eventsToTimeline,
|
|
119
|
-
timelineToCommands,
|
|
120
|
-
pickLayer,
|
|
121
|
-
}
|
package/trace.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { Pool } from 'undici'
|
|
2
2
|
|
|
3
3
|
function sleep(n) {
|
|
4
4
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n)
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export function makeTrace({
|
|
8
8
|
url,
|
|
9
9
|
stringify = JSON.stringify,
|
|
10
10
|
index,
|
package/util/cached.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { Observable, ReplaySubject, Subject } from 'rxjs'
|
|
2
2
|
|
|
3
3
|
const registry = new FinalizationRegistry(({ interval, array }) => {
|
|
4
4
|
clearInterval(interval)
|
|
@@ -7,7 +7,7 @@ const registry = new FinalizationRegistry(({ interval, array }) => {
|
|
|
7
7
|
}
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
export default function cached(fn, options, keySelector) {
|
|
11
11
|
if (Number.isFinite(options)) {
|
|
12
12
|
options = { maxAge: options }
|
|
13
13
|
} else if (options == null) {
|
package/util/compare-rev.js
CHANGED
|
@@ -197,7 +197,7 @@ const compareRevBufferString = (a, b) => {
|
|
|
197
197
|
return lenA - lenB
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
export default function compareRev(a, b) {
|
|
201
201
|
// Handle null and undefined
|
|
202
202
|
if (!a || !a.length) {
|
|
203
203
|
return !b || !b.length ? 0 : -1
|
|
@@ -213,6 +213,6 @@ module.exports = function (a, b) {
|
|
|
213
213
|
? compareRevStringString(a, b)
|
|
214
214
|
: -compareRevBufferString(b, a)
|
|
215
215
|
: isStringB
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
? compareRevBufferString(a, b)
|
|
217
|
+
: compareRevBufferBuffer(a, b)
|
|
218
218
|
}
|
package/util/template/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import rx from 'rxjs/operators'
|
|
2
|
+
import rxjs from 'rxjs'
|
|
3
|
+
import fp from 'lodash/fp.js'
|
|
4
|
+
import getNxtpressionsCompiler from './nextpressions.js'
|
|
5
|
+
import getJavascriptCompiler from './javascript.js'
|
|
6
|
+
import JSON5 from 'json5'
|
|
7
|
+
import objectHash from 'object-hash'
|
|
8
|
+
import { makeWeakCache } from '../../weakCache.js'
|
|
9
|
+
import firstValueFrom from '../../rxjs/firstValueFrom.js'
|
|
10
|
+
|
|
11
|
+
export function makeTemplateCompiler({ ds, proxify }) {
|
|
12
12
|
const compiler = {
|
|
13
13
|
current: null,
|
|
14
14
|
resolveTemplate,
|
|
@@ -207,7 +207,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
207
207
|
return typeof val === 'string' && val.indexOf('{{') !== -1
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
const _compileTemplateCache =
|
|
210
|
+
const _compileTemplateCache = makeWeakCache(
|
|
211
211
|
(template) => {
|
|
212
212
|
if (fp.isPlainObject(template)) {
|
|
213
213
|
return compileObjectTemplate(template)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { makeWeakCache } from '../../weakCache.js'
|
|
3
|
+
import rxjs from 'rxjs'
|
|
4
|
+
import vm from 'node:vm'
|
|
5
|
+
import objectHash from 'object-hash'
|
|
6
|
+
import datefns from 'date-fns'
|
|
7
|
+
import JSON5 from 'json5'
|
|
8
|
+
import { request } from '@nxtedition/nxt-undici'
|
|
9
|
+
import undici from 'undici'
|
|
10
10
|
|
|
11
11
|
const kSuspend = Symbol('kSuspend')
|
|
12
12
|
const kEmpty = Symbol('kEmpty')
|
|
@@ -178,10 +178,10 @@ function pipe(value, ...fns) {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
const globals = {
|
|
181
|
-
fp:
|
|
182
|
-
_:
|
|
183
|
-
moment:
|
|
184
|
-
Timecode:
|
|
181
|
+
fp: await import('lodash/fp.js'),
|
|
182
|
+
_: await import('lodash'),
|
|
183
|
+
moment: await import('moment-timezone'),
|
|
184
|
+
Timecode: await import('smpte-timecode'),
|
|
185
185
|
datefns,
|
|
186
186
|
JSON5,
|
|
187
187
|
pipe,
|
|
@@ -215,7 +215,7 @@ function makeWrapper(expression) {
|
|
|
215
215
|
return (value, suspend = true) => proxify(value, expression, handler, suspend)
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
export default function ({ ds, proxify, compiler }) {
|
|
219
219
|
class Expression {
|
|
220
220
|
constructor(context, script, expression, args, observer) {
|
|
221
221
|
this._context = context
|
|
@@ -539,7 +539,7 @@ module.exports = ({ ds, proxify, compiler }) => {
|
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
-
return
|
|
542
|
+
return makeWeakCache((expression) => {
|
|
543
543
|
let script
|
|
544
544
|
try {
|
|
545
545
|
script = new vm.Script(`
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import moment from 'moment-timezone'
|
|
2
|
+
import rx from 'rxjs/operators'
|
|
3
|
+
import Observable from 'rxjs'
|
|
4
|
+
import JSON5 from 'json5'
|
|
5
|
+
import fp from 'lodash/fp.js'
|
|
6
|
+
import NestedError from 'nested-error-stacks'
|
|
7
|
+
import { hashSync } from 'hasha'
|
|
8
|
+
import split from 'split-string'
|
|
9
|
+
import { makeWeakCache } from '../../weakCache.js'
|
|
10
|
+
|
|
9
11
|
const RETURN = {}
|
|
10
|
-
const weakCache = require('../../weakCache')
|
|
11
12
|
|
|
12
13
|
function asFilter(transform, predicate, obj) {
|
|
13
14
|
return fp.mapValues(
|
|
@@ -23,11 +24,11 @@ function asFilter(transform, predicate, obj) {
|
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
|
-
obj
|
|
27
|
+
obj,
|
|
27
28
|
)
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
export default function ({ ds } = {}) {
|
|
31
32
|
const FILTERS = {
|
|
32
33
|
// any
|
|
33
34
|
...asFilter(null, null, {
|
|
@@ -52,7 +53,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
52
53
|
}
|
|
53
54
|
return Number(value)
|
|
54
55
|
},
|
|
55
|
-
date: (tz) => (value) => tz ? moment.tz(value, tz) : moment(value),
|
|
56
|
+
date: (tz) => (value) => (tz ? moment.tz(value, tz) : moment(value)),
|
|
56
57
|
array: () => (value) => [value],
|
|
57
58
|
value: (value) => () => value,
|
|
58
59
|
int:
|
|
@@ -85,11 +86,11 @@ module.exports = ({ ds } = {}) => {
|
|
|
85
86
|
isNil: () => (value) => value == null,
|
|
86
87
|
isNumber: () => (value) => Number.isFinite(value),
|
|
87
88
|
isString: () => (value) => fp.isString(value),
|
|
88
|
-
ternary: (a, b) => (value) => value ? a : b,
|
|
89
|
-
cond: (a, b) => (value) => value ? a : b,
|
|
90
|
-
hasha: (options) => (value) =>
|
|
89
|
+
ternary: (a, b) => (value) => (value ? a : b),
|
|
90
|
+
cond: (a, b) => (value) => (value ? a : b),
|
|
91
|
+
hasha: (options) => (value) => hashSync(JSON.stringify(value), options || {}),
|
|
91
92
|
hashaint: (options) => (value) =>
|
|
92
|
-
parseInt(
|
|
93
|
+
parseInt(hashSync(JSON.stringify(value), options || {}).slice(-13), 16),
|
|
93
94
|
return: () => (value) => value || RETURN,
|
|
94
95
|
add:
|
|
95
96
|
(...args) =>
|
|
@@ -131,7 +132,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
131
132
|
floor: () => (value) => Math.floor(value),
|
|
132
133
|
ceil: () => (value) => Math.ceil(value),
|
|
133
134
|
clamp: (min, max) => (value) => Math.max(min, Math.min(max, value)),
|
|
134
|
-
}
|
|
135
|
+
},
|
|
135
136
|
),
|
|
136
137
|
...asFilter(
|
|
137
138
|
(value) =>
|
|
@@ -148,7 +149,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
148
149
|
(...args) =>
|
|
149
150
|
(value) =>
|
|
150
151
|
Math.max(...value, ...args),
|
|
151
|
-
}
|
|
152
|
+
},
|
|
152
153
|
),
|
|
153
154
|
// date
|
|
154
155
|
...asFilter(
|
|
@@ -172,7 +173,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
172
173
|
// TODO (fix): Validate arguments...
|
|
173
174
|
return (value) => value.endOf(endOf)
|
|
174
175
|
},
|
|
175
|
-
}
|
|
176
|
+
},
|
|
176
177
|
),
|
|
177
178
|
// ds
|
|
178
179
|
...asFilter(null, (value) => value && (typeof value === 'string' || Array.isArray(value)), {
|
|
@@ -224,8 +225,8 @@ module.exports = ({ ds } = {}) => {
|
|
|
224
225
|
value == null || fp.isPlainObject(value) || Array.isArray(value) ? '' : String(value),
|
|
225
226
|
(value) => typeof value === 'string',
|
|
226
227
|
{
|
|
227
|
-
fromJSON: () => (value) => value ? JSON.parse(value) : null,
|
|
228
|
-
fromJSON5: () => (value) => value ? JSON5.parse(value) : null,
|
|
228
|
+
fromJSON: () => (value) => (value ? JSON.parse(value) : null),
|
|
229
|
+
fromJSON5: () => (value) => (value ? JSON5.parse(value) : null),
|
|
229
230
|
toSlate: () => (value) => ({
|
|
230
231
|
object: 'value',
|
|
231
232
|
document: {
|
|
@@ -268,7 +269,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
268
269
|
rx.filter(({ state, data }) => data || state >= ds.record.PROVIDER),
|
|
269
270
|
rx.pluck('data'),
|
|
270
271
|
rx.distinctUntilChanged(),
|
|
271
|
-
rx.map((isType) => (isType ? value : _return ? RETURN : null))
|
|
272
|
+
rx.map((isType) => (isType ? value : _return ? RETURN : null)),
|
|
272
273
|
)
|
|
273
274
|
: null
|
|
274
275
|
},
|
|
@@ -371,7 +372,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
371
372
|
},
|
|
372
373
|
wordcount: () => (value) => fp.words(value).length,
|
|
373
374
|
words: () => (value) => fp.words(value),
|
|
374
|
-
}
|
|
375
|
+
},
|
|
375
376
|
),
|
|
376
377
|
...asFilter(
|
|
377
378
|
(value) => (Array.isArray(value) || typeof value === 'string' ? value : []),
|
|
@@ -381,7 +382,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
381
382
|
(...args) =>
|
|
382
383
|
(value) =>
|
|
383
384
|
value.includes(...args),
|
|
384
|
-
}
|
|
385
|
+
},
|
|
385
386
|
),
|
|
386
387
|
// array
|
|
387
388
|
...asFilter(
|
|
@@ -443,7 +444,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
443
444
|
(...args) =>
|
|
444
445
|
(value) =>
|
|
445
446
|
fp.pull(args[0], value),
|
|
446
|
-
}
|
|
447
|
+
},
|
|
447
448
|
),
|
|
448
449
|
// object
|
|
449
450
|
...asFilter(
|
|
@@ -452,7 +453,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
452
453
|
{
|
|
453
454
|
merge: (value) => fp.merge(value),
|
|
454
455
|
set: (path, value) => fp.set(path, value),
|
|
455
|
-
}
|
|
456
|
+
},
|
|
456
457
|
),
|
|
457
458
|
// collection
|
|
458
459
|
...asFilter(
|
|
@@ -467,7 +468,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
467
468
|
keys: () => (value) => fp.keys(value),
|
|
468
469
|
size: () => (value) => fp.size(value),
|
|
469
470
|
entries: () => (value) => fp.entries(value),
|
|
470
|
-
}
|
|
471
|
+
},
|
|
471
472
|
),
|
|
472
473
|
// misc
|
|
473
474
|
...asFilter(null, null, {
|
|
@@ -491,13 +492,13 @@ module.exports = ({ ds } = {}) => {
|
|
|
491
492
|
|
|
492
493
|
return Observable.timer(dueTime, period).pipe(
|
|
493
494
|
rx.map(() => moment()),
|
|
494
|
-
rx.startWith(null)
|
|
495
|
+
rx.startWith(null),
|
|
495
496
|
)
|
|
496
497
|
},
|
|
497
498
|
}),
|
|
498
499
|
}
|
|
499
500
|
|
|
500
|
-
const getFilter =
|
|
501
|
+
const getFilter = makeWeakCache((filterStr) => {
|
|
501
502
|
const [, filterName, argsStr] =
|
|
502
503
|
filterStr
|
|
503
504
|
.replace(/\n/g, '\\n')
|
|
@@ -541,7 +542,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
541
542
|
return Observable.isObservable(value)
|
|
542
543
|
? value.pipe(
|
|
543
544
|
rx.switchMap((value) => getValue(value[path], rest)),
|
|
544
|
-
rx.distinctUntilChanged()
|
|
545
|
+
rx.distinctUntilChanged(),
|
|
545
546
|
)
|
|
546
547
|
: getValue(value[path], rest)
|
|
547
548
|
}
|
|
@@ -564,7 +565,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
564
565
|
rx.switchMap((value) => reduceValue(value, index, filters, options)),
|
|
565
566
|
rx.distinctUntilChanged(),
|
|
566
567
|
// TODO (fix): better error handling...
|
|
567
|
-
rx.catchError(() => Observable.of(null))
|
|
568
|
+
rx.catchError(() => Observable.of(null)),
|
|
568
569
|
)
|
|
569
570
|
}
|
|
570
571
|
}
|
|
@@ -572,7 +573,7 @@ module.exports = ({ ds } = {}) => {
|
|
|
572
573
|
return Observable.of(value)
|
|
573
574
|
}
|
|
574
575
|
|
|
575
|
-
return
|
|
576
|
+
return makeWeakCache((expression) => {
|
|
576
577
|
try {
|
|
577
578
|
const [basePathStr, ...tokens] = split(expression, {
|
|
578
579
|
separator: '|',
|
|
@@ -589,10 +590,10 @@ module.exports = ({ ds } = {}) => {
|
|
|
589
590
|
rx.catchError((err) => {
|
|
590
591
|
options?.logger?.error(
|
|
591
592
|
{ err, expression: { expression, context: JSON.stringify(context) } },
|
|
592
|
-
'expression failed'
|
|
593
|
+
'expression failed',
|
|
593
594
|
)
|
|
594
595
|
return Observable.of(null)
|
|
595
|
-
})
|
|
596
|
+
}),
|
|
596
597
|
)
|
|
597
598
|
} catch (err) {
|
|
598
599
|
throw new NestedError(`failed to parse expression ${expression}`, err)
|
package/weakCache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* globals WeakRef FinalizationRegistry */
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export function makeWeakCache(valueSelector, keySelector) {
|
|
4
4
|
const cache = new Map()
|
|
5
5
|
const finalizationRegistry = new FinalizationRegistry((key) => {
|
|
6
6
|
const ref = cache.get(key)
|
package/worker.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { once } from 'node:events'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export async function terminate(worker, { logger = null, timeout = 10e3 } = {}) {
|
|
4
4
|
try {
|
|
5
5
|
worker.postMessage({ type: 'nxt:worker:terminate' })
|
|
6
6
|
await Promise.race([
|
|
7
|
-
|
|
7
|
+
once(worker, 'exit'),
|
|
8
8
|
new Promise((resolve, reject) =>
|
|
9
|
-
setTimeout(() => reject(new Error('worker close timeout')), timeout)
|
|
9
|
+
setTimeout(() => reject(new Error('worker close timeout')), timeout),
|
|
10
10
|
),
|
|
11
11
|
])
|
|
12
12
|
} catch (err) {
|