Refactor crate::generate::Generator per-target emission into modules #59
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_rpc#59
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Follow-up from #56. The agent who modularized
build/build.rsflagged (comment 33741) that per-target code emission (rust_types,rust_rpc,openrpc,js,rhai) does not live inbuild.rs— it lives incrate::generate::Generator. #56 was scoped "no behaviour change," so the per-target split couldn't be done there.This issue tracks splitting
Generatoritself.Goal
Extract per-target emission from the monolithic
crate::generate::Generatorinto focused modules, one per output target:generate/rust_types.rs— Rust struct/enum emission from OSchema typesgenerate/rust_server.rs— OSIS server handler emissiongenerate/rust_rpc.rs— RPC trait + handler emission (will need updating again once hero_rpc2 macro path lands in #55)generate/openrpc.rs— OpenRPC 1.3.2 spec emissiongenerate/js.rs— JS/TS SDK class emissiongenerate/rhai.rs— Rhai binding emissiongenerate/python.rs— Python SDK emission (new target per #55; empty stub for now if hero_rpc2 work hasn't added the Python codegen yet)Keep
Generatoritself as a thin orchestrator that loads schemas, picks targets per the build config, and dispatches to the per-target modules.Constraints
recipe_serverandpetstore_servermust build unchanged.Generatorstays stable.Out of scope
python.rsplaceholder.build/build.rsfurther (handled in #56).Acceptance
crates/generator/src/generate/exceeds ~500 LOC.cargo build,cargo test,cargo clippyall green.example/recipe_serverandexample/petstore_*build unchanged.Generator::from_dir,Generator::generate, etc.) unchanged.Related
build.rssplit.generator/src/build/build.rs#56Status: implementation complete, branch
issue-59-generate-modularSingle commit
9b1d6b4: pure refactor, no behaviour change.Layout —
crates/generator/src/generate/mod.rsGeneratorstruct, builders,generate()dispatch,GenerationResult, helpers, testsrust_types.rstypes_generated.rs,types_wasm_generated.rs,types.rswrapper, domain coremod.rsrust_server.rsosis_server_generated.rs, optionalserver/mod.rs(nested layout)rust_rpc.rsosis_client_generated.rs+ clientmod.rs). hero_rpc2 lives inbuild::emit::rust_rpc2openrpc.rsopenrpc.json(shared helper for core + server dirs)js.rstypes_generated.jsrhai.rsrhai_types_generated.rspython.rsbuild::emit::python_sdkexamples.rsbasic_crudexample +run.sh+READMEscaffoldinge2e.rsclient_server.rsTokio exampletests_emit.rstests.rsCRUD round-trip generationwasm_build_script.rs#[allow(dead_code)]WASM packaging helper, isolatedAll files ≤ 500 LOC ✓.
Pattern
Per-target methods use
impl super::Generator { pub(in crate::generate) fn ... }blocks across sibling modules. Generator fields arepub(in crate::generate)so submodules can read them. Shared helpers (to_pascal_case,to_snake_case,write_file) stay inmod.rs.openrpc::write_openrpc_jsonandrhai::write_rhai_typesare free functions because bothrust_types.rsandrust_server.rsinvoke openrpc.Acceptance
crates/generator/src/generate/exceeds ~500 LOC (largest:mod.rsat 470).cargo buildgreen (workspace).cargo test -p hero_rpc_generator --lib: 125 passed, 1 ignored.example/recipe_serverandexample/petstore_serverbuild unchanged.build::emit::rust_sdk,build::emit::domain,build::scaffold,build::configall still compile against the sameGenerator::from_dir/.core/.server/.client/.js/.rhai/.tests/.e2e_examples/.nested_layout/.server_output_dir/.sdk_output_dir/.client_only/.client_types_crate/.debug/.generate()API.Byte-for-byte verification
Notes
clippy::too_many_argumentsandclippy::items_after_test_moduleerrors inbuild/emit/python_sdk.rsandbuild/scaffold.rs(from #54/#60) remain — confirmed they reproduce ondevelopment. Out of scope for #59.cargo fmt --checkflags pre-existing formatting inbuild/emit/python_sdk.rs; also pre-existing ondevelopment.generate/itself is fmt-clean.Ready for review. PR can target
development.