@xata.io/client 0.22.3 → 0.23.0
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 +1 -1
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +18 -0
- package/dist/index.cjs +414 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +295 -49
- package/dist/index.mjs +410 -216
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -93,8 +93,7 @@ function getEnvironment() {
|
|
93
93
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
94
94
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
95
95
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
96
|
-
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH
|
97
|
-
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
96
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH
|
98
97
|
};
|
99
98
|
}
|
100
99
|
} catch (err) {
|
@@ -105,8 +104,7 @@ function getEnvironment() {
|
|
105
104
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
106
105
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
107
106
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
108
|
-
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH")
|
109
|
-
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
107
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH")
|
110
108
|
};
|
111
109
|
}
|
112
110
|
} catch (err) {
|
@@ -115,8 +113,7 @@ function getEnvironment() {
|
|
115
113
|
apiKey: getGlobalApiKey(),
|
116
114
|
databaseURL: getGlobalDatabaseURL(),
|
117
115
|
branch: getGlobalBranch(),
|
118
|
-
envBranch: void 0
|
119
|
-
fallbackBranch: getGlobalFallbackBranch()
|
116
|
+
envBranch: void 0
|
120
117
|
};
|
121
118
|
}
|
122
119
|
function getEnableBrowserVariable() {
|
@@ -159,37 +156,26 @@ function getGlobalBranch() {
|
|
159
156
|
return void 0;
|
160
157
|
}
|
161
158
|
}
|
162
|
-
function
|
159
|
+
function getDatabaseURL() {
|
163
160
|
try {
|
164
|
-
|
161
|
+
const { databaseURL } = getEnvironment();
|
162
|
+
return databaseURL;
|
165
163
|
} catch (err) {
|
166
164
|
return void 0;
|
167
165
|
}
|
168
166
|
}
|
169
|
-
|
170
|
-
const cmd = ["git", "branch", "--show-current"];
|
171
|
-
const fullCmd = cmd.join(" ");
|
172
|
-
const nodeModule = ["child", "process"].join("_");
|
173
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
174
|
-
try {
|
175
|
-
if (typeof require === "function") {
|
176
|
-
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
177
|
-
}
|
178
|
-
} catch (err) {
|
179
|
-
}
|
167
|
+
function getAPIKey() {
|
180
168
|
try {
|
181
|
-
|
182
|
-
|
183
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
184
|
-
}
|
169
|
+
const { apiKey } = getEnvironment();
|
170
|
+
return apiKey;
|
185
171
|
} catch (err) {
|
172
|
+
return void 0;
|
186
173
|
}
|
187
174
|
}
|
188
|
-
|
189
|
-
function getAPIKey() {
|
175
|
+
function getBranch() {
|
190
176
|
try {
|
191
|
-
const {
|
192
|
-
return
|
177
|
+
const { branch, envBranch } = getEnvironment();
|
178
|
+
return branch ?? envBranch;
|
193
179
|
} catch (err) {
|
194
180
|
return void 0;
|
195
181
|
}
|
@@ -302,7 +288,180 @@ function generateUUID() {
|
|
302
288
|
});
|
303
289
|
}
|
304
290
|
|
305
|
-
|
291
|
+
async function getBytes(stream, onChunk) {
|
292
|
+
const reader = stream.getReader();
|
293
|
+
let result;
|
294
|
+
while (!(result = await reader.read()).done) {
|
295
|
+
onChunk(result.value);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
function getLines(onLine) {
|
299
|
+
let buffer;
|
300
|
+
let position;
|
301
|
+
let fieldLength;
|
302
|
+
let discardTrailingNewline = false;
|
303
|
+
return function onChunk(arr) {
|
304
|
+
if (buffer === void 0) {
|
305
|
+
buffer = arr;
|
306
|
+
position = 0;
|
307
|
+
fieldLength = -1;
|
308
|
+
} else {
|
309
|
+
buffer = concat(buffer, arr);
|
310
|
+
}
|
311
|
+
const bufLength = buffer.length;
|
312
|
+
let lineStart = 0;
|
313
|
+
while (position < bufLength) {
|
314
|
+
if (discardTrailingNewline) {
|
315
|
+
if (buffer[position] === 10 /* NewLine */) {
|
316
|
+
lineStart = ++position;
|
317
|
+
}
|
318
|
+
discardTrailingNewline = false;
|
319
|
+
}
|
320
|
+
let lineEnd = -1;
|
321
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
322
|
+
switch (buffer[position]) {
|
323
|
+
case 58 /* Colon */:
|
324
|
+
if (fieldLength === -1) {
|
325
|
+
fieldLength = position - lineStart;
|
326
|
+
}
|
327
|
+
break;
|
328
|
+
case 13 /* CarriageReturn */:
|
329
|
+
discardTrailingNewline = true;
|
330
|
+
case 10 /* NewLine */:
|
331
|
+
lineEnd = position;
|
332
|
+
break;
|
333
|
+
}
|
334
|
+
}
|
335
|
+
if (lineEnd === -1) {
|
336
|
+
break;
|
337
|
+
}
|
338
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
339
|
+
lineStart = position;
|
340
|
+
fieldLength = -1;
|
341
|
+
}
|
342
|
+
if (lineStart === bufLength) {
|
343
|
+
buffer = void 0;
|
344
|
+
} else if (lineStart !== 0) {
|
345
|
+
buffer = buffer.subarray(lineStart);
|
346
|
+
position -= lineStart;
|
347
|
+
}
|
348
|
+
};
|
349
|
+
}
|
350
|
+
function getMessages(onId, onRetry, onMessage) {
|
351
|
+
let message = newMessage();
|
352
|
+
const decoder = new TextDecoder();
|
353
|
+
return function onLine(line, fieldLength) {
|
354
|
+
if (line.length === 0) {
|
355
|
+
onMessage?.(message);
|
356
|
+
message = newMessage();
|
357
|
+
} else if (fieldLength > 0) {
|
358
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
359
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
360
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
361
|
+
switch (field) {
|
362
|
+
case "data":
|
363
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
364
|
+
break;
|
365
|
+
case "event":
|
366
|
+
message.event = value;
|
367
|
+
break;
|
368
|
+
case "id":
|
369
|
+
onId(message.id = value);
|
370
|
+
break;
|
371
|
+
case "retry":
|
372
|
+
const retry = parseInt(value, 10);
|
373
|
+
if (!isNaN(retry)) {
|
374
|
+
onRetry(message.retry = retry);
|
375
|
+
}
|
376
|
+
break;
|
377
|
+
}
|
378
|
+
}
|
379
|
+
};
|
380
|
+
}
|
381
|
+
function concat(a, b) {
|
382
|
+
const res = new Uint8Array(a.length + b.length);
|
383
|
+
res.set(a);
|
384
|
+
res.set(b, a.length);
|
385
|
+
return res;
|
386
|
+
}
|
387
|
+
function newMessage() {
|
388
|
+
return {
|
389
|
+
data: "",
|
390
|
+
event: "",
|
391
|
+
id: "",
|
392
|
+
retry: void 0
|
393
|
+
};
|
394
|
+
}
|
395
|
+
const EventStreamContentType = "text/event-stream";
|
396
|
+
const LastEventId = "last-event-id";
|
397
|
+
function fetchEventSource(input, {
|
398
|
+
signal: inputSignal,
|
399
|
+
headers: inputHeaders,
|
400
|
+
onopen: inputOnOpen,
|
401
|
+
onmessage,
|
402
|
+
onclose,
|
403
|
+
onerror,
|
404
|
+
fetch: inputFetch,
|
405
|
+
...rest
|
406
|
+
}) {
|
407
|
+
return new Promise((resolve, reject) => {
|
408
|
+
const headers = { ...inputHeaders };
|
409
|
+
if (!headers.accept) {
|
410
|
+
headers.accept = EventStreamContentType;
|
411
|
+
}
|
412
|
+
let curRequestController;
|
413
|
+
function dispose() {
|
414
|
+
curRequestController.abort();
|
415
|
+
}
|
416
|
+
inputSignal?.addEventListener("abort", () => {
|
417
|
+
dispose();
|
418
|
+
resolve();
|
419
|
+
});
|
420
|
+
const fetchImpl = inputFetch ?? fetch;
|
421
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
422
|
+
async function create() {
|
423
|
+
curRequestController = new AbortController();
|
424
|
+
try {
|
425
|
+
const response = await fetchImpl(input, {
|
426
|
+
...rest,
|
427
|
+
headers,
|
428
|
+
signal: curRequestController.signal
|
429
|
+
});
|
430
|
+
await onopen(response);
|
431
|
+
await getBytes(
|
432
|
+
response.body,
|
433
|
+
getLines(
|
434
|
+
getMessages(
|
435
|
+
(id) => {
|
436
|
+
if (id) {
|
437
|
+
headers[LastEventId] = id;
|
438
|
+
} else {
|
439
|
+
delete headers[LastEventId];
|
440
|
+
}
|
441
|
+
},
|
442
|
+
(_retry) => {
|
443
|
+
},
|
444
|
+
onmessage
|
445
|
+
)
|
446
|
+
)
|
447
|
+
);
|
448
|
+
onclose?.();
|
449
|
+
dispose();
|
450
|
+
resolve();
|
451
|
+
} catch (err) {
|
452
|
+
}
|
453
|
+
}
|
454
|
+
create();
|
455
|
+
});
|
456
|
+
}
|
457
|
+
function defaultOnOpen(response) {
|
458
|
+
const contentType = response.headers?.get("content-type");
|
459
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
460
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
|
464
|
+
const VERSION = "0.23.0";
|
306
465
|
|
307
466
|
class ErrorWithCause extends Error {
|
308
467
|
constructor(message, options) {
|
@@ -386,7 +545,7 @@ async function fetch$1({
|
|
386
545
|
headers: customHeaders,
|
387
546
|
pathParams,
|
388
547
|
queryParams,
|
389
|
-
|
548
|
+
fetch: fetch2,
|
390
549
|
apiKey,
|
391
550
|
endpoint,
|
392
551
|
apiUrl,
|
@@ -399,7 +558,7 @@ async function fetch$1({
|
|
399
558
|
xataAgentExtra,
|
400
559
|
fetchOptions = {}
|
401
560
|
}) {
|
402
|
-
pool.setFetch(
|
561
|
+
pool.setFetch(fetch2);
|
403
562
|
return await trace(
|
404
563
|
`${method.toUpperCase()} ${path}`,
|
405
564
|
async ({ setAttributes }) => {
|
@@ -461,6 +620,59 @@ async function fetch$1({
|
|
461
620
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
462
621
|
);
|
463
622
|
}
|
623
|
+
function fetchSSERequest({
|
624
|
+
url: path,
|
625
|
+
method,
|
626
|
+
body,
|
627
|
+
headers: customHeaders,
|
628
|
+
pathParams,
|
629
|
+
queryParams,
|
630
|
+
fetch: fetch2,
|
631
|
+
apiKey,
|
632
|
+
endpoint,
|
633
|
+
apiUrl,
|
634
|
+
workspacesApiUrl,
|
635
|
+
onMessage,
|
636
|
+
onError,
|
637
|
+
onClose,
|
638
|
+
signal,
|
639
|
+
clientID,
|
640
|
+
sessionID,
|
641
|
+
clientName,
|
642
|
+
xataAgentExtra
|
643
|
+
}) {
|
644
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
645
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
646
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
647
|
+
void fetchEventSource(url, {
|
648
|
+
method,
|
649
|
+
body: JSON.stringify(body),
|
650
|
+
fetch: fetch2,
|
651
|
+
signal,
|
652
|
+
headers: {
|
653
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
654
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
655
|
+
"X-Xata-Agent": compact([
|
656
|
+
["client", "TS_SDK"],
|
657
|
+
["version", VERSION],
|
658
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
659
|
+
...Object.entries(xataAgentExtra ?? {})
|
660
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
661
|
+
...customHeaders,
|
662
|
+
Authorization: `Bearer ${apiKey}`,
|
663
|
+
"Content-Type": "application/json"
|
664
|
+
},
|
665
|
+
onmessage(ev) {
|
666
|
+
onMessage?.(JSON.parse(ev.data));
|
667
|
+
},
|
668
|
+
onerror(ev) {
|
669
|
+
onError?.(JSON.parse(ev.data));
|
670
|
+
},
|
671
|
+
onclose() {
|
672
|
+
onClose?.();
|
673
|
+
}
|
674
|
+
});
|
675
|
+
}
|
464
676
|
function parseUrl(url) {
|
465
677
|
try {
|
466
678
|
const { host, protocol } = new URL(url);
|
@@ -491,6 +703,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
491
703
|
...variables,
|
492
704
|
signal
|
493
705
|
});
|
706
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
707
|
+
url: "/db/{dbBranchName}/copy",
|
708
|
+
method: "post",
|
709
|
+
...variables,
|
710
|
+
signal
|
711
|
+
});
|
494
712
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
495
713
|
url: "/db/{dbBranchName}/metadata",
|
496
714
|
method: "put",
|
@@ -540,6 +758,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
540
758
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
541
759
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
542
760
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
761
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
543
762
|
const createTable = (variables, signal) => dataPlaneFetch({
|
544
763
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
545
764
|
method: "put",
|
@@ -614,6 +833,12 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
614
833
|
signal
|
615
834
|
});
|
616
835
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
836
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
837
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
838
|
+
method: "post",
|
839
|
+
...variables,
|
840
|
+
signal
|
841
|
+
});
|
617
842
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
618
843
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
619
844
|
const operationsByTag$2 = {
|
@@ -622,6 +847,7 @@ const operationsByTag$2 = {
|
|
622
847
|
getBranchDetails,
|
623
848
|
createBranch,
|
624
849
|
deleteBranch,
|
850
|
+
copyBranch,
|
625
851
|
updateBranchMetadata,
|
626
852
|
getBranchMetadata,
|
627
853
|
getBranchStats,
|
@@ -639,7 +865,8 @@ const operationsByTag$2 = {
|
|
639
865
|
compareBranchSchemas,
|
640
866
|
updateBranchSchema,
|
641
867
|
previewBranchSchemaEdit,
|
642
|
-
applyBranchSchemaEdit
|
868
|
+
applyBranchSchemaEdit,
|
869
|
+
pushBranchMigrations
|
643
870
|
},
|
644
871
|
migrationRequests: {
|
645
872
|
queryMigrationRequests,
|
@@ -673,7 +900,15 @@ const operationsByTag$2 = {
|
|
673
900
|
deleteRecord,
|
674
901
|
bulkInsertTableRecords
|
675
902
|
},
|
676
|
-
searchAndFilter: {
|
903
|
+
searchAndFilter: {
|
904
|
+
queryTable,
|
905
|
+
searchBranch,
|
906
|
+
searchTable,
|
907
|
+
vectorSearchTable,
|
908
|
+
askTable,
|
909
|
+
summarizeTable,
|
910
|
+
aggregateTable
|
911
|
+
}
|
677
912
|
};
|
678
913
|
|
679
914
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -832,6 +1067,10 @@ const providers = {
|
|
832
1067
|
staging: {
|
833
1068
|
main: "https://api.staging-xata.dev",
|
834
1069
|
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1070
|
+
},
|
1071
|
+
dev: {
|
1072
|
+
main: "https://api.dev-xata.dev",
|
1073
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
835
1074
|
}
|
836
1075
|
};
|
837
1076
|
function isHostProviderAlias(alias) {
|
@@ -849,6 +1088,11 @@ function parseProviderString(provider = "production") {
|
|
849
1088
|
return null;
|
850
1089
|
return { main, workspaces };
|
851
1090
|
}
|
1091
|
+
function buildProviderString(provider) {
|
1092
|
+
if (isHostProviderAlias(provider))
|
1093
|
+
return provider;
|
1094
|
+
return `${provider.main},${provider.workspaces}`;
|
1095
|
+
}
|
852
1096
|
function parseWorkspacesUrlParts(url) {
|
853
1097
|
if (!isString(url))
|
854
1098
|
return null;
|
@@ -895,7 +1139,7 @@ class XataApiClient {
|
|
895
1139
|
__privateSet$7(this, _extraProps, {
|
896
1140
|
apiUrl: getHostUrl(provider, "main"),
|
897
1141
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
898
|
-
|
1142
|
+
fetch: getFetchImplementation(options.fetch),
|
899
1143
|
apiKey,
|
900
1144
|
trace,
|
901
1145
|
clientName: options.clientName,
|
@@ -1161,6 +1405,20 @@ class BranchApi {
|
|
1161
1405
|
...this.extraProps
|
1162
1406
|
});
|
1163
1407
|
}
|
1408
|
+
copyBranch({
|
1409
|
+
workspace,
|
1410
|
+
region,
|
1411
|
+
database,
|
1412
|
+
branch,
|
1413
|
+
destinationBranch,
|
1414
|
+
limit
|
1415
|
+
}) {
|
1416
|
+
return operationsByTag.branch.copyBranch({
|
1417
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1418
|
+
body: { destinationBranch, limit },
|
1419
|
+
...this.extraProps
|
1420
|
+
});
|
1421
|
+
}
|
1164
1422
|
updateBranchMetadata({
|
1165
1423
|
workspace,
|
1166
1424
|
region,
|
@@ -1575,6 +1833,38 @@ class SearchAndFilterApi {
|
|
1575
1833
|
...this.extraProps
|
1576
1834
|
});
|
1577
1835
|
}
|
1836
|
+
vectorSearchTable({
|
1837
|
+
workspace,
|
1838
|
+
region,
|
1839
|
+
database,
|
1840
|
+
branch,
|
1841
|
+
table,
|
1842
|
+
queryVector,
|
1843
|
+
column,
|
1844
|
+
similarityFunction,
|
1845
|
+
size,
|
1846
|
+
filter
|
1847
|
+
}) {
|
1848
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
1849
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1850
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
1851
|
+
...this.extraProps
|
1852
|
+
});
|
1853
|
+
}
|
1854
|
+
askTable({
|
1855
|
+
workspace,
|
1856
|
+
region,
|
1857
|
+
database,
|
1858
|
+
branch,
|
1859
|
+
table,
|
1860
|
+
options
|
1861
|
+
}) {
|
1862
|
+
return operationsByTag.searchAndFilter.askTable({
|
1863
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1864
|
+
body: { ...options },
|
1865
|
+
...this.extraProps
|
1866
|
+
});
|
1867
|
+
}
|
1578
1868
|
summarizeTable({
|
1579
1869
|
workspace,
|
1580
1870
|
region,
|
@@ -1839,6 +2129,19 @@ class MigrationsApi {
|
|
1839
2129
|
...this.extraProps
|
1840
2130
|
});
|
1841
2131
|
}
|
2132
|
+
pushBranchMigrations({
|
2133
|
+
workspace,
|
2134
|
+
region,
|
2135
|
+
database,
|
2136
|
+
branch,
|
2137
|
+
migrations
|
2138
|
+
}) {
|
2139
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2140
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2141
|
+
body: { migrations },
|
2142
|
+
...this.extraProps
|
2143
|
+
});
|
2144
|
+
}
|
1842
2145
|
}
|
1843
2146
|
class DatabaseApi {
|
1844
2147
|
constructor(extraProps) {
|
@@ -1928,9 +2231,8 @@ class DatabaseApi {
|
|
1928
2231
|
}
|
1929
2232
|
|
1930
2233
|
class XataApiPlugin {
|
1931
|
-
|
1932
|
-
|
1933
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2234
|
+
build(options) {
|
2235
|
+
return new XataApiClient(options);
|
1934
2236
|
}
|
1935
2237
|
}
|
1936
2238
|
|
@@ -2344,10 +2646,7 @@ class RestRepository extends Query {
|
|
2344
2646
|
__privateSet$4(this, _db, options.db);
|
2345
2647
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2346
2648
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2347
|
-
__privateSet$4(this, _getFetchProps,
|
2348
|
-
const props = await options.pluginOptions.getFetchProps();
|
2349
|
-
return { ...props, sessionID: generateUUID() };
|
2350
|
-
});
|
2649
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2351
2650
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2352
2651
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2353
2652
|
return trace(name, fn, {
|
@@ -2404,7 +2703,6 @@ class RestRepository extends Query {
|
|
2404
2703
|
}
|
2405
2704
|
const id = extractId(a);
|
2406
2705
|
if (id) {
|
2407
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2408
2706
|
try {
|
2409
2707
|
const response = await getRecord({
|
2410
2708
|
pathParams: {
|
@@ -2415,7 +2713,7 @@ class RestRepository extends Query {
|
|
2415
2713
|
recordId: id
|
2416
2714
|
},
|
2417
2715
|
queryParams: { columns },
|
2418
|
-
...
|
2716
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2419
2717
|
});
|
2420
2718
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2421
2719
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2593,7 +2891,6 @@ class RestRepository extends Query {
|
|
2593
2891
|
}
|
2594
2892
|
async search(query, options = {}) {
|
2595
2893
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2596
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2597
2894
|
const { records } = await searchTable({
|
2598
2895
|
pathParams: {
|
2599
2896
|
workspace: "{workspaceId}",
|
@@ -2611,7 +2908,7 @@ class RestRepository extends Query {
|
|
2611
2908
|
page: options.page,
|
2612
2909
|
target: options.target
|
2613
2910
|
},
|
2614
|
-
...
|
2911
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2615
2912
|
});
|
2616
2913
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2617
2914
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2619,7 +2916,6 @@ class RestRepository extends Query {
|
|
2619
2916
|
}
|
2620
2917
|
async vectorSearch(column, query, options) {
|
2621
2918
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
2622
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2623
2919
|
const { records } = await vectorSearchTable({
|
2624
2920
|
pathParams: {
|
2625
2921
|
workspace: "{workspaceId}",
|
@@ -2634,7 +2930,7 @@ class RestRepository extends Query {
|
|
2634
2930
|
size: options?.size,
|
2635
2931
|
filter: options?.filter
|
2636
2932
|
},
|
2637
|
-
...
|
2933
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2638
2934
|
});
|
2639
2935
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2640
2936
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2642,7 +2938,6 @@ class RestRepository extends Query {
|
|
2642
2938
|
}
|
2643
2939
|
async aggregate(aggs, filter) {
|
2644
2940
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2645
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2646
2941
|
const result = await aggregateTable({
|
2647
2942
|
pathParams: {
|
2648
2943
|
workspace: "{workspaceId}",
|
@@ -2651,7 +2946,7 @@ class RestRepository extends Query {
|
|
2651
2946
|
tableName: __privateGet$4(this, _table)
|
2652
2947
|
},
|
2653
2948
|
body: { aggs, filter },
|
2654
|
-
...
|
2949
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2655
2950
|
});
|
2656
2951
|
return result;
|
2657
2952
|
});
|
@@ -2662,7 +2957,6 @@ class RestRepository extends Query {
|
|
2662
2957
|
if (cacheQuery)
|
2663
2958
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2664
2959
|
const data = query.getQueryOptions();
|
2665
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2666
2960
|
const { meta, records: objects } = await queryTable({
|
2667
2961
|
pathParams: {
|
2668
2962
|
workspace: "{workspaceId}",
|
@@ -2678,7 +2972,7 @@ class RestRepository extends Query {
|
|
2678
2972
|
consistency: data.consistency
|
2679
2973
|
},
|
2680
2974
|
fetchOptions: data.fetchOptions,
|
2681
|
-
...
|
2975
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2682
2976
|
});
|
2683
2977
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2684
2978
|
const records = objects.map(
|
@@ -2691,7 +2985,6 @@ class RestRepository extends Query {
|
|
2691
2985
|
async summarizeTable(query, summaries, summariesFilter) {
|
2692
2986
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2693
2987
|
const data = query.getQueryOptions();
|
2694
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2695
2988
|
const result = await summarizeTable({
|
2696
2989
|
pathParams: {
|
2697
2990
|
workspace: "{workspaceId}",
|
@@ -2708,11 +3001,39 @@ class RestRepository extends Query {
|
|
2708
3001
|
summaries,
|
2709
3002
|
summariesFilter
|
2710
3003
|
},
|
2711
|
-
...
|
3004
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2712
3005
|
});
|
2713
3006
|
return result;
|
2714
3007
|
});
|
2715
3008
|
}
|
3009
|
+
ask(question, options) {
|
3010
|
+
const params = {
|
3011
|
+
pathParams: {
|
3012
|
+
workspace: "{workspaceId}",
|
3013
|
+
dbBranchName: "{dbBranch}",
|
3014
|
+
region: "{region}",
|
3015
|
+
tableName: __privateGet$4(this, _table)
|
3016
|
+
},
|
3017
|
+
body: {
|
3018
|
+
question,
|
3019
|
+
...options
|
3020
|
+
},
|
3021
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3022
|
+
};
|
3023
|
+
if (options?.onMessage) {
|
3024
|
+
fetchSSERequest({
|
3025
|
+
endpoint: "dataPlane",
|
3026
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3027
|
+
method: "POST",
|
3028
|
+
onMessage: (message) => {
|
3029
|
+
options.onMessage?.({ answer: message.text });
|
3030
|
+
},
|
3031
|
+
...params
|
3032
|
+
});
|
3033
|
+
} else {
|
3034
|
+
return askTable(params);
|
3035
|
+
}
|
3036
|
+
}
|
2716
3037
|
}
|
2717
3038
|
_table = new WeakMap();
|
2718
3039
|
_getFetchProps = new WeakMap();
|
@@ -2722,7 +3043,6 @@ _schemaTables$2 = new WeakMap();
|
|
2722
3043
|
_trace = new WeakMap();
|
2723
3044
|
_insertRecordWithoutId = new WeakSet();
|
2724
3045
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2725
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2726
3046
|
const record = transformObjectLinks(object);
|
2727
3047
|
const response = await insertRecord({
|
2728
3048
|
pathParams: {
|
@@ -2733,14 +3053,13 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2733
3053
|
},
|
2734
3054
|
queryParams: { columns },
|
2735
3055
|
body: record,
|
2736
|
-
...
|
3056
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2737
3057
|
});
|
2738
3058
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2739
3059
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2740
3060
|
};
|
2741
3061
|
_insertRecordWithId = new WeakSet();
|
2742
3062
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2743
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2744
3063
|
const record = transformObjectLinks(object);
|
2745
3064
|
const response = await insertRecordWithID({
|
2746
3065
|
pathParams: {
|
@@ -2752,14 +3071,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2752
3071
|
},
|
2753
3072
|
body: record,
|
2754
3073
|
queryParams: { createOnly, columns, ifVersion },
|
2755
|
-
...
|
3074
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2756
3075
|
});
|
2757
3076
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2758
3077
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2759
3078
|
};
|
2760
3079
|
_insertRecords = new WeakSet();
|
2761
3080
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2762
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2763
3081
|
const chunkedOperations = chunk(
|
2764
3082
|
objects.map((object) => ({
|
2765
3083
|
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
@@ -2775,7 +3093,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2775
3093
|
region: "{region}"
|
2776
3094
|
},
|
2777
3095
|
body: { operations },
|
2778
|
-
...
|
3096
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2779
3097
|
});
|
2780
3098
|
for (const result of results) {
|
2781
3099
|
if (result.operation === "insert") {
|
@@ -2789,7 +3107,6 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2789
3107
|
};
|
2790
3108
|
_updateRecordWithID = new WeakSet();
|
2791
3109
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2792
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2793
3110
|
const { id: _id, ...record } = transformObjectLinks(object);
|
2794
3111
|
try {
|
2795
3112
|
const response = await updateRecordWithID({
|
@@ -2802,7 +3119,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2802
3119
|
},
|
2803
3120
|
queryParams: { columns, ifVersion },
|
2804
3121
|
body: record,
|
2805
|
-
...
|
3122
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2806
3123
|
});
|
2807
3124
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2808
3125
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2815,7 +3132,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2815
3132
|
};
|
2816
3133
|
_updateRecords = new WeakSet();
|
2817
3134
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2818
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2819
3135
|
const chunkedOperations = chunk(
|
2820
3136
|
objects.map(({ id, ...object }) => ({
|
2821
3137
|
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
@@ -2831,7 +3147,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2831
3147
|
region: "{region}"
|
2832
3148
|
},
|
2833
3149
|
body: { operations },
|
2834
|
-
...
|
3150
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2835
3151
|
});
|
2836
3152
|
for (const result of results) {
|
2837
3153
|
if (result.operation === "update") {
|
@@ -2845,7 +3161,6 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2845
3161
|
};
|
2846
3162
|
_upsertRecordWithID = new WeakSet();
|
2847
3163
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2848
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2849
3164
|
const response = await upsertRecordWithID({
|
2850
3165
|
pathParams: {
|
2851
3166
|
workspace: "{workspaceId}",
|
@@ -2856,14 +3171,13 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2856
3171
|
},
|
2857
3172
|
queryParams: { columns, ifVersion },
|
2858
3173
|
body: object,
|
2859
|
-
...
|
3174
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2860
3175
|
});
|
2861
3176
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2862
3177
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2863
3178
|
};
|
2864
3179
|
_deleteRecord = new WeakSet();
|
2865
3180
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2866
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2867
3181
|
try {
|
2868
3182
|
const response = await deleteRecord({
|
2869
3183
|
pathParams: {
|
@@ -2874,7 +3188,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2874
3188
|
recordId
|
2875
3189
|
},
|
2876
3190
|
queryParams: { columns },
|
2877
|
-
...
|
3191
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2878
3192
|
});
|
2879
3193
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2880
3194
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2887,7 +3201,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2887
3201
|
};
|
2888
3202
|
_deleteRecords = new WeakSet();
|
2889
3203
|
deleteRecords_fn = async function(recordIds) {
|
2890
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2891
3204
|
const chunkedOperations = chunk(
|
2892
3205
|
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2893
3206
|
BULK_OPERATION_MAX_SIZE
|
@@ -2900,21 +3213,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2900
3213
|
region: "{region}"
|
2901
3214
|
},
|
2902
3215
|
body: { operations },
|
2903
|
-
...
|
3216
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2904
3217
|
});
|
2905
3218
|
}
|
2906
3219
|
};
|
2907
3220
|
_setCacheQuery = new WeakSet();
|
2908
3221
|
setCacheQuery_fn = async function(query, meta, records) {
|
2909
|
-
await __privateGet$4(this, _cache)
|
3222
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
2910
3223
|
};
|
2911
3224
|
_getCacheQuery = new WeakSet();
|
2912
3225
|
getCacheQuery_fn = async function(query) {
|
2913
3226
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2914
|
-
const result = await __privateGet$4(this, _cache)
|
3227
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2915
3228
|
if (!result)
|
2916
3229
|
return null;
|
2917
|
-
const
|
3230
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3231
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2918
3232
|
if (ttl < 0)
|
2919
3233
|
return null;
|
2920
3234
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2924,10 +3238,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
2924
3238
|
getSchemaTables_fn$1 = async function() {
|
2925
3239
|
if (__privateGet$4(this, _schemaTables$2))
|
2926
3240
|
return __privateGet$4(this, _schemaTables$2);
|
2927
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2928
3241
|
const { schema } = await getBranchDetails({
|
2929
3242
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2930
|
-
...
|
3243
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2931
3244
|
});
|
2932
3245
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2933
3246
|
return schema.tables;
|
@@ -3203,19 +3516,19 @@ class SearchPlugin extends XataPlugin {
|
|
3203
3516
|
__privateAdd$1(this, _schemaTables, void 0);
|
3204
3517
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3205
3518
|
}
|
3206
|
-
build(
|
3519
|
+
build(pluginOptions) {
|
3207
3520
|
return {
|
3208
3521
|
all: async (query, options = {}) => {
|
3209
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3210
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3522
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3523
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3211
3524
|
return records.map((record) => {
|
3212
3525
|
const { table = "orphan" } = record.xata;
|
3213
3526
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3214
3527
|
});
|
3215
3528
|
},
|
3216
3529
|
byTable: async (query, options = {}) => {
|
3217
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3218
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3530
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3531
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3219
3532
|
return records.reduce((acc, record) => {
|
3220
3533
|
const { table = "orphan" } = record.xata;
|
3221
3534
|
const items = acc[table] ?? [];
|
@@ -3228,38 +3541,35 @@ class SearchPlugin extends XataPlugin {
|
|
3228
3541
|
}
|
3229
3542
|
_schemaTables = new WeakMap();
|
3230
3543
|
_search = new WeakSet();
|
3231
|
-
search_fn = async function(query, options,
|
3232
|
-
const fetchProps = await getFetchProps();
|
3544
|
+
search_fn = async function(query, options, pluginOptions) {
|
3233
3545
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3234
3546
|
const { records } = await searchBranch({
|
3235
3547
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3236
3548
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3237
|
-
...
|
3549
|
+
...pluginOptions
|
3238
3550
|
});
|
3239
3551
|
return records;
|
3240
3552
|
};
|
3241
3553
|
_getSchemaTables = new WeakSet();
|
3242
|
-
getSchemaTables_fn = async function(
|
3554
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3243
3555
|
if (__privateGet$1(this, _schemaTables))
|
3244
3556
|
return __privateGet$1(this, _schemaTables);
|
3245
|
-
const fetchProps = await getFetchProps();
|
3246
3557
|
const { schema } = await getBranchDetails({
|
3247
3558
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3248
|
-
...
|
3559
|
+
...pluginOptions
|
3249
3560
|
});
|
3250
3561
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3251
3562
|
return schema.tables;
|
3252
3563
|
};
|
3253
3564
|
|
3254
3565
|
class TransactionPlugin extends XataPlugin {
|
3255
|
-
build(
|
3566
|
+
build(pluginOptions) {
|
3256
3567
|
return {
|
3257
3568
|
run: async (operations) => {
|
3258
|
-
const fetchProps = await getFetchProps();
|
3259
3569
|
const response = await branchTransaction({
|
3260
3570
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3261
3571
|
body: { operations },
|
3262
|
-
...
|
3572
|
+
...pluginOptions
|
3263
3573
|
});
|
3264
3574
|
return response;
|
3265
3575
|
}
|
@@ -3267,91 +3577,6 @@ class TransactionPlugin extends XataPlugin {
|
|
3267
3577
|
}
|
3268
3578
|
}
|
3269
3579
|
|
3270
|
-
const isBranchStrategyBuilder = (strategy) => {
|
3271
|
-
return typeof strategy === "function";
|
3272
|
-
};
|
3273
|
-
|
3274
|
-
async function getCurrentBranchName(options) {
|
3275
|
-
const { branch, envBranch } = getEnvironment();
|
3276
|
-
if (branch)
|
3277
|
-
return branch;
|
3278
|
-
const gitBranch = envBranch || await getGitBranch();
|
3279
|
-
return resolveXataBranch(gitBranch, options);
|
3280
|
-
}
|
3281
|
-
async function getCurrentBranchDetails(options) {
|
3282
|
-
const branch = await getCurrentBranchName(options);
|
3283
|
-
return getDatabaseBranch(branch, options);
|
3284
|
-
}
|
3285
|
-
async function resolveXataBranch(gitBranch, options) {
|
3286
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3287
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3288
|
-
if (!databaseURL)
|
3289
|
-
throw new Error(
|
3290
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3291
|
-
);
|
3292
|
-
if (!apiKey)
|
3293
|
-
throw new Error(
|
3294
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3295
|
-
);
|
3296
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3297
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3298
|
-
if (!urlParts)
|
3299
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3300
|
-
const { workspace, region } = urlParts;
|
3301
|
-
const { fallbackBranch } = getEnvironment();
|
3302
|
-
const { branch } = await resolveBranch({
|
3303
|
-
apiKey,
|
3304
|
-
apiUrl: databaseURL,
|
3305
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3306
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3307
|
-
pathParams: { dbName, workspace, region },
|
3308
|
-
queryParams: { gitBranch, fallbackBranch },
|
3309
|
-
trace: defaultTrace,
|
3310
|
-
clientName: options?.clientName,
|
3311
|
-
xataAgentExtra: options?.xataAgentExtra
|
3312
|
-
});
|
3313
|
-
return branch;
|
3314
|
-
}
|
3315
|
-
async function getDatabaseBranch(branch, options) {
|
3316
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3317
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3318
|
-
if (!databaseURL)
|
3319
|
-
throw new Error(
|
3320
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3321
|
-
);
|
3322
|
-
if (!apiKey)
|
3323
|
-
throw new Error(
|
3324
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3325
|
-
);
|
3326
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3327
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3328
|
-
if (!urlParts)
|
3329
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3330
|
-
const { workspace, region } = urlParts;
|
3331
|
-
try {
|
3332
|
-
return await getBranchDetails({
|
3333
|
-
apiKey,
|
3334
|
-
apiUrl: databaseURL,
|
3335
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3336
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3337
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3338
|
-
trace: defaultTrace
|
3339
|
-
});
|
3340
|
-
} catch (err) {
|
3341
|
-
if (isObject(err) && err.status === 404)
|
3342
|
-
return null;
|
3343
|
-
throw err;
|
3344
|
-
}
|
3345
|
-
}
|
3346
|
-
function getDatabaseURL() {
|
3347
|
-
try {
|
3348
|
-
const { databaseURL } = getEnvironment();
|
3349
|
-
return databaseURL;
|
3350
|
-
} catch (err) {
|
3351
|
-
return void 0;
|
3352
|
-
}
|
3353
|
-
}
|
3354
|
-
|
3355
3580
|
var __accessCheck = (obj, member, msg) => {
|
3356
3581
|
if (!member.has(obj))
|
3357
3582
|
throw TypeError("Cannot " + msg);
|
@@ -3375,20 +3600,18 @@ var __privateMethod = (obj, member, method) => {
|
|
3375
3600
|
return method;
|
3376
3601
|
};
|
3377
3602
|
const buildClient = (plugins) => {
|
3378
|
-
var
|
3603
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3379
3604
|
return _a = class {
|
3380
3605
|
constructor(options = {}, schemaTables) {
|
3381
3606
|
__privateAdd(this, _parseOptions);
|
3382
3607
|
__privateAdd(this, _getFetchProps);
|
3383
|
-
__privateAdd(this, _evaluateBranch);
|
3384
|
-
__privateAdd(this, _branch, void 0);
|
3385
3608
|
__privateAdd(this, _options, void 0);
|
3386
3609
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3387
3610
|
__privateSet(this, _options, safeOptions);
|
3388
3611
|
const pluginOptions = {
|
3389
|
-
|
3612
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3390
3613
|
cache: safeOptions.cache,
|
3391
|
-
|
3614
|
+
host: safeOptions.host
|
3392
3615
|
};
|
3393
3616
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3394
3617
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -3399,22 +3622,15 @@ const buildClient = (plugins) => {
|
|
3399
3622
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3400
3623
|
if (namespace === void 0)
|
3401
3624
|
continue;
|
3402
|
-
|
3403
|
-
if (result instanceof Promise) {
|
3404
|
-
void result.then((namespace2) => {
|
3405
|
-
this[key] = namespace2;
|
3406
|
-
});
|
3407
|
-
} else {
|
3408
|
-
this[key] = result;
|
3409
|
-
}
|
3625
|
+
this[key] = namespace.build(pluginOptions);
|
3410
3626
|
}
|
3411
3627
|
}
|
3412
3628
|
async getConfig() {
|
3413
3629
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3414
|
-
const branch =
|
3630
|
+
const branch = __privateGet(this, _options).branch;
|
3415
3631
|
return { databaseURL, branch };
|
3416
3632
|
}
|
3417
|
-
},
|
3633
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3418
3634
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3419
3635
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3420
3636
|
if (isBrowser && !enableBrowser) {
|
@@ -3424,18 +3640,13 @@ const buildClient = (plugins) => {
|
|
3424
3640
|
}
|
3425
3641
|
const fetch = getFetchImplementation(options?.fetch);
|
3426
3642
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3643
|
+
const branch = options?.branch || getBranch() || "main";
|
3427
3644
|
const apiKey = options?.apiKey || getAPIKey();
|
3428
3645
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3429
3646
|
const trace = options?.trace ?? defaultTrace;
|
3430
3647
|
const clientName = options?.clientName;
|
3648
|
+
const host = options?.host ?? "production";
|
3431
3649
|
const xataAgentExtra = options?.xataAgentExtra;
|
3432
|
-
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3433
|
-
apiKey,
|
3434
|
-
databaseURL,
|
3435
|
-
fetchImpl: options?.fetch,
|
3436
|
-
clientName,
|
3437
|
-
xataAgentExtra
|
3438
|
-
});
|
3439
3650
|
if (!apiKey) {
|
3440
3651
|
throw new Error("Option apiKey is required");
|
3441
3652
|
}
|
@@ -3449,12 +3660,13 @@ const buildClient = (plugins) => {
|
|
3449
3660
|
branch,
|
3450
3661
|
cache,
|
3451
3662
|
trace,
|
3663
|
+
host,
|
3452
3664
|
clientID: generateUUID(),
|
3453
3665
|
enableBrowser,
|
3454
3666
|
clientName,
|
3455
3667
|
xataAgentExtra
|
3456
3668
|
};
|
3457
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn =
|
3669
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3458
3670
|
fetch,
|
3459
3671
|
apiKey,
|
3460
3672
|
databaseURL,
|
@@ -3464,16 +3676,13 @@ const buildClient = (plugins) => {
|
|
3464
3676
|
clientName,
|
3465
3677
|
xataAgentExtra
|
3466
3678
|
}) {
|
3467
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3468
|
-
if (!branchValue)
|
3469
|
-
throw new Error("Unable to resolve branch value");
|
3470
3679
|
return {
|
3471
|
-
|
3680
|
+
fetch,
|
3472
3681
|
apiKey,
|
3473
3682
|
apiUrl: "",
|
3474
3683
|
workspacesApiUrl: (path, params) => {
|
3475
3684
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3476
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
3685
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3477
3686
|
return databaseURL + newPath;
|
3478
3687
|
},
|
3479
3688
|
trace,
|
@@ -3481,22 +3690,6 @@ const buildClient = (plugins) => {
|
|
3481
3690
|
clientName,
|
3482
3691
|
xataAgentExtra
|
3483
3692
|
};
|
3484
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3485
|
-
if (__privateGet(this, _branch))
|
3486
|
-
return __privateGet(this, _branch);
|
3487
|
-
if (param === void 0)
|
3488
|
-
return void 0;
|
3489
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3490
|
-
const evaluateBranch = async (strategy) => {
|
3491
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3492
|
-
};
|
3493
|
-
for await (const strategy of strategies) {
|
3494
|
-
const branch = await evaluateBranch(strategy);
|
3495
|
-
if (branch) {
|
3496
|
-
__privateSet(this, _branch, branch);
|
3497
|
-
return branch;
|
3498
|
-
}
|
3499
|
-
}
|
3500
3693
|
}, _a;
|
3501
3694
|
};
|
3502
3695
|
class BaseClient extends buildClient() {
|
@@ -3616,8 +3809,10 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
3616
3809
|
exports.addTableColumn = addTableColumn;
|
3617
3810
|
exports.aggregateTable = aggregateTable;
|
3618
3811
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
3812
|
+
exports.askTable = askTable;
|
3619
3813
|
exports.branchTransaction = branchTransaction;
|
3620
3814
|
exports.buildClient = buildClient;
|
3815
|
+
exports.buildProviderString = buildProviderString;
|
3621
3816
|
exports.buildWorkerRunner = buildWorkerRunner;
|
3622
3817
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
3623
3818
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
@@ -3625,6 +3820,7 @@ exports.compareBranchSchemas = compareBranchSchemas;
|
|
3625
3820
|
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3626
3821
|
exports.compareMigrationRequest = compareMigrationRequest;
|
3627
3822
|
exports.contains = contains;
|
3823
|
+
exports.copyBranch = copyBranch;
|
3628
3824
|
exports.createBranch = createBranch;
|
3629
3825
|
exports.createDatabase = createDatabase;
|
3630
3826
|
exports.createMigrationRequest = createMigrationRequest;
|
@@ -3647,6 +3843,7 @@ exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
|
3647
3843
|
exports.exists = exists;
|
3648
3844
|
exports.ge = ge;
|
3649
3845
|
exports.getAPIKey = getAPIKey;
|
3846
|
+
exports.getBranch = getBranch;
|
3650
3847
|
exports.getBranchDetails = getBranchDetails;
|
3651
3848
|
exports.getBranchList = getBranchList;
|
3652
3849
|
exports.getBranchMetadata = getBranchMetadata;
|
@@ -3655,8 +3852,6 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
|
3655
3852
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
3656
3853
|
exports.getBranchStats = getBranchStats;
|
3657
3854
|
exports.getColumn = getColumn;
|
3658
|
-
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
3659
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
3660
3855
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3661
3856
|
exports.getDatabaseList = getDatabaseList;
|
3662
3857
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
@@ -3707,6 +3902,7 @@ exports.parseProviderString = parseProviderString;
|
|
3707
3902
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
3708
3903
|
exports.pattern = pattern;
|
3709
3904
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
3905
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
3710
3906
|
exports.queryMigrationRequests = queryMigrationRequests;
|
3711
3907
|
exports.queryTable = queryTable;
|
3712
3908
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|