rxtutils 1.0.5-beta.5 → 1.0.5-beta.6
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/package.json +7 -6
- package/es/cache/index.mjs +0 -31
- package/es/cache/indexDB.mjs +0 -12
- package/es/createStateStore/index.mjs +0 -14
- package/es/index.mjs +0 -3
- package/es/request/index.mjs +0 -40
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rxtutils",
|
|
3
|
-
"version": "1.0.5-beta.
|
|
4
|
-
"main": "
|
|
5
|
-
"module": "
|
|
6
|
-
"types": "
|
|
3
|
+
"version": "1.0.5-beta.6",
|
|
4
|
+
"main": "cjs/index.cjs",
|
|
5
|
+
"module": "es/index.mjs",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist",
|
|
9
|
-
"es"
|
|
8
|
+
"dist/cjs",
|
|
9
|
+
"dist/es",
|
|
10
|
+
"dist/types"
|
|
10
11
|
],
|
|
11
12
|
"scripts": {
|
|
12
13
|
"build": "rollup -c",
|
package/es/cache/index.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { IndexedDBStorage } from './indexDB.mjs';
|
|
2
|
-
|
|
3
|
-
type StorageType = 'sessionStorage' | 'localStorage' | 'indexedDB';
|
|
4
|
-
interface ICache<Param, Data> {
|
|
5
|
-
params: Param;
|
|
6
|
-
data: Data;
|
|
7
|
-
expireTime: string;
|
|
8
|
-
}
|
|
9
|
-
interface ICacheOptions<Param> {
|
|
10
|
-
storageType?: StorageType;
|
|
11
|
-
cacheKey?: string;
|
|
12
|
-
cacheTime?: number;
|
|
13
|
-
cacheKeyEquals: (prev: Param, next: Param) => boolean;
|
|
14
|
-
indexDBName?: string;
|
|
15
|
-
}
|
|
16
|
-
declare const StorageMap: Record<StorageType | string, Storage>;
|
|
17
|
-
declare class Cache<Param, Data> {
|
|
18
|
-
cache: ICache<Param, Data>[];
|
|
19
|
-
private cacheOptions;
|
|
20
|
-
storage?: Storage | IndexedDBStorage;
|
|
21
|
-
constructor(cacheType?: StorageType, cacheKey?: string, cacheTime?: number, indexDBName?: string, cacheKeyEquals?: (prev: Param, next: Param) => boolean);
|
|
22
|
-
private _init;
|
|
23
|
-
private _filterExpired;
|
|
24
|
-
private _saveToStorage;
|
|
25
|
-
setCache(params: Param, data: Data, cacheOptions?: Omit<ICacheOptions<Param>, 'storageType' | 'cacheKey' | 'cacheKeyEquals'>): void;
|
|
26
|
-
getCache(params: Param): Data;
|
|
27
|
-
clear(): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { StorageMap, Cache as default };
|
|
31
|
-
export type { ICache, ICacheOptions, StorageType };
|
package/es/cache/indexDB.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare class IndexedDBStorage {
|
|
2
|
-
private dbName;
|
|
3
|
-
private storeName;
|
|
4
|
-
private db;
|
|
5
|
-
constructor(dbName: string, storeName: string);
|
|
6
|
-
private _open;
|
|
7
|
-
private _getStore;
|
|
8
|
-
setItem<T>(key: string, value: T): Promise<void>;
|
|
9
|
-
getItem<T = any>(key: string): Promise<T>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { IndexedDBStorage };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type IHookStateInitialSetter<S> = () => S;
|
|
2
|
-
type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
|
|
3
|
-
type IHookStateSetter<S> = ((prevState: S) => S) | (() => S);
|
|
4
|
-
type IHookStateSetAction<S> = S | IHookStateSetter<S>;
|
|
5
|
-
type IHookStateResolvable<S> = S | IHookStateInitialSetter<S> | IHookStateSetter<S>;
|
|
6
|
-
declare function createStateStore<S>(initialState?: S): {
|
|
7
|
-
use: () => [S, (state: IHookStateSetAction<S>) => void];
|
|
8
|
-
get: () => S;
|
|
9
|
-
set: (state: IHookStateSetAction<S>) => void;
|
|
10
|
-
watch: (callback: (state: S) => S | void) => () => void;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { createStateStore as default };
|
|
14
|
-
export type { IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter };
|
package/es/index.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { default as Cache, ICache, ICacheOptions, StorageMap, StorageType } from './cache/index.mjs';
|
|
2
|
-
export { ErrorHandlerReturnType, Options, RequestOptions, default as createBaseRequest } from './request/index.mjs';
|
|
3
|
-
export { IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter, default as createStateStore } from './createStateStore/index.mjs';
|
package/es/request/index.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse, Method, AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { StorageType } from '../cache/index.mjs';
|
|
3
|
-
|
|
4
|
-
type ErrorHandlerReturnType<D> = {
|
|
5
|
-
replaceResData?: D;
|
|
6
|
-
throwError?: boolean | 'default';
|
|
7
|
-
};
|
|
8
|
-
interface Options<Params = any, Data = any> {
|
|
9
|
-
baseURL?: string;
|
|
10
|
-
throwError?: boolean;
|
|
11
|
-
defaultMessageShower?: (message: string) => void;
|
|
12
|
-
enableCache?: boolean;
|
|
13
|
-
cacheKeyEquals?: (prev: Params, next: Params) => boolean;
|
|
14
|
-
cacheData?: boolean;
|
|
15
|
-
cacheTime?: number;
|
|
16
|
-
cacheDataInStorage?: StorageType;
|
|
17
|
-
cacheDataKey?: string;
|
|
18
|
-
indexDBName?: string;
|
|
19
|
-
errorCodePath?: string;
|
|
20
|
-
errorCodeMap?: Record<string, string | ((code: string, data: Data, res: AxiosResponse<Data>, requestParam: RequestOptions<Params>) => ErrorHandlerReturnType<Data> | void)>;
|
|
21
|
-
defaultErrorCodeHandler?: (code: string, data: Data, res: AxiosResponse<Data>) => ErrorHandlerReturnType<Data> | void;
|
|
22
|
-
successCodes?: string[];
|
|
23
|
-
httpErrorCodeMap?: Record<string, string | ((code: number, res: AxiosResponse<Data>, requestParam: RequestOptions<Params>) => ErrorHandlerReturnType<Data> | void)>;
|
|
24
|
-
defaultHttpErrorCodeHandler?: (code: number, error: any) => ErrorHandlerReturnType<Data> | void;
|
|
25
|
-
otherErrorHandler?: (error: any) => ErrorHandlerReturnType<Data> | void;
|
|
26
|
-
axiosOptions?: Omit<AxiosRequestConfig<Params>, 'method' | 'url' | 'params' | 'data'>;
|
|
27
|
-
}
|
|
28
|
-
interface RequestOptions<Param> {
|
|
29
|
-
method: Method;
|
|
30
|
-
url: string;
|
|
31
|
-
data?: Param;
|
|
32
|
-
params?: Param;
|
|
33
|
-
}
|
|
34
|
-
declare function createBaseRequest(baseOptions?: Options): <Param, Data extends Record<any, any>>(requestOptions: RequestOptions<Param>, createOptions?: Omit<Options<Param, Data>, "baseURL">) => {
|
|
35
|
-
(requestParam?: Omit<RequestOptions<Param>, "url" | "method">, options?: Omit<Options<Param, Data>, "baseURL" | "cacheDataKey" | "cacheDataInStorage" | "cacheKeyEquals">): Promise<Data>;
|
|
36
|
-
clearCache(): void;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export { createBaseRequest as default };
|
|
40
|
-
export type { ErrorHandlerReturnType, Options, RequestOptions };
|