@pisell/core 1.0.53 → 1.0.55
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/logger/index.js +22 -25
- package/es/tasks/index.js +1 -13
- package/lib/logger/index.js +0 -2
- package/lib/tasks/index.js +0 -4
- package/package.json +1 -1
- package/es/logger/index.d.ts +0 -135
- package/lib/logger/index.d.ts +0 -135
package/es/logger/index.js
CHANGED
|
@@ -308,18 +308,16 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
308
308
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
309
309
|
while (1) switch (_context4.prev = _context4.next) {
|
|
310
310
|
case 0:
|
|
311
|
-
// 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
|
|
312
|
-
this.uploadIndexDBLog();
|
|
313
311
|
if (!(this.logBuffer.length === 0 || !this.db)) {
|
|
314
|
-
_context4.next =
|
|
312
|
+
_context4.next = 2;
|
|
315
313
|
break;
|
|
316
314
|
}
|
|
317
315
|
return _context4.abrupt("return");
|
|
318
|
-
case
|
|
319
|
-
_context4.prev =
|
|
320
|
-
_context4.next =
|
|
316
|
+
case 2:
|
|
317
|
+
_context4.prev = 2;
|
|
318
|
+
_context4.next = 5;
|
|
321
319
|
return this.createAWSFileName(urgent);
|
|
322
|
-
case
|
|
320
|
+
case 5:
|
|
323
321
|
fileName = _context4.sent;
|
|
324
322
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
325
323
|
|
|
@@ -333,13 +331,13 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
333
331
|
return item.logId;
|
|
334
332
|
});
|
|
335
333
|
logs = JSON.stringify(buffer, null, 2);
|
|
336
|
-
_context4.next =
|
|
334
|
+
_context4.next = 12;
|
|
337
335
|
return this.app.aws.upload({
|
|
338
336
|
Bucket: "",
|
|
339
337
|
Key: fileName,
|
|
340
338
|
Body: logs
|
|
341
339
|
});
|
|
342
|
-
case
|
|
340
|
+
case 12:
|
|
343
341
|
this.addLog({
|
|
344
342
|
type: "info",
|
|
345
343
|
title: "存储日志到AWS 成功",
|
|
@@ -356,11 +354,11 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
356
354
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
357
355
|
return !bufferIds.includes(item.logId);
|
|
358
356
|
});
|
|
359
|
-
_context4.next =
|
|
357
|
+
_context4.next = 30;
|
|
360
358
|
break;
|
|
361
|
-
case
|
|
362
|
-
_context4.prev =
|
|
363
|
-
_context4.t0 = _context4["catch"](
|
|
359
|
+
case 17:
|
|
360
|
+
_context4.prev = 17;
|
|
361
|
+
_context4.t0 = _context4["catch"](2);
|
|
364
362
|
console.error("存储日志上传AWS失败:", _context4.t0);
|
|
365
363
|
this.addLog({
|
|
366
364
|
type: "info",
|
|
@@ -375,15 +373,15 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
375
373
|
});
|
|
376
374
|
|
|
377
375
|
// 将日志存储到IndexDB
|
|
378
|
-
_context4.prev =
|
|
379
|
-
_context4.next =
|
|
376
|
+
_context4.prev = 21;
|
|
377
|
+
_context4.next = 24;
|
|
380
378
|
return this.storeLogToIndexDB();
|
|
381
|
-
case
|
|
382
|
-
_context4.next =
|
|
379
|
+
case 24:
|
|
380
|
+
_context4.next = 30;
|
|
383
381
|
break;
|
|
384
|
-
case
|
|
385
|
-
_context4.prev =
|
|
386
|
-
_context4.t1 = _context4["catch"](
|
|
382
|
+
case 26:
|
|
383
|
+
_context4.prev = 26;
|
|
384
|
+
_context4.t1 = _context4["catch"](21);
|
|
387
385
|
this.sendFeishuNotification({
|
|
388
386
|
type: "error",
|
|
389
387
|
title: "将日志存储到IndexDB失败",
|
|
@@ -396,11 +394,11 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
396
394
|
}
|
|
397
395
|
});
|
|
398
396
|
console.error("存储日志到IndexDB也失败:", _context4.t1);
|
|
399
|
-
case
|
|
397
|
+
case 30:
|
|
400
398
|
case "end":
|
|
401
399
|
return _context4.stop();
|
|
402
400
|
}
|
|
403
|
-
}, _callee4, this, [[
|
|
401
|
+
}, _callee4, this, [[2, 17], [21, 26]]);
|
|
404
402
|
}));
|
|
405
403
|
function storeLog(_x2) {
|
|
406
404
|
return _storeLog.apply(this, arguments);
|
|
@@ -453,7 +451,7 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
453
451
|
return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
|
|
454
452
|
case 18:
|
|
455
453
|
console.log("-------- 清空IndexDB日志成功");
|
|
456
|
-
_context5.next =
|
|
454
|
+
_context5.next = 25;
|
|
457
455
|
break;
|
|
458
456
|
case 21:
|
|
459
457
|
_context5.prev = 21;
|
|
@@ -482,8 +480,7 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
482
480
|
// },
|
|
483
481
|
// });
|
|
484
482
|
// 重新抛出错误,让外层 catch 能够捕获
|
|
485
|
-
|
|
486
|
-
case 26:
|
|
483
|
+
case 25:
|
|
487
484
|
case "end":
|
|
488
485
|
return _context5.stop();
|
|
489
486
|
}
|
package/es/tasks/index.js
CHANGED
|
@@ -586,25 +586,13 @@ export var TasksManager = /*#__PURE__*/function () {
|
|
|
586
586
|
key: "init",
|
|
587
587
|
value: function () {
|
|
588
588
|
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
589
|
-
var tasks;
|
|
590
589
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
591
590
|
while (1) switch (_context6.prev = _context6.next) {
|
|
592
591
|
case 0:
|
|
593
|
-
_context6.next = 2;
|
|
594
|
-
return this.loadTaskQueueFromLocal();
|
|
595
|
-
case 2:
|
|
596
|
-
tasks = _context6.sent;
|
|
597
|
-
if (tasks) {
|
|
598
|
-
console.log("initTasks", tasks);
|
|
599
|
-
// this.tasks = tasks;
|
|
600
|
-
|
|
601
|
-
// 自动执行缓存的任务?
|
|
602
|
-
}
|
|
603
|
-
case 4:
|
|
604
592
|
case "end":
|
|
605
593
|
return _context6.stop();
|
|
606
594
|
}
|
|
607
|
-
}, _callee6
|
|
595
|
+
}, _callee6);
|
|
608
596
|
}));
|
|
609
597
|
function init() {
|
|
610
598
|
return _init.apply(this, arguments);
|
package/lib/logger/index.js
CHANGED
|
@@ -211,7 +211,6 @@ var LoggerManager = class {
|
|
|
211
211
|
*/
|
|
212
212
|
async storeLog(urgent) {
|
|
213
213
|
var _a;
|
|
214
|
-
this.uploadIndexDBLog();
|
|
215
214
|
if (this.logBuffer.length === 0 || !this.db) {
|
|
216
215
|
return;
|
|
217
216
|
}
|
|
@@ -302,7 +301,6 @@ var LoggerManager = class {
|
|
|
302
301
|
}
|
|
303
302
|
}
|
|
304
303
|
});
|
|
305
|
-
throw error;
|
|
306
304
|
}
|
|
307
305
|
}
|
|
308
306
|
async storeLogToIndexDB() {
|
package/lib/tasks/index.js
CHANGED
|
@@ -90,10 +90,6 @@ var TasksManager = class _TasksManager {
|
|
|
90
90
|
}
|
|
91
91
|
// 初始化任务
|
|
92
92
|
async init() {
|
|
93
|
-
const tasks = await this.loadTaskQueueFromLocal();
|
|
94
|
-
if (tasks) {
|
|
95
|
-
console.log("initTasks", tasks);
|
|
96
|
-
}
|
|
97
93
|
}
|
|
98
94
|
// 将任务队列状态同步到 local
|
|
99
95
|
saveTaskQueueToLocal = async (state) => {
|
package/package.json
CHANGED
package/es/logger/index.d.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import App from "../app";
|
|
2
|
-
export declare type LogConsoleType = "info" | "warning" | "error" | "debug";
|
|
3
|
-
/**
|
|
4
|
-
* 日志项接口
|
|
5
|
-
*/
|
|
6
|
-
interface LogItem {
|
|
7
|
-
logId?: string | number;
|
|
8
|
-
type: LogConsoleType;
|
|
9
|
-
title: string;
|
|
10
|
-
date?: string;
|
|
11
|
-
metadata?: any;
|
|
12
|
-
feishu?: any;
|
|
13
|
-
}
|
|
14
|
-
interface LogFile {
|
|
15
|
-
fileName: string;
|
|
16
|
-
date: string;
|
|
17
|
-
fileContent: LogFileContent;
|
|
18
|
-
}
|
|
19
|
-
interface LogFileContent {
|
|
20
|
-
metadata: any;
|
|
21
|
-
logs: LogItem[];
|
|
22
|
-
}
|
|
23
|
-
export interface LoggerOptions {
|
|
24
|
-
prefix?: string;
|
|
25
|
-
checkInterval?: number;
|
|
26
|
-
feishuConfig?: any;
|
|
27
|
-
retentionDays?: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 日志管理器类
|
|
31
|
-
*/
|
|
32
|
-
declare class LoggerManager {
|
|
33
|
-
private logBuffer;
|
|
34
|
-
private timer;
|
|
35
|
-
private checkInterval;
|
|
36
|
-
private prefix;
|
|
37
|
-
private metadata;
|
|
38
|
-
private db;
|
|
39
|
-
private app;
|
|
40
|
-
private feishuConfig;
|
|
41
|
-
private retentionDays;
|
|
42
|
-
private metadataFunction;
|
|
43
|
-
private status;
|
|
44
|
-
/**
|
|
45
|
-
* 构造函数
|
|
46
|
-
* @param prefix 日志前缀
|
|
47
|
-
* @param checkInterval 检查间隔时间,默认5分钟
|
|
48
|
-
*/
|
|
49
|
-
constructor(app: App, options?: LoggerOptions);
|
|
50
|
-
init(): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* 初始化 IndexDB
|
|
53
|
-
*/
|
|
54
|
-
private initDB;
|
|
55
|
-
/**
|
|
56
|
-
* 设置元数据
|
|
57
|
-
* @param metadata 元数据
|
|
58
|
-
*/
|
|
59
|
-
setMetadata(metadata: any): void;
|
|
60
|
-
setMetadataFunction(metadataFunction: () => any): void;
|
|
61
|
-
/**
|
|
62
|
-
* 初始化定时器
|
|
63
|
-
*/
|
|
64
|
-
initTimer(): void;
|
|
65
|
-
private setStatus;
|
|
66
|
-
stop(): void;
|
|
67
|
-
/**
|
|
68
|
-
* 添加日志
|
|
69
|
-
* @param log 日志项
|
|
70
|
-
*/
|
|
71
|
-
addLog(log: LogItem): void;
|
|
72
|
-
/**
|
|
73
|
-
* 发送飞书通知
|
|
74
|
-
* @param log 日志项
|
|
75
|
-
*/
|
|
76
|
-
private sendFeishuNotification;
|
|
77
|
-
/**
|
|
78
|
-
* 创建日志文件名
|
|
79
|
-
* @returns 日志文件名
|
|
80
|
-
*/
|
|
81
|
-
private createFileName;
|
|
82
|
-
/**
|
|
83
|
-
* 创建AWS日志文件名
|
|
84
|
-
* @param isManual 紧急上传
|
|
85
|
-
* @returns 日志文件名
|
|
86
|
-
*/
|
|
87
|
-
createAWSFileName(urgent?: boolean): Promise<any>;
|
|
88
|
-
/**
|
|
89
|
-
* 创建日志文件
|
|
90
|
-
* @param _fileName 文件名
|
|
91
|
-
* @returns 日志文件对象
|
|
92
|
-
*/
|
|
93
|
-
private createFile;
|
|
94
|
-
/**
|
|
95
|
-
* 存储日志到持久化存储
|
|
96
|
-
*/
|
|
97
|
-
storeLog(urgent?: boolean): Promise<void>;
|
|
98
|
-
uploadIndexDBLog(): Promise<void>;
|
|
99
|
-
private storeLogToIndexDB;
|
|
100
|
-
/**
|
|
101
|
-
* 清理旧日志,只保留最近指定天数的日志
|
|
102
|
-
*/
|
|
103
|
-
private cleanupOldLogs;
|
|
104
|
-
/**
|
|
105
|
-
* 获取日志文件列表
|
|
106
|
-
* @returns 日志文件列表
|
|
107
|
-
*/
|
|
108
|
-
getLogFiles(): Promise<LogFile[]>;
|
|
109
|
-
/**
|
|
110
|
-
* 获取指定日志文件的内容
|
|
111
|
-
* @param fileName 日志文件名
|
|
112
|
-
* @returns 日志文件内容
|
|
113
|
-
*/
|
|
114
|
-
getLogFile(fileName: string): Promise<LogFile | null>;
|
|
115
|
-
/**
|
|
116
|
-
* 清空指定日志文件
|
|
117
|
-
* @param fileName 日志文件名,不指定则清空所有日志
|
|
118
|
-
* @returns 是否成功
|
|
119
|
-
*/
|
|
120
|
-
clearLogs(fileName?: string): Promise<boolean>;
|
|
121
|
-
/**
|
|
122
|
-
* 设置日志保留天数
|
|
123
|
-
* @param days 保留天数
|
|
124
|
-
*/
|
|
125
|
-
setRetentionDays(days: number): void;
|
|
126
|
-
/**
|
|
127
|
-
* 手动触发清理旧日志
|
|
128
|
-
*/
|
|
129
|
-
manualCleanup(): Promise<void>;
|
|
130
|
-
/**
|
|
131
|
-
* 销毁实例
|
|
132
|
-
*/
|
|
133
|
-
destroy(): void;
|
|
134
|
-
}
|
|
135
|
-
export default LoggerManager;
|
package/lib/logger/index.d.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import App from "../app";
|
|
2
|
-
export declare type LogConsoleType = "info" | "warning" | "error" | "debug";
|
|
3
|
-
/**
|
|
4
|
-
* 日志项接口
|
|
5
|
-
*/
|
|
6
|
-
interface LogItem {
|
|
7
|
-
logId?: string | number;
|
|
8
|
-
type: LogConsoleType;
|
|
9
|
-
title: string;
|
|
10
|
-
date?: string;
|
|
11
|
-
metadata?: any;
|
|
12
|
-
feishu?: any;
|
|
13
|
-
}
|
|
14
|
-
interface LogFile {
|
|
15
|
-
fileName: string;
|
|
16
|
-
date: string;
|
|
17
|
-
fileContent: LogFileContent;
|
|
18
|
-
}
|
|
19
|
-
interface LogFileContent {
|
|
20
|
-
metadata: any;
|
|
21
|
-
logs: LogItem[];
|
|
22
|
-
}
|
|
23
|
-
export interface LoggerOptions {
|
|
24
|
-
prefix?: string;
|
|
25
|
-
checkInterval?: number;
|
|
26
|
-
feishuConfig?: any;
|
|
27
|
-
retentionDays?: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 日志管理器类
|
|
31
|
-
*/
|
|
32
|
-
declare class LoggerManager {
|
|
33
|
-
private logBuffer;
|
|
34
|
-
private timer;
|
|
35
|
-
private checkInterval;
|
|
36
|
-
private prefix;
|
|
37
|
-
private metadata;
|
|
38
|
-
private db;
|
|
39
|
-
private app;
|
|
40
|
-
private feishuConfig;
|
|
41
|
-
private retentionDays;
|
|
42
|
-
private metadataFunction;
|
|
43
|
-
private status;
|
|
44
|
-
/**
|
|
45
|
-
* 构造函数
|
|
46
|
-
* @param prefix 日志前缀
|
|
47
|
-
* @param checkInterval 检查间隔时间,默认5分钟
|
|
48
|
-
*/
|
|
49
|
-
constructor(app: App, options?: LoggerOptions);
|
|
50
|
-
init(): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* 初始化 IndexDB
|
|
53
|
-
*/
|
|
54
|
-
private initDB;
|
|
55
|
-
/**
|
|
56
|
-
* 设置元数据
|
|
57
|
-
* @param metadata 元数据
|
|
58
|
-
*/
|
|
59
|
-
setMetadata(metadata: any): void;
|
|
60
|
-
setMetadataFunction(metadataFunction: () => any): void;
|
|
61
|
-
/**
|
|
62
|
-
* 初始化定时器
|
|
63
|
-
*/
|
|
64
|
-
initTimer(): void;
|
|
65
|
-
private setStatus;
|
|
66
|
-
stop(): void;
|
|
67
|
-
/**
|
|
68
|
-
* 添加日志
|
|
69
|
-
* @param log 日志项
|
|
70
|
-
*/
|
|
71
|
-
addLog(log: LogItem): void;
|
|
72
|
-
/**
|
|
73
|
-
* 发送飞书通知
|
|
74
|
-
* @param log 日志项
|
|
75
|
-
*/
|
|
76
|
-
private sendFeishuNotification;
|
|
77
|
-
/**
|
|
78
|
-
* 创建日志文件名
|
|
79
|
-
* @returns 日志文件名
|
|
80
|
-
*/
|
|
81
|
-
private createFileName;
|
|
82
|
-
/**
|
|
83
|
-
* 创建AWS日志文件名
|
|
84
|
-
* @param isManual 紧急上传
|
|
85
|
-
* @returns 日志文件名
|
|
86
|
-
*/
|
|
87
|
-
createAWSFileName(urgent?: boolean): Promise<any>;
|
|
88
|
-
/**
|
|
89
|
-
* 创建日志文件
|
|
90
|
-
* @param _fileName 文件名
|
|
91
|
-
* @returns 日志文件对象
|
|
92
|
-
*/
|
|
93
|
-
private createFile;
|
|
94
|
-
/**
|
|
95
|
-
* 存储日志到持久化存储
|
|
96
|
-
*/
|
|
97
|
-
storeLog(urgent?: boolean): Promise<void>;
|
|
98
|
-
uploadIndexDBLog(): Promise<void>;
|
|
99
|
-
private storeLogToIndexDB;
|
|
100
|
-
/**
|
|
101
|
-
* 清理旧日志,只保留最近指定天数的日志
|
|
102
|
-
*/
|
|
103
|
-
private cleanupOldLogs;
|
|
104
|
-
/**
|
|
105
|
-
* 获取日志文件列表
|
|
106
|
-
* @returns 日志文件列表
|
|
107
|
-
*/
|
|
108
|
-
getLogFiles(): Promise<LogFile[]>;
|
|
109
|
-
/**
|
|
110
|
-
* 获取指定日志文件的内容
|
|
111
|
-
* @param fileName 日志文件名
|
|
112
|
-
* @returns 日志文件内容
|
|
113
|
-
*/
|
|
114
|
-
getLogFile(fileName: string): Promise<LogFile | null>;
|
|
115
|
-
/**
|
|
116
|
-
* 清空指定日志文件
|
|
117
|
-
* @param fileName 日志文件名,不指定则清空所有日志
|
|
118
|
-
* @returns 是否成功
|
|
119
|
-
*/
|
|
120
|
-
clearLogs(fileName?: string): Promise<boolean>;
|
|
121
|
-
/**
|
|
122
|
-
* 设置日志保留天数
|
|
123
|
-
* @param days 保留天数
|
|
124
|
-
*/
|
|
125
|
-
setRetentionDays(days: number): void;
|
|
126
|
-
/**
|
|
127
|
-
* 手动触发清理旧日志
|
|
128
|
-
*/
|
|
129
|
-
manualCleanup(): Promise<void>;
|
|
130
|
-
/**
|
|
131
|
-
* 销毁实例
|
|
132
|
-
*/
|
|
133
|
-
destroy(): void;
|
|
134
|
-
}
|
|
135
|
-
export default LoggerManager;
|