vue-api-kit 1.10.2 → 1.10.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/index.js +29 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48,9 +48,9 @@ function K(e) {
|
|
|
48
48
|
const i = (m) => {
|
|
49
49
|
if (m)
|
|
50
50
|
for (const [d, t] of Object.entries(m)) {
|
|
51
|
-
const
|
|
52
|
-
r.url.includes(
|
|
53
|
-
|
|
51
|
+
const o = `{${d}}`;
|
|
52
|
+
r.url.includes(o) && (r.url = r.url.replace(
|
|
53
|
+
o,
|
|
54
54
|
encodeURIComponent(String(t))
|
|
55
55
|
), delete m[d]);
|
|
56
56
|
}
|
|
@@ -87,9 +87,9 @@ function K(e) {
|
|
|
87
87
|
if (d)
|
|
88
88
|
if (z(d)) {
|
|
89
89
|
const t = d;
|
|
90
|
-
i[m] = (
|
|
90
|
+
i[m] = (o) => {
|
|
91
91
|
let s;
|
|
92
|
-
|
|
92
|
+
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 ? s = o : s = { params: o });
|
|
93
93
|
const C = R(), g = R(), q = R(), j = R(!1), A = R(!1), B = R(!0);
|
|
94
94
|
let w = new AbortController();
|
|
95
95
|
const u = () => {
|
|
@@ -114,18 +114,18 @@ function K(e) {
|
|
|
114
114
|
const f = await s.onBeforeRequest(c);
|
|
115
115
|
f !== void 0 && Object.assign(c, f);
|
|
116
116
|
}
|
|
117
|
-
const h = await y.request(c),
|
|
118
|
-
C.value =
|
|
117
|
+
const h = await y.request(c), n = t.response ? t.response.parse(h.data) : h.data;
|
|
118
|
+
C.value = n, s?.onResult?.(n);
|
|
119
119
|
} catch (a) {
|
|
120
120
|
if (a instanceof F) {
|
|
121
121
|
if (a.code !== "ERR_CANCELED") {
|
|
122
|
-
const c = a.config?.url, h = a.response?.data?.message || a.message || "An error occurred",
|
|
123
|
-
g.value = h, s?.onError?.(a), e.onErrorRequest?.({ message: h, status:
|
|
122
|
+
const c = a.config?.url, h = a.response?.data?.message || a.message || "An error occurred", n = a.response?.status, f = a.code, v = a.response?.data;
|
|
123
|
+
g.value = h, s?.onError?.(a), e.onErrorRequest?.({ message: h, status: n, code: f, data: v, url: c });
|
|
124
124
|
}
|
|
125
125
|
} else if (a instanceof S) {
|
|
126
126
|
q.value = a.issues || [];
|
|
127
127
|
const h = `Validation error: ${q.value.map(
|
|
128
|
-
(
|
|
128
|
+
(n) => `${n.path.join(".")}: ${n.message}`
|
|
129
129
|
).join(", ")}`;
|
|
130
130
|
g.value = h, s?.onError?.(a), s?.onZodError?.(q.value), e.onErrorRequest?.({ message: h, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(q.value);
|
|
131
131
|
} else {
|
|
@@ -161,7 +161,7 @@ function K(e) {
|
|
|
161
161
|
if (d)
|
|
162
162
|
if (V(d)) {
|
|
163
163
|
const t = d;
|
|
164
|
-
i[m] = (
|
|
164
|
+
i[m] = (o) => {
|
|
165
165
|
const s = R(), C = R(), g = R(), q = R(!1), j = R(!1), A = R(0);
|
|
166
166
|
return { result: s, errorMessage: C, zodErrors: g, isLoading: q, isDone: j, uploadProgress: A, mutate: async (w) => {
|
|
167
167
|
if (!q.value) {
|
|
@@ -170,12 +170,12 @@ function K(e) {
|
|
|
170
170
|
const { data: u = {}, params: l } = w ?? {};
|
|
171
171
|
let E = u ?? {}, p = {};
|
|
172
172
|
if (t.isMultipart) {
|
|
173
|
-
const
|
|
173
|
+
const n = new FormData();
|
|
174
174
|
for (const [f, v] of Object.entries(u))
|
|
175
|
-
v instanceof File || v instanceof Blob ?
|
|
176
|
-
P instanceof File || P instanceof Blob ?
|
|
177
|
-
}) : typeof v == "object" && v !== null ?
|
|
178
|
-
E =
|
|
175
|
+
v instanceof File || v instanceof Blob ? n.append(f, v) : Array.isArray(v) ? v.forEach((P) => {
|
|
176
|
+
P instanceof File || P instanceof Blob ? n.append(f, P) : n.append(f, JSON.stringify(P));
|
|
177
|
+
}) : typeof v == "object" && v !== null ? n.append(f, JSON.stringify(v)) : n.append(f, String(v));
|
|
178
|
+
E = n, p["Content-Type"] = "multipart/form-data";
|
|
179
179
|
} else t.data && t.data.parse(u);
|
|
180
180
|
t.params && l && t.params.parse(l);
|
|
181
181
|
const a = {
|
|
@@ -184,36 +184,36 @@ function K(e) {
|
|
|
184
184
|
data: E,
|
|
185
185
|
params: l,
|
|
186
186
|
headers: p,
|
|
187
|
-
onUploadProgress: (
|
|
188
|
-
if (
|
|
189
|
-
const f = Math.round(
|
|
190
|
-
A.value = f,
|
|
187
|
+
onUploadProgress: (n) => {
|
|
188
|
+
if (n.total) {
|
|
189
|
+
const f = Math.round(n.loaded * 100 / n.total);
|
|
190
|
+
A.value = f, o?.onUploadProgress?.(f);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
194
|
if (t.onBeforeRequest) {
|
|
195
|
-
const
|
|
196
|
-
|
|
195
|
+
const n = await t.onBeforeRequest(a);
|
|
196
|
+
n !== void 0 && Object.assign(a, n);
|
|
197
197
|
}
|
|
198
|
-
if (
|
|
199
|
-
const
|
|
200
|
-
|
|
198
|
+
if (o?.onBeforeRequest) {
|
|
199
|
+
const n = await o.onBeforeRequest(a);
|
|
200
|
+
n !== void 0 && Object.assign(a, n);
|
|
201
201
|
}
|
|
202
202
|
const c = await y.request(a), h = t.response ? t.response.parse(c.data) : c.data;
|
|
203
|
-
s.value = h,
|
|
203
|
+
s.value = h, o?.onResult?.(h);
|
|
204
204
|
} catch (u) {
|
|
205
205
|
if (u instanceof F) {
|
|
206
206
|
const l = u.response?.data?.message || u.message || "An error occurred", E = u.response?.status, p = u.code;
|
|
207
|
-
C.value = l,
|
|
207
|
+
C.value = l, o?.onError?.(u), e.onErrorRequest?.({ message: l, status: E, code: p });
|
|
208
208
|
} else if (u instanceof S) {
|
|
209
209
|
g.value = u.issues || [];
|
|
210
210
|
const E = `Validation error: ${g.value.map(
|
|
211
211
|
(p) => `${p.path.join(".")}: ${p.message}`
|
|
212
212
|
).join(", ")}`;
|
|
213
|
-
C.value = E,
|
|
213
|
+
C.value = E, o?.onError?.(u), o?.onZodError?.(g.value), e.onErrorRequest?.({ message: E, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(g.value);
|
|
214
214
|
} else {
|
|
215
215
|
const l = u.message || "An error occurred";
|
|
216
|
-
C.value = l,
|
|
216
|
+
C.value = l, o?.onError?.(u), e.onErrorRequest?.({ message: l });
|
|
217
217
|
}
|
|
218
218
|
} finally {
|
|
219
219
|
q.value = !1, j.value = !0;
|
package/package.json
CHANGED