-
Notifications
You must be signed in to change notification settings - Fork 0
feat: v0.2 — template-driven real handlers in generateRoutes() #3
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem
generateRoutes() currently emits stub handlers:
lines.push(` // TODO: implement ${routeName} handler`);
lines.push(` return c.json({ status: 'ok' });`);Specs pass but handlers are hollow. No DB queries, no response shaping, no error handling. This blocks FoodFiles domain contracts (Stackbilt-dev/foodfilesapi_v2#23) from producing usable code.
Decided Approach: Handlebars-style string templates
Per prior architecture decision:
- Template files under
src/generators/templates/with placeholders ({{contractName}},{{inputSchema}},{{refImports}}, etc.) - Zod walker builds a context object, feeds it to templates
- Generated handler bodies include:
req.bodyvalidation against Zod schema (already done)- DB queries via
surfaces.dbhelpers (db.prepare().bind().run()for D1) - Standard success/error response shaping (try/catch with
errorResponse()envelope) - State transition guards from
contract.states - Authority middleware from
contract.authority(already done)
- Prettier pass on output
Why Templates (Not AST)
- Speed: instant iteration on contract definitions
- Auditability: deterministic, diffable output
- Low risk: no complex AST transforms — aligns with speed + rigor
AST-based generation (ts-morph) is v0.3, gated on template coverage ≥ 90%.
Scope
Must have (v0.2)
- Route template: CRUD handler bodies (create, read, update, delete, list)
- Route template: state transition operations (e.g.,
publish,archive) - DB query generation from
surfaces.db.table+ schema columns -
ref()→ JOIN clause generation - Error handling: try/catch with structured error response
- Test harness: generated code compiles, zero TODO markers
Also fix
-
generateSQL()— validate against FoodFiles migration 001 (recipe/org tables) -
generateSDK()— fix syntax bug (unmatched paren line 72) -
generateTests()— emit integration tests that hit handlers, not just schema validation
Validation Target
Write RecipeContract (state machine: draft→published→archived, refs to Organization + User, invariant: published requires ingredients). Run all generators. Diff SQL against FoodFiles 001_fresh_multitenant_schema.sql.
Roadmap
| Version | Approach | Status |
|---|---|---|
| v0.1 | Stub handlers | Done |
| v0.2 | Template-driven real handlers | This issue |
| v0.3 | AST-based generation (ts-morph) | Planned |
| v0.4 | CI integration + no-TODO lint rule | Planned |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request