@supabase/postgrest-js 2.107.0-canary.0 → 2.107.0-canary.2
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 +82 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +82 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +82 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PostgrestError.ts +19 -0
- package/src/PostgrestQueryBuilder.ts +63 -0
- package/src/version.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,25 @@ const RETRYABLE_METHODS = [
|
|
|
33
33
|
/**
|
|
34
34
|
* Error format
|
|
35
35
|
*
|
|
36
|
+
* Returned by every PostgREST request that fails. When something fails, the
|
|
37
|
+
* single most useful field is usually `hint` — Postgres often returns the
|
|
38
|
+
* actionable fix there, not in `message`. Always log the full object (e.g.
|
|
39
|
+
* `console.error(error)`); logging only `error.message` hides the hint.
|
|
40
|
+
*
|
|
41
|
+
* Read the fields in roughly this order of usefulness:
|
|
42
|
+
*
|
|
43
|
+
* - `hint` — actionable guidance from the database when available. For
|
|
44
|
+
* permission-denied errors (`42501`), this is the literal SQL to fix the
|
|
45
|
+
* problem, e.g.
|
|
46
|
+
* `"Grant the required privileges to the current role with: GRANT SELECT ON public.users TO anon;"`.
|
|
47
|
+
* Missing column? `hint` suggests the column you probably meant. Whenever
|
|
48
|
+
* Postgres knows the fix, it puts it in `hint`.
|
|
49
|
+
* - `code` — stable error code from PostgREST (e.g. `PGRST301`) or Postgres
|
|
50
|
+
* (e.g. `42501`). Branch on this rather than on `message` text.
|
|
51
|
+
* - `details` — extra context, often the offending value, key, or row.
|
|
52
|
+
* - `message` — human-readable summary. Useful in UI strings; less useful
|
|
53
|
+
* for debugging.
|
|
54
|
+
*
|
|
36
55
|
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
|
|
37
56
|
*/
|
|
38
57
|
var PostgrestError = class extends Error {
|
|
@@ -3247,6 +3266,33 @@ var PostgrestQueryBuilder = class {
|
|
|
3247
3266
|
* }
|
|
3248
3267
|
* ```
|
|
3249
3268
|
*
|
|
3269
|
+
* @exampleDescription Handling errors
|
|
3270
|
+
* The most useful field on a Postgres error is usually `hint` — when the database knows the fix, it puts the literal SQL there. For example, a permission-denied error (`code: '42501'`) arrives with a `hint` like `"Grant the required privileges to the current role with: GRANT SELECT ON public.characters TO anon;"`. Log the full `error` object so the hint isn't hidden behind `error.message`.
|
|
3271
|
+
*
|
|
3272
|
+
* @example Handling errors
|
|
3273
|
+
* ```js
|
|
3274
|
+
* const { data, error } = await supabase.from('characters').select()
|
|
3275
|
+
* if (error) {
|
|
3276
|
+
* // Logs the full error: message, code, details, and hint.
|
|
3277
|
+
* console.error(error)
|
|
3278
|
+
* return
|
|
3279
|
+
* }
|
|
3280
|
+
* ```
|
|
3281
|
+
*
|
|
3282
|
+
* @exampleResponse Handling errors
|
|
3283
|
+
* ```json
|
|
3284
|
+
* {
|
|
3285
|
+
* "error": {
|
|
3286
|
+
* "code": "42501",
|
|
3287
|
+
* "details": null,
|
|
3288
|
+
* "hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.characters TO anon;",
|
|
3289
|
+
* "message": "permission denied for table characters"
|
|
3290
|
+
* },
|
|
3291
|
+
* "status": 401,
|
|
3292
|
+
* "statusText": "Unauthorized"
|
|
3293
|
+
* }
|
|
3294
|
+
* ```
|
|
3295
|
+
*
|
|
3250
3296
|
* @example Selecting specific columns
|
|
3251
3297
|
* ```js
|
|
3252
3298
|
* const { data, error } = await supabase
|
|
@@ -4024,6 +4070,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4024
4070
|
* }
|
|
4025
4071
|
* ```
|
|
4026
4072
|
*
|
|
4073
|
+
* @exampleDescription Handling errors
|
|
4074
|
+
* `error.hint` from Postgres often contains the actionable fix (e.g. `"Grant the required privileges to the current role with: GRANT INSERT ON public.countries TO anon;"` for a `42501` permission-denied error). Log the full `error` object so it isn't hidden behind `error.message`.
|
|
4075
|
+
*
|
|
4076
|
+
* @example Handling errors
|
|
4077
|
+
* ```js
|
|
4078
|
+
* const { error } = await supabase.from('countries').insert({ id: 1, name: 'Mordor' })
|
|
4079
|
+
* if (error) console.error(error)
|
|
4080
|
+
* ```
|
|
4081
|
+
*
|
|
4027
4082
|
* @example Create a record and return it
|
|
4028
4083
|
* ```ts
|
|
4029
4084
|
* const { data, error } = await supabase
|
|
@@ -4233,6 +4288,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4233
4288
|
* }
|
|
4234
4289
|
* ```
|
|
4235
4290
|
*
|
|
4291
|
+
* @exampleDescription Handling errors
|
|
4292
|
+
* `error.hint` from Postgres often contains the actionable fix (e.g. `"Grant the required privileges to the current role with: GRANT INSERT, UPDATE ON public.instruments TO anon;"` for a `42501` permission-denied error). Log the full `error` object so it isn't hidden behind `error.message`.
|
|
4293
|
+
*
|
|
4294
|
+
* @example Handling errors
|
|
4295
|
+
* ```js
|
|
4296
|
+
* const { data, error } = await supabase.from('instruments').upsert({ id: 1, name: 'piano' }).select()
|
|
4297
|
+
* if (error) console.error(error)
|
|
4298
|
+
* ```
|
|
4299
|
+
*
|
|
4236
4300
|
* @example Bulk Upsert your data
|
|
4237
4301
|
* ```ts
|
|
4238
4302
|
* const { data, error } = await supabase
|
|
@@ -4397,6 +4461,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4397
4461
|
* }
|
|
4398
4462
|
* ```
|
|
4399
4463
|
*
|
|
4464
|
+
* @exampleDescription Handling errors
|
|
4465
|
+
* `error.hint` from Postgres often contains the actionable fix (e.g. `"Grant the required privileges to the current role with: GRANT UPDATE ON public.instruments TO anon;"` for a `42501` permission-denied error). Log the full `error` object so it isn't hidden behind `error.message`.
|
|
4466
|
+
*
|
|
4467
|
+
* @example Handling errors
|
|
4468
|
+
* ```js
|
|
4469
|
+
* const { error } = await supabase.from('instruments').update({ name: 'piano' }).eq('id', 1)
|
|
4470
|
+
* if (error) console.error(error)
|
|
4471
|
+
* ```
|
|
4472
|
+
*
|
|
4400
4473
|
* @example Update a record and return it
|
|
4401
4474
|
* ```ts
|
|
4402
4475
|
* const { data, error } = await supabase
|
|
@@ -4556,6 +4629,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4556
4629
|
* }
|
|
4557
4630
|
* ```
|
|
4558
4631
|
*
|
|
4632
|
+
* @exampleDescription Handling errors
|
|
4633
|
+
* `error.hint` from Postgres often contains the actionable fix (e.g. `"Grant the required privileges to the current role with: GRANT DELETE ON public.countries TO anon;"` for a `42501` permission-denied error). Log the full `error` object so it isn't hidden behind `error.message`.
|
|
4634
|
+
*
|
|
4635
|
+
* @example Handling errors
|
|
4636
|
+
* ```js
|
|
4637
|
+
* const { error } = await supabase.from('countries').delete().eq('id', 1)
|
|
4638
|
+
* if (error) console.error(error)
|
|
4639
|
+
* ```
|
|
4640
|
+
*
|
|
4559
4641
|
* @example Delete a record and return it
|
|
4560
4642
|
* ```ts
|
|
4561
4643
|
* const { data, error } = await supabase
|