@pisell/pisellos 2.2.305 → 2.2.307

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.
@@ -95,6 +95,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
95
95
  _defineProperty(_assertThisInitialized(_this), "lastRecentSqliteWriteCleanupAtMs", 0);
96
96
  /** 最近一次 SSE 全量拉取完成时间 */
97
97
  _defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
98
+ _defineProperty(_assertThisInitialized(_this), "businessDayRefreshPromise", null);
98
99
  return _this;
99
100
  }
100
101
 
@@ -1256,31 +1257,83 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1256
1257
  }
1257
1258
  return loadOrdersByServer;
1258
1259
  }()
1260
+ /**
1261
+ * 供展示屏按需补齐当前营业日的订单快照;成功标记复用全量拉取落库逻辑。
1262
+ * 拉取或落库失败时不记录已刷新,下一次调用仍可重试。
1263
+ */
1264
+ }, {
1265
+ key: "refreshOrdersForCurrentBusinessDay",
1266
+ value: (function () {
1267
+ var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1268
+ var options,
1269
+ refreshPromise,
1270
+ _args9 = arguments;
1271
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1272
+ while (1) switch (_context9.prev = _context9.next) {
1273
+ case 0:
1274
+ options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1275
+ if (!this.businessDayRefreshPromise) {
1276
+ _context9.next = 3;
1277
+ break;
1278
+ }
1279
+ return _context9.abrupt("return", this.businessDayRefreshPromise);
1280
+ case 3:
1281
+ if (!(!this.orderDataSource || !this.getCurrentShopId() || this.hasPulledOrdersToday())) {
1282
+ _context9.next = 5;
1283
+ break;
1284
+ }
1285
+ return _context9.abrupt("return");
1286
+ case 5:
1287
+ refreshPromise = this.silentRefresh({
1288
+ trigger: options.trigger || 'business_day_rollover'
1289
+ }).then(function () {
1290
+ return undefined;
1291
+ });
1292
+ this.businessDayRefreshPromise = refreshPromise;
1293
+ _context9.prev = 7;
1294
+ _context9.next = 10;
1295
+ return refreshPromise;
1296
+ case 10:
1297
+ _context9.prev = 10;
1298
+ this.businessDayRefreshPromise = null;
1299
+ return _context9.finish(10);
1300
+ case 13:
1301
+ case "end":
1302
+ return _context9.stop();
1303
+ }
1304
+ }, _callee9, this, [[7,, 10, 13]]);
1305
+ }));
1306
+ function refreshOrdersForCurrentBusinessDay() {
1307
+ return _refreshOrdersForCurrentBusinessDay.apply(this, arguments);
1308
+ }
1309
+ return refreshOrdersForCurrentBusinessDay;
1310
+ }()
1259
1311
  /**
1260
1312
  * 静默全量刷新:后台重新拉取全量 SSE 订单数据并更新本地
1261
1313
  * 拿到完整数据后一次性替换 store,触发订单变更与同步完成事件
1262
1314
  * @returns 刷新后的订单列表
1263
1315
  */
1316
+ )
1264
1317
  }, {
1265
1318
  key: "silentRefresh",
1266
1319
  value: (function () {
1267
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1320
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1268
1321
  var options,
1269
1322
  startTime,
1270
1323
  trigger,
1271
1324
  elapsedSinceFullFetch,
1272
1325
  orders,
1273
1326
  errorMessage,
1274
- _args9 = arguments;
1275
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1276
- while (1) switch (_context9.prev = _context9.next) {
1327
+ _args10 = arguments;
1328
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1329
+ while (1) switch (_context10.prev = _context10.next) {
1277
1330
  case 0:
1278
- options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1331
+ options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1279
1332
  startTime = Date.now();
1280
1333
  trigger = options.trigger || 'background';
1281
1334
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1282
1335
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1283
- _context9.next = 7;
1336
+ _context10.next = 7;
1284
1337
  break;
1285
1338
  }
1286
1339
  this.logInfo('silentRefresh 跳过全量 SSE', {
@@ -1290,28 +1343,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1290
1343
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1291
1344
  orderCount: this.store.list.length
1292
1345
  });
1293
- return _context9.abrupt("return", this.store.list);
1346
+ return _context10.abrupt("return", this.store.list);
1294
1347
  case 7:
1295
1348
  this.logInfo('silentRefresh 开始', {
1296
1349
  trigger: trigger,
1297
1350
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1298
1351
  orderCount: this.store.list.length
1299
1352
  });
1300
- _context9.prev = 8;
1353
+ _context10.prev = 8;
1301
1354
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1302
1355
  this.updateCreateStore();
1303
- _context9.next = 12;
1356
+ _context10.next = 12;
1304
1357
  return this.loadOrdersByServer({
1305
1358
  trigger: trigger
1306
1359
  });
1307
1360
  case 12:
1308
- orders = _context9.sent;
1361
+ orders = _context10.sent;
1309
1362
  this.store.list = cloneDeep(orders);
1310
1363
  this.syncOrdersMap();
1311
- _context9.next = 17;
1364
+ _context10.next = 17;
1312
1365
  return this.emitOrdersChanged([], 'silentRefresh');
1313
1366
  case 17:
1314
- _context9.next = 19;
1367
+ _context10.next = 19;
1315
1368
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1316
1369
  case 19:
1317
1370
  this.logInfo('silentRefresh 完成', {
@@ -1319,22 +1372,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1319
1372
  orderCount: orders.length,
1320
1373
  duration: "".concat(Date.now() - startTime, "ms")
1321
1374
  });
1322
- return _context9.abrupt("return", this.store.list);
1375
+ return _context10.abrupt("return", this.store.list);
1323
1376
  case 23:
1324
- _context9.prev = 23;
1325
- _context9.t0 = _context9["catch"](8);
1326
- errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1377
+ _context10.prev = 23;
1378
+ _context10.t0 = _context10["catch"](8);
1379
+ errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
1327
1380
  this.logError('silentRefresh 失败', {
1328
1381
  trigger: trigger,
1329
1382
  duration: "".concat(Date.now() - startTime, "ms"),
1330
1383
  error: errorMessage
1331
1384
  });
1332
- return _context9.abrupt("return", this.store.list);
1385
+ return _context10.abrupt("return", this.store.list);
1333
1386
  case 28:
1334
1387
  case "end":
1335
- return _context9.stop();
1388
+ return _context10.stop();
1336
1389
  }
1337
- }, _callee9, this, [[8, 23]]);
1390
+ }, _callee10, this, [[8, 23]]);
1338
1391
  }));
1339
1392
  function silentRefresh() {
1340
1393
  return _silentRefresh.apply(this, arguments);
@@ -1420,31 +1473,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1420
1473
  }, {
1421
1474
  key: "overwriteExistingOrder",
1422
1475
  value: (function () {
1423
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1476
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(fresh) {
1424
1477
  var _this8 = this;
1425
1478
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1426
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1427
- while (1) switch (_context10.prev = _context10.next) {
1479
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1480
+ while (1) switch (_context11.prev = _context11.next) {
1428
1481
  case 0:
1429
1482
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
1430
1483
  if (!(orderId === undefined || orderId === null)) {
1431
- _context10.next = 4;
1484
+ _context11.next = 4;
1432
1485
  break;
1433
1486
  }
1434
1487
  this.logError('overwriteExistingOrder-入参缺少 order_id');
1435
- return _context10.abrupt("return", {
1488
+ return _context11.abrupt("return", {
1436
1489
  overwritten: false
1437
1490
  });
1438
1491
  case 4:
1439
1492
  key = this.getIdKey(orderId);
1440
1493
  if (this.store.map.has(key)) {
1441
- _context10.next = 8;
1494
+ _context11.next = 8;
1442
1495
  break;
1443
1496
  }
1444
1497
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
1445
1498
  orderId: orderId
1446
1499
  });
1447
- return _context10.abrupt("return", {
1500
+ return _context11.abrupt("return", {
1448
1501
  overwritten: false
1449
1502
  });
1450
1503
  case 8:
@@ -1463,24 +1516,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1463
1516
  return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1464
1517
  });
1465
1518
  this.syncOrdersMap();
1466
- _context10.next = 16;
1519
+ _context11.next = 16;
1467
1520
  return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1468
1521
  case 16:
1469
1522
  this.logInfo('overwriteExistingOrder-结束', {
1470
1523
  orderId: orderId,
1471
1524
  storeOrderCountAfter: this.store.list.length
1472
1525
  });
1473
- _context10.next = 19;
1526
+ _context11.next = 19;
1474
1527
  return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1475
1528
  case 19:
1476
- return _context10.abrupt("return", {
1529
+ return _context11.abrupt("return", {
1477
1530
  overwritten: true
1478
1531
  });
1479
1532
  case 20:
1480
1533
  case "end":
1481
- return _context10.stop();
1534
+ return _context11.stop();
1482
1535
  }
1483
- }, _callee10, this);
1536
+ }, _callee11, this);
1484
1537
  }));
1485
1538
  function overwriteExistingOrder(_x7) {
1486
1539
  return _overwriteExistingOrder.apply(this, arguments);
@@ -1495,33 +1548,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1495
1548
  }, {
1496
1549
  key: "upsertOrdersFromRemote",
1497
1550
  value: (function () {
1498
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(freshOrders) {
1551
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(freshOrders) {
1499
1552
  var source,
1500
- _args11 = arguments;
1501
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1502
- while (1) switch (_context11.prev = _context11.next) {
1553
+ _args12 = arguments;
1554
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1555
+ while (1) switch (_context12.prev = _context12.next) {
1503
1556
  case 0:
1504
- source = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : 'upsertOrdersFromRemote';
1557
+ source = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : 'upsertOrdersFromRemote';
1505
1558
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
1506
- _context11.next = 4;
1559
+ _context12.next = 4;
1507
1560
  break;
1508
1561
  }
1509
1562
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {
1510
1563
  source: source
1511
1564
  });
1512
- return _context11.abrupt("return");
1565
+ return _context12.abrupt("return");
1513
1566
  case 4:
1514
1567
  this.logInfo('upsertOrdersFromRemote-开始', {
1515
1568
  count: freshOrders.length,
1516
1569
  source: source
1517
1570
  });
1518
- _context11.next = 7;
1571
+ _context12.next = 7;
1519
1572
  return this.mergeOrdersToStore(freshOrders, source);
1520
1573
  case 7:
1521
1574
  case "end":
1522
- return _context11.stop();
1575
+ return _context12.stop();
1523
1576
  }
1524
- }, _callee11, this);
1577
+ }, _callee12, this);
1525
1578
  }));
1526
1579
  function upsertOrdersFromRemote(_x8) {
1527
1580
  return _upsertOrdersFromRemote.apply(this, arguments);
@@ -1531,21 +1584,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1531
1584
  }, {
1532
1585
  key: "markOrderSyncedByExternalSaleNumber",
1533
1586
  value: function () {
1534
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1587
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
1535
1588
  var _this9 = this,
1536
1589
  _existing$external_sa,
1537
1590
  _nextOrder$order_id;
1538
1591
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1539
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1540
- while (1) switch (_context12.prev = _context12.next) {
1592
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1593
+ while (1) switch (_context13.prev = _context13.next) {
1541
1594
  case 0:
1542
1595
  externalSaleNumber = params.externalSaleNumber;
1543
1596
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1544
- _context12.next = 4;
1597
+ _context13.next = 4;
1545
1598
  break;
1546
1599
  }
1547
1600
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1548
- return _context12.abrupt("return", {
1601
+ return _context13.abrupt("return", {
1549
1602
  updated: false
1550
1603
  });
1551
1604
  case 4:
@@ -1556,13 +1609,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1556
1609
  return _this9.getIdKey(value) === key;
1557
1610
  });
1558
1611
  if (!(targetIndex < 0)) {
1559
- _context12.next = 9;
1612
+ _context13.next = 9;
1560
1613
  break;
1561
1614
  }
1562
1615
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1563
1616
  external_sale_number: externalSaleNumber
1564
1617
  });
1565
- return _context12.abrupt("return", {
1618
+ return _context13.abrupt("return", {
1566
1619
  updated: false
1567
1620
  });
1568
1621
  case 9:
@@ -1578,25 +1631,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1578
1631
  return nextOrder;
1579
1632
  });
1580
1633
  this.syncOrdersMap();
1581
- _context12.next = 16;
1634
+ _context13.next = 16;
1582
1635
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1583
1636
  case 16:
1584
1637
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1585
1638
  external_sale_number: externalSaleNumber,
1586
1639
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1587
1640
  });
1588
- _context12.next = 19;
1641
+ _context13.next = 19;
1589
1642
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1590
1643
  case 19:
1591
- return _context12.abrupt("return", {
1644
+ return _context13.abrupt("return", {
1592
1645
  updated: true,
1593
1646
  order: nextOrder
1594
1647
  });
1595
1648
  case 20:
1596
1649
  case "end":
1597
- return _context12.stop();
1650
+ return _context13.stop();
1598
1651
  }
1599
- }, _callee12, this);
1652
+ }, _callee13, this);
1600
1653
  }));
1601
1654
  function markOrderSyncedByExternalSaleNumber(_x9) {
1602
1655
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
@@ -1610,7 +1663,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1610
1663
  }, {
1611
1664
  key: "upsertPendingSyncOrders",
1612
1665
  value: (function () {
1613
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(pendingOrders) {
1666
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(pendingOrders) {
1614
1667
  var _this10 = this;
1615
1668
  var options,
1616
1669
  pendingMap,
@@ -1641,26 +1694,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1641
1694
  insertIndex,
1642
1695
  patchedOrders,
1643
1696
  previousList,
1644
- _args13 = arguments;
1645
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1646
- while (1) switch (_context13.prev = _context13.next) {
1697
+ _args14 = arguments;
1698
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1699
+ while (1) switch (_context14.prev = _context14.next) {
1647
1700
  case 0:
1648
- options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
1701
+ options = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {};
1649
1702
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1650
- _context13.next = 4;
1703
+ _context14.next = 4;
1651
1704
  break;
1652
1705
  }
1653
1706
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1654
- return _context13.abrupt("return");
1707
+ return _context14.abrupt("return");
1655
1708
  case 4:
1656
1709
  pendingMap = new Map();
1657
1710
  memoryPendingMap = new Map();
1658
1711
  _iterator7 = _createForOfIteratorHelper(pendingOrders);
1659
- _context13.prev = 7;
1712
+ _context14.prev = 7;
1660
1713
  _iterator7.s();
1661
1714
  case 9:
1662
1715
  if ((_step7 = _iterator7.n()).done) {
1663
- _context13.next = 20;
1716
+ _context14.next = 20;
1664
1717
  break;
1665
1718
  }
1666
1719
  order = _step7.value;
@@ -1671,36 +1724,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1671
1724
  });
1672
1725
  storageKey = this.getOrderStorageKey(pendingOrder);
1673
1726
  if (storageKey) {
1674
- _context13.next = 16;
1727
+ _context14.next = 16;
1675
1728
  break;
1676
1729
  }
1677
- return _context13.abrupt("continue", 18);
1730
+ return _context14.abrupt("continue", 18);
1678
1731
  case 16:
1679
1732
  pendingMap.set(storageKey, pendingOrder);
1680
1733
  memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1681
1734
  case 18:
1682
- _context13.next = 9;
1735
+ _context14.next = 9;
1683
1736
  break;
1684
1737
  case 20:
1685
- _context13.next = 25;
1738
+ _context14.next = 25;
1686
1739
  break;
1687
1740
  case 22:
1688
- _context13.prev = 22;
1689
- _context13.t0 = _context13["catch"](7);
1690
- _iterator7.e(_context13.t0);
1741
+ _context14.prev = 22;
1742
+ _context14.t0 = _context14["catch"](7);
1743
+ _iterator7.e(_context14.t0);
1691
1744
  case 25:
1692
- _context13.prev = 25;
1745
+ _context14.prev = 25;
1693
1746
  _iterator7.f();
1694
- return _context13.finish(25);
1747
+ return _context14.finish(25);
1695
1748
  case 28:
1696
1749
  if (!(pendingMap.size === 0)) {
1697
- _context13.next = 31;
1750
+ _context14.next = 31;
1698
1751
  break;
1699
1752
  }
1700
1753
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1701
1754
  count: pendingOrders.length
1702
1755
  });
1703
- return _context13.abrupt("return");
1756
+ return _context14.abrupt("return");
1704
1757
  case 31:
1705
1758
  this.logInfo('upsertPendingSyncOrders-开始', {
1706
1759
  count: pendingMap.size
@@ -1726,17 +1779,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1726
1779
  }
1727
1780
  }
1728
1781
  _iterator9 = _createForOfIteratorHelper(memoryPendingMap.entries());
1729
- _context13.prev = 37;
1782
+ _context14.prev = 37;
1730
1783
  _iterator9.s();
1731
1784
  case 39:
1732
1785
  if ((_step9 = _iterator9.n()).done) {
1733
- _context13.next = 58;
1786
+ _context14.next = 58;
1734
1787
  break;
1735
1788
  }
1736
1789
  _step9$value = _slicedToArray(_step9.value, 2), _storageKey = _step9$value[0], _pendingOrder = _step9$value[1];
1737
1790
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
1738
1791
  if (!(matchIndex >= 0)) {
1739
- _context13.next = 52;
1792
+ _context14.next = 52;
1740
1793
  break;
1741
1794
  }
1742
1795
  existingOrder = updatedList[matchIndex];
@@ -1753,55 +1806,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1753
1806
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1754
1807
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1755
1808
  mergeActions[_storageKey] = 'update';
1756
- return _context13.abrupt("continue", 56);
1809
+ return _context14.abrupt("continue", 56);
1757
1810
  case 52:
1758
1811
  insertIndex = updatedList.length;
1759
1812
  updatedList.push(_pendingOrder);
1760
1813
  this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1761
1814
  mergeActions[_storageKey] = 'insert';
1762
1815
  case 56:
1763
- _context13.next = 39;
1816
+ _context14.next = 39;
1764
1817
  break;
1765
1818
  case 58:
1766
- _context13.next = 63;
1819
+ _context14.next = 63;
1767
1820
  break;
1768
1821
  case 60:
1769
- _context13.prev = 60;
1770
- _context13.t1 = _context13["catch"](37);
1771
- _iterator9.e(_context13.t1);
1822
+ _context14.prev = 60;
1823
+ _context14.t1 = _context14["catch"](37);
1824
+ _iterator9.e(_context14.t1);
1772
1825
  case 63:
1773
- _context13.prev = 63;
1826
+ _context14.prev = 63;
1774
1827
  _iterator9.f();
1775
- return _context13.finish(63);
1828
+ return _context14.finish(63);
1776
1829
  case 66:
1777
1830
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1778
1831
  previousList = this.store.list;
1779
1832
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1780
1833
  this.syncOrdersMap();
1781
- _context13.prev = 70;
1782
- _context13.next = 73;
1834
+ _context14.prev = 70;
1835
+ _context14.next = 73;
1783
1836
  return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1784
1837
  case 73:
1785
- _context13.next = 80;
1838
+ _context14.next = 80;
1786
1839
  break;
1787
1840
  case 75:
1788
- _context13.prev = 75;
1789
- _context13.t2 = _context13["catch"](70);
1841
+ _context14.prev = 75;
1842
+ _context14.t2 = _context14["catch"](70);
1790
1843
  this.store.list = previousList;
1791
1844
  this.syncOrdersMap();
1792
- throw _context13.t2;
1845
+ throw _context14.t2;
1793
1846
  case 80:
1794
1847
  this.logInfo('upsertPendingSyncOrders-结束', {
1795
1848
  count: patchedOrders.length,
1796
1849
  storeOrderCountAfter: this.store.list.length
1797
1850
  });
1798
- _context13.next = 83;
1851
+ _context14.next = 83;
1799
1852
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1800
1853
  case 83:
1801
1854
  case "end":
1802
- return _context13.stop();
1855
+ return _context14.stop();
1803
1856
  }
1804
- }, _callee13, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1857
+ }, _callee14, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1805
1858
  }));
1806
1859
  function upsertPendingSyncOrders(_x10) {
1807
1860
  return _upsertPendingSyncOrders.apply(this, arguments);
@@ -1816,27 +1869,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1816
1869
  }, {
1817
1870
  key: "upsertLocalDraftOrders",
1818
1871
  value: (function () {
1819
- var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(draftOrders) {
1872
+ var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(draftOrders) {
1820
1873
  var _this11 = this;
1821
1874
  var draftMap, memoryDraftMap, _iterator10, _step10, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator11, _step11, key, _iterator12, _step12, _step12$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1822
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1823
- while (1) switch (_context14.prev = _context14.next) {
1875
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1876
+ while (1) switch (_context15.prev = _context15.next) {
1824
1877
  case 0:
1825
1878
  if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
1826
- _context14.next = 3;
1879
+ _context15.next = 3;
1827
1880
  break;
1828
1881
  }
1829
1882
  this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
1830
- return _context14.abrupt("return");
1883
+ return _context15.abrupt("return");
1831
1884
  case 3:
1832
1885
  draftMap = new Map();
1833
1886
  memoryDraftMap = new Map();
1834
1887
  _iterator10 = _createForOfIteratorHelper(draftOrders);
1835
- _context14.prev = 6;
1888
+ _context15.prev = 6;
1836
1889
  _iterator10.s();
1837
1890
  case 8:
1838
1891
  if ((_step10 = _iterator10.n()).done) {
1839
- _context14.next = 19;
1892
+ _context15.next = 19;
1840
1893
  break;
1841
1894
  }
1842
1895
  order = _step10.value;
@@ -1846,10 +1899,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1846
1899
  });
1847
1900
  storageKey = this.getOrderStorageKey(draftOrder);
1848
1901
  if (storageKey) {
1849
- _context14.next = 14;
1902
+ _context15.next = 14;
1850
1903
  break;
1851
1904
  }
1852
- return _context14.abrupt("continue", 17);
1905
+ return _context15.abrupt("continue", 17);
1853
1906
  case 14:
1854
1907
  draftMap.set(storageKey, draftOrder);
1855
1908
  memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
@@ -1857,28 +1910,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1857
1910
  memoryDraftMap.set(storageKey, memoryDraftOrder);
1858
1911
  }
1859
1912
  case 17:
1860
- _context14.next = 8;
1913
+ _context15.next = 8;
1861
1914
  break;
1862
1915
  case 19:
1863
- _context14.next = 24;
1916
+ _context15.next = 24;
1864
1917
  break;
1865
1918
  case 21:
1866
- _context14.prev = 21;
1867
- _context14.t0 = _context14["catch"](6);
1868
- _iterator10.e(_context14.t0);
1919
+ _context15.prev = 21;
1920
+ _context15.t0 = _context15["catch"](6);
1921
+ _iterator10.e(_context15.t0);
1869
1922
  case 24:
1870
- _context14.prev = 24;
1923
+ _context15.prev = 24;
1871
1924
  _iterator10.f();
1872
- return _context14.finish(24);
1925
+ return _context15.finish(24);
1873
1926
  case 27:
1874
1927
  if (!(draftMap.size === 0)) {
1875
- _context14.next = 30;
1928
+ _context15.next = 30;
1876
1929
  break;
1877
1930
  }
1878
1931
  this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
1879
1932
  count: draftOrders.length
1880
1933
  });
1881
- return _context14.abrupt("return");
1934
+ return _context15.abrupt("return");
1882
1935
  case 30:
1883
1936
  this.logInfo('upsertLocalDraftOrders-开始', {
1884
1937
  count: draftMap.size,
@@ -1904,17 +1957,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1904
1957
  }
1905
1958
  }
1906
1959
  _iterator12 = _createForOfIteratorHelper(memoryDraftMap.entries());
1907
- _context14.prev = 36;
1960
+ _context15.prev = 36;
1908
1961
  _iterator12.s();
1909
1962
  case 38:
1910
1963
  if ((_step12 = _iterator12.n()).done) {
1911
- _context14.next = 57;
1964
+ _context15.next = 57;
1912
1965
  break;
1913
1966
  }
1914
1967
  _step12$value = _slicedToArray(_step12.value, 2), _storageKey2 = _step12$value[0], _draftOrder = _step12$value[1];
1915
1968
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
1916
1969
  if (!(matchIndex >= 0)) {
1917
- _context14.next = 51;
1970
+ _context15.next = 51;
1918
1971
  break;
1919
1972
  }
1920
1973
  existingOrder = updatedList[matchIndex];
@@ -1929,45 +1982,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1929
1982
  draftMap.set(_storageKey2, reconciledDraftOrder);
1930
1983
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1931
1984
  mergeActions[_storageKey2] = 'update';
1932
- return _context14.abrupt("continue", 55);
1985
+ return _context15.abrupt("continue", 55);
1933
1986
  case 51:
1934
1987
  insertIndex = updatedList.length;
1935
1988
  updatedList.push(_draftOrder);
1936
1989
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1937
1990
  mergeActions[_storageKey2] = 'insert';
1938
1991
  case 55:
1939
- _context14.next = 38;
1992
+ _context15.next = 38;
1940
1993
  break;
1941
1994
  case 57:
1942
- _context14.next = 62;
1995
+ _context15.next = 62;
1943
1996
  break;
1944
1997
  case 59:
1945
- _context14.prev = 59;
1946
- _context14.t1 = _context14["catch"](36);
1947
- _iterator12.e(_context14.t1);
1998
+ _context15.prev = 59;
1999
+ _context15.t1 = _context15["catch"](36);
2000
+ _iterator12.e(_context15.t1);
1948
2001
  case 62:
1949
- _context14.prev = 62;
2002
+ _context15.prev = 62;
1950
2003
  _iterator12.f();
1951
- return _context14.finish(62);
2004
+ return _context15.finish(62);
1952
2005
  case 65:
1953
2006
  patchedOrders = _toConsumableArray(draftMap.values());
1954
2007
  previousList = this.store.list;
1955
2008
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
1956
2009
  this.syncOrdersMap();
1957
- _context14.prev = 69;
1958
- _context14.next = 72;
2010
+ _context15.prev = 69;
2011
+ _context15.next = 72;
1959
2012
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
1960
2013
  throwOnError: true
1961
2014
  });
1962
2015
  case 72:
1963
- _context14.next = 79;
2016
+ _context15.next = 79;
1964
2017
  break;
1965
2018
  case 74:
1966
- _context14.prev = 74;
1967
- _context14.t2 = _context14["catch"](69);
2019
+ _context15.prev = 74;
2020
+ _context15.t2 = _context15["catch"](69);
1968
2021
  this.store.list = previousList;
1969
2022
  this.syncOrdersMap();
1970
- throw _context14.t2;
2023
+ throw _context15.t2;
1971
2024
  case 79:
1972
2025
  this.logInfo('upsertLocalDraftOrders-结束', {
1973
2026
  count: patchedOrders.length,
@@ -1977,18 +2030,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1977
2030
  return !_this11.shouldKeepOrderInMemory(order);
1978
2031
  });
1979
2032
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
1980
- _context14.next = 84;
2033
+ _context15.next = 84;
1981
2034
  break;
1982
2035
  }
1983
- _context14.next = 84;
2036
+ _context15.next = 84;
1984
2037
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
1985
2038
  return _this11.shouldKeepOrderInMemory(order);
1986
2039
  }), 'upsertLocalDraftOrders');
1987
2040
  case 84:
1988
2041
  case "end":
1989
- return _context14.stop();
2042
+ return _context15.stop();
1990
2043
  }
1991
- }, _callee14, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2044
+ }, _callee15, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
1992
2045
  }));
1993
2046
  function upsertLocalDraftOrders(_x11) {
1994
2047
  return _upsertLocalDraftOrders.apply(this, arguments);
@@ -2002,42 +2055,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2002
2055
  }, {
2003
2056
  key: "fetchOrdersBySSE",
2004
2057
  value: (function () {
2005
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
2058
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2006
2059
  var query,
2007
2060
  data,
2008
- _args15 = arguments;
2009
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
2010
- while (1) switch (_context15.prev = _context15.next) {
2061
+ _args16 = arguments;
2062
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2063
+ while (1) switch (_context16.prev = _context16.next) {
2011
2064
  case 0:
2012
- query = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
2065
+ query = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {};
2013
2066
  if (this.orderDataSource) {
2014
- _context15.next = 3;
2067
+ _context16.next = 3;
2015
2068
  break;
2016
2069
  }
2017
- return _context15.abrupt("return", []);
2070
+ return _context16.abrupt("return", []);
2018
2071
  case 3:
2019
- _context15.prev = 3;
2020
- _context15.next = 6;
2072
+ _context16.prev = 3;
2073
+ _context16.next = 6;
2021
2074
  return this.orderDataSource.run({
2022
2075
  sse: {
2023
2076
  query: query
2024
2077
  }
2025
2078
  });
2026
2079
  case 6:
2027
- data = _context15.sent;
2028
- return _context15.abrupt("return", data || []);
2080
+ data = _context16.sent;
2081
+ return _context16.abrupt("return", data || []);
2029
2082
  case 10:
2030
- _context15.prev = 10;
2031
- _context15.t0 = _context15["catch"](3);
2083
+ _context16.prev = 10;
2084
+ _context16.t0 = _context16["catch"](3);
2032
2085
  this.logError('fetchOrdersBySSE-失败', {
2033
- error: _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0)
2086
+ error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0)
2034
2087
  });
2035
- return _context15.abrupt("return", []);
2088
+ return _context16.abrupt("return", []);
2036
2089
  case 14:
2037
2090
  case "end":
2038
- return _context15.stop();
2091
+ return _context16.stop();
2039
2092
  }
2040
- }, _callee15, this, [[3, 10]]);
2093
+ }, _callee16, this, [[3, 10]]);
2041
2094
  }));
2042
2095
  function fetchOrdersBySSE() {
2043
2096
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -2274,41 +2327,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2274
2327
  }, {
2275
2328
  key: "flushOrderSyncMessagesByThrottle",
2276
2329
  value: (function () {
2277
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2278
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2279
- while (1) switch (_context16.prev = _context16.next) {
2330
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2331
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2332
+ while (1) switch (_context17.prev = _context17.next) {
2280
2333
  case 0:
2281
2334
  if (!this.isProcessingSyncBatch) {
2282
- _context16.next = 2;
2335
+ _context17.next = 2;
2283
2336
  break;
2284
2337
  }
2285
- return _context16.abrupt("return");
2338
+ return _context17.abrupt("return");
2286
2339
  case 2:
2287
2340
  if (!(this.pendingSyncMessages.length === 0)) {
2288
- _context16.next = 5;
2341
+ _context17.next = 5;
2289
2342
  break;
2290
2343
  }
2291
2344
  this.isIdlePhase = true;
2292
- return _context16.abrupt("return");
2345
+ return _context17.abrupt("return");
2293
2346
  case 5:
2294
2347
  this.isProcessingSyncBatch = true;
2295
- _context16.prev = 6;
2296
- _context16.next = 9;
2348
+ _context17.prev = 6;
2349
+ _context17.next = 9;
2297
2350
  return this.processOrderSyncMessages();
2298
2351
  case 9:
2299
- _context16.prev = 9;
2352
+ _context17.prev = 9;
2300
2353
  this.isProcessingSyncBatch = false;
2301
2354
  if (this.pendingSyncMessages.length > 0) {
2302
2355
  this.scheduleOrderSyncThrottle();
2303
2356
  } else {
2304
2357
  this.isIdlePhase = true;
2305
2358
  }
2306
- return _context16.finish(9);
2359
+ return _context17.finish(9);
2307
2360
  case 13:
2308
2361
  case "end":
2309
- return _context16.stop();
2362
+ return _context17.stop();
2310
2363
  }
2311
- }, _callee16, this, [[6,, 9, 13]]);
2364
+ }, _callee17, this, [[6,, 9, 13]]);
2312
2365
  }));
2313
2366
  function flushOrderSyncMessagesByThrottle() {
2314
2367
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -2330,19 +2383,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2330
2383
  }, {
2331
2384
  key: "processOrderSyncMessages",
2332
2385
  value: (function () {
2333
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2386
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2334
2387
  var _this16 = this;
2335
2388
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2336
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2337
- while (1) switch (_context17.prev = _context17.next) {
2389
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2390
+ while (1) switch (_context18.prev = _context18.next) {
2338
2391
  case 0:
2339
2392
  messages = _toConsumableArray(this.pendingSyncMessages);
2340
2393
  this.pendingSyncMessages = [];
2341
2394
  if (!(messages.length === 0)) {
2342
- _context17.next = 4;
2395
+ _context18.next = 4;
2343
2396
  break;
2344
2397
  }
2345
- return _context17.abrupt("return");
2398
+ return _context18.abrupt("return");
2346
2399
  case 4:
2347
2400
  batchProcessStartAt = Date.now();
2348
2401
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -2376,41 +2429,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2376
2429
  refreshIdCount: uniqueRefreshIds.length
2377
2430
  });
2378
2431
  if (!(upsertList.length > 0)) {
2379
- _context17.next = 16;
2432
+ _context18.next = 16;
2380
2433
  break;
2381
2434
  }
2382
- _context17.next = 16;
2435
+ _context18.next = 16;
2383
2436
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
2384
2437
  case 16:
2385
2438
  if (!(uniqueRefreshIds.length > 0)) {
2386
- _context17.next = 28;
2439
+ _context18.next = 28;
2387
2440
  break;
2388
2441
  }
2389
2442
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
2390
2443
  if (skipped.length > 0) {}
2391
2444
  if (!(toFetch.length > 0)) {
2392
- _context17.next = 28;
2445
+ _context18.next = 28;
2393
2446
  break;
2394
2447
  }
2395
- _context17.next = 22;
2448
+ _context18.next = 22;
2396
2449
  return this.fetchOrdersByHttp(toFetch);
2397
2450
  case 22:
2398
- freshOrders = _context17.sent;
2451
+ freshOrders = _context18.sent;
2399
2452
  if (!(freshOrders.length > 0)) {
2400
- _context17.next = 28;
2453
+ _context18.next = 28;
2401
2454
  break;
2402
2455
  }
2403
- _context17.next = 26;
2456
+ _context18.next = 26;
2404
2457
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
2405
2458
  case 26:
2406
- _context17.next = 28;
2459
+ _context18.next = 28;
2407
2460
  break;
2408
2461
  case 28:
2409
2462
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
2410
- _context17.next = 30;
2463
+ _context18.next = 30;
2411
2464
  break;
2412
2465
  }
2413
- return _context17.abrupt("return");
2466
+ return _context18.abrupt("return");
2414
2467
  case 30:
2415
2468
  batchProcessEndAt = Date.now();
2416
2469
  this.logInfo('processOrderSyncMessages-结束', {
@@ -2419,13 +2472,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2419
2472
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
2420
2473
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
2421
2474
  });
2422
- _context17.next = 34;
2475
+ _context18.next = 34;
2423
2476
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
2424
2477
  case 34:
2425
2478
  case "end":
2426
- return _context17.stop();
2479
+ return _context18.stop();
2427
2480
  }
2428
- }, _callee17, this);
2481
+ }, _callee18, this);
2429
2482
  }));
2430
2483
  function processOrderSyncMessages() {
2431
2484
  return _processOrderSyncMessages.apply(this, arguments);
@@ -2446,29 +2499,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2446
2499
  }, {
2447
2500
  key: "fetchOrdersByHttp",
2448
2501
  value: (function () {
2449
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
2502
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(ids) {
2450
2503
  var _orderList, orderList;
2451
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2452
- while (1) switch (_context18.prev = _context18.next) {
2504
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2505
+ while (1) switch (_context19.prev = _context19.next) {
2453
2506
  case 0:
2454
2507
  if (!(!this.orderDataSource || ids.length === 0)) {
2455
- _context18.next = 2;
2508
+ _context19.next = 2;
2456
2509
  break;
2457
2510
  }
2458
- return _context18.abrupt("return", []);
2511
+ return _context19.abrupt("return", []);
2459
2512
  case 2:
2460
- _context18.prev = 2;
2513
+ _context19.prev = 2;
2461
2514
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
2462
- _context18.next = 8;
2515
+ _context19.next = 8;
2463
2516
  break;
2464
2517
  }
2465
- _context18.next = 6;
2518
+ _context19.next = 6;
2466
2519
  return this.orderDataSource.fetchOrdersByIds(ids);
2467
2520
  case 6:
2468
- _orderList = _context18.sent;
2469
- return _context18.abrupt("return", _orderList || []);
2521
+ _orderList = _context19.sent;
2522
+ return _context19.abrupt("return", _orderList || []);
2470
2523
  case 8:
2471
- _context18.next = 10;
2524
+ _context19.next = 10;
2472
2525
  return this.orderDataSource.run({
2473
2526
  http: {
2474
2527
  query: {
@@ -2477,17 +2530,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2477
2530
  }
2478
2531
  });
2479
2532
  case 10:
2480
- orderList = _context18.sent;
2481
- return _context18.abrupt("return", orderList || []);
2533
+ orderList = _context19.sent;
2534
+ return _context19.abrupt("return", orderList || []);
2482
2535
  case 14:
2483
- _context18.prev = 14;
2484
- _context18.t0 = _context18["catch"](2);
2485
- return _context18.abrupt("return", []);
2536
+ _context19.prev = 14;
2537
+ _context19.t0 = _context19["catch"](2);
2538
+ return _context19.abrupt("return", []);
2486
2539
  case 17:
2487
2540
  case "end":
2488
- return _context18.stop();
2541
+ return _context19.stop();
2489
2542
  }
2490
- }, _callee18, this, [[2, 14]]);
2543
+ }, _callee19, this, [[2, 14]]);
2491
2544
  }));
2492
2545
  function fetchOrdersByHttp(_x12) {
2493
2546
  return _fetchOrdersByHttp.apply(this, arguments);
@@ -2501,11 +2554,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2501
2554
  }, {
2502
2555
  key: "mergeOrdersToStore",
2503
2556
  value: (function () {
2504
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
2557
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshOrders, source) {
2505
2558
  var _this17 = this;
2506
2559
  var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator15, _step15, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, storageKeyMigrations, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator16, _step16, key, _iterator17, _step17, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, previousStorageKey, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, freshOrderId, incomingProductsAreStable, membershipChange, mergedProductsHaveStableIdentity, adjustedMatchIndex, duplicateIndexes, _iterator18, _step18, _key2, _duplicateIndex, _iterator19, _step19, duplicateIndex, _index, _iterator20, _step20, _key, nextStorageKey, _ref5, _ref6, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
2507
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2508
- while (1) switch (_context19.prev = _context19.next) {
2560
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2561
+ while (1) switch (_context20.prev = _context20.next) {
2509
2562
  case 0:
2510
2563
  storeOrderCountBefore = this.store.list.length;
2511
2564
  this.logInfo('mergeOrdersToStore-开始', {
@@ -2517,20 +2570,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2517
2570
  normalizedFreshOrders = [];
2518
2571
  incomingProductsHaveStableIdentity = new Map();
2519
2572
  _iterator15 = _createForOfIteratorHelper(freshOrders);
2520
- _context19.prev = 6;
2573
+ _context20.prev = 6;
2521
2574
  _iterator15.s();
2522
2575
  case 8:
2523
2576
  if ((_step15 = _iterator15.n()).done) {
2524
- _context19.next = 18;
2577
+ _context20.next = 18;
2525
2578
  break;
2526
2579
  }
2527
2580
  order = _step15.value;
2528
2581
  id = order === null || order === void 0 ? void 0 : order.order_id;
2529
2582
  if (!(id === undefined || id === null)) {
2530
- _context19.next = 13;
2583
+ _context20.next = 13;
2531
2584
  break;
2532
2585
  }
2533
- return _context19.abrupt("continue", 16);
2586
+ return _context20.abrupt("continue", 16);
2534
2587
  case 13:
2535
2588
  rawProducts = order.products;
2536
2589
  if (Array.isArray(rawProducts)) {
@@ -2540,19 +2593,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2540
2593
  }
2541
2594
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2542
2595
  case 16:
2543
- _context19.next = 8;
2596
+ _context20.next = 8;
2544
2597
  break;
2545
2598
  case 18:
2546
- _context19.next = 23;
2599
+ _context20.next = 23;
2547
2600
  break;
2548
2601
  case 20:
2549
- _context19.prev = 20;
2550
- _context19.t0 = _context19["catch"](6);
2551
- _iterator15.e(_context19.t0);
2602
+ _context20.prev = 20;
2603
+ _context20.t0 = _context20["catch"](6);
2604
+ _iterator15.e(_context20.t0);
2552
2605
  case 23:
2553
- _context19.prev = 23;
2606
+ _context20.prev = 23;
2554
2607
  _iterator15.f();
2555
- return _context19.finish(23);
2608
+ return _context20.finish(23);
2556
2609
  case 26:
2557
2610
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2558
2611
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
@@ -2587,11 +2640,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2587
2640
  }
2588
2641
  }
2589
2642
  _iterator17 = _createForOfIteratorHelper(uniqueFreshOrders);
2590
- _context19.prev = 38;
2643
+ _context20.prev = 38;
2591
2644
  _iterator17.s();
2592
2645
  case 40:
2593
2646
  if ((_step17 = _iterator17.n()).done) {
2594
- _context19.next = 100;
2647
+ _context20.next = 100;
2595
2648
  break;
2596
2649
  }
2597
2650
  fresh = _step17.value;
@@ -2600,13 +2653,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2600
2653
  storageKey = this.getOrderStorageKey(fresh);
2601
2654
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2602
2655
  if (!(matchIndex >= 0)) {
2603
- _context19.next = 92;
2656
+ _context20.next = 92;
2604
2657
  break;
2605
2658
  }
2606
2659
  existingOrder = updatedList[matchIndex];
2607
2660
  previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2608
2661
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2609
- _context19.next = 52;
2662
+ _context20.next = 52;
2610
2663
  break;
2611
2664
  }
2612
2665
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2619,10 +2672,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2619
2672
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2620
2673
  reason: 'protect_pending_sync_order_from_remote_echo'
2621
2674
  });
2622
- return _context19.abrupt("continue", 98);
2675
+ return _context20.abrupt("continue", 98);
2623
2676
  case 52:
2624
2677
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2625
- _context19.next = 55;
2678
+ _context20.next = 55;
2626
2679
  break;
2627
2680
  }
2628
2681
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2633,7 +2686,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2633
2686
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2634
2687
  reason: 'protect_draft_order_from_remote_echo'
2635
2688
  });
2636
- return _context19.abrupt("continue", 98);
2689
+ return _context20.abrupt("continue", 98);
2637
2690
  case 55:
2638
2691
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2639
2692
  freshOrderId = fresh.order_id;
@@ -2646,36 +2699,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2646
2699
  adjustedMatchIndex = matchIndex;
2647
2700
  duplicateIndexes = new Set();
2648
2701
  _iterator18 = _createForOfIteratorHelper(freshIdentityKeys);
2649
- _context19.prev = 64;
2702
+ _context20.prev = 64;
2650
2703
  _iterator18.s();
2651
2704
  case 66:
2652
2705
  if ((_step18 = _iterator18.n()).done) {
2653
- _context19.next = 74;
2706
+ _context20.next = 74;
2654
2707
  break;
2655
2708
  }
2656
2709
  _key2 = _step18.value;
2657
2710
  _duplicateIndex = identityKeyToIndex.get(_key2);
2658
2711
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2659
- _context19.next = 71;
2712
+ _context20.next = 71;
2660
2713
  break;
2661
2714
  }
2662
- return _context19.abrupt("continue", 72);
2715
+ return _context20.abrupt("continue", 72);
2663
2716
  case 71:
2664
2717
  duplicateIndexes.add(_duplicateIndex);
2665
2718
  case 72:
2666
- _context19.next = 66;
2719
+ _context20.next = 66;
2667
2720
  break;
2668
2721
  case 74:
2669
- _context19.next = 79;
2722
+ _context20.next = 79;
2670
2723
  break;
2671
2724
  case 76:
2672
- _context19.prev = 76;
2673
- _context19.t1 = _context19["catch"](64);
2674
- _iterator18.e(_context19.t1);
2725
+ _context20.prev = 76;
2726
+ _context20.t1 = _context20["catch"](64);
2727
+ _iterator18.e(_context20.t1);
2675
2728
  case 79:
2676
- _context19.prev = 79;
2729
+ _context20.prev = 79;
2677
2730
  _iterator18.f();
2678
- return _context19.finish(79);
2731
+ return _context20.finish(79);
2679
2732
  case 82:
2680
2733
  if (duplicateIndexes.size > 0) {
2681
2734
  _iterator19 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
@@ -2730,7 +2783,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2730
2783
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2731
2784
  patchedOrders.push(mergedOrder);
2732
2785
  if (mergeKey) mergeActions[mergeKey] = 'update';
2733
- return _context19.abrupt("continue", 98);
2786
+ return _context20.abrupt("continue", 98);
2734
2787
  case 92:
2735
2788
  insertIndex = updatedList.length;
2736
2789
  updatedList.push(fresh);
@@ -2739,19 +2792,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2739
2792
  patchedOrders.push(fresh);
2740
2793
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2741
2794
  case 98:
2742
- _context19.next = 40;
2795
+ _context20.next = 40;
2743
2796
  break;
2744
2797
  case 100:
2745
- _context19.next = 105;
2798
+ _context20.next = 105;
2746
2799
  break;
2747
2800
  case 102:
2748
- _context19.prev = 102;
2749
- _context19.t2 = _context19["catch"](38);
2750
- _iterator17.e(_context19.t2);
2801
+ _context20.prev = 102;
2802
+ _context20.t2 = _context20["catch"](38);
2803
+ _iterator17.e(_context20.t2);
2751
2804
  case 105:
2752
- _context19.prev = 105;
2805
+ _context20.prev = 105;
2753
2806
  _iterator17.f();
2754
- return _context19.finish(105);
2807
+ return _context20.finish(105);
2755
2808
  case 108:
2756
2809
  insertCount = Object.values(mergeActions).filter(function (v) {
2757
2810
  return v === 'insert';
@@ -2768,7 +2821,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2768
2821
  // 仅在自检开关开启时做一次兜底校验。
2769
2822
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2770
2823
  this.syncOrdersMap();
2771
- _context19.next = 115;
2824
+ _context20.next = 115;
2772
2825
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
2773
2826
  storageKeyMigrations: storageKeyMigrations
2774
2827
  }, forceWriteStorageKeys);
@@ -2779,16 +2832,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2779
2832
  insertCount: insertCount,
2780
2833
  updateCount: updateCount
2781
2834
  });
2782
- _context19.next = 118;
2835
+ _context20.next = 118;
2783
2836
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2784
2837
  case 118:
2785
- _context19.next = 120;
2838
+ _context20.next = 120;
2786
2839
  return this.emitOrdersChanged(patchedOrders, source);
2787
2840
  case 120:
2788
2841
  case "end":
2789
- return _context19.stop();
2842
+ return _context20.stop();
2790
2843
  }
2791
- }, _callee19, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
2844
+ }, _callee20, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
2792
2845
  }));
2793
2846
  function mergeOrdersToStore(_x13, _x14) {
2794
2847
  return _mergeOrdersToStore.apply(this, arguments);
@@ -3503,7 +3556,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3503
3556
  }, {
3504
3557
  key: "loadOrdersFromSQLite",
3505
3558
  value: function () {
3506
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
3559
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3507
3560
  var _this21 = this;
3508
3561
  var options,
3509
3562
  _options$onTiming,
@@ -3514,24 +3567,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3514
3567
  normalizeStartedAt,
3515
3568
  normalizedOrders,
3516
3569
  sqliteNormalizeMs,
3517
- _args20 = arguments;
3518
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3519
- while (1) switch (_context20.prev = _context20.next) {
3570
+ _args21 = arguments;
3571
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3572
+ while (1) switch (_context21.prev = _context21.next) {
3520
3573
  case 0:
3521
- options = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
3574
+ options = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {};
3522
3575
  if (this.dbManager) {
3523
- _context20.next = 3;
3576
+ _context21.next = 3;
3524
3577
  break;
3525
3578
  }
3526
- return _context20.abrupt("return", []);
3579
+ return _context21.abrupt("return", []);
3527
3580
  case 3:
3528
- _context20.prev = 3;
3581
+ _context21.prev = 3;
3529
3582
  loadStartedAt = performance.now();
3530
3583
  rawReadStartedAt = performance.now();
3531
- _context20.next = 8;
3584
+ _context21.next = 8;
3532
3585
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3533
3586
  case 8:
3534
- orders = _context20.sent;
3587
+ orders = _context21.sent;
3535
3588
  sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3536
3589
  normalizeStartedAt = performance.now();
3537
3590
  normalizedOrders = (orders || []).map(function (order) {
@@ -3543,22 +3596,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3543
3596
  sqliteNormalizeMs: sqliteNormalizeMs,
3544
3597
  sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3545
3598
  });
3546
- return _context20.abrupt("return", normalizedOrders);
3599
+ return _context21.abrupt("return", normalizedOrders);
3547
3600
  case 17:
3548
- _context20.prev = 17;
3549
- _context20.t0 = _context20["catch"](3);
3601
+ _context21.prev = 17;
3602
+ _context21.t0 = _context21["catch"](3);
3550
3603
  if (!options.throwOnError) {
3551
- _context20.next = 21;
3604
+ _context21.next = 21;
3552
3605
  break;
3553
3606
  }
3554
- throw _context20.t0;
3607
+ throw _context21.t0;
3555
3608
  case 21:
3556
- return _context20.abrupt("return", []);
3609
+ return _context21.abrupt("return", []);
3557
3610
  case 22:
3558
3611
  case "end":
3559
- return _context20.stop();
3612
+ return _context21.stop();
3560
3613
  }
3561
- }, _callee20, this, [[3, 17]]);
3614
+ }, _callee21, this, [[3, 17]]);
3562
3615
  }));
3563
3616
  function loadOrdersFromSQLite() {
3564
3617
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3650,10 +3703,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3650
3703
  }, {
3651
3704
  key: "runInOrderSQLiteSaveQueue",
3652
3705
  value: (function () {
3653
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(task) {
3706
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(task) {
3654
3707
  var queuedTask;
3655
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3656
- while (1) switch (_context21.prev = _context21.next) {
3708
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3709
+ while (1) switch (_context22.prev = _context22.next) {
3657
3710
  case 0:
3658
3711
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3659
3712
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3661,12 +3714,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3661
3714
  }, function () {
3662
3715
  return undefined;
3663
3716
  });
3664
- return _context21.abrupt("return", queuedTask);
3717
+ return _context22.abrupt("return", queuedTask);
3665
3718
  case 3:
3666
3719
  case "end":
3667
- return _context21.stop();
3720
+ return _context22.stop();
3668
3721
  }
3669
- }, _callee21, this);
3722
+ }, _callee22, this);
3670
3723
  }));
3671
3724
  function runInOrderSQLiteSaveQueue(_x15) {
3672
3725
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
@@ -3683,7 +3736,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3683
3736
  }, {
3684
3737
  key: "patchOrdersInSQLite",
3685
3738
  value: (function () {
3686
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
3739
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orders, source) {
3687
3740
  var _this23 = this;
3688
3741
  var mergeActions,
3689
3742
  options,
@@ -3699,30 +3752,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3699
3752
  _iterator33,
3700
3753
  _step33,
3701
3754
  migration,
3702
- _args23 = arguments;
3703
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3704
- while (1) switch (_context23.prev = _context23.next) {
3755
+ _args24 = arguments;
3756
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3757
+ while (1) switch (_context24.prev = _context24.next) {
3705
3758
  case 0:
3706
- mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
3707
- options = _args23.length > 3 && _args23[3] !== undefined ? _args23[3] : {};
3708
- forceWriteStorageKeys = _args23.length > 4 && _args23[4] !== undefined ? _args23[4] : new Set();
3759
+ mergeActions = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
3760
+ options = _args24.length > 3 && _args24[3] !== undefined ? _args24[3] : {};
3761
+ forceWriteStorageKeys = _args24.length > 4 && _args24[4] !== undefined ? _args24[4] : new Set();
3709
3762
  if (!(orders.length === 0)) {
3710
- _context23.next = 5;
3763
+ _context24.next = 5;
3711
3764
  break;
3712
3765
  }
3713
- return _context23.abrupt("return");
3766
+ return _context24.abrupt("return");
3714
3767
  case 5:
3715
3768
  if (this.dbManager) {
3716
- _context23.next = 9;
3769
+ _context24.next = 9;
3717
3770
  break;
3718
3771
  }
3719
3772
  if (!options.throwOnError) {
3720
- _context23.next = 8;
3773
+ _context24.next = 8;
3721
3774
  break;
3722
3775
  }
3723
3776
  throw new Error('订单 SQLite 数据库未初始化');
3724
3777
  case 8:
3725
- return _context23.abrupt("return");
3778
+ return _context24.abrupt("return");
3726
3779
  case 9:
3727
3780
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3728
3781
  return migration.to;
@@ -3737,72 +3790,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3737
3790
  return _this23.getOrderStorageKey(order);
3738
3791
  });
3739
3792
  if (!(ordersSnapshot.length === 0)) {
3740
- _context23.next = 13;
3793
+ _context24.next = 13;
3741
3794
  break;
3742
3795
  }
3743
- return _context23.abrupt("return");
3796
+ return _context24.abrupt("return");
3744
3797
  case 13:
3745
3798
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3746
3799
  if (!(toWrite.length === 0)) {
3747
- _context23.next = 16;
3800
+ _context24.next = 16;
3748
3801
  break;
3749
3802
  }
3750
- return _context23.abrupt("return");
3803
+ return _context24.abrupt("return");
3751
3804
  case 16:
3752
3805
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3753
3806
  if (!(compactedToWrite.length === 0)) {
3754
- _context23.next = 19;
3807
+ _context24.next = 19;
3755
3808
  break;
3756
3809
  }
3757
- return _context23.abrupt("return");
3810
+ return _context24.abrupt("return");
3758
3811
  case 19:
3759
3812
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3760
3813
  return _this23.getOrderStorageKey(order);
3761
3814
  }).filter(Boolean));
3762
3815
  storageKeyMigrations = new Map();
3763
3816
  _iterator33 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
3764
- _context23.prev = 22;
3817
+ _context24.prev = 22;
3765
3818
  _iterator33.s();
3766
3819
  case 24:
3767
3820
  if ((_step33 = _iterator33.n()).done) {
3768
- _context23.next = 33;
3821
+ _context24.next = 33;
3769
3822
  break;
3770
3823
  }
3771
3824
  migration = _step33.value;
3772
3825
  if (writtenStorageKeys.has(migration.to)) {
3773
- _context23.next = 28;
3826
+ _context24.next = 28;
3774
3827
  break;
3775
3828
  }
3776
- return _context23.abrupt("continue", 31);
3829
+ return _context24.abrupt("continue", 31);
3777
3830
  case 28:
3778
3831
  if (!writtenStorageKeys.has(migration.from)) {
3779
- _context23.next = 30;
3832
+ _context24.next = 30;
3780
3833
  break;
3781
3834
  }
3782
- return _context23.abrupt("continue", 31);
3835
+ return _context24.abrupt("continue", 31);
3783
3836
  case 30:
3784
3837
  storageKeyMigrations.set(migration.from, migration);
3785
3838
  case 31:
3786
- _context23.next = 24;
3839
+ _context24.next = 24;
3787
3840
  break;
3788
3841
  case 33:
3789
- _context23.next = 38;
3842
+ _context24.next = 38;
3790
3843
  break;
3791
3844
  case 35:
3792
- _context23.prev = 35;
3793
- _context23.t0 = _context23["catch"](22);
3794
- _iterator33.e(_context23.t0);
3845
+ _context24.prev = 35;
3846
+ _context24.t0 = _context24["catch"](22);
3847
+ _iterator33.e(_context24.t0);
3795
3848
  case 38:
3796
- _context23.prev = 38;
3849
+ _context24.prev = 38;
3797
3850
  _iterator33.f();
3798
- return _context23.finish(38);
3851
+ return _context24.finish(38);
3799
3852
  case 41:
3800
- _context23.prev = 41;
3801
- _context23.next = 44;
3802
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
3853
+ _context24.prev = 41;
3854
+ _context24.next = 44;
3855
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
3803
3856
  var writeMethod, _iterator34, _step34, order, _iterator35, _step35, migration, _iterator36, _step36, _orderRecord$ORDER_ST, _order, orderRecord;
3804
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3805
- while (1) switch (_context22.prev = _context22.next) {
3857
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3858
+ while (1) switch (_context23.prev = _context23.next) {
3806
3859
  case 0:
3807
3860
  writeMethod = 'none';
3808
3861
  _this23.logInfo('patchOrdersInSQLite-开始', {
@@ -3811,150 +3864,150 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3811
3864
  dedupedCount: skipped.length
3812
3865
  });
3813
3866
  if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3814
- _context22.next = 8;
3867
+ _context23.next = 8;
3815
3868
  break;
3816
3869
  }
3817
3870
  writeMethod = 'bulkUpdate';
3818
- _context22.next = 6;
3871
+ _context23.next = 6;
3819
3872
  return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3820
3873
  case 6:
3821
- _context22.next = 37;
3874
+ _context23.next = 37;
3822
3875
  break;
3823
3876
  case 8:
3824
3877
  if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3825
- _context22.next = 14;
3878
+ _context23.next = 14;
3826
3879
  break;
3827
3880
  }
3828
3881
  writeMethod = 'bulkAdd';
3829
- _context22.next = 12;
3882
+ _context23.next = 12;
3830
3883
  return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3831
3884
  case 12:
3832
- _context22.next = 37;
3885
+ _context23.next = 37;
3833
3886
  break;
3834
3887
  case 14:
3835
3888
  if (!(typeof _this23.dbManager.update === 'function')) {
3836
- _context22.next = 35;
3889
+ _context23.next = 35;
3837
3890
  break;
3838
3891
  }
3839
3892
  writeMethod = 'update';
3840
3893
  _iterator34 = _createForOfIteratorHelper(compactedToWrite);
3841
- _context22.prev = 17;
3894
+ _context23.prev = 17;
3842
3895
  _iterator34.s();
3843
3896
  case 19:
3844
3897
  if ((_step34 = _iterator34.n()).done) {
3845
- _context22.next = 25;
3898
+ _context23.next = 25;
3846
3899
  break;
3847
3900
  }
3848
3901
  order = _step34.value;
3849
- _context22.next = 23;
3902
+ _context23.next = 23;
3850
3903
  return _this23.dbManager.update(INDEXDB_STORE_NAME, order);
3851
3904
  case 23:
3852
- _context22.next = 19;
3905
+ _context23.next = 19;
3853
3906
  break;
3854
3907
  case 25:
3855
- _context22.next = 30;
3908
+ _context23.next = 30;
3856
3909
  break;
3857
3910
  case 27:
3858
- _context22.prev = 27;
3859
- _context22.t0 = _context22["catch"](17);
3860
- _iterator34.e(_context22.t0);
3911
+ _context23.prev = 27;
3912
+ _context23.t0 = _context23["catch"](17);
3913
+ _iterator34.e(_context23.t0);
3861
3914
  case 30:
3862
- _context22.prev = 30;
3915
+ _context23.prev = 30;
3863
3916
  _iterator34.f();
3864
- return _context22.finish(30);
3917
+ return _context23.finish(30);
3865
3918
  case 33:
3866
- _context22.next = 37;
3919
+ _context23.next = 37;
3867
3920
  break;
3868
3921
  case 35:
3869
3922
  if (!options.throwOnError) {
3870
- _context22.next = 37;
3923
+ _context23.next = 37;
3871
3924
  break;
3872
3925
  }
3873
3926
  throw new Error('订单 SQLite 数据库不支持写入');
3874
3927
  case 37:
3875
3928
  _this23.recordRecentSqliteWrite(source, compactedToWrite);
3876
3929
  if (!(writeMethod !== 'none')) {
3877
- _context22.next = 84;
3930
+ _context23.next = 84;
3878
3931
  break;
3879
3932
  }
3880
3933
  _iterator35 = _createForOfIteratorHelper(storageKeyMigrations.values());
3881
- _context22.prev = 40;
3934
+ _context23.prev = 40;
3882
3935
  _iterator35.s();
3883
3936
  case 42:
3884
3937
  if ((_step35 = _iterator35.n()).done) {
3885
- _context22.next = 76;
3938
+ _context23.next = 76;
3886
3939
  break;
3887
3940
  }
3888
3941
  migration = _step35.value;
3889
- _context22.prev = 44;
3890
- _context22.next = 47;
3942
+ _context23.prev = 44;
3943
+ _context23.next = 47;
3891
3944
  return _this23.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
3892
3945
  case 47:
3893
3946
  _this23.recentSqliteWriteByStorageKey.delete(migration.from);
3894
3947
  _iterator36 = _createForOfIteratorHelper(orders);
3895
- _context22.prev = 49;
3948
+ _context23.prev = 49;
3896
3949
  _iterator36.s();
3897
3950
  case 51:
3898
3951
  if ((_step36 = _iterator36.n()).done) {
3899
- _context22.next = 61;
3952
+ _context23.next = 61;
3900
3953
  break;
3901
3954
  }
3902
3955
  _order = _step36.value;
3903
3956
  if (!(_this23.getOrderStorageKey(_order) !== migration.to)) {
3904
- _context22.next = 55;
3957
+ _context23.next = 55;
3905
3958
  break;
3906
3959
  }
3907
- return _context22.abrupt("continue", 59);
3960
+ return _context23.abrupt("continue", 59);
3908
3961
  case 55:
3909
3962
  orderRecord = _order;
3910
3963
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
3911
- _context22.next = 58;
3964
+ _context23.next = 58;
3912
3965
  break;
3913
3966
  }
3914
- return _context22.abrupt("continue", 59);
3967
+ return _context23.abrupt("continue", 59);
3915
3968
  case 58:
3916
3969
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
3917
3970
  case 59:
3918
- _context22.next = 51;
3971
+ _context23.next = 51;
3919
3972
  break;
3920
3973
  case 61:
3921
- _context22.next = 66;
3974
+ _context23.next = 66;
3922
3975
  break;
3923
3976
  case 63:
3924
- _context22.prev = 63;
3925
- _context22.t1 = _context22["catch"](49);
3926
- _iterator36.e(_context22.t1);
3977
+ _context23.prev = 63;
3978
+ _context23.t1 = _context23["catch"](49);
3979
+ _iterator36.e(_context23.t1);
3927
3980
  case 66:
3928
- _context22.prev = 66;
3981
+ _context23.prev = 66;
3929
3982
  _iterator36.f();
3930
- return _context22.finish(66);
3983
+ return _context23.finish(66);
3931
3984
  case 69:
3932
- _context22.next = 74;
3985
+ _context23.next = 74;
3933
3986
  break;
3934
3987
  case 71:
3935
- _context22.prev = 71;
3936
- _context22.t2 = _context22["catch"](44);
3988
+ _context23.prev = 71;
3989
+ _context23.t2 = _context23["catch"](44);
3937
3990
  _this23.logError('删除订单旧 SQLite storage key 失败', {
3938
3991
  source: source,
3939
3992
  order_id: migration.orderId,
3940
3993
  oldStorageKey: migration.from,
3941
3994
  newStorageKey: migration.to,
3942
- error: _context22.t2 instanceof Error ? _context22.t2.message : String(_context22.t2)
3995
+ error: _context23.t2 instanceof Error ? _context23.t2.message : String(_context23.t2)
3943
3996
  });
3944
3997
  case 74:
3945
- _context22.next = 42;
3998
+ _context23.next = 42;
3946
3999
  break;
3947
4000
  case 76:
3948
- _context22.next = 81;
4001
+ _context23.next = 81;
3949
4002
  break;
3950
4003
  case 78:
3951
- _context22.prev = 78;
3952
- _context22.t3 = _context22["catch"](40);
3953
- _iterator35.e(_context22.t3);
4004
+ _context23.prev = 78;
4005
+ _context23.t3 = _context23["catch"](40);
4006
+ _iterator35.e(_context23.t3);
3954
4007
  case 81:
3955
- _context22.prev = 81;
4008
+ _context23.prev = 81;
3956
4009
  _iterator35.f();
3957
- return _context22.finish(81);
4010
+ return _context23.finish(81);
3958
4011
  case 84:
3959
4012
  _this23.logInfo('patchOrdersInSQLite-完成', {
3960
4013
  source: source,
@@ -3964,30 +4017,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3964
4017
  });
3965
4018
  case 85:
3966
4019
  case "end":
3967
- return _context22.stop();
4020
+ return _context23.stop();
3968
4021
  }
3969
- }, _callee22, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4022
+ }, _callee23, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
3970
4023
  })));
3971
4024
  case 44:
3972
- _context23.next = 51;
4025
+ _context24.next = 51;
3973
4026
  break;
3974
4027
  case 46:
3975
- _context23.prev = 46;
3976
- _context23.t1 = _context23["catch"](41);
4028
+ _context24.prev = 46;
4029
+ _context24.t1 = _context24["catch"](41);
3977
4030
  this.logError('增量保存订单到 SQLite 失败', {
3978
- error: _context23.t1 instanceof Error ? _context23.t1.message : String(_context23.t1),
4031
+ error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
3979
4032
  orderCount: ordersSnapshot.length
3980
4033
  });
3981
4034
  if (!options.throwOnError) {
3982
- _context23.next = 51;
4035
+ _context24.next = 51;
3983
4036
  break;
3984
4037
  }
3985
- throw _context23.t1;
4038
+ throw _context24.t1;
3986
4039
  case 51:
3987
4040
  case "end":
3988
- return _context23.stop();
4041
+ return _context24.stop();
3989
4042
  }
3990
- }, _callee23, this, [[22, 35, 38, 41], [41, 46]]);
4043
+ }, _callee24, this, [[22, 35, 38, 41], [41, 46]]);
3991
4044
  }));
3992
4045
  function patchOrdersInSQLite(_x16, _x17) {
3993
4046
  return _patchOrdersInSQLite.apply(this, arguments);
@@ -4004,48 +4057,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4004
4057
  }, {
4005
4058
  key: "updateOrderInSQLite",
4006
4059
  value: (function () {
4007
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
4060
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(order, source) {
4008
4061
  var _this24 = this;
4009
4062
  var options,
4010
4063
  orderSnapshot,
4011
4064
  _orderSnapshot$order_3,
4012
- _args25 = arguments;
4013
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4014
- while (1) switch (_context25.prev = _context25.next) {
4065
+ _args26 = arguments;
4066
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4067
+ while (1) switch (_context26.prev = _context26.next) {
4015
4068
  case 0:
4016
- options = _args25.length > 2 && _args25[2] !== undefined ? _args25[2] : {};
4069
+ options = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : {};
4017
4070
  if (this.getOrderStorageKey(order)) {
4018
- _context25.next = 5;
4071
+ _context26.next = 5;
4019
4072
  break;
4020
4073
  }
4021
4074
  if (!options.throwOnError) {
4022
- _context25.next = 4;
4075
+ _context26.next = 4;
4023
4076
  break;
4024
4077
  }
4025
4078
  throw new Error('订单缺少可用的 SQLite 存储主键');
4026
4079
  case 4:
4027
- return _context25.abrupt("return");
4080
+ return _context26.abrupt("return");
4028
4081
  case 5:
4029
4082
  if (this.dbManager) {
4030
- _context25.next = 9;
4083
+ _context26.next = 9;
4031
4084
  break;
4032
4085
  }
4033
4086
  if (!options.throwOnError) {
4034
- _context25.next = 8;
4087
+ _context26.next = 8;
4035
4088
  break;
4036
4089
  }
4037
4090
  throw new Error('订单 SQLite 数据库未初始化');
4038
4091
  case 8:
4039
- return _context25.abrupt("return");
4092
+ return _context26.abrupt("return");
4040
4093
  case 9:
4041
4094
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4042
- _context25.prev = 10;
4043
- _context25.next = 13;
4044
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
4095
+ _context26.prev = 10;
4096
+ _context26.next = 13;
4097
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4045
4098
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4046
4099
  var writeMethod;
4047
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
4048
- while (1) switch (_context24.prev = _context24.next) {
4100
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4101
+ while (1) switch (_context25.prev = _context25.next) {
4049
4102
  case 0:
4050
4103
  writeMethod = 'none';
4051
4104
  _this24.logInfo('updateOrderInSQLite-开始', {
@@ -4054,40 +4107,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4054
4107
  storageKey: _this24.getOrderStorageKey(orderSnapshot)
4055
4108
  });
4056
4109
  if (!(typeof _this24.dbManager.update === 'function')) {
4057
- _context24.next = 8;
4110
+ _context25.next = 8;
4058
4111
  break;
4059
4112
  }
4060
4113
  writeMethod = 'update';
4061
- _context24.next = 6;
4114
+ _context25.next = 6;
4062
4115
  return _this24.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4063
4116
  case 6:
4064
- _context24.next = 22;
4117
+ _context25.next = 22;
4065
4118
  break;
4066
4119
  case 8:
4067
4120
  if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4068
- _context24.next = 14;
4121
+ _context25.next = 14;
4069
4122
  break;
4070
4123
  }
4071
4124
  writeMethod = 'bulkUpdate';
4072
- _context24.next = 12;
4125
+ _context25.next = 12;
4073
4126
  return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4074
4127
  case 12:
4075
- _context24.next = 22;
4128
+ _context25.next = 22;
4076
4129
  break;
4077
4130
  case 14:
4078
4131
  if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4079
- _context24.next = 20;
4132
+ _context25.next = 20;
4080
4133
  break;
4081
4134
  }
4082
4135
  writeMethod = 'bulkAdd';
4083
- _context24.next = 18;
4136
+ _context25.next = 18;
4084
4137
  return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4085
4138
  case 18:
4086
- _context24.next = 22;
4139
+ _context25.next = 22;
4087
4140
  break;
4088
4141
  case 20:
4089
4142
  if (!options.throwOnError) {
4090
- _context24.next = 22;
4143
+ _context25.next = 22;
4091
4144
  break;
4092
4145
  }
4093
4146
  throw new Error('订单 SQLite 数据库不支持写入');
@@ -4100,30 +4153,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4100
4153
  });
4101
4154
  case 24:
4102
4155
  case "end":
4103
- return _context24.stop();
4156
+ return _context25.stop();
4104
4157
  }
4105
- }, _callee24);
4158
+ }, _callee25);
4106
4159
  })));
4107
4160
  case 13:
4108
- _context25.next = 20;
4161
+ _context26.next = 20;
4109
4162
  break;
4110
4163
  case 15:
4111
- _context25.prev = 15;
4112
- _context25.t0 = _context25["catch"](10);
4164
+ _context26.prev = 15;
4165
+ _context26.t0 = _context26["catch"](10);
4113
4166
  this.logError('单条保存订单到 SQLite 失败', {
4114
- error: _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0),
4167
+ error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
4115
4168
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4116
4169
  });
4117
4170
  if (!options.throwOnError) {
4118
- _context25.next = 20;
4171
+ _context26.next = 20;
4119
4172
  break;
4120
4173
  }
4121
- throw _context25.t0;
4174
+ throw _context26.t0;
4122
4175
  case 20:
4123
4176
  case "end":
4124
- return _context25.stop();
4177
+ return _context26.stop();
4125
4178
  }
4126
- }, _callee25, this, [[10, 15]]);
4179
+ }, _callee26, this, [[10, 15]]);
4127
4180
  }));
4128
4181
  function updateOrderInSQLite(_x18, _x19) {
4129
4182
  return _updateOrderInSQLite.apply(this, arguments);
@@ -4141,22 +4194,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4141
4194
  }, {
4142
4195
  key: "replaceOrdersSnapshotInSQLite",
4143
4196
  value: (function () {
4144
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
4197
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(orderList, source) {
4145
4198
  var _this25 = this;
4146
4199
  var protectedOrdersBeforeRemoteFetch,
4147
4200
  remoteSnapshot,
4148
4201
  mergedSnapshot,
4149
4202
  persisted,
4150
- _args27 = arguments;
4151
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4152
- while (1) switch (_context27.prev = _context27.next) {
4203
+ _args28 = arguments;
4204
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4205
+ while (1) switch (_context28.prev = _context28.next) {
4153
4206
  case 0:
4154
- protectedOrdersBeforeRemoteFetch = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : [];
4207
+ protectedOrdersBeforeRemoteFetch = _args28.length > 2 && _args28[2] !== undefined ? _args28[2] : [];
4155
4208
  if (this.dbManager) {
4156
- _context27.next = 3;
4209
+ _context28.next = 3;
4157
4210
  break;
4158
4211
  }
4159
- return _context27.abrupt("return", {
4212
+ return _context28.abrupt("return", {
4160
4213
  orders: this.compactOrderListByIdentity(orderList.map(function (order) {
4161
4214
  return _this25.normalizeRemoteSyncedOrder(order);
4162
4215
  }), "".concat(source, ".snapshotNoDb")).list,
@@ -4170,38 +4223,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4170
4223
  return _this25.normalizeRemoteSyncedOrder(order);
4171
4224
  }), "".concat(source, ".remoteSnapshot")).list;
4172
4225
  persisted = false;
4173
- _context27.prev = 6;
4174
- _context27.next = 9;
4175
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4226
+ _context28.prev = 6;
4227
+ _context28.next = 9;
4228
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4176
4229
  var existingOrders, protectedLocalOrders, _iterator37, _step37, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4177
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4178
- while (1) switch (_context26.prev = _context26.next) {
4230
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4231
+ while (1) switch (_context27.prev = _context27.next) {
4179
4232
  case 0:
4180
4233
  if (!(typeof _this25.dbManager.getAll === 'function')) {
4181
- _context26.next = 6;
4234
+ _context27.next = 6;
4182
4235
  break;
4183
4236
  }
4184
- _context26.next = 3;
4237
+ _context27.next = 3;
4185
4238
  return _this25.dbManager.getAll(INDEXDB_STORE_NAME);
4186
4239
  case 3:
4187
- _context26.t0 = _context26.sent;
4188
- _context26.next = 7;
4240
+ _context27.t0 = _context27.sent;
4241
+ _context27.next = 7;
4189
4242
  break;
4190
4243
  case 6:
4191
- _context26.t0 = [];
4244
+ _context27.t0 = [];
4192
4245
  case 7:
4193
- existingOrders = _context26.t0;
4246
+ existingOrders = _context27.t0;
4194
4247
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4195
4248
  return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4196
4249
  }).filter(function (order) {
4197
4250
  return _this25.shouldProtectLocalOrderFromRemoteSnapshot(order);
4198
4251
  });
4199
4252
  _iterator37 = _createForOfIteratorHelper(existingOrders || []);
4200
- _context26.prev = 10;
4253
+ _context27.prev = 10;
4201
4254
  _iterator37.s();
4202
4255
  case 12:
4203
4256
  if ((_step37 = _iterator37.n()).done) {
4204
- _context26.next = 23;
4257
+ _context27.next = 23;
4205
4258
  break;
4206
4259
  }
4207
4260
  rawCurrentOrder = _step37.value;
@@ -4209,7 +4262,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4209
4262
  protectedIndex = _this25.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4210
4263
  currentNeedsProtection = _this25.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4211
4264
  if (!(protectedIndex >= 0)) {
4212
- _context26.next = 20;
4265
+ _context27.next = 20;
4213
4266
  break;
4214
4267
  }
4215
4268
  if (currentNeedsProtection) {
@@ -4217,23 +4270,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4217
4270
  } else {
4218
4271
  protectedLocalOrders.splice(protectedIndex, 1);
4219
4272
  }
4220
- return _context26.abrupt("continue", 21);
4273
+ return _context27.abrupt("continue", 21);
4221
4274
  case 20:
4222
4275
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4223
4276
  case 21:
4224
- _context26.next = 12;
4277
+ _context27.next = 12;
4225
4278
  break;
4226
4279
  case 23:
4227
- _context26.next = 28;
4280
+ _context27.next = 28;
4228
4281
  break;
4229
4282
  case 25:
4230
- _context26.prev = 25;
4231
- _context26.t1 = _context26["catch"](10);
4232
- _iterator37.e(_context26.t1);
4283
+ _context27.prev = 25;
4284
+ _context27.t1 = _context27["catch"](10);
4285
+ _iterator37.e(_context27.t1);
4233
4286
  case 28:
4234
- _context26.prev = 28;
4287
+ _context27.prev = 28;
4235
4288
  _iterator37.f();
4236
- return _context26.finish(28);
4289
+ return _context27.finish(28);
4237
4290
  case 31:
4238
4291
  orderListSnapshot = _this25.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4239
4292
  mergedSnapshot = _this25.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
@@ -4258,19 +4311,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4258
4311
  });
4259
4312
  })
4260
4313
  });
4261
- _context26.next = 36;
4314
+ _context27.next = 36;
4262
4315
  return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4263
4316
  case 36:
4264
4317
  _this25.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4265
4318
  count: mergedSnapshot.length
4266
4319
  });
4267
4320
  if (!(mergedSnapshot.length === 0)) {
4268
- _context26.next = 39;
4321
+ _context27.next = 39;
4269
4322
  break;
4270
4323
  }
4271
- return _context26.abrupt("return");
4324
+ return _context27.abrupt("return");
4272
4325
  case 39:
4273
- _context26.next = 41;
4326
+ _context27.next = 41;
4274
4327
  return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4275
4328
  case 41:
4276
4329
  _this25.recordRecentSqliteWrite(source, mergedSnapshot);
@@ -4280,31 +4333,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4280
4333
  });
4281
4334
  case 43:
4282
4335
  case "end":
4283
- return _context26.stop();
4336
+ return _context27.stop();
4284
4337
  }
4285
- }, _callee26, null, [[10, 25, 28, 31]]);
4338
+ }, _callee27, null, [[10, 25, 28, 31]]);
4286
4339
  })));
4287
4340
  case 9:
4288
4341
  persisted = true;
4289
- _context27.next = 15;
4342
+ _context28.next = 15;
4290
4343
  break;
4291
4344
  case 12:
4292
- _context27.prev = 12;
4293
- _context27.t0 = _context27["catch"](6);
4345
+ _context28.prev = 12;
4346
+ _context28.t0 = _context28["catch"](6);
4294
4347
  this.logError('全量保存订单到 SQLite 失败', {
4295
- error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
4348
+ error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0),
4296
4349
  orderList: remoteSnapshot.length
4297
4350
  });
4298
4351
  case 15:
4299
- return _context27.abrupt("return", {
4352
+ return _context28.abrupt("return", {
4300
4353
  orders: mergedSnapshot,
4301
4354
  persisted: persisted
4302
4355
  });
4303
4356
  case 16:
4304
4357
  case "end":
4305
- return _context27.stop();
4358
+ return _context28.stop();
4306
4359
  }
4307
- }, _callee27, this, [[6, 12]]);
4360
+ }, _callee28, this, [[6, 12]]);
4308
4361
  }));
4309
4362
  function replaceOrdersSnapshotInSQLite(_x20, _x21) {
4310
4363
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
@@ -4321,38 +4374,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4321
4374
  }, {
4322
4375
  key: "clear",
4323
4376
  value: (function () {
4324
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4377
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4325
4378
  var _this26 = this;
4326
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4327
- while (1) switch (_context29.prev = _context29.next) {
4379
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4380
+ while (1) switch (_context30.prev = _context30.next) {
4328
4381
  case 0:
4329
4382
  this.store.list = [];
4330
4383
  this.store.map = new Map();
4331
4384
  if (!this.dbManager) {
4332
- _context29.next = 5;
4385
+ _context30.next = 5;
4333
4386
  break;
4334
4387
  }
4335
- _context29.next = 5;
4336
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4337
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4338
- while (1) switch (_context28.prev = _context28.next) {
4388
+ _context30.next = 5;
4389
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4390
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4391
+ while (1) switch (_context29.prev = _context29.next) {
4339
4392
  case 0:
4340
- _context28.next = 2;
4393
+ _context29.next = 2;
4341
4394
  return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4342
4395
  case 2:
4343
4396
  case "end":
4344
- return _context28.stop();
4397
+ return _context29.stop();
4345
4398
  }
4346
- }, _callee28);
4399
+ }, _callee29);
4347
4400
  })));
4348
4401
  case 5:
4349
4402
  this.clearOrderSnapshotMarker();
4350
4403
  this.emitOrdersChanged([], 'clear');
4351
4404
  case 7:
4352
4405
  case "end":
4353
- return _context29.stop();
4406
+ return _context30.stop();
4354
4407
  }
4355
- }, _callee29, this);
4408
+ }, _callee30, this);
4356
4409
  }));
4357
4410
  function clear() {
4358
4411
  return _clear.apply(this, arguments);