@supabase/postgrest-js
Advanced tools
Comparing version
@@ -80,3 +80,3 @@ import { GenericTable } from '../types'; | ||
*/ | ||
export declare type ProcessEmbeddedResource<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews<Schema>> = ResolveRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer Resolved ? Resolved extends { | ||
export declare type ProcessEmbeddedResource<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews<Schema> & string> = ResolveRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer Resolved ? Resolved extends { | ||
referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>; | ||
@@ -83,0 +83,0 @@ relation: GenericRelationship & { |
@@ -88,3 +88,3 @@ import { Ast } from './parser'; | ||
*/ | ||
export declare type ResolveRelationship<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews<Schema>> = ResolveReverseRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer ReverseRelationship ? ReverseRelationship extends false ? CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ResolveForwardRelationship<Schema, Field, CurrentTableOrView>> : CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ReverseRelationship> : never; | ||
export declare type ResolveRelationship<Schema extends GenericSchema, Relationships extends GenericRelationship[], Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews<Schema> & string> = ResolveReverseRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer ReverseRelationship ? ReverseRelationship extends false ? CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ResolveForwardRelationship<Schema, Field, CurrentTableOrView>> : CheckRelationshipError<Schema, Relationships, CurrentTableOrView, ReverseRelationship> : never; | ||
/** | ||
@@ -179,3 +179,3 @@ * Resolves reverse relationships (from children to parent) | ||
} : never : never; | ||
declare type ResolveForwardRelationship<Schema extends GenericSchema, Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews<Schema>> = FindFieldMatchingRelationships<Schema, TablesAndViews<Schema>[Field['name']]['Relationships'], Ast.FieldNode & { | ||
declare type ResolveForwardRelationship<Schema extends GenericSchema, Field extends Ast.FieldNode, CurrentTableOrView extends keyof TablesAndViews<Schema> & string> = FindFieldMatchingRelationships<Schema, TablesAndViews<Schema>[Field['name']]['Relationships'], Ast.FieldNode & { | ||
name: CurrentTableOrView; | ||
@@ -196,5 +196,38 @@ hint: Field['hint']; | ||
from: CurrentTableOrView; | ||
type: 'found-my-match'; | ||
} : SelectQueryError<'could not find the relation'>; | ||
type: 'found-by-match'; | ||
} : FindJoinTableRelationship<Schema, CurrentTableOrView, Field['name']> extends infer FoundByJoinTable extends GenericRelationship ? { | ||
referencedTable: TablesAndViews<Schema>[FoundByJoinTable['referencedRelation']]; | ||
relation: FoundByJoinTable & { | ||
match: 'refrel'; | ||
}; | ||
direction: 'forward'; | ||
from: CurrentTableOrView; | ||
type: 'found-by-join-table'; | ||
} : SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`>; | ||
/** | ||
* Given a CurrentTableOrView, finds all join tables to this relation. | ||
* For example, if products and categories are linked via product_categories table: | ||
* | ||
* @example | ||
* Given: | ||
* - CurrentTableView = 'products' | ||
* - FieldName = "categories" | ||
* | ||
* It should return this relationship from product_categories: | ||
* { | ||
* foreignKeyName: "product_categories_category_id_fkey", | ||
* columns: ["category_id"], | ||
* isOneToOne: false, | ||
* referencedRelation: "categories", | ||
* referencedColumns: ["id"] | ||
* } | ||
*/ | ||
export declare type FindJoinTableRelationship<Schema extends GenericSchema, CurrentTableOrView extends keyof TablesAndViews<Schema> & string, FieldName extends string> = { | ||
[TableName in keyof TablesAndViews<Schema>]: TablesAndViews<Schema>[TableName]['Relationships'] extends readonly (infer Rel)[] ? Rel extends { | ||
referencedRelation: CurrentTableOrView; | ||
} ? TablesAndViews<Schema>[TableName]['Relationships'] extends readonly (infer OtherRel)[] ? OtherRel extends { | ||
referencedRelation: FieldName; | ||
} ? OtherRel : never : never : never : never; | ||
}[keyof TablesAndViews<Schema>]; | ||
/** | ||
* Finds a matching relationship based on the FieldNode's name and optional hint. | ||
@@ -201,0 +234,0 @@ */ |
{ | ||
"name": "@supabase/postgrest-js", | ||
"version": "1.17.0-rc.2", | ||
"version": "1.17.0-rc.3", | ||
"description": "Isomorphic PostgREST client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -201,3 +201,3 @@ import { GenericTable } from '../types' | ||
Field extends Ast.FieldNode, | ||
CurrentTableOrView extends keyof TablesAndViews<Schema> | ||
CurrentTableOrView extends keyof TablesAndViews<Schema> & string | ||
> = ResolveRelationship<Schema, Relationships, Field, CurrentTableOrView> extends infer Resolved | ||
@@ -204,0 +204,0 @@ ? Resolved extends { |
@@ -208,3 +208,3 @@ import { Ast } from './parser' | ||
Field extends Ast.FieldNode, | ||
CurrentTableOrView extends keyof TablesAndViews<Schema> | ||
CurrentTableOrView extends keyof TablesAndViews<Schema> & string | ||
> = ResolveReverseRelationship< | ||
@@ -389,3 +389,3 @@ Schema, | ||
Field extends Ast.FieldNode, | ||
CurrentTableOrView extends keyof TablesAndViews<Schema> | ||
CurrentTableOrView extends keyof TablesAndViews<Schema> & string | ||
> = FindFieldMatchingRelationships< | ||
@@ -418,7 +418,56 @@ Schema, | ||
from: CurrentTableOrView | ||
type: 'found-my-match' | ||
type: 'found-by-match' | ||
} | ||
: SelectQueryError<'could not find the relation'> | ||
: // Forward relations can also alias other tables via tables joins relationships | ||
// in such cases we crawl all the tables looking for a join table between our current table | ||
// and the Field['name'] desired desitnation | ||
FindJoinTableRelationship< | ||
Schema, | ||
CurrentTableOrView, | ||
Field['name'] | ||
> extends infer FoundByJoinTable extends GenericRelationship | ||
? { | ||
referencedTable: TablesAndViews<Schema>[FoundByJoinTable['referencedRelation']] | ||
relation: FoundByJoinTable & { match: 'refrel' } | ||
direction: 'forward' | ||
from: CurrentTableOrView | ||
type: 'found-by-join-table' | ||
} | ||
: SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`> | ||
/** | ||
* Given a CurrentTableOrView, finds all join tables to this relation. | ||
* For example, if products and categories are linked via product_categories table: | ||
* | ||
* @example | ||
* Given: | ||
* - CurrentTableView = 'products' | ||
* - FieldName = "categories" | ||
* | ||
* It should return this relationship from product_categories: | ||
* { | ||
* foreignKeyName: "product_categories_category_id_fkey", | ||
* columns: ["category_id"], | ||
* isOneToOne: false, | ||
* referencedRelation: "categories", | ||
* referencedColumns: ["id"] | ||
* } | ||
*/ | ||
export type FindJoinTableRelationship< | ||
Schema extends GenericSchema, | ||
CurrentTableOrView extends keyof TablesAndViews<Schema> & string, | ||
FieldName extends string | ||
> = { | ||
[TableName in keyof TablesAndViews<Schema>]: TablesAndViews<Schema>[TableName]['Relationships'] extends readonly (infer Rel)[] | ||
? Rel extends { referencedRelation: CurrentTableOrView } | ||
? TablesAndViews<Schema>[TableName]['Relationships'] extends readonly (infer OtherRel)[] | ||
? OtherRel extends { referencedRelation: FieldName } | ||
? OtherRel | ||
: never | ||
: never | ||
: never | ||
: never | ||
}[keyof TablesAndViews<Schema>] | ||
/** | ||
* Finds a matching relationship based on the FieldNode's name and optional hint. | ||
@@ -425,0 +474,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
export const version = '1.17.0-rc.2' | ||
export const version = '1.17.0-rc.3' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
310471
1.43%5490
1.52%