@nxtedition/lib 14.3.1 → 14.3.3
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/http.js +7 -3
- package/package.json +1 -1
- package/util/template/index.js +17 -11
package/http.js
CHANGED
|
@@ -135,6 +135,8 @@ module.exports.request = async function request(ctx, next) {
|
|
|
135
135
|
reqLogger.warn('request failed')
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
reqLogger.debug('request ended')
|
|
139
|
+
|
|
138
140
|
res.end()
|
|
139
141
|
} else {
|
|
140
142
|
if (req.aborted || err.name === 'AbortError') {
|
|
@@ -145,6 +147,8 @@ module.exports.request = async function request(ctx, next) {
|
|
|
145
147
|
reqLogger.error('request error')
|
|
146
148
|
}
|
|
147
149
|
|
|
150
|
+
reqLogger.debug('request destroyed')
|
|
151
|
+
|
|
148
152
|
res.destroy()
|
|
149
153
|
}
|
|
150
154
|
}
|
|
@@ -206,7 +210,7 @@ module.exports.createServer = function (options, ctx, middleware) {
|
|
|
206
210
|
requestTimeout: 0,
|
|
207
211
|
...options,
|
|
208
212
|
},
|
|
209
|
-
(req, res) => middleware({ req, res, ...factory() })
|
|
213
|
+
(req, res) => middleware({ req, res, ...factory() }),
|
|
210
214
|
)
|
|
211
215
|
|
|
212
216
|
server.setTimeout(2 * 60e3)
|
|
@@ -256,7 +260,7 @@ module.exports.upgrade = async function upgrade(ctx, next) {
|
|
|
256
260
|
.on('error', reject)
|
|
257
261
|
.on('timeout', () => {
|
|
258
262
|
reject(new createError.RequestTimeout())
|
|
259
|
-
})
|
|
263
|
+
}),
|
|
260
264
|
),
|
|
261
265
|
new Promise((resolve, reject) =>
|
|
262
266
|
socket
|
|
@@ -264,7 +268,7 @@ module.exports.upgrade = async function upgrade(ctx, next) {
|
|
|
264
268
|
.on('error', reject)
|
|
265
269
|
.on('timeout', () => {
|
|
266
270
|
reject(new createError.RequestTimeout())
|
|
267
|
-
})
|
|
271
|
+
}),
|
|
268
272
|
),
|
|
269
273
|
next(),
|
|
270
274
|
])
|
package/package.json
CHANGED
package/util/template/index.js
CHANGED
|
@@ -84,7 +84,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
84
84
|
let indices
|
|
85
85
|
|
|
86
86
|
for (let i = 0; i < template.length; i++) {
|
|
87
|
-
const resolver =
|
|
87
|
+
const resolver = _compileTemplate(template[i])
|
|
88
88
|
if (resolver) {
|
|
89
89
|
resolvers ??= []
|
|
90
90
|
resolvers.push(resolver)
|
|
@@ -108,7 +108,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
108
108
|
ret[indices[n]] = values[n]
|
|
109
109
|
}
|
|
110
110
|
return ret
|
|
111
|
-
})
|
|
111
|
+
}),
|
|
112
112
|
)
|
|
113
113
|
}
|
|
114
114
|
: null
|
|
@@ -121,7 +121,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
121
121
|
const keys = Object.keys(template)
|
|
122
122
|
|
|
123
123
|
for (let i = 0; i < keys.length; i++) {
|
|
124
|
-
const resolver =
|
|
124
|
+
const resolver = _compileTemplate(template[keys[i]])
|
|
125
125
|
if (resolver) {
|
|
126
126
|
resolvers ??= []
|
|
127
127
|
resolvers.push(resolver)
|
|
@@ -145,7 +145,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
145
145
|
ret[indices[n]] = values[n]
|
|
146
146
|
}
|
|
147
147
|
return ret
|
|
148
|
-
})
|
|
148
|
+
}),
|
|
149
149
|
)
|
|
150
150
|
}
|
|
151
151
|
: null
|
|
@@ -174,7 +174,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
174
174
|
compileStringTemplate(post)?.(str, args$) ?? rxjs.of(post),
|
|
175
175
|
])
|
|
176
176
|
.pipe(
|
|
177
|
-
rx.map(([pre, body, post]) => (pre || post ? `${pre}${stringify(body)}${post}` : body))
|
|
177
|
+
rx.map(([pre, body, post]) => (pre || post ? `${pre}${stringify(body)}${post}` : body)),
|
|
178
178
|
)
|
|
179
179
|
} else if (type === 'nxt') {
|
|
180
180
|
const expr = compilers.nxt(body)
|
|
@@ -185,7 +185,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
185
185
|
|
|
186
186
|
return (str, args$) =>
|
|
187
187
|
expr(args$).pipe(
|
|
188
|
-
rx.switchMap((body) => onResolveTemplate(`${pre}${stringify(body, true)}${post}`, args$))
|
|
188
|
+
rx.switchMap((body) => onResolveTemplate(`${pre}${stringify(body, true)}${post}`, args$)),
|
|
189
189
|
)
|
|
190
190
|
} else {
|
|
191
191
|
throw new Error('unknown expression type: ' + type)
|
|
@@ -207,7 +207,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
207
207
|
return typeof val === 'string' && val.indexOf('{{') !== -1
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
const
|
|
210
|
+
const _compileTemplateCache = weakCache(
|
|
211
211
|
(template) => {
|
|
212
212
|
if (fp.isPlainObject(template)) {
|
|
213
213
|
return compileObjectTemplate(template)
|
|
@@ -219,12 +219,18 @@ module.exports = ({ ds, proxify }) => {
|
|
|
219
219
|
return null
|
|
220
220
|
}
|
|
221
221
|
},
|
|
222
|
-
(template, hash) => hash
|
|
222
|
+
(template, hash) => hash,
|
|
223
223
|
)
|
|
224
224
|
|
|
225
|
-
function
|
|
225
|
+
function _compileTemplate(template) {
|
|
226
226
|
const hash = hashTemplate(template)
|
|
227
|
-
|
|
227
|
+
const resolver = hash ? _compileTemplateCache(template, hash) : null
|
|
228
|
+
return resolver // ? (args$) => resolver(template, args$) : null
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function compileTemplate(template) {
|
|
232
|
+
const resolver = _compileTemplate(template)
|
|
233
|
+
return resolver ? (args$) => resolver(template, args$) : null
|
|
228
234
|
}
|
|
229
235
|
|
|
230
236
|
async function resolveTemplate(template, args$, options) {
|
|
@@ -233,7 +239,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
233
239
|
|
|
234
240
|
function onResolveTemplate(template, args$) {
|
|
235
241
|
try {
|
|
236
|
-
return
|
|
242
|
+
return _compileTemplate(template)?.(template, args$) ?? rxjs.of(template)
|
|
237
243
|
} catch (err) {
|
|
238
244
|
return rxjs.throwError(() => err)
|
|
239
245
|
}
|