fix(db): support optional nested single-row refs - #1850
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe pull request updates ChangesOptional reference proxy
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The optional nested-reference behavior is covered without an identified remaining regression risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 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 |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/react-router-with-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 165 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 7.34 kB ℹ️ View Unchanged
|
SingleRowRefProxynow lets collection index and change-filter callbacks traverse optional or nullable nested plain objects with schema-required guards. Dates, arrays, Maps, functions, and other built-ins remain scalar query leaves instead of exposing nonsensical method/property paths.Root cause
The mapped proxy checked
T[K] extends Record<string, any>before separating nullish members. An optional object such asTimestamp | undefinedtherefore collapsed to an opaque leaf, even though the runtime proxy recordstimestamp.secondscorrectly.Normalizing with
NonNullablefixed that case but made theRecordcheck too permissive: built-ins such asDate | nullbecame recursive proxies. That disagreed with the query builder's established plain-object traversal rule and allowed paths such asupdatedAt.getTimeto typecheck.Approach
NonNullable<V>before classifying it.IsPlainObjectclassifier so all query refs share one leaf/traversal boundary.null | undefinedmembers outside nested proxies so TypeScript still requires a guard.nulland exactundefinedfields as leaves with a non-distributiveneverguard.Key invariants
Non-goals
Trade-offs
Exporting and reusing the internal
IsPlainObjecttype adds a small shared dependency between the two query-ref implementations. It avoids duplicating a subtle classifier and preserves the leaf behavior established for Dates and other built-ins.Verification
@tanstack/dbsuite: 206 files, 6,257 tests, no type errors.Recordclassifier, an all-objects classifier, and removal of the exact-nullish guard.Files changed
packages/db/src/query/builder/ref-proxy.ts: classify normalized fields with the shared plain-object rule.packages/db/src/query/builder/types.ts: export the existing classifier for internal reuse.packages/db/tests/single-row-ref-proxy.test-d.ts: cover nullish plain objects, built-in leaves, unions, generics, expression consumers, and public callback paths.packages/db/tests/query/builder/ref-proxy.test.ts: verify valid nested paths and the forced built-in-path failure mode..changeset/fix-single-row-optional-ref-proxy.md: document both optional traversal and preserved built-in leaves.Fixes #1726
Summary by CodeRabbit