1mod codegen;
2pub mod convex;
3pub mod errors;
4
5use std::path::PathBuf;
6
7use codegen::generate_code;
8use convex::{create_functions_ast, create_schema_ast, parse_function_ast, parse_schema_ast};
9use errors::ConvexTypeGeneratorError;
10
11#[derive(Debug, Clone)]
13pub struct Configuration
14{
15 pub schema_path: PathBuf,
17
18 pub out_file: String,
20
21 pub function_paths: Vec<PathBuf>,
23}
24
25impl Default for Configuration
26{
27 fn default() -> Self
28 {
29 Self {
30 schema_path: PathBuf::from("convex/schema.ts"),
31 out_file: "src/convex_types.rs".to_string(),
32 function_paths: Vec::new(),
33 }
34 }
35}
36
37pub fn generate(config: Configuration) -> Result<(), ConvexTypeGeneratorError>
53{
54 if !config.schema_path.exists() {
55 return Err(ConvexTypeGeneratorError::MissingSchemaFile);
56 }
57
58 let schema_path = config
59 .schema_path
60 .canonicalize()
61 .map_err(|e| ConvexTypeGeneratorError::IOError {
62 file: config.schema_path.to_string_lossy().to_string(),
63 error: e,
64 })?;
65
66 let schema_ast = create_schema_ast(schema_path)?;
67 let functions_ast = create_functions_ast(config.function_paths)?;
68
69 let parsed_schema = parse_schema_ast(schema_ast)?;
70 let parsed_functions = parse_function_ast(functions_ast)?;
71
72 generate_code(&config.out_file, (parsed_schema, parsed_functions))?;
73
74 Ok(())
75}