@pisell/pisellos 2.2.122 → 2.2.123

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.
@@ -36,6 +36,8 @@ import { OrderHooks } from "./types";
36
36
  */
37
37
  var INDEXDB_STORE_NAME = 'orders';
38
38
  var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
39
+ var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = 'order_sync_throttle_ms';
40
+ var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2000;
39
41
 
40
42
  /**
41
43
  * Order 模块 - 基础框架
@@ -54,7 +56,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
54
56
  _defineProperty(_assertThisInitialized(_this), "orderDataSource", void 0);
55
57
  _defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
56
58
  _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
57
- _defineProperty(_assertThisInitialized(_this), "ORDER_SYNC_DEBOUNCE_MS", 5000);
59
+ _defineProperty(_assertThisInitialized(_this), "isProcessingSyncBatch", false);
60
+ _defineProperty(_assertThisInitialized(_this), "isIdlePhase", true);
58
61
  // Map<resource_id, OrderId[]> 资源到订单的倒排索引
59
62
  _defineProperty(_assertThisInitialized(_this), "resourceIdIndex", new Map());
60
63
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
@@ -179,6 +182,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
179
182
  // 日志记录失败不影响主流程
180
183
  }
181
184
  }
185
+ }, {
186
+ key: "getOrderSyncThrottleMs",
187
+ value: function getOrderSyncThrottleMs() {
188
+ var raw = localStorage.getItem(ORDER_SYNC_THROTTLE_MS_STORAGE_KEY);
189
+ if (raw !== null) {
190
+ var parsed = Number(raw);
191
+ if (Number.isFinite(parsed) && parsed >= 0) return parsed;
192
+ }
193
+ return DEFAULT_ORDER_SYNC_THROTTLE_MS;
194
+ }
182
195
  }, {
183
196
  key: "preload",
184
197
  value: function () {
@@ -283,14 +296,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
283
296
  _context4.prev = 3;
284
297
  _context4.next = 6;
285
298
  return this.orderDataSource.run({
286
- http: {
299
+ sse: {
287
300
  query: this.store.createdAtQuery
288
301
  }
289
302
  });
290
303
  case 6:
291
304
  data = _context4.sent;
292
305
  orderList = data || [];
293
- this.logInfo('loadOrdersByServer-拉取成功', {
306
+ this.logInfo('loadOrdersByServer-SSE拉取成功', {
294
307
  count: orderList.length
295
308
  });
296
309
  this.markOrderPulledAtNow();
@@ -300,7 +313,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
300
313
  _context4.prev = 12;
301
314
  _context4.t0 = _context4["catch"](3);
302
315
  orderList = [];
303
- this.logInfo('loadOrdersByServer-拉取失败,回退为空数组');
316
+ this.logInfo('loadOrdersByServer-SSE拉取失败,回退为空数组');
304
317
  case 16:
305
318
  _context4.next = 18;
306
319
  return this.saveOrdersToSQLite(orderList);
@@ -334,6 +347,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
334
347
  return !!order;
335
348
  });
336
349
  }
350
+
351
+ /**
352
+ * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
353
+ */
354
+ }, {
355
+ key: "fetchOrdersBySSE",
356
+ value: (function () {
357
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
358
+ var query,
359
+ data,
360
+ _args5 = arguments;
361
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
362
+ while (1) switch (_context5.prev = _context5.next) {
363
+ case 0:
364
+ query = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
365
+ if (this.orderDataSource) {
366
+ _context5.next = 3;
367
+ break;
368
+ }
369
+ return _context5.abrupt("return", []);
370
+ case 3:
371
+ _context5.prev = 3;
372
+ _context5.next = 6;
373
+ return this.orderDataSource.run({
374
+ sse: {
375
+ query: query
376
+ }
377
+ });
378
+ case 6:
379
+ data = _context5.sent;
380
+ return _context5.abrupt("return", data || []);
381
+ case 10:
382
+ _context5.prev = 10;
383
+ _context5.t0 = _context5["catch"](3);
384
+ this.logError('fetchOrdersBySSE-失败', {
385
+ error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
386
+ });
387
+ return _context5.abrupt("return", []);
388
+ case 14:
389
+ case "end":
390
+ return _context5.stop();
391
+ }
392
+ }, _callee5, this, [[3, 10]]);
393
+ }));
394
+ function fetchOrdersBySSE() {
395
+ return _fetchOrdersBySSE.apply(this, arguments);
396
+ }
397
+ return fetchOrdersBySSE;
398
+ }())
337
399
  }, {
338
400
  key: "getRoutes",
339
401
  value: function getRoutes() {
@@ -347,6 +409,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
347
409
  clearTimeout(this.syncTimer);
348
410
  this.syncTimer = undefined;
349
411
  }
412
+ this.isProcessingSyncBatch = false;
350
413
  this.pendingSyncMessages = [];
351
414
  if ((_this$orderDataSource = this.orderDataSource) !== null && _this$orderDataSource !== void 0 && _this$orderDataSource.destroy) this.orderDataSource.destroy();
352
415
  _get(_getPrototypeOf(OrderModule.prototype), "destroy", this).call(this);
@@ -441,80 +504,160 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
441
504
  }
442
505
 
443
506
  /**
444
- * 初始化 pubsub 订阅,监听订单变更
507
+ * 初始化 pubsub 订阅,监听订单变更(纯订阅,不拉数据;全量 SSE 由 loadOrdersByServer 负责)
445
508
  */
446
509
  }, {
447
510
  key: "setupOrderSync",
448
511
  value: function setupOrderSync() {
449
512
  var _this5 = this;
450
513
  if (!this.orderDataSource) return;
451
- var shouldSkipHttpPull = this.hasPulledOrdersToday();
452
- var syncPayload = {
514
+ this.orderDataSource.run({
453
515
  pubsub: {
454
516
  callback: function callback(res) {
455
517
  var _message$id, _message$order_id, _message$type;
518
+ console.log('orderDataSource');
519
+ var pubsubReceivedAt = Date.now();
456
520
  var message = _this5.normalizeOrderSyncMessage(res);
457
521
  if (!message) return;
522
+ message._pubsubReceivedAt = pubsubReceivedAt;
458
523
  _this5.pendingSyncMessages.push(message);
524
+ var throttleMs = _this5.getOrderSyncThrottleMs();
459
525
  _this5.logInfo('orderSync-收到消息并入队', {
460
526
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
461
527
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
462
528
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
463
529
  pendingCount: _this5.pendingSyncMessages.length,
464
- debounceMs: _this5.ORDER_SYNC_DEBOUNCE_MS
530
+ throttleMs: throttleMs,
531
+ pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString()
465
532
  });
466
- if (_this5.syncTimer) clearTimeout(_this5.syncTimer);
467
- _this5.syncTimer = setTimeout(function () {
468
- _this5.processOrderSyncMessages();
469
- }, _this5.ORDER_SYNC_DEBOUNCE_MS);
533
+ _this5.scheduleOrderSyncThrottle();
470
534
  }
471
535
  }
472
- };
473
- syncPayload.http = {
474
- query: this.store.createdAtQuery,
475
- skipHttp: shouldSkipHttpPull
476
- };
477
- this.orderDataSource.run(syncPayload).then(function () {
478
- if (!shouldSkipHttpPull) _this5.markOrderPulledAtNow();
479
536
  }).catch(function () {
480
537
  // 忽略同步初始化异常,避免影响主流程
481
538
  });
482
539
  }
483
540
 
484
541
  /**
485
- * 处理防抖后的同步消息批次
542
+ * 调度订单同步节流窗口(leading-edge throttle):
543
+ * - 空闲状态下收到的第一条消息立即触发批处理,无需等待;
544
+ * - 首条处理后进入冷却窗口,窗口期间的后续消息聚合,窗口结束后批量处理;
545
+ * - 若当前批处理执行中,则由批处理结束后决定是否开启下一轮窗口。
546
+ */
547
+ }, {
548
+ key: "scheduleOrderSyncThrottle",
549
+ value: function scheduleOrderSyncThrottle() {
550
+ var _this6 = this;
551
+ if (this.isProcessingSyncBatch) return;
552
+ if (this.isIdlePhase) {
553
+ this.isIdlePhase = false;
554
+ this.logInfo('orderSync-首条消息立即触发处理');
555
+ void this.flushOrderSyncMessagesByThrottle();
556
+ return;
557
+ }
558
+ if (this.syncTimer) return;
559
+ var throttleMs = this.getOrderSyncThrottleMs();
560
+ this.syncTimer = setTimeout(function () {
561
+ _this6.syncTimer = undefined;
562
+ void _this6.flushOrderSyncMessagesByThrottle();
563
+ }, throttleMs);
564
+ }
565
+
566
+ /**
567
+ * 执行一次节流批处理并在需要时续约下一轮窗口。
568
+ * 批处理完成且无后续消息时恢复空闲状态,下一条消息将立即触发。
569
+ */
570
+ }, {
571
+ key: "flushOrderSyncMessagesByThrottle",
572
+ value: (function () {
573
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
574
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
575
+ while (1) switch (_context6.prev = _context6.next) {
576
+ case 0:
577
+ if (!this.isProcessingSyncBatch) {
578
+ _context6.next = 2;
579
+ break;
580
+ }
581
+ return _context6.abrupt("return");
582
+ case 2:
583
+ if (!(this.pendingSyncMessages.length === 0)) {
584
+ _context6.next = 5;
585
+ break;
586
+ }
587
+ this.isIdlePhase = true;
588
+ return _context6.abrupt("return");
589
+ case 5:
590
+ this.isProcessingSyncBatch = true;
591
+ _context6.prev = 6;
592
+ _context6.next = 9;
593
+ return this.processOrderSyncMessages();
594
+ case 9:
595
+ _context6.prev = 9;
596
+ this.isProcessingSyncBatch = false;
597
+ if (this.pendingSyncMessages.length > 0) {
598
+ this.scheduleOrderSyncThrottle();
599
+ } else {
600
+ this.isIdlePhase = true;
601
+ }
602
+ return _context6.finish(9);
603
+ case 13:
604
+ case "end":
605
+ return _context6.stop();
606
+ }
607
+ }, _callee6, this, [[6,, 9, 13]]);
608
+ }));
609
+ function flushOrderSyncMessagesByThrottle() {
610
+ return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
611
+ }
612
+ return flushOrderSyncMessagesByThrottle;
613
+ }()
614
+ /**
615
+ * 处理节流窗口内聚合后的同步消息批次
486
616
  *
487
617
  * 后端统一发送 change 消息,不再区分新增/编辑/删除。
488
618
  * - 单条(id/order_id):若携带 body/data 则直接 upsert 到本地
489
619
  * - 批量(ids):通过 HTTP 按 ids 增量拉取,再 merge 到本地
620
+ *
621
+ * @example
622
+ * // pending 队列中存在 8 条消息时,仅处理一次批次并统一 merge
623
+ * await this.processOrderSyncMessages()
490
624
  */
625
+ )
491
626
  }, {
492
627
  key: "processOrderSyncMessages",
493
628
  value: (function () {
494
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
495
- var messages, upsertOrders, refreshIds, _iterator3, _step3, _msg$id, _msg$relation_order_i, msg, hasBatchIds, singleId, hasSingleId, rawBody, normalizedBody, uniqueRefreshIds, upsertList, freshOrders;
496
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
497
- while (1) switch (_context5.prev = _context5.next) {
629
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
630
+ var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, _iterator3, _step3, _msg$id, _msg$relation_order_i, msg, hasBatchIds, singleId, hasSingleId, rawBody, normalizedBody, uniqueRefreshIds, upsertList, freshOrders, batchProcessEndAt;
631
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
632
+ while (1) switch (_context7.prev = _context7.next) {
498
633
  case 0:
499
634
  messages = _toConsumableArray(this.pendingSyncMessages);
500
635
  this.pendingSyncMessages = [];
501
636
  if (!(messages.length === 0)) {
502
- _context5.next = 4;
637
+ _context7.next = 4;
503
638
  break;
504
639
  }
505
- return _context5.abrupt("return");
640
+ return _context7.abrupt("return");
506
641
  case 4:
642
+ batchProcessStartAt = Date.now();
643
+ earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
644
+ var _m$_pubsubReceivedAt;
645
+ return (_m$_pubsubReceivedAt = m._pubsubReceivedAt) !== null && _m$_pubsubReceivedAt !== void 0 ? _m$_pubsubReceivedAt : batchProcessStartAt;
646
+ })));
507
647
  this.logInfo('processOrderSyncMessages-开始', {
508
- messageCount: messages.length
648
+ messageCount: messages.length,
649
+ earliestReceivedAt: new Date(earliestReceivedAt).toISOString(),
650
+ batchProcessStartAt: new Date(batchProcessStartAt).toISOString(),
651
+ waitDurationMs: batchProcessStartAt - earliestReceivedAt
509
652
  });
510
653
  upsertOrders = new Map();
511
654
  refreshIds = [];
512
655
  _iterator3 = _createForOfIteratorHelper(messages);
513
- _context5.prev = 8;
656
+ _context7.prev = 10;
514
657
  _iterator3.s();
515
- case 10:
658
+ case 12:
516
659
  if ((_step3 = _iterator3.n()).done) {
517
- _context5.next = 23;
660
+ _context7.next = 25;
518
661
  break;
519
662
  }
520
663
  msg = _step3.value;
@@ -524,28 +667,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
524
667
  rawBody = msg.body || msg.data;
525
668
  normalizedBody = this.normalizeOrderSyncPayload(rawBody);
526
669
  if (!(hasSingleId && normalizedBody)) {
527
- _context5.next = 20;
670
+ _context7.next = 22;
528
671
  break;
529
672
  }
530
673
  upsertOrders.set(this.getIdKey(normalizedBody.order_id), normalizedBody);
531
- return _context5.abrupt("continue", 21);
532
- case 20:
674
+ return _context7.abrupt("continue", 23);
675
+ case 22:
533
676
  if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(msg.ids));else if (hasSingleId) refreshIds.push(singleId);else if ((_msg$relation_order_i = msg.relation_order_ids) !== null && _msg$relation_order_i !== void 0 && _msg$relation_order_i.length) refreshIds.push.apply(refreshIds, _toConsumableArray(msg.relation_order_ids));
534
- case 21:
535
- _context5.next = 10;
536
- break;
537
677
  case 23:
538
- _context5.next = 28;
678
+ _context7.next = 12;
539
679
  break;
540
680
  case 25:
541
- _context5.prev = 25;
542
- _context5.t0 = _context5["catch"](8);
543
- _iterator3.e(_context5.t0);
544
- case 28:
545
- _context5.prev = 28;
681
+ _context7.next = 30;
682
+ break;
683
+ case 27:
684
+ _context7.prev = 27;
685
+ _context7.t0 = _context7["catch"](10);
686
+ _iterator3.e(_context7.t0);
687
+ case 30:
688
+ _context7.prev = 30;
546
689
  _iterator3.f();
547
- return _context5.finish(28);
548
- case 31:
690
+ return _context7.finish(30);
691
+ case 33:
549
692
  uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
550
693
  upsertList = _toConsumableArray(upsertOrders.values());
551
694
  this.logInfo('processOrderSyncMessages-去重完成', {
@@ -553,44 +696,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
553
696
  refreshIdCount: uniqueRefreshIds.length
554
697
  });
555
698
  if (!(upsertList.length > 0)) {
556
- _context5.next = 37;
699
+ _context7.next = 39;
557
700
  break;
558
701
  }
559
- _context5.next = 37;
702
+ _context7.next = 39;
560
703
  return this.mergeOrdersToStore(upsertList);
561
- case 37:
704
+ case 39:
562
705
  if (!(uniqueRefreshIds.length > 0)) {
563
- _context5.next = 44;
706
+ _context7.next = 46;
564
707
  break;
565
708
  }
566
- _context5.next = 40;
709
+ _context7.next = 42;
567
710
  return this.fetchOrdersByHttp(uniqueRefreshIds);
568
- case 40:
569
- freshOrders = _context5.sent;
711
+ case 42:
712
+ freshOrders = _context7.sent;
570
713
  if (!(freshOrders.length > 0)) {
571
- _context5.next = 44;
714
+ _context7.next = 46;
572
715
  break;
573
716
  }
574
- _context5.next = 44;
717
+ _context7.next = 46;
575
718
  return this.mergeOrdersToStore(freshOrders);
576
- case 44:
719
+ case 46:
577
720
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
578
- _context5.next = 46;
721
+ _context7.next = 48;
579
722
  break;
580
723
  }
581
- return _context5.abrupt("return");
582
- case 46:
724
+ return _context7.abrupt("return");
725
+ case 48:
726
+ batchProcessEndAt = Date.now();
583
727
  this.logInfo('processOrderSyncMessages-结束', {
584
728
  upsertCount: upsertList.length,
585
- refreshIdCount: uniqueRefreshIds.length
729
+ refreshIdCount: uniqueRefreshIds.length,
730
+ batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
731
+ totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
586
732
  });
587
- _context5.next = 49;
733
+ _context7.next = 52;
588
734
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
589
- case 49:
735
+ case 52:
590
736
  case "end":
591
- return _context5.stop();
737
+ return _context7.stop();
592
738
  }
593
- }, _callee5, this, [[8, 25, 28, 31]]);
739
+ }, _callee7, this, [[10, 27, 30, 33]]);
594
740
  }));
595
741
  function processOrderSyncMessages() {
596
742
  return _processOrderSyncMessages.apply(this, arguments);
@@ -604,29 +750,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
604
750
  }, {
605
751
  key: "fetchOrdersByHttp",
606
752
  value: (function () {
607
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(ids) {
753
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(ids) {
608
754
  var _orderList, orderList;
609
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
610
- while (1) switch (_context6.prev = _context6.next) {
755
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
756
+ while (1) switch (_context8.prev = _context8.next) {
611
757
  case 0:
612
758
  if (!(!this.orderDataSource || ids.length === 0)) {
613
- _context6.next = 2;
759
+ _context8.next = 2;
614
760
  break;
615
761
  }
616
- return _context6.abrupt("return", []);
762
+ return _context8.abrupt("return", []);
617
763
  case 2:
618
- _context6.prev = 2;
764
+ _context8.prev = 2;
619
765
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
620
- _context6.next = 8;
766
+ _context8.next = 8;
621
767
  break;
622
768
  }
623
- _context6.next = 6;
769
+ _context8.next = 6;
624
770
  return this.orderDataSource.fetchOrdersByIds(ids);
625
771
  case 6:
626
- _orderList = _context6.sent;
627
- return _context6.abrupt("return", _orderList || []);
772
+ _orderList = _context8.sent;
773
+ return _context8.abrupt("return", _orderList || []);
628
774
  case 8:
629
- _context6.next = 10;
775
+ _context8.next = 10;
630
776
  return this.orderDataSource.run({
631
777
  http: {
632
778
  query: {
@@ -635,17 +781,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
635
781
  }
636
782
  });
637
783
  case 10:
638
- orderList = _context6.sent;
639
- return _context6.abrupt("return", orderList || []);
784
+ orderList = _context8.sent;
785
+ return _context8.abrupt("return", orderList || []);
640
786
  case 14:
641
- _context6.prev = 14;
642
- _context6.t0 = _context6["catch"](2);
643
- return _context6.abrupt("return", []);
787
+ _context8.prev = 14;
788
+ _context8.t0 = _context8["catch"](2);
789
+ return _context8.abrupt("return", []);
644
790
  case 17:
645
791
  case "end":
646
- return _context6.stop();
792
+ return _context8.stop();
647
793
  }
648
- }, _callee6, this, [[2, 14]]);
794
+ }, _callee8, this, [[2, 14]]);
649
795
  }));
650
796
  function fetchOrdersByHttp(_x3) {
651
797
  return _fetchOrdersByHttp.apply(this, arguments);
@@ -659,11 +805,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
659
805
  }, {
660
806
  key: "mergeOrdersToStore",
661
807
  value: (function () {
662
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(freshOrders) {
663
- var _this6 = this;
808
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(freshOrders) {
809
+ var _this7 = this;
664
810
  var freshMap, _iterator4, _step4, order, id, uniqueFreshCount, updatedList, _iterator5, _step5, _order;
665
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
666
- while (1) switch (_context7.prev = _context7.next) {
811
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
812
+ while (1) switch (_context9.prev = _context9.next) {
667
813
  case 0:
668
814
  this.logInfo('mergeOrdersToStore-开始', {
669
815
  freshOrderCount: freshOrders.length,
@@ -671,42 +817,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
671
817
  });
672
818
  freshMap = new Map();
673
819
  _iterator4 = _createForOfIteratorHelper(freshOrders);
674
- _context7.prev = 3;
820
+ _context9.prev = 3;
675
821
  _iterator4.s();
676
822
  case 5:
677
823
  if ((_step4 = _iterator4.n()).done) {
678
- _context7.next = 13;
824
+ _context9.next = 13;
679
825
  break;
680
826
  }
681
827
  order = _step4.value;
682
828
  id = order === null || order === void 0 ? void 0 : order.order_id;
683
829
  if (!(id === undefined || id === null)) {
684
- _context7.next = 10;
830
+ _context9.next = 10;
685
831
  break;
686
832
  }
687
- return _context7.abrupt("continue", 11);
833
+ return _context9.abrupt("continue", 11);
688
834
  case 10:
689
835
  freshMap.set(this.getIdKey(id), order);
690
836
  case 11:
691
- _context7.next = 5;
837
+ _context9.next = 5;
692
838
  break;
693
839
  case 13:
694
- _context7.next = 18;
840
+ _context9.next = 18;
695
841
  break;
696
842
  case 15:
697
- _context7.prev = 15;
698
- _context7.t0 = _context7["catch"](3);
699
- _iterator4.e(_context7.t0);
843
+ _context9.prev = 15;
844
+ _context9.t0 = _context9["catch"](3);
845
+ _iterator4.e(_context9.t0);
700
846
  case 18:
701
- _context7.prev = 18;
847
+ _context9.prev = 18;
702
848
  _iterator4.f();
703
- return _context7.finish(18);
849
+ return _context9.finish(18);
704
850
  case 21:
705
851
  uniqueFreshCount = freshMap.size;
706
852
  updatedList = this.store.list.map(function (order) {
707
853
  var id = order.order_id;
708
854
  if (id === undefined || id === null) return order;
709
- var key = _this6.getIdKey(id);
855
+ var key = _this7.getIdKey(id);
710
856
  if (!freshMap.has(key)) return order;
711
857
  var fresh = freshMap.get(key);
712
858
  freshMap.delete(key);
@@ -725,7 +871,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
725
871
  }
726
872
  this.store.list = updatedList;
727
873
  this.syncOrdersMap();
728
- _context7.next = 29;
874
+ _context9.next = 29;
729
875
  return this.saveOrdersToSQLite(this.store.list);
730
876
  case 29:
731
877
  this.logInfo('mergeOrdersToStore-结束', {
@@ -735,9 +881,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
735
881
  this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
736
882
  case 31:
737
883
  case "end":
738
- return _context7.stop();
884
+ return _context9.stop();
739
885
  }
740
- }, _callee7, this, [[3, 15, 18, 21]]);
886
+ }, _callee9, this, [[3, 15, 18, 21]]);
741
887
  }));
742
888
  function mergeOrdersToStore(_x4) {
743
889
  return _mergeOrdersToStore.apply(this, arguments);
@@ -876,32 +1022,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
876
1022
  }, {
877
1023
  key: "loadOrdersFromSQLite",
878
1024
  value: function () {
879
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1025
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
880
1026
  var orders;
881
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
882
- while (1) switch (_context8.prev = _context8.next) {
1027
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1028
+ while (1) switch (_context10.prev = _context10.next) {
883
1029
  case 0:
884
1030
  if (this.dbManager) {
885
- _context8.next = 2;
1031
+ _context10.next = 2;
886
1032
  break;
887
1033
  }
888
- return _context8.abrupt("return", []);
1034
+ return _context10.abrupt("return", []);
889
1035
  case 2:
890
- _context8.prev = 2;
891
- _context8.next = 5;
1036
+ _context10.prev = 2;
1037
+ _context10.next = 5;
892
1038
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
893
1039
  case 5:
894
- orders = _context8.sent;
895
- return _context8.abrupt("return", orders || []);
1040
+ orders = _context10.sent;
1041
+ return _context10.abrupt("return", orders || []);
896
1042
  case 9:
897
- _context8.prev = 9;
898
- _context8.t0 = _context8["catch"](2);
899
- return _context8.abrupt("return", []);
1043
+ _context10.prev = 9;
1044
+ _context10.t0 = _context10["catch"](2);
1045
+ return _context10.abrupt("return", []);
900
1046
  case 12:
901
1047
  case "end":
902
- return _context8.stop();
1048
+ return _context10.stop();
903
1049
  }
904
- }, _callee8, this, [[2, 9]]);
1050
+ }, _callee10, this, [[2, 9]]);
905
1051
  }));
906
1052
  function loadOrdersFromSQLite() {
907
1053
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -911,53 +1057,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
911
1057
  }, {
912
1058
  key: "saveOrdersToSQLite",
913
1059
  value: function () {
914
- var _saveOrdersToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderList) {
915
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
916
- while (1) switch (_context9.prev = _context9.next) {
1060
+ var _saveOrdersToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderList) {
1061
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1062
+ while (1) switch (_context11.prev = _context11.next) {
917
1063
  case 0:
918
1064
  if (this.dbManager) {
919
- _context9.next = 2;
1065
+ _context11.next = 2;
920
1066
  break;
921
1067
  }
922
- return _context9.abrupt("return");
1068
+ return _context11.abrupt("return");
923
1069
  case 2:
924
- _context9.prev = 2;
1070
+ _context11.prev = 2;
925
1071
  this.logInfo('saveOrdersToSQLite-开始', {
926
1072
  count: orderList.length
927
1073
  });
928
- _context9.next = 6;
1074
+ _context11.next = 6;
929
1075
  return this.dbManager.clear(INDEXDB_STORE_NAME);
930
1076
  case 6:
931
1077
  this.logInfo('saveOrdersToSQLite-clear完成', {
932
1078
  count: orderList.length
933
1079
  });
934
1080
  if (!(orderList.length === 0)) {
935
- _context9.next = 9;
1081
+ _context11.next = 9;
936
1082
  break;
937
1083
  }
938
- return _context9.abrupt("return");
1084
+ return _context11.abrupt("return");
939
1085
  case 9:
940
- _context9.next = 11;
1086
+ _context11.next = 11;
941
1087
  return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderList);
942
1088
  case 11:
943
1089
  this.logInfo('saveOrdersToSQLite-bulkAdd完成', {
944
1090
  count: orderList.length
945
1091
  });
946
- _context9.next = 17;
1092
+ _context11.next = 17;
947
1093
  break;
948
1094
  case 14:
949
- _context9.prev = 14;
950
- _context9.t0 = _context9["catch"](2);
1095
+ _context11.prev = 14;
1096
+ _context11.t0 = _context11["catch"](2);
951
1097
  // SQLite 异常,避免影响主流程
952
1098
  this.logError('保存订单到 SQLite 失败', {
953
- error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0),
1099
+ error: _context11.t0 instanceof Error ? _context11.t0.message : String(_context11.t0),
954
1100
  orderList: orderList.length
955
1101
  });
956
1102
  case 17:
957
1103
  case "end":
958
- return _context9.stop();
1104
+ return _context11.stop();
959
1105
  }
960
- }, _callee9, this, [[2, 14]]);
1106
+ }, _callee11, this, [[2, 14]]);
961
1107
  }));
962
1108
  function saveOrdersToSQLite(_x5) {
963
1109
  return _saveOrdersToSQLite.apply(this, arguments);
@@ -967,27 +1113,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
967
1113
  }, {
968
1114
  key: "clear",
969
1115
  value: function () {
970
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
971
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
972
- while (1) switch (_context10.prev = _context10.next) {
1116
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1117
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1118
+ while (1) switch (_context12.prev = _context12.next) {
973
1119
  case 0:
974
1120
  this.store.list = [];
975
1121
  this.store.map = new Map();
976
1122
  this.resourceIdIndex.clear();
977
1123
  if (!this.dbManager) {
978
- _context10.next = 6;
1124
+ _context12.next = 6;
979
1125
  break;
980
1126
  }
981
- _context10.next = 6;
1127
+ _context12.next = 6;
982
1128
  return this.dbManager.clear(INDEXDB_STORE_NAME);
983
1129
  case 6:
984
1130
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
985
1131
  this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
986
1132
  case 8:
987
1133
  case "end":
988
- return _context10.stop();
1134
+ return _context12.stop();
989
1135
  }
990
- }, _callee10, this);
1136
+ }, _callee12, this);
991
1137
  }));
992
1138
  function clear() {
993
1139
  return _clear.apply(this, arguments);