@supabase/postgrest-js
Advanced tools
Comparing version 1.17.8 to 1.17.9
import PostgrestTransformBuilder from './PostgrestTransformBuilder'; | ||
import { GenericSchema } from './types'; | ||
import { GenericSchema, GenericTable } from './types'; | ||
declare type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'is' | 'in' | 'cs' | 'cd' | 'sl' | 'sr' | 'nxl' | 'nxr' | 'adj' | 'ov' | 'fts' | 'plfts' | 'phfts' | 'wfts'; | ||
declare type ResolveFilterValue<Tables extends Record<string, GenericTable>, Row extends Record<string, unknown>, ColumnName extends string> = ColumnName extends `${infer RelationshipTable}.${infer Remainder}` ? Remainder extends `${infer _}.${infer _}` ? ResolveFilterValue<Tables, Row, Remainder> : ResolveFilterRelationshipValue<Tables, RelationshipTable, Remainder> : ColumnName extends keyof Row ? Row[ColumnName] : never; | ||
declare type ResolveFilterRelationshipValue<Tables extends Record<string, GenericTable>, RelationshipTable extends string, RelationshipColumn extends string> = RelationshipTable extends keyof Tables ? 'Row' extends keyof Tables[RelationshipTable] ? RelationshipColumn extends keyof Tables[RelationshipTable]['Row'] ? Tables[RelationshipTable]['Row'][RelationshipColumn] : unknown : unknown : unknown; | ||
export default class PostgrestFilterBuilder<Schema extends GenericSchema, Row extends Record<string, unknown>, Result, RelationName = unknown, Relationships = unknown> extends PostgrestTransformBuilder<Schema, Row, Result, RelationName, Relationships> { | ||
@@ -13,3 +15,3 @@ /** | ||
*/ | ||
eq<ColumnName extends string>(column: ColumnName, value: ColumnName extends keyof Row ? NonNullable<Row[ColumnName]> : NonNullable<unknown>): this; | ||
eq<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema['Tables'], Row, ColumnName> extends never ? NonNullable<unknown> : NonNullable<ResolveFilterValue<Schema['Tables'], Row, ColumnName>>): this; | ||
/** | ||
@@ -21,3 +23,3 @@ * Match only rows where `column` is not equal to `value`. | ||
*/ | ||
neq<ColumnName extends string>(column: ColumnName, value: ColumnName extends keyof Row ? Row[ColumnName] : unknown): this; | ||
neq<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema['Tables'], Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema['Tables'], Row, ColumnName>): this; | ||
gt<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this; | ||
@@ -51,3 +53,3 @@ gt(column: string, value: unknown): this; | ||
*/ | ||
in<ColumnName extends string>(column: ColumnName, values: ColumnName extends keyof Row ? ReadonlyArray<Row[ColumnName]> : unknown[]): this; | ||
in<ColumnName extends string>(column: ColumnName, values: ResolveFilterValue<Schema['Tables'], Row, ColumnName> extends never ? unknown[] : ReadonlyArray<ResolveFilterValue<Schema['Tables'], Row, ColumnName>>): this; | ||
contains<ColumnName extends string & keyof Row>(column: ColumnName, value: string | ReadonlyArray<Row[ColumnName]> | Record<string, unknown>): this; | ||
@@ -54,0 +56,0 @@ contains(column: string, value: string | readonly unknown[] | Record<string, unknown>): this; |
{ | ||
"name": "@supabase/postgrest-js", | ||
"version": "1.17.8", | ||
"version": "1.17.9", | ||
"description": "Isomorphic PostgREST client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import PostgrestTransformBuilder from './PostgrestTransformBuilder' | ||
import { GenericSchema } from './types' | ||
import { GenericSchema, GenericTable } from './types' | ||
@@ -28,2 +28,31 @@ type FilterOperator = | ||
// Match relationship filters with `table.column` syntax and resolve underlying | ||
// column value. If not matched, fallback to generic type. | ||
// TODO: Validate the relationship itself ala select-query-parser. Currently we | ||
// assume that all tables have valid relationships to each other, despite | ||
// nonexistent foreign keys. | ||
type ResolveFilterValue< | ||
Tables extends Record<string, GenericTable>, | ||
Row extends Record<string, unknown>, | ||
ColumnName extends string | ||
> = ColumnName extends `${infer RelationshipTable}.${infer Remainder}` | ||
? Remainder extends `${infer _}.${infer _}` | ||
? ResolveFilterValue<Tables, Row, Remainder> | ||
: ResolveFilterRelationshipValue<Tables, RelationshipTable, Remainder> | ||
: ColumnName extends keyof Row | ||
? Row[ColumnName] | ||
: never | ||
type ResolveFilterRelationshipValue< | ||
Tables extends Record<string, GenericTable>, | ||
RelationshipTable extends string, | ||
RelationshipColumn extends string | ||
> = RelationshipTable extends keyof Tables | ||
? 'Row' extends keyof Tables[RelationshipTable] | ||
? RelationshipColumn extends keyof Tables[RelationshipTable]['Row'] | ||
? Tables[RelationshipTable]['Row'][RelationshipColumn] | ||
: unknown | ||
: unknown | ||
: unknown | ||
export default class PostgrestFilterBuilder< | ||
@@ -46,3 +75,5 @@ Schema extends GenericSchema, | ||
column: ColumnName, | ||
value: ColumnName extends keyof Row ? NonNullable<Row[ColumnName]> : NonNullable<unknown> | ||
value: ResolveFilterValue<Schema['Tables'], Row, ColumnName> extends never | ||
? NonNullable<unknown> | ||
: NonNullable<ResolveFilterValue<Schema['Tables'], Row, ColumnName>> | ||
): this { | ||
@@ -61,3 +92,5 @@ this.url.searchParams.append(column, `eq.${value}`) | ||
column: ColumnName, | ||
value: ColumnName extends keyof Row ? Row[ColumnName] : unknown | ||
value: ResolveFilterValue<Schema['Tables'], Row, ColumnName> extends never | ||
? unknown | ||
: ResolveFilterValue<Schema['Tables'], Row, ColumnName> | ||
): this { | ||
@@ -240,3 +273,5 @@ this.url.searchParams.append(column, `neq.${value}`) | ||
column: ColumnName, | ||
values: ColumnName extends keyof Row ? ReadonlyArray<Row[ColumnName]> : unknown[] | ||
values: ResolveFilterValue<Schema['Tables'], Row, ColumnName> extends never | ||
? unknown[] | ||
: ReadonlyArray<ResolveFilterValue<Schema['Tables'], Row, ColumnName>> | ||
): this { | ||
@@ -243,0 +278,0 @@ const cleanedValues = Array.from(new Set(values)) |
@@ -1,1 +0,1 @@ | ||
export const version = '1.17.8' | ||
export const version = '1.17.9' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
328734
5680