Conversation
* fix(tanstack): query result $optimistic typing * update
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
WalkthroughThis PR bumps many package versions from 3.0.0-beta.18 to 3.0.0-beta.19, adds optimistic-update typing support to the TanStack Query client, and enhances schema/relation metadata to mark relations whose foreign-key fields all have defaults. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ 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). (3)
🔇 Additional comments (1)
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 PR Review: v3.0.0-beta.19 ReleaseReviewing this PR that merges dev to main for the v3.0.0-beta.19 release. Tasks:
Review SummaryThis PR contains three main categories of changes for the v3.0.0-beta.19 release: ✅ Version Bumps (35 files)All package.json files have been consistently updated to version ✅ TanStack Query Typing ImprovementsLocation:
✅ Schema Generation Enhancement for Default Auth FieldsLocation:
✅ Comprehensive Test Coverage for Default AuthLocation:
Code Quality Assessment✅ Security: No security concerns identified
✅ Performance: No performance impacts
✅ Best Practices:
🔍 Minor Observations:
Recommendation: ✅ APPROVEThis is a solid beta release with:
The changes are well-implemented, properly tested, and ready for release. |
There was a problem hiding this comment.
Pull Request Overview
This PR bumps the version from 3.0.0-beta.18 to 3.0.0-beta.19 and adds support for detecting relations with foreign key fields that have default values, particularly for the use case where auth() is used as a default value. The key changes enable relations to be created without explicitly providing foreign key values when those fields have defaults.
- Version bump across all packages and samples
- Added logic to detect when all foreign key fields in a relation have default values and mark the relation with
hasDefault: true - Updated the
FieldHasDefaulttype to consider relations with default foreign keys - Added
$optimisticproperty to TanStack Query result types for optimistic update support
Reviewed Changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| package.json, packages//package.json, tests//package.json, samples/*/package.json | Version bump to 3.0.0-beta.19 |
| packages/sdk/src/ts-schema-generator.ts | Added logic to detect and mark relations where all FK fields have default values |
| packages/schema/src/schema.ts | Extended RelationInfo type with hasDefault property and updated FieldHasDefault type logic |
| packages/clients/tanstack-query/src/utils/types.ts | Added WithOptimistic type for marking items in optimistic update state |
| packages/clients/tanstack-query/src/{react,svelte,vue}.ts | Updated query result types to include WithOptimistic wrapper |
| packages/clients/tanstack-query/test/*-typing-test.ts | Added type tests for $optimistic property |
| tests/e2e/orm/schemas/default-auth/* | New test schema demonstrating auth() as default value |
| tests/e2e/orm/client-api/default-auth.test.ts | Test coverage for creating relations without providing defaulted FK fields |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (35)
package.json(1 hunks)packages/cli/package.json(1 hunks)packages/clients/tanstack-query/package.json(1 hunks)packages/clients/tanstack-query/src/react.ts(2 hunks)packages/clients/tanstack-query/src/svelte.ts(2 hunks)packages/clients/tanstack-query/src/utils/types.ts(1 hunks)packages/clients/tanstack-query/src/vue.ts(2 hunks)packages/clients/tanstack-query/test/react-typing-test.ts(2 hunks)packages/clients/tanstack-query/test/svelte-typing-test.ts(2 hunks)packages/clients/tanstack-query/test/vue-typing-test.ts(2 hunks)packages/common-helpers/package.json(1 hunks)packages/config/eslint-config/package.json(1 hunks)packages/config/typescript-config/package.json(1 hunks)packages/config/vitest-config/package.json(1 hunks)packages/create-zenstack/package.json(1 hunks)packages/dialects/sql.js/package.json(1 hunks)packages/language/package.json(1 hunks)packages/orm/package.json(1 hunks)packages/plugins/policy/package.json(1 hunks)packages/schema/package.json(1 hunks)packages/schema/src/schema.ts(2 hunks)packages/sdk/package.json(1 hunks)packages/sdk/src/ts-schema-generator.ts(2 hunks)packages/server/package.json(1 hunks)packages/testtools/package.json(1 hunks)packages/zod/package.json(1 hunks)samples/next.js/package.json(1 hunks)samples/orm/package.json(1 hunks)tests/e2e/orm/client-api/default-auth.test.ts(1 hunks)tests/e2e/orm/schemas/default-auth/input.ts(1 hunks)tests/e2e/orm/schemas/default-auth/models.ts(1 hunks)tests/e2e/orm/schemas/default-auth/schema.ts(1 hunks)tests/e2e/orm/schemas/default-auth/schema.zmodel(1 hunks)tests/e2e/package.json(1 hunks)tests/regression/package.json(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 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:
tests/e2e/orm/schemas/default-auth/schema.ts
🧬 Code graph analysis (6)
packages/clients/tanstack-query/src/svelte.ts (3)
packages/clients/tanstack-query/src/react.ts (1)
ModelQueryResult(96-96)packages/clients/tanstack-query/src/vue.ts (1)
ModelQueryResult(89-89)packages/clients/tanstack-query/src/utils/types.ts (1)
WithOptimistic(34-49)
packages/sdk/src/ts-schema-generator.ts (1)
packages/sdk/src/model-utils.ts (1)
hasAttribute(59-64)
packages/clients/tanstack-query/src/react.ts (4)
packages/clients/tanstack-query/src/svelte.ts (1)
ModelQueryResult(94-96)packages/clients/tanstack-query/src/vue.ts (1)
ModelQueryResult(89-89)packages/clients/tanstack-query/src/utils/types.ts (1)
WithOptimistic(34-49)packages/clients/tanstack-query/src/utils/common.ts (1)
ExtraQueryOptions(101-106)
tests/e2e/orm/schemas/default-auth/schema.ts (2)
packages/schema/src/expression-utils.ts (1)
ExpressionUtils(19-123)packages/schema/src/schema.ts (1)
SchemaDef(10-18)
packages/clients/tanstack-query/src/vue.ts (3)
packages/clients/tanstack-query/src/react.ts (1)
ModelQueryResult(96-96)packages/clients/tanstack-query/src/svelte.ts (1)
ModelQueryResult(94-96)packages/clients/tanstack-query/src/utils/types.ts (1)
WithOptimistic(34-49)
tests/e2e/orm/client-api/default-auth.test.ts (2)
packages/testtools/src/client.ts (1)
createTestClient(52-169)tests/e2e/orm/schemas/default-auth/schema.ts (1)
schema(9-121)
⏰ 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). (3)
- GitHub Check: build-test (20.x, postgresql)
- GitHub Check: build-test (20.x, sqlite)
- GitHub Check: claude-review
🔇 Additional comments (27)
tests/e2e/package.json (1)
1-35: Version bump consistent with root package and monorepo release.packages/config/typescript-config/package.json (1)
1-6: Version bump aligns with release series.packages/plugins/policy/package.json (1)
1-54: Version bump consistent across the monorepo.tests/regression/package.json (1)
1-22: Version bump aligns with monorepo release.packages/dialects/sql.js/package.json (1)
1-46: Version bump correct and consistent with other packages.samples/orm/package.json (1)
1-29: Version bump aligns with release.package.json (1)
1-42: Root package version update is correct.The root version bump to 3.0.0-beta.19 is the source of truth for workspace dependencies, making this change critical to the coordinated version update across the monorepo.
packages/orm/package.json (1)
1-101: Inconsistency detected: VSCode package version diverges from coordinated release.Verification shows 21 of 22 packages correctly updated to 3.0.0-beta.19, but
packages/ide/vscode/package.jsonremains at 3.0.11. Confirm whether this separate versioning is intentional or requires alignment with the coordinated release.packages/server/package.json (1)
3-3: Version bump to beta.19 is consistent with PR release objectives.The version metadata update aligns with the coordinated monorepo release.
samples/next.js/package.json (1)
3-3: Version bump to beta.19 maintained for consistency.Sample package version aligns with the release version.
packages/zod/package.json (1)
3-3: Version bump to beta.19 is appropriate.Version metadata updated consistently.
packages/testtools/package.json (1)
3-3: Version bump to beta.19 maintained consistently.Version metadata aligns with release.
packages/config/vitest-config/package.json (1)
4-4: Version bump to beta.19 is consistent.Version metadata updated as part of coordinated release.
packages/common-helpers/package.json (1)
3-3: Version bump to beta.19 aligns with release.Version metadata consistently updated.
packages/config/eslint-config/package.json (1)
3-3: Version bump to beta.19 is consistent.Version metadata updated appropriately.
packages/create-zenstack/package.json (1)
3-3: Version bump to beta.19 maintains consistency.Version metadata updated as part of coordinated release.
packages/schema/src/schema.ts (2)
55-55: LGTM! Relation metadata enhancement.The addition of the optional
hasDefaultproperty toRelationInfocorrectly extends the schema to track whether foreign key fields have defaults, aligning with the runtime type generation changes.
257-259: LGTM! Default detection logic correctly extended.The
FieldHasDefaulttype now properly checks forrelation.hasDefaultalongside existing checks for primitive defaults andupdatedAtfields. The logic flow is correct and maintains backward compatibility.packages/clients/tanstack-query/src/react.ts (3)
60-60: LGTM! Import added for optimistic update typing.The
WithOptimistictype import enables the query result types to surface optimistic update state to consumers.
96-96: LGTM! Query result type enhanced with optimistic flag.The
ModelQueryResult<T>now wraps data withWithOptimistic<T>, exposing the$optimisticproperty to track optimistic update state. This aligns with parallel changes in Vue and Svelte clients.
101-103: LGTM! Suspense query result type enhanced with optimistic flag.The
ModelSuspenseQueryResult<T>now wraps data withWithOptimistic<T>, maintaining consistency with standard query results.packages/clients/tanstack-query/test/svelte-typing-test.ts (2)
20-24: LGTM! Test coverage for optimistic update typing.The tests correctly validate that
$optimisticis accessible onuseFindFirstanduseFindManyresults, confirming theWithOptimistic<T>wrapper is properly applied.
36-37: LGTM! Negative test case for infinite query.The
ts-expect-errorcorrectly validates that$optimisticis not available at the item level inuseInfiniteFindManyresults, confirming the expected type behavior.tests/e2e/orm/schemas/default-auth/schema.zmodel (1)
1-24: LGTM! Test schema for default tracking.The schema correctly defines test models with intentional variation:
Profile.userIdhas@default(auth().id)whileProfile.addressIddoes not, enabling validation of the newhasDefaultrelation metadata tracking feature.packages/clients/tanstack-query/test/vue-typing-test.ts (2)
19-22: LGTM! Test coverage for Vue optimistic update typing.The tests correctly validate that
$optimisticis accessible on Vue query results viadata.value?.$optimistic, confirming theWithOptimistic<T>wrapper works properly with Vue's reactive references.
33-34: LGTM! Negative test case for Vue infinite query.The
ts-expect-errorcorrectly validates that$optimisticis not available at the item level in infinite query results, maintaining consistency with React and Svelte test patterns.tests/e2e/orm/schemas/default-auth/input.ts (1)
1-70: Auto-generated file looks correct.This file is auto-generated by ZenStack CLI and provides the expected type aliases for ORM operations on the User, Profile, and Address models.
|
I'll analyze this and get back to you. |

Summary by CodeRabbit
New Features
Schema
Tests
Chores