@nxtedition/lib 14.0.9 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "14.0.9",
3
+ "version": "14.0.11",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "files": [
@@ -71,8 +71,8 @@ module.exports = (options) => {
71
71
  }
72
72
 
73
73
  const _compileArrayTemplate = weakCache(
74
- (arr, hash) => {
75
- if (!fp.isArray(arr)) {
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 < arr.length; i++) {
87
- const resolver = compileTemplate(arr[i])
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
- rxjs.combineLatest(resolvers.map((resolver) => resolver(args$))).pipe(
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 = (arr) => {
113
- if (!fp.isArray(arr)) {
119
+ const compileArrayTemplate = (template) => {
120
+ if (!fp.isArray(template)) {
114
121
  throw new Error('invalid argument')
115
122
  }
116
- const hash = hashTemplate(arr)
117
- return hash ? _compileArrayTemplate(arr, hash) : null
123
+ const hash = hashTemplate(template)
124
+ return hash ? _compileArrayTemplate(template, hash) : null
118
125
  }
119
126
 
120
127
  const _compileObjectTemplate = weakCache(
121
- (obj, hash) => {
122
- if (!fp.isPlainObject(obj)) {
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(obj)
140
+ const keys = Object.keys(template)
134
141
 
135
142
  for (let i = 0; i < keys.length; i++) {
136
- const resolver = compileTemplate(obj[keys[i]])
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
- rxjs.combineLatest(resolvers.map((resolver) => resolver(args$))).pipe(
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 = (obj) => {
162
- if (!fp.isPlainObject(obj)) {
175
+ const compileObjectTemplate = (template) => {
176
+ if (!fp.isPlainObject(template)) {
163
177
  throw new Error('invalid argument')
164
178
  }
165
179
 
166
- const hash = hashTemplate(obj)
167
- return hash ? _compileObjectTemplate(obj, hash) : null
180
+ const hash = hashTemplate(template)
181
+ return hash ? _compileObjectTemplate(template, hash) : null
168
182
  }
169
183
 
170
184
  const _compileStringTemplate = weakCache(
171
- (str, hash) => {
172
- if (!fp.isString(str)) {
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(str)
194
+ const match = inner(template)
181
195
  if (!match) {
182
196
  return null
183
197
  }
@@ -192,27 +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$) =>
199
- expr(args$).pipe(
200
- rx.switchMap((body) => {
201
- const str = `${pre}${stringify(body, type !== 'js')}${post}`
202
- return compileStringTemplate(str)?.(args$) ?? rxjs.of(str)
203
- })
204
- )
212
+ return (str, args$) =>
213
+ expr(args$).pipe(rx.map((body) => `${pre}${stringify(body, type !== 'js')}${post}`))
205
214
  },
206
215
  (str, hash) => hash ?? hashTemplate(str)
207
216
  )
208
217
 
209
- const compileStringTemplate = (obj) => {
210
- if (!fp.isString(obj)) {
218
+ const compileStringTemplate = (template) => {
219
+ if (!fp.isString(template)) {
211
220
  throw new Error('invalid argument')
212
221
  }
213
222
 
214
- const hash = hashTemplate(obj)
215
- return hash ? _compileStringTemplate(obj, hash) : null
223
+ const hash = hashTemplate(template)
224
+ return hash ? _compileStringTemplate(template, hash) : null
216
225
  }
217
226
 
218
227
  function stringify(value, escape) {
@@ -248,7 +257,7 @@ module.exports = (options) => {
248
257
 
249
258
  function onResolveTemplate(template, args$) {
250
259
  try {
251
- return compileTemplate(template)?.(args$) ?? rxjs.of(template)
260
+ return compileTemplate(template)?.(template, args$) ?? rxjs.of(template)
252
261
  } catch (err) {
253
262
  return rxjs.throwError(() => err)
254
263
  }