@xata.io/client 0.22.3 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -91,8 +91,7 @@ function getEnvironment() {
91
91
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
92
92
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
93
93
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
94
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
95
- fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
94
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH
96
95
  };
97
96
  }
98
97
  } catch (err) {
@@ -103,8 +102,7 @@ function getEnvironment() {
103
102
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
104
103
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
105
104
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
106
- envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
107
- fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
105
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH")
108
106
  };
109
107
  }
110
108
  } catch (err) {
@@ -113,8 +111,7 @@ function getEnvironment() {
113
111
  apiKey: getGlobalApiKey(),
114
112
  databaseURL: getGlobalDatabaseURL(),
115
113
  branch: getGlobalBranch(),
116
- envBranch: void 0,
117
- fallbackBranch: getGlobalFallbackBranch()
114
+ envBranch: void 0
118
115
  };
119
116
  }
120
117
  function getEnableBrowserVariable() {
@@ -157,36 +154,26 @@ function getGlobalBranch() {
157
154
  return void 0;
158
155
  }
159
156
  }
160
- function getGlobalFallbackBranch() {
157
+ function getDatabaseURL() {
161
158
  try {
162
- return XATA_FALLBACK_BRANCH;
159
+ const { databaseURL } = getEnvironment();
160
+ return databaseURL;
163
161
  } catch (err) {
164
162
  return void 0;
165
163
  }
166
164
  }
167
- async function getGitBranch() {
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"] };
172
- try {
173
- const { execSync } = await import(nodeModule);
174
- return execSync(fullCmd, execOptions).toString().trim();
175
- } catch (err) {
176
- }
165
+ function getAPIKey() {
177
166
  try {
178
- if (isObject(Deno)) {
179
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
180
- return new TextDecoder().decode(await process2.output()).trim();
181
- }
167
+ const { apiKey } = getEnvironment();
168
+ return apiKey;
182
169
  } catch (err) {
170
+ return void 0;
183
171
  }
184
172
  }
185
-
186
- function getAPIKey() {
173
+ function getBranch() {
187
174
  try {
188
- const { apiKey } = getEnvironment();
189
- return apiKey;
175
+ const { branch, envBranch } = getEnvironment();
176
+ return branch ?? envBranch;
190
177
  } catch (err) {
191
178
  return void 0;
192
179
  }
@@ -299,7 +286,180 @@ function generateUUID() {
299
286
  });
300
287
  }
301
288
 
302
- const VERSION = "0.22.3";
289
+ async function getBytes(stream, onChunk) {
290
+ const reader = stream.getReader();
291
+ let result;
292
+ while (!(result = await reader.read()).done) {
293
+ onChunk(result.value);
294
+ }
295
+ }
296
+ function getLines(onLine) {
297
+ let buffer;
298
+ let position;
299
+ let fieldLength;
300
+ let discardTrailingNewline = false;
301
+ return function onChunk(arr) {
302
+ if (buffer === void 0) {
303
+ buffer = arr;
304
+ position = 0;
305
+ fieldLength = -1;
306
+ } else {
307
+ buffer = concat(buffer, arr);
308
+ }
309
+ const bufLength = buffer.length;
310
+ let lineStart = 0;
311
+ while (position < bufLength) {
312
+ if (discardTrailingNewline) {
313
+ if (buffer[position] === 10 /* NewLine */) {
314
+ lineStart = ++position;
315
+ }
316
+ discardTrailingNewline = false;
317
+ }
318
+ let lineEnd = -1;
319
+ for (; position < bufLength && lineEnd === -1; ++position) {
320
+ switch (buffer[position]) {
321
+ case 58 /* Colon */:
322
+ if (fieldLength === -1) {
323
+ fieldLength = position - lineStart;
324
+ }
325
+ break;
326
+ case 13 /* CarriageReturn */:
327
+ discardTrailingNewline = true;
328
+ case 10 /* NewLine */:
329
+ lineEnd = position;
330
+ break;
331
+ }
332
+ }
333
+ if (lineEnd === -1) {
334
+ break;
335
+ }
336
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
337
+ lineStart = position;
338
+ fieldLength = -1;
339
+ }
340
+ if (lineStart === bufLength) {
341
+ buffer = void 0;
342
+ } else if (lineStart !== 0) {
343
+ buffer = buffer.subarray(lineStart);
344
+ position -= lineStart;
345
+ }
346
+ };
347
+ }
348
+ function getMessages(onId, onRetry, onMessage) {
349
+ let message = newMessage();
350
+ const decoder = new TextDecoder();
351
+ return function onLine(line, fieldLength) {
352
+ if (line.length === 0) {
353
+ onMessage?.(message);
354
+ message = newMessage();
355
+ } else if (fieldLength > 0) {
356
+ const field = decoder.decode(line.subarray(0, fieldLength));
357
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
358
+ const value = decoder.decode(line.subarray(valueOffset));
359
+ switch (field) {
360
+ case "data":
361
+ message.data = message.data ? message.data + "\n" + value : value;
362
+ break;
363
+ case "event":
364
+ message.event = value;
365
+ break;
366
+ case "id":
367
+ onId(message.id = value);
368
+ break;
369
+ case "retry":
370
+ const retry = parseInt(value, 10);
371
+ if (!isNaN(retry)) {
372
+ onRetry(message.retry = retry);
373
+ }
374
+ break;
375
+ }
376
+ }
377
+ };
378
+ }
379
+ function concat(a, b) {
380
+ const res = new Uint8Array(a.length + b.length);
381
+ res.set(a);
382
+ res.set(b, a.length);
383
+ return res;
384
+ }
385
+ function newMessage() {
386
+ return {
387
+ data: "",
388
+ event: "",
389
+ id: "",
390
+ retry: void 0
391
+ };
392
+ }
393
+ const EventStreamContentType = "text/event-stream";
394
+ const LastEventId = "last-event-id";
395
+ function fetchEventSource(input, {
396
+ signal: inputSignal,
397
+ headers: inputHeaders,
398
+ onopen: inputOnOpen,
399
+ onmessage,
400
+ onclose,
401
+ onerror,
402
+ fetch: inputFetch,
403
+ ...rest
404
+ }) {
405
+ return new Promise((resolve, reject) => {
406
+ const headers = { ...inputHeaders };
407
+ if (!headers.accept) {
408
+ headers.accept = EventStreamContentType;
409
+ }
410
+ let curRequestController;
411
+ function dispose() {
412
+ curRequestController.abort();
413
+ }
414
+ inputSignal?.addEventListener("abort", () => {
415
+ dispose();
416
+ resolve();
417
+ });
418
+ const fetchImpl = inputFetch ?? fetch;
419
+ const onopen = inputOnOpen ?? defaultOnOpen;
420
+ async function create() {
421
+ curRequestController = new AbortController();
422
+ try {
423
+ const response = await fetchImpl(input, {
424
+ ...rest,
425
+ headers,
426
+ signal: curRequestController.signal
427
+ });
428
+ await onopen(response);
429
+ await getBytes(
430
+ response.body,
431
+ getLines(
432
+ getMessages(
433
+ (id) => {
434
+ if (id) {
435
+ headers[LastEventId] = id;
436
+ } else {
437
+ delete headers[LastEventId];
438
+ }
439
+ },
440
+ (_retry) => {
441
+ },
442
+ onmessage
443
+ )
444
+ )
445
+ );
446
+ onclose?.();
447
+ dispose();
448
+ resolve();
449
+ } catch (err) {
450
+ }
451
+ }
452
+ create();
453
+ });
454
+ }
455
+ function defaultOnOpen(response) {
456
+ const contentType = response.headers?.get("content-type");
457
+ if (!contentType?.startsWith(EventStreamContentType)) {
458
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
459
+ }
460
+ }
461
+
462
+ const VERSION = "0.23.0";
303
463
 
304
464
  class ErrorWithCause extends Error {
305
465
  constructor(message, options) {
@@ -383,7 +543,7 @@ async function fetch$1({
383
543
  headers: customHeaders,
384
544
  pathParams,
385
545
  queryParams,
386
- fetchImpl,
546
+ fetch: fetch2,
387
547
  apiKey,
388
548
  endpoint,
389
549
  apiUrl,
@@ -396,7 +556,7 @@ async function fetch$1({
396
556
  xataAgentExtra,
397
557
  fetchOptions = {}
398
558
  }) {
399
- pool.setFetch(fetchImpl);
559
+ pool.setFetch(fetch2);
400
560
  return await trace(
401
561
  `${method.toUpperCase()} ${path}`,
402
562
  async ({ setAttributes }) => {
@@ -458,6 +618,59 @@ async function fetch$1({
458
618
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
459
619
  );
460
620
  }
621
+ function fetchSSERequest({
622
+ url: path,
623
+ method,
624
+ body,
625
+ headers: customHeaders,
626
+ pathParams,
627
+ queryParams,
628
+ fetch: fetch2,
629
+ apiKey,
630
+ endpoint,
631
+ apiUrl,
632
+ workspacesApiUrl,
633
+ onMessage,
634
+ onError,
635
+ onClose,
636
+ signal,
637
+ clientID,
638
+ sessionID,
639
+ clientName,
640
+ xataAgentExtra
641
+ }) {
642
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
643
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
644
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
645
+ void fetchEventSource(url, {
646
+ method,
647
+ body: JSON.stringify(body),
648
+ fetch: fetch2,
649
+ signal,
650
+ headers: {
651
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
652
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
653
+ "X-Xata-Agent": compact([
654
+ ["client", "TS_SDK"],
655
+ ["version", VERSION],
656
+ isDefined(clientName) ? ["service", clientName] : void 0,
657
+ ...Object.entries(xataAgentExtra ?? {})
658
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
659
+ ...customHeaders,
660
+ Authorization: `Bearer ${apiKey}`,
661
+ "Content-Type": "application/json"
662
+ },
663
+ onmessage(ev) {
664
+ onMessage?.(JSON.parse(ev.data));
665
+ },
666
+ onerror(ev) {
667
+ onError?.(JSON.parse(ev.data));
668
+ },
669
+ onclose() {
670
+ onClose?.();
671
+ }
672
+ });
673
+ }
461
674
  function parseUrl(url) {
462
675
  try {
463
676
  const { host, protocol } = new URL(url);
@@ -488,6 +701,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
488
701
  ...variables,
489
702
  signal
490
703
  });
704
+ const copyBranch = (variables, signal) => dataPlaneFetch({
705
+ url: "/db/{dbBranchName}/copy",
706
+ method: "post",
707
+ ...variables,
708
+ signal
709
+ });
491
710
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
492
711
  url: "/db/{dbBranchName}/metadata",
493
712
  method: "put",
@@ -537,6 +756,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
537
756
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
538
757
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
539
758
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
759
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
540
760
  const createTable = (variables, signal) => dataPlaneFetch({
541
761
  url: "/db/{dbBranchName}/tables/{tableName}",
542
762
  method: "put",
@@ -611,6 +831,12 @@ const searchTable = (variables, signal) => dataPlaneFetch({
611
831
  signal
612
832
  });
613
833
  const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
834
+ const askTable = (variables, signal) => dataPlaneFetch({
835
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
836
+ method: "post",
837
+ ...variables,
838
+ signal
839
+ });
614
840
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
615
841
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
616
842
  const operationsByTag$2 = {
@@ -619,6 +845,7 @@ const operationsByTag$2 = {
619
845
  getBranchDetails,
620
846
  createBranch,
621
847
  deleteBranch,
848
+ copyBranch,
622
849
  updateBranchMetadata,
623
850
  getBranchMetadata,
624
851
  getBranchStats,
@@ -636,7 +863,8 @@ const operationsByTag$2 = {
636
863
  compareBranchSchemas,
637
864
  updateBranchSchema,
638
865
  previewBranchSchemaEdit,
639
- applyBranchSchemaEdit
866
+ applyBranchSchemaEdit,
867
+ pushBranchMigrations
640
868
  },
641
869
  migrationRequests: {
642
870
  queryMigrationRequests,
@@ -670,7 +898,15 @@ const operationsByTag$2 = {
670
898
  deleteRecord,
671
899
  bulkInsertTableRecords
672
900
  },
673
- searchAndFilter: { queryTable, searchBranch, searchTable, vectorSearchTable, summarizeTable, aggregateTable }
901
+ searchAndFilter: {
902
+ queryTable,
903
+ searchBranch,
904
+ searchTable,
905
+ vectorSearchTable,
906
+ askTable,
907
+ summarizeTable,
908
+ aggregateTable
909
+ }
674
910
  };
675
911
 
676
912
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
@@ -829,6 +1065,10 @@ const providers = {
829
1065
  staging: {
830
1066
  main: "https://api.staging-xata.dev",
831
1067
  workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1068
+ },
1069
+ dev: {
1070
+ main: "https://api.dev-xata.dev",
1071
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
832
1072
  }
833
1073
  };
834
1074
  function isHostProviderAlias(alias) {
@@ -846,6 +1086,11 @@ function parseProviderString(provider = "production") {
846
1086
  return null;
847
1087
  return { main, workspaces };
848
1088
  }
1089
+ function buildProviderString(provider) {
1090
+ if (isHostProviderAlias(provider))
1091
+ return provider;
1092
+ return `${provider.main},${provider.workspaces}`;
1093
+ }
849
1094
  function parseWorkspacesUrlParts(url) {
850
1095
  if (!isString(url))
851
1096
  return null;
@@ -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
- fetchImpl: getFetchImplementation(options.fetch),
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,
@@ -1836,6 +2127,19 @@ class MigrationsApi {
1836
2127
  ...this.extraProps
1837
2128
  });
1838
2129
  }
2130
+ pushBranchMigrations({
2131
+ workspace,
2132
+ region,
2133
+ database,
2134
+ branch,
2135
+ migrations
2136
+ }) {
2137
+ return operationsByTag.migrations.pushBranchMigrations({
2138
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2139
+ body: { migrations },
2140
+ ...this.extraProps
2141
+ });
2142
+ }
1839
2143
  }
1840
2144
  class DatabaseApi {
1841
2145
  constructor(extraProps) {
@@ -1925,9 +2229,8 @@ class DatabaseApi {
1925
2229
  }
1926
2230
 
1927
2231
  class XataApiPlugin {
1928
- async build(options) {
1929
- const { fetchImpl, apiKey } = await options.getFetchProps();
1930
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2232
+ build(options) {
2233
+ return new XataApiClient(options);
1931
2234
  }
1932
2235
  }
1933
2236
 
@@ -2341,10 +2644,7 @@ class RestRepository extends Query {
2341
2644
  __privateSet$4(this, _db, options.db);
2342
2645
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2343
2646
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2344
- __privateSet$4(this, _getFetchProps, async () => {
2345
- const props = await options.pluginOptions.getFetchProps();
2346
- return { ...props, sessionID: generateUUID() };
2347
- });
2647
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2348
2648
  const trace = options.pluginOptions.trace ?? defaultTrace;
2349
2649
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2350
2650
  return trace(name, fn, {
@@ -2401,7 +2701,6 @@ class RestRepository extends Query {
2401
2701
  }
2402
2702
  const id = extractId(a);
2403
2703
  if (id) {
2404
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2405
2704
  try {
2406
2705
  const response = await getRecord({
2407
2706
  pathParams: {
@@ -2412,7 +2711,7 @@ class RestRepository extends Query {
2412
2711
  recordId: id
2413
2712
  },
2414
2713
  queryParams: { columns },
2415
- ...fetchProps
2714
+ ...__privateGet$4(this, _getFetchProps).call(this)
2416
2715
  });
2417
2716
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2418
2717
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2590,7 +2889,6 @@ class RestRepository extends Query {
2590
2889
  }
2591
2890
  async search(query, options = {}) {
2592
2891
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2593
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2594
2892
  const { records } = await searchTable({
2595
2893
  pathParams: {
2596
2894
  workspace: "{workspaceId}",
@@ -2608,7 +2906,7 @@ class RestRepository extends Query {
2608
2906
  page: options.page,
2609
2907
  target: options.target
2610
2908
  },
2611
- ...fetchProps
2909
+ ...__privateGet$4(this, _getFetchProps).call(this)
2612
2910
  });
2613
2911
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2614
2912
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2616,7 +2914,6 @@ class RestRepository extends Query {
2616
2914
  }
2617
2915
  async vectorSearch(column, query, options) {
2618
2916
  return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2619
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2620
2917
  const { records } = await vectorSearchTable({
2621
2918
  pathParams: {
2622
2919
  workspace: "{workspaceId}",
@@ -2631,7 +2928,7 @@ class RestRepository extends Query {
2631
2928
  size: options?.size,
2632
2929
  filter: options?.filter
2633
2930
  },
2634
- ...fetchProps
2931
+ ...__privateGet$4(this, _getFetchProps).call(this)
2635
2932
  });
2636
2933
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2637
2934
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2639,7 +2936,6 @@ class RestRepository extends Query {
2639
2936
  }
2640
2937
  async aggregate(aggs, filter) {
2641
2938
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2642
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2643
2939
  const result = await aggregateTable({
2644
2940
  pathParams: {
2645
2941
  workspace: "{workspaceId}",
@@ -2648,7 +2944,7 @@ class RestRepository extends Query {
2648
2944
  tableName: __privateGet$4(this, _table)
2649
2945
  },
2650
2946
  body: { aggs, filter },
2651
- ...fetchProps
2947
+ ...__privateGet$4(this, _getFetchProps).call(this)
2652
2948
  });
2653
2949
  return result;
2654
2950
  });
@@ -2659,7 +2955,6 @@ class RestRepository extends Query {
2659
2955
  if (cacheQuery)
2660
2956
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2661
2957
  const data = query.getQueryOptions();
2662
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2663
2958
  const { meta, records: objects } = await queryTable({
2664
2959
  pathParams: {
2665
2960
  workspace: "{workspaceId}",
@@ -2675,7 +2970,7 @@ class RestRepository extends Query {
2675
2970
  consistency: data.consistency
2676
2971
  },
2677
2972
  fetchOptions: data.fetchOptions,
2678
- ...fetchProps
2973
+ ...__privateGet$4(this, _getFetchProps).call(this)
2679
2974
  });
2680
2975
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2681
2976
  const records = objects.map(
@@ -2688,7 +2983,6 @@ class RestRepository extends Query {
2688
2983
  async summarizeTable(query, summaries, summariesFilter) {
2689
2984
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2690
2985
  const data = query.getQueryOptions();
2691
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2692
2986
  const result = await summarizeTable({
2693
2987
  pathParams: {
2694
2988
  workspace: "{workspaceId}",
@@ -2705,11 +2999,39 @@ class RestRepository extends Query {
2705
2999
  summaries,
2706
3000
  summariesFilter
2707
3001
  },
2708
- ...fetchProps
3002
+ ...__privateGet$4(this, _getFetchProps).call(this)
2709
3003
  });
2710
3004
  return result;
2711
3005
  });
2712
3006
  }
3007
+ ask(question, options) {
3008
+ const params = {
3009
+ pathParams: {
3010
+ workspace: "{workspaceId}",
3011
+ dbBranchName: "{dbBranch}",
3012
+ region: "{region}",
3013
+ tableName: __privateGet$4(this, _table)
3014
+ },
3015
+ body: {
3016
+ question,
3017
+ ...options
3018
+ },
3019
+ ...__privateGet$4(this, _getFetchProps).call(this)
3020
+ };
3021
+ if (options?.onMessage) {
3022
+ fetchSSERequest({
3023
+ endpoint: "dataPlane",
3024
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
3025
+ method: "POST",
3026
+ onMessage: (message) => {
3027
+ options.onMessage?.({ answer: message.text });
3028
+ },
3029
+ ...params
3030
+ });
3031
+ } else {
3032
+ return askTable(params);
3033
+ }
3034
+ }
2713
3035
  }
2714
3036
  _table = new WeakMap();
2715
3037
  _getFetchProps = new WeakMap();
@@ -2719,7 +3041,6 @@ _schemaTables$2 = new WeakMap();
2719
3041
  _trace = new WeakMap();
2720
3042
  _insertRecordWithoutId = new WeakSet();
2721
3043
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2722
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2723
3044
  const record = transformObjectLinks(object);
2724
3045
  const response = await insertRecord({
2725
3046
  pathParams: {
@@ -2730,14 +3051,13 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2730
3051
  },
2731
3052
  queryParams: { columns },
2732
3053
  body: record,
2733
- ...fetchProps
3054
+ ...__privateGet$4(this, _getFetchProps).call(this)
2734
3055
  });
2735
3056
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2736
3057
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2737
3058
  };
2738
3059
  _insertRecordWithId = new WeakSet();
2739
3060
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2740
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2741
3061
  const record = transformObjectLinks(object);
2742
3062
  const response = await insertRecordWithID({
2743
3063
  pathParams: {
@@ -2749,14 +3069,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2749
3069
  },
2750
3070
  body: record,
2751
3071
  queryParams: { createOnly, columns, ifVersion },
2752
- ...fetchProps
3072
+ ...__privateGet$4(this, _getFetchProps).call(this)
2753
3073
  });
2754
3074
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2755
3075
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2756
3076
  };
2757
3077
  _insertRecords = new WeakSet();
2758
3078
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2759
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2760
3079
  const chunkedOperations = chunk(
2761
3080
  objects.map((object) => ({
2762
3081
  insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
@@ -2772,7 +3091,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2772
3091
  region: "{region}"
2773
3092
  },
2774
3093
  body: { operations },
2775
- ...fetchProps
3094
+ ...__privateGet$4(this, _getFetchProps).call(this)
2776
3095
  });
2777
3096
  for (const result of results) {
2778
3097
  if (result.operation === "insert") {
@@ -2786,7 +3105,6 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2786
3105
  };
2787
3106
  _updateRecordWithID = new WeakSet();
2788
3107
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2789
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2790
3108
  const { id: _id, ...record } = transformObjectLinks(object);
2791
3109
  try {
2792
3110
  const response = await updateRecordWithID({
@@ -2799,7 +3117,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2799
3117
  },
2800
3118
  queryParams: { columns, ifVersion },
2801
3119
  body: record,
2802
- ...fetchProps
3120
+ ...__privateGet$4(this, _getFetchProps).call(this)
2803
3121
  });
2804
3122
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2805
3123
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2812,7 +3130,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2812
3130
  };
2813
3131
  _updateRecords = new WeakSet();
2814
3132
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2815
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2816
3133
  const chunkedOperations = chunk(
2817
3134
  objects.map(({ id, ...object }) => ({
2818
3135
  update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
@@ -2828,7 +3145,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2828
3145
  region: "{region}"
2829
3146
  },
2830
3147
  body: { operations },
2831
- ...fetchProps
3148
+ ...__privateGet$4(this, _getFetchProps).call(this)
2832
3149
  });
2833
3150
  for (const result of results) {
2834
3151
  if (result.operation === "update") {
@@ -2842,7 +3159,6 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2842
3159
  };
2843
3160
  _upsertRecordWithID = new WeakSet();
2844
3161
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2845
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2846
3162
  const response = await upsertRecordWithID({
2847
3163
  pathParams: {
2848
3164
  workspace: "{workspaceId}",
@@ -2853,14 +3169,13 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2853
3169
  },
2854
3170
  queryParams: { columns, ifVersion },
2855
3171
  body: object,
2856
- ...fetchProps
3172
+ ...__privateGet$4(this, _getFetchProps).call(this)
2857
3173
  });
2858
3174
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2859
3175
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2860
3176
  };
2861
3177
  _deleteRecord = new WeakSet();
2862
3178
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2863
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2864
3179
  try {
2865
3180
  const response = await deleteRecord({
2866
3181
  pathParams: {
@@ -2871,7 +3186,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2871
3186
  recordId
2872
3187
  },
2873
3188
  queryParams: { columns },
2874
- ...fetchProps
3189
+ ...__privateGet$4(this, _getFetchProps).call(this)
2875
3190
  });
2876
3191
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2877
3192
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2884,7 +3199,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2884
3199
  };
2885
3200
  _deleteRecords = new WeakSet();
2886
3201
  deleteRecords_fn = async function(recordIds) {
2887
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2888
3202
  const chunkedOperations = chunk(
2889
3203
  recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2890
3204
  BULK_OPERATION_MAX_SIZE
@@ -2897,21 +3211,22 @@ deleteRecords_fn = async function(recordIds) {
2897
3211
  region: "{region}"
2898
3212
  },
2899
3213
  body: { operations },
2900
- ...fetchProps
3214
+ ...__privateGet$4(this, _getFetchProps).call(this)
2901
3215
  });
2902
3216
  }
2903
3217
  };
2904
3218
  _setCacheQuery = new WeakSet();
2905
3219
  setCacheQuery_fn = async function(query, meta, records) {
2906
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
3220
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2907
3221
  };
2908
3222
  _getCacheQuery = new WeakSet();
2909
3223
  getCacheQuery_fn = async function(query) {
2910
3224
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2911
- const result = await __privateGet$4(this, _cache).get(key);
3225
+ const result = await __privateGet$4(this, _cache)?.get(key);
2912
3226
  if (!result)
2913
3227
  return null;
2914
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
3228
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
3229
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2915
3230
  if (ttl < 0)
2916
3231
  return null;
2917
3232
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2921,10 +3236,9 @@ _getSchemaTables$1 = new WeakSet();
2921
3236
  getSchemaTables_fn$1 = async function() {
2922
3237
  if (__privateGet$4(this, _schemaTables$2))
2923
3238
  return __privateGet$4(this, _schemaTables$2);
2924
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2925
3239
  const { schema } = await getBranchDetails({
2926
3240
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2927
- ...fetchProps
3241
+ ...__privateGet$4(this, _getFetchProps).call(this)
2928
3242
  });
2929
3243
  __privateSet$4(this, _schemaTables$2, schema.tables);
2930
3244
  return schema.tables;
@@ -3200,19 +3514,19 @@ class SearchPlugin extends XataPlugin {
3200
3514
  __privateAdd$1(this, _schemaTables, void 0);
3201
3515
  __privateSet$1(this, _schemaTables, schemaTables);
3202
3516
  }
3203
- build({ getFetchProps }) {
3517
+ build(pluginOptions) {
3204
3518
  return {
3205
3519
  all: async (query, options = {}) => {
3206
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3207
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3520
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3521
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3208
3522
  return records.map((record) => {
3209
3523
  const { table = "orphan" } = record.xata;
3210
3524
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3211
3525
  });
3212
3526
  },
3213
3527
  byTable: async (query, options = {}) => {
3214
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3215
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3528
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3529
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3216
3530
  return records.reduce((acc, record) => {
3217
3531
  const { table = "orphan" } = record.xata;
3218
3532
  const items = acc[table] ?? [];
@@ -3225,38 +3539,35 @@ class SearchPlugin extends XataPlugin {
3225
3539
  }
3226
3540
  _schemaTables = new WeakMap();
3227
3541
  _search = new WeakSet();
3228
- search_fn = async function(query, options, getFetchProps) {
3229
- const fetchProps = await getFetchProps();
3542
+ search_fn = async function(query, options, pluginOptions) {
3230
3543
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3231
3544
  const { records } = await searchBranch({
3232
3545
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3233
3546
  body: { tables, query, fuzziness, prefix, highlight, page },
3234
- ...fetchProps
3547
+ ...pluginOptions
3235
3548
  });
3236
3549
  return records;
3237
3550
  };
3238
3551
  _getSchemaTables = new WeakSet();
3239
- getSchemaTables_fn = async function(getFetchProps) {
3552
+ getSchemaTables_fn = async function(pluginOptions) {
3240
3553
  if (__privateGet$1(this, _schemaTables))
3241
3554
  return __privateGet$1(this, _schemaTables);
3242
- const fetchProps = await getFetchProps();
3243
3555
  const { schema } = await getBranchDetails({
3244
3556
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3245
- ...fetchProps
3557
+ ...pluginOptions
3246
3558
  });
3247
3559
  __privateSet$1(this, _schemaTables, schema.tables);
3248
3560
  return schema.tables;
3249
3561
  };
3250
3562
 
3251
3563
  class TransactionPlugin extends XataPlugin {
3252
- build({ getFetchProps }) {
3564
+ build(pluginOptions) {
3253
3565
  return {
3254
3566
  run: async (operations) => {
3255
- const fetchProps = await getFetchProps();
3256
3567
  const response = await branchTransaction({
3257
3568
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3258
3569
  body: { operations },
3259
- ...fetchProps
3570
+ ...pluginOptions
3260
3571
  });
3261
3572
  return response;
3262
3573
  }
@@ -3264,91 +3575,6 @@ class TransactionPlugin extends XataPlugin {
3264
3575
  }
3265
3576
  }
3266
3577
 
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
3578
  var __accessCheck = (obj, member, msg) => {
3353
3579
  if (!member.has(obj))
3354
3580
  throw TypeError("Cannot " + msg);
@@ -3372,20 +3598,18 @@ var __privateMethod = (obj, member, method) => {
3372
3598
  return method;
3373
3599
  };
3374
3600
  const buildClient = (plugins) => {
3375
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3601
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3376
3602
  return _a = class {
3377
3603
  constructor(options = {}, schemaTables) {
3378
3604
  __privateAdd(this, _parseOptions);
3379
3605
  __privateAdd(this, _getFetchProps);
3380
- __privateAdd(this, _evaluateBranch);
3381
- __privateAdd(this, _branch, void 0);
3382
3606
  __privateAdd(this, _options, void 0);
3383
3607
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3384
3608
  __privateSet(this, _options, safeOptions);
3385
3609
  const pluginOptions = {
3386
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3610
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3387
3611
  cache: safeOptions.cache,
3388
- trace: safeOptions.trace
3612
+ host: safeOptions.host
3389
3613
  };
3390
3614
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3391
3615
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -3396,22 +3620,15 @@ const buildClient = (plugins) => {
3396
3620
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3397
3621
  if (namespace === void 0)
3398
3622
  continue;
3399
- const result = namespace.build(pluginOptions);
3400
- if (result instanceof Promise) {
3401
- void result.then((namespace2) => {
3402
- this[key] = namespace2;
3403
- });
3404
- } else {
3405
- this[key] = result;
3406
- }
3623
+ this[key] = namespace.build(pluginOptions);
3407
3624
  }
3408
3625
  }
3409
3626
  async getConfig() {
3410
3627
  const databaseURL = __privateGet(this, _options).databaseURL;
3411
- const branch = await __privateGet(this, _options).branch();
3628
+ const branch = __privateGet(this, _options).branch;
3412
3629
  return { databaseURL, branch };
3413
3630
  }
3414
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3631
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3415
3632
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3416
3633
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3417
3634
  if (isBrowser && !enableBrowser) {
@@ -3421,18 +3638,13 @@ const buildClient = (plugins) => {
3421
3638
  }
3422
3639
  const fetch = getFetchImplementation(options?.fetch);
3423
3640
  const databaseURL = options?.databaseURL || getDatabaseURL();
3641
+ const branch = options?.branch || getBranch() || "main";
3424
3642
  const apiKey = options?.apiKey || getAPIKey();
3425
3643
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3426
3644
  const trace = options?.trace ?? defaultTrace;
3427
3645
  const clientName = options?.clientName;
3646
+ const host = options?.host ?? "production";
3428
3647
  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
3648
  if (!apiKey) {
3437
3649
  throw new Error("Option apiKey is required");
3438
3650
  }
@@ -3446,12 +3658,13 @@ const buildClient = (plugins) => {
3446
3658
  branch,
3447
3659
  cache,
3448
3660
  trace,
3661
+ host,
3449
3662
  clientID: generateUUID(),
3450
3663
  enableBrowser,
3451
3664
  clientName,
3452
3665
  xataAgentExtra
3453
3666
  };
3454
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3667
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3455
3668
  fetch,
3456
3669
  apiKey,
3457
3670
  databaseURL,
@@ -3461,16 +3674,13 @@ const buildClient = (plugins) => {
3461
3674
  clientName,
3462
3675
  xataAgentExtra
3463
3676
  }) {
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
3677
  return {
3468
- fetchImpl: fetch,
3678
+ fetch,
3469
3679
  apiKey,
3470
3680
  apiUrl: "",
3471
3681
  workspacesApiUrl: (path, params) => {
3472
3682
  const hasBranch = params.dbBranchName ?? params.branch;
3473
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
3683
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3474
3684
  return databaseURL + newPath;
3475
3685
  },
3476
3686
  trace,
@@ -3478,22 +3688,6 @@ const buildClient = (plugins) => {
3478
3688
  clientName,
3479
3689
  xataAgentExtra
3480
3690
  };
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
3691
  }, _a;
3498
3692
  };
3499
3693
  class BaseClient extends buildClient() {
@@ -3588,5 +3782,5 @@ class XataError extends Error {
3588
3782
  }
3589
3783
  }
3590
3784
 
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, getCurrentBranchDetails, getCurrentBranchName, 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 };
3785
+ 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, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
3592
3786
  //# sourceMappingURL=index.mjs.map