rxtutils 1.0.5-beta.3 → 1.0.5-beta.5

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.
@@ -0,0 +1,31 @@
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 };
@@ -0,0 +1,12 @@
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 };
@@ -0,0 +1,14 @@
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 ADDED
@@ -0,0 +1,3 @@
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';
@@ -0,0 +1,40 @@
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 };
package/package.json CHANGED
@@ -1,33 +1,12 @@
1
1
  {
2
2
  "name": "rxtutils",
3
- "version": "1.0.5-beta.3",
3
+ "version": "1.0.5-beta.5",
4
4
  "main": "dist/cjs/index.cjs",
5
5
  "module": "dist/es/index.mjs",
6
6
  "types": "dist/types/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/es/index.mjs",
10
- "require": "./dist/cjs/index.cjs",
11
- "types": "./dist/types/index.d.ts"
12
- },
13
- "./request": {
14
- "import": "./dist/es/request/index.mjs",
15
- "require": "./dist/cjs/request/index.cjs",
16
- "types": "./dist/types/request/index.d.ts"
17
- },
18
- "./cache":{
19
- "import": "./dist/es/cache/index.mjs",
20
- "require": "./dist/cjs/cache/index.cjs",
21
- "types": "./dist/types/cache/index.d.ts"
22
- },
23
- "./createStateStore":{
24
- "import": "./dist/es/createStateStore/index.mjs",
25
- "require": "./dist/cjs/createStateStore/index.cjs",
26
- "types": "./dist/types/createStateStore/index.d.ts"
27
- }
28
- },
29
7
  "files": [
30
- "dist"
8
+ "dist",
9
+ "es"
31
10
  ],
32
11
  "scripts": {
33
12
  "build": "rollup -c",