Repository navigation
feat(postgrest)!: type a partial select as a partial row instead of the full row - #1897
Conversation
…he full row `select([Books.id, Books.title])` on the typed builders resolved to `List<Row>`, so the getters of every column left out compiled and failed at runtime with a null cast that did not name the column. The same held for embeds, whose row getters converted a partial embedded object into a full row of the target. The column list moves to `selectOnly`, which resolves to `PostgrestPartialRow`s. Values are read through the select list entries, `row.read(Books.title)`, so the entry types the read and an entry the list did not ask for throws a `StateError` naming it. Relations are read the same way, `row.read(Books.author)?.read(Authors.name)`, and so are aggregates, casts and JSON paths under the key PostgREST answers with. `select()` keeps resolving to the full `Row`. To type the reads, `PostgrestNullableColumn` no longer extends `PostgrestColumn`; both extend the new `PostgrestStoredColumn`, which every list of key columns now takes. Column tokens carry a `fromJson` decoder so a partial row produces the same Dart values as the row getters, and `single()` and `maybeSingle()` move to an extension on the list-shaped builders, so a mutation without a trailing select has none. `supabase_typegen` emits the decoders as one private function per Dart type, passes them to the column tokens, and drops the relation getters from the row types, which only a partial select could have populated.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Repository: supabase/supabase-flutter/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: supabase/supabase-flutter/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (24)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughTyped queries now distinguish full-row ChangesTyped partial-row selections
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~60 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant TypedQuery as PostgrestTypedQueryBuilder
participant Transform as PostgrestTypedTransformBuilder
participant PartialRow as PostgrestPartialRow
participant Relation as PostgrestToOneRelation
TypedQuery->>Transform: selectOnly(selections)
Transform->>PartialRow: wrap result row with selections
PartialRow->>Relation: read(relation)
Relation->>PartialRow: decode nested partial row
Suggested reviewers: Merge Risk: ⚪ Minimal · up to No merge-blocking issue was identified in the typed partial-row changes; the reviewed single-row and array-read paths preserve their expected behavior. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Partial selections now produce a distinct result type across several client packages. The reviewed paths retain the existing request execution route and narrow, rather than expand, typed stream column inputs. The public contract change still requires coordinated adoption, and server-side authorization was not assessed. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
…xecutor (#1939) ## What #1857 was merged before the plugin seam was ready. This takes the plugin system and the executor extension point back out of the public API. #1940 brings them back for review. The typed builders keep their internal structure: they still collect a `PostgrestTableRequest` and run it through `PostgrestHttpTableExecutor`. Several later PRs build on that (#1907, #1913, #1910, #1897 and others). Only the public surface is removed: - `SupabaseClientPlugin`, `SupabaseClient(plugins:)`, `SupabaseClient.plugins`, `Supabase.initialize(plugins:)` and the plugin resume handling in the Flutter lifecycle listener, and `testSupabaseClient(plugins:)`. - `PostgrestClient.table(executor:)`, `SupabaseQuerySchema(tableExecutor:)` and `PostgrestTypedBuilder.request`. - `PostgrestTableExecutor`, `PostgrestHttpTableExecutor`, `PostgrestTableRequest`, `PostgrestTableResult`, `PostgrestTableOperation`, `PostgrestResultShape`, `PostgrestEmbeddedPage`, `PostgrestExplainOptions` and `PostgrestRequestOptions` are no longer exported. - `PostgrestTypedQueryBuilder` and `SupabaseTypedQueryBuilder` take a `client` instead of an `executor`. The matching `sdk-compliance.yaml` entries and the plugin paragraph in `MIGRATION.md` are removed, and `AGENTS.md` describes the executor as internal. ## Tests `table_executor_test.dart`, `client_plugin_test.dart` and the Flutter `plugin_test.dart` are removed with the API they cover. They come back in #1940. The update/delete test in `typed_query_test.dart` used to assert on `request.filter`. It now checks the filter on the request that goes out. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Breaking Changes** * Supabase client initialization no longer accepts plugins, and plugin lifecycle and request-wrapping support have been removed. * Typed table queries no longer allow supplying a custom executor. Supporting typed-query types and request details are no longer exposed through the main library exports. * **Documentation** * Updated query-building and migration guidance to reflect the current typed table query behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Closes SDK-1976.
Problem
select([Books.id, Books.title])on the typed builders resolved toList<BooksRow>. The generated row type reads_json['created_at'] as String, so every getter of a column the list left out compiled and crashed at runtime with a null cast that did not name the column. Since #1891 the same applied to embeds:Books.author.select([Authors.name])was read throughBooksRow.authors, which converted the partial embedded object into a fullAuthorsRow.What changes
postgrestselectOnly([...])replacesselect([...])onPostgrestTypedQueryBuilderandPostgrestTypedTransformBuilderand resolves toList<PostgrestPartialRow<Row>>.select()keeps resolving toList<Row>.PostgrestPartialRow.readreads a value through the select list entry, so the entry types the read and an entry of another table does not compile:A
PostgrestColumnreads as its value type, aPostgrestNullableColumn, a derived expression and a JSON path as the nullable form, a to-one relation as a nestedPostgrestPartialRow?, a to-many relation as a list of them. Aggregates come back under the function name, a cast under the key of what was cast, a JSON path under its last key. Entries of one relation merge into the nested row the way they merge into one embed, andBooks.author.select()lets any column of the embedded table be read. A selected nullable column thatstripNulls()dropped readsnull; an unselected one throws.PostgrestStoredColumnis the new sealed base ofPostgrestColumnandPostgrestNullableColumn, which no longer extend each other, since one reads asValueand the other asValue?.primaryKey,relationskey columns,onConflict, and the streamprimaryKeyandordertake it.fromJsonon the column tokens and onPostgrestCastTargetdecodes a value the way the generated row getters do, soreadproducesDateTime, enums,Uint8List, ranges and so on.sumandavgread asdoubleeven when PostgREST sends an integer;minandmaxinherit the decoder of the column.single()andmaybeSingle()move to thePostgrestTypedRowsBuilderextension onPostgrestTypedTransformBuilder<Row, List<Element>>, so they keep the element type ofselect()andselectOnly()alike, and a mutation without a trailing select no longer offers asingle()that could only fail.responseKeyon everyPostgrestSelectableand on relations names the key the entry comes back under.supabase_typegenDateTime _dateTimeFromJson(Object json) => DateTime.parse(json as String);, and passes it to the column tokens:PostgrestColumn<BooksRow, DateTime>('created_at', fromJson: _dateTimeFromJson).select()sends*, which never includes an embed, so they could only be reached through a partial select, which now reads relations throughread.Elsewhere
supabase: the typed stream builder takesPostgrestStoredColumn.sdk-compliance.yaml: registers the new symbols and moves the ones that changed owner.Breaking changes
All on the
@experimentaltyped surface:select([columns])isselectOnly(columns)and resolves to partial rows.PostgrestNullableColumnis not aPostgrestColumn; lists of key columns takePostgrestStoredColumn.single()andmaybeSingle()only exist on list-shaped builders.Tests
postgrest/test/postgrest_partial_row_test.dartcovers typed reads, decoders, nullable and stripped columns, aggregates, casts, JSON paths, to-one and to-many relations, merged embed entries, the*rules, embedded entry reads,single,maybeSingle,count, and a trailingselectOnlyon a mutation.List<String$>enum array next toList<String>, and that row types carry no relation getters. The behavior tests read embeds through the relation.postgrestsuite against the local stack,supabaseandsupabase_typegensuites, DCM and the compliance symbol, drift and schema checks all pass locally.Summary by CodeRabbit
selectOnlyfor explicit column selection;select()now returns full typed rows.single()andmaybeSingle()for typed query results.