@xata.io/client 0.22.2 → 0.22.4
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 +3 -3
- package/CHANGELOG.md +18 -0
- package/dist/index.cjs +378 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +293 -40
- package/dist/index.mjs +376 -190
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -164,22 +164,20 @@ function getGlobalFallbackBranch() {
|
|
164
164
|
return void 0;
|
165
165
|
}
|
166
166
|
}
|
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"] };
|
167
|
+
function getDatabaseURL() {
|
172
168
|
try {
|
173
|
-
const {
|
174
|
-
return
|
169
|
+
const { databaseURL } = getEnvironment();
|
170
|
+
return databaseURL;
|
175
171
|
} catch (err) {
|
172
|
+
return void 0;
|
176
173
|
}
|
174
|
+
}
|
175
|
+
function getBranch() {
|
177
176
|
try {
|
178
|
-
|
179
|
-
|
180
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
181
|
-
}
|
177
|
+
const { branch, envBranch } = getEnvironment();
|
178
|
+
return branch ?? envBranch;
|
182
179
|
} catch (err) {
|
180
|
+
return void 0;
|
183
181
|
}
|
184
182
|
}
|
185
183
|
|
@@ -299,7 +297,180 @@ function generateUUID() {
|
|
299
297
|
});
|
300
298
|
}
|
301
299
|
|
302
|
-
|
300
|
+
async function getBytes(stream, onChunk) {
|
301
|
+
const reader = stream.getReader();
|
302
|
+
let result;
|
303
|
+
while (!(result = await reader.read()).done) {
|
304
|
+
onChunk(result.value);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
function getLines(onLine) {
|
308
|
+
let buffer;
|
309
|
+
let position;
|
310
|
+
let fieldLength;
|
311
|
+
let discardTrailingNewline = false;
|
312
|
+
return function onChunk(arr) {
|
313
|
+
if (buffer === void 0) {
|
314
|
+
buffer = arr;
|
315
|
+
position = 0;
|
316
|
+
fieldLength = -1;
|
317
|
+
} else {
|
318
|
+
buffer = concat(buffer, arr);
|
319
|
+
}
|
320
|
+
const bufLength = buffer.length;
|
321
|
+
let lineStart = 0;
|
322
|
+
while (position < bufLength) {
|
323
|
+
if (discardTrailingNewline) {
|
324
|
+
if (buffer[position] === 10 /* NewLine */) {
|
325
|
+
lineStart = ++position;
|
326
|
+
}
|
327
|
+
discardTrailingNewline = false;
|
328
|
+
}
|
329
|
+
let lineEnd = -1;
|
330
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
331
|
+
switch (buffer[position]) {
|
332
|
+
case 58 /* Colon */:
|
333
|
+
if (fieldLength === -1) {
|
334
|
+
fieldLength = position - lineStart;
|
335
|
+
}
|
336
|
+
break;
|
337
|
+
case 13 /* CarriageReturn */:
|
338
|
+
discardTrailingNewline = true;
|
339
|
+
case 10 /* NewLine */:
|
340
|
+
lineEnd = position;
|
341
|
+
break;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
if (lineEnd === -1) {
|
345
|
+
break;
|
346
|
+
}
|
347
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
348
|
+
lineStart = position;
|
349
|
+
fieldLength = -1;
|
350
|
+
}
|
351
|
+
if (lineStart === bufLength) {
|
352
|
+
buffer = void 0;
|
353
|
+
} else if (lineStart !== 0) {
|
354
|
+
buffer = buffer.subarray(lineStart);
|
355
|
+
position -= lineStart;
|
356
|
+
}
|
357
|
+
};
|
358
|
+
}
|
359
|
+
function getMessages(onId, onRetry, onMessage) {
|
360
|
+
let message = newMessage();
|
361
|
+
const decoder = new TextDecoder();
|
362
|
+
return function onLine(line, fieldLength) {
|
363
|
+
if (line.length === 0) {
|
364
|
+
onMessage?.(message);
|
365
|
+
message = newMessage();
|
366
|
+
} else if (fieldLength > 0) {
|
367
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
368
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
369
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
370
|
+
switch (field) {
|
371
|
+
case "data":
|
372
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
373
|
+
break;
|
374
|
+
case "event":
|
375
|
+
message.event = value;
|
376
|
+
break;
|
377
|
+
case "id":
|
378
|
+
onId(message.id = value);
|
379
|
+
break;
|
380
|
+
case "retry":
|
381
|
+
const retry = parseInt(value, 10);
|
382
|
+
if (!isNaN(retry)) {
|
383
|
+
onRetry(message.retry = retry);
|
384
|
+
}
|
385
|
+
break;
|
386
|
+
}
|
387
|
+
}
|
388
|
+
};
|
389
|
+
}
|
390
|
+
function concat(a, b) {
|
391
|
+
const res = new Uint8Array(a.length + b.length);
|
392
|
+
res.set(a);
|
393
|
+
res.set(b, a.length);
|
394
|
+
return res;
|
395
|
+
}
|
396
|
+
function newMessage() {
|
397
|
+
return {
|
398
|
+
data: "",
|
399
|
+
event: "",
|
400
|
+
id: "",
|
401
|
+
retry: void 0
|
402
|
+
};
|
403
|
+
}
|
404
|
+
const EventStreamContentType = "text/event-stream";
|
405
|
+
const LastEventId = "last-event-id";
|
406
|
+
function fetchEventSource(input, {
|
407
|
+
signal: inputSignal,
|
408
|
+
headers: inputHeaders,
|
409
|
+
onopen: inputOnOpen,
|
410
|
+
onmessage,
|
411
|
+
onclose,
|
412
|
+
onerror,
|
413
|
+
fetch: inputFetch,
|
414
|
+
...rest
|
415
|
+
}) {
|
416
|
+
return new Promise((resolve, reject) => {
|
417
|
+
const headers = { ...inputHeaders };
|
418
|
+
if (!headers.accept) {
|
419
|
+
headers.accept = EventStreamContentType;
|
420
|
+
}
|
421
|
+
let curRequestController;
|
422
|
+
function dispose() {
|
423
|
+
curRequestController.abort();
|
424
|
+
}
|
425
|
+
inputSignal?.addEventListener("abort", () => {
|
426
|
+
dispose();
|
427
|
+
resolve();
|
428
|
+
});
|
429
|
+
const fetchImpl = inputFetch ?? fetch;
|
430
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
431
|
+
async function create() {
|
432
|
+
curRequestController = new AbortController();
|
433
|
+
try {
|
434
|
+
const response = await fetchImpl(input, {
|
435
|
+
...rest,
|
436
|
+
headers,
|
437
|
+
signal: curRequestController.signal
|
438
|
+
});
|
439
|
+
await onopen(response);
|
440
|
+
await getBytes(
|
441
|
+
response.body,
|
442
|
+
getLines(
|
443
|
+
getMessages(
|
444
|
+
(id) => {
|
445
|
+
if (id) {
|
446
|
+
headers[LastEventId] = id;
|
447
|
+
} else {
|
448
|
+
delete headers[LastEventId];
|
449
|
+
}
|
450
|
+
},
|
451
|
+
(_retry) => {
|
452
|
+
},
|
453
|
+
onmessage
|
454
|
+
)
|
455
|
+
)
|
456
|
+
);
|
457
|
+
onclose?.();
|
458
|
+
dispose();
|
459
|
+
resolve();
|
460
|
+
} catch (err) {
|
461
|
+
}
|
462
|
+
}
|
463
|
+
create();
|
464
|
+
});
|
465
|
+
}
|
466
|
+
function defaultOnOpen(response) {
|
467
|
+
const contentType = response.headers?.get("content-type");
|
468
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
469
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
const VERSION = "0.22.4";
|
303
474
|
|
304
475
|
class ErrorWithCause extends Error {
|
305
476
|
constructor(message, options) {
|
@@ -383,7 +554,7 @@ async function fetch$1({
|
|
383
554
|
headers: customHeaders,
|
384
555
|
pathParams,
|
385
556
|
queryParams,
|
386
|
-
|
557
|
+
fetch: fetch2,
|
387
558
|
apiKey,
|
388
559
|
endpoint,
|
389
560
|
apiUrl,
|
@@ -396,7 +567,7 @@ async function fetch$1({
|
|
396
567
|
xataAgentExtra,
|
397
568
|
fetchOptions = {}
|
398
569
|
}) {
|
399
|
-
pool.setFetch(
|
570
|
+
pool.setFetch(fetch2);
|
400
571
|
return await trace(
|
401
572
|
`${method.toUpperCase()} ${path}`,
|
402
573
|
async ({ setAttributes }) => {
|
@@ -458,6 +629,59 @@ async function fetch$1({
|
|
458
629
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
459
630
|
);
|
460
631
|
}
|
632
|
+
function fetchSSERequest({
|
633
|
+
url: path,
|
634
|
+
method,
|
635
|
+
body,
|
636
|
+
headers: customHeaders,
|
637
|
+
pathParams,
|
638
|
+
queryParams,
|
639
|
+
fetch: fetch2,
|
640
|
+
apiKey,
|
641
|
+
endpoint,
|
642
|
+
apiUrl,
|
643
|
+
workspacesApiUrl,
|
644
|
+
onMessage,
|
645
|
+
onError,
|
646
|
+
onClose,
|
647
|
+
signal,
|
648
|
+
clientID,
|
649
|
+
sessionID,
|
650
|
+
clientName,
|
651
|
+
xataAgentExtra
|
652
|
+
}) {
|
653
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
654
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
655
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
656
|
+
void fetchEventSource(url, {
|
657
|
+
method,
|
658
|
+
body: JSON.stringify(body),
|
659
|
+
fetch: fetch2,
|
660
|
+
signal,
|
661
|
+
headers: {
|
662
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
663
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
664
|
+
"X-Xata-Agent": compact([
|
665
|
+
["client", "TS_SDK"],
|
666
|
+
["version", VERSION],
|
667
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
668
|
+
...Object.entries(xataAgentExtra ?? {})
|
669
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
670
|
+
...customHeaders,
|
671
|
+
Authorization: `Bearer ${apiKey}`,
|
672
|
+
"Content-Type": "application/json"
|
673
|
+
},
|
674
|
+
onmessage(ev) {
|
675
|
+
onMessage?.(JSON.parse(ev.data));
|
676
|
+
},
|
677
|
+
onerror(ev) {
|
678
|
+
onError?.(JSON.parse(ev.data));
|
679
|
+
},
|
680
|
+
onclose() {
|
681
|
+
onClose?.();
|
682
|
+
}
|
683
|
+
});
|
684
|
+
}
|
461
685
|
function parseUrl(url) {
|
462
686
|
try {
|
463
687
|
const { host, protocol } = new URL(url);
|
@@ -488,6 +712,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
488
712
|
...variables,
|
489
713
|
signal
|
490
714
|
});
|
715
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
716
|
+
url: "/db/{dbBranchName}/copy",
|
717
|
+
method: "post",
|
718
|
+
...variables,
|
719
|
+
signal
|
720
|
+
});
|
491
721
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
492
722
|
url: "/db/{dbBranchName}/metadata",
|
493
723
|
method: "put",
|
@@ -611,6 +841,12 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
611
841
|
signal
|
612
842
|
});
|
613
843
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
844
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
845
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
846
|
+
method: "post",
|
847
|
+
...variables,
|
848
|
+
signal
|
849
|
+
});
|
614
850
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
615
851
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
616
852
|
const operationsByTag$2 = {
|
@@ -619,6 +855,7 @@ const operationsByTag$2 = {
|
|
619
855
|
getBranchDetails,
|
620
856
|
createBranch,
|
621
857
|
deleteBranch,
|
858
|
+
copyBranch,
|
622
859
|
updateBranchMetadata,
|
623
860
|
getBranchMetadata,
|
624
861
|
getBranchStats,
|
@@ -670,7 +907,15 @@ const operationsByTag$2 = {
|
|
670
907
|
deleteRecord,
|
671
908
|
bulkInsertTableRecords
|
672
909
|
},
|
673
|
-
searchAndFilter: {
|
910
|
+
searchAndFilter: {
|
911
|
+
queryTable,
|
912
|
+
searchBranch,
|
913
|
+
searchTable,
|
914
|
+
vectorSearchTable,
|
915
|
+
askTable,
|
916
|
+
summarizeTable,
|
917
|
+
aggregateTable
|
918
|
+
}
|
674
919
|
};
|
675
920
|
|
676
921
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -892,7 +1137,7 @@ class XataApiClient {
|
|
892
1137
|
__privateSet$7(this, _extraProps, {
|
893
1138
|
apiUrl: getHostUrl(provider, "main"),
|
894
1139
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
895
|
-
|
1140
|
+
fetch: getFetchImplementation(options.fetch),
|
896
1141
|
apiKey,
|
897
1142
|
trace,
|
898
1143
|
clientName: options.clientName,
|
@@ -1158,6 +1403,20 @@ class BranchApi {
|
|
1158
1403
|
...this.extraProps
|
1159
1404
|
});
|
1160
1405
|
}
|
1406
|
+
copyBranch({
|
1407
|
+
workspace,
|
1408
|
+
region,
|
1409
|
+
database,
|
1410
|
+
branch,
|
1411
|
+
destinationBranch,
|
1412
|
+
limit
|
1413
|
+
}) {
|
1414
|
+
return operationsByTag.branch.copyBranch({
|
1415
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1416
|
+
body: { destinationBranch, limit },
|
1417
|
+
...this.extraProps
|
1418
|
+
});
|
1419
|
+
}
|
1161
1420
|
updateBranchMetadata({
|
1162
1421
|
workspace,
|
1163
1422
|
region,
|
@@ -1572,6 +1831,38 @@ class SearchAndFilterApi {
|
|
1572
1831
|
...this.extraProps
|
1573
1832
|
});
|
1574
1833
|
}
|
1834
|
+
vectorSearchTable({
|
1835
|
+
workspace,
|
1836
|
+
region,
|
1837
|
+
database,
|
1838
|
+
branch,
|
1839
|
+
table,
|
1840
|
+
queryVector,
|
1841
|
+
column,
|
1842
|
+
similarityFunction,
|
1843
|
+
size,
|
1844
|
+
filter
|
1845
|
+
}) {
|
1846
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
1847
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1848
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
1849
|
+
...this.extraProps
|
1850
|
+
});
|
1851
|
+
}
|
1852
|
+
askTable({
|
1853
|
+
workspace,
|
1854
|
+
region,
|
1855
|
+
database,
|
1856
|
+
branch,
|
1857
|
+
table,
|
1858
|
+
options
|
1859
|
+
}) {
|
1860
|
+
return operationsByTag.searchAndFilter.askTable({
|
1861
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1862
|
+
body: { ...options },
|
1863
|
+
...this.extraProps
|
1864
|
+
});
|
1865
|
+
}
|
1575
1866
|
summarizeTable({
|
1576
1867
|
workspace,
|
1577
1868
|
region,
|
@@ -1925,9 +2216,8 @@ class DatabaseApi {
|
|
1925
2216
|
}
|
1926
2217
|
|
1927
2218
|
class XataApiPlugin {
|
1928
|
-
|
1929
|
-
|
1930
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2219
|
+
build(options) {
|
2220
|
+
return new XataApiClient(options);
|
1931
2221
|
}
|
1932
2222
|
}
|
1933
2223
|
|
@@ -2341,10 +2631,7 @@ class RestRepository extends Query {
|
|
2341
2631
|
__privateSet$4(this, _db, options.db);
|
2342
2632
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2343
2633
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2344
|
-
__privateSet$4(this, _getFetchProps,
|
2345
|
-
const props = await options.pluginOptions.getFetchProps();
|
2346
|
-
return { ...props, sessionID: generateUUID() };
|
2347
|
-
});
|
2634
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2348
2635
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2349
2636
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2350
2637
|
return trace(name, fn, {
|
@@ -2401,7 +2688,6 @@ class RestRepository extends Query {
|
|
2401
2688
|
}
|
2402
2689
|
const id = extractId(a);
|
2403
2690
|
if (id) {
|
2404
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2405
2691
|
try {
|
2406
2692
|
const response = await getRecord({
|
2407
2693
|
pathParams: {
|
@@ -2412,7 +2698,7 @@ class RestRepository extends Query {
|
|
2412
2698
|
recordId: id
|
2413
2699
|
},
|
2414
2700
|
queryParams: { columns },
|
2415
|
-
...
|
2701
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2416
2702
|
});
|
2417
2703
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2418
2704
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2590,7 +2876,6 @@ class RestRepository extends Query {
|
|
2590
2876
|
}
|
2591
2877
|
async search(query, options = {}) {
|
2592
2878
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2593
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2594
2879
|
const { records } = await searchTable({
|
2595
2880
|
pathParams: {
|
2596
2881
|
workspace: "{workspaceId}",
|
@@ -2608,7 +2893,7 @@ class RestRepository extends Query {
|
|
2608
2893
|
page: options.page,
|
2609
2894
|
target: options.target
|
2610
2895
|
},
|
2611
|
-
...
|
2896
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2612
2897
|
});
|
2613
2898
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2614
2899
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2616,7 +2901,6 @@ class RestRepository extends Query {
|
|
2616
2901
|
}
|
2617
2902
|
async vectorSearch(column, query, options) {
|
2618
2903
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
2619
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2620
2904
|
const { records } = await vectorSearchTable({
|
2621
2905
|
pathParams: {
|
2622
2906
|
workspace: "{workspaceId}",
|
@@ -2631,7 +2915,7 @@ class RestRepository extends Query {
|
|
2631
2915
|
size: options?.size,
|
2632
2916
|
filter: options?.filter
|
2633
2917
|
},
|
2634
|
-
...
|
2918
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2635
2919
|
});
|
2636
2920
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2637
2921
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2639,7 +2923,6 @@ class RestRepository extends Query {
|
|
2639
2923
|
}
|
2640
2924
|
async aggregate(aggs, filter) {
|
2641
2925
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2642
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2643
2926
|
const result = await aggregateTable({
|
2644
2927
|
pathParams: {
|
2645
2928
|
workspace: "{workspaceId}",
|
@@ -2648,7 +2931,7 @@ class RestRepository extends Query {
|
|
2648
2931
|
tableName: __privateGet$4(this, _table)
|
2649
2932
|
},
|
2650
2933
|
body: { aggs, filter },
|
2651
|
-
...
|
2934
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2652
2935
|
});
|
2653
2936
|
return result;
|
2654
2937
|
});
|
@@ -2659,7 +2942,6 @@ class RestRepository extends Query {
|
|
2659
2942
|
if (cacheQuery)
|
2660
2943
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2661
2944
|
const data = query.getQueryOptions();
|
2662
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2663
2945
|
const { meta, records: objects } = await queryTable({
|
2664
2946
|
pathParams: {
|
2665
2947
|
workspace: "{workspaceId}",
|
@@ -2675,7 +2957,7 @@ class RestRepository extends Query {
|
|
2675
2957
|
consistency: data.consistency
|
2676
2958
|
},
|
2677
2959
|
fetchOptions: data.fetchOptions,
|
2678
|
-
...
|
2960
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2679
2961
|
});
|
2680
2962
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2681
2963
|
const records = objects.map(
|
@@ -2688,7 +2970,6 @@ class RestRepository extends Query {
|
|
2688
2970
|
async summarizeTable(query, summaries, summariesFilter) {
|
2689
2971
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2690
2972
|
const data = query.getQueryOptions();
|
2691
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2692
2973
|
const result = await summarizeTable({
|
2693
2974
|
pathParams: {
|
2694
2975
|
workspace: "{workspaceId}",
|
@@ -2705,11 +2986,39 @@ class RestRepository extends Query {
|
|
2705
2986
|
summaries,
|
2706
2987
|
summariesFilter
|
2707
2988
|
},
|
2708
|
-
...
|
2989
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2709
2990
|
});
|
2710
2991
|
return result;
|
2711
2992
|
});
|
2712
2993
|
}
|
2994
|
+
ask(question, options) {
|
2995
|
+
const params = {
|
2996
|
+
pathParams: {
|
2997
|
+
workspace: "{workspaceId}",
|
2998
|
+
dbBranchName: "{dbBranch}",
|
2999
|
+
region: "{region}",
|
3000
|
+
tableName: __privateGet$4(this, _table)
|
3001
|
+
},
|
3002
|
+
body: {
|
3003
|
+
question,
|
3004
|
+
...options
|
3005
|
+
},
|
3006
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3007
|
+
};
|
3008
|
+
if (options?.onMessage) {
|
3009
|
+
fetchSSERequest({
|
3010
|
+
endpoint: "dataPlane",
|
3011
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3012
|
+
method: "POST",
|
3013
|
+
onMessage: (message) => {
|
3014
|
+
options.onMessage?.({ answer: message.text });
|
3015
|
+
},
|
3016
|
+
...params
|
3017
|
+
});
|
3018
|
+
} else {
|
3019
|
+
return askTable(params);
|
3020
|
+
}
|
3021
|
+
}
|
2713
3022
|
}
|
2714
3023
|
_table = new WeakMap();
|
2715
3024
|
_getFetchProps = new WeakMap();
|
@@ -2719,7 +3028,6 @@ _schemaTables$2 = new WeakMap();
|
|
2719
3028
|
_trace = new WeakMap();
|
2720
3029
|
_insertRecordWithoutId = new WeakSet();
|
2721
3030
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2722
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2723
3031
|
const record = transformObjectLinks(object);
|
2724
3032
|
const response = await insertRecord({
|
2725
3033
|
pathParams: {
|
@@ -2730,14 +3038,13 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2730
3038
|
},
|
2731
3039
|
queryParams: { columns },
|
2732
3040
|
body: record,
|
2733
|
-
...
|
3041
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2734
3042
|
});
|
2735
3043
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2736
3044
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2737
3045
|
};
|
2738
3046
|
_insertRecordWithId = new WeakSet();
|
2739
3047
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2740
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2741
3048
|
const record = transformObjectLinks(object);
|
2742
3049
|
const response = await insertRecordWithID({
|
2743
3050
|
pathParams: {
|
@@ -2749,14 +3056,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2749
3056
|
},
|
2750
3057
|
body: record,
|
2751
3058
|
queryParams: { createOnly, columns, ifVersion },
|
2752
|
-
...
|
3059
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2753
3060
|
});
|
2754
3061
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2755
3062
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2756
3063
|
};
|
2757
3064
|
_insertRecords = new WeakSet();
|
2758
3065
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2759
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2760
3066
|
const chunkedOperations = chunk(
|
2761
3067
|
objects.map((object) => ({
|
2762
3068
|
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
@@ -2772,7 +3078,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2772
3078
|
region: "{region}"
|
2773
3079
|
},
|
2774
3080
|
body: { operations },
|
2775
|
-
...
|
3081
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2776
3082
|
});
|
2777
3083
|
for (const result of results) {
|
2778
3084
|
if (result.operation === "insert") {
|
@@ -2786,7 +3092,6 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2786
3092
|
};
|
2787
3093
|
_updateRecordWithID = new WeakSet();
|
2788
3094
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2789
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2790
3095
|
const { id: _id, ...record } = transformObjectLinks(object);
|
2791
3096
|
try {
|
2792
3097
|
const response = await updateRecordWithID({
|
@@ -2799,7 +3104,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2799
3104
|
},
|
2800
3105
|
queryParams: { columns, ifVersion },
|
2801
3106
|
body: record,
|
2802
|
-
...
|
3107
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2803
3108
|
});
|
2804
3109
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2805
3110
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2812,7 +3117,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2812
3117
|
};
|
2813
3118
|
_updateRecords = new WeakSet();
|
2814
3119
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2815
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2816
3120
|
const chunkedOperations = chunk(
|
2817
3121
|
objects.map(({ id, ...object }) => ({
|
2818
3122
|
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
@@ -2828,7 +3132,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2828
3132
|
region: "{region}"
|
2829
3133
|
},
|
2830
3134
|
body: { operations },
|
2831
|
-
...
|
3135
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2832
3136
|
});
|
2833
3137
|
for (const result of results) {
|
2834
3138
|
if (result.operation === "update") {
|
@@ -2842,7 +3146,6 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2842
3146
|
};
|
2843
3147
|
_upsertRecordWithID = new WeakSet();
|
2844
3148
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2845
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2846
3149
|
const response = await upsertRecordWithID({
|
2847
3150
|
pathParams: {
|
2848
3151
|
workspace: "{workspaceId}",
|
@@ -2853,14 +3156,13 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2853
3156
|
},
|
2854
3157
|
queryParams: { columns, ifVersion },
|
2855
3158
|
body: object,
|
2856
|
-
...
|
3159
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2857
3160
|
});
|
2858
3161
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2859
3162
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2860
3163
|
};
|
2861
3164
|
_deleteRecord = new WeakSet();
|
2862
3165
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2863
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2864
3166
|
try {
|
2865
3167
|
const response = await deleteRecord({
|
2866
3168
|
pathParams: {
|
@@ -2871,7 +3173,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2871
3173
|
recordId
|
2872
3174
|
},
|
2873
3175
|
queryParams: { columns },
|
2874
|
-
...
|
3176
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2875
3177
|
});
|
2876
3178
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2877
3179
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2884,7 +3186,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2884
3186
|
};
|
2885
3187
|
_deleteRecords = new WeakSet();
|
2886
3188
|
deleteRecords_fn = async function(recordIds) {
|
2887
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2888
3189
|
const chunkedOperations = chunk(
|
2889
3190
|
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2890
3191
|
BULK_OPERATION_MAX_SIZE
|
@@ -2897,7 +3198,7 @@ deleteRecords_fn = async function(recordIds) {
|
|
2897
3198
|
region: "{region}"
|
2898
3199
|
},
|
2899
3200
|
body: { operations },
|
2900
|
-
...
|
3201
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2901
3202
|
});
|
2902
3203
|
}
|
2903
3204
|
};
|
@@ -2921,10 +3222,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
2921
3222
|
getSchemaTables_fn$1 = async function() {
|
2922
3223
|
if (__privateGet$4(this, _schemaTables$2))
|
2923
3224
|
return __privateGet$4(this, _schemaTables$2);
|
2924
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2925
3225
|
const { schema } = await getBranchDetails({
|
2926
3226
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2927
|
-
...
|
3227
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2928
3228
|
});
|
2929
3229
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2930
3230
|
return schema.tables;
|
@@ -3200,19 +3500,19 @@ class SearchPlugin extends XataPlugin {
|
|
3200
3500
|
__privateAdd$1(this, _schemaTables, void 0);
|
3201
3501
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3202
3502
|
}
|
3203
|
-
build(
|
3503
|
+
build(pluginOptions) {
|
3204
3504
|
return {
|
3205
3505
|
all: async (query, options = {}) => {
|
3206
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3207
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3506
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3507
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3208
3508
|
return records.map((record) => {
|
3209
3509
|
const { table = "orphan" } = record.xata;
|
3210
3510
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3211
3511
|
});
|
3212
3512
|
},
|
3213
3513
|
byTable: async (query, options = {}) => {
|
3214
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3215
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3514
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3515
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3216
3516
|
return records.reduce((acc, record) => {
|
3217
3517
|
const { table = "orphan" } = record.xata;
|
3218
3518
|
const items = acc[table] ?? [];
|
@@ -3225,38 +3525,35 @@ class SearchPlugin extends XataPlugin {
|
|
3225
3525
|
}
|
3226
3526
|
_schemaTables = new WeakMap();
|
3227
3527
|
_search = new WeakSet();
|
3228
|
-
search_fn = async function(query, options,
|
3229
|
-
const fetchProps = await getFetchProps();
|
3528
|
+
search_fn = async function(query, options, pluginOptions) {
|
3230
3529
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3231
3530
|
const { records } = await searchBranch({
|
3232
3531
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3233
3532
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3234
|
-
...
|
3533
|
+
...pluginOptions
|
3235
3534
|
});
|
3236
3535
|
return records;
|
3237
3536
|
};
|
3238
3537
|
_getSchemaTables = new WeakSet();
|
3239
|
-
getSchemaTables_fn = async function(
|
3538
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3240
3539
|
if (__privateGet$1(this, _schemaTables))
|
3241
3540
|
return __privateGet$1(this, _schemaTables);
|
3242
|
-
const fetchProps = await getFetchProps();
|
3243
3541
|
const { schema } = await getBranchDetails({
|
3244
3542
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3245
|
-
...
|
3543
|
+
...pluginOptions
|
3246
3544
|
});
|
3247
3545
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3248
3546
|
return schema.tables;
|
3249
3547
|
};
|
3250
3548
|
|
3251
3549
|
class TransactionPlugin extends XataPlugin {
|
3252
|
-
build(
|
3550
|
+
build(pluginOptions) {
|
3253
3551
|
return {
|
3254
3552
|
run: async (operations) => {
|
3255
|
-
const fetchProps = await getFetchProps();
|
3256
3553
|
const response = await branchTransaction({
|
3257
3554
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3258
3555
|
body: { operations },
|
3259
|
-
...
|
3556
|
+
...pluginOptions
|
3260
3557
|
});
|
3261
3558
|
return response;
|
3262
3559
|
}
|
@@ -3264,91 +3561,6 @@ class TransactionPlugin extends XataPlugin {
|
|
3264
3561
|
}
|
3265
3562
|
}
|
3266
3563
|
|
3267
|
-
const isBranchStrategyBuilder = (strategy) => {
|
3268
|
-
return typeof strategy === "function";
|
3269
|
-
};
|
3270
|
-
|
3271
|
-
async function getCurrentBranchName(options) {
|
3272
|
-
const { branch, envBranch } = getEnvironment();
|
3273
|
-
if (branch)
|
3274
|
-
return branch;
|
3275
|
-
const gitBranch = envBranch || await getGitBranch();
|
3276
|
-
return resolveXataBranch(gitBranch, options);
|
3277
|
-
}
|
3278
|
-
async function getCurrentBranchDetails(options) {
|
3279
|
-
const branch = await getCurrentBranchName(options);
|
3280
|
-
return getDatabaseBranch(branch, options);
|
3281
|
-
}
|
3282
|
-
async function resolveXataBranch(gitBranch, options) {
|
3283
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3284
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3285
|
-
if (!databaseURL)
|
3286
|
-
throw new Error(
|
3287
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3288
|
-
);
|
3289
|
-
if (!apiKey)
|
3290
|
-
throw new Error(
|
3291
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3292
|
-
);
|
3293
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3294
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3295
|
-
if (!urlParts)
|
3296
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3297
|
-
const { workspace, region } = urlParts;
|
3298
|
-
const { fallbackBranch } = getEnvironment();
|
3299
|
-
const { branch } = await resolveBranch({
|
3300
|
-
apiKey,
|
3301
|
-
apiUrl: databaseURL,
|
3302
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3303
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3304
|
-
pathParams: { dbName, workspace, region },
|
3305
|
-
queryParams: { gitBranch, fallbackBranch },
|
3306
|
-
trace: defaultTrace,
|
3307
|
-
clientName: options?.clientName,
|
3308
|
-
xataAgentExtra: options?.xataAgentExtra
|
3309
|
-
});
|
3310
|
-
return branch;
|
3311
|
-
}
|
3312
|
-
async function getDatabaseBranch(branch, options) {
|
3313
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3314
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3315
|
-
if (!databaseURL)
|
3316
|
-
throw new Error(
|
3317
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3318
|
-
);
|
3319
|
-
if (!apiKey)
|
3320
|
-
throw new Error(
|
3321
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3322
|
-
);
|
3323
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3324
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3325
|
-
if (!urlParts)
|
3326
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3327
|
-
const { workspace, region } = urlParts;
|
3328
|
-
try {
|
3329
|
-
return await getBranchDetails({
|
3330
|
-
apiKey,
|
3331
|
-
apiUrl: databaseURL,
|
3332
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3333
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3334
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3335
|
-
trace: defaultTrace
|
3336
|
-
});
|
3337
|
-
} catch (err) {
|
3338
|
-
if (isObject(err) && err.status === 404)
|
3339
|
-
return null;
|
3340
|
-
throw err;
|
3341
|
-
}
|
3342
|
-
}
|
3343
|
-
function getDatabaseURL() {
|
3344
|
-
try {
|
3345
|
-
const { databaseURL } = getEnvironment();
|
3346
|
-
return databaseURL;
|
3347
|
-
} catch (err) {
|
3348
|
-
return void 0;
|
3349
|
-
}
|
3350
|
-
}
|
3351
|
-
|
3352
3564
|
var __accessCheck = (obj, member, msg) => {
|
3353
3565
|
if (!member.has(obj))
|
3354
3566
|
throw TypeError("Cannot " + msg);
|
@@ -3372,20 +3584,17 @@ var __privateMethod = (obj, member, method) => {
|
|
3372
3584
|
return method;
|
3373
3585
|
};
|
3374
3586
|
const buildClient = (plugins) => {
|
3375
|
-
var
|
3587
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3376
3588
|
return _a = class {
|
3377
3589
|
constructor(options = {}, schemaTables) {
|
3378
3590
|
__privateAdd(this, _parseOptions);
|
3379
3591
|
__privateAdd(this, _getFetchProps);
|
3380
|
-
__privateAdd(this, _evaluateBranch);
|
3381
|
-
__privateAdd(this, _branch, void 0);
|
3382
3592
|
__privateAdd(this, _options, void 0);
|
3383
3593
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3384
3594
|
__privateSet(this, _options, safeOptions);
|
3385
3595
|
const pluginOptions = {
|
3386
|
-
|
3387
|
-
cache: safeOptions.cache
|
3388
|
-
trace: safeOptions.trace
|
3596
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3597
|
+
cache: safeOptions.cache
|
3389
3598
|
};
|
3390
3599
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3391
3600
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -3408,10 +3617,10 @@ const buildClient = (plugins) => {
|
|
3408
3617
|
}
|
3409
3618
|
async getConfig() {
|
3410
3619
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3411
|
-
const branch =
|
3620
|
+
const branch = __privateGet(this, _options).branch;
|
3412
3621
|
return { databaseURL, branch };
|
3413
3622
|
}
|
3414
|
-
},
|
3623
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3415
3624
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3416
3625
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3417
3626
|
if (isBrowser && !enableBrowser) {
|
@@ -3421,18 +3630,13 @@ const buildClient = (plugins) => {
|
|
3421
3630
|
}
|
3422
3631
|
const fetch = getFetchImplementation(options?.fetch);
|
3423
3632
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3633
|
+
const branch = options?.branch || getBranch() || "main";
|
3424
3634
|
const apiKey = options?.apiKey || getAPIKey();
|
3425
3635
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3426
3636
|
const trace = options?.trace ?? defaultTrace;
|
3427
3637
|
const clientName = options?.clientName;
|
3638
|
+
const host = options?.host ?? "production";
|
3428
3639
|
const xataAgentExtra = options?.xataAgentExtra;
|
3429
|
-
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3430
|
-
apiKey,
|
3431
|
-
databaseURL,
|
3432
|
-
fetchImpl: options?.fetch,
|
3433
|
-
clientName,
|
3434
|
-
xataAgentExtra
|
3435
|
-
});
|
3436
3640
|
if (!apiKey) {
|
3437
3641
|
throw new Error("Option apiKey is required");
|
3438
3642
|
}
|
@@ -3446,12 +3650,13 @@ const buildClient = (plugins) => {
|
|
3446
3650
|
branch,
|
3447
3651
|
cache,
|
3448
3652
|
trace,
|
3653
|
+
host,
|
3449
3654
|
clientID: generateUUID(),
|
3450
3655
|
enableBrowser,
|
3451
3656
|
clientName,
|
3452
3657
|
xataAgentExtra
|
3453
3658
|
};
|
3454
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn =
|
3659
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3455
3660
|
fetch,
|
3456
3661
|
apiKey,
|
3457
3662
|
databaseURL,
|
@@ -3461,16 +3666,13 @@ const buildClient = (plugins) => {
|
|
3461
3666
|
clientName,
|
3462
3667
|
xataAgentExtra
|
3463
3668
|
}) {
|
3464
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3465
|
-
if (!branchValue)
|
3466
|
-
throw new Error("Unable to resolve branch value");
|
3467
3669
|
return {
|
3468
|
-
|
3670
|
+
fetch,
|
3469
3671
|
apiKey,
|
3470
3672
|
apiUrl: "",
|
3471
3673
|
workspacesApiUrl: (path, params) => {
|
3472
3674
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3473
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
3675
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3474
3676
|
return databaseURL + newPath;
|
3475
3677
|
},
|
3476
3678
|
trace,
|
@@ -3478,22 +3680,6 @@ const buildClient = (plugins) => {
|
|
3478
3680
|
clientName,
|
3479
3681
|
xataAgentExtra
|
3480
3682
|
};
|
3481
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3482
|
-
if (__privateGet(this, _branch))
|
3483
|
-
return __privateGet(this, _branch);
|
3484
|
-
if (param === void 0)
|
3485
|
-
return void 0;
|
3486
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3487
|
-
const evaluateBranch = async (strategy) => {
|
3488
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3489
|
-
};
|
3490
|
-
for await (const strategy of strategies) {
|
3491
|
-
const branch = await evaluateBranch(strategy);
|
3492
|
-
if (branch) {
|
3493
|
-
__privateSet(this, _branch, branch);
|
3494
|
-
return branch;
|
3495
|
-
}
|
3496
|
-
}
|
3497
3683
|
}, _a;
|
3498
3684
|
};
|
3499
3685
|
class BaseClient extends buildClient() {
|
@@ -3588,5 +3774,5 @@ class XataError extends Error {
|
|
3588
3774
|
}
|
3589
3775
|
}
|
3590
3776
|
|
3591
|
-
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, deleteDatabaseGithubSettings, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn,
|
3777
|
+
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, 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, 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, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3592
3778
|
//# sourceMappingURL=index.mjs.map
|