@supabase/postgrest-js 2.93.3 → 2.93.4-canary.1
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 +128 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +15 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +128 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PostgrestBuilder.ts +32 -2
- package/src/PostgrestClient.ts +54 -1
- package/src/PostgrestQueryBuilder.ts +9 -0
- package/src/version.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,7 +46,7 @@ var PostgrestBuilder = class {
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
constructor(builder) {
|
|
49
|
-
var _builder$shouldThrowO, _builder$isMaybeSingl;
|
|
49
|
+
var _builder$shouldThrowO, _builder$isMaybeSingl, _builder$urlLengthLim;
|
|
50
50
|
this.shouldThrowOnError = false;
|
|
51
51
|
this.method = builder.method;
|
|
52
52
|
this.url = builder.url;
|
|
@@ -56,6 +56,7 @@ var PostgrestBuilder = class {
|
|
|
56
56
|
this.shouldThrowOnError = (_builder$shouldThrowO = builder.shouldThrowOnError) !== null && _builder$shouldThrowO !== void 0 ? _builder$shouldThrowO : false;
|
|
57
57
|
this.signal = builder.signal;
|
|
58
58
|
this.isMaybeSingle = (_builder$isMaybeSingl = builder.isMaybeSingle) !== null && _builder$isMaybeSingl !== void 0 ? _builder$isMaybeSingl : false;
|
|
59
|
+
this.urlLengthLimit = (_builder$urlLengthLim = builder.urlLengthLimit) !== null && _builder$urlLengthLim !== void 0 ? _builder$urlLengthLim : 8e3;
|
|
59
60
|
if (builder.fetch) this.fetch = builder.fetch;
|
|
60
61
|
else this.fetch = fetch;
|
|
61
62
|
}
|
|
@@ -154,6 +155,8 @@ var PostgrestBuilder = class {
|
|
|
154
155
|
if (!this.shouldThrowOnError) res = res.catch((fetchError) => {
|
|
155
156
|
var _fetchError$name2;
|
|
156
157
|
let errorDetails = "";
|
|
158
|
+
let hint = "";
|
|
159
|
+
let code = "";
|
|
157
160
|
const cause = fetchError === null || fetchError === void 0 ? void 0 : fetchError.cause;
|
|
158
161
|
if (cause) {
|
|
159
162
|
var _cause$message, _cause$code, _fetchError$name, _cause$name;
|
|
@@ -167,12 +170,22 @@ var PostgrestBuilder = class {
|
|
|
167
170
|
var _fetchError$stack;
|
|
168
171
|
errorDetails = (_fetchError$stack = fetchError === null || fetchError === void 0 ? void 0 : fetchError.stack) !== null && _fetchError$stack !== void 0 ? _fetchError$stack : "";
|
|
169
172
|
}
|
|
173
|
+
const urlLength = this.url.toString().length;
|
|
174
|
+
if ((fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) === "AbortError" || (fetchError === null || fetchError === void 0 ? void 0 : fetchError.code) === "ABORT_ERR") {
|
|
175
|
+
code = "";
|
|
176
|
+
hint = "Request was aborted (timeout or manual cancellation)";
|
|
177
|
+
if (urlLength > this.urlLengthLimit) hint += `. Note: Your request URL is ${urlLength} characters, which may exceed server limits. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [many IDs])), consider using an RPC function to pass values server-side.`;
|
|
178
|
+
} else if ((cause === null || cause === void 0 ? void 0 : cause.name) === "HeadersOverflowError" || (cause === null || cause === void 0 ? void 0 : cause.code) === "UND_ERR_HEADERS_OVERFLOW") {
|
|
179
|
+
code = "";
|
|
180
|
+
hint = "HTTP headers exceeded server limits (typically 16KB)";
|
|
181
|
+
if (urlLength > this.urlLengthLimit) hint += `. Your request URL is ${urlLength} characters. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [200+ IDs])), consider using an RPC function instead.`;
|
|
182
|
+
}
|
|
170
183
|
return {
|
|
171
184
|
error: {
|
|
172
185
|
message: `${(_fetchError$name2 = fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) !== null && _fetchError$name2 !== void 0 ? _fetchError$name2 : "FetchError"}: ${fetchError === null || fetchError === void 0 ? void 0 : fetchError.message}`,
|
|
173
186
|
details: errorDetails,
|
|
174
|
-
hint
|
|
175
|
-
code
|
|
187
|
+
hint,
|
|
188
|
+
code
|
|
176
189
|
},
|
|
177
190
|
data: null,
|
|
178
191
|
count: null,
|
|
@@ -824,11 +837,12 @@ var PostgrestQueryBuilder = class {
|
|
|
824
837
|
* )
|
|
825
838
|
* ```
|
|
826
839
|
*/
|
|
827
|
-
constructor(url, { headers = {}, schema, fetch: fetch$1 }) {
|
|
840
|
+
constructor(url, { headers = {}, schema, fetch: fetch$1, urlLengthLimit = 8e3 }) {
|
|
828
841
|
this.url = url;
|
|
829
842
|
this.headers = new Headers(headers);
|
|
830
843
|
this.schema = schema;
|
|
831
844
|
this.fetch = fetch$1;
|
|
845
|
+
this.urlLengthLimit = urlLengthLimit;
|
|
832
846
|
}
|
|
833
847
|
/**
|
|
834
848
|
* Clone URL and headers to prevent shared state between operations.
|
|
@@ -881,7 +895,8 @@ var PostgrestQueryBuilder = class {
|
|
|
881
895
|
url,
|
|
882
896
|
headers,
|
|
883
897
|
schema: this.schema,
|
|
884
|
-
fetch: this.fetch
|
|
898
|
+
fetch: this.fetch,
|
|
899
|
+
urlLengthLimit: this.urlLengthLimit
|
|
885
900
|
});
|
|
886
901
|
}
|
|
887
902
|
/**
|
|
@@ -929,7 +944,8 @@ var PostgrestQueryBuilder = class {
|
|
|
929
944
|
headers,
|
|
930
945
|
schema: this.schema,
|
|
931
946
|
body: values,
|
|
932
|
-
fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch
|
|
947
|
+
fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch,
|
|
948
|
+
urlLengthLimit: this.urlLengthLimit
|
|
933
949
|
});
|
|
934
950
|
}
|
|
935
951
|
/**
|
|
@@ -1038,7 +1054,8 @@ var PostgrestQueryBuilder = class {
|
|
|
1038
1054
|
headers,
|
|
1039
1055
|
schema: this.schema,
|
|
1040
1056
|
body: values,
|
|
1041
|
-
fetch: (_this$fetch2 = this.fetch) !== null && _this$fetch2 !== void 0 ? _this$fetch2 : fetch
|
|
1057
|
+
fetch: (_this$fetch2 = this.fetch) !== null && _this$fetch2 !== void 0 ? _this$fetch2 : fetch,
|
|
1058
|
+
urlLengthLimit: this.urlLengthLimit
|
|
1042
1059
|
});
|
|
1043
1060
|
}
|
|
1044
1061
|
/**
|
|
@@ -1073,7 +1090,8 @@ var PostgrestQueryBuilder = class {
|
|
|
1073
1090
|
headers,
|
|
1074
1091
|
schema: this.schema,
|
|
1075
1092
|
body: values,
|
|
1076
|
-
fetch: (_this$fetch3 = this.fetch) !== null && _this$fetch3 !== void 0 ? _this$fetch3 : fetch
|
|
1093
|
+
fetch: (_this$fetch3 = this.fetch) !== null && _this$fetch3 !== void 0 ? _this$fetch3 : fetch,
|
|
1094
|
+
urlLengthLimit: this.urlLengthLimit
|
|
1077
1095
|
});
|
|
1078
1096
|
}
|
|
1079
1097
|
/**
|
|
@@ -1105,11 +1123,78 @@ var PostgrestQueryBuilder = class {
|
|
|
1105
1123
|
url,
|
|
1106
1124
|
headers,
|
|
1107
1125
|
schema: this.schema,
|
|
1108
|
-
fetch: (_this$fetch4 = this.fetch) !== null && _this$fetch4 !== void 0 ? _this$fetch4 : fetch
|
|
1126
|
+
fetch: (_this$fetch4 = this.fetch) !== null && _this$fetch4 !== void 0 ? _this$fetch4 : fetch,
|
|
1127
|
+
urlLengthLimit: this.urlLengthLimit
|
|
1109
1128
|
});
|
|
1110
1129
|
}
|
|
1111
1130
|
};
|
|
1112
1131
|
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/typeof.js
|
|
1134
|
+
function _typeof(o) {
|
|
1135
|
+
"@babel/helpers - typeof";
|
|
1136
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
1137
|
+
return typeof o$1;
|
|
1138
|
+
} : function(o$1) {
|
|
1139
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
1140
|
+
}, _typeof(o);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
//#endregion
|
|
1144
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/toPrimitive.js
|
|
1145
|
+
function toPrimitive(t, r) {
|
|
1146
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
1147
|
+
var e = t[Symbol.toPrimitive];
|
|
1148
|
+
if (void 0 !== e) {
|
|
1149
|
+
var i = e.call(t, r || "default");
|
|
1150
|
+
if ("object" != _typeof(i)) return i;
|
|
1151
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1152
|
+
}
|
|
1153
|
+
return ("string" === r ? String : Number)(t);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
//#endregion
|
|
1157
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/toPropertyKey.js
|
|
1158
|
+
function toPropertyKey(t) {
|
|
1159
|
+
var i = toPrimitive(t, "string");
|
|
1160
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
//#endregion
|
|
1164
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/defineProperty.js
|
|
1165
|
+
function _defineProperty(e, r, t) {
|
|
1166
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1167
|
+
value: t,
|
|
1168
|
+
enumerable: !0,
|
|
1169
|
+
configurable: !0,
|
|
1170
|
+
writable: !0
|
|
1171
|
+
}) : e[r] = t, e;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
//#endregion
|
|
1175
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/objectSpread2.js
|
|
1176
|
+
function ownKeys(e, r) {
|
|
1177
|
+
var t = Object.keys(e);
|
|
1178
|
+
if (Object.getOwnPropertySymbols) {
|
|
1179
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
1180
|
+
r && (o = o.filter(function(r$1) {
|
|
1181
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
1182
|
+
})), t.push.apply(t, o);
|
|
1183
|
+
}
|
|
1184
|
+
return t;
|
|
1185
|
+
}
|
|
1186
|
+
function _objectSpread2(e) {
|
|
1187
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
1188
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
1189
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
1190
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
1191
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
1192
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
return e;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1113
1198
|
//#endregion
|
|
1114
1199
|
//#region src/PostgrestClient.ts
|
|
1115
1200
|
/**
|
|
@@ -1131,6 +1216,8 @@ var PostgrestClient = class PostgrestClient {
|
|
|
1131
1216
|
* @param options.headers - Custom headers
|
|
1132
1217
|
* @param options.schema - Postgres schema to switch to
|
|
1133
1218
|
* @param options.fetch - Custom fetch
|
|
1219
|
+
* @param options.timeout - Optional timeout in milliseconds for all requests. When set, requests will automatically abort after this duration to prevent indefinite hangs.
|
|
1220
|
+
* @param options.urlLengthLimit - Maximum URL length in characters before warnings/errors are triggered. Defaults to 8000.
|
|
1134
1221
|
* @example
|
|
1135
1222
|
* ```ts
|
|
1136
1223
|
* import PostgrestClient from '@supabase/postgrest-js'
|
|
@@ -1138,14 +1225,38 @@ var PostgrestClient = class PostgrestClient {
|
|
|
1138
1225
|
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
1139
1226
|
* headers: { apikey: 'public-anon-key' },
|
|
1140
1227
|
* schema: 'public',
|
|
1228
|
+
* timeout: 30000, // 30 second timeout
|
|
1141
1229
|
* })
|
|
1142
1230
|
* ```
|
|
1143
1231
|
*/
|
|
1144
|
-
constructor(url, { headers = {}, schema, fetch: fetch$1 } = {}) {
|
|
1232
|
+
constructor(url, { headers = {}, schema, fetch: fetch$1, timeout, urlLengthLimit = 8e3 } = {}) {
|
|
1145
1233
|
this.url = url;
|
|
1146
1234
|
this.headers = new Headers(headers);
|
|
1147
1235
|
this.schemaName = schema;
|
|
1148
|
-
this.
|
|
1236
|
+
this.urlLengthLimit = urlLengthLimit;
|
|
1237
|
+
const originalFetch = fetch$1 !== null && fetch$1 !== void 0 ? fetch$1 : globalThis.fetch;
|
|
1238
|
+
if (timeout !== void 0 && timeout > 0) this.fetch = (input, init) => {
|
|
1239
|
+
const controller = new AbortController();
|
|
1240
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
1241
|
+
const existingSignal = init === null || init === void 0 ? void 0 : init.signal;
|
|
1242
|
+
if (existingSignal) {
|
|
1243
|
+
if (existingSignal.aborted) {
|
|
1244
|
+
clearTimeout(timeoutId);
|
|
1245
|
+
return originalFetch(input, init);
|
|
1246
|
+
}
|
|
1247
|
+
const abortHandler = () => {
|
|
1248
|
+
clearTimeout(timeoutId);
|
|
1249
|
+
controller.abort();
|
|
1250
|
+
};
|
|
1251
|
+
existingSignal.addEventListener("abort", abortHandler, { once: true });
|
|
1252
|
+
return originalFetch(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => {
|
|
1253
|
+
clearTimeout(timeoutId);
|
|
1254
|
+
existingSignal.removeEventListener("abort", abortHandler);
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
return originalFetch(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => clearTimeout(timeoutId));
|
|
1258
|
+
};
|
|
1259
|
+
else this.fetch = originalFetch;
|
|
1149
1260
|
}
|
|
1150
1261
|
/**
|
|
1151
1262
|
* Perform a query on a table or a view.
|
|
@@ -1157,7 +1268,8 @@ var PostgrestClient = class PostgrestClient {
|
|
|
1157
1268
|
return new PostgrestQueryBuilder(new URL(`${this.url}/${relation}`), {
|
|
1158
1269
|
headers: new Headers(this.headers),
|
|
1159
1270
|
schema: this.schemaName,
|
|
1160
|
-
fetch: this.fetch
|
|
1271
|
+
fetch: this.fetch,
|
|
1272
|
+
urlLengthLimit: this.urlLengthLimit
|
|
1161
1273
|
});
|
|
1162
1274
|
}
|
|
1163
1275
|
/**
|
|
@@ -1171,7 +1283,8 @@ var PostgrestClient = class PostgrestClient {
|
|
|
1171
1283
|
return new PostgrestClient(this.url, {
|
|
1172
1284
|
headers: this.headers,
|
|
1173
1285
|
schema,
|
|
1174
|
-
fetch: this.fetch
|
|
1286
|
+
fetch: this.fetch,
|
|
1287
|
+
urlLengthLimit: this.urlLengthLimit
|
|
1175
1288
|
});
|
|
1176
1289
|
}
|
|
1177
1290
|
/**
|
|
@@ -1234,7 +1347,8 @@ var PostgrestClient = class PostgrestClient {
|
|
|
1234
1347
|
headers,
|
|
1235
1348
|
schema: this.schemaName,
|
|
1236
1349
|
body,
|
|
1237
|
-
fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch
|
|
1350
|
+
fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch,
|
|
1351
|
+
urlLengthLimit: this.urlLengthLimit
|
|
1238
1352
|
});
|
|
1239
1353
|
}
|
|
1240
1354
|
};
|