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