@freehour/supabase-core 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.js +78 -379
- package/package.json +2 -2
package/LICENSE
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,369 +1,68 @@
|
|
|
1
1
|
import { assert as e } from "@freehour/assert";
|
|
2
2
|
import t from "zod";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
], o = class extends Error {
|
|
9
|
-
constructor(e) {
|
|
10
|
-
super(e.message), this.name = "PostgrestError", this.details = e.details, this.hint = e.hint, this.code = e.code;
|
|
11
|
-
}
|
|
12
|
-
toJSON() {
|
|
13
|
-
return {
|
|
14
|
-
name: this.name,
|
|
15
|
-
message: this.message,
|
|
16
|
-
details: this.details,
|
|
17
|
-
hint: this.hint,
|
|
18
|
-
code: this.code
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
function s(e, t) {
|
|
23
|
-
return new Promise((n) => {
|
|
24
|
-
if (t?.aborted) {
|
|
25
|
-
n();
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
let r = setTimeout(() => {
|
|
29
|
-
t?.removeEventListener("abort", i), n();
|
|
30
|
-
}, e);
|
|
31
|
-
function i() {
|
|
32
|
-
clearTimeout(r), n();
|
|
33
|
-
}
|
|
34
|
-
t?.addEventListener("abort", i);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function c(e, t, r, o) {
|
|
38
|
-
return !(!o || r >= n || !a.includes(e) || !i.includes(t));
|
|
39
|
-
}
|
|
40
|
-
var l = class {
|
|
41
|
-
constructor(e) {
|
|
42
|
-
this.shouldThrowOnError = !1, this.retryEnabled = !0, this.method = e.method, this.url = e.url, this.headers = new Headers(e.headers), this.schema = e.schema, this.body = e.body, this.shouldThrowOnError = e.shouldThrowOnError ?? !1, this.signal = e.signal, this.isMaybeSingle = e.isMaybeSingle ?? !1, this.shouldStripNulls = e.shouldStripNulls ?? !1, this.urlLengthLimit = e.urlLengthLimit ?? 8e3, this.retryEnabled = e.retry ?? !0, e.fetch ? this.fetch = e.fetch : this.fetch = fetch;
|
|
43
|
-
}
|
|
44
|
-
throwOnError() {
|
|
45
|
-
return this.shouldThrowOnError = !0, this;
|
|
46
|
-
}
|
|
47
|
-
stripNulls() {
|
|
48
|
-
if (this.headers.get("Accept") === "text/csv") throw Error("stripNulls() cannot be used with csv()");
|
|
49
|
-
return this.shouldStripNulls = !0, this;
|
|
50
|
-
}
|
|
51
|
-
setHeader(e, t) {
|
|
52
|
-
return this.headers = new Headers(this.headers), this.headers.set(e, t), this;
|
|
53
|
-
}
|
|
54
|
-
retry(e) {
|
|
55
|
-
return this.retryEnabled = e, this;
|
|
56
|
-
}
|
|
57
|
-
then(e, t) {
|
|
58
|
-
var i = this;
|
|
59
|
-
if (this.schema === void 0 || (["GET", "HEAD"].includes(this.method) ? this.headers.set("Accept-Profile", this.schema) : this.headers.set("Content-Profile", this.schema)), this.method !== "GET" && this.method !== "HEAD" && this.headers.set("Content-Type", "application/json"), this.shouldStripNulls) {
|
|
60
|
-
let e = this.headers.get("Accept");
|
|
61
|
-
e === "application/vnd.pgrst.object+json" ? this.headers.set("Accept", "application/vnd.pgrst.object+json;nulls=stripped") : (!e || e === "application/json") && this.headers.set("Accept", "application/vnd.pgrst.array+json;nulls=stripped");
|
|
62
|
-
}
|
|
63
|
-
let o = this.fetch, l = (async () => {
|
|
64
|
-
let e = 0;
|
|
65
|
-
for (;;) {
|
|
66
|
-
let t = new Headers(i.headers);
|
|
67
|
-
e > 0 && t.set("X-Retry-Count", String(e));
|
|
68
|
-
let l;
|
|
69
|
-
try {
|
|
70
|
-
l = await o(i.url.toString(), {
|
|
71
|
-
method: i.method,
|
|
72
|
-
headers: t,
|
|
73
|
-
body: JSON.stringify(i.body, (e, t) => typeof t == "bigint" ? t.toString() : t),
|
|
74
|
-
signal: i.signal
|
|
75
|
-
});
|
|
76
|
-
} catch (t) {
|
|
77
|
-
if (t?.name === "AbortError" || t?.code === "ABORT_ERR" || !a.includes(i.method)) throw t;
|
|
78
|
-
if (i.retryEnabled && e < n) {
|
|
79
|
-
let t = r(e);
|
|
80
|
-
e++, await s(t, i.signal);
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
throw t;
|
|
84
|
-
}
|
|
85
|
-
if (c(i.method, l.status, e, i.retryEnabled)) {
|
|
86
|
-
let t = l.headers?.get("Retry-After") ?? null, n = t === null ? r(e) : Math.max(0, parseInt(t, 10) || 0) * 1e3;
|
|
87
|
-
await l.text(), e++, await s(n, i.signal);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
return await i.processResponse(l);
|
|
91
|
-
}
|
|
92
|
-
})();
|
|
93
|
-
return this.shouldThrowOnError || (l = l.catch((e) => {
|
|
94
|
-
let t = "", n = "", r = "", i = e?.cause;
|
|
95
|
-
if (i) {
|
|
96
|
-
let n = i?.message ?? "", r = i?.code ?? "";
|
|
97
|
-
t = `${e?.name ?? "FetchError"}: ${e?.message}`, t += `\n\nCaused by: ${i?.name ?? "Error"}: ${n}`, r && (t += ` (${r})`), i?.stack && (t += `\n${i.stack}`);
|
|
98
|
-
} else t = e?.stack ?? "";
|
|
99
|
-
let a = this.url.toString().length;
|
|
100
|
-
return e?.name === "AbortError" || e?.code === "ABORT_ERR" ? (r = "", n = "Request was aborted (timeout or manual cancellation)", a > this.urlLengthLimit && (n += `. Note: Your request URL is ${a} characters, which may exceed server limits. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [many IDs])), consider using an RPC function to pass values server-side.`)) : (i?.name === "HeadersOverflowError" || i?.code === "UND_ERR_HEADERS_OVERFLOW") && (r = "", n = "HTTP headers exceeded server limits (typically 16KB)", a > this.urlLengthLimit && (n += `. Your request URL is ${a} characters. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [200+ IDs])), consider using an RPC function instead.`)), {
|
|
101
|
-
success: !1,
|
|
102
|
-
error: {
|
|
103
|
-
message: `${e?.name ?? "FetchError"}: ${e?.message}`,
|
|
104
|
-
details: t,
|
|
105
|
-
hint: n,
|
|
106
|
-
code: r
|
|
107
|
-
},
|
|
108
|
-
data: null,
|
|
109
|
-
count: null,
|
|
110
|
-
status: 0,
|
|
111
|
-
statusText: ""
|
|
112
|
-
};
|
|
113
|
-
})), l.then(e, t);
|
|
114
|
-
}
|
|
115
|
-
async processResponse(e) {
|
|
116
|
-
var t = this;
|
|
117
|
-
let n = null, r = null, i = null, a = e.status, s = e.statusText;
|
|
118
|
-
if (e.ok) {
|
|
119
|
-
if (t.method !== "HEAD") {
|
|
120
|
-
let n = await e.text();
|
|
121
|
-
n === "" || (r = t.headers.get("Accept") === "text/csv" || t.headers.get("Accept") && t.headers.get("Accept")?.includes("application/vnd.pgrst.plan+text") ? n : JSON.parse(n));
|
|
122
|
-
}
|
|
123
|
-
let o = t.headers.get("Prefer")?.match(/count=(exact|planned|estimated)/), c = e.headers.get("content-range")?.split("/");
|
|
124
|
-
o && c && c.length > 1 && (i = parseInt(c[1])), t.isMaybeSingle && Array.isArray(r) && (r.length > 1 ? (n = {
|
|
125
|
-
code: "PGRST116",
|
|
126
|
-
details: `Results contain ${r.length} rows, application/vnd.pgrst.object+json requires 1 row`,
|
|
127
|
-
hint: null,
|
|
128
|
-
message: "JSON object requested, multiple (or no) rows returned"
|
|
129
|
-
}, r = null, i = null, a = 406, s = "Not Acceptable") : r = r.length === 1 ? r[0] : null);
|
|
130
|
-
} else {
|
|
131
|
-
let i = await e.text();
|
|
132
|
-
try {
|
|
133
|
-
n = JSON.parse(i), Array.isArray(n) && e.status === 404 && (r = [], n = null, a = 200, s = "OK");
|
|
134
|
-
} catch {
|
|
135
|
-
e.status === 404 && i === "" ? (a = 204, s = "No Content") : n = { message: i };
|
|
136
|
-
}
|
|
137
|
-
if (n && t.shouldThrowOnError) throw new o(n);
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
success: n === null,
|
|
141
|
-
error: n,
|
|
142
|
-
data: r,
|
|
143
|
-
count: i,
|
|
144
|
-
status: a,
|
|
145
|
-
statusText: s
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
returns() {
|
|
149
|
-
/* istanbul ignore next */
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
overrideTypes() {
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
}, u = class extends l {
|
|
156
|
-
select(e) {
|
|
157
|
-
let t = !1, n = (e ?? "*").split("").map((e) => /\s/.test(e) && !t ? "" : (e === "\"" && (t = !t), e)).join("");
|
|
158
|
-
return this.url.searchParams.set("select", n), this.headers.append("Prefer", "return=representation"), this;
|
|
159
|
-
}
|
|
160
|
-
order(e, { ascending: t = !0, nullsFirst: n, foreignTable: r, referencedTable: i = r } = {}) {
|
|
161
|
-
let a = i ? `${i}.order` : "order", o = this.url.searchParams.get(a);
|
|
162
|
-
return this.url.searchParams.set(a, `${o ? `${o},` : ""}${e}.${t ? "asc" : "desc"}${n === void 0 ? "" : n ? ".nullsfirst" : ".nullslast"}`), this;
|
|
163
|
-
}
|
|
164
|
-
limit(e, { foreignTable: t, referencedTable: n = t } = {}) {
|
|
165
|
-
let r = n === void 0 ? "limit" : `${n}.limit`;
|
|
166
|
-
return this.url.searchParams.set(r, `${e}`), this;
|
|
167
|
-
}
|
|
168
|
-
range(e, t, { foreignTable: n, referencedTable: r = n } = {}) {
|
|
169
|
-
let i = r === void 0 ? "offset" : `${r}.offset`, a = r === void 0 ? "limit" : `${r}.limit`;
|
|
170
|
-
return this.url.searchParams.set(i, `${e}`), this.url.searchParams.set(a, `${t - e + 1}`), this;
|
|
171
|
-
}
|
|
172
|
-
abortSignal(e) {
|
|
173
|
-
return this.signal = e, this;
|
|
174
|
-
}
|
|
175
|
-
single() {
|
|
176
|
-
return this.headers.set("Accept", "application/vnd.pgrst.object+json"), this;
|
|
177
|
-
}
|
|
178
|
-
maybeSingle() {
|
|
179
|
-
return this.isMaybeSingle = !0, this;
|
|
180
|
-
}
|
|
181
|
-
csv() {
|
|
182
|
-
return this.headers.set("Accept", "text/csv"), this;
|
|
183
|
-
}
|
|
184
|
-
geojson() {
|
|
185
|
-
return this.headers.set("Accept", "application/geo+json"), this;
|
|
186
|
-
}
|
|
187
|
-
explain({ analyze: e = !1, verbose: t = !1, settings: n = !1, buffers: r = !1, wal: i = !1, format: a = "text" } = {}) {
|
|
188
|
-
let o = [
|
|
189
|
-
e ? "analyze" : null,
|
|
190
|
-
t ? "verbose" : null,
|
|
191
|
-
n ? "settings" : null,
|
|
192
|
-
r ? "buffers" : null,
|
|
193
|
-
i ? "wal" : null
|
|
194
|
-
].filter(Boolean).join("|"), s = this.headers.get("Accept") ?? "application/json";
|
|
195
|
-
return this.headers.set("Accept", `application/vnd.pgrst.plan+${a}; for="${s}"; options=${o};`), this;
|
|
196
|
-
}
|
|
197
|
-
rollback() {
|
|
198
|
-
return this.headers.append("Prefer", "tx=rollback"), this;
|
|
199
|
-
}
|
|
200
|
-
returns() {
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
maxAffected(e) {
|
|
204
|
-
return this.headers.append("Prefer", "handling=strict"), this.headers.append("Prefer", `max-affected=${e}`), this;
|
|
205
|
-
}
|
|
206
|
-
}, d = /* @__PURE__ */ RegExp("[,()]"), f = class extends u {
|
|
207
|
-
eq(e, t) {
|
|
208
|
-
return this.url.searchParams.append(e, `eq.${t}`), this;
|
|
209
|
-
}
|
|
210
|
-
neq(e, t) {
|
|
211
|
-
return this.url.searchParams.append(e, `neq.${t}`), this;
|
|
212
|
-
}
|
|
213
|
-
gt(e, t) {
|
|
214
|
-
return this.url.searchParams.append(e, `gt.${t}`), this;
|
|
215
|
-
}
|
|
216
|
-
gte(e, t) {
|
|
217
|
-
return this.url.searchParams.append(e, `gte.${t}`), this;
|
|
218
|
-
}
|
|
219
|
-
lt(e, t) {
|
|
220
|
-
return this.url.searchParams.append(e, `lt.${t}`), this;
|
|
221
|
-
}
|
|
222
|
-
lte(e, t) {
|
|
223
|
-
return this.url.searchParams.append(e, `lte.${t}`), this;
|
|
224
|
-
}
|
|
225
|
-
like(e, t) {
|
|
226
|
-
return this.url.searchParams.append(e, `like.${t}`), this;
|
|
227
|
-
}
|
|
228
|
-
likeAllOf(e, t) {
|
|
229
|
-
return this.url.searchParams.append(e, `like(all).{${t.join(",")}}`), this;
|
|
230
|
-
}
|
|
231
|
-
likeAnyOf(e, t) {
|
|
232
|
-
return this.url.searchParams.append(e, `like(any).{${t.join(",")}}`), this;
|
|
233
|
-
}
|
|
234
|
-
ilike(e, t) {
|
|
235
|
-
return this.url.searchParams.append(e, `ilike.${t}`), this;
|
|
236
|
-
}
|
|
237
|
-
ilikeAllOf(e, t) {
|
|
238
|
-
return this.url.searchParams.append(e, `ilike(all).{${t.join(",")}}`), this;
|
|
239
|
-
}
|
|
240
|
-
ilikeAnyOf(e, t) {
|
|
241
|
-
return this.url.searchParams.append(e, `ilike(any).{${t.join(",")}}`), this;
|
|
242
|
-
}
|
|
243
|
-
regexMatch(e, t) {
|
|
244
|
-
return this.url.searchParams.append(e, `match.${t}`), this;
|
|
245
|
-
}
|
|
246
|
-
regexIMatch(e, t) {
|
|
247
|
-
return this.url.searchParams.append(e, `imatch.${t}`), this;
|
|
248
|
-
}
|
|
249
|
-
is(e, t) {
|
|
250
|
-
return this.url.searchParams.append(e, `is.${t}`), this;
|
|
251
|
-
}
|
|
252
|
-
isDistinct(e, t) {
|
|
253
|
-
return this.url.searchParams.append(e, `isdistinct.${t}`), this;
|
|
254
|
-
}
|
|
255
|
-
in(e, t) {
|
|
256
|
-
let n = Array.from(new Set(t)).map((e) => typeof e == "string" && d.test(e) ? `"${e}"` : `${e}`).join(",");
|
|
257
|
-
return this.url.searchParams.append(e, `in.(${n})`), this;
|
|
258
|
-
}
|
|
259
|
-
notIn(e, t) {
|
|
260
|
-
let n = Array.from(new Set(t)).map((e) => typeof e == "string" && d.test(e) ? `"${e}"` : `${e}`).join(",");
|
|
261
|
-
return this.url.searchParams.append(e, `not.in.(${n})`), this;
|
|
262
|
-
}
|
|
263
|
-
contains(e, t) {
|
|
264
|
-
return typeof t == "string" ? this.url.searchParams.append(e, `cs.${t}`) : Array.isArray(t) ? this.url.searchParams.append(e, `cs.{${t.join(",")}}`) : this.url.searchParams.append(e, `cs.${JSON.stringify(t)}`), this;
|
|
265
|
-
}
|
|
266
|
-
containedBy(e, t) {
|
|
267
|
-
return typeof t == "string" ? this.url.searchParams.append(e, `cd.${t}`) : Array.isArray(t) ? this.url.searchParams.append(e, `cd.{${t.join(",")}}`) : this.url.searchParams.append(e, `cd.${JSON.stringify(t)}`), this;
|
|
268
|
-
}
|
|
269
|
-
rangeGt(e, t) {
|
|
270
|
-
return this.url.searchParams.append(e, `sr.${t}`), this;
|
|
271
|
-
}
|
|
272
|
-
rangeGte(e, t) {
|
|
273
|
-
return this.url.searchParams.append(e, `nxl.${t}`), this;
|
|
274
|
-
}
|
|
275
|
-
rangeLt(e, t) {
|
|
276
|
-
return this.url.searchParams.append(e, `sl.${t}`), this;
|
|
277
|
-
}
|
|
278
|
-
rangeLte(e, t) {
|
|
279
|
-
return this.url.searchParams.append(e, `nxr.${t}`), this;
|
|
280
|
-
}
|
|
281
|
-
rangeAdjacent(e, t) {
|
|
282
|
-
return this.url.searchParams.append(e, `adj.${t}`), this;
|
|
283
|
-
}
|
|
284
|
-
overlaps(e, t) {
|
|
285
|
-
return typeof t == "string" ? this.url.searchParams.append(e, `ov.${t}`) : this.url.searchParams.append(e, `ov.{${t.join(",")}}`), this;
|
|
286
|
-
}
|
|
287
|
-
textSearch(e, t, { config: n, type: r } = {}) {
|
|
288
|
-
let i = "";
|
|
289
|
-
r === "plain" ? i = "pl" : r === "phrase" ? i = "ph" : r === "websearch" && (i = "w");
|
|
290
|
-
let a = n === void 0 ? "" : `(${n})`;
|
|
291
|
-
return this.url.searchParams.append(e, `${i}fts${a}.${t}`), this;
|
|
292
|
-
}
|
|
293
|
-
match(e) {
|
|
294
|
-
return Object.entries(e).filter(([e, t]) => t !== void 0).forEach(([e, t]) => {
|
|
295
|
-
this.url.searchParams.append(e, `eq.${t}`);
|
|
296
|
-
}), this;
|
|
297
|
-
}
|
|
298
|
-
not(e, t, n) {
|
|
299
|
-
return this.url.searchParams.append(e, `not.${t}.${n}`), this;
|
|
300
|
-
}
|
|
301
|
-
or(e, { foreignTable: t, referencedTable: n = t } = {}) {
|
|
302
|
-
let r = n ? `${n}.or` : "or";
|
|
303
|
-
return this.url.searchParams.append(r, `(${e})`), this;
|
|
304
|
-
}
|
|
305
|
-
filter(e, t, n) {
|
|
306
|
-
return this.url.searchParams.append(e, `${t}.${n}`), this;
|
|
307
|
-
}
|
|
308
|
-
}, p = class extends Error {
|
|
3
|
+
import { PostgrestError as n } from "@supabase/supabase-js";
|
|
4
|
+
import * as r from "@supabase/postgrest-js";
|
|
5
|
+
import "@supabase/storage-js";
|
|
6
|
+
//#region lib/errors.ts
|
|
7
|
+
var i = class extends Error {
|
|
309
8
|
constructor(e, t = {}) {
|
|
310
9
|
super(e, t), this.name = this.constructor.name, Error.captureStackTrace(this, this.constructor);
|
|
311
10
|
}
|
|
312
|
-
},
|
|
11
|
+
}, a = class extends i {
|
|
313
12
|
fileId;
|
|
314
13
|
bucket;
|
|
315
14
|
path;
|
|
316
15
|
constructor(e, { fileId: t, bucket: n, path: r } = {}) {
|
|
317
16
|
super(e), this.fileId = t, this.bucket = n, this.path = r;
|
|
318
17
|
}
|
|
319
|
-
},
|
|
18
|
+
}, o = class extends i {
|
|
320
19
|
expression;
|
|
321
20
|
format;
|
|
322
21
|
constructor(e, { expression: t, format: n, ...r } = {}) {
|
|
323
22
|
super(e, r), this.expression = t, this.format = n;
|
|
324
23
|
}
|
|
325
|
-
},
|
|
24
|
+
}, s = class extends i {
|
|
326
25
|
schema;
|
|
327
26
|
relation;
|
|
328
27
|
id;
|
|
329
28
|
constructor(e, { schema: t, relation: n, id: r } = {}) {
|
|
330
29
|
super(e), this.schema = t, this.relation = n, this.id = r;
|
|
331
30
|
}
|
|
332
|
-
},
|
|
31
|
+
}, c = t.object({
|
|
333
32
|
code: t.string(),
|
|
334
33
|
details: t.string().nullable(),
|
|
335
34
|
hint: t.string().nullable(),
|
|
336
35
|
name: t.string().optional(),
|
|
337
36
|
message: t.string().optional()
|
|
338
37
|
});
|
|
339
|
-
function
|
|
340
|
-
return e instanceof
|
|
38
|
+
function l(e) {
|
|
39
|
+
return e instanceof n || c.safeParse(e).success;
|
|
341
40
|
}
|
|
342
41
|
//#endregion
|
|
343
42
|
//#region lib/utils.ts
|
|
344
|
-
function
|
|
43
|
+
function u(e, t = "/") {
|
|
345
44
|
let n = e.lastIndexOf(t);
|
|
346
45
|
return n === -1 ? ["", e] : [e.substring(0, n), e.substring(n + 1)];
|
|
347
46
|
}
|
|
348
|
-
function
|
|
47
|
+
function d(e) {
|
|
349
48
|
return Array.isArray(e) ? e : [e];
|
|
350
49
|
}
|
|
351
|
-
function
|
|
50
|
+
function f(e, t) {
|
|
352
51
|
return e.reduce((e, n) => {
|
|
353
52
|
let r = t(n);
|
|
354
53
|
return (e[r] ??= []).push(n), e;
|
|
355
54
|
}, {});
|
|
356
55
|
}
|
|
357
|
-
function
|
|
56
|
+
function p(e, t) {
|
|
358
57
|
let n = e.findIndex(t);
|
|
359
58
|
return n !== -1 && e.splice(n, 1), e;
|
|
360
59
|
}
|
|
361
|
-
function
|
|
60
|
+
function m(e) {
|
|
362
61
|
return Object.entries(e);
|
|
363
62
|
}
|
|
364
63
|
//#endregion
|
|
365
64
|
//#region lib/data-service.ts
|
|
366
|
-
var
|
|
65
|
+
var h = class {
|
|
367
66
|
database;
|
|
368
67
|
schema;
|
|
369
68
|
relation;
|
|
@@ -371,7 +70,7 @@ var w = class {
|
|
|
371
70
|
this.database = e, this.schema = t, this.relation = n;
|
|
372
71
|
}
|
|
373
72
|
recordNotFoundError(e) {
|
|
374
|
-
return new
|
|
73
|
+
return new s(`Record with id ${e} not found in ${this.schema}.${this.relation}`, {
|
|
375
74
|
schema: this.schema,
|
|
376
75
|
relation: this.relation,
|
|
377
76
|
id: e
|
|
@@ -419,7 +118,7 @@ var w = class {
|
|
|
419
118
|
}
|
|
420
119
|
async upsert(e, { onConflict: t, ...n } = {}) {
|
|
421
120
|
let { data: r } = await this.query.upsert(e, {
|
|
422
|
-
onConflict: t === void 0 ? void 0 :
|
|
121
|
+
onConflict: t === void 0 ? void 0 : d(t).join(","),
|
|
423
122
|
...n
|
|
424
123
|
}).select().single().throwOnError();
|
|
425
124
|
return r;
|
|
@@ -428,7 +127,7 @@ var w = class {
|
|
|
428
127
|
let { data: n } = await this.query.update(t).eq("id", e).select().single().throwOnError();
|
|
429
128
|
return n;
|
|
430
129
|
}
|
|
431
|
-
},
|
|
130
|
+
}, g = class extends h {
|
|
432
131
|
constructor({ database: e, schema: t, table: n }) {
|
|
433
132
|
super({
|
|
434
133
|
database: e,
|
|
@@ -436,7 +135,7 @@ var w = class {
|
|
|
436
135
|
relation: n
|
|
437
136
|
});
|
|
438
137
|
}
|
|
439
|
-
},
|
|
138
|
+
}, _ = class extends h {
|
|
440
139
|
constructor({ database: e, schema: t, view: n }) {
|
|
441
140
|
super({
|
|
442
141
|
database: e,
|
|
@@ -445,13 +144,13 @@ var w = class {
|
|
|
445
144
|
});
|
|
446
145
|
}
|
|
447
146
|
};
|
|
448
|
-
function
|
|
147
|
+
function v(t) {
|
|
449
148
|
if (t.error) throw t.error;
|
|
450
149
|
return e(t.count !== null, "Response does not contain a count. Make sure to set the `count` option in the request."), t;
|
|
451
150
|
}
|
|
452
151
|
//#endregion
|
|
453
152
|
//#region lib/postgrest/filter.ts
|
|
454
|
-
var
|
|
153
|
+
var y = [
|
|
455
154
|
"eq",
|
|
456
155
|
"neq",
|
|
457
156
|
"gt",
|
|
@@ -477,17 +176,17 @@ var O = [
|
|
|
477
176
|
"nxr",
|
|
478
177
|
"nxl",
|
|
479
178
|
"adj"
|
|
480
|
-
],
|
|
179
|
+
], b = ["and", "or"], x = ",", S = "~", C = (e) => (n = {}) => {
|
|
481
180
|
let r = (e) => n[e] ?? e, i = Object.keys(e.shape);
|
|
482
181
|
return t.string().transform((e, t) => {
|
|
483
182
|
try {
|
|
484
|
-
return
|
|
183
|
+
return k(e, i, r);
|
|
485
184
|
} catch (n) {
|
|
486
185
|
return t.addIssue({
|
|
487
186
|
code: "custom",
|
|
488
187
|
input: e,
|
|
489
188
|
message: n instanceof Error ? n.message : void 0,
|
|
490
|
-
params: n instanceof
|
|
189
|
+
params: n instanceof o ? {
|
|
491
190
|
expression: n.expression,
|
|
492
191
|
format: n.format
|
|
493
192
|
} : void 0
|
|
@@ -495,26 +194,26 @@ var O = [
|
|
|
495
194
|
}
|
|
496
195
|
});
|
|
497
196
|
};
|
|
498
|
-
function
|
|
197
|
+
function w(e) {
|
|
499
198
|
return e.startsWith("not.") ? e.slice(4) : `not.${e}`;
|
|
500
199
|
}
|
|
501
|
-
function
|
|
200
|
+
function T(e) {
|
|
502
201
|
return {
|
|
503
202
|
...e,
|
|
504
|
-
op:
|
|
203
|
+
op: w(e.op)
|
|
505
204
|
};
|
|
506
205
|
}
|
|
507
|
-
function
|
|
206
|
+
function E(e, t = (e) => e) {
|
|
508
207
|
if (e.type === "logical") {
|
|
509
|
-
let n = e.args.map((e) =>
|
|
208
|
+
let n = e.args.map((e) => E(e, t));
|
|
510
209
|
return `${e.op}(${n})`;
|
|
511
210
|
}
|
|
512
211
|
return `${t(e.key)}.${e.op}.${e.value}`;
|
|
513
212
|
}
|
|
514
|
-
function
|
|
515
|
-
return e.map((e) =>
|
|
213
|
+
function D(e, t = (e) => e, n = "~") {
|
|
214
|
+
return e.map((e) => E(e, t)).join(n);
|
|
516
215
|
}
|
|
517
|
-
function
|
|
216
|
+
function O(t, n = [], r = (e) => e) {
|
|
518
217
|
function i(e) {
|
|
519
218
|
let t = [], n = 0, r = "", i = !1;
|
|
520
219
|
for (let a of e) a === "\"" ? (i = !i, r += a) : a === "(" && !i ? (n++, r += a) : a === ")" && !i ? (n--, r += a) : a === "," && n === 0 && !i ? (t.push(r.trim()), r = "") : r += a;
|
|
@@ -524,47 +223,47 @@ function L(t, n = [], r = (e) => e) {
|
|
|
524
223
|
if (t.startsWith("and(")) return {
|
|
525
224
|
type: "logical",
|
|
526
225
|
op: "and",
|
|
527
|
-
args: i(t.slice(4, -1)).map((e) =>
|
|
226
|
+
args: i(t.slice(4, -1)).map((e) => O(e, n, r))
|
|
528
227
|
};
|
|
529
228
|
if (t.startsWith("or(")) return {
|
|
530
229
|
type: "logical",
|
|
531
230
|
op: "or",
|
|
532
|
-
args: i(t.slice(3, -1)).map((e) =>
|
|
231
|
+
args: i(t.slice(3, -1)).map((e) => O(e, n, r))
|
|
533
232
|
};
|
|
534
233
|
if (t.startsWith("not.and(")) return {
|
|
535
234
|
type: "logical",
|
|
536
235
|
op: "not.and",
|
|
537
|
-
args: i(t.slice(8, -1)).map((e) =>
|
|
236
|
+
args: i(t.slice(8, -1)).map((e) => O(e, n, r))
|
|
538
237
|
};
|
|
539
238
|
if (t.startsWith("not.or(")) return {
|
|
540
239
|
type: "logical",
|
|
541
240
|
op: "not.or",
|
|
542
|
-
args: i(t.slice(7, -1)).map((e) =>
|
|
241
|
+
args: i(t.slice(7, -1)).map((e) => O(e, n, r))
|
|
543
242
|
};
|
|
544
243
|
}
|
|
545
|
-
let a = `^(${n.length === 0 ? "[a-zA-Z_][a-zA-Z0-9_]*" : n.join("|")})\\.((?:not\\.)?(?:${
|
|
546
|
-
if (!
|
|
244
|
+
let a = `^(${n.length === 0 ? "[a-zA-Z_][a-zA-Z0-9_]*" : n.join("|")})\\.((?:not\\.)?(?:${y.join("|")}))\\.(.+)$`, s = new RegExp(a).exec(t);
|
|
245
|
+
if (!s) throw new o(`Invalid filter expression '${t}'`, {
|
|
547
246
|
expression: t,
|
|
548
247
|
format: {
|
|
549
248
|
syntax: "key.(not.)op.value",
|
|
550
249
|
keys: n.length === 0 ? "*" : n,
|
|
551
|
-
operators:
|
|
250
|
+
operators: y
|
|
552
251
|
}
|
|
553
252
|
});
|
|
554
|
-
let [,
|
|
253
|
+
let [, c, l, u] = s;
|
|
555
254
|
return {
|
|
556
255
|
type: "condition",
|
|
557
|
-
key: r(
|
|
558
|
-
op:
|
|
559
|
-
value: e.defined(
|
|
256
|
+
key: r(c),
|
|
257
|
+
op: l,
|
|
258
|
+
value: e.defined(u)
|
|
560
259
|
};
|
|
561
260
|
}
|
|
562
|
-
function
|
|
563
|
-
return e.length === 0 ? [] : e.split(r).map((e) =>
|
|
261
|
+
function k(e, t = [], n = (e) => e, r = "~") {
|
|
262
|
+
return e.length === 0 ? [] : e.split(r).map((e) => O(e, t, n));
|
|
564
263
|
}
|
|
565
264
|
//#endregion
|
|
566
265
|
//#region lib/postgrest/pagination-builder.ts
|
|
567
|
-
var
|
|
266
|
+
var A = class t extends j {
|
|
568
267
|
pagination;
|
|
569
268
|
constructor(e, t) {
|
|
570
269
|
super(e), this.pagination = t;
|
|
@@ -593,16 +292,16 @@ var z = class t extends B {
|
|
|
593
292
|
return t;
|
|
594
293
|
});
|
|
595
294
|
}
|
|
596
|
-
},
|
|
295
|
+
}, j = class t extends r.PostgrestFilterBuilder {
|
|
597
296
|
constructor(e) {
|
|
598
297
|
super(e);
|
|
599
298
|
}
|
|
600
299
|
select(e = "*") {
|
|
601
|
-
return new t(super.select(
|
|
300
|
+
return new t(super.select(d(e).join(",")));
|
|
602
301
|
}
|
|
603
302
|
where(e) {
|
|
604
303
|
if (e.type === "logical") {
|
|
605
|
-
let t = e.args.map((e) =>
|
|
304
|
+
let t = e.args.map((e) => E(e)).join(",");
|
|
606
305
|
return this.url.searchParams.append(e.op, `(${t})`), this;
|
|
607
306
|
}
|
|
608
307
|
return this.filter(e.key, e.op, e.value);
|
|
@@ -610,75 +309,75 @@ var z = class t extends B {
|
|
|
610
309
|
paginate(t, n) {
|
|
611
310
|
e(t >= 0, "Page index must be ≥ 0"), e(n >= 0, "Page limit must be ≥ 0");
|
|
612
311
|
let r = t * n, i = r + n - 1;
|
|
613
|
-
return new
|
|
312
|
+
return new A(this.range(r, i), {
|
|
614
313
|
page: t,
|
|
615
314
|
limit: n
|
|
616
315
|
});
|
|
617
316
|
}
|
|
618
|
-
},
|
|
317
|
+
}, M = class {
|
|
619
318
|
builder;
|
|
620
319
|
constructor(e) {
|
|
621
320
|
this.builder = e;
|
|
622
321
|
}
|
|
623
322
|
select(e = "*", t) {
|
|
624
|
-
return new
|
|
323
|
+
return new j(this.builder.select(d(e).join(","), t));
|
|
625
324
|
}
|
|
626
325
|
count(e = "exact") {
|
|
627
|
-
return new
|
|
326
|
+
return new j(this.select("*", {
|
|
628
327
|
count: e,
|
|
629
328
|
head: !0
|
|
630
329
|
}));
|
|
631
330
|
}
|
|
632
331
|
insert(e, t) {
|
|
633
|
-
return new
|
|
332
|
+
return new j(this.builder.insert(e, t));
|
|
634
333
|
}
|
|
635
334
|
upsert(e, { onConflict: t, ...n } = {}) {
|
|
636
|
-
return new
|
|
637
|
-
onConflict:
|
|
335
|
+
return new j(this.builder.upsert(e, {
|
|
336
|
+
onConflict: d(t).join(","),
|
|
638
337
|
...n
|
|
639
338
|
}));
|
|
640
339
|
}
|
|
641
340
|
update(e, t) {
|
|
642
|
-
return new
|
|
341
|
+
return new j(this.builder.update(e, t));
|
|
643
342
|
}
|
|
644
343
|
delete() {
|
|
645
|
-
return new
|
|
344
|
+
return new j(this.builder.delete());
|
|
646
345
|
}
|
|
647
|
-
},
|
|
346
|
+
}, N = class {
|
|
648
347
|
client;
|
|
649
348
|
constructor(e) {
|
|
650
349
|
this.client = e;
|
|
651
350
|
}
|
|
652
351
|
from(e) {
|
|
653
|
-
return new
|
|
352
|
+
return new M(this.client.from(e));
|
|
654
353
|
}
|
|
655
354
|
rpc(e, t, n) {
|
|
656
|
-
return new
|
|
355
|
+
return new j(this.client.rpc(e, t, n));
|
|
657
356
|
}
|
|
658
|
-
},
|
|
357
|
+
}, P = class {
|
|
659
358
|
supabase;
|
|
660
359
|
constructor({ supabase: e }) {
|
|
661
360
|
this.supabase = e;
|
|
662
361
|
}
|
|
663
362
|
schema(e) {
|
|
664
|
-
return new
|
|
363
|
+
return new N(this.supabase.schema(e));
|
|
665
364
|
}
|
|
666
365
|
relation(e, t) {
|
|
667
|
-
return new
|
|
366
|
+
return new h({
|
|
668
367
|
database: this,
|
|
669
368
|
schema: e,
|
|
670
369
|
relation: t
|
|
671
370
|
});
|
|
672
371
|
}
|
|
673
372
|
table(e, t) {
|
|
674
|
-
return new
|
|
373
|
+
return new g({
|
|
675
374
|
database: this,
|
|
676
375
|
schema: e,
|
|
677
376
|
table: t
|
|
678
377
|
});
|
|
679
378
|
}
|
|
680
379
|
view(e, t) {
|
|
681
|
-
return new
|
|
380
|
+
return new _({
|
|
682
381
|
database: this,
|
|
683
382
|
schema: e,
|
|
684
383
|
view: t
|
|
@@ -687,15 +386,15 @@ var z = class t extends B {
|
|
|
687
386
|
};
|
|
688
387
|
//#endregion
|
|
689
388
|
//#region lib/storage.ts
|
|
690
|
-
function
|
|
389
|
+
function F(e) {
|
|
691
390
|
return e.bucket !== void 0 && e.path !== void 0;
|
|
692
391
|
}
|
|
693
|
-
function
|
|
392
|
+
function I(e) {
|
|
694
393
|
return e.fileId !== void 0 && e.bucket !== void 0;
|
|
695
394
|
}
|
|
696
395
|
//#endregion
|
|
697
396
|
//#region lib/storage-service.ts
|
|
698
|
-
var
|
|
397
|
+
var L = class {
|
|
699
398
|
client;
|
|
700
399
|
database;
|
|
701
400
|
constructor({ client: e, database: t }) {
|
|
@@ -715,8 +414,8 @@ var K = class {
|
|
|
715
414
|
return n;
|
|
716
415
|
}
|
|
717
416
|
async getFileStorageLocation(t) {
|
|
718
|
-
if (
|
|
719
|
-
if (
|
|
417
|
+
if (I(t)) return t;
|
|
418
|
+
if (F(t)) {
|
|
720
419
|
let { id: e } = await this.getFileObject(t);
|
|
721
420
|
return {
|
|
722
421
|
fileId: e,
|
|
@@ -724,7 +423,7 @@ var K = class {
|
|
|
724
423
|
};
|
|
725
424
|
}
|
|
726
425
|
let { fileId: n } = t, r = await this.files.get(n, ["bucket_id", "path_tokens"]);
|
|
727
|
-
if (r === void 0) throw new
|
|
426
|
+
if (r === void 0) throw new a(`File with ID ${n} not found`, { fileId: n });
|
|
728
427
|
return {
|
|
729
428
|
fileId: n,
|
|
730
429
|
bucket: e.notNull(r.bucket_id, "bucket_id must not be null"),
|
|
@@ -755,7 +454,7 @@ var K = class {
|
|
|
755
454
|
async assertExistsFile(e) {
|
|
756
455
|
let { bucket: t, path: n } = await this.getFileStorageLocation(e), { data: r, error: i } = await this.client.from(t).exists(n);
|
|
757
456
|
if (i) throw i;
|
|
758
|
-
if (!r) throw new
|
|
457
|
+
if (!r) throw new a(`File not found in bucket '${t}' at path '${n}'`, {
|
|
759
458
|
bucket: t,
|
|
760
459
|
path: n
|
|
761
460
|
});
|
|
@@ -772,7 +471,7 @@ var K = class {
|
|
|
772
471
|
async downloadFile(e) {
|
|
773
472
|
let { fileId: t, bucket: n, path: r, properties: i } = await this.getFileInfo(e), { data: a, error: o } = await this.client.from(n).download(r);
|
|
774
473
|
if (o) throw o;
|
|
775
|
-
let [, s] =
|
|
474
|
+
let [, s] = u(r);
|
|
776
475
|
return {
|
|
777
476
|
fileId: t,
|
|
778
477
|
bucket: n,
|
|
@@ -784,7 +483,7 @@ var K = class {
|
|
|
784
483
|
let n = t.filter((e) => "fileId" in e).map((e) => e.fileId), r = (await this.files.query.select(["bucket_id", "path_tokens"]).containedBy("id", n).throwOnError()).data.map(({ bucket_id: t, path_tokens: n }) => ({
|
|
785
484
|
bucket: e.notNull(t, "bucket_id must not be null"),
|
|
786
485
|
path: e.notNull(n, "path_tokens must not be null").join("/")
|
|
787
|
-
})), i =
|
|
486
|
+
})), i = m(f(t.filter((e) => F(e)).concat(r), (e) => e.bucket)).map(([e, t]) => ({
|
|
788
487
|
bucket: e,
|
|
789
488
|
paths: t.map((e) => e.path)
|
|
790
489
|
}));
|
|
@@ -799,4 +498,4 @@ var K = class {
|
|
|
799
498
|
}
|
|
800
499
|
};
|
|
801
500
|
//#endregion
|
|
802
|
-
export {
|
|
501
|
+
export { h as DataService, P as DatabaseService, a as FileNotFoundError, C as Filter, S as FilterChainSeparator, y as FilterOp, b as LogicalOp, x as LogicalOpSeparator, o as ParseError, N as PostgrestClient, c as PostgrestErrorInterface, j as PostgrestFilterBuilder, A as PostgrestPaginationBuilder, M as PostgrestQueryBuilder, s as RecordNotFoundError, L as StorageService, g as TableDataService, i as TracedError, _ as ViewDataService, v as assertCounted, d as coerceArray, D as encodeFilter, E as encodeFilterNode, m as entries, f as groupBy, l as isDatabaseApiError, T as negateFilterNode, w as negateOp, O as parseFilterExpression, k as parseFilterExpressionChain, p as removeElement, u as splitPath };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"private": false,
|
|
4
4
|
"displayName": "Supabase-Core",
|
|
5
5
|
"description": "Lightweight services for supabase to make it easier to work with databases, tables and storage buckets",
|
|
6
|
-
"version": "2.2.
|
|
6
|
+
"version": "2.2.2",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@freehour/assert": "^1.0.1",
|
|
31
|
-
"zod": "4.3
|
|
31
|
+
"zod": "^4.4.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@supabase/postgrest-js": "^2.106.1",
|