gear_mesh_generator/
lib.rs

1//! gear-mesh-generator: TypeScript code generator and main API
2//!
3//! This crate provides TypeScript code generation from Rust types
4//! and serves as the main entry point for the gear-mesh library.
5
6mod branded;
7mod typescript;
8pub mod utils;
9mod validation_gen;
10
11#[cfg(test)]
12mod tests;
13
14pub use branded::BrandedTypeGenerator;
15pub use typescript::TypeScriptGenerator;
16pub use validation_gen::ValidationGenerator;
17
18// ============================================================================
19// Facade: Re-export core types for convenient access
20// ============================================================================
21
22pub use gear_mesh_core::{
23    DocComment, EnumRepresentation, EnumType, EnumVariant, FieldInfo, GearMeshType, GenericParam,
24    NewtypeType, PrimitiveType, SerdeFieldAttrs, StructType, TypeAttributes, TypeKind, TypeRef,
25    ValidationRule, VariantContent,
26};
27
28// Re-export derive macro
29pub use gear_mesh_derive::GearMesh;
30
31/// Trait for types that can be exported to TypeScript
32///
33/// This trait is automatically implemented by the `#[derive(GearMesh)]` macro.
34pub trait GearMeshExport {
35    /// Get the intermediate representation of this type
36    fn gear_mesh_type() -> GearMeshType;
37
38    /// Get the name of this type
39    fn type_name() -> &'static str;
40}
41
42// ============================================================================
43// Generator Configuration
44// ============================================================================
45
46/// 生成設定
47#[derive(Debug, Clone, Default)]
48pub struct GeneratorConfig {
49    /// BigIntを自動的に使用するか
50    pub use_bigint: bool,
51    /// Branded Typeを生成するか
52    pub generate_branded: bool,
53    /// バリデーション関数を生成するか
54    pub generate_validation: bool,
55    /// Zodスキーマを生成するか
56    pub generate_zod: bool,
57    /// JSDocを生成するか
58    pub generate_jsdoc: bool,
59    /// インデント文字列
60    pub indent: String,
61}
62
63impl GeneratorConfig {
64    pub fn new() -> Self {
65        Self {
66            use_bigint: true,
67            generate_branded: true,
68            generate_validation: false,
69            generate_zod: false,
70            generate_jsdoc: true,
71            indent: "    ".to_string(),
72        }
73    }
74
75    pub fn with_bigint(mut self, use_bigint: bool) -> Self {
76        self.use_bigint = use_bigint;
77        self
78    }
79
80    pub fn with_branded(mut self, generate: bool) -> Self {
81        self.generate_branded = generate;
82        self
83    }
84
85    pub fn with_validation(mut self, generate: bool) -> Self {
86        self.generate_validation = generate;
87        self
88    }
89
90    pub fn with_zod(mut self, generate: bool) -> Self {
91        self.generate_zod = generate;
92        self
93    }
94
95    pub fn with_jsdoc(mut self, generate: bool) -> Self {
96        self.generate_jsdoc = generate;
97        self
98    }
99}