@nxtedition/lib 24.1.0 → 24.1.1
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/package.json
CHANGED
|
@@ -3,9 +3,7 @@ import fp from 'lodash/fp.js'
|
|
|
3
3
|
import getNxtpressionsCompiler from './nextpressions.js'
|
|
4
4
|
import getJavascriptCompiler from './javascript.js'
|
|
5
5
|
import JSON5 from 'json5'
|
|
6
|
-
import objectHash from 'object-hash'
|
|
7
6
|
import firstValueFrom from '../../rxjs/firstValueFrom.js'
|
|
8
|
-
import { LRUCache } from 'lru-cache'
|
|
9
7
|
|
|
10
8
|
export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
|
|
11
9
|
const compiler = {
|
|
@@ -50,34 +48,6 @@ export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
|
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
const hashTemplate = (template, prefix) => {
|
|
54
|
-
if (typeof template === 'string') {
|
|
55
|
-
return isTemplate(template) ? objectHash([prefix, template]) : ''
|
|
56
|
-
} else if (fp.isPlainObject(template)) {
|
|
57
|
-
let hashes
|
|
58
|
-
for (const key of Object.keys(template)) {
|
|
59
|
-
const hash = hashTemplate(template[key], key)
|
|
60
|
-
if (hash) {
|
|
61
|
-
hashes ??= []
|
|
62
|
-
hashes.push(hash)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return hashes ? objectHash([prefix, hashes]) : ''
|
|
66
|
-
} else if (fp.isArray(template)) {
|
|
67
|
-
let hashes
|
|
68
|
-
for (let idx = 0; idx < template.length; idx++) {
|
|
69
|
-
const hash = hashTemplate(template[idx], idx)
|
|
70
|
-
if (hash) {
|
|
71
|
-
hashes ??= []
|
|
72
|
-
hashes.push(hash)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return hashes ? objectHash([prefix, hashes]) : ''
|
|
76
|
-
} else {
|
|
77
|
-
return ''
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
51
|
function compileArrayTemplate(template) {
|
|
82
52
|
let resolvers
|
|
83
53
|
let indices
|
|
@@ -211,9 +181,8 @@ export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
|
|
|
211
181
|
}
|
|
212
182
|
|
|
213
183
|
const objCache = new WeakMap()
|
|
214
|
-
const strCache = new LRUCache({ max: 8192 })
|
|
215
184
|
|
|
216
|
-
const
|
|
185
|
+
const _compileTemplate = (template) => {
|
|
217
186
|
if (fp.isPlainObject(template)) {
|
|
218
187
|
let resolver = objCache.get(template)
|
|
219
188
|
if (resolver == null) {
|
|
@@ -229,23 +198,12 @@ export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
|
|
|
229
198
|
}
|
|
230
199
|
return resolver
|
|
231
200
|
} else if (isTemplate(template)) {
|
|
232
|
-
|
|
233
|
-
if (resolver == null) {
|
|
234
|
-
resolver = compileStringTemplate(template)
|
|
235
|
-
strCache.set(template, resolver)
|
|
236
|
-
}
|
|
237
|
-
return resolver
|
|
201
|
+
return compileStringTemplate(template)
|
|
238
202
|
} else {
|
|
239
203
|
return null
|
|
240
204
|
}
|
|
241
205
|
}
|
|
242
206
|
|
|
243
|
-
function _compileTemplate(template) {
|
|
244
|
-
const hash = hashTemplate(template)
|
|
245
|
-
const resolver = hash ? _compileTemplateCache(template, hash) : null
|
|
246
|
-
return resolver // ? (args$) => resolver(template, args$) : null
|
|
247
|
-
}
|
|
248
|
-
|
|
249
207
|
function compileTemplate(template) {
|
|
250
208
|
const resolver = _compileTemplate(template)
|
|
251
209
|
return resolver ? (args$) => resolver(template, args$) : null
|