@nxtedition/lib 14.0.10 → 14.0.11
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 +44 -30
package/package.json
CHANGED
package/util/template/index.js
CHANGED
|
@@ -71,8 +71,8 @@ module.exports = (options) => {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
const _compileArrayTemplate = weakCache(
|
|
74
|
-
(
|
|
75
|
-
if (!fp.isArray(
|
|
74
|
+
(template, hash) => {
|
|
75
|
+
if (!fp.isArray(template)) {
|
|
76
76
|
throw new Error('invalid argument')
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -83,8 +83,8 @@ module.exports = (options) => {
|
|
|
83
83
|
let resolvers
|
|
84
84
|
let indices
|
|
85
85
|
|
|
86
|
-
for (let i = 0; i <
|
|
87
|
-
const resolver = compileTemplate(
|
|
86
|
+
for (let i = 0; i < template.length; i++) {
|
|
87
|
+
const resolver = compileTemplate(template[i])
|
|
88
88
|
if (resolver) {
|
|
89
89
|
resolvers ??= []
|
|
90
90
|
resolvers.push(resolver)
|
|
@@ -94,8 +94,14 @@ module.exports = (options) => {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
return resolvers
|
|
97
|
-
? (args$) =>
|
|
98
|
-
|
|
97
|
+
? (arr, args$) => {
|
|
98
|
+
const len = resolvers.length
|
|
99
|
+
const values = new Array(len)
|
|
100
|
+
for (let n = 0; n < len; n++) {
|
|
101
|
+
values[n] = resolvers[n](arr[indices[n]], args$)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return rxjs.combineLatest(values).pipe(
|
|
99
105
|
rx.map((values) => {
|
|
100
106
|
const ret = [...arr]
|
|
101
107
|
for (let n = 0; n < values.length; n++) {
|
|
@@ -104,22 +110,23 @@ module.exports = (options) => {
|
|
|
104
110
|
return ret
|
|
105
111
|
})
|
|
106
112
|
)
|
|
113
|
+
}
|
|
107
114
|
: null
|
|
108
115
|
},
|
|
109
116
|
(arr, hash) => hash ?? hashTemplate(arr)
|
|
110
117
|
)
|
|
111
118
|
|
|
112
|
-
const compileArrayTemplate = (
|
|
113
|
-
if (!fp.isArray(
|
|
119
|
+
const compileArrayTemplate = (template) => {
|
|
120
|
+
if (!fp.isArray(template)) {
|
|
114
121
|
throw new Error('invalid argument')
|
|
115
122
|
}
|
|
116
|
-
const hash = hashTemplate(
|
|
117
|
-
return hash ? _compileArrayTemplate(
|
|
123
|
+
const hash = hashTemplate(template)
|
|
124
|
+
return hash ? _compileArrayTemplate(template, hash) : null
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
const _compileObjectTemplate = weakCache(
|
|
121
|
-
(
|
|
122
|
-
if (!fp.isPlainObject(
|
|
128
|
+
(template, hash) => {
|
|
129
|
+
if (!fp.isPlainObject(template)) {
|
|
123
130
|
throw new Error('invalid argument')
|
|
124
131
|
}
|
|
125
132
|
|
|
@@ -130,10 +137,10 @@ module.exports = (options) => {
|
|
|
130
137
|
let resolvers
|
|
131
138
|
let indices
|
|
132
139
|
|
|
133
|
-
const keys = Object.keys(
|
|
140
|
+
const keys = Object.keys(template)
|
|
134
141
|
|
|
135
142
|
for (let i = 0; i < keys.length; i++) {
|
|
136
|
-
const resolver = compileTemplate(
|
|
143
|
+
const resolver = compileTemplate(template[keys[i]])
|
|
137
144
|
if (resolver) {
|
|
138
145
|
resolvers ??= []
|
|
139
146
|
resolvers.push(resolver)
|
|
@@ -143,8 +150,14 @@ module.exports = (options) => {
|
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
return resolvers
|
|
146
|
-
? (args$) =>
|
|
147
|
-
|
|
153
|
+
? (obj, args$) => {
|
|
154
|
+
const len = resolvers.length
|
|
155
|
+
const values = new Array(len)
|
|
156
|
+
for (let n = 0; n < len; n++) {
|
|
157
|
+
values[n] = resolvers[n](obj[indices[n]], args$)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return rxjs.combineLatest(values).pipe(
|
|
148
161
|
rx.map((values) => {
|
|
149
162
|
const ret = { ...obj }
|
|
150
163
|
for (let n = 0; n < values.length; n++) {
|
|
@@ -153,23 +166,24 @@ module.exports = (options) => {
|
|
|
153
166
|
return ret
|
|
154
167
|
})
|
|
155
168
|
)
|
|
169
|
+
}
|
|
156
170
|
: null
|
|
157
171
|
},
|
|
158
172
|
(obj, hash) => hash ?? hashTemplate(obj)
|
|
159
173
|
)
|
|
160
174
|
|
|
161
|
-
const compileObjectTemplate = (
|
|
162
|
-
if (!fp.isPlainObject(
|
|
175
|
+
const compileObjectTemplate = (template) => {
|
|
176
|
+
if (!fp.isPlainObject(template)) {
|
|
163
177
|
throw new Error('invalid argument')
|
|
164
178
|
}
|
|
165
179
|
|
|
166
|
-
const hash = hashTemplate(
|
|
167
|
-
return hash ? _compileObjectTemplate(
|
|
180
|
+
const hash = hashTemplate(template)
|
|
181
|
+
return hash ? _compileObjectTemplate(template, hash) : null
|
|
168
182
|
}
|
|
169
183
|
|
|
170
184
|
const _compileStringTemplate = weakCache(
|
|
171
|
-
(
|
|
172
|
-
if (!fp.isString(
|
|
185
|
+
(template, hash) => {
|
|
186
|
+
if (!fp.isString(template)) {
|
|
173
187
|
throw new Error('invalid argument')
|
|
174
188
|
}
|
|
175
189
|
|
|
@@ -177,7 +191,7 @@ module.exports = (options) => {
|
|
|
177
191
|
return null
|
|
178
192
|
}
|
|
179
193
|
|
|
180
|
-
const match = inner(
|
|
194
|
+
const match = inner(template)
|
|
181
195
|
if (!match) {
|
|
182
196
|
return null
|
|
183
197
|
}
|
|
@@ -192,22 +206,22 @@ module.exports = (options) => {
|
|
|
192
206
|
const expr = compileExpression(body)
|
|
193
207
|
|
|
194
208
|
if (!pre && !post) {
|
|
195
|
-
return (args$) => expr(args$)
|
|
209
|
+
return (str, args$) => expr(args$)
|
|
196
210
|
}
|
|
197
211
|
|
|
198
|
-
return (args$) =>
|
|
212
|
+
return (str, args$) =>
|
|
199
213
|
expr(args$).pipe(rx.map((body) => `${pre}${stringify(body, type !== 'js')}${post}`))
|
|
200
214
|
},
|
|
201
215
|
(str, hash) => hash ?? hashTemplate(str)
|
|
202
216
|
)
|
|
203
217
|
|
|
204
|
-
const compileStringTemplate = (
|
|
205
|
-
if (!fp.isString(
|
|
218
|
+
const compileStringTemplate = (template) => {
|
|
219
|
+
if (!fp.isString(template)) {
|
|
206
220
|
throw new Error('invalid argument')
|
|
207
221
|
}
|
|
208
222
|
|
|
209
|
-
const hash = hashTemplate(
|
|
210
|
-
return hash ? _compileStringTemplate(
|
|
223
|
+
const hash = hashTemplate(template)
|
|
224
|
+
return hash ? _compileStringTemplate(template, hash) : null
|
|
211
225
|
}
|
|
212
226
|
|
|
213
227
|
function stringify(value, escape) {
|
|
@@ -243,7 +257,7 @@ module.exports = (options) => {
|
|
|
243
257
|
|
|
244
258
|
function onResolveTemplate(template, args$) {
|
|
245
259
|
try {
|
|
246
|
-
return compileTemplate(template)?.(args$) ?? rxjs.of(template)
|
|
260
|
+
return compileTemplate(template)?.(template, args$) ?? rxjs.of(template)
|
|
247
261
|
} catch (err) {
|
|
248
262
|
return rxjs.throwError(() => err)
|
|
249
263
|
}
|