@pisell/pisellos 2.3.164 → 2.3.166

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/model/strategy/adapter/promotion/evaluator.js +89 -104
  2. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  3. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +28 -4
  4. package/dist/modules/Holder/utils.d.ts +2 -0
  5. package/dist/modules/Holder/utils.js +32 -2
  6. package/dist/modules/OpenData/contactInfo.d.ts +20 -0
  7. package/dist/modules/OpenData/contactInfo.js +70 -0
  8. package/dist/modules/OpenData/index.d.ts +1 -0
  9. package/dist/modules/OpenData/index.js +1 -0
  10. package/dist/modules/OpenData/types.d.ts +9 -0
  11. package/dist/modules/Order/holderRelations.d.ts +14 -0
  12. package/dist/modules/Order/holderRelations.js +154 -0
  13. package/dist/modules/Order/index.d.ts +1 -1
  14. package/dist/modules/Order/index.js +89 -44
  15. package/dist/modules/Order/types.d.ts +19 -1
  16. package/dist/modules/Order/types.js +2 -0
  17. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  18. package/dist/modules/Order/utils/discountProductLineIdentity.js +142 -7
  19. package/dist/modules/Order/utils/orderCollectionIdentity.js +24 -10
  20. package/dist/modules/Order/utils.d.ts +1 -1
  21. package/dist/modules/Order/utils.js +35 -9
  22. package/dist/modules/Rules/index.js +62 -61
  23. package/dist/server/index.js +18 -12
  24. package/dist/server/modules/order/index.d.ts +4 -0
  25. package/dist/server/modules/order/index.js +255 -190
  26. package/dist/server/modules/order/types.d.ts +3 -0
  27. package/dist/server/modules/products/index.js +3 -2
  28. package/dist/shared/receipt/small-ticket.js +17 -6
  29. package/dist/shared/sales/loadSalesOrderSnapshot.js +1 -1
  30. package/dist/solution/BaseSales/index.d.ts +4 -0
  31. package/dist/solution/BaseSales/index.js +1116 -935
  32. package/dist/solution/BaseSales/types.d.ts +2 -1
  33. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  34. package/dist/solution/BaseSales/utils/parseSalesResponse.js +7 -3
  35. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -4
  36. package/dist/solution/BookingTicket/index.d.ts +15 -1
  37. package/dist/solution/BookingTicket/index.js +784 -501
  38. package/dist/solution/UnifiedBookingSales/index.js +1 -1
  39. package/lib/model/strategy/adapter/promotion/evaluator.js +9 -14
  40. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  41. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +17 -1
  42. package/lib/modules/Holder/utils.d.ts +2 -0
  43. package/lib/modules/Holder/utils.js +27 -1
  44. package/lib/modules/OpenData/contactInfo.d.ts +20 -0
  45. package/lib/modules/OpenData/contactInfo.js +56 -0
  46. package/lib/modules/OpenData/index.d.ts +1 -0
  47. package/lib/modules/OpenData/index.js +12 -0
  48. package/lib/modules/OpenData/types.d.ts +9 -0
  49. package/lib/modules/Order/holderRelations.d.ts +14 -0
  50. package/lib/modules/Order/holderRelations.js +98 -0
  51. package/lib/modules/Order/index.d.ts +1 -1
  52. package/lib/modules/Order/index.js +44 -12
  53. package/lib/modules/Order/types.d.ts +19 -1
  54. package/lib/modules/Order/types.js +1 -0
  55. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  56. package/lib/modules/Order/utils/discountProductLineIdentity.js +51 -2
  57. package/lib/modules/Order/utils/orderCollectionIdentity.js +5 -0
  58. package/lib/modules/Order/utils.d.ts +1 -1
  59. package/lib/modules/Order/utils.js +27 -6
  60. package/lib/modules/Rules/index.js +2 -1
  61. package/lib/server/index.js +6 -0
  62. package/lib/server/modules/order/index.d.ts +4 -0
  63. package/lib/server/modules/order/index.js +46 -4
  64. package/lib/server/modules/order/types.d.ts +3 -0
  65. package/lib/server/modules/products/index.js +2 -1
  66. package/lib/shared/receipt/small-ticket.js +15 -7
  67. package/lib/shared/sales/loadSalesOrderSnapshot.js +1 -1
  68. package/lib/solution/BaseSales/index.d.ts +4 -0
  69. package/lib/solution/BaseSales/index.js +68 -2
  70. package/lib/solution/BaseSales/types.d.ts +2 -1
  71. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  72. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -0
  73. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +16 -8
  74. package/lib/solution/BookingTicket/index.d.ts +15 -1
  75. package/lib/solution/BookingTicket/index.js +132 -3
  76. package/lib/solution/UnifiedBookingSales/index.js +1 -1
  77. package/package.json +1 -1
@@ -30,7 +30,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
30
30
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
31
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
32
32
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
33
- import { cloneDeep } from 'lodash-es';
33
+ import { cloneDeep, isEqual } from 'lodash-es';
34
34
  import { isLocalFinalizedPayment, LOCAL_EFTPOS_FINALIZED, LOCAL_EFTPOS_REFRESH_REQUIRED, requiresLocalPaymentRefresh } from "../../../modules/Order/localEftposState";
35
35
  import dayjs from 'dayjs';
36
36
  import { BaseModule } from "../../../modules/BaseModule";
@@ -432,6 +432,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
432
432
  var existingRecord = existing;
433
433
  var incomingRecord = incoming;
434
434
  var uidRemaps = [];
435
+ this.applyHolderRelationsSnapshot(reconciled, existing, incoming);
435
436
  for (var _i = 0, _ORDER_AUTHORITATIVE_ = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i < _ORDER_AUTHORITATIVE_.length; _i++) {
436
437
  var field = _ORDER_AUTHORITATIVE_[_i];
437
438
  if (!Array.isArray(incomingRecord[field])) continue;
@@ -540,7 +541,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
540
541
  continue;
541
542
  }
542
543
 
543
- // 远端商品成员确实发生增删时必须落库,避免内存已更新但 SQLite 仍被回声窗口跳过。
544
+ // 远端商品成员或 Holder 关系确实变化时必须落库,避免被回声窗口跳过。
544
545
  if (forceWriteStorageKeys.has(storageKey)) {
545
546
  toWrite.push(order);
546
547
  continue;
@@ -2190,17 +2191,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2190
2191
  _iterator12.s();
2191
2192
  case 38:
2192
2193
  if ((_step12 = _iterator12.n()).done) {
2193
- _context18.next = 57;
2194
+ _context18.next = 58;
2194
2195
  break;
2195
2196
  }
2196
2197
  _step12$value = _slicedToArray(_step12.value, 2), _storageKey2 = _step12$value[0], _draftOrder = _step12$value[1];
2197
2198
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
2198
2199
  if (!(matchIndex >= 0)) {
2199
- _context18.next = 51;
2200
+ _context18.next = 52;
2200
2201
  break;
2201
2202
  }
2202
2203
  existingOrder = updatedList[matchIndex];
2203
2204
  reconciledDraftOrder = this.preserveExistingBusinessCodeForDraft(existingOrder, _draftOrder);
2205
+ this.applyHolderRelationsSnapshot(reconciledDraftOrder, existingOrder, _draftOrder);
2204
2206
  mergedOrder = this.mergeOrderRecords(existingOrder, reconciledDraftOrder);
2205
2207
  nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
2206
2208
  need_sync: 0,
@@ -2211,46 +2213,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2211
2213
  draftMap.set(_storageKey2, reconciledDraftOrder);
2212
2214
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
2213
2215
  mergeActions[_storageKey2] = 'update';
2214
- return _context18.abrupt("continue", 55);
2215
- case 51:
2216
+ return _context18.abrupt("continue", 56);
2217
+ case 52:
2216
2218
  insertIndex = updatedList.length;
2217
2219
  updatedList.push(_draftOrder);
2218
2220
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
2219
2221
  mergeActions[_storageKey2] = 'insert';
2220
- case 55:
2222
+ case 56:
2221
2223
  _context18.next = 38;
2222
2224
  break;
2223
- case 57:
2224
- _context18.next = 62;
2225
+ case 58:
2226
+ _context18.next = 63;
2225
2227
  break;
2226
- case 59:
2227
- _context18.prev = 59;
2228
+ case 60:
2229
+ _context18.prev = 60;
2228
2230
  _context18.t1 = _context18["catch"](36);
2229
2231
  _iterator12.e(_context18.t1);
2230
- case 62:
2231
- _context18.prev = 62;
2232
+ case 63:
2233
+ _context18.prev = 63;
2232
2234
  _iterator12.f();
2233
- return _context18.finish(62);
2234
- case 65:
2235
+ return _context18.finish(63);
2236
+ case 66:
2235
2237
  patchedOrders = _toConsumableArray(draftMap.values());
2236
2238
  previousList = this.store.list;
2237
2239
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
2238
2240
  this.syncOrdersMap();
2239
- _context18.prev = 69;
2240
- _context18.next = 72;
2241
+ _context18.prev = 70;
2242
+ _context18.next = 73;
2241
2243
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
2242
2244
  throwOnError: true
2243
2245
  });
2244
- case 72:
2245
- _context18.next = 79;
2246
+ case 73:
2247
+ _context18.next = 80;
2246
2248
  break;
2247
- case 74:
2248
- _context18.prev = 74;
2249
- _context18.t2 = _context18["catch"](69);
2249
+ case 75:
2250
+ _context18.prev = 75;
2251
+ _context18.t2 = _context18["catch"](70);
2250
2252
  this.store.list = previousList;
2251
2253
  this.syncOrdersMap();
2252
2254
  throw _context18.t2;
2253
- case 79:
2255
+ case 80:
2254
2256
  this.logInfo('upsertLocalDraftOrders-结束', {
2255
2257
  count: patchedOrders.length,
2256
2258
  storeOrderCountAfter: this.store.list.length
@@ -2259,18 +2261,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2259
2261
  return !_this12.shouldKeepOrderInMemory(order);
2260
2262
  });
2261
2263
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
2262
- _context18.next = 84;
2264
+ _context18.next = 85;
2263
2265
  break;
2264
2266
  }
2265
- _context18.next = 84;
2267
+ _context18.next = 85;
2266
2268
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
2267
2269
  return _this12.shouldKeepOrderInMemory(order);
2268
2270
  }), 'upsertLocalDraftOrders');
2269
- case 84:
2271
+ case 85:
2270
2272
  case "end":
2271
2273
  return _context18.stop();
2272
2274
  }
2273
- }, _callee18, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2275
+ }, _callee18, this, [[6, 21, 24, 27], [36, 60, 63, 66], [70, 75]]);
2274
2276
  }));
2275
2277
  function upsertLocalDraftOrders(_x14) {
2276
2278
  return _upsertLocalDraftOrders.apply(this, arguments);
@@ -2646,7 +2648,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2646
2648
  var hasSingleId = routeInfo.hasSingleId;
2647
2649
  var normalizedBody = _this17.normalizeOrderSyncPayload(msg.body || msg.data);
2648
2650
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
2649
- upsertOrders.set(_this17.getIdKey(normalizedBody.order_id), normalizedBody);
2651
+ var orderKey = _this17.getIdKey(normalizedBody.order_id);
2652
+ var previousBody = upsertOrders.get(orderKey);
2653
+ if (previousBody) _this17.applyHolderRelationsSnapshot(normalizedBody, previousBody, normalizedBody);
2654
+ upsertOrders.set(orderKey, normalizedBody);
2650
2655
  return;
2651
2656
  }
2652
2657
  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));
@@ -2873,7 +2878,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2873
2878
  _iterator17.s();
2874
2879
  case 40:
2875
2880
  if ((_step17 = _iterator17.n()).done) {
2876
- _context23.next = 100;
2881
+ _context23.next = 101;
2877
2882
  break;
2878
2883
  }
2879
2884
  fresh = _step17.value;
@@ -2882,7 +2887,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2882
2887
  storageKey = this.getOrderStorageKey(fresh);
2883
2888
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2884
2889
  if (!(matchIndex >= 0)) {
2885
- _context23.next = 92;
2890
+ _context23.next = 93;
2886
2891
  break;
2887
2892
  }
2888
2893
  existingOrder = updatedList[matchIndex];
@@ -2901,7 +2906,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2901
2906
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2902
2907
  reason: 'protect_pending_sync_order_from_remote_echo'
2903
2908
  });
2904
- return _context23.abrupt("continue", 98);
2909
+ return _context23.abrupt("continue", 99);
2905
2910
  case 52:
2906
2911
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2907
2912
  _context23.next = 55;
@@ -2915,7 +2920,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2915
2920
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2916
2921
  reason: 'protect_draft_order_from_remote_echo'
2917
2922
  });
2918
- return _context23.abrupt("continue", 98);
2923
+ return _context23.abrupt("continue", 99);
2919
2924
  case 55:
2920
2925
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2921
2926
  freshOrderId = fresh.order_id;
@@ -3007,34 +3012,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3007
3012
  mergedStorageKey = this.getOrderStorageKey(mergedOrder);
3008
3013
  if (mergedStorageKey) forceWriteStorageKeys.add(mergedStorageKey);
3009
3014
  }
3015
+ if (nextStorageKey && !isEqual(existingOrder.holder_relations, mergedOrder.holder_relations)) {
3016
+ forceWriteStorageKeys.add(nextStorageKey);
3017
+ }
3010
3018
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
3011
3019
  // 供同批后续 fresh 命中同一槽位,避免重复插入
3012
3020
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
3013
3021
  patchedOrders.push(mergedOrder);
3014
3022
  if (mergeKey) mergeActions[mergeKey] = 'update';
3015
- return _context23.abrupt("continue", 98);
3016
- case 92:
3023
+ return _context23.abrupt("continue", 99);
3024
+ case 93:
3017
3025
  insertIndex = updatedList.length;
3018
3026
  updatedList.push(fresh);
3019
3027
  existingProductsHaveStableIdentity.push(fresh.order_id !== undefined && fresh.order_id !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(fresh.order_id)) !== false);
3020
3028
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
3021
3029
  patchedOrders.push(fresh);
3022
3030
  if (mergeKey) mergeActions[mergeKey] = 'insert';
3023
- case 98:
3031
+ case 99:
3024
3032
  _context23.next = 40;
3025
3033
  break;
3026
- case 100:
3027
- _context23.next = 105;
3034
+ case 101:
3035
+ _context23.next = 106;
3028
3036
  break;
3029
- case 102:
3030
- _context23.prev = 102;
3037
+ case 103:
3038
+ _context23.prev = 103;
3031
3039
  _context23.t2 = _context23["catch"](38);
3032
3040
  _iterator17.e(_context23.t2);
3033
- case 105:
3034
- _context23.prev = 105;
3041
+ case 106:
3042
+ _context23.prev = 106;
3035
3043
  _iterator17.f();
3036
- return _context23.finish(105);
3037
- case 108:
3044
+ return _context23.finish(106);
3045
+ case 109:
3038
3046
  insertCount = Object.values(mergeActions).filter(function (v) {
3039
3047
  return v === 'insert';
3040
3048
  }).length;
@@ -3050,27 +3058,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3050
3058
  // 仅在自检开关开启时做一次兜底校验。
3051
3059
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
3052
3060
  this.syncOrdersMap();
3053
- _context23.next = 115;
3061
+ _context23.next = 116;
3054
3062
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
3055
3063
  storageKeyMigrations: storageKeyMigrations
3056
3064
  }, forceWriteStorageKeys);
3057
- case 115:
3065
+ case 116:
3058
3066
  this.logInfo('mergeOrdersToStore-结束', {
3059
3067
  uniqueFreshCount: uniqueFreshCount,
3060
3068
  storeOrderCountAfter: this.store.list.length,
3061
3069
  insertCount: insertCount,
3062
3070
  updateCount: updateCount
3063
3071
  });
3064
- _context23.next = 118;
3072
+ _context23.next = 119;
3065
3073
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
3066
- case 118:
3067
- _context23.next = 120;
3074
+ case 119:
3075
+ _context23.next = 121;
3068
3076
  return this.emitOrdersChanged(patchedOrders, source);
3069
- case 120:
3077
+ case 121:
3070
3078
  case "end":
3071
3079
  return _context23.stop();
3072
3080
  }
3073
- }, _callee23, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
3081
+ }, _callee23, this, [[6, 20, 23, 26], [38, 103, 106, 109], [64, 76, 79, 82]]);
3074
3082
  }));
3075
3083
  function mergeOrdersToStore(_x16, _x17) {
3076
3084
  return _mergeOrdersToStore.apply(this, arguments);
@@ -3499,6 +3507,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3499
3507
  });
3500
3508
  });
3501
3509
  }
3510
+
3511
+ /** 关系数组是完整快照,不能拼接或按商品子项生成 UID;扩展字段整体保留。 */
3512
+ }, {
3513
+ key: "applyHolderRelationsSnapshot",
3514
+ value: function applyHolderRelationsSnapshot(target, existing, incoming) {
3515
+ if (Array.isArray(incoming.holder_relations)) {
3516
+ target.holder_relations = cloneDeep(incoming.holder_relations);
3517
+ } else if (Array.isArray(existing.holder_relations)) {
3518
+ target.holder_relations = cloneDeep(existing.holder_relations);
3519
+ } else {
3520
+ delete target.holder_relations;
3521
+ }
3522
+ }
3523
+
3524
+ /** 全量拉取缺少关系字段时,仍保留同一订单已有的关系快照。 */
3525
+ }, {
3526
+ key: "preserveOmittedHolderRelations",
3527
+ value: function preserveOmittedHolderRelations(incomingOrders, existingOrders) {
3528
+ var _this22 = this;
3529
+ var existingByIdentity = new Map();
3530
+ var _iterator29 = _createForOfIteratorHelper(existingOrders),
3531
+ _step29;
3532
+ try {
3533
+ for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3534
+ var order = _step29.value;
3535
+ if (!Array.isArray(order.holder_relations)) continue;
3536
+ var _iterator30 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3537
+ _step30;
3538
+ try {
3539
+ for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
3540
+ var key = _step30.value;
3541
+ existingByIdentity.set(key, order);
3542
+ }
3543
+ } catch (err) {
3544
+ _iterator30.e(err);
3545
+ } finally {
3546
+ _iterator30.f();
3547
+ }
3548
+ }
3549
+ } catch (err) {
3550
+ _iterator29.e(err);
3551
+ } finally {
3552
+ _iterator29.f();
3553
+ }
3554
+ return incomingOrders.map(function (order) {
3555
+ if (Array.isArray(order.holder_relations)) return order;
3556
+ var existingOrder = _this22.getOrderIdentityMatchKeys(order).map(function (key) {
3557
+ return existingByIdentity.get(key);
3558
+ }).find(Boolean);
3559
+ if (!existingOrder) return order;
3560
+ var nextOrder = _objectSpread({}, order);
3561
+ _this22.applyHolderRelationsSnapshot(nextOrder, existingOrder, order);
3562
+ return nextOrder;
3563
+ });
3564
+ }
3502
3565
  }, {
3503
3566
  key: "mergeOrderRecords",
3504
3567
  value: function mergeOrderRecords(existing, incoming) {
@@ -3539,6 +3602,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3539
3602
  if (Object.prototype.hasOwnProperty.call(incomingRecord, 'order_meta_list')) {
3540
3603
  mergedRecord.order_meta_list = cloneDeep(incomingRecord.order_meta_list);
3541
3604
  }
3605
+ this.applyHolderRelationsSnapshot(merged, existing, incoming);
3542
3606
 
3543
3607
  // 子项数组遵循完整快照语义:incoming 自有且为数组(包括 [])时权威替换;
3544
3608
  // 字段缺席或不是数组时视为稀疏 patch,继续保留 existing。
@@ -3579,30 +3643,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3579
3643
  key: "summarizeDuplicateOrders",
3580
3644
  value: function summarizeDuplicateOrders(orders) {
3581
3645
  var groups = new Map();
3582
- var _iterator29 = _createForOfIteratorHelper(orders),
3583
- _step29;
3646
+ var _iterator31 = _createForOfIteratorHelper(orders),
3647
+ _step31;
3584
3648
  try {
3585
- for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3586
- var order = _step29.value;
3587
- var _iterator30 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3588
- _step30;
3649
+ for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) {
3650
+ var order = _step31.value;
3651
+ var _iterator32 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3652
+ _step32;
3589
3653
  try {
3590
- for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
3591
- var key = _step30.value;
3654
+ for (_iterator32.s(); !(_step32 = _iterator32.n()).done;) {
3655
+ var key = _step32.value;
3592
3656
  var group = groups.get(key) || [];
3593
3657
  group.push(order);
3594
3658
  groups.set(key, group);
3595
3659
  }
3596
3660
  } catch (err) {
3597
- _iterator30.e(err);
3661
+ _iterator32.e(err);
3598
3662
  } finally {
3599
- _iterator30.f();
3663
+ _iterator32.f();
3600
3664
  }
3601
3665
  }
3602
3666
  } catch (err) {
3603
- _iterator29.e(err);
3667
+ _iterator31.e(err);
3604
3668
  } finally {
3605
- _iterator29.f();
3669
+ _iterator31.f();
3606
3670
  }
3607
3671
  return _toConsumableArray(groups.entries()).filter(function (_ref9) {
3608
3672
  var _ref10 = _slicedToArray(_ref9, 2),
@@ -3645,11 +3709,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3645
3709
  value: function compactOrderListByIdentity(orders, source) {
3646
3710
  var list = [];
3647
3711
  var removedCount = 0;
3648
- var _iterator31 = _createForOfIteratorHelper(orders),
3649
- _step31;
3712
+ var _iterator33 = _createForOfIteratorHelper(orders),
3713
+ _step33;
3650
3714
  try {
3651
- for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) {
3652
- var order = _step31.value;
3715
+ for (_iterator33.s(); !(_step33 = _iterator33.n()).done;) {
3716
+ var order = _step33.value;
3653
3717
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
3654
3718
  var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
3655
3719
  if (matchIndex < 0) {
@@ -3660,9 +3724,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3660
3724
  removedCount += 1;
3661
3725
  }
3662
3726
  } catch (err) {
3663
- _iterator31.e(err);
3727
+ _iterator33.e(err);
3664
3728
  } finally {
3665
- _iterator31.f();
3729
+ _iterator33.f();
3666
3730
  }
3667
3731
  if (removedCount > 0) {
3668
3732
  this.logWarning('订单列表重复项已压缩', {
@@ -3795,7 +3859,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3795
3859
  key: "loadOrdersFromSQLite",
3796
3860
  value: function () {
3797
3861
  var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
3798
- var _this22 = this;
3862
+ var _this23 = this;
3799
3863
  var options,
3800
3864
  _options$onTiming,
3801
3865
  loadStartedAt,
@@ -3826,7 +3890,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3826
3890
  sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3827
3891
  normalizeStartedAt = performance.now();
3828
3892
  normalizedOrders = (orders || []).map(function (order) {
3829
- return _this22.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3893
+ return _this23.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3830
3894
  });
3831
3895
  sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3832
3896
  (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
@@ -3899,15 +3963,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3899
3963
  }, {
3900
3964
  key: "mergeRemoteSnapshotWithPendingOrders",
3901
3965
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3902
- var _this23 = this;
3966
+ var _this24 = this;
3903
3967
  var merged = remoteOrders.map(function (order) {
3904
- return _this23.normalizeRemoteSyncedOrder(order);
3968
+ return _this24.normalizeRemoteSyncedOrder(order);
3905
3969
  });
3906
- var _iterator32 = _createForOfIteratorHelper(existingOrders),
3907
- _step32;
3970
+ var _iterator34 = _createForOfIteratorHelper(existingOrders),
3971
+ _step34;
3908
3972
  try {
3909
- for (_iterator32.s(); !(_step32 = _iterator32.n()).done;) {
3910
- var rawOrder = _step32.value;
3973
+ for (_iterator34.s(); !(_step34 = _iterator34.n()).done;) {
3974
+ var rawOrder = _step34.value;
3911
3975
  var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
3912
3976
  if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
3913
3977
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
@@ -3923,9 +3987,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3923
3987
  merged.push(order);
3924
3988
  }
3925
3989
  } catch (err) {
3926
- _iterator32.e(err);
3990
+ _iterator34.e(err);
3927
3991
  } finally {
3928
- _iterator32.f();
3992
+ _iterator34.f();
3929
3993
  }
3930
3994
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
3931
3995
  }
@@ -3975,7 +4039,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3975
4039
  key: "patchOrdersInSQLite",
3976
4040
  value: (function () {
3977
4041
  var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orders, source) {
3978
- var _this24 = this;
4042
+ var _this25 = this;
3979
4043
  var mergeActions,
3980
4044
  options,
3981
4045
  forceWriteStorageKeys,
@@ -3987,8 +4051,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3987
4051
  compactedToWrite,
3988
4052
  writtenStorageKeys,
3989
4053
  storageKeyMigrations,
3990
- _iterator33,
3991
- _step33,
4054
+ _iterator35,
4055
+ _step35,
3992
4056
  migration,
3993
4057
  _args27 = arguments;
3994
4058
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
@@ -4019,13 +4083,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4019
4083
  return migration.to;
4020
4084
  }));
4021
4085
  ordersSnapshot = cloneDeep(orders).map(function (order) {
4022
- return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
4086
+ return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
4023
4087
  }).map(function (order) {
4024
- var storageKey = _this24.getOrderStorageKey(order);
4088
+ var storageKey = _this25.getOrderStorageKey(order);
4025
4089
  if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
4026
4090
  return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
4027
4091
  }).filter(function (order) {
4028
- return _this24.getOrderStorageKey(order);
4092
+ return _this25.getOrderStorageKey(order);
4029
4093
  });
4030
4094
  if (!(ordersSnapshot.length === 0)) {
4031
4095
  _context27.next = 13;
@@ -4048,18 +4112,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4048
4112
  return _context27.abrupt("return");
4049
4113
  case 19:
4050
4114
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
4051
- return _this24.getOrderStorageKey(order);
4115
+ return _this25.getOrderStorageKey(order);
4052
4116
  }).filter(Boolean));
4053
4117
  storageKeyMigrations = new Map();
4054
- _iterator33 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
4118
+ _iterator35 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
4055
4119
  _context27.prev = 22;
4056
- _iterator33.s();
4120
+ _iterator35.s();
4057
4121
  case 24:
4058
- if ((_step33 = _iterator33.n()).done) {
4122
+ if ((_step35 = _iterator35.n()).done) {
4059
4123
  _context27.next = 33;
4060
4124
  break;
4061
4125
  }
4062
- migration = _step33.value;
4126
+ migration = _step35.value;
4063
4127
  if (writtenStorageKeys.has(migration.to)) {
4064
4128
  _context27.next = 28;
4065
4129
  break;
@@ -4082,63 +4146,63 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4082
4146
  case 35:
4083
4147
  _context27.prev = 35;
4084
4148
  _context27.t0 = _context27["catch"](22);
4085
- _iterator33.e(_context27.t0);
4149
+ _iterator35.e(_context27.t0);
4086
4150
  case 38:
4087
4151
  _context27.prev = 38;
4088
- _iterator33.f();
4152
+ _iterator35.f();
4089
4153
  return _context27.finish(38);
4090
4154
  case 41:
4091
4155
  _context27.prev = 41;
4092
4156
  _context27.next = 44;
4093
4157
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4094
- var writeMethod, _iterator34, _step34, order, _iterator35, _step35, migration, _iterator36, _step36, _orderRecord$ORDER_ST, _order, orderRecord;
4158
+ var writeMethod, _iterator36, _step36, order, _iterator37, _step37, migration, _iterator38, _step38, _orderRecord$ORDER_ST, _order, orderRecord;
4095
4159
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4096
4160
  while (1) switch (_context26.prev = _context26.next) {
4097
4161
  case 0:
4098
4162
  writeMethod = 'none';
4099
- _this24.logInfo('patchOrdersInSQLite-开始', {
4163
+ _this25.logInfo('patchOrdersInSQLite-开始', {
4100
4164
  source: source,
4101
4165
  count: compactedToWrite.length,
4102
4166
  dedupedCount: skipped.length
4103
4167
  });
4104
- if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4168
+ if (!(typeof _this25.dbManager.bulkUpdate === 'function')) {
4105
4169
  _context26.next = 8;
4106
4170
  break;
4107
4171
  }
4108
4172
  writeMethod = 'bulkUpdate';
4109
4173
  _context26.next = 6;
4110
- return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
4174
+ return _this25.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
4111
4175
  case 6:
4112
4176
  _context26.next = 37;
4113
4177
  break;
4114
4178
  case 8:
4115
- if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4179
+ if (!(typeof _this25.dbManager.bulkAdd === 'function')) {
4116
4180
  _context26.next = 14;
4117
4181
  break;
4118
4182
  }
4119
4183
  writeMethod = 'bulkAdd';
4120
4184
  _context26.next = 12;
4121
- return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
4185
+ return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
4122
4186
  case 12:
4123
4187
  _context26.next = 37;
4124
4188
  break;
4125
4189
  case 14:
4126
- if (!(typeof _this24.dbManager.update === 'function')) {
4190
+ if (!(typeof _this25.dbManager.update === 'function')) {
4127
4191
  _context26.next = 35;
4128
4192
  break;
4129
4193
  }
4130
4194
  writeMethod = 'update';
4131
- _iterator34 = _createForOfIteratorHelper(compactedToWrite);
4195
+ _iterator36 = _createForOfIteratorHelper(compactedToWrite);
4132
4196
  _context26.prev = 17;
4133
- _iterator34.s();
4197
+ _iterator36.s();
4134
4198
  case 19:
4135
- if ((_step34 = _iterator34.n()).done) {
4199
+ if ((_step36 = _iterator36.n()).done) {
4136
4200
  _context26.next = 25;
4137
4201
  break;
4138
4202
  }
4139
- order = _step34.value;
4203
+ order = _step36.value;
4140
4204
  _context26.next = 23;
4141
- return _this24.dbManager.update(INDEXDB_STORE_NAME, order);
4205
+ return _this25.dbManager.update(INDEXDB_STORE_NAME, order);
4142
4206
  case 23:
4143
4207
  _context26.next = 19;
4144
4208
  break;
@@ -4148,10 +4212,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4148
4212
  case 27:
4149
4213
  _context26.prev = 27;
4150
4214
  _context26.t0 = _context26["catch"](17);
4151
- _iterator34.e(_context26.t0);
4215
+ _iterator36.e(_context26.t0);
4152
4216
  case 30:
4153
4217
  _context26.prev = 30;
4154
- _iterator34.f();
4218
+ _iterator36.f();
4155
4219
  return _context26.finish(30);
4156
4220
  case 33:
4157
4221
  _context26.next = 37;
@@ -4163,35 +4227,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4163
4227
  }
4164
4228
  throw new Error('订单 SQLite 数据库不支持写入');
4165
4229
  case 37:
4166
- _this24.recordRecentSqliteWrite(source, compactedToWrite);
4230
+ _this25.recordRecentSqliteWrite(source, compactedToWrite);
4167
4231
  if (!(writeMethod !== 'none')) {
4168
4232
  _context26.next = 84;
4169
4233
  break;
4170
4234
  }
4171
- _iterator35 = _createForOfIteratorHelper(storageKeyMigrations.values());
4235
+ _iterator37 = _createForOfIteratorHelper(storageKeyMigrations.values());
4172
4236
  _context26.prev = 40;
4173
- _iterator35.s();
4237
+ _iterator37.s();
4174
4238
  case 42:
4175
- if ((_step35 = _iterator35.n()).done) {
4239
+ if ((_step37 = _iterator37.n()).done) {
4176
4240
  _context26.next = 76;
4177
4241
  break;
4178
4242
  }
4179
- migration = _step35.value;
4243
+ migration = _step37.value;
4180
4244
  _context26.prev = 44;
4181
4245
  _context26.next = 47;
4182
- return _this24.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4246
+ return _this25.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4183
4247
  case 47:
4184
- _this24.recentSqliteWriteByStorageKey.delete(migration.from);
4185
- _iterator36 = _createForOfIteratorHelper(orders);
4248
+ _this25.recentSqliteWriteByStorageKey.delete(migration.from);
4249
+ _iterator38 = _createForOfIteratorHelper(orders);
4186
4250
  _context26.prev = 49;
4187
- _iterator36.s();
4251
+ _iterator38.s();
4188
4252
  case 51:
4189
- if ((_step36 = _iterator36.n()).done) {
4253
+ if ((_step38 = _iterator38.n()).done) {
4190
4254
  _context26.next = 61;
4191
4255
  break;
4192
4256
  }
4193
- _order = _step36.value;
4194
- if (!(_this24.getOrderStorageKey(_order) !== migration.to)) {
4257
+ _order = _step38.value;
4258
+ if (!(_this25.getOrderStorageKey(_order) !== migration.to)) {
4195
4259
  _context26.next = 55;
4196
4260
  break;
4197
4261
  }
@@ -4214,10 +4278,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4214
4278
  case 63:
4215
4279
  _context26.prev = 63;
4216
4280
  _context26.t1 = _context26["catch"](49);
4217
- _iterator36.e(_context26.t1);
4281
+ _iterator38.e(_context26.t1);
4218
4282
  case 66:
4219
4283
  _context26.prev = 66;
4220
- _iterator36.f();
4284
+ _iterator38.f();
4221
4285
  return _context26.finish(66);
4222
4286
  case 69:
4223
4287
  _context26.next = 74;
@@ -4225,7 +4289,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4225
4289
  case 71:
4226
4290
  _context26.prev = 71;
4227
4291
  _context26.t2 = _context26["catch"](44);
4228
- _this24.logError('删除订单旧 SQLite storage key 失败', {
4292
+ _this25.logError('删除订单旧 SQLite storage key 失败', {
4229
4293
  source: source,
4230
4294
  order_id: migration.orderId,
4231
4295
  oldStorageKey: migration.from,
@@ -4241,13 +4305,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4241
4305
  case 78:
4242
4306
  _context26.prev = 78;
4243
4307
  _context26.t3 = _context26["catch"](40);
4244
- _iterator35.e(_context26.t3);
4308
+ _iterator37.e(_context26.t3);
4245
4309
  case 81:
4246
4310
  _context26.prev = 81;
4247
- _iterator35.f();
4311
+ _iterator37.f();
4248
4312
  return _context26.finish(81);
4249
4313
  case 84:
4250
- _this24.logInfo('patchOrdersInSQLite-完成', {
4314
+ _this25.logInfo('patchOrdersInSQLite-完成', {
4251
4315
  source: source,
4252
4316
  count: compactedToWrite.length,
4253
4317
  writeMethod: writeMethod,
@@ -4296,7 +4360,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4296
4360
  key: "updateOrderInSQLite",
4297
4361
  value: (function () {
4298
4362
  var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order, source) {
4299
- var _this25 = this;
4363
+ var _this26 = this;
4300
4364
  var options,
4301
4365
  orderSnapshot,
4302
4366
  _orderSnapshot$order_3,
@@ -4339,40 +4403,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4339
4403
  while (1) switch (_context28.prev = _context28.next) {
4340
4404
  case 0:
4341
4405
  writeMethod = 'none';
4342
- _this25.logInfo('updateOrderInSQLite-开始', {
4406
+ _this26.logInfo('updateOrderInSQLite-开始', {
4343
4407
  source: source,
4344
4408
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
4345
- storageKey: _this25.getOrderStorageKey(orderSnapshot)
4409
+ storageKey: _this26.getOrderStorageKey(orderSnapshot)
4346
4410
  });
4347
- if (!(typeof _this25.dbManager.update === 'function')) {
4411
+ if (!(typeof _this26.dbManager.update === 'function')) {
4348
4412
  _context28.next = 8;
4349
4413
  break;
4350
4414
  }
4351
4415
  writeMethod = 'update';
4352
4416
  _context28.next = 6;
4353
- return _this25.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4417
+ return _this26.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4354
4418
  case 6:
4355
4419
  _context28.next = 22;
4356
4420
  break;
4357
4421
  case 8:
4358
- if (!(typeof _this25.dbManager.bulkUpdate === 'function')) {
4422
+ if (!(typeof _this26.dbManager.bulkUpdate === 'function')) {
4359
4423
  _context28.next = 14;
4360
4424
  break;
4361
4425
  }
4362
4426
  writeMethod = 'bulkUpdate';
4363
4427
  _context28.next = 12;
4364
- return _this25.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4428
+ return _this26.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4365
4429
  case 12:
4366
4430
  _context28.next = 22;
4367
4431
  break;
4368
4432
  case 14:
4369
- if (!(typeof _this25.dbManager.bulkAdd === 'function')) {
4433
+ if (!(typeof _this26.dbManager.bulkAdd === 'function')) {
4370
4434
  _context28.next = 20;
4371
4435
  break;
4372
4436
  }
4373
4437
  writeMethod = 'bulkAdd';
4374
4438
  _context28.next = 18;
4375
- return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4439
+ return _this26.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4376
4440
  case 18:
4377
4441
  _context28.next = 22;
4378
4442
  break;
@@ -4383,8 +4447,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4383
4447
  }
4384
4448
  throw new Error('订单 SQLite 数据库不支持写入');
4385
4449
  case 22:
4386
- _this25.recordRecentSqliteWrite(source, [orderSnapshot]);
4387
- _this25.logInfo('updateOrderInSQLite-完成', {
4450
+ _this26.recordRecentSqliteWrite(source, [orderSnapshot]);
4451
+ _this26.logInfo('updateOrderInSQLite-完成', {
4388
4452
  source: source,
4389
4453
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
4390
4454
  writeMethod: writeMethod
@@ -4433,7 +4497,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4433
4497
  key: "replaceOrdersSnapshotInSQLite",
4434
4498
  value: (function () {
4435
4499
  var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderList, source) {
4436
- var _this26 = this;
4500
+ var _this27 = this;
4437
4501
  var protectedOrdersBeforeRemoteFetch,
4438
4502
  remoteSnapshot,
4439
4503
  mergedSnapshot,
@@ -4448,32 +4512,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4448
4512
  break;
4449
4513
  }
4450
4514
  return _context31.abrupt("return", {
4451
- orders: this.compactOrderListByIdentity(orderList.map(function (order) {
4452
- return _this26.normalizeRemoteSyncedOrder(order);
4515
+ orders: this.compactOrderListByIdentity(this.preserveOmittedHolderRelations(orderList, this.store.list).map(function (order) {
4516
+ return _this27.normalizeRemoteSyncedOrder(order);
4453
4517
  }), "".concat(source, ".snapshotNoDb")).list,
4454
4518
  persisted: false
4455
4519
  });
4456
4520
  case 3:
4457
4521
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
4458
- return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4522
+ return _this27.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4459
4523
  });
4460
4524
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
4461
- return _this26.normalizeRemoteSyncedOrder(order);
4525
+ return _this27.normalizeRemoteSyncedOrder(order);
4462
4526
  }), "".concat(source, ".remoteSnapshot")).list;
4463
4527
  persisted = false;
4464
4528
  _context31.prev = 6;
4465
4529
  _context31.next = 9;
4466
4530
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4467
- var existingOrders, protectedLocalOrders, _iterator37, _step37, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4531
+ var existingOrders, remoteSnapshotWithHolderRelations, protectedLocalOrders, _iterator39, _step39, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4468
4532
  return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4469
4533
  while (1) switch (_context30.prev = _context30.next) {
4470
4534
  case 0:
4471
- if (!(typeof _this26.dbManager.getAll === 'function')) {
4535
+ if (!(typeof _this27.dbManager.getAll === 'function')) {
4472
4536
  _context30.next = 6;
4473
4537
  break;
4474
4538
  }
4475
4539
  _context30.next = 3;
4476
- return _this26.dbManager.getAll(INDEXDB_STORE_NAME);
4540
+ return _this27.dbManager.getAll(INDEXDB_STORE_NAME);
4477
4541
  case 3:
4478
4542
  _context30.t0 = _context30.sent;
4479
4543
  _context30.next = 7;
@@ -4482,25 +4546,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4482
4546
  _context30.t0 = [];
4483
4547
  case 7:
4484
4548
  existingOrders = _context30.t0;
4549
+ remoteSnapshotWithHolderRelations = _this27.preserveOmittedHolderRelations(remoteSnapshot, [].concat(_toConsumableArray(protectedOrdersBeforeRemoteFetch), _toConsumableArray(existingOrders || [])));
4485
4550
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4486
- return _this26.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4551
+ return _this27.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4487
4552
  }).filter(function (order) {
4488
- return _this26.shouldProtectLocalOrderFromRemoteSnapshot(order);
4553
+ return _this27.shouldProtectLocalOrderFromRemoteSnapshot(order);
4489
4554
  });
4490
- _iterator37 = _createForOfIteratorHelper(existingOrders || []);
4491
- _context30.prev = 10;
4492
- _iterator37.s();
4493
- case 12:
4494
- if ((_step37 = _iterator37.n()).done) {
4495
- _context30.next = 23;
4555
+ _iterator39 = _createForOfIteratorHelper(existingOrders || []);
4556
+ _context30.prev = 11;
4557
+ _iterator39.s();
4558
+ case 13:
4559
+ if ((_step39 = _iterator39.n()).done) {
4560
+ _context30.next = 24;
4496
4561
  break;
4497
4562
  }
4498
- rawCurrentOrder = _step37.value;
4499
- currentOrder = _this26.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4500
- protectedIndex = _this26.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4501
- currentNeedsProtection = _this26.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4563
+ rawCurrentOrder = _step39.value;
4564
+ currentOrder = _this27.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4565
+ protectedIndex = _this27.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4566
+ currentNeedsProtection = _this27.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4502
4567
  if (!(protectedIndex >= 0)) {
4503
- _context30.next = 20;
4568
+ _context30.next = 21;
4504
4569
  break;
4505
4570
  }
4506
4571
  if (currentNeedsProtection) {
@@ -4508,27 +4573,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4508
4573
  } else {
4509
4574
  protectedLocalOrders.splice(protectedIndex, 1);
4510
4575
  }
4511
- return _context30.abrupt("continue", 21);
4512
- case 20:
4513
- if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4576
+ return _context30.abrupt("continue", 22);
4514
4577
  case 21:
4515
- _context30.next = 12;
4578
+ if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4579
+ case 22:
4580
+ _context30.next = 13;
4516
4581
  break;
4517
- case 23:
4518
- _context30.next = 28;
4582
+ case 24:
4583
+ _context30.next = 29;
4519
4584
  break;
4520
- case 25:
4521
- _context30.prev = 25;
4522
- _context30.t1 = _context30["catch"](10);
4523
- _iterator37.e(_context30.t1);
4524
- case 28:
4525
- _context30.prev = 28;
4526
- _iterator37.f();
4527
- return _context30.finish(28);
4528
- case 31:
4529
- orderListSnapshot = _this26.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4530
- mergedSnapshot = _this26.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4531
- _this26.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4585
+ case 26:
4586
+ _context30.prev = 26;
4587
+ _context30.t1 = _context30["catch"](11);
4588
+ _iterator39.e(_context30.t1);
4589
+ case 29:
4590
+ _context30.prev = 29;
4591
+ _iterator39.f();
4592
+ return _context30.finish(29);
4593
+ case 32:
4594
+ orderListSnapshot = _this27.mergeRemoteSnapshotWithPendingOrders(remoteSnapshotWithHolderRelations, protectedLocalOrders);
4595
+ mergedSnapshot = _this27.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4596
+ _this27.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4532
4597
  source: source,
4533
4598
  count: mergedSnapshot.length,
4534
4599
  remoteCount: remoteSnapshot.length,
@@ -4536,10 +4601,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4536
4601
  protectedLocalOrderCount: protectedLocalOrders.length,
4537
4602
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
4538
4603
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
4539
- return count + _this26.getIdentifiedPendingPayments(order).length;
4604
+ return count + _this27.getIdentifiedPendingPayments(order).length;
4540
4605
  }, 0),
4541
4606
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
4542
- return _this26.getIdentifiedPendingPayments(order).map(function (payment) {
4607
+ return _this27.getIdentifiedPendingPayments(order).map(function (payment) {
4543
4608
  var _order$order_id5, _external_sale_number5;
4544
4609
  return {
4545
4610
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -4549,31 +4614,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4549
4614
  });
4550
4615
  })
4551
4616
  });
4552
- _context30.next = 36;
4553
- return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4554
- case 36:
4555
- _this26.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4617
+ _context30.next = 37;
4618
+ return _this27.dbManager.clear(INDEXDB_STORE_NAME);
4619
+ case 37:
4620
+ _this27.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4556
4621
  count: mergedSnapshot.length
4557
4622
  });
4558
4623
  if (!(mergedSnapshot.length === 0)) {
4559
- _context30.next = 39;
4624
+ _context30.next = 40;
4560
4625
  break;
4561
4626
  }
4562
4627
  return _context30.abrupt("return");
4563
- case 39:
4564
- _context30.next = 41;
4565
- return _this26.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4566
- case 41:
4567
- _this26.recordRecentSqliteWrite(source, mergedSnapshot);
4568
- _this26.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4628
+ case 40:
4629
+ _context30.next = 42;
4630
+ return _this27.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4631
+ case 42:
4632
+ _this27.recordRecentSqliteWrite(source, mergedSnapshot);
4633
+ _this27.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4569
4634
  source: source,
4570
4635
  count: mergedSnapshot.length
4571
4636
  });
4572
- case 43:
4637
+ case 44:
4573
4638
  case "end":
4574
4639
  return _context30.stop();
4575
4640
  }
4576
- }, _callee30, null, [[10, 25, 28, 31]]);
4641
+ }, _callee30, null, [[11, 26, 29, 32]]);
4577
4642
  })));
4578
4643
  case 9:
4579
4644
  persisted = true;
@@ -4613,7 +4678,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4613
4678
  key: "clear",
4614
4679
  value: (function () {
4615
4680
  var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4616
- var _this27 = this;
4681
+ var _this28 = this;
4617
4682
  return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4618
4683
  while (1) switch (_context33.prev = _context33.next) {
4619
4684
  case 0:
@@ -4629,7 +4694,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4629
4694
  while (1) switch (_context32.prev = _context32.next) {
4630
4695
  case 0:
4631
4696
  _context32.next = 2;
4632
- return _this27.dbManager.clear(INDEXDB_STORE_NAME);
4697
+ return _this28.dbManager.clear(INDEXDB_STORE_NAME);
4633
4698
  case 2:
4634
4699
  case "end":
4635
4700
  return _context32.stop();