@pisell/pisellos 2.3.210 → 2.3.211

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.
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
345
+ weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -389,7 +389,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
389
389
  };
390
390
  setOtherData(key: string, value: any): void;
391
391
  getOtherData(key: string): any;
392
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
392
+ getProductTypeById(id: number): Promise<"normal" | "session" | "duration">;
393
393
  /**
394
394
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
395
395
  *
@@ -640,7 +640,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
640
640
  generateIdempotencyToken(): string;
641
641
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
642
642
  createOrder(params: CommitOrderParams['query']): {
643
- type: "appointment_booking" | "virtual";
643
+ type: "virtual" | "appointment_booking";
644
644
  platform: string;
645
645
  sales_channel: string;
646
646
  order_sales_channel: string;
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "normal" | "session" | "duration";
53
53
  }
@@ -35,8 +35,10 @@ export declare class ProductsModule extends BaseModule implements Module {
35
35
  private syncTimer?;
36
36
  /** 最近一次 SSE 全量拉取完成时间 */
37
37
  private lastServerFullFetchAtMs;
38
- /** 最近一次 preload 完成时间(含 IndexDB 命中) */
38
+ /** 最近一次 preload 完成时间(含 IndexDB 命中,仅用于日志) */
39
39
  private lastPreloadCompletedAtMs;
40
+ private serverFullFetchPromise?;
41
+ private silentRefreshPromise?;
40
42
  /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
41
43
  private productIndexDBSaveQueue;
42
44
  /** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
@@ -206,7 +208,8 @@ export declare class ProductsModule extends BaseModule implements Module {
206
208
  */
207
209
  loadProductsByServer(options?: {
208
210
  trigger?: string;
209
- }): Promise<any>;
211
+ }): Promise<ProductData[]>;
212
+ private fetchAndPersistProductsByServer;
210
213
  /**
211
214
  * 纯请求方法:通过 HTTP 接口获取商品列表(无副作用,不触发事件、不写 IndexDB)
212
215
  * @param params 查询参数
@@ -358,6 +361,7 @@ export declare class ProductsModule extends BaseModule implements Module {
358
361
  silentRefresh(options?: {
359
362
  trigger?: string;
360
363
  }): Promise<ProductData[]>;
364
+ private runSilentRefresh;
361
365
  /**
362
366
  * 销毁同步资源(取消 pubsub 订阅、清除定时器)
363
367
  */
@@ -16,7 +16,7 @@ var _replication = require("./replication");
16
16
  const INDEXDB_STORE_NAME = 'products';
17
17
  /** 商品同步防抖时间(毫秒) */
18
18
  const PRODUCT_SYNC_DEBOUNCE_MS = 10_000;
19
- /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
19
+ /** silentRefresh 最小间隔,仅从成功的服务器全量刷新计时 */
20
20
  const PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS = 30_000;
21
21
 
22
22
  /**
@@ -63,8 +63,10 @@ class ProductsModule extends _BaseModule.BaseModule {
63
63
  syncTimer;
64
64
  /** 最近一次 SSE 全量拉取完成时间 */
65
65
  lastServerFullFetchAtMs = 0;
66
- /** 最近一次 preload 完成时间(含 IndexDB 命中) */
66
+ /** 最近一次 preload 完成时间(含 IndexDB 命中,仅用于日志) */
67
67
  lastPreloadCompletedAtMs = 0;
68
+ serverFullFetchPromise;
69
+ silentRefreshPromise;
68
70
  /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
69
71
  productIndexDBSaveQueue = Promise.resolve();
70
72
 
@@ -961,11 +963,20 @@ class ProductsModule extends _BaseModule.BaseModule {
961
963
  */
962
964
  async loadProductsByServer(options = {}) {
963
965
  if (this.isMemoryReplica()) return this.refreshFromReplica(options.trigger || 'loadProductsByServer');
966
+ if (this.serverFullFetchPromise) return this.serverFullFetchPromise;
967
+ const fetchPromise = this.fetchAndPersistProductsByServer(options.trigger || 'unknown');
968
+ this.serverFullFetchPromise = fetchPromise;
969
+ try {
970
+ return await fetchPromise;
971
+ } finally {
972
+ if (this.serverFullFetchPromise === fetchPromise) this.serverFullFetchPromise = undefined;
973
+ }
974
+ }
975
+ async fetchAndPersistProductsByServer(trigger) {
964
976
  if (!this.productDataSource) {
965
977
  this.logWarning('loadProductsByServer: ProductDataSource 不可用');
966
978
  return [];
967
979
  }
968
- const trigger = options.trigger || 'unknown';
969
980
  this.logInfo('开始通过 DataSource SSE 加载商品列表', {
970
981
  trigger
971
982
  });
@@ -1415,6 +1426,8 @@ class ProductsModule extends _BaseModule.BaseModule {
1415
1426
  await this.refreshFromReplica('preload');
1416
1427
  return;
1417
1428
  }
1429
+ const productsBeforePreload = this.store.list;
1430
+ const fullFetchBeforePreload = this.lastServerFullFetchAtMs;
1418
1431
  const tTotal = performance.now();
1419
1432
  this.logInfo('开始预加载数据');
1420
1433
  try {
@@ -1423,6 +1436,11 @@ class ProductsModule extends _BaseModule.BaseModule {
1423
1436
  (0, _product.perfMark)('preload.loadFromIndexDB', performance.now() - tIndexDB, {
1424
1437
  count: cachedData?.length ?? 0
1425
1438
  });
1439
+
1440
+ // PIN 刷新若先完成,不用随后读出的旧缓存覆盖服务器列表。
1441
+ if (this.lastServerFullFetchAtMs !== fullFetchBeforePreload && this.store.list !== productsBeforePreload) {
1442
+ return;
1443
+ }
1426
1444
  if (cachedData && cachedData.length > 0) {
1427
1445
  // IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
1428
1446
  this.store.list = cachedData;
@@ -1915,13 +1933,18 @@ class ProductsModule extends _BaseModule.BaseModule {
1915
1933
  * @returns 刷新后的商品列表
1916
1934
  */
1917
1935
  async silentRefresh(options = {}) {
1918
- if (this.isMemoryReplica()) return this.refreshFromReplica(options.trigger || 'background');
1919
- const t0 = performance.now();
1920
- const now = Date.now();
1921
1936
  const trigger = options.trigger || 'background';
1937
+ if (this.isMemoryReplica()) return this.refreshFromReplica(trigger);
1938
+ if (this.silentRefreshPromise) {
1939
+ this.logInfo('silentRefresh 复用进行中的全量刷新', {
1940
+ trigger
1941
+ });
1942
+ return this.silentRefreshPromise;
1943
+ }
1944
+ const now = Date.now();
1922
1945
  const elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
1923
1946
  const elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
1924
- if (this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS) {
1947
+ if (!this.serverFullFetchPromise && this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS) {
1925
1948
  this.logInfo('silentRefresh 跳过全量 SSE', {
1926
1949
  trigger,
1927
1950
  reason: 'within_min_interval',
@@ -1938,6 +1961,16 @@ class ProductsModule extends _BaseModule.BaseModule {
1938
1961
  elapsedSinceFullFetchMs,
1939
1962
  productCount: this.store.list.length
1940
1963
  });
1964
+ const refreshPromise = this.runSilentRefresh(trigger);
1965
+ this.silentRefreshPromise = refreshPromise;
1966
+ try {
1967
+ return await refreshPromise;
1968
+ } finally {
1969
+ if (this.silentRefreshPromise === refreshPromise) this.silentRefreshPromise = undefined;
1970
+ }
1971
+ }
1972
+ async runSilentRefresh(trigger) {
1973
+ const t0 = performance.now();
1941
1974
  try {
1942
1975
  const products = await this.loadProductsByServer({
1943
1976
  trigger
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
345
+ weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -389,7 +389,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
389
389
  };
390
390
  setOtherData(key: string, value: any): void;
391
391
  getOtherData(key: string): any;
392
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
392
+ getProductTypeById(id: number): Promise<"normal" | "session" | "duration">;
393
393
  /**
394
394
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
395
395
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.210",
4
+ "version": "2.3.211",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",