vue3-request 1.0.14 → 1.0.16

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.
@@ -1,8 +1,110 @@
1
- import { Plugin as Plugin_2 } from './types';
2
- import { useRequest } from './useRequest';
1
+ import { Reactive } from 'vue';
2
+ import { Ref } from 'vue';
3
+ import { ToRefs } from 'vue';
3
4
 
5
+ export declare type CacheCallbackType<D = any, P = any> = ({ data, params, time, }: CacheParamsType<D, P>) => void;
6
+
7
+ export declare type CacheParamsType<D = any, P = any> = {
8
+ data: D;
9
+ params: P;
10
+ time: number;
11
+ };
12
+
13
+ export declare type CallbackType<D = any, P extends any[] = any> = (signal?: AbortSignal) => ServiceType<D, P>;
14
+
15
+ declare type DebounceOptionsType = {
16
+ leading?: boolean;
17
+ trailing?: boolean;
18
+ };
19
+
20
+ export declare type IOptions<D, P extends any[]> = Partial<{
21
+ onBefore: (params: P) => void;
22
+ onSuccess: (data: D, params: P) => void;
23
+ onFinally: (params: P, data: D, error: Error) => void;
24
+ onError: (error: Error, params: P) => void;
25
+ manual: boolean;
26
+ defaultParams: P;
27
+ refreshDeps: (Ref<any> | Reactive<any>)[];
28
+ refreshDepsAction: () => void;
29
+ pollingInterval: number | Ref<number>;
30
+ errorRetryCount: number | Ref<number>;
31
+ errorRetryInterval: number | Ref<number>;
32
+ refreshOnWindowFocus: boolean;
33
+ refocusTimespan: number;
34
+ cacheKey: string;
35
+ cacheTime: number;
36
+ staleTime: number;
37
+ ready: Ref<boolean> | (() => boolean);
38
+ debounceWait: Ref<number> | number;
39
+ debounceOptions: Reactive<DebounceOptionsType> | DebounceOptionsType;
40
+ throttleWait: Ref<number> | number;
41
+ throttleOptions: Reactive<ThrottleOptionsType> | ThrottleOptionsType;
42
+ }>;
43
+
44
+ export declare interface IState<D, P extends any[]> {
45
+ data: D | undefined;
46
+ isLoading: boolean;
47
+ isFinished: boolean;
48
+ isAborted: boolean;
49
+ error: Error | undefined;
50
+ params: P;
51
+ }
52
+
53
+ declare type Plugin_2<D = any, P extends any[] = any> = (requestInstance: Request_2<D, P>, options: IOptions<D, P>) => PluginReturn<D, P>;
4
54
  export { Plugin_2 as Plugin }
5
55
 
6
- export { useRequest }
56
+ export declare type PluginMethodsReturn<D, P extends any[]> = Partial<{
57
+ servicePromise?: ReturnType<ServiceType<D, P>>;
58
+ signal?: AbortSignal;
59
+ isStaleTime?: boolean;
60
+ isReady?: boolean;
61
+ }>;
62
+
63
+ export declare type PluginReturn<D, P extends any[]> = Partial<{
64
+ onBefore: (params: P) => void;
65
+ onSuccess: (data: D, params: P) => void;
66
+ onFinally: (params: P, data: D, error: Error) => void;
67
+ onError: (error: Error, params: P) => void;
68
+ onCancel: () => void;
69
+ onRequest: (service: ServiceType<D, P>) => ServiceType<D, P>;
70
+ }>;
71
+
72
+ declare class Request_2<D, P extends any[]> {
73
+ service: CallbackType<D, P>;
74
+ options?: IOptions<D, P>;
75
+ currentRequestId: number;
76
+ pluginImpls: PluginReturn<D, P>[];
77
+ state: IState<D, P>;
78
+ abort: () => void;
79
+ constructor(service: CallbackType<D, P>, options?: IOptions<D, P>);
80
+ setState: (s: Partial<IState<D, P>>) => void;
81
+ executePlugin: (event: keyof PluginReturn<D, P>, ...rest: any[]) => PluginMethodsReturn<D, P>;
82
+ loading: (isLoading: boolean) => void;
83
+ onFinished: () => void;
84
+ runAsync: (...params: P) => Promise<D>;
85
+ run: (...params: P) => void;
86
+ refresh: () => void;
87
+ refreshAsync: () => Promise<D>;
88
+ cancel: () => void;
89
+ }
90
+
91
+ export declare type ServiceType<D = any, P extends any[] = any> = (...args: P) => Promise<D>;
92
+
93
+ declare type ThrottleOptionsType = {
94
+ leading?: boolean;
95
+ trailing?: boolean;
96
+ };
97
+
98
+ export declare function useRequest<D, P extends any[]>(service: CallbackType<D, P>, options?: IOptions<D, P>, plugins?: Plugin_2<D, P>[]): UseRequestReturnType<D, P>;
99
+
100
+ export declare interface UseRequestReturnType<D, P extends any[]> extends ToRefs<IState<D, P>> {
101
+ run: (...args: P) => void;
102
+ cancel: () => void;
103
+ refresh: () => void;
104
+ runAsync: (...args: P) => Promise<D>;
105
+ abort: () => void;
106
+ refreshAsync: () => Promise<D>;
107
+ clearCache: () => void;
108
+ }
7
109
 
8
110
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-request",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "type": "module",
5
5
  "description": "A Vue3 asynchronous request processing library, designed to simplify your asynchronous operations and API calls.",
6
6
  "main": "dist/vue3-request.es.js",