nuxt-custom-fetch 1.0.6-alpha.1 → 1.0.7
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 -0
- package/dist/module.json +1 -1
- package/dist/runtime/ajax.d.ts +9 -4
- package/dist/runtime/ajax.mjs +5 -5
- package/dist/runtime/type.d.ts +10 -11
- package/package.json +10 -10
package/README.md
CHANGED
package/dist/module.json
CHANGED
package/dist/runtime/ajax.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { FetchOptions } from 'ofetch';
|
|
2
1
|
import type { _AsyncData, AsyncDataOptions } from 'nuxt/dist/app/composables/asyncData';
|
|
3
2
|
import { HTTPConfig, Interceptors, AjaxConfig } from './type';
|
|
4
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>>;
|
|
@@ -7,7 +6,13 @@ export declare class HTTP {
|
|
|
7
6
|
interceptors: Interceptors;
|
|
8
7
|
constructor(config?: HTTPConfig);
|
|
9
8
|
private baseConfig;
|
|
10
|
-
http<DataT, ErrorT = Error | null>(url: string, config?:
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
http<DataT, ErrorT = Error | null>(url: string, config?: HTTPConfig & {
|
|
10
|
+
key?: string;
|
|
11
|
+
}, options?: AsyncDataOptions<DataT>): Promise<_AsyncData<DataT, ErrorT>>;
|
|
12
|
+
get<DataT, ErrorT = Error | null>(url: string, config?: HTTPConfig & {
|
|
13
|
+
key?: string;
|
|
14
|
+
}, options?: AsyncDataOptions<DataT>): Promise<_AsyncData<DataT, ErrorT>>;
|
|
15
|
+
post<DataT, ErrorT = Error | null>(url: string, config?: HTTPConfig & {
|
|
16
|
+
key?: string;
|
|
17
|
+
}, options?: AsyncDataOptions<DataT>): Promise<_AsyncData<DataT, ErrorT>>;
|
|
13
18
|
}
|
package/dist/runtime/ajax.mjs
CHANGED
|
@@ -7,7 +7,6 @@ export const ajax = (url, key, config, options) => {
|
|
|
7
7
|
}
|
|
8
8
|
const { onRequest, onRequestError, onResponse, onResponseError, interceptors, ...restAjaxConfig } = config;
|
|
9
9
|
const defaultOptions = {
|
|
10
|
-
key,
|
|
11
10
|
onRequest(ctx) {
|
|
12
11
|
[interceptors.onRequest, onRequest].map((fn) => fn && fn(ctx));
|
|
13
12
|
},
|
|
@@ -36,7 +35,8 @@ export const ajax = (url, key, config, options) => {
|
|
|
36
35
|
};
|
|
37
36
|
return useAsyncData(key, () => $fetch(url, {
|
|
38
37
|
...defaultOptions,
|
|
39
|
-
...restAjaxConfig
|
|
38
|
+
...restAjaxConfig,
|
|
39
|
+
method: restAjaxConfig.method
|
|
40
40
|
}), options);
|
|
41
41
|
};
|
|
42
42
|
function getKey(url, config, extraParams = []) {
|
|
@@ -77,7 +77,7 @@ export class HTTP {
|
|
|
77
77
|
return { ...params };
|
|
78
78
|
}
|
|
79
79
|
http(url, config = {}, options) {
|
|
80
|
-
const key = getKey(url, config, this.params.extraParams);
|
|
80
|
+
const key = config.key ? config.key : getKey(url, config, this.params.extraParams);
|
|
81
81
|
const query = this.baseConfig(config);
|
|
82
82
|
return ajax(url, key, {
|
|
83
83
|
baseURL: this.params.baseURL,
|
|
@@ -88,9 +88,9 @@ export class HTTP {
|
|
|
88
88
|
}, options);
|
|
89
89
|
}
|
|
90
90
|
get(url, config = {}, options) {
|
|
91
|
-
return this.http(url, { method: "GET"
|
|
91
|
+
return this.http(url, { ...config, method: "GET" }, options);
|
|
92
92
|
}
|
|
93
93
|
post(url, config = {}, options) {
|
|
94
|
-
return this.http(url, { method: "POST"
|
|
94
|
+
return this.http(url, { ...config, method: "POST" }, options);
|
|
95
95
|
}
|
|
96
96
|
}
|
package/dist/runtime/type.d.ts
CHANGED
|
@@ -18,23 +18,22 @@ export interface OnResponseErrorType {
|
|
|
18
18
|
options: FetchOptions;
|
|
19
19
|
response: FetchResponse<any>;
|
|
20
20
|
}
|
|
21
|
-
export type
|
|
21
|
+
export type FetchMethod = 'options' | 'GET' | 'POST' | 'get' | 'HEAD' | 'PATCH' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'post' | 'head' | 'patch' | 'put' | 'delete' | 'connect' | 'trace' | undefined;
|
|
22
|
+
export interface HTTPConfig extends Omit<FetchOptions, 'method'> {
|
|
22
23
|
baseURL?: string;
|
|
23
24
|
extraParams?: string[];
|
|
24
|
-
paramsHandler?: (params: FetchOptions['params']) =>
|
|
25
|
+
paramsHandler?: (params: FetchOptions['params']) => HTTPConfig;
|
|
25
26
|
offline?: () => void;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
onResponse?: ({ request, response, options }: OnResponseType) => Promise<void> | void;
|
|
29
|
-
onResponseError?: ({ request, response, options }: OnResponseErrorType) => void;
|
|
30
|
-
};
|
|
27
|
+
method?: FetchMethod;
|
|
28
|
+
}
|
|
31
29
|
export interface Interceptors {
|
|
32
|
-
onRequest?:
|
|
33
|
-
onRequestError?:
|
|
34
|
-
onResponse?:
|
|
35
|
-
onResponseError?:
|
|
30
|
+
onRequest?: FetchOptions['onRequest'];
|
|
31
|
+
onRequestError?: FetchOptions['onRequestError'];
|
|
32
|
+
onResponse?: FetchOptions['onResponse'];
|
|
33
|
+
onResponseError?: FetchOptions['onResponseError'];
|
|
36
34
|
}
|
|
37
35
|
export type AjaxConfig = FetchOptions & {
|
|
36
|
+
key?: string;
|
|
38
37
|
extraParams?: string[];
|
|
39
38
|
offline?: () => void;
|
|
40
39
|
interceptors: Interceptors;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-custom-fetch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "https://github.com/xjccc/nuxt-custom-fetch.git"
|
|
20
20
|
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"prepack": "nuxt-module-build",
|
|
23
|
+
"dev": "nuxi dev playground",
|
|
24
|
+
"dev:build": "nuxi build playground",
|
|
25
|
+
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
|
|
26
|
+
},
|
|
21
27
|
"dependencies": {
|
|
22
|
-
"@nuxt/kit": "^3.0.0"
|
|
23
|
-
"nuxt-custom-fetch": "1.0.6-alpha.1"
|
|
28
|
+
"@nuxt/kit": "^3.0.0"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"@nuxt/module-builder": "^0.2.1",
|
|
27
32
|
"@nuxt/schema": "^3.0.0",
|
|
28
33
|
"@nuxtjs/eslint-config-typescript": "^12.0.0",
|
|
29
34
|
"eslint": "^8.29.0",
|
|
30
|
-
"nuxt": "^3.
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"dev": "nuxi dev playground",
|
|
34
|
-
"dev:build": "nuxi build playground",
|
|
35
|
-
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
|
|
35
|
+
"nuxt": "^3.1.1"
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
}
|