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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "configKey": "customFetch",
4
- "version": "2.0.2"
4
+ "version": "2.0.3"
5
5
  }
@@ -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;
@@ -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 key = hash(["custom|", url, ...generateOptionSegments(config)]);
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?.();
@@ -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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {