@pisell/pisellos 2.2.328 → 2.2.329

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.
@@ -2822,12 +2822,109 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2822
2822
  }, {
2823
2823
  key: "mergeOrdersToStore",
2824
2824
  value: (function () {
2825
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(freshOrders, source) {
2825
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(freshOrders, source) {
2826
2826
  var _this18 = this;
2827
- 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, _key3, _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, _key5, _duplicateIndex, _iterator19, _step19, duplicateIndex, _index, _iterator20, _step20, _key4, nextStorageKey, _ref5, _ref6, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
2828
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2829
- while (1) switch (_context23.prev = _context23.next) {
2827
+ var cancelledOrders, ids, cloudOrders, storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator16, _step16, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, storageKeyMigrations, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator17, _step17, _key4, _iterator18, _step18, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, previousStorageKey, _ref2, _existingOrder$order_, _ref3, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref4, _existingOrder$order_2, _ref5, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, freshOrderId, incomingProductsAreStable, membershipChange, mergedProductsHaveStableIdentity, adjustedMatchIndex, duplicateIndexes, _iterator19, _step19, _key6, _duplicateIndex, _iterator20, _step20, duplicateIndex, _index, _iterator21, _step21, _key5, nextStorageKey, _ref6, _ref7, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
2828
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2829
+ while (1) switch (_context24.prev = _context24.next) {
2830
2830
  case 0:
2831
+ if (!this.isRemoteEchoMergeSource(source)) {
2832
+ _context24.next = 11;
2833
+ break;
2834
+ }
2835
+ cancelledOrders = freshOrders.filter(function (order) {
2836
+ return (order === null || order === void 0 ? void 0 : order.status) === 'cancelled' && order.order_id != null;
2837
+ });
2838
+ if (!cancelledOrders.length) {
2839
+ _context24.next = 11;
2840
+ break;
2841
+ }
2842
+ ids = new Set(cancelledOrders.map(function (order) {
2843
+ return _this18.getIdKey(order.order_id);
2844
+ }));
2845
+ cloudOrders = cancelledOrders.map(function (order) {
2846
+ return _this18.normalizeRemoteSyncedOrder(order);
2847
+ });
2848
+ _context24.next = 7;
2849
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2850
+ var stored, keys, _iterator15, _step15, _key3;
2851
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2852
+ while (1) switch (_context23.prev = _context23.next) {
2853
+ case 0:
2854
+ if (!_this18.dbManager) {
2855
+ _context23.next = 26;
2856
+ break;
2857
+ }
2858
+ _context23.next = 3;
2859
+ return _this18.dbManager.getAll(INDEXDB_STORE_NAME);
2860
+ case 3:
2861
+ stored = _context23.sent;
2862
+ keys = new Set((stored || []).filter(function (order) {
2863
+ return order.order_id != null && ids.has(_this18.getIdKey(order.order_id));
2864
+ }).map(function (order) {
2865
+ return _this18.getPersistedOrderStorageKey(order);
2866
+ }).filter(Boolean));
2867
+ _iterator15 = _createForOfIteratorHelper(keys);
2868
+ _context23.prev = 6;
2869
+ _iterator15.s();
2870
+ case 8:
2871
+ if ((_step15 = _iterator15.n()).done) {
2872
+ _context23.next = 15;
2873
+ break;
2874
+ }
2875
+ _key3 = _step15.value;
2876
+ _context23.next = 12;
2877
+ return _this18.dbManager.delete(INDEXDB_STORE_NAME, _key3);
2878
+ case 12:
2879
+ _this18.recentSqliteWriteByStorageKey.delete(_key3);
2880
+ case 13:
2881
+ _context23.next = 8;
2882
+ break;
2883
+ case 15:
2884
+ _context23.next = 20;
2885
+ break;
2886
+ case 17:
2887
+ _context23.prev = 17;
2888
+ _context23.t0 = _context23["catch"](6);
2889
+ _iterator15.e(_context23.t0);
2890
+ case 20:
2891
+ _context23.prev = 20;
2892
+ _iterator15.f();
2893
+ return _context23.finish(20);
2894
+ case 23:
2895
+ _context23.next = 25;
2896
+ return _this18.writeOrderRowsToSQLite(cloudOrders);
2897
+ case 25:
2898
+ _this18.recordRecentSqliteWrite(source, cloudOrders);
2899
+ case 26:
2900
+ _this18.store.list = _this18.store.list.filter(function (order) {
2901
+ return order.order_id == null || !ids.has(_this18.getIdKey(order.order_id));
2902
+ }).concat(cloudOrders);
2903
+ _this18.syncOrdersMap();
2904
+ case 28:
2905
+ case "end":
2906
+ return _context23.stop();
2907
+ }
2908
+ }, _callee23, null, [[6, 17, 20, 23]]);
2909
+ })));
2910
+ case 7:
2911
+ this.logInfo('取消订单已清理本地副本并采用云端数据', {
2912
+ source: source,
2913
+ order_ids: _toConsumableArray(ids)
2914
+ });
2915
+ _context24.next = 10;
2916
+ return this.emitOrdersChanged(cloudOrders, source);
2917
+ case 10:
2918
+ freshOrders = freshOrders.filter(function (order) {
2919
+ return order.order_id == null || !ids.has(_this18.getIdKey(order.order_id));
2920
+ });
2921
+ case 11:
2922
+ if (freshOrders.length) {
2923
+ _context24.next = 13;
2924
+ break;
2925
+ }
2926
+ return _context24.abrupt("return");
2927
+ case 13:
2831
2928
  storeOrderCountBefore = this.store.list.length;
2832
2929
  this.logInfo('mergeOrdersToStore-开始', {
2833
2930
  freshOrderCount: freshOrders.length,
@@ -2837,22 +2934,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2837
2934
  this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
2838
2935
  normalizedFreshOrders = [];
2839
2936
  incomingProductsHaveStableIdentity = new Map();
2840
- _iterator15 = _createForOfIteratorHelper(freshOrders);
2841
- _context23.prev = 6;
2842
- _iterator15.s();
2843
- case 8:
2844
- if ((_step15 = _iterator15.n()).done) {
2845
- _context23.next = 18;
2937
+ _iterator16 = _createForOfIteratorHelper(freshOrders);
2938
+ _context24.prev = 19;
2939
+ _iterator16.s();
2940
+ case 21:
2941
+ if ((_step16 = _iterator16.n()).done) {
2942
+ _context24.next = 31;
2846
2943
  break;
2847
2944
  }
2848
- order = _step15.value;
2945
+ order = _step16.value;
2849
2946
  id = order === null || order === void 0 ? void 0 : order.order_id;
2850
2947
  if (!(id === undefined || id === null)) {
2851
- _context23.next = 13;
2948
+ _context24.next = 26;
2852
2949
  break;
2853
2950
  }
2854
- return _context23.abrupt("continue", 16);
2855
- case 13:
2951
+ return _context24.abrupt("continue", 29);
2952
+ case 26:
2856
2953
  rawProducts = order.products;
2857
2954
  if (Array.isArray(rawProducts)) {
2858
2955
  allProductsHaveStableIdentity = this.doProductsHaveStableMembershipIdentity(rawProducts);
@@ -2860,21 +2957,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2860
2957
  incomingProductsHaveStableIdentity.set(orderIdKey, ((_incomingProductsHave = incomingProductsHaveStableIdentity.get(orderIdKey)) !== null && _incomingProductsHave !== void 0 ? _incomingProductsHave : true) && allProductsHaveStableIdentity);
2861
2958
  }
2862
2959
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2863
- case 16:
2864
- _context23.next = 8;
2960
+ case 29:
2961
+ _context24.next = 21;
2865
2962
  break;
2866
- case 18:
2867
- _context23.next = 23;
2963
+ case 31:
2964
+ _context24.next = 36;
2868
2965
  break;
2869
- case 20:
2870
- _context23.prev = 20;
2871
- _context23.t0 = _context23["catch"](6);
2872
- _iterator15.e(_context23.t0);
2873
- case 23:
2874
- _context23.prev = 23;
2875
- _iterator15.f();
2876
- return _context23.finish(23);
2877
- case 26:
2966
+ case 33:
2967
+ _context24.prev = 33;
2968
+ _context24.t0 = _context24["catch"](19);
2969
+ _iterator16.e(_context24.t0);
2970
+ case 36:
2971
+ _context24.prev = 36;
2972
+ _iterator16.f();
2973
+ return _context24.finish(36);
2974
+ case 39:
2878
2975
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2879
2976
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
2880
2977
  uniqueFreshCount = uniqueFreshOrders.length;
@@ -2894,68 +2991,68 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2894
2991
  identityKeyToIndex = new Map();
2895
2992
  for (index = 0; index < updatedList.length; index += 1) {
2896
2993
  identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
2897
- _iterator16 = _createForOfIteratorHelper(identityKeys);
2994
+ _iterator17 = _createForOfIteratorHelper(identityKeys);
2898
2995
  try {
2899
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2900
- _key3 = _step16.value;
2996
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2997
+ _key4 = _step17.value;
2901
2998
  // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
2902
- if (!identityKeyToIndex.has(_key3)) identityKeyToIndex.set(_key3, index);
2999
+ if (!identityKeyToIndex.has(_key4)) identityKeyToIndex.set(_key4, index);
2903
3000
  }
2904
3001
  } catch (err) {
2905
- _iterator16.e(err);
3002
+ _iterator17.e(err);
2906
3003
  } finally {
2907
- _iterator16.f();
3004
+ _iterator17.f();
2908
3005
  }
2909
3006
  }
2910
- _iterator17 = _createForOfIteratorHelper(uniqueFreshOrders);
2911
- _context23.prev = 38;
2912
- _iterator17.s();
2913
- case 40:
2914
- if ((_step17 = _iterator17.n()).done) {
2915
- _context23.next = 101;
3007
+ _iterator18 = _createForOfIteratorHelper(uniqueFreshOrders);
3008
+ _context24.prev = 51;
3009
+ _iterator18.s();
3010
+ case 53:
3011
+ if ((_step18 = _iterator18.n()).done) {
3012
+ _context24.next = 114;
2916
3013
  break;
2917
3014
  }
2918
- fresh = _step17.value;
3015
+ fresh = _step18.value;
2919
3016
  freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
2920
3017
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
2921
3018
  storageKey = this.getOrderStorageKey(fresh);
2922
3019
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2923
3020
  if (!(matchIndex >= 0)) {
2924
- _context23.next = 93;
3021
+ _context24.next = 106;
2925
3022
  break;
2926
3023
  }
2927
3024
  existingOrder = updatedList[matchIndex];
2928
3025
  previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2929
3026
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2930
- _context23.next = 52;
3027
+ _context24.next = 65;
2931
3028
  break;
2932
3029
  }
2933
3030
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
2934
3031
  source: source,
2935
- order_id: (_ref = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref !== void 0 ? _ref : null,
2936
- external_sale_number: (_ref2 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref2 !== void 0 ? _ref2 : null,
3032
+ order_id: (_ref2 = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref2 !== void 0 ? _ref2 : null,
3033
+ external_sale_number: (_ref3 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref3 !== void 0 ? _ref3 : null,
2937
3034
  local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
2938
3035
  remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
2939
3036
  local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
2940
3037
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2941
3038
  reason: 'protect_pending_sync_order_from_remote_echo'
2942
3039
  });
2943
- return _context23.abrupt("continue", 99);
2944
- case 52:
3040
+ return _context24.abrupt("continue", 112);
3041
+ case 65:
2945
3042
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2946
- _context23.next = 55;
3043
+ _context24.next = 68;
2947
3044
  break;
2948
3045
  }
2949
3046
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
2950
3047
  source: source,
2951
- order_id: (_ref3 = (_existingOrder$order_2 = existingOrder.order_id) !== null && _existingOrder$order_2 !== void 0 ? _existingOrder$order_2 : fresh.order_id) !== null && _ref3 !== void 0 ? _ref3 : null,
2952
- external_sale_number: (_ref4 = (_external_sale_number3 = existingOrder.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : fresh.external_sale_number) !== null && _ref4 !== void 0 ? _ref4 : null,
3048
+ order_id: (_ref4 = (_existingOrder$order_2 = existingOrder.order_id) !== null && _existingOrder$order_2 !== void 0 ? _existingOrder$order_2 : fresh.order_id) !== null && _ref4 !== void 0 ? _ref4 : null,
3049
+ external_sale_number: (_ref5 = (_external_sale_number3 = existingOrder.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : fresh.external_sale_number) !== null && _ref5 !== void 0 ? _ref5 : null,
2953
3050
  local_is_draft_order: (_existingOrder$is_dra = existingOrder.is_draft_order) !== null && _existingOrder$is_dra !== void 0 ? _existingOrder$is_dra : null,
2954
3051
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2955
3052
  reason: 'protect_draft_order_from_remote_echo'
2956
3053
  });
2957
- return _context23.abrupt("continue", 99);
2958
- case 55:
3054
+ return _context24.abrupt("continue", 112);
3055
+ case 68:
2959
3056
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2960
3057
  freshOrderId = fresh.order_id;
2961
3058
  incomingProductsAreStable = freshOrderId !== undefined && freshOrderId !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(freshOrderId)) !== false;
@@ -2966,45 +3063,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2966
3063
  mergedProductsHaveStableIdentity = existingProductsHaveStableIdentity[matchIndex] !== false && incomingProductsAreStable;
2967
3064
  adjustedMatchIndex = matchIndex;
2968
3065
  duplicateIndexes = new Set();
2969
- _iterator18 = _createForOfIteratorHelper(freshIdentityKeys);
2970
- _context23.prev = 64;
2971
- _iterator18.s();
2972
- case 66:
2973
- if ((_step18 = _iterator18.n()).done) {
2974
- _context23.next = 74;
3066
+ _iterator19 = _createForOfIteratorHelper(freshIdentityKeys);
3067
+ _context24.prev = 77;
3068
+ _iterator19.s();
3069
+ case 79:
3070
+ if ((_step19 = _iterator19.n()).done) {
3071
+ _context24.next = 87;
2975
3072
  break;
2976
3073
  }
2977
- _key5 = _step18.value;
2978
- _duplicateIndex = identityKeyToIndex.get(_key5);
3074
+ _key6 = _step19.value;
3075
+ _duplicateIndex = identityKeyToIndex.get(_key6);
2979
3076
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2980
- _context23.next = 71;
3077
+ _context24.next = 84;
2981
3078
  break;
2982
3079
  }
2983
- return _context23.abrupt("continue", 72);
2984
- case 71:
3080
+ return _context24.abrupt("continue", 85);
3081
+ case 84:
2985
3082
  duplicateIndexes.add(_duplicateIndex);
2986
- case 72:
2987
- _context23.next = 66;
3083
+ case 85:
3084
+ _context24.next = 79;
2988
3085
  break;
2989
- case 74:
2990
- _context23.next = 79;
3086
+ case 87:
3087
+ _context24.next = 92;
2991
3088
  break;
2992
- case 76:
2993
- _context23.prev = 76;
2994
- _context23.t1 = _context23["catch"](64);
2995
- _iterator18.e(_context23.t1);
2996
- case 79:
2997
- _context23.prev = 79;
2998
- _iterator18.f();
2999
- return _context23.finish(79);
3000
- case 82:
3089
+ case 89:
3090
+ _context24.prev = 89;
3091
+ _context24.t1 = _context24["catch"](77);
3092
+ _iterator19.e(_context24.t1);
3093
+ case 92:
3094
+ _context24.prev = 92;
3095
+ _iterator19.f();
3096
+ return _context24.finish(92);
3097
+ case 95:
3001
3098
  if (duplicateIndexes.size > 0) {
3002
- _iterator19 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
3099
+ _iterator20 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
3003
3100
  return right - left;
3004
3101
  }));
3005
3102
  try {
3006
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
3007
- duplicateIndex = _step19.value;
3103
+ for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
3104
+ duplicateIndex = _step20.value;
3008
3105
  mergedOrder = this.mergeOrderRecords(mergedOrder, updatedList[duplicateIndex]);
3009
3106
  mergedProductsHaveStableIdentity = mergedProductsHaveStableIdentity && existingProductsHaveStableIdentity[duplicateIndex] !== false;
3010
3107
  updatedList.splice(duplicateIndex, 1);
@@ -3012,29 +3109,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3012
3109
  if (duplicateIndex < adjustedMatchIndex) adjustedMatchIndex -= 1;
3013
3110
  }
3014
3111
  } catch (err) {
3015
- _iterator19.e(err);
3112
+ _iterator20.e(err);
3016
3113
  } finally {
3017
- _iterator19.f();
3114
+ _iterator20.f();
3018
3115
  }
3019
3116
  identityKeyToIndex.clear();
3020
3117
  for (_index = 0; _index < updatedList.length; _index += 1) {
3021
- _iterator20 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
3118
+ _iterator21 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
3022
3119
  try {
3023
- for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
3024
- _key4 = _step20.value;
3025
- if (!identityKeyToIndex.has(_key4)) identityKeyToIndex.set(_key4, _index);
3120
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
3121
+ _key5 = _step21.value;
3122
+ if (!identityKeyToIndex.has(_key5)) identityKeyToIndex.set(_key5, _index);
3026
3123
  }
3027
3124
  } catch (err) {
3028
- _iterator20.e(err);
3125
+ _iterator21.e(err);
3029
3126
  } finally {
3030
- _iterator20.f();
3127
+ _iterator21.f();
3031
3128
  }
3032
3129
  }
3033
3130
  }
3034
3131
  nextStorageKey = this.getOrderStorageKey(mergedOrder);
3035
3132
  if (previousStorageKey && nextStorageKey && previousStorageKey !== nextStorageKey) {
3036
3133
  storageKeyMigrations.push({
3037
- orderId: (_ref5 = (_ref6 = (_mergedOrder$order_id = mergedOrder.order_id) !== null && _mergedOrder$order_id !== void 0 ? _mergedOrder$order_id : existingOrder.order_id) !== null && _ref6 !== void 0 ? _ref6 : fresh.order_id) !== null && _ref5 !== void 0 ? _ref5 : null,
3134
+ orderId: (_ref6 = (_ref7 = (_mergedOrder$order_id = mergedOrder.order_id) !== null && _mergedOrder$order_id !== void 0 ? _mergedOrder$order_id : existingOrder.order_id) !== null && _ref7 !== void 0 ? _ref7 : fresh.order_id) !== null && _ref6 !== void 0 ? _ref6 : null,
3038
3135
  from: previousStorageKey,
3039
3136
  to: nextStorageKey
3040
3137
  });
@@ -3054,29 +3151,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3054
3151
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
3055
3152
  patchedOrders.push(mergedOrder);
3056
3153
  if (mergeKey) mergeActions[mergeKey] = 'update';
3057
- return _context23.abrupt("continue", 99);
3058
- case 93:
3154
+ return _context24.abrupt("continue", 112);
3155
+ case 106:
3059
3156
  insertIndex = updatedList.length;
3060
3157
  updatedList.push(fresh);
3061
3158
  existingProductsHaveStableIdentity.push(fresh.order_id !== undefined && fresh.order_id !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(fresh.order_id)) !== false);
3062
3159
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
3063
3160
  patchedOrders.push(fresh);
3064
3161
  if (mergeKey) mergeActions[mergeKey] = 'insert';
3065
- case 99:
3066
- _context23.next = 40;
3162
+ case 112:
3163
+ _context24.next = 53;
3067
3164
  break;
3068
- case 101:
3069
- _context23.next = 106;
3165
+ case 114:
3166
+ _context24.next = 119;
3070
3167
  break;
3071
- case 103:
3072
- _context23.prev = 103;
3073
- _context23.t2 = _context23["catch"](38);
3074
- _iterator17.e(_context23.t2);
3075
- case 106:
3076
- _context23.prev = 106;
3077
- _iterator17.f();
3078
- return _context23.finish(106);
3079
- case 109:
3168
+ case 116:
3169
+ _context24.prev = 116;
3170
+ _context24.t2 = _context24["catch"](51);
3171
+ _iterator18.e(_context24.t2);
3172
+ case 119:
3173
+ _context24.prev = 119;
3174
+ _iterator18.f();
3175
+ return _context24.finish(119);
3176
+ case 122:
3080
3177
  insertCount = Object.values(mergeActions).filter(function (v) {
3081
3178
  return v === 'insert';
3082
3179
  }).length;
@@ -3092,27 +3189,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3092
3189
  // 仅在自检开关开启时做一次兜底校验。
3093
3190
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
3094
3191
  this.syncOrdersMap();
3095
- _context23.next = 116;
3192
+ _context24.next = 129;
3096
3193
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
3097
3194
  storageKeyMigrations: storageKeyMigrations
3098
3195
  }, forceWriteStorageKeys);
3099
- case 116:
3196
+ case 129:
3100
3197
  this.logInfo('mergeOrdersToStore-结束', {
3101
3198
  uniqueFreshCount: uniqueFreshCount,
3102
3199
  storeOrderCountAfter: this.store.list.length,
3103
3200
  insertCount: insertCount,
3104
3201
  updateCount: updateCount
3105
3202
  });
3106
- _context23.next = 119;
3203
+ _context24.next = 132;
3107
3204
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
3108
- case 119:
3109
- _context23.next = 121;
3205
+ case 132:
3206
+ _context24.next = 134;
3110
3207
  return this.emitOrdersChanged(patchedOrders, source);
3111
- case 121:
3208
+ case 134:
3112
3209
  case "end":
3113
- return _context23.stop();
3210
+ return _context24.stop();
3114
3211
  }
3115
- }, _callee23, this, [[6, 20, 23, 26], [38, 103, 106, 109], [64, 76, 79, 82]]);
3212
+ }, _callee24, this, [[19, 33, 36, 39], [51, 116, 119, 122], [77, 89, 92, 95]]);
3116
3213
  }));
3117
3214
  function mergeOrdersToStore(_x16, _x17) {
3118
3215
  return _mergeOrdersToStore.apply(this, arguments);
@@ -3131,19 +3228,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3131
3228
  key: "lookupOrderIndexByIdentityKeys",
3132
3229
  value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
3133
3230
  var matchIndex = -1;
3134
- var _iterator21 = _createForOfIteratorHelper(identityKeys),
3135
- _step21;
3231
+ var _iterator22 = _createForOfIteratorHelper(identityKeys),
3232
+ _step22;
3136
3233
  try {
3137
- for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
3138
- var _key6 = _step21.value;
3139
- var index = identityKeyToIndex.get(_key6);
3234
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
3235
+ var _key7 = _step22.value;
3236
+ var index = identityKeyToIndex.get(_key7);
3140
3237
  if (index === undefined) continue;
3141
3238
  if (matchIndex < 0 || index < matchIndex) matchIndex = index;
3142
3239
  }
3143
3240
  } catch (err) {
3144
- _iterator21.e(err);
3241
+ _iterator22.e(err);
3145
3242
  } finally {
3146
- _iterator21.f();
3243
+ _iterator22.f();
3147
3244
  }
3148
3245
  return matchIndex;
3149
3246
  }
@@ -3203,11 +3300,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3203
3300
  return index;
3204
3301
  }));
3205
3302
  var removedProductKeys = [];
3206
- var _iterator22 = _createForOfIteratorHelper(previousProducts),
3207
- _step22;
3303
+ var _iterator23 = _createForOfIteratorHelper(previousProducts),
3304
+ _step23;
3208
3305
  try {
3209
3306
  var _loop2 = function _loop2() {
3210
- var previousProduct = _step22.value;
3307
+ var previousProduct = _step23.value;
3211
3308
  var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
3212
3309
  return unmatchedCurrentIndexes.has(index) && _this19.isSameProductMembershipItem(previousProduct, currentProduct);
3213
3310
  });
@@ -3218,13 +3315,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3218
3315
  var productKey = _this19.getProductMembershipKey(previousProduct);
3219
3316
  if (productKey) removedProductKeys.push(productKey);
3220
3317
  };
3221
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
3318
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
3222
3319
  if (_loop2()) continue;
3223
3320
  }
3224
3321
  } catch (err) {
3225
- _iterator22.e(err);
3322
+ _iterator23.e(err);
3226
3323
  } finally {
3227
- _iterator22.f();
3324
+ _iterator23.f();
3228
3325
  }
3229
3326
  var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
3230
3327
  return _this19.getProductMembershipKey(currentProducts[index]);
@@ -3255,17 +3352,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3255
3352
  key: "registerOrderIdentityKeys",
3256
3353
  value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
3257
3354
  var identityKeys = this.getOrderIdentityMatchKeys(order);
3258
- var _iterator23 = _createForOfIteratorHelper(identityKeys),
3259
- _step23;
3355
+ var _iterator24 = _createForOfIteratorHelper(identityKeys),
3356
+ _step24;
3260
3357
  try {
3261
- for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
3262
- var _key7 = _step23.value;
3263
- identityKeyToIndex.set(_key7, index);
3358
+ for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
3359
+ var _key8 = _step24.value;
3360
+ identityKeyToIndex.set(_key8, index);
3264
3361
  }
3265
3362
  } catch (err) {
3266
- _iterator23.e(err);
3363
+ _iterator24.e(err);
3267
3364
  } finally {
3268
- _iterator23.f();
3365
+ _iterator24.f();
3269
3366
  }
3270
3367
  }
3271
3368
 
@@ -3320,17 +3417,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3320
3417
  key: "uniqueOrderIds",
3321
3418
  value: function uniqueOrderIds(ids) {
3322
3419
  var idMap = new Map();
3323
- var _iterator24 = _createForOfIteratorHelper(ids),
3324
- _step24;
3420
+ var _iterator25 = _createForOfIteratorHelper(ids),
3421
+ _step25;
3325
3422
  try {
3326
- for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
3327
- var id = _step24.value;
3423
+ for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
3424
+ var id = _step25.value;
3328
3425
  idMap.set(this.getIdKey(id), id);
3329
3426
  }
3330
3427
  } catch (err) {
3331
- _iterator24.e(err);
3428
+ _iterator25.e(err);
3332
3429
  } finally {
3333
- _iterator24.f();
3430
+ _iterator25.f();
3334
3431
  }
3335
3432
  return _toConsumableArray(idMap.values());
3336
3433
  }
@@ -3480,58 +3577,58 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3480
3577
  if (secondaryList.length === 0) return preferredList;
3481
3578
  if (preferredList.length === 0) return secondaryList;
3482
3579
  var seenKeys = new Set();
3483
- var _iterator25 = _createForOfIteratorHelper(preferredList),
3484
- _step25;
3580
+ var _iterator26 = _createForOfIteratorHelper(preferredList),
3581
+ _step26;
3485
3582
  try {
3486
- for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
3487
- var item = _step25.value;
3583
+ for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
3584
+ var item = _step26.value;
3488
3585
  var keys = this.getProductIdentityKeys(item);
3489
- var _iterator27 = _createForOfIteratorHelper(keys),
3490
- _step27;
3586
+ var _iterator28 = _createForOfIteratorHelper(keys),
3587
+ _step28;
3491
3588
  try {
3492
- for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
3493
- var _key8 = _step27.value;
3494
- seenKeys.add(_key8);
3589
+ for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
3590
+ var _key9 = _step28.value;
3591
+ seenKeys.add(_key9);
3495
3592
  }
3496
3593
  } catch (err) {
3497
- _iterator27.e(err);
3594
+ _iterator28.e(err);
3498
3595
  } finally {
3499
- _iterator27.f();
3596
+ _iterator28.f();
3500
3597
  }
3501
3598
  }
3502
3599
  } catch (err) {
3503
- _iterator25.e(err);
3600
+ _iterator26.e(err);
3504
3601
  } finally {
3505
- _iterator25.f();
3602
+ _iterator26.f();
3506
3603
  }
3507
3604
  var result = _toConsumableArray(preferredList);
3508
- var _iterator26 = _createForOfIteratorHelper(secondaryList),
3509
- _step26;
3605
+ var _iterator27 = _createForOfIteratorHelper(secondaryList),
3606
+ _step27;
3510
3607
  try {
3511
- for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
3512
- var _item = _step26.value;
3608
+ for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
3609
+ var _item = _step27.value;
3513
3610
  var _keys = this.getProductIdentityKeys(_item);
3514
3611
  if (_keys.length === 0 || _keys.some(function (key) {
3515
3612
  return seenKeys.has(key);
3516
3613
  })) continue;
3517
- var _iterator28 = _createForOfIteratorHelper(_keys),
3518
- _step28;
3614
+ var _iterator29 = _createForOfIteratorHelper(_keys),
3615
+ _step29;
3519
3616
  try {
3520
- for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
3521
- var _key9 = _step28.value;
3522
- seenKeys.add(_key9);
3617
+ for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3618
+ var _key10 = _step29.value;
3619
+ seenKeys.add(_key10);
3523
3620
  }
3524
3621
  } catch (err) {
3525
- _iterator28.e(err);
3622
+ _iterator29.e(err);
3526
3623
  } finally {
3527
- _iterator28.f();
3624
+ _iterator29.f();
3528
3625
  }
3529
3626
  result.push(cloneDeep(_item));
3530
3627
  }
3531
3628
  } catch (err) {
3532
- _iterator26.e(err);
3629
+ _iterator27.e(err);
3533
3630
  } finally {
3534
- _iterator26.f();
3631
+ _iterator27.f();
3535
3632
  }
3536
3633
  return result;
3537
3634
  }
@@ -3590,29 +3687,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3590
3687
  value: function preserveOmittedHolderRelations(incomingOrders, existingOrders) {
3591
3688
  var _this23 = this;
3592
3689
  var existingByIdentity = new Map();
3593
- var _iterator29 = _createForOfIteratorHelper(existingOrders),
3594
- _step29;
3690
+ var _iterator30 = _createForOfIteratorHelper(existingOrders),
3691
+ _step30;
3595
3692
  try {
3596
- for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3597
- var order = _step29.value;
3693
+ for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
3694
+ var order = _step30.value;
3598
3695
  if (!Array.isArray(order.holder_relations)) continue;
3599
- var _iterator30 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3600
- _step30;
3696
+ var _iterator31 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3697
+ _step31;
3601
3698
  try {
3602
- for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
3603
- var _key10 = _step30.value;
3604
- existingByIdentity.set(_key10, order);
3699
+ for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) {
3700
+ var _key11 = _step31.value;
3701
+ existingByIdentity.set(_key11, order);
3605
3702
  }
3606
3703
  } catch (err) {
3607
- _iterator30.e(err);
3704
+ _iterator31.e(err);
3608
3705
  } finally {
3609
- _iterator30.f();
3706
+ _iterator31.f();
3610
3707
  }
3611
3708
  }
3612
3709
  } catch (err) {
3613
- _iterator29.e(err);
3710
+ _iterator30.e(err);
3614
3711
  } finally {
3615
- _iterator29.f();
3712
+ _iterator30.f();
3616
3713
  }
3617
3714
  return incomingOrders.map(function (order) {
3618
3715
  if (Array.isArray(order.holder_relations)) return order;
@@ -3675,10 +3772,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3675
3772
  if (_field2 === 'payments') {
3676
3773
  var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
3677
3774
  if (preservedPending.length > 0) {
3678
- var _ref7, _existing$order_id, _ref8, _existingRecord$exter;
3775
+ var _ref8, _existing$order_id, _ref9, _existingRecord$exter;
3679
3776
  this.logInfo('mergeOrderRecords-保留本地 pending 支付项', {
3680
- order_id: (_ref7 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref7 !== void 0 ? _ref7 : null,
3681
- external_sale_number: (_ref8 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref8 !== void 0 ? _ref8 : null,
3777
+ order_id: (_ref8 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref8 !== void 0 ? _ref8 : null,
3778
+ external_sale_number: (_ref9 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref9 !== void 0 ? _ref9 : null,
3682
3779
  preserved_pending_count: preservedPending.length,
3683
3780
  preserved_payment_identities: preservedPending.map(function (payment) {
3684
3781
  return getOrderPaymentIdentityKeys(payment);
@@ -3706,39 +3803,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3706
3803
  key: "summarizeDuplicateOrders",
3707
3804
  value: function summarizeDuplicateOrders(orders) {
3708
3805
  var groups = new Map();
3709
- var _iterator31 = _createForOfIteratorHelper(orders),
3710
- _step31;
3806
+ var _iterator32 = _createForOfIteratorHelper(orders),
3807
+ _step32;
3711
3808
  try {
3712
- for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) {
3713
- var order = _step31.value;
3714
- var _iterator32 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3715
- _step32;
3809
+ for (_iterator32.s(); !(_step32 = _iterator32.n()).done;) {
3810
+ var order = _step32.value;
3811
+ var _iterator33 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3812
+ _step33;
3716
3813
  try {
3717
- for (_iterator32.s(); !(_step32 = _iterator32.n()).done;) {
3718
- var _key11 = _step32.value;
3719
- var group = groups.get(_key11) || [];
3814
+ for (_iterator33.s(); !(_step33 = _iterator33.n()).done;) {
3815
+ var _key12 = _step33.value;
3816
+ var group = groups.get(_key12) || [];
3720
3817
  group.push(order);
3721
- groups.set(_key11, group);
3818
+ groups.set(_key12, group);
3722
3819
  }
3723
3820
  } catch (err) {
3724
- _iterator32.e(err);
3821
+ _iterator33.e(err);
3725
3822
  } finally {
3726
- _iterator32.f();
3823
+ _iterator33.f();
3727
3824
  }
3728
3825
  }
3729
3826
  } catch (err) {
3730
- _iterator31.e(err);
3827
+ _iterator32.e(err);
3731
3828
  } finally {
3732
- _iterator31.f();
3829
+ _iterator32.f();
3733
3830
  }
3734
- return _toConsumableArray(groups.entries()).filter(function (_ref9) {
3735
- var _ref10 = _slicedToArray(_ref9, 2),
3736
- group = _ref10[1];
3831
+ return _toConsumableArray(groups.entries()).filter(function (_ref10) {
3832
+ var _ref11 = _slicedToArray(_ref10, 2),
3833
+ group = _ref11[1];
3737
3834
  return group.length > 1;
3738
- }).slice(0, 20).map(function (_ref11) {
3739
- var _ref12 = _slicedToArray(_ref11, 2),
3740
- key = _ref12[0],
3741
- group = _ref12[1];
3835
+ }).slice(0, 20).map(function (_ref12) {
3836
+ var _ref13 = _slicedToArray(_ref12, 2),
3837
+ key = _ref13[0],
3838
+ group = _ref13[1];
3742
3839
  return {
3743
3840
  key: key,
3744
3841
  count: group.length,
@@ -3772,11 +3869,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3772
3869
  value: function compactOrderListByIdentity(orders, source) {
3773
3870
  var list = [];
3774
3871
  var removedCount = 0;
3775
- var _iterator33 = _createForOfIteratorHelper(orders),
3776
- _step33;
3872
+ var _iterator34 = _createForOfIteratorHelper(orders),
3873
+ _step34;
3777
3874
  try {
3778
- for (_iterator33.s(); !(_step33 = _iterator33.n()).done;) {
3779
- var order = _step33.value;
3875
+ for (_iterator34.s(); !(_step34 = _iterator34.n()).done;) {
3876
+ var order = _step34.value;
3780
3877
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
3781
3878
  var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
3782
3879
  if (matchIndex < 0) {
@@ -3787,9 +3884,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3787
3884
  removedCount += 1;
3788
3885
  }
3789
3886
  } catch (err) {
3790
- _iterator33.e(err);
3887
+ _iterator34.e(err);
3791
3888
  } finally {
3792
- _iterator33.f();
3889
+ _iterator34.f();
3793
3890
  }
3794
3891
  if (removedCount > 0) {
3795
3892
  this.logWarning('订单列表重复项已压缩', {
@@ -3921,7 +4018,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3921
4018
  }, {
3922
4019
  key: "loadOrdersFromSQLite",
3923
4020
  value: function () {
3924
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4021
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3925
4022
  var _this24 = this;
3926
4023
  var options,
3927
4024
  loadStartedAt,
@@ -3929,74 +4026,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3929
4026
  normalizedOrders,
3930
4027
  previousOrders,
3931
4028
  protectedMemoryOrders,
3932
- _args25 = arguments;
3933
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3934
- while (1) switch (_context25.prev = _context25.next) {
4029
+ _args26 = arguments;
4030
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4031
+ while (1) switch (_context26.prev = _context26.next) {
3935
4032
  case 0:
3936
- options = _args25.length > 0 && _args25[0] !== undefined ? _args25[0] : {};
4033
+ options = _args26.length > 0 && _args26[0] !== undefined ? _args26[0] : {};
3937
4034
  if (this.dbManager) {
3938
- _context25.next = 3;
4035
+ _context26.next = 3;
3939
4036
  break;
3940
4037
  }
3941
- return _context25.abrupt("return", []);
4038
+ return _context26.abrupt("return", []);
3942
4039
  case 3:
3943
- _context25.prev = 3;
4040
+ _context26.prev = 3;
3944
4041
  loadStartedAt = performance.now();
3945
4042
  memoryBeforeLoad = this.store.list;
3946
4043
  normalizedOrders = []; // 读修复与普通订单写入共用队列,避免用排队前的旧快照覆盖新的待同步订单。
3947
- _context25.next = 9;
3948
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
4044
+ _context26.next = 9;
4045
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
3949
4046
  var _options$onTiming;
3950
- var rawReadStartedAt, orders, sqliteRawReadMs, normalizeStartedAt, _this24$deduplicateSt, list, repairs, obsoleteKeys, sqliteNormalizeMs, _iterator34, _step34, _key12;
3951
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3952
- while (1) switch (_context24.prev = _context24.next) {
4047
+ var rawReadStartedAt, orders, sqliteRawReadMs, normalizeStartedAt, _this24$deduplicateSt, list, repairs, obsoleteKeys, sqliteNormalizeMs, _iterator35, _step35, _key13;
4048
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4049
+ while (1) switch (_context25.prev = _context25.next) {
3953
4050
  case 0:
3954
4051
  rawReadStartedAt = performance.now();
3955
- _context24.next = 3;
4052
+ _context25.next = 3;
3956
4053
  return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
3957
4054
  case 3:
3958
- orders = _context24.sent;
4055
+ orders = _context25.sent;
3959
4056
  sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3960
4057
  normalizeStartedAt = performance.now();
3961
4058
  _this24$deduplicateSt = _this24.deduplicateStoredOrders(orders || []), list = _this24$deduplicateSt.list, repairs = _this24$deduplicateSt.repairs, obsoleteKeys = _this24$deduplicateSt.obsoleteKeys;
3962
4059
  normalizedOrders = list;
3963
4060
  sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3964
4061
  if (!(repairs.length > 0)) {
3965
- _context24.next = 38;
4062
+ _context25.next = 38;
3966
4063
  break;
3967
4064
  }
3968
- _context24.prev = 10;
3969
- _context24.next = 13;
4065
+ _context25.prev = 10;
4066
+ _context25.next = 13;
3970
4067
  return _this24.writeOrderRowsToSQLite(repairs);
3971
4068
  case 13:
3972
4069
  _this24.recordRecentSqliteWrite('loadOrdersFromSQLite.deduplicate', repairs);
3973
- _iterator34 = _createForOfIteratorHelper(obsoleteKeys);
3974
- _context24.prev = 15;
3975
- _iterator34.s();
4070
+ _iterator35 = _createForOfIteratorHelper(obsoleteKeys);
4071
+ _context25.prev = 15;
4072
+ _iterator35.s();
3976
4073
  case 17:
3977
- if ((_step34 = _iterator34.n()).done) {
3978
- _context24.next = 24;
4074
+ if ((_step35 = _iterator35.n()).done) {
4075
+ _context25.next = 24;
3979
4076
  break;
3980
4077
  }
3981
- _key12 = _step34.value;
3982
- _context24.next = 21;
3983
- return _this24.dbManager.delete(INDEXDB_STORE_NAME, _key12);
4078
+ _key13 = _step35.value;
4079
+ _context25.next = 21;
4080
+ return _this24.dbManager.delete(INDEXDB_STORE_NAME, _key13);
3984
4081
  case 21:
3985
- _this24.recentSqliteWriteByStorageKey.delete(_key12);
4082
+ _this24.recentSqliteWriteByStorageKey.delete(_key13);
3986
4083
  case 22:
3987
- _context24.next = 17;
4084
+ _context25.next = 17;
3988
4085
  break;
3989
4086
  case 24:
3990
- _context24.next = 29;
4087
+ _context25.next = 29;
3991
4088
  break;
3992
4089
  case 26:
3993
- _context24.prev = 26;
3994
- _context24.t0 = _context24["catch"](15);
3995
- _iterator34.e(_context24.t0);
4090
+ _context25.prev = 26;
4091
+ _context25.t0 = _context25["catch"](15);
4092
+ _iterator35.e(_context25.t0);
3996
4093
  case 29:
3997
- _context24.prev = 29;
3998
- _iterator34.f();
3999
- return _context24.finish(29);
4094
+ _context25.prev = 29;
4095
+ _iterator35.f();
4096
+ return _context25.finish(29);
4000
4097
  case 32:
4001
4098
  _this24.logInfo('SQLite重复订单已修复', {
4002
4099
  beforeCount: orders.length,
@@ -4004,14 +4101,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4004
4101
  repairedCount: repairs.length,
4005
4102
  deletedKeyCount: obsoleteKeys.size
4006
4103
  });
4007
- _context24.next = 38;
4104
+ _context25.next = 38;
4008
4105
  break;
4009
4106
  case 35:
4010
- _context24.prev = 35;
4011
- _context24.t1 = _context24["catch"](10);
4107
+ _context25.prev = 35;
4108
+ _context25.t1 = _context25["catch"](10);
4012
4109
  // 本次仍使用去重后的内存快照;保留磁盘记录,后续读取可重试修复。
4013
4110
  _this24.logError('SQLite重复订单修复写入失败', {
4014
- error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
4111
+ error: _context25.t1 instanceof Error ? _context25.t1.message : String(_context25.t1),
4015
4112
  repairedCount: repairs.length
4016
4113
  });
4017
4114
  case 38:
@@ -4022,9 +4119,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4022
4119
  });
4023
4120
  case 39:
4024
4121
  case "end":
4025
- return _context24.stop();
4122
+ return _context25.stop();
4026
4123
  }
4027
- }, _callee24, null, [[10, 35], [15, 26, 29, 32]]);
4124
+ }, _callee25, null, [[10, 35], [15, 26, 29, 32]]);
4028
4125
  })));
4029
4126
  case 9:
4030
4127
  if (this.store.list !== memoryBeforeLoad) {
@@ -4037,22 +4134,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4037
4134
  });
4038
4135
  normalizedOrders = this.deduplicateStoredOrders([].concat(_toConsumableArray(normalizedOrders), _toConsumableArray(protectedMemoryOrders)), new Set(protectedMemoryOrders)).list;
4039
4136
  }
4040
- return _context25.abrupt("return", normalizedOrders);
4137
+ return _context26.abrupt("return", normalizedOrders);
4041
4138
  case 13:
4042
- _context25.prev = 13;
4043
- _context25.t0 = _context25["catch"](3);
4139
+ _context26.prev = 13;
4140
+ _context26.t0 = _context26["catch"](3);
4044
4141
  if (!options.throwOnError) {
4045
- _context25.next = 17;
4142
+ _context26.next = 17;
4046
4143
  break;
4047
4144
  }
4048
- throw _context25.t0;
4145
+ throw _context26.t0;
4049
4146
  case 17:
4050
- return _context25.abrupt("return", []);
4147
+ return _context26.abrupt("return", []);
4051
4148
  case 18:
4052
4149
  case "end":
4053
- return _context25.stop();
4150
+ return _context26.stop();
4054
4151
  }
4055
- }, _callee25, this, [[3, 13]]);
4152
+ }, _callee26, this, [[3, 13]]);
4056
4153
  }));
4057
4154
  function loadOrdersFromSQLite() {
4058
4155
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -4065,31 +4162,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4065
4162
  var _this25 = this;
4066
4163
  var authoritativeOrders = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
4067
4164
  var idsByExternal = new Map();
4068
- var _iterator35 = _createForOfIteratorHelper(orders),
4069
- _step35;
4165
+ var _iterator36 = _createForOfIteratorHelper(orders),
4166
+ _step36;
4070
4167
  try {
4071
- for (_iterator35.s(); !(_step35 = _iterator35.n()).done;) {
4072
- var order = _step35.value;
4168
+ for (_iterator36.s(); !(_step36 = _iterator36.n()).done;) {
4169
+ var order = _step36.value;
4073
4170
  var id = this.getRealOrderId(order);
4074
4171
  var external = order.external_sale_number;
4075
4172
  if (!id || this.isBlankIdentityValue(external)) continue;
4076
- var _key13 = String(external);
4077
- var previous = idsByExternal.get(_key13);
4078
- idsByExternal.set(_key13, previous === undefined || previous === id ? id : null);
4173
+ var _key14 = String(external);
4174
+ var previous = idsByExternal.get(_key14);
4175
+ idsByExternal.set(_key14, previous === undefined || previous === id ? id : null);
4079
4176
  }
4080
4177
  } catch (err) {
4081
- _iterator35.e(err);
4178
+ _iterator36.e(err);
4082
4179
  } finally {
4083
- _iterator35.f();
4180
+ _iterator36.f();
4084
4181
  }
4085
4182
  var groups = new Map();
4086
- var _iterator36 = _createForOfIteratorHelper(orders.entries()),
4087
- _step36;
4183
+ var _iterator37 = _createForOfIteratorHelper(orders.entries()),
4184
+ _step37;
4088
4185
  try {
4089
- for (_iterator36.s(); !(_step36 = _iterator36.n()).done;) {
4090
- var _step36$value = _slicedToArray(_step36.value, 2),
4091
- index = _step36$value[0],
4092
- rawOrder = _step36$value[1];
4186
+ for (_iterator37.s(); !(_step37 = _iterator37.n()).done;) {
4187
+ var _step37$value = _slicedToArray(_step37.value, 2),
4188
+ index = _step37$value[0],
4189
+ rawOrder = _step37$value[1];
4093
4190
  var _external = this.isBlankIdentityValue(rawOrder.external_sale_number) ? '' : String(rawOrder.external_sale_number);
4094
4191
  var _id = this.getRealOrderId(rawOrder) || _external && idsByExternal.get(_external);
4095
4192
  var identity = _id ? "id:".concat(_id) : _external ? "external:".concat(_external) : "row:".concat(index);
@@ -4109,32 +4206,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4109
4206
  }
4110
4207
  }
4111
4208
  } catch (err) {
4112
- _iterator36.e(err);
4209
+ _iterator37.e(err);
4113
4210
  } finally {
4114
- _iterator36.f();
4211
+ _iterator37.f();
4115
4212
  }
4116
4213
  var canonicalKeyCounts = new Map();
4117
- var _iterator37 = _createForOfIteratorHelper(groups.values()),
4118
- _step37;
4214
+ var _iterator38 = _createForOfIteratorHelper(groups.values()),
4215
+ _step38;
4119
4216
  try {
4120
- for (_iterator37.s(); !(_step37 = _iterator37.n()).done;) {
4121
- var _order2 = _step37.value.order;
4122
- var _key14 = this.getOrderStorageKey(_order2);
4123
- canonicalKeyCounts.set(_key14, (canonicalKeyCounts.get(_key14) || 0) + 1);
4217
+ for (_iterator38.s(); !(_step38 = _iterator38.n()).done;) {
4218
+ var _order2 = _step38.value.order;
4219
+ var _key15 = this.getOrderStorageKey(_order2);
4220
+ canonicalKeyCounts.set(_key15, (canonicalKeyCounts.get(_key15) || 0) + 1);
4124
4221
  }
4125
4222
  } catch (err) {
4126
- _iterator37.e(err);
4223
+ _iterator38.e(err);
4127
4224
  } finally {
4128
- _iterator37.f();
4225
+ _iterator38.f();
4129
4226
  }
4130
4227
  var list = [];
4131
4228
  var repairs = [];
4132
4229
  var obsoleteKeys = new Set();
4133
- var _iterator38 = _createForOfIteratorHelper(groups.values()),
4134
- _step38;
4230
+ var _iterator39 = _createForOfIteratorHelper(groups.values()),
4231
+ _step39;
4135
4232
  try {
4136
4233
  var _loop3 = function _loop3() {
4137
- var group = _step38.value;
4234
+ var group = _step39.value;
4138
4235
  var key = _this25.getOrderStorageKey(group.order);
4139
4236
  var needsRepair = group.count > 1 || _toConsumableArray(group.keys).some(function (oldKey) {
4140
4237
  return oldKey !== key;
@@ -4143,28 +4240,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4143
4240
  if (needsRepair && key && canonicalKeyCounts.get(key) === 1) {
4144
4241
  group.order = _objectSpread(_objectSpread({}, group.order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, key));
4145
4242
  repairs.push(group.order);
4146
- var _iterator39 = _createForOfIteratorHelper(group.keys),
4147
- _step39;
4243
+ var _iterator40 = _createForOfIteratorHelper(group.keys),
4244
+ _step40;
4148
4245
  try {
4149
- for (_iterator39.s(); !(_step39 = _iterator39.n()).done;) {
4150
- var oldKey = _step39.value;
4246
+ for (_iterator40.s(); !(_step40 = _iterator40.n()).done;) {
4247
+ var oldKey = _step40.value;
4151
4248
  if (oldKey && oldKey !== key && !canonicalKeyCounts.has(oldKey)) obsoleteKeys.add(oldKey);
4152
4249
  }
4153
4250
  } catch (err) {
4154
- _iterator39.e(err);
4251
+ _iterator40.e(err);
4155
4252
  } finally {
4156
- _iterator39.f();
4253
+ _iterator40.f();
4157
4254
  }
4158
4255
  }
4159
4256
  list.push(group.order);
4160
4257
  };
4161
- for (_iterator38.s(); !(_step38 = _iterator38.n()).done;) {
4258
+ for (_iterator39.s(); !(_step39 = _iterator39.n()).done;) {
4162
4259
  _loop3();
4163
4260
  }
4164
4261
  } catch (err) {
4165
- _iterator38.e(err);
4262
+ _iterator39.e(err);
4166
4263
  } finally {
4167
- _iterator38.f();
4264
+ _iterator39.f();
4168
4265
  }
4169
4266
  return {
4170
4267
  list: list,
@@ -4188,11 +4285,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4188
4285
  } else if (priority(left) !== priority(right)) {
4189
4286
  preferred = priority(left) > priority(right) ? left : right;
4190
4287
  } else {
4191
- var _iterator40 = _createForOfIteratorHelper(['updated_at', 'created_at']),
4192
- _step40;
4288
+ var _iterator41 = _createForOfIteratorHelper(['updated_at', 'created_at']),
4289
+ _step41;
4193
4290
  try {
4194
4291
  var _loop4 = function _loop4() {
4195
- var field = _step40.value;
4292
+ var field = _step41.value;
4196
4293
  var timestamp = function timestamp(order) {
4197
4294
  var value = order[field];
4198
4295
  if (!value) return 0;
@@ -4204,15 +4301,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4204
4301
  return 1; // break
4205
4302
  },
4206
4303
  _ret2;
4207
- for (_iterator40.s(); !(_step40 = _iterator40.n()).done;) {
4304
+ for (_iterator41.s(); !(_step41 = _iterator41.n()).done;) {
4208
4305
  _ret2 = _loop4();
4209
4306
  if (_ret2 === 0) continue;
4210
4307
  if (_ret2 === 1) break;
4211
4308
  }
4212
4309
  } catch (err) {
4213
- _iterator40.e(err);
4310
+ _iterator41.e(err);
4214
4311
  } finally {
4215
- _iterator40.f();
4312
+ _iterator41.f();
4216
4313
  }
4217
4314
  }
4218
4315
  var secondary = preferred === left ? right : left;
@@ -4221,17 +4318,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4221
4318
  var merged = _objectSpread(_objectSpread({}, reconciled), cloneDeep(preferred));
4222
4319
  var realOrder = this.getRealOrderId(preferred) ? preferred : secondary;
4223
4320
  if (this.getRealOrderId(realOrder)) merged.order_id = realOrder.order_id;
4224
- var _iterator41 = _createForOfIteratorHelper(this.getOrderIdentityEntries(reconciled)),
4225
- _step41;
4321
+ var _iterator42 = _createForOfIteratorHelper(this.getOrderIdentityEntries(reconciled)),
4322
+ _step42;
4226
4323
  try {
4227
- for (_iterator41.s(); !(_step41 = _iterator41.n()).done;) {
4228
- var _field3 = _step41.value.field;
4324
+ for (_iterator42.s(); !(_step42 = _iterator42.n()).done;) {
4325
+ var _field3 = _step42.value.field;
4229
4326
  if (this.isBlankIdentityValue(merged[_field3])) merged[_field3] = reconciled[_field3];
4230
4327
  }
4231
4328
  } catch (err) {
4232
- _iterator41.e(err);
4329
+ _iterator42.e(err);
4233
4330
  } finally {
4234
- _iterator41.f();
4331
+ _iterator42.f();
4235
4332
  }
4236
4333
  for (var _i8 = 0, _ORDER_AUTHORITATIVE_3 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i8 < _ORDER_AUTHORITATIVE_3.length; _i8++) {
4237
4334
  var field = _ORDER_AUTHORITATIVE_3[_i8];
@@ -4247,67 +4344,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4247
4344
  }, {
4248
4345
  key: "writeOrderRowsToSQLite",
4249
4346
  value: function () {
4250
- var _writeOrderRowsToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orders) {
4251
- var _iterator42, _step42, order;
4252
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4253
- while (1) switch (_context26.prev = _context26.next) {
4347
+ var _writeOrderRowsToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orders) {
4348
+ var _iterator43, _step43, order;
4349
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4350
+ while (1) switch (_context27.prev = _context27.next) {
4254
4351
  case 0:
4255
4352
  if (!(typeof this.dbManager.bulkUpdate === 'function')) {
4256
- _context26.next = 4;
4353
+ _context27.next = 4;
4257
4354
  break;
4258
4355
  }
4259
- _context26.next = 3;
4356
+ _context27.next = 3;
4260
4357
  return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, orders);
4261
4358
  case 3:
4262
- return _context26.abrupt("return", 'bulkUpdate');
4359
+ return _context27.abrupt("return", 'bulkUpdate');
4263
4360
  case 4:
4264
4361
  if (!(typeof this.dbManager.bulkAdd === 'function')) {
4265
- _context26.next = 8;
4362
+ _context27.next = 8;
4266
4363
  break;
4267
4364
  }
4268
- _context26.next = 7;
4365
+ _context27.next = 7;
4269
4366
  return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orders);
4270
4367
  case 7:
4271
- return _context26.abrupt("return", 'bulkAdd');
4368
+ return _context27.abrupt("return", 'bulkAdd');
4272
4369
  case 8:
4273
4370
  if (!(typeof this.dbManager.update === 'function')) {
4274
- _context26.next = 27;
4371
+ _context27.next = 27;
4275
4372
  break;
4276
4373
  }
4277
- _iterator42 = _createForOfIteratorHelper(orders);
4278
- _context26.prev = 10;
4279
- _iterator42.s();
4374
+ _iterator43 = _createForOfIteratorHelper(orders);
4375
+ _context27.prev = 10;
4376
+ _iterator43.s();
4280
4377
  case 12:
4281
- if ((_step42 = _iterator42.n()).done) {
4282
- _context26.next = 18;
4378
+ if ((_step43 = _iterator43.n()).done) {
4379
+ _context27.next = 18;
4283
4380
  break;
4284
4381
  }
4285
- order = _step42.value;
4286
- _context26.next = 16;
4382
+ order = _step43.value;
4383
+ _context27.next = 16;
4287
4384
  return this.dbManager.update(INDEXDB_STORE_NAME, order);
4288
4385
  case 16:
4289
- _context26.next = 12;
4386
+ _context27.next = 12;
4290
4387
  break;
4291
4388
  case 18:
4292
- _context26.next = 23;
4389
+ _context27.next = 23;
4293
4390
  break;
4294
4391
  case 20:
4295
- _context26.prev = 20;
4296
- _context26.t0 = _context26["catch"](10);
4297
- _iterator42.e(_context26.t0);
4392
+ _context27.prev = 20;
4393
+ _context27.t0 = _context27["catch"](10);
4394
+ _iterator43.e(_context27.t0);
4298
4395
  case 23:
4299
- _context26.prev = 23;
4300
- _iterator42.f();
4301
- return _context26.finish(23);
4396
+ _context27.prev = 23;
4397
+ _iterator43.f();
4398
+ return _context27.finish(23);
4302
4399
  case 26:
4303
- return _context26.abrupt("return", 'update');
4400
+ return _context27.abrupt("return", 'update');
4304
4401
  case 27:
4305
4402
  throw new Error('订单 SQLite 数据库不支持写入');
4306
4403
  case 28:
4307
4404
  case "end":
4308
- return _context26.stop();
4405
+ return _context27.stop();
4309
4406
  }
4310
- }, _callee26, this, [[10, 20, 23, 26]]);
4407
+ }, _callee27, this, [[10, 20, 23, 26]]);
4311
4408
  }));
4312
4409
  function writeOrderRowsToSQLite(_x18) {
4313
4410
  return _writeOrderRowsToSQLite.apply(this, arguments);
@@ -4361,11 +4458,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4361
4458
  var merged = remoteOrders.map(function (order) {
4362
4459
  return _this27.normalizeRemoteSyncedOrder(order);
4363
4460
  });
4364
- var _iterator43 = _createForOfIteratorHelper(existingOrders),
4365
- _step43;
4461
+ var _iterator44 = _createForOfIteratorHelper(existingOrders),
4462
+ _step44;
4366
4463
  try {
4367
- for (_iterator43.s(); !(_step43 = _iterator43.n()).done;) {
4368
- var rawOrder = _step43.value;
4464
+ for (_iterator44.s(); !(_step44 = _iterator44.n()).done;) {
4465
+ var rawOrder = _step44.value;
4369
4466
  var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
4370
4467
  if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
4371
4468
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
@@ -4381,9 +4478,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4381
4478
  merged.push(order);
4382
4479
  }
4383
4480
  } catch (err) {
4384
- _iterator43.e(err);
4481
+ _iterator44.e(err);
4385
4482
  } finally {
4386
- _iterator43.f();
4483
+ _iterator44.f();
4387
4484
  }
4388
4485
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
4389
4486
  }
@@ -4399,10 +4496,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4399
4496
  }, {
4400
4497
  key: "runInOrderSQLiteSaveQueue",
4401
4498
  value: (function () {
4402
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(task) {
4499
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(task) {
4403
4500
  var queuedTask;
4404
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4405
- while (1) switch (_context27.prev = _context27.next) {
4501
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4502
+ while (1) switch (_context28.prev = _context28.next) {
4406
4503
  case 0:
4407
4504
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
4408
4505
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -4410,12 +4507,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4410
4507
  }, function () {
4411
4508
  return undefined;
4412
4509
  });
4413
- return _context27.abrupt("return", queuedTask);
4510
+ return _context28.abrupt("return", queuedTask);
4414
4511
  case 3:
4415
4512
  case "end":
4416
- return _context27.stop();
4513
+ return _context28.stop();
4417
4514
  }
4418
- }, _callee27, this);
4515
+ }, _callee28, this);
4419
4516
  }));
4420
4517
  function runInOrderSQLiteSaveQueue(_x19) {
4421
4518
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
@@ -4432,7 +4529,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4432
4529
  }, {
4433
4530
  key: "patchOrdersInSQLite",
4434
4531
  value: (function () {
4435
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(orders, source) {
4532
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(orders, source) {
4436
4533
  var _this28 = this;
4437
4534
  var mergeActions,
4438
4535
  options,
@@ -4445,33 +4542,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4445
4542
  compactedToWrite,
4446
4543
  writtenStorageKeys,
4447
4544
  storageKeyMigrations,
4448
- _iterator44,
4449
- _step44,
4545
+ _iterator45,
4546
+ _step45,
4450
4547
  migration,
4451
- _args29 = arguments;
4452
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4453
- while (1) switch (_context29.prev = _context29.next) {
4548
+ _args30 = arguments;
4549
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4550
+ while (1) switch (_context30.prev = _context30.next) {
4454
4551
  case 0:
4455
- mergeActions = _args29.length > 2 && _args29[2] !== undefined ? _args29[2] : {};
4456
- options = _args29.length > 3 && _args29[3] !== undefined ? _args29[3] : {};
4457
- forceWriteStorageKeys = _args29.length > 4 && _args29[4] !== undefined ? _args29[4] : new Set();
4552
+ mergeActions = _args30.length > 2 && _args30[2] !== undefined ? _args30[2] : {};
4553
+ options = _args30.length > 3 && _args30[3] !== undefined ? _args30[3] : {};
4554
+ forceWriteStorageKeys = _args30.length > 4 && _args30[4] !== undefined ? _args30[4] : new Set();
4458
4555
  if (!(orders.length === 0)) {
4459
- _context29.next = 5;
4556
+ _context30.next = 5;
4460
4557
  break;
4461
4558
  }
4462
- return _context29.abrupt("return");
4559
+ return _context30.abrupt("return");
4463
4560
  case 5:
4464
4561
  if (this.dbManager) {
4465
- _context29.next = 9;
4562
+ _context30.next = 9;
4466
4563
  break;
4467
4564
  }
4468
4565
  if (!options.throwOnError) {
4469
- _context29.next = 8;
4566
+ _context30.next = 8;
4470
4567
  break;
4471
4568
  }
4472
4569
  throw new Error('订单 SQLite 数据库未初始化');
4473
4570
  case 8:
4474
- return _context29.abrupt("return");
4571
+ return _context30.abrupt("return");
4475
4572
  case 9:
4476
4573
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
4477
4574
  return migration.to;
@@ -4486,72 +4583,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4486
4583
  return _this28.getOrderStorageKey(order);
4487
4584
  });
4488
4585
  if (!(ordersSnapshot.length === 0)) {
4489
- _context29.next = 13;
4586
+ _context30.next = 13;
4490
4587
  break;
4491
4588
  }
4492
- return _context29.abrupt("return");
4589
+ return _context30.abrupt("return");
4493
4590
  case 13:
4494
4591
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, new Set([].concat(_toConsumableArray(forceWriteStorageKeys), _toConsumableArray(migrationTargetStorageKeys)))), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
4495
4592
  if (!(toWrite.length === 0)) {
4496
- _context29.next = 16;
4593
+ _context30.next = 16;
4497
4594
  break;
4498
4595
  }
4499
- return _context29.abrupt("return");
4596
+ return _context30.abrupt("return");
4500
4597
  case 16:
4501
4598
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
4502
4599
  if (!(compactedToWrite.length === 0)) {
4503
- _context29.next = 19;
4600
+ _context30.next = 19;
4504
4601
  break;
4505
4602
  }
4506
- return _context29.abrupt("return");
4603
+ return _context30.abrupt("return");
4507
4604
  case 19:
4508
4605
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
4509
4606
  return _this28.getOrderStorageKey(order);
4510
4607
  }).filter(Boolean));
4511
4608
  storageKeyMigrations = new Map();
4512
- _iterator44 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
4513
- _context29.prev = 22;
4514
- _iterator44.s();
4609
+ _iterator45 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
4610
+ _context30.prev = 22;
4611
+ _iterator45.s();
4515
4612
  case 24:
4516
- if ((_step44 = _iterator44.n()).done) {
4517
- _context29.next = 33;
4613
+ if ((_step45 = _iterator45.n()).done) {
4614
+ _context30.next = 33;
4518
4615
  break;
4519
4616
  }
4520
- migration = _step44.value;
4617
+ migration = _step45.value;
4521
4618
  if (writtenStorageKeys.has(migration.to)) {
4522
- _context29.next = 28;
4619
+ _context30.next = 28;
4523
4620
  break;
4524
4621
  }
4525
- return _context29.abrupt("continue", 31);
4622
+ return _context30.abrupt("continue", 31);
4526
4623
  case 28:
4527
4624
  if (!writtenStorageKeys.has(migration.from)) {
4528
- _context29.next = 30;
4625
+ _context30.next = 30;
4529
4626
  break;
4530
4627
  }
4531
- return _context29.abrupt("continue", 31);
4628
+ return _context30.abrupt("continue", 31);
4532
4629
  case 30:
4533
4630
  storageKeyMigrations.set(migration.from, migration);
4534
4631
  case 31:
4535
- _context29.next = 24;
4632
+ _context30.next = 24;
4536
4633
  break;
4537
4634
  case 33:
4538
- _context29.next = 38;
4635
+ _context30.next = 38;
4539
4636
  break;
4540
4637
  case 35:
4541
- _context29.prev = 35;
4542
- _context29.t0 = _context29["catch"](22);
4543
- _iterator44.e(_context29.t0);
4638
+ _context30.prev = 35;
4639
+ _context30.t0 = _context30["catch"](22);
4640
+ _iterator45.e(_context30.t0);
4544
4641
  case 38:
4545
- _context29.prev = 38;
4546
- _iterator44.f();
4547
- return _context29.finish(38);
4642
+ _context30.prev = 38;
4643
+ _iterator45.f();
4644
+ return _context30.finish(38);
4548
4645
  case 41:
4549
- _context29.prev = 41;
4550
- _context29.next = 44;
4551
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4552
- var writeMethod, _iterator45, _step45, migration, _iterator46, _step46, _orderRecord$ORDER_ST, order, orderRecord;
4553
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4554
- while (1) switch (_context28.prev = _context28.next) {
4646
+ _context30.prev = 41;
4647
+ _context30.next = 44;
4648
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4649
+ var writeMethod, _iterator46, _step46, migration, _iterator47, _step47, _orderRecord$ORDER_ST, order, orderRecord;
4650
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4651
+ while (1) switch (_context29.prev = _context29.next) {
4555
4652
  case 0:
4556
4653
  writeMethod = 'none';
4557
4654
  _this28.logInfo('patchOrdersInSQLite-开始', {
@@ -4559,93 +4656,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4559
4656
  count: compactedToWrite.length,
4560
4657
  dedupedCount: skipped.length
4561
4658
  });
4562
- _context28.next = 4;
4659
+ _context29.next = 4;
4563
4660
  return _this28.writeOrderRowsToSQLite(compactedToWrite);
4564
4661
  case 4:
4565
- writeMethod = _context28.sent;
4662
+ writeMethod = _context29.sent;
4566
4663
  _this28.recordRecentSqliteWrite(source, compactedToWrite);
4567
4664
  if (!(writeMethod !== 'none')) {
4568
- _context28.next = 52;
4665
+ _context29.next = 52;
4569
4666
  break;
4570
4667
  }
4571
- _iterator45 = _createForOfIteratorHelper(storageKeyMigrations.values());
4572
- _context28.prev = 8;
4573
- _iterator45.s();
4668
+ _iterator46 = _createForOfIteratorHelper(storageKeyMigrations.values());
4669
+ _context29.prev = 8;
4670
+ _iterator46.s();
4574
4671
  case 10:
4575
- if ((_step45 = _iterator45.n()).done) {
4576
- _context28.next = 44;
4672
+ if ((_step46 = _iterator46.n()).done) {
4673
+ _context29.next = 44;
4577
4674
  break;
4578
4675
  }
4579
- migration = _step45.value;
4580
- _context28.prev = 12;
4581
- _context28.next = 15;
4676
+ migration = _step46.value;
4677
+ _context29.prev = 12;
4678
+ _context29.next = 15;
4582
4679
  return _this28.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4583
4680
  case 15:
4584
4681
  _this28.recentSqliteWriteByStorageKey.delete(migration.from);
4585
- _iterator46 = _createForOfIteratorHelper(orders);
4586
- _context28.prev = 17;
4587
- _iterator46.s();
4682
+ _iterator47 = _createForOfIteratorHelper(orders);
4683
+ _context29.prev = 17;
4684
+ _iterator47.s();
4588
4685
  case 19:
4589
- if ((_step46 = _iterator46.n()).done) {
4590
- _context28.next = 29;
4686
+ if ((_step47 = _iterator47.n()).done) {
4687
+ _context29.next = 29;
4591
4688
  break;
4592
4689
  }
4593
- order = _step46.value;
4690
+ order = _step47.value;
4594
4691
  if (!(_this28.getOrderStorageKey(order) !== migration.to)) {
4595
- _context28.next = 23;
4692
+ _context29.next = 23;
4596
4693
  break;
4597
4694
  }
4598
- return _context28.abrupt("continue", 27);
4695
+ return _context29.abrupt("continue", 27);
4599
4696
  case 23:
4600
4697
  orderRecord = order;
4601
4698
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
4602
- _context28.next = 26;
4699
+ _context29.next = 26;
4603
4700
  break;
4604
4701
  }
4605
- return _context28.abrupt("continue", 27);
4702
+ return _context29.abrupt("continue", 27);
4606
4703
  case 26:
4607
4704
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
4608
4705
  case 27:
4609
- _context28.next = 19;
4706
+ _context29.next = 19;
4610
4707
  break;
4611
4708
  case 29:
4612
- _context28.next = 34;
4709
+ _context29.next = 34;
4613
4710
  break;
4614
4711
  case 31:
4615
- _context28.prev = 31;
4616
- _context28.t0 = _context28["catch"](17);
4617
- _iterator46.e(_context28.t0);
4712
+ _context29.prev = 31;
4713
+ _context29.t0 = _context29["catch"](17);
4714
+ _iterator47.e(_context29.t0);
4618
4715
  case 34:
4619
- _context28.prev = 34;
4620
- _iterator46.f();
4621
- return _context28.finish(34);
4716
+ _context29.prev = 34;
4717
+ _iterator47.f();
4718
+ return _context29.finish(34);
4622
4719
  case 37:
4623
- _context28.next = 42;
4720
+ _context29.next = 42;
4624
4721
  break;
4625
4722
  case 39:
4626
- _context28.prev = 39;
4627
- _context28.t1 = _context28["catch"](12);
4723
+ _context29.prev = 39;
4724
+ _context29.t1 = _context29["catch"](12);
4628
4725
  _this28.logError('删除订单旧 SQLite storage key 失败', {
4629
4726
  source: source,
4630
4727
  order_id: migration.orderId,
4631
4728
  oldStorageKey: migration.from,
4632
4729
  newStorageKey: migration.to,
4633
- error: _context28.t1 instanceof Error ? _context28.t1.message : String(_context28.t1)
4730
+ error: _context29.t1 instanceof Error ? _context29.t1.message : String(_context29.t1)
4634
4731
  });
4635
4732
  case 42:
4636
- _context28.next = 10;
4733
+ _context29.next = 10;
4637
4734
  break;
4638
4735
  case 44:
4639
- _context28.next = 49;
4736
+ _context29.next = 49;
4640
4737
  break;
4641
4738
  case 46:
4642
- _context28.prev = 46;
4643
- _context28.t2 = _context28["catch"](8);
4644
- _iterator45.e(_context28.t2);
4739
+ _context29.prev = 46;
4740
+ _context29.t2 = _context29["catch"](8);
4741
+ _iterator46.e(_context29.t2);
4645
4742
  case 49:
4646
- _context28.prev = 49;
4647
- _iterator45.f();
4648
- return _context28.finish(49);
4743
+ _context29.prev = 49;
4744
+ _iterator46.f();
4745
+ return _context29.finish(49);
4649
4746
  case 52:
4650
4747
  _this28.logInfo('patchOrdersInSQLite-完成', {
4651
4748
  source: source,
@@ -4655,30 +4752,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4655
4752
  });
4656
4753
  case 53:
4657
4754
  case "end":
4658
- return _context28.stop();
4755
+ return _context29.stop();
4659
4756
  }
4660
- }, _callee28, null, [[8, 46, 49, 52], [12, 39], [17, 31, 34, 37]]);
4757
+ }, _callee29, null, [[8, 46, 49, 52], [12, 39], [17, 31, 34, 37]]);
4661
4758
  })));
4662
4759
  case 44:
4663
- _context29.next = 51;
4760
+ _context30.next = 51;
4664
4761
  break;
4665
4762
  case 46:
4666
- _context29.prev = 46;
4667
- _context29.t1 = _context29["catch"](41);
4763
+ _context30.prev = 46;
4764
+ _context30.t1 = _context30["catch"](41);
4668
4765
  this.logError('增量保存订单到 SQLite 失败', {
4669
- error: _context29.t1 instanceof Error ? _context29.t1.message : String(_context29.t1),
4766
+ error: _context30.t1 instanceof Error ? _context30.t1.message : String(_context30.t1),
4670
4767
  orderCount: ordersSnapshot.length
4671
4768
  });
4672
4769
  if (!options.throwOnError) {
4673
- _context29.next = 51;
4770
+ _context30.next = 51;
4674
4771
  break;
4675
4772
  }
4676
- throw _context29.t1;
4773
+ throw _context30.t1;
4677
4774
  case 51:
4678
4775
  case "end":
4679
- return _context29.stop();
4776
+ return _context30.stop();
4680
4777
  }
4681
- }, _callee29, this, [[22, 35, 38, 41], [41, 46]]);
4778
+ }, _callee30, this, [[22, 35, 38, 41], [41, 46]]);
4682
4779
  }));
4683
4780
  function patchOrdersInSQLite(_x20, _x21) {
4684
4781
  return _patchOrdersInSQLite.apply(this, arguments);
@@ -4695,48 +4792,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4695
4792
  }, {
4696
4793
  key: "updateOrderInSQLite",
4697
4794
  value: (function () {
4698
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(order, source) {
4795
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(order, source) {
4699
4796
  var _this29 = this;
4700
4797
  var options,
4701
4798
  orderSnapshot,
4702
4799
  _orderSnapshot$order_3,
4703
- _args31 = arguments;
4704
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4705
- while (1) switch (_context31.prev = _context31.next) {
4800
+ _args32 = arguments;
4801
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4802
+ while (1) switch (_context32.prev = _context32.next) {
4706
4803
  case 0:
4707
- options = _args31.length > 2 && _args31[2] !== undefined ? _args31[2] : {};
4804
+ options = _args32.length > 2 && _args32[2] !== undefined ? _args32[2] : {};
4708
4805
  if (this.getOrderStorageKey(order)) {
4709
- _context31.next = 5;
4806
+ _context32.next = 5;
4710
4807
  break;
4711
4808
  }
4712
4809
  if (!options.throwOnError) {
4713
- _context31.next = 4;
4810
+ _context32.next = 4;
4714
4811
  break;
4715
4812
  }
4716
4813
  throw new Error('订单缺少可用的 SQLite 存储主键');
4717
4814
  case 4:
4718
- return _context31.abrupt("return");
4815
+ return _context32.abrupt("return");
4719
4816
  case 5:
4720
4817
  if (this.dbManager) {
4721
- _context31.next = 9;
4818
+ _context32.next = 9;
4722
4819
  break;
4723
4820
  }
4724
4821
  if (!options.throwOnError) {
4725
- _context31.next = 8;
4822
+ _context32.next = 8;
4726
4823
  break;
4727
4824
  }
4728
4825
  throw new Error('订单 SQLite 数据库未初始化');
4729
4826
  case 8:
4730
- return _context31.abrupt("return");
4827
+ return _context32.abrupt("return");
4731
4828
  case 9:
4732
4829
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4733
- _context31.prev = 10;
4734
- _context31.next = 13;
4735
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4830
+ _context32.prev = 10;
4831
+ _context32.next = 13;
4832
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
4736
4833
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4737
4834
  var writeMethod;
4738
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4739
- while (1) switch (_context30.prev = _context30.next) {
4835
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4836
+ while (1) switch (_context31.prev = _context31.next) {
4740
4837
  case 0:
4741
4838
  writeMethod = 'none';
4742
4839
  _this29.logInfo('updateOrderInSQLite-开始', {
@@ -4745,40 +4842,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4745
4842
  storageKey: _this29.getOrderStorageKey(orderSnapshot)
4746
4843
  });
4747
4844
  if (!(typeof _this29.dbManager.update === 'function')) {
4748
- _context30.next = 8;
4845
+ _context31.next = 8;
4749
4846
  break;
4750
4847
  }
4751
4848
  writeMethod = 'update';
4752
- _context30.next = 6;
4849
+ _context31.next = 6;
4753
4850
  return _this29.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4754
4851
  case 6:
4755
- _context30.next = 22;
4852
+ _context31.next = 22;
4756
4853
  break;
4757
4854
  case 8:
4758
4855
  if (!(typeof _this29.dbManager.bulkUpdate === 'function')) {
4759
- _context30.next = 14;
4856
+ _context31.next = 14;
4760
4857
  break;
4761
4858
  }
4762
4859
  writeMethod = 'bulkUpdate';
4763
- _context30.next = 12;
4860
+ _context31.next = 12;
4764
4861
  return _this29.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4765
4862
  case 12:
4766
- _context30.next = 22;
4863
+ _context31.next = 22;
4767
4864
  break;
4768
4865
  case 14:
4769
4866
  if (!(typeof _this29.dbManager.bulkAdd === 'function')) {
4770
- _context30.next = 20;
4867
+ _context31.next = 20;
4771
4868
  break;
4772
4869
  }
4773
4870
  writeMethod = 'bulkAdd';
4774
- _context30.next = 18;
4871
+ _context31.next = 18;
4775
4872
  return _this29.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4776
4873
  case 18:
4777
- _context30.next = 22;
4874
+ _context31.next = 22;
4778
4875
  break;
4779
4876
  case 20:
4780
4877
  if (!options.throwOnError) {
4781
- _context30.next = 22;
4878
+ _context31.next = 22;
4782
4879
  break;
4783
4880
  }
4784
4881
  throw new Error('订单 SQLite 数据库不支持写入');
@@ -4791,30 +4888,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4791
4888
  });
4792
4889
  case 24:
4793
4890
  case "end":
4794
- return _context30.stop();
4891
+ return _context31.stop();
4795
4892
  }
4796
- }, _callee30);
4893
+ }, _callee31);
4797
4894
  })));
4798
4895
  case 13:
4799
- _context31.next = 20;
4896
+ _context32.next = 20;
4800
4897
  break;
4801
4898
  case 15:
4802
- _context31.prev = 15;
4803
- _context31.t0 = _context31["catch"](10);
4899
+ _context32.prev = 15;
4900
+ _context32.t0 = _context32["catch"](10);
4804
4901
  this.logError('单条保存订单到 SQLite 失败', {
4805
- error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0),
4902
+ error: _context32.t0 instanceof Error ? _context32.t0.message : String(_context32.t0),
4806
4903
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4807
4904
  });
4808
4905
  if (!options.throwOnError) {
4809
- _context31.next = 20;
4906
+ _context32.next = 20;
4810
4907
  break;
4811
4908
  }
4812
- throw _context31.t0;
4909
+ throw _context32.t0;
4813
4910
  case 20:
4814
4911
  case "end":
4815
- return _context31.stop();
4912
+ return _context32.stop();
4816
4913
  }
4817
- }, _callee31, this, [[10, 15]]);
4914
+ }, _callee32, this, [[10, 15]]);
4818
4915
  }));
4819
4916
  function updateOrderInSQLite(_x22, _x23) {
4820
4917
  return _updateOrderInSQLite.apply(this, arguments);
@@ -4832,22 +4929,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4832
4929
  }, {
4833
4930
  key: "replaceOrdersSnapshotInSQLite",
4834
4931
  value: (function () {
4835
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(orderList, source) {
4932
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(orderList, source) {
4836
4933
  var _this30 = this;
4837
4934
  var protectedOrdersBeforeRemoteFetch,
4838
4935
  remoteSnapshot,
4839
4936
  mergedSnapshot,
4840
4937
  persisted,
4841
- _args33 = arguments;
4842
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4843
- while (1) switch (_context33.prev = _context33.next) {
4938
+ _args34 = arguments;
4939
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
4940
+ while (1) switch (_context34.prev = _context34.next) {
4844
4941
  case 0:
4845
- protectedOrdersBeforeRemoteFetch = _args33.length > 2 && _args33[2] !== undefined ? _args33[2] : [];
4942
+ protectedOrdersBeforeRemoteFetch = _args34.length > 2 && _args34[2] !== undefined ? _args34[2] : [];
4846
4943
  if (this.dbManager) {
4847
- _context33.next = 3;
4944
+ _context34.next = 3;
4848
4945
  break;
4849
4946
  }
4850
- return _context33.abrupt("return", {
4947
+ return _context34.abrupt("return", {
4851
4948
  orders: this.compactOrderListByIdentity(this.preserveOmittedHolderRelations(orderList, this.store.list).map(function (order) {
4852
4949
  return _this30.normalizeRemoteSyncedOrder(order);
4853
4950
  }), "".concat(source, ".snapshotNoDb")).list,
@@ -4861,47 +4958,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4861
4958
  return _this30.normalizeRemoteSyncedOrder(order);
4862
4959
  }), "".concat(source, ".remoteSnapshot")).list;
4863
4960
  persisted = false;
4864
- _context33.prev = 6;
4865
- _context33.next = 9;
4866
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4867
- var existingOrders, remoteSnapshotWithHolderRelations, protectedLocalOrders, _iterator47, _step47, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4868
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4869
- while (1) switch (_context32.prev = _context32.next) {
4961
+ _context34.prev = 6;
4962
+ _context34.next = 9;
4963
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4964
+ var existingOrders, remoteSnapshotWithHolderRelations, protectedLocalOrders, _iterator48, _step48, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4965
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4966
+ while (1) switch (_context33.prev = _context33.next) {
4870
4967
  case 0:
4871
4968
  if (!(typeof _this30.dbManager.getAll === 'function')) {
4872
- _context32.next = 6;
4969
+ _context33.next = 6;
4873
4970
  break;
4874
4971
  }
4875
- _context32.next = 3;
4972
+ _context33.next = 3;
4876
4973
  return _this30.dbManager.getAll(INDEXDB_STORE_NAME);
4877
4974
  case 3:
4878
- _context32.t0 = _context32.sent;
4879
- _context32.next = 7;
4975
+ _context33.t0 = _context33.sent;
4976
+ _context33.next = 7;
4880
4977
  break;
4881
4978
  case 6:
4882
- _context32.t0 = [];
4979
+ _context33.t0 = [];
4883
4980
  case 7:
4884
- existingOrders = _context32.t0;
4981
+ existingOrders = _context33.t0;
4885
4982
  remoteSnapshotWithHolderRelations = _this30.preserveOmittedHolderRelations(remoteSnapshot, [].concat(_toConsumableArray(protectedOrdersBeforeRemoteFetch), _toConsumableArray(existingOrders || [])));
4886
4983
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4887
4984
  return _this30.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4888
4985
  }).filter(function (order) {
4889
4986
  return _this30.shouldProtectLocalOrderFromRemoteSnapshot(order);
4890
4987
  });
4891
- _iterator47 = _createForOfIteratorHelper(existingOrders || []);
4892
- _context32.prev = 11;
4893
- _iterator47.s();
4988
+ _iterator48 = _createForOfIteratorHelper(existingOrders || []);
4989
+ _context33.prev = 11;
4990
+ _iterator48.s();
4894
4991
  case 13:
4895
- if ((_step47 = _iterator47.n()).done) {
4896
- _context32.next = 24;
4992
+ if ((_step48 = _iterator48.n()).done) {
4993
+ _context33.next = 24;
4897
4994
  break;
4898
4995
  }
4899
- rawCurrentOrder = _step47.value;
4996
+ rawCurrentOrder = _step48.value;
4900
4997
  currentOrder = _this30.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4901
4998
  protectedIndex = _this30.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4902
4999
  currentNeedsProtection = _this30.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4903
5000
  if (!(protectedIndex >= 0)) {
4904
- _context32.next = 21;
5001
+ _context33.next = 21;
4905
5002
  break;
4906
5003
  }
4907
5004
  if (currentNeedsProtection) {
@@ -4909,23 +5006,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4909
5006
  } else {
4910
5007
  protectedLocalOrders.splice(protectedIndex, 1);
4911
5008
  }
4912
- return _context32.abrupt("continue", 22);
5009
+ return _context33.abrupt("continue", 22);
4913
5010
  case 21:
4914
5011
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4915
5012
  case 22:
4916
- _context32.next = 13;
5013
+ _context33.next = 13;
4917
5014
  break;
4918
5015
  case 24:
4919
- _context32.next = 29;
5016
+ _context33.next = 29;
4920
5017
  break;
4921
5018
  case 26:
4922
- _context32.prev = 26;
4923
- _context32.t1 = _context32["catch"](11);
4924
- _iterator47.e(_context32.t1);
5019
+ _context33.prev = 26;
5020
+ _context33.t1 = _context33["catch"](11);
5021
+ _iterator48.e(_context33.t1);
4925
5022
  case 29:
4926
- _context32.prev = 29;
4927
- _iterator47.f();
4928
- return _context32.finish(29);
5023
+ _context33.prev = 29;
5024
+ _iterator48.f();
5025
+ return _context33.finish(29);
4929
5026
  case 32:
4930
5027
  orderListSnapshot = _this30.mergeRemoteSnapshotWithPendingOrders(remoteSnapshotWithHolderRelations, protectedLocalOrders);
4931
5028
  mergedSnapshot = _this30.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
@@ -4950,19 +5047,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4950
5047
  });
4951
5048
  })
4952
5049
  });
4953
- _context32.next = 37;
5050
+ _context33.next = 37;
4954
5051
  return _this30.dbManager.clear(INDEXDB_STORE_NAME);
4955
5052
  case 37:
4956
5053
  _this30.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4957
5054
  count: mergedSnapshot.length
4958
5055
  });
4959
5056
  if (!(mergedSnapshot.length === 0)) {
4960
- _context32.next = 40;
5057
+ _context33.next = 40;
4961
5058
  break;
4962
5059
  }
4963
- return _context32.abrupt("return");
5060
+ return _context33.abrupt("return");
4964
5061
  case 40:
4965
- _context32.next = 42;
5062
+ _context33.next = 42;
4966
5063
  return _this30.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4967
5064
  case 42:
4968
5065
  _this30.recordRecentSqliteWrite(source, mergedSnapshot);
@@ -4972,31 +5069,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4972
5069
  });
4973
5070
  case 44:
4974
5071
  case "end":
4975
- return _context32.stop();
5072
+ return _context33.stop();
4976
5073
  }
4977
- }, _callee32, null, [[11, 26, 29, 32]]);
5074
+ }, _callee33, null, [[11, 26, 29, 32]]);
4978
5075
  })));
4979
5076
  case 9:
4980
5077
  persisted = true;
4981
- _context33.next = 15;
5078
+ _context34.next = 15;
4982
5079
  break;
4983
5080
  case 12:
4984
- _context33.prev = 12;
4985
- _context33.t0 = _context33["catch"](6);
5081
+ _context34.prev = 12;
5082
+ _context34.t0 = _context34["catch"](6);
4986
5083
  this.logError('全量保存订单到 SQLite 失败', {
4987
- error: _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0),
5084
+ error: _context34.t0 instanceof Error ? _context34.t0.message : String(_context34.t0),
4988
5085
  orderList: remoteSnapshot.length
4989
5086
  });
4990
5087
  case 15:
4991
- return _context33.abrupt("return", {
5088
+ return _context34.abrupt("return", {
4992
5089
  orders: mergedSnapshot,
4993
5090
  persisted: persisted
4994
5091
  });
4995
5092
  case 16:
4996
5093
  case "end":
4997
- return _context33.stop();
5094
+ return _context34.stop();
4998
5095
  }
4999
- }, _callee33, this, [[6, 12]]);
5096
+ }, _callee34, this, [[6, 12]]);
5000
5097
  }));
5001
5098
  function replaceOrdersSnapshotInSQLite(_x24, _x25) {
5002
5099
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
@@ -5013,38 +5110,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5013
5110
  }, {
5014
5111
  key: "clear",
5015
5112
  value: (function () {
5016
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
5113
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
5017
5114
  var _this31 = this;
5018
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
5019
- while (1) switch (_context35.prev = _context35.next) {
5115
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
5116
+ while (1) switch (_context36.prev = _context36.next) {
5020
5117
  case 0:
5021
5118
  this.store.list = [];
5022
5119
  this.store.map = new Map();
5023
5120
  if (!this.dbManager) {
5024
- _context35.next = 5;
5121
+ _context36.next = 5;
5025
5122
  break;
5026
5123
  }
5027
- _context35.next = 5;
5028
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
5029
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
5030
- while (1) switch (_context34.prev = _context34.next) {
5124
+ _context36.next = 5;
5125
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
5126
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
5127
+ while (1) switch (_context35.prev = _context35.next) {
5031
5128
  case 0:
5032
- _context34.next = 2;
5129
+ _context35.next = 2;
5033
5130
  return _this31.dbManager.clear(INDEXDB_STORE_NAME);
5034
5131
  case 2:
5035
5132
  case "end":
5036
- return _context34.stop();
5133
+ return _context35.stop();
5037
5134
  }
5038
- }, _callee34);
5135
+ }, _callee35);
5039
5136
  })));
5040
5137
  case 5:
5041
5138
  this.clearOrderSnapshotMarker();
5042
5139
  this.emitOrdersChanged([], 'clear');
5043
5140
  case 7:
5044
5141
  case "end":
5045
- return _context35.stop();
5142
+ return _context36.stop();
5046
5143
  }
5047
- }, _callee35, this);
5144
+ }, _callee36, this);
5048
5145
  }));
5049
5146
  function clear() {
5050
5147
  return _clear.apply(this, arguments);