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

Commit 6352132

Browse files
committed
Adding better JSDoc
1 parent 35fee9b commit 6352132

File tree

1 file changed

+75
-70
lines changed

1 file changed

+75
-70
lines changed

src/builder.ts

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fetch from 'cross-fetch'
22

33
/**
44
* Error format
5+
*
56
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
67
*/
78
interface PostgrestError {
@@ -13,6 +14,7 @@ interface PostgrestError {
1314

1415
/**
1516
* Response format
17+
*
1618
* {@link https://github.com/supabase/supabase-js/issues/32}
1719
*/
1820
interface PostgrestResponse<T> {
@@ -95,7 +97,7 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
9597
/**
9698
* Performs horizontal filtering with SELECT.
9799
*
98-
* @param {string} columns The columns to retrieve, separated by commas.
100+
* @param {string} columns - The columns to retrieve, separated by commas.
99101
*/
100102
select(columns = '*'): PostgrestFilterBuilder<T> {
101103
this.method = 'GET'
@@ -120,8 +122,8 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
120122
/**
121123
* Performs an INSERT into the table.
122124
*
123-
* @param {Partial<T>|Partial<T>[]} values The values to insert.
124-
* @param {boolean} object.upsert If `true`, performs an UPSERT.
125+
* @param {(Partial<T>|Partial<T>[])} values - The values to insert.
126+
* @param {boolean} object.upsert - If `true`, performs an UPSERT.
125127
*/
126128
insert(values: Partial<T> | Partial<T>[], { upsert = false } = {}): PostgrestBuilder<T> {
127129
this.method = 'POST'
@@ -135,7 +137,7 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
135137
/**
136138
* Performs an UPDATE on the table.
137139
*
138-
* @param {Partial<T>} values The values to update.
140+
* @param {Partial<T>} values - The values to update.
139141
*/
140142
update(values: Partial<T>): PostgrestFilterBuilder<T> {
141143
this.method = 'PATCH'
@@ -153,7 +155,10 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
153155
return new PostgrestFilterBuilder(this)
154156
}
155157

156-
/** @internal */
158+
/**
159+
* @internal
160+
* @param {?object} params
161+
*/
157162
rpc(params?: object): PostgrestBuilder<T> {
158163
this.method = 'POST'
159164
this.body = params
@@ -169,10 +174,10 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
169174
/**
170175
* Orders the result with the specified `column`.
171176
*
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).
177+
* @param {T} column - The column to order on.
178+
* @param {?boolean} ascending - If `true`, the result will be in ascending order.
179+
* @param {?boolean} nullsFirst - If `true`, `null`s appear first.
180+
* @param {?string} foreignTable - The foreign table to use (if `column` is a foreign column).
176181
*/
177182
order(
178183
column: keyof T,
@@ -193,8 +198,8 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
193198
/**
194199
* Limits the result with the specified `count`.
195200
*
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).
201+
* @param {number} count - The maximum no. of rows to limit to.
202+
* @param {?string} object.foreignTable - The foreign table to use (for foreign columns).
198203
*/
199204
limit(
200205
count: number,
@@ -208,9 +213,9 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
208213
/**
209214
* Limits the result to rows within the specified range, inclusive.
210215
*
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).
216+
* @param {number} from - The starting index from which to limit the result, inclusive.
217+
* @param {number} to - The last index to which to limit the result, inclusive.
218+
* @param {?string} foreignTable - The foreign table to use (for foreign columns).
214219
*/
215220
range(
216221
from: number,
@@ -269,9 +274,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
269274
/**
270275
* Finds all rows which doesn't satisfy the filter.
271276
*
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.
277+
* @param {T} column - The column to filter on.
278+
* @param {FilterOperator} operator - The operator to filter with.
279+
* @param {*} value - The value to filter with.
275280
*/
276281
not(column: keyof T, operator: FilterOperator, value: any): this {
277282
this.url.searchParams.append(`${column}`, `not.${operator}.${value}`)
@@ -281,7 +286,7 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
281286
/**
282287
* Finds all rows satisfying at least one of the filters.
283288
*
284-
* @param {string} filters The filters to use, separated by commas.
289+
* @param {string} filters - The filters to use, separated by commas.
285290
*/
286291
or(filters: string): this {
287292
this.url.searchParams.append('or', `(${filters})`)
@@ -292,8 +297,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
292297
* Finds all rows whose value on the stated `column` exactly matches the
293298
* specified `value`.
294299
*
295-
* @param {T} column The column to filter on.
296-
* @param {T[]} value The value to filter with.
300+
* @param {T} column - The column to filter on.
301+
* @param {T[]} value - The value to filter with.
297302
*/
298303
eq(column: keyof T, value: T[keyof T]): this {
299304
this.url.searchParams.append(`${column}`, `eq.${value}`)
@@ -304,8 +309,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
304309
* Finds all rows whose value on the stated `column` doesn't match the
305310
* specified `value`.
306311
*
307-
* @param {T} column The column to filter on.
308-
* @param {T[]} value The value to filter with.
312+
* @param {T} column - The column to filter on.
313+
* @param {T[]} value - The value to filter with.
309314
*/
310315
neq(column: keyof T, value: T[keyof T]): this {
311316
this.url.searchParams.append(`${column}`, `neq.${value}`)
@@ -316,8 +321,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
316321
* Finds all rows whose value on the stated `column` is greater than the
317322
* specified `value`.
318323
*
319-
* @param {T} column The column to filter on.
320-
* @param {T[]} value The value to filter with.
324+
* @param {T} column - The column to filter on.
325+
* @param {T[]} value - The value to filter with.
321326
*/
322327
gt(column: keyof T, value: T[keyof T]): this {
323328
this.url.searchParams.append(`${column}`, `gt.${value}`)
@@ -328,8 +333,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
328333
* Finds all rows whose value on the stated `column` is greater than or
329334
* equal to the specified `value`.
330335
*
331-
* @param {T} column The column to filter on.
332-
* @param {T[]} value The value to filter with.
336+
* @param {T} column - The column to filter on.
337+
* @param {T[]} value - The value to filter with.
333338
*/
334339
gte(column: keyof T, value: T[keyof T]): this {
335340
this.url.searchParams.append(`${column}`, `gte.${value}`)
@@ -340,8 +345,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
340345
* Finds all rows whose value on the stated `column` is less than the
341346
* specified `value`.
342347
*
343-
* @param {T} column The column to filter on.
344-
* @param {T[]} value The value to filter with.
348+
* @param {T} column - The column to filter on.
349+
* @param {T[]} value - The value to filter with.
345350
*/
346351
lt(column: keyof T, value: T[keyof T]): this {
347352
this.url.searchParams.append(`${column}`, `lt.${value}`)
@@ -352,8 +357,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
352357
* Finds all rows whose value on the stated `column` is less than or equal
353358
* to the specified `value`.
354359
*
355-
* @param {T} column The column to filter on.
356-
* @param {T[]} value The value to filter with.
360+
* @param {T} column - The column to filter on.
361+
* @param {T[]} value - The value to filter with.
357362
*/
358363
lte(column: keyof T, value: T[keyof T]): this {
359364
this.url.searchParams.append(`${column}`, `lte.${value}`)
@@ -364,8 +369,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
364369
* Finds all rows whose value in the stated `column` matches the supplied
365370
* `pattern` (case sensitive).
366371
*
367-
* @param {T} column The column to filter on.
368-
* @param {string} pattern The pattern to filter with.
372+
* @param {T} column - The column to filter on.
373+
* @param {string} pattern - The pattern to filter with.
369374
*/
370375
like(column: keyof T, pattern: string): this {
371376
this.url.searchParams.append(`${column}`, `like.${pattern}`)
@@ -376,8 +381,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
376381
* Finds all rows whose value in the stated `column` matches the supplied
377382
* `pattern` (case insensitive).
378383
*
379-
* @param {T} column The column to filter on.
380-
* @param {string} pattern The pattern to filter with.
384+
* @param {T} column - The column to filter on.
385+
* @param {string} pattern - The pattern to filter with.
381386
*/
382387
ilike(column: keyof T, pattern: string): this {
383388
this.url.searchParams.append(`${column}`, `ilike.${pattern}`)
@@ -388,8 +393,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
388393
* A check for exact equality (null, true, false), finds all rows whose
389394
* value on the stated `column` exactly match the specified `value`.
390395
*
391-
* @param {T} column The column to filter on.
392-
* @param {boolean|null} value The value to filter with.
396+
* @param {T} column - The column to filter on.
397+
* @param {(boolean|null)} value - The value to filter with.
393398
*/
394399
is(column: keyof T, value: boolean | null): this {
395400
this.url.searchParams.append(`${column}`, `is.${value}`)
@@ -400,8 +405,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
400405
* Finds all rows whose value on the stated `column` is found on the
401406
* specified `values`.
402407
*
403-
* @param {T} column The column to filter on.
404-
* @param {T[]} values The values to filter with.
408+
* @param {T} column - The column to filter on.
409+
* @param {T[]} values - The values to filter with.
405410
*/
406411
in(column: keyof T, values: T[keyof T][]): this {
407412
this.url.searchParams.append(`${column}`, `in.(${cleanFilterArray(values)})`)
@@ -412,8 +417,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
412417
* Finds all rows whose json, array, or range value on the stated `column`
413418
* contains the values specified in `value`.
414419
*
415-
* @param {T} column The column to filter on.
416-
* @param {string|T[]|object} value The value to filter with.
420+
* @param {T} column - The column to filter on.
421+
* @param {(string|T[][]|object)} value - The value to filter with.
417422
*/
418423
cs(column: keyof T, value: string | T[keyof T][] | object): this {
419424
if (typeof value === 'string') {
@@ -434,8 +439,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
434439
* Finds all rows whose json, array, or range value on the stated `column` is
435440
* contained by the specified `value`.
436441
*
437-
* @param {T} column The column to filter on.
438-
* @param {string|T[]|object} value The value to filter with.
442+
* @param {T} column - The column to filter on.
443+
* @param {string|T[][]|object} value - The value to filter with.
439444
*/
440445
cd(column: keyof T, value: string | T[keyof T][] | object): this {
441446
if (typeof value === 'string') {
@@ -455,8 +460,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
455460
* Finds all rows whose range value on the stated `column` is strictly to the
456461
* left of the specified `range`.
457462
*
458-
* @param {T} column The column to filter on.
459-
* @param {string} range The range to filter with.
463+
* @param {T} column - The column to filter on.
464+
* @param {string} range - The range to filter with.
460465
*/
461466
sl(column: keyof T, range: string): this {
462467
this.url.searchParams.append(`${column}`, `sl.${range}`)
@@ -467,8 +472,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
467472
* Finds all rows whose range value on the stated `column` is strictly to
468473
* the right of the specified `range`.
469474
*
470-
* @param {T} column The column to filter on.
471-
* @param {string} range The range to filter with.
475+
* @param {T} column - The column to filter on.
476+
* @param {string} range - The range to filter with.
472477
*/
473478
sr(column: keyof T, range: string): this {
474479
this.url.searchParams.append(`${column}`, `sr.${range}`)
@@ -479,8 +484,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
479484
* Finds all rows whose range value on the stated `column` does not extend
480485
* to the left of the specified `range`.
481486
*
482-
* @param {T} column The column to filter on.
483-
* @param {string} range The range to filter with.
487+
* @param {T} column - The column to filter on.
488+
* @param {string} range - The range to filter with.
484489
*/
485490
nxl(column: keyof T, range: string): this {
486491
this.url.searchParams.append(`${column}`, `nxl.${range}`)
@@ -491,8 +496,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
491496
* Finds all rows whose range value on the stated `column` does not extend
492497
* to the right of the specified `range`.
493498
*
494-
* @param {T} column The column to filter on.
495-
* @param {string} range The range to filter with.
499+
* @param {T} column - The column to filter on.
500+
* @param {string} range - The range to filter with.
496501
*/
497502
nxr(column: keyof T, range: string): this {
498503
this.url.searchParams.append(`${column}`, `nxr.${range}`)
@@ -503,8 +508,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
503508
* Finds all rows whose range value on the stated `column` is adjacent to
504509
* the specified `range`.
505510
*
506-
* @param {T} column The column to filter on.
507-
* @param {string} range The range to filter with.
511+
* @param {T} column - The column to filter on.
512+
* @param {string} range - The range to filter with.
508513
*/
509514
adj(column: keyof T, range: string): this {
510515
this.url.searchParams.append(`${column}`, `adj.${range}`)
@@ -515,8 +520,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
515520
* Finds all rows whose array or range value on the stated `column` is
516521
* contained by the specified `value`.
517522
*
518-
* @param {T} column The column to filter on.
519-
* @param {string|T[]} value The value to filter with.
523+
* @param {T} column - The column to filter on.
524+
* @param {string|T[][]} value - The value to filter with.
520525
*/
521526
ov(column: keyof T, value: string | T[keyof T][]): this {
522527
if (typeof value === 'string') {
@@ -533,9 +538,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
533538
* Finds all rows whose tsvector value on the stated `column` matches
534539
* to_tsquery(`query`).
535540
*
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.
541+
* @param {T} column - The column to filter on.
542+
* @param {string} query - The Postgres tsquery string to filter with.
543+
* @param {?string} config - The text search configuration to use.
539544
*/
540545
fts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
541546
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -547,9 +552,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
547552
* Finds all rows whose tsvector value on the stated `column` matches
548553
* plainto_tsquery(`query`).
549554
*
550-
* @param {*} column The column to filter on.
551-
* @param {} query The Postgres tsquery string to filter with.
552-
* @param config The text search configuration to use.
555+
* @param {*} column - The column to filter on.
556+
* @param {string} query - The Postgres tsquery string to filter with.
557+
* @param {?string} config - The text search configuration to use.
553558
*/
554559
plfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
555560
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -561,9 +566,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
561566
* Finds all rows whose tsvector value on the stated `column` matches
562567
* phraseto_tsquery(`query`).
563568
*
564-
* @param column The column to filter on.
565-
* @param query The Postgres tsquery string to filter with.
566-
* @param config The text search configuration to use.
569+
* @param {T} column - The column to filter on.
570+
* @param {string} query - The Postgres tsquery string to filter with.
571+
* @param {?string} config - The text search configuration to use.
567572
*/
568573
phfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
569574
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -575,9 +580,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
575580
* Finds all rows whose tsvector value on the stated `column` matches
576581
* websearch_to_tsquery(`query`).
577582
*
578-
* @param column The column to filter on.
579-
* @param query The Postgres tsquery string to filter with.
580-
* @param config The text search configuration to use.
583+
* @param {T} column - The column to filter on.
584+
* @param {string}query - The Postgres tsquery string to filter with.
585+
* @param {?string} config - The text search configuration to use.
581586
*/
582587
wfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
583588
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -588,9 +593,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
588593
/**
589594
* Finds all rows whose `column` satisfies the filter.
590595
*
591-
* @param column The column to filter on.
592-
* @param operator The operator to filter with.
593-
* @param value The value to filter with.
596+
* @param {T} column - The column to filter on.
597+
* @param {FilterOperator} operator - The operator to filter with.
598+
* @param {*} value - The value to filter with.
594599
*/
595600
filter(column: keyof T, operator: FilterOperator, value: any): this {
596601
this.url.searchParams.append(`${column}`, `${operator}.${value}`)
@@ -600,7 +605,7 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
600605
/**
601606
* Finds all rows whose columns match the specified `query` object.
602607
*
603-
* @param query The object to filter with, with column names as keys mapped
608+
* @param {object} query - The object to filter with, with column names as keys mapped
604609
* to their filter values.
605610
*/
606611
match(query: { [key: string]: string }) {

0 commit comments

Comments
 (0)