@pisell/pisellos 0.10.94 → 0.10.96
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.
- package/dist/modules/OpenData/index.d.ts +13 -0
- package/dist/modules/OpenData/index.js +243 -93
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/SalesSummary/index.d.ts +3 -0
- package/dist/modules/SalesSummary/index.js +104 -56
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +1036 -598
- package/dist/server/modules/order/index.d.ts +1 -0
- package/dist/server/modules/order/index.js +51 -51
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
- package/dist/solution/Sales/index.d.ts +2 -1
- package/dist/solution/Sales/index.js +154 -48
- package/dist/solution/Sales/types.d.ts +12 -0
- package/dist/solution/Sales/types.js +2 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +1 -0
- package/dist/solution/UnifiedBookingSales/index.js +48 -49
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +4 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +91 -14
- package/lib/modules/OpenData/index.d.ts +13 -0
- package/lib/modules/OpenData/index.js +97 -18
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/SalesSummary/index.d.ts +3 -0
- package/lib/modules/SalesSummary/index.js +36 -15
- package/lib/server/index.d.ts +7 -0
- package/lib/server/index.js +240 -18
- package/lib/server/modules/order/index.d.ts +1 -0
- package/lib/server/modules/order/index.js +4 -3
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +8 -8
- package/lib/solution/Sales/index.d.ts +2 -1
- package/lib/solution/Sales/index.js +53 -0
- package/lib/solution/Sales/types.d.ts +12 -0
- package/lib/solution/Sales/types.js +1 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +1 -0
- package/lib/solution/UnifiedBookingSales/index.js +11 -10
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +4 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +69 -4
- package/package.json +1 -1
|
@@ -678,6 +678,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
678
678
|
}
|
|
679
679
|
async getLocalOrderByLookup(lookup, options = {}) {
|
|
680
680
|
const key = this.getIdKey(lookup);
|
|
681
|
+
const matches = order => options.exactOrderId ? order.order_id != null && this.getIdKey(order.order_id) === key : this.isOrderLookupMatch(order, key);
|
|
681
682
|
const logContext = {
|
|
682
683
|
operation_id: options.operationId,
|
|
683
684
|
lookup: key,
|
|
@@ -687,7 +688,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
687
688
|
this.logInfo('getLocalOrderByLookup-localPayment-开始', logContext);
|
|
688
689
|
}
|
|
689
690
|
const memoryOrderById = this.store.map.get(key);
|
|
690
|
-
if (memoryOrderById) {
|
|
691
|
+
if (memoryOrderById && (!options.exactOrderId || matches(memoryOrderById))) {
|
|
691
692
|
if (options.operationId) {
|
|
692
693
|
this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', {
|
|
693
694
|
...logContext,
|
|
@@ -696,7 +697,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
696
697
|
}
|
|
697
698
|
return memoryOrderById;
|
|
698
699
|
}
|
|
699
|
-
const memoryOrder = this.store.list.find(
|
|
700
|
+
const memoryOrder = this.store.list.find(matches);
|
|
700
701
|
if (memoryOrder) {
|
|
701
702
|
if (options.operationId) {
|
|
702
703
|
this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', {
|
|
@@ -710,7 +711,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
710
711
|
this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
|
|
711
712
|
}
|
|
712
713
|
const orders = await this.loadOrdersFromSQLite();
|
|
713
|
-
const localOrder = orders.find(
|
|
714
|
+
const localOrder = orders.find(matches);
|
|
714
715
|
if (!localOrder) {
|
|
715
716
|
if (options.operationId) {
|
|
716
717
|
this.logWarning('getLocalOrderByLookup-localPayment-SQLite未命中', {
|
|
@@ -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 |
|
|
345
|
+
weekNum: 0 | 5 | 1 | 2 | 4 | 3 | 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<"
|
|
392
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
393
393
|
/**
|
|
394
394
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
395
395
|
*
|
|
@@ -25,18 +25,18 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
|
|
|
25
25
|
notes?: import("../../../modules/Order/types").SalesNote[] | undefined;
|
|
26
26
|
summary?: import("../../../modules/Order/types").OrderSummary | undefined;
|
|
27
27
|
bookings: any[];
|
|
28
|
-
order_id: number | null;
|
|
29
28
|
external_sale_number: string;
|
|
29
|
+
payments: any[];
|
|
30
|
+
customer_id: number | null;
|
|
31
|
+
order_id: number | null;
|
|
30
32
|
order_number: string | null;
|
|
31
33
|
shop_order_number: string | null;
|
|
32
|
-
shop_full_order_number: string | null;
|
|
33
34
|
type: string;
|
|
34
35
|
business_code?: string | undefined;
|
|
35
36
|
sales_channel: string;
|
|
36
37
|
order_sales_channel: string;
|
|
37
38
|
status: string;
|
|
38
39
|
shipping_status: string;
|
|
39
|
-
customer_id: number | null;
|
|
40
40
|
customer_name: string;
|
|
41
41
|
country_calling_code: string;
|
|
42
42
|
phone: string;
|
|
@@ -52,20 +52,20 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
|
|
|
52
52
|
shop_discount: string;
|
|
53
53
|
surcharge_fee: string;
|
|
54
54
|
note: string;
|
|
55
|
-
buzzer?: string | undefined;
|
|
56
|
-
delivery_type?: string | undefined;
|
|
57
|
-
table_number?: Record<string, any> | undefined;
|
|
58
55
|
schedule_date: string;
|
|
59
|
-
holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
|
|
60
|
-
payments: any[];
|
|
61
56
|
refunds?: any[] | undefined;
|
|
62
57
|
surcharges: any[];
|
|
63
58
|
relation_forms: any[];
|
|
64
59
|
contacts: any[];
|
|
65
60
|
contacts_info: Record<string, any> | null;
|
|
66
61
|
holder: Record<string, any> | null;
|
|
62
|
+
holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
|
|
67
63
|
order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
|
|
68
64
|
metadata: Record<string, any>;
|
|
65
|
+
buzzer?: string | undefined;
|
|
66
|
+
shop_full_order_number: string | null;
|
|
67
|
+
delivery_type?: string | undefined;
|
|
68
|
+
table_number?: Record<string, any> | undefined;
|
|
69
69
|
};
|
|
70
70
|
export declare function describeChangedBookings(before: OrderTempOrder['bookings'], after: OrderTempOrder['bookings']): {
|
|
71
71
|
schedule_event_id: any;
|
|
@@ -2,7 +2,7 @@ import dayjs from 'dayjs';
|
|
|
2
2
|
import { Module, ModuleOptions, PisellCore } from '../../types';
|
|
3
3
|
import { BaseModule } from '../../modules/BaseModule';
|
|
4
4
|
import type { RequestPlugin } from '../../plugins/request';
|
|
5
|
-
import { SalesState, SalesModuleAPI, Reservation, SalesResourceBookingItem, SalesResourceBookingItemWithGroups, SalesTimelineHighlights, ChangeBookingStatusParams, GetResourceBookingItemParams, SalesPrintLocalOrderReceiptOptions } from './types';
|
|
5
|
+
import { SalesState, SalesModuleAPI, Reservation, SalesResourceBookingItem, SalesResourceBookingItemWithGroups, SalesTimelineHighlights, ChangeBookingStatusParams, GetResourceBookingItemParams, SalesPrintLocalOrderReceiptOptions, CloudOrderInvoiceRequest, CloudOrderInvoiceResult } from './types';
|
|
6
6
|
import type { BookingData } from '../../server/modules/order/types';
|
|
7
7
|
export * from './types';
|
|
8
8
|
/**
|
|
@@ -55,6 +55,7 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
|
|
|
55
55
|
private logInvoiceOpenDataFallback;
|
|
56
56
|
private resolveInvoiceConfigs;
|
|
57
57
|
printLocalOrderReceipt<T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions): Promise<T>;
|
|
58
|
+
printCloudOrderInvoice(input: CloudOrderInvoiceRequest): Promise<CloudOrderInvoiceResult>;
|
|
58
59
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
59
60
|
clearOpenDataCache(): void;
|
|
60
61
|
destroy(): Promise<void>;
|
|
@@ -287,6 +287,59 @@ class SalesImpl extends _BaseModule.BaseModule {
|
|
|
287
287
|
customToast: () => {}
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
|
+
async printCloudOrderInvoice(input) {
|
|
291
|
+
const openData = this.invoiceOpenDataModule;
|
|
292
|
+
if (!openData) throw new Error('Cloud Invoice is not initialized');
|
|
293
|
+
const orderId = typeof input?.order_id === 'string' ? input.order_id.trim() : Number.isSafeInteger(input?.order_id) ? String(input.order_id) : '';
|
|
294
|
+
const channel = typeof input?.channel === 'string' ? input.channel.trim() : '';
|
|
295
|
+
const messageUuid = typeof input?.message_uuid === 'string' ? input.message_uuid.trim() : '';
|
|
296
|
+
if (!/^[1-9]\d*$/.test(orderId) || !channel || !messageUuid) {
|
|
297
|
+
throw new Error('Cloud Invoice requires order_id, channel and message_uuid');
|
|
298
|
+
}
|
|
299
|
+
const scope = openData.captureCloudInvoiceScope(input.shop_id);
|
|
300
|
+
const event = {
|
|
301
|
+
order_id: orderId,
|
|
302
|
+
channel,
|
|
303
|
+
message_uuid: messageUuid,
|
|
304
|
+
shop_id: scope.shopId
|
|
305
|
+
};
|
|
306
|
+
const requestOptions = {
|
|
307
|
+
osServer: true,
|
|
308
|
+
customToast: () => {}
|
|
309
|
+
};
|
|
310
|
+
const lookup = await this.request.post('/shop/local/cloud-order-invoice/lookup', event, requestOptions);
|
|
311
|
+
scope.assertCurrent();
|
|
312
|
+
if (lookup?.status !== true || lookup.code !== 200) {
|
|
313
|
+
throw new Error(lookup?.message || 'Cloud Invoice order lookup failed');
|
|
314
|
+
}
|
|
315
|
+
const accepted = lookup.data?.task_uuid;
|
|
316
|
+
if (typeof accepted === 'string' && accepted.trim()) return {
|
|
317
|
+
task_uuid: accepted
|
|
318
|
+
};
|
|
319
|
+
const rawBusinessCode = lookup.data?.business_code;
|
|
320
|
+
const businessCode = typeof rawBusinessCode === 'string' ? rawBusinessCode.trim() : '';
|
|
321
|
+
if (!businessCode) throw new Error('Cloud Invoice order has no business_code');
|
|
322
|
+
const deviceId = lookup.data?.device_id;
|
|
323
|
+
if (typeof deviceId !== 'string' || !deviceId.trim()) {
|
|
324
|
+
throw new Error('Cloud Invoice lookup has no device_id');
|
|
325
|
+
}
|
|
326
|
+
const settings = await openData.loadCloudInvoiceTemplate(`${businessCode}+${channel}`, scope);
|
|
327
|
+
scope.assertCurrent();
|
|
328
|
+
const submitted = await this.request.post('/shop/local/cloud-order-invoice/submit', {
|
|
329
|
+
...event,
|
|
330
|
+
business_code: businessCode,
|
|
331
|
+
device_id: deviceId,
|
|
332
|
+
template_settings: (0, _lodashEs.cloneDeep)(settings)
|
|
333
|
+
}, requestOptions);
|
|
334
|
+
scope.assertCurrent();
|
|
335
|
+
const taskUuid = submitted?.data?.task_uuid;
|
|
336
|
+
if (submitted?.status !== true || submitted.code !== 200 || typeof taskUuid !== 'string' || !taskUuid.trim()) {
|
|
337
|
+
throw new Error(submitted?.message || 'Cloud Invoice task was not accepted');
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
task_uuid: taskUuid
|
|
341
|
+
};
|
|
342
|
+
}
|
|
290
343
|
|
|
291
344
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
292
345
|
clearOpenDataCache() {
|
|
@@ -56,6 +56,17 @@ export interface SalesPrintLocalOrderReceiptOptions {
|
|
|
56
56
|
/** 当前销售入口;缺失或为 system 时按 pos 处理。 */
|
|
57
57
|
channel?: string;
|
|
58
58
|
}
|
|
59
|
+
/** Order and delivery identity supplied by the native cloud-print listener. */
|
|
60
|
+
export interface CloudOrderInvoiceRequest {
|
|
61
|
+
shop_id: string | number;
|
|
62
|
+
order_id: string | number;
|
|
63
|
+
message_uuid: string;
|
|
64
|
+
channel: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CloudOrderInvoiceResult {
|
|
67
|
+
/** DeviceTask accepted for this message on the current device. */
|
|
68
|
+
task_uuid: string;
|
|
69
|
+
}
|
|
59
70
|
/**
|
|
60
71
|
* Sales 解决方案状态
|
|
61
72
|
*
|
|
@@ -90,6 +101,7 @@ export interface SalesModuleAPI {
|
|
|
90
101
|
changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
|
|
91
102
|
/** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
|
|
92
103
|
printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
|
|
104
|
+
printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<CloudOrderInvoiceResult>;
|
|
93
105
|
/** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
|
|
94
106
|
clearOpenDataCache: () => void;
|
|
95
107
|
/** 获取资源维度的预约占用列表 */
|
|
@@ -18,6 +18,7 @@ let SalesHooks = exports.SalesHooks = /*#__PURE__*/function (SalesHooks) {
|
|
|
18
18
|
* 将 Server/Order 原始数据转换为真正的 Reservation DTO,
|
|
19
19
|
* 当前不要直接把 OrderData 当作最终 UI 数据结构。
|
|
20
20
|
*/
|
|
21
|
+
/** Order and delivery identity supplied by the native cloud-print listener. */
|
|
21
22
|
/**
|
|
22
23
|
* Sales 解决方案状态
|
|
23
24
|
*
|
|
@@ -91,6 +91,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
91
91
|
private availabilityProjectionRefreshInFlight;
|
|
92
92
|
private availabilityRemoteOccupancyCache;
|
|
93
93
|
private availabilitySessionResourceCache;
|
|
94
|
+
private readonly fetchAvailabilitySessionResources;
|
|
94
95
|
private availabilityRemoteResourceQueryInFlight;
|
|
95
96
|
private availabilityRemoteResourceQuerySequence;
|
|
96
97
|
private availabilityRemoteResourceEpoch;
|
|
@@ -1308,6 +1308,10 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1308
1308
|
availabilityProjectionRefreshInFlight = new Map();
|
|
1309
1309
|
availabilityRemoteOccupancyCache = new _remoteOccupancyCache.AvailabilityRemoteOccupancyCache(MAX_REMOTE_OCCUPANCY_RESOURCE_DATE_CELLS);
|
|
1310
1310
|
availabilitySessionResourceCache = new _sessionResourceCache.AvailabilitySessionResourceCache();
|
|
1311
|
+
fetchAvailabilitySessionResources = query => this.fetchAvailabilityResourcesV2({
|
|
1312
|
+
...query,
|
|
1313
|
+
strictResponse: true
|
|
1314
|
+
});
|
|
1311
1315
|
availabilityRemoteResourceQueryInFlight = new Map();
|
|
1312
1316
|
availabilityRemoteResourceQuerySequence = 0;
|
|
1313
1317
|
availabilityRemoteResourceEpoch = 0;
|
|
@@ -2855,8 +2859,11 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2855
2859
|
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_DATETIME_INVALID', 'Choose a valid venue catalog date and time.');
|
|
2856
2860
|
}
|
|
2857
2861
|
const menus = (0, _venueCatalogSession.activeVenueMenus)(pool.menus, this.getAvailabilityScheduleCatalog(), datetime, Boolean(input.schedule_date && !input.schedule_datetime));
|
|
2858
|
-
let products = pool.products.filter(product => menus.some(menu => (0, _venueCatalogSession.productMatchesVenueMenu)(product, menu)))
|
|
2862
|
+
let products = pool.products.filter(product => menus.some(menu => (0, _venueCatalogSession.productMatchesVenueMenu)(product, menu)));
|
|
2859
2863
|
if (input.product_ids?.length) products = products.filter(product => input.product_ids.some(id => Number(id) === Number(product.id)));
|
|
2864
|
+
// Detail/quote reads must not deep-clone every other member of the pool.
|
|
2865
|
+
// Hydration owns a fresh copy of each selected product, including variants.
|
|
2866
|
+
products = products.map(product => this.getVenueCatalogHydratedProduct(product));
|
|
2860
2867
|
const user = this.core.getPlugin?.('user');
|
|
2861
2868
|
const queryPayload = {
|
|
2862
2869
|
schedule_date: datetime.slice(0, 10),
|
|
@@ -2870,7 +2877,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2870
2877
|
const result = (0, _clientDataVariants.tryResolveClientDataVariants)({
|
|
2871
2878
|
core: this.core,
|
|
2872
2879
|
otherParams: this.otherParams,
|
|
2873
|
-
products
|
|
2880
|
+
products,
|
|
2874
2881
|
queryPayload,
|
|
2875
2882
|
handledByOsServer: false,
|
|
2876
2883
|
scheduleList: this.getAvailabilityScheduleCatalog(),
|
|
@@ -3848,10 +3855,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
3848
3855
|
scopeKey: `${scope}:${this.buildAvailabilityRemoteResourceScopeKey(timezone)}`,
|
|
3849
3856
|
timezoneName: timezone,
|
|
3850
3857
|
...resourceQuery,
|
|
3851
|
-
fetch:
|
|
3852
|
-
...query,
|
|
3853
|
-
strictResponse: true
|
|
3854
|
-
})
|
|
3858
|
+
fetch: this.fetchAvailabilitySessionResources
|
|
3855
3859
|
}) : await this.fetchAvailabilityResourcesV2({
|
|
3856
3860
|
...resourceQuery,
|
|
3857
3861
|
strictResponse: true
|
|
@@ -3978,10 +3982,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
3978
3982
|
timezoneName: params.timezone,
|
|
3979
3983
|
resourceIds,
|
|
3980
3984
|
dateRange: params.dateRange,
|
|
3981
|
-
fetch:
|
|
3982
|
-
...query,
|
|
3983
|
-
strictResponse: true
|
|
3984
|
-
})
|
|
3985
|
+
fetch: this.fetchAvailabilitySessionResources
|
|
3985
3986
|
});
|
|
3986
3987
|
return buildAvailabilityResourcesFromV2({
|
|
3987
3988
|
rawResources,
|
|
@@ -21,7 +21,11 @@ export declare class AvailabilitySessionResourceCache {
|
|
|
21
21
|
private readonly cells;
|
|
22
22
|
private readonly pending;
|
|
23
23
|
private generation;
|
|
24
|
+
private queuedBatches;
|
|
25
|
+
private batchFlushScheduled;
|
|
24
26
|
clear(): void;
|
|
27
|
+
private enqueueFetch;
|
|
28
|
+
private flushFetchBatches;
|
|
25
29
|
load(params: AvailabilitySessionResourceLoadParams): Promise<RawResource[]>;
|
|
26
30
|
}
|
|
27
31
|
export {};
|
|
@@ -6,6 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.AvailabilitySessionResourceCache = void 0;
|
|
7
7
|
var _lodashEs = require("lodash-es");
|
|
8
8
|
var _localClock = require("../../modules/ResourcePlanner/localClock");
|
|
9
|
+
function sessionChangedError() {
|
|
10
|
+
return Object.assign(new Error('Resource session changed while loading. Please prepare again.'), {
|
|
11
|
+
code: 'AVAILABILITY_CONTEXT_NOT_FOUND'
|
|
12
|
+
});
|
|
13
|
+
}
|
|
9
14
|
function datesInRange(range) {
|
|
10
15
|
const count = (0, _localClock.dateOrdinalFromLocalDate)(range.endDate) - (0, _localClock.dateOrdinalFromLocalDate)(range.startDate) + 1;
|
|
11
16
|
// A legal 90-business-day projection may include its preceding opening and overnight tail.
|
|
@@ -67,18 +72,78 @@ class AvailabilitySessionResourceCache {
|
|
|
67
72
|
cells = new Map();
|
|
68
73
|
pending = new Map();
|
|
69
74
|
generation = 0;
|
|
75
|
+
queuedBatches = [];
|
|
76
|
+
batchFlushScheduled = false;
|
|
70
77
|
clear() {
|
|
71
78
|
this.generation += 1;
|
|
72
79
|
this.cells.clear();
|
|
73
80
|
this.pending.clear();
|
|
81
|
+
// A queued request has not reached the transport yet. Settle its waiters
|
|
82
|
+
// now, rather than leaving them pending or dispatching it in the new scope.
|
|
83
|
+
const queued = this.queuedBatches;
|
|
84
|
+
this.queuedBatches = [];
|
|
85
|
+
queued.forEach(batch => batch.reject(sessionChangedError()));
|
|
86
|
+
}
|
|
87
|
+
enqueueFetch(params, query, generation) {
|
|
88
|
+
let batch = this.queuedBatches.find(entry => entry.generation === generation && entry.scopeKey === params.scopeKey && entry.timezoneName === params.timezoneName && entry.fetch === params.fetch && entry.dateRange.startDate === query.dateRange.startDate && entry.dateRange.endDate === query.dateRange.endDate);
|
|
89
|
+
if (!batch) {
|
|
90
|
+
let resolve;
|
|
91
|
+
let reject;
|
|
92
|
+
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
93
|
+
resolve = resolvePromise;
|
|
94
|
+
reject = rejectPromise;
|
|
95
|
+
});
|
|
96
|
+
batch = {
|
|
97
|
+
generation,
|
|
98
|
+
scopeKey: params.scopeKey,
|
|
99
|
+
timezoneName: params.timezoneName,
|
|
100
|
+
dateRange: {
|
|
101
|
+
...query.dateRange
|
|
102
|
+
},
|
|
103
|
+
fetch: params.fetch,
|
|
104
|
+
resourceIds: new Map(),
|
|
105
|
+
promise,
|
|
106
|
+
resolve,
|
|
107
|
+
reject
|
|
108
|
+
};
|
|
109
|
+
this.queuedBatches.push(batch);
|
|
110
|
+
}
|
|
111
|
+
query.resourceIds.forEach(id => batch.resourceIds.set(String(id), id));
|
|
112
|
+
if (!this.batchFlushScheduled) {
|
|
113
|
+
this.batchFlushScheduled = true;
|
|
114
|
+
// Fetching was already asynchronous. Collect requests from this turn only;
|
|
115
|
+
// do not add a timer or broaden their physical date coverage.
|
|
116
|
+
void Promise.resolve().then(() => this.flushFetchBatches());
|
|
117
|
+
}
|
|
118
|
+
return batch.promise;
|
|
119
|
+
}
|
|
120
|
+
flushFetchBatches() {
|
|
121
|
+
this.batchFlushScheduled = false;
|
|
122
|
+
const queued = this.queuedBatches;
|
|
123
|
+
this.queuedBatches = [];
|
|
124
|
+
queued.forEach(batch => {
|
|
125
|
+
if (batch.generation !== this.generation) {
|
|
126
|
+
batch.reject(sessionChangedError());
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const query = {
|
|
130
|
+
resourceIds: Array.from(batch.resourceIds.values()).sort((left, right) => String(left).localeCompare(String(right))),
|
|
131
|
+
dateRange: {
|
|
132
|
+
...batch.dateRange
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
Promise.resolve(batch.fetch((0, _lodashEs.cloneDeep)(query))).then(batch.resolve, batch.reject);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
batch.reject(error);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
74
141
|
}
|
|
75
142
|
async load(params) {
|
|
76
143
|
const generation = this.generation;
|
|
77
144
|
const assertCurrent = () => {
|
|
78
145
|
if (generation !== this.generation) {
|
|
79
|
-
throw
|
|
80
|
-
code: 'AVAILABILITY_CONTEXT_NOT_FOUND'
|
|
81
|
-
});
|
|
146
|
+
throw sessionChangedError();
|
|
82
147
|
}
|
|
83
148
|
};
|
|
84
149
|
const resources = Array.from(new Map(params.resourceIds.filter(id => id !== undefined && id !== null && id !== '').map(id => [String(id), id])).values());
|
|
@@ -121,7 +186,7 @@ class AvailabilitySessionResourceCache {
|
|
|
121
186
|
const cellKeys = query.resourceIds.flatMap(id => queryDates.map(date => key(id, date)));
|
|
122
187
|
const promise = Promise.resolve().then(async () => {
|
|
123
188
|
assertCurrent();
|
|
124
|
-
const response = await
|
|
189
|
+
const response = await this.enqueueFetch(params, query, generation);
|
|
125
190
|
assertCurrent();
|
|
126
191
|
if (!Array.isArray(response)) throw new Error('Booking resources returned an invalid response.');
|
|
127
192
|
const byId = new Map();
|