@wener/utils 1.1.14 → 1.1.16
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/dist/cjs/{globalThis-ee7c1669.js → getGlobalThis-304f74e0.js} +2 -2
- package/dist/cjs/getGlobalThis-304f74e0.js.map +1 -0
- package/dist/cjs/index.cjs +16 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/server.cjs +1 -1
- package/dist/cjs/server.cjs.map +1 -1
- package/dist/esm/{globalThis-000611c3.js → getGlobalThis-b7ad0cf9.js} +2 -2
- package/dist/esm/getGlobalThis-b7ad0cf9.js.map +1 -0
- package/dist/esm/index.js +15 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/system/getGlobalThis-8951eb0e.js +2 -0
- package/dist/system/getGlobalThis-8951eb0e.js.map +1 -0
- package/dist/system/index.js +16 -5
- package/dist/system/index.js.map +1 -1
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/lib/asyncs/timeout.js.map +1 -1
- package/lib/browsers/download.js.map +1 -1
- package/lib/browsers/loaders.js.map +1 -1
- package/lib/crypto/getRandomValues.js +2 -1
- package/lib/crypto/getRandomValues.js.map +1 -1
- package/lib/crypto/randomUUID.js +2 -1
- package/lib/crypto/randomUUID.js.map +1 -1
- package/lib/fetch/createFetchWith.js +26 -0
- package/lib/fetch/createFetchWith.js.map +1 -0
- package/lib/fetch/createFetchWithLogging.js +21 -0
- package/lib/fetch/createFetchWithLogging.js.map +1 -0
- package/lib/fetch/dumpRequest.js +46 -0
- package/lib/fetch/dumpRequest.js.map +1 -0
- package/lib/fetch/dumpResponse.js +23 -0
- package/lib/fetch/dumpResponse.js.map +1 -0
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/io/ArrayBuffers.js +2 -2
- package/lib/io/ArrayBuffers.js.map +1 -1
- package/lib/io/isTransferable.js +2 -1
- package/lib/io/isTransferable.js.map +1 -1
- package/lib/isomorphics/structuredClone.js +2 -1
- package/lib/isomorphics/structuredClone.js.map +1 -1
- package/lib/logging/createLogger.js.map +1 -1
- package/lib/objects/get.js.map +1 -1
- package/lib/objects/set.js.map +1 -1
- package/lib/server.js +0 -2
- package/lib/server.js.map +1 -1
- package/lib/servers/createFetchWithProxy.js +1 -8
- package/lib/servers/createFetchWithProxy.js.map +1 -1
- package/lib/servers/createFetchWithProxyByUndici.js +25 -3
- package/lib/servers/createFetchWithProxyByUndici.js.map +1 -1
- package/lib/servers/polyfillCrypto.js +2 -1
- package/lib/servers/polyfillCrypto.js.map +1 -1
- package/lib/servers/polyfillJsDom.js +2 -1
- package/lib/servers/polyfillJsDom.js.map +1 -1
- package/package.json +35 -38
- package/src/asyncs/timeout.ts +3 -1
- package/src/browsers/download.ts +3 -1
- package/src/browsers/loaders.ts +6 -2
- package/src/crypto/getRandomValues.ts +2 -1
- package/src/crypto/randomUUID.ts +3 -1
- package/src/fetch/createFetchWith.ts +33 -0
- package/src/fetch/createFetchWithLogging.ts +22 -0
- package/src/fetch/dumpRequest.ts +51 -0
- package/src/fetch/dumpResponse.ts +28 -0
- package/src/fetch/index.ts +5 -1
- package/src/fetch/types.ts +1 -0
- package/src/index.ts +4 -2
- package/src/io/ArrayBuffers.ts +2 -2
- package/src/io/isTransferable.ts +3 -1
- package/src/isomorphics/structuredClone.ts +3 -1
- package/src/logging/createLogger.ts +15 -5
- package/src/objects/get.ts +1 -1
- package/src/objects/set.ts +1 -1
- package/src/server.ts +0 -2
- package/src/servers/createFetchWithProxy.ts +1 -10
- package/src/servers/createFetchWithProxyByNodeFetch.ts +3 -2
- package/src/servers/createFetchWithProxyByUndici.ts +35 -8
- package/src/servers/polyfillCrypto.ts +2 -1
- package/src/servers/polyfillJsDom.ts +3 -1
- package/src/servers/polyfillWebSocket.ts +2 -1
- package/dist/cjs/globalThis-ee7c1669.js.map +0 -1
- package/dist/esm/globalThis-000611c3.js.map +0 -1
- package/dist/system/globalThis-7bba6592.js +0 -2
- package/dist/system/globalThis-7bba6592.js.map +0 -1
- package/lib/isomorphics/globalThis.js +0 -6
- package/lib/isomorphics/globalThis.js.map +0 -1
- package/lib/servers/createFetchWithProxyByNodeFetch.js +0 -37
- package/lib/servers/createFetchWithProxyByNodeFetch.js.map +0 -1
- package/src/isomorphics/globalThis.ts +0 -3
- package/src/servers/createFetchWithLogger.ts +0 -75
package/lib/objects/set.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set.js","sources":["../../src/objects/set.ts"],"sourcesContent":["import type { ObjectKey, ObjectPath} from './parseObjectPath';\nimport { parseObjectPath } from './parseObjectPath';\n\n/**\n * Deep set\n *\n * {@link https://github.com/lukeed/dset dset}\n */\nexport function set<T extends object, V>(obj: T, key: ObjectKey | ObjectPath, val: V, merging = true) {\n const path = parseObjectPath(key);\n let i = 0;\n const len = path.length;\n let current: any = obj;\n let x, k;\n while (i < len) {\n k = path[i++];\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n // noinspection PointlessArithmeticExpressionJS\n current = current[k] =\n i === len\n ? merging\n ? merge(current[k], val)\n : val\n : typeof (x = current[k]) === typeof path\n ? x\n : // @ts-expect-error hacky type check\n path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.') // eslint-disable-line\n ? {}\n : [];\n }\n}\n\nexport function merge(a: any, b: any) {\n let k;\n if (typeof a === 'object' && typeof b === 'object') {\n if (Array.isArray(a) && Array.isArray(b)) {\n for (k = 0; k < b.length; k++) {\n a[k] = merge(a[k], b[k]);\n }\n } else {\n for (k in b) {\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n a[k] = merge(a[k], b[k]);\n }\n }\n return a;\n }\n return b;\n}\n"],"names":[],"mappings":";;AAQO,SAAS,GAAyB,CAAA,GAAA,EAAQ,GAA6B,EAAA,GAAA,EAAQ,UAAU,IAAM,EAAA;AACpG,EAAM,MAAA,IAAA,GAAO,gBA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CAAC,CAAC,CAAA,CAAA;AAAA,OACzB;AAAA,KACK,MAAA;AACL,MAAA,KAAK,KAAK,CAAG,EAAA;AACX,QAAA,IAAI,CAAM,KAAA,WAAA,IAAe,CAAM,KAAA,aAAA,IAAiB,CAAM,KAAA,WAAA;AAAa,UAAA,MAAA;AACnE,QAAE,CAAA,CAAA,CAAC,IAAI,KAAM,CAAA,CAAA,CAAE,CAAC,CAAG,EAAA,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AAAA,OACzB;AAAA,KACF;AACA,IAAO,OAAA,CAAA,CAAA;AAAA,GACT;AACA,EAAO,OAAA,CAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"set.js","sources":["../../src/objects/set.ts"],"sourcesContent":["import type { ObjectKey, ObjectPath } from './parseObjectPath';\nimport { parseObjectPath } from './parseObjectPath';\n\n/**\n * Deep set\n *\n * {@link https://github.com/lukeed/dset dset}\n */\nexport function set<T extends object, V>(obj: T, key: ObjectKey | ObjectPath, val: V, merging = true) {\n const path = parseObjectPath(key);\n let i = 0;\n const len = path.length;\n let current: any = obj;\n let x, k;\n while (i < len) {\n k = path[i++];\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n // noinspection PointlessArithmeticExpressionJS\n current = current[k] =\n i === len\n ? merging\n ? merge(current[k], val)\n : val\n : typeof (x = current[k]) === typeof path\n ? x\n : // @ts-expect-error hacky type check\n path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.') // eslint-disable-line\n ? {}\n : [];\n }\n}\n\nexport function merge(a: any, b: any) {\n let k;\n if (typeof a === 'object' && typeof b === 'object') {\n if (Array.isArray(a) && Array.isArray(b)) {\n for (k = 0; k < b.length; k++) {\n a[k] = merge(a[k], b[k]);\n }\n } else {\n for (k in b) {\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n a[k] = merge(a[k], b[k]);\n }\n }\n return a;\n }\n return b;\n}\n"],"names":[],"mappings":";;AAQO,SAAS,GAAyB,CAAA,G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AC7B,QAAE,CAAA,CAAA,CAAC,IAAI,KAAM,CAAA,CAAA,CAAE,CAAC,CAAG,EAAA,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AAAA,OACzB;AAAA,KACK,MAAA;AACL,MAAA,KAAK,KAAK,CAAG,EAAA;AACX,QAAA,IAAI,CAAM,KAAA,WAAA,IAAe,CAAM,KAAA,aAAA,IAAiB,CAAM,KAAA,WAAA;AAAa,UAAA,MAAA;AACnE,QAAE,CAAA,CAAA,CAAC,IAAI,KAAM,CAAA,CAAA,CAAE,CAAC,CAAG,EAAA,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AAAA,OACzB;AAAA,KACF;AACA,IAAO,OAAA,CAAA,CAAA;AAAA,GACT;AACA,EAAO,OAAA,CAAA,CAAA;AACT;;;;"}
|
package/lib/server.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { polyfillCrypto } from './servers/polyfillCrypto.js';
|
|
2
|
-
export { polyfillFetch } from './servers/polyfillFetch.js';
|
|
3
2
|
export { polyfillJsDom } from './servers/polyfillJsDom.js';
|
|
4
3
|
export { polyfillBrowser } from './servers/polyfillBrowser.js';
|
|
5
|
-
export { createFetchWithProxyByNodeFetch } from './servers/createFetchWithProxyByNodeFetch.js';
|
|
6
4
|
export { createFetchWithProxyByUndici } from './servers/createFetchWithProxyByUndici.js';
|
|
7
5
|
export { createFetchWithProxy } from './servers/createFetchWithProxy.js';
|
|
8
6
|
//# sourceMappingURL=server.js.map
|
package/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import '../isomorphics/globalThis.js';
|
|
2
|
-
import { createFetchWithProxyByNodeFetch } from './createFetchWithProxyByNodeFetch.js';
|
|
3
1
|
import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici.js';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
if (!proxy) {
|
|
7
|
-
return fetch || globalThis.fetch;
|
|
8
|
-
}
|
|
9
|
-
return parseInt(process.versions.node) >= 18 ? createFetchWithProxyByUndici({ proxy, fetch }) : createFetchWithProxyByNodeFetch({ proxy, fetch });
|
|
10
|
-
}
|
|
3
|
+
const createFetchWithProxy = createFetchWithProxyByUndici;
|
|
11
4
|
|
|
12
5
|
export { createFetchWithProxy };
|
|
13
6
|
//# sourceMappingURL=createFetchWithProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFetchWithProxy.js","sources":["../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"createFetchWithProxy.js","sources":["../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport const createFetchWithProxy = createFetchWithProxyByUndici;\n"],"names":[],"mappings":";;AAEO,MAAM,oBAAuB,GAAA;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
function createFetchWithProxyByUndici({
|
|
2
2
|
proxy,
|
|
3
|
+
token: _token,
|
|
3
4
|
fetch,
|
|
4
5
|
undici
|
|
5
6
|
} = {}) {
|
|
@@ -9,15 +10,36 @@ function createFetchWithProxyByUndici({
|
|
|
9
10
|
let agent;
|
|
10
11
|
return async (...args) => {
|
|
11
12
|
const init = args[1] || (args[1] = {});
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
{
|
|
14
|
+
const body = init.body;
|
|
15
|
+
if (typeof body === "object" && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {
|
|
16
|
+
init.duplex || (init.duplex = "half");
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
19
|
if (!agent) {
|
|
20
|
+
let uri = proxy;
|
|
21
|
+
let token = _token;
|
|
22
|
+
{
|
|
23
|
+
let u;
|
|
24
|
+
try {
|
|
25
|
+
u = new URL(proxy);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
}
|
|
28
|
+
if (!token && u && (u.username || u.password)) {
|
|
29
|
+
token = `Basic ${btoa(`${u.username || ""}:${u.password}`)}`;
|
|
30
|
+
u.username = "";
|
|
31
|
+
u.password = "";
|
|
32
|
+
uri = u.toString();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
16
35
|
undici || (undici = import('undici'));
|
|
17
36
|
const mod = await undici;
|
|
18
37
|
const ProxyAgent = mod.ProxyAgent;
|
|
19
38
|
fetch || (fetch = mod.fetch);
|
|
20
|
-
agent = new ProxyAgent(
|
|
39
|
+
agent = new ProxyAgent({
|
|
40
|
+
uri,
|
|
41
|
+
token
|
|
42
|
+
});
|
|
21
43
|
}
|
|
22
44
|
init.dispatcher = agent;
|
|
23
45
|
return await fetch(...args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFetchWithProxyByUndici.js","sources":["../../src/servers/createFetchWithProxyByUndici.ts"],"sourcesContent":["import { MaybePromise } from '
|
|
1
|
+
{"version":3,"file":"createFetchWithProxyByUndici.js","sources":["../../src/servers/createFetchWithProxyByUndici.ts"],"sourcesContent":["import { MaybePromise } from '../asyncs/MaybePromise';\nimport { FetchLike } from '../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n token: _token,\n fetch,\n undici,\n}: {\n proxy?: string;\n token?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n let agent: any;\n // https://github.com/nodejs/undici/blob/main/docs/best-practices/proxy.md\n return async (...args) => {\n const init = (args[1] ||= {}) as RequestInit & {\n duplex?: string;\n dispatcher?: any;\n };\n {\n const body = init.body;\n if (typeof body === 'object' && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {\n // request.duplex must be set if request.body is ReadableStream or Async Iterables\n init.duplex ||= 'half';\n }\n }\n if (!agent) {\n let uri = proxy;\n let token = _token;\n {\n let u: URL | undefined;\n try {\n u = new URL(proxy);\n } catch (e) {}\n if (!token && u && (u.username || u.password)) {\n token = `Basic ${btoa(`${u.username || ''}:${u.password}`)}`;\n u.username = '';\n u.password = '';\n uri = u.toString();\n }\n }\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent as new (_: any) => any;\n fetch ||= mod.fetch as FetchLike;\n // https://github.com/nodejs/undici/blob/main/docs/api/ProxyAgent.md\n agent = new ProxyAgent({\n uri,\n token,\n });\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n"],"names":[],"mappings":"AAGO,SAAS,4BAA6B,CAAA;AAAA,EAC3C,KAAA;AAAA,EACA,KAAO,EAAA,MAAA;AAAA,EACP,KAAA;AAAA,EACA,MAAA;AACF,CAAA,GAKI,EAAe,EAAA;AACjB,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,SAAS,UAAW,CAAA,KAAA,CAAA;AAAA,GAC7B;AACA,EAAI,IAAA,KAAA,CAAA;AAEJ,EAAA,OAAO,UAAU,IAAS,KAAA;AACxB,IAAM,MAAA,IAAA,GAAQ,sBAAY,EAAC,CAAA,CAAA;AAI3B,IAAA;AACE,MAAA,MAAM,OAAO,IAAK,CAAA,IAAA,CAAA;AAClB,MAAI,IAAA,OAAO,SAAS,QAAY,IAAA,IAAA,KAAS,gBAAgB,cAAkB,IAAA,MAAA,CAAO,iBAAiB,IAAO,CAAA,EAAA;AAExG,QAAK,IAAA,CAAA,MAAA,KAAL,KAAK,MAAW,GAAA,MAAA,CAAA,CAAA;AAAA,OAClB;AAAA,KACF;AACA,IAAA,IAAI,CAAC,KAAO,EAAA;AACV,MAAA,IAAI,GAAM,GAAA,KAAA,CAAA;AACV,MAAA,IAAI,KAAQ,GAAA,MAAA,CAAA;AACZ,MAAA;AACE,QAAI,IAAA,CAAA,CAAA;AACJ,QAAI,IAAA;AACF,UAAI,CAAA,GAAA,IAAI,IAAI,KAAK,CAAA,CAAA;AAAA,iBACV,CAAP,EAAA;AAAA,SAAW;AACb,QAAA,IAAI,CAAC,KAAS,IAAA,CAAA,KAAM,CAAE,CAAA,QAAA,IAAY,EAAE,QAAW,CAAA,EAAA;AAC7C,UAAA,KAAA,GAAQ,SAAS,IAAK,CAAA,CAAA,EAAG,EAAE,QAAY,IAAA,EAAA,CAAA,CAAA,EAAM,EAAE,QAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AACzD,UAAA,CAAA,CAAE,QAAW,GAAA,EAAA,CAAA;AACb,UAAA,CAAA,CAAE,QAAW,GAAA,EAAA,CAAA;AACb,UAAA,GAAA,GAAM,EAAE,QAAS,EAAA,CAAA;AAAA,SACnB;AAAA,OACF;AAEA,MAAA,MAAA,KAAA,MAAA,GAAW,OAAO,QAAQ,CAAA,CAAA,CAAA;AAC1B,MAAA,MAAM,MAAM,MAAM,MAAA,CAAA;AAClB,MAAA,MAAM,aAAa,GAAI,CAAA,UAAA,CAAA;AACvB,MAAA,KAAA,KAAA,KAAA,GAAU,GAAI,CAAA,KAAA,CAAA,CAAA;AAEd,MAAA,KAAA,GAAQ,IAAI,UAAW,CAAA;AAAA,QACrB,GAAA;AAAA,QACA,KAAA;AAAA,OACD,CAAA,CAAA;AAAA,KAGH;AACA,IAAA,IAAA,CAAK,UAAa,GAAA,KAAA,CAAA;AAClB,IAAO,OAAA,MAAM,KAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAAA,GAC7B,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfillCrypto.js","sources":["../../src/servers/polyfillCrypto.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"polyfillCrypto.js","sources":["../../src/servers/polyfillCrypto.ts"],"sourcesContent":["import { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillCrypto() {\n const globalThis = getGlobalThis();\n if ('crypto' in globalThis) {\n return false;\n }\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n"],"names":[],"mappings":";;AAEA,eAAsB,cAAiB,GAAA;AACrC,EAAA,MAAM,aAAa,aAAc,EAAA,CAAA;AACjC,EAAA,IAAI,YAAY,UAAY,EAAA;AAC1B,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAC,UAAmB,CAAA,MAAA,GAAA,CAAU,MAAM,OAAO,aAAa,CAAG,EAAA,SAAA,CAAA;AAC3D,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis.js';
|
|
2
2
|
|
|
3
3
|
async function polyfillJsDom() {
|
|
4
4
|
if (typeof window !== "undefined") {
|
|
5
5
|
return false;
|
|
6
6
|
}
|
|
7
|
+
const globalThis = getGlobalThis();
|
|
7
8
|
const { ResourceLoader, JSDOM } = await import('jsdom');
|
|
8
9
|
class Window {
|
|
9
10
|
constructor(opts = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfillJsDom.js","sources":["../../src/servers/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport {
|
|
1
|
+
{"version":3,"file":"polyfillJsDom.js","sources":["../../src/servers/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const globalThis = getGlobalThis();\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n // eslint-disable-next-line @typescript-eslint/no-extraneous-class\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => !protectedProperties.includes(prop))\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n"],"names":["window"],"mappings":";;AAGA,eAAsB,aAAgB,GAAA;AACpC,EAAI,IAAA,OAAO,WAAW,WAAa,EAAA;AACjC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA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IAAI,MAAO,CAAA,MAAA,CAAO,OAAO,EAAC,EAAG,eAAiB,EAAA,kBAAkB,CAAC,CAAA,CAAA;AAGhF,IAAO,MAAA,CAAA,mBAAA,CAAoBA,OAAM,CAAA,CAG9B,MAAO,CAAA,CAAC,SAAS,CAAC,mBAAA,CAAoB,QAAS,CAAA,IAAI,CAAC,CAAA,CAGpD,OAAO,CAAC,IAAA,KAAS,EAAE,UAAA,IAAc,UAAW,CAAA,OAAA,CAAQ,IAAI,CAAA,KAAM,CAAG,CAAA,CAAA,CAAA,CACjE,MAAO,CAAA,CAAC,IAAS,KAAA;AAChB,MAAA,QAAQ,IAAM;AAAA,QACZ,KAAK,WAAA;AACH,UAAO,OAAA,KAAA,CAAA;AAAA,OACX;AACA,MAAO,OAAA,IAAA,CAAA;AAAA,KACR,CAAA,CAGA,OAAQ,CAAA,CAAC,IAAS,KAAA;AAEjB,MAAO,MAAA,CAAA,cAAA,CAAe,YAAY,IAAM,EAAA;AAAA,QACtC,YAAc,EAAA,IAAA;AAAA,QACd,GAAA,EAAK,MAAMA,OAAAA,CAAO,IAAoB,CAAA;AAAA,OACvC,CAAA,CAAA;AAAA,KACF,CAAA,CAAA;AAEH,IAAOA,OAAAA,OAAAA,CAAAA;AAAA,GACT;AAEA,EAAW,UAAA,CAAA,EAAE,GAAK,EAAA,kBAAA,EAAoB,CAAA,CAAA;AACtC,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wener/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utils for daily use",
|
|
6
6
|
"repository": {
|
|
@@ -12,25 +12,6 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "dist/cjs/index.cjs",
|
|
14
14
|
"module": "lib/index.js",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./src/index.ts",
|
|
18
|
-
"typescript": "./src/index.ts",
|
|
19
|
-
"system": "./dist/system/index.js",
|
|
20
|
-
"import": "./lib/index.js"
|
|
21
|
-
},
|
|
22
|
-
"./types": {
|
|
23
|
-
"types": "./types.d.ts"
|
|
24
|
-
},
|
|
25
|
-
"./server": {
|
|
26
|
-
"types": "./src/server.ts",
|
|
27
|
-
"typescript": "./src/server.ts",
|
|
28
|
-
"system": "./dist/system/server.js",
|
|
29
|
-
"import": "./lib/server.js"
|
|
30
|
-
},
|
|
31
|
-
"./src/*": "./src/*",
|
|
32
|
-
"./package.json": "./package.json"
|
|
33
|
-
},
|
|
34
15
|
"types": "src/index.ts",
|
|
35
16
|
"files": [
|
|
36
17
|
"dist",
|
|
@@ -50,28 +31,26 @@
|
|
|
50
31
|
"template",
|
|
51
32
|
"lodash"
|
|
52
33
|
],
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@types/lodash": "^4.14.194",
|
|
55
|
-
"@types/ws": "^8.5.4",
|
|
56
|
-
"https-proxy-agent": "^5.0.1",
|
|
57
|
-
"lodash": "^4.17.21"
|
|
58
|
-
},
|
|
59
|
-
"publishConfig": {
|
|
60
|
-
"registry": "https://registry.npmjs.org",
|
|
61
|
-
"access": "public"
|
|
62
|
-
},
|
|
63
34
|
"peerDependencies": {
|
|
64
|
-
"https-proxy-agent": "*",
|
|
65
35
|
"undici": "*"
|
|
66
36
|
},
|
|
67
37
|
"peerDependenciesMeta": {
|
|
68
38
|
"undici": {
|
|
69
39
|
"optional": true
|
|
70
|
-
},
|
|
71
|
-
"https-proxy-agent": {
|
|
72
|
-
"optional": true
|
|
73
40
|
}
|
|
74
41
|
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/lodash": "^4.14.195",
|
|
44
|
+
"@types/ws": "^8.5.4",
|
|
45
|
+
"https-proxy-agent": "^7.0.0",
|
|
46
|
+
"lodash": "^4.17.21",
|
|
47
|
+
"node-fetch": "^3.3.1",
|
|
48
|
+
"undici": "^5.22.1"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"registry": "https://registry.npmjs.org",
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
75
54
|
"sideEffects": false,
|
|
76
55
|
"rollup": {
|
|
77
56
|
"input": [
|
|
@@ -79,17 +58,35 @@
|
|
|
79
58
|
"./src/server.ts"
|
|
80
59
|
],
|
|
81
60
|
"external": [
|
|
61
|
+
"crypto",
|
|
82
62
|
"jsdom",
|
|
83
|
-
"node-fetch"
|
|
63
|
+
"node-fetch",
|
|
64
|
+
"undici"
|
|
84
65
|
]
|
|
85
66
|
},
|
|
86
|
-
"dependencies": {
|
|
87
|
-
"undici": "^5.22.0"
|
|
88
|
-
},
|
|
89
67
|
"scripts": {
|
|
90
68
|
"build": "make prepublish",
|
|
91
69
|
"clean": "make clean",
|
|
92
70
|
"dev": "make dev",
|
|
93
71
|
"test": "make test"
|
|
72
|
+
},
|
|
73
|
+
"exports": {
|
|
74
|
+
".": {
|
|
75
|
+
"types": "./src/index.ts",
|
|
76
|
+
"typescript": "./src/index.ts",
|
|
77
|
+
"system": "./dist/system/index.js",
|
|
78
|
+
"import": "./lib/index.js"
|
|
79
|
+
},
|
|
80
|
+
"./types": {
|
|
81
|
+
"types": "./types.d.ts"
|
|
82
|
+
},
|
|
83
|
+
"./server": {
|
|
84
|
+
"types": "./src/server.ts",
|
|
85
|
+
"typescript": "./src/server.ts",
|
|
86
|
+
"system": "./dist/system/server.js",
|
|
87
|
+
"import": "./lib/server.js"
|
|
88
|
+
},
|
|
89
|
+
"./src/*": "./src/*",
|
|
90
|
+
"./package.json": "./package.json"
|
|
94
91
|
}
|
|
95
92
|
}
|
package/src/asyncs/timeout.ts
CHANGED
|
@@ -4,7 +4,9 @@ export function timeout<T = any>(v: Promise<T>, ms: number): Promise<T> {
|
|
|
4
4
|
return Promise.race([
|
|
5
5
|
v,
|
|
6
6
|
new Promise((_resolve, reject) => {
|
|
7
|
-
timeout = setTimeout(() => {
|
|
7
|
+
timeout = setTimeout(() => {
|
|
8
|
+
reject(error);
|
|
9
|
+
}, ms);
|
|
8
10
|
}),
|
|
9
11
|
]).then(
|
|
10
12
|
(v) => {
|
package/src/browsers/download.ts
CHANGED
|
@@ -26,7 +26,9 @@ export function download(filename: string, data: any, { type = 'application/octe
|
|
|
26
26
|
|
|
27
27
|
if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
|
|
28
28
|
a.href = URL.createObjectURL(data);
|
|
29
|
-
closer = () => {
|
|
29
|
+
closer = () => {
|
|
30
|
+
URL.revokeObjectURL(a.href);
|
|
31
|
+
};
|
|
30
32
|
} else {
|
|
31
33
|
console.error(`invalid download data`, data);
|
|
32
34
|
throw new Error(`can not download ${Object.getPrototypeOf(data)}`);
|
package/src/browsers/loaders.ts
CHANGED
|
@@ -4,13 +4,17 @@ function load(
|
|
|
4
4
|
reject: (v: any) => void,
|
|
5
5
|
options: { attributes: Record<string, string> } | undefined,
|
|
6
6
|
) {
|
|
7
|
-
el.onload = () => {
|
|
7
|
+
el.onload = () => {
|
|
8
|
+
resolve(el);
|
|
9
|
+
};
|
|
8
10
|
el.onerror = (e) => {
|
|
9
11
|
el.remove();
|
|
10
12
|
reject(e);
|
|
11
13
|
};
|
|
12
14
|
const { attributes = {} } = options || {};
|
|
13
|
-
Object.entries(attributes).forEach(([k, v]) => {
|
|
15
|
+
Object.entries(attributes).forEach(([k, v]) => {
|
|
16
|
+
el.setAttribute(k, v);
|
|
17
|
+
});
|
|
14
18
|
|
|
15
19
|
document.head.appendChild(el);
|
|
16
20
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
2
2
|
import type { TypedArray } from '../io/ArrayBuffers';
|
|
3
|
-
import {
|
|
3
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
4
4
|
import { getNodeCrypto } from './getNodeCrypto';
|
|
5
5
|
|
|
6
|
+
const globalThis = getGlobalThis();
|
|
6
7
|
export let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float64Array>>(typedArray: T) => T =
|
|
7
8
|
globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) ||
|
|
8
9
|
(globalThis as any).msCrypto?.getRandomValues?.bind((globalThis as any).msCrypto) ||
|
package/src/crypto/randomUUID.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MaybePromise } from '../asyncs/MaybePromise';
|
|
2
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
3
|
+
import { type FetchLike } from './types';
|
|
4
|
+
|
|
5
|
+
export function createFetchWith({
|
|
6
|
+
fetch = getGlobalThis().fetch,
|
|
7
|
+
onRequest = (ctx) => ctx.next(ctx.url, ctx.req),
|
|
8
|
+
onResponse = (ctx) => ctx.res,
|
|
9
|
+
}: {
|
|
10
|
+
fetch?: FetchLike;
|
|
11
|
+
onRequest?: (ctx: {
|
|
12
|
+
url: string;
|
|
13
|
+
req: RequestInit;
|
|
14
|
+
next: (url: string, req: RequestInit) => Promise<Response>;
|
|
15
|
+
}) => MaybePromise<Response | void>;
|
|
16
|
+
onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;
|
|
17
|
+
}) {
|
|
18
|
+
return async (urlOrRequest: string | Request, init?: RequestInit & { fetch?: FetchLike }) => {
|
|
19
|
+
const url = String(urlOrRequest);
|
|
20
|
+
let req = init || {};
|
|
21
|
+
const nextFetch = req.fetch || fetch;
|
|
22
|
+
const res =
|
|
23
|
+
(await onRequest({
|
|
24
|
+
url,
|
|
25
|
+
req,
|
|
26
|
+
next: (url, init) => {
|
|
27
|
+
req = init;
|
|
28
|
+
return nextFetch(url, init);
|
|
29
|
+
},
|
|
30
|
+
})) ?? (await nextFetch(url, init));
|
|
31
|
+
return onResponse({ url, req, res });
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createFetchWith } from './createFetchWith';
|
|
2
|
+
import { dumpRequest } from './dumpRequest';
|
|
3
|
+
import { dumpResponse } from './dumpResponse';
|
|
4
|
+
import { type FetchLike } from './types';
|
|
5
|
+
|
|
6
|
+
export function createFetchWithLogging({
|
|
7
|
+
fetch,
|
|
8
|
+
log = console.log,
|
|
9
|
+
}: {
|
|
10
|
+
fetch?: FetchLike;
|
|
11
|
+
log?: (s: string) => void;
|
|
12
|
+
} = {}): FetchLike {
|
|
13
|
+
return createFetchWith({
|
|
14
|
+
fetch,
|
|
15
|
+
onRequest: ({ url, req }) => {
|
|
16
|
+
void dumpRequest({ url, req, log });
|
|
17
|
+
},
|
|
18
|
+
onResponse: ({ url, req, res }) => {
|
|
19
|
+
return dumpResponse({ url, req, res, log });
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function dumpRequest({
|
|
2
|
+
url,
|
|
3
|
+
req = {},
|
|
4
|
+
log = console.log,
|
|
5
|
+
}: {
|
|
6
|
+
url: string;
|
|
7
|
+
req?: RequestInit;
|
|
8
|
+
log?: (s: string) => void;
|
|
9
|
+
}) {
|
|
10
|
+
const { method = 'GET' } = req;
|
|
11
|
+
let out = `-> ${method} ${url}
|
|
12
|
+
${Array.from(new Headers(req.headers).entries())
|
|
13
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
14
|
+
.join('\n')}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
let done: Promise<string> | undefined;
|
|
18
|
+
if (req.body) {
|
|
19
|
+
if (req.body instanceof ReadableStream) {
|
|
20
|
+
const [a, b] = req.body.tee();
|
|
21
|
+
req.body = a;
|
|
22
|
+
const signal = req.signal;
|
|
23
|
+
done = Promise.resolve().then(async () => {
|
|
24
|
+
const reader = b.getReader();
|
|
25
|
+
log(out);
|
|
26
|
+
while (true) {
|
|
27
|
+
if (signal?.aborted) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let { done, value } = await reader.read();
|
|
32
|
+
value instanceof Uint8Array && (value = new TextDecoder().decode(value));
|
|
33
|
+
out += value;
|
|
34
|
+
log(value);
|
|
35
|
+
if (!done) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// maybe for archive
|
|
40
|
+
out += `\n`;
|
|
41
|
+
return out;
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
out += `
|
|
45
|
+
${req.body}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
log(out);
|
|
49
|
+
}
|
|
50
|
+
return done || Promise.resolve(out);
|
|
51
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export async function dumpResponse({
|
|
2
|
+
res,
|
|
3
|
+
url,
|
|
4
|
+
req,
|
|
5
|
+
log = console.log,
|
|
6
|
+
}: {
|
|
7
|
+
res: Response;
|
|
8
|
+
url: string;
|
|
9
|
+
req: RequestInit;
|
|
10
|
+
log?: (s: string) => void;
|
|
11
|
+
}) {
|
|
12
|
+
let out = `<- ${res.status} ${res.statusText} ${req.method} ${url}
|
|
13
|
+
${Array.from(res.headers.entries())
|
|
14
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
15
|
+
.join('\n')}
|
|
16
|
+
`;
|
|
17
|
+
let contentType = res.headers.get('content-type');
|
|
18
|
+
// TODO text/event-stream
|
|
19
|
+
if (contentType?.includes('application/json') || contentType?.includes('text/plain')) {
|
|
20
|
+
const body = await res.text();
|
|
21
|
+
out += `\n${body}\n`;
|
|
22
|
+
res = new Response(body, res);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log(out);
|
|
26
|
+
|
|
27
|
+
return res;
|
|
28
|
+
}
|
package/src/fetch/index.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type * from './types';
|
|
2
|
+
export { createFetchWith } from './createFetchWith';
|
|
3
|
+
export { createFetchWithLogging } from './createFetchWithLogging';
|
|
4
|
+
export { dumpRequest } from './dumpRequest';
|
|
5
|
+
export { dumpResponse } from './dumpResponse';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type FetchLike = (url: string | Request, init?: RequestInit) => Promise<Response>;
|
package/src/index.ts
CHANGED
|
@@ -72,8 +72,9 @@ export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
|
|
|
72
72
|
|
|
73
73
|
// polyfills
|
|
74
74
|
export { getGlobalThis } from './isomorphics/getGlobalThis';
|
|
75
|
-
export { globalThis } from './isomorphics/globalThis';
|
|
76
75
|
export { structuredClone } from './isomorphics/structuredClone';
|
|
76
|
+
// should not export as sideEffect
|
|
77
|
+
// export { globalThis } from './isomorphics/globalThis';
|
|
77
78
|
|
|
78
79
|
// crypto
|
|
79
80
|
export { randomUUID } from './crypto/randomUUID';
|
|
@@ -86,7 +87,8 @@ export { PEM } from './crypto/pem/pem';
|
|
|
86
87
|
// misc
|
|
87
88
|
export { createRandom } from './maths/random';
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
// network
|
|
91
|
+
export { type FetchLike, createFetchWith, createFetchWithLogging, dumpResponse, dumpRequest } from './fetch';
|
|
90
92
|
|
|
91
93
|
// bundled
|
|
92
94
|
export { default as ms } from './libs/ms';
|
package/src/io/ArrayBuffers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
2
2
|
import { classOf } from '../langs/classOf';
|
|
3
3
|
import { decodeBase64ToArrayBuffer, encodeArrayBufferToBase64 } from './base64';
|
|
4
4
|
import { isBuffer } from './isBuffer';
|
|
@@ -74,7 +74,7 @@ export class ArrayBuffers {
|
|
|
74
74
|
|
|
75
75
|
static isNativeBufferAvailable() {
|
|
76
76
|
// eslint-disable-next-line no-return-assign
|
|
77
|
-
return (this.#isBufferAvailable ??= !(
|
|
77
|
+
return (this.#isBufferAvailable ??= !(getGlobalThis().Buffer as any)?.isPollyfill?.());
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
static isNativeBufferAllowed() {
|
package/src/io/isTransferable.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint no-proto:0 */
|
|
2
2
|
import { classOf } from '../langs/classOf';
|
|
3
|
-
import {
|
|
3
|
+
import { getGlobalThis } from './getGlobalThis';
|
|
4
|
+
|
|
5
|
+
const globalThis = getGlobalThis();
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Clone an object using structured cloning algorithm
|
|
@@ -12,11 +12,21 @@ export function createLogger(
|
|
|
12
12
|
context: object = {},
|
|
13
13
|
): LoggerWithChild {
|
|
14
14
|
return {
|
|
15
|
-
trace: (...values) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
trace: (...values) => {
|
|
16
|
+
write({ ...context, level: 'trace', values });
|
|
17
|
+
},
|
|
18
|
+
debug: (...values) => {
|
|
19
|
+
write({ ...context, level: 'debug', values });
|
|
20
|
+
},
|
|
21
|
+
info: (...values) => {
|
|
22
|
+
write({ ...context, level: 'info', values });
|
|
23
|
+
},
|
|
24
|
+
warn: (...values) => {
|
|
25
|
+
write({ ...context, level: 'warn', values });
|
|
26
|
+
},
|
|
27
|
+
error: (...values) => {
|
|
28
|
+
write({ ...context, level: 'error', values });
|
|
29
|
+
},
|
|
20
30
|
child: (ctx) => createLogger(write, { ...context, ...ctx }),
|
|
21
31
|
};
|
|
22
32
|
}
|
package/src/objects/get.ts
CHANGED
package/src/objects/set.ts
CHANGED
package/src/server.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { polyfillCrypto } from './servers/polyfillCrypto';
|
|
2
|
-
export { polyfillFetch } from './servers/polyfillFetch';
|
|
3
2
|
export { polyfillJsDom } from './servers/polyfillJsDom';
|
|
4
3
|
export { polyfillBrowser } from './servers/polyfillBrowser';
|
|
5
|
-
export { createFetchWithProxyByNodeFetch } from './servers/createFetchWithProxyByNodeFetch';
|
|
6
4
|
export { createFetchWithProxyByUndici } from './servers/createFetchWithProxyByUndici';
|
|
7
5
|
export { createFetchWithProxy } from './servers/createFetchWithProxy';
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import { FetchLike } from '../fetch';
|
|
2
|
-
import { createFetchWithProxyByNodeFetch } from '../server';
|
|
3
1
|
import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';
|
|
4
2
|
|
|
5
|
-
export
|
|
6
|
-
if (!proxy) {
|
|
7
|
-
return fetch || globalThis.fetch;
|
|
8
|
-
}
|
|
9
|
-
return parseInt(process.versions.node) >= 18
|
|
10
|
-
? createFetchWithProxyByUndici({ proxy, fetch })
|
|
11
|
-
: createFetchWithProxyByNodeFetch({ proxy, fetch });
|
|
12
|
-
}
|
|
3
|
+
export const createFetchWithProxy = createFetchWithProxyByUndici;
|