@xata.io/client 0.0.0-alpha.ve914594 → 0.0.0-alpha.ve91fd39
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/.eslintrc.cjs +2 -1
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +78 -0
- package/README.md +3 -269
- package/dist/index.cjs +589 -237
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1566 -926
- package/dist/index.mjs +578 -235
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
- package/Usage.md +0 -451
package/dist/index.mjs
CHANGED
|
@@ -91,8 +91,10 @@ function getEnvironment() {
|
|
|
91
91
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
|
92
92
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
|
93
93
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
deployPreview: process.env.XATA_PREVIEW,
|
|
95
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
|
96
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
|
97
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
100
|
} catch (err) {
|
|
@@ -103,8 +105,10 @@ function getEnvironment() {
|
|
|
103
105
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
|
104
106
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
|
105
107
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
|
109
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
|
110
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
|
111
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
|
108
112
|
};
|
|
109
113
|
}
|
|
110
114
|
} catch (err) {
|
|
@@ -113,8 +117,10 @@ function getEnvironment() {
|
|
|
113
117
|
apiKey: getGlobalApiKey(),
|
|
114
118
|
databaseURL: getGlobalDatabaseURL(),
|
|
115
119
|
branch: getGlobalBranch(),
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
deployPreview: void 0,
|
|
121
|
+
deployPreviewBranch: void 0,
|
|
122
|
+
vercelGitCommitRef: void 0,
|
|
123
|
+
vercelGitRepoOwner: void 0
|
|
118
124
|
};
|
|
119
125
|
}
|
|
120
126
|
function getEnableBrowserVariable() {
|
|
@@ -157,36 +163,48 @@ function getGlobalBranch() {
|
|
|
157
163
|
return void 0;
|
|
158
164
|
}
|
|
159
165
|
}
|
|
160
|
-
function
|
|
166
|
+
function getDatabaseURL() {
|
|
161
167
|
try {
|
|
162
|
-
|
|
168
|
+
const { databaseURL } = getEnvironment();
|
|
169
|
+
return databaseURL;
|
|
163
170
|
} catch (err) {
|
|
164
171
|
return void 0;
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
|
-
|
|
168
|
-
const cmd = ["git", "branch", "--show-current"];
|
|
169
|
-
const fullCmd = cmd.join(" ");
|
|
170
|
-
const nodeModule = ["child", "process"].join("_");
|
|
171
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
|
174
|
+
function getAPIKey() {
|
|
172
175
|
try {
|
|
173
|
-
const {
|
|
174
|
-
return
|
|
176
|
+
const { apiKey } = getEnvironment();
|
|
177
|
+
return apiKey;
|
|
175
178
|
} catch (err) {
|
|
179
|
+
return void 0;
|
|
176
180
|
}
|
|
181
|
+
}
|
|
182
|
+
function getBranch() {
|
|
177
183
|
try {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
|
181
|
-
}
|
|
184
|
+
const { branch } = getEnvironment();
|
|
185
|
+
return branch ?? "main";
|
|
182
186
|
} catch (err) {
|
|
187
|
+
return void 0;
|
|
183
188
|
}
|
|
184
189
|
}
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
function buildPreviewBranchName({ org, branch }) {
|
|
191
|
+
return `preview-${org}-${branch}`;
|
|
192
|
+
}
|
|
193
|
+
function getPreviewBranch() {
|
|
187
194
|
try {
|
|
188
|
-
const {
|
|
189
|
-
|
|
195
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
|
196
|
+
if (deployPreviewBranch)
|
|
197
|
+
return deployPreviewBranch;
|
|
198
|
+
switch (deployPreview) {
|
|
199
|
+
case "vercel": {
|
|
200
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
|
201
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return void 0;
|
|
190
208
|
} catch (err) {
|
|
191
209
|
return void 0;
|
|
192
210
|
}
|
|
@@ -299,7 +317,180 @@ function generateUUID() {
|
|
|
299
317
|
});
|
|
300
318
|
}
|
|
301
319
|
|
|
302
|
-
|
|
320
|
+
async function getBytes(stream, onChunk) {
|
|
321
|
+
const reader = stream.getReader();
|
|
322
|
+
let result;
|
|
323
|
+
while (!(result = await reader.read()).done) {
|
|
324
|
+
onChunk(result.value);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function getLines(onLine) {
|
|
328
|
+
let buffer;
|
|
329
|
+
let position;
|
|
330
|
+
let fieldLength;
|
|
331
|
+
let discardTrailingNewline = false;
|
|
332
|
+
return function onChunk(arr) {
|
|
333
|
+
if (buffer === void 0) {
|
|
334
|
+
buffer = arr;
|
|
335
|
+
position = 0;
|
|
336
|
+
fieldLength = -1;
|
|
337
|
+
} else {
|
|
338
|
+
buffer = concat(buffer, arr);
|
|
339
|
+
}
|
|
340
|
+
const bufLength = buffer.length;
|
|
341
|
+
let lineStart = 0;
|
|
342
|
+
while (position < bufLength) {
|
|
343
|
+
if (discardTrailingNewline) {
|
|
344
|
+
if (buffer[position] === 10 /* NewLine */) {
|
|
345
|
+
lineStart = ++position;
|
|
346
|
+
}
|
|
347
|
+
discardTrailingNewline = false;
|
|
348
|
+
}
|
|
349
|
+
let lineEnd = -1;
|
|
350
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
|
351
|
+
switch (buffer[position]) {
|
|
352
|
+
case 58 /* Colon */:
|
|
353
|
+
if (fieldLength === -1) {
|
|
354
|
+
fieldLength = position - lineStart;
|
|
355
|
+
}
|
|
356
|
+
break;
|
|
357
|
+
case 13 /* CarriageReturn */:
|
|
358
|
+
discardTrailingNewline = true;
|
|
359
|
+
case 10 /* NewLine */:
|
|
360
|
+
lineEnd = position;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (lineEnd === -1) {
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
|
368
|
+
lineStart = position;
|
|
369
|
+
fieldLength = -1;
|
|
370
|
+
}
|
|
371
|
+
if (lineStart === bufLength) {
|
|
372
|
+
buffer = void 0;
|
|
373
|
+
} else if (lineStart !== 0) {
|
|
374
|
+
buffer = buffer.subarray(lineStart);
|
|
375
|
+
position -= lineStart;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function getMessages(onId, onRetry, onMessage) {
|
|
380
|
+
let message = newMessage();
|
|
381
|
+
const decoder = new TextDecoder();
|
|
382
|
+
return function onLine(line, fieldLength) {
|
|
383
|
+
if (line.length === 0) {
|
|
384
|
+
onMessage?.(message);
|
|
385
|
+
message = newMessage();
|
|
386
|
+
} else if (fieldLength > 0) {
|
|
387
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
|
388
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
|
389
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
|
390
|
+
switch (field) {
|
|
391
|
+
case "data":
|
|
392
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
|
393
|
+
break;
|
|
394
|
+
case "event":
|
|
395
|
+
message.event = value;
|
|
396
|
+
break;
|
|
397
|
+
case "id":
|
|
398
|
+
onId(message.id = value);
|
|
399
|
+
break;
|
|
400
|
+
case "retry":
|
|
401
|
+
const retry = parseInt(value, 10);
|
|
402
|
+
if (!isNaN(retry)) {
|
|
403
|
+
onRetry(message.retry = retry);
|
|
404
|
+
}
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function concat(a, b) {
|
|
411
|
+
const res = new Uint8Array(a.length + b.length);
|
|
412
|
+
res.set(a);
|
|
413
|
+
res.set(b, a.length);
|
|
414
|
+
return res;
|
|
415
|
+
}
|
|
416
|
+
function newMessage() {
|
|
417
|
+
return {
|
|
418
|
+
data: "",
|
|
419
|
+
event: "",
|
|
420
|
+
id: "",
|
|
421
|
+
retry: void 0
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
const EventStreamContentType = "text/event-stream";
|
|
425
|
+
const LastEventId = "last-event-id";
|
|
426
|
+
function fetchEventSource(input, {
|
|
427
|
+
signal: inputSignal,
|
|
428
|
+
headers: inputHeaders,
|
|
429
|
+
onopen: inputOnOpen,
|
|
430
|
+
onmessage,
|
|
431
|
+
onclose,
|
|
432
|
+
onerror,
|
|
433
|
+
fetch: inputFetch,
|
|
434
|
+
...rest
|
|
435
|
+
}) {
|
|
436
|
+
return new Promise((resolve, reject) => {
|
|
437
|
+
const headers = { ...inputHeaders };
|
|
438
|
+
if (!headers.accept) {
|
|
439
|
+
headers.accept = EventStreamContentType;
|
|
440
|
+
}
|
|
441
|
+
let curRequestController;
|
|
442
|
+
function dispose() {
|
|
443
|
+
curRequestController.abort();
|
|
444
|
+
}
|
|
445
|
+
inputSignal?.addEventListener("abort", () => {
|
|
446
|
+
dispose();
|
|
447
|
+
resolve();
|
|
448
|
+
});
|
|
449
|
+
const fetchImpl = inputFetch ?? fetch;
|
|
450
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
|
451
|
+
async function create() {
|
|
452
|
+
curRequestController = new AbortController();
|
|
453
|
+
try {
|
|
454
|
+
const response = await fetchImpl(input, {
|
|
455
|
+
...rest,
|
|
456
|
+
headers,
|
|
457
|
+
signal: curRequestController.signal
|
|
458
|
+
});
|
|
459
|
+
await onopen(response);
|
|
460
|
+
await getBytes(
|
|
461
|
+
response.body,
|
|
462
|
+
getLines(
|
|
463
|
+
getMessages(
|
|
464
|
+
(id) => {
|
|
465
|
+
if (id) {
|
|
466
|
+
headers[LastEventId] = id;
|
|
467
|
+
} else {
|
|
468
|
+
delete headers[LastEventId];
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
(_retry) => {
|
|
472
|
+
},
|
|
473
|
+
onmessage
|
|
474
|
+
)
|
|
475
|
+
)
|
|
476
|
+
);
|
|
477
|
+
onclose?.();
|
|
478
|
+
dispose();
|
|
479
|
+
resolve();
|
|
480
|
+
} catch (err) {
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
create();
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
function defaultOnOpen(response) {
|
|
487
|
+
const contentType = response.headers?.get("content-type");
|
|
488
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
|
489
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const VERSION = "0.23.2";
|
|
303
494
|
|
|
304
495
|
class ErrorWithCause extends Error {
|
|
305
496
|
constructor(message, options) {
|
|
@@ -383,7 +574,7 @@ async function fetch$1({
|
|
|
383
574
|
headers: customHeaders,
|
|
384
575
|
pathParams,
|
|
385
576
|
queryParams,
|
|
386
|
-
|
|
577
|
+
fetch: fetch2,
|
|
387
578
|
apiKey,
|
|
388
579
|
endpoint,
|
|
389
580
|
apiUrl,
|
|
@@ -393,12 +584,13 @@ async function fetch$1({
|
|
|
393
584
|
clientID,
|
|
394
585
|
sessionID,
|
|
395
586
|
clientName,
|
|
587
|
+
xataAgentExtra,
|
|
396
588
|
fetchOptions = {}
|
|
397
589
|
}) {
|
|
398
|
-
pool.setFetch(
|
|
590
|
+
pool.setFetch(fetch2);
|
|
399
591
|
return await trace(
|
|
400
592
|
`${method.toUpperCase()} ${path}`,
|
|
401
|
-
async ({
|
|
593
|
+
async ({ setAttributes }) => {
|
|
402
594
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
|
403
595
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
|
404
596
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
|
@@ -409,7 +601,8 @@ async function fetch$1({
|
|
|
409
601
|
const xataAgent = compact([
|
|
410
602
|
["client", "TS_SDK"],
|
|
411
603
|
["version", VERSION],
|
|
412
|
-
isDefined(clientName) ? ["service", clientName] : void 0
|
|
604
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
|
605
|
+
...Object.entries(xataAgentExtra ?? {})
|
|
413
606
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
|
414
607
|
const headers = {
|
|
415
608
|
"Accept-Encoding": "identity",
|
|
@@ -456,6 +649,59 @@ async function fetch$1({
|
|
|
456
649
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
|
457
650
|
);
|
|
458
651
|
}
|
|
652
|
+
function fetchSSERequest({
|
|
653
|
+
url: path,
|
|
654
|
+
method,
|
|
655
|
+
body,
|
|
656
|
+
headers: customHeaders,
|
|
657
|
+
pathParams,
|
|
658
|
+
queryParams,
|
|
659
|
+
fetch: fetch2,
|
|
660
|
+
apiKey,
|
|
661
|
+
endpoint,
|
|
662
|
+
apiUrl,
|
|
663
|
+
workspacesApiUrl,
|
|
664
|
+
onMessage,
|
|
665
|
+
onError,
|
|
666
|
+
onClose,
|
|
667
|
+
signal,
|
|
668
|
+
clientID,
|
|
669
|
+
sessionID,
|
|
670
|
+
clientName,
|
|
671
|
+
xataAgentExtra
|
|
672
|
+
}) {
|
|
673
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
|
674
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
|
675
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
|
676
|
+
void fetchEventSource(url, {
|
|
677
|
+
method,
|
|
678
|
+
body: JSON.stringify(body),
|
|
679
|
+
fetch: fetch2,
|
|
680
|
+
signal,
|
|
681
|
+
headers: {
|
|
682
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
|
683
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
|
684
|
+
"X-Xata-Agent": compact([
|
|
685
|
+
["client", "TS_SDK"],
|
|
686
|
+
["version", VERSION],
|
|
687
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
|
688
|
+
...Object.entries(xataAgentExtra ?? {})
|
|
689
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
|
690
|
+
...customHeaders,
|
|
691
|
+
Authorization: `Bearer ${apiKey}`,
|
|
692
|
+
"Content-Type": "application/json"
|
|
693
|
+
},
|
|
694
|
+
onmessage(ev) {
|
|
695
|
+
onMessage?.(JSON.parse(ev.data));
|
|
696
|
+
},
|
|
697
|
+
onerror(ev) {
|
|
698
|
+
onError?.(JSON.parse(ev.data));
|
|
699
|
+
},
|
|
700
|
+
onclose() {
|
|
701
|
+
onClose?.();
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
}
|
|
459
705
|
function parseUrl(url) {
|
|
460
706
|
try {
|
|
461
707
|
const { host, protocol } = new URL(url);
|
|
@@ -486,6 +732,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
|
486
732
|
...variables,
|
|
487
733
|
signal
|
|
488
734
|
});
|
|
735
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
|
736
|
+
url: "/db/{dbBranchName}/copy",
|
|
737
|
+
method: "post",
|
|
738
|
+
...variables,
|
|
739
|
+
signal
|
|
740
|
+
});
|
|
489
741
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
|
490
742
|
url: "/db/{dbBranchName}/metadata",
|
|
491
743
|
method: "put",
|
|
@@ -511,7 +763,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
|
511
763
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
|
512
764
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
|
513
765
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
|
514
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
|
515
766
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
|
516
767
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
|
517
768
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
|
@@ -536,6 +787,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
|
536
787
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
|
537
788
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
|
538
789
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
|
790
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
|
539
791
|
const createTable = (variables, signal) => dataPlaneFetch({
|
|
540
792
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
541
793
|
method: "put",
|
|
@@ -578,6 +830,7 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
|
578
830
|
...variables,
|
|
579
831
|
signal
|
|
580
832
|
});
|
|
833
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
|
581
834
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
|
582
835
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
|
583
836
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
|
@@ -608,6 +861,19 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
|
608
861
|
...variables,
|
|
609
862
|
signal
|
|
610
863
|
});
|
|
864
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
865
|
+
url: "/db/{dbBranchName}/sql",
|
|
866
|
+
method: "post",
|
|
867
|
+
...variables,
|
|
868
|
+
signal
|
|
869
|
+
});
|
|
870
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
|
871
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
|
872
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
|
873
|
+
method: "post",
|
|
874
|
+
...variables,
|
|
875
|
+
signal
|
|
876
|
+
});
|
|
611
877
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
|
612
878
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
|
613
879
|
const operationsByTag$2 = {
|
|
@@ -616,6 +882,7 @@ const operationsByTag$2 = {
|
|
|
616
882
|
getBranchDetails,
|
|
617
883
|
createBranch,
|
|
618
884
|
deleteBranch,
|
|
885
|
+
copyBranch,
|
|
619
886
|
updateBranchMetadata,
|
|
620
887
|
getBranchMetadata,
|
|
621
888
|
getBranchStats,
|
|
@@ -633,17 +900,8 @@ const operationsByTag$2 = {
|
|
|
633
900
|
compareBranchSchemas,
|
|
634
901
|
updateBranchSchema,
|
|
635
902
|
previewBranchSchemaEdit,
|
|
636
|
-
applyBranchSchemaEdit
|
|
637
|
-
|
|
638
|
-
records: {
|
|
639
|
-
branchTransaction,
|
|
640
|
-
insertRecord,
|
|
641
|
-
getRecord,
|
|
642
|
-
insertRecordWithID,
|
|
643
|
-
updateRecordWithID,
|
|
644
|
-
upsertRecordWithID,
|
|
645
|
-
deleteRecord,
|
|
646
|
-
bulkInsertTableRecords
|
|
903
|
+
applyBranchSchemaEdit,
|
|
904
|
+
pushBranchMigrations
|
|
647
905
|
},
|
|
648
906
|
migrationRequests: {
|
|
649
907
|
queryMigrationRequests,
|
|
@@ -667,7 +925,26 @@ const operationsByTag$2 = {
|
|
|
667
925
|
updateColumn,
|
|
668
926
|
deleteColumn
|
|
669
927
|
},
|
|
670
|
-
|
|
928
|
+
records: {
|
|
929
|
+
branchTransaction,
|
|
930
|
+
insertRecord,
|
|
931
|
+
getRecord,
|
|
932
|
+
insertRecordWithID,
|
|
933
|
+
updateRecordWithID,
|
|
934
|
+
upsertRecordWithID,
|
|
935
|
+
deleteRecord,
|
|
936
|
+
bulkInsertTableRecords
|
|
937
|
+
},
|
|
938
|
+
searchAndFilter: {
|
|
939
|
+
queryTable,
|
|
940
|
+
searchBranch,
|
|
941
|
+
searchTable,
|
|
942
|
+
sqlQuery,
|
|
943
|
+
vectorSearchTable,
|
|
944
|
+
askTable,
|
|
945
|
+
summarizeTable,
|
|
946
|
+
aggregateTable
|
|
947
|
+
}
|
|
671
948
|
};
|
|
672
949
|
|
|
673
950
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
|
@@ -766,6 +1043,9 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
|
766
1043
|
});
|
|
767
1044
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
|
768
1045
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
|
1046
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
|
1047
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
|
1048
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
|
769
1049
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
|
770
1050
|
url: "/workspaces/{workspaceId}/regions",
|
|
771
1051
|
method: "get",
|
|
@@ -798,6 +1078,9 @@ const operationsByTag$1 = {
|
|
|
798
1078
|
deleteDatabase,
|
|
799
1079
|
getDatabaseMetadata,
|
|
800
1080
|
updateDatabaseMetadata,
|
|
1081
|
+
getDatabaseGithubSettings,
|
|
1082
|
+
updateDatabaseGithubSettings,
|
|
1083
|
+
deleteDatabaseGithubSettings,
|
|
801
1084
|
listRegions
|
|
802
1085
|
}
|
|
803
1086
|
};
|
|
@@ -818,8 +1101,12 @@ const providers = {
|
|
|
818
1101
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
|
819
1102
|
},
|
|
820
1103
|
staging: {
|
|
821
|
-
main: "https://staging.
|
|
822
|
-
workspaces: "https://{workspaceId}.
|
|
1104
|
+
main: "https://api.staging-xata.dev",
|
|
1105
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
|
1106
|
+
},
|
|
1107
|
+
dev: {
|
|
1108
|
+
main: "https://api.dev-xata.dev",
|
|
1109
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
|
823
1110
|
}
|
|
824
1111
|
};
|
|
825
1112
|
function isHostProviderAlias(alias) {
|
|
@@ -837,12 +1124,19 @@ function parseProviderString(provider = "production") {
|
|
|
837
1124
|
return null;
|
|
838
1125
|
return { main, workspaces };
|
|
839
1126
|
}
|
|
1127
|
+
function buildProviderString(provider) {
|
|
1128
|
+
if (isHostProviderAlias(provider))
|
|
1129
|
+
return provider;
|
|
1130
|
+
return `${provider.main},${provider.workspaces}`;
|
|
1131
|
+
}
|
|
840
1132
|
function parseWorkspacesUrlParts(url) {
|
|
841
1133
|
if (!isString(url))
|
|
842
1134
|
return null;
|
|
843
1135
|
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
|
844
|
-
const
|
|
845
|
-
const
|
|
1136
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
|
1137
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
|
1138
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
|
1139
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
|
846
1140
|
if (!match)
|
|
847
1141
|
return null;
|
|
848
1142
|
return { workspace: match[1], region: match[2] };
|
|
@@ -881,10 +1175,11 @@ class XataApiClient {
|
|
|
881
1175
|
__privateSet$7(this, _extraProps, {
|
|
882
1176
|
apiUrl: getHostUrl(provider, "main"),
|
|
883
1177
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
|
884
|
-
|
|
1178
|
+
fetch: getFetchImplementation(options.fetch),
|
|
885
1179
|
apiKey,
|
|
886
1180
|
trace,
|
|
887
1181
|
clientName: options.clientName,
|
|
1182
|
+
xataAgentExtra: options.xataAgentExtra,
|
|
888
1183
|
clientID
|
|
889
1184
|
});
|
|
890
1185
|
}
|
|
@@ -1146,6 +1441,20 @@ class BranchApi {
|
|
|
1146
1441
|
...this.extraProps
|
|
1147
1442
|
});
|
|
1148
1443
|
}
|
|
1444
|
+
copyBranch({
|
|
1445
|
+
workspace,
|
|
1446
|
+
region,
|
|
1447
|
+
database,
|
|
1448
|
+
branch,
|
|
1449
|
+
destinationBranch,
|
|
1450
|
+
limit
|
|
1451
|
+
}) {
|
|
1452
|
+
return operationsByTag.branch.copyBranch({
|
|
1453
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1454
|
+
body: { destinationBranch, limit },
|
|
1455
|
+
...this.extraProps
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1149
1458
|
updateBranchMetadata({
|
|
1150
1459
|
workspace,
|
|
1151
1460
|
region,
|
|
@@ -1560,6 +1869,38 @@ class SearchAndFilterApi {
|
|
|
1560
1869
|
...this.extraProps
|
|
1561
1870
|
});
|
|
1562
1871
|
}
|
|
1872
|
+
vectorSearchTable({
|
|
1873
|
+
workspace,
|
|
1874
|
+
region,
|
|
1875
|
+
database,
|
|
1876
|
+
branch,
|
|
1877
|
+
table,
|
|
1878
|
+
queryVector,
|
|
1879
|
+
column,
|
|
1880
|
+
similarityFunction,
|
|
1881
|
+
size,
|
|
1882
|
+
filter
|
|
1883
|
+
}) {
|
|
1884
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
|
1885
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1886
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
|
1887
|
+
...this.extraProps
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
askTable({
|
|
1891
|
+
workspace,
|
|
1892
|
+
region,
|
|
1893
|
+
database,
|
|
1894
|
+
branch,
|
|
1895
|
+
table,
|
|
1896
|
+
options
|
|
1897
|
+
}) {
|
|
1898
|
+
return operationsByTag.searchAndFilter.askTable({
|
|
1899
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1900
|
+
body: { ...options },
|
|
1901
|
+
...this.extraProps
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1563
1904
|
summarizeTable({
|
|
1564
1905
|
workspace,
|
|
1565
1906
|
region,
|
|
@@ -1760,11 +2101,13 @@ class MigrationsApi {
|
|
|
1760
2101
|
region,
|
|
1761
2102
|
database,
|
|
1762
2103
|
branch,
|
|
1763
|
-
schema
|
|
2104
|
+
schema,
|
|
2105
|
+
schemaOperations,
|
|
2106
|
+
branchOperations
|
|
1764
2107
|
}) {
|
|
1765
2108
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
|
1766
2109
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1767
|
-
body: { schema },
|
|
2110
|
+
body: { schema, schemaOperations, branchOperations },
|
|
1768
2111
|
...this.extraProps
|
|
1769
2112
|
});
|
|
1770
2113
|
}
|
|
@@ -1774,11 +2117,12 @@ class MigrationsApi {
|
|
|
1774
2117
|
database,
|
|
1775
2118
|
branch,
|
|
1776
2119
|
compare,
|
|
1777
|
-
|
|
2120
|
+
sourceBranchOperations,
|
|
2121
|
+
targetBranchOperations
|
|
1778
2122
|
}) {
|
|
1779
2123
|
return operationsByTag.migrations.compareBranchSchemas({
|
|
1780
2124
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
|
1781
|
-
body: {
|
|
2125
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
|
1782
2126
|
...this.extraProps
|
|
1783
2127
|
});
|
|
1784
2128
|
}
|
|
@@ -1821,6 +2165,19 @@ class MigrationsApi {
|
|
|
1821
2165
|
...this.extraProps
|
|
1822
2166
|
});
|
|
1823
2167
|
}
|
|
2168
|
+
pushBranchMigrations({
|
|
2169
|
+
workspace,
|
|
2170
|
+
region,
|
|
2171
|
+
database,
|
|
2172
|
+
branch,
|
|
2173
|
+
migrations
|
|
2174
|
+
}) {
|
|
2175
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
|
2176
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
2177
|
+
body: { migrations },
|
|
2178
|
+
...this.extraProps
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
1824
2181
|
}
|
|
1825
2182
|
class DatabaseApi {
|
|
1826
2183
|
constructor(extraProps) {
|
|
@@ -1872,6 +2229,35 @@ class DatabaseApi {
|
|
|
1872
2229
|
...this.extraProps
|
|
1873
2230
|
});
|
|
1874
2231
|
}
|
|
2232
|
+
getDatabaseGithubSettings({
|
|
2233
|
+
workspace,
|
|
2234
|
+
database
|
|
2235
|
+
}) {
|
|
2236
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
|
2237
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2238
|
+
...this.extraProps
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
updateDatabaseGithubSettings({
|
|
2242
|
+
workspace,
|
|
2243
|
+
database,
|
|
2244
|
+
settings
|
|
2245
|
+
}) {
|
|
2246
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
|
2247
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2248
|
+
body: settings,
|
|
2249
|
+
...this.extraProps
|
|
2250
|
+
});
|
|
2251
|
+
}
|
|
2252
|
+
deleteDatabaseGithubSettings({
|
|
2253
|
+
workspace,
|
|
2254
|
+
database
|
|
2255
|
+
}) {
|
|
2256
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
|
2257
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2258
|
+
...this.extraProps
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
1875
2261
|
listRegions({ workspace }) {
|
|
1876
2262
|
return operationsByTag.databases.listRegions({
|
|
1877
2263
|
pathParams: { workspaceId: workspace },
|
|
@@ -1881,9 +2267,8 @@ class DatabaseApi {
|
|
|
1881
2267
|
}
|
|
1882
2268
|
|
|
1883
2269
|
class XataApiPlugin {
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
|
2270
|
+
build(options) {
|
|
2271
|
+
return new XataApiClient(options);
|
|
1887
2272
|
}
|
|
1888
2273
|
}
|
|
1889
2274
|
|
|
@@ -1966,6 +2351,12 @@ const _RecordArray = class extends Array {
|
|
|
1966
2351
|
toArray() {
|
|
1967
2352
|
return new Array(...this);
|
|
1968
2353
|
}
|
|
2354
|
+
toSerializable() {
|
|
2355
|
+
return JSON.parse(this.toString());
|
|
2356
|
+
}
|
|
2357
|
+
toString() {
|
|
2358
|
+
return JSON.stringify(this.toArray());
|
|
2359
|
+
}
|
|
1969
2360
|
map(callbackfn, thisArg) {
|
|
1970
2361
|
return this.toArray().map(callbackfn, thisArg);
|
|
1971
2362
|
}
|
|
@@ -2291,10 +2682,7 @@ class RestRepository extends Query {
|
|
|
2291
2682
|
__privateSet$4(this, _db, options.db);
|
|
2292
2683
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
|
2293
2684
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
|
2294
|
-
__privateSet$4(this, _getFetchProps,
|
|
2295
|
-
const props = await options.pluginOptions.getFetchProps();
|
|
2296
|
-
return { ...props, sessionID: generateUUID() };
|
|
2297
|
-
});
|
|
2685
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
|
2298
2686
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
|
2299
2687
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
|
2300
2688
|
return trace(name, fn, {
|
|
@@ -2351,7 +2739,6 @@ class RestRepository extends Query {
|
|
|
2351
2739
|
}
|
|
2352
2740
|
const id = extractId(a);
|
|
2353
2741
|
if (id) {
|
|
2354
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2355
2742
|
try {
|
|
2356
2743
|
const response = await getRecord({
|
|
2357
2744
|
pathParams: {
|
|
@@ -2362,7 +2749,7 @@ class RestRepository extends Query {
|
|
|
2362
2749
|
recordId: id
|
|
2363
2750
|
},
|
|
2364
2751
|
queryParams: { columns },
|
|
2365
|
-
...
|
|
2752
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2366
2753
|
});
|
|
2367
2754
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2368
2755
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
@@ -2540,7 +2927,6 @@ class RestRepository extends Query {
|
|
|
2540
2927
|
}
|
|
2541
2928
|
async search(query, options = {}) {
|
|
2542
2929
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
|
2543
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2544
2930
|
const { records } = await searchTable({
|
|
2545
2931
|
pathParams: {
|
|
2546
2932
|
workspace: "{workspaceId}",
|
|
@@ -2558,7 +2944,29 @@ class RestRepository extends Query {
|
|
|
2558
2944
|
page: options.page,
|
|
2559
2945
|
target: options.target
|
|
2560
2946
|
},
|
|
2561
|
-
...
|
|
2947
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2948
|
+
});
|
|
2949
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2950
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
|
2951
|
+
});
|
|
2952
|
+
}
|
|
2953
|
+
async vectorSearch(column, query, options) {
|
|
2954
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
|
2955
|
+
const { records } = await vectorSearchTable({
|
|
2956
|
+
pathParams: {
|
|
2957
|
+
workspace: "{workspaceId}",
|
|
2958
|
+
dbBranchName: "{dbBranch}",
|
|
2959
|
+
region: "{region}",
|
|
2960
|
+
tableName: __privateGet$4(this, _table)
|
|
2961
|
+
},
|
|
2962
|
+
body: {
|
|
2963
|
+
column,
|
|
2964
|
+
queryVector: query,
|
|
2965
|
+
similarityFunction: options?.similarityFunction,
|
|
2966
|
+
size: options?.size,
|
|
2967
|
+
filter: options?.filter
|
|
2968
|
+
},
|
|
2969
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2562
2970
|
});
|
|
2563
2971
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2564
2972
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
|
@@ -2566,7 +2974,6 @@ class RestRepository extends Query {
|
|
|
2566
2974
|
}
|
|
2567
2975
|
async aggregate(aggs, filter) {
|
|
2568
2976
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
|
2569
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2570
2977
|
const result = await aggregateTable({
|
|
2571
2978
|
pathParams: {
|
|
2572
2979
|
workspace: "{workspaceId}",
|
|
@@ -2575,7 +2982,7 @@ class RestRepository extends Query {
|
|
|
2575
2982
|
tableName: __privateGet$4(this, _table)
|
|
2576
2983
|
},
|
|
2577
2984
|
body: { aggs, filter },
|
|
2578
|
-
...
|
|
2985
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2579
2986
|
});
|
|
2580
2987
|
return result;
|
|
2581
2988
|
});
|
|
@@ -2586,7 +2993,6 @@ class RestRepository extends Query {
|
|
|
2586
2993
|
if (cacheQuery)
|
|
2587
2994
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
|
2588
2995
|
const data = query.getQueryOptions();
|
|
2589
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2590
2996
|
const { meta, records: objects } = await queryTable({
|
|
2591
2997
|
pathParams: {
|
|
2592
2998
|
workspace: "{workspaceId}",
|
|
@@ -2602,7 +3008,7 @@ class RestRepository extends Query {
|
|
|
2602
3008
|
consistency: data.consistency
|
|
2603
3009
|
},
|
|
2604
3010
|
fetchOptions: data.fetchOptions,
|
|
2605
|
-
...
|
|
3011
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2606
3012
|
});
|
|
2607
3013
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2608
3014
|
const records = objects.map(
|
|
@@ -2615,7 +3021,6 @@ class RestRepository extends Query {
|
|
|
2615
3021
|
async summarizeTable(query, summaries, summariesFilter) {
|
|
2616
3022
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
|
2617
3023
|
const data = query.getQueryOptions();
|
|
2618
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2619
3024
|
const result = await summarizeTable({
|
|
2620
3025
|
pathParams: {
|
|
2621
3026
|
workspace: "{workspaceId}",
|
|
@@ -2632,11 +3037,39 @@ class RestRepository extends Query {
|
|
|
2632
3037
|
summaries,
|
|
2633
3038
|
summariesFilter
|
|
2634
3039
|
},
|
|
2635
|
-
...
|
|
3040
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2636
3041
|
});
|
|
2637
3042
|
return result;
|
|
2638
3043
|
});
|
|
2639
3044
|
}
|
|
3045
|
+
ask(question, options) {
|
|
3046
|
+
const params = {
|
|
3047
|
+
pathParams: {
|
|
3048
|
+
workspace: "{workspaceId}",
|
|
3049
|
+
dbBranchName: "{dbBranch}",
|
|
3050
|
+
region: "{region}",
|
|
3051
|
+
tableName: __privateGet$4(this, _table)
|
|
3052
|
+
},
|
|
3053
|
+
body: {
|
|
3054
|
+
question,
|
|
3055
|
+
...options
|
|
3056
|
+
},
|
|
3057
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3058
|
+
};
|
|
3059
|
+
if (options?.onMessage) {
|
|
3060
|
+
fetchSSERequest({
|
|
3061
|
+
endpoint: "dataPlane",
|
|
3062
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
|
3063
|
+
method: "POST",
|
|
3064
|
+
onMessage: (message) => {
|
|
3065
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
|
3066
|
+
},
|
|
3067
|
+
...params
|
|
3068
|
+
});
|
|
3069
|
+
} else {
|
|
3070
|
+
return askTable(params);
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
2640
3073
|
}
|
|
2641
3074
|
_table = new WeakMap();
|
|
2642
3075
|
_getFetchProps = new WeakMap();
|
|
@@ -2646,7 +3079,6 @@ _schemaTables$2 = new WeakMap();
|
|
|
2646
3079
|
_trace = new WeakMap();
|
|
2647
3080
|
_insertRecordWithoutId = new WeakSet();
|
|
2648
3081
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2649
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2650
3082
|
const record = transformObjectLinks(object);
|
|
2651
3083
|
const response = await insertRecord({
|
|
2652
3084
|
pathParams: {
|
|
@@ -2657,14 +3089,13 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
|
2657
3089
|
},
|
|
2658
3090
|
queryParams: { columns },
|
|
2659
3091
|
body: record,
|
|
2660
|
-
...
|
|
3092
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2661
3093
|
});
|
|
2662
3094
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2663
3095
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2664
3096
|
};
|
|
2665
3097
|
_insertRecordWithId = new WeakSet();
|
|
2666
3098
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
|
2667
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2668
3099
|
const record = transformObjectLinks(object);
|
|
2669
3100
|
const response = await insertRecordWithID({
|
|
2670
3101
|
pathParams: {
|
|
@@ -2676,14 +3107,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
|
2676
3107
|
},
|
|
2677
3108
|
body: record,
|
|
2678
3109
|
queryParams: { createOnly, columns, ifVersion },
|
|
2679
|
-
...
|
|
3110
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2680
3111
|
});
|
|
2681
3112
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2682
3113
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2683
3114
|
};
|
|
2684
3115
|
_insertRecords = new WeakSet();
|
|
2685
3116
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2686
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2687
3117
|
const chunkedOperations = chunk(
|
|
2688
3118
|
objects.map((object) => ({
|
|
2689
3119
|
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
|
@@ -2699,7 +3129,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
|
2699
3129
|
region: "{region}"
|
|
2700
3130
|
},
|
|
2701
3131
|
body: { operations },
|
|
2702
|
-
...
|
|
3132
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2703
3133
|
});
|
|
2704
3134
|
for (const result of results) {
|
|
2705
3135
|
if (result.operation === "insert") {
|
|
@@ -2713,7 +3143,6 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
|
2713
3143
|
};
|
|
2714
3144
|
_updateRecordWithID = new WeakSet();
|
|
2715
3145
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
2716
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2717
3146
|
const { id: _id, ...record } = transformObjectLinks(object);
|
|
2718
3147
|
try {
|
|
2719
3148
|
const response = await updateRecordWithID({
|
|
@@ -2726,7 +3155,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
2726
3155
|
},
|
|
2727
3156
|
queryParams: { columns, ifVersion },
|
|
2728
3157
|
body: record,
|
|
2729
|
-
...
|
|
3158
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2730
3159
|
});
|
|
2731
3160
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2732
3161
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
@@ -2739,7 +3168,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
2739
3168
|
};
|
|
2740
3169
|
_updateRecords = new WeakSet();
|
|
2741
3170
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2742
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2743
3171
|
const chunkedOperations = chunk(
|
|
2744
3172
|
objects.map(({ id, ...object }) => ({
|
|
2745
3173
|
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
|
@@ -2755,7 +3183,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
|
2755
3183
|
region: "{region}"
|
|
2756
3184
|
},
|
|
2757
3185
|
body: { operations },
|
|
2758
|
-
...
|
|
3186
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2759
3187
|
});
|
|
2760
3188
|
for (const result of results) {
|
|
2761
3189
|
if (result.operation === "update") {
|
|
@@ -2769,7 +3197,6 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
|
2769
3197
|
};
|
|
2770
3198
|
_upsertRecordWithID = new WeakSet();
|
|
2771
3199
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
2772
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2773
3200
|
const response = await upsertRecordWithID({
|
|
2774
3201
|
pathParams: {
|
|
2775
3202
|
workspace: "{workspaceId}",
|
|
@@ -2780,14 +3207,13 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
2780
3207
|
},
|
|
2781
3208
|
queryParams: { columns, ifVersion },
|
|
2782
3209
|
body: object,
|
|
2783
|
-
...
|
|
3210
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2784
3211
|
});
|
|
2785
3212
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2786
3213
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2787
3214
|
};
|
|
2788
3215
|
_deleteRecord = new WeakSet();
|
|
2789
3216
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2790
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2791
3217
|
try {
|
|
2792
3218
|
const response = await deleteRecord({
|
|
2793
3219
|
pathParams: {
|
|
@@ -2798,7 +3224,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
|
2798
3224
|
recordId
|
|
2799
3225
|
},
|
|
2800
3226
|
queryParams: { columns },
|
|
2801
|
-
...
|
|
3227
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2802
3228
|
});
|
|
2803
3229
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2804
3230
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
@@ -2811,7 +3237,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
|
2811
3237
|
};
|
|
2812
3238
|
_deleteRecords = new WeakSet();
|
|
2813
3239
|
deleteRecords_fn = async function(recordIds) {
|
|
2814
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2815
3240
|
const chunkedOperations = chunk(
|
|
2816
3241
|
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
|
2817
3242
|
BULK_OPERATION_MAX_SIZE
|
|
@@ -2824,21 +3249,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
|
2824
3249
|
region: "{region}"
|
|
2825
3250
|
},
|
|
2826
3251
|
body: { operations },
|
|
2827
|
-
...
|
|
3252
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2828
3253
|
});
|
|
2829
3254
|
}
|
|
2830
3255
|
};
|
|
2831
3256
|
_setCacheQuery = new WeakSet();
|
|
2832
3257
|
setCacheQuery_fn = async function(query, meta, records) {
|
|
2833
|
-
await __privateGet$4(this, _cache)
|
|
3258
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
|
2834
3259
|
};
|
|
2835
3260
|
_getCacheQuery = new WeakSet();
|
|
2836
3261
|
getCacheQuery_fn = async function(query) {
|
|
2837
3262
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
|
2838
|
-
const result = await __privateGet$4(this, _cache)
|
|
3263
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
|
2839
3264
|
if (!result)
|
|
2840
3265
|
return null;
|
|
2841
|
-
const
|
|
3266
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
|
3267
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
|
2842
3268
|
if (ttl < 0)
|
|
2843
3269
|
return null;
|
|
2844
3270
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
|
@@ -2848,10 +3274,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
|
2848
3274
|
getSchemaTables_fn$1 = async function() {
|
|
2849
3275
|
if (__privateGet$4(this, _schemaTables$2))
|
|
2850
3276
|
return __privateGet$4(this, _schemaTables$2);
|
|
2851
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2852
3277
|
const { schema } = await getBranchDetails({
|
|
2853
3278
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
2854
|
-
...
|
|
3279
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2855
3280
|
});
|
|
2856
3281
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
|
2857
3282
|
return schema.tables;
|
|
@@ -2933,10 +3358,13 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
|
2933
3358
|
record.getMetadata = function() {
|
|
2934
3359
|
return xata;
|
|
2935
3360
|
};
|
|
2936
|
-
record.
|
|
3361
|
+
record.toSerializable = function() {
|
|
2937
3362
|
return JSON.parse(JSON.stringify(transformObjectLinks(data)));
|
|
2938
3363
|
};
|
|
2939
|
-
|
|
3364
|
+
record.toString = function() {
|
|
3365
|
+
return JSON.stringify(transformObjectLinks(data));
|
|
3366
|
+
};
|
|
3367
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
|
2940
3368
|
Object.defineProperty(record, prop, { enumerable: false });
|
|
2941
3369
|
}
|
|
2942
3370
|
Object.freeze(record);
|
|
@@ -3124,19 +3552,19 @@ class SearchPlugin extends XataPlugin {
|
|
|
3124
3552
|
__privateAdd$1(this, _schemaTables, void 0);
|
|
3125
3553
|
__privateSet$1(this, _schemaTables, schemaTables);
|
|
3126
3554
|
}
|
|
3127
|
-
build(
|
|
3555
|
+
build(pluginOptions) {
|
|
3128
3556
|
return {
|
|
3129
3557
|
all: async (query, options = {}) => {
|
|
3130
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
|
3131
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
|
3558
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
|
3559
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
|
3132
3560
|
return records.map((record) => {
|
|
3133
3561
|
const { table = "orphan" } = record.xata;
|
|
3134
3562
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
|
3135
3563
|
});
|
|
3136
3564
|
},
|
|
3137
3565
|
byTable: async (query, options = {}) => {
|
|
3138
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
|
3139
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
|
3566
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
|
3567
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
|
3140
3568
|
return records.reduce((acc, record) => {
|
|
3141
3569
|
const { table = "orphan" } = record.xata;
|
|
3142
3570
|
const items = acc[table] ?? [];
|
|
@@ -3149,38 +3577,35 @@ class SearchPlugin extends XataPlugin {
|
|
|
3149
3577
|
}
|
|
3150
3578
|
_schemaTables = new WeakMap();
|
|
3151
3579
|
_search = new WeakSet();
|
|
3152
|
-
search_fn = async function(query, options,
|
|
3153
|
-
const fetchProps = await getFetchProps();
|
|
3580
|
+
search_fn = async function(query, options, pluginOptions) {
|
|
3154
3581
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
|
3155
3582
|
const { records } = await searchBranch({
|
|
3156
3583
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
3157
3584
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
|
3158
|
-
...
|
|
3585
|
+
...pluginOptions
|
|
3159
3586
|
});
|
|
3160
3587
|
return records;
|
|
3161
3588
|
};
|
|
3162
3589
|
_getSchemaTables = new WeakSet();
|
|
3163
|
-
getSchemaTables_fn = async function(
|
|
3590
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
|
3164
3591
|
if (__privateGet$1(this, _schemaTables))
|
|
3165
3592
|
return __privateGet$1(this, _schemaTables);
|
|
3166
|
-
const fetchProps = await getFetchProps();
|
|
3167
3593
|
const { schema } = await getBranchDetails({
|
|
3168
3594
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
3169
|
-
...
|
|
3595
|
+
...pluginOptions
|
|
3170
3596
|
});
|
|
3171
3597
|
__privateSet$1(this, _schemaTables, schema.tables);
|
|
3172
3598
|
return schema.tables;
|
|
3173
3599
|
};
|
|
3174
3600
|
|
|
3175
3601
|
class TransactionPlugin extends XataPlugin {
|
|
3176
|
-
build(
|
|
3602
|
+
build(pluginOptions) {
|
|
3177
3603
|
return {
|
|
3178
3604
|
run: async (operations) => {
|
|
3179
|
-
const fetchProps = await getFetchProps();
|
|
3180
3605
|
const response = await branchTransaction({
|
|
3181
3606
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
3182
3607
|
body: { operations },
|
|
3183
|
-
...
|
|
3608
|
+
...pluginOptions
|
|
3184
3609
|
});
|
|
3185
3610
|
return response;
|
|
3186
3611
|
}
|
|
@@ -3188,90 +3613,6 @@ class TransactionPlugin extends XataPlugin {
|
|
|
3188
3613
|
}
|
|
3189
3614
|
}
|
|
3190
3615
|
|
|
3191
|
-
const isBranchStrategyBuilder = (strategy) => {
|
|
3192
|
-
return typeof strategy === "function";
|
|
3193
|
-
};
|
|
3194
|
-
|
|
3195
|
-
async function getCurrentBranchName(options) {
|
|
3196
|
-
const { branch, envBranch } = getEnvironment();
|
|
3197
|
-
if (branch)
|
|
3198
|
-
return branch;
|
|
3199
|
-
const gitBranch = envBranch || await getGitBranch();
|
|
3200
|
-
return resolveXataBranch(gitBranch, options);
|
|
3201
|
-
}
|
|
3202
|
-
async function getCurrentBranchDetails(options) {
|
|
3203
|
-
const branch = await getCurrentBranchName(options);
|
|
3204
|
-
return getDatabaseBranch(branch, options);
|
|
3205
|
-
}
|
|
3206
|
-
async function resolveXataBranch(gitBranch, options) {
|
|
3207
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
3208
|
-
const apiKey = options?.apiKey || getAPIKey();
|
|
3209
|
-
if (!databaseURL)
|
|
3210
|
-
throw new Error(
|
|
3211
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
3212
|
-
);
|
|
3213
|
-
if (!apiKey)
|
|
3214
|
-
throw new Error(
|
|
3215
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
3216
|
-
);
|
|
3217
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
|
3218
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
|
3219
|
-
if (!urlParts)
|
|
3220
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
|
3221
|
-
const { workspace, region } = urlParts;
|
|
3222
|
-
const { fallbackBranch } = getEnvironment();
|
|
3223
|
-
const { branch } = await resolveBranch({
|
|
3224
|
-
apiKey,
|
|
3225
|
-
apiUrl: databaseURL,
|
|
3226
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
3227
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
|
3228
|
-
pathParams: { dbName, workspace, region },
|
|
3229
|
-
queryParams: { gitBranch, fallbackBranch },
|
|
3230
|
-
trace: defaultTrace,
|
|
3231
|
-
clientName: options?.clientName
|
|
3232
|
-
});
|
|
3233
|
-
return branch;
|
|
3234
|
-
}
|
|
3235
|
-
async function getDatabaseBranch(branch, options) {
|
|
3236
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
3237
|
-
const apiKey = options?.apiKey || getAPIKey();
|
|
3238
|
-
if (!databaseURL)
|
|
3239
|
-
throw new Error(
|
|
3240
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
3241
|
-
);
|
|
3242
|
-
if (!apiKey)
|
|
3243
|
-
throw new Error(
|
|
3244
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
3245
|
-
);
|
|
3246
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
|
3247
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
|
3248
|
-
if (!urlParts)
|
|
3249
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
|
3250
|
-
const { workspace, region } = urlParts;
|
|
3251
|
-
try {
|
|
3252
|
-
return await getBranchDetails({
|
|
3253
|
-
apiKey,
|
|
3254
|
-
apiUrl: databaseURL,
|
|
3255
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
3256
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
|
3257
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
|
3258
|
-
trace: defaultTrace
|
|
3259
|
-
});
|
|
3260
|
-
} catch (err) {
|
|
3261
|
-
if (isObject(err) && err.status === 404)
|
|
3262
|
-
return null;
|
|
3263
|
-
throw err;
|
|
3264
|
-
}
|
|
3265
|
-
}
|
|
3266
|
-
function getDatabaseURL() {
|
|
3267
|
-
try {
|
|
3268
|
-
const { databaseURL } = getEnvironment();
|
|
3269
|
-
return databaseURL;
|
|
3270
|
-
} catch (err) {
|
|
3271
|
-
return void 0;
|
|
3272
|
-
}
|
|
3273
|
-
}
|
|
3274
|
-
|
|
3275
3616
|
var __accessCheck = (obj, member, msg) => {
|
|
3276
3617
|
if (!member.has(obj))
|
|
3277
3618
|
throw TypeError("Cannot " + msg);
|
|
@@ -3295,20 +3636,18 @@ var __privateMethod = (obj, member, method) => {
|
|
|
3295
3636
|
return method;
|
|
3296
3637
|
};
|
|
3297
3638
|
const buildClient = (plugins) => {
|
|
3298
|
-
var
|
|
3639
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
|
3299
3640
|
return _a = class {
|
|
3300
3641
|
constructor(options = {}, schemaTables) {
|
|
3301
3642
|
__privateAdd(this, _parseOptions);
|
|
3302
3643
|
__privateAdd(this, _getFetchProps);
|
|
3303
|
-
__privateAdd(this, _evaluateBranch);
|
|
3304
|
-
__privateAdd(this, _branch, void 0);
|
|
3305
3644
|
__privateAdd(this, _options, void 0);
|
|
3306
3645
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
|
3307
3646
|
__privateSet(this, _options, safeOptions);
|
|
3308
3647
|
const pluginOptions = {
|
|
3309
|
-
|
|
3648
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
|
3310
3649
|
cache: safeOptions.cache,
|
|
3311
|
-
|
|
3650
|
+
host: safeOptions.host
|
|
3312
3651
|
};
|
|
3313
3652
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
|
3314
3653
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
|
@@ -3319,22 +3658,15 @@ const buildClient = (plugins) => {
|
|
|
3319
3658
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
|
3320
3659
|
if (namespace === void 0)
|
|
3321
3660
|
continue;
|
|
3322
|
-
|
|
3323
|
-
if (result instanceof Promise) {
|
|
3324
|
-
void result.then((namespace2) => {
|
|
3325
|
-
this[key] = namespace2;
|
|
3326
|
-
});
|
|
3327
|
-
} else {
|
|
3328
|
-
this[key] = result;
|
|
3329
|
-
}
|
|
3661
|
+
this[key] = namespace.build(pluginOptions);
|
|
3330
3662
|
}
|
|
3331
3663
|
}
|
|
3332
3664
|
async getConfig() {
|
|
3333
3665
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
|
3334
|
-
const branch =
|
|
3666
|
+
const branch = __privateGet(this, _options).branch;
|
|
3335
3667
|
return { databaseURL, branch };
|
|
3336
3668
|
}
|
|
3337
|
-
},
|
|
3669
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
|
3338
3670
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
|
3339
3671
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
|
3340
3672
|
if (isBrowser && !enableBrowser) {
|
|
@@ -3348,60 +3680,71 @@ const buildClient = (plugins) => {
|
|
|
3348
3680
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
|
3349
3681
|
const trace = options?.trace ?? defaultTrace;
|
|
3350
3682
|
const clientName = options?.clientName;
|
|
3351
|
-
const
|
|
3352
|
-
|
|
3353
|
-
databaseURL,
|
|
3354
|
-
fetchImpl: options?.fetch,
|
|
3355
|
-
clientName: options?.clientName
|
|
3356
|
-
});
|
|
3683
|
+
const host = options?.host ?? "production";
|
|
3684
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
|
3357
3685
|
if (!apiKey) {
|
|
3358
3686
|
throw new Error("Option apiKey is required");
|
|
3359
3687
|
}
|
|
3360
3688
|
if (!databaseURL) {
|
|
3361
3689
|
throw new Error("Option databaseURL is required");
|
|
3362
3690
|
}
|
|
3363
|
-
|
|
3364
|
-
|
|
3691
|
+
const envBranch = getBranch();
|
|
3692
|
+
const previewBranch = getPreviewBranch();
|
|
3693
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
|
3694
|
+
if (!!previewBranch && branch !== previewBranch) {
|
|
3695
|
+
console.warn(
|
|
3696
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
|
3697
|
+
);
|
|
3698
|
+
} else if (!!envBranch && branch !== envBranch) {
|
|
3699
|
+
console.warn(
|
|
3700
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
|
3701
|
+
);
|
|
3702
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
|
3703
|
+
console.warn(
|
|
3704
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
|
3705
|
+
);
|
|
3706
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
|
3707
|
+
console.warn(
|
|
3708
|
+
`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.`
|
|
3709
|
+
);
|
|
3710
|
+
}
|
|
3711
|
+
return {
|
|
3712
|
+
fetch,
|
|
3713
|
+
databaseURL,
|
|
3714
|
+
apiKey,
|
|
3715
|
+
branch,
|
|
3716
|
+
cache,
|
|
3717
|
+
trace,
|
|
3718
|
+
host,
|
|
3719
|
+
clientID: generateUUID(),
|
|
3720
|
+
enableBrowser,
|
|
3721
|
+
clientName,
|
|
3722
|
+
xataAgentExtra
|
|
3723
|
+
};
|
|
3724
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
|
3365
3725
|
fetch,
|
|
3366
3726
|
apiKey,
|
|
3367
3727
|
databaseURL,
|
|
3368
3728
|
branch,
|
|
3369
3729
|
trace,
|
|
3370
3730
|
clientID,
|
|
3371
|
-
clientName
|
|
3731
|
+
clientName,
|
|
3732
|
+
xataAgentExtra
|
|
3372
3733
|
}) {
|
|
3373
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
|
3374
|
-
if (!branchValue)
|
|
3375
|
-
throw new Error("Unable to resolve branch value");
|
|
3376
3734
|
return {
|
|
3377
|
-
|
|
3735
|
+
fetch,
|
|
3378
3736
|
apiKey,
|
|
3379
3737
|
apiUrl: "",
|
|
3380
3738
|
workspacesApiUrl: (path, params) => {
|
|
3381
3739
|
const hasBranch = params.dbBranchName ?? params.branch;
|
|
3382
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
|
3740
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
|
3383
3741
|
return databaseURL + newPath;
|
|
3384
3742
|
},
|
|
3385
3743
|
trace,
|
|
3386
3744
|
clientID,
|
|
3387
|
-
clientName
|
|
3388
|
-
|
|
3389
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
|
3390
|
-
if (__privateGet(this, _branch))
|
|
3391
|
-
return __privateGet(this, _branch);
|
|
3392
|
-
if (param === void 0)
|
|
3393
|
-
return void 0;
|
|
3394
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
|
3395
|
-
const evaluateBranch = async (strategy) => {
|
|
3396
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
|
3745
|
+
clientName,
|
|
3746
|
+
xataAgentExtra
|
|
3397
3747
|
};
|
|
3398
|
-
for await (const strategy of strategies) {
|
|
3399
|
-
const branch = await evaluateBranch(strategy);
|
|
3400
|
-
if (branch) {
|
|
3401
|
-
__privateSet(this, _branch, branch);
|
|
3402
|
-
return branch;
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
3748
|
}, _a;
|
|
3406
3749
|
};
|
|
3407
3750
|
class BaseClient extends buildClient() {
|
|
@@ -3496,5 +3839,5 @@ class XataError extends Error {
|
|
|
3496
3839
|
}
|
|
3497
3840
|
}
|
|
3498
3841
|
|
|
3499
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn,
|
|
3842
|
+
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
|
3500
3843
|
//# sourceMappingURL=index.mjs.map
|