reactive_graph/client/types/flows/
mod.rs1use crate::client::error::CommandError;
2use crate::client::error::CommandError::NoContent;
3use crate::client::error::CommandError::NotCreated;
4use crate::client::error::CommandError::NotFound;
5use crate::client::result::CommandResult;
6use crate::client::types::extension::output_format::ExtensionsOutputFormatWrapper;
7use crate::client::types::flows::args::FlowTypesArgs;
8use crate::client::types::flows::commands::FlowTypesCommands;
9use crate::client::types::flows::output_format::FlowTypesOutputFormatWrapper;
10use crate::client::types::property_type::output_format::PropertyTypesOutputFormatWrapper;
11use reactive_graph_client::ReactiveGraphClient;
12use reactive_graph_graph::NamespacedTypeContainer;
13use std::sync::Arc;
14
15pub(crate) mod args;
16pub(crate) mod commands;
17pub(crate) mod output_format;
18
19pub(crate) async fn flow_types(client: &Arc<ReactiveGraphClient>, flow_type_args: FlowTypesArgs) -> CommandResult {
20 let output_format_wrapper: FlowTypesOutputFormatWrapper = flow_type_args.output_format.clone().into();
21 let Some(command) = flow_type_args.commands else {
22 return Err(CommandError::MissingSubCommand);
23 };
24 match command {
25 FlowTypesCommands::List => match client.types().flows().get_all_flow_types().await {
26 Ok(Some(flow_types)) => output_format_wrapper.collection(flow_types),
27 Ok(None) => Err(NoContent("No flow types found".to_string())),
28 Err(e) => Err(e.into()),
29 },
30 FlowTypesCommands::Get(args) => match client.types().flows().get_flow_type_by_type(args.clone()).await {
31 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
32 Ok(None) => Err(args.not_found()),
33 Err(e) => Err(e.into()),
34 },
35 FlowTypesCommands::ListVariables(args) => match client.types().flows().get_flow_type_by_type(args.clone()).await {
36 Ok(Some(flow_type)) => {
37 let output_format_wrapper: PropertyTypesOutputFormatWrapper = flow_type_args.output_format.into();
38 output_format_wrapper.collection(flow_type.variables.to_vec())
39 }
40 Ok(None) => Err(args.not_found()),
41 Err(e) => Err(e.into()),
42 },
43 FlowTypesCommands::ListExtensions(args) => match client.types().flows().get_flow_type_by_type(args.clone()).await {
44 Ok(Some(flow_type)) => {
45 let output_format_wrapper: ExtensionsOutputFormatWrapper = flow_type_args.output_format.into();
46 output_format_wrapper.collection(flow_type.extensions.to_vec())
47 }
48 Ok(None) => Err(args.not_found()),
49 Err(e) => Err(e.into()),
50 },
51 FlowTypesCommands::Create(args) => match client.types().flows().create_flow_type_with_variables((&args).into()).await {
52 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
53 Ok(None) => Err(NotCreated("Flow type wasn't created".to_string())),
54 Err(e) => Err(e.into()),
55 },
56 FlowTypesCommands::Delete(args) => match client.types().flows().delete_flow_type_with_variables((&args).into()).await {
57 Ok(Some(true)) => Ok(format!("Flow type {}__{} deleted", args.namespace, args.name).into()),
58 Ok(Some(false)) => Ok(format!("Flow type {}__{} not deleted", args.namespace, args.name).into()),
59 Ok(None) => Err(args.not_found()),
60 Err(e) => Err(e.into()),
61 },
62 FlowTypesCommands::AddVariable(args) => match client.types().flows().add_variable_with_variables((&args).into()).await {
63 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
64 Ok(None) => Err(NotCreated("Property wasn't created".to_string())),
65 Err(e) => Err(e.into()),
66 },
67 FlowTypesCommands::RemoveVariable(args) => match client.types().flows().remove_variable_with_variables((&args).into()).await {
68 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
69 Ok(None) => Err(NotFound(format!("Flow type {}__{} not found", args.ty.namespace, args.ty.name))),
70 Err(e) => Err(e.into()),
71 },
72 FlowTypesCommands::AddExtension(args) => match client.types().flows().add_extension_with_variables((&args).into()).await {
73 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
74 Ok(None) => Err(NotCreated("Extension wasn't created".to_string())),
75 Err(e) => Err(e.into()),
76 },
77 FlowTypesCommands::RemoveExtension(args) => match client.types().flows().remove_extension_with_variables((&args).into()).await {
78 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
79 Ok(None) => Err(args.flow_ty.not_found()),
80 Err(e) => Err(e.into()),
81 },
82 FlowTypesCommands::AddEntityInstance(args) => match client.types().flows().add_entity_instance_with_variables((&args).into()).await {
83 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
84 Ok(None) => Err(NotCreated("Entity instance wasn't created".to_string())),
85 Err(e) => Err(e.into()),
86 },
87 FlowTypesCommands::RemoveEntityInstance(args) => match client.types().flows().remove_entity_instance_with_variables((&args).into()).await {
88 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
89 Ok(None) => Err(NotCreated("Entity instance wasn't removed".to_string())),
90 Err(e) => Err(e.into()),
91 },
92 FlowTypesCommands::UpdateDescription(args) => match client.types().flows().update_description_with_variables((&args).into()).await {
93 Ok(Some(flow_type)) => output_format_wrapper.single(flow_type),
94 Ok(None) => Err(args.ty.not_found()),
95 Err(e) => Err(e.into()),
96 },
97 FlowTypesCommands::JsonSchema => match client.json_schema().types().flows().await {
98 Ok(Some(json_schema)) => Ok(json_schema.into()),
99 Ok(None) => Err(NotFound("JSON Schema not available".to_string())),
100 Err(e) => Err(e.into()),
101 },
102 }
103}