Skip to main content

greentic_dev/dev_runner/
registry.rs

1use std::collections::HashMap;
2
3use serde_yaml_bw::Value as YamlValue;
4
5#[derive(Clone, Debug)]
6pub struct ComponentStub {
7    pub schema: String,
8    pub defaults: YamlValue,
9}
10
11#[derive(Clone, Debug)]
12pub struct DescribeRegistry {
13    stubs: HashMap<String, ComponentStub>,
14}
15
16impl DescribeRegistry {
17    pub fn new() -> Self {
18        let mut stubs = HashMap::new();
19        let defaults: YamlValue = serde_yaml_bw::from_str(
20            r#"
21component: oauth
22inputs:
23  client_id: null
24  client_secret: null
25  scopes: []
26"#,
27        )
28        .expect("static oauth defaults");
29
30        stubs.insert(
31            "oauth".to_string(),
32            ComponentStub {
33                schema: r#"{"$id":"https://greentic-ai.github.io/component-oauth/schemas/v1/oauth.node.schema.json","type":"object"}"#.to_string(),
34                defaults,
35            },
36        );
37        Self { stubs }
38    }
39
40    pub fn get_schema(&self, name: &str) -> Option<&str> {
41        self.stubs.get(name).map(|stub| stub.schema.as_str())
42    }
43
44    pub fn get_defaults(&self, name: &str) -> Option<&YamlValue> {
45        self.stubs.get(name).map(|stub| &stub.defaults)
46    }
47
48    pub fn iter(&self) -> impl Iterator<Item = (&str, &ComponentStub)> {
49        self.stubs.iter().map(|(name, stub)| (name.as_str(), stub))
50    }
51}
52
53impl Default for DescribeRegistry {
54    fn default() -> Self {
55        Self::new()
56    }
57}