nuxt-custom-fetch 2.0.2 → 2.0.3
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/module.json +1 -1
- package/dist/runtime/ajax.d.ts +1 -0
- package/dist/runtime/ajax.mjs +7 -1
- package/dist/runtime/type.d.ts +1 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/runtime/ajax.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { HTTPConfig, Interceptors, FetchMethod, KeysOf, PickFrom } from './
|
|
|
4
4
|
type CustomFetchReturnValue<DataT, ErrorT> = AsyncData<PickFrom<DataT, KeysOf<DataT>> | null, (ErrorT extends Error | NuxtError<unknown> ? ErrorT : NuxtError<ErrorT>) | null>;
|
|
5
5
|
export declare class CustomFetch {
|
|
6
6
|
baseURL: any;
|
|
7
|
+
immutableKey: boolean;
|
|
7
8
|
params: HTTPConfig;
|
|
8
9
|
baseHandler: HTTPConfig['handler'];
|
|
9
10
|
interceptors: Interceptors;
|
package/dist/runtime/ajax.mjs
CHANGED
|
@@ -30,6 +30,7 @@ function pick(obj, keys) {
|
|
|
30
30
|
const _cachedController = /* @__PURE__ */ new Map();
|
|
31
31
|
export class CustomFetch {
|
|
32
32
|
baseURL;
|
|
33
|
+
immutableKey = false;
|
|
33
34
|
params = {};
|
|
34
35
|
baseHandler;
|
|
35
36
|
interceptors = {};
|
|
@@ -39,6 +40,7 @@ export class CustomFetch {
|
|
|
39
40
|
...config
|
|
40
41
|
};
|
|
41
42
|
this.baseURL = config.baseURL;
|
|
43
|
+
this.immutableKey = config.immutableKey ?? false;
|
|
42
44
|
if (config.handler) {
|
|
43
45
|
this.baseHandler = config.handler;
|
|
44
46
|
}
|
|
@@ -105,7 +107,11 @@ export class CustomFetch {
|
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
109
|
};
|
|
108
|
-
const
|
|
110
|
+
const hashValue = ["custom|", url];
|
|
111
|
+
if (!this.immutableKey) {
|
|
112
|
+
hashValue.push(...generateOptionSegments(config));
|
|
113
|
+
}
|
|
114
|
+
const key = hash(hashValue);
|
|
109
115
|
const handler = () => {
|
|
110
116
|
if (_cachedController.get(key)) {
|
|
111
117
|
_cachedController.get(key)?.abort?.();
|
package/dist/runtime/type.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface OnResponseErrorType {
|
|
|
23
23
|
export type FetchMethod = 'options' | 'GET' | 'POST' | 'get' | 'HEAD' | 'PATCH' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'post' | 'head' | 'patch' | 'put' | 'delete' | 'connect' | 'trace' | undefined;
|
|
24
24
|
export interface HTTPConfig extends Omit<FetchOptions, 'method'> {
|
|
25
25
|
key?: string;
|
|
26
|
+
immutableKey?: boolean;
|
|
26
27
|
baseURL?: string;
|
|
27
28
|
useHandler?: boolean;
|
|
28
29
|
handler?: (params: Record<string, any>) => Record<string, any>;
|