@varlet/axle 0.2.6 → 0.2.7-alpha.1701535975035

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/es/use.js CHANGED
@@ -1,92 +1,183 @@
1
- import { ref } from 'vue';
2
- import { isFunction } from '@varlet/shared';
3
- export function createUseAxle(options) {
4
- const { axle, onTransform: defaultOnTransform } = options;
5
- const useAxle = (options) => {
6
- var _a;
7
- const { url, method, immediate, value: initialValue, resetValue: initialResetValue, params: initialParamsOrGetter, config: initialConfig, retry = 0, onBefore = () => { }, onAfter = () => { }, onTransform = (_a = defaultOnTransform) !== null && _a !== void 0 ? _a : ((response) => response), onSuccess = () => { }, onError = () => { }, } = options;
8
- const initialUrl = url;
9
- const value = ref(initialValue);
10
- const loading = ref(false);
11
- const error = ref();
12
- const downloadProgress = ref(0);
13
- const uploadProgress = ref(0);
14
- const shouldRetry = retry > 0;
15
- const refs = {
16
- value,
17
- loading,
18
- error,
19
- downloadProgress,
20
- uploadProgress,
21
- };
22
- let controller = new AbortController();
23
- const run = async (options = {}) => {
24
- var _a, _b, _c;
25
- if (controller.signal.aborted) {
26
- controller = new AbortController();
27
- }
28
- const resetValue = (_b = (_a = options.resetValue) !== null && _a !== void 0 ? _a : initialResetValue) !== null && _b !== void 0 ? _b : false;
29
- if (resetValue === true) {
30
- value.value = initialValue;
31
- }
32
- uploadProgress.value = 0;
33
- downloadProgress.value = 0;
34
- const url = (_c = options.url) !== null && _c !== void 0 ? _c : initialUrl;
35
- onBefore(refs);
36
- loading.value = true;
37
- try {
38
- const getterParams = isFunction(initialParamsOrGetter) ? initialParamsOrGetter() : {};
39
- const response = await axle[method](url, Object.assign(Object.assign({}, getterParams), options.params), Object.assign({ signal: controller.signal, onUploadProgress(event) {
40
- var _a;
41
- uploadProgress.value = (_a = event.progress) !== null && _a !== void 0 ? _a : 0;
42
- },
43
- onDownloadProgress(event) {
44
- var _a;
45
- downloadProgress.value = (_a = event.progress) !== null && _a !== void 0 ? _a : 0;
46
- } }, options.config));
47
- value.value = onTransform(response, refs);
48
- error.value = undefined;
49
- onSuccess(response, refs);
50
- loading.value = false;
51
- onAfter(refs);
52
- return response;
53
- }
54
- catch (responseError) {
55
- const currentRetryCount = options._retryCount == null ? 0 : options._retryCount;
56
- if (shouldRetry && currentRetryCount < retry) {
57
- return run(Object.assign(Object.assign({}, options), { _retryCount: currentRetryCount + 1 }));
58
- }
59
- error.value = responseError;
60
- onError(responseError, refs);
61
- loading.value = false;
62
- onAfter(refs);
63
- throw responseError;
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/use.ts
22
+ import { ref as ref3 } from "vue";
23
+ import { isFunction } from "@varlet/shared";
24
+
25
+ // src/useValues.ts
26
+ import { computed } from "vue";
27
+ function useValues(...valueCollection) {
28
+ return computed({
29
+ get: () => valueCollection.map((value) => value.value),
30
+ set(values) {
31
+ valueCollection.forEach((value, index) => {
32
+ value.value = values[index];
33
+ });
34
+ }
35
+ });
36
+ }
37
+
38
+ // src/useHasLoading.ts
39
+ import { ref, watch } from "vue";
40
+ function useHasLoading(...loadings) {
41
+ const hasLoading = ref(false);
42
+ watch(
43
+ () => loadings.map((loading) => loading.value),
44
+ (newLoadings) => {
45
+ hasLoading.value = newLoadings.some(Boolean);
46
+ },
47
+ { immediate: true }
48
+ );
49
+ return hasLoading;
50
+ }
51
+
52
+ // src/useAverageProgress.ts
53
+ import { ref as ref2, watch as watch2 } from "vue";
54
+ function useAverageProgress(...progressCollection) {
55
+ const averageProgress = ref2(0);
56
+ watch2(
57
+ () => progressCollection.map((progress) => progress.value),
58
+ (newProgressCollection) => {
59
+ const total = newProgressCollection.reduce((total2, progress) => total2 + progress, 0);
60
+ averageProgress.value = total / progressCollection.length;
61
+ },
62
+ { immediate: true }
63
+ );
64
+ return averageProgress;
65
+ }
66
+
67
+ // src/use.ts
68
+ function createUseAxle(options) {
69
+ const { axle, onTransform: defaultOnTransform } = options;
70
+ const useAxle = (options2) => {
71
+ const {
72
+ url,
73
+ method,
74
+ immediate,
75
+ value: initialValue,
76
+ resetValue: initialResetValue,
77
+ params: initialParamsOrGetter,
78
+ config: initialConfig,
79
+ retry = 0,
80
+ onBefore = () => {
81
+ },
82
+ onAfter = () => {
83
+ },
84
+ onTransform = defaultOnTransform != null ? defaultOnTransform : (response) => response,
85
+ onSuccess = () => {
86
+ },
87
+ onError = () => {
88
+ }
89
+ } = options2;
90
+ const initialUrl = url;
91
+ const value = ref3(initialValue);
92
+ const loading = ref3(false);
93
+ const error = ref3();
94
+ const downloadProgress = ref3(0);
95
+ const uploadProgress = ref3(0);
96
+ const shouldRetry = retry > 0;
97
+ const refs = {
98
+ value,
99
+ loading,
100
+ error,
101
+ downloadProgress,
102
+ uploadProgress
103
+ };
104
+ let controller = new AbortController();
105
+ const run = async (options3 = {}) => {
106
+ var _a, _b, _c;
107
+ if (controller.signal.aborted) {
108
+ controller = new AbortController();
109
+ }
110
+ const resetValue = (_b = (_a = options3.resetValue) != null ? _a : initialResetValue) != null ? _b : false;
111
+ if (resetValue === true) {
112
+ value.value = initialValue;
113
+ }
114
+ uploadProgress.value = 0;
115
+ downloadProgress.value = 0;
116
+ const url2 = (_c = options3.url) != null ? _c : initialUrl;
117
+ onBefore(refs);
118
+ loading.value = true;
119
+ try {
120
+ const getterParams = isFunction(initialParamsOrGetter) ? initialParamsOrGetter() : {};
121
+ const response = await axle[method](
122
+ url2,
123
+ __spreadValues(__spreadValues({}, getterParams), options3.params),
124
+ __spreadValues({
125
+ signal: controller.signal,
126
+ onUploadProgress(event) {
127
+ var _a2;
128
+ uploadProgress.value = (_a2 = event.progress) != null ? _a2 : 0;
129
+ },
130
+ onDownloadProgress(event) {
131
+ var _a2;
132
+ downloadProgress.value = (_a2 = event.progress) != null ? _a2 : 0;
64
133
  }
65
- };
66
- const abort = () => {
67
- controller.abort();
68
- };
69
- if (immediate) {
70
- run({
71
- url: initialUrl,
72
- params: isFunction(initialParamsOrGetter) ? {} : initialParamsOrGetter,
73
- config: initialConfig,
74
- });
134
+ }, options3.config)
135
+ );
136
+ value.value = onTransform(response, refs);
137
+ error.value = void 0;
138
+ onSuccess(response, refs);
139
+ loading.value = false;
140
+ onAfter(refs);
141
+ return response;
142
+ } catch (responseError) {
143
+ const currentRetryCount = options3._retryCount == null ? 0 : options3._retryCount;
144
+ if (shouldRetry && currentRetryCount < retry) {
145
+ return run(__spreadProps(__spreadValues({}, options3), { _retryCount: currentRetryCount + 1 }));
75
146
  }
76
- return [
77
- value,
78
- run,
79
- {
80
- loading,
81
- error,
82
- uploadProgress,
83
- downloadProgress,
84
- abort,
85
- },
86
- ];
147
+ error.value = responseError;
148
+ onError(responseError, refs);
149
+ loading.value = false;
150
+ onAfter(refs);
151
+ throw responseError;
152
+ }
153
+ };
154
+ const abort = () => {
155
+ controller.abort();
87
156
  };
88
- return useAxle;
157
+ if (immediate) {
158
+ run({
159
+ url: initialUrl,
160
+ params: isFunction(initialParamsOrGetter) ? {} : initialParamsOrGetter,
161
+ config: initialConfig
162
+ });
163
+ }
164
+ return [
165
+ value,
166
+ run,
167
+ {
168
+ loading,
169
+ error,
170
+ uploadProgress,
171
+ downloadProgress,
172
+ abort
173
+ }
174
+ ];
175
+ };
176
+ return useAxle;
89
177
  }
90
- export * from './useValues.js';
91
- export * from './useHasLoading.js';
92
- export * from './useAverageProgress.js';
178
+ export {
179
+ createUseAxle,
180
+ useAverageProgress,
181
+ useHasLoading,
182
+ useValues
183
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.2.6",
3
+ "version": "0.2.7-alpha.1701535975035",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "type": "module",
6
6
  "main": "es/index.js",
@@ -24,21 +24,45 @@
24
24
  "keywords": [
25
25
  "axle",
26
26
  "axios",
27
- "helpers"
27
+ "helpers",
28
+ "vue3",
29
+ "composition api"
28
30
  ],
29
31
  "author": "haoziqaq <357229046@qq.com>",
30
32
  "license": "MIT",
33
+ "simple-git-hooks": {
34
+ "pre-commit": "pnpm exec nano-staged --allow-empty --concurrent false",
35
+ "commit-msg": "pnpm exec commitlint -e $1"
36
+ },
37
+ "nano-staged": {
38
+ "*.{vue,ts,tsx,js,jsx,less,css}": "pnpm format",
39
+ "*.{vue,ts,tsx,js,jsx}": "pnpm lint"
40
+ },
31
41
  "dependencies": {
32
42
  "@varlet/shared": "^2.19.2",
33
43
  "axios": "^1.4.0",
44
+ "micromatch": "^4.0.5",
45
+ "minimatch": "^9.0.3",
34
46
  "qs": "^6.11.0"
35
47
  },
48
+ "peerDependencies": {
49
+ "vue": "^3.2.0"
50
+ },
36
51
  "devDependencies": {
37
- "@types/qs": "^6.9.7",
38
- "@varlet/release": "0.0.3",
52
+ "tsup": "7.2.0",
53
+ "nano-staged": "0.8.0",
39
54
  "rimraf": "^5.0.1",
55
+ "simple-git-hooks": "^2.8.1",
40
56
  "typescript": "^5.1.5",
41
- "vue": "3.3.4"
57
+ "vue": "3.3.4",
58
+ "eslint": "^8.43.0",
59
+ "prettier": "^2.8.8",
60
+ "@varlet/release": "0.0.3",
61
+ "@varlet/eslint-config": "^2.19.2",
62
+ "@commitlint/cli": "^17.6.5",
63
+ "@commitlint/config-conventional": "^17.6.5",
64
+ "@types/minimatch": "^5.1.2",
65
+ "@types/qs": "^6.9.7"
42
66
  },
43
67
  "repository": {
44
68
  "type": "git",
@@ -52,9 +76,14 @@
52
76
  "pnpm": ">=8.0"
53
77
  },
54
78
  "scripts": {
79
+ "preinstall": "npx only-allow pnpm",
80
+ "postinstall": "simple-git-hooks",
55
81
  "bootstrap": "pnpm i && pnpm build && pnpm --filter ./playground i",
56
- "dev": "tsc -w",
57
- "build": "rimraf ./es && tsc",
82
+ "dev": "tsup src/index.ts, src/use.ts --format esm --out-dir=es --watch --dts",
83
+ "build": "tsup src/index.ts, src/use.ts --format esm --out-dir=es --dts --clean",
84
+ "dev:play": "pnpm --dir ./playground dev",
85
+ "lint": "eslint . --fix",
86
+ "format": "prettier --write .",
58
87
  "release": "pnpm build && vr release"
59
88
  }
60
89
  }
package/es/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './instance.js';
2
- export * from './interceptors';
package/es/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './instance.js';
2
- export * from './interceptors';
package/es/instance.d.ts DELETED
@@ -1,61 +0,0 @@
1
- import type { AxiosInstance, AxiosInterceptorOptions, AxiosRequestConfig, AxiosResponse, HeadersDefaults, InternalAxiosRequestConfig, ResponseType } from 'axios';
2
- export type AxleRequestConfig = AxiosRequestConfig & {
3
- exceptionMessage?: any;
4
- };
5
- export type FetchRunner = <T = any, R = AxiosResponse<T>>(url: string, params?: any, config?: AxleRequestConfig) => Promise<R>;
6
- export type ModifyRunner = <T = any, R = AxiosResponse<T>>(url: string, params?: any, config?: AxleRequestConfig) => Promise<R>;
7
- export type FetchMethod = 'get' | 'delete' | 'options' | 'head';
8
- export type ModifyMethod = 'post' | 'put' | 'patch';
9
- export type RunnerMethod = keyof Omit<AxleInstance, 'axios' | 'getHeaders' | 'setHeader' | 'removeHeader' | 'useRequestInterceptor' | 'useResponseInterceptor'>;
10
- export interface Interceptor<V> {
11
- onFulfilled?: ((value: V) => any) | null;
12
- onRejected?: ((error: any) => any) | null;
13
- options?: AxiosInterceptorOptions;
14
- }
15
- export type RequestInterceptor = Interceptor<InternalAxiosRequestConfig>;
16
- export type ResponseInterceptor<V = AxiosResponse<any, any>> = Interceptor<V>;
17
- export type AxleInstance = {
18
- get: FetchRunner;
19
- getBlob: FetchRunner;
20
- getDocument: FetchRunner;
21
- getText: FetchRunner;
22
- getArrayBuffer: FetchRunner;
23
- getStream: FetchRunner;
24
- head: FetchRunner;
25
- headBlob: FetchRunner;
26
- headDocument: FetchRunner;
27
- headText: FetchRunner;
28
- headArrayBuffer: FetchRunner;
29
- headStream: FetchRunner;
30
- options: FetchRunner;
31
- optionsBlob: FetchRunner;
32
- optionsDocument: FetchRunner;
33
- optionsText: FetchRunner;
34
- optionsArrayBuffer: FetchRunner;
35
- optionsStream: FetchRunner;
36
- delete: FetchRunner;
37
- deleteBlob: FetchRunner;
38
- deleteDocument: FetchRunner;
39
- deleteText: FetchRunner;
40
- deleteArrayBuffer: FetchRunner;
41
- deleteStream: FetchRunner;
42
- post: ModifyRunner;
43
- postUrlEncode: ModifyRunner;
44
- postMultipart: ModifyRunner;
45
- put: ModifyRunner;
46
- putUrlEncode: ModifyRunner;
47
- putMultipart: ModifyRunner;
48
- patch: ModifyRunner;
49
- patchUrlEncode: ModifyRunner;
50
- patchMultipart: ModifyRunner;
51
- getHeaders(): HeadersDefaults['common'];
52
- setHeader(key: string, value: string): void;
53
- removeHeader(key: string | string[]): void;
54
- useRequestInterceptor(...interceptors: RequestInterceptor[]): void;
55
- useResponseInterceptor(...interceptors: ResponseInterceptor[]): void;
56
- axios: AxiosInstance;
57
- };
58
- export declare function createFetchRunner(service: AxiosInstance, method: FetchMethod, responseType: ResponseType): <T, R = AxiosResponse<T, any>>(url: string, params?: any, config?: AxleRequestConfig) => Promise<R>;
59
- export declare function createModifyRunner(service: AxiosInstance, method: ModifyMethod, contentType: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded'): <T, R = AxiosResponse<T, any>>(url: string, params?: any, config?: AxleRequestConfig) => Promise<R>;
60
- export declare function download(url: string | Blob, filename: string): void;
61
- export declare function createAxle(config?: AxiosRequestConfig): AxleInstance;
package/es/instance.js DELETED
@@ -1,105 +0,0 @@
1
- import axios from 'axios';
2
- import qs from 'qs';
3
- import { inBrowser } from '@varlet/shared';
4
- export function createFetchRunner(service, method, responseType) {
5
- return function (url, params, config) {
6
- return service[method](url, Object.assign({ params,
7
- responseType }, config));
8
- };
9
- }
10
- export function createModifyRunner(service, method, contentType) {
11
- return function (url, params, config) {
12
- if (contentType === 'application/x-www-form-urlencoded') {
13
- params = qs.stringify(params);
14
- }
15
- if (contentType === 'multipart/form-data') {
16
- const formData = new FormData();
17
- Object.keys(params).forEach((key) => formData.append(key, params[key]));
18
- params = formData;
19
- }
20
- return service[method](url, params, Object.assign({ headers: {
21
- 'Content-Type': contentType,
22
- } }, config));
23
- };
24
- }
25
- export function download(url, filename) {
26
- if (!inBrowser()) {
27
- return;
28
- }
29
- const a = document.createElement('a');
30
- a.download = filename;
31
- a.style.display = 'none';
32
- a.href = typeof url === 'string' ? url : URL.createObjectURL(url);
33
- document.body.appendChild(a);
34
- a.click();
35
- URL.revokeObjectURL(a.href);
36
- document.body.removeChild(a);
37
- }
38
- export function createAxle(config = {}) {
39
- const service = axios.create(config);
40
- function getHeaders() {
41
- return service.defaults.headers['common'];
42
- }
43
- function setHeader(key, value) {
44
- ;
45
- service.defaults.headers['common'][key] = value;
46
- }
47
- function removeHeader(key) {
48
- if (typeof key === 'string') {
49
- Reflect.deleteProperty(service.defaults.headers['common'], key);
50
- return;
51
- }
52
- key.forEach((k) => Reflect.deleteProperty(service.defaults.headers['common'], k));
53
- }
54
- function useRequestInterceptor(...interceptors) {
55
- interceptors.forEach((interceptor) => {
56
- service.interceptors.request.use(interceptor.onFulfilled, interceptor.onRejected, interceptor.options);
57
- });
58
- }
59
- function useResponseInterceptor(...interceptors) {
60
- interceptors.forEach((interceptor) => {
61
- service.interceptors.response.use(interceptor.onFulfilled, interceptor.onRejected, interceptor.options);
62
- });
63
- }
64
- return {
65
- get: createFetchRunner(service, 'get', 'json'),
66
- getBlob: createFetchRunner(service, 'get', 'blob'),
67
- getDocument: createFetchRunner(service, 'get', 'document'),
68
- getArrayBuffer: createFetchRunner(service, 'get', 'arraybuffer'),
69
- getText: createFetchRunner(service, 'get', 'text'),
70
- getStream: createFetchRunner(service, 'get', 'stream'),
71
- head: createFetchRunner(service, 'head', 'json'),
72
- headBlob: createFetchRunner(service, 'head', 'blob'),
73
- headDocument: createFetchRunner(service, 'head', 'document'),
74
- headArrayBuffer: createFetchRunner(service, 'head', 'arraybuffer'),
75
- headText: createFetchRunner(service, 'head', 'text'),
76
- headStream: createFetchRunner(service, 'head', 'stream'),
77
- options: createFetchRunner(service, 'options', 'json'),
78
- optionsBlob: createFetchRunner(service, 'options', 'blob'),
79
- optionsDocument: createFetchRunner(service, 'options', 'document'),
80
- optionsArrayBuffer: createFetchRunner(service, 'options', 'arraybuffer'),
81
- optionsText: createFetchRunner(service, 'options', 'text'),
82
- optionsStream: createFetchRunner(service, 'options', 'stream'),
83
- delete: createFetchRunner(service, 'delete', 'json'),
84
- deleteBlob: createFetchRunner(service, 'delete', 'blob'),
85
- deleteDocument: createFetchRunner(service, 'delete', 'document'),
86
- deleteArrayBuffer: createFetchRunner(service, 'delete', 'arraybuffer'),
87
- deleteText: createFetchRunner(service, 'delete', 'text'),
88
- deleteStream: createFetchRunner(service, 'delete', 'stream'),
89
- post: createModifyRunner(service, 'post', 'application/json'),
90
- postUrlEncode: createModifyRunner(service, 'post', 'application/x-www-form-urlencoded'),
91
- postMultipart: createModifyRunner(service, 'post', 'multipart/form-data'),
92
- put: createModifyRunner(service, 'put', 'application/json'),
93
- putUrlEncode: createModifyRunner(service, 'put', 'application/x-www-form-urlencoded'),
94
- putMultipart: createModifyRunner(service, 'put', 'multipart/form-data'),
95
- patch: createModifyRunner(service, 'patch', 'application/json'),
96
- patchUrlEncode: createModifyRunner(service, 'patch', 'application/x-www-form-urlencoded'),
97
- patchMultipart: createModifyRunner(service, 'patch', 'multipart/form-data'),
98
- getHeaders,
99
- setHeader,
100
- removeHeader,
101
- useRequestInterceptor,
102
- useResponseInterceptor,
103
- axios: service,
104
- };
105
- }
@@ -1,3 +0,0 @@
1
- export * from './requestHeadersInterceptor';
2
- export * from './responseBlobInterceptor';
3
- export * from './responseTimeoutInterceptor';
@@ -1,3 +0,0 @@
1
- export * from './requestHeadersInterceptor';
2
- export * from './responseBlobInterceptor';
3
- export * from './responseTimeoutInterceptor';
@@ -1,7 +0,0 @@
1
- import type { RequestInterceptor } from '../instance';
2
- import type { AxiosInterceptorOptions } from 'axios';
3
- export interface RequestHeadersInterceptorOptions {
4
- headers?: Record<string, string> | (() => Record<string, string>);
5
- axiosInterceptorOptions?: AxiosInterceptorOptions;
6
- }
7
- export declare function requestHeadersInterceptor(options?: RequestHeadersInterceptorOptions): RequestInterceptor;
@@ -1,18 +0,0 @@
1
- import { isFunction } from '@varlet/shared';
2
- export function requestHeadersInterceptor(options = {}) {
3
- const { headers: headersOrGetter } = options;
4
- return {
5
- onFulfilled(config) {
6
- var _a;
7
- const headers = (_a = (isFunction(headersOrGetter) ? headersOrGetter() : headersOrGetter)) !== null && _a !== void 0 ? _a : {};
8
- Object.entries(headers).forEach(([key, value]) => {
9
- config.headers[key] = value;
10
- });
11
- return config;
12
- },
13
- onRejected(error) {
14
- return Promise.reject(error);
15
- },
16
- options: options.axiosInterceptorOptions,
17
- };
18
- }
@@ -1,7 +0,0 @@
1
- import type { AxiosInterceptorOptions, AxiosResponse } from 'axios';
2
- import type { ResponseInterceptor } from '../instance';
3
- export interface ResponseBlobInterceptorOptions {
4
- onResponse?: (response: AxiosResponse<any, any>) => any;
5
- axiosInterceptorOptions?: AxiosInterceptorOptions;
6
- }
7
- export declare function responseBlobInterceptor(options?: ResponseBlobInterceptorOptions): ResponseInterceptor;
@@ -1,15 +0,0 @@
1
- export function responseBlobInterceptor(options = {}) {
2
- return {
3
- onFulfilled(response) {
4
- var _a, _b;
5
- if (response.request.responseType === 'blob') {
6
- return (_b = (_a = options.onResponse) === null || _a === void 0 ? void 0 : _a.call(options, response)) !== null && _b !== void 0 ? _b : response;
7
- }
8
- return response;
9
- },
10
- onRejected(error) {
11
- return Promise.reject(error);
12
- },
13
- options: options.axiosInterceptorOptions,
14
- };
15
- }
@@ -1,7 +0,0 @@
1
- import type { AxiosInterceptorOptions } from 'axios';
2
- import type { ResponseInterceptor } from '../instance';
3
- export interface ResponseTimeoutInterceptorOptions {
4
- normalizeErrorCode?: string;
5
- axiosInterceptorOptions?: AxiosInterceptorOptions;
6
- }
7
- export declare function responseTimeoutInterceptor(options?: ResponseTimeoutInterceptorOptions): ResponseInterceptor;
@@ -1,15 +0,0 @@
1
- export function responseTimeoutInterceptor(options = {}) {
2
- return {
3
- onFulfilled(response) {
4
- return response;
5
- },
6
- onRejected(error) {
7
- var _a;
8
- if ((error.code == 'ECONNABORTED' && error.message.includes('timeout')) || error.code === 'ETIMEDOUT') {
9
- error.code = (_a = options === null || options === void 0 ? void 0 : options.normalizeErrorCode) !== null && _a !== void 0 ? _a : 'TIMEOUT';
10
- }
11
- return Promise.reject(error);
12
- },
13
- options: options.axiosInterceptorOptions,
14
- };
15
- }
@@ -1,2 +0,0 @@
1
- import { type Ref } from "vue";
2
- export declare function useAverageProgress(...progressCollection: Ref<number>[]): Ref<number>;
@@ -1,9 +0,0 @@
1
- import { ref, watch } from "vue";
2
- export function useAverageProgress(...progressCollection) {
3
- const averageProgress = ref(0);
4
- watch(() => progressCollection.map(progress => progress.value), (newProgressCollection) => {
5
- const total = newProgressCollection.reduce((total, progress) => total + progress, 0);
6
- averageProgress.value = total / progressCollection.length;
7
- }, { immediate: true });
8
- return averageProgress;
9
- }
@@ -1,2 +0,0 @@
1
- import { type Ref } from "vue";
2
- export declare function useHasLoading(...loadings: Ref<boolean>[]): Ref<boolean>;
@@ -1,8 +0,0 @@
1
- import { ref, watch } from "vue";
2
- export function useHasLoading(...loadings) {
3
- const hasLoading = ref(false);
4
- watch(() => loadings.map(loading => loading.value), (newLoadings) => {
5
- hasLoading.value = newLoadings.some(Boolean);
6
- }, { immediate: true });
7
- return hasLoading;
8
- }
package/es/useValues.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { type Ref, type WritableComputedRef } from 'vue';
2
- export declare function useValues<T extends Ref<any>[]>(...valueCollection: T): WritableComputedRef<T[number]['value'][]>;