fix(orm): make orderBy nulls optional#2670
Conversation
Prisma's `SortOrderInput` defines `nulls` as optional, but ZenStack's
Zod schema required it, causing valid inputs like
`orderBy: { name: { sort: 'asc' } }` to be rejected by validation.
- Make `nulls` optional in the orderBy Zod schema
- Handle the `nulls`-less object form in `applyScalarOrderBy`
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughMakes ChangesOptional nulls in orderBy
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 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. Comment |
|
Claude finished @ymc9's task —— View job Code Review: Make orderBy
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/orm/src/client/crud/dialects/base-dialect.ts`:
- Around line 1240-1246: The conditional that checks sort on the incoming value
can throw when value is null; update the if-condition in the method in
BaseDialect to guard against null by adding value !== null before using 'in' and
property accesses (so the branch that calls this.negateSort(value.sort, negated)
and either this.buildOrderByField(query, fieldRef, sort, value.nulls) or
query.orderBy(fieldRef, sort) only runs when value is not null). Locate the
block that references negateSort, buildOrderByField, and query.orderBy and
modify the predicate to include value !== null while preserving existing checks
for value.sort and value.nulls.
🪄 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: a29adcc7-1247-43d3-8f21-e9b2be235c8d
📒 Files selected for processing (3)
packages/orm/src/client/crud/dialects/base-dialect.tspackages/orm/src/client/zod/factory.tstests/e2e/orm/client-api/find.test.ts
nulls optional to match Prisma's SortOrderInputnulls optional
|
Claude finished @ymc9's task —— View job Code Review: Make orderBy
|
|
Claude finished @ymc9's task —— View job Code Review: Make orderBy
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/e2e/orm/client-api/find.test.ts`:
- Around line 150-155: The test currently asserts that
client.user.findFirst({...}).resolves.toBeDefined(), which would incorrectly
pass if the result is null; replace the assertion with the stronger custom
matcher toResolveTruthy() so the promise must resolve to a truthy user. Locate
the call to client.user.findFirst with orderBy: { name: { sort: 'desc' } } and
change the expectation from .resolves.toBeDefined() to .toResolveTruthy() to
match the suite's pattern.
🪄 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: af073876-324a-4f95-a928-a226553258bd
📒 Files selected for processing (1)
tests/e2e/orm/client-api/find.test.ts
Summary
SortOrderInputdefinesnullsas optional, but ZenStack's Zod schema required it, so valid inputs likeorderBy: { name: { sort: 'asc' } }were rejected by validation before reaching the dialect.nullsoptional in the orderBy Zod schema.applyScalarOrderByin the base dialect to handle thenulls-less object form by falling back toquery.orderBy(fieldRef, sort).Test plan
tests/e2e/orm/client-api/find.test.tscoveringorderBy: { name: { sort: 'desc' } }.pnpm vitest run orm/client-api/find.test.ts— all 18 tests pass.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
orderBynow allows omitting thenullsoption for optional scalar fields.Chores
thresholdis now optional andunaccentis required.Tests
nullsis omitted.