rxtutils 1.0.2-b → 1.0.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.d.ts DELETED
@@ -1,89 +0,0 @@
1
- import { AxiosResponse, Method, AxiosRequestConfig } from 'axios';
2
-
3
- declare class IndexedDBStorage {
4
- private dbName;
5
- private storeName;
6
- private db;
7
- constructor(dbName: string, storeName: string);
8
- private _open;
9
- private _getStore;
10
- setItem<T>(key: string, value: T): Promise<void>;
11
- getItem<T = any>(key: string): Promise<T>;
12
- }
13
-
14
- type StorageType = 'sessionStorage' | 'localStorage' | 'indexedDB';
15
- interface ICache<Param, Data> {
16
- params: Param;
17
- data: Data;
18
- expireTime: string;
19
- }
20
- interface ICacheOptions<Param> {
21
- storageType?: StorageType;
22
- cacheKey?: string;
23
- cacheTime?: number;
24
- cacheKeyEquals: (prev: Param, next: Param) => boolean;
25
- indexDBName?: string;
26
- }
27
- declare const StorageMap: Record<StorageType | string, Storage>;
28
- declare class Cache<Param, Data> {
29
- cache: ICache<Param, Data>[];
30
- cacheOptions: ICacheOptions<Param>;
31
- storage?: Storage | IndexedDBStorage;
32
- constructor(cacheType?: StorageType, cacheKey?: string, cacheTime?: number, indexDBName?: string, cacheKeyEquals?: (prev: Param, next: Param) => boolean);
33
- private _init;
34
- private _filterExpired;
35
- private _saveToStorage;
36
- setCache(params: Param, data: Data, cacheOptions?: Omit<ICacheOptions<Param>, 'storageType' | 'cacheKey' | 'cacheKeyEquals'>): void;
37
- getCache(params: Param): Data;
38
- clear(): void;
39
- }
40
-
41
- type ErrorHandlerReturnType<D> = {
42
- replaceResData?: D;
43
- throwError?: boolean | 'default';
44
- };
45
- interface Options<Params = any, Data = any> {
46
- baseURL?: string;
47
- throwError?: boolean;
48
- defaultMessageShower?: (message: string) => void;
49
- enableCache?: boolean;
50
- cacheKeyEquals?: (prev: Params, next: Params) => boolean;
51
- cacheData?: boolean;
52
- cacheTime?: number;
53
- cacheDataInStorage?: StorageType;
54
- cacheDataKey?: string;
55
- indexDBName?: string;
56
- errorCodePath?: string;
57
- errorCodeMap?: Record<string, string | ((code: string, data: Data, res: AxiosResponse<Data>, requestParam: RequestOptions<Params>) => ErrorHandlerReturnType<Data> | void)>;
58
- defaultErrorCodeHandler?: (code: string, data: Data, res: AxiosResponse<Data>) => ErrorHandlerReturnType<Data> | void;
59
- successCodes?: string[];
60
- httpErrorCodeMap?: Record<string, string | ((code: number, res: AxiosResponse<Data>, requestParam: RequestOptions<Params>) => ErrorHandlerReturnType<Data> | void)>;
61
- defaultHttpErrorCodeHandler?: (code: number, error: any) => ErrorHandlerReturnType<Data> | void;
62
- otherErrorHandler?: (error: any) => ErrorHandlerReturnType<Data> | void;
63
- axiosOptions?: Omit<AxiosRequestConfig<Params>, 'method' | 'url' | 'params' | 'data'>;
64
- }
65
- interface RequestOptions<Param> {
66
- method: Method;
67
- url: string;
68
- data?: Param;
69
- params?: Param;
70
- }
71
- declare function createBaseRequest(baseOptions?: Options): <Param, Data extends Record<any, any>>(requestOptions: RequestOptions<Param>, createOptions?: Omit<Options<Param, Data>, "baseURL">) => {
72
- (requestParam?: Omit<RequestOptions<Param>, "url" | "method">, options?: Omit<Options<Param, Data>, "baseURL" | "cacheDataKey" | "cacheDataInStorage" | "cacheKeyEquals">): Promise<Data>;
73
- clearCache(): void;
74
- };
75
-
76
- type IHookStateInitialSetter<S> = () => S;
77
- type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
78
- type IHookStateSetter<S> = ((prevState: S) => S) | (() => S);
79
- type IHookStateSetAction<S> = S | IHookStateSetter<S>;
80
- type IHookStateResolvable<S> = S | IHookStateInitialSetter<S> | IHookStateSetter<S>;
81
- declare function createStateStore<S>(initialState?: S): {
82
- use: () => [S, (state: IHookStateSetAction<S>) => void];
83
- get: () => S;
84
- set: (state: IHookStateSetAction<S>) => void;
85
- watch: (callback: (state: S) => S | void) => () => void;
86
- };
87
-
88
- export { Cache, StorageMap, createBaseRequest, createStateStore };
89
- export type { ErrorHandlerReturnType, ICache, ICacheOptions, IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter, Options, RequestOptions };