Functional Weave
Code in TypeScript

monitor.component-state

A status page component's state from its checks: operational, degraded, partial or major outage, or maintenance.

1.0.0 · published 2026-10-03 by charlie · Anterra

Pinned by 15 tests, run in TypeScript, Python and Rust.

What it does

The state a status page shows for one component (the API, the website, the database), from the latest status of each check behind it, in the vocabulary of Atlassian Statuspage, the de facto standard for public status pages:

| `ComponentState` | Statuspage label | Statuspage API value | | --- | --- | --- | | `operational` | Operational | `operational` | | `degraded` | Degraded performance | `degraded_performance` | | `partial-outage` | Partial outage | `partial_outage` | | `major-outage` | Major outage | `major_outage` | | `maintenance` | Under maintenance | `under_maintenance` |

For example

  • componentState(up, up, up, false) → operational every check up is operational
  • componentState(up, degraded, up, false) → degraded one slow check is degraded performance
  • componentState(up, down, up, false) → partial-outage some checks down is a partial outage

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

export function componentState(statuses: readonly CheckStatus[], underMaintenance: boolean): ComponentState
statusesCheckStatus[]the latest status of each check behind the component, at least one
underMaintenancebooltrue during a scheduled maintenance window; wins over every status
returnsComponentState

The type it declares, generated into your project

export type ComponentState = "operational" | "degraded" | "partial-outage" | "major-outage" | "maintenance";

Your code names it in one line, in the file that uses it

import { componentState } from "#fune/monitor.component-state@^1";
impl/typescript.ts · 23 lines · open · 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 ComponentState } from "./monitor_component_state_types.ts";

/**
 * One component's state in Atlassian Statuspage's vocabulary. Maintenance
 * wins, so planned work never pages anyone as an outage; the statuses are
 * still checked, so a bad feed fails loudly even during maintenance.
 */
export function componentState(statuses: readonly CheckStatus[], underMaintenance: boolean): ComponentState {
  if (statuses.length === 0) throw new RangeError("statuses must not be empty");
  if (typeof underMaintenance !== "boolean") throw new TypeError("underMaintenance must be true or false");
  let down = 0;
  let degraded = 0;
  for (const s of statuses) {
    if (s === "down") down += 1;
    else if (s === "degraded") degraded += 1;
    else if (s !== "up") throw new RangeError(`unknown check status: ${String(s)}`);
  }
  if (underMaintenance) return "maintenance";
  if (down === statuses.length) return "major-outage";
  if (down > 0) return "partial-outage";
  return degraded > 0 ? "degraded" : "operational";
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add monitor.component-state
Download for TypeScript monitor.component-state-1.0.0-typescript.fune · 7,041 bytes sha256 9d7e3c24592355399fbc8cbf7af4dde6f8f8394868dc119a882992d0d347f28b

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./monitor.component-state-1.0.0-typescript.fune, or fetch it from a terminal with fune pull monitor.component-state@1.0.0:typescript.

The whole function, every language, is one file too: monitor.component-state-1.0.0.fune, 9,719 bytes, sha256 cffd933922c240ddf102b7ac117550f261e261ec98c4c1781338eee2a23942d6. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

// fune: before monitor.component-state

after — your function gets the result and the arguments, and returns the final result.

// fune: after monitor.component-state

replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.

// fune: replace monitor.check-status in monitor.component-state

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show monitor.component-state --steps.

// fune: step monitor.component-state after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

CaseArgumentsExpected
every check up is operational up, up, up, false → operational
one slow check is degraded performance up, degraded, up, false → degraded
some checks down is a partial outage up, down, up, false → partial-outage
down beats degraded: one down and one degraded is still a partial outage degraded, down, up, false → partial-outage
every check down is a major outage down, down, false → major-outage
a single check down is a major outage, not a partial one down, false → major-outage
all degraded is degraded, never an outage degraded, degraded, false → degraded
maintenance wins over a major outage down, down, true → maintenance
maintenance with every check up is still maintenance up, true → maintenance
a single check up is operational up, false → operational
Show the other 5 tests
CaseArgumentsExpected
an empty list is an error , false → error: statuses must not be empty
an empty list is an error even under maintenance , true → error: statuses must not be empty
an unknown status is an error up, offline, false → error: unknown check status: offline
an unknown status is an error even under maintenance partial, true → error: unknown check status: partial
a maintenance flag that is not a boolean is an error up, 1 → error: underMaintenance must be true or false

More from the author

The values here are kebab-case like the rest of the registry's enums; map them to Statuspage's snake_case when calling its API.

## The rule, in order

1. `underMaintenance` is true: **maintenance**. Planned work is announced as such, not reported as an outage. 2. Every check down: **major-outage**. So a component with one check that is down is a major outage, not a partial one. 3. Some checks down: **partial-outage**. 4. Any check degraded: **degraded**. Degraded checks never add up to an outage. 5. Otherwise **operational**.

The statuses are validated even under maintenance, so a broken feed fails loudly instead of hiding behind a maintenance window. To decide whether a maintenance window is active, see `monitor.maintenance-window`; to combine one target's probe locations into a single status first, `monitor.check-status`.

## Errors

- `statuses must not be empty`: a component with no checks has no state. - `unknown check status: X` - `underMaintenance must be true or false`

## Sources

- Atlassian Support, "Show service status with components": https://support.atlassian.com/statuspage/docs/show-service-status-with-components/ (the five component statuses: Operational, Degraded performance, Partial outage, Major outage, Under maintenance). - Statuspage Status API (component `status` values `operational`, `degraded_performance`, `partial_outage`, `major_outage`): https://metastatuspage.com/api

Files

PathBytes
README.md2,055
impl/python.py1,122
impl/rust.rs1,410
impl/typescript.ts1,094
vectors.json1,849