perf: add z.ZodType annotations to high-impact schemas (#26114)
* perf: add z.ZodType annotations to high-impact schemas Add explicit type annotations to reduce TypeScript type inference overhead and .d.ts file bloat in the tRPC package. Changes: - packages/prisma/zod-utils.ts: Add EventTypeLocation type and annotate eventTypeLocations schema - packages/features/eventtypes/lib/schemas.ts: Add TEventTypeDuplicateInput and TCreateEventTypeInput types with annotations - packages/app-store/routing-forms/zod.ts: Add FieldOption, TNonRouterField, TRouterField, TField, TFields types with annotations for zodField and zodFields These schemas feed into multiple tRPC routers and were identified as high-impact targets for reducing type checking time and declaration file sizes. Co-Authored-By: [email protected] <[email protected]> * fix: replace z.infer with explicit types and define EventTypeLocation locally Address PR feedback: - Replace z.infer<typeof calVideoSettingsSchema> with explicit CalVideoSettings type - Define EventTypeLocation type locally instead of importing from prisma - Add z.ZodType annotation to calVideoSettingsSchema Note: Still importing Zod schemas from @calcom/prisma/zod-utils for validation. Awaiting guidance on whether to move those to @calcom/lib. 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
ee6989a575
commit
851cca25aa
3 files changed
+100
-6
No files matched your search
@@ -3,7 +3,21 @@ import { z } from "zod";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { eventTypeLocations, EventTypeMetaDataSchema, eventTypeSlug } from "@calcom/prisma/zod-utils";
|
||||
|
||||
const calVideoSettingsSchema = z
|
||||
type CalVideoSettings =
|
||||
| {
|
||||
disableRecordingForGuests?: boolean | null;
|
||||
disableRecordingForOrganizer?: boolean | null;
|
||||
enableAutomaticTranscription?: boolean | null;
|
||||
enableAutomaticRecordingForOrganizer?: boolean | null;
|
||||
disableTranscriptionForGuests?: boolean | null;
|
||||
disableTranscriptionForOrganizer?: boolean | null;
|
||||
redirectUrlOnExit?: string | null;
|
||||
requireEmailForGuests?: boolean | null;
|
||||
}
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
const calVideoSettingsSchema: z.ZodType<CalVideoSettings> = z
|
||||
.object({
|
||||
disableRecordingForGuests: z.boolean().nullish(),
|
||||
disableRecordingForOrganizer: z.boolean().nullish(),
|
||||
@@ -17,7 +31,29 @@ const calVideoSettingsSchema = z
|
||||
.optional()
|
||||
.nullable();
|
||||
|
||||
export const EventTypeDuplicateInput = z
|
||||
type EventTypeLocation = {
|
||||
type: string;
|
||||
address?: string;
|
||||
link?: string;
|
||||
displayLocationPublicly?: boolean;
|
||||
hostPhoneNumber?: string;
|
||||
credentialId?: number;
|
||||
teamName?: string;
|
||||
customLabel?: string;
|
||||
};
|
||||
|
||||
type EventTypeMetadata = z.infer<typeof EventTypeMetaDataSchema>;
|
||||
|
||||
export type TEventTypeDuplicateInput = {
|
||||
id: number;
|
||||
slug: string;
|
||||
title: string;
|
||||
description: string;
|
||||
length: number;
|
||||
teamId?: number | null;
|
||||
};
|
||||
|
||||
export const EventTypeDuplicateInput: z.ZodType<TEventTypeDuplicateInput> = z
|
||||
.object({
|
||||
id: z.number(),
|
||||
slug: z.string(),
|
||||
@@ -28,7 +64,26 @@ export const EventTypeDuplicateInput = z
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const createEventTypeInput = z
|
||||
export type TCreateEventTypeInput = {
|
||||
title: string;
|
||||
slug: string;
|
||||
description?: string | null;
|
||||
length: number;
|
||||
hidden?: boolean;
|
||||
teamId?: number | null;
|
||||
schedulingType?: SchedulingType | null;
|
||||
locations?: EventTypeLocation[];
|
||||
metadata?: EventTypeMetadata;
|
||||
disableGuests?: boolean;
|
||||
slotInterval?: number | null;
|
||||
minimumBookingNotice?: number;
|
||||
beforeEventBuffer?: number;
|
||||
afterEventBuffer?: number;
|
||||
scheduleId?: number;
|
||||
calVideoSettings?: CalVideoSettings;
|
||||
};
|
||||
|
||||
export const createEventTypeInput: z.ZodType<TCreateEventTypeInput> = z
|
||||
.object({
|
||||
title: z.string().trim().min(1),
|
||||
slug: eventTypeSlug,
|
||||
|
||||
Reference in new issue
Block a user