Expand description
§crdt-codegen
Code generation from TOML schema definitions for crdt-kit.
Reads a crdt-schema.toml file and generates a complete persistence layer
organized for Clean Architecture / Hexagonal Architecture:
models/— Versioned Rust structs with#[crdt_schema]annotationsmigrations/— Migration functions with#[migration]annotations + helpersrepositories/— Repository traits (ports) andCrdtDb-backed implementations (adapters)store.rs— UnifiedPersistence<S>entry point with scoped repository accessevents/— Event sourcing types, snapshots, and policies (optional)sync/— Delta sync and state-based merge helpers for CRDT entities (optional)
All generated files contain a header marking them as auto-generated.
§Example
use crdt_codegen::generate_from_str;
let toml = r#"
[config]
output = "src/persistence"
[[entity]]
name = "Task"
table = "tasks"
[[entity.versions]]
version = 1
fields = [
{ name = "title", type = "String" },
{ name = "done", type = "bool" },
]
"#;
let output = generate_from_str(toml).unwrap();
assert_eq!(output.output_dir, "src/persistence");
assert!(!output.files.is_empty());Modules§
Structs§
- Entity
- A single entity definition with one or more versioned schemas.
- Entity
Version - A specific version of an entity’s schema.
- Field
- A single field within an entity version.
- Generated
File - A single generated file ready to be written to disk.
- Generated
Output - The complete output of the code-generation process.
- Schema
Config - Global code-generation configuration.
- Schema
File - Top-level schema file structure parsed from
crdt-schema.toml. - Validation
Error - A single validation error with context about where it occurred.
Enums§
- Codegen
Error - Error type for the code-generation process.
Functions§
- generate
- Parse a TOML schema file from disk and generate all code.
- generate_
from_ schema - Generate code from an already-parsed schema.
- generate_
from_ str - Parse a TOML string and generate all code.
- validate_
schema - Validate a parsed schema file. Returns
Ok(())if valid, or a list of errors.