-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix(tanstack): delegate hooks typing #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@ymc9 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 52 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (6)
WalkthroughIntroduces support for delegate models in the TanStack Query client by adding a new type that maps ineligible operations to hook names, updating the type-trimming logic, and expanding test schemas with Foo and Bar delegate models alongside corresponding type-checking tests. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
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 for TanStack Delegate Hooks Typing FixI'll review this PR focusing on code quality, potential bugs, performance, security, and test coverage. Review Checklist:
📋 Review SummaryThis PR successfully fixes a typing issue where delegate model hooks were not properly excluding certain operations. The fix is well-implemented and thoroughly tested. ✅ Strengths
🔍 Technical AnalysisCore Fix (
Test Verification ( // @ts-expect-error delegate model
client.foo.useCreate();
client.foo.useUpdate();
client.bar.useCreate(); // This should work since Bar extends Foo🎯 Specific Operations ExcludedBased on the ORM contract (
This makes sense architecturally - delegate models shouldn't support direct creation since they're abstract. 🔒 Security & Performance
📝 Code Quality
🧪 Test Coverage AssessmentExcellent coverage:
🚀 Recommendations
🎉 Final AssessmentScore: ✅ Excellent This is a high-quality fix that:
The PR is ready for merge. Great work on identifying and fixing this subtle but important typing issue! |
There was a problem hiding this 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 support for delegate models in TanStack Query hooks by excluding operations that are ineligible for delegate models from the generated hook types. The implementation maps ORM-level operation restrictions to the corresponding hook names (prefixed with "use").
- Updated type definition to transform ORM operation names to hook names (e.g., 'create' → 'useCreate')
- Added test coverage with delegate model schema definitions (Foo as delegate, Bar extending Foo)
- Added typing tests to verify that ineligible hooks properly show TypeScript errors for delegate models
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/clients/tanstack-query/src/utils/types.ts | Added type mapping to convert ORM operation names to hook names for delegate model exclusions |
| packages/clients/tanstack-query/test/schemas/basic/schema.zmodel | Added Foo (delegate) and Bar (extends Foo) models to test schema |
| packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts | Generated schema metadata for the new delegate models |
| packages/clients/tanstack-query/test/schemas/basic/models.ts | Added type exports for Foo and Bar models |
| packages/clients/tanstack-query/test/schemas/basic/input.ts | Generated input types for Foo and Bar models |
| packages/clients/tanstack-query/test/react-typing-test.ts | Added TypeScript tests verifying delegate model hook restrictions |
| packages/clients/tanstack-query/test/vue-typing-test.ts | Added TypeScript tests verifying delegate model hook restrictions |
| packages/clients/tanstack-query/test/svelte-typing-test.ts | Added TypeScript tests verifying delegate model hook restrictions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
packages/clients/tanstack-query/test/svelte-typing-test.ts (1)
102-105: Same inconsistency as React tests.This file has the same
useUpdateinconsistency noted in the React typing test. See the comment onreact-typing-test.tslines 105-108 for details.packages/clients/tanstack-query/test/vue-typing-test.ts (1)
103-106: Same inconsistency as other framework tests.This file has the same
useUpdateinconsistency noted in the React and Svelte typing tests. See the comment onreact-typing-test.tslines 105-108 for details.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
packages/clients/tanstack-query/src/utils/types.ts(1 hunks)packages/clients/tanstack-query/test/react-typing-test.ts(1 hunks)packages/clients/tanstack-query/test/schemas/basic/input.ts(1 hunks)packages/clients/tanstack-query/test/schemas/basic/models.ts(1 hunks)packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts(1 hunks)packages/clients/tanstack-query/test/schemas/basic/schema.zmodel(1 hunks)packages/clients/tanstack-query/test/svelte-typing-test.ts(1 hunks)packages/clients/tanstack-query/test/vue-typing-test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ymc9
Repo: zenstackhq/zenstack-v3 PR: 319
File: packages/runtime/src/client/executor/zenstack-query-executor.ts:63-72
Timestamp: 2025-10-21T16:09:31.218Z
Learning: In ZenStack, TypeDefs can be inherited by models. When a TypeDef contains fields with `map` attributes, those mapped field names need to be processed by the QueryNameMapper since they become part of the inheriting model's schema. Therefore, when checking if a schema has mapped names (e.g., in `schemaHasMappedNames`), both `schema.models` and `schema.typeDefs` must be inspected for `@map` and `map` attributes.
📚 Learning: 2025-10-21T16:09:31.218Z
Learnt from: ymc9
Repo: zenstackhq/zenstack-v3 PR: 319
File: packages/runtime/src/client/executor/zenstack-query-executor.ts:63-72
Timestamp: 2025-10-21T16:09:31.218Z
Learning: In ZenStack, TypeDefs can be inherited by models. When a TypeDef contains fields with `map` attributes, those mapped field names need to be processed by the QueryNameMapper since they become part of the inheriting model's schema. Therefore, when checking if a schema has mapped names (e.g., in `schemaHasMappedNames`), both `schema.models` and `schema.typeDefs` must be inspected for `@map` and `map` attributes.
Applied to files:
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts
🧬 Code graph analysis (2)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (1)
packages/schema/src/expression-utils.ts (1)
ExpressionUtils(19-123)
packages/clients/tanstack-query/src/utils/types.ts (2)
packages/orm/src/client/contract.ts (1)
OperationsIneligibleForDelegateModels(798-798)packages/schema/src/schema.ts (3)
SchemaDef(10-18)GetModels(109-109)IsDelegateModel(264-267)
⏰ 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, postgresql)
- GitHub Check: build-test (20.x, sqlite)
🔇 Additional comments (6)
packages/clients/tanstack-query/src/utils/types.ts (2)
24-26: LGTM: Clean type transformation.The distributive conditional type correctly maps operation names to their corresponding hook names using template literals and
Capitalize.
32-32: LGTM: Correct use of hook-based operation names.The updated type correctly omits hook methods (e.g.,
useCreate) rather than operation names, which aligns with the actual API surface of the TanStack Query client.packages/clients/tanstack-query/test/schemas/basic/schema.zmodel (1)
27-35: LGTM: Correct delegate model pattern.The
Foomodel with@@delegate(type)andBarextendingFoofollows the proper ZenStack delegate model pattern, providing appropriate test coverage for the new typing changes.packages/clients/tanstack-query/test/schemas/basic/models.ts (1)
13-14: LGTM: Standard generated model exports.The generated type exports for
FooandBarfollow the established pattern and correctly reference the schema.packages/clients/tanstack-query/test/schemas/basic/input.ts (1)
71-110: LGTM: Comprehensive generated type definitions.The generated input types for
FooandBarprovide complete coverage of all operation arguments and payload types, following the established pattern used for other models.packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (1)
120-167: LGTM: Well-structured delegate model schema.The generated schema correctly represents the delegate relationship:
Foois marked asisDelegate: truewithsubModels: ["Bar"]Barproperly referencesbaseModel: "Foo"with the discriminator field includingoriginModel: "Foo"This provides the necessary metadata for the type system to enforce delegate model restrictions.
|
Claude finished @ymc9's task —— View job Code Review for TanStack Delegate Hooks Typing FixI'll review this PR focusing on code quality, potential bugs, performance, security, and test coverage. Review Checklist:
📋 Review SummaryThis PR successfully fixes a typing issue where delegate model hooks were not properly excluding certain operations. The fix is well-implemented and thoroughly tested. ✅ Strengths
🔍 Technical AnalysisCore Fix (
Test Verification ( // @ts-expect-error delegate model
client.foo.useCreate();
client.foo.useUpdate();
client.bar.useCreate(); // This should work since Bar extends Foo🎯 Specific Operations ExcludedBased on the ORM contract (
This makes sense architecturally - delegate models shouldn't support direct creation since they're abstract.
|
|
Claude finished @ymc9's task —— View job Code Review for TanStack Delegate Hooks Typing FixReview Checklist:
📋 Review SummaryThis PR successfully fixes a typing issue where delegate model hooks were not properly excluding certain operations. The implementation is sound, but there are test inconsistencies that need addressing. ✅ Strengths
🔍 Technical AnalysisCore Fix (
Operations Excluded (from
This makes architectural sense - delegate models shouldn't support direct creation since they're abstract.
|
Summary by CodeRabbit
Type System Improvements
Tests