refactor: move eventTypeSlug and eventTypeLocations to @calcom/lib/zod (#26115)
* refactor: move eventTypeSlug and eventTypeLocations to @calcom/lib/zod Move shared Zod schemas from @calcom/prisma/zod-utils to @calcom/lib/zod to avoid prisma imports in non-repository code. Changes: - Create packages/lib/zod/eventType.ts with eventTypeSlug, eventTypeLocations, and EventTypeLocation type - Re-export from @calcom/prisma/zod-utils for backwards compatibility - Update packages/features/eventtypes/lib/schemas.ts to import from @calcom/lib/zod - Remove unused slugify function from zod-utils.ts This allows files like schemas.ts to avoid importing from @calcom/prisma, which helps maintain the architectural boundary that prisma should only be imported in repository code. Co-Authored-By: [email protected] <[email protected]> * refactor: remove barrel file and use explicit imports Address PR feedback: - Delete packages/lib/zod/index.ts barrel file - Update imports to use explicit path @calcom/lib/zod/eventType - Simplify EventTypeLocation type to use z.infer Co-Authored-By: [email protected] <[email protected]> * refactor: use explicit type definition with z.ZodType for eventTypeLocations 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
319d9858d4
commit
bc6ff386a4
3 files changed
+55
-62
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import slugify from "../slugify";
|
||||
|
||||
/**
|
||||
* Type definition for event type location
|
||||
* Moved from @calcom/prisma/zod-utils to avoid prisma imports in non-repository code
|
||||
*/
|
||||
export type EventTypeLocation = {
|
||||
type: string;
|
||||
address?: string;
|
||||
link?: string;
|
||||
displayLocationPublicly?: boolean;
|
||||
hostPhoneNumber?: string;
|
||||
credentialId?: number;
|
||||
teamName?: string;
|
||||
customLabel?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Schema for event type locations
|
||||
* Validates an array of location objects for event types
|
||||
*/
|
||||
export const eventTypeLocations: z.ZodType<EventTypeLocation[]> = z.array(
|
||||
z.object({
|
||||
// TODO: Couldn't find a way to make it a union of types from App Store locations
|
||||
// Creating a dynamic union by iterating over the object doesn't seem to make TS happy
|
||||
type: z.string(),
|
||||
address: z.string().optional(),
|
||||
link: z.string().url().optional(),
|
||||
displayLocationPublicly: z.boolean().optional(),
|
||||
hostPhoneNumber: z.string().optional(),
|
||||
credentialId: z.number().optional(),
|
||||
teamName: z.string().optional(),
|
||||
customLabel: z.string().optional(),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Schema for event type slug
|
||||
* Transforms and validates slugs for event types
|
||||
*/
|
||||
export const eventTypeSlug = z
|
||||
.string()
|
||||
.trim()
|
||||
.transform((val) => slugify(val))
|
||||
.refine((val) => val.length >= 1, {
|
||||
message: "Please enter at least one character",
|
||||
});
|
||||
Reference in new issue
Block a user