Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Nov 5, 2025

Summary by CodeRabbit

  • New Features

    • Added Svelte support to the TanStack Query client with first-class, model-aware hooks for queries, infinite queries, and mutations plus global context/settings.
  • Refactor

    • Tightened hook argument typings for React and Vue integrations to enforce more precise query/aggregate/group-by shapes.
  • Chores

    • Updated package/build configuration and workspace metadata to include Svelte and related package declarations.

Copilot AI review requested due to automatic review settings November 5, 2025 05:51
@coderabbitai
Copy link

coderabbitai bot commented Nov 5, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds Svelte framework support to the TanStack Query client: new src/svelte.ts integration, package exports and dependencies for Svelte, tsup build entry, and workspace catalog entry; also tightens several hook type signatures in React and Vue modules.

Changes

Cohort / File(s) Summary
Package manifest
packages/clients/tanstack-query/package.json
Added ./svelte export with .js, .cjs, .d.ts, .d.cts paths; added devDependency @tanstack/[email protected], peerDependency @tanstack/svelte-query@^5.0.0 (optional via peerDependenciesMeta), and devDependency svelte via catalog.
Svelte integration
packages/clients/tanstack-query/src/svelte.ts
New comprehensive Svelte integration: context/defaults, schema-driven useClientQueries/useModelQueries, typed query/mutation/infinite hooks, store-aware option handling, query key generation, fetcher/marshalling, invalidation and optimistic update helpers, and derived store result shapes.
Build config
packages/clients/tanstack-query/tsup.config.ts
Added svelte: 'src/svelte.ts' entry to the tsup build configuration alongside existing entries.
Workspace catalog
pnpm-workspace.yaml
Added Svelte 5.43.3 entry to the workspace catalog.
Type tightening (React & Vue)
packages/clients/tanstack-query/src/react.ts, packages/clients/tanstack-query/src/vue.ts
Imported Subset from @zenstackhq/orm and updated several ModelQueryHooks signatures to accept Subset-constrained args for useCount, useAggregate, useGroupBy (and their suspense variants) to more strictly type allowed argument shapes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • Pay extra attention to packages/clients/tanstack-query/src/svelte.ts (dense generics, Svelte store interplay, optimistic update/invalidation flows).
  • Verify parity and consistency of query key generation and behavior with existing React/Vue implementations.
  • Confirm package.json exports and tsup entries produce correct build artifacts and type files.

Possibly related PRs

Poem

🐰
I nibble keys and hop through code so bright,
Svelte leaves rustle, queries take flight,
Hooks hum softly in a schema-filled glade,
Mutations and stores in a rabbit-made parade,
Hooray — another framework joins the night! 🥕✨

Pre-merge checks and finishing touches

✅ 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 'feat(tanstack): migrate svelte query' accurately summarizes the main change—adding comprehensive Svelte integration to the TanStack Query client with new exports, configuration, and hook implementations.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/svelte-query

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb0a7fc and f7e0292.

📒 Files selected for processing (3)
  • packages/clients/tanstack-query/src/react.ts (2 hunks)
  • packages/clients/tanstack-query/src/svelte.ts (1 hunks)
  • packages/clients/tanstack-query/src/vue.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/clients/tanstack-query/src/vue.ts (1)
packages/orm/src/client/crud-types.ts (6)
  • Subset (505-507)
  • CountArgs (977-982)
  • CountResult (988-998)
  • AggregateArgs (1004-1018)
  • AggregateResult (1044-1072)
  • GroupByArgs (1091-1108)
packages/clients/tanstack-query/src/react.ts (1)
packages/orm/src/client/crud-types.ts (7)
  • Subset (505-507)
  • CountArgs (977-982)
  • CountResult (988-998)
  • AggregateArgs (1004-1018)
  • AggregateResult (1044-1072)
  • GroupByArgs (1091-1108)
  • GroupByResult (1110-1144)
packages/clients/tanstack-query/src/svelte.ts (3)
packages/clients/tanstack-query/src/utils/common.ts (8)
  • APIContext (111-126)
  • ExtraQueryOptions (101-106)
  • ExtraMutationOptions (81-96)
  • getQueryKey (180-190)
  • fetcher (128-159)
  • marshal (192-199)
  • setupInvalidation (234-255)
  • setupOptimisticUpdate (313-357)
packages/schema/src/schema.ts (2)
  • SchemaDef (10-18)
  • GetModels (109-109)
packages/common-helpers/src/lower-case-first.ts (1)
  • lowerCaseFirst (1-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
🔇 Additional comments (8)
packages/clients/tanstack-query/src/vue.ts (2)

34-34: LGTM! Type import addition is correct.

The Subset type import is necessary for the improved type constraints on aggregation hooks.


160-174: LGTM! Type constraints correctly tightened.

The migration from SelectSubset to Subset for aggregation hook arguments provides better type safety and aligns with the React implementation.

packages/clients/tanstack-query/src/react.ts (2)

40-40: LGTM! Type import addition is correct.

The Subset type import is necessary for the improved type constraints on aggregation hooks, consistent with the Vue implementation.


203-231: LGTM! Type constraints correctly tightened.

The migration from SelectSubset to Subset for aggregation hook arguments (both regular and suspense variants) provides better type safety and aligns with the Vue implementation.

packages/clients/tanstack-query/src/svelte.ts (4)

92-103: Verify the UnwrapStore + Readable type wrapping pattern.

The query result types unwrap the store and re-wrap in Readable, while mutation results (lines 105-108) don't follow this pattern. Since CreateQueryResult already returns a store, verify whether this double-wrapping is necessary or if it can be simplified to match the mutation pattern.

Based on learnings


171-184: LGTM! Hook signatures correctly defined.

The useCount, useAggregate, and useGroupBy signatures properly use Subset for type constraints, consistent with React and Vue implementations.


278-371: LGTM! Query hook implementations are correct.

The internal query functions properly handle Svelte's reactivity with StoreOrVal inputs, correctly unwrap stores, and return derived stores for reactive results.


462-470: LGTM! Store helper utilities are well-implemented.

The isStore type guard and unwrapStore helper correctly handle Svelte's store reactivity patterns.


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.

@claude
Copy link

claude bot commented Nov 5, 2025

Claude finished @ymc9's task —— View job


Code Review Complete ✅

Reviewing the Svelte Query migration PR. Here's my analysis plan:

  • Read and analyze package.json changes
  • Review the new svelte.ts implementation
  • Check build configuration updates
  • Assess code quality and best practices
  • Identify potential bugs or issues
  • Evaluate performance considerations
  • Check for security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Overall Assessment

This PR successfully adds Svelte support to the TanStack Query client package. The implementation follows the established patterns from React and Vue implementations and maintains consistency with the existing codebase architecture.

Code Quality & Best Practices ✅

Strengths:

  • Consistent API Design: The Svelte implementation mirrors the React and Vue implementations with appropriate framework-specific adaptations
  • Proper TypeScript Integration: Comprehensive type definitions with proper generic constraints
  • Framework-Specific Adaptations: Correctly uses Svelte's context API (getContext/setContext) and store system (derived, get, isStore)
  • Code Reuse: Leverages shared utilities from ./utils/common, maintaining DRY principles

Observations:

  • The deprecated setHooksContext function (lines 73-75 in svelte.ts:73-75) maintains backward compatibility while providing a migration path
  • Type definitions are comprehensive and follow the established patterns from other implementations

Potential Issues & Suggestions

1. Missing Error Handling

The useModelQueries function has a potential issue with case-insensitive model lookup:

// svelte.ts:200-203
const modelDef = Object.values(schema.models).find((m) => m.name.toLowerCase() === model.toLowerCase());
if (!modelDef) {
    throw new Error(`Model "${model}" not found in schema`);
}

Suggestion: Consider more robust error messaging that lists available models.

2. Store Handling Consistency

The store unwrapping logic is well-implemented but could benefit from more explicit type guards:

// svelte.ts:458-460
function isStore<T>(opt: unknown): opt is Readable<T> {
    return typeof (opt as any)?.subscribe === 'function';
}

This is correct but the any casting could be more type-safe.

3. Context Key Export

The context key is exported but could benefit from documentation:

// svelte.ts:66
export const SvelteQueryContextKey = 'zenstack-svelte-query-context';

Performance Considerations ✅

Good practices implemented:

  • Proper Memoization: Uses derived stores appropriately to prevent unnecessary re-computations
  • Conditional Store Creation: Smart handling of store vs. value options prevents unnecessary reactivity overhead
  • Query Key Consistency: Maintains consistent query key generation for proper caching

Security Concerns ✅

No security issues identified:

  • Uses the same secure fetcher function from common utilities
  • Proper request serialization with marshal function
  • No direct DOM manipulation or unsafe operations

Build Configuration ✅

package.json changes are appropriate:

  • ✅ Added @tanstack/svelte-query as dev dependency and peer dependency
  • ✅ Added svelte as dev dependency with catalog version
  • ✅ Proper export configuration for the new Svelte entry point
  • ✅ Peer dependency marked as optional for flexibility

tsup.config.ts:

  • ✅ Added Svelte entry point following the established pattern

Test Coverage ⚠️

Missing test coverage for Svelte implementation:

  • The existing tests only cover React (react-query.test.tsx)
  • No Svelte-specific tests were added in this PR

Recommendation: Add comprehensive tests following the pattern of the React tests:

// Suggested test structure
describe('Svelte Query Test', () => {
  // Test useClientQueries
  // Test context setup
  // Test store reactivity
  // Test error handling
});

Dependencies & Compatibility ✅

Proper dependency management:

  • Uses @tanstack/svelte-query: 5.90.2 which is compatible with the React (5.90.6) and Vue (5.90.6) versions
  • Svelte version 5.43.3 is current and supports the required store APIs

Recommendations

  1. Add Svelte Tests: Create svelte-query.test.ts following the React test patterns
  2. Documentation: Consider adding Svelte-specific usage examples to complement React/Vue docs
  3. Error Messages: Enhance error messages with more context (e.g., list available models)
  4. Type Safety: Consider stricter typing for the isStore function

Summary

This is a well-implemented migration that successfully brings Svelte support to the TanStack Query integration. The code follows established patterns, maintains type safety, and integrates properly with the existing architecture. The main area for improvement is test coverage.

Recommendation: ✅ Approve with suggestions - Consider adding tests before merging to maintain code quality standards.


Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Svelte support to the @zenstackhq/tanstack-query client package, enabling developers to use ZenStack with Svelte applications via TanStack Query. The implementation follows the existing patterns established for React and Vue integrations.

  • Adds Svelte as a new framework target alongside React and Vue
  • Implements comprehensive query and mutation hooks for Svelte using @tanstack/svelte-query
  • Updates dependencies and build configuration to support the new Svelte entry point

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pnpm-workspace.yaml Adds Svelte 5.43.3 to the catalog for dependency management
pnpm-lock.yaml Updates lock file with Svelte dependencies, decimal.js version bump, and TanStack Svelte Query integration
packages/clients/tanstack-query/tsup.config.ts Adds Svelte entry point to build configuration
packages/clients/tanstack-query/src/svelte.ts Implements complete Svelte query/mutation hooks API following React/Vue patterns
packages/clients/tanstack-query/package.json Adds Svelte-related dependencies, exports, and peer dependencies
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@claude
Copy link

claude bot commented Nov 5, 2025

Claude finished @ymc9's task —— View job


Code Review Complete ✅

Reviewing the Svelte Query migration PR. Here's my analysis plan:

  • Read and analyze package.json changes
  • Review the new svelte.ts implementation
  • Check build configuration updates
  • Assess code quality and best practices
  • Identify potential bugs or issues
  • Evaluate performance considerations
  • Check for security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Overall Assessment

This PR successfully adds Svelte support to the TanStack Query client package. The implementation follows the established patterns from React and Vue implementations and maintains consistency with the existing codebase architecture.

Code Quality & Best Practices ✅

Strengths:

  • Consistent API Design: The Svelte implementation mirrors the React and Vue implementations with appropriate framework-specific adaptations
  • Proper TypeScript Integration: Comprehensive type definitions with proper generic constraints
  • Framework-Specific Adaptations: Correctly uses Svelte's context API (getContext/setContext) and store system (derived, get, isStore)
  • Code Reuse: Leverages shared utilities from ./utils/common, maintaining DRY principles

Observations:

  • The deprecated setHooksContext function (lines 73-75 in svelte.ts:73-75) maintains backward compatibility while providing a migration path
  • Type definitions are comprehensive and follow the established patterns from other implementations

Potential Issues & Suggestions

1. Missing Error Handling

The useModelQueries function has a potential issue with case-insensitive model lookup:

// svelte.ts:200-203
const modelDef = Object.values(schema.models).find((m) => m.name.toLowerCase() === model.toLowerCase());
if (!modelDef) {
    throw new Error(`Model "${model}" not found in schema`);
}

Suggestion: Consider more robust error messaging that lists available models.

2. Store Handling Consistency

The store unwrapping logic is well-implemented but could benefit from more explicit type guards:

// svelte.ts:458-460
function isStore<T>(opt: unknown): opt is Readable<T> {
    return typeof (opt as any)?.subscribe === 'function';
}

This is correct but the any casting could be more type-safe.

3. Context Key Export

The context key is exported but could benefit from documentation:

// svelte.ts:66
export const SvelteQueryContextKey = 'zenstack-svelte-query-context';

Performance Considerations ✅

Good practices implemented:

  • Proper Memoization: Uses derived stores appropriately to prevent unnecessary re-computations
  • Conditional Store Creation: Smart handling of store vs. value options prevents unnecessary reactivity overhead
  • Query Key Consistency: Maintains consistent query key generation for proper caching

Security Concerns ✅

No security issues identified:

  • Uses the same secure fetcher function from common utilities
  • Proper request serialization with marshal function
  • No direct DOM manipulation or unsafe operations

Build Configuration ✅

package.json changes are appropriate:

  • ✅ Added @tanstack/svelte-query as dev dependency and peer dependency
  • ✅ Added svelte as dev dependency with catalog version
  • ✅ Proper export configuration for the new Svelte entry point
  • ✅ Peer dependency marked as optional for flexibility

tsup.config.ts:

  • ✅ Added Svelte entry point following the established pattern

Test Coverage ⚠️

Missing test coverage for Svelte implementation:

  • The existing tests only cover React (react-query.test.tsx)
  • No Svelte-specific tests were added in this PR

Recommendation: Add comprehensive tests following the pattern of the React tests:

// Suggested test structure
describe('Svelte Query Test', () => {
  // Test useClientQueries
  // Test context setup
  // Test store reactivity
  // Test error handling
});

Dependencies & Compatibility ✅

Proper dependency management:

  • Uses @tanstack/svelte-query: 5.90.2 which is compatible with the React (5.90.6) and Vue (5.90.6) versions
  • Svelte version 5.43.3 is current and supports the required store APIs

Recommendations

  1. Add Svelte Tests: Create svelte-query.test.ts following the React test patterns
  2. Documentation: Consider adding Svelte-specific usage examples to complement React/Vue docs
  3. Error Messages: Enhance error messages with more context (e.g., list available models)
  4. Type Safety: Consider stricter typing for the isStore function

Summary

This is a well-implemented migration that successfully brings Svelte support to the TanStack Query integration. The code follows established patterns, maintains type safety, and integrates properly with the existing architecture. The main area for improvement is test coverage.

Recommendation: ✅ Approve with suggestions - Consider adding tests before merging to maintain code quality standards.


Copy link

@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: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f530fd and eb0a7fc.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • packages/clients/tanstack-query/package.json (3 hunks)
  • packages/clients/tanstack-query/src/svelte.ts (1 hunks)
  • packages/clients/tanstack-query/tsup.config.ts (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/clients/tanstack-query/src/svelte.ts (4)
packages/clients/tanstack-query/src/utils/common.ts (8)
  • APIContext (111-126)
  • ExtraQueryOptions (101-106)
  • ExtraMutationOptions (81-96)
  • getQueryKey (180-190)
  • fetcher (128-159)
  • marshal (192-199)
  • setupInvalidation (234-255)
  • setupOptimisticUpdate (313-357)
packages/schema/src/schema.ts (2)
  • SchemaDef (10-18)
  • GetModels (109-109)
packages/orm/src/client/crud-types.ts (20)
  • FindUniqueArgs (669-671)
  • SelectSubset (509-515)
  • ModelResult (135-179)
  • FindArgs (648-664)
  • CreateArgs (677-682)
  • CreateManyArgs (684-684)
  • BatchResult (201-201)
  • CreateManyAndReturnArgs (686-692)
  • UpdateArgs (815-821)
  • UpdateManyArgs (823-826)
  • UpdateManyAndReturnArgs (828-834)
  • UpsertArgs (842-849)
  • DeleteArgs (961-966)
  • DeleteManyArgs (968-971)
  • CountArgs (977-982)
  • CountResult (988-998)
  • AggregateArgs (1004-1018)
  • AggregateResult (1044-1072)
  • GroupByArgs (1091-1108)
  • GroupByResult (1110-1144)
packages/common-helpers/src/lower-case-first.ts (1)
  • lowerCaseFirst (1-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Upload results
  • GitHub Check: claude-review
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: build-test (20.x, postgresql)

@claude
Copy link

claude bot commented Nov 5, 2025

Claude finished @ymc9's task —— View job


Code Review Complete ✅

Reviewing the Svelte Query migration PR. Here's my analysis plan:

  • Read and analyze package.json changes
  • Review the new svelte.ts implementation
  • Check build configuration updates
  • Assess code quality and best practices
  • Identify potential bugs or issues
  • Evaluate performance considerations
  • Check for security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Overall Assessment

This PR successfully adds Svelte support to the TanStack Query client package. The implementation follows the established patterns from React and Vue implementations and maintains consistency with the existing codebase architecture.

Code Quality & Best Practices ✅

Strengths:

  • Consistent API Design: The Svelte implementation mirrors the React and Vue implementations with appropriate framework-specific adaptations
  • Proper TypeScript Integration: Comprehensive type definitions with proper generic constraints
  • Framework-Specific Adaptations: Correctly uses Svelte's context API (getContext/setContext) and store system (derived, get, isStore)
  • Code Reuse: Leverages shared utilities from ./utils/common, maintaining DRY principles

Observations:

  • The deprecated setHooksContext function (lines 73-75 in svelte.ts:73-75) maintains backward compatibility while providing a migration path
  • Type definitions are comprehensive and follow the established patterns from other implementations

Potential Issues & Suggestions

1. Missing Error Handling

The useModelQueries function has a potential issue with case-insensitive model lookup:

// svelte.ts:200-203
const modelDef = Object.values(schema.models).find((m) => m.name.toLowerCase() === model.toLowerCase());
if (!modelDef) {
    throw new Error(`Model "${model}" not found in schema`);
}

Suggestion: Consider more robust error messaging that lists available models.

2. Store Handling Consistency

The store unwrapping logic is well-implemented but could benefit from more explicit type guards:

// svelte.ts:458-460
function isStore<T>(opt: unknown): opt is Readable<T> {
    return typeof (opt as any)?.subscribe === 'function';
}

This is correct but the any casting could be more type-safe.

3. Context Key Export

The context key is exported but could benefit from documentation:

// svelte.ts:66
export const SvelteQueryContextKey = 'zenstack-svelte-query-context';

Performance Considerations ✅

Good practices implemented:

  • Proper Memoization: Uses derived stores appropriately to prevent unnecessary re-computations
  • Conditional Store Creation: Smart handling of store vs. value options prevents unnecessary reactivity overhead
  • Query Key Consistency: Maintains consistent query key generation for proper caching

Security Concerns ✅

No security issues identified:

  • Uses the same secure fetcher function from common utilities
  • Proper request serialization with marshal function
  • No direct DOM manipulation or unsafe operations

Build Configuration ✅

package.json changes are appropriate:

  • ✅ Added @tanstack/svelte-query as dev dependency and peer dependency
  • ✅ Added svelte as dev dependency with catalog version
  • ✅ Proper export configuration for the new Svelte entry point
  • ✅ Peer dependency marked as optional for flexibility

tsup.config.ts:

  • ✅ Added Svelte entry point following the established pattern

Test Coverage ⚠️

Missing test coverage for Svelte implementation:

  • The existing tests only cover React (react-query.test.tsx)
  • No Svelte-specific tests were added in this PR

Recommendation: Add comprehensive tests following the pattern of the React tests:

// Suggested test structure
describe('Svelte Query Test', () => {
  // Test useClientQueries
  // Test context setup
  // Test store reactivity
  // Test error handling
});

Dependencies & Compatibility ✅

Proper dependency management:

  • Uses @tanstack/svelte-query: 5.90.2 which is compatible with the React (5.90.6) and Vue (5.90.6) versions
  • Svelte version 5.43.3 is current and supports the required store APIs

Recommendations

  1. Add Svelte Tests: Create svelte-query.test.ts following the React test patterns
  2. Documentation: Consider adding Svelte-specific usage examples to complement React/Vue docs
  3. Error Messages: Enhance error messages with more context (e.g., list available models)
  4. Type Safety: Consider stricter typing for the isStore function

Summary

This is a well-implemented migration that successfully brings Svelte support to the TanStack Query integration. The code follows established patterns, maintains type safety, and integrates properly with the existing architecture. The main area for improvement is test coverage.

Recommendation: ✅ Approve with suggestions - Consider adding tests before merging to maintain code quality standards.


@ymc9 ymc9 merged commit 9372688 into dev Nov 5, 2025
4 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.

2 participants