yah-workload-spec 0.8.21

WorkloadSpec — typed wire format for yubaba workloads. Schema crate with zero deps on yubaba; yubaba depends on this, not the other way around.
Documentation
//! Codegen: emit a single-file TypeScript binding for `WorkloadSpec` and
//! every type it references.
//!
//! Run with `cargo run -p yah-workload-spec --bin export-ts`. Writes to
//! `packages/yah/workload-spec/index.ts` (relative to the workspace root).
//! The output is deterministic — the drift CI step regenerates and fails on
//! `git diff` so divergence between Rust and TS shows up as a CI failure.

use std::path::PathBuf;

use ts_rs::{Config, TS};
use workload_spec::*;

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.

";

fn main() {
    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!(SchemaVersion);
    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);

    emit!(WorkloadSpec);

    emit!(BuildConfig);
    emit!(BuildMode);
    emit!(MesofactStaticWorkload);
    emit!(MesofactServeBundle);
    emit!(BundleLifecycle);

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

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

    emit!(Workload);

    // Anchor the output path to the workspace root via CARGO_MANIFEST_DIR so
    // the bin produces the same file regardless of the cwd cargo is invoked
    // from. The crate sits at crates/yah/workload-spec — three parents up is
    // the workspace root.
    let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let workspace_root = manifest_dir
        .parent()
        .and_then(|p| p.parent())
        .and_then(|p| p.parent())
        .expect("CARGO_MANIFEST_DIR has at least three parents");
    let path = workspace_root.join("packages/yah/workload-spec/index.ts");

    if let Some(parent) = path.parent() {
        std::fs::create_dir_all(parent).expect("create parent dirs");
    }
    std::fs::write(&path, &out).expect("write index.ts");

    println!("Wrote {} ({} bytes)", path.display(), out.len());
}