euv-cli 0.48.0

Cross-platform CLI tool for the euv native UI framework supporting run, build, check, fmt, doctor, new, and Hyperlane SSE dynamic updates across all supported platforms.
Documentation
use super::*;

/// Configuration for the read-only Hyperlane HTTP + SSE update server (never holds signing keys).
#[derive(Clone, Data, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct UpdateServerConfig {
    /// Local filesystem store root containing `staging/`, `blobs/`, `releases/`, `channels/`, and `state/`.
    pub(crate) store_root: PathBuf,
    /// Bind host address (default `127.0.0.1`).
    pub(crate) host: String,
    /// Bind TCP port (`0` selects an ephemeral port).
    #[get(type(copy))]
    pub(crate) port: u16,
    /// SSE keep-alive heartbeat interval in milliseconds.
    #[get(type(copy))]
    pub(crate) heartbeat_ms: u64,
    /// SSE client reconnect retry hint in milliseconds.
    #[get(type(copy))]
    pub(crate) retry_ms: u64,
    /// Bounded per-topic SSE `Last-Event-ID` replay buffer size.
    #[get(type(copy))]
    pub(crate) replay_capacity: usize,
    /// Filesystem pointer watcher polling interval in milliseconds.
    #[get(type(copy))]
    pub(crate) watch_poll_ms: u64,
    /// Maximum allowed artifact byte size enforced during staging and publishing.
    #[get(type(copy))]
    pub(crate) max_artifact_bytes: u64,
    /// When `true`, initializes the store, validates bind readiness, and exits immediately.
    #[get(type(copy))]
    pub(crate) once: bool,
}

/// Atomically swapped active release pointer persisted in `channels/<project>/<channel>/active.json`.
#[derive(Clone, Data, Debug, Default, Deserialize, Eq, New, PartialEq, Serialize)]
pub struct ChannelPointer {
    /// Logical project identifier.
    pub(crate) project: String,
    /// Release channel name.
    pub(crate) channel: String,
    /// Compatibility track label.
    pub(crate) track: String,
    /// Strictly monotonic active release sequence number.
    #[get(type(copy))]
    pub(crate) active_release_seq: u64,
    /// SHA-256 hex digest of the active signed `ReleaseManifest`.
    pub(crate) manifest_sha256: String,
    /// UNIX epoch timestamp in seconds of the atomic pointer swap.
    #[get(type(copy))]
    pub(crate) updated_at_unix: u64,
}

/// Persisted bounded event record written to `state/events/<project>/<channel>.jsonl`.
#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
pub struct StoredReleaseEvent {
    /// Monotonic event identifier matching `event.to_release`.
    #[get(type(copy))]
    pub(crate) event_id: u64,
    /// Minimal `release.activated` metadata frame.
    pub(crate) event: ReleaseActivatedEvent,
}

/// Local filesystem update store managing `staging/`, `blobs/sha256/`, `releases/`, `channels/`, and `state/`.
#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
pub struct UpdateStore {
    /// Root filesystem directory of the update store.
    pub(crate) root: PathBuf,
    /// Maximum allowed byte size for any single artifact (`0` disables cap).
    #[new(skip)]
    #[get(type(copy))]
    pub(crate) max_artifact_bytes: u64,
}

/// RAII writer lock guard owning `state/writer.lock` across multi-process CLI publish/rollback operations.
#[derive(Debug)]
pub(crate) struct UpdateWriterLockGuard {
    /// Lockfile path removed automatically on drop.
    pub(crate) lock_path: PathBuf,
}

/// Summary report emitted by `euv update stage`.
#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
pub struct StageReport {
    /// Stage identifier inside `staging/`.
    pub(crate) stage_id: String,
    /// Logical project identifier.
    pub(crate) project: String,
    /// Target release channel.
    pub(crate) channel: String,
    /// Number of verified blobs staged.
    #[get(type(copy))]
    pub(crate) blob_count: usize,
    /// Total verified staged bytes.
    #[get(type(copy))]
    pub(crate) total_bytes: u64,
}

/// Summary report emitted by `euv update publish` and `euv update rollback`.
#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
pub struct PublishReport {
    /// Logical project identifier.
    pub(crate) project: String,
    /// Release channel name.
    pub(crate) channel: String,
    /// Compatibility track name.
    pub(crate) track: String,
    /// Previous active release sequence (`0` if initial release).
    #[get(type(copy))]
    pub(crate) from_release: u64,
    /// Newly activated strictly monotonic release sequence.
    #[get(type(copy))]
    pub(crate) to_release: u64,
    /// Optional historical release sequence targeted when this publish is a rollback.
    #[new(skip)]
    #[get(skip)]
    pub(crate) rollback_of: Option<u64>,
    /// SHA-256 hex digest of the sealed signed manifest.
    pub(crate) manifest_sha256: String,
    /// Routes whose pinned dependency graphs changed.
    #[new(skip)]
    pub(crate) affected_routes: Vec<String>,
    /// Number of new blobs written into `blobs/sha256/`.
    #[new(skip)]
    #[get(type(copy))]
    pub(crate) blobs_written: usize,
}

/// Status summary for a single project/channel inside `UpdateStoreStatus`.
#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
pub struct ChannelStatusEntry {
    /// Logical project identifier.
    pub(crate) project: String,
    /// Channel name.
    pub(crate) channel: String,
    /// Current active channel pointer.
    pub(crate) pointer: ChannelPointer,
    /// Number of immutable release manifests stored under this channel.
    #[get(type(copy))]
    pub(crate) release_count: usize,
    /// Number of retained event log records under `state/events/`.
    #[get(type(copy))]
    pub(crate) event_count: usize,
}

/// Complete status snapshot emitted by `euv update status`.
#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
pub struct UpdateStoreStatus {
    /// Store root path string.
    pub(crate) store_root: String,
    /// Total immutable blobs currently stored in `blobs/sha256/`.
    #[get(type(copy))]
    pub(crate) blob_count: usize,
    /// Total disk bytes occupied by immutable blobs.
    #[get(type(copy))]
    pub(crate) blob_total_bytes: u64,
    /// Active channel summaries.
    pub(crate) channels: Vec<ChannelStatusEntry>,
}

/// Machine-readable report emitted by `euv update serve`.
#[derive(Clone, Data, Debug, Deserialize, Eq, New, PartialEq, Serialize)]
pub struct UpdateServerReport {
    /// Store root directory served.
    pub(crate) store_root: String,
    /// Bound HTTP base URL (e.g. `http://127.0.0.1:8787`).
    pub(crate) url: String,
    /// Manifest endpoint route template.
    pub(crate) manifest_route: String,
    /// Blob endpoint route template.
    pub(crate) blob_route: String,
    /// SSE events endpoint route template.
    pub(crate) events_route: String,
    /// Whether the server exited immediately after readiness validation (`--once`).
    #[get(type(copy))]
    pub(crate) once: bool,
}

/// Shared state mounted into Hyperlane routes for read-only manifest, blob, and SSE delivery.
#[cfg(feature = "update-server")]
#[derive(Clone)]
pub struct UpdateServerState {
    /// Backing atomic local filesystem update store.
    pub(crate) store: UpdateStore,
    /// Shared Hyperlane SSE pub/sub hub with bounded `Last-Event-ID` replay.
    pub(crate) sse_hub: SseHub,
    /// SSE stream heartbeat and reconnect configuration.
    pub(crate) sse_config: SseConfig,
    /// Last release sequence dispatched per `(project, channel)` to ensure exactly-once SSE fan-out per sequence.
    pub(crate) dispatched_seqs: Arc<Mutex<HashMap<(String, String), u64>>>,
    /// Cooperative running flag shared with the background pointer watcher.
    pub(crate) running: Arc<AtomicBool>,
}

/// Running handle to a live Hyperlane HTTP + SSE update server with clean programmatic shutdown.
#[cfg(feature = "update-server")]
pub struct UpdateServerHandle {
    /// Bound socket address (`ip:port`).
    pub(crate) address: SocketAddr,
    /// Shared update server state (store + SSE hub).
    pub(crate) state: Arc<UpdateServerState>,
    /// Hyperlane shutdown control hook.
    pub(crate) control: Option<ServerControlHook>,
    /// Dedicated Tokio runtime hosting the Hyperlane server and pointer watcher.
    pub(crate) runtime: Option<runtime::Runtime>,
}

/// Hyperlane `ServerHook` serving `GET /v1/projects/{project}/channels/{channel}/manifest`.
#[cfg(feature = "update-server")]
pub struct ManifestRouteHook;

/// Hyperlane `ServerHook` serving `GET /v1/blobs/{sha256}` with Range resume support.
#[cfg(feature = "update-server")]
pub struct BlobRouteHook;

/// Hyperlane `ServerHook` streaming `GET /v1/projects/{project}/channels/{channel}/events` via `hyperlane-plugin-sse`.
#[cfg(feature = "update-server")]
pub struct EventsRouteHook;