Openstatus www.openstatus.dev
at main 28 lines 911 B view raw
1import { createInsertSchema, createSelectSchema } from "drizzle-zod"; 2import type { z } from "zod"; 3import { pageComponent } from "./page_components"; 4 5export const selectPageComponentSchema = createSelectSchema(pageComponent); 6 7export const insertPageComponentSchema = createInsertSchema(pageComponent, { 8 name: (schema) => schema.min(1), 9}).refine( 10 (data) => { 11 // monitorId must be set when type='monitor' 12 if (data.type === "monitor" && !data.monitorId) { 13 return false; 14 } 15 // monitorId must be null when type='static' 16 if (data.type === "static" && data.monitorId) { 17 return false; 18 } 19 return true; 20 }, 21 { 22 message: 23 "monitorId must be set when type is 'monitor' and must be null when type is 'static'", 24 }, 25); 26 27export type InsertPageComponent = z.infer<typeof insertPageComponentSchema>; 28export type PageComponent = z.infer<typeof selectPageComponentSchema>;