fix(orm): export UncheckedCreateInput/CheckedCreateInput and add XOR to UpdateInput#2627
Conversation
…to UpdateInput (#2567) - Export `UncheckedCreateInput` and `CheckedCreateInput` as public types so users can use `Partial<ModelUncheckedCreateInput>` in builder/factory patterns without hitting the XOR type error when spreading alongside an explicit FK field - Apply the same XOR pattern to `UpdateInput` for consistency with create - Export `UncheckedUpdateInput` and `CheckedUpdateInput` as public types - Add non-owned relation fields to `UncheckedUpdateInput` (mirrors create behavior where non-owned relations are valid in both the unchecked and checked branches) - Emit the four new input types in ts-schema-generator's input.ts output - Add regression test for issue #2567 - Add e2e tests for runtime and type-level XOR enforcement on create/update Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR splits Create/Update input types into exported "unchecked" (FK-scalar) and "checked" (relation-object) variants, makes Create/Update inputs an XOR between those variants, updates the TS schema generator to emit model-scoped aliases, and adds compile-time and runtime tests validating the checked/unchecked behavior. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
|
Claude finished @ymc9's task —— View job PR Review AnalysisReviewing PR #2627: Export UncheckedCreateInput/CheckedCreateInput and add XOR to UpdateInput Todo List:
Review FeedbackThis PR addresses a real TypeScript issue with XOR union collapse when using ✅ Strengths1. Sound Technical Solution
2. Excellent Type Safety Improvements
3. Comprehensive Test Coverage
📝 Code Quality Observations1. Implementation Details (
2. Schema Generator Updates (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/orm/src/client/crud-types.ts`:
- Around line 1654-1657: UpdateManyPayload.data currently only allows
UpdateScalarInput<Schema, Model> which excludes ForeignKeyFields; change it to
also accept FK updates by widening the type to match the
CreateManyPayload/UpdateInput pattern — e.g. replace the single
UpdateScalarInput usage in UpdateManyPayload.data with a union (or the
UncheckedUpdateInput equivalent) that includes the FK payload type
(UpdateFKPayload or CreateFKPayload style) so ForeignKeyFields<Schema, Model>
are accepted during updateMany; update the type alias referenced as
UpdateManyPayload.data and ensure consistency with CreateManyPayload.data and
UpdateInput.
In `@tests/regression/test/issue-2567/regression.test.ts`:
- Around line 1-36: Rename the test file currently named regression.test.ts to
issue-2567.test.ts so it follows the regression-test naming convention; keep the
file in the same tests/regression/test directory and ensure any imports or CI
patterns that reference the old filename are updated if necessary so the suite
remains discoverable as the regression test for issue `#2567`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4fa7d3b1-0ff0-4b49-a9f9-0595e3155247
📒 Files selected for processing (11)
packages/orm/src/client/crud-types.tspackages/sdk/src/ts-schema-generator.tstests/e2e/orm/client-api/checked-unchecked.test-d.tstests/e2e/orm/client-api/checked-unchecked.test.tstests/e2e/orm/client-api/update.test.tstests/e2e/orm/schemas/basic/input.tstests/regression/test/issue-2567/input.tstests/regression/test/issue-2567/models.tstests/regression/test/issue-2567/regression.test.tstests/regression/test/issue-2567/schema.tstests/regression/test/issue-2567/schema.zmodel
|
Claude finished @ymc9's task —— View job PR Review AnalysisReviewing PR #2627: Export UncheckedCreateInput/CheckedCreateInput and add XOR to UpdateInput Todo List:
Review FeedbackThis PR addresses a real TypeScript issue with XOR union collapse when using ✅ Strengths1. Sound Technical Solution
2. Excellent Type Safety Improvements
3. Comprehensive Test Coverage
📝 Code Quality Observations1. Implementation Details (
2. Schema Generator Updates (
|
Fixes #2567
Problem
Spreading
Partial<PostCreateArgs['data']>alongside an explicit FK field caused a TypeScript error becauseCreateArgs['data']is an XOR union — its exclusive keys become?: neverin each branch, andPartial<XOR<A,B>>collapses that to?: T | undefinedwhich is not assignable to?: never.Solution
Export the two halves of the XOR as standalone public types (mirroring Prisma 6):
UncheckedCreateInput— scalars + FK fields + non-owned relations (no relation objects)CheckedCreateInput— scalars + relation objects (no FK fields)Users can now write
Partial<PostUncheckedCreateInput>for builder/factory patterns while the XOR onCreateArgs['data']still enforces mutual exclusion at the call site.The same pattern is applied to update operations:
UncheckedUpdateInput— scalars + FK fields + non-owned relationsCheckedUpdateInput— scalars + relation objectsUpdateInputnow also uses XOR (previously it did not enforce mutual exclusion between FK fields and relation objects).All four new types are emitted in
input.tsby the TypeScript schema generator.Changes
packages/orm/src/client/crud-types.ts— export four new public types; wireUpdateInputthrough XOR; addUpdateNonOwnedRelationInputso non-owned relations (e.g.Post.comments) appear in both XOR branchespackages/sdk/src/ts-schema-generator.ts— add the four new types to theinputTypeslist so they are emitted ininput.tstests/regression/test/issue-2567/— regression test for the original bugtests/e2e/orm/client-api/checked-unchecked.test.ts— runtime tests verifying mixed FK+relation payloads are rejectedtests/e2e/orm/client-api/checked-unchecked.test-d.ts— type-level tests verifying XOR enforcement and correct shapes of the new exported typesTest plan
tests/regression/test/issue-2567/regression.test.tspasses —Partial<PostUncheckedCreateInput>spread works at runtime and compile timetests/e2e/orm/client-api/checked-unchecked.test.tspasses — runtime rejects mixed FK+relation payloads in create and updatetests/e2e/orm/client-api/checked-unchecked.test-d.tspasses — type-level XOR enforcement verified for create and updatetests/e2e/orm/client-api/update.test.tspasses — no regressions in existing update tests🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests