@nxtedition/nxt-undici 6.2.35 → 6.3.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/lib/index.js +2 -0
- package/lib/interceptor/cache.js +1 -1
- package/lib/interceptor/query.js +25 -0
- package/lib/sqlite-cache-store.js +1 -1
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { SqliteCacheStore } from './sqlite-cache-store.js'
|
|
|
6
6
|
const dispatcherCache = new WeakMap()
|
|
7
7
|
|
|
8
8
|
export const interceptors = {
|
|
9
|
+
query: (await import('./interceptor/query.js')).default,
|
|
9
10
|
requestBodyFactory: (await import('./interceptor/request-body-factory.js')).default,
|
|
10
11
|
responseError: (await import('./interceptor/response-error.js')).default,
|
|
11
12
|
responseRetry: (await import('./interceptor/response-retry.js')).default,
|
|
@@ -92,6 +93,7 @@ function wrapDispatch(dispatcher) {
|
|
|
92
93
|
interceptors.log({ bindings: { intercept: 'downstream' } }),
|
|
93
94
|
interceptors.requestId(),
|
|
94
95
|
interceptors.responseError(),
|
|
96
|
+
interceptors.query(),
|
|
95
97
|
(dispatch) => (opts, handler) => {
|
|
96
98
|
const headers = parseHeaders(opts.headers)
|
|
97
99
|
|
package/lib/interceptor/cache.js
CHANGED
|
@@ -4,7 +4,7 @@ import { SqliteCacheStore } from '../sqlite-cache-store.js'
|
|
|
4
4
|
|
|
5
5
|
const DEFAULT_STORE = new SqliteCacheStore({ location: ':memory:' })
|
|
6
6
|
const DEFAULT_MAX_ENTRY_SIZE = 128 * 1024
|
|
7
|
-
const DEFAULT_MAX_ENTRY_TTL =
|
|
7
|
+
const DEFAULT_MAX_ENTRY_TTL = 24 * 3600
|
|
8
8
|
const NOOP = () => {}
|
|
9
9
|
|
|
10
10
|
class CacheHandler extends DecoratorHandler {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { stringify } from 'fast-querystring'
|
|
2
|
+
|
|
3
|
+
export default () => (dispatch) => (opts, handler) => {
|
|
4
|
+
if (!opts.query) {
|
|
5
|
+
return dispatch(opts, handler)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const { query, path, ...rest } = opts
|
|
9
|
+
|
|
10
|
+
dispatch({ ...rest, path: serializePathWithQuery(path, query) })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function serializePathWithQuery(url, queryParams) {
|
|
14
|
+
if (url.includes('?') || url.includes('#')) {
|
|
15
|
+
throw new Error('Query params cannot be passed when url already contains "?" or "#".')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const stringified = stringify(queryParams)
|
|
19
|
+
|
|
20
|
+
if (stringified) {
|
|
21
|
+
url += '?' + stringified
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return url
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/nxt-undici",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@nxtedition/undici": "^11.0.0",
|
|
13
13
|
"cache-control-parser": "^2.0.6",
|
|
14
|
+
"fast-querystring": "^1.1.2",
|
|
14
15
|
"http-errors": "^2.0.0"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|