Skip to content

Commit 1de25c8

Browse files
committed
Improve comments
1 parent 4525dc4 commit 1de25c8

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/select-query-parser.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ type EatWhitespace<Input extends string> = string extends Input
118118
? EatWhitespace<Remainder>
119119
: Input
120120

121+
/**
122+
* Returns a boolean representing whether there is a foreign key with the given name.
123+
*/
121124
type HasFKey<FKeyName, Relationships> = Relationships extends [infer R]
122125
? R extends { foreignKeyName: FKeyName }
123126
? true
@@ -128,6 +131,9 @@ type HasFKey<FKeyName, Relationships> = Relationships extends [infer R]
128131
: HasFKey<FKeyName, Rest>
129132
: false
130133

134+
/**
135+
* Returns a boolean representing whether there the foreign key has a unique constraint.
136+
*/
131137
type HasUniqueFKey<FKeyName, Relationships> = Relationships extends [infer R]
132138
? R extends { foreignKeyName: FKeyName; isOneToOne: true }
133139
? true
@@ -138,6 +144,10 @@ type HasUniqueFKey<FKeyName, Relationships> = Relationships extends [infer R]
138144
: HasUniqueFKey<FKeyName, Rest>
139145
: false
140146

147+
/**
148+
* Returns a boolean representing whether there is a foreign key referencing
149+
* a given relation.
150+
*/
141151
type HasFKeyToFRel<FRelName, Relationships> = Relationships extends [infer R]
142152
? R extends { referencedRelation: FRelName }
143153
? true
@@ -161,8 +171,9 @@ type HasUniqueFKeyToFRel<FRelName, Relationships> = Relationships extends [infer
161171
/**
162172
* Constructs a type definition for a single field of an object.
163173
*
164-
* @param Definitions Record of definitions, possibly generated from PostgREST's OpenAPI spec.
165-
* @param Name Name of the table being queried.
174+
* @param Schema Database schema.
175+
* @param Row Type of a row in the given table.
176+
* @param Relationships Relationships between different tables in the database.
166177
* @param Field Single field parsed by `ParseQuery`.
167178
*/
168179
type ConstructFieldDefinition<
@@ -246,8 +257,7 @@ type ConstructFieldDefinition<
246257
*/
247258

248259
/**
249-
* Reads a consecutive sequence of more than 1 letter,
250-
* where letters are `[0-9a-zA-Z_]`.
260+
* Reads a consecutive sequence of 1 or more letter, where letters are `[0-9a-zA-Z_]`.
251261
*/
252262
type ReadLetters<Input extends string> = string extends Input
253263
? GenericStringError
@@ -266,7 +276,7 @@ type ReadLettersHelper<Input extends string, Acc extends string> = string extend
266276
: [Acc, '']
267277

268278
/**
269-
* Reads a consecutive sequence of more than 1 double-quoted letters,
279+
* Reads a consecutive sequence of 1 or more double-quoted letters,
270280
* where letters are `[^"]`.
271281
*/
272282
type ReadQuotedLetters<Input extends string> = string extends Input
@@ -289,7 +299,7 @@ type ReadQuotedLettersHelper<Input extends string, Acc extends string> = string
289299

290300
/**
291301
* Parses a (possibly double-quoted) identifier.
292-
* For now, identifiers are just sequences of more than 1 letter.
302+
* Identifiers are sequences of 1 or more letters.
293303
*/
294304
type ParseIdentifier<Input extends string> = ReadLetters<Input> extends [
295305
infer Name,
@@ -560,7 +570,9 @@ type GetResultHelper<
560570
/**
561571
* Constructs a type definition for an object based on a given PostgREST query.
562572
*
563-
* @param Row Record<string, unknown>.
573+
* @param Schema Database schema.
574+
* @param Row Type of a row in the given table.
575+
* @param Relationships Relationships between different tables in the database.
564576
* @param Query Select query string literal to parse.
565577
*/
566578
export type GetResult<

0 commit comments

Comments
 (0)