Skip to content

Conversation

@pyramation
Copy link
Contributor

Summary

This PR completes the migration of all ORM code generators from ts-morph to Babel AST (@babel/types + @babel/generator). This follows the React Query codegen migration in PR #611.

Files converted to Babel AST:

  • orm/input-types-generator.ts - generates TypeScript interfaces for filters, CRUD inputs, and payload types
  • orm/model-generator.ts - generates model classes with findMany, findFirst, create, update, delete methods
  • orm/barrel.ts - generates index.ts barrel exports
  • orm/custom-ops-generator.ts - generates custom query/mutation operation factories
  • orm/client-generator.ts - generates createClient factory function
  • types.ts - generates entity interfaces and filter types

Removed:

  • ts-ast.ts - no longer needed
  • ts-morph dependency from package.json

All 135 tests pass with 56 snapshots updated to match Babel AST output format.

Review & Testing Checklist for Human

  • Run the ORM codegen example to verify generated code is correct: pnpm example:codegen:orm or pnpm example:codegen:orm:schema
  • Verify complex type generation - check that union types, arrays, and generic type parameters are correctly generated in the output
  • Test generated ORM against a real endpoint - the unit tests validate snapshot output but don't test runtime behavior
  • Review parseTypeAnnotation function in custom-ops-generator.ts (lines 136-154) - this does string parsing to convert type strings to AST nodes and may have edge cases

Recommended test plan:

  1. Run pnpm example:codegen:orm:schema to generate ORM code from the example schema
  2. Inspect the generated files in examples/output/generated-orm-schema/
  3. Compare key files (input-types.ts, models/*.ts, index.ts) against expected structure

Notes

The static runtime code in client-generator.ts (OrmClient class, QueryBuilder class, select-types) still uses template strings since this is runtime code that doesn't change based on schema - this is intentional.

Link to Devin run: https://app.devin.ai/sessions/4d5df52ad251452da815b8cb06618596
Requested by: @pyramation

yyyyaaa and others added 9 commits January 14, 2026 13:51
…tion

- Add babel-ast.ts helper file with reusable AST builders for:
  - Export const declarations with object literals
  - Object properties with string/array/function values
  - Arrow function expressions with parameters
  - TSAsExpression for 'as const'
  - Type aliases and imports
  - Block statements with conditionals
  - JSDoc and line comments using Babel's comment system

- Rewrite query-keys.ts using pure Babel AST (@babel/types + @babel/generator)
- Rewrite mutation-keys.ts using pure Babel AST
- Rewrite invalidation.ts using pure Babel AST

- Add @babel/generator, @babel/types, @types/babel__generator dependencies
- Update snapshots to match Babel generator output

All code generation now uses AST nodes instead of string concatenation.
Prettier formatting is applied at file-write time in the CLI pipeline.
…arrel to pure Babel AST

- Remove unnecessary helper abstractions from babel-ast.ts
- Use raw t.* calls instead of wrapper functions
- Convert barrel.ts from string concatenation to Babel AST
- Fix if statement formatting to use block statements
- All 102 tests pass
- Rewrite queries.ts with pure Babel AST (replace ts-morph)
- Rewrite mutations.ts with pure Babel AST (replace ts-morph)
- Rewrite custom-queries.ts with pure Babel AST (replace ts-morph)
- Rewrite custom-mutations.ts with pure Babel AST (replace ts-morph)
- Rewrite schema-types-generator.ts with pure Babel AST
- Update type-resolver.ts to remove ts-ast dependency (keep ts-ast.ts for ORM generators)

All 102 tests pass, all 23 snapshots pass.
…generators

Add 33 new snapshot tests covering:
- Query hooks (list/single) with/without centralized keys
- Mutation hooks (create/update/delete) with/without centralized keys
- Custom query hooks with/without arguments
- Custom mutation hooks with various argument types
- Schema types generator
- Barrel file generators (queries, mutations, main, custom)
…en' into devin/1768387040-orm-babel-migration
- Convert orm/input-types-generator.ts to pure Babel AST
- Convert orm/model-generator.ts to pure Babel AST
- Convert orm/barrel.ts to pure Babel AST
- Convert orm/custom-ops-generator.ts to pure Babel AST
- Convert orm/client-generator.ts to pure Babel AST
- Convert types.ts to pure Babel AST
- Delete ts-ast.ts (no longer needed)
- Remove ts-morph dependency from package.json
- Update snapshots to match Babel AST output format
- All 135 tests pass, all 56 snapshots pass
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit da84ee8 into main Jan 14, 2026
36 checks passed
@pyramation pyramation deleted the devin/1768387040-orm-babel-migration branch January 14, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants