Repository navigation
fix: type ROWS 1 set-returning functions as arrays - #1077
peter941221 wants to merge 4 commits into
Conversation
|
The one-line fix is correct and well-targeted is_set_returning_function is exactly the right signal here. |
|
Added a dedicated regression test in test/server/typegen.ts for the two cases from the review: function_using_table_returns stays a single object, while function_using_setof_rows_one still generates an array even with ROWS 1. I also kept the assertion focused on the generated function fragments so it locks the return-shape behavior without depending on the full inline snapshot formatting. |
avallete
left a comment
There was a problem hiding this comment.
Hey there !
Thank's for your contribution !
I would like this change backed by an e2e test on the postgrest-js repo.
I think this is tested against the actual postgrest runtime:
And the behavior seems correct. Embedding result in an ojbect:
While direct RPC call result in an array:
The type inference job seems to be doing it's job.
Problem
TypeScript type generation used
prorows > 1to decide whether an RPC return type should be an array.prorowscomes from PostgreSQLROWS n, which is a planner estimate. It does not change the runtime shape of a set-returning function. A function declared asRETURNS SETOF ... ROWS 1still returns a list through PostgREST.That made generated RPC types collapse
RETURNS SETOF ... ROWS 1functions to a single object.Change
Use
is_set_returning_functionas the return-shape signal for generated TypeScript RPC types.This keeps scalar and table-returning functions on the existing single-object path, while
RETURNS SETOF ... ROWS 1now gets an arrayReturnstype.The existing snapshots now reflect the corrected
ReturnsandSetofOptions.isOneToOnebehavior for theROWS 1fixtures. This PR also adds a dedicated regression test that contrasts the two relevant cases directly:function_using_table_returnsstays a single objectfunction_using_setof_rows_onestill generates an array even withROWS 1Issue
Addresses supabase/supabase#46525.
Validation
npm run checknpx prettier --check src/server/templates/typescript.ts test/server/typegen.tsnpx -p node@20 node ./node_modules/vitest/vitest.mjs run test/index.test.ts -t "typegen: typescript keeps ROWS 1 set-returning functions as arrays" --reporter verbose