Functional Weave
Code in Rust

monitor.heartbeat-check@1.0.0

impl/typescript.ts

820 bytes · the TypeScript implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { type CheckStatus } from "./monitor_check_status.ts";  ← from monitor.check-status ^1.0.0 · built alongside by fune
import { type HeartbeatState } from "./monitor_heartbeat.ts";  ← from monitor.heartbeat ^1.0.0 · built alongside by fune

const STATUS: Readonly<Record<string, CheckStatus>> = { up: "up", late: "degraded", down: "down" };

/**
 * A heartbeat as one check behind a status page component. Late is
 * degraded, not down: the job may still ping within its grace time, which is
 * what the grace time is for. A new heartbeat has proved nothing either way,
 * so it is null rather than a guess.
 */
export function heartbeatCheck(state: HeartbeatState): CheckStatus | null {
  if (state === "new") return null;
  const status = Object.prototype.hasOwnProperty.call(STATUS, state) ? STATUS[state] : undefined;
  if (status === undefined) throw new RangeError(`unknown heartbeat state: ${String(state)}`);
  return status;
}