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