@pisell/core 1.0.54 → 1.0.56
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.js +6 -17
- package/es/tasks/index.js +1 -13
- package/lib/indexDB/index.js +2 -4
- 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/indexDB/index.js
CHANGED
|
@@ -634,6 +634,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
634
634
|
// })
|
|
635
635
|
}
|
|
636
636
|
return _context10.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
637
|
+
var issExists;
|
|
637
638
|
return _regeneratorRuntime().wrap(function _callee7$(_context9) {
|
|
638
639
|
while (1) switch (_context9.prev = _context9.next) {
|
|
639
640
|
case 0:
|
|
@@ -657,25 +658,13 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
657
658
|
_context9.next = 6;
|
|
658
659
|
return _this8.db.table(storeName).add(data);
|
|
659
660
|
case 6:
|
|
660
|
-
if (log) {
|
|
661
|
-
// this.app.logger.addLog({
|
|
662
|
-
// type: 'info',
|
|
663
|
-
// title: uuid,
|
|
664
|
-
// metadata: { msg: '添加数据成功' }
|
|
665
|
-
// });
|
|
666
|
-
console.log('✅ 添加事务完成');
|
|
667
|
-
// this.app.logger.addLog({
|
|
668
|
-
// type: 'info',
|
|
669
|
-
// title: uuid,
|
|
670
|
-
// metadata: { msg: '事务完成' }
|
|
671
|
-
// });
|
|
672
|
-
}
|
|
673
661
|
return _context9.abrupt("return", data);
|
|
674
|
-
case
|
|
675
|
-
_context9.prev =
|
|
662
|
+
case 9:
|
|
663
|
+
_context9.prev = 9;
|
|
676
664
|
_context9.t0 = _context9["catch"](3);
|
|
665
|
+
issExists = ((_context9.t0 === null || _context9.t0 === void 0 ? void 0 : _context9.t0.message) || '').includes('exists'); // 如果错误信息中包含 'exists',则表示数据已存在,不报日志
|
|
677
666
|
_this8.app.logger.addLog({
|
|
678
|
-
type: 'error',
|
|
667
|
+
type: issExists ? 'info' : 'error',
|
|
679
668
|
title: uuid,
|
|
680
669
|
metadata: {
|
|
681
670
|
msg: '添加数据失败',
|
|
@@ -688,7 +677,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
688
677
|
case "end":
|
|
689
678
|
return _context9.stop();
|
|
690
679
|
}
|
|
691
|
-
}, _callee7, null, [[3,
|
|
680
|
+
}, _callee7, null, [[3, 9]]);
|
|
692
681
|
}))(), "add(".concat(storeName, ")")));
|
|
693
682
|
case 11:
|
|
694
683
|
case "end":
|
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/indexDB/index.js
CHANGED
|
@@ -367,13 +367,11 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
367
367
|
}
|
|
368
368
|
try {
|
|
369
369
|
await this.db.table(storeName).add(data);
|
|
370
|
-
if (log) {
|
|
371
|
-
console.log("✅ 添加事务完成");
|
|
372
|
-
}
|
|
373
370
|
return data;
|
|
374
371
|
} catch (error) {
|
|
372
|
+
const issExists = ((error == null ? void 0 : error.message) || "").includes("exists");
|
|
375
373
|
this.app.logger.addLog({
|
|
376
|
-
type: "error",
|
|
374
|
+
type: issExists ? "info" : "error",
|
|
377
375
|
title: uuid,
|
|
378
376
|
metadata: {
|
|
379
377
|
msg: "添加数据失败",
|
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;
|