@varlet/axle 0.11.1 → 0.12.0
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 +9 -0
- package/README.zh-CN.md +9 -0
- package/lib/api.cjs +8 -2
- package/lib/api.d.cts +17 -6
- package/lib/api.d.ts +17 -6
- package/lib/api.js +6 -2
- package/lib/index.cjs +16 -14
- package/lib/index.d.cts +26 -21
- package/lib/index.d.ts +26 -21
- package/lib/index.js +13 -11
- package/lib/{instance-ab0b388e.d.ts → instance-857fe07c.d.ts} +4 -3
- package/lib/use.cjs +234 -80
- package/lib/use.d.cts +31 -7
- package/lib/use.d.ts +31 -7
- package/lib/use.js +239 -86
- package/package.json +1 -3
package/lib/use.cjs
CHANGED
|
@@ -34,6 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
34
34
|
// src/use.ts
|
|
35
35
|
var use_exports = {};
|
|
36
36
|
__export(use_exports, {
|
|
37
|
+
cleanupCacheBuffer: () => cleanupCacheBuffer,
|
|
37
38
|
createUseAxle: () => createUseAxle,
|
|
38
39
|
normalizeValueGetter: () => normalizeValueGetter,
|
|
39
40
|
useAverageProgress: () => useAverageProgress,
|
|
@@ -44,17 +45,19 @@ module.exports = __toCommonJS(use_exports);
|
|
|
44
45
|
var import_vue4 = require("vue");
|
|
45
46
|
var import_rattail = require("rattail");
|
|
46
47
|
|
|
47
|
-
// src/composables/
|
|
48
|
+
// src/composables/useAverageProgress.ts
|
|
48
49
|
var import_vue = require("vue");
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
50
|
+
function useAverageProgress(...progressCollection) {
|
|
51
|
+
const averageProgress = (0, import_vue.ref)(0);
|
|
52
|
+
(0, import_vue.watch)(
|
|
53
|
+
() => progressCollection.map((progress) => progress.value),
|
|
54
|
+
(newProgressCollection) => {
|
|
55
|
+
const total = newProgressCollection.reduce((total2, progress) => total2 + progress, 0);
|
|
56
|
+
averageProgress.value = total / progressCollection.length;
|
|
57
|
+
},
|
|
58
|
+
{ immediate: true }
|
|
59
|
+
);
|
|
60
|
+
return averageProgress;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
// src/composables/useHasLoading.ts
|
|
@@ -71,31 +74,38 @@ function useHasLoading(...loadings) {
|
|
|
71
74
|
return hasLoading;
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
// src/composables/
|
|
77
|
+
// src/composables/useValues.ts
|
|
75
78
|
var import_vue3 = require("vue");
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
return averageProgress;
|
|
79
|
+
function useValues(...valueCollection) {
|
|
80
|
+
return (0, import_vue3.computed)({
|
|
81
|
+
get: () => valueCollection.map((value) => value.value),
|
|
82
|
+
set(values) {
|
|
83
|
+
valueCollection.forEach((value, index) => {
|
|
84
|
+
value.value = values[index];
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
// src/use.ts
|
|
90
91
|
function normalizeValueGetter(valueGetter) {
|
|
91
92
|
return (0, import_rattail.isFunction)(valueGetter) ? valueGetter() : valueGetter;
|
|
92
93
|
}
|
|
94
|
+
var cacheBuffer = /* @__PURE__ */ new Map();
|
|
95
|
+
function cleanupCacheBuffer() {
|
|
96
|
+
cacheBuffer.forEach((value, key) => {
|
|
97
|
+
if (value.expiredTime && Date.now() >= value.expiredTime) {
|
|
98
|
+
cacheBuffer.delete(key);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
93
102
|
function createUseAxle(options) {
|
|
94
103
|
const {
|
|
95
104
|
axle,
|
|
96
105
|
onTransform: defaultOnTransform,
|
|
97
106
|
immediate: defaultImmediate = true,
|
|
98
|
-
abortOnUnmount: defaultAbortOnUnmount = true
|
|
107
|
+
abortOnUnmount: defaultAbortOnUnmount = true,
|
|
108
|
+
cacheTime: defaultCacheTime = Infinity
|
|
99
109
|
} = options;
|
|
100
110
|
const useAxle = (options2) => {
|
|
101
111
|
const {
|
|
@@ -103,11 +113,18 @@ function createUseAxle(options) {
|
|
|
103
113
|
method,
|
|
104
114
|
immediate = defaultImmediate,
|
|
105
115
|
abortOnUnmount = defaultAbortOnUnmount,
|
|
116
|
+
cacheTime = defaultCacheTime,
|
|
117
|
+
cacheKey,
|
|
118
|
+
pollingInterval,
|
|
119
|
+
pollingOnHidden = true,
|
|
120
|
+
pollingOnDeactivated = false,
|
|
106
121
|
value: initialValue,
|
|
107
122
|
resetValue: initialResetValue,
|
|
108
123
|
cloneResetValue: initialCloneResetValue,
|
|
109
124
|
params: initialParamsOrGetter,
|
|
110
125
|
config: initialConfigOrGetter,
|
|
126
|
+
watch: watchOptions,
|
|
127
|
+
runnable = () => true,
|
|
111
128
|
onBefore = () => {
|
|
112
129
|
},
|
|
113
130
|
onAfter = () => {
|
|
@@ -123,86 +140,179 @@ function createUseAxle(options) {
|
|
|
123
140
|
const error = (0, import_vue4.ref)();
|
|
124
141
|
const downloadProgress = (0, import_vue4.ref)(0);
|
|
125
142
|
const uploadProgress = (0, import_vue4.ref)(0);
|
|
143
|
+
const pollingCanceled = (0, import_vue4.ref)(false);
|
|
126
144
|
const refs = {
|
|
127
145
|
value,
|
|
128
146
|
loading,
|
|
129
147
|
error,
|
|
130
148
|
downloadProgress,
|
|
131
|
-
uploadProgress
|
|
149
|
+
uploadProgress,
|
|
150
|
+
pollingCanceled
|
|
132
151
|
};
|
|
133
152
|
const extra = {
|
|
134
153
|
uploadProgress,
|
|
135
154
|
downloadProgress,
|
|
136
155
|
loading,
|
|
137
156
|
error,
|
|
157
|
+
pollingCanceled,
|
|
138
158
|
abort,
|
|
139
|
-
resetValue
|
|
159
|
+
resetValue,
|
|
160
|
+
invalidateCache,
|
|
161
|
+
cancelPolling
|
|
140
162
|
};
|
|
141
163
|
let controller = new AbortController();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
164
|
+
let pollingTimer = null;
|
|
165
|
+
let deactivated = false;
|
|
166
|
+
let hidden = false;
|
|
167
|
+
const run = Object.assign(async (options3 = {}) => {
|
|
168
|
+
var _a, _b, _c, _d, _e;
|
|
169
|
+
if (!runnable()) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
pollingCanceled.value = false;
|
|
173
|
+
if (controller.signal.aborted) {
|
|
174
|
+
controller = new AbortController();
|
|
175
|
+
}
|
|
176
|
+
const resetValueOption = (_b = (_a = options3.resetValue) != null ? _a : initialResetValue) != null ? _b : false;
|
|
177
|
+
if (resetValueOption === true) {
|
|
178
|
+
resetValue(options3);
|
|
179
|
+
}
|
|
180
|
+
uploadProgress.value = 0;
|
|
181
|
+
downloadProgress.value = 0;
|
|
182
|
+
const url = (_c = options3.url) != null ? _c : normalizeValueGetter(initialUrlOrGetter);
|
|
183
|
+
const params = (_d = options3.params) != null ? _d : normalizeValueGetter(initialParamsOrGetter);
|
|
184
|
+
const config = (_e = options3.config) != null ? _e : normalizeValueGetter(initialConfigOrGetter);
|
|
185
|
+
const normalizedCacheKey = cacheKey ? normalizeValueGetter(cacheKey) : void 0;
|
|
186
|
+
onBefore(refs);
|
|
187
|
+
loading.value = true;
|
|
188
|
+
try {
|
|
189
|
+
cleanupCacheBuffer();
|
|
190
|
+
const response = await getResponse();
|
|
191
|
+
if (shouldSetCacheResponse(normalizedCacheKey)) {
|
|
192
|
+
const cache = cacheBuffer.get(normalizedCacheKey);
|
|
193
|
+
cache.response = response;
|
|
194
|
+
cache.expiredTime = Date.now() + cacheTime;
|
|
147
195
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
196
|
+
value.value = await onTransform(response, refs);
|
|
197
|
+
error.value = void 0;
|
|
198
|
+
onSuccess(response, refs);
|
|
199
|
+
loading.value = false;
|
|
200
|
+
onAfter(refs);
|
|
201
|
+
return response;
|
|
202
|
+
} catch (responseError) {
|
|
203
|
+
error.value = responseError;
|
|
204
|
+
onError(responseError, refs);
|
|
205
|
+
loading.value = false;
|
|
206
|
+
onAfter(refs);
|
|
207
|
+
throw responseError;
|
|
208
|
+
} finally {
|
|
209
|
+
clearPolling();
|
|
210
|
+
startPolling();
|
|
211
|
+
}
|
|
212
|
+
function getResponse() {
|
|
213
|
+
if (shouldUseCache(normalizedCacheKey)) {
|
|
214
|
+
return JSON.parse(JSON.stringify(cacheBuffer.get(normalizedCacheKey).response));
|
|
151
215
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const url = (_c = options3.url) != null ? _c : normalizeValueGetter(initialUrlOrGetter);
|
|
155
|
-
const params = (_d = options3.params) != null ? _d : normalizeValueGetter(initialParamsOrGetter);
|
|
156
|
-
const config = (_e = options3.config) != null ? _e : normalizeValueGetter(initialConfigOrGetter);
|
|
157
|
-
onBefore(refs);
|
|
158
|
-
loading.value = true;
|
|
159
|
-
try {
|
|
160
|
-
const response = await axle[method](url, params, __spreadValues({
|
|
161
|
-
signal: controller.signal,
|
|
162
|
-
onUploadProgress(event) {
|
|
163
|
-
var _a2;
|
|
164
|
-
uploadProgress.value = (_a2 = event.progress) != null ? _a2 : 0;
|
|
165
|
-
},
|
|
166
|
-
onDownloadProgress(event) {
|
|
167
|
-
var _a2;
|
|
168
|
-
downloadProgress.value = (_a2 = event.progress) != null ? _a2 : 0;
|
|
169
|
-
}
|
|
170
|
-
}, config));
|
|
171
|
-
value.value = await onTransform(response, refs);
|
|
172
|
-
error.value = void 0;
|
|
173
|
-
onSuccess(response, refs);
|
|
174
|
-
loading.value = false;
|
|
175
|
-
onAfter(refs);
|
|
176
|
-
return response;
|
|
177
|
-
} catch (responseError) {
|
|
178
|
-
error.value = responseError;
|
|
179
|
-
onError(responseError, refs);
|
|
180
|
-
loading.value = false;
|
|
181
|
-
onAfter(refs);
|
|
182
|
-
throw responseError;
|
|
216
|
+
if (shouldAwaitCachePromise(normalizedCacheKey)) {
|
|
217
|
+
return cacheBuffer.get(normalizedCacheKey).promise;
|
|
183
218
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
219
|
+
const promise = fetchResponse();
|
|
220
|
+
if (shouldSetCachePromise(normalizedCacheKey)) {
|
|
221
|
+
cacheBuffer.set(normalizedCacheKey, { promise });
|
|
222
|
+
}
|
|
223
|
+
return promise;
|
|
224
|
+
}
|
|
225
|
+
function fetchResponse() {
|
|
226
|
+
return axle[method](url, params, __spreadValues({
|
|
227
|
+
signal: controller.signal,
|
|
228
|
+
onUploadProgress(event) {
|
|
229
|
+
var _a2;
|
|
230
|
+
uploadProgress.value = (_a2 = event.progress) != null ? _a2 : 0;
|
|
231
|
+
},
|
|
232
|
+
onDownloadProgress(event) {
|
|
233
|
+
var _a2;
|
|
234
|
+
downloadProgress.value = (_a2 = event.progress) != null ? _a2 : 0;
|
|
235
|
+
}
|
|
236
|
+
}, config));
|
|
237
|
+
}
|
|
238
|
+
function shouldUseCache(key) {
|
|
239
|
+
if (!key || !cacheBuffer.has(key)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
const buffer = cacheBuffer.get(key);
|
|
243
|
+
return buffer.response != null;
|
|
244
|
+
}
|
|
245
|
+
function shouldAwaitCachePromise(key) {
|
|
246
|
+
if (!key || !cacheBuffer.has(key)) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
const buffer = cacheBuffer.get(key);
|
|
250
|
+
return buffer.promise;
|
|
251
|
+
}
|
|
252
|
+
function shouldSetCachePromise(key) {
|
|
253
|
+
if (!key || cacheBuffer.has(key)) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
function shouldSetCacheResponse(key) {
|
|
259
|
+
if (!key || !cacheBuffer.has(key)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
const buffer = cacheBuffer.get(key);
|
|
263
|
+
return buffer.response == null;
|
|
264
|
+
}
|
|
265
|
+
}, extra);
|
|
194
266
|
if (immediate) {
|
|
195
|
-
|
|
267
|
+
runWithInitialConfig();
|
|
268
|
+
}
|
|
269
|
+
if ((0, import_vue4.getCurrentInstance)()) {
|
|
270
|
+
(0, import_vue4.onActivated)(() => {
|
|
271
|
+
deactivated = false;
|
|
272
|
+
addVisibilityChangeListener();
|
|
273
|
+
startPolling();
|
|
274
|
+
});
|
|
275
|
+
(0, import_vue4.onMounted)(() => {
|
|
276
|
+
addVisibilityChangeListener();
|
|
277
|
+
});
|
|
278
|
+
(0, import_vue4.onDeactivated)(() => {
|
|
279
|
+
deactivated = true;
|
|
280
|
+
removeVisibilityChangeListener();
|
|
281
|
+
clearPolling();
|
|
282
|
+
});
|
|
283
|
+
(0, import_vue4.onUnmounted)(() => {
|
|
284
|
+
removeVisibilityChangeListener();
|
|
285
|
+
cancelPolling();
|
|
286
|
+
});
|
|
287
|
+
if (abortOnUnmount) {
|
|
288
|
+
(0, import_vue4.onUnmounted)(() => {
|
|
289
|
+
abort();
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (watchOptions) {
|
|
293
|
+
const normalizedWatchOptions = watchOptions === true ? { params: true, config: true } : __spreadValues({ params: false, config: false }, watchOptions);
|
|
294
|
+
const enableWatchParams = (0, import_rattail.isFunction)(initialParamsOrGetter) && normalizedWatchOptions.params;
|
|
295
|
+
const enableWatchConfig = (0, import_rattail.isFunction)(initialConfigOrGetter) && normalizedWatchOptions.config;
|
|
296
|
+
(0, import_vue4.watch)(
|
|
297
|
+
() => [
|
|
298
|
+
enableWatchParams ? normalizeValueGetter(initialParamsOrGetter) : void 0,
|
|
299
|
+
enableWatchConfig ? normalizeValueGetter(initialConfigOrGetter) : void 0,
|
|
300
|
+
normalizedWatchOptions._custom ? normalizedWatchOptions._custom() : void 0
|
|
301
|
+
],
|
|
302
|
+
() => {
|
|
303
|
+
runWithInitialConfig();
|
|
304
|
+
},
|
|
305
|
+
{ deep: true }
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function runWithInitialConfig() {
|
|
310
|
+
return run({
|
|
196
311
|
url: normalizeValueGetter(initialUrlOrGetter),
|
|
197
312
|
params: normalizeValueGetter(initialParamsOrGetter),
|
|
198
313
|
config: normalizeValueGetter(initialConfigOrGetter)
|
|
199
314
|
});
|
|
200
315
|
}
|
|
201
|
-
if (abortOnUnmount && (0, import_vue4.getCurrentInstance)()) {
|
|
202
|
-
(0, import_vue4.onUnmounted)(() => {
|
|
203
|
-
abort();
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
316
|
function resetValue(options3 = {}) {
|
|
207
317
|
var _a, _b;
|
|
208
318
|
const cloneResetValue = (_b = (_a = options3.cloneResetValue) != null ? _a : initialCloneResetValue) != null ? _b : false;
|
|
@@ -212,12 +322,56 @@ function createUseAxle(options) {
|
|
|
212
322
|
function abort() {
|
|
213
323
|
controller.abort();
|
|
214
324
|
}
|
|
325
|
+
function addVisibilityChangeListener() {
|
|
326
|
+
if (typeof document !== "undefined") {
|
|
327
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function removeVisibilityChangeListener() {
|
|
331
|
+
if (typeof document !== "undefined") {
|
|
332
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function handleVisibilityChange() {
|
|
336
|
+
hidden = document.visibilityState === "hidden";
|
|
337
|
+
if (pollingOnHidden) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
hidden ? clearPolling() : startPolling();
|
|
341
|
+
}
|
|
342
|
+
function startPolling() {
|
|
343
|
+
if (pollingInterval == null || pollingCanceled.value || pollingTimer != null || deactivated && !pollingOnDeactivated || hidden && !pollingOnHidden) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
pollingTimer = setTimeout(() => {
|
|
347
|
+
runWithInitialConfig();
|
|
348
|
+
}, pollingInterval);
|
|
349
|
+
}
|
|
350
|
+
function clearPolling() {
|
|
351
|
+
if (pollingTimer == null) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
clearTimeout(pollingTimer);
|
|
355
|
+
pollingTimer = null;
|
|
356
|
+
}
|
|
357
|
+
function cancelPolling() {
|
|
358
|
+
clearPolling();
|
|
359
|
+
pollingCanceled.value = true;
|
|
360
|
+
}
|
|
361
|
+
function invalidateCache() {
|
|
362
|
+
const normalizedCacheKey = cacheKey ? normalizeValueGetter(cacheKey) : void 0;
|
|
363
|
+
if (!normalizedCacheKey || !cacheBuffer.has(normalizedCacheKey)) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
cacheBuffer.delete(normalizedCacheKey);
|
|
367
|
+
}
|
|
215
368
|
return [value, run, extra];
|
|
216
369
|
};
|
|
217
370
|
return useAxle;
|
|
218
371
|
}
|
|
219
372
|
// Annotate the CommonJS export names for ESM import in node:
|
|
220
373
|
0 && (module.exports = {
|
|
374
|
+
cleanupCacheBuffer,
|
|
221
375
|
createUseAxle,
|
|
222
376
|
normalizeValueGetter,
|
|
223
377
|
useAverageProgress,
|
package/lib/use.d.cts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Ref, WritableComputedRef } from 'vue';
|
|
2
|
-
import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-
|
|
2
|
+
import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-857fe07c.js';
|
|
3
3
|
import 'axios';
|
|
4
4
|
|
|
5
|
-
declare function
|
|
5
|
+
declare function useAverageProgress(...progressCollection: Ref<number>[]): Ref<number>;
|
|
6
6
|
|
|
7
7
|
declare function useHasLoading(...loadings: Ref<boolean>[]): Ref<boolean>;
|
|
8
8
|
|
|
9
|
-
declare function
|
|
9
|
+
declare function useValues<T extends Ref<any>[]>(...valueCollection: T): WritableComputedRef<T[number]['value'][]>;
|
|
10
10
|
|
|
11
|
+
type Runnable = () => boolean;
|
|
11
12
|
interface RunOptions<V, P, D> {
|
|
12
13
|
url?: string;
|
|
13
14
|
params?: P;
|
|
@@ -16,12 +17,15 @@ interface RunOptions<V, P, D> {
|
|
|
16
17
|
cloneResetValue?: boolean | ((value: V) => V);
|
|
17
18
|
}
|
|
18
19
|
type UseAxleExtra<V> = {
|
|
19
|
-
uploadProgress: Ref<number>;
|
|
20
|
-
downloadProgress: Ref<number>;
|
|
21
20
|
loading: Ref<boolean>;
|
|
22
21
|
error: Ref<Error | undefined>;
|
|
22
|
+
uploadProgress: Ref<number>;
|
|
23
|
+
downloadProgress: Ref<number>;
|
|
24
|
+
pollingCanceled: Ref<boolean>;
|
|
23
25
|
abort(): void;
|
|
24
26
|
resetValue(options?: ResetValueOptions<V>): void;
|
|
27
|
+
invalidateCache(): void;
|
|
28
|
+
cancelPolling(): void;
|
|
25
29
|
};
|
|
26
30
|
interface UseAxleRefs<V> {
|
|
27
31
|
value: Ref<V>;
|
|
@@ -29,10 +33,16 @@ interface UseAxleRefs<V> {
|
|
|
29
33
|
error: Ref<Error | undefined>;
|
|
30
34
|
uploadProgress: Ref<number>;
|
|
31
35
|
downloadProgress: Ref<number>;
|
|
36
|
+
pollingCanceled: Ref<boolean>;
|
|
32
37
|
}
|
|
33
38
|
type Run<V, R, P, D> = {
|
|
34
39
|
(options?: RunOptions<V, P, D>): Promise<R>;
|
|
35
40
|
} & UseAxleExtra<V>;
|
|
41
|
+
type WatchOptions = boolean | {
|
|
42
|
+
params?: boolean;
|
|
43
|
+
config?: boolean;
|
|
44
|
+
_custom?: () => any;
|
|
45
|
+
};
|
|
36
46
|
interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<string, any>> {
|
|
37
47
|
url: string | (() => string);
|
|
38
48
|
method: RunnerMethod;
|
|
@@ -41,7 +51,13 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<s
|
|
|
41
51
|
resetValue?: boolean;
|
|
42
52
|
cloneResetValue?: boolean | ((value: V) => V);
|
|
43
53
|
abortOnUnmount?: boolean;
|
|
54
|
+
cacheKey?: string | (() => string);
|
|
55
|
+
cacheTime?: number;
|
|
44
56
|
config?: AxleRequestConfig<D> | (() => AxleRequestConfig<D>);
|
|
57
|
+
watch?: WatchOptions;
|
|
58
|
+
pollingInterval?: number;
|
|
59
|
+
pollingOnHidden?: boolean;
|
|
60
|
+
pollingOnDeactivated?: boolean;
|
|
45
61
|
params?: P | (() => P);
|
|
46
62
|
onBefore?(refs: UseAxleRefs<V>): void;
|
|
47
63
|
onAfter?(refs: UseAxleRefs<V>): void;
|
|
@@ -57,10 +73,18 @@ interface CreateUseAxleOptions {
|
|
|
57
73
|
axle: AxleInstance;
|
|
58
74
|
immediate?: boolean;
|
|
59
75
|
abortOnUnmount?: boolean;
|
|
76
|
+
cacheTime?: number;
|
|
60
77
|
onTransform?(response: any, refs: any): any;
|
|
61
78
|
}
|
|
62
|
-
type
|
|
79
|
+
type UseAxleOptionsWithRunnable<V = any, R = any, P = Record<string, any>, D = Record<string, any>> = UseAxleOptions<V, R, P, D> & {
|
|
80
|
+
runnable: Runnable;
|
|
81
|
+
};
|
|
82
|
+
interface UseAxle {
|
|
83
|
+
<V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptionsWithRunnable<V, R, P, D>): UseAxleInstance<V, R | undefined, P, D>;
|
|
84
|
+
<V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptions<V, R, P, D>): UseAxleInstance<V, R, P, D>;
|
|
85
|
+
}
|
|
63
86
|
declare function normalizeValueGetter<T>(valueGetter: T | (() => T)): T;
|
|
87
|
+
declare function cleanupCacheBuffer(): void;
|
|
64
88
|
declare function createUseAxle(options: CreateUseAxleOptions): UseAxle;
|
|
65
89
|
|
|
66
|
-
export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleRefs, createUseAxle, normalizeValueGetter, useAverageProgress, useHasLoading, useValues };
|
|
90
|
+
export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, Runnable, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxleRefs, WatchOptions, cleanupCacheBuffer, createUseAxle, normalizeValueGetter, useAverageProgress, useHasLoading, useValues };
|
package/lib/use.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Ref, WritableComputedRef } from 'vue';
|
|
2
|
-
import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-
|
|
2
|
+
import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-857fe07c.js';
|
|
3
3
|
import 'axios';
|
|
4
4
|
|
|
5
|
-
declare function
|
|
5
|
+
declare function useAverageProgress(...progressCollection: Ref<number>[]): Ref<number>;
|
|
6
6
|
|
|
7
7
|
declare function useHasLoading(...loadings: Ref<boolean>[]): Ref<boolean>;
|
|
8
8
|
|
|
9
|
-
declare function
|
|
9
|
+
declare function useValues<T extends Ref<any>[]>(...valueCollection: T): WritableComputedRef<T[number]['value'][]>;
|
|
10
10
|
|
|
11
|
+
type Runnable = () => boolean;
|
|
11
12
|
interface RunOptions<V, P, D> {
|
|
12
13
|
url?: string;
|
|
13
14
|
params?: P;
|
|
@@ -16,12 +17,15 @@ interface RunOptions<V, P, D> {
|
|
|
16
17
|
cloneResetValue?: boolean | ((value: V) => V);
|
|
17
18
|
}
|
|
18
19
|
type UseAxleExtra<V> = {
|
|
19
|
-
uploadProgress: Ref<number>;
|
|
20
|
-
downloadProgress: Ref<number>;
|
|
21
20
|
loading: Ref<boolean>;
|
|
22
21
|
error: Ref<Error | undefined>;
|
|
22
|
+
uploadProgress: Ref<number>;
|
|
23
|
+
downloadProgress: Ref<number>;
|
|
24
|
+
pollingCanceled: Ref<boolean>;
|
|
23
25
|
abort(): void;
|
|
24
26
|
resetValue(options?: ResetValueOptions<V>): void;
|
|
27
|
+
invalidateCache(): void;
|
|
28
|
+
cancelPolling(): void;
|
|
25
29
|
};
|
|
26
30
|
interface UseAxleRefs<V> {
|
|
27
31
|
value: Ref<V>;
|
|
@@ -29,10 +33,16 @@ interface UseAxleRefs<V> {
|
|
|
29
33
|
error: Ref<Error | undefined>;
|
|
30
34
|
uploadProgress: Ref<number>;
|
|
31
35
|
downloadProgress: Ref<number>;
|
|
36
|
+
pollingCanceled: Ref<boolean>;
|
|
32
37
|
}
|
|
33
38
|
type Run<V, R, P, D> = {
|
|
34
39
|
(options?: RunOptions<V, P, D>): Promise<R>;
|
|
35
40
|
} & UseAxleExtra<V>;
|
|
41
|
+
type WatchOptions = boolean | {
|
|
42
|
+
params?: boolean;
|
|
43
|
+
config?: boolean;
|
|
44
|
+
_custom?: () => any;
|
|
45
|
+
};
|
|
36
46
|
interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<string, any>> {
|
|
37
47
|
url: string | (() => string);
|
|
38
48
|
method: RunnerMethod;
|
|
@@ -41,7 +51,13 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<s
|
|
|
41
51
|
resetValue?: boolean;
|
|
42
52
|
cloneResetValue?: boolean | ((value: V) => V);
|
|
43
53
|
abortOnUnmount?: boolean;
|
|
54
|
+
cacheKey?: string | (() => string);
|
|
55
|
+
cacheTime?: number;
|
|
44
56
|
config?: AxleRequestConfig<D> | (() => AxleRequestConfig<D>);
|
|
57
|
+
watch?: WatchOptions;
|
|
58
|
+
pollingInterval?: number;
|
|
59
|
+
pollingOnHidden?: boolean;
|
|
60
|
+
pollingOnDeactivated?: boolean;
|
|
45
61
|
params?: P | (() => P);
|
|
46
62
|
onBefore?(refs: UseAxleRefs<V>): void;
|
|
47
63
|
onAfter?(refs: UseAxleRefs<V>): void;
|
|
@@ -57,10 +73,18 @@ interface CreateUseAxleOptions {
|
|
|
57
73
|
axle: AxleInstance;
|
|
58
74
|
immediate?: boolean;
|
|
59
75
|
abortOnUnmount?: boolean;
|
|
76
|
+
cacheTime?: number;
|
|
60
77
|
onTransform?(response: any, refs: any): any;
|
|
61
78
|
}
|
|
62
|
-
type
|
|
79
|
+
type UseAxleOptionsWithRunnable<V = any, R = any, P = Record<string, any>, D = Record<string, any>> = UseAxleOptions<V, R, P, D> & {
|
|
80
|
+
runnable: Runnable;
|
|
81
|
+
};
|
|
82
|
+
interface UseAxle {
|
|
83
|
+
<V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptionsWithRunnable<V, R, P, D>): UseAxleInstance<V, R | undefined, P, D>;
|
|
84
|
+
<V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptions<V, R, P, D>): UseAxleInstance<V, R, P, D>;
|
|
85
|
+
}
|
|
63
86
|
declare function normalizeValueGetter<T>(valueGetter: T | (() => T)): T;
|
|
87
|
+
declare function cleanupCacheBuffer(): void;
|
|
64
88
|
declare function createUseAxle(options: CreateUseAxleOptions): UseAxle;
|
|
65
89
|
|
|
66
|
-
export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleRefs, createUseAxle, normalizeValueGetter, useAverageProgress, useHasLoading, useValues };
|
|
90
|
+
export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, Runnable, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxleRefs, WatchOptions, cleanupCacheBuffer, createUseAxle, normalizeValueGetter, useAverageProgress, useHasLoading, useValues };
|