Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
7.9 kB ยท 236 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237import { z } from "zod";
import { selectIncidentSchema } from "./incidents/validation";import { selectMaintenanceSchema } from "./maintenances";import { selectMonitorGroupSchema } from "./monitor_groups";import { selectMonitorSchema } from "./monitors";import { selectPageComponentGroupSchema } from "./page_component_groups";import { selectPageComponentSchema, selectStatusReportUpdateToPageComponentSchema,} from "./page_components";import { selectPageSchema } from "./pages";import { selectStatusReportSchema, selectStatusReportUpdateSchema,} from "./status_reports";import { workspacePlanSchema } from "./workspaces";
// TODO: create a 'public-status' schema with all the different types and validations
// Base schema without transform so it can be extendedconst selectPublicMonitorBaseSchema = selectMonitorSchema.omit({ body: true, headers: true, method: true, otelEndpoint: true, otelHeaders: true,});
export const selectPublicMonitorSchema = selectPublicMonitorBaseSchema.transform((data) => ({ ...data, name: data.externalName || data.name, }));
export const selectStatusReportPageSchema = selectStatusReportSchema.extend({ statusReportUpdates: z .array( selectStatusReportUpdateSchema.extend({ statusReportUpdateToPageComponents: z .array(selectStatusReportUpdateToPageComponentSchema) .prefault([]), }), ) .prefault([]), statusReportsToPageComponents: z .array( z.object({ pageComponentId: z.number(), statusReportId: z.number(), pageComponent: selectPageComponentSchema, }), ) .prefault([]),});
export const selectMaintenancePageSchema = selectMaintenanceSchema.extend({ maintenancesToPageComponents: z .array( z.object({ pageComponentId: z.number(), maintenanceId: z.number(), pageComponent: selectPageComponentSchema, }), ) .prefault([]),});
export const selectPageSchemaWithRelation = selectPageSchema.extend({ monitors: z.array(selectMonitorSchema), statusReports: z.array(selectStatusReportPageSchema),});
export const legacy_selectPublicPageSchemaWithRelation = selectPageSchema .extend({ monitors: z.array(selectPublicMonitorSchema).prefault([]), statusReports: z.array(selectStatusReportPageSchema).prefault([]), incidents: z.array(selectIncidentSchema).prefault([]), maintenances: z.array(selectMaintenancePageSchema).prefault([]), workspacePlan: workspacePlanSchema .nullable() .prefault("free") .transform((val) => val ?? "free"), }) .omit({ // workspaceId: true, id: true, });
const selectPublicMonitorWithStatusSchema = selectPublicMonitorBaseSchema .extend({ status: z .enum(["success", "degraded", "error", "info"]) .prefault("success"), monitorGroupId: z.number().nullable().optional(), order: z.number().default(0).optional(), groupOrder: z.number().default(0).nullish(), privateLocationCount: z.number().optional(), }) .transform((data) => ({ ...data, name: data.externalName || data.name, }));
export const statusPageEventSchema = z.object({ id: z.number(), name: z.string(), from: z.date(), to: z.date().nullable(), status: z.enum(["success", "degraded", "error", "info"]).prefault("success"), type: z.enum(["maintenance", "incident", "report"]),});
// Page component with status - used for new tracker systemconst selectPublicPageComponentWithStatusSchema = selectPageComponentSchema.extend({ status: z .enum(["success", "degraded", "error", "info"]) .prefault("success"), events: z.array(statusPageEventSchema).prefault([]), // For monitor-type components - omit status since it's now at component level monitor: selectPublicMonitorBaseSchema .extend({ incidents: selectIncidentSchema.array().nullish(), }) .nullish(), });
const trackersSchema = z .array( z.discriminatedUnion("type", [ z.object({ type: z.literal("component"), component: selectPublicPageComponentWithStatusSchema, order: z.number(), }), z.object({ type: z.literal("group"), groupId: z.number(), groupName: z.string(), defaultOpen: z.boolean().default(false), components: z.array(selectPublicPageComponentWithStatusSchema), status: z .enum(["success", "degraded", "error", "info"]) .prefault("success"), order: z.number(), }), ]), ) .prefault([]);
export const selectPageComponentWithMonitorRelation = selectPageComponentSchema .extend({ monitor: selectPublicMonitorBaseSchema .extend({ incidents: selectIncidentSchema.array().nullish(), }) .nullish(), group: selectPageComponentGroupSchema.nullish(), }) // the component owns the public-facing monitor name/description; externalName // is cleared so downstream `externalName || name` transforms keep the override. // description: NULL means never backfilled โ fall back to the monitor's own; // "" is a deliberately cleared field (the dashboard stores "") โ stays blank. .transform(({ monitor, ...component }) => ({ ...component, monitor: monitor ? { ...monitor, name: component.name, description: component.description ?? monitor.description, externalName: null, } : monitor, }));
export type PageComponentWithMonitorRelation = z.infer< typeof selectPageComponentWithMonitorRelation>;
export const selectPublicPageLightSchemaWithRelation = selectPageSchema .extend({ monitors: z.array(selectPublicMonitorSchema).prefault([]), statusReports: z.array(selectStatusReportPageSchema).prefault([]), incidents: z.array(selectIncidentSchema).prefault([]), maintenances: z.array(selectMaintenancePageSchema).prefault([]), workspacePlan: workspacePlanSchema .nullable() .prefault("free") .transform((val) => val ?? "free"), // NEW: Include pageComponents for modern consumers pageComponents: selectPageComponentWithMonitorRelation.array().prefault([]), pageComponentGroups: selectPageComponentGroupSchema.array().prefault([]), whiteLabel: z.boolean().prefault(false), }) // `password` is access-control state, never client-facing โ gates read it // server-side from the DB. See status-page markdown/feed routes. .omit({ id: true, password: true, });
export const selectPublicPageSchemaWithRelation = selectPageSchema .extend({ monitorGroups: selectMonitorGroupSchema.array().prefault([]), // TODO: include status of the monitor monitors: selectPublicMonitorWithStatusSchema.array(), pageComponents: selectPageComponentWithMonitorRelation.array().prefault([]), pageComponentGroups: selectPageComponentGroupSchema.array().prefault([]), trackers: trackersSchema, lastEvents: z.array(statusPageEventSchema), openEvents: z.array(statusPageEventSchema), statusReports: z.array(selectStatusReportPageSchema), incidents: z.array(selectIncidentSchema), maintenances: z.array(selectMaintenancePageSchema), status: z .enum(["success", "degraded", "error", "info"]) .prefault("success"), workspacePlan: workspacePlanSchema .nullable() .prefault("free") .transform((val) => val ?? "free"), whiteLabel: z.boolean().prefault(false), }) .omit({ password: true });
export type StatusReportWithUpdates = z.infer< typeof selectStatusReportPageSchema>;export type PublicMonitor = z.infer<typeof selectPublicMonitorSchema>;export type PublicPage = z.infer< typeof legacy_selectPublicPageSchemaWithRelation>;export type PublicPageComponentWithStatus = z.infer< typeof selectPublicPageComponentWithStatusSchema>;