@xata.io/client 0.0.0-alpha.ve914594 → 0.0.0-alpha.ve91fd39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -93,8 +93,10 @@ function getEnvironment() {
93
93
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
94
94
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
95
95
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
96
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
97
- fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
96
+ deployPreview: process.env.XATA_PREVIEW,
97
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
98
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
99
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
98
100
  };
99
101
  }
100
102
  } catch (err) {
@@ -105,8 +107,10 @@ function getEnvironment() {
105
107
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
106
108
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
107
109
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
108
- envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
109
- fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
110
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
111
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
112
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
113
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
110
114
  };
111
115
  }
112
116
  } catch (err) {
@@ -115,8 +119,10 @@ function getEnvironment() {
115
119
  apiKey: getGlobalApiKey(),
116
120
  databaseURL: getGlobalDatabaseURL(),
117
121
  branch: getGlobalBranch(),
118
- envBranch: void 0,
119
- fallbackBranch: getGlobalFallbackBranch()
122
+ deployPreview: void 0,
123
+ deployPreviewBranch: void 0,
124
+ vercelGitCommitRef: void 0,
125
+ vercelGitRepoOwner: void 0
120
126
  };
121
127
  }
122
128
  function getEnableBrowserVariable() {
@@ -159,37 +165,48 @@ function getGlobalBranch() {
159
165
  return void 0;
160
166
  }
161
167
  }
162
- function getGlobalFallbackBranch() {
168
+ function getDatabaseURL() {
163
169
  try {
164
- return XATA_FALLBACK_BRANCH;
170
+ const { databaseURL } = getEnvironment();
171
+ return databaseURL;
165
172
  } catch (err) {
166
173
  return void 0;
167
174
  }
168
175
  }
169
- async function getGitBranch() {
170
- const cmd = ["git", "branch", "--show-current"];
171
- const fullCmd = cmd.join(" ");
172
- const nodeModule = ["child", "process"].join("_");
173
- const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
176
+ function getAPIKey() {
174
177
  try {
175
- if (typeof require === "function") {
176
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
177
- }
178
+ const { apiKey } = getEnvironment();
179
+ return apiKey;
178
180
  } catch (err) {
181
+ return void 0;
179
182
  }
183
+ }
184
+ function getBranch() {
180
185
  try {
181
- if (isObject(Deno)) {
182
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
183
- return new TextDecoder().decode(await process2.output()).trim();
184
- }
186
+ const { branch } = getEnvironment();
187
+ return branch ?? "main";
185
188
  } catch (err) {
189
+ return void 0;
186
190
  }
187
191
  }
188
-
189
- function getAPIKey() {
192
+ function buildPreviewBranchName({ org, branch }) {
193
+ return `preview-${org}-${branch}`;
194
+ }
195
+ function getPreviewBranch() {
190
196
  try {
191
- const { apiKey } = getEnvironment();
192
- return apiKey;
197
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
198
+ if (deployPreviewBranch)
199
+ return deployPreviewBranch;
200
+ switch (deployPreview) {
201
+ case "vercel": {
202
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
203
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
204
+ return void 0;
205
+ }
206
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
207
+ }
208
+ }
209
+ return void 0;
193
210
  } catch (err) {
194
211
  return void 0;
195
212
  }
@@ -302,7 +319,180 @@ function generateUUID() {
302
319
  });
303
320
  }
304
321
 
305
- const VERSION = "0.0.0-alpha.ve914594";
322
+ async function getBytes(stream, onChunk) {
323
+ const reader = stream.getReader();
324
+ let result;
325
+ while (!(result = await reader.read()).done) {
326
+ onChunk(result.value);
327
+ }
328
+ }
329
+ function getLines(onLine) {
330
+ let buffer;
331
+ let position;
332
+ let fieldLength;
333
+ let discardTrailingNewline = false;
334
+ return function onChunk(arr) {
335
+ if (buffer === void 0) {
336
+ buffer = arr;
337
+ position = 0;
338
+ fieldLength = -1;
339
+ } else {
340
+ buffer = concat(buffer, arr);
341
+ }
342
+ const bufLength = buffer.length;
343
+ let lineStart = 0;
344
+ while (position < bufLength) {
345
+ if (discardTrailingNewline) {
346
+ if (buffer[position] === 10 /* NewLine */) {
347
+ lineStart = ++position;
348
+ }
349
+ discardTrailingNewline = false;
350
+ }
351
+ let lineEnd = -1;
352
+ for (; position < bufLength && lineEnd === -1; ++position) {
353
+ switch (buffer[position]) {
354
+ case 58 /* Colon */:
355
+ if (fieldLength === -1) {
356
+ fieldLength = position - lineStart;
357
+ }
358
+ break;
359
+ case 13 /* CarriageReturn */:
360
+ discardTrailingNewline = true;
361
+ case 10 /* NewLine */:
362
+ lineEnd = position;
363
+ break;
364
+ }
365
+ }
366
+ if (lineEnd === -1) {
367
+ break;
368
+ }
369
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
370
+ lineStart = position;
371
+ fieldLength = -1;
372
+ }
373
+ if (lineStart === bufLength) {
374
+ buffer = void 0;
375
+ } else if (lineStart !== 0) {
376
+ buffer = buffer.subarray(lineStart);
377
+ position -= lineStart;
378
+ }
379
+ };
380
+ }
381
+ function getMessages(onId, onRetry, onMessage) {
382
+ let message = newMessage();
383
+ const decoder = new TextDecoder();
384
+ return function onLine(line, fieldLength) {
385
+ if (line.length === 0) {
386
+ onMessage?.(message);
387
+ message = newMessage();
388
+ } else if (fieldLength > 0) {
389
+ const field = decoder.decode(line.subarray(0, fieldLength));
390
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
391
+ const value = decoder.decode(line.subarray(valueOffset));
392
+ switch (field) {
393
+ case "data":
394
+ message.data = message.data ? message.data + "\n" + value : value;
395
+ break;
396
+ case "event":
397
+ message.event = value;
398
+ break;
399
+ case "id":
400
+ onId(message.id = value);
401
+ break;
402
+ case "retry":
403
+ const retry = parseInt(value, 10);
404
+ if (!isNaN(retry)) {
405
+ onRetry(message.retry = retry);
406
+ }
407
+ break;
408
+ }
409
+ }
410
+ };
411
+ }
412
+ function concat(a, b) {
413
+ const res = new Uint8Array(a.length + b.length);
414
+ res.set(a);
415
+ res.set(b, a.length);
416
+ return res;
417
+ }
418
+ function newMessage() {
419
+ return {
420
+ data: "",
421
+ event: "",
422
+ id: "",
423
+ retry: void 0
424
+ };
425
+ }
426
+ const EventStreamContentType = "text/event-stream";
427
+ const LastEventId = "last-event-id";
428
+ function fetchEventSource(input, {
429
+ signal: inputSignal,
430
+ headers: inputHeaders,
431
+ onopen: inputOnOpen,
432
+ onmessage,
433
+ onclose,
434
+ onerror,
435
+ fetch: inputFetch,
436
+ ...rest
437
+ }) {
438
+ return new Promise((resolve, reject) => {
439
+ const headers = { ...inputHeaders };
440
+ if (!headers.accept) {
441
+ headers.accept = EventStreamContentType;
442
+ }
443
+ let curRequestController;
444
+ function dispose() {
445
+ curRequestController.abort();
446
+ }
447
+ inputSignal?.addEventListener("abort", () => {
448
+ dispose();
449
+ resolve();
450
+ });
451
+ const fetchImpl = inputFetch ?? fetch;
452
+ const onopen = inputOnOpen ?? defaultOnOpen;
453
+ async function create() {
454
+ curRequestController = new AbortController();
455
+ try {
456
+ const response = await fetchImpl(input, {
457
+ ...rest,
458
+ headers,
459
+ signal: curRequestController.signal
460
+ });
461
+ await onopen(response);
462
+ await getBytes(
463
+ response.body,
464
+ getLines(
465
+ getMessages(
466
+ (id) => {
467
+ if (id) {
468
+ headers[LastEventId] = id;
469
+ } else {
470
+ delete headers[LastEventId];
471
+ }
472
+ },
473
+ (_retry) => {
474
+ },
475
+ onmessage
476
+ )
477
+ )
478
+ );
479
+ onclose?.();
480
+ dispose();
481
+ resolve();
482
+ } catch (err) {
483
+ }
484
+ }
485
+ create();
486
+ });
487
+ }
488
+ function defaultOnOpen(response) {
489
+ const contentType = response.headers?.get("content-type");
490
+ if (!contentType?.startsWith(EventStreamContentType)) {
491
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
492
+ }
493
+ }
494
+
495
+ const VERSION = "0.23.2";
306
496
 
307
497
  class ErrorWithCause extends Error {
308
498
  constructor(message, options) {
@@ -386,7 +576,7 @@ async function fetch$1({
386
576
  headers: customHeaders,
387
577
  pathParams,
388
578
  queryParams,
389
- fetchImpl,
579
+ fetch: fetch2,
390
580
  apiKey,
391
581
  endpoint,
392
582
  apiUrl,
@@ -396,12 +586,13 @@ async function fetch$1({
396
586
  clientID,
397
587
  sessionID,
398
588
  clientName,
589
+ xataAgentExtra,
399
590
  fetchOptions = {}
400
591
  }) {
401
- pool.setFetch(fetchImpl);
592
+ pool.setFetch(fetch2);
402
593
  return await trace(
403
594
  `${method.toUpperCase()} ${path}`,
404
- async ({ name, setAttributes }) => {
595
+ async ({ setAttributes }) => {
405
596
  const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
406
597
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
407
598
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
@@ -412,7 +603,8 @@ async function fetch$1({
412
603
  const xataAgent = compact([
413
604
  ["client", "TS_SDK"],
414
605
  ["version", VERSION],
415
- isDefined(clientName) ? ["service", clientName] : void 0
606
+ isDefined(clientName) ? ["service", clientName] : void 0,
607
+ ...Object.entries(xataAgentExtra ?? {})
416
608
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
417
609
  const headers = {
418
610
  "Accept-Encoding": "identity",
@@ -459,6 +651,59 @@ async function fetch$1({
459
651
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
460
652
  );
461
653
  }
654
+ function fetchSSERequest({
655
+ url: path,
656
+ method,
657
+ body,
658
+ headers: customHeaders,
659
+ pathParams,
660
+ queryParams,
661
+ fetch: fetch2,
662
+ apiKey,
663
+ endpoint,
664
+ apiUrl,
665
+ workspacesApiUrl,
666
+ onMessage,
667
+ onError,
668
+ onClose,
669
+ signal,
670
+ clientID,
671
+ sessionID,
672
+ clientName,
673
+ xataAgentExtra
674
+ }) {
675
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
676
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
677
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
678
+ void fetchEventSource(url, {
679
+ method,
680
+ body: JSON.stringify(body),
681
+ fetch: fetch2,
682
+ signal,
683
+ headers: {
684
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
685
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
686
+ "X-Xata-Agent": compact([
687
+ ["client", "TS_SDK"],
688
+ ["version", VERSION],
689
+ isDefined(clientName) ? ["service", clientName] : void 0,
690
+ ...Object.entries(xataAgentExtra ?? {})
691
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
692
+ ...customHeaders,
693
+ Authorization: `Bearer ${apiKey}`,
694
+ "Content-Type": "application/json"
695
+ },
696
+ onmessage(ev) {
697
+ onMessage?.(JSON.parse(ev.data));
698
+ },
699
+ onerror(ev) {
700
+ onError?.(JSON.parse(ev.data));
701
+ },
702
+ onclose() {
703
+ onClose?.();
704
+ }
705
+ });
706
+ }
462
707
  function parseUrl(url) {
463
708
  try {
464
709
  const { host, protocol } = new URL(url);
@@ -489,6 +734,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
489
734
  ...variables,
490
735
  signal
491
736
  });
737
+ const copyBranch = (variables, signal) => dataPlaneFetch({
738
+ url: "/db/{dbBranchName}/copy",
739
+ method: "post",
740
+ ...variables,
741
+ signal
742
+ });
492
743
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
493
744
  url: "/db/{dbBranchName}/metadata",
494
745
  method: "put",
@@ -514,7 +765,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
514
765
  const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
515
766
  const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
516
767
  const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
517
- const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
518
768
  const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
519
769
  const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
520
770
  const getMigrationRequest = (variables, signal) => dataPlaneFetch({
@@ -539,6 +789,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
539
789
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
540
790
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
541
791
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
792
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
542
793
  const createTable = (variables, signal) => dataPlaneFetch({
543
794
  url: "/db/{dbBranchName}/tables/{tableName}",
544
795
  method: "put",
@@ -581,6 +832,7 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
581
832
  ...variables,
582
833
  signal
583
834
  });
835
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
584
836
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
585
837
  const getRecord = (variables, signal) => dataPlaneFetch({
586
838
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
@@ -611,6 +863,19 @@ const searchTable = (variables, signal) => dataPlaneFetch({
611
863
  ...variables,
612
864
  signal
613
865
  });
866
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
867
+ url: "/db/{dbBranchName}/sql",
868
+ method: "post",
869
+ ...variables,
870
+ signal
871
+ });
872
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
873
+ const askTable = (variables, signal) => dataPlaneFetch({
874
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
875
+ method: "post",
876
+ ...variables,
877
+ signal
878
+ });
614
879
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
615
880
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
616
881
  const operationsByTag$2 = {
@@ -619,6 +884,7 @@ const operationsByTag$2 = {
619
884
  getBranchDetails,
620
885
  createBranch,
621
886
  deleteBranch,
887
+ copyBranch,
622
888
  updateBranchMetadata,
623
889
  getBranchMetadata,
624
890
  getBranchStats,
@@ -636,17 +902,8 @@ const operationsByTag$2 = {
636
902
  compareBranchSchemas,
637
903
  updateBranchSchema,
638
904
  previewBranchSchemaEdit,
639
- applyBranchSchemaEdit
640
- },
641
- records: {
642
- branchTransaction,
643
- insertRecord,
644
- getRecord,
645
- insertRecordWithID,
646
- updateRecordWithID,
647
- upsertRecordWithID,
648
- deleteRecord,
649
- bulkInsertTableRecords
905
+ applyBranchSchemaEdit,
906
+ pushBranchMigrations
650
907
  },
651
908
  migrationRequests: {
652
909
  queryMigrationRequests,
@@ -670,7 +927,26 @@ const operationsByTag$2 = {
670
927
  updateColumn,
671
928
  deleteColumn
672
929
  },
673
- searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
930
+ records: {
931
+ branchTransaction,
932
+ insertRecord,
933
+ getRecord,
934
+ insertRecordWithID,
935
+ updateRecordWithID,
936
+ upsertRecordWithID,
937
+ deleteRecord,
938
+ bulkInsertTableRecords
939
+ },
940
+ searchAndFilter: {
941
+ queryTable,
942
+ searchBranch,
943
+ searchTable,
944
+ sqlQuery,
945
+ vectorSearchTable,
946
+ askTable,
947
+ summarizeTable,
948
+ aggregateTable
949
+ }
674
950
  };
675
951
 
676
952
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
@@ -769,6 +1045,9 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
769
1045
  });
770
1046
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
771
1047
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1048
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
1049
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
1050
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
772
1051
  const listRegions = (variables, signal) => controlPlaneFetch({
773
1052
  url: "/workspaces/{workspaceId}/regions",
774
1053
  method: "get",
@@ -801,6 +1080,9 @@ const operationsByTag$1 = {
801
1080
  deleteDatabase,
802
1081
  getDatabaseMetadata,
803
1082
  updateDatabaseMetadata,
1083
+ getDatabaseGithubSettings,
1084
+ updateDatabaseGithubSettings,
1085
+ deleteDatabaseGithubSettings,
804
1086
  listRegions
805
1087
  }
806
1088
  };
@@ -821,8 +1103,12 @@ const providers = {
821
1103
  workspaces: "https://{workspaceId}.{region}.xata.sh"
822
1104
  },
823
1105
  staging: {
824
- main: "https://staging.xatabase.co",
825
- workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
1106
+ main: "https://api.staging-xata.dev",
1107
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1108
+ },
1109
+ dev: {
1110
+ main: "https://api.dev-xata.dev",
1111
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
826
1112
  }
827
1113
  };
828
1114
  function isHostProviderAlias(alias) {
@@ -840,12 +1126,19 @@ function parseProviderString(provider = "production") {
840
1126
  return null;
841
1127
  return { main, workspaces };
842
1128
  }
1129
+ function buildProviderString(provider) {
1130
+ if (isHostProviderAlias(provider))
1131
+ return provider;
1132
+ return `${provider.main},${provider.workspaces}`;
1133
+ }
843
1134
  function parseWorkspacesUrlParts(url) {
844
1135
  if (!isString(url))
845
1136
  return null;
846
1137
  const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
847
- const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
848
- const match = url.match(regex) || url.match(regexStaging);
1138
+ const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1139
+ const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1140
+ const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1141
+ const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
849
1142
  if (!match)
850
1143
  return null;
851
1144
  return { workspace: match[1], region: match[2] };
@@ -884,10 +1177,11 @@ class XataApiClient {
884
1177
  __privateSet$7(this, _extraProps, {
885
1178
  apiUrl: getHostUrl(provider, "main"),
886
1179
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
887
- fetchImpl: getFetchImplementation(options.fetch),
1180
+ fetch: getFetchImplementation(options.fetch),
888
1181
  apiKey,
889
1182
  trace,
890
1183
  clientName: options.clientName,
1184
+ xataAgentExtra: options.xataAgentExtra,
891
1185
  clientID
892
1186
  });
893
1187
  }
@@ -1149,6 +1443,20 @@ class BranchApi {
1149
1443
  ...this.extraProps
1150
1444
  });
1151
1445
  }
1446
+ copyBranch({
1447
+ workspace,
1448
+ region,
1449
+ database,
1450
+ branch,
1451
+ destinationBranch,
1452
+ limit
1453
+ }) {
1454
+ return operationsByTag.branch.copyBranch({
1455
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1456
+ body: { destinationBranch, limit },
1457
+ ...this.extraProps
1458
+ });
1459
+ }
1152
1460
  updateBranchMetadata({
1153
1461
  workspace,
1154
1462
  region,
@@ -1563,6 +1871,38 @@ class SearchAndFilterApi {
1563
1871
  ...this.extraProps
1564
1872
  });
1565
1873
  }
1874
+ vectorSearchTable({
1875
+ workspace,
1876
+ region,
1877
+ database,
1878
+ branch,
1879
+ table,
1880
+ queryVector,
1881
+ column,
1882
+ similarityFunction,
1883
+ size,
1884
+ filter
1885
+ }) {
1886
+ return operationsByTag.searchAndFilter.vectorSearchTable({
1887
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1888
+ body: { queryVector, column, similarityFunction, size, filter },
1889
+ ...this.extraProps
1890
+ });
1891
+ }
1892
+ askTable({
1893
+ workspace,
1894
+ region,
1895
+ database,
1896
+ branch,
1897
+ table,
1898
+ options
1899
+ }) {
1900
+ return operationsByTag.searchAndFilter.askTable({
1901
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1902
+ body: { ...options },
1903
+ ...this.extraProps
1904
+ });
1905
+ }
1566
1906
  summarizeTable({
1567
1907
  workspace,
1568
1908
  region,
@@ -1763,11 +2103,13 @@ class MigrationsApi {
1763
2103
  region,
1764
2104
  database,
1765
2105
  branch,
1766
- schema
2106
+ schema,
2107
+ schemaOperations,
2108
+ branchOperations
1767
2109
  }) {
1768
2110
  return operationsByTag.migrations.compareBranchWithUserSchema({
1769
2111
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1770
- body: { schema },
2112
+ body: { schema, schemaOperations, branchOperations },
1771
2113
  ...this.extraProps
1772
2114
  });
1773
2115
  }
@@ -1777,11 +2119,12 @@ class MigrationsApi {
1777
2119
  database,
1778
2120
  branch,
1779
2121
  compare,
1780
- schema
2122
+ sourceBranchOperations,
2123
+ targetBranchOperations
1781
2124
  }) {
1782
2125
  return operationsByTag.migrations.compareBranchSchemas({
1783
2126
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1784
- body: { schema },
2127
+ body: { sourceBranchOperations, targetBranchOperations },
1785
2128
  ...this.extraProps
1786
2129
  });
1787
2130
  }
@@ -1824,6 +2167,19 @@ class MigrationsApi {
1824
2167
  ...this.extraProps
1825
2168
  });
1826
2169
  }
2170
+ pushBranchMigrations({
2171
+ workspace,
2172
+ region,
2173
+ database,
2174
+ branch,
2175
+ migrations
2176
+ }) {
2177
+ return operationsByTag.migrations.pushBranchMigrations({
2178
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2179
+ body: { migrations },
2180
+ ...this.extraProps
2181
+ });
2182
+ }
1827
2183
  }
1828
2184
  class DatabaseApi {
1829
2185
  constructor(extraProps) {
@@ -1875,6 +2231,35 @@ class DatabaseApi {
1875
2231
  ...this.extraProps
1876
2232
  });
1877
2233
  }
2234
+ getDatabaseGithubSettings({
2235
+ workspace,
2236
+ database
2237
+ }) {
2238
+ return operationsByTag.databases.getDatabaseGithubSettings({
2239
+ pathParams: { workspaceId: workspace, dbName: database },
2240
+ ...this.extraProps
2241
+ });
2242
+ }
2243
+ updateDatabaseGithubSettings({
2244
+ workspace,
2245
+ database,
2246
+ settings
2247
+ }) {
2248
+ return operationsByTag.databases.updateDatabaseGithubSettings({
2249
+ pathParams: { workspaceId: workspace, dbName: database },
2250
+ body: settings,
2251
+ ...this.extraProps
2252
+ });
2253
+ }
2254
+ deleteDatabaseGithubSettings({
2255
+ workspace,
2256
+ database
2257
+ }) {
2258
+ return operationsByTag.databases.deleteDatabaseGithubSettings({
2259
+ pathParams: { workspaceId: workspace, dbName: database },
2260
+ ...this.extraProps
2261
+ });
2262
+ }
1878
2263
  listRegions({ workspace }) {
1879
2264
  return operationsByTag.databases.listRegions({
1880
2265
  pathParams: { workspaceId: workspace },
@@ -1884,9 +2269,8 @@ class DatabaseApi {
1884
2269
  }
1885
2270
 
1886
2271
  class XataApiPlugin {
1887
- async build(options) {
1888
- const { fetchImpl, apiKey } = await options.getFetchProps();
1889
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2272
+ build(options) {
2273
+ return new XataApiClient(options);
1890
2274
  }
1891
2275
  }
1892
2276
 
@@ -1969,6 +2353,12 @@ const _RecordArray = class extends Array {
1969
2353
  toArray() {
1970
2354
  return new Array(...this);
1971
2355
  }
2356
+ toSerializable() {
2357
+ return JSON.parse(this.toString());
2358
+ }
2359
+ toString() {
2360
+ return JSON.stringify(this.toArray());
2361
+ }
1972
2362
  map(callbackfn, thisArg) {
1973
2363
  return this.toArray().map(callbackfn, thisArg);
1974
2364
  }
@@ -2294,10 +2684,7 @@ class RestRepository extends Query {
2294
2684
  __privateSet$4(this, _db, options.db);
2295
2685
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2296
2686
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2297
- __privateSet$4(this, _getFetchProps, async () => {
2298
- const props = await options.pluginOptions.getFetchProps();
2299
- return { ...props, sessionID: generateUUID() };
2300
- });
2687
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2301
2688
  const trace = options.pluginOptions.trace ?? defaultTrace;
2302
2689
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2303
2690
  return trace(name, fn, {
@@ -2354,7 +2741,6 @@ class RestRepository extends Query {
2354
2741
  }
2355
2742
  const id = extractId(a);
2356
2743
  if (id) {
2357
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2358
2744
  try {
2359
2745
  const response = await getRecord({
2360
2746
  pathParams: {
@@ -2365,7 +2751,7 @@ class RestRepository extends Query {
2365
2751
  recordId: id
2366
2752
  },
2367
2753
  queryParams: { columns },
2368
- ...fetchProps
2754
+ ...__privateGet$4(this, _getFetchProps).call(this)
2369
2755
  });
2370
2756
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2371
2757
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2543,7 +2929,6 @@ class RestRepository extends Query {
2543
2929
  }
2544
2930
  async search(query, options = {}) {
2545
2931
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2546
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2547
2932
  const { records } = await searchTable({
2548
2933
  pathParams: {
2549
2934
  workspace: "{workspaceId}",
@@ -2561,7 +2946,29 @@ class RestRepository extends Query {
2561
2946
  page: options.page,
2562
2947
  target: options.target
2563
2948
  },
2564
- ...fetchProps
2949
+ ...__privateGet$4(this, _getFetchProps).call(this)
2950
+ });
2951
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2952
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2953
+ });
2954
+ }
2955
+ async vectorSearch(column, query, options) {
2956
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2957
+ const { records } = await vectorSearchTable({
2958
+ pathParams: {
2959
+ workspace: "{workspaceId}",
2960
+ dbBranchName: "{dbBranch}",
2961
+ region: "{region}",
2962
+ tableName: __privateGet$4(this, _table)
2963
+ },
2964
+ body: {
2965
+ column,
2966
+ queryVector: query,
2967
+ similarityFunction: options?.similarityFunction,
2968
+ size: options?.size,
2969
+ filter: options?.filter
2970
+ },
2971
+ ...__privateGet$4(this, _getFetchProps).call(this)
2565
2972
  });
2566
2973
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2567
2974
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2569,7 +2976,6 @@ class RestRepository extends Query {
2569
2976
  }
2570
2977
  async aggregate(aggs, filter) {
2571
2978
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2572
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2573
2979
  const result = await aggregateTable({
2574
2980
  pathParams: {
2575
2981
  workspace: "{workspaceId}",
@@ -2578,7 +2984,7 @@ class RestRepository extends Query {
2578
2984
  tableName: __privateGet$4(this, _table)
2579
2985
  },
2580
2986
  body: { aggs, filter },
2581
- ...fetchProps
2987
+ ...__privateGet$4(this, _getFetchProps).call(this)
2582
2988
  });
2583
2989
  return result;
2584
2990
  });
@@ -2589,7 +2995,6 @@ class RestRepository extends Query {
2589
2995
  if (cacheQuery)
2590
2996
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2591
2997
  const data = query.getQueryOptions();
2592
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2593
2998
  const { meta, records: objects } = await queryTable({
2594
2999
  pathParams: {
2595
3000
  workspace: "{workspaceId}",
@@ -2605,7 +3010,7 @@ class RestRepository extends Query {
2605
3010
  consistency: data.consistency
2606
3011
  },
2607
3012
  fetchOptions: data.fetchOptions,
2608
- ...fetchProps
3013
+ ...__privateGet$4(this, _getFetchProps).call(this)
2609
3014
  });
2610
3015
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2611
3016
  const records = objects.map(
@@ -2618,7 +3023,6 @@ class RestRepository extends Query {
2618
3023
  async summarizeTable(query, summaries, summariesFilter) {
2619
3024
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2620
3025
  const data = query.getQueryOptions();
2621
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2622
3026
  const result = await summarizeTable({
2623
3027
  pathParams: {
2624
3028
  workspace: "{workspaceId}",
@@ -2635,11 +3039,39 @@ class RestRepository extends Query {
2635
3039
  summaries,
2636
3040
  summariesFilter
2637
3041
  },
2638
- ...fetchProps
3042
+ ...__privateGet$4(this, _getFetchProps).call(this)
2639
3043
  });
2640
3044
  return result;
2641
3045
  });
2642
3046
  }
3047
+ ask(question, options) {
3048
+ const params = {
3049
+ pathParams: {
3050
+ workspace: "{workspaceId}",
3051
+ dbBranchName: "{dbBranch}",
3052
+ region: "{region}",
3053
+ tableName: __privateGet$4(this, _table)
3054
+ },
3055
+ body: {
3056
+ question,
3057
+ ...options
3058
+ },
3059
+ ...__privateGet$4(this, _getFetchProps).call(this)
3060
+ };
3061
+ if (options?.onMessage) {
3062
+ fetchSSERequest({
3063
+ endpoint: "dataPlane",
3064
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
3065
+ method: "POST",
3066
+ onMessage: (message) => {
3067
+ options.onMessage?.({ answer: message.text, records: message.records });
3068
+ },
3069
+ ...params
3070
+ });
3071
+ } else {
3072
+ return askTable(params);
3073
+ }
3074
+ }
2643
3075
  }
2644
3076
  _table = new WeakMap();
2645
3077
  _getFetchProps = new WeakMap();
@@ -2649,7 +3081,6 @@ _schemaTables$2 = new WeakMap();
2649
3081
  _trace = new WeakMap();
2650
3082
  _insertRecordWithoutId = new WeakSet();
2651
3083
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2652
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2653
3084
  const record = transformObjectLinks(object);
2654
3085
  const response = await insertRecord({
2655
3086
  pathParams: {
@@ -2660,14 +3091,13 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2660
3091
  },
2661
3092
  queryParams: { columns },
2662
3093
  body: record,
2663
- ...fetchProps
3094
+ ...__privateGet$4(this, _getFetchProps).call(this)
2664
3095
  });
2665
3096
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2666
3097
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2667
3098
  };
2668
3099
  _insertRecordWithId = new WeakSet();
2669
3100
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2670
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2671
3101
  const record = transformObjectLinks(object);
2672
3102
  const response = await insertRecordWithID({
2673
3103
  pathParams: {
@@ -2679,14 +3109,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2679
3109
  },
2680
3110
  body: record,
2681
3111
  queryParams: { createOnly, columns, ifVersion },
2682
- ...fetchProps
3112
+ ...__privateGet$4(this, _getFetchProps).call(this)
2683
3113
  });
2684
3114
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2685
3115
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2686
3116
  };
2687
3117
  _insertRecords = new WeakSet();
2688
3118
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2689
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2690
3119
  const chunkedOperations = chunk(
2691
3120
  objects.map((object) => ({
2692
3121
  insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
@@ -2702,7 +3131,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2702
3131
  region: "{region}"
2703
3132
  },
2704
3133
  body: { operations },
2705
- ...fetchProps
3134
+ ...__privateGet$4(this, _getFetchProps).call(this)
2706
3135
  });
2707
3136
  for (const result of results) {
2708
3137
  if (result.operation === "insert") {
@@ -2716,7 +3145,6 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2716
3145
  };
2717
3146
  _updateRecordWithID = new WeakSet();
2718
3147
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2719
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2720
3148
  const { id: _id, ...record } = transformObjectLinks(object);
2721
3149
  try {
2722
3150
  const response = await updateRecordWithID({
@@ -2729,7 +3157,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2729
3157
  },
2730
3158
  queryParams: { columns, ifVersion },
2731
3159
  body: record,
2732
- ...fetchProps
3160
+ ...__privateGet$4(this, _getFetchProps).call(this)
2733
3161
  });
2734
3162
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2735
3163
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2742,7 +3170,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2742
3170
  };
2743
3171
  _updateRecords = new WeakSet();
2744
3172
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2745
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2746
3173
  const chunkedOperations = chunk(
2747
3174
  objects.map(({ id, ...object }) => ({
2748
3175
  update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
@@ -2758,7 +3185,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2758
3185
  region: "{region}"
2759
3186
  },
2760
3187
  body: { operations },
2761
- ...fetchProps
3188
+ ...__privateGet$4(this, _getFetchProps).call(this)
2762
3189
  });
2763
3190
  for (const result of results) {
2764
3191
  if (result.operation === "update") {
@@ -2772,7 +3199,6 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2772
3199
  };
2773
3200
  _upsertRecordWithID = new WeakSet();
2774
3201
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2775
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2776
3202
  const response = await upsertRecordWithID({
2777
3203
  pathParams: {
2778
3204
  workspace: "{workspaceId}",
@@ -2783,14 +3209,13 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2783
3209
  },
2784
3210
  queryParams: { columns, ifVersion },
2785
3211
  body: object,
2786
- ...fetchProps
3212
+ ...__privateGet$4(this, _getFetchProps).call(this)
2787
3213
  });
2788
3214
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2789
3215
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2790
3216
  };
2791
3217
  _deleteRecord = new WeakSet();
2792
3218
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2793
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2794
3219
  try {
2795
3220
  const response = await deleteRecord({
2796
3221
  pathParams: {
@@ -2801,7 +3226,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2801
3226
  recordId
2802
3227
  },
2803
3228
  queryParams: { columns },
2804
- ...fetchProps
3229
+ ...__privateGet$4(this, _getFetchProps).call(this)
2805
3230
  });
2806
3231
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2807
3232
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2814,7 +3239,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2814
3239
  };
2815
3240
  _deleteRecords = new WeakSet();
2816
3241
  deleteRecords_fn = async function(recordIds) {
2817
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2818
3242
  const chunkedOperations = chunk(
2819
3243
  recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2820
3244
  BULK_OPERATION_MAX_SIZE
@@ -2827,21 +3251,22 @@ deleteRecords_fn = async function(recordIds) {
2827
3251
  region: "{region}"
2828
3252
  },
2829
3253
  body: { operations },
2830
- ...fetchProps
3254
+ ...__privateGet$4(this, _getFetchProps).call(this)
2831
3255
  });
2832
3256
  }
2833
3257
  };
2834
3258
  _setCacheQuery = new WeakSet();
2835
3259
  setCacheQuery_fn = async function(query, meta, records) {
2836
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
3260
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2837
3261
  };
2838
3262
  _getCacheQuery = new WeakSet();
2839
3263
  getCacheQuery_fn = async function(query) {
2840
3264
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2841
- const result = await __privateGet$4(this, _cache).get(key);
3265
+ const result = await __privateGet$4(this, _cache)?.get(key);
2842
3266
  if (!result)
2843
3267
  return null;
2844
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
3268
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
3269
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2845
3270
  if (ttl < 0)
2846
3271
  return null;
2847
3272
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2851,10 +3276,9 @@ _getSchemaTables$1 = new WeakSet();
2851
3276
  getSchemaTables_fn$1 = async function() {
2852
3277
  if (__privateGet$4(this, _schemaTables$2))
2853
3278
  return __privateGet$4(this, _schemaTables$2);
2854
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2855
3279
  const { schema } = await getBranchDetails({
2856
3280
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2857
- ...fetchProps
3281
+ ...__privateGet$4(this, _getFetchProps).call(this)
2858
3282
  });
2859
3283
  __privateSet$4(this, _schemaTables$2, schema.tables);
2860
3284
  return schema.tables;
@@ -2936,10 +3360,13 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2936
3360
  record.getMetadata = function() {
2937
3361
  return xata;
2938
3362
  };
2939
- record.toJSON = function() {
3363
+ record.toSerializable = function() {
2940
3364
  return JSON.parse(JSON.stringify(transformObjectLinks(data)));
2941
3365
  };
2942
- for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toJSON"]) {
3366
+ record.toString = function() {
3367
+ return JSON.stringify(transformObjectLinks(data));
3368
+ };
3369
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
2943
3370
  Object.defineProperty(record, prop, { enumerable: false });
2944
3371
  }
2945
3372
  Object.freeze(record);
@@ -3127,19 +3554,19 @@ class SearchPlugin extends XataPlugin {
3127
3554
  __privateAdd$1(this, _schemaTables, void 0);
3128
3555
  __privateSet$1(this, _schemaTables, schemaTables);
3129
3556
  }
3130
- build({ getFetchProps }) {
3557
+ build(pluginOptions) {
3131
3558
  return {
3132
3559
  all: async (query, options = {}) => {
3133
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3134
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3560
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3561
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3135
3562
  return records.map((record) => {
3136
3563
  const { table = "orphan" } = record.xata;
3137
3564
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3138
3565
  });
3139
3566
  },
3140
3567
  byTable: async (query, options = {}) => {
3141
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3142
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3568
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3569
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3143
3570
  return records.reduce((acc, record) => {
3144
3571
  const { table = "orphan" } = record.xata;
3145
3572
  const items = acc[table] ?? [];
@@ -3152,38 +3579,35 @@ class SearchPlugin extends XataPlugin {
3152
3579
  }
3153
3580
  _schemaTables = new WeakMap();
3154
3581
  _search = new WeakSet();
3155
- search_fn = async function(query, options, getFetchProps) {
3156
- const fetchProps = await getFetchProps();
3582
+ search_fn = async function(query, options, pluginOptions) {
3157
3583
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3158
3584
  const { records } = await searchBranch({
3159
3585
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3160
3586
  body: { tables, query, fuzziness, prefix, highlight, page },
3161
- ...fetchProps
3587
+ ...pluginOptions
3162
3588
  });
3163
3589
  return records;
3164
3590
  };
3165
3591
  _getSchemaTables = new WeakSet();
3166
- getSchemaTables_fn = async function(getFetchProps) {
3592
+ getSchemaTables_fn = async function(pluginOptions) {
3167
3593
  if (__privateGet$1(this, _schemaTables))
3168
3594
  return __privateGet$1(this, _schemaTables);
3169
- const fetchProps = await getFetchProps();
3170
3595
  const { schema } = await getBranchDetails({
3171
3596
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3172
- ...fetchProps
3597
+ ...pluginOptions
3173
3598
  });
3174
3599
  __privateSet$1(this, _schemaTables, schema.tables);
3175
3600
  return schema.tables;
3176
3601
  };
3177
3602
 
3178
3603
  class TransactionPlugin extends XataPlugin {
3179
- build({ getFetchProps }) {
3604
+ build(pluginOptions) {
3180
3605
  return {
3181
3606
  run: async (operations) => {
3182
- const fetchProps = await getFetchProps();
3183
3607
  const response = await branchTransaction({
3184
3608
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3185
3609
  body: { operations },
3186
- ...fetchProps
3610
+ ...pluginOptions
3187
3611
  });
3188
3612
  return response;
3189
3613
  }
@@ -3191,90 +3615,6 @@ class TransactionPlugin extends XataPlugin {
3191
3615
  }
3192
3616
  }
3193
3617
 
3194
- const isBranchStrategyBuilder = (strategy) => {
3195
- return typeof strategy === "function";
3196
- };
3197
-
3198
- async function getCurrentBranchName(options) {
3199
- const { branch, envBranch } = getEnvironment();
3200
- if (branch)
3201
- return branch;
3202
- const gitBranch = envBranch || await getGitBranch();
3203
- return resolveXataBranch(gitBranch, options);
3204
- }
3205
- async function getCurrentBranchDetails(options) {
3206
- const branch = await getCurrentBranchName(options);
3207
- return getDatabaseBranch(branch, options);
3208
- }
3209
- async function resolveXataBranch(gitBranch, options) {
3210
- const databaseURL = options?.databaseURL || getDatabaseURL();
3211
- const apiKey = options?.apiKey || getAPIKey();
3212
- if (!databaseURL)
3213
- throw new Error(
3214
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3215
- );
3216
- if (!apiKey)
3217
- throw new Error(
3218
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3219
- );
3220
- const [protocol, , host, , dbName] = databaseURL.split("/");
3221
- const urlParts = parseWorkspacesUrlParts(host);
3222
- if (!urlParts)
3223
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3224
- const { workspace, region } = urlParts;
3225
- const { fallbackBranch } = getEnvironment();
3226
- const { branch } = await resolveBranch({
3227
- apiKey,
3228
- apiUrl: databaseURL,
3229
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3230
- workspacesApiUrl: `${protocol}//${host}`,
3231
- pathParams: { dbName, workspace, region },
3232
- queryParams: { gitBranch, fallbackBranch },
3233
- trace: defaultTrace,
3234
- clientName: options?.clientName
3235
- });
3236
- return branch;
3237
- }
3238
- async function getDatabaseBranch(branch, options) {
3239
- const databaseURL = options?.databaseURL || getDatabaseURL();
3240
- const apiKey = options?.apiKey || getAPIKey();
3241
- if (!databaseURL)
3242
- throw new Error(
3243
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3244
- );
3245
- if (!apiKey)
3246
- throw new Error(
3247
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3248
- );
3249
- const [protocol, , host, , database] = databaseURL.split("/");
3250
- const urlParts = parseWorkspacesUrlParts(host);
3251
- if (!urlParts)
3252
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3253
- const { workspace, region } = urlParts;
3254
- try {
3255
- return await getBranchDetails({
3256
- apiKey,
3257
- apiUrl: databaseURL,
3258
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3259
- workspacesApiUrl: `${protocol}//${host}`,
3260
- pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3261
- trace: defaultTrace
3262
- });
3263
- } catch (err) {
3264
- if (isObject(err) && err.status === 404)
3265
- return null;
3266
- throw err;
3267
- }
3268
- }
3269
- function getDatabaseURL() {
3270
- try {
3271
- const { databaseURL } = getEnvironment();
3272
- return databaseURL;
3273
- } catch (err) {
3274
- return void 0;
3275
- }
3276
- }
3277
-
3278
3618
  var __accessCheck = (obj, member, msg) => {
3279
3619
  if (!member.has(obj))
3280
3620
  throw TypeError("Cannot " + msg);
@@ -3298,20 +3638,18 @@ var __privateMethod = (obj, member, method) => {
3298
3638
  return method;
3299
3639
  };
3300
3640
  const buildClient = (plugins) => {
3301
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3641
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3302
3642
  return _a = class {
3303
3643
  constructor(options = {}, schemaTables) {
3304
3644
  __privateAdd(this, _parseOptions);
3305
3645
  __privateAdd(this, _getFetchProps);
3306
- __privateAdd(this, _evaluateBranch);
3307
- __privateAdd(this, _branch, void 0);
3308
3646
  __privateAdd(this, _options, void 0);
3309
3647
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3310
3648
  __privateSet(this, _options, safeOptions);
3311
3649
  const pluginOptions = {
3312
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3650
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3313
3651
  cache: safeOptions.cache,
3314
- trace: safeOptions.trace
3652
+ host: safeOptions.host
3315
3653
  };
3316
3654
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3317
3655
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -3322,22 +3660,15 @@ const buildClient = (plugins) => {
3322
3660
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3323
3661
  if (namespace === void 0)
3324
3662
  continue;
3325
- const result = namespace.build(pluginOptions);
3326
- if (result instanceof Promise) {
3327
- void result.then((namespace2) => {
3328
- this[key] = namespace2;
3329
- });
3330
- } else {
3331
- this[key] = result;
3332
- }
3663
+ this[key] = namespace.build(pluginOptions);
3333
3664
  }
3334
3665
  }
3335
3666
  async getConfig() {
3336
3667
  const databaseURL = __privateGet(this, _options).databaseURL;
3337
- const branch = await __privateGet(this, _options).branch();
3668
+ const branch = __privateGet(this, _options).branch;
3338
3669
  return { databaseURL, branch };
3339
3670
  }
3340
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3671
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3341
3672
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3342
3673
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3343
3674
  if (isBrowser && !enableBrowser) {
@@ -3351,60 +3682,71 @@ const buildClient = (plugins) => {
3351
3682
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3352
3683
  const trace = options?.trace ?? defaultTrace;
3353
3684
  const clientName = options?.clientName;
3354
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3355
- apiKey,
3356
- databaseURL,
3357
- fetchImpl: options?.fetch,
3358
- clientName: options?.clientName
3359
- });
3685
+ const host = options?.host ?? "production";
3686
+ const xataAgentExtra = options?.xataAgentExtra;
3360
3687
  if (!apiKey) {
3361
3688
  throw new Error("Option apiKey is required");
3362
3689
  }
3363
3690
  if (!databaseURL) {
3364
3691
  throw new Error("Option databaseURL is required");
3365
3692
  }
3366
- return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
3367
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3693
+ const envBranch = getBranch();
3694
+ const previewBranch = getPreviewBranch();
3695
+ const branch = options?.branch || previewBranch || envBranch || "main";
3696
+ if (!!previewBranch && branch !== previewBranch) {
3697
+ console.warn(
3698
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
3699
+ );
3700
+ } else if (!!envBranch && branch !== envBranch) {
3701
+ console.warn(
3702
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3703
+ );
3704
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
3705
+ console.warn(
3706
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3707
+ );
3708
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
3709
+ console.warn(
3710
+ `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.`
3711
+ );
3712
+ }
3713
+ return {
3714
+ fetch,
3715
+ databaseURL,
3716
+ apiKey,
3717
+ branch,
3718
+ cache,
3719
+ trace,
3720
+ host,
3721
+ clientID: generateUUID(),
3722
+ enableBrowser,
3723
+ clientName,
3724
+ xataAgentExtra
3725
+ };
3726
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3368
3727
  fetch,
3369
3728
  apiKey,
3370
3729
  databaseURL,
3371
3730
  branch,
3372
3731
  trace,
3373
3732
  clientID,
3374
- clientName
3733
+ clientName,
3734
+ xataAgentExtra
3375
3735
  }) {
3376
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3377
- if (!branchValue)
3378
- throw new Error("Unable to resolve branch value");
3379
3736
  return {
3380
- fetchImpl: fetch,
3737
+ fetch,
3381
3738
  apiKey,
3382
3739
  apiUrl: "",
3383
3740
  workspacesApiUrl: (path, params) => {
3384
3741
  const hasBranch = params.dbBranchName ?? params.branch;
3385
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
3742
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3386
3743
  return databaseURL + newPath;
3387
3744
  },
3388
3745
  trace,
3389
3746
  clientID,
3390
- clientName
3391
- };
3392
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3393
- if (__privateGet(this, _branch))
3394
- return __privateGet(this, _branch);
3395
- if (param === void 0)
3396
- return void 0;
3397
- const strategies = Array.isArray(param) ? [...param] : [param];
3398
- const evaluateBranch = async (strategy) => {
3399
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3747
+ clientName,
3748
+ xataAgentExtra
3400
3749
  };
3401
- for await (const strategy of strategies) {
3402
- const branch = await evaluateBranch(strategy);
3403
- if (branch) {
3404
- __privateSet(this, _branch, branch);
3405
- return branch;
3406
- }
3407
- }
3408
3750
  }, _a;
3409
3751
  };
3410
3752
  class BaseClient extends buildClient() {
@@ -3524,8 +3866,11 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
3524
3866
  exports.addTableColumn = addTableColumn;
3525
3867
  exports.aggregateTable = aggregateTable;
3526
3868
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3869
+ exports.askTable = askTable;
3527
3870
  exports.branchTransaction = branchTransaction;
3528
3871
  exports.buildClient = buildClient;
3872
+ exports.buildPreviewBranchName = buildPreviewBranchName;
3873
+ exports.buildProviderString = buildProviderString;
3529
3874
  exports.buildWorkerRunner = buildWorkerRunner;
3530
3875
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
3531
3876
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
@@ -3533,6 +3878,7 @@ exports.compareBranchSchemas = compareBranchSchemas;
3533
3878
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3534
3879
  exports.compareMigrationRequest = compareMigrationRequest;
3535
3880
  exports.contains = contains;
3881
+ exports.copyBranch = copyBranch;
3536
3882
  exports.createBranch = createBranch;
3537
3883
  exports.createDatabase = createDatabase;
3538
3884
  exports.createMigrationRequest = createMigrationRequest;
@@ -3542,6 +3888,7 @@ exports.createWorkspace = createWorkspace;
3542
3888
  exports.deleteBranch = deleteBranch;
3543
3889
  exports.deleteColumn = deleteColumn;
3544
3890
  exports.deleteDatabase = deleteDatabase;
3891
+ exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
3545
3892
  exports.deleteRecord = deleteRecord;
3546
3893
  exports.deleteTable = deleteTable;
3547
3894
  exports.deleteUser = deleteUser;
@@ -3554,6 +3901,7 @@ exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
3554
3901
  exports.exists = exists;
3555
3902
  exports.ge = ge;
3556
3903
  exports.getAPIKey = getAPIKey;
3904
+ exports.getBranch = getBranch;
3557
3905
  exports.getBranchDetails = getBranchDetails;
3558
3906
  exports.getBranchList = getBranchList;
3559
3907
  exports.getBranchMetadata = getBranchMetadata;
@@ -3562,8 +3910,7 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
3562
3910
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
3563
3911
  exports.getBranchStats = getBranchStats;
3564
3912
  exports.getColumn = getColumn;
3565
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
3566
- exports.getCurrentBranchName = getCurrentBranchName;
3913
+ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3567
3914
  exports.getDatabaseList = getDatabaseList;
3568
3915
  exports.getDatabaseMetadata = getDatabaseMetadata;
3569
3916
  exports.getDatabaseURL = getDatabaseURL;
@@ -3571,6 +3918,7 @@ exports.getGitBranchesMapping = getGitBranchesMapping;
3571
3918
  exports.getHostUrl = getHostUrl;
3572
3919
  exports.getMigrationRequest = getMigrationRequest;
3573
3920
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
3921
+ exports.getPreviewBranch = getPreviewBranch;
3574
3922
  exports.getRecord = getRecord;
3575
3923
  exports.getTableColumns = getTableColumns;
3576
3924
  exports.getTableSchema = getTableSchema;
@@ -3613,6 +3961,7 @@ exports.parseProviderString = parseProviderString;
3613
3961
  exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
3614
3962
  exports.pattern = pattern;
3615
3963
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3964
+ exports.pushBranchMigrations = pushBranchMigrations;
3616
3965
  exports.queryMigrationRequests = queryMigrationRequests;
3617
3966
  exports.queryTable = queryTable;
3618
3967
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
@@ -3623,11 +3972,13 @@ exports.searchBranch = searchBranch;
3623
3972
  exports.searchTable = searchTable;
3624
3973
  exports.serialize = serialize;
3625
3974
  exports.setTableSchema = setTableSchema;
3975
+ exports.sqlQuery = sqlQuery;
3626
3976
  exports.startsWith = startsWith;
3627
3977
  exports.summarizeTable = summarizeTable;
3628
3978
  exports.updateBranchMetadata = updateBranchMetadata;
3629
3979
  exports.updateBranchSchema = updateBranchSchema;
3630
3980
  exports.updateColumn = updateColumn;
3981
+ exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
3631
3982
  exports.updateDatabaseMetadata = updateDatabaseMetadata;
3632
3983
  exports.updateMigrationRequest = updateMigrationRequest;
3633
3984
  exports.updateRecordWithID = updateRecordWithID;
@@ -3637,4 +3988,5 @@ exports.updateWorkspace = updateWorkspace;
3637
3988
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
3638
3989
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
3639
3990
  exports.upsertRecordWithID = upsertRecordWithID;
3991
+ exports.vectorSearchTable = vectorSearchTable;
3640
3992
  //# sourceMappingURL=index.cjs.map