diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index 561a5acfc..fda586850 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -11,7 +11,7 @@ use crate::objects::{Object, Objects, WithHandle}; pub use self::{ objects::{InsertObject, Operation}, service::{Service, State}, - validation::{Validation, ValidationFailed}, + validation::{Validation, ValidationCommand, ValidationFailed}, }; /// The kernel services @@ -46,7 +46,10 @@ impl Services { .execute(Operation::InsertObject { object }, &mut object_events); for object_event in object_events { - self.validation.execute(object_event, &mut Vec::new()); + let command = ValidationCommand::ValidateObject { + object: object_event.object, + }; + self.validation.execute(command, &mut Vec::new()); } } } diff --git a/crates/fj-kernel/src/services/validation.rs b/crates/fj-kernel/src/services/validation.rs index 2d37bdc6b..90cff079f 100644 --- a/crates/fj-kernel/src/services/validation.rs +++ b/crates/fj-kernel/src/services/validation.rs @@ -1,12 +1,12 @@ use std::{collections::BTreeMap, thread}; use crate::{ - objects::{BehindHandle, Object}, + objects::{BehindHandle, Object, WithHandle}, storage::ObjectId, validate::ValidationError, }; -use super::{objects::InsertObject, State}; +use super::State; /// Errors that occurred while validating the objects inserted into the stores #[derive(Default)] @@ -33,16 +33,18 @@ impl Drop for Validation { } impl State for Validation { - type Command = InsertObject; + type Command = ValidationCommand; type Event = ValidationFailed; fn decide(&self, command: Self::Command, events: &mut Vec) { + let ValidationCommand::ValidateObject { object } = command; + let mut errors = Vec::new(); - command.object.validate(&mut errors); + object.validate(&mut errors); for err in errors { events.push(ValidationFailed { - object: command.object.clone().into(), + object: object.clone().into(), err, }); } @@ -53,6 +55,15 @@ impl State for Validation { } } +/// The command accepted by the validation service +pub enum ValidationCommand { + /// Validate the provided object + ValidateObject { + /// The object to validate + object: Object, + }, +} + /// The event produced by the validation service #[derive(Clone)] pub struct ValidationFailed {