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

Commit 15ee92b

Browse files
authored
Adding better JSDoc (incomplete yet)
1 parent 2258b83 commit 15ee92b

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

src/builder.ts

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import fetch from 'cross-fetch'
22

3-
// https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes
3+
/**
4+
* Error format
5+
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
6+
*/
47
interface PostgrestError {
58
message: string
69
details: string
710
hint: string
811
code: string
912
}
1013

11-
// Response format: https://github.com/supabase/supabase-js/issues/32
14+
/**
15+
* Response format
16+
* {@link https://github.com/supabase/supabase-js/issues/32}
17+
*/
1218
interface PostgrestResponse<T> {
1319
error: PostgrestError | null
1420
data: T | T[] | null
@@ -21,7 +27,6 @@ interface PostgrestResponse<T> {
2127
/**
2228
* Base builder
2329
*/
24-
2530
export abstract class PostgrestBuilder<T> implements PromiseLike<any> {
2631
method!: 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE'
2732
url!: URL
@@ -90,7 +95,7 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
9095
/**
9196
* Performs horizontal filtering with SELECT.
9297
*
93-
* @param columns The columns to retrieve, separated by commas.
98+
* @param {string} columns The columns to retrieve, separated by commas.
9499
*/
95100
select(columns = '*'): PostgrestFilterBuilder<T> {
96101
this.method = 'GET'
@@ -115,8 +120,8 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
115120
/**
116121
* Performs an INSERT into the table.
117122
*
118-
* @param values The values to insert.
119-
* @param upsert If `true`, performs an UPSERT.
123+
* @param {Partial<T>|Partial<T>[]} values The values to insert.
124+
* @param {boolean} object.upsert If `true`, performs an UPSERT.
120125
*/
121126
insert(values: Partial<T> | Partial<T>[], { upsert = false } = {}): PostgrestBuilder<T> {
122127
this.method = 'POST'
@@ -130,7 +135,7 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
130135
/**
131136
* Performs an UPDATE on the table.
132137
*
133-
* @param values The values to update.
138+
* @param {Partial<T>} values The values to update.
134139
*/
135140
update(values: Partial<T>): PostgrestFilterBuilder<T> {
136141
this.method = 'PATCH'
@@ -164,10 +169,10 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
164169
/**
165170
* Orders the result with the specified `column`.
166171
*
167-
* @param column The column to order on.
168-
* @param ascending If `true`, the result will be in ascending order.
169-
* @param nullsFirst If `true`, `null`s appear first.
170-
* @param foreignTable The foreign table to use (if `column` is a foreign column).
172+
* @param {T} column The column to order on.
173+
* @param {boolean?} ascending If `true`, the result will be in ascending order.
174+
* @param {boolean?} nullsFirst If `true`, `null`s appear first.
175+
* @param {string?} foreignTable The foreign table to use (if `column` is a foreign column).
171176
*/
172177
order(
173178
column: keyof T,
@@ -188,8 +193,8 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
188193
/**
189194
* Limits the result with the specified `count`.
190195
*
191-
* @param count The maximum no. of rows to limit to.
192-
* @param foreignTable The foreign table to use (for foreign columns).
196+
* @param {number} count The maximum no. of rows to limit to.
197+
* @param {string?} object.foreignTable The foreign table to use (for foreign columns).
193198
*/
194199
limit(
195200
count: number,
@@ -203,9 +208,9 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
203208
/**
204209
* Limits the result to rows within the specified range, inclusive.
205210
*
206-
* @param from The starting index from which to limit the result, inclusive.
207-
* @param to The last index to which to limit the result, inclusive.
208-
* @param foreignTable The foreign table to use (for foreign columns).
211+
* @param {number} from The starting index from which to limit the result, inclusive.
212+
* @param {number} to The last index to which to limit the result, inclusive.
213+
* @param {string?} foreignTable The foreign table to use (for foreign columns).
209214
*/
210215
range(
211216
from: number,
@@ -264,9 +269,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
264269
/**
265270
* Finds all rows which doesn't satisfy the filter.
266271
*
267-
* @param column The column to filter on.
268-
* @param operator The operator to filter with.
269-
* @param value The value to filter with.
272+
* @param {T} column The column to filter on.
273+
* @param {FilterOperator} operator The operator to filter with.
274+
* @param {any} value The value to filter with.
270275
*/
271276
not(column: keyof T, operator: FilterOperator, value: any): this {
272277
this.url.searchParams.append(`${column}`, `not.${operator}.${value}`)
@@ -276,7 +281,7 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
276281
/**
277282
* Finds all rows satisfying at least one of the filters.
278283
*
279-
* @param filters The filters to use, separated by commas.
284+
* @param {string} filters The filters to use, separated by commas.
280285
*/
281286
or(filters: string): this {
282287
this.url.searchParams.append('or', `(${filters})`)
@@ -287,8 +292,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
287292
* Finds all rows whose value on the stated `column` exactly matches the
288293
* specified `value`.
289294
*
290-
* @param column The column to filter on.
291-
* @param value The value to filter with.
295+
* @param {T} column The column to filter on.
296+
* @param {T[]} value The value to filter with.
292297
*/
293298
eq(column: keyof T, value: T[keyof T]): this {
294299
this.url.searchParams.append(`${column}`, `eq.${value}`)
@@ -299,8 +304,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
299304
* Finds all rows whose value on the stated `column` doesn't match the
300305
* specified `value`.
301306
*
302-
* @param column The column to filter on.
303-
* @param value The value to filter with.
307+
* @param {T} column The column to filter on.
308+
* @param {T[]} value The value to filter with.
304309
*/
305310
neq(column: keyof T, value: T[keyof T]): this {
306311
this.url.searchParams.append(`${column}`, `neq.${value}`)
@@ -311,8 +316,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
311316
* Finds all rows whose value on the stated `column` is greater than the
312317
* specified `value`.
313318
*
314-
* @param column The column to filter on.
315-
* @param value The value to filter with.
319+
* @param {T} column The column to filter on.
320+
* @param {T[]} value The value to filter with.
316321
*/
317322
gt(column: keyof T, value: T[keyof T]): this {
318323
this.url.searchParams.append(`${column}`, `gt.${value}`)
@@ -323,8 +328,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
323328
* Finds all rows whose value on the stated `column` is greater than or
324329
* equal to the specified `value`.
325330
*
326-
* @param column The column to filter on.
327-
* @param value The value to filter with.
331+
* @param {T} column The column to filter on.
332+
* @param {T[]} value The value to filter with.
328333
*/
329334
gte(column: keyof T, value: T[keyof T]): this {
330335
this.url.searchParams.append(`${column}`, `gte.${value}`)
@@ -335,8 +340,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
335340
* Finds all rows whose value on the stated `column` is less than the
336341
* specified `value`.
337342
*
338-
* @param column The column to filter on.
339-
* @param value The value to filter with.
343+
* @param {T} column The column to filter on.
344+
* @param {T[]} value The value to filter with.
340345
*/
341346
lt(column: keyof T, value: T[keyof T]): this {
342347
this.url.searchParams.append(`${column}`, `lt.${value}`)
@@ -347,8 +352,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
347352
* Finds all rows whose value on the stated `column` is less than or equal
348353
* to the specified `value`.
349354
*
350-
* @param column The column to filter on.
351-
* @param value The value to filter with.
355+
* @param {T} column The column to filter on.
356+
* @param {T[]} value The value to filter with.
352357
*/
353358
lte(column: keyof T, value: T[keyof T]): this {
354359
this.url.searchParams.append(`${column}`, `lte.${value}`)
@@ -359,8 +364,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
359364
* Finds all rows whose value in the stated `column` matches the supplied
360365
* `pattern` (case sensitive).
361366
*
362-
* @param column The column to filter on.
363-
* @param pattern The pattern to filter with.
367+
* @param {T} column The column to filter on.
368+
* @param {string} pattern The pattern to filter with.
364369
*/
365370
like(column: keyof T, pattern: string): this {
366371
this.url.searchParams.append(`${column}`, `like.${pattern}`)
@@ -371,8 +376,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
371376
* Finds all rows whose value in the stated `column` matches the supplied
372377
* `pattern` (case insensitive).
373378
*
374-
* @param column The column to filter on.
375-
* @param pattern The pattern to filter with.
379+
* @param {T} column The column to filter on.
380+
* @param {string} pattern The pattern to filter with.
376381
*/
377382
ilike(column: keyof T, pattern: string): this {
378383
this.url.searchParams.append(`${column}`, `ilike.${pattern}`)
@@ -383,8 +388,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
383388
* A check for exact equality (null, true, false), finds all rows whose
384389
* value on the stated `column` exactly match the specified `value`.
385390
*
386-
* @param column The column to filter on.
387-
* @param value The value to filter with.
391+
* @param {T} column The column to filter on.
392+
* @param {boolean|null} value The value to filter with.
388393
*/
389394
is(column: keyof T, value: boolean | null): this {
390395
this.url.searchParams.append(`${column}`, `is.${value}`)
@@ -395,8 +400,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
395400
* Finds all rows whose value on the stated `column` is found on the
396401
* specified `values`.
397402
*
398-
* @param column The column to filter on.
399-
* @param values The values to filter with.
403+
* @param {T} column The column to filter on.
404+
* @param {T[]} values The values to filter with.
400405
*/
401406
in(column: keyof T, values: T[keyof T][]): this {
402407
this.url.searchParams.append(`${column}`, `in.(${cleanFilterArray(values)})`)
@@ -407,8 +412,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
407412
* Finds all rows whose json, array, or range value on the stated `column`
408413
* contains the values specified in `value`.
409414
*
410-
* @param column The column to filter on.
411-
* @param value The value to filter with.
415+
* @param {T} column The column to filter on.
416+
* @param {string|T[]|object} value The value to filter with.
412417
*/
413418
cs(column: keyof T, value: string | T[keyof T][] | object): this {
414419
if (typeof value === 'string') {
@@ -429,8 +434,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
429434
* Finds all rows whose json, array, or range value on the stated `column` is
430435
* contained by the specified `value`.
431436
*
432-
* @param column The column to filter on.
433-
* @param value The value to filter with.
437+
* @param {T} column The column to filter on.
438+
* @param {string|T[]|object} value The value to filter with.
434439
*/
435440
cd(column: keyof T, value: string | T[keyof T][] | object): this {
436441
if (typeof value === 'string') {
@@ -450,8 +455,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
450455
* Finds all rows whose range value on the stated `column` is strictly to the
451456
* left of the specified `range`.
452457
*
453-
* @param column The column to filter on.
454-
* @param range The range to filter with.
458+
* @param {T} column The column to filter on.
459+
* @param {string} range The range to filter with.
455460
*/
456461
sl(column: keyof T, range: string): this {
457462
this.url.searchParams.append(`${column}`, `sl.${range}`)
@@ -462,8 +467,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
462467
* Finds all rows whose range value on the stated `column` is strictly to
463468
* the right of the specified `range`.
464469
*
465-
* @param column The column to filter on.
466-
* @param range The range to filter with.
470+
* @param {T} column The column to filter on.
471+
* @param {string} range The range to filter with.
467472
*/
468473
sr(column: keyof T, range: string): this {
469474
this.url.searchParams.append(`${column}`, `sr.${range}`)
@@ -474,8 +479,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
474479
* Finds all rows whose range value on the stated `column` does not extend
475480
* to the left of the specified `range`.
476481
*
477-
* @param column The column to filter on.
478-
* @param range The range to filter with.
482+
* @param {T} column The column to filter on.
483+
* @param {string} range The range to filter with.
479484
*/
480485
nxl(column: keyof T, range: string): this {
481486
this.url.searchParams.append(`${column}`, `nxl.${range}`)
@@ -486,8 +491,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
486491
* Finds all rows whose range value on the stated `column` does not extend
487492
* to the right of the specified `range`.
488493
*
489-
* @param column The column to filter on.
490-
* @param range The range to filter with.
494+
* @param {T} column The column to filter on.
495+
* @param {string} range The range to filter with.
491496
*/
492497
nxr(column: keyof T, range: string): this {
493498
this.url.searchParams.append(`${column}`, `nxr.${range}`)
@@ -498,8 +503,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
498503
* Finds all rows whose range value on the stated `column` is adjacent to
499504
* the specified `range`.
500505
*
501-
* @param column The column to filter on.
502-
* @param range The range to filter with.
506+
* @param {T} column The column to filter on.
507+
* @param {string} range The range to filter with.
503508
*/
504509
adj(column: keyof T, range: string): this {
505510
this.url.searchParams.append(`${column}`, `adj.${range}`)
@@ -510,8 +515,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
510515
* Finds all rows whose array or range value on the stated `column` is
511516
* contained by the specified `value`.
512517
*
513-
* @param column The column to filter on.
514-
* @param value The value to filter with.
518+
* @param {T} column The column to filter on.
519+
* @param {string|T[]} value The value to filter with.
515520
*/
516521
ov(column: keyof T, value: string | T[keyof T][]): this {
517522
if (typeof value === 'string') {
@@ -528,9 +533,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
528533
* Finds all rows whose tsvector value on the stated `column` matches
529534
* to_tsquery(`query`).
530535
*
531-
* @param column The column to filter on.
532-
* @param query The Postgres tsquery string to filter with.
533-
* @param config The text search configuration to use.
536+
* @param {T} column The column to filter on.
537+
* @param {string} query The Postgres tsquery string to filter with.
538+
* @param {string?} config The text search configuration to use.
534539
*/
535540
fts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
536541
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -542,8 +547,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
542547
* Finds all rows whose tsvector value on the stated `column` matches
543548
* plainto_tsquery(`query`).
544549
*
545-
* @param column The column to filter on.
546-
* @param query The Postgres tsquery string to filter with.
550+
* @param {*} column The column to filter on.
551+
* @param {} query The Postgres tsquery string to filter with.
547552
* @param config The text search configuration to use.
548553
*/
549554
plfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {

0 commit comments

Comments
 (0)