mod typescript;
use std::io::Write;
use crate::{HandlerCodegen, reflection::ty::CodegenType};
pub use self::typescript::TypeScript;
pub trait Backend<W: Write> {
type HandlerBackend: HandlerBackend<W>;
type TypeBackend: TypeBackend<W>;
const STAGES: &[BackendStage];
fn get_handler_backend(&self) -> &Self::HandlerBackend;
fn get_type_backend(&self) -> &Self::TypeBackend;
#[allow(unused)]
fn begin(&self, writer: &mut W) -> std::io::Result<()> {
Ok(())
}
#[allow(unused)]
fn end(&self, writer: &mut W) -> std::io::Result<()> {
Ok(())
}
}
pub trait HandlerBackend<W: Write> {
#[allow(unused)]
fn begin(&self, writer: &mut W) -> std::io::Result<()> {
Ok(())
}
#[allow(unused)]
fn end(&self, writer: &mut W) -> std::io::Result<()> {
Ok(())
}
fn write_key(&self, key: &str, writer: &mut W) -> std::io::Result<()>;
fn write_handler(&self, handler: &HandlerCodegen, writer: &mut W) -> std::io::Result<()>;
fn begin_nested(&self, root: bool, writer: &mut W) -> std::io::Result<()>;
fn end_nested(&self, root: bool, writer: &mut W) -> std::io::Result<()>;
}
pub trait TypeBackend<W: Write> {
#[allow(unused)]
fn begin(&self, writer: &mut W) -> std::io::Result<()> {
Ok(())
}
#[allow(unused)]
fn end(&self, writer: &mut W) -> std::io::Result<()> {
Ok(())
}
fn write_type(
&self,
name: &CodegenType,
definition: &str,
writer: &mut W,
) -> std::io::Result<()>;
}
pub enum BackendStage {
Handler,
Type,
}