use golem_schema_derive::{FromSchema, IntoSchema};
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
#[derive(
Clone,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
IntoSchema,
FromSchema,
)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(transparent))]
#[serde(transparent)]
#[schema(transparent)]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct TypeId(pub String);
impl TypeId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl Display for TypeId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl From<String> for TypeId {
fn from(value: String) -> Self {
Self(value)
}
}
impl From<&str> for TypeId {
fn from(value: &str) -> Self {
Self(value.to_string())
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[schema(named = "metadata-envelope")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct MetadataEnvelope {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub doc: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub aliases: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub examples: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deprecated: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub role: Option<Role>,
}
impl MetadataEnvelope {
pub fn is_empty(&self) -> bool {
self.doc.is_none()
&& self.aliases.is_empty()
&& self.examples.is_empty()
&& self.deprecated.is_none()
&& self.role.is_none()
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "tag", content = "value", rename_all = "kebab-case")]
#[schema(named = "role")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub enum Role {
Multimodal,
UnstructuredText,
UnstructuredBinary,
Other(String),
}