yah-workload-spec 0.8.22

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);
    // 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);

    emit!(Workload);

    // Anchor the output path to the yah camp root via CARGO_MANIFEST_DIR so the
    // bin produces the same file regardless of the cwd cargo is invoked from.
    // The crate sits at oss/yah-base/crates/workload-spec — FOUR parents up is
    // the camp root (75d8df7e split yah-base out of yubaba and added the extra
    // `oss/yah-base` level; the count stayed at three, so since that commit
    // this bin silently wrote to oss/yah-base/packages/… and the committed
    // bindings stopped tracking the Rust types. Found while regenerating for
    // R546-B7).
    let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let camp_root = manifest_dir
        .ancestors()
        .nth(4)
        .expect("CARGO_MANIFEST_DIR has at least four parents");
    let path = camp_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());
}