moduforge_transform/
attr_step.rs1use std::sync::Arc;
2
3use crate::draft::Draft;
4
5use super::{
6 ConcreteStep,
7 step::{Step, StepResult},
8 transform::TransformError,
9};
10use im::HashMap;
11use moduforge_model::{schema::Schema, types::NodeId};
12use serde::{Deserialize, Serialize};
13use serde_json::Value;
14#[derive(Debug, Serialize, Deserialize, Clone)]
15pub struct AttrStep {
16 id: NodeId,
17 values: HashMap<String, Value>,
18}
19impl AttrStep {
20 pub fn new(
21 id: String,
22 values: HashMap<String, Value>,
23 ) -> Self {
24 AttrStep { id, values }
25 }
26}
27impl Step for AttrStep {
28 fn apply(
29 &self,
30 dart: &mut Draft,
31 schema: Arc<Schema>,
32 ) -> Result<StepResult, TransformError> {
33 let _ = schema;
34 match dart.update_attr(&self.id, self.values.clone()) {
35 Ok(_) => Ok(dart.commit()),
36 Err(err) => Err(TransformError::new(err.to_string())),
37 }
38 }
39
40 fn to_concrete(&self) -> super::ConcreteStep {
41 ConcreteStep::UpdateAttrs(self.clone())
42 }
43}