@xata.io/client 0.0.0-alpha.vf76843f → 0.0.0-alpha.vf7a5219a6da9afdecee2e8995fcc249036ff88a1
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 +350 -0
- package/README.md +3 -269
- package/dist/index.cjs +1962 -460
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5248 -2796
- package/dist/index.mjs +1914 -453
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -451
- 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);
|
@@ -69,16 +93,42 @@ function chunk(array, chunkSize) {
|
|
69
93
|
}
|
70
94
|
return result;
|
71
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
|
+
}
|
72
120
|
|
73
121
|
function getEnvironment() {
|
74
122
|
try {
|
75
|
-
if (
|
123
|
+
if (isDefined(process) && isDefined(process.env)) {
|
76
124
|
return {
|
77
125
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
78
126
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
79
127
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
80
|
-
|
81
|
-
|
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
|
82
132
|
};
|
83
133
|
}
|
84
134
|
} catch (err) {
|
@@ -89,8 +139,10 @@ function getEnvironment() {
|
|
89
139
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
90
140
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
91
141
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
92
|
-
|
93
|
-
|
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")
|
94
146
|
};
|
95
147
|
}
|
96
148
|
} catch (err) {
|
@@ -99,8 +151,10 @@ function getEnvironment() {
|
|
99
151
|
apiKey: getGlobalApiKey(),
|
100
152
|
databaseURL: getGlobalDatabaseURL(),
|
101
153
|
branch: getGlobalBranch(),
|
102
|
-
|
103
|
-
|
154
|
+
deployPreview: void 0,
|
155
|
+
deployPreviewBranch: void 0,
|
156
|
+
vercelGitCommitRef: void 0,
|
157
|
+
vercelGitRepoOwner: void 0
|
104
158
|
};
|
105
159
|
}
|
106
160
|
function getEnableBrowserVariable() {
|
@@ -143,56 +197,338 @@ function getGlobalBranch() {
|
|
143
197
|
return void 0;
|
144
198
|
}
|
145
199
|
}
|
146
|
-
function
|
200
|
+
function getDatabaseURL() {
|
147
201
|
try {
|
148
|
-
|
202
|
+
const { databaseURL } = getEnvironment();
|
203
|
+
return databaseURL;
|
149
204
|
} catch (err) {
|
150
205
|
return void 0;
|
151
206
|
}
|
152
207
|
}
|
153
|
-
|
154
|
-
const cmd = ["git", "branch", "--show-current"];
|
155
|
-
const fullCmd = cmd.join(" ");
|
156
|
-
const nodeModule = ["child", "process"].join("_");
|
157
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
208
|
+
function getAPIKey() {
|
158
209
|
try {
|
159
|
-
|
160
|
-
|
161
|
-
}
|
162
|
-
const { execSync } = await import(nodeModule);
|
163
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
210
|
+
const { apiKey } = getEnvironment();
|
211
|
+
return apiKey;
|
164
212
|
} catch (err) {
|
213
|
+
return void 0;
|
165
214
|
}
|
215
|
+
}
|
216
|
+
function getBranch() {
|
166
217
|
try {
|
167
|
-
|
168
|
-
|
169
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
170
|
-
}
|
218
|
+
const { branch } = getEnvironment();
|
219
|
+
return branch;
|
171
220
|
} catch (err) {
|
221
|
+
return void 0;
|
172
222
|
}
|
173
223
|
}
|
174
|
-
|
175
|
-
|
224
|
+
function buildPreviewBranchName({ org, branch }) {
|
225
|
+
return `preview-${org}-${branch}`;
|
226
|
+
}
|
227
|
+
function getPreviewBranch() {
|
176
228
|
try {
|
177
|
-
const {
|
178
|
-
|
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;
|
179
242
|
} catch (err) {
|
180
243
|
return void 0;
|
181
244
|
}
|
182
245
|
}
|
183
246
|
|
247
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
248
|
+
if (!member.has(obj))
|
249
|
+
throw TypeError("Cannot " + msg);
|
250
|
+
};
|
251
|
+
var __privateGet$8 = (obj, member, getter) => {
|
252
|
+
__accessCheck$8(obj, member, "read from private field");
|
253
|
+
return getter ? getter.call(obj) : member.get(obj);
|
254
|
+
};
|
255
|
+
var __privateAdd$8 = (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$8 = (obj, member, value, setter) => {
|
261
|
+
__accessCheck$8(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$8(obj, member, "access private method");
|
267
|
+
return method;
|
268
|
+
};
|
269
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
270
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
184
271
|
function getFetchImplementation(userFetch) {
|
185
272
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
186
|
-
const
|
273
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
274
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
187
275
|
if (!fetchImpl) {
|
188
|
-
throw new Error(
|
189
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
190
|
-
);
|
276
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
191
277
|
}
|
192
278
|
return fetchImpl;
|
193
279
|
}
|
280
|
+
class ApiRequestPool {
|
281
|
+
constructor(concurrency = 10) {
|
282
|
+
__privateAdd$8(this, _enqueue);
|
283
|
+
__privateAdd$8(this, _fetch, void 0);
|
284
|
+
__privateAdd$8(this, _queue, void 0);
|
285
|
+
__privateAdd$8(this, _concurrency, void 0);
|
286
|
+
__privateSet$8(this, _queue, []);
|
287
|
+
__privateSet$8(this, _concurrency, concurrency);
|
288
|
+
this.running = 0;
|
289
|
+
this.started = 0;
|
290
|
+
}
|
291
|
+
setFetch(fetch2) {
|
292
|
+
__privateSet$8(this, _fetch, fetch2);
|
293
|
+
}
|
294
|
+
getFetch() {
|
295
|
+
if (!__privateGet$8(this, _fetch)) {
|
296
|
+
throw new Error("Fetch not set");
|
297
|
+
}
|
298
|
+
return __privateGet$8(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$8(this, _queue).push(resolve)).finally(() => {
|
331
|
+
this.started--;
|
332
|
+
this.running++;
|
333
|
+
}).then(() => task()).finally(() => {
|
334
|
+
this.running--;
|
335
|
+
const next = __privateGet$8(this, _queue).shift();
|
336
|
+
if (next !== void 0) {
|
337
|
+
this.started++;
|
338
|
+
next();
|
339
|
+
}
|
340
|
+
});
|
341
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
342
|
+
const next = __privateGet$8(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
|
+
}
|
194
530
|
|
195
|
-
const VERSION = "0.
|
531
|
+
const VERSION = "0.28.3";
|
196
532
|
|
197
533
|
class ErrorWithCause extends Error {
|
198
534
|
constructor(message, options) {
|
@@ -203,7 +539,7 @@ class FetcherError extends ErrorWithCause {
|
|
203
539
|
constructor(status, data, requestId) {
|
204
540
|
super(getMessage(data));
|
205
541
|
this.status = status;
|
206
|
-
this.errors = isBulkError(data) ? data.errors :
|
542
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
207
543
|
this.requestId = requestId;
|
208
544
|
if (data instanceof Error) {
|
209
545
|
this.stack = data.stack;
|
@@ -235,6 +571,68 @@ function getMessage(data) {
|
|
235
571
|
}
|
236
572
|
}
|
237
573
|
|
574
|
+
function getHostUrl(provider, type) {
|
575
|
+
if (isHostProviderAlias(provider)) {
|
576
|
+
return providers[provider][type];
|
577
|
+
} else if (isHostProviderBuilder(provider)) {
|
578
|
+
return provider[type];
|
579
|
+
}
|
580
|
+
throw new Error("Invalid API provider");
|
581
|
+
}
|
582
|
+
const providers = {
|
583
|
+
production: {
|
584
|
+
main: "https://api.xata.io",
|
585
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
586
|
+
},
|
587
|
+
staging: {
|
588
|
+
main: "https://api.staging-xata.dev",
|
589
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
590
|
+
},
|
591
|
+
dev: {
|
592
|
+
main: "https://api.dev-xata.dev",
|
593
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
594
|
+
},
|
595
|
+
local: {
|
596
|
+
main: "http://localhost:6001",
|
597
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
598
|
+
}
|
599
|
+
};
|
600
|
+
function isHostProviderAlias(alias) {
|
601
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
602
|
+
}
|
603
|
+
function isHostProviderBuilder(builder) {
|
604
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
605
|
+
}
|
606
|
+
function parseProviderString(provider = "production") {
|
607
|
+
if (isHostProviderAlias(provider)) {
|
608
|
+
return provider;
|
609
|
+
}
|
610
|
+
const [main, workspaces] = provider.split(",");
|
611
|
+
if (!main || !workspaces)
|
612
|
+
return null;
|
613
|
+
return { main, workspaces };
|
614
|
+
}
|
615
|
+
function buildProviderString(provider) {
|
616
|
+
if (isHostProviderAlias(provider))
|
617
|
+
return provider;
|
618
|
+
return `${provider.main},${provider.workspaces}`;
|
619
|
+
}
|
620
|
+
function parseWorkspacesUrlParts(url) {
|
621
|
+
if (!isString(url))
|
622
|
+
return null;
|
623
|
+
const matches = {
|
624
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
625
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
626
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
627
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
628
|
+
};
|
629
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
630
|
+
if (!isHostProviderAlias(host) || !match)
|
631
|
+
return null;
|
632
|
+
return { workspace: match[1], region: match[2], host };
|
633
|
+
}
|
634
|
+
|
635
|
+
const pool = new ApiRequestPool();
|
238
636
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
239
637
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
240
638
|
if (value === void 0 || value === null)
|
@@ -249,6 +647,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
249
647
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
250
648
|
};
|
251
649
|
function buildBaseUrl({
|
650
|
+
method,
|
252
651
|
endpoint,
|
253
652
|
path,
|
254
653
|
workspacesApiUrl,
|
@@ -256,7 +655,24 @@ function buildBaseUrl({
|
|
256
655
|
pathParams = {}
|
257
656
|
}) {
|
258
657
|
if (endpoint === "dataPlane") {
|
259
|
-
|
658
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
659
|
+
if (method.toUpperCase() === "PUT" && [
|
660
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
661
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
662
|
+
].includes(path)) {
|
663
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
664
|
+
switch (host) {
|
665
|
+
case "production":
|
666
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
667
|
+
break;
|
668
|
+
case "staging":
|
669
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
670
|
+
break;
|
671
|
+
case "dev":
|
672
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
673
|
+
break;
|
674
|
+
}
|
675
|
+
}
|
260
676
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
261
677
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
262
678
|
}
|
@@ -267,14 +683,27 @@ function hostHeader(url) {
|
|
267
683
|
const { groups } = pattern.exec(url) ?? {};
|
268
684
|
return groups?.host ? { Host: groups.host } : {};
|
269
685
|
}
|
686
|
+
async function parseBody(body, headers) {
|
687
|
+
if (!isDefined(body))
|
688
|
+
return void 0;
|
689
|
+
if (isBlob(body) || typeof body.text === "function") {
|
690
|
+
return body;
|
691
|
+
}
|
692
|
+
const { "Content-Type": contentType } = headers ?? {};
|
693
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
694
|
+
return JSON.stringify(body);
|
695
|
+
}
|
696
|
+
return body;
|
697
|
+
}
|
698
|
+
const defaultClientID = generateUUID();
|
270
699
|
async function fetch$1({
|
271
700
|
url: path,
|
272
701
|
method,
|
273
702
|
body,
|
274
|
-
headers,
|
703
|
+
headers: customHeaders,
|
275
704
|
pathParams,
|
276
705
|
queryParams,
|
277
|
-
|
706
|
+
fetch: fetch2,
|
278
707
|
apiKey,
|
279
708
|
endpoint,
|
280
709
|
apiUrl,
|
@@ -283,36 +712,45 @@ async function fetch$1({
|
|
283
712
|
signal,
|
284
713
|
clientID,
|
285
714
|
sessionID,
|
286
|
-
|
715
|
+
clientName,
|
716
|
+
xataAgentExtra,
|
717
|
+
fetchOptions = {},
|
718
|
+
rawResponse = false
|
287
719
|
}) {
|
288
|
-
|
720
|
+
pool.setFetch(fetch2);
|
721
|
+
return await trace(
|
289
722
|
`${method.toUpperCase()} ${path}`,
|
290
723
|
async ({ setAttributes }) => {
|
291
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
724
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
292
725
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
293
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
726
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
294
727
|
setAttributes({
|
295
728
|
[TraceAttributes.HTTP_URL]: url,
|
296
729
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
297
730
|
});
|
298
|
-
const
|
731
|
+
const xataAgent = compact([
|
732
|
+
["client", "TS_SDK"],
|
733
|
+
["version", VERSION],
|
734
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
735
|
+
...Object.entries(xataAgentExtra ?? {})
|
736
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
737
|
+
const headers = compactObject({
|
738
|
+
"Accept-Encoding": "identity",
|
739
|
+
"Content-Type": "application/json",
|
740
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
741
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
742
|
+
"X-Xata-Agent": xataAgent,
|
743
|
+
...customHeaders,
|
744
|
+
...hostHeader(fullUrl),
|
745
|
+
Authorization: `Bearer ${apiKey}`
|
746
|
+
});
|
747
|
+
const response = await pool.request(url, {
|
299
748
|
...fetchOptions,
|
300
749
|
method: method.toUpperCase(),
|
301
|
-
body:
|
302
|
-
headers
|
303
|
-
"Content-Type": "application/json",
|
304
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
305
|
-
"X-Xata-Client-ID": clientID ?? "",
|
306
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
307
|
-
...headers,
|
308
|
-
...hostHeader(fullUrl),
|
309
|
-
Authorization: `Bearer ${apiKey}`
|
310
|
-
},
|
750
|
+
body: await parseBody(body, headers),
|
751
|
+
headers,
|
311
752
|
signal
|
312
753
|
});
|
313
|
-
if (response.status === 204) {
|
314
|
-
return {};
|
315
|
-
}
|
316
754
|
const { host, protocol } = parseUrl(response.url);
|
317
755
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
318
756
|
setAttributes({
|
@@ -320,10 +758,20 @@ async function fetch$1({
|
|
320
758
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
321
759
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
322
760
|
[TraceAttributes.HTTP_HOST]: host,
|
323
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
761
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
762
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
324
763
|
});
|
764
|
+
const message = response.headers?.get("x-xata-message");
|
765
|
+
if (message)
|
766
|
+
console.warn(message);
|
767
|
+
if (response.status === 204) {
|
768
|
+
return {};
|
769
|
+
}
|
770
|
+
if (response.status === 429) {
|
771
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
772
|
+
}
|
325
773
|
try {
|
326
|
-
const jsonResponse = await response.json();
|
774
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
327
775
|
if (response.ok) {
|
328
776
|
return jsonResponse;
|
329
777
|
}
|
@@ -335,6 +783,59 @@ async function fetch$1({
|
|
335
783
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
336
784
|
);
|
337
785
|
}
|
786
|
+
function fetchSSERequest({
|
787
|
+
url: path,
|
788
|
+
method,
|
789
|
+
body,
|
790
|
+
headers: customHeaders,
|
791
|
+
pathParams,
|
792
|
+
queryParams,
|
793
|
+
fetch: fetch2,
|
794
|
+
apiKey,
|
795
|
+
endpoint,
|
796
|
+
apiUrl,
|
797
|
+
workspacesApiUrl,
|
798
|
+
onMessage,
|
799
|
+
onError,
|
800
|
+
onClose,
|
801
|
+
signal,
|
802
|
+
clientID,
|
803
|
+
sessionID,
|
804
|
+
clientName,
|
805
|
+
xataAgentExtra
|
806
|
+
}) {
|
807
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
808
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
809
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
810
|
+
void fetchEventSource(url, {
|
811
|
+
method,
|
812
|
+
body: JSON.stringify(body),
|
813
|
+
fetch: fetch2,
|
814
|
+
signal,
|
815
|
+
headers: {
|
816
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
817
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
818
|
+
"X-Xata-Agent": compact([
|
819
|
+
["client", "TS_SDK"],
|
820
|
+
["version", VERSION],
|
821
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
822
|
+
...Object.entries(xataAgentExtra ?? {})
|
823
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
824
|
+
...customHeaders,
|
825
|
+
Authorization: `Bearer ${apiKey}`,
|
826
|
+
"Content-Type": "application/json"
|
827
|
+
},
|
828
|
+
onmessage(ev) {
|
829
|
+
onMessage?.(JSON.parse(ev.data));
|
830
|
+
},
|
831
|
+
onerror(ev) {
|
832
|
+
onError?.(JSON.parse(ev.data));
|
833
|
+
},
|
834
|
+
onclose() {
|
835
|
+
onClose?.();
|
836
|
+
}
|
837
|
+
});
|
838
|
+
}
|
338
839
|
function parseUrl(url) {
|
339
840
|
try {
|
340
841
|
const { host, protocol } = new URL(url);
|
@@ -346,17 +847,26 @@ function parseUrl(url) {
|
|
346
847
|
|
347
848
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
348
849
|
|
349
|
-
const
|
850
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
851
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
852
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
853
|
+
method: "get",
|
854
|
+
...variables,
|
855
|
+
signal
|
856
|
+
});
|
857
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
858
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
859
|
+
method: "get",
|
860
|
+
...variables,
|
861
|
+
signal
|
862
|
+
});
|
863
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
350
864
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
351
865
|
url: "/dbs/{dbName}",
|
352
866
|
method: "get",
|
353
867
|
...variables,
|
354
868
|
signal
|
355
869
|
});
|
356
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
357
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
358
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
359
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
360
870
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
361
871
|
url: "/db/{dbBranchName}",
|
362
872
|
method: "get",
|
@@ -370,6 +880,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
370
880
|
...variables,
|
371
881
|
signal
|
372
882
|
});
|
883
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
884
|
+
url: "/db/{dbBranchName}/schema",
|
885
|
+
method: "get",
|
886
|
+
...variables,
|
887
|
+
signal
|
888
|
+
});
|
889
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
890
|
+
url: "/db/{dbBranchName}/copy",
|
891
|
+
method: "post",
|
892
|
+
...variables,
|
893
|
+
signal
|
894
|
+
});
|
373
895
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
374
896
|
url: "/db/{dbBranchName}/metadata",
|
375
897
|
method: "put",
|
@@ -395,7 +917,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
395
917
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
396
918
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
397
919
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
398
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
399
920
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
400
921
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
401
922
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -420,6 +941,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
420
941
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
421
942
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
422
943
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
944
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
423
945
|
const createTable = (variables, signal) => dataPlaneFetch({
|
424
946
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
425
947
|
method: "put",
|
@@ -462,7 +984,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
462
984
|
...variables,
|
463
985
|
signal
|
464
986
|
});
|
987
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
465
988
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
989
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
990
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
991
|
+
method: "get",
|
992
|
+
...variables,
|
993
|
+
signal
|
994
|
+
});
|
995
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
996
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
997
|
+
method: "put",
|
998
|
+
...variables,
|
999
|
+
signal
|
1000
|
+
});
|
1001
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
1002
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
1003
|
+
method: "delete",
|
1004
|
+
...variables,
|
1005
|
+
signal
|
1006
|
+
});
|
1007
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
1008
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1009
|
+
method: "get",
|
1010
|
+
...variables,
|
1011
|
+
signal
|
1012
|
+
});
|
1013
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
1014
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1015
|
+
method: "put",
|
1016
|
+
...variables,
|
1017
|
+
signal
|
1018
|
+
});
|
1019
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
1020
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1021
|
+
method: "delete",
|
1022
|
+
...variables,
|
1023
|
+
signal
|
1024
|
+
});
|
466
1025
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
467
1026
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
468
1027
|
method: "get",
|
@@ -492,21 +1051,45 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
492
1051
|
...variables,
|
493
1052
|
signal
|
494
1053
|
});
|
1054
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
1055
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
1056
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
1057
|
+
method: "post",
|
1058
|
+
...variables,
|
1059
|
+
signal
|
1060
|
+
});
|
1061
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
495
1062
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
496
1063
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
1064
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
1065
|
+
url: "/file/{fileId}",
|
1066
|
+
method: "get",
|
1067
|
+
...variables,
|
1068
|
+
signal
|
1069
|
+
});
|
1070
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1071
|
+
url: "/file/{fileId}",
|
1072
|
+
method: "put",
|
1073
|
+
...variables,
|
1074
|
+
signal
|
1075
|
+
});
|
1076
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
1077
|
+
url: "/db/{dbBranchName}/sql",
|
1078
|
+
method: "post",
|
1079
|
+
...variables,
|
1080
|
+
signal
|
1081
|
+
});
|
497
1082
|
const operationsByTag$2 = {
|
498
|
-
database: {
|
499
|
-
dEPRECATEDgetDatabaseList,
|
500
|
-
dEPRECATEDcreateDatabase,
|
501
|
-
dEPRECATEDdeleteDatabase,
|
502
|
-
dEPRECATEDgetDatabaseMetadata,
|
503
|
-
dEPRECATEDupdateDatabaseMetadata
|
504
|
-
},
|
505
1083
|
branch: {
|
1084
|
+
applyMigration,
|
1085
|
+
pgRollStatus,
|
1086
|
+
pgRollJobStatus,
|
1087
|
+
pgRollMigrationHistory,
|
506
1088
|
getBranchList,
|
507
1089
|
getBranchDetails,
|
508
1090
|
createBranch,
|
509
1091
|
deleteBranch,
|
1092
|
+
copyBranch,
|
510
1093
|
updateBranchMetadata,
|
511
1094
|
getBranchMetadata,
|
512
1095
|
getBranchStats,
|
@@ -516,6 +1099,7 @@ const operationsByTag$2 = {
|
|
516
1099
|
resolveBranch
|
517
1100
|
},
|
518
1101
|
migrations: {
|
1102
|
+
getSchema,
|
519
1103
|
getBranchMigrationHistory,
|
520
1104
|
getBranchMigrationPlan,
|
521
1105
|
executeBranchMigrationPlan,
|
@@ -524,17 +1108,8 @@ const operationsByTag$2 = {
|
|
524
1108
|
compareBranchSchemas,
|
525
1109
|
updateBranchSchema,
|
526
1110
|
previewBranchSchemaEdit,
|
527
|
-
applyBranchSchemaEdit
|
528
|
-
|
529
|
-
records: {
|
530
|
-
branchTransaction,
|
531
|
-
insertRecord,
|
532
|
-
getRecord,
|
533
|
-
insertRecordWithID,
|
534
|
-
updateRecordWithID,
|
535
|
-
upsertRecordWithID,
|
536
|
-
deleteRecord,
|
537
|
-
bulkInsertTableRecords
|
1111
|
+
applyBranchSchemaEdit,
|
1112
|
+
pushBranchMigrations
|
538
1113
|
},
|
539
1114
|
migrationRequests: {
|
540
1115
|
queryMigrationRequests,
|
@@ -558,11 +1133,34 @@ const operationsByTag$2 = {
|
|
558
1133
|
updateColumn,
|
559
1134
|
deleteColumn
|
560
1135
|
},
|
561
|
-
|
1136
|
+
records: {
|
1137
|
+
branchTransaction,
|
1138
|
+
insertRecord,
|
1139
|
+
getRecord,
|
1140
|
+
insertRecordWithID,
|
1141
|
+
updateRecordWithID,
|
1142
|
+
upsertRecordWithID,
|
1143
|
+
deleteRecord,
|
1144
|
+
bulkInsertTableRecords
|
1145
|
+
},
|
1146
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1147
|
+
searchAndFilter: {
|
1148
|
+
queryTable,
|
1149
|
+
searchBranch,
|
1150
|
+
searchTable,
|
1151
|
+
vectorSearchTable,
|
1152
|
+
askTable,
|
1153
|
+
askTableSession,
|
1154
|
+
summarizeTable,
|
1155
|
+
aggregateTable
|
1156
|
+
},
|
1157
|
+
sql: { sqlQuery }
|
562
1158
|
};
|
563
1159
|
|
564
1160
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
565
1161
|
|
1162
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1163
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
566
1164
|
const getUser = (variables, signal) => controlPlaneFetch({
|
567
1165
|
url: "/user",
|
568
1166
|
method: "get",
|
@@ -587,18 +1185,43 @@ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
|
587
1185
|
...variables,
|
588
1186
|
signal
|
589
1187
|
});
|
590
|
-
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
591
|
-
url: "/user/keys/{keyName}",
|
592
|
-
method: "post",
|
1188
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1189
|
+
url: "/user/keys/{keyName}",
|
1190
|
+
method: "post",
|
1191
|
+
...variables,
|
1192
|
+
signal
|
1193
|
+
});
|
1194
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1195
|
+
url: "/user/keys/{keyName}",
|
1196
|
+
method: "delete",
|
1197
|
+
...variables,
|
1198
|
+
signal
|
1199
|
+
});
|
1200
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1201
|
+
url: "/user/oauth/clients",
|
1202
|
+
method: "get",
|
1203
|
+
...variables,
|
1204
|
+
signal
|
1205
|
+
});
|
1206
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1207
|
+
url: "/user/oauth/clients/{clientId}",
|
1208
|
+
method: "delete",
|
1209
|
+
...variables,
|
1210
|
+
signal
|
1211
|
+
});
|
1212
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1213
|
+
url: "/user/oauth/tokens",
|
1214
|
+
method: "get",
|
593
1215
|
...variables,
|
594
1216
|
signal
|
595
1217
|
});
|
596
|
-
const
|
597
|
-
url: "/user/
|
1218
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1219
|
+
url: "/user/oauth/tokens/{token}",
|
598
1220
|
method: "delete",
|
599
1221
|
...variables,
|
600
1222
|
signal
|
601
1223
|
});
|
1224
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
602
1225
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
603
1226
|
url: "/workspaces",
|
604
1227
|
method: "get",
|
@@ -642,6 +1265,15 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
642
1265
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
643
1266
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
644
1267
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1268
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1269
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1270
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1271
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1272
|
+
method: "get",
|
1273
|
+
...variables,
|
1274
|
+
signal
|
1275
|
+
});
|
1276
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
645
1277
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
646
1278
|
url: "/workspaces/{workspaceId}/dbs",
|
647
1279
|
method: "get",
|
@@ -657,6 +1289,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
657
1289
|
});
|
658
1290
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
659
1291
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1292
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1293
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1294
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1295
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
660
1296
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
661
1297
|
url: "/workspaces/{workspaceId}/regions",
|
662
1298
|
method: "get",
|
@@ -664,6 +1300,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
664
1300
|
signal
|
665
1301
|
});
|
666
1302
|
const operationsByTag$1 = {
|
1303
|
+
oAuth: {
|
1304
|
+
getAuthorizationCode,
|
1305
|
+
grantAuthorizationCode,
|
1306
|
+
getUserOAuthClients,
|
1307
|
+
deleteUserOAuthClient,
|
1308
|
+
getUserOAuthAccessTokens,
|
1309
|
+
deleteOAuthAccessToken,
|
1310
|
+
updateOAuthAccessToken
|
1311
|
+
},
|
667
1312
|
users: { getUser, updateUser, deleteUser },
|
668
1313
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
669
1314
|
workspaces: {
|
@@ -683,62 +1328,23 @@ const operationsByTag$1 = {
|
|
683
1328
|
acceptWorkspaceMemberInvite,
|
684
1329
|
resendWorkspaceMemberInvite
|
685
1330
|
},
|
1331
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
686
1332
|
databases: {
|
687
1333
|
getDatabaseList,
|
688
1334
|
createDatabase,
|
689
1335
|
deleteDatabase,
|
690
1336
|
getDatabaseMetadata,
|
691
1337
|
updateDatabaseMetadata,
|
1338
|
+
renameDatabase,
|
1339
|
+
getDatabaseGithubSettings,
|
1340
|
+
updateDatabaseGithubSettings,
|
1341
|
+
deleteDatabaseGithubSettings,
|
692
1342
|
listRegions
|
693
1343
|
}
|
694
1344
|
};
|
695
1345
|
|
696
1346
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
697
1347
|
|
698
|
-
function getHostUrl(provider, type) {
|
699
|
-
if (isHostProviderAlias(provider)) {
|
700
|
-
return providers[provider][type];
|
701
|
-
} else if (isHostProviderBuilder(provider)) {
|
702
|
-
return provider[type];
|
703
|
-
}
|
704
|
-
throw new Error("Invalid API provider");
|
705
|
-
}
|
706
|
-
const providers = {
|
707
|
-
production: {
|
708
|
-
main: "https://api.xata.io",
|
709
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
710
|
-
},
|
711
|
-
staging: {
|
712
|
-
main: "https://staging.xatabase.co",
|
713
|
-
workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
|
714
|
-
}
|
715
|
-
};
|
716
|
-
function isHostProviderAlias(alias) {
|
717
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
718
|
-
}
|
719
|
-
function isHostProviderBuilder(builder) {
|
720
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
721
|
-
}
|
722
|
-
function parseProviderString(provider = "production") {
|
723
|
-
if (isHostProviderAlias(provider)) {
|
724
|
-
return provider;
|
725
|
-
}
|
726
|
-
const [main, workspaces] = provider.split(",");
|
727
|
-
if (!main || !workspaces)
|
728
|
-
return null;
|
729
|
-
return { main, workspaces };
|
730
|
-
}
|
731
|
-
function parseWorkspacesUrlParts(url) {
|
732
|
-
if (!isString(url))
|
733
|
-
return null;
|
734
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
|
735
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
|
736
|
-
const match = url.match(regex) || url.match(regexStaging);
|
737
|
-
if (!match)
|
738
|
-
return null;
|
739
|
-
return { workspace: match[1], region: match[2] ?? "eu-west-1" };
|
740
|
-
}
|
741
|
-
|
742
1348
|
var __accessCheck$7 = (obj, member, msg) => {
|
743
1349
|
if (!member.has(obj))
|
744
1350
|
throw TypeError("Cannot " + msg);
|
@@ -765,15 +1371,19 @@ class XataApiClient {
|
|
765
1371
|
const provider = options.host ?? "production";
|
766
1372
|
const apiKey = options.apiKey ?? getAPIKey();
|
767
1373
|
const trace = options.trace ?? defaultTrace;
|
1374
|
+
const clientID = generateUUID();
|
768
1375
|
if (!apiKey) {
|
769
1376
|
throw new Error("Could not resolve a valid apiKey");
|
770
1377
|
}
|
771
1378
|
__privateSet$7(this, _extraProps, {
|
772
1379
|
apiUrl: getHostUrl(provider, "main"),
|
773
1380
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
774
|
-
|
1381
|
+
fetch: getFetchImplementation(options.fetch),
|
775
1382
|
apiKey,
|
776
|
-
trace
|
1383
|
+
trace,
|
1384
|
+
clientName: options.clientName,
|
1385
|
+
xataAgentExtra: options.xataAgentExtra,
|
1386
|
+
clientID
|
777
1387
|
});
|
778
1388
|
}
|
779
1389
|
get user() {
|
@@ -826,6 +1436,11 @@ class XataApiClient {
|
|
826
1436
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
827
1437
|
return __privateGet$7(this, _namespaces).records;
|
828
1438
|
}
|
1439
|
+
get files() {
|
1440
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1441
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1442
|
+
return __privateGet$7(this, _namespaces).files;
|
1443
|
+
}
|
829
1444
|
get searchAndFilter() {
|
830
1445
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
831
1446
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1034,6 +1649,20 @@ class BranchApi {
|
|
1034
1649
|
...this.extraProps
|
1035
1650
|
});
|
1036
1651
|
}
|
1652
|
+
copyBranch({
|
1653
|
+
workspace,
|
1654
|
+
region,
|
1655
|
+
database,
|
1656
|
+
branch,
|
1657
|
+
destinationBranch,
|
1658
|
+
limit
|
1659
|
+
}) {
|
1660
|
+
return operationsByTag.branch.copyBranch({
|
1661
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1662
|
+
body: { destinationBranch, limit },
|
1663
|
+
...this.extraProps
|
1664
|
+
});
|
1665
|
+
}
|
1037
1666
|
updateBranchMetadata({
|
1038
1667
|
workspace,
|
1039
1668
|
region,
|
@@ -1389,6 +2018,164 @@ class RecordsApi {
|
|
1389
2018
|
});
|
1390
2019
|
}
|
1391
2020
|
}
|
2021
|
+
class FilesApi {
|
2022
|
+
constructor(extraProps) {
|
2023
|
+
this.extraProps = extraProps;
|
2024
|
+
}
|
2025
|
+
getFileItem({
|
2026
|
+
workspace,
|
2027
|
+
region,
|
2028
|
+
database,
|
2029
|
+
branch,
|
2030
|
+
table,
|
2031
|
+
record,
|
2032
|
+
column,
|
2033
|
+
fileId
|
2034
|
+
}) {
|
2035
|
+
return operationsByTag.files.getFileItem({
|
2036
|
+
pathParams: {
|
2037
|
+
workspace,
|
2038
|
+
region,
|
2039
|
+
dbBranchName: `${database}:${branch}`,
|
2040
|
+
tableName: table,
|
2041
|
+
recordId: record,
|
2042
|
+
columnName: column,
|
2043
|
+
fileId
|
2044
|
+
},
|
2045
|
+
...this.extraProps
|
2046
|
+
});
|
2047
|
+
}
|
2048
|
+
putFileItem({
|
2049
|
+
workspace,
|
2050
|
+
region,
|
2051
|
+
database,
|
2052
|
+
branch,
|
2053
|
+
table,
|
2054
|
+
record,
|
2055
|
+
column,
|
2056
|
+
fileId,
|
2057
|
+
file
|
2058
|
+
}) {
|
2059
|
+
return operationsByTag.files.putFileItem({
|
2060
|
+
pathParams: {
|
2061
|
+
workspace,
|
2062
|
+
region,
|
2063
|
+
dbBranchName: `${database}:${branch}`,
|
2064
|
+
tableName: table,
|
2065
|
+
recordId: record,
|
2066
|
+
columnName: column,
|
2067
|
+
fileId
|
2068
|
+
},
|
2069
|
+
// @ts-ignore
|
2070
|
+
body: file,
|
2071
|
+
...this.extraProps
|
2072
|
+
});
|
2073
|
+
}
|
2074
|
+
deleteFileItem({
|
2075
|
+
workspace,
|
2076
|
+
region,
|
2077
|
+
database,
|
2078
|
+
branch,
|
2079
|
+
table,
|
2080
|
+
record,
|
2081
|
+
column,
|
2082
|
+
fileId
|
2083
|
+
}) {
|
2084
|
+
return operationsByTag.files.deleteFileItem({
|
2085
|
+
pathParams: {
|
2086
|
+
workspace,
|
2087
|
+
region,
|
2088
|
+
dbBranchName: `${database}:${branch}`,
|
2089
|
+
tableName: table,
|
2090
|
+
recordId: record,
|
2091
|
+
columnName: column,
|
2092
|
+
fileId
|
2093
|
+
},
|
2094
|
+
...this.extraProps
|
2095
|
+
});
|
2096
|
+
}
|
2097
|
+
getFile({
|
2098
|
+
workspace,
|
2099
|
+
region,
|
2100
|
+
database,
|
2101
|
+
branch,
|
2102
|
+
table,
|
2103
|
+
record,
|
2104
|
+
column
|
2105
|
+
}) {
|
2106
|
+
return operationsByTag.files.getFile({
|
2107
|
+
pathParams: {
|
2108
|
+
workspace,
|
2109
|
+
region,
|
2110
|
+
dbBranchName: `${database}:${branch}`,
|
2111
|
+
tableName: table,
|
2112
|
+
recordId: record,
|
2113
|
+
columnName: column
|
2114
|
+
},
|
2115
|
+
...this.extraProps
|
2116
|
+
});
|
2117
|
+
}
|
2118
|
+
putFile({
|
2119
|
+
workspace,
|
2120
|
+
region,
|
2121
|
+
database,
|
2122
|
+
branch,
|
2123
|
+
table,
|
2124
|
+
record,
|
2125
|
+
column,
|
2126
|
+
file
|
2127
|
+
}) {
|
2128
|
+
return operationsByTag.files.putFile({
|
2129
|
+
pathParams: {
|
2130
|
+
workspace,
|
2131
|
+
region,
|
2132
|
+
dbBranchName: `${database}:${branch}`,
|
2133
|
+
tableName: table,
|
2134
|
+
recordId: record,
|
2135
|
+
columnName: column
|
2136
|
+
},
|
2137
|
+
body: file,
|
2138
|
+
...this.extraProps
|
2139
|
+
});
|
2140
|
+
}
|
2141
|
+
deleteFile({
|
2142
|
+
workspace,
|
2143
|
+
region,
|
2144
|
+
database,
|
2145
|
+
branch,
|
2146
|
+
table,
|
2147
|
+
record,
|
2148
|
+
column
|
2149
|
+
}) {
|
2150
|
+
return operationsByTag.files.deleteFile({
|
2151
|
+
pathParams: {
|
2152
|
+
workspace,
|
2153
|
+
region,
|
2154
|
+
dbBranchName: `${database}:${branch}`,
|
2155
|
+
tableName: table,
|
2156
|
+
recordId: record,
|
2157
|
+
columnName: column
|
2158
|
+
},
|
2159
|
+
...this.extraProps
|
2160
|
+
});
|
2161
|
+
}
|
2162
|
+
fileAccess({
|
2163
|
+
workspace,
|
2164
|
+
region,
|
2165
|
+
fileId,
|
2166
|
+
verify
|
2167
|
+
}) {
|
2168
|
+
return operationsByTag.files.fileAccess({
|
2169
|
+
pathParams: {
|
2170
|
+
workspace,
|
2171
|
+
region,
|
2172
|
+
fileId
|
2173
|
+
},
|
2174
|
+
queryParams: { verify },
|
2175
|
+
...this.extraProps
|
2176
|
+
});
|
2177
|
+
}
|
2178
|
+
}
|
1392
2179
|
class SearchAndFilterApi {
|
1393
2180
|
constructor(extraProps) {
|
1394
2181
|
this.extraProps = extraProps;
|
@@ -1448,6 +2235,53 @@ class SearchAndFilterApi {
|
|
1448
2235
|
...this.extraProps
|
1449
2236
|
});
|
1450
2237
|
}
|
2238
|
+
vectorSearchTable({
|
2239
|
+
workspace,
|
2240
|
+
region,
|
2241
|
+
database,
|
2242
|
+
branch,
|
2243
|
+
table,
|
2244
|
+
queryVector,
|
2245
|
+
column,
|
2246
|
+
similarityFunction,
|
2247
|
+
size,
|
2248
|
+
filter
|
2249
|
+
}) {
|
2250
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2251
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2252
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2253
|
+
...this.extraProps
|
2254
|
+
});
|
2255
|
+
}
|
2256
|
+
askTable({
|
2257
|
+
workspace,
|
2258
|
+
region,
|
2259
|
+
database,
|
2260
|
+
branch,
|
2261
|
+
table,
|
2262
|
+
options
|
2263
|
+
}) {
|
2264
|
+
return operationsByTag.searchAndFilter.askTable({
|
2265
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2266
|
+
body: { ...options },
|
2267
|
+
...this.extraProps
|
2268
|
+
});
|
2269
|
+
}
|
2270
|
+
askTableSession({
|
2271
|
+
workspace,
|
2272
|
+
region,
|
2273
|
+
database,
|
2274
|
+
branch,
|
2275
|
+
table,
|
2276
|
+
sessionId,
|
2277
|
+
message
|
2278
|
+
}) {
|
2279
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2280
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2281
|
+
body: { message },
|
2282
|
+
...this.extraProps
|
2283
|
+
});
|
2284
|
+
}
|
1451
2285
|
summarizeTable({
|
1452
2286
|
workspace,
|
1453
2287
|
region,
|
@@ -1648,11 +2482,13 @@ class MigrationsApi {
|
|
1648
2482
|
region,
|
1649
2483
|
database,
|
1650
2484
|
branch,
|
1651
|
-
schema
|
2485
|
+
schema,
|
2486
|
+
schemaOperations,
|
2487
|
+
branchOperations
|
1652
2488
|
}) {
|
1653
2489
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1654
2490
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1655
|
-
body: { schema },
|
2491
|
+
body: { schema, schemaOperations, branchOperations },
|
1656
2492
|
...this.extraProps
|
1657
2493
|
});
|
1658
2494
|
}
|
@@ -1662,11 +2498,12 @@ class MigrationsApi {
|
|
1662
2498
|
database,
|
1663
2499
|
branch,
|
1664
2500
|
compare,
|
1665
|
-
|
2501
|
+
sourceBranchOperations,
|
2502
|
+
targetBranchOperations
|
1666
2503
|
}) {
|
1667
2504
|
return operationsByTag.migrations.compareBranchSchemas({
|
1668
2505
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1669
|
-
body: {
|
2506
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1670
2507
|
...this.extraProps
|
1671
2508
|
});
|
1672
2509
|
}
|
@@ -1709,6 +2546,19 @@ class MigrationsApi {
|
|
1709
2546
|
...this.extraProps
|
1710
2547
|
});
|
1711
2548
|
}
|
2549
|
+
pushBranchMigrations({
|
2550
|
+
workspace,
|
2551
|
+
region,
|
2552
|
+
database,
|
2553
|
+
branch,
|
2554
|
+
migrations
|
2555
|
+
}) {
|
2556
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2557
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2558
|
+
body: { migrations },
|
2559
|
+
...this.extraProps
|
2560
|
+
});
|
2561
|
+
}
|
1712
2562
|
}
|
1713
2563
|
class DatabaseApi {
|
1714
2564
|
constructor(extraProps) {
|
@@ -1723,11 +2573,13 @@ class DatabaseApi {
|
|
1723
2573
|
createDatabase({
|
1724
2574
|
workspace,
|
1725
2575
|
database,
|
1726
|
-
data
|
2576
|
+
data,
|
2577
|
+
headers
|
1727
2578
|
}) {
|
1728
2579
|
return operationsByTag.databases.createDatabase({
|
1729
2580
|
pathParams: { workspaceId: workspace, dbName: database },
|
1730
2581
|
body: data,
|
2582
|
+
headers,
|
1731
2583
|
...this.extraProps
|
1732
2584
|
});
|
1733
2585
|
}
|
@@ -1760,36 +2612,252 @@ class DatabaseApi {
|
|
1760
2612
|
...this.extraProps
|
1761
2613
|
});
|
1762
2614
|
}
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
2615
|
+
renameDatabase({
|
2616
|
+
workspace,
|
2617
|
+
database,
|
2618
|
+
newName
|
2619
|
+
}) {
|
2620
|
+
return operationsByTag.databases.renameDatabase({
|
2621
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2622
|
+
body: { newName },
|
2623
|
+
...this.extraProps
|
2624
|
+
});
|
2625
|
+
}
|
2626
|
+
getDatabaseGithubSettings({
|
2627
|
+
workspace,
|
2628
|
+
database
|
2629
|
+
}) {
|
2630
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2631
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2632
|
+
...this.extraProps
|
2633
|
+
});
|
2634
|
+
}
|
2635
|
+
updateDatabaseGithubSettings({
|
2636
|
+
workspace,
|
2637
|
+
database,
|
2638
|
+
settings
|
2639
|
+
}) {
|
2640
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2641
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2642
|
+
body: settings,
|
2643
|
+
...this.extraProps
|
2644
|
+
});
|
2645
|
+
}
|
2646
|
+
deleteDatabaseGithubSettings({
|
2647
|
+
workspace,
|
2648
|
+
database
|
2649
|
+
}) {
|
2650
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2651
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2652
|
+
...this.extraProps
|
2653
|
+
});
|
2654
|
+
}
|
2655
|
+
listRegions({ workspace }) {
|
2656
|
+
return operationsByTag.databases.listRegions({
|
2657
|
+
pathParams: { workspaceId: workspace },
|
2658
|
+
...this.extraProps
|
2659
|
+
});
|
2660
|
+
}
|
2661
|
+
}
|
2662
|
+
|
2663
|
+
class XataApiPlugin {
|
2664
|
+
build(options) {
|
2665
|
+
return new XataApiClient(options);
|
2666
|
+
}
|
2667
|
+
}
|
2668
|
+
|
2669
|
+
class XataPlugin {
|
2670
|
+
}
|
2671
|
+
|
2672
|
+
function buildTransformString(transformations) {
|
2673
|
+
return transformations.flatMap(
|
2674
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2675
|
+
if (key === "trim") {
|
2676
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2677
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2678
|
+
}
|
2679
|
+
if (key === "gravity" && typeof value === "object") {
|
2680
|
+
const { x = 0.5, y = 0.5 } = value;
|
2681
|
+
return `${key}=${[x, y].join("x")}`;
|
2682
|
+
}
|
2683
|
+
return `${key}=${value}`;
|
2684
|
+
})
|
2685
|
+
).join(",");
|
2686
|
+
}
|
2687
|
+
function transformImage(url, ...transformations) {
|
2688
|
+
if (!isDefined(url))
|
2689
|
+
return void 0;
|
2690
|
+
const newTransformations = buildTransformString(transformations);
|
2691
|
+
const { hostname, pathname, search } = new URL(url);
|
2692
|
+
const pathParts = pathname.split("/");
|
2693
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2694
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2695
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2696
|
+
const path = pathParts.join("/");
|
2697
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2698
|
+
}
|
2699
|
+
|
2700
|
+
class XataFile {
|
2701
|
+
constructor(file) {
|
2702
|
+
this.id = file.id;
|
2703
|
+
this.name = file.name;
|
2704
|
+
this.mediaType = file.mediaType;
|
2705
|
+
this.base64Content = file.base64Content;
|
2706
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2707
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2708
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2709
|
+
this.size = file.size;
|
2710
|
+
this.version = file.version;
|
2711
|
+
this.url = file.url;
|
2712
|
+
this.signedUrl = file.signedUrl;
|
2713
|
+
this.uploadUrl = file.uploadUrl;
|
2714
|
+
this.attributes = file.attributes;
|
2715
|
+
}
|
2716
|
+
static fromBuffer(buffer, options = {}) {
|
2717
|
+
const base64Content = buffer.toString("base64");
|
2718
|
+
return new XataFile({ ...options, base64Content });
|
2719
|
+
}
|
2720
|
+
toBuffer() {
|
2721
|
+
if (!this.base64Content) {
|
2722
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2723
|
+
}
|
2724
|
+
return Buffer.from(this.base64Content, "base64");
|
2725
|
+
}
|
2726
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2727
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2728
|
+
return this.fromUint8Array(uint8Array, options);
|
2729
|
+
}
|
2730
|
+
toArrayBuffer() {
|
2731
|
+
if (!this.base64Content) {
|
2732
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2733
|
+
}
|
2734
|
+
const binary = atob(this.base64Content);
|
2735
|
+
return new ArrayBuffer(binary.length);
|
2736
|
+
}
|
2737
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2738
|
+
let binary = "";
|
2739
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2740
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2741
|
+
}
|
2742
|
+
const base64Content = btoa(binary);
|
2743
|
+
return new XataFile({ ...options, base64Content });
|
2744
|
+
}
|
2745
|
+
toUint8Array() {
|
2746
|
+
if (!this.base64Content) {
|
2747
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2748
|
+
}
|
2749
|
+
const binary = atob(this.base64Content);
|
2750
|
+
const uint8Array = new Uint8Array(binary.length);
|
2751
|
+
for (let i = 0; i < binary.length; i++) {
|
2752
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2753
|
+
}
|
2754
|
+
return uint8Array;
|
2755
|
+
}
|
2756
|
+
static async fromBlob(file, options = {}) {
|
2757
|
+
const name = options.name ?? file.name;
|
2758
|
+
const mediaType = file.type;
|
2759
|
+
const arrayBuffer = await file.arrayBuffer();
|
2760
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2761
|
+
}
|
2762
|
+
toBlob() {
|
2763
|
+
if (!this.base64Content) {
|
2764
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2765
|
+
}
|
2766
|
+
const binary = atob(this.base64Content);
|
2767
|
+
const uint8Array = new Uint8Array(binary.length);
|
2768
|
+
for (let i = 0; i < binary.length; i++) {
|
2769
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2770
|
+
}
|
2771
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2772
|
+
}
|
2773
|
+
static fromString(string, options = {}) {
|
2774
|
+
const base64Content = btoa(string);
|
2775
|
+
return new XataFile({ ...options, base64Content });
|
1768
2776
|
}
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
2777
|
+
toString() {
|
2778
|
+
if (!this.base64Content) {
|
2779
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2780
|
+
}
|
2781
|
+
return atob(this.base64Content);
|
2782
|
+
}
|
2783
|
+
static fromBase64(base64Content, options = {}) {
|
2784
|
+
return new XataFile({ ...options, base64Content });
|
2785
|
+
}
|
2786
|
+
toBase64() {
|
2787
|
+
if (!this.base64Content) {
|
2788
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2789
|
+
}
|
2790
|
+
return this.base64Content;
|
2791
|
+
}
|
2792
|
+
transform(...options) {
|
2793
|
+
return {
|
2794
|
+
url: transformImage(this.url, ...options),
|
2795
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2796
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2797
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2798
|
+
};
|
1775
2799
|
}
|
1776
2800
|
}
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
2801
|
+
const parseInputFileEntry = async (entry) => {
|
2802
|
+
if (!isDefined(entry))
|
2803
|
+
return null;
|
2804
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2805
|
+
return compactObject({
|
2806
|
+
id,
|
2807
|
+
// Name cannot be an empty string in our API
|
2808
|
+
name: name ? name : void 0,
|
2809
|
+
mediaType,
|
2810
|
+
base64Content,
|
2811
|
+
enablePublicUrl,
|
2812
|
+
signedUrlTimeout,
|
2813
|
+
uploadUrlTimeout
|
1785
2814
|
});
|
1786
|
-
}
|
2815
|
+
};
|
1787
2816
|
|
1788
2817
|
function cleanFilter(filter) {
|
1789
|
-
if (!filter)
|
2818
|
+
if (!isDefined(filter))
|
1790
2819
|
return void 0;
|
1791
|
-
|
1792
|
-
|
2820
|
+
if (!isObject(filter))
|
2821
|
+
return filter;
|
2822
|
+
const values = Object.fromEntries(
|
2823
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2824
|
+
if (!isDefined(value))
|
2825
|
+
return acc;
|
2826
|
+
if (Array.isArray(value)) {
|
2827
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2828
|
+
if (clean.length === 0)
|
2829
|
+
return acc;
|
2830
|
+
return [...acc, [key, clean]];
|
2831
|
+
}
|
2832
|
+
if (isObject(value)) {
|
2833
|
+
const clean = cleanFilter(value);
|
2834
|
+
if (!isDefined(clean))
|
2835
|
+
return acc;
|
2836
|
+
return [...acc, [key, clean]];
|
2837
|
+
}
|
2838
|
+
return [...acc, [key, value]];
|
2839
|
+
}, [])
|
2840
|
+
);
|
2841
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2842
|
+
}
|
2843
|
+
|
2844
|
+
function stringifyJson(value) {
|
2845
|
+
if (!isDefined(value))
|
2846
|
+
return value;
|
2847
|
+
if (isString(value))
|
2848
|
+
return value;
|
2849
|
+
try {
|
2850
|
+
return JSON.stringify(value);
|
2851
|
+
} catch (e) {
|
2852
|
+
return value;
|
2853
|
+
}
|
2854
|
+
}
|
2855
|
+
function parseJson(value) {
|
2856
|
+
try {
|
2857
|
+
return JSON.parse(value);
|
2858
|
+
} catch (e) {
|
2859
|
+
return value;
|
2860
|
+
}
|
1793
2861
|
}
|
1794
2862
|
|
1795
2863
|
var __accessCheck$6 = (obj, member, msg) => {
|
@@ -1818,31 +2886,59 @@ class Page {
|
|
1818
2886
|
this.meta = meta;
|
1819
2887
|
this.records = new RecordArray(this, records);
|
1820
2888
|
}
|
2889
|
+
/**
|
2890
|
+
* Retrieves the next page of results.
|
2891
|
+
* @param size Maximum number of results to be retrieved.
|
2892
|
+
* @param offset Number of results to skip when retrieving the results.
|
2893
|
+
* @returns The next page or results.
|
2894
|
+
*/
|
1821
2895
|
async nextPage(size, offset) {
|
1822
2896
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1823
2897
|
}
|
2898
|
+
/**
|
2899
|
+
* Retrieves the previous page of results.
|
2900
|
+
* @param size Maximum number of results to be retrieved.
|
2901
|
+
* @param offset Number of results to skip when retrieving the results.
|
2902
|
+
* @returns The previous page or results.
|
2903
|
+
*/
|
1824
2904
|
async previousPage(size, offset) {
|
1825
2905
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1826
2906
|
}
|
2907
|
+
/**
|
2908
|
+
* Retrieves the start page of results.
|
2909
|
+
* @param size Maximum number of results to be retrieved.
|
2910
|
+
* @param offset Number of results to skip when retrieving the results.
|
2911
|
+
* @returns The start page or results.
|
2912
|
+
*/
|
1827
2913
|
async startPage(size, offset) {
|
1828
2914
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1829
2915
|
}
|
2916
|
+
/**
|
2917
|
+
* Retrieves the end page of results.
|
2918
|
+
* @param size Maximum number of results to be retrieved.
|
2919
|
+
* @param offset Number of results to skip when retrieving the results.
|
2920
|
+
* @returns The end page or results.
|
2921
|
+
*/
|
1830
2922
|
async endPage(size, offset) {
|
1831
2923
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1832
2924
|
}
|
2925
|
+
/**
|
2926
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2927
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2928
|
+
*/
|
1833
2929
|
hasNextPage() {
|
1834
2930
|
return this.meta.page.more;
|
1835
2931
|
}
|
1836
2932
|
}
|
1837
2933
|
_query = new WeakMap();
|
1838
|
-
const PAGINATION_MAX_SIZE =
|
2934
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1839
2935
|
const PAGINATION_DEFAULT_SIZE = 20;
|
1840
|
-
const PAGINATION_MAX_OFFSET =
|
2936
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
1841
2937
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1842
2938
|
function isCursorPaginationOptions(options) {
|
1843
2939
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1844
2940
|
}
|
1845
|
-
const _RecordArray = class extends Array {
|
2941
|
+
const _RecordArray = class _RecordArray extends Array {
|
1846
2942
|
constructor(...args) {
|
1847
2943
|
super(..._RecordArray.parseConstructorParams(...args));
|
1848
2944
|
__privateAdd$6(this, _page, void 0);
|
@@ -1861,31 +2957,60 @@ const _RecordArray = class extends Array {
|
|
1861
2957
|
toArray() {
|
1862
2958
|
return new Array(...this);
|
1863
2959
|
}
|
2960
|
+
toSerializable() {
|
2961
|
+
return JSON.parse(this.toString());
|
2962
|
+
}
|
2963
|
+
toString() {
|
2964
|
+
return JSON.stringify(this.toArray());
|
2965
|
+
}
|
1864
2966
|
map(callbackfn, thisArg) {
|
1865
2967
|
return this.toArray().map(callbackfn, thisArg);
|
1866
2968
|
}
|
2969
|
+
/**
|
2970
|
+
* Retrieve next page of records
|
2971
|
+
*
|
2972
|
+
* @returns A new array of objects
|
2973
|
+
*/
|
1867
2974
|
async nextPage(size, offset) {
|
1868
2975
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1869
2976
|
return new _RecordArray(newPage);
|
1870
2977
|
}
|
2978
|
+
/**
|
2979
|
+
* Retrieve previous page of records
|
2980
|
+
*
|
2981
|
+
* @returns A new array of objects
|
2982
|
+
*/
|
1871
2983
|
async previousPage(size, offset) {
|
1872
2984
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1873
2985
|
return new _RecordArray(newPage);
|
1874
2986
|
}
|
2987
|
+
/**
|
2988
|
+
* Retrieve start page of records
|
2989
|
+
*
|
2990
|
+
* @returns A new array of objects
|
2991
|
+
*/
|
1875
2992
|
async startPage(size, offset) {
|
1876
2993
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1877
2994
|
return new _RecordArray(newPage);
|
1878
2995
|
}
|
2996
|
+
/**
|
2997
|
+
* Retrieve end page of records
|
2998
|
+
*
|
2999
|
+
* @returns A new array of objects
|
3000
|
+
*/
|
1879
3001
|
async endPage(size, offset) {
|
1880
3002
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1881
3003
|
return new _RecordArray(newPage);
|
1882
3004
|
}
|
3005
|
+
/**
|
3006
|
+
* @returns Boolean indicating if there is a next page
|
3007
|
+
*/
|
1883
3008
|
hasNextPage() {
|
1884
3009
|
return __privateGet$6(this, _page).meta.page.more;
|
1885
3010
|
}
|
1886
3011
|
};
|
1887
|
-
let RecordArray = _RecordArray;
|
1888
3012
|
_page = new WeakMap();
|
3013
|
+
let RecordArray = _RecordArray;
|
1889
3014
|
|
1890
3015
|
var __accessCheck$5 = (obj, member, msg) => {
|
1891
3016
|
if (!member.has(obj))
|
@@ -1910,13 +3035,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
1910
3035
|
return method;
|
1911
3036
|
};
|
1912
3037
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1913
|
-
const _Query = class {
|
3038
|
+
const _Query = class _Query {
|
1914
3039
|
constructor(repository, table, data, rawParent) {
|
1915
3040
|
__privateAdd$5(this, _cleanFilterConstraint);
|
1916
3041
|
__privateAdd$5(this, _table$1, void 0);
|
1917
3042
|
__privateAdd$5(this, _repository, void 0);
|
1918
3043
|
__privateAdd$5(this, _data, { filter: {} });
|
1919
|
-
|
3044
|
+
// Implements pagination
|
3045
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1920
3046
|
this.records = new RecordArray(this, []);
|
1921
3047
|
__privateSet$5(this, _table$1, table);
|
1922
3048
|
if (repository) {
|
@@ -1932,6 +3058,7 @@ const _Query = class {
|
|
1932
3058
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1933
3059
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1934
3060
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
3061
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1935
3062
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1936
3063
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
1937
3064
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -1952,18 +3079,38 @@ const _Query = class {
|
|
1952
3079
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1953
3080
|
return toBase64(key);
|
1954
3081
|
}
|
3082
|
+
/**
|
3083
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3084
|
+
* @param queries An array of subqueries.
|
3085
|
+
* @returns A new Query object.
|
3086
|
+
*/
|
1955
3087
|
any(...queries) {
|
1956
3088
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1957
3089
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1958
3090
|
}
|
3091
|
+
/**
|
3092
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3093
|
+
* @param queries An array of subqueries.
|
3094
|
+
* @returns A new Query object.
|
3095
|
+
*/
|
1959
3096
|
all(...queries) {
|
1960
3097
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1961
3098
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1962
3099
|
}
|
3100
|
+
/**
|
3101
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3102
|
+
* @param queries An array of subqueries.
|
3103
|
+
* @returns A new Query object.
|
3104
|
+
*/
|
1963
3105
|
not(...queries) {
|
1964
3106
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1965
3107
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1966
3108
|
}
|
3109
|
+
/**
|
3110
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3111
|
+
* @param queries An array of subqueries.
|
3112
|
+
* @returns A new Query object.
|
3113
|
+
*/
|
1967
3114
|
none(...queries) {
|
1968
3115
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1969
3116
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -1986,6 +3133,11 @@ const _Query = class {
|
|
1986
3133
|
const sort = [...originalSort, { column, direction }];
|
1987
3134
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1988
3135
|
}
|
3136
|
+
/**
|
3137
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3138
|
+
* @param columns Array of column names to be returned by the query.
|
3139
|
+
* @returns A new Query object.
|
3140
|
+
*/
|
1989
3141
|
select(columns) {
|
1990
3142
|
return new _Query(
|
1991
3143
|
__privateGet$5(this, _repository),
|
@@ -1998,6 +3150,12 @@ const _Query = class {
|
|
1998
3150
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1999
3151
|
return __privateGet$5(this, _repository).query(query);
|
2000
3152
|
}
|
3153
|
+
/**
|
3154
|
+
* Get results in an iterator
|
3155
|
+
*
|
3156
|
+
* @async
|
3157
|
+
* @returns Async interable of results
|
3158
|
+
*/
|
2001
3159
|
async *[Symbol.asyncIterator]() {
|
2002
3160
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2003
3161
|
yield record;
|
@@ -2058,26 +3216,53 @@ const _Query = class {
|
|
2058
3216
|
);
|
2059
3217
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2060
3218
|
}
|
3219
|
+
/**
|
3220
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3221
|
+
* @param ttl The cache TTL in milliseconds.
|
3222
|
+
* @returns A new Query object.
|
3223
|
+
*/
|
2061
3224
|
cache(ttl) {
|
2062
3225
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2063
3226
|
}
|
3227
|
+
/**
|
3228
|
+
* Retrieve next page of records
|
3229
|
+
*
|
3230
|
+
* @returns A new page object.
|
3231
|
+
*/
|
2064
3232
|
nextPage(size, offset) {
|
2065
3233
|
return this.startPage(size, offset);
|
2066
3234
|
}
|
3235
|
+
/**
|
3236
|
+
* Retrieve previous page of records
|
3237
|
+
*
|
3238
|
+
* @returns A new page object
|
3239
|
+
*/
|
2067
3240
|
previousPage(size, offset) {
|
2068
3241
|
return this.startPage(size, offset);
|
2069
3242
|
}
|
3243
|
+
/**
|
3244
|
+
* Retrieve start page of records
|
3245
|
+
*
|
3246
|
+
* @returns A new page object
|
3247
|
+
*/
|
2070
3248
|
startPage(size, offset) {
|
2071
3249
|
return this.getPaginated({ pagination: { size, offset } });
|
2072
3250
|
}
|
3251
|
+
/**
|
3252
|
+
* Retrieve last page of records
|
3253
|
+
*
|
3254
|
+
* @returns A new page object
|
3255
|
+
*/
|
2073
3256
|
endPage(size, offset) {
|
2074
3257
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2075
3258
|
}
|
3259
|
+
/**
|
3260
|
+
* @returns Boolean indicating if there is a next page
|
3261
|
+
*/
|
2076
3262
|
hasNextPage() {
|
2077
3263
|
return this.meta.page.more;
|
2078
3264
|
}
|
2079
3265
|
};
|
2080
|
-
let Query = _Query;
|
2081
3266
|
_table$1 = new WeakMap();
|
2082
3267
|
_repository = new WeakMap();
|
2083
3268
|
_data = new WeakMap();
|
@@ -2092,6 +3277,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2092
3277
|
}
|
2093
3278
|
return value;
|
2094
3279
|
};
|
3280
|
+
let Query = _Query;
|
2095
3281
|
function cleanParent(data, parent) {
|
2096
3282
|
if (isCursorPaginationOptions(data.pagination)) {
|
2097
3283
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2099,6 +3285,21 @@ function cleanParent(data, parent) {
|
|
2099
3285
|
return parent;
|
2100
3286
|
}
|
2101
3287
|
|
3288
|
+
const RecordColumnTypes = [
|
3289
|
+
"bool",
|
3290
|
+
"int",
|
3291
|
+
"float",
|
3292
|
+
"string",
|
3293
|
+
"text",
|
3294
|
+
"email",
|
3295
|
+
"multiple",
|
3296
|
+
"link",
|
3297
|
+
"datetime",
|
3298
|
+
"vector",
|
3299
|
+
"file[]",
|
3300
|
+
"file",
|
3301
|
+
"json"
|
3302
|
+
];
|
2102
3303
|
function isIdentifiable(x) {
|
2103
3304
|
return isObject(x) && isString(x?.id);
|
2104
3305
|
}
|
@@ -2108,11 +3309,33 @@ function isXataRecord(x) {
|
|
2108
3309
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2109
3310
|
}
|
2110
3311
|
|
3312
|
+
function isValidExpandedColumn(column) {
|
3313
|
+
return isObject(column) && isString(column.name);
|
3314
|
+
}
|
3315
|
+
function isValidSelectableColumns(columns) {
|
3316
|
+
if (!Array.isArray(columns)) {
|
3317
|
+
return false;
|
3318
|
+
}
|
3319
|
+
return columns.every((column) => {
|
3320
|
+
if (typeof column === "string") {
|
3321
|
+
return true;
|
3322
|
+
}
|
3323
|
+
if (typeof column === "object") {
|
3324
|
+
return isValidExpandedColumn(column);
|
3325
|
+
}
|
3326
|
+
return false;
|
3327
|
+
});
|
3328
|
+
}
|
3329
|
+
|
2111
3330
|
function isSortFilterString(value) {
|
2112
3331
|
return isString(value);
|
2113
3332
|
}
|
2114
3333
|
function isSortFilterBase(filter) {
|
2115
|
-
return isObject(filter) && Object.
|
3334
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3335
|
+
if (key === "*")
|
3336
|
+
return value === "random";
|
3337
|
+
return value === "asc" || value === "desc";
|
3338
|
+
});
|
2116
3339
|
}
|
2117
3340
|
function isSortFilterObject(filter) {
|
2118
3341
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2153,7 +3376,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2153
3376
|
__accessCheck$4(obj, member, "access private method");
|
2154
3377
|
return method;
|
2155
3378
|
};
|
2156
|
-
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;
|
3379
|
+
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;
|
2157
3380
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2158
3381
|
class Repository extends Query {
|
2159
3382
|
}
|
@@ -2175,6 +3398,7 @@ class RestRepository extends Query {
|
|
2175
3398
|
__privateAdd$4(this, _setCacheQuery);
|
2176
3399
|
__privateAdd$4(this, _getCacheQuery);
|
2177
3400
|
__privateAdd$4(this, _getSchemaTables$1);
|
3401
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2178
3402
|
__privateAdd$4(this, _table, void 0);
|
2179
3403
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2180
3404
|
__privateAdd$4(this, _db, void 0);
|
@@ -2185,10 +3409,7 @@ class RestRepository extends Query {
|
|
2185
3409
|
__privateSet$4(this, _db, options.db);
|
2186
3410
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2187
3411
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2188
|
-
__privateSet$4(this, _getFetchProps,
|
2189
|
-
const props = await options.pluginOptions.getFetchProps();
|
2190
|
-
return { ...props, sessionID: generateUUID() };
|
2191
|
-
});
|
3412
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2192
3413
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2193
3414
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2194
3415
|
return trace(name, fn, {
|
@@ -2206,24 +3427,24 @@ class RestRepository extends Query {
|
|
2206
3427
|
if (a.length === 0)
|
2207
3428
|
return [];
|
2208
3429
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2209
|
-
const columns =
|
3430
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2210
3431
|
const result = await this.read(ids, columns);
|
2211
3432
|
return result;
|
2212
3433
|
}
|
2213
3434
|
if (isString(a) && isObject(b)) {
|
2214
3435
|
if (a === "")
|
2215
3436
|
throw new Error("The id can't be empty");
|
2216
|
-
const columns =
|
3437
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2217
3438
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2218
3439
|
}
|
2219
3440
|
if (isObject(a) && isString(a.id)) {
|
2220
3441
|
if (a.id === "")
|
2221
3442
|
throw new Error("The id can't be empty");
|
2222
|
-
const columns =
|
3443
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2223
3444
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2224
3445
|
}
|
2225
3446
|
if (isObject(a)) {
|
2226
|
-
const columns =
|
3447
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2227
3448
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2228
3449
|
}
|
2229
3450
|
throw new Error("Invalid arguments for create method");
|
@@ -2231,7 +3452,7 @@ class RestRepository extends Query {
|
|
2231
3452
|
}
|
2232
3453
|
async read(a, b) {
|
2233
3454
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2234
|
-
const columns =
|
3455
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2235
3456
|
if (Array.isArray(a)) {
|
2236
3457
|
if (a.length === 0)
|
2237
3458
|
return [];
|
@@ -2245,7 +3466,6 @@ class RestRepository extends Query {
|
|
2245
3466
|
}
|
2246
3467
|
const id = extractId(a);
|
2247
3468
|
if (id) {
|
2248
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2249
3469
|
try {
|
2250
3470
|
const response = await getRecord({
|
2251
3471
|
pathParams: {
|
@@ -2256,10 +3476,16 @@ class RestRepository extends Query {
|
|
2256
3476
|
recordId: id
|
2257
3477
|
},
|
2258
3478
|
queryParams: { columns },
|
2259
|
-
...
|
3479
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2260
3480
|
});
|
2261
3481
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2262
|
-
return initObject(
|
3482
|
+
return initObject(
|
3483
|
+
__privateGet$4(this, _db),
|
3484
|
+
schemaTables,
|
3485
|
+
__privateGet$4(this, _table),
|
3486
|
+
response,
|
3487
|
+
columns
|
3488
|
+
);
|
2263
3489
|
} catch (e) {
|
2264
3490
|
if (isObject(e) && e.status === 404) {
|
2265
3491
|
return null;
|
@@ -2301,17 +3527,23 @@ class RestRepository extends Query {
|
|
2301
3527
|
ifVersion,
|
2302
3528
|
upsert: false
|
2303
3529
|
});
|
2304
|
-
const columns =
|
3530
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2305
3531
|
const result = await this.read(a, columns);
|
2306
3532
|
return result;
|
2307
3533
|
}
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
3534
|
+
try {
|
3535
|
+
if (isString(a) && isObject(b)) {
|
3536
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3537
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3538
|
+
}
|
3539
|
+
if (isObject(a) && isString(a.id)) {
|
3540
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3541
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3542
|
+
}
|
3543
|
+
} catch (error) {
|
3544
|
+
if (error.status === 422)
|
3545
|
+
return null;
|
3546
|
+
throw error;
|
2315
3547
|
}
|
2316
3548
|
throw new Error("Invalid arguments for update method");
|
2317
3549
|
});
|
@@ -2345,17 +3577,27 @@ class RestRepository extends Query {
|
|
2345
3577
|
ifVersion,
|
2346
3578
|
upsert: true
|
2347
3579
|
});
|
2348
|
-
const columns =
|
3580
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2349
3581
|
const result = await this.read(a, columns);
|
2350
3582
|
return result;
|
2351
3583
|
}
|
2352
3584
|
if (isString(a) && isObject(b)) {
|
2353
|
-
|
2354
|
-
|
3585
|
+
if (a === "")
|
3586
|
+
throw new Error("The id can't be empty");
|
3587
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3588
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2355
3589
|
}
|
2356
3590
|
if (isObject(a) && isString(a.id)) {
|
2357
|
-
|
2358
|
-
|
3591
|
+
if (a.id === "")
|
3592
|
+
throw new Error("The id can't be empty");
|
3593
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3594
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3595
|
+
}
|
3596
|
+
if (!isDefined(a) && isObject(b)) {
|
3597
|
+
return await this.create(b, c);
|
3598
|
+
}
|
3599
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3600
|
+
return await this.create(a, b);
|
2359
3601
|
}
|
2360
3602
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2361
3603
|
});
|
@@ -2367,17 +3609,27 @@ class RestRepository extends Query {
|
|
2367
3609
|
if (a.length === 0)
|
2368
3610
|
return [];
|
2369
3611
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2370
|
-
const columns =
|
3612
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2371
3613
|
const result = await this.read(ids, columns);
|
2372
3614
|
return result;
|
2373
3615
|
}
|
2374
3616
|
if (isString(a) && isObject(b)) {
|
2375
|
-
|
2376
|
-
|
3617
|
+
if (a === "")
|
3618
|
+
throw new Error("The id can't be empty");
|
3619
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3620
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2377
3621
|
}
|
2378
3622
|
if (isObject(a) && isString(a.id)) {
|
2379
|
-
|
2380
|
-
|
3623
|
+
if (a.id === "")
|
3624
|
+
throw new Error("The id can't be empty");
|
3625
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3626
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3627
|
+
}
|
3628
|
+
if (!isDefined(a) && isObject(b)) {
|
3629
|
+
return await this.create(b, c);
|
3630
|
+
}
|
3631
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3632
|
+
return await this.create(a, b);
|
2381
3633
|
}
|
2382
3634
|
throw new Error("Invalid arguments for createOrReplace method");
|
2383
3635
|
});
|
@@ -2394,7 +3646,7 @@ class RestRepository extends Query {
|
|
2394
3646
|
return o.id;
|
2395
3647
|
throw new Error("Invalid arguments for delete method");
|
2396
3648
|
});
|
2397
|
-
const columns =
|
3649
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2398
3650
|
const result = await this.read(a, columns);
|
2399
3651
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2400
3652
|
return result;
|
@@ -2428,8 +3680,7 @@ class RestRepository extends Query {
|
|
2428
3680
|
}
|
2429
3681
|
async search(query, options = {}) {
|
2430
3682
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2431
|
-
const
|
2432
|
-
const { records } = await searchTable({
|
3683
|
+
const { records, totalCount } = await searchTable({
|
2433
3684
|
pathParams: {
|
2434
3685
|
workspace: "{workspaceId}",
|
2435
3686
|
dbBranchName: "{dbBranch}",
|
@@ -2442,17 +3693,46 @@ class RestRepository extends Query {
|
|
2442
3693
|
prefix: options.prefix,
|
2443
3694
|
highlight: options.highlight,
|
2444
3695
|
filter: options.filter,
|
2445
|
-
boosters: options.boosters
|
3696
|
+
boosters: options.boosters,
|
3697
|
+
page: options.page,
|
3698
|
+
target: options.target
|
3699
|
+
},
|
3700
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3701
|
+
});
|
3702
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3703
|
+
return {
|
3704
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3705
|
+
totalCount
|
3706
|
+
};
|
3707
|
+
});
|
3708
|
+
}
|
3709
|
+
async vectorSearch(column, query, options) {
|
3710
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3711
|
+
const { records, totalCount } = await vectorSearchTable({
|
3712
|
+
pathParams: {
|
3713
|
+
workspace: "{workspaceId}",
|
3714
|
+
dbBranchName: "{dbBranch}",
|
3715
|
+
region: "{region}",
|
3716
|
+
tableName: __privateGet$4(this, _table)
|
2446
3717
|
},
|
2447
|
-
|
3718
|
+
body: {
|
3719
|
+
column,
|
3720
|
+
queryVector: query,
|
3721
|
+
similarityFunction: options?.similarityFunction,
|
3722
|
+
size: options?.size,
|
3723
|
+
filter: options?.filter
|
3724
|
+
},
|
3725
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2448
3726
|
});
|
2449
3727
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2450
|
-
return
|
3728
|
+
return {
|
3729
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3730
|
+
totalCount
|
3731
|
+
};
|
2451
3732
|
});
|
2452
3733
|
}
|
2453
3734
|
async aggregate(aggs, filter) {
|
2454
3735
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2455
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2456
3736
|
const result = await aggregateTable({
|
2457
3737
|
pathParams: {
|
2458
3738
|
workspace: "{workspaceId}",
|
@@ -2461,7 +3741,7 @@ class RestRepository extends Query {
|
|
2461
3741
|
tableName: __privateGet$4(this, _table)
|
2462
3742
|
},
|
2463
3743
|
body: { aggs, filter },
|
2464
|
-
...
|
3744
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2465
3745
|
});
|
2466
3746
|
return result;
|
2467
3747
|
});
|
@@ -2472,7 +3752,6 @@ class RestRepository extends Query {
|
|
2472
3752
|
if (cacheQuery)
|
2473
3753
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2474
3754
|
const data = query.getQueryOptions();
|
2475
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2476
3755
|
const { meta, records: objects } = await queryTable({
|
2477
3756
|
pathParams: {
|
2478
3757
|
workspace: "{workspaceId}",
|
@@ -2484,14 +3763,21 @@ class RestRepository extends Query {
|
|
2484
3763
|
filter: cleanFilter(data.filter),
|
2485
3764
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2486
3765
|
page: data.pagination,
|
2487
|
-
columns: data.columns ?? ["*"]
|
3766
|
+
columns: data.columns ?? ["*"],
|
3767
|
+
consistency: data.consistency
|
2488
3768
|
},
|
2489
3769
|
fetchOptions: data.fetchOptions,
|
2490
|
-
...
|
3770
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2491
3771
|
});
|
2492
3772
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2493
3773
|
const records = objects.map(
|
2494
|
-
(record) => initObject(
|
3774
|
+
(record) => initObject(
|
3775
|
+
__privateGet$4(this, _db),
|
3776
|
+
schemaTables,
|
3777
|
+
__privateGet$4(this, _table),
|
3778
|
+
record,
|
3779
|
+
data.columns ?? ["*"]
|
3780
|
+
)
|
2495
3781
|
);
|
2496
3782
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2497
3783
|
return new Page(query, meta, records);
|
@@ -2500,7 +3786,6 @@ class RestRepository extends Query {
|
|
2500
3786
|
async summarizeTable(query, summaries, summariesFilter) {
|
2501
3787
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2502
3788
|
const data = query.getQueryOptions();
|
2503
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2504
3789
|
const result = await summarizeTable({
|
2505
3790
|
pathParams: {
|
2506
3791
|
workspace: "{workspaceId}",
|
@@ -2512,15 +3797,55 @@ class RestRepository extends Query {
|
|
2512
3797
|
filter: cleanFilter(data.filter),
|
2513
3798
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2514
3799
|
columns: data.columns,
|
3800
|
+
consistency: data.consistency,
|
2515
3801
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2516
3802
|
summaries,
|
2517
3803
|
summariesFilter
|
2518
3804
|
},
|
2519
|
-
...
|
3805
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2520
3806
|
});
|
2521
|
-
|
3807
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3808
|
+
return {
|
3809
|
+
...result,
|
3810
|
+
summaries: result.summaries.map(
|
3811
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3812
|
+
)
|
3813
|
+
};
|
2522
3814
|
});
|
2523
3815
|
}
|
3816
|
+
ask(question, options) {
|
3817
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3818
|
+
const params = {
|
3819
|
+
pathParams: {
|
3820
|
+
workspace: "{workspaceId}",
|
3821
|
+
dbBranchName: "{dbBranch}",
|
3822
|
+
region: "{region}",
|
3823
|
+
tableName: __privateGet$4(this, _table),
|
3824
|
+
sessionId: options?.sessionId
|
3825
|
+
},
|
3826
|
+
body: {
|
3827
|
+
...questionParam,
|
3828
|
+
rules: options?.rules,
|
3829
|
+
searchType: options?.searchType,
|
3830
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3831
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3832
|
+
},
|
3833
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3834
|
+
};
|
3835
|
+
if (options?.onMessage) {
|
3836
|
+
fetchSSERequest({
|
3837
|
+
endpoint: "dataPlane",
|
3838
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3839
|
+
method: "POST",
|
3840
|
+
onMessage: (message) => {
|
3841
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3842
|
+
},
|
3843
|
+
...params
|
3844
|
+
});
|
3845
|
+
} else {
|
3846
|
+
return askTableSession(params);
|
3847
|
+
}
|
3848
|
+
}
|
2524
3849
|
}
|
2525
3850
|
_table = new WeakMap();
|
2526
3851
|
_getFetchProps = new WeakMap();
|
@@ -2530,8 +3855,7 @@ _schemaTables$2 = new WeakMap();
|
|
2530
3855
|
_trace = new WeakMap();
|
2531
3856
|
_insertRecordWithoutId = new WeakSet();
|
2532
3857
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2533
|
-
const
|
2534
|
-
const record = transformObjectLinks(object);
|
3858
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2535
3859
|
const response = await insertRecord({
|
2536
3860
|
pathParams: {
|
2537
3861
|
workspace: "{workspaceId}",
|
@@ -2541,15 +3865,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2541
3865
|
},
|
2542
3866
|
queryParams: { columns },
|
2543
3867
|
body: record,
|
2544
|
-
...
|
3868
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2545
3869
|
});
|
2546
3870
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2547
3871
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2548
3872
|
};
|
2549
3873
|
_insertRecordWithId = new WeakSet();
|
2550
3874
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2551
|
-
|
2552
|
-
|
3875
|
+
if (!recordId)
|
3876
|
+
return null;
|
3877
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2553
3878
|
const response = await insertRecordWithID({
|
2554
3879
|
pathParams: {
|
2555
3880
|
workspace: "{workspaceId}",
|
@@ -2560,30 +3885,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2560
3885
|
},
|
2561
3886
|
body: record,
|
2562
3887
|
queryParams: { createOnly, columns, ifVersion },
|
2563
|
-
...
|
3888
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2564
3889
|
});
|
2565
3890
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2566
3891
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2567
3892
|
};
|
2568
3893
|
_insertRecords = new WeakSet();
|
2569
3894
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2570
|
-
const
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2574
|
-
|
2575
|
-
BULK_OPERATION_MAX_SIZE
|
2576
|
-
);
|
3895
|
+
const operations = await promiseMap(objects, async (object) => {
|
3896
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3897
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3898
|
+
});
|
3899
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2577
3900
|
const ids = [];
|
2578
|
-
for (const
|
3901
|
+
for (const operations2 of chunkedOperations) {
|
2579
3902
|
const { results } = await branchTransaction({
|
2580
3903
|
pathParams: {
|
2581
3904
|
workspace: "{workspaceId}",
|
2582
3905
|
dbBranchName: "{dbBranch}",
|
2583
3906
|
region: "{region}"
|
2584
3907
|
},
|
2585
|
-
body: { operations },
|
2586
|
-
...
|
3908
|
+
body: { operations: operations2 },
|
3909
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2587
3910
|
});
|
2588
3911
|
for (const result of results) {
|
2589
3912
|
if (result.operation === "insert") {
|
@@ -2597,8 +3920,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2597
3920
|
};
|
2598
3921
|
_updateRecordWithID = new WeakSet();
|
2599
3922
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2600
|
-
|
2601
|
-
|
3923
|
+
if (!recordId)
|
3924
|
+
return null;
|
3925
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2602
3926
|
try {
|
2603
3927
|
const response = await updateRecordWithID({
|
2604
3928
|
pathParams: {
|
@@ -2610,7 +3934,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2610
3934
|
},
|
2611
3935
|
queryParams: { columns, ifVersion },
|
2612
3936
|
body: record,
|
2613
|
-
...
|
3937
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2614
3938
|
});
|
2615
3939
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2616
3940
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2623,23 +3947,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2623
3947
|
};
|
2624
3948
|
_updateRecords = new WeakSet();
|
2625
3949
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2626
|
-
const
|
2627
|
-
|
2628
|
-
|
2629
|
-
|
2630
|
-
|
2631
|
-
BULK_OPERATION_MAX_SIZE
|
2632
|
-
);
|
3950
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3951
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3952
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3953
|
+
});
|
3954
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2633
3955
|
const ids = [];
|
2634
|
-
for (const
|
3956
|
+
for (const operations2 of chunkedOperations) {
|
2635
3957
|
const { results } = await branchTransaction({
|
2636
3958
|
pathParams: {
|
2637
3959
|
workspace: "{workspaceId}",
|
2638
3960
|
dbBranchName: "{dbBranch}",
|
2639
3961
|
region: "{region}"
|
2640
3962
|
},
|
2641
|
-
body: { operations },
|
2642
|
-
...
|
3963
|
+
body: { operations: operations2 },
|
3964
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2643
3965
|
});
|
2644
3966
|
for (const result of results) {
|
2645
3967
|
if (result.operation === "update") {
|
@@ -2653,7 +3975,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2653
3975
|
};
|
2654
3976
|
_upsertRecordWithID = new WeakSet();
|
2655
3977
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2656
|
-
|
3978
|
+
if (!recordId)
|
3979
|
+
return null;
|
2657
3980
|
const response = await upsertRecordWithID({
|
2658
3981
|
pathParams: {
|
2659
3982
|
workspace: "{workspaceId}",
|
@@ -2664,14 +3987,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2664
3987
|
},
|
2665
3988
|
queryParams: { columns, ifVersion },
|
2666
3989
|
body: object,
|
2667
|
-
...
|
3990
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2668
3991
|
});
|
2669
3992
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2670
3993
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2671
3994
|
};
|
2672
3995
|
_deleteRecord = new WeakSet();
|
2673
3996
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2674
|
-
|
3997
|
+
if (!recordId)
|
3998
|
+
return null;
|
2675
3999
|
try {
|
2676
4000
|
const response = await deleteRecord({
|
2677
4001
|
pathParams: {
|
@@ -2682,7 +4006,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2682
4006
|
recordId
|
2683
4007
|
},
|
2684
4008
|
queryParams: { columns },
|
2685
|
-
...
|
4009
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2686
4010
|
});
|
2687
4011
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2688
4012
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2695,9 +4019,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2695
4019
|
};
|
2696
4020
|
_deleteRecords = new WeakSet();
|
2697
4021
|
deleteRecords_fn = async function(recordIds) {
|
2698
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2699
4022
|
const chunkedOperations = chunk(
|
2700
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
4023
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2701
4024
|
BULK_OPERATION_MAX_SIZE
|
2702
4025
|
);
|
2703
4026
|
for (const operations of chunkedOperations) {
|
@@ -2708,21 +4031,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2708
4031
|
region: "{region}"
|
2709
4032
|
},
|
2710
4033
|
body: { operations },
|
2711
|
-
...
|
4034
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2712
4035
|
});
|
2713
4036
|
}
|
2714
4037
|
};
|
2715
4038
|
_setCacheQuery = new WeakSet();
|
2716
4039
|
setCacheQuery_fn = async function(query, meta, records) {
|
2717
|
-
await __privateGet$4(this, _cache)
|
4040
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2718
4041
|
};
|
2719
4042
|
_getCacheQuery = new WeakSet();
|
2720
4043
|
getCacheQuery_fn = async function(query) {
|
2721
4044
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2722
|
-
const result = await __privateGet$4(this, _cache)
|
4045
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2723
4046
|
if (!result)
|
2724
4047
|
return null;
|
2725
|
-
const
|
4048
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4049
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2726
4050
|
if (ttl < 0)
|
2727
4051
|
return null;
|
2728
4052
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2732,39 +4056,66 @@ _getSchemaTables$1 = new WeakSet();
|
|
2732
4056
|
getSchemaTables_fn$1 = async function() {
|
2733
4057
|
if (__privateGet$4(this, _schemaTables$2))
|
2734
4058
|
return __privateGet$4(this, _schemaTables$2);
|
2735
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2736
4059
|
const { schema } = await getBranchDetails({
|
2737
4060
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2738
|
-
...
|
4061
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2739
4062
|
});
|
2740
4063
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2741
4064
|
return schema.tables;
|
2742
4065
|
};
|
2743
|
-
|
2744
|
-
|
4066
|
+
_transformObjectToApi = new WeakSet();
|
4067
|
+
transformObjectToApi_fn = async function(object) {
|
4068
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4069
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4070
|
+
if (!schema)
|
4071
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4072
|
+
const result = {};
|
4073
|
+
for (const [key, value] of Object.entries(object)) {
|
2745
4074
|
if (key === "xata")
|
2746
|
-
|
2747
|
-
|
2748
|
-
|
4075
|
+
continue;
|
4076
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4077
|
+
switch (type) {
|
4078
|
+
case "link": {
|
4079
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4080
|
+
break;
|
4081
|
+
}
|
4082
|
+
case "datetime": {
|
4083
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4084
|
+
break;
|
4085
|
+
}
|
4086
|
+
case `file`:
|
4087
|
+
result[key] = await parseInputFileEntry(value);
|
4088
|
+
break;
|
4089
|
+
case "file[]":
|
4090
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4091
|
+
break;
|
4092
|
+
case "json":
|
4093
|
+
result[key] = stringifyJson(value);
|
4094
|
+
break;
|
4095
|
+
default:
|
4096
|
+
result[key] = value;
|
4097
|
+
}
|
4098
|
+
}
|
4099
|
+
return result;
|
2749
4100
|
};
|
2750
4101
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2751
|
-
const
|
4102
|
+
const data = {};
|
2752
4103
|
const { xata, ...rest } = object ?? {};
|
2753
|
-
Object.assign(
|
4104
|
+
Object.assign(data, rest);
|
2754
4105
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2755
4106
|
if (!columns)
|
2756
4107
|
console.error(`Table ${table} not found in schema`);
|
2757
4108
|
for (const column of columns ?? []) {
|
2758
4109
|
if (!isValidColumn(selectedColumns, column))
|
2759
4110
|
continue;
|
2760
|
-
const value =
|
4111
|
+
const value = data[column.name];
|
2761
4112
|
switch (column.type) {
|
2762
4113
|
case "datetime": {
|
2763
|
-
const date = value !== void 0 ? new Date(value) :
|
2764
|
-
if (date && isNaN(date.getTime())) {
|
4114
|
+
const date = value !== void 0 ? new Date(value) : null;
|
4115
|
+
if (date !== null && isNaN(date.getTime())) {
|
2765
4116
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2766
|
-
} else
|
2767
|
-
|
4117
|
+
} else {
|
4118
|
+
data[column.name] = date;
|
2768
4119
|
}
|
2769
4120
|
break;
|
2770
4121
|
}
|
@@ -2777,50 +4128,76 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2777
4128
|
if (item === column.name) {
|
2778
4129
|
return [...acc, "*"];
|
2779
4130
|
}
|
2780
|
-
if (item.startsWith(`${column.name}.`)) {
|
4131
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2781
4132
|
const [, ...path] = item.split(".");
|
2782
4133
|
return [...acc, path.join(".")];
|
2783
4134
|
}
|
2784
4135
|
return acc;
|
2785
4136
|
}, []);
|
2786
|
-
|
4137
|
+
data[column.name] = initObject(
|
4138
|
+
db,
|
4139
|
+
schemaTables,
|
4140
|
+
linkTable,
|
4141
|
+
value,
|
4142
|
+
selectedLinkColumns
|
4143
|
+
);
|
2787
4144
|
} else {
|
2788
|
-
|
4145
|
+
data[column.name] = null;
|
2789
4146
|
}
|
2790
4147
|
break;
|
2791
4148
|
}
|
4149
|
+
case "file":
|
4150
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4151
|
+
break;
|
4152
|
+
case "file[]":
|
4153
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4154
|
+
break;
|
4155
|
+
case "json":
|
4156
|
+
data[column.name] = parseJson(value);
|
4157
|
+
break;
|
2792
4158
|
default:
|
2793
|
-
|
4159
|
+
data[column.name] = value ?? null;
|
2794
4160
|
if (column.notNull === true && value === null) {
|
2795
4161
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2796
4162
|
}
|
2797
4163
|
break;
|
2798
4164
|
}
|
2799
4165
|
}
|
2800
|
-
|
2801
|
-
|
4166
|
+
const record = { ...data };
|
4167
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4168
|
+
record.read = function(columns2) {
|
4169
|
+
return db[table].read(record["id"], columns2);
|
2802
4170
|
};
|
2803
|
-
|
2804
|
-
const columns2 =
|
4171
|
+
record.update = function(data2, b, c) {
|
4172
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2805
4173
|
const ifVersion = parseIfVersion(b, c);
|
2806
|
-
return db[table].update(
|
4174
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2807
4175
|
};
|
2808
|
-
|
2809
|
-
const columns2 =
|
4176
|
+
record.replace = function(data2, b, c) {
|
4177
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2810
4178
|
const ifVersion = parseIfVersion(b, c);
|
2811
|
-
return db[table].createOrReplace(
|
4179
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4180
|
+
};
|
4181
|
+
record.delete = function() {
|
4182
|
+
return db[table].delete(record["id"]);
|
4183
|
+
};
|
4184
|
+
if (metadata !== void 0) {
|
4185
|
+
record.xata = Object.freeze(metadata);
|
4186
|
+
}
|
4187
|
+
record.getMetadata = function() {
|
4188
|
+
return record.xata;
|
2812
4189
|
};
|
2813
|
-
|
2814
|
-
return
|
4190
|
+
record.toSerializable = function() {
|
4191
|
+
return JSON.parse(JSON.stringify(record));
|
2815
4192
|
};
|
2816
|
-
|
2817
|
-
return
|
4193
|
+
record.toString = function() {
|
4194
|
+
return JSON.stringify(record);
|
2818
4195
|
};
|
2819
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
2820
|
-
Object.defineProperty(
|
4196
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4197
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2821
4198
|
}
|
2822
|
-
Object.freeze(
|
2823
|
-
return
|
4199
|
+
Object.freeze(record);
|
4200
|
+
return record;
|
2824
4201
|
};
|
2825
4202
|
function extractId(value) {
|
2826
4203
|
if (isString(value))
|
@@ -2832,11 +4209,7 @@ function extractId(value) {
|
|
2832
4209
|
function isValidColumn(columns, column) {
|
2833
4210
|
if (columns.includes("*"))
|
2834
4211
|
return true;
|
2835
|
-
|
2836
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2837
|
-
return linkColumns.length > 0;
|
2838
|
-
}
|
2839
|
-
return columns.includes(column.name);
|
4212
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
2840
4213
|
}
|
2841
4214
|
function parseIfVersion(...args) {
|
2842
4215
|
for (const arg of args) {
|
@@ -2913,10 +4286,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
2913
4286
|
const startsWith = (value) => ({ $startsWith: value });
|
2914
4287
|
const endsWith = (value) => ({ $endsWith: value });
|
2915
4288
|
const pattern = (value) => ({ $pattern: value });
|
4289
|
+
const iPattern = (value) => ({ $iPattern: value });
|
2916
4290
|
const is = (value) => ({ $is: value });
|
2917
4291
|
const equals = is;
|
2918
4292
|
const isNot = (value) => ({ $isNot: value });
|
2919
4293
|
const contains = (value) => ({ $contains: value });
|
4294
|
+
const iContains = (value) => ({ $iContains: value });
|
2920
4295
|
const includes = (value) => ({ $includes: value });
|
2921
4296
|
const includesAll = (value) => ({ $includesAll: value });
|
2922
4297
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -2972,6 +4347,80 @@ class SchemaPlugin extends XataPlugin {
|
|
2972
4347
|
_tables = new WeakMap();
|
2973
4348
|
_schemaTables$1 = new WeakMap();
|
2974
4349
|
|
4350
|
+
class FilesPlugin extends XataPlugin {
|
4351
|
+
build(pluginOptions) {
|
4352
|
+
return {
|
4353
|
+
download: async (location) => {
|
4354
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4355
|
+
return await getFileItem({
|
4356
|
+
pathParams: {
|
4357
|
+
workspace: "{workspaceId}",
|
4358
|
+
dbBranchName: "{dbBranch}",
|
4359
|
+
region: "{region}",
|
4360
|
+
tableName: table ?? "",
|
4361
|
+
recordId: record ?? "",
|
4362
|
+
columnName: column ?? "",
|
4363
|
+
fileId
|
4364
|
+
},
|
4365
|
+
...pluginOptions,
|
4366
|
+
rawResponse: true
|
4367
|
+
});
|
4368
|
+
},
|
4369
|
+
upload: async (location, file, options) => {
|
4370
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4371
|
+
const resolvedFile = await file;
|
4372
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4373
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4374
|
+
return await putFileItem({
|
4375
|
+
...pluginOptions,
|
4376
|
+
pathParams: {
|
4377
|
+
workspace: "{workspaceId}",
|
4378
|
+
dbBranchName: "{dbBranch}",
|
4379
|
+
region: "{region}",
|
4380
|
+
tableName: table ?? "",
|
4381
|
+
recordId: record ?? "",
|
4382
|
+
columnName: column ?? "",
|
4383
|
+
fileId
|
4384
|
+
},
|
4385
|
+
body,
|
4386
|
+
headers: { "Content-Type": contentType }
|
4387
|
+
});
|
4388
|
+
},
|
4389
|
+
delete: async (location) => {
|
4390
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4391
|
+
return await deleteFileItem({
|
4392
|
+
pathParams: {
|
4393
|
+
workspace: "{workspaceId}",
|
4394
|
+
dbBranchName: "{dbBranch}",
|
4395
|
+
region: "{region}",
|
4396
|
+
tableName: table ?? "",
|
4397
|
+
recordId: record ?? "",
|
4398
|
+
columnName: column ?? "",
|
4399
|
+
fileId
|
4400
|
+
},
|
4401
|
+
...pluginOptions
|
4402
|
+
});
|
4403
|
+
}
|
4404
|
+
};
|
4405
|
+
}
|
4406
|
+
}
|
4407
|
+
function getContentType(file) {
|
4408
|
+
if (typeof file === "string") {
|
4409
|
+
return "text/plain";
|
4410
|
+
}
|
4411
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4412
|
+
return file.mediaType;
|
4413
|
+
}
|
4414
|
+
if (isBlob(file)) {
|
4415
|
+
return file.type;
|
4416
|
+
}
|
4417
|
+
try {
|
4418
|
+
return file.type;
|
4419
|
+
} catch (e) {
|
4420
|
+
}
|
4421
|
+
return "application/octet-stream";
|
4422
|
+
}
|
4423
|
+
|
2975
4424
|
var __accessCheck$1 = (obj, member, msg) => {
|
2976
4425
|
if (!member.has(obj))
|
2977
4426
|
throw TypeError("Cannot " + msg);
|
@@ -3004,138 +4453,141 @@ class SearchPlugin extends XataPlugin {
|
|
3004
4453
|
__privateAdd$1(this, _schemaTables, void 0);
|
3005
4454
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3006
4455
|
}
|
3007
|
-
build(
|
4456
|
+
build(pluginOptions) {
|
3008
4457
|
return {
|
3009
4458
|
all: async (query, options = {}) => {
|
3010
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3011
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3012
|
-
return
|
3013
|
-
|
3014
|
-
|
3015
|
-
|
4459
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4460
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4461
|
+
return {
|
4462
|
+
totalCount,
|
4463
|
+
records: records.map((record) => {
|
4464
|
+
const { table = "orphan" } = record.xata;
|
4465
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4466
|
+
})
|
4467
|
+
};
|
3016
4468
|
},
|
3017
4469
|
byTable: async (query, options = {}) => {
|
3018
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3019
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3020
|
-
|
4470
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4471
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4472
|
+
const records = rawRecords.reduce((acc, record) => {
|
3021
4473
|
const { table = "orphan" } = record.xata;
|
3022
4474
|
const items = acc[table] ?? [];
|
3023
4475
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
3024
4476
|
return { ...acc, [table]: [...items, item] };
|
3025
4477
|
}, {});
|
4478
|
+
return { totalCount, records };
|
3026
4479
|
}
|
3027
4480
|
};
|
3028
4481
|
}
|
3029
4482
|
}
|
3030
4483
|
_schemaTables = new WeakMap();
|
3031
4484
|
_search = new WeakSet();
|
3032
|
-
search_fn = async function(query, options,
|
3033
|
-
const
|
3034
|
-
const {
|
3035
|
-
const { records } = await searchBranch({
|
4485
|
+
search_fn = async function(query, options, pluginOptions) {
|
4486
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4487
|
+
const { records, totalCount } = await searchBranch({
|
3036
4488
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3037
|
-
|
3038
|
-
|
4489
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4490
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4491
|
+
...pluginOptions
|
3039
4492
|
});
|
3040
|
-
return records;
|
4493
|
+
return { records, totalCount };
|
3041
4494
|
};
|
3042
4495
|
_getSchemaTables = new WeakSet();
|
3043
|
-
getSchemaTables_fn = async function(
|
4496
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3044
4497
|
if (__privateGet$1(this, _schemaTables))
|
3045
4498
|
return __privateGet$1(this, _schemaTables);
|
3046
|
-
const fetchProps = await getFetchProps();
|
3047
4499
|
const { schema } = await getBranchDetails({
|
3048
4500
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3049
|
-
...
|
4501
|
+
...pluginOptions
|
3050
4502
|
});
|
3051
4503
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3052
4504
|
return schema.tables;
|
3053
4505
|
};
|
3054
4506
|
|
3055
|
-
|
3056
|
-
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
|
3061
|
-
|
3062
|
-
|
3063
|
-
|
3064
|
-
|
3065
|
-
|
3066
|
-
|
3067
|
-
|
3068
|
-
|
3069
|
-
}
|
3070
|
-
|
3071
|
-
|
3072
|
-
|
3073
|
-
}
|
3074
|
-
async function resolveXataBranch(gitBranch, options) {
|
3075
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3076
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3077
|
-
if (!databaseURL)
|
3078
|
-
throw new Error(
|
3079
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3080
|
-
);
|
3081
|
-
if (!apiKey)
|
3082
|
-
throw new Error(
|
3083
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3084
|
-
);
|
3085
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3086
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3087
|
-
if (!urlParts)
|
3088
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3089
|
-
const { workspace, region } = urlParts;
|
3090
|
-
const { fallbackBranch } = getEnvironment();
|
3091
|
-
const { branch } = await resolveBranch({
|
3092
|
-
apiKey,
|
3093
|
-
apiUrl: databaseURL,
|
3094
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3095
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3096
|
-
pathParams: { dbName, workspace, region },
|
3097
|
-
queryParams: { gitBranch, fallbackBranch },
|
3098
|
-
trace: defaultTrace
|
3099
|
-
});
|
3100
|
-
return branch;
|
3101
|
-
}
|
3102
|
-
async function getDatabaseBranch(branch, options) {
|
3103
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3104
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3105
|
-
if (!databaseURL)
|
3106
|
-
throw new Error(
|
3107
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3108
|
-
);
|
3109
|
-
if (!apiKey)
|
3110
|
-
throw new Error(
|
3111
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3112
|
-
);
|
3113
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3114
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3115
|
-
if (!urlParts)
|
3116
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3117
|
-
const { workspace, region } = urlParts;
|
3118
|
-
try {
|
3119
|
-
return await getBranchDetails({
|
3120
|
-
apiKey,
|
3121
|
-
apiUrl: databaseURL,
|
3122
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3123
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3124
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3125
|
-
trace: defaultTrace
|
3126
|
-
});
|
3127
|
-
} catch (err) {
|
3128
|
-
if (isObject(err) && err.status === 404)
|
3129
|
-
return null;
|
3130
|
-
throw err;
|
4507
|
+
function escapeElement(elementRepresentation) {
|
4508
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4509
|
+
return '"' + escaped + '"';
|
4510
|
+
}
|
4511
|
+
function arrayString(val) {
|
4512
|
+
let result = "{";
|
4513
|
+
for (let i = 0; i < val.length; i++) {
|
4514
|
+
if (i > 0) {
|
4515
|
+
result = result + ",";
|
4516
|
+
}
|
4517
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4518
|
+
result = result + "NULL";
|
4519
|
+
} else if (Array.isArray(val[i])) {
|
4520
|
+
result = result + arrayString(val[i]);
|
4521
|
+
} else if (val[i] instanceof Buffer) {
|
4522
|
+
result += "\\\\x" + val[i].toString("hex");
|
4523
|
+
} else {
|
4524
|
+
result += escapeElement(prepareValue(val[i]));
|
4525
|
+
}
|
3131
4526
|
}
|
4527
|
+
result = result + "}";
|
4528
|
+
return result;
|
3132
4529
|
}
|
3133
|
-
function
|
4530
|
+
function prepareValue(value) {
|
4531
|
+
if (!isDefined(value))
|
4532
|
+
return null;
|
4533
|
+
if (value instanceof Date) {
|
4534
|
+
return value.toISOString();
|
4535
|
+
}
|
4536
|
+
if (Array.isArray(value)) {
|
4537
|
+
return arrayString(value);
|
4538
|
+
}
|
4539
|
+
if (isObject(value)) {
|
4540
|
+
return JSON.stringify(value);
|
4541
|
+
}
|
3134
4542
|
try {
|
3135
|
-
|
3136
|
-
|
3137
|
-
|
3138
|
-
|
4543
|
+
return value.toString();
|
4544
|
+
} catch (e) {
|
4545
|
+
return value;
|
4546
|
+
}
|
4547
|
+
}
|
4548
|
+
function prepareParams(param1, param2) {
|
4549
|
+
if (isString(param1)) {
|
4550
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4551
|
+
}
|
4552
|
+
if (isStringArray(param1)) {
|
4553
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4554
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4555
|
+
}, "");
|
4556
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4557
|
+
}
|
4558
|
+
if (isObject(param1)) {
|
4559
|
+
const { statement, params, consistency } = param1;
|
4560
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4561
|
+
}
|
4562
|
+
throw new Error("Invalid query");
|
4563
|
+
}
|
4564
|
+
|
4565
|
+
class SQLPlugin extends XataPlugin {
|
4566
|
+
build(pluginOptions) {
|
4567
|
+
return async (param1, ...param2) => {
|
4568
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4569
|
+
const { records, warning } = await sqlQuery({
|
4570
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4571
|
+
body: { statement, params, consistency },
|
4572
|
+
...pluginOptions
|
4573
|
+
});
|
4574
|
+
return { records, warning };
|
4575
|
+
};
|
4576
|
+
}
|
4577
|
+
}
|
4578
|
+
|
4579
|
+
class TransactionPlugin extends XataPlugin {
|
4580
|
+
build(pluginOptions) {
|
4581
|
+
return {
|
4582
|
+
run: async (operations) => {
|
4583
|
+
const response = await branchTransaction({
|
4584
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4585
|
+
body: { operations },
|
4586
|
+
...pluginOptions
|
4587
|
+
});
|
4588
|
+
return response;
|
4589
|
+
}
|
4590
|
+
};
|
3139
4591
|
}
|
3140
4592
|
}
|
3141
4593
|
|
@@ -3162,46 +4614,43 @@ var __privateMethod = (obj, member, method) => {
|
|
3162
4614
|
return method;
|
3163
4615
|
};
|
3164
4616
|
const buildClient = (plugins) => {
|
3165
|
-
var
|
4617
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3166
4618
|
return _a = class {
|
3167
4619
|
constructor(options = {}, schemaTables) {
|
3168
4620
|
__privateAdd(this, _parseOptions);
|
3169
4621
|
__privateAdd(this, _getFetchProps);
|
3170
|
-
__privateAdd(this, _evaluateBranch);
|
3171
|
-
__privateAdd(this, _branch, void 0);
|
3172
4622
|
__privateAdd(this, _options, void 0);
|
3173
4623
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3174
4624
|
__privateSet(this, _options, safeOptions);
|
3175
4625
|
const pluginOptions = {
|
3176
|
-
|
4626
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3177
4627
|
cache: safeOptions.cache,
|
3178
|
-
|
4628
|
+
host: safeOptions.host
|
3179
4629
|
};
|
3180
4630
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3181
4631
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4632
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
4633
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4634
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3182
4635
|
this.db = db;
|
3183
4636
|
this.search = search;
|
4637
|
+
this.transactions = transactions;
|
4638
|
+
this.sql = sql;
|
4639
|
+
this.files = files;
|
3184
4640
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3185
4641
|
if (namespace === void 0)
|
3186
4642
|
continue;
|
3187
|
-
|
3188
|
-
if (result instanceof Promise) {
|
3189
|
-
void result.then((namespace2) => {
|
3190
|
-
this[key] = namespace2;
|
3191
|
-
});
|
3192
|
-
} else {
|
3193
|
-
this[key] = result;
|
3194
|
-
}
|
4643
|
+
this[key] = namespace.build(pluginOptions);
|
3195
4644
|
}
|
3196
4645
|
}
|
3197
4646
|
async getConfig() {
|
3198
4647
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3199
|
-
const branch =
|
4648
|
+
const branch = __privateGet(this, _options).branch;
|
3200
4649
|
return { databaseURL, branch };
|
3201
4650
|
}
|
3202
|
-
},
|
4651
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3203
4652
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3204
|
-
const isBrowser = typeof window !== "undefined";
|
4653
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3205
4654
|
if (isBrowser && !enableBrowser) {
|
3206
4655
|
throw new Error(
|
3207
4656
|
"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."
|
@@ -3212,46 +4661,73 @@ const buildClient = (plugins) => {
|
|
3212
4661
|
const apiKey = options?.apiKey || getAPIKey();
|
3213
4662
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3214
4663
|
const trace = options?.trace ?? defaultTrace;
|
3215
|
-
const
|
4664
|
+
const clientName = options?.clientName;
|
4665
|
+
const host = options?.host ?? "production";
|
4666
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3216
4667
|
if (!apiKey) {
|
3217
4668
|
throw new Error("Option apiKey is required");
|
3218
4669
|
}
|
3219
4670
|
if (!databaseURL) {
|
3220
4671
|
throw new Error("Option databaseURL is required");
|
3221
4672
|
}
|
3222
|
-
|
3223
|
-
|
3224
|
-
const
|
3225
|
-
if (
|
3226
|
-
|
4673
|
+
const envBranch = getBranch();
|
4674
|
+
const previewBranch = getPreviewBranch();
|
4675
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4676
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4677
|
+
console.warn(
|
4678
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4679
|
+
);
|
4680
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4681
|
+
console.warn(
|
4682
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4683
|
+
);
|
4684
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4685
|
+
console.warn(
|
4686
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4687
|
+
);
|
4688
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4689
|
+
console.warn(
|
4690
|
+
`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.`
|
4691
|
+
);
|
4692
|
+
}
|
4693
|
+
return {
|
4694
|
+
fetch,
|
4695
|
+
databaseURL,
|
4696
|
+
apiKey,
|
4697
|
+
branch,
|
4698
|
+
cache,
|
4699
|
+
trace,
|
4700
|
+
host,
|
4701
|
+
clientID: generateUUID(),
|
4702
|
+
enableBrowser,
|
4703
|
+
clientName,
|
4704
|
+
xataAgentExtra
|
4705
|
+
};
|
4706
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4707
|
+
fetch,
|
4708
|
+
apiKey,
|
4709
|
+
databaseURL,
|
4710
|
+
branch,
|
4711
|
+
trace,
|
4712
|
+
clientID,
|
4713
|
+
clientName,
|
4714
|
+
xataAgentExtra
|
4715
|
+
}) {
|
3227
4716
|
return {
|
3228
|
-
|
4717
|
+
fetch,
|
3229
4718
|
apiKey,
|
3230
4719
|
apiUrl: "",
|
4720
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3231
4721
|
workspacesApiUrl: (path, params) => {
|
3232
4722
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3233
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4723
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3234
4724
|
return databaseURL + newPath;
|
3235
4725
|
},
|
3236
4726
|
trace,
|
3237
|
-
clientID
|
3238
|
-
|
3239
|
-
|
3240
|
-
if (__privateGet(this, _branch))
|
3241
|
-
return __privateGet(this, _branch);
|
3242
|
-
if (param === void 0)
|
3243
|
-
return void 0;
|
3244
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3245
|
-
const evaluateBranch = async (strategy) => {
|
3246
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
4727
|
+
clientID,
|
4728
|
+
clientName,
|
4729
|
+
xataAgentExtra
|
3247
4730
|
};
|
3248
|
-
for await (const strategy of strategies) {
|
3249
|
-
const branch = await evaluateBranch(strategy);
|
3250
|
-
if (branch) {
|
3251
|
-
__privateSet(this, _branch, branch);
|
3252
|
-
return branch;
|
3253
|
-
}
|
3254
|
-
}
|
3255
4731
|
}, _a;
|
3256
4732
|
};
|
3257
4733
|
class BaseClient extends buildClient() {
|
@@ -3324,21 +4800,6 @@ const deserialize = (json) => {
|
|
3324
4800
|
return defaultSerializer.fromJSON(json);
|
3325
4801
|
};
|
3326
4802
|
|
3327
|
-
function buildWorkerRunner(config) {
|
3328
|
-
return function xataWorker(name, _worker) {
|
3329
|
-
return async (...args) => {
|
3330
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3331
|
-
const result = await fetch(url, {
|
3332
|
-
method: "POST",
|
3333
|
-
headers: { "Content-Type": "application/json" },
|
3334
|
-
body: serialize({ args })
|
3335
|
-
});
|
3336
|
-
const text = await result.text();
|
3337
|
-
return deserialize(text);
|
3338
|
-
};
|
3339
|
-
};
|
3340
|
-
}
|
3341
|
-
|
3342
4803
|
class XataError extends Error {
|
3343
4804
|
constructor(message, status) {
|
3344
4805
|
super(message);
|
@@ -3347,6 +4808,8 @@ class XataError extends Error {
|
|
3347
4808
|
}
|
3348
4809
|
|
3349
4810
|
exports.BaseClient = BaseClient;
|
4811
|
+
exports.FetcherError = FetcherError;
|
4812
|
+
exports.FilesPlugin = FilesPlugin;
|
3350
4813
|
exports.Operations = operationsByTag;
|
3351
4814
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
3352
4815
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -3355,56 +4818,70 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
|
3355
4818
|
exports.Page = Page;
|
3356
4819
|
exports.Query = Query;
|
3357
4820
|
exports.RecordArray = RecordArray;
|
4821
|
+
exports.RecordColumnTypes = RecordColumnTypes;
|
3358
4822
|
exports.Repository = Repository;
|
3359
4823
|
exports.RestRepository = RestRepository;
|
4824
|
+
exports.SQLPlugin = SQLPlugin;
|
3360
4825
|
exports.SchemaPlugin = SchemaPlugin;
|
3361
4826
|
exports.SearchPlugin = SearchPlugin;
|
3362
4827
|
exports.Serializer = Serializer;
|
3363
4828
|
exports.SimpleCache = SimpleCache;
|
4829
|
+
exports.TransactionPlugin = TransactionPlugin;
|
3364
4830
|
exports.XataApiClient = XataApiClient;
|
3365
4831
|
exports.XataApiPlugin = XataApiPlugin;
|
3366
4832
|
exports.XataError = XataError;
|
4833
|
+
exports.XataFile = XataFile;
|
3367
4834
|
exports.XataPlugin = XataPlugin;
|
3368
4835
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
3369
4836
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
3370
4837
|
exports.addTableColumn = addTableColumn;
|
3371
4838
|
exports.aggregateTable = aggregateTable;
|
3372
4839
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4840
|
+
exports.applyMigration = applyMigration;
|
4841
|
+
exports.askTable = askTable;
|
4842
|
+
exports.askTableSession = askTableSession;
|
3373
4843
|
exports.branchTransaction = branchTransaction;
|
3374
4844
|
exports.buildClient = buildClient;
|
3375
|
-
exports.
|
4845
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4846
|
+
exports.buildProviderString = buildProviderString;
|
3376
4847
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
3377
4848
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
3378
4849
|
exports.compareBranchSchemas = compareBranchSchemas;
|
3379
4850
|
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3380
4851
|
exports.compareMigrationRequest = compareMigrationRequest;
|
3381
4852
|
exports.contains = contains;
|
4853
|
+
exports.copyBranch = copyBranch;
|
3382
4854
|
exports.createBranch = createBranch;
|
4855
|
+
exports.createCluster = createCluster;
|
3383
4856
|
exports.createDatabase = createDatabase;
|
3384
4857
|
exports.createMigrationRequest = createMigrationRequest;
|
3385
4858
|
exports.createTable = createTable;
|
3386
4859
|
exports.createUserAPIKey = createUserAPIKey;
|
3387
4860
|
exports.createWorkspace = createWorkspace;
|
3388
|
-
exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
|
3389
|
-
exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
|
3390
|
-
exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
|
3391
|
-
exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
|
3392
|
-
exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
|
3393
4861
|
exports.deleteBranch = deleteBranch;
|
3394
4862
|
exports.deleteColumn = deleteColumn;
|
3395
4863
|
exports.deleteDatabase = deleteDatabase;
|
4864
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4865
|
+
exports.deleteFile = deleteFile;
|
4866
|
+
exports.deleteFileItem = deleteFileItem;
|
4867
|
+
exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
|
3396
4868
|
exports.deleteRecord = deleteRecord;
|
3397
4869
|
exports.deleteTable = deleteTable;
|
3398
4870
|
exports.deleteUser = deleteUser;
|
3399
4871
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
4872
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
3400
4873
|
exports.deleteWorkspace = deleteWorkspace;
|
3401
4874
|
exports.deserialize = deserialize;
|
3402
4875
|
exports.endsWith = endsWith;
|
3403
4876
|
exports.equals = equals;
|
3404
4877
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
3405
4878
|
exports.exists = exists;
|
4879
|
+
exports.fileAccess = fileAccess;
|
4880
|
+
exports.fileUpload = fileUpload;
|
3406
4881
|
exports.ge = ge;
|
3407
4882
|
exports.getAPIKey = getAPIKey;
|
4883
|
+
exports.getAuthorizationCode = getAuthorizationCode;
|
4884
|
+
exports.getBranch = getBranch;
|
3408
4885
|
exports.getBranchDetails = getBranchDetails;
|
3409
4886
|
exports.getBranchList = getBranchList;
|
3410
4887
|
exports.getBranchMetadata = getBranchMetadata;
|
@@ -3412,29 +4889,38 @@ exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
|
3412
4889
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
3413
4890
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
3414
4891
|
exports.getBranchStats = getBranchStats;
|
4892
|
+
exports.getCluster = getCluster;
|
3415
4893
|
exports.getColumn = getColumn;
|
3416
|
-
exports.
|
3417
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
4894
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3418
4895
|
exports.getDatabaseList = getDatabaseList;
|
3419
4896
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
3420
4897
|
exports.getDatabaseURL = getDatabaseURL;
|
4898
|
+
exports.getFile = getFile;
|
4899
|
+
exports.getFileItem = getFileItem;
|
3421
4900
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3422
4901
|
exports.getHostUrl = getHostUrl;
|
3423
4902
|
exports.getMigrationRequest = getMigrationRequest;
|
3424
4903
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4904
|
+
exports.getPreviewBranch = getPreviewBranch;
|
3425
4905
|
exports.getRecord = getRecord;
|
4906
|
+
exports.getSchema = getSchema;
|
3426
4907
|
exports.getTableColumns = getTableColumns;
|
3427
4908
|
exports.getTableSchema = getTableSchema;
|
3428
4909
|
exports.getUser = getUser;
|
3429
4910
|
exports.getUserAPIKeys = getUserAPIKeys;
|
4911
|
+
exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
4912
|
+
exports.getUserOAuthClients = getUserOAuthClients;
|
3430
4913
|
exports.getWorkspace = getWorkspace;
|
3431
4914
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
3432
4915
|
exports.getWorkspacesList = getWorkspacesList;
|
4916
|
+
exports.grantAuthorizationCode = grantAuthorizationCode;
|
3433
4917
|
exports.greaterEquals = greaterEquals;
|
3434
4918
|
exports.greaterThan = greaterThan;
|
3435
4919
|
exports.greaterThanEquals = greaterThanEquals;
|
3436
4920
|
exports.gt = gt;
|
3437
4921
|
exports.gte = gte;
|
4922
|
+
exports.iContains = iContains;
|
4923
|
+
exports.iPattern = iPattern;
|
3438
4924
|
exports.includes = includes;
|
3439
4925
|
exports.includesAll = includesAll;
|
3440
4926
|
exports.includesAny = includesAny;
|
@@ -3448,11 +4934,14 @@ exports.isHostProviderAlias = isHostProviderAlias;
|
|
3448
4934
|
exports.isHostProviderBuilder = isHostProviderBuilder;
|
3449
4935
|
exports.isIdentifiable = isIdentifiable;
|
3450
4936
|
exports.isNot = isNot;
|
4937
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
4938
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
3451
4939
|
exports.isXataRecord = isXataRecord;
|
3452
4940
|
exports.le = le;
|
3453
4941
|
exports.lessEquals = lessEquals;
|
3454
4942
|
exports.lessThan = lessThan;
|
3455
4943
|
exports.lessThanEquals = lessThanEquals;
|
4944
|
+
exports.listClusters = listClusters;
|
3456
4945
|
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
3457
4946
|
exports.listRegions = listRegions;
|
3458
4947
|
exports.lt = lt;
|
@@ -3463,24 +4952,36 @@ exports.operationsByTag = operationsByTag;
|
|
3463
4952
|
exports.parseProviderString = parseProviderString;
|
3464
4953
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
3465
4954
|
exports.pattern = pattern;
|
4955
|
+
exports.pgRollJobStatus = pgRollJobStatus;
|
4956
|
+
exports.pgRollMigrationHistory = pgRollMigrationHistory;
|
4957
|
+
exports.pgRollStatus = pgRollStatus;
|
3466
4958
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4959
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
4960
|
+
exports.putFile = putFile;
|
4961
|
+
exports.putFileItem = putFileItem;
|
3467
4962
|
exports.queryMigrationRequests = queryMigrationRequests;
|
3468
4963
|
exports.queryTable = queryTable;
|
3469
4964
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
3470
4965
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
4966
|
+
exports.renameDatabase = renameDatabase;
|
3471
4967
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
3472
4968
|
exports.resolveBranch = resolveBranch;
|
3473
4969
|
exports.searchBranch = searchBranch;
|
3474
4970
|
exports.searchTable = searchTable;
|
3475
4971
|
exports.serialize = serialize;
|
3476
4972
|
exports.setTableSchema = setTableSchema;
|
4973
|
+
exports.sqlQuery = sqlQuery;
|
3477
4974
|
exports.startsWith = startsWith;
|
3478
4975
|
exports.summarizeTable = summarizeTable;
|
4976
|
+
exports.transformImage = transformImage;
|
3479
4977
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3480
4978
|
exports.updateBranchSchema = updateBranchSchema;
|
4979
|
+
exports.updateCluster = updateCluster;
|
3481
4980
|
exports.updateColumn = updateColumn;
|
4981
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3482
4982
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3483
4983
|
exports.updateMigrationRequest = updateMigrationRequest;
|
4984
|
+
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
3484
4985
|
exports.updateRecordWithID = updateRecordWithID;
|
3485
4986
|
exports.updateTable = updateTable;
|
3486
4987
|
exports.updateUser = updateUser;
|
@@ -3488,4 +4989,5 @@ exports.updateWorkspace = updateWorkspace;
|
|
3488
4989
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
3489
4990
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
3490
4991
|
exports.upsertRecordWithID = upsertRecordWithID;
|
4992
|
+
exports.vectorSearchTable = vectorSearchTable;
|
3491
4993
|
//# sourceMappingURL=index.cjs.map
|