@xata.io/client 0.0.0-alpha.vf9f8d99 → 0.0.0-alpha.vfa37ea7

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,10 @@ function getEnvironment() {
91
91
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
92
92
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
93
93
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
94
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
95
- fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
94
+ deployPreview: process.env.XATA_PREVIEW,
95
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
96
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
97
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
96
98
  };
97
99
  }
98
100
  } catch (err) {
@@ -103,8 +105,10 @@ function getEnvironment() {
103
105
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
104
106
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
105
107
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
106
- 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()
108
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
109
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
110
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
111
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
108
112
  };
109
113
  }
110
114
  } catch (err) {
@@ -113,8 +117,10 @@ function getEnvironment() {
113
117
  apiKey: getGlobalApiKey(),
114
118
  databaseURL: getGlobalDatabaseURL(),
115
119
  branch: getGlobalBranch(),
116
- envBranch: void 0,
117
- fallbackBranch: getGlobalFallbackBranch()
120
+ deployPreview: void 0,
121
+ deployPreviewBranch: void 0,
122
+ vercelGitCommitRef: void 0,
123
+ vercelGitRepoOwner: void 0
118
124
  };
119
125
  }
120
126
  function getEnableBrowserVariable() {
@@ -157,34 +163,48 @@ function getGlobalBranch() {
157
163
  return void 0;
158
164
  }
159
165
  }
160
- function getGlobalFallbackBranch() {
166
+ function getDatabaseURL() {
161
167
  try {
162
- return XATA_FALLBACK_BRANCH;
168
+ const { databaseURL } = getEnvironment();
169
+ return databaseURL;
163
170
  } catch (err) {
164
171
  return void 0;
165
172
  }
166
173
  }
167
- function getDatabaseURL() {
174
+ function getAPIKey() {
168
175
  try {
169
- const { databaseURL } = getEnvironment();
170
- return databaseURL;
176
+ const { apiKey } = getEnvironment();
177
+ return apiKey;
171
178
  } catch (err) {
172
179
  return void 0;
173
180
  }
174
181
  }
175
182
  function getBranch() {
176
183
  try {
177
- const { branch, envBranch } = getEnvironment();
178
- return branch ?? envBranch;
184
+ const { branch } = getEnvironment();
185
+ return branch ?? "main";
179
186
  } catch (err) {
180
187
  return void 0;
181
188
  }
182
189
  }
183
-
184
- function getAPIKey() {
190
+ function buildPreviewBranchName({ org, branch }) {
191
+ return `preview-${org}-${branch}`;
192
+ }
193
+ function getPreviewBranch() {
185
194
  try {
186
- const { apiKey } = getEnvironment();
187
- return apiKey;
195
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
196
+ if (deployPreviewBranch)
197
+ return deployPreviewBranch;
198
+ switch (deployPreview) {
199
+ case "vercel": {
200
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
201
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
202
+ return void 0;
203
+ }
204
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
205
+ }
206
+ }
207
+ return void 0;
188
208
  } catch (err) {
189
209
  return void 0;
190
210
  }
@@ -244,7 +264,7 @@ class ApiRequestPool {
244
264
  return __privateGet$8(this, _fetch);
245
265
  }
246
266
  request(url, options) {
247
- const start = new Date();
267
+ const start = /* @__PURE__ */ new Date();
248
268
  const fetch2 = this.getFetch();
249
269
  const runRequest = async (stalled = false) => {
250
270
  const response = await fetch2(url, options);
@@ -254,7 +274,7 @@ class ApiRequestPool {
254
274
  return await runRequest(true);
255
275
  }
256
276
  if (stalled) {
257
- const stalledTime = new Date().getTime() - start.getTime();
277
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
258
278
  console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
259
279
  }
260
280
  return response;
@@ -297,7 +317,180 @@ function generateUUID() {
297
317
  });
298
318
  }
299
319
 
300
- const VERSION = "0.22.3";
320
+ async function getBytes(stream, onChunk) {
321
+ const reader = stream.getReader();
322
+ let result;
323
+ while (!(result = await reader.read()).done) {
324
+ onChunk(result.value);
325
+ }
326
+ }
327
+ function getLines(onLine) {
328
+ let buffer;
329
+ let position;
330
+ let fieldLength;
331
+ let discardTrailingNewline = false;
332
+ return function onChunk(arr) {
333
+ if (buffer === void 0) {
334
+ buffer = arr;
335
+ position = 0;
336
+ fieldLength = -1;
337
+ } else {
338
+ buffer = concat(buffer, arr);
339
+ }
340
+ const bufLength = buffer.length;
341
+ let lineStart = 0;
342
+ while (position < bufLength) {
343
+ if (discardTrailingNewline) {
344
+ if (buffer[position] === 10 /* NewLine */) {
345
+ lineStart = ++position;
346
+ }
347
+ discardTrailingNewline = false;
348
+ }
349
+ let lineEnd = -1;
350
+ for (; position < bufLength && lineEnd === -1; ++position) {
351
+ switch (buffer[position]) {
352
+ case 58 /* Colon */:
353
+ if (fieldLength === -1) {
354
+ fieldLength = position - lineStart;
355
+ }
356
+ break;
357
+ case 13 /* CarriageReturn */:
358
+ discardTrailingNewline = true;
359
+ case 10 /* NewLine */:
360
+ lineEnd = position;
361
+ break;
362
+ }
363
+ }
364
+ if (lineEnd === -1) {
365
+ break;
366
+ }
367
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
368
+ lineStart = position;
369
+ fieldLength = -1;
370
+ }
371
+ if (lineStart === bufLength) {
372
+ buffer = void 0;
373
+ } else if (lineStart !== 0) {
374
+ buffer = buffer.subarray(lineStart);
375
+ position -= lineStart;
376
+ }
377
+ };
378
+ }
379
+ function getMessages(onId, onRetry, onMessage) {
380
+ let message = newMessage();
381
+ const decoder = new TextDecoder();
382
+ return function onLine(line, fieldLength) {
383
+ if (line.length === 0) {
384
+ onMessage?.(message);
385
+ message = newMessage();
386
+ } else if (fieldLength > 0) {
387
+ const field = decoder.decode(line.subarray(0, fieldLength));
388
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
389
+ const value = decoder.decode(line.subarray(valueOffset));
390
+ switch (field) {
391
+ case "data":
392
+ message.data = message.data ? message.data + "\n" + value : value;
393
+ break;
394
+ case "event":
395
+ message.event = value;
396
+ break;
397
+ case "id":
398
+ onId(message.id = value);
399
+ break;
400
+ case "retry":
401
+ const retry = parseInt(value, 10);
402
+ if (!isNaN(retry)) {
403
+ onRetry(message.retry = retry);
404
+ }
405
+ break;
406
+ }
407
+ }
408
+ };
409
+ }
410
+ function concat(a, b) {
411
+ const res = new Uint8Array(a.length + b.length);
412
+ res.set(a);
413
+ res.set(b, a.length);
414
+ return res;
415
+ }
416
+ function newMessage() {
417
+ return {
418
+ data: "",
419
+ event: "",
420
+ id: "",
421
+ retry: void 0
422
+ };
423
+ }
424
+ const EventStreamContentType = "text/event-stream";
425
+ const LastEventId = "last-event-id";
426
+ function fetchEventSource(input, {
427
+ signal: inputSignal,
428
+ headers: inputHeaders,
429
+ onopen: inputOnOpen,
430
+ onmessage,
431
+ onclose,
432
+ onerror,
433
+ fetch: inputFetch,
434
+ ...rest
435
+ }) {
436
+ return new Promise((resolve, reject) => {
437
+ const headers = { ...inputHeaders };
438
+ if (!headers.accept) {
439
+ headers.accept = EventStreamContentType;
440
+ }
441
+ let curRequestController;
442
+ function dispose() {
443
+ curRequestController.abort();
444
+ }
445
+ inputSignal?.addEventListener("abort", () => {
446
+ dispose();
447
+ resolve();
448
+ });
449
+ const fetchImpl = inputFetch ?? fetch;
450
+ const onopen = inputOnOpen ?? defaultOnOpen;
451
+ async function create() {
452
+ curRequestController = new AbortController();
453
+ try {
454
+ const response = await fetchImpl(input, {
455
+ ...rest,
456
+ headers,
457
+ signal: curRequestController.signal
458
+ });
459
+ await onopen(response);
460
+ await getBytes(
461
+ response.body,
462
+ getLines(
463
+ getMessages(
464
+ (id) => {
465
+ if (id) {
466
+ headers[LastEventId] = id;
467
+ } else {
468
+ delete headers[LastEventId];
469
+ }
470
+ },
471
+ (_retry) => {
472
+ },
473
+ onmessage
474
+ )
475
+ )
476
+ );
477
+ onclose?.();
478
+ dispose();
479
+ resolve();
480
+ } catch (err) {
481
+ }
482
+ }
483
+ create();
484
+ });
485
+ }
486
+ function defaultOnOpen(response) {
487
+ const contentType = response.headers?.get("content-type");
488
+ if (!contentType?.startsWith(EventStreamContentType)) {
489
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
490
+ }
491
+ }
492
+
493
+ const VERSION = "0.24.0";
301
494
 
302
495
  class ErrorWithCause extends Error {
303
496
  constructor(message, options) {
@@ -456,6 +649,59 @@ async function fetch$1({
456
649
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
457
650
  );
458
651
  }
652
+ function fetchSSERequest({
653
+ url: path,
654
+ method,
655
+ body,
656
+ headers: customHeaders,
657
+ pathParams,
658
+ queryParams,
659
+ fetch: fetch2,
660
+ apiKey,
661
+ endpoint,
662
+ apiUrl,
663
+ workspacesApiUrl,
664
+ onMessage,
665
+ onError,
666
+ onClose,
667
+ signal,
668
+ clientID,
669
+ sessionID,
670
+ clientName,
671
+ xataAgentExtra
672
+ }) {
673
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
674
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
675
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
676
+ void fetchEventSource(url, {
677
+ method,
678
+ body: JSON.stringify(body),
679
+ fetch: fetch2,
680
+ signal,
681
+ headers: {
682
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
683
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
684
+ "X-Xata-Agent": compact([
685
+ ["client", "TS_SDK"],
686
+ ["version", VERSION],
687
+ isDefined(clientName) ? ["service", clientName] : void 0,
688
+ ...Object.entries(xataAgentExtra ?? {})
689
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
690
+ ...customHeaders,
691
+ Authorization: `Bearer ${apiKey}`,
692
+ "Content-Type": "application/json"
693
+ },
694
+ onmessage(ev) {
695
+ onMessage?.(JSON.parse(ev.data));
696
+ },
697
+ onerror(ev) {
698
+ onError?.(JSON.parse(ev.data));
699
+ },
700
+ onclose() {
701
+ onClose?.();
702
+ }
703
+ });
704
+ }
459
705
  function parseUrl(url) {
460
706
  try {
461
707
  const { host, protocol } = new URL(url);
@@ -486,6 +732,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
486
732
  ...variables,
487
733
  signal
488
734
  });
735
+ const copyBranch = (variables, signal) => dataPlaneFetch({
736
+ url: "/db/{dbBranchName}/copy",
737
+ method: "post",
738
+ ...variables,
739
+ signal
740
+ });
489
741
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
490
742
  url: "/db/{dbBranchName}/metadata",
491
743
  method: "put",
@@ -535,6 +787,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
535
787
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
536
788
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
537
789
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
790
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
538
791
  const createTable = (variables, signal) => dataPlaneFetch({
539
792
  url: "/db/{dbBranchName}/tables/{tableName}",
540
793
  method: "put",
@@ -579,6 +832,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
579
832
  });
580
833
  const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
581
834
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
835
+ const getFileItem = (variables, signal) => dataPlaneFetch({
836
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
837
+ method: "get",
838
+ ...variables,
839
+ signal
840
+ });
841
+ const putFileItem = (variables, signal) => dataPlaneFetch({
842
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
843
+ method: "put",
844
+ ...variables,
845
+ signal
846
+ });
847
+ const deleteFileItem = (variables, signal) => dataPlaneFetch({
848
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
849
+ method: "delete",
850
+ ...variables,
851
+ signal
852
+ });
853
+ const getFile = (variables, signal) => dataPlaneFetch({
854
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
855
+ method: "get",
856
+ ...variables,
857
+ signal
858
+ });
859
+ const putFile = (variables, signal) => dataPlaneFetch({
860
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
861
+ method: "put",
862
+ ...variables,
863
+ signal
864
+ });
865
+ const deleteFile = (variables, signal) => dataPlaneFetch({
866
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
867
+ method: "delete",
868
+ ...variables,
869
+ signal
870
+ });
582
871
  const getRecord = (variables, signal) => dataPlaneFetch({
583
872
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
584
873
  method: "get",
@@ -608,6 +897,12 @@ const searchTable = (variables, signal) => dataPlaneFetch({
608
897
  ...variables,
609
898
  signal
610
899
  });
900
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
901
+ url: "/db/{dbBranchName}/sql",
902
+ method: "post",
903
+ ...variables,
904
+ signal
905
+ });
611
906
  const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
612
907
  const askTable = (variables, signal) => dataPlaneFetch({
613
908
  url: "/db/{dbBranchName}/tables/{tableName}/ask",
@@ -617,12 +912,19 @@ const askTable = (variables, signal) => dataPlaneFetch({
617
912
  });
618
913
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
619
914
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
915
+ const fileAccess = (variables, signal) => dataPlaneFetch({
916
+ url: "/file/{fileId}",
917
+ method: "get",
918
+ ...variables,
919
+ signal
920
+ });
620
921
  const operationsByTag$2 = {
621
922
  branch: {
622
923
  getBranchList,
623
924
  getBranchDetails,
624
925
  createBranch,
625
926
  deleteBranch,
927
+ copyBranch,
626
928
  updateBranchMetadata,
627
929
  getBranchMetadata,
628
930
  getBranchStats,
@@ -640,7 +942,8 @@ const operationsByTag$2 = {
640
942
  compareBranchSchemas,
641
943
  updateBranchSchema,
642
944
  previewBranchSchemaEdit,
643
- applyBranchSchemaEdit
945
+ applyBranchSchemaEdit,
946
+ pushBranchMigrations
644
947
  },
645
948
  migrationRequests: {
646
949
  queryMigrationRequests,
@@ -674,10 +977,12 @@ const operationsByTag$2 = {
674
977
  deleteRecord,
675
978
  bulkInsertTableRecords
676
979
  },
980
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
677
981
  searchAndFilter: {
678
982
  queryTable,
679
983
  searchBranch,
680
984
  searchTable,
985
+ sqlQuery,
681
986
  vectorSearchTable,
682
987
  askTable,
683
988
  summarizeTable,
@@ -781,6 +1086,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
781
1086
  });
782
1087
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
783
1088
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1089
+ const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
784
1090
  const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
785
1091
  const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
786
1092
  const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
@@ -816,6 +1122,7 @@ const operationsByTag$1 = {
816
1122
  deleteDatabase,
817
1123
  getDatabaseMetadata,
818
1124
  updateDatabaseMetadata,
1125
+ renameDatabase,
819
1126
  getDatabaseGithubSettings,
820
1127
  updateDatabaseGithubSettings,
821
1128
  deleteDatabaseGithubSettings,
@@ -841,6 +1148,10 @@ const providers = {
841
1148
  staging: {
842
1149
  main: "https://api.staging-xata.dev",
843
1150
  workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1151
+ },
1152
+ dev: {
1153
+ main: "https://api.dev-xata.dev",
1154
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
844
1155
  }
845
1156
  };
846
1157
  function isHostProviderAlias(alias) {
@@ -858,6 +1169,11 @@ function parseProviderString(provider = "production") {
858
1169
  return null;
859
1170
  return { main, workspaces };
860
1171
  }
1172
+ function buildProviderString(provider) {
1173
+ if (isHostProviderAlias(provider))
1174
+ return provider;
1175
+ return `${provider.main},${provider.workspaces}`;
1176
+ }
861
1177
  function parseWorkspacesUrlParts(url) {
862
1178
  if (!isString(url))
863
1179
  return null;
@@ -962,6 +1278,11 @@ class XataApiClient {
962
1278
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
963
1279
  return __privateGet$7(this, _namespaces).records;
964
1280
  }
1281
+ get files() {
1282
+ if (!__privateGet$7(this, _namespaces).files)
1283
+ __privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
1284
+ return __privateGet$7(this, _namespaces).files;
1285
+ }
965
1286
  get searchAndFilter() {
966
1287
  if (!__privateGet$7(this, _namespaces).searchAndFilter)
967
1288
  __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
@@ -1170,6 +1491,20 @@ class BranchApi {
1170
1491
  ...this.extraProps
1171
1492
  });
1172
1493
  }
1494
+ copyBranch({
1495
+ workspace,
1496
+ region,
1497
+ database,
1498
+ branch,
1499
+ destinationBranch,
1500
+ limit
1501
+ }) {
1502
+ return operationsByTag.branch.copyBranch({
1503
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1504
+ body: { destinationBranch, limit },
1505
+ ...this.extraProps
1506
+ });
1507
+ }
1173
1508
  updateBranchMetadata({
1174
1509
  workspace,
1175
1510
  region,
@@ -1525,6 +1860,164 @@ class RecordsApi {
1525
1860
  });
1526
1861
  }
1527
1862
  }
1863
+ class FilesApi {
1864
+ constructor(extraProps) {
1865
+ this.extraProps = extraProps;
1866
+ }
1867
+ getFileItem({
1868
+ workspace,
1869
+ region,
1870
+ database,
1871
+ branch,
1872
+ table,
1873
+ record,
1874
+ column,
1875
+ fileId
1876
+ }) {
1877
+ return operationsByTag.files.getFileItem({
1878
+ pathParams: {
1879
+ workspace,
1880
+ region,
1881
+ dbBranchName: `${database}:${branch}`,
1882
+ tableName: table,
1883
+ recordId: record,
1884
+ columnName: column,
1885
+ fileId
1886
+ },
1887
+ ...this.extraProps
1888
+ });
1889
+ }
1890
+ putFileItem({
1891
+ workspace,
1892
+ region,
1893
+ database,
1894
+ branch,
1895
+ table,
1896
+ record,
1897
+ column,
1898
+ fileId,
1899
+ file
1900
+ }) {
1901
+ return operationsByTag.files.putFileItem({
1902
+ pathParams: {
1903
+ workspace,
1904
+ region,
1905
+ dbBranchName: `${database}:${branch}`,
1906
+ tableName: table,
1907
+ recordId: record,
1908
+ columnName: column,
1909
+ fileId
1910
+ },
1911
+ // @ts-ignore
1912
+ body: file,
1913
+ ...this.extraProps
1914
+ });
1915
+ }
1916
+ deleteFileItem({
1917
+ workspace,
1918
+ region,
1919
+ database,
1920
+ branch,
1921
+ table,
1922
+ record,
1923
+ column,
1924
+ fileId
1925
+ }) {
1926
+ return operationsByTag.files.deleteFileItem({
1927
+ pathParams: {
1928
+ workspace,
1929
+ region,
1930
+ dbBranchName: `${database}:${branch}`,
1931
+ tableName: table,
1932
+ recordId: record,
1933
+ columnName: column,
1934
+ fileId
1935
+ },
1936
+ ...this.extraProps
1937
+ });
1938
+ }
1939
+ getFile({
1940
+ workspace,
1941
+ region,
1942
+ database,
1943
+ branch,
1944
+ table,
1945
+ record,
1946
+ column
1947
+ }) {
1948
+ return operationsByTag.files.getFile({
1949
+ pathParams: {
1950
+ workspace,
1951
+ region,
1952
+ dbBranchName: `${database}:${branch}`,
1953
+ tableName: table,
1954
+ recordId: record,
1955
+ columnName: column
1956
+ },
1957
+ ...this.extraProps
1958
+ });
1959
+ }
1960
+ putFile({
1961
+ workspace,
1962
+ region,
1963
+ database,
1964
+ branch,
1965
+ table,
1966
+ record,
1967
+ column,
1968
+ file
1969
+ }) {
1970
+ return operationsByTag.files.putFile({
1971
+ pathParams: {
1972
+ workspace,
1973
+ region,
1974
+ dbBranchName: `${database}:${branch}`,
1975
+ tableName: table,
1976
+ recordId: record,
1977
+ columnName: column
1978
+ },
1979
+ body: file,
1980
+ ...this.extraProps
1981
+ });
1982
+ }
1983
+ deleteFile({
1984
+ workspace,
1985
+ region,
1986
+ database,
1987
+ branch,
1988
+ table,
1989
+ record,
1990
+ column
1991
+ }) {
1992
+ return operationsByTag.files.deleteFile({
1993
+ pathParams: {
1994
+ workspace,
1995
+ region,
1996
+ dbBranchName: `${database}:${branch}`,
1997
+ tableName: table,
1998
+ recordId: record,
1999
+ columnName: column
2000
+ },
2001
+ ...this.extraProps
2002
+ });
2003
+ }
2004
+ fileAccess({
2005
+ workspace,
2006
+ region,
2007
+ fileId,
2008
+ verify
2009
+ }) {
2010
+ return operationsByTag.files.fileAccess({
2011
+ pathParams: {
2012
+ workspace,
2013
+ region,
2014
+ fileId
2015
+ },
2016
+ queryParams: { verify },
2017
+ ...this.extraProps
2018
+ });
2019
+ }
2020
+ }
1528
2021
  class SearchAndFilterApi {
1529
2022
  constructor(extraProps) {
1530
2023
  this.extraProps = extraProps;
@@ -1608,17 +2101,11 @@ class SearchAndFilterApi {
1608
2101
  database,
1609
2102
  branch,
1610
2103
  table,
1611
- question,
1612
- fuzziness,
1613
- target,
1614
- prefix,
1615
- filter,
1616
- boosters,
1617
- rules
2104
+ options
1618
2105
  }) {
1619
2106
  return operationsByTag.searchAndFilter.askTable({
1620
2107
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1621
- body: { question, fuzziness, target, prefix, filter, boosters, rules },
2108
+ body: { ...options },
1622
2109
  ...this.extraProps
1623
2110
  });
1624
2111
  }
@@ -1886,6 +2373,19 @@ class MigrationsApi {
1886
2373
  ...this.extraProps
1887
2374
  });
1888
2375
  }
2376
+ pushBranchMigrations({
2377
+ workspace,
2378
+ region,
2379
+ database,
2380
+ branch,
2381
+ migrations
2382
+ }) {
2383
+ return operationsByTag.migrations.pushBranchMigrations({
2384
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2385
+ body: { migrations },
2386
+ ...this.extraProps
2387
+ });
2388
+ }
1889
2389
  }
1890
2390
  class DatabaseApi {
1891
2391
  constructor(extraProps) {
@@ -1937,6 +2437,17 @@ class DatabaseApi {
1937
2437
  ...this.extraProps
1938
2438
  });
1939
2439
  }
2440
+ renameDatabase({
2441
+ workspace,
2442
+ database,
2443
+ newName
2444
+ }) {
2445
+ return operationsByTag.databases.renameDatabase({
2446
+ pathParams: { workspaceId: workspace, dbName: database },
2447
+ body: { newName },
2448
+ ...this.extraProps
2449
+ });
2450
+ }
1940
2451
  getDatabaseGithubSettings({
1941
2452
  workspace,
1942
2453
  database
@@ -2016,18 +2527,46 @@ class Page {
2016
2527
  this.meta = meta;
2017
2528
  this.records = new RecordArray(this, records);
2018
2529
  }
2530
+ /**
2531
+ * Retrieves the next page of results.
2532
+ * @param size Maximum number of results to be retrieved.
2533
+ * @param offset Number of results to skip when retrieving the results.
2534
+ * @returns The next page or results.
2535
+ */
2019
2536
  async nextPage(size, offset) {
2020
2537
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
2021
2538
  }
2539
+ /**
2540
+ * Retrieves the previous page of results.
2541
+ * @param size Maximum number of results to be retrieved.
2542
+ * @param offset Number of results to skip when retrieving the results.
2543
+ * @returns The previous page or results.
2544
+ */
2022
2545
  async previousPage(size, offset) {
2023
2546
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
2024
2547
  }
2548
+ /**
2549
+ * Retrieves the start page of results.
2550
+ * @param size Maximum number of results to be retrieved.
2551
+ * @param offset Number of results to skip when retrieving the results.
2552
+ * @returns The start page or results.
2553
+ */
2025
2554
  async startPage(size, offset) {
2026
2555
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
2027
2556
  }
2557
+ /**
2558
+ * Retrieves the end page of results.
2559
+ * @param size Maximum number of results to be retrieved.
2560
+ * @param offset Number of results to skip when retrieving the results.
2561
+ * @returns The end page or results.
2562
+ */
2028
2563
  async endPage(size, offset) {
2029
2564
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
2030
2565
  }
2566
+ /**
2567
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
2568
+ * @returns Whether or not there will be additional results in the next page of results.
2569
+ */
2031
2570
  hasNextPage() {
2032
2571
  return this.meta.page.more;
2033
2572
  }
@@ -2068,22 +2607,45 @@ const _RecordArray = class extends Array {
2068
2607
  map(callbackfn, thisArg) {
2069
2608
  return this.toArray().map(callbackfn, thisArg);
2070
2609
  }
2610
+ /**
2611
+ * Retrieve next page of records
2612
+ *
2613
+ * @returns A new array of objects
2614
+ */
2071
2615
  async nextPage(size, offset) {
2072
2616
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
2073
2617
  return new _RecordArray(newPage);
2074
2618
  }
2619
+ /**
2620
+ * Retrieve previous page of records
2621
+ *
2622
+ * @returns A new array of objects
2623
+ */
2075
2624
  async previousPage(size, offset) {
2076
2625
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
2077
2626
  return new _RecordArray(newPage);
2078
2627
  }
2628
+ /**
2629
+ * Retrieve start page of records
2630
+ *
2631
+ * @returns A new array of objects
2632
+ */
2079
2633
  async startPage(size, offset) {
2080
2634
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
2081
2635
  return new _RecordArray(newPage);
2082
2636
  }
2637
+ /**
2638
+ * Retrieve end page of records
2639
+ *
2640
+ * @returns A new array of objects
2641
+ */
2083
2642
  async endPage(size, offset) {
2084
2643
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
2085
2644
  return new _RecordArray(newPage);
2086
2645
  }
2646
+ /**
2647
+ * @returns Boolean indicating if there is a next page
2648
+ */
2087
2649
  hasNextPage() {
2088
2650
  return __privateGet$6(this, _page).meta.page.more;
2089
2651
  }
@@ -2120,7 +2682,8 @@ const _Query = class {
2120
2682
  __privateAdd$5(this, _table$1, void 0);
2121
2683
  __privateAdd$5(this, _repository, void 0);
2122
2684
  __privateAdd$5(this, _data, { filter: {} });
2123
- this.meta = { page: { cursor: "start", more: true } };
2685
+ // Implements pagination
2686
+ this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
2124
2687
  this.records = new RecordArray(this, []);
2125
2688
  __privateSet$5(this, _table$1, table);
2126
2689
  if (repository) {
@@ -2157,18 +2720,38 @@ const _Query = class {
2157
2720
  const key = JSON.stringify({ columns, filter, sort, pagination });
2158
2721
  return toBase64(key);
2159
2722
  }
2723
+ /**
2724
+ * Builds a new query object representing a logical OR between the given subqueries.
2725
+ * @param queries An array of subqueries.
2726
+ * @returns A new Query object.
2727
+ */
2160
2728
  any(...queries) {
2161
2729
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2162
2730
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2163
2731
  }
2732
+ /**
2733
+ * Builds a new query object representing a logical AND between the given subqueries.
2734
+ * @param queries An array of subqueries.
2735
+ * @returns A new Query object.
2736
+ */
2164
2737
  all(...queries) {
2165
2738
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2166
2739
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2167
2740
  }
2741
+ /**
2742
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
2743
+ * @param queries An array of subqueries.
2744
+ * @returns A new Query object.
2745
+ */
2168
2746
  not(...queries) {
2169
2747
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2170
2748
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2171
2749
  }
2750
+ /**
2751
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
2752
+ * @param queries An array of subqueries.
2753
+ * @returns A new Query object.
2754
+ */
2172
2755
  none(...queries) {
2173
2756
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2174
2757
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2191,6 +2774,11 @@ const _Query = class {
2191
2774
  const sort = [...originalSort, { column, direction }];
2192
2775
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2193
2776
  }
2777
+ /**
2778
+ * Builds a new query specifying the set of columns to be returned in the query response.
2779
+ * @param columns Array of column names to be returned by the query.
2780
+ * @returns A new Query object.
2781
+ */
2194
2782
  select(columns) {
2195
2783
  return new _Query(
2196
2784
  __privateGet$5(this, _repository),
@@ -2203,6 +2791,12 @@ const _Query = class {
2203
2791
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2204
2792
  return __privateGet$5(this, _repository).query(query);
2205
2793
  }
2794
+ /**
2795
+ * Get results in an iterator
2796
+ *
2797
+ * @async
2798
+ * @returns Async interable of results
2799
+ */
2206
2800
  async *[Symbol.asyncIterator]() {
2207
2801
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2208
2802
  yield record;
@@ -2263,21 +2857,49 @@ const _Query = class {
2263
2857
  );
2264
2858
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2265
2859
  }
2860
+ /**
2861
+ * Builds a new query object adding a cache TTL in milliseconds.
2862
+ * @param ttl The cache TTL in milliseconds.
2863
+ * @returns A new Query object.
2864
+ */
2266
2865
  cache(ttl) {
2267
2866
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2268
2867
  }
2868
+ /**
2869
+ * Retrieve next page of records
2870
+ *
2871
+ * @returns A new page object.
2872
+ */
2269
2873
  nextPage(size, offset) {
2270
2874
  return this.startPage(size, offset);
2271
2875
  }
2876
+ /**
2877
+ * Retrieve previous page of records
2878
+ *
2879
+ * @returns A new page object
2880
+ */
2272
2881
  previousPage(size, offset) {
2273
2882
  return this.startPage(size, offset);
2274
2883
  }
2884
+ /**
2885
+ * Retrieve start page of records
2886
+ *
2887
+ * @returns A new page object
2888
+ */
2275
2889
  startPage(size, offset) {
2276
2890
  return this.getPaginated({ pagination: { size, offset } });
2277
2891
  }
2892
+ /**
2893
+ * Retrieve last page of records
2894
+ *
2895
+ * @returns A new page object
2896
+ */
2278
2897
  endPage(size, offset) {
2279
2898
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2280
2899
  }
2900
+ /**
2901
+ * @returns Boolean indicating if there is a next page
2902
+ */
2281
2903
  hasNextPage() {
2282
2904
  return this.meta.page.more;
2283
2905
  }
@@ -2317,7 +2939,11 @@ function isSortFilterString(value) {
2317
2939
  return isString(value);
2318
2940
  }
2319
2941
  function isSortFilterBase(filter) {
2320
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
2942
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
2943
+ if (key === "*")
2944
+ return value === "random";
2945
+ return value === "asc" || value === "desc";
2946
+ });
2321
2947
  }
2322
2948
  function isSortFilterObject(filter) {
2323
2949
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2750,6 +3376,34 @@ class RestRepository extends Query {
2750
3376
  return result;
2751
3377
  });
2752
3378
  }
3379
+ ask(question, options) {
3380
+ const params = {
3381
+ pathParams: {
3382
+ workspace: "{workspaceId}",
3383
+ dbBranchName: "{dbBranch}",
3384
+ region: "{region}",
3385
+ tableName: __privateGet$4(this, _table)
3386
+ },
3387
+ body: {
3388
+ question,
3389
+ ...options
3390
+ },
3391
+ ...__privateGet$4(this, _getFetchProps).call(this)
3392
+ };
3393
+ if (options?.onMessage) {
3394
+ fetchSSERequest({
3395
+ endpoint: "dataPlane",
3396
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
3397
+ method: "POST",
3398
+ onMessage: (message) => {
3399
+ options.onMessage?.({ answer: message.text, records: message.records });
3400
+ },
3401
+ ...params
3402
+ });
3403
+ } else {
3404
+ return askTable(params);
3405
+ }
3406
+ }
2753
3407
  }
2754
3408
  _table = new WeakMap();
2755
3409
  _getFetchProps = new WeakMap();
@@ -2935,15 +3589,16 @@ deleteRecords_fn = async function(recordIds) {
2935
3589
  };
2936
3590
  _setCacheQuery = new WeakSet();
2937
3591
  setCacheQuery_fn = async function(query, meta, records) {
2938
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
3592
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
2939
3593
  };
2940
3594
  _getCacheQuery = new WeakSet();
2941
3595
  getCacheQuery_fn = async function(query) {
2942
3596
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2943
- const result = await __privateGet$4(this, _cache).get(key);
3597
+ const result = await __privateGet$4(this, _cache)?.get(key);
2944
3598
  if (!result)
2945
3599
  return null;
2946
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
3600
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
3601
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2947
3602
  if (ttl < 0)
2948
3603
  return null;
2949
3604
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -3018,6 +3673,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3018
3673
  }
3019
3674
  }
3020
3675
  const record = { ...data };
3676
+ const serializable = { xata, ...transformObjectLinks(data) };
3677
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
3021
3678
  record.read = function(columns2) {
3022
3679
  return db[table].read(record["id"], columns2);
3023
3680
  };
@@ -3034,16 +3691,17 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3034
3691
  record.delete = function() {
3035
3692
  return db[table].delete(record["id"]);
3036
3693
  };
3694
+ record.xata = metadata;
3037
3695
  record.getMetadata = function() {
3038
- return xata;
3696
+ return metadata;
3039
3697
  };
3040
3698
  record.toSerializable = function() {
3041
- return JSON.parse(JSON.stringify(transformObjectLinks(data)));
3699
+ return JSON.parse(JSON.stringify(serializable));
3042
3700
  };
3043
3701
  record.toString = function() {
3044
- return JSON.stringify(transformObjectLinks(data));
3702
+ return JSON.stringify(transformObjectLinks(serializable));
3045
3703
  };
3046
- for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3704
+ for (const prop of ["read", "update", "replace", "delete", "xata", "getMetadata", "toSerializable", "toString"]) {
3047
3705
  Object.defineProperty(record, prop, { enumerable: false });
3048
3706
  }
3049
3707
  Object.freeze(record);
@@ -3260,6 +3918,7 @@ search_fn = async function(query, options, pluginOptions) {
3260
3918
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3261
3919
  const { records } = await searchBranch({
3262
3920
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3921
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3263
3922
  body: { tables, query, fuzziness, prefix, highlight, page },
3264
3923
  ...pluginOptions
3265
3924
  });
@@ -3325,7 +3984,8 @@ const buildClient = (plugins) => {
3325
3984
  __privateSet(this, _options, safeOptions);
3326
3985
  const pluginOptions = {
3327
3986
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3328
- cache: safeOptions.cache
3987
+ cache: safeOptions.cache,
3988
+ host: safeOptions.host
3329
3989
  };
3330
3990
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3331
3991
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -3336,14 +3996,7 @@ const buildClient = (plugins) => {
3336
3996
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3337
3997
  if (namespace === void 0)
3338
3998
  continue;
3339
- const result = namespace.build(pluginOptions);
3340
- if (result instanceof Promise) {
3341
- void result.then((namespace2) => {
3342
- this[key] = namespace2;
3343
- });
3344
- } else {
3345
- this[key] = result;
3346
- }
3999
+ this[key] = namespace.build(pluginOptions);
3347
4000
  }
3348
4001
  }
3349
4002
  async getConfig() {
@@ -3361,7 +4014,6 @@ const buildClient = (plugins) => {
3361
4014
  }
3362
4015
  const fetch = getFetchImplementation(options?.fetch);
3363
4016
  const databaseURL = options?.databaseURL || getDatabaseURL();
3364
- const branch = options?.branch || getBranch() || "main";
3365
4017
  const apiKey = options?.apiKey || getAPIKey();
3366
4018
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3367
4019
  const trace = options?.trace ?? defaultTrace;
@@ -3374,6 +4026,26 @@ const buildClient = (plugins) => {
3374
4026
  if (!databaseURL) {
3375
4027
  throw new Error("Option databaseURL is required");
3376
4028
  }
4029
+ const envBranch = getBranch();
4030
+ const previewBranch = getPreviewBranch();
4031
+ const branch = options?.branch || previewBranch || envBranch || "main";
4032
+ if (!!previewBranch && branch !== previewBranch) {
4033
+ console.warn(
4034
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
4035
+ );
4036
+ } else if (!!envBranch && branch !== envBranch) {
4037
+ console.warn(
4038
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4039
+ );
4040
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
4041
+ console.warn(
4042
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4043
+ );
4044
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
4045
+ console.warn(
4046
+ `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.`
4047
+ );
4048
+ }
3377
4049
  return {
3378
4050
  fetch,
3379
4051
  databaseURL,
@@ -3401,6 +4073,7 @@ const buildClient = (plugins) => {
3401
4073
  fetch,
3402
4074
  apiKey,
3403
4075
  apiUrl: "",
4076
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3404
4077
  workspacesApiUrl: (path, params) => {
3405
4078
  const hasBranch = params.dbBranchName ?? params.branch;
3406
4079
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
@@ -3505,5 +4178,5 @@ class XataError extends Error {
3505
4178
  }
3506
4179
  }
3507
4180
 
3508
- export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
4181
+ export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
3509
4182
  //# sourceMappingURL=index.mjs.map