@indra211/exios 3.1.0 → 3.1.1
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/README.md +8 -3
- package/dist/index.cjs +73 -8
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +64 -56
- package/dist/index.js +73 -8
- package/dist/index.node.cjs +73 -8
- package/dist/index.node.js +73 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -196,6 +196,10 @@ try {
|
|
|
196
196
|
}
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
+
`isExiosError` narrows the error type. Pass your API's error body type to type `err.response.data`: `if (isExiosError<{ message: string }>(err)) err.response?.data.message`.
|
|
200
|
+
|
|
201
|
+
Every option accepts an explicit `undefined`, meaning "use the default". This also type-checks with TypeScript's `exactOptionalPropertyTypes`, so `retry: { retries: process.env.RETRIES ? Number(process.env.RETRIES) : undefined }` works.
|
|
202
|
+
|
|
199
203
|
`meta.url` is `baseURL + url` without the serialized `params`. A query string you wrote into `url` yourself is kept.
|
|
200
204
|
|
|
201
205
|
`error.toJSON()` (and so `JSON.stringify(error)`) is **log-safe**: the values of `Authorization`, `Proxy-Authorization`, `Cookie`, `Set-Cookie`, `X-Api-Key`, `X-Auth-Token`, `X-XSRF-Token` and `X-CSRF-Token`, `auth.password`, proxy credentials and the request body are replaced with `"[REDACTED]"`. The error object itself (`error.config`) is not modified.
|
|
@@ -265,10 +269,10 @@ const [a, b] = await Promise.all([api.get("/me"), api.get("/me")]); // one netwo
|
|
|
265
269
|
b.meta.deduped; // true
|
|
266
270
|
```
|
|
267
271
|
|
|
268
|
-
- **What counts as identical:** same method, URL, params, headers, `auth` and `responseType
|
|
272
|
+
- **What counts as identical:** same method, URL, params, headers, `auth` and `responseType`, and the same request policy: `timeout`, `totalTimeout`, `validateStatus`, `transformResponse`, `responseEncoding`, `retry`, `breaker`, `adapter` and size limits. The shared request runs with one caller's settings, so callers with different settings never share it. Functions match by identity: the instance's shared defaults match; an inline arrow function written per call does not. Requests with different `Authorization` headers are never shared.
|
|
269
273
|
- **Methods:** only `GET` and `HEAD` are deduplicated, unless you list others in `dedupe: { methods: [...] }`. Requests with a body, and `responseType: 'stream'`, are never shared.
|
|
270
274
|
- **Cancellation:** each caller keeps its own `signal` / `CancelToken`. A caller that aborts is rejected at once, and the others still get the response. The network request is aborted only when **every** caller has aborted.
|
|
271
|
-
- **Separate results:** every caller gets its own response object, with its own `requestId` and a cloned copy of `data`, and runs its own response interceptors. Errors are passed to every caller.
|
|
275
|
+
- **Separate results:** every caller gets its own response object, with its own `requestId` and a cloned copy of `data`, and runs its own response interceptors. Errors are passed to every caller. When `data` can't be copied exactly (class instances, functions), callers share the same object: treat it as read-only.
|
|
272
276
|
- **Custom key:** `dedupe: { key: (config) => string | undefined }`. Return `undefined` to skip deduplication for a request.
|
|
273
277
|
- **Events:** lifecycle events and request interceptors see the first caller's request. `onDownloadProgress` / `onUploadProgress` fire only for that caller.
|
|
274
278
|
|
|
@@ -292,7 +296,8 @@ res.meta.cached; // true
|
|
|
292
296
|
| `key` | method + URL + params + headers hash | `(config) => string \| undefined`; `undefined` skips the cache for that request |
|
|
293
297
|
| `provider` | built-in memory LRU (100 entries) | Any object with `get` / `set` / `delete` / `clear` (sync or async), plus optional `keys` |
|
|
294
298
|
|
|
295
|
-
- **What is stored:** only 2xx responses. Errors, request bodies
|
|
299
|
+
- **What is stored:** only 2xx responses. Errors, request bodies and streams are never cached. Neither is data that `structuredClone` can't copy exactly: class instances (for example from a custom `transformResponse`), functions, or Node `Buffer`s anywhere in the data. Plain objects, arrays, `Date`, `Map`, `Set`, `RegExp`, typed arrays, `ArrayBuffer` and `Blob` are fine.
|
|
300
|
+
- **Transforms:** the key includes `transformResponse` and `responseEncoding`, so differently transformed data is never mixed. An inline `transformResponse` written per call gets a new key each time, so it never hits the cache: define it once and reuse it.
|
|
296
301
|
- **Isolated data:** every response read from the cache gets its own copy of `data`, so changing it can't affect the cache or other callers.
|
|
297
302
|
- **Credentials:** the key includes a hash of the request headers and `auth`, so requests made with different credentials never share an entry. Secrets never appear in the key text.
|
|
298
303
|
- **Cache-Control:** a response with `no-store` or `no-cache` is not stored, and `max-age` shortens the `ttl`. A request sent with `Cache-Control: no-cache` skips the read and refreshes the entry; `no-store` skips both the read and the write.
|
package/dist/index.cjs
CHANGED
|
@@ -239,8 +239,8 @@ function encode(s) {
|
|
|
239
239
|
}
|
|
240
240
|
function isPlainObject(v) {
|
|
241
241
|
if (v === null || typeof v !== "object") return false;
|
|
242
|
-
const
|
|
243
|
-
return
|
|
242
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
243
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
244
244
|
}
|
|
245
245
|
function serializeParams(params, opts = {}) {
|
|
246
246
|
if (params === void 0 || params === null) return "";
|
|
@@ -308,8 +308,8 @@ function toFormData(obj, fd = new FormData()) {
|
|
|
308
308
|
// src/core/transforms.ts
|
|
309
309
|
function isPlainObject2(v) {
|
|
310
310
|
if (v === null || typeof v !== "object") return false;
|
|
311
|
-
const
|
|
312
|
-
return
|
|
311
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
312
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
313
313
|
}
|
|
314
314
|
function isPassThrough(data) {
|
|
315
315
|
return typeof FormData !== "undefined" && data instanceof FormData || typeof Blob !== "undefined" && data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || typeof ReadableStream !== "undefined" && data instanceof ReadableStream || data instanceof URLSearchParams || isNodeStream(data);
|
|
@@ -2030,26 +2030,57 @@ function requestTarget(config) {
|
|
|
2030
2030
|
);
|
|
2031
2031
|
return `${(config.method ?? "get").toUpperCase()} ${url}`;
|
|
2032
2032
|
}
|
|
2033
|
-
function defaultRequestKey(config) {
|
|
2033
|
+
function defaultRequestKey(config, scope = "cache") {
|
|
2034
2034
|
const skip = config.correlationIdHeader?.toLowerCase();
|
|
2035
2035
|
const parts = [];
|
|
2036
2036
|
for (const k of Object.keys(config.headers).sort())
|
|
2037
2037
|
if (k !== skip && !CACHE_DIRECTIVE_HEADERS.has(k)) parts.push(`${k}:${config.headers[k]}`);
|
|
2038
2038
|
if (config.auth) parts.push(`auth:${config.auth.username}:${config.auth.password}`);
|
|
2039
2039
|
parts.push(`rt:${config.responseType ?? ""}`);
|
|
2040
|
+
parts.push(
|
|
2041
|
+
`shape:${fingerprint([config.transformResponse, config.responseEncoding, config.decompress])}`
|
|
2042
|
+
);
|
|
2043
|
+
if (scope === "dedupe") {
|
|
2044
|
+
parts.push(
|
|
2045
|
+
`policy:${fingerprint([
|
|
2046
|
+
config.timeout,
|
|
2047
|
+
config.totalTimeout,
|
|
2048
|
+
config.validateStatus,
|
|
2049
|
+
config.retry,
|
|
2050
|
+
config.breaker,
|
|
2051
|
+
config.adapter,
|
|
2052
|
+
config.maxContentLength,
|
|
2053
|
+
config.maxRedirects,
|
|
2054
|
+
config.transitional
|
|
2055
|
+
])}`
|
|
2056
|
+
);
|
|
2057
|
+
}
|
|
2040
2058
|
return `${requestTarget(config)} #${hash(parts.join("\n"))}`;
|
|
2041
2059
|
}
|
|
2060
|
+
var fnIds = /* @__PURE__ */ new WeakMap();
|
|
2061
|
+
var nextFnId = 0;
|
|
2062
|
+
function fingerprint(v) {
|
|
2063
|
+
if (typeof v === "function") {
|
|
2064
|
+
let id = fnIds.get(v);
|
|
2065
|
+
if (id === void 0) fnIds.set(v, id = ++nextFnId);
|
|
2066
|
+
return `f${id}`;
|
|
2067
|
+
}
|
|
2068
|
+
if (v === null || typeof v !== "object") return v === void 0 ? "u" : JSON.stringify(v);
|
|
2069
|
+
if (Array.isArray(v)) return `[${v.map(fingerprint).join(",")}]`;
|
|
2070
|
+
const o = v;
|
|
2071
|
+
return `{${Object.keys(o).filter((k) => o[k] !== void 0).sort().map((k) => `${k}:${fingerprint(o[k])}`).join(",")}}`;
|
|
2072
|
+
}
|
|
2042
2073
|
function keyURL(key) {
|
|
2043
2074
|
const sp = key.indexOf(" ");
|
|
2044
2075
|
const h = key.lastIndexOf(" #");
|
|
2045
2076
|
return sp > 0 && h > sp ? key.slice(sp + 1, h) : void 0;
|
|
2046
2077
|
}
|
|
2047
|
-
function keyFor(config, opts) {
|
|
2078
|
+
function keyFor(config, opts, scope = "cache") {
|
|
2048
2079
|
if (!opts.methods.includes(config.method)) return void 0;
|
|
2049
2080
|
if (config.responseType === "stream") return void 0;
|
|
2050
2081
|
if (opts.key) return opts.key(config);
|
|
2051
2082
|
if (config.data !== void 0) return void 0;
|
|
2052
|
-
return defaultRequestKey(config);
|
|
2083
|
+
return defaultRequestKey(config, scope);
|
|
2053
2084
|
}
|
|
2054
2085
|
function checkMethods(name, m) {
|
|
2055
2086
|
if (!Array.isArray(m)) bad(name, m, "an array");
|
|
@@ -2094,12 +2125,46 @@ function parseCacheControl(value) {
|
|
|
2094
2125
|
function cloneData(data) {
|
|
2095
2126
|
if (data === null || typeof data !== "object") return { ok: true, value: data };
|
|
2096
2127
|
if (typeof structuredClone !== "function") return { ok: false, value: data };
|
|
2128
|
+
if (!clonesFaithfully(data, /* @__PURE__ */ new Set())) return { ok: false, value: data };
|
|
2097
2129
|
try {
|
|
2098
2130
|
return { ok: true, value: structuredClone(data) };
|
|
2099
2131
|
} catch {
|
|
2100
2132
|
return { ok: false, value: data };
|
|
2101
2133
|
}
|
|
2102
2134
|
}
|
|
2135
|
+
var proto = (v) => Object.getPrototypeOf(v);
|
|
2136
|
+
var VIEW_TYPES = [
|
|
2137
|
+
"Int8Array",
|
|
2138
|
+
"Uint8Array",
|
|
2139
|
+
"Uint8ClampedArray",
|
|
2140
|
+
"Int16Array",
|
|
2141
|
+
"Uint16Array",
|
|
2142
|
+
"Int32Array",
|
|
2143
|
+
"Uint32Array",
|
|
2144
|
+
"Float32Array",
|
|
2145
|
+
"Float64Array",
|
|
2146
|
+
"BigInt64Array",
|
|
2147
|
+
"BigUint64Array",
|
|
2148
|
+
"DataView"
|
|
2149
|
+
];
|
|
2150
|
+
var isType = (v, name) => {
|
|
2151
|
+
const C = globalThis[name];
|
|
2152
|
+
return typeof C === "function" && v instanceof C;
|
|
2153
|
+
};
|
|
2154
|
+
function clonesFaithfully(v, seen) {
|
|
2155
|
+
if (typeof v === "function" || typeof v === "symbol") return false;
|
|
2156
|
+
if (v === null || typeof v !== "object") return true;
|
|
2157
|
+
if (seen.has(v)) return true;
|
|
2158
|
+
seen.add(v);
|
|
2159
|
+
if (Array.isArray(v)) return proto(v) === Array.prototype && v.every((x) => clonesFaithfully(x, seen));
|
|
2160
|
+
if (v instanceof Map) return proto(v) === Map.prototype && [...v].every(([k, x]) => clonesFaithfully(k, seen) && clonesFaithfully(x, seen));
|
|
2161
|
+
if (v instanceof Set) return proto(v) === Set.prototype && [...v].every((x) => clonesFaithfully(x, seen));
|
|
2162
|
+
const p = proto(v);
|
|
2163
|
+
if (p === Object.prototype || p === null)
|
|
2164
|
+
return Object.values(v).every((x) => clonesFaithfully(x, seen));
|
|
2165
|
+
return p === Date.prototype || p === RegExp.prototype || p === ArrayBuffer.prototype || VIEW_TYPES.some((name) => p === globalThis[name]?.prototype) || // exact built-ins only: byte-array subclasses would come back as Uint8Array
|
|
2166
|
+
isType(v, "Blob") || isType(v, "FormData");
|
|
2167
|
+
}
|
|
2103
2168
|
function reportCacheError(op, err) {
|
|
2104
2169
|
if (typeof console !== "undefined") console.error(`[exios] cache provider ${op} failed:`, err);
|
|
2105
2170
|
}
|
|
@@ -2254,7 +2319,7 @@ var Exios = class {
|
|
|
2254
2319
|
const cacheCfg = resolveCache(config.cache);
|
|
2255
2320
|
const dedupeCfg = resolveDedupe(config.dedupe);
|
|
2256
2321
|
const cacheKey = cacheCfg ? keyFor(config, cacheCfg) : void 0;
|
|
2257
|
-
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg) : void 0;
|
|
2322
|
+
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg, "dedupe") : void 0;
|
|
2258
2323
|
const provider = cacheCfg ? cacheCfg.provider ?? this.memoryCache : void 0;
|
|
2259
2324
|
const reqCC = cacheCfg && cacheCfg.respectCacheControl ? parseCacheControl(config.headers["cache-control"]) : void 0;
|
|
2260
2325
|
if (cacheKey !== void 0 && provider && !reqCC?.has("no-cache") && !reqCC?.has("no-store")) {
|
package/dist/index.d.cts
CHANGED
|
@@ -40,6 +40,7 @@ declare namespace exios {
|
|
|
40
40
|
type DedupeConfig = Pkg.DedupeConfig;
|
|
41
41
|
type ExiosCache = Pkg.ExiosCache;
|
|
42
42
|
type MemoryCache = Pkg.MemoryCache;
|
|
43
|
+
type Options<T> = Pkg.Options<T>;
|
|
43
44
|
type CanceledEvent = Pkg.CanceledEvent;
|
|
44
45
|
type CircuitEvent = Pkg.CircuitEvent;
|
|
45
46
|
type ErrorEvent = Pkg.ErrorEvent;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,8 @@ declare class CircuitOpenError extends ExiosError {
|
|
|
29
29
|
retryAt: number;
|
|
30
30
|
constructor(origin: string, retryAt: number, config?: InternalConfig);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
/** Type guard; pass the error body type to narrow `error.response.data`: `isExiosError<ApiError>(err)`. */
|
|
33
|
+
declare function isExiosError<T = any, D = any>(v: unknown): v is ExiosError<T, D>;
|
|
33
34
|
/** Also true for a canceled error from another copy of the package (dual-package hazard). */
|
|
34
35
|
declare function isCancel(v: unknown): v is CanceledError;
|
|
35
36
|
|
|
@@ -66,6 +67,13 @@ type RawHeaders = Record<string, HeaderValue> | Headers;
|
|
|
66
67
|
type HeadersDefaults = {
|
|
67
68
|
common: Record<string, HeaderValue>;
|
|
68
69
|
} & Record<Lowercase<Method>, Record<string, HeaderValue>>;
|
|
70
|
+
/**
|
|
71
|
+
* Option object where every field may be omitted or set to `undefined` (= keep the default), so it
|
|
72
|
+
* also type-checks under `exactOptionalPropertyTypes`.
|
|
73
|
+
*/
|
|
74
|
+
type Options<T> = {
|
|
75
|
+
[K in keyof T]?: T[K] | undefined;
|
|
76
|
+
};
|
|
69
77
|
type AdapterName = "xhr" | "http" | "fetch";
|
|
70
78
|
type AdapterFn = (config: InternalConfig) => Promise<ExiosResponse>;
|
|
71
79
|
type AdapterConfig = AdapterName | AdapterFn | Array<AdapterName | AdapterFn>;
|
|
@@ -115,7 +123,7 @@ interface BreakerConfig {
|
|
|
115
123
|
onStateChange?: (key: string, from: BreakerState, to: BreakerState) => void;
|
|
116
124
|
}
|
|
117
125
|
type BreakerState = "closed" | "open" | "half-open";
|
|
118
|
-
type RequestBreakerOverride = false | Pick<
|
|
126
|
+
type RequestBreakerOverride = false | Pick<Options<BreakerConfig>, "key" | "isFailure">;
|
|
119
127
|
interface ProgressEvent {
|
|
120
128
|
loaded: number;
|
|
121
129
|
total?: number;
|
|
@@ -129,94 +137,94 @@ interface ProgressEvent {
|
|
|
129
137
|
}
|
|
130
138
|
type Transformer = (this: InternalConfig, data: any, headers: Record<string, string>, status?: number) => any;
|
|
131
139
|
interface ExiosRequestConfig<D = any> {
|
|
132
|
-
url?: string;
|
|
133
|
-
method?: Method;
|
|
134
|
-
baseURL?: string;
|
|
135
|
-
allowAbsoluteUrls?: boolean;
|
|
136
|
-
headers?: RawHeaders | (Partial<HeadersDefaults> & Record<string, HeaderValue | Record<string, HeaderValue>>);
|
|
137
|
-
params?: any;
|
|
140
|
+
url?: string | undefined;
|
|
141
|
+
method?: Method | undefined;
|
|
142
|
+
baseURL?: string | undefined;
|
|
143
|
+
allowAbsoluteUrls?: boolean | undefined;
|
|
144
|
+
headers?: RawHeaders | (Partial<HeadersDefaults> & Record<string, HeaderValue | Record<string, HeaderValue>>) | undefined;
|
|
145
|
+
params?: any | undefined;
|
|
138
146
|
paramsSerializer?: ((params: any) => string) | {
|
|
139
147
|
serialize?: (p: any) => string;
|
|
140
148
|
indexes?: boolean | null;
|
|
141
149
|
encode?: (s: string) => string;
|
|
142
|
-
};
|
|
143
|
-
data?: D;
|
|
144
|
-
transformRequest?: Transformer | Transformer[];
|
|
145
|
-
transformResponse?: Transformer | Transformer[];
|
|
146
|
-
timeout?: number;
|
|
147
|
-
timeoutErrorMessage?: string;
|
|
148
|
-
withCredentials?: boolean;
|
|
150
|
+
} | undefined;
|
|
151
|
+
data?: D | undefined;
|
|
152
|
+
transformRequest?: Transformer | Transformer[] | undefined;
|
|
153
|
+
transformResponse?: Transformer | Transformer[] | undefined;
|
|
154
|
+
timeout?: number | undefined;
|
|
155
|
+
timeoutErrorMessage?: string | undefined;
|
|
156
|
+
withCredentials?: boolean | undefined;
|
|
149
157
|
auth?: {
|
|
150
158
|
username: string;
|
|
151
159
|
password: string;
|
|
152
|
-
};
|
|
153
|
-
responseType?: ResponseType;
|
|
154
|
-
responseEncoding?: string;
|
|
155
|
-
validateStatus?: ((status: number) => boolean) | null;
|
|
156
|
-
signal?: AbortSignal;
|
|
157
|
-
onDownloadProgress?: (e: ProgressEvent) => void;
|
|
158
|
-
maxContentLength?: number;
|
|
159
|
-
maxBodyLength?: number;
|
|
160
|
+
} | undefined;
|
|
161
|
+
responseType?: ResponseType | undefined;
|
|
162
|
+
responseEncoding?: string | undefined;
|
|
163
|
+
validateStatus?: (((status: number) => boolean) | null) | undefined;
|
|
164
|
+
signal?: AbortSignal | undefined;
|
|
165
|
+
onDownloadProgress?: ((e: ProgressEvent) => void) | undefined;
|
|
166
|
+
maxContentLength?: number | undefined;
|
|
167
|
+
maxBodyLength?: number | undefined;
|
|
160
168
|
transitional?: {
|
|
161
169
|
silentJSONParsing?: boolean;
|
|
162
170
|
clarifyTimeoutError?: boolean;
|
|
163
|
-
};
|
|
164
|
-
adapter?: AdapterConfig;
|
|
165
|
-
onUploadProgress?: (e: ProgressEvent) => void;
|
|
166
|
-
xsrfCookieName?: string;
|
|
167
|
-
xsrfHeaderName?: string;
|
|
168
|
-
withXSRFToken?: boolean | ((config: InternalConfig) => boolean | undefined);
|
|
171
|
+
} | undefined;
|
|
172
|
+
adapter?: AdapterConfig | undefined;
|
|
173
|
+
onUploadProgress?: ((e: ProgressEvent) => void) | undefined;
|
|
174
|
+
xsrfCookieName?: string | undefined;
|
|
175
|
+
xsrfHeaderName?: string | undefined;
|
|
176
|
+
withXSRFToken?: (boolean | ((config: InternalConfig) => boolean | undefined)) | undefined;
|
|
169
177
|
/** @deprecated Use `signal` (AbortController), as in axios. */
|
|
170
|
-
cancelToken?: CancelToken;
|
|
178
|
+
cancelToken?: CancelToken | undefined;
|
|
171
179
|
/** Node http adapter: proxy server, or `false` to ignore HTTP(S)_PROXY env vars. */
|
|
172
|
-
proxy?: ProxyConfig | false;
|
|
180
|
+
proxy?: ProxyConfig | false | undefined;
|
|
173
181
|
/** Node http adapter: `http.Agent` used for http: URLs. */
|
|
174
|
-
httpAgent?: unknown;
|
|
182
|
+
httpAgent?: unknown | undefined;
|
|
175
183
|
/** Node http adapter: `https.Agent` used for https: URLs. */
|
|
176
|
-
httpsAgent?: unknown;
|
|
184
|
+
httpsAgent?: unknown | undefined;
|
|
177
185
|
/** Node http adapter: redirects to follow (default 21; 0 = return the 3xx). */
|
|
178
|
-
maxRedirects?: number;
|
|
179
|
-
beforeRedirect?: (options: Record<string, any>, responseDetails: {
|
|
186
|
+
maxRedirects?: number | undefined;
|
|
187
|
+
beforeRedirect?: ((options: Record<string, any>, responseDetails: {
|
|
180
188
|
headers: Record<string, string | string[]>;
|
|
181
189
|
statusCode: number;
|
|
182
|
-
}) => void;
|
|
190
|
+
}) => void) | undefined;
|
|
183
191
|
/** Node http adapter: unix socket path. */
|
|
184
|
-
socketPath?: string | null;
|
|
192
|
+
socketPath?: string | null | undefined;
|
|
185
193
|
/** Node http adapter: decode gzip/deflate/br responses (default true). */
|
|
186
|
-
decompress?: boolean;
|
|
187
|
-
insecureHTTPParser?: boolean;
|
|
188
|
-
fetch?: typeof fetch;
|
|
189
|
-
fetchOptions?: Omit<RequestInit, "body" | "headers" | "method" | "signal"
|
|
190
|
-
redirect?: RequestRedirect;
|
|
191
|
-
retry?: false |
|
|
192
|
-
breaker?: false |
|
|
194
|
+
decompress?: boolean | undefined;
|
|
195
|
+
insecureHTTPParser?: boolean | undefined;
|
|
196
|
+
fetch?: typeof fetch | undefined;
|
|
197
|
+
fetchOptions?: Omit<RequestInit, "body" | "headers" | "method" | "signal"> | undefined;
|
|
198
|
+
redirect?: RequestRedirect | undefined;
|
|
199
|
+
retry?: false | Options<RetryConfig> | undefined;
|
|
200
|
+
breaker?: false | Options<BreakerConfig> | undefined;
|
|
193
201
|
/** Id of this logical request (retries share it). Generated when not set. */
|
|
194
|
-
requestId?: string;
|
|
202
|
+
requestId?: string | undefined;
|
|
195
203
|
/** Id that ties this request to a wider operation; often set on an instance. */
|
|
196
|
-
correlationId?: string;
|
|
204
|
+
correlationId?: string | undefined;
|
|
197
205
|
/**
|
|
198
206
|
* Send `correlationId` (or `requestId` when there is none) in this header, e.g. "x-correlation-id".
|
|
199
207
|
* Off by default: an extra header can trigger a CORS preflight. A header the caller already set wins.
|
|
200
208
|
*/
|
|
201
|
-
correlationIdHeader?: string;
|
|
209
|
+
correlationIdHeader?: string | undefined;
|
|
202
210
|
/** Free-form data that travels with the request: readable in interceptors, events and adapters. Never sent. */
|
|
203
|
-
metadata?: Record<string, unknown
|
|
211
|
+
metadata?: Record<string, unknown> | undefined;
|
|
204
212
|
/**
|
|
205
213
|
* Time limit (ms) for the whole logical request: every attempt, retry and backoff sleep.
|
|
206
214
|
* `timeout` still limits each attempt. 0 / undefined = no limit. For `responseType: 'stream'` it ends
|
|
207
215
|
* when the headers arrive.
|
|
208
216
|
*/
|
|
209
|
-
totalTimeout?: number;
|
|
217
|
+
totalTimeout?: number | undefined;
|
|
210
218
|
/** Share one in-flight request between identical concurrent requests (GET/HEAD by default). Off by default. */
|
|
211
|
-
dedupe?: boolean | DedupeConfig;
|
|
219
|
+
dedupe?: boolean | DedupeConfig | undefined;
|
|
212
220
|
/** Cache successful responses (GET/HEAD by default). Off by default. */
|
|
213
|
-
cache?: boolean |
|
|
221
|
+
cache?: boolean | Options<CacheConfig> | undefined;
|
|
214
222
|
}
|
|
215
223
|
interface DedupeConfig {
|
|
216
224
|
/** Methods that may be deduplicated. Default: ["get", "head"]. */
|
|
217
|
-
methods?: Lowercase<Method>[];
|
|
225
|
+
methods?: Lowercase<Method>[] | undefined;
|
|
218
226
|
/** Custom key; return undefined to not deduplicate this request. Default: method + URL + params + headers. */
|
|
219
|
-
key?: (config: InternalConfig) => string | undefined;
|
|
227
|
+
key?: ((config: InternalConfig) => string | undefined) | undefined;
|
|
220
228
|
}
|
|
221
229
|
/** What a cache provider stores for one response. */
|
|
222
230
|
interface CacheEntry {
|
|
@@ -256,8 +264,8 @@ interface CacheConfig {
|
|
|
256
264
|
*/
|
|
257
265
|
interface ExiosDefaults<D = any> extends Omit<ExiosRequestConfig<D>, "headers" | "retry" | "breaker"> {
|
|
258
266
|
headers: HeadersDefaults & Record<string, HeaderValue | Record<string, HeaderValue>>;
|
|
259
|
-
retry: false |
|
|
260
|
-
breaker: false |
|
|
267
|
+
retry: false | Options<RetryConfig>;
|
|
268
|
+
breaker: false | Options<BreakerConfig>;
|
|
261
269
|
}
|
|
262
270
|
interface InternalConfig<D = any> extends Omit<ExiosRequestConfig<D>, "headers" | "retry" | "breaker"> {
|
|
263
271
|
method: Lowercase<Method>;
|
|
@@ -502,4 +510,4 @@ declare const exios: ExiosDefault;
|
|
|
502
510
|
declare const create: (config?: ExiosRequestConfig) => ExiosStatic;
|
|
503
511
|
|
|
504
512
|
export { CancelToken, CanceledError, CircuitOpenError, ExiosError, InterceptorManager, MemoryCache, create, exios as default, isCancel, isExiosError, mergeConfig, toFormData };
|
|
505
|
-
export type { AdapterConfig, AdapterFn, AdapterName, BreakerConfig, BreakerState, CacheConfig, CacheEntry, CacheProvider, CancelTokenSource, CanceledEvent, Canceler, CircuitEvent, DedupeConfig, ErrorEvent, ErrorMeta, ExiosCache, ExiosDefault, ExiosDefaults, ExiosEventListener, ExiosEventMap, ExiosEventName, ExiosInstance, ExiosRequestConfig, ExiosResponse, ExiosStatic, HeaderValue, HeadersDefaults, InterceptorHandler, InterceptorOptions, InternalConfig, Method, Outcome, ProgressEvent, ProxyConfig, RawHeaders, RequestBreakerOverride, RequestEvent, RequestEventBase, ResponseEvent, ResponseMeta, ResponseType, RetryConfig, RetryEvent, TimeoutEvent, Transformer };
|
|
513
|
+
export type { AdapterConfig, AdapterFn, AdapterName, BreakerConfig, BreakerState, CacheConfig, CacheEntry, CacheProvider, CancelTokenSource, CanceledEvent, Canceler, CircuitEvent, DedupeConfig, ErrorEvent, ErrorMeta, ExiosCache, ExiosDefault, ExiosDefaults, ExiosEventListener, ExiosEventMap, ExiosEventName, ExiosInstance, ExiosRequestConfig, ExiosResponse, ExiosStatic, HeaderValue, HeadersDefaults, InterceptorHandler, InterceptorOptions, InternalConfig, Method, Options, Outcome, ProgressEvent, ProxyConfig, RawHeaders, RequestBreakerOverride, RequestEvent, RequestEventBase, ResponseEvent, ResponseMeta, ResponseType, RetryConfig, RetryEvent, TimeoutEvent, Transformer };
|
package/dist/index.js
CHANGED
|
@@ -213,8 +213,8 @@ function encode(s) {
|
|
|
213
213
|
}
|
|
214
214
|
function isPlainObject(v) {
|
|
215
215
|
if (v === null || typeof v !== "object") return false;
|
|
216
|
-
const
|
|
217
|
-
return
|
|
216
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
217
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
218
218
|
}
|
|
219
219
|
function serializeParams(params, opts = {}) {
|
|
220
220
|
if (params === void 0 || params === null) return "";
|
|
@@ -282,8 +282,8 @@ function toFormData(obj, fd = new FormData()) {
|
|
|
282
282
|
// src/core/transforms.ts
|
|
283
283
|
function isPlainObject2(v) {
|
|
284
284
|
if (v === null || typeof v !== "object") return false;
|
|
285
|
-
const
|
|
286
|
-
return
|
|
285
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
286
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
287
287
|
}
|
|
288
288
|
function isPassThrough(data) {
|
|
289
289
|
return typeof FormData !== "undefined" && data instanceof FormData || typeof Blob !== "undefined" && data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || typeof ReadableStream !== "undefined" && data instanceof ReadableStream || data instanceof URLSearchParams || isNodeStream(data);
|
|
@@ -2004,26 +2004,57 @@ function requestTarget(config) {
|
|
|
2004
2004
|
);
|
|
2005
2005
|
return `${(config.method ?? "get").toUpperCase()} ${url}`;
|
|
2006
2006
|
}
|
|
2007
|
-
function defaultRequestKey(config) {
|
|
2007
|
+
function defaultRequestKey(config, scope = "cache") {
|
|
2008
2008
|
const skip = config.correlationIdHeader?.toLowerCase();
|
|
2009
2009
|
const parts = [];
|
|
2010
2010
|
for (const k of Object.keys(config.headers).sort())
|
|
2011
2011
|
if (k !== skip && !CACHE_DIRECTIVE_HEADERS.has(k)) parts.push(`${k}:${config.headers[k]}`);
|
|
2012
2012
|
if (config.auth) parts.push(`auth:${config.auth.username}:${config.auth.password}`);
|
|
2013
2013
|
parts.push(`rt:${config.responseType ?? ""}`);
|
|
2014
|
+
parts.push(
|
|
2015
|
+
`shape:${fingerprint([config.transformResponse, config.responseEncoding, config.decompress])}`
|
|
2016
|
+
);
|
|
2017
|
+
if (scope === "dedupe") {
|
|
2018
|
+
parts.push(
|
|
2019
|
+
`policy:${fingerprint([
|
|
2020
|
+
config.timeout,
|
|
2021
|
+
config.totalTimeout,
|
|
2022
|
+
config.validateStatus,
|
|
2023
|
+
config.retry,
|
|
2024
|
+
config.breaker,
|
|
2025
|
+
config.adapter,
|
|
2026
|
+
config.maxContentLength,
|
|
2027
|
+
config.maxRedirects,
|
|
2028
|
+
config.transitional
|
|
2029
|
+
])}`
|
|
2030
|
+
);
|
|
2031
|
+
}
|
|
2014
2032
|
return `${requestTarget(config)} #${hash(parts.join("\n"))}`;
|
|
2015
2033
|
}
|
|
2034
|
+
var fnIds = /* @__PURE__ */ new WeakMap();
|
|
2035
|
+
var nextFnId = 0;
|
|
2036
|
+
function fingerprint(v) {
|
|
2037
|
+
if (typeof v === "function") {
|
|
2038
|
+
let id = fnIds.get(v);
|
|
2039
|
+
if (id === void 0) fnIds.set(v, id = ++nextFnId);
|
|
2040
|
+
return `f${id}`;
|
|
2041
|
+
}
|
|
2042
|
+
if (v === null || typeof v !== "object") return v === void 0 ? "u" : JSON.stringify(v);
|
|
2043
|
+
if (Array.isArray(v)) return `[${v.map(fingerprint).join(",")}]`;
|
|
2044
|
+
const o = v;
|
|
2045
|
+
return `{${Object.keys(o).filter((k) => o[k] !== void 0).sort().map((k) => `${k}:${fingerprint(o[k])}`).join(",")}}`;
|
|
2046
|
+
}
|
|
2016
2047
|
function keyURL(key) {
|
|
2017
2048
|
const sp = key.indexOf(" ");
|
|
2018
2049
|
const h = key.lastIndexOf(" #");
|
|
2019
2050
|
return sp > 0 && h > sp ? key.slice(sp + 1, h) : void 0;
|
|
2020
2051
|
}
|
|
2021
|
-
function keyFor(config, opts) {
|
|
2052
|
+
function keyFor(config, opts, scope = "cache") {
|
|
2022
2053
|
if (!opts.methods.includes(config.method)) return void 0;
|
|
2023
2054
|
if (config.responseType === "stream") return void 0;
|
|
2024
2055
|
if (opts.key) return opts.key(config);
|
|
2025
2056
|
if (config.data !== void 0) return void 0;
|
|
2026
|
-
return defaultRequestKey(config);
|
|
2057
|
+
return defaultRequestKey(config, scope);
|
|
2027
2058
|
}
|
|
2028
2059
|
function checkMethods(name, m) {
|
|
2029
2060
|
if (!Array.isArray(m)) bad(name, m, "an array");
|
|
@@ -2068,12 +2099,46 @@ function parseCacheControl(value) {
|
|
|
2068
2099
|
function cloneData(data) {
|
|
2069
2100
|
if (data === null || typeof data !== "object") return { ok: true, value: data };
|
|
2070
2101
|
if (typeof structuredClone !== "function") return { ok: false, value: data };
|
|
2102
|
+
if (!clonesFaithfully(data, /* @__PURE__ */ new Set())) return { ok: false, value: data };
|
|
2071
2103
|
try {
|
|
2072
2104
|
return { ok: true, value: structuredClone(data) };
|
|
2073
2105
|
} catch {
|
|
2074
2106
|
return { ok: false, value: data };
|
|
2075
2107
|
}
|
|
2076
2108
|
}
|
|
2109
|
+
var proto = (v) => Object.getPrototypeOf(v);
|
|
2110
|
+
var VIEW_TYPES = [
|
|
2111
|
+
"Int8Array",
|
|
2112
|
+
"Uint8Array",
|
|
2113
|
+
"Uint8ClampedArray",
|
|
2114
|
+
"Int16Array",
|
|
2115
|
+
"Uint16Array",
|
|
2116
|
+
"Int32Array",
|
|
2117
|
+
"Uint32Array",
|
|
2118
|
+
"Float32Array",
|
|
2119
|
+
"Float64Array",
|
|
2120
|
+
"BigInt64Array",
|
|
2121
|
+
"BigUint64Array",
|
|
2122
|
+
"DataView"
|
|
2123
|
+
];
|
|
2124
|
+
var isType = (v, name) => {
|
|
2125
|
+
const C = globalThis[name];
|
|
2126
|
+
return typeof C === "function" && v instanceof C;
|
|
2127
|
+
};
|
|
2128
|
+
function clonesFaithfully(v, seen) {
|
|
2129
|
+
if (typeof v === "function" || typeof v === "symbol") return false;
|
|
2130
|
+
if (v === null || typeof v !== "object") return true;
|
|
2131
|
+
if (seen.has(v)) return true;
|
|
2132
|
+
seen.add(v);
|
|
2133
|
+
if (Array.isArray(v)) return proto(v) === Array.prototype && v.every((x) => clonesFaithfully(x, seen));
|
|
2134
|
+
if (v instanceof Map) return proto(v) === Map.prototype && [...v].every(([k, x]) => clonesFaithfully(k, seen) && clonesFaithfully(x, seen));
|
|
2135
|
+
if (v instanceof Set) return proto(v) === Set.prototype && [...v].every((x) => clonesFaithfully(x, seen));
|
|
2136
|
+
const p = proto(v);
|
|
2137
|
+
if (p === Object.prototype || p === null)
|
|
2138
|
+
return Object.values(v).every((x) => clonesFaithfully(x, seen));
|
|
2139
|
+
return p === Date.prototype || p === RegExp.prototype || p === ArrayBuffer.prototype || VIEW_TYPES.some((name) => p === globalThis[name]?.prototype) || // exact built-ins only: byte-array subclasses would come back as Uint8Array
|
|
2140
|
+
isType(v, "Blob") || isType(v, "FormData");
|
|
2141
|
+
}
|
|
2077
2142
|
function reportCacheError(op, err) {
|
|
2078
2143
|
if (typeof console !== "undefined") console.error(`[exios] cache provider ${op} failed:`, err);
|
|
2079
2144
|
}
|
|
@@ -2228,7 +2293,7 @@ var Exios = class {
|
|
|
2228
2293
|
const cacheCfg = resolveCache(config.cache);
|
|
2229
2294
|
const dedupeCfg = resolveDedupe(config.dedupe);
|
|
2230
2295
|
const cacheKey = cacheCfg ? keyFor(config, cacheCfg) : void 0;
|
|
2231
|
-
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg) : void 0;
|
|
2296
|
+
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg, "dedupe") : void 0;
|
|
2232
2297
|
const provider = cacheCfg ? cacheCfg.provider ?? this.memoryCache : void 0;
|
|
2233
2298
|
const reqCC = cacheCfg && cacheCfg.respectCacheControl ? parseCacheControl(config.headers["cache-control"]) : void 0;
|
|
2234
2299
|
if (cacheKey !== void 0 && provider && !reqCC?.has("no-cache") && !reqCC?.has("no-store")) {
|
package/dist/index.node.cjs
CHANGED
|
@@ -173,8 +173,8 @@ function encode(s) {
|
|
|
173
173
|
}
|
|
174
174
|
function isPlainObject(v) {
|
|
175
175
|
if (v === null || typeof v !== "object") return false;
|
|
176
|
-
const
|
|
177
|
-
return
|
|
176
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
177
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
178
178
|
}
|
|
179
179
|
function serializeParams(params, opts2 = {}) {
|
|
180
180
|
if (params === void 0 || params === null) return "";
|
|
@@ -242,8 +242,8 @@ function toFormData(obj, fd = new FormData()) {
|
|
|
242
242
|
// src/core/transforms.ts
|
|
243
243
|
function isPlainObject2(v) {
|
|
244
244
|
if (v === null || typeof v !== "object") return false;
|
|
245
|
-
const
|
|
246
|
-
return
|
|
245
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
246
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
247
247
|
}
|
|
248
248
|
function isPassThrough(data) {
|
|
249
249
|
return typeof FormData !== "undefined" && data instanceof FormData || typeof Blob !== "undefined" && data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || typeof ReadableStream !== "undefined" && data instanceof ReadableStream || data instanceof URLSearchParams || isNodeStream(data);
|
|
@@ -2564,26 +2564,57 @@ function requestTarget(config) {
|
|
|
2564
2564
|
);
|
|
2565
2565
|
return `${(config.method ?? "get").toUpperCase()} ${url}`;
|
|
2566
2566
|
}
|
|
2567
|
-
function defaultRequestKey(config) {
|
|
2567
|
+
function defaultRequestKey(config, scope = "cache") {
|
|
2568
2568
|
const skip = config.correlationIdHeader?.toLowerCase();
|
|
2569
2569
|
const parts = [];
|
|
2570
2570
|
for (const k of Object.keys(config.headers).sort())
|
|
2571
2571
|
if (k !== skip && !CACHE_DIRECTIVE_HEADERS.has(k)) parts.push(`${k}:${config.headers[k]}`);
|
|
2572
2572
|
if (config.auth) parts.push(`auth:${config.auth.username}:${config.auth.password}`);
|
|
2573
2573
|
parts.push(`rt:${config.responseType ?? ""}`);
|
|
2574
|
+
parts.push(
|
|
2575
|
+
`shape:${fingerprint([config.transformResponse, config.responseEncoding, config.decompress])}`
|
|
2576
|
+
);
|
|
2577
|
+
if (scope === "dedupe") {
|
|
2578
|
+
parts.push(
|
|
2579
|
+
`policy:${fingerprint([
|
|
2580
|
+
config.timeout,
|
|
2581
|
+
config.totalTimeout,
|
|
2582
|
+
config.validateStatus,
|
|
2583
|
+
config.retry,
|
|
2584
|
+
config.breaker,
|
|
2585
|
+
config.adapter,
|
|
2586
|
+
config.maxContentLength,
|
|
2587
|
+
config.maxRedirects,
|
|
2588
|
+
config.transitional
|
|
2589
|
+
])}`
|
|
2590
|
+
);
|
|
2591
|
+
}
|
|
2574
2592
|
return `${requestTarget(config)} #${hash(parts.join("\n"))}`;
|
|
2575
2593
|
}
|
|
2594
|
+
var fnIds = /* @__PURE__ */ new WeakMap();
|
|
2595
|
+
var nextFnId = 0;
|
|
2596
|
+
function fingerprint(v) {
|
|
2597
|
+
if (typeof v === "function") {
|
|
2598
|
+
let id = fnIds.get(v);
|
|
2599
|
+
if (id === void 0) fnIds.set(v, id = ++nextFnId);
|
|
2600
|
+
return `f${id}`;
|
|
2601
|
+
}
|
|
2602
|
+
if (v === null || typeof v !== "object") return v === void 0 ? "u" : JSON.stringify(v);
|
|
2603
|
+
if (Array.isArray(v)) return `[${v.map(fingerprint).join(",")}]`;
|
|
2604
|
+
const o = v;
|
|
2605
|
+
return `{${Object.keys(o).filter((k) => o[k] !== void 0).sort().map((k) => `${k}:${fingerprint(o[k])}`).join(",")}}`;
|
|
2606
|
+
}
|
|
2576
2607
|
function keyURL(key) {
|
|
2577
2608
|
const sp = key.indexOf(" ");
|
|
2578
2609
|
const h = key.lastIndexOf(" #");
|
|
2579
2610
|
return sp > 0 && h > sp ? key.slice(sp + 1, h) : void 0;
|
|
2580
2611
|
}
|
|
2581
|
-
function keyFor(config, opts2) {
|
|
2612
|
+
function keyFor(config, opts2, scope = "cache") {
|
|
2582
2613
|
if (!opts2.methods.includes(config.method)) return void 0;
|
|
2583
2614
|
if (config.responseType === "stream") return void 0;
|
|
2584
2615
|
if (opts2.key) return opts2.key(config);
|
|
2585
2616
|
if (config.data !== void 0) return void 0;
|
|
2586
|
-
return defaultRequestKey(config);
|
|
2617
|
+
return defaultRequestKey(config, scope);
|
|
2587
2618
|
}
|
|
2588
2619
|
function checkMethods(name, m) {
|
|
2589
2620
|
if (!Array.isArray(m)) bad(name, m, "an array");
|
|
@@ -2628,12 +2659,46 @@ function parseCacheControl(value) {
|
|
|
2628
2659
|
function cloneData(data) {
|
|
2629
2660
|
if (data === null || typeof data !== "object") return { ok: true, value: data };
|
|
2630
2661
|
if (typeof structuredClone !== "function") return { ok: false, value: data };
|
|
2662
|
+
if (!clonesFaithfully(data, /* @__PURE__ */ new Set())) return { ok: false, value: data };
|
|
2631
2663
|
try {
|
|
2632
2664
|
return { ok: true, value: structuredClone(data) };
|
|
2633
2665
|
} catch {
|
|
2634
2666
|
return { ok: false, value: data };
|
|
2635
2667
|
}
|
|
2636
2668
|
}
|
|
2669
|
+
var proto = (v) => Object.getPrototypeOf(v);
|
|
2670
|
+
var VIEW_TYPES = [
|
|
2671
|
+
"Int8Array",
|
|
2672
|
+
"Uint8Array",
|
|
2673
|
+
"Uint8ClampedArray",
|
|
2674
|
+
"Int16Array",
|
|
2675
|
+
"Uint16Array",
|
|
2676
|
+
"Int32Array",
|
|
2677
|
+
"Uint32Array",
|
|
2678
|
+
"Float32Array",
|
|
2679
|
+
"Float64Array",
|
|
2680
|
+
"BigInt64Array",
|
|
2681
|
+
"BigUint64Array",
|
|
2682
|
+
"DataView"
|
|
2683
|
+
];
|
|
2684
|
+
var isType = (v, name) => {
|
|
2685
|
+
const C = globalThis[name];
|
|
2686
|
+
return typeof C === "function" && v instanceof C;
|
|
2687
|
+
};
|
|
2688
|
+
function clonesFaithfully(v, seen) {
|
|
2689
|
+
if (typeof v === "function" || typeof v === "symbol") return false;
|
|
2690
|
+
if (v === null || typeof v !== "object") return true;
|
|
2691
|
+
if (seen.has(v)) return true;
|
|
2692
|
+
seen.add(v);
|
|
2693
|
+
if (Array.isArray(v)) return proto(v) === Array.prototype && v.every((x) => clonesFaithfully(x, seen));
|
|
2694
|
+
if (v instanceof Map) return proto(v) === Map.prototype && [...v].every(([k, x]) => clonesFaithfully(k, seen) && clonesFaithfully(x, seen));
|
|
2695
|
+
if (v instanceof Set) return proto(v) === Set.prototype && [...v].every((x) => clonesFaithfully(x, seen));
|
|
2696
|
+
const p = proto(v);
|
|
2697
|
+
if (p === Object.prototype || p === null)
|
|
2698
|
+
return Object.values(v).every((x) => clonesFaithfully(x, seen));
|
|
2699
|
+
return p === Date.prototype || p === RegExp.prototype || p === ArrayBuffer.prototype || VIEW_TYPES.some((name) => p === globalThis[name]?.prototype) || // exact built-ins only: byte-array subclasses would come back as Uint8Array
|
|
2700
|
+
isType(v, "Blob") || isType(v, "FormData");
|
|
2701
|
+
}
|
|
2637
2702
|
function reportCacheError(op, err) {
|
|
2638
2703
|
if (typeof console !== "undefined") console.error(`[exios] cache provider ${op} failed:`, err);
|
|
2639
2704
|
}
|
|
@@ -2788,7 +2853,7 @@ var Exios = class {
|
|
|
2788
2853
|
const cacheCfg = resolveCache(config.cache);
|
|
2789
2854
|
const dedupeCfg = resolveDedupe(config.dedupe);
|
|
2790
2855
|
const cacheKey = cacheCfg ? keyFor(config, cacheCfg) : void 0;
|
|
2791
|
-
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg) : void 0;
|
|
2856
|
+
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg, "dedupe") : void 0;
|
|
2792
2857
|
const provider = cacheCfg ? cacheCfg.provider ?? this.memoryCache : void 0;
|
|
2793
2858
|
const reqCC = cacheCfg && cacheCfg.respectCacheControl ? parseCacheControl(config.headers["cache-control"]) : void 0;
|
|
2794
2859
|
if (cacheKey !== void 0 && provider && !reqCC?.has("no-cache") && !reqCC?.has("no-store")) {
|
package/dist/index.node.js
CHANGED
|
@@ -137,8 +137,8 @@ function encode(s) {
|
|
|
137
137
|
}
|
|
138
138
|
function isPlainObject(v) {
|
|
139
139
|
if (v === null || typeof v !== "object") return false;
|
|
140
|
-
const
|
|
141
|
-
return
|
|
140
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
141
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
142
142
|
}
|
|
143
143
|
function serializeParams(params, opts2 = {}) {
|
|
144
144
|
if (params === void 0 || params === null) return "";
|
|
@@ -206,8 +206,8 @@ function toFormData(obj, fd = new FormData()) {
|
|
|
206
206
|
// src/core/transforms.ts
|
|
207
207
|
function isPlainObject2(v) {
|
|
208
208
|
if (v === null || typeof v !== "object") return false;
|
|
209
|
-
const
|
|
210
|
-
return
|
|
209
|
+
const proto2 = Object.getPrototypeOf(v);
|
|
210
|
+
return proto2 === Object.prototype || proto2 === null;
|
|
211
211
|
}
|
|
212
212
|
function isPassThrough(data) {
|
|
213
213
|
return typeof FormData !== "undefined" && data instanceof FormData || typeof Blob !== "undefined" && data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || typeof ReadableStream !== "undefined" && data instanceof ReadableStream || data instanceof URLSearchParams || isNodeStream(data);
|
|
@@ -2528,26 +2528,57 @@ function requestTarget(config) {
|
|
|
2528
2528
|
);
|
|
2529
2529
|
return `${(config.method ?? "get").toUpperCase()} ${url}`;
|
|
2530
2530
|
}
|
|
2531
|
-
function defaultRequestKey(config) {
|
|
2531
|
+
function defaultRequestKey(config, scope = "cache") {
|
|
2532
2532
|
const skip = config.correlationIdHeader?.toLowerCase();
|
|
2533
2533
|
const parts = [];
|
|
2534
2534
|
for (const k of Object.keys(config.headers).sort())
|
|
2535
2535
|
if (k !== skip && !CACHE_DIRECTIVE_HEADERS.has(k)) parts.push(`${k}:${config.headers[k]}`);
|
|
2536
2536
|
if (config.auth) parts.push(`auth:${config.auth.username}:${config.auth.password}`);
|
|
2537
2537
|
parts.push(`rt:${config.responseType ?? ""}`);
|
|
2538
|
+
parts.push(
|
|
2539
|
+
`shape:${fingerprint([config.transformResponse, config.responseEncoding, config.decompress])}`
|
|
2540
|
+
);
|
|
2541
|
+
if (scope === "dedupe") {
|
|
2542
|
+
parts.push(
|
|
2543
|
+
`policy:${fingerprint([
|
|
2544
|
+
config.timeout,
|
|
2545
|
+
config.totalTimeout,
|
|
2546
|
+
config.validateStatus,
|
|
2547
|
+
config.retry,
|
|
2548
|
+
config.breaker,
|
|
2549
|
+
config.adapter,
|
|
2550
|
+
config.maxContentLength,
|
|
2551
|
+
config.maxRedirects,
|
|
2552
|
+
config.transitional
|
|
2553
|
+
])}`
|
|
2554
|
+
);
|
|
2555
|
+
}
|
|
2538
2556
|
return `${requestTarget(config)} #${hash(parts.join("\n"))}`;
|
|
2539
2557
|
}
|
|
2558
|
+
var fnIds = /* @__PURE__ */ new WeakMap();
|
|
2559
|
+
var nextFnId = 0;
|
|
2560
|
+
function fingerprint(v) {
|
|
2561
|
+
if (typeof v === "function") {
|
|
2562
|
+
let id = fnIds.get(v);
|
|
2563
|
+
if (id === void 0) fnIds.set(v, id = ++nextFnId);
|
|
2564
|
+
return `f${id}`;
|
|
2565
|
+
}
|
|
2566
|
+
if (v === null || typeof v !== "object") return v === void 0 ? "u" : JSON.stringify(v);
|
|
2567
|
+
if (Array.isArray(v)) return `[${v.map(fingerprint).join(",")}]`;
|
|
2568
|
+
const o = v;
|
|
2569
|
+
return `{${Object.keys(o).filter((k) => o[k] !== void 0).sort().map((k) => `${k}:${fingerprint(o[k])}`).join(",")}}`;
|
|
2570
|
+
}
|
|
2540
2571
|
function keyURL(key) {
|
|
2541
2572
|
const sp = key.indexOf(" ");
|
|
2542
2573
|
const h = key.lastIndexOf(" #");
|
|
2543
2574
|
return sp > 0 && h > sp ? key.slice(sp + 1, h) : void 0;
|
|
2544
2575
|
}
|
|
2545
|
-
function keyFor(config, opts2) {
|
|
2576
|
+
function keyFor(config, opts2, scope = "cache") {
|
|
2546
2577
|
if (!opts2.methods.includes(config.method)) return void 0;
|
|
2547
2578
|
if (config.responseType === "stream") return void 0;
|
|
2548
2579
|
if (opts2.key) return opts2.key(config);
|
|
2549
2580
|
if (config.data !== void 0) return void 0;
|
|
2550
|
-
return defaultRequestKey(config);
|
|
2581
|
+
return defaultRequestKey(config, scope);
|
|
2551
2582
|
}
|
|
2552
2583
|
function checkMethods(name, m) {
|
|
2553
2584
|
if (!Array.isArray(m)) bad(name, m, "an array");
|
|
@@ -2592,12 +2623,46 @@ function parseCacheControl(value) {
|
|
|
2592
2623
|
function cloneData(data) {
|
|
2593
2624
|
if (data === null || typeof data !== "object") return { ok: true, value: data };
|
|
2594
2625
|
if (typeof structuredClone !== "function") return { ok: false, value: data };
|
|
2626
|
+
if (!clonesFaithfully(data, /* @__PURE__ */ new Set())) return { ok: false, value: data };
|
|
2595
2627
|
try {
|
|
2596
2628
|
return { ok: true, value: structuredClone(data) };
|
|
2597
2629
|
} catch {
|
|
2598
2630
|
return { ok: false, value: data };
|
|
2599
2631
|
}
|
|
2600
2632
|
}
|
|
2633
|
+
var proto = (v) => Object.getPrototypeOf(v);
|
|
2634
|
+
var VIEW_TYPES = [
|
|
2635
|
+
"Int8Array",
|
|
2636
|
+
"Uint8Array",
|
|
2637
|
+
"Uint8ClampedArray",
|
|
2638
|
+
"Int16Array",
|
|
2639
|
+
"Uint16Array",
|
|
2640
|
+
"Int32Array",
|
|
2641
|
+
"Uint32Array",
|
|
2642
|
+
"Float32Array",
|
|
2643
|
+
"Float64Array",
|
|
2644
|
+
"BigInt64Array",
|
|
2645
|
+
"BigUint64Array",
|
|
2646
|
+
"DataView"
|
|
2647
|
+
];
|
|
2648
|
+
var isType = (v, name) => {
|
|
2649
|
+
const C = globalThis[name];
|
|
2650
|
+
return typeof C === "function" && v instanceof C;
|
|
2651
|
+
};
|
|
2652
|
+
function clonesFaithfully(v, seen) {
|
|
2653
|
+
if (typeof v === "function" || typeof v === "symbol") return false;
|
|
2654
|
+
if (v === null || typeof v !== "object") return true;
|
|
2655
|
+
if (seen.has(v)) return true;
|
|
2656
|
+
seen.add(v);
|
|
2657
|
+
if (Array.isArray(v)) return proto(v) === Array.prototype && v.every((x) => clonesFaithfully(x, seen));
|
|
2658
|
+
if (v instanceof Map) return proto(v) === Map.prototype && [...v].every(([k, x]) => clonesFaithfully(k, seen) && clonesFaithfully(x, seen));
|
|
2659
|
+
if (v instanceof Set) return proto(v) === Set.prototype && [...v].every((x) => clonesFaithfully(x, seen));
|
|
2660
|
+
const p = proto(v);
|
|
2661
|
+
if (p === Object.prototype || p === null)
|
|
2662
|
+
return Object.values(v).every((x) => clonesFaithfully(x, seen));
|
|
2663
|
+
return p === Date.prototype || p === RegExp.prototype || p === ArrayBuffer.prototype || VIEW_TYPES.some((name) => p === globalThis[name]?.prototype) || // exact built-ins only: byte-array subclasses would come back as Uint8Array
|
|
2664
|
+
isType(v, "Blob") || isType(v, "FormData");
|
|
2665
|
+
}
|
|
2601
2666
|
function reportCacheError(op, err) {
|
|
2602
2667
|
if (typeof console !== "undefined") console.error(`[exios] cache provider ${op} failed:`, err);
|
|
2603
2668
|
}
|
|
@@ -2752,7 +2817,7 @@ var Exios = class {
|
|
|
2752
2817
|
const cacheCfg = resolveCache(config.cache);
|
|
2753
2818
|
const dedupeCfg = resolveDedupe(config.dedupe);
|
|
2754
2819
|
const cacheKey = cacheCfg ? keyFor(config, cacheCfg) : void 0;
|
|
2755
|
-
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg) : void 0;
|
|
2820
|
+
const dedupeKey = dedupeCfg ? keyFor(config, dedupeCfg, "dedupe") : void 0;
|
|
2756
2821
|
const provider = cacheCfg ? cacheCfg.provider ?? this.memoryCache : void 0;
|
|
2757
2822
|
const reqCC = cacheCfg && cacheCfg.respectCacheControl ? parseCacheControl(config.headers["cache-control"]) : void 0;
|
|
2758
2823
|
if (cacheKey !== void 0 && provider && !reqCC?.has("no-cache") && !reqCC?.has("no-store")) {
|
package/package.json
CHANGED