nuxt-custom-fetch 1.0.8 → 1.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 CHANGED
@@ -6,11 +6,13 @@
6
6
 
7
7
  实例化全局 CustomFetch
8
8
 
9
- ```
10
- baseURL?: string
11
- paramsHandler?: (params: FetchOptions['params']) => FetchOptions & HTTPConfig
12
- extraParams?: string[]
13
- offline?: () => void
9
+ ```ts
10
+ {
11
+ baseURL?: string
12
+ paramsHandler?: (params: FetchOptions['params']) => FetchOptions & HTTPConfig
13
+ extraParams?: string[]
14
+ offline?: () => void
15
+ }
14
16
  ```
15
17
 
16
18
  ### baseURL
@@ -28,8 +30,9 @@ offline?: () => void
28
30
 
29
31
  ### 请求-响应拦截
30
32
 
31
- ```
32
- onRequest?: ({ request, options }: {
33
+ ```ts
34
+ {
35
+ onRequest?: ({ request, options }: {
33
36
  request: FetchRequest
34
37
  options: FetchOptions
35
38
  }) => void
@@ -60,6 +63,7 @@ onRequest?: ({ request, options }: {
60
63
  options: FetchOptions
61
64
  response: FetchResponse<any>
62
65
  }) => void
66
+ }
63
67
  ```
64
68
 
65
69
  ## 实例方法
@@ -83,45 +87,65 @@ const key = hash(JSON.stringify(restConfig) + url)
83
87
 
84
88
  ### fetchOptions
85
89
 
86
- ```
87
- baseURL?: string;
88
- key?: string;
89
- body?: RequestInit["body"] | Record<string, any>;
90
- useParamsHandler: HTTPConfig['paramsHandler'];
91
- paramsHandler: HTTPConfig['paramsHandler'];
92
- params?: SearchParameters;
93
- query?: SearchParameters;
94
- parseResponse?: (responseText: string) => any;
95
- responseType?: R;
96
- response?: boolean;
97
- retry?: number | false;
98
- onRequest?(context: FetchContext): Promise<void> | void;
99
- onRequestError?(context: FetchContext & {
100
- error: Error;
101
- }): Promise<void> | void;
102
- onResponse?(context: FetchContext & {
103
- response: FetchResponse<R>;
104
- }): Promise<void> | void;
105
- onResponseError?(context: FetchContext & {
106
- response: FetchResponse<R>;
107
- }): Promise<void> | void;
90
+ ```ts
91
+ interface fetchOptions {
92
+ baseURL?: string
93
+ key?: string
94
+ body?: RequestInit['body'] | Record<string, any>
95
+ useParamsHandler: HTTPConfig['paramsHandler']
96
+ paramsHandler: HTTPConfig['paramsHandler']
97
+ params?: SearchParameters
98
+ query?: SearchParameters
99
+ parseResponse?: (responseText: string) => any
100
+ responseType?: R
101
+ response?: boolean
102
+ retry?: number | false
103
+ onRequest?(context: FetchContext): Promise<void> | void
104
+ onRequestError?(
105
+ context: FetchContext & {
106
+ error: Error
107
+ }
108
+ ): Promise<void> | void
109
+ onResponse?(
110
+ context: FetchContext & {
111
+ response: FetchResponse<R>
112
+ }
113
+ ): Promise<void> | void
114
+ onResponseError?(
115
+ context: FetchContext & {
116
+ response: FetchResponse<R>
117
+ }
118
+ ): Promise<void> | void
119
+ }
108
120
  ```
109
121
 
110
- ### AsyncDataOptions<DataT>
122
+ ### AsyncDataOptions
111
123
 
112
- ```
113
- server?: boolean;
114
- lazy?: boolean;
115
- default?: () => DataT | Ref<DataT> | null;
116
- transform?: Transform;
117
- pick?: PickKeys;
118
- watch?: MultiWatchSources;
119
- immediate?: boolean;
124
+ ```ts
125
+ // AsyncDataOptions<DataT>
126
+ {
127
+ server?: boolean;
128
+ lazy?: boolean;
129
+ default?: () => DataT | Ref<DataT> | null;
130
+ transform?: Transform;
131
+ pick?: PickKeys;
132
+ watch?: MultiWatchSources;
133
+ immediate?: boolean;
134
+ }
120
135
  ```
121
136
 
122
137
  ## 使用方式
123
138
 
139
+ ```bash
140
+ pnpm add nuxt-custom-fetch
141
+ ```
142
+
124
143
  ```ts
144
+ // nuxt.config.ts
145
+ export default defineNuxtConfig({
146
+ modules: ['nuxt-custom-fetch']
147
+ })
148
+
125
149
  // ajax.ts文件
126
150
  import type { FetchOptions } from 'ofetch'
127
151
  const ajax = new CustomFetch({
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "configKey": "customFetch",
4
- "version": "1.0.8"
4
+ "version": "1.1.1"
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import type { _AsyncData, AsyncDataOptions } from 'nuxt/dist/app/composables/asyncData';
2
- import { HTTPConfig, Interceptors, AjaxConfig } from './type';
3
- export declare const ajax: <DataT, ErrorT = Error | null>(url: string, key: string, config: AjaxConfig, options?: AsyncDataOptions<DataT, import("nuxt/dist/app/composables/asyncData")._Transform<DataT, DataT>, import("nuxt/dist/app/composables/asyncData").KeyOfRes<import("nuxt/dist/app/composables/asyncData")._Transform<DataT, DataT>>> | undefined) => Promise<_AsyncData<DataT, ErrorT>>;
2
+ import type { HTTPConfig, Interceptors, AjaxConfig } from './type';
3
+ export declare const ajax: <DataT, ErrorT = Error | null>(url: string, key: string, config: AjaxConfig, options?: AsyncDataOptions<DataT, DataT, import("nuxt/dist/app/composables/asyncData").KeysOf<DataT>, null> | undefined) => Promise<_AsyncData<DataT, ErrorT>>;
4
4
  export declare class CustomFetch {
5
5
  baseURL: any;
6
6
  params: HTTPConfig;
@@ -53,10 +53,12 @@ function getKey(url, config, extraParams = []) {
53
53
  const Noop = () => {
54
54
  };
55
55
  export class CustomFetch {
56
+ baseURL;
57
+ params = {};
58
+ baseParamsHandler;
59
+ interceptors = {};
60
+ offline = Noop;
56
61
  constructor(config = { baseURL: "" }) {
57
- this.params = {};
58
- this.interceptors = {};
59
- this.offline = Noop;
60
62
  this.params = {
61
63
  ...config
62
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -25,13 +25,13 @@
25
25
  "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
26
26
  },
27
27
  "dependencies": {
28
- "@nuxt/kit": "^3.0.0"
28
+ "@nuxt/kit": "^3.8.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@nuxt/module-builder": "^0.2.1",
32
- "@nuxt/schema": "^3.0.0",
33
- "@nuxtjs/eslint-config-typescript": "^12.0.0",
34
- "eslint": "^8.29.0",
35
- "nuxt": "^3.1.1"
32
+ "@nuxt/schema": "^3.8.1",
33
+ "@nuxtjs/eslint-config-typescript": "^12.1.0",
34
+ "eslint": "^8.53.0",
35
+ "nuxt": "^3.8.1"
36
36
  }
37
37
  }