@pisell/pisellos 2.3.159 → 2.3.160

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.
@@ -891,11 +891,91 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
891
891
  });
892
892
  return memoryOrder || null;
893
893
  }
894
+
895
+ /** Read-only payment gate lookup; never hydrate the whole order list on a miss. */
896
+ }, {
897
+ key: "getLocalOrderForPaymentReadiness",
898
+ value: (function () {
899
+ var _getLocalOrderForPaymentReadiness = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
900
+ var _this$dbManager,
901
+ _this4 = this;
902
+ var memoryOrder, key, fields, candidates, _i2, _fields, column, rows;
903
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
904
+ while (1) switch (_context5.prev = _context5.next) {
905
+ case 0:
906
+ if (!(lookup === undefined || lookup === null || lookup === '')) {
907
+ _context5.next = 2;
908
+ break;
909
+ }
910
+ return _context5.abrupt("return", null);
911
+ case 2:
912
+ memoryOrder = this.getLocalOrderFromMemoryByLookup(lookup);
913
+ if (!memoryOrder) {
914
+ _context5.next = 5;
915
+ break;
916
+ }
917
+ return _context5.abrupt("return", memoryOrder);
918
+ case 5:
919
+ if (!(typeof ((_this$dbManager = this.dbManager) === null || _this$dbManager === void 0 ? void 0 : _this$dbManager.find) !== 'function')) {
920
+ _context5.next = 7;
921
+ break;
922
+ }
923
+ return _context5.abrupt("return", this.getLocalOrderByLookup(lookup));
924
+ case 7:
925
+ key = this.getIdKey(lookup);
926
+ fields = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
927
+ candidates = [];
928
+ _i2 = 0, _fields = fields;
929
+ case 11:
930
+ if (!(_i2 < _fields.length)) {
931
+ _context5.next = 20;
932
+ break;
933
+ }
934
+ column = _fields[_i2];
935
+ _context5.next = 15;
936
+ return this.dbManager.find(INDEXDB_STORE_NAME, {
937
+ filters: [{
938
+ column: column,
939
+ op: '=',
940
+ value: key
941
+ }],
942
+ orderBy: [{
943
+ column: '__order_storage_key',
944
+ dir: 'asc'
945
+ }],
946
+ limit: 1
947
+ });
948
+ case 15:
949
+ rows = _context5.sent;
950
+ if (rows !== null && rows !== void 0 && rows[0] && this.isOrderLookupMatch(rows[0], key)) candidates.push(rows[0]);
951
+ case 17:
952
+ _i2++;
953
+ _context5.next = 11;
954
+ break;
955
+ case 20:
956
+ candidates.sort(function (left, right) {
957
+ var _order_storage_key, _order_storage_key2;
958
+ var leftKey = String((_order_storage_key = left.__order_storage_key) !== null && _order_storage_key !== void 0 ? _order_storage_key : _this4.getOrderStorageKey(left));
959
+ var rightKey = String((_order_storage_key2 = right.__order_storage_key) !== null && _order_storage_key2 !== void 0 ? _order_storage_key2 : _this4.getOrderStorageKey(right));
960
+ return leftKey < rightKey ? -1 : leftKey > rightKey ? 1 : 0;
961
+ });
962
+ return _context5.abrupt("return", candidates.length ? this.normalizeOrderForMemoryList(candidates[0], 'paymentReadiness.sqlite') : null);
963
+ case 22:
964
+ case "end":
965
+ return _context5.stop();
966
+ }
967
+ }, _callee5, this);
968
+ }));
969
+ function getLocalOrderForPaymentReadiness(_x4) {
970
+ return _getLocalOrderForPaymentReadiness.apply(this, arguments);
971
+ }
972
+ return getLocalOrderForPaymentReadiness;
973
+ }())
894
974
  }, {
895
975
  key: "getLocalOrderByLookup",
896
976
  value: function () {
897
- var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
898
- var _this4 = this;
977
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(lookup) {
978
+ var _this5 = this;
899
979
  var options,
900
980
  key,
901
981
  logContext,
@@ -904,11 +984,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
904
984
  orders,
905
985
  localOrder,
906
986
  normalizedOrder,
907
- _args5 = arguments;
908
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
909
- while (1) switch (_context5.prev = _context5.next) {
987
+ _args6 = arguments;
988
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
989
+ while (1) switch (_context6.prev = _context6.next) {
910
990
  case 0:
911
- options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
991
+ options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
912
992
  key = this.getIdKey(lookup);
913
993
  logContext = {
914
994
  operation_id: options.operationId,
@@ -920,38 +1000,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
920
1000
  }
921
1001
  memoryOrderById = this.store.map.get(key);
922
1002
  if (!memoryOrderById) {
923
- _context5.next = 8;
1003
+ _context6.next = 8;
924
1004
  break;
925
1005
  }
926
1006
  if (options.operationId) {
927
1007
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
928
1008
  }
929
- return _context5.abrupt("return", memoryOrderById);
1009
+ return _context6.abrupt("return", memoryOrderById);
930
1010
  case 8:
931
1011
  memoryOrder = this.store.list.find(function (order) {
932
- return _this4.isOrderLookupMatch(order, key);
1012
+ return _this5.isOrderLookupMatch(order, key);
933
1013
  });
934
1014
  if (!memoryOrder) {
935
- _context5.next = 12;
1015
+ _context6.next = 12;
936
1016
  break;
937
1017
  }
938
1018
  if (options.operationId) {
939
1019
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
940
1020
  }
941
- return _context5.abrupt("return", memoryOrder);
1021
+ return _context6.abrupt("return", memoryOrder);
942
1022
  case 12:
943
1023
  if (options.operationId) {
944
1024
  this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
945
1025
  }
946
- _context5.next = 15;
1026
+ _context6.next = 15;
947
1027
  return this.loadOrdersFromSQLite();
948
1028
  case 15:
949
- orders = _context5.sent;
1029
+ orders = _context6.sent;
950
1030
  localOrder = orders.find(function (order) {
951
- return _this4.isOrderLookupMatch(order, key);
1031
+ return _this5.isOrderLookupMatch(order, key);
952
1032
  });
953
1033
  if (localOrder) {
954
- _context5.next = 20;
1034
+ _context6.next = 20;
955
1035
  break;
956
1036
  }
957
1037
  if (options.operationId) {
@@ -959,7 +1039,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
959
1039
  sqlite_order_count: orders.length
960
1040
  }));
961
1041
  }
962
- return _context5.abrupt("return", null);
1042
+ return _context6.abrupt("return", null);
963
1043
  case 20:
964
1044
  this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
965
1045
  this.syncOrdersMap();
@@ -969,14 +1049,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
969
1049
  sqlite_order_count: orders.length
970
1050
  }, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
971
1051
  }
972
- return _context5.abrupt("return", normalizedOrder);
1052
+ return _context6.abrupt("return", normalizedOrder);
973
1053
  case 25:
974
1054
  case "end":
975
- return _context5.stop();
1055
+ return _context6.stop();
976
1056
  }
977
- }, _callee5, this);
1057
+ }, _callee6, this);
978
1058
  }));
979
- function getLocalOrderByLookup(_x4) {
1059
+ function getLocalOrderByLookup(_x5) {
980
1060
  return _getLocalOrderByLookup.apply(this, arguments);
981
1061
  }
982
1062
  return getLocalOrderByLookup;
@@ -984,10 +1064,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
984
1064
  }, {
985
1065
  key: "getLocalPayment",
986
1066
  value: function () {
987
- var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
1067
+ var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
988
1068
  var logContext, order, payments, match;
989
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
990
- while (1) switch (_context6.prev = _context6.next) {
1069
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1070
+ while (1) switch (_context7.prev = _context7.next) {
991
1071
  case 0:
992
1072
  logContext = {
993
1073
  operation_id: params.operationId,
@@ -995,56 +1075,56 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
995
1075
  payment_number: params.paymentNumber
996
1076
  };
997
1077
  this.logInfo('getLocalPayment-开始', logContext);
998
- _context6.prev = 2;
999
- _context6.next = 5;
1078
+ _context7.prev = 2;
1079
+ _context7.next = 5;
1000
1080
  return this.getLocalOrderByLookup(params.saleId, {
1001
1081
  operationId: params.operationId
1002
1082
  });
1003
1083
  case 5:
1004
- order = _context6.sent;
1084
+ order = _context7.sent;
1005
1085
  if (order) {
1006
- _context6.next = 9;
1086
+ _context7.next = 9;
1007
1087
  break;
1008
1088
  }
1009
1089
  this.logWarning('getLocalPayment-订单未命中', logContext);
1010
- return _context6.abrupt("return", null);
1090
+ return _context7.abrupt("return", null);
1011
1091
  case 9:
1012
1092
  payments = order.payments || [];
1013
1093
  match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
1014
1094
  if (match) {
1015
- _context6.next = 14;
1095
+ _context7.next = 14;
1016
1096
  break;
1017
1097
  }
1018
1098
  this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
1019
1099
  payments: payments
1020
1100
  }));
1021
- return _context6.abrupt("return", null);
1101
+ return _context7.abrupt("return", null);
1022
1102
  case 14:
1023
1103
  this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
1024
1104
  matched_by: match.matchedBy,
1025
1105
  payment_index: match.index,
1026
1106
  payment: match.payment
1027
1107
  }));
1028
- return _context6.abrupt("return", {
1108
+ return _context7.abrupt("return", {
1029
1109
  order: order,
1030
1110
  payment: match.payment,
1031
1111
  paymentIndex: match.index,
1032
1112
  matchedBy: match.matchedBy
1033
1113
  });
1034
1114
  case 18:
1035
- _context6.prev = 18;
1036
- _context6.t0 = _context6["catch"](2);
1115
+ _context7.prev = 18;
1116
+ _context7.t0 = _context7["catch"](2);
1037
1117
  this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
1038
- error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
1118
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1039
1119
  }));
1040
- throw _context6.t0;
1120
+ throw _context7.t0;
1041
1121
  case 22:
1042
1122
  case "end":
1043
- return _context6.stop();
1123
+ return _context7.stop();
1044
1124
  }
1045
- }, _callee6, this, [[2, 18]]);
1125
+ }, _callee7, this, [[2, 18]]);
1046
1126
  }));
1047
- function getLocalPayment(_x5) {
1127
+ function getLocalPayment(_x6) {
1048
1128
  return _getLocalPayment.apply(this, arguments);
1049
1129
  }
1050
1130
  return getLocalPayment;
@@ -1052,11 +1132,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1052
1132
  }, {
1053
1133
  key: "updateLocalPayment",
1054
1134
  value: function () {
1055
- var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
1135
+ var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1056
1136
  var _found$payment$metada;
1057
1137
  var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
1058
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1059
- while (1) switch (_context7.prev = _context7.next) {
1138
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1139
+ while (1) switch (_context8.prev = _context8.next) {
1060
1140
  case 0:
1061
1141
  logContext = {
1062
1142
  operation_id: params.operationId,
@@ -1065,25 +1145,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1065
1145
  incoming_payment_update: params.updates
1066
1146
  };
1067
1147
  this.logInfo('updateLocalPayment-开始', logContext);
1068
- _context7.next = 4;
1148
+ _context8.next = 4;
1069
1149
  return this.getLocalPayment(params);
1070
1150
  case 4:
1071
- found = _context7.sent;
1151
+ found = _context8.sent;
1072
1152
  if (found) {
1073
- _context7.next = 8;
1153
+ _context8.next = 8;
1074
1154
  break;
1075
1155
  }
1076
1156
  this.logWarning('updateLocalPayment-支付项未命中', logContext);
1077
- return _context7.abrupt("return", null);
1157
+ return _context8.abrupt("return", null);
1078
1158
  case 8:
1079
1159
  previousPayment = cloneDeep(found.payment);
1080
1160
  if (!(params.finalizeUnsuccessful && (found.payment.status === 'paid' || (_found$payment$metada = found.payment.metadata) !== null && _found$payment$metada !== void 0 && (_found$payment$metada = _found$payment$metada.transactions) !== null && _found$payment$metada !== void 0 && _found$payment$metada.some(function (transaction) {
1081
1161
  return transaction.status === 'success';
1082
1162
  }) || isLocalFinalizedPayment(found.payment)))) {
1083
- _context7.next = 11;
1163
+ _context8.next = 11;
1084
1164
  break;
1085
1165
  }
1086
- return _context7.abrupt("return", {
1166
+ return _context8.abrupt("return", {
1087
1167
  order: found.order,
1088
1168
  payment: found.payment,
1089
1169
  previousPayment: previousPayment
@@ -1113,11 +1193,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1113
1193
  targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
1114
1194
  shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
1115
1195
  if (!(targetIndex < 0 && shouldKeepInMemory)) {
1116
- _context7.next = 21;
1196
+ _context8.next = 21;
1117
1197
  break;
1118
1198
  }
1119
1199
  this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
1120
- return _context7.abrupt("return", null);
1200
+ return _context8.abrupt("return", null);
1121
1201
  case 21:
1122
1202
  previousList = this.store.list;
1123
1203
  this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
@@ -1127,11 +1207,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1127
1207
  });
1128
1208
  this.syncOrdersMap();
1129
1209
  storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
1130
- _context7.prev = 25;
1210
+ _context8.prev = 25;
1131
1211
  this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
1132
1212
  storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
1133
1213
  }));
1134
- _context7.next = 29;
1214
+ _context8.next = 29;
1135
1215
  return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
1136
1216
  throwOnError: true
1137
1217
  });
@@ -1139,39 +1219,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1139
1219
  this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
1140
1220
  storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
1141
1221
  }));
1142
- _context7.next = 38;
1222
+ _context8.next = 38;
1143
1223
  break;
1144
1224
  case 32:
1145
- _context7.prev = 32;
1146
- _context7.t0 = _context7["catch"](25);
1225
+ _context8.prev = 32;
1226
+ _context8.t0 = _context8["catch"](25);
1147
1227
  this.store.list = previousList;
1148
1228
  this.syncOrdersMap();
1149
1229
  this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
1150
1230
  storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
1151
- error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1231
+ error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
1152
1232
  }));
1153
- throw _context7.t0;
1233
+ throw _context8.t0;
1154
1234
  case 38:
1155
1235
  if (!(shouldKeepInMemory || targetIndex >= 0)) {
1156
- _context7.next = 41;
1236
+ _context8.next = 41;
1157
1237
  break;
1158
1238
  }
1159
- _context7.next = 41;
1239
+ _context8.next = 41;
1160
1240
  return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
1161
1241
  case 41:
1162
1242
  this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
1163
- return _context7.abrupt("return", {
1243
+ return _context8.abrupt("return", {
1164
1244
  order: nextOrder,
1165
1245
  payment: nextPayment,
1166
1246
  previousPayment: previousPayment
1167
1247
  });
1168
1248
  case 43:
1169
1249
  case "end":
1170
- return _context7.stop();
1250
+ return _context8.stop();
1171
1251
  }
1172
- }, _callee7, this, [[25, 32]]);
1252
+ }, _callee8, this, [[25, 32]]);
1173
1253
  }));
1174
- function updateLocalPayment(_x6) {
1254
+ function updateLocalPayment(_x7) {
1175
1255
  return _updateLocalPayment.apply(this, arguments);
1176
1256
  }
1177
1257
  return updateLocalPayment;
@@ -1179,18 +1259,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1179
1259
  }, {
1180
1260
  key: "finalizeLocalEftposPayment",
1181
1261
  value: function () {
1182
- var _finalizeLocalEftposPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1262
+ var _finalizeLocalEftposPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
1183
1263
  var _found$payment$metada2;
1184
1264
  var found, transactions;
1185
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1186
- while (1) switch (_context8.prev = _context8.next) {
1265
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1266
+ while (1) switch (_context9.prev = _context9.next) {
1187
1267
  case 0:
1188
- _context8.next = 2;
1268
+ _context9.next = 2;
1189
1269
  return this.getLocalPayment(params);
1190
1270
  case 2:
1191
- found = _context8.sent;
1271
+ found = _context9.sent;
1192
1272
  if (found) {
1193
- _context8.next = 5;
1273
+ _context9.next = 5;
1194
1274
  break;
1195
1275
  }
1196
1276
  throw new Error('未找到本地支付记录');
@@ -1199,18 +1279,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1199
1279
  if (!transactions.some(function (transaction) {
1200
1280
  return transaction.status !== 'fail' && transaction.status !== 'success' && !params.failedTransactionNumbers.includes(String(transaction.number));
1201
1281
  })) {
1202
- _context8.next = 8;
1282
+ _context9.next = 8;
1203
1283
  break;
1204
1284
  }
1205
1285
  throw new Error('仍有结果未知的交易,保留待确认支付');
1206
1286
  case 8:
1207
1287
  if (!(params.result === 'not_started' && transactions.length > 0 && !isLocalFinalizedPayment(found.payment) && found.payment.status !== 'paid')) {
1208
- _context8.next = 10;
1288
+ _context9.next = 10;
1209
1289
  break;
1210
1290
  }
1211
1291
  throw new Error('支付已有交易记录,不能按未发起交易结束');
1212
1292
  case 10:
1213
- return _context8.abrupt("return", this.updateLocalPayment(_objectSpread(_objectSpread({}, params), {}, {
1293
+ return _context9.abrupt("return", this.updateLocalPayment(_objectSpread(_objectSpread({}, params), {}, {
1214
1294
  finalizeUnsuccessful: true,
1215
1295
  updates: {
1216
1296
  status: 'voided',
@@ -1224,11 +1304,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1224
1304
  })));
1225
1305
  case 11:
1226
1306
  case "end":
1227
- return _context8.stop();
1307
+ return _context9.stop();
1228
1308
  }
1229
- }, _callee8, this);
1309
+ }, _callee9, this);
1230
1310
  }));
1231
- function finalizeLocalEftposPayment(_x7) {
1311
+ function finalizeLocalEftposPayment(_x8) {
1232
1312
  return _finalizeLocalEftposPayment.apply(this, arguments);
1233
1313
  }
1234
1314
  return finalizeLocalEftposPayment;
@@ -1236,42 +1316,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1236
1316
  }, {
1237
1317
  key: "completeLocalPaymentRefresh",
1238
1318
  value: (function () {
1239
- var _completeLocalPaymentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fresh) {
1319
+ var _completeLocalPaymentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1240
1320
  var existing, nextOrder, index;
1241
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1242
- while (1) switch (_context9.prev = _context9.next) {
1321
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1322
+ while (1) switch (_context10.prev = _context10.next) {
1243
1323
  case 0:
1244
- _context9.next = 2;
1324
+ _context10.next = 2;
1245
1325
  return this.getLocalOrderByLookup(fresh.order_id);
1246
1326
  case 2:
1247
- existing = _context9.sent;
1327
+ existing = _context10.sent;
1248
1328
  if (!(!existing || !requiresLocalPaymentRefresh(existing))) {
1249
- _context9.next = 12;
1329
+ _context10.next = 12;
1250
1330
  break;
1251
1331
  }
1252
- _context9.next = 6;
1332
+ _context10.next = 6;
1253
1333
  return this.upsertOrdersFromRemote([fresh]);
1254
1334
  case 6:
1255
- _context9.next = 8;
1335
+ _context10.next = 8;
1256
1336
  return this.getLocalOrderByLookup(fresh.order_id);
1257
1337
  case 8:
1258
- _context9.t0 = _context9.sent;
1259
- if (_context9.t0) {
1260
- _context9.next = 11;
1338
+ _context10.t0 = _context10.sent;
1339
+ if (_context10.t0) {
1340
+ _context10.next = 11;
1261
1341
  break;
1262
1342
  }
1263
- _context9.t0 = fresh;
1343
+ _context10.t0 = fresh;
1264
1344
  case 11:
1265
- return _context9.abrupt("return", _context9.t0);
1345
+ return _context10.abrupt("return", _context10.t0);
1266
1346
  case 12:
1267
1347
  if (!(this.isPendingSyncOrder(existing) || this.isDraftOrder(existing) || (existing.payments || []).some(isPendingOrderPayment))) {
1268
- _context9.next = 14;
1348
+ _context10.next = 14;
1269
1349
  break;
1270
1350
  }
1271
1351
  throw new Error('订单仍有未结束支付或待同步改动,暂不能刷新');
1272
1352
  case 14:
1273
1353
  if (!(!Array.isArray(fresh.products) || !fresh.summary)) {
1274
- _context9.next = 16;
1354
+ _context10.next = 16;
1275
1355
  break;
1276
1356
  }
1277
1357
  throw new Error('远端订单详情不完整,请重新刷新');
@@ -1280,7 +1360,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1280
1360
  nextOrder.metadata = _objectSpread({}, nextOrder.metadata);
1281
1361
  delete nextOrder.metadata[LOCAL_EFTPOS_REFRESH_REQUIRED];
1282
1362
  // Do not publish/clear the gate in memory until SQLite has accepted the full snapshot.
1283
- _context9.next = 21;
1363
+ _context10.next = 21;
1284
1364
  return this.updateOrderInSQLite(nextOrder, 'completeLocalPaymentRefresh', {
1285
1365
  throwOnError: true
1286
1366
  });
@@ -1290,17 +1370,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1290
1370
  return i === index ? nextOrder : order;
1291
1371
  });
1292
1372
  this.syncOrdersMap();
1293
- _context9.next = 26;
1373
+ _context10.next = 26;
1294
1374
  return this.emitOrdersChanged([nextOrder], 'completeLocalPaymentRefresh');
1295
1375
  case 26:
1296
- return _context9.abrupt("return", nextOrder);
1376
+ return _context10.abrupt("return", nextOrder);
1297
1377
  case 27:
1298
1378
  case "end":
1299
- return _context9.stop();
1379
+ return _context10.stop();
1300
1380
  }
1301
- }, _callee9, this);
1381
+ }, _callee10, this);
1302
1382
  }));
1303
- function completeLocalPaymentRefresh(_x8) {
1383
+ function completeLocalPaymentRefresh(_x9) {
1304
1384
  return _completeLocalPaymentRefresh.apply(this, arguments);
1305
1385
  }
1306
1386
  return completeLocalPaymentRefresh;
@@ -1308,8 +1388,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1308
1388
  }, {
1309
1389
  key: "loadOrdersByServer",
1310
1390
  value: function () {
1311
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1312
- var _this5 = this,
1391
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1392
+ var _this6 = this,
1313
1393
  _this$store;
1314
1394
  var options,
1315
1395
  orderList,
@@ -1321,19 +1401,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1321
1401
  mergedOrders,
1322
1402
  isRemoteSnapshotPersisted,
1323
1403
  memoryOrders,
1324
- _args10 = arguments;
1325
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1326
- while (1) switch (_context10.prev = _context10.next) {
1404
+ _args11 = arguments;
1405
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1406
+ while (1) switch (_context11.prev = _context11.next) {
1327
1407
  case 0:
1328
- options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1408
+ options = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
1329
1409
  orderList = [];
1330
1410
  hasFetchedRemoteSnapshot = false;
1331
1411
  trigger = options.trigger || 'unknown';
1332
- _context10.next = 6;
1412
+ _context11.next = 6;
1333
1413
  return this.loadOrdersFromSQLite();
1334
1414
  case 6:
1335
- protectedOrdersBeforeRemoteFetch = _context10.sent.filter(function (order) {
1336
- return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1415
+ protectedOrdersBeforeRemoteFetch = _context11.sent.filter(function (order) {
1416
+ return _this6.shouldProtectLocalOrderFromRemoteSnapshot(order);
1337
1417
  });
1338
1418
  this.logInfo('loadOrdersByServer-开始', {
1339
1419
  trigger: trigger,
@@ -1341,22 +1421,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1341
1421
  query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1342
1422
  protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
1343
1423
  protectedPendingPaymentCount: protectedOrdersBeforeRemoteFetch.reduce(function (count, order) {
1344
- return count + _this5.getIdentifiedPendingPayments(order).length;
1424
+ return count + _this6.getIdentifiedPendingPayments(order).length;
1345
1425
  }, 0)
1346
1426
  });
1347
1427
  if (!this.orderDataSource) {
1348
- _context10.next = 23;
1428
+ _context11.next = 23;
1349
1429
  break;
1350
1430
  }
1351
- _context10.prev = 9;
1352
- _context10.next = 12;
1431
+ _context11.prev = 9;
1432
+ _context11.next = 12;
1353
1433
  return this.orderDataSource.run({
1354
1434
  sse: {
1355
1435
  query: this.store.createdAtQuery
1356
1436
  }
1357
1437
  });
1358
1438
  case 12:
1359
- data = _context10.sent;
1439
+ data = _context11.sent;
1360
1440
  orderList = data || [];
1361
1441
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1362
1442
  trigger: trigger,
@@ -1364,21 +1444,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1364
1444
  });
1365
1445
  hasFetchedRemoteSnapshot = true;
1366
1446
  this.lastServerFullFetchAtMs = Date.now();
1367
- _context10.next = 23;
1447
+ _context11.next = 23;
1368
1448
  break;
1369
1449
  case 19:
1370
- _context10.prev = 19;
1371
- _context10.t0 = _context10["catch"](9);
1450
+ _context11.prev = 19;
1451
+ _context11.t0 = _context11["catch"](9);
1372
1452
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1373
- return _context10.abrupt("return", this.store.list);
1453
+ return _context11.abrupt("return", this.store.list);
1374
1454
  case 23:
1375
1455
  if (hasFetchedRemoteSnapshot) {
1376
1456
  this.clearOrderSnapshotMarker();
1377
1457
  }
1378
- _context10.next = 26;
1458
+ _context11.next = 26;
1379
1459
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1380
1460
  case 26:
1381
- _yield$this$replaceOr = _context10.sent;
1461
+ _yield$this$replaceOr = _context11.sent;
1382
1462
  mergedOrders = _yield$this$replaceOr.orders;
1383
1463
  isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
1384
1464
  if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
@@ -1391,15 +1471,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1391
1471
  persistedCount: mergedOrders.length,
1392
1472
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1393
1473
  });
1394
- _context10.next = 34;
1474
+ _context11.next = 34;
1395
1475
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1396
1476
  case 34:
1397
- return _context10.abrupt("return", memoryOrders);
1477
+ return _context11.abrupt("return", memoryOrders);
1398
1478
  case 35:
1399
1479
  case "end":
1400
- return _context10.stop();
1480
+ return _context11.stop();
1401
1481
  }
1402
- }, _callee10, this, [[9, 19]]);
1482
+ }, _callee11, this, [[9, 19]]);
1403
1483
  }));
1404
1484
  function loadOrdersByServer() {
1405
1485
  return _loadOrdersByServer.apply(this, arguments);
@@ -1413,25 +1493,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1413
1493
  }, {
1414
1494
  key: "refreshOrdersForCurrentBusinessDay",
1415
1495
  value: (function () {
1416
- var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1496
+ var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1417
1497
  var options,
1418
1498
  refreshPromise,
1419
- _args11 = arguments;
1420
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1421
- while (1) switch (_context11.prev = _context11.next) {
1499
+ _args12 = arguments;
1500
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1501
+ while (1) switch (_context12.prev = _context12.next) {
1422
1502
  case 0:
1423
- options = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
1503
+ options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1424
1504
  if (!this.businessDayRefreshPromise) {
1425
- _context11.next = 3;
1505
+ _context12.next = 3;
1426
1506
  break;
1427
1507
  }
1428
- return _context11.abrupt("return", this.businessDayRefreshPromise);
1508
+ return _context12.abrupt("return", this.businessDayRefreshPromise);
1429
1509
  case 3:
1430
1510
  if (!(!this.orderDataSource || !this.getCurrentShopId() || this.hasPulledOrdersToday())) {
1431
- _context11.next = 5;
1511
+ _context12.next = 5;
1432
1512
  break;
1433
1513
  }
1434
- return _context11.abrupt("return");
1514
+ return _context12.abrupt("return");
1435
1515
  case 5:
1436
1516
  refreshPromise = this.silentRefresh({
1437
1517
  trigger: options.trigger || 'business_day_rollover'
@@ -1439,18 +1519,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1439
1519
  return undefined;
1440
1520
  });
1441
1521
  this.businessDayRefreshPromise = refreshPromise;
1442
- _context11.prev = 7;
1443
- _context11.next = 10;
1522
+ _context12.prev = 7;
1523
+ _context12.next = 10;
1444
1524
  return refreshPromise;
1445
1525
  case 10:
1446
- _context11.prev = 10;
1526
+ _context12.prev = 10;
1447
1527
  this.businessDayRefreshPromise = null;
1448
- return _context11.finish(10);
1528
+ return _context12.finish(10);
1449
1529
  case 13:
1450
1530
  case "end":
1451
- return _context11.stop();
1531
+ return _context12.stop();
1452
1532
  }
1453
- }, _callee11, this, [[7,, 10, 13]]);
1533
+ }, _callee12, this, [[7,, 10, 13]]);
1454
1534
  }));
1455
1535
  function refreshOrdersForCurrentBusinessDay() {
1456
1536
  return _refreshOrdersForCurrentBusinessDay.apply(this, arguments);
@@ -1466,23 +1546,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1466
1546
  }, {
1467
1547
  key: "silentRefresh",
1468
1548
  value: (function () {
1469
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1549
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1470
1550
  var options,
1471
1551
  startTime,
1472
1552
  trigger,
1473
1553
  elapsedSinceFullFetch,
1474
1554
  orders,
1475
1555
  errorMessage,
1476
- _args12 = arguments;
1477
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1478
- while (1) switch (_context12.prev = _context12.next) {
1556
+ _args13 = arguments;
1557
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1558
+ while (1) switch (_context13.prev = _context13.next) {
1479
1559
  case 0:
1480
- options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1560
+ options = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
1481
1561
  startTime = Date.now();
1482
1562
  trigger = options.trigger || 'background';
1483
1563
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1484
1564
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1485
- _context12.next = 7;
1565
+ _context13.next = 7;
1486
1566
  break;
1487
1567
  }
1488
1568
  this.logInfo('silentRefresh 跳过全量 SSE', {
@@ -1492,28 +1572,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1492
1572
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1493
1573
  orderCount: this.store.list.length
1494
1574
  });
1495
- return _context12.abrupt("return", this.store.list);
1575
+ return _context13.abrupt("return", this.store.list);
1496
1576
  case 7:
1497
1577
  this.logInfo('silentRefresh 开始', {
1498
1578
  trigger: trigger,
1499
1579
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1500
1580
  orderCount: this.store.list.length
1501
1581
  });
1502
- _context12.prev = 8;
1582
+ _context13.prev = 8;
1503
1583
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1504
1584
  this.updateCreateStore();
1505
- _context12.next = 12;
1585
+ _context13.next = 12;
1506
1586
  return this.loadOrdersByServer({
1507
1587
  trigger: trigger
1508
1588
  });
1509
1589
  case 12:
1510
- orders = _context12.sent;
1590
+ orders = _context13.sent;
1511
1591
  this.store.list = cloneDeep(orders);
1512
1592
  this.syncOrdersMap();
1513
- _context12.next = 17;
1593
+ _context13.next = 17;
1514
1594
  return this.emitOrdersChanged([], 'silentRefresh');
1515
1595
  case 17:
1516
- _context12.next = 19;
1596
+ _context13.next = 19;
1517
1597
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1518
1598
  case 19:
1519
1599
  this.logInfo('silentRefresh 完成', {
@@ -1521,22 +1601,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1521
1601
  orderCount: orders.length,
1522
1602
  duration: "".concat(Date.now() - startTime, "ms")
1523
1603
  });
1524
- return _context12.abrupt("return", this.store.list);
1604
+ return _context13.abrupt("return", this.store.list);
1525
1605
  case 23:
1526
- _context12.prev = 23;
1527
- _context12.t0 = _context12["catch"](8);
1528
- errorMessage = _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0);
1606
+ _context13.prev = 23;
1607
+ _context13.t0 = _context13["catch"](8);
1608
+ errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1529
1609
  this.logError('silentRefresh 失败', {
1530
1610
  trigger: trigger,
1531
1611
  duration: "".concat(Date.now() - startTime, "ms"),
1532
1612
  error: errorMessage
1533
1613
  });
1534
- return _context12.abrupt("return", this.store.list);
1614
+ return _context13.abrupt("return", this.store.list);
1535
1615
  case 28:
1536
1616
  case "end":
1537
- return _context12.stop();
1617
+ return _context13.stop();
1538
1618
  }
1539
- }, _callee12, this, [[8, 23]]);
1619
+ }, _callee13, this, [[8, 23]]);
1540
1620
  }));
1541
1621
  function silentRefresh() {
1542
1622
  return _silentRefresh.apply(this, arguments);
@@ -1574,21 +1654,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1574
1654
  }, {
1575
1655
  key: "prepareNormalizedOrdersForMemoryList",
1576
1656
  value: function prepareNormalizedOrdersForMemoryList(orders) {
1577
- var _this6 = this;
1657
+ var _this7 = this;
1578
1658
  return orders.map(function (order) {
1579
- return _this6.prepareNormalizedOrderForMemoryList(order);
1659
+ return _this7.prepareNormalizedOrderForMemoryList(order);
1580
1660
  }).filter(function (order) {
1581
- return _this6.shouldKeepOrderInMemory(order);
1661
+ return _this7.shouldKeepOrderInMemory(order);
1582
1662
  });
1583
1663
  }
1584
1664
  }, {
1585
1665
  key: "normalizeOrdersForMemoryList",
1586
1666
  value: function normalizeOrdersForMemoryList(orders, source) {
1587
- var _this7 = this;
1667
+ var _this8 = this;
1588
1668
  return orders.map(function (order) {
1589
- return _this7.normalizeOrderForMemoryList(order, source);
1669
+ return _this8.normalizeOrderForMemoryList(order, source);
1590
1670
  }).filter(function (order) {
1591
- return _this7.shouldKeepOrderInMemory(order);
1671
+ return _this8.shouldKeepOrderInMemory(order);
1592
1672
  });
1593
1673
  }
1594
1674
  }, {
@@ -1622,31 +1702,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1622
1702
  }, {
1623
1703
  key: "overwriteExistingOrder",
1624
1704
  value: (function () {
1625
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(fresh) {
1626
- var _this8 = this;
1705
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(fresh) {
1706
+ var _this9 = this;
1627
1707
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1628
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1629
- while (1) switch (_context13.prev = _context13.next) {
1708
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1709
+ while (1) switch (_context14.prev = _context14.next) {
1630
1710
  case 0:
1631
1711
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
1632
1712
  if (!(orderId === undefined || orderId === null)) {
1633
- _context13.next = 4;
1713
+ _context14.next = 4;
1634
1714
  break;
1635
1715
  }
1636
1716
  this.logError('overwriteExistingOrder-入参缺少 order_id');
1637
- return _context13.abrupt("return", {
1717
+ return _context14.abrupt("return", {
1638
1718
  overwritten: false
1639
1719
  });
1640
1720
  case 4:
1641
1721
  key = this.getIdKey(orderId);
1642
1722
  if (this.store.map.has(key)) {
1643
- _context13.next = 8;
1723
+ _context14.next = 8;
1644
1724
  break;
1645
1725
  }
1646
1726
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
1647
1727
  orderId: orderId
1648
1728
  });
1649
- return _context13.abrupt("return", {
1729
+ return _context14.abrupt("return", {
1650
1730
  overwritten: false
1651
1731
  });
1652
1732
  case 8:
@@ -1660,31 +1740,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1660
1740
  this.store.list = this.store.list.map(function (order) {
1661
1741
  var id = order === null || order === void 0 ? void 0 : order.order_id;
1662
1742
  if (id === undefined || id === null) {
1663
- return _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1743
+ return _this9.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1664
1744
  }
1665
- return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1745
+ return _this9.getIdKey(id) === key ? reconciledFresh : _this9.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1666
1746
  });
1667
1747
  this.syncOrdersMap();
1668
- _context13.next = 16;
1748
+ _context14.next = 16;
1669
1749
  return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1670
1750
  case 16:
1671
1751
  this.logInfo('overwriteExistingOrder-结束', {
1672
1752
  orderId: orderId,
1673
1753
  storeOrderCountAfter: this.store.list.length
1674
1754
  });
1675
- _context13.next = 19;
1755
+ _context14.next = 19;
1676
1756
  return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1677
1757
  case 19:
1678
- return _context13.abrupt("return", {
1758
+ return _context14.abrupt("return", {
1679
1759
  overwritten: true
1680
1760
  });
1681
1761
  case 20:
1682
1762
  case "end":
1683
- return _context13.stop();
1763
+ return _context14.stop();
1684
1764
  }
1685
- }, _callee13, this);
1765
+ }, _callee14, this);
1686
1766
  }));
1687
- function overwriteExistingOrder(_x9) {
1767
+ function overwriteExistingOrder(_x10) {
1688
1768
  return _overwriteExistingOrder.apply(this, arguments);
1689
1769
  }
1690
1770
  return overwriteExistingOrder;
@@ -1697,35 +1777,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1697
1777
  }, {
1698
1778
  key: "upsertOrdersFromRemote",
1699
1779
  value: (function () {
1700
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(freshOrders) {
1780
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(freshOrders) {
1701
1781
  var source,
1702
- _args14 = arguments;
1703
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1704
- while (1) switch (_context14.prev = _context14.next) {
1782
+ _args15 = arguments;
1783
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1784
+ while (1) switch (_context15.prev = _context15.next) {
1705
1785
  case 0:
1706
- source = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : 'upsertOrdersFromRemote';
1786
+ source = _args15.length > 1 && _args15[1] !== undefined ? _args15[1] : 'upsertOrdersFromRemote';
1707
1787
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
1708
- _context14.next = 4;
1788
+ _context15.next = 4;
1709
1789
  break;
1710
1790
  }
1711
1791
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {
1712
1792
  source: source
1713
1793
  });
1714
- return _context14.abrupt("return");
1794
+ return _context15.abrupt("return");
1715
1795
  case 4:
1716
1796
  this.logInfo('upsertOrdersFromRemote-开始', {
1717
1797
  count: freshOrders.length,
1718
1798
  source: source
1719
1799
  });
1720
- _context14.next = 7;
1800
+ _context15.next = 7;
1721
1801
  return this.mergeOrdersToStore(freshOrders, source);
1722
1802
  case 7:
1723
1803
  case "end":
1724
- return _context14.stop();
1804
+ return _context15.stop();
1725
1805
  }
1726
- }, _callee14, this);
1806
+ }, _callee15, this);
1727
1807
  }));
1728
- function upsertOrdersFromRemote(_x10) {
1808
+ function upsertOrdersFromRemote(_x11) {
1729
1809
  return _upsertOrdersFromRemote.apply(this, arguments);
1730
1810
  }
1731
1811
  return upsertOrdersFromRemote;
@@ -1733,21 +1813,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1733
1813
  }, {
1734
1814
  key: "markOrderSyncedByExternalSaleNumber",
1735
1815
  value: function () {
1736
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1737
- var _this9 = this,
1816
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1817
+ var _this10 = this,
1738
1818
  _existing$external_sa,
1739
1819
  _nextOrder$order_id;
1740
1820
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1741
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1742
- while (1) switch (_context15.prev = _context15.next) {
1821
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1822
+ while (1) switch (_context16.prev = _context16.next) {
1743
1823
  case 0:
1744
1824
  externalSaleNumber = params.externalSaleNumber;
1745
1825
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1746
- _context15.next = 4;
1826
+ _context16.next = 4;
1747
1827
  break;
1748
1828
  }
1749
1829
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1750
- return _context15.abrupt("return", {
1830
+ return _context16.abrupt("return", {
1751
1831
  updated: false
1752
1832
  });
1753
1833
  case 4:
@@ -1755,16 +1835,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1755
1835
  targetIndex = this.store.list.findIndex(function (order) {
1756
1836
  var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
1757
1837
  if (value === undefined || value === null || value === '') return false;
1758
- return _this9.getIdKey(value) === key;
1838
+ return _this10.getIdKey(value) === key;
1759
1839
  });
1760
1840
  if (!(targetIndex < 0)) {
1761
- _context15.next = 9;
1841
+ _context16.next = 9;
1762
1842
  break;
1763
1843
  }
1764
1844
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1765
1845
  external_sale_number: externalSaleNumber
1766
1846
  });
1767
- return _context15.abrupt("return", {
1847
+ return _context16.abrupt("return", {
1768
1848
  updated: false
1769
1849
  });
1770
1850
  case 9:
@@ -1780,27 +1860,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1780
1860
  return nextOrder;
1781
1861
  });
1782
1862
  this.syncOrdersMap();
1783
- _context15.next = 16;
1863
+ _context16.next = 16;
1784
1864
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1785
1865
  case 16:
1786
1866
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1787
1867
  external_sale_number: externalSaleNumber,
1788
1868
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1789
1869
  });
1790
- _context15.next = 19;
1870
+ _context16.next = 19;
1791
1871
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1792
1872
  case 19:
1793
- return _context15.abrupt("return", {
1873
+ return _context16.abrupt("return", {
1794
1874
  updated: true,
1795
1875
  order: nextOrder
1796
1876
  });
1797
1877
  case 20:
1798
1878
  case "end":
1799
- return _context15.stop();
1879
+ return _context16.stop();
1800
1880
  }
1801
- }, _callee15, this);
1881
+ }, _callee16, this);
1802
1882
  }));
1803
- function markOrderSyncedByExternalSaleNumber(_x11) {
1883
+ function markOrderSyncedByExternalSaleNumber(_x12) {
1804
1884
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
1805
1885
  }
1806
1886
  return markOrderSyncedByExternalSaleNumber;
@@ -1812,8 +1892,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1812
1892
  }, {
1813
1893
  key: "upsertPendingSyncOrders",
1814
1894
  value: (function () {
1815
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(pendingOrders) {
1816
- var _this10 = this;
1895
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(pendingOrders) {
1896
+ var _this11 = this;
1817
1897
  var options,
1818
1898
  pendingMap,
1819
1899
  memoryPendingMap,
@@ -1843,26 +1923,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1843
1923
  insertIndex,
1844
1924
  patchedOrders,
1845
1925
  previousList,
1846
- _args16 = arguments;
1847
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1848
- while (1) switch (_context16.prev = _context16.next) {
1926
+ _args17 = arguments;
1927
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1928
+ while (1) switch (_context17.prev = _context17.next) {
1849
1929
  case 0:
1850
- options = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : {};
1930
+ options = _args17.length > 1 && _args17[1] !== undefined ? _args17[1] : {};
1851
1931
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1852
- _context16.next = 4;
1932
+ _context17.next = 4;
1853
1933
  break;
1854
1934
  }
1855
1935
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1856
- return _context16.abrupt("return");
1936
+ return _context17.abrupt("return");
1857
1937
  case 4:
1858
1938
  pendingMap = new Map();
1859
1939
  memoryPendingMap = new Map();
1860
1940
  _iterator7 = _createForOfIteratorHelper(pendingOrders);
1861
- _context16.prev = 7;
1941
+ _context17.prev = 7;
1862
1942
  _iterator7.s();
1863
1943
  case 9:
1864
1944
  if ((_step7 = _iterator7.n()).done) {
1865
- _context16.next = 20;
1945
+ _context17.next = 20;
1866
1946
  break;
1867
1947
  }
1868
1948
  order = _step7.value;
@@ -1873,43 +1953,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1873
1953
  });
1874
1954
  storageKey = this.getOrderStorageKey(pendingOrder);
1875
1955
  if (storageKey) {
1876
- _context16.next = 16;
1956
+ _context17.next = 16;
1877
1957
  break;
1878
1958
  }
1879
- return _context16.abrupt("continue", 18);
1959
+ return _context17.abrupt("continue", 18);
1880
1960
  case 16:
1881
1961
  pendingMap.set(storageKey, pendingOrder);
1882
1962
  memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1883
1963
  case 18:
1884
- _context16.next = 9;
1964
+ _context17.next = 9;
1885
1965
  break;
1886
1966
  case 20:
1887
- _context16.next = 25;
1967
+ _context17.next = 25;
1888
1968
  break;
1889
1969
  case 22:
1890
- _context16.prev = 22;
1891
- _context16.t0 = _context16["catch"](7);
1892
- _iterator7.e(_context16.t0);
1970
+ _context17.prev = 22;
1971
+ _context17.t0 = _context17["catch"](7);
1972
+ _iterator7.e(_context17.t0);
1893
1973
  case 25:
1894
- _context16.prev = 25;
1974
+ _context17.prev = 25;
1895
1975
  _iterator7.f();
1896
- return _context16.finish(25);
1976
+ return _context17.finish(25);
1897
1977
  case 28:
1898
1978
  if (!(pendingMap.size === 0)) {
1899
- _context16.next = 31;
1979
+ _context17.next = 31;
1900
1980
  break;
1901
1981
  }
1902
1982
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1903
1983
  count: pendingOrders.length
1904
1984
  });
1905
- return _context16.abrupt("return");
1985
+ return _context17.abrupt("return");
1906
1986
  case 31:
1907
1987
  this.logInfo('upsertPendingSyncOrders-开始', {
1908
1988
  count: pendingMap.size
1909
1989
  });
1910
1990
  mergeActions = {};
1911
1991
  updatedList = this.store.list.map(function (order) {
1912
- return _this10.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1992
+ return _this11.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1913
1993
  }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1914
1994
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1915
1995
  identityKeyToIndex = new Map();
@@ -1928,17 +2008,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1928
2008
  }
1929
2009
  }
1930
2010
  _iterator9 = _createForOfIteratorHelper(memoryPendingMap.entries());
1931
- _context16.prev = 37;
2011
+ _context17.prev = 37;
1932
2012
  _iterator9.s();
1933
2013
  case 39:
1934
2014
  if ((_step9 = _iterator9.n()).done) {
1935
- _context16.next = 58;
2015
+ _context17.next = 58;
1936
2016
  break;
1937
2017
  }
1938
2018
  _step9$value = _slicedToArray(_step9.value, 2), _storageKey = _step9$value[0], _pendingOrder = _step9$value[1];
1939
2019
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
1940
2020
  if (!(matchIndex >= 0)) {
1941
- _context16.next = 52;
2021
+ _context17.next = 52;
1942
2022
  break;
1943
2023
  }
1944
2024
  existingOrder = updatedList[matchIndex];
@@ -1955,57 +2035,57 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1955
2035
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1956
2036
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1957
2037
  mergeActions[_storageKey] = 'update';
1958
- return _context16.abrupt("continue", 56);
2038
+ return _context17.abrupt("continue", 56);
1959
2039
  case 52:
1960
2040
  insertIndex = updatedList.length;
1961
2041
  updatedList.push(_pendingOrder);
1962
2042
  this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1963
2043
  mergeActions[_storageKey] = 'insert';
1964
2044
  case 56:
1965
- _context16.next = 39;
2045
+ _context17.next = 39;
1966
2046
  break;
1967
2047
  case 58:
1968
- _context16.next = 63;
2048
+ _context17.next = 63;
1969
2049
  break;
1970
2050
  case 60:
1971
- _context16.prev = 60;
1972
- _context16.t1 = _context16["catch"](37);
1973
- _iterator9.e(_context16.t1);
2051
+ _context17.prev = 60;
2052
+ _context17.t1 = _context17["catch"](37);
2053
+ _iterator9.e(_context17.t1);
1974
2054
  case 63:
1975
- _context16.prev = 63;
2055
+ _context17.prev = 63;
1976
2056
  _iterator9.f();
1977
- return _context16.finish(63);
2057
+ return _context17.finish(63);
1978
2058
  case 66:
1979
2059
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1980
2060
  previousList = this.store.list;
1981
2061
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1982
2062
  this.syncOrdersMap();
1983
- _context16.prev = 70;
1984
- _context16.next = 73;
2063
+ _context17.prev = 70;
2064
+ _context17.next = 73;
1985
2065
  return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1986
2066
  case 73:
1987
- _context16.next = 80;
2067
+ _context17.next = 80;
1988
2068
  break;
1989
2069
  case 75:
1990
- _context16.prev = 75;
1991
- _context16.t2 = _context16["catch"](70);
2070
+ _context17.prev = 75;
2071
+ _context17.t2 = _context17["catch"](70);
1992
2072
  this.store.list = previousList;
1993
2073
  this.syncOrdersMap();
1994
- throw _context16.t2;
2074
+ throw _context17.t2;
1995
2075
  case 80:
1996
2076
  this.logInfo('upsertPendingSyncOrders-结束', {
1997
2077
  count: patchedOrders.length,
1998
2078
  storeOrderCountAfter: this.store.list.length
1999
2079
  });
2000
- _context16.next = 83;
2080
+ _context17.next = 83;
2001
2081
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
2002
2082
  case 83:
2003
2083
  case "end":
2004
- return _context16.stop();
2084
+ return _context17.stop();
2005
2085
  }
2006
- }, _callee16, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
2086
+ }, _callee17, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
2007
2087
  }));
2008
- function upsertPendingSyncOrders(_x12) {
2088
+ function upsertPendingSyncOrders(_x13) {
2009
2089
  return _upsertPendingSyncOrders.apply(this, arguments);
2010
2090
  }
2011
2091
  return upsertPendingSyncOrders;
@@ -2018,27 +2098,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2018
2098
  }, {
2019
2099
  key: "upsertLocalDraftOrders",
2020
2100
  value: (function () {
2021
- var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(draftOrders) {
2022
- var _this11 = this;
2101
+ var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(draftOrders) {
2102
+ var _this12 = this;
2023
2103
  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;
2024
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2025
- while (1) switch (_context17.prev = _context17.next) {
2104
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2105
+ while (1) switch (_context18.prev = _context18.next) {
2026
2106
  case 0:
2027
2107
  if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
2028
- _context17.next = 3;
2108
+ _context18.next = 3;
2029
2109
  break;
2030
2110
  }
2031
2111
  this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
2032
- return _context17.abrupt("return");
2112
+ return _context18.abrupt("return");
2033
2113
  case 3:
2034
2114
  draftMap = new Map();
2035
2115
  memoryDraftMap = new Map();
2036
2116
  _iterator10 = _createForOfIteratorHelper(draftOrders);
2037
- _context17.prev = 6;
2117
+ _context18.prev = 6;
2038
2118
  _iterator10.s();
2039
2119
  case 8:
2040
2120
  if ((_step10 = _iterator10.n()).done) {
2041
- _context17.next = 19;
2121
+ _context18.next = 19;
2042
2122
  break;
2043
2123
  }
2044
2124
  order = _step10.value;
@@ -2048,10 +2128,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2048
2128
  });
2049
2129
  storageKey = this.getOrderStorageKey(draftOrder);
2050
2130
  if (storageKey) {
2051
- _context17.next = 14;
2131
+ _context18.next = 14;
2052
2132
  break;
2053
2133
  }
2054
- return _context17.abrupt("continue", 17);
2134
+ return _context18.abrupt("continue", 17);
2055
2135
  case 14:
2056
2136
  draftMap.set(storageKey, draftOrder);
2057
2137
  memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
@@ -2059,28 +2139,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2059
2139
  memoryDraftMap.set(storageKey, memoryDraftOrder);
2060
2140
  }
2061
2141
  case 17:
2062
- _context17.next = 8;
2142
+ _context18.next = 8;
2063
2143
  break;
2064
2144
  case 19:
2065
- _context17.next = 24;
2145
+ _context18.next = 24;
2066
2146
  break;
2067
2147
  case 21:
2068
- _context17.prev = 21;
2069
- _context17.t0 = _context17["catch"](6);
2070
- _iterator10.e(_context17.t0);
2148
+ _context18.prev = 21;
2149
+ _context18.t0 = _context18["catch"](6);
2150
+ _iterator10.e(_context18.t0);
2071
2151
  case 24:
2072
- _context17.prev = 24;
2152
+ _context18.prev = 24;
2073
2153
  _iterator10.f();
2074
- return _context17.finish(24);
2154
+ return _context18.finish(24);
2075
2155
  case 27:
2076
2156
  if (!(draftMap.size === 0)) {
2077
- _context17.next = 30;
2157
+ _context18.next = 30;
2078
2158
  break;
2079
2159
  }
2080
2160
  this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
2081
2161
  count: draftOrders.length
2082
2162
  });
2083
- return _context17.abrupt("return");
2163
+ return _context18.abrupt("return");
2084
2164
  case 30:
2085
2165
  this.logInfo('upsertLocalDraftOrders-开始', {
2086
2166
  count: draftMap.size,
@@ -2089,7 +2169,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2089
2169
  });
2090
2170
  mergeActions = {};
2091
2171
  updatedList = this.store.list.filter(function (order) {
2092
- return _this11.shouldKeepOrderInMemory(order);
2172
+ return _this12.shouldKeepOrderInMemory(order);
2093
2173
  });
2094
2174
  identityKeyToIndex = new Map();
2095
2175
  for (index = 0; index < updatedList.length; index += 1) {
@@ -2106,17 +2186,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2106
2186
  }
2107
2187
  }
2108
2188
  _iterator12 = _createForOfIteratorHelper(memoryDraftMap.entries());
2109
- _context17.prev = 36;
2189
+ _context18.prev = 36;
2110
2190
  _iterator12.s();
2111
2191
  case 38:
2112
2192
  if ((_step12 = _iterator12.n()).done) {
2113
- _context17.next = 57;
2193
+ _context18.next = 57;
2114
2194
  break;
2115
2195
  }
2116
2196
  _step12$value = _slicedToArray(_step12.value, 2), _storageKey2 = _step12$value[0], _draftOrder = _step12$value[1];
2117
2197
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
2118
2198
  if (!(matchIndex >= 0)) {
2119
- _context17.next = 51;
2199
+ _context18.next = 51;
2120
2200
  break;
2121
2201
  }
2122
2202
  existingOrder = updatedList[matchIndex];
@@ -2131,68 +2211,68 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2131
2211
  draftMap.set(_storageKey2, reconciledDraftOrder);
2132
2212
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
2133
2213
  mergeActions[_storageKey2] = 'update';
2134
- return _context17.abrupt("continue", 55);
2214
+ return _context18.abrupt("continue", 55);
2135
2215
  case 51:
2136
2216
  insertIndex = updatedList.length;
2137
2217
  updatedList.push(_draftOrder);
2138
2218
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
2139
2219
  mergeActions[_storageKey2] = 'insert';
2140
2220
  case 55:
2141
- _context17.next = 38;
2221
+ _context18.next = 38;
2142
2222
  break;
2143
2223
  case 57:
2144
- _context17.next = 62;
2224
+ _context18.next = 62;
2145
2225
  break;
2146
2226
  case 59:
2147
- _context17.prev = 59;
2148
- _context17.t1 = _context17["catch"](36);
2149
- _iterator12.e(_context17.t1);
2227
+ _context18.prev = 59;
2228
+ _context18.t1 = _context18["catch"](36);
2229
+ _iterator12.e(_context18.t1);
2150
2230
  case 62:
2151
- _context17.prev = 62;
2231
+ _context18.prev = 62;
2152
2232
  _iterator12.f();
2153
- return _context17.finish(62);
2233
+ return _context18.finish(62);
2154
2234
  case 65:
2155
2235
  patchedOrders = _toConsumableArray(draftMap.values());
2156
2236
  previousList = this.store.list;
2157
2237
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
2158
2238
  this.syncOrdersMap();
2159
- _context17.prev = 69;
2160
- _context17.next = 72;
2239
+ _context18.prev = 69;
2240
+ _context18.next = 72;
2161
2241
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
2162
2242
  throwOnError: true
2163
2243
  });
2164
2244
  case 72:
2165
- _context17.next = 79;
2245
+ _context18.next = 79;
2166
2246
  break;
2167
2247
  case 74:
2168
- _context17.prev = 74;
2169
- _context17.t2 = _context17["catch"](69);
2248
+ _context18.prev = 74;
2249
+ _context18.t2 = _context18["catch"](69);
2170
2250
  this.store.list = previousList;
2171
2251
  this.syncOrdersMap();
2172
- throw _context17.t2;
2252
+ throw _context18.t2;
2173
2253
  case 79:
2174
2254
  this.logInfo('upsertLocalDraftOrders-结束', {
2175
2255
  count: patchedOrders.length,
2176
2256
  storeOrderCountAfter: this.store.list.length
2177
2257
  });
2178
2258
  removedLegacyMemoryDraft = previousList.some(function (order) {
2179
- return !_this11.shouldKeepOrderInMemory(order);
2259
+ return !_this12.shouldKeepOrderInMemory(order);
2180
2260
  });
2181
2261
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
2182
- _context17.next = 84;
2262
+ _context18.next = 84;
2183
2263
  break;
2184
2264
  }
2185
- _context17.next = 84;
2265
+ _context18.next = 84;
2186
2266
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
2187
- return _this11.shouldKeepOrderInMemory(order);
2267
+ return _this12.shouldKeepOrderInMemory(order);
2188
2268
  }), 'upsertLocalDraftOrders');
2189
2269
  case 84:
2190
2270
  case "end":
2191
- return _context17.stop();
2271
+ return _context18.stop();
2192
2272
  }
2193
- }, _callee17, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2273
+ }, _callee18, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2194
2274
  }));
2195
- function upsertLocalDraftOrders(_x13) {
2275
+ function upsertLocalDraftOrders(_x14) {
2196
2276
  return _upsertLocalDraftOrders.apply(this, arguments);
2197
2277
  }
2198
2278
  return upsertLocalDraftOrders;
@@ -2204,42 +2284,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2204
2284
  }, {
2205
2285
  key: "fetchOrdersBySSE",
2206
2286
  value: (function () {
2207
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2287
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2208
2288
  var query,
2209
2289
  data,
2210
- _args18 = arguments;
2211
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2212
- while (1) switch (_context18.prev = _context18.next) {
2290
+ _args19 = arguments;
2291
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2292
+ while (1) switch (_context19.prev = _context19.next) {
2213
2293
  case 0:
2214
- query = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {};
2294
+ query = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {};
2215
2295
  if (this.orderDataSource) {
2216
- _context18.next = 3;
2296
+ _context19.next = 3;
2217
2297
  break;
2218
2298
  }
2219
- return _context18.abrupt("return", []);
2299
+ return _context19.abrupt("return", []);
2220
2300
  case 3:
2221
- _context18.prev = 3;
2222
- _context18.next = 6;
2301
+ _context19.prev = 3;
2302
+ _context19.next = 6;
2223
2303
  return this.orderDataSource.run({
2224
2304
  sse: {
2225
2305
  query: query
2226
2306
  }
2227
2307
  });
2228
2308
  case 6:
2229
- data = _context18.sent;
2230
- return _context18.abrupt("return", data || []);
2309
+ data = _context19.sent;
2310
+ return _context19.abrupt("return", data || []);
2231
2311
  case 10:
2232
- _context18.prev = 10;
2233
- _context18.t0 = _context18["catch"](3);
2312
+ _context19.prev = 10;
2313
+ _context19.t0 = _context19["catch"](3);
2234
2314
  this.logError('fetchOrdersBySSE-失败', {
2235
- error: _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0)
2315
+ error: _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0)
2236
2316
  });
2237
- return _context18.abrupt("return", []);
2317
+ return _context19.abrupt("return", []);
2238
2318
  case 14:
2239
2319
  case "end":
2240
- return _context18.stop();
2320
+ return _context19.stop();
2241
2321
  }
2242
- }, _callee18, this, [[3, 10]]);
2322
+ }, _callee19, this, [[3, 10]]);
2243
2323
  }));
2244
2324
  function fetchOrdersBySSE() {
2245
2325
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -2269,9 +2349,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2269
2349
  }, {
2270
2350
  key: "syncOrdersMap",
2271
2351
  value: function syncOrdersMap() {
2272
- var _this12 = this;
2352
+ var _this13 = this;
2273
2353
  this.store.list = this.store.list.filter(function (order) {
2274
- return _this12.shouldKeepOrderInMemory(order);
2354
+ return _this13.shouldKeepOrderInMemory(order);
2275
2355
  });
2276
2356
  this.store.map.clear();
2277
2357
  var _iterator13 = _createForOfIteratorHelper(this.store.list),
@@ -2327,7 +2407,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2327
2407
  }, {
2328
2408
  key: "getOrderIdentityEntries",
2329
2409
  value: function getOrderIdentityEntries(order) {
2330
- var _this13 = this;
2410
+ var _this14 = this;
2331
2411
  if (!order) return [];
2332
2412
  var record = order;
2333
2413
  var candidates = [{
@@ -2345,9 +2425,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2345
2425
  }];
2346
2426
  var entries = [];
2347
2427
  var _loop = function _loop() {
2348
- var candidate = _candidates[_i2];
2349
- if (_this13.isBlankIdentityValue(candidate.value)) return 0; // continue
2350
- var key = _this13.getIdKey(candidate.value);
2428
+ var candidate = _candidates[_i3];
2429
+ if (_this14.isBlankIdentityValue(candidate.value)) return 0; // continue
2430
+ var key = _this14.getIdKey(candidate.value);
2351
2431
  if (entries.some(function (entry) {
2352
2432
  return entry.field === candidate.field && entry.key === key;
2353
2433
  })) return 0; // continue
@@ -2357,7 +2437,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2357
2437
  });
2358
2438
  },
2359
2439
  _ret;
2360
- for (var _i2 = 0, _candidates = candidates; _i2 < _candidates.length; _i2++) {
2440
+ for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
2361
2441
  _ret = _loop();
2362
2442
  if (_ret === 0) continue;
2363
2443
  }
@@ -2386,8 +2466,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2386
2466
  value: function getOrderDateKey(order) {
2387
2467
  var _order$bookings, _order$bookings2;
2388
2468
  var candidates = [order === null || order === void 0 ? void 0 : order.schedule_date, order === null || order === void 0 ? void 0 : order.create_date, order === null || order === void 0 ? void 0 : order.created_at, order === null || order === void 0 || (_order$bookings = order.bookings) === null || _order$bookings === void 0 || (_order$bookings = _order$bookings[0]) === null || _order$bookings === void 0 ? void 0 : _order$bookings.start_date, order === null || order === void 0 || (_order$bookings2 = order.bookings) === null || _order$bookings2 === void 0 || (_order$bookings2 = _order$bookings2[0]) === null || _order$bookings2 === void 0 ? void 0 : _order$bookings2.select_date];
2389
- for (var _i3 = 0, _candidates2 = candidates; _i3 < _candidates2.length; _i3++) {
2390
- var v = _candidates2[_i3];
2469
+ for (var _i4 = 0, _candidates2 = candidates; _i4 < _candidates2.length; _i4++) {
2470
+ var v = _candidates2[_i4];
2391
2471
  if (!v) continue;
2392
2472
  var text = String(v);
2393
2473
  if (!text) continue;
@@ -2414,29 +2494,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2414
2494
  }, {
2415
2495
  key: "setupOrderSync",
2416
2496
  value: function setupOrderSync() {
2417
- var _this14 = this;
2497
+ var _this15 = this;
2418
2498
  if (!this.orderDataSource) return;
2419
2499
  this.orderDataSource.run({
2420
2500
  pubsub: {
2421
2501
  callback: function callback(res) {
2422
2502
  var _message$id, _message$order_id, _message$type;
2423
2503
  var pubsubReceivedAt = Date.now();
2424
- var message = _this14.normalizeOrderSyncMessage(res);
2504
+ var message = _this15.normalizeOrderSyncMessage(res);
2425
2505
  if (!message) return;
2426
2506
  message._pubsubReceivedAt = pubsubReceivedAt;
2427
- _this14.pendingSyncMessages.push(message);
2428
- var throttleMs = _this14.getOrderSyncThrottleMs();
2429
- var routeInfo = _this14.resolveSyncMessageRoute(message);
2430
- _this14.logInfo('orderSync-收到消息并入队', {
2507
+ _this15.pendingSyncMessages.push(message);
2508
+ var throttleMs = _this15.getOrderSyncThrottleMs();
2509
+ var routeInfo = _this15.resolveSyncMessageRoute(message);
2510
+ _this15.logInfo('orderSync-收到消息并入队', {
2431
2511
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
2432
2512
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
2433
2513
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
2434
- pendingCount: _this14.pendingSyncMessages.length,
2514
+ pendingCount: _this15.pendingSyncMessages.length,
2435
2515
  throttleMs: throttleMs,
2436
2516
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
2437
2517
  fullMessage: JSON.stringify(message)
2438
2518
  });
2439
- _this14.scheduleOrderSyncThrottle();
2519
+ _this15.scheduleOrderSyncThrottle();
2440
2520
  }
2441
2521
  }
2442
2522
  }).catch(function () {
@@ -2453,7 +2533,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2453
2533
  }, {
2454
2534
  key: "scheduleOrderSyncThrottle",
2455
2535
  value: function scheduleOrderSyncThrottle() {
2456
- var _this15 = this;
2536
+ var _this16 = this;
2457
2537
  if (this.isProcessingSyncBatch) return;
2458
2538
  if (this.isIdlePhase) {
2459
2539
  this.isIdlePhase = false;
@@ -2464,8 +2544,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2464
2544
  if (this.syncTimer) return;
2465
2545
  var throttleMs = this.getOrderSyncThrottleMs();
2466
2546
  this.syncTimer = setTimeout(function () {
2467
- _this15.syncTimer = undefined;
2468
- void _this15.flushOrderSyncMessagesByThrottle();
2547
+ _this16.syncTimer = undefined;
2548
+ void _this16.flushOrderSyncMessagesByThrottle();
2469
2549
  }, throttleMs);
2470
2550
  }
2471
2551
 
@@ -2476,41 +2556,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2476
2556
  }, {
2477
2557
  key: "flushOrderSyncMessagesByThrottle",
2478
2558
  value: (function () {
2479
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2480
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2481
- while (1) switch (_context19.prev = _context19.next) {
2559
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2560
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2561
+ while (1) switch (_context20.prev = _context20.next) {
2482
2562
  case 0:
2483
2563
  if (!this.isProcessingSyncBatch) {
2484
- _context19.next = 2;
2564
+ _context20.next = 2;
2485
2565
  break;
2486
2566
  }
2487
- return _context19.abrupt("return");
2567
+ return _context20.abrupt("return");
2488
2568
  case 2:
2489
2569
  if (!(this.pendingSyncMessages.length === 0)) {
2490
- _context19.next = 5;
2570
+ _context20.next = 5;
2491
2571
  break;
2492
2572
  }
2493
2573
  this.isIdlePhase = true;
2494
- return _context19.abrupt("return");
2574
+ return _context20.abrupt("return");
2495
2575
  case 5:
2496
2576
  this.isProcessingSyncBatch = true;
2497
- _context19.prev = 6;
2498
- _context19.next = 9;
2577
+ _context20.prev = 6;
2578
+ _context20.next = 9;
2499
2579
  return this.processOrderSyncMessages();
2500
2580
  case 9:
2501
- _context19.prev = 9;
2581
+ _context20.prev = 9;
2502
2582
  this.isProcessingSyncBatch = false;
2503
2583
  if (this.pendingSyncMessages.length > 0) {
2504
2584
  this.scheduleOrderSyncThrottle();
2505
2585
  } else {
2506
2586
  this.isIdlePhase = true;
2507
2587
  }
2508
- return _context19.finish(9);
2588
+ return _context20.finish(9);
2509
2589
  case 13:
2510
2590
  case "end":
2511
- return _context19.stop();
2591
+ return _context20.stop();
2512
2592
  }
2513
- }, _callee19, this, [[6,, 9, 13]]);
2593
+ }, _callee20, this, [[6,, 9, 13]]);
2514
2594
  }));
2515
2595
  function flushOrderSyncMessagesByThrottle() {
2516
2596
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -2532,19 +2612,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2532
2612
  }, {
2533
2613
  key: "processOrderSyncMessages",
2534
2614
  value: (function () {
2535
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2536
- var _this16 = this;
2615
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2616
+ var _this17 = this;
2537
2617
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2538
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2539
- while (1) switch (_context20.prev = _context20.next) {
2618
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2619
+ while (1) switch (_context21.prev = _context21.next) {
2540
2620
  case 0:
2541
2621
  messages = _toConsumableArray(this.pendingSyncMessages);
2542
2622
  this.pendingSyncMessages = [];
2543
2623
  if (!(messages.length === 0)) {
2544
- _context20.next = 4;
2624
+ _context21.next = 4;
2545
2625
  break;
2546
2626
  }
2547
- return _context20.abrupt("return");
2627
+ return _context21.abrupt("return");
2548
2628
  case 4:
2549
2629
  batchProcessStartAt = Date.now();
2550
2630
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -2560,13 +2640,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2560
2640
  upsertOrders = new Map();
2561
2641
  refreshIds = [];
2562
2642
  messages.forEach(function (msg, msgIndex) {
2563
- var routeInfo = _this16.resolveSyncMessageRoute(msg);
2643
+ var routeInfo = _this17.resolveSyncMessageRoute(msg);
2564
2644
  var hasBatchIds = routeInfo.hasBatchIds;
2565
2645
  var singleId = routeInfo.singleId;
2566
2646
  var hasSingleId = routeInfo.hasSingleId;
2567
- var normalizedBody = _this16.normalizeOrderSyncPayload(msg.body || msg.data);
2647
+ var normalizedBody = _this17.normalizeOrderSyncPayload(msg.body || msg.data);
2568
2648
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
2569
- upsertOrders.set(_this16.getIdKey(normalizedBody.order_id), normalizedBody);
2649
+ upsertOrders.set(_this17.getIdKey(normalizedBody.order_id), normalizedBody);
2570
2650
  return;
2571
2651
  }
2572
2652
  if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
@@ -2578,41 +2658,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2578
2658
  refreshIdCount: uniqueRefreshIds.length
2579
2659
  });
2580
2660
  if (!(upsertList.length > 0)) {
2581
- _context20.next = 16;
2661
+ _context21.next = 16;
2582
2662
  break;
2583
2663
  }
2584
- _context20.next = 16;
2664
+ _context21.next = 16;
2585
2665
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
2586
2666
  case 16:
2587
2667
  if (!(uniqueRefreshIds.length > 0)) {
2588
- _context20.next = 28;
2668
+ _context21.next = 28;
2589
2669
  break;
2590
2670
  }
2591
2671
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
2592
2672
  if (skipped.length > 0) {}
2593
2673
  if (!(toFetch.length > 0)) {
2594
- _context20.next = 28;
2674
+ _context21.next = 28;
2595
2675
  break;
2596
2676
  }
2597
- _context20.next = 22;
2677
+ _context21.next = 22;
2598
2678
  return this.fetchOrdersByHttp(toFetch);
2599
2679
  case 22:
2600
- freshOrders = _context20.sent;
2680
+ freshOrders = _context21.sent;
2601
2681
  if (!(freshOrders.length > 0)) {
2602
- _context20.next = 28;
2682
+ _context21.next = 28;
2603
2683
  break;
2604
2684
  }
2605
- _context20.next = 26;
2685
+ _context21.next = 26;
2606
2686
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
2607
2687
  case 26:
2608
- _context20.next = 28;
2688
+ _context21.next = 28;
2609
2689
  break;
2610
2690
  case 28:
2611
2691
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
2612
- _context20.next = 30;
2692
+ _context21.next = 30;
2613
2693
  break;
2614
2694
  }
2615
- return _context20.abrupt("return");
2695
+ return _context21.abrupt("return");
2616
2696
  case 30:
2617
2697
  batchProcessEndAt = Date.now();
2618
2698
  this.logInfo('processOrderSyncMessages-结束', {
@@ -2621,13 +2701,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2621
2701
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
2622
2702
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
2623
2703
  });
2624
- _context20.next = 34;
2704
+ _context21.next = 34;
2625
2705
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
2626
2706
  case 34:
2627
2707
  case "end":
2628
- return _context20.stop();
2708
+ return _context21.stop();
2629
2709
  }
2630
- }, _callee20, this);
2710
+ }, _callee21, this);
2631
2711
  }));
2632
2712
  function processOrderSyncMessages() {
2633
2713
  return _processOrderSyncMessages.apply(this, arguments);
@@ -2648,29 +2728,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2648
2728
  }, {
2649
2729
  key: "fetchOrdersByHttp",
2650
2730
  value: (function () {
2651
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(ids) {
2731
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(ids) {
2652
2732
  var _orderList, orderList;
2653
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2654
- while (1) switch (_context21.prev = _context21.next) {
2733
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2734
+ while (1) switch (_context22.prev = _context22.next) {
2655
2735
  case 0:
2656
2736
  if (!(!this.orderDataSource || ids.length === 0)) {
2657
- _context21.next = 2;
2737
+ _context22.next = 2;
2658
2738
  break;
2659
2739
  }
2660
- return _context21.abrupt("return", []);
2740
+ return _context22.abrupt("return", []);
2661
2741
  case 2:
2662
- _context21.prev = 2;
2742
+ _context22.prev = 2;
2663
2743
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
2664
- _context21.next = 8;
2744
+ _context22.next = 8;
2665
2745
  break;
2666
2746
  }
2667
- _context21.next = 6;
2747
+ _context22.next = 6;
2668
2748
  return this.orderDataSource.fetchOrdersByIds(ids);
2669
2749
  case 6:
2670
- _orderList = _context21.sent;
2671
- return _context21.abrupt("return", _orderList || []);
2750
+ _orderList = _context22.sent;
2751
+ return _context22.abrupt("return", _orderList || []);
2672
2752
  case 8:
2673
- _context21.next = 10;
2753
+ _context22.next = 10;
2674
2754
  return this.orderDataSource.run({
2675
2755
  http: {
2676
2756
  query: {
@@ -2679,19 +2759,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2679
2759
  }
2680
2760
  });
2681
2761
  case 10:
2682
- orderList = _context21.sent;
2683
- return _context21.abrupt("return", orderList || []);
2762
+ orderList = _context22.sent;
2763
+ return _context22.abrupt("return", orderList || []);
2684
2764
  case 14:
2685
- _context21.prev = 14;
2686
- _context21.t0 = _context21["catch"](2);
2687
- return _context21.abrupt("return", []);
2765
+ _context22.prev = 14;
2766
+ _context22.t0 = _context22["catch"](2);
2767
+ return _context22.abrupt("return", []);
2688
2768
  case 17:
2689
2769
  case "end":
2690
- return _context21.stop();
2770
+ return _context22.stop();
2691
2771
  }
2692
- }, _callee21, this, [[2, 14]]);
2772
+ }, _callee22, this, [[2, 14]]);
2693
2773
  }));
2694
- function fetchOrdersByHttp(_x14) {
2774
+ function fetchOrdersByHttp(_x15) {
2695
2775
  return _fetchOrdersByHttp.apply(this, arguments);
2696
2776
  }
2697
2777
  return fetchOrdersByHttp;
@@ -2703,11 +2783,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2703
2783
  }, {
2704
2784
  key: "mergeOrdersToStore",
2705
2785
  value: (function () {
2706
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(freshOrders, source) {
2707
- var _this17 = this;
2786
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(freshOrders, source) {
2787
+ var _this18 = this;
2708
2788
  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;
2709
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2710
- while (1) switch (_context22.prev = _context22.next) {
2789
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2790
+ while (1) switch (_context23.prev = _context23.next) {
2711
2791
  case 0:
2712
2792
  storeOrderCountBefore = this.store.list.length;
2713
2793
  this.logInfo('mergeOrdersToStore-开始', {
@@ -2719,20 +2799,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2719
2799
  normalizedFreshOrders = [];
2720
2800
  incomingProductsHaveStableIdentity = new Map();
2721
2801
  _iterator15 = _createForOfIteratorHelper(freshOrders);
2722
- _context22.prev = 6;
2802
+ _context23.prev = 6;
2723
2803
  _iterator15.s();
2724
2804
  case 8:
2725
2805
  if ((_step15 = _iterator15.n()).done) {
2726
- _context22.next = 18;
2806
+ _context23.next = 18;
2727
2807
  break;
2728
2808
  }
2729
2809
  order = _step15.value;
2730
2810
  id = order === null || order === void 0 ? void 0 : order.order_id;
2731
2811
  if (!(id === undefined || id === null)) {
2732
- _context22.next = 13;
2812
+ _context23.next = 13;
2733
2813
  break;
2734
2814
  }
2735
- return _context22.abrupt("continue", 16);
2815
+ return _context23.abrupt("continue", 16);
2736
2816
  case 13:
2737
2817
  rawProducts = order.products;
2738
2818
  if (Array.isArray(rawProducts)) {
@@ -2742,19 +2822,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2742
2822
  }
2743
2823
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2744
2824
  case 16:
2745
- _context22.next = 8;
2825
+ _context23.next = 8;
2746
2826
  break;
2747
2827
  case 18:
2748
- _context22.next = 23;
2828
+ _context23.next = 23;
2749
2829
  break;
2750
2830
  case 20:
2751
- _context22.prev = 20;
2752
- _context22.t0 = _context22["catch"](6);
2753
- _iterator15.e(_context22.t0);
2831
+ _context23.prev = 20;
2832
+ _context23.t0 = _context23["catch"](6);
2833
+ _iterator15.e(_context23.t0);
2754
2834
  case 23:
2755
- _context22.prev = 23;
2835
+ _context23.prev = 23;
2756
2836
  _iterator15.f();
2757
- return _context22.finish(23);
2837
+ return _context23.finish(23);
2758
2838
  case 26:
2759
2839
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2760
2840
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
@@ -2765,10 +2845,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2765
2845
  storageKeyMigrations = [];
2766
2846
  mergeActions = {};
2767
2847
  existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2768
- return _this17.doProductsHaveStableMembershipIdentity(order.products);
2848
+ return _this18.doProductsHaveStableMembershipIdentity(order.products);
2769
2849
  });
2770
2850
  updatedList = this.store.list.map(function (order) {
2771
- return _this17.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2851
+ return _this18.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2772
2852
  }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
2773
2853
  // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
2774
2854
  // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
@@ -2789,11 +2869,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2789
2869
  }
2790
2870
  }
2791
2871
  _iterator17 = _createForOfIteratorHelper(uniqueFreshOrders);
2792
- _context22.prev = 38;
2872
+ _context23.prev = 38;
2793
2873
  _iterator17.s();
2794
2874
  case 40:
2795
2875
  if ((_step17 = _iterator17.n()).done) {
2796
- _context22.next = 100;
2876
+ _context23.next = 100;
2797
2877
  break;
2798
2878
  }
2799
2879
  fresh = _step17.value;
@@ -2802,13 +2882,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2802
2882
  storageKey = this.getOrderStorageKey(fresh);
2803
2883
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2804
2884
  if (!(matchIndex >= 0)) {
2805
- _context22.next = 92;
2885
+ _context23.next = 92;
2806
2886
  break;
2807
2887
  }
2808
2888
  existingOrder = updatedList[matchIndex];
2809
2889
  previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2810
2890
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2811
- _context22.next = 52;
2891
+ _context23.next = 52;
2812
2892
  break;
2813
2893
  }
2814
2894
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2821,10 +2901,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2821
2901
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2822
2902
  reason: 'protect_pending_sync_order_from_remote_echo'
2823
2903
  });
2824
- return _context22.abrupt("continue", 98);
2904
+ return _context23.abrupt("continue", 98);
2825
2905
  case 52:
2826
2906
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2827
- _context22.next = 55;
2907
+ _context23.next = 55;
2828
2908
  break;
2829
2909
  }
2830
2910
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2835,7 +2915,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2835
2915
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2836
2916
  reason: 'protect_draft_order_from_remote_echo'
2837
2917
  });
2838
- return _context22.abrupt("continue", 98);
2918
+ return _context23.abrupt("continue", 98);
2839
2919
  case 55:
2840
2920
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2841
2921
  freshOrderId = fresh.order_id;
@@ -2848,36 +2928,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2848
2928
  adjustedMatchIndex = matchIndex;
2849
2929
  duplicateIndexes = new Set();
2850
2930
  _iterator18 = _createForOfIteratorHelper(freshIdentityKeys);
2851
- _context22.prev = 64;
2931
+ _context23.prev = 64;
2852
2932
  _iterator18.s();
2853
2933
  case 66:
2854
2934
  if ((_step18 = _iterator18.n()).done) {
2855
- _context22.next = 74;
2935
+ _context23.next = 74;
2856
2936
  break;
2857
2937
  }
2858
2938
  _key2 = _step18.value;
2859
2939
  _duplicateIndex = identityKeyToIndex.get(_key2);
2860
2940
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2861
- _context22.next = 71;
2941
+ _context23.next = 71;
2862
2942
  break;
2863
2943
  }
2864
- return _context22.abrupt("continue", 72);
2944
+ return _context23.abrupt("continue", 72);
2865
2945
  case 71:
2866
2946
  duplicateIndexes.add(_duplicateIndex);
2867
2947
  case 72:
2868
- _context22.next = 66;
2948
+ _context23.next = 66;
2869
2949
  break;
2870
2950
  case 74:
2871
- _context22.next = 79;
2951
+ _context23.next = 79;
2872
2952
  break;
2873
2953
  case 76:
2874
- _context22.prev = 76;
2875
- _context22.t1 = _context22["catch"](64);
2876
- _iterator18.e(_context22.t1);
2954
+ _context23.prev = 76;
2955
+ _context23.t1 = _context23["catch"](64);
2956
+ _iterator18.e(_context23.t1);
2877
2957
  case 79:
2878
- _context22.prev = 79;
2958
+ _context23.prev = 79;
2879
2959
  _iterator18.f();
2880
- return _context22.finish(79);
2960
+ return _context23.finish(79);
2881
2961
  case 82:
2882
2962
  if (duplicateIndexes.size > 0) {
2883
2963
  _iterator19 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
@@ -2932,7 +3012,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2932
3012
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2933
3013
  patchedOrders.push(mergedOrder);
2934
3014
  if (mergeKey) mergeActions[mergeKey] = 'update';
2935
- return _context22.abrupt("continue", 98);
3015
+ return _context23.abrupt("continue", 98);
2936
3016
  case 92:
2937
3017
  insertIndex = updatedList.length;
2938
3018
  updatedList.push(fresh);
@@ -2941,19 +3021,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2941
3021
  patchedOrders.push(fresh);
2942
3022
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2943
3023
  case 98:
2944
- _context22.next = 40;
3024
+ _context23.next = 40;
2945
3025
  break;
2946
3026
  case 100:
2947
- _context22.next = 105;
3027
+ _context23.next = 105;
2948
3028
  break;
2949
3029
  case 102:
2950
- _context22.prev = 102;
2951
- _context22.t2 = _context22["catch"](38);
2952
- _iterator17.e(_context22.t2);
3030
+ _context23.prev = 102;
3031
+ _context23.t2 = _context23["catch"](38);
3032
+ _iterator17.e(_context23.t2);
2953
3033
  case 105:
2954
- _context22.prev = 105;
3034
+ _context23.prev = 105;
2955
3035
  _iterator17.f();
2956
- return _context22.finish(105);
3036
+ return _context23.finish(105);
2957
3037
  case 108:
2958
3038
  insertCount = Object.values(mergeActions).filter(function (v) {
2959
3039
  return v === 'insert';
@@ -2970,7 +3050,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2970
3050
  // 仅在自检开关开启时做一次兜底校验。
2971
3051
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2972
3052
  this.syncOrdersMap();
2973
- _context22.next = 115;
3053
+ _context23.next = 115;
2974
3054
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
2975
3055
  storageKeyMigrations: storageKeyMigrations
2976
3056
  }, forceWriteStorageKeys);
@@ -2981,18 +3061,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2981
3061
  insertCount: insertCount,
2982
3062
  updateCount: updateCount
2983
3063
  });
2984
- _context22.next = 118;
3064
+ _context23.next = 118;
2985
3065
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2986
3066
  case 118:
2987
- _context22.next = 120;
3067
+ _context23.next = 120;
2988
3068
  return this.emitOrdersChanged(patchedOrders, source);
2989
3069
  case 120:
2990
3070
  case "end":
2991
- return _context22.stop();
3071
+ return _context23.stop();
2992
3072
  }
2993
- }, _callee22, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
3073
+ }, _callee23, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
2994
3074
  }));
2995
- function mergeOrdersToStore(_x15, _x16) {
3075
+ function mergeOrdersToStore(_x16, _x17) {
2996
3076
  return _mergeOrdersToStore.apply(this, arguments);
2997
3077
  }
2998
3078
  return mergeOrdersToStore;
@@ -3072,7 +3152,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3072
3152
  }, {
3073
3153
  key: "getRemoteProductMembershipChange",
3074
3154
  value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
3075
- var _this18 = this,
3155
+ var _this19 = this,
3076
3156
  _mergedOrder$order_id2;
3077
3157
  if (!this.isRemoteProductMembershipChangeSource(source)) return null;
3078
3158
  var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
@@ -3087,13 +3167,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3087
3167
  var _loop2 = function _loop2() {
3088
3168
  var previousProduct = _step22.value;
3089
3169
  var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
3090
- return unmatchedCurrentIndexes.has(index) && _this18.isSameProductMembershipItem(previousProduct, currentProduct);
3170
+ return unmatchedCurrentIndexes.has(index) && _this19.isSameProductMembershipItem(previousProduct, currentProduct);
3091
3171
  });
3092
3172
  if (matchedIndex >= 0) {
3093
3173
  unmatchedCurrentIndexes.delete(matchedIndex);
3094
3174
  return 1; // continue
3095
3175
  }
3096
- var productKey = _this18.getProductMembershipKey(previousProduct);
3176
+ var productKey = _this19.getProductMembershipKey(previousProduct);
3097
3177
  if (productKey) removedProductKeys.push(productKey);
3098
3178
  };
3099
3179
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
@@ -3105,7 +3185,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3105
3185
  _iterator22.f();
3106
3186
  }
3107
3187
  var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
3108
- return _this18.getProductMembershipKey(currentProducts[index]);
3188
+ return _this19.getProductMembershipKey(currentProducts[index]);
3109
3189
  }).filter(Boolean);
3110
3190
  if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
3111
3191
  return null;
@@ -3220,12 +3300,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3220
3300
  }, {
3221
3301
  key: "isOrderLookupMatch",
3222
3302
  value: function isOrderLookupMatch(order, lookupKey) {
3223
- var _this19 = this;
3303
+ var _this20 = this;
3224
3304
  if (!order || !lookupKey) return false;
3225
3305
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
3226
3306
  return candidates.some(function (value) {
3227
3307
  if (value === undefined || value === null || value === '') return false;
3228
- return _this19.getIdKey(value) === lookupKey;
3308
+ return _this20.getIdKey(value) === lookupKey;
3229
3309
  });
3230
3310
  }
3231
3311
 
@@ -3277,10 +3357,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3277
3357
  }, {
3278
3358
  key: "findOrderIndexByIdentity",
3279
3359
  value: function findOrderIndexByIdentity(orders, target) {
3280
- var _this20 = this;
3360
+ var _this21 = this;
3281
3361
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
3282
3362
  return orders.findIndex(function (order) {
3283
- return _this20.doOrdersShareIdentity(order, target);
3363
+ return _this21.doOrdersShareIdentity(order, target);
3284
3364
  });
3285
3365
  }
3286
3366
  }, {
@@ -3436,8 +3516,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3436
3516
  mergedRecord.metadata = _objectSpread(_objectSpread({}, mergedRecord.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
3437
3517
  }
3438
3518
  var childUidRemaps = [];
3439
- for (var _i4 = 0, _fieldsToPreserve = fieldsToPreserve; _i4 < _fieldsToPreserve.length; _i4++) {
3440
- var field = _fieldsToPreserve[_i4];
3519
+ for (var _i5 = 0, _fieldsToPreserve = fieldsToPreserve; _i5 < _fieldsToPreserve.length; _i5++) {
3520
+ var field = _fieldsToPreserve[_i5];
3441
3521
  if (!this.isBlankIdentityValue(preferredRecord[field])) {
3442
3522
  mergedRecord[field] = preferredRecord[field];
3443
3523
  continue;
@@ -3446,8 +3526,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3446
3526
  mergedRecord[field] = secondaryRecord[field];
3447
3527
  }
3448
3528
  }
3449
- for (var _i5 = 0, _incomingPatchFields = incomingPatchFields; _i5 < _incomingPatchFields.length; _i5++) {
3450
- var _field = _incomingPatchFields[_i5];
3529
+ for (var _i6 = 0, _incomingPatchFields = incomingPatchFields; _i6 < _incomingPatchFields.length; _i6++) {
3530
+ var _field = _incomingPatchFields[_i6];
3451
3531
  if (!Object.prototype.hasOwnProperty.call(incomingRecord, _field)) continue;
3452
3532
  if (incomingRecord[_field] === undefined || incomingRecord[_field] === null) continue;
3453
3533
  if (typeof incomingRecord[_field] === 'string' && incomingRecord[_field] === '') continue;
@@ -3462,8 +3542,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3462
3542
 
3463
3543
  // 子项数组遵循完整快照语义:incoming 自有且为数组(包括 [])时权威替换;
3464
3544
  // 字段缺席或不是数组时视为稀疏 patch,继续保留 existing。
3465
- for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
3466
- var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
3545
+ for (var _i7 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i7 < _ORDER_AUTHORITATIVE_2.length; _i7++) {
3546
+ var _field2 = _ORDER_AUTHORITATIVE_2[_i7];
3467
3547
  if (Array.isArray(incomingRecord[_field2])) {
3468
3548
  if (_field2 === 'payments') {
3469
3549
  var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
@@ -3714,8 +3794,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3714
3794
  }, {
3715
3795
  key: "loadOrdersFromSQLite",
3716
3796
  value: function () {
3717
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
3718
- var _this21 = this;
3797
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
3798
+ var _this22 = this;
3719
3799
  var options,
3720
3800
  _options$onTiming,
3721
3801
  loadStartedAt,
@@ -3725,28 +3805,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3725
3805
  normalizeStartedAt,
3726
3806
  normalizedOrders,
3727
3807
  sqliteNormalizeMs,
3728
- _args23 = arguments;
3729
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3730
- while (1) switch (_context23.prev = _context23.next) {
3808
+ _args24 = arguments;
3809
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3810
+ while (1) switch (_context24.prev = _context24.next) {
3731
3811
  case 0:
3732
- options = _args23.length > 0 && _args23[0] !== undefined ? _args23[0] : {};
3812
+ options = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : {};
3733
3813
  if (this.dbManager) {
3734
- _context23.next = 3;
3814
+ _context24.next = 3;
3735
3815
  break;
3736
3816
  }
3737
- return _context23.abrupt("return", []);
3817
+ return _context24.abrupt("return", []);
3738
3818
  case 3:
3739
- _context23.prev = 3;
3819
+ _context24.prev = 3;
3740
3820
  loadStartedAt = performance.now();
3741
3821
  rawReadStartedAt = performance.now();
3742
- _context23.next = 8;
3822
+ _context24.next = 8;
3743
3823
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3744
3824
  case 8:
3745
- orders = _context23.sent;
3825
+ orders = _context24.sent;
3746
3826
  sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3747
3827
  normalizeStartedAt = performance.now();
3748
3828
  normalizedOrders = (orders || []).map(function (order) {
3749
- return _this21.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3829
+ return _this22.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3750
3830
  });
3751
3831
  sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3752
3832
  (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
@@ -3754,22 +3834,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3754
3834
  sqliteNormalizeMs: sqliteNormalizeMs,
3755
3835
  sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3756
3836
  });
3757
- return _context23.abrupt("return", normalizedOrders);
3837
+ return _context24.abrupt("return", normalizedOrders);
3758
3838
  case 17:
3759
- _context23.prev = 17;
3760
- _context23.t0 = _context23["catch"](3);
3839
+ _context24.prev = 17;
3840
+ _context24.t0 = _context24["catch"](3);
3761
3841
  if (!options.throwOnError) {
3762
- _context23.next = 21;
3842
+ _context24.next = 21;
3763
3843
  break;
3764
3844
  }
3765
- throw _context23.t0;
3845
+ throw _context24.t0;
3766
3846
  case 21:
3767
- return _context23.abrupt("return", []);
3847
+ return _context24.abrupt("return", []);
3768
3848
  case 22:
3769
3849
  case "end":
3770
- return _context23.stop();
3850
+ return _context24.stop();
3771
3851
  }
3772
- }, _callee23, this, [[3, 17]]);
3852
+ }, _callee24, this, [[3, 17]]);
3773
3853
  }));
3774
3854
  function loadOrdersFromSQLite() {
3775
3855
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3808,8 +3888,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3808
3888
  value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
3809
3889
  var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
3810
3890
  var remote = remoteOrder;
3811
- for (var _i7 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i7 < _arr.length; _i7++) {
3812
- var field = _arr[_i7];
3891
+ for (var _i8 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i8 < _arr.length; _i8++) {
3892
+ var field = _arr[_i8];
3813
3893
  if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
3814
3894
  merged[field] = remote[field];
3815
3895
  }
@@ -3819,9 +3899,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3819
3899
  }, {
3820
3900
  key: "mergeRemoteSnapshotWithPendingOrders",
3821
3901
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3822
- var _this22 = this;
3902
+ var _this23 = this;
3823
3903
  var merged = remoteOrders.map(function (order) {
3824
- return _this22.normalizeRemoteSyncedOrder(order);
3904
+ return _this23.normalizeRemoteSyncedOrder(order);
3825
3905
  });
3826
3906
  var _iterator32 = _createForOfIteratorHelper(existingOrders),
3827
3907
  _step32;
@@ -3861,10 +3941,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3861
3941
  }, {
3862
3942
  key: "runInOrderSQLiteSaveQueue",
3863
3943
  value: (function () {
3864
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(task) {
3944
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(task) {
3865
3945
  var queuedTask;
3866
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3867
- while (1) switch (_context24.prev = _context24.next) {
3946
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3947
+ while (1) switch (_context25.prev = _context25.next) {
3868
3948
  case 0:
3869
3949
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3870
3950
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3872,14 +3952,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3872
3952
  }, function () {
3873
3953
  return undefined;
3874
3954
  });
3875
- return _context24.abrupt("return", queuedTask);
3955
+ return _context25.abrupt("return", queuedTask);
3876
3956
  case 3:
3877
3957
  case "end":
3878
- return _context24.stop();
3958
+ return _context25.stop();
3879
3959
  }
3880
- }, _callee24, this);
3960
+ }, _callee25, this);
3881
3961
  }));
3882
- function runInOrderSQLiteSaveQueue(_x17) {
3962
+ function runInOrderSQLiteSaveQueue(_x18) {
3883
3963
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
3884
3964
  }
3885
3965
  return runInOrderSQLiteSaveQueue;
@@ -3894,8 +3974,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3894
3974
  }, {
3895
3975
  key: "patchOrdersInSQLite",
3896
3976
  value: (function () {
3897
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orders, source) {
3898
- var _this23 = this;
3977
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orders, source) {
3978
+ var _this24 = this;
3899
3979
  var mergeActions,
3900
3980
  options,
3901
3981
  forceWriteStorageKeys,
@@ -3910,264 +3990,264 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3910
3990
  _iterator33,
3911
3991
  _step33,
3912
3992
  migration,
3913
- _args26 = arguments;
3914
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3915
- while (1) switch (_context26.prev = _context26.next) {
3993
+ _args27 = arguments;
3994
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3995
+ while (1) switch (_context27.prev = _context27.next) {
3916
3996
  case 0:
3917
- mergeActions = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : {};
3918
- options = _args26.length > 3 && _args26[3] !== undefined ? _args26[3] : {};
3919
- forceWriteStorageKeys = _args26.length > 4 && _args26[4] !== undefined ? _args26[4] : new Set();
3997
+ mergeActions = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : {};
3998
+ options = _args27.length > 3 && _args27[3] !== undefined ? _args27[3] : {};
3999
+ forceWriteStorageKeys = _args27.length > 4 && _args27[4] !== undefined ? _args27[4] : new Set();
3920
4000
  if (!(orders.length === 0)) {
3921
- _context26.next = 5;
4001
+ _context27.next = 5;
3922
4002
  break;
3923
4003
  }
3924
- return _context26.abrupt("return");
4004
+ return _context27.abrupt("return");
3925
4005
  case 5:
3926
4006
  if (this.dbManager) {
3927
- _context26.next = 9;
4007
+ _context27.next = 9;
3928
4008
  break;
3929
4009
  }
3930
4010
  if (!options.throwOnError) {
3931
- _context26.next = 8;
4011
+ _context27.next = 8;
3932
4012
  break;
3933
4013
  }
3934
4014
  throw new Error('订单 SQLite 数据库未初始化');
3935
4015
  case 8:
3936
- return _context26.abrupt("return");
4016
+ return _context27.abrupt("return");
3937
4017
  case 9:
3938
4018
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3939
4019
  return migration.to;
3940
4020
  }));
3941
4021
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3942
- return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
4022
+ return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3943
4023
  }).map(function (order) {
3944
- var storageKey = _this23.getOrderStorageKey(order);
4024
+ var storageKey = _this24.getOrderStorageKey(order);
3945
4025
  if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
3946
4026
  return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
3947
4027
  }).filter(function (order) {
3948
- return _this23.getOrderStorageKey(order);
4028
+ return _this24.getOrderStorageKey(order);
3949
4029
  });
3950
4030
  if (!(ordersSnapshot.length === 0)) {
3951
- _context26.next = 13;
4031
+ _context27.next = 13;
3952
4032
  break;
3953
4033
  }
3954
- return _context26.abrupt("return");
4034
+ return _context27.abrupt("return");
3955
4035
  case 13:
3956
4036
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3957
4037
  if (!(toWrite.length === 0)) {
3958
- _context26.next = 16;
4038
+ _context27.next = 16;
3959
4039
  break;
3960
4040
  }
3961
- return _context26.abrupt("return");
4041
+ return _context27.abrupt("return");
3962
4042
  case 16:
3963
4043
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3964
4044
  if (!(compactedToWrite.length === 0)) {
3965
- _context26.next = 19;
4045
+ _context27.next = 19;
3966
4046
  break;
3967
4047
  }
3968
- return _context26.abrupt("return");
4048
+ return _context27.abrupt("return");
3969
4049
  case 19:
3970
4050
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3971
- return _this23.getOrderStorageKey(order);
4051
+ return _this24.getOrderStorageKey(order);
3972
4052
  }).filter(Boolean));
3973
4053
  storageKeyMigrations = new Map();
3974
4054
  _iterator33 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
3975
- _context26.prev = 22;
4055
+ _context27.prev = 22;
3976
4056
  _iterator33.s();
3977
4057
  case 24:
3978
4058
  if ((_step33 = _iterator33.n()).done) {
3979
- _context26.next = 33;
4059
+ _context27.next = 33;
3980
4060
  break;
3981
4061
  }
3982
4062
  migration = _step33.value;
3983
4063
  if (writtenStorageKeys.has(migration.to)) {
3984
- _context26.next = 28;
4064
+ _context27.next = 28;
3985
4065
  break;
3986
4066
  }
3987
- return _context26.abrupt("continue", 31);
4067
+ return _context27.abrupt("continue", 31);
3988
4068
  case 28:
3989
4069
  if (!writtenStorageKeys.has(migration.from)) {
3990
- _context26.next = 30;
4070
+ _context27.next = 30;
3991
4071
  break;
3992
4072
  }
3993
- return _context26.abrupt("continue", 31);
4073
+ return _context27.abrupt("continue", 31);
3994
4074
  case 30:
3995
4075
  storageKeyMigrations.set(migration.from, migration);
3996
4076
  case 31:
3997
- _context26.next = 24;
4077
+ _context27.next = 24;
3998
4078
  break;
3999
4079
  case 33:
4000
- _context26.next = 38;
4080
+ _context27.next = 38;
4001
4081
  break;
4002
4082
  case 35:
4003
- _context26.prev = 35;
4004
- _context26.t0 = _context26["catch"](22);
4005
- _iterator33.e(_context26.t0);
4083
+ _context27.prev = 35;
4084
+ _context27.t0 = _context27["catch"](22);
4085
+ _iterator33.e(_context27.t0);
4006
4086
  case 38:
4007
- _context26.prev = 38;
4087
+ _context27.prev = 38;
4008
4088
  _iterator33.f();
4009
- return _context26.finish(38);
4089
+ return _context27.finish(38);
4010
4090
  case 41:
4011
- _context26.prev = 41;
4012
- _context26.next = 44;
4013
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4091
+ _context27.prev = 41;
4092
+ _context27.next = 44;
4093
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4014
4094
  var writeMethod, _iterator34, _step34, order, _iterator35, _step35, migration, _iterator36, _step36, _orderRecord$ORDER_ST, _order, orderRecord;
4015
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4016
- while (1) switch (_context25.prev = _context25.next) {
4095
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4096
+ while (1) switch (_context26.prev = _context26.next) {
4017
4097
  case 0:
4018
4098
  writeMethod = 'none';
4019
- _this23.logInfo('patchOrdersInSQLite-开始', {
4099
+ _this24.logInfo('patchOrdersInSQLite-开始', {
4020
4100
  source: source,
4021
4101
  count: compactedToWrite.length,
4022
4102
  dedupedCount: skipped.length
4023
4103
  });
4024
- if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
4025
- _context25.next = 8;
4104
+ if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4105
+ _context26.next = 8;
4026
4106
  break;
4027
4107
  }
4028
4108
  writeMethod = 'bulkUpdate';
4029
- _context25.next = 6;
4030
- return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
4109
+ _context26.next = 6;
4110
+ return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
4031
4111
  case 6:
4032
- _context25.next = 37;
4112
+ _context26.next = 37;
4033
4113
  break;
4034
4114
  case 8:
4035
- if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
4036
- _context25.next = 14;
4115
+ if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4116
+ _context26.next = 14;
4037
4117
  break;
4038
4118
  }
4039
4119
  writeMethod = 'bulkAdd';
4040
- _context25.next = 12;
4041
- return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
4120
+ _context26.next = 12;
4121
+ return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
4042
4122
  case 12:
4043
- _context25.next = 37;
4123
+ _context26.next = 37;
4044
4124
  break;
4045
4125
  case 14:
4046
- if (!(typeof _this23.dbManager.update === 'function')) {
4047
- _context25.next = 35;
4126
+ if (!(typeof _this24.dbManager.update === 'function')) {
4127
+ _context26.next = 35;
4048
4128
  break;
4049
4129
  }
4050
4130
  writeMethod = 'update';
4051
4131
  _iterator34 = _createForOfIteratorHelper(compactedToWrite);
4052
- _context25.prev = 17;
4132
+ _context26.prev = 17;
4053
4133
  _iterator34.s();
4054
4134
  case 19:
4055
4135
  if ((_step34 = _iterator34.n()).done) {
4056
- _context25.next = 25;
4136
+ _context26.next = 25;
4057
4137
  break;
4058
4138
  }
4059
4139
  order = _step34.value;
4060
- _context25.next = 23;
4061
- return _this23.dbManager.update(INDEXDB_STORE_NAME, order);
4140
+ _context26.next = 23;
4141
+ return _this24.dbManager.update(INDEXDB_STORE_NAME, order);
4062
4142
  case 23:
4063
- _context25.next = 19;
4143
+ _context26.next = 19;
4064
4144
  break;
4065
4145
  case 25:
4066
- _context25.next = 30;
4146
+ _context26.next = 30;
4067
4147
  break;
4068
4148
  case 27:
4069
- _context25.prev = 27;
4070
- _context25.t0 = _context25["catch"](17);
4071
- _iterator34.e(_context25.t0);
4149
+ _context26.prev = 27;
4150
+ _context26.t0 = _context26["catch"](17);
4151
+ _iterator34.e(_context26.t0);
4072
4152
  case 30:
4073
- _context25.prev = 30;
4153
+ _context26.prev = 30;
4074
4154
  _iterator34.f();
4075
- return _context25.finish(30);
4155
+ return _context26.finish(30);
4076
4156
  case 33:
4077
- _context25.next = 37;
4157
+ _context26.next = 37;
4078
4158
  break;
4079
4159
  case 35:
4080
4160
  if (!options.throwOnError) {
4081
- _context25.next = 37;
4161
+ _context26.next = 37;
4082
4162
  break;
4083
4163
  }
4084
4164
  throw new Error('订单 SQLite 数据库不支持写入');
4085
4165
  case 37:
4086
- _this23.recordRecentSqliteWrite(source, compactedToWrite);
4166
+ _this24.recordRecentSqliteWrite(source, compactedToWrite);
4087
4167
  if (!(writeMethod !== 'none')) {
4088
- _context25.next = 84;
4168
+ _context26.next = 84;
4089
4169
  break;
4090
4170
  }
4091
4171
  _iterator35 = _createForOfIteratorHelper(storageKeyMigrations.values());
4092
- _context25.prev = 40;
4172
+ _context26.prev = 40;
4093
4173
  _iterator35.s();
4094
4174
  case 42:
4095
4175
  if ((_step35 = _iterator35.n()).done) {
4096
- _context25.next = 76;
4176
+ _context26.next = 76;
4097
4177
  break;
4098
4178
  }
4099
4179
  migration = _step35.value;
4100
- _context25.prev = 44;
4101
- _context25.next = 47;
4102
- return _this23.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4180
+ _context26.prev = 44;
4181
+ _context26.next = 47;
4182
+ return _this24.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4103
4183
  case 47:
4104
- _this23.recentSqliteWriteByStorageKey.delete(migration.from);
4184
+ _this24.recentSqliteWriteByStorageKey.delete(migration.from);
4105
4185
  _iterator36 = _createForOfIteratorHelper(orders);
4106
- _context25.prev = 49;
4186
+ _context26.prev = 49;
4107
4187
  _iterator36.s();
4108
4188
  case 51:
4109
4189
  if ((_step36 = _iterator36.n()).done) {
4110
- _context25.next = 61;
4190
+ _context26.next = 61;
4111
4191
  break;
4112
4192
  }
4113
4193
  _order = _step36.value;
4114
- if (!(_this23.getOrderStorageKey(_order) !== migration.to)) {
4115
- _context25.next = 55;
4194
+ if (!(_this24.getOrderStorageKey(_order) !== migration.to)) {
4195
+ _context26.next = 55;
4116
4196
  break;
4117
4197
  }
4118
- return _context25.abrupt("continue", 59);
4198
+ return _context26.abrupt("continue", 59);
4119
4199
  case 55:
4120
4200
  orderRecord = _order;
4121
4201
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
4122
- _context25.next = 58;
4202
+ _context26.next = 58;
4123
4203
  break;
4124
4204
  }
4125
- return _context25.abrupt("continue", 59);
4205
+ return _context26.abrupt("continue", 59);
4126
4206
  case 58:
4127
4207
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
4128
4208
  case 59:
4129
- _context25.next = 51;
4209
+ _context26.next = 51;
4130
4210
  break;
4131
4211
  case 61:
4132
- _context25.next = 66;
4212
+ _context26.next = 66;
4133
4213
  break;
4134
4214
  case 63:
4135
- _context25.prev = 63;
4136
- _context25.t1 = _context25["catch"](49);
4137
- _iterator36.e(_context25.t1);
4215
+ _context26.prev = 63;
4216
+ _context26.t1 = _context26["catch"](49);
4217
+ _iterator36.e(_context26.t1);
4138
4218
  case 66:
4139
- _context25.prev = 66;
4219
+ _context26.prev = 66;
4140
4220
  _iterator36.f();
4141
- return _context25.finish(66);
4221
+ return _context26.finish(66);
4142
4222
  case 69:
4143
- _context25.next = 74;
4223
+ _context26.next = 74;
4144
4224
  break;
4145
4225
  case 71:
4146
- _context25.prev = 71;
4147
- _context25.t2 = _context25["catch"](44);
4148
- _this23.logError('删除订单旧 SQLite storage key 失败', {
4226
+ _context26.prev = 71;
4227
+ _context26.t2 = _context26["catch"](44);
4228
+ _this24.logError('删除订单旧 SQLite storage key 失败', {
4149
4229
  source: source,
4150
4230
  order_id: migration.orderId,
4151
4231
  oldStorageKey: migration.from,
4152
4232
  newStorageKey: migration.to,
4153
- error: _context25.t2 instanceof Error ? _context25.t2.message : String(_context25.t2)
4233
+ error: _context26.t2 instanceof Error ? _context26.t2.message : String(_context26.t2)
4154
4234
  });
4155
4235
  case 74:
4156
- _context25.next = 42;
4236
+ _context26.next = 42;
4157
4237
  break;
4158
4238
  case 76:
4159
- _context25.next = 81;
4239
+ _context26.next = 81;
4160
4240
  break;
4161
4241
  case 78:
4162
- _context25.prev = 78;
4163
- _context25.t3 = _context25["catch"](40);
4164
- _iterator35.e(_context25.t3);
4242
+ _context26.prev = 78;
4243
+ _context26.t3 = _context26["catch"](40);
4244
+ _iterator35.e(_context26.t3);
4165
4245
  case 81:
4166
- _context25.prev = 81;
4246
+ _context26.prev = 81;
4167
4247
  _iterator35.f();
4168
- return _context25.finish(81);
4248
+ return _context26.finish(81);
4169
4249
  case 84:
4170
- _this23.logInfo('patchOrdersInSQLite-完成', {
4250
+ _this24.logInfo('patchOrdersInSQLite-完成', {
4171
4251
  source: source,
4172
4252
  count: compactedToWrite.length,
4173
4253
  writeMethod: writeMethod,
@@ -4175,32 +4255,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4175
4255
  });
4176
4256
  case 85:
4177
4257
  case "end":
4178
- return _context25.stop();
4258
+ return _context26.stop();
4179
4259
  }
4180
- }, _callee25, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4260
+ }, _callee26, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4181
4261
  })));
4182
4262
  case 44:
4183
- _context26.next = 51;
4263
+ _context27.next = 51;
4184
4264
  break;
4185
4265
  case 46:
4186
- _context26.prev = 46;
4187
- _context26.t1 = _context26["catch"](41);
4266
+ _context27.prev = 46;
4267
+ _context27.t1 = _context27["catch"](41);
4188
4268
  this.logError('增量保存订单到 SQLite 失败', {
4189
- error: _context26.t1 instanceof Error ? _context26.t1.message : String(_context26.t1),
4269
+ error: _context27.t1 instanceof Error ? _context27.t1.message : String(_context27.t1),
4190
4270
  orderCount: ordersSnapshot.length
4191
4271
  });
4192
4272
  if (!options.throwOnError) {
4193
- _context26.next = 51;
4273
+ _context27.next = 51;
4194
4274
  break;
4195
4275
  }
4196
- throw _context26.t1;
4276
+ throw _context27.t1;
4197
4277
  case 51:
4198
4278
  case "end":
4199
- return _context26.stop();
4279
+ return _context27.stop();
4200
4280
  }
4201
- }, _callee26, this, [[22, 35, 38, 41], [41, 46]]);
4281
+ }, _callee27, this, [[22, 35, 38, 41], [41, 46]]);
4202
4282
  }));
4203
- function patchOrdersInSQLite(_x18, _x19) {
4283
+ function patchOrdersInSQLite(_x19, _x20) {
4204
4284
  return _patchOrdersInSQLite.apply(this, arguments);
4205
4285
  }
4206
4286
  return patchOrdersInSQLite;
@@ -4215,128 +4295,128 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4215
4295
  }, {
4216
4296
  key: "updateOrderInSQLite",
4217
4297
  value: (function () {
4218
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(order, source) {
4219
- var _this24 = this;
4298
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order, source) {
4299
+ var _this25 = this;
4220
4300
  var options,
4221
4301
  orderSnapshot,
4222
4302
  _orderSnapshot$order_3,
4223
- _args28 = arguments;
4224
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4225
- while (1) switch (_context28.prev = _context28.next) {
4303
+ _args29 = arguments;
4304
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4305
+ while (1) switch (_context29.prev = _context29.next) {
4226
4306
  case 0:
4227
- options = _args28.length > 2 && _args28[2] !== undefined ? _args28[2] : {};
4307
+ options = _args29.length > 2 && _args29[2] !== undefined ? _args29[2] : {};
4228
4308
  if (this.getOrderStorageKey(order)) {
4229
- _context28.next = 5;
4309
+ _context29.next = 5;
4230
4310
  break;
4231
4311
  }
4232
4312
  if (!options.throwOnError) {
4233
- _context28.next = 4;
4313
+ _context29.next = 4;
4234
4314
  break;
4235
4315
  }
4236
4316
  throw new Error('订单缺少可用的 SQLite 存储主键');
4237
4317
  case 4:
4238
- return _context28.abrupt("return");
4318
+ return _context29.abrupt("return");
4239
4319
  case 5:
4240
4320
  if (this.dbManager) {
4241
- _context28.next = 9;
4321
+ _context29.next = 9;
4242
4322
  break;
4243
4323
  }
4244
4324
  if (!options.throwOnError) {
4245
- _context28.next = 8;
4325
+ _context29.next = 8;
4246
4326
  break;
4247
4327
  }
4248
4328
  throw new Error('订单 SQLite 数据库未初始化');
4249
4329
  case 8:
4250
- return _context28.abrupt("return");
4330
+ return _context29.abrupt("return");
4251
4331
  case 9:
4252
4332
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4253
- _context28.prev = 10;
4254
- _context28.next = 13;
4255
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4333
+ _context29.prev = 10;
4334
+ _context29.next = 13;
4335
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4256
4336
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4257
4337
  var writeMethod;
4258
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4259
- while (1) switch (_context27.prev = _context27.next) {
4338
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4339
+ while (1) switch (_context28.prev = _context28.next) {
4260
4340
  case 0:
4261
4341
  writeMethod = 'none';
4262
- _this24.logInfo('updateOrderInSQLite-开始', {
4342
+ _this25.logInfo('updateOrderInSQLite-开始', {
4263
4343
  source: source,
4264
4344
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
4265
- storageKey: _this24.getOrderStorageKey(orderSnapshot)
4345
+ storageKey: _this25.getOrderStorageKey(orderSnapshot)
4266
4346
  });
4267
- if (!(typeof _this24.dbManager.update === 'function')) {
4268
- _context27.next = 8;
4347
+ if (!(typeof _this25.dbManager.update === 'function')) {
4348
+ _context28.next = 8;
4269
4349
  break;
4270
4350
  }
4271
4351
  writeMethod = 'update';
4272
- _context27.next = 6;
4273
- return _this24.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4352
+ _context28.next = 6;
4353
+ return _this25.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4274
4354
  case 6:
4275
- _context27.next = 22;
4355
+ _context28.next = 22;
4276
4356
  break;
4277
4357
  case 8:
4278
- if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4279
- _context27.next = 14;
4358
+ if (!(typeof _this25.dbManager.bulkUpdate === 'function')) {
4359
+ _context28.next = 14;
4280
4360
  break;
4281
4361
  }
4282
4362
  writeMethod = 'bulkUpdate';
4283
- _context27.next = 12;
4284
- return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4363
+ _context28.next = 12;
4364
+ return _this25.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4285
4365
  case 12:
4286
- _context27.next = 22;
4366
+ _context28.next = 22;
4287
4367
  break;
4288
4368
  case 14:
4289
- if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4290
- _context27.next = 20;
4369
+ if (!(typeof _this25.dbManager.bulkAdd === 'function')) {
4370
+ _context28.next = 20;
4291
4371
  break;
4292
4372
  }
4293
4373
  writeMethod = 'bulkAdd';
4294
- _context27.next = 18;
4295
- return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4374
+ _context28.next = 18;
4375
+ return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4296
4376
  case 18:
4297
- _context27.next = 22;
4377
+ _context28.next = 22;
4298
4378
  break;
4299
4379
  case 20:
4300
4380
  if (!options.throwOnError) {
4301
- _context27.next = 22;
4381
+ _context28.next = 22;
4302
4382
  break;
4303
4383
  }
4304
4384
  throw new Error('订单 SQLite 数据库不支持写入');
4305
4385
  case 22:
4306
- _this24.recordRecentSqliteWrite(source, [orderSnapshot]);
4307
- _this24.logInfo('updateOrderInSQLite-完成', {
4386
+ _this25.recordRecentSqliteWrite(source, [orderSnapshot]);
4387
+ _this25.logInfo('updateOrderInSQLite-完成', {
4308
4388
  source: source,
4309
4389
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
4310
4390
  writeMethod: writeMethod
4311
4391
  });
4312
4392
  case 24:
4313
4393
  case "end":
4314
- return _context27.stop();
4394
+ return _context28.stop();
4315
4395
  }
4316
- }, _callee27);
4396
+ }, _callee28);
4317
4397
  })));
4318
4398
  case 13:
4319
- _context28.next = 20;
4399
+ _context29.next = 20;
4320
4400
  break;
4321
4401
  case 15:
4322
- _context28.prev = 15;
4323
- _context28.t0 = _context28["catch"](10);
4402
+ _context29.prev = 15;
4403
+ _context29.t0 = _context29["catch"](10);
4324
4404
  this.logError('单条保存订单到 SQLite 失败', {
4325
- error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0),
4405
+ error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0),
4326
4406
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4327
4407
  });
4328
4408
  if (!options.throwOnError) {
4329
- _context28.next = 20;
4409
+ _context29.next = 20;
4330
4410
  break;
4331
4411
  }
4332
- throw _context28.t0;
4412
+ throw _context29.t0;
4333
4413
  case 20:
4334
4414
  case "end":
4335
- return _context28.stop();
4415
+ return _context29.stop();
4336
4416
  }
4337
- }, _callee28, this, [[10, 15]]);
4417
+ }, _callee29, this, [[10, 15]]);
4338
4418
  }));
4339
- function updateOrderInSQLite(_x20, _x21) {
4419
+ function updateOrderInSQLite(_x21, _x22) {
4340
4420
  return _updateOrderInSQLite.apply(this, arguments);
4341
4421
  }
4342
4422
  return updateOrderInSQLite;
@@ -4352,75 +4432,75 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4352
4432
  }, {
4353
4433
  key: "replaceOrdersSnapshotInSQLite",
4354
4434
  value: (function () {
4355
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(orderList, source) {
4356
- var _this25 = this;
4435
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderList, source) {
4436
+ var _this26 = this;
4357
4437
  var protectedOrdersBeforeRemoteFetch,
4358
4438
  remoteSnapshot,
4359
4439
  mergedSnapshot,
4360
4440
  persisted,
4361
- _args30 = arguments;
4362
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4363
- while (1) switch (_context30.prev = _context30.next) {
4441
+ _args31 = arguments;
4442
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4443
+ while (1) switch (_context31.prev = _context31.next) {
4364
4444
  case 0:
4365
- protectedOrdersBeforeRemoteFetch = _args30.length > 2 && _args30[2] !== undefined ? _args30[2] : [];
4445
+ protectedOrdersBeforeRemoteFetch = _args31.length > 2 && _args31[2] !== undefined ? _args31[2] : [];
4366
4446
  if (this.dbManager) {
4367
- _context30.next = 3;
4447
+ _context31.next = 3;
4368
4448
  break;
4369
4449
  }
4370
- return _context30.abrupt("return", {
4450
+ return _context31.abrupt("return", {
4371
4451
  orders: this.compactOrderListByIdentity(orderList.map(function (order) {
4372
- return _this25.normalizeRemoteSyncedOrder(order);
4452
+ return _this26.normalizeRemoteSyncedOrder(order);
4373
4453
  }), "".concat(source, ".snapshotNoDb")).list,
4374
4454
  persisted: false
4375
4455
  });
4376
4456
  case 3:
4377
4457
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
4378
- return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4458
+ return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4379
4459
  });
4380
4460
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
4381
- return _this25.normalizeRemoteSyncedOrder(order);
4461
+ return _this26.normalizeRemoteSyncedOrder(order);
4382
4462
  }), "".concat(source, ".remoteSnapshot")).list;
4383
4463
  persisted = false;
4384
- _context30.prev = 6;
4385
- _context30.next = 9;
4386
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4464
+ _context31.prev = 6;
4465
+ _context31.next = 9;
4466
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4387
4467
  var existingOrders, protectedLocalOrders, _iterator37, _step37, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4388
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4389
- while (1) switch (_context29.prev = _context29.next) {
4468
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4469
+ while (1) switch (_context30.prev = _context30.next) {
4390
4470
  case 0:
4391
- if (!(typeof _this25.dbManager.getAll === 'function')) {
4392
- _context29.next = 6;
4471
+ if (!(typeof _this26.dbManager.getAll === 'function')) {
4472
+ _context30.next = 6;
4393
4473
  break;
4394
4474
  }
4395
- _context29.next = 3;
4396
- return _this25.dbManager.getAll(INDEXDB_STORE_NAME);
4475
+ _context30.next = 3;
4476
+ return _this26.dbManager.getAll(INDEXDB_STORE_NAME);
4397
4477
  case 3:
4398
- _context29.t0 = _context29.sent;
4399
- _context29.next = 7;
4478
+ _context30.t0 = _context30.sent;
4479
+ _context30.next = 7;
4400
4480
  break;
4401
4481
  case 6:
4402
- _context29.t0 = [];
4482
+ _context30.t0 = [];
4403
4483
  case 7:
4404
- existingOrders = _context29.t0;
4484
+ existingOrders = _context30.t0;
4405
4485
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4406
- return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4486
+ return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4407
4487
  }).filter(function (order) {
4408
- return _this25.shouldProtectLocalOrderFromRemoteSnapshot(order);
4488
+ return _this26.shouldProtectLocalOrderFromRemoteSnapshot(order);
4409
4489
  });
4410
4490
  _iterator37 = _createForOfIteratorHelper(existingOrders || []);
4411
- _context29.prev = 10;
4491
+ _context30.prev = 10;
4412
4492
  _iterator37.s();
4413
4493
  case 12:
4414
4494
  if ((_step37 = _iterator37.n()).done) {
4415
- _context29.next = 23;
4495
+ _context30.next = 23;
4416
4496
  break;
4417
4497
  }
4418
4498
  rawCurrentOrder = _step37.value;
4419
- currentOrder = _this25.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4420
- protectedIndex = _this25.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4421
- currentNeedsProtection = _this25.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4499
+ currentOrder = _this26.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4500
+ protectedIndex = _this26.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4501
+ currentNeedsProtection = _this26.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4422
4502
  if (!(protectedIndex >= 0)) {
4423
- _context29.next = 20;
4503
+ _context30.next = 20;
4424
4504
  break;
4425
4505
  }
4426
4506
  if (currentNeedsProtection) {
@@ -4428,27 +4508,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4428
4508
  } else {
4429
4509
  protectedLocalOrders.splice(protectedIndex, 1);
4430
4510
  }
4431
- return _context29.abrupt("continue", 21);
4511
+ return _context30.abrupt("continue", 21);
4432
4512
  case 20:
4433
4513
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4434
4514
  case 21:
4435
- _context29.next = 12;
4515
+ _context30.next = 12;
4436
4516
  break;
4437
4517
  case 23:
4438
- _context29.next = 28;
4518
+ _context30.next = 28;
4439
4519
  break;
4440
4520
  case 25:
4441
- _context29.prev = 25;
4442
- _context29.t1 = _context29["catch"](10);
4443
- _iterator37.e(_context29.t1);
4521
+ _context30.prev = 25;
4522
+ _context30.t1 = _context30["catch"](10);
4523
+ _iterator37.e(_context30.t1);
4444
4524
  case 28:
4445
- _context29.prev = 28;
4525
+ _context30.prev = 28;
4446
4526
  _iterator37.f();
4447
- return _context29.finish(28);
4527
+ return _context30.finish(28);
4448
4528
  case 31:
4449
- orderListSnapshot = _this25.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4450
- mergedSnapshot = _this25.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4451
- _this25.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4529
+ orderListSnapshot = _this26.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4530
+ mergedSnapshot = _this26.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4531
+ _this26.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4452
4532
  source: source,
4453
4533
  count: mergedSnapshot.length,
4454
4534
  remoteCount: remoteSnapshot.length,
@@ -4456,10 +4536,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4456
4536
  protectedLocalOrderCount: protectedLocalOrders.length,
4457
4537
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
4458
4538
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
4459
- return count + _this25.getIdentifiedPendingPayments(order).length;
4539
+ return count + _this26.getIdentifiedPendingPayments(order).length;
4460
4540
  }, 0),
4461
4541
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
4462
- return _this25.getIdentifiedPendingPayments(order).map(function (payment) {
4542
+ return _this26.getIdentifiedPendingPayments(order).map(function (payment) {
4463
4543
  var _order$order_id5, _external_sale_number5;
4464
4544
  return {
4465
4545
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -4469,55 +4549,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4469
4549
  });
4470
4550
  })
4471
4551
  });
4472
- _context29.next = 36;
4473
- return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4552
+ _context30.next = 36;
4553
+ return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4474
4554
  case 36:
4475
- _this25.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4555
+ _this26.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4476
4556
  count: mergedSnapshot.length
4477
4557
  });
4478
4558
  if (!(mergedSnapshot.length === 0)) {
4479
- _context29.next = 39;
4559
+ _context30.next = 39;
4480
4560
  break;
4481
4561
  }
4482
- return _context29.abrupt("return");
4562
+ return _context30.abrupt("return");
4483
4563
  case 39:
4484
- _context29.next = 41;
4485
- return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4564
+ _context30.next = 41;
4565
+ return _this26.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4486
4566
  case 41:
4487
- _this25.recordRecentSqliteWrite(source, mergedSnapshot);
4488
- _this25.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4567
+ _this26.recordRecentSqliteWrite(source, mergedSnapshot);
4568
+ _this26.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4489
4569
  source: source,
4490
4570
  count: mergedSnapshot.length
4491
4571
  });
4492
4572
  case 43:
4493
4573
  case "end":
4494
- return _context29.stop();
4574
+ return _context30.stop();
4495
4575
  }
4496
- }, _callee29, null, [[10, 25, 28, 31]]);
4576
+ }, _callee30, null, [[10, 25, 28, 31]]);
4497
4577
  })));
4498
4578
  case 9:
4499
4579
  persisted = true;
4500
- _context30.next = 15;
4580
+ _context31.next = 15;
4501
4581
  break;
4502
4582
  case 12:
4503
- _context30.prev = 12;
4504
- _context30.t0 = _context30["catch"](6);
4583
+ _context31.prev = 12;
4584
+ _context31.t0 = _context31["catch"](6);
4505
4585
  this.logError('全量保存订单到 SQLite 失败', {
4506
- error: _context30.t0 instanceof Error ? _context30.t0.message : String(_context30.t0),
4586
+ error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0),
4507
4587
  orderList: remoteSnapshot.length
4508
4588
  });
4509
4589
  case 15:
4510
- return _context30.abrupt("return", {
4590
+ return _context31.abrupt("return", {
4511
4591
  orders: mergedSnapshot,
4512
4592
  persisted: persisted
4513
4593
  });
4514
4594
  case 16:
4515
4595
  case "end":
4516
- return _context30.stop();
4596
+ return _context31.stop();
4517
4597
  }
4518
- }, _callee30, this, [[6, 12]]);
4598
+ }, _callee31, this, [[6, 12]]);
4519
4599
  }));
4520
- function replaceOrdersSnapshotInSQLite(_x22, _x23) {
4600
+ function replaceOrdersSnapshotInSQLite(_x23, _x24) {
4521
4601
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
4522
4602
  }
4523
4603
  return replaceOrdersSnapshotInSQLite;
@@ -4532,38 +4612,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4532
4612
  }, {
4533
4613
  key: "clear",
4534
4614
  value: (function () {
4535
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4536
- var _this26 = this;
4537
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4538
- while (1) switch (_context32.prev = _context32.next) {
4615
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4616
+ var _this27 = this;
4617
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4618
+ while (1) switch (_context33.prev = _context33.next) {
4539
4619
  case 0:
4540
4620
  this.store.list = [];
4541
4621
  this.store.map = new Map();
4542
4622
  if (!this.dbManager) {
4543
- _context32.next = 5;
4623
+ _context33.next = 5;
4544
4624
  break;
4545
4625
  }
4546
- _context32.next = 5;
4547
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
4548
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4549
- while (1) switch (_context31.prev = _context31.next) {
4626
+ _context33.next = 5;
4627
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4628
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4629
+ while (1) switch (_context32.prev = _context32.next) {
4550
4630
  case 0:
4551
- _context31.next = 2;
4552
- return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4631
+ _context32.next = 2;
4632
+ return _this27.dbManager.clear(INDEXDB_STORE_NAME);
4553
4633
  case 2:
4554
4634
  case "end":
4555
- return _context31.stop();
4635
+ return _context32.stop();
4556
4636
  }
4557
- }, _callee31);
4637
+ }, _callee32);
4558
4638
  })));
4559
4639
  case 5:
4560
4640
  this.clearOrderSnapshotMarker();
4561
4641
  this.emitOrdersChanged([], 'clear');
4562
4642
  case 7:
4563
4643
  case "end":
4564
- return _context32.stop();
4644
+ return _context33.stop();
4565
4645
  }
4566
- }, _callee32, this);
4646
+ }, _callee33, this);
4567
4647
  }));
4568
4648
  function clear() {
4569
4649
  return _clear.apply(this, arguments);