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.
2.8 kB ยท 91 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import { z } from "zod";
import { incidentCreatedSchema, incidentResolvedSchema, monitorDegradedSchema, monitorFailedSchema, monitorRecoveredSchema, notificationSentSchema,} from "./action-schema";import { ingestBaseEventSchema, pipeBaseResponseData } from "./base-validation";
/** * The schema for the event object. * It extends the base schema. It uses the `discriminatedUnion` method for faster * evaluation to determine which schema to be used to parse the input. * It also transforms the metadata object into a string. * * @todo: whenever a new action is added, it should be included to the discriminatedUnion */export const ingestActionEventSchema = z .intersection( // Unfortunately, the array cannot be dynamic, otherwise could be added to the Client // and made available to devs as library z.discriminatedUnion("action", [ monitorRecoveredSchema, monitorDegradedSchema, monitorFailedSchema, notificationSentSchema, incidentCreatedSchema, incidentResolvedSchema, ]), ingestBaseEventSchema, ) .transform((val) => ({ ...val, metadata: JSON.stringify(val.metadata), }));
/** * The schema for the response object. * It extends the base schema. It uses the `discriminatedUnion` method for faster * evaluation to determine which schema to be used to parse the input. * It also preprocesses the metadata string into the correct schema object. * * @todo: whenever a new action is added, it should be included to the discriminatedUnion */export const pipeActionResponseData = z.intersection( z.discriminatedUnion("action", [ monitorRecoveredSchema.extend({ metadata: z.preprocess( (val) => JSON.parse(String(val)), monitorRecoveredSchema.shape.metadata, ), }), monitorDegradedSchema.extend({ metadata: z.preprocess( (val) => JSON.parse(String(val)), monitorDegradedSchema.shape.metadata, ), }), monitorFailedSchema.extend({ metadata: z.preprocess( (val) => JSON.parse(String(val)), monitorFailedSchema.shape.metadata, ), }), notificationSentSchema.extend({ metadata: z.preprocess( (val) => JSON.parse(String(val)), notificationSentSchema.shape.metadata, ), }), incidentCreatedSchema.extend({ metadata: z.preprocess( (val) => JSON.parse(String(val)), incidentCreatedSchema.shape.metadata, ), }), incidentResolvedSchema.extend({ metadata: z.preprocess( (val) => JSON.parse(String(val)), incidentResolvedSchema.shape.metadata, ), }), ]), pipeBaseResponseData,);
export type IngestActionEvent = z.infer<typeof ingestActionEventSchema>;export type PipeActionResponseData = z.infer<typeof pipeActionResponseData>;