@pisell/pisellos 2.2.125 → 2.2.127

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.
@@ -348,48 +348,118 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
348
348
  });
349
349
  }
350
350
 
351
+ /**
352
+ * 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
353
+ * 适用于"按 order_id 主动刷新本地订单详情"的代理场景。
354
+ */
355
+ }, {
356
+ key: "overwriteExistingOrder",
357
+ value: (function () {
358
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(fresh) {
359
+ var _this4 = this;
360
+ var orderId, key;
361
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
362
+ while (1) switch (_context5.prev = _context5.next) {
363
+ case 0:
364
+ orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
365
+ if (!(orderId === undefined || orderId === null)) {
366
+ _context5.next = 4;
367
+ break;
368
+ }
369
+ this.logError('overwriteExistingOrder-入参缺少 order_id');
370
+ return _context5.abrupt("return", {
371
+ overwritten: false
372
+ });
373
+ case 4:
374
+ key = this.getIdKey(orderId);
375
+ if (this.store.map.has(key)) {
376
+ _context5.next = 8;
377
+ break;
378
+ }
379
+ this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
380
+ orderId: orderId
381
+ });
382
+ return _context5.abrupt("return", {
383
+ overwritten: false
384
+ });
385
+ case 8:
386
+ this.logInfo('overwriteExistingOrder-开始覆盖', {
387
+ orderId: orderId,
388
+ storeOrderCountBefore: this.store.list.length
389
+ });
390
+ this.store.list = this.store.list.map(function (order) {
391
+ var id = order === null || order === void 0 ? void 0 : order.order_id;
392
+ if (id === undefined || id === null) return order;
393
+ return _this4.getIdKey(id) === key ? fresh : order;
394
+ });
395
+ this.syncOrdersMap();
396
+ _context5.next = 13;
397
+ return this.saveOrdersToSQLite(this.store.list);
398
+ case 13:
399
+ this.logInfo('overwriteExistingOrder-结束', {
400
+ orderId: orderId,
401
+ storeOrderCountAfter: this.store.list.length
402
+ });
403
+ _context5.next = 16;
404
+ return this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
405
+ case 16:
406
+ return _context5.abrupt("return", {
407
+ overwritten: true
408
+ });
409
+ case 17:
410
+ case "end":
411
+ return _context5.stop();
412
+ }
413
+ }, _callee5, this);
414
+ }));
415
+ function overwriteExistingOrder(_x3) {
416
+ return _overwriteExistingOrder.apply(this, arguments);
417
+ }
418
+ return overwriteExistingOrder;
419
+ }()
351
420
  /**
352
421
  * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
353
422
  */
423
+ )
354
424
  }, {
355
425
  key: "fetchOrdersBySSE",
356
426
  value: (function () {
357
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
427
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
358
428
  var query,
359
429
  data,
360
- _args5 = arguments;
361
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
362
- while (1) switch (_context5.prev = _context5.next) {
430
+ _args6 = arguments;
431
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
432
+ while (1) switch (_context6.prev = _context6.next) {
363
433
  case 0:
364
- query = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
434
+ query = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
365
435
  if (this.orderDataSource) {
366
- _context5.next = 3;
436
+ _context6.next = 3;
367
437
  break;
368
438
  }
369
- return _context5.abrupt("return", []);
439
+ return _context6.abrupt("return", []);
370
440
  case 3:
371
- _context5.prev = 3;
372
- _context5.next = 6;
441
+ _context6.prev = 3;
442
+ _context6.next = 6;
373
443
  return this.orderDataSource.run({
374
444
  sse: {
375
445
  query: query
376
446
  }
377
447
  });
378
448
  case 6:
379
- data = _context5.sent;
380
- return _context5.abrupt("return", data || []);
449
+ data = _context6.sent;
450
+ return _context6.abrupt("return", data || []);
381
451
  case 10:
382
- _context5.prev = 10;
383
- _context5.t0 = _context5["catch"](3);
452
+ _context6.prev = 10;
453
+ _context6.t0 = _context6["catch"](3);
384
454
  this.logError('fetchOrdersBySSE-失败', {
385
- error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
455
+ error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
386
456
  });
387
- return _context5.abrupt("return", []);
457
+ return _context6.abrupt("return", []);
388
458
  case 14:
389
459
  case "end":
390
- return _context5.stop();
460
+ return _context6.stop();
391
461
  }
392
- }, _callee5, this, [[3, 10]]);
462
+ }, _callee6, this, [[3, 10]]);
393
463
  }));
394
464
  function fetchOrdersBySSE() {
395
465
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -417,7 +487,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
417
487
  }, {
418
488
  key: "syncOrdersMap",
419
489
  value: function syncOrdersMap() {
420
- var _this4 = this;
490
+ var _this5 = this;
421
491
  this.store.map.clear();
422
492
  this.resourceIdIndex.clear();
423
493
  var _iterator = _createForOfIteratorHelper(this.store.list),
@@ -427,20 +497,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
427
497
  var order = _step.value;
428
498
  var id = order.order_id;
429
499
  if (id === undefined || id === null) return 1; // continue
430
- _this4.store.map.set(_this4.getIdKey(id), order);
431
- var resourceIds = _this4.extractResourceIds(order);
500
+ _this5.store.map.set(_this5.getIdKey(id), order);
501
+ var resourceIds = _this5.extractResourceIds(order);
432
502
  var _iterator2 = _createForOfIteratorHelper(resourceIds),
433
503
  _step2;
434
504
  try {
435
505
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
436
506
  var resourceId = _step2.value;
437
507
  var key = String(resourceId);
438
- var existing = _this4.resourceIdIndex.get(key) || [];
508
+ var existing = _this5.resourceIdIndex.get(key) || [];
439
509
  if (existing.some(function (eid) {
440
- return _this4.getIdKey(eid) === _this4.getIdKey(id);
510
+ return _this5.getIdKey(eid) === _this5.getIdKey(id);
441
511
  })) continue;
442
512
  existing.push(id);
443
- _this4.resourceIdIndex.set(key, existing);
513
+ _this5.resourceIdIndex.set(key, existing);
444
514
  }
445
515
  } catch (err) {
446
516
  _iterator2.e(err);
@@ -509,7 +579,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
509
579
  }, {
510
580
  key: "setupOrderSync",
511
581
  value: function setupOrderSync() {
512
- var _this5 = this;
582
+ var _this6 = this;
513
583
  if (!this.orderDataSource) return;
514
584
  this.orderDataSource.run({
515
585
  pubsub: {
@@ -517,20 +587,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
517
587
  var _message$id, _message$order_id, _message$type;
518
588
  console.log('orderDataSource');
519
589
  var pubsubReceivedAt = Date.now();
520
- var message = _this5.normalizeOrderSyncMessage(res);
590
+ var message = _this6.normalizeOrderSyncMessage(res);
521
591
  if (!message) return;
522
592
  message._pubsubReceivedAt = pubsubReceivedAt;
523
- _this5.pendingSyncMessages.push(message);
524
- var throttleMs = _this5.getOrderSyncThrottleMs();
525
- _this5.logInfo('orderSync-收到消息并入队', {
593
+ _this6.pendingSyncMessages.push(message);
594
+ var throttleMs = _this6.getOrderSyncThrottleMs();
595
+ _this6.logInfo('orderSync-收到消息并入队', {
526
596
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
527
597
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
528
598
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
529
- pendingCount: _this5.pendingSyncMessages.length,
599
+ pendingCount: _this6.pendingSyncMessages.length,
530
600
  throttleMs: throttleMs,
531
601
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString()
532
602
  });
533
- _this5.scheduleOrderSyncThrottle();
603
+ _this6.scheduleOrderSyncThrottle();
534
604
  }
535
605
  }
536
606
  }).catch(function () {
@@ -547,7 +617,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
547
617
  }, {
548
618
  key: "scheduleOrderSyncThrottle",
549
619
  value: function scheduleOrderSyncThrottle() {
550
- var _this6 = this;
620
+ var _this7 = this;
551
621
  if (this.isProcessingSyncBatch) return;
552
622
  if (this.isIdlePhase) {
553
623
  this.isIdlePhase = false;
@@ -558,8 +628,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
558
628
  if (this.syncTimer) return;
559
629
  var throttleMs = this.getOrderSyncThrottleMs();
560
630
  this.syncTimer = setTimeout(function () {
561
- _this6.syncTimer = undefined;
562
- void _this6.flushOrderSyncMessagesByThrottle();
631
+ _this7.syncTimer = undefined;
632
+ void _this7.flushOrderSyncMessagesByThrottle();
563
633
  }, throttleMs);
564
634
  }
565
635
 
@@ -570,41 +640,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
570
640
  }, {
571
641
  key: "flushOrderSyncMessagesByThrottle",
572
642
  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) {
643
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
644
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
645
+ while (1) switch (_context7.prev = _context7.next) {
576
646
  case 0:
577
647
  if (!this.isProcessingSyncBatch) {
578
- _context6.next = 2;
648
+ _context7.next = 2;
579
649
  break;
580
650
  }
581
- return _context6.abrupt("return");
651
+ return _context7.abrupt("return");
582
652
  case 2:
583
653
  if (!(this.pendingSyncMessages.length === 0)) {
584
- _context6.next = 5;
654
+ _context7.next = 5;
585
655
  break;
586
656
  }
587
657
  this.isIdlePhase = true;
588
- return _context6.abrupt("return");
658
+ return _context7.abrupt("return");
589
659
  case 5:
590
660
  this.isProcessingSyncBatch = true;
591
- _context6.prev = 6;
592
- _context6.next = 9;
661
+ _context7.prev = 6;
662
+ _context7.next = 9;
593
663
  return this.processOrderSyncMessages();
594
664
  case 9:
595
- _context6.prev = 9;
665
+ _context7.prev = 9;
596
666
  this.isProcessingSyncBatch = false;
597
667
  if (this.pendingSyncMessages.length > 0) {
598
668
  this.scheduleOrderSyncThrottle();
599
669
  } else {
600
670
  this.isIdlePhase = true;
601
671
  }
602
- return _context6.finish(9);
672
+ return _context7.finish(9);
603
673
  case 13:
604
674
  case "end":
605
- return _context6.stop();
675
+ return _context7.stop();
606
676
  }
607
- }, _callee6, this, [[6,, 9, 13]]);
677
+ }, _callee7, this, [[6,, 9, 13]]);
608
678
  }));
609
679
  function flushOrderSyncMessagesByThrottle() {
610
680
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -626,18 +696,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
626
696
  }, {
627
697
  key: "processOrderSyncMessages",
628
698
  value: (function () {
629
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
699
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
630
700
  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) {
701
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
702
+ while (1) switch (_context8.prev = _context8.next) {
633
703
  case 0:
634
704
  messages = _toConsumableArray(this.pendingSyncMessages);
635
705
  this.pendingSyncMessages = [];
636
706
  if (!(messages.length === 0)) {
637
- _context7.next = 4;
707
+ _context8.next = 4;
638
708
  break;
639
709
  }
640
- return _context7.abrupt("return");
710
+ return _context8.abrupt("return");
641
711
  case 4:
642
712
  batchProcessStartAt = Date.now();
643
713
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -653,11 +723,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
653
723
  upsertOrders = new Map();
654
724
  refreshIds = [];
655
725
  _iterator3 = _createForOfIteratorHelper(messages);
656
- _context7.prev = 10;
726
+ _context8.prev = 10;
657
727
  _iterator3.s();
658
728
  case 12:
659
729
  if ((_step3 = _iterator3.n()).done) {
660
- _context7.next = 25;
730
+ _context8.next = 25;
661
731
  break;
662
732
  }
663
733
  msg = _step3.value;
@@ -667,27 +737,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
667
737
  rawBody = msg.body || msg.data;
668
738
  normalizedBody = this.normalizeOrderSyncPayload(rawBody);
669
739
  if (!(hasSingleId && normalizedBody)) {
670
- _context7.next = 22;
740
+ _context8.next = 22;
671
741
  break;
672
742
  }
673
743
  upsertOrders.set(this.getIdKey(normalizedBody.order_id), normalizedBody);
674
- return _context7.abrupt("continue", 23);
744
+ return _context8.abrupt("continue", 23);
675
745
  case 22:
676
746
  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));
677
747
  case 23:
678
- _context7.next = 12;
748
+ _context8.next = 12;
679
749
  break;
680
750
  case 25:
681
- _context7.next = 30;
751
+ _context8.next = 30;
682
752
  break;
683
753
  case 27:
684
- _context7.prev = 27;
685
- _context7.t0 = _context7["catch"](10);
686
- _iterator3.e(_context7.t0);
754
+ _context8.prev = 27;
755
+ _context8.t0 = _context8["catch"](10);
756
+ _iterator3.e(_context8.t0);
687
757
  case 30:
688
- _context7.prev = 30;
758
+ _context8.prev = 30;
689
759
  _iterator3.f();
690
- return _context7.finish(30);
760
+ return _context8.finish(30);
691
761
  case 33:
692
762
  uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
693
763
  upsertList = _toConsumableArray(upsertOrders.values());
@@ -696,32 +766,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
696
766
  refreshIdCount: uniqueRefreshIds.length
697
767
  });
698
768
  if (!(upsertList.length > 0)) {
699
- _context7.next = 39;
769
+ _context8.next = 39;
700
770
  break;
701
771
  }
702
- _context7.next = 39;
772
+ _context8.next = 39;
703
773
  return this.mergeOrdersToStore(upsertList);
704
774
  case 39:
705
775
  if (!(uniqueRefreshIds.length > 0)) {
706
- _context7.next = 46;
776
+ _context8.next = 46;
707
777
  break;
708
778
  }
709
- _context7.next = 42;
779
+ _context8.next = 42;
710
780
  return this.fetchOrdersByHttp(uniqueRefreshIds);
711
781
  case 42:
712
- freshOrders = _context7.sent;
782
+ freshOrders = _context8.sent;
713
783
  if (!(freshOrders.length > 0)) {
714
- _context7.next = 46;
784
+ _context8.next = 46;
715
785
  break;
716
786
  }
717
- _context7.next = 46;
787
+ _context8.next = 46;
718
788
  return this.mergeOrdersToStore(freshOrders);
719
789
  case 46:
720
790
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
721
- _context7.next = 48;
791
+ _context8.next = 48;
722
792
  break;
723
793
  }
724
- return _context7.abrupt("return");
794
+ return _context8.abrupt("return");
725
795
  case 48:
726
796
  batchProcessEndAt = Date.now();
727
797
  this.logInfo('processOrderSyncMessages-结束', {
@@ -730,13 +800,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
730
800
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
731
801
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
732
802
  });
733
- _context7.next = 52;
803
+ _context8.next = 52;
734
804
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
735
805
  case 52:
736
806
  case "end":
737
- return _context7.stop();
807
+ return _context8.stop();
738
808
  }
739
- }, _callee7, this, [[10, 27, 30, 33]]);
809
+ }, _callee8, this, [[10, 27, 30, 33]]);
740
810
  }));
741
811
  function processOrderSyncMessages() {
742
812
  return _processOrderSyncMessages.apply(this, arguments);
@@ -750,29 +820,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
750
820
  }, {
751
821
  key: "fetchOrdersByHttp",
752
822
  value: (function () {
753
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(ids) {
823
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(ids) {
754
824
  var _orderList, orderList;
755
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
756
- while (1) switch (_context8.prev = _context8.next) {
825
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
826
+ while (1) switch (_context9.prev = _context9.next) {
757
827
  case 0:
758
828
  if (!(!this.orderDataSource || ids.length === 0)) {
759
- _context8.next = 2;
829
+ _context9.next = 2;
760
830
  break;
761
831
  }
762
- return _context8.abrupt("return", []);
832
+ return _context9.abrupt("return", []);
763
833
  case 2:
764
- _context8.prev = 2;
834
+ _context9.prev = 2;
765
835
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
766
- _context8.next = 8;
836
+ _context9.next = 8;
767
837
  break;
768
838
  }
769
- _context8.next = 6;
839
+ _context9.next = 6;
770
840
  return this.orderDataSource.fetchOrdersByIds(ids);
771
841
  case 6:
772
- _orderList = _context8.sent;
773
- return _context8.abrupt("return", _orderList || []);
842
+ _orderList = _context9.sent;
843
+ return _context9.abrupt("return", _orderList || []);
774
844
  case 8:
775
- _context8.next = 10;
845
+ _context9.next = 10;
776
846
  return this.orderDataSource.run({
777
847
  http: {
778
848
  query: {
@@ -781,19 +851,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
781
851
  }
782
852
  });
783
853
  case 10:
784
- orderList = _context8.sent;
785
- return _context8.abrupt("return", orderList || []);
854
+ orderList = _context9.sent;
855
+ return _context9.abrupt("return", orderList || []);
786
856
  case 14:
787
- _context8.prev = 14;
788
- _context8.t0 = _context8["catch"](2);
789
- return _context8.abrupt("return", []);
857
+ _context9.prev = 14;
858
+ _context9.t0 = _context9["catch"](2);
859
+ return _context9.abrupt("return", []);
790
860
  case 17:
791
861
  case "end":
792
- return _context8.stop();
862
+ return _context9.stop();
793
863
  }
794
- }, _callee8, this, [[2, 14]]);
864
+ }, _callee9, this, [[2, 14]]);
795
865
  }));
796
- function fetchOrdersByHttp(_x3) {
866
+ function fetchOrdersByHttp(_x4) {
797
867
  return _fetchOrdersByHttp.apply(this, arguments);
798
868
  }
799
869
  return fetchOrdersByHttp;
@@ -805,11 +875,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
805
875
  }, {
806
876
  key: "mergeOrdersToStore",
807
877
  value: (function () {
808
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(freshOrders) {
809
- var _this7 = this;
878
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(freshOrders) {
879
+ var _this8 = this;
810
880
  var freshMap, _iterator4, _step4, order, id, uniqueFreshCount, updatedList, _iterator5, _step5, _order;
811
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
812
- while (1) switch (_context9.prev = _context9.next) {
881
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
882
+ while (1) switch (_context10.prev = _context10.next) {
813
883
  case 0:
814
884
  this.logInfo('mergeOrdersToStore-开始', {
815
885
  freshOrderCount: freshOrders.length,
@@ -817,42 +887,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
817
887
  });
818
888
  freshMap = new Map();
819
889
  _iterator4 = _createForOfIteratorHelper(freshOrders);
820
- _context9.prev = 3;
890
+ _context10.prev = 3;
821
891
  _iterator4.s();
822
892
  case 5:
823
893
  if ((_step4 = _iterator4.n()).done) {
824
- _context9.next = 13;
894
+ _context10.next = 13;
825
895
  break;
826
896
  }
827
897
  order = _step4.value;
828
898
  id = order === null || order === void 0 ? void 0 : order.order_id;
829
899
  if (!(id === undefined || id === null)) {
830
- _context9.next = 10;
900
+ _context10.next = 10;
831
901
  break;
832
902
  }
833
- return _context9.abrupt("continue", 11);
903
+ return _context10.abrupt("continue", 11);
834
904
  case 10:
835
905
  freshMap.set(this.getIdKey(id), order);
836
906
  case 11:
837
- _context9.next = 5;
907
+ _context10.next = 5;
838
908
  break;
839
909
  case 13:
840
- _context9.next = 18;
910
+ _context10.next = 18;
841
911
  break;
842
912
  case 15:
843
- _context9.prev = 15;
844
- _context9.t0 = _context9["catch"](3);
845
- _iterator4.e(_context9.t0);
913
+ _context10.prev = 15;
914
+ _context10.t0 = _context10["catch"](3);
915
+ _iterator4.e(_context10.t0);
846
916
  case 18:
847
- _context9.prev = 18;
917
+ _context10.prev = 18;
848
918
  _iterator4.f();
849
- return _context9.finish(18);
919
+ return _context10.finish(18);
850
920
  case 21:
851
921
  uniqueFreshCount = freshMap.size;
852
922
  updatedList = this.store.list.map(function (order) {
853
923
  var id = order.order_id;
854
924
  if (id === undefined || id === null) return order;
855
- var key = _this7.getIdKey(id);
925
+ var key = _this8.getIdKey(id);
856
926
  if (!freshMap.has(key)) return order;
857
927
  var fresh = freshMap.get(key);
858
928
  freshMap.delete(key);
@@ -871,7 +941,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
871
941
  }
872
942
  this.store.list = updatedList;
873
943
  this.syncOrdersMap();
874
- _context9.next = 29;
944
+ _context10.next = 29;
875
945
  return this.saveOrdersToSQLite(this.store.list);
876
946
  case 29:
877
947
  this.logInfo('mergeOrdersToStore-结束', {
@@ -881,11 +951,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
881
951
  this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
882
952
  case 31:
883
953
  case "end":
884
- return _context9.stop();
954
+ return _context10.stop();
885
955
  }
886
- }, _callee9, this, [[3, 15, 18, 21]]);
956
+ }, _callee10, this, [[3, 15, 18, 21]]);
887
957
  }));
888
- function mergeOrdersToStore(_x4) {
958
+ function mergeOrdersToStore(_x5) {
889
959
  return _mergeOrdersToStore.apply(this, arguments);
890
960
  }
891
961
  return mergeOrdersToStore;
@@ -1022,32 +1092,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1022
1092
  }, {
1023
1093
  key: "loadOrdersFromSQLite",
1024
1094
  value: function () {
1025
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1095
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1026
1096
  var orders;
1027
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1028
- while (1) switch (_context10.prev = _context10.next) {
1097
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1098
+ while (1) switch (_context11.prev = _context11.next) {
1029
1099
  case 0:
1030
1100
  if (this.dbManager) {
1031
- _context10.next = 2;
1101
+ _context11.next = 2;
1032
1102
  break;
1033
1103
  }
1034
- return _context10.abrupt("return", []);
1104
+ return _context11.abrupt("return", []);
1035
1105
  case 2:
1036
- _context10.prev = 2;
1037
- _context10.next = 5;
1106
+ _context11.prev = 2;
1107
+ _context11.next = 5;
1038
1108
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
1039
1109
  case 5:
1040
- orders = _context10.sent;
1041
- return _context10.abrupt("return", orders || []);
1110
+ orders = _context11.sent;
1111
+ return _context11.abrupt("return", orders || []);
1042
1112
  case 9:
1043
- _context10.prev = 9;
1044
- _context10.t0 = _context10["catch"](2);
1045
- return _context10.abrupt("return", []);
1113
+ _context11.prev = 9;
1114
+ _context11.t0 = _context11["catch"](2);
1115
+ return _context11.abrupt("return", []);
1046
1116
  case 12:
1047
1117
  case "end":
1048
- return _context10.stop();
1118
+ return _context11.stop();
1049
1119
  }
1050
- }, _callee10, this, [[2, 9]]);
1120
+ }, _callee11, this, [[2, 9]]);
1051
1121
  }));
1052
1122
  function loadOrdersFromSQLite() {
1053
1123
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -1057,55 +1127,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1057
1127
  }, {
1058
1128
  key: "saveOrdersToSQLite",
1059
1129
  value: function () {
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) {
1130
+ var _saveOrdersToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderList) {
1131
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1132
+ while (1) switch (_context12.prev = _context12.next) {
1063
1133
  case 0:
1064
1134
  if (this.dbManager) {
1065
- _context11.next = 2;
1135
+ _context12.next = 2;
1066
1136
  break;
1067
1137
  }
1068
- return _context11.abrupt("return");
1138
+ return _context12.abrupt("return");
1069
1139
  case 2:
1070
- _context11.prev = 2;
1140
+ _context12.prev = 2;
1071
1141
  this.logInfo('saveOrdersToSQLite-开始', {
1072
1142
  count: orderList.length
1073
1143
  });
1074
- _context11.next = 6;
1144
+ _context12.next = 6;
1075
1145
  return this.dbManager.clear(INDEXDB_STORE_NAME);
1076
1146
  case 6:
1077
1147
  this.logInfo('saveOrdersToSQLite-clear完成', {
1078
1148
  count: orderList.length
1079
1149
  });
1080
1150
  if (!(orderList.length === 0)) {
1081
- _context11.next = 9;
1151
+ _context12.next = 9;
1082
1152
  break;
1083
1153
  }
1084
- return _context11.abrupt("return");
1154
+ return _context12.abrupt("return");
1085
1155
  case 9:
1086
- _context11.next = 11;
1156
+ _context12.next = 11;
1087
1157
  return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderList);
1088
1158
  case 11:
1089
1159
  this.logInfo('saveOrdersToSQLite-bulkAdd完成', {
1090
1160
  count: orderList.length
1091
1161
  });
1092
- _context11.next = 17;
1162
+ _context12.next = 17;
1093
1163
  break;
1094
1164
  case 14:
1095
- _context11.prev = 14;
1096
- _context11.t0 = _context11["catch"](2);
1165
+ _context12.prev = 14;
1166
+ _context12.t0 = _context12["catch"](2);
1097
1167
  // SQLite 异常,避免影响主流程
1098
1168
  this.logError('保存订单到 SQLite 失败', {
1099
- error: _context11.t0 instanceof Error ? _context11.t0.message : String(_context11.t0),
1169
+ error: _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0),
1100
1170
  orderList: orderList.length
1101
1171
  });
1102
1172
  case 17:
1103
1173
  case "end":
1104
- return _context11.stop();
1174
+ return _context12.stop();
1105
1175
  }
1106
- }, _callee11, this, [[2, 14]]);
1176
+ }, _callee12, this, [[2, 14]]);
1107
1177
  }));
1108
- function saveOrdersToSQLite(_x5) {
1178
+ function saveOrdersToSQLite(_x6) {
1109
1179
  return _saveOrdersToSQLite.apply(this, arguments);
1110
1180
  }
1111
1181
  return saveOrdersToSQLite;
@@ -1113,27 +1183,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1113
1183
  }, {
1114
1184
  key: "clear",
1115
1185
  value: function () {
1116
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1117
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1118
- while (1) switch (_context12.prev = _context12.next) {
1186
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1187
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1188
+ while (1) switch (_context13.prev = _context13.next) {
1119
1189
  case 0:
1120
1190
  this.store.list = [];
1121
1191
  this.store.map = new Map();
1122
1192
  this.resourceIdIndex.clear();
1123
1193
  if (!this.dbManager) {
1124
- _context12.next = 6;
1194
+ _context13.next = 6;
1125
1195
  break;
1126
1196
  }
1127
- _context12.next = 6;
1197
+ _context13.next = 6;
1128
1198
  return this.dbManager.clear(INDEXDB_STORE_NAME);
1129
1199
  case 6:
1130
1200
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
1131
1201
  this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
1132
1202
  case 8:
1133
1203
  case "end":
1134
- return _context12.stop();
1204
+ return _context13.stop();
1135
1205
  }
1136
- }, _callee12, this);
1206
+ }, _callee13, this);
1137
1207
  }));
1138
1208
  function clear() {
1139
1209
  return _clear.apply(this, arguments);