reactive_graph_command_model/component/
command.rs

1use serde_json::json;
2use std::sync::LazyLock;
3
4use reactive_graph_graph::DataType;
5use reactive_graph_graph::Mutability::Immutable;
6use reactive_graph_graph::PropertyType;
7use reactive_graph_graph::PropertyTypeDefinition;
8use reactive_graph_graph::PropertyTypes;
9use reactive_graph_graph::SocketType;
10use reactive_graph_graph::component_model;
11use reactive_graph_graph::component_ty;
12use reactive_graph_graph::properties;
13use reactive_graph_runtime_model::ActionProperties::TRIGGER;
14use reactive_graph_runtime_model::LabeledProperties::LABEL;
15use reactive_graph_runtime_model::NAMESPACE_CORE;
16
17properties!(
18    CommandProperties,
19    (COMMAND_NAMESPACE, "namespace", ""),
20    (COMMAND_NAME, "command", ""),
21    (COMMAND_ARGS, "args", json!([])),
22    (COMMAND_HELP, "help", ""),
23    (COMMAND_RESULT, "cmd_result", "")
24);
25
26component_ty!(COMPONENT_COMMAND, NAMESPACE_CORE, COMPONENT_NAME_COMMAND, "command");
27
28component_model!(
29    CommandComponent,
30    get scope string,
31    get command string,
32    get help string,
33);
34
35pub static COMMAND_PROPERTIES: LazyLock<PropertyTypes> = LazyLock::new(|| {
36    PropertyTypes::new()
37        .property(
38            PropertyType::builder()
39                .name(LABEL.property_name())
40                .data_type(DataType::String)
41                .mutability(Immutable)
42                .socket_type(SocketType::None)
43                .build(),
44        )
45        .property(PropertyType::input(TRIGGER.property_name(), DataType::Bool))
46        .property(
47            PropertyType::builder()
48                .name(CommandProperties::COMMAND_NAMESPACE.property_name())
49                .data_type(DataType::String)
50                .mutability(Immutable)
51                .socket_type(SocketType::None)
52                .build(),
53        )
54        .property(
55            PropertyType::builder()
56                .name(CommandProperties::COMMAND_NAME.property_name())
57                .data_type(DataType::String)
58                .mutability(Immutable)
59                .socket_type(SocketType::None)
60                .build(),
61        )
62        .property(PropertyType::input(CommandProperties::COMMAND_ARGS.property_name(), DataType::Array))
63        .property(
64            PropertyType::builder()
65                .name(CommandProperties::COMMAND_HELP.property_name())
66                .data_type(DataType::String)
67                .mutability(Immutable)
68                .socket_type(SocketType::None)
69                .build(),
70        )
71        .property(PropertyType::output(CommandProperties::COMMAND_RESULT.property_name(), DataType::Any))
72});