euv-core 0.48.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Formats an artifact key string `"<module_id>@<version>"`.
///
/// # Arguments
///
/// - `&str` - Stable module identifier.
/// - `&str` - Exact implementation version string.
///
/// # Returns
///
/// - `String` - Canonical artifact map key.
#[must_use]
pub fn format_artifact_key(module_id: &str, version: &str) -> String {
    format!("{module_id}@{version}")
}

/// Resolves the default compatibility track name for a host ABI and delivery mode.
///
/// # Arguments
///
/// - `u32` - Host ABI version.
/// - `DeliveryChannelMode` - Target channel delivery mode.
///
/// # Returns
///
/// - `String` - Deterministic track identifier.
#[must_use]
pub fn default_track_for(host_abi: u32, mode: DeliveryChannelMode) -> String {
    match mode {
        DeliveryChannelMode::WasmComponent => format!("abi-v{host_abi}-wasm"),
        DeliveryChannelMode::DeclarativeData => format!("abi-v{host_abi}-data"),
    }
}

/// Computes the transitive SHA-256 closure for a single route from `artifacts`.
///
/// # Arguments
///
/// - `&RouteManifest` - Route entry and slot bindings.
/// - `&BTreeMap<String, BlobArtifact>` - Release artifact table.
///
/// # Returns
///
/// - `Result<BTreeSet<String>, DynamicReleaseError>` - Complete set of required SHA-256 digests.
pub fn compute_route_transitive_hashes(
    route: &RouteManifest,
    artifacts: &BTreeMap<String, BlobArtifact>,
) -> Result<BTreeSet<String>, DynamicReleaseError> {
    let mut visited_keys: BTreeSet<String> = BTreeSet::new();
    let mut queue: VecDeque<String> = VecDeque::new();
    let entry_key: &str = route.get_entry_module().as_str();
    if !artifacts.contains_key(entry_key) {
        return Err(DynamicReleaseError::BrokenDependencyClosure(format!(
            "{ERR_MISSING_ENTRY_ARTIFACT}: {entry_key}"
        )));
    }
    queue.push_back(entry_key.to_string());
    for bound_key in route.get_slot_bindings().values() {
        if !artifacts.contains_key(bound_key) {
            return Err(DynamicReleaseError::BrokenDependencyClosure(format!(
                "{ERR_MISSING_SLOT_ARTIFACT}: {bound_key}"
            )));
        }
        queue.push_back(bound_key.clone());
    }
    let mut hashes: BTreeSet<String> = BTreeSet::new();
    while let Some(key) = queue.pop_front() {
        if !visited_keys.insert(key.clone()) {
            continue;
        }
        let Some(artifact) = artifacts.get(&key) else {
            return Err(DynamicReleaseError::BrokenDependencyClosure(format!(
                "{ERR_MISSING_DEP_ARTIFACT}: {key}"
            )));
        };
        let sha: &str = artifact.get_sha256().as_str();
        if !is_valid_sha256_hex(sha) {
            return Err(DynamicReleaseError::BrokenDependencyClosure(format!(
                "{ERR_INVALID_HASH_FORMAT}: {key}"
            )));
        }
        let _: bool = hashes.insert(sha.to_string());
        for dep_key in artifact.get_dependencies().iter() {
            if !artifacts.contains_key(dep_key) {
                return Err(DynamicReleaseError::BrokenDependencyClosure(format!(
                    "{ERR_MISSING_DEP_ARTIFACT}: {dep_key}"
                )));
            }
            if !visited_keys.contains(dep_key) {
                queue.push_back(dep_key.clone());
            }
        }
    }
    Ok(hashes)
}