@nxtedition/nxt-undici 6.2.30 → 6.2.32
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 +23 -1
- package/lib/sqlite-cache-store.js +5 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -26,7 +26,29 @@ export { parseHeaders } from './utils.js'
|
|
|
26
26
|
export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from '@nxtedition/undici'
|
|
27
27
|
|
|
28
28
|
function defaultLookup(origin, opts, callback) {
|
|
29
|
-
|
|
29
|
+
try {
|
|
30
|
+
if (Array.isArray(origin)) {
|
|
31
|
+
origin = origin[Math.floor(Math.random() * origin.length)]
|
|
32
|
+
} else if (origin != null && typeof origin === 'object') {
|
|
33
|
+
const protocol = origin.protocol || 'http:'
|
|
34
|
+
|
|
35
|
+
let host = origin.host
|
|
36
|
+
if (!host && origin.hostname) {
|
|
37
|
+
const port = origin.port || (protocol === 'https:' ? 443 : 80)
|
|
38
|
+
host = `${origin.hostname}:${port}`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!host) {
|
|
42
|
+
throw new Error('invalid url')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
origin = `${protocol}//${host}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
callback(null, origin)
|
|
49
|
+
} catch (err) {
|
|
50
|
+
callback(err, null)
|
|
51
|
+
}
|
|
30
52
|
}
|
|
31
53
|
|
|
32
54
|
export function compose(...interceptors) {
|
|
@@ -57,6 +57,11 @@ export class SqliteCacheStore {
|
|
|
57
57
|
this.#db = new DatabaseSync(opts?.location ?? ':memory:')
|
|
58
58
|
|
|
59
59
|
this.#db.exec(`
|
|
60
|
+
PRAGMA journal_mode = WAL;
|
|
61
|
+
PRAGMA synchronous = NORMAL;
|
|
62
|
+
PRAGMA temp_store = memory;
|
|
63
|
+
PRAGMA optimize;
|
|
64
|
+
|
|
60
65
|
CREATE TABLE IF NOT EXISTS cacheInterceptorV${VERSION} (
|
|
61
66
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
62
67
|
url TEXT NOT NULL,
|