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.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import type { MonitorPeriodicity } from "@openstatus/db/src/schema";import { endOfDay, startOfDay, startOfHour, subDays } from "date-fns";
export const periods = ["1d", "7d", "14d"] as const; // If neeeded (e.g. Pro plans), "7d", "30d"export const quantiles = ["p99", "p95", "p90", "p75", "p50"] as const;export const intervals = ["1m", "10m", "30m", "1h"] as const;export const triggers = ["cron", "api"] as const;
export type Period = (typeof periods)[number];export type Quantile = (typeof quantiles)[number];export type Interval = (typeof intervals)[number];export type Trigger = (typeof triggers)[number];
export function getDateByPeriod(period: Period) { switch (period) { case "1d": return { from: subDays(startOfHour(new Date()), 1), to: endOfDay(new Date()), }; case "7d": return { from: subDays(startOfDay(new Date()), 7), to: endOfDay(new Date()), }; case "14d": return { from: subDays(startOfDay(new Date()), 14), to: endOfDay(new Date()), }; default: { const _exhaustiveCheck: never = period; throw new Error(`Unhandled period: ${_exhaustiveCheck}`); } }}
export function getHoursByPeriod(period: Period) { switch (period) { case "1d": return 24; case "7d": return 168; case "14d": return 336; default: { const _exhaustiveCheck: never = period; throw new Error(`Unhandled period: ${_exhaustiveCheck}`); } }}
export function periodFormatter(period: Period) { switch (period) { case "1d": return "Last day"; case "7d": return "Last 7 days"; case "14d": return "Last 14 days"; default: { const _exhaustiveCheck: never = period; return _exhaustiveCheck; } }}
export function getMinutesByInterval(interval: MonitorPeriodicity) { switch (interval) { case "30s": // return 0.5; return 1; // FIX TINYBIRD case "1m": return 1; case "5m": return 5; case "10m": return 10; case "30m": return 30; case "1h": return 60; case "other": return 60; // TODO: remove "other" from here default: { const _exhaustiveCheck: never = interval; throw new Error(`Unhandled interval: ${_exhaustiveCheck}`); } }}