@pisell/core 1.0.42 → 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.
- package/es/logger/index.d.ts +1 -1
- package/es/logger/index.js +193 -171
- 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 +6 -3
- 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,55 @@ 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
|
+
_context.next = 4;
|
|
77
|
+
return this.cleanupOldLogs();
|
|
78
|
+
case 4:
|
|
79
|
+
_context.prev = 4;
|
|
80
|
+
_context.next = 7;
|
|
81
|
+
return this.uploadIndexDBLog();
|
|
82
|
+
case 7:
|
|
83
|
+
_context.next = 11;
|
|
84
|
+
break;
|
|
85
|
+
case 9:
|
|
86
|
+
_context.prev = 9;
|
|
87
|
+
_context.t0 = _context["catch"](4);
|
|
88
|
+
case 11:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context.stop();
|
|
91
|
+
}
|
|
92
|
+
}, _callee, this, [[4, 9]]);
|
|
93
|
+
}));
|
|
94
|
+
function init() {
|
|
95
|
+
return _init.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
return init;
|
|
98
|
+
}()
|
|
75
99
|
/**
|
|
76
100
|
* 初始化 IndexDB
|
|
77
101
|
*/
|
|
78
102
|
}, {
|
|
79
103
|
key: "initDB",
|
|
80
104
|
value: (function () {
|
|
81
|
-
var _initDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
82
|
-
return _regeneratorRuntime().wrap(function
|
|
83
|
-
while (1) switch (
|
|
105
|
+
var _initDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
106
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
107
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
84
108
|
case 0:
|
|
85
109
|
if (this.app.dbManager) {
|
|
86
110
|
this.db = this.app.dbManager;
|
|
87
111
|
}
|
|
88
112
|
case 1:
|
|
89
113
|
case "end":
|
|
90
|
-
return
|
|
114
|
+
return _context2.stop();
|
|
91
115
|
}
|
|
92
|
-
},
|
|
116
|
+
}, _callee2, this);
|
|
93
117
|
}));
|
|
94
118
|
function initDB() {
|
|
95
119
|
return _initDB.apply(this, arguments);
|
|
@@ -229,11 +253,11 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
229
253
|
}, {
|
|
230
254
|
key: "createAWSFileName",
|
|
231
255
|
value: (function () {
|
|
232
|
-
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
256
|
+
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(urgent) {
|
|
233
257
|
var _this$app;
|
|
234
258
|
var _date, _hour, _this$app2, fileName;
|
|
235
|
-
return _regeneratorRuntime().wrap(function
|
|
236
|
-
while (1) switch (
|
|
259
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
260
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
237
261
|
case 0:
|
|
238
262
|
_date = dayjs().format("YYYY-MM-DD");
|
|
239
263
|
_hour = dayjs().format("HH:mm"); // 紧急上传时,在小时后面加上当前时间戳 避免文件名重复覆盖
|
|
@@ -241,22 +265,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
241
265
|
_hour = "".concat(dayjs().format("HH:mm"), " [ urgent ] ").concat(dayjs().valueOf());
|
|
242
266
|
}
|
|
243
267
|
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
|
-
|
|
268
|
+
_context3.next = 5;
|
|
245
269
|
break;
|
|
246
270
|
}
|
|
247
|
-
return
|
|
271
|
+
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
272
|
date: _date,
|
|
249
273
|
hour: _hour,
|
|
250
274
|
isManual: false
|
|
251
275
|
}));
|
|
252
276
|
case 5:
|
|
253
277
|
fileName = "logs/".concat("pisell", "/", _date, "/").concat(_hour);
|
|
254
|
-
return
|
|
278
|
+
return _context3.abrupt("return", "".concat(fileName, ".json"));
|
|
255
279
|
case 7:
|
|
256
280
|
case "end":
|
|
257
|
-
return
|
|
281
|
+
return _context3.stop();
|
|
258
282
|
}
|
|
259
|
-
},
|
|
283
|
+
}, _callee3, this);
|
|
260
284
|
}));
|
|
261
285
|
function createAWSFileName(_x) {
|
|
262
286
|
return _createAWSFileName.apply(this, arguments);
|
|
@@ -290,24 +314,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
290
314
|
}, {
|
|
291
315
|
key: "storeLog",
|
|
292
316
|
value: (function () {
|
|
293
|
-
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
317
|
+
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(urgent) {
|
|
294
318
|
var _this$logBuffer, fileName, buffer, bufferIds, logs;
|
|
295
|
-
return _regeneratorRuntime().wrap(function
|
|
296
|
-
while (1) switch (
|
|
319
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
320
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
297
321
|
case 0:
|
|
298
|
-
// 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
|
|
299
|
-
this.uploadIndexDBLog();
|
|
300
322
|
if (!(this.logBuffer.length === 0 || !this.db)) {
|
|
301
|
-
|
|
323
|
+
_context4.next = 2;
|
|
302
324
|
break;
|
|
303
325
|
}
|
|
304
|
-
return
|
|
305
|
-
case
|
|
306
|
-
|
|
307
|
-
|
|
326
|
+
return _context4.abrupt("return");
|
|
327
|
+
case 2:
|
|
328
|
+
_context4.prev = 2;
|
|
329
|
+
_context4.next = 5;
|
|
308
330
|
return this.createAWSFileName(urgent);
|
|
309
|
-
case
|
|
310
|
-
fileName =
|
|
331
|
+
case 5:
|
|
332
|
+
fileName = _context4.sent;
|
|
311
333
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
312
334
|
|
|
313
335
|
// 将buffer中的metadata转换为对象
|
|
@@ -319,57 +341,57 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
319
341
|
return item.logId;
|
|
320
342
|
});
|
|
321
343
|
logs = JSON.stringify(buffer, null, 2);
|
|
322
|
-
|
|
344
|
+
_context4.next = 12;
|
|
323
345
|
return this.app.aws.upload({
|
|
324
346
|
Bucket: "",
|
|
325
347
|
Key: fileName,
|
|
326
348
|
Body: logs
|
|
327
349
|
});
|
|
328
|
-
case
|
|
350
|
+
case 12:
|
|
329
351
|
console.log("-------- 存储日志到AWS 成功");
|
|
330
352
|
// 上传成功后需要清空缓冲区,避免重复上传
|
|
331
353
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
332
354
|
return !bufferIds.includes(item.logId);
|
|
333
355
|
});
|
|
334
|
-
|
|
356
|
+
_context4.next = 28;
|
|
335
357
|
break;
|
|
336
|
-
case
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
console.error("存储日志上传AWS失败:",
|
|
358
|
+
case 16:
|
|
359
|
+
_context4.prev = 16;
|
|
360
|
+
_context4.t0 = _context4["catch"](2);
|
|
361
|
+
console.error("存储日志上传AWS失败:", _context4.t0);
|
|
340
362
|
|
|
341
363
|
// 将日志存储到IndexDB
|
|
342
|
-
|
|
343
|
-
|
|
364
|
+
_context4.prev = 19;
|
|
365
|
+
_context4.next = 22;
|
|
344
366
|
return this.storeLogToIndexDB();
|
|
345
|
-
case
|
|
346
|
-
|
|
367
|
+
case 22:
|
|
368
|
+
_context4.next = 28;
|
|
347
369
|
break;
|
|
348
|
-
case
|
|
349
|
-
|
|
350
|
-
|
|
370
|
+
case 24:
|
|
371
|
+
_context4.prev = 24;
|
|
372
|
+
_context4.t1 = _context4["catch"](19);
|
|
351
373
|
this.sendFeishuNotification({
|
|
352
374
|
type: "error",
|
|
353
375
|
title: "存储日志到AWS失败",
|
|
354
376
|
metadata: {
|
|
355
377
|
error: {
|
|
356
|
-
name:
|
|
357
|
-
message:
|
|
358
|
-
stack:
|
|
378
|
+
name: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.name,
|
|
379
|
+
message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
|
|
380
|
+
stack: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.stack
|
|
359
381
|
},
|
|
360
382
|
indexDBError: {
|
|
361
|
-
name:
|
|
362
|
-
message:
|
|
363
|
-
stack:
|
|
383
|
+
name: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.name,
|
|
384
|
+
message: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.message,
|
|
385
|
+
stack: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.stack
|
|
364
386
|
}
|
|
365
387
|
}
|
|
366
388
|
});
|
|
367
|
-
console.error("存储日志到IndexDB也失败:",
|
|
368
|
-
case
|
|
389
|
+
console.error("存储日志到IndexDB也失败:", _context4.t1);
|
|
390
|
+
case 28:
|
|
369
391
|
case "end":
|
|
370
|
-
return
|
|
392
|
+
return _context4.stop();
|
|
371
393
|
}
|
|
372
|
-
},
|
|
394
|
+
}, _callee4, this, [[2, 16], [19, 24]]);
|
|
373
395
|
}));
|
|
374
396
|
function storeLog(_x2) {
|
|
375
397
|
return _storeLog.apply(this, arguments);
|
|
@@ -379,34 +401,34 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
379
401
|
}, {
|
|
380
402
|
key: "uploadIndexDBLog",
|
|
381
403
|
value: function () {
|
|
382
|
-
var _uploadIndexDBLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
404
|
+
var _uploadIndexDBLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
383
405
|
var _this$db, _this$db2, logFile, awsFileName, logs;
|
|
384
|
-
return _regeneratorRuntime().wrap(function
|
|
385
|
-
while (1) switch (
|
|
406
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
407
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
386
408
|
case 0:
|
|
387
|
-
|
|
409
|
+
_context5.prev = 0;
|
|
388
410
|
if (this.db) {
|
|
389
|
-
|
|
411
|
+
_context5.next = 3;
|
|
390
412
|
break;
|
|
391
413
|
}
|
|
392
|
-
return
|
|
414
|
+
return _context5.abrupt("return");
|
|
393
415
|
case 3:
|
|
394
|
-
|
|
416
|
+
_context5.next = 5;
|
|
395
417
|
return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
|
|
396
418
|
case 5:
|
|
397
|
-
logFile =
|
|
419
|
+
logFile = _context5.sent;
|
|
398
420
|
if (!(!logFile || (logFile === null || logFile === void 0 ? void 0 : logFile.length) === 0)) {
|
|
399
|
-
|
|
421
|
+
_context5.next = 8;
|
|
400
422
|
break;
|
|
401
423
|
}
|
|
402
|
-
return
|
|
424
|
+
return _context5.abrupt("return");
|
|
403
425
|
case 8:
|
|
404
|
-
|
|
426
|
+
_context5.next = 10;
|
|
405
427
|
return this.createAWSFileName(true);
|
|
406
428
|
case 10:
|
|
407
|
-
awsFileName =
|
|
429
|
+
awsFileName = _context5.sent;
|
|
408
430
|
logs = JSON.stringify(logFile, null, 2);
|
|
409
|
-
|
|
431
|
+
_context5.next = 14;
|
|
410
432
|
return this.app.aws.upload({
|
|
411
433
|
Bucket: "",
|
|
412
434
|
Key: awsFileName,
|
|
@@ -414,34 +436,34 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
414
436
|
});
|
|
415
437
|
case 14:
|
|
416
438
|
console.log("-------- 存储日志到AWS 成功");
|
|
417
|
-
|
|
439
|
+
_context5.next = 17;
|
|
418
440
|
return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
|
|
419
441
|
case 17:
|
|
420
442
|
console.log("-------- 清空IndexDB日志成功");
|
|
421
|
-
|
|
443
|
+
_context5.next = 25;
|
|
422
444
|
break;
|
|
423
445
|
case 20:
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
console.log("-------- 存储日志到IndexDB 失败",
|
|
446
|
+
_context5.prev = 20;
|
|
447
|
+
_context5.t0 = _context5["catch"](0);
|
|
448
|
+
console.log("-------- 存储日志到IndexDB 失败", _context5.t0);
|
|
427
449
|
this.sendFeishuNotification({
|
|
428
450
|
type: "error",
|
|
429
451
|
title: "存储IndexDB日志到AWS失败",
|
|
430
452
|
metadata: {
|
|
431
453
|
error: {
|
|
432
|
-
name:
|
|
433
|
-
message:
|
|
434
|
-
stack:
|
|
454
|
+
name: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.name,
|
|
455
|
+
message: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message,
|
|
456
|
+
stack: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.stack
|
|
435
457
|
}
|
|
436
458
|
}
|
|
437
459
|
});
|
|
438
460
|
// 重新抛出错误,让外层 catch 能够捕获
|
|
439
|
-
throw
|
|
461
|
+
throw _context5.t0;
|
|
440
462
|
case 25:
|
|
441
463
|
case "end":
|
|
442
|
-
return
|
|
464
|
+
return _context5.stop();
|
|
443
465
|
}
|
|
444
|
-
},
|
|
466
|
+
}, _callee5, this, [[0, 20]]);
|
|
445
467
|
}));
|
|
446
468
|
function uploadIndexDBLog() {
|
|
447
469
|
return _uploadIndexDBLog.apply(this, arguments);
|
|
@@ -451,32 +473,32 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
451
473
|
}, {
|
|
452
474
|
key: "storeLogToIndexDB",
|
|
453
475
|
value: function () {
|
|
454
|
-
var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
476
|
+
var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
455
477
|
var _this$db3, _this$db5, fileName, buffer, logFile, _this$db4, bufferIds;
|
|
456
|
-
return _regeneratorRuntime().wrap(function
|
|
457
|
-
while (1) switch (
|
|
478
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
479
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
458
480
|
case 0:
|
|
459
|
-
|
|
481
|
+
_context6.prev = 0;
|
|
460
482
|
fileName = this.createFileName();
|
|
461
483
|
console.log("storeLog", fileName);
|
|
462
484
|
buffer = this.logBuffer || []; // 获取现有日志文件
|
|
463
|
-
|
|
485
|
+
_context6.next = 6;
|
|
464
486
|
return (_this$db3 = this.db) === null || _this$db3 === void 0 ? void 0 : _this$db3.get("logs", fileName);
|
|
465
487
|
case 6:
|
|
466
|
-
logFile =
|
|
488
|
+
logFile = _context6.sent;
|
|
467
489
|
if (logFile) {
|
|
468
|
-
|
|
490
|
+
_context6.next = 11;
|
|
469
491
|
break;
|
|
470
492
|
}
|
|
471
493
|
logFile = this.createFile(fileName);
|
|
472
|
-
|
|
494
|
+
_context6.next = 11;
|
|
473
495
|
return (_this$db4 = this.db) === null || _this$db4 === void 0 ? void 0 : _this$db4.add("logs", logFile);
|
|
474
496
|
case 11:
|
|
475
497
|
// 添加日志到文件内容
|
|
476
498
|
logFile.fileContent.logs = [].concat(_toConsumableArray(logFile.fileContent.logs), _toConsumableArray(buffer));
|
|
477
499
|
|
|
478
500
|
// 更新日志文件
|
|
479
|
-
|
|
501
|
+
_context6.next = 14;
|
|
480
502
|
return (_this$db5 = this.db) === null || _this$db5 === void 0 ? void 0 : _this$db5.update("logs", logFile);
|
|
481
503
|
case 14:
|
|
482
504
|
console.log("-------- 存储日志到IndexDB", {
|
|
@@ -489,19 +511,19 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
489
511
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
490
512
|
return !bufferIds.includes(item.logId);
|
|
491
513
|
});
|
|
492
|
-
|
|
514
|
+
_context6.next = 23;
|
|
493
515
|
break;
|
|
494
516
|
case 19:
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
console.log("-------- 存储日志到IndexDB 失败",
|
|
517
|
+
_context6.prev = 19;
|
|
518
|
+
_context6.t0 = _context6["catch"](0);
|
|
519
|
+
console.log("-------- 存储日志到IndexDB 失败", _context6.t0);
|
|
498
520
|
// 重新抛出错误,让外层 catch 能够捕获
|
|
499
|
-
throw
|
|
521
|
+
throw _context6.t0;
|
|
500
522
|
case 23:
|
|
501
523
|
case "end":
|
|
502
|
-
return
|
|
524
|
+
return _context6.stop();
|
|
503
525
|
}
|
|
504
|
-
},
|
|
526
|
+
}, _callee6, this, [[0, 19]]);
|
|
505
527
|
}));
|
|
506
528
|
function storeLogToIndexDB() {
|
|
507
529
|
return _storeLogToIndexDB.apply(this, arguments);
|
|
@@ -514,22 +536,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
514
536
|
}, {
|
|
515
537
|
key: "cleanupOldLogs",
|
|
516
538
|
value: (function () {
|
|
517
|
-
var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
539
|
+
var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
518
540
|
var logFiles, cutoffDate, filesToDelete, _iterator, _step, file;
|
|
519
|
-
return _regeneratorRuntime().wrap(function
|
|
520
|
-
while (1) switch (
|
|
541
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
542
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
521
543
|
case 0:
|
|
522
544
|
if (this.db) {
|
|
523
|
-
|
|
545
|
+
_context7.next = 2;
|
|
524
546
|
break;
|
|
525
547
|
}
|
|
526
|
-
return
|
|
548
|
+
return _context7.abrupt("return");
|
|
527
549
|
case 2:
|
|
528
|
-
|
|
529
|
-
|
|
550
|
+
_context7.prev = 2;
|
|
551
|
+
_context7.next = 5;
|
|
530
552
|
return this.getLogFiles();
|
|
531
553
|
case 5:
|
|
532
|
-
logFiles =
|
|
554
|
+
logFiles = _context7.sent;
|
|
533
555
|
// 计算保留日志的截止日期
|
|
534
556
|
cutoffDate = dayjs().subtract(this.retentionDays, "day").format("YYYY-MM-DD"); // 筛选出需要删除的日志文件
|
|
535
557
|
filesToDelete = logFiles.filter(function (file) {
|
|
@@ -539,47 +561,47 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
539
561
|
|
|
540
562
|
// 删除旧日志文件
|
|
541
563
|
_iterator = _createForOfIteratorHelper(filesToDelete);
|
|
542
|
-
|
|
564
|
+
_context7.prev = 10;
|
|
543
565
|
_iterator.s();
|
|
544
566
|
case 12:
|
|
545
567
|
if ((_step = _iterator.n()).done) {
|
|
546
|
-
|
|
568
|
+
_context7.next = 19;
|
|
547
569
|
break;
|
|
548
570
|
}
|
|
549
571
|
file = _step.value;
|
|
550
|
-
|
|
572
|
+
_context7.next = 16;
|
|
551
573
|
return this.db.delete("logs", file.fileName);
|
|
552
574
|
case 16:
|
|
553
575
|
console.log("-------- \u5220\u9664\u65E7\u65E5\u5FD7\u6587\u4EF6: ".concat(file.fileName, ", \u65E5\u671F: ").concat(file.date));
|
|
554
576
|
case 17:
|
|
555
|
-
|
|
577
|
+
_context7.next = 12;
|
|
556
578
|
break;
|
|
557
579
|
case 19:
|
|
558
|
-
|
|
580
|
+
_context7.next = 24;
|
|
559
581
|
break;
|
|
560
582
|
case 21:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
_iterator.e(
|
|
583
|
+
_context7.prev = 21;
|
|
584
|
+
_context7.t0 = _context7["catch"](10);
|
|
585
|
+
_iterator.e(_context7.t0);
|
|
564
586
|
case 24:
|
|
565
|
-
|
|
587
|
+
_context7.prev = 24;
|
|
566
588
|
_iterator.f();
|
|
567
|
-
return
|
|
589
|
+
return _context7.finish(24);
|
|
568
590
|
case 27:
|
|
569
591
|
if (filesToDelete.length > 0) {
|
|
570
592
|
console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
|
|
571
593
|
}
|
|
572
|
-
|
|
594
|
+
_context7.next = 33;
|
|
573
595
|
break;
|
|
574
596
|
case 30:
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
console.error("清理旧日志失败:",
|
|
597
|
+
_context7.prev = 30;
|
|
598
|
+
_context7.t1 = _context7["catch"](2);
|
|
599
|
+
console.error("清理旧日志失败:", _context7.t1);
|
|
578
600
|
case 33:
|
|
579
601
|
case "end":
|
|
580
|
-
return
|
|
602
|
+
return _context7.stop();
|
|
581
603
|
}
|
|
582
|
-
},
|
|
604
|
+
}, _callee7, this, [[2, 30], [10, 21, 24, 27]]);
|
|
583
605
|
}));
|
|
584
606
|
function cleanupOldLogs() {
|
|
585
607
|
return _cleanupOldLogs.apply(this, arguments);
|
|
@@ -594,31 +616,31 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
594
616
|
}, {
|
|
595
617
|
key: "getLogFiles",
|
|
596
618
|
value: (function () {
|
|
597
|
-
var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
598
|
-
return _regeneratorRuntime().wrap(function
|
|
599
|
-
while (1) switch (
|
|
619
|
+
var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
620
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
621
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
600
622
|
case 0:
|
|
601
623
|
if (this.db) {
|
|
602
|
-
|
|
624
|
+
_context8.next = 2;
|
|
603
625
|
break;
|
|
604
626
|
}
|
|
605
|
-
return
|
|
627
|
+
return _context8.abrupt("return", []);
|
|
606
628
|
case 2:
|
|
607
|
-
|
|
608
|
-
|
|
629
|
+
_context8.prev = 2;
|
|
630
|
+
_context8.next = 5;
|
|
609
631
|
return this.db.getAll("logs");
|
|
610
632
|
case 5:
|
|
611
|
-
return
|
|
633
|
+
return _context8.abrupt("return", _context8.sent);
|
|
612
634
|
case 8:
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
console.error("获取日志文件列表失败:",
|
|
616
|
-
return
|
|
635
|
+
_context8.prev = 8;
|
|
636
|
+
_context8.t0 = _context8["catch"](2);
|
|
637
|
+
console.error("获取日志文件列表失败:", _context8.t0);
|
|
638
|
+
return _context8.abrupt("return", []);
|
|
617
639
|
case 12:
|
|
618
640
|
case "end":
|
|
619
|
-
return
|
|
641
|
+
return _context8.stop();
|
|
620
642
|
}
|
|
621
|
-
},
|
|
643
|
+
}, _callee8, this, [[2, 8]]);
|
|
622
644
|
}));
|
|
623
645
|
function getLogFiles() {
|
|
624
646
|
return _getLogFiles.apply(this, arguments);
|
|
@@ -634,31 +656,31 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
634
656
|
}, {
|
|
635
657
|
key: "getLogFile",
|
|
636
658
|
value: (function () {
|
|
637
|
-
var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
638
|
-
return _regeneratorRuntime().wrap(function
|
|
639
|
-
while (1) switch (
|
|
659
|
+
var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fileName) {
|
|
660
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
661
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
640
662
|
case 0:
|
|
641
663
|
if (this.db) {
|
|
642
|
-
|
|
664
|
+
_context9.next = 2;
|
|
643
665
|
break;
|
|
644
666
|
}
|
|
645
|
-
return
|
|
667
|
+
return _context9.abrupt("return", null);
|
|
646
668
|
case 2:
|
|
647
|
-
|
|
648
|
-
|
|
669
|
+
_context9.prev = 2;
|
|
670
|
+
_context9.next = 5;
|
|
649
671
|
return this.db.get("logs", fileName);
|
|
650
672
|
case 5:
|
|
651
|
-
return
|
|
673
|
+
return _context9.abrupt("return", _context9.sent);
|
|
652
674
|
case 8:
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
console.error("获取日志文件内容失败:",
|
|
656
|
-
return
|
|
675
|
+
_context9.prev = 8;
|
|
676
|
+
_context9.t0 = _context9["catch"](2);
|
|
677
|
+
console.error("获取日志文件内容失败:", _context9.t0);
|
|
678
|
+
return _context9.abrupt("return", null);
|
|
657
679
|
case 12:
|
|
658
680
|
case "end":
|
|
659
|
-
return
|
|
681
|
+
return _context9.stop();
|
|
660
682
|
}
|
|
661
|
-
},
|
|
683
|
+
}, _callee9, this, [[2, 8]]);
|
|
662
684
|
}));
|
|
663
685
|
function getLogFile(_x3) {
|
|
664
686
|
return _getLogFile.apply(this, arguments);
|
|
@@ -674,41 +696,41 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
674
696
|
}, {
|
|
675
697
|
key: "clearLogs",
|
|
676
698
|
value: (function () {
|
|
677
|
-
var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
678
|
-
return _regeneratorRuntime().wrap(function
|
|
679
|
-
while (1) switch (
|
|
699
|
+
var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fileName) {
|
|
700
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
701
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
680
702
|
case 0:
|
|
681
703
|
if (this.db) {
|
|
682
|
-
|
|
704
|
+
_context10.next = 2;
|
|
683
705
|
break;
|
|
684
706
|
}
|
|
685
|
-
return
|
|
707
|
+
return _context10.abrupt("return", false);
|
|
686
708
|
case 2:
|
|
687
|
-
|
|
709
|
+
_context10.prev = 2;
|
|
688
710
|
if (!fileName) {
|
|
689
|
-
|
|
711
|
+
_context10.next = 8;
|
|
690
712
|
break;
|
|
691
713
|
}
|
|
692
|
-
|
|
714
|
+
_context10.next = 6;
|
|
693
715
|
return this.db.delete("logs", fileName);
|
|
694
716
|
case 6:
|
|
695
|
-
|
|
717
|
+
_context10.next = 10;
|
|
696
718
|
break;
|
|
697
719
|
case 8:
|
|
698
|
-
|
|
720
|
+
_context10.next = 10;
|
|
699
721
|
return this.db.clear("logs");
|
|
700
722
|
case 10:
|
|
701
|
-
return
|
|
723
|
+
return _context10.abrupt("return", true);
|
|
702
724
|
case 13:
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
console.error("清空日志失败:",
|
|
706
|
-
return
|
|
725
|
+
_context10.prev = 13;
|
|
726
|
+
_context10.t0 = _context10["catch"](2);
|
|
727
|
+
console.error("清空日志失败:", _context10.t0);
|
|
728
|
+
return _context10.abrupt("return", false);
|
|
707
729
|
case 17:
|
|
708
730
|
case "end":
|
|
709
|
-
return
|
|
731
|
+
return _context10.stop();
|
|
710
732
|
}
|
|
711
|
-
},
|
|
733
|
+
}, _callee10, this, [[2, 13]]);
|
|
712
734
|
}));
|
|
713
735
|
function clearLogs(_x4) {
|
|
714
736
|
return _clearLogs.apply(this, arguments);
|
|
@@ -737,17 +759,17 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
737
759
|
}, {
|
|
738
760
|
key: "manualCleanup",
|
|
739
761
|
value: (function () {
|
|
740
|
-
var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
741
|
-
return _regeneratorRuntime().wrap(function
|
|
742
|
-
while (1) switch (
|
|
762
|
+
var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
763
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
764
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
743
765
|
case 0:
|
|
744
|
-
|
|
766
|
+
_context11.next = 2;
|
|
745
767
|
return this.cleanupOldLogs();
|
|
746
768
|
case 2:
|
|
747
769
|
case "end":
|
|
748
|
-
return
|
|
770
|
+
return _context11.stop();
|
|
749
771
|
}
|
|
750
|
-
},
|
|
772
|
+
}, _callee11, this);
|
|
751
773
|
}));
|
|
752
774
|
function manualCleanup() {
|
|
753
775
|
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,10 +67,14 @@ 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
|
-
this.cleanupOldLogs();
|
|
73
|
+
await this.cleanupOldLogs();
|
|
74
|
+
try {
|
|
75
|
+
await this.uploadIndexDBLog();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
80
|
* 初始化 IndexDB
|
|
@@ -211,7 +215,6 @@ var LoggerManager = class {
|
|
|
211
215
|
*/
|
|
212
216
|
async storeLog(urgent) {
|
|
213
217
|
var _a;
|
|
214
|
-
this.uploadIndexDBLog();
|
|
215
218
|
if (this.logBuffer.length === 0 || !this.db) {
|
|
216
219
|
return;
|
|
217
220
|
}
|
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
|
+
});
|