cal.pub0.org/packages/prisma/zod-utils.ts

28 lines
927 B
TypeScript
Raw Normal View History

import { Frequency as RRuleFrequency } from "rrule";
import { z } from "zod";
import { LocationType } from "@calcom/core/location";
import { slugify } from "@calcom/lib/slugify";
export const eventTypeLocations = z.array(
2022-03-13 15:56:56 +00:00
z.object({
type: z.nativeEnum(LocationType),
address: z.string().optional(),
link: z.string().url().optional(),
})
);
// Matching RRule.Options: rrule/dist/esm/src/types.d.ts
export const recurringEvent = z.object({
dtstart: z.date().optional(),
interval: z.number().optional(),
count: z.number().optional(),
freq: z.nativeEnum(RRuleFrequency).optional(),
until: z.date().optional(),
tzid: z.string().optional(),
});
export const eventTypeSlug = z.string().transform((val) => slugify(val.trim()));
export const stringToDate = z.string().transform((a) => new Date(a));
export const stringOrNumber = z.union([z.string().transform((v) => parseInt(v, 10)), z.number().int()]);