@xata.io/client 0.0.0-alpha.vfd071d9 → 0.0.0-alpha.vfd609764793466374d6519edeb1be8debc9a83d5
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/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +700 -0
- package/README.md +7 -1
- package/dist/index.cjs +2965 -1278
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7757 -1719
- package/dist/index.mjs +2878 -1275
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -10
- package/.eslintrc.cjs +0 -13
- package/rollup.config.js +0 -29
- package/tsconfig.json +0 -22
package/dist/index.cjs
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
const defaultTrace = async (name, fn, _options) => {
|
4
|
+
return await fn({
|
5
|
+
name,
|
6
|
+
setAttributes: () => {
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
});
|
10
|
+
};
|
11
|
+
const TraceAttributes = {
|
12
|
+
KIND: "xata.trace.kind",
|
13
|
+
VERSION: "xata.sdk.version",
|
14
|
+
TABLE: "xata.table",
|
15
|
+
HTTP_REQUEST_ID: "http.request_id",
|
16
|
+
HTTP_STATUS_CODE: "http.status_code",
|
17
|
+
HTTP_HOST: "http.host",
|
18
|
+
HTTP_SCHEME: "http.scheme",
|
19
|
+
HTTP_USER_AGENT: "http.user_agent",
|
20
|
+
HTTP_METHOD: "http.method",
|
21
|
+
HTTP_URL: "http.url",
|
22
|
+
HTTP_ROUTE: "http.route",
|
23
|
+
HTTP_TARGET: "http.target",
|
24
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
25
|
+
};
|
4
26
|
|
5
27
|
function notEmpty(value) {
|
6
28
|
return value !== null && value !== void 0;
|
@@ -8,82 +30,526 @@ function notEmpty(value) {
|
|
8
30
|
function compact(arr) {
|
9
31
|
return arr.filter(notEmpty);
|
10
32
|
}
|
33
|
+
function compactObject(obj) {
|
34
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
35
|
+
}
|
36
|
+
function isBlob(value) {
|
37
|
+
try {
|
38
|
+
return value instanceof Blob;
|
39
|
+
} catch (error) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
}
|
11
43
|
function isObject(value) {
|
12
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
44
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
45
|
+
}
|
46
|
+
function isDefined(value) {
|
47
|
+
return value !== null && value !== void 0;
|
13
48
|
}
|
14
49
|
function isString(value) {
|
15
|
-
return value
|
50
|
+
return isDefined(value) && typeof value === "string";
|
51
|
+
}
|
52
|
+
function isStringArray(value) {
|
53
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
54
|
+
}
|
55
|
+
function isNumber(value) {
|
56
|
+
return isDefined(value) && typeof value === "number";
|
57
|
+
}
|
58
|
+
function parseNumber(value) {
|
59
|
+
if (isNumber(value)) {
|
60
|
+
return value;
|
61
|
+
}
|
62
|
+
if (isString(value)) {
|
63
|
+
const parsed = Number(value);
|
64
|
+
if (!Number.isNaN(parsed)) {
|
65
|
+
return parsed;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return void 0;
|
16
69
|
}
|
17
70
|
function toBase64(value) {
|
18
71
|
try {
|
19
72
|
return btoa(value);
|
20
73
|
} catch (err) {
|
21
|
-
|
74
|
+
const buf = Buffer;
|
75
|
+
return buf.from(value).toString("base64");
|
76
|
+
}
|
77
|
+
}
|
78
|
+
function deepMerge(a, b) {
|
79
|
+
const result = { ...a };
|
80
|
+
for (const [key, value] of Object.entries(b)) {
|
81
|
+
if (isObject(value) && isObject(result[key])) {
|
82
|
+
result[key] = deepMerge(result[key], value);
|
83
|
+
} else {
|
84
|
+
result[key] = value;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return result;
|
88
|
+
}
|
89
|
+
function chunk(array, chunkSize) {
|
90
|
+
const result = [];
|
91
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
92
|
+
result.push(array.slice(i, i + chunkSize));
|
22
93
|
}
|
94
|
+
return result;
|
95
|
+
}
|
96
|
+
async function timeout(ms) {
|
97
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
98
|
+
}
|
99
|
+
function timeoutWithCancel(ms) {
|
100
|
+
let timeoutId;
|
101
|
+
const promise = new Promise((resolve) => {
|
102
|
+
timeoutId = setTimeout(() => {
|
103
|
+
resolve();
|
104
|
+
}, ms);
|
105
|
+
});
|
106
|
+
return {
|
107
|
+
cancel: () => clearTimeout(timeoutId),
|
108
|
+
promise
|
109
|
+
};
|
110
|
+
}
|
111
|
+
function promiseMap(inputValues, mapper) {
|
112
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
113
|
+
(acc) => mapper(inputValue).then((result) => {
|
114
|
+
acc.push(result);
|
115
|
+
return acc;
|
116
|
+
})
|
117
|
+
);
|
118
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
23
119
|
}
|
24
120
|
|
25
|
-
function
|
121
|
+
function getEnvironment() {
|
26
122
|
try {
|
27
|
-
if (
|
28
|
-
return
|
123
|
+
if (isDefined(process) && isDefined(process.env)) {
|
124
|
+
return {
|
125
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
126
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
127
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
128
|
+
deployPreview: process.env.XATA_PREVIEW,
|
129
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
130
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
131
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
132
|
+
};
|
29
133
|
}
|
30
134
|
} catch (err) {
|
31
135
|
}
|
32
136
|
try {
|
33
|
-
if (isObject(Deno) &&
|
34
|
-
return
|
137
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
138
|
+
return {
|
139
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
140
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
141
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
142
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
143
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
144
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
145
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
146
|
+
};
|
35
147
|
}
|
36
148
|
} catch (err) {
|
37
149
|
}
|
150
|
+
return {
|
151
|
+
apiKey: getGlobalApiKey(),
|
152
|
+
databaseURL: getGlobalDatabaseURL(),
|
153
|
+
branch: getGlobalBranch(),
|
154
|
+
deployPreview: void 0,
|
155
|
+
deployPreviewBranch: void 0,
|
156
|
+
vercelGitCommitRef: void 0,
|
157
|
+
vercelGitRepoOwner: void 0
|
158
|
+
};
|
38
159
|
}
|
39
|
-
|
160
|
+
function getEnableBrowserVariable() {
|
40
161
|
try {
|
41
|
-
if (
|
42
|
-
|
43
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
162
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
163
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
44
164
|
}
|
45
165
|
} catch (err) {
|
46
166
|
}
|
47
167
|
try {
|
48
|
-
if (isObject(Deno)) {
|
49
|
-
|
50
|
-
cmd: ["git", "branch", "--show-current"],
|
51
|
-
stdout: "piped",
|
52
|
-
stderr: "piped"
|
53
|
-
});
|
54
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
168
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
169
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
55
170
|
}
|
56
171
|
} catch (err) {
|
57
172
|
}
|
173
|
+
try {
|
174
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
175
|
+
} catch (err) {
|
176
|
+
return void 0;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
function getGlobalApiKey() {
|
180
|
+
try {
|
181
|
+
return XATA_API_KEY;
|
182
|
+
} catch (err) {
|
183
|
+
return void 0;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
function getGlobalDatabaseURL() {
|
187
|
+
try {
|
188
|
+
return XATA_DATABASE_URL;
|
189
|
+
} catch (err) {
|
190
|
+
return void 0;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
function getGlobalBranch() {
|
194
|
+
try {
|
195
|
+
return XATA_BRANCH;
|
196
|
+
} catch (err) {
|
197
|
+
return void 0;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
function getDatabaseURL() {
|
201
|
+
try {
|
202
|
+
const { databaseURL } = getEnvironment();
|
203
|
+
return databaseURL;
|
204
|
+
} catch (err) {
|
205
|
+
return void 0;
|
206
|
+
}
|
58
207
|
}
|
59
|
-
|
60
208
|
function getAPIKey() {
|
61
209
|
try {
|
62
|
-
|
210
|
+
const { apiKey } = getEnvironment();
|
211
|
+
return apiKey;
|
212
|
+
} catch (err) {
|
213
|
+
return void 0;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
function getBranch() {
|
217
|
+
try {
|
218
|
+
const { branch } = getEnvironment();
|
219
|
+
return branch;
|
220
|
+
} catch (err) {
|
221
|
+
return void 0;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
function buildPreviewBranchName({ org, branch }) {
|
225
|
+
return `preview-${org}-${branch}`;
|
226
|
+
}
|
227
|
+
function getPreviewBranch() {
|
228
|
+
try {
|
229
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
230
|
+
if (deployPreviewBranch)
|
231
|
+
return deployPreviewBranch;
|
232
|
+
switch (deployPreview) {
|
233
|
+
case "vercel": {
|
234
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
235
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
236
|
+
return void 0;
|
237
|
+
}
|
238
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
239
|
+
}
|
240
|
+
}
|
241
|
+
return void 0;
|
63
242
|
} catch (err) {
|
64
243
|
return void 0;
|
65
244
|
}
|
66
245
|
}
|
67
246
|
|
247
|
+
var __accessCheck$6 = (obj, member, msg) => {
|
248
|
+
if (!member.has(obj))
|
249
|
+
throw TypeError("Cannot " + msg);
|
250
|
+
};
|
251
|
+
var __privateGet$5 = (obj, member, getter) => {
|
252
|
+
__accessCheck$6(obj, member, "read from private field");
|
253
|
+
return getter ? getter.call(obj) : member.get(obj);
|
254
|
+
};
|
255
|
+
var __privateAdd$6 = (obj, member, value) => {
|
256
|
+
if (member.has(obj))
|
257
|
+
throw TypeError("Cannot add the same private member more than once");
|
258
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
259
|
+
};
|
260
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
261
|
+
__accessCheck$6(obj, member, "write to private field");
|
262
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
263
|
+
return value;
|
264
|
+
};
|
265
|
+
var __privateMethod$4 = (obj, member, method) => {
|
266
|
+
__accessCheck$6(obj, member, "access private method");
|
267
|
+
return method;
|
268
|
+
};
|
269
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
270
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
68
271
|
function getFetchImplementation(userFetch) {
|
69
272
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
70
|
-
const
|
273
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
274
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
71
275
|
if (!fetchImpl) {
|
72
|
-
throw new Error(`
|
276
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
73
277
|
}
|
74
278
|
return fetchImpl;
|
75
279
|
}
|
280
|
+
class ApiRequestPool {
|
281
|
+
constructor(concurrency = 10) {
|
282
|
+
__privateAdd$6(this, _enqueue);
|
283
|
+
__privateAdd$6(this, _fetch, void 0);
|
284
|
+
__privateAdd$6(this, _queue, void 0);
|
285
|
+
__privateAdd$6(this, _concurrency, void 0);
|
286
|
+
__privateSet$4(this, _queue, []);
|
287
|
+
__privateSet$4(this, _concurrency, concurrency);
|
288
|
+
this.running = 0;
|
289
|
+
this.started = 0;
|
290
|
+
}
|
291
|
+
setFetch(fetch2) {
|
292
|
+
__privateSet$4(this, _fetch, fetch2);
|
293
|
+
}
|
294
|
+
getFetch() {
|
295
|
+
if (!__privateGet$5(this, _fetch)) {
|
296
|
+
throw new Error("Fetch not set");
|
297
|
+
}
|
298
|
+
return __privateGet$5(this, _fetch);
|
299
|
+
}
|
300
|
+
request(url, options) {
|
301
|
+
const start = /* @__PURE__ */ new Date();
|
302
|
+
const fetchImpl = this.getFetch();
|
303
|
+
const runRequest = async (stalled = false) => {
|
304
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
305
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
306
|
+
if (!response) {
|
307
|
+
throw new Error("Request timed out");
|
308
|
+
}
|
309
|
+
if (response.status === 429) {
|
310
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
311
|
+
await timeout(rateLimitReset * 1e3);
|
312
|
+
return await runRequest(true);
|
313
|
+
}
|
314
|
+
if (stalled) {
|
315
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
316
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
317
|
+
}
|
318
|
+
return response;
|
319
|
+
};
|
320
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
321
|
+
return await runRequest();
|
322
|
+
});
|
323
|
+
}
|
324
|
+
}
|
325
|
+
_fetch = new WeakMap();
|
326
|
+
_queue = new WeakMap();
|
327
|
+
_concurrency = new WeakMap();
|
328
|
+
_enqueue = new WeakSet();
|
329
|
+
enqueue_fn = function(task) {
|
330
|
+
const promise = new Promise((resolve) => __privateGet$5(this, _queue).push(resolve)).finally(() => {
|
331
|
+
this.started--;
|
332
|
+
this.running++;
|
333
|
+
}).then(() => task()).finally(() => {
|
334
|
+
this.running--;
|
335
|
+
const next = __privateGet$5(this, _queue).shift();
|
336
|
+
if (next !== void 0) {
|
337
|
+
this.started++;
|
338
|
+
next();
|
339
|
+
}
|
340
|
+
});
|
341
|
+
if (this.running + this.started < __privateGet$5(this, _concurrency)) {
|
342
|
+
const next = __privateGet$5(this, _queue).shift();
|
343
|
+
if (next !== void 0) {
|
344
|
+
this.started++;
|
345
|
+
next();
|
346
|
+
}
|
347
|
+
}
|
348
|
+
return promise;
|
349
|
+
};
|
350
|
+
|
351
|
+
function generateUUID() {
|
352
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
353
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
354
|
+
return v.toString(16);
|
355
|
+
});
|
356
|
+
}
|
76
357
|
|
77
|
-
|
78
|
-
|
358
|
+
async function getBytes(stream, onChunk) {
|
359
|
+
const reader = stream.getReader();
|
360
|
+
let result;
|
361
|
+
while (!(result = await reader.read()).done) {
|
362
|
+
onChunk(result.value);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
function getLines(onLine) {
|
366
|
+
let buffer;
|
367
|
+
let position;
|
368
|
+
let fieldLength;
|
369
|
+
let discardTrailingNewline = false;
|
370
|
+
return function onChunk(arr) {
|
371
|
+
if (buffer === void 0) {
|
372
|
+
buffer = arr;
|
373
|
+
position = 0;
|
374
|
+
fieldLength = -1;
|
375
|
+
} else {
|
376
|
+
buffer = concat(buffer, arr);
|
377
|
+
}
|
378
|
+
const bufLength = buffer.length;
|
379
|
+
let lineStart = 0;
|
380
|
+
while (position < bufLength) {
|
381
|
+
if (discardTrailingNewline) {
|
382
|
+
if (buffer[position] === 10 /* NewLine */) {
|
383
|
+
lineStart = ++position;
|
384
|
+
}
|
385
|
+
discardTrailingNewline = false;
|
386
|
+
}
|
387
|
+
let lineEnd = -1;
|
388
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
389
|
+
switch (buffer[position]) {
|
390
|
+
case 58 /* Colon */:
|
391
|
+
if (fieldLength === -1) {
|
392
|
+
fieldLength = position - lineStart;
|
393
|
+
}
|
394
|
+
break;
|
395
|
+
case 13 /* CarriageReturn */:
|
396
|
+
discardTrailingNewline = true;
|
397
|
+
case 10 /* NewLine */:
|
398
|
+
lineEnd = position;
|
399
|
+
break;
|
400
|
+
}
|
401
|
+
}
|
402
|
+
if (lineEnd === -1) {
|
403
|
+
break;
|
404
|
+
}
|
405
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
406
|
+
lineStart = position;
|
407
|
+
fieldLength = -1;
|
408
|
+
}
|
409
|
+
if (lineStart === bufLength) {
|
410
|
+
buffer = void 0;
|
411
|
+
} else if (lineStart !== 0) {
|
412
|
+
buffer = buffer.subarray(lineStart);
|
413
|
+
position -= lineStart;
|
414
|
+
}
|
415
|
+
};
|
416
|
+
}
|
417
|
+
function getMessages(onId, onRetry, onMessage) {
|
418
|
+
let message = newMessage();
|
419
|
+
const decoder = new TextDecoder();
|
420
|
+
return function onLine(line, fieldLength) {
|
421
|
+
if (line.length === 0) {
|
422
|
+
onMessage?.(message);
|
423
|
+
message = newMessage();
|
424
|
+
} else if (fieldLength > 0) {
|
425
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
426
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
427
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
428
|
+
switch (field) {
|
429
|
+
case "data":
|
430
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
431
|
+
break;
|
432
|
+
case "event":
|
433
|
+
message.event = value;
|
434
|
+
break;
|
435
|
+
case "id":
|
436
|
+
onId(message.id = value);
|
437
|
+
break;
|
438
|
+
case "retry":
|
439
|
+
const retry = parseInt(value, 10);
|
440
|
+
if (!isNaN(retry)) {
|
441
|
+
onRetry(message.retry = retry);
|
442
|
+
}
|
443
|
+
break;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
};
|
447
|
+
}
|
448
|
+
function concat(a, b) {
|
449
|
+
const res = new Uint8Array(a.length + b.length);
|
450
|
+
res.set(a);
|
451
|
+
res.set(b, a.length);
|
452
|
+
return res;
|
453
|
+
}
|
454
|
+
function newMessage() {
|
455
|
+
return {
|
456
|
+
data: "",
|
457
|
+
event: "",
|
458
|
+
id: "",
|
459
|
+
retry: void 0
|
460
|
+
};
|
461
|
+
}
|
462
|
+
const EventStreamContentType = "text/event-stream";
|
463
|
+
const LastEventId = "last-event-id";
|
464
|
+
function fetchEventSource(input, {
|
465
|
+
signal: inputSignal,
|
466
|
+
headers: inputHeaders,
|
467
|
+
onopen: inputOnOpen,
|
468
|
+
onmessage,
|
469
|
+
onclose,
|
470
|
+
onerror,
|
471
|
+
fetch: inputFetch,
|
472
|
+
...rest
|
473
|
+
}) {
|
474
|
+
return new Promise((resolve, reject) => {
|
475
|
+
const headers = { ...inputHeaders };
|
476
|
+
if (!headers.accept) {
|
477
|
+
headers.accept = EventStreamContentType;
|
478
|
+
}
|
479
|
+
let curRequestController;
|
480
|
+
function dispose() {
|
481
|
+
curRequestController.abort();
|
482
|
+
}
|
483
|
+
inputSignal?.addEventListener("abort", () => {
|
484
|
+
dispose();
|
485
|
+
resolve();
|
486
|
+
});
|
487
|
+
const fetchImpl = inputFetch ?? fetch;
|
488
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
489
|
+
async function create() {
|
490
|
+
curRequestController = new AbortController();
|
491
|
+
try {
|
492
|
+
const response = await fetchImpl(input, {
|
493
|
+
...rest,
|
494
|
+
headers,
|
495
|
+
signal: curRequestController.signal
|
496
|
+
});
|
497
|
+
await onopen(response);
|
498
|
+
await getBytes(
|
499
|
+
response.body,
|
500
|
+
getLines(
|
501
|
+
getMessages(
|
502
|
+
(id) => {
|
503
|
+
if (id) {
|
504
|
+
headers[LastEventId] = id;
|
505
|
+
} else {
|
506
|
+
delete headers[LastEventId];
|
507
|
+
}
|
508
|
+
},
|
509
|
+
(_retry) => {
|
510
|
+
},
|
511
|
+
onmessage
|
512
|
+
)
|
513
|
+
)
|
514
|
+
);
|
515
|
+
onclose?.();
|
516
|
+
dispose();
|
517
|
+
resolve();
|
518
|
+
} catch (err) {
|
519
|
+
}
|
520
|
+
}
|
521
|
+
create();
|
522
|
+
});
|
523
|
+
}
|
524
|
+
function defaultOnOpen(response) {
|
525
|
+
const contentType = response.headers?.get("content-type");
|
526
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
527
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
528
|
+
}
|
529
|
+
}
|
530
|
+
|
531
|
+
const VERSION = "0.29.1";
|
532
|
+
|
533
|
+
class ErrorWithCause extends Error {
|
534
|
+
constructor(message, options) {
|
535
|
+
super(message, options);
|
536
|
+
}
|
537
|
+
}
|
538
|
+
class FetcherError extends ErrorWithCause {
|
539
|
+
constructor(status, data, requestId) {
|
79
540
|
super(getMessage(data));
|
80
541
|
this.status = status;
|
81
|
-
this.errors = isBulkError(data) ? data.errors :
|
542
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
543
|
+
this.requestId = requestId;
|
82
544
|
if (data instanceof Error) {
|
83
545
|
this.stack = data.stack;
|
84
546
|
this.cause = data.cause;
|
85
547
|
}
|
86
548
|
}
|
549
|
+
toString() {
|
550
|
+
const error = super.toString();
|
551
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
552
|
+
}
|
87
553
|
}
|
88
554
|
function isBulkError(error) {
|
89
555
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -105,312 +571,555 @@ function getMessage(data) {
|
|
105
571
|
}
|
106
572
|
}
|
107
573
|
|
574
|
+
function getHostUrl(provider, type) {
|
575
|
+
if (isHostProviderAlias(provider)) {
|
576
|
+
return providers[provider][type];
|
577
|
+
} else if (isHostProviderBuilder(provider)) {
|
578
|
+
return provider[type];
|
579
|
+
}
|
580
|
+
throw new Error("Invalid API provider");
|
581
|
+
}
|
582
|
+
const providers = {
|
583
|
+
production: {
|
584
|
+
main: "https://api.xata.io",
|
585
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
586
|
+
},
|
587
|
+
staging: {
|
588
|
+
main: "https://api.staging-xata.dev",
|
589
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
590
|
+
},
|
591
|
+
dev: {
|
592
|
+
main: "https://api.dev-xata.dev",
|
593
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
594
|
+
},
|
595
|
+
local: {
|
596
|
+
main: "http://localhost:6001",
|
597
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
598
|
+
}
|
599
|
+
};
|
600
|
+
function isHostProviderAlias(alias) {
|
601
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
602
|
+
}
|
603
|
+
function isHostProviderBuilder(builder) {
|
604
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
605
|
+
}
|
606
|
+
function parseProviderString(provider = "production") {
|
607
|
+
if (isHostProviderAlias(provider)) {
|
608
|
+
return provider;
|
609
|
+
}
|
610
|
+
const [main, workspaces] = provider.split(",");
|
611
|
+
if (!main || !workspaces)
|
612
|
+
return null;
|
613
|
+
return { main, workspaces };
|
614
|
+
}
|
615
|
+
function buildProviderString(provider) {
|
616
|
+
if (isHostProviderAlias(provider))
|
617
|
+
return provider;
|
618
|
+
return `${provider.main},${provider.workspaces}`;
|
619
|
+
}
|
620
|
+
function parseWorkspacesUrlParts(url) {
|
621
|
+
if (!isString(url))
|
622
|
+
return null;
|
623
|
+
const matches = {
|
624
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
625
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
626
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
627
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
628
|
+
};
|
629
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
630
|
+
if (!isHostProviderAlias(host) || !match)
|
631
|
+
return null;
|
632
|
+
return { workspace: match[1], region: match[2], host };
|
633
|
+
}
|
634
|
+
|
635
|
+
const pool = new ApiRequestPool();
|
108
636
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
109
|
-
const
|
637
|
+
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
638
|
+
if (value === void 0 || value === null)
|
639
|
+
return acc;
|
640
|
+
return { ...acc, [key]: value };
|
641
|
+
}, {});
|
642
|
+
const query = new URLSearchParams(cleanQueryParams).toString();
|
110
643
|
const queryString = query.length > 0 ? `?${query}` : "";
|
111
|
-
|
644
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
645
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
646
|
+
}, {});
|
647
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
112
648
|
};
|
113
649
|
function buildBaseUrl({
|
650
|
+
method,
|
651
|
+
endpoint,
|
114
652
|
path,
|
115
653
|
workspacesApiUrl,
|
116
654
|
apiUrl,
|
117
|
-
pathParams
|
655
|
+
pathParams = {}
|
118
656
|
}) {
|
119
|
-
if (
|
120
|
-
|
121
|
-
|
122
|
-
|
657
|
+
if (endpoint === "dataPlane") {
|
658
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
659
|
+
if (method.toUpperCase() === "PUT" && [
|
660
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
661
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
662
|
+
].includes(path)) {
|
663
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
664
|
+
switch (host) {
|
665
|
+
case "production":
|
666
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
667
|
+
break;
|
668
|
+
case "staging":
|
669
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
670
|
+
break;
|
671
|
+
case "dev":
|
672
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
673
|
+
break;
|
674
|
+
}
|
675
|
+
}
|
676
|
+
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
677
|
+
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
678
|
+
}
|
679
|
+
return `${apiUrl}${path}`;
|
123
680
|
}
|
124
681
|
function hostHeader(url) {
|
125
682
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
126
683
|
const { groups } = pattern.exec(url) ?? {};
|
127
684
|
return groups?.host ? { Host: groups.host } : {};
|
128
685
|
}
|
686
|
+
async function parseBody(body, headers) {
|
687
|
+
if (!isDefined(body))
|
688
|
+
return void 0;
|
689
|
+
if (isBlob(body) || typeof body.text === "function") {
|
690
|
+
return body;
|
691
|
+
}
|
692
|
+
const { "Content-Type": contentType } = headers ?? {};
|
693
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
694
|
+
return JSON.stringify(body);
|
695
|
+
}
|
696
|
+
return body;
|
697
|
+
}
|
698
|
+
const defaultClientID = generateUUID();
|
129
699
|
async function fetch$1({
|
130
700
|
url: path,
|
131
701
|
method,
|
132
702
|
body,
|
133
|
-
headers,
|
703
|
+
headers: customHeaders,
|
704
|
+
pathParams,
|
705
|
+
queryParams,
|
706
|
+
fetch: fetch2,
|
707
|
+
apiKey,
|
708
|
+
endpoint,
|
709
|
+
apiUrl,
|
710
|
+
workspacesApiUrl,
|
711
|
+
trace,
|
712
|
+
signal,
|
713
|
+
clientID,
|
714
|
+
sessionID,
|
715
|
+
clientName,
|
716
|
+
xataAgentExtra,
|
717
|
+
fetchOptions = {},
|
718
|
+
rawResponse = false
|
719
|
+
}) {
|
720
|
+
pool.setFetch(fetch2);
|
721
|
+
return await trace(
|
722
|
+
`${method.toUpperCase()} ${path}`,
|
723
|
+
async ({ setAttributes }) => {
|
724
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
725
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
726
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
727
|
+
setAttributes({
|
728
|
+
[TraceAttributes.HTTP_URL]: url,
|
729
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
730
|
+
});
|
731
|
+
const xataAgent = compact([
|
732
|
+
["client", "TS_SDK"],
|
733
|
+
["version", VERSION],
|
734
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
735
|
+
...Object.entries(xataAgentExtra ?? {})
|
736
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
737
|
+
const headers = compactObject({
|
738
|
+
"Accept-Encoding": "identity",
|
739
|
+
"Content-Type": "application/json",
|
740
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
741
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
742
|
+
"X-Xata-Agent": xataAgent,
|
743
|
+
...customHeaders,
|
744
|
+
...hostHeader(fullUrl),
|
745
|
+
Authorization: `Bearer ${apiKey}`
|
746
|
+
});
|
747
|
+
const response = await pool.request(url, {
|
748
|
+
...fetchOptions,
|
749
|
+
method: method.toUpperCase(),
|
750
|
+
body: await parseBody(body, headers),
|
751
|
+
headers,
|
752
|
+
signal
|
753
|
+
});
|
754
|
+
const { host, protocol } = parseUrl(response.url);
|
755
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
756
|
+
setAttributes({
|
757
|
+
[TraceAttributes.KIND]: "http",
|
758
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
759
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
760
|
+
[TraceAttributes.HTTP_HOST]: host,
|
761
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
762
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
763
|
+
});
|
764
|
+
const message = response.headers?.get("x-xata-message");
|
765
|
+
if (message)
|
766
|
+
console.warn(message);
|
767
|
+
if (response.status === 204) {
|
768
|
+
return {};
|
769
|
+
}
|
770
|
+
if (response.status === 429) {
|
771
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
772
|
+
}
|
773
|
+
try {
|
774
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
775
|
+
if (response.ok) {
|
776
|
+
return jsonResponse;
|
777
|
+
}
|
778
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
779
|
+
} catch (error) {
|
780
|
+
throw new FetcherError(response.status, error, requestId);
|
781
|
+
}
|
782
|
+
},
|
783
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
784
|
+
);
|
785
|
+
}
|
786
|
+
function fetchSSERequest({
|
787
|
+
url: path,
|
788
|
+
method,
|
789
|
+
body,
|
790
|
+
headers: customHeaders,
|
134
791
|
pathParams,
|
135
792
|
queryParams,
|
136
|
-
|
793
|
+
fetch: fetch2,
|
137
794
|
apiKey,
|
795
|
+
endpoint,
|
138
796
|
apiUrl,
|
139
|
-
workspacesApiUrl
|
797
|
+
workspacesApiUrl,
|
798
|
+
onMessage,
|
799
|
+
onError,
|
800
|
+
onClose,
|
801
|
+
signal,
|
802
|
+
clientID,
|
803
|
+
sessionID,
|
804
|
+
clientName,
|
805
|
+
xataAgentExtra
|
140
806
|
}) {
|
141
|
-
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
807
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
142
808
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
143
809
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
144
|
-
|
145
|
-
method
|
146
|
-
body:
|
810
|
+
void fetchEventSource(url, {
|
811
|
+
method,
|
812
|
+
body: JSON.stringify(body),
|
813
|
+
fetch: fetch2,
|
814
|
+
signal,
|
147
815
|
headers: {
|
148
|
-
"
|
149
|
-
|
150
|
-
|
151
|
-
|
816
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
817
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
818
|
+
"X-Xata-Agent": compact([
|
819
|
+
["client", "TS_SDK"],
|
820
|
+
["version", VERSION],
|
821
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
822
|
+
...Object.entries(xataAgentExtra ?? {})
|
823
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
824
|
+
...customHeaders,
|
825
|
+
Authorization: `Bearer ${apiKey}`,
|
826
|
+
"Content-Type": "application/json"
|
827
|
+
},
|
828
|
+
onmessage(ev) {
|
829
|
+
onMessage?.(JSON.parse(ev.data));
|
830
|
+
},
|
831
|
+
onerror(ev) {
|
832
|
+
onError?.(JSON.parse(ev.data));
|
833
|
+
},
|
834
|
+
onclose() {
|
835
|
+
onClose?.();
|
152
836
|
}
|
153
837
|
});
|
154
|
-
|
155
|
-
|
156
|
-
}
|
838
|
+
}
|
839
|
+
function parseUrl(url) {
|
157
840
|
try {
|
158
|
-
const
|
159
|
-
|
160
|
-
return jsonResponse;
|
161
|
-
}
|
162
|
-
throw new FetcherError(response.status, jsonResponse);
|
841
|
+
const { host, protocol } = new URL(url);
|
842
|
+
return { host, protocol };
|
163
843
|
} catch (error) {
|
164
|
-
|
844
|
+
return {};
|
165
845
|
}
|
166
846
|
}
|
167
847
|
|
168
|
-
const
|
169
|
-
|
170
|
-
const
|
171
|
-
const
|
172
|
-
url: "/
|
173
|
-
method: "get",
|
174
|
-
...variables
|
175
|
-
});
|
176
|
-
const createUserAPIKey = (variables) => fetch$1({
|
177
|
-
url: "/user/keys/{keyName}",
|
178
|
-
method: "post",
|
179
|
-
...variables
|
180
|
-
});
|
181
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
182
|
-
url: "/user/keys/{keyName}",
|
183
|
-
method: "delete",
|
184
|
-
...variables
|
185
|
-
});
|
186
|
-
const createWorkspace = (variables) => fetch$1({
|
187
|
-
url: "/workspaces",
|
188
|
-
method: "post",
|
189
|
-
...variables
|
190
|
-
});
|
191
|
-
const getWorkspacesList = (variables) => fetch$1({
|
192
|
-
url: "/workspaces",
|
848
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
849
|
+
|
850
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
851
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
852
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
193
853
|
method: "get",
|
194
|
-
...variables
|
854
|
+
...variables,
|
855
|
+
signal
|
195
856
|
});
|
196
|
-
const
|
197
|
-
url: "/
|
857
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
858
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
198
859
|
method: "get",
|
199
|
-
...variables
|
200
|
-
|
201
|
-
const updateWorkspace = (variables) => fetch$1({
|
202
|
-
url: "/workspaces/{workspaceId}",
|
203
|
-
method: "put",
|
204
|
-
...variables
|
860
|
+
...variables,
|
861
|
+
signal
|
205
862
|
});
|
206
|
-
const
|
207
|
-
|
208
|
-
method: "delete",
|
209
|
-
...variables
|
210
|
-
});
|
211
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
212
|
-
url: "/workspaces/{workspaceId}/members",
|
213
|
-
method: "get",
|
214
|
-
...variables
|
215
|
-
});
|
216
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
217
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
218
|
-
url: "/workspaces/{workspaceId}/members/{userId}",
|
219
|
-
method: "delete",
|
220
|
-
...variables
|
221
|
-
});
|
222
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
223
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
224
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
225
|
-
method: "delete",
|
226
|
-
...variables
|
227
|
-
});
|
228
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
229
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
230
|
-
method: "post",
|
231
|
-
...variables
|
232
|
-
});
|
233
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
234
|
-
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
235
|
-
method: "post",
|
236
|
-
...variables
|
237
|
-
});
|
238
|
-
const getDatabaseList = (variables) => fetch$1({
|
239
|
-
url: "/dbs",
|
240
|
-
method: "get",
|
241
|
-
...variables
|
242
|
-
});
|
243
|
-
const getBranchList = (variables) => fetch$1({
|
863
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
864
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
244
865
|
url: "/dbs/{dbName}",
|
245
866
|
method: "get",
|
246
|
-
...variables
|
867
|
+
...variables,
|
868
|
+
signal
|
247
869
|
});
|
248
|
-
const
|
249
|
-
url: "/dbs/{dbName}",
|
250
|
-
method: "put",
|
251
|
-
...variables
|
252
|
-
});
|
253
|
-
const deleteDatabase = (variables) => fetch$1({
|
254
|
-
url: "/dbs/{dbName}",
|
255
|
-
method: "delete",
|
256
|
-
...variables
|
257
|
-
});
|
258
|
-
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
259
|
-
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
260
|
-
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
261
|
-
const resolveBranch = (variables) => fetch$1({
|
262
|
-
url: "/dbs/{dbName}/resolveBranch",
|
263
|
-
method: "get",
|
264
|
-
...variables
|
265
|
-
});
|
266
|
-
const getBranchDetails = (variables) => fetch$1({
|
870
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
267
871
|
url: "/db/{dbBranchName}",
|
268
872
|
method: "get",
|
269
|
-
...variables
|
873
|
+
...variables,
|
874
|
+
signal
|
270
875
|
});
|
271
|
-
const createBranch = (variables) =>
|
272
|
-
|
273
|
-
method: "put",
|
274
|
-
...variables
|
275
|
-
});
|
276
|
-
const deleteBranch = (variables) => fetch$1({
|
876
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
877
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
277
878
|
url: "/db/{dbBranchName}",
|
278
879
|
method: "delete",
|
279
|
-
...variables
|
880
|
+
...variables,
|
881
|
+
signal
|
882
|
+
});
|
883
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
884
|
+
url: "/db/{dbBranchName}/schema",
|
885
|
+
method: "get",
|
886
|
+
...variables,
|
887
|
+
signal
|
888
|
+
});
|
889
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
890
|
+
url: "/db/{dbBranchName}/copy",
|
891
|
+
method: "post",
|
892
|
+
...variables,
|
893
|
+
signal
|
280
894
|
});
|
281
|
-
const updateBranchMetadata = (variables) =>
|
895
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
282
896
|
url: "/db/{dbBranchName}/metadata",
|
283
897
|
method: "put",
|
284
|
-
...variables
|
898
|
+
...variables,
|
899
|
+
signal
|
285
900
|
});
|
286
|
-
const getBranchMetadata = (variables) =>
|
901
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
287
902
|
url: "/db/{dbBranchName}/metadata",
|
288
903
|
method: "get",
|
289
|
-
...variables
|
904
|
+
...variables,
|
905
|
+
signal
|
290
906
|
});
|
291
|
-
const
|
292
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
293
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
294
|
-
const getBranchStats = (variables) => fetch$1({
|
907
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
295
908
|
url: "/db/{dbBranchName}/stats",
|
296
909
|
method: "get",
|
297
|
-
...variables
|
910
|
+
...variables,
|
911
|
+
signal
|
912
|
+
});
|
913
|
+
const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
914
|
+
const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
915
|
+
const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
916
|
+
const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
|
917
|
+
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
918
|
+
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
919
|
+
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
920
|
+
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
921
|
+
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
922
|
+
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
923
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
924
|
+
method: "get",
|
925
|
+
...variables,
|
926
|
+
signal
|
927
|
+
});
|
928
|
+
const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
929
|
+
const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
930
|
+
const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
931
|
+
const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
932
|
+
const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
|
933
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
934
|
+
method: "post",
|
935
|
+
...variables,
|
936
|
+
signal
|
298
937
|
});
|
299
|
-
const
|
938
|
+
const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
939
|
+
const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
940
|
+
const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
941
|
+
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
942
|
+
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
943
|
+
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
944
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
945
|
+
const createTable = (variables, signal) => dataPlaneFetch({
|
300
946
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
301
947
|
method: "put",
|
302
|
-
...variables
|
948
|
+
...variables,
|
949
|
+
signal
|
303
950
|
});
|
304
|
-
const deleteTable = (variables) =>
|
951
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
305
952
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
306
953
|
method: "delete",
|
307
|
-
...variables
|
954
|
+
...variables,
|
955
|
+
signal
|
308
956
|
});
|
309
|
-
const updateTable = (variables) =>
|
310
|
-
|
311
|
-
method: "patch",
|
312
|
-
...variables
|
313
|
-
});
|
314
|
-
const getTableSchema = (variables) => fetch$1({
|
957
|
+
const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
|
958
|
+
const getTableSchema = (variables, signal) => dataPlaneFetch({
|
315
959
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
316
960
|
method: "get",
|
317
|
-
...variables
|
961
|
+
...variables,
|
962
|
+
signal
|
318
963
|
});
|
319
|
-
const setTableSchema = (variables) =>
|
320
|
-
|
321
|
-
method: "put",
|
322
|
-
...variables
|
323
|
-
});
|
324
|
-
const getTableColumns = (variables) => fetch$1({
|
964
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
965
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
325
966
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
326
967
|
method: "get",
|
327
|
-
...variables
|
328
|
-
|
329
|
-
const addTableColumn = (variables) => fetch$1({
|
330
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
331
|
-
method: "post",
|
332
|
-
...variables
|
968
|
+
...variables,
|
969
|
+
signal
|
333
970
|
});
|
334
|
-
const
|
971
|
+
const addTableColumn = (variables, signal) => dataPlaneFetch(
|
972
|
+
{ url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
|
973
|
+
);
|
974
|
+
const getColumn = (variables, signal) => dataPlaneFetch({
|
335
975
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
336
976
|
method: "get",
|
337
|
-
...variables
|
977
|
+
...variables,
|
978
|
+
signal
|
338
979
|
});
|
339
|
-
const
|
980
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
981
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
340
982
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
341
983
|
method: "delete",
|
342
|
-
...variables
|
984
|
+
...variables,
|
985
|
+
signal
|
343
986
|
});
|
344
|
-
const
|
345
|
-
|
346
|
-
|
347
|
-
|
987
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
988
|
+
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
989
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
990
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
991
|
+
method: "get",
|
992
|
+
...variables,
|
993
|
+
signal
|
348
994
|
});
|
349
|
-
const
|
350
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
351
|
-
method: "
|
352
|
-
...variables
|
995
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
996
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
997
|
+
method: "put",
|
998
|
+
...variables,
|
999
|
+
signal
|
353
1000
|
});
|
354
|
-
const
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
1001
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
1002
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
1003
|
+
method: "delete",
|
1004
|
+
...variables,
|
1005
|
+
signal
|
1006
|
+
});
|
1007
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
1008
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1009
|
+
method: "get",
|
1010
|
+
...variables,
|
1011
|
+
signal
|
1012
|
+
});
|
1013
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
1014
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1015
|
+
method: "put",
|
1016
|
+
...variables,
|
1017
|
+
signal
|
1018
|
+
});
|
1019
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
1020
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
359
1021
|
method: "delete",
|
360
|
-
...variables
|
1022
|
+
...variables,
|
1023
|
+
signal
|
361
1024
|
});
|
362
|
-
const getRecord = (variables) =>
|
1025
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
363
1026
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
364
1027
|
method: "get",
|
365
|
-
...variables
|
1028
|
+
...variables,
|
1029
|
+
signal
|
366
1030
|
});
|
367
|
-
const
|
368
|
-
const
|
1031
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
1032
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
1033
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
1034
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
1035
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
1036
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
369
1037
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
370
1038
|
method: "post",
|
371
|
-
...variables
|
1039
|
+
...variables,
|
1040
|
+
signal
|
372
1041
|
});
|
373
|
-
const searchBranch = (variables) =>
|
1042
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
374
1043
|
url: "/db/{dbBranchName}/search",
|
375
1044
|
method: "post",
|
376
|
-
...variables
|
1045
|
+
...variables,
|
1046
|
+
signal
|
377
1047
|
});
|
378
|
-
const
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
1048
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
1049
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
1050
|
+
method: "post",
|
1051
|
+
...variables,
|
1052
|
+
signal
|
1053
|
+
});
|
1054
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
1055
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
1056
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
1057
|
+
method: "post",
|
1058
|
+
...variables,
|
1059
|
+
signal
|
1060
|
+
});
|
1061
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
1062
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
1063
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
1064
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
1065
|
+
url: "/file/{fileId}",
|
1066
|
+
method: "get",
|
1067
|
+
...variables,
|
1068
|
+
signal
|
1069
|
+
});
|
1070
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1071
|
+
url: "/file/{fileId}",
|
1072
|
+
method: "put",
|
1073
|
+
...variables,
|
1074
|
+
signal
|
1075
|
+
});
|
1076
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
1077
|
+
url: "/db/{dbBranchName}/sql",
|
1078
|
+
method: "post",
|
1079
|
+
...variables,
|
1080
|
+
signal
|
1081
|
+
});
|
1082
|
+
const operationsByTag$2 = {
|
403
1083
|
branch: {
|
1084
|
+
applyMigration,
|
1085
|
+
pgRollStatus,
|
1086
|
+
pgRollJobStatus,
|
1087
|
+
pgRollMigrationHistory,
|
404
1088
|
getBranchList,
|
405
1089
|
getBranchDetails,
|
406
1090
|
createBranch,
|
407
1091
|
deleteBranch,
|
1092
|
+
copyBranch,
|
408
1093
|
updateBranchMetadata,
|
409
1094
|
getBranchMetadata,
|
1095
|
+
getBranchStats,
|
1096
|
+
getGitBranchesMapping,
|
1097
|
+
addGitBranchesEntry,
|
1098
|
+
removeGitBranchesEntry,
|
1099
|
+
resolveBranch
|
1100
|
+
},
|
1101
|
+
migrations: {
|
1102
|
+
getSchema,
|
410
1103
|
getBranchMigrationHistory,
|
411
|
-
executeBranchMigrationPlan,
|
412
1104
|
getBranchMigrationPlan,
|
413
|
-
|
1105
|
+
executeBranchMigrationPlan,
|
1106
|
+
getBranchSchemaHistory,
|
1107
|
+
compareBranchWithUserSchema,
|
1108
|
+
compareBranchSchemas,
|
1109
|
+
updateBranchSchema,
|
1110
|
+
previewBranchSchemaEdit,
|
1111
|
+
applyBranchSchemaEdit,
|
1112
|
+
pushBranchMigrations
|
1113
|
+
},
|
1114
|
+
migrationRequests: {
|
1115
|
+
queryMigrationRequests,
|
1116
|
+
createMigrationRequest,
|
1117
|
+
getMigrationRequest,
|
1118
|
+
updateMigrationRequest,
|
1119
|
+
listMigrationRequestsCommits,
|
1120
|
+
compareMigrationRequest,
|
1121
|
+
getMigrationRequestIsMerged,
|
1122
|
+
mergeMigrationRequest
|
414
1123
|
},
|
415
1124
|
table: {
|
416
1125
|
createTable,
|
@@ -421,581 +1130,694 @@ const operationsByTag = {
|
|
421
1130
|
getTableColumns,
|
422
1131
|
addTableColumn,
|
423
1132
|
getColumn,
|
424
|
-
|
425
|
-
|
1133
|
+
updateColumn,
|
1134
|
+
deleteColumn
|
426
1135
|
},
|
427
1136
|
records: {
|
1137
|
+
branchTransaction,
|
428
1138
|
insertRecord,
|
1139
|
+
getRecord,
|
429
1140
|
insertRecordWithID,
|
430
1141
|
updateRecordWithID,
|
431
1142
|
upsertRecordWithID,
|
432
1143
|
deleteRecord,
|
433
|
-
|
434
|
-
|
1144
|
+
bulkInsertTableRecords
|
1145
|
+
},
|
1146
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1147
|
+
searchAndFilter: {
|
435
1148
|
queryTable,
|
436
|
-
searchBranch
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
} else if (isValidBuilder(provider)) {
|
444
|
-
return provider[type];
|
445
|
-
}
|
446
|
-
throw new Error("Invalid API provider");
|
447
|
-
}
|
448
|
-
const providers = {
|
449
|
-
production: {
|
450
|
-
main: "https://api.xata.io",
|
451
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
1149
|
+
searchBranch,
|
1150
|
+
searchTable,
|
1151
|
+
vectorSearchTable,
|
1152
|
+
askTable,
|
1153
|
+
askTableSession,
|
1154
|
+
summarizeTable,
|
1155
|
+
aggregateTable
|
452
1156
|
},
|
453
|
-
|
454
|
-
main: "https://staging.xatabase.co",
|
455
|
-
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
456
|
-
}
|
1157
|
+
sql: { sqlQuery }
|
457
1158
|
};
|
458
|
-
function isValidAlias(alias) {
|
459
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
460
|
-
}
|
461
|
-
function isValidBuilder(builder) {
|
462
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
463
|
-
}
|
464
1159
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
};
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
}
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
}
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
1160
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
1161
|
+
|
1162
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1163
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
1164
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
1165
|
+
url: "/user",
|
1166
|
+
method: "get",
|
1167
|
+
...variables,
|
1168
|
+
signal
|
1169
|
+
});
|
1170
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
1171
|
+
url: "/user",
|
1172
|
+
method: "put",
|
1173
|
+
...variables,
|
1174
|
+
signal
|
1175
|
+
});
|
1176
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
1177
|
+
url: "/user",
|
1178
|
+
method: "delete",
|
1179
|
+
...variables,
|
1180
|
+
signal
|
1181
|
+
});
|
1182
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
1183
|
+
url: "/user/keys",
|
1184
|
+
method: "get",
|
1185
|
+
...variables,
|
1186
|
+
signal
|
1187
|
+
});
|
1188
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1189
|
+
url: "/user/keys/{keyName}",
|
1190
|
+
method: "post",
|
1191
|
+
...variables,
|
1192
|
+
signal
|
1193
|
+
});
|
1194
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1195
|
+
url: "/user/keys/{keyName}",
|
1196
|
+
method: "delete",
|
1197
|
+
...variables,
|
1198
|
+
signal
|
1199
|
+
});
|
1200
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1201
|
+
url: "/user/oauth/clients",
|
1202
|
+
method: "get",
|
1203
|
+
...variables,
|
1204
|
+
signal
|
1205
|
+
});
|
1206
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1207
|
+
url: "/user/oauth/clients/{clientId}",
|
1208
|
+
method: "delete",
|
1209
|
+
...variables,
|
1210
|
+
signal
|
1211
|
+
});
|
1212
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1213
|
+
url: "/user/oauth/tokens",
|
1214
|
+
method: "get",
|
1215
|
+
...variables,
|
1216
|
+
signal
|
1217
|
+
});
|
1218
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1219
|
+
url: "/user/oauth/tokens/{token}",
|
1220
|
+
method: "delete",
|
1221
|
+
...variables,
|
1222
|
+
signal
|
1223
|
+
});
|
1224
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
1225
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
1226
|
+
url: "/workspaces",
|
1227
|
+
method: "get",
|
1228
|
+
...variables,
|
1229
|
+
signal
|
1230
|
+
});
|
1231
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
1232
|
+
url: "/workspaces",
|
1233
|
+
method: "post",
|
1234
|
+
...variables,
|
1235
|
+
signal
|
1236
|
+
});
|
1237
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
1238
|
+
url: "/workspaces/{workspaceId}",
|
1239
|
+
method: "get",
|
1240
|
+
...variables,
|
1241
|
+
signal
|
1242
|
+
});
|
1243
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
1244
|
+
url: "/workspaces/{workspaceId}",
|
1245
|
+
method: "put",
|
1246
|
+
...variables,
|
1247
|
+
signal
|
1248
|
+
});
|
1249
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
1250
|
+
url: "/workspaces/{workspaceId}",
|
1251
|
+
method: "delete",
|
1252
|
+
...variables,
|
1253
|
+
signal
|
1254
|
+
});
|
1255
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
1256
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
1257
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
1258
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
1259
|
+
method: "delete",
|
1260
|
+
...variables,
|
1261
|
+
signal
|
1262
|
+
});
|
1263
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
1264
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
1265
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1266
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1267
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1268
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1269
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1270
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1271
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1272
|
+
method: "get",
|
1273
|
+
...variables,
|
1274
|
+
signal
|
1275
|
+
});
|
1276
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
1277
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1278
|
+
url: "/workspaces/{workspaceId}/dbs",
|
1279
|
+
method: "get",
|
1280
|
+
...variables,
|
1281
|
+
signal
|
1282
|
+
});
|
1283
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
1284
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
1285
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
1286
|
+
method: "delete",
|
1287
|
+
...variables,
|
1288
|
+
signal
|
1289
|
+
});
|
1290
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
1291
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1292
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1293
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1294
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1295
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
1296
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
1297
|
+
url: "/workspaces/{workspaceId}/regions",
|
1298
|
+
method: "get",
|
1299
|
+
...variables,
|
1300
|
+
signal
|
1301
|
+
});
|
1302
|
+
const operationsByTag$1 = {
|
1303
|
+
oAuth: {
|
1304
|
+
getAuthorizationCode,
|
1305
|
+
grantAuthorizationCode,
|
1306
|
+
getUserOAuthClients,
|
1307
|
+
deleteUserOAuthClient,
|
1308
|
+
getUserOAuthAccessTokens,
|
1309
|
+
deleteOAuthAccessToken,
|
1310
|
+
updateOAuthAccessToken
|
1311
|
+
},
|
1312
|
+
users: { getUser, updateUser, deleteUser },
|
1313
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1314
|
+
workspaces: {
|
1315
|
+
getWorkspacesList,
|
1316
|
+
createWorkspace,
|
1317
|
+
getWorkspace,
|
1318
|
+
updateWorkspace,
|
1319
|
+
deleteWorkspace,
|
1320
|
+
getWorkspaceMembersList,
|
1321
|
+
updateWorkspaceMemberRole,
|
1322
|
+
removeWorkspaceMember
|
1323
|
+
},
|
1324
|
+
invites: {
|
1325
|
+
inviteWorkspaceMember,
|
1326
|
+
updateWorkspaceMemberInvite,
|
1327
|
+
cancelWorkspaceMemberInvite,
|
1328
|
+
acceptWorkspaceMemberInvite,
|
1329
|
+
resendWorkspaceMemberInvite
|
1330
|
+
},
|
1331
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
1332
|
+
databases: {
|
1333
|
+
getDatabaseList,
|
1334
|
+
createDatabase,
|
1335
|
+
deleteDatabase,
|
1336
|
+
getDatabaseMetadata,
|
1337
|
+
updateDatabaseMetadata,
|
1338
|
+
renameDatabase,
|
1339
|
+
getDatabaseGithubSettings,
|
1340
|
+
updateDatabaseGithubSettings,
|
1341
|
+
deleteDatabaseGithubSettings,
|
1342
|
+
listRegions
|
631
1343
|
}
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
1344
|
+
};
|
1345
|
+
|
1346
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1347
|
+
|
1348
|
+
const buildApiClient = () => class {
|
1349
|
+
constructor(options = {}) {
|
1350
|
+
const provider = options.host ?? "production";
|
1351
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
1352
|
+
const trace = options.trace ?? defaultTrace;
|
1353
|
+
const clientID = generateUUID();
|
1354
|
+
if (!apiKey) {
|
1355
|
+
throw new Error("Could not resolve a valid apiKey");
|
1356
|
+
}
|
1357
|
+
const extraProps = {
|
1358
|
+
apiUrl: getHostUrl(provider, "main"),
|
1359
|
+
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
1360
|
+
fetch: getFetchImplementation(options.fetch),
|
1361
|
+
apiKey,
|
1362
|
+
trace,
|
1363
|
+
clientName: options.clientName,
|
1364
|
+
xataAgentExtra: options.xataAgentExtra,
|
1365
|
+
clientID
|
1366
|
+
};
|
1367
|
+
return new Proxy(this, {
|
1368
|
+
get: (_target, namespace) => {
|
1369
|
+
if (operationsByTag[namespace] === void 0) {
|
1370
|
+
return void 0;
|
1371
|
+
}
|
1372
|
+
return new Proxy(
|
1373
|
+
{},
|
1374
|
+
{
|
1375
|
+
get: (_target2, operation) => {
|
1376
|
+
if (operationsByTag[namespace][operation] === void 0) {
|
1377
|
+
return void 0;
|
1378
|
+
}
|
1379
|
+
const method = operationsByTag[namespace][operation];
|
1380
|
+
return async (params) => {
|
1381
|
+
return await method({ ...params, ...extraProps });
|
1382
|
+
};
|
1383
|
+
}
|
1384
|
+
}
|
1385
|
+
);
|
1386
|
+
}
|
636
1387
|
});
|
637
1388
|
}
|
1389
|
+
};
|
1390
|
+
class XataApiClient extends buildApiClient() {
|
638
1391
|
}
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
getDatabaseList(workspace) {
|
644
|
-
return operationsByTag.database.getDatabaseList({
|
645
|
-
pathParams: { workspace },
|
646
|
-
...this.extraProps
|
647
|
-
});
|
648
|
-
}
|
649
|
-
createDatabase(workspace, dbName, options = {}) {
|
650
|
-
return operationsByTag.database.createDatabase({
|
651
|
-
pathParams: { workspace, dbName },
|
652
|
-
body: options,
|
653
|
-
...this.extraProps
|
654
|
-
});
|
655
|
-
}
|
656
|
-
deleteDatabase(workspace, dbName) {
|
657
|
-
return operationsByTag.database.deleteDatabase({
|
658
|
-
pathParams: { workspace, dbName },
|
659
|
-
...this.extraProps
|
660
|
-
});
|
661
|
-
}
|
662
|
-
getGitBranchesMapping(workspace, dbName) {
|
663
|
-
return operationsByTag.database.getGitBranchesMapping({
|
664
|
-
pathParams: { workspace, dbName },
|
665
|
-
...this.extraProps
|
666
|
-
});
|
667
|
-
}
|
668
|
-
addGitBranchesEntry(workspace, dbName, body) {
|
669
|
-
return operationsByTag.database.addGitBranchesEntry({
|
670
|
-
pathParams: { workspace, dbName },
|
671
|
-
body,
|
672
|
-
...this.extraProps
|
673
|
-
});
|
674
|
-
}
|
675
|
-
removeGitBranchesEntry(workspace, dbName, gitBranch) {
|
676
|
-
return operationsByTag.database.removeGitBranchesEntry({
|
677
|
-
pathParams: { workspace, dbName },
|
678
|
-
queryParams: { gitBranch },
|
679
|
-
...this.extraProps
|
680
|
-
});
|
681
|
-
}
|
682
|
-
resolveBranch(workspace, dbName, gitBranch) {
|
683
|
-
return operationsByTag.database.resolveBranch({
|
684
|
-
pathParams: { workspace, dbName },
|
685
|
-
queryParams: { gitBranch },
|
686
|
-
...this.extraProps
|
687
|
-
});
|
1392
|
+
|
1393
|
+
class XataApiPlugin {
|
1394
|
+
build(options) {
|
1395
|
+
return new XataApiClient(options);
|
688
1396
|
}
|
689
1397
|
}
|
690
|
-
|
691
|
-
|
692
|
-
this.extraProps = extraProps;
|
693
|
-
}
|
694
|
-
getBranchList(workspace, dbName) {
|
695
|
-
return operationsByTag.branch.getBranchList({
|
696
|
-
pathParams: { workspace, dbName },
|
697
|
-
...this.extraProps
|
698
|
-
});
|
699
|
-
}
|
700
|
-
getBranchDetails(workspace, database, branch) {
|
701
|
-
return operationsByTag.branch.getBranchDetails({
|
702
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
703
|
-
...this.extraProps
|
704
|
-
});
|
705
|
-
}
|
706
|
-
createBranch(workspace, database, branch, from = "", options = {}) {
|
707
|
-
return operationsByTag.branch.createBranch({
|
708
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
709
|
-
queryParams: { from },
|
710
|
-
body: options,
|
711
|
-
...this.extraProps
|
712
|
-
});
|
713
|
-
}
|
714
|
-
deleteBranch(workspace, database, branch) {
|
715
|
-
return operationsByTag.branch.deleteBranch({
|
716
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
717
|
-
...this.extraProps
|
718
|
-
});
|
719
|
-
}
|
720
|
-
updateBranchMetadata(workspace, database, branch, metadata = {}) {
|
721
|
-
return operationsByTag.branch.updateBranchMetadata({
|
722
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
723
|
-
body: metadata,
|
724
|
-
...this.extraProps
|
725
|
-
});
|
726
|
-
}
|
727
|
-
getBranchMetadata(workspace, database, branch) {
|
728
|
-
return operationsByTag.branch.getBranchMetadata({
|
729
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
730
|
-
...this.extraProps
|
731
|
-
});
|
732
|
-
}
|
733
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
734
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
735
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
736
|
-
body: options,
|
737
|
-
...this.extraProps
|
738
|
-
});
|
739
|
-
}
|
740
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
741
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
742
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
743
|
-
body: migrationPlan,
|
744
|
-
...this.extraProps
|
745
|
-
});
|
746
|
-
}
|
747
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
748
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
749
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
750
|
-
body: schema,
|
751
|
-
...this.extraProps
|
752
|
-
});
|
753
|
-
}
|
754
|
-
getBranchStats(workspace, database, branch) {
|
755
|
-
return operationsByTag.branch.getBranchStats({
|
756
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
757
|
-
...this.extraProps
|
758
|
-
});
|
759
|
-
}
|
1398
|
+
|
1399
|
+
class XataPlugin {
|
760
1400
|
}
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
});
|
809
|
-
}
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
}
|
816
|
-
deleteColumn(workspace, database, branch, tableName, columnName) {
|
817
|
-
return operationsByTag.table.deleteColumn({
|
818
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
|
819
|
-
...this.extraProps
|
820
|
-
});
|
1401
|
+
|
1402
|
+
function buildTransformString(transformations) {
|
1403
|
+
return transformations.flatMap(
|
1404
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
1405
|
+
if (key === "trim") {
|
1406
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
1407
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
1408
|
+
}
|
1409
|
+
if (key === "gravity" && typeof value === "object") {
|
1410
|
+
const { x = 0.5, y = 0.5 } = value;
|
1411
|
+
return `${key}=${[x, y].join("x")}`;
|
1412
|
+
}
|
1413
|
+
return `${key}=${value}`;
|
1414
|
+
})
|
1415
|
+
).join(",");
|
1416
|
+
}
|
1417
|
+
function transformImage(url, ...transformations) {
|
1418
|
+
if (!isDefined(url))
|
1419
|
+
return void 0;
|
1420
|
+
const newTransformations = buildTransformString(transformations);
|
1421
|
+
const { hostname, pathname, search } = new URL(url);
|
1422
|
+
const pathParts = pathname.split("/");
|
1423
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
1424
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
1425
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
1426
|
+
const path = pathParts.join("/");
|
1427
|
+
return `https://${hostname}${transform}${path}${search}`;
|
1428
|
+
}
|
1429
|
+
|
1430
|
+
class XataFile {
|
1431
|
+
constructor(file) {
|
1432
|
+
this.id = file.id;
|
1433
|
+
this.name = file.name;
|
1434
|
+
this.mediaType = file.mediaType;
|
1435
|
+
this.base64Content = file.base64Content;
|
1436
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
1437
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
1438
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
1439
|
+
this.size = file.size;
|
1440
|
+
this.version = file.version;
|
1441
|
+
this.url = file.url;
|
1442
|
+
this.signedUrl = file.signedUrl;
|
1443
|
+
this.uploadUrl = file.uploadUrl;
|
1444
|
+
this.attributes = file.attributes;
|
1445
|
+
}
|
1446
|
+
static fromBuffer(buffer, options = {}) {
|
1447
|
+
const base64Content = buffer.toString("base64");
|
1448
|
+
return new XataFile({ ...options, base64Content });
|
1449
|
+
}
|
1450
|
+
toBuffer() {
|
1451
|
+
if (!this.base64Content) {
|
1452
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1453
|
+
}
|
1454
|
+
return Buffer.from(this.base64Content, "base64");
|
821
1455
|
}
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
body: options,
|
826
|
-
...this.extraProps
|
827
|
-
});
|
1456
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
1457
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
1458
|
+
return this.fromUint8Array(uint8Array, options);
|
828
1459
|
}
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
1460
|
+
toArrayBuffer() {
|
1461
|
+
if (!this.base64Content) {
|
1462
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1463
|
+
}
|
1464
|
+
const binary = atob(this.base64Content);
|
1465
|
+
return new ArrayBuffer(binary.length);
|
833
1466
|
}
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
1467
|
+
static fromUint8Array(uint8Array, options = {}) {
|
1468
|
+
let binary = "";
|
1469
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
1470
|
+
binary += String.fromCharCode(uint8Array[i]);
|
1471
|
+
}
|
1472
|
+
const base64Content = btoa(binary);
|
1473
|
+
return new XataFile({ ...options, base64Content });
|
840
1474
|
}
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
1475
|
+
toUint8Array() {
|
1476
|
+
if (!this.base64Content) {
|
1477
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1478
|
+
}
|
1479
|
+
const binary = atob(this.base64Content);
|
1480
|
+
const uint8Array = new Uint8Array(binary.length);
|
1481
|
+
for (let i = 0; i < binary.length; i++) {
|
1482
|
+
uint8Array[i] = binary.charCodeAt(i);
|
1483
|
+
}
|
1484
|
+
return uint8Array;
|
848
1485
|
}
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
...this.extraProps
|
855
|
-
});
|
1486
|
+
static async fromBlob(file, options = {}) {
|
1487
|
+
const name = options.name ?? file.name;
|
1488
|
+
const mediaType = file.type;
|
1489
|
+
const arrayBuffer = await file.arrayBuffer();
|
1490
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
856
1491
|
}
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
1492
|
+
toBlob() {
|
1493
|
+
if (!this.base64Content) {
|
1494
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1495
|
+
}
|
1496
|
+
const binary = atob(this.base64Content);
|
1497
|
+
const uint8Array = new Uint8Array(binary.length);
|
1498
|
+
for (let i = 0; i < binary.length; i++) {
|
1499
|
+
uint8Array[i] = binary.charCodeAt(i);
|
1500
|
+
}
|
1501
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
864
1502
|
}
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
...this.extraProps
|
869
|
-
});
|
1503
|
+
static fromString(string, options = {}) {
|
1504
|
+
const base64Content = btoa(string);
|
1505
|
+
return new XataFile({ ...options, base64Content });
|
870
1506
|
}
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
1507
|
+
toString() {
|
1508
|
+
if (!this.base64Content) {
|
1509
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1510
|
+
}
|
1511
|
+
return atob(this.base64Content);
|
876
1512
|
}
|
877
|
-
|
878
|
-
return
|
879
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
880
|
-
body: { records },
|
881
|
-
...this.extraProps
|
882
|
-
});
|
1513
|
+
static fromBase64(base64Content, options = {}) {
|
1514
|
+
return new XataFile({ ...options, base64Content });
|
883
1515
|
}
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
});
|
1516
|
+
toBase64() {
|
1517
|
+
if (!this.base64Content) {
|
1518
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1519
|
+
}
|
1520
|
+
return this.base64Content;
|
890
1521
|
}
|
891
|
-
|
892
|
-
return
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
1522
|
+
transform(...options) {
|
1523
|
+
return {
|
1524
|
+
url: transformImage(this.url, ...options),
|
1525
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
1526
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
1527
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
1528
|
+
};
|
897
1529
|
}
|
898
1530
|
}
|
1531
|
+
const parseInputFileEntry = async (entry) => {
|
1532
|
+
if (!isDefined(entry))
|
1533
|
+
return null;
|
1534
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
1535
|
+
return compactObject({
|
1536
|
+
id,
|
1537
|
+
// Name cannot be an empty string in our API
|
1538
|
+
name: name ? name : void 0,
|
1539
|
+
mediaType,
|
1540
|
+
base64Content,
|
1541
|
+
enablePublicUrl,
|
1542
|
+
signedUrlTimeout,
|
1543
|
+
uploadUrlTimeout
|
1544
|
+
});
|
1545
|
+
};
|
899
1546
|
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
1547
|
+
function cleanFilter(filter) {
|
1548
|
+
if (!isDefined(filter))
|
1549
|
+
return void 0;
|
1550
|
+
if (!isObject(filter))
|
1551
|
+
return filter;
|
1552
|
+
const values = Object.fromEntries(
|
1553
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
1554
|
+
if (!isDefined(value))
|
1555
|
+
return acc;
|
1556
|
+
if (Array.isArray(value)) {
|
1557
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
1558
|
+
if (clean.length === 0)
|
1559
|
+
return acc;
|
1560
|
+
return [...acc, [key, clean]];
|
1561
|
+
}
|
1562
|
+
if (isObject(value)) {
|
1563
|
+
const clean = cleanFilter(value);
|
1564
|
+
if (!isDefined(clean))
|
1565
|
+
return acc;
|
1566
|
+
return [...acc, [key, clean]];
|
1567
|
+
}
|
1568
|
+
return [...acc, [key, value]];
|
1569
|
+
}, [])
|
1570
|
+
);
|
1571
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
905
1572
|
}
|
906
1573
|
|
907
|
-
|
1574
|
+
function stringifyJson(value) {
|
1575
|
+
if (!isDefined(value))
|
1576
|
+
return value;
|
1577
|
+
if (isString(value))
|
1578
|
+
return value;
|
1579
|
+
try {
|
1580
|
+
return JSON.stringify(value);
|
1581
|
+
} catch (e) {
|
1582
|
+
return value;
|
1583
|
+
}
|
1584
|
+
}
|
1585
|
+
function parseJson(value) {
|
1586
|
+
try {
|
1587
|
+
return JSON.parse(value);
|
1588
|
+
} catch (e) {
|
1589
|
+
return value;
|
1590
|
+
}
|
908
1591
|
}
|
909
1592
|
|
910
|
-
var __accessCheck$
|
1593
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
911
1594
|
if (!member.has(obj))
|
912
1595
|
throw TypeError("Cannot " + msg);
|
913
1596
|
};
|
914
|
-
var __privateGet$
|
915
|
-
__accessCheck$
|
1597
|
+
var __privateGet$4 = (obj, member, getter) => {
|
1598
|
+
__accessCheck$5(obj, member, "read from private field");
|
916
1599
|
return getter ? getter.call(obj) : member.get(obj);
|
917
1600
|
};
|
918
|
-
var __privateAdd$
|
1601
|
+
var __privateAdd$5 = (obj, member, value) => {
|
919
1602
|
if (member.has(obj))
|
920
1603
|
throw TypeError("Cannot add the same private member more than once");
|
921
1604
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
922
1605
|
};
|
923
|
-
var __privateSet$
|
924
|
-
__accessCheck$
|
1606
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1607
|
+
__accessCheck$5(obj, member, "write to private field");
|
925
1608
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
926
1609
|
return value;
|
927
1610
|
};
|
928
|
-
var _query;
|
1611
|
+
var _query, _page;
|
929
1612
|
class Page {
|
930
1613
|
constructor(query, meta, records = []) {
|
931
|
-
__privateAdd$
|
932
|
-
__privateSet$
|
1614
|
+
__privateAdd$5(this, _query, void 0);
|
1615
|
+
__privateSet$3(this, _query, query);
|
933
1616
|
this.meta = meta;
|
934
|
-
this.records = records;
|
935
|
-
}
|
1617
|
+
this.records = new PageRecordArray(this, records);
|
1618
|
+
}
|
1619
|
+
/**
|
1620
|
+
* Retrieves the next page of results.
|
1621
|
+
* @param size Maximum number of results to be retrieved.
|
1622
|
+
* @param offset Number of results to skip when retrieving the results.
|
1623
|
+
* @returns The next page or results.
|
1624
|
+
*/
|
936
1625
|
async nextPage(size, offset) {
|
937
|
-
return __privateGet$
|
938
|
-
}
|
1626
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1627
|
+
}
|
1628
|
+
/**
|
1629
|
+
* Retrieves the previous page of results.
|
1630
|
+
* @param size Maximum number of results to be retrieved.
|
1631
|
+
* @param offset Number of results to skip when retrieving the results.
|
1632
|
+
* @returns The previous page or results.
|
1633
|
+
*/
|
939
1634
|
async previousPage(size, offset) {
|
940
|
-
return __privateGet$
|
941
|
-
}
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
1635
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1636
|
+
}
|
1637
|
+
/**
|
1638
|
+
* Retrieves the start page of results.
|
1639
|
+
* @param size Maximum number of results to be retrieved.
|
1640
|
+
* @param offset Number of results to skip when retrieving the results.
|
1641
|
+
* @returns The start page or results.
|
1642
|
+
*/
|
1643
|
+
async startPage(size, offset) {
|
1644
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1645
|
+
}
|
1646
|
+
/**
|
1647
|
+
* Retrieves the end page of results.
|
1648
|
+
* @param size Maximum number of results to be retrieved.
|
1649
|
+
* @param offset Number of results to skip when retrieving the results.
|
1650
|
+
* @returns The end page or results.
|
1651
|
+
*/
|
1652
|
+
async endPage(size, offset) {
|
1653
|
+
return __privateGet$4(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1654
|
+
}
|
1655
|
+
/**
|
1656
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
1657
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
1658
|
+
*/
|
948
1659
|
hasNextPage() {
|
949
1660
|
return this.meta.page.more;
|
950
1661
|
}
|
951
1662
|
}
|
952
1663
|
_query = new WeakMap();
|
953
|
-
const PAGINATION_MAX_SIZE =
|
954
|
-
const PAGINATION_DEFAULT_SIZE =
|
955
|
-
const PAGINATION_MAX_OFFSET =
|
1664
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1665
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
1666
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
956
1667
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1668
|
+
function isCursorPaginationOptions(options) {
|
1669
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1670
|
+
}
|
1671
|
+
class RecordArray extends Array {
|
1672
|
+
constructor(...args) {
|
1673
|
+
super(...RecordArray.parseConstructorParams(...args));
|
1674
|
+
}
|
1675
|
+
static parseConstructorParams(...args) {
|
1676
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1677
|
+
return new Array(args[0]);
|
1678
|
+
}
|
1679
|
+
if (args.length <= 1 && Array.isArray(args[0] ?? [])) {
|
1680
|
+
const result = args[0] ?? [];
|
1681
|
+
return new Array(...result);
|
1682
|
+
}
|
1683
|
+
return new Array(...args);
|
1684
|
+
}
|
1685
|
+
toArray() {
|
1686
|
+
return new Array(...this);
|
1687
|
+
}
|
1688
|
+
toSerializable() {
|
1689
|
+
return JSON.parse(this.toString());
|
1690
|
+
}
|
1691
|
+
toString() {
|
1692
|
+
return JSON.stringify(this.toArray());
|
1693
|
+
}
|
1694
|
+
map(callbackfn, thisArg) {
|
1695
|
+
return this.toArray().map(callbackfn, thisArg);
|
1696
|
+
}
|
1697
|
+
}
|
1698
|
+
const _PageRecordArray = class _PageRecordArray extends Array {
|
1699
|
+
constructor(...args) {
|
1700
|
+
super(..._PageRecordArray.parseConstructorParams(...args));
|
1701
|
+
__privateAdd$5(this, _page, void 0);
|
1702
|
+
__privateSet$3(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1703
|
+
}
|
1704
|
+
static parseConstructorParams(...args) {
|
1705
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1706
|
+
return new Array(args[0]);
|
1707
|
+
}
|
1708
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
1709
|
+
const result = args[1] ?? args[0].records ?? [];
|
1710
|
+
return new Array(...result);
|
1711
|
+
}
|
1712
|
+
return new Array(...args);
|
1713
|
+
}
|
1714
|
+
toArray() {
|
1715
|
+
return new Array(...this);
|
1716
|
+
}
|
1717
|
+
toSerializable() {
|
1718
|
+
return JSON.parse(this.toString());
|
1719
|
+
}
|
1720
|
+
toString() {
|
1721
|
+
return JSON.stringify(this.toArray());
|
1722
|
+
}
|
1723
|
+
map(callbackfn, thisArg) {
|
1724
|
+
return this.toArray().map(callbackfn, thisArg);
|
1725
|
+
}
|
1726
|
+
/**
|
1727
|
+
* Retrieve next page of records
|
1728
|
+
*
|
1729
|
+
* @returns A new array of objects
|
1730
|
+
*/
|
1731
|
+
async nextPage(size, offset) {
|
1732
|
+
const newPage = await __privateGet$4(this, _page).nextPage(size, offset);
|
1733
|
+
return new _PageRecordArray(newPage);
|
1734
|
+
}
|
1735
|
+
/**
|
1736
|
+
* Retrieve previous page of records
|
1737
|
+
*
|
1738
|
+
* @returns A new array of objects
|
1739
|
+
*/
|
1740
|
+
async previousPage(size, offset) {
|
1741
|
+
const newPage = await __privateGet$4(this, _page).previousPage(size, offset);
|
1742
|
+
return new _PageRecordArray(newPage);
|
1743
|
+
}
|
1744
|
+
/**
|
1745
|
+
* Retrieve start page of records
|
1746
|
+
*
|
1747
|
+
* @returns A new array of objects
|
1748
|
+
*/
|
1749
|
+
async startPage(size, offset) {
|
1750
|
+
const newPage = await __privateGet$4(this, _page).startPage(size, offset);
|
1751
|
+
return new _PageRecordArray(newPage);
|
1752
|
+
}
|
1753
|
+
/**
|
1754
|
+
* Retrieve end page of records
|
1755
|
+
*
|
1756
|
+
* @returns A new array of objects
|
1757
|
+
*/
|
1758
|
+
async endPage(size, offset) {
|
1759
|
+
const newPage = await __privateGet$4(this, _page).endPage(size, offset);
|
1760
|
+
return new _PageRecordArray(newPage);
|
1761
|
+
}
|
1762
|
+
/**
|
1763
|
+
* @returns Boolean indicating if there is a next page
|
1764
|
+
*/
|
1765
|
+
hasNextPage() {
|
1766
|
+
return __privateGet$4(this, _page).meta.page.more;
|
1767
|
+
}
|
1768
|
+
};
|
1769
|
+
_page = new WeakMap();
|
1770
|
+
let PageRecordArray = _PageRecordArray;
|
957
1771
|
|
958
|
-
var __accessCheck$
|
1772
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
959
1773
|
if (!member.has(obj))
|
960
1774
|
throw TypeError("Cannot " + msg);
|
961
1775
|
};
|
962
|
-
var __privateGet$
|
963
|
-
__accessCheck$
|
1776
|
+
var __privateGet$3 = (obj, member, getter) => {
|
1777
|
+
__accessCheck$4(obj, member, "read from private field");
|
964
1778
|
return getter ? getter.call(obj) : member.get(obj);
|
965
1779
|
};
|
966
|
-
var __privateAdd$
|
1780
|
+
var __privateAdd$4 = (obj, member, value) => {
|
967
1781
|
if (member.has(obj))
|
968
1782
|
throw TypeError("Cannot add the same private member more than once");
|
969
1783
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
970
1784
|
};
|
971
|
-
var __privateSet$
|
972
|
-
__accessCheck$
|
1785
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1786
|
+
__accessCheck$4(obj, member, "write to private field");
|
973
1787
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
974
1788
|
return value;
|
975
1789
|
};
|
976
|
-
var
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
this
|
984
|
-
|
1790
|
+
var __privateMethod$3 = (obj, member, method) => {
|
1791
|
+
__accessCheck$4(obj, member, "access private method");
|
1792
|
+
return method;
|
1793
|
+
};
|
1794
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1795
|
+
const _Query = class _Query {
|
1796
|
+
constructor(repository, table, data, rawParent) {
|
1797
|
+
__privateAdd$4(this, _cleanFilterConstraint);
|
1798
|
+
__privateAdd$4(this, _table$1, void 0);
|
1799
|
+
__privateAdd$4(this, _repository, void 0);
|
1800
|
+
__privateAdd$4(this, _data, { filter: {} });
|
1801
|
+
// Implements pagination
|
1802
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1803
|
+
this.records = new PageRecordArray(this, []);
|
1804
|
+
__privateSet$2(this, _table$1, table);
|
985
1805
|
if (repository) {
|
986
|
-
__privateSet$
|
1806
|
+
__privateSet$2(this, _repository, repository);
|
987
1807
|
} else {
|
988
|
-
__privateSet$
|
1808
|
+
__privateSet$2(this, _repository, this);
|
989
1809
|
}
|
990
|
-
|
991
|
-
__privateGet$
|
992
|
-
__privateGet$
|
993
|
-
__privateGet$
|
994
|
-
__privateGet$
|
995
|
-
__privateGet$
|
996
|
-
__privateGet$
|
997
|
-
__privateGet$
|
998
|
-
__privateGet$
|
1810
|
+
const parent = cleanParent(data, rawParent);
|
1811
|
+
__privateGet$3(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
1812
|
+
__privateGet$3(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
1813
|
+
__privateGet$3(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
1814
|
+
__privateGet$3(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1815
|
+
__privateGet$3(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1816
|
+
__privateGet$3(this, _data).sort = data.sort ?? parent?.sort;
|
1817
|
+
__privateGet$3(this, _data).columns = data.columns ?? parent?.columns;
|
1818
|
+
__privateGet$3(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1819
|
+
__privateGet$3(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1820
|
+
__privateGet$3(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
999
1821
|
this.any = this.any.bind(this);
|
1000
1822
|
this.all = this.all.bind(this);
|
1001
1823
|
this.not = this.not.bind(this);
|
@@ -1006,117 +1828,262 @@ const _Query = class {
|
|
1006
1828
|
Object.defineProperty(this, "repository", { enumerable: false });
|
1007
1829
|
}
|
1008
1830
|
getQueryOptions() {
|
1009
|
-
return __privateGet$
|
1831
|
+
return __privateGet$3(this, _data);
|
1010
1832
|
}
|
1011
1833
|
key() {
|
1012
|
-
const { columns = [], filter = {}, sort = [],
|
1013
|
-
const key = JSON.stringify({ columns, filter, sort,
|
1834
|
+
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$3(this, _data);
|
1835
|
+
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1014
1836
|
return toBase64(key);
|
1015
1837
|
}
|
1838
|
+
/**
|
1839
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
1840
|
+
* @param queries An array of subqueries.
|
1841
|
+
* @returns A new Query object.
|
1842
|
+
*/
|
1016
1843
|
any(...queries) {
|
1017
1844
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1018
|
-
return new _Query(__privateGet$
|
1845
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $any } }, __privateGet$3(this, _data));
|
1019
1846
|
}
|
1847
|
+
/**
|
1848
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
1849
|
+
* @param queries An array of subqueries.
|
1850
|
+
* @returns A new Query object.
|
1851
|
+
*/
|
1020
1852
|
all(...queries) {
|
1021
1853
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1022
|
-
return new _Query(__privateGet$
|
1854
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
1023
1855
|
}
|
1856
|
+
/**
|
1857
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
1858
|
+
* @param queries An array of subqueries.
|
1859
|
+
* @returns A new Query object.
|
1860
|
+
*/
|
1024
1861
|
not(...queries) {
|
1025
1862
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1026
|
-
return new _Query(__privateGet$
|
1863
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $not } }, __privateGet$3(this, _data));
|
1027
1864
|
}
|
1865
|
+
/**
|
1866
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
1867
|
+
* @param queries An array of subqueries.
|
1868
|
+
* @returns A new Query object.
|
1869
|
+
*/
|
1028
1870
|
none(...queries) {
|
1029
1871
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1030
|
-
return new _Query(__privateGet$
|
1872
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $none } }, __privateGet$3(this, _data));
|
1031
1873
|
}
|
1032
1874
|
filter(a, b) {
|
1033
1875
|
if (arguments.length === 1) {
|
1034
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
1035
|
-
|
1036
|
-
|
1876
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1877
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1878
|
+
}));
|
1879
|
+
const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
|
1880
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
1037
1881
|
} else {
|
1038
|
-
const
|
1039
|
-
|
1882
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1883
|
+
const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
|
1884
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
|
1040
1885
|
}
|
1041
1886
|
}
|
1042
|
-
sort(column, direction) {
|
1043
|
-
const originalSort = [__privateGet$
|
1887
|
+
sort(column, direction = "asc") {
|
1888
|
+
const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
|
1044
1889
|
const sort = [...originalSort, { column, direction }];
|
1045
|
-
return new _Query(__privateGet$
|
1890
|
+
return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
|
1046
1891
|
}
|
1892
|
+
/**
|
1893
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
1894
|
+
* @param columns Array of column names to be returned by the query.
|
1895
|
+
* @returns A new Query object.
|
1896
|
+
*/
|
1047
1897
|
select(columns) {
|
1048
|
-
return new _Query(
|
1898
|
+
return new _Query(
|
1899
|
+
__privateGet$3(this, _repository),
|
1900
|
+
__privateGet$3(this, _table$1),
|
1901
|
+
{ columns },
|
1902
|
+
__privateGet$3(this, _data)
|
1903
|
+
);
|
1049
1904
|
}
|
1050
1905
|
getPaginated(options = {}) {
|
1051
|
-
const query = new _Query(__privateGet$
|
1052
|
-
return __privateGet$
|
1053
|
-
}
|
1906
|
+
const query = new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), options, __privateGet$3(this, _data));
|
1907
|
+
return __privateGet$3(this, _repository).query(query);
|
1908
|
+
}
|
1909
|
+
/**
|
1910
|
+
* Get results in an iterator
|
1911
|
+
*
|
1912
|
+
* @async
|
1913
|
+
* @returns Async interable of results
|
1914
|
+
*/
|
1054
1915
|
async *[Symbol.asyncIterator]() {
|
1055
|
-
for await (const [record] of this.getIterator(1)) {
|
1916
|
+
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1056
1917
|
yield record;
|
1057
1918
|
}
|
1058
1919
|
}
|
1059
|
-
async *getIterator(
|
1060
|
-
|
1061
|
-
let
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1920
|
+
async *getIterator(options = {}) {
|
1921
|
+
const { batchSize = 1 } = options;
|
1922
|
+
let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
|
1923
|
+
let more = page.hasNextPage();
|
1924
|
+
yield page.records;
|
1925
|
+
while (more) {
|
1926
|
+
page = await page.nextPage();
|
1927
|
+
more = page.hasNextPage();
|
1928
|
+
yield page.records;
|
1067
1929
|
}
|
1068
1930
|
}
|
1069
1931
|
async getMany(options = {}) {
|
1070
|
-
const {
|
1071
|
-
|
1932
|
+
const { pagination = {}, ...rest } = options;
|
1933
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1934
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1935
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1936
|
+
const results = [...page.records];
|
1937
|
+
while (page.hasNextPage() && results.length < size) {
|
1938
|
+
page = await page.nextPage();
|
1939
|
+
results.push(...page.records);
|
1940
|
+
}
|
1941
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1942
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1943
|
+
}
|
1944
|
+
const array = new PageRecordArray(page, results.slice(0, size));
|
1945
|
+
return array;
|
1072
1946
|
}
|
1073
|
-
async getAll(
|
1947
|
+
async getAll(options = {}) {
|
1948
|
+
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
1074
1949
|
const results = [];
|
1075
|
-
for await (const page of this.getIterator(
|
1950
|
+
for await (const page of this.getIterator({ ...rest, batchSize })) {
|
1076
1951
|
results.push(...page);
|
1077
1952
|
}
|
1078
|
-
return results;
|
1953
|
+
return new RecordArray(results);
|
1079
1954
|
}
|
1080
1955
|
async getFirst(options = {}) {
|
1081
|
-
const records = await this.getMany({ ...options,
|
1082
|
-
return records[0]
|
1083
|
-
}
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1956
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1957
|
+
return records[0] ?? null;
|
1958
|
+
}
|
1959
|
+
async getFirstOrThrow(options = {}) {
|
1960
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1961
|
+
if (records[0] === void 0)
|
1962
|
+
throw new Error("No results found.");
|
1963
|
+
return records[0];
|
1964
|
+
}
|
1965
|
+
async summarize(params = {}) {
|
1966
|
+
const { summaries, summariesFilter, ...options } = params;
|
1967
|
+
const query = new _Query(
|
1968
|
+
__privateGet$3(this, _repository),
|
1969
|
+
__privateGet$3(this, _table$1),
|
1970
|
+
options,
|
1971
|
+
__privateGet$3(this, _data)
|
1972
|
+
);
|
1973
|
+
return __privateGet$3(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
1974
|
+
}
|
1975
|
+
/**
|
1976
|
+
* Retrieve next page of records
|
1977
|
+
*
|
1978
|
+
* @returns A new page object.
|
1979
|
+
*/
|
1087
1980
|
nextPage(size, offset) {
|
1088
|
-
return this.
|
1981
|
+
return this.startPage(size, offset);
|
1089
1982
|
}
|
1983
|
+
/**
|
1984
|
+
* Retrieve previous page of records
|
1985
|
+
*
|
1986
|
+
* @returns A new page object
|
1987
|
+
*/
|
1090
1988
|
previousPage(size, offset) {
|
1091
|
-
return this.
|
1092
|
-
}
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1989
|
+
return this.startPage(size, offset);
|
1990
|
+
}
|
1991
|
+
/**
|
1992
|
+
* Retrieve start page of records
|
1993
|
+
*
|
1994
|
+
* @returns A new page object
|
1995
|
+
*/
|
1996
|
+
startPage(size, offset) {
|
1997
|
+
return this.getPaginated({ pagination: { size, offset } });
|
1998
|
+
}
|
1999
|
+
/**
|
2000
|
+
* Retrieve last page of records
|
2001
|
+
*
|
2002
|
+
* @returns A new page object
|
2003
|
+
*/
|
2004
|
+
endPage(size, offset) {
|
2005
|
+
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2006
|
+
}
|
2007
|
+
/**
|
2008
|
+
* @returns Boolean indicating if there is a next page
|
2009
|
+
*/
|
1099
2010
|
hasNextPage() {
|
1100
2011
|
return this.meta.page.more;
|
1101
2012
|
}
|
1102
2013
|
};
|
1103
|
-
let Query = _Query;
|
1104
2014
|
_table$1 = new WeakMap();
|
1105
2015
|
_repository = new WeakMap();
|
1106
2016
|
_data = new WeakMap();
|
2017
|
+
_cleanFilterConstraint = new WeakSet();
|
2018
|
+
cleanFilterConstraint_fn = function(column, value) {
|
2019
|
+
const columnType = __privateGet$3(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
2020
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2021
|
+
return { $includes: value };
|
2022
|
+
}
|
2023
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
2024
|
+
return value.id;
|
2025
|
+
}
|
2026
|
+
return value;
|
2027
|
+
};
|
2028
|
+
let Query = _Query;
|
2029
|
+
function cleanParent(data, parent) {
|
2030
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
2031
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
2032
|
+
}
|
2033
|
+
return parent;
|
2034
|
+
}
|
1107
2035
|
|
2036
|
+
const RecordColumnTypes = [
|
2037
|
+
"bool",
|
2038
|
+
"int",
|
2039
|
+
"float",
|
2040
|
+
"string",
|
2041
|
+
"text",
|
2042
|
+
"email",
|
2043
|
+
"multiple",
|
2044
|
+
"link",
|
2045
|
+
"datetime",
|
2046
|
+
"vector",
|
2047
|
+
"file[]",
|
2048
|
+
"file",
|
2049
|
+
"json"
|
2050
|
+
];
|
1108
2051
|
function isIdentifiable(x) {
|
1109
2052
|
return isObject(x) && isString(x?.id);
|
1110
2053
|
}
|
1111
2054
|
function isXataRecord(x) {
|
1112
|
-
|
2055
|
+
const record = x;
|
2056
|
+
const metadata = record?.getMetadata();
|
2057
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2058
|
+
}
|
2059
|
+
|
2060
|
+
function isValidExpandedColumn(column) {
|
2061
|
+
return isObject(column) && isString(column.name);
|
2062
|
+
}
|
2063
|
+
function isValidSelectableColumns(columns) {
|
2064
|
+
if (!Array.isArray(columns)) {
|
2065
|
+
return false;
|
2066
|
+
}
|
2067
|
+
return columns.every((column) => {
|
2068
|
+
if (typeof column === "string") {
|
2069
|
+
return true;
|
2070
|
+
}
|
2071
|
+
if (typeof column === "object") {
|
2072
|
+
return isValidExpandedColumn(column);
|
2073
|
+
}
|
2074
|
+
return false;
|
2075
|
+
});
|
1113
2076
|
}
|
1114
2077
|
|
1115
2078
|
function isSortFilterString(value) {
|
1116
2079
|
return isString(value);
|
1117
2080
|
}
|
1118
2081
|
function isSortFilterBase(filter) {
|
1119
|
-
return isObject(filter) && Object.
|
2082
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2083
|
+
if (key === "*")
|
2084
|
+
return value === "random";
|
2085
|
+
return value === "asc" || value === "desc";
|
2086
|
+
});
|
1120
2087
|
}
|
1121
2088
|
function isSortFilterObject(filter) {
|
1122
2089
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -1135,433 +2102,869 @@ function buildSortFilter(filter) {
|
|
1135
2102
|
}
|
1136
2103
|
}
|
1137
2104
|
|
1138
|
-
var __accessCheck$
|
2105
|
+
var __accessCheck$3 = (obj, member, msg) => {
|
1139
2106
|
if (!member.has(obj))
|
1140
2107
|
throw TypeError("Cannot " + msg);
|
1141
2108
|
};
|
1142
|
-
var __privateGet$
|
1143
|
-
__accessCheck$
|
2109
|
+
var __privateGet$2 = (obj, member, getter) => {
|
2110
|
+
__accessCheck$3(obj, member, "read from private field");
|
1144
2111
|
return getter ? getter.call(obj) : member.get(obj);
|
1145
2112
|
};
|
1146
|
-
var __privateAdd$
|
2113
|
+
var __privateAdd$3 = (obj, member, value) => {
|
1147
2114
|
if (member.has(obj))
|
1148
2115
|
throw TypeError("Cannot add the same private member more than once");
|
1149
2116
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1150
2117
|
};
|
1151
|
-
var __privateSet$
|
1152
|
-
__accessCheck$
|
2118
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
2119
|
+
__accessCheck$3(obj, member, "write to private field");
|
1153
2120
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1154
2121
|
return value;
|
1155
2122
|
};
|
1156
2123
|
var __privateMethod$2 = (obj, member, method) => {
|
1157
|
-
__accessCheck$
|
2124
|
+
__accessCheck$3(obj, member, "access private method");
|
1158
2125
|
return method;
|
1159
2126
|
};
|
1160
|
-
var _table,
|
2127
|
+
var _table, _getFetchProps, _db, _schemaTables, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _getSchemaTables, getSchemaTables_fn, _transformObjectToApi, transformObjectToApi_fn;
|
2128
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
1161
2129
|
class Repository extends Query {
|
1162
2130
|
}
|
1163
2131
|
class RestRepository extends Query {
|
1164
2132
|
constructor(options) {
|
1165
|
-
super(
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
__privateAdd$
|
1171
|
-
__privateAdd$
|
1172
|
-
__privateAdd$
|
1173
|
-
__privateAdd$
|
1174
|
-
__privateAdd$
|
1175
|
-
__privateAdd$
|
1176
|
-
__privateAdd$
|
1177
|
-
__privateAdd$
|
1178
|
-
__privateAdd$
|
1179
|
-
__privateAdd$
|
1180
|
-
__privateAdd$
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
this
|
1185
|
-
__privateSet$
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
return
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
|
1197
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1198
|
-
return record;
|
1199
|
-
}
|
1200
|
-
if (isObject(a) && isString(a.id)) {
|
1201
|
-
if (a.id === "")
|
1202
|
-
throw new Error("The id can't be empty");
|
1203
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
|
1204
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1205
|
-
return record;
|
1206
|
-
}
|
1207
|
-
if (isObject(a)) {
|
1208
|
-
const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
|
1209
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1210
|
-
return record;
|
1211
|
-
}
|
1212
|
-
throw new Error("Invalid arguments for create method");
|
1213
|
-
}
|
1214
|
-
async read(recordId) {
|
1215
|
-
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
|
1216
|
-
if (cacheRecord)
|
1217
|
-
return cacheRecord;
|
1218
|
-
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1219
|
-
try {
|
1220
|
-
const response = await getRecord({
|
1221
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
|
1222
|
-
...fetchProps
|
2133
|
+
super(
|
2134
|
+
null,
|
2135
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2136
|
+
{}
|
2137
|
+
);
|
2138
|
+
__privateAdd$3(this, _insertRecordWithoutId);
|
2139
|
+
__privateAdd$3(this, _insertRecordWithId);
|
2140
|
+
__privateAdd$3(this, _insertRecords);
|
2141
|
+
__privateAdd$3(this, _updateRecordWithID);
|
2142
|
+
__privateAdd$3(this, _updateRecords);
|
2143
|
+
__privateAdd$3(this, _upsertRecordWithID);
|
2144
|
+
__privateAdd$3(this, _deleteRecord);
|
2145
|
+
__privateAdd$3(this, _deleteRecords);
|
2146
|
+
__privateAdd$3(this, _getSchemaTables);
|
2147
|
+
__privateAdd$3(this, _transformObjectToApi);
|
2148
|
+
__privateAdd$3(this, _table, void 0);
|
2149
|
+
__privateAdd$3(this, _getFetchProps, void 0);
|
2150
|
+
__privateAdd$3(this, _db, void 0);
|
2151
|
+
__privateAdd$3(this, _schemaTables, void 0);
|
2152
|
+
__privateAdd$3(this, _trace, void 0);
|
2153
|
+
__privateSet$1(this, _table, options.table);
|
2154
|
+
__privateSet$1(this, _db, options.db);
|
2155
|
+
__privateSet$1(this, _schemaTables, options.schemaTables);
|
2156
|
+
__privateSet$1(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2157
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2158
|
+
__privateSet$1(this, _trace, async (name, fn, options2 = {}) => {
|
2159
|
+
return trace(name, fn, {
|
2160
|
+
...options2,
|
2161
|
+
[TraceAttributes.TABLE]: __privateGet$2(this, _table),
|
2162
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
2163
|
+
[TraceAttributes.VERSION]: VERSION
|
1223
2164
|
});
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
2165
|
+
});
|
2166
|
+
}
|
2167
|
+
async create(a, b, c, d) {
|
2168
|
+
return __privateGet$2(this, _trace).call(this, "create", async () => {
|
2169
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2170
|
+
if (Array.isArray(a)) {
|
2171
|
+
if (a.length === 0)
|
2172
|
+
return [];
|
2173
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2174
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2175
|
+
const result = await this.read(ids, columns);
|
2176
|
+
return result;
|
2177
|
+
}
|
2178
|
+
if (isString(a) && isObject(b)) {
|
2179
|
+
if (a === "")
|
2180
|
+
throw new Error("The id can't be empty");
|
2181
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2182
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2183
|
+
}
|
2184
|
+
if (isObject(a) && isString(a.id)) {
|
2185
|
+
if (a.id === "")
|
2186
|
+
throw new Error("The id can't be empty");
|
2187
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2188
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2189
|
+
}
|
2190
|
+
if (isObject(a)) {
|
2191
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2192
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2193
|
+
}
|
2194
|
+
throw new Error("Invalid arguments for create method");
|
2195
|
+
});
|
2196
|
+
}
|
2197
|
+
async read(a, b) {
|
2198
|
+
return __privateGet$2(this, _trace).call(this, "read", async () => {
|
2199
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2200
|
+
if (Array.isArray(a)) {
|
2201
|
+
if (a.length === 0)
|
2202
|
+
return [];
|
2203
|
+
const ids = a.map((item) => extractId(item));
|
2204
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
2205
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
2206
|
+
acc[object.id] = object;
|
2207
|
+
return acc;
|
2208
|
+
}, {});
|
2209
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
2210
|
+
}
|
2211
|
+
const id = extractId(a);
|
2212
|
+
if (id) {
|
2213
|
+
try {
|
2214
|
+
const response = await getRecord({
|
2215
|
+
pathParams: {
|
2216
|
+
workspace: "{workspaceId}",
|
2217
|
+
dbBranchName: "{dbBranch}",
|
2218
|
+
region: "{region}",
|
2219
|
+
tableName: __privateGet$2(this, _table),
|
2220
|
+
recordId: id
|
2221
|
+
},
|
2222
|
+
queryParams: { columns },
|
2223
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2224
|
+
});
|
2225
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2226
|
+
return initObject(
|
2227
|
+
__privateGet$2(this, _db),
|
2228
|
+
schemaTables,
|
2229
|
+
__privateGet$2(this, _table),
|
2230
|
+
response,
|
2231
|
+
columns
|
2232
|
+
);
|
2233
|
+
} catch (e) {
|
2234
|
+
if (isObject(e) && e.status === 404) {
|
2235
|
+
return null;
|
2236
|
+
}
|
2237
|
+
throw e;
|
2238
|
+
}
|
2239
|
+
}
|
2240
|
+
return null;
|
2241
|
+
});
|
2242
|
+
}
|
2243
|
+
async readOrThrow(a, b) {
|
2244
|
+
return __privateGet$2(this, _trace).call(this, "readOrThrow", async () => {
|
2245
|
+
const result = await this.read(a, b);
|
2246
|
+
if (Array.isArray(result)) {
|
2247
|
+
const missingIds = compact(
|
2248
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2249
|
+
);
|
2250
|
+
if (missingIds.length > 0) {
|
2251
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2252
|
+
}
|
2253
|
+
return result;
|
2254
|
+
}
|
2255
|
+
if (result === null) {
|
2256
|
+
const id = extractId(a) ?? "unknown";
|
2257
|
+
throw new Error(`Record with id ${id} not found`);
|
2258
|
+
}
|
2259
|
+
return result;
|
2260
|
+
});
|
2261
|
+
}
|
2262
|
+
async update(a, b, c, d) {
|
2263
|
+
return __privateGet$2(this, _trace).call(this, "update", async () => {
|
2264
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2265
|
+
if (Array.isArray(a)) {
|
2266
|
+
if (a.length === 0)
|
2267
|
+
return [];
|
2268
|
+
const existing = await this.read(a, ["id"]);
|
2269
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
2270
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2271
|
+
ifVersion,
|
2272
|
+
upsert: false
|
2273
|
+
});
|
2274
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2275
|
+
const result = await this.read(a, columns);
|
2276
|
+
return result;
|
1228
2277
|
}
|
1229
|
-
|
1230
|
-
|
2278
|
+
try {
|
2279
|
+
if (isString(a) && isObject(b)) {
|
2280
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2281
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2282
|
+
}
|
2283
|
+
if (isObject(a) && isString(a.id)) {
|
2284
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2285
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2286
|
+
}
|
2287
|
+
} catch (error) {
|
2288
|
+
if (error.status === 422)
|
2289
|
+
return null;
|
2290
|
+
throw error;
|
2291
|
+
}
|
2292
|
+
throw new Error("Invalid arguments for update method");
|
2293
|
+
});
|
1231
2294
|
}
|
1232
|
-
async
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
2295
|
+
async updateOrThrow(a, b, c, d) {
|
2296
|
+
return __privateGet$2(this, _trace).call(this, "updateOrThrow", async () => {
|
2297
|
+
const result = await this.update(a, b, c, d);
|
2298
|
+
if (Array.isArray(result)) {
|
2299
|
+
const missingIds = compact(
|
2300
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2301
|
+
);
|
2302
|
+
if (missingIds.length > 0) {
|
2303
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2304
|
+
}
|
2305
|
+
return result;
|
1236
2306
|
}
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
return record;
|
1244
|
-
}
|
1245
|
-
if (isObject(a) && isString(a.id)) {
|
1246
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1247
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1248
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1249
|
-
return record;
|
1250
|
-
}
|
1251
|
-
throw new Error("Invalid arguments for update method");
|
2307
|
+
if (result === null) {
|
2308
|
+
const id = extractId(a) ?? "unknown";
|
2309
|
+
throw new Error(`Record with id ${id} not found`);
|
2310
|
+
}
|
2311
|
+
return result;
|
2312
|
+
});
|
1252
2313
|
}
|
1253
|
-
async createOrUpdate(a, b) {
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
2314
|
+
async createOrUpdate(a, b, c, d) {
|
2315
|
+
return __privateGet$2(this, _trace).call(this, "createOrUpdate", async () => {
|
2316
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2317
|
+
if (Array.isArray(a)) {
|
2318
|
+
if (a.length === 0)
|
2319
|
+
return [];
|
2320
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
2321
|
+
ifVersion,
|
2322
|
+
upsert: true
|
2323
|
+
});
|
2324
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2325
|
+
const result = await this.read(a, columns);
|
2326
|
+
return result;
|
1257
2327
|
}
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
2328
|
+
if (isString(a) && isObject(b)) {
|
2329
|
+
if (a === "")
|
2330
|
+
throw new Error("The id can't be empty");
|
2331
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2332
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2333
|
+
}
|
2334
|
+
if (isObject(a) && isString(a.id)) {
|
2335
|
+
if (a.id === "")
|
2336
|
+
throw new Error("The id can't be empty");
|
2337
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2338
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2339
|
+
}
|
2340
|
+
if (!isDefined(a) && isObject(b)) {
|
2341
|
+
return await this.create(b, c);
|
2342
|
+
}
|
2343
|
+
if (isObject(a) && !isDefined(a.id)) {
|
2344
|
+
return await this.create(a, b);
|
2345
|
+
}
|
2346
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
2347
|
+
});
|
1273
2348
|
}
|
1274
|
-
async
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
2349
|
+
async createOrReplace(a, b, c, d) {
|
2350
|
+
return __privateGet$2(this, _trace).call(this, "createOrReplace", async () => {
|
2351
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2352
|
+
if (Array.isArray(a)) {
|
2353
|
+
if (a.length === 0)
|
2354
|
+
return [];
|
2355
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2356
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2357
|
+
const result = await this.read(ids, columns);
|
2358
|
+
return result;
|
1278
2359
|
}
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
2360
|
+
if (isString(a) && isObject(b)) {
|
2361
|
+
if (a === "")
|
2362
|
+
throw new Error("The id can't be empty");
|
2363
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2364
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2365
|
+
}
|
2366
|
+
if (isObject(a) && isString(a.id)) {
|
2367
|
+
if (a.id === "")
|
2368
|
+
throw new Error("The id can't be empty");
|
2369
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2370
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
2371
|
+
}
|
2372
|
+
if (!isDefined(a) && isObject(b)) {
|
2373
|
+
return await this.create(b, c);
|
2374
|
+
}
|
2375
|
+
if (isObject(a) && !isDefined(a.id)) {
|
2376
|
+
return await this.create(a, b);
|
2377
|
+
}
|
2378
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
2379
|
+
});
|
2380
|
+
}
|
2381
|
+
async delete(a, b) {
|
2382
|
+
return __privateGet$2(this, _trace).call(this, "delete", async () => {
|
2383
|
+
if (Array.isArray(a)) {
|
2384
|
+
if (a.length === 0)
|
2385
|
+
return [];
|
2386
|
+
const ids = a.map((o) => {
|
2387
|
+
if (isString(o))
|
2388
|
+
return o;
|
2389
|
+
if (isString(o.id))
|
2390
|
+
return o.id;
|
2391
|
+
throw new Error("Invalid arguments for delete method");
|
2392
|
+
});
|
2393
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2394
|
+
const result = await this.read(a, columns);
|
2395
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2396
|
+
return result;
|
2397
|
+
}
|
2398
|
+
if (isString(a)) {
|
2399
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
2400
|
+
}
|
2401
|
+
if (isObject(a) && isString(a.id)) {
|
2402
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
2403
|
+
}
|
2404
|
+
throw new Error("Invalid arguments for delete method");
|
2405
|
+
});
|
2406
|
+
}
|
2407
|
+
async deleteOrThrow(a, b) {
|
2408
|
+
return __privateGet$2(this, _trace).call(this, "deleteOrThrow", async () => {
|
2409
|
+
const result = await this.delete(a, b);
|
2410
|
+
if (Array.isArray(result)) {
|
2411
|
+
const missingIds = compact(
|
2412
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2413
|
+
);
|
2414
|
+
if (missingIds.length > 0) {
|
2415
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2416
|
+
}
|
2417
|
+
return result;
|
2418
|
+
} else if (result === null) {
|
2419
|
+
const id = extractId(a) ?? "unknown";
|
2420
|
+
throw new Error(`Record with id ${id} not found`);
|
2421
|
+
}
|
2422
|
+
return result;
|
2423
|
+
});
|
1293
2424
|
}
|
1294
2425
|
async search(query, options = {}) {
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
2426
|
+
return __privateGet$2(this, _trace).call(this, "search", async () => {
|
2427
|
+
const { records, totalCount } = await searchTable({
|
2428
|
+
pathParams: {
|
2429
|
+
workspace: "{workspaceId}",
|
2430
|
+
dbBranchName: "{dbBranch}",
|
2431
|
+
region: "{region}",
|
2432
|
+
tableName: __privateGet$2(this, _table)
|
2433
|
+
},
|
2434
|
+
body: {
|
2435
|
+
query,
|
2436
|
+
fuzziness: options.fuzziness,
|
2437
|
+
prefix: options.prefix,
|
2438
|
+
highlight: options.highlight,
|
2439
|
+
filter: options.filter,
|
2440
|
+
boosters: options.boosters,
|
2441
|
+
page: options.page,
|
2442
|
+
target: options.target
|
2443
|
+
},
|
2444
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2445
|
+
});
|
2446
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2447
|
+
return {
|
2448
|
+
records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
|
2449
|
+
totalCount
|
2450
|
+
};
|
2451
|
+
});
|
2452
|
+
}
|
2453
|
+
async vectorSearch(column, query, options) {
|
2454
|
+
return __privateGet$2(this, _trace).call(this, "vectorSearch", async () => {
|
2455
|
+
const { records, totalCount } = await vectorSearchTable({
|
2456
|
+
pathParams: {
|
2457
|
+
workspace: "{workspaceId}",
|
2458
|
+
dbBranchName: "{dbBranch}",
|
2459
|
+
region: "{region}",
|
2460
|
+
tableName: __privateGet$2(this, _table)
|
2461
|
+
},
|
2462
|
+
body: {
|
2463
|
+
column,
|
2464
|
+
queryVector: query,
|
2465
|
+
similarityFunction: options?.similarityFunction,
|
2466
|
+
size: options?.size,
|
2467
|
+
filter: options?.filter
|
2468
|
+
},
|
2469
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2470
|
+
});
|
2471
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2472
|
+
return {
|
2473
|
+
records: records.map((item) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), item, ["*"])),
|
2474
|
+
totalCount
|
2475
|
+
};
|
2476
|
+
});
|
2477
|
+
}
|
2478
|
+
async aggregate(aggs, filter) {
|
2479
|
+
return __privateGet$2(this, _trace).call(this, "aggregate", async () => {
|
2480
|
+
const result = await aggregateTable({
|
2481
|
+
pathParams: {
|
2482
|
+
workspace: "{workspaceId}",
|
2483
|
+
dbBranchName: "{dbBranch}",
|
2484
|
+
region: "{region}",
|
2485
|
+
tableName: __privateGet$2(this, _table)
|
2486
|
+
},
|
2487
|
+
body: { aggs, filter },
|
2488
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2489
|
+
});
|
2490
|
+
return result;
|
1300
2491
|
});
|
1301
|
-
return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
|
1302
2492
|
}
|
1303
2493
|
async query(query) {
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
2494
|
+
return __privateGet$2(this, _trace).call(this, "query", async () => {
|
2495
|
+
const data = query.getQueryOptions();
|
2496
|
+
const { meta, records: objects } = await queryTable({
|
2497
|
+
pathParams: {
|
2498
|
+
workspace: "{workspaceId}",
|
2499
|
+
dbBranchName: "{dbBranch}",
|
2500
|
+
region: "{region}",
|
2501
|
+
tableName: __privateGet$2(this, _table)
|
2502
|
+
},
|
2503
|
+
body: {
|
2504
|
+
filter: cleanFilter(data.filter),
|
2505
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2506
|
+
page: data.pagination,
|
2507
|
+
columns: data.columns ?? ["*"],
|
2508
|
+
consistency: data.consistency
|
2509
|
+
},
|
2510
|
+
fetchOptions: data.fetchOptions,
|
2511
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2512
|
+
});
|
2513
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2514
|
+
const records = objects.map(
|
2515
|
+
(record) => initObject(
|
2516
|
+
__privateGet$2(this, _db),
|
2517
|
+
schemaTables,
|
2518
|
+
__privateGet$2(this, _table),
|
2519
|
+
record,
|
2520
|
+
data.columns ?? ["*"]
|
2521
|
+
)
|
2522
|
+
);
|
2523
|
+
return new Page(query, meta, records);
|
2524
|
+
});
|
2525
|
+
}
|
2526
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
2527
|
+
return __privateGet$2(this, _trace).call(this, "summarize", async () => {
|
2528
|
+
const data = query.getQueryOptions();
|
2529
|
+
const result = await summarizeTable({
|
2530
|
+
pathParams: {
|
2531
|
+
workspace: "{workspaceId}",
|
2532
|
+
dbBranchName: "{dbBranch}",
|
2533
|
+
region: "{region}",
|
2534
|
+
tableName: __privateGet$2(this, _table)
|
2535
|
+
},
|
2536
|
+
body: {
|
2537
|
+
filter: cleanFilter(data.filter),
|
2538
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2539
|
+
columns: data.columns,
|
2540
|
+
consistency: data.consistency,
|
2541
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2542
|
+
summaries,
|
2543
|
+
summariesFilter
|
2544
|
+
},
|
2545
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2546
|
+
});
|
2547
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2548
|
+
return {
|
2549
|
+
...result,
|
2550
|
+
summaries: result.summaries.map(
|
2551
|
+
(summary) => initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), summary, data.columns ?? [])
|
2552
|
+
)
|
2553
|
+
};
|
1319
2554
|
});
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
2555
|
+
}
|
2556
|
+
ask(question, options) {
|
2557
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
2558
|
+
const params = {
|
2559
|
+
pathParams: {
|
2560
|
+
workspace: "{workspaceId}",
|
2561
|
+
dbBranchName: "{dbBranch}",
|
2562
|
+
region: "{region}",
|
2563
|
+
tableName: __privateGet$2(this, _table),
|
2564
|
+
sessionId: options?.sessionId
|
2565
|
+
},
|
2566
|
+
body: {
|
2567
|
+
...questionParam,
|
2568
|
+
rules: options?.rules,
|
2569
|
+
searchType: options?.searchType,
|
2570
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
2571
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
2572
|
+
},
|
2573
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2574
|
+
};
|
2575
|
+
if (options?.onMessage) {
|
2576
|
+
fetchSSERequest({
|
2577
|
+
endpoint: "dataPlane",
|
2578
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
2579
|
+
method: "POST",
|
2580
|
+
onMessage: (message) => {
|
2581
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
2582
|
+
},
|
2583
|
+
...params
|
2584
|
+
});
|
2585
|
+
} else {
|
2586
|
+
return askTableSession(params);
|
2587
|
+
}
|
1323
2588
|
}
|
1324
2589
|
}
|
1325
2590
|
_table = new WeakMap();
|
1326
|
-
_links = new WeakMap();
|
1327
2591
|
_getFetchProps = new WeakMap();
|
1328
|
-
|
2592
|
+
_db = new WeakMap();
|
2593
|
+
_schemaTables = new WeakMap();
|
2594
|
+
_trace = new WeakMap();
|
1329
2595
|
_insertRecordWithoutId = new WeakSet();
|
1330
|
-
insertRecordWithoutId_fn = async function(object) {
|
1331
|
-
const
|
1332
|
-
const record = transformObjectLinks(object);
|
2596
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2597
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
1333
2598
|
const response = await insertRecord({
|
1334
2599
|
pathParams: {
|
1335
2600
|
workspace: "{workspaceId}",
|
1336
2601
|
dbBranchName: "{dbBranch}",
|
1337
|
-
|
2602
|
+
region: "{region}",
|
2603
|
+
tableName: __privateGet$2(this, _table)
|
1338
2604
|
},
|
2605
|
+
queryParams: { columns },
|
1339
2606
|
body: record,
|
1340
|
-
...
|
2607
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
1341
2608
|
});
|
1342
|
-
const
|
1343
|
-
|
1344
|
-
throw new Error("The server failed to save the record");
|
1345
|
-
}
|
1346
|
-
return finalObject;
|
2609
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2610
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
1347
2611
|
};
|
1348
2612
|
_insertRecordWithId = new WeakSet();
|
1349
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1350
|
-
|
1351
|
-
|
2613
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2614
|
+
if (!recordId)
|
2615
|
+
return null;
|
2616
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
1352
2617
|
const response = await insertRecordWithID({
|
1353
2618
|
pathParams: {
|
1354
2619
|
workspace: "{workspaceId}",
|
1355
2620
|
dbBranchName: "{dbBranch}",
|
1356
|
-
|
2621
|
+
region: "{region}",
|
2622
|
+
tableName: __privateGet$2(this, _table),
|
1357
2623
|
recordId
|
1358
2624
|
},
|
1359
2625
|
body: record,
|
1360
|
-
queryParams: { createOnly
|
1361
|
-
...
|
2626
|
+
queryParams: { createOnly, columns, ifVersion },
|
2627
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
1362
2628
|
});
|
1363
|
-
const
|
1364
|
-
|
1365
|
-
throw new Error("The server failed to save the record");
|
1366
|
-
}
|
1367
|
-
return finalObject;
|
2629
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2630
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
1368
2631
|
};
|
1369
|
-
|
1370
|
-
|
1371
|
-
const
|
1372
|
-
|
1373
|
-
|
1374
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
|
1375
|
-
body: { records },
|
1376
|
-
...fetchProps
|
2632
|
+
_insertRecords = new WeakSet();
|
2633
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2634
|
+
const operations = await promiseMap(objects, async (object) => {
|
2635
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2636
|
+
return { insert: { table: __privateGet$2(this, _table), record, createOnly, ifVersion } };
|
1377
2637
|
});
|
1378
|
-
const
|
1379
|
-
|
1380
|
-
|
2638
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2639
|
+
const ids = [];
|
2640
|
+
for (const operations2 of chunkedOperations) {
|
2641
|
+
const { results } = await branchTransaction({
|
2642
|
+
pathParams: {
|
2643
|
+
workspace: "{workspaceId}",
|
2644
|
+
dbBranchName: "{dbBranch}",
|
2645
|
+
region: "{region}"
|
2646
|
+
},
|
2647
|
+
body: { operations: operations2 },
|
2648
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2649
|
+
});
|
2650
|
+
for (const result of results) {
|
2651
|
+
if (result.operation === "insert") {
|
2652
|
+
ids.push(result.id);
|
2653
|
+
} else {
|
2654
|
+
ids.push(null);
|
2655
|
+
}
|
2656
|
+
}
|
1381
2657
|
}
|
1382
|
-
return
|
2658
|
+
return ids;
|
1383
2659
|
};
|
1384
2660
|
_updateRecordWithID = new WeakSet();
|
1385
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1386
|
-
|
1387
|
-
|
1388
|
-
const
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
2661
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2662
|
+
if (!recordId)
|
2663
|
+
return null;
|
2664
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2665
|
+
try {
|
2666
|
+
const response = await updateRecordWithID({
|
2667
|
+
pathParams: {
|
2668
|
+
workspace: "{workspaceId}",
|
2669
|
+
dbBranchName: "{dbBranch}",
|
2670
|
+
region: "{region}",
|
2671
|
+
tableName: __privateGet$2(this, _table),
|
2672
|
+
recordId
|
2673
|
+
},
|
2674
|
+
queryParams: { columns, ifVersion },
|
2675
|
+
body: record,
|
2676
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2677
|
+
});
|
2678
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2679
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
2680
|
+
} catch (e) {
|
2681
|
+
if (isObject(e) && e.status === 404) {
|
2682
|
+
return null;
|
2683
|
+
}
|
2684
|
+
throw e;
|
2685
|
+
}
|
2686
|
+
};
|
2687
|
+
_updateRecords = new WeakSet();
|
2688
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2689
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
2690
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2691
|
+
return { update: { table: __privateGet$2(this, _table), id, ifVersion, upsert, fields } };
|
1392
2692
|
});
|
1393
|
-
const
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
2693
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2694
|
+
const ids = [];
|
2695
|
+
for (const operations2 of chunkedOperations) {
|
2696
|
+
const { results } = await branchTransaction({
|
2697
|
+
pathParams: {
|
2698
|
+
workspace: "{workspaceId}",
|
2699
|
+
dbBranchName: "{dbBranch}",
|
2700
|
+
region: "{region}"
|
2701
|
+
},
|
2702
|
+
body: { operations: operations2 },
|
2703
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2704
|
+
});
|
2705
|
+
for (const result of results) {
|
2706
|
+
if (result.operation === "update") {
|
2707
|
+
ids.push(result.id);
|
2708
|
+
} else {
|
2709
|
+
ids.push(null);
|
2710
|
+
}
|
2711
|
+
}
|
2712
|
+
}
|
2713
|
+
return ids;
|
1397
2714
|
};
|
1398
2715
|
_upsertRecordWithID = new WeakSet();
|
1399
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1400
|
-
|
2716
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2717
|
+
if (!recordId)
|
2718
|
+
return null;
|
1401
2719
|
const response = await upsertRecordWithID({
|
1402
|
-
pathParams: {
|
2720
|
+
pathParams: {
|
2721
|
+
workspace: "{workspaceId}",
|
2722
|
+
dbBranchName: "{dbBranch}",
|
2723
|
+
region: "{region}",
|
2724
|
+
tableName: __privateGet$2(this, _table),
|
2725
|
+
recordId
|
2726
|
+
},
|
2727
|
+
queryParams: { columns, ifVersion },
|
1403
2728
|
body: object,
|
1404
|
-
...
|
2729
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
1405
2730
|
});
|
1406
|
-
const
|
1407
|
-
|
1408
|
-
throw new Error("The server failed to save the record");
|
1409
|
-
return item;
|
2731
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2732
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
1410
2733
|
};
|
1411
2734
|
_deleteRecord = new WeakSet();
|
1412
|
-
deleteRecord_fn = async function(recordId) {
|
1413
|
-
|
1414
|
-
await deleteRecord({
|
1415
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
|
1416
|
-
...fetchProps
|
1417
|
-
});
|
1418
|
-
};
|
1419
|
-
_invalidateCache = new WeakSet();
|
1420
|
-
invalidateCache_fn = async function(recordId) {
|
1421
|
-
await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
|
1422
|
-
const cacheItems = await __privateGet$3(this, _cache).getAll();
|
1423
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1424
|
-
for (const [key, value] of queries) {
|
1425
|
-
const ids = getIds(value);
|
1426
|
-
if (ids.includes(recordId))
|
1427
|
-
await __privateGet$3(this, _cache).delete(key);
|
1428
|
-
}
|
1429
|
-
};
|
1430
|
-
_setCacheRecord = new WeakSet();
|
1431
|
-
setCacheRecord_fn = async function(record) {
|
1432
|
-
if (!__privateGet$3(this, _cache).cacheRecords)
|
1433
|
-
return;
|
1434
|
-
await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
|
1435
|
-
};
|
1436
|
-
_getCacheRecord = new WeakSet();
|
1437
|
-
getCacheRecord_fn = async function(recordId) {
|
1438
|
-
if (!__privateGet$3(this, _cache).cacheRecords)
|
2735
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2736
|
+
if (!recordId)
|
1439
2737
|
return null;
|
1440
|
-
|
2738
|
+
try {
|
2739
|
+
const response = await deleteRecord({
|
2740
|
+
pathParams: {
|
2741
|
+
workspace: "{workspaceId}",
|
2742
|
+
dbBranchName: "{dbBranch}",
|
2743
|
+
region: "{region}",
|
2744
|
+
tableName: __privateGet$2(this, _table),
|
2745
|
+
recordId
|
2746
|
+
},
|
2747
|
+
queryParams: { columns },
|
2748
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2749
|
+
});
|
2750
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2751
|
+
return initObject(__privateGet$2(this, _db), schemaTables, __privateGet$2(this, _table), response, columns);
|
2752
|
+
} catch (e) {
|
2753
|
+
if (isObject(e) && e.status === 404) {
|
2754
|
+
return null;
|
2755
|
+
}
|
2756
|
+
throw e;
|
2757
|
+
}
|
1441
2758
|
};
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
2759
|
+
_deleteRecords = new WeakSet();
|
2760
|
+
deleteRecords_fn = async function(recordIds) {
|
2761
|
+
const chunkedOperations = chunk(
|
2762
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$2(this, _table), id } })),
|
2763
|
+
BULK_OPERATION_MAX_SIZE
|
2764
|
+
);
|
2765
|
+
for (const operations of chunkedOperations) {
|
2766
|
+
await branchTransaction({
|
2767
|
+
pathParams: {
|
2768
|
+
workspace: "{workspaceId}",
|
2769
|
+
dbBranchName: "{dbBranch}",
|
2770
|
+
region: "{region}"
|
2771
|
+
},
|
2772
|
+
body: { operations },
|
2773
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2774
|
+
});
|
2775
|
+
}
|
1445
2776
|
};
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
return hasExpired ? null : result;
|
2777
|
+
_getSchemaTables = new WeakSet();
|
2778
|
+
getSchemaTables_fn = async function() {
|
2779
|
+
if (__privateGet$2(this, _schemaTables))
|
2780
|
+
return __privateGet$2(this, _schemaTables);
|
2781
|
+
const { schema } = await getBranchDetails({
|
2782
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2783
|
+
...__privateGet$2(this, _getFetchProps).call(this)
|
2784
|
+
});
|
2785
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
2786
|
+
return schema.tables;
|
1457
2787
|
};
|
1458
|
-
|
1459
|
-
|
2788
|
+
_transformObjectToApi = new WeakSet();
|
2789
|
+
transformObjectToApi_fn = async function(object) {
|
2790
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
2791
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$2(this, _table));
|
2792
|
+
if (!schema)
|
2793
|
+
throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
|
2794
|
+
const result = {};
|
2795
|
+
for (const [key, value] of Object.entries(object)) {
|
1460
2796
|
if (key === "xata")
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
2797
|
+
continue;
|
2798
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
2799
|
+
switch (type) {
|
2800
|
+
case "link": {
|
2801
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
2802
|
+
break;
|
2803
|
+
}
|
2804
|
+
case "datetime": {
|
2805
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
2806
|
+
break;
|
2807
|
+
}
|
2808
|
+
case `file`:
|
2809
|
+
result[key] = await parseInputFileEntry(value);
|
2810
|
+
break;
|
2811
|
+
case "file[]":
|
2812
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
2813
|
+
break;
|
2814
|
+
case "json":
|
2815
|
+
result[key] = stringifyJson(value);
|
2816
|
+
break;
|
2817
|
+
default:
|
2818
|
+
result[key] = value;
|
2819
|
+
}
|
2820
|
+
}
|
2821
|
+
return result;
|
1464
2822
|
};
|
1465
|
-
const initObject = (db,
|
1466
|
-
const
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
2823
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2824
|
+
const data = {};
|
2825
|
+
const { xata, ...rest } = object ?? {};
|
2826
|
+
Object.assign(data, rest);
|
2827
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2828
|
+
if (!columns)
|
2829
|
+
console.error(`Table ${table} not found in schema`);
|
2830
|
+
for (const column of columns ?? []) {
|
2831
|
+
if (!isValidColumn(selectedColumns, column))
|
2832
|
+
continue;
|
2833
|
+
const value = data[column.name];
|
2834
|
+
switch (column.type) {
|
2835
|
+
case "datetime": {
|
2836
|
+
const date = value !== void 0 ? new Date(value) : null;
|
2837
|
+
if (date !== null && isNaN(date.getTime())) {
|
2838
|
+
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2839
|
+
} else {
|
2840
|
+
data[column.name] = date;
|
2841
|
+
}
|
2842
|
+
break;
|
2843
|
+
}
|
2844
|
+
case "link": {
|
2845
|
+
const linkTable = column.link?.table;
|
2846
|
+
if (!linkTable) {
|
2847
|
+
console.error(`Failed to parse link for field ${column.name}`);
|
2848
|
+
} else if (isObject(value)) {
|
2849
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2850
|
+
if (item === column.name) {
|
2851
|
+
return [...acc, "*"];
|
2852
|
+
}
|
2853
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2854
|
+
const [, ...path] = item.split(".");
|
2855
|
+
return [...acc, path.join(".")];
|
2856
|
+
}
|
2857
|
+
return acc;
|
2858
|
+
}, []);
|
2859
|
+
data[column.name] = initObject(
|
2860
|
+
db,
|
2861
|
+
schemaTables,
|
2862
|
+
linkTable,
|
2863
|
+
value,
|
2864
|
+
selectedLinkColumns
|
2865
|
+
);
|
2866
|
+
} else {
|
2867
|
+
data[column.name] = null;
|
2868
|
+
}
|
2869
|
+
break;
|
2870
|
+
}
|
2871
|
+
case "file":
|
2872
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
2873
|
+
break;
|
2874
|
+
case "file[]":
|
2875
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
2876
|
+
break;
|
2877
|
+
case "json":
|
2878
|
+
data[column.name] = parseJson(value);
|
2879
|
+
break;
|
2880
|
+
default:
|
2881
|
+
data[column.name] = value ?? null;
|
2882
|
+
if (column.notNull === true && value === null) {
|
2883
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2884
|
+
}
|
2885
|
+
break;
|
1474
2886
|
}
|
1475
2887
|
}
|
1476
|
-
|
1477
|
-
|
2888
|
+
const record = { ...data };
|
2889
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2890
|
+
record.read = function(columns2) {
|
2891
|
+
return db[table].read(record["id"], columns2);
|
2892
|
+
};
|
2893
|
+
record.update = function(data2, b, c) {
|
2894
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2895
|
+
const ifVersion = parseIfVersion(b, c);
|
2896
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
1478
2897
|
};
|
1479
|
-
|
1480
|
-
|
2898
|
+
record.replace = function(data2, b, c) {
|
2899
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2900
|
+
const ifVersion = parseIfVersion(b, c);
|
2901
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
1481
2902
|
};
|
1482
|
-
|
1483
|
-
return db[table].delete(
|
2903
|
+
record.delete = function() {
|
2904
|
+
return db[table].delete(record["id"]);
|
1484
2905
|
};
|
1485
|
-
|
1486
|
-
Object.
|
2906
|
+
if (metadata !== void 0) {
|
2907
|
+
record.xata = Object.freeze(metadata);
|
1487
2908
|
}
|
1488
|
-
|
1489
|
-
|
1490
|
-
};
|
1491
|
-
function
|
1492
|
-
|
1493
|
-
|
2909
|
+
record.getMetadata = function() {
|
2910
|
+
return record.xata;
|
2911
|
+
};
|
2912
|
+
record.toSerializable = function() {
|
2913
|
+
return JSON.parse(JSON.stringify(record));
|
2914
|
+
};
|
2915
|
+
record.toString = function() {
|
2916
|
+
return JSON.stringify(record);
|
2917
|
+
};
|
2918
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2919
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
1494
2920
|
}
|
1495
|
-
|
1496
|
-
|
1497
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1498
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1499
|
-
}
|
1500
|
-
|
1501
|
-
var __accessCheck$3 = (obj, member, msg) => {
|
1502
|
-
if (!member.has(obj))
|
1503
|
-
throw TypeError("Cannot " + msg);
|
1504
|
-
};
|
1505
|
-
var __privateGet$2 = (obj, member, getter) => {
|
1506
|
-
__accessCheck$3(obj, member, "read from private field");
|
1507
|
-
return getter ? getter.call(obj) : member.get(obj);
|
1508
|
-
};
|
1509
|
-
var __privateAdd$3 = (obj, member, value) => {
|
1510
|
-
if (member.has(obj))
|
1511
|
-
throw TypeError("Cannot add the same private member more than once");
|
1512
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1513
|
-
};
|
1514
|
-
var __privateSet$1 = (obj, member, value, setter) => {
|
1515
|
-
__accessCheck$3(obj, member, "write to private field");
|
1516
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
1517
|
-
return value;
|
2921
|
+
Object.freeze(record);
|
2922
|
+
return record;
|
1518
2923
|
};
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
await this.delete(key);
|
1536
|
-
__privateGet$2(this, _map).set(key, value);
|
1537
|
-
if (__privateGet$2(this, _map).size > this.capacity) {
|
1538
|
-
const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
|
1539
|
-
await this.delete(leastRecentlyUsed);
|
2924
|
+
function extractId(value) {
|
2925
|
+
if (isString(value))
|
2926
|
+
return value;
|
2927
|
+
if (isObject(value) && isString(value.id))
|
2928
|
+
return value.id;
|
2929
|
+
return void 0;
|
2930
|
+
}
|
2931
|
+
function isValidColumn(columns, column) {
|
2932
|
+
if (columns.includes("*"))
|
2933
|
+
return true;
|
2934
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
2935
|
+
}
|
2936
|
+
function parseIfVersion(...args) {
|
2937
|
+
for (const arg of args) {
|
2938
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
2939
|
+
return arg.ifVersion;
|
1540
2940
|
}
|
1541
2941
|
}
|
1542
|
-
|
1543
|
-
__privateGet$2(this, _map).delete(key);
|
1544
|
-
}
|
1545
|
-
async clear() {
|
1546
|
-
return __privateGet$2(this, _map).clear();
|
1547
|
-
}
|
2942
|
+
return void 0;
|
1548
2943
|
}
|
1549
|
-
_map = new WeakMap();
|
1550
2944
|
|
1551
|
-
const
|
1552
|
-
const
|
1553
|
-
const
|
1554
|
-
const
|
1555
|
-
const
|
1556
|
-
const
|
2945
|
+
const greaterThan = (value) => ({ $gt: value });
|
2946
|
+
const gt = greaterThan;
|
2947
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2948
|
+
const greaterEquals = greaterThanEquals;
|
2949
|
+
const gte = greaterThanEquals;
|
2950
|
+
const ge = greaterThanEquals;
|
2951
|
+
const lessThan = (value) => ({ $lt: value });
|
2952
|
+
const lt = lessThan;
|
2953
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2954
|
+
const lessEquals = lessThanEquals;
|
2955
|
+
const lte = lessThanEquals;
|
2956
|
+
const le = lessThanEquals;
|
1557
2957
|
const exists = (column) => ({ $exists: column });
|
1558
2958
|
const notExists = (column) => ({ $notExists: column });
|
1559
2959
|
const startsWith = (value) => ({ $startsWith: value });
|
1560
2960
|
const endsWith = (value) => ({ $endsWith: value });
|
1561
2961
|
const pattern = (value) => ({ $pattern: value });
|
2962
|
+
const iPattern = (value) => ({ $iPattern: value });
|
1562
2963
|
const is = (value) => ({ $is: value });
|
2964
|
+
const equals = is;
|
1563
2965
|
const isNot = (value) => ({ $isNot: value });
|
1564
2966
|
const contains = (value) => ({ $contains: value });
|
2967
|
+
const iContains = (value) => ({ $iContains: value });
|
1565
2968
|
const includes = (value) => ({ $includes: value });
|
1566
2969
|
const includesAll = (value) => ({ $includesAll: value });
|
1567
2970
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -1582,32 +2985,107 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1582
2985
|
};
|
1583
2986
|
var _tables;
|
1584
2987
|
class SchemaPlugin extends XataPlugin {
|
1585
|
-
constructor(
|
2988
|
+
constructor() {
|
1586
2989
|
super();
|
1587
|
-
this.links = links;
|
1588
|
-
this.tableNames = tableNames;
|
1589
2990
|
__privateAdd$2(this, _tables, {});
|
1590
2991
|
}
|
1591
2992
|
build(pluginOptions) {
|
1592
|
-
const
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
__privateGet$1(this, _tables)[table]
|
2993
|
+
const db = new Proxy(
|
2994
|
+
{},
|
2995
|
+
{
|
2996
|
+
get: (_target, table) => {
|
2997
|
+
if (!isString(table))
|
2998
|
+
throw new Error("Invalid table name");
|
2999
|
+
if (__privateGet$1(this, _tables)[table] === void 0) {
|
3000
|
+
__privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
3001
|
+
}
|
3002
|
+
return __privateGet$1(this, _tables)[table];
|
1599
3003
|
}
|
1600
|
-
return __privateGet$1(this, _tables)[table];
|
1601
3004
|
}
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
3005
|
+
);
|
3006
|
+
const tableNames = pluginOptions.tables?.map(({ name }) => name) ?? [];
|
3007
|
+
for (const table of tableNames) {
|
3008
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
1605
3009
|
}
|
1606
3010
|
return db;
|
1607
3011
|
}
|
1608
3012
|
}
|
1609
3013
|
_tables = new WeakMap();
|
1610
3014
|
|
3015
|
+
class FilesPlugin extends XataPlugin {
|
3016
|
+
build(pluginOptions) {
|
3017
|
+
return {
|
3018
|
+
download: async (location) => {
|
3019
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3020
|
+
return await getFileItem({
|
3021
|
+
pathParams: {
|
3022
|
+
workspace: "{workspaceId}",
|
3023
|
+
dbBranchName: "{dbBranch}",
|
3024
|
+
region: "{region}",
|
3025
|
+
tableName: table ?? "",
|
3026
|
+
recordId: record ?? "",
|
3027
|
+
columnName: column ?? "",
|
3028
|
+
fileId
|
3029
|
+
},
|
3030
|
+
...pluginOptions,
|
3031
|
+
rawResponse: true
|
3032
|
+
});
|
3033
|
+
},
|
3034
|
+
upload: async (location, file, options) => {
|
3035
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3036
|
+
const resolvedFile = await file;
|
3037
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
3038
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
3039
|
+
return await putFileItem({
|
3040
|
+
...pluginOptions,
|
3041
|
+
pathParams: {
|
3042
|
+
workspace: "{workspaceId}",
|
3043
|
+
dbBranchName: "{dbBranch}",
|
3044
|
+
region: "{region}",
|
3045
|
+
tableName: table ?? "",
|
3046
|
+
recordId: record ?? "",
|
3047
|
+
columnName: column ?? "",
|
3048
|
+
fileId
|
3049
|
+
},
|
3050
|
+
body,
|
3051
|
+
headers: { "Content-Type": contentType }
|
3052
|
+
});
|
3053
|
+
},
|
3054
|
+
delete: async (location) => {
|
3055
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3056
|
+
return await deleteFileItem({
|
3057
|
+
pathParams: {
|
3058
|
+
workspace: "{workspaceId}",
|
3059
|
+
dbBranchName: "{dbBranch}",
|
3060
|
+
region: "{region}",
|
3061
|
+
tableName: table ?? "",
|
3062
|
+
recordId: record ?? "",
|
3063
|
+
columnName: column ?? "",
|
3064
|
+
fileId
|
3065
|
+
},
|
3066
|
+
...pluginOptions
|
3067
|
+
});
|
3068
|
+
}
|
3069
|
+
};
|
3070
|
+
}
|
3071
|
+
}
|
3072
|
+
function getContentType(file) {
|
3073
|
+
if (typeof file === "string") {
|
3074
|
+
return "text/plain";
|
3075
|
+
}
|
3076
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
3077
|
+
return file.mediaType;
|
3078
|
+
}
|
3079
|
+
if (isBlob(file)) {
|
3080
|
+
return file.type;
|
3081
|
+
}
|
3082
|
+
try {
|
3083
|
+
return file.type;
|
3084
|
+
} catch (e) {
|
3085
|
+
}
|
3086
|
+
return "application/octet-stream";
|
3087
|
+
}
|
3088
|
+
|
1611
3089
|
var __accessCheck$1 = (obj, member, msg) => {
|
1612
3090
|
if (!member.has(obj))
|
1613
3091
|
throw TypeError("Cannot " + msg);
|
@@ -1623,124 +3101,141 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1623
3101
|
};
|
1624
3102
|
var _search, search_fn;
|
1625
3103
|
class SearchPlugin extends XataPlugin {
|
1626
|
-
constructor(db
|
3104
|
+
constructor(db) {
|
1627
3105
|
super();
|
1628
3106
|
this.db = db;
|
1629
|
-
this.links = links;
|
1630
3107
|
__privateAdd$1(this, _search);
|
1631
3108
|
}
|
1632
|
-
build(
|
3109
|
+
build(pluginOptions) {
|
1633
3110
|
return {
|
1634
3111
|
all: async (query, options = {}) => {
|
1635
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1636
|
-
return
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
3112
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3113
|
+
return {
|
3114
|
+
totalCount,
|
3115
|
+
records: records.map((record) => {
|
3116
|
+
const { table = "orphan" } = record.xata;
|
3117
|
+
return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
|
3118
|
+
})
|
3119
|
+
};
|
1640
3120
|
},
|
1641
3121
|
byTable: async (query, options = {}) => {
|
1642
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1643
|
-
|
3122
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3123
|
+
const records = rawRecords.reduce((acc, record) => {
|
1644
3124
|
const { table = "orphan" } = record.xata;
|
1645
3125
|
const items = acc[table] ?? [];
|
1646
|
-
const item = initObject(this.db,
|
3126
|
+
const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
|
1647
3127
|
return { ...acc, [table]: [...items, item] };
|
1648
3128
|
}, {});
|
3129
|
+
return { totalCount, records };
|
1649
3130
|
}
|
1650
3131
|
};
|
1651
3132
|
}
|
1652
3133
|
}
|
1653
3134
|
_search = new WeakSet();
|
1654
|
-
search_fn = async function(query, options,
|
1655
|
-
const
|
1656
|
-
const {
|
1657
|
-
|
1658
|
-
|
1659
|
-
body: { tables, query, fuzziness },
|
1660
|
-
...
|
3135
|
+
search_fn = async function(query, options, pluginOptions) {
|
3136
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3137
|
+
const { records, totalCount } = await searchBranch({
|
3138
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3139
|
+
// @ts-expect-error Filter properties do not match inferred type
|
3140
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3141
|
+
...pluginOptions
|
1661
3142
|
});
|
1662
|
-
return records;
|
1663
|
-
};
|
1664
|
-
|
1665
|
-
const isBranchStrategyBuilder = (strategy) => {
|
1666
|
-
return typeof strategy === "function";
|
3143
|
+
return { records, totalCount };
|
1667
3144
|
};
|
1668
3145
|
|
1669
|
-
|
1670
|
-
"
|
1671
|
-
"
|
1672
|
-
"CF_PAGES_BRANCH",
|
1673
|
-
"BRANCH"
|
1674
|
-
];
|
1675
|
-
const defaultBranch = "main";
|
1676
|
-
async function getCurrentBranchName(options) {
|
1677
|
-
const env = await getBranchByEnvVariable();
|
1678
|
-
if (env)
|
1679
|
-
return env;
|
1680
|
-
const branch = await getGitBranch();
|
1681
|
-
if (!branch)
|
1682
|
-
return defaultBranch;
|
1683
|
-
const details = await getDatabaseBranch(branch, options);
|
1684
|
-
if (details)
|
1685
|
-
return branch;
|
1686
|
-
return defaultBranch;
|
1687
|
-
}
|
1688
|
-
async function getCurrentBranchDetails(options) {
|
1689
|
-
const env = await getBranchByEnvVariable();
|
1690
|
-
if (env)
|
1691
|
-
return getDatabaseBranch(env, options);
|
1692
|
-
const branch = await getGitBranch();
|
1693
|
-
if (!branch)
|
1694
|
-
return getDatabaseBranch(defaultBranch, options);
|
1695
|
-
const details = await getDatabaseBranch(branch, options);
|
1696
|
-
if (details)
|
1697
|
-
return details;
|
1698
|
-
return getDatabaseBranch(defaultBranch, options);
|
1699
|
-
}
|
1700
|
-
async function getDatabaseBranch(branch, options) {
|
1701
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1702
|
-
const apiKey = options?.apiKey || getAPIKey();
|
1703
|
-
if (!databaseURL)
|
1704
|
-
throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
|
1705
|
-
if (!apiKey)
|
1706
|
-
throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
|
1707
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
1708
|
-
const [workspace] = host.split(".");
|
1709
|
-
const dbBranchName = `${database}:${branch}`;
|
1710
|
-
try {
|
1711
|
-
return await getBranchDetails({
|
1712
|
-
apiKey,
|
1713
|
-
apiUrl: databaseURL,
|
1714
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1715
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
1716
|
-
pathParams: {
|
1717
|
-
dbBranchName,
|
1718
|
-
workspace
|
1719
|
-
}
|
1720
|
-
});
|
1721
|
-
} catch (err) {
|
1722
|
-
if (isObject(err) && err.status === 404)
|
1723
|
-
return null;
|
1724
|
-
throw err;
|
1725
|
-
}
|
3146
|
+
function escapeElement(elementRepresentation) {
|
3147
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
3148
|
+
return '"' + escaped + '"';
|
1726
3149
|
}
|
1727
|
-
function
|
1728
|
-
|
1729
|
-
|
1730
|
-
if (
|
1731
|
-
|
3150
|
+
function arrayString(val) {
|
3151
|
+
let result = "{";
|
3152
|
+
for (let i = 0; i < val.length; i++) {
|
3153
|
+
if (i > 0) {
|
3154
|
+
result = result + ",";
|
3155
|
+
}
|
3156
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
3157
|
+
result = result + "NULL";
|
3158
|
+
} else if (Array.isArray(val[i])) {
|
3159
|
+
result = result + arrayString(val[i]);
|
3160
|
+
} else if (val[i] instanceof Buffer) {
|
3161
|
+
result += "\\\\x" + val[i].toString("hex");
|
3162
|
+
} else {
|
3163
|
+
result += escapeElement(prepareValue(val[i]));
|
1732
3164
|
}
|
1733
3165
|
}
|
3166
|
+
result = result + "}";
|
3167
|
+
return result;
|
3168
|
+
}
|
3169
|
+
function prepareValue(value) {
|
3170
|
+
if (!isDefined(value))
|
3171
|
+
return null;
|
3172
|
+
if (value instanceof Date) {
|
3173
|
+
return value.toISOString();
|
3174
|
+
}
|
3175
|
+
if (Array.isArray(value)) {
|
3176
|
+
return arrayString(value);
|
3177
|
+
}
|
3178
|
+
if (isObject(value)) {
|
3179
|
+
return JSON.stringify(value);
|
3180
|
+
}
|
1734
3181
|
try {
|
1735
|
-
return
|
1736
|
-
} catch (
|
3182
|
+
return value.toString();
|
3183
|
+
} catch (e) {
|
3184
|
+
return value;
|
1737
3185
|
}
|
1738
3186
|
}
|
1739
|
-
function
|
1740
|
-
|
1741
|
-
return
|
1742
|
-
}
|
1743
|
-
|
3187
|
+
function prepareParams(param1, param2) {
|
3188
|
+
if (isString(param1)) {
|
3189
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
3190
|
+
}
|
3191
|
+
if (isStringArray(param1)) {
|
3192
|
+
const statement = param1.reduce((acc, curr, index) => {
|
3193
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
3194
|
+
}, "");
|
3195
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
3196
|
+
}
|
3197
|
+
if (isObject(param1)) {
|
3198
|
+
const { statement, params, consistency } = param1;
|
3199
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
3200
|
+
}
|
3201
|
+
throw new Error("Invalid query");
|
3202
|
+
}
|
3203
|
+
|
3204
|
+
class SQLPlugin extends XataPlugin {
|
3205
|
+
build(pluginOptions) {
|
3206
|
+
return async (query, ...parameters) => {
|
3207
|
+
if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
|
3208
|
+
throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
|
3209
|
+
}
|
3210
|
+
const { statement, params, consistency } = prepareParams(query, parameters);
|
3211
|
+
const { records, warning, columns } = await sqlQuery({
|
3212
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3213
|
+
body: { statement, params, consistency },
|
3214
|
+
...pluginOptions
|
3215
|
+
});
|
3216
|
+
return { records, warning, columns };
|
3217
|
+
};
|
3218
|
+
}
|
3219
|
+
}
|
3220
|
+
function isTemplateStringsArray(strings) {
|
3221
|
+
return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
|
3222
|
+
}
|
3223
|
+
function isParamsObject(params) {
|
3224
|
+
return isObject(params) && "statement" in params;
|
3225
|
+
}
|
3226
|
+
|
3227
|
+
class TransactionPlugin extends XataPlugin {
|
3228
|
+
build(pluginOptions) {
|
3229
|
+
return {
|
3230
|
+
run: async (operations) => {
|
3231
|
+
const response = await branchTransaction({
|
3232
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3233
|
+
body: { operations },
|
3234
|
+
...pluginOptions
|
3235
|
+
});
|
3236
|
+
return response;
|
3237
|
+
}
|
3238
|
+
};
|
1744
3239
|
}
|
1745
3240
|
}
|
1746
3241
|
|
@@ -1767,85 +3262,191 @@ var __privateMethod = (obj, member, method) => {
|
|
1767
3262
|
return method;
|
1768
3263
|
};
|
1769
3264
|
const buildClient = (plugins) => {
|
1770
|
-
var
|
3265
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
1771
3266
|
return _a = class {
|
1772
|
-
constructor(options = {},
|
3267
|
+
constructor(options = {}, tables) {
|
1773
3268
|
__privateAdd(this, _parseOptions);
|
1774
3269
|
__privateAdd(this, _getFetchProps);
|
1775
|
-
__privateAdd(this,
|
1776
|
-
__privateAdd(this, _branch, void 0);
|
3270
|
+
__privateAdd(this, _options, void 0);
|
1777
3271
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3272
|
+
__privateSet(this, _options, safeOptions);
|
1778
3273
|
const pluginOptions = {
|
1779
|
-
|
1780
|
-
|
3274
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3275
|
+
host: safeOptions.host,
|
3276
|
+
tables
|
1781
3277
|
};
|
1782
|
-
const db = new SchemaPlugin(
|
1783
|
-
const search = new SearchPlugin(db
|
3278
|
+
const db = new SchemaPlugin().build(pluginOptions);
|
3279
|
+
const search = new SearchPlugin(db).build(pluginOptions);
|
3280
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
3281
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
3282
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3283
|
+
this.schema = { tables };
|
1784
3284
|
this.db = db;
|
1785
3285
|
this.search = search;
|
3286
|
+
this.transactions = transactions;
|
3287
|
+
this.sql = sql;
|
3288
|
+
this.files = files;
|
1786
3289
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
1787
|
-
if (
|
3290
|
+
if (namespace === void 0)
|
1788
3291
|
continue;
|
1789
|
-
|
1790
|
-
if (result instanceof Promise) {
|
1791
|
-
void result.then((namespace2) => {
|
1792
|
-
this[key] = namespace2;
|
1793
|
-
});
|
1794
|
-
} else {
|
1795
|
-
this[key] = result;
|
1796
|
-
}
|
3292
|
+
this[key] = namespace.build(pluginOptions);
|
1797
3293
|
}
|
1798
3294
|
}
|
1799
|
-
|
3295
|
+
async getConfig() {
|
3296
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
3297
|
+
const branch = __privateGet(this, _options).branch;
|
3298
|
+
return { databaseURL, branch };
|
3299
|
+
}
|
3300
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3301
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3302
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3303
|
+
if (isBrowser && !enableBrowser) {
|
3304
|
+
throw new Error(
|
3305
|
+
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
3306
|
+
);
|
3307
|
+
}
|
1800
3308
|
const fetch = getFetchImplementation(options?.fetch);
|
1801
3309
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1802
3310
|
const apiKey = options?.apiKey || getAPIKey();
|
1803
|
-
const
|
1804
|
-
const
|
1805
|
-
|
1806
|
-
|
3311
|
+
const trace = options?.trace ?? defaultTrace;
|
3312
|
+
const clientName = options?.clientName;
|
3313
|
+
const host = options?.host ?? "production";
|
3314
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3315
|
+
if (!apiKey) {
|
3316
|
+
throw new Error("Option apiKey is required");
|
3317
|
+
}
|
3318
|
+
if (!databaseURL) {
|
3319
|
+
throw new Error("Option databaseURL is required");
|
1807
3320
|
}
|
1808
|
-
|
1809
|
-
|
3321
|
+
const envBranch = getBranch();
|
3322
|
+
const previewBranch = getPreviewBranch();
|
3323
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
3324
|
+
if (!!previewBranch && branch !== previewBranch) {
|
3325
|
+
console.warn(
|
3326
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
3327
|
+
);
|
3328
|
+
} else if (!!envBranch && branch !== envBranch) {
|
3329
|
+
console.warn(
|
3330
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3331
|
+
);
|
3332
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
3333
|
+
console.warn(
|
3334
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3335
|
+
);
|
3336
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
3337
|
+
console.warn(
|
3338
|
+
`No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
|
3339
|
+
);
|
3340
|
+
}
|
3341
|
+
return {
|
3342
|
+
fetch,
|
3343
|
+
databaseURL,
|
3344
|
+
apiKey,
|
3345
|
+
branch,
|
3346
|
+
trace,
|
3347
|
+
host,
|
3348
|
+
clientID: generateUUID(),
|
3349
|
+
enableBrowser,
|
3350
|
+
clientName,
|
3351
|
+
xataAgentExtra
|
3352
|
+
};
|
3353
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
1810
3354
|
fetch,
|
1811
3355
|
apiKey,
|
1812
3356
|
databaseURL,
|
1813
|
-
branch
|
3357
|
+
branch,
|
3358
|
+
trace,
|
3359
|
+
clientID,
|
3360
|
+
clientName,
|
3361
|
+
xataAgentExtra
|
1814
3362
|
}) {
|
1815
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1816
|
-
if (!branchValue)
|
1817
|
-
throw new Error("Unable to resolve branch value");
|
1818
3363
|
return {
|
1819
|
-
|
3364
|
+
fetch,
|
1820
3365
|
apiKey,
|
1821
3366
|
apiUrl: "",
|
3367
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
1822
3368
|
workspacesApiUrl: (path, params) => {
|
1823
3369
|
const hasBranch = params.dbBranchName ?? params.branch;
|
1824
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${
|
3370
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
1825
3371
|
return databaseURL + newPath;
|
1826
|
-
}
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
if (!param)
|
1832
|
-
return void 0;
|
1833
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
1834
|
-
const evaluateBranch = async (strategy) => {
|
1835
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3372
|
+
},
|
3373
|
+
trace,
|
3374
|
+
clientID,
|
3375
|
+
clientName,
|
3376
|
+
xataAgentExtra
|
1836
3377
|
};
|
1837
|
-
for await (const strategy of strategies) {
|
1838
|
-
const branch = await evaluateBranch(strategy);
|
1839
|
-
if (branch) {
|
1840
|
-
__privateSet(this, _branch, branch);
|
1841
|
-
return branch;
|
1842
|
-
}
|
1843
|
-
}
|
1844
3378
|
}, _a;
|
1845
3379
|
};
|
1846
3380
|
class BaseClient extends buildClient() {
|
1847
3381
|
}
|
1848
3382
|
|
3383
|
+
const META = "__";
|
3384
|
+
const VALUE = "___";
|
3385
|
+
class Serializer {
|
3386
|
+
constructor() {
|
3387
|
+
this.classes = {};
|
3388
|
+
}
|
3389
|
+
add(clazz) {
|
3390
|
+
this.classes[clazz.name] = clazz;
|
3391
|
+
}
|
3392
|
+
toJSON(data) {
|
3393
|
+
function visit(obj) {
|
3394
|
+
if (Array.isArray(obj))
|
3395
|
+
return obj.map(visit);
|
3396
|
+
const type = typeof obj;
|
3397
|
+
if (type === "undefined")
|
3398
|
+
return { [META]: "undefined" };
|
3399
|
+
if (type === "bigint")
|
3400
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
3401
|
+
if (obj === null || type !== "object")
|
3402
|
+
return obj;
|
3403
|
+
const constructor = obj.constructor;
|
3404
|
+
const o = { [META]: constructor.name };
|
3405
|
+
for (const [key, value] of Object.entries(obj)) {
|
3406
|
+
o[key] = visit(value);
|
3407
|
+
}
|
3408
|
+
if (constructor === Date)
|
3409
|
+
o[VALUE] = obj.toISOString();
|
3410
|
+
if (constructor === Map)
|
3411
|
+
o[VALUE] = Object.fromEntries(obj);
|
3412
|
+
if (constructor === Set)
|
3413
|
+
o[VALUE] = [...obj];
|
3414
|
+
return o;
|
3415
|
+
}
|
3416
|
+
return JSON.stringify(visit(data));
|
3417
|
+
}
|
3418
|
+
fromJSON(json) {
|
3419
|
+
return JSON.parse(json, (key, value) => {
|
3420
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
3421
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
3422
|
+
const constructor = this.classes[clazz];
|
3423
|
+
if (constructor) {
|
3424
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
3425
|
+
}
|
3426
|
+
if (clazz === "Date")
|
3427
|
+
return new Date(val);
|
3428
|
+
if (clazz === "Set")
|
3429
|
+
return new Set(val);
|
3430
|
+
if (clazz === "Map")
|
3431
|
+
return new Map(Object.entries(val));
|
3432
|
+
if (clazz === "bigint")
|
3433
|
+
return BigInt(val);
|
3434
|
+
if (clazz === "undefined")
|
3435
|
+
return void 0;
|
3436
|
+
return rest;
|
3437
|
+
}
|
3438
|
+
return value;
|
3439
|
+
});
|
3440
|
+
}
|
3441
|
+
}
|
3442
|
+
const defaultSerializer = new Serializer();
|
3443
|
+
const serialize = (data) => {
|
3444
|
+
return defaultSerializer.toJSON(data);
|
3445
|
+
};
|
3446
|
+
const deserialize = (json) => {
|
3447
|
+
return defaultSerializer.fromJSON(json);
|
3448
|
+
};
|
3449
|
+
|
1849
3450
|
class XataError extends Error {
|
1850
3451
|
constructor(message, status) {
|
1851
3452
|
super(message);
|
@@ -1854,69 +3455,119 @@ class XataError extends Error {
|
|
1854
3455
|
}
|
1855
3456
|
|
1856
3457
|
exports.BaseClient = BaseClient;
|
3458
|
+
exports.FetcherError = FetcherError;
|
3459
|
+
exports.FilesPlugin = FilesPlugin;
|
1857
3460
|
exports.Operations = operationsByTag;
|
1858
3461
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
1859
3462
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
1860
3463
|
exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
|
1861
3464
|
exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
1862
3465
|
exports.Page = Page;
|
3466
|
+
exports.PageRecordArray = PageRecordArray;
|
1863
3467
|
exports.Query = Query;
|
3468
|
+
exports.RecordArray = RecordArray;
|
3469
|
+
exports.RecordColumnTypes = RecordColumnTypes;
|
1864
3470
|
exports.Repository = Repository;
|
1865
3471
|
exports.RestRepository = RestRepository;
|
3472
|
+
exports.SQLPlugin = SQLPlugin;
|
1866
3473
|
exports.SchemaPlugin = SchemaPlugin;
|
1867
3474
|
exports.SearchPlugin = SearchPlugin;
|
1868
|
-
exports.
|
3475
|
+
exports.Serializer = Serializer;
|
3476
|
+
exports.TransactionPlugin = TransactionPlugin;
|
1869
3477
|
exports.XataApiClient = XataApiClient;
|
1870
3478
|
exports.XataApiPlugin = XataApiPlugin;
|
1871
3479
|
exports.XataError = XataError;
|
3480
|
+
exports.XataFile = XataFile;
|
1872
3481
|
exports.XataPlugin = XataPlugin;
|
1873
3482
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
1874
3483
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
1875
3484
|
exports.addTableColumn = addTableColumn;
|
3485
|
+
exports.aggregateTable = aggregateTable;
|
3486
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
3487
|
+
exports.applyMigration = applyMigration;
|
3488
|
+
exports.askTable = askTable;
|
3489
|
+
exports.askTableSession = askTableSession;
|
3490
|
+
exports.branchTransaction = branchTransaction;
|
1876
3491
|
exports.buildClient = buildClient;
|
3492
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
3493
|
+
exports.buildProviderString = buildProviderString;
|
1877
3494
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
1878
3495
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
3496
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
3497
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3498
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
1879
3499
|
exports.contains = contains;
|
3500
|
+
exports.copyBranch = copyBranch;
|
1880
3501
|
exports.createBranch = createBranch;
|
3502
|
+
exports.createCluster = createCluster;
|
1881
3503
|
exports.createDatabase = createDatabase;
|
3504
|
+
exports.createMigrationRequest = createMigrationRequest;
|
1882
3505
|
exports.createTable = createTable;
|
1883
3506
|
exports.createUserAPIKey = createUserAPIKey;
|
1884
3507
|
exports.createWorkspace = createWorkspace;
|
1885
3508
|
exports.deleteBranch = deleteBranch;
|
1886
3509
|
exports.deleteColumn = deleteColumn;
|
1887
3510
|
exports.deleteDatabase = deleteDatabase;
|
3511
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
3512
|
+
exports.deleteFile = deleteFile;
|
3513
|
+
exports.deleteFileItem = deleteFileItem;
|
3514
|
+
exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
|
1888
3515
|
exports.deleteRecord = deleteRecord;
|
1889
3516
|
exports.deleteTable = deleteTable;
|
1890
3517
|
exports.deleteUser = deleteUser;
|
1891
3518
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
3519
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
1892
3520
|
exports.deleteWorkspace = deleteWorkspace;
|
3521
|
+
exports.deserialize = deserialize;
|
1893
3522
|
exports.endsWith = endsWith;
|
3523
|
+
exports.equals = equals;
|
1894
3524
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
1895
3525
|
exports.exists = exists;
|
3526
|
+
exports.fileAccess = fileAccess;
|
3527
|
+
exports.fileUpload = fileUpload;
|
1896
3528
|
exports.ge = ge;
|
1897
3529
|
exports.getAPIKey = getAPIKey;
|
3530
|
+
exports.getAuthorizationCode = getAuthorizationCode;
|
3531
|
+
exports.getBranch = getBranch;
|
1898
3532
|
exports.getBranchDetails = getBranchDetails;
|
1899
3533
|
exports.getBranchList = getBranchList;
|
1900
3534
|
exports.getBranchMetadata = getBranchMetadata;
|
1901
3535
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
1902
3536
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
3537
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
1903
3538
|
exports.getBranchStats = getBranchStats;
|
3539
|
+
exports.getCluster = getCluster;
|
1904
3540
|
exports.getColumn = getColumn;
|
1905
|
-
exports.
|
1906
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
3541
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
1907
3542
|
exports.getDatabaseList = getDatabaseList;
|
3543
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
1908
3544
|
exports.getDatabaseURL = getDatabaseURL;
|
3545
|
+
exports.getFile = getFile;
|
3546
|
+
exports.getFileItem = getFileItem;
|
1909
3547
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3548
|
+
exports.getHostUrl = getHostUrl;
|
3549
|
+
exports.getMigrationRequest = getMigrationRequest;
|
3550
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
3551
|
+
exports.getPreviewBranch = getPreviewBranch;
|
1910
3552
|
exports.getRecord = getRecord;
|
3553
|
+
exports.getSchema = getSchema;
|
1911
3554
|
exports.getTableColumns = getTableColumns;
|
1912
3555
|
exports.getTableSchema = getTableSchema;
|
1913
3556
|
exports.getUser = getUser;
|
1914
3557
|
exports.getUserAPIKeys = getUserAPIKeys;
|
3558
|
+
exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
3559
|
+
exports.getUserOAuthClients = getUserOAuthClients;
|
1915
3560
|
exports.getWorkspace = getWorkspace;
|
1916
3561
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
1917
3562
|
exports.getWorkspacesList = getWorkspacesList;
|
3563
|
+
exports.grantAuthorizationCode = grantAuthorizationCode;
|
3564
|
+
exports.greaterEquals = greaterEquals;
|
3565
|
+
exports.greaterThan = greaterThan;
|
3566
|
+
exports.greaterThanEquals = greaterThanEquals;
|
1918
3567
|
exports.gt = gt;
|
1919
3568
|
exports.gte = gte;
|
3569
|
+
exports.iContains = iContains;
|
3570
|
+
exports.iPattern = iPattern;
|
1920
3571
|
exports.includes = includes;
|
1921
3572
|
exports.includesAll = includesAll;
|
1922
3573
|
exports.includesAny = includesAny;
|
@@ -1925,29 +3576,65 @@ exports.insertRecord = insertRecord;
|
|
1925
3576
|
exports.insertRecordWithID = insertRecordWithID;
|
1926
3577
|
exports.inviteWorkspaceMember = inviteWorkspaceMember;
|
1927
3578
|
exports.is = is;
|
3579
|
+
exports.isCursorPaginationOptions = isCursorPaginationOptions;
|
3580
|
+
exports.isHostProviderAlias = isHostProviderAlias;
|
3581
|
+
exports.isHostProviderBuilder = isHostProviderBuilder;
|
1928
3582
|
exports.isIdentifiable = isIdentifiable;
|
1929
3583
|
exports.isNot = isNot;
|
3584
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
3585
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
1930
3586
|
exports.isXataRecord = isXataRecord;
|
1931
3587
|
exports.le = le;
|
3588
|
+
exports.lessEquals = lessEquals;
|
3589
|
+
exports.lessThan = lessThan;
|
3590
|
+
exports.lessThanEquals = lessThanEquals;
|
3591
|
+
exports.listClusters = listClusters;
|
3592
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
3593
|
+
exports.listRegions = listRegions;
|
1932
3594
|
exports.lt = lt;
|
1933
3595
|
exports.lte = lte;
|
3596
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
1934
3597
|
exports.notExists = notExists;
|
1935
3598
|
exports.operationsByTag = operationsByTag;
|
3599
|
+
exports.parseProviderString = parseProviderString;
|
3600
|
+
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
1936
3601
|
exports.pattern = pattern;
|
3602
|
+
exports.pgRollJobStatus = pgRollJobStatus;
|
3603
|
+
exports.pgRollMigrationHistory = pgRollMigrationHistory;
|
3604
|
+
exports.pgRollStatus = pgRollStatus;
|
3605
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
3606
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
3607
|
+
exports.putFile = putFile;
|
3608
|
+
exports.putFileItem = putFileItem;
|
3609
|
+
exports.queryMigrationRequests = queryMigrationRequests;
|
1937
3610
|
exports.queryTable = queryTable;
|
1938
3611
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
1939
3612
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
3613
|
+
exports.renameDatabase = renameDatabase;
|
1940
3614
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
1941
3615
|
exports.resolveBranch = resolveBranch;
|
1942
3616
|
exports.searchBranch = searchBranch;
|
3617
|
+
exports.searchTable = searchTable;
|
3618
|
+
exports.serialize = serialize;
|
1943
3619
|
exports.setTableSchema = setTableSchema;
|
3620
|
+
exports.sqlQuery = sqlQuery;
|
1944
3621
|
exports.startsWith = startsWith;
|
3622
|
+
exports.summarizeTable = summarizeTable;
|
3623
|
+
exports.transformImage = transformImage;
|
1945
3624
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3625
|
+
exports.updateBranchSchema = updateBranchSchema;
|
3626
|
+
exports.updateCluster = updateCluster;
|
1946
3627
|
exports.updateColumn = updateColumn;
|
3628
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3629
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3630
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
3631
|
+
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
1947
3632
|
exports.updateRecordWithID = updateRecordWithID;
|
1948
3633
|
exports.updateTable = updateTable;
|
1949
3634
|
exports.updateUser = updateUser;
|
1950
3635
|
exports.updateWorkspace = updateWorkspace;
|
3636
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
1951
3637
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
1952
3638
|
exports.upsertRecordWithID = upsertRecordWithID;
|
3639
|
+
exports.vectorSearchTable = vectorSearchTable;
|
1953
3640
|
//# sourceMappingURL=index.cjs.map
|