use std::{borrow::Cow, path::Path};
use specta::ResolvedTypes;
use crate::{Branded, BrandedTypeExporter, Error, Exporter, Layout};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Typescript(Exporter);
impl Default for Typescript {
fn default() -> Self {
Exporter::default().into()
}
}
impl From<Typescript> for Exporter {
fn from(value: Typescript) -> Self {
value.0
}
}
impl From<Exporter> for Typescript {
fn from(mut value: Exporter) -> Self {
value.jsdoc = false;
Self(value)
}
}
impl Typescript {
pub fn new() -> Self {
Default::default()
}
pub fn header(self, header: impl Into<Cow<'static, str>>) -> Self {
Self(self.0.header(header))
}
pub fn layout(self, layout: Layout) -> Self {
Self(self.0.layout(layout))
}
pub fn branded_type_impl(
self,
builder: impl for<'a> Fn(BrandedTypeExporter<'a>, &Branded) -> Result<Cow<'static, str>, Error>
+ Send
+ Sync
+ 'static,
) -> Self {
Self(self.0.branded_type_impl(builder))
}
pub fn export(&self, types: &ResolvedTypes) -> Result<String, Error> {
self.0.export(types)
}
pub fn export_to(&self, path: impl AsRef<Path>, types: &ResolvedTypes) -> Result<(), Error> {
self.0.export_to(path, types)
}
}
impl AsRef<Exporter> for Typescript {
fn as_ref(&self) -> &Exporter {
&self.0
}
}
impl AsMut<Exporter> for Typescript {
fn as_mut(&mut self) -> &mut Exporter {
&mut self.0
}
}