@pisell/core 1.0.42 → 1.0.44
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.d.ts +1 -1
- package/es/logger/index.js +187 -173
- package/es/routes/index.d.ts +1 -1
- package/es/tasks/index.d.ts +1 -1
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +2 -2
- package/lib/routes/index.d.ts +1 -1
- package/lib/tasks/index.d.ts +1 -1
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/package.json +1 -1
package/es/logger/index.d.ts
CHANGED
package/es/logger/index.js
CHANGED
|
@@ -65,31 +65,44 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
65
65
|
}
|
|
66
66
|
_createClass(LoggerManager, [{
|
|
67
67
|
key: "init",
|
|
68
|
-
value: function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
value: function () {
|
|
69
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
70
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
71
|
+
while (1) switch (_context.prev = _context.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
this.setStatus("running");
|
|
74
|
+
this.initTimer();
|
|
75
|
+
// 定期清理旧日志
|
|
76
|
+
this.cleanupOldLogs();
|
|
77
|
+
case 3:
|
|
78
|
+
case "end":
|
|
79
|
+
return _context.stop();
|
|
80
|
+
}
|
|
81
|
+
}, _callee, this);
|
|
82
|
+
}));
|
|
83
|
+
function init() {
|
|
84
|
+
return _init.apply(this, arguments);
|
|
85
|
+
}
|
|
86
|
+
return init;
|
|
87
|
+
}()
|
|
75
88
|
/**
|
|
76
89
|
* 初始化 IndexDB
|
|
77
90
|
*/
|
|
78
91
|
}, {
|
|
79
92
|
key: "initDB",
|
|
80
93
|
value: (function () {
|
|
81
|
-
var _initDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
82
|
-
return _regeneratorRuntime().wrap(function
|
|
83
|
-
while (1) switch (
|
|
94
|
+
var _initDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
95
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
96
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
84
97
|
case 0:
|
|
85
98
|
if (this.app.dbManager) {
|
|
86
99
|
this.db = this.app.dbManager;
|
|
87
100
|
}
|
|
88
101
|
case 1:
|
|
89
102
|
case "end":
|
|
90
|
-
return
|
|
103
|
+
return _context2.stop();
|
|
91
104
|
}
|
|
92
|
-
},
|
|
105
|
+
}, _callee2, this);
|
|
93
106
|
}));
|
|
94
107
|
function initDB() {
|
|
95
108
|
return _initDB.apply(this, arguments);
|
|
@@ -229,11 +242,11 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
229
242
|
}, {
|
|
230
243
|
key: "createAWSFileName",
|
|
231
244
|
value: (function () {
|
|
232
|
-
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
245
|
+
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(urgent) {
|
|
233
246
|
var _this$app;
|
|
234
247
|
var _date, _hour, _this$app2, fileName;
|
|
235
|
-
return _regeneratorRuntime().wrap(function
|
|
236
|
-
while (1) switch (
|
|
248
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
249
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
237
250
|
case 0:
|
|
238
251
|
_date = dayjs().format("YYYY-MM-DD");
|
|
239
252
|
_hour = dayjs().format("HH:mm"); // 紧急上传时,在小时后面加上当前时间戳 避免文件名重复覆盖
|
|
@@ -241,22 +254,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
241
254
|
_hour = "".concat(dayjs().format("HH:mm"), " [ urgent ] ").concat(dayjs().valueOf());
|
|
242
255
|
}
|
|
243
256
|
if (!((_this$app = this.app) !== null && _this$app !== void 0 && (_this$app = _this$app.getPlugin("aws")) !== null && _this$app !== void 0 && _this$app.createFileName)) {
|
|
244
|
-
|
|
257
|
+
_context3.next = 5;
|
|
245
258
|
break;
|
|
246
259
|
}
|
|
247
|
-
return
|
|
260
|
+
return _context3.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({
|
|
248
261
|
date: _date,
|
|
249
262
|
hour: _hour,
|
|
250
263
|
isManual: false
|
|
251
264
|
}));
|
|
252
265
|
case 5:
|
|
253
266
|
fileName = "logs/".concat("pisell", "/", _date, "/").concat(_hour);
|
|
254
|
-
return
|
|
267
|
+
return _context3.abrupt("return", "".concat(fileName, ".json"));
|
|
255
268
|
case 7:
|
|
256
269
|
case "end":
|
|
257
|
-
return
|
|
270
|
+
return _context3.stop();
|
|
258
271
|
}
|
|
259
|
-
},
|
|
272
|
+
}, _callee3, this);
|
|
260
273
|
}));
|
|
261
274
|
function createAWSFileName(_x) {
|
|
262
275
|
return _createAWSFileName.apply(this, arguments);
|
|
@@ -290,24 +303,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
290
303
|
}, {
|
|
291
304
|
key: "storeLog",
|
|
292
305
|
value: (function () {
|
|
293
|
-
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
306
|
+
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(urgent) {
|
|
294
307
|
var _this$logBuffer, fileName, buffer, bufferIds, logs;
|
|
295
|
-
return _regeneratorRuntime().wrap(function
|
|
296
|
-
while (1) switch (
|
|
308
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
309
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
297
310
|
case 0:
|
|
298
|
-
// 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
|
|
299
|
-
this.uploadIndexDBLog();
|
|
300
311
|
if (!(this.logBuffer.length === 0 || !this.db)) {
|
|
301
|
-
|
|
312
|
+
_context4.next = 2;
|
|
302
313
|
break;
|
|
303
314
|
}
|
|
304
|
-
return
|
|
305
|
-
case
|
|
306
|
-
|
|
307
|
-
|
|
315
|
+
return _context4.abrupt("return");
|
|
316
|
+
case 2:
|
|
317
|
+
_context4.prev = 2;
|
|
318
|
+
_context4.next = 5;
|
|
308
319
|
return this.createAWSFileName(urgent);
|
|
309
|
-
case
|
|
310
|
-
fileName =
|
|
320
|
+
case 5:
|
|
321
|
+
fileName = _context4.sent;
|
|
311
322
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
312
323
|
|
|
313
324
|
// 将buffer中的metadata转换为对象
|
|
@@ -319,57 +330,57 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
319
330
|
return item.logId;
|
|
320
331
|
});
|
|
321
332
|
logs = JSON.stringify(buffer, null, 2);
|
|
322
|
-
|
|
333
|
+
_context4.next = 12;
|
|
323
334
|
return this.app.aws.upload({
|
|
324
335
|
Bucket: "",
|
|
325
336
|
Key: fileName,
|
|
326
337
|
Body: logs
|
|
327
338
|
});
|
|
328
|
-
case
|
|
339
|
+
case 12:
|
|
329
340
|
console.log("-------- 存储日志到AWS 成功");
|
|
330
341
|
// 上传成功后需要清空缓冲区,避免重复上传
|
|
331
342
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
332
343
|
return !bufferIds.includes(item.logId);
|
|
333
344
|
});
|
|
334
|
-
|
|
345
|
+
_context4.next = 28;
|
|
335
346
|
break;
|
|
336
|
-
case
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
console.error("存储日志上传AWS失败:",
|
|
347
|
+
case 16:
|
|
348
|
+
_context4.prev = 16;
|
|
349
|
+
_context4.t0 = _context4["catch"](2);
|
|
350
|
+
console.error("存储日志上传AWS失败:", _context4.t0);
|
|
340
351
|
|
|
341
352
|
// 将日志存储到IndexDB
|
|
342
|
-
|
|
343
|
-
|
|
353
|
+
_context4.prev = 19;
|
|
354
|
+
_context4.next = 22;
|
|
344
355
|
return this.storeLogToIndexDB();
|
|
345
|
-
case
|
|
346
|
-
|
|
356
|
+
case 22:
|
|
357
|
+
_context4.next = 28;
|
|
347
358
|
break;
|
|
348
|
-
case
|
|
349
|
-
|
|
350
|
-
|
|
359
|
+
case 24:
|
|
360
|
+
_context4.prev = 24;
|
|
361
|
+
_context4.t1 = _context4["catch"](19);
|
|
351
362
|
this.sendFeishuNotification({
|
|
352
363
|
type: "error",
|
|
353
364
|
title: "存储日志到AWS失败",
|
|
354
365
|
metadata: {
|
|
355
366
|
error: {
|
|
356
|
-
name:
|
|
357
|
-
message:
|
|
358
|
-
stack:
|
|
367
|
+
name: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.name,
|
|
368
|
+
message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
|
|
369
|
+
stack: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.stack
|
|
359
370
|
},
|
|
360
371
|
indexDBError: {
|
|
361
|
-
name:
|
|
362
|
-
message:
|
|
363
|
-
stack:
|
|
372
|
+
name: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.name,
|
|
373
|
+
message: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.message,
|
|
374
|
+
stack: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.stack
|
|
364
375
|
}
|
|
365
376
|
}
|
|
366
377
|
});
|
|
367
|
-
console.error("存储日志到IndexDB也失败:",
|
|
368
|
-
case
|
|
378
|
+
console.error("存储日志到IndexDB也失败:", _context4.t1);
|
|
379
|
+
case 28:
|
|
369
380
|
case "end":
|
|
370
|
-
return
|
|
381
|
+
return _context4.stop();
|
|
371
382
|
}
|
|
372
|
-
},
|
|
383
|
+
}, _callee4, this, [[2, 16], [19, 24]]);
|
|
373
384
|
}));
|
|
374
385
|
function storeLog(_x2) {
|
|
375
386
|
return _storeLog.apply(this, arguments);
|
|
@@ -379,34 +390,34 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
379
390
|
}, {
|
|
380
391
|
key: "uploadIndexDBLog",
|
|
381
392
|
value: function () {
|
|
382
|
-
var _uploadIndexDBLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
393
|
+
var _uploadIndexDBLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
383
394
|
var _this$db, _this$db2, logFile, awsFileName, logs;
|
|
384
|
-
return _regeneratorRuntime().wrap(function
|
|
385
|
-
while (1) switch (
|
|
395
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
396
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
386
397
|
case 0:
|
|
387
|
-
|
|
398
|
+
_context5.prev = 0;
|
|
388
399
|
if (this.db) {
|
|
389
|
-
|
|
400
|
+
_context5.next = 3;
|
|
390
401
|
break;
|
|
391
402
|
}
|
|
392
|
-
return
|
|
403
|
+
return _context5.abrupt("return");
|
|
393
404
|
case 3:
|
|
394
|
-
|
|
405
|
+
_context5.next = 5;
|
|
395
406
|
return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
|
|
396
407
|
case 5:
|
|
397
|
-
logFile =
|
|
408
|
+
logFile = _context5.sent;
|
|
398
409
|
if (!(!logFile || (logFile === null || logFile === void 0 ? void 0 : logFile.length) === 0)) {
|
|
399
|
-
|
|
410
|
+
_context5.next = 8;
|
|
400
411
|
break;
|
|
401
412
|
}
|
|
402
|
-
return
|
|
413
|
+
return _context5.abrupt("return");
|
|
403
414
|
case 8:
|
|
404
|
-
|
|
415
|
+
_context5.next = 10;
|
|
405
416
|
return this.createAWSFileName(true);
|
|
406
417
|
case 10:
|
|
407
|
-
awsFileName =
|
|
418
|
+
awsFileName = _context5.sent;
|
|
408
419
|
logs = JSON.stringify(logFile, null, 2);
|
|
409
|
-
|
|
420
|
+
_context5.next = 14;
|
|
410
421
|
return this.app.aws.upload({
|
|
411
422
|
Bucket: "",
|
|
412
423
|
Key: awsFileName,
|
|
@@ -414,34 +425,34 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
414
425
|
});
|
|
415
426
|
case 14:
|
|
416
427
|
console.log("-------- 存储日志到AWS 成功");
|
|
417
|
-
|
|
428
|
+
_context5.next = 17;
|
|
418
429
|
return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
|
|
419
430
|
case 17:
|
|
420
431
|
console.log("-------- 清空IndexDB日志成功");
|
|
421
|
-
|
|
432
|
+
_context5.next = 25;
|
|
422
433
|
break;
|
|
423
434
|
case 20:
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
console.log("-------- 存储日志到IndexDB 失败",
|
|
435
|
+
_context5.prev = 20;
|
|
436
|
+
_context5.t0 = _context5["catch"](0);
|
|
437
|
+
console.log("-------- 存储日志到IndexDB 失败", _context5.t0);
|
|
427
438
|
this.sendFeishuNotification({
|
|
428
439
|
type: "error",
|
|
429
440
|
title: "存储IndexDB日志到AWS失败",
|
|
430
441
|
metadata: {
|
|
431
442
|
error: {
|
|
432
|
-
name:
|
|
433
|
-
message:
|
|
434
|
-
stack:
|
|
443
|
+
name: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.name,
|
|
444
|
+
message: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message,
|
|
445
|
+
stack: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.stack
|
|
435
446
|
}
|
|
436
447
|
}
|
|
437
448
|
});
|
|
438
449
|
// 重新抛出错误,让外层 catch 能够捕获
|
|
439
|
-
throw
|
|
450
|
+
throw _context5.t0;
|
|
440
451
|
case 25:
|
|
441
452
|
case "end":
|
|
442
|
-
return
|
|
453
|
+
return _context5.stop();
|
|
443
454
|
}
|
|
444
|
-
},
|
|
455
|
+
}, _callee5, this, [[0, 20]]);
|
|
445
456
|
}));
|
|
446
457
|
function uploadIndexDBLog() {
|
|
447
458
|
return _uploadIndexDBLog.apply(this, arguments);
|
|
@@ -451,32 +462,32 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
451
462
|
}, {
|
|
452
463
|
key: "storeLogToIndexDB",
|
|
453
464
|
value: function () {
|
|
454
|
-
var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
465
|
+
var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
455
466
|
var _this$db3, _this$db5, fileName, buffer, logFile, _this$db4, bufferIds;
|
|
456
|
-
return _regeneratorRuntime().wrap(function
|
|
457
|
-
while (1) switch (
|
|
467
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
468
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
458
469
|
case 0:
|
|
459
|
-
|
|
470
|
+
_context6.prev = 0;
|
|
460
471
|
fileName = this.createFileName();
|
|
461
472
|
console.log("storeLog", fileName);
|
|
462
473
|
buffer = this.logBuffer || []; // 获取现有日志文件
|
|
463
|
-
|
|
474
|
+
_context6.next = 6;
|
|
464
475
|
return (_this$db3 = this.db) === null || _this$db3 === void 0 ? void 0 : _this$db3.get("logs", fileName);
|
|
465
476
|
case 6:
|
|
466
|
-
logFile =
|
|
477
|
+
logFile = _context6.sent;
|
|
467
478
|
if (logFile) {
|
|
468
|
-
|
|
479
|
+
_context6.next = 11;
|
|
469
480
|
break;
|
|
470
481
|
}
|
|
471
482
|
logFile = this.createFile(fileName);
|
|
472
|
-
|
|
483
|
+
_context6.next = 11;
|
|
473
484
|
return (_this$db4 = this.db) === null || _this$db4 === void 0 ? void 0 : _this$db4.add("logs", logFile);
|
|
474
485
|
case 11:
|
|
475
486
|
// 添加日志到文件内容
|
|
476
487
|
logFile.fileContent.logs = [].concat(_toConsumableArray(logFile.fileContent.logs), _toConsumableArray(buffer));
|
|
477
488
|
|
|
478
489
|
// 更新日志文件
|
|
479
|
-
|
|
490
|
+
_context6.next = 14;
|
|
480
491
|
return (_this$db5 = this.db) === null || _this$db5 === void 0 ? void 0 : _this$db5.update("logs", logFile);
|
|
481
492
|
case 14:
|
|
482
493
|
console.log("-------- 存储日志到IndexDB", {
|
|
@@ -489,19 +500,19 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
489
500
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
490
501
|
return !bufferIds.includes(item.logId);
|
|
491
502
|
});
|
|
492
|
-
|
|
503
|
+
_context6.next = 23;
|
|
493
504
|
break;
|
|
494
505
|
case 19:
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
console.log("-------- 存储日志到IndexDB 失败",
|
|
506
|
+
_context6.prev = 19;
|
|
507
|
+
_context6.t0 = _context6["catch"](0);
|
|
508
|
+
console.log("-------- 存储日志到IndexDB 失败", _context6.t0);
|
|
498
509
|
// 重新抛出错误,让外层 catch 能够捕获
|
|
499
|
-
throw
|
|
510
|
+
throw _context6.t0;
|
|
500
511
|
case 23:
|
|
501
512
|
case "end":
|
|
502
|
-
return
|
|
513
|
+
return _context6.stop();
|
|
503
514
|
}
|
|
504
|
-
},
|
|
515
|
+
}, _callee6, this, [[0, 19]]);
|
|
505
516
|
}));
|
|
506
517
|
function storeLogToIndexDB() {
|
|
507
518
|
return _storeLogToIndexDB.apply(this, arguments);
|
|
@@ -514,22 +525,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
514
525
|
}, {
|
|
515
526
|
key: "cleanupOldLogs",
|
|
516
527
|
value: (function () {
|
|
517
|
-
var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
528
|
+
var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
518
529
|
var logFiles, cutoffDate, filesToDelete, _iterator, _step, file;
|
|
519
|
-
return _regeneratorRuntime().wrap(function
|
|
520
|
-
while (1) switch (
|
|
530
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
531
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
521
532
|
case 0:
|
|
522
533
|
if (this.db) {
|
|
523
|
-
|
|
534
|
+
_context7.next = 2;
|
|
524
535
|
break;
|
|
525
536
|
}
|
|
526
|
-
return
|
|
537
|
+
return _context7.abrupt("return");
|
|
527
538
|
case 2:
|
|
528
|
-
|
|
529
|
-
|
|
539
|
+
_context7.prev = 2;
|
|
540
|
+
_context7.next = 5;
|
|
530
541
|
return this.getLogFiles();
|
|
531
542
|
case 5:
|
|
532
|
-
logFiles =
|
|
543
|
+
logFiles = _context7.sent;
|
|
533
544
|
// 计算保留日志的截止日期
|
|
534
545
|
cutoffDate = dayjs().subtract(this.retentionDays, "day").format("YYYY-MM-DD"); // 筛选出需要删除的日志文件
|
|
535
546
|
filesToDelete = logFiles.filter(function (file) {
|
|
@@ -539,47 +550,50 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
539
550
|
|
|
540
551
|
// 删除旧日志文件
|
|
541
552
|
_iterator = _createForOfIteratorHelper(filesToDelete);
|
|
542
|
-
|
|
553
|
+
_context7.prev = 10;
|
|
543
554
|
_iterator.s();
|
|
544
555
|
case 12:
|
|
545
556
|
if ((_step = _iterator.n()).done) {
|
|
546
|
-
|
|
557
|
+
_context7.next = 19;
|
|
547
558
|
break;
|
|
548
559
|
}
|
|
549
560
|
file = _step.value;
|
|
550
|
-
|
|
561
|
+
_context7.next = 16;
|
|
551
562
|
return this.db.delete("logs", file.fileName);
|
|
552
563
|
case 16:
|
|
553
564
|
console.log("-------- \u5220\u9664\u65E7\u65E5\u5FD7\u6587\u4EF6: ".concat(file.fileName, ", \u65E5\u671F: ").concat(file.date));
|
|
554
565
|
case 17:
|
|
555
|
-
|
|
566
|
+
_context7.next = 12;
|
|
556
567
|
break;
|
|
557
568
|
case 19:
|
|
558
|
-
|
|
569
|
+
_context7.next = 24;
|
|
559
570
|
break;
|
|
560
571
|
case 21:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
_iterator.e(
|
|
572
|
+
_context7.prev = 21;
|
|
573
|
+
_context7.t0 = _context7["catch"](10);
|
|
574
|
+
_iterator.e(_context7.t0);
|
|
564
575
|
case 24:
|
|
565
|
-
|
|
576
|
+
_context7.prev = 24;
|
|
566
577
|
_iterator.f();
|
|
567
|
-
return
|
|
578
|
+
return _context7.finish(24);
|
|
568
579
|
case 27:
|
|
569
580
|
if (filesToDelete.length > 0) {
|
|
570
581
|
console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
|
|
571
582
|
}
|
|
572
|
-
|
|
583
|
+
|
|
584
|
+
// 清理完成后,将IndexDB中的日志上传到AWS
|
|
585
|
+
this.uploadIndexDBLog();
|
|
586
|
+
_context7.next = 34;
|
|
573
587
|
break;
|
|
574
|
-
case
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
console.error("清理旧日志失败:",
|
|
578
|
-
case
|
|
588
|
+
case 31:
|
|
589
|
+
_context7.prev = 31;
|
|
590
|
+
_context7.t1 = _context7["catch"](2);
|
|
591
|
+
console.error("清理旧日志失败:", _context7.t1);
|
|
592
|
+
case 34:
|
|
579
593
|
case "end":
|
|
580
|
-
return
|
|
594
|
+
return _context7.stop();
|
|
581
595
|
}
|
|
582
|
-
},
|
|
596
|
+
}, _callee7, this, [[2, 31], [10, 21, 24, 27]]);
|
|
583
597
|
}));
|
|
584
598
|
function cleanupOldLogs() {
|
|
585
599
|
return _cleanupOldLogs.apply(this, arguments);
|
|
@@ -594,31 +608,31 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
594
608
|
}, {
|
|
595
609
|
key: "getLogFiles",
|
|
596
610
|
value: (function () {
|
|
597
|
-
var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
598
|
-
return _regeneratorRuntime().wrap(function
|
|
599
|
-
while (1) switch (
|
|
611
|
+
var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
612
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
613
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
600
614
|
case 0:
|
|
601
615
|
if (this.db) {
|
|
602
|
-
|
|
616
|
+
_context8.next = 2;
|
|
603
617
|
break;
|
|
604
618
|
}
|
|
605
|
-
return
|
|
619
|
+
return _context8.abrupt("return", []);
|
|
606
620
|
case 2:
|
|
607
|
-
|
|
608
|
-
|
|
621
|
+
_context8.prev = 2;
|
|
622
|
+
_context8.next = 5;
|
|
609
623
|
return this.db.getAll("logs");
|
|
610
624
|
case 5:
|
|
611
|
-
return
|
|
625
|
+
return _context8.abrupt("return", _context8.sent);
|
|
612
626
|
case 8:
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
console.error("获取日志文件列表失败:",
|
|
616
|
-
return
|
|
627
|
+
_context8.prev = 8;
|
|
628
|
+
_context8.t0 = _context8["catch"](2);
|
|
629
|
+
console.error("获取日志文件列表失败:", _context8.t0);
|
|
630
|
+
return _context8.abrupt("return", []);
|
|
617
631
|
case 12:
|
|
618
632
|
case "end":
|
|
619
|
-
return
|
|
633
|
+
return _context8.stop();
|
|
620
634
|
}
|
|
621
|
-
},
|
|
635
|
+
}, _callee8, this, [[2, 8]]);
|
|
622
636
|
}));
|
|
623
637
|
function getLogFiles() {
|
|
624
638
|
return _getLogFiles.apply(this, arguments);
|
|
@@ -634,31 +648,31 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
634
648
|
}, {
|
|
635
649
|
key: "getLogFile",
|
|
636
650
|
value: (function () {
|
|
637
|
-
var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
638
|
-
return _regeneratorRuntime().wrap(function
|
|
639
|
-
while (1) switch (
|
|
651
|
+
var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fileName) {
|
|
652
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
653
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
640
654
|
case 0:
|
|
641
655
|
if (this.db) {
|
|
642
|
-
|
|
656
|
+
_context9.next = 2;
|
|
643
657
|
break;
|
|
644
658
|
}
|
|
645
|
-
return
|
|
659
|
+
return _context9.abrupt("return", null);
|
|
646
660
|
case 2:
|
|
647
|
-
|
|
648
|
-
|
|
661
|
+
_context9.prev = 2;
|
|
662
|
+
_context9.next = 5;
|
|
649
663
|
return this.db.get("logs", fileName);
|
|
650
664
|
case 5:
|
|
651
|
-
return
|
|
665
|
+
return _context9.abrupt("return", _context9.sent);
|
|
652
666
|
case 8:
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
console.error("获取日志文件内容失败:",
|
|
656
|
-
return
|
|
667
|
+
_context9.prev = 8;
|
|
668
|
+
_context9.t0 = _context9["catch"](2);
|
|
669
|
+
console.error("获取日志文件内容失败:", _context9.t0);
|
|
670
|
+
return _context9.abrupt("return", null);
|
|
657
671
|
case 12:
|
|
658
672
|
case "end":
|
|
659
|
-
return
|
|
673
|
+
return _context9.stop();
|
|
660
674
|
}
|
|
661
|
-
},
|
|
675
|
+
}, _callee9, this, [[2, 8]]);
|
|
662
676
|
}));
|
|
663
677
|
function getLogFile(_x3) {
|
|
664
678
|
return _getLogFile.apply(this, arguments);
|
|
@@ -674,41 +688,41 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
674
688
|
}, {
|
|
675
689
|
key: "clearLogs",
|
|
676
690
|
value: (function () {
|
|
677
|
-
var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
678
|
-
return _regeneratorRuntime().wrap(function
|
|
679
|
-
while (1) switch (
|
|
691
|
+
var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fileName) {
|
|
692
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
693
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
680
694
|
case 0:
|
|
681
695
|
if (this.db) {
|
|
682
|
-
|
|
696
|
+
_context10.next = 2;
|
|
683
697
|
break;
|
|
684
698
|
}
|
|
685
|
-
return
|
|
699
|
+
return _context10.abrupt("return", false);
|
|
686
700
|
case 2:
|
|
687
|
-
|
|
701
|
+
_context10.prev = 2;
|
|
688
702
|
if (!fileName) {
|
|
689
|
-
|
|
703
|
+
_context10.next = 8;
|
|
690
704
|
break;
|
|
691
705
|
}
|
|
692
|
-
|
|
706
|
+
_context10.next = 6;
|
|
693
707
|
return this.db.delete("logs", fileName);
|
|
694
708
|
case 6:
|
|
695
|
-
|
|
709
|
+
_context10.next = 10;
|
|
696
710
|
break;
|
|
697
711
|
case 8:
|
|
698
|
-
|
|
712
|
+
_context10.next = 10;
|
|
699
713
|
return this.db.clear("logs");
|
|
700
714
|
case 10:
|
|
701
|
-
return
|
|
715
|
+
return _context10.abrupt("return", true);
|
|
702
716
|
case 13:
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
console.error("清空日志失败:",
|
|
706
|
-
return
|
|
717
|
+
_context10.prev = 13;
|
|
718
|
+
_context10.t0 = _context10["catch"](2);
|
|
719
|
+
console.error("清空日志失败:", _context10.t0);
|
|
720
|
+
return _context10.abrupt("return", false);
|
|
707
721
|
case 17:
|
|
708
722
|
case "end":
|
|
709
|
-
return
|
|
723
|
+
return _context10.stop();
|
|
710
724
|
}
|
|
711
|
-
},
|
|
725
|
+
}, _callee10, this, [[2, 13]]);
|
|
712
726
|
}));
|
|
713
727
|
function clearLogs(_x4) {
|
|
714
728
|
return _clearLogs.apply(this, arguments);
|
|
@@ -737,17 +751,17 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
737
751
|
}, {
|
|
738
752
|
key: "manualCleanup",
|
|
739
753
|
value: (function () {
|
|
740
|
-
var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
741
|
-
return _regeneratorRuntime().wrap(function
|
|
742
|
-
while (1) switch (
|
|
754
|
+
var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
755
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
756
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
743
757
|
case 0:
|
|
744
|
-
|
|
758
|
+
_context11.next = 2;
|
|
745
759
|
return this.cleanupOldLogs();
|
|
746
760
|
case 2:
|
|
747
761
|
case "end":
|
|
748
|
-
return
|
|
762
|
+
return _context11.stop();
|
|
749
763
|
}
|
|
750
|
-
},
|
|
764
|
+
}, _callee11, this);
|
|
751
765
|
}));
|
|
752
766
|
function manualCleanup() {
|
|
753
767
|
return _manualCleanup.apply(this, arguments);
|
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 | React.ReactFragment | JSX.Element | null | undefined;
|
|
24
24
|
getPageByRoute(route: string): ApplicationInterface | undefined;
|
|
25
25
|
getRouterComponent({ fallback }: {
|
|
26
26
|
fallback?: React.ReactNode;
|
package/es/tasks/index.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export declare class TasksManager {
|
|
|
108
108
|
*/
|
|
109
109
|
getQueueStatus(module: string, queueId: string): {
|
|
110
110
|
isRunning: boolean;
|
|
111
|
-
status: "
|
|
111
|
+
status: "uncompleted" | "completed";
|
|
112
112
|
progress: {
|
|
113
113
|
total: number;
|
|
114
114
|
completed: number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare type ThrottleLevel = number;
|
|
2
|
+
export interface ThrottleExecuteContext {
|
|
3
|
+
/** 事务唯一 key */
|
|
4
|
+
key: string;
|
|
5
|
+
/** 当前节流窗口内的触发次数 */
|
|
6
|
+
count: number;
|
|
7
|
+
/** 是否首次立即执行 */
|
|
8
|
+
isFirst: boolean;
|
|
9
|
+
/** 当前节流等级 */
|
|
10
|
+
level: ThrottleLevel;
|
|
11
|
+
/** 上一次执行时间 */
|
|
12
|
+
lastExecuteTime: number;
|
|
13
|
+
}
|
|
14
|
+
export declare type ThrottleHandler = (ctx: ThrottleExecuteContext) => void | Promise<void>;
|
|
15
|
+
export declare const DEFAULT_THROTTLE_INTERVALS: number[];
|
|
16
|
+
export declare class AdaptiveThrottle {
|
|
17
|
+
private store;
|
|
18
|
+
private intervals;
|
|
19
|
+
constructor(intervals?: number[]);
|
|
20
|
+
/**
|
|
21
|
+
* 触发事务
|
|
22
|
+
*/
|
|
23
|
+
trigger(key: string, handler: ThrottleHandler): void;
|
|
24
|
+
/**
|
|
25
|
+
* 调度下一次节流执行
|
|
26
|
+
*/
|
|
27
|
+
private schedule;
|
|
28
|
+
/**
|
|
29
|
+
* 主动清理某个事务
|
|
30
|
+
*/
|
|
31
|
+
clear(key: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* 清空所有事务
|
|
34
|
+
*/
|
|
35
|
+
clearAll(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
export var DEFAULT_THROTTLE_INTERVALS = [5 * 60 * 1000,
|
|
12
|
+
// 5分钟
|
|
13
|
+
30 * 60 * 1000,
|
|
14
|
+
// 30分钟
|
|
15
|
+
60 * 60 * 1000,
|
|
16
|
+
// 1小时
|
|
17
|
+
6 * 60 * 60 * 1000,
|
|
18
|
+
// 6小时
|
|
19
|
+
24 * 60 * 60 * 1000 // 1天
|
|
20
|
+
];
|
|
21
|
+
export var AdaptiveThrottle = /*#__PURE__*/function () {
|
|
22
|
+
function AdaptiveThrottle() {
|
|
23
|
+
var intervals = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_THROTTLE_INTERVALS;
|
|
24
|
+
_classCallCheck(this, AdaptiveThrottle);
|
|
25
|
+
_defineProperty(this, "store", new Map());
|
|
26
|
+
_defineProperty(this, "intervals", void 0);
|
|
27
|
+
this.intervals = intervals;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 触发事务
|
|
32
|
+
*/
|
|
33
|
+
_createClass(AdaptiveThrottle, [{
|
|
34
|
+
key: "trigger",
|
|
35
|
+
value: function trigger(key, handler) {
|
|
36
|
+
var now = Date.now();
|
|
37
|
+
var record = this.store.get(key);
|
|
38
|
+
|
|
39
|
+
// ① 首次调用:立即执行
|
|
40
|
+
if (!record) {
|
|
41
|
+
handler({
|
|
42
|
+
key: key,
|
|
43
|
+
count: 1,
|
|
44
|
+
isFirst: true,
|
|
45
|
+
level: 0,
|
|
46
|
+
lastExecuteTime: now
|
|
47
|
+
});
|
|
48
|
+
record = {
|
|
49
|
+
key: key,
|
|
50
|
+
count: 0,
|
|
51
|
+
level: 0,
|
|
52
|
+
lastExecuteTime: now
|
|
53
|
+
};
|
|
54
|
+
this.store.set(key, record);
|
|
55
|
+
this.schedule(key, handler, record);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ② 同 key 事务:累计次数
|
|
60
|
+
record.count++;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 调度下一次节流执行
|
|
65
|
+
*/
|
|
66
|
+
}, {
|
|
67
|
+
key: "schedule",
|
|
68
|
+
value: function schedule(key, handler, record) {
|
|
69
|
+
var _this = this;
|
|
70
|
+
var interval = this.intervals[record.level];
|
|
71
|
+
record.timer = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
72
|
+
var count;
|
|
73
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
74
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
count = record.count;
|
|
77
|
+
if (!(count > 0)) {
|
|
78
|
+
_context.next = 4;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
_context.next = 4;
|
|
82
|
+
return handler({
|
|
83
|
+
key: key,
|
|
84
|
+
count: count,
|
|
85
|
+
isFirst: false,
|
|
86
|
+
level: record.level,
|
|
87
|
+
lastExecuteTime: record.lastExecuteTime
|
|
88
|
+
});
|
|
89
|
+
case 4:
|
|
90
|
+
// 自适应升级节流等级
|
|
91
|
+
if (count > 0 && record.level < _this.intervals.length - 1) {
|
|
92
|
+
record.level++;
|
|
93
|
+
}
|
|
94
|
+
record.count = 0;
|
|
95
|
+
record.lastExecuteTime = Date.now();
|
|
96
|
+
|
|
97
|
+
// 继续下一轮
|
|
98
|
+
_this.schedule(key, handler, record);
|
|
99
|
+
case 8:
|
|
100
|
+
case "end":
|
|
101
|
+
return _context.stop();
|
|
102
|
+
}
|
|
103
|
+
}, _callee);
|
|
104
|
+
})), interval);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 主动清理某个事务
|
|
109
|
+
*/
|
|
110
|
+
}, {
|
|
111
|
+
key: "clear",
|
|
112
|
+
value: function clear(key) {
|
|
113
|
+
var record = this.store.get(key);
|
|
114
|
+
if (!record) return;
|
|
115
|
+
if (record.timer) {
|
|
116
|
+
clearTimeout(record.timer);
|
|
117
|
+
}
|
|
118
|
+
this.store.delete(key);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 清空所有事务
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "clearAll",
|
|
126
|
+
value: function clearAll() {
|
|
127
|
+
this.store.forEach(function (record) {
|
|
128
|
+
if (record.timer) {
|
|
129
|
+
clearTimeout(record.timer);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
this.store.clear();
|
|
133
|
+
}
|
|
134
|
+
}]);
|
|
135
|
+
return AdaptiveThrottle;
|
|
136
|
+
}();
|
package/lib/logger/index.d.ts
CHANGED
package/lib/logger/index.js
CHANGED
|
@@ -67,7 +67,7 @@ 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
73
|
this.cleanupOldLogs();
|
|
@@ -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
|
}
|
|
@@ -324,6 +323,7 @@ var LoggerManager = class {
|
|
|
324
323
|
if (filesToDelete.length > 0) {
|
|
325
324
|
console.log(`-------- 共清理 ${filesToDelete.length} 个旧日志文件`);
|
|
326
325
|
}
|
|
326
|
+
this.uploadIndexDBLog();
|
|
327
327
|
} catch (error) {
|
|
328
328
|
console.error("清理旧日志失败:", error);
|
|
329
329
|
}
|
package/lib/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 | React.ReactFragment | JSX.Element | null | undefined;
|
|
24
24
|
getPageByRoute(route: string): ApplicationInterface | undefined;
|
|
25
25
|
getRouterComponent({ fallback }: {
|
|
26
26
|
fallback?: React.ReactNode;
|
package/lib/tasks/index.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export declare class TasksManager {
|
|
|
108
108
|
*/
|
|
109
109
|
getQueueStatus(module: string, queueId: string): {
|
|
110
110
|
isRunning: boolean;
|
|
111
|
-
status: "
|
|
111
|
+
status: "uncompleted" | "completed";
|
|
112
112
|
progress: {
|
|
113
113
|
total: number;
|
|
114
114
|
completed: number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare type ThrottleLevel = number;
|
|
2
|
+
export interface ThrottleExecuteContext {
|
|
3
|
+
/** 事务唯一 key */
|
|
4
|
+
key: string;
|
|
5
|
+
/** 当前节流窗口内的触发次数 */
|
|
6
|
+
count: number;
|
|
7
|
+
/** 是否首次立即执行 */
|
|
8
|
+
isFirst: boolean;
|
|
9
|
+
/** 当前节流等级 */
|
|
10
|
+
level: ThrottleLevel;
|
|
11
|
+
/** 上一次执行时间 */
|
|
12
|
+
lastExecuteTime: number;
|
|
13
|
+
}
|
|
14
|
+
export declare type ThrottleHandler = (ctx: ThrottleExecuteContext) => void | Promise<void>;
|
|
15
|
+
export declare const DEFAULT_THROTTLE_INTERVALS: number[];
|
|
16
|
+
export declare class AdaptiveThrottle {
|
|
17
|
+
private store;
|
|
18
|
+
private intervals;
|
|
19
|
+
constructor(intervals?: number[]);
|
|
20
|
+
/**
|
|
21
|
+
* 触发事务
|
|
22
|
+
*/
|
|
23
|
+
trigger(key: string, handler: ThrottleHandler): void;
|
|
24
|
+
/**
|
|
25
|
+
* 调度下一次节流执行
|
|
26
|
+
*/
|
|
27
|
+
private schedule;
|
|
28
|
+
/**
|
|
29
|
+
* 主动清理某个事务
|
|
30
|
+
*/
|
|
31
|
+
clear(key: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* 清空所有事务
|
|
34
|
+
*/
|
|
35
|
+
clearAll(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/adaptiveThrottle/index.ts
|
|
20
|
+
var adaptiveThrottle_exports = {};
|
|
21
|
+
__export(adaptiveThrottle_exports, {
|
|
22
|
+
AdaptiveThrottle: () => AdaptiveThrottle,
|
|
23
|
+
DEFAULT_THROTTLE_INTERVALS: () => DEFAULT_THROTTLE_INTERVALS
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(adaptiveThrottle_exports);
|
|
26
|
+
var DEFAULT_THROTTLE_INTERVALS = [
|
|
27
|
+
5 * 60 * 1e3,
|
|
28
|
+
// 5分钟
|
|
29
|
+
30 * 60 * 1e3,
|
|
30
|
+
// 30分钟
|
|
31
|
+
60 * 60 * 1e3,
|
|
32
|
+
// 1小时
|
|
33
|
+
6 * 60 * 60 * 1e3,
|
|
34
|
+
// 6小时
|
|
35
|
+
24 * 60 * 60 * 1e3
|
|
36
|
+
// 1天
|
|
37
|
+
];
|
|
38
|
+
var AdaptiveThrottle = class {
|
|
39
|
+
store = /* @__PURE__ */ new Map();
|
|
40
|
+
intervals;
|
|
41
|
+
constructor(intervals = DEFAULT_THROTTLE_INTERVALS) {
|
|
42
|
+
this.intervals = intervals;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 触发事务
|
|
46
|
+
*/
|
|
47
|
+
trigger(key, handler) {
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
let record = this.store.get(key);
|
|
50
|
+
if (!record) {
|
|
51
|
+
handler({
|
|
52
|
+
key,
|
|
53
|
+
count: 1,
|
|
54
|
+
isFirst: true,
|
|
55
|
+
level: 0,
|
|
56
|
+
lastExecuteTime: now
|
|
57
|
+
});
|
|
58
|
+
record = {
|
|
59
|
+
key,
|
|
60
|
+
count: 0,
|
|
61
|
+
level: 0,
|
|
62
|
+
lastExecuteTime: now
|
|
63
|
+
};
|
|
64
|
+
this.store.set(key, record);
|
|
65
|
+
this.schedule(key, handler, record);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
record.count++;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 调度下一次节流执行
|
|
72
|
+
*/
|
|
73
|
+
schedule(key, handler, record) {
|
|
74
|
+
const interval = this.intervals[record.level];
|
|
75
|
+
record.timer = setTimeout(async () => {
|
|
76
|
+
const count = record.count;
|
|
77
|
+
if (count > 0) {
|
|
78
|
+
await handler({
|
|
79
|
+
key,
|
|
80
|
+
count,
|
|
81
|
+
isFirst: false,
|
|
82
|
+
level: record.level,
|
|
83
|
+
lastExecuteTime: record.lastExecuteTime
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (count > 0 && record.level < this.intervals.length - 1) {
|
|
87
|
+
record.level++;
|
|
88
|
+
}
|
|
89
|
+
record.count = 0;
|
|
90
|
+
record.lastExecuteTime = Date.now();
|
|
91
|
+
this.schedule(key, handler, record);
|
|
92
|
+
}, interval);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 主动清理某个事务
|
|
96
|
+
*/
|
|
97
|
+
clear(key) {
|
|
98
|
+
const record = this.store.get(key);
|
|
99
|
+
if (!record) return;
|
|
100
|
+
if (record.timer) {
|
|
101
|
+
clearTimeout(record.timer);
|
|
102
|
+
}
|
|
103
|
+
this.store.delete(key);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 清空所有事务
|
|
107
|
+
*/
|
|
108
|
+
clearAll() {
|
|
109
|
+
this.store.forEach((record) => {
|
|
110
|
+
if (record.timer) {
|
|
111
|
+
clearTimeout(record.timer);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
this.store.clear();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
AdaptiveThrottle,
|
|
120
|
+
DEFAULT_THROTTLE_INTERVALS
|
|
121
|
+
});
|