@pisell/pisellos 0.10.49 → 0.10.51

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.
Files changed (62) hide show
  1. package/dist/modules/Discount/types.d.ts +2 -0
  2. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  3. package/dist/modules/FulfillmentTiming/index.js +407 -0
  4. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  5. package/dist/modules/FulfillmentTiming/types.js +1 -0
  6. package/dist/modules/OpenData/types.d.ts +6 -0
  7. package/dist/modules/Order/index.d.ts +19 -1
  8. package/dist/modules/Order/index.js +362 -217
  9. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  10. package/dist/modules/Order/pickupTiming.js +53 -0
  11. package/dist/modules/Order/types.d.ts +11 -1
  12. package/dist/modules/Order/utils.d.ts +10 -0
  13. package/dist/modules/Order/utils.js +145 -85
  14. package/dist/modules/Rules/index.js +45 -26
  15. package/dist/modules/Rules/types.d.ts +4 -0
  16. package/dist/modules/index.d.ts +1 -0
  17. package/dist/modules/index.js +1 -0
  18. package/dist/server/modules/order/index.d.ts +8 -0
  19. package/dist/server/modules/order/index.js +506 -453
  20. package/dist/server/modules/order/types.d.ts +1 -0
  21. package/dist/server/utils/small-ticket.js +173 -95
  22. package/dist/solution/BaseSales/index.d.ts +23 -0
  23. package/dist/solution/BaseSales/index.js +1216 -1031
  24. package/dist/solution/BaseSales/pickupTiming.d.ts +37 -0
  25. package/dist/solution/BaseSales/pickupTiming.js +482 -0
  26. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  27. package/dist/solution/BookingByStep/index.d.ts +1 -1
  28. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  29. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -0
  30. package/dist/solution/UnifiedBookingSales/index.js +583 -531
  31. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  32. package/lib/modules/Discount/types.d.ts +2 -0
  33. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  34. package/lib/modules/FulfillmentTiming/index.js +359 -0
  35. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  36. package/lib/modules/FulfillmentTiming/types.js +5 -0
  37. package/lib/modules/OpenData/types.d.ts +6 -0
  38. package/lib/modules/Order/index.d.ts +19 -1
  39. package/lib/modules/Order/index.js +120 -7
  40. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  41. package/lib/modules/Order/pickupTiming.js +61 -0
  42. package/lib/modules/Order/types.d.ts +11 -1
  43. package/lib/modules/Order/utils.d.ts +10 -0
  44. package/lib/modules/Order/utils.js +58 -4
  45. package/lib/modules/Rules/index.js +24 -13
  46. package/lib/modules/Rules/types.d.ts +4 -0
  47. package/lib/modules/index.d.ts +1 -0
  48. package/lib/modules/index.js +11 -0
  49. package/lib/server/modules/order/index.d.ts +8 -0
  50. package/lib/server/modules/order/index.js +19 -0
  51. package/lib/server/modules/order/types.d.ts +1 -0
  52. package/lib/server/utils/small-ticket.js +93 -22
  53. package/lib/solution/BaseSales/index.d.ts +23 -0
  54. package/lib/solution/BaseSales/index.js +104 -1
  55. package/lib/solution/BaseSales/pickupTiming.d.ts +37 -0
  56. package/lib/solution/BaseSales/pickupTiming.js +222 -0
  57. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  58. package/lib/solution/BookingByStep/index.d.ts +1 -1
  59. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  60. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -0
  61. package/lib/solution/UnifiedBookingSales/index.js +20 -0
  62. package/package.json +1 -1
@@ -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);
@@ -3509,7 +3562,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3509
3562
  }, {
3510
3563
  key: "loadOrdersFromSQLite",
3511
3564
  value: function () {
3512
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
3565
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3513
3566
  var _this21 = this;
3514
3567
  var options,
3515
3568
  _options$onTiming,
@@ -3520,24 +3573,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3520
3573
  normalizeStartedAt,
3521
3574
  normalizedOrders,
3522
3575
  sqliteNormalizeMs,
3523
- _args20 = arguments;
3524
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3525
- while (1) switch (_context20.prev = _context20.next) {
3576
+ _args21 = arguments;
3577
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3578
+ while (1) switch (_context21.prev = _context21.next) {
3526
3579
  case 0:
3527
- options = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
3580
+ options = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {};
3528
3581
  if (this.dbManager) {
3529
- _context20.next = 3;
3582
+ _context21.next = 3;
3530
3583
  break;
3531
3584
  }
3532
- return _context20.abrupt("return", []);
3585
+ return _context21.abrupt("return", []);
3533
3586
  case 3:
3534
- _context20.prev = 3;
3587
+ _context21.prev = 3;
3535
3588
  loadStartedAt = performance.now();
3536
3589
  rawReadStartedAt = performance.now();
3537
- _context20.next = 8;
3590
+ _context21.next = 8;
3538
3591
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3539
3592
  case 8:
3540
- orders = _context20.sent;
3593
+ orders = _context21.sent;
3541
3594
  sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3542
3595
  normalizeStartedAt = performance.now();
3543
3596
  normalizedOrders = (orders || []).map(function (order) {
@@ -3549,22 +3602,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3549
3602
  sqliteNormalizeMs: sqliteNormalizeMs,
3550
3603
  sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3551
3604
  });
3552
- return _context20.abrupt("return", normalizedOrders);
3605
+ return _context21.abrupt("return", normalizedOrders);
3553
3606
  case 17:
3554
- _context20.prev = 17;
3555
- _context20.t0 = _context20["catch"](3);
3607
+ _context21.prev = 17;
3608
+ _context21.t0 = _context21["catch"](3);
3556
3609
  if (!options.throwOnError) {
3557
- _context20.next = 21;
3610
+ _context21.next = 21;
3558
3611
  break;
3559
3612
  }
3560
- throw _context20.t0;
3613
+ throw _context21.t0;
3561
3614
  case 21:
3562
- return _context20.abrupt("return", []);
3615
+ return _context21.abrupt("return", []);
3563
3616
  case 22:
3564
3617
  case "end":
3565
- return _context20.stop();
3618
+ return _context21.stop();
3566
3619
  }
3567
- }, _callee20, this, [[3, 17]]);
3620
+ }, _callee21, this, [[3, 17]]);
3568
3621
  }));
3569
3622
  function loadOrdersFromSQLite() {
3570
3623
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3656,10 +3709,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3656
3709
  }, {
3657
3710
  key: "runInOrderSQLiteSaveQueue",
3658
3711
  value: (function () {
3659
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(task) {
3712
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(task) {
3660
3713
  var queuedTask;
3661
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3662
- while (1) switch (_context21.prev = _context21.next) {
3714
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3715
+ while (1) switch (_context22.prev = _context22.next) {
3663
3716
  case 0:
3664
3717
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3665
3718
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3667,12 +3720,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3667
3720
  }, function () {
3668
3721
  return undefined;
3669
3722
  });
3670
- return _context21.abrupt("return", queuedTask);
3723
+ return _context22.abrupt("return", queuedTask);
3671
3724
  case 3:
3672
3725
  case "end":
3673
- return _context21.stop();
3726
+ return _context22.stop();
3674
3727
  }
3675
- }, _callee21, this);
3728
+ }, _callee22, this);
3676
3729
  }));
3677
3730
  function runInOrderSQLiteSaveQueue(_x15) {
3678
3731
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
@@ -3689,7 +3742,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3689
3742
  }, {
3690
3743
  key: "patchOrdersInSQLite",
3691
3744
  value: (function () {
3692
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
3745
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orders, source) {
3693
3746
  var _this23 = this;
3694
3747
  var mergeActions,
3695
3748
  options,
@@ -3705,30 +3758,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3705
3758
  _iterator33,
3706
3759
  _step33,
3707
3760
  migration,
3708
- _args23 = arguments;
3709
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3710
- while (1) switch (_context23.prev = _context23.next) {
3761
+ _args24 = arguments;
3762
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3763
+ while (1) switch (_context24.prev = _context24.next) {
3711
3764
  case 0:
3712
- mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
3713
- options = _args23.length > 3 && _args23[3] !== undefined ? _args23[3] : {};
3714
- forceWriteStorageKeys = _args23.length > 4 && _args23[4] !== undefined ? _args23[4] : new Set();
3765
+ mergeActions = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
3766
+ options = _args24.length > 3 && _args24[3] !== undefined ? _args24[3] : {};
3767
+ forceWriteStorageKeys = _args24.length > 4 && _args24[4] !== undefined ? _args24[4] : new Set();
3715
3768
  if (!(orders.length === 0)) {
3716
- _context23.next = 5;
3769
+ _context24.next = 5;
3717
3770
  break;
3718
3771
  }
3719
- return _context23.abrupt("return");
3772
+ return _context24.abrupt("return");
3720
3773
  case 5:
3721
3774
  if (this.dbManager) {
3722
- _context23.next = 9;
3775
+ _context24.next = 9;
3723
3776
  break;
3724
3777
  }
3725
3778
  if (!options.throwOnError) {
3726
- _context23.next = 8;
3779
+ _context24.next = 8;
3727
3780
  break;
3728
3781
  }
3729
3782
  throw new Error('订单 SQLite 数据库未初始化');
3730
3783
  case 8:
3731
- return _context23.abrupt("return");
3784
+ return _context24.abrupt("return");
3732
3785
  case 9:
3733
3786
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3734
3787
  return migration.to;
@@ -3743,72 +3796,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3743
3796
  return _this23.getOrderStorageKey(order);
3744
3797
  });
3745
3798
  if (!(ordersSnapshot.length === 0)) {
3746
- _context23.next = 13;
3799
+ _context24.next = 13;
3747
3800
  break;
3748
3801
  }
3749
- return _context23.abrupt("return");
3802
+ return _context24.abrupt("return");
3750
3803
  case 13:
3751
3804
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3752
3805
  if (!(toWrite.length === 0)) {
3753
- _context23.next = 16;
3806
+ _context24.next = 16;
3754
3807
  break;
3755
3808
  }
3756
- return _context23.abrupt("return");
3809
+ return _context24.abrupt("return");
3757
3810
  case 16:
3758
3811
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3759
3812
  if (!(compactedToWrite.length === 0)) {
3760
- _context23.next = 19;
3813
+ _context24.next = 19;
3761
3814
  break;
3762
3815
  }
3763
- return _context23.abrupt("return");
3816
+ return _context24.abrupt("return");
3764
3817
  case 19:
3765
3818
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3766
3819
  return _this23.getOrderStorageKey(order);
3767
3820
  }).filter(Boolean));
3768
3821
  storageKeyMigrations = new Map();
3769
3822
  _iterator33 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
3770
- _context23.prev = 22;
3823
+ _context24.prev = 22;
3771
3824
  _iterator33.s();
3772
3825
  case 24:
3773
3826
  if ((_step33 = _iterator33.n()).done) {
3774
- _context23.next = 33;
3827
+ _context24.next = 33;
3775
3828
  break;
3776
3829
  }
3777
3830
  migration = _step33.value;
3778
3831
  if (writtenStorageKeys.has(migration.to)) {
3779
- _context23.next = 28;
3832
+ _context24.next = 28;
3780
3833
  break;
3781
3834
  }
3782
- return _context23.abrupt("continue", 31);
3835
+ return _context24.abrupt("continue", 31);
3783
3836
  case 28:
3784
3837
  if (!writtenStorageKeys.has(migration.from)) {
3785
- _context23.next = 30;
3838
+ _context24.next = 30;
3786
3839
  break;
3787
3840
  }
3788
- return _context23.abrupt("continue", 31);
3841
+ return _context24.abrupt("continue", 31);
3789
3842
  case 30:
3790
3843
  storageKeyMigrations.set(migration.from, migration);
3791
3844
  case 31:
3792
- _context23.next = 24;
3845
+ _context24.next = 24;
3793
3846
  break;
3794
3847
  case 33:
3795
- _context23.next = 38;
3848
+ _context24.next = 38;
3796
3849
  break;
3797
3850
  case 35:
3798
- _context23.prev = 35;
3799
- _context23.t0 = _context23["catch"](22);
3800
- _iterator33.e(_context23.t0);
3851
+ _context24.prev = 35;
3852
+ _context24.t0 = _context24["catch"](22);
3853
+ _iterator33.e(_context24.t0);
3801
3854
  case 38:
3802
- _context23.prev = 38;
3855
+ _context24.prev = 38;
3803
3856
  _iterator33.f();
3804
- return _context23.finish(38);
3857
+ return _context24.finish(38);
3805
3858
  case 41:
3806
- _context23.prev = 41;
3807
- _context23.next = 44;
3808
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
3859
+ _context24.prev = 41;
3860
+ _context24.next = 44;
3861
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
3809
3862
  var writeMethod, _iterator34, _step34, order, _iterator35, _step35, migration, _iterator36, _step36, _orderRecord$ORDER_ST, _order, orderRecord;
3810
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3811
- while (1) switch (_context22.prev = _context22.next) {
3863
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3864
+ while (1) switch (_context23.prev = _context23.next) {
3812
3865
  case 0:
3813
3866
  writeMethod = 'none';
3814
3867
  _this23.logInfo('patchOrdersInSQLite-开始', {
@@ -3817,150 +3870,150 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3817
3870
  dedupedCount: skipped.length
3818
3871
  });
3819
3872
  if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3820
- _context22.next = 8;
3873
+ _context23.next = 8;
3821
3874
  break;
3822
3875
  }
3823
3876
  writeMethod = 'bulkUpdate';
3824
- _context22.next = 6;
3877
+ _context23.next = 6;
3825
3878
  return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3826
3879
  case 6:
3827
- _context22.next = 37;
3880
+ _context23.next = 37;
3828
3881
  break;
3829
3882
  case 8:
3830
3883
  if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3831
- _context22.next = 14;
3884
+ _context23.next = 14;
3832
3885
  break;
3833
3886
  }
3834
3887
  writeMethod = 'bulkAdd';
3835
- _context22.next = 12;
3888
+ _context23.next = 12;
3836
3889
  return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3837
3890
  case 12:
3838
- _context22.next = 37;
3891
+ _context23.next = 37;
3839
3892
  break;
3840
3893
  case 14:
3841
3894
  if (!(typeof _this23.dbManager.update === 'function')) {
3842
- _context22.next = 35;
3895
+ _context23.next = 35;
3843
3896
  break;
3844
3897
  }
3845
3898
  writeMethod = 'update';
3846
3899
  _iterator34 = _createForOfIteratorHelper(compactedToWrite);
3847
- _context22.prev = 17;
3900
+ _context23.prev = 17;
3848
3901
  _iterator34.s();
3849
3902
  case 19:
3850
3903
  if ((_step34 = _iterator34.n()).done) {
3851
- _context22.next = 25;
3904
+ _context23.next = 25;
3852
3905
  break;
3853
3906
  }
3854
3907
  order = _step34.value;
3855
- _context22.next = 23;
3908
+ _context23.next = 23;
3856
3909
  return _this23.dbManager.update(INDEXDB_STORE_NAME, order);
3857
3910
  case 23:
3858
- _context22.next = 19;
3911
+ _context23.next = 19;
3859
3912
  break;
3860
3913
  case 25:
3861
- _context22.next = 30;
3914
+ _context23.next = 30;
3862
3915
  break;
3863
3916
  case 27:
3864
- _context22.prev = 27;
3865
- _context22.t0 = _context22["catch"](17);
3866
- _iterator34.e(_context22.t0);
3917
+ _context23.prev = 27;
3918
+ _context23.t0 = _context23["catch"](17);
3919
+ _iterator34.e(_context23.t0);
3867
3920
  case 30:
3868
- _context22.prev = 30;
3921
+ _context23.prev = 30;
3869
3922
  _iterator34.f();
3870
- return _context22.finish(30);
3923
+ return _context23.finish(30);
3871
3924
  case 33:
3872
- _context22.next = 37;
3925
+ _context23.next = 37;
3873
3926
  break;
3874
3927
  case 35:
3875
3928
  if (!options.throwOnError) {
3876
- _context22.next = 37;
3929
+ _context23.next = 37;
3877
3930
  break;
3878
3931
  }
3879
3932
  throw new Error('订单 SQLite 数据库不支持写入');
3880
3933
  case 37:
3881
3934
  _this23.recordRecentSqliteWrite(source, compactedToWrite);
3882
3935
  if (!(writeMethod !== 'none')) {
3883
- _context22.next = 84;
3936
+ _context23.next = 84;
3884
3937
  break;
3885
3938
  }
3886
3939
  _iterator35 = _createForOfIteratorHelper(storageKeyMigrations.values());
3887
- _context22.prev = 40;
3940
+ _context23.prev = 40;
3888
3941
  _iterator35.s();
3889
3942
  case 42:
3890
3943
  if ((_step35 = _iterator35.n()).done) {
3891
- _context22.next = 76;
3944
+ _context23.next = 76;
3892
3945
  break;
3893
3946
  }
3894
3947
  migration = _step35.value;
3895
- _context22.prev = 44;
3896
- _context22.next = 47;
3948
+ _context23.prev = 44;
3949
+ _context23.next = 47;
3897
3950
  return _this23.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
3898
3951
  case 47:
3899
3952
  _this23.recentSqliteWriteByStorageKey.delete(migration.from);
3900
3953
  _iterator36 = _createForOfIteratorHelper(orders);
3901
- _context22.prev = 49;
3954
+ _context23.prev = 49;
3902
3955
  _iterator36.s();
3903
3956
  case 51:
3904
3957
  if ((_step36 = _iterator36.n()).done) {
3905
- _context22.next = 61;
3958
+ _context23.next = 61;
3906
3959
  break;
3907
3960
  }
3908
3961
  _order = _step36.value;
3909
3962
  if (!(_this23.getOrderStorageKey(_order) !== migration.to)) {
3910
- _context22.next = 55;
3963
+ _context23.next = 55;
3911
3964
  break;
3912
3965
  }
3913
- return _context22.abrupt("continue", 59);
3966
+ return _context23.abrupt("continue", 59);
3914
3967
  case 55:
3915
3968
  orderRecord = _order;
3916
3969
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
3917
- _context22.next = 58;
3970
+ _context23.next = 58;
3918
3971
  break;
3919
3972
  }
3920
- return _context22.abrupt("continue", 59);
3973
+ return _context23.abrupt("continue", 59);
3921
3974
  case 58:
3922
3975
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
3923
3976
  case 59:
3924
- _context22.next = 51;
3977
+ _context23.next = 51;
3925
3978
  break;
3926
3979
  case 61:
3927
- _context22.next = 66;
3980
+ _context23.next = 66;
3928
3981
  break;
3929
3982
  case 63:
3930
- _context22.prev = 63;
3931
- _context22.t1 = _context22["catch"](49);
3932
- _iterator36.e(_context22.t1);
3983
+ _context23.prev = 63;
3984
+ _context23.t1 = _context23["catch"](49);
3985
+ _iterator36.e(_context23.t1);
3933
3986
  case 66:
3934
- _context22.prev = 66;
3987
+ _context23.prev = 66;
3935
3988
  _iterator36.f();
3936
- return _context22.finish(66);
3989
+ return _context23.finish(66);
3937
3990
  case 69:
3938
- _context22.next = 74;
3991
+ _context23.next = 74;
3939
3992
  break;
3940
3993
  case 71:
3941
- _context22.prev = 71;
3942
- _context22.t2 = _context22["catch"](44);
3994
+ _context23.prev = 71;
3995
+ _context23.t2 = _context23["catch"](44);
3943
3996
  _this23.logError('删除订单旧 SQLite storage key 失败', {
3944
3997
  source: source,
3945
3998
  order_id: migration.orderId,
3946
3999
  oldStorageKey: migration.from,
3947
4000
  newStorageKey: migration.to,
3948
- error: _context22.t2 instanceof Error ? _context22.t2.message : String(_context22.t2)
4001
+ error: _context23.t2 instanceof Error ? _context23.t2.message : String(_context23.t2)
3949
4002
  });
3950
4003
  case 74:
3951
- _context22.next = 42;
4004
+ _context23.next = 42;
3952
4005
  break;
3953
4006
  case 76:
3954
- _context22.next = 81;
4007
+ _context23.next = 81;
3955
4008
  break;
3956
4009
  case 78:
3957
- _context22.prev = 78;
3958
- _context22.t3 = _context22["catch"](40);
3959
- _iterator35.e(_context22.t3);
4010
+ _context23.prev = 78;
4011
+ _context23.t3 = _context23["catch"](40);
4012
+ _iterator35.e(_context23.t3);
3960
4013
  case 81:
3961
- _context22.prev = 81;
4014
+ _context23.prev = 81;
3962
4015
  _iterator35.f();
3963
- return _context22.finish(81);
4016
+ return _context23.finish(81);
3964
4017
  case 84:
3965
4018
  _this23.logInfo('patchOrdersInSQLite-完成', {
3966
4019
  source: source,
@@ -3970,30 +4023,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3970
4023
  });
3971
4024
  case 85:
3972
4025
  case "end":
3973
- return _context22.stop();
4026
+ return _context23.stop();
3974
4027
  }
3975
- }, _callee22, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4028
+ }, _callee23, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
3976
4029
  })));
3977
4030
  case 44:
3978
- _context23.next = 51;
4031
+ _context24.next = 51;
3979
4032
  break;
3980
4033
  case 46:
3981
- _context23.prev = 46;
3982
- _context23.t1 = _context23["catch"](41);
4034
+ _context24.prev = 46;
4035
+ _context24.t1 = _context24["catch"](41);
3983
4036
  this.logError('增量保存订单到 SQLite 失败', {
3984
- error: _context23.t1 instanceof Error ? _context23.t1.message : String(_context23.t1),
4037
+ error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
3985
4038
  orderCount: ordersSnapshot.length
3986
4039
  });
3987
4040
  if (!options.throwOnError) {
3988
- _context23.next = 51;
4041
+ _context24.next = 51;
3989
4042
  break;
3990
4043
  }
3991
- throw _context23.t1;
4044
+ throw _context24.t1;
3992
4045
  case 51:
3993
4046
  case "end":
3994
- return _context23.stop();
4047
+ return _context24.stop();
3995
4048
  }
3996
- }, _callee23, this, [[22, 35, 38, 41], [41, 46]]);
4049
+ }, _callee24, this, [[22, 35, 38, 41], [41, 46]]);
3997
4050
  }));
3998
4051
  function patchOrdersInSQLite(_x16, _x17) {
3999
4052
  return _patchOrdersInSQLite.apply(this, arguments);
@@ -4010,48 +4063,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4010
4063
  }, {
4011
4064
  key: "updateOrderInSQLite",
4012
4065
  value: (function () {
4013
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
4066
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(order, source) {
4014
4067
  var _this24 = this;
4015
4068
  var options,
4016
4069
  orderSnapshot,
4017
4070
  _orderSnapshot$order_3,
4018
- _args25 = arguments;
4019
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4020
- while (1) switch (_context25.prev = _context25.next) {
4071
+ _args26 = arguments;
4072
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4073
+ while (1) switch (_context26.prev = _context26.next) {
4021
4074
  case 0:
4022
- options = _args25.length > 2 && _args25[2] !== undefined ? _args25[2] : {};
4075
+ options = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : {};
4023
4076
  if (this.getOrderStorageKey(order)) {
4024
- _context25.next = 5;
4077
+ _context26.next = 5;
4025
4078
  break;
4026
4079
  }
4027
4080
  if (!options.throwOnError) {
4028
- _context25.next = 4;
4081
+ _context26.next = 4;
4029
4082
  break;
4030
4083
  }
4031
4084
  throw new Error('订单缺少可用的 SQLite 存储主键');
4032
4085
  case 4:
4033
- return _context25.abrupt("return");
4086
+ return _context26.abrupt("return");
4034
4087
  case 5:
4035
4088
  if (this.dbManager) {
4036
- _context25.next = 9;
4089
+ _context26.next = 9;
4037
4090
  break;
4038
4091
  }
4039
4092
  if (!options.throwOnError) {
4040
- _context25.next = 8;
4093
+ _context26.next = 8;
4041
4094
  break;
4042
4095
  }
4043
4096
  throw new Error('订单 SQLite 数据库未初始化');
4044
4097
  case 8:
4045
- return _context25.abrupt("return");
4098
+ return _context26.abrupt("return");
4046
4099
  case 9:
4047
4100
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4048
- _context25.prev = 10;
4049
- _context25.next = 13;
4050
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
4101
+ _context26.prev = 10;
4102
+ _context26.next = 13;
4103
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4051
4104
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4052
4105
  var writeMethod;
4053
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
4054
- while (1) switch (_context24.prev = _context24.next) {
4106
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4107
+ while (1) switch (_context25.prev = _context25.next) {
4055
4108
  case 0:
4056
4109
  writeMethod = 'none';
4057
4110
  _this24.logInfo('updateOrderInSQLite-开始', {
@@ -4060,40 +4113,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4060
4113
  storageKey: _this24.getOrderStorageKey(orderSnapshot)
4061
4114
  });
4062
4115
  if (!(typeof _this24.dbManager.update === 'function')) {
4063
- _context24.next = 8;
4116
+ _context25.next = 8;
4064
4117
  break;
4065
4118
  }
4066
4119
  writeMethod = 'update';
4067
- _context24.next = 6;
4120
+ _context25.next = 6;
4068
4121
  return _this24.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4069
4122
  case 6:
4070
- _context24.next = 22;
4123
+ _context25.next = 22;
4071
4124
  break;
4072
4125
  case 8:
4073
4126
  if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4074
- _context24.next = 14;
4127
+ _context25.next = 14;
4075
4128
  break;
4076
4129
  }
4077
4130
  writeMethod = 'bulkUpdate';
4078
- _context24.next = 12;
4131
+ _context25.next = 12;
4079
4132
  return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4080
4133
  case 12:
4081
- _context24.next = 22;
4134
+ _context25.next = 22;
4082
4135
  break;
4083
4136
  case 14:
4084
4137
  if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4085
- _context24.next = 20;
4138
+ _context25.next = 20;
4086
4139
  break;
4087
4140
  }
4088
4141
  writeMethod = 'bulkAdd';
4089
- _context24.next = 18;
4142
+ _context25.next = 18;
4090
4143
  return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4091
4144
  case 18:
4092
- _context24.next = 22;
4145
+ _context25.next = 22;
4093
4146
  break;
4094
4147
  case 20:
4095
4148
  if (!options.throwOnError) {
4096
- _context24.next = 22;
4149
+ _context25.next = 22;
4097
4150
  break;
4098
4151
  }
4099
4152
  throw new Error('订单 SQLite 数据库不支持写入');
@@ -4106,30 +4159,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4106
4159
  });
4107
4160
  case 24:
4108
4161
  case "end":
4109
- return _context24.stop();
4162
+ return _context25.stop();
4110
4163
  }
4111
- }, _callee24);
4164
+ }, _callee25);
4112
4165
  })));
4113
4166
  case 13:
4114
- _context25.next = 20;
4167
+ _context26.next = 20;
4115
4168
  break;
4116
4169
  case 15:
4117
- _context25.prev = 15;
4118
- _context25.t0 = _context25["catch"](10);
4170
+ _context26.prev = 15;
4171
+ _context26.t0 = _context26["catch"](10);
4119
4172
  this.logError('单条保存订单到 SQLite 失败', {
4120
- error: _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0),
4173
+ error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
4121
4174
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4122
4175
  });
4123
4176
  if (!options.throwOnError) {
4124
- _context25.next = 20;
4177
+ _context26.next = 20;
4125
4178
  break;
4126
4179
  }
4127
- throw _context25.t0;
4180
+ throw _context26.t0;
4128
4181
  case 20:
4129
4182
  case "end":
4130
- return _context25.stop();
4183
+ return _context26.stop();
4131
4184
  }
4132
- }, _callee25, this, [[10, 15]]);
4185
+ }, _callee26, this, [[10, 15]]);
4133
4186
  }));
4134
4187
  function updateOrderInSQLite(_x18, _x19) {
4135
4188
  return _updateOrderInSQLite.apply(this, arguments);
@@ -4147,22 +4200,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4147
4200
  }, {
4148
4201
  key: "replaceOrdersSnapshotInSQLite",
4149
4202
  value: (function () {
4150
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
4203
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(orderList, source) {
4151
4204
  var _this25 = this;
4152
4205
  var protectedOrdersBeforeRemoteFetch,
4153
4206
  remoteSnapshot,
4154
4207
  mergedSnapshot,
4155
4208
  persisted,
4156
- _args27 = arguments;
4157
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4158
- while (1) switch (_context27.prev = _context27.next) {
4209
+ _args28 = arguments;
4210
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4211
+ while (1) switch (_context28.prev = _context28.next) {
4159
4212
  case 0:
4160
- protectedOrdersBeforeRemoteFetch = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : [];
4213
+ protectedOrdersBeforeRemoteFetch = _args28.length > 2 && _args28[2] !== undefined ? _args28[2] : [];
4161
4214
  if (this.dbManager) {
4162
- _context27.next = 3;
4215
+ _context28.next = 3;
4163
4216
  break;
4164
4217
  }
4165
- return _context27.abrupt("return", {
4218
+ return _context28.abrupt("return", {
4166
4219
  orders: this.compactOrderListByIdentity(orderList.map(function (order) {
4167
4220
  return _this25.normalizeRemoteSyncedOrder(order);
4168
4221
  }), "".concat(source, ".snapshotNoDb")).list,
@@ -4176,38 +4229,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4176
4229
  return _this25.normalizeRemoteSyncedOrder(order);
4177
4230
  }), "".concat(source, ".remoteSnapshot")).list;
4178
4231
  persisted = false;
4179
- _context27.prev = 6;
4180
- _context27.next = 9;
4181
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4232
+ _context28.prev = 6;
4233
+ _context28.next = 9;
4234
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4182
4235
  var existingOrders, protectedLocalOrders, _iterator37, _step37, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4183
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4184
- while (1) switch (_context26.prev = _context26.next) {
4236
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4237
+ while (1) switch (_context27.prev = _context27.next) {
4185
4238
  case 0:
4186
4239
  if (!(typeof _this25.dbManager.getAll === 'function')) {
4187
- _context26.next = 6;
4240
+ _context27.next = 6;
4188
4241
  break;
4189
4242
  }
4190
- _context26.next = 3;
4243
+ _context27.next = 3;
4191
4244
  return _this25.dbManager.getAll(INDEXDB_STORE_NAME);
4192
4245
  case 3:
4193
- _context26.t0 = _context26.sent;
4194
- _context26.next = 7;
4246
+ _context27.t0 = _context27.sent;
4247
+ _context27.next = 7;
4195
4248
  break;
4196
4249
  case 6:
4197
- _context26.t0 = [];
4250
+ _context27.t0 = [];
4198
4251
  case 7:
4199
- existingOrders = _context26.t0;
4252
+ existingOrders = _context27.t0;
4200
4253
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4201
4254
  return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4202
4255
  }).filter(function (order) {
4203
4256
  return _this25.shouldProtectLocalOrderFromRemoteSnapshot(order);
4204
4257
  });
4205
4258
  _iterator37 = _createForOfIteratorHelper(existingOrders || []);
4206
- _context26.prev = 10;
4259
+ _context27.prev = 10;
4207
4260
  _iterator37.s();
4208
4261
  case 12:
4209
4262
  if ((_step37 = _iterator37.n()).done) {
4210
- _context26.next = 23;
4263
+ _context27.next = 23;
4211
4264
  break;
4212
4265
  }
4213
4266
  rawCurrentOrder = _step37.value;
@@ -4215,7 +4268,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4215
4268
  protectedIndex = _this25.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4216
4269
  currentNeedsProtection = _this25.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4217
4270
  if (!(protectedIndex >= 0)) {
4218
- _context26.next = 20;
4271
+ _context27.next = 20;
4219
4272
  break;
4220
4273
  }
4221
4274
  if (currentNeedsProtection) {
@@ -4223,23 +4276,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4223
4276
  } else {
4224
4277
  protectedLocalOrders.splice(protectedIndex, 1);
4225
4278
  }
4226
- return _context26.abrupt("continue", 21);
4279
+ return _context27.abrupt("continue", 21);
4227
4280
  case 20:
4228
4281
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4229
4282
  case 21:
4230
- _context26.next = 12;
4283
+ _context27.next = 12;
4231
4284
  break;
4232
4285
  case 23:
4233
- _context26.next = 28;
4286
+ _context27.next = 28;
4234
4287
  break;
4235
4288
  case 25:
4236
- _context26.prev = 25;
4237
- _context26.t1 = _context26["catch"](10);
4238
- _iterator37.e(_context26.t1);
4289
+ _context27.prev = 25;
4290
+ _context27.t1 = _context27["catch"](10);
4291
+ _iterator37.e(_context27.t1);
4239
4292
  case 28:
4240
- _context26.prev = 28;
4293
+ _context27.prev = 28;
4241
4294
  _iterator37.f();
4242
- return _context26.finish(28);
4295
+ return _context27.finish(28);
4243
4296
  case 31:
4244
4297
  orderListSnapshot = _this25.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4245
4298
  mergedSnapshot = _this25.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
@@ -4264,19 +4317,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4264
4317
  });
4265
4318
  })
4266
4319
  });
4267
- _context26.next = 36;
4320
+ _context27.next = 36;
4268
4321
  return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4269
4322
  case 36:
4270
4323
  _this25.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4271
4324
  count: mergedSnapshot.length
4272
4325
  });
4273
4326
  if (!(mergedSnapshot.length === 0)) {
4274
- _context26.next = 39;
4327
+ _context27.next = 39;
4275
4328
  break;
4276
4329
  }
4277
- return _context26.abrupt("return");
4330
+ return _context27.abrupt("return");
4278
4331
  case 39:
4279
- _context26.next = 41;
4332
+ _context27.next = 41;
4280
4333
  return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4281
4334
  case 41:
4282
4335
  _this25.recordRecentSqliteWrite(source, mergedSnapshot);
@@ -4286,31 +4339,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4286
4339
  });
4287
4340
  case 43:
4288
4341
  case "end":
4289
- return _context26.stop();
4342
+ return _context27.stop();
4290
4343
  }
4291
- }, _callee26, null, [[10, 25, 28, 31]]);
4344
+ }, _callee27, null, [[10, 25, 28, 31]]);
4292
4345
  })));
4293
4346
  case 9:
4294
4347
  persisted = true;
4295
- _context27.next = 15;
4348
+ _context28.next = 15;
4296
4349
  break;
4297
4350
  case 12:
4298
- _context27.prev = 12;
4299
- _context27.t0 = _context27["catch"](6);
4351
+ _context28.prev = 12;
4352
+ _context28.t0 = _context28["catch"](6);
4300
4353
  this.logError('全量保存订单到 SQLite 失败', {
4301
- error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
4354
+ error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0),
4302
4355
  orderList: remoteSnapshot.length
4303
4356
  });
4304
4357
  case 15:
4305
- return _context27.abrupt("return", {
4358
+ return _context28.abrupt("return", {
4306
4359
  orders: mergedSnapshot,
4307
4360
  persisted: persisted
4308
4361
  });
4309
4362
  case 16:
4310
4363
  case "end":
4311
- return _context27.stop();
4364
+ return _context28.stop();
4312
4365
  }
4313
- }, _callee27, this, [[6, 12]]);
4366
+ }, _callee28, this, [[6, 12]]);
4314
4367
  }));
4315
4368
  function replaceOrdersSnapshotInSQLite(_x20, _x21) {
4316
4369
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
@@ -4327,38 +4380,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4327
4380
  }, {
4328
4381
  key: "clear",
4329
4382
  value: (function () {
4330
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4383
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4331
4384
  var _this26 = this;
4332
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4333
- while (1) switch (_context29.prev = _context29.next) {
4385
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4386
+ while (1) switch (_context30.prev = _context30.next) {
4334
4387
  case 0:
4335
4388
  this.store.list = [];
4336
4389
  this.store.map = new Map();
4337
4390
  if (!this.dbManager) {
4338
- _context29.next = 5;
4391
+ _context30.next = 5;
4339
4392
  break;
4340
4393
  }
4341
- _context29.next = 5;
4342
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4343
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4344
- while (1) switch (_context28.prev = _context28.next) {
4394
+ _context30.next = 5;
4395
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4396
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4397
+ while (1) switch (_context29.prev = _context29.next) {
4345
4398
  case 0:
4346
- _context28.next = 2;
4399
+ _context29.next = 2;
4347
4400
  return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4348
4401
  case 2:
4349
4402
  case "end":
4350
- return _context28.stop();
4403
+ return _context29.stop();
4351
4404
  }
4352
- }, _callee28);
4405
+ }, _callee29);
4353
4406
  })));
4354
4407
  case 5:
4355
4408
  this.clearOrderSnapshotMarker();
4356
4409
  this.emitOrdersChanged([], 'clear');
4357
4410
  case 7:
4358
4411
  case "end":
4359
- return _context29.stop();
4412
+ return _context30.stop();
4360
4413
  }
4361
- }, _callee29, this);
4414
+ }, _callee30, this);
4362
4415
  }));
4363
4416
  function clear() {
4364
4417
  return _clear.apply(this, arguments);