@pisell/core 1.0.41 → 1.0.43
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/es/app/app.d.ts +99 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/history/index.d.ts +23 -0
- package/es/index.d.ts +7 -0
- package/es/indexDB/index.js +48 -68
- package/es/logger/index.d.ts +1 -1
- package/es/logger/index.js +199 -165
- package/es/menuManager/index.d.ts +28 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/type.d.ts +52 -0
- package/es/request/utils.d.ts +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/lib/app/app.d.ts +99 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/history/index.d.ts +23 -0
- package/lib/index.d.ts +7 -0
- package/lib/indexDB/index.js +2 -48
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +21 -6
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/type.d.ts +52 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/package.json +1 -1
package/lib/app/app.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { RouterManager } from '../routes';
|
|
2
|
+
import { ApplicationManager } from '../applicationManager';
|
|
3
|
+
import { History, HistoryOptions } from '../history';
|
|
4
|
+
import { Data } from '../data';
|
|
5
|
+
import { Locales, LocalesOptions } from '../locales';
|
|
6
|
+
import { Storage, StorageOptions } from '../storage';
|
|
7
|
+
import { MenuManager } from '../menuManager';
|
|
8
|
+
import LoggerManager, { LoggerOptions } from '../logger';
|
|
9
|
+
import { TasksManager } from '../tasks';
|
|
10
|
+
import IndexDBManager, { DBOptions } from '../indexDB';
|
|
11
|
+
import CMD, { CMDOptions } from "../cmd";
|
|
12
|
+
import AWS, { AWSOptions } from "../aws";
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
app: App;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export interface Bootstrap {
|
|
19
|
+
hooks: {
|
|
20
|
+
[key: string]: () => Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface AppOptions {
|
|
24
|
+
logger?: LoggerOptions;
|
|
25
|
+
db?: DBOptions;
|
|
26
|
+
constants?: any;
|
|
27
|
+
history?: HistoryOptions;
|
|
28
|
+
storage?: StorageOptions;
|
|
29
|
+
locales?: LocalesOptions;
|
|
30
|
+
cmd?: CMDOptions;
|
|
31
|
+
aws?: AWSOptions;
|
|
32
|
+
getPisellos?: () => any;
|
|
33
|
+
}
|
|
34
|
+
declare class App {
|
|
35
|
+
private static instance;
|
|
36
|
+
private plugins;
|
|
37
|
+
globalData: any;
|
|
38
|
+
router: RouterManager;
|
|
39
|
+
applicationManager: ApplicationManager;
|
|
40
|
+
history: History;
|
|
41
|
+
data: Data;
|
|
42
|
+
hooks: import("../hooks").HooksExport;
|
|
43
|
+
locales: Locales;
|
|
44
|
+
models: {
|
|
45
|
+
getStore: () => import("../models").Store;
|
|
46
|
+
StoreProvider: typeof import("react-redux").Provider;
|
|
47
|
+
setConfig: (models: any[]) => void;
|
|
48
|
+
};
|
|
49
|
+
request: {
|
|
50
|
+
get: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
51
|
+
post: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
52
|
+
put: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
53
|
+
remove: (url: string, data: any, config: import("../request").RequestSetting | undefined) => Promise<any>;
|
|
54
|
+
custom: (url: string, config: import("../request").RequestSetting | undefined) => any;
|
|
55
|
+
setConfig: (newConfig: Partial<import("../request").RequestConfig>) => void;
|
|
56
|
+
getConfig: () => import("../request").RequestConfig;
|
|
57
|
+
};
|
|
58
|
+
storage: Storage;
|
|
59
|
+
menuManager: MenuManager;
|
|
60
|
+
cookie: {
|
|
61
|
+
setCookie: (name: string, value: string, domain?: string | undefined) => void;
|
|
62
|
+
getCookie: (name: string) => string | null;
|
|
63
|
+
deleteCookie: (name: string, domain?: string | undefined) => void;
|
|
64
|
+
checkCookie: (name: string) => boolean;
|
|
65
|
+
updateCookie: (name: string, value: string, domain?: string | undefined) => void;
|
|
66
|
+
};
|
|
67
|
+
website: {
|
|
68
|
+
setTitle: (title: string) => void;
|
|
69
|
+
setIcon: (paramsIcon: string) => void;
|
|
70
|
+
setAppleWebAppTitle: (title: string) => void;
|
|
71
|
+
};
|
|
72
|
+
logger: LoggerManager;
|
|
73
|
+
pubsub: import("../pubsub").PubSub;
|
|
74
|
+
cmd: CMD;
|
|
75
|
+
aws: AWS;
|
|
76
|
+
tasksManager: TasksManager;
|
|
77
|
+
getPisellos: any;
|
|
78
|
+
bootstrap?: Bootstrap;
|
|
79
|
+
dbManager: IndexDBManager | null;
|
|
80
|
+
constants: {
|
|
81
|
+
channel: string;
|
|
82
|
+
[key: string]: string;
|
|
83
|
+
};
|
|
84
|
+
private constructor();
|
|
85
|
+
static getInstance(options?: AppOptions): App;
|
|
86
|
+
setGlobalData(globalData: any): void;
|
|
87
|
+
usePlugin(name: string, plugin: any): void;
|
|
88
|
+
usePlugins(plugins: {
|
|
89
|
+
name: string;
|
|
90
|
+
plugin: any;
|
|
91
|
+
}[]): void;
|
|
92
|
+
getPlugin(name: string): any;
|
|
93
|
+
getGlobalData(): any;
|
|
94
|
+
install(): void;
|
|
95
|
+
unInstall(): void;
|
|
96
|
+
setBootstrap(bootstrap: Bootstrap): void;
|
|
97
|
+
getBootstrap(): Bootstrap | undefined;
|
|
98
|
+
}
|
|
99
|
+
export default App;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import App from '../app';
|
|
2
|
+
import { LoadLibraryByUrlParams } from '../locales/type';
|
|
3
|
+
import { MenuItem } from '../menuManager/index';
|
|
4
|
+
/**
|
|
5
|
+
* 应用接口类型定义
|
|
6
|
+
* @description 描述应用中单个页面、组件或功能的接口结构
|
|
7
|
+
*/
|
|
8
|
+
export declare type ApplicationInterface = {
|
|
9
|
+
page_type: 'low_code' | 'code';
|
|
10
|
+
page_id: number | string;
|
|
11
|
+
page_code: string;
|
|
12
|
+
page_version?: string;
|
|
13
|
+
page_name: string;
|
|
14
|
+
router: string;
|
|
15
|
+
category: 'page' | 'component' | 'function';
|
|
16
|
+
Component?: any;
|
|
17
|
+
children?: any;
|
|
18
|
+
layout?: string;
|
|
19
|
+
originalUrl?: string;
|
|
20
|
+
routeConfig?: {
|
|
21
|
+
cache?: boolean;
|
|
22
|
+
preload?: boolean;
|
|
23
|
+
prerender?: boolean;
|
|
24
|
+
priority?: 'high' | 'normal' | 'low';
|
|
25
|
+
};
|
|
26
|
+
autoRender?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 应用数据类型定义
|
|
30
|
+
* @description 描述完整应用的数据结构,包含应用的基本信息、接口、功能等
|
|
31
|
+
*/
|
|
32
|
+
export declare type ApplicationData = {
|
|
33
|
+
/** 应用唯一标识 */
|
|
34
|
+
app_id: number;
|
|
35
|
+
/** 应用名称 */
|
|
36
|
+
app_name: string;
|
|
37
|
+
/** 应用类型:系统应用或自定义应用 */
|
|
38
|
+
app_type: 'system' | 'custom';
|
|
39
|
+
/** 应用包含的接口列表 */
|
|
40
|
+
interfaces: ApplicationInterface[];
|
|
41
|
+
/** 应用包含的功能列表,可选 */
|
|
42
|
+
functions?: any[];
|
|
43
|
+
/** 应用的菜单配置 */
|
|
44
|
+
menu?: {
|
|
45
|
+
[key: string]: MenuItem[];
|
|
46
|
+
};
|
|
47
|
+
/** 多语言配置,可选 */
|
|
48
|
+
locales?: LoadLibraryByUrlParams;
|
|
49
|
+
/** 其他扩展属性 */
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* 应用管理类
|
|
54
|
+
* @description 负责管理单个应用的生命周期,包括接口、组件、功能的初始化和管理
|
|
55
|
+
* @class Application
|
|
56
|
+
* @author zhiwei.Wang
|
|
57
|
+
*/
|
|
58
|
+
export declare class Application {
|
|
59
|
+
/** 应用配置数据 */
|
|
60
|
+
options: ApplicationData;
|
|
61
|
+
/** 应用名称 */
|
|
62
|
+
name: ApplicationData['app_name'];
|
|
63
|
+
/** 应用内的页面接口映射表,以页面名称为键 */
|
|
64
|
+
interfaces: Map<ApplicationInterface['page_name'], ApplicationInterface>;
|
|
65
|
+
/** 应用内的组件映射表,以组件编码为键 */
|
|
66
|
+
components: Map<string, any>;
|
|
67
|
+
/** 应用内的功能函数映射表,比如跳转登录页面的方法等 */
|
|
68
|
+
functions: Map<string, any>;
|
|
69
|
+
/** 应用实例引用 */
|
|
70
|
+
app: App;
|
|
71
|
+
/**
|
|
72
|
+
* 构造函数
|
|
73
|
+
* @description 初始化应用实例,设置基本属性并初始化接口和功能
|
|
74
|
+
* @param {ApplicationData} options - 应用配置数据
|
|
75
|
+
* @param {App} app - 应用实例引用
|
|
76
|
+
*/
|
|
77
|
+
constructor(options: ApplicationData, app: App);
|
|
78
|
+
/**
|
|
79
|
+
* 应用添加后的内部处理方法
|
|
80
|
+
* @description 在应用被添加到应用管理器后执行的内部逻辑,包括加载多语言配置和执行用户自定义的afterAdd方法
|
|
81
|
+
* @param {Application} application - 被添加的应用实例
|
|
82
|
+
* @returns {Promise<void>}
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
_afterAdd(application: Application): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* 应用加载前的内部处理方法
|
|
88
|
+
* @description 在应用开始加载前执行的内部逻辑,调用用户自定义的beforeLoad方法
|
|
89
|
+
* @returns {Promise<void>}
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
_beforeLoad(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* 应用加载的内部处理方法
|
|
95
|
+
* @description 执行应用的实际加载逻辑,将应用中的所有接口注册为路由
|
|
96
|
+
* @returns {Promise<void>}
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
_load(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* 初始化应用接口
|
|
102
|
+
* @description 遍历应用配置中的接口列表,根据类别将它们分别设置到对应的映射表中
|
|
103
|
+
* @param {ApplicationData['interfaces']} interfaces - 接口配置数组
|
|
104
|
+
* @returns {void}
|
|
105
|
+
*/
|
|
106
|
+
initInterfaces(interfaces: ApplicationData['interfaces']): void;
|
|
107
|
+
/**
|
|
108
|
+
* 初始化应用功能函数
|
|
109
|
+
* @description 遍历应用配置中的功能列表,将它们设置到功能映射表中
|
|
110
|
+
* @param {ApplicationData['functions']} functions - 功能配置数组,可选
|
|
111
|
+
* @returns {void}
|
|
112
|
+
*/
|
|
113
|
+
initFunctions(functions: ApplicationData['functions']): void;
|
|
114
|
+
/**
|
|
115
|
+
* 加载接口组件
|
|
116
|
+
* @description 根据接口类型加载对应的组件,支持低代码和普通代码两种类型
|
|
117
|
+
* @param {ApplicationInterface} interfaceItem - 接口配置项
|
|
118
|
+
* @returns {Promise<ApplicationInterface>} 加载后的接口配置
|
|
119
|
+
*/
|
|
120
|
+
loadInterface(interfaceItem: ApplicationInterface): Promise<ApplicationInterface>;
|
|
121
|
+
/**
|
|
122
|
+
* 设置页面
|
|
123
|
+
* @description 将页面接口添加到接口映射表中
|
|
124
|
+
* @param {string} code - 页面编码
|
|
125
|
+
* @param {ApplicationInterface} interfaceItem - 接口配置项
|
|
126
|
+
* @returns {void}
|
|
127
|
+
*/
|
|
128
|
+
setInterface(code: string, interfaceItem: ApplicationInterface): void;
|
|
129
|
+
/**
|
|
130
|
+
* 设置组件
|
|
131
|
+
* @description 将组件添加到组件映射表中
|
|
132
|
+
* @param {string} code - 组件编码
|
|
133
|
+
* @param {ApplicationInterface} component - 组件配置项
|
|
134
|
+
* @returns {void}
|
|
135
|
+
*/
|
|
136
|
+
setComponent(code: string, component: ApplicationInterface): void;
|
|
137
|
+
/**
|
|
138
|
+
* 设置功能函数
|
|
139
|
+
* @description 将功能函数添加到功能映射表中
|
|
140
|
+
* @param {string} code - 功能编码
|
|
141
|
+
* @param {ApplicationInterface} functionItem - 功能配置项
|
|
142
|
+
* @returns {void}
|
|
143
|
+
*/
|
|
144
|
+
setFunction(code: string, functionItem: ApplicationInterface): void;
|
|
145
|
+
/**
|
|
146
|
+
* 获取页面
|
|
147
|
+
* @description 根据编码从接口映射表中获取页面接口
|
|
148
|
+
* @param {string} code - 页面编码
|
|
149
|
+
* @returns {ApplicationInterface | undefined} 接口配置项或undefined
|
|
150
|
+
*/
|
|
151
|
+
getInterface(code: string): ApplicationInterface | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* 获取组件
|
|
154
|
+
* @description 根据编码从组件映射表中获取组件
|
|
155
|
+
* @param {string} code - 组件编码
|
|
156
|
+
* @returns {any | undefined} 组件或undefined
|
|
157
|
+
*/
|
|
158
|
+
getComponent(code: string): any;
|
|
159
|
+
/**
|
|
160
|
+
* 获取功能函数
|
|
161
|
+
* @description 根据编码从功能映射表中获取功能函数
|
|
162
|
+
* @param {string} code - 功能编码
|
|
163
|
+
* @returns {any | undefined} 功能函数或undefined
|
|
164
|
+
*/
|
|
165
|
+
getFunction(code: string): any;
|
|
166
|
+
/**
|
|
167
|
+
* 执行功能函数
|
|
168
|
+
* @description 根据编码执行对应的功能函数,自动注入应用实例并合并参数
|
|
169
|
+
* @param {string} code - 功能编码
|
|
170
|
+
* @param {any} params - 传递给功能函数的参数对象,可选
|
|
171
|
+
* @param {...any} args - 传递给功能函数的其他参数
|
|
172
|
+
* @returns {any} 功能函数的执行结果
|
|
173
|
+
*/
|
|
174
|
+
runFunction(code: string, params?: any, ...args: any): any;
|
|
175
|
+
/**
|
|
176
|
+
* 应用添加后触发的钩子函数
|
|
177
|
+
* @description 在应用被添加到应用管理器后触发,可被子类覆盖以实现自定义逻辑
|
|
178
|
+
* @param {Application} application - 被添加的应用实例
|
|
179
|
+
* @returns {Promise<void>}
|
|
180
|
+
* @author zhiwei.Wang
|
|
181
|
+
*/
|
|
182
|
+
afterAdd(application: Application): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* 应用加载前触发的钩子函数
|
|
185
|
+
* @description 在应用开始加载前触发,可被子类覆盖以实现自定义预处理逻辑
|
|
186
|
+
* @returns {Promise<void>}
|
|
187
|
+
* @author zhiwei.Wang
|
|
188
|
+
*/
|
|
189
|
+
beforeLoad(application: Application): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* 应用加载完成后触发的钩子函数
|
|
192
|
+
* @description 在应用完成加载后触发,可被子类覆盖以实现自定义后处理逻辑
|
|
193
|
+
* @returns {Promise<void>}
|
|
194
|
+
* @author zhiwei.Wang
|
|
195
|
+
*/
|
|
196
|
+
load(application: Application): Promise<void>;
|
|
197
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import APP from '../app';
|
|
2
|
+
import { Application, ApplicationData } from './application';
|
|
3
|
+
export * from "./application";
|
|
4
|
+
export declare class ApplicationManager {
|
|
5
|
+
applicationList: Application[];
|
|
6
|
+
protected app: APP;
|
|
7
|
+
applications: Map<string, Application>;
|
|
8
|
+
constructor(applicationList: Application[], app: APP);
|
|
9
|
+
init(applicationList: Application[] | ApplicationData[]): Promise<unknown>;
|
|
10
|
+
add(application: Application): Promise<void>;
|
|
11
|
+
get(appName: Application['name']): Application | undefined;
|
|
12
|
+
remove(appName: Application['name']): void;
|
|
13
|
+
load(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* 循环所有的应用, 找出所有的components进行渲染
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
getAllComponents(): any[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LocationDescriptor } from "history";
|
|
2
|
+
import type { History as HistoryType } from "history";
|
|
3
|
+
import { useHistory, useLocation, useParams } from "react-router-dom";
|
|
4
|
+
import App from "../app";
|
|
5
|
+
export interface HistoryOptions {
|
|
6
|
+
basename?: string;
|
|
7
|
+
interceptor?: (path: LocationDescriptor<unknown>, state: any, next: () => void) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare class History {
|
|
10
|
+
instance: HistoryType<unknown>;
|
|
11
|
+
useHistory: typeof useHistory;
|
|
12
|
+
useLocation: typeof useLocation;
|
|
13
|
+
useParams: typeof useParams;
|
|
14
|
+
app: App;
|
|
15
|
+
interceptor?: (path: LocationDescriptor<unknown>, state: unknown, next: () => void) => void;
|
|
16
|
+
constructor(app: App, options?: HistoryOptions);
|
|
17
|
+
push: HistoryType["push"];
|
|
18
|
+
replace: HistoryType["replace"];
|
|
19
|
+
reload: () => void;
|
|
20
|
+
reloadTo: (path: string) => void;
|
|
21
|
+
externalPage: (path: string) => void;
|
|
22
|
+
goLogin: () => any;
|
|
23
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as request } from './request';
|
|
2
|
+
export { default as hooks } from './hooks';
|
|
3
|
+
export { default as models } from './models';
|
|
4
|
+
export { default as pubsub } from './pubsub';
|
|
5
|
+
export { default as socket } from './socket';
|
|
6
|
+
export * from './applicationManager';
|
|
7
|
+
export * from './app';
|
package/lib/indexDB/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
52
52
|
// 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
|
|
53
53
|
memoryStorage = /* @__PURE__ */ new Map();
|
|
54
54
|
// 操作超时时间(毫秒)
|
|
55
|
-
timeout =
|
|
55
|
+
timeout = 1e4;
|
|
56
56
|
/**
|
|
57
57
|
* 创建 IndexDBManager 实例
|
|
58
58
|
* @param {DBOptions} options - 数据库配置选项
|
|
@@ -63,7 +63,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
63
63
|
this.version = options.version;
|
|
64
64
|
this.stores = options.stores;
|
|
65
65
|
this.useIndexDB = _IndexDBManager.isSupported();
|
|
66
|
-
this.timeout = options.timeout ??
|
|
66
|
+
this.timeout = options.timeout ?? 1e4;
|
|
67
67
|
if (!this.useIndexDB) {
|
|
68
68
|
this.stores.forEach((store) => {
|
|
69
69
|
this.memoryStorage.set(store.name, /* @__PURE__ */ new Map());
|
|
@@ -200,11 +200,6 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
200
200
|
}
|
|
201
201
|
const uuid = `[ IndexDB ] ADD: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
|
|
202
202
|
if (log) {
|
|
203
|
-
this.app.logger.addLog({
|
|
204
|
-
type: "info",
|
|
205
|
-
title: uuid,
|
|
206
|
-
metadata: { msg: "添加数据前", data }
|
|
207
|
-
});
|
|
208
203
|
}
|
|
209
204
|
return this.withTimeout(
|
|
210
205
|
(async () => {
|
|
@@ -221,17 +216,7 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
221
216
|
try {
|
|
222
217
|
await this.db.table(storeName).add(data);
|
|
223
218
|
if (log) {
|
|
224
|
-
this.app.logger.addLog({
|
|
225
|
-
type: "info",
|
|
226
|
-
title: uuid,
|
|
227
|
-
metadata: { msg: "添加数据成功" }
|
|
228
|
-
});
|
|
229
219
|
console.log("✅ 添加事务完成");
|
|
230
|
-
this.app.logger.addLog({
|
|
231
|
-
type: "info",
|
|
232
|
-
title: uuid,
|
|
233
|
-
metadata: { msg: "事务完成" }
|
|
234
|
-
});
|
|
235
220
|
}
|
|
236
221
|
return data;
|
|
237
222
|
} catch (error) {
|
|
@@ -285,11 +270,6 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
285
270
|
async get(storeName, key, log = false) {
|
|
286
271
|
const uuid = `[ IndexDB ] GET: - ${storeName} - ${key} - ${(0, import_dayjs.default)().valueOf()}`;
|
|
287
272
|
if (log) {
|
|
288
|
-
this.app.logger.addLog({
|
|
289
|
-
type: "info",
|
|
290
|
-
title: uuid,
|
|
291
|
-
metadata: { msg: "获取数据前" }
|
|
292
|
-
});
|
|
293
273
|
}
|
|
294
274
|
if (!this.useIndexDB) {
|
|
295
275
|
const memStore = this.getMemoryStore(storeName);
|
|
@@ -310,16 +290,6 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
310
290
|
try {
|
|
311
291
|
const result = await this.db.table(storeName).get(key);
|
|
312
292
|
if (log) {
|
|
313
|
-
this.app.logger.addLog({
|
|
314
|
-
type: "info",
|
|
315
|
-
title: uuid,
|
|
316
|
-
metadata: { msg: "获取成功" }
|
|
317
|
-
});
|
|
318
|
-
this.app.logger.addLog({
|
|
319
|
-
type: "info",
|
|
320
|
-
title: uuid,
|
|
321
|
-
metadata: { msg: "事务完成" }
|
|
322
|
-
});
|
|
323
293
|
}
|
|
324
294
|
return result ?? null;
|
|
325
295
|
} catch (error) {
|
|
@@ -355,11 +325,6 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
355
325
|
}
|
|
356
326
|
const uuid = `[ IndexDB ] UPDATE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
|
|
357
327
|
if (log) {
|
|
358
|
-
this.app.logger.addLog({
|
|
359
|
-
type: "info",
|
|
360
|
-
title: uuid,
|
|
361
|
-
metadata: { msg: "更新数据前", data }
|
|
362
|
-
});
|
|
363
328
|
}
|
|
364
329
|
return this.withTimeout(
|
|
365
330
|
(async () => {
|
|
@@ -376,17 +341,6 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
376
341
|
try {
|
|
377
342
|
await this.db.table(storeName).put(data);
|
|
378
343
|
if (log) {
|
|
379
|
-
this.app.logger.addLog({
|
|
380
|
-
type: "info",
|
|
381
|
-
title: uuid,
|
|
382
|
-
metadata: { msg: "数据更新完成" }
|
|
383
|
-
});
|
|
384
|
-
console.log("✅ 事务完成");
|
|
385
|
-
this.app.logger.addLog({
|
|
386
|
-
type: "info",
|
|
387
|
-
title: uuid,
|
|
388
|
-
metadata: { msg: "事务完成" }
|
|
389
|
-
});
|
|
390
344
|
}
|
|
391
345
|
return data;
|
|
392
346
|
} catch (error) {
|
package/lib/logger/index.d.ts
CHANGED
package/lib/logger/index.js
CHANGED
|
@@ -67,10 +67,14 @@ var LoggerManager = class {
|
|
|
67
67
|
this.retentionDays = (options == null ? void 0 : options.retentionDays) || 7;
|
|
68
68
|
this.initDB();
|
|
69
69
|
}
|
|
70
|
-
init() {
|
|
70
|
+
async init() {
|
|
71
71
|
this.setStatus("running");
|
|
72
72
|
this.initTimer();
|
|
73
|
-
this.cleanupOldLogs();
|
|
73
|
+
await this.cleanupOldLogs();
|
|
74
|
+
try {
|
|
75
|
+
await this.uploadIndexDBLog();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
80
|
* 初始化 IndexDB
|
|
@@ -211,7 +215,6 @@ var LoggerManager = class {
|
|
|
211
215
|
*/
|
|
212
216
|
async storeLog(urgent) {
|
|
213
217
|
var _a;
|
|
214
|
-
this.uploadIndexDBLog();
|
|
215
218
|
if (this.logBuffer.length === 0 || !this.db) {
|
|
216
219
|
return;
|
|
217
220
|
}
|
|
@@ -236,8 +239,16 @@ var LoggerManager = class {
|
|
|
236
239
|
type: "error",
|
|
237
240
|
title: "存储日志到AWS失败",
|
|
238
241
|
metadata: {
|
|
239
|
-
error:
|
|
240
|
-
|
|
242
|
+
error: {
|
|
243
|
+
name: error == null ? void 0 : error.name,
|
|
244
|
+
message: error == null ? void 0 : error.message,
|
|
245
|
+
stack: error == null ? void 0 : error.stack
|
|
246
|
+
},
|
|
247
|
+
indexDBError: {
|
|
248
|
+
name: indexDBError == null ? void 0 : indexDBError.name,
|
|
249
|
+
message: indexDBError == null ? void 0 : indexDBError.message,
|
|
250
|
+
stack: indexDBError == null ? void 0 : indexDBError.stack
|
|
251
|
+
}
|
|
241
252
|
}
|
|
242
253
|
});
|
|
243
254
|
console.error("存储日志到IndexDB也失败:", indexDBError);
|
|
@@ -266,7 +277,11 @@ var LoggerManager = class {
|
|
|
266
277
|
type: "error",
|
|
267
278
|
title: "存储IndexDB日志到AWS失败",
|
|
268
279
|
metadata: {
|
|
269
|
-
error:
|
|
280
|
+
error: {
|
|
281
|
+
name: error == null ? void 0 : error.name,
|
|
282
|
+
message: error == null ? void 0 : error.message,
|
|
283
|
+
stack: error == null ? void 0 : error.stack
|
|
284
|
+
}
|
|
270
285
|
}
|
|
271
286
|
});
|
|
272
287
|
throw error;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import App from '../app';
|
|
3
|
+
export interface MenuItem {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
path: string;
|
|
7
|
+
children?: MenuItem[];
|
|
8
|
+
icon?: string | React.ReactNode;
|
|
9
|
+
hide?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class MenuManager {
|
|
12
|
+
private menuItems;
|
|
13
|
+
private menuMaps;
|
|
14
|
+
private app;
|
|
15
|
+
useMenu: () => import("./hooks").MenuContextType;
|
|
16
|
+
MenuProvider: React.FC<{
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
menus: MenuItem[];
|
|
19
|
+
}>;
|
|
20
|
+
constructor(items: MenuItem[], app: App);
|
|
21
|
+
set(items: MenuItem[]): void;
|
|
22
|
+
getMenus(): MenuItem[];
|
|
23
|
+
getMenuMaps(): void;
|
|
24
|
+
findMenuItemByPath(items: MenuItem[], path: string): MenuItem | null;
|
|
25
|
+
findParent(items: MenuItem[], key: string, parent?: MenuItem | null): MenuItem | null;
|
|
26
|
+
getShowChildren(items: MenuItem[]): MenuItem[];
|
|
27
|
+
findMenuItemByKey(items: MenuItem[], key: string): MenuItem | null;
|
|
28
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CacheProps } from './type';
|
|
2
|
+
export declare type CacheType = 'memory' | 'storage' | 'indexDB';
|
|
3
|
+
/**
|
|
4
|
+
* @title: 设置缓存
|
|
5
|
+
* @description:
|
|
6
|
+
* @return {*}
|
|
7
|
+
* @Author: zhiwei.Wang
|
|
8
|
+
*/
|
|
9
|
+
export declare const setCache: (key: string, data: any, cache: CacheProps) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* @title: 删除缓存数据
|
|
12
|
+
* @description:
|
|
13
|
+
* @return {*}
|
|
14
|
+
* @Author: zhiwei.Wang
|
|
15
|
+
*/
|
|
16
|
+
export declare const removeCache: (key: string, cache: CacheProps) => void;
|
|
17
|
+
/**
|
|
18
|
+
* @title: 获取数据
|
|
19
|
+
* @description:
|
|
20
|
+
* @param {any} url
|
|
21
|
+
* @param {any} data
|
|
22
|
+
* @return {*}
|
|
23
|
+
* @Author: zhiwei.Wang
|
|
24
|
+
*/
|
|
25
|
+
export declare const getCacheData: (url: string, data: any, cache: CacheProps) => Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* @title: 设置缓存
|
|
28
|
+
* @description:
|
|
29
|
+
* @param {any} url 路径
|
|
30
|
+
* @param {any} data 参数
|
|
31
|
+
* @param {any} res 数据
|
|
32
|
+
* @return {*}
|
|
33
|
+
* @Author: zhiwei.Wang
|
|
34
|
+
*/
|
|
35
|
+
export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
|
|
36
|
+
/**
|
|
37
|
+
* @title: 缓存函数包装器
|
|
38
|
+
* @description:
|
|
39
|
+
* @param {any} url
|
|
40
|
+
* @param {any} data
|
|
41
|
+
* @param {any} config
|
|
42
|
+
* @param {any} fn
|
|
43
|
+
* @return {*}
|
|
44
|
+
* @Author: zhiwei.Wang
|
|
45
|
+
*/
|
|
46
|
+
export declare const cacheFn: (props: any, fn: any) => Promise<any>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RequestWrapperProps, RequestConfig } from "./type";
|
|
2
|
+
export declare const createRequest: (props: RequestWrapperProps) => Promise<unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* 请求
|
|
5
|
+
* @param props
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const request: (props: RequestWrapperProps) => any;
|
|
9
|
+
export declare const get: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
10
|
+
export declare const post: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
11
|
+
export declare const put: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
12
|
+
export declare const remove: (url: RequestWrapperProps["url"], data: RequestWrapperProps["data"], config: RequestWrapperProps["config"]) => Promise<any>;
|
|
13
|
+
export declare const custom: (url: RequestWrapperProps["url"], config: RequestWrapperProps["config"]) => any;
|
|
14
|
+
export * from "./type";
|
|
15
|
+
declare const _default: {
|
|
16
|
+
get: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
17
|
+
post: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
18
|
+
put: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
19
|
+
remove: (url: string, data: any, config: import("./type").RequestSetting | undefined) => Promise<any>;
|
|
20
|
+
custom: (url: string, config: import("./type").RequestSetting | undefined) => any;
|
|
21
|
+
setConfig: (newConfig: Partial<RequestConfig>) => void;
|
|
22
|
+
getConfig: () => RequestConfig;
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CreateAxiosDefaults } from "axios";
|
|
2
|
+
import { CacheType } from './cache';
|
|
3
|
+
export interface RequestConfig {
|
|
4
|
+
interceptorsRequest?: ((value: any) => any | Promise<any>) | null;
|
|
5
|
+
interceptorsRequestError?: ((error: any) => any) | null;
|
|
6
|
+
interceptorsResponse?: any;
|
|
7
|
+
interceptorsResponseError?: ((error: any) => any) | null;
|
|
8
|
+
axiosConfig?: CreateAxiosDefaults;
|
|
9
|
+
storage?: any;
|
|
10
|
+
getToken?: () => string | null;
|
|
11
|
+
setToken?: (token: string) => void;
|
|
12
|
+
getLocale?: () => string | null;
|
|
13
|
+
getUrl?: (config: any) => string;
|
|
14
|
+
requestCallbacks?: {
|
|
15
|
+
200?: (data: any) => void;
|
|
16
|
+
401?: (data: any) => void;
|
|
17
|
+
403?: (data: any) => void;
|
|
18
|
+
other?: (data: any) => void;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare enum RequestModeENUM {
|
|
23
|
+
LOCAL = "local",
|
|
24
|
+
REMOTE = "remote",
|
|
25
|
+
LOCAL_REMOTE = "local_remote",
|
|
26
|
+
REMOTE_LOCAL = "remote_local",
|
|
27
|
+
OS_SERVER = "os_server"
|
|
28
|
+
}
|
|
29
|
+
export declare type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
|
|
30
|
+
export interface CacheProps {
|
|
31
|
+
key?: string;
|
|
32
|
+
type?: CacheType;
|
|
33
|
+
updateCache?: boolean;
|
|
34
|
+
cacheUpdateChange?: (data: any) => void;
|
|
35
|
+
mode?: RequestModeType;
|
|
36
|
+
cacheKeyData?: any;
|
|
37
|
+
}
|
|
38
|
+
export interface RequestSetting {
|
|
39
|
+
abort?: boolean;
|
|
40
|
+
headers?: any;
|
|
41
|
+
cache?: CacheProps;
|
|
42
|
+
signal?: any;
|
|
43
|
+
token?: string;
|
|
44
|
+
osServer?: boolean;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
export interface RequestWrapperProps {
|
|
48
|
+
url: string;
|
|
49
|
+
method: 'get' | 'post' | 'remove' | 'put';
|
|
50
|
+
data?: any;
|
|
51
|
+
config?: RequestSetting;
|
|
52
|
+
}
|