Skip to main content

golem_schema/
model.rs

1// Copyright 2024-2026 Golem Cloud
2//
3// Licensed under the Golem Source License v1.1 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://license.golem.cloud/LICENSE
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use golem_schema_derive::{FromSchema, IntoSchema};
16use serde::{Deserialize, Serialize};
17
18/// Native counterpart of `golem:core/types@2.0.0::uuid`.
19pub type Uuid = uuid::Uuid;
20
21/// Native counterpart of `golem:core/types@2.0.0::datetime`.
22pub type Datetime = chrono::DateTime<chrono::Utc>;
23
24/// Native counterpart of `golem:core/types@2.0.0::environment-id`.
25#[derive(
26    Clone,
27    Debug,
28    PartialEq,
29    Eq,
30    PartialOrd,
31    Ord,
32    Hash,
33    Serialize,
34    Deserialize,
35    IntoSchema,
36    FromSchema,
37)]
38#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
39#[cfg_attr(feature = "full", desert(evolution()))]
40#[serde(rename_all = "camelCase")]
41#[schema(named = "golem.core.EnvironmentId")]
42#[cfg_attr(
43    feature = "guest",
44    derive(
45        golem_schema_derive::FromWire,
46        golem_schema_derive::IntoWire,
47        golem_schema_derive::WireSchema
48    )
49)]
50#[cfg_attr(feature = "full", derive(golem_schema_derive::PoemSchema))]
51pub struct EnvironmentId {
52    pub uuid: Uuid,
53}
54
55impl EnvironmentId {
56    pub fn new(uuid: Uuid) -> Self {
57        Self { uuid }
58    }
59}
60
61impl From<Uuid> for EnvironmentId {
62    fn from(uuid: Uuid) -> Self {
63        Self::new(uuid)
64    }
65}
66
67impl From<EnvironmentId> for Uuid {
68    fn from(value: EnvironmentId) -> Self {
69        value.uuid
70    }
71}
72
73/// Native counterpart of `golem:core/types@2.0.0::component-id`.
74#[derive(
75    Clone,
76    Debug,
77    PartialEq,
78    Eq,
79    PartialOrd,
80    Ord,
81    Hash,
82    Serialize,
83    Deserialize,
84    IntoSchema,
85    FromSchema,
86)]
87#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
88#[cfg_attr(feature = "full", desert(evolution()))]
89#[serde(rename_all = "camelCase")]
90#[schema(named = "golem.core.ComponentId")]
91#[cfg_attr(
92    feature = "guest",
93    derive(
94        golem_schema_derive::FromWire,
95        golem_schema_derive::IntoWire,
96        golem_schema_derive::WireSchema
97    )
98)]
99pub struct ComponentId {
100    pub uuid: Uuid,
101}
102
103impl ComponentId {
104    pub fn new(uuid: Uuid) -> Self {
105        Self { uuid }
106    }
107}
108
109impl From<Uuid> for ComponentId {
110    fn from(uuid: Uuid) -> Self {
111        Self::new(uuid)
112    }
113}
114
115impl From<ComponentId> for Uuid {
116    fn from(value: ComponentId) -> Self {
117        value.uuid
118    }
119}
120
121/// Native counterpart of `golem:core/types@2.0.0::account-id`.
122#[derive(
123    Clone,
124    Debug,
125    PartialEq,
126    Eq,
127    PartialOrd,
128    Ord,
129    Hash,
130    Serialize,
131    Deserialize,
132    IntoSchema,
133    FromSchema,
134)]
135#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
136#[cfg_attr(feature = "full", desert(evolution()))]
137#[serde(rename_all = "camelCase")]
138#[schema(named = "golem.core.AccountId")]
139#[cfg_attr(
140    feature = "guest",
141    derive(
142        golem_schema_derive::FromWire,
143        golem_schema_derive::IntoWire,
144        golem_schema_derive::WireSchema
145    )
146)]
147pub struct AccountId {
148    pub uuid: Uuid,
149}
150
151impl AccountId {
152    pub fn new(uuid: Uuid) -> Self {
153        Self { uuid }
154    }
155}
156
157impl From<Uuid> for AccountId {
158    fn from(uuid: Uuid) -> Self {
159        Self::new(uuid)
160    }
161}
162
163impl From<AccountId> for Uuid {
164    fn from(value: AccountId) -> Self {
165        value.uuid
166    }
167}
168
169/// Native counterpart of `golem:core/types@2.0.0::card-id`.
170#[derive(
171    Clone,
172    Debug,
173    PartialEq,
174    Eq,
175    PartialOrd,
176    Ord,
177    Hash,
178    Serialize,
179    Deserialize,
180    IntoSchema,
181    FromSchema,
182)]
183#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
184#[cfg_attr(feature = "full", desert(evolution()))]
185#[schema(named = "golem.core.CardId")]
186#[cfg_attr(
187    feature = "guest",
188    derive(
189        golem_schema_derive::FromWire,
190        golem_schema_derive::IntoWire,
191        golem_schema_derive::WireSchema
192    )
193)]
194pub struct CardId {
195    pub uuid: Uuid,
196}
197
198impl CardId {
199    pub fn new(uuid: Uuid) -> Self {
200        Self { uuid }
201    }
202}
203
204impl From<Uuid> for CardId {
205    fn from(uuid: Uuid) -> Self {
206        Self::new(uuid)
207    }
208}
209
210impl From<CardId> for Uuid {
211    fn from(value: CardId) -> Self {
212        value.uuid
213    }
214}
215
216/// Native counterpart of `golem:core/types@2.0.0::agent-id`.
217#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, IntoSchema, FromSchema)]
218#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
219#[cfg_attr(feature = "full", desert(evolution()))]
220#[serde(rename_all = "camelCase")]
221#[schema(named = "golem.core.AgentId")]
222#[cfg_attr(
223    feature = "guest",
224    derive(
225        golem_schema_derive::FromWire,
226        golem_schema_derive::IntoWire,
227        golem_schema_derive::WireSchema
228    )
229)]
230pub struct AgentId {
231    pub component_id: ComponentId,
232    pub agent_id: String,
233}
234
235impl AgentId {
236    pub fn new(component_id: ComponentId, agent_id: String) -> Self {
237        Self {
238            component_id,
239            agent_id,
240        }
241    }
242}
243
244/// Native counterpart of `golem:core/types@2.0.0::oplog-index`.
245pub type OplogIndex = u64;
246
247/// Native counterpart of `golem:core/types@2.0.0::promise-id`.
248#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, IntoSchema, FromSchema)]
249#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
250#[cfg_attr(feature = "full", desert(evolution()))]
251#[serde(rename_all = "camelCase")]
252#[schema(named = "golem.core.PromiseId")]
253#[cfg_attr(
254    feature = "guest",
255    derive(
256        golem_schema_derive::FromWire,
257        golem_schema_derive::IntoWire,
258        golem_schema_derive::WireSchema
259    )
260)]
261pub struct PromiseId {
262    pub agent_id: AgentId,
263    pub oplog_idx: OplogIndex,
264}
265
266impl PromiseId {
267    pub fn new(agent_id: AgentId, oplog_idx: OplogIndex) -> Self {
268        Self {
269            agent_id,
270            oplog_idx,
271        }
272    }
273}