vue-api-kit 1.10.6 → 1.10.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/dist/index.d.ts +1 -1
- package/dist/index.js +18 -16
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * as z from 'zod';
|
|
|
2
2
|
export { createApiClient } from './core/client';
|
|
3
3
|
export { mergeQueries, mergeMutations, defineQuery, defineMutation } from './core/merge';
|
|
4
4
|
export type * from './core/types';
|
|
5
|
-
export
|
|
5
|
+
export { ZodError } from 'zod';
|
|
6
6
|
export { AxiosError } from 'axios';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import A, { ZodError as F } from "zod";
|
|
2
2
|
import * as G from "zod";
|
|
3
|
+
import { ZodError as ae } from "zod";
|
|
3
4
|
import U, { AxiosError as Z } from "axios";
|
|
4
|
-
import { AxiosError as
|
|
5
|
-
import { nextTick as _, ref as
|
|
5
|
+
import { AxiosError as ie } from "axios";
|
|
6
|
+
import { nextTick as _, ref as p, onMounted as N, watch as Q, onBeforeUnmount as z } from "vue";
|
|
6
7
|
import { debounce as J } from "lodash-es";
|
|
7
8
|
function H(e) {
|
|
8
9
|
return e && typeof e == "object" && e !== null && typeof e.path == "string";
|
|
@@ -11,7 +12,7 @@ function W(e) {
|
|
|
11
12
|
return e && typeof e == "object" && e !== null && typeof e.path == "string" && typeof e.method == "string";
|
|
12
13
|
}
|
|
13
14
|
function Y(e) {
|
|
14
|
-
const
|
|
15
|
+
const h = U.create({
|
|
15
16
|
baseURL: e.baseURL,
|
|
16
17
|
headers: {
|
|
17
18
|
"Content-Type": "application/json",
|
|
@@ -22,7 +23,7 @@ function Y(e) {
|
|
|
22
23
|
withXSRFToken: e.withXSRFToken ?? !1
|
|
23
24
|
});
|
|
24
25
|
let B = !1, w = null;
|
|
25
|
-
e.onBeforeRequest &&
|
|
26
|
+
e.onBeforeRequest && h.interceptors.request.use(
|
|
26
27
|
async (r) => {
|
|
27
28
|
try {
|
|
28
29
|
return await e.onBeforeRequest(r) || r;
|
|
@@ -31,7 +32,7 @@ function Y(e) {
|
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
34
|
(r) => Promise.reject(r)
|
|
34
|
-
), e.onStartRequest &&
|
|
35
|
+
), e.onStartRequest && h.interceptors.request.use(
|
|
35
36
|
async (r) => {
|
|
36
37
|
try {
|
|
37
38
|
return await e.onStartRequest(), r;
|
|
@@ -40,10 +41,10 @@ function Y(e) {
|
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
43
|
(r) => Promise.reject(r)
|
|
43
|
-
), e.onFinishRequest &&
|
|
44
|
+
), e.onFinishRequest && h.interceptors.response.use(
|
|
44
45
|
(r) => (e.onFinishRequest(), r),
|
|
45
46
|
(r) => (e.onFinishRequest(), Promise.reject(r))
|
|
46
|
-
),
|
|
47
|
+
), h.interceptors.request.use((r) => {
|
|
47
48
|
if (!r.url) return r;
|
|
48
49
|
const n = (m) => {
|
|
49
50
|
if (m)
|
|
@@ -56,7 +57,7 @@ function Y(e) {
|
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
59
|
return r.method !== "get" && r.data?.params && n(r.data.params), n(r.params), r;
|
|
59
|
-
}), e.csrfRefreshEndpoint &&
|
|
60
|
+
}), e.csrfRefreshEndpoint && h.interceptors.response.use(
|
|
60
61
|
(r) => r,
|
|
61
62
|
async (r) => {
|
|
62
63
|
const n = r.config;
|
|
@@ -65,16 +66,16 @@ function Y(e) {
|
|
|
65
66
|
if (r.response && (r.response.status === 403 || r.response.status === 419) && !n?._retry) {
|
|
66
67
|
n._retry = !0;
|
|
67
68
|
try {
|
|
68
|
-
return B && w ? await w : (B = !0, w =
|
|
69
|
+
return B && w ? await w : (B = !0, w = h.get(e.csrfRefreshEndpoint).then(() => {
|
|
69
70
|
B = !1, w = null;
|
|
70
|
-
}), await w),
|
|
71
|
+
}), await w), h.request(n);
|
|
71
72
|
} catch (m) {
|
|
72
73
|
return B = !1, w = null, Promise.reject(m);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
return Promise.reject(r);
|
|
76
77
|
}
|
|
77
|
-
),
|
|
78
|
+
), h.interceptors.response.use(
|
|
78
79
|
(r) => r,
|
|
79
80
|
(r) => (_(() => {
|
|
80
81
|
r.code;
|
|
@@ -90,7 +91,7 @@ function Y(e) {
|
|
|
90
91
|
n[m] = (o) => {
|
|
91
92
|
let a;
|
|
92
93
|
o && typeof o == "object" && ("loadOnMount" in o || "debounce" in o || "onResult" in o || "onError" in o || "onZodError" in o || "onBeforeRequest" in o || "params" in o || "data" in o ? a = o : a = { params: o });
|
|
93
|
-
const g =
|
|
94
|
+
const g = p(), v = p(), E = p(), C = p(!1), j = p(!1), k = p(!0);
|
|
94
95
|
let P = new AbortController();
|
|
95
96
|
const i = () => {
|
|
96
97
|
P?.abort(), P = new AbortController();
|
|
@@ -115,7 +116,7 @@ function Y(e) {
|
|
|
115
116
|
d !== void 0 && Object.assign(u, d);
|
|
116
117
|
}
|
|
117
118
|
v.value = void 0, E.value = void 0;
|
|
118
|
-
const b = await
|
|
119
|
+
const b = await h.request(u), f = s.response ? s.response.parse(b.data) : b.data;
|
|
119
120
|
g.value = f, a?.onResult?.(f);
|
|
120
121
|
} catch (t) {
|
|
121
122
|
if (t instanceof Z) {
|
|
@@ -161,7 +162,7 @@ function Y(e) {
|
|
|
161
162
|
if (W(c)) {
|
|
162
163
|
const s = c;
|
|
163
164
|
n[m] = (o) => {
|
|
164
|
-
const a =
|
|
165
|
+
const a = p(), g = p(), v = p(), E = p(!1), C = p(!1), j = p(0);
|
|
165
166
|
return { result: a, errorMessage: g, zodError: v, isLoading: E, isDone: C, uploadProgress: j, mutate: async (P) => {
|
|
166
167
|
if (!E.value) {
|
|
167
168
|
E.value = !0, g.value = void 0, j.value = 0;
|
|
@@ -199,7 +200,7 @@ function Y(e) {
|
|
|
199
200
|
f !== void 0 && Object.assign(t, f);
|
|
200
201
|
}
|
|
201
202
|
g.value = void 0, v.value = void 0;
|
|
202
|
-
const u = await
|
|
203
|
+
const u = await h.request(t), b = s.response ? s.response.parse(u.data) : u.data;
|
|
203
204
|
a.value = b, o?.onResult?.(b);
|
|
204
205
|
} catch (i) {
|
|
205
206
|
if (i instanceof Z) {
|
|
@@ -242,7 +243,8 @@ function te(...e) {
|
|
|
242
243
|
return Object.assign({}, ...e);
|
|
243
244
|
}
|
|
244
245
|
export {
|
|
245
|
-
|
|
246
|
+
ie as AxiosError,
|
|
247
|
+
ae as ZodError,
|
|
246
248
|
Y as createApiClient,
|
|
247
249
|
ee as defineMutation,
|
|
248
250
|
O as defineQuery,
|
package/package.json
CHANGED