1use crate::model::EnvironmentId;
16use crate::schema::schema_type::QuantityValue;
17use crate::schema::stream::SchemaValueStream;
18use chrono::{DateTime, Utc};
19use golem_schema_derive::{FromSchema, IntoSchema};
20use serde::{Deserialize, Serialize};
21
22#[cfg(not(all(feature = "guest", not(feature = "host"))))]
29pub type SecretVariantValue = SecretValuePayload;
30
31#[cfg(all(feature = "guest", not(feature = "host")))]
34pub type SecretVariantValue = crate::schema::wit::GuestSecretHandle;
35
36#[cfg(not(all(feature = "guest", not(feature = "host"))))]
49pub type QuotaTokenVariantValue = QuotaTokenValuePayload;
50
51#[cfg(all(feature = "guest", not(feature = "host")))]
54pub type QuotaTokenVariantValue = crate::schema::wit::GuestQuotaTokenHandle;
55
56#[cfg(not(all(feature = "guest", not(feature = "host"))))]
70pub type PermissionCardVariantValue = PermissionCardValuePayload;
71
72#[cfg(all(feature = "guest", not(feature = "host")))]
76pub type PermissionCardVariantValue = crate::schema::wit::GuestPermissionCardHandle;
77
78#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
88#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
89#[cfg_attr(feature = "full", desert(evolution()))]
90#[serde(tag = "kind", content = "value", rename_all = "kebab-case")]
91#[schema(named = "schema-value")]
92#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
93pub enum SchemaValue {
94 Bool(bool),
96 S8(i8),
97 S16(i16),
98 S32(i32),
99 S64(i64),
100 U8(u8),
101 U16(u16),
102 U32(u32),
103 U64(u64),
104 F32(f32),
105 F64(f64),
106 Char(char),
107 String(String),
108
109 Record {
111 fields: Vec<SchemaValue>,
112 },
113 Variant(VariantValuePayload),
114 Enum {
115 case: u32,
116 },
117 Flags {
118 bits: Vec<bool>,
119 },
120 Tuple {
121 elements: Vec<SchemaValue>,
122 },
123 List {
124 elements: Vec<SchemaValue>,
125 },
126 FixedList {
127 elements: Vec<SchemaValue>,
128 },
129 Map {
130 entries: Vec<(SchemaValue, SchemaValue)>,
131 },
132 Option {
133 inner: Option<Box<SchemaValue>>,
134 },
135 Result(ResultValuePayload),
136
137 Text(TextValuePayload),
139 Binary(BinaryValuePayload),
140 Path {
141 path: String,
142 },
143 Url {
144 url: String,
145 },
146 Uuid(uuid::Uuid),
147 Datetime {
148 value: DateTime<Utc>,
149 },
150 Duration(DurationValuePayload),
151 Quantity(QuantityValue),
152
153 Union(UnionValuePayload),
155
156 #[cfg_attr(all(feature = "guest", not(feature = "host")), serde(skip))]
158 #[cfg_attr(
159 all(feature = "full", feature = "guest", not(feature = "host")),
160 transient
161 )]
162 Secret(SecretVariantValue),
163 #[cfg_attr(all(feature = "guest", not(feature = "host")), serde(skip))]
164 #[cfg_attr(
165 all(feature = "full", feature = "guest", not(feature = "host")),
166 transient
167 )]
168 QuotaToken(QuotaTokenVariantValue),
169 PermissionCard(PermissionCardVariantValue),
170 #[serde(skip)]
171 #[cfg_attr(feature = "full", transient)]
172 Stream(SchemaValueStream),
173}
174
175#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
176#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
177#[cfg_attr(feature = "full", desert(evolution()))]
178#[serde(rename_all = "camelCase")]
179#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
180pub struct VariantValuePayload {
181 pub case: u32,
182 #[serde(default, skip_serializing_if = "Option::is_none")]
183 pub payload: Option<Box<SchemaValue>>,
184}
185
186#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
189#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
190#[cfg_attr(feature = "full", desert(evolution()))]
191#[serde(tag = "tag", rename_all = "kebab-case")]
192#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
193pub enum ResultValuePayload {
194 Ok { value: Option<Box<SchemaValue>> },
195 Err { value: Option<Box<SchemaValue>> },
196}
197
198#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
199#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
200#[cfg_attr(feature = "full", desert(evolution()))]
201#[serde(rename_all = "camelCase")]
202#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
203pub struct TextValuePayload {
204 pub text: String,
205 #[serde(default, skip_serializing_if = "Option::is_none")]
207 pub language: Option<String>,
208}
209
210#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
211#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
212#[cfg_attr(feature = "full", desert(evolution()))]
213#[serde(rename_all = "camelCase")]
214#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
215pub struct BinaryValuePayload {
216 pub bytes: Vec<u8>,
217 #[serde(default, skip_serializing_if = "Option::is_none")]
218 pub mime_type: Option<String>,
219}
220
221#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
223#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
224#[cfg_attr(feature = "full", desert(evolution()))]
225#[serde(rename_all = "camelCase")]
226#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
227pub struct DurationValuePayload {
228 pub nanoseconds: i64,
229}
230
231#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, IntoSchema, FromSchema)]
232#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
233#[cfg_attr(feature = "full", desert(evolution()))]
234#[serde(rename_all = "camelCase")]
235#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
236pub struct UnionValuePayload {
237 pub tag: String,
242 pub body: Box<SchemaValue>,
245}
246
247#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
253#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
254#[cfg_attr(feature = "full", desert(evolution()))]
255#[serde(rename_all = "camelCase")]
256#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
257pub struct SecretValuePayload {
258 pub secret_id: uuid::Uuid,
259 #[serde(default, skip_serializing_if = "Option::is_none")]
260 pub config_key: Option<Vec<String>>,
261 pub version: u64,
262 pub resolved_at: DateTime<Utc>,
263 #[serde(default, skip_serializing_if = "Option::is_none")]
264 pub category: Option<String>,
265}
266
267#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
275#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
276#[cfg_attr(feature = "full", desert(evolution()))]
277#[serde(rename_all = "camelCase")]
278#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
279pub struct QuotaTokenValuePayload {
280 pub environment_id: EnvironmentId,
281 pub resource_name: String,
282 pub expected_use: u64,
283 pub last_credit: i64,
284 pub last_credit_at: DateTime<Utc>,
285}
286
287#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoSchema, FromSchema)]
300#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
301#[cfg_attr(feature = "full", desert(evolution()))]
302#[serde(rename_all = "camelCase")]
303#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
304pub struct PermissionCardValuePayload {
305 pub card_id: uuid::Uuid,
308 #[serde(default, skip_serializing_if = "Vec::is_empty")]
311 pub parent_ids: Vec<uuid::Uuid>,
312 #[serde(default, skip_serializing_if = "Option::is_none")]
314 pub expires_at: Option<DateTime<Utc>>,
315 pub polymorphic: bool,
318}