Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit b1a2cab

Browse files
committed
fix: remove intermediate type for better end result
1 parent 3097228 commit b1a2cab

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/select-query-parser/utils.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import {
1212

1313
export type SelectQueryError<Message extends string> = { error: true } & Message
1414

15-
type RequireHintingSelectQueryError<
16-
DistantName extends string,
17-
RelationName extends string
18-
> = SelectQueryError<`Could not embed because more than one relationship was found for '${DistantName}' and '${RelationName}' you need to hint the column with ${DistantName}!<columnName> ?`>
19-
2015
export type GetFieldNodeResultName<Field extends Ast.FieldNode> = Field['alias'] extends string
2116
? Field['alias']
2217
: Field['aggregateFunction'] extends AggregateFunctions
@@ -151,7 +146,7 @@ type HasMultipleFKeysToFRel<FRelName, Relationships> = Relationships extends [
151146
type CheckRelationshipError<
152147
Schema extends GenericSchema,
153148
Relationships extends GenericRelationship[],
154-
CurrentTableOrView extends keyof TablesAndViews<Schema>,
149+
CurrentTableOrView extends keyof TablesAndViews<Schema> & string,
155150
FoundRelation
156151
> = FoundRelation extends SelectQueryError<string>
157152
? FoundRelation
@@ -166,10 +161,7 @@ type CheckRelationshipError<
166161
? // We check if there is possible confusion with other relations with this table
167162
HasMultipleFKeysToFRel<RelatedRelationName, Relationships> extends true
168163
? // If there is, postgrest will fail at runtime, and require desambiguation via hinting
169-
RequireHintingSelectQueryError<
170-
RelatedRelationName,
171-
CurrentTableOrView extends string ? CurrentTableOrView : 'unknown'
172-
>
164+
SelectQueryError<`Could not embed because more than one relationship was found for '${RelatedRelationName}' and '${CurrentTableOrView}' you need to hint the column with ${RelatedRelationName}!<columnName> ?`>
173165
: FoundRelation
174166
: // Same check for forward relationships, but we must gather the relationships from the found relation
175167
FoundRelation extends {
@@ -178,13 +170,13 @@ type CheckRelationshipError<
178170
name: string
179171
}
180172
direction: 'forward'
181-
from: infer From extends keyof TablesAndViews<Schema>
173+
from: infer From extends keyof TablesAndViews<Schema> & string
182174
}
183175
? HasMultipleFKeysToFRel<
184176
RelatedRelationName,
185177
TablesAndViews<Schema>[From]['Relationships']
186178
> extends true
187-
? RequireHintingSelectQueryError<From extends string ? From : 'unknown', RelatedRelationName>
179+
? SelectQueryError<`Could not embed because more than one relationship was found for '${From}' and '${RelatedRelationName}' you need to hint the column with ${From}!<columnName> ?`>
188180
: FoundRelation
189181
: FoundRelation
190182

@@ -219,7 +211,7 @@ type ResolveReverseRelationship<
219211
Schema extends GenericSchema,
220212
Relationships extends GenericRelationship[],
221213
Field extends Ast.FieldNode,
222-
CurrentTableOrView extends keyof TablesAndViews<Schema>
214+
CurrentTableOrView extends keyof TablesAndViews<Schema> & string
223215
> = FindFieldMatchingRelationships<Schema, Relationships, Field> extends infer FoundRelation
224216
? FoundRelation extends never
225217
? false
@@ -235,10 +227,7 @@ type ResolveReverseRelationship<
235227
}
236228
: // If the relation was found via implicit relation naming, we must ensure there is no conflicting matches
237229
HasMultipleFKeysToFRel<RelatedRelationName, Relationships> extends true
238-
? RequireHintingSelectQueryError<
239-
RelatedRelationName,
240-
CurrentTableOrView extends string ? CurrentTableOrView : 'unknown'
241-
>
230+
? SelectQueryError<`Could not embed because more than one relationship was found for '${RelatedRelationName}' and '${CurrentTableOrView}' you need to hint the column with ${RelatedRelationName}!<columnName> ?`>
242231
: {
243232
referencedTable: TablesAndViews<Schema>[RelatedRelationName]
244233
relation: FoundRelation

0 commit comments

Comments
 (0)