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