@@ -2,6 +2,7 @@ import fetch from 'cross-fetch'
2
2
3
3
/**
4
4
* Error format
5
+ *
5
6
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
6
7
*/
7
8
interface PostgrestError {
@@ -13,6 +14,7 @@ interface PostgrestError {
13
14
14
15
/**
15
16
* Response format
17
+ *
16
18
* {@link https://github.com/supabase/supabase-js/issues/32}
17
19
*/
18
20
interface PostgrestResponse < T > {
@@ -95,7 +97,7 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
95
97
/**
96
98
* Performs horizontal filtering with SELECT.
97
99
*
98
- * @param {string } columns The columns to retrieve, separated by commas.
100
+ * @param {string } columns - The columns to retrieve, separated by commas.
99
101
*/
100
102
select ( columns = '*' ) : PostgrestFilterBuilder < T > {
101
103
this . method = 'GET'
@@ -120,8 +122,8 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
120
122
/**
121
123
* Performs an INSERT into the table.
122
124
*
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.
125
127
*/
126
128
insert ( values : Partial < T > | Partial < T > [ ] , { upsert = false } = { } ) : PostgrestBuilder < T > {
127
129
this . method = 'POST'
@@ -135,7 +137,7 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
135
137
/**
136
138
* Performs an UPDATE on the table.
137
139
*
138
- * @param {Partial<T> } values The values to update.
140
+ * @param {Partial<T> } values - The values to update.
139
141
*/
140
142
update ( values : Partial < T > ) : PostgrestFilterBuilder < T > {
141
143
this . method = 'PATCH'
@@ -153,7 +155,10 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
153
155
return new PostgrestFilterBuilder ( this )
154
156
}
155
157
156
- /** @internal */
158
+ /**
159
+ * @internal
160
+ * @param {?object } params
161
+ */
157
162
rpc ( params ?: object ) : PostgrestBuilder < T > {
158
163
this . method = 'POST'
159
164
this . body = params
@@ -169,10 +174,10 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
169
174
/**
170
175
* Orders the result with the specified `column`.
171
176
*
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).
176
181
*/
177
182
order (
178
183
column : keyof T ,
@@ -193,8 +198,8 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
193
198
/**
194
199
* Limits the result with the specified `count`.
195
200
*
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).
198
203
*/
199
204
limit (
200
205
count : number ,
@@ -208,9 +213,9 @@ class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
208
213
/**
209
214
* Limits the result to rows within the specified range, inclusive.
210
215
*
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).
214
219
*/
215
220
range (
216
221
from : number ,
@@ -269,9 +274,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
269
274
/**
270
275
* Finds all rows which doesn't satisfy the filter.
271
276
*
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.
275
280
*/
276
281
not ( column : keyof T , operator : FilterOperator , value : any ) : this {
277
282
this . url . searchParams . append ( `${ column } ` , `not.${ operator } .${ value } ` )
@@ -281,7 +286,7 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
281
286
/**
282
287
* Finds all rows satisfying at least one of the filters.
283
288
*
284
- * @param {string } filters The filters to use, separated by commas.
289
+ * @param {string } filters - The filters to use, separated by commas.
285
290
*/
286
291
or ( filters : string ) : this {
287
292
this . url . searchParams . append ( 'or' , `(${ filters } )` )
@@ -292,8 +297,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
292
297
* Finds all rows whose value on the stated `column` exactly matches the
293
298
* specified `value`.
294
299
*
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.
297
302
*/
298
303
eq ( column : keyof T , value : T [ keyof T ] ) : this {
299
304
this . url . searchParams . append ( `${ column } ` , `eq.${ value } ` )
@@ -304,8 +309,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
304
309
* Finds all rows whose value on the stated `column` doesn't match the
305
310
* specified `value`.
306
311
*
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.
309
314
*/
310
315
neq ( column : keyof T , value : T [ keyof T ] ) : this {
311
316
this . url . searchParams . append ( `${ column } ` , `neq.${ value } ` )
@@ -316,8 +321,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
316
321
* Finds all rows whose value on the stated `column` is greater than the
317
322
* specified `value`.
318
323
*
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.
321
326
*/
322
327
gt ( column : keyof T , value : T [ keyof T ] ) : this {
323
328
this . url . searchParams . append ( `${ column } ` , `gt.${ value } ` )
@@ -328,8 +333,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
328
333
* Finds all rows whose value on the stated `column` is greater than or
329
334
* equal to the specified `value`.
330
335
*
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.
333
338
*/
334
339
gte ( column : keyof T , value : T [ keyof T ] ) : this {
335
340
this . url . searchParams . append ( `${ column } ` , `gte.${ value } ` )
@@ -340,8 +345,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
340
345
* Finds all rows whose value on the stated `column` is less than the
341
346
* specified `value`.
342
347
*
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.
345
350
*/
346
351
lt ( column : keyof T , value : T [ keyof T ] ) : this {
347
352
this . url . searchParams . append ( `${ column } ` , `lt.${ value } ` )
@@ -352,8 +357,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
352
357
* Finds all rows whose value on the stated `column` is less than or equal
353
358
* to the specified `value`.
354
359
*
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.
357
362
*/
358
363
lte ( column : keyof T , value : T [ keyof T ] ) : this {
359
364
this . url . searchParams . append ( `${ column } ` , `lte.${ value } ` )
@@ -364,8 +369,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
364
369
* Finds all rows whose value in the stated `column` matches the supplied
365
370
* `pattern` (case sensitive).
366
371
*
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.
369
374
*/
370
375
like ( column : keyof T , pattern : string ) : this {
371
376
this . url . searchParams . append ( `${ column } ` , `like.${ pattern } ` )
@@ -376,8 +381,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
376
381
* Finds all rows whose value in the stated `column` matches the supplied
377
382
* `pattern` (case insensitive).
378
383
*
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.
381
386
*/
382
387
ilike ( column : keyof T , pattern : string ) : this {
383
388
this . url . searchParams . append ( `${ column } ` , `ilike.${ pattern } ` )
@@ -388,8 +393,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
388
393
* A check for exact equality (null, true, false), finds all rows whose
389
394
* value on the stated `column` exactly match the specified `value`.
390
395
*
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.
393
398
*/
394
399
is ( column : keyof T , value : boolean | null ) : this {
395
400
this . url . searchParams . append ( `${ column } ` , `is.${ value } ` )
@@ -400,8 +405,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
400
405
* Finds all rows whose value on the stated `column` is found on the
401
406
* specified `values`.
402
407
*
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.
405
410
*/
406
411
in ( column : keyof T , values : T [ keyof T ] [ ] ) : this {
407
412
this . url . searchParams . append ( `${ column } ` , `in.(${ cleanFilterArray ( values ) } )` )
@@ -412,8 +417,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
412
417
* Finds all rows whose json, array, or range value on the stated `column`
413
418
* contains the values specified in `value`.
414
419
*
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.
417
422
*/
418
423
cs ( column : keyof T , value : string | T [ keyof T ] [ ] | object ) : this {
419
424
if ( typeof value === 'string' ) {
@@ -434,8 +439,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
434
439
* Finds all rows whose json, array, or range value on the stated `column` is
435
440
* contained by the specified `value`.
436
441
*
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.
439
444
*/
440
445
cd ( column : keyof T , value : string | T [ keyof T ] [ ] | object ) : this {
441
446
if ( typeof value === 'string' ) {
@@ -455,8 +460,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
455
460
* Finds all rows whose range value on the stated `column` is strictly to the
456
461
* left of the specified `range`.
457
462
*
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.
460
465
*/
461
466
sl ( column : keyof T , range : string ) : this {
462
467
this . url . searchParams . append ( `${ column } ` , `sl.${ range } ` )
@@ -467,8 +472,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
467
472
* Finds all rows whose range value on the stated `column` is strictly to
468
473
* the right of the specified `range`.
469
474
*
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.
472
477
*/
473
478
sr ( column : keyof T , range : string ) : this {
474
479
this . url . searchParams . append ( `${ column } ` , `sr.${ range } ` )
@@ -479,8 +484,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
479
484
* Finds all rows whose range value on the stated `column` does not extend
480
485
* to the left of the specified `range`.
481
486
*
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.
484
489
*/
485
490
nxl ( column : keyof T , range : string ) : this {
486
491
this . url . searchParams . append ( `${ column } ` , `nxl.${ range } ` )
@@ -491,8 +496,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
491
496
* Finds all rows whose range value on the stated `column` does not extend
492
497
* to the right of the specified `range`.
493
498
*
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.
496
501
*/
497
502
nxr ( column : keyof T , range : string ) : this {
498
503
this . url . searchParams . append ( `${ column } ` , `nxr.${ range } ` )
@@ -503,8 +508,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
503
508
* Finds all rows whose range value on the stated `column` is adjacent to
504
509
* the specified `range`.
505
510
*
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.
508
513
*/
509
514
adj ( column : keyof T , range : string ) : this {
510
515
this . url . searchParams . append ( `${ column } ` , `adj.${ range } ` )
@@ -515,8 +520,8 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
515
520
* Finds all rows whose array or range value on the stated `column` is
516
521
* contained by the specified `value`.
517
522
*
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.
520
525
*/
521
526
ov ( column : keyof T , value : string | T [ keyof T ] [ ] ) : this {
522
527
if ( typeof value === 'string' ) {
@@ -533,9 +538,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
533
538
* Finds all rows whose tsvector value on the stated `column` matches
534
539
* to_tsquery(`query`).
535
540
*
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.
539
544
*/
540
545
fts ( column : keyof T , query : string , { config } : { config ?: string } = { } ) : this {
541
546
const configPart = typeof config === 'undefined' ? '' : `(${ config } )`
@@ -547,9 +552,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
547
552
* Finds all rows whose tsvector value on the stated `column` matches
548
553
* plainto_tsquery(`query`).
549
554
*
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.
553
558
*/
554
559
plfts ( column : keyof T , query : string , { config } : { config ?: string } = { } ) : this {
555
560
const configPart = typeof config === 'undefined' ? '' : `(${ config } )`
@@ -561,9 +566,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
561
566
* Finds all rows whose tsvector value on the stated `column` matches
562
567
* phraseto_tsquery(`query`).
563
568
*
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.
567
572
*/
568
573
phfts ( column : keyof T , query : string , { config } : { config ?: string } = { } ) : this {
569
574
const configPart = typeof config === 'undefined' ? '' : `(${ config } )`
@@ -575,9 +580,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
575
580
* Finds all rows whose tsvector value on the stated `column` matches
576
581
* websearch_to_tsquery(`query`).
577
582
*
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.
581
586
*/
582
587
wfts ( column : keyof T , query : string , { config } : { config ?: string } = { } ) : this {
583
588
const configPart = typeof config === 'undefined' ? '' : `(${ config } )`
@@ -588,9 +593,9 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
588
593
/**
589
594
* Finds all rows whose `column` satisfies the filter.
590
595
*
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.
594
599
*/
595
600
filter ( column : keyof T , operator : FilterOperator , value : any ) : this {
596
601
this . url . searchParams . append ( `${ column } ` , `${ operator } .${ value } ` )
@@ -600,7 +605,7 @@ class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder<T> {
600
605
/**
601
606
* Finds all rows whose columns match the specified `query` object.
602
607
*
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
604
609
* to their filter values.
605
610
*/
606
611
match ( query : { [ key : string ] : string } ) {
0 commit comments