@pisell/core 1.1.4 → 1.1.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/es/indexDB/index.d.ts +27 -11
- package/es/indexDB/index.js +751 -636
- package/es/logger/index.d.ts +3 -3
- package/es/logger/index.js +17 -15
- package/es/routes/index.d.ts +1 -1
- package/es/socket/monitor.js +2 -0
- package/es/socket/types.d.ts +3 -2
- package/lib/applicationManager/index.js +3 -1
- package/lib/indexDB/index.d.ts +27 -11
- package/lib/indexDB/index.js +332 -359
- package/lib/logger/index.d.ts +3 -3
- package/lib/logger/index.js +11 -10
- package/lib/routes/index.d.ts +1 -1
- package/lib/socket/monitor.js +2 -0
- package/lib/socket/types.d.ts +3 -2
- package/package.json +3 -2
package/es/logger/index.d.ts
CHANGED
|
@@ -81,10 +81,10 @@ declare class LoggerManager {
|
|
|
81
81
|
private createFileName;
|
|
82
82
|
/**
|
|
83
83
|
* 创建AWS日志文件名
|
|
84
|
-
* @param isManual
|
|
84
|
+
* @param isManual 紧急上传
|
|
85
85
|
* @returns 日志文件名
|
|
86
86
|
*/
|
|
87
|
-
createAWSFileName(
|
|
87
|
+
createAWSFileName(urgent?: boolean): Promise<any>;
|
|
88
88
|
/**
|
|
89
89
|
* 创建日志文件
|
|
90
90
|
* @param _fileName 文件名
|
|
@@ -94,7 +94,7 @@ declare class LoggerManager {
|
|
|
94
94
|
/**
|
|
95
95
|
* 存储日志到持久化存储
|
|
96
96
|
*/
|
|
97
|
-
storeLog(): Promise<void>;
|
|
97
|
+
storeLog(urgent?: boolean): Promise<void>;
|
|
98
98
|
private storeLogToIndexDB;
|
|
99
99
|
/**
|
|
100
100
|
* 清理旧日志,只保留最近指定天数的日志
|
package/es/logger/index.js
CHANGED
|
@@ -159,12 +159,14 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
159
159
|
logId: dayjs().valueOf()
|
|
160
160
|
});
|
|
161
161
|
console.log("---- 行为日志", logItem);
|
|
162
|
+
this.logBuffer.push(logItem);
|
|
162
163
|
if (log.type === "error") {
|
|
163
164
|
this.sendFeishuNotification(_objectSpread(_objectSpread({}, logItem || {}), {}, {
|
|
164
165
|
feishu: feishu
|
|
165
166
|
}));
|
|
167
|
+
// error 级别日志需要立即存储
|
|
168
|
+
this.storeLog(true);
|
|
166
169
|
}
|
|
167
|
-
this.logBuffer.push(logItem);
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
/**
|
|
@@ -221,34 +223,34 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
221
223
|
|
|
222
224
|
/**
|
|
223
225
|
* 创建AWS日志文件名
|
|
224
|
-
* @param isManual
|
|
226
|
+
* @param isManual 紧急上传
|
|
225
227
|
* @returns 日志文件名
|
|
226
228
|
*/
|
|
227
229
|
}, {
|
|
228
230
|
key: "createAWSFileName",
|
|
229
231
|
value: (function () {
|
|
230
|
-
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(
|
|
232
|
+
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(urgent) {
|
|
231
233
|
var _this$app;
|
|
232
234
|
var _date, _hour, _this$app2, fileName;
|
|
233
235
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
234
236
|
while (1) switch (_context2.prev = _context2.next) {
|
|
235
237
|
case 0:
|
|
236
238
|
_date = dayjs().format("YYYY-MM-DD");
|
|
237
|
-
_hour = dayjs().format("HH:mm"); //
|
|
239
|
+
_hour = dayjs().format("HH:mm"); // 紧急上传时,在小时后面加上当前时间戳 避免文件名重复覆盖
|
|
240
|
+
if (urgent) {
|
|
241
|
+
_hour = "".concat(dayjs().format("HH:mm"), " [ urgent ] ").concat(dayjs().valueOf());
|
|
242
|
+
}
|
|
238
243
|
if (!((_this$app = this.app) !== null && _this$app !== void 0 && (_this$app = _this$app.getPlugin("aws")) !== null && _this$app !== void 0 && _this$app.createFileName)) {
|
|
239
|
-
_context2.next =
|
|
244
|
+
_context2.next = 5;
|
|
240
245
|
break;
|
|
241
246
|
}
|
|
242
247
|
return _context2.abrupt("return", (_this$app2 = this.app) === null || _this$app2 === void 0 || (_this$app2 = _this$app2.getPlugin("aws")) === null || _this$app2 === void 0 ? void 0 : _this$app2.createFileName({
|
|
243
248
|
date: _date,
|
|
244
249
|
hour: _hour,
|
|
245
|
-
isManual:
|
|
250
|
+
isManual: false
|
|
246
251
|
}));
|
|
247
|
-
case
|
|
252
|
+
case 5:
|
|
248
253
|
fileName = "logs/".concat("pisell", "/", _date, "/").concat(_hour);
|
|
249
|
-
if (isManual) {
|
|
250
|
-
fileName += "-manual";
|
|
251
|
-
}
|
|
252
254
|
return _context2.abrupt("return", "".concat(fileName, ".json"));
|
|
253
255
|
case 7:
|
|
254
256
|
case "end":
|
|
@@ -288,7 +290,7 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
288
290
|
}, {
|
|
289
291
|
key: "storeLog",
|
|
290
292
|
value: (function () {
|
|
291
|
-
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
293
|
+
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(urgent) {
|
|
292
294
|
var _this$logBuffer, fileName, buffer, logs;
|
|
293
295
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
294
296
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -301,7 +303,7 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
301
303
|
case 2:
|
|
302
304
|
_context3.prev = 2;
|
|
303
305
|
_context3.next = 5;
|
|
304
|
-
return this.createAWSFileName();
|
|
306
|
+
return this.createAWSFileName(urgent);
|
|
305
307
|
case 5:
|
|
306
308
|
fileName = _context3.sent;
|
|
307
309
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
@@ -346,7 +348,7 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
346
348
|
}
|
|
347
349
|
}, _callee3, this, [[2, 15], [18, 23]]);
|
|
348
350
|
}));
|
|
349
|
-
function storeLog() {
|
|
351
|
+
function storeLog(_x2) {
|
|
350
352
|
return _storeLog.apply(this, arguments);
|
|
351
353
|
}
|
|
352
354
|
return storeLog;
|
|
@@ -561,7 +563,7 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
561
563
|
}
|
|
562
564
|
}, _callee7, this, [[2, 8]]);
|
|
563
565
|
}));
|
|
564
|
-
function getLogFile(
|
|
566
|
+
function getLogFile(_x3) {
|
|
565
567
|
return _getLogFile.apply(this, arguments);
|
|
566
568
|
}
|
|
567
569
|
return getLogFile;
|
|
@@ -611,7 +613,7 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
611
613
|
}
|
|
612
614
|
}, _callee8, this, [[2, 13]]);
|
|
613
615
|
}));
|
|
614
|
-
function clearLogs(
|
|
616
|
+
function clearLogs(_x4) {
|
|
615
617
|
return _clearLogs.apply(this, arguments);
|
|
616
618
|
}
|
|
617
619
|
return clearLogs;
|
package/es/routes/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class RouterManager {
|
|
|
20
20
|
get(name: string): RouteType;
|
|
21
21
|
has(name: string): boolean;
|
|
22
22
|
remove(name: string): void;
|
|
23
|
-
renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean |
|
|
23
|
+
renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
|
|
24
24
|
getPageByRoute(route: string): ApplicationInterface | undefined;
|
|
25
25
|
getRouterComponent({ fallback }: {
|
|
26
26
|
fallback?: React.ReactNode;
|
package/es/socket/monitor.js
CHANGED
|
@@ -332,6 +332,7 @@ export var SocketMonitor = /*#__PURE__*/function () {
|
|
|
332
332
|
id: message.id || "out_".concat(Date.now()),
|
|
333
333
|
timestamp: Date.now(),
|
|
334
334
|
direction: 'out',
|
|
335
|
+
//@ts-ignore
|
|
335
336
|
message: this.options.recordMessageContent ? message : {
|
|
336
337
|
event: message.event
|
|
337
338
|
},
|
|
@@ -363,6 +364,7 @@ export var SocketMonitor = /*#__PURE__*/function () {
|
|
|
363
364
|
id: message.id || "in_".concat(Date.now()),
|
|
364
365
|
timestamp: Date.now(),
|
|
365
366
|
direction: 'in',
|
|
367
|
+
//@ts-ignore
|
|
366
368
|
message: this.options.recordMessageContent ? message : {
|
|
367
369
|
event: message.event
|
|
368
370
|
},
|
package/es/socket/types.d.ts
CHANGED
|
@@ -38,13 +38,14 @@ export declare enum SocketStatus {
|
|
|
38
38
|
/**
|
|
39
39
|
* Socket消息格式
|
|
40
40
|
*/
|
|
41
|
-
export interface SocketMessage
|
|
41
|
+
export interface SocketMessage {
|
|
42
42
|
/** 事件类型 */
|
|
43
43
|
type: string;
|
|
44
44
|
/** 消息数据 */
|
|
45
|
-
data?:
|
|
45
|
+
data?: any;
|
|
46
46
|
/** 消息ID */
|
|
47
47
|
id?: string;
|
|
48
|
+
event?: any;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* 心跳配置选项
|
|
@@ -74,7 +74,9 @@ var ApplicationManager = class {
|
|
|
74
74
|
* @returns
|
|
75
75
|
*/
|
|
76
76
|
getAllComponents() {
|
|
77
|
-
return Array.from(this.applications.values()).flatMap(
|
|
77
|
+
return Array.from(this.applications.values()).flatMap(
|
|
78
|
+
(application) => Array.from(application.components.values())
|
|
79
|
+
).filter((component) => component.autoRender).map((component) => component.Component);
|
|
78
80
|
}
|
|
79
81
|
};
|
|
80
82
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/indexDB/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import App from "../app";
|
|
|
2
2
|
/**
|
|
3
3
|
* IndexDB 管理器模块
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* 这个模块使用 Dexie.js 提供了对浏览器 IndexedDB 的简单封装,并在不支持 IndexedDB 的环境中
|
|
6
|
+
* 自动降级使用内存存储作为备选存储方案。
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* 数据库配置选项接口
|
|
@@ -30,10 +30,11 @@ export interface DBOptions {
|
|
|
30
30
|
options?: IDBIndexParameters;
|
|
31
31
|
}[];
|
|
32
32
|
}[];
|
|
33
|
+
timeout?: number;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* IndexDB 管理器类
|
|
36
|
-
* 提供对 IndexedDB
|
|
37
|
+
* 使用 Dexie.js 提供对 IndexedDB 的封装,支持自动降级到内存存储
|
|
37
38
|
* @class IndexDBManager
|
|
38
39
|
*/
|
|
39
40
|
declare class IndexDBManager {
|
|
@@ -49,25 +50,34 @@ declare class IndexDBManager {
|
|
|
49
50
|
private stores;
|
|
50
51
|
private useIndexDB;
|
|
51
52
|
private app;
|
|
53
|
+
private memoryStorage;
|
|
54
|
+
private timeout;
|
|
52
55
|
/**
|
|
53
56
|
* 创建 IndexDBManager 实例
|
|
54
57
|
* @param {DBOptions} options - 数据库配置选项
|
|
55
58
|
*/
|
|
56
59
|
constructor(app: App, options: DBOptions);
|
|
60
|
+
/**
|
|
61
|
+
* 超时包装器 - 为 Promise 添加超时控制
|
|
62
|
+
* @param {Promise<T>} promise - 需要包装的 Promise
|
|
63
|
+
* @param {string} operation - 操作名称(用于错误提示)
|
|
64
|
+
* @returns {Promise<T>} 带超时控制的 Promise
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
private withTimeout;
|
|
57
68
|
/**
|
|
58
69
|
* 初始化数据库连接
|
|
59
|
-
* 如果环境不支持 IndexedDB
|
|
70
|
+
* 如果环境不支持 IndexedDB,将自动使用内存存储
|
|
60
71
|
* @returns {Promise<boolean>} 连接是否成功
|
|
61
72
|
*/
|
|
62
73
|
connect(): Promise<boolean>;
|
|
63
74
|
/**
|
|
64
|
-
*
|
|
75
|
+
* 获取内存存储中指定 store 的 Map
|
|
65
76
|
* @param {string} storeName - 存储对象名称
|
|
66
|
-
* @
|
|
67
|
-
* @returns {string} 格式化的存储键
|
|
77
|
+
* @returns {Map<string | number, any>} 存储 Map
|
|
68
78
|
* @private
|
|
69
79
|
*/
|
|
70
|
-
private
|
|
80
|
+
private getMemoryStore;
|
|
71
81
|
/**
|
|
72
82
|
* 添加数据到指定的存储对象
|
|
73
83
|
* @param {string} storeName - 存储对象名称
|
|
@@ -169,9 +179,9 @@ declare class IndexDBManager {
|
|
|
169
179
|
close(): void;
|
|
170
180
|
/**
|
|
171
181
|
* 获取当前使用的存储方式
|
|
172
|
-
* @returns {'indexDB'|'
|
|
182
|
+
* @returns {'indexDB'|'memory'} 当前使用的存储方式
|
|
173
183
|
*/
|
|
174
|
-
getCurrentStorage(): 'indexDB' | '
|
|
184
|
+
getCurrentStorage(): 'indexDB' | 'memory';
|
|
175
185
|
}
|
|
176
186
|
/**
|
|
177
187
|
* 使用示例:
|
|
@@ -240,12 +250,18 @@ declare class IndexDBManager {
|
|
|
240
250
|
* db.close();
|
|
241
251
|
*
|
|
242
252
|
* // 15. 检查当前使用的存储方式
|
|
243
|
-
* const storageType = db.getCurrentStorage(); // 'indexDB' 或 '
|
|
253
|
+
* const storageType = db.getCurrentStorage(); // 'indexDB' 或 'memory'
|
|
244
254
|
*
|
|
245
255
|
* // 性能优化建议:
|
|
246
256
|
* // - 使用 exists() 而不是 get() 来检查数据是否存在
|
|
247
257
|
* // - 为常用查询字段创建索引
|
|
248
258
|
* // - 使用索引查询方法来提高查询效率
|
|
249
259
|
* // - 批量操作时使用事务(可以考虑后续扩展)
|
|
260
|
+
*
|
|
261
|
+
* // 降级方案说明:
|
|
262
|
+
* // - 当浏览器不支持 IndexedDB 时,会自动使用内存存储 (Map) 作为降级方案
|
|
263
|
+
* // - 内存存储的数据在页面刷新后会丢失,仅适合临时数据存储
|
|
264
|
+
* // - 内存存储支持所有 IndexedDB API,包括索引查询
|
|
265
|
+
* // - 对于需要持久化的数据,请确保浏览器支持 IndexedDB
|
|
250
266
|
*/
|
|
251
267
|
export default IndexDBManager;
|