@xata.io/client 0.0.0-alpha.vebc4a36 → 0.0.0-alpha.vec0147b

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/dist/index.cjs CHANGED
@@ -93,8 +93,10 @@ 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
+ deployPreview: process.env.XATA_PREVIEW,
97
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
98
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
99
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
98
100
  };
99
101
  }
100
102
  } catch (err) {
@@ -105,8 +107,10 @@ function getEnvironment() {
105
107
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
106
108
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
107
109
  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()
110
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
111
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
112
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
113
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
110
114
  };
111
115
  }
112
116
  } catch (err) {
@@ -115,8 +119,10 @@ function getEnvironment() {
115
119
  apiKey: getGlobalApiKey(),
116
120
  databaseURL: getGlobalDatabaseURL(),
117
121
  branch: getGlobalBranch(),
118
- envBranch: void 0,
119
- fallbackBranch: getGlobalFallbackBranch()
122
+ deployPreview: void 0,
123
+ deployPreviewBranch: void 0,
124
+ vercelGitCommitRef: void 0,
125
+ vercelGitRepoOwner: void 0
120
126
  };
121
127
  }
122
128
  function getEnableBrowserVariable() {
@@ -159,37 +165,48 @@ function getGlobalBranch() {
159
165
  return void 0;
160
166
  }
161
167
  }
162
- function getGlobalFallbackBranch() {
168
+ function getDatabaseURL() {
163
169
  try {
164
- return XATA_FALLBACK_BRANCH;
170
+ const { databaseURL } = getEnvironment();
171
+ return databaseURL;
165
172
  } catch (err) {
166
173
  return void 0;
167
174
  }
168
175
  }
169
- async function getGitBranch() {
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"] };
176
+ function getAPIKey() {
174
177
  try {
175
- if (typeof require === "function") {
176
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
177
- }
178
+ const { apiKey } = getEnvironment();
179
+ return apiKey;
178
180
  } catch (err) {
181
+ return void 0;
179
182
  }
183
+ }
184
+ function getBranch() {
180
185
  try {
181
- if (isObject(Deno)) {
182
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
183
- return new TextDecoder().decode(await process2.output()).trim();
184
- }
186
+ const { branch } = getEnvironment();
187
+ return branch ?? "main";
185
188
  } catch (err) {
189
+ return void 0;
186
190
  }
187
191
  }
188
-
189
- function getAPIKey() {
192
+ function buildPreviewBranchName({ org, branch }) {
193
+ return `preview-${org}-${branch}`;
194
+ }
195
+ function getPreviewBranch() {
190
196
  try {
191
- const { apiKey } = getEnvironment();
192
- return apiKey;
197
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
198
+ if (deployPreviewBranch)
199
+ return deployPreviewBranch;
200
+ switch (deployPreview) {
201
+ case "vercel": {
202
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
203
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
204
+ return void 0;
205
+ }
206
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
207
+ }
208
+ }
209
+ return void 0;
193
210
  } catch (err) {
194
211
  return void 0;
195
212
  }
@@ -302,7 +319,180 @@ function generateUUID() {
302
319
  });
303
320
  }
304
321
 
305
- const VERSION = "0.22.1";
322
+ async function getBytes(stream, onChunk) {
323
+ const reader = stream.getReader();
324
+ let result;
325
+ while (!(result = await reader.read()).done) {
326
+ onChunk(result.value);
327
+ }
328
+ }
329
+ function getLines(onLine) {
330
+ let buffer;
331
+ let position;
332
+ let fieldLength;
333
+ let discardTrailingNewline = false;
334
+ return function onChunk(arr) {
335
+ if (buffer === void 0) {
336
+ buffer = arr;
337
+ position = 0;
338
+ fieldLength = -1;
339
+ } else {
340
+ buffer = concat(buffer, arr);
341
+ }
342
+ const bufLength = buffer.length;
343
+ let lineStart = 0;
344
+ while (position < bufLength) {
345
+ if (discardTrailingNewline) {
346
+ if (buffer[position] === 10 /* NewLine */) {
347
+ lineStart = ++position;
348
+ }
349
+ discardTrailingNewline = false;
350
+ }
351
+ let lineEnd = -1;
352
+ for (; position < bufLength && lineEnd === -1; ++position) {
353
+ switch (buffer[position]) {
354
+ case 58 /* Colon */:
355
+ if (fieldLength === -1) {
356
+ fieldLength = position - lineStart;
357
+ }
358
+ break;
359
+ case 13 /* CarriageReturn */:
360
+ discardTrailingNewline = true;
361
+ case 10 /* NewLine */:
362
+ lineEnd = position;
363
+ break;
364
+ }
365
+ }
366
+ if (lineEnd === -1) {
367
+ break;
368
+ }
369
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
370
+ lineStart = position;
371
+ fieldLength = -1;
372
+ }
373
+ if (lineStart === bufLength) {
374
+ buffer = void 0;
375
+ } else if (lineStart !== 0) {
376
+ buffer = buffer.subarray(lineStart);
377
+ position -= lineStart;
378
+ }
379
+ };
380
+ }
381
+ function getMessages(onId, onRetry, onMessage) {
382
+ let message = newMessage();
383
+ const decoder = new TextDecoder();
384
+ return function onLine(line, fieldLength) {
385
+ if (line.length === 0) {
386
+ onMessage?.(message);
387
+ message = newMessage();
388
+ } else if (fieldLength > 0) {
389
+ const field = decoder.decode(line.subarray(0, fieldLength));
390
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
391
+ const value = decoder.decode(line.subarray(valueOffset));
392
+ switch (field) {
393
+ case "data":
394
+ message.data = message.data ? message.data + "\n" + value : value;
395
+ break;
396
+ case "event":
397
+ message.event = value;
398
+ break;
399
+ case "id":
400
+ onId(message.id = value);
401
+ break;
402
+ case "retry":
403
+ const retry = parseInt(value, 10);
404
+ if (!isNaN(retry)) {
405
+ onRetry(message.retry = retry);
406
+ }
407
+ break;
408
+ }
409
+ }
410
+ };
411
+ }
412
+ function concat(a, b) {
413
+ const res = new Uint8Array(a.length + b.length);
414
+ res.set(a);
415
+ res.set(b, a.length);
416
+ return res;
417
+ }
418
+ function newMessage() {
419
+ return {
420
+ data: "",
421
+ event: "",
422
+ id: "",
423
+ retry: void 0
424
+ };
425
+ }
426
+ const EventStreamContentType = "text/event-stream";
427
+ const LastEventId = "last-event-id";
428
+ function fetchEventSource(input, {
429
+ signal: inputSignal,
430
+ headers: inputHeaders,
431
+ onopen: inputOnOpen,
432
+ onmessage,
433
+ onclose,
434
+ onerror,
435
+ fetch: inputFetch,
436
+ ...rest
437
+ }) {
438
+ return new Promise((resolve, reject) => {
439
+ const headers = { ...inputHeaders };
440
+ if (!headers.accept) {
441
+ headers.accept = EventStreamContentType;
442
+ }
443
+ let curRequestController;
444
+ function dispose() {
445
+ curRequestController.abort();
446
+ }
447
+ inputSignal?.addEventListener("abort", () => {
448
+ dispose();
449
+ resolve();
450
+ });
451
+ const fetchImpl = inputFetch ?? fetch;
452
+ const onopen = inputOnOpen ?? defaultOnOpen;
453
+ async function create() {
454
+ curRequestController = new AbortController();
455
+ try {
456
+ const response = await fetchImpl(input, {
457
+ ...rest,
458
+ headers,
459
+ signal: curRequestController.signal
460
+ });
461
+ await onopen(response);
462
+ await getBytes(
463
+ response.body,
464
+ getLines(
465
+ getMessages(
466
+ (id) => {
467
+ if (id) {
468
+ headers[LastEventId] = id;
469
+ } else {
470
+ delete headers[LastEventId];
471
+ }
472
+ },
473
+ (_retry) => {
474
+ },
475
+ onmessage
476
+ )
477
+ )
478
+ );
479
+ onclose?.();
480
+ dispose();
481
+ resolve();
482
+ } catch (err) {
483
+ }
484
+ }
485
+ create();
486
+ });
487
+ }
488
+ function defaultOnOpen(response) {
489
+ const contentType = response.headers?.get("content-type");
490
+ if (!contentType?.startsWith(EventStreamContentType)) {
491
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
492
+ }
493
+ }
494
+
495
+ const VERSION = "0.23.3";
306
496
 
307
497
  class ErrorWithCause extends Error {
308
498
  constructor(message, options) {
@@ -386,7 +576,7 @@ async function fetch$1({
386
576
  headers: customHeaders,
387
577
  pathParams,
388
578
  queryParams,
389
- fetchImpl,
579
+ fetch: fetch2,
390
580
  apiKey,
391
581
  endpoint,
392
582
  apiUrl,
@@ -399,7 +589,7 @@ async function fetch$1({
399
589
  xataAgentExtra,
400
590
  fetchOptions = {}
401
591
  }) {
402
- pool.setFetch(fetchImpl);
592
+ pool.setFetch(fetch2);
403
593
  return await trace(
404
594
  `${method.toUpperCase()} ${path}`,
405
595
  async ({ setAttributes }) => {
@@ -461,6 +651,59 @@ async function fetch$1({
461
651
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
462
652
  );
463
653
  }
654
+ function fetchSSERequest({
655
+ url: path,
656
+ method,
657
+ body,
658
+ headers: customHeaders,
659
+ pathParams,
660
+ queryParams,
661
+ fetch: fetch2,
662
+ apiKey,
663
+ endpoint,
664
+ apiUrl,
665
+ workspacesApiUrl,
666
+ onMessage,
667
+ onError,
668
+ onClose,
669
+ signal,
670
+ clientID,
671
+ sessionID,
672
+ clientName,
673
+ xataAgentExtra
674
+ }) {
675
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
676
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
677
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
678
+ void fetchEventSource(url, {
679
+ method,
680
+ body: JSON.stringify(body),
681
+ fetch: fetch2,
682
+ signal,
683
+ headers: {
684
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
685
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
686
+ "X-Xata-Agent": compact([
687
+ ["client", "TS_SDK"],
688
+ ["version", VERSION],
689
+ isDefined(clientName) ? ["service", clientName] : void 0,
690
+ ...Object.entries(xataAgentExtra ?? {})
691
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
692
+ ...customHeaders,
693
+ Authorization: `Bearer ${apiKey}`,
694
+ "Content-Type": "application/json"
695
+ },
696
+ onmessage(ev) {
697
+ onMessage?.(JSON.parse(ev.data));
698
+ },
699
+ onerror(ev) {
700
+ onError?.(JSON.parse(ev.data));
701
+ },
702
+ onclose() {
703
+ onClose?.();
704
+ }
705
+ });
706
+ }
464
707
  function parseUrl(url) {
465
708
  try {
466
709
  const { host, protocol } = new URL(url);
@@ -491,6 +734,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
491
734
  ...variables,
492
735
  signal
493
736
  });
737
+ const copyBranch = (variables, signal) => dataPlaneFetch({
738
+ url: "/db/{dbBranchName}/copy",
739
+ method: "post",
740
+ ...variables,
741
+ signal
742
+ });
494
743
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
495
744
  url: "/db/{dbBranchName}/metadata",
496
745
  method: "put",
@@ -540,6 +789,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
540
789
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
541
790
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
542
791
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
792
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
543
793
  const createTable = (variables, signal) => dataPlaneFetch({
544
794
  url: "/db/{dbBranchName}/tables/{tableName}",
545
795
  method: "put",
@@ -613,7 +863,19 @@ const searchTable = (variables, signal) => dataPlaneFetch({
613
863
  ...variables,
614
864
  signal
615
865
  });
866
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
867
+ url: "/db/{dbBranchName}/sql",
868
+ method: "post",
869
+ ...variables,
870
+ signal
871
+ });
616
872
  const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
873
+ const askTable = (variables, signal) => dataPlaneFetch({
874
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
875
+ method: "post",
876
+ ...variables,
877
+ signal
878
+ });
617
879
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
618
880
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
619
881
  const operationsByTag$2 = {
@@ -622,6 +884,7 @@ const operationsByTag$2 = {
622
884
  getBranchDetails,
623
885
  createBranch,
624
886
  deleteBranch,
887
+ copyBranch,
625
888
  updateBranchMetadata,
626
889
  getBranchMetadata,
627
890
  getBranchStats,
@@ -639,7 +902,8 @@ const operationsByTag$2 = {
639
902
  compareBranchSchemas,
640
903
  updateBranchSchema,
641
904
  previewBranchSchemaEdit,
642
- applyBranchSchemaEdit
905
+ applyBranchSchemaEdit,
906
+ pushBranchMigrations
643
907
  },
644
908
  migrationRequests: {
645
909
  queryMigrationRequests,
@@ -673,7 +937,16 @@ const operationsByTag$2 = {
673
937
  deleteRecord,
674
938
  bulkInsertTableRecords
675
939
  },
676
- searchAndFilter: { queryTable, searchBranch, searchTable, vectorSearchTable, summarizeTable, aggregateTable }
940
+ searchAndFilter: {
941
+ queryTable,
942
+ searchBranch,
943
+ searchTable,
944
+ sqlQuery,
945
+ vectorSearchTable,
946
+ askTable,
947
+ summarizeTable,
948
+ aggregateTable
949
+ }
677
950
  };
678
951
 
679
952
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
@@ -832,6 +1105,10 @@ const providers = {
832
1105
  staging: {
833
1106
  main: "https://api.staging-xata.dev",
834
1107
  workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1108
+ },
1109
+ dev: {
1110
+ main: "https://api.dev-xata.dev",
1111
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
835
1112
  }
836
1113
  };
837
1114
  function isHostProviderAlias(alias) {
@@ -849,6 +1126,11 @@ function parseProviderString(provider = "production") {
849
1126
  return null;
850
1127
  return { main, workspaces };
851
1128
  }
1129
+ function buildProviderString(provider) {
1130
+ if (isHostProviderAlias(provider))
1131
+ return provider;
1132
+ return `${provider.main},${provider.workspaces}`;
1133
+ }
852
1134
  function parseWorkspacesUrlParts(url) {
853
1135
  if (!isString(url))
854
1136
  return null;
@@ -895,7 +1177,7 @@ class XataApiClient {
895
1177
  __privateSet$7(this, _extraProps, {
896
1178
  apiUrl: getHostUrl(provider, "main"),
897
1179
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
898
- fetchImpl: getFetchImplementation(options.fetch),
1180
+ fetch: getFetchImplementation(options.fetch),
899
1181
  apiKey,
900
1182
  trace,
901
1183
  clientName: options.clientName,
@@ -1161,6 +1443,20 @@ class BranchApi {
1161
1443
  ...this.extraProps
1162
1444
  });
1163
1445
  }
1446
+ copyBranch({
1447
+ workspace,
1448
+ region,
1449
+ database,
1450
+ branch,
1451
+ destinationBranch,
1452
+ limit
1453
+ }) {
1454
+ return operationsByTag.branch.copyBranch({
1455
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1456
+ body: { destinationBranch, limit },
1457
+ ...this.extraProps
1458
+ });
1459
+ }
1164
1460
  updateBranchMetadata({
1165
1461
  workspace,
1166
1462
  region,
@@ -1575,6 +1871,38 @@ class SearchAndFilterApi {
1575
1871
  ...this.extraProps
1576
1872
  });
1577
1873
  }
1874
+ vectorSearchTable({
1875
+ workspace,
1876
+ region,
1877
+ database,
1878
+ branch,
1879
+ table,
1880
+ queryVector,
1881
+ column,
1882
+ similarityFunction,
1883
+ size,
1884
+ filter
1885
+ }) {
1886
+ return operationsByTag.searchAndFilter.vectorSearchTable({
1887
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1888
+ body: { queryVector, column, similarityFunction, size, filter },
1889
+ ...this.extraProps
1890
+ });
1891
+ }
1892
+ askTable({
1893
+ workspace,
1894
+ region,
1895
+ database,
1896
+ branch,
1897
+ table,
1898
+ options
1899
+ }) {
1900
+ return operationsByTag.searchAndFilter.askTable({
1901
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1902
+ body: { ...options },
1903
+ ...this.extraProps
1904
+ });
1905
+ }
1578
1906
  summarizeTable({
1579
1907
  workspace,
1580
1908
  region,
@@ -1839,6 +2167,19 @@ class MigrationsApi {
1839
2167
  ...this.extraProps
1840
2168
  });
1841
2169
  }
2170
+ pushBranchMigrations({
2171
+ workspace,
2172
+ region,
2173
+ database,
2174
+ branch,
2175
+ migrations
2176
+ }) {
2177
+ return operationsByTag.migrations.pushBranchMigrations({
2178
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2179
+ body: { migrations },
2180
+ ...this.extraProps
2181
+ });
2182
+ }
1842
2183
  }
1843
2184
  class DatabaseApi {
1844
2185
  constructor(extraProps) {
@@ -1928,9 +2269,8 @@ class DatabaseApi {
1928
2269
  }
1929
2270
 
1930
2271
  class XataApiPlugin {
1931
- async build(options) {
1932
- const { fetchImpl, apiKey } = await options.getFetchProps();
1933
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2272
+ build(options) {
2273
+ return new XataApiClient(options);
1934
2274
  }
1935
2275
  }
1936
2276
 
@@ -2271,7 +2611,11 @@ function isSortFilterString(value) {
2271
2611
  return isString(value);
2272
2612
  }
2273
2613
  function isSortFilterBase(filter) {
2274
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
2614
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
2615
+ if (key === "*")
2616
+ return value === "random";
2617
+ return value === "asc" || value === "desc";
2618
+ });
2275
2619
  }
2276
2620
  function isSortFilterObject(filter) {
2277
2621
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2344,10 +2688,7 @@ class RestRepository extends Query {
2344
2688
  __privateSet$4(this, _db, options.db);
2345
2689
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2346
2690
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2347
- __privateSet$4(this, _getFetchProps, async () => {
2348
- const props = await options.pluginOptions.getFetchProps();
2349
- return { ...props, sessionID: generateUUID() };
2350
- });
2691
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2351
2692
  const trace = options.pluginOptions.trace ?? defaultTrace;
2352
2693
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2353
2694
  return trace(name, fn, {
@@ -2404,7 +2745,6 @@ class RestRepository extends Query {
2404
2745
  }
2405
2746
  const id = extractId(a);
2406
2747
  if (id) {
2407
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2408
2748
  try {
2409
2749
  const response = await getRecord({
2410
2750
  pathParams: {
@@ -2415,7 +2755,7 @@ class RestRepository extends Query {
2415
2755
  recordId: id
2416
2756
  },
2417
2757
  queryParams: { columns },
2418
- ...fetchProps
2758
+ ...__privateGet$4(this, _getFetchProps).call(this)
2419
2759
  });
2420
2760
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2421
2761
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2593,7 +2933,6 @@ class RestRepository extends Query {
2593
2933
  }
2594
2934
  async search(query, options = {}) {
2595
2935
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2596
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2597
2936
  const { records } = await searchTable({
2598
2937
  pathParams: {
2599
2938
  workspace: "{workspaceId}",
@@ -2611,15 +2950,14 @@ class RestRepository extends Query {
2611
2950
  page: options.page,
2612
2951
  target: options.target
2613
2952
  },
2614
- ...fetchProps
2953
+ ...__privateGet$4(this, _getFetchProps).call(this)
2615
2954
  });
2616
2955
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2617
2956
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2618
2957
  });
2619
2958
  }
2620
2959
  async vectorSearch(column, query, options) {
2621
- return __privateGet$4(this, _trace).call(this, "searchVector", async () => {
2622
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2960
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2623
2961
  const { records } = await vectorSearchTable({
2624
2962
  pathParams: {
2625
2963
  workspace: "{workspaceId}",
@@ -2630,11 +2968,11 @@ class RestRepository extends Query {
2630
2968
  body: {
2631
2969
  column,
2632
2970
  queryVector: query,
2633
- spaceFunction: options?.spaceFunction,
2971
+ similarityFunction: options?.similarityFunction,
2634
2972
  size: options?.size,
2635
2973
  filter: options?.filter
2636
2974
  },
2637
- ...fetchProps
2975
+ ...__privateGet$4(this, _getFetchProps).call(this)
2638
2976
  });
2639
2977
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2640
2978
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2642,7 +2980,6 @@ class RestRepository extends Query {
2642
2980
  }
2643
2981
  async aggregate(aggs, filter) {
2644
2982
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2645
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2646
2983
  const result = await aggregateTable({
2647
2984
  pathParams: {
2648
2985
  workspace: "{workspaceId}",
@@ -2651,7 +2988,7 @@ class RestRepository extends Query {
2651
2988
  tableName: __privateGet$4(this, _table)
2652
2989
  },
2653
2990
  body: { aggs, filter },
2654
- ...fetchProps
2991
+ ...__privateGet$4(this, _getFetchProps).call(this)
2655
2992
  });
2656
2993
  return result;
2657
2994
  });
@@ -2662,7 +2999,6 @@ class RestRepository extends Query {
2662
2999
  if (cacheQuery)
2663
3000
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2664
3001
  const data = query.getQueryOptions();
2665
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2666
3002
  const { meta, records: objects } = await queryTable({
2667
3003
  pathParams: {
2668
3004
  workspace: "{workspaceId}",
@@ -2678,7 +3014,7 @@ class RestRepository extends Query {
2678
3014
  consistency: data.consistency
2679
3015
  },
2680
3016
  fetchOptions: data.fetchOptions,
2681
- ...fetchProps
3017
+ ...__privateGet$4(this, _getFetchProps).call(this)
2682
3018
  });
2683
3019
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2684
3020
  const records = objects.map(
@@ -2691,7 +3027,6 @@ class RestRepository extends Query {
2691
3027
  async summarizeTable(query, summaries, summariesFilter) {
2692
3028
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2693
3029
  const data = query.getQueryOptions();
2694
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2695
3030
  const result = await summarizeTable({
2696
3031
  pathParams: {
2697
3032
  workspace: "{workspaceId}",
@@ -2708,11 +3043,39 @@ class RestRepository extends Query {
2708
3043
  summaries,
2709
3044
  summariesFilter
2710
3045
  },
2711
- ...fetchProps
3046
+ ...__privateGet$4(this, _getFetchProps).call(this)
2712
3047
  });
2713
3048
  return result;
2714
3049
  });
2715
3050
  }
3051
+ ask(question, options) {
3052
+ const params = {
3053
+ pathParams: {
3054
+ workspace: "{workspaceId}",
3055
+ dbBranchName: "{dbBranch}",
3056
+ region: "{region}",
3057
+ tableName: __privateGet$4(this, _table)
3058
+ },
3059
+ body: {
3060
+ question,
3061
+ ...options
3062
+ },
3063
+ ...__privateGet$4(this, _getFetchProps).call(this)
3064
+ };
3065
+ if (options?.onMessage) {
3066
+ fetchSSERequest({
3067
+ endpoint: "dataPlane",
3068
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
3069
+ method: "POST",
3070
+ onMessage: (message) => {
3071
+ options.onMessage?.({ answer: message.text, records: message.records });
3072
+ },
3073
+ ...params
3074
+ });
3075
+ } else {
3076
+ return askTable(params);
3077
+ }
3078
+ }
2716
3079
  }
2717
3080
  _table = new WeakMap();
2718
3081
  _getFetchProps = new WeakMap();
@@ -2722,7 +3085,6 @@ _schemaTables$2 = new WeakMap();
2722
3085
  _trace = new WeakMap();
2723
3086
  _insertRecordWithoutId = new WeakSet();
2724
3087
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2725
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2726
3088
  const record = transformObjectLinks(object);
2727
3089
  const response = await insertRecord({
2728
3090
  pathParams: {
@@ -2733,14 +3095,13 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2733
3095
  },
2734
3096
  queryParams: { columns },
2735
3097
  body: record,
2736
- ...fetchProps
3098
+ ...__privateGet$4(this, _getFetchProps).call(this)
2737
3099
  });
2738
3100
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2739
3101
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2740
3102
  };
2741
3103
  _insertRecordWithId = new WeakSet();
2742
3104
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2743
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2744
3105
  const record = transformObjectLinks(object);
2745
3106
  const response = await insertRecordWithID({
2746
3107
  pathParams: {
@@ -2752,14 +3113,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2752
3113
  },
2753
3114
  body: record,
2754
3115
  queryParams: { createOnly, columns, ifVersion },
2755
- ...fetchProps
3116
+ ...__privateGet$4(this, _getFetchProps).call(this)
2756
3117
  });
2757
3118
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2758
3119
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2759
3120
  };
2760
3121
  _insertRecords = new WeakSet();
2761
3122
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2762
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2763
3123
  const chunkedOperations = chunk(
2764
3124
  objects.map((object) => ({
2765
3125
  insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
@@ -2775,7 +3135,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2775
3135
  region: "{region}"
2776
3136
  },
2777
3137
  body: { operations },
2778
- ...fetchProps
3138
+ ...__privateGet$4(this, _getFetchProps).call(this)
2779
3139
  });
2780
3140
  for (const result of results) {
2781
3141
  if (result.operation === "insert") {
@@ -2789,7 +3149,6 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2789
3149
  };
2790
3150
  _updateRecordWithID = new WeakSet();
2791
3151
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2792
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2793
3152
  const { id: _id, ...record } = transformObjectLinks(object);
2794
3153
  try {
2795
3154
  const response = await updateRecordWithID({
@@ -2802,7 +3161,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2802
3161
  },
2803
3162
  queryParams: { columns, ifVersion },
2804
3163
  body: record,
2805
- ...fetchProps
3164
+ ...__privateGet$4(this, _getFetchProps).call(this)
2806
3165
  });
2807
3166
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2808
3167
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2815,7 +3174,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2815
3174
  };
2816
3175
  _updateRecords = new WeakSet();
2817
3176
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2818
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2819
3177
  const chunkedOperations = chunk(
2820
3178
  objects.map(({ id, ...object }) => ({
2821
3179
  update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
@@ -2831,7 +3189,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2831
3189
  region: "{region}"
2832
3190
  },
2833
3191
  body: { operations },
2834
- ...fetchProps
3192
+ ...__privateGet$4(this, _getFetchProps).call(this)
2835
3193
  });
2836
3194
  for (const result of results) {
2837
3195
  if (result.operation === "update") {
@@ -2845,7 +3203,6 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2845
3203
  };
2846
3204
  _upsertRecordWithID = new WeakSet();
2847
3205
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2848
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2849
3206
  const response = await upsertRecordWithID({
2850
3207
  pathParams: {
2851
3208
  workspace: "{workspaceId}",
@@ -2856,14 +3213,13 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2856
3213
  },
2857
3214
  queryParams: { columns, ifVersion },
2858
3215
  body: object,
2859
- ...fetchProps
3216
+ ...__privateGet$4(this, _getFetchProps).call(this)
2860
3217
  });
2861
3218
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2862
3219
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2863
3220
  };
2864
3221
  _deleteRecord = new WeakSet();
2865
3222
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2866
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2867
3223
  try {
2868
3224
  const response = await deleteRecord({
2869
3225
  pathParams: {
@@ -2874,7 +3230,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2874
3230
  recordId
2875
3231
  },
2876
3232
  queryParams: { columns },
2877
- ...fetchProps
3233
+ ...__privateGet$4(this, _getFetchProps).call(this)
2878
3234
  });
2879
3235
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2880
3236
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2887,7 +3243,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2887
3243
  };
2888
3244
  _deleteRecords = new WeakSet();
2889
3245
  deleteRecords_fn = async function(recordIds) {
2890
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2891
3246
  const chunkedOperations = chunk(
2892
3247
  recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2893
3248
  BULK_OPERATION_MAX_SIZE
@@ -2900,21 +3255,22 @@ deleteRecords_fn = async function(recordIds) {
2900
3255
  region: "{region}"
2901
3256
  },
2902
3257
  body: { operations },
2903
- ...fetchProps
3258
+ ...__privateGet$4(this, _getFetchProps).call(this)
2904
3259
  });
2905
3260
  }
2906
3261
  };
2907
3262
  _setCacheQuery = new WeakSet();
2908
3263
  setCacheQuery_fn = async function(query, meta, records) {
2909
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
3264
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2910
3265
  };
2911
3266
  _getCacheQuery = new WeakSet();
2912
3267
  getCacheQuery_fn = async function(query) {
2913
3268
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2914
- const result = await __privateGet$4(this, _cache).get(key);
3269
+ const result = await __privateGet$4(this, _cache)?.get(key);
2915
3270
  if (!result)
2916
3271
  return null;
2917
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
3272
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
3273
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2918
3274
  if (ttl < 0)
2919
3275
  return null;
2920
3276
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2924,10 +3280,9 @@ _getSchemaTables$1 = new WeakSet();
2924
3280
  getSchemaTables_fn$1 = async function() {
2925
3281
  if (__privateGet$4(this, _schemaTables$2))
2926
3282
  return __privateGet$4(this, _schemaTables$2);
2927
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2928
3283
  const { schema } = await getBranchDetails({
2929
3284
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2930
- ...fetchProps
3285
+ ...__privateGet$4(this, _getFetchProps).call(this)
2931
3286
  });
2932
3287
  __privateSet$4(this, _schemaTables$2, schema.tables);
2933
3288
  return schema.tables;
@@ -3203,19 +3558,19 @@ class SearchPlugin extends XataPlugin {
3203
3558
  __privateAdd$1(this, _schemaTables, void 0);
3204
3559
  __privateSet$1(this, _schemaTables, schemaTables);
3205
3560
  }
3206
- build({ getFetchProps }) {
3561
+ build(pluginOptions) {
3207
3562
  return {
3208
3563
  all: async (query, options = {}) => {
3209
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3210
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3564
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3565
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3211
3566
  return records.map((record) => {
3212
3567
  const { table = "orphan" } = record.xata;
3213
3568
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3214
3569
  });
3215
3570
  },
3216
3571
  byTable: async (query, options = {}) => {
3217
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3218
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3572
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3573
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3219
3574
  return records.reduce((acc, record) => {
3220
3575
  const { table = "orphan" } = record.xata;
3221
3576
  const items = acc[table] ?? [];
@@ -3228,38 +3583,35 @@ class SearchPlugin extends XataPlugin {
3228
3583
  }
3229
3584
  _schemaTables = new WeakMap();
3230
3585
  _search = new WeakSet();
3231
- search_fn = async function(query, options, getFetchProps) {
3232
- const fetchProps = await getFetchProps();
3586
+ search_fn = async function(query, options, pluginOptions) {
3233
3587
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3234
3588
  const { records } = await searchBranch({
3235
3589
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3236
3590
  body: { tables, query, fuzziness, prefix, highlight, page },
3237
- ...fetchProps
3591
+ ...pluginOptions
3238
3592
  });
3239
3593
  return records;
3240
3594
  };
3241
3595
  _getSchemaTables = new WeakSet();
3242
- getSchemaTables_fn = async function(getFetchProps) {
3596
+ getSchemaTables_fn = async function(pluginOptions) {
3243
3597
  if (__privateGet$1(this, _schemaTables))
3244
3598
  return __privateGet$1(this, _schemaTables);
3245
- const fetchProps = await getFetchProps();
3246
3599
  const { schema } = await getBranchDetails({
3247
3600
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3248
- ...fetchProps
3601
+ ...pluginOptions
3249
3602
  });
3250
3603
  __privateSet$1(this, _schemaTables, schema.tables);
3251
3604
  return schema.tables;
3252
3605
  };
3253
3606
 
3254
3607
  class TransactionPlugin extends XataPlugin {
3255
- build({ getFetchProps }) {
3608
+ build(pluginOptions) {
3256
3609
  return {
3257
3610
  run: async (operations) => {
3258
- const fetchProps = await getFetchProps();
3259
3611
  const response = await branchTransaction({
3260
3612
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3261
3613
  body: { operations },
3262
- ...fetchProps
3614
+ ...pluginOptions
3263
3615
  });
3264
3616
  return response;
3265
3617
  }
@@ -3267,91 +3619,6 @@ class TransactionPlugin extends XataPlugin {
3267
3619
  }
3268
3620
  }
3269
3621
 
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
3622
  var __accessCheck = (obj, member, msg) => {
3356
3623
  if (!member.has(obj))
3357
3624
  throw TypeError("Cannot " + msg);
@@ -3375,20 +3642,18 @@ var __privateMethod = (obj, member, method) => {
3375
3642
  return method;
3376
3643
  };
3377
3644
  const buildClient = (plugins) => {
3378
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3645
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3379
3646
  return _a = class {
3380
3647
  constructor(options = {}, schemaTables) {
3381
3648
  __privateAdd(this, _parseOptions);
3382
3649
  __privateAdd(this, _getFetchProps);
3383
- __privateAdd(this, _evaluateBranch);
3384
- __privateAdd(this, _branch, void 0);
3385
3650
  __privateAdd(this, _options, void 0);
3386
3651
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3387
3652
  __privateSet(this, _options, safeOptions);
3388
3653
  const pluginOptions = {
3389
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3654
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3390
3655
  cache: safeOptions.cache,
3391
- trace: safeOptions.trace
3656
+ host: safeOptions.host
3392
3657
  };
3393
3658
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3394
3659
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -3399,22 +3664,15 @@ const buildClient = (plugins) => {
3399
3664
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3400
3665
  if (namespace === void 0)
3401
3666
  continue;
3402
- const result = namespace.build(pluginOptions);
3403
- if (result instanceof Promise) {
3404
- void result.then((namespace2) => {
3405
- this[key] = namespace2;
3406
- });
3407
- } else {
3408
- this[key] = result;
3409
- }
3667
+ this[key] = namespace.build(pluginOptions);
3410
3668
  }
3411
3669
  }
3412
3670
  async getConfig() {
3413
3671
  const databaseURL = __privateGet(this, _options).databaseURL;
3414
- const branch = await __privateGet(this, _options).branch();
3672
+ const branch = __privateGet(this, _options).branch;
3415
3673
  return { databaseURL, branch };
3416
3674
  }
3417
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3675
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3418
3676
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3419
3677
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3420
3678
  if (isBrowser && !enableBrowser) {
@@ -3428,20 +3686,34 @@ const buildClient = (plugins) => {
3428
3686
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3429
3687
  const trace = options?.trace ?? defaultTrace;
3430
3688
  const clientName = options?.clientName;
3689
+ const host = options?.host ?? "production";
3431
3690
  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
3691
  if (!apiKey) {
3440
3692
  throw new Error("Option apiKey is required");
3441
3693
  }
3442
3694
  if (!databaseURL) {
3443
3695
  throw new Error("Option databaseURL is required");
3444
3696
  }
3697
+ const envBranch = getBranch();
3698
+ const previewBranch = getPreviewBranch();
3699
+ const branch = options?.branch || previewBranch || envBranch || "main";
3700
+ if (!!previewBranch && branch !== previewBranch) {
3701
+ console.warn(
3702
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
3703
+ );
3704
+ } else if (!!envBranch && branch !== envBranch) {
3705
+ console.warn(
3706
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3707
+ );
3708
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
3709
+ console.warn(
3710
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3711
+ );
3712
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
3713
+ console.warn(
3714
+ `No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
3715
+ );
3716
+ }
3445
3717
  return {
3446
3718
  fetch,
3447
3719
  databaseURL,
@@ -3449,12 +3721,13 @@ const buildClient = (plugins) => {
3449
3721
  branch,
3450
3722
  cache,
3451
3723
  trace,
3724
+ host,
3452
3725
  clientID: generateUUID(),
3453
3726
  enableBrowser,
3454
3727
  clientName,
3455
3728
  xataAgentExtra
3456
3729
  };
3457
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3730
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3458
3731
  fetch,
3459
3732
  apiKey,
3460
3733
  databaseURL,
@@ -3464,16 +3737,13 @@ const buildClient = (plugins) => {
3464
3737
  clientName,
3465
3738
  xataAgentExtra
3466
3739
  }) {
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
3740
  return {
3471
- fetchImpl: fetch,
3741
+ fetch,
3472
3742
  apiKey,
3473
3743
  apiUrl: "",
3474
3744
  workspacesApiUrl: (path, params) => {
3475
3745
  const hasBranch = params.dbBranchName ?? params.branch;
3476
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
3746
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3477
3747
  return databaseURL + newPath;
3478
3748
  },
3479
3749
  trace,
@@ -3481,22 +3751,6 @@ const buildClient = (plugins) => {
3481
3751
  clientName,
3482
3752
  xataAgentExtra
3483
3753
  };
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
3754
  }, _a;
3501
3755
  };
3502
3756
  class BaseClient extends buildClient() {
@@ -3616,8 +3870,11 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
3616
3870
  exports.addTableColumn = addTableColumn;
3617
3871
  exports.aggregateTable = aggregateTable;
3618
3872
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3873
+ exports.askTable = askTable;
3619
3874
  exports.branchTransaction = branchTransaction;
3620
3875
  exports.buildClient = buildClient;
3876
+ exports.buildPreviewBranchName = buildPreviewBranchName;
3877
+ exports.buildProviderString = buildProviderString;
3621
3878
  exports.buildWorkerRunner = buildWorkerRunner;
3622
3879
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
3623
3880
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
@@ -3625,6 +3882,7 @@ exports.compareBranchSchemas = compareBranchSchemas;
3625
3882
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3626
3883
  exports.compareMigrationRequest = compareMigrationRequest;
3627
3884
  exports.contains = contains;
3885
+ exports.copyBranch = copyBranch;
3628
3886
  exports.createBranch = createBranch;
3629
3887
  exports.createDatabase = createDatabase;
3630
3888
  exports.createMigrationRequest = createMigrationRequest;
@@ -3647,6 +3905,7 @@ exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
3647
3905
  exports.exists = exists;
3648
3906
  exports.ge = ge;
3649
3907
  exports.getAPIKey = getAPIKey;
3908
+ exports.getBranch = getBranch;
3650
3909
  exports.getBranchDetails = getBranchDetails;
3651
3910
  exports.getBranchList = getBranchList;
3652
3911
  exports.getBranchMetadata = getBranchMetadata;
@@ -3655,8 +3914,6 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
3655
3914
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
3656
3915
  exports.getBranchStats = getBranchStats;
3657
3916
  exports.getColumn = getColumn;
3658
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
3659
- exports.getCurrentBranchName = getCurrentBranchName;
3660
3917
  exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3661
3918
  exports.getDatabaseList = getDatabaseList;
3662
3919
  exports.getDatabaseMetadata = getDatabaseMetadata;
@@ -3665,6 +3922,7 @@ exports.getGitBranchesMapping = getGitBranchesMapping;
3665
3922
  exports.getHostUrl = getHostUrl;
3666
3923
  exports.getMigrationRequest = getMigrationRequest;
3667
3924
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
3925
+ exports.getPreviewBranch = getPreviewBranch;
3668
3926
  exports.getRecord = getRecord;
3669
3927
  exports.getTableColumns = getTableColumns;
3670
3928
  exports.getTableSchema = getTableSchema;
@@ -3707,6 +3965,7 @@ exports.parseProviderString = parseProviderString;
3707
3965
  exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
3708
3966
  exports.pattern = pattern;
3709
3967
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3968
+ exports.pushBranchMigrations = pushBranchMigrations;
3710
3969
  exports.queryMigrationRequests = queryMigrationRequests;
3711
3970
  exports.queryTable = queryTable;
3712
3971
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
@@ -3717,6 +3976,7 @@ exports.searchBranch = searchBranch;
3717
3976
  exports.searchTable = searchTable;
3718
3977
  exports.serialize = serialize;
3719
3978
  exports.setTableSchema = setTableSchema;
3979
+ exports.sqlQuery = sqlQuery;
3720
3980
  exports.startsWith = startsWith;
3721
3981
  exports.summarizeTable = summarizeTable;
3722
3982
  exports.updateBranchMetadata = updateBranchMetadata;