golem_rib_repl/dependency_manager.rs
1// Copyright 2024-2025 Golem Cloud
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use async_trait::async_trait;
16use golem_wasm_ast::analysis::AnalysedExport;
17use std::fmt::Debug;
18use std::path::Path;
19use uuid::Uuid;
20
21/// Dependency manager for the Rib REPL environment.
22#[async_trait]
23pub trait RibDependencyManager {
24 /// Deploys all components within the current context if they are not already registered
25 /// with the Golem engine. Returns a list of successfully registered components.
26 ///
27 /// Note: It is the responsibility of the REPL client to resolve component paths.
28 /// In the future, Rib may support multiple components.
29 async fn get_dependencies(&self) -> Result<ReplDependencies, String>;
30
31 /// Deploys a specific component if the REPL was started with a reference to it.
32 ///
33 /// Currently, dynamic component loading is not supported.
34 ///
35 /// # Arguments
36 ///
37 /// * `source_path` - The file path to the component.
38 /// * `component_name` - The name of the component.
39 ///
40 /// # Returns
41 ///
42 /// Returns a `ComponentDependency` on success or an error message as a `String` if the operation fails.
43 async fn add_component(
44 &self,
45 source_path: &Path,
46 component_name: String,
47 ) -> Result<RibComponentMetadata, String>;
48}
49
50pub struct ReplDependencies {
51 pub component_dependencies: Vec<RibComponentMetadata>,
52}
53
54#[derive(Clone, Debug)]
55pub struct RibComponentMetadata {
56 pub component_id: Uuid,
57 pub metadata: Vec<AnalysedExport>,
58}