cellos-server 0.5.0

HTTP control plane for CellOS — admission, projection over JetStream, WebSocket fan-out of CloudEvents. Pure event-sourced architecture.
Documentation
//! `/v1/cells` — read-only projection over JetStream cell events.
//!
//! For the MVP this serves out of the in-memory `cells` map populated by
//! a future event-replay task on startup; until that lands, the endpoint
//! returns an empty list (and 404 for individual lookups) rather than
//! lying about state.

use axum::extract::{Path, State};
use axum::http::HeaderMap;
use axum::Json;

use crate::auth::require_bearer;
use crate::error::AppError;
use crate::state::{AppState, CellRecord};

pub async fn list_cells(
    State(state): State<AppState>,
    headers: HeaderMap,
) -> Result<Json<Vec<CellRecord>>, AppError> {
    require_bearer(&headers, &state.api_token)?;
    let map = state.cells.read().await;
    Ok(Json(map.values().cloned().collect()))
}

pub async fn get_cell(
    State(state): State<AppState>,
    headers: HeaderMap,
    Path(id): Path<String>,
) -> Result<Json<CellRecord>, AppError> {
    require_bearer(&headers, &state.api_token)?;
    let map = state.cells.read().await;
    map.get(&id)
        .cloned()
        .map(Json)
        .ok_or_else(|| AppError::not_found(format!("cell {id} not found")))
}