perf: optimize video adapter imports to avoid loading entire app store (#23435)
* perf: optimize video adapter imports to avoid loading entire app store - Creates VideoApiAdapterMap with lazy imports for 12 video services - Updates getVideoAdapters function to use VideoApiAdapterMap instead of dynamic app store imports - Preserves zoom app name parsing logic (zoom_video → zoomvideo) - Follows same optimization pattern as calendar, analytics, and payment services - Reduces bundle size by avoiding import of 100+ apps when only video functionality needed Affected files: - packages/app-store-cli/src/build.ts: Added video service generation logic - packages/lib/videoClient.ts: Updated to use VideoApiAdapterMap - packages/features/bookings/lib/handleCancelBooking.ts: Updated FAKE_DAILY_CREDENTIAL import - packages/lib/EventManager.ts: Updated FAKE_DAILY_CREDENTIAL import - packages/trpc/server/routers/viewer/calVideo/getMeetingInformation.handler.ts: Updated to use VideoApiAdapterMap - apps/web/lib/video/[uid]/getServerSideProps.ts: Updated daily video function imports - packages/app-store/video.services.generated.ts: Generated video adapter map with re-exports Co-Authored-By: [email protected] <[email protected]> * fix: add missing re-exports to video.services.generated.ts - Updates build.ts to include FAKE_DAILY_CREDENTIAL and other daily video function re-exports - Fixes type errors in EventManager.ts and other files importing from video.services.generated - Ensures video adapter refactoring maintains all existing functionality Co-Authored-By: [email protected] <[email protected]> * fix: update video adapter test mocks to work with VideoApiAdapterMap - Creates global mockVideoAdapterRegistry for dynamic video adapter mocks - Uses Proxy in vi.mock for VideoApiAdapterMap to return registered mocks - Updates mockVideoApp and mockErrorOnVideoMeetingCreation to register mocks - Fixes unit test failures in booking scenario tests - Ensures video meeting operations (createMeeting, updateMeeting, deleteMeeting) work correctly Co-Authored-By: [email protected] <[email protected]> * fix: remove re-exports from video.services.generated.ts and revert imports - Remove re-export block from video.services.generated.ts as requested - Revert imports back to pull directly from dailyvideo/lib/VideoApiAdapter - Update build.ts to not generate the re-exports - Maintains all existing functionality while addressing GitHub feedback Co-Authored-By: [email protected] <[email protected]> * fix: rename video.services.generated.ts to video.adapters.generated.ts - Updates build.ts to generate video.adapters.generated.ts instead of video.services.generated.ts - Updates all import statements to use new filename - Removes unnecessary mock exports from bookingScenario.ts (FAKE_DAILY_CREDENTIAL, etc.) - Addresses GitHub comments from @keithwillcode on PR #23435 The terminology change from 'services map' to 'adapters map' better reflects the actual content (video adapters, not services) and maintains consistency with the established refactoring pattern. Co-Authored-By: [email protected] <[email protected]> * refactor: rename videoServices to videoAdapters and simplify return statement - Rename variable from videoServices to videoAdapters for consistency - Remove unnecessary const variable and return directly in same line - Addresses GitHub comments from @keithwillcode on PR #23435 Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
bfacd8a780
commit
191db5104a
5 files changed
+159
-65
No files matched your search
@@ -51,6 +51,22 @@ vi.mock("@calcom/app-store/calendar.services.generated", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const mockVideoAdapterRegistry: Record<string, any> = {};
|
||||
|
||||
vi.mock("@calcom/app-store/video.adapters.generated", () => ({
|
||||
VideoApiAdapterMap: new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, prop) {
|
||||
if (typeof prop === "string" && mockVideoAdapterRegistry[prop]) {
|
||||
return mockVideoAdapterRegistry[prop];
|
||||
}
|
||||
return Promise.resolve({ default: vi.fn() });
|
||||
},
|
||||
}
|
||||
),
|
||||
}));
|
||||
|
||||
// We don't need to test it. Also, it causes Formbricks error when imported
|
||||
vi.mock("@calcom/lib/raqb/findTeamMembersMatchingAttributeLogic", () => ({
|
||||
default: {},
|
||||
@@ -1995,6 +2011,61 @@ export function mockVideoApp({
|
||||
const updateMeetingCalls: any[] = [];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const deleteMeetingCalls: any[] = [];
|
||||
|
||||
const mockVideoAdapter = (credential: any) => {
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
createMeeting: (...rest: any[]) => {
|
||||
if (creationCrash) {
|
||||
throw new Error("MockVideoApiAdapter.createMeeting fake error");
|
||||
}
|
||||
createMeetingCalls.push({
|
||||
credential,
|
||||
args: rest,
|
||||
});
|
||||
|
||||
return Promise.resolve({
|
||||
type: appStoreMetadata[metadataLookupKey as keyof typeof appStoreMetadata].type,
|
||||
...videoMeetingData,
|
||||
});
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
updateMeeting: async (...rest: any[]) => {
|
||||
if (updationCrash) {
|
||||
throw new Error("MockVideoApiAdapter.updateMeeting fake error");
|
||||
}
|
||||
const [bookingRef, calEvent] = rest;
|
||||
updateMeetingCalls.push({
|
||||
credential,
|
||||
args: rest,
|
||||
});
|
||||
if (!bookingRef.type) {
|
||||
throw new Error("bookingRef.type is not defined");
|
||||
}
|
||||
if (!calEvent.organizer) {
|
||||
throw new Error("calEvent.organizer is not defined");
|
||||
}
|
||||
log.silly("MockVideoApiAdapter.updateMeeting", JSON.stringify({ bookingRef, calEvent }));
|
||||
return Promise.resolve({
|
||||
type: appStoreMetadata[metadataLookupKey as keyof typeof appStoreMetadata].type,
|
||||
...videoMeetingData,
|
||||
});
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deleteMeeting: async (...rest: any[]) => {
|
||||
log.silly("MockVideoApiAdapter.deleteMeeting", JSON.stringify(rest));
|
||||
deleteMeetingCalls.push({
|
||||
credential,
|
||||
args: rest,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
mockVideoAdapterRegistry[appStoreLookupKey] = Promise.resolve({
|
||||
default: mockVideoAdapter,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
appStoreMock.default[appStoreLookupKey as keyof typeof appStoreMock.default].mockImplementation(() => {
|
||||
@@ -2003,59 +2074,12 @@ export function mockVideoApp({
|
||||
lib: {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
VideoApiAdapter: (credential) => {
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
createMeeting: (...rest: any[]) => {
|
||||
if (creationCrash) {
|
||||
throw new Error("MockVideoApiAdapter.createMeeting fake error");
|
||||
}
|
||||
createMeetingCalls.push({
|
||||
credential,
|
||||
args: rest,
|
||||
});
|
||||
|
||||
return Promise.resolve({
|
||||
type: appStoreMetadata[metadataLookupKey as keyof typeof appStoreMetadata].type,
|
||||
...videoMeetingData,
|
||||
});
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
updateMeeting: async (...rest: any[]) => {
|
||||
if (updationCrash) {
|
||||
throw new Error("MockVideoApiAdapter.updateMeeting fake error");
|
||||
}
|
||||
const [bookingRef, calEvent] = rest;
|
||||
updateMeetingCalls.push({
|
||||
credential,
|
||||
args: rest,
|
||||
});
|
||||
if (!bookingRef.type) {
|
||||
throw new Error("bookingRef.type is not defined");
|
||||
}
|
||||
if (!calEvent.organizer) {
|
||||
throw new Error("calEvent.organizer is not defined");
|
||||
}
|
||||
log.silly("MockVideoApiAdapter.updateMeeting", JSON.stringify({ bookingRef, calEvent }));
|
||||
return Promise.resolve({
|
||||
type: appStoreMetadata[metadataLookupKey as keyof typeof appStoreMetadata].type,
|
||||
...videoMeetingData,
|
||||
});
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deleteMeeting: async (...rest: any[]) => {
|
||||
log.silly("MockVideoApiAdapter.deleteMeeting", JSON.stringify(rest));
|
||||
deleteMeetingCalls.push({
|
||||
credential,
|
||||
args: rest,
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
VideoApiAdapter: mockVideoAdapter,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
createMeetingCalls,
|
||||
updateMeetingCalls,
|
||||
@@ -2121,6 +2145,17 @@ export function mockErrorOnVideoMeetingCreation({
|
||||
appStoreLookupKey?: string;
|
||||
}) {
|
||||
appStoreLookupKey = appStoreLookupKey || metadataLookupKey;
|
||||
|
||||
const mockErrorAdapter = () => ({
|
||||
createMeeting: () => {
|
||||
throw new MockError("Error creating Video meeting");
|
||||
},
|
||||
});
|
||||
|
||||
mockVideoAdapterRegistry[appStoreLookupKey] = Promise.resolve({
|
||||
default: mockErrorAdapter,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
appStoreMock.default[appStoreLookupKey].mockImplementation(() => {
|
||||
@@ -2129,11 +2164,7 @@ export function mockErrorOnVideoMeetingCreation({
|
||||
lib: {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
VideoApiAdapter: () => ({
|
||||
createMeeting: () => {
|
||||
throw new MockError("Error creating Video meeting");
|
||||
},
|
||||
}),
|
||||
VideoApiAdapter: mockErrorAdapter,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user