|
| 1 | +use tucana::shared::{ |
| 2 | + FlowType, FlowTypeSetting, FunctionDefinition, Module, ParameterDefinition, RuntimeFlowType, RuntimeFlowTypeSetting, RuntimeFunctionDefinition, RuntimeParameterDefinition |
| 3 | +}; |
| 4 | + |
| 5 | +use crate::{analyser::core::Analyser, command::parse_errors::fail_on_parser_errors, parser::{DefinitionModule, Parser}}; |
| 6 | + |
| 7 | +fn runtime_function_into_function( |
| 8 | + runtime_function: &RuntimeFunctionDefinition, |
| 9 | +) -> FunctionDefinition { |
| 10 | + let parameter: Vec<ParameterDefinition> = runtime_function |
| 11 | + .runtime_parameter_definitions |
| 12 | + .iter() |
| 13 | + .map(|x| runtime_parameter_into_parameter(x)) |
| 14 | + .collect(); |
| 15 | + FunctionDefinition { |
| 16 | + runtime_name: runtime_function.runtime_name.clone(), |
| 17 | + parameter_definitions: parameter, |
| 18 | + signature: runtime_function.signature.clone(), |
| 19 | + throws_error: runtime_function.throws_error, |
| 20 | + name: runtime_function.name.clone(), |
| 21 | + description: runtime_function.description.clone(), |
| 22 | + documentation: runtime_function.documentation.clone(), |
| 23 | + deprecation_message: runtime_function.deprecation_message.clone(), |
| 24 | + display_message: runtime_function.display_message.clone(), |
| 25 | + alias: runtime_function.alias.clone(), |
| 26 | + linked_data_type_identifiers: runtime_function.linked_data_type_identifiers.clone(), |
| 27 | + version: runtime_function.version.clone(), |
| 28 | + display_icon: runtime_function.display_icon.clone(), |
| 29 | + definition_source: runtime_function.definition_source.clone(), |
| 30 | + runtime_definition_name: runtime_function.runtime_name.clone(), |
| 31 | + design: runtime_function.design.clone(), |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +fn runtime_parameter_into_parameter( |
| 36 | + runtime_parameter: &RuntimeParameterDefinition, |
| 37 | +) -> ParameterDefinition { |
| 38 | + ParameterDefinition { |
| 39 | + runtime_name: runtime_parameter.runtime_name.clone(), |
| 40 | + default_value: runtime_parameter.default_value.clone(), |
| 41 | + optional: runtime_parameter.optional.clone(), |
| 42 | + hidden: runtime_parameter.hidden.clone(), |
| 43 | + name: runtime_parameter.name.clone(), |
| 44 | + description: runtime_parameter.description.clone(), |
| 45 | + documentation: runtime_parameter.documentation.clone(), |
| 46 | + runtime_definition_name: runtime_parameter.runtime_name.clone(), |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +fn runtime_flow_type_into_flow_type(runtime_flow_type: &RuntimeFlowType) -> FlowType { |
| 51 | + let settings: Vec<FlowTypeSetting> = runtime_flow_type |
| 52 | + .runtime_settings |
| 53 | + .iter() |
| 54 | + .map(|x| runtime_flow_setting_into_flow_setting(x)) |
| 55 | + .collect(); |
| 56 | + FlowType { |
| 57 | + identifier: runtime_flow_type.identifier.clone(), |
| 58 | + settings: settings, |
| 59 | + editable: runtime_flow_type.editable.clone(), |
| 60 | + name: runtime_flow_type.name.clone(), |
| 61 | + description: runtime_flow_type.description.clone(), |
| 62 | + documentation: runtime_flow_type.documentation.clone(), |
| 63 | + display_message: runtime_flow_type.display_message.clone(), |
| 64 | + alias: runtime_flow_type.alias.clone(), |
| 65 | + version: runtime_flow_type.version.clone(), |
| 66 | + display_icon: runtime_flow_type.display_icon.clone(), |
| 67 | + definition_source: runtime_flow_type.definition_source.clone(), |
| 68 | + linked_data_type_identifiers: runtime_flow_type.linked_data_type_identifiers.clone(), |
| 69 | + signature: runtime_flow_type.signature.clone(), |
| 70 | + runtime_identifier: runtime_flow_type.identifier.clone(), |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +fn runtime_flow_setting_into_flow_setting( |
| 75 | + runtime_flow_setting: &RuntimeFlowTypeSetting, |
| 76 | +) -> FlowTypeSetting { |
| 77 | + FlowTypeSetting { |
| 78 | + identifier: runtime_flow_setting.identifier.clone(), |
| 79 | + unique: runtime_flow_setting.unique.clone(), |
| 80 | + default_value: runtime_flow_setting.default_value.clone(), |
| 81 | + name: runtime_flow_setting.name.clone(), |
| 82 | + description: runtime_flow_setting.description.clone(), |
| 83 | + optional: runtime_flow_setting.optional.clone(), |
| 84 | + hidden: runtime_flow_setting.hidden.clone(), |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +fn apply_version_to_module(mut module: Module, version: String) -> Module { |
| 89 | + module.version = version.clone(); |
| 90 | + |
| 91 | + for data_type in &mut module.definition_data_types { |
| 92 | + data_type.version = version.clone(); |
| 93 | + } |
| 94 | + for flow_type in &mut module.flow_types { |
| 95 | + flow_type.version = version.clone(); |
| 96 | + } |
| 97 | + for runtime_flow_type in &mut module.runtime_flow_types { |
| 98 | + runtime_flow_type.version = version.clone(); |
| 99 | + } |
| 100 | + for function in &mut module.function_definitions { |
| 101 | + function.version = version.clone(); |
| 102 | + } |
| 103 | + for runtime_function in &mut module.runtime_function_definitions { |
| 104 | + runtime_function.version = version.clone(); |
| 105 | + } |
| 106 | + |
| 107 | + module |
| 108 | +} |
| 109 | + |
| 110 | +fn configure_module(definition_module: &DefinitionModule, version: String) -> Module { |
| 111 | + let mut module = definition_module.clone().into_module(); |
| 112 | + |
| 113 | + module.function_definitions = module.runtime_function_definitions.iter().map(|x| runtime_function_into_function(x)).collect(); |
| 114 | + module.flow_types = module.runtime_flow_types.iter().map(|x| runtime_flow_type_into_flow_type(x)).collect(); |
| 115 | + |
| 116 | + apply_version_to_module(module, version) |
| 117 | +} |
| 118 | + |
| 119 | +pub async fn publish(version: String, path: Option<String>) { |
| 120 | + let dir_path = path.unwrap_or_else(|| "./definitions".to_string()); |
| 121 | + |
| 122 | + let mut analyzer = Analyser::new(dir_path.as_str()); |
| 123 | + analyzer.report(false, true); |
| 124 | + |
| 125 | + let parser = match Parser::from_path(dir_path.as_str()) { |
| 126 | + Some(parser) => parser, |
| 127 | + None => { |
| 128 | + panic!("Error reading definitions"); |
| 129 | + } |
| 130 | + }; |
| 131 | + fail_on_parser_errors(&parser); |
| 132 | + |
| 133 | + let modules: Vec<Module> = parser.modules.into_iter().map(|x| configure_module(&x, version.clone())).collect(); |
| 134 | + |
| 135 | + //TODO: Gen out files |
| 136 | +} |
0 commit comments