@supabase/postgrest-js 2.99.2 → 2.99.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2475 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1055 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1055 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2475 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PostgrestBuilder.ts +93 -1
- package/src/PostgrestClient.ts +165 -1
- package/src/PostgrestFilterBuilder.ts +1382 -3
- package/src/PostgrestQueryBuilder.ts +112 -1
- package/src/PostgrestTransformBuilder.ts +603 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/PostgrestBuilder.ts
CHANGED
|
@@ -34,7 +34,19 @@ export default abstract class PostgrestBuilder<
|
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
* ```ts
|
|
37
|
-
* import PostgrestQueryBuilder from '@supabase/postgrest-js'
|
|
37
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
38
|
+
*
|
|
39
|
+
* const builder = new PostgrestQueryBuilder(
|
|
40
|
+
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
41
|
+
* { headers: new Headers({ apikey: 'public-anon-key' }) }
|
|
42
|
+
* )
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @category Database
|
|
46
|
+
*
|
|
47
|
+
* @example Example 1
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
38
50
|
*
|
|
39
51
|
* const builder = new PostgrestQueryBuilder(
|
|
40
52
|
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
@@ -76,6 +88,8 @@ export default abstract class PostgrestBuilder<
|
|
|
76
88
|
* throwing the error instead of returning it as part of a successful response.
|
|
77
89
|
*
|
|
78
90
|
* {@link https://github.com/supabase/supabase-js/issues/92}
|
|
91
|
+
*
|
|
92
|
+
* @category Database
|
|
79
93
|
*/
|
|
80
94
|
throwOnError(): this & PostgrestBuilder<ClientOptions, Result, true> {
|
|
81
95
|
this.shouldThrowOnError = true
|
|
@@ -84,6 +98,8 @@ export default abstract class PostgrestBuilder<
|
|
|
84
98
|
|
|
85
99
|
/**
|
|
86
100
|
* Set an HTTP header for the request.
|
|
101
|
+
*
|
|
102
|
+
* @category Database
|
|
87
103
|
*/
|
|
88
104
|
setHeader(name: string, value: string): this {
|
|
89
105
|
this.headers = new Headers(this.headers)
|
|
@@ -91,6 +107,9 @@ export default abstract class PostgrestBuilder<
|
|
|
91
107
|
return this
|
|
92
108
|
}
|
|
93
109
|
|
|
110
|
+
/** *
|
|
111
|
+
* @category Database
|
|
112
|
+
*/
|
|
94
113
|
then<
|
|
95
114
|
TResult1 = ThrowOnError extends true
|
|
96
115
|
? PostgrestResponseSuccess<Result>
|
|
@@ -300,6 +319,8 @@ export default abstract class PostgrestBuilder<
|
|
|
300
319
|
*
|
|
301
320
|
* @typeParam NewResult - The new result type to override with
|
|
302
321
|
* @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
|
|
322
|
+
*
|
|
323
|
+
* @category Database
|
|
303
324
|
*/
|
|
304
325
|
returns<NewResult>(): PostgrestBuilder<
|
|
305
326
|
ClientOptions,
|
|
@@ -335,6 +356,77 @@ export default abstract class PostgrestBuilder<
|
|
|
335
356
|
* .overrideTypes<{ id: number; name: string }, { merge: false }>()
|
|
336
357
|
* ```
|
|
337
358
|
* @returns A PostgrestBuilder instance with the new type
|
|
359
|
+
*
|
|
360
|
+
* @category Database
|
|
361
|
+
*
|
|
362
|
+
* @example Complete Override type of successful response
|
|
363
|
+
* ```ts
|
|
364
|
+
* const { data } = await supabase
|
|
365
|
+
* .from('countries')
|
|
366
|
+
* .select()
|
|
367
|
+
* .overrideTypes<Array<MyType>, { merge: false }>()
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @exampleResponse Complete Override type of successful response
|
|
371
|
+
* ```ts
|
|
372
|
+
* let x: typeof data // MyType[]
|
|
373
|
+
* ```
|
|
374
|
+
*
|
|
375
|
+
* @example Complete Override type of object response
|
|
376
|
+
* ```ts
|
|
377
|
+
* const { data } = await supabase
|
|
378
|
+
* .from('countries')
|
|
379
|
+
* .select()
|
|
380
|
+
* .maybeSingle()
|
|
381
|
+
* .overrideTypes<MyType, { merge: false }>()
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* @exampleResponse Complete Override type of object response
|
|
385
|
+
* ```ts
|
|
386
|
+
* let x: typeof data // MyType | null
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* @example Partial Override type of successful response
|
|
390
|
+
* ```ts
|
|
391
|
+
* const { data } = await supabase
|
|
392
|
+
* .from('countries')
|
|
393
|
+
* .select()
|
|
394
|
+
* .overrideTypes<Array<{ status: "A" | "B" }>>()
|
|
395
|
+
* ```
|
|
396
|
+
*
|
|
397
|
+
* @exampleResponse Partial Override type of successful response
|
|
398
|
+
* ```ts
|
|
399
|
+
* let x: typeof data // Array<CountryRowProperties & { status: "A" | "B" }>
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* @example Partial Override type of object response
|
|
403
|
+
* ```ts
|
|
404
|
+
* const { data } = await supabase
|
|
405
|
+
* .from('countries')
|
|
406
|
+
* .select()
|
|
407
|
+
* .maybeSingle()
|
|
408
|
+
* .overrideTypes<{ status: "A" | "B" }>()
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* @exampleResponse Partial Override type of object response
|
|
412
|
+
* ```ts
|
|
413
|
+
* let x: typeof data // CountryRowProperties & { status: "A" | "B" } | null
|
|
414
|
+
* ```
|
|
415
|
+
*
|
|
416
|
+
* @example Example 5
|
|
417
|
+
* ```typescript
|
|
418
|
+
* // Merge with existing types (default behavior)
|
|
419
|
+
* const query = supabase
|
|
420
|
+
* .from('users')
|
|
421
|
+
* .select()
|
|
422
|
+
* .overrideTypes<{ custom_field: string }>()
|
|
423
|
+
*
|
|
424
|
+
* // Replace existing types completely
|
|
425
|
+
* const replaceQuery = supabase
|
|
426
|
+
* .from('users')
|
|
427
|
+
* .select()
|
|
428
|
+
* .overrideTypes<{ id: number; name: string }, { merge: false }>()
|
|
429
|
+
* ```
|
|
338
430
|
*/
|
|
339
431
|
overrideTypes<
|
|
340
432
|
NewResult,
|
package/src/PostgrestClient.ts
CHANGED
|
@@ -53,7 +53,34 @@ export default class PostgrestClient<
|
|
|
53
53
|
* @param options.urlLengthLimit - Maximum URL length in characters before warnings/errors are triggered. Defaults to 8000.
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
56
|
-
* import PostgrestClient from '@supabase/postgrest-js'
|
|
56
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
57
|
+
*
|
|
58
|
+
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
59
|
+
* headers: { apikey: 'public-anon-key' },
|
|
60
|
+
* schema: 'public',
|
|
61
|
+
* timeout: 30000, // 30 second timeout
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @category Database
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* - A `timeout` option (in milliseconds) can be set to automatically abort requests that take too long.
|
|
69
|
+
* - A `urlLengthLimit` option (default: 8000) can be set to control when URL length warnings are included in error messages for aborted requests.
|
|
70
|
+
*
|
|
71
|
+
* @example Example 1
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
74
|
+
*
|
|
75
|
+
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
76
|
+
* headers: { apikey: 'public-anon-key' },
|
|
77
|
+
* schema: 'public',
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example With timeout
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
57
84
|
*
|
|
58
85
|
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
59
86
|
* headers: { apikey: 'public-anon-key' },
|
|
@@ -136,6 +163,8 @@ export default class PostgrestClient<
|
|
|
136
163
|
* Perform a query on a table or a view.
|
|
137
164
|
*
|
|
138
165
|
* @param relation - The table or view name to query
|
|
166
|
+
*
|
|
167
|
+
* @category Database
|
|
139
168
|
*/
|
|
140
169
|
from(
|
|
141
170
|
relation: (string & keyof Schema['Tables']) | (string & keyof Schema['Views'])
|
|
@@ -159,6 +188,8 @@ export default class PostgrestClient<
|
|
|
159
188
|
* The schema needs to be on the list of exposed schemas inside Supabase.
|
|
160
189
|
*
|
|
161
190
|
* @param schema - The schema to query
|
|
191
|
+
*
|
|
192
|
+
* @category Database
|
|
162
193
|
*/
|
|
163
194
|
schema<DynamicSchema extends string & keyof Omit<Database, '__InternalSupabase'>>(
|
|
164
195
|
schema: DynamicSchema
|
|
@@ -207,6 +238,139 @@ export default class PostgrestClient<
|
|
|
207
238
|
* .rpc('function_a', {})
|
|
208
239
|
* .overrideTypes<{ id: string; user_id: string }[]>()
|
|
209
240
|
* ```
|
|
241
|
+
*
|
|
242
|
+
* @category Database
|
|
243
|
+
*
|
|
244
|
+
* @example Call a Postgres function without arguments
|
|
245
|
+
* ```ts
|
|
246
|
+
* const { data, error } = await supabase.rpc('hello_world')
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @exampleSql Call a Postgres function without arguments
|
|
250
|
+
* ```sql
|
|
251
|
+
* create function hello_world() returns text as $$
|
|
252
|
+
* select 'Hello world';
|
|
253
|
+
* $$ language sql;
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* @exampleResponse Call a Postgres function without arguments
|
|
257
|
+
* ```json
|
|
258
|
+
* {
|
|
259
|
+
* "data": "Hello world",
|
|
260
|
+
* "status": 200,
|
|
261
|
+
* "statusText": "OK"
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @example Call a Postgres function with arguments
|
|
266
|
+
* ```ts
|
|
267
|
+
* const { data, error } = await supabase.rpc('echo', { say: '👋' })
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @exampleSql Call a Postgres function with arguments
|
|
271
|
+
* ```sql
|
|
272
|
+
* create function echo(say text) returns text as $$
|
|
273
|
+
* select say;
|
|
274
|
+
* $$ language sql;
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
277
|
+
* @exampleResponse Call a Postgres function with arguments
|
|
278
|
+
* ```json
|
|
279
|
+
* {
|
|
280
|
+
* "data": "👋",
|
|
281
|
+
* "status": 200,
|
|
282
|
+
* "statusText": "OK"
|
|
283
|
+
* }
|
|
284
|
+
*
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @exampleDescription Bulk processing
|
|
288
|
+
* You can process large payloads by passing in an array as an argument.
|
|
289
|
+
*
|
|
290
|
+
* @example Bulk processing
|
|
291
|
+
* ```ts
|
|
292
|
+
* const { data, error } = await supabase.rpc('add_one_each', { arr: [1, 2, 3] })
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @exampleSql Bulk processing
|
|
296
|
+
* ```sql
|
|
297
|
+
* create function add_one_each(arr int[]) returns int[] as $$
|
|
298
|
+
* select array_agg(n + 1) from unnest(arr) as n;
|
|
299
|
+
* $$ language sql;
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @exampleResponse Bulk processing
|
|
303
|
+
* ```json
|
|
304
|
+
* {
|
|
305
|
+
* "data": [
|
|
306
|
+
* 2,
|
|
307
|
+
* 3,
|
|
308
|
+
* 4
|
|
309
|
+
* ],
|
|
310
|
+
* "status": 200,
|
|
311
|
+
* "statusText": "OK"
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @exampleDescription Call a Postgres function with filters
|
|
316
|
+
* Postgres functions that return tables can also be combined with [Filters](/docs/reference/javascript/using-filters) and [Modifiers](/docs/reference/javascript/using-modifiers).
|
|
317
|
+
*
|
|
318
|
+
* @example Call a Postgres function with filters
|
|
319
|
+
* ```ts
|
|
320
|
+
* const { data, error } = await supabase
|
|
321
|
+
* .rpc('list_stored_countries')
|
|
322
|
+
* .eq('id', 1)
|
|
323
|
+
* .single()
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @exampleSql Call a Postgres function with filters
|
|
327
|
+
* ```sql
|
|
328
|
+
* create table
|
|
329
|
+
* countries (id int8 primary key, name text);
|
|
330
|
+
*
|
|
331
|
+
* insert into
|
|
332
|
+
* countries (id, name)
|
|
333
|
+
* values
|
|
334
|
+
* (1, 'Rohan'),
|
|
335
|
+
* (2, 'The Shire');
|
|
336
|
+
*
|
|
337
|
+
* create function list_stored_countries() returns setof countries as $$
|
|
338
|
+
* select * from countries;
|
|
339
|
+
* $$ language sql;
|
|
340
|
+
* ```
|
|
341
|
+
*
|
|
342
|
+
* @exampleResponse Call a Postgres function with filters
|
|
343
|
+
* ```json
|
|
344
|
+
* {
|
|
345
|
+
* "data": {
|
|
346
|
+
* "id": 1,
|
|
347
|
+
* "name": "Rohan"
|
|
348
|
+
* },
|
|
349
|
+
* "status": 200,
|
|
350
|
+
* "statusText": "OK"
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @example Call a read-only Postgres function
|
|
355
|
+
* ```ts
|
|
356
|
+
* const { data, error } = await supabase.rpc('hello_world', undefined, { get: true })
|
|
357
|
+
* ```
|
|
358
|
+
*
|
|
359
|
+
* @exampleSql Call a read-only Postgres function
|
|
360
|
+
* ```sql
|
|
361
|
+
* create function hello_world() returns text as $$
|
|
362
|
+
* select 'Hello world';
|
|
363
|
+
* $$ language sql;
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* @exampleResponse Call a read-only Postgres function
|
|
367
|
+
* ```json
|
|
368
|
+
* {
|
|
369
|
+
* "data": "Hello world",
|
|
370
|
+
* "status": 200,
|
|
371
|
+
* "statusText": "OK"
|
|
372
|
+
* }
|
|
373
|
+
* ```
|
|
210
374
|
*/
|
|
211
375
|
rpc<
|
|
212
376
|
FnName extends string & keyof Schema['Functions'],
|