Skip to content

fix: map vector type to number[] in TypeScript type generation#1048

Open
nancysangani wants to merge 1 commit intosupabase:masterfrom
nancysangani:fix/typegen-vector-rpc-params-1029-final
Open

fix: map vector type to number[] in TypeScript type generation#1048
nancysangani wants to merge 1 commit intosupabase:masterfrom
nancysangani:fix/typegen-vector-rpc-params-1029-final

Conversation

@nancysangani
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

vector type in RPC function parameters generates as string in TypeScript. The Supabase client requires number[] for vector parameters — JSON.stringify() does not work as a workaround for RPC functions and causes queries to fail or return zero results.

Fixes #1029

What is the new behavior?

vector type now correctly generates as number[].

Before:

match_documents: {
  Args: {
    query_embedding: string  // ❌
  }
}

After:

match_documents: {
  Args: {
    query_embedding: number[]  // ✅
  }
}

Additional context

vector was grouped with string types in pgTypeToTsType. Moved it to its own condition returning number[]. A unit test for pgTypeToTsType is added in test/lib/typegen-typescript.test.ts covering vector → number[] and _vector → (number[])[].

Copilot AI review requested due to automatic review settings February 28, 2026 15:53
@nancysangani nancysangani requested review from a team, avallete and soedirgo as code owners February 28, 2026 15:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5b6537d and 0027bf2.

📒 Files selected for processing (2)
  • src/server/templates/typescript.ts
  • test/lib/typegen-typescript.test.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Corrected TypeScript type mapping for PostgreSQL vector types to properly represent them as number arrays instead of strings.
  • Tests

    • Added unit tests for PostgreSQL to TypeScript type mappings, including vector type conversions.

Walkthrough

This PR updates the TypeScript type generation to correctly map PostgreSQL vector types to TypeScript number arrays. Previously, the vector type was mapped to string, but the Supabase client requires number[] for RPC function parameters. The changes modify the pgTypeToTsType function to handle the vector type as a distinct case returning number[], and add comprehensive unit tests to verify mappings for both scalar vectors and array vectors.

Assessment against linked issues

Objective Addressed Explanation
Map vector type to number[] in TypeScript generation for RPC function parameters [#1029] The pgTypeToTsType function now returns 'number[]' for the 'vector' PostgreSQL type instead of 'string'.
Ensure vector array types are correctly handled [#1029] The array vector type (_vector) is mapped to (number[])[] through the existing array handling logic.
Validate type mappings through unit tests [#1029] Tests verify vector → number[], _vector → (number[])[], and other standard type mappings.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes TypeScript type generation for Postgres vector so generated types align with Supabase client expectations when calling RPC functions.

Changes:

  • Update pgTypeToTsType to map vector to number[] (and _vector to (number[])[] via existing array handling).
  • Add unit tests covering vector / _vector mappings and a few basic scalar mappings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/server/templates/typescript.ts Changes the TypeScript type mapping for vector from string to number[].
test/lib/typegen-typescript.test.ts Adds unit tests asserting the new vector / _vector mappings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,27 @@
import { expect, test, describe } from 'vitest'
import { pgTypeToTsType } from '../../src/server/templates/typescript.js'
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test imports pgTypeToTsType from ../../src/server/templates/typescript.js, but there is no typescript.js file under src/server/templates (only typescript.ts). This will fail module resolution when running tests. Import from ../../src/server/templates/typescript (consistent with test/types.test.ts) or reference the .ts file as appropriate for the test runner config.

Suggested change
import { pgTypeToTsType } from '../../src/server/templates/typescript.js'
import { pgTypeToTsType } from '../../src/server/templates/typescript'

Copilot uses AI. Check for mistakes.
) {
return 'string'
} else if (pgType === 'vector') {
return 'number[]'
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mapping vector to number[] here affects all type generation that uses pgTypeToTsType, including table/view column types (e.g. via generateColumnTsDefinition(... pgTypeToTsType(schema, column.format, ...) )), not just RPC function args. Given the reported runtime behavior difference between vector columns (often requiring a string representation) and RPC parameters (accepting number[]), consider scoping this mapping to RPC args only (e.g. add a mode/flag or a separate mapper for function params) or otherwise documenting/handling the column case to avoid a regression in generated table types.

Suggested change
return 'number[]'
return 'string | number[]'

Copilot uses AI. Check for mistakes.
@nancysangani
Copy link
Copy Markdown
Contributor Author

/cc @mandarini
/cc @avallete

@avallete avallete added deploy-canary Deploy a canary image for postgres-meta and removed deploy-canary Deploy a canary image for postgres-meta labels Apr 2, 2026
@supabase supabase deleted a comment from github-actions bot Apr 2, 2026
Copy link
Copy Markdown
Member

@avallete avallete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank's for contributing.

Only issue I have with this PR is the global scope of it, and lack of e2e tests about how this will work with postgrest-js end to end. I think the next steps we need is:

We need to first verify if this change would:

  1. Fix the issue on postgrest-js side
  2. Have any noticeable side effect

To do so, we need to add more tests to reproduce the initial issue here:

https://github.com/supabase/supabase-js/blob/master/packages/core/postgrest-js/test/supabase/migrations/00000000000000_schema.sql

And add some e2e tests:

https://github.com/supabase/supabase-js/blob/master/packages/core/postgrest-js/test/rpc.test.ts

Also add some tests with the behavior for similar types for insert/update/select on views/table.

Demonstrating that re-generating the types with this change doesn't BC something else and fix the original issue.

We currently don't have a good easy way to do so, that would be the first thing to do.
I think we need to change/add a scripts in postgrest-js:
https://github.com/supabase/supabase-js/blob/master/scripts/generate-postgrest-types.js

So we can easily point it to a local postgres-meta repo and regenerate the types from this version.
Right now the only way I see to do so, is to do:

cd supabase-js/packages/core/postgrest-js/test
npx supabase start db # start the test database
cd postgres-meta
PG_META_DB_URL="postgresql://postgres:postgres@127.0.0.1:54322/postgres" npm run dev # start pg-meta dev server and link it to the postgrest-js test db
 curl --location 'http://localhost:1337/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' -o supabase-js/packages/core/postgrest-js/test/types.generated.ts # regenerate the type tests for postgrest-js
cd supabase-js/packages/core/postgrest-js && npm run test:run # run the tests

With this new context we can safely proceed to deploy this more globally.

@nancysangani
Copy link
Copy Markdown
Contributor Author

Thank's for contributing.

Only issue I have with this PR is the global scope of it, and lack of e2e tests about how this will work with postgrest-js end to end. I think the next steps we need is:

We need to first verify if this change would:

  1. Fix the issue on postgrest-js side
  2. Have any noticeable side effect

To do so, we need to add more tests to reproduce the initial issue here:

https://github.com/supabase/supabase-js/blob/master/packages/core/postgrest-js/test/supabase/migrations/00000000000000_schema.sql

And add some e2e tests:

https://github.com/supabase/supabase-js/blob/master/packages/core/postgrest-js/test/rpc.test.ts

Also add some tests with the behavior for similar types for insert/update/select on views/table.

Demonstrating that re-generating the types with this change doesn't BC something else and fix the original issue.

We currently don't have a good easy way to do so, that would be the first thing to do. I think we need to change/add a scripts in postgrest-js: https://github.com/supabase/supabase-js/blob/master/scripts/generate-postgrest-types.js

So we can easily point it to a local postgres-meta repo and regenerate the types from this version. Right now the only way I see to do so, is to do:

cd supabase-js/packages/core/postgrest-js/test
npx supabase start db # start the test database
cd postgres-meta
PG_META_DB_URL="postgresql://postgres:postgres@127.0.0.1:54322/postgres" npm run dev # start pg-meta dev server and link it to the postgrest-js test db
 curl --location 'http://localhost:1337/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' -o supabase-js/packages/core/postgrest-js/test/types.generated.ts # regenerate the type tests for postgrest-js
cd supabase-js/packages/core/postgrest-js && npm run test:run # run the tests

With this new context we can safely proceed to deploy this more globally.

Thanks for the feedback. I’ll add tests to reproduce the issue, extend e2e coverage, and verify there are no breaking changes with regenerated types. I’ll also look into improving the type generation workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vector type in RPC function parameters generates incorrect TypeScript types

3 participants