@pisell/core 1.0.46 → 1.0.48

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.
@@ -326,17 +326,15 @@ var IndexDBManager = /*#__PURE__*/function () {
326
326
  case 10:
327
327
  _context3.prev = 10;
328
328
  _context3.t0 = _context3["catch"](3);
329
- if (log) {
330
- _this4.app.logger.addLog({
331
- type: 'error',
332
- title: uuid,
333
- metadata: {
334
- msg: '添加数据失败',
335
- error: _context3.t0.message
336
- }
337
- });
338
- }
339
- throw new Error('添加数据失败');
329
+ _this4.app.logger.addLog({
330
+ type: 'error',
331
+ title: uuid,
332
+ metadata: {
333
+ msg: '添加数据失败',
334
+ error: _context3.t0.message
335
+ }
336
+ });
337
+ throw new Error(_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message);
340
338
  case 14:
341
339
  case "end":
342
340
  return _context3.stop();
@@ -611,17 +609,15 @@ var IndexDBManager = /*#__PURE__*/function () {
611
609
  case 10:
612
610
  _context9.prev = 10;
613
611
  _context9.t0 = _context9["catch"](3);
614
- if (log) {
615
- _this7.app.logger.addLog({
616
- type: 'error',
617
- title: uuid,
618
- metadata: {
619
- msg: '数据更新失败',
620
- error: _context9.t0.message
621
- }
622
- });
623
- }
624
- throw new Error('更新数据失败');
612
+ _this7.app.logger.addLog({
613
+ type: 'error',
614
+ title: uuid,
615
+ metadata: {
616
+ msg: '数据更新失败',
617
+ error: _context9.t0.message
618
+ }
619
+ });
620
+ throw new Error(_context9.t0 === null || _context9.t0 === void 0 ? void 0 : _context9.t0.message);
625
621
  case 14:
626
622
  case "end":
627
623
  return _context9.stop();
@@ -1110,8 +1106,16 @@ var IndexDBManager = /*#__PURE__*/function () {
1110
1106
  case 9:
1111
1107
  _context23.prev = 9;
1112
1108
  _context23.t0 = _context23["catch"](2);
1113
- throw new Error('获取所有数据失败');
1114
- case 12:
1109
+ _this14.app.logger.addLog({
1110
+ type: 'error',
1111
+ title: "[ IndexDB ] ERROR: - getAll(".concat(storeName, ")"),
1112
+ metadata: {
1113
+ msg: '获取所有数据失败',
1114
+ error: _context23.t0.message
1115
+ }
1116
+ });
1117
+ throw new Error(_context23.t0 === null || _context23.t0 === void 0 ? void 0 : _context23.t0.message);
1118
+ case 13:
1115
1119
  case "end":
1116
1120
  return _context23.stop();
1117
1121
  }
@@ -325,8 +325,9 @@ var LoggerManager = /*#__PURE__*/function () {
325
325
 
326
326
  // 将buffer中的metadata转换为对象
327
327
  buffer = (_this$logBuffer = this.logBuffer) === null || _this$logBuffer === void 0 ? void 0 : _this$logBuffer.map(function (item) {
328
- item.metadata = JSON.parse(item.metadata || "{}");
329
- return item;
328
+ return _objectSpread(_objectSpread({}, item || {}), {}, {
329
+ metadata: JSON.parse(item.metadata || "{}")
330
+ });
330
331
  });
331
332
  bufferIds = buffer.map(function (item) {
332
333
  return item.logId;
@@ -339,37 +340,54 @@ var LoggerManager = /*#__PURE__*/function () {
339
340
  Body: logs
340
341
  });
341
342
  case 13:
343
+ this.addLog({
344
+ type: "info",
345
+ title: "存储日志到AWS 成功",
346
+ metadata: {
347
+ fileName: fileName,
348
+ '本地上传的ids': bufferIds,
349
+ '实例下的ids': this.logBuffer.map(function (item) {
350
+ return item.logId;
351
+ })
352
+ }
353
+ });
342
354
  console.log("-------- 存储日志到AWS 成功");
343
355
  // 上传成功后需要清空缓冲区,避免重复上传
344
356
  this.logBuffer = this.logBuffer.filter(function (item) {
345
357
  return !bufferIds.includes(item.logId);
346
358
  });
347
- _context4.next = 29;
359
+ _context4.next = 31;
348
360
  break;
349
- case 17:
350
- _context4.prev = 17;
361
+ case 18:
362
+ _context4.prev = 18;
351
363
  _context4.t0 = _context4["catch"](3);
352
364
  console.error("存储日志上传AWS失败:", _context4.t0);
365
+ this.addLog({
366
+ type: "info",
367
+ title: "存储日志到AWS失败",
368
+ metadata: {
369
+ error: {
370
+ name: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.name,
371
+ message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
372
+ stack: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.stack
373
+ }
374
+ }
375
+ });
353
376
 
354
377
  // 将日志存储到IndexDB
355
- _context4.prev = 20;
356
- _context4.next = 23;
378
+ _context4.prev = 22;
379
+ _context4.next = 25;
357
380
  return this.storeLogToIndexDB();
358
- case 23:
359
- _context4.next = 29;
360
- break;
361
381
  case 25:
362
- _context4.prev = 25;
363
- _context4.t1 = _context4["catch"](20);
382
+ _context4.next = 31;
383
+ break;
384
+ case 27:
385
+ _context4.prev = 27;
386
+ _context4.t1 = _context4["catch"](22);
364
387
  this.sendFeishuNotification({
365
388
  type: "error",
366
- title: "存储日志到AWS失败",
389
+ title: "将日志存储到IndexDB失败",
367
390
  metadata: {
368
- error: {
369
- name: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.name,
370
- message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
371
- stack: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.stack
372
- },
373
391
  indexDBError: {
374
392
  name: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.name,
375
393
  message: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.message,
@@ -378,11 +396,11 @@ var LoggerManager = /*#__PURE__*/function () {
378
396
  }
379
397
  });
380
398
  console.error("存储日志到IndexDB也失败:", _context4.t1);
381
- case 29:
399
+ case 31:
382
400
  case "end":
383
401
  return _context4.stop();
384
402
  }
385
- }, _callee4, this, [[3, 17], [20, 25]]);
403
+ }, _callee4, this, [[3, 18], [22, 27]]);
386
404
  }));
387
405
  function storeLog(_x2) {
388
406
  return _storeLog.apply(this, arguments);
@@ -59,7 +59,7 @@ export var setCache = /*#__PURE__*/function () {
59
59
  }
60
60
  // 将数据存储至缓存池
61
61
  CACHES[key] = cacheData;
62
- _context.next = 20;
62
+ _context.next = 23;
63
63
  break;
64
64
  case 6:
65
65
  if (!(cache.type === 'storage')) {
@@ -68,17 +68,17 @@ export var setCache = /*#__PURE__*/function () {
68
68
  }
69
69
  // 设置缓存
70
70
  storage.setStorage(key, JSON.stringify(cacheData));
71
- _context.next = 20;
71
+ _context.next = 23;
72
72
  break;
73
73
  case 10:
74
74
  if (!(cache.type === 'indexDB')) {
75
- _context.next = 20;
75
+ _context.next = 23;
76
76
  break;
77
77
  }
78
78
  // 设置缓存
79
79
  app = getApp();
80
80
  if (!app.dbManager) {
81
- _context.next = 20;
81
+ _context.next = 23;
82
82
  break;
83
83
  }
84
84
  _context.next = 15;
@@ -86,16 +86,20 @@ export var setCache = /*#__PURE__*/function () {
86
86
  case 15:
87
87
  tasksData = _context.sent;
88
88
  if (tasksData) {
89
- _context.next = 19;
89
+ _context.next = 21;
90
90
  break;
91
91
  }
92
92
  _context.next = 19;
93
93
  return app.dbManager.add('requests', cacheData);
94
94
  case 19:
95
- app.dbManager.update('requests', cacheData);
96
- case 20:
97
- console.log('设置缓存成功', CACHES);
95
+ _context.next = 23;
96
+ break;
98
97
  case 21:
98
+ _context.next = 23;
99
+ return app.dbManager.update('requests', cacheData);
100
+ case 23:
101
+ console.log('设置缓存成功', CACHES);
102
+ case 24:
99
103
  case "end":
100
104
  return _context.stop();
101
105
  }
@@ -99,7 +99,8 @@ export var createRequest = function createRequest(props) {
99
99
  title: "[ Request ]: Complete - ".concat(requestId),
100
100
  metadata: {
101
101
  error: isError ? JSON.stringify(result) : '',
102
- duration: "".concat((duration / 1000).toFixed(2), "s")
102
+ duration: "".concat((duration / 1000).toFixed(2), "s"),
103
+ url: url
103
104
  }
104
105
  });
105
106
  } catch (error) {}
@@ -108,7 +108,7 @@ export declare class TasksManager {
108
108
  */
109
109
  getQueueStatus(module: string, queueId: string): {
110
110
  isRunning: boolean;
111
- status: "completed" | "uncompleted";
111
+ status: "uncompleted" | "completed";
112
112
  progress: {
113
113
  total: number;
114
114
  completed: number;
@@ -220,14 +220,12 @@ var IndexDBManager = class _IndexDBManager {
220
220
  }
221
221
  return data;
222
222
  } catch (error) {
223
- if (log) {
224
- this.app.logger.addLog({
225
- type: "error",
226
- title: uuid,
227
- metadata: { msg: "添加数据失败", error: error.message }
228
- });
229
- }
230
- throw new Error("添加数据失败");
223
+ this.app.logger.addLog({
224
+ type: "error",
225
+ title: uuid,
226
+ metadata: { msg: "添加数据失败", error: error.message }
227
+ });
228
+ throw new Error(error == null ? void 0 : error.message);
231
229
  }
232
230
  })(),
233
231
  `add(${storeName})`
@@ -344,14 +342,12 @@ var IndexDBManager = class _IndexDBManager {
344
342
  }
345
343
  return data;
346
344
  } catch (error) {
347
- if (log) {
348
- this.app.logger.addLog({
349
- type: "error",
350
- title: uuid,
351
- metadata: { msg: "数据更新失败", error: error.message }
352
- });
353
- }
354
- throw new Error("更新数据失败");
345
+ this.app.logger.addLog({
346
+ type: "error",
347
+ title: uuid,
348
+ metadata: { msg: "数据更新失败", error: error.message }
349
+ });
350
+ throw new Error(error == null ? void 0 : error.message);
355
351
  }
356
352
  })(),
357
353
  `update(${storeName})`
@@ -550,7 +546,12 @@ var IndexDBManager = class _IndexDBManager {
550
546
  const results = await this.db.table(storeName).toArray();
551
547
  return results;
552
548
  } catch (error) {
553
- throw new Error("获取所有数据失败");
549
+ this.app.logger.addLog({
550
+ type: "error",
551
+ title: `[ IndexDB ] ERROR: - getAll(${storeName})`,
552
+ metadata: { msg: "获取所有数据失败", error: error.message }
553
+ });
554
+ throw new Error(error == null ? void 0 : error.message);
554
555
  }
555
556
  })(),
556
557
  `getAll(${storeName})`
@@ -219,28 +219,45 @@ var LoggerManager = class {
219
219
  const fileName = await this.createAWSFileName(urgent);
220
220
  console.log("-------- 存储日志到AWS 开始", fileName);
221
221
  const buffer = (_a = this.logBuffer) == null ? void 0 : _a.map((item) => {
222
- item.metadata = JSON.parse(item.metadata || "{}");
223
- return item;
222
+ return {
223
+ ...item || {},
224
+ metadata: JSON.parse(item.metadata || "{}")
225
+ };
224
226
  });
225
227
  const bufferIds = buffer.map((item) => item.logId);
226
228
  const logs = JSON.stringify(buffer, null, 2);
227
229
  await this.app.aws.upload({ Bucket: "", Key: fileName, Body: logs });
230
+ this.addLog({
231
+ type: "info",
232
+ title: "存储日志到AWS 成功",
233
+ metadata: {
234
+ fileName,
235
+ "本地上传的ids": bufferIds,
236
+ "实例下的ids": this.logBuffer.map((item) => item.logId)
237
+ }
238
+ });
228
239
  console.log("-------- 存储日志到AWS 成功");
229
240
  this.logBuffer = this.logBuffer.filter((item) => !bufferIds.includes(item.logId));
230
241
  } catch (error) {
231
242
  console.error("存储日志上传AWS失败:", error);
243
+ this.addLog({
244
+ type: "info",
245
+ title: "存储日志到AWS失败",
246
+ metadata: {
247
+ error: {
248
+ name: error == null ? void 0 : error.name,
249
+ message: error == null ? void 0 : error.message,
250
+ stack: error == null ? void 0 : error.stack
251
+ }
252
+ }
253
+ });
232
254
  try {
233
255
  await this.storeLogToIndexDB();
234
256
  } catch (indexDBError) {
235
257
  this.sendFeishuNotification({
236
258
  type: "error",
237
- title: "存储日志到AWS失败",
259
+ title: "将日志存储到IndexDB失败",
238
260
  metadata: {
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
261
  indexDBError: {
245
262
  name: indexDBError == null ? void 0 : indexDBError.name,
246
263
  message: indexDBError == null ? void 0 : indexDBError.message,
@@ -66,8 +66,9 @@ var setCache = async (key, data, cache) => {
66
66
  let tasksData = await app.dbManager.get("requests", key);
67
67
  if (!tasksData) {
68
68
  await app.dbManager.add("requests", cacheData);
69
+ } else {
70
+ await app.dbManager.update("requests", cacheData);
69
71
  }
70
- app.dbManager.update("requests", cacheData);
71
72
  }
72
73
  }
73
74
  console.log("设置缓存成功", CACHES);
@@ -103,7 +103,8 @@ var createRequest = (props) => {
103
103
  title: `[ Request ]: Complete - ${requestId2}`,
104
104
  metadata: {
105
105
  error: isError ? JSON.stringify(result) : "",
106
- duration: `${(duration / 1e3).toFixed(2)}s`
106
+ duration: `${(duration / 1e3).toFixed(2)}s`,
107
+ url: url2
107
108
  }
108
109
  });
109
110
  } catch (error) {
@@ -108,7 +108,7 @@ export declare class TasksManager {
108
108
  */
109
109
  getQueueStatus(module: string, queueId: string): {
110
110
  isRunning: boolean;
111
- status: "completed" | "uncompleted";
111
+ status: "uncompleted" | "completed";
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.46",
3
+ "version": "1.0.48",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",