Skip to content

merge dev to main (v3.5.6)#2566

Merged
ymc9 merged 4 commits intomainfrom
dev
Apr 7, 2026
Merged

merge dev to main (v3.5.6)#2566
ymc9 merged 4 commits intomainfrom
dev

Conversation

@ymc9
Copy link
Copy Markdown
Member

@ymc9 ymc9 commented Apr 7, 2026

Summary by CodeRabbit

  • New Features

    • Added configurable page parameter type support for infinite queries in TanStack Query clients (React, Vue, Svelte).
  • Bug Fixes

    • Fixed DISTINCT ON behavior to automatically prepend distinct fields to ORDER BY when necessary.
    • Enhanced orderBy validation to enforce single-field objects, improving query clarity.
  • Chores

    • Version bump to 3.5.6 across all packages.

github-actions bot and others added 4 commits April 6, 2026 13:14
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
…tibility (#2562)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>
…FindMany (#2561)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 7, 2026

Claude finished @ymc9's task —— View job


Code Review Analysis

Reviewing PR #2566 (dev → main, v3.5.6) for code quality, bugs, performance, security, and test coverage.

Tasks:

  • Analyze key code changes (non-version bumps)
  • Review tanstack-query changes (React, Svelte, Vue)
  • Review ORM package changes
  • Check new regression test
  • Assess code quality and best practices
  • Look for potential bugs and security issues
  • Evaluate performance considerations
  • Provide comprehensive feedback

Review Summary

This is a solid release merge with several important fixes and improvements. The changes focus on TanStack Query integration improvements and PostgreSQL DISTINCT ON compatibility.

Key Findings

Positive Changes

  1. TanStack Query Generic Propagation Fix (packages/clients/tanstack-query/src/*.ts)

    • Issue: Fixed TPageParam generic propagation through useInfiniteFindMany hooks across React, Svelte, and Vue
    • Quality: Clean implementation with consistent pattern across all three frameworks
    • Testing: Proper type tests added for all frameworks
  2. PostgreSQL DISTINCT ON Compatibility (packages/orm/src/client/crud/dialects/base-dialect.ts:153-165)

    • Issue: Addresses PostgreSQL requirement that DISTINCT ON expressions match leftmost ORDER BY expressions
    • Implementation: Smart logic to prepend distinct fields to ORDER BY only when needed
    • Test Coverage: Comprehensive regression test in tests/regression/test/issue-2529.test.ts
  3. Optional Typed-JSON Field Mutation (packages/orm/src/client/zod/factory.ts)

    • Enhancement: Better handling of array mutation shapes for optional typed-JSON fields
    • Robustness: Preserves existing mutation operations (set, push, etc.)

🎯 Strengths

  • Type Safety: All changes maintain strict TypeScript typing
  • Framework Consistency: TanStack Query changes applied uniformly across React/Svelte/Vue
  • Backward Compatibility: No breaking changes detected
  • Test Coverage: New regression test covers edge cases well
  • Database Compatibility: Proper handling of PostgreSQL-specific requirements

⚠️ Minor Observations

  1. Code Complexity: The DISTINCT ON logic in base-dialect.ts:153-165 is complex but necessary for PostgreSQL compatibility. The logic is well-commented.

  2. Type Casting: Some as any usage in TanStack Query implementations, but this appears necessary for framework integration patterns.

Security Assessment

No security concerns identified

  • No credential exposure
  • No injection vulnerabilities
  • Proper input validation maintained
  • No unsafe type assertions

Performance Considerations

Performance neutral to positive

  • DISTINCT ON fix may improve PostgreSQL query performance by avoiding unnecessary sorting
  • TanStack Query improvements maintain existing performance characteristics
  • No N+1 query risks introduced

Test Coverage

Excellent test coverage

  • New regression test comprehensively covers DISTINCT ON scenarios
  • Type tests ensure generic propagation works correctly
  • Existing test suite maintained

Code Quality

High quality changes

  • Consistent coding patterns
  • Proper error handling
  • Clear variable naming
  • Appropriate comments for complex logic

Recommendation

✅ APPROVE - This is a well-executed release merge with important bug fixes and no significant issues identified.

Minor Suggestions

  1. Documentation: Consider adding a brief comment in the TanStack Query files explaining why TPageParam propagation was needed
  2. Monitoring: Keep an eye on the PostgreSQL DISTINCT ON logic in production to ensure it handles all edge cases

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

📝 Walkthrough

Walkthrough

Patch release 3.5.6 updates all package versions and introduces type safety improvements for TanStack Query infinite queries with configurable page-parameter generics. ORM query construction is enhanced to properly align DISTINCT ON with ORDER BY fields, and orderBy validation restricts objects to single keys.

Changes

Cohort / File(s) Summary
Version Bumps
package.json, packages/*/package.json, tests/*/package.json, samples/orm/package.json
All package manifests incremented from version 3.5.5 to 3.5.6.
TanStack Query Infinite Query Types
packages/clients/tanstack-query/src/react.ts, packages/clients/tanstack-query/src/svelte/index.svelte.ts, packages/clients/tanstack-query/src/vue.ts
Added generic TPageParam = unknown to ModelInfiniteQueryOptions, useInfiniteFindMany, and internal infinite-query hook functions. Updated type threading through InfiniteData<T, TPageParam> and UseInfiniteQueryOptions. Svelte version also made args parameter optional and adjusted control flow.
TanStack Query Infinite Query Tests
packages/clients/tanstack-query/test/react-typing.test-d.ts, packages/clients/tanstack-query/test/svelte-typing-test.ts, packages/clients/tanstack-query/test/vue-typing-test.ts
Added type assertions validating TPageParam inference from getNextPageParam callback return types and pageParams array access.
ORM DISTINCT ON & ORDER BY Handling
packages/orm/src/client/crud/dialects/base-dialect.ts
Reordered query construction in buildFilterSortTake: now computes distinct fields first, prepends them to orderBy only when supportsDistinctOn is true and distinct fields don't already lead the sort order, and uses the adjusted effectiveOrderBy in subsequent operations including cursor filter construction.
ORM orderBy Validation
packages/orm/src/client/zod/factory.ts
Introduced refineAtMostOneKey refinement to validate that each orderBy object contains at most one key. Applied to scalar and nested/extended relation schemas.
ORM & E2E Tests
tests/regression/test/issue-2529.test.ts, tests/e2e/orm/client-api/find.test.ts
Added regression test for DISTINCT/ORDER BY field ordering scenarios. Removed multi-key orderBy test and replaced with validation assertions rejecting orderBy objects with multiple keys.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #2541: Modifies the same packages/orm/src/client/crud/dialects/base-dialect.ts file, adding buildComparison logic that may interact with the buildFilterSortTake changes in this PR.

Poem

🐰 Hop hop, the version's bumped so bright,
Page params now generic, types align just right,
DISTINCT fields dance with ORDER BY's grace,
No multi-key chaos in this ordered place!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly indicates this is a version release (v3.5.6) merging dev to main, accurately reflecting the changeset's primary purpose of releasing a new version.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/clients/tanstack-query/src/vue.ts (1)

543-550: ⚠️ Potential issue | 🔴 Critical

Use pageParam when building paginated requests in queryFn.

In TanStack Vue Query's useInfiniteQuery, the queryFn receives a pageParam argument that TanStack Query automatically manages for pagination. Your current implementation ignores it and always builds the URL from argsValue, causing fetchNextPage() to repeatedly fetch the same initial page instead of advancing through results.

Suggested fix
-            queryFn: ({ signal }: any) => {
-                const reqUrl = makeUrl(endpoint, model, operation, argsValue);
+            queryFn: ({ pageParam, signal }: any) => {
+                const reqUrl = makeUrl(endpoint, model, operation, pageParam ?? argsValue);
                 return fetcher<TQueryFnData>(reqUrl, { signal }, fetch);
             },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/clients/tanstack-query/src/vue.ts` around lines 543 - 550, The
queryFn inside finalOptions ignores TanStack Query's pageParam so infinite
queries always request the same page; update the queryFn signature to accept ({
signal, pageParam }) and incorporate pageParam into the request arguments when
building reqUrl (use the pageParam to override/augment argsValue or pass it to
makeUrl) so makeUrl(endpoint, model, operation, ...) uses the current page;
update any call sites using finalOptions/queryFn to expect the pageParam
handling (symbols: finalOptions, queryFn, argsValue, makeUrl, pageParam).
🧹 Nitpick comments (1)
tests/regression/test/issue-2529.test.ts (1)

6-21: Consider adding explicit cleanup to prevent connection leaks.

The setup() function creates a database client but doesn't clean up. While createTestClient may handle some cleanup, adding explicit $disconnect() in an afterEach hook would be more robust and consistent with patterns in other test files (e.g., find.test.ts lines 14-16).

♻️ Suggested improvement
+import { afterEach, describe, expect, it } from 'vitest';
+
 // https://github.com/zenstackhq/zenstack/issues/2529
 describe('Regression for issue `#2529`', () => {
+    let db: any;
+
+    afterEach(async () => {
+        await db?.$disconnect();
+    });
+
     async function setup() {
-        const db = await createTestClient(
+        db = await createTestClient(
             `
 model Post {
     id        Int      `@id` `@default`(autoincrement())
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/regression/test/issue-2529.test.ts` around lines 6 - 21, The setup()
helper creates a Prisma client via createTestClient but never disconnects it,
risking connection leaks; add an afterEach hook in this test file that calls
await db.$disconnect() for the client returned by setup() (or store the db in a
file-scoped variable set by setup()), ensuring the Prisma client created by
createTestClient is explicitly disconnected between tests; reference the setup()
function, createTestClient, and the $disconnect() method when implementing this
cleanup.
🤖 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/clients/tanstack-query/src/react.ts`:
- Around line 615-619: The infinite-query helper is incorrectly using the full
args object as initialPageParam while queryFn treats pageParam as a cursor
passed to makeUrl, making TPageParam unsound; update the types and API so
TPageParam represents the full request shape (the same type as args) or add a
public option to let callers set initialPageParam explicitly. Concretely, change
the generic/alias used for TPageParam to the args-type used by makeUrl (so
initialPageParam: args is type-correct) or add an options parameter (exposed
from the infinite-query helper) that maps to react-query's initialPageParam and
use that instead of always assigning args to initialPageParam; ensure queryFn,
makeUrl, fetcher, and the public helper signature are updated to keep types
aligned.

In `@packages/clients/tanstack-query/src/svelte/index.svelte.ts`:
- Around line 527-533: The pagination loses original filters because
initialPageParam is set from args()?. Fix by preserving the full initial request
args for subsequent pages: either change TPageParam to include both cursor and
full request shape (so getNextPageParam returns { cursor, initialArgs }) or
capture a stable initialArgs value in the closure and use that in queryFn when
pageParam is a cursor-only value; update queryFn, initialPageParam and
getNextPageParam handling (references: queryFn, initialPageParam,
getNextPageParam, TPageParam, args, makeUrl, fetcher) so every page request
composes makeUrl(endpoint, model, operation, { ...initialArgs,
...pageParamCursor }) rather than recomputing args() on later pages.

In `@packages/clients/tanstack-query/src/vue.ts`:
- Around line 551-552: The current code sets initialPageParam from argsValue
(via initialPageParam: toValue(argsValue) as TPageParam) which forces TPageParam
to represent the entire request args when stored in data.pageParams[0]; fix by
either (A) adding a new explicit option (e.g., initialPageArgs or
initialPageParamArgs) that callers can provide to override the full-args initial
page value and defaulting it to argsValue when absent, or (B) tighten the type
by constraining the generic so TPageParam extends the full request args type
(bind TPageParam to the request args shape) so callers cannot supply a narrower
cursor-only type; update references to initialPageParam, argsValue, options and
any code that reads data.pageParams[0] accordingly so the runtime page param
always matches the full request args shape or is explicitly overridden by the
new option.

---

Outside diff comments:
In `@packages/clients/tanstack-query/src/vue.ts`:
- Around line 543-550: The queryFn inside finalOptions ignores TanStack Query's
pageParam so infinite queries always request the same page; update the queryFn
signature to accept ({ signal, pageParam }) and incorporate pageParam into the
request arguments when building reqUrl (use the pageParam to override/augment
argsValue or pass it to makeUrl) so makeUrl(endpoint, model, operation, ...)
uses the current page; update any call sites using finalOptions/queryFn to
expect the pageParam handling (symbols: finalOptions, queryFn, argsValue,
makeUrl, pageParam).

---

Nitpick comments:
In `@tests/regression/test/issue-2529.test.ts`:
- Around line 6-21: The setup() helper creates a Prisma client via
createTestClient but never disconnects it, risking connection leaks; add an
afterEach hook in this test file that calls await db.$disconnect() for the
client returned by setup() (or store the db in a file-scoped variable set by
setup()), ensuring the Prisma client created by createTestClient is explicitly
disconnected between tests; reference the setup() function, createTestClient,
and the $disconnect() method when implementing this cleanup.
🪄 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: de8b2d5e-804d-40e7-b8d6-c182b81bde72

📥 Commits

Reviewing files that changed from the base of the PR and between 14780c3 and 39a0a28.

📒 Files selected for processing (34)
  • package.json
  • packages/auth-adapters/better-auth/package.json
  • packages/cli/package.json
  • packages/clients/client-helpers/package.json
  • packages/clients/tanstack-query/package.json
  • packages/clients/tanstack-query/src/react.ts
  • packages/clients/tanstack-query/src/svelte/index.svelte.ts
  • packages/clients/tanstack-query/src/vue.ts
  • packages/clients/tanstack-query/test/react-typing.test-d.ts
  • packages/clients/tanstack-query/test/svelte-typing-test.ts
  • packages/clients/tanstack-query/test/vue-typing-test.ts
  • packages/common-helpers/package.json
  • packages/config/eslint-config/package.json
  • packages/config/typescript-config/package.json
  • packages/config/vitest-config/package.json
  • packages/create-zenstack/package.json
  • packages/ide/vscode/package.json
  • packages/language/package.json
  • packages/orm/package.json
  • packages/orm/src/client/crud/dialects/base-dialect.ts
  • packages/orm/src/client/zod/factory.ts
  • packages/plugins/policy/package.json
  • packages/schema/package.json
  • packages/sdk/package.json
  • packages/server/package.json
  • packages/testtools/package.json
  • packages/zod/package.json
  • samples/orm/package.json
  • tests/e2e/orm/client-api/find.test.ts
  • tests/e2e/package.json
  • tests/regression/package.json
  • tests/regression/test/issue-2529.test.ts
  • tests/runtimes/bun/package.json
  • tests/runtimes/edge-runtime/package.json

@ymc9 ymc9 merged commit ddc1b14 into main Apr 7, 2026
18 checks passed
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.

1 participant