Skip to content

fix(postgrest): enforce array value type for array columns in contains and containedBy - #2793

Open
Roshanraj2580 wants to merge 1 commit into
supabase:masterfrom
Roshanraj2580:fix/postgrest-contains-containedby-types
Open

Roshanraj2580 wants to merge 1 commit into
supabase:masterfrom
Roshanraj2580:fix/postgrest-contains-containedby-types

Conversation

@Roshanraj2580

Copy link
Copy Markdown

Problem

Fixes supabase/postgrest-js#435

In PostgrestFilterBuilder, .contains() and .containedBy() previously accepted string | ReadonlyArray<Row[ColumnName]> | Record<string, unknown>.

When querying an array column (e.g. uuid[] or string[]), passing a single string was accepted by TypeScript without error, but failed at runtime in PostgreSQL with error 22P02: malformed array literal because PostgREST requires array syntax cs.{...}. Additionally, ReadonlyArray<Row[ColumnName]> typed an array-of-arrays ((T[])[]) rather than T[], and the duplicate fallback overload silently masked type mismatches.

Solution

  1. Introduced ResolveContainsFilterValue:
    • When NonNullable extends an array (infer Element)[], enforces
      eadonly Element[] (preventing raw strings or objects).
    • When NonNullable is an unmapped type, range, or JSON, permits string | readonly unknown[] | Record<string, unknown>.
  2. Replaced duplicate overloads with a unified generic signature using ColumnName extends keyof Row ? ResolveContainsFilterValue<Row[ColumnName]> : string | readonly unknown[] | Record<string, unknown>.
  3. Applied matching updates to .containedBy().
  4. Added type test assertions in packages/core/postgrest-js/test/index.test-d.ts.

Checklist

  • Code conforms to project conventions and passes prettier --check
  • pnpm test:types passes (35/35 test suites)
  • pnpm build in packages/core/postgrest-js generates clean CJS and ESM distributions

@Roshanraj2580
Roshanraj2580 requested review from a team as code owners October 26, 2026 10:29
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d16431bf-7878-4694-846f-774f162899f6
Commits

Reviewing files that changed from the base of the PR and between 51816da and d0e5b58.

Files selected for processing: 2
  • packages/core/postgrest-js/src/PostgrestFilterBuilder.ts
  • packages/core/postgrest-js/test/index.test-d.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Developer Experience
    • Improved TypeScript type checking for contains() and containedBy(), with accepted values guided by the selected column’s type.
    • Array columns now support readonly arrays of the correct element type, while range and JSON columns accept appropriate string and object values.
    • Invalid value types are caught during development.

The contains and containedBy method signatures now infer accepted values from known row column types. Array columns accept readonly arrays of their element type. Other known columns use the helper’s string, readonly-array, or object value union. Unknown column names retain a broad value union. Runtime serialization is unchanged. Compile-time tests cover these types.

Assessment against linked issues

Objective Addressed Explanation
Make .contains() value types specific to the column type, including array columns [#435] ✅

Priority: Low

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to d0e5b

No merge-blocking issue is identified; the type changes are ready for normal checks.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

This branch has not been deployed

No deployments
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.

value type for .contains() is not specific enough

1 participant