yah-workload-spec 0.8.42

WorkloadSpec — typed wire format for yubaba workloads. Schema crate with zero deps on yubaba; yubaba depends on this, not the other way around.
Documentation
//! In-memory TS-binding rendering, shared by `bin/export-ts.rs` (which writes
//! it to `packages/yah/workload-spec/index.ts`) and `tests/ts_drift.rs`
//! (which compares [`render`]'s output against that committed file without
//! writing anything or touching git — R605-B28).
//!
//! [`render`] used to be inlined in `bin/export-ts.rs`'s `main`, which made
//! "is the committed file what the Rust types imply" undecidable except by a
//! `git diff` against HEAD — a question the drift guard actually needed to
//! answer without going through git at all (R605-B28's fix on the sibling
//! `.yah/schema/*.toml.schema.json` guard, `xtask::schemas::render_all`, is
//! the pattern this mirrors).

use ts_rs::{Config, TS};

use crate::*;

pub const HEADER: &str = "\
// AUTO-GENERATED by `cargo run -p yah-workload-spec --bin export-ts`.
// Source of truth: crates/yah/workload-spec/src/lib.rs.
// Do not edit by hand. Regenerate after changing the Rust types and commit
// the result; CI fails if this file drifts from the Rust schema.

";

/// Render the full single-file TS binding for `WorkloadSpec` and every type
/// it references, in the same fixed leaves-first order `bin/export-ts.rs`
/// always wrote. Pure — no filesystem access.
pub fn render() -> String {
    let cfg = Config::default();
    let mut out = String::from(HEADER);

    macro_rules! emit {
        ($t:ty) => {
            out.push_str("export ");
            out.push_str(&<$t as TS>::decl(&cfg));
            out.push_str("\n\n");
        };
    }

    // Order: leaves first, then composites that reference them.
    emit!(Millis);
    emit!(MachineId);
    emit!(MeshIdent);
    emit!(TierTag);
    emit!(TenantId);
    emit!(NamespaceId);

    emit!(MeshLookup);
    emit!(EnvValue);
    emit!(EnvVar);

    emit!(SecretRef);
    emit!(SecretTarget);
    emit!(SecretMount);

    emit!(VolumeSource);
    emit!(VolumeMount);

    emit!(ImageRef);
    emit!(ResourceLimits);

    emit!(HealthProbe);
    emit!(Healthcheck);

    emit!(BackoffPolicy);
    emit!(RestartPolicy);
    emit!(StopPolicy);

    emit!(MeshPeer);
    emit!(MeshExpose);
    emit!(PublicTls);
    emit!(PublicExpose);
    emit!(OperatorExpose);
    emit!(ExposeSpec);

    // R860-T1: the requirement vocabulary. Requirement.provides makes this
    // mutually recursive with WorkloadSpec, so the order is arbitrary — the
    // declarations reference each other by name either way.
    emit!(Locality);
    emit!(Supply);
    emit!(Requirement);

    emit!(WorkloadSpec);

    // The two on-disk forms of `kind = "container"` (R783-F1 / W324). Leaves
    // first: ContainerManifest is a union over WorkloadSpec and ContainerBuild.
    emit!(ContainerMount);
    emit!(ContainerRunConfig);
    emit!(ContainerBuildStep);
    emit!(ContainerBuild);
    emit!(ContainerManifest);

    emit!(BuildConfig);
    emit!(BuildMode);
    emit!(MesofactStaticWorkload);
    emit!(MesofactServeBundle);
    emit!(BundleLifecycle);
    // Referenced by MesofactStaticWorkload.revalidate_receiver — omitting it
    // emitted a binding that names a type this file never declares.
    emit!(AlmanacFeed);
    emit!(MesofactRevalidateReceiver);

    emit!(AlmanacTarget);
    emit!(NotReadyPolicy);
    emit!(Cadence);
    emit!(AlmanacManifest);

    emit!(BlakeHash);
    emit!(License);
    emit!(FetchSource);
    emit!(TransformSpec);
    emit!(AssetDerive);
    emit!(AssetEntry);
    emit!(StaticAssetWorkload);

    // R852-F1 — the per-tenant passway. Leaf first: TenantPasswayWorkload
    // names TenantPasswayTls.
    emit!(TenantPasswayTls);
    emit!(TenantPasswayWorkload);

    emit!(Workload);

    out
}