@pisell/pisellos 2.3.46 → 2.3.47

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.
@@ -7,11 +7,11 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
7
7
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
12
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
11
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
15
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
16
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
17
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -135,15 +135,77 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
135
135
  return _emitOrdersChanged.apply(this, arguments);
136
136
  }
137
137
  return emitOrdersChanged;
138
+ }()
139
+ /**
140
+ * 广播远端商品成员增删。监听器异常必须与订单落库和原有订单广播隔离。
141
+ */
142
+ )
143
+ }, {
144
+ key: "emitRemoteProductMembershipChanges",
145
+ value: (function () {
146
+ var _emitRemoteProductMembershipChanges = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(changes) {
147
+ var _iterator, _step, payload;
148
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
149
+ while (1) switch (_context2.prev = _context2.next) {
150
+ case 0:
151
+ _iterator = _createForOfIteratorHelper(changes);
152
+ _context2.prev = 1;
153
+ _iterator.s();
154
+ case 3:
155
+ if ((_step = _iterator.n()).done) {
156
+ _context2.next = 15;
157
+ break;
158
+ }
159
+ payload = _step.value;
160
+ _context2.prev = 5;
161
+ _context2.next = 8;
162
+ return this.core.effects.emit(OrderHooks.onRemoteProductMembershipChanged, payload);
163
+ case 8:
164
+ _context2.next = 13;
165
+ break;
166
+ case 10:
167
+ _context2.prev = 10;
168
+ _context2.t0 = _context2["catch"](5);
169
+ this.logError('广播远端订单商品成员变更失败', {
170
+ order_id: payload.order_id,
171
+ source: payload.source,
172
+ added_product_count: payload.added_product_keys.length,
173
+ removed_product_count: payload.removed_product_keys.length,
174
+ error: _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0)
175
+ });
176
+ case 13:
177
+ _context2.next = 3;
178
+ break;
179
+ case 15:
180
+ _context2.next = 20;
181
+ break;
182
+ case 17:
183
+ _context2.prev = 17;
184
+ _context2.t1 = _context2["catch"](1);
185
+ _iterator.e(_context2.t1);
186
+ case 20:
187
+ _context2.prev = 20;
188
+ _iterator.f();
189
+ return _context2.finish(20);
190
+ case 23:
191
+ case "end":
192
+ return _context2.stop();
193
+ }
194
+ }, _callee2, this, [[1, 17, 20, 23], [5, 10]]);
195
+ }));
196
+ function emitRemoteProductMembershipChanges(_x) {
197
+ return _emitRemoteProductMembershipChanges.apply(this, arguments);
198
+ }
199
+ return emitRemoteProductMembershipChanges;
138
200
  }())
139
201
  }, {
140
202
  key: "initialize",
141
203
  value: function () {
142
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
204
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(core, options) {
143
205
  var _options$initialState;
144
206
  var appPlugin, app;
145
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
146
- while (1) switch (_context2.prev = _context2.next) {
207
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
208
+ while (1) switch (_context3.prev = _context3.next) {
147
209
  case 0:
148
210
  this.core = core;
149
211
  this.store = options === null || options === void 0 ? void 0 : options.store;
@@ -173,11 +235,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
173
235
  });
174
236
  case 10:
175
237
  case "end":
176
- return _context2.stop();
238
+ return _context3.stop();
177
239
  }
178
- }, _callee2, this);
240
+ }, _callee3, this);
179
241
  }));
180
- function initialize(_x, _x2) {
242
+ function initialize(_x2, _x3) {
181
243
  return _initialize.apply(this, arguments);
182
244
  }
183
245
  return initialize;
@@ -330,11 +392,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
330
392
  var mergedItem = mergeOrderCollectionItems(kind, existingItem, incomingItem);
331
393
  var mergedUid = getOrderCollectionUid(kind, mergedItem);
332
394
  if (mergedUid) {
333
- var _iterator = _createForOfIteratorHelper(new Set([getOrderCollectionReferenceUid(kind, existingItem), getOrderCollectionReferenceUid(kind, incomingItem)])),
334
- _step;
395
+ var _iterator2 = _createForOfIteratorHelper(new Set([getOrderCollectionReferenceUid(kind, existingItem), getOrderCollectionReferenceUid(kind, incomingItem)])),
396
+ _step2;
335
397
  try {
336
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
337
- var from = _step.value;
398
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
399
+ var from = _step2.value;
338
400
  if (!from || from === mergedUid) continue;
339
401
  uidRemaps.push({
340
402
  kind: kind,
@@ -344,9 +406,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
344
406
  });
345
407
  }
346
408
  } catch (err) {
347
- _iterator.e(err);
409
+ _iterator2.e(err);
348
410
  } finally {
349
- _iterator.f();
411
+ _iterator2.f();
350
412
  }
351
413
  }
352
414
  return mergedItem;
@@ -377,11 +439,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
377
439
  key: "recordRecentSqliteWrite",
378
440
  value: function recordRecentSqliteWrite(source, orders) {
379
441
  var now = Date.now();
380
- var _iterator2 = _createForOfIteratorHelper(orders),
381
- _step2;
442
+ var _iterator3 = _createForOfIteratorHelper(orders),
443
+ _step3;
382
444
  try {
383
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
384
- var order = _step2.value;
445
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
446
+ var order = _step3.value;
385
447
  var storageKey = this.getOrderStorageKey(order);
386
448
  if (!storageKey) continue;
387
449
  this.recentSqliteWriteByStorageKey.set(storageKey, {
@@ -390,9 +452,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
390
452
  });
391
453
  }
392
454
  } catch (err) {
393
- _iterator2.e(err);
455
+ _iterator3.e(err);
394
456
  } finally {
395
- _iterator2.f();
457
+ _iterator3.f();
396
458
  }
397
459
  }
398
460
 
@@ -405,6 +467,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
405
467
  }, {
406
468
  key: "filterRedundantPatchOrders",
407
469
  value: function filterRedundantPatchOrders(source, orders, mergeActions) {
470
+ var forceWriteStorageKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Set();
408
471
  var eligibleSkipSources = new Set(['pubsub.bodyUpsert', 'pubsub.httpRefresh']);
409
472
  if (!eligibleSkipSources.has(source)) {
410
473
  return {
@@ -415,11 +478,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
415
478
  var now = Date.now();
416
479
  var toWrite = [];
417
480
  var skipped = [];
418
- var _iterator3 = _createForOfIteratorHelper(orders),
419
- _step3;
481
+ var _iterator4 = _createForOfIteratorHelper(orders),
482
+ _step4;
420
483
  try {
421
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
422
- var order = _step3.value;
484
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
485
+ var order = _step4.value;
423
486
  var storageKey = this.getOrderStorageKey(order);
424
487
  if (!storageKey) {
425
488
  toWrite.push(order);
@@ -433,6 +496,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
433
496
  toWrite.push(order);
434
497
  continue;
435
498
  }
499
+
500
+ // 远端商品成员确实发生增删时必须落库,避免内存已更新但 SQLite 仍被回声窗口跳过。
501
+ if (forceWriteStorageKeys.has(storageKey)) {
502
+ toWrite.push(order);
503
+ continue;
504
+ }
436
505
  var recent = this.recentSqliteWriteByStorageKey.get(storageKey);
437
506
  if (recent && ORDER_BUSINESS_WRITE_SOURCES.has(recent.source) && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
438
507
  var _order$order_id2;
@@ -448,9 +517,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
448
517
  toWrite.push(order);
449
518
  }
450
519
  } catch (err) {
451
- _iterator3.e(err);
520
+ _iterator4.e(err);
452
521
  } finally {
453
- _iterator3.f();
522
+ _iterator4.f();
454
523
  }
455
524
  return {
456
525
  toWrite: toWrite,
@@ -470,11 +539,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
470
539
  var now = Date.now();
471
540
  var toFetch = [];
472
541
  var skipped = [];
473
- var _iterator4 = _createForOfIteratorHelper(ids),
474
- _step4;
542
+ var _iterator5 = _createForOfIteratorHelper(ids),
543
+ _step5;
475
544
  try {
476
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
477
- var id = _step4.value;
545
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
546
+ var id = _step5.value;
478
547
  var existing = this.getOrderByOrderId(id);
479
548
  if (!existing) {
480
549
  toFetch.push(id);
@@ -493,9 +562,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
493
562
  toFetch.push(id);
494
563
  }
495
564
  } catch (err) {
496
- _iterator4.e(err);
565
+ _iterator5.e(err);
497
566
  } finally {
498
- _iterator4.f();
567
+ _iterator5.f();
499
568
  }
500
569
  return {
501
570
  toFetch: toFetch,
@@ -630,27 +699,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
630
699
  }, {
631
700
  key: "preload",
632
701
  value: function () {
633
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
702
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
634
703
  var orders;
635
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
636
- while (1) switch (_context3.prev = _context3.next) {
704
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
705
+ while (1) switch (_context4.prev = _context4.next) {
637
706
  case 0:
638
- _context3.next = 2;
707
+ _context4.next = 2;
639
708
  return this.loadOrdersByServer();
640
709
  case 2:
641
- orders = _context3.sent;
710
+ orders = _context4.sent;
642
711
  this.store.list = cloneDeep(orders);
643
712
  this.syncOrdersMap();
644
- _context3.next = 7;
713
+ _context4.next = 7;
645
714
  return this.emitOrdersChanged([], 'preload');
646
715
  case 7:
647
- _context3.next = 9;
716
+ _context4.next = 9;
648
717
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
649
718
  case 9:
650
719
  case "end":
651
- return _context3.stop();
720
+ return _context4.stop();
652
721
  }
653
- }, _callee3, this);
722
+ }, _callee4, this);
654
723
  }));
655
724
  function preload() {
656
725
  return _preload.apply(this, arguments);
@@ -712,7 +781,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
712
781
  }, {
713
782
  key: "getLocalOrderByLookup",
714
783
  value: function () {
715
- var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(lookup) {
784
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
716
785
  var _this4 = this;
717
786
  var options,
718
787
  key,
@@ -722,11 +791,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
722
791
  orders,
723
792
  localOrder,
724
793
  normalizedOrder,
725
- _args4 = arguments;
726
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
727
- while (1) switch (_context4.prev = _context4.next) {
794
+ _args5 = arguments;
795
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
796
+ while (1) switch (_context5.prev = _context5.next) {
728
797
  case 0:
729
- options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
798
+ options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
730
799
  key = this.getIdKey(lookup);
731
800
  logContext = {
732
801
  operation_id: options.operationId,
@@ -738,38 +807,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
738
807
  }
739
808
  memoryOrderById = this.store.map.get(key);
740
809
  if (!memoryOrderById) {
741
- _context4.next = 8;
810
+ _context5.next = 8;
742
811
  break;
743
812
  }
744
813
  if (options.operationId) {
745
814
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
746
815
  }
747
- return _context4.abrupt("return", memoryOrderById);
816
+ return _context5.abrupt("return", memoryOrderById);
748
817
  case 8:
749
818
  memoryOrder = this.store.list.find(function (order) {
750
819
  return _this4.isOrderLookupMatch(order, key);
751
820
  });
752
821
  if (!memoryOrder) {
753
- _context4.next = 12;
822
+ _context5.next = 12;
754
823
  break;
755
824
  }
756
825
  if (options.operationId) {
757
826
  this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
758
827
  }
759
- return _context4.abrupt("return", memoryOrder);
828
+ return _context5.abrupt("return", memoryOrder);
760
829
  case 12:
761
830
  if (options.operationId) {
762
831
  this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
763
832
  }
764
- _context4.next = 15;
833
+ _context5.next = 15;
765
834
  return this.loadOrdersFromSQLite();
766
835
  case 15:
767
- orders = _context4.sent;
836
+ orders = _context5.sent;
768
837
  localOrder = orders.find(function (order) {
769
838
  return _this4.isOrderLookupMatch(order, key);
770
839
  });
771
840
  if (localOrder) {
772
- _context4.next = 20;
841
+ _context5.next = 20;
773
842
  break;
774
843
  }
775
844
  if (options.operationId) {
@@ -777,7 +846,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
777
846
  sqlite_order_count: orders.length
778
847
  }));
779
848
  }
780
- return _context4.abrupt("return", null);
849
+ return _context5.abrupt("return", null);
781
850
  case 20:
782
851
  this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
783
852
  this.syncOrdersMap();
@@ -787,14 +856,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
787
856
  sqlite_order_count: orders.length
788
857
  }, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
789
858
  }
790
- return _context4.abrupt("return", normalizedOrder);
859
+ return _context5.abrupt("return", normalizedOrder);
791
860
  case 25:
792
861
  case "end":
793
- return _context4.stop();
862
+ return _context5.stop();
794
863
  }
795
- }, _callee4, this);
864
+ }, _callee5, this);
796
865
  }));
797
- function getLocalOrderByLookup(_x3) {
866
+ function getLocalOrderByLookup(_x4) {
798
867
  return _getLocalOrderByLookup.apply(this, arguments);
799
868
  }
800
869
  return getLocalOrderByLookup;
@@ -802,10 +871,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
802
871
  }, {
803
872
  key: "getLocalPayment",
804
873
  value: function () {
805
- var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
874
+ var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
806
875
  var logContext, order, payments, match;
807
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
808
- while (1) switch (_context5.prev = _context5.next) {
876
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
877
+ while (1) switch (_context6.prev = _context6.next) {
809
878
  case 0:
810
879
  logContext = {
811
880
  operation_id: params.operationId,
@@ -813,56 +882,56 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
813
882
  payment_number: params.paymentNumber
814
883
  };
815
884
  this.logInfo('getLocalPayment-开始', logContext);
816
- _context5.prev = 2;
817
- _context5.next = 5;
885
+ _context6.prev = 2;
886
+ _context6.next = 5;
818
887
  return this.getLocalOrderByLookup(params.saleId, {
819
888
  operationId: params.operationId
820
889
  });
821
890
  case 5:
822
- order = _context5.sent;
891
+ order = _context6.sent;
823
892
  if (order) {
824
- _context5.next = 9;
893
+ _context6.next = 9;
825
894
  break;
826
895
  }
827
896
  this.logWarning('getLocalPayment-订单未命中', logContext);
828
- return _context5.abrupt("return", null);
897
+ return _context6.abrupt("return", null);
829
898
  case 9:
830
899
  payments = order.payments || [];
831
900
  match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
832
901
  if (match) {
833
- _context5.next = 14;
902
+ _context6.next = 14;
834
903
  break;
835
904
  }
836
905
  this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
837
906
  payments: payments
838
907
  }));
839
- return _context5.abrupt("return", null);
908
+ return _context6.abrupt("return", null);
840
909
  case 14:
841
910
  this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
842
911
  matched_by: match.matchedBy,
843
912
  payment_index: match.index,
844
913
  payment: match.payment
845
914
  }));
846
- return _context5.abrupt("return", {
915
+ return _context6.abrupt("return", {
847
916
  order: order,
848
917
  payment: match.payment,
849
918
  paymentIndex: match.index,
850
919
  matchedBy: match.matchedBy
851
920
  });
852
921
  case 18:
853
- _context5.prev = 18;
854
- _context5.t0 = _context5["catch"](2);
922
+ _context6.prev = 18;
923
+ _context6.t0 = _context6["catch"](2);
855
924
  this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
856
- error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
925
+ error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
857
926
  }));
858
- throw _context5.t0;
927
+ throw _context6.t0;
859
928
  case 22:
860
929
  case "end":
861
- return _context5.stop();
930
+ return _context6.stop();
862
931
  }
863
- }, _callee5, this, [[2, 18]]);
932
+ }, _callee6, this, [[2, 18]]);
864
933
  }));
865
- function getLocalPayment(_x4) {
934
+ function getLocalPayment(_x5) {
866
935
  return _getLocalPayment.apply(this, arguments);
867
936
  }
868
937
  return getLocalPayment;
@@ -870,10 +939,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
870
939
  }, {
871
940
  key: "updateLocalPayment",
872
941
  value: function () {
873
- var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
942
+ var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
874
943
  var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
875
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
876
- while (1) switch (_context6.prev = _context6.next) {
944
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
945
+ while (1) switch (_context7.prev = _context7.next) {
877
946
  case 0:
878
947
  logContext = {
879
948
  operation_id: params.operationId,
@@ -882,16 +951,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
882
951
  incoming_payment_update: params.updates
883
952
  };
884
953
  this.logInfo('updateLocalPayment-开始', logContext);
885
- _context6.next = 4;
954
+ _context7.next = 4;
886
955
  return this.getLocalPayment(params);
887
956
  case 4:
888
- found = _context6.sent;
957
+ found = _context7.sent;
889
958
  if (found) {
890
- _context6.next = 8;
959
+ _context7.next = 8;
891
960
  break;
892
961
  }
893
962
  this.logWarning('updateLocalPayment-支付项未命中', logContext);
894
- return _context6.abrupt("return", null);
963
+ return _context7.abrupt("return", null);
895
964
  case 8:
896
965
  previousPayment = cloneDeep(found.payment);
897
966
  nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
@@ -914,11 +983,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
914
983
  targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
915
984
  shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
916
985
  if (!(targetIndex < 0 && shouldKeepInMemory)) {
917
- _context6.next = 18;
986
+ _context7.next = 18;
918
987
  break;
919
988
  }
920
989
  this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
921
- return _context6.abrupt("return", null);
990
+ return _context7.abrupt("return", null);
922
991
  case 18:
923
992
  previousList = this.store.list;
924
993
  this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
@@ -928,11 +997,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
928
997
  });
929
998
  this.syncOrdersMap();
930
999
  storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
931
- _context6.prev = 22;
1000
+ _context7.prev = 22;
932
1001
  this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
933
1002
  storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
934
1003
  }));
935
- _context6.next = 26;
1004
+ _context7.next = 26;
936
1005
  return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
937
1006
  throwOnError: true
938
1007
  });
@@ -940,39 +1009,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
940
1009
  this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
941
1010
  storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
942
1011
  }));
943
- _context6.next = 35;
1012
+ _context7.next = 35;
944
1013
  break;
945
1014
  case 29:
946
- _context6.prev = 29;
947
- _context6.t0 = _context6["catch"](22);
1015
+ _context7.prev = 29;
1016
+ _context7.t0 = _context7["catch"](22);
948
1017
  this.store.list = previousList;
949
1018
  this.syncOrdersMap();
950
1019
  this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
951
1020
  storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
952
- error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
1021
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
953
1022
  }));
954
- throw _context6.t0;
1023
+ throw _context7.t0;
955
1024
  case 35:
956
1025
  if (!(shouldKeepInMemory || targetIndex >= 0)) {
957
- _context6.next = 38;
1026
+ _context7.next = 38;
958
1027
  break;
959
1028
  }
960
- _context6.next = 38;
1029
+ _context7.next = 38;
961
1030
  return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
962
1031
  case 38:
963
1032
  this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
964
- return _context6.abrupt("return", {
1033
+ return _context7.abrupt("return", {
965
1034
  order: nextOrder,
966
1035
  payment: nextPayment,
967
1036
  previousPayment: previousPayment
968
1037
  });
969
1038
  case 40:
970
1039
  case "end":
971
- return _context6.stop();
1040
+ return _context7.stop();
972
1041
  }
973
- }, _callee6, this, [[22, 29]]);
1042
+ }, _callee7, this, [[22, 29]]);
974
1043
  }));
975
- function updateLocalPayment(_x5) {
1044
+ function updateLocalPayment(_x6) {
976
1045
  return _updateLocalPayment.apply(this, arguments);
977
1046
  }
978
1047
  return updateLocalPayment;
@@ -980,18 +1049,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
980
1049
  }, {
981
1050
  key: "loadOrdersByServer",
982
1051
  value: function () {
983
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1052
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
984
1053
  var _this5 = this,
985
1054
  _this$store;
986
1055
  var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
987
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
988
- while (1) switch (_context7.prev = _context7.next) {
1056
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1057
+ while (1) switch (_context8.prev = _context8.next) {
989
1058
  case 0:
990
1059
  orderList = [];
991
- _context7.next = 3;
1060
+ _context8.next = 3;
992
1061
  return this.loadOrdersFromSQLite();
993
1062
  case 3:
994
- protectedOrdersBeforeRemoteFetch = _context7.sent.filter(function (order) {
1063
+ protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
995
1064
  return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
996
1065
  });
997
1066
  this.logInfo('loadOrdersByServer-开始', {
@@ -1003,51 +1072,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1003
1072
  }, 0)
1004
1073
  });
1005
1074
  if (!this.orderDataSource) {
1006
- _context7.next = 20;
1075
+ _context8.next = 20;
1007
1076
  break;
1008
1077
  }
1009
- _context7.prev = 6;
1010
- _context7.next = 9;
1078
+ _context8.prev = 6;
1079
+ _context8.next = 9;
1011
1080
  return this.orderDataSource.run({
1012
1081
  sse: {
1013
1082
  query: this.store.createdAtQuery
1014
1083
  }
1015
1084
  });
1016
1085
  case 9:
1017
- data = _context7.sent;
1086
+ data = _context8.sent;
1018
1087
  orderList = data || [];
1019
1088
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1020
1089
  count: orderList.length
1021
1090
  });
1022
1091
  this.markOrderPulledAtNow();
1023
1092
  this.lastServerFullFetchAtMs = Date.now();
1024
- _context7.next = 20;
1093
+ _context8.next = 20;
1025
1094
  break;
1026
1095
  case 16:
1027
- _context7.prev = 16;
1028
- _context7.t0 = _context7["catch"](6);
1096
+ _context8.prev = 16;
1097
+ _context8.t0 = _context8["catch"](6);
1029
1098
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1030
- return _context7.abrupt("return", this.store.list);
1099
+ return _context8.abrupt("return", this.store.list);
1031
1100
  case 20:
1032
- _context7.next = 22;
1101
+ _context8.next = 22;
1033
1102
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1034
1103
  case 22:
1035
- mergedOrders = _context7.sent;
1104
+ mergedOrders = _context8.sent;
1036
1105
  memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
1037
1106
  this.logInfo('loadOrdersByServer-结束', {
1038
1107
  count: memoryOrders.length,
1039
1108
  persistedCount: mergedOrders.length,
1040
1109
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1041
1110
  });
1042
- _context7.next = 27;
1111
+ _context8.next = 27;
1043
1112
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1044
1113
  case 27:
1045
- return _context7.abrupt("return", memoryOrders);
1114
+ return _context8.abrupt("return", memoryOrders);
1046
1115
  case 28:
1047
1116
  case "end":
1048
- return _context7.stop();
1117
+ return _context8.stop();
1049
1118
  }
1050
- }, _callee7, this, [[6, 16]]);
1119
+ }, _callee8, this, [[6, 16]]);
1051
1120
  }));
1052
1121
  function loadOrdersByServer() {
1053
1122
  return _loadOrdersByServer.apply(this, arguments);
@@ -1062,54 +1131,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1062
1131
  }, {
1063
1132
  key: "silentRefresh",
1064
1133
  value: (function () {
1065
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1134
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1066
1135
  var startTime, elapsedSinceFullFetch, orders, errorMessage;
1067
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1068
- while (1) switch (_context8.prev = _context8.next) {
1136
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1137
+ while (1) switch (_context9.prev = _context9.next) {
1069
1138
  case 0:
1070
1139
  startTime = Date.now();
1071
1140
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1072
1141
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1073
- _context8.next = 4;
1142
+ _context9.next = 4;
1074
1143
  break;
1075
1144
  }
1076
- return _context8.abrupt("return", this.store.list);
1145
+ return _context9.abrupt("return", this.store.list);
1077
1146
  case 4:
1078
1147
  this.logInfo('silentRefresh 开始');
1079
- _context8.prev = 5;
1148
+ _context9.prev = 5;
1080
1149
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1081
1150
  this.updateCreateStore();
1082
- _context8.next = 9;
1151
+ _context9.next = 9;
1083
1152
  return this.loadOrdersByServer();
1084
1153
  case 9:
1085
- orders = _context8.sent;
1154
+ orders = _context9.sent;
1086
1155
  this.store.list = cloneDeep(orders);
1087
1156
  this.syncOrdersMap();
1088
- _context8.next = 14;
1157
+ _context9.next = 14;
1089
1158
  return this.emitOrdersChanged([], 'silentRefresh');
1090
1159
  case 14:
1091
- _context8.next = 16;
1160
+ _context9.next = 16;
1092
1161
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1093
1162
  case 16:
1094
1163
  this.logInfo('silentRefresh 完成', {
1095
1164
  orderCount: orders.length,
1096
1165
  duration: "".concat(Date.now() - startTime, "ms")
1097
1166
  });
1098
- return _context8.abrupt("return", this.store.list);
1167
+ return _context9.abrupt("return", this.store.list);
1099
1168
  case 20:
1100
- _context8.prev = 20;
1101
- _context8.t0 = _context8["catch"](5);
1102
- errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
1169
+ _context9.prev = 20;
1170
+ _context9.t0 = _context9["catch"](5);
1171
+ errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1103
1172
  this.logError('silentRefresh 失败', {
1104
1173
  duration: "".concat(Date.now() - startTime, "ms"),
1105
1174
  error: errorMessage
1106
1175
  });
1107
- return _context8.abrupt("return", this.store.list);
1176
+ return _context9.abrupt("return", this.store.list);
1108
1177
  case 25:
1109
1178
  case "end":
1110
- return _context8.stop();
1179
+ return _context9.stop();
1111
1180
  }
1112
- }, _callee8, this, [[5, 20]]);
1181
+ }, _callee9, this, [[5, 20]]);
1113
1182
  }));
1114
1183
  function silentRefresh() {
1115
1184
  return _silentRefresh.apply(this, arguments);
@@ -1176,31 +1245,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1176
1245
  }, {
1177
1246
  key: "overwriteExistingOrder",
1178
1247
  value: (function () {
1179
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fresh) {
1248
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1180
1249
  var _this7 = this;
1181
1250
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1182
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1183
- while (1) switch (_context9.prev = _context9.next) {
1251
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1252
+ while (1) switch (_context10.prev = _context10.next) {
1184
1253
  case 0:
1185
1254
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
1186
1255
  if (!(orderId === undefined || orderId === null)) {
1187
- _context9.next = 4;
1256
+ _context10.next = 4;
1188
1257
  break;
1189
1258
  }
1190
1259
  this.logError('overwriteExistingOrder-入参缺少 order_id');
1191
- return _context9.abrupt("return", {
1260
+ return _context10.abrupt("return", {
1192
1261
  overwritten: false
1193
1262
  });
1194
1263
  case 4:
1195
1264
  key = this.getIdKey(orderId);
1196
1265
  if (this.store.map.has(key)) {
1197
- _context9.next = 8;
1266
+ _context10.next = 8;
1198
1267
  break;
1199
1268
  }
1200
1269
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
1201
1270
  orderId: orderId
1202
1271
  });
1203
- return _context9.abrupt("return", {
1272
+ return _context10.abrupt("return", {
1204
1273
  overwritten: false
1205
1274
  });
1206
1275
  case 8:
@@ -1219,26 +1288,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1219
1288
  return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1220
1289
  });
1221
1290
  this.syncOrdersMap();
1222
- _context9.next = 16;
1291
+ _context10.next = 16;
1223
1292
  return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1224
1293
  case 16:
1225
1294
  this.logInfo('overwriteExistingOrder-结束', {
1226
1295
  orderId: orderId,
1227
1296
  storeOrderCountAfter: this.store.list.length
1228
1297
  });
1229
- _context9.next = 19;
1298
+ _context10.next = 19;
1230
1299
  return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1231
1300
  case 19:
1232
- return _context9.abrupt("return", {
1301
+ return _context10.abrupt("return", {
1233
1302
  overwritten: true
1234
1303
  });
1235
1304
  case 20:
1236
1305
  case "end":
1237
- return _context9.stop();
1306
+ return _context10.stop();
1238
1307
  }
1239
- }, _callee9, this);
1308
+ }, _callee10, this);
1240
1309
  }));
1241
- function overwriteExistingOrder(_x6) {
1310
+ function overwriteExistingOrder(_x7) {
1242
1311
  return _overwriteExistingOrder.apply(this, arguments);
1243
1312
  }
1244
1313
  return overwriteExistingOrder;
@@ -1251,33 +1320,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1251
1320
  }, {
1252
1321
  key: "upsertOrdersFromRemote",
1253
1322
  value: (function () {
1254
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(freshOrders) {
1323
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(freshOrders) {
1255
1324
  var source,
1256
- _args10 = arguments;
1257
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1258
- while (1) switch (_context10.prev = _context10.next) {
1325
+ _args11 = arguments;
1326
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1327
+ while (1) switch (_context11.prev = _context11.next) {
1259
1328
  case 0:
1260
- source = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : 'upsertOrdersFromRemote';
1329
+ source = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : 'upsertOrdersFromRemote';
1261
1330
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
1262
- _context10.next = 4;
1331
+ _context11.next = 4;
1263
1332
  break;
1264
1333
  }
1265
1334
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
1266
- return _context10.abrupt("return");
1335
+ return _context11.abrupt("return");
1267
1336
  case 4:
1268
1337
  this.logInfo('upsertOrdersFromRemote-开始', {
1269
1338
  count: freshOrders.length,
1270
1339
  source: source
1271
1340
  });
1272
- _context10.next = 7;
1341
+ _context11.next = 7;
1273
1342
  return this.mergeOrdersToStore(freshOrders, source);
1274
1343
  case 7:
1275
1344
  case "end":
1276
- return _context10.stop();
1345
+ return _context11.stop();
1277
1346
  }
1278
- }, _callee10, this);
1347
+ }, _callee11, this);
1279
1348
  }));
1280
- function upsertOrdersFromRemote(_x7) {
1349
+ function upsertOrdersFromRemote(_x8) {
1281
1350
  return _upsertOrdersFromRemote.apply(this, arguments);
1282
1351
  }
1283
1352
  return upsertOrdersFromRemote;
@@ -1285,21 +1354,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1285
1354
  }, {
1286
1355
  key: "markOrderSyncedByExternalSaleNumber",
1287
1356
  value: function () {
1288
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
1357
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1289
1358
  var _this8 = this,
1290
1359
  _existing$external_sa,
1291
1360
  _nextOrder$order_id;
1292
1361
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1293
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1294
- while (1) switch (_context11.prev = _context11.next) {
1362
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1363
+ while (1) switch (_context12.prev = _context12.next) {
1295
1364
  case 0:
1296
1365
  externalSaleNumber = params.externalSaleNumber;
1297
1366
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1298
- _context11.next = 4;
1367
+ _context12.next = 4;
1299
1368
  break;
1300
1369
  }
1301
1370
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1302
- return _context11.abrupt("return", {
1371
+ return _context12.abrupt("return", {
1303
1372
  updated: false
1304
1373
  });
1305
1374
  case 4:
@@ -1310,13 +1379,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1310
1379
  return _this8.getIdKey(value) === key;
1311
1380
  });
1312
1381
  if (!(targetIndex < 0)) {
1313
- _context11.next = 9;
1382
+ _context12.next = 9;
1314
1383
  break;
1315
1384
  }
1316
1385
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1317
1386
  external_sale_number: externalSaleNumber
1318
1387
  });
1319
- return _context11.abrupt("return", {
1388
+ return _context12.abrupt("return", {
1320
1389
  updated: false
1321
1390
  });
1322
1391
  case 9:
@@ -1332,27 +1401,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1332
1401
  return nextOrder;
1333
1402
  });
1334
1403
  this.syncOrdersMap();
1335
- _context11.next = 16;
1404
+ _context12.next = 16;
1336
1405
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1337
1406
  case 16:
1338
1407
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1339
1408
  external_sale_number: externalSaleNumber,
1340
1409
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1341
1410
  });
1342
- _context11.next = 19;
1411
+ _context12.next = 19;
1343
1412
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1344
1413
  case 19:
1345
- return _context11.abrupt("return", {
1414
+ return _context12.abrupt("return", {
1346
1415
  updated: true,
1347
1416
  order: nextOrder
1348
1417
  });
1349
1418
  case 20:
1350
1419
  case "end":
1351
- return _context11.stop();
1420
+ return _context12.stop();
1352
1421
  }
1353
- }, _callee11, this);
1422
+ }, _callee12, this);
1354
1423
  }));
1355
- function markOrderSyncedByExternalSaleNumber(_x8) {
1424
+ function markOrderSyncedByExternalSaleNumber(_x9) {
1356
1425
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
1357
1426
  }
1358
1427
  return markOrderSyncedByExternalSaleNumber;
@@ -1364,13 +1433,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1364
1433
  }, {
1365
1434
  key: "upsertPendingSyncOrders",
1366
1435
  value: (function () {
1367
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(pendingOrders) {
1436
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(pendingOrders) {
1368
1437
  var _this9 = this;
1369
1438
  var options,
1370
1439
  pendingMap,
1371
1440
  memoryPendingMap,
1372
- _iterator5,
1373
- _step5,
1441
+ _iterator6,
1442
+ _step6,
1374
1443
  order,
1375
1444
  normalizedOrder,
1376
1445
  pendingOrder,
@@ -1379,12 +1448,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1379
1448
  updatedList,
1380
1449
  identityKeyToIndex,
1381
1450
  index,
1382
- _iterator6,
1383
- _step6,
1384
- key,
1385
1451
  _iterator7,
1386
1452
  _step7,
1387
- _step7$value,
1453
+ key,
1454
+ _iterator8,
1455
+ _step8,
1456
+ _step8$value,
1388
1457
  _storageKey,
1389
1458
  _pendingOrder,
1390
1459
  matchIndex,
@@ -1395,29 +1464,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1395
1464
  insertIndex,
1396
1465
  patchedOrders,
1397
1466
  previousList,
1398
- _args12 = arguments;
1399
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1400
- while (1) switch (_context12.prev = _context12.next) {
1467
+ _args13 = arguments;
1468
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1469
+ while (1) switch (_context13.prev = _context13.next) {
1401
1470
  case 0:
1402
- options = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {};
1471
+ options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
1403
1472
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1404
- _context12.next = 4;
1473
+ _context13.next = 4;
1405
1474
  break;
1406
1475
  }
1407
1476
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1408
- return _context12.abrupt("return");
1477
+ return _context13.abrupt("return");
1409
1478
  case 4:
1410
1479
  pendingMap = new Map();
1411
1480
  memoryPendingMap = new Map();
1412
- _iterator5 = _createForOfIteratorHelper(pendingOrders);
1413
- _context12.prev = 7;
1414
- _iterator5.s();
1481
+ _iterator6 = _createForOfIteratorHelper(pendingOrders);
1482
+ _context13.prev = 7;
1483
+ _iterator6.s();
1415
1484
  case 9:
1416
- if ((_step5 = _iterator5.n()).done) {
1417
- _context12.next = 20;
1485
+ if ((_step6 = _iterator6.n()).done) {
1486
+ _context13.next = 20;
1418
1487
  break;
1419
1488
  }
1420
- order = _step5.value;
1489
+ order = _step6.value;
1421
1490
  normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'upsertPendingSyncOrders.incoming');
1422
1491
  pendingOrder = _objectSpread(_objectSpread({}, normalizedOrder), {}, {
1423
1492
  need_sync: 1,
@@ -1425,36 +1494,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1425
1494
  });
1426
1495
  storageKey = this.getOrderStorageKey(pendingOrder);
1427
1496
  if (storageKey) {
1428
- _context12.next = 16;
1497
+ _context13.next = 16;
1429
1498
  break;
1430
1499
  }
1431
- return _context12.abrupt("continue", 18);
1500
+ return _context13.abrupt("continue", 18);
1432
1501
  case 16:
1433
1502
  pendingMap.set(storageKey, pendingOrder);
1434
1503
  memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1435
1504
  case 18:
1436
- _context12.next = 9;
1505
+ _context13.next = 9;
1437
1506
  break;
1438
1507
  case 20:
1439
- _context12.next = 25;
1508
+ _context13.next = 25;
1440
1509
  break;
1441
1510
  case 22:
1442
- _context12.prev = 22;
1443
- _context12.t0 = _context12["catch"](7);
1444
- _iterator5.e(_context12.t0);
1511
+ _context13.prev = 22;
1512
+ _context13.t0 = _context13["catch"](7);
1513
+ _iterator6.e(_context13.t0);
1445
1514
  case 25:
1446
- _context12.prev = 25;
1447
- _iterator5.f();
1448
- return _context12.finish(25);
1515
+ _context13.prev = 25;
1516
+ _iterator6.f();
1517
+ return _context13.finish(25);
1449
1518
  case 28:
1450
1519
  if (!(pendingMap.size === 0)) {
1451
- _context12.next = 31;
1520
+ _context13.next = 31;
1452
1521
  break;
1453
1522
  }
1454
1523
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1455
1524
  count: pendingOrders.length
1456
1525
  });
1457
- return _context12.abrupt("return");
1526
+ return _context13.abrupt("return");
1458
1527
  case 31:
1459
1528
  this.logInfo('upsertPendingSyncOrders-开始', {
1460
1529
  count: pendingMap.size
@@ -1466,31 +1535,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1466
1535
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1467
1536
  identityKeyToIndex = new Map();
1468
1537
  for (index = 0; index < updatedList.length; index += 1) {
1469
- _iterator6 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1538
+ _iterator7 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1470
1539
  try {
1471
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1472
- key = _step6.value;
1540
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1541
+ key = _step7.value;
1473
1542
  // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
1474
1543
  if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1475
1544
  }
1476
1545
  } catch (err) {
1477
- _iterator6.e(err);
1546
+ _iterator7.e(err);
1478
1547
  } finally {
1479
- _iterator6.f();
1548
+ _iterator7.f();
1480
1549
  }
1481
1550
  }
1482
- _iterator7 = _createForOfIteratorHelper(memoryPendingMap.entries());
1483
- _context12.prev = 37;
1484
- _iterator7.s();
1551
+ _iterator8 = _createForOfIteratorHelper(memoryPendingMap.entries());
1552
+ _context13.prev = 37;
1553
+ _iterator8.s();
1485
1554
  case 39:
1486
- if ((_step7 = _iterator7.n()).done) {
1487
- _context12.next = 58;
1555
+ if ((_step8 = _iterator8.n()).done) {
1556
+ _context13.next = 58;
1488
1557
  break;
1489
1558
  }
1490
- _step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0], _pendingOrder = _step7$value[1];
1559
+ _step8$value = _slicedToArray(_step8.value, 2), _storageKey = _step8$value[0], _pendingOrder = _step8$value[1];
1491
1560
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
1492
1561
  if (!(matchIndex >= 0)) {
1493
- _context12.next = 52;
1562
+ _context13.next = 52;
1494
1563
  break;
1495
1564
  }
1496
1565
  existingOrder = updatedList[matchIndex];
@@ -1507,57 +1576,57 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1507
1576
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1508
1577
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1509
1578
  mergeActions[_storageKey] = 'update';
1510
- return _context12.abrupt("continue", 56);
1579
+ return _context13.abrupt("continue", 56);
1511
1580
  case 52:
1512
1581
  insertIndex = updatedList.length;
1513
1582
  updatedList.push(_pendingOrder);
1514
1583
  this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1515
1584
  mergeActions[_storageKey] = 'insert';
1516
1585
  case 56:
1517
- _context12.next = 39;
1586
+ _context13.next = 39;
1518
1587
  break;
1519
1588
  case 58:
1520
- _context12.next = 63;
1589
+ _context13.next = 63;
1521
1590
  break;
1522
1591
  case 60:
1523
- _context12.prev = 60;
1524
- _context12.t1 = _context12["catch"](37);
1525
- _iterator7.e(_context12.t1);
1592
+ _context13.prev = 60;
1593
+ _context13.t1 = _context13["catch"](37);
1594
+ _iterator8.e(_context13.t1);
1526
1595
  case 63:
1527
- _context12.prev = 63;
1528
- _iterator7.f();
1529
- return _context12.finish(63);
1596
+ _context13.prev = 63;
1597
+ _iterator8.f();
1598
+ return _context13.finish(63);
1530
1599
  case 66:
1531
1600
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1532
1601
  previousList = this.store.list;
1533
1602
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1534
1603
  this.syncOrdersMap();
1535
- _context12.prev = 70;
1536
- _context12.next = 73;
1604
+ _context13.prev = 70;
1605
+ _context13.next = 73;
1537
1606
  return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1538
1607
  case 73:
1539
- _context12.next = 80;
1608
+ _context13.next = 80;
1540
1609
  break;
1541
1610
  case 75:
1542
- _context12.prev = 75;
1543
- _context12.t2 = _context12["catch"](70);
1611
+ _context13.prev = 75;
1612
+ _context13.t2 = _context13["catch"](70);
1544
1613
  this.store.list = previousList;
1545
1614
  this.syncOrdersMap();
1546
- throw _context12.t2;
1615
+ throw _context13.t2;
1547
1616
  case 80:
1548
1617
  this.logInfo('upsertPendingSyncOrders-结束', {
1549
1618
  count: patchedOrders.length,
1550
1619
  storeOrderCountAfter: this.store.list.length
1551
1620
  });
1552
- _context12.next = 83;
1621
+ _context13.next = 83;
1553
1622
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1554
1623
  case 83:
1555
1624
  case "end":
1556
- return _context12.stop();
1625
+ return _context13.stop();
1557
1626
  }
1558
- }, _callee12, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1627
+ }, _callee13, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1559
1628
  }));
1560
- function upsertPendingSyncOrders(_x9) {
1629
+ function upsertPendingSyncOrders(_x10) {
1561
1630
  return _upsertPendingSyncOrders.apply(this, arguments);
1562
1631
  }
1563
1632
  return upsertPendingSyncOrders;
@@ -1570,40 +1639,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1570
1639
  }, {
1571
1640
  key: "upsertLocalDraftOrders",
1572
1641
  value: (function () {
1573
- var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(draftOrders) {
1642
+ var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(draftOrders) {
1574
1643
  var _this10 = this;
1575
- var draftMap, memoryDraftMap, _iterator8, _step8, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator9, _step9, key, _iterator10, _step10, _step10$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1576
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1577
- while (1) switch (_context13.prev = _context13.next) {
1644
+ var draftMap, memoryDraftMap, _iterator9, _step9, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator10, _step10, key, _iterator11, _step11, _step11$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1645
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1646
+ while (1) switch (_context14.prev = _context14.next) {
1578
1647
  case 0:
1579
1648
  if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
1580
- _context13.next = 3;
1649
+ _context14.next = 3;
1581
1650
  break;
1582
1651
  }
1583
1652
  this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
1584
- return _context13.abrupt("return");
1653
+ return _context14.abrupt("return");
1585
1654
  case 3:
1586
1655
  draftMap = new Map();
1587
1656
  memoryDraftMap = new Map();
1588
- _iterator8 = _createForOfIteratorHelper(draftOrders);
1589
- _context13.prev = 6;
1590
- _iterator8.s();
1657
+ _iterator9 = _createForOfIteratorHelper(draftOrders);
1658
+ _context14.prev = 6;
1659
+ _iterator9.s();
1591
1660
  case 8:
1592
- if ((_step8 = _iterator8.n()).done) {
1593
- _context13.next = 19;
1661
+ if ((_step9 = _iterator9.n()).done) {
1662
+ _context14.next = 19;
1594
1663
  break;
1595
1664
  }
1596
- order = _step8.value;
1665
+ order = _step9.value;
1597
1666
  draftOrder = _objectSpread(_objectSpread({}, order), {}, {
1598
1667
  need_sync: 0,
1599
1668
  is_draft_order: 1
1600
1669
  });
1601
1670
  storageKey = this.getOrderStorageKey(draftOrder);
1602
1671
  if (storageKey) {
1603
- _context13.next = 14;
1672
+ _context14.next = 14;
1604
1673
  break;
1605
1674
  }
1606
- return _context13.abrupt("continue", 17);
1675
+ return _context14.abrupt("continue", 17);
1607
1676
  case 14:
1608
1677
  draftMap.set(storageKey, draftOrder);
1609
1678
  memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
@@ -1611,28 +1680,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1611
1680
  memoryDraftMap.set(storageKey, memoryDraftOrder);
1612
1681
  }
1613
1682
  case 17:
1614
- _context13.next = 8;
1683
+ _context14.next = 8;
1615
1684
  break;
1616
1685
  case 19:
1617
- _context13.next = 24;
1686
+ _context14.next = 24;
1618
1687
  break;
1619
1688
  case 21:
1620
- _context13.prev = 21;
1621
- _context13.t0 = _context13["catch"](6);
1622
- _iterator8.e(_context13.t0);
1689
+ _context14.prev = 21;
1690
+ _context14.t0 = _context14["catch"](6);
1691
+ _iterator9.e(_context14.t0);
1623
1692
  case 24:
1624
- _context13.prev = 24;
1625
- _iterator8.f();
1626
- return _context13.finish(24);
1693
+ _context14.prev = 24;
1694
+ _iterator9.f();
1695
+ return _context14.finish(24);
1627
1696
  case 27:
1628
1697
  if (!(draftMap.size === 0)) {
1629
- _context13.next = 30;
1698
+ _context14.next = 30;
1630
1699
  break;
1631
1700
  }
1632
1701
  this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
1633
1702
  count: draftOrders.length
1634
1703
  });
1635
- return _context13.abrupt("return");
1704
+ return _context14.abrupt("return");
1636
1705
  case 30:
1637
1706
  this.logInfo('upsertLocalDraftOrders-开始', {
1638
1707
  count: draftMap.size,
@@ -1645,30 +1714,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1645
1714
  });
1646
1715
  identityKeyToIndex = new Map();
1647
1716
  for (index = 0; index < updatedList.length; index += 1) {
1648
- _iterator9 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1717
+ _iterator10 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1649
1718
  try {
1650
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1651
- key = _step9.value;
1719
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1720
+ key = _step10.value;
1652
1721
  if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1653
1722
  }
1654
1723
  } catch (err) {
1655
- _iterator9.e(err);
1724
+ _iterator10.e(err);
1656
1725
  } finally {
1657
- _iterator9.f();
1726
+ _iterator10.f();
1658
1727
  }
1659
1728
  }
1660
- _iterator10 = _createForOfIteratorHelper(memoryDraftMap.entries());
1661
- _context13.prev = 36;
1662
- _iterator10.s();
1729
+ _iterator11 = _createForOfIteratorHelper(memoryDraftMap.entries());
1730
+ _context14.prev = 36;
1731
+ _iterator11.s();
1663
1732
  case 38:
1664
- if ((_step10 = _iterator10.n()).done) {
1665
- _context13.next = 57;
1733
+ if ((_step11 = _iterator11.n()).done) {
1734
+ _context14.next = 57;
1666
1735
  break;
1667
1736
  }
1668
- _step10$value = _slicedToArray(_step10.value, 2), _storageKey2 = _step10$value[0], _draftOrder = _step10$value[1];
1737
+ _step11$value = _slicedToArray(_step11.value, 2), _storageKey2 = _step11$value[0], _draftOrder = _step11$value[1];
1669
1738
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
1670
1739
  if (!(matchIndex >= 0)) {
1671
- _context13.next = 51;
1740
+ _context14.next = 51;
1672
1741
  break;
1673
1742
  }
1674
1743
  existingOrder = updatedList[matchIndex];
@@ -1683,45 +1752,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1683
1752
  draftMap.set(_storageKey2, reconciledDraftOrder);
1684
1753
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1685
1754
  mergeActions[_storageKey2] = 'update';
1686
- return _context13.abrupt("continue", 55);
1755
+ return _context14.abrupt("continue", 55);
1687
1756
  case 51:
1688
1757
  insertIndex = updatedList.length;
1689
1758
  updatedList.push(_draftOrder);
1690
1759
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1691
1760
  mergeActions[_storageKey2] = 'insert';
1692
1761
  case 55:
1693
- _context13.next = 38;
1762
+ _context14.next = 38;
1694
1763
  break;
1695
1764
  case 57:
1696
- _context13.next = 62;
1765
+ _context14.next = 62;
1697
1766
  break;
1698
1767
  case 59:
1699
- _context13.prev = 59;
1700
- _context13.t1 = _context13["catch"](36);
1701
- _iterator10.e(_context13.t1);
1768
+ _context14.prev = 59;
1769
+ _context14.t1 = _context14["catch"](36);
1770
+ _iterator11.e(_context14.t1);
1702
1771
  case 62:
1703
- _context13.prev = 62;
1704
- _iterator10.f();
1705
- return _context13.finish(62);
1772
+ _context14.prev = 62;
1773
+ _iterator11.f();
1774
+ return _context14.finish(62);
1706
1775
  case 65:
1707
1776
  patchedOrders = _toConsumableArray(draftMap.values());
1708
1777
  previousList = this.store.list;
1709
1778
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
1710
1779
  this.syncOrdersMap();
1711
- _context13.prev = 69;
1712
- _context13.next = 72;
1780
+ _context14.prev = 69;
1781
+ _context14.next = 72;
1713
1782
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
1714
1783
  throwOnError: true
1715
1784
  });
1716
1785
  case 72:
1717
- _context13.next = 79;
1786
+ _context14.next = 79;
1718
1787
  break;
1719
1788
  case 74:
1720
- _context13.prev = 74;
1721
- _context13.t2 = _context13["catch"](69);
1789
+ _context14.prev = 74;
1790
+ _context14.t2 = _context14["catch"](69);
1722
1791
  this.store.list = previousList;
1723
1792
  this.syncOrdersMap();
1724
- throw _context13.t2;
1793
+ throw _context14.t2;
1725
1794
  case 79:
1726
1795
  this.logInfo('upsertLocalDraftOrders-结束', {
1727
1796
  count: patchedOrders.length,
@@ -1731,20 +1800,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1731
1800
  return !_this10.shouldKeepOrderInMemory(order);
1732
1801
  });
1733
1802
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
1734
- _context13.next = 84;
1803
+ _context14.next = 84;
1735
1804
  break;
1736
1805
  }
1737
- _context13.next = 84;
1806
+ _context14.next = 84;
1738
1807
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
1739
1808
  return _this10.shouldKeepOrderInMemory(order);
1740
1809
  }), 'upsertLocalDraftOrders');
1741
1810
  case 84:
1742
1811
  case "end":
1743
- return _context13.stop();
1812
+ return _context14.stop();
1744
1813
  }
1745
- }, _callee13, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
1814
+ }, _callee14, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
1746
1815
  }));
1747
- function upsertLocalDraftOrders(_x10) {
1816
+ function upsertLocalDraftOrders(_x11) {
1748
1817
  return _upsertLocalDraftOrders.apply(this, arguments);
1749
1818
  }
1750
1819
  return upsertLocalDraftOrders;
@@ -1756,42 +1825,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1756
1825
  }, {
1757
1826
  key: "fetchOrdersBySSE",
1758
1827
  value: (function () {
1759
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1828
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1760
1829
  var query,
1761
1830
  data,
1762
- _args14 = arguments;
1763
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1764
- while (1) switch (_context14.prev = _context14.next) {
1831
+ _args15 = arguments;
1832
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1833
+ while (1) switch (_context15.prev = _context15.next) {
1765
1834
  case 0:
1766
- query = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
1835
+ query = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
1767
1836
  if (this.orderDataSource) {
1768
- _context14.next = 3;
1837
+ _context15.next = 3;
1769
1838
  break;
1770
1839
  }
1771
- return _context14.abrupt("return", []);
1840
+ return _context15.abrupt("return", []);
1772
1841
  case 3:
1773
- _context14.prev = 3;
1774
- _context14.next = 6;
1842
+ _context15.prev = 3;
1843
+ _context15.next = 6;
1775
1844
  return this.orderDataSource.run({
1776
1845
  sse: {
1777
1846
  query: query
1778
1847
  }
1779
1848
  });
1780
1849
  case 6:
1781
- data = _context14.sent;
1782
- return _context14.abrupt("return", data || []);
1850
+ data = _context15.sent;
1851
+ return _context15.abrupt("return", data || []);
1783
1852
  case 10:
1784
- _context14.prev = 10;
1785
- _context14.t0 = _context14["catch"](3);
1853
+ _context15.prev = 10;
1854
+ _context15.t0 = _context15["catch"](3);
1786
1855
  this.logError('fetchOrdersBySSE-失败', {
1787
- error: _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0)
1856
+ error: _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0)
1788
1857
  });
1789
- return _context14.abrupt("return", []);
1858
+ return _context15.abrupt("return", []);
1790
1859
  case 14:
1791
1860
  case "end":
1792
- return _context14.stop();
1861
+ return _context15.stop();
1793
1862
  }
1794
- }, _callee14, this, [[3, 10]]);
1863
+ }, _callee15, this, [[3, 10]]);
1795
1864
  }));
1796
1865
  function fetchOrdersBySSE() {
1797
1866
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -1824,19 +1893,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1824
1893
  return _this11.shouldKeepOrderInMemory(order);
1825
1894
  });
1826
1895
  this.store.map.clear();
1827
- var _iterator11 = _createForOfIteratorHelper(this.store.list),
1828
- _step11;
1896
+ var _iterator12 = _createForOfIteratorHelper(this.store.list),
1897
+ _step12;
1829
1898
  try {
1830
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1831
- var order = _step11.value;
1899
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1900
+ var order = _step12.value;
1832
1901
  var primaryIdentity = this.getOrderMapKey(order);
1833
1902
  if (!primaryIdentity) continue;
1834
1903
  this.store.map.set(primaryIdentity, order);
1835
1904
  }
1836
1905
  } catch (err) {
1837
- _iterator11.e(err);
1906
+ _iterator12.e(err);
1838
1907
  } finally {
1839
- _iterator11.f();
1908
+ _iterator12.f();
1840
1909
  }
1841
1910
  }
1842
1911
  }, {
@@ -1917,17 +1986,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1917
1986
  key: "getOrderIdentityKeys",
1918
1987
  value: function getOrderIdentityKeys(order) {
1919
1988
  var keys = [];
1920
- var _iterator12 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1921
- _step12;
1989
+ var _iterator13 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1990
+ _step13;
1922
1991
  try {
1923
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1924
- var entry = _step12.value;
1992
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1993
+ var entry = _step13.value;
1925
1994
  if (!keys.includes(entry.key)) keys.push(entry.key);
1926
1995
  }
1927
1996
  } catch (err) {
1928
- _iterator12.e(err);
1997
+ _iterator13.e(err);
1929
1998
  } finally {
1930
- _iterator12.f();
1999
+ _iterator13.f();
1931
2000
  }
1932
2001
  return keys;
1933
2002
  }
@@ -2027,41 +2096,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2027
2096
  }, {
2028
2097
  key: "flushOrderSyncMessagesByThrottle",
2029
2098
  value: (function () {
2030
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
2031
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
2032
- while (1) switch (_context15.prev = _context15.next) {
2099
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2100
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2101
+ while (1) switch (_context16.prev = _context16.next) {
2033
2102
  case 0:
2034
2103
  if (!this.isProcessingSyncBatch) {
2035
- _context15.next = 2;
2104
+ _context16.next = 2;
2036
2105
  break;
2037
2106
  }
2038
- return _context15.abrupt("return");
2107
+ return _context16.abrupt("return");
2039
2108
  case 2:
2040
2109
  if (!(this.pendingSyncMessages.length === 0)) {
2041
- _context15.next = 5;
2110
+ _context16.next = 5;
2042
2111
  break;
2043
2112
  }
2044
2113
  this.isIdlePhase = true;
2045
- return _context15.abrupt("return");
2114
+ return _context16.abrupt("return");
2046
2115
  case 5:
2047
2116
  this.isProcessingSyncBatch = true;
2048
- _context15.prev = 6;
2049
- _context15.next = 9;
2117
+ _context16.prev = 6;
2118
+ _context16.next = 9;
2050
2119
  return this.processOrderSyncMessages();
2051
2120
  case 9:
2052
- _context15.prev = 9;
2121
+ _context16.prev = 9;
2053
2122
  this.isProcessingSyncBatch = false;
2054
2123
  if (this.pendingSyncMessages.length > 0) {
2055
2124
  this.scheduleOrderSyncThrottle();
2056
2125
  } else {
2057
2126
  this.isIdlePhase = true;
2058
2127
  }
2059
- return _context15.finish(9);
2128
+ return _context16.finish(9);
2060
2129
  case 13:
2061
2130
  case "end":
2062
- return _context15.stop();
2131
+ return _context16.stop();
2063
2132
  }
2064
- }, _callee15, this, [[6,, 9, 13]]);
2133
+ }, _callee16, this, [[6,, 9, 13]]);
2065
2134
  }));
2066
2135
  function flushOrderSyncMessagesByThrottle() {
2067
2136
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -2083,19 +2152,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2083
2152
  }, {
2084
2153
  key: "processOrderSyncMessages",
2085
2154
  value: (function () {
2086
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2155
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2087
2156
  var _this15 = this;
2088
2157
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2089
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2090
- while (1) switch (_context16.prev = _context16.next) {
2158
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2159
+ while (1) switch (_context17.prev = _context17.next) {
2091
2160
  case 0:
2092
2161
  messages = _toConsumableArray(this.pendingSyncMessages);
2093
2162
  this.pendingSyncMessages = [];
2094
2163
  if (!(messages.length === 0)) {
2095
- _context16.next = 4;
2164
+ _context17.next = 4;
2096
2165
  break;
2097
2166
  }
2098
- return _context16.abrupt("return");
2167
+ return _context17.abrupt("return");
2099
2168
  case 4:
2100
2169
  batchProcessStartAt = Date.now();
2101
2170
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -2129,41 +2198,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2129
2198
  refreshIdCount: uniqueRefreshIds.length
2130
2199
  });
2131
2200
  if (!(upsertList.length > 0)) {
2132
- _context16.next = 16;
2201
+ _context17.next = 16;
2133
2202
  break;
2134
2203
  }
2135
- _context16.next = 16;
2204
+ _context17.next = 16;
2136
2205
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
2137
2206
  case 16:
2138
2207
  if (!(uniqueRefreshIds.length > 0)) {
2139
- _context16.next = 28;
2208
+ _context17.next = 28;
2140
2209
  break;
2141
2210
  }
2142
2211
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
2143
2212
  if (skipped.length > 0) {}
2144
2213
  if (!(toFetch.length > 0)) {
2145
- _context16.next = 28;
2214
+ _context17.next = 28;
2146
2215
  break;
2147
2216
  }
2148
- _context16.next = 22;
2217
+ _context17.next = 22;
2149
2218
  return this.fetchOrdersByHttp(toFetch);
2150
2219
  case 22:
2151
- freshOrders = _context16.sent;
2220
+ freshOrders = _context17.sent;
2152
2221
  if (!(freshOrders.length > 0)) {
2153
- _context16.next = 28;
2222
+ _context17.next = 28;
2154
2223
  break;
2155
2224
  }
2156
- _context16.next = 26;
2225
+ _context17.next = 26;
2157
2226
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
2158
2227
  case 26:
2159
- _context16.next = 28;
2228
+ _context17.next = 28;
2160
2229
  break;
2161
2230
  case 28:
2162
2231
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
2163
- _context16.next = 30;
2232
+ _context17.next = 30;
2164
2233
  break;
2165
2234
  }
2166
- return _context16.abrupt("return");
2235
+ return _context17.abrupt("return");
2167
2236
  case 30:
2168
2237
  batchProcessEndAt = Date.now();
2169
2238
  this.logInfo('processOrderSyncMessages-结束', {
@@ -2172,13 +2241,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2172
2241
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
2173
2242
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
2174
2243
  });
2175
- _context16.next = 34;
2244
+ _context17.next = 34;
2176
2245
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
2177
2246
  case 34:
2178
2247
  case "end":
2179
- return _context16.stop();
2248
+ return _context17.stop();
2180
2249
  }
2181
- }, _callee16, this);
2250
+ }, _callee17, this);
2182
2251
  }));
2183
2252
  function processOrderSyncMessages() {
2184
2253
  return _processOrderSyncMessages.apply(this, arguments);
@@ -2199,29 +2268,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2199
2268
  }, {
2200
2269
  key: "fetchOrdersByHttp",
2201
2270
  value: (function () {
2202
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(ids) {
2271
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
2203
2272
  var _orderList, orderList;
2204
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2205
- while (1) switch (_context17.prev = _context17.next) {
2273
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2274
+ while (1) switch (_context18.prev = _context18.next) {
2206
2275
  case 0:
2207
2276
  if (!(!this.orderDataSource || ids.length === 0)) {
2208
- _context17.next = 2;
2277
+ _context18.next = 2;
2209
2278
  break;
2210
2279
  }
2211
- return _context17.abrupt("return", []);
2280
+ return _context18.abrupt("return", []);
2212
2281
  case 2:
2213
- _context17.prev = 2;
2282
+ _context18.prev = 2;
2214
2283
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
2215
- _context17.next = 8;
2284
+ _context18.next = 8;
2216
2285
  break;
2217
2286
  }
2218
- _context17.next = 6;
2287
+ _context18.next = 6;
2219
2288
  return this.orderDataSource.fetchOrdersByIds(ids);
2220
2289
  case 6:
2221
- _orderList = _context17.sent;
2222
- return _context17.abrupt("return", _orderList || []);
2290
+ _orderList = _context18.sent;
2291
+ return _context18.abrupt("return", _orderList || []);
2223
2292
  case 8:
2224
- _context17.next = 10;
2293
+ _context18.next = 10;
2225
2294
  return this.orderDataSource.run({
2226
2295
  http: {
2227
2296
  query: {
@@ -2230,19 +2299,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2230
2299
  }
2231
2300
  });
2232
2301
  case 10:
2233
- orderList = _context17.sent;
2234
- return _context17.abrupt("return", orderList || []);
2302
+ orderList = _context18.sent;
2303
+ return _context18.abrupt("return", orderList || []);
2235
2304
  case 14:
2236
- _context17.prev = 14;
2237
- _context17.t0 = _context17["catch"](2);
2238
- return _context17.abrupt("return", []);
2305
+ _context18.prev = 14;
2306
+ _context18.t0 = _context18["catch"](2);
2307
+ return _context18.abrupt("return", []);
2239
2308
  case 17:
2240
2309
  case "end":
2241
- return _context17.stop();
2310
+ return _context18.stop();
2242
2311
  }
2243
- }, _callee17, this, [[2, 14]]);
2312
+ }, _callee18, this, [[2, 14]]);
2244
2313
  }));
2245
- function fetchOrdersByHttp(_x11) {
2314
+ function fetchOrdersByHttp(_x12) {
2246
2315
  return _fetchOrdersByHttp.apply(this, arguments);
2247
2316
  }
2248
2317
  return fetchOrdersByHttp;
@@ -2254,11 +2323,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2254
2323
  }, {
2255
2324
  key: "mergeOrdersToStore",
2256
2325
  value: (function () {
2257
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(freshOrders, source) {
2326
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
2258
2327
  var _this16 = this;
2259
- var storeOrderCountBefore, normalizedFreshOrders, _iterator13, _step13, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator14, _step14, key, _iterator15, _step15, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _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, adjustedMatchIndex, duplicateIndexes, _iterator16, _step16, _key2, _duplicateIndex, _iterator17, _step17, duplicateIndex, _index, _iterator18, _step18, _key, insertIndex, insertCount, updateCount;
2260
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2261
- while (1) switch (_context18.prev = _context18.next) {
2328
+ var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator14, _step14, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator15, _step15, key, _iterator16, _step16, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _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, _iterator17, _step17, _key2, _duplicateIndex, _iterator18, _step18, duplicateIndex, _index, _iterator19, _step19, _key, mergedStorageKey, insertIndex, insertCount, updateCount;
2329
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2330
+ while (1) switch (_context19.prev = _context19.next) {
2262
2331
  case 0:
2263
2332
  storeOrderCountBefore = this.store.list.length;
2264
2333
  this.logInfo('mergeOrdersToStore-开始', {
@@ -2268,43 +2337,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2268
2337
  });
2269
2338
  this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
2270
2339
  normalizedFreshOrders = [];
2271
- _iterator13 = _createForOfIteratorHelper(freshOrders);
2272
- _context18.prev = 5;
2273
- _iterator13.s();
2274
- case 7:
2275
- if ((_step13 = _iterator13.n()).done) {
2276
- _context18.next = 15;
2340
+ incomingProductsHaveStableIdentity = new Map();
2341
+ _iterator14 = _createForOfIteratorHelper(freshOrders);
2342
+ _context19.prev = 6;
2343
+ _iterator14.s();
2344
+ case 8:
2345
+ if ((_step14 = _iterator14.n()).done) {
2346
+ _context19.next = 18;
2277
2347
  break;
2278
2348
  }
2279
- order = _step13.value;
2349
+ order = _step14.value;
2280
2350
  id = order === null || order === void 0 ? void 0 : order.order_id;
2281
2351
  if (!(id === undefined || id === null)) {
2282
- _context18.next = 12;
2352
+ _context19.next = 13;
2283
2353
  break;
2284
2354
  }
2285
- return _context18.abrupt("continue", 13);
2286
- case 12:
2287
- normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2355
+ return _context19.abrupt("continue", 16);
2288
2356
  case 13:
2289
- _context18.next = 7;
2357
+ rawProducts = order.products;
2358
+ if (Array.isArray(rawProducts)) {
2359
+ allProductsHaveStableIdentity = this.doProductsHaveStableMembershipIdentity(rawProducts);
2360
+ orderIdKey = this.getIdKey(id);
2361
+ incomingProductsHaveStableIdentity.set(orderIdKey, ((_incomingProductsHave = incomingProductsHaveStableIdentity.get(orderIdKey)) !== null && _incomingProductsHave !== void 0 ? _incomingProductsHave : true) && allProductsHaveStableIdentity);
2362
+ }
2363
+ normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2364
+ case 16:
2365
+ _context19.next = 8;
2290
2366
  break;
2291
- case 15:
2292
- _context18.next = 20;
2367
+ case 18:
2368
+ _context19.next = 23;
2293
2369
  break;
2294
- case 17:
2295
- _context18.prev = 17;
2296
- _context18.t0 = _context18["catch"](5);
2297
- _iterator13.e(_context18.t0);
2298
2370
  case 20:
2299
- _context18.prev = 20;
2300
- _iterator13.f();
2301
- return _context18.finish(20);
2371
+ _context19.prev = 20;
2372
+ _context19.t0 = _context19["catch"](6);
2373
+ _iterator14.e(_context19.t0);
2302
2374
  case 23:
2375
+ _context19.prev = 23;
2376
+ _iterator14.f();
2377
+ return _context19.finish(23);
2378
+ case 26:
2303
2379
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2304
2380
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
2305
2381
  uniqueFreshCount = uniqueFreshOrders.length;
2306
2382
  patchedOrders = [];
2383
+ remoteProductMembershipChanges = [];
2384
+ forceWriteStorageKeys = new Set();
2307
2385
  mergeActions = {};
2386
+ existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2387
+ return _this16.doProductsHaveStableMembershipIdentity(order.products);
2388
+ });
2308
2389
  updatedList = this.store.list.map(function (order) {
2309
2390
  return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2310
2391
  }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
@@ -2313,39 +2394,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2313
2394
  identityKeyToIndex = new Map();
2314
2395
  for (index = 0; index < updatedList.length; index += 1) {
2315
2396
  identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
2316
- _iterator14 = _createForOfIteratorHelper(identityKeys);
2397
+ _iterator15 = _createForOfIteratorHelper(identityKeys);
2317
2398
  try {
2318
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2319
- key = _step14.value;
2399
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2400
+ key = _step15.value;
2320
2401
  // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
2321
2402
  if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
2322
2403
  }
2323
2404
  } catch (err) {
2324
- _iterator14.e(err);
2405
+ _iterator15.e(err);
2325
2406
  } finally {
2326
- _iterator14.f();
2407
+ _iterator15.f();
2327
2408
  }
2328
2409
  }
2329
- _iterator15 = _createForOfIteratorHelper(uniqueFreshOrders);
2330
- _context18.prev = 31;
2331
- _iterator15.s();
2332
- case 33:
2333
- if ((_step15 = _iterator15.n()).done) {
2334
- _context18.next = 82;
2410
+ _iterator16 = _createForOfIteratorHelper(uniqueFreshOrders);
2411
+ _context19.prev = 37;
2412
+ _iterator16.s();
2413
+ case 39:
2414
+ if ((_step16 = _iterator16.n()).done) {
2415
+ _context19.next = 96;
2335
2416
  break;
2336
2417
  }
2337
- fresh = _step15.value;
2418
+ fresh = _step16.value;
2338
2419
  freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
2339
2420
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
2340
2421
  storageKey = this.getOrderStorageKey(fresh);
2341
2422
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2342
2423
  if (!(matchIndex >= 0)) {
2343
- _context18.next = 75;
2424
+ _context19.next = 88;
2344
2425
  break;
2345
2426
  }
2346
2427
  existingOrder = updatedList[matchIndex];
2347
2428
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2348
- _context18.next = 44;
2429
+ _context19.next = 50;
2349
2430
  break;
2350
2431
  }
2351
2432
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2358,10 +2439,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2358
2439
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2359
2440
  reason: 'protect_pending_sync_order_from_remote_echo'
2360
2441
  });
2361
- return _context18.abrupt("continue", 80);
2362
- case 44:
2442
+ return _context19.abrupt("continue", 94);
2443
+ case 50:
2363
2444
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2364
- _context18.next = 47;
2445
+ _context19.next = 53;
2365
2446
  break;
2366
2447
  }
2367
2448
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2372,102 +2453,118 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2372
2453
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2373
2454
  reason: 'protect_draft_order_from_remote_echo'
2374
2455
  });
2375
- return _context18.abrupt("continue", 80);
2376
- case 47:
2456
+ return _context19.abrupt("continue", 94);
2457
+ case 53:
2377
2458
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2459
+ freshOrderId = fresh.order_id;
2460
+ incomingProductsAreStable = freshOrderId !== undefined && freshOrderId !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(freshOrderId)) !== false;
2461
+ membershipChange = null;
2462
+ if (Array.isArray(fresh.products) && freshOrderId !== undefined && freshOrderId !== null && existingProductsHaveStableIdentity[matchIndex] !== false && incomingProductsAreStable) {
2463
+ membershipChange = this.getRemoteProductMembershipChange(existingOrder, mergedOrder, source);
2464
+ }
2465
+ mergedProductsHaveStableIdentity = existingProductsHaveStableIdentity[matchIndex] !== false && incomingProductsAreStable;
2378
2466
  adjustedMatchIndex = matchIndex;
2379
2467
  duplicateIndexes = new Set();
2380
- _iterator16 = _createForOfIteratorHelper(freshIdentityKeys);
2381
- _context18.prev = 51;
2382
- _iterator16.s();
2383
- case 53:
2384
- if ((_step16 = _iterator16.n()).done) {
2385
- _context18.next = 61;
2468
+ _iterator17 = _createForOfIteratorHelper(freshIdentityKeys);
2469
+ _context19.prev = 62;
2470
+ _iterator17.s();
2471
+ case 64:
2472
+ if ((_step17 = _iterator17.n()).done) {
2473
+ _context19.next = 72;
2386
2474
  break;
2387
2475
  }
2388
- _key2 = _step16.value;
2476
+ _key2 = _step17.value;
2389
2477
  _duplicateIndex = identityKeyToIndex.get(_key2);
2390
2478
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2391
- _context18.next = 58;
2479
+ _context19.next = 69;
2392
2480
  break;
2393
2481
  }
2394
- return _context18.abrupt("continue", 59);
2395
- case 58:
2482
+ return _context19.abrupt("continue", 70);
2483
+ case 69:
2396
2484
  duplicateIndexes.add(_duplicateIndex);
2397
- case 59:
2398
- _context18.next = 53;
2485
+ case 70:
2486
+ _context19.next = 64;
2399
2487
  break;
2400
- case 61:
2401
- _context18.next = 66;
2488
+ case 72:
2489
+ _context19.next = 77;
2402
2490
  break;
2403
- case 63:
2404
- _context18.prev = 63;
2405
- _context18.t1 = _context18["catch"](51);
2406
- _iterator16.e(_context18.t1);
2407
- case 66:
2408
- _context18.prev = 66;
2409
- _iterator16.f();
2410
- return _context18.finish(66);
2411
- case 69:
2491
+ case 74:
2492
+ _context19.prev = 74;
2493
+ _context19.t1 = _context19["catch"](62);
2494
+ _iterator17.e(_context19.t1);
2495
+ case 77:
2496
+ _context19.prev = 77;
2497
+ _iterator17.f();
2498
+ return _context19.finish(77);
2499
+ case 80:
2412
2500
  if (duplicateIndexes.size > 0) {
2413
- _iterator17 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
2501
+ _iterator18 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
2414
2502
  return right - left;
2415
2503
  }));
2416
2504
  try {
2417
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2418
- duplicateIndex = _step17.value;
2505
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2506
+ duplicateIndex = _step18.value;
2419
2507
  mergedOrder = this.mergeOrderRecords(mergedOrder, updatedList[duplicateIndex]);
2508
+ mergedProductsHaveStableIdentity = mergedProductsHaveStableIdentity && existingProductsHaveStableIdentity[duplicateIndex] !== false;
2420
2509
  updatedList.splice(duplicateIndex, 1);
2510
+ existingProductsHaveStableIdentity.splice(duplicateIndex, 1);
2421
2511
  if (duplicateIndex < adjustedMatchIndex) adjustedMatchIndex -= 1;
2422
2512
  }
2423
2513
  } catch (err) {
2424
- _iterator17.e(err);
2514
+ _iterator18.e(err);
2425
2515
  } finally {
2426
- _iterator17.f();
2516
+ _iterator18.f();
2427
2517
  }
2428
2518
  identityKeyToIndex.clear();
2429
2519
  for (_index = 0; _index < updatedList.length; _index += 1) {
2430
- _iterator18 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
2520
+ _iterator19 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
2431
2521
  try {
2432
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2433
- _key = _step18.value;
2522
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2523
+ _key = _step19.value;
2434
2524
  if (!identityKeyToIndex.has(_key)) identityKeyToIndex.set(_key, _index);
2435
2525
  }
2436
2526
  } catch (err) {
2437
- _iterator18.e(err);
2527
+ _iterator19.e(err);
2438
2528
  } finally {
2439
- _iterator18.f();
2529
+ _iterator19.f();
2440
2530
  }
2441
2531
  }
2442
2532
  }
2443
2533
  updatedList[adjustedMatchIndex] = mergedOrder;
2534
+ existingProductsHaveStableIdentity[adjustedMatchIndex] = mergedProductsHaveStableIdentity;
2535
+ if (membershipChange) {
2536
+ remoteProductMembershipChanges.push(membershipChange);
2537
+ mergedStorageKey = this.getOrderStorageKey(mergedOrder);
2538
+ if (mergedStorageKey) forceWriteStorageKeys.add(mergedStorageKey);
2539
+ }
2444
2540
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
2445
2541
  // 供同批后续 fresh 命中同一槽位,避免重复插入
2446
2542
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2447
2543
  patchedOrders.push(mergedOrder);
2448
2544
  if (mergeKey) mergeActions[mergeKey] = 'update';
2449
- return _context18.abrupt("continue", 80);
2450
- case 75:
2545
+ return _context19.abrupt("continue", 94);
2546
+ case 88:
2451
2547
  insertIndex = updatedList.length;
2452
2548
  updatedList.push(fresh);
2549
+ existingProductsHaveStableIdentity.push(fresh.order_id !== undefined && fresh.order_id !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(fresh.order_id)) !== false);
2453
2550
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
2454
2551
  patchedOrders.push(fresh);
2455
2552
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2456
- case 80:
2457
- _context18.next = 33;
2553
+ case 94:
2554
+ _context19.next = 39;
2458
2555
  break;
2459
- case 82:
2460
- _context18.next = 87;
2556
+ case 96:
2557
+ _context19.next = 101;
2461
2558
  break;
2462
- case 84:
2463
- _context18.prev = 84;
2464
- _context18.t2 = _context18["catch"](31);
2465
- _iterator15.e(_context18.t2);
2466
- case 87:
2467
- _context18.prev = 87;
2468
- _iterator15.f();
2469
- return _context18.finish(87);
2470
- case 90:
2559
+ case 98:
2560
+ _context19.prev = 98;
2561
+ _context19.t2 = _context19["catch"](37);
2562
+ _iterator16.e(_context19.t2);
2563
+ case 101:
2564
+ _context19.prev = 101;
2565
+ _iterator16.f();
2566
+ return _context19.finish(101);
2567
+ case 104:
2471
2568
  insertCount = Object.values(mergeActions).filter(function (v) {
2472
2569
  return v === 'insert';
2473
2570
  }).length;
@@ -2483,24 +2580,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2483
2580
  // 仅在自检开关开启时做一次兜底校验。
2484
2581
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2485
2582
  this.syncOrdersMap();
2486
- _context18.next = 97;
2487
- return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
2488
- case 97:
2583
+ _context19.next = 111;
2584
+ return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {}, forceWriteStorageKeys);
2585
+ case 111:
2489
2586
  this.logInfo('mergeOrdersToStore-结束', {
2490
2587
  uniqueFreshCount: uniqueFreshCount,
2491
2588
  storeOrderCountAfter: this.store.list.length,
2492
2589
  insertCount: insertCount,
2493
2590
  updateCount: updateCount
2494
2591
  });
2495
- _context18.next = 100;
2592
+ _context19.next = 114;
2593
+ return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2594
+ case 114:
2595
+ _context19.next = 116;
2496
2596
  return this.emitOrdersChanged(patchedOrders, source);
2497
- case 100:
2597
+ case 116:
2498
2598
  case "end":
2499
- return _context18.stop();
2599
+ return _context19.stop();
2500
2600
  }
2501
- }, _callee18, this, [[5, 17, 20, 23], [31, 84, 87, 90], [51, 63, 66, 69]]);
2601
+ }, _callee19, this, [[6, 20, 23, 26], [37, 98, 101, 104], [62, 74, 77, 80]]);
2502
2602
  }));
2503
- function mergeOrdersToStore(_x12, _x13) {
2603
+ function mergeOrdersToStore(_x13, _x14) {
2504
2604
  return _mergeOrdersToStore.apply(this, arguments);
2505
2605
  }
2506
2606
  return mergeOrdersToStore;
@@ -2517,19 +2617,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2517
2617
  key: "lookupOrderIndexByIdentityKeys",
2518
2618
  value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
2519
2619
  var matchIndex = -1;
2520
- var _iterator19 = _createForOfIteratorHelper(identityKeys),
2521
- _step19;
2620
+ var _iterator20 = _createForOfIteratorHelper(identityKeys),
2621
+ _step20;
2522
2622
  try {
2523
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2524
- var key = _step19.value;
2623
+ for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
2624
+ var key = _step20.value;
2525
2625
  var index = identityKeyToIndex.get(key);
2526
2626
  if (index === undefined) continue;
2527
2627
  if (matchIndex < 0 || index < matchIndex) matchIndex = index;
2528
2628
  }
2529
2629
  } catch (err) {
2530
- _iterator19.e(err);
2630
+ _iterator20.e(err);
2531
2631
  } finally {
2532
- _iterator19.f();
2632
+ _iterator20.f();
2533
2633
  }
2534
2634
  return matchIndex;
2535
2635
  }
@@ -2538,6 +2638,92 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2538
2638
  value: function isRemoteEchoMergeSource(source) {
2539
2639
  return source === 'pubsub.bodyUpsert' || source === 'pubsub.httpRefresh';
2540
2640
  }
2641
+ }, {
2642
+ key: "getProductMembershipKey",
2643
+ value: function getProductMembershipKey(product) {
2644
+ var persistentId = getOrderCollectionPersistentId('product', product);
2645
+ if (persistentId) return "order_detail_id:".concat(persistentId);
2646
+ var uid = getOrderCollectionUid('product', product);
2647
+ return uid ? "unique_identification_number:".concat(uid) : '';
2648
+ }
2649
+ }, {
2650
+ key: "doProductsHaveStableMembershipIdentity",
2651
+ value: function doProductsHaveStableMembershipIdentity(products) {
2652
+ if (!Array.isArray(products)) return true;
2653
+ return products.every(function (product) {
2654
+ return Boolean(getOrderCollectionPersistentId('product', product) || getOrderCollectionUid('product', product));
2655
+ });
2656
+ }
2657
+
2658
+ /**
2659
+ * 冲突提示关注逻辑商品行,而不是服务端 checkout 过程中可能被重建的 detail 记录。
2660
+ * 通用集合合并仍以 order_detail_id 为事实主键;这里只允许相同稳定 UID 跨 detail id 对齐,
2661
+ * 避免本机 checkout 回声被误判成“一删一增”。
2662
+ */
2663
+ }, {
2664
+ key: "isSameProductMembershipItem",
2665
+ value: function isSameProductMembershipItem(left, right) {
2666
+ if (isSameOrderCollectionItem('product', left, right)) return true;
2667
+ var leftUid = getOrderCollectionUid('product', left);
2668
+ var rightUid = getOrderCollectionUid('product', right);
2669
+ return Boolean(leftUid && rightUid && leftUid === rightUid);
2670
+ }
2671
+
2672
+ /**
2673
+ * 对比合并前后的商品成员集合。商品字段修改与数组重排不会产生 diff。
2674
+ */
2675
+ }, {
2676
+ key: "getRemoteProductMembershipChange",
2677
+ value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
2678
+ var _this17 = this,
2679
+ _mergedOrder$order_id;
2680
+ if (!this.isRemoteEchoMergeSource(source)) return null;
2681
+ var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
2682
+ var currentProducts = Array.isArray(mergedOrder.products) ? mergedOrder.products : [];
2683
+ var unmatchedCurrentIndexes = new Set(currentProducts.map(function (_, index) {
2684
+ return index;
2685
+ }));
2686
+ var removedProductKeys = [];
2687
+ var _iterator21 = _createForOfIteratorHelper(previousProducts),
2688
+ _step21;
2689
+ try {
2690
+ var _loop2 = function _loop2() {
2691
+ var previousProduct = _step21.value;
2692
+ var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
2693
+ return unmatchedCurrentIndexes.has(index) && _this17.isSameProductMembershipItem(previousProduct, currentProduct);
2694
+ });
2695
+ if (matchedIndex >= 0) {
2696
+ unmatchedCurrentIndexes.delete(matchedIndex);
2697
+ return 1; // continue
2698
+ }
2699
+ var productKey = _this17.getProductMembershipKey(previousProduct);
2700
+ if (productKey) removedProductKeys.push(productKey);
2701
+ };
2702
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2703
+ if (_loop2()) continue;
2704
+ }
2705
+ } catch (err) {
2706
+ _iterator21.e(err);
2707
+ } finally {
2708
+ _iterator21.f();
2709
+ }
2710
+ var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
2711
+ return _this17.getProductMembershipKey(currentProducts[index]);
2712
+ }).filter(Boolean);
2713
+ if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
2714
+ return null;
2715
+ }
2716
+ var orderId = (_mergedOrder$order_id = mergedOrder.order_id) !== null && _mergedOrder$order_id !== void 0 ? _mergedOrder$order_id : existingOrder.order_id;
2717
+ if (orderId === undefined || orderId === null) return null;
2718
+ return {
2719
+ order_id: orderId,
2720
+ source: source,
2721
+ added_product_keys: addedProductKeys,
2722
+ removed_product_keys: removedProductKeys,
2723
+ previous_product_count: previousProducts.length,
2724
+ current_product_count: currentProducts.length
2725
+ };
2726
+ }
2541
2727
 
2542
2728
  /**
2543
2729
  * 将订单的全部身份键登记到索引并指向其在列表中的下标。
@@ -2550,17 +2736,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2550
2736
  key: "registerOrderIdentityKeys",
2551
2737
  value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
2552
2738
  var identityKeys = this.getOrderIdentityMatchKeys(order);
2553
- var _iterator20 = _createForOfIteratorHelper(identityKeys),
2554
- _step20;
2739
+ var _iterator22 = _createForOfIteratorHelper(identityKeys),
2740
+ _step22;
2555
2741
  try {
2556
- for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
2557
- var key = _step20.value;
2742
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
2743
+ var key = _step22.value;
2558
2744
  identityKeyToIndex.set(key, index);
2559
2745
  }
2560
2746
  } catch (err) {
2561
- _iterator20.e(err);
2747
+ _iterator22.e(err);
2562
2748
  } finally {
2563
- _iterator20.f();
2749
+ _iterator22.f();
2564
2750
  }
2565
2751
  }
2566
2752
 
@@ -2615,17 +2801,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2615
2801
  key: "uniqueOrderIds",
2616
2802
  value: function uniqueOrderIds(ids) {
2617
2803
  var idMap = new Map();
2618
- var _iterator21 = _createForOfIteratorHelper(ids),
2619
- _step21;
2804
+ var _iterator23 = _createForOfIteratorHelper(ids),
2805
+ _step23;
2620
2806
  try {
2621
- for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2622
- var id = _step21.value;
2807
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
2808
+ var id = _step23.value;
2623
2809
  idMap.set(this.getIdKey(id), id);
2624
2810
  }
2625
2811
  } catch (err) {
2626
- _iterator21.e(err);
2812
+ _iterator23.e(err);
2627
2813
  } finally {
2628
- _iterator21.f();
2814
+ _iterator23.f();
2629
2815
  }
2630
2816
  return _toConsumableArray(idMap.values());
2631
2817
  }
@@ -2637,12 +2823,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2637
2823
  }, {
2638
2824
  key: "isOrderLookupMatch",
2639
2825
  value: function isOrderLookupMatch(order, lookupKey) {
2640
- var _this17 = this;
2826
+ var _this18 = this;
2641
2827
  if (!order || !lookupKey) return false;
2642
2828
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
2643
2829
  return candidates.some(function (value) {
2644
2830
  if (value === undefined || value === null || value === '') return false;
2645
- return _this17.getIdKey(value) === lookupKey;
2831
+ return _this18.getIdKey(value) === lookupKey;
2646
2832
  });
2647
2833
  }
2648
2834
 
@@ -2685,10 +2871,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2685
2871
  }, {
2686
2872
  key: "findOrderIndexByIdentity",
2687
2873
  value: function findOrderIndexByIdentity(orders, target) {
2688
- var _this18 = this;
2874
+ var _this19 = this;
2689
2875
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
2690
2876
  return orders.findIndex(function (order) {
2691
- return _this18.doOrdersShareIdentity(order, target);
2877
+ return _this19.doOrdersShareIdentity(order, target);
2692
2878
  });
2693
2879
  }
2694
2880
  }, {
@@ -2737,58 +2923,58 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2737
2923
  if (secondaryList.length === 0) return preferredList;
2738
2924
  if (preferredList.length === 0) return secondaryList;
2739
2925
  var seenKeys = new Set();
2740
- var _iterator22 = _createForOfIteratorHelper(preferredList),
2741
- _step22;
2926
+ var _iterator24 = _createForOfIteratorHelper(preferredList),
2927
+ _step24;
2742
2928
  try {
2743
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
2744
- var item = _step22.value;
2929
+ for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
2930
+ var item = _step24.value;
2745
2931
  var keys = this.getProductIdentityKeys(item);
2746
- var _iterator24 = _createForOfIteratorHelper(keys),
2747
- _step24;
2932
+ var _iterator26 = _createForOfIteratorHelper(keys),
2933
+ _step26;
2748
2934
  try {
2749
- for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
2750
- var key = _step24.value;
2935
+ for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
2936
+ var key = _step26.value;
2751
2937
  seenKeys.add(key);
2752
2938
  }
2753
2939
  } catch (err) {
2754
- _iterator24.e(err);
2940
+ _iterator26.e(err);
2755
2941
  } finally {
2756
- _iterator24.f();
2942
+ _iterator26.f();
2757
2943
  }
2758
2944
  }
2759
2945
  } catch (err) {
2760
- _iterator22.e(err);
2946
+ _iterator24.e(err);
2761
2947
  } finally {
2762
- _iterator22.f();
2948
+ _iterator24.f();
2763
2949
  }
2764
2950
  var result = _toConsumableArray(preferredList);
2765
- var _iterator23 = _createForOfIteratorHelper(secondaryList),
2766
- _step23;
2951
+ var _iterator25 = _createForOfIteratorHelper(secondaryList),
2952
+ _step25;
2767
2953
  try {
2768
- for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
2769
- var _item = _step23.value;
2954
+ for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
2955
+ var _item = _step25.value;
2770
2956
  var _keys = this.getProductIdentityKeys(_item);
2771
2957
  if (_keys.length === 0 || _keys.some(function (key) {
2772
2958
  return seenKeys.has(key);
2773
2959
  })) continue;
2774
- var _iterator25 = _createForOfIteratorHelper(_keys),
2775
- _step25;
2960
+ var _iterator27 = _createForOfIteratorHelper(_keys),
2961
+ _step27;
2776
2962
  try {
2777
- for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
2778
- var _key3 = _step25.value;
2963
+ for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
2964
+ var _key3 = _step27.value;
2779
2965
  seenKeys.add(_key3);
2780
2966
  }
2781
2967
  } catch (err) {
2782
- _iterator25.e(err);
2968
+ _iterator27.e(err);
2783
2969
  } finally {
2784
- _iterator25.f();
2970
+ _iterator27.f();
2785
2971
  }
2786
2972
  result.push(cloneDeep(_item));
2787
2973
  }
2788
2974
  } catch (err) {
2789
- _iterator23.e(err);
2975
+ _iterator25.e(err);
2790
2976
  } finally {
2791
- _iterator23.f();
2977
+ _iterator25.f();
2792
2978
  }
2793
2979
  return result;
2794
2980
  }
@@ -2898,30 +3084,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2898
3084
  key: "summarizeDuplicateOrders",
2899
3085
  value: function summarizeDuplicateOrders(orders) {
2900
3086
  var groups = new Map();
2901
- var _iterator26 = _createForOfIteratorHelper(orders),
2902
- _step26;
3087
+ var _iterator28 = _createForOfIteratorHelper(orders),
3088
+ _step28;
2903
3089
  try {
2904
- for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
2905
- var order = _step26.value;
2906
- var _iterator27 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
2907
- _step27;
3090
+ for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
3091
+ var order = _step28.value;
3092
+ var _iterator29 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
3093
+ _step29;
2908
3094
  try {
2909
- for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
2910
- var key = _step27.value;
3095
+ for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3096
+ var key = _step29.value;
2911
3097
  var group = groups.get(key) || [];
2912
3098
  group.push(order);
2913
3099
  groups.set(key, group);
2914
3100
  }
2915
3101
  } catch (err) {
2916
- _iterator27.e(err);
3102
+ _iterator29.e(err);
2917
3103
  } finally {
2918
- _iterator27.f();
3104
+ _iterator29.f();
2919
3105
  }
2920
3106
  }
2921
3107
  } catch (err) {
2922
- _iterator26.e(err);
3108
+ _iterator28.e(err);
2923
3109
  } finally {
2924
- _iterator26.f();
3110
+ _iterator28.f();
2925
3111
  }
2926
3112
  return _toConsumableArray(groups.entries()).filter(function (_ref7) {
2927
3113
  var _ref8 = _slicedToArray(_ref7, 2),
@@ -2964,11 +3150,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2964
3150
  value: function compactOrderListByIdentity(orders, source) {
2965
3151
  var list = [];
2966
3152
  var removedCount = 0;
2967
- var _iterator28 = _createForOfIteratorHelper(orders),
2968
- _step28;
3153
+ var _iterator30 = _createForOfIteratorHelper(orders),
3154
+ _step30;
2969
3155
  try {
2970
- for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
2971
- var order = _step28.value;
3156
+ for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
3157
+ var order = _step30.value;
2972
3158
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
2973
3159
  var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
2974
3160
  if (matchIndex < 0) {
@@ -2979,9 +3165,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2979
3165
  removedCount += 1;
2980
3166
  }
2981
3167
  } catch (err) {
2982
- _iterator28.e(err);
3168
+ _iterator30.e(err);
2983
3169
  } finally {
2984
- _iterator28.f();
3170
+ _iterator30.f();
2985
3171
  }
2986
3172
  if (removedCount > 0) {
2987
3173
  this.logWarning('订单列表重复项已压缩', {
@@ -3079,35 +3265,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3079
3265
  }, {
3080
3266
  key: "loadOrdersFromSQLite",
3081
3267
  value: function () {
3082
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
3083
- var _this19 = this;
3268
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
3269
+ var _this20 = this;
3084
3270
  var orders;
3085
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
3086
- while (1) switch (_context19.prev = _context19.next) {
3271
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3272
+ while (1) switch (_context20.prev = _context20.next) {
3087
3273
  case 0:
3088
3274
  if (this.dbManager) {
3089
- _context19.next = 2;
3275
+ _context20.next = 2;
3090
3276
  break;
3091
3277
  }
3092
- return _context19.abrupt("return", []);
3278
+ return _context20.abrupt("return", []);
3093
3279
  case 2:
3094
- _context19.prev = 2;
3095
- _context19.next = 5;
3280
+ _context20.prev = 2;
3281
+ _context20.next = 5;
3096
3282
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3097
3283
  case 5:
3098
- orders = _context19.sent;
3099
- return _context19.abrupt("return", (orders || []).map(function (order) {
3100
- return _this19.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3284
+ orders = _context20.sent;
3285
+ return _context20.abrupt("return", (orders || []).map(function (order) {
3286
+ return _this20.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3101
3287
  }));
3102
3288
  case 9:
3103
- _context19.prev = 9;
3104
- _context19.t0 = _context19["catch"](2);
3105
- return _context19.abrupt("return", []);
3289
+ _context20.prev = 9;
3290
+ _context20.t0 = _context20["catch"](2);
3291
+ return _context20.abrupt("return", []);
3106
3292
  case 12:
3107
3293
  case "end":
3108
- return _context19.stop();
3294
+ return _context20.stop();
3109
3295
  }
3110
- }, _callee19, this, [[2, 9]]);
3296
+ }, _callee20, this, [[2, 9]]);
3111
3297
  }));
3112
3298
  function loadOrdersFromSQLite() {
3113
3299
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3157,15 +3343,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3157
3343
  }, {
3158
3344
  key: "mergeRemoteSnapshotWithPendingOrders",
3159
3345
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3160
- var _this20 = this;
3346
+ var _this21 = this;
3161
3347
  var merged = remoteOrders.map(function (order) {
3162
- return _this20.normalizeRemoteSyncedOrder(order);
3348
+ return _this21.normalizeRemoteSyncedOrder(order);
3163
3349
  });
3164
- var _iterator29 = _createForOfIteratorHelper(existingOrders),
3165
- _step29;
3350
+ var _iterator31 = _createForOfIteratorHelper(existingOrders),
3351
+ _step31;
3166
3352
  try {
3167
- for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
3168
- var rawOrder = _step29.value;
3353
+ for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) {
3354
+ var rawOrder = _step31.value;
3169
3355
  var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
3170
3356
  if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
3171
3357
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
@@ -3181,9 +3367,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3181
3367
  merged.push(order);
3182
3368
  }
3183
3369
  } catch (err) {
3184
- _iterator29.e(err);
3370
+ _iterator31.e(err);
3185
3371
  } finally {
3186
- _iterator29.f();
3372
+ _iterator31.f();
3187
3373
  }
3188
3374
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
3189
3375
  }
@@ -3199,10 +3385,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3199
3385
  }, {
3200
3386
  key: "runInOrderSQLiteSaveQueue",
3201
3387
  value: (function () {
3202
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(task) {
3388
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(task) {
3203
3389
  var queuedTask;
3204
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3205
- while (1) switch (_context20.prev = _context20.next) {
3390
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3391
+ while (1) switch (_context21.prev = _context21.next) {
3206
3392
  case 0:
3207
3393
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3208
3394
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3210,14 +3396,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3210
3396
  }, function () {
3211
3397
  return undefined;
3212
3398
  });
3213
- return _context20.abrupt("return", queuedTask);
3399
+ return _context21.abrupt("return", queuedTask);
3214
3400
  case 3:
3215
3401
  case "end":
3216
- return _context20.stop();
3402
+ return _context21.stop();
3217
3403
  }
3218
- }, _callee20, this);
3404
+ }, _callee21, this);
3219
3405
  }));
3220
- function runInOrderSQLiteSaveQueue(_x14) {
3406
+ function runInOrderSQLiteSaveQueue(_x15) {
3221
3407
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
3222
3408
  }
3223
3409
  return runInOrderSQLiteSaveQueue;
@@ -3232,141 +3418,143 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3232
3418
  }, {
3233
3419
  key: "patchOrdersInSQLite",
3234
3420
  value: (function () {
3235
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orders, source) {
3236
- var _this21 = this;
3421
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
3422
+ var _this22 = this;
3237
3423
  var mergeActions,
3238
3424
  options,
3425
+ forceWriteStorageKeys,
3239
3426
  ordersSnapshot,
3240
3427
  _this$filterRedundant2,
3241
3428
  toWrite,
3242
3429
  skipped,
3243
3430
  compactedToWrite,
3244
- _args22 = arguments;
3245
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3246
- while (1) switch (_context22.prev = _context22.next) {
3431
+ _args23 = arguments;
3432
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3433
+ while (1) switch (_context23.prev = _context23.next) {
3247
3434
  case 0:
3248
- mergeActions = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
3249
- options = _args22.length > 3 && _args22[3] !== undefined ? _args22[3] : {};
3435
+ mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
3436
+ options = _args23.length > 3 && _args23[3] !== undefined ? _args23[3] : {};
3437
+ forceWriteStorageKeys = _args23.length > 4 && _args23[4] !== undefined ? _args23[4] : new Set();
3250
3438
  if (!(orders.length === 0)) {
3251
- _context22.next = 4;
3439
+ _context23.next = 5;
3252
3440
  break;
3253
3441
  }
3254
- return _context22.abrupt("return");
3255
- case 4:
3442
+ return _context23.abrupt("return");
3443
+ case 5:
3256
3444
  if (this.dbManager) {
3257
- _context22.next = 8;
3445
+ _context23.next = 9;
3258
3446
  break;
3259
3447
  }
3260
3448
  if (!options.throwOnError) {
3261
- _context22.next = 7;
3449
+ _context23.next = 8;
3262
3450
  break;
3263
3451
  }
3264
3452
  throw new Error('订单 SQLite 数据库未初始化');
3265
- case 7:
3266
- return _context22.abrupt("return");
3267
3453
  case 8:
3454
+ return _context23.abrupt("return");
3455
+ case 9:
3268
3456
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3269
- return _this21.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3457
+ return _this22.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3270
3458
  }).filter(function (order) {
3271
- return _this21.getOrderStorageKey(order);
3459
+ return _this22.getOrderStorageKey(order);
3272
3460
  });
3273
3461
  if (!(ordersSnapshot.length === 0)) {
3274
- _context22.next = 11;
3462
+ _context23.next = 12;
3275
3463
  break;
3276
3464
  }
3277
- return _context22.abrupt("return");
3278
- case 11:
3279
- _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3465
+ return _context23.abrupt("return");
3466
+ case 12:
3467
+ _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3280
3468
  if (!(toWrite.length === 0)) {
3281
- _context22.next = 14;
3469
+ _context23.next = 15;
3282
3470
  break;
3283
3471
  }
3284
- return _context22.abrupt("return");
3285
- case 14:
3472
+ return _context23.abrupt("return");
3473
+ case 15:
3286
3474
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3287
3475
  if (!(compactedToWrite.length === 0)) {
3288
- _context22.next = 17;
3476
+ _context23.next = 18;
3289
3477
  break;
3290
3478
  }
3291
- return _context22.abrupt("return");
3292
- case 17:
3293
- _context22.prev = 17;
3294
- _context22.next = 20;
3295
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3296
- var writeMethod, _iterator30, _step30, order;
3297
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3298
- while (1) switch (_context21.prev = _context21.next) {
3479
+ return _context23.abrupt("return");
3480
+ case 18:
3481
+ _context23.prev = 18;
3482
+ _context23.next = 21;
3483
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
3484
+ var writeMethod, _iterator32, _step32, order;
3485
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3486
+ while (1) switch (_context22.prev = _context22.next) {
3299
3487
  case 0:
3300
3488
  writeMethod = 'none';
3301
- _this21.logInfo('patchOrdersInSQLite-开始', {
3489
+ _this22.logInfo('patchOrdersInSQLite-开始', {
3302
3490
  source: source,
3303
3491
  count: compactedToWrite.length,
3304
3492
  dedupedCount: skipped.length
3305
3493
  });
3306
- if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
3307
- _context21.next = 8;
3494
+ if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
3495
+ _context22.next = 8;
3308
3496
  break;
3309
3497
  }
3310
3498
  writeMethod = 'bulkUpdate';
3311
- _context21.next = 6;
3312
- return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3499
+ _context22.next = 6;
3500
+ return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3313
3501
  case 6:
3314
- _context21.next = 37;
3502
+ _context22.next = 37;
3315
3503
  break;
3316
3504
  case 8:
3317
- if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
3318
- _context21.next = 14;
3505
+ if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
3506
+ _context22.next = 14;
3319
3507
  break;
3320
3508
  }
3321
3509
  writeMethod = 'bulkAdd';
3322
- _context21.next = 12;
3323
- return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3510
+ _context22.next = 12;
3511
+ return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3324
3512
  case 12:
3325
- _context21.next = 37;
3513
+ _context22.next = 37;
3326
3514
  break;
3327
3515
  case 14:
3328
- if (!(typeof _this21.dbManager.update === 'function')) {
3329
- _context21.next = 35;
3516
+ if (!(typeof _this22.dbManager.update === 'function')) {
3517
+ _context22.next = 35;
3330
3518
  break;
3331
3519
  }
3332
3520
  writeMethod = 'update';
3333
- _iterator30 = _createForOfIteratorHelper(compactedToWrite);
3334
- _context21.prev = 17;
3335
- _iterator30.s();
3521
+ _iterator32 = _createForOfIteratorHelper(compactedToWrite);
3522
+ _context22.prev = 17;
3523
+ _iterator32.s();
3336
3524
  case 19:
3337
- if ((_step30 = _iterator30.n()).done) {
3338
- _context21.next = 25;
3525
+ if ((_step32 = _iterator32.n()).done) {
3526
+ _context22.next = 25;
3339
3527
  break;
3340
3528
  }
3341
- order = _step30.value;
3342
- _context21.next = 23;
3343
- return _this21.dbManager.update(INDEXDB_STORE_NAME, order);
3529
+ order = _step32.value;
3530
+ _context22.next = 23;
3531
+ return _this22.dbManager.update(INDEXDB_STORE_NAME, order);
3344
3532
  case 23:
3345
- _context21.next = 19;
3533
+ _context22.next = 19;
3346
3534
  break;
3347
3535
  case 25:
3348
- _context21.next = 30;
3536
+ _context22.next = 30;
3349
3537
  break;
3350
3538
  case 27:
3351
- _context21.prev = 27;
3352
- _context21.t0 = _context21["catch"](17);
3353
- _iterator30.e(_context21.t0);
3539
+ _context22.prev = 27;
3540
+ _context22.t0 = _context22["catch"](17);
3541
+ _iterator32.e(_context22.t0);
3354
3542
  case 30:
3355
- _context21.prev = 30;
3356
- _iterator30.f();
3357
- return _context21.finish(30);
3543
+ _context22.prev = 30;
3544
+ _iterator32.f();
3545
+ return _context22.finish(30);
3358
3546
  case 33:
3359
- _context21.next = 37;
3547
+ _context22.next = 37;
3360
3548
  break;
3361
3549
  case 35:
3362
3550
  if (!options.throwOnError) {
3363
- _context21.next = 37;
3551
+ _context22.next = 37;
3364
3552
  break;
3365
3553
  }
3366
3554
  throw new Error('订单 SQLite 数据库不支持写入');
3367
3555
  case 37:
3368
- _this21.recordRecentSqliteWrite(source, compactedToWrite);
3369
- _this21.logInfo('patchOrdersInSQLite-完成', {
3556
+ _this22.recordRecentSqliteWrite(source, compactedToWrite);
3557
+ _this22.logInfo('patchOrdersInSQLite-完成', {
3370
3558
  source: source,
3371
3559
  count: compactedToWrite.length,
3372
3560
  writeMethod: writeMethod,
@@ -3374,32 +3562,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3374
3562
  });
3375
3563
  case 39:
3376
3564
  case "end":
3377
- return _context21.stop();
3565
+ return _context22.stop();
3378
3566
  }
3379
- }, _callee21, null, [[17, 27, 30, 33]]);
3567
+ }, _callee22, null, [[17, 27, 30, 33]]);
3380
3568
  })));
3381
- case 20:
3382
- _context22.next = 27;
3569
+ case 21:
3570
+ _context23.next = 28;
3383
3571
  break;
3384
- case 22:
3385
- _context22.prev = 22;
3386
- _context22.t0 = _context22["catch"](17);
3572
+ case 23:
3573
+ _context23.prev = 23;
3574
+ _context23.t0 = _context23["catch"](18);
3387
3575
  this.logError('增量保存订单到 SQLite 失败', {
3388
- error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
3576
+ error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
3389
3577
  orderCount: ordersSnapshot.length
3390
3578
  });
3391
3579
  if (!options.throwOnError) {
3392
- _context22.next = 27;
3580
+ _context23.next = 28;
3393
3581
  break;
3394
3582
  }
3395
- throw _context22.t0;
3396
- case 27:
3583
+ throw _context23.t0;
3584
+ case 28:
3397
3585
  case "end":
3398
- return _context22.stop();
3586
+ return _context23.stop();
3399
3587
  }
3400
- }, _callee22, this, [[17, 22]]);
3588
+ }, _callee23, this, [[18, 23]]);
3401
3589
  }));
3402
- function patchOrdersInSQLite(_x15, _x16) {
3590
+ function patchOrdersInSQLite(_x16, _x17) {
3403
3591
  return _patchOrdersInSQLite.apply(this, arguments);
3404
3592
  }
3405
3593
  return patchOrdersInSQLite;
@@ -3414,128 +3602,128 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3414
3602
  }, {
3415
3603
  key: "updateOrderInSQLite",
3416
3604
  value: (function () {
3417
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order, source) {
3418
- var _this22 = this;
3605
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
3606
+ var _this23 = this;
3419
3607
  var options,
3420
3608
  orderSnapshot,
3421
3609
  _orderSnapshot$order_3,
3422
- _args24 = arguments;
3423
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3424
- while (1) switch (_context24.prev = _context24.next) {
3610
+ _args25 = arguments;
3611
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3612
+ while (1) switch (_context25.prev = _context25.next) {
3425
3613
  case 0:
3426
- options = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
3614
+ options = _args25.length > 2 && _args25[2] !== undefined ? _args25[2] : {};
3427
3615
  if (this.getOrderStorageKey(order)) {
3428
- _context24.next = 5;
3616
+ _context25.next = 5;
3429
3617
  break;
3430
3618
  }
3431
3619
  if (!options.throwOnError) {
3432
- _context24.next = 4;
3620
+ _context25.next = 4;
3433
3621
  break;
3434
3622
  }
3435
3623
  throw new Error('订单缺少可用的 SQLite 存储主键');
3436
3624
  case 4:
3437
- return _context24.abrupt("return");
3625
+ return _context25.abrupt("return");
3438
3626
  case 5:
3439
3627
  if (this.dbManager) {
3440
- _context24.next = 9;
3628
+ _context25.next = 9;
3441
3629
  break;
3442
3630
  }
3443
3631
  if (!options.throwOnError) {
3444
- _context24.next = 8;
3632
+ _context25.next = 8;
3445
3633
  break;
3446
3634
  }
3447
3635
  throw new Error('订单 SQLite 数据库未初始化');
3448
3636
  case 8:
3449
- return _context24.abrupt("return");
3637
+ return _context25.abrupt("return");
3450
3638
  case 9:
3451
3639
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
3452
- _context24.prev = 10;
3453
- _context24.next = 13;
3454
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
3640
+ _context25.prev = 10;
3641
+ _context25.next = 13;
3642
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
3455
3643
  var _orderSnapshot$order_, _orderSnapshot$order_2;
3456
3644
  var writeMethod;
3457
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3458
- while (1) switch (_context23.prev = _context23.next) {
3645
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3646
+ while (1) switch (_context24.prev = _context24.next) {
3459
3647
  case 0:
3460
3648
  writeMethod = 'none';
3461
- _this22.logInfo('updateOrderInSQLite-开始', {
3649
+ _this23.logInfo('updateOrderInSQLite-开始', {
3462
3650
  source: source,
3463
3651
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
3464
- storageKey: _this22.getOrderStorageKey(orderSnapshot)
3652
+ storageKey: _this23.getOrderStorageKey(orderSnapshot)
3465
3653
  });
3466
- if (!(typeof _this22.dbManager.update === 'function')) {
3467
- _context23.next = 8;
3654
+ if (!(typeof _this23.dbManager.update === 'function')) {
3655
+ _context24.next = 8;
3468
3656
  break;
3469
3657
  }
3470
3658
  writeMethod = 'update';
3471
- _context23.next = 6;
3472
- return _this22.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
3659
+ _context24.next = 6;
3660
+ return _this23.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
3473
3661
  case 6:
3474
- _context23.next = 22;
3662
+ _context24.next = 22;
3475
3663
  break;
3476
3664
  case 8:
3477
- if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
3478
- _context23.next = 14;
3665
+ if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3666
+ _context24.next = 14;
3479
3667
  break;
3480
3668
  }
3481
3669
  writeMethod = 'bulkUpdate';
3482
- _context23.next = 12;
3483
- return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
3670
+ _context24.next = 12;
3671
+ return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
3484
3672
  case 12:
3485
- _context23.next = 22;
3673
+ _context24.next = 22;
3486
3674
  break;
3487
3675
  case 14:
3488
- if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
3489
- _context23.next = 20;
3676
+ if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3677
+ _context24.next = 20;
3490
3678
  break;
3491
3679
  }
3492
3680
  writeMethod = 'bulkAdd';
3493
- _context23.next = 18;
3494
- return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
3681
+ _context24.next = 18;
3682
+ return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
3495
3683
  case 18:
3496
- _context23.next = 22;
3684
+ _context24.next = 22;
3497
3685
  break;
3498
3686
  case 20:
3499
3687
  if (!options.throwOnError) {
3500
- _context23.next = 22;
3688
+ _context24.next = 22;
3501
3689
  break;
3502
3690
  }
3503
3691
  throw new Error('订单 SQLite 数据库不支持写入');
3504
3692
  case 22:
3505
- _this22.recordRecentSqliteWrite(source, [orderSnapshot]);
3506
- _this22.logInfo('updateOrderInSQLite-完成', {
3693
+ _this23.recordRecentSqliteWrite(source, [orderSnapshot]);
3694
+ _this23.logInfo('updateOrderInSQLite-完成', {
3507
3695
  source: source,
3508
3696
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
3509
3697
  writeMethod: writeMethod
3510
3698
  });
3511
3699
  case 24:
3512
3700
  case "end":
3513
- return _context23.stop();
3701
+ return _context24.stop();
3514
3702
  }
3515
- }, _callee23);
3703
+ }, _callee24);
3516
3704
  })));
3517
3705
  case 13:
3518
- _context24.next = 20;
3706
+ _context25.next = 20;
3519
3707
  break;
3520
3708
  case 15:
3521
- _context24.prev = 15;
3522
- _context24.t0 = _context24["catch"](10);
3709
+ _context25.prev = 15;
3710
+ _context25.t0 = _context25["catch"](10);
3523
3711
  this.logError('单条保存订单到 SQLite 失败', {
3524
- error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
3712
+ error: _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0),
3525
3713
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
3526
3714
  });
3527
3715
  if (!options.throwOnError) {
3528
- _context24.next = 20;
3716
+ _context25.next = 20;
3529
3717
  break;
3530
3718
  }
3531
- throw _context24.t0;
3719
+ throw _context25.t0;
3532
3720
  case 20:
3533
3721
  case "end":
3534
- return _context24.stop();
3722
+ return _context25.stop();
3535
3723
  }
3536
- }, _callee24, this, [[10, 15]]);
3724
+ }, _callee25, this, [[10, 15]]);
3537
3725
  }));
3538
- function updateOrderInSQLite(_x17, _x18) {
3726
+ function updateOrderInSQLite(_x18, _x19) {
3539
3727
  return _updateOrderInSQLite.apply(this, arguments);
3540
3728
  }
3541
3729
  return updateOrderInSQLite;
@@ -3551,70 +3739,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3551
3739
  }, {
3552
3740
  key: "replaceOrdersSnapshotInSQLite",
3553
3741
  value: (function () {
3554
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orderList, source) {
3555
- var _this23 = this;
3742
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
3743
+ var _this24 = this;
3556
3744
  var protectedOrdersBeforeRemoteFetch,
3557
3745
  remoteSnapshot,
3558
3746
  mergedSnapshot,
3559
- _args26 = arguments;
3560
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3561
- while (1) switch (_context26.prev = _context26.next) {
3747
+ _args27 = arguments;
3748
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3749
+ while (1) switch (_context27.prev = _context27.next) {
3562
3750
  case 0:
3563
- protectedOrdersBeforeRemoteFetch = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : [];
3751
+ protectedOrdersBeforeRemoteFetch = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : [];
3564
3752
  if (this.dbManager) {
3565
- _context26.next = 3;
3753
+ _context27.next = 3;
3566
3754
  break;
3567
3755
  }
3568
- return _context26.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
3569
- return _this23.normalizeRemoteSyncedOrder(order);
3756
+ return _context27.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
3757
+ return _this24.normalizeRemoteSyncedOrder(order);
3570
3758
  }), "".concat(source, ".snapshotNoDb")).list);
3571
3759
  case 3:
3572
3760
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
3573
- return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
3761
+ return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
3574
3762
  });
3575
3763
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
3576
- return _this23.normalizeRemoteSyncedOrder(order);
3764
+ return _this24.normalizeRemoteSyncedOrder(order);
3577
3765
  }), "".concat(source, ".remoteSnapshot")).list;
3578
- _context26.prev = 5;
3579
- _context26.next = 8;
3580
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
3581
- var existingOrders, protectedLocalOrders, _iterator31, _step31, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3582
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3583
- while (1) switch (_context25.prev = _context25.next) {
3766
+ _context27.prev = 5;
3767
+ _context27.next = 8;
3768
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3769
+ var existingOrders, protectedLocalOrders, _iterator33, _step33, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3770
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3771
+ while (1) switch (_context26.prev = _context26.next) {
3584
3772
  case 0:
3585
- if (!(typeof _this23.dbManager.getAll === 'function')) {
3586
- _context25.next = 6;
3773
+ if (!(typeof _this24.dbManager.getAll === 'function')) {
3774
+ _context26.next = 6;
3587
3775
  break;
3588
3776
  }
3589
- _context25.next = 3;
3590
- return _this23.dbManager.getAll(INDEXDB_STORE_NAME);
3777
+ _context26.next = 3;
3778
+ return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
3591
3779
  case 3:
3592
- _context25.t0 = _context25.sent;
3593
- _context25.next = 7;
3780
+ _context26.t0 = _context26.sent;
3781
+ _context26.next = 7;
3594
3782
  break;
3595
3783
  case 6:
3596
- _context25.t0 = [];
3784
+ _context26.t0 = [];
3597
3785
  case 7:
3598
- existingOrders = _context25.t0;
3786
+ existingOrders = _context26.t0;
3599
3787
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
3600
- return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
3788
+ return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
3601
3789
  }).filter(function (order) {
3602
- return _this23.shouldProtectLocalOrderFromRemoteSnapshot(order);
3790
+ return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order);
3603
3791
  });
3604
- _iterator31 = _createForOfIteratorHelper(existingOrders || []);
3605
- _context25.prev = 10;
3606
- _iterator31.s();
3792
+ _iterator33 = _createForOfIteratorHelper(existingOrders || []);
3793
+ _context26.prev = 10;
3794
+ _iterator33.s();
3607
3795
  case 12:
3608
- if ((_step31 = _iterator31.n()).done) {
3609
- _context25.next = 23;
3796
+ if ((_step33 = _iterator33.n()).done) {
3797
+ _context26.next = 23;
3610
3798
  break;
3611
3799
  }
3612
- rawCurrentOrder = _step31.value;
3613
- currentOrder = _this23.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
3614
- protectedIndex = _this23.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
3615
- currentNeedsProtection = _this23.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
3800
+ rawCurrentOrder = _step33.value;
3801
+ currentOrder = _this24.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
3802
+ protectedIndex = _this24.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
3803
+ currentNeedsProtection = _this24.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
3616
3804
  if (!(protectedIndex >= 0)) {
3617
- _context25.next = 20;
3805
+ _context26.next = 20;
3618
3806
  break;
3619
3807
  }
3620
3808
  if (currentNeedsProtection) {
@@ -3622,27 +3810,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3622
3810
  } else {
3623
3811
  protectedLocalOrders.splice(protectedIndex, 1);
3624
3812
  }
3625
- return _context25.abrupt("continue", 21);
3813
+ return _context26.abrupt("continue", 21);
3626
3814
  case 20:
3627
3815
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
3628
3816
  case 21:
3629
- _context25.next = 12;
3817
+ _context26.next = 12;
3630
3818
  break;
3631
3819
  case 23:
3632
- _context25.next = 28;
3820
+ _context26.next = 28;
3633
3821
  break;
3634
3822
  case 25:
3635
- _context25.prev = 25;
3636
- _context25.t1 = _context25["catch"](10);
3637
- _iterator31.e(_context25.t1);
3823
+ _context26.prev = 25;
3824
+ _context26.t1 = _context26["catch"](10);
3825
+ _iterator33.e(_context26.t1);
3638
3826
  case 28:
3639
- _context25.prev = 28;
3640
- _iterator31.f();
3641
- return _context25.finish(28);
3827
+ _context26.prev = 28;
3828
+ _iterator33.f();
3829
+ return _context26.finish(28);
3642
3830
  case 31:
3643
- orderListSnapshot = _this23.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
3644
- mergedSnapshot = _this23.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
3645
- _this23.logInfo('replaceOrdersSnapshotInSQLite-开始', {
3831
+ orderListSnapshot = _this24.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
3832
+ mergedSnapshot = _this24.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
3833
+ _this24.logInfo('replaceOrdersSnapshotInSQLite-开始', {
3646
3834
  source: source,
3647
3835
  count: mergedSnapshot.length,
3648
3836
  remoteCount: remoteSnapshot.length,
@@ -3650,10 +3838,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3650
3838
  protectedLocalOrderCount: protectedLocalOrders.length,
3651
3839
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
3652
3840
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
3653
- return count + _this23.getIdentifiedPendingPayments(order).length;
3841
+ return count + _this24.getIdentifiedPendingPayments(order).length;
3654
3842
  }, 0),
3655
3843
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
3656
- return _this23.getIdentifiedPendingPayments(order).map(function (payment) {
3844
+ return _this24.getIdentifiedPendingPayments(order).map(function (payment) {
3657
3845
  var _order$order_id5, _external_sale_number5;
3658
3846
  return {
3659
3847
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -3663,51 +3851,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3663
3851
  });
3664
3852
  })
3665
3853
  });
3666
- _context25.next = 36;
3667
- return _this23.dbManager.clear(INDEXDB_STORE_NAME);
3854
+ _context26.next = 36;
3855
+ return _this24.dbManager.clear(INDEXDB_STORE_NAME);
3668
3856
  case 36:
3669
- _this23.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
3857
+ _this24.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
3670
3858
  count: mergedSnapshot.length
3671
3859
  });
3672
3860
  if (!(mergedSnapshot.length === 0)) {
3673
- _context25.next = 39;
3861
+ _context26.next = 39;
3674
3862
  break;
3675
3863
  }
3676
- return _context25.abrupt("return");
3864
+ return _context26.abrupt("return");
3677
3865
  case 39:
3678
- _context25.next = 41;
3679
- return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
3866
+ _context26.next = 41;
3867
+ return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
3680
3868
  case 41:
3681
- _this23.recordRecentSqliteWrite(source, mergedSnapshot);
3682
- _this23.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
3869
+ _this24.recordRecentSqliteWrite(source, mergedSnapshot);
3870
+ _this24.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
3683
3871
  source: source,
3684
3872
  count: mergedSnapshot.length
3685
3873
  });
3686
3874
  case 43:
3687
3875
  case "end":
3688
- return _context25.stop();
3876
+ return _context26.stop();
3689
3877
  }
3690
- }, _callee25, null, [[10, 25, 28, 31]]);
3878
+ }, _callee26, null, [[10, 25, 28, 31]]);
3691
3879
  })));
3692
3880
  case 8:
3693
- _context26.next = 13;
3881
+ _context27.next = 13;
3694
3882
  break;
3695
3883
  case 10:
3696
- _context26.prev = 10;
3697
- _context26.t0 = _context26["catch"](5);
3884
+ _context27.prev = 10;
3885
+ _context27.t0 = _context27["catch"](5);
3698
3886
  this.logError('全量保存订单到 SQLite 失败', {
3699
- error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
3887
+ error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
3700
3888
  orderList: remoteSnapshot.length
3701
3889
  });
3702
3890
  case 13:
3703
- return _context26.abrupt("return", mergedSnapshot);
3891
+ return _context27.abrupt("return", mergedSnapshot);
3704
3892
  case 14:
3705
3893
  case "end":
3706
- return _context26.stop();
3894
+ return _context27.stop();
3707
3895
  }
3708
- }, _callee26, this, [[5, 10]]);
3896
+ }, _callee27, this, [[5, 10]]);
3709
3897
  }));
3710
- function replaceOrdersSnapshotInSQLite(_x19, _x20) {
3898
+ function replaceOrdersSnapshotInSQLite(_x20, _x21) {
3711
3899
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
3712
3900
  }
3713
3901
  return replaceOrdersSnapshotInSQLite;
@@ -3722,38 +3910,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3722
3910
  }, {
3723
3911
  key: "clear",
3724
3912
  value: (function () {
3725
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
3726
- var _this24 = this;
3727
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
3728
- while (1) switch (_context28.prev = _context28.next) {
3913
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
3914
+ var _this25 = this;
3915
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
3916
+ while (1) switch (_context29.prev = _context29.next) {
3729
3917
  case 0:
3730
3918
  this.store.list = [];
3731
3919
  this.store.map = new Map();
3732
3920
  if (!this.dbManager) {
3733
- _context28.next = 5;
3921
+ _context29.next = 5;
3734
3922
  break;
3735
3923
  }
3736
- _context28.next = 5;
3737
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
3738
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3739
- while (1) switch (_context27.prev = _context27.next) {
3924
+ _context29.next = 5;
3925
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
3926
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
3927
+ while (1) switch (_context28.prev = _context28.next) {
3740
3928
  case 0:
3741
- _context27.next = 2;
3742
- return _this24.dbManager.clear(INDEXDB_STORE_NAME);
3929
+ _context28.next = 2;
3930
+ return _this25.dbManager.clear(INDEXDB_STORE_NAME);
3743
3931
  case 2:
3744
3932
  case "end":
3745
- return _context27.stop();
3933
+ return _context28.stop();
3746
3934
  }
3747
- }, _callee27);
3935
+ }, _callee28);
3748
3936
  })));
3749
3937
  case 5:
3750
3938
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
3751
3939
  this.emitOrdersChanged([], 'clear');
3752
3940
  case 7:
3753
3941
  case "end":
3754
- return _context28.stop();
3942
+ return _context29.stop();
3755
3943
  }
3756
- }, _callee28, this);
3944
+ }, _callee29, this);
3757
3945
  }));
3758
3946
  function clear() {
3759
3947
  return _clear.apply(this, arguments);