fix(postgrest): enforce type safety for table and view names in from() method#2058
Conversation
📝 WalkthroughWalkthroughThe PostgrestClient.from method signature was updated to accept only valid table or view keys from the Schema, replacing the previous open string parameter with a union type that enforces type-level validation while preserving existing runtime behavior. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Failure to add the new IP will result in interrupted reviews. 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 |
|
The type tests were already there, |
avallete
left a comment
There was a problem hiding this comment.
Flagging here that I wonder if that will break for clients that don't use Database introspected types. It might require a BC release.
For users with generated Database types, this adds compile time safety. thanks for the review @steve-chavez & @avallete 😁💚 |
* fix(postgrest): enforce type safety for table and view names in from() method (supabase#2058) * docs(auth): clarify updateUserById does not trigger client listeners (supabase#2114) * fix(auth): resolve Firefox content script Promise.then() security errors in locks (supabase#2112) * build(deps): bump qs from 6.14.1 to 6.14.2 in the npm_and_yarn group across 1 directory (supabase#2118) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(release): version 2.96.0 changelogs (supabase#2121) Co-authored-by: supabase-releaser[bot] <supabase-releaser[bot]@users.noreply.github.com> * docs(supabase): document UNUSED_EXTERNAL_IMPORT build warning as false positive (supabase#2122) * feat(auth): add skipAutoInitialize option to prevent constructor auto-init (supabase#2123) * chore(release): version 2.97.0 changelogs (supabase#2124) Co-authored-by: supabase-releaser[bot] <supabase-releaser[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Vaibhav <[email protected]> Co-authored-by: Katerina Skroumpelou <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com> Co-authored-by: supabase-releaser[bot] <supabase-releaser[bot]@users.noreply.github.com>
Problem
The
from()method's implementation signature accepted any string,defeating TypeScript's type safety and allowing typos or invalid table/view names to pass compile time checks.
Solution
Constrained the implementation signature parameter type to
(string & keyof Schema['Tables']) | (string & keyof Schema['Views']),ensuring only valid schema-defined table and view names are accepted
Related
Summary by CodeRabbit
Breaking Changes
Improvements