@xata.io/client 0.0.0-alpha.vfa22996 → 0.0.0-alpha.vfaba5d6
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 +18 -0
- package/CHANGELOG.md +196 -0
- package/README.md +3 -269
- package/dist/index.cjs +1220 -337
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3034 -1622
- package/dist/index.mjs +1198 -331
- 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
|
}
|
@@ -28,8 +29,11 @@ function notEmpty(value) {
|
|
28
29
|
function compact(arr) {
|
29
30
|
return arr.filter(notEmpty);
|
30
31
|
}
|
32
|
+
function compactObject(obj) {
|
33
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
34
|
+
}
|
31
35
|
function isObject(value) {
|
32
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
36
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
33
37
|
}
|
34
38
|
function isDefined(value) {
|
35
39
|
return value !== null && value !== void 0;
|
@@ -92,8 +96,10 @@ function getEnvironment() {
|
|
92
96
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
93
97
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
94
98
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
95
|
-
|
96
|
-
|
99
|
+
deployPreview: process.env.XATA_PREVIEW,
|
100
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
101
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
102
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
97
103
|
};
|
98
104
|
}
|
99
105
|
} catch (err) {
|
@@ -104,8 +110,10 @@ function getEnvironment() {
|
|
104
110
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
105
111
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
106
112
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
107
|
-
|
108
|
-
|
113
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
114
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
115
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
116
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
109
117
|
};
|
110
118
|
}
|
111
119
|
} catch (err) {
|
@@ -114,8 +122,10 @@ function getEnvironment() {
|
|
114
122
|
apiKey: getGlobalApiKey(),
|
115
123
|
databaseURL: getGlobalDatabaseURL(),
|
116
124
|
branch: getGlobalBranch(),
|
117
|
-
|
118
|
-
|
125
|
+
deployPreview: void 0,
|
126
|
+
deployPreviewBranch: void 0,
|
127
|
+
vercelGitCommitRef: void 0,
|
128
|
+
vercelGitRepoOwner: void 0
|
119
129
|
};
|
120
130
|
}
|
121
131
|
function getEnableBrowserVariable() {
|
@@ -158,44 +168,59 @@ function getGlobalBranch() {
|
|
158
168
|
return void 0;
|
159
169
|
}
|
160
170
|
}
|
161
|
-
function
|
171
|
+
function getDatabaseURL() {
|
162
172
|
try {
|
163
|
-
|
173
|
+
const { databaseURL } = getEnvironment();
|
174
|
+
return databaseURL;
|
164
175
|
} catch (err) {
|
165
176
|
return void 0;
|
166
177
|
}
|
167
178
|
}
|
168
|
-
|
169
|
-
const cmd = ["git", "branch", "--show-current"];
|
170
|
-
const fullCmd = cmd.join(" ");
|
171
|
-
const nodeModule = ["child", "process"].join("_");
|
172
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
179
|
+
function getAPIKey() {
|
173
180
|
try {
|
174
|
-
|
175
|
-
|
176
|
-
}
|
177
|
-
const { execSync } = await import(nodeModule);
|
178
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
181
|
+
const { apiKey } = getEnvironment();
|
182
|
+
return apiKey;
|
179
183
|
} catch (err) {
|
184
|
+
return void 0;
|
180
185
|
}
|
186
|
+
}
|
187
|
+
function getBranch() {
|
181
188
|
try {
|
182
|
-
|
183
|
-
|
184
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
185
|
-
}
|
189
|
+
const { branch } = getEnvironment();
|
190
|
+
return branch ?? "main";
|
186
191
|
} catch (err) {
|
192
|
+
return void 0;
|
187
193
|
}
|
188
194
|
}
|
189
|
-
|
190
|
-
|
195
|
+
function buildPreviewBranchName({ org, branch }) {
|
196
|
+
return `preview-${org}-${branch}`;
|
197
|
+
}
|
198
|
+
function getPreviewBranch() {
|
191
199
|
try {
|
192
|
-
const {
|
193
|
-
|
200
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
201
|
+
if (deployPreviewBranch)
|
202
|
+
return deployPreviewBranch;
|
203
|
+
switch (deployPreview) {
|
204
|
+
case "vercel": {
|
205
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
206
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
207
|
+
return void 0;
|
208
|
+
}
|
209
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
210
|
+
}
|
211
|
+
}
|
212
|
+
return void 0;
|
194
213
|
} catch (err) {
|
195
214
|
return void 0;
|
196
215
|
}
|
197
216
|
}
|
198
217
|
|
218
|
+
var __defProp$7 = Object.defineProperty;
|
219
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
220
|
+
var __publicField$7 = (obj, key, value) => {
|
221
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
222
|
+
return value;
|
223
|
+
};
|
199
224
|
var __accessCheck$8 = (obj, member, msg) => {
|
200
225
|
if (!member.has(obj))
|
201
226
|
throw TypeError("Cannot " + msg);
|
@@ -235,6 +260,8 @@ class ApiRequestPool {
|
|
235
260
|
__privateAdd$8(this, _fetch, void 0);
|
236
261
|
__privateAdd$8(this, _queue, void 0);
|
237
262
|
__privateAdd$8(this, _concurrency, void 0);
|
263
|
+
__publicField$7(this, "running");
|
264
|
+
__publicField$7(this, "started");
|
238
265
|
__privateSet$8(this, _queue, []);
|
239
266
|
__privateSet$8(this, _concurrency, concurrency);
|
240
267
|
this.running = 0;
|
@@ -250,7 +277,7 @@ class ApiRequestPool {
|
|
250
277
|
return __privateGet$8(this, _fetch);
|
251
278
|
}
|
252
279
|
request(url, options) {
|
253
|
-
const start = new Date();
|
280
|
+
const start = /* @__PURE__ */ new Date();
|
254
281
|
const fetch2 = this.getFetch();
|
255
282
|
const runRequest = async (stalled = false) => {
|
256
283
|
const response = await fetch2(url, options);
|
@@ -260,7 +287,7 @@ class ApiRequestPool {
|
|
260
287
|
return await runRequest(true);
|
261
288
|
}
|
262
289
|
if (stalled) {
|
263
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
290
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
264
291
|
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
265
292
|
}
|
266
293
|
return response;
|
@@ -296,18 +323,208 @@ enqueue_fn = function(task) {
|
|
296
323
|
return promise;
|
297
324
|
};
|
298
325
|
|
299
|
-
|
326
|
+
function generateUUID() {
|
327
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
328
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
329
|
+
return v.toString(16);
|
330
|
+
});
|
331
|
+
}
|
332
|
+
|
333
|
+
async function getBytes(stream, onChunk) {
|
334
|
+
const reader = stream.getReader();
|
335
|
+
let result;
|
336
|
+
while (!(result = await reader.read()).done) {
|
337
|
+
onChunk(result.value);
|
338
|
+
}
|
339
|
+
}
|
340
|
+
function getLines(onLine) {
|
341
|
+
let buffer;
|
342
|
+
let position;
|
343
|
+
let fieldLength;
|
344
|
+
let discardTrailingNewline = false;
|
345
|
+
return function onChunk(arr) {
|
346
|
+
if (buffer === void 0) {
|
347
|
+
buffer = arr;
|
348
|
+
position = 0;
|
349
|
+
fieldLength = -1;
|
350
|
+
} else {
|
351
|
+
buffer = concat(buffer, arr);
|
352
|
+
}
|
353
|
+
const bufLength = buffer.length;
|
354
|
+
let lineStart = 0;
|
355
|
+
while (position < bufLength) {
|
356
|
+
if (discardTrailingNewline) {
|
357
|
+
if (buffer[position] === 10 /* NewLine */) {
|
358
|
+
lineStart = ++position;
|
359
|
+
}
|
360
|
+
discardTrailingNewline = false;
|
361
|
+
}
|
362
|
+
let lineEnd = -1;
|
363
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
364
|
+
switch (buffer[position]) {
|
365
|
+
case 58 /* Colon */:
|
366
|
+
if (fieldLength === -1) {
|
367
|
+
fieldLength = position - lineStart;
|
368
|
+
}
|
369
|
+
break;
|
370
|
+
case 13 /* CarriageReturn */:
|
371
|
+
discardTrailingNewline = true;
|
372
|
+
case 10 /* NewLine */:
|
373
|
+
lineEnd = position;
|
374
|
+
break;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
if (lineEnd === -1) {
|
378
|
+
break;
|
379
|
+
}
|
380
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
381
|
+
lineStart = position;
|
382
|
+
fieldLength = -1;
|
383
|
+
}
|
384
|
+
if (lineStart === bufLength) {
|
385
|
+
buffer = void 0;
|
386
|
+
} else if (lineStart !== 0) {
|
387
|
+
buffer = buffer.subarray(lineStart);
|
388
|
+
position -= lineStart;
|
389
|
+
}
|
390
|
+
};
|
391
|
+
}
|
392
|
+
function getMessages(onId, onRetry, onMessage) {
|
393
|
+
let message = newMessage();
|
394
|
+
const decoder = new TextDecoder();
|
395
|
+
return function onLine(line, fieldLength) {
|
396
|
+
if (line.length === 0) {
|
397
|
+
onMessage?.(message);
|
398
|
+
message = newMessage();
|
399
|
+
} else if (fieldLength > 0) {
|
400
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
401
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
402
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
403
|
+
switch (field) {
|
404
|
+
case "data":
|
405
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
406
|
+
break;
|
407
|
+
case "event":
|
408
|
+
message.event = value;
|
409
|
+
break;
|
410
|
+
case "id":
|
411
|
+
onId(message.id = value);
|
412
|
+
break;
|
413
|
+
case "retry":
|
414
|
+
const retry = parseInt(value, 10);
|
415
|
+
if (!isNaN(retry)) {
|
416
|
+
onRetry(message.retry = retry);
|
417
|
+
}
|
418
|
+
break;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
};
|
422
|
+
}
|
423
|
+
function concat(a, b) {
|
424
|
+
const res = new Uint8Array(a.length + b.length);
|
425
|
+
res.set(a);
|
426
|
+
res.set(b, a.length);
|
427
|
+
return res;
|
428
|
+
}
|
429
|
+
function newMessage() {
|
430
|
+
return {
|
431
|
+
data: "",
|
432
|
+
event: "",
|
433
|
+
id: "",
|
434
|
+
retry: void 0
|
435
|
+
};
|
436
|
+
}
|
437
|
+
const EventStreamContentType = "text/event-stream";
|
438
|
+
const LastEventId = "last-event-id";
|
439
|
+
function fetchEventSource(input, {
|
440
|
+
signal: inputSignal,
|
441
|
+
headers: inputHeaders,
|
442
|
+
onopen: inputOnOpen,
|
443
|
+
onmessage,
|
444
|
+
onclose,
|
445
|
+
onerror,
|
446
|
+
fetch: inputFetch,
|
447
|
+
...rest
|
448
|
+
}) {
|
449
|
+
return new Promise((resolve, reject) => {
|
450
|
+
const headers = { ...inputHeaders };
|
451
|
+
if (!headers.accept) {
|
452
|
+
headers.accept = EventStreamContentType;
|
453
|
+
}
|
454
|
+
let curRequestController;
|
455
|
+
function dispose() {
|
456
|
+
curRequestController.abort();
|
457
|
+
}
|
458
|
+
inputSignal?.addEventListener("abort", () => {
|
459
|
+
dispose();
|
460
|
+
resolve();
|
461
|
+
});
|
462
|
+
const fetchImpl = inputFetch ?? fetch;
|
463
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
464
|
+
async function create() {
|
465
|
+
curRequestController = new AbortController();
|
466
|
+
try {
|
467
|
+
const response = await fetchImpl(input, {
|
468
|
+
...rest,
|
469
|
+
headers,
|
470
|
+
signal: curRequestController.signal
|
471
|
+
});
|
472
|
+
await onopen(response);
|
473
|
+
await getBytes(
|
474
|
+
response.body,
|
475
|
+
getLines(
|
476
|
+
getMessages(
|
477
|
+
(id) => {
|
478
|
+
if (id) {
|
479
|
+
headers[LastEventId] = id;
|
480
|
+
} else {
|
481
|
+
delete headers[LastEventId];
|
482
|
+
}
|
483
|
+
},
|
484
|
+
(_retry) => {
|
485
|
+
},
|
486
|
+
onmessage
|
487
|
+
)
|
488
|
+
)
|
489
|
+
);
|
490
|
+
onclose?.();
|
491
|
+
dispose();
|
492
|
+
resolve();
|
493
|
+
} catch (err) {
|
494
|
+
}
|
495
|
+
}
|
496
|
+
create();
|
497
|
+
});
|
498
|
+
}
|
499
|
+
function defaultOnOpen(response) {
|
500
|
+
const contentType = response.headers?.get("content-type");
|
501
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
502
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
503
|
+
}
|
504
|
+
}
|
505
|
+
|
506
|
+
const VERSION = "0.24.3";
|
300
507
|
|
508
|
+
var __defProp$6 = Object.defineProperty;
|
509
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
510
|
+
var __publicField$6 = (obj, key, value) => {
|
511
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
512
|
+
return value;
|
513
|
+
};
|
301
514
|
class ErrorWithCause extends Error {
|
302
515
|
constructor(message, options) {
|
303
516
|
super(message, options);
|
517
|
+
__publicField$6(this, "cause");
|
304
518
|
}
|
305
519
|
}
|
306
520
|
class FetcherError extends ErrorWithCause {
|
307
521
|
constructor(status, data, requestId) {
|
308
522
|
super(getMessage(data));
|
523
|
+
__publicField$6(this, "status");
|
524
|
+
__publicField$6(this, "requestId");
|
525
|
+
__publicField$6(this, "errors");
|
309
526
|
this.status = status;
|
310
|
-
this.errors = isBulkError(data) ? data.errors :
|
527
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
311
528
|
this.requestId = requestId;
|
312
529
|
if (data instanceof Error) {
|
313
530
|
this.stack = data.stack;
|
@@ -372,14 +589,24 @@ function hostHeader(url) {
|
|
372
589
|
const { groups } = pattern.exec(url) ?? {};
|
373
590
|
return groups?.host ? { Host: groups.host } : {};
|
374
591
|
}
|
592
|
+
function parseBody(body, headers) {
|
593
|
+
if (!isDefined(body))
|
594
|
+
return void 0;
|
595
|
+
const { "Content-Type": contentType } = headers ?? {};
|
596
|
+
if (String(contentType).toLowerCase() === "application/json") {
|
597
|
+
return JSON.stringify(body);
|
598
|
+
}
|
599
|
+
return body;
|
600
|
+
}
|
601
|
+
const defaultClientID = generateUUID();
|
375
602
|
async function fetch$1({
|
376
603
|
url: path,
|
377
604
|
method,
|
378
605
|
body,
|
379
|
-
headers,
|
606
|
+
headers: customHeaders,
|
380
607
|
pathParams,
|
381
608
|
queryParams,
|
382
|
-
|
609
|
+
fetch: fetch2,
|
383
610
|
apiKey,
|
384
611
|
endpoint,
|
385
612
|
apiUrl,
|
@@ -388,9 +615,12 @@ async function fetch$1({
|
|
388
615
|
signal,
|
389
616
|
clientID,
|
390
617
|
sessionID,
|
391
|
-
|
618
|
+
clientName,
|
619
|
+
xataAgentExtra,
|
620
|
+
fetchOptions = {},
|
621
|
+
rawResponse = false
|
392
622
|
}) {
|
393
|
-
pool.setFetch(
|
623
|
+
pool.setFetch(fetch2);
|
394
624
|
return await trace(
|
395
625
|
`${method.toUpperCase()} ${path}`,
|
396
626
|
async ({ setAttributes }) => {
|
@@ -401,19 +631,27 @@ async function fetch$1({
|
|
401
631
|
[TraceAttributes.HTTP_URL]: url,
|
402
632
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
403
633
|
});
|
634
|
+
const xataAgent = compact([
|
635
|
+
["client", "TS_SDK"],
|
636
|
+
["version", VERSION],
|
637
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
638
|
+
...Object.entries(xataAgentExtra ?? {})
|
639
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
640
|
+
const headers = compactObject({
|
641
|
+
"Accept-Encoding": "identity",
|
642
|
+
"Content-Type": "application/json",
|
643
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
644
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
645
|
+
"X-Xata-Agent": xataAgent,
|
646
|
+
...customHeaders,
|
647
|
+
...hostHeader(fullUrl),
|
648
|
+
Authorization: `Bearer ${apiKey}`
|
649
|
+
});
|
404
650
|
const response = await pool.request(url, {
|
405
651
|
...fetchOptions,
|
406
652
|
method: method.toUpperCase(),
|
407
|
-
body: body
|
408
|
-
headers
|
409
|
-
"Content-Type": "application/json",
|
410
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
411
|
-
"X-Xata-Client-ID": clientID ?? "",
|
412
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
413
|
-
...headers,
|
414
|
-
...hostHeader(fullUrl),
|
415
|
-
Authorization: `Bearer ${apiKey}`
|
416
|
-
},
|
653
|
+
body: parseBody(body, headers),
|
654
|
+
headers,
|
417
655
|
signal
|
418
656
|
});
|
419
657
|
const { host, protocol } = parseUrl(response.url);
|
@@ -425,6 +663,9 @@ async function fetch$1({
|
|
425
663
|
[TraceAttributes.HTTP_HOST]: host,
|
426
664
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
427
665
|
});
|
666
|
+
const message = response.headers?.get("x-xata-message");
|
667
|
+
if (message)
|
668
|
+
console.warn(message);
|
428
669
|
if (response.status === 204) {
|
429
670
|
return {};
|
430
671
|
}
|
@@ -432,7 +673,7 @@ async function fetch$1({
|
|
432
673
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
433
674
|
}
|
434
675
|
try {
|
435
|
-
const jsonResponse = await response.json();
|
676
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
436
677
|
if (response.ok) {
|
437
678
|
return jsonResponse;
|
438
679
|
}
|
@@ -444,6 +685,59 @@ async function fetch$1({
|
|
444
685
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
445
686
|
);
|
446
687
|
}
|
688
|
+
function fetchSSERequest({
|
689
|
+
url: path,
|
690
|
+
method,
|
691
|
+
body,
|
692
|
+
headers: customHeaders,
|
693
|
+
pathParams,
|
694
|
+
queryParams,
|
695
|
+
fetch: fetch2,
|
696
|
+
apiKey,
|
697
|
+
endpoint,
|
698
|
+
apiUrl,
|
699
|
+
workspacesApiUrl,
|
700
|
+
onMessage,
|
701
|
+
onError,
|
702
|
+
onClose,
|
703
|
+
signal,
|
704
|
+
clientID,
|
705
|
+
sessionID,
|
706
|
+
clientName,
|
707
|
+
xataAgentExtra
|
708
|
+
}) {
|
709
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
710
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
711
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
712
|
+
void fetchEventSource(url, {
|
713
|
+
method,
|
714
|
+
body: JSON.stringify(body),
|
715
|
+
fetch: fetch2,
|
716
|
+
signal,
|
717
|
+
headers: {
|
718
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
719
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
720
|
+
"X-Xata-Agent": compact([
|
721
|
+
["client", "TS_SDK"],
|
722
|
+
["version", VERSION],
|
723
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
724
|
+
...Object.entries(xataAgentExtra ?? {})
|
725
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
726
|
+
...customHeaders,
|
727
|
+
Authorization: `Bearer ${apiKey}`,
|
728
|
+
"Content-Type": "application/json"
|
729
|
+
},
|
730
|
+
onmessage(ev) {
|
731
|
+
onMessage?.(JSON.parse(ev.data));
|
732
|
+
},
|
733
|
+
onerror(ev) {
|
734
|
+
onError?.(JSON.parse(ev.data));
|
735
|
+
},
|
736
|
+
onclose() {
|
737
|
+
onClose?.();
|
738
|
+
}
|
739
|
+
});
|
740
|
+
}
|
447
741
|
function parseUrl(url) {
|
448
742
|
try {
|
449
743
|
const { host, protocol } = new URL(url);
|
@@ -455,17 +749,12 @@ function parseUrl(url) {
|
|
455
749
|
|
456
750
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
457
751
|
|
458
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
459
752
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
460
753
|
url: "/dbs/{dbName}",
|
461
754
|
method: "get",
|
462
755
|
...variables,
|
463
756
|
signal
|
464
757
|
});
|
465
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
466
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
467
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
468
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
469
758
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
470
759
|
url: "/db/{dbBranchName}",
|
471
760
|
method: "get",
|
@@ -479,6 +768,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
479
768
|
...variables,
|
480
769
|
signal
|
481
770
|
});
|
771
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
772
|
+
url: "/db/{dbBranchName}/copy",
|
773
|
+
method: "post",
|
774
|
+
...variables,
|
775
|
+
signal
|
776
|
+
});
|
482
777
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
483
778
|
url: "/db/{dbBranchName}/metadata",
|
484
779
|
method: "put",
|
@@ -504,7 +799,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
504
799
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
505
800
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
506
801
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
507
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
508
802
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
509
803
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
510
804
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -529,6 +823,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
529
823
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
530
824
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
531
825
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
826
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
532
827
|
const createTable = (variables, signal) => dataPlaneFetch({
|
533
828
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
534
829
|
method: "put",
|
@@ -571,7 +866,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
571
866
|
...variables,
|
572
867
|
signal
|
573
868
|
});
|
869
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
574
870
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
871
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
872
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
873
|
+
method: "get",
|
874
|
+
...variables,
|
875
|
+
signal
|
876
|
+
});
|
877
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
878
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
879
|
+
method: "put",
|
880
|
+
...variables,
|
881
|
+
signal
|
882
|
+
});
|
883
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
884
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
885
|
+
method: "delete",
|
886
|
+
...variables,
|
887
|
+
signal
|
888
|
+
});
|
889
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
890
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
891
|
+
method: "get",
|
892
|
+
...variables,
|
893
|
+
signal
|
894
|
+
});
|
895
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
896
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
897
|
+
method: "put",
|
898
|
+
...variables,
|
899
|
+
signal
|
900
|
+
});
|
901
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
902
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
903
|
+
method: "delete",
|
904
|
+
...variables,
|
905
|
+
signal
|
906
|
+
});
|
575
907
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
576
908
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
577
909
|
method: "get",
|
@@ -601,21 +933,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
601
933
|
...variables,
|
602
934
|
signal
|
603
935
|
});
|
936
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
937
|
+
url: "/db/{dbBranchName}/sql",
|
938
|
+
method: "post",
|
939
|
+
...variables,
|
940
|
+
signal
|
941
|
+
});
|
942
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
943
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
944
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
945
|
+
method: "post",
|
946
|
+
...variables,
|
947
|
+
signal
|
948
|
+
});
|
949
|
+
const chatSessionMessage = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
604
950
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
605
951
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
952
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
953
|
+
url: "/file/{fileId}",
|
954
|
+
method: "get",
|
955
|
+
...variables,
|
956
|
+
signal
|
957
|
+
});
|
606
958
|
const operationsByTag$2 = {
|
607
|
-
database: {
|
608
|
-
dEPRECATEDgetDatabaseList,
|
609
|
-
dEPRECATEDcreateDatabase,
|
610
|
-
dEPRECATEDdeleteDatabase,
|
611
|
-
dEPRECATEDgetDatabaseMetadata,
|
612
|
-
dEPRECATEDupdateDatabaseMetadata
|
613
|
-
},
|
614
959
|
branch: {
|
615
960
|
getBranchList,
|
616
961
|
getBranchDetails,
|
617
962
|
createBranch,
|
618
963
|
deleteBranch,
|
964
|
+
copyBranch,
|
619
965
|
updateBranchMetadata,
|
620
966
|
getBranchMetadata,
|
621
967
|
getBranchStats,
|
@@ -633,17 +979,8 @@ const operationsByTag$2 = {
|
|
633
979
|
compareBranchSchemas,
|
634
980
|
updateBranchSchema,
|
635
981
|
previewBranchSchemaEdit,
|
636
|
-
applyBranchSchemaEdit
|
637
|
-
|
638
|
-
records: {
|
639
|
-
branchTransaction,
|
640
|
-
insertRecord,
|
641
|
-
getRecord,
|
642
|
-
insertRecordWithID,
|
643
|
-
updateRecordWithID,
|
644
|
-
upsertRecordWithID,
|
645
|
-
deleteRecord,
|
646
|
-
bulkInsertTableRecords
|
982
|
+
applyBranchSchemaEdit,
|
983
|
+
pushBranchMigrations
|
647
984
|
},
|
648
985
|
migrationRequests: {
|
649
986
|
queryMigrationRequests,
|
@@ -667,7 +1004,28 @@ const operationsByTag$2 = {
|
|
667
1004
|
updateColumn,
|
668
1005
|
deleteColumn
|
669
1006
|
},
|
670
|
-
|
1007
|
+
records: {
|
1008
|
+
branchTransaction,
|
1009
|
+
insertRecord,
|
1010
|
+
getRecord,
|
1011
|
+
insertRecordWithID,
|
1012
|
+
updateRecordWithID,
|
1013
|
+
upsertRecordWithID,
|
1014
|
+
deleteRecord,
|
1015
|
+
bulkInsertTableRecords
|
1016
|
+
},
|
1017
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1018
|
+
searchAndFilter: {
|
1019
|
+
queryTable,
|
1020
|
+
searchBranch,
|
1021
|
+
searchTable,
|
1022
|
+
sqlQuery,
|
1023
|
+
vectorSearchTable,
|
1024
|
+
askTable,
|
1025
|
+
chatSessionMessage,
|
1026
|
+
summarizeTable,
|
1027
|
+
aggregateTable
|
1028
|
+
}
|
671
1029
|
};
|
672
1030
|
|
673
1031
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -766,6 +1124,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
766
1124
|
});
|
767
1125
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
768
1126
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1127
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1128
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1129
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1130
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
769
1131
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
770
1132
|
url: "/workspaces/{workspaceId}/regions",
|
771
1133
|
method: "get",
|
@@ -798,6 +1160,10 @@ const operationsByTag$1 = {
|
|
798
1160
|
deleteDatabase,
|
799
1161
|
getDatabaseMetadata,
|
800
1162
|
updateDatabaseMetadata,
|
1163
|
+
renameDatabase,
|
1164
|
+
getDatabaseGithubSettings,
|
1165
|
+
updateDatabaseGithubSettings,
|
1166
|
+
deleteDatabaseGithubSettings,
|
801
1167
|
listRegions
|
802
1168
|
}
|
803
1169
|
};
|
@@ -818,8 +1184,12 @@ const providers = {
|
|
818
1184
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
819
1185
|
},
|
820
1186
|
staging: {
|
821
|
-
main: "https://staging.
|
822
|
-
workspaces: "https://{workspaceId}.
|
1187
|
+
main: "https://api.staging-xata.dev",
|
1188
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1189
|
+
},
|
1190
|
+
dev: {
|
1191
|
+
main: "https://api.dev-xata.dev",
|
1192
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
823
1193
|
}
|
824
1194
|
};
|
825
1195
|
function isHostProviderAlias(alias) {
|
@@ -837,15 +1207,22 @@ function parseProviderString(provider = "production") {
|
|
837
1207
|
return null;
|
838
1208
|
return { main, workspaces };
|
839
1209
|
}
|
1210
|
+
function buildProviderString(provider) {
|
1211
|
+
if (isHostProviderAlias(provider))
|
1212
|
+
return provider;
|
1213
|
+
return `${provider.main},${provider.workspaces}`;
|
1214
|
+
}
|
840
1215
|
function parseWorkspacesUrlParts(url) {
|
841
1216
|
if (!isString(url))
|
842
1217
|
return null;
|
843
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
844
|
-
const
|
845
|
-
const
|
1218
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1219
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1220
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1221
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1222
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
846
1223
|
if (!match)
|
847
1224
|
return null;
|
848
|
-
return { workspace: match[1], region: match[2]
|
1225
|
+
return { workspace: match[1], region: match[2] };
|
849
1226
|
}
|
850
1227
|
|
851
1228
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -874,15 +1251,19 @@ class XataApiClient {
|
|
874
1251
|
const provider = options.host ?? "production";
|
875
1252
|
const apiKey = options.apiKey ?? getAPIKey();
|
876
1253
|
const trace = options.trace ?? defaultTrace;
|
1254
|
+
const clientID = generateUUID();
|
877
1255
|
if (!apiKey) {
|
878
1256
|
throw new Error("Could not resolve a valid apiKey");
|
879
1257
|
}
|
880
1258
|
__privateSet$7(this, _extraProps, {
|
881
1259
|
apiUrl: getHostUrl(provider, "main"),
|
882
1260
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
883
|
-
|
1261
|
+
fetch: getFetchImplementation(options.fetch),
|
884
1262
|
apiKey,
|
885
|
-
trace
|
1263
|
+
trace,
|
1264
|
+
clientName: options.clientName,
|
1265
|
+
xataAgentExtra: options.xataAgentExtra,
|
1266
|
+
clientID
|
886
1267
|
});
|
887
1268
|
}
|
888
1269
|
get user() {
|
@@ -935,6 +1316,11 @@ class XataApiClient {
|
|
935
1316
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
936
1317
|
return __privateGet$7(this, _namespaces).records;
|
937
1318
|
}
|
1319
|
+
get files() {
|
1320
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1321
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1322
|
+
return __privateGet$7(this, _namespaces).files;
|
1323
|
+
}
|
938
1324
|
get searchAndFilter() {
|
939
1325
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
940
1326
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1143,6 +1529,20 @@ class BranchApi {
|
|
1143
1529
|
...this.extraProps
|
1144
1530
|
});
|
1145
1531
|
}
|
1532
|
+
copyBranch({
|
1533
|
+
workspace,
|
1534
|
+
region,
|
1535
|
+
database,
|
1536
|
+
branch,
|
1537
|
+
destinationBranch,
|
1538
|
+
limit
|
1539
|
+
}) {
|
1540
|
+
return operationsByTag.branch.copyBranch({
|
1541
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1542
|
+
body: { destinationBranch, limit },
|
1543
|
+
...this.extraProps
|
1544
|
+
});
|
1545
|
+
}
|
1146
1546
|
updateBranchMetadata({
|
1147
1547
|
workspace,
|
1148
1548
|
region,
|
@@ -1498,6 +1898,164 @@ class RecordsApi {
|
|
1498
1898
|
});
|
1499
1899
|
}
|
1500
1900
|
}
|
1901
|
+
class FilesApi {
|
1902
|
+
constructor(extraProps) {
|
1903
|
+
this.extraProps = extraProps;
|
1904
|
+
}
|
1905
|
+
getFileItem({
|
1906
|
+
workspace,
|
1907
|
+
region,
|
1908
|
+
database,
|
1909
|
+
branch,
|
1910
|
+
table,
|
1911
|
+
record,
|
1912
|
+
column,
|
1913
|
+
fileId
|
1914
|
+
}) {
|
1915
|
+
return operationsByTag.files.getFileItem({
|
1916
|
+
pathParams: {
|
1917
|
+
workspace,
|
1918
|
+
region,
|
1919
|
+
dbBranchName: `${database}:${branch}`,
|
1920
|
+
tableName: table,
|
1921
|
+
recordId: record,
|
1922
|
+
columnName: column,
|
1923
|
+
fileId
|
1924
|
+
},
|
1925
|
+
...this.extraProps
|
1926
|
+
});
|
1927
|
+
}
|
1928
|
+
putFileItem({
|
1929
|
+
workspace,
|
1930
|
+
region,
|
1931
|
+
database,
|
1932
|
+
branch,
|
1933
|
+
table,
|
1934
|
+
record,
|
1935
|
+
column,
|
1936
|
+
fileId,
|
1937
|
+
file
|
1938
|
+
}) {
|
1939
|
+
return operationsByTag.files.putFileItem({
|
1940
|
+
pathParams: {
|
1941
|
+
workspace,
|
1942
|
+
region,
|
1943
|
+
dbBranchName: `${database}:${branch}`,
|
1944
|
+
tableName: table,
|
1945
|
+
recordId: record,
|
1946
|
+
columnName: column,
|
1947
|
+
fileId
|
1948
|
+
},
|
1949
|
+
// @ts-ignore
|
1950
|
+
body: file,
|
1951
|
+
...this.extraProps
|
1952
|
+
});
|
1953
|
+
}
|
1954
|
+
deleteFileItem({
|
1955
|
+
workspace,
|
1956
|
+
region,
|
1957
|
+
database,
|
1958
|
+
branch,
|
1959
|
+
table,
|
1960
|
+
record,
|
1961
|
+
column,
|
1962
|
+
fileId
|
1963
|
+
}) {
|
1964
|
+
return operationsByTag.files.deleteFileItem({
|
1965
|
+
pathParams: {
|
1966
|
+
workspace,
|
1967
|
+
region,
|
1968
|
+
dbBranchName: `${database}:${branch}`,
|
1969
|
+
tableName: table,
|
1970
|
+
recordId: record,
|
1971
|
+
columnName: column,
|
1972
|
+
fileId
|
1973
|
+
},
|
1974
|
+
...this.extraProps
|
1975
|
+
});
|
1976
|
+
}
|
1977
|
+
getFile({
|
1978
|
+
workspace,
|
1979
|
+
region,
|
1980
|
+
database,
|
1981
|
+
branch,
|
1982
|
+
table,
|
1983
|
+
record,
|
1984
|
+
column
|
1985
|
+
}) {
|
1986
|
+
return operationsByTag.files.getFile({
|
1987
|
+
pathParams: {
|
1988
|
+
workspace,
|
1989
|
+
region,
|
1990
|
+
dbBranchName: `${database}:${branch}`,
|
1991
|
+
tableName: table,
|
1992
|
+
recordId: record,
|
1993
|
+
columnName: column
|
1994
|
+
},
|
1995
|
+
...this.extraProps
|
1996
|
+
});
|
1997
|
+
}
|
1998
|
+
putFile({
|
1999
|
+
workspace,
|
2000
|
+
region,
|
2001
|
+
database,
|
2002
|
+
branch,
|
2003
|
+
table,
|
2004
|
+
record,
|
2005
|
+
column,
|
2006
|
+
file
|
2007
|
+
}) {
|
2008
|
+
return operationsByTag.files.putFile({
|
2009
|
+
pathParams: {
|
2010
|
+
workspace,
|
2011
|
+
region,
|
2012
|
+
dbBranchName: `${database}:${branch}`,
|
2013
|
+
tableName: table,
|
2014
|
+
recordId: record,
|
2015
|
+
columnName: column
|
2016
|
+
},
|
2017
|
+
body: file,
|
2018
|
+
...this.extraProps
|
2019
|
+
});
|
2020
|
+
}
|
2021
|
+
deleteFile({
|
2022
|
+
workspace,
|
2023
|
+
region,
|
2024
|
+
database,
|
2025
|
+
branch,
|
2026
|
+
table,
|
2027
|
+
record,
|
2028
|
+
column
|
2029
|
+
}) {
|
2030
|
+
return operationsByTag.files.deleteFile({
|
2031
|
+
pathParams: {
|
2032
|
+
workspace,
|
2033
|
+
region,
|
2034
|
+
dbBranchName: `${database}:${branch}`,
|
2035
|
+
tableName: table,
|
2036
|
+
recordId: record,
|
2037
|
+
columnName: column
|
2038
|
+
},
|
2039
|
+
...this.extraProps
|
2040
|
+
});
|
2041
|
+
}
|
2042
|
+
fileAccess({
|
2043
|
+
workspace,
|
2044
|
+
region,
|
2045
|
+
fileId,
|
2046
|
+
verify
|
2047
|
+
}) {
|
2048
|
+
return operationsByTag.files.fileAccess({
|
2049
|
+
pathParams: {
|
2050
|
+
workspace,
|
2051
|
+
region,
|
2052
|
+
fileId
|
2053
|
+
},
|
2054
|
+
queryParams: { verify },
|
2055
|
+
...this.extraProps
|
2056
|
+
});
|
2057
|
+
}
|
2058
|
+
}
|
1501
2059
|
class SearchAndFilterApi {
|
1502
2060
|
constructor(extraProps) {
|
1503
2061
|
this.extraProps = extraProps;
|
@@ -1557,6 +2115,53 @@ class SearchAndFilterApi {
|
|
1557
2115
|
...this.extraProps
|
1558
2116
|
});
|
1559
2117
|
}
|
2118
|
+
vectorSearchTable({
|
2119
|
+
workspace,
|
2120
|
+
region,
|
2121
|
+
database,
|
2122
|
+
branch,
|
2123
|
+
table,
|
2124
|
+
queryVector,
|
2125
|
+
column,
|
2126
|
+
similarityFunction,
|
2127
|
+
size,
|
2128
|
+
filter
|
2129
|
+
}) {
|
2130
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2131
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2132
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2133
|
+
...this.extraProps
|
2134
|
+
});
|
2135
|
+
}
|
2136
|
+
askTable({
|
2137
|
+
workspace,
|
2138
|
+
region,
|
2139
|
+
database,
|
2140
|
+
branch,
|
2141
|
+
table,
|
2142
|
+
options
|
2143
|
+
}) {
|
2144
|
+
return operationsByTag.searchAndFilter.askTable({
|
2145
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2146
|
+
body: { ...options },
|
2147
|
+
...this.extraProps
|
2148
|
+
});
|
2149
|
+
}
|
2150
|
+
chatSessionMessage({
|
2151
|
+
workspace,
|
2152
|
+
region,
|
2153
|
+
database,
|
2154
|
+
branch,
|
2155
|
+
table,
|
2156
|
+
sessionId,
|
2157
|
+
message
|
2158
|
+
}) {
|
2159
|
+
return operationsByTag.searchAndFilter.chatSessionMessage({
|
2160
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2161
|
+
body: { message },
|
2162
|
+
...this.extraProps
|
2163
|
+
});
|
2164
|
+
}
|
1560
2165
|
summarizeTable({
|
1561
2166
|
workspace,
|
1562
2167
|
region,
|
@@ -1757,11 +2362,13 @@ class MigrationsApi {
|
|
1757
2362
|
region,
|
1758
2363
|
database,
|
1759
2364
|
branch,
|
1760
|
-
schema
|
2365
|
+
schema,
|
2366
|
+
schemaOperations,
|
2367
|
+
branchOperations
|
1761
2368
|
}) {
|
1762
2369
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1763
2370
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1764
|
-
body: { schema },
|
2371
|
+
body: { schema, schemaOperations, branchOperations },
|
1765
2372
|
...this.extraProps
|
1766
2373
|
});
|
1767
2374
|
}
|
@@ -1771,11 +2378,12 @@ class MigrationsApi {
|
|
1771
2378
|
database,
|
1772
2379
|
branch,
|
1773
2380
|
compare,
|
1774
|
-
|
2381
|
+
sourceBranchOperations,
|
2382
|
+
targetBranchOperations
|
1775
2383
|
}) {
|
1776
2384
|
return operationsByTag.migrations.compareBranchSchemas({
|
1777
2385
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1778
|
-
body: {
|
2386
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1779
2387
|
...this.extraProps
|
1780
2388
|
});
|
1781
2389
|
}
|
@@ -1818,6 +2426,19 @@ class MigrationsApi {
|
|
1818
2426
|
...this.extraProps
|
1819
2427
|
});
|
1820
2428
|
}
|
2429
|
+
pushBranchMigrations({
|
2430
|
+
workspace,
|
2431
|
+
region,
|
2432
|
+
database,
|
2433
|
+
branch,
|
2434
|
+
migrations
|
2435
|
+
}) {
|
2436
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2437
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2438
|
+
body: { migrations },
|
2439
|
+
...this.extraProps
|
2440
|
+
});
|
2441
|
+
}
|
1821
2442
|
}
|
1822
2443
|
class DatabaseApi {
|
1823
2444
|
constructor(extraProps) {
|
@@ -1869,6 +2490,46 @@ class DatabaseApi {
|
|
1869
2490
|
...this.extraProps
|
1870
2491
|
});
|
1871
2492
|
}
|
2493
|
+
renameDatabase({
|
2494
|
+
workspace,
|
2495
|
+
database,
|
2496
|
+
newName
|
2497
|
+
}) {
|
2498
|
+
return operationsByTag.databases.renameDatabase({
|
2499
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2500
|
+
body: { newName },
|
2501
|
+
...this.extraProps
|
2502
|
+
});
|
2503
|
+
}
|
2504
|
+
getDatabaseGithubSettings({
|
2505
|
+
workspace,
|
2506
|
+
database
|
2507
|
+
}) {
|
2508
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2509
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2510
|
+
...this.extraProps
|
2511
|
+
});
|
2512
|
+
}
|
2513
|
+
updateDatabaseGithubSettings({
|
2514
|
+
workspace,
|
2515
|
+
database,
|
2516
|
+
settings
|
2517
|
+
}) {
|
2518
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2519
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2520
|
+
body: settings,
|
2521
|
+
...this.extraProps
|
2522
|
+
});
|
2523
|
+
}
|
2524
|
+
deleteDatabaseGithubSettings({
|
2525
|
+
workspace,
|
2526
|
+
database
|
2527
|
+
}) {
|
2528
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2529
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2530
|
+
...this.extraProps
|
2531
|
+
});
|
2532
|
+
}
|
1872
2533
|
listRegions({ workspace }) {
|
1873
2534
|
return operationsByTag.databases.listRegions({
|
1874
2535
|
pathParams: { workspaceId: workspace },
|
@@ -1878,29 +2539,47 @@ class DatabaseApi {
|
|
1878
2539
|
}
|
1879
2540
|
|
1880
2541
|
class XataApiPlugin {
|
1881
|
-
|
1882
|
-
|
1883
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2542
|
+
build(options) {
|
2543
|
+
return new XataApiClient(options);
|
1884
2544
|
}
|
1885
2545
|
}
|
1886
2546
|
|
1887
2547
|
class XataPlugin {
|
1888
2548
|
}
|
1889
2549
|
|
1890
|
-
function generateUUID() {
|
1891
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1892
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1893
|
-
return v.toString(16);
|
1894
|
-
});
|
1895
|
-
}
|
1896
|
-
|
1897
2550
|
function cleanFilter(filter) {
|
1898
|
-
if (!filter)
|
2551
|
+
if (!isDefined(filter))
|
1899
2552
|
return void 0;
|
1900
|
-
|
1901
|
-
|
2553
|
+
if (!isObject(filter))
|
2554
|
+
return filter;
|
2555
|
+
const values = Object.fromEntries(
|
2556
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2557
|
+
if (!isDefined(value))
|
2558
|
+
return acc;
|
2559
|
+
if (Array.isArray(value)) {
|
2560
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2561
|
+
if (clean.length === 0)
|
2562
|
+
return acc;
|
2563
|
+
return [...acc, [key, clean]];
|
2564
|
+
}
|
2565
|
+
if (isObject(value)) {
|
2566
|
+
const clean = cleanFilter(value);
|
2567
|
+
if (!isDefined(clean))
|
2568
|
+
return acc;
|
2569
|
+
return [...acc, [key, clean]];
|
2570
|
+
}
|
2571
|
+
return [...acc, [key, value]];
|
2572
|
+
}, [])
|
2573
|
+
);
|
2574
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1902
2575
|
}
|
1903
2576
|
|
2577
|
+
var __defProp$5 = Object.defineProperty;
|
2578
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2579
|
+
var __publicField$5 = (obj, key, value) => {
|
2580
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2581
|
+
return value;
|
2582
|
+
};
|
1904
2583
|
var __accessCheck$6 = (obj, member, msg) => {
|
1905
2584
|
if (!member.has(obj))
|
1906
2585
|
throw TypeError("Cannot " + msg);
|
@@ -1923,22 +2602,58 @@ var _query, _page;
|
|
1923
2602
|
class Page {
|
1924
2603
|
constructor(query, meta, records = []) {
|
1925
2604
|
__privateAdd$6(this, _query, void 0);
|
2605
|
+
/**
|
2606
|
+
* Page metadata, required to retrieve additional records.
|
2607
|
+
*/
|
2608
|
+
__publicField$5(this, "meta");
|
2609
|
+
/**
|
2610
|
+
* The set of results for this page.
|
2611
|
+
*/
|
2612
|
+
__publicField$5(this, "records");
|
1926
2613
|
__privateSet$6(this, _query, query);
|
1927
2614
|
this.meta = meta;
|
1928
2615
|
this.records = new RecordArray(this, records);
|
1929
2616
|
}
|
2617
|
+
/**
|
2618
|
+
* Retrieves the next page of results.
|
2619
|
+
* @param size Maximum number of results to be retrieved.
|
2620
|
+
* @param offset Number of results to skip when retrieving the results.
|
2621
|
+
* @returns The next page or results.
|
2622
|
+
*/
|
1930
2623
|
async nextPage(size, offset) {
|
1931
2624
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1932
2625
|
}
|
2626
|
+
/**
|
2627
|
+
* Retrieves the previous page of results.
|
2628
|
+
* @param size Maximum number of results to be retrieved.
|
2629
|
+
* @param offset Number of results to skip when retrieving the results.
|
2630
|
+
* @returns The previous page or results.
|
2631
|
+
*/
|
1933
2632
|
async previousPage(size, offset) {
|
1934
2633
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1935
2634
|
}
|
2635
|
+
/**
|
2636
|
+
* Retrieves the start page of results.
|
2637
|
+
* @param size Maximum number of results to be retrieved.
|
2638
|
+
* @param offset Number of results to skip when retrieving the results.
|
2639
|
+
* @returns The start page or results.
|
2640
|
+
*/
|
1936
2641
|
async startPage(size, offset) {
|
1937
2642
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1938
2643
|
}
|
2644
|
+
/**
|
2645
|
+
* Retrieves the end page of results.
|
2646
|
+
* @param size Maximum number of results to be retrieved.
|
2647
|
+
* @param offset Number of results to skip when retrieving the results.
|
2648
|
+
* @returns The end page or results.
|
2649
|
+
*/
|
1939
2650
|
async endPage(size, offset) {
|
1940
2651
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1941
2652
|
}
|
2653
|
+
/**
|
2654
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2655
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2656
|
+
*/
|
1942
2657
|
hasNextPage() {
|
1943
2658
|
return this.meta.page.more;
|
1944
2659
|
}
|
@@ -1951,7 +2666,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1951
2666
|
function isCursorPaginationOptions(options) {
|
1952
2667
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1953
2668
|
}
|
1954
|
-
const _RecordArray = class extends Array {
|
2669
|
+
const _RecordArray = class _RecordArray extends Array {
|
1955
2670
|
constructor(...args) {
|
1956
2671
|
super(..._RecordArray.parseConstructorParams(...args));
|
1957
2672
|
__privateAdd$6(this, _page, void 0);
|
@@ -1970,32 +2685,67 @@ const _RecordArray = class extends Array {
|
|
1970
2685
|
toArray() {
|
1971
2686
|
return new Array(...this);
|
1972
2687
|
}
|
2688
|
+
toSerializable() {
|
2689
|
+
return JSON.parse(this.toString());
|
2690
|
+
}
|
2691
|
+
toString() {
|
2692
|
+
return JSON.stringify(this.toArray());
|
2693
|
+
}
|
1973
2694
|
map(callbackfn, thisArg) {
|
1974
2695
|
return this.toArray().map(callbackfn, thisArg);
|
1975
2696
|
}
|
2697
|
+
/**
|
2698
|
+
* Retrieve next page of records
|
2699
|
+
*
|
2700
|
+
* @returns A new array of objects
|
2701
|
+
*/
|
1976
2702
|
async nextPage(size, offset) {
|
1977
2703
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1978
2704
|
return new _RecordArray(newPage);
|
1979
2705
|
}
|
2706
|
+
/**
|
2707
|
+
* Retrieve previous page of records
|
2708
|
+
*
|
2709
|
+
* @returns A new array of objects
|
2710
|
+
*/
|
1980
2711
|
async previousPage(size, offset) {
|
1981
2712
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1982
2713
|
return new _RecordArray(newPage);
|
1983
2714
|
}
|
2715
|
+
/**
|
2716
|
+
* Retrieve start page of records
|
2717
|
+
*
|
2718
|
+
* @returns A new array of objects
|
2719
|
+
*/
|
1984
2720
|
async startPage(size, offset) {
|
1985
2721
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1986
2722
|
return new _RecordArray(newPage);
|
1987
2723
|
}
|
2724
|
+
/**
|
2725
|
+
* Retrieve end page of records
|
2726
|
+
*
|
2727
|
+
* @returns A new array of objects
|
2728
|
+
*/
|
1988
2729
|
async endPage(size, offset) {
|
1989
2730
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1990
2731
|
return new _RecordArray(newPage);
|
1991
2732
|
}
|
2733
|
+
/**
|
2734
|
+
* @returns Boolean indicating if there is a next page
|
2735
|
+
*/
|
1992
2736
|
hasNextPage() {
|
1993
2737
|
return __privateGet$6(this, _page).meta.page.more;
|
1994
2738
|
}
|
1995
2739
|
};
|
1996
|
-
let RecordArray = _RecordArray;
|
1997
2740
|
_page = new WeakMap();
|
2741
|
+
let RecordArray = _RecordArray;
|
1998
2742
|
|
2743
|
+
var __defProp$4 = Object.defineProperty;
|
2744
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2745
|
+
var __publicField$4 = (obj, key, value) => {
|
2746
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2747
|
+
return value;
|
2748
|
+
};
|
1999
2749
|
var __accessCheck$5 = (obj, member, msg) => {
|
2000
2750
|
if (!member.has(obj))
|
2001
2751
|
throw TypeError("Cannot " + msg);
|
@@ -2019,14 +2769,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2019
2769
|
return method;
|
2020
2770
|
};
|
2021
2771
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2022
|
-
const _Query = class {
|
2772
|
+
const _Query = class _Query {
|
2023
2773
|
constructor(repository, table, data, rawParent) {
|
2024
2774
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2025
2775
|
__privateAdd$5(this, _table$1, void 0);
|
2026
2776
|
__privateAdd$5(this, _repository, void 0);
|
2027
2777
|
__privateAdd$5(this, _data, { filter: {} });
|
2028
|
-
|
2029
|
-
this
|
2778
|
+
// Implements pagination
|
2779
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
2780
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2030
2781
|
__privateSet$5(this, _table$1, table);
|
2031
2782
|
if (repository) {
|
2032
2783
|
__privateSet$5(this, _repository, repository);
|
@@ -2041,6 +2792,7 @@ const _Query = class {
|
|
2041
2792
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
2042
2793
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
2043
2794
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2795
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
2044
2796
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
2045
2797
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2046
2798
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -2061,18 +2813,38 @@ const _Query = class {
|
|
2061
2813
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2062
2814
|
return toBase64(key);
|
2063
2815
|
}
|
2816
|
+
/**
|
2817
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
2818
|
+
* @param queries An array of subqueries.
|
2819
|
+
* @returns A new Query object.
|
2820
|
+
*/
|
2064
2821
|
any(...queries) {
|
2065
2822
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2066
2823
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2067
2824
|
}
|
2825
|
+
/**
|
2826
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
2827
|
+
* @param queries An array of subqueries.
|
2828
|
+
* @returns A new Query object.
|
2829
|
+
*/
|
2068
2830
|
all(...queries) {
|
2069
2831
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2070
2832
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2071
2833
|
}
|
2834
|
+
/**
|
2835
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
2836
|
+
* @param queries An array of subqueries.
|
2837
|
+
* @returns A new Query object.
|
2838
|
+
*/
|
2072
2839
|
not(...queries) {
|
2073
2840
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2074
2841
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2075
2842
|
}
|
2843
|
+
/**
|
2844
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
2845
|
+
* @param queries An array of subqueries.
|
2846
|
+
* @returns A new Query object.
|
2847
|
+
*/
|
2076
2848
|
none(...queries) {
|
2077
2849
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2078
2850
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2095,6 +2867,11 @@ const _Query = class {
|
|
2095
2867
|
const sort = [...originalSort, { column, direction }];
|
2096
2868
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2097
2869
|
}
|
2870
|
+
/**
|
2871
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
2872
|
+
* @param columns Array of column names to be returned by the query.
|
2873
|
+
* @returns A new Query object.
|
2874
|
+
*/
|
2098
2875
|
select(columns) {
|
2099
2876
|
return new _Query(
|
2100
2877
|
__privateGet$5(this, _repository),
|
@@ -2107,6 +2884,12 @@ const _Query = class {
|
|
2107
2884
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2108
2885
|
return __privateGet$5(this, _repository).query(query);
|
2109
2886
|
}
|
2887
|
+
/**
|
2888
|
+
* Get results in an iterator
|
2889
|
+
*
|
2890
|
+
* @async
|
2891
|
+
* @returns Async interable of results
|
2892
|
+
*/
|
2110
2893
|
async *[Symbol.asyncIterator]() {
|
2111
2894
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2112
2895
|
yield record;
|
@@ -2167,26 +2950,53 @@ const _Query = class {
|
|
2167
2950
|
);
|
2168
2951
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2169
2952
|
}
|
2953
|
+
/**
|
2954
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
2955
|
+
* @param ttl The cache TTL in milliseconds.
|
2956
|
+
* @returns A new Query object.
|
2957
|
+
*/
|
2170
2958
|
cache(ttl) {
|
2171
2959
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2172
2960
|
}
|
2961
|
+
/**
|
2962
|
+
* Retrieve next page of records
|
2963
|
+
*
|
2964
|
+
* @returns A new page object.
|
2965
|
+
*/
|
2173
2966
|
nextPage(size, offset) {
|
2174
2967
|
return this.startPage(size, offset);
|
2175
2968
|
}
|
2969
|
+
/**
|
2970
|
+
* Retrieve previous page of records
|
2971
|
+
*
|
2972
|
+
* @returns A new page object
|
2973
|
+
*/
|
2176
2974
|
previousPage(size, offset) {
|
2177
2975
|
return this.startPage(size, offset);
|
2178
2976
|
}
|
2977
|
+
/**
|
2978
|
+
* Retrieve start page of records
|
2979
|
+
*
|
2980
|
+
* @returns A new page object
|
2981
|
+
*/
|
2179
2982
|
startPage(size, offset) {
|
2180
2983
|
return this.getPaginated({ pagination: { size, offset } });
|
2181
2984
|
}
|
2985
|
+
/**
|
2986
|
+
* Retrieve last page of records
|
2987
|
+
*
|
2988
|
+
* @returns A new page object
|
2989
|
+
*/
|
2182
2990
|
endPage(size, offset) {
|
2183
2991
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2184
2992
|
}
|
2993
|
+
/**
|
2994
|
+
* @returns Boolean indicating if there is a next page
|
2995
|
+
*/
|
2185
2996
|
hasNextPage() {
|
2186
2997
|
return this.meta.page.more;
|
2187
2998
|
}
|
2188
2999
|
};
|
2189
|
-
let Query = _Query;
|
2190
3000
|
_table$1 = new WeakMap();
|
2191
3001
|
_repository = new WeakMap();
|
2192
3002
|
_data = new WeakMap();
|
@@ -2201,6 +3011,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2201
3011
|
}
|
2202
3012
|
return value;
|
2203
3013
|
};
|
3014
|
+
let Query = _Query;
|
2204
3015
|
function cleanParent(data, parent) {
|
2205
3016
|
if (isCursorPaginationOptions(data.pagination)) {
|
2206
3017
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2208,6 +3019,21 @@ function cleanParent(data, parent) {
|
|
2208
3019
|
return parent;
|
2209
3020
|
}
|
2210
3021
|
|
3022
|
+
const RecordColumnTypes = [
|
3023
|
+
"bool",
|
3024
|
+
"int",
|
3025
|
+
"float",
|
3026
|
+
"string",
|
3027
|
+
"text",
|
3028
|
+
"email",
|
3029
|
+
"multiple",
|
3030
|
+
"link",
|
3031
|
+
"object",
|
3032
|
+
"datetime",
|
3033
|
+
"vector",
|
3034
|
+
"file[]",
|
3035
|
+
"file"
|
3036
|
+
];
|
2211
3037
|
function isIdentifiable(x) {
|
2212
3038
|
return isObject(x) && isString(x?.id);
|
2213
3039
|
}
|
@@ -2221,7 +3047,11 @@ function isSortFilterString(value) {
|
|
2221
3047
|
return isString(value);
|
2222
3048
|
}
|
2223
3049
|
function isSortFilterBase(filter) {
|
2224
|
-
return isObject(filter) && Object.
|
3050
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3051
|
+
if (key === "*")
|
3052
|
+
return value === "random";
|
3053
|
+
return value === "asc" || value === "desc";
|
3054
|
+
});
|
2225
3055
|
}
|
2226
3056
|
function isSortFilterObject(filter) {
|
2227
3057
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2294,10 +3124,7 @@ class RestRepository extends Query {
|
|
2294
3124
|
__privateSet$4(this, _db, options.db);
|
2295
3125
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2296
3126
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2297
|
-
__privateSet$4(this, _getFetchProps,
|
2298
|
-
const props = await options.pluginOptions.getFetchProps();
|
2299
|
-
return { ...props, sessionID: generateUUID() };
|
2300
|
-
});
|
3127
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2301
3128
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2302
3129
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2303
3130
|
return trace(name, fn, {
|
@@ -2354,7 +3181,6 @@ class RestRepository extends Query {
|
|
2354
3181
|
}
|
2355
3182
|
const id = extractId(a);
|
2356
3183
|
if (id) {
|
2357
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2358
3184
|
try {
|
2359
3185
|
const response = await getRecord({
|
2360
3186
|
pathParams: {
|
@@ -2365,7 +3191,7 @@ class RestRepository extends Query {
|
|
2365
3191
|
recordId: id
|
2366
3192
|
},
|
2367
3193
|
queryParams: { columns },
|
2368
|
-
...
|
3194
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2369
3195
|
});
|
2370
3196
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2371
3197
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2414,13 +3240,19 @@ class RestRepository extends Query {
|
|
2414
3240
|
const result = await this.read(a, columns);
|
2415
3241
|
return result;
|
2416
3242
|
}
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
3243
|
+
try {
|
3244
|
+
if (isString(a) && isObject(b)) {
|
3245
|
+
const columns = isStringArray(c) ? c : void 0;
|
3246
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3247
|
+
}
|
3248
|
+
if (isObject(a) && isString(a.id)) {
|
3249
|
+
const columns = isStringArray(b) ? b : void 0;
|
3250
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3251
|
+
}
|
3252
|
+
} catch (error) {
|
3253
|
+
if (error.status === 422)
|
3254
|
+
return null;
|
3255
|
+
throw error;
|
2424
3256
|
}
|
2425
3257
|
throw new Error("Invalid arguments for update method");
|
2426
3258
|
});
|
@@ -2459,12 +3291,22 @@ class RestRepository extends Query {
|
|
2459
3291
|
return result;
|
2460
3292
|
}
|
2461
3293
|
if (isString(a) && isObject(b)) {
|
3294
|
+
if (a === "")
|
3295
|
+
throw new Error("The id can't be empty");
|
2462
3296
|
const columns = isStringArray(c) ? c : void 0;
|
2463
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3297
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2464
3298
|
}
|
2465
3299
|
if (isObject(a) && isString(a.id)) {
|
3300
|
+
if (a.id === "")
|
3301
|
+
throw new Error("The id can't be empty");
|
2466
3302
|
const columns = isStringArray(c) ? c : void 0;
|
2467
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3303
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3304
|
+
}
|
3305
|
+
if (!isDefined(a) && isObject(b)) {
|
3306
|
+
return await this.create(b, c);
|
3307
|
+
}
|
3308
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3309
|
+
return await this.create(a, b);
|
2468
3310
|
}
|
2469
3311
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2470
3312
|
});
|
@@ -2481,12 +3323,22 @@ class RestRepository extends Query {
|
|
2481
3323
|
return result;
|
2482
3324
|
}
|
2483
3325
|
if (isString(a) && isObject(b)) {
|
3326
|
+
if (a === "")
|
3327
|
+
throw new Error("The id can't be empty");
|
2484
3328
|
const columns = isStringArray(c) ? c : void 0;
|
2485
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3329
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2486
3330
|
}
|
2487
3331
|
if (isObject(a) && isString(a.id)) {
|
3332
|
+
if (a.id === "")
|
3333
|
+
throw new Error("The id can't be empty");
|
2488
3334
|
const columns = isStringArray(c) ? c : void 0;
|
2489
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3335
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3336
|
+
}
|
3337
|
+
if (!isDefined(a) && isObject(b)) {
|
3338
|
+
return await this.create(b, c);
|
3339
|
+
}
|
3340
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3341
|
+
return await this.create(a, b);
|
2490
3342
|
}
|
2491
3343
|
throw new Error("Invalid arguments for createOrReplace method");
|
2492
3344
|
});
|
@@ -2537,7 +3389,6 @@ class RestRepository extends Query {
|
|
2537
3389
|
}
|
2538
3390
|
async search(query, options = {}) {
|
2539
3391
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2540
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2541
3392
|
const { records } = await searchTable({
|
2542
3393
|
pathParams: {
|
2543
3394
|
workspace: "{workspaceId}",
|
@@ -2551,9 +3402,33 @@ class RestRepository extends Query {
|
|
2551
3402
|
prefix: options.prefix,
|
2552
3403
|
highlight: options.highlight,
|
2553
3404
|
filter: options.filter,
|
2554
|
-
boosters: options.boosters
|
3405
|
+
boosters: options.boosters,
|
3406
|
+
page: options.page,
|
3407
|
+
target: options.target
|
2555
3408
|
},
|
2556
|
-
...
|
3409
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3410
|
+
});
|
3411
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3412
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3413
|
+
});
|
3414
|
+
}
|
3415
|
+
async vectorSearch(column, query, options) {
|
3416
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3417
|
+
const { records } = await vectorSearchTable({
|
3418
|
+
pathParams: {
|
3419
|
+
workspace: "{workspaceId}",
|
3420
|
+
dbBranchName: "{dbBranch}",
|
3421
|
+
region: "{region}",
|
3422
|
+
tableName: __privateGet$4(this, _table)
|
3423
|
+
},
|
3424
|
+
body: {
|
3425
|
+
column,
|
3426
|
+
queryVector: query,
|
3427
|
+
similarityFunction: options?.similarityFunction,
|
3428
|
+
size: options?.size,
|
3429
|
+
filter: options?.filter
|
3430
|
+
},
|
3431
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2557
3432
|
});
|
2558
3433
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2559
3434
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2561,7 +3436,6 @@ class RestRepository extends Query {
|
|
2561
3436
|
}
|
2562
3437
|
async aggregate(aggs, filter) {
|
2563
3438
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2564
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2565
3439
|
const result = await aggregateTable({
|
2566
3440
|
pathParams: {
|
2567
3441
|
workspace: "{workspaceId}",
|
@@ -2570,7 +3444,7 @@ class RestRepository extends Query {
|
|
2570
3444
|
tableName: __privateGet$4(this, _table)
|
2571
3445
|
},
|
2572
3446
|
body: { aggs, filter },
|
2573
|
-
...
|
3447
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2574
3448
|
});
|
2575
3449
|
return result;
|
2576
3450
|
});
|
@@ -2581,7 +3455,6 @@ class RestRepository extends Query {
|
|
2581
3455
|
if (cacheQuery)
|
2582
3456
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2583
3457
|
const data = query.getQueryOptions();
|
2584
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2585
3458
|
const { meta, records: objects } = await queryTable({
|
2586
3459
|
pathParams: {
|
2587
3460
|
workspace: "{workspaceId}",
|
@@ -2593,10 +3466,11 @@ class RestRepository extends Query {
|
|
2593
3466
|
filter: cleanFilter(data.filter),
|
2594
3467
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2595
3468
|
page: data.pagination,
|
2596
|
-
columns: data.columns ?? ["*"]
|
3469
|
+
columns: data.columns ?? ["*"],
|
3470
|
+
consistency: data.consistency
|
2597
3471
|
},
|
2598
3472
|
fetchOptions: data.fetchOptions,
|
2599
|
-
...
|
3473
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2600
3474
|
});
|
2601
3475
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2602
3476
|
const records = objects.map(
|
@@ -2609,7 +3483,6 @@ class RestRepository extends Query {
|
|
2609
3483
|
async summarizeTable(query, summaries, summariesFilter) {
|
2610
3484
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2611
3485
|
const data = query.getQueryOptions();
|
2612
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2613
3486
|
const result = await summarizeTable({
|
2614
3487
|
pathParams: {
|
2615
3488
|
workspace: "{workspaceId}",
|
@@ -2621,15 +3494,44 @@ class RestRepository extends Query {
|
|
2621
3494
|
filter: cleanFilter(data.filter),
|
2622
3495
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2623
3496
|
columns: data.columns,
|
3497
|
+
consistency: data.consistency,
|
2624
3498
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2625
3499
|
summaries,
|
2626
3500
|
summariesFilter
|
2627
3501
|
},
|
2628
|
-
...
|
3502
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2629
3503
|
});
|
2630
3504
|
return result;
|
2631
3505
|
});
|
2632
3506
|
}
|
3507
|
+
ask(question, options) {
|
3508
|
+
const params = {
|
3509
|
+
pathParams: {
|
3510
|
+
workspace: "{workspaceId}",
|
3511
|
+
dbBranchName: "{dbBranch}",
|
3512
|
+
region: "{region}",
|
3513
|
+
tableName: __privateGet$4(this, _table)
|
3514
|
+
},
|
3515
|
+
body: {
|
3516
|
+
question,
|
3517
|
+
...options
|
3518
|
+
},
|
3519
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3520
|
+
};
|
3521
|
+
if (options?.onMessage) {
|
3522
|
+
fetchSSERequest({
|
3523
|
+
endpoint: "dataPlane",
|
3524
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3525
|
+
method: "POST",
|
3526
|
+
onMessage: (message) => {
|
3527
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3528
|
+
},
|
3529
|
+
...params
|
3530
|
+
});
|
3531
|
+
} else {
|
3532
|
+
return askTable(params);
|
3533
|
+
}
|
3534
|
+
}
|
2633
3535
|
}
|
2634
3536
|
_table = new WeakMap();
|
2635
3537
|
_getFetchProps = new WeakMap();
|
@@ -2639,8 +3541,7 @@ _schemaTables$2 = new WeakMap();
|
|
2639
3541
|
_trace = new WeakMap();
|
2640
3542
|
_insertRecordWithoutId = new WeakSet();
|
2641
3543
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2642
|
-
const
|
2643
|
-
const record = transformObjectLinks(object);
|
3544
|
+
const record = removeLinksFromObject(object);
|
2644
3545
|
const response = await insertRecord({
|
2645
3546
|
pathParams: {
|
2646
3547
|
workspace: "{workspaceId}",
|
@@ -2650,15 +3551,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2650
3551
|
},
|
2651
3552
|
queryParams: { columns },
|
2652
3553
|
body: record,
|
2653
|
-
...
|
3554
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2654
3555
|
});
|
2655
3556
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2656
3557
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2657
3558
|
};
|
2658
3559
|
_insertRecordWithId = new WeakSet();
|
2659
3560
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2660
|
-
|
2661
|
-
|
3561
|
+
if (!recordId)
|
3562
|
+
return null;
|
3563
|
+
const record = removeLinksFromObject(object);
|
2662
3564
|
const response = await insertRecordWithID({
|
2663
3565
|
pathParams: {
|
2664
3566
|
workspace: "{workspaceId}",
|
@@ -2669,17 +3571,16 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2669
3571
|
},
|
2670
3572
|
body: record,
|
2671
3573
|
queryParams: { createOnly, columns, ifVersion },
|
2672
|
-
...
|
3574
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2673
3575
|
});
|
2674
3576
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2675
3577
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2676
3578
|
};
|
2677
3579
|
_insertRecords = new WeakSet();
|
2678
3580
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2679
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2680
3581
|
const chunkedOperations = chunk(
|
2681
3582
|
objects.map((object) => ({
|
2682
|
-
insert: { table: __privateGet$4(this, _table), record:
|
3583
|
+
insert: { table: __privateGet$4(this, _table), record: removeLinksFromObject(object), createOnly, ifVersion }
|
2683
3584
|
})),
|
2684
3585
|
BULK_OPERATION_MAX_SIZE
|
2685
3586
|
);
|
@@ -2692,7 +3593,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2692
3593
|
region: "{region}"
|
2693
3594
|
},
|
2694
3595
|
body: { operations },
|
2695
|
-
...
|
3596
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2696
3597
|
});
|
2697
3598
|
for (const result of results) {
|
2698
3599
|
if (result.operation === "insert") {
|
@@ -2706,8 +3607,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2706
3607
|
};
|
2707
3608
|
_updateRecordWithID = new WeakSet();
|
2708
3609
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2709
|
-
|
2710
|
-
|
3610
|
+
if (!recordId)
|
3611
|
+
return null;
|
3612
|
+
const { id: _id, ...record } = removeLinksFromObject(object);
|
2711
3613
|
try {
|
2712
3614
|
const response = await updateRecordWithID({
|
2713
3615
|
pathParams: {
|
@@ -2719,7 +3621,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2719
3621
|
},
|
2720
3622
|
queryParams: { columns, ifVersion },
|
2721
3623
|
body: record,
|
2722
|
-
...
|
3624
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2723
3625
|
});
|
2724
3626
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2725
3627
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2732,10 +3634,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2732
3634
|
};
|
2733
3635
|
_updateRecords = new WeakSet();
|
2734
3636
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2735
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2736
3637
|
const chunkedOperations = chunk(
|
2737
3638
|
objects.map(({ id, ...object }) => ({
|
2738
|
-
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields:
|
3639
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: removeLinksFromObject(object) }
|
2739
3640
|
})),
|
2740
3641
|
BULK_OPERATION_MAX_SIZE
|
2741
3642
|
);
|
@@ -2748,7 +3649,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2748
3649
|
region: "{region}"
|
2749
3650
|
},
|
2750
3651
|
body: { operations },
|
2751
|
-
...
|
3652
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2752
3653
|
});
|
2753
3654
|
for (const result of results) {
|
2754
3655
|
if (result.operation === "update") {
|
@@ -2762,7 +3663,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2762
3663
|
};
|
2763
3664
|
_upsertRecordWithID = new WeakSet();
|
2764
3665
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2765
|
-
|
3666
|
+
if (!recordId)
|
3667
|
+
return null;
|
2766
3668
|
const response = await upsertRecordWithID({
|
2767
3669
|
pathParams: {
|
2768
3670
|
workspace: "{workspaceId}",
|
@@ -2773,14 +3675,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2773
3675
|
},
|
2774
3676
|
queryParams: { columns, ifVersion },
|
2775
3677
|
body: object,
|
2776
|
-
...
|
3678
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2777
3679
|
});
|
2778
3680
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2779
3681
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2780
3682
|
};
|
2781
3683
|
_deleteRecord = new WeakSet();
|
2782
3684
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2783
|
-
|
3685
|
+
if (!recordId)
|
3686
|
+
return null;
|
2784
3687
|
try {
|
2785
3688
|
const response = await deleteRecord({
|
2786
3689
|
pathParams: {
|
@@ -2791,7 +3694,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2791
3694
|
recordId
|
2792
3695
|
},
|
2793
3696
|
queryParams: { columns },
|
2794
|
-
...
|
3697
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2795
3698
|
});
|
2796
3699
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2797
3700
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2804,9 +3707,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2804
3707
|
};
|
2805
3708
|
_deleteRecords = new WeakSet();
|
2806
3709
|
deleteRecords_fn = async function(recordIds) {
|
2807
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2808
3710
|
const chunkedOperations = chunk(
|
2809
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3711
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2810
3712
|
BULK_OPERATION_MAX_SIZE
|
2811
3713
|
);
|
2812
3714
|
for (const operations of chunkedOperations) {
|
@@ -2817,21 +3719,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2817
3719
|
region: "{region}"
|
2818
3720
|
},
|
2819
3721
|
body: { operations },
|
2820
|
-
...
|
3722
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2821
3723
|
});
|
2822
3724
|
}
|
2823
3725
|
};
|
2824
3726
|
_setCacheQuery = new WeakSet();
|
2825
3727
|
setCacheQuery_fn = async function(query, meta, records) {
|
2826
|
-
await __privateGet$4(this, _cache)
|
3728
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2827
3729
|
};
|
2828
3730
|
_getCacheQuery = new WeakSet();
|
2829
3731
|
getCacheQuery_fn = async function(query) {
|
2830
3732
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2831
|
-
const result = await __privateGet$4(this, _cache)
|
3733
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2832
3734
|
if (!result)
|
2833
3735
|
return null;
|
2834
|
-
const
|
3736
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3737
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2835
3738
|
if (ttl < 0)
|
2836
3739
|
return null;
|
2837
3740
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2841,15 +3744,14 @@ _getSchemaTables$1 = new WeakSet();
|
|
2841
3744
|
getSchemaTables_fn$1 = async function() {
|
2842
3745
|
if (__privateGet$4(this, _schemaTables$2))
|
2843
3746
|
return __privateGet$4(this, _schemaTables$2);
|
2844
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2845
3747
|
const { schema } = await getBranchDetails({
|
2846
3748
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2847
|
-
...
|
3749
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2848
3750
|
});
|
2849
3751
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2850
3752
|
return schema.tables;
|
2851
3753
|
};
|
2852
|
-
const
|
3754
|
+
const removeLinksFromObject = (object) => {
|
2853
3755
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2854
3756
|
if (key === "xata")
|
2855
3757
|
return acc;
|
@@ -2857,23 +3759,23 @@ const transformObjectLinks = (object) => {
|
|
2857
3759
|
}, {});
|
2858
3760
|
};
|
2859
3761
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2860
|
-
const
|
3762
|
+
const data = {};
|
2861
3763
|
const { xata, ...rest } = object ?? {};
|
2862
|
-
Object.assign(
|
3764
|
+
Object.assign(data, rest);
|
2863
3765
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2864
3766
|
if (!columns)
|
2865
3767
|
console.error(`Table ${table} not found in schema`);
|
2866
3768
|
for (const column of columns ?? []) {
|
2867
3769
|
if (!isValidColumn(selectedColumns, column))
|
2868
3770
|
continue;
|
2869
|
-
const value =
|
3771
|
+
const value = data[column.name];
|
2870
3772
|
switch (column.type) {
|
2871
3773
|
case "datetime": {
|
2872
3774
|
const date = value !== void 0 ? new Date(value) : null;
|
2873
3775
|
if (date !== null && isNaN(date.getTime())) {
|
2874
3776
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2875
3777
|
} else {
|
2876
|
-
|
3778
|
+
data[column.name] = date;
|
2877
3779
|
}
|
2878
3780
|
break;
|
2879
3781
|
}
|
@@ -2892,44 +3794,54 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2892
3794
|
}
|
2893
3795
|
return acc;
|
2894
3796
|
}, []);
|
2895
|
-
|
3797
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2896
3798
|
} else {
|
2897
|
-
|
3799
|
+
data[column.name] = null;
|
2898
3800
|
}
|
2899
3801
|
break;
|
2900
3802
|
}
|
2901
3803
|
default:
|
2902
|
-
|
3804
|
+
data[column.name] = value ?? null;
|
2903
3805
|
if (column.notNull === true && value === null) {
|
2904
3806
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2905
3807
|
}
|
2906
3808
|
break;
|
2907
3809
|
}
|
2908
3810
|
}
|
2909
|
-
|
2910
|
-
|
3811
|
+
const record = { ...data };
|
3812
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
3813
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3814
|
+
record.read = function(columns2) {
|
3815
|
+
return db[table].read(record["id"], columns2);
|
2911
3816
|
};
|
2912
|
-
|
3817
|
+
record.update = function(data2, b, c) {
|
2913
3818
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2914
3819
|
const ifVersion = parseIfVersion(b, c);
|
2915
|
-
return db[table].update(
|
3820
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2916
3821
|
};
|
2917
|
-
|
3822
|
+
record.replace = function(data2, b, c) {
|
2918
3823
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2919
3824
|
const ifVersion = parseIfVersion(b, c);
|
2920
|
-
return db[table].createOrReplace(
|
3825
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
3826
|
+
};
|
3827
|
+
record.delete = function() {
|
3828
|
+
return db[table].delete(record["id"]);
|
3829
|
+
};
|
3830
|
+
record.xata = Object.freeze(metadata);
|
3831
|
+
record.getMetadata = function() {
|
3832
|
+
return record.xata;
|
2921
3833
|
};
|
2922
|
-
|
2923
|
-
return
|
3834
|
+
record.toSerializable = function() {
|
3835
|
+
return JSON.parse(JSON.stringify(serializable));
|
2924
3836
|
};
|
2925
|
-
|
2926
|
-
return
|
3837
|
+
record.toString = function() {
|
3838
|
+
return JSON.stringify(serializable);
|
2927
3839
|
};
|
2928
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
2929
|
-
Object.defineProperty(
|
3840
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3841
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2930
3842
|
}
|
2931
|
-
Object.freeze(
|
2932
|
-
return
|
3843
|
+
Object.freeze(record);
|
3844
|
+
return record;
|
2933
3845
|
};
|
2934
3846
|
function extractId(value) {
|
2935
3847
|
if (isString(value))
|
@@ -2941,11 +3853,7 @@ function extractId(value) {
|
|
2941
3853
|
function isValidColumn(columns, column) {
|
2942
3854
|
if (columns.includes("*"))
|
2943
3855
|
return true;
|
2944
|
-
|
2945
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2946
|
-
return linkColumns.length > 0;
|
2947
|
-
}
|
2948
|
-
return columns.includes(column.name);
|
3856
|
+
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
2949
3857
|
}
|
2950
3858
|
function parseIfVersion(...args) {
|
2951
3859
|
for (const arg of args) {
|
@@ -2956,6 +3864,12 @@ function parseIfVersion(...args) {
|
|
2956
3864
|
return void 0;
|
2957
3865
|
}
|
2958
3866
|
|
3867
|
+
var __defProp$3 = Object.defineProperty;
|
3868
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3869
|
+
var __publicField$3 = (obj, key, value) => {
|
3870
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3871
|
+
return value;
|
3872
|
+
};
|
2959
3873
|
var __accessCheck$3 = (obj, member, msg) => {
|
2960
3874
|
if (!member.has(obj))
|
2961
3875
|
throw TypeError("Cannot " + msg);
|
@@ -2978,6 +3892,8 @@ var _map;
|
|
2978
3892
|
class SimpleCache {
|
2979
3893
|
constructor(options = {}) {
|
2980
3894
|
__privateAdd$3(this, _map, void 0);
|
3895
|
+
__publicField$3(this, "capacity");
|
3896
|
+
__publicField$3(this, "defaultQueryTTL");
|
2981
3897
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
2982
3898
|
this.capacity = options.max ?? 500;
|
2983
3899
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3113,19 +4029,19 @@ class SearchPlugin extends XataPlugin {
|
|
3113
4029
|
__privateAdd$1(this, _schemaTables, void 0);
|
3114
4030
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3115
4031
|
}
|
3116
|
-
build(
|
4032
|
+
build(pluginOptions) {
|
3117
4033
|
return {
|
3118
4034
|
all: async (query, options = {}) => {
|
3119
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3120
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4035
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4036
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3121
4037
|
return records.map((record) => {
|
3122
4038
|
const { table = "orphan" } = record.xata;
|
3123
4039
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3124
4040
|
});
|
3125
4041
|
},
|
3126
4042
|
byTable: async (query, options = {}) => {
|
3127
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3128
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4043
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4044
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3129
4045
|
return records.reduce((acc, record) => {
|
3130
4046
|
const { table = "orphan" } = record.xata;
|
3131
4047
|
const items = acc[table] ?? [];
|
@@ -3138,38 +4054,36 @@ class SearchPlugin extends XataPlugin {
|
|
3138
4054
|
}
|
3139
4055
|
_schemaTables = new WeakMap();
|
3140
4056
|
_search = new WeakSet();
|
3141
|
-
search_fn = async function(query, options,
|
3142
|
-
const
|
3143
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
4057
|
+
search_fn = async function(query, options, pluginOptions) {
|
4058
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3144
4059
|
const { records } = await searchBranch({
|
3145
4060
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3146
|
-
|
3147
|
-
|
4061
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4062
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4063
|
+
...pluginOptions
|
3148
4064
|
});
|
3149
4065
|
return records;
|
3150
4066
|
};
|
3151
4067
|
_getSchemaTables = new WeakSet();
|
3152
|
-
getSchemaTables_fn = async function(
|
4068
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3153
4069
|
if (__privateGet$1(this, _schemaTables))
|
3154
4070
|
return __privateGet$1(this, _schemaTables);
|
3155
|
-
const fetchProps = await getFetchProps();
|
3156
4071
|
const { schema } = await getBranchDetails({
|
3157
4072
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3158
|
-
...
|
4073
|
+
...pluginOptions
|
3159
4074
|
});
|
3160
4075
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3161
4076
|
return schema.tables;
|
3162
4077
|
};
|
3163
4078
|
|
3164
4079
|
class TransactionPlugin extends XataPlugin {
|
3165
|
-
build(
|
4080
|
+
build(pluginOptions) {
|
3166
4081
|
return {
|
3167
4082
|
run: async (operations) => {
|
3168
|
-
const fetchProps = await getFetchProps();
|
3169
4083
|
const response = await branchTransaction({
|
3170
4084
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3171
4085
|
body: { operations },
|
3172
|
-
...
|
4086
|
+
...pluginOptions
|
3173
4087
|
});
|
3174
4088
|
return response;
|
3175
4089
|
}
|
@@ -3177,93 +4091,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3177
4091
|
}
|
3178
4092
|
}
|
3179
4093
|
|
3180
|
-
|
3181
|
-
|
4094
|
+
var __defProp$2 = Object.defineProperty;
|
4095
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4096
|
+
var __publicField$2 = (obj, key, value) => {
|
4097
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4098
|
+
return value;
|
3182
4099
|
};
|
3183
|
-
|
3184
|
-
async function getCurrentBranchName(options) {
|
3185
|
-
const { branch, envBranch } = getEnvironment();
|
3186
|
-
if (branch) {
|
3187
|
-
const details = await getDatabaseBranch(branch, options);
|
3188
|
-
if (details)
|
3189
|
-
return branch;
|
3190
|
-
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
3191
|
-
}
|
3192
|
-
const gitBranch = envBranch || await getGitBranch();
|
3193
|
-
return resolveXataBranch(gitBranch, options);
|
3194
|
-
}
|
3195
|
-
async function getCurrentBranchDetails(options) {
|
3196
|
-
const branch = await getCurrentBranchName(options);
|
3197
|
-
return getDatabaseBranch(branch, options);
|
3198
|
-
}
|
3199
|
-
async function resolveXataBranch(gitBranch, options) {
|
3200
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3201
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3202
|
-
if (!databaseURL)
|
3203
|
-
throw new Error(
|
3204
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3205
|
-
);
|
3206
|
-
if (!apiKey)
|
3207
|
-
throw new Error(
|
3208
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3209
|
-
);
|
3210
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3211
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3212
|
-
if (!urlParts)
|
3213
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3214
|
-
const { workspace, region } = urlParts;
|
3215
|
-
const { fallbackBranch } = getEnvironment();
|
3216
|
-
const { branch } = await resolveBranch({
|
3217
|
-
apiKey,
|
3218
|
-
apiUrl: databaseURL,
|
3219
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3220
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3221
|
-
pathParams: { dbName, workspace, region },
|
3222
|
-
queryParams: { gitBranch, fallbackBranch },
|
3223
|
-
trace: defaultTrace
|
3224
|
-
});
|
3225
|
-
return branch;
|
3226
|
-
}
|
3227
|
-
async function getDatabaseBranch(branch, options) {
|
3228
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3229
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3230
|
-
if (!databaseURL)
|
3231
|
-
throw new Error(
|
3232
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3233
|
-
);
|
3234
|
-
if (!apiKey)
|
3235
|
-
throw new Error(
|
3236
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3237
|
-
);
|
3238
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3239
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3240
|
-
if (!urlParts)
|
3241
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3242
|
-
const { workspace, region } = urlParts;
|
3243
|
-
try {
|
3244
|
-
return await getBranchDetails({
|
3245
|
-
apiKey,
|
3246
|
-
apiUrl: databaseURL,
|
3247
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3248
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3249
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3250
|
-
trace: defaultTrace
|
3251
|
-
});
|
3252
|
-
} catch (err) {
|
3253
|
-
if (isObject(err) && err.status === 404)
|
3254
|
-
return null;
|
3255
|
-
throw err;
|
3256
|
-
}
|
3257
|
-
}
|
3258
|
-
function getDatabaseURL() {
|
3259
|
-
try {
|
3260
|
-
const { databaseURL } = getEnvironment();
|
3261
|
-
return databaseURL;
|
3262
|
-
} catch (err) {
|
3263
|
-
return void 0;
|
3264
|
-
}
|
3265
|
-
}
|
3266
|
-
|
3267
4100
|
var __accessCheck = (obj, member, msg) => {
|
3268
4101
|
if (!member.has(obj))
|
3269
4102
|
throw TypeError("Cannot " + msg);
|
@@ -3287,20 +4120,21 @@ var __privateMethod = (obj, member, method) => {
|
|
3287
4120
|
return method;
|
3288
4121
|
};
|
3289
4122
|
const buildClient = (plugins) => {
|
3290
|
-
var
|
4123
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3291
4124
|
return _a = class {
|
3292
4125
|
constructor(options = {}, schemaTables) {
|
3293
4126
|
__privateAdd(this, _parseOptions);
|
3294
4127
|
__privateAdd(this, _getFetchProps);
|
3295
|
-
__privateAdd(this, _evaluateBranch);
|
3296
|
-
__privateAdd(this, _branch, void 0);
|
3297
4128
|
__privateAdd(this, _options, void 0);
|
4129
|
+
__publicField$2(this, "db");
|
4130
|
+
__publicField$2(this, "search");
|
4131
|
+
__publicField$2(this, "transactions");
|
3298
4132
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3299
4133
|
__privateSet(this, _options, safeOptions);
|
3300
4134
|
const pluginOptions = {
|
3301
|
-
|
4135
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3302
4136
|
cache: safeOptions.cache,
|
3303
|
-
|
4137
|
+
host: safeOptions.host
|
3304
4138
|
};
|
3305
4139
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3306
4140
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -3311,24 +4145,17 @@ const buildClient = (plugins) => {
|
|
3311
4145
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3312
4146
|
if (namespace === void 0)
|
3313
4147
|
continue;
|
3314
|
-
|
3315
|
-
if (result instanceof Promise) {
|
3316
|
-
void result.then((namespace2) => {
|
3317
|
-
this[key] = namespace2;
|
3318
|
-
});
|
3319
|
-
} else {
|
3320
|
-
this[key] = result;
|
3321
|
-
}
|
4148
|
+
this[key] = namespace.build(pluginOptions);
|
3322
4149
|
}
|
3323
4150
|
}
|
3324
4151
|
async getConfig() {
|
3325
4152
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3326
|
-
const branch =
|
4153
|
+
const branch = __privateGet(this, _options).branch;
|
3327
4154
|
return { databaseURL, branch };
|
3328
4155
|
}
|
3329
|
-
},
|
4156
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3330
4157
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3331
|
-
const isBrowser = typeof window !== "undefined";
|
4158
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3332
4159
|
if (isBrowser && !enableBrowser) {
|
3333
4160
|
throw new Error(
|
3334
4161
|
"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."
|
@@ -3339,56 +4166,89 @@ const buildClient = (plugins) => {
|
|
3339
4166
|
const apiKey = options?.apiKey || getAPIKey();
|
3340
4167
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3341
4168
|
const trace = options?.trace ?? defaultTrace;
|
3342
|
-
const
|
4169
|
+
const clientName = options?.clientName;
|
4170
|
+
const host = options?.host ?? "production";
|
4171
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3343
4172
|
if (!apiKey) {
|
3344
4173
|
throw new Error("Option apiKey is required");
|
3345
4174
|
}
|
3346
4175
|
if (!databaseURL) {
|
3347
4176
|
throw new Error("Option databaseURL is required");
|
3348
4177
|
}
|
3349
|
-
|
3350
|
-
|
3351
|
-
const
|
3352
|
-
if (
|
3353
|
-
|
4178
|
+
const envBranch = getBranch();
|
4179
|
+
const previewBranch = getPreviewBranch();
|
4180
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4181
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4182
|
+
console.warn(
|
4183
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4184
|
+
);
|
4185
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4186
|
+
console.warn(
|
4187
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4188
|
+
);
|
4189
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4190
|
+
console.warn(
|
4191
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4192
|
+
);
|
4193
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4194
|
+
console.warn(
|
4195
|
+
`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.`
|
4196
|
+
);
|
4197
|
+
}
|
3354
4198
|
return {
|
3355
|
-
|
4199
|
+
fetch,
|
4200
|
+
databaseURL,
|
4201
|
+
apiKey,
|
4202
|
+
branch,
|
4203
|
+
cache,
|
4204
|
+
trace,
|
4205
|
+
host,
|
4206
|
+
clientID: generateUUID(),
|
4207
|
+
enableBrowser,
|
4208
|
+
clientName,
|
4209
|
+
xataAgentExtra
|
4210
|
+
};
|
4211
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4212
|
+
fetch,
|
4213
|
+
apiKey,
|
4214
|
+
databaseURL,
|
4215
|
+
branch,
|
4216
|
+
trace,
|
4217
|
+
clientID,
|
4218
|
+
clientName,
|
4219
|
+
xataAgentExtra
|
4220
|
+
}) {
|
4221
|
+
return {
|
4222
|
+
fetch,
|
3356
4223
|
apiKey,
|
3357
4224
|
apiUrl: "",
|
4225
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3358
4226
|
workspacesApiUrl: (path, params) => {
|
3359
4227
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3360
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4228
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3361
4229
|
return databaseURL + newPath;
|
3362
4230
|
},
|
3363
4231
|
trace,
|
3364
|
-
clientID
|
4232
|
+
clientID,
|
4233
|
+
clientName,
|
4234
|
+
xataAgentExtra
|
3365
4235
|
};
|
3366
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3367
|
-
if (__privateGet(this, _branch))
|
3368
|
-
return __privateGet(this, _branch);
|
3369
|
-
if (param === void 0)
|
3370
|
-
return void 0;
|
3371
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3372
|
-
const evaluateBranch = async (strategy) => {
|
3373
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3374
|
-
};
|
3375
|
-
for await (const strategy of strategies) {
|
3376
|
-
const branch = await evaluateBranch(strategy);
|
3377
|
-
if (branch) {
|
3378
|
-
__privateSet(this, _branch, branch);
|
3379
|
-
return branch;
|
3380
|
-
}
|
3381
|
-
}
|
3382
4236
|
}, _a;
|
3383
4237
|
};
|
3384
4238
|
class BaseClient extends buildClient() {
|
3385
4239
|
}
|
3386
4240
|
|
4241
|
+
var __defProp$1 = Object.defineProperty;
|
4242
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4243
|
+
var __publicField$1 = (obj, key, value) => {
|
4244
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4245
|
+
return value;
|
4246
|
+
};
|
3387
4247
|
const META = "__";
|
3388
4248
|
const VALUE = "___";
|
3389
4249
|
class Serializer {
|
3390
4250
|
constructor() {
|
3391
|
-
this
|
4251
|
+
__publicField$1(this, "classes", {});
|
3392
4252
|
}
|
3393
4253
|
add(clazz) {
|
3394
4254
|
this.classes[clazz.name] = clazz;
|
@@ -3452,7 +4312,7 @@ const deserialize = (json) => {
|
|
3452
4312
|
};
|
3453
4313
|
|
3454
4314
|
function buildWorkerRunner(config) {
|
3455
|
-
return function xataWorker(name,
|
4315
|
+
return function xataWorker(name, worker) {
|
3456
4316
|
return async (...args) => {
|
3457
4317
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3458
4318
|
const result = await fetch(url, {
|
@@ -3466,14 +4326,22 @@ function buildWorkerRunner(config) {
|
|
3466
4326
|
};
|
3467
4327
|
}
|
3468
4328
|
|
4329
|
+
var __defProp = Object.defineProperty;
|
4330
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4331
|
+
var __publicField = (obj, key, value) => {
|
4332
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4333
|
+
return value;
|
4334
|
+
};
|
3469
4335
|
class XataError extends Error {
|
3470
4336
|
constructor(message, status) {
|
3471
4337
|
super(message);
|
4338
|
+
__publicField(this, "status");
|
3472
4339
|
this.status = status;
|
3473
4340
|
}
|
3474
4341
|
}
|
3475
4342
|
|
3476
4343
|
exports.BaseClient = BaseClient;
|
4344
|
+
exports.FetcherError = FetcherError;
|
3477
4345
|
exports.Operations = operationsByTag;
|
3478
4346
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
3479
4347
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -3482,6 +4350,7 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
|
3482
4350
|
exports.Page = Page;
|
3483
4351
|
exports.Query = Query;
|
3484
4352
|
exports.RecordArray = RecordArray;
|
4353
|
+
exports.RecordColumnTypes = RecordColumnTypes;
|
3485
4354
|
exports.Repository = Repository;
|
3486
4355
|
exports.RestRepository = RestRepository;
|
3487
4356
|
exports.SchemaPlugin = SchemaPlugin;
|
@@ -3497,29 +4366,32 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
3497
4366
|
exports.addTableColumn = addTableColumn;
|
3498
4367
|
exports.aggregateTable = aggregateTable;
|
3499
4368
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4369
|
+
exports.askTable = askTable;
|
3500
4370
|
exports.branchTransaction = branchTransaction;
|
3501
4371
|
exports.buildClient = buildClient;
|
4372
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4373
|
+
exports.buildProviderString = buildProviderString;
|
3502
4374
|
exports.buildWorkerRunner = buildWorkerRunner;
|
3503
4375
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
3504
4376
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
4377
|
+
exports.chatSessionMessage = chatSessionMessage;
|
3505
4378
|
exports.compareBranchSchemas = compareBranchSchemas;
|
3506
4379
|
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3507
4380
|
exports.compareMigrationRequest = compareMigrationRequest;
|
3508
4381
|
exports.contains = contains;
|
4382
|
+
exports.copyBranch = copyBranch;
|
3509
4383
|
exports.createBranch = createBranch;
|
3510
4384
|
exports.createDatabase = createDatabase;
|
3511
4385
|
exports.createMigrationRequest = createMigrationRequest;
|
3512
4386
|
exports.createTable = createTable;
|
3513
4387
|
exports.createUserAPIKey = createUserAPIKey;
|
3514
4388
|
exports.createWorkspace = createWorkspace;
|
3515
|
-
exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
|
3516
|
-
exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
|
3517
|
-
exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
|
3518
|
-
exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
|
3519
|
-
exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
|
3520
4389
|
exports.deleteBranch = deleteBranch;
|
3521
4390
|
exports.deleteColumn = deleteColumn;
|
3522
4391
|
exports.deleteDatabase = deleteDatabase;
|
4392
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4393
|
+
exports.deleteFile = deleteFile;
|
4394
|
+
exports.deleteFileItem = deleteFileItem;
|
3523
4395
|
exports.deleteRecord = deleteRecord;
|
3524
4396
|
exports.deleteTable = deleteTable;
|
3525
4397
|
exports.deleteUser = deleteUser;
|
@@ -3530,8 +4402,10 @@ exports.endsWith = endsWith;
|
|
3530
4402
|
exports.equals = equals;
|
3531
4403
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
3532
4404
|
exports.exists = exists;
|
4405
|
+
exports.fileAccess = fileAccess;
|
3533
4406
|
exports.ge = ge;
|
3534
4407
|
exports.getAPIKey = getAPIKey;
|
4408
|
+
exports.getBranch = getBranch;
|
3535
4409
|
exports.getBranchDetails = getBranchDetails;
|
3536
4410
|
exports.getBranchList = getBranchList;
|
3537
4411
|
exports.getBranchMetadata = getBranchMetadata;
|
@@ -3540,15 +4414,17 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
|
3540
4414
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
3541
4415
|
exports.getBranchStats = getBranchStats;
|
3542
4416
|
exports.getColumn = getColumn;
|
3543
|
-
exports.
|
3544
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
4417
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3545
4418
|
exports.getDatabaseList = getDatabaseList;
|
3546
4419
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
3547
4420
|
exports.getDatabaseURL = getDatabaseURL;
|
4421
|
+
exports.getFile = getFile;
|
4422
|
+
exports.getFileItem = getFileItem;
|
3548
4423
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3549
4424
|
exports.getHostUrl = getHostUrl;
|
3550
4425
|
exports.getMigrationRequest = getMigrationRequest;
|
3551
4426
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4427
|
+
exports.getPreviewBranch = getPreviewBranch;
|
3552
4428
|
exports.getRecord = getRecord;
|
3553
4429
|
exports.getTableColumns = getTableColumns;
|
3554
4430
|
exports.getTableSchema = getTableSchema;
|
@@ -3591,21 +4467,27 @@ exports.parseProviderString = parseProviderString;
|
|
3591
4467
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
3592
4468
|
exports.pattern = pattern;
|
3593
4469
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4470
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
4471
|
+
exports.putFile = putFile;
|
4472
|
+
exports.putFileItem = putFileItem;
|
3594
4473
|
exports.queryMigrationRequests = queryMigrationRequests;
|
3595
4474
|
exports.queryTable = queryTable;
|
3596
4475
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
3597
4476
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
4477
|
+
exports.renameDatabase = renameDatabase;
|
3598
4478
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
3599
4479
|
exports.resolveBranch = resolveBranch;
|
3600
4480
|
exports.searchBranch = searchBranch;
|
3601
4481
|
exports.searchTable = searchTable;
|
3602
4482
|
exports.serialize = serialize;
|
3603
4483
|
exports.setTableSchema = setTableSchema;
|
4484
|
+
exports.sqlQuery = sqlQuery;
|
3604
4485
|
exports.startsWith = startsWith;
|
3605
4486
|
exports.summarizeTable = summarizeTable;
|
3606
4487
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3607
4488
|
exports.updateBranchSchema = updateBranchSchema;
|
3608
4489
|
exports.updateColumn = updateColumn;
|
4490
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3609
4491
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3610
4492
|
exports.updateMigrationRequest = updateMigrationRequest;
|
3611
4493
|
exports.updateRecordWithID = updateRecordWithID;
|
@@ -3615,4 +4497,5 @@ exports.updateWorkspace = updateWorkspace;
|
|
3615
4497
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
3616
4498
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
3617
4499
|
exports.upsertRecordWithID = upsertRecordWithID;
|
4500
|
+
exports.vectorSearchTable = vectorSearchTable;
|
3618
4501
|
//# sourceMappingURL=index.cjs.map
|