wasmer-deploy-schema 0.0.21

Utilty crate that holds shared types and logic used in Wasmer Deploy.
Documentation
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use super::{
    CapabilityCpuV1, CapabilityFileSystemV1, CapabilityLoggingV1, CapabilityMemorySwapV1,
    CapabilityMemoryV1, CapabilityNetworkDnsV1, CapabilityNetworkGatewayV1, CapabilityNetworkV1,
    CapabilityPersistentMemoryV1, CapabilityWasiV1, Merge,
};

#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub enum CapabilityV1 {
    #[serde(rename = "cpu")]
    Cpu(CapabilityCpuV1),
    #[serde(rename = "fs")]
    FileSystem(CapabilityFileSystemV1),
    #[serde(rename = "memory_swap")]
    MemorySwap(CapabilityMemorySwapV1),
    #[serde(rename = "memory_persistent")]
    MemoryPersistent(CapabilityPersistentMemoryV1),
    #[serde(rename = "network")]
    Network(CapabilityNetworkV1),
    #[serde(rename = "network_dns")]
    NetworkDns(CapabilityNetworkDnsV1),
    #[serde(rename = "network_gateway")]
    NetworkGateway(CapabilityNetworkGatewayV1),
}

#[derive(Serialize, Deserialize, Default, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct CapabilityMapV1 {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub wasi: Option<CapabilityWasiV1>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cpu: Option<CapabilityCpuV1>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fs: Option<CapabilityFileSystemV1>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub memory: Option<CapabilityMemoryV1>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub network: Option<CapabilityNetworkV1>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub network_dns: Option<CapabilityNetworkDnsV1>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub network_gateway: Option<CapabilityNetworkGatewayV1>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logging: Option<CapabilityLoggingV1>,

    /// Additional unknown capabilities.
    #[serde(flatten)]
    pub other: HashMap<String, serde_json::Value>,
}

impl Merge for CapabilityMapV1 {
    fn merge_extend(self, other: &Self) -> Self {
        Self {
            wasi: self.wasi.merge_extend(&other.wasi),
            cpu: self.cpu.merge_extend(&other.cpu),
            fs: self.fs.merge_extend(&other.fs),
            memory: self.memory.merge_extend(&other.memory),
            network: self.network.merge_extend(&other.network),
            network_dns: self.network_dns.merge_extend(&other.network_dns),
            network_gateway: self.network_gateway.merge_extend(&other.network_gateway),
            logging: self.logging.merge_extend(&other.logging),
            other: self.other,
        }
    }
}