@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.
Files changed (37) hide show
  1. package/es/app/app.d.ts +99 -0
  2. package/es/applicationManager/application.d.ts +197 -0
  3. package/es/applicationManager/index.d.ts +19 -0
  4. package/es/history/index.d.ts +23 -0
  5. package/es/index.d.ts +7 -0
  6. package/es/indexDB/index.js +48 -68
  7. package/es/logger/index.d.ts +1 -1
  8. package/es/logger/index.js +199 -165
  9. package/es/menuManager/index.d.ts +28 -0
  10. package/es/request/cache.d.ts +46 -0
  11. package/es/request/index.d.ts +24 -0
  12. package/es/request/type.d.ts +52 -0
  13. package/es/request/utils.d.ts +46 -0
  14. package/es/tasks/index.d.ts +127 -0
  15. package/es/tasks/scheduledTasksExample.d.ts +61 -0
  16. package/es/tasks/type.d.ts +100 -0
  17. package/es/utils/adaptiveThrottle/index.d.ts +36 -0
  18. package/es/utils/adaptiveThrottle/index.js +136 -0
  19. package/lib/app/app.d.ts +99 -0
  20. package/lib/applicationManager/application.d.ts +197 -0
  21. package/lib/applicationManager/index.d.ts +19 -0
  22. package/lib/history/index.d.ts +23 -0
  23. package/lib/index.d.ts +7 -0
  24. package/lib/indexDB/index.js +2 -48
  25. package/lib/logger/index.d.ts +1 -1
  26. package/lib/logger/index.js +21 -6
  27. package/lib/menuManager/index.d.ts +28 -0
  28. package/lib/request/cache.d.ts +46 -0
  29. package/lib/request/index.d.ts +24 -0
  30. package/lib/request/type.d.ts +52 -0
  31. package/lib/request/utils.d.ts +46 -0
  32. package/lib/tasks/index.d.ts +127 -0
  33. package/lib/tasks/scheduledTasksExample.d.ts +61 -0
  34. package/lib/tasks/type.d.ts +100 -0
  35. package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
  36. package/lib/utils/adaptiveThrottle/index.js +121 -0
  37. package/package.json +1 -1
@@ -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/es/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';
@@ -60,13 +60,13 @@ var IndexDBManager = /*#__PURE__*/function () {
60
60
  // 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
61
61
  _defineProperty(this, "memoryStorage", new Map());
62
62
  // 操作超时时间(毫秒)
63
- _defineProperty(this, "timeout", 5000);
63
+ _defineProperty(this, "timeout", 10000);
64
64
  this.app = app;
65
65
  this.dbName = options.dbName;
66
66
  this.version = options.version;
67
67
  this.stores = options.stores;
68
68
  this.useIndexDB = IndexDBManager.isSupported();
69
- this.timeout = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 5000; // 默认 5 秒超时
69
+ this.timeout = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 10000; // 默认 10 秒超时
70
70
 
71
71
  // 初始化内存存储的各个 store
72
72
  if (!this.useIndexDB) {
@@ -279,14 +279,11 @@ var IndexDBManager = /*#__PURE__*/function () {
279
279
  case 8:
280
280
  uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
281
281
  if (log) {
282
- this.app.logger.addLog({
283
- type: 'info',
284
- title: uuid,
285
- metadata: {
286
- msg: '添加数据前',
287
- data: data
288
- }
289
- });
282
+ // this.app.logger.addLog({
283
+ // type: 'info',
284
+ // title: uuid,
285
+ // metadata: { msg: '添加数据前', data: data }
286
+ // })
290
287
  }
291
288
  return _context4.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
292
289
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
@@ -313,21 +310,17 @@ var IndexDBManager = /*#__PURE__*/function () {
313
310
  return _this4.db.table(storeName).add(data);
314
311
  case 6:
315
312
  if (log) {
316
- _this4.app.logger.addLog({
317
- type: 'info',
318
- title: uuid,
319
- metadata: {
320
- msg: '添加数据成功'
321
- }
322
- });
313
+ // this.app.logger.addLog({
314
+ // type: 'info',
315
+ // title: uuid,
316
+ // metadata: { msg: '添加数据成功' }
317
+ // });
323
318
  console.log('✅ 添加事务完成');
324
- _this4.app.logger.addLog({
325
- type: 'info',
326
- title: uuid,
327
- metadata: {
328
- msg: '事务完成'
329
- }
330
- });
319
+ // this.app.logger.addLog({
320
+ // type: 'info',
321
+ // title: uuid,
322
+ // metadata: { msg: '事务完成' }
323
+ // });
331
324
  }
332
325
  return _context3.abrupt("return", data);
333
326
  case 10:
@@ -448,13 +441,11 @@ var IndexDBManager = /*#__PURE__*/function () {
448
441
  log = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : false;
449
442
  uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
450
443
  if (log) {
451
- this.app.logger.addLog({
452
- type: 'info',
453
- title: uuid,
454
- metadata: {
455
- msg: '获取数据前'
456
- }
457
- });
444
+ // this.app.logger.addLog({
445
+ // type: 'info',
446
+ // title: uuid,
447
+ // metadata: { msg: '获取数据前' }
448
+ // })
458
449
  }
459
450
  if (this.useIndexDB) {
460
451
  _context8.next = 6;
@@ -490,20 +481,16 @@ var IndexDBManager = /*#__PURE__*/function () {
490
481
  case 6:
491
482
  result = _context7.sent;
492
483
  if (log) {
493
- _this6.app.logger.addLog({
494
- type: 'info',
495
- title: uuid,
496
- metadata: {
497
- msg: '获取成功'
498
- }
499
- });
500
- _this6.app.logger.addLog({
501
- type: 'info',
502
- title: uuid,
503
- metadata: {
504
- msg: '事务完成'
505
- }
506
- });
484
+ // this.app.logger.addLog({
485
+ // type: 'info',
486
+ // title: uuid,
487
+ // metadata: { msg: '获取成功' }
488
+ // });
489
+ // this.app.logger.addLog({
490
+ // type: 'info',
491
+ // title: uuid,
492
+ // metadata: { msg: '事务完成' }
493
+ // });
507
494
  }
508
495
  return _context7.abrupt("return", result !== null && result !== void 0 ? result : null);
509
496
  case 11:
@@ -578,14 +565,11 @@ var IndexDBManager = /*#__PURE__*/function () {
578
565
  case 8:
579
566
  uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
580
567
  if (log) {
581
- this.app.logger.addLog({
582
- type: 'info',
583
- title: uuid,
584
- metadata: {
585
- msg: '更新数据前',
586
- data: data
587
- }
588
- });
568
+ // this.app.logger.addLog({
569
+ // type: 'info',
570
+ // title: uuid,
571
+ // metadata: { msg: '更新数据前', data: data }
572
+ // })
589
573
  }
590
574
  return _context10.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
591
575
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
@@ -611,21 +595,17 @@ var IndexDBManager = /*#__PURE__*/function () {
611
595
  return _this7.db.table(storeName).put(data);
612
596
  case 6:
613
597
  if (log) {
614
- _this7.app.logger.addLog({
615
- type: 'info',
616
- title: uuid,
617
- metadata: {
618
- msg: '数据更新完成'
619
- }
620
- });
621
- console.log('✅ 事务完成');
622
- _this7.app.logger.addLog({
623
- type: 'info',
624
- title: uuid,
625
- metadata: {
626
- msg: '事务完成'
627
- }
628
- });
598
+ // this.app.logger.addLog({
599
+ // type: 'info',
600
+ // title: uuid,
601
+ // metadata: { msg: '数据更新完成' }
602
+ // });
603
+ // console.log('✅ 事务完成');
604
+ // this.app.logger.addLog({
605
+ // type: 'info',
606
+ // title: uuid,
607
+ // metadata: { msg: '事务完成' }
608
+ // });
629
609
  }
630
610
  return _context9.abrupt("return", data);
631
611
  case 10:
@@ -47,7 +47,7 @@ declare class LoggerManager {
47
47
  * @param checkInterval 检查间隔时间,默认5分钟
48
48
  */
49
49
  constructor(app: App, options?: LoggerOptions);
50
- init(): void;
50
+ init(): Promise<void>;
51
51
  /**
52
52
  * 初始化 IndexDB
53
53
  */