use serde::{Deserialize, Serialize};
mod broker;
mod otel;
pub mod client;
pub use client::{Client, ClientBuilder};
mod types;
pub use types::component::*;
pub use types::ctl::*;
pub use types::host::*;
pub use types::link::*;
pub use types::provider::*;
pub use types::registry::*;
pub use types::rpc::*;
#[deprecated(
since = "2.3.0",
note = "String type aliases are deprecated, use Strings instead"
)]
#[allow(dead_code)]
mod aliases {
type ComponentId = String;
type KnownConfigName = String;
type LatticeTarget = String;
type LinkName = String;
type WitInterface = String;
type WitNamespace = String;
type WitPackage = String;
}
#[allow(unused_imports)]
#[allow(deprecated)]
pub use aliases::*;
type Result<T> = ::core::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
#[allow(unused)]
pub(crate) enum IdentifierKind {
HostId,
ComponentId,
ComponentRefs,
ProviderRef,
LinkName,
}
impl IdentifierKind {
fn is_host_id(value: impl AsRef<str>) -> Result<String> {
assert_non_empty_string(value, "Host ID cannot be empty")
}
fn is_component_id(value: impl AsRef<str>) -> Result<String> {
assert_non_empty_string(value, "Component ID cannot be empty")
}
fn is_component_ref(value: impl AsRef<str>) -> Result<String> {
assert_non_empty_string(value, "Component OCI reference cannot be empty")
}
fn is_provider_ref(value: impl AsRef<str>) -> Result<String> {
assert_non_empty_string(value, "Provider OCI reference cannot be empty")
}
fn is_provider_id(value: impl AsRef<str>) -> Result<String> {
assert_non_empty_string(value, "Provider ID cannot be empty")
}
fn is_link_name(value: impl AsRef<str>) -> Result<String> {
assert_non_empty_string(value, "Link Name cannot be empty")
}
}
pub(crate) fn json_serialize<T>(item: T) -> Result<Vec<u8>>
where
T: Serialize,
{
serde_json::to_vec(&item).map_err(|e| format!("JSON serialization failure: {e}").into())
}
pub(crate) fn json_deserialize<'de, T: Deserialize<'de>>(buf: &'de [u8]) -> Result<T> {
serde_json::from_slice(buf).map_err(|e| format!("JSON deserialization failure: {e}").into())
}
fn assert_non_empty_string(input: impl AsRef<str>, message: impl AsRef<str>) -> Result<String> {
let input = input.as_ref();
let message = message.as_ref();
if input.trim().is_empty() {
Err(message.into())
} else {
Ok(input.trim().to_string())
}
}