@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/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 {
|
|
@@ -351,7 +370,18 @@ var PostgrestBuilder = class {
|
|
|
351
370
|
const body = await res.text();
|
|
352
371
|
if (body === "") {} else if (_this2.headers.get("Accept") === "text/csv") data = body;
|
|
353
372
|
else if (_this2.headers.get("Accept") && ((_this$headers$get = _this2.headers.get("Accept")) === null || _this$headers$get === void 0 ? void 0 : _this$headers$get.includes("application/vnd.pgrst.plan+text"))) data = body;
|
|
354
|
-
else
|
|
373
|
+
else try {
|
|
374
|
+
data = JSON.parse(body);
|
|
375
|
+
} catch (_unused) {
|
|
376
|
+
error = { message: body };
|
|
377
|
+
data = null;
|
|
378
|
+
if (_this2.shouldThrowOnError) throw new PostgrestError({
|
|
379
|
+
message: body,
|
|
380
|
+
details: "",
|
|
381
|
+
hint: "",
|
|
382
|
+
code: ""
|
|
383
|
+
});
|
|
384
|
+
}
|
|
355
385
|
}
|
|
356
386
|
const countHeader = (_this$headers$get2 = _this2.headers.get("Prefer")) === null || _this$headers$get2 === void 0 ? void 0 : _this$headers$get2.match(/count=(exact|planned|estimated)/);
|
|
357
387
|
const contentRange = (_res$headers$get2 = res.headers.get("content-range")) === null || _res$headers$get2 === void 0 ? void 0 : _res$headers$get2.split("/");
|
|
@@ -379,7 +409,7 @@ var PostgrestBuilder = class {
|
|
|
379
409
|
status = 200;
|
|
380
410
|
statusText = "OK";
|
|
381
411
|
}
|
|
382
|
-
} catch (
|
|
412
|
+
} catch (_unused2) {
|
|
383
413
|
if (res.status === 404 && body === "") {
|
|
384
414
|
status = 204;
|
|
385
415
|
statusText = "No Content";
|
|
@@ -3236,6 +3266,33 @@ var PostgrestQueryBuilder = class {
|
|
|
3236
3266
|
* }
|
|
3237
3267
|
* ```
|
|
3238
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
|
+
*
|
|
3239
3296
|
* @example Selecting specific columns
|
|
3240
3297
|
* ```js
|
|
3241
3298
|
* const { data, error } = await supabase
|
|
@@ -4013,6 +4070,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4013
4070
|
* }
|
|
4014
4071
|
* ```
|
|
4015
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
|
+
*
|
|
4016
4082
|
* @example Create a record and return it
|
|
4017
4083
|
* ```ts
|
|
4018
4084
|
* const { data, error } = await supabase
|
|
@@ -4222,6 +4288,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4222
4288
|
* }
|
|
4223
4289
|
* ```
|
|
4224
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
|
+
*
|
|
4225
4300
|
* @example Bulk Upsert your data
|
|
4226
4301
|
* ```ts
|
|
4227
4302
|
* const { data, error } = await supabase
|
|
@@ -4386,6 +4461,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4386
4461
|
* }
|
|
4387
4462
|
* ```
|
|
4388
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
|
+
*
|
|
4389
4473
|
* @example Update a record and return it
|
|
4390
4474
|
* ```ts
|
|
4391
4475
|
* const { data, error } = await supabase
|
|
@@ -4545,6 +4629,15 @@ var PostgrestQueryBuilder = class {
|
|
|
4545
4629
|
* }
|
|
4546
4630
|
* ```
|
|
4547
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
|
+
*
|
|
4548
4641
|
* @example Delete a record and return it
|
|
4549
4642
|
* ```ts
|
|
4550
4643
|
* const { data, error } = await supabase
|