@nxtedition/lib 15.0.32 → 15.0.34
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/lib/undici/index.js +8 -2
- package/package.json +1 -1
- package/util/template/index.js +11 -6
package/lib/undici/index.js
CHANGED
|
@@ -77,15 +77,21 @@ const dispatchers = {
|
|
|
77
77
|
cache: require('./interceptor/cache.js'),
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
async function request(url, opts
|
|
80
|
+
async function request(url, opts) {
|
|
81
81
|
if (typeof url === 'string') {
|
|
82
82
|
url = new URL(url)
|
|
83
83
|
} else if (url instanceof URL) {
|
|
84
84
|
// Do nothing...
|
|
85
|
+
} else if (typeof url.origin === 'string' && typeof (url.path ?? url.pathname) === 'string') {
|
|
86
|
+
// Do nothing...
|
|
85
87
|
} else {
|
|
86
88
|
throw new Error('missing url')
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
if (opts == null && typeof url === 'object' && url != null) {
|
|
92
|
+
opts = url
|
|
93
|
+
}
|
|
94
|
+
|
|
89
95
|
const method = opts.method ?? (opts.body ? 'POST' : 'GET')
|
|
90
96
|
const idempotent = opts.idempotent ?? (method === 'GET' || method === 'HEAD')
|
|
91
97
|
|
|
@@ -117,7 +123,7 @@ async function request(url, opts = {}) {
|
|
|
117
123
|
...headers,
|
|
118
124
|
},
|
|
119
125
|
origin: url.origin,
|
|
120
|
-
path: url.search ? `${url.pathname}${url.search ?? ''}` : url.pathname,
|
|
126
|
+
path: url.path ? url.path : url.search ? `${url.pathname}${url.search ?? ''}` : url.pathname,
|
|
121
127
|
reset: opts.reset ?? false,
|
|
122
128
|
headersTimeout: opts.headersTimeout,
|
|
123
129
|
bodyTimeout: opts.bodyTimeout,
|
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)
|
|
@@ -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)
|
|
@@ -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)
|
|
@@ -222,9 +222,14 @@ module.exports = ({ ds, proxify }) => {
|
|
|
222
222
|
(template, hash) => hash,
|
|
223
223
|
)
|
|
224
224
|
|
|
225
|
-
function
|
|
225
|
+
function _compileTemplate(template) {
|
|
226
226
|
const hash = hashTemplate(template)
|
|
227
|
-
const resolver = hash ?
|
|
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)
|
|
228
233
|
return resolver ? (args$) => resolver(template, args$) : null
|
|
229
234
|
}
|
|
230
235
|
|
|
@@ -234,7 +239,7 @@ module.exports = ({ ds, proxify }) => {
|
|
|
234
239
|
|
|
235
240
|
function onResolveTemplate(template, args$) {
|
|
236
241
|
try {
|
|
237
|
-
return
|
|
242
|
+
return _compileTemplate(template)?.(template, args$) ?? rxjs.of(template)
|
|
238
243
|
} catch (err) {
|
|
239
244
|
return rxjs.throwError(() => err)
|
|
240
245
|
}
|