@pisell/pisellos 2.3.167 → 2.3.168

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.
@@ -1,16 +1,16 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ 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; }
3
+ 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; }
1
4
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
5
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
6
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
4
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ 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; } } }; }
5
9
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
10
  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."); }
11
+ 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); }
7
12
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
13
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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; }
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; } } }; }
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); }
14
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; }
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); } }
@@ -18,6 +18,8 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
18
18
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
19
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
20
20
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
22
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
21
23
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
24
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
25
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -33,6 +35,7 @@ import { resolveProductHolderConfig } from "../../../modules/Holder/utils";
33
35
  import { QuotationModule as ClientQuotationModule } from "../../../modules/Quotation";
34
36
  import { ProductsHooks } from "./types";
35
37
  import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
38
+ import { CommittedProductState } from "./replication";
36
39
  /**
37
40
  * IndexDB 存储名称
38
41
  */
@@ -95,16 +98,376 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
95
98
  _defineProperty(_assertThisInitialized(_this), "productIndexDBSaveQueue", Promise.resolve());
96
99
  /** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
97
100
  _defineProperty(_assertThisInitialized(_this), "lastScheduleTimePoints", []);
101
+ _defineProperty(_assertThisInitialized(_this), "committedProductState", void 0);
102
+ _defineProperty(_assertThisInitialized(_this), "productReplicationSourceGeneration", 0);
103
+ _defineProperty(_assertThisInitialized(_this), "productPersistenceFailed", false);
104
+ _defineProperty(_assertThisInitialized(_this), "runtimeSyncMode", 'normal');
105
+ _defineProperty(_assertThisInitialized(_this), "runtimeSyncGeneration", 0);
106
+ _defineProperty(_assertThisInitialized(_this), "requestReplicaRefresh", void 0);
107
+ _defineProperty(_assertThisInitialized(_this), "replicaApplyQueue", Promise.resolve());
108
+ _defineProperty(_assertThisInitialized(_this), "productSyncQueue", Promise.resolve());
109
+ _defineProperty(_assertThisInitialized(_this), "replicaPriceDirtyIds", new Map());
98
110
  return _this;
99
111
  }
100
112
  _createClass(ProductsModule, [{
113
+ key: "setRuntimeSyncMode",
114
+ value: ( /** Installed after initial preload; initial cache/network loading stays unchanged. */function () {
115
+ var _setRuntimeSyncMode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(mode, requestRefresh) {
116
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
117
+ while (1) switch (_context.prev = _context.next) {
118
+ case 0:
119
+ this.runtimeSyncGeneration += 1;
120
+ this.runtimeSyncMode = mode;
121
+ this.requestReplicaRefresh = requestRefresh;
122
+ if (!(mode === 'memoryReplica')) {
123
+ _context.next = 10;
124
+ break;
125
+ }
126
+ if (this.syncTimer) clearTimeout(this.syncTimer);
127
+ this.pendingSyncMessages = [];
128
+ _context.next = 8;
129
+ return this.productSyncQueue;
130
+ case 8:
131
+ _context.next = 10;
132
+ return this.productIndexDBSaveQueue;
133
+ case 10:
134
+ case "end":
135
+ return _context.stop();
136
+ }
137
+ }, _callee, this);
138
+ }));
139
+ function setRuntimeSyncMode(_x, _x2) {
140
+ return _setRuntimeSyncMode.apply(this, arguments);
141
+ }
142
+ return setRuntimeSyncMode;
143
+ }())
144
+ }, {
145
+ key: "isMemoryReplica",
146
+ value: function isMemoryReplica() {
147
+ return this.runtimeSyncMode === 'memoryReplica';
148
+ }
149
+
150
+ /** Read persisted data once on the main screen to establish a committed baseline. */
151
+ }, {
152
+ key: "enableProductReplicationSource",
153
+ value: (function () {
154
+ var _enableProductReplicationSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
155
+ var _this2 = this;
156
+ var generation;
157
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
158
+ while (1) switch (_context3.prev = _context3.next) {
159
+ case 0:
160
+ generation = this.productReplicationSourceGeneration;
161
+ _context3.next = 3;
162
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
163
+ var products;
164
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
165
+ while (1) switch (_context2.prev = _context2.next) {
166
+ case 0:
167
+ if (!(generation !== _this2.productReplicationSourceGeneration)) {
168
+ _context2.next = 2;
169
+ break;
170
+ }
171
+ return _context2.abrupt("return");
172
+ case 2:
173
+ if (!_this2.committedProductState) {
174
+ _context2.next = 4;
175
+ break;
176
+ }
177
+ return _context2.abrupt("return");
178
+ case 4:
179
+ if (!(!_this2.dbManager || _this2.productPersistenceFailed)) {
180
+ _context2.next = 6;
181
+ break;
182
+ }
183
+ throw new Error('Product replication requires a successful persistence baseline');
184
+ case 6:
185
+ _context2.next = 8;
186
+ return _this2.dbManager.getAll(INDEXDB_STORE_NAME);
187
+ case 8:
188
+ products = _context2.sent;
189
+ if (!(generation !== _this2.productReplicationSourceGeneration)) {
190
+ _context2.next = 11;
191
+ break;
192
+ }
193
+ return _context2.abrupt("return");
194
+ case 11:
195
+ if (Array.isArray(products)) {
196
+ _context2.next = 13;
197
+ break;
198
+ }
199
+ throw new Error('Invalid persisted product snapshot');
200
+ case 13:
201
+ _this2.committedProductState = new CommittedProductState();
202
+ _this2.committedProductState.commit({
203
+ kind: 'snapshot',
204
+ upserts: products,
205
+ deletedIds: []
206
+ });
207
+ case 15:
208
+ case "end":
209
+ return _context2.stop();
210
+ }
211
+ }, _callee2);
212
+ })));
213
+ case 3:
214
+ case "end":
215
+ return _context3.stop();
216
+ }
217
+ }, _callee3, this);
218
+ }));
219
+ function enableProductReplicationSource() {
220
+ return _enableProductReplicationSource.apply(this, arguments);
221
+ }
222
+ return enableProductReplicationSource;
223
+ }() /** Release the extra catalog without changing the normal product store or persistence. */)
224
+ }, {
225
+ key: "disableProductReplicationSource",
226
+ value: function disableProductReplicationSource() {
227
+ this.productReplicationSourceGeneration += 1;
228
+ this.committedProductState = undefined;
229
+ }
230
+ }, {
231
+ key: "getCommittedProductSnapshot",
232
+ value: function getCommittedProductSnapshot() {
233
+ var _this$committedProduc, _this$committedProduc2;
234
+ return (_this$committedProduc = (_this$committedProduc2 = this.committedProductState) === null || _this$committedProduc2 === void 0 ? void 0 : _this$committedProduc2.snapshot()) !== null && _this$committedProduc !== void 0 ? _this$committedProduc : null;
235
+ }
236
+ }, {
237
+ key: "recordProductCommit",
238
+ value: function () {
239
+ var _recordProductCommit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(change) {
240
+ var committed;
241
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
242
+ while (1) switch (_context4.prev = _context4.next) {
243
+ case 0:
244
+ this.productPersistenceFailed = false;
245
+ if (this.committedProductState) {
246
+ _context4.next = 3;
247
+ break;
248
+ }
249
+ return _context4.abrupt("return");
250
+ case 3:
251
+ committed = this.committedProductState.commit(change);
252
+ _context4.prev = 4;
253
+ _context4.next = 7;
254
+ return this.core.effects.emit(ProductsHooks.onProductsCommitted, committed);
255
+ case 7:
256
+ _context4.next = 12;
257
+ break;
258
+ case 9:
259
+ _context4.prev = 9;
260
+ _context4.t0 = _context4["catch"](4);
261
+ // Transport failure is not a persistence failure; peers recover using the snapshot.
262
+ this.logWarning('商品提交通知失败', {
263
+ revision: committed.revision,
264
+ error: String(_context4.t0)
265
+ });
266
+ case 12:
267
+ case "end":
268
+ return _context4.stop();
269
+ }
270
+ }, _callee4, this, [[4, 9]]);
271
+ }));
272
+ function recordProductCommit(_x3) {
273
+ return _recordProductCommit.apply(this, arguments);
274
+ }
275
+ return recordProductCommit;
276
+ }()
277
+ }, {
278
+ key: "applyReplicatedProducts",
279
+ value: function () {
280
+ var _applyReplicatedProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(change) {
281
+ var _this3 = this;
282
+ var generation, apply, task;
283
+ return _regeneratorRuntime().wrap(function _callee6$(_context7) {
284
+ while (1) switch (_context7.prev = _context7.next) {
285
+ case 0:
286
+ if (this.isMemoryReplica()) {
287
+ _context7.next = 2;
288
+ break;
289
+ }
290
+ throw new Error('Product module is not a memory replica');
291
+ case 2:
292
+ generation = this.runtimeSyncGeneration;
293
+ apply = /*#__PURE__*/function () {
294
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
295
+ var changedIds, _this3$store$list, removed, updates, _iterator, _step, id, _iterator2, _step2, product, _iterator3, _step3, _loop;
296
+ return _regeneratorRuntime().wrap(function _callee5$(_context6) {
297
+ while (1) switch (_context6.prev = _context6.next) {
298
+ case 0:
299
+ if (!(!_this3.isMemoryReplica() || generation !== _this3.runtimeSyncGeneration)) {
300
+ _context6.next = 2;
301
+ break;
302
+ }
303
+ return _context6.abrupt("return");
304
+ case 2:
305
+ changedIds = _toConsumableArray(new Set([].concat(_toConsumableArray(change.deletedIds), _toConsumableArray(change.upserts.map(function (p) {
306
+ return p.id;
307
+ })))));
308
+ if (!(change.kind === 'snapshot')) {
309
+ _context6.next = 9;
310
+ break;
311
+ }
312
+ _this3.store.list = change.upserts;
313
+ _this3.syncProductsMap();
314
+ _this3.clearPriceCache();
315
+ _context6.next = 33;
316
+ break;
317
+ case 9:
318
+ removed = new Set(change.deletedIds);
319
+ updates = new Map(change.upserts.map(function (p) {
320
+ return [p.id, p];
321
+ }));
322
+ _this3.store.list = _this3.store.list.filter(function (p) {
323
+ return !removed.has(p.id);
324
+ }).map(function (p) {
325
+ var next = updates.get(p.id);
326
+ if (!next) return p;
327
+ updates.delete(p.id);
328
+ return next;
329
+ });
330
+ (_this3$store$list = _this3.store.list).push.apply(_this3$store$list, _toConsumableArray(updates.values()));
331
+ _iterator = _createForOfIteratorHelper(removed);
332
+ try {
333
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
334
+ id = _step.value;
335
+ _this3.store.map.delete(id);
336
+ }
337
+ } catch (err) {
338
+ _iterator.e(err);
339
+ } finally {
340
+ _iterator.f();
341
+ }
342
+ _iterator2 = _createForOfIteratorHelper(change.upserts);
343
+ try {
344
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
345
+ product = _step2.value;
346
+ _this3.store.map.set(product.id, product);
347
+ }
348
+ } catch (err) {
349
+ _iterator2.e(err);
350
+ } finally {
351
+ _iterator2.f();
352
+ }
353
+ _iterator3 = _createForOfIteratorHelper(_this3.productsPriceCache);
354
+ _context6.prev = 18;
355
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
356
+ var _this3$replicaPriceDi;
357
+ var _step3$value, key, cached, dirty;
358
+ return _regeneratorRuntime().wrap(function _loop$(_context5) {
359
+ while (1) switch (_context5.prev = _context5.next) {
360
+ case 0:
361
+ _step3$value = _slicedToArray(_step3.value, 2), key = _step3$value[0], cached = _step3$value[1];
362
+ _this3.productsPriceCache.set(key, cached.filter(function (p) {
363
+ return !removed.has(p.id);
364
+ }));
365
+ dirty = (_this3$replicaPriceDi = _this3.replicaPriceDirtyIds.get(key)) !== null && _this3$replicaPriceDi !== void 0 ? _this3$replicaPriceDi : new Set();
366
+ change.upserts.forEach(function (p) {
367
+ return dirty.add(p.id);
368
+ });
369
+ removed.forEach(function (id) {
370
+ return dirty.delete(id);
371
+ });
372
+ _this3.replicaPriceDirtyIds.set(key, dirty);
373
+ case 6:
374
+ case "end":
375
+ return _context5.stop();
376
+ }
377
+ }, _loop);
378
+ });
379
+ _iterator3.s();
380
+ case 21:
381
+ if ((_step3 = _iterator3.n()).done) {
382
+ _context6.next = 25;
383
+ break;
384
+ }
385
+ return _context6.delegateYield(_loop(), "t0", 23);
386
+ case 23:
387
+ _context6.next = 21;
388
+ break;
389
+ case 25:
390
+ _context6.next = 30;
391
+ break;
392
+ case 27:
393
+ _context6.prev = 27;
394
+ _context6.t1 = _context6["catch"](18);
395
+ _iterator3.e(_context6.t1);
396
+ case 30:
397
+ _context6.prev = 30;
398
+ _iterator3.f();
399
+ return _context6.finish(30);
400
+ case 33:
401
+ _context6.next = 35;
402
+ return _this3.core.effects.emit(ProductsHooks.onProductsChanged, _this3.store.list);
403
+ case 35:
404
+ if (!(generation !== _this3.runtimeSyncGeneration)) {
405
+ _context6.next = 37;
406
+ break;
407
+ }
408
+ return _context6.abrupt("return");
409
+ case 37:
410
+ _context6.next = 39;
411
+ return _this3.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
412
+ changedIds: changedIds
413
+ });
414
+ case 39:
415
+ case "end":
416
+ return _context6.stop();
417
+ }
418
+ }, _callee5, null, [[18, 27, 30, 33]]);
419
+ }));
420
+ return function apply() {
421
+ return _ref2.apply(this, arguments);
422
+ };
423
+ }();
424
+ task = this.replicaApplyQueue.then(apply, apply);
425
+ this.replicaApplyQueue = task.catch(function () {
426
+ return undefined;
427
+ });
428
+ return _context7.abrupt("return", task);
429
+ case 7:
430
+ case "end":
431
+ return _context7.stop();
432
+ }
433
+ }, _callee6, this);
434
+ }));
435
+ function applyReplicatedProducts(_x4) {
436
+ return _applyReplicatedProducts.apply(this, arguments);
437
+ }
438
+ return applyReplicatedProducts;
439
+ }()
440
+ }, {
441
+ key: "refreshFromReplica",
442
+ value: function () {
443
+ var _refreshFromReplica = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(trigger) {
444
+ var _this$requestReplicaR;
445
+ return _regeneratorRuntime().wrap(function _callee7$(_context8) {
446
+ while (1) switch (_context8.prev = _context8.next) {
447
+ case 0:
448
+ _context8.next = 2;
449
+ return (_this$requestReplicaR = this.requestReplicaRefresh) === null || _this$requestReplicaR === void 0 ? void 0 : _this$requestReplicaR.call(this, trigger);
450
+ case 2:
451
+ return _context8.abrupt("return", this.store.list);
452
+ case 3:
453
+ case "end":
454
+ return _context8.stop();
455
+ }
456
+ }, _callee7, this);
457
+ }));
458
+ function refreshFromReplica(_x5) {
459
+ return _refreshFromReplica.apply(this, arguments);
460
+ }
461
+ return refreshFromReplica;
462
+ }()
463
+ }, {
101
464
  key: "initialize",
102
465
  value: function () {
103
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
466
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(core, options) {
104
467
  var _options$initialState;
105
468
  var appPlugin, app;
106
- return _regeneratorRuntime().wrap(function _callee$(_context) {
107
- while (1) switch (_context.prev = _context.next) {
469
+ return _regeneratorRuntime().wrap(function _callee8$(_context9) {
470
+ while (1) switch (_context9.prev = _context9.next) {
108
471
  case 0:
109
472
  this.core = core;
110
473
  this.store = options.store;
@@ -146,11 +509,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
146
509
  });
147
510
  case 11:
148
511
  case "end":
149
- return _context.stop();
512
+ return _context9.stop();
150
513
  }
151
- }, _callee, this);
514
+ }, _callee8, this);
152
515
  }));
153
- function initialize(_x, _x2) {
516
+ function initialize(_x6, _x7) {
154
517
  return _initialize.apply(this, arguments);
155
518
  }
156
519
  return initialize;
@@ -225,13 +588,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
225
588
  }, {
226
589
  key: "loadProductsPrice",
227
590
  value: (function () {
228
- var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
229
- var _this2 = this;
230
- var _ref$ids, ids, schedule_date, schedule_datetime, customer_id, startTime, datetime, idSet, products, priceData, duration, _duration, errorMessage;
231
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
232
- while (1) switch (_context2.prev = _context2.next) {
591
+ var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref3) {
592
+ var _this4 = this;
593
+ var _ref3$ids, ids, schedule_date, schedule_datetime, customer_id, startTime, datetime, idSet, products, priceData, duration, _duration, errorMessage;
594
+ return _regeneratorRuntime().wrap(function _callee9$(_context10) {
595
+ while (1) switch (_context10.prev = _context10.next) {
233
596
  case 0:
234
- _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, schedule_date = _ref.schedule_date, schedule_datetime = _ref.schedule_datetime, customer_id = _ref.customer_id;
597
+ _ref3$ids = _ref3.ids, ids = _ref3$ids === void 0 ? [] : _ref3$ids, schedule_date = _ref3.schedule_date, schedule_datetime = _ref3.schedule_datetime, customer_id = _ref3.customer_id;
235
598
  this.logInfo('开始加载商品价格', {
236
599
  productCount: ids.length,
237
600
  schedule_date: schedule_date,
@@ -240,8 +603,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
240
603
  });
241
604
  startTime = Date.now();
242
605
  datetime = schedule_datetime || schedule_date;
243
- _context2.prev = 4;
244
- _context2.next = 7;
606
+ _context10.prev = 4;
607
+ _context10.next = 7;
245
608
  return this.ensureQuotationBridgeReady(customer_id);
246
609
  case 7:
247
610
  idSet = new Set(ids);
@@ -249,7 +612,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
249
612
  return idSet.has(product.id);
250
613
  });
251
614
  priceData = products.map(function (product) {
252
- return _this2.buildPriceDataFromQuotation(product, datetime, customer_id);
615
+ return _this4.buildPriceDataFromQuotation(product, datetime, customer_id);
253
616
  });
254
617
  duration = Date.now() - startTime;
255
618
  this.logInfo('加载商品价格成功', {
@@ -257,25 +620,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
257
620
  priceDataCount: priceData.length,
258
621
  duration: "".concat(duration, "ms")
259
622
  });
260
- return _context2.abrupt("return", priceData);
623
+ return _context10.abrupt("return", priceData);
261
624
  case 15:
262
- _context2.prev = 15;
263
- _context2.t0 = _context2["catch"](4);
625
+ _context10.prev = 15;
626
+ _context10.t0 = _context10["catch"](4);
264
627
  _duration = Date.now() - startTime;
265
- errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
628
+ errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
266
629
  this.logError('加载商品价格失败', {
267
630
  productCount: ids.length,
268
631
  duration: "".concat(_duration, "ms"),
269
632
  error: errorMessage
270
633
  });
271
- return _context2.abrupt("return", []);
634
+ return _context10.abrupt("return", []);
272
635
  case 21:
273
636
  case "end":
274
- return _context2.stop();
637
+ return _context10.stop();
275
638
  }
276
- }, _callee2, this, [[4, 15]]);
639
+ }, _callee9, this, [[4, 15]]);
277
640
  }));
278
- function loadProductsPrice(_x3) {
641
+ function loadProductsPrice(_x8) {
279
642
  return _loadProductsPrice.apply(this, arguments);
280
643
  }
281
644
  return loadProductsPrice;
@@ -288,30 +651,30 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
288
651
  }, {
289
652
  key: "setupQuotationPriceBridge",
290
653
  value: (function () {
291
- var _setupQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
654
+ var _setupQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
292
655
  var _this$otherParams,
293
- _this3 = this,
656
+ _this5 = this,
294
657
  _this$quotationPriceB,
295
658
  _this$quotationPriceB2;
296
659
  var channel, quotation;
297
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
298
- while (1) switch (_context3.prev = _context3.next) {
660
+ return _regeneratorRuntime().wrap(function _callee10$(_context11) {
661
+ while (1) switch (_context11.prev = _context11.next) {
299
662
  case 0:
300
663
  if (this.core) {
301
- _context3.next = 3;
664
+ _context11.next = 3;
302
665
  break;
303
666
  }
304
667
  this.logWarning('setupQuotationPriceBridge: core 尚未初始化');
305
- return _context3.abrupt("return");
668
+ return _context11.abrupt("return");
306
669
  case 3:
307
670
  channel = params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel);
308
671
  this.quotationBridgeChannel = channel;
309
672
  if (this.quotationPriceBridge) {
310
- _context3.next = 10;
673
+ _context11.next = 10;
311
674
  break;
312
675
  }
313
676
  quotation = new ClientQuotationModule("".concat(this.name, "_quotation_price_bridge"));
314
- _context3.next = 9;
677
+ _context11.next = 9;
315
678
  return quotation.initialize(this.core, {});
316
679
  case 9:
317
680
  this.quotationPriceBridge = quotation;
@@ -325,31 +688,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
325
688
  this.quotationPriceBridge.setScheduleResolver(function (id) {
326
689
  var _params$scheduleModul3, _params$scheduleModul4, _params$scheduleModul5, _params$scheduleModul6;
327
690
  var scheduleId = String(id);
328
- if (_this3.quotationScheduleCache.has(scheduleId)) {
329
- return _this3.quotationScheduleCache.get(scheduleId);
691
+ if (_this5.quotationScheduleCache.has(scheduleId)) {
692
+ return _this5.quotationScheduleCache.get(scheduleId);
330
693
  }
331
- if (!_this3.quotationScheduleCacheLoaded) {
694
+ if (!_this5.quotationScheduleCacheLoaded) {
332
695
  var _params$scheduleModul, _params$scheduleModul2;
333
696
  var scheduleList = ((_params$scheduleModul = (_params$scheduleModul2 = params.scheduleModule).getScheduleList) === null || _params$scheduleModul === void 0 ? void 0 : _params$scheduleModul.call(_params$scheduleModul2)) || [];
334
- var _iterator = _createForOfIteratorHelper(scheduleList),
335
- _step;
697
+ var _iterator4 = _createForOfIteratorHelper(scheduleList),
698
+ _step4;
336
699
  try {
337
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
338
- var schedule = _step.value;
339
- _this3.quotationScheduleCache.set(String(schedule.id), schedule);
700
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
701
+ var schedule = _step4.value;
702
+ _this5.quotationScheduleCache.set(String(schedule.id), schedule);
340
703
  }
341
704
  } catch (err) {
342
- _iterator.e(err);
705
+ _iterator4.e(err);
343
706
  } finally {
344
- _iterator.f();
707
+ _iterator4.f();
345
708
  }
346
- _this3.quotationScheduleCacheLoaded = true;
709
+ _this5.quotationScheduleCacheLoaded = true;
347
710
  }
348
- if (_this3.quotationScheduleCache.has(scheduleId)) {
349
- return _this3.quotationScheduleCache.get(scheduleId);
711
+ if (_this5.quotationScheduleCache.has(scheduleId)) {
712
+ return _this5.quotationScheduleCache.get(scheduleId);
350
713
  }
351
714
  var schedules = ((_params$scheduleModul3 = (_params$scheduleModul4 = params.scheduleModule).getScheduleListByIds) === null || _params$scheduleModul3 === void 0 ? void 0 : _params$scheduleModul3.call(_params$scheduleModul4, [id])) || ((_params$scheduleModul5 = (_params$scheduleModul6 = params.scheduleModule).getScheduleByIds) === null || _params$scheduleModul5 === void 0 ? void 0 : _params$scheduleModul5.call(_params$scheduleModul6, [id])) || [];
352
- if (schedules[0]) _this3.quotationScheduleCache.set(scheduleId, schedules[0]);
715
+ if (schedules[0]) _this5.quotationScheduleCache.set(scheduleId, schedules[0]);
353
716
  return schedules[0];
354
717
  });
355
718
  }
@@ -357,22 +720,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
357
720
  this.quotationBridgeUpdatedCallback = params.onQuotationUpdated;
358
721
  }
359
722
  (_this$quotationPriceB = (_this$quotationPriceB2 = this.quotationPriceBridge).setQuotationListUpdatedListener) === null || _this$quotationPriceB === void 0 || _this$quotationPriceB.call(_this$quotationPriceB2, function () {
360
- var _this3$quotationBridg;
361
- _this3.quotationBridgeLoadedKey = _this3.getQuotationBridgeScopeKey();
362
- _this3.clearPriceCache();
363
- (_this3$quotationBridg = _this3.quotationBridgeUpdatedCallback) === null || _this3$quotationBridg === void 0 || _this3$quotationBridg.call(_this3);
723
+ var _this5$quotationBridg;
724
+ _this5.quotationBridgeLoadedKey = _this5.getQuotationBridgeScopeKey();
725
+ _this5.clearPriceCache();
726
+ (_this5$quotationBridg = _this5.quotationBridgeUpdatedCallback) === null || _this5$quotationBridg === void 0 || _this5$quotationBridg.call(_this5);
364
727
  });
365
- _context3.next = 15;
728
+ _context11.next = 15;
366
729
  return this.refreshQuotationPriceBridge({
367
730
  customer_id: params.customer_id
368
731
  });
369
732
  case 15:
370
733
  case "end":
371
- return _context3.stop();
734
+ return _context11.stop();
372
735
  }
373
- }, _callee3, this);
736
+ }, _callee10, this);
374
737
  }));
375
- function setupQuotationPriceBridge(_x4) {
738
+ function setupQuotationPriceBridge(_x9) {
376
739
  return _setupQuotationPriceBridge.apply(this, arguments);
377
740
  }
378
741
  return setupQuotationPriceBridge;
@@ -384,53 +747,53 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
384
747
  }, {
385
748
  key: "refreshQuotationPriceBridge",
386
749
  value: (function () {
387
- var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
388
- var _this4 = this;
750
+ var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
751
+ var _this6 = this;
389
752
  var refreshKey;
390
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
391
- while (1) switch (_context4.prev = _context4.next) {
753
+ return _regeneratorRuntime().wrap(function _callee11$(_context12) {
754
+ while (1) switch (_context12.prev = _context12.next) {
392
755
  case 0:
393
756
  if (this.quotationPriceBridge) {
394
- _context4.next = 2;
757
+ _context12.next = 2;
395
758
  break;
396
759
  }
397
- return _context4.abrupt("return");
760
+ return _context12.abrupt("return");
398
761
  case 2:
399
762
  refreshKey = this.getQuotationBridgeScopeKey();
400
763
  if (!(this.quotationBridgeRefreshPromise && this.quotationBridgeRefreshKey === refreshKey)) {
401
- _context4.next = 7;
764
+ _context12.next = 7;
402
765
  break;
403
766
  }
404
- _context4.next = 6;
767
+ _context12.next = 6;
405
768
  return this.quotationBridgeRefreshPromise;
406
769
  case 6:
407
- return _context4.abrupt("return");
770
+ return _context12.abrupt("return");
408
771
  case 7:
409
772
  if (!this.quotationBridgeRefreshPromise) {
410
- _context4.next = 10;
773
+ _context12.next = 10;
411
774
  break;
412
775
  }
413
- _context4.next = 10;
776
+ _context12.next = 10;
414
777
  return this.quotationBridgeRefreshPromise;
415
778
  case 10:
416
779
  this.quotationBridgeRefreshKey = refreshKey;
417
780
  this.quotationBridgeRefreshPromise = this.quotationPriceBridge.loadQuotations({
418
781
  channel: this.quotationBridgeChannel
419
782
  }).then(function () {
420
- _this4.quotationBridgeLoadedKey = refreshKey;
783
+ _this6.quotationBridgeLoadedKey = refreshKey;
421
784
  }).finally(function () {
422
- _this4.quotationBridgeRefreshPromise = undefined;
423
- _this4.quotationBridgeRefreshKey = undefined;
785
+ _this6.quotationBridgeRefreshPromise = undefined;
786
+ _this6.quotationBridgeRefreshKey = undefined;
424
787
  });
425
- _context4.next = 14;
788
+ _context12.next = 14;
426
789
  return this.quotationBridgeRefreshPromise;
427
790
  case 14:
428
791
  case "end":
429
- return _context4.stop();
792
+ return _context12.stop();
430
793
  }
431
- }, _callee4, this);
794
+ }, _callee11, this);
432
795
  }));
433
- function refreshQuotationPriceBridge(_x5) {
796
+ function refreshQuotationPriceBridge(_x10) {
434
797
  return _refreshQuotationPriceBridge.apply(this, arguments);
435
798
  }
436
799
  return refreshQuotationPriceBridge;
@@ -438,45 +801,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
438
801
  }, {
439
802
  key: "ensureQuotationBridgeReady",
440
803
  value: function () {
441
- var _ensureQuotationBridgeReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(customerId) {
804
+ var _ensureQuotationBridgeReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(customerId) {
442
805
  var _this$otherParams2;
443
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
444
- while (1) switch (_context5.prev = _context5.next) {
806
+ return _regeneratorRuntime().wrap(function _callee12$(_context13) {
807
+ while (1) switch (_context13.prev = _context13.next) {
445
808
  case 0:
446
809
  if (this.quotationPriceBridge) {
447
- _context5.next = 4;
810
+ _context13.next = 4;
448
811
  break;
449
812
  }
450
- _context5.next = 3;
813
+ _context13.next = 3;
451
814
  return this.setupQuotationPriceBridge({
452
815
  channel: (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel,
453
816
  customer_id: customerId
454
817
  });
455
818
  case 3:
456
- return _context5.abrupt("return");
819
+ return _context13.abrupt("return");
457
820
  case 4:
458
821
  if (!this.quotationBridgeRefreshPromise) {
459
- _context5.next = 7;
822
+ _context13.next = 7;
460
823
  break;
461
824
  }
462
- _context5.next = 7;
825
+ _context13.next = 7;
463
826
  return this.quotationBridgeRefreshPromise;
464
827
  case 7:
465
828
  if (!(this.getQuotationBridgeScopeKey() !== this.quotationBridgeLoadedKey)) {
466
- _context5.next = 10;
829
+ _context13.next = 10;
467
830
  break;
468
831
  }
469
- _context5.next = 10;
832
+ _context13.next = 10;
470
833
  return this.refreshQuotationPriceBridge({
471
834
  customer_id: customerId
472
835
  });
473
836
  case 10:
474
837
  case "end":
475
- return _context5.stop();
838
+ return _context13.stop();
476
839
  }
477
- }, _callee5, this);
840
+ }, _callee12, this);
478
841
  }));
479
- function ensureQuotationBridgeReady(_x6) {
842
+ function ensureQuotationBridgeReady(_x11) {
480
843
  return _ensureQuotationBridgeReady.apply(this, arguments);
481
844
  }
482
845
  return ensureQuotationBridgeReady;
@@ -509,14 +872,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
509
872
  }, {
510
873
  key: "buildPriceDataFromQuotation",
511
874
  value: function buildPriceDataFromQuotation(product, datetime, customerId) {
512
- var _ref2, _ref3;
875
+ var _ref4, _ref5;
513
876
  var quotedPrice = this.getQuotedPrice({
514
877
  productId: product.id,
515
878
  datetime: datetime,
516
879
  customerId: customerId
517
880
  });
518
881
  var productPrice = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.price;
519
- var productBasePrice = (_ref2 = (_ref3 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.base_price) !== null && _ref3 !== void 0 ? _ref3 : product.price) !== null && _ref2 !== void 0 ? _ref2 : 0;
882
+ var productBasePrice = (_ref4 = (_ref5 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.base_price) !== null && _ref5 !== void 0 ? _ref5 : product.price) !== null && _ref4 !== void 0 ? _ref4 : 0;
520
883
  return {
521
884
  id: product.id,
522
885
  price: String(productPrice !== null && productPrice !== void 0 ? productPrice : 0),
@@ -528,18 +891,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
528
891
  }, {
529
892
  key: "buildVariantPriceData",
530
893
  value: function buildVariantPriceData(product, datetime, customerId) {
531
- var _this5 = this;
894
+ var _this7 = this;
532
895
  if (!Array.isArray(product.variant)) return [];
533
896
  return product.variant.map(function (variant) {
534
- var _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _variant$product_id;
535
- var quotedPrice = _this5.getQuotedPrice({
897
+ var _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _variant$product_id;
898
+ var quotedPrice = _this7.getQuotedPrice({
536
899
  productId: product.id,
537
900
  variantId: Number(variant.id),
538
901
  datetime: datetime,
539
902
  customerId: customerId
540
903
  });
541
- var price = (_ref4 = (_ref5 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.price) !== null && _ref5 !== void 0 ? _ref5 : product.price) !== null && _ref4 !== void 0 ? _ref4 : 0;
542
- var basePrice = (_ref6 = (_ref7 = (_ref8 = (_ref9 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.base_price) !== null && _ref9 !== void 0 ? _ref9 : variant.price) !== null && _ref8 !== void 0 ? _ref8 : product.base_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : 0;
904
+ var price = (_ref6 = (_ref7 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : 0;
905
+ var basePrice = (_ref8 = (_ref9 = (_ref10 = (_ref11 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.base_price) !== null && _ref11 !== void 0 ? _ref11 : variant.price) !== null && _ref10 !== void 0 ? _ref10 : product.base_price) !== null && _ref9 !== void 0 ? _ref9 : product.price) !== null && _ref8 !== void 0 ? _ref8 : 0;
543
906
  return {
544
907
  id: Number(variant.id),
545
908
  product_id: Number((_variant$product_id = variant.product_id) !== null && _variant$product_id !== void 0 ? _variant$product_id : product.id),
@@ -551,23 +914,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
551
914
  }, {
552
915
  key: "buildBundleGroupPriceData",
553
916
  value: function buildBundleGroupPriceData(product, datetime, customerId) {
554
- var _this6 = this;
917
+ var _this8 = this;
555
918
  if (!Array.isArray(product.bundle_group)) return [];
556
919
  return product.bundle_group.map(function (group) {
557
920
  return {
558
921
  id: Number(group.id),
559
922
  bundle_item: (group.bundle_item || []).map(function (item) {
560
- var _ref10, _ref11, _ref12, _item$product_id, _item$group_id;
923
+ var _ref12, _ref13, _ref14, _item$product_id, _item$group_id;
561
924
  var bundleProductId = Number(item.bundle_product_id);
562
925
  var bundleVariantId = Number(item.bundle_variant_id || 0);
563
- var quotedPrice = _this6.getQuotedPrice({
926
+ var quotedPrice = _this8.getQuotedPrice({
564
927
  productId: bundleProductId,
565
928
  variantId: bundleVariantId,
566
929
  datetime: datetime,
567
930
  customerId: customerId
568
931
  });
569
- var price = (_ref10 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref10 !== void 0 ? _ref10 : 0;
570
- var basePrice = (_ref11 = (_ref12 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.base_price) !== null && _ref12 !== void 0 ? _ref12 : item.price) !== null && _ref11 !== void 0 ? _ref11 : 0;
932
+ var price = (_ref12 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref12 !== void 0 ? _ref12 : 0;
933
+ var basePrice = (_ref13 = (_ref14 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.base_price) !== null && _ref14 !== void 0 ? _ref14 : item.price) !== null && _ref13 !== void 0 ? _ref13 : 0;
571
934
  return {
572
935
  id: Number(item.id),
573
936
  product_id: Number((_item$product_id = item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : product.id),
@@ -598,26 +961,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
598
961
  }, {
599
962
  key: "getProductsWithPrice",
600
963
  value: (function () {
601
- var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schedule_date, extraContext, options) {
602
- var _options$changedIds;
603
- var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator2, _step2, p, _iterator3, _step3, _p, errorMessage, result;
604
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
605
- while (1) switch (_context6.prev = _context6.next) {
964
+ var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(schedule_date, extraContext, options) {
965
+ var _options$changedIds, _this$replicaPriceDir;
966
+ var t0, scopedProductIds, cacheKey, scopedProductIdSet, pendingIds, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator5, _step5, p, _iterator6, _step6, _p, errorMessage, result;
967
+ return _regeneratorRuntime().wrap(function _callee13$(_context14) {
968
+ while (1) switch (_context14.prev = _context14.next) {
606
969
  case 0:
607
970
  t0 = performance.now();
608
971
  scopedProductIds = this.normalizeProductIds(options === null || options === void 0 ? void 0 : options.productIds);
609
972
  cacheKey = this.getProductsPriceCacheKey(schedule_date, extraContext, scopedProductIds);
610
973
  scopedProductIdSet = scopedProductIds ? new Set(scopedProductIds) : undefined;
611
- changedIds = scopedProductIdSet ? options === null || options === void 0 || (_options$changedIds = options.changedIds) === null || _options$changedIds === void 0 ? void 0 : _options$changedIds.filter(function (id) {
974
+ pendingIds = _toConsumableArray(new Set([].concat(_toConsumableArray((_options$changedIds = options === null || options === void 0 ? void 0 : options.changedIds) !== null && _options$changedIds !== void 0 ? _options$changedIds : []), _toConsumableArray((_this$replicaPriceDir = this.replicaPriceDirtyIds.get(cacheKey)) !== null && _this$replicaPriceDir !== void 0 ? _this$replicaPriceDir : []))));
975
+ changedIds = scopedProductIdSet ? pendingIds.filter(function (id) {
612
976
  return scopedProductIdSet.has(id);
613
- }) : options === null || options === void 0 ? void 0 : options.changedIds;
977
+ }) : pendingIds;
614
978
  if (!this.productsPriceCache.has(cacheKey)) {
615
- _context6.next = 35;
979
+ _context14.next = 37;
616
980
  break;
617
981
  }
618
982
  cachedProducts = this.productsPriceCache.get(cacheKey); // 有变更的商品 → 增量 prepare 后 merge 回缓存
619
983
  if (!(changedIds && changedIds.length > 0)) {
620
- _context6.next = 32;
984
+ _context14.next = 34;
621
985
  break;
622
986
  }
623
987
  this.logInfo('商品价格缓存命中,增量更新变更商品', {
@@ -625,15 +989,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
625
989
  changedIds: changedIds,
626
990
  cachedProductCount: cachedProducts.length
627
991
  });
628
- _context6.prev = 9;
629
- _context6.next = 12;
992
+ _context14.prev = 10;
993
+ _context14.next = 13;
630
994
  return this.prepareProductsWithPrice(schedule_date, extraContext, {
631
995
  productIds: changedIds
632
996
  });
633
- case 12:
634
- updatedProducts = _context6.sent;
635
- if (!(updatedProducts.length > 0)) {
636
- _context6.next = 24;
997
+ case 13:
998
+ updatedProducts = _context14.sent;
999
+ if (!(updatedProducts.length > 0 || this.isMemoryReplica())) {
1000
+ _context14.next = 26;
637
1001
  break;
638
1002
  }
639
1003
  // merge:用更新结果替换缓存中对应的商品,新增的追加
@@ -641,35 +1005,36 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
641
1005
  return [p.id, p];
642
1006
  }));
643
1007
  mergedCache = [];
644
- _iterator2 = _createForOfIteratorHelper(cachedProducts);
1008
+ _iterator5 = _createForOfIteratorHelper(cachedProducts);
645
1009
  try {
646
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
647
- p = _step2.value;
1010
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1011
+ p = _step5.value;
648
1012
  if (updatedMap.has(p.id)) {
649
1013
  mergedCache.push(updatedMap.get(p.id));
650
1014
  updatedMap.delete(p.id);
651
- } else {
1015
+ } else if (!this.isMemoryReplica() || !changedIds.includes(p.id)) {
652
1016
  mergedCache.push(p);
653
1017
  }
654
1018
  }
655
1019
  // 剩余的是新增商品(create 场景)
656
1020
  } catch (err) {
657
- _iterator2.e(err);
1021
+ _iterator5.e(err);
658
1022
  } finally {
659
- _iterator2.f();
1023
+ _iterator5.f();
660
1024
  }
661
- _iterator3 = _createForOfIteratorHelper(updatedMap.values());
1025
+ _iterator6 = _createForOfIteratorHelper(updatedMap.values());
662
1026
  try {
663
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
664
- _p = _step3.value;
1027
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1028
+ _p = _step6.value;
665
1029
  mergedCache.push(_p);
666
1030
  }
667
1031
  } catch (err) {
668
- _iterator3.e(err);
1032
+ _iterator6.e(err);
669
1033
  } finally {
670
- _iterator3.f();
1034
+ _iterator6.f();
671
1035
  }
672
1036
  this.productsPriceCache.set(cacheKey, mergedCache);
1037
+ this.replicaPriceDirtyIds.delete(cacheKey);
673
1038
  this.logInfo('增量更新完成', {
674
1039
  cacheKey: cacheKey,
675
1040
  changedCount: updatedProducts.length,
@@ -680,27 +1045,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
680
1045
  changedCount: changedIds.length,
681
1046
  count: mergedCache.length
682
1047
  });
683
- return _context6.abrupt("return", mergedCache);
684
- case 24:
685
- _context6.next = 30;
686
- break;
1048
+ return _context14.abrupt("return", mergedCache);
687
1049
  case 26:
688
- _context6.prev = 26;
689
- _context6.t0 = _context6["catch"](9);
690
- errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
1050
+ _context14.next = 32;
1051
+ break;
1052
+ case 28:
1053
+ _context14.prev = 28;
1054
+ _context14.t0 = _context14["catch"](10);
1055
+ errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0);
691
1056
  this.logError('增量更新失败,返回现有缓存', {
692
1057
  cacheKey: cacheKey,
693
1058
  changedIds: changedIds,
694
1059
  error: errorMessage
695
1060
  });
696
- case 30:
1061
+ case 32:
697
1062
  perfMark('getProductsWithPrice(incrementalUpdate)', performance.now() - t0, {
698
1063
  cacheKey: cacheKey,
699
1064
  changedCount: changedIds.length,
700
1065
  count: cachedProducts.length
701
1066
  });
702
- return _context6.abrupt("return", cachedProducts);
703
- case 32:
1067
+ return _context14.abrupt("return", cachedProducts);
1068
+ case 34:
704
1069
  perfMark('getProductsWithPrice(cacheHit)', performance.now() - t0, {
705
1070
  cacheKey: cacheKey,
706
1071
  count: cachedProducts.length
@@ -709,19 +1074,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
709
1074
  cacheKey: cacheKey,
710
1075
  productCount: cachedProducts.length
711
1076
  });
712
- return _context6.abrupt("return", cachedProducts);
713
- case 35:
1077
+ return _context14.abrupt("return", cachedProducts);
1078
+ case 37:
714
1079
  this.logInfo('商品价格缓存未命中,准备获取', {
715
1080
  cacheKey: cacheKey,
716
1081
  scopedProductCount: scopedProductIds === null || scopedProductIds === void 0 ? void 0 : scopedProductIds.length
717
1082
  });
718
- _context6.next = 38;
1083
+ _context14.next = 40;
719
1084
  return this.prepareProductsWithPrice(schedule_date, extraContext, scopedProductIds ? {
720
1085
  productIds: scopedProductIds
721
1086
  } : undefined);
722
- case 38:
723
- result = _context6.sent;
1087
+ case 40:
1088
+ result = _context14.sent;
724
1089
  this.productsPriceCache.set(cacheKey, result);
1090
+ this.replicaPriceDirtyIds.delete(cacheKey);
725
1091
  this.logInfo('商品价格已缓存', {
726
1092
  cacheKey: cacheKey,
727
1093
  productCount: result.length
@@ -731,14 +1097,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
731
1097
  cacheKey: cacheKey,
732
1098
  count: result.length
733
1099
  });
734
- return _context6.abrupt("return", result);
735
- case 44:
1100
+ return _context14.abrupt("return", result);
1101
+ case 47:
736
1102
  case "end":
737
- return _context6.stop();
1103
+ return _context14.stop();
738
1104
  }
739
- }, _callee6, this, [[9, 26]]);
1105
+ }, _callee13, this, [[10, 28]]);
740
1106
  }));
741
- function getProductsWithPrice(_x7, _x8, _x9) {
1107
+ function getProductsWithPrice(_x12, _x13, _x14) {
742
1108
  return _getProductsWithPrice.apply(this, arguments);
743
1109
  }
744
1110
  return getProductsWithPrice;
@@ -756,10 +1122,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
756
1122
  }, {
757
1123
  key: "prepareProductsWithPrice",
758
1124
  value: (function () {
759
- var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(schedule_date, extraContext, options) {
1125
+ var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(schedule_date, extraContext, options) {
760
1126
  var tTotal, targetIds, isIncremental, _this$core, _this$core2, products, ids, tIds, i, priceData, _priceData$length, _priceData, tPrice, context, tFormat, processedProducts, errorMessage;
761
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
762
- while (1) switch (_context7.prev = _context7.next) {
1127
+ return _regeneratorRuntime().wrap(function _callee14$(_context15) {
1128
+ while (1) switch (_context15.prev = _context15.next) {
763
1129
  case 0:
764
1130
  tTotal = performance.now();
765
1131
  targetIds = options === null || options === void 0 ? void 0 : options.productIds;
@@ -769,7 +1135,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
769
1135
  mode: isIncremental ? 'incremental' : 'full',
770
1136
  targetIdsCount: targetIds === null || targetIds === void 0 ? void 0 : targetIds.length
771
1137
  });
772
- _context7.prev = 4;
1138
+ _context15.prev = 4;
773
1139
  // 1. 获取商品列表:指定 IDs 时从 store 取子集,否则取全量
774
1140
 
775
1141
  if (isIncremental) {
@@ -795,11 +1161,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
795
1161
  // 2. 仅在 legacy 报价单 formatter 启用时加载报价单价格;默认由智能定价覆盖商品价格。
796
1162
  priceData = [];
797
1163
  if (!this.isLegacyPriceFormatterEnabled) {
798
- _context7.next = 15;
1164
+ _context15.next = 15;
799
1165
  break;
800
1166
  }
801
1167
  tPrice = performance.now();
802
- _context7.next = 12;
1168
+ _context15.next = 12;
803
1169
  return this.loadProductsPrice({
804
1170
  ids: ids,
805
1171
  schedule_date: schedule_date,
@@ -807,7 +1173,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
807
1173
  customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id
808
1174
  });
809
1175
  case 12:
810
- priceData = _context7.sent;
1176
+ priceData = _context15.sent;
811
1177
  perfMark('prepareProducts.loadPrice', performance.now() - tPrice, {
812
1178
  count: ids.length
813
1179
  });
@@ -827,10 +1193,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
827
1193
  strategy_context: extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context
828
1194
  }, extraContext); // 3. 通过格式化器流程处理商品
829
1195
  tFormat = performance.now();
830
- _context7.next = 19;
1196
+ _context15.next = 19;
831
1197
  return this.applyFormatters(products, context);
832
1198
  case 19:
833
- processedProducts = _context7.sent;
1199
+ processedProducts = _context15.sent;
834
1200
  perfMark('prepareProducts.applyFormatters', performance.now() - tFormat, {
835
1201
  count: products.length,
836
1202
  formatterCount: this.formatters.length
@@ -842,10 +1208,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
842
1208
  formatterCount: this.formatters.length
843
1209
  });
844
1210
  if (isIncremental) {
845
- _context7.next = 25;
1211
+ _context15.next = 25;
846
1212
  break;
847
1213
  }
848
- _context7.next = 25;
1214
+ _context15.next = 25;
849
1215
  return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
850
1216
  case 25:
851
1217
  perfMark('prepareProductsWithPrice', performance.now() - tTotal, {
@@ -853,24 +1219,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
853
1219
  formatterCount: this.formatters.length,
854
1220
  mode: isIncremental ? 'incremental' : 'full'
855
1221
  });
856
- return _context7.abrupt("return", processedProducts);
1222
+ return _context15.abrupt("return", processedProducts);
857
1223
  case 29:
858
- _context7.prev = 29;
859
- _context7.t0 = _context7["catch"](4);
860
- errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
1224
+ _context15.prev = 29;
1225
+ _context15.t0 = _context15["catch"](4);
1226
+ errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
861
1227
  this.logError('prepareProductsWithPrice 处理失败', {
862
1228
  schedule_date: schedule_date,
863
1229
  error: errorMessage
864
1230
  });
865
1231
  case 33:
866
- return _context7.abrupt("return", []);
1232
+ return _context15.abrupt("return", []);
867
1233
  case 34:
868
1234
  case "end":
869
- return _context7.stop();
1235
+ return _context15.stop();
870
1236
  }
871
- }, _callee7, this, [[4, 29]]);
1237
+ }, _callee14, this, [[4, 29]]);
872
1238
  }));
873
- function prepareProductsWithPrice(_x10, _x11, _x12) {
1239
+ function prepareProductsWithPrice(_x15, _x16, _x17) {
874
1240
  return _prepareProductsWithPrice.apply(this, arguments);
875
1241
  }
876
1242
  return prepareProductsWithPrice;
@@ -878,9 +1244,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
878
1244
  }, {
879
1245
  key: "getProductsPriceCacheKey",
880
1246
  value: function getProductsPriceCacheKey(schedule_date, extraContext, productIds) {
881
- var _ref13, _extraContext$locale, _this$core3, _extraContext$custome;
1247
+ var _ref15, _extraContext$locale, _this$core3, _extraContext$custome;
882
1248
  var datetime = (extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime) || schedule_date;
883
- var locale = (_ref13 = (_extraContext$locale = extraContext === null || extraContext === void 0 ? void 0 : extraContext.locale) !== null && _extraContext$locale !== void 0 ? _extraContext$locale : (_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.locale) !== null && _ref13 !== void 0 ? _ref13 : '';
1249
+ var locale = (_ref15 = (_extraContext$locale = extraContext === null || extraContext === void 0 ? void 0 : extraContext.locale) !== null && _extraContext$locale !== void 0 ? _extraContext$locale : (_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.locale) !== null && _ref15 !== void 0 ? _ref15 : '';
884
1250
  var productScope = productIds ? ":products:".concat(productIds.join(',')) : '';
885
1251
  var strategyScope = this.stringifyStable((extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context) || {});
886
1252
  return "".concat(datetime, ":locale:").concat(locale, ":customer:").concat((_extraContext$custome = extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id) !== null && _extraContext$custome !== void 0 ? _extraContext$custome : '') + ":strategy:".concat(strategyScope).concat(productScope);
@@ -892,14 +1258,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
892
1258
  }, {
893
1259
  key: "stringifyStable",
894
1260
  value: function stringifyStable(value) {
895
- var _this7 = this;
1261
+ var _this9 = this;
896
1262
  if (value == null) return '';
897
1263
  if (Array.isArray(value)) return "[".concat(value.map(function (item) {
898
- return _this7.stringifyStable(item);
1264
+ return _this9.stringifyStable(item);
899
1265
  }).join(','), "]");
900
1266
  if (_typeof(value) === 'object') {
901
1267
  return "{".concat(Object.keys(value).sort().map(function (key) {
902
- return "".concat(key, ":").concat(_this7.stringifyStable(value[key]));
1268
+ return "".concat(key, ":").concat(_this9.stringifyStable(value[key]));
903
1269
  }).join(','), "}");
904
1270
  }
905
1271
  return String(value);
@@ -932,25 +1298,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
932
1298
  }
933
1299
  if (productIds.length === 0 && collectionIds.length === 0) return [];
934
1300
  var result = new Set();
935
- var _iterator4 = _createForOfIteratorHelper(productIds),
936
- _step4;
1301
+ var _iterator7 = _createForOfIteratorHelper(productIds),
1302
+ _step7;
937
1303
  try {
938
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
939
- var id = _step4.value;
1304
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1305
+ var id = _step7.value;
940
1306
  if (this.store.map.has(id)) result.add(id);
941
1307
  }
942
1308
  } catch (err) {
943
- _iterator4.e(err);
1309
+ _iterator7.e(err);
944
1310
  } finally {
945
- _iterator4.f();
1311
+ _iterator7.f();
946
1312
  }
947
1313
  if (collectionIds.length === 0) return Array.from(result);
948
1314
  var collectionIdSet = new Set(collectionIds);
949
- var _iterator5 = _createForOfIteratorHelper(this.getProductsRef()),
950
- _step5;
1315
+ var _iterator8 = _createForOfIteratorHelper(this.getProductsRef()),
1316
+ _step8;
951
1317
  try {
952
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
953
- var product = _step5.value;
1318
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1319
+ var product = _step8.value;
954
1320
  if (result.has(product.id)) continue;
955
1321
  if (!Array.isArray(product.collection)) continue;
956
1322
  var isInCollection = product.collection.some(function (collection) {
@@ -959,9 +1325,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
959
1325
  if (isInCollection) result.add(product.id);
960
1326
  }
961
1327
  } catch (err) {
962
- _iterator5.e(err);
1328
+ _iterator8.e(err);
963
1329
  } finally {
964
- _iterator5.f();
1330
+ _iterator8.f();
965
1331
  }
966
1332
  return Array.from(result);
967
1333
  }
@@ -976,21 +1342,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
976
1342
  }, {
977
1343
  key: "applyFormatters",
978
1344
  value: (function () {
979
- var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(products, context) {
1345
+ var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(products, context) {
980
1346
  var result, i, formatter, tF, errorMessage;
981
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
982
- while (1) switch (_context8.prev = _context8.next) {
1347
+ return _regeneratorRuntime().wrap(function _callee15$(_context16) {
1348
+ while (1) switch (_context16.prev = _context16.next) {
983
1349
  case 0:
984
1350
  result = products;
985
1351
  if (!(this.formatters.length === 0)) {
986
- _context8.next = 5;
1352
+ _context16.next = 5;
987
1353
  break;
988
1354
  }
989
1355
  console.warn('[ProductsModule] ⚠️ 没有注册任何格式化器');
990
1356
  this.logWarning('没有注册任何格式化器', {
991
1357
  productCount: products.length
992
1358
  });
993
- return _context8.abrupt("return", result);
1359
+ return _context16.abrupt("return", result);
994
1360
  case 5:
995
1361
  this.logInfo('开始应用格式化器', {
996
1362
  productCount: products.length,
@@ -999,28 +1365,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
999
1365
  i = 0;
1000
1366
  case 7:
1001
1367
  if (!(i < this.formatters.length)) {
1002
- _context8.next = 25;
1368
+ _context16.next = 25;
1003
1369
  break;
1004
1370
  }
1005
1371
  formatter = this.formatters[i];
1006
- _context8.prev = 9;
1372
+ _context16.prev = 9;
1007
1373
  tF = performance.now();
1008
- _context8.next = 13;
1374
+ _context16.next = 13;
1009
1375
  return formatter(result, context);
1010
1376
  case 13:
1011
- result = _context8.sent;
1377
+ result = _context16.sent;
1012
1378
  perfMark("applyFormatters[".concat(i, "]"), performance.now() - tF, {
1013
1379
  index: i,
1014
1380
  total: this.formatters.length,
1015
1381
  productCount: result.length
1016
1382
  });
1017
- _context8.next = 22;
1383
+ _context16.next = 22;
1018
1384
  break;
1019
1385
  case 17:
1020
- _context8.prev = 17;
1021
- _context8.t0 = _context8["catch"](9);
1022
- errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
1023
- console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context8.t0);
1386
+ _context16.prev = 17;
1387
+ _context16.t0 = _context16["catch"](9);
1388
+ errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
1389
+ console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context16.t0);
1024
1390
  this.logError("\u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25"), {
1025
1391
  formatterIndex: i + 1,
1026
1392
  totalFormatters: this.formatters.length,
@@ -1028,21 +1394,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1028
1394
  });
1029
1395
  case 22:
1030
1396
  i++;
1031
- _context8.next = 7;
1397
+ _context16.next = 7;
1032
1398
  break;
1033
1399
  case 25:
1034
1400
  this.logInfo('所有格式化器已应用', {
1035
1401
  formatterCount: this.formatters.length,
1036
1402
  resultProductCount: result.length
1037
1403
  });
1038
- return _context8.abrupt("return", result);
1404
+ return _context16.abrupt("return", result);
1039
1405
  case 27:
1040
1406
  case "end":
1041
- return _context8.stop();
1407
+ return _context16.stop();
1042
1408
  }
1043
- }, _callee8, this, [[9, 17]]);
1409
+ }, _callee15, this, [[9, 17]]);
1044
1410
  }));
1045
- function applyFormatters(_x13, _x14) {
1411
+ function applyFormatters(_x18, _x19) {
1046
1412
  return _applyFormatters.apply(this, arguments);
1047
1413
  }
1048
1414
  return applyFormatters;
@@ -1057,18 +1423,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1057
1423
  }, {
1058
1424
  key: "registerBuiltinProductFormatters",
1059
1425
  value: function registerBuiltinProductFormatters() {
1060
- var _this8 = this;
1426
+ var _this10 = this;
1061
1427
  if (this.isBuiltinFormatterRegistered) {
1062
1428
  console.warn('[ProductsModule] 内置商品格式化器已注册,跳过');
1063
1429
  return;
1064
1430
  }
1065
1431
  this.isLegacyPriceFormatterEnabled = this.shouldEnableLegacyPriceFormatter();
1066
1432
  var dataVariantFormatter = function dataVariantFormatter(products, context) {
1067
- var _this8$core, _strategyContext$busi;
1068
- var evaluator = context.dataVariantEvaluator || ((_this8$core = _this8.core) === null || _this8$core === void 0 || (_this8$core = _this8$core.context) === null || _this8$core === void 0 ? void 0 : _this8$core.dataVariantEvaluator);
1433
+ var _this10$core, _strategyContext$busi;
1434
+ var evaluator = context.dataVariantEvaluator || ((_this10$core = _this10.core) === null || _this10$core === void 0 || (_this10$core = _this10$core.context) === null || _this10$core === void 0 ? void 0 : _this10$core.dataVariantEvaluator);
1069
1435
  if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
1070
- _this8.lastScheduleTimePoints = [];
1071
- _this8.logWarning('智能定价评估器未注入,跳过 DataVariant 格式化', {
1436
+ _this10.lastScheduleTimePoints = [];
1437
+ _this10.logWarning('智能定价评估器未注入,跳过 DataVariant 格式化', {
1072
1438
  productCount: products.length
1073
1439
  });
1074
1440
  return products;
@@ -1087,7 +1453,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1087
1453
  custom: strategyContext
1088
1454
  };
1089
1455
  var result = evaluator.resolveProducts(businessData);
1090
- _this8.lastScheduleTimePoints = Array.isArray(result === null || result === void 0 ? void 0 : result.scheduleTimePoints) ? _toConsumableArray(result.scheduleTimePoints) : [];
1456
+ _this10.lastScheduleTimePoints = Array.isArray(result === null || result === void 0 ? void 0 : result.scheduleTimePoints) ? _toConsumableArray(result.scheduleTimePoints) : [];
1091
1457
  return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
1092
1458
  };
1093
1459
 
@@ -1194,6 +1560,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1194
1560
  var keys = Array.from(this.productsPriceCache.keys());
1195
1561
  var oldestKey = keys[0];
1196
1562
  this.productsPriceCache.delete(oldestKey);
1563
+ this.replicaPriceDirtyIds.delete(oldestKey);
1197
1564
  }
1198
1565
  }
1199
1566
 
@@ -1205,6 +1572,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1205
1572
  key: "clearPriceCache",
1206
1573
  value: function clearPriceCache() {
1207
1574
  this.productsPriceCache.clear();
1575
+ this.replicaPriceDirtyIds.clear();
1208
1576
  this.quotationScheduleCache.clear();
1209
1577
  this.quotationScheduleCacheLoaded = false;
1210
1578
  }
@@ -1215,7 +1583,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1215
1583
  }, {
1216
1584
  key: "loadProductsByServer",
1217
1585
  value: (function () {
1218
- var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1586
+ var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1219
1587
  var options,
1220
1588
  trigger,
1221
1589
  t0,
@@ -1224,32 +1592,44 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1224
1592
  list,
1225
1593
  duration,
1226
1594
  errorMessage,
1227
- _args9 = arguments;
1228
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1229
- while (1) switch (_context9.prev = _context9.next) {
1595
+ _args17 = arguments;
1596
+ return _regeneratorRuntime().wrap(function _callee16$(_context17) {
1597
+ while (1) switch (_context17.prev = _context17.next) {
1230
1598
  case 0:
1231
- options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1599
+ options = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : {};
1600
+ if (!this.isMemoryReplica()) {
1601
+ _context17.next = 3;
1602
+ break;
1603
+ }
1604
+ return _context17.abrupt("return", this.refreshFromReplica(options.trigger || 'loadProductsByServer'));
1605
+ case 3:
1232
1606
  if (this.productDataSource) {
1233
- _context9.next = 4;
1607
+ _context17.next = 6;
1234
1608
  break;
1235
1609
  }
1236
1610
  this.logWarning('loadProductsByServer: ProductDataSource 不可用');
1237
- return _context9.abrupt("return", []);
1238
- case 4:
1611
+ return _context17.abrupt("return", []);
1612
+ case 6:
1239
1613
  trigger = options.trigger || 'unknown';
1240
1614
  this.logInfo('开始通过 DataSource SSE 加载商品列表', {
1241
1615
  trigger: trigger
1242
1616
  });
1243
1617
  t0 = performance.now();
1244
- _context9.prev = 7;
1618
+ _context17.prev = 9;
1245
1619
  tSSE = performance.now();
1246
- _context9.next = 11;
1620
+ _context17.next = 13;
1247
1621
  return this.productDataSource.run({
1248
1622
  sse: {}
1249
1623
  });
1250
- case 11:
1251
- productList = _context9.sent;
1624
+ case 13:
1625
+ productList = _context17.sent;
1252
1626
  list = productList || [];
1627
+ if (!this.isMemoryReplica()) {
1628
+ _context17.next = 17;
1629
+ break;
1630
+ }
1631
+ return _context17.abrupt("return", this.store.list);
1632
+ case 17:
1253
1633
  perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
1254
1634
  count: list.length
1255
1635
  });
@@ -1258,34 +1638,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1258
1638
  productCount: list.length,
1259
1639
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1260
1640
  });
1261
- _context9.next = 17;
1641
+ _context17.next = 21;
1262
1642
  return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
1263
- case 17:
1643
+ case 21:
1264
1644
  this.lastServerFullFetchAtMs = Date.now();
1265
- _context9.next = 20;
1645
+ _context17.next = 24;
1266
1646
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
1267
- case 20:
1647
+ case 24:
1268
1648
  perfMark('loadProductsByServer', performance.now() - t0, {
1269
1649
  count: list.length
1270
1650
  });
1271
- return _context9.abrupt("return", list);
1272
- case 24:
1273
- _context9.prev = 24;
1274
- _context9.t0 = _context9["catch"](7);
1651
+ return _context17.abrupt("return", list);
1652
+ case 28:
1653
+ _context17.prev = 28;
1654
+ _context17.t0 = _context17["catch"](9);
1275
1655
  duration = Math.round(performance.now() - t0);
1276
- errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1277
- console.error('[Products] 加载商品数据失败:', _context9.t0);
1656
+ errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
1657
+ console.error('[Products] 加载商品数据失败:', _context17.t0);
1278
1658
  this.logError('通过 DataSource SSE 加载商品列表失败', {
1279
1659
  trigger: trigger,
1280
1660
  duration: "".concat(duration, "ms"),
1281
1661
  error: errorMessage
1282
1662
  });
1283
- return _context9.abrupt("return", []);
1284
- case 31:
1663
+ return _context17.abrupt("return", []);
1664
+ case 35:
1285
1665
  case "end":
1286
- return _context9.stop();
1666
+ return _context17.stop();
1287
1667
  }
1288
- }, _callee9, this, [[7, 24]]);
1668
+ }, _callee16, this, [[9, 28]]);
1289
1669
  }));
1290
1670
  function loadProductsByServer() {
1291
1671
  return _loadProductsByServer.apply(this, arguments);
@@ -1301,12 +1681,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1301
1681
  }, {
1302
1682
  key: "fetchProductsByHttp",
1303
1683
  value: (function () {
1304
- var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
1305
- var _ref14, _ref14$category_ids, category_ids, _ref14$product_ids, product_ids, _ref14$collection, collection, customer_id, cacheId, startTime, _this$otherParams4, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
1306
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1307
- while (1) switch (_context10.prev = _context10.next) {
1684
+ var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1685
+ var _ref16, _ref16$category_ids, category_ids, _ref16$product_ids, product_ids, _ref16$collection, collection, customer_id, cacheId, startTime, _this$otherParams4, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
1686
+ return _regeneratorRuntime().wrap(function _callee17$(_context18) {
1687
+ while (1) switch (_context18.prev = _context18.next) {
1308
1688
  case 0:
1309
- _ref14 = params || {}, _ref14$category_ids = _ref14.category_ids, category_ids = _ref14$category_ids === void 0 ? [] : _ref14$category_ids, _ref14$product_ids = _ref14.product_ids, product_ids = _ref14$product_ids === void 0 ? [] : _ref14$product_ids, _ref14$collection = _ref14.collection, collection = _ref14$collection === void 0 ? [] : _ref14$collection, customer_id = _ref14.customer_id, cacheId = _ref14.cacheId;
1689
+ _ref16 = params || {}, _ref16$category_ids = _ref16.category_ids, category_ids = _ref16$category_ids === void 0 ? [] : _ref16$category_ids, _ref16$product_ids = _ref16.product_ids, product_ids = _ref16$product_ids === void 0 ? [] : _ref16$product_ids, _ref16$collection = _ref16.collection, collection = _ref16$collection === void 0 ? [] : _ref16$collection, customer_id = _ref16.customer_id, cacheId = _ref16.cacheId;
1310
1690
  this.logInfo('fetchProductsByHttp: 开始请求', {
1311
1691
  categoryIdsCount: category_ids.length,
1312
1692
  productIdsCount: product_ids.length,
@@ -1314,8 +1694,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1314
1694
  customer_id: customer_id
1315
1695
  });
1316
1696
  startTime = Date.now();
1317
- _context10.prev = 3;
1318
- _context10.next = 6;
1697
+ _context18.prev = 3;
1698
+ _context18.next = 6;
1319
1699
  return this.request.post("/product/query", {
1320
1700
  open_bundle: 1,
1321
1701
  exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
@@ -1337,32 +1717,32 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1337
1717
  cache: undefined
1338
1718
  });
1339
1719
  case 6:
1340
- productsData = _context10.sent;
1720
+ productsData = _context18.sent;
1341
1721
  productList = (productsData === null || productsData === void 0 || (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.list) || [];
1342
1722
  duration = Date.now() - startTime;
1343
1723
  this.logInfo('fetchProductsByHttp: 请求成功', {
1344
1724
  productCount: productList.length,
1345
1725
  duration: "".concat(duration, "ms")
1346
1726
  });
1347
- return _context10.abrupt("return", productList);
1727
+ return _context18.abrupt("return", productList);
1348
1728
  case 13:
1349
- _context10.prev = 13;
1350
- _context10.t0 = _context10["catch"](3);
1729
+ _context18.prev = 13;
1730
+ _context18.t0 = _context18["catch"](3);
1351
1731
  _duration2 = Date.now() - startTime;
1352
- errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
1353
- console.error('[Products] fetchProductsByHttp 失败:', _context10.t0);
1732
+ errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1733
+ console.error('[Products] fetchProductsByHttp 失败:', _context18.t0);
1354
1734
  this.logError('fetchProductsByHttp: 请求失败', {
1355
1735
  duration: "".concat(_duration2, "ms"),
1356
1736
  error: errorMessage
1357
1737
  });
1358
- return _context10.abrupt("return", []);
1738
+ return _context18.abrupt("return", []);
1359
1739
  case 20:
1360
1740
  case "end":
1361
- return _context10.stop();
1741
+ return _context18.stop();
1362
1742
  }
1363
- }, _callee10, this, [[3, 13]]);
1743
+ }, _callee17, this, [[3, 13]]);
1364
1744
  }));
1365
- function fetchProductsByHttp(_x15) {
1745
+ function fetchProductsByHttp(_x20) {
1366
1746
  return _fetchProductsByHttp.apply(this, arguments);
1367
1747
  }
1368
1748
  return fetchProductsByHttp;
@@ -1376,34 +1756,46 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1376
1756
  }, {
1377
1757
  key: "loadProductsByServerHttp",
1378
1758
  value: (function () {
1379
- var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
1759
+ var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1380
1760
  var productList;
1381
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1382
- while (1) switch (_context11.prev = _context11.next) {
1761
+ return _regeneratorRuntime().wrap(function _callee18$(_context19) {
1762
+ while (1) switch (_context19.prev = _context19.next) {
1383
1763
  case 0:
1384
- _context11.next = 2;
1385
- return this.fetchProductsByHttp(params);
1764
+ if (!this.isMemoryReplica()) {
1765
+ _context19.next = 2;
1766
+ break;
1767
+ }
1768
+ return _context19.abrupt("return", this.refreshFromReplica('loadProductsByServerHttp'));
1386
1769
  case 2:
1387
- productList = _context11.sent;
1770
+ _context19.next = 4;
1771
+ return this.fetchProductsByHttp(params);
1772
+ case 4:
1773
+ productList = _context19.sent;
1774
+ if (!this.isMemoryReplica()) {
1775
+ _context19.next = 7;
1776
+ break;
1777
+ }
1778
+ return _context19.abrupt("return", this.store.list);
1779
+ case 7:
1388
1780
  if (!(productList.length > 0)) {
1389
- _context11.next = 9;
1781
+ _context19.next = 13;
1390
1782
  break;
1391
1783
  }
1392
- _context11.next = 6;
1784
+ _context19.next = 10;
1393
1785
  return this.replaceProductsSnapshotInIndexDB(productList, 'loadProductsByServerHttp');
1394
- case 6:
1786
+ case 10:
1395
1787
  this.lastServerFullFetchAtMs = Date.now();
1396
- _context11.next = 9;
1788
+ _context19.next = 13;
1397
1789
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
1398
- case 9:
1399
- return _context11.abrupt("return", productList);
1400
- case 10:
1790
+ case 13:
1791
+ return _context19.abrupt("return", productList);
1792
+ case 14:
1401
1793
  case "end":
1402
- return _context11.stop();
1794
+ return _context19.stop();
1403
1795
  }
1404
- }, _callee11, this);
1796
+ }, _callee18, this);
1405
1797
  }));
1406
- function loadProductsByServerHttp(_x16) {
1798
+ function loadProductsByServerHttp(_x21) {
1407
1799
  return _loadProductsByServerHttp.apply(this, arguments);
1408
1800
  }
1409
1801
  return loadProductsByServerHttp;
@@ -1415,22 +1807,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1415
1807
  }, {
1416
1808
  key: "getProducts",
1417
1809
  value: (function () {
1418
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1810
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1419
1811
  var t0, result;
1420
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1421
- while (1) switch (_context12.prev = _context12.next) {
1812
+ return _regeneratorRuntime().wrap(function _callee19$(_context20) {
1813
+ while (1) switch (_context20.prev = _context20.next) {
1422
1814
  case 0:
1423
1815
  t0 = performance.now();
1424
1816
  result = structuredClone(this.store.list);
1425
1817
  perfMark('ProductsModule.getProducts(structuredClone)', performance.now() - t0, {
1426
1818
  count: result.length
1427
1819
  });
1428
- return _context12.abrupt("return", result);
1820
+ return _context20.abrupt("return", result);
1429
1821
  case 4:
1430
1822
  case "end":
1431
- return _context12.stop();
1823
+ return _context20.stop();
1432
1824
  }
1433
- }, _callee12, this);
1825
+ }, _callee19, this);
1434
1826
  }));
1435
1827
  function getProducts() {
1436
1828
  return _getProducts.apply(this, arguments);
@@ -1444,63 +1836,63 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1444
1836
  }, {
1445
1837
  key: "getProductSnapshotsByIds",
1446
1838
  value: (function () {
1447
- var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
1448
- var snapshots, seen, _iterator6, _step6, _resolveProductHolder, id, product;
1449
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1450
- while (1) switch (_context13.prev = _context13.next) {
1839
+ var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(ids) {
1840
+ var snapshots, seen, _iterator9, _step9, _resolveProductHolder, id, product;
1841
+ return _regeneratorRuntime().wrap(function _callee20$(_context21) {
1842
+ while (1) switch (_context21.prev = _context21.next) {
1451
1843
  case 0:
1452
1844
  snapshots = {};
1453
1845
  seen = new Set();
1454
- _iterator6 = _createForOfIteratorHelper(ids);
1455
- _context13.prev = 3;
1456
- _iterator6.s();
1846
+ _iterator9 = _createForOfIteratorHelper(ids);
1847
+ _context21.prev = 3;
1848
+ _iterator9.s();
1457
1849
  case 5:
1458
- if ((_step6 = _iterator6.n()).done) {
1459
- _context13.next = 16;
1850
+ if ((_step9 = _iterator9.n()).done) {
1851
+ _context21.next = 16;
1460
1852
  break;
1461
1853
  }
1462
- id = _step6.value;
1854
+ id = _step9.value;
1463
1855
  if (!(!Number.isFinite(id) || seen.has(id))) {
1464
- _context13.next = 9;
1856
+ _context21.next = 9;
1465
1857
  break;
1466
1858
  }
1467
- return _context13.abrupt("continue", 14);
1859
+ return _context21.abrupt("continue", 14);
1468
1860
  case 9:
1469
1861
  seen.add(id);
1470
1862
  product = this.store.map.get(id);
1471
1863
  if (product) {
1472
- _context13.next = 13;
1864
+ _context21.next = 13;
1473
1865
  break;
1474
1866
  }
1475
- return _context13.abrupt("continue", 14);
1867
+ return _context21.abrupt("continue", 14);
1476
1868
  case 13:
1477
1869
  snapshots[String(id)] = {
1478
1870
  cover: product.cover,
1479
1871
  holder_config: (_resolveProductHolder = resolveProductHolderConfig(product)) !== null && _resolveProductHolder !== void 0 ? _resolveProductHolder : undefined
1480
1872
  };
1481
1873
  case 14:
1482
- _context13.next = 5;
1874
+ _context21.next = 5;
1483
1875
  break;
1484
1876
  case 16:
1485
- _context13.next = 21;
1877
+ _context21.next = 21;
1486
1878
  break;
1487
1879
  case 18:
1488
- _context13.prev = 18;
1489
- _context13.t0 = _context13["catch"](3);
1490
- _iterator6.e(_context13.t0);
1880
+ _context21.prev = 18;
1881
+ _context21.t0 = _context21["catch"](3);
1882
+ _iterator9.e(_context21.t0);
1491
1883
  case 21:
1492
- _context13.prev = 21;
1493
- _iterator6.f();
1494
- return _context13.finish(21);
1884
+ _context21.prev = 21;
1885
+ _iterator9.f();
1886
+ return _context21.finish(21);
1495
1887
  case 24:
1496
- return _context13.abrupt("return", snapshots);
1888
+ return _context21.abrupt("return", snapshots);
1497
1889
  case 25:
1498
1890
  case "end":
1499
- return _context13.stop();
1891
+ return _context21.stop();
1500
1892
  }
1501
- }, _callee13, this, [[3, 18, 21, 24]]);
1893
+ }, _callee20, this, [[3, 18, 21, 24]]);
1502
1894
  }));
1503
- function getProductSnapshotsByIds(_x17) {
1895
+ function getProductSnapshotsByIds(_x22) {
1504
1896
  return _getProductSnapshotsByIds.apply(this, arguments);
1505
1897
  }
1506
1898
  return getProductSnapshotsByIds;
@@ -1523,18 +1915,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1523
1915
  key: "getProductsRefByIds",
1524
1916
  value: function getProductsRefByIds(ids) {
1525
1917
  var products = [];
1526
- var _iterator7 = _createForOfIteratorHelper(ids),
1527
- _step7;
1918
+ var _iterator10 = _createForOfIteratorHelper(ids),
1919
+ _step10;
1528
1920
  try {
1529
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1530
- var id = _step7.value;
1921
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1922
+ var id = _step10.value;
1531
1923
  var product = this.store.map.get(id);
1532
1924
  if (product) products.push(product);
1533
1925
  }
1534
1926
  } catch (err) {
1535
- _iterator7.e(err);
1927
+ _iterator10.e(err);
1536
1928
  } finally {
1537
- _iterator7.f();
1929
+ _iterator10.f();
1538
1930
  }
1539
1931
  return products;
1540
1932
  }
@@ -1546,20 +1938,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1546
1938
  }, {
1547
1939
  key: "getProductById",
1548
1940
  value: (function () {
1549
- var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(id) {
1941
+ var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(id) {
1550
1942
  var product;
1551
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1552
- while (1) switch (_context14.prev = _context14.next) {
1943
+ return _regeneratorRuntime().wrap(function _callee21$(_context22) {
1944
+ while (1) switch (_context22.prev = _context22.next) {
1553
1945
  case 0:
1554
1946
  product = this.store.map.get(id);
1555
- return _context14.abrupt("return", product ? structuredClone(product) : undefined);
1947
+ return _context22.abrupt("return", product ? structuredClone(product) : undefined);
1556
1948
  case 2:
1557
1949
  case "end":
1558
- return _context14.stop();
1950
+ return _context22.stop();
1559
1951
  }
1560
- }, _callee14, this);
1952
+ }, _callee21, this);
1561
1953
  }));
1562
- function getProductById(_x18) {
1954
+ function getProductById(_x23) {
1563
1955
  return _getProductById.apply(this, arguments);
1564
1956
  }
1565
1957
  return getProductById;
@@ -1572,11 +1964,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1572
1964
  }, {
1573
1965
  key: "removeProductsByIds",
1574
1966
  value: (function () {
1575
- var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
1576
- var idSet, _iterator8, _step8, _id, _iterator9, _step9, id, errorMessage, _iterator10, _step10, _step10$value, dateKey, cachedProducts;
1577
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1578
- while (1) switch (_context15.prev = _context15.next) {
1967
+ var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(ids, options) {
1968
+ var idSet, _iterator11, _step11, id, _iterator12, _step12, _step12$value, dateKey, cachedProducts;
1969
+ return _regeneratorRuntime().wrap(function _callee22$(_context23) {
1970
+ while (1) switch (_context23.prev = _context23.next) {
1579
1971
  case 0:
1972
+ if (!(this.isMemoryReplica() && !(options !== null && options !== void 0 && options.skipIndexDB))) {
1973
+ _context23.next = 4;
1974
+ break;
1975
+ }
1976
+ _context23.next = 3;
1977
+ return this.refreshFromReplica('removeProducts');
1978
+ case 3:
1979
+ return _context23.abrupt("return");
1980
+ case 4:
1580
1981
  idSet = new Set(ids);
1581
1982
  this.logInfo('removeProductsByIds', {
1582
1983
  ids: ids,
@@ -1585,83 +1986,48 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1585
1986
  this.store.list = this.store.list.filter(function (p) {
1586
1987
  return !idSet.has(p.id);
1587
1988
  });
1588
- _iterator8 = _createForOfIteratorHelper(ids);
1989
+ _iterator11 = _createForOfIteratorHelper(ids);
1589
1990
  try {
1590
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1591
- _id = _step8.value;
1592
- this.store.map.delete(_id);
1991
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1992
+ id = _step11.value;
1993
+ this.store.map.delete(id);
1593
1994
  }
1594
1995
  } catch (err) {
1595
- _iterator8.e(err);
1996
+ _iterator11.e(err);
1596
1997
  } finally {
1597
- _iterator8.f();
1598
- }
1599
- if (!this.dbManager) {
1600
- _context15.next = 30;
1601
- break;
1998
+ _iterator11.f();
1602
1999
  }
1603
- _context15.prev = 6;
1604
- _iterator9 = _createForOfIteratorHelper(ids);
1605
- _context15.prev = 8;
1606
- _iterator9.s();
1607
- case 10:
1608
- if ((_step9 = _iterator9.n()).done) {
1609
- _context15.next = 16;
2000
+ if (options !== null && options !== void 0 && options.skipIndexDB) {
2001
+ _context23.next = 12;
1610
2002
  break;
1611
2003
  }
1612
- id = _step9.value;
1613
- _context15.next = 14;
1614
- return this.dbManager.delete(INDEXDB_STORE_NAME, id);
1615
- case 14:
1616
- _context15.next = 10;
1617
- break;
1618
- case 16:
1619
- _context15.next = 21;
1620
- break;
1621
- case 18:
1622
- _context15.prev = 18;
1623
- _context15.t0 = _context15["catch"](8);
1624
- _iterator9.e(_context15.t0);
1625
- case 21:
1626
- _context15.prev = 21;
1627
- _iterator9.f();
1628
- return _context15.finish(21);
1629
- case 24:
1630
- _context15.next = 30;
1631
- break;
1632
- case 26:
1633
- _context15.prev = 26;
1634
- _context15.t1 = _context15["catch"](6);
1635
- errorMessage = _context15.t1 instanceof Error ? _context15.t1.message : String(_context15.t1);
1636
- this.logError('removeProductsByIds: IndexDB 删除失败', {
1637
- ids: ids,
1638
- error: errorMessage
1639
- });
1640
- case 30:
1641
- _iterator10 = _createForOfIteratorHelper(this.productsPriceCache.entries());
2004
+ _context23.next = 12;
2005
+ return this.persistProductDelta([], ids, 'removeProductsByIds');
2006
+ case 12:
2007
+ _iterator12 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1642
2008
  try {
1643
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1644
- _step10$value = _slicedToArray(_step10.value, 2), dateKey = _step10$value[0], cachedProducts = _step10$value[1];
2009
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
2010
+ _step12$value = _slicedToArray(_step12.value, 2), dateKey = _step12$value[0], cachedProducts = _step12$value[1];
1645
2011
  this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
1646
2012
  return !idSet.has(p.id);
1647
2013
  }));
1648
2014
  }
1649
2015
  } catch (err) {
1650
- _iterator10.e(err);
2016
+ _iterator12.e(err);
1651
2017
  } finally {
1652
- _iterator10.f();
2018
+ _iterator12.f();
1653
2019
  }
1654
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2020
+ if (!(options !== null && options !== void 0 && options.skipEmit)) this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1655
2021
  this.logInfo('removeProductsByIds 完成', {
1656
2022
  remaining: this.store.list.length
1657
2023
  });
1658
- case 34:
2024
+ case 16:
1659
2025
  case "end":
1660
- return _context15.stop();
2026
+ return _context23.stop();
1661
2027
  }
1662
- }, _callee15, this, [[6, 26], [8, 18, 21, 24]]);
2028
+ }, _callee22, this);
1663
2029
  }));
1664
- function removeProductsByIds(_x19) {
2030
+ function removeProductsByIds(_x24, _x25) {
1665
2031
  return _removeProductsByIds.apply(this, arguments);
1666
2032
  }
1667
2033
  return removeProductsByIds;
@@ -1674,19 +2040,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1674
2040
  }, {
1675
2041
  key: "refreshProducts",
1676
2042
  value: (function () {
1677
- var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2043
+ var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1678
2044
  var tTotal, products;
1679
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1680
- while (1) switch (_context16.prev = _context16.next) {
2045
+ return _regeneratorRuntime().wrap(function _callee23$(_context24) {
2046
+ while (1) switch (_context24.prev = _context24.next) {
1681
2047
  case 0:
2048
+ if (!this.isMemoryReplica()) {
2049
+ _context24.next = 2;
2050
+ break;
2051
+ }
2052
+ return _context24.abrupt("return", this.refreshFromReplica('refreshProducts'));
2053
+ case 2:
1682
2054
  tTotal = performance.now();
1683
2055
  this.logInfo('refreshProducts 开始');
1684
- _context16.next = 4;
2056
+ _context24.next = 6;
1685
2057
  return this.loadProductsByServer({
1686
2058
  trigger: 'product_sync'
1687
2059
  });
1688
- case 4:
1689
- products = _context16.sent;
2060
+ case 6:
2061
+ products = _context24.sent;
1690
2062
  if (products && products.length > 0) {
1691
2063
  // 服务器返回的数据已经是全新的,无需 cloneDeep
1692
2064
  this.store.list = products;
@@ -1701,12 +2073,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1701
2073
  perfMark('refreshProducts', performance.now() - tTotal, {
1702
2074
  count: this.store.list.length
1703
2075
  });
1704
- return _context16.abrupt("return", this.store.list);
1705
- case 8:
2076
+ return _context24.abrupt("return", this.store.list);
2077
+ case 10:
1706
2078
  case "end":
1707
- return _context16.stop();
2079
+ return _context24.stop();
1708
2080
  }
1709
- }, _callee16, this);
2081
+ }, _callee23, this);
1710
2082
  }));
1711
2083
  function refreshProducts() {
1712
2084
  return _refreshProducts.apply(this, arguments);
@@ -1720,10 +2092,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1720
2092
  }, {
1721
2093
  key: "clear",
1722
2094
  value: (function () {
1723
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2095
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1724
2096
  var errorMessage;
1725
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1726
- while (1) switch (_context17.prev = _context17.next) {
2097
+ return _regeneratorRuntime().wrap(function _callee24$(_context25) {
2098
+ while (1) switch (_context25.prev = _context25.next) {
1727
2099
  case 0:
1728
2100
  this.logInfo('开始清空缓存', {
1729
2101
  currentProductCount: this.store.list.length,
@@ -1734,21 +2106,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1734
2106
 
1735
2107
  // 同时清空 IndexDB 中的所有数据(包括商品和元数据)
1736
2108
  if (!this.dbManager) {
1737
- _context17.next = 15;
2109
+ _context25.next = 15;
1738
2110
  break;
1739
2111
  }
1740
- _context17.prev = 4;
1741
- _context17.next = 7;
2112
+ _context25.prev = 4;
2113
+ _context25.next = 7;
1742
2114
  return this.dbManager.clear(INDEXDB_STORE_NAME);
1743
2115
  case 7:
1744
2116
  this.logInfo('IndexDB 缓存已清空');
1745
- _context17.next = 15;
2117
+ _context25.next = 15;
1746
2118
  break;
1747
2119
  case 10:
1748
- _context17.prev = 10;
1749
- _context17.t0 = _context17["catch"](4);
1750
- errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
1751
- console.error('[Products] 清空 IndexDB 缓存失败:', _context17.t0);
2120
+ _context25.prev = 10;
2121
+ _context25.t0 = _context25["catch"](4);
2122
+ errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
2123
+ console.error('[Products] 清空 IndexDB 缓存失败:', _context25.t0);
1752
2124
  this.logError('清空 IndexDB 缓存失败', {
1753
2125
  error: errorMessage
1754
2126
  });
@@ -1756,9 +2128,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1756
2128
  this.logInfo('缓存清空完成');
1757
2129
  case 16:
1758
2130
  case "end":
1759
- return _context17.stop();
2131
+ return _context25.stop();
1760
2132
  }
1761
- }, _callee17, this, [[4, 10]]);
2133
+ }, _callee24, this, [[4, 10]]);
1762
2134
  }));
1763
2135
  function clear() {
1764
2136
  return _clear.apply(this, arguments);
@@ -1773,24 +2145,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1773
2145
  }, {
1774
2146
  key: "loadProductsFromIndexDB",
1775
2147
  value: (function () {
1776
- var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2148
+ var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1777
2149
  var startedAt, _products$length, _products$length2, products, durationMs, errorMessage;
1778
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1779
- while (1) switch (_context18.prev = _context18.next) {
2150
+ return _regeneratorRuntime().wrap(function _callee25$(_context26) {
2151
+ while (1) switch (_context26.prev = _context26.next) {
1780
2152
  case 0:
1781
2153
  if (this.dbManager) {
1782
- _context18.next = 3;
2154
+ _context26.next = 3;
1783
2155
  break;
1784
2156
  }
1785
2157
  this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
1786
- return _context18.abrupt("return", []);
2158
+ return _context26.abrupt("return", []);
1787
2159
  case 3:
1788
2160
  startedAt = performance.now();
1789
- _context18.prev = 4;
1790
- _context18.next = 7;
2161
+ _context26.prev = 4;
2162
+ _context26.next = 7;
1791
2163
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
1792
2164
  case 7:
1793
- products = _context18.sent;
2165
+ products = _context26.sent;
1794
2166
  durationMs = +(performance.now() - startedAt).toFixed(2);
1795
2167
  perfMark('loadProductsFromIndexDB', durationMs, {
1796
2168
  count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
@@ -1799,22 +2171,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1799
2171
  productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0,
1800
2172
  durationMs: durationMs
1801
2173
  });
1802
- return _context18.abrupt("return", products || []);
2174
+ return _context26.abrupt("return", products || []);
1803
2175
  case 14:
1804
- _context18.prev = 14;
1805
- _context18.t0 = _context18["catch"](4);
1806
- errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1807
- console.error('[Products] 从 IndexDB 读取数据失败:', _context18.t0);
2176
+ _context26.prev = 14;
2177
+ _context26.t0 = _context26["catch"](4);
2178
+ errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
2179
+ console.error('[Products] 从 IndexDB 读取数据失败:', _context26.t0);
1808
2180
  this.logError('从 IndexDB 读取数据失败', {
1809
2181
  durationMs: +(performance.now() - startedAt).toFixed(2),
1810
2182
  error: errorMessage
1811
2183
  });
1812
- return _context18.abrupt("return", []);
2184
+ return _context26.abrupt("return", []);
1813
2185
  case 20:
1814
2186
  case "end":
1815
- return _context18.stop();
2187
+ return _context26.stop();
1816
2188
  }
1817
- }, _callee18, this, [[4, 14]]);
2189
+ }, _callee25, this, [[4, 14]]);
1818
2190
  }));
1819
2191
  function loadProductsFromIndexDB() {
1820
2192
  return _loadProductsFromIndexDB.apply(this, arguments);
@@ -1833,10 +2205,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1833
2205
  }, {
1834
2206
  key: "runInProductIndexDBSaveQueue",
1835
2207
  value: (function () {
1836
- var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(task) {
2208
+ var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(task) {
1837
2209
  var queuedTask;
1838
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1839
- while (1) switch (_context19.prev = _context19.next) {
2210
+ return _regeneratorRuntime().wrap(function _callee26$(_context27) {
2211
+ while (1) switch (_context27.prev = _context27.next) {
1840
2212
  case 0:
1841
2213
  queuedTask = this.productIndexDBSaveQueue.then(task, task);
1842
2214
  this.productIndexDBSaveQueue = queuedTask.then(function () {
@@ -1844,14 +2216,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1844
2216
  }, function () {
1845
2217
  return undefined;
1846
2218
  });
1847
- return _context19.abrupt("return", queuedTask);
2219
+ return _context27.abrupt("return", queuedTask);
1848
2220
  case 3:
1849
2221
  case "end":
1850
- return _context19.stop();
2222
+ return _context27.stop();
1851
2223
  }
1852
- }, _callee19, this);
2224
+ }, _callee26, this);
1853
2225
  }));
1854
- function runInProductIndexDBSaveQueue(_x20) {
2226
+ function runInProductIndexDBSaveQueue(_x26) {
1855
2227
  return _runInProductIndexDBSaveQueue.apply(this, arguments);
1856
2228
  }
1857
2229
  return runInProductIndexDBSaveQueue;
@@ -1866,64 +2238,77 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1866
2238
  }, {
1867
2239
  key: "replaceProductsSnapshotInIndexDB",
1868
2240
  value: (function () {
1869
- var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(products, source) {
1870
- var _this9 = this;
2241
+ var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(products, source) {
2242
+ var _this11 = this;
1871
2243
  var enqueuedAt, queueWaitMs, clearDurationMs, writeDurationMs, errorMessage;
1872
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1873
- while (1) switch (_context21.prev = _context21.next) {
2244
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2245
+ while (1) switch (_context29.prev = _context29.next) {
1874
2246
  case 0:
2247
+ if (!this.isMemoryReplica()) {
2248
+ _context29.next = 2;
2249
+ break;
2250
+ }
2251
+ return _context29.abrupt("return", false);
2252
+ case 2:
1875
2253
  if (this.dbManager) {
1876
- _context21.next = 3;
2254
+ _context29.next = 5;
1877
2255
  break;
1878
2256
  }
1879
2257
  this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
1880
- return _context21.abrupt("return");
1881
- case 3:
2258
+ return _context29.abrupt("return", false);
2259
+ case 5:
1882
2260
  enqueuedAt = performance.now();
1883
2261
  queueWaitMs = 0;
1884
2262
  clearDurationMs = 0;
1885
2263
  writeDurationMs = 0;
1886
- _context21.prev = 7;
1887
- _context21.next = 10;
1888
- return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2264
+ _context29.prev = 9;
2265
+ _context29.next = 12;
2266
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
1889
2267
  var operationStartedAt, clearStartedAt, writeStartedAt, executeDurationMs;
1890
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1891
- while (1) switch (_context20.prev = _context20.next) {
2268
+ return _regeneratorRuntime().wrap(function _callee27$(_context28) {
2269
+ while (1) switch (_context28.prev = _context28.next) {
1892
2270
  case 0:
1893
2271
  operationStartedAt = performance.now();
1894
2272
  queueWaitMs = +(operationStartedAt - enqueuedAt).toFixed(2);
1895
- _this9.logInfo('replaceProductsSnapshotInIndexDB 开始', {
2273
+ _this11.logInfo('replaceProductsSnapshotInIndexDB 开始', {
1896
2274
  source: source,
1897
2275
  productCount: products.length,
1898
2276
  queueWaitMs: queueWaitMs
1899
2277
  });
1900
2278
  clearStartedAt = performance.now();
1901
- _context20.prev = 4;
1902
- _context20.next = 7;
1903
- return _this9.dbManager.clear(INDEXDB_STORE_NAME);
2279
+ _context28.prev = 4;
2280
+ _context28.next = 7;
2281
+ return _this11.dbManager.clear(INDEXDB_STORE_NAME);
1904
2282
  case 7:
1905
- _context20.prev = 7;
2283
+ _context28.prev = 7;
1906
2284
  clearDurationMs = +(performance.now() - clearStartedAt).toFixed(2);
1907
- return _context20.finish(7);
2285
+ return _context28.finish(7);
1908
2286
  case 10:
1909
2287
  if (!(products.length > 0)) {
1910
- _context20.next = 18;
2288
+ _context28.next = 18;
1911
2289
  break;
1912
2290
  }
1913
2291
  writeStartedAt = performance.now();
1914
- _context20.prev = 12;
1915
- _context20.next = 15;
1916
- return _this9.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
2292
+ _context28.prev = 12;
2293
+ _context28.next = 15;
2294
+ return _this11.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1917
2295
  case 15:
1918
- _context20.prev = 15;
2296
+ _context28.prev = 15;
1919
2297
  writeDurationMs = +(performance.now() - writeStartedAt).toFixed(2);
1920
- return _context20.finish(15);
2298
+ return _context28.finish(15);
1921
2299
  case 18:
2300
+ _context28.next = 20;
2301
+ return _this11.recordProductCommit({
2302
+ kind: 'snapshot',
2303
+ upserts: products,
2304
+ deletedIds: []
2305
+ });
2306
+ case 20:
1922
2307
  executeDurationMs = +(performance.now() - operationStartedAt).toFixed(2);
1923
2308
  perfMark('replaceProductsSnapshotInIndexDB', executeDurationMs, {
1924
2309
  count: products.length
1925
2310
  });
1926
- _this9.logInfo('replaceProductsSnapshotInIndexDB 完成', {
2311
+ _this11.logInfo('replaceProductsSnapshotInIndexDB 完成', {
1927
2312
  source: source,
1928
2313
  productCount: products.length,
1929
2314
  queueWaitMs: queueWaitMs,
@@ -1932,19 +2317,19 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1932
2317
  executeDurationMs: executeDurationMs,
1933
2318
  totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2)
1934
2319
  });
1935
- case 21:
2320
+ case 23:
1936
2321
  case "end":
1937
- return _context20.stop();
2322
+ return _context28.stop();
1938
2323
  }
1939
- }, _callee20, null, [[4,, 7, 10], [12,, 15, 18]]);
2324
+ }, _callee27, null, [[4,, 7, 10], [12,, 15, 18]]);
1940
2325
  })));
1941
- case 10:
1942
- _context21.next = 16;
1943
- break;
1944
2326
  case 12:
1945
- _context21.prev = 12;
1946
- _context21.t0 = _context21["catch"](7);
1947
- errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
2327
+ return _context29.abrupt("return", true);
2328
+ case 15:
2329
+ _context29.prev = 15;
2330
+ _context29.t0 = _context29["catch"](9);
2331
+ this.productPersistenceFailed = true;
2332
+ errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
1948
2333
  this.logError('全量保存商品到 IndexDB 失败', {
1949
2334
  source: source,
1950
2335
  productCount: products.length,
@@ -1954,162 +2339,211 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1954
2339
  totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2),
1955
2340
  error: errorMessage
1956
2341
  });
1957
- case 16:
2342
+ return _context29.abrupt("return", false);
2343
+ case 21:
1958
2344
  case "end":
1959
- return _context21.stop();
2345
+ return _context29.stop();
1960
2346
  }
1961
- }, _callee21, this, [[7, 12]]);
2347
+ }, _callee28, this, [[9, 15]]);
1962
2348
  }));
1963
- function replaceProductsSnapshotInIndexDB(_x21, _x22) {
2349
+ function replaceProductsSnapshotInIndexDB(_x27, _x28) {
1964
2350
  return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
1965
2351
  }
1966
2352
  return replaceProductsSnapshotInIndexDB;
1967
- }()
1968
- /**
1969
- * 增量 upsert 商品到 IndexDB,不清空表;用于 pubsub 批次合并后的变更商品。
1970
- *
1971
- * @example
1972
- * await this.patchProductsInIndexDB(changedProducts, 'pubsub.processProductSyncMessages', mergeActions)
1973
- */
1974
- )
2353
+ }())
1975
2354
  }, {
1976
2355
  key: "patchProductsInIndexDB",
1977
- value: (function () {
1978
- var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(products, source) {
1979
- var _this10 = this;
1980
- var mergeActions,
1981
- validProducts,
1982
- errorMessage,
1983
- _args23 = arguments;
1984
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1985
- while (1) switch (_context23.prev = _context23.next) {
2356
+ value: function () {
2357
+ var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(products, source) {
2358
+ var _mergeActions,
2359
+ _args30 = arguments;
2360
+ return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2361
+ while (1) switch (_context30.prev = _context30.next) {
2362
+ case 0:
2363
+ _mergeActions = _args30.length > 2 && _args30[2] !== undefined ? _args30[2] : {};
2364
+ return _context30.abrupt("return", this.persistProductDelta(products, [], source));
2365
+ case 2:
2366
+ case "end":
2367
+ return _context30.stop();
2368
+ }
2369
+ }, _callee29, this);
2370
+ }));
2371
+ function patchProductsInIndexDB(_x29, _x30) {
2372
+ return _patchProductsInIndexDB.apply(this, arguments);
2373
+ }
2374
+ return patchProductsInIndexDB;
2375
+ }()
2376
+ }, {
2377
+ key: "persistProductDelta",
2378
+ value: function () {
2379
+ var _persistProductDelta = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(products, deletedIds, source) {
2380
+ var _this12 = this;
2381
+ var validProducts, startedAt;
2382
+ return _regeneratorRuntime().wrap(function _callee31$(_context32) {
2383
+ while (1) switch (_context32.prev = _context32.next) {
1986
2384
  case 0:
1987
- mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
1988
- if (!(!this.dbManager || products.length === 0)) {
1989
- _context23.next = 3;
2385
+ if (!(this.isMemoryReplica() || !this.dbManager)) {
2386
+ _context32.next = 2;
1990
2387
  break;
1991
2388
  }
1992
- return _context23.abrupt("return");
1993
- case 3:
2389
+ return _context32.abrupt("return", false);
2390
+ case 2:
1994
2391
  validProducts = products.filter(function (p) {
1995
2392
  return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
1996
2393
  });
1997
- if (!(validProducts.length === 0)) {
1998
- _context23.next = 6;
2394
+ if (!(!validProducts.length && !deletedIds.length)) {
2395
+ _context32.next = 5;
1999
2396
  break;
2000
2397
  }
2001
- return _context23.abrupt("return");
2002
- case 6:
2003
- _context23.prev = 6;
2004
- _context23.next = 9;
2005
- return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
2006
- var t0, _iterator11, _step11, product;
2007
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2008
- while (1) switch (_context22.prev = _context22.next) {
2398
+ return _context32.abrupt("return", true);
2399
+ case 5:
2400
+ startedAt = performance.now();
2401
+ _context32.prev = 6;
2402
+ _context32.next = 9;
2403
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2404
+ var _iterator13, _step13, id, _iterator14, _step14, product;
2405
+ return _regeneratorRuntime().wrap(function _callee30$(_context31) {
2406
+ while (1) switch (_context31.prev = _context31.next) {
2009
2407
  case 0:
2010
- _this10.logInfo('patchProductsInIndexDB 开始', {
2011
- source: source,
2012
- count: validProducts.length
2013
- });
2014
- t0 = performance.now();
2015
- if (!(typeof _this10.dbManager.bulkUpdate === 'function')) {
2016
- _context22.next = 7;
2408
+ _iterator13 = _createForOfIteratorHelper(deletedIds);
2409
+ _context31.prev = 1;
2410
+ _iterator13.s();
2411
+ case 3:
2412
+ if ((_step13 = _iterator13.n()).done) {
2413
+ _context31.next = 9;
2017
2414
  break;
2018
2415
  }
2019
- _context22.next = 5;
2020
- return _this10.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
2021
- case 5:
2022
- _context22.next = 25;
2023
- break;
2416
+ id = _step13.value;
2417
+ _context31.next = 7;
2418
+ return _this12.dbManager.delete(INDEXDB_STORE_NAME, id);
2024
2419
  case 7:
2025
- if (!(typeof _this10.dbManager.update === 'function')) {
2026
- _context22.next = 25;
2420
+ _context31.next = 3;
2421
+ break;
2422
+ case 9:
2423
+ _context31.next = 14;
2424
+ break;
2425
+ case 11:
2426
+ _context31.prev = 11;
2427
+ _context31.t0 = _context31["catch"](1);
2428
+ _iterator13.e(_context31.t0);
2429
+ case 14:
2430
+ _context31.prev = 14;
2431
+ _iterator13.f();
2432
+ return _context31.finish(14);
2433
+ case 17:
2434
+ if (!validProducts.length) {
2435
+ _context31.next = 44;
2027
2436
  break;
2028
2437
  }
2029
- _iterator11 = _createForOfIteratorHelper(validProducts);
2030
- _context22.prev = 9;
2031
- _iterator11.s();
2032
- case 11:
2033
- if ((_step11 = _iterator11.n()).done) {
2034
- _context22.next = 17;
2438
+ if (!(typeof _this12.dbManager.bulkUpdate === 'function')) {
2439
+ _context31.next = 23;
2035
2440
  break;
2036
2441
  }
2037
- product = _step11.value;
2038
- _context22.next = 15;
2039
- return _this10.dbManager.update(INDEXDB_STORE_NAME, product);
2040
- case 15:
2041
- _context22.next = 11;
2442
+ _context31.next = 21;
2443
+ return _this12.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
2444
+ case 21:
2445
+ _context31.next = 44;
2042
2446
  break;
2043
- case 17:
2044
- _context22.next = 22;
2447
+ case 23:
2448
+ if (!(typeof _this12.dbManager.update === 'function')) {
2449
+ _context31.next = 43;
2450
+ break;
2451
+ }
2452
+ _iterator14 = _createForOfIteratorHelper(validProducts);
2453
+ _context31.prev = 25;
2454
+ _iterator14.s();
2455
+ case 27:
2456
+ if ((_step14 = _iterator14.n()).done) {
2457
+ _context31.next = 33;
2458
+ break;
2459
+ }
2460
+ product = _step14.value;
2461
+ _context31.next = 31;
2462
+ return _this12.dbManager.update(INDEXDB_STORE_NAME, product);
2463
+ case 31:
2464
+ _context31.next = 27;
2465
+ break;
2466
+ case 33:
2467
+ _context31.next = 38;
2468
+ break;
2469
+ case 35:
2470
+ _context31.prev = 35;
2471
+ _context31.t1 = _context31["catch"](25);
2472
+ _iterator14.e(_context31.t1);
2473
+ case 38:
2474
+ _context31.prev = 38;
2475
+ _iterator14.f();
2476
+ return _context31.finish(38);
2477
+ case 41:
2478
+ _context31.next = 44;
2045
2479
  break;
2046
- case 19:
2047
- _context22.prev = 19;
2048
- _context22.t0 = _context22["catch"](9);
2049
- _iterator11.e(_context22.t0);
2050
- case 22:
2051
- _context22.prev = 22;
2052
- _iterator11.f();
2053
- return _context22.finish(22);
2054
- case 25:
2055
- perfMark('patchProductsInIndexDB', performance.now() - t0, {
2056
- count: validProducts.length
2480
+ case 43:
2481
+ throw new Error('Product persistence adapter has no upsert method');
2482
+ case 44:
2483
+ _context31.next = 46;
2484
+ return _this12.recordProductCommit({
2485
+ kind: 'delta',
2486
+ upserts: validProducts,
2487
+ deletedIds: deletedIds
2057
2488
  });
2058
- _this10.logInfo('patchProductsInIndexDB 完成', {
2489
+ case 46:
2490
+ _this12.logInfo('patchProductsInIndexDB 完成', {
2059
2491
  source: source,
2060
- count: validProducts.length
2492
+ productCount: validProducts.length,
2493
+ deletedCount: deletedIds.length,
2494
+ durationMs: Math.round(performance.now() - startedAt)
2061
2495
  });
2062
- case 27:
2496
+ case 47:
2063
2497
  case "end":
2064
- return _context22.stop();
2498
+ return _context31.stop();
2065
2499
  }
2066
- }, _callee22, null, [[9, 19, 22, 25]]);
2500
+ }, _callee30, null, [[1, 11, 14, 17], [25, 35, 38, 41]]);
2067
2501
  })));
2068
2502
  case 9:
2069
- _context23.next = 15;
2070
- break;
2071
- case 11:
2072
- _context23.prev = 11;
2073
- _context23.t0 = _context23["catch"](6);
2074
- errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
2075
- this.logError('增量保存商品到 IndexDB 失败', {
2503
+ return _context32.abrupt("return", true);
2504
+ case 12:
2505
+ _context32.prev = 12;
2506
+ _context32.t0 = _context32["catch"](6);
2507
+ this.productPersistenceFailed = true;
2508
+ this.logError('增量保存商品失败', {
2076
2509
  source: source,
2077
- error: errorMessage,
2078
- productCount: validProducts.length
2510
+ productCount: validProducts.length,
2511
+ deletedCount: deletedIds.length,
2512
+ error: String(_context32.t0)
2079
2513
  });
2080
- case 15:
2514
+ return _context32.abrupt("return", false);
2515
+ case 17:
2081
2516
  case "end":
2082
- return _context23.stop();
2517
+ return _context32.stop();
2083
2518
  }
2084
- }, _callee23, this, [[6, 11]]);
2519
+ }, _callee31, this, [[6, 12]]);
2085
2520
  }));
2086
- function patchProductsInIndexDB(_x23, _x24) {
2087
- return _patchProductsInIndexDB.apply(this, arguments);
2521
+ function persistProductDelta(_x31, _x32, _x33) {
2522
+ return _persistProductDelta.apply(this, arguments);
2088
2523
  }
2089
- return patchProductsInIndexDB;
2524
+ return persistProductDelta;
2090
2525
  }()
2091
2526
  /**
2092
2527
  * 同步更新商品 Map 缓存
2093
2528
  * 将 list 中的商品同步到 map,以 id 为 key
2094
2529
  * @private
2095
2530
  */
2096
- )
2097
2531
  }, {
2098
2532
  key: "syncProductsMap",
2099
2533
  value: function syncProductsMap() {
2100
2534
  var t0 = performance.now();
2101
2535
  this.store.map.clear();
2102
- var _iterator12 = _createForOfIteratorHelper(this.store.list),
2103
- _step12;
2536
+ var _iterator15 = _createForOfIteratorHelper(this.store.list),
2537
+ _step15;
2104
2538
  try {
2105
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
2106
- var product = _step12.value;
2539
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2540
+ var product = _step15.value;
2107
2541
  this.store.map.set(product.id, product);
2108
2542
  }
2109
2543
  } catch (err) {
2110
- _iterator12.e(err);
2544
+ _iterator15.e(err);
2111
2545
  } finally {
2112
- _iterator12.f();
2546
+ _iterator15.f();
2113
2547
  }
2114
2548
  perfMark('syncProductsMap', performance.now() - t0, {
2115
2549
  count: this.store.map.size
@@ -2123,25 +2557,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2123
2557
  }, {
2124
2558
  key: "preload",
2125
2559
  value: (function () {
2126
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2560
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2127
2561
  var _products$length3;
2128
2562
  var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
2129
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2130
- while (1) switch (_context24.prev = _context24.next) {
2563
+ return _regeneratorRuntime().wrap(function _callee32$(_context33) {
2564
+ while (1) switch (_context33.prev = _context33.next) {
2131
2565
  case 0:
2566
+ if (!this.isMemoryReplica()) {
2567
+ _context33.next = 4;
2568
+ break;
2569
+ }
2570
+ _context33.next = 3;
2571
+ return this.refreshFromReplica('preload');
2572
+ case 3:
2573
+ return _context33.abrupt("return");
2574
+ case 4:
2132
2575
  tTotal = performance.now();
2133
2576
  this.logInfo('开始预加载数据');
2134
- _context24.prev = 2;
2577
+ _context33.prev = 6;
2135
2578
  tIndexDB = performance.now();
2136
- _context24.next = 6;
2579
+ _context33.next = 10;
2137
2580
  return this.loadProductsFromIndexDB();
2138
- case 6:
2139
- cachedData = _context24.sent;
2581
+ case 10:
2582
+ cachedData = _context33.sent;
2140
2583
  perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
2141
2584
  count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
2142
2585
  });
2143
2586
  if (!(cachedData && cachedData.length > 0)) {
2144
- _context24.next = 18;
2587
+ _context33.next = 22;
2145
2588
  break;
2146
2589
  }
2147
2590
  // IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
@@ -2163,27 +2606,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2163
2606
  source: 'IndexDB'
2164
2607
  });
2165
2608
  this.lastPreloadCompletedAtMs = Date.now();
2166
- return _context24.abrupt("return");
2167
- case 18:
2609
+ return _context33.abrupt("return");
2610
+ case 22:
2168
2611
  this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
2169
- _context24.next = 26;
2612
+ _context33.next = 30;
2170
2613
  break;
2171
- case 21:
2172
- _context24.prev = 21;
2173
- _context24.t0 = _context24["catch"](2);
2174
- errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
2175
- console.warn('[Products] 从 IndexDB 加载数据失败:', _context24.t0);
2614
+ case 25:
2615
+ _context33.prev = 25;
2616
+ _context33.t0 = _context33["catch"](6);
2617
+ errorMessage = _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0);
2618
+ console.warn('[Products] 从 IndexDB 加载数据失败:', _context33.t0);
2176
2619
  this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
2177
2620
  error: errorMessage
2178
2621
  });
2179
- case 26:
2622
+ case 30:
2180
2623
  tServer = performance.now();
2181
- _context24.next = 29;
2624
+ _context33.next = 33;
2182
2625
  return this.loadProductsByServer({
2183
2626
  trigger: 'preload'
2184
2627
  });
2185
- case 29:
2186
- products = _context24.sent;
2628
+ case 33:
2629
+ products = _context33.sent;
2187
2630
  perfMark('preload.loadFromServer', performance.now() - tServer, {
2188
2631
  count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
2189
2632
  });
@@ -2215,11 +2658,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2215
2658
  duration: "".concat(Math.round(performance.now() - tTotal), "ms")
2216
2659
  });
2217
2660
  }
2218
- case 32:
2661
+ case 36:
2219
2662
  case "end":
2220
- return _context24.stop();
2663
+ return _context33.stop();
2221
2664
  }
2222
- }, _callee24, this, [[2, 21]]);
2665
+ }, _callee32, this, [[6, 25]]);
2223
2666
  }));
2224
2667
  function preload() {
2225
2668
  return _preload.apply(this, arguments);
@@ -2254,29 +2697,30 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2254
2697
  }, {
2255
2698
  key: "setupProductSync",
2256
2699
  value: function setupProductSync() {
2257
- var _this11 = this;
2700
+ var _this13 = this;
2258
2701
  if (!this.productDataSource) {
2259
2702
  this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
2260
2703
  return;
2261
2704
  }
2262
2705
  var createHandler = function createHandler(channelKey) {
2263
2706
  return function (message) {
2707
+ if (_this13.isMemoryReplica()) return;
2264
2708
  var data = (message === null || message === void 0 ? void 0 : message.data) || message;
2265
2709
  if (!data) return;
2266
- _this11.logInfo('收到同步消息', {
2710
+ _this13.logInfo('收到同步消息', {
2267
2711
  channelKey: channelKey,
2268
2712
  action: data.action,
2269
2713
  id: data.id,
2270
2714
  action_filed: data.action_filed
2271
2715
  });
2272
- _this11.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
2716
+ _this13.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
2273
2717
  _channelKey: channelKey
2274
2718
  }));
2275
- if (_this11.syncTimer) {
2276
- clearTimeout(_this11.syncTimer);
2719
+ if (_this13.syncTimer) {
2720
+ clearTimeout(_this13.syncTimer);
2277
2721
  }
2278
- _this11.syncTimer = setTimeout(function () {
2279
- _this11.processProductSyncMessages();
2722
+ _this13.syncTimer = setTimeout(function () {
2723
+ _this13.processProductSyncMessages();
2280
2724
  }, PRODUCT_SYNC_DEBOUNCE_MS);
2281
2725
  };
2282
2726
  };
@@ -2294,7 +2738,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2294
2738
  }
2295
2739
  }
2296
2740
  }).catch(function (err) {
2297
- _this11.logError('setupProductSync: DataSource run 出错', {
2741
+ _this13.logError('setupProductSync: DataSource run 出错', {
2298
2742
  error: err instanceof Error ? err.message : String(err)
2299
2743
  });
2300
2744
  });
@@ -2321,40 +2765,61 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2321
2765
  */
2322
2766
  }, {
2323
2767
  key: "processProductSyncMessages",
2324
- value: (function () {
2325
- var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2326
- var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator13, _step13, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, patchMergeActions, storeMutated, bodyResult, _iterator14, _step14, product, freshProducts, mergeResult, _iterator15, _step15, _product, patchProducts, allChangedIds, hasChanges, errorMessage;
2327
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2328
- while (1) switch (_context25.prev = _context25.next) {
2768
+ value: function processProductSyncMessages() {
2769
+ var _this14 = this;
2770
+ var run = function run() {
2771
+ return _this14.processProductSyncBatch();
2772
+ };
2773
+ var task = this.productSyncQueue.then(run, run);
2774
+ this.productSyncQueue = task.catch(function (error) {
2775
+ _this14.logError('商品同步批次失败', {
2776
+ error: String(error)
2777
+ });
2778
+ });
2779
+ return this.productSyncQueue;
2780
+ }
2781
+ }, {
2782
+ key: "processProductSyncBatch",
2783
+ value: function () {
2784
+ var _processProductSyncBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2785
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator16, _step16, msg, channelKey, _msg$relation_product, _msg$body, _msg$change_types, _msg$ids2, _msg$ids, ids, _iterator20, _step20, id, _iterator21, _step21, _id, _ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, storeMutated, bodyResult, _iterator17, _step17, product, freshProducts, mergeResult, _iterator18, _step18, _product, patchProducts, committedUpserts, _iterator19, _step19, _id2, _product2, allChangedIds, hasChanges, errorMessage;
2786
+ return _regeneratorRuntime().wrap(function _callee33$(_context34) {
2787
+ while (1) switch (_context34.prev = _context34.next) {
2329
2788
  case 0:
2789
+ if (!this.isMemoryReplica()) {
2790
+ _context34.next = 2;
2791
+ break;
2792
+ }
2793
+ return _context34.abrupt("return");
2794
+ case 2:
2330
2795
  messages = _toConsumableArray(this.pendingSyncMessages);
2331
2796
  this.pendingSyncMessages = [];
2332
2797
  if (!(messages.length === 0)) {
2333
- _context25.next = 4;
2798
+ _context34.next = 6;
2334
2799
  break;
2335
2800
  }
2336
- return _context25.abrupt("return");
2337
- case 4:
2801
+ return _context34.abrupt("return");
2802
+ case 6:
2338
2803
  this.logInfo('processProductSyncMessages: 开始处理', {
2339
2804
  count: messages.length
2340
2805
  });
2341
- deleteIds = [];
2806
+ deleteIds = new Set();
2342
2807
  bodyUpdates = new Map();
2343
2808
  sseRefreshIds = [];
2344
2809
  priceRefreshIds = [];
2345
2810
  shouldClearPriceCache = false;
2346
- _iterator13 = _createForOfIteratorHelper(messages);
2347
- _context25.prev = 11;
2348
- _iterator13.s();
2349
- case 13:
2350
- if ((_step13 = _iterator13.n()).done) {
2351
- _context25.next = 36;
2811
+ _iterator16 = _createForOfIteratorHelper(messages);
2812
+ _context34.prev = 13;
2813
+ _iterator16.s();
2814
+ case 15:
2815
+ if ((_step16 = _iterator16.n()).done) {
2816
+ _context34.next = 43;
2352
2817
  break;
2353
2818
  }
2354
- msg = _step13.value;
2819
+ msg = _step16.value;
2355
2820
  channelKey = msg._channelKey || msg.module || 'product';
2356
2821
  if (!(channelKey === 'product')) {
2357
- _context25.next = 33;
2822
+ _context34.next = 40;
2358
2823
  break;
2359
2824
  }
2360
2825
  if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
@@ -2362,41 +2827,68 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2362
2827
  }
2363
2828
  // 1. 删除场景:operation === 'delete' 或 action === 'delete'
2364
2829
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
2365
- _context25.next = 21;
2830
+ _context34.next = 25;
2366
2831
  break;
2367
2832
  }
2368
- if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id) deleteIds.push(msg.id);
2369
- return _context25.abrupt("continue", 34);
2370
- case 21:
2833
+ ids = (_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length ? msg.ids : msg.id ? [msg.id] : [];
2834
+ _iterator20 = _createForOfIteratorHelper(ids);
2835
+ try {
2836
+ for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
2837
+ id = _step20.value;
2838
+ deleteIds.add(id);
2839
+ bodyUpdates.delete(id);
2840
+ }
2841
+ } catch (err) {
2842
+ _iterator20.e(err);
2843
+ } finally {
2844
+ _iterator20.f();
2845
+ }
2846
+ return _context34.abrupt("continue", 41);
2847
+ case 25:
2848
+ // The last explicit product operation wins within the existing sync batch.
2849
+ _iterator21 = _createForOfIteratorHelper(msg.ids || (msg.id ? [msg.id] : []));
2850
+ try {
2851
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2852
+ _id = _step21.value;
2853
+ deleteIds.delete(_id);
2854
+ }
2855
+ } catch (err) {
2856
+ _iterator21.e(err);
2857
+ } finally {
2858
+ _iterator21.f();
2859
+ }
2860
+ if ((_msg$body = msg.body) !== null && _msg$body !== void 0 && _msg$body.id) deleteIds.delete(msg.body.id);
2861
+
2862
+ // 2. change_types 包含 price → 仅收集需要刷新价格的 IDs(不走 SSE 拉取)
2371
2863
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
2372
- _context25.next = 26;
2864
+ _context34.next = 33;
2373
2865
  break;
2374
2866
  }
2375
- ids = msg.ids || (msg.id ? [msg.id] : []);
2376
- priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(ids));
2867
+ _ids = msg.ids || (msg.id ? [msg.id] : []);
2868
+ priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(_ids));
2377
2869
  if (msg.body) {
2378
2870
  bodyId = msg.body.id;
2379
2871
  if (bodyId) bodyUpdates.set(bodyId, msg.body);
2380
2872
  }
2381
- return _context25.abrupt("continue", 34);
2382
- case 26:
2873
+ return _context34.abrupt("continue", 41);
2874
+ case 33:
2383
2875
  if (!msg.body) {
2384
- _context25.next = 30;
2876
+ _context34.next = 37;
2385
2877
  break;
2386
2878
  }
2387
2879
  _bodyId = msg.body.id || msg.id;
2388
2880
  if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
2389
- return _context25.abrupt("continue", 34);
2390
- case 30:
2881
+ return _context34.abrupt("continue", 41);
2882
+ case 37:
2391
2883
  // 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
2392
2884
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
2393
2885
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
2394
2886
  } else if (msg.id) {
2395
2887
  sseRefreshIds.push(msg.id);
2396
2888
  }
2397
- _context25.next = 34;
2889
+ _context34.next = 41;
2398
2890
  break;
2399
- case 33:
2891
+ case 40:
2400
2892
  if (channelKey === 'product_quotation') {
2401
2893
  // 报价单变更影响范围大,标记清除全量价格缓存
2402
2894
  shouldClearPriceCache = true;
@@ -2412,108 +2904,127 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2412
2904
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.product_ids));
2413
2905
  }
2414
2906
  }
2415
- case 34:
2416
- _context25.next = 13;
2907
+ case 41:
2908
+ _context34.next = 15;
2417
2909
  break;
2418
- case 36:
2419
- _context25.next = 41;
2910
+ case 43:
2911
+ _context34.next = 48;
2420
2912
  break;
2421
- case 38:
2422
- _context25.prev = 38;
2423
- _context25.t0 = _context25["catch"](11);
2424
- _iterator13.e(_context25.t0);
2425
- case 41:
2426
- _context25.prev = 41;
2427
- _iterator13.f();
2428
- return _context25.finish(41);
2429
- case 44:
2430
- uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
2431
- uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
2432
- uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
2913
+ case 45:
2914
+ _context34.prev = 45;
2915
+ _context34.t0 = _context34["catch"](13);
2916
+ _iterator16.e(_context34.t0);
2917
+ case 48:
2918
+ _context34.prev = 48;
2919
+ _iterator16.f();
2920
+ return _context34.finish(48);
2921
+ case 51:
2922
+ uniqueDeleteIds = _toConsumableArray(deleteIds);
2923
+ uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds)).filter(function (id) {
2924
+ return !deleteIds.has(id);
2925
+ });
2926
+ uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)).filter(function (id) {
2927
+ return !deleteIds.has(id);
2928
+ }); // 1. 处理删除
2433
2929
  if (!(uniqueDeleteIds.length > 0)) {
2434
- _context25.next = 50;
2930
+ _context34.next = 57;
2435
2931
  break;
2436
2932
  }
2437
- _context25.next = 50;
2438
- return this.removeProductsByIds(uniqueDeleteIds);
2439
- case 50:
2933
+ _context34.next = 57;
2934
+ return this.removeProductsByIds(uniqueDeleteIds, {
2935
+ skipIndexDB: true,
2936
+ skipEmit: true
2937
+ });
2938
+ case 57:
2440
2939
  /** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
2441
2940
  patchProductMap = new Map();
2442
- patchMergeActions = {};
2443
2941
  storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
2444
2942
  if (!(bodyUpdates.size > 0)) {
2445
- _context25.next = 60;
2943
+ _context34.next = 66;
2446
2944
  break;
2447
2945
  }
2448
- _context25.next = 56;
2946
+ _context34.next = 62;
2449
2947
  return this.applyBodyUpdatesToStore(bodyUpdates, {
2450
2948
  skipIndexDB: true,
2451
2949
  skipEmit: true
2452
2950
  });
2453
- case 56:
2454
- bodyResult = _context25.sent;
2455
- _iterator14 = _createForOfIteratorHelper(bodyResult.changedProducts);
2951
+ case 62:
2952
+ bodyResult = _context34.sent;
2953
+ _iterator17 = _createForOfIteratorHelper(bodyResult.changedProducts);
2456
2954
  try {
2457
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2458
- product = _step14.value;
2955
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2956
+ product = _step17.value;
2459
2957
  patchProductMap.set(product.id, product);
2460
- patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
2461
2958
  }
2462
2959
  } catch (err) {
2463
- _iterator14.e(err);
2960
+ _iterator17.e(err);
2464
2961
  } finally {
2465
- _iterator14.f();
2962
+ _iterator17.f();
2466
2963
  }
2467
2964
  storeMutated = true;
2468
- case 60:
2965
+ case 66:
2469
2966
  // 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
2470
2967
  freshProducts = [];
2471
2968
  if (!(uniqueSSEIds.length > 0)) {
2472
- _context25.next = 73;
2969
+ _context34.next = 79;
2473
2970
  break;
2474
2971
  }
2475
- _context25.next = 64;
2972
+ _context34.next = 70;
2476
2973
  return this.fetchProductsBySSE(uniqueSSEIds);
2477
- case 64:
2478
- freshProducts = _context25.sent;
2974
+ case 70:
2975
+ freshProducts = _context34.sent;
2479
2976
  if (!(freshProducts.length > 0)) {
2480
- _context25.next = 72;
2977
+ _context34.next = 78;
2481
2978
  break;
2482
2979
  }
2483
- _context25.next = 68;
2980
+ _context34.next = 74;
2484
2981
  return this.mergeProductsToStore(freshProducts, {
2485
2982
  skipIndexDB: true,
2486
2983
  skipEmit: true
2487
2984
  });
2488
- case 68:
2489
- mergeResult = _context25.sent;
2490
- _iterator15 = _createForOfIteratorHelper(mergeResult.changedProducts);
2985
+ case 74:
2986
+ mergeResult = _context34.sent;
2987
+ _iterator18 = _createForOfIteratorHelper(mergeResult.changedProducts);
2491
2988
  try {
2492
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2493
- _product = _step15.value;
2989
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2990
+ _product = _step18.value;
2494
2991
  patchProductMap.set(_product.id, _product);
2495
- patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
2496
2992
  }
2497
2993
  } catch (err) {
2498
- _iterator15.e(err);
2994
+ _iterator18.e(err);
2499
2995
  } finally {
2500
- _iterator15.f();
2996
+ _iterator18.f();
2501
2997
  }
2502
2998
  storeMutated = true;
2503
- case 72:
2999
+ case 78:
2504
3000
  this.logInfo('processProductSyncMessages: SSE 增量更新完成123', {
2505
3001
  requestedCount: uniqueSSEIds.length,
2506
3002
  receivedCount: freshProducts.length
2507
3003
  });
2508
- case 73:
2509
- patchProducts = _toConsumableArray(patchProductMap.values());
2510
- if (!(patchProducts.length > 0)) {
2511
- _context25.next = 77;
3004
+ case 79:
3005
+ patchProducts = _toConsumableArray(patchProductMap.values()); // Publish one committed delta for the entire batch, including deletions and price-only IDs.
3006
+ committedUpserts = new Map(patchProducts.map(function (p) {
3007
+ return [p.id, p];
3008
+ }));
3009
+ _iterator19 = _createForOfIteratorHelper(uniquePriceIds);
3010
+ try {
3011
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
3012
+ _id2 = _step19.value;
3013
+ _product2 = this.store.map.get(_id2);
3014
+ if (_product2 && !uniqueDeleteIds.includes(_id2)) committedUpserts.set(_id2, _product2);
3015
+ }
3016
+ } catch (err) {
3017
+ _iterator19.e(err);
3018
+ } finally {
3019
+ _iterator19.f();
3020
+ }
3021
+ if (!(committedUpserts.size || uniqueDeleteIds.length)) {
3022
+ _context34.next = 86;
2512
3023
  break;
2513
3024
  }
2514
- _context25.next = 77;
2515
- return this.patchProductsInIndexDB(patchProducts, 'pubsub.processProductSyncMessages', patchMergeActions);
2516
- case 77:
3025
+ _context34.next = 86;
3026
+ return this.persistProductDelta(_toConsumableArray(committedUpserts.values()), uniqueDeleteIds, 'pubsub.batch');
3027
+ case 86:
2517
3028
  if (storeMutated) {
2518
3029
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2519
3030
  }
@@ -2530,74 +3041,73 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2530
3041
  });
2531
3042
  hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
2532
3043
  if (hasChanges) {
2533
- _context25.next = 84;
3044
+ _context34.next = 93;
2534
3045
  break;
2535
3046
  }
2536
3047
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
2537
- return _context25.abrupt("return");
2538
- case 84:
3048
+ return _context34.abrupt("return");
3049
+ case 93:
2539
3050
  if (!shouldClearPriceCache) {
2540
- _context25.next = 95;
3051
+ _context34.next = 104;
2541
3052
  break;
2542
3053
  }
2543
- _context25.prev = 85;
2544
- _context25.next = 88;
3054
+ _context34.prev = 94;
3055
+ _context34.next = 97;
2545
3056
  return this.refreshQuotationPriceBridge();
2546
- case 88:
2547
- _context25.next = 94;
3057
+ case 97:
3058
+ _context34.next = 103;
2548
3059
  break;
2549
- case 90:
2550
- _context25.prev = 90;
2551
- _context25.t1 = _context25["catch"](85);
2552
- errorMessage = _context25.t1 instanceof Error ? _context25.t1.message : String(_context25.t1);
3060
+ case 99:
3061
+ _context34.prev = 99;
3062
+ _context34.t1 = _context34["catch"](94);
3063
+ errorMessage = _context34.t1 instanceof Error ? _context34.t1.message : String(_context34.t1);
2553
3064
  this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
2554
3065
  error: errorMessage
2555
3066
  });
2556
- case 94:
3067
+ case 103:
2557
3068
  this.clearPriceCache();
2558
- case 95:
2559
- _context25.next = 97;
3069
+ case 104:
3070
+ _context34.next = 106;
2560
3071
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
2561
3072
  changedIds: allChangedIds
2562
3073
  });
2563
- case 97:
3074
+ case 106:
2564
3075
  case "end":
2565
- return _context25.stop();
3076
+ return _context34.stop();
2566
3077
  }
2567
- }, _callee25, this, [[11, 38, 41, 44], [85, 90]]);
3078
+ }, _callee33, this, [[13, 45, 48, 51], [94, 99]]);
2568
3079
  }));
2569
- function processProductSyncMessages() {
2570
- return _processProductSyncMessages.apply(this, arguments);
3080
+ function processProductSyncBatch() {
3081
+ return _processProductSyncBatch.apply(this, arguments);
2571
3082
  }
2572
- return processProductSyncMessages;
3083
+ return processProductSyncBatch;
2573
3084
  }()
2574
3085
  /**
2575
3086
  * 通过 SSE 按 ids 增量拉取商品数据
2576
3087
  * 请求 GET /shop/core/stream?type=product&ids={ids}
2577
3088
  */
2578
- )
2579
3089
  }, {
2580
3090
  key: "fetchProductsBySSE",
2581
3091
  value: (function () {
2582
- var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(ids) {
3092
+ var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(ids) {
2583
3093
  var t0, productList, list, errorMessage;
2584
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2585
- while (1) switch (_context26.prev = _context26.next) {
3094
+ return _regeneratorRuntime().wrap(function _callee34$(_context35) {
3095
+ while (1) switch (_context35.prev = _context35.next) {
2586
3096
  case 0:
2587
3097
  if (this.productDataSource) {
2588
- _context26.next = 3;
3098
+ _context35.next = 3;
2589
3099
  break;
2590
3100
  }
2591
3101
  this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
2592
- return _context26.abrupt("return", []);
3102
+ return _context35.abrupt("return", []);
2593
3103
  case 3:
2594
3104
  this.logInfo('fetchProductsBySSE: 开始', {
2595
3105
  ids: ids,
2596
3106
  count: ids.length
2597
3107
  });
2598
3108
  t0 = performance.now();
2599
- _context26.prev = 5;
2600
- _context26.next = 8;
3109
+ _context35.prev = 5;
3110
+ _context35.next = 8;
2601
3111
  return this.productDataSource.run({
2602
3112
  sse: {
2603
3113
  query: {
@@ -2607,7 +3117,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2607
3117
  }
2608
3118
  });
2609
3119
  case 8:
2610
- productList = _context26.sent;
3120
+ productList = _context35.sent;
2611
3121
  list = productList || [];
2612
3122
  perfMark('fetchProductsBySSE', performance.now() - t0, {
2613
3123
  count: list.length
@@ -2617,23 +3127,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2617
3127
  receivedCount: list.length,
2618
3128
  duration: "".concat(Math.round(performance.now() - t0), "ms")
2619
3129
  });
2620
- return _context26.abrupt("return", list);
3130
+ return _context35.abrupt("return", list);
2621
3131
  case 15:
2622
- _context26.prev = 15;
2623
- _context26.t0 = _context26["catch"](5);
2624
- errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
3132
+ _context35.prev = 15;
3133
+ _context35.t0 = _context35["catch"](5);
3134
+ errorMessage = _context35.t0 instanceof Error ? _context35.t0.message : String(_context35.t0);
2625
3135
  this.logError('fetchProductsBySSE: 失败', {
2626
3136
  ids: ids,
2627
3137
  error: errorMessage
2628
3138
  });
2629
- return _context26.abrupt("return", []);
3139
+ return _context35.abrupt("return", []);
2630
3140
  case 20:
2631
3141
  case "end":
2632
- return _context26.stop();
3142
+ return _context35.stop();
2633
3143
  }
2634
- }, _callee26, this, [[5, 15]]);
3144
+ }, _callee34, this, [[5, 15]]);
2635
3145
  }));
2636
- function fetchProductsBySSE(_x25) {
3146
+ function fetchProductsBySSE(_x34) {
2637
3147
  return _fetchProductsBySSE.apply(this, arguments);
2638
3148
  }
2639
3149
  return fetchProductsBySSE;
@@ -2649,10 +3159,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2649
3159
  }, {
2650
3160
  key: "applyBodyUpdatesToStore",
2651
3161
  value: (function () {
2652
- var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(bodyUpdates, options) {
2653
- var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator16, _step16, _step16$value, id, body;
2654
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2655
- while (1) switch (_context27.prev = _context27.next) {
3162
+ var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(bodyUpdates, options) {
3163
+ var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator22, _step22, _step22$value, id, body;
3164
+ return _regeneratorRuntime().wrap(function _callee35$(_context36) {
3165
+ while (1) switch (_context36.prev = _context36.next) {
2656
3166
  case 0:
2657
3167
  changedProductIds = _toConsumableArray(bodyUpdates.keys());
2658
3168
  this.logInfo('applyBodyUpdatesToStore: 开始', {
@@ -2674,10 +3184,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2674
3184
  }
2675
3185
  return p;
2676
3186
  });
2677
- _iterator16 = _createForOfIteratorHelper(bodyUpdates);
3187
+ _iterator22 = _createForOfIteratorHelper(bodyUpdates);
2678
3188
  try {
2679
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2680
- _step16$value = _slicedToArray(_step16.value, 2), id = _step16$value[0], body = _step16$value[1];
3189
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
3190
+ _step22$value = _slicedToArray(_step22.value, 2), id = _step22$value[0], body = _step22$value[1];
2681
3191
  if (!appliedIds.has(id)) {
2682
3192
  this.store.list.push(body);
2683
3193
  newCount++;
@@ -2686,16 +3196,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2686
3196
  }
2687
3197
  }
2688
3198
  } catch (err) {
2689
- _iterator16.e(err);
3199
+ _iterator22.e(err);
2690
3200
  } finally {
2691
- _iterator16.f();
3201
+ _iterator22.f();
2692
3202
  }
2693
3203
  this.syncProductsMap();
2694
3204
  if (options !== null && options !== void 0 && options.skipIndexDB) {
2695
- _context27.next = 14;
3205
+ _context36.next = 14;
2696
3206
  break;
2697
3207
  }
2698
- _context27.next = 14;
3208
+ _context36.next = 14;
2699
3209
  return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
2700
3210
  case 14:
2701
3211
  if (!(options !== null && options !== void 0 && options.skipEmit)) {
@@ -2706,7 +3216,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2706
3216
  newCount: newCount,
2707
3217
  totalCount: this.store.list.length
2708
3218
  });
2709
- return _context27.abrupt("return", {
3219
+ return _context36.abrupt("return", {
2710
3220
  changedProducts: changedProducts,
2711
3221
  mergeActions: mergeActions,
2712
3222
  updatedCount: updatedCount,
@@ -2714,11 +3224,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2714
3224
  });
2715
3225
  case 17:
2716
3226
  case "end":
2717
- return _context27.stop();
3227
+ return _context36.stop();
2718
3228
  }
2719
- }, _callee27, this);
3229
+ }, _callee35, this);
2720
3230
  }));
2721
- function applyBodyUpdatesToStore(_x26, _x27) {
3231
+ function applyBodyUpdatesToStore(_x35, _x36) {
2722
3232
  return _applyBodyUpdatesToStore.apply(this, arguments);
2723
3233
  }
2724
3234
  return applyBodyUpdatesToStore;
@@ -2734,22 +3244,22 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2734
3244
  }, {
2735
3245
  key: "mergeProductsToStore",
2736
3246
  value: (function () {
2737
- var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(freshProducts, options) {
2738
- var freshMap, _iterator17, _step17, p, mergeActions, changedProducts, updatedList, newCount, _iterator18, _step18, _p2, updatedCount, changedProductIds;
2739
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2740
- while (1) switch (_context28.prev = _context28.next) {
3247
+ var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(freshProducts, options) {
3248
+ var freshMap, _iterator23, _step23, p, mergeActions, changedProducts, updatedList, newCount, _iterator24, _step24, _p2, updatedCount, changedProductIds;
3249
+ return _regeneratorRuntime().wrap(function _callee36$(_context37) {
3250
+ while (1) switch (_context37.prev = _context37.next) {
2741
3251
  case 0:
2742
3252
  freshMap = new Map();
2743
- _iterator17 = _createForOfIteratorHelper(freshProducts);
3253
+ _iterator23 = _createForOfIteratorHelper(freshProducts);
2744
3254
  try {
2745
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2746
- p = _step17.value;
3255
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
3256
+ p = _step23.value;
2747
3257
  freshMap.set(p.id, p);
2748
3258
  }
2749
3259
  } catch (err) {
2750
- _iterator17.e(err);
3260
+ _iterator23.e(err);
2751
3261
  } finally {
2752
- _iterator17.f();
3262
+ _iterator23.f();
2753
3263
  }
2754
3264
  mergeActions = {};
2755
3265
  changedProducts = [];
@@ -2764,18 +3274,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2764
3274
  return p;
2765
3275
  }); // freshMap 中剩余的是新商品(create 场景)
2766
3276
  newCount = freshMap.size;
2767
- _iterator18 = _createForOfIteratorHelper(freshMap.values());
3277
+ _iterator24 = _createForOfIteratorHelper(freshMap.values());
2768
3278
  try {
2769
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2770
- _p2 = _step18.value;
3279
+ for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
3280
+ _p2 = _step24.value;
2771
3281
  updatedList.push(_p2);
2772
3282
  mergeActions[_p2.id] = 'insert';
2773
3283
  changedProducts.push(_p2);
2774
3284
  }
2775
3285
  } catch (err) {
2776
- _iterator18.e(err);
3286
+ _iterator24.e(err);
2777
3287
  } finally {
2778
- _iterator18.f();
3288
+ _iterator24.f();
2779
3289
  }
2780
3290
  updatedCount = freshProducts.length - newCount;
2781
3291
  changedProductIds = freshProducts.map(function (p) {
@@ -2784,10 +3294,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2784
3294
  this.store.list = updatedList;
2785
3295
  this.syncProductsMap();
2786
3296
  if (options !== null && options !== void 0 && options.skipIndexDB) {
2787
- _context28.next = 16;
3297
+ _context37.next = 16;
2788
3298
  break;
2789
3299
  }
2790
- _context28.next = 16;
3300
+ _context37.next = 16;
2791
3301
  return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
2792
3302
  case 16:
2793
3303
  if (!(options !== null && options !== void 0 && options.skipEmit)) {
@@ -2798,7 +3308,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2798
3308
  newCount: newCount,
2799
3309
  totalCount: this.store.list.length
2800
3310
  });
2801
- return _context28.abrupt("return", {
3311
+ return _context37.abrupt("return", {
2802
3312
  changedProducts: changedProducts,
2803
3313
  mergeActions: mergeActions,
2804
3314
  updatedCount: updatedCount,
@@ -2806,11 +3316,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2806
3316
  });
2807
3317
  case 19:
2808
3318
  case "end":
2809
- return _context28.stop();
3319
+ return _context37.stop();
2810
3320
  }
2811
- }, _callee28, this);
3321
+ }, _callee36, this);
2812
3322
  }));
2813
- function mergeProductsToStore(_x28, _x29) {
3323
+ function mergeProductsToStore(_x37, _x38) {
2814
3324
  return _mergeProductsToStore.apply(this, arguments);
2815
3325
  }
2816
3326
  return mergeProductsToStore;
@@ -2824,7 +3334,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2824
3334
  }, {
2825
3335
  key: "silentRefresh",
2826
3336
  value: (function () {
2827
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
3337
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
2828
3338
  var options,
2829
3339
  t0,
2830
3340
  now,
@@ -2833,18 +3343,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2833
3343
  elapsedSinceFullFetchMs,
2834
3344
  products,
2835
3345
  errorMessage,
2836
- _args29 = arguments;
2837
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2838
- while (1) switch (_context29.prev = _context29.next) {
3346
+ _args38 = arguments;
3347
+ return _regeneratorRuntime().wrap(function _callee37$(_context38) {
3348
+ while (1) switch (_context38.prev = _context38.next) {
2839
3349
  case 0:
2840
- options = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
3350
+ options = _args38.length > 0 && _args38[0] !== undefined ? _args38[0] : {};
3351
+ if (!this.isMemoryReplica()) {
3352
+ _context38.next = 3;
3353
+ break;
3354
+ }
3355
+ return _context38.abrupt("return", this.refreshFromReplica(options.trigger || 'background'));
3356
+ case 3:
2841
3357
  t0 = performance.now();
2842
3358
  now = Date.now();
2843
3359
  trigger = options.trigger || 'background';
2844
3360
  elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
2845
3361
  elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
2846
3362
  if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
2847
- _context29.next = 9;
3363
+ _context38.next = 11;
2848
3364
  break;
2849
3365
  }
2850
3366
  this.logInfo('silentRefresh 跳过全量 SSE', {
@@ -2855,61 +3371,61 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2855
3371
  elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
2856
3372
  productCount: this.store.list.length
2857
3373
  });
2858
- return _context29.abrupt("return", this.store.list);
2859
- case 9:
3374
+ return _context38.abrupt("return", this.store.list);
3375
+ case 11:
2860
3376
  this.logInfo('silentRefresh 开始', {
2861
3377
  trigger: trigger,
2862
3378
  elapsedSincePreloadMs: elapsedSincePreloadMs,
2863
3379
  elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
2864
3380
  productCount: this.store.list.length
2865
3381
  });
2866
- _context29.prev = 10;
2867
- _context29.next = 13;
3382
+ _context38.prev = 12;
3383
+ _context38.next = 15;
2868
3384
  return this.loadProductsByServer({
2869
3385
  trigger: trigger
2870
3386
  });
2871
- case 13:
2872
- products = _context29.sent;
3387
+ case 15:
3388
+ products = _context38.sent;
2873
3389
  if (!(products && products.length > 0)) {
2874
- _context29.next = 24;
3390
+ _context38.next = 26;
2875
3391
  break;
2876
3392
  }
2877
3393
  this.store.list = products;
2878
3394
  this.syncProductsMap();
2879
3395
  this.clearPriceCache();
2880
3396
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2881
- _context29.next = 21;
3397
+ _context38.next = 23;
2882
3398
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
2883
- case 21:
3399
+ case 23:
2884
3400
  this.logInfo('silentRefresh 完成', {
2885
3401
  trigger: trigger,
2886
3402
  productCount: products.length,
2887
3403
  duration: "".concat(Math.round(performance.now() - t0), "ms")
2888
3404
  });
2889
- _context29.next = 25;
3405
+ _context38.next = 27;
2890
3406
  break;
2891
- case 24:
3407
+ case 26:
2892
3408
  this.logWarning('silentRefresh: 服务器未返回数据');
2893
- case 25:
3409
+ case 27:
2894
3410
  perfMark('silentRefresh', performance.now() - t0, {
2895
3411
  count: this.store.list.length
2896
3412
  });
2897
- return _context29.abrupt("return", this.store.list);
2898
- case 29:
2899
- _context29.prev = 29;
2900
- _context29.t0 = _context29["catch"](10);
2901
- errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
3413
+ return _context38.abrupt("return", this.store.list);
3414
+ case 31:
3415
+ _context38.prev = 31;
3416
+ _context38.t0 = _context38["catch"](12);
3417
+ errorMessage = _context38.t0 instanceof Error ? _context38.t0.message : String(_context38.t0);
2902
3418
  this.logError('silentRefresh 失败', {
2903
3419
  trigger: trigger,
2904
3420
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
2905
3421
  error: errorMessage
2906
3422
  });
2907
- return _context29.abrupt("return", this.store.list);
2908
- case 34:
3423
+ return _context38.abrupt("return", this.store.list);
3424
+ case 36:
2909
3425
  case "end":
2910
- return _context29.stop();
3426
+ return _context38.stop();
2911
3427
  }
2912
- }, _callee29, this, [[10, 29]]);
3428
+ }, _callee37, this, [[12, 31]]);
2913
3429
  }));
2914
3430
  function silentRefresh() {
2915
3431
  return _silentRefresh.apply(this, arguments);
@@ -2924,6 +3440,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2924
3440
  key: "destroyProductSync",
2925
3441
  value: function destroyProductSync() {
2926
3442
  var _this$productDataSour;
3443
+ void this.core.effects.emit(ProductsHooks.onProductSyncDestroyed, null);
3444
+ this.disableProductReplicationSource();
3445
+ this.requestReplicaRefresh = undefined;
2927
3446
  if (this.syncTimer) {
2928
3447
  clearTimeout(this.syncTimer);
2929
3448
  this.syncTimer = undefined;
@@ -2934,6 +3453,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2934
3453
  this.pendingSyncMessages = [];
2935
3454
  this.logInfo('destroyProductSync: 同步资源已销毁');
2936
3455
  }
3456
+ }, {
3457
+ key: "destroy",
3458
+ value: function destroy() {
3459
+ this.runtimeSyncGeneration += 1;
3460
+ this.destroyProductSync();
3461
+ _get(_getPrototypeOf(ProductsModule.prototype), "destroy", this).call(this);
3462
+ }
2937
3463
 
2938
3464
  /**
2939
3465
  * 获取模块的路由定义