use arora_types::call::Call;
use arora_types::data::Key;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct TaskId(pub Uuid);
impl arora_types::AroraType for TaskId {
fn arora_type_id() -> Uuid {
*arora_types::ty::UUID_ID
}
fn arora_type() -> arora_types::ty::low::Type {
arora_types::ty::PRIMITIVE_TYPES
.get(&*arora_types::ty::UUID_ID)
.expect("the uuid primitive is always registered")
.clone()
}
fn register_types(_registry: &mut arora_types::ty::TypeRegistry) {
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum RunPolicy {
Concurrent,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, arora_types::AroraType)]
#[arora(id = "d1f79433-a751-4fe3-9e6f-561cea873293")]
pub struct TaskHandle {
#[arora(id = "35a14602-9fb2-4387-b202-21f0fc8cfb0c")]
pub id: TaskId,
#[arora(id = "41e5efbb-959a-4aa0-b078-fc2812ab6181")]
pub stop: Call,
#[arora(id = "f1a077ed-4007-4f18-b3be-cc3711058515")]
pub status: Key,
#[arora(id = "60f2f967-16a3-4631-b27c-92445b583d9c")]
pub feedback: Vec<Key>,
#[arora(id = "d6afb314-2bfd-444a-b041-39d9223ba700")]
pub result: Vec<Key>,
#[arora(id = "53d75772-12bd-4a55-a0a5-696b2bc4f6a9")]
pub update: Vec<Key>,
}
#[cfg(test)]
mod tests {
use super::*;
use arora_types::module::low::TypeRef;
use arora_types::ty::low::TypeKind;
use arora_types::AroraType;
#[test]
fn task_handle_arora_type_shapes_its_fields() {
let (ty, registry) = TaskHandle::arora_type_with_registry();
let TypeKind::Structure(structure) = &ty.kind else {
panic!("TaskHandle is a structure type");
};
let field = |id: &str| {
structure.fields[&arora_types::Uuid::parse_str(id).unwrap()]
.type_ref
.clone()
};
assert!(matches!(
field("35a14602-9fb2-4387-b202-21f0fc8cfb0c"),
TypeRef::Scalar { id } if id == *arora_types::ty::UUID_ID
));
assert!(matches!(
field("41e5efbb-959a-4aa0-b078-fc2812ab6181"),
TypeRef::Scalar { id } if id == Call::arora_type_id()
));
assert!(matches!(
field("f1a077ed-4007-4f18-b3be-cc3711058515"),
TypeRef::Scalar { id } if id == *arora_types::ty::STRING_ID
));
for id in [
"60f2f967-16a3-4631-b27c-92445b583d9c",
"d6afb314-2bfd-444a-b041-39d9223ba700",
"53d75772-12bd-4a55-a0a5-696b2bc4f6a9",
] {
assert!(matches!(
field(id),
TypeRef::Array { id } if id == *arora_types::ty::STRING_ID
));
}
assert!(registry.contains_key(&Call::arora_type_id()));
}
}