@nxtedition/lib 14.0.0-alpha.1 → 14.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/package.json +1 -1
- package/util/template/index.js +40 -44
package/package.json
CHANGED
package/util/template/index.js
CHANGED
|
@@ -22,7 +22,7 @@ module.exports = (options) => {
|
|
|
22
22
|
try {
|
|
23
23
|
return compileObjectTemplate(obj)(...args)
|
|
24
24
|
} catch (err) {
|
|
25
|
-
return rxjs.throwError(err)
|
|
25
|
+
return rxjs.throwError(() => err)
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -37,27 +37,25 @@ module.exports = (options) => {
|
|
|
37
37
|
for (let i = 0; i < arr.length; i++) {
|
|
38
38
|
const resolver = compileTemplateLazy(arr[i])
|
|
39
39
|
if (resolver) {
|
|
40
|
-
resolvers ??= []
|
|
40
|
+
resolvers ??= [() => rxjs.of({ indices, arr })]
|
|
41
41
|
resolvers.push(resolver)
|
|
42
42
|
indices ??= []
|
|
43
43
|
indices.push(i)
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
)
|
|
47
|
+
return resolvers
|
|
48
|
+
? (...args) =>
|
|
49
|
+
rxjs.combineLatest(resolvers.map((resolver) => resolver(...args))).pipe(
|
|
50
|
+
rx.map((values) => {
|
|
51
|
+
const ret = [...arr]
|
|
52
|
+
for (let n = 0; n < values.length; n++) {
|
|
53
|
+
ret[indices[n]] = values[n]
|
|
54
|
+
}
|
|
55
|
+
return ret
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
: null
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
const compileArrayTemplate = weakCache(function compileArrayTemplate(arr) {
|
|
@@ -84,20 +82,18 @@ module.exports = (options) => {
|
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
})
|
|
100
|
-
)
|
|
85
|
+
return resolvers
|
|
86
|
+
? (...args) =>
|
|
87
|
+
rxjs.combineLatest(resolvers.map((resolver) => resolver(...args))).pipe(
|
|
88
|
+
rx.map((values) => {
|
|
89
|
+
const ret = { ...obj }
|
|
90
|
+
for (let n = 0; n < values.length; n++) {
|
|
91
|
+
ret[indices[n]] = values[n]
|
|
92
|
+
}
|
|
93
|
+
return ret
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
: null
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
const compileObjectTemplate = weakCache(function compileObjectTemplate(obj) {
|
|
@@ -125,6 +121,7 @@ module.exports = (options) => {
|
|
|
125
121
|
}
|
|
126
122
|
|
|
127
123
|
return {
|
|
124
|
+
input: str,
|
|
128
125
|
pre: str.slice(0, templateStart),
|
|
129
126
|
type,
|
|
130
127
|
body: str.slice(bodyStart, bodyEnd),
|
|
@@ -132,22 +129,12 @@ module.exports = (options) => {
|
|
|
132
129
|
}
|
|
133
130
|
}
|
|
134
131
|
|
|
135
|
-
const
|
|
136
|
-
if (!fp.isString(str)) {
|
|
137
|
-
throw new Error('invalid argument')
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const match = inner(str)
|
|
141
|
-
|
|
142
|
-
if (!match) {
|
|
143
|
-
return null
|
|
144
|
-
}
|
|
145
|
-
|
|
132
|
+
const _compileStringTemplate = weakCache(function _compileStringTemplate(str, match) {
|
|
146
133
|
const { pre, type, body, post } = match
|
|
147
134
|
|
|
148
135
|
const compileExpression = compilers[type]
|
|
149
136
|
if (!compileExpression) {
|
|
150
|
-
throw new Error('unknown expression type')
|
|
137
|
+
throw new Error('unknown expression type: ' + type)
|
|
151
138
|
}
|
|
152
139
|
|
|
153
140
|
const expr = compileExpression(body)
|
|
@@ -164,7 +151,16 @@ module.exports = (options) => {
|
|
|
164
151
|
)
|
|
165
152
|
})
|
|
166
153
|
|
|
167
|
-
|
|
154
|
+
function compileStringTemplateLazy(str) {
|
|
155
|
+
if (!fp.isString(str)) {
|
|
156
|
+
throw new Error('invalid argument')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const match = inner(str)
|
|
160
|
+
return match ? _compileStringTemplate(str, match) : null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function compileStringTemplate(str) {
|
|
168
164
|
return compileStringTemplateLazy(str) ?? (() => rxjs.of(str))
|
|
169
165
|
}
|
|
170
166
|
|
|
@@ -221,7 +217,7 @@ module.exports = (options) => {
|
|
|
221
217
|
try {
|
|
222
218
|
return compileTemplate(str)(...args)
|
|
223
219
|
} catch (err) {
|
|
224
|
-
return rxjs.throwError(err)
|
|
220
|
+
return rxjs.throwError(() => err)
|
|
225
221
|
}
|
|
226
222
|
}
|
|
227
223
|
|