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