@supabase/postgrest-js 2.107.0-beta.1 → 2.107.0-beta.7
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 +95 -2
- 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 +95 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PostgrestBuilder.ts +14 -6
- package/src/PostgrestError.ts +19 -0
- package/src/PostgrestQueryBuilder.ts +63 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/PostgrestBuilder.ts
CHANGED
|
@@ -69,11 +69,9 @@ export default abstract class PostgrestBuilder<
|
|
|
69
69
|
ClientOptions extends ClientServerOptions,
|
|
70
70
|
Result,
|
|
71
71
|
ThrowOnError extends boolean = false,
|
|
72
|
-
> implements
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
>
|
|
76
|
-
{
|
|
72
|
+
> implements PromiseLike<
|
|
73
|
+
ThrowOnError extends true ? PostgrestResponseSuccess<Result> : PostgrestSingleResponse<Result>
|
|
74
|
+
> {
|
|
77
75
|
protected method: 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE'
|
|
78
76
|
protected url: URL
|
|
79
77
|
protected headers: Headers
|
|
@@ -476,7 +474,17 @@ export default abstract class PostgrestBuilder<
|
|
|
476
474
|
) {
|
|
477
475
|
data = body
|
|
478
476
|
} else {
|
|
479
|
-
|
|
477
|
+
try {
|
|
478
|
+
data = JSON.parse(body)
|
|
479
|
+
} catch {
|
|
480
|
+
// A 2xx status doesn't guarantee a JSON body; mirror the non-2xx fallback below.
|
|
481
|
+
error = { message: body }
|
|
482
|
+
data = null
|
|
483
|
+
|
|
484
|
+
if (this.shouldThrowOnError) {
|
|
485
|
+
throw new PostgrestError({ message: body, details: '', hint: '', code: '' })
|
|
486
|
+
}
|
|
487
|
+
}
|
|
480
488
|
}
|
|
481
489
|
}
|
|
482
490
|
|
package/src/PostgrestError.ts
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Error format
|
|
3
3
|
*
|
|
4
|
+
* Returned by every PostgREST request that fails. When something fails, the
|
|
5
|
+
* single most useful field is usually `hint` — Postgres often returns the
|
|
6
|
+
* actionable fix there, not in `message`. Always log the full object (e.g.
|
|
7
|
+
* `console.error(error)`); logging only `error.message` hides the hint.
|
|
8
|
+
*
|
|
9
|
+
* Read the fields in roughly this order of usefulness:
|
|
10
|
+
*
|
|
11
|
+
* - `hint` — actionable guidance from the database when available. For
|
|
12
|
+
* permission-denied errors (`42501`), this is the literal SQL to fix the
|
|
13
|
+
* problem, e.g.
|
|
14
|
+
* `"Grant the required privileges to the current role with: GRANT SELECT ON public.users TO anon;"`.
|
|
15
|
+
* Missing column? `hint` suggests the column you probably meant. Whenever
|
|
16
|
+
* Postgres knows the fix, it puts it in `hint`.
|
|
17
|
+
* - `code` — stable error code from PostgREST (e.g. `PGRST301`) or Postgres
|
|
18
|
+
* (e.g. `42501`). Branch on this rather than on `message` text.
|
|
19
|
+
* - `details` — extra context, often the offending value, key, or row.
|
|
20
|
+
* - `message` — human-readable summary. Useful in UI strings; less useful
|
|
21
|
+
* for debugging.
|
|
22
|
+
*
|
|
4
23
|
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
|
|
5
24
|
*/
|
|
6
25
|
export default class PostgrestError extends Error {
|
|
@@ -169,6 +169,33 @@ export default class PostgrestQueryBuilder<
|
|
|
169
169
|
* }
|
|
170
170
|
* ```
|
|
171
171
|
*
|
|
172
|
+
* @exampleDescription Handling errors
|
|
173
|
+
* 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`.
|
|
174
|
+
*
|
|
175
|
+
* @example Handling errors
|
|
176
|
+
* ```js
|
|
177
|
+
* const { data, error } = await supabase.from('characters').select()
|
|
178
|
+
* if (error) {
|
|
179
|
+
* // Logs the full error: message, code, details, and hint.
|
|
180
|
+
* console.error(error)
|
|
181
|
+
* return
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @exampleResponse Handling errors
|
|
186
|
+
* ```json
|
|
187
|
+
* {
|
|
188
|
+
* "error": {
|
|
189
|
+
* "code": "42501",
|
|
190
|
+
* "details": null,
|
|
191
|
+
* "hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.characters TO anon;",
|
|
192
|
+
* "message": "permission denied for table characters"
|
|
193
|
+
* },
|
|
194
|
+
* "status": 401,
|
|
195
|
+
* "statusText": "Unauthorized"
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
172
199
|
* @example Selecting specific columns
|
|
173
200
|
* ```js
|
|
174
201
|
* const { data, error } = await supabase
|
|
@@ -985,6 +1012,15 @@ export default class PostgrestQueryBuilder<
|
|
|
985
1012
|
* }
|
|
986
1013
|
* ```
|
|
987
1014
|
*
|
|
1015
|
+
* @exampleDescription Handling errors
|
|
1016
|
+
* `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`.
|
|
1017
|
+
*
|
|
1018
|
+
* @example Handling errors
|
|
1019
|
+
* ```js
|
|
1020
|
+
* const { error } = await supabase.from('countries').insert({ id: 1, name: 'Mordor' })
|
|
1021
|
+
* if (error) console.error(error)
|
|
1022
|
+
* ```
|
|
1023
|
+
*
|
|
988
1024
|
* @example Create a record and return it
|
|
989
1025
|
* ```ts
|
|
990
1026
|
* const { data, error } = await supabase
|
|
@@ -1226,6 +1262,15 @@ export default class PostgrestQueryBuilder<
|
|
|
1226
1262
|
* }
|
|
1227
1263
|
* ```
|
|
1228
1264
|
*
|
|
1265
|
+
* @exampleDescription Handling errors
|
|
1266
|
+
* `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`.
|
|
1267
|
+
*
|
|
1268
|
+
* @example Handling errors
|
|
1269
|
+
* ```js
|
|
1270
|
+
* const { data, error } = await supabase.from('instruments').upsert({ id: 1, name: 'piano' }).select()
|
|
1271
|
+
* if (error) console.error(error)
|
|
1272
|
+
* ```
|
|
1273
|
+
*
|
|
1229
1274
|
* @example Bulk Upsert your data
|
|
1230
1275
|
* ```ts
|
|
1231
1276
|
* const { data, error } = await supabase
|
|
@@ -1428,6 +1473,15 @@ export default class PostgrestQueryBuilder<
|
|
|
1428
1473
|
* }
|
|
1429
1474
|
* ```
|
|
1430
1475
|
*
|
|
1476
|
+
* @exampleDescription Handling errors
|
|
1477
|
+
* `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`.
|
|
1478
|
+
*
|
|
1479
|
+
* @example Handling errors
|
|
1480
|
+
* ```js
|
|
1481
|
+
* const { error } = await supabase.from('instruments').update({ name: 'piano' }).eq('id', 1)
|
|
1482
|
+
* if (error) console.error(error)
|
|
1483
|
+
* ```
|
|
1484
|
+
*
|
|
1431
1485
|
* @example Update a record and return it
|
|
1432
1486
|
* ```ts
|
|
1433
1487
|
* const { data, error } = await supabase
|
|
@@ -1609,6 +1663,15 @@ export default class PostgrestQueryBuilder<
|
|
|
1609
1663
|
* }
|
|
1610
1664
|
* ```
|
|
1611
1665
|
*
|
|
1666
|
+
* @exampleDescription Handling errors
|
|
1667
|
+
* `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`.
|
|
1668
|
+
*
|
|
1669
|
+
* @example Handling errors
|
|
1670
|
+
* ```js
|
|
1671
|
+
* const { error } = await supabase.from('countries').delete().eq('id', 1)
|
|
1672
|
+
* if (error) console.error(error)
|
|
1673
|
+
* ```
|
|
1674
|
+
*
|
|
1612
1675
|
* @example Delete a record and return it
|
|
1613
1676
|
* ```ts
|
|
1614
1677
|
* const { data, error } = await supabase
|
package/src/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// - Debugging and support (identifying which version is running)
|
|
5
5
|
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
6
|
// - Ensuring build artifacts match the published package version
|
|
7
|
-
export const version = '2.107.0-beta.
|
|
7
|
+
export const version = '2.107.0-beta.7'
|