@pisell/pisellos 0.10.97 → 0.10.98

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,9 +0,0 @@
1
- // 导出评估器
2
- export { PromotionEvaluator } from "./evaluator";
3
-
4
- // 导出适配器
5
- export { PromotionAdapter } from "./adapter";
6
- export { default } from "./adapter";
7
-
8
- // 导出策略配置示例常量
9
- export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -21,6 +21,23 @@ var DEFAULT_BUSINESS_HOURS = {
21
21
  startTime: '00:00',
22
22
  endTime: '00:00'
23
23
  };
24
+ // Only factory-owned snapshots are immutable. A caller may provide a mutable
25
+ // projection, or freeze its outer object without freezing its products/cells.
26
+ var immutableProjections = new WeakSet();
27
+ var projectionStaticIndices = new WeakMap();
28
+ function getProjectionStaticIndex(projection, key, build) {
29
+ if (!immutableProjections.has(projection)) return build(projection);
30
+ var indices = projectionStaticIndices.get(projection);
31
+ if (!indices) {
32
+ indices = {};
33
+ projectionStaticIndices.set(projection, indices);
34
+ }
35
+ var existing = indices[key];
36
+ if (existing) return existing;
37
+ var index = build(projection);
38
+ indices[key] = index;
39
+ return index;
40
+ }
24
41
  function availabilityError(code, message, details) {
25
42
  return new AvailabilityError(code, message, details);
26
43
  }
@@ -882,9 +899,11 @@ export function createAvailabilityProjection(input) {
882
899
  resources: resources,
883
900
  resourceOccupancies: resourceOccupancies
884
901
  };
885
- return deepFreeze(_objectSpread(_objectSpread({}, projectionBase), {}, {
902
+ var projection = deepFreeze(_objectSpread(_objectSpread({}, projectionBase), {}, {
886
903
  cells: buildCells(projectionBase)
887
904
  }));
905
+ immutableProjections.add(projection);
906
+ return projection;
888
907
  }
889
908
  function uniqByOccupancy(occupancies) {
890
909
  var map = new Map();
@@ -2255,8 +2274,8 @@ export function queryAvailabilityProjection(projection, request) {
2255
2274
  assertRangesWithinProjection(projection, request.selectedRanges);
2256
2275
  }
2257
2276
  var productIdSet = (_request$productIds2 = request.productIds) !== null && _request$productIds2 !== void 0 && _request$productIds2.length ? new Set(request.productIds.map(String)) : null;
2258
- var productIndex = buildProductIndex(projection);
2259
- var cellIndex = buildAvailabilityCellIndex(projection);
2277
+ var productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
2278
+ var cellIndex = getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex);
2260
2279
  var groupResourceIndex = buildGroupResourceIndex({
2261
2280
  projection: projection,
2262
2281
  resourceIds: request.resourceIds,
@@ -2577,14 +2596,14 @@ export function validateAvailabilitySelection(projection, params) {
2577
2596
  var normalizedPartySize = normalizePartySize(params.partySize);
2578
2597
  var normalizedBookingCount = normalizeBookingCount(params.bookingCount);
2579
2598
  assertRangesWithinProjection(projection, [params.candidate]);
2580
- var productIndex = buildProductIndex(projection);
2599
+ var productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
2581
2600
  var evaluatedAt = formatDateTime(localDateToScalar(new Date()), projection.meta.timezone, (_extractFixedOffsetMi7 = extractFixedOffsetMinutes(projection.meta.now)) !== null && _extractFixedOffsetMi7 !== void 0 ? _extractFixedOffsetMi7 : captureRuntimeOffsetMinutes());
2582
2601
  var evaluated = evaluateCandidate(projection, params.candidate, {
2583
2602
  partySize: normalizedPartySize,
2584
2603
  evaluatedAt: evaluatedAt,
2585
2604
  requirementSelections: params.requirementSelections,
2586
2605
  allowImplicitSelection: false,
2587
- cellIndex: buildAvailabilityCellIndex(projection),
2606
+ cellIndex: getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex),
2588
2607
  productIndex: productIndex,
2589
2608
  groupResourceIndex: buildGroupResourceIndex({
2590
2609
  projection: projection,
@@ -15,6 +15,23 @@ const DEFAULT_BUSINESS_HOURS = {
15
15
  startTime: '00:00',
16
16
  endTime: '00:00'
17
17
  };
18
+ // Only factory-owned snapshots are immutable. A caller may provide a mutable
19
+ // projection, or freeze its outer object without freezing its products/cells.
20
+ const immutableProjections = new WeakSet();
21
+ const projectionStaticIndices = new WeakMap();
22
+ function getProjectionStaticIndex(projection, key, build) {
23
+ if (!immutableProjections.has(projection)) return build(projection);
24
+ let indices = projectionStaticIndices.get(projection);
25
+ if (!indices) {
26
+ indices = {};
27
+ projectionStaticIndices.set(projection, indices);
28
+ }
29
+ const existing = indices[key];
30
+ if (existing) return existing;
31
+ const index = build(projection);
32
+ indices[key] = index;
33
+ return index;
34
+ }
18
35
  function availabilityError(code, message, details) {
19
36
  return new _types.AvailabilityError(code, message, details);
20
37
  }
@@ -799,10 +816,12 @@ function createAvailabilityProjection(input) {
799
816
  resources,
800
817
  resourceOccupancies
801
818
  };
802
- return deepFreeze({
819
+ const projection = deepFreeze({
803
820
  ...projectionBase,
804
821
  cells: buildCells(projectionBase)
805
822
  });
823
+ immutableProjections.add(projection);
824
+ return projection;
806
825
  }
807
826
  function uniqByOccupancy(occupancies) {
808
827
  const map = new Map();
@@ -1919,8 +1938,8 @@ function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
1919
1938
  assertRangesWithinProjection(projection, request.selectedRanges);
1920
1939
  }
1921
1940
  const productIdSet = request.productIds?.length ? new Set(request.productIds.map(String)) : null;
1922
- const productIndex = buildProductIndex(projection);
1923
- const cellIndex = buildAvailabilityCellIndex(projection);
1941
+ const productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
1942
+ const cellIndex = getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex);
1924
1943
  const groupResourceIndex = buildGroupResourceIndex({
1925
1944
  projection,
1926
1945
  resourceIds: request.resourceIds,
@@ -2195,14 +2214,14 @@ function validateAvailabilitySelection(projection, params, runtimeOptions = {})
2195
2214
  const normalizedPartySize = normalizePartySize(params.partySize);
2196
2215
  const normalizedBookingCount = normalizeBookingCount(params.bookingCount);
2197
2216
  assertRangesWithinProjection(projection, [params.candidate]);
2198
- const productIndex = buildProductIndex(projection);
2217
+ const productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
2199
2218
  const evaluatedAt = formatDateTime((0, _localClock.localDateToScalar)(new Date()), projection.meta.timezone, (0, _localClock.extractFixedOffsetMinutes)(projection.meta.now) ?? (0, _localClock.captureRuntimeOffsetMinutes)());
2200
2219
  const evaluated = evaluateCandidate(projection, params.candidate, {
2201
2220
  partySize: normalizedPartySize,
2202
2221
  evaluatedAt,
2203
2222
  requirementSelections: params.requirementSelections,
2204
2223
  allowImplicitSelection: false,
2205
- cellIndex: buildAvailabilityCellIndex(projection),
2224
+ cellIndex: getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex),
2206
2225
  productIndex,
2207
2226
  groupResourceIndex: buildGroupResourceIndex({
2208
2227
  projection,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.10.97",
4
+ "version": "0.10.98",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",