@pisell/pisellos 0.10.77 → 0.10.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/modules/Product/index.d.ts +1 -1
  2. package/dist/modules/ProductList/index.d.ts +2 -0
  3. package/dist/modules/ProductList/index.js +125 -39
  4. package/dist/modules/ResourcePlanner/planner.js +5 -0
  5. package/dist/solution/BaseSales/index.d.ts +12 -1
  6. package/dist/solution/BaseSales/index.js +275 -185
  7. package/dist/solution/BookingByStep/index.d.ts +2 -2
  8. package/dist/solution/BookingTicket/index.d.ts +1 -13
  9. package/dist/solution/UnifiedBookingSales/index.d.ts +23 -1
  10. package/dist/solution/UnifiedBookingSales/index.js +1307 -635
  11. package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  12. package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
  13. package/dist/solution/UnifiedBookingSales/types.d.ts +25 -2
  14. package/dist/solution/UnifiedBookingSales/types.js +2 -0
  15. package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  16. package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +277 -0
  17. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  18. package/lib/modules/Product/index.d.ts +1 -1
  19. package/lib/modules/ProductList/index.d.ts +2 -0
  20. package/lib/modules/ProductList/index.js +56 -0
  21. package/lib/modules/ResourcePlanner/planner.js +4 -0
  22. package/lib/solution/BaseSales/index.d.ts +12 -1
  23. package/lib/solution/BaseSales/index.js +65 -0
  24. package/lib/solution/BookingByStep/index.d.ts +2 -2
  25. package/lib/solution/BookingTicket/index.d.ts +1 -13
  26. package/lib/solution/UnifiedBookingSales/index.d.ts +23 -1
  27. package/lib/solution/UnifiedBookingSales/index.js +359 -5
  28. package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  29. package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
  30. package/lib/solution/UnifiedBookingSales/types.d.ts +25 -2
  31. package/lib/solution/UnifiedBookingSales/types.js +1 -0
  32. package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  33. package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +151 -0
  34. package/package.json +1 -1
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AvailabilitySessionResourceCache = void 0;
7
+ var _lodashEs = require("lodash-es");
8
+ var _localClock = require("../../modules/ResourcePlanner/localClock");
9
+ function datesInRange(range) {
10
+ const count = (0, _localClock.dateOrdinalFromLocalDate)(range.endDate) - (0, _localClock.dateOrdinalFromLocalDate)(range.startDate) + 1;
11
+ // A legal 90-business-day projection may include its preceding opening and overnight tail.
12
+ if (count < 1 || count > 92) throw new Error('Resource coverage requires a valid range of at most 92 days.');
13
+ const dates = [];
14
+ let date = (0, _localClock.formatLocalDate)(range.startDate);
15
+ for (let index = 0; index < count; index += 1) {
16
+ dates.push(date);
17
+ date = (0, _localClock.nextDate)(date);
18
+ }
19
+ return dates;
20
+ }
21
+ function resourceIdOf(resource) {
22
+ return resource.resourceId ?? resource.resource_id ?? resource.id;
23
+ }
24
+ function eventTime(event, edge) {
25
+ return String(event[`${edge}_at`] ?? event[`${edge}At`] ?? event[`${edge}_time`] ?? event[`${edge}Time`] ?? '');
26
+ }
27
+ function stableValue(value) {
28
+ if (Array.isArray(value)) return value.map(stableValue);
29
+ if (value && typeof value === 'object') {
30
+ return Object.keys(value).sort().reduce((result, key) => {
31
+ result[key] = stableValue(value[key]);
32
+ return result;
33
+ }, {});
34
+ }
35
+ return value;
36
+ }
37
+ function eventIdentity(event) {
38
+ const id = event.schedule_event_id ?? event.scheduleEventId ?? event.server_event_id ?? event.id;
39
+ const isUniqueEvent = id !== undefined && id !== null && id !== '';
40
+ return {
41
+ // A booking/product UID can own several allocations. Only an actual event ID plus its
42
+ // interval identifies one event; otherwise retain the complete payload and its multiplicity.
43
+ key: isUniqueEvent ? `event:${JSON.stringify([String(id), eventTime(event, 'start'), eventTime(event, 'end')])}` : `raw:${JSON.stringify(stableValue(event))}`,
44
+ isUniqueEvent
45
+ };
46
+ }
47
+ function eventsOnDate(events, date) {
48
+ const start = (0, _localClock.localDateToScalarStart)(date);
49
+ const end = (0, _localClock.localDateToScalarStart)((0, _localClock.nextDate)(date));
50
+ return events.filter(event => {
51
+ try {
52
+ const eventStart = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(eventTime(event, 'start')));
53
+ const eventEnd = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(eventTime(event, 'end')));
54
+ return eventStart < eventEnd && eventStart < end && eventEnd > start;
55
+ } catch {
56
+ return false;
57
+ }
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Opt-in venue-session snapshots. Unlike the legacy SWR cache, a covered resource/day is never
63
+ * refreshed or evicted during this session. Only missing cells are fetched, including when a new
64
+ * resource set partly overlaps an earlier one. The final backend submission remains authoritative.
65
+ */
66
+ class AvailabilitySessionResourceCache {
67
+ cells = new Map();
68
+ pending = new Map();
69
+ generation = 0;
70
+ clear() {
71
+ this.generation += 1;
72
+ this.cells.clear();
73
+ this.pending.clear();
74
+ }
75
+ async load(params) {
76
+ const generation = this.generation;
77
+ const assertCurrent = () => {
78
+ if (generation !== this.generation) {
79
+ throw Object.assign(new Error('Resource session changed while loading. Please prepare again.'), {
80
+ code: 'AVAILABILITY_CONTEXT_NOT_FOUND'
81
+ });
82
+ }
83
+ };
84
+ const resources = Array.from(new Map(params.resourceIds.filter(id => id !== undefined && id !== null && id !== '').map(id => [String(id), id])).values());
85
+ const dates = datesInRange(params.dateRange);
86
+ const key = (resourceId, date) => JSON.stringify([params.scopeKey, params.timezoneName, String(resourceId), date]);
87
+ const waits = new Set();
88
+ const gaps = [];
89
+ let previousIds = '';
90
+ dates.forEach(date => {
91
+ const missing = resources.filter(resourceId => {
92
+ const cellKey = key(resourceId, date);
93
+ if (this.cells.has(cellKey)) return false;
94
+ const pending = this.pending.get(cellKey);
95
+ if (pending) {
96
+ waits.add(pending);
97
+ return false;
98
+ }
99
+ return true;
100
+ }).sort((left, right) => String(left).localeCompare(String(right)));
101
+ const ids = JSON.stringify(missing.map(String));
102
+ const previous = gaps[gaps.length - 1];
103
+ if (missing.length && ids === previousIds && previous && (0, _localClock.nextDate)(previous.dateRange.endDate) === date) {
104
+ previous.dateRange.endDate = date;
105
+ } else if (missing.length) {
106
+ gaps.push({
107
+ resourceIds: missing,
108
+ dateRange: {
109
+ startDate: date,
110
+ endDate: date
111
+ }
112
+ });
113
+ }
114
+ previousIds = ids;
115
+ });
116
+
117
+ // Reserve every missing cell synchronously before dispatching any request. This also deduplicates
118
+ // partial overlapping in-flight queries, rather than only identical or fully covering requests.
119
+ gaps.forEach(query => {
120
+ const queryDates = datesInRange(query.dateRange);
121
+ const cellKeys = query.resourceIds.flatMap(id => queryDates.map(date => key(id, date)));
122
+ const promise = Promise.resolve().then(async () => {
123
+ assertCurrent();
124
+ const response = await params.fetch((0, _lodashEs.cloneDeep)(query));
125
+ assertCurrent();
126
+ if (!Array.isArray(response)) throw new Error('Booking resources returned an invalid response.');
127
+ const byId = new Map();
128
+ response.forEach(resource => {
129
+ if (!resource || typeof resource !== 'object' || Array.isArray(resource)) {
130
+ throw new Error('Booking resources returned an invalid resource.');
131
+ }
132
+ const id = resourceIdOf(resource);
133
+ if (typeof id !== 'string' && typeof id !== 'number' || id === '' || typeof id === 'number' && !Number.isFinite(id) || resource.event_list != null && !Array.isArray(resource.event_list)) {
134
+ throw new Error('Booking resources returned invalid identity or occupancy data.');
135
+ }
136
+ byId.set(String(id), (0, _lodashEs.cloneDeep)(resource));
137
+ });
138
+ // Assemble the response before publishing any cells, so malformed data cannot mark a
139
+ // partially successful range as covered. Missing resources in a valid response are cached too.
140
+ const updates = new Map();
141
+ query.resourceIds.forEach(id => {
142
+ const raw = byId.get(String(id));
143
+ const events = Array.isArray(raw?.event_list) ? raw.event_list : [];
144
+ const metadata = raw ? (({
145
+ event_list: _events,
146
+ ...rest
147
+ }) => rest)(raw) : null;
148
+ queryDates.forEach(date => updates.set(key(id, date), {
149
+ resource: metadata,
150
+ events: eventsOnDate(events, date)
151
+ }));
152
+ });
153
+ assertCurrent();
154
+ updates.forEach((cell, cellKey) => {
155
+ if (!this.cells.has(cellKey)) this.cells.set(cellKey, cell);
156
+ });
157
+ }).finally(() => {
158
+ cellKeys.forEach(cellKey => {
159
+ if (this.pending.get(cellKey) === promise) this.pending.delete(cellKey);
160
+ });
161
+ });
162
+ cellKeys.forEach(cellKey => this.pending.set(cellKey, promise));
163
+ waits.add(promise);
164
+ });
165
+ await Promise.all(Array.from(waits));
166
+ assertCurrent();
167
+ const result = [];
168
+ resources.forEach(id => {
169
+ let metadata = null;
170
+ const events = new Map();
171
+ dates.forEach(date => {
172
+ const cell = this.cells.get(key(id, date));
173
+ if (!cell) throw new Error('Resource session coverage was lost. Please prepare again.');
174
+ if (!metadata && cell.resource) metadata = cell.resource;
175
+ const occurrences = new Map();
176
+ cell.events.forEach(event => {
177
+ const identity = eventIdentity(event);
178
+ const occurrence = identity.isUniqueEvent ? 0 : occurrences.get(identity.key) || 0;
179
+ occurrences.set(identity.key, occurrence + 1);
180
+ const occupancyKey = JSON.stringify([identity.key, occurrence]);
181
+ // Merge the maximum count seen in a day, not a set of booking UIDs: anonymous duplicate
182
+ // allocations must still count twice, while one cross-midnight event counts only once.
183
+ if (!events.has(occupancyKey)) events.set(occupancyKey, {
184
+ ...event,
185
+ __availabilitySessionOccupancyKey: occupancyKey
186
+ });
187
+ });
188
+ });
189
+ if (metadata) {
190
+ result.push((0, _lodashEs.cloneDeep)({
191
+ ...metadata,
192
+ event_list: Array.from(events.values()).sort((left, right) => eventTime(left, 'start').localeCompare(eventTime(right, 'start')) || eventTime(left, 'end').localeCompare(eventTime(right, 'end')))
193
+ }));
194
+ }
195
+ });
196
+ return result;
197
+ }
198
+ }
199
+ exports.AvailabilitySessionResourceCache = AvailabilitySessionResourceCache;
@@ -6,6 +6,7 @@ import type { AvailabilityDateRange, AvailabilityErrorCode, AvailabilityId, Avai
6
6
  import type { BookingTicketState } from '../BookingTicket/types';
7
7
  import type { AllergyRequirement } from '../../model/strategy/adapter/itemRule';
8
8
  import type { SalesNoteDraftInput } from '../../modules/Order/types';
9
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../BaseSales/types';
9
10
  export type { ProductListStoreQueryParams } from '../../modules/ProductList';
10
11
  export type { AvailabilityAbsoluteRange, AvailabilityAssignment, AvailabilityCell, AvailabilityDateRange, AvailabilityDisplayRange, AvailabilityErrorCode, AvailabilityId, AvailabilityMode, AvailabilityOccupancy, AvailabilityProduct, AvailabilityProductKind, AvailabilityProjection, AvailabilityProjectionInput, AvailabilityProjectionMeta, AvailabilityQuery, AvailabilityQueryResult, AvailabilityRequirementGroup, AvailabilityRequirementGroupResult, AvailabilityRequirementSelection, AvailabilityResource, AvailabilityResourceOption, AvailabilityResourceType, AvailabilityResourceWindow, AvailabilityScheduleMode, AvailabilityScheduleRef, AvailabilityScheduleRule, AvailabilitySelectionValidationParams, AvailabilitySelectionValidationResult, AvailabilitySessionRange, AvailabilityStatus, DateAvailabilityGroup, DateAvailabilityItem, DateAvailabilityQuery, DateAvailabilityQueryResult, GetProductTimeRangesRequest, ProductAvailabilityGroup, ProductAvailabilityItem, ProductAvailabilityQuery, ProductAvailabilityQueryResult, ProductTimeRange, ProductTimeRangeGroup, QueryAvailabilityBaseRequest, ResourceAvailabilityGroup, ResourceAvailabilityQuery, ResourceAvailabilityQueryResult, ResourceAvailabilityRangeGroup, TimeAvailabilityGroup, TimeAvailabilityItem, TimeAvailabilityQuery, TimeAvailabilityQueryResult, } from '../../modules/ResourcePlanner';
11
12
  export interface UnifiedBookingSalesState extends BookingTicketState {
@@ -19,6 +20,28 @@ export interface UnifiedBookingSalesCatalogQueryBatch {
19
20
  /** Releases retained results. A disposed batch cannot be reused. */
20
21
  dispose(): void;
21
22
  }
23
+ /** Venue page lifetime pool. Reads/quotes stay local; explicit opening may hydrate a variant once. */
24
+ export interface UnifiedBookingSalesVenueCatalogSession {
25
+ queryCatalogSnapshot(params?: ProductListLoadProductsParams): Promise<ProductData[]>;
26
+ queryCatalogProductDetail(params: ProductListLoadProductsParams & {
27
+ product_id: number;
28
+ }): Promise<ProductData | undefined>;
29
+ /** User-initiated opening only. Non-variant products never load a detail endpoint. */
30
+ prepareProductDetail(params: ProductListLoadProductsParams & {
31
+ product_id: number;
32
+ retry?: boolean;
33
+ }): Promise<ProductData | undefined>;
34
+ calculateProductBookingPrice(params: BaseSalesCalculateProductBookingPriceParams): Promise<BaseSalesProductBookingPriceResult>;
35
+ /** Retries failed pool/detail loads; successfully loaded records remain cached. */
36
+ retry(): void;
37
+ dispose(): void;
38
+ }
39
+ export type UnifiedBookingSalesVenueCatalogSessionParams = ProductListLoadProductsParams & {
40
+ /** Stable page/order session identity shared by main and extras pools. */
41
+ sessionKey?: string;
42
+ /** Lets implicit order repricing select the originating pool without guessing by product ID. */
43
+ poolRole?: 'main' | 'extras';
44
+ };
22
45
  export interface UnifiedBookingSalesPolicy {
23
46
  id?: AvailabilityId;
24
47
  title?: unknown;
@@ -85,8 +108,8 @@ export interface UnifiedBookingSalesPrepareAvailabilityProjectionParams {
85
108
  publishCatalog?: boolean;
86
109
  /** Await remote occupancy refresh instead of stale-while-revalidate. Ignores rawResources; does not lock resources. */
87
110
  refreshOccupancies?: boolean;
88
- /** Preview only: reuse complete resource/date coverage for 30 seconds without a background request. refreshOccupancies takes precedence. Omit to retain stale-while-revalidate. */
89
- occupancyCachePolicy?: 'cache_first';
111
+ /** cache_first: 30-second preview. session: retain resource/date coverage for this venue page, including commit; overrides refreshOccupancies. Omit for legacy SWR. */
112
+ occupancyCachePolicy?: 'cache_first' | 'session';
90
113
  /** Enforce configured sale cutoffs and disable manual POS availability overrides for this context. Defaults to false. */
91
114
  strictAvailability?: boolean;
92
115
  rawResources?: Record<string, any>[];
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.UnifiedBookingSalesHooks = void 0;
7
7
  /** Read-only preview scope; existing solution queries remain fresh for selection and submission. */
8
+ /** Venue page lifetime pool. Reads/quotes stay local; explicit opening may hydrate a variant once. */
8
9
  let UnifiedBookingSalesHooks = exports.UnifiedBookingSalesHooks = /*#__PURE__*/function (UnifiedBookingSalesHooks) {
9
10
  UnifiedBookingSalesHooks["onAvailabilityProjectionPrepared"] = "unifiedBookingSales:onAvailabilityProjectionPrepared";
10
11
  UnifiedBookingSalesHooks["onAvailabilitySelectionCommitted"] = "unifiedBookingSales:onAvailabilitySelectionCommitted";
@@ -0,0 +1,32 @@
1
+ import type { ProductData } from '../../modules/Product/types';
2
+ import type { ProductListLoadProductsParams } from '../../modules/ProductList';
3
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../BaseSales/types';
4
+ import type { UnifiedBookingSalesVenueCatalogSession } from './types';
5
+ export type VenueCatalogRecord = Record<string, any>;
6
+ export interface VenueCatalogPool {
7
+ products: ProductData[];
8
+ menus: VenueCatalogRecord[];
9
+ /** Pricing menu_match follows the OS evaluator's full menu-definition contract. */
10
+ pricingMenus: VenueCatalogRecord[];
11
+ }
12
+ export declare function venueCatalogError(code: string, message: string): Error & {
13
+ code: string;
14
+ };
15
+ export declare function readVenueCatalogList(response: any, description: string): VenueCatalogRecord[];
16
+ export declare function validateVenueMenus(records: VenueCatalogRecord[], ids: number[]): VenueCatalogRecord[];
17
+ /** Same ID/collection union as the local OS product query; variant selection stays with SKU validation. */
18
+ export declare function productMatchesVenueMenu(product: VenueCatalogRecord, menu: VenueCatalogRecord): boolean;
19
+ export declare function activeVenueMenus(menus: VenueCatalogRecord[], schedules: VenueCatalogRecord[], datetime: string, dateOnly?: boolean): VenueCatalogRecord[];
20
+ /** Internal loader injection is not exposed to material callers. Rejected loads remain rejected until explicit retry. */
21
+ export declare function createVenueCatalogSessionAdapter(options: {
22
+ assertCurrent(): void;
23
+ load(): Promise<VenueCatalogPool>;
24
+ snapshot(pool: VenueCatalogPool, params: ProductListLoadProductsParams): ProductData[];
25
+ prepareDetail(pool: VenueCatalogPool, params: ProductListLoadProductsParams & {
26
+ product_id: number;
27
+ retry?: boolean;
28
+ }): Promise<void>;
29
+ quote(pool: VenueCatalogPool, params: BaseSalesCalculateProductBookingPriceParams): Promise<BaseSalesProductBookingPriceResult>;
30
+ onDispose?(): void;
31
+ onRetry?(): void;
32
+ }): UnifiedBookingSalesVenueCatalogSession;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.activeVenueMenus = activeVenueMenus;
7
+ exports.createVenueCatalogSessionAdapter = createVenueCatalogSessionAdapter;
8
+ exports.productMatchesVenueMenu = productMatchesVenueMenu;
9
+ exports.readVenueCatalogList = readVenueCatalogList;
10
+ exports.validateVenueMenus = validateVenueMenus;
11
+ exports.venueCatalogError = venueCatalogError;
12
+ var _lodashEs = require("lodash-es");
13
+ var _getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
14
+ function venueCatalogError(code, message) {
15
+ return Object.assign(new Error(message), {
16
+ code
17
+ });
18
+ }
19
+ function readVenueCatalogList(response, description) {
20
+ const list = response?.data?.list;
21
+ if (!response || response.status === false || response.success === false || response.code != null && Number(response.code) !== 200 || !Array.isArray(list)) {
22
+ throw venueCatalogError('VENUE_CATALOG_LOAD_FAILED', response?.message || `${description} could not be loaded.`);
23
+ }
24
+ const total = response.data.total ?? response.data.total_count ?? response.data.total_num;
25
+ if (total != null && Number.isFinite(Number(total)) && Number(total) > list.length) {
26
+ throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', `${description} is incomplete. A complete catalog response is required.`);
27
+ }
28
+ return list;
29
+ }
30
+ function validateVenueMenus(records, ids) {
31
+ return ids.map(id => {
32
+ const menu = records.find(row => Number(row.form_record_id) === id);
33
+ const config = menu?.partyroom_package;
34
+ if (!menu || !['product_all', 'products', 'product_collection'].includes(config?.type) || !Array.isArray(menu.schedule) || menu.schedule.some(value => !Number.isSafeInteger(Number(value)) || Number(value) <= 0) || config.type !== 'product_all' && (!Array.isArray(config.products) || config.products.some(row => {
35
+ const value = Number(row?.[config.type === 'products' ? 'product_id' : 'product_collection_id']);
36
+ return !Number.isSafeInteger(value) || value <= 0;
37
+ }))) {
38
+ throw venueCatalogError('VENUE_MENU_INCOMPLETE', 'The configured menu is incomplete. Reload the booking page.');
39
+ }
40
+ return (0, _lodashEs.cloneDeep)(menu);
41
+ });
42
+ }
43
+
44
+ /** Same ID/collection union as the local OS product query; variant selection stays with SKU validation. */
45
+ function productMatchesVenueMenu(product, menu) {
46
+ if (menu.status && menu.status !== 'valid') return false;
47
+ const config = menu.partyroom_package;
48
+ if (config?.type === 'product_all') return true;
49
+ if (config?.type === 'products') return config.products.some(row => Number(row.product_id) === Number(product.id));
50
+ if (config?.type === 'product_collection') {
51
+ if (!Array.isArray(product.collection)) {
52
+ throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', 'Product collection data is missing from the catalog.');
53
+ }
54
+ return config.products.some(row => product.collection.some(collection => Number(collection.id) === Number(row.product_collection_id)));
55
+ }
56
+ return false;
57
+ }
58
+ function activeVenueMenus(menus, schedules, datetime, dateOnly = false) {
59
+ const scheduleMap = new Map(schedules.map(row => [Number(row.id), row]));
60
+ return menus.filter(menu => {
61
+ if (menu.status && menu.status !== 'valid') return false;
62
+ const records = menu.schedule.map(id => scheduleMap.get(Number(id)));
63
+ if (records.some(record => !record)) {
64
+ throw venueCatalogError('VENUE_SCHEDULE_INCOMPLETE', 'Menu schedule data is not ready. Please retry.');
65
+ }
66
+ // A calendar/card read asks whether the menu opens at any point on that date.
67
+ // Only selected-time/retail quotes require membership at an exact instant.
68
+ return dateOnly ? (0, _getDateIsInSchedule.getScheduleStartEndTimePoints)(datetime.slice(0, 10), records).length > 0 : (0, _getDateIsInSchedule.getDateIsInSchedule)(datetime, records);
69
+ });
70
+ }
71
+
72
+ /** Internal loader injection is not exposed to material callers. Rejected loads remain rejected until explicit retry. */
73
+ function createVenueCatalogSessionAdapter(options) {
74
+ let disposed = false;
75
+ let failed = false;
76
+ let pending;
77
+ const assertCurrent = () => {
78
+ if (disposed) throw venueCatalogError('VENUE_CATALOG_DISPOSED', 'The venue catalog session is closed.');
79
+ options.assertCurrent();
80
+ };
81
+ const load = async () => {
82
+ assertCurrent();
83
+ if (!pending) {
84
+ pending = Promise.resolve().then(() => {
85
+ assertCurrent();
86
+ return options.load();
87
+ }).then(pool => {
88
+ assertCurrent();
89
+ return (0, _lodashEs.cloneDeep)(pool);
90
+ }).catch(error => {
91
+ failed = true;
92
+ throw error;
93
+ });
94
+ }
95
+ const pool = await pending;
96
+ assertCurrent();
97
+ return pool;
98
+ };
99
+ return {
100
+ queryCatalogSnapshot: async (params = {}) => {
101
+ const pool = await load();
102
+ const result = options.snapshot(pool, (0, _lodashEs.cloneDeep)(params));
103
+ assertCurrent();
104
+ return (0, _lodashEs.cloneDeep)(result);
105
+ },
106
+ queryCatalogProductDetail: async ({
107
+ product_id,
108
+ ...params
109
+ }) => {
110
+ const pool = await load();
111
+ const result = options.snapshot(pool, {
112
+ ...(0, _lodashEs.cloneDeep)(params),
113
+ product_ids: [product_id]
114
+ });
115
+ assertCurrent();
116
+ return (0, _lodashEs.cloneDeep)(result.find(product => Number(product.id) === Number(product_id)));
117
+ },
118
+ prepareProductDetail: async params => {
119
+ const pool = await load();
120
+ const query = {
121
+ ...(0, _lodashEs.cloneDeep)(params),
122
+ product_ids: [params.product_id]
123
+ };
124
+ if (!options.snapshot(pool, query).some(product => Number(product.id) === Number(params.product_id))) return undefined;
125
+ await options.prepareDetail(pool, (0, _lodashEs.cloneDeep)(params));
126
+ assertCurrent();
127
+ return (0, _lodashEs.cloneDeep)(options.snapshot(pool, query).find(product => Number(product.id) === Number(params.product_id)));
128
+ },
129
+ calculateProductBookingPrice: async params => {
130
+ const pool = await load();
131
+ const result = await options.quote(pool, (0, _lodashEs.cloneDeep)(params));
132
+ assertCurrent();
133
+ return (0, _lodashEs.cloneDeep)(result);
134
+ },
135
+ retry: () => {
136
+ assertCurrent();
137
+ if (failed) {
138
+ pending = undefined;
139
+ failed = false;
140
+ }
141
+ options.onRetry?.();
142
+ },
143
+ dispose: () => {
144
+ if (!disposed) {
145
+ disposed = true;
146
+ pending = undefined;
147
+ options.onDispose?.();
148
+ }
149
+ }
150
+ };
151
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.10.77",
4
+ "version": "0.10.78",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",