@xata.io/client 0.0.0-alpha.vf81a0c6 → 0.0.0-alpha.vf864fe862f895317faad5b0041a40e871fe5ad03

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
@@ -18,7 +18,8 @@ const TraceAttributes = {
18
18
  HTTP_METHOD: "http.method",
19
19
  HTTP_URL: "http.url",
20
20
  HTTP_ROUTE: "http.route",
21
- HTTP_TARGET: "http.target"
21
+ HTTP_TARGET: "http.target",
22
+ CLOUDFLARE_RAY_ID: "cf.ray"
22
23
  };
23
24
 
24
25
  function notEmpty(value) {
@@ -27,8 +28,18 @@ function notEmpty(value) {
27
28
  function compact(arr) {
28
29
  return arr.filter(notEmpty);
29
30
  }
31
+ function compactObject(obj) {
32
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
33
+ }
34
+ function isBlob(value) {
35
+ try {
36
+ return value instanceof Blob;
37
+ } catch (error) {
38
+ return false;
39
+ }
40
+ }
30
41
  function isObject(value) {
31
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
42
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
32
43
  }
33
44
  function isDefined(value) {
34
45
  return value !== null && value !== void 0;
@@ -83,6 +94,27 @@ function chunk(array, chunkSize) {
83
94
  async function timeout(ms) {
84
95
  return new Promise((resolve) => setTimeout(resolve, ms));
85
96
  }
97
+ function timeoutWithCancel(ms) {
98
+ let timeoutId;
99
+ const promise = new Promise((resolve) => {
100
+ timeoutId = setTimeout(() => {
101
+ resolve();
102
+ }, ms);
103
+ });
104
+ return {
105
+ cancel: () => clearTimeout(timeoutId),
106
+ promise
107
+ };
108
+ }
109
+ function promiseMap(inputValues, mapper) {
110
+ const reducer = (acc$, inputValue) => acc$.then(
111
+ (acc) => mapper(inputValue).then((result) => {
112
+ acc.push(result);
113
+ return acc;
114
+ })
115
+ );
116
+ return inputValues.reduce(reducer, Promise.resolve([]));
117
+ }
86
118
 
87
119
  function getEnvironment() {
88
120
  try {
@@ -182,7 +214,7 @@ function getAPIKey() {
182
214
  function getBranch() {
183
215
  try {
184
216
  const { branch } = getEnvironment();
185
- return branch ?? "main";
217
+ return branch;
186
218
  } catch (err) {
187
219
  return void 0;
188
220
  }
@@ -214,7 +246,7 @@ var __accessCheck$8 = (obj, member, msg) => {
214
246
  if (!member.has(obj))
215
247
  throw TypeError("Cannot " + msg);
216
248
  };
217
- var __privateGet$8 = (obj, member, getter) => {
249
+ var __privateGet$7 = (obj, member, getter) => {
218
250
  __accessCheck$8(obj, member, "read from private field");
219
251
  return getter ? getter.call(obj) : member.get(obj);
220
252
  };
@@ -223,7 +255,7 @@ var __privateAdd$8 = (obj, member, value) => {
223
255
  throw TypeError("Cannot add the same private member more than once");
224
256
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
225
257
  };
226
- var __privateSet$8 = (obj, member, value, setter) => {
258
+ var __privateSet$6 = (obj, member, value, setter) => {
227
259
  __accessCheck$8(obj, member, "write to private field");
228
260
  setter ? setter.call(obj, value) : member.set(obj, value);
229
261
  return value;
@@ -233,13 +265,13 @@ var __privateMethod$4 = (obj, member, method) => {
233
265
  return method;
234
266
  };
235
267
  var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
268
+ const REQUEST_TIMEOUT = 5 * 60 * 1e3;
236
269
  function getFetchImplementation(userFetch) {
237
270
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
238
- const fetchImpl = userFetch ?? globalFetch;
271
+ const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
272
+ const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
239
273
  if (!fetchImpl) {
240
- throw new Error(
241
- `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
242
- );
274
+ throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
243
275
  }
244
276
  return fetchImpl;
245
277
  }
@@ -249,33 +281,37 @@ class ApiRequestPool {
249
281
  __privateAdd$8(this, _fetch, void 0);
250
282
  __privateAdd$8(this, _queue, void 0);
251
283
  __privateAdd$8(this, _concurrency, void 0);
252
- __privateSet$8(this, _queue, []);
253
- __privateSet$8(this, _concurrency, concurrency);
284
+ __privateSet$6(this, _queue, []);
285
+ __privateSet$6(this, _concurrency, concurrency);
254
286
  this.running = 0;
255
287
  this.started = 0;
256
288
  }
257
289
  setFetch(fetch2) {
258
- __privateSet$8(this, _fetch, fetch2);
290
+ __privateSet$6(this, _fetch, fetch2);
259
291
  }
260
292
  getFetch() {
261
- if (!__privateGet$8(this, _fetch)) {
293
+ if (!__privateGet$7(this, _fetch)) {
262
294
  throw new Error("Fetch not set");
263
295
  }
264
- return __privateGet$8(this, _fetch);
296
+ return __privateGet$7(this, _fetch);
265
297
  }
266
298
  request(url, options) {
267
- const start = new Date();
268
- const fetch2 = this.getFetch();
299
+ const start = /* @__PURE__ */ new Date();
300
+ const fetchImpl = this.getFetch();
269
301
  const runRequest = async (stalled = false) => {
270
- const response = await fetch2(url, options);
302
+ const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
303
+ const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
304
+ if (!response) {
305
+ throw new Error("Request timed out");
306
+ }
271
307
  if (response.status === 429) {
272
308
  const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
273
309
  await timeout(rateLimitReset * 1e3);
274
310
  return await runRequest(true);
275
311
  }
276
312
  if (stalled) {
277
- const stalledTime = new Date().getTime() - start.getTime();
278
- console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
313
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
314
+ console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
279
315
  }
280
316
  return response;
281
317
  };
@@ -289,19 +325,19 @@ _queue = new WeakMap();
289
325
  _concurrency = new WeakMap();
290
326
  _enqueue = new WeakSet();
291
327
  enqueue_fn = function(task) {
292
- const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
328
+ const promise = new Promise((resolve) => __privateGet$7(this, _queue).push(resolve)).finally(() => {
293
329
  this.started--;
294
330
  this.running++;
295
331
  }).then(() => task()).finally(() => {
296
332
  this.running--;
297
- const next = __privateGet$8(this, _queue).shift();
333
+ const next = __privateGet$7(this, _queue).shift();
298
334
  if (next !== void 0) {
299
335
  this.started++;
300
336
  next();
301
337
  }
302
338
  });
303
- if (this.running + this.started < __privateGet$8(this, _concurrency)) {
304
- const next = __privateGet$8(this, _queue).shift();
339
+ if (this.running + this.started < __privateGet$7(this, _concurrency)) {
340
+ const next = __privateGet$7(this, _queue).shift();
305
341
  if (next !== void 0) {
306
342
  this.started++;
307
343
  next();
@@ -490,7 +526,7 @@ function defaultOnOpen(response) {
490
526
  }
491
527
  }
492
528
 
493
- const VERSION = "0.23.5";
529
+ const VERSION = "0.29.0";
494
530
 
495
531
  class ErrorWithCause extends Error {
496
532
  constructor(message, options) {
@@ -533,6 +569,67 @@ function getMessage(data) {
533
569
  }
534
570
  }
535
571
 
572
+ function getHostUrl(provider, type) {
573
+ if (isHostProviderAlias(provider)) {
574
+ return providers[provider][type];
575
+ } else if (isHostProviderBuilder(provider)) {
576
+ return provider[type];
577
+ }
578
+ throw new Error("Invalid API provider");
579
+ }
580
+ const providers = {
581
+ production: {
582
+ main: "https://api.xata.io",
583
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
584
+ },
585
+ staging: {
586
+ main: "https://api.staging-xata.dev",
587
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
588
+ },
589
+ dev: {
590
+ main: "https://api.dev-xata.dev",
591
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
592
+ },
593
+ local: {
594
+ main: "http://localhost:6001",
595
+ workspaces: "http://{workspaceId}.{region}.localhost:6001"
596
+ }
597
+ };
598
+ function isHostProviderAlias(alias) {
599
+ return isString(alias) && Object.keys(providers).includes(alias);
600
+ }
601
+ function isHostProviderBuilder(builder) {
602
+ return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
603
+ }
604
+ function parseProviderString(provider = "production") {
605
+ if (isHostProviderAlias(provider)) {
606
+ return provider;
607
+ }
608
+ const [main, workspaces] = provider.split(",");
609
+ if (!main || !workspaces)
610
+ return null;
611
+ return { main, workspaces };
612
+ }
613
+ function buildProviderString(provider) {
614
+ if (isHostProviderAlias(provider))
615
+ return provider;
616
+ return `${provider.main},${provider.workspaces}`;
617
+ }
618
+ function parseWorkspacesUrlParts(url) {
619
+ if (!isString(url))
620
+ return null;
621
+ const matches = {
622
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
623
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
624
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
625
+ local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
626
+ };
627
+ const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
628
+ if (!isHostProviderAlias(host) || !match)
629
+ return null;
630
+ return { workspace: match[1], region: match[2], host };
631
+ }
632
+
536
633
  const pool = new ApiRequestPool();
537
634
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
538
635
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
@@ -548,6 +645,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
548
645
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
549
646
  };
550
647
  function buildBaseUrl({
648
+ method,
551
649
  endpoint,
552
650
  path,
553
651
  workspacesApiUrl,
@@ -555,7 +653,24 @@ function buildBaseUrl({
555
653
  pathParams = {}
556
654
  }) {
557
655
  if (endpoint === "dataPlane") {
558
- const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
656
+ let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
657
+ if (method.toUpperCase() === "PUT" && [
658
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
659
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
660
+ ].includes(path)) {
661
+ const { host } = parseWorkspacesUrlParts(url) ?? {};
662
+ switch (host) {
663
+ case "production":
664
+ url = url.replace("xata.sh", "upload.xata.sh");
665
+ break;
666
+ case "staging":
667
+ url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
668
+ break;
669
+ case "dev":
670
+ url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
671
+ break;
672
+ }
673
+ }
559
674
  const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
560
675
  return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
561
676
  }
@@ -566,6 +681,18 @@ function hostHeader(url) {
566
681
  const { groups } = pattern.exec(url) ?? {};
567
682
  return groups?.host ? { Host: groups.host } : {};
568
683
  }
684
+ async function parseBody(body, headers) {
685
+ if (!isDefined(body))
686
+ return void 0;
687
+ if (isBlob(body) || typeof body.text === "function") {
688
+ return body;
689
+ }
690
+ const { "Content-Type": contentType } = headers ?? {};
691
+ if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
692
+ return JSON.stringify(body);
693
+ }
694
+ return body;
695
+ }
569
696
  const defaultClientID = generateUUID();
570
697
  async function fetch$1({
571
698
  url: path,
@@ -585,15 +712,16 @@ async function fetch$1({
585
712
  sessionID,
586
713
  clientName,
587
714
  xataAgentExtra,
588
- fetchOptions = {}
715
+ fetchOptions = {},
716
+ rawResponse = false
589
717
  }) {
590
718
  pool.setFetch(fetch2);
591
719
  return await trace(
592
720
  `${method.toUpperCase()} ${path}`,
593
721
  async ({ setAttributes }) => {
594
- const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
722
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
595
723
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
596
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
724
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
597
725
  setAttributes({
598
726
  [TraceAttributes.HTTP_URL]: url,
599
727
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
@@ -604,7 +732,7 @@ async function fetch$1({
604
732
  isDefined(clientName) ? ["service", clientName] : void 0,
605
733
  ...Object.entries(xataAgentExtra ?? {})
606
734
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
607
- const headers = {
735
+ const headers = compactObject({
608
736
  "Accept-Encoding": "identity",
609
737
  "Content-Type": "application/json",
610
738
  "X-Xata-Client-ID": clientID ?? defaultClientID,
@@ -613,11 +741,11 @@ async function fetch$1({
613
741
  ...customHeaders,
614
742
  ...hostHeader(fullUrl),
615
743
  Authorization: `Bearer ${apiKey}`
616
- };
744
+ });
617
745
  const response = await pool.request(url, {
618
746
  ...fetchOptions,
619
747
  method: method.toUpperCase(),
620
- body: body ? JSON.stringify(body) : void 0,
748
+ body: await parseBody(body, headers),
621
749
  headers,
622
750
  signal
623
751
  });
@@ -628,8 +756,12 @@ async function fetch$1({
628
756
  [TraceAttributes.HTTP_REQUEST_ID]: requestId,
629
757
  [TraceAttributes.HTTP_STATUS_CODE]: response.status,
630
758
  [TraceAttributes.HTTP_HOST]: host,
631
- [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
759
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
760
+ [TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
632
761
  });
762
+ const message = response.headers?.get("x-xata-message");
763
+ if (message)
764
+ console.warn(message);
633
765
  if (response.status === 204) {
634
766
  return {};
635
767
  }
@@ -637,7 +769,7 @@ async function fetch$1({
637
769
  throw new FetcherError(response.status, "Rate limit exceeded", requestId);
638
770
  }
639
771
  try {
640
- const jsonResponse = await response.json();
772
+ const jsonResponse = rawResponse ? await response.blob() : await response.json();
641
773
  if (response.ok) {
642
774
  return jsonResponse;
643
775
  }
@@ -670,7 +802,7 @@ function fetchSSERequest({
670
802
  clientName,
671
803
  xataAgentExtra
672
804
  }) {
673
- const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
805
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
674
806
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
675
807
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
676
808
  void fetchEventSource(url, {
@@ -713,6 +845,20 @@ function parseUrl(url) {
713
845
 
714
846
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
715
847
 
848
+ const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
849
+ const pgRollStatus = (variables, signal) => dataPlaneFetch({
850
+ url: "/db/{dbBranchName}/pgroll/status",
851
+ method: "get",
852
+ ...variables,
853
+ signal
854
+ });
855
+ const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
856
+ url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
857
+ method: "get",
858
+ ...variables,
859
+ signal
860
+ });
861
+ const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
716
862
  const getBranchList = (variables, signal) => dataPlaneFetch({
717
863
  url: "/dbs/{dbName}",
718
864
  method: "get",
@@ -732,6 +878,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
732
878
  ...variables,
733
879
  signal
734
880
  });
881
+ const getSchema = (variables, signal) => dataPlaneFetch({
882
+ url: "/db/{dbBranchName}/schema",
883
+ method: "get",
884
+ ...variables,
885
+ signal
886
+ });
735
887
  const copyBranch = (variables, signal) => dataPlaneFetch({
736
888
  url: "/db/{dbBranchName}/copy",
737
889
  method: "post",
@@ -862,6 +1014,12 @@ const putFile = (variables, signal) => dataPlaneFetch({
862
1014
  ...variables,
863
1015
  signal
864
1016
  });
1017
+ const deleteFile = (variables, signal) => dataPlaneFetch({
1018
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
1019
+ method: "delete",
1020
+ ...variables,
1021
+ signal
1022
+ });
865
1023
  const getRecord = (variables, signal) => dataPlaneFetch({
866
1024
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
867
1025
  method: "get",
@@ -891,12 +1049,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
891
1049
  ...variables,
892
1050
  signal
893
1051
  });
894
- const sqlQuery = (variables, signal) => dataPlaneFetch({
895
- url: "/db/{dbBranchName}/sql",
896
- method: "post",
897
- ...variables,
898
- signal
899
- });
900
1052
  const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
901
1053
  const askTable = (variables, signal) => dataPlaneFetch({
902
1054
  url: "/db/{dbBranchName}/tables/{tableName}/ask",
@@ -904,6 +1056,7 @@ const askTable = (variables, signal) => dataPlaneFetch({
904
1056
  ...variables,
905
1057
  signal
906
1058
  });
1059
+ const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
907
1060
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
908
1061
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
909
1062
  const fileAccess = (variables, signal) => dataPlaneFetch({
@@ -912,8 +1065,24 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
912
1065
  ...variables,
913
1066
  signal
914
1067
  });
1068
+ const fileUpload = (variables, signal) => dataPlaneFetch({
1069
+ url: "/file/{fileId}",
1070
+ method: "put",
1071
+ ...variables,
1072
+ signal
1073
+ });
1074
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
1075
+ url: "/db/{dbBranchName}/sql",
1076
+ method: "post",
1077
+ ...variables,
1078
+ signal
1079
+ });
915
1080
  const operationsByTag$2 = {
916
1081
  branch: {
1082
+ applyMigration,
1083
+ pgRollStatus,
1084
+ pgRollJobStatus,
1085
+ pgRollMigrationHistory,
917
1086
  getBranchList,
918
1087
  getBranchDetails,
919
1088
  createBranch,
@@ -928,6 +1097,7 @@ const operationsByTag$2 = {
928
1097
  resolveBranch
929
1098
  },
930
1099
  migrations: {
1100
+ getSchema,
931
1101
  getBranchMigrationHistory,
932
1102
  getBranchMigrationPlan,
933
1103
  executeBranchMigrationPlan,
@@ -971,21 +1141,24 @@ const operationsByTag$2 = {
971
1141
  deleteRecord,
972
1142
  bulkInsertTableRecords
973
1143
  },
974
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, fileAccess },
1144
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
975
1145
  searchAndFilter: {
976
1146
  queryTable,
977
1147
  searchBranch,
978
1148
  searchTable,
979
- sqlQuery,
980
1149
  vectorSearchTable,
981
1150
  askTable,
1151
+ askTableSession,
982
1152
  summarizeTable,
983
1153
  aggregateTable
984
- }
1154
+ },
1155
+ sql: { sqlQuery }
985
1156
  };
986
1157
 
987
1158
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
988
1159
 
1160
+ const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
1161
+ const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
989
1162
  const getUser = (variables, signal) => controlPlaneFetch({
990
1163
  url: "/user",
991
1164
  method: "get",
@@ -1022,6 +1195,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
1022
1195
  ...variables,
1023
1196
  signal
1024
1197
  });
1198
+ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
1199
+ url: "/user/oauth/clients",
1200
+ method: "get",
1201
+ ...variables,
1202
+ signal
1203
+ });
1204
+ const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
1205
+ url: "/user/oauth/clients/{clientId}",
1206
+ method: "delete",
1207
+ ...variables,
1208
+ signal
1209
+ });
1210
+ const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
1211
+ url: "/user/oauth/tokens",
1212
+ method: "get",
1213
+ ...variables,
1214
+ signal
1215
+ });
1216
+ const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
1217
+ url: "/user/oauth/tokens/{token}",
1218
+ method: "delete",
1219
+ ...variables,
1220
+ signal
1221
+ });
1222
+ const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
1025
1223
  const getWorkspacesList = (variables, signal) => controlPlaneFetch({
1026
1224
  url: "/workspaces",
1027
1225
  method: "get",
@@ -1065,6 +1263,15 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
1065
1263
  const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
1066
1264
  const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
1067
1265
  const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
1266
+ const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
1267
+ const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
1268
+ const getCluster = (variables, signal) => controlPlaneFetch({
1269
+ url: "/workspaces/{workspaceId}/clusters/{clusterId}",
1270
+ method: "get",
1271
+ ...variables,
1272
+ signal
1273
+ });
1274
+ const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
1068
1275
  const getDatabaseList = (variables, signal) => controlPlaneFetch({
1069
1276
  url: "/workspaces/{workspaceId}/dbs",
1070
1277
  method: "get",
@@ -1091,6 +1298,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
1091
1298
  signal
1092
1299
  });
1093
1300
  const operationsByTag$1 = {
1301
+ oAuth: {
1302
+ getAuthorizationCode,
1303
+ grantAuthorizationCode,
1304
+ getUserOAuthClients,
1305
+ deleteUserOAuthClient,
1306
+ getUserOAuthAccessTokens,
1307
+ deleteOAuthAccessToken,
1308
+ updateOAuthAccessToken
1309
+ },
1094
1310
  users: { getUser, updateUser, deleteUser },
1095
1311
  authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
1096
1312
  workspaces: {
@@ -1110,6 +1326,7 @@ const operationsByTag$1 = {
1110
1326
  acceptWorkspaceMemberInvite,
1111
1327
  resendWorkspaceMemberInvite
1112
1328
  },
1329
+ xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
1113
1330
  databases: {
1114
1331
  getDatabaseList,
1115
1332
  createDatabase,
@@ -1126,66 +1343,11 @@ const operationsByTag$1 = {
1126
1343
 
1127
1344
  const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
1128
1345
 
1129
- function getHostUrl(provider, type) {
1130
- if (isHostProviderAlias(provider)) {
1131
- return providers[provider][type];
1132
- } else if (isHostProviderBuilder(provider)) {
1133
- return provider[type];
1134
- }
1135
- throw new Error("Invalid API provider");
1136
- }
1137
- const providers = {
1138
- production: {
1139
- main: "https://api.xata.io",
1140
- workspaces: "https://{workspaceId}.{region}.xata.sh"
1141
- },
1142
- staging: {
1143
- main: "https://api.staging-xata.dev",
1144
- workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1145
- },
1146
- dev: {
1147
- main: "https://api.dev-xata.dev",
1148
- workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
1149
- }
1150
- };
1151
- function isHostProviderAlias(alias) {
1152
- return isString(alias) && Object.keys(providers).includes(alias);
1153
- }
1154
- function isHostProviderBuilder(builder) {
1155
- return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
1156
- }
1157
- function parseProviderString(provider = "production") {
1158
- if (isHostProviderAlias(provider)) {
1159
- return provider;
1160
- }
1161
- const [main, workspaces] = provider.split(",");
1162
- if (!main || !workspaces)
1163
- return null;
1164
- return { main, workspaces };
1165
- }
1166
- function buildProviderString(provider) {
1167
- if (isHostProviderAlias(provider))
1168
- return provider;
1169
- return `${provider.main},${provider.workspaces}`;
1170
- }
1171
- function parseWorkspacesUrlParts(url) {
1172
- if (!isString(url))
1173
- return null;
1174
- const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
1175
- const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1176
- const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1177
- const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1178
- const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
1179
- if (!match)
1180
- return null;
1181
- return { workspace: match[1], region: match[2] };
1182
- }
1183
-
1184
1346
  var __accessCheck$7 = (obj, member, msg) => {
1185
1347
  if (!member.has(obj))
1186
1348
  throw TypeError("Cannot " + msg);
1187
1349
  };
1188
- var __privateGet$7 = (obj, member, getter) => {
1350
+ var __privateGet$6 = (obj, member, getter) => {
1189
1351
  __accessCheck$7(obj, member, "read from private field");
1190
1352
  return getter ? getter.call(obj) : member.get(obj);
1191
1353
  };
@@ -1194,7 +1356,7 @@ var __privateAdd$7 = (obj, member, value) => {
1194
1356
  throw TypeError("Cannot add the same private member more than once");
1195
1357
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1196
1358
  };
1197
- var __privateSet$7 = (obj, member, value, setter) => {
1359
+ var __privateSet$5 = (obj, member, value, setter) => {
1198
1360
  __accessCheck$7(obj, member, "write to private field");
1199
1361
  setter ? setter.call(obj, value) : member.set(obj, value);
1200
1362
  return value;
@@ -1211,7 +1373,7 @@ class XataApiClient {
1211
1373
  if (!apiKey) {
1212
1374
  throw new Error("Could not resolve a valid apiKey");
1213
1375
  }
1214
- __privateSet$7(this, _extraProps, {
1376
+ __privateSet$5(this, _extraProps, {
1215
1377
  apiUrl: getHostUrl(provider, "main"),
1216
1378
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
1217
1379
  fetch: getFetchImplementation(options.fetch),
@@ -1223,64 +1385,64 @@ class XataApiClient {
1223
1385
  });
1224
1386
  }
1225
1387
  get user() {
1226
- if (!__privateGet$7(this, _namespaces).user)
1227
- __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
1228
- return __privateGet$7(this, _namespaces).user;
1388
+ if (!__privateGet$6(this, _namespaces).user)
1389
+ __privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
1390
+ return __privateGet$6(this, _namespaces).user;
1229
1391
  }
1230
1392
  get authentication() {
1231
- if (!__privateGet$7(this, _namespaces).authentication)
1232
- __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
1233
- return __privateGet$7(this, _namespaces).authentication;
1393
+ if (!__privateGet$6(this, _namespaces).authentication)
1394
+ __privateGet$6(this, _namespaces).authentication = new AuthenticationApi(__privateGet$6(this, _extraProps));
1395
+ return __privateGet$6(this, _namespaces).authentication;
1234
1396
  }
1235
1397
  get workspaces() {
1236
- if (!__privateGet$7(this, _namespaces).workspaces)
1237
- __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
1238
- return __privateGet$7(this, _namespaces).workspaces;
1398
+ if (!__privateGet$6(this, _namespaces).workspaces)
1399
+ __privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
1400
+ return __privateGet$6(this, _namespaces).workspaces;
1239
1401
  }
1240
1402
  get invites() {
1241
- if (!__privateGet$7(this, _namespaces).invites)
1242
- __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
1243
- return __privateGet$7(this, _namespaces).invites;
1403
+ if (!__privateGet$6(this, _namespaces).invites)
1404
+ __privateGet$6(this, _namespaces).invites = new InvitesApi(__privateGet$6(this, _extraProps));
1405
+ return __privateGet$6(this, _namespaces).invites;
1244
1406
  }
1245
1407
  get database() {
1246
- if (!__privateGet$7(this, _namespaces).database)
1247
- __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
1248
- return __privateGet$7(this, _namespaces).database;
1408
+ if (!__privateGet$6(this, _namespaces).database)
1409
+ __privateGet$6(this, _namespaces).database = new DatabaseApi(__privateGet$6(this, _extraProps));
1410
+ return __privateGet$6(this, _namespaces).database;
1249
1411
  }
1250
1412
  get branches() {
1251
- if (!__privateGet$7(this, _namespaces).branches)
1252
- __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
1253
- return __privateGet$7(this, _namespaces).branches;
1413
+ if (!__privateGet$6(this, _namespaces).branches)
1414
+ __privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
1415
+ return __privateGet$6(this, _namespaces).branches;
1254
1416
  }
1255
1417
  get migrations() {
1256
- if (!__privateGet$7(this, _namespaces).migrations)
1257
- __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
1258
- return __privateGet$7(this, _namespaces).migrations;
1418
+ if (!__privateGet$6(this, _namespaces).migrations)
1419
+ __privateGet$6(this, _namespaces).migrations = new MigrationsApi(__privateGet$6(this, _extraProps));
1420
+ return __privateGet$6(this, _namespaces).migrations;
1259
1421
  }
1260
1422
  get migrationRequests() {
1261
- if (!__privateGet$7(this, _namespaces).migrationRequests)
1262
- __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
1263
- return __privateGet$7(this, _namespaces).migrationRequests;
1423
+ if (!__privateGet$6(this, _namespaces).migrationRequests)
1424
+ __privateGet$6(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$6(this, _extraProps));
1425
+ return __privateGet$6(this, _namespaces).migrationRequests;
1264
1426
  }
1265
1427
  get tables() {
1266
- if (!__privateGet$7(this, _namespaces).tables)
1267
- __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
1268
- return __privateGet$7(this, _namespaces).tables;
1428
+ if (!__privateGet$6(this, _namespaces).tables)
1429
+ __privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
1430
+ return __privateGet$6(this, _namespaces).tables;
1269
1431
  }
1270
1432
  get records() {
1271
- if (!__privateGet$7(this, _namespaces).records)
1272
- __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
1273
- return __privateGet$7(this, _namespaces).records;
1433
+ if (!__privateGet$6(this, _namespaces).records)
1434
+ __privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
1435
+ return __privateGet$6(this, _namespaces).records;
1274
1436
  }
1275
1437
  get files() {
1276
- if (!__privateGet$7(this, _namespaces).files)
1277
- __privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
1278
- return __privateGet$7(this, _namespaces).files;
1438
+ if (!__privateGet$6(this, _namespaces).files)
1439
+ __privateGet$6(this, _namespaces).files = new FilesApi(__privateGet$6(this, _extraProps));
1440
+ return __privateGet$6(this, _namespaces).files;
1279
1441
  }
1280
1442
  get searchAndFilter() {
1281
- if (!__privateGet$7(this, _namespaces).searchAndFilter)
1282
- __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
1283
- return __privateGet$7(this, _namespaces).searchAndFilter;
1443
+ if (!__privateGet$6(this, _namespaces).searchAndFilter)
1444
+ __privateGet$6(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$6(this, _extraProps));
1445
+ return __privateGet$6(this, _namespaces).searchAndFilter;
1284
1446
  }
1285
1447
  }
1286
1448
  _extraProps = new WeakMap();
@@ -1582,6 +1744,30 @@ class BranchApi {
1582
1744
  ...this.extraProps
1583
1745
  });
1584
1746
  }
1747
+ pgRollMigrationHistory({
1748
+ workspace,
1749
+ region,
1750
+ database,
1751
+ branch
1752
+ }) {
1753
+ return operationsByTag.branch.pgRollMigrationHistory({
1754
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1755
+ ...this.extraProps
1756
+ });
1757
+ }
1758
+ applyMigration({
1759
+ workspace,
1760
+ region,
1761
+ database,
1762
+ branch,
1763
+ migration
1764
+ }) {
1765
+ return operationsByTag.branch.applyMigration({
1766
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1767
+ body: migration,
1768
+ ...this.extraProps
1769
+ });
1770
+ }
1585
1771
  }
1586
1772
  class TableApi {
1587
1773
  constructor(extraProps) {
@@ -1902,6 +2088,7 @@ class FilesApi {
1902
2088
  columnName: column,
1903
2089
  fileId
1904
2090
  },
2091
+ // @ts-ignore
1905
2092
  body: file,
1906
2093
  ...this.extraProps
1907
2094
  });
@@ -1973,6 +2160,27 @@ class FilesApi {
1973
2160
  ...this.extraProps
1974
2161
  });
1975
2162
  }
2163
+ deleteFile({
2164
+ workspace,
2165
+ region,
2166
+ database,
2167
+ branch,
2168
+ table,
2169
+ record,
2170
+ column
2171
+ }) {
2172
+ return operationsByTag.files.deleteFile({
2173
+ pathParams: {
2174
+ workspace,
2175
+ region,
2176
+ dbBranchName: `${database}:${branch}`,
2177
+ tableName: table,
2178
+ recordId: record,
2179
+ columnName: column
2180
+ },
2181
+ ...this.extraProps
2182
+ });
2183
+ }
1976
2184
  fileAccess({
1977
2185
  workspace,
1978
2186
  region,
@@ -2081,6 +2289,21 @@ class SearchAndFilterApi {
2081
2289
  ...this.extraProps
2082
2290
  });
2083
2291
  }
2292
+ askTableSession({
2293
+ workspace,
2294
+ region,
2295
+ database,
2296
+ branch,
2297
+ table,
2298
+ sessionId,
2299
+ message
2300
+ }) {
2301
+ return operationsByTag.searchAndFilter.askTableSession({
2302
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
2303
+ body: { message },
2304
+ ...this.extraProps
2305
+ });
2306
+ }
2084
2307
  summarizeTable({
2085
2308
  workspace,
2086
2309
  region,
@@ -2358,6 +2581,17 @@ class MigrationsApi {
2358
2581
  ...this.extraProps
2359
2582
  });
2360
2583
  }
2584
+ getSchema({
2585
+ workspace,
2586
+ region,
2587
+ database,
2588
+ branch
2589
+ }) {
2590
+ return operationsByTag.migrations.getSchema({
2591
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2592
+ ...this.extraProps
2593
+ });
2594
+ }
2361
2595
  }
2362
2596
  class DatabaseApi {
2363
2597
  constructor(extraProps) {
@@ -2372,11 +2606,13 @@ class DatabaseApi {
2372
2606
  createDatabase({
2373
2607
  workspace,
2374
2608
  database,
2375
- data
2609
+ data,
2610
+ headers
2376
2611
  }) {
2377
2612
  return operationsByTag.databases.createDatabase({
2378
2613
  pathParams: { workspaceId: workspace, dbName: database },
2379
2614
  body: data,
2615
+ headers,
2380
2616
  ...this.extraProps
2381
2617
  });
2382
2618
  }
@@ -2466,18 +2702,202 @@ class XataApiPlugin {
2466
2702
  class XataPlugin {
2467
2703
  }
2468
2704
 
2705
+ function buildTransformString(transformations) {
2706
+ return transformations.flatMap(
2707
+ (t) => Object.entries(t).map(([key, value]) => {
2708
+ if (key === "trim") {
2709
+ const { left = 0, top = 0, right = 0, bottom = 0 } = value;
2710
+ return `${key}=${[top, right, bottom, left].join(";")}`;
2711
+ }
2712
+ if (key === "gravity" && typeof value === "object") {
2713
+ const { x = 0.5, y = 0.5 } = value;
2714
+ return `${key}=${[x, y].join("x")}`;
2715
+ }
2716
+ return `${key}=${value}`;
2717
+ })
2718
+ ).join(",");
2719
+ }
2720
+ function transformImage(url, ...transformations) {
2721
+ if (!isDefined(url))
2722
+ return void 0;
2723
+ const newTransformations = buildTransformString(transformations);
2724
+ const { hostname, pathname, search } = new URL(url);
2725
+ const pathParts = pathname.split("/");
2726
+ const transformIndex = pathParts.findIndex((part) => part === "transform");
2727
+ const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
2728
+ const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
2729
+ const path = pathParts.join("/");
2730
+ return `https://${hostname}${transform}${path}${search}`;
2731
+ }
2732
+
2733
+ class XataFile {
2734
+ constructor(file) {
2735
+ this.id = file.id;
2736
+ this.name = file.name;
2737
+ this.mediaType = file.mediaType;
2738
+ this.base64Content = file.base64Content;
2739
+ this.enablePublicUrl = file.enablePublicUrl;
2740
+ this.signedUrlTimeout = file.signedUrlTimeout;
2741
+ this.uploadUrlTimeout = file.uploadUrlTimeout;
2742
+ this.size = file.size;
2743
+ this.version = file.version;
2744
+ this.url = file.url;
2745
+ this.signedUrl = file.signedUrl;
2746
+ this.uploadUrl = file.uploadUrl;
2747
+ this.attributes = file.attributes;
2748
+ }
2749
+ static fromBuffer(buffer, options = {}) {
2750
+ const base64Content = buffer.toString("base64");
2751
+ return new XataFile({ ...options, base64Content });
2752
+ }
2753
+ toBuffer() {
2754
+ if (!this.base64Content) {
2755
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2756
+ }
2757
+ return Buffer.from(this.base64Content, "base64");
2758
+ }
2759
+ static fromArrayBuffer(arrayBuffer, options = {}) {
2760
+ const uint8Array = new Uint8Array(arrayBuffer);
2761
+ return this.fromUint8Array(uint8Array, options);
2762
+ }
2763
+ toArrayBuffer() {
2764
+ if (!this.base64Content) {
2765
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2766
+ }
2767
+ const binary = atob(this.base64Content);
2768
+ return new ArrayBuffer(binary.length);
2769
+ }
2770
+ static fromUint8Array(uint8Array, options = {}) {
2771
+ let binary = "";
2772
+ for (let i = 0; i < uint8Array.byteLength; i++) {
2773
+ binary += String.fromCharCode(uint8Array[i]);
2774
+ }
2775
+ const base64Content = btoa(binary);
2776
+ return new XataFile({ ...options, base64Content });
2777
+ }
2778
+ toUint8Array() {
2779
+ if (!this.base64Content) {
2780
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2781
+ }
2782
+ const binary = atob(this.base64Content);
2783
+ const uint8Array = new Uint8Array(binary.length);
2784
+ for (let i = 0; i < binary.length; i++) {
2785
+ uint8Array[i] = binary.charCodeAt(i);
2786
+ }
2787
+ return uint8Array;
2788
+ }
2789
+ static async fromBlob(file, options = {}) {
2790
+ const name = options.name ?? file.name;
2791
+ const mediaType = file.type;
2792
+ const arrayBuffer = await file.arrayBuffer();
2793
+ return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
2794
+ }
2795
+ toBlob() {
2796
+ if (!this.base64Content) {
2797
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2798
+ }
2799
+ const binary = atob(this.base64Content);
2800
+ const uint8Array = new Uint8Array(binary.length);
2801
+ for (let i = 0; i < binary.length; i++) {
2802
+ uint8Array[i] = binary.charCodeAt(i);
2803
+ }
2804
+ return new Blob([uint8Array], { type: this.mediaType });
2805
+ }
2806
+ static fromString(string, options = {}) {
2807
+ const base64Content = btoa(string);
2808
+ return new XataFile({ ...options, base64Content });
2809
+ }
2810
+ toString() {
2811
+ if (!this.base64Content) {
2812
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2813
+ }
2814
+ return atob(this.base64Content);
2815
+ }
2816
+ static fromBase64(base64Content, options = {}) {
2817
+ return new XataFile({ ...options, base64Content });
2818
+ }
2819
+ toBase64() {
2820
+ if (!this.base64Content) {
2821
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2822
+ }
2823
+ return this.base64Content;
2824
+ }
2825
+ transform(...options) {
2826
+ return {
2827
+ url: transformImage(this.url, ...options),
2828
+ signedUrl: transformImage(this.signedUrl, ...options),
2829
+ metadataUrl: transformImage(this.url, ...options, { format: "json" }),
2830
+ metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
2831
+ };
2832
+ }
2833
+ }
2834
+ const parseInputFileEntry = async (entry) => {
2835
+ if (!isDefined(entry))
2836
+ return null;
2837
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
2838
+ return compactObject({
2839
+ id,
2840
+ // Name cannot be an empty string in our API
2841
+ name: name ? name : void 0,
2842
+ mediaType,
2843
+ base64Content,
2844
+ enablePublicUrl,
2845
+ signedUrlTimeout,
2846
+ uploadUrlTimeout
2847
+ });
2848
+ };
2849
+
2469
2850
  function cleanFilter(filter) {
2470
- if (!filter)
2851
+ if (!isDefined(filter))
2471
2852
  return void 0;
2472
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2473
- return values.length > 0 ? filter : void 0;
2853
+ if (!isObject(filter))
2854
+ return filter;
2855
+ const values = Object.fromEntries(
2856
+ Object.entries(filter).reduce((acc, [key, value]) => {
2857
+ if (!isDefined(value))
2858
+ return acc;
2859
+ if (Array.isArray(value)) {
2860
+ const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
2861
+ if (clean.length === 0)
2862
+ return acc;
2863
+ return [...acc, [key, clean]];
2864
+ }
2865
+ if (isObject(value)) {
2866
+ const clean = cleanFilter(value);
2867
+ if (!isDefined(clean))
2868
+ return acc;
2869
+ return [...acc, [key, clean]];
2870
+ }
2871
+ return [...acc, [key, value]];
2872
+ }, [])
2873
+ );
2874
+ return Object.keys(values).length > 0 ? values : void 0;
2875
+ }
2876
+
2877
+ function stringifyJson(value) {
2878
+ if (!isDefined(value))
2879
+ return value;
2880
+ if (isString(value))
2881
+ return value;
2882
+ try {
2883
+ return JSON.stringify(value);
2884
+ } catch (e) {
2885
+ return value;
2886
+ }
2887
+ }
2888
+ function parseJson(value) {
2889
+ try {
2890
+ return JSON.parse(value);
2891
+ } catch (e) {
2892
+ return value;
2893
+ }
2474
2894
  }
2475
2895
 
2476
2896
  var __accessCheck$6 = (obj, member, msg) => {
2477
2897
  if (!member.has(obj))
2478
2898
  throw TypeError("Cannot " + msg);
2479
2899
  };
2480
- var __privateGet$6 = (obj, member, getter) => {
2900
+ var __privateGet$5 = (obj, member, getter) => {
2481
2901
  __accessCheck$6(obj, member, "read from private field");
2482
2902
  return getter ? getter.call(obj) : member.get(obj);
2483
2903
  };
@@ -2486,7 +2906,7 @@ var __privateAdd$6 = (obj, member, value) => {
2486
2906
  throw TypeError("Cannot add the same private member more than once");
2487
2907
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2488
2908
  };
2489
- var __privateSet$6 = (obj, member, value, setter) => {
2909
+ var __privateSet$4 = (obj, member, value, setter) => {
2490
2910
  __accessCheck$6(obj, member, "write to private field");
2491
2911
  setter ? setter.call(obj, value) : member.set(obj, value);
2492
2912
  return value;
@@ -2495,39 +2915,67 @@ var _query, _page;
2495
2915
  class Page {
2496
2916
  constructor(query, meta, records = []) {
2497
2917
  __privateAdd$6(this, _query, void 0);
2498
- __privateSet$6(this, _query, query);
2918
+ __privateSet$4(this, _query, query);
2499
2919
  this.meta = meta;
2500
2920
  this.records = new RecordArray(this, records);
2501
2921
  }
2922
+ /**
2923
+ * Retrieves the next page of results.
2924
+ * @param size Maximum number of results to be retrieved.
2925
+ * @param offset Number of results to skip when retrieving the results.
2926
+ * @returns The next page or results.
2927
+ */
2502
2928
  async nextPage(size, offset) {
2503
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
2504
- }
2929
+ return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
2930
+ }
2931
+ /**
2932
+ * Retrieves the previous page of results.
2933
+ * @param size Maximum number of results to be retrieved.
2934
+ * @param offset Number of results to skip when retrieving the results.
2935
+ * @returns The previous page or results.
2936
+ */
2505
2937
  async previousPage(size, offset) {
2506
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
2507
- }
2938
+ return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
2939
+ }
2940
+ /**
2941
+ * Retrieves the start page of results.
2942
+ * @param size Maximum number of results to be retrieved.
2943
+ * @param offset Number of results to skip when retrieving the results.
2944
+ * @returns The start page or results.
2945
+ */
2508
2946
  async startPage(size, offset) {
2509
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
2510
- }
2947
+ return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
2948
+ }
2949
+ /**
2950
+ * Retrieves the end page of results.
2951
+ * @param size Maximum number of results to be retrieved.
2952
+ * @param offset Number of results to skip when retrieving the results.
2953
+ * @returns The end page or results.
2954
+ */
2511
2955
  async endPage(size, offset) {
2512
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
2956
+ return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
2513
2957
  }
2958
+ /**
2959
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
2960
+ * @returns Whether or not there will be additional results in the next page of results.
2961
+ */
2514
2962
  hasNextPage() {
2515
2963
  return this.meta.page.more;
2516
2964
  }
2517
2965
  }
2518
2966
  _query = new WeakMap();
2519
- const PAGINATION_MAX_SIZE = 200;
2967
+ const PAGINATION_MAX_SIZE = 1e3;
2520
2968
  const PAGINATION_DEFAULT_SIZE = 20;
2521
- const PAGINATION_MAX_OFFSET = 800;
2969
+ const PAGINATION_MAX_OFFSET = 49e3;
2522
2970
  const PAGINATION_DEFAULT_OFFSET = 0;
2523
2971
  function isCursorPaginationOptions(options) {
2524
2972
  return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
2525
2973
  }
2526
- const _RecordArray = class extends Array {
2974
+ const _RecordArray = class _RecordArray extends Array {
2527
2975
  constructor(...args) {
2528
2976
  super(..._RecordArray.parseConstructorParams(...args));
2529
2977
  __privateAdd$6(this, _page, void 0);
2530
- __privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
2978
+ __privateSet$4(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
2531
2979
  }
2532
2980
  static parseConstructorParams(...args) {
2533
2981
  if (args.length === 1 && typeof args[0] === "number") {
@@ -2551,34 +2999,57 @@ const _RecordArray = class extends Array {
2551
2999
  map(callbackfn, thisArg) {
2552
3000
  return this.toArray().map(callbackfn, thisArg);
2553
3001
  }
3002
+ /**
3003
+ * Retrieve next page of records
3004
+ *
3005
+ * @returns A new array of objects
3006
+ */
2554
3007
  async nextPage(size, offset) {
2555
- const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
3008
+ const newPage = await __privateGet$5(this, _page).nextPage(size, offset);
2556
3009
  return new _RecordArray(newPage);
2557
3010
  }
3011
+ /**
3012
+ * Retrieve previous page of records
3013
+ *
3014
+ * @returns A new array of objects
3015
+ */
2558
3016
  async previousPage(size, offset) {
2559
- const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
3017
+ const newPage = await __privateGet$5(this, _page).previousPage(size, offset);
2560
3018
  return new _RecordArray(newPage);
2561
3019
  }
3020
+ /**
3021
+ * Retrieve start page of records
3022
+ *
3023
+ * @returns A new array of objects
3024
+ */
2562
3025
  async startPage(size, offset) {
2563
- const newPage = await __privateGet$6(this, _page).startPage(size, offset);
3026
+ const newPage = await __privateGet$5(this, _page).startPage(size, offset);
2564
3027
  return new _RecordArray(newPage);
2565
3028
  }
3029
+ /**
3030
+ * Retrieve end page of records
3031
+ *
3032
+ * @returns A new array of objects
3033
+ */
2566
3034
  async endPage(size, offset) {
2567
- const newPage = await __privateGet$6(this, _page).endPage(size, offset);
3035
+ const newPage = await __privateGet$5(this, _page).endPage(size, offset);
2568
3036
  return new _RecordArray(newPage);
2569
3037
  }
3038
+ /**
3039
+ * @returns Boolean indicating if there is a next page
3040
+ */
2570
3041
  hasNextPage() {
2571
- return __privateGet$6(this, _page).meta.page.more;
3042
+ return __privateGet$5(this, _page).meta.page.more;
2572
3043
  }
2573
3044
  };
2574
- let RecordArray = _RecordArray;
2575
3045
  _page = new WeakMap();
3046
+ let RecordArray = _RecordArray;
2576
3047
 
2577
3048
  var __accessCheck$5 = (obj, member, msg) => {
2578
3049
  if (!member.has(obj))
2579
3050
  throw TypeError("Cannot " + msg);
2580
3051
  };
2581
- var __privateGet$5 = (obj, member, getter) => {
3052
+ var __privateGet$4 = (obj, member, getter) => {
2582
3053
  __accessCheck$5(obj, member, "read from private field");
2583
3054
  return getter ? getter.call(obj) : member.get(obj);
2584
3055
  };
@@ -2587,7 +3058,7 @@ var __privateAdd$5 = (obj, member, value) => {
2587
3058
  throw TypeError("Cannot add the same private member more than once");
2588
3059
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2589
3060
  };
2590
- var __privateSet$5 = (obj, member, value, setter) => {
3061
+ var __privateSet$3 = (obj, member, value, setter) => {
2591
3062
  __accessCheck$5(obj, member, "write to private field");
2592
3063
  setter ? setter.call(obj, value) : member.set(obj, value);
2593
3064
  return value;
@@ -2597,32 +3068,33 @@ var __privateMethod$3 = (obj, member, method) => {
2597
3068
  return method;
2598
3069
  };
2599
3070
  var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
2600
- const _Query = class {
3071
+ const _Query = class _Query {
2601
3072
  constructor(repository, table, data, rawParent) {
2602
3073
  __privateAdd$5(this, _cleanFilterConstraint);
2603
3074
  __privateAdd$5(this, _table$1, void 0);
2604
3075
  __privateAdd$5(this, _repository, void 0);
2605
3076
  __privateAdd$5(this, _data, { filter: {} });
3077
+ // Implements pagination
2606
3078
  this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
2607
3079
  this.records = new RecordArray(this, []);
2608
- __privateSet$5(this, _table$1, table);
3080
+ __privateSet$3(this, _table$1, table);
2609
3081
  if (repository) {
2610
- __privateSet$5(this, _repository, repository);
3082
+ __privateSet$3(this, _repository, repository);
2611
3083
  } else {
2612
- __privateSet$5(this, _repository, this);
3084
+ __privateSet$3(this, _repository, this);
2613
3085
  }
2614
3086
  const parent = cleanParent(data, rawParent);
2615
- __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
2616
- __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
2617
- __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
2618
- __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
2619
- __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
2620
- __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
2621
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2622
- __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
2623
- __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
2624
- __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2625
- __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
3087
+ __privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
3088
+ __privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
3089
+ __privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
3090
+ __privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
3091
+ __privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
3092
+ __privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
3093
+ __privateGet$4(this, _data).columns = data.columns ?? parent?.columns;
3094
+ __privateGet$4(this, _data).consistency = data.consistency ?? parent?.consistency;
3095
+ __privateGet$4(this, _data).pagination = data.pagination ?? parent?.pagination;
3096
+ __privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
3097
+ __privateGet$4(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
2626
3098
  this.any = this.any.bind(this);
2627
3099
  this.all = this.all.bind(this);
2628
3100
  this.not = this.not.bind(this);
@@ -2633,59 +3105,90 @@ const _Query = class {
2633
3105
  Object.defineProperty(this, "repository", { enumerable: false });
2634
3106
  }
2635
3107
  getQueryOptions() {
2636
- return __privateGet$5(this, _data);
3108
+ return __privateGet$4(this, _data);
2637
3109
  }
2638
3110
  key() {
2639
- const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
3111
+ const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$4(this, _data);
2640
3112
  const key = JSON.stringify({ columns, filter, sort, pagination });
2641
3113
  return toBase64(key);
2642
3114
  }
3115
+ /**
3116
+ * Builds a new query object representing a logical OR between the given subqueries.
3117
+ * @param queries An array of subqueries.
3118
+ * @returns A new Query object.
3119
+ */
2643
3120
  any(...queries) {
2644
3121
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2645
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
3122
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
2646
3123
  }
3124
+ /**
3125
+ * Builds a new query object representing a logical AND between the given subqueries.
3126
+ * @param queries An array of subqueries.
3127
+ * @returns A new Query object.
3128
+ */
2647
3129
  all(...queries) {
2648
3130
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2649
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
3131
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
2650
3132
  }
3133
+ /**
3134
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
3135
+ * @param queries An array of subqueries.
3136
+ * @returns A new Query object.
3137
+ */
2651
3138
  not(...queries) {
2652
3139
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2653
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
3140
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
2654
3141
  }
3142
+ /**
3143
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
3144
+ * @param queries An array of subqueries.
3145
+ * @returns A new Query object.
3146
+ */
2655
3147
  none(...queries) {
2656
3148
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2657
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
3149
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
2658
3150
  }
2659
3151
  filter(a, b) {
2660
3152
  if (arguments.length === 1) {
2661
3153
  const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
2662
3154
  [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
2663
3155
  }));
2664
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
2665
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
3156
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
3157
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
2666
3158
  } else {
2667
3159
  const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
2668
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
2669
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
3160
+ const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
3161
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
2670
3162
  }
2671
3163
  }
2672
3164
  sort(column, direction = "asc") {
2673
- const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
3165
+ const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
2674
3166
  const sort = [...originalSort, { column, direction }];
2675
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
3167
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
2676
3168
  }
3169
+ /**
3170
+ * Builds a new query specifying the set of columns to be returned in the query response.
3171
+ * @param columns Array of column names to be returned by the query.
3172
+ * @returns A new Query object.
3173
+ */
2677
3174
  select(columns) {
2678
3175
  return new _Query(
2679
- __privateGet$5(this, _repository),
2680
- __privateGet$5(this, _table$1),
3176
+ __privateGet$4(this, _repository),
3177
+ __privateGet$4(this, _table$1),
2681
3178
  { columns },
2682
- __privateGet$5(this, _data)
3179
+ __privateGet$4(this, _data)
2683
3180
  );
2684
3181
  }
2685
3182
  getPaginated(options = {}) {
2686
- const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2687
- return __privateGet$5(this, _repository).query(query);
2688
- }
3183
+ const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
3184
+ return __privateGet$4(this, _repository).query(query);
3185
+ }
3186
+ /**
3187
+ * Get results in an iterator
3188
+ *
3189
+ * @async
3190
+ * @returns Async interable of results
3191
+ */
2689
3192
  async *[Symbol.asyncIterator]() {
2690
3193
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2691
3194
  yield record;
@@ -2739,39 +3242,66 @@ const _Query = class {
2739
3242
  async summarize(params = {}) {
2740
3243
  const { summaries, summariesFilter, ...options } = params;
2741
3244
  const query = new _Query(
2742
- __privateGet$5(this, _repository),
2743
- __privateGet$5(this, _table$1),
3245
+ __privateGet$4(this, _repository),
3246
+ __privateGet$4(this, _table$1),
2744
3247
  options,
2745
- __privateGet$5(this, _data)
3248
+ __privateGet$4(this, _data)
2746
3249
  );
2747
- return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
3250
+ return __privateGet$4(this, _repository).summarizeTable(query, summaries, summariesFilter);
2748
3251
  }
3252
+ /**
3253
+ * Builds a new query object adding a cache TTL in milliseconds.
3254
+ * @param ttl The cache TTL in milliseconds.
3255
+ * @returns A new Query object.
3256
+ */
2749
3257
  cache(ttl) {
2750
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
3258
+ return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
2751
3259
  }
3260
+ /**
3261
+ * Retrieve next page of records
3262
+ *
3263
+ * @returns A new page object.
3264
+ */
2752
3265
  nextPage(size, offset) {
2753
3266
  return this.startPage(size, offset);
2754
3267
  }
3268
+ /**
3269
+ * Retrieve previous page of records
3270
+ *
3271
+ * @returns A new page object
3272
+ */
2755
3273
  previousPage(size, offset) {
2756
3274
  return this.startPage(size, offset);
2757
3275
  }
3276
+ /**
3277
+ * Retrieve start page of records
3278
+ *
3279
+ * @returns A new page object
3280
+ */
2758
3281
  startPage(size, offset) {
2759
3282
  return this.getPaginated({ pagination: { size, offset } });
2760
3283
  }
3284
+ /**
3285
+ * Retrieve last page of records
3286
+ *
3287
+ * @returns A new page object
3288
+ */
2761
3289
  endPage(size, offset) {
2762
3290
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2763
3291
  }
3292
+ /**
3293
+ * @returns Boolean indicating if there is a next page
3294
+ */
2764
3295
  hasNextPage() {
2765
3296
  return this.meta.page.more;
2766
3297
  }
2767
3298
  };
2768
- let Query = _Query;
2769
3299
  _table$1 = new WeakMap();
2770
3300
  _repository = new WeakMap();
2771
3301
  _data = new WeakMap();
2772
3302
  _cleanFilterConstraint = new WeakSet();
2773
3303
  cleanFilterConstraint_fn = function(column, value) {
2774
- const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
3304
+ const columnType = __privateGet$4(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2775
3305
  if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2776
3306
  return { $includes: value };
2777
3307
  }
@@ -2780,6 +3310,7 @@ cleanFilterConstraint_fn = function(column, value) {
2780
3310
  }
2781
3311
  return value;
2782
3312
  };
3313
+ let Query = _Query;
2783
3314
  function cleanParent(data, parent) {
2784
3315
  if (isCursorPaginationOptions(data.pagination)) {
2785
3316
  return { ...parent, sort: void 0, filter: void 0 };
@@ -2787,6 +3318,21 @@ function cleanParent(data, parent) {
2787
3318
  return parent;
2788
3319
  }
2789
3320
 
3321
+ const RecordColumnTypes = [
3322
+ "bool",
3323
+ "int",
3324
+ "float",
3325
+ "string",
3326
+ "text",
3327
+ "email",
3328
+ "multiple",
3329
+ "link",
3330
+ "datetime",
3331
+ "vector",
3332
+ "file[]",
3333
+ "file",
3334
+ "json"
3335
+ ];
2790
3336
  function isIdentifiable(x) {
2791
3337
  return isObject(x) && isString(x?.id);
2792
3338
  }
@@ -2796,6 +3342,24 @@ function isXataRecord(x) {
2796
3342
  return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
2797
3343
  }
2798
3344
 
3345
+ function isValidExpandedColumn(column) {
3346
+ return isObject(column) && isString(column.name);
3347
+ }
3348
+ function isValidSelectableColumns(columns) {
3349
+ if (!Array.isArray(columns)) {
3350
+ return false;
3351
+ }
3352
+ return columns.every((column) => {
3353
+ if (typeof column === "string") {
3354
+ return true;
3355
+ }
3356
+ if (typeof column === "object") {
3357
+ return isValidExpandedColumn(column);
3358
+ }
3359
+ return false;
3360
+ });
3361
+ }
3362
+
2799
3363
  function isSortFilterString(value) {
2800
3364
  return isString(value);
2801
3365
  }
@@ -2827,7 +3391,7 @@ var __accessCheck$4 = (obj, member, msg) => {
2827
3391
  if (!member.has(obj))
2828
3392
  throw TypeError("Cannot " + msg);
2829
3393
  };
2830
- var __privateGet$4 = (obj, member, getter) => {
3394
+ var __privateGet$3 = (obj, member, getter) => {
2831
3395
  __accessCheck$4(obj, member, "read from private field");
2832
3396
  return getter ? getter.call(obj) : member.get(obj);
2833
3397
  };
@@ -2836,7 +3400,7 @@ var __privateAdd$4 = (obj, member, value) => {
2836
3400
  throw TypeError("Cannot add the same private member more than once");
2837
3401
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2838
3402
  };
2839
- var __privateSet$4 = (obj, member, value, setter) => {
3403
+ var __privateSet$2 = (obj, member, value, setter) => {
2840
3404
  __accessCheck$4(obj, member, "write to private field");
2841
3405
  setter ? setter.call(obj, value) : member.set(obj, value);
2842
3406
  return value;
@@ -2845,7 +3409,7 @@ var __privateMethod$2 = (obj, member, method) => {
2845
3409
  __accessCheck$4(obj, member, "access private method");
2846
3410
  return method;
2847
3411
  };
2848
- var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
3412
+ var _table, _getFetchProps, _db, _cache, _schemaTables, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables, getSchemaTables_fn, _transformObjectToApi, transformObjectToApi_fn;
2849
3413
  const BULK_OPERATION_MAX_SIZE = 1e3;
2850
3414
  class Repository extends Query {
2851
3415
  }
@@ -2866,61 +3430,62 @@ class RestRepository extends Query {
2866
3430
  __privateAdd$4(this, _deleteRecords);
2867
3431
  __privateAdd$4(this, _setCacheQuery);
2868
3432
  __privateAdd$4(this, _getCacheQuery);
2869
- __privateAdd$4(this, _getSchemaTables$1);
3433
+ __privateAdd$4(this, _getSchemaTables);
3434
+ __privateAdd$4(this, _transformObjectToApi);
2870
3435
  __privateAdd$4(this, _table, void 0);
2871
3436
  __privateAdd$4(this, _getFetchProps, void 0);
2872
3437
  __privateAdd$4(this, _db, void 0);
2873
3438
  __privateAdd$4(this, _cache, void 0);
2874
- __privateAdd$4(this, _schemaTables$2, void 0);
3439
+ __privateAdd$4(this, _schemaTables, void 0);
2875
3440
  __privateAdd$4(this, _trace, void 0);
2876
- __privateSet$4(this, _table, options.table);
2877
- __privateSet$4(this, _db, options.db);
2878
- __privateSet$4(this, _cache, options.pluginOptions.cache);
2879
- __privateSet$4(this, _schemaTables$2, options.schemaTables);
2880
- __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
3441
+ __privateSet$2(this, _table, options.table);
3442
+ __privateSet$2(this, _db, options.db);
3443
+ __privateSet$2(this, _cache, options.pluginOptions.cache);
3444
+ __privateSet$2(this, _schemaTables, options.schemaTables);
3445
+ __privateSet$2(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2881
3446
  const trace = options.pluginOptions.trace ?? defaultTrace;
2882
- __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
3447
+ __privateSet$2(this, _trace, async (name, fn, options2 = {}) => {
2883
3448
  return trace(name, fn, {
2884
3449
  ...options2,
2885
- [TraceAttributes.TABLE]: __privateGet$4(this, _table),
3450
+ [TraceAttributes.TABLE]: __privateGet$3(this, _table),
2886
3451
  [TraceAttributes.KIND]: "sdk-operation",
2887
3452
  [TraceAttributes.VERSION]: VERSION
2888
3453
  });
2889
3454
  });
2890
3455
  }
2891
3456
  async create(a, b, c, d) {
2892
- return __privateGet$4(this, _trace).call(this, "create", async () => {
3457
+ return __privateGet$3(this, _trace).call(this, "create", async () => {
2893
3458
  const ifVersion = parseIfVersion(b, c, d);
2894
3459
  if (Array.isArray(a)) {
2895
3460
  if (a.length === 0)
2896
3461
  return [];
2897
3462
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2898
- const columns = isStringArray(b) ? b : ["*"];
3463
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2899
3464
  const result = await this.read(ids, columns);
2900
3465
  return result;
2901
3466
  }
2902
3467
  if (isString(a) && isObject(b)) {
2903
3468
  if (a === "")
2904
3469
  throw new Error("The id can't be empty");
2905
- const columns = isStringArray(c) ? c : void 0;
3470
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2906
3471
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2907
3472
  }
2908
3473
  if (isObject(a) && isString(a.id)) {
2909
3474
  if (a.id === "")
2910
3475
  throw new Error("The id can't be empty");
2911
- const columns = isStringArray(b) ? b : void 0;
3476
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2912
3477
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2913
3478
  }
2914
3479
  if (isObject(a)) {
2915
- const columns = isStringArray(b) ? b : void 0;
3480
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2916
3481
  return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2917
3482
  }
2918
3483
  throw new Error("Invalid arguments for create method");
2919
3484
  });
2920
3485
  }
2921
3486
  async read(a, b) {
2922
- return __privateGet$4(this, _trace).call(this, "read", async () => {
2923
- const columns = isStringArray(b) ? b : ["*"];
3487
+ return __privateGet$3(this, _trace).call(this, "read", async () => {
3488
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2924
3489
  if (Array.isArray(a)) {
2925
3490
  if (a.length === 0)
2926
3491
  return [];
@@ -2940,14 +3505,20 @@ class RestRepository extends Query {
2940
3505
  workspace: "{workspaceId}",
2941
3506
  dbBranchName: "{dbBranch}",
2942
3507
  region: "{region}",
2943
- tableName: __privateGet$4(this, _table),
3508
+ tableName: __privateGet$3(this, _table),
2944
3509
  recordId: id
2945
3510
  },
2946
3511
  queryParams: { columns },
2947
- ...__privateGet$4(this, _getFetchProps).call(this)
3512
+ ...__privateGet$3(this, _getFetchProps).call(this)
2948
3513
  });
2949
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2950
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
3514
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3515
+ return initObject(
3516
+ __privateGet$3(this, _db),
3517
+ schemaTables,
3518
+ __privateGet$3(this, _table),
3519
+ response,
3520
+ columns
3521
+ );
2951
3522
  } catch (e) {
2952
3523
  if (isObject(e) && e.status === 404) {
2953
3524
  return null;
@@ -2959,7 +3530,7 @@ class RestRepository extends Query {
2959
3530
  });
2960
3531
  }
2961
3532
  async readOrThrow(a, b) {
2962
- return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
3533
+ return __privateGet$3(this, _trace).call(this, "readOrThrow", async () => {
2963
3534
  const result = await this.read(a, b);
2964
3535
  if (Array.isArray(result)) {
2965
3536
  const missingIds = compact(
@@ -2978,7 +3549,7 @@ class RestRepository extends Query {
2978
3549
  });
2979
3550
  }
2980
3551
  async update(a, b, c, d) {
2981
- return __privateGet$4(this, _trace).call(this, "update", async () => {
3552
+ return __privateGet$3(this, _trace).call(this, "update", async () => {
2982
3553
  const ifVersion = parseIfVersion(b, c, d);
2983
3554
  if (Array.isArray(a)) {
2984
3555
  if (a.length === 0)
@@ -2989,17 +3560,17 @@ class RestRepository extends Query {
2989
3560
  ifVersion,
2990
3561
  upsert: false
2991
3562
  });
2992
- const columns = isStringArray(b) ? b : ["*"];
3563
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2993
3564
  const result = await this.read(a, columns);
2994
3565
  return result;
2995
3566
  }
2996
3567
  try {
2997
3568
  if (isString(a) && isObject(b)) {
2998
- const columns = isStringArray(c) ? c : void 0;
3569
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2999
3570
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3000
3571
  }
3001
3572
  if (isObject(a) && isString(a.id)) {
3002
- const columns = isStringArray(b) ? b : void 0;
3573
+ const columns = isValidSelectableColumns(b) ? b : void 0;
3003
3574
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3004
3575
  }
3005
3576
  } catch (error) {
@@ -3011,7 +3582,7 @@ class RestRepository extends Query {
3011
3582
  });
3012
3583
  }
3013
3584
  async updateOrThrow(a, b, c, d) {
3014
- return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
3585
+ return __privateGet$3(this, _trace).call(this, "updateOrThrow", async () => {
3015
3586
  const result = await this.update(a, b, c, d);
3016
3587
  if (Array.isArray(result)) {
3017
3588
  const missingIds = compact(
@@ -3030,7 +3601,7 @@ class RestRepository extends Query {
3030
3601
  });
3031
3602
  }
3032
3603
  async createOrUpdate(a, b, c, d) {
3033
- return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
3604
+ return __privateGet$3(this, _trace).call(this, "createOrUpdate", async () => {
3034
3605
  const ifVersion = parseIfVersion(b, c, d);
3035
3606
  if (Array.isArray(a)) {
3036
3607
  if (a.length === 0)
@@ -3039,45 +3610,65 @@ class RestRepository extends Query {
3039
3610
  ifVersion,
3040
3611
  upsert: true
3041
3612
  });
3042
- const columns = isStringArray(b) ? b : ["*"];
3613
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3043
3614
  const result = await this.read(a, columns);
3044
3615
  return result;
3045
3616
  }
3046
3617
  if (isString(a) && isObject(b)) {
3047
- const columns = isStringArray(c) ? c : void 0;
3048
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3618
+ if (a === "")
3619
+ throw new Error("The id can't be empty");
3620
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3621
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3049
3622
  }
3050
3623
  if (isObject(a) && isString(a.id)) {
3051
- const columns = isStringArray(c) ? c : void 0;
3052
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3624
+ if (a.id === "")
3625
+ throw new Error("The id can't be empty");
3626
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3627
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3628
+ }
3629
+ if (!isDefined(a) && isObject(b)) {
3630
+ return await this.create(b, c);
3631
+ }
3632
+ if (isObject(a) && !isDefined(a.id)) {
3633
+ return await this.create(a, b);
3053
3634
  }
3054
3635
  throw new Error("Invalid arguments for createOrUpdate method");
3055
3636
  });
3056
3637
  }
3057
3638
  async createOrReplace(a, b, c, d) {
3058
- return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
3639
+ return __privateGet$3(this, _trace).call(this, "createOrReplace", async () => {
3059
3640
  const ifVersion = parseIfVersion(b, c, d);
3060
3641
  if (Array.isArray(a)) {
3061
3642
  if (a.length === 0)
3062
3643
  return [];
3063
3644
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
3064
- const columns = isStringArray(b) ? b : ["*"];
3645
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3065
3646
  const result = await this.read(ids, columns);
3066
3647
  return result;
3067
3648
  }
3068
3649
  if (isString(a) && isObject(b)) {
3069
- const columns = isStringArray(c) ? c : void 0;
3070
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
3650
+ if (a === "")
3651
+ throw new Error("The id can't be empty");
3652
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3653
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
3071
3654
  }
3072
3655
  if (isObject(a) && isString(a.id)) {
3073
- const columns = isStringArray(c) ? c : void 0;
3074
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3656
+ if (a.id === "")
3657
+ throw new Error("The id can't be empty");
3658
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3659
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3660
+ }
3661
+ if (!isDefined(a) && isObject(b)) {
3662
+ return await this.create(b, c);
3663
+ }
3664
+ if (isObject(a) && !isDefined(a.id)) {
3665
+ return await this.create(a, b);
3075
3666
  }
3076
3667
  throw new Error("Invalid arguments for createOrReplace method");
3077
3668
  });
3078
3669
  }
3079
3670
  async delete(a, b) {
3080
- return __privateGet$4(this, _trace).call(this, "delete", async () => {
3671
+ return __privateGet$3(this, _trace).call(this, "delete", async () => {
3081
3672
  if (Array.isArray(a)) {
3082
3673
  if (a.length === 0)
3083
3674
  return [];
@@ -3088,7 +3679,7 @@ class RestRepository extends Query {
3088
3679
  return o.id;
3089
3680
  throw new Error("Invalid arguments for delete method");
3090
3681
  });
3091
- const columns = isStringArray(b) ? b : ["*"];
3682
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3092
3683
  const result = await this.read(a, columns);
3093
3684
  await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
3094
3685
  return result;
@@ -3103,7 +3694,7 @@ class RestRepository extends Query {
3103
3694
  });
3104
3695
  }
3105
3696
  async deleteOrThrow(a, b) {
3106
- return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
3697
+ return __privateGet$3(this, _trace).call(this, "deleteOrThrow", async () => {
3107
3698
  const result = await this.delete(a, b);
3108
3699
  if (Array.isArray(result)) {
3109
3700
  const missingIds = compact(
@@ -3121,13 +3712,13 @@ class RestRepository extends Query {
3121
3712
  });
3122
3713
  }
3123
3714
  async search(query, options = {}) {
3124
- return __privateGet$4(this, _trace).call(this, "search", async () => {
3125
- const { records } = await searchTable({
3715
+ return __privateGet$3(this, _trace).call(this, "search", async () => {
3716
+ const { records, totalCount } = await searchTable({
3126
3717
  pathParams: {
3127
3718
  workspace: "{workspaceId}",
3128
3719
  dbBranchName: "{dbBranch}",
3129
3720
  region: "{region}",
3130
- tableName: __privateGet$4(this, _table)
3721
+ tableName: __privateGet$3(this, _table)
3131
3722
  },
3132
3723
  body: {
3133
3724
  query,
@@ -3139,20 +3730,23 @@ class RestRepository extends Query {
3139
3730
  page: options.page,
3140
3731
  target: options.target
3141
3732
  },
3142
- ...__privateGet$4(this, _getFetchProps).call(this)
3733
+ ...__privateGet$3(this, _getFetchProps).call(this)
3143
3734
  });
3144
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3145
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
3735
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3736
+ return {
3737
+ records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
3738
+ totalCount
3739
+ };
3146
3740
  });
3147
3741
  }
3148
3742
  async vectorSearch(column, query, options) {
3149
- return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
3150
- const { records } = await vectorSearchTable({
3743
+ return __privateGet$3(this, _trace).call(this, "vectorSearch", async () => {
3744
+ const { records, totalCount } = await vectorSearchTable({
3151
3745
  pathParams: {
3152
3746
  workspace: "{workspaceId}",
3153
3747
  dbBranchName: "{dbBranch}",
3154
3748
  region: "{region}",
3155
- tableName: __privateGet$4(this, _table)
3749
+ tableName: __privateGet$3(this, _table)
3156
3750
  },
3157
3751
  body: {
3158
3752
  column,
@@ -3161,29 +3755,32 @@ class RestRepository extends Query {
3161
3755
  size: options?.size,
3162
3756
  filter: options?.filter
3163
3757
  },
3164
- ...__privateGet$4(this, _getFetchProps).call(this)
3758
+ ...__privateGet$3(this, _getFetchProps).call(this)
3165
3759
  });
3166
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3167
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
3760
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3761
+ return {
3762
+ records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
3763
+ totalCount
3764
+ };
3168
3765
  });
3169
3766
  }
3170
3767
  async aggregate(aggs, filter) {
3171
- return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
3768
+ return __privateGet$3(this, _trace).call(this, "aggregate", async () => {
3172
3769
  const result = await aggregateTable({
3173
3770
  pathParams: {
3174
3771
  workspace: "{workspaceId}",
3175
3772
  dbBranchName: "{dbBranch}",
3176
3773
  region: "{region}",
3177
- tableName: __privateGet$4(this, _table)
3774
+ tableName: __privateGet$3(this, _table)
3178
3775
  },
3179
3776
  body: { aggs, filter },
3180
- ...__privateGet$4(this, _getFetchProps).call(this)
3777
+ ...__privateGet$3(this, _getFetchProps).call(this)
3181
3778
  });
3182
3779
  return result;
3183
3780
  });
3184
3781
  }
3185
3782
  async query(query) {
3186
- return __privateGet$4(this, _trace).call(this, "query", async () => {
3783
+ return __privateGet$3(this, _trace).call(this, "query", async () => {
3187
3784
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
3188
3785
  if (cacheQuery)
3189
3786
  return new Page(query, cacheQuery.meta, cacheQuery.records);
@@ -3193,7 +3790,7 @@ class RestRepository extends Query {
3193
3790
  workspace: "{workspaceId}",
3194
3791
  dbBranchName: "{dbBranch}",
3195
3792
  region: "{region}",
3196
- tableName: __privateGet$4(this, _table)
3793
+ tableName: __privateGet$3(this, _table)
3197
3794
  },
3198
3795
  body: {
3199
3796
  filter: cleanFilter(data.filter),
@@ -3203,25 +3800,31 @@ class RestRepository extends Query {
3203
3800
  consistency: data.consistency
3204
3801
  },
3205
3802
  fetchOptions: data.fetchOptions,
3206
- ...__privateGet$4(this, _getFetchProps).call(this)
3803
+ ...__privateGet$3(this, _getFetchProps).call(this)
3207
3804
  });
3208
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3805
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3209
3806
  const records = objects.map(
3210
- (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
3807
+ (record) => initObject(
3808
+ __privateGet$3(this, _db),
3809
+ schemaTables,
3810
+ __privateGet$3(this, _table),
3811
+ record,
3812
+ data.columns ?? ["*"]
3813
+ )
3211
3814
  );
3212
3815
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
3213
3816
  return new Page(query, meta, records);
3214
3817
  });
3215
3818
  }
3216
3819
  async summarizeTable(query, summaries, summariesFilter) {
3217
- return __privateGet$4(this, _trace).call(this, "summarize", async () => {
3820
+ return __privateGet$3(this, _trace).call(this, "summarize", async () => {
3218
3821
  const data = query.getQueryOptions();
3219
3822
  const result = await summarizeTable({
3220
3823
  pathParams: {
3221
3824
  workspace: "{workspaceId}",
3222
3825
  dbBranchName: "{dbBranch}",
3223
3826
  region: "{region}",
3224
- tableName: __privateGet$4(this, _table)
3827
+ tableName: __privateGet$3(this, _table)
3225
3828
  },
3226
3829
  body: {
3227
3830
  filter: cleanFilter(data.filter),
@@ -3232,29 +3835,40 @@ class RestRepository extends Query {
3232
3835
  summaries,
3233
3836
  summariesFilter
3234
3837
  },
3235
- ...__privateGet$4(this, _getFetchProps).call(this)
3838
+ ...__privateGet$3(this, _getFetchProps).call(this)
3236
3839
  });
3237
- return result;
3840
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3841
+ return {
3842
+ ...result,
3843
+ summaries: result.summaries.map(
3844
+ (summary) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), summary, data.columns ?? [])
3845
+ )
3846
+ };
3238
3847
  });
3239
3848
  }
3240
3849
  ask(question, options) {
3850
+ const questionParam = options?.sessionId ? { message: question } : { question };
3241
3851
  const params = {
3242
3852
  pathParams: {
3243
3853
  workspace: "{workspaceId}",
3244
3854
  dbBranchName: "{dbBranch}",
3245
3855
  region: "{region}",
3246
- tableName: __privateGet$4(this, _table)
3856
+ tableName: __privateGet$3(this, _table),
3857
+ sessionId: options?.sessionId
3247
3858
  },
3248
3859
  body: {
3249
- question,
3250
- ...options
3860
+ ...questionParam,
3861
+ rules: options?.rules,
3862
+ searchType: options?.searchType,
3863
+ search: options?.searchType === "keyword" ? options?.search : void 0,
3864
+ vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
3251
3865
  },
3252
- ...__privateGet$4(this, _getFetchProps).call(this)
3866
+ ...__privateGet$3(this, _getFetchProps).call(this)
3253
3867
  };
3254
3868
  if (options?.onMessage) {
3255
3869
  fetchSSERequest({
3256
3870
  endpoint: "dataPlane",
3257
- url: "/db/{dbBranchName}/tables/{tableName}/ask",
3871
+ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
3258
3872
  method: "POST",
3259
3873
  onMessage: (message) => {
3260
3874
  options.onMessage?.({ answer: message.text, records: message.records });
@@ -3262,7 +3876,7 @@ class RestRepository extends Query {
3262
3876
  ...params
3263
3877
  });
3264
3878
  } else {
3265
- return askTable(params);
3879
+ return askTableSession(params);
3266
3880
  }
3267
3881
  }
3268
3882
  }
@@ -3270,61 +3884,62 @@ _table = new WeakMap();
3270
3884
  _getFetchProps = new WeakMap();
3271
3885
  _db = new WeakMap();
3272
3886
  _cache = new WeakMap();
3273
- _schemaTables$2 = new WeakMap();
3887
+ _schemaTables = new WeakMap();
3274
3888
  _trace = new WeakMap();
3275
3889
  _insertRecordWithoutId = new WeakSet();
3276
3890
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
3277
- const record = transformObjectLinks(object);
3891
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3278
3892
  const response = await insertRecord({
3279
3893
  pathParams: {
3280
3894
  workspace: "{workspaceId}",
3281
3895
  dbBranchName: "{dbBranch}",
3282
3896
  region: "{region}",
3283
- tableName: __privateGet$4(this, _table)
3897
+ tableName: __privateGet$3(this, _table)
3284
3898
  },
3285
3899
  queryParams: { columns },
3286
3900
  body: record,
3287
- ...__privateGet$4(this, _getFetchProps).call(this)
3901
+ ...__privateGet$3(this, _getFetchProps).call(this)
3288
3902
  });
3289
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3290
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
3903
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3904
+ return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
3291
3905
  };
3292
3906
  _insertRecordWithId = new WeakSet();
3293
3907
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
3294
- const record = transformObjectLinks(object);
3908
+ if (!recordId)
3909
+ return null;
3910
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3295
3911
  const response = await insertRecordWithID({
3296
3912
  pathParams: {
3297
3913
  workspace: "{workspaceId}",
3298
3914
  dbBranchName: "{dbBranch}",
3299
3915
  region: "{region}",
3300
- tableName: __privateGet$4(this, _table),
3916
+ tableName: __privateGet$3(this, _table),
3301
3917
  recordId
3302
3918
  },
3303
3919
  body: record,
3304
3920
  queryParams: { createOnly, columns, ifVersion },
3305
- ...__privateGet$4(this, _getFetchProps).call(this)
3921
+ ...__privateGet$3(this, _getFetchProps).call(this)
3306
3922
  });
3307
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3308
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
3923
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3924
+ return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
3309
3925
  };
3310
3926
  _insertRecords = new WeakSet();
3311
3927
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
3312
- const chunkedOperations = chunk(
3313
- objects.map((object) => ({
3314
- insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
3315
- })),
3316
- BULK_OPERATION_MAX_SIZE
3317
- );
3928
+ const operations = await promiseMap(objects, async (object) => {
3929
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3930
+ return { insert: { table: __privateGet$3(this, _table), record, createOnly, ifVersion } };
3931
+ });
3932
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
3318
3933
  const ids = [];
3319
- for (const operations of chunkedOperations) {
3934
+ for (const operations2 of chunkedOperations) {
3320
3935
  const { results } = await branchTransaction({
3321
3936
  pathParams: {
3322
3937
  workspace: "{workspaceId}",
3323
3938
  dbBranchName: "{dbBranch}",
3324
3939
  region: "{region}"
3325
3940
  },
3326
- body: { operations },
3327
- ...__privateGet$4(this, _getFetchProps).call(this)
3941
+ body: { operations: operations2 },
3942
+ ...__privateGet$3(this, _getFetchProps).call(this)
3328
3943
  });
3329
3944
  for (const result of results) {
3330
3945
  if (result.operation === "insert") {
@@ -3338,22 +3953,24 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
3338
3953
  };
3339
3954
  _updateRecordWithID = new WeakSet();
3340
3955
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
3341
- const { id: _id, ...record } = transformObjectLinks(object);
3956
+ if (!recordId)
3957
+ return null;
3958
+ const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3342
3959
  try {
3343
3960
  const response = await updateRecordWithID({
3344
3961
  pathParams: {
3345
3962
  workspace: "{workspaceId}",
3346
3963
  dbBranchName: "{dbBranch}",
3347
3964
  region: "{region}",
3348
- tableName: __privateGet$4(this, _table),
3965
+ tableName: __privateGet$3(this, _table),
3349
3966
  recordId
3350
3967
  },
3351
3968
  queryParams: { columns, ifVersion },
3352
3969
  body: record,
3353
- ...__privateGet$4(this, _getFetchProps).call(this)
3970
+ ...__privateGet$3(this, _getFetchProps).call(this)
3354
3971
  });
3355
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3356
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
3972
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
3973
+ return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
3357
3974
  } catch (e) {
3358
3975
  if (isObject(e) && e.status === 404) {
3359
3976
  return null;
@@ -3363,22 +3980,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
3363
3980
  };
3364
3981
  _updateRecords = new WeakSet();
3365
3982
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
3366
- const chunkedOperations = chunk(
3367
- objects.map(({ id, ...object }) => ({
3368
- update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
3369
- })),
3370
- BULK_OPERATION_MAX_SIZE
3371
- );
3983
+ const operations = await promiseMap(objects, async ({ id, ...object }) => {
3984
+ const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3985
+ return { update: { table: __privateGet$3(this, _table), id, ifVersion, upsert, fields } };
3986
+ });
3987
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
3372
3988
  const ids = [];
3373
- for (const operations of chunkedOperations) {
3989
+ for (const operations2 of chunkedOperations) {
3374
3990
  const { results } = await branchTransaction({
3375
3991
  pathParams: {
3376
3992
  workspace: "{workspaceId}",
3377
3993
  dbBranchName: "{dbBranch}",
3378
3994
  region: "{region}"
3379
3995
  },
3380
- body: { operations },
3381
- ...__privateGet$4(this, _getFetchProps).call(this)
3996
+ body: { operations: operations2 },
3997
+ ...__privateGet$3(this, _getFetchProps).call(this)
3382
3998
  });
3383
3999
  for (const result of results) {
3384
4000
  if (result.operation === "update") {
@@ -3392,37 +4008,41 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
3392
4008
  };
3393
4009
  _upsertRecordWithID = new WeakSet();
3394
4010
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
4011
+ if (!recordId)
4012
+ return null;
3395
4013
  const response = await upsertRecordWithID({
3396
4014
  pathParams: {
3397
4015
  workspace: "{workspaceId}",
3398
4016
  dbBranchName: "{dbBranch}",
3399
4017
  region: "{region}",
3400
- tableName: __privateGet$4(this, _table),
4018
+ tableName: __privateGet$3(this, _table),
3401
4019
  recordId
3402
4020
  },
3403
4021
  queryParams: { columns, ifVersion },
3404
4022
  body: object,
3405
- ...__privateGet$4(this, _getFetchProps).call(this)
4023
+ ...__privateGet$3(this, _getFetchProps).call(this)
3406
4024
  });
3407
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3408
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
4025
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4026
+ return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
3409
4027
  };
3410
4028
  _deleteRecord = new WeakSet();
3411
4029
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
4030
+ if (!recordId)
4031
+ return null;
3412
4032
  try {
3413
4033
  const response = await deleteRecord({
3414
4034
  pathParams: {
3415
4035
  workspace: "{workspaceId}",
3416
4036
  dbBranchName: "{dbBranch}",
3417
4037
  region: "{region}",
3418
- tableName: __privateGet$4(this, _table),
4038
+ tableName: __privateGet$3(this, _table),
3419
4039
  recordId
3420
4040
  },
3421
4041
  queryParams: { columns },
3422
- ...__privateGet$4(this, _getFetchProps).call(this)
4042
+ ...__privateGet$3(this, _getFetchProps).call(this)
3423
4043
  });
3424
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3425
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
4044
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4045
+ return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
3426
4046
  } catch (e) {
3427
4047
  if (isObject(e) && e.status === 404) {
3428
4048
  return null;
@@ -3433,7 +4053,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
3433
4053
  _deleteRecords = new WeakSet();
3434
4054
  deleteRecords_fn = async function(recordIds) {
3435
4055
  const chunkedOperations = chunk(
3436
- recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
4056
+ compact(recordIds).map((id) => ({ delete: { table: __privateGet$3(this, _table), id } })),
3437
4057
  BULK_OPERATION_MAX_SIZE
3438
4058
  );
3439
4059
  for (const operations of chunkedOperations) {
@@ -3444,44 +4064,72 @@ deleteRecords_fn = async function(recordIds) {
3444
4064
  region: "{region}"
3445
4065
  },
3446
4066
  body: { operations },
3447
- ...__privateGet$4(this, _getFetchProps).call(this)
4067
+ ...__privateGet$3(this, _getFetchProps).call(this)
3448
4068
  });
3449
4069
  }
3450
4070
  };
3451
4071
  _setCacheQuery = new WeakSet();
3452
4072
  setCacheQuery_fn = async function(query, meta, records) {
3453
- await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
4073
+ await __privateGet$3(this, _cache)?.set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
3454
4074
  };
3455
4075
  _getCacheQuery = new WeakSet();
3456
4076
  getCacheQuery_fn = async function(query) {
3457
- const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
3458
- const result = await __privateGet$4(this, _cache)?.get(key);
4077
+ const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
4078
+ const result = await __privateGet$3(this, _cache)?.get(key);
3459
4079
  if (!result)
3460
4080
  return null;
3461
- const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
4081
+ const defaultTTL = __privateGet$3(this, _cache)?.defaultQueryTTL ?? -1;
3462
4082
  const { cache: ttl = defaultTTL } = query.getQueryOptions();
3463
4083
  if (ttl < 0)
3464
4084
  return null;
3465
4085
  const hasExpired = result.date.getTime() + ttl < Date.now();
3466
4086
  return hasExpired ? null : result;
3467
4087
  };
3468
- _getSchemaTables$1 = new WeakSet();
3469
- getSchemaTables_fn$1 = async function() {
3470
- if (__privateGet$4(this, _schemaTables$2))
3471
- return __privateGet$4(this, _schemaTables$2);
4088
+ _getSchemaTables = new WeakSet();
4089
+ getSchemaTables_fn = async function() {
4090
+ if (__privateGet$3(this, _schemaTables))
4091
+ return __privateGet$3(this, _schemaTables);
3472
4092
  const { schema } = await getBranchDetails({
3473
4093
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3474
- ...__privateGet$4(this, _getFetchProps).call(this)
4094
+ ...__privateGet$3(this, _getFetchProps).call(this)
3475
4095
  });
3476
- __privateSet$4(this, _schemaTables$2, schema.tables);
4096
+ __privateSet$2(this, _schemaTables, schema.tables);
3477
4097
  return schema.tables;
3478
4098
  };
3479
- const transformObjectLinks = (object) => {
3480
- return Object.entries(object).reduce((acc, [key, value]) => {
4099
+ _transformObjectToApi = new WeakSet();
4100
+ transformObjectToApi_fn = async function(object) {
4101
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
4102
+ const schema = schemaTables.find((table) => table.name === __privateGet$3(this, _table));
4103
+ if (!schema)
4104
+ throw new Error(`Table ${__privateGet$3(this, _table)} not found in schema`);
4105
+ const result = {};
4106
+ for (const [key, value] of Object.entries(object)) {
3481
4107
  if (key === "xata")
3482
- return acc;
3483
- return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
3484
- }, {});
4108
+ continue;
4109
+ const type = schema.columns.find((column) => column.name === key)?.type;
4110
+ switch (type) {
4111
+ case "link": {
4112
+ result[key] = isIdentifiable(value) ? value.id : value;
4113
+ break;
4114
+ }
4115
+ case "datetime": {
4116
+ result[key] = value instanceof Date ? value.toISOString() : value;
4117
+ break;
4118
+ }
4119
+ case `file`:
4120
+ result[key] = await parseInputFileEntry(value);
4121
+ break;
4122
+ case "file[]":
4123
+ result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
4124
+ break;
4125
+ case "json":
4126
+ result[key] = stringifyJson(value);
4127
+ break;
4128
+ default:
4129
+ result[key] = value;
4130
+ }
4131
+ }
4132
+ return result;
3485
4133
  };
3486
4134
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
3487
4135
  const data = {};
@@ -3513,18 +4161,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3513
4161
  if (item === column.name) {
3514
4162
  return [...acc, "*"];
3515
4163
  }
3516
- if (item.startsWith(`${column.name}.`)) {
4164
+ if (isString(item) && item.startsWith(`${column.name}.`)) {
3517
4165
  const [, ...path] = item.split(".");
3518
4166
  return [...acc, path.join(".")];
3519
4167
  }
3520
4168
  return acc;
3521
4169
  }, []);
3522
- data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
4170
+ data[column.name] = initObject(
4171
+ db,
4172
+ schemaTables,
4173
+ linkTable,
4174
+ value,
4175
+ selectedLinkColumns
4176
+ );
3523
4177
  } else {
3524
4178
  data[column.name] = null;
3525
4179
  }
3526
4180
  break;
3527
4181
  }
4182
+ case "file":
4183
+ data[column.name] = isDefined(value) ? new XataFile(value) : null;
4184
+ break;
4185
+ case "file[]":
4186
+ data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
4187
+ break;
4188
+ case "json":
4189
+ data[column.name] = parseJson(value);
4190
+ break;
3528
4191
  default:
3529
4192
  data[column.name] = value ?? null;
3530
4193
  if (column.notNull === true && value === null) {
@@ -3534,30 +4197,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3534
4197
  }
3535
4198
  }
3536
4199
  const record = { ...data };
4200
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
3537
4201
  record.read = function(columns2) {
3538
4202
  return db[table].read(record["id"], columns2);
3539
4203
  };
3540
4204
  record.update = function(data2, b, c) {
3541
- const columns2 = isStringArray(b) ? b : ["*"];
4205
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
3542
4206
  const ifVersion = parseIfVersion(b, c);
3543
4207
  return db[table].update(record["id"], data2, columns2, { ifVersion });
3544
4208
  };
3545
4209
  record.replace = function(data2, b, c) {
3546
- const columns2 = isStringArray(b) ? b : ["*"];
4210
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
3547
4211
  const ifVersion = parseIfVersion(b, c);
3548
4212
  return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
3549
4213
  };
3550
4214
  record.delete = function() {
3551
4215
  return db[table].delete(record["id"]);
3552
4216
  };
4217
+ if (metadata !== void 0) {
4218
+ record.xata = Object.freeze(metadata);
4219
+ }
3553
4220
  record.getMetadata = function() {
3554
- return xata;
4221
+ return record.xata;
3555
4222
  };
3556
4223
  record.toSerializable = function() {
3557
- return JSON.parse(JSON.stringify(transformObjectLinks(data)));
4224
+ return JSON.parse(JSON.stringify(record));
3558
4225
  };
3559
4226
  record.toString = function() {
3560
- return JSON.stringify(transformObjectLinks(data));
4227
+ return JSON.stringify(record);
3561
4228
  };
3562
4229
  for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3563
4230
  Object.defineProperty(record, prop, { enumerable: false });
@@ -3575,11 +4242,7 @@ function extractId(value) {
3575
4242
  function isValidColumn(columns, column) {
3576
4243
  if (columns.includes("*"))
3577
4244
  return true;
3578
- if (column.type === "link") {
3579
- const linkColumns = columns.filter((item) => item.startsWith(column.name));
3580
- return linkColumns.length > 0;
3581
- }
3582
- return columns.includes(column.name);
4245
+ return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
3583
4246
  }
3584
4247
  function parseIfVersion(...args) {
3585
4248
  for (const arg of args) {
@@ -3594,7 +4257,7 @@ var __accessCheck$3 = (obj, member, msg) => {
3594
4257
  if (!member.has(obj))
3595
4258
  throw TypeError("Cannot " + msg);
3596
4259
  };
3597
- var __privateGet$3 = (obj, member, getter) => {
4260
+ var __privateGet$2 = (obj, member, getter) => {
3598
4261
  __accessCheck$3(obj, member, "read from private field");
3599
4262
  return getter ? getter.call(obj) : member.get(obj);
3600
4263
  };
@@ -3603,7 +4266,7 @@ var __privateAdd$3 = (obj, member, value) => {
3603
4266
  throw TypeError("Cannot add the same private member more than once");
3604
4267
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3605
4268
  };
3606
- var __privateSet$3 = (obj, member, value, setter) => {
4269
+ var __privateSet$1 = (obj, member, value, setter) => {
3607
4270
  __accessCheck$3(obj, member, "write to private field");
3608
4271
  setter ? setter.call(obj, value) : member.set(obj, value);
3609
4272
  return value;
@@ -3612,29 +4275,29 @@ var _map;
3612
4275
  class SimpleCache {
3613
4276
  constructor(options = {}) {
3614
4277
  __privateAdd$3(this, _map, void 0);
3615
- __privateSet$3(this, _map, /* @__PURE__ */ new Map());
4278
+ __privateSet$1(this, _map, /* @__PURE__ */ new Map());
3616
4279
  this.capacity = options.max ?? 500;
3617
4280
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
3618
4281
  }
3619
4282
  async getAll() {
3620
- return Object.fromEntries(__privateGet$3(this, _map));
4283
+ return Object.fromEntries(__privateGet$2(this, _map));
3621
4284
  }
3622
4285
  async get(key) {
3623
- return __privateGet$3(this, _map).get(key) ?? null;
4286
+ return __privateGet$2(this, _map).get(key) ?? null;
3624
4287
  }
3625
4288
  async set(key, value) {
3626
4289
  await this.delete(key);
3627
- __privateGet$3(this, _map).set(key, value);
3628
- if (__privateGet$3(this, _map).size > this.capacity) {
3629
- const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
4290
+ __privateGet$2(this, _map).set(key, value);
4291
+ if (__privateGet$2(this, _map).size > this.capacity) {
4292
+ const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
3630
4293
  await this.delete(leastRecentlyUsed);
3631
4294
  }
3632
4295
  }
3633
4296
  async delete(key) {
3634
- __privateGet$3(this, _map).delete(key);
4297
+ __privateGet$2(this, _map).delete(key);
3635
4298
  }
3636
4299
  async clear() {
3637
- return __privateGet$3(this, _map).clear();
4300
+ return __privateGet$2(this, _map).clear();
3638
4301
  }
3639
4302
  }
3640
4303
  _map = new WeakMap();
@@ -3656,10 +4319,12 @@ const notExists = (column) => ({ $notExists: column });
3656
4319
  const startsWith = (value) => ({ $startsWith: value });
3657
4320
  const endsWith = (value) => ({ $endsWith: value });
3658
4321
  const pattern = (value) => ({ $pattern: value });
4322
+ const iPattern = (value) => ({ $iPattern: value });
3659
4323
  const is = (value) => ({ $is: value });
3660
4324
  const equals = is;
3661
4325
  const isNot = (value) => ({ $isNot: value });
3662
4326
  const contains = (value) => ({ $contains: value });
4327
+ const iContains = (value) => ({ $iContains: value });
3663
4328
  const includes = (value) => ({ $includes: value });
3664
4329
  const includesAll = (value) => ({ $includesAll: value });
3665
4330
  const includesNone = (value) => ({ $includesNone: value });
@@ -3669,7 +4334,7 @@ var __accessCheck$2 = (obj, member, msg) => {
3669
4334
  if (!member.has(obj))
3670
4335
  throw TypeError("Cannot " + msg);
3671
4336
  };
3672
- var __privateGet$2 = (obj, member, getter) => {
4337
+ var __privateGet$1 = (obj, member, getter) => {
3673
4338
  __accessCheck$2(obj, member, "read from private field");
3674
4339
  return getter ? getter.call(obj) : member.get(obj);
3675
4340
  };
@@ -3678,18 +4343,11 @@ var __privateAdd$2 = (obj, member, value) => {
3678
4343
  throw TypeError("Cannot add the same private member more than once");
3679
4344
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3680
4345
  };
3681
- var __privateSet$2 = (obj, member, value, setter) => {
3682
- __accessCheck$2(obj, member, "write to private field");
3683
- setter ? setter.call(obj, value) : member.set(obj, value);
3684
- return value;
3685
- };
3686
- var _tables, _schemaTables$1;
4346
+ var _tables;
3687
4347
  class SchemaPlugin extends XataPlugin {
3688
- constructor(schemaTables) {
4348
+ constructor() {
3689
4349
  super();
3690
4350
  __privateAdd$2(this, _tables, {});
3691
- __privateAdd$2(this, _schemaTables$1, void 0);
3692
- __privateSet$2(this, _schemaTables$1, schemaTables);
3693
4351
  }
3694
4352
  build(pluginOptions) {
3695
4353
  const db = new Proxy(
@@ -3698,101 +4356,234 @@ class SchemaPlugin extends XataPlugin {
3698
4356
  get: (_target, table) => {
3699
4357
  if (!isString(table))
3700
4358
  throw new Error("Invalid table name");
3701
- if (__privateGet$2(this, _tables)[table] === void 0) {
3702
- __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
4359
+ if (__privateGet$1(this, _tables)[table] === void 0) {
4360
+ __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
3703
4361
  }
3704
- return __privateGet$2(this, _tables)[table];
4362
+ return __privateGet$1(this, _tables)[table];
3705
4363
  }
3706
4364
  }
3707
4365
  );
3708
- const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
4366
+ const tableNames = pluginOptions.tables?.map(({ name }) => name) ?? [];
3709
4367
  for (const table of tableNames) {
3710
- db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
4368
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
3711
4369
  }
3712
4370
  return db;
3713
4371
  }
3714
4372
  }
3715
4373
  _tables = new WeakMap();
3716
- _schemaTables$1 = new WeakMap();
4374
+
4375
+ class FilesPlugin extends XataPlugin {
4376
+ build(pluginOptions) {
4377
+ return {
4378
+ download: async (location) => {
4379
+ const { table, record, column, fileId = "" } = location ?? {};
4380
+ return await getFileItem({
4381
+ pathParams: {
4382
+ workspace: "{workspaceId}",
4383
+ dbBranchName: "{dbBranch}",
4384
+ region: "{region}",
4385
+ tableName: table ?? "",
4386
+ recordId: record ?? "",
4387
+ columnName: column ?? "",
4388
+ fileId
4389
+ },
4390
+ ...pluginOptions,
4391
+ rawResponse: true
4392
+ });
4393
+ },
4394
+ upload: async (location, file, options) => {
4395
+ const { table, record, column, fileId = "" } = location ?? {};
4396
+ const resolvedFile = await file;
4397
+ const contentType = options?.mediaType || getContentType(resolvedFile);
4398
+ const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
4399
+ return await putFileItem({
4400
+ ...pluginOptions,
4401
+ pathParams: {
4402
+ workspace: "{workspaceId}",
4403
+ dbBranchName: "{dbBranch}",
4404
+ region: "{region}",
4405
+ tableName: table ?? "",
4406
+ recordId: record ?? "",
4407
+ columnName: column ?? "",
4408
+ fileId
4409
+ },
4410
+ body,
4411
+ headers: { "Content-Type": contentType }
4412
+ });
4413
+ },
4414
+ delete: async (location) => {
4415
+ const { table, record, column, fileId = "" } = location ?? {};
4416
+ return await deleteFileItem({
4417
+ pathParams: {
4418
+ workspace: "{workspaceId}",
4419
+ dbBranchName: "{dbBranch}",
4420
+ region: "{region}",
4421
+ tableName: table ?? "",
4422
+ recordId: record ?? "",
4423
+ columnName: column ?? "",
4424
+ fileId
4425
+ },
4426
+ ...pluginOptions
4427
+ });
4428
+ }
4429
+ };
4430
+ }
4431
+ }
4432
+ function getContentType(file) {
4433
+ if (typeof file === "string") {
4434
+ return "text/plain";
4435
+ }
4436
+ if ("mediaType" in file && file.mediaType !== void 0) {
4437
+ return file.mediaType;
4438
+ }
4439
+ if (isBlob(file)) {
4440
+ return file.type;
4441
+ }
4442
+ try {
4443
+ return file.type;
4444
+ } catch (e) {
4445
+ }
4446
+ return "application/octet-stream";
4447
+ }
3717
4448
 
3718
4449
  var __accessCheck$1 = (obj, member, msg) => {
3719
4450
  if (!member.has(obj))
3720
4451
  throw TypeError("Cannot " + msg);
3721
4452
  };
3722
- var __privateGet$1 = (obj, member, getter) => {
3723
- __accessCheck$1(obj, member, "read from private field");
3724
- return getter ? getter.call(obj) : member.get(obj);
3725
- };
3726
4453
  var __privateAdd$1 = (obj, member, value) => {
3727
4454
  if (member.has(obj))
3728
4455
  throw TypeError("Cannot add the same private member more than once");
3729
4456
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3730
4457
  };
3731
- var __privateSet$1 = (obj, member, value, setter) => {
3732
- __accessCheck$1(obj, member, "write to private field");
3733
- setter ? setter.call(obj, value) : member.set(obj, value);
3734
- return value;
3735
- };
3736
4458
  var __privateMethod$1 = (obj, member, method) => {
3737
4459
  __accessCheck$1(obj, member, "access private method");
3738
4460
  return method;
3739
4461
  };
3740
- var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
4462
+ var _search, search_fn;
3741
4463
  class SearchPlugin extends XataPlugin {
3742
- constructor(db, schemaTables) {
4464
+ constructor(db) {
3743
4465
  super();
3744
4466
  this.db = db;
3745
4467
  __privateAdd$1(this, _search);
3746
- __privateAdd$1(this, _getSchemaTables);
3747
- __privateAdd$1(this, _schemaTables, void 0);
3748
- __privateSet$1(this, _schemaTables, schemaTables);
3749
4468
  }
3750
4469
  build(pluginOptions) {
3751
4470
  return {
3752
4471
  all: async (query, options = {}) => {
3753
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3754
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3755
- return records.map((record) => {
3756
- const { table = "orphan" } = record.xata;
3757
- return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3758
- });
4472
+ const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4473
+ return {
4474
+ totalCount,
4475
+ records: records.map((record) => {
4476
+ const { table = "orphan" } = record.xata;
4477
+ return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
4478
+ })
4479
+ };
3759
4480
  },
3760
4481
  byTable: async (query, options = {}) => {
3761
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3762
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3763
- return records.reduce((acc, record) => {
4482
+ const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4483
+ const records = rawRecords.reduce((acc, record) => {
3764
4484
  const { table = "orphan" } = record.xata;
3765
4485
  const items = acc[table] ?? [];
3766
- const item = initObject(this.db, schemaTables, table, record, ["*"]);
4486
+ const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
3767
4487
  return { ...acc, [table]: [...items, item] };
3768
4488
  }, {});
4489
+ return { totalCount, records };
3769
4490
  }
3770
4491
  };
3771
4492
  }
3772
4493
  }
3773
- _schemaTables = new WeakMap();
3774
4494
  _search = new WeakSet();
3775
4495
  search_fn = async function(query, options, pluginOptions) {
3776
4496
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3777
- const { records } = await searchBranch({
4497
+ const { records, totalCount } = await searchBranch({
3778
4498
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4499
+ // @ts-expect-error Filter properties do not match inferred type
3779
4500
  body: { tables, query, fuzziness, prefix, highlight, page },
3780
4501
  ...pluginOptions
3781
4502
  });
3782
- return records;
3783
- };
3784
- _getSchemaTables = new WeakSet();
3785
- getSchemaTables_fn = async function(pluginOptions) {
3786
- if (__privateGet$1(this, _schemaTables))
3787
- return __privateGet$1(this, _schemaTables);
3788
- const { schema } = await getBranchDetails({
3789
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3790
- ...pluginOptions
3791
- });
3792
- __privateSet$1(this, _schemaTables, schema.tables);
3793
- return schema.tables;
4503
+ return { records, totalCount };
3794
4504
  };
3795
4505
 
4506
+ function escapeElement(elementRepresentation) {
4507
+ const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
4508
+ return '"' + escaped + '"';
4509
+ }
4510
+ function arrayString(val) {
4511
+ let result = "{";
4512
+ for (let i = 0; i < val.length; i++) {
4513
+ if (i > 0) {
4514
+ result = result + ",";
4515
+ }
4516
+ if (val[i] === null || typeof val[i] === "undefined") {
4517
+ result = result + "NULL";
4518
+ } else if (Array.isArray(val[i])) {
4519
+ result = result + arrayString(val[i]);
4520
+ } else if (val[i] instanceof Buffer) {
4521
+ result += "\\\\x" + val[i].toString("hex");
4522
+ } else {
4523
+ result += escapeElement(prepareValue(val[i]));
4524
+ }
4525
+ }
4526
+ result = result + "}";
4527
+ return result;
4528
+ }
4529
+ function prepareValue(value) {
4530
+ if (!isDefined(value))
4531
+ return null;
4532
+ if (value instanceof Date) {
4533
+ return value.toISOString();
4534
+ }
4535
+ if (Array.isArray(value)) {
4536
+ return arrayString(value);
4537
+ }
4538
+ if (isObject(value)) {
4539
+ return JSON.stringify(value);
4540
+ }
4541
+ try {
4542
+ return value.toString();
4543
+ } catch (e) {
4544
+ return value;
4545
+ }
4546
+ }
4547
+ function prepareParams(param1, param2) {
4548
+ if (isString(param1)) {
4549
+ return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
4550
+ }
4551
+ if (isStringArray(param1)) {
4552
+ const statement = param1.reduce((acc, curr, index) => {
4553
+ return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
4554
+ }, "");
4555
+ return { statement, params: param2?.map((value) => prepareValue(value)) };
4556
+ }
4557
+ if (isObject(param1)) {
4558
+ const { statement, params, consistency } = param1;
4559
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency };
4560
+ }
4561
+ throw new Error("Invalid query");
4562
+ }
4563
+
4564
+ class SQLPlugin extends XataPlugin {
4565
+ build(pluginOptions) {
4566
+ return async (query, ...parameters) => {
4567
+ if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
4568
+ throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
4569
+ }
4570
+ const { statement, params, consistency } = prepareParams(query, parameters);
4571
+ const { records, warning, columns } = await sqlQuery({
4572
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4573
+ body: { statement, params, consistency },
4574
+ ...pluginOptions
4575
+ });
4576
+ return { records, warning, columns };
4577
+ };
4578
+ }
4579
+ }
4580
+ function isTemplateStringsArray(strings) {
4581
+ return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
4582
+ }
4583
+ function isParamsObject(params) {
4584
+ return isObject(params) && "statement" in params;
4585
+ }
4586
+
3796
4587
  class TransactionPlugin extends XataPlugin {
3797
4588
  build(pluginOptions) {
3798
4589
  return {
@@ -3833,7 +4624,7 @@ var __privateMethod = (obj, member, method) => {
3833
4624
  const buildClient = (plugins) => {
3834
4625
  var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3835
4626
  return _a = class {
3836
- constructor(options = {}, schemaTables) {
4627
+ constructor(options = {}, tables) {
3837
4628
  __privateAdd(this, _parseOptions);
3838
4629
  __privateAdd(this, _getFetchProps);
3839
4630
  __privateAdd(this, _options, void 0);
@@ -3842,14 +4633,20 @@ const buildClient = (plugins) => {
3842
4633
  const pluginOptions = {
3843
4634
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3844
4635
  cache: safeOptions.cache,
3845
- host: safeOptions.host
4636
+ host: safeOptions.host,
4637
+ tables
3846
4638
  };
3847
- const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3848
- const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
4639
+ const db = new SchemaPlugin().build(pluginOptions);
4640
+ const search = new SearchPlugin(db).build(pluginOptions);
3849
4641
  const transactions = new TransactionPlugin().build(pluginOptions);
4642
+ const sql = new SQLPlugin().build(pluginOptions);
4643
+ const files = new FilesPlugin().build(pluginOptions);
4644
+ this.schema = { tables };
3850
4645
  this.db = db;
3851
4646
  this.search = search;
3852
4647
  this.transactions = transactions;
4648
+ this.sql = sql;
4649
+ this.files = files;
3853
4650
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3854
4651
  if (namespace === void 0)
3855
4652
  continue;
@@ -3930,6 +4727,7 @@ const buildClient = (plugins) => {
3930
4727
  fetch,
3931
4728
  apiKey,
3932
4729
  apiUrl: "",
4730
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3933
4731
  workspacesApiUrl: (path, params) => {
3934
4732
  const hasBranch = params.dbBranchName ?? params.branch;
3935
4733
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
@@ -4012,21 +4810,6 @@ const deserialize = (json) => {
4012
4810
  return defaultSerializer.fromJSON(json);
4013
4811
  };
4014
4812
 
4015
- function buildWorkerRunner(config) {
4016
- return function xataWorker(name, worker) {
4017
- return async (...args) => {
4018
- const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
4019
- const result = await fetch(url, {
4020
- method: "POST",
4021
- headers: { "Content-Type": "application/json" },
4022
- body: serialize({ args })
4023
- });
4024
- const text = await result.text();
4025
- return deserialize(text);
4026
- };
4027
- };
4028
- }
4029
-
4030
4813
  class XataError extends Error {
4031
4814
  constructor(message, status) {
4032
4815
  super(message);
@@ -4034,5 +4817,5 @@ class XataError extends Error {
4034
4817
  }
4035
4818
  }
4036
4819
 
4037
- 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, 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 };
4820
+ export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollMigrationHistory, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
4038
4821
  //# sourceMappingURL=index.mjs.map