refactor(codegen): generic type params for CLI→ORM bridge + flip condition default to false#926
Closed
pyramation wants to merge 4 commits intomainfrom
Closed
refactor(codegen): generic type params for CLI→ORM bridge + flip condition default to false#926pyramation wants to merge 4 commits intomainfrom
pyramation wants to merge 4 commits intomainfrom
Conversation
…M type compatibility The ORM's findMany/findFirst methods require typed args with a required 'select' property, but the CLI runtime helpers return Record<string, unknown>. Adding 'as any' casts in the generated code prevents TS2345 errors when the generated CLI is compiled against the typed ORM client.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…arseFindManyArgs/parseFindFirstArgs Instead of casting ORM args to 'any', the helpers are now generic: parseFindManyArgs<T>() / parseFindFirstArgs<T>() The codegen passes specific table types: parseFindManyArgs<FindManyArgs<CarSelect, CarFilter, CarCondition, CarsOrderBy>>(...) This gives proper type safety at the ORM call site without escape hatches. The internal 'as unknown as T' cast in the helpers is the single known bridge between the untyped CLI argv layer and the typed ORM interface.
as any for CLI→ORM type bridge
…first-class, condition is opt-in - Change all condition checks from `!== false` to `=== true` (8 locations) - Flip function parameter defaults from `= true` to `= false` - Thread config.codegen.condition through CLI codegen TableCommandOptions - Update tests that explicitly test condition types to pass condition: true - Update snapshots to reflect condition-disabled output
as any for CLI→ORM type bridge… params
The ORM's findMany/findFirst methods require select to be present
(via intersection & { select: SelectType }). parseFindManyArgs always
sets select at runtime, but the generic type parameter only had
FindManyArgs<...> where select is optional.
Fix: generate FindManyArgs<...> & { select: SelectType } as the
type parameter, making the type match what the ORM expects.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes TS2345 build errors in the generated CLI code (e.g.
sdk/constructive-cli) whereparseFindManyArgs()/parseFindFirstArgs()returnRecord<string, unknown>but the ORM'sfindMany/findFirstmethods expect typed args with a requiredselectproperty.Instead of casting at the ORM call sites (
findManyArgs as any), the helpers are now generic and the codegen passes table-specific type parameters:What changed
cli-utils.ts(template):parseFindManyArgs<T>()andparseFindFirstArgs<T>()are now generic withT = Record<string, unknown>default. Internally usesas unknown as T— this is the single controlled bridge between the untyped CLI argv layer and the typed ORM interface.table-command-generator.ts(codegen):buildFindManyArgsType()/buildFindFirstArgsType()helpers construct the properFindManyArgs<Select, Filter, Condition, OrderBy>/FindFirstArgs<Select, Filter, Condition>type instantiations per tablebuildListHandler,buildFindFirstHandler,buildSearchHandler*Select,*Filter,*Condition,*OrderBy) frominput-typesandFindManyArgs/FindFirstArgsfromselect-typescondition?: booleantoTableCommandOptions— no longer hardcodedCondition default flipped to
false(opt-in):where/filteris now the first-class filtering mechanism;condition(PostGraphile simple equality filters) is opt-in. To enable condition types, setconfig.codegen.condition: trueexplicitly.All 8 locations where condition was checked have been flipped from
!== false(default true) to=== true(default false):codegen/index.ts— hooks generatorcodegen/orm/index.ts— ORM generatorcodegen/orm/model-generator.ts— model generatorcodegen/orm/input-types-generator.ts— input types generatorcodegen/cli/table-command-generator.ts— CLI table command generatorcodegen/cli/index.ts— CLI single-target and multi-target generatorscodegen/queries.ts— query hook destructuring defaultgenerate.ts— multi-target pipelineWhen condition is disabled (the new default), the generated code uses
neveras the condition type parameter, effectively making it unusable at the type level.Review & Testing Checklist for Human
codegen.condition: true. Verify no downstream consumers are broken by this default flipFindManyArgsandFindFirstArgsare exported fromselect-typeswith the expected generic parameters<Select, Filter, Condition, OrderBy>and<Select, Filter, Condition>respectively — the generated imports depend on thisas unknown as Tcast inside the helpers is acceptable — it's architecturally cleaner thanas anyat every call site but is still an escape hatch at the argv→ORM boundarysdk/constructive-clibuilds successfully (the generated code will now have these new imports, type parameters, and no condition types by default)codegen.condition: truestill generates condition types correctly (the updated tests cover this but a real-world config is worth verifying)Notes
as anyfrom ORM call sites, condition type interfaces removed from default output{ condition: true }to the generators, reflecting the new opt-in behaviorbuildListHandler,buildFindFirstHandler,buildSearchHandleralso flipped from= trueto= falseLink to Devin session: https://app.devin.ai/sessions/c92c3a11450342f8875625a60fa1be28
Requested by: @pyramation