Skip to main content

seam_server/
manifest.rs

1/* packages/server/core/rust/src/manifest.rs */
2
3use std::collections::BTreeMap;
4
5use serde::Serialize;
6
7use crate::procedure::{ProcedureDef, SubscriptionDef};
8
9#[derive(Serialize)]
10pub struct Manifest {
11  pub version: String,
12  pub procedures: BTreeMap<String, ProcedureSchema>,
13}
14
15#[derive(Serialize)]
16pub struct ProcedureSchema {
17  #[serde(rename = "type")]
18  pub proc_type: String,
19  pub input: serde_json::Value,
20  pub output: serde_json::Value,
21}
22
23pub fn build_manifest(procedures: &[ProcedureDef], subscriptions: &[SubscriptionDef]) -> Manifest {
24  let mut map = BTreeMap::new();
25  for proc in procedures {
26    map.insert(
27      proc.name.clone(),
28      ProcedureSchema {
29        proc_type: "query".to_string(),
30        input: proc.input_schema.clone(),
31        output: proc.output_schema.clone(),
32      },
33    );
34  }
35  for sub in subscriptions {
36    map.insert(
37      sub.name.clone(),
38      ProcedureSchema {
39        proc_type: "subscription".to_string(),
40        input: sub.input_schema.clone(),
41        output: sub.output_schema.clone(),
42      },
43    );
44  }
45  Manifest { version: "0.1.0".to_string(), procedures: map }
46}