@supabase/postgrest-js 2.87.4-canary.3 → 2.87.4-canary.4

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.
Files changed (80) hide show
  1. package/dist/index.cjs +1237 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +1421 -0
  4. package/dist/index.d.cts.map +1 -0
  5. package/dist/index.d.mts +1421 -0
  6. package/dist/index.d.mts.map +1 -0
  7. package/dist/index.mjs +1229 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +18 -16
  10. package/src/version.ts +1 -1
  11. package/dist/cjs/PostgrestBuilder.d.ts +0 -85
  12. package/dist/cjs/PostgrestBuilder.d.ts.map +0 -1
  13. package/dist/cjs/PostgrestBuilder.js +0 -250
  14. package/dist/cjs/PostgrestBuilder.js.map +0 -1
  15. package/dist/cjs/PostgrestClient.d.ts +0 -93
  16. package/dist/cjs/PostgrestClient.d.ts.map +0 -1
  17. package/dist/cjs/PostgrestClient.js +0 -140
  18. package/dist/cjs/PostgrestClient.js.map +0 -1
  19. package/dist/cjs/PostgrestError.d.ts +0 -30
  20. package/dist/cjs/PostgrestError.d.ts.map +0 -1
  21. package/dist/cjs/PostgrestError.js +0 -31
  22. package/dist/cjs/PostgrestError.js.map +0 -1
  23. package/dist/cjs/PostgrestFilterBuilder.d.ts +0 -130
  24. package/dist/cjs/PostgrestFilterBuilder.d.ts.map +0 -1
  25. package/dist/cjs/PostgrestFilterBuilder.js +0 -436
  26. package/dist/cjs/PostgrestFilterBuilder.js.map +0 -1
  27. package/dist/cjs/PostgrestQueryBuilder.d.ts +0 -130
  28. package/dist/cjs/PostgrestQueryBuilder.d.ts.map +0 -1
  29. package/dist/cjs/PostgrestQueryBuilder.js +0 -310
  30. package/dist/cjs/PostgrestQueryBuilder.js.map +0 -1
  31. package/dist/cjs/PostgrestTransformBuilder.d.ts +0 -159
  32. package/dist/cjs/PostgrestTransformBuilder.d.ts.map +0 -1
  33. package/dist/cjs/PostgrestTransformBuilder.js +0 -224
  34. package/dist/cjs/PostgrestTransformBuilder.js.map +0 -1
  35. package/dist/cjs/constants.d.ts +0 -4
  36. package/dist/cjs/constants.d.ts.map +0 -1
  37. package/dist/cjs/constants.js +0 -6
  38. package/dist/cjs/constants.js.map +0 -1
  39. package/dist/cjs/index.d.ts +0 -20
  40. package/dist/cjs/index.d.ts.map +0 -1
  41. package/dist/cjs/index.js +0 -26
  42. package/dist/cjs/index.js.map +0 -1
  43. package/dist/cjs/select-query-parser/parser.d.ts +0 -258
  44. package/dist/cjs/select-query-parser/parser.d.ts.map +0 -1
  45. package/dist/cjs/select-query-parser/parser.js +0 -5
  46. package/dist/cjs/select-query-parser/parser.js.map +0 -1
  47. package/dist/cjs/select-query-parser/result.d.ts +0 -160
  48. package/dist/cjs/select-query-parser/result.d.ts.map +0 -1
  49. package/dist/cjs/select-query-parser/result.js +0 -3
  50. package/dist/cjs/select-query-parser/result.js.map +0 -1
  51. package/dist/cjs/select-query-parser/types.d.ts +0 -32
  52. package/dist/cjs/select-query-parser/types.d.ts.map +0 -1
  53. package/dist/cjs/select-query-parser/types.js +0 -3
  54. package/dist/cjs/select-query-parser/types.js.map +0 -1
  55. package/dist/cjs/select-query-parser/utils.d.ts +0 -283
  56. package/dist/cjs/select-query-parser/utils.d.ts.map +0 -1
  57. package/dist/cjs/select-query-parser/utils.js +0 -3
  58. package/dist/cjs/select-query-parser/utils.js.map +0 -1
  59. package/dist/cjs/types/common/common.d.ts +0 -46
  60. package/dist/cjs/types/common/common.d.ts.map +0 -1
  61. package/dist/cjs/types/common/common.js +0 -4
  62. package/dist/cjs/types/common/common.js.map +0 -1
  63. package/dist/cjs/types/common/rpc.d.ts +0 -40
  64. package/dist/cjs/types/common/rpc.d.ts.map +0 -1
  65. package/dist/cjs/types/common/rpc.js +0 -3
  66. package/dist/cjs/types/common/rpc.js.map +0 -1
  67. package/dist/cjs/types/feature-flags.d.ts +0 -7
  68. package/dist/cjs/types/feature-flags.d.ts.map +0 -1
  69. package/dist/cjs/types/feature-flags.js +0 -3
  70. package/dist/cjs/types/feature-flags.js.map +0 -1
  71. package/dist/cjs/types/types.d.ts +0 -69
  72. package/dist/cjs/types/types.d.ts.map +0 -1
  73. package/dist/cjs/types/types.js +0 -3
  74. package/dist/cjs/types/types.js.map +0 -1
  75. package/dist/cjs/version.d.ts +0 -2
  76. package/dist/cjs/version.d.ts.map +0 -1
  77. package/dist/cjs/version.js +0 -11
  78. package/dist/cjs/version.js.map +0 -1
  79. package/dist/esm/wrapper.mjs +0 -28
  80. package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/index.mjs ADDED
@@ -0,0 +1,1229 @@
1
+ //#region src/PostgrestError.ts
2
+ /**
3
+ * Error format
4
+ *
5
+ * {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
6
+ */
7
+ var PostgrestError = class extends Error {
8
+ /**
9
+ * @example
10
+ * ```ts
11
+ * import PostgrestError from '@supabase/postgrest-js'
12
+ *
13
+ * throw new PostgrestError({
14
+ * message: 'Row level security prevented the request',
15
+ * details: 'RLS denied the insert',
16
+ * hint: 'Check your policies',
17
+ * code: 'PGRST301',
18
+ * })
19
+ * ```
20
+ */
21
+ constructor(context) {
22
+ super(context.message);
23
+ this.name = "PostgrestError";
24
+ this.details = context.details;
25
+ this.hint = context.hint;
26
+ this.code = context.code;
27
+ }
28
+ };
29
+
30
+ //#endregion
31
+ //#region src/PostgrestBuilder.ts
32
+ var PostgrestBuilder = class {
33
+ /**
34
+ * Creates a builder configured for a specific PostgREST request.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import PostgrestQueryBuilder from '@supabase/postgrest-js'
39
+ *
40
+ * const builder = new PostgrestQueryBuilder(
41
+ * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
42
+ * { headers: new Headers({ apikey: 'public-anon-key' }) }
43
+ * )
44
+ * ```
45
+ */
46
+ constructor(builder) {
47
+ var _builder$shouldThrowO, _builder$isMaybeSingl;
48
+ this.shouldThrowOnError = false;
49
+ this.method = builder.method;
50
+ this.url = builder.url;
51
+ this.headers = new Headers(builder.headers);
52
+ this.schema = builder.schema;
53
+ this.body = builder.body;
54
+ this.shouldThrowOnError = (_builder$shouldThrowO = builder.shouldThrowOnError) !== null && _builder$shouldThrowO !== void 0 ? _builder$shouldThrowO : false;
55
+ this.signal = builder.signal;
56
+ this.isMaybeSingle = (_builder$isMaybeSingl = builder.isMaybeSingle) !== null && _builder$isMaybeSingl !== void 0 ? _builder$isMaybeSingl : false;
57
+ if (builder.fetch) this.fetch = builder.fetch;
58
+ else this.fetch = fetch;
59
+ }
60
+ /**
61
+ * If there's an error with the query, throwOnError will reject the promise by
62
+ * throwing the error instead of returning it as part of a successful response.
63
+ *
64
+ * {@link https://github.com/supabase/supabase-js/issues/92}
65
+ */
66
+ throwOnError() {
67
+ this.shouldThrowOnError = true;
68
+ return this;
69
+ }
70
+ /**
71
+ * Set an HTTP header for the request.
72
+ */
73
+ setHeader(name, value) {
74
+ this.headers = new Headers(this.headers);
75
+ this.headers.set(name, value);
76
+ return this;
77
+ }
78
+ then(onfulfilled, onrejected) {
79
+ var _this = this;
80
+ if (this.schema === void 0) {} else if (["GET", "HEAD"].includes(this.method)) this.headers.set("Accept-Profile", this.schema);
81
+ else this.headers.set("Content-Profile", this.schema);
82
+ if (this.method !== "GET" && this.method !== "HEAD") this.headers.set("Content-Type", "application/json");
83
+ const _fetch = this.fetch;
84
+ let res = _fetch(this.url.toString(), {
85
+ method: this.method,
86
+ headers: this.headers,
87
+ body: JSON.stringify(this.body),
88
+ signal: this.signal
89
+ }).then(async (res$1) => {
90
+ let error = null;
91
+ let data = null;
92
+ let count = null;
93
+ let status = res$1.status;
94
+ let statusText = res$1.statusText;
95
+ if (res$1.ok) {
96
+ var _this$headers$get2, _res$headers$get;
97
+ if (_this.method !== "HEAD") {
98
+ var _this$headers$get;
99
+ const body = await res$1.text();
100
+ if (body === "") {} else if (_this.headers.get("Accept") === "text/csv") data = body;
101
+ else if (_this.headers.get("Accept") && ((_this$headers$get = _this.headers.get("Accept")) === null || _this$headers$get === void 0 ? void 0 : _this$headers$get.includes("application/vnd.pgrst.plan+text"))) data = body;
102
+ else data = JSON.parse(body);
103
+ }
104
+ const countHeader = (_this$headers$get2 = _this.headers.get("Prefer")) === null || _this$headers$get2 === void 0 ? void 0 : _this$headers$get2.match(/count=(exact|planned|estimated)/);
105
+ const contentRange = (_res$headers$get = res$1.headers.get("content-range")) === null || _res$headers$get === void 0 ? void 0 : _res$headers$get.split("/");
106
+ if (countHeader && contentRange && contentRange.length > 1) count = parseInt(contentRange[1]);
107
+ if (_this.isMaybeSingle && _this.method === "GET" && Array.isArray(data)) if (data.length > 1) {
108
+ error = {
109
+ code: "PGRST116",
110
+ details: `Results contain ${data.length} rows, application/vnd.pgrst.object+json requires 1 row`,
111
+ hint: null,
112
+ message: "JSON object requested, multiple (or no) rows returned"
113
+ };
114
+ data = null;
115
+ count = null;
116
+ status = 406;
117
+ statusText = "Not Acceptable";
118
+ } else if (data.length === 1) data = data[0];
119
+ else data = null;
120
+ } else {
121
+ var _error$details;
122
+ const body = await res$1.text();
123
+ try {
124
+ error = JSON.parse(body);
125
+ if (Array.isArray(error) && res$1.status === 404) {
126
+ data = [];
127
+ error = null;
128
+ status = 200;
129
+ statusText = "OK";
130
+ }
131
+ } catch (_unused) {
132
+ if (res$1.status === 404 && body === "") {
133
+ status = 204;
134
+ statusText = "No Content";
135
+ } else error = { message: body };
136
+ }
137
+ if (error && _this.isMaybeSingle && (error === null || error === void 0 || (_error$details = error.details) === null || _error$details === void 0 ? void 0 : _error$details.includes("0 rows"))) {
138
+ error = null;
139
+ status = 200;
140
+ statusText = "OK";
141
+ }
142
+ if (error && _this.shouldThrowOnError) throw new PostgrestError(error);
143
+ }
144
+ return {
145
+ error,
146
+ data,
147
+ count,
148
+ status,
149
+ statusText
150
+ };
151
+ });
152
+ if (!this.shouldThrowOnError) res = res.catch((fetchError) => {
153
+ var _fetchError$name2;
154
+ let errorDetails = "";
155
+ const cause = fetchError === null || fetchError === void 0 ? void 0 : fetchError.cause;
156
+ if (cause) {
157
+ var _cause$message, _cause$code, _fetchError$name, _cause$name;
158
+ const causeMessage = (_cause$message = cause === null || cause === void 0 ? void 0 : cause.message) !== null && _cause$message !== void 0 ? _cause$message : "";
159
+ const causeCode = (_cause$code = cause === null || cause === void 0 ? void 0 : cause.code) !== null && _cause$code !== void 0 ? _cause$code : "";
160
+ errorDetails = `${(_fetchError$name = fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) !== null && _fetchError$name !== void 0 ? _fetchError$name : "FetchError"}: ${fetchError === null || fetchError === void 0 ? void 0 : fetchError.message}`;
161
+ errorDetails += `\n\nCaused by: ${(_cause$name = cause === null || cause === void 0 ? void 0 : cause.name) !== null && _cause$name !== void 0 ? _cause$name : "Error"}: ${causeMessage}`;
162
+ if (causeCode) errorDetails += ` (${causeCode})`;
163
+ if (cause === null || cause === void 0 ? void 0 : cause.stack) errorDetails += `\n${cause.stack}`;
164
+ } else {
165
+ var _fetchError$stack;
166
+ errorDetails = (_fetchError$stack = fetchError === null || fetchError === void 0 ? void 0 : fetchError.stack) !== null && _fetchError$stack !== void 0 ? _fetchError$stack : "";
167
+ }
168
+ return {
169
+ error: {
170
+ 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}`,
171
+ details: errorDetails,
172
+ hint: "",
173
+ code: ""
174
+ },
175
+ data: null,
176
+ count: null,
177
+ status: 0,
178
+ statusText: ""
179
+ };
180
+ });
181
+ return res.then(onfulfilled, onrejected);
182
+ }
183
+ /**
184
+ * Override the type of the returned `data`.
185
+ *
186
+ * @typeParam NewResult - The new result type to override with
187
+ * @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
188
+ */
189
+ returns() {
190
+ /* istanbul ignore next */
191
+ return this;
192
+ }
193
+ /**
194
+ * Override the type of the returned `data` field in the response.
195
+ *
196
+ * @typeParam NewResult - The new type to cast the response data to
197
+ * @typeParam Options - Optional type configuration (defaults to { merge: true })
198
+ * @typeParam Options.merge - When true, merges the new type with existing return type. When false, replaces the existing types entirely (defaults to true)
199
+ * @example
200
+ * ```typescript
201
+ * // Merge with existing types (default behavior)
202
+ * const query = supabase
203
+ * .from('users')
204
+ * .select()
205
+ * .overrideTypes<{ custom_field: string }>()
206
+ *
207
+ * // Replace existing types completely
208
+ * const replaceQuery = supabase
209
+ * .from('users')
210
+ * .select()
211
+ * .overrideTypes<{ id: number; name: string }, { merge: false }>()
212
+ * ```
213
+ * @returns A PostgrestBuilder instance with the new type
214
+ */
215
+ overrideTypes() {
216
+ return this;
217
+ }
218
+ };
219
+
220
+ //#endregion
221
+ //#region src/PostgrestTransformBuilder.ts
222
+ var PostgrestTransformBuilder = class extends PostgrestBuilder {
223
+ /**
224
+ * Perform a SELECT on the query result.
225
+ *
226
+ * By default, `.insert()`, `.update()`, `.upsert()`, and `.delete()` do not
227
+ * return modified rows. By calling this method, modified rows are returned in
228
+ * `data`.
229
+ *
230
+ * @param columns - The columns to retrieve, separated by commas
231
+ */
232
+ select(columns) {
233
+ let quoted = false;
234
+ const cleanedColumns = (columns !== null && columns !== void 0 ? columns : "*").split("").map((c) => {
235
+ if (/\s/.test(c) && !quoted) return "";
236
+ if (c === "\"") quoted = !quoted;
237
+ return c;
238
+ }).join("");
239
+ this.url.searchParams.set("select", cleanedColumns);
240
+ this.headers.append("Prefer", "return=representation");
241
+ return this;
242
+ }
243
+ /**
244
+ * Order the query result by `column`.
245
+ *
246
+ * You can call this method multiple times to order by multiple columns.
247
+ *
248
+ * You can order referenced tables, but it only affects the ordering of the
249
+ * parent table if you use `!inner` in the query.
250
+ *
251
+ * @param column - The column to order by
252
+ * @param options - Named parameters
253
+ * @param options.ascending - If `true`, the result will be in ascending order
254
+ * @param options.nullsFirst - If `true`, `null`s appear first. If `false`,
255
+ * `null`s appear last.
256
+ * @param options.referencedTable - Set this to order a referenced table by
257
+ * its columns
258
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
259
+ * instead
260
+ */
261
+ order(column, { ascending = true, nullsFirst, foreignTable, referencedTable = foreignTable } = {}) {
262
+ const key = referencedTable ? `${referencedTable}.order` : "order";
263
+ const existingOrder = this.url.searchParams.get(key);
264
+ this.url.searchParams.set(key, `${existingOrder ? `${existingOrder},` : ""}${column}.${ascending ? "asc" : "desc"}${nullsFirst === void 0 ? "" : nullsFirst ? ".nullsfirst" : ".nullslast"}`);
265
+ return this;
266
+ }
267
+ /**
268
+ * Limit the query result by `count`.
269
+ *
270
+ * @param count - The maximum number of rows to return
271
+ * @param options - Named parameters
272
+ * @param options.referencedTable - Set this to limit rows of referenced
273
+ * tables instead of the parent table
274
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
275
+ * instead
276
+ */
277
+ limit(count, { foreignTable, referencedTable = foreignTable } = {}) {
278
+ const key = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`;
279
+ this.url.searchParams.set(key, `${count}`);
280
+ return this;
281
+ }
282
+ /**
283
+ * Limit the query result by starting at an offset `from` and ending at the offset `to`.
284
+ * Only records within this range are returned.
285
+ * This respects the query order and if there is no order clause the range could behave unexpectedly.
286
+ * The `from` and `to` values are 0-based and inclusive: `range(1, 3)` will include the second, third
287
+ * and fourth rows of the query.
288
+ *
289
+ * @param from - The starting index from which to limit the result
290
+ * @param to - The last index to which to limit the result
291
+ * @param options - Named parameters
292
+ * @param options.referencedTable - Set this to limit rows of referenced
293
+ * tables instead of the parent table
294
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
295
+ * instead
296
+ */
297
+ range(from, to, { foreignTable, referencedTable = foreignTable } = {}) {
298
+ const keyOffset = typeof referencedTable === "undefined" ? "offset" : `${referencedTable}.offset`;
299
+ const keyLimit = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`;
300
+ this.url.searchParams.set(keyOffset, `${from}`);
301
+ this.url.searchParams.set(keyLimit, `${to - from + 1}`);
302
+ return this;
303
+ }
304
+ /**
305
+ * Set the AbortSignal for the fetch request.
306
+ *
307
+ * @param signal - The AbortSignal to use for the fetch request
308
+ */
309
+ abortSignal(signal) {
310
+ this.signal = signal;
311
+ return this;
312
+ }
313
+ /**
314
+ * Return `data` as a single object instead of an array of objects.
315
+ *
316
+ * Query result must be one row (e.g. using `.limit(1)`), otherwise this
317
+ * returns an error.
318
+ */
319
+ single() {
320
+ this.headers.set("Accept", "application/vnd.pgrst.object+json");
321
+ return this;
322
+ }
323
+ /**
324
+ * Return `data` as a single object instead of an array of objects.
325
+ *
326
+ * Query result must be zero or one row (e.g. using `.limit(1)`), otherwise
327
+ * this returns an error.
328
+ */
329
+ maybeSingle() {
330
+ if (this.method === "GET") this.headers.set("Accept", "application/json");
331
+ else this.headers.set("Accept", "application/vnd.pgrst.object+json");
332
+ this.isMaybeSingle = true;
333
+ return this;
334
+ }
335
+ /**
336
+ * Return `data` as a string in CSV format.
337
+ */
338
+ csv() {
339
+ this.headers.set("Accept", "text/csv");
340
+ return this;
341
+ }
342
+ /**
343
+ * Return `data` as an object in [GeoJSON](https://geojson.org) format.
344
+ */
345
+ geojson() {
346
+ this.headers.set("Accept", "application/geo+json");
347
+ return this;
348
+ }
349
+ /**
350
+ * Return `data` as the EXPLAIN plan for the query.
351
+ *
352
+ * You need to enable the
353
+ * [db_plan_enabled](https://supabase.com/docs/guides/database/debugging-performance#enabling-explain)
354
+ * setting before using this method.
355
+ *
356
+ * @param options - Named parameters
357
+ *
358
+ * @param options.analyze - If `true`, the query will be executed and the
359
+ * actual run time will be returned
360
+ *
361
+ * @param options.verbose - If `true`, the query identifier will be returned
362
+ * and `data` will include the output columns of the query
363
+ *
364
+ * @param options.settings - If `true`, include information on configuration
365
+ * parameters that affect query planning
366
+ *
367
+ * @param options.buffers - If `true`, include information on buffer usage
368
+ *
369
+ * @param options.wal - If `true`, include information on WAL record generation
370
+ *
371
+ * @param options.format - The format of the output, can be `"text"` (default)
372
+ * or `"json"`
373
+ */
374
+ explain({ analyze = false, verbose = false, settings = false, buffers = false, wal = false, format = "text" } = {}) {
375
+ var _this$headers$get;
376
+ const options = [
377
+ analyze ? "analyze" : null,
378
+ verbose ? "verbose" : null,
379
+ settings ? "settings" : null,
380
+ buffers ? "buffers" : null,
381
+ wal ? "wal" : null
382
+ ].filter(Boolean).join("|");
383
+ const forMediatype = (_this$headers$get = this.headers.get("Accept")) !== null && _this$headers$get !== void 0 ? _this$headers$get : "application/json";
384
+ this.headers.set("Accept", `application/vnd.pgrst.plan+${format}; for="${forMediatype}"; options=${options};`);
385
+ if (format === "json") return this;
386
+ else return this;
387
+ }
388
+ /**
389
+ * Rollback the query.
390
+ *
391
+ * `data` will still be returned, but the query is not committed.
392
+ */
393
+ rollback() {
394
+ this.headers.append("Prefer", "tx=rollback");
395
+ return this;
396
+ }
397
+ /**
398
+ * Override the type of the returned `data`.
399
+ *
400
+ * @typeParam NewResult - The new result type to override with
401
+ * @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
402
+ */
403
+ returns() {
404
+ return this;
405
+ }
406
+ /**
407
+ * Set the maximum number of rows that can be affected by the query.
408
+ * Only available in PostgREST v13+ and only works with PATCH and DELETE methods.
409
+ *
410
+ * @param value - The maximum number of rows that can be affected
411
+ */
412
+ maxAffected(value) {
413
+ this.headers.append("Prefer", "handling=strict");
414
+ this.headers.append("Prefer", `max-affected=${value}`);
415
+ return this;
416
+ }
417
+ };
418
+
419
+ //#endregion
420
+ //#region src/PostgrestFilterBuilder.ts
421
+ const PostgrestReservedCharsRegexp = /* @__PURE__ */ new RegExp("[,()]");
422
+ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
423
+ /**
424
+ * Match only rows where `column` is equal to `value`.
425
+ *
426
+ * To check if the value of `column` is NULL, you should use `.is()` instead.
427
+ *
428
+ * @param column - The column to filter on
429
+ * @param value - The value to filter with
430
+ */
431
+ eq(column, value) {
432
+ this.url.searchParams.append(column, `eq.${value}`);
433
+ return this;
434
+ }
435
+ /**
436
+ * Match only rows where `column` is not equal to `value`.
437
+ *
438
+ * @param column - The column to filter on
439
+ * @param value - The value to filter with
440
+ */
441
+ neq(column, value) {
442
+ this.url.searchParams.append(column, `neq.${value}`);
443
+ return this;
444
+ }
445
+ /**
446
+ * Match only rows where `column` is greater than `value`.
447
+ *
448
+ * @param column - The column to filter on
449
+ * @param value - The value to filter with
450
+ */
451
+ gt(column, value) {
452
+ this.url.searchParams.append(column, `gt.${value}`);
453
+ return this;
454
+ }
455
+ /**
456
+ * Match only rows where `column` is greater than or equal to `value`.
457
+ *
458
+ * @param column - The column to filter on
459
+ * @param value - The value to filter with
460
+ */
461
+ gte(column, value) {
462
+ this.url.searchParams.append(column, `gte.${value}`);
463
+ return this;
464
+ }
465
+ /**
466
+ * Match only rows where `column` is less than `value`.
467
+ *
468
+ * @param column - The column to filter on
469
+ * @param value - The value to filter with
470
+ */
471
+ lt(column, value) {
472
+ this.url.searchParams.append(column, `lt.${value}`);
473
+ return this;
474
+ }
475
+ /**
476
+ * Match only rows where `column` is less than or equal to `value`.
477
+ *
478
+ * @param column - The column to filter on
479
+ * @param value - The value to filter with
480
+ */
481
+ lte(column, value) {
482
+ this.url.searchParams.append(column, `lte.${value}`);
483
+ return this;
484
+ }
485
+ /**
486
+ * Match only rows where `column` matches `pattern` case-sensitively.
487
+ *
488
+ * @param column - The column to filter on
489
+ * @param pattern - The pattern to match with
490
+ */
491
+ like(column, pattern) {
492
+ this.url.searchParams.append(column, `like.${pattern}`);
493
+ return this;
494
+ }
495
+ /**
496
+ * Match only rows where `column` matches all of `patterns` case-sensitively.
497
+ *
498
+ * @param column - The column to filter on
499
+ * @param patterns - The patterns to match with
500
+ */
501
+ likeAllOf(column, patterns) {
502
+ this.url.searchParams.append(column, `like(all).{${patterns.join(",")}}`);
503
+ return this;
504
+ }
505
+ /**
506
+ * Match only rows where `column` matches any of `patterns` case-sensitively.
507
+ *
508
+ * @param column - The column to filter on
509
+ * @param patterns - The patterns to match with
510
+ */
511
+ likeAnyOf(column, patterns) {
512
+ this.url.searchParams.append(column, `like(any).{${patterns.join(",")}}`);
513
+ return this;
514
+ }
515
+ /**
516
+ * Match only rows where `column` matches `pattern` case-insensitively.
517
+ *
518
+ * @param column - The column to filter on
519
+ * @param pattern - The pattern to match with
520
+ */
521
+ ilike(column, pattern) {
522
+ this.url.searchParams.append(column, `ilike.${pattern}`);
523
+ return this;
524
+ }
525
+ /**
526
+ * Match only rows where `column` matches all of `patterns` case-insensitively.
527
+ *
528
+ * @param column - The column to filter on
529
+ * @param patterns - The patterns to match with
530
+ */
531
+ ilikeAllOf(column, patterns) {
532
+ this.url.searchParams.append(column, `ilike(all).{${patterns.join(",")}}`);
533
+ return this;
534
+ }
535
+ /**
536
+ * Match only rows where `column` matches any of `patterns` case-insensitively.
537
+ *
538
+ * @param column - The column to filter on
539
+ * @param patterns - The patterns to match with
540
+ */
541
+ ilikeAnyOf(column, patterns) {
542
+ this.url.searchParams.append(column, `ilike(any).{${patterns.join(",")}}`);
543
+ return this;
544
+ }
545
+ /**
546
+ * Match only rows where `column` matches the PostgreSQL regex `pattern`
547
+ * case-sensitively (using the `~` operator).
548
+ *
549
+ * @param column - The column to filter on
550
+ * @param pattern - The PostgreSQL regular expression pattern to match with
551
+ */
552
+ regexMatch(column, pattern) {
553
+ this.url.searchParams.append(column, `match.${pattern}`);
554
+ return this;
555
+ }
556
+ /**
557
+ * Match only rows where `column` matches the PostgreSQL regex `pattern`
558
+ * case-insensitively (using the `~*` operator).
559
+ *
560
+ * @param column - The column to filter on
561
+ * @param pattern - The PostgreSQL regular expression pattern to match with
562
+ */
563
+ regexIMatch(column, pattern) {
564
+ this.url.searchParams.append(column, `imatch.${pattern}`);
565
+ return this;
566
+ }
567
+ /**
568
+ * Match only rows where `column` IS `value`.
569
+ *
570
+ * For non-boolean columns, this is only relevant for checking if the value of
571
+ * `column` is NULL by setting `value` to `null`.
572
+ *
573
+ * For boolean columns, you can also set `value` to `true` or `false` and it
574
+ * will behave the same way as `.eq()`.
575
+ *
576
+ * @param column - The column to filter on
577
+ * @param value - The value to filter with
578
+ */
579
+ is(column, value) {
580
+ this.url.searchParams.append(column, `is.${value}`);
581
+ return this;
582
+ }
583
+ /**
584
+ * Match only rows where `column` IS DISTINCT FROM `value`.
585
+ *
586
+ * Unlike `.neq()`, this treats `NULL` as a comparable value. Two `NULL` values
587
+ * are considered equal (not distinct), and comparing `NULL` with any non-NULL
588
+ * value returns true (distinct).
589
+ *
590
+ * @param column - The column to filter on
591
+ * @param value - The value to filter with
592
+ */
593
+ isDistinct(column, value) {
594
+ this.url.searchParams.append(column, `isdistinct.${value}`);
595
+ return this;
596
+ }
597
+ /**
598
+ * Match only rows where `column` is included in the `values` array.
599
+ *
600
+ * @param column - The column to filter on
601
+ * @param values - The values array to filter with
602
+ */
603
+ in(column, values) {
604
+ const cleanedValues = Array.from(new Set(values)).map((s) => {
605
+ if (typeof s === "string" && PostgrestReservedCharsRegexp.test(s)) return `"${s}"`;
606
+ else return `${s}`;
607
+ }).join(",");
608
+ this.url.searchParams.append(column, `in.(${cleanedValues})`);
609
+ return this;
610
+ }
611
+ /**
612
+ * Match only rows where `column` is NOT included in the `values` array.
613
+ *
614
+ * @param column - The column to filter on
615
+ * @param values - The values array to filter with
616
+ */
617
+ notIn(column, values) {
618
+ const cleanedValues = Array.from(new Set(values)).map((s) => {
619
+ if (typeof s === "string" && PostgrestReservedCharsRegexp.test(s)) return `"${s}"`;
620
+ else return `${s}`;
621
+ }).join(",");
622
+ this.url.searchParams.append(column, `not.in.(${cleanedValues})`);
623
+ return this;
624
+ }
625
+ /**
626
+ * Only relevant for jsonb, array, and range columns. Match only rows where
627
+ * `column` contains every element appearing in `value`.
628
+ *
629
+ * @param column - The jsonb, array, or range column to filter on
630
+ * @param value - The jsonb, array, or range value to filter with
631
+ */
632
+ contains(column, value) {
633
+ if (typeof value === "string") this.url.searchParams.append(column, `cs.${value}`);
634
+ else if (Array.isArray(value)) this.url.searchParams.append(column, `cs.{${value.join(",")}}`);
635
+ else this.url.searchParams.append(column, `cs.${JSON.stringify(value)}`);
636
+ return this;
637
+ }
638
+ /**
639
+ * Only relevant for jsonb, array, and range columns. Match only rows where
640
+ * every element appearing in `column` is contained by `value`.
641
+ *
642
+ * @param column - The jsonb, array, or range column to filter on
643
+ * @param value - The jsonb, array, or range value to filter with
644
+ */
645
+ containedBy(column, value) {
646
+ if (typeof value === "string") this.url.searchParams.append(column, `cd.${value}`);
647
+ else if (Array.isArray(value)) this.url.searchParams.append(column, `cd.{${value.join(",")}}`);
648
+ else this.url.searchParams.append(column, `cd.${JSON.stringify(value)}`);
649
+ return this;
650
+ }
651
+ /**
652
+ * Only relevant for range columns. Match only rows where every element in
653
+ * `column` is greater than any element in `range`.
654
+ *
655
+ * @param column - The range column to filter on
656
+ * @param range - The range to filter with
657
+ */
658
+ rangeGt(column, range) {
659
+ this.url.searchParams.append(column, `sr.${range}`);
660
+ return this;
661
+ }
662
+ /**
663
+ * Only relevant for range columns. Match only rows where every element in
664
+ * `column` is either contained in `range` or greater than any element in
665
+ * `range`.
666
+ *
667
+ * @param column - The range column to filter on
668
+ * @param range - The range to filter with
669
+ */
670
+ rangeGte(column, range) {
671
+ this.url.searchParams.append(column, `nxl.${range}`);
672
+ return this;
673
+ }
674
+ /**
675
+ * Only relevant for range columns. Match only rows where every element in
676
+ * `column` is less than any element in `range`.
677
+ *
678
+ * @param column - The range column to filter on
679
+ * @param range - The range to filter with
680
+ */
681
+ rangeLt(column, range) {
682
+ this.url.searchParams.append(column, `sl.${range}`);
683
+ return this;
684
+ }
685
+ /**
686
+ * Only relevant for range columns. Match only rows where every element in
687
+ * `column` is either contained in `range` or less than any element in
688
+ * `range`.
689
+ *
690
+ * @param column - The range column to filter on
691
+ * @param range - The range to filter with
692
+ */
693
+ rangeLte(column, range) {
694
+ this.url.searchParams.append(column, `nxr.${range}`);
695
+ return this;
696
+ }
697
+ /**
698
+ * Only relevant for range columns. Match only rows where `column` is
699
+ * mutually exclusive to `range` and there can be no element between the two
700
+ * ranges.
701
+ *
702
+ * @param column - The range column to filter on
703
+ * @param range - The range to filter with
704
+ */
705
+ rangeAdjacent(column, range) {
706
+ this.url.searchParams.append(column, `adj.${range}`);
707
+ return this;
708
+ }
709
+ /**
710
+ * Only relevant for array and range columns. Match only rows where
711
+ * `column` and `value` have an element in common.
712
+ *
713
+ * @param column - The array or range column to filter on
714
+ * @param value - The array or range value to filter with
715
+ */
716
+ overlaps(column, value) {
717
+ if (typeof value === "string") this.url.searchParams.append(column, `ov.${value}`);
718
+ else this.url.searchParams.append(column, `ov.{${value.join(",")}}`);
719
+ return this;
720
+ }
721
+ /**
722
+ * Only relevant for text and tsvector columns. Match only rows where
723
+ * `column` matches the query string in `query`.
724
+ *
725
+ * @param column - The text or tsvector column to filter on
726
+ * @param query - The query text to match with
727
+ * @param options - Named parameters
728
+ * @param options.config - The text search configuration to use
729
+ * @param options.type - Change how the `query` text is interpreted
730
+ */
731
+ textSearch(column, query, { config, type } = {}) {
732
+ let typePart = "";
733
+ if (type === "plain") typePart = "pl";
734
+ else if (type === "phrase") typePart = "ph";
735
+ else if (type === "websearch") typePart = "w";
736
+ const configPart = config === void 0 ? "" : `(${config})`;
737
+ this.url.searchParams.append(column, `${typePart}fts${configPart}.${query}`);
738
+ return this;
739
+ }
740
+ /**
741
+ * Match only rows where each column in `query` keys is equal to its
742
+ * associated value. Shorthand for multiple `.eq()`s.
743
+ *
744
+ * @param query - The object to filter with, with column names as keys mapped
745
+ * to their filter values
746
+ */
747
+ match(query) {
748
+ Object.entries(query).forEach(([column, value]) => {
749
+ this.url.searchParams.append(column, `eq.${value}`);
750
+ });
751
+ return this;
752
+ }
753
+ /**
754
+ * Match only rows which doesn't satisfy the filter.
755
+ *
756
+ * Unlike most filters, `opearator` and `value` are used as-is and need to
757
+ * follow [PostgREST
758
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
759
+ * to make sure they are properly sanitized.
760
+ *
761
+ * @param column - The column to filter on
762
+ * @param operator - The operator to be negated to filter with, following
763
+ * PostgREST syntax
764
+ * @param value - The value to filter with, following PostgREST syntax
765
+ */
766
+ not(column, operator, value) {
767
+ this.url.searchParams.append(column, `not.${operator}.${value}`);
768
+ return this;
769
+ }
770
+ /**
771
+ * Match only rows which satisfy at least one of the filters.
772
+ *
773
+ * Unlike most filters, `filters` is used as-is and needs to follow [PostgREST
774
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
775
+ * to make sure it's properly sanitized.
776
+ *
777
+ * It's currently not possible to do an `.or()` filter across multiple tables.
778
+ *
779
+ * @param filters - The filters to use, following PostgREST syntax
780
+ * @param options - Named parameters
781
+ * @param options.referencedTable - Set this to filter on referenced tables
782
+ * instead of the parent table
783
+ * @param options.foreignTable - Deprecated, use `referencedTable` instead
784
+ */
785
+ or(filters, { foreignTable, referencedTable = foreignTable } = {}) {
786
+ const key = referencedTable ? `${referencedTable}.or` : "or";
787
+ this.url.searchParams.append(key, `(${filters})`);
788
+ return this;
789
+ }
790
+ /**
791
+ * Match only rows which satisfy the filter. This is an escape hatch - you
792
+ * should use the specific filter methods wherever possible.
793
+ *
794
+ * Unlike most filters, `opearator` and `value` are used as-is and need to
795
+ * follow [PostgREST
796
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
797
+ * to make sure they are properly sanitized.
798
+ *
799
+ * @param column - The column to filter on
800
+ * @param operator - The operator to filter with, following PostgREST syntax
801
+ * @param value - The value to filter with, following PostgREST syntax
802
+ */
803
+ filter(column, operator, value) {
804
+ this.url.searchParams.append(column, `${operator}.${value}`);
805
+ return this;
806
+ }
807
+ };
808
+
809
+ //#endregion
810
+ //#region src/PostgrestQueryBuilder.ts
811
+ var PostgrestQueryBuilder = class {
812
+ /**
813
+ * Creates a query builder scoped to a Postgres table or view.
814
+ *
815
+ * @example
816
+ * ```ts
817
+ * import PostgrestQueryBuilder from '@supabase/postgrest-js'
818
+ *
819
+ * const query = new PostgrestQueryBuilder(
820
+ * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
821
+ * { headers: { apikey: 'public-anon-key' } }
822
+ * )
823
+ * ```
824
+ */
825
+ constructor(url, { headers = {}, schema, fetch: fetch$1 }) {
826
+ this.url = url;
827
+ this.headers = new Headers(headers);
828
+ this.schema = schema;
829
+ this.fetch = fetch$1;
830
+ }
831
+ /**
832
+ * Perform a SELECT query on the table or view.
833
+ *
834
+ * @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName`
835
+ *
836
+ * @param options - Named parameters
837
+ *
838
+ * @param options.head - When set to `true`, `data` will not be returned.
839
+ * Useful if you only need the count.
840
+ *
841
+ * @param options.count - Count algorithm to use to count rows in the table or view.
842
+ *
843
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
844
+ * hood.
845
+ *
846
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
847
+ * statistics under the hood.
848
+ *
849
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
850
+ * numbers.
851
+ */
852
+ select(columns, options) {
853
+ const { head = false, count } = options !== null && options !== void 0 ? options : {};
854
+ const method = head ? "HEAD" : "GET";
855
+ let quoted = false;
856
+ const cleanedColumns = (columns !== null && columns !== void 0 ? columns : "*").split("").map((c) => {
857
+ if (/\s/.test(c) && !quoted) return "";
858
+ if (c === "\"") quoted = !quoted;
859
+ return c;
860
+ }).join("");
861
+ this.url.searchParams.set("select", cleanedColumns);
862
+ if (count) this.headers.append("Prefer", `count=${count}`);
863
+ return new PostgrestFilterBuilder({
864
+ method,
865
+ url: this.url,
866
+ headers: this.headers,
867
+ schema: this.schema,
868
+ fetch: this.fetch
869
+ });
870
+ }
871
+ /**
872
+ * Perform an INSERT into the table or view.
873
+ *
874
+ * By default, inserted rows are not returned. To return it, chain the call
875
+ * with `.select()`.
876
+ *
877
+ * @param values - The values to insert. Pass an object to insert a single row
878
+ * or an array to insert multiple rows.
879
+ *
880
+ * @param options - Named parameters
881
+ *
882
+ * @param options.count - Count algorithm to use to count inserted rows.
883
+ *
884
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
885
+ * hood.
886
+ *
887
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
888
+ * statistics under the hood.
889
+ *
890
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
891
+ * numbers.
892
+ *
893
+ * @param options.defaultToNull - Make missing fields default to `null`.
894
+ * Otherwise, use the default value for the column. Only applies for bulk
895
+ * inserts.
896
+ */
897
+ insert(values, { count, defaultToNull = true } = {}) {
898
+ var _this$fetch;
899
+ const method = "POST";
900
+ if (count) this.headers.append("Prefer", `count=${count}`);
901
+ if (!defaultToNull) this.headers.append("Prefer", `missing=default`);
902
+ if (Array.isArray(values)) {
903
+ const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
904
+ if (columns.length > 0) {
905
+ const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`);
906
+ this.url.searchParams.set("columns", uniqueColumns.join(","));
907
+ }
908
+ }
909
+ return new PostgrestFilterBuilder({
910
+ method,
911
+ url: this.url,
912
+ headers: this.headers,
913
+ schema: this.schema,
914
+ body: values,
915
+ fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch
916
+ });
917
+ }
918
+ /**
919
+ * Perform an UPSERT on the table or view. Depending on the column(s) passed
920
+ * to `onConflict`, `.upsert()` allows you to perform the equivalent of
921
+ * `.insert()` if a row with the corresponding `onConflict` columns doesn't
922
+ * exist, or if it does exist, perform an alternative action depending on
923
+ * `ignoreDuplicates`.
924
+ *
925
+ * By default, upserted rows are not returned. To return it, chain the call
926
+ * with `.select()`.
927
+ *
928
+ * @param values - The values to upsert with. Pass an object to upsert a
929
+ * single row or an array to upsert multiple rows.
930
+ *
931
+ * @param options - Named parameters
932
+ *
933
+ * @param options.onConflict - Comma-separated UNIQUE column(s) to specify how
934
+ * duplicate rows are determined. Two rows are duplicates if all the
935
+ * `onConflict` columns are equal.
936
+ *
937
+ * @param options.ignoreDuplicates - If `true`, duplicate rows are ignored. If
938
+ * `false`, duplicate rows are merged with existing rows.
939
+ *
940
+ * @param options.count - Count algorithm to use to count upserted rows.
941
+ *
942
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
943
+ * hood.
944
+ *
945
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
946
+ * statistics under the hood.
947
+ *
948
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
949
+ * numbers.
950
+ *
951
+ * @param options.defaultToNull - Make missing fields default to `null`.
952
+ * Otherwise, use the default value for the column. This only applies when
953
+ * inserting new rows, not when merging with existing rows under
954
+ * `ignoreDuplicates: false`. This also only applies when doing bulk upserts.
955
+ *
956
+ * @example Upsert a single row using a unique key
957
+ * ```ts
958
+ * // Upserting a single row, overwriting based on the 'username' unique column
959
+ * const { data, error } = await supabase
960
+ * .from('users')
961
+ * .upsert({ username: 'supabot' }, { onConflict: 'username' })
962
+ *
963
+ * // Example response:
964
+ * // {
965
+ * // data: [
966
+ * // { id: 4, message: 'bar', username: 'supabot' }
967
+ * // ],
968
+ * // error: null
969
+ * // }
970
+ * ```
971
+ *
972
+ * @example Upsert with conflict resolution and exact row counting
973
+ * ```ts
974
+ * // Upserting and returning exact count
975
+ * const { data, error, count } = await supabase
976
+ * .from('users')
977
+ * .upsert(
978
+ * {
979
+ * id: 3,
980
+ * message: 'foo',
981
+ * username: 'supabot'
982
+ * },
983
+ * {
984
+ * onConflict: 'username',
985
+ * count: 'exact'
986
+ * }
987
+ * )
988
+ *
989
+ * // Example response:
990
+ * // {
991
+ * // data: [
992
+ * // {
993
+ * // id: 42,
994
+ * // handle: "saoirse",
995
+ * // display_name: "Saoirse"
996
+ * // }
997
+ * // ],
998
+ * // count: 1,
999
+ * // error: null
1000
+ * // }
1001
+ * ```
1002
+ */
1003
+ upsert(values, { onConflict, ignoreDuplicates = false, count, defaultToNull = true } = {}) {
1004
+ var _this$fetch2;
1005
+ const method = "POST";
1006
+ this.headers.append("Prefer", `resolution=${ignoreDuplicates ? "ignore" : "merge"}-duplicates`);
1007
+ if (onConflict !== void 0) this.url.searchParams.set("on_conflict", onConflict);
1008
+ if (count) this.headers.append("Prefer", `count=${count}`);
1009
+ if (!defaultToNull) this.headers.append("Prefer", "missing=default");
1010
+ if (Array.isArray(values)) {
1011
+ const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
1012
+ if (columns.length > 0) {
1013
+ const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`);
1014
+ this.url.searchParams.set("columns", uniqueColumns.join(","));
1015
+ }
1016
+ }
1017
+ return new PostgrestFilterBuilder({
1018
+ method,
1019
+ url: this.url,
1020
+ headers: this.headers,
1021
+ schema: this.schema,
1022
+ body: values,
1023
+ fetch: (_this$fetch2 = this.fetch) !== null && _this$fetch2 !== void 0 ? _this$fetch2 : fetch
1024
+ });
1025
+ }
1026
+ /**
1027
+ * Perform an UPDATE on the table or view.
1028
+ *
1029
+ * By default, updated rows are not returned. To return it, chain the call
1030
+ * with `.select()` after filters.
1031
+ *
1032
+ * @param values - The values to update with
1033
+ *
1034
+ * @param options - Named parameters
1035
+ *
1036
+ * @param options.count - Count algorithm to use to count updated rows.
1037
+ *
1038
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
1039
+ * hood.
1040
+ *
1041
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
1042
+ * statistics under the hood.
1043
+ *
1044
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
1045
+ * numbers.
1046
+ */
1047
+ update(values, { count } = {}) {
1048
+ var _this$fetch3;
1049
+ const method = "PATCH";
1050
+ if (count) this.headers.append("Prefer", `count=${count}`);
1051
+ return new PostgrestFilterBuilder({
1052
+ method,
1053
+ url: this.url,
1054
+ headers: this.headers,
1055
+ schema: this.schema,
1056
+ body: values,
1057
+ fetch: (_this$fetch3 = this.fetch) !== null && _this$fetch3 !== void 0 ? _this$fetch3 : fetch
1058
+ });
1059
+ }
1060
+ /**
1061
+ * Perform a DELETE on the table or view.
1062
+ *
1063
+ * By default, deleted rows are not returned. To return it, chain the call
1064
+ * with `.select()` after filters.
1065
+ *
1066
+ * @param options - Named parameters
1067
+ *
1068
+ * @param options.count - Count algorithm to use to count deleted rows.
1069
+ *
1070
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
1071
+ * hood.
1072
+ *
1073
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
1074
+ * statistics under the hood.
1075
+ *
1076
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
1077
+ * numbers.
1078
+ */
1079
+ delete({ count } = {}) {
1080
+ var _this$fetch4;
1081
+ const method = "DELETE";
1082
+ if (count) this.headers.append("Prefer", `count=${count}`);
1083
+ return new PostgrestFilterBuilder({
1084
+ method,
1085
+ url: this.url,
1086
+ headers: this.headers,
1087
+ schema: this.schema,
1088
+ fetch: (_this$fetch4 = this.fetch) !== null && _this$fetch4 !== void 0 ? _this$fetch4 : fetch
1089
+ });
1090
+ }
1091
+ };
1092
+
1093
+ //#endregion
1094
+ //#region src/PostgrestClient.ts
1095
+ /**
1096
+ * PostgREST client.
1097
+ *
1098
+ * @typeParam Database - Types for the schema from the [type
1099
+ * generator](https://supabase.com/docs/reference/javascript/next/typescript-support)
1100
+ *
1101
+ * @typeParam SchemaName - Postgres schema to switch to. Must be a string
1102
+ * literal, the same one passed to the constructor. If the schema is not
1103
+ * `"public"`, this must be supplied manually.
1104
+ */
1105
+ var PostgrestClient = class PostgrestClient {
1106
+ /**
1107
+ * Creates a PostgREST client.
1108
+ *
1109
+ * @param url - URL of the PostgREST endpoint
1110
+ * @param options - Named parameters
1111
+ * @param options.headers - Custom headers
1112
+ * @param options.schema - Postgres schema to switch to
1113
+ * @param options.fetch - Custom fetch
1114
+ * @example
1115
+ * ```ts
1116
+ * import PostgrestClient from '@supabase/postgrest-js'
1117
+ *
1118
+ * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
1119
+ * headers: { apikey: 'public-anon-key' },
1120
+ * schema: 'public',
1121
+ * })
1122
+ * ```
1123
+ */
1124
+ constructor(url, { headers = {}, schema, fetch: fetch$1 } = {}) {
1125
+ this.url = url;
1126
+ this.headers = new Headers(headers);
1127
+ this.schemaName = schema;
1128
+ this.fetch = fetch$1;
1129
+ }
1130
+ /**
1131
+ * Perform a query on a table or a view.
1132
+ *
1133
+ * @param relation - The table or view name to query
1134
+ */
1135
+ from(relation) {
1136
+ if (!relation || typeof relation !== "string" || relation.trim() === "") throw new Error("Invalid relation name: relation must be a non-empty string.");
1137
+ return new PostgrestQueryBuilder(new URL(`${this.url}/${relation}`), {
1138
+ headers: new Headers(this.headers),
1139
+ schema: this.schemaName,
1140
+ fetch: this.fetch
1141
+ });
1142
+ }
1143
+ /**
1144
+ * Select a schema to query or perform an function (rpc) call.
1145
+ *
1146
+ * The schema needs to be on the list of exposed schemas inside Supabase.
1147
+ *
1148
+ * @param schema - The schema to query
1149
+ */
1150
+ schema(schema) {
1151
+ return new PostgrestClient(this.url, {
1152
+ headers: this.headers,
1153
+ schema,
1154
+ fetch: this.fetch
1155
+ });
1156
+ }
1157
+ /**
1158
+ * Perform a function call.
1159
+ *
1160
+ * @param fn - The function name to call
1161
+ * @param args - The arguments to pass to the function call
1162
+ * @param options - Named parameters
1163
+ * @param options.head - When set to `true`, `data` will not be returned.
1164
+ * Useful if you only need the count.
1165
+ * @param options.get - When set to `true`, the function will be called with
1166
+ * read-only access mode.
1167
+ * @param options.count - Count algorithm to use to count rows returned by the
1168
+ * function. Only applicable for [set-returning
1169
+ * functions](https://www.postgresql.org/docs/current/functions-srf.html).
1170
+ *
1171
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
1172
+ * hood.
1173
+ *
1174
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
1175
+ * statistics under the hood.
1176
+ *
1177
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
1178
+ * numbers.
1179
+ *
1180
+ * @example
1181
+ * ```ts
1182
+ * // For cross-schema functions where type inference fails, use overrideTypes:
1183
+ * const { data } = await supabase
1184
+ * .schema('schema_b')
1185
+ * .rpc('function_a', {})
1186
+ * .overrideTypes<{ id: string; user_id: string }[]>()
1187
+ * ```
1188
+ */
1189
+ rpc(fn, args = {}, { head = false, get = false, count } = {}) {
1190
+ var _this$fetch;
1191
+ let method;
1192
+ const url = new URL(`${this.url}/rpc/${fn}`);
1193
+ let body;
1194
+ if (head || get) {
1195
+ method = head ? "HEAD" : "GET";
1196
+ Object.entries(args).filter(([_, value]) => value !== void 0).map(([name, value]) => [name, Array.isArray(value) ? `{${value.join(",")}}` : `${value}`]).forEach(([name, value]) => {
1197
+ url.searchParams.append(name, value);
1198
+ });
1199
+ } else {
1200
+ method = "POST";
1201
+ body = args;
1202
+ }
1203
+ const headers = new Headers(this.headers);
1204
+ if (count) headers.set("Prefer", `count=${count}`);
1205
+ return new PostgrestFilterBuilder({
1206
+ method,
1207
+ url,
1208
+ headers,
1209
+ schema: this.schemaName,
1210
+ body,
1211
+ fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch
1212
+ });
1213
+ }
1214
+ };
1215
+
1216
+ //#endregion
1217
+ //#region src/index.ts
1218
+ var src_default = {
1219
+ PostgrestClient,
1220
+ PostgrestQueryBuilder,
1221
+ PostgrestFilterBuilder,
1222
+ PostgrestTransformBuilder,
1223
+ PostgrestBuilder,
1224
+ PostgrestError
1225
+ };
1226
+
1227
+ //#endregion
1228
+ export { PostgrestBuilder, PostgrestClient, PostgrestError, PostgrestFilterBuilder, PostgrestQueryBuilder, PostgrestTransformBuilder, src_default as default };
1229
+ //# sourceMappingURL=index.mjs.map