@pisell/core 1.0.40 → 1.0.42

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.
@@ -60,13 +60,13 @@ var IndexDBManager = /*#__PURE__*/function () {
60
60
  // 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
61
61
  _defineProperty(this, "memoryStorage", new Map());
62
62
  // 操作超时时间(毫秒)
63
- _defineProperty(this, "timeout", 5000);
63
+ _defineProperty(this, "timeout", 10000);
64
64
  this.app = app;
65
65
  this.dbName = options.dbName;
66
66
  this.version = options.version;
67
67
  this.stores = options.stores;
68
68
  this.useIndexDB = IndexDBManager.isSupported();
69
- this.timeout = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 5000; // 默认 5 秒超时
69
+ this.timeout = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 10000; // 默认 10 秒超时
70
70
 
71
71
  // 初始化内存存储的各个 store
72
72
  if (!this.useIndexDB) {
@@ -279,14 +279,11 @@ var IndexDBManager = /*#__PURE__*/function () {
279
279
  case 8:
280
280
  uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
281
281
  if (log) {
282
- this.app.logger.addLog({
283
- type: 'info',
284
- title: uuid,
285
- metadata: {
286
- msg: '添加数据前',
287
- data: data
288
- }
289
- });
282
+ // this.app.logger.addLog({
283
+ // type: 'info',
284
+ // title: uuid,
285
+ // metadata: { msg: '添加数据前', data: data }
286
+ // })
290
287
  }
291
288
  return _context4.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
292
289
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
@@ -313,21 +310,17 @@ var IndexDBManager = /*#__PURE__*/function () {
313
310
  return _this4.db.table(storeName).add(data);
314
311
  case 6:
315
312
  if (log) {
316
- _this4.app.logger.addLog({
317
- type: 'info',
318
- title: uuid,
319
- metadata: {
320
- msg: '添加数据成功'
321
- }
322
- });
313
+ // this.app.logger.addLog({
314
+ // type: 'info',
315
+ // title: uuid,
316
+ // metadata: { msg: '添加数据成功' }
317
+ // });
323
318
  console.log('✅ 添加事务完成');
324
- _this4.app.logger.addLog({
325
- type: 'info',
326
- title: uuid,
327
- metadata: {
328
- msg: '事务完成'
329
- }
330
- });
319
+ // this.app.logger.addLog({
320
+ // type: 'info',
321
+ // title: uuid,
322
+ // metadata: { msg: '事务完成' }
323
+ // });
331
324
  }
332
325
  return _context3.abrupt("return", data);
333
326
  case 10:
@@ -448,13 +441,11 @@ var IndexDBManager = /*#__PURE__*/function () {
448
441
  log = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : false;
449
442
  uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
450
443
  if (log) {
451
- this.app.logger.addLog({
452
- type: 'info',
453
- title: uuid,
454
- metadata: {
455
- msg: '获取数据前'
456
- }
457
- });
444
+ // this.app.logger.addLog({
445
+ // type: 'info',
446
+ // title: uuid,
447
+ // metadata: { msg: '获取数据前' }
448
+ // })
458
449
  }
459
450
  if (this.useIndexDB) {
460
451
  _context8.next = 6;
@@ -490,20 +481,16 @@ var IndexDBManager = /*#__PURE__*/function () {
490
481
  case 6:
491
482
  result = _context7.sent;
492
483
  if (log) {
493
- _this6.app.logger.addLog({
494
- type: 'info',
495
- title: uuid,
496
- metadata: {
497
- msg: '获取成功'
498
- }
499
- });
500
- _this6.app.logger.addLog({
501
- type: 'info',
502
- title: uuid,
503
- metadata: {
504
- msg: '事务完成'
505
- }
506
- });
484
+ // this.app.logger.addLog({
485
+ // type: 'info',
486
+ // title: uuid,
487
+ // metadata: { msg: '获取成功' }
488
+ // });
489
+ // this.app.logger.addLog({
490
+ // type: 'info',
491
+ // title: uuid,
492
+ // metadata: { msg: '事务完成' }
493
+ // });
507
494
  }
508
495
  return _context7.abrupt("return", result !== null && result !== void 0 ? result : null);
509
496
  case 11:
@@ -578,14 +565,11 @@ var IndexDBManager = /*#__PURE__*/function () {
578
565
  case 8:
579
566
  uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
580
567
  if (log) {
581
- this.app.logger.addLog({
582
- type: 'info',
583
- title: uuid,
584
- metadata: {
585
- msg: '更新数据前',
586
- data: data
587
- }
588
- });
568
+ // this.app.logger.addLog({
569
+ // type: 'info',
570
+ // title: uuid,
571
+ // metadata: { msg: '更新数据前', data: data }
572
+ // })
589
573
  }
590
574
  return _context10.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
591
575
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
@@ -611,21 +595,17 @@ var IndexDBManager = /*#__PURE__*/function () {
611
595
  return _this7.db.table(storeName).put(data);
612
596
  case 6:
613
597
  if (log) {
614
- _this7.app.logger.addLog({
615
- type: 'info',
616
- title: uuid,
617
- metadata: {
618
- msg: '数据更新完成'
619
- }
620
- });
621
- console.log('✅ 事务完成');
622
- _this7.app.logger.addLog({
623
- type: 'info',
624
- title: uuid,
625
- metadata: {
626
- msg: '事务完成'
627
- }
628
- });
598
+ // this.app.logger.addLog({
599
+ // type: 'info',
600
+ // title: uuid,
601
+ // metadata: { msg: '数据更新完成' }
602
+ // });
603
+ // console.log('✅ 事务完成');
604
+ // this.app.logger.addLog({
605
+ // type: 'info',
606
+ // title: uuid,
607
+ // metadata: { msg: '事务完成' }
608
+ // });
629
609
  }
630
610
  return _context9.abrupt("return", data);
631
611
  case 10:
@@ -295,16 +295,18 @@ var LoggerManager = /*#__PURE__*/function () {
295
295
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
296
296
  while (1) switch (_context3.prev = _context3.next) {
297
297
  case 0:
298
+ // 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
299
+ this.uploadIndexDBLog();
298
300
  if (!(this.logBuffer.length === 0 || !this.db)) {
299
- _context3.next = 2;
301
+ _context3.next = 3;
300
302
  break;
301
303
  }
302
304
  return _context3.abrupt("return");
303
- case 2:
304
- _context3.prev = 2;
305
- _context3.next = 5;
305
+ case 3:
306
+ _context3.prev = 3;
307
+ _context3.next = 6;
306
308
  return this.createAWSFileName(urgent);
307
- case 5:
309
+ case 6:
308
310
  fileName = _context3.sent;
309
311
  console.log("-------- 存储日志到AWS 开始", fileName);
310
312
 
@@ -317,49 +319,57 @@ var LoggerManager = /*#__PURE__*/function () {
317
319
  return item.logId;
318
320
  });
319
321
  logs = JSON.stringify(buffer, null, 2);
320
- _context3.next = 12;
322
+ _context3.next = 13;
321
323
  return this.app.aws.upload({
322
324
  Bucket: "",
323
325
  Key: fileName,
324
326
  Body: logs
325
327
  });
326
- case 12:
328
+ case 13:
327
329
  console.log("-------- 存储日志到AWS 成功");
328
330
  // 上传成功后需要清空缓冲区,避免重复上传
329
331
  this.logBuffer = this.logBuffer.filter(function (item) {
330
332
  return !bufferIds.includes(item.logId);
331
333
  });
332
- _context3.next = 28;
334
+ _context3.next = 29;
333
335
  break;
334
- case 16:
335
- _context3.prev = 16;
336
- _context3.t0 = _context3["catch"](2);
336
+ case 17:
337
+ _context3.prev = 17;
338
+ _context3.t0 = _context3["catch"](3);
337
339
  console.error("存储日志上传AWS失败:", _context3.t0);
338
340
 
339
341
  // 将日志存储到IndexDB
340
- _context3.prev = 19;
341
- _context3.next = 22;
342
+ _context3.prev = 20;
343
+ _context3.next = 23;
342
344
  return this.storeLogToIndexDB();
343
- case 22:
344
- _context3.next = 28;
345
+ case 23:
346
+ _context3.next = 29;
345
347
  break;
346
- case 24:
347
- _context3.prev = 24;
348
- _context3.t1 = _context3["catch"](19);
348
+ case 25:
349
+ _context3.prev = 25;
350
+ _context3.t1 = _context3["catch"](20);
349
351
  this.sendFeishuNotification({
350
352
  type: "error",
351
353
  title: "存储日志到AWS失败",
352
354
  metadata: {
353
- error: JSON.stringify(_context3.t0),
354
- indexDBError: JSON.stringify(_context3.t1)
355
+ error: {
356
+ name: _context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.name,
357
+ message: _context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message,
358
+ stack: _context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.stack
359
+ },
360
+ indexDBError: {
361
+ name: _context3.t1 === null || _context3.t1 === void 0 ? void 0 : _context3.t1.name,
362
+ message: _context3.t1 === null || _context3.t1 === void 0 ? void 0 : _context3.t1.message,
363
+ stack: _context3.t1 === null || _context3.t1 === void 0 ? void 0 : _context3.t1.stack
364
+ }
355
365
  }
356
366
  });
357
367
  console.error("存储日志到IndexDB也失败:", _context3.t1);
358
- case 28:
368
+ case 29:
359
369
  case "end":
360
370
  return _context3.stop();
361
371
  }
362
- }, _callee3, this, [[2, 16], [19, 24]]);
372
+ }, _callee3, this, [[3, 17], [20, 25]]);
363
373
  }));
364
374
  function storeLog(_x2) {
365
375
  return _storeLog.apply(this, arguments);
@@ -375,47 +385,63 @@ var LoggerManager = /*#__PURE__*/function () {
375
385
  while (1) switch (_context4.prev = _context4.next) {
376
386
  case 0:
377
387
  _context4.prev = 0;
378
- _context4.next = 3;
379
- return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
388
+ if (this.db) {
389
+ _context4.next = 3;
390
+ break;
391
+ }
392
+ return _context4.abrupt("return");
380
393
  case 3:
394
+ _context4.next = 5;
395
+ return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
396
+ case 5:
381
397
  logFile = _context4.sent;
382
- _context4.next = 6;
398
+ if (!(!logFile || (logFile === null || logFile === void 0 ? void 0 : logFile.length) === 0)) {
399
+ _context4.next = 8;
400
+ break;
401
+ }
402
+ return _context4.abrupt("return");
403
+ case 8:
404
+ _context4.next = 10;
383
405
  return this.createAWSFileName(true);
384
- case 6:
406
+ case 10:
385
407
  awsFileName = _context4.sent;
386
408
  logs = JSON.stringify(logFile, null, 2);
387
- _context4.next = 10;
409
+ _context4.next = 14;
388
410
  return this.app.aws.upload({
389
411
  Bucket: "",
390
412
  Key: awsFileName,
391
413
  Body: logs
392
414
  });
393
- case 10:
415
+ case 14:
394
416
  console.log("-------- 存储日志到AWS 成功");
395
- _context4.next = 13;
417
+ _context4.next = 17;
396
418
  return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
397
- case 13:
419
+ case 17:
398
420
  console.log("-------- 清空IndexDB日志成功");
399
- _context4.next = 21;
421
+ _context4.next = 25;
400
422
  break;
401
- case 16:
402
- _context4.prev = 16;
423
+ case 20:
424
+ _context4.prev = 20;
403
425
  _context4.t0 = _context4["catch"](0);
404
426
  console.log("-------- 存储日志到IndexDB 失败", _context4.t0);
405
427
  this.sendFeishuNotification({
406
428
  type: "error",
407
429
  title: "存储IndexDB日志到AWS失败",
408
430
  metadata: {
409
- error: JSON.stringify(_context4.t0)
431
+ error: {
432
+ name: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.name,
433
+ message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
434
+ stack: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.stack
435
+ }
410
436
  }
411
437
  });
412
438
  // 重新抛出错误,让外层 catch 能够捕获
413
439
  throw _context4.t0;
414
- case 21:
440
+ case 25:
415
441
  case "end":
416
442
  return _context4.stop();
417
443
  }
418
- }, _callee4, this, [[0, 16]]);
444
+ }, _callee4, this, [[0, 20]]);
419
445
  }));
420
446
  function uploadIndexDBLog() {
421
447
  return _uploadIndexDBLog.apply(this, arguments);
@@ -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 | React.ReactFragment | JSX.Element | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
@@ -108,7 +108,7 @@ export declare class TasksManager {
108
108
  */
109
109
  getQueueStatus(module: string, queueId: string): {
110
110
  isRunning: boolean;
111
- status: "uncompleted" | "completed";
111
+ status: "completed" | "uncompleted";
112
112
  progress: {
113
113
  total: number;
114
114
  completed: number;
@@ -52,7 +52,7 @@ var IndexDBManager = class _IndexDBManager {
52
52
  // 内存存储:每个 store 使用一个 Map,key 为主键,value 为数据
53
53
  memoryStorage = /* @__PURE__ */ new Map();
54
54
  // 操作超时时间(毫秒)
55
- timeout = 5e3;
55
+ timeout = 1e4;
56
56
  /**
57
57
  * 创建 IndexDBManager 实例
58
58
  * @param {DBOptions} options - 数据库配置选项
@@ -63,7 +63,7 @@ var IndexDBManager = class _IndexDBManager {
63
63
  this.version = options.version;
64
64
  this.stores = options.stores;
65
65
  this.useIndexDB = _IndexDBManager.isSupported();
66
- this.timeout = options.timeout ?? 5e3;
66
+ this.timeout = options.timeout ?? 1e4;
67
67
  if (!this.useIndexDB) {
68
68
  this.stores.forEach((store) => {
69
69
  this.memoryStorage.set(store.name, /* @__PURE__ */ new Map());
@@ -200,11 +200,6 @@ var IndexDBManager = class _IndexDBManager {
200
200
  }
201
201
  const uuid = `[ IndexDB ] ADD: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
202
202
  if (log) {
203
- this.app.logger.addLog({
204
- type: "info",
205
- title: uuid,
206
- metadata: { msg: "添加数据前", data }
207
- });
208
203
  }
209
204
  return this.withTimeout(
210
205
  (async () => {
@@ -221,17 +216,7 @@ var IndexDBManager = class _IndexDBManager {
221
216
  try {
222
217
  await this.db.table(storeName).add(data);
223
218
  if (log) {
224
- this.app.logger.addLog({
225
- type: "info",
226
- title: uuid,
227
- metadata: { msg: "添加数据成功" }
228
- });
229
219
  console.log("✅ 添加事务完成");
230
- this.app.logger.addLog({
231
- type: "info",
232
- title: uuid,
233
- metadata: { msg: "事务完成" }
234
- });
235
220
  }
236
221
  return data;
237
222
  } catch (error) {
@@ -285,11 +270,6 @@ var IndexDBManager = class _IndexDBManager {
285
270
  async get(storeName, key, log = false) {
286
271
  const uuid = `[ IndexDB ] GET: - ${storeName} - ${key} - ${(0, import_dayjs.default)().valueOf()}`;
287
272
  if (log) {
288
- this.app.logger.addLog({
289
- type: "info",
290
- title: uuid,
291
- metadata: { msg: "获取数据前" }
292
- });
293
273
  }
294
274
  if (!this.useIndexDB) {
295
275
  const memStore = this.getMemoryStore(storeName);
@@ -310,16 +290,6 @@ var IndexDBManager = class _IndexDBManager {
310
290
  try {
311
291
  const result = await this.db.table(storeName).get(key);
312
292
  if (log) {
313
- this.app.logger.addLog({
314
- type: "info",
315
- title: uuid,
316
- metadata: { msg: "获取成功" }
317
- });
318
- this.app.logger.addLog({
319
- type: "info",
320
- title: uuid,
321
- metadata: { msg: "事务完成" }
322
- });
323
293
  }
324
294
  return result ?? null;
325
295
  } catch (error) {
@@ -355,11 +325,6 @@ var IndexDBManager = class _IndexDBManager {
355
325
  }
356
326
  const uuid = `[ IndexDB ] UPDATE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
357
327
  if (log) {
358
- this.app.logger.addLog({
359
- type: "info",
360
- title: uuid,
361
- metadata: { msg: "更新数据前", data }
362
- });
363
328
  }
364
329
  return this.withTimeout(
365
330
  (async () => {
@@ -376,17 +341,6 @@ var IndexDBManager = class _IndexDBManager {
376
341
  try {
377
342
  await this.db.table(storeName).put(data);
378
343
  if (log) {
379
- this.app.logger.addLog({
380
- type: "info",
381
- title: uuid,
382
- metadata: { msg: "数据更新完成" }
383
- });
384
- console.log("✅ 事务完成");
385
- this.app.logger.addLog({
386
- type: "info",
387
- title: uuid,
388
- metadata: { msg: "事务完成" }
389
- });
390
344
  }
391
345
  return data;
392
346
  } catch (error) {
@@ -211,6 +211,7 @@ var LoggerManager = class {
211
211
  */
212
212
  async storeLog(urgent) {
213
213
  var _a;
214
+ this.uploadIndexDBLog();
214
215
  if (this.logBuffer.length === 0 || !this.db) {
215
216
  return;
216
217
  }
@@ -235,8 +236,16 @@ var LoggerManager = class {
235
236
  type: "error",
236
237
  title: "存储日志到AWS失败",
237
238
  metadata: {
238
- error: JSON.stringify(error),
239
- indexDBError: JSON.stringify(indexDBError)
239
+ error: {
240
+ name: error == null ? void 0 : error.name,
241
+ message: error == null ? void 0 : error.message,
242
+ stack: error == null ? void 0 : error.stack
243
+ },
244
+ indexDBError: {
245
+ name: indexDBError == null ? void 0 : indexDBError.name,
246
+ message: indexDBError == null ? void 0 : indexDBError.message,
247
+ stack: indexDBError == null ? void 0 : indexDBError.stack
248
+ }
240
249
  }
241
250
  });
242
251
  console.error("存储日志到IndexDB也失败:", indexDBError);
@@ -246,7 +255,13 @@ var LoggerManager = class {
246
255
  async uploadIndexDBLog() {
247
256
  var _a, _b;
248
257
  try {
258
+ if (!this.db) {
259
+ return;
260
+ }
249
261
  let logFile = await ((_a = this.db) == null ? void 0 : _a.getAll("logs"));
262
+ if (!logFile || (logFile == null ? void 0 : logFile.length) === 0) {
263
+ return;
264
+ }
250
265
  const awsFileName = await this.createAWSFileName(true);
251
266
  const logs = JSON.stringify(logFile, null, 2);
252
267
  await this.app.aws.upload({ Bucket: "", Key: awsFileName, Body: logs });
@@ -259,7 +274,11 @@ var LoggerManager = class {
259
274
  type: "error",
260
275
  title: "存储IndexDB日志到AWS失败",
261
276
  metadata: {
262
- error: JSON.stringify(error)
277
+ error: {
278
+ name: error == null ? void 0 : error.name,
279
+ message: error == null ? void 0 : error.message,
280
+ stack: error == null ? void 0 : error.stack
281
+ }
263
282
  }
264
283
  });
265
284
  throw error;
@@ -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 | React.ReactFragment | JSX.Element | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
@@ -108,7 +108,7 @@ export declare class TasksManager {
108
108
  */
109
109
  getQueueStatus(module: string, queueId: string): {
110
110
  isRunning: boolean;
111
- status: "uncompleted" | "completed";
111
+ status: "completed" | "uncompleted";
112
112
  progress: {
113
113
  total: number;
114
114
  completed: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",