use crate::model::EnvironmentId;
use crate::schema::schema_type::QuantityValue;
use crate::schema::stream::SchemaValueStream;
use chrono::{DateTime, Utc};
use golem_schema_derive::{FromSchema, IntoSchema};
use serde::{Deserialize, Serialize};
#[cfg(not(all(feature = "guest", not(feature = "host"))))]
pub type SecretVariantValue = SecretValuePayload;
#[cfg(all(feature = "guest", not(feature = "host")))]
pub type SecretVariantValue = crate::schema::wit::GuestSecretHandle;
#[cfg(not(all(feature = "guest", not(feature = "host"))))]
pub type QuotaTokenVariantValue = QuotaTokenValuePayload;
#[cfg(all(feature = "guest", not(feature = "host")))]
pub type QuotaTokenVariantValue = crate::schema::wit::GuestQuotaTokenHandle;
#[cfg(not(all(feature = "guest", not(feature = "host"))))]
pub type PermissionCardVariantValue = PermissionCardValuePayload;
#[cfg(all(feature = "guest", not(feature = "host")))]
pub type PermissionCardVariantValue = crate::schema::wit::GuestPermissionCardHandle;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
#[schema(named = "schema-value")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub enum SchemaValue {
Bool(bool),
S8(i8),
S16(i16),
S32(i32),
S64(i64),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
F32(f32),
F64(f64),
Char(char),
String(String),
Record {
fields: Vec<SchemaValue>,
},
Variant(VariantValuePayload),
Enum {
case: u32,
},
Flags {
bits: Vec<bool>,
},
Tuple {
elements: Vec<SchemaValue>,
},
List {
elements: Vec<SchemaValue>,
},
FixedList {
elements: Vec<SchemaValue>,
},
Map {
entries: Vec<(SchemaValue, SchemaValue)>,
},
Option {
inner: Option<Box<SchemaValue>>,
},
Result(ResultValuePayload),
Text(TextValuePayload),
Binary(BinaryValuePayload),
Path {
path: String,
},
Url {
url: String,
},
Uuid(uuid::Uuid),
Datetime {
value: DateTime<Utc>,
},
Duration(DurationValuePayload),
Quantity(QuantityValue),
Union(UnionValuePayload),
#[cfg_attr(all(feature = "guest", not(feature = "host")), serde(skip))]
#[cfg_attr(
all(feature = "full", feature = "guest", not(feature = "host")),
transient
)]
Secret(SecretVariantValue),
#[cfg_attr(all(feature = "guest", not(feature = "host")), serde(skip))]
#[cfg_attr(
all(feature = "full", feature = "guest", not(feature = "host")),
transient
)]
QuotaToken(QuotaTokenVariantValue),
PermissionCard(PermissionCardVariantValue),
#[serde(skip)]
#[cfg_attr(feature = "full", transient)]
Stream(SchemaValueStream),
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct VariantValuePayload {
pub case: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub payload: Option<Box<SchemaValue>>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(tag = "tag", rename_all = "kebab-case")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub enum ResultValuePayload {
Ok { value: Option<Box<SchemaValue>> },
Err { value: Option<Box<SchemaValue>> },
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct TextValuePayload {
pub text: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub language: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct BinaryValuePayload {
pub bytes: Vec<u8>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct DurationValuePayload {
pub nanoseconds: i64,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct UnionValuePayload {
pub tag: String,
pub body: Box<SchemaValue>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct SecretValuePayload {
pub secret_id: uuid::Uuid,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub config_key: Option<Vec<String>>,
pub version: u64,
pub resolved_at: DateTime<Utc>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct QuotaTokenValuePayload {
pub environment_id: EnvironmentId,
pub resource_name: String,
pub expected_use: u64,
pub last_credit: i64,
pub last_credit_at: DateTime<Utc>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
#[cfg_attr(feature = "full", desert(evolution()))]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
pub struct PermissionCardValuePayload {
pub card_id: uuid::Uuid,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub parent_ids: Vec<uuid::Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expires_at: Option<DateTime<Utc>>,
pub polymorphic: bool,
}