@xata.io/client 0.0.0-alpha.vf61048f → 0.0.0-alpha.vf63fddb

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,11 @@ 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
+ }
32
36
  function isObject(value) {
33
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
37
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof Blob);
34
38
  }
35
39
  function isDefined(value) {
36
40
  return value !== null && value !== void 0;
@@ -85,6 +89,27 @@ function chunk(array, chunkSize) {
85
89
  async function timeout(ms) {
86
90
  return new Promise((resolve) => setTimeout(resolve, ms));
87
91
  }
92
+ function timeoutWithCancel(ms) {
93
+ let timeoutId;
94
+ const promise = new Promise((resolve) => {
95
+ timeoutId = setTimeout(() => {
96
+ resolve();
97
+ }, ms);
98
+ });
99
+ return {
100
+ cancel: () => clearTimeout(timeoutId),
101
+ promise
102
+ };
103
+ }
104
+ function promiseMap(inputValues, mapper) {
105
+ const reducer = (acc$, inputValue) => acc$.then(
106
+ (acc) => mapper(inputValue).then((result) => {
107
+ acc.push(result);
108
+ return acc;
109
+ })
110
+ );
111
+ return inputValues.reduce(reducer, Promise.resolve([]));
112
+ }
88
113
 
89
114
  function getEnvironment() {
90
115
  try {
@@ -93,8 +118,10 @@ function getEnvironment() {
93
118
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
94
119
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
95
120
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
96
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
97
- fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
121
+ deployPreview: process.env.XATA_PREVIEW,
122
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
123
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
124
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
98
125
  };
99
126
  }
100
127
  } catch (err) {
@@ -105,8 +132,10 @@ function getEnvironment() {
105
132
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
106
133
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
107
134
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
108
- envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
109
- fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
135
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
136
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
137
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
138
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
110
139
  };
111
140
  }
112
141
  } catch (err) {
@@ -115,8 +144,10 @@ function getEnvironment() {
115
144
  apiKey: getGlobalApiKey(),
116
145
  databaseURL: getGlobalDatabaseURL(),
117
146
  branch: getGlobalBranch(),
118
- envBranch: void 0,
119
- fallbackBranch: getGlobalFallbackBranch()
147
+ deployPreview: void 0,
148
+ deployPreviewBranch: void 0,
149
+ vercelGitCommitRef: void 0,
150
+ vercelGitRepoOwner: void 0
120
151
  };
121
152
  }
122
153
  function getEnableBrowserVariable() {
@@ -159,42 +190,59 @@ function getGlobalBranch() {
159
190
  return void 0;
160
191
  }
161
192
  }
162
- function getGlobalFallbackBranch() {
193
+ function getDatabaseURL() {
163
194
  try {
164
- return XATA_FALLBACK_BRANCH;
195
+ const { databaseURL } = getEnvironment();
196
+ return databaseURL;
165
197
  } catch (err) {
166
198
  return void 0;
167
199
  }
168
200
  }
169
- async function getGitBranch() {
170
- const cmd = ["git", "branch", "--show-current"];
171
- const fullCmd = cmd.join(" ");
172
- const nodeModule = ["child", "process"].join("_");
173
- const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
201
+ function getAPIKey() {
174
202
  try {
175
- if (typeof require === "function") {
176
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
177
- }
203
+ const { apiKey } = getEnvironment();
204
+ return apiKey;
178
205
  } catch (err) {
206
+ return void 0;
179
207
  }
208
+ }
209
+ function getBranch() {
180
210
  try {
181
- if (isObject(Deno)) {
182
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
183
- return new TextDecoder().decode(await process2.output()).trim();
184
- }
211
+ const { branch } = getEnvironment();
212
+ return branch;
185
213
  } catch (err) {
214
+ return void 0;
186
215
  }
187
216
  }
188
-
189
- function getAPIKey() {
217
+ function buildPreviewBranchName({ org, branch }) {
218
+ return `preview-${org}-${branch}`;
219
+ }
220
+ function getPreviewBranch() {
190
221
  try {
191
- const { apiKey } = getEnvironment();
192
- return apiKey;
222
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
223
+ if (deployPreviewBranch)
224
+ return deployPreviewBranch;
225
+ switch (deployPreview) {
226
+ case "vercel": {
227
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
228
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
229
+ return void 0;
230
+ }
231
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
232
+ }
233
+ }
234
+ return void 0;
193
235
  } catch (err) {
194
236
  return void 0;
195
237
  }
196
238
  }
197
239
 
240
+ var __defProp$8 = Object.defineProperty;
241
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
242
+ var __publicField$8 = (obj, key, value) => {
243
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
244
+ return value;
245
+ };
198
246
  var __accessCheck$8 = (obj, member, msg) => {
199
247
  if (!member.has(obj))
200
248
  throw TypeError("Cannot " + msg);
@@ -218,6 +266,7 @@ var __privateMethod$4 = (obj, member, method) => {
218
266
  return method;
219
267
  };
220
268
  var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
269
+ const REQUEST_TIMEOUT = 3e4;
221
270
  function getFetchImplementation(userFetch) {
222
271
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
223
272
  const fetchImpl = userFetch ?? globalFetch;
@@ -234,6 +283,8 @@ class ApiRequestPool {
234
283
  __privateAdd$8(this, _fetch, void 0);
235
284
  __privateAdd$8(this, _queue, void 0);
236
285
  __privateAdd$8(this, _concurrency, void 0);
286
+ __publicField$8(this, "running");
287
+ __publicField$8(this, "started");
237
288
  __privateSet$8(this, _queue, []);
238
289
  __privateSet$8(this, _concurrency, concurrency);
239
290
  this.running = 0;
@@ -249,18 +300,22 @@ class ApiRequestPool {
249
300
  return __privateGet$8(this, _fetch);
250
301
  }
251
302
  request(url, options) {
252
- const start = new Date();
253
- const fetch2 = this.getFetch();
303
+ const start = /* @__PURE__ */ new Date();
304
+ const fetchImpl = this.getFetch();
254
305
  const runRequest = async (stalled = false) => {
255
- const response = await fetch2(url, options);
306
+ const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
307
+ const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
308
+ if (!response) {
309
+ throw new Error("Request timed out");
310
+ }
256
311
  if (response.status === 429) {
257
312
  const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
258
313
  await timeout(rateLimitReset * 1e3);
259
314
  return await runRequest(true);
260
315
  }
261
316
  if (stalled) {
262
- const stalledTime = new Date().getTime() - start.getTime();
263
- console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
317
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
318
+ console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
264
319
  }
265
320
  return response;
266
321
  };
@@ -302,16 +357,199 @@ function generateUUID() {
302
357
  });
303
358
  }
304
359
 
305
- const VERSION = "0.21.6";
360
+ async function getBytes(stream, onChunk) {
361
+ const reader = stream.getReader();
362
+ let result;
363
+ while (!(result = await reader.read()).done) {
364
+ onChunk(result.value);
365
+ }
366
+ }
367
+ function getLines(onLine) {
368
+ let buffer;
369
+ let position;
370
+ let fieldLength;
371
+ let discardTrailingNewline = false;
372
+ return function onChunk(arr) {
373
+ if (buffer === void 0) {
374
+ buffer = arr;
375
+ position = 0;
376
+ fieldLength = -1;
377
+ } else {
378
+ buffer = concat(buffer, arr);
379
+ }
380
+ const bufLength = buffer.length;
381
+ let lineStart = 0;
382
+ while (position < bufLength) {
383
+ if (discardTrailingNewline) {
384
+ if (buffer[position] === 10 /* NewLine */) {
385
+ lineStart = ++position;
386
+ }
387
+ discardTrailingNewline = false;
388
+ }
389
+ let lineEnd = -1;
390
+ for (; position < bufLength && lineEnd === -1; ++position) {
391
+ switch (buffer[position]) {
392
+ case 58 /* Colon */:
393
+ if (fieldLength === -1) {
394
+ fieldLength = position - lineStart;
395
+ }
396
+ break;
397
+ case 13 /* CarriageReturn */:
398
+ discardTrailingNewline = true;
399
+ case 10 /* NewLine */:
400
+ lineEnd = position;
401
+ break;
402
+ }
403
+ }
404
+ if (lineEnd === -1) {
405
+ break;
406
+ }
407
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
408
+ lineStart = position;
409
+ fieldLength = -1;
410
+ }
411
+ if (lineStart === bufLength) {
412
+ buffer = void 0;
413
+ } else if (lineStart !== 0) {
414
+ buffer = buffer.subarray(lineStart);
415
+ position -= lineStart;
416
+ }
417
+ };
418
+ }
419
+ function getMessages(onId, onRetry, onMessage) {
420
+ let message = newMessage();
421
+ const decoder = new TextDecoder();
422
+ return function onLine(line, fieldLength) {
423
+ if (line.length === 0) {
424
+ onMessage?.(message);
425
+ message = newMessage();
426
+ } else if (fieldLength > 0) {
427
+ const field = decoder.decode(line.subarray(0, fieldLength));
428
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
429
+ const value = decoder.decode(line.subarray(valueOffset));
430
+ switch (field) {
431
+ case "data":
432
+ message.data = message.data ? message.data + "\n" + value : value;
433
+ break;
434
+ case "event":
435
+ message.event = value;
436
+ break;
437
+ case "id":
438
+ onId(message.id = value);
439
+ break;
440
+ case "retry":
441
+ const retry = parseInt(value, 10);
442
+ if (!isNaN(retry)) {
443
+ onRetry(message.retry = retry);
444
+ }
445
+ break;
446
+ }
447
+ }
448
+ };
449
+ }
450
+ function concat(a, b) {
451
+ const res = new Uint8Array(a.length + b.length);
452
+ res.set(a);
453
+ res.set(b, a.length);
454
+ return res;
455
+ }
456
+ function newMessage() {
457
+ return {
458
+ data: "",
459
+ event: "",
460
+ id: "",
461
+ retry: void 0
462
+ };
463
+ }
464
+ const EventStreamContentType = "text/event-stream";
465
+ const LastEventId = "last-event-id";
466
+ function fetchEventSource(input, {
467
+ signal: inputSignal,
468
+ headers: inputHeaders,
469
+ onopen: inputOnOpen,
470
+ onmessage,
471
+ onclose,
472
+ onerror,
473
+ fetch: inputFetch,
474
+ ...rest
475
+ }) {
476
+ return new Promise((resolve, reject) => {
477
+ const headers = { ...inputHeaders };
478
+ if (!headers.accept) {
479
+ headers.accept = EventStreamContentType;
480
+ }
481
+ let curRequestController;
482
+ function dispose() {
483
+ curRequestController.abort();
484
+ }
485
+ inputSignal?.addEventListener("abort", () => {
486
+ dispose();
487
+ resolve();
488
+ });
489
+ const fetchImpl = inputFetch ?? fetch;
490
+ const onopen = inputOnOpen ?? defaultOnOpen;
491
+ async function create() {
492
+ curRequestController = new AbortController();
493
+ try {
494
+ const response = await fetchImpl(input, {
495
+ ...rest,
496
+ headers,
497
+ signal: curRequestController.signal
498
+ });
499
+ await onopen(response);
500
+ await getBytes(
501
+ response.body,
502
+ getLines(
503
+ getMessages(
504
+ (id) => {
505
+ if (id) {
506
+ headers[LastEventId] = id;
507
+ } else {
508
+ delete headers[LastEventId];
509
+ }
510
+ },
511
+ (_retry) => {
512
+ },
513
+ onmessage
514
+ )
515
+ )
516
+ );
517
+ onclose?.();
518
+ dispose();
519
+ resolve();
520
+ } catch (err) {
521
+ }
522
+ }
523
+ create();
524
+ });
525
+ }
526
+ function defaultOnOpen(response) {
527
+ const contentType = response.headers?.get("content-type");
528
+ if (!contentType?.startsWith(EventStreamContentType)) {
529
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
530
+ }
531
+ }
532
+
533
+ const VERSION = "0.26.4";
306
534
 
535
+ var __defProp$7 = Object.defineProperty;
536
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
537
+ var __publicField$7 = (obj, key, value) => {
538
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
539
+ return value;
540
+ };
307
541
  class ErrorWithCause extends Error {
308
542
  constructor(message, options) {
309
543
  super(message, options);
544
+ __publicField$7(this, "cause");
310
545
  }
311
546
  }
312
547
  class FetcherError extends ErrorWithCause {
313
548
  constructor(status, data, requestId) {
314
549
  super(getMessage(data));
550
+ __publicField$7(this, "status");
551
+ __publicField$7(this, "requestId");
552
+ __publicField$7(this, "errors");
315
553
  this.status = status;
316
554
  this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
317
555
  this.requestId = requestId;
@@ -378,6 +616,18 @@ function hostHeader(url) {
378
616
  const { groups } = pattern.exec(url) ?? {};
379
617
  return groups?.host ? { Host: groups.host } : {};
380
618
  }
619
+ async function parseBody(body, headers) {
620
+ if (!isDefined(body))
621
+ return void 0;
622
+ if (body instanceof Blob || typeof body.text === "function") {
623
+ return body;
624
+ }
625
+ const { "Content-Type": contentType } = headers ?? {};
626
+ if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
627
+ return JSON.stringify(body);
628
+ }
629
+ return body;
630
+ }
381
631
  const defaultClientID = generateUUID();
382
632
  async function fetch$1({
383
633
  url: path,
@@ -386,7 +636,7 @@ async function fetch$1({
386
636
  headers: customHeaders,
387
637
  pathParams,
388
638
  queryParams,
389
- fetchImpl,
639
+ fetch: fetch2,
390
640
  apiKey,
391
641
  endpoint,
392
642
  apiUrl,
@@ -396,9 +646,11 @@ async function fetch$1({
396
646
  clientID,
397
647
  sessionID,
398
648
  clientName,
399
- fetchOptions = {}
649
+ xataAgentExtra,
650
+ fetchOptions = {},
651
+ rawResponse = false
400
652
  }) {
401
- pool.setFetch(fetchImpl);
653
+ pool.setFetch(fetch2);
402
654
  return await trace(
403
655
  `${method.toUpperCase()} ${path}`,
404
656
  async ({ setAttributes }) => {
@@ -412,9 +664,10 @@ async function fetch$1({
412
664
  const xataAgent = compact([
413
665
  ["client", "TS_SDK"],
414
666
  ["version", VERSION],
415
- isDefined(clientName) ? ["service", clientName] : void 0
667
+ isDefined(clientName) ? ["service", clientName] : void 0,
668
+ ...Object.entries(xataAgentExtra ?? {})
416
669
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
417
- const headers = {
670
+ const headers = compactObject({
418
671
  "Accept-Encoding": "identity",
419
672
  "Content-Type": "application/json",
420
673
  "X-Xata-Client-ID": clientID ?? defaultClientID,
@@ -423,11 +676,11 @@ async function fetch$1({
423
676
  ...customHeaders,
424
677
  ...hostHeader(fullUrl),
425
678
  Authorization: `Bearer ${apiKey}`
426
- };
679
+ });
427
680
  const response = await pool.request(url, {
428
681
  ...fetchOptions,
429
682
  method: method.toUpperCase(),
430
- body: body ? JSON.stringify(body) : void 0,
683
+ body: await parseBody(body, headers),
431
684
  headers,
432
685
  signal
433
686
  });
@@ -438,8 +691,12 @@ async function fetch$1({
438
691
  [TraceAttributes.HTTP_REQUEST_ID]: requestId,
439
692
  [TraceAttributes.HTTP_STATUS_CODE]: response.status,
440
693
  [TraceAttributes.HTTP_HOST]: host,
441
- [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
694
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
695
+ [TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
442
696
  });
697
+ const message = response.headers?.get("x-xata-message");
698
+ if (message)
699
+ console.warn(message);
443
700
  if (response.status === 204) {
444
701
  return {};
445
702
  }
@@ -447,7 +704,7 @@ async function fetch$1({
447
704
  throw new FetcherError(response.status, "Rate limit exceeded", requestId);
448
705
  }
449
706
  try {
450
- const jsonResponse = await response.json();
707
+ const jsonResponse = rawResponse ? await response.blob() : await response.json();
451
708
  if (response.ok) {
452
709
  return jsonResponse;
453
710
  }
@@ -459,6 +716,59 @@ async function fetch$1({
459
716
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
460
717
  );
461
718
  }
719
+ function fetchSSERequest({
720
+ url: path,
721
+ method,
722
+ body,
723
+ headers: customHeaders,
724
+ pathParams,
725
+ queryParams,
726
+ fetch: fetch2,
727
+ apiKey,
728
+ endpoint,
729
+ apiUrl,
730
+ workspacesApiUrl,
731
+ onMessage,
732
+ onError,
733
+ onClose,
734
+ signal,
735
+ clientID,
736
+ sessionID,
737
+ clientName,
738
+ xataAgentExtra
739
+ }) {
740
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
741
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
742
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
743
+ void fetchEventSource(url, {
744
+ method,
745
+ body: JSON.stringify(body),
746
+ fetch: fetch2,
747
+ signal,
748
+ headers: {
749
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
750
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
751
+ "X-Xata-Agent": compact([
752
+ ["client", "TS_SDK"],
753
+ ["version", VERSION],
754
+ isDefined(clientName) ? ["service", clientName] : void 0,
755
+ ...Object.entries(xataAgentExtra ?? {})
756
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
757
+ ...customHeaders,
758
+ Authorization: `Bearer ${apiKey}`,
759
+ "Content-Type": "application/json"
760
+ },
761
+ onmessage(ev) {
762
+ onMessage?.(JSON.parse(ev.data));
763
+ },
764
+ onerror(ev) {
765
+ onError?.(JSON.parse(ev.data));
766
+ },
767
+ onclose() {
768
+ onClose?.();
769
+ }
770
+ });
771
+ }
462
772
  function parseUrl(url) {
463
773
  try {
464
774
  const { host, protocol } = new URL(url);
@@ -489,6 +799,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
489
799
  ...variables,
490
800
  signal
491
801
  });
802
+ const copyBranch = (variables, signal) => dataPlaneFetch({
803
+ url: "/db/{dbBranchName}/copy",
804
+ method: "post",
805
+ ...variables,
806
+ signal
807
+ });
492
808
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
493
809
  url: "/db/{dbBranchName}/metadata",
494
810
  method: "put",
@@ -538,6 +854,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
538
854
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
539
855
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
540
856
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
857
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
541
858
  const createTable = (variables, signal) => dataPlaneFetch({
542
859
  url: "/db/{dbBranchName}/tables/{tableName}",
543
860
  method: "put",
@@ -582,6 +899,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
582
899
  });
583
900
  const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
584
901
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
902
+ const getFileItem = (variables, signal) => dataPlaneFetch({
903
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
904
+ method: "get",
905
+ ...variables,
906
+ signal
907
+ });
908
+ const putFileItem = (variables, signal) => dataPlaneFetch({
909
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
910
+ method: "put",
911
+ ...variables,
912
+ signal
913
+ });
914
+ const deleteFileItem = (variables, signal) => dataPlaneFetch({
915
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
916
+ method: "delete",
917
+ ...variables,
918
+ signal
919
+ });
920
+ const getFile = (variables, signal) => dataPlaneFetch({
921
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
922
+ method: "get",
923
+ ...variables,
924
+ signal
925
+ });
926
+ const putFile = (variables, signal) => dataPlaneFetch({
927
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
928
+ method: "put",
929
+ ...variables,
930
+ signal
931
+ });
932
+ const deleteFile = (variables, signal) => dataPlaneFetch({
933
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
934
+ method: "delete",
935
+ ...variables,
936
+ signal
937
+ });
585
938
  const getRecord = (variables, signal) => dataPlaneFetch({
586
939
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
587
940
  method: "get",
@@ -611,14 +964,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
611
964
  ...variables,
612
965
  signal
613
966
  });
967
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
968
+ const askTable = (variables, signal) => dataPlaneFetch({
969
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
970
+ method: "post",
971
+ ...variables,
972
+ signal
973
+ });
974
+ const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
614
975
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
615
976
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
977
+ const fileAccess = (variables, signal) => dataPlaneFetch({
978
+ url: "/file/{fileId}",
979
+ method: "get",
980
+ ...variables,
981
+ signal
982
+ });
983
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
984
+ url: "/db/{dbBranchName}/sql",
985
+ method: "post",
986
+ ...variables,
987
+ signal
988
+ });
616
989
  const operationsByTag$2 = {
617
990
  branch: {
618
991
  getBranchList,
619
992
  getBranchDetails,
620
993
  createBranch,
621
994
  deleteBranch,
995
+ copyBranch,
622
996
  updateBranchMetadata,
623
997
  getBranchMetadata,
624
998
  getBranchStats,
@@ -636,7 +1010,8 @@ const operationsByTag$2 = {
636
1010
  compareBranchSchemas,
637
1011
  updateBranchSchema,
638
1012
  previewBranchSchemaEdit,
639
- applyBranchSchemaEdit
1013
+ applyBranchSchemaEdit,
1014
+ pushBranchMigrations
640
1015
  },
641
1016
  migrationRequests: {
642
1017
  queryMigrationRequests,
@@ -670,11 +1045,24 @@ const operationsByTag$2 = {
670
1045
  deleteRecord,
671
1046
  bulkInsertTableRecords
672
1047
  },
673
- searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
1048
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1049
+ searchAndFilter: {
1050
+ queryTable,
1051
+ searchBranch,
1052
+ searchTable,
1053
+ vectorSearchTable,
1054
+ askTable,
1055
+ askTableSession,
1056
+ summarizeTable,
1057
+ aggregateTable
1058
+ },
1059
+ sql: { sqlQuery }
674
1060
  };
675
1061
 
676
1062
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
677
1063
 
1064
+ const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
1065
+ const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
678
1066
  const getUser = (variables, signal) => controlPlaneFetch({
679
1067
  url: "/user",
680
1068
  method: "get",
@@ -711,6 +1099,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
711
1099
  ...variables,
712
1100
  signal
713
1101
  });
1102
+ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
1103
+ url: "/user/oauth/clients",
1104
+ method: "get",
1105
+ ...variables,
1106
+ signal
1107
+ });
1108
+ const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
1109
+ url: "/user/oauth/clients/{clientId}",
1110
+ method: "delete",
1111
+ ...variables,
1112
+ signal
1113
+ });
1114
+ const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
1115
+ url: "/user/oauth/tokens",
1116
+ method: "get",
1117
+ ...variables,
1118
+ signal
1119
+ });
1120
+ const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
1121
+ url: "/user/oauth/tokens/{token}",
1122
+ method: "delete",
1123
+ ...variables,
1124
+ signal
1125
+ });
1126
+ const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
714
1127
  const getWorkspacesList = (variables, signal) => controlPlaneFetch({
715
1128
  url: "/workspaces",
716
1129
  method: "get",
@@ -769,6 +1182,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
769
1182
  });
770
1183
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
771
1184
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1185
+ const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
1186
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
1187
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
1188
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
772
1189
  const listRegions = (variables, signal) => controlPlaneFetch({
773
1190
  url: "/workspaces/{workspaceId}/regions",
774
1191
  method: "get",
@@ -776,6 +1193,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
776
1193
  signal
777
1194
  });
778
1195
  const operationsByTag$1 = {
1196
+ oAuth: {
1197
+ getAuthorizationCode,
1198
+ grantAuthorizationCode,
1199
+ getUserOAuthClients,
1200
+ deleteUserOAuthClient,
1201
+ getUserOAuthAccessTokens,
1202
+ deleteOAuthAccessToken,
1203
+ updateOAuthAccessToken
1204
+ },
779
1205
  users: { getUser, updateUser, deleteUser },
780
1206
  authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
781
1207
  workspaces: {
@@ -801,6 +1227,10 @@ const operationsByTag$1 = {
801
1227
  deleteDatabase,
802
1228
  getDatabaseMetadata,
803
1229
  updateDatabaseMetadata,
1230
+ renameDatabase,
1231
+ getDatabaseGithubSettings,
1232
+ updateDatabaseGithubSettings,
1233
+ deleteDatabaseGithubSettings,
804
1234
  listRegions
805
1235
  }
806
1236
  };
@@ -821,8 +1251,12 @@ const providers = {
821
1251
  workspaces: "https://{workspaceId}.{region}.xata.sh"
822
1252
  },
823
1253
  staging: {
824
- main: "https://staging.xatabase.co",
825
- workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
1254
+ main: "https://api.staging-xata.dev",
1255
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1256
+ },
1257
+ dev: {
1258
+ main: "https://api.dev-xata.dev",
1259
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
826
1260
  }
827
1261
  };
828
1262
  function isHostProviderAlias(alias) {
@@ -840,12 +1274,19 @@ function parseProviderString(provider = "production") {
840
1274
  return null;
841
1275
  return { main, workspaces };
842
1276
  }
1277
+ function buildProviderString(provider) {
1278
+ if (isHostProviderAlias(provider))
1279
+ return provider;
1280
+ return `${provider.main},${provider.workspaces}`;
1281
+ }
843
1282
  function parseWorkspacesUrlParts(url) {
844
1283
  if (!isString(url))
845
1284
  return null;
846
1285
  const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
847
- const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
848
- const match = url.match(regex) || url.match(regexStaging);
1286
+ const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1287
+ const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1288
+ const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1289
+ const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
849
1290
  if (!match)
850
1291
  return null;
851
1292
  return { workspace: match[1], region: match[2] };
@@ -884,10 +1325,11 @@ class XataApiClient {
884
1325
  __privateSet$7(this, _extraProps, {
885
1326
  apiUrl: getHostUrl(provider, "main"),
886
1327
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
887
- fetchImpl: getFetchImplementation(options.fetch),
1328
+ fetch: getFetchImplementation(options.fetch),
888
1329
  apiKey,
889
1330
  trace,
890
1331
  clientName: options.clientName,
1332
+ xataAgentExtra: options.xataAgentExtra,
891
1333
  clientID
892
1334
  });
893
1335
  }
@@ -941,6 +1383,11 @@ class XataApiClient {
941
1383
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
942
1384
  return __privateGet$7(this, _namespaces).records;
943
1385
  }
1386
+ get files() {
1387
+ if (!__privateGet$7(this, _namespaces).files)
1388
+ __privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
1389
+ return __privateGet$7(this, _namespaces).files;
1390
+ }
944
1391
  get searchAndFilter() {
945
1392
  if (!__privateGet$7(this, _namespaces).searchAndFilter)
946
1393
  __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
@@ -1149,6 +1596,20 @@ class BranchApi {
1149
1596
  ...this.extraProps
1150
1597
  });
1151
1598
  }
1599
+ copyBranch({
1600
+ workspace,
1601
+ region,
1602
+ database,
1603
+ branch,
1604
+ destinationBranch,
1605
+ limit
1606
+ }) {
1607
+ return operationsByTag.branch.copyBranch({
1608
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1609
+ body: { destinationBranch, limit },
1610
+ ...this.extraProps
1611
+ });
1612
+ }
1152
1613
  updateBranchMetadata({
1153
1614
  workspace,
1154
1615
  region,
@@ -1504,115 +1965,320 @@ class RecordsApi {
1504
1965
  });
1505
1966
  }
1506
1967
  }
1507
- class SearchAndFilterApi {
1968
+ class FilesApi {
1508
1969
  constructor(extraProps) {
1509
1970
  this.extraProps = extraProps;
1510
1971
  }
1511
- queryTable({
1972
+ getFileItem({
1512
1973
  workspace,
1513
1974
  region,
1514
1975
  database,
1515
1976
  branch,
1516
1977
  table,
1517
- filter,
1518
- sort,
1519
- page,
1520
- columns,
1521
- consistency
1978
+ record,
1979
+ column,
1980
+ fileId
1522
1981
  }) {
1523
- return operationsByTag.searchAndFilter.queryTable({
1524
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1525
- body: { filter, sort, page, columns, consistency },
1982
+ return operationsByTag.files.getFileItem({
1983
+ pathParams: {
1984
+ workspace,
1985
+ region,
1986
+ dbBranchName: `${database}:${branch}`,
1987
+ tableName: table,
1988
+ recordId: record,
1989
+ columnName: column,
1990
+ fileId
1991
+ },
1526
1992
  ...this.extraProps
1527
1993
  });
1528
1994
  }
1529
- searchTable({
1995
+ putFileItem({
1530
1996
  workspace,
1531
1997
  region,
1532
1998
  database,
1533
1999
  branch,
1534
2000
  table,
1535
- query,
1536
- fuzziness,
1537
- target,
1538
- prefix,
1539
- filter,
1540
- highlight,
1541
- boosters
2001
+ record,
2002
+ column,
2003
+ fileId,
2004
+ file
1542
2005
  }) {
1543
- return operationsByTag.searchAndFilter.searchTable({
1544
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1545
- body: { query, fuzziness, target, prefix, filter, highlight, boosters },
2006
+ return operationsByTag.files.putFileItem({
2007
+ pathParams: {
2008
+ workspace,
2009
+ region,
2010
+ dbBranchName: `${database}:${branch}`,
2011
+ tableName: table,
2012
+ recordId: record,
2013
+ columnName: column,
2014
+ fileId
2015
+ },
2016
+ // @ts-ignore
2017
+ body: file,
1546
2018
  ...this.extraProps
1547
2019
  });
1548
2020
  }
1549
- searchBranch({
2021
+ deleteFileItem({
1550
2022
  workspace,
1551
2023
  region,
1552
2024
  database,
1553
2025
  branch,
1554
- tables,
1555
- query,
1556
- fuzziness,
1557
- prefix,
1558
- highlight
2026
+ table,
2027
+ record,
2028
+ column,
2029
+ fileId
1559
2030
  }) {
1560
- return operationsByTag.searchAndFilter.searchBranch({
1561
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1562
- body: { tables, query, fuzziness, prefix, highlight },
2031
+ return operationsByTag.files.deleteFileItem({
2032
+ pathParams: {
2033
+ workspace,
2034
+ region,
2035
+ dbBranchName: `${database}:${branch}`,
2036
+ tableName: table,
2037
+ recordId: record,
2038
+ columnName: column,
2039
+ fileId
2040
+ },
1563
2041
  ...this.extraProps
1564
2042
  });
1565
2043
  }
1566
- summarizeTable({
2044
+ getFile({
1567
2045
  workspace,
1568
2046
  region,
1569
2047
  database,
1570
2048
  branch,
1571
2049
  table,
1572
- filter,
1573
- columns,
1574
- summaries,
1575
- sort,
1576
- summariesFilter,
1577
- page,
1578
- consistency
2050
+ record,
2051
+ column
1579
2052
  }) {
1580
- return operationsByTag.searchAndFilter.summarizeTable({
1581
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1582
- body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
2053
+ return operationsByTag.files.getFile({
2054
+ pathParams: {
2055
+ workspace,
2056
+ region,
2057
+ dbBranchName: `${database}:${branch}`,
2058
+ tableName: table,
2059
+ recordId: record,
2060
+ columnName: column
2061
+ },
1583
2062
  ...this.extraProps
1584
2063
  });
1585
2064
  }
1586
- aggregateTable({
2065
+ putFile({
1587
2066
  workspace,
1588
2067
  region,
1589
2068
  database,
1590
2069
  branch,
1591
2070
  table,
1592
- filter,
1593
- aggs
2071
+ record,
2072
+ column,
2073
+ file
1594
2074
  }) {
1595
- return operationsByTag.searchAndFilter.aggregateTable({
1596
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1597
- body: { filter, aggs },
2075
+ return operationsByTag.files.putFile({
2076
+ pathParams: {
2077
+ workspace,
2078
+ region,
2079
+ dbBranchName: `${database}:${branch}`,
2080
+ tableName: table,
2081
+ recordId: record,
2082
+ columnName: column
2083
+ },
2084
+ body: file,
1598
2085
  ...this.extraProps
1599
2086
  });
1600
2087
  }
1601
- }
1602
- class MigrationRequestsApi {
1603
- constructor(extraProps) {
1604
- this.extraProps = extraProps;
1605
- }
1606
- queryMigrationRequests({
2088
+ deleteFile({
1607
2089
  workspace,
1608
2090
  region,
1609
2091
  database,
1610
- filter,
1611
- sort,
1612
- page,
1613
- columns
2092
+ branch,
2093
+ table,
2094
+ record,
2095
+ column
1614
2096
  }) {
1615
- return operationsByTag.migrationRequests.queryMigrationRequests({
2097
+ return operationsByTag.files.deleteFile({
2098
+ pathParams: {
2099
+ workspace,
2100
+ region,
2101
+ dbBranchName: `${database}:${branch}`,
2102
+ tableName: table,
2103
+ recordId: record,
2104
+ columnName: column
2105
+ },
2106
+ ...this.extraProps
2107
+ });
2108
+ }
2109
+ fileAccess({
2110
+ workspace,
2111
+ region,
2112
+ fileId,
2113
+ verify
2114
+ }) {
2115
+ return operationsByTag.files.fileAccess({
2116
+ pathParams: {
2117
+ workspace,
2118
+ region,
2119
+ fileId
2120
+ },
2121
+ queryParams: { verify },
2122
+ ...this.extraProps
2123
+ });
2124
+ }
2125
+ }
2126
+ class SearchAndFilterApi {
2127
+ constructor(extraProps) {
2128
+ this.extraProps = extraProps;
2129
+ }
2130
+ queryTable({
2131
+ workspace,
2132
+ region,
2133
+ database,
2134
+ branch,
2135
+ table,
2136
+ filter,
2137
+ sort,
2138
+ page,
2139
+ columns,
2140
+ consistency
2141
+ }) {
2142
+ return operationsByTag.searchAndFilter.queryTable({
2143
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2144
+ body: { filter, sort, page, columns, consistency },
2145
+ ...this.extraProps
2146
+ });
2147
+ }
2148
+ searchTable({
2149
+ workspace,
2150
+ region,
2151
+ database,
2152
+ branch,
2153
+ table,
2154
+ query,
2155
+ fuzziness,
2156
+ target,
2157
+ prefix,
2158
+ filter,
2159
+ highlight,
2160
+ boosters
2161
+ }) {
2162
+ return operationsByTag.searchAndFilter.searchTable({
2163
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2164
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
2165
+ ...this.extraProps
2166
+ });
2167
+ }
2168
+ searchBranch({
2169
+ workspace,
2170
+ region,
2171
+ database,
2172
+ branch,
2173
+ tables,
2174
+ query,
2175
+ fuzziness,
2176
+ prefix,
2177
+ highlight
2178
+ }) {
2179
+ return operationsByTag.searchAndFilter.searchBranch({
2180
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2181
+ body: { tables, query, fuzziness, prefix, highlight },
2182
+ ...this.extraProps
2183
+ });
2184
+ }
2185
+ vectorSearchTable({
2186
+ workspace,
2187
+ region,
2188
+ database,
2189
+ branch,
2190
+ table,
2191
+ queryVector,
2192
+ column,
2193
+ similarityFunction,
2194
+ size,
2195
+ filter
2196
+ }) {
2197
+ return operationsByTag.searchAndFilter.vectorSearchTable({
2198
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2199
+ body: { queryVector, column, similarityFunction, size, filter },
2200
+ ...this.extraProps
2201
+ });
2202
+ }
2203
+ askTable({
2204
+ workspace,
2205
+ region,
2206
+ database,
2207
+ branch,
2208
+ table,
2209
+ options
2210
+ }) {
2211
+ return operationsByTag.searchAndFilter.askTable({
2212
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2213
+ body: { ...options },
2214
+ ...this.extraProps
2215
+ });
2216
+ }
2217
+ askTableSession({
2218
+ workspace,
2219
+ region,
2220
+ database,
2221
+ branch,
2222
+ table,
2223
+ sessionId,
2224
+ message
2225
+ }) {
2226
+ return operationsByTag.searchAndFilter.askTableSession({
2227
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
2228
+ body: { message },
2229
+ ...this.extraProps
2230
+ });
2231
+ }
2232
+ summarizeTable({
2233
+ workspace,
2234
+ region,
2235
+ database,
2236
+ branch,
2237
+ table,
2238
+ filter,
2239
+ columns,
2240
+ summaries,
2241
+ sort,
2242
+ summariesFilter,
2243
+ page,
2244
+ consistency
2245
+ }) {
2246
+ return operationsByTag.searchAndFilter.summarizeTable({
2247
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2248
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
2249
+ ...this.extraProps
2250
+ });
2251
+ }
2252
+ aggregateTable({
2253
+ workspace,
2254
+ region,
2255
+ database,
2256
+ branch,
2257
+ table,
2258
+ filter,
2259
+ aggs
2260
+ }) {
2261
+ return operationsByTag.searchAndFilter.aggregateTable({
2262
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2263
+ body: { filter, aggs },
2264
+ ...this.extraProps
2265
+ });
2266
+ }
2267
+ }
2268
+ class MigrationRequestsApi {
2269
+ constructor(extraProps) {
2270
+ this.extraProps = extraProps;
2271
+ }
2272
+ queryMigrationRequests({
2273
+ workspace,
2274
+ region,
2275
+ database,
2276
+ filter,
2277
+ sort,
2278
+ page,
2279
+ columns
2280
+ }) {
2281
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1616
2282
  pathParams: { workspace, region, dbName: database },
1617
2283
  body: { filter, sort, page, columns },
1618
2284
  ...this.extraProps
@@ -1763,11 +2429,13 @@ class MigrationsApi {
1763
2429
  region,
1764
2430
  database,
1765
2431
  branch,
1766
- schema
2432
+ schema,
2433
+ schemaOperations,
2434
+ branchOperations
1767
2435
  }) {
1768
2436
  return operationsByTag.migrations.compareBranchWithUserSchema({
1769
2437
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1770
- body: { schema },
2438
+ body: { schema, schemaOperations, branchOperations },
1771
2439
  ...this.extraProps
1772
2440
  });
1773
2441
  }
@@ -1777,11 +2445,12 @@ class MigrationsApi {
1777
2445
  database,
1778
2446
  branch,
1779
2447
  compare,
1780
- schema
2448
+ sourceBranchOperations,
2449
+ targetBranchOperations
1781
2450
  }) {
1782
2451
  return operationsByTag.migrations.compareBranchSchemas({
1783
2452
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1784
- body: { schema },
2453
+ body: { sourceBranchOperations, targetBranchOperations },
1785
2454
  ...this.extraProps
1786
2455
  });
1787
2456
  }
@@ -1824,6 +2493,19 @@ class MigrationsApi {
1824
2493
  ...this.extraProps
1825
2494
  });
1826
2495
  }
2496
+ pushBranchMigrations({
2497
+ workspace,
2498
+ region,
2499
+ database,
2500
+ branch,
2501
+ migrations
2502
+ }) {
2503
+ return operationsByTag.migrations.pushBranchMigrations({
2504
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2505
+ body: { migrations },
2506
+ ...this.extraProps
2507
+ });
2508
+ }
1827
2509
  }
1828
2510
  class DatabaseApi {
1829
2511
  constructor(extraProps) {
@@ -1838,11 +2520,13 @@ class DatabaseApi {
1838
2520
  createDatabase({
1839
2521
  workspace,
1840
2522
  database,
1841
- data
2523
+ data,
2524
+ headers
1842
2525
  }) {
1843
2526
  return operationsByTag.databases.createDatabase({
1844
2527
  pathParams: { workspaceId: workspace, dbName: database },
1845
2528
  body: data,
2529
+ headers,
1846
2530
  ...this.extraProps
1847
2531
  });
1848
2532
  }
@@ -1875,6 +2559,46 @@ class DatabaseApi {
1875
2559
  ...this.extraProps
1876
2560
  });
1877
2561
  }
2562
+ renameDatabase({
2563
+ workspace,
2564
+ database,
2565
+ newName
2566
+ }) {
2567
+ return operationsByTag.databases.renameDatabase({
2568
+ pathParams: { workspaceId: workspace, dbName: database },
2569
+ body: { newName },
2570
+ ...this.extraProps
2571
+ });
2572
+ }
2573
+ getDatabaseGithubSettings({
2574
+ workspace,
2575
+ database
2576
+ }) {
2577
+ return operationsByTag.databases.getDatabaseGithubSettings({
2578
+ pathParams: { workspaceId: workspace, dbName: database },
2579
+ ...this.extraProps
2580
+ });
2581
+ }
2582
+ updateDatabaseGithubSettings({
2583
+ workspace,
2584
+ database,
2585
+ settings
2586
+ }) {
2587
+ return operationsByTag.databases.updateDatabaseGithubSettings({
2588
+ pathParams: { workspaceId: workspace, dbName: database },
2589
+ body: settings,
2590
+ ...this.extraProps
2591
+ });
2592
+ }
2593
+ deleteDatabaseGithubSettings({
2594
+ workspace,
2595
+ database
2596
+ }) {
2597
+ return operationsByTag.databases.deleteDatabaseGithubSettings({
2598
+ pathParams: { workspaceId: workspace, dbName: database },
2599
+ ...this.extraProps
2600
+ });
2601
+ }
1878
2602
  listRegions({ workspace }) {
1879
2603
  return operationsByTag.databases.listRegions({
1880
2604
  pathParams: { workspaceId: workspace },
@@ -1884,22 +2608,319 @@ class DatabaseApi {
1884
2608
  }
1885
2609
 
1886
2610
  class XataApiPlugin {
1887
- async build(options) {
1888
- const { fetchImpl, apiKey } = await options.getFetchProps();
1889
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2611
+ build(options) {
2612
+ return new XataApiClient(options);
1890
2613
  }
1891
2614
  }
1892
2615
 
1893
2616
  class XataPlugin {
1894
2617
  }
1895
2618
 
2619
+ class FilesPlugin extends XataPlugin {
2620
+ build(pluginOptions) {
2621
+ return {
2622
+ download: async (location) => {
2623
+ const { table, record, column, fileId = "" } = location ?? {};
2624
+ return await getFileItem({
2625
+ pathParams: {
2626
+ workspace: "{workspaceId}",
2627
+ dbBranchName: "{dbBranch}",
2628
+ region: "{region}",
2629
+ tableName: table ?? "",
2630
+ recordId: record ?? "",
2631
+ columnName: column ?? "",
2632
+ fileId
2633
+ },
2634
+ ...pluginOptions,
2635
+ rawResponse: true
2636
+ });
2637
+ },
2638
+ upload: async (location, file) => {
2639
+ const { table, record, column, fileId = "" } = location ?? {};
2640
+ const contentType = getContentType(file);
2641
+ return await putFileItem({
2642
+ ...pluginOptions,
2643
+ pathParams: {
2644
+ workspace: "{workspaceId}",
2645
+ dbBranchName: "{dbBranch}",
2646
+ region: "{region}",
2647
+ tableName: table ?? "",
2648
+ recordId: record ?? "",
2649
+ columnName: column ?? "",
2650
+ fileId
2651
+ },
2652
+ body: file,
2653
+ headers: { "Content-Type": contentType }
2654
+ });
2655
+ },
2656
+ delete: async (location) => {
2657
+ const { table, record, column, fileId = "" } = location ?? {};
2658
+ return await deleteFileItem({
2659
+ pathParams: {
2660
+ workspace: "{workspaceId}",
2661
+ dbBranchName: "{dbBranch}",
2662
+ region: "{region}",
2663
+ tableName: table ?? "",
2664
+ recordId: record ?? "",
2665
+ columnName: column ?? "",
2666
+ fileId
2667
+ },
2668
+ ...pluginOptions
2669
+ });
2670
+ }
2671
+ };
2672
+ }
2673
+ }
2674
+ function getContentType(file) {
2675
+ if (typeof file === "string") {
2676
+ return "text/plain";
2677
+ }
2678
+ if (file instanceof Blob) {
2679
+ return file.type;
2680
+ }
2681
+ try {
2682
+ return file.type;
2683
+ } catch (e) {
2684
+ }
2685
+ return "application/octet-stream";
2686
+ }
2687
+
2688
+ function buildTransformString(transformations) {
2689
+ return transformations.flatMap(
2690
+ (t) => Object.entries(t).map(([key, value]) => {
2691
+ if (key === "trim") {
2692
+ const { left = 0, top = 0, right = 0, bottom = 0 } = value;
2693
+ return `${key}=${[top, right, bottom, left].join(";")}`;
2694
+ }
2695
+ if (key === "gravity" && typeof value === "object") {
2696
+ const { x = 0.5, y = 0.5 } = value;
2697
+ return `${key}=${[x, y].join("x")}`;
2698
+ }
2699
+ return `${key}=${value}`;
2700
+ })
2701
+ ).join(",");
2702
+ }
2703
+ function transformImage(url, ...transformations) {
2704
+ if (!isDefined(url))
2705
+ return void 0;
2706
+ const newTransformations = buildTransformString(transformations);
2707
+ const { hostname, pathname, search } = new URL(url);
2708
+ const pathParts = pathname.split("/");
2709
+ const transformIndex = pathParts.findIndex((part) => part === "transform");
2710
+ const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
2711
+ const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
2712
+ const path = pathParts.join("/");
2713
+ return `https://${hostname}${transform}${path}${search}`;
2714
+ }
2715
+
2716
+ var __defProp$6 = Object.defineProperty;
2717
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2718
+ var __publicField$6 = (obj, key, value) => {
2719
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
2720
+ return value;
2721
+ };
2722
+ class XataFile {
2723
+ constructor(file) {
2724
+ /**
2725
+ * Identifier of the file.
2726
+ */
2727
+ __publicField$6(this, "id");
2728
+ /**
2729
+ * Name of the file.
2730
+ */
2731
+ __publicField$6(this, "name");
2732
+ /**
2733
+ * Media type of the file.
2734
+ */
2735
+ __publicField$6(this, "mediaType");
2736
+ /**
2737
+ * Base64 encoded content of the file.
2738
+ */
2739
+ __publicField$6(this, "base64Content");
2740
+ /**
2741
+ * Whether to enable public url for the file.
2742
+ */
2743
+ __publicField$6(this, "enablePublicUrl");
2744
+ /**
2745
+ * Timeout for the signed url.
2746
+ */
2747
+ __publicField$6(this, "signedUrlTimeout");
2748
+ /**
2749
+ * Size of the file.
2750
+ */
2751
+ __publicField$6(this, "size");
2752
+ /**
2753
+ * Version of the file.
2754
+ */
2755
+ __publicField$6(this, "version");
2756
+ /**
2757
+ * Url of the file.
2758
+ */
2759
+ __publicField$6(this, "url");
2760
+ /**
2761
+ * Signed url of the file.
2762
+ */
2763
+ __publicField$6(this, "signedUrl");
2764
+ /**
2765
+ * Attributes of the file.
2766
+ */
2767
+ __publicField$6(this, "attributes");
2768
+ this.id = file.id;
2769
+ this.name = file.name || "";
2770
+ this.mediaType = file.mediaType || "application/octet-stream";
2771
+ this.base64Content = file.base64Content;
2772
+ this.enablePublicUrl = file.enablePublicUrl ?? false;
2773
+ this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
2774
+ this.size = file.size ?? 0;
2775
+ this.version = file.version ?? 1;
2776
+ this.url = file.url || "";
2777
+ this.signedUrl = file.signedUrl;
2778
+ this.attributes = file.attributes || {};
2779
+ }
2780
+ static fromBuffer(buffer, options = {}) {
2781
+ const base64Content = buffer.toString("base64");
2782
+ return new XataFile({ ...options, base64Content });
2783
+ }
2784
+ toBuffer() {
2785
+ if (!this.base64Content) {
2786
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2787
+ }
2788
+ return Buffer.from(this.base64Content, "base64");
2789
+ }
2790
+ static fromArrayBuffer(arrayBuffer, options = {}) {
2791
+ const uint8Array = new Uint8Array(arrayBuffer);
2792
+ return this.fromUint8Array(uint8Array, options);
2793
+ }
2794
+ toArrayBuffer() {
2795
+ if (!this.base64Content) {
2796
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2797
+ }
2798
+ const binary = atob(this.base64Content);
2799
+ return new ArrayBuffer(binary.length);
2800
+ }
2801
+ static fromUint8Array(uint8Array, options = {}) {
2802
+ let binary = "";
2803
+ for (let i = 0; i < uint8Array.byteLength; i++) {
2804
+ binary += String.fromCharCode(uint8Array[i]);
2805
+ }
2806
+ const base64Content = btoa(binary);
2807
+ return new XataFile({ ...options, base64Content });
2808
+ }
2809
+ toUint8Array() {
2810
+ if (!this.base64Content) {
2811
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2812
+ }
2813
+ const binary = atob(this.base64Content);
2814
+ const uint8Array = new Uint8Array(binary.length);
2815
+ for (let i = 0; i < binary.length; i++) {
2816
+ uint8Array[i] = binary.charCodeAt(i);
2817
+ }
2818
+ return uint8Array;
2819
+ }
2820
+ static async fromBlob(file, options = {}) {
2821
+ const name = options.name ?? file.name;
2822
+ const mediaType = file.type;
2823
+ const arrayBuffer = await file.arrayBuffer();
2824
+ return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
2825
+ }
2826
+ toBlob() {
2827
+ if (!this.base64Content) {
2828
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2829
+ }
2830
+ const binary = atob(this.base64Content);
2831
+ const uint8Array = new Uint8Array(binary.length);
2832
+ for (let i = 0; i < binary.length; i++) {
2833
+ uint8Array[i] = binary.charCodeAt(i);
2834
+ }
2835
+ return new Blob([uint8Array], { type: this.mediaType });
2836
+ }
2837
+ static fromString(string, options = {}) {
2838
+ const base64Content = btoa(string);
2839
+ return new XataFile({ ...options, base64Content });
2840
+ }
2841
+ toString() {
2842
+ if (!this.base64Content) {
2843
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2844
+ }
2845
+ return atob(this.base64Content);
2846
+ }
2847
+ static fromBase64(base64Content, options = {}) {
2848
+ return new XataFile({ ...options, base64Content });
2849
+ }
2850
+ toBase64() {
2851
+ if (!this.base64Content) {
2852
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2853
+ }
2854
+ return this.base64Content;
2855
+ }
2856
+ transform(...options) {
2857
+ return {
2858
+ url: transformImage(this.url, ...options),
2859
+ signedUrl: transformImage(this.signedUrl, ...options),
2860
+ metadataUrl: transformImage(this.url, ...options, { format: "json" }),
2861
+ metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
2862
+ };
2863
+ }
2864
+ }
2865
+ const parseInputFileEntry = async (entry) => {
2866
+ if (!isDefined(entry))
2867
+ return null;
2868
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
2869
+ return compactObject({ id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout });
2870
+ };
2871
+
1896
2872
  function cleanFilter(filter) {
1897
- if (!filter)
2873
+ if (!isDefined(filter))
1898
2874
  return void 0;
1899
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1900
- return values.length > 0 ? filter : void 0;
2875
+ if (!isObject(filter))
2876
+ return filter;
2877
+ const values = Object.fromEntries(
2878
+ Object.entries(filter).reduce((acc, [key, value]) => {
2879
+ if (!isDefined(value))
2880
+ return acc;
2881
+ if (Array.isArray(value)) {
2882
+ const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
2883
+ if (clean.length === 0)
2884
+ return acc;
2885
+ return [...acc, [key, clean]];
2886
+ }
2887
+ if (isObject(value)) {
2888
+ const clean = cleanFilter(value);
2889
+ if (!isDefined(clean))
2890
+ return acc;
2891
+ return [...acc, [key, clean]];
2892
+ }
2893
+ return [...acc, [key, value]];
2894
+ }, [])
2895
+ );
2896
+ return Object.keys(values).length > 0 ? values : void 0;
2897
+ }
2898
+
2899
+ function stringifyJson(value) {
2900
+ if (!isDefined(value))
2901
+ return value;
2902
+ if (isString(value))
2903
+ return value;
2904
+ try {
2905
+ return JSON.stringify(value);
2906
+ } catch (e) {
2907
+ return value;
2908
+ }
2909
+ }
2910
+ function parseJson(value) {
2911
+ try {
2912
+ return JSON.parse(value);
2913
+ } catch (e) {
2914
+ return value;
2915
+ }
1901
2916
  }
1902
2917
 
2918
+ var __defProp$5 = Object.defineProperty;
2919
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2920
+ var __publicField$5 = (obj, key, value) => {
2921
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2922
+ return value;
2923
+ };
1903
2924
  var __accessCheck$6 = (obj, member, msg) => {
1904
2925
  if (!member.has(obj))
1905
2926
  throw TypeError("Cannot " + msg);
@@ -1922,22 +2943,58 @@ var _query, _page;
1922
2943
  class Page {
1923
2944
  constructor(query, meta, records = []) {
1924
2945
  __privateAdd$6(this, _query, void 0);
2946
+ /**
2947
+ * Page metadata, required to retrieve additional records.
2948
+ */
2949
+ __publicField$5(this, "meta");
2950
+ /**
2951
+ * The set of results for this page.
2952
+ */
2953
+ __publicField$5(this, "records");
1925
2954
  __privateSet$6(this, _query, query);
1926
2955
  this.meta = meta;
1927
2956
  this.records = new RecordArray(this, records);
1928
2957
  }
2958
+ /**
2959
+ * Retrieves the next page of results.
2960
+ * @param size Maximum number of results to be retrieved.
2961
+ * @param offset Number of results to skip when retrieving the results.
2962
+ * @returns The next page or results.
2963
+ */
1929
2964
  async nextPage(size, offset) {
1930
2965
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
1931
2966
  }
2967
+ /**
2968
+ * Retrieves the previous page of results.
2969
+ * @param size Maximum number of results to be retrieved.
2970
+ * @param offset Number of results to skip when retrieving the results.
2971
+ * @returns The previous page or results.
2972
+ */
1932
2973
  async previousPage(size, offset) {
1933
2974
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1934
2975
  }
2976
+ /**
2977
+ * Retrieves the start page of results.
2978
+ * @param size Maximum number of results to be retrieved.
2979
+ * @param offset Number of results to skip when retrieving the results.
2980
+ * @returns The start page or results.
2981
+ */
1935
2982
  async startPage(size, offset) {
1936
2983
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1937
2984
  }
2985
+ /**
2986
+ * Retrieves the end page of results.
2987
+ * @param size Maximum number of results to be retrieved.
2988
+ * @param offset Number of results to skip when retrieving the results.
2989
+ * @returns The end page or results.
2990
+ */
1938
2991
  async endPage(size, offset) {
1939
2992
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1940
2993
  }
2994
+ /**
2995
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
2996
+ * @returns Whether or not there will be additional results in the next page of results.
2997
+ */
1941
2998
  hasNextPage() {
1942
2999
  return this.meta.page.more;
1943
3000
  }
@@ -1950,7 +3007,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
1950
3007
  function isCursorPaginationOptions(options) {
1951
3008
  return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1952
3009
  }
1953
- const _RecordArray = class extends Array {
3010
+ const _RecordArray = class _RecordArray extends Array {
1954
3011
  constructor(...args) {
1955
3012
  super(..._RecordArray.parseConstructorParams(...args));
1956
3013
  __privateAdd$6(this, _page, void 0);
@@ -1978,29 +3035,58 @@ const _RecordArray = class extends Array {
1978
3035
  map(callbackfn, thisArg) {
1979
3036
  return this.toArray().map(callbackfn, thisArg);
1980
3037
  }
3038
+ /**
3039
+ * Retrieve next page of records
3040
+ *
3041
+ * @returns A new array of objects
3042
+ */
1981
3043
  async nextPage(size, offset) {
1982
3044
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1983
3045
  return new _RecordArray(newPage);
1984
3046
  }
3047
+ /**
3048
+ * Retrieve previous page of records
3049
+ *
3050
+ * @returns A new array of objects
3051
+ */
1985
3052
  async previousPage(size, offset) {
1986
3053
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1987
3054
  return new _RecordArray(newPage);
1988
3055
  }
3056
+ /**
3057
+ * Retrieve start page of records
3058
+ *
3059
+ * @returns A new array of objects
3060
+ */
1989
3061
  async startPage(size, offset) {
1990
3062
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1991
3063
  return new _RecordArray(newPage);
1992
3064
  }
3065
+ /**
3066
+ * Retrieve end page of records
3067
+ *
3068
+ * @returns A new array of objects
3069
+ */
1993
3070
  async endPage(size, offset) {
1994
3071
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1995
3072
  return new _RecordArray(newPage);
1996
3073
  }
3074
+ /**
3075
+ * @returns Boolean indicating if there is a next page
3076
+ */
1997
3077
  hasNextPage() {
1998
3078
  return __privateGet$6(this, _page).meta.page.more;
1999
3079
  }
2000
3080
  };
2001
- let RecordArray = _RecordArray;
2002
3081
  _page = new WeakMap();
3082
+ let RecordArray = _RecordArray;
2003
3083
 
3084
+ var __defProp$4 = Object.defineProperty;
3085
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3086
+ var __publicField$4 = (obj, key, value) => {
3087
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3088
+ return value;
3089
+ };
2004
3090
  var __accessCheck$5 = (obj, member, msg) => {
2005
3091
  if (!member.has(obj))
2006
3092
  throw TypeError("Cannot " + msg);
@@ -2024,14 +3110,15 @@ var __privateMethod$3 = (obj, member, method) => {
2024
3110
  return method;
2025
3111
  };
2026
3112
  var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
2027
- const _Query = class {
3113
+ const _Query = class _Query {
2028
3114
  constructor(repository, table, data, rawParent) {
2029
3115
  __privateAdd$5(this, _cleanFilterConstraint);
2030
3116
  __privateAdd$5(this, _table$1, void 0);
2031
3117
  __privateAdd$5(this, _repository, void 0);
2032
3118
  __privateAdd$5(this, _data, { filter: {} });
2033
- this.meta = { page: { cursor: "start", more: true } };
2034
- this.records = new RecordArray(this, []);
3119
+ // Implements pagination
3120
+ __publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
3121
+ __publicField$4(this, "records", new RecordArray(this, []));
2035
3122
  __privateSet$5(this, _table$1, table);
2036
3123
  if (repository) {
2037
3124
  __privateSet$5(this, _repository, repository);
@@ -2067,18 +3154,38 @@ const _Query = class {
2067
3154
  const key = JSON.stringify({ columns, filter, sort, pagination });
2068
3155
  return toBase64(key);
2069
3156
  }
3157
+ /**
3158
+ * Builds a new query object representing a logical OR between the given subqueries.
3159
+ * @param queries An array of subqueries.
3160
+ * @returns A new Query object.
3161
+ */
2070
3162
  any(...queries) {
2071
3163
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2072
3164
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2073
3165
  }
3166
+ /**
3167
+ * Builds a new query object representing a logical AND between the given subqueries.
3168
+ * @param queries An array of subqueries.
3169
+ * @returns A new Query object.
3170
+ */
2074
3171
  all(...queries) {
2075
3172
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2076
3173
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2077
3174
  }
3175
+ /**
3176
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
3177
+ * @param queries An array of subqueries.
3178
+ * @returns A new Query object.
3179
+ */
2078
3180
  not(...queries) {
2079
3181
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2080
3182
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2081
3183
  }
3184
+ /**
3185
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
3186
+ * @param queries An array of subqueries.
3187
+ * @returns A new Query object.
3188
+ */
2082
3189
  none(...queries) {
2083
3190
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2084
3191
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2101,6 +3208,11 @@ const _Query = class {
2101
3208
  const sort = [...originalSort, { column, direction }];
2102
3209
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2103
3210
  }
3211
+ /**
3212
+ * Builds a new query specifying the set of columns to be returned in the query response.
3213
+ * @param columns Array of column names to be returned by the query.
3214
+ * @returns A new Query object.
3215
+ */
2104
3216
  select(columns) {
2105
3217
  return new _Query(
2106
3218
  __privateGet$5(this, _repository),
@@ -2113,6 +3225,12 @@ const _Query = class {
2113
3225
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2114
3226
  return __privateGet$5(this, _repository).query(query);
2115
3227
  }
3228
+ /**
3229
+ * Get results in an iterator
3230
+ *
3231
+ * @async
3232
+ * @returns Async interable of results
3233
+ */
2116
3234
  async *[Symbol.asyncIterator]() {
2117
3235
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2118
3236
  yield record;
@@ -2173,26 +3291,53 @@ const _Query = class {
2173
3291
  );
2174
3292
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2175
3293
  }
3294
+ /**
3295
+ * Builds a new query object adding a cache TTL in milliseconds.
3296
+ * @param ttl The cache TTL in milliseconds.
3297
+ * @returns A new Query object.
3298
+ */
2176
3299
  cache(ttl) {
2177
3300
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2178
3301
  }
3302
+ /**
3303
+ * Retrieve next page of records
3304
+ *
3305
+ * @returns A new page object.
3306
+ */
2179
3307
  nextPage(size, offset) {
2180
3308
  return this.startPage(size, offset);
2181
3309
  }
3310
+ /**
3311
+ * Retrieve previous page of records
3312
+ *
3313
+ * @returns A new page object
3314
+ */
2182
3315
  previousPage(size, offset) {
2183
3316
  return this.startPage(size, offset);
2184
3317
  }
3318
+ /**
3319
+ * Retrieve start page of records
3320
+ *
3321
+ * @returns A new page object
3322
+ */
2185
3323
  startPage(size, offset) {
2186
3324
  return this.getPaginated({ pagination: { size, offset } });
2187
3325
  }
3326
+ /**
3327
+ * Retrieve last page of records
3328
+ *
3329
+ * @returns A new page object
3330
+ */
2188
3331
  endPage(size, offset) {
2189
3332
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2190
3333
  }
3334
+ /**
3335
+ * @returns Boolean indicating if there is a next page
3336
+ */
2191
3337
  hasNextPage() {
2192
3338
  return this.meta.page.more;
2193
3339
  }
2194
3340
  };
2195
- let Query = _Query;
2196
3341
  _table$1 = new WeakMap();
2197
3342
  _repository = new WeakMap();
2198
3343
  _data = new WeakMap();
@@ -2207,6 +3352,7 @@ cleanFilterConstraint_fn = function(column, value) {
2207
3352
  }
2208
3353
  return value;
2209
3354
  };
3355
+ let Query = _Query;
2210
3356
  function cleanParent(data, parent) {
2211
3357
  if (isCursorPaginationOptions(data.pagination)) {
2212
3358
  return { ...parent, sort: void 0, filter: void 0 };
@@ -2214,6 +3360,22 @@ function cleanParent(data, parent) {
2214
3360
  return parent;
2215
3361
  }
2216
3362
 
3363
+ const RecordColumnTypes = [
3364
+ "bool",
3365
+ "int",
3366
+ "float",
3367
+ "string",
3368
+ "text",
3369
+ "email",
3370
+ "multiple",
3371
+ "link",
3372
+ "object",
3373
+ "datetime",
3374
+ "vector",
3375
+ "file[]",
3376
+ "file",
3377
+ "json"
3378
+ ];
2217
3379
  function isIdentifiable(x) {
2218
3380
  return isObject(x) && isString(x?.id);
2219
3381
  }
@@ -2223,11 +3385,33 @@ function isXataRecord(x) {
2223
3385
  return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
2224
3386
  }
2225
3387
 
3388
+ function isValidExpandedColumn(column) {
3389
+ return isObject(column) && isString(column.name);
3390
+ }
3391
+ function isValidSelectableColumns(columns) {
3392
+ if (!Array.isArray(columns)) {
3393
+ return false;
3394
+ }
3395
+ return columns.every((column) => {
3396
+ if (typeof column === "string") {
3397
+ return true;
3398
+ }
3399
+ if (typeof column === "object") {
3400
+ return isValidExpandedColumn(column);
3401
+ }
3402
+ return false;
3403
+ });
3404
+ }
3405
+
2226
3406
  function isSortFilterString(value) {
2227
3407
  return isString(value);
2228
3408
  }
2229
3409
  function isSortFilterBase(filter) {
2230
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
3410
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
3411
+ if (key === "*")
3412
+ return value === "random";
3413
+ return value === "asc" || value === "desc";
3414
+ });
2231
3415
  }
2232
3416
  function isSortFilterObject(filter) {
2233
3417
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2268,7 +3452,7 @@ var __privateMethod$2 = (obj, member, method) => {
2268
3452
  __accessCheck$4(obj, member, "access private method");
2269
3453
  return method;
2270
3454
  };
2271
- 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;
3455
+ 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, _transformObjectToApi, transformObjectToApi_fn;
2272
3456
  const BULK_OPERATION_MAX_SIZE = 1e3;
2273
3457
  class Repository extends Query {
2274
3458
  }
@@ -2290,6 +3474,7 @@ class RestRepository extends Query {
2290
3474
  __privateAdd$4(this, _setCacheQuery);
2291
3475
  __privateAdd$4(this, _getCacheQuery);
2292
3476
  __privateAdd$4(this, _getSchemaTables$1);
3477
+ __privateAdd$4(this, _transformObjectToApi);
2293
3478
  __privateAdd$4(this, _table, void 0);
2294
3479
  __privateAdd$4(this, _getFetchProps, void 0);
2295
3480
  __privateAdd$4(this, _db, void 0);
@@ -2300,10 +3485,7 @@ class RestRepository extends Query {
2300
3485
  __privateSet$4(this, _db, options.db);
2301
3486
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2302
3487
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2303
- __privateSet$4(this, _getFetchProps, async () => {
2304
- const props = await options.pluginOptions.getFetchProps();
2305
- return { ...props, sessionID: generateUUID() };
2306
- });
3488
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2307
3489
  const trace = options.pluginOptions.trace ?? defaultTrace;
2308
3490
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2309
3491
  return trace(name, fn, {
@@ -2321,24 +3503,24 @@ class RestRepository extends Query {
2321
3503
  if (a.length === 0)
2322
3504
  return [];
2323
3505
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2324
- const columns = isStringArray(b) ? b : ["*"];
3506
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2325
3507
  const result = await this.read(ids, columns);
2326
3508
  return result;
2327
3509
  }
2328
3510
  if (isString(a) && isObject(b)) {
2329
3511
  if (a === "")
2330
3512
  throw new Error("The id can't be empty");
2331
- const columns = isStringArray(c) ? c : void 0;
3513
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2332
3514
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2333
3515
  }
2334
3516
  if (isObject(a) && isString(a.id)) {
2335
3517
  if (a.id === "")
2336
3518
  throw new Error("The id can't be empty");
2337
- const columns = isStringArray(b) ? b : void 0;
3519
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2338
3520
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2339
3521
  }
2340
3522
  if (isObject(a)) {
2341
- const columns = isStringArray(b) ? b : void 0;
3523
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2342
3524
  return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2343
3525
  }
2344
3526
  throw new Error("Invalid arguments for create method");
@@ -2346,7 +3528,7 @@ class RestRepository extends Query {
2346
3528
  }
2347
3529
  async read(a, b) {
2348
3530
  return __privateGet$4(this, _trace).call(this, "read", async () => {
2349
- const columns = isStringArray(b) ? b : ["*"];
3531
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2350
3532
  if (Array.isArray(a)) {
2351
3533
  if (a.length === 0)
2352
3534
  return [];
@@ -2360,7 +3542,6 @@ class RestRepository extends Query {
2360
3542
  }
2361
3543
  const id = extractId(a);
2362
3544
  if (id) {
2363
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2364
3545
  try {
2365
3546
  const response = await getRecord({
2366
3547
  pathParams: {
@@ -2371,10 +3552,16 @@ class RestRepository extends Query {
2371
3552
  recordId: id
2372
3553
  },
2373
3554
  queryParams: { columns },
2374
- ...fetchProps
3555
+ ...__privateGet$4(this, _getFetchProps).call(this)
2375
3556
  });
2376
3557
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2377
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
3558
+ return initObject(
3559
+ __privateGet$4(this, _db),
3560
+ schemaTables,
3561
+ __privateGet$4(this, _table),
3562
+ response,
3563
+ columns
3564
+ );
2378
3565
  } catch (e) {
2379
3566
  if (isObject(e) && e.status === 404) {
2380
3567
  return null;
@@ -2416,17 +3603,17 @@ class RestRepository extends Query {
2416
3603
  ifVersion,
2417
3604
  upsert: false
2418
3605
  });
2419
- const columns = isStringArray(b) ? b : ["*"];
3606
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2420
3607
  const result = await this.read(a, columns);
2421
3608
  return result;
2422
3609
  }
2423
3610
  try {
2424
3611
  if (isString(a) && isObject(b)) {
2425
- const columns = isStringArray(c) ? c : void 0;
3612
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2426
3613
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2427
3614
  }
2428
3615
  if (isObject(a) && isString(a.id)) {
2429
- const columns = isStringArray(b) ? b : void 0;
3616
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2430
3617
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2431
3618
  }
2432
3619
  } catch (error) {
@@ -2466,17 +3653,27 @@ class RestRepository extends Query {
2466
3653
  ifVersion,
2467
3654
  upsert: true
2468
3655
  });
2469
- const columns = isStringArray(b) ? b : ["*"];
3656
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2470
3657
  const result = await this.read(a, columns);
2471
3658
  return result;
2472
3659
  }
2473
3660
  if (isString(a) && isObject(b)) {
2474
- const columns = isStringArray(c) ? c : void 0;
2475
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3661
+ if (a === "")
3662
+ throw new Error("The id can't be empty");
3663
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3664
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2476
3665
  }
2477
3666
  if (isObject(a) && isString(a.id)) {
2478
- const columns = isStringArray(c) ? c : void 0;
2479
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3667
+ if (a.id === "")
3668
+ throw new Error("The id can't be empty");
3669
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3670
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3671
+ }
3672
+ if (!isDefined(a) && isObject(b)) {
3673
+ return await this.create(b, c);
3674
+ }
3675
+ if (isObject(a) && !isDefined(a.id)) {
3676
+ return await this.create(a, b);
2480
3677
  }
2481
3678
  throw new Error("Invalid arguments for createOrUpdate method");
2482
3679
  });
@@ -2488,17 +3685,27 @@ class RestRepository extends Query {
2488
3685
  if (a.length === 0)
2489
3686
  return [];
2490
3687
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2491
- const columns = isStringArray(b) ? b : ["*"];
3688
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2492
3689
  const result = await this.read(ids, columns);
2493
3690
  return result;
2494
3691
  }
2495
3692
  if (isString(a) && isObject(b)) {
2496
- const columns = isStringArray(c) ? c : void 0;
2497
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
3693
+ if (a === "")
3694
+ throw new Error("The id can't be empty");
3695
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3696
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2498
3697
  }
2499
3698
  if (isObject(a) && isString(a.id)) {
2500
- const columns = isStringArray(c) ? c : void 0;
2501
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3699
+ if (a.id === "")
3700
+ throw new Error("The id can't be empty");
3701
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3702
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3703
+ }
3704
+ if (!isDefined(a) && isObject(b)) {
3705
+ return await this.create(b, c);
3706
+ }
3707
+ if (isObject(a) && !isDefined(a.id)) {
3708
+ return await this.create(a, b);
2502
3709
  }
2503
3710
  throw new Error("Invalid arguments for createOrReplace method");
2504
3711
  });
@@ -2515,7 +3722,7 @@ class RestRepository extends Query {
2515
3722
  return o.id;
2516
3723
  throw new Error("Invalid arguments for delete method");
2517
3724
  });
2518
- const columns = isStringArray(b) ? b : ["*"];
3725
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2519
3726
  const result = await this.read(a, columns);
2520
3727
  await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2521
3728
  return result;
@@ -2549,7 +3756,6 @@ class RestRepository extends Query {
2549
3756
  }
2550
3757
  async search(query, options = {}) {
2551
3758
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2552
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2553
3759
  const { records } = await searchTable({
2554
3760
  pathParams: {
2555
3761
  workspace: "{workspaceId}",
@@ -2567,7 +3773,29 @@ class RestRepository extends Query {
2567
3773
  page: options.page,
2568
3774
  target: options.target
2569
3775
  },
2570
- ...fetchProps
3776
+ ...__privateGet$4(this, _getFetchProps).call(this)
3777
+ });
3778
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3779
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
3780
+ });
3781
+ }
3782
+ async vectorSearch(column, query, options) {
3783
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
3784
+ const { records } = await vectorSearchTable({
3785
+ pathParams: {
3786
+ workspace: "{workspaceId}",
3787
+ dbBranchName: "{dbBranch}",
3788
+ region: "{region}",
3789
+ tableName: __privateGet$4(this, _table)
3790
+ },
3791
+ body: {
3792
+ column,
3793
+ queryVector: query,
3794
+ similarityFunction: options?.similarityFunction,
3795
+ size: options?.size,
3796
+ filter: options?.filter
3797
+ },
3798
+ ...__privateGet$4(this, _getFetchProps).call(this)
2571
3799
  });
2572
3800
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2573
3801
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2575,7 +3803,6 @@ class RestRepository extends Query {
2575
3803
  }
2576
3804
  async aggregate(aggs, filter) {
2577
3805
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2578
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2579
3806
  const result = await aggregateTable({
2580
3807
  pathParams: {
2581
3808
  workspace: "{workspaceId}",
@@ -2584,7 +3811,7 @@ class RestRepository extends Query {
2584
3811
  tableName: __privateGet$4(this, _table)
2585
3812
  },
2586
3813
  body: { aggs, filter },
2587
- ...fetchProps
3814
+ ...__privateGet$4(this, _getFetchProps).call(this)
2588
3815
  });
2589
3816
  return result;
2590
3817
  });
@@ -2595,7 +3822,6 @@ class RestRepository extends Query {
2595
3822
  if (cacheQuery)
2596
3823
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2597
3824
  const data = query.getQueryOptions();
2598
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2599
3825
  const { meta, records: objects } = await queryTable({
2600
3826
  pathParams: {
2601
3827
  workspace: "{workspaceId}",
@@ -2611,11 +3837,17 @@ class RestRepository extends Query {
2611
3837
  consistency: data.consistency
2612
3838
  },
2613
3839
  fetchOptions: data.fetchOptions,
2614
- ...fetchProps
3840
+ ...__privateGet$4(this, _getFetchProps).call(this)
2615
3841
  });
2616
3842
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2617
3843
  const records = objects.map(
2618
- (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
3844
+ (record) => initObject(
3845
+ __privateGet$4(this, _db),
3846
+ schemaTables,
3847
+ __privateGet$4(this, _table),
3848
+ record,
3849
+ data.columns ?? ["*"]
3850
+ )
2619
3851
  );
2620
3852
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
2621
3853
  return new Page(query, meta, records);
@@ -2624,7 +3856,6 @@ class RestRepository extends Query {
2624
3856
  async summarizeTable(query, summaries, summariesFilter) {
2625
3857
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2626
3858
  const data = query.getQueryOptions();
2627
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2628
3859
  const result = await summarizeTable({
2629
3860
  pathParams: {
2630
3861
  workspace: "{workspaceId}",
@@ -2641,11 +3872,44 @@ class RestRepository extends Query {
2641
3872
  summaries,
2642
3873
  summariesFilter
2643
3874
  },
2644
- ...fetchProps
3875
+ ...__privateGet$4(this, _getFetchProps).call(this)
2645
3876
  });
2646
3877
  return result;
2647
3878
  });
2648
3879
  }
3880
+ ask(question, options) {
3881
+ const questionParam = options?.sessionId ? { message: question } : { question };
3882
+ const params = {
3883
+ pathParams: {
3884
+ workspace: "{workspaceId}",
3885
+ dbBranchName: "{dbBranch}",
3886
+ region: "{region}",
3887
+ tableName: __privateGet$4(this, _table),
3888
+ sessionId: options?.sessionId
3889
+ },
3890
+ body: {
3891
+ ...questionParam,
3892
+ rules: options?.rules,
3893
+ searchType: options?.searchType,
3894
+ search: options?.searchType === "keyword" ? options?.search : void 0,
3895
+ vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
3896
+ },
3897
+ ...__privateGet$4(this, _getFetchProps).call(this)
3898
+ };
3899
+ if (options?.onMessage) {
3900
+ fetchSSERequest({
3901
+ endpoint: "dataPlane",
3902
+ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
3903
+ method: "POST",
3904
+ onMessage: (message) => {
3905
+ options.onMessage?.({ answer: message.text, records: message.records });
3906
+ },
3907
+ ...params
3908
+ });
3909
+ } else {
3910
+ return askTableSession(params);
3911
+ }
3912
+ }
2649
3913
  }
2650
3914
  _table = new WeakMap();
2651
3915
  _getFetchProps = new WeakMap();
@@ -2655,8 +3919,7 @@ _schemaTables$2 = new WeakMap();
2655
3919
  _trace = new WeakMap();
2656
3920
  _insertRecordWithoutId = new WeakSet();
2657
3921
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2658
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2659
- const record = transformObjectLinks(object);
3922
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2660
3923
  const response = await insertRecord({
2661
3924
  pathParams: {
2662
3925
  workspace: "{workspaceId}",
@@ -2666,15 +3929,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2666
3929
  },
2667
3930
  queryParams: { columns },
2668
3931
  body: record,
2669
- ...fetchProps
3932
+ ...__privateGet$4(this, _getFetchProps).call(this)
2670
3933
  });
2671
3934
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2672
3935
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2673
3936
  };
2674
3937
  _insertRecordWithId = new WeakSet();
2675
3938
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2676
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2677
- const record = transformObjectLinks(object);
3939
+ if (!recordId)
3940
+ return null;
3941
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2678
3942
  const response = await insertRecordWithID({
2679
3943
  pathParams: {
2680
3944
  workspace: "{workspaceId}",
@@ -2685,30 +3949,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2685
3949
  },
2686
3950
  body: record,
2687
3951
  queryParams: { createOnly, columns, ifVersion },
2688
- ...fetchProps
3952
+ ...__privateGet$4(this, _getFetchProps).call(this)
2689
3953
  });
2690
3954
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2691
3955
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2692
3956
  };
2693
3957
  _insertRecords = new WeakSet();
2694
3958
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2695
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2696
- const chunkedOperations = chunk(
2697
- objects.map((object) => ({
2698
- insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2699
- })),
2700
- BULK_OPERATION_MAX_SIZE
2701
- );
3959
+ const operations = await promiseMap(objects, async (object) => {
3960
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3961
+ return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
3962
+ });
3963
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2702
3964
  const ids = [];
2703
- for (const operations of chunkedOperations) {
3965
+ for (const operations2 of chunkedOperations) {
2704
3966
  const { results } = await branchTransaction({
2705
3967
  pathParams: {
2706
3968
  workspace: "{workspaceId}",
2707
3969
  dbBranchName: "{dbBranch}",
2708
3970
  region: "{region}"
2709
3971
  },
2710
- body: { operations },
2711
- ...fetchProps
3972
+ body: { operations: operations2 },
3973
+ ...__privateGet$4(this, _getFetchProps).call(this)
2712
3974
  });
2713
3975
  for (const result of results) {
2714
3976
  if (result.operation === "insert") {
@@ -2722,8 +3984,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2722
3984
  };
2723
3985
  _updateRecordWithID = new WeakSet();
2724
3986
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2725
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2726
- const { id: _id, ...record } = transformObjectLinks(object);
3987
+ if (!recordId)
3988
+ return null;
3989
+ const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2727
3990
  try {
2728
3991
  const response = await updateRecordWithID({
2729
3992
  pathParams: {
@@ -2735,7 +3998,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2735
3998
  },
2736
3999
  queryParams: { columns, ifVersion },
2737
4000
  body: record,
2738
- ...fetchProps
4001
+ ...__privateGet$4(this, _getFetchProps).call(this)
2739
4002
  });
2740
4003
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2741
4004
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2748,23 +4011,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2748
4011
  };
2749
4012
  _updateRecords = new WeakSet();
2750
4013
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2751
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2752
- const chunkedOperations = chunk(
2753
- objects.map(({ id, ...object }) => ({
2754
- update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2755
- })),
2756
- BULK_OPERATION_MAX_SIZE
2757
- );
4014
+ const operations = await promiseMap(objects, async ({ id, ...object }) => {
4015
+ const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4016
+ return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
4017
+ });
4018
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2758
4019
  const ids = [];
2759
- for (const operations of chunkedOperations) {
4020
+ for (const operations2 of chunkedOperations) {
2760
4021
  const { results } = await branchTransaction({
2761
4022
  pathParams: {
2762
4023
  workspace: "{workspaceId}",
2763
4024
  dbBranchName: "{dbBranch}",
2764
4025
  region: "{region}"
2765
4026
  },
2766
- body: { operations },
2767
- ...fetchProps
4027
+ body: { operations: operations2 },
4028
+ ...__privateGet$4(this, _getFetchProps).call(this)
2768
4029
  });
2769
4030
  for (const result of results) {
2770
4031
  if (result.operation === "update") {
@@ -2778,7 +4039,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2778
4039
  };
2779
4040
  _upsertRecordWithID = new WeakSet();
2780
4041
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2781
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
4042
+ if (!recordId)
4043
+ return null;
2782
4044
  const response = await upsertRecordWithID({
2783
4045
  pathParams: {
2784
4046
  workspace: "{workspaceId}",
@@ -2789,14 +4051,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2789
4051
  },
2790
4052
  queryParams: { columns, ifVersion },
2791
4053
  body: object,
2792
- ...fetchProps
4054
+ ...__privateGet$4(this, _getFetchProps).call(this)
2793
4055
  });
2794
4056
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2795
4057
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2796
4058
  };
2797
4059
  _deleteRecord = new WeakSet();
2798
4060
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2799
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
4061
+ if (!recordId)
4062
+ return null;
2800
4063
  try {
2801
4064
  const response = await deleteRecord({
2802
4065
  pathParams: {
@@ -2807,7 +4070,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2807
4070
  recordId
2808
4071
  },
2809
4072
  queryParams: { columns },
2810
- ...fetchProps
4073
+ ...__privateGet$4(this, _getFetchProps).call(this)
2811
4074
  });
2812
4075
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2813
4076
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2820,9 +4083,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2820
4083
  };
2821
4084
  _deleteRecords = new WeakSet();
2822
4085
  deleteRecords_fn = async function(recordIds) {
2823
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2824
4086
  const chunkedOperations = chunk(
2825
- recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
4087
+ compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2826
4088
  BULK_OPERATION_MAX_SIZE
2827
4089
  );
2828
4090
  for (const operations of chunkedOperations) {
@@ -2833,21 +4095,22 @@ deleteRecords_fn = async function(recordIds) {
2833
4095
  region: "{region}"
2834
4096
  },
2835
4097
  body: { operations },
2836
- ...fetchProps
4098
+ ...__privateGet$4(this, _getFetchProps).call(this)
2837
4099
  });
2838
4100
  }
2839
4101
  };
2840
4102
  _setCacheQuery = new WeakSet();
2841
4103
  setCacheQuery_fn = async function(query, meta, records) {
2842
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
4104
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
2843
4105
  };
2844
4106
  _getCacheQuery = new WeakSet();
2845
4107
  getCacheQuery_fn = async function(query) {
2846
4108
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2847
- const result = await __privateGet$4(this, _cache).get(key);
4109
+ const result = await __privateGet$4(this, _cache)?.get(key);
2848
4110
  if (!result)
2849
4111
  return null;
2850
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
4112
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
4113
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2851
4114
  if (ttl < 0)
2852
4115
  return null;
2853
4116
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2857,15 +4120,49 @@ _getSchemaTables$1 = new WeakSet();
2857
4120
  getSchemaTables_fn$1 = async function() {
2858
4121
  if (__privateGet$4(this, _schemaTables$2))
2859
4122
  return __privateGet$4(this, _schemaTables$2);
2860
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2861
4123
  const { schema } = await getBranchDetails({
2862
4124
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2863
- ...fetchProps
4125
+ ...__privateGet$4(this, _getFetchProps).call(this)
2864
4126
  });
2865
4127
  __privateSet$4(this, _schemaTables$2, schema.tables);
2866
4128
  return schema.tables;
2867
4129
  };
2868
- const transformObjectLinks = (object) => {
4130
+ _transformObjectToApi = new WeakSet();
4131
+ transformObjectToApi_fn = async function(object) {
4132
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
4133
+ const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
4134
+ if (!schema)
4135
+ throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
4136
+ const result = {};
4137
+ for (const [key, value] of Object.entries(object)) {
4138
+ if (key === "xata")
4139
+ continue;
4140
+ const type = schema.columns.find((column) => column.name === key)?.type;
4141
+ switch (type) {
4142
+ case "link": {
4143
+ result[key] = isIdentifiable(value) ? value.id : value;
4144
+ break;
4145
+ }
4146
+ case "datetime": {
4147
+ result[key] = value instanceof Date ? value.toISOString() : value;
4148
+ break;
4149
+ }
4150
+ case `file`:
4151
+ result[key] = await parseInputFileEntry(value);
4152
+ break;
4153
+ case "file[]":
4154
+ result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
4155
+ break;
4156
+ case "json":
4157
+ result[key] = stringifyJson(value);
4158
+ break;
4159
+ default:
4160
+ result[key] = value;
4161
+ }
4162
+ }
4163
+ return result;
4164
+ };
4165
+ const removeLinksFromObject = (object) => {
2869
4166
  return Object.entries(object).reduce((acc, [key, value]) => {
2870
4167
  if (key === "xata")
2871
4168
  return acc;
@@ -2902,18 +4199,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2902
4199
  if (item === column.name) {
2903
4200
  return [...acc, "*"];
2904
4201
  }
2905
- if (item.startsWith(`${column.name}.`)) {
4202
+ if (isString(item) && item.startsWith(`${column.name}.`)) {
2906
4203
  const [, ...path] = item.split(".");
2907
4204
  return [...acc, path.join(".")];
2908
4205
  }
2909
4206
  return acc;
2910
4207
  }, []);
2911
- data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
4208
+ data[column.name] = initObject(
4209
+ db,
4210
+ schemaTables,
4211
+ linkTable,
4212
+ value,
4213
+ selectedLinkColumns
4214
+ );
2912
4215
  } else {
2913
4216
  data[column.name] = null;
2914
4217
  }
2915
4218
  break;
2916
4219
  }
4220
+ case "file":
4221
+ data[column.name] = isDefined(value) ? new XataFile(value) : null;
4222
+ break;
4223
+ case "file[]":
4224
+ data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
4225
+ break;
4226
+ case "json":
4227
+ data[column.name] = parseJson(value);
4228
+ break;
2917
4229
  default:
2918
4230
  data[column.name] = value ?? null;
2919
4231
  if (column.notNull === true && value === null) {
@@ -2923,30 +4235,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2923
4235
  }
2924
4236
  }
2925
4237
  const record = { ...data };
4238
+ const serializable = { xata, ...removeLinksFromObject(data) };
4239
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2926
4240
  record.read = function(columns2) {
2927
4241
  return db[table].read(record["id"], columns2);
2928
4242
  };
2929
4243
  record.update = function(data2, b, c) {
2930
- const columns2 = isStringArray(b) ? b : ["*"];
4244
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2931
4245
  const ifVersion = parseIfVersion(b, c);
2932
4246
  return db[table].update(record["id"], data2, columns2, { ifVersion });
2933
4247
  };
2934
4248
  record.replace = function(data2, b, c) {
2935
- const columns2 = isStringArray(b) ? b : ["*"];
4249
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2936
4250
  const ifVersion = parseIfVersion(b, c);
2937
4251
  return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2938
4252
  };
2939
4253
  record.delete = function() {
2940
4254
  return db[table].delete(record["id"]);
2941
4255
  };
4256
+ record.xata = Object.freeze(metadata);
2942
4257
  record.getMetadata = function() {
2943
- return xata;
4258
+ return record.xata;
2944
4259
  };
2945
4260
  record.toSerializable = function() {
2946
- return JSON.parse(JSON.stringify(transformObjectLinks(data)));
4261
+ return JSON.parse(JSON.stringify(serializable));
2947
4262
  };
2948
4263
  record.toString = function() {
2949
- return JSON.stringify(transformObjectLinks(data));
4264
+ return JSON.stringify(serializable);
2950
4265
  };
2951
4266
  for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
2952
4267
  Object.defineProperty(record, prop, { enumerable: false });
@@ -2964,11 +4279,7 @@ function extractId(value) {
2964
4279
  function isValidColumn(columns, column) {
2965
4280
  if (columns.includes("*"))
2966
4281
  return true;
2967
- if (column.type === "link") {
2968
- const linkColumns = columns.filter((item) => item.startsWith(column.name));
2969
- return linkColumns.length > 0;
2970
- }
2971
- return columns.includes(column.name);
4282
+ return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
2972
4283
  }
2973
4284
  function parseIfVersion(...args) {
2974
4285
  for (const arg of args) {
@@ -2979,6 +4290,12 @@ function parseIfVersion(...args) {
2979
4290
  return void 0;
2980
4291
  }
2981
4292
 
4293
+ var __defProp$3 = Object.defineProperty;
4294
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4295
+ var __publicField$3 = (obj, key, value) => {
4296
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
4297
+ return value;
4298
+ };
2982
4299
  var __accessCheck$3 = (obj, member, msg) => {
2983
4300
  if (!member.has(obj))
2984
4301
  throw TypeError("Cannot " + msg);
@@ -3001,6 +4318,8 @@ var _map;
3001
4318
  class SimpleCache {
3002
4319
  constructor(options = {}) {
3003
4320
  __privateAdd$3(this, _map, void 0);
4321
+ __publicField$3(this, "capacity");
4322
+ __publicField$3(this, "defaultQueryTTL");
3004
4323
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
3005
4324
  this.capacity = options.max ?? 500;
3006
4325
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
@@ -3136,19 +4455,19 @@ class SearchPlugin extends XataPlugin {
3136
4455
  __privateAdd$1(this, _schemaTables, void 0);
3137
4456
  __privateSet$1(this, _schemaTables, schemaTables);
3138
4457
  }
3139
- build({ getFetchProps }) {
4458
+ build(pluginOptions) {
3140
4459
  return {
3141
4460
  all: async (query, options = {}) => {
3142
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3143
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
4461
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4462
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3144
4463
  return records.map((record) => {
3145
4464
  const { table = "orphan" } = record.xata;
3146
4465
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3147
4466
  });
3148
4467
  },
3149
4468
  byTable: async (query, options = {}) => {
3150
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3151
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
4469
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4470
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3152
4471
  return records.reduce((acc, record) => {
3153
4472
  const { table = "orphan" } = record.xata;
3154
4473
  const items = acc[table] ?? [];
@@ -3161,38 +4480,108 @@ class SearchPlugin extends XataPlugin {
3161
4480
  }
3162
4481
  _schemaTables = new WeakMap();
3163
4482
  _search = new WeakSet();
3164
- search_fn = async function(query, options, getFetchProps) {
3165
- const fetchProps = await getFetchProps();
4483
+ search_fn = async function(query, options, pluginOptions) {
3166
4484
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3167
4485
  const { records } = await searchBranch({
3168
4486
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4487
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3169
4488
  body: { tables, query, fuzziness, prefix, highlight, page },
3170
- ...fetchProps
4489
+ ...pluginOptions
3171
4490
  });
3172
4491
  return records;
3173
4492
  };
3174
4493
  _getSchemaTables = new WeakSet();
3175
- getSchemaTables_fn = async function(getFetchProps) {
4494
+ getSchemaTables_fn = async function(pluginOptions) {
3176
4495
  if (__privateGet$1(this, _schemaTables))
3177
4496
  return __privateGet$1(this, _schemaTables);
3178
- const fetchProps = await getFetchProps();
3179
4497
  const { schema } = await getBranchDetails({
3180
4498
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3181
- ...fetchProps
4499
+ ...pluginOptions
3182
4500
  });
3183
4501
  __privateSet$1(this, _schemaTables, schema.tables);
3184
4502
  return schema.tables;
3185
4503
  };
3186
4504
 
4505
+ function escapeElement(elementRepresentation) {
4506
+ const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
4507
+ return '"' + escaped + '"';
4508
+ }
4509
+ function arrayString(val) {
4510
+ let result = "{";
4511
+ for (let i = 0; i < val.length; i++) {
4512
+ if (i > 0) {
4513
+ result = result + ",";
4514
+ }
4515
+ if (val[i] === null || typeof val[i] === "undefined") {
4516
+ result = result + "NULL";
4517
+ } else if (Array.isArray(val[i])) {
4518
+ result = result + arrayString(val[i]);
4519
+ } else if (val[i] instanceof Buffer) {
4520
+ result += "\\\\x" + val[i].toString("hex");
4521
+ } else {
4522
+ result += escapeElement(prepareValue(val[i]));
4523
+ }
4524
+ }
4525
+ result = result + "}";
4526
+ return result;
4527
+ }
4528
+ function prepareValue(value) {
4529
+ if (!isDefined(value))
4530
+ return null;
4531
+ if (value instanceof Date) {
4532
+ return value.toISOString();
4533
+ }
4534
+ if (Array.isArray(value)) {
4535
+ return arrayString(value);
4536
+ }
4537
+ if (isObject(value)) {
4538
+ return JSON.stringify(value);
4539
+ }
4540
+ try {
4541
+ return value.toString();
4542
+ } catch (e) {
4543
+ return value;
4544
+ }
4545
+ }
4546
+ function prepareParams(param1, param2) {
4547
+ if (isString(param1)) {
4548
+ return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
4549
+ }
4550
+ if (isStringArray(param1)) {
4551
+ const statement = param1.reduce((acc, curr, index) => {
4552
+ return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
4553
+ }, "");
4554
+ return { statement, params: param2?.map((value) => prepareValue(value)) };
4555
+ }
4556
+ if (isObject(param1)) {
4557
+ const { statement, params, consistency } = param1;
4558
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency };
4559
+ }
4560
+ throw new Error("Invalid query");
4561
+ }
4562
+
4563
+ class SQLPlugin extends XataPlugin {
4564
+ build(pluginOptions) {
4565
+ return async (param1, ...param2) => {
4566
+ const { statement, params, consistency } = prepareParams(param1, param2);
4567
+ const { records, warning } = await sqlQuery({
4568
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4569
+ body: { statement, params, consistency },
4570
+ ...pluginOptions
4571
+ });
4572
+ return { records, warning };
4573
+ };
4574
+ }
4575
+ }
4576
+
3187
4577
  class TransactionPlugin extends XataPlugin {
3188
- build({ getFetchProps }) {
4578
+ build(pluginOptions) {
3189
4579
  return {
3190
4580
  run: async (operations) => {
3191
- const fetchProps = await getFetchProps();
3192
4581
  const response = await branchTransaction({
3193
4582
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3194
4583
  body: { operations },
3195
- ...fetchProps
4584
+ ...pluginOptions
3196
4585
  });
3197
4586
  return response;
3198
4587
  }
@@ -3200,90 +4589,12 @@ class TransactionPlugin extends XataPlugin {
3200
4589
  }
3201
4590
  }
3202
4591
 
3203
- const isBranchStrategyBuilder = (strategy) => {
3204
- return typeof strategy === "function";
4592
+ var __defProp$2 = Object.defineProperty;
4593
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4594
+ var __publicField$2 = (obj, key, value) => {
4595
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
4596
+ return value;
3205
4597
  };
3206
-
3207
- async function getCurrentBranchName(options) {
3208
- const { branch, envBranch } = getEnvironment();
3209
- if (branch)
3210
- return branch;
3211
- const gitBranch = envBranch || await getGitBranch();
3212
- return resolveXataBranch(gitBranch, options);
3213
- }
3214
- async function getCurrentBranchDetails(options) {
3215
- const branch = await getCurrentBranchName(options);
3216
- return getDatabaseBranch(branch, options);
3217
- }
3218
- async function resolveXataBranch(gitBranch, options) {
3219
- const databaseURL = options?.databaseURL || getDatabaseURL();
3220
- const apiKey = options?.apiKey || getAPIKey();
3221
- if (!databaseURL)
3222
- throw new Error(
3223
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3224
- );
3225
- if (!apiKey)
3226
- throw new Error(
3227
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3228
- );
3229
- const [protocol, , host, , dbName] = databaseURL.split("/");
3230
- const urlParts = parseWorkspacesUrlParts(host);
3231
- if (!urlParts)
3232
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3233
- const { workspace, region } = urlParts;
3234
- const { fallbackBranch } = getEnvironment();
3235
- const { branch } = await resolveBranch({
3236
- apiKey,
3237
- apiUrl: databaseURL,
3238
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3239
- workspacesApiUrl: `${protocol}//${host}`,
3240
- pathParams: { dbName, workspace, region },
3241
- queryParams: { gitBranch, fallbackBranch },
3242
- trace: defaultTrace,
3243
- clientName: options?.clientName
3244
- });
3245
- return branch;
3246
- }
3247
- async function getDatabaseBranch(branch, options) {
3248
- const databaseURL = options?.databaseURL || getDatabaseURL();
3249
- const apiKey = options?.apiKey || getAPIKey();
3250
- if (!databaseURL)
3251
- throw new Error(
3252
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3253
- );
3254
- if (!apiKey)
3255
- throw new Error(
3256
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3257
- );
3258
- const [protocol, , host, , database] = databaseURL.split("/");
3259
- const urlParts = parseWorkspacesUrlParts(host);
3260
- if (!urlParts)
3261
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3262
- const { workspace, region } = urlParts;
3263
- try {
3264
- return await getBranchDetails({
3265
- apiKey,
3266
- apiUrl: databaseURL,
3267
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3268
- workspacesApiUrl: `${protocol}//${host}`,
3269
- pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3270
- trace: defaultTrace
3271
- });
3272
- } catch (err) {
3273
- if (isObject(err) && err.status === 404)
3274
- return null;
3275
- throw err;
3276
- }
3277
- }
3278
- function getDatabaseURL() {
3279
- try {
3280
- const { databaseURL } = getEnvironment();
3281
- return databaseURL;
3282
- } catch (err) {
3283
- return void 0;
3284
- }
3285
- }
3286
-
3287
4598
  var __accessCheck = (obj, member, msg) => {
3288
4599
  if (!member.has(obj))
3289
4600
  throw TypeError("Cannot " + msg);
@@ -3307,46 +4618,46 @@ var __privateMethod = (obj, member, method) => {
3307
4618
  return method;
3308
4619
  };
3309
4620
  const buildClient = (plugins) => {
3310
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
4621
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3311
4622
  return _a = class {
3312
4623
  constructor(options = {}, schemaTables) {
3313
4624
  __privateAdd(this, _parseOptions);
3314
4625
  __privateAdd(this, _getFetchProps);
3315
- __privateAdd(this, _evaluateBranch);
3316
- __privateAdd(this, _branch, void 0);
3317
4626
  __privateAdd(this, _options, void 0);
4627
+ __publicField$2(this, "db");
4628
+ __publicField$2(this, "search");
4629
+ __publicField$2(this, "transactions");
4630
+ __publicField$2(this, "sql");
4631
+ __publicField$2(this, "files");
3318
4632
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3319
4633
  __privateSet(this, _options, safeOptions);
3320
4634
  const pluginOptions = {
3321
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
4635
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3322
4636
  cache: safeOptions.cache,
3323
- trace: safeOptions.trace
4637
+ host: safeOptions.host
3324
4638
  };
3325
4639
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3326
4640
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3327
4641
  const transactions = new TransactionPlugin().build(pluginOptions);
4642
+ const sql = new SQLPlugin().build(pluginOptions);
4643
+ const files = new FilesPlugin().build(pluginOptions);
3328
4644
  this.db = db;
3329
4645
  this.search = search;
3330
4646
  this.transactions = transactions;
4647
+ this.sql = sql;
4648
+ this.files = files;
3331
4649
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3332
4650
  if (namespace === void 0)
3333
4651
  continue;
3334
- const result = namespace.build(pluginOptions);
3335
- if (result instanceof Promise) {
3336
- void result.then((namespace2) => {
3337
- this[key] = namespace2;
3338
- });
3339
- } else {
3340
- this[key] = result;
3341
- }
4652
+ this[key] = namespace.build(pluginOptions);
3342
4653
  }
3343
4654
  }
3344
4655
  async getConfig() {
3345
4656
  const databaseURL = __privateGet(this, _options).databaseURL;
3346
- const branch = await __privateGet(this, _options).branch();
4657
+ const branch = __privateGet(this, _options).branch;
3347
4658
  return { databaseURL, branch };
3348
4659
  }
3349
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
4660
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3350
4661
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3351
4662
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3352
4663
  if (isBrowser && !enableBrowser) {
@@ -3360,70 +4671,88 @@ const buildClient = (plugins) => {
3360
4671
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3361
4672
  const trace = options?.trace ?? defaultTrace;
3362
4673
  const clientName = options?.clientName;
3363
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3364
- apiKey,
3365
- databaseURL,
3366
- fetchImpl: options?.fetch,
3367
- clientName: options?.clientName
3368
- });
4674
+ const host = options?.host ?? "production";
4675
+ const xataAgentExtra = options?.xataAgentExtra;
3369
4676
  if (!apiKey) {
3370
4677
  throw new Error("Option apiKey is required");
3371
4678
  }
3372
4679
  if (!databaseURL) {
3373
4680
  throw new Error("Option databaseURL is required");
3374
4681
  }
3375
- return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
3376
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
4682
+ const envBranch = getBranch();
4683
+ const previewBranch = getPreviewBranch();
4684
+ const branch = options?.branch || previewBranch || envBranch || "main";
4685
+ if (!!previewBranch && branch !== previewBranch) {
4686
+ console.warn(
4687
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
4688
+ );
4689
+ } else if (!!envBranch && branch !== envBranch) {
4690
+ console.warn(
4691
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4692
+ );
4693
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
4694
+ console.warn(
4695
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4696
+ );
4697
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
4698
+ console.warn(
4699
+ `No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
4700
+ );
4701
+ }
4702
+ return {
4703
+ fetch,
4704
+ databaseURL,
4705
+ apiKey,
4706
+ branch,
4707
+ cache,
4708
+ trace,
4709
+ host,
4710
+ clientID: generateUUID(),
4711
+ enableBrowser,
4712
+ clientName,
4713
+ xataAgentExtra
4714
+ };
4715
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3377
4716
  fetch,
3378
4717
  apiKey,
3379
4718
  databaseURL,
3380
4719
  branch,
3381
4720
  trace,
3382
4721
  clientID,
3383
- clientName
4722
+ clientName,
4723
+ xataAgentExtra
3384
4724
  }) {
3385
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3386
- if (!branchValue)
3387
- throw new Error("Unable to resolve branch value");
3388
4725
  return {
3389
- fetchImpl: fetch,
4726
+ fetch,
3390
4727
  apiKey,
3391
4728
  apiUrl: "",
4729
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3392
4730
  workspacesApiUrl: (path, params) => {
3393
4731
  const hasBranch = params.dbBranchName ?? params.branch;
3394
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
4732
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3395
4733
  return databaseURL + newPath;
3396
4734
  },
3397
4735
  trace,
3398
4736
  clientID,
3399
- clientName
3400
- };
3401
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3402
- if (__privateGet(this, _branch))
3403
- return __privateGet(this, _branch);
3404
- if (param === void 0)
3405
- return void 0;
3406
- const strategies = Array.isArray(param) ? [...param] : [param];
3407
- const evaluateBranch = async (strategy) => {
3408
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
4737
+ clientName,
4738
+ xataAgentExtra
3409
4739
  };
3410
- for await (const strategy of strategies) {
3411
- const branch = await evaluateBranch(strategy);
3412
- if (branch) {
3413
- __privateSet(this, _branch, branch);
3414
- return branch;
3415
- }
3416
- }
3417
4740
  }, _a;
3418
4741
  };
3419
4742
  class BaseClient extends buildClient() {
3420
4743
  }
3421
4744
 
4745
+ var __defProp$1 = Object.defineProperty;
4746
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4747
+ var __publicField$1 = (obj, key, value) => {
4748
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
4749
+ return value;
4750
+ };
3422
4751
  const META = "__";
3423
4752
  const VALUE = "___";
3424
4753
  class Serializer {
3425
4754
  constructor() {
3426
- this.classes = {};
4755
+ __publicField$1(this, "classes", {});
3427
4756
  }
3428
4757
  add(clazz) {
3429
4758
  this.classes[clazz.name] = clazz;
@@ -3501,15 +4830,23 @@ function buildWorkerRunner(config) {
3501
4830
  };
3502
4831
  }
3503
4832
 
4833
+ var __defProp = Object.defineProperty;
4834
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4835
+ var __publicField = (obj, key, value) => {
4836
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4837
+ return value;
4838
+ };
3504
4839
  class XataError extends Error {
3505
4840
  constructor(message, status) {
3506
4841
  super(message);
4842
+ __publicField(this, "status");
3507
4843
  this.status = status;
3508
4844
  }
3509
4845
  }
3510
4846
 
3511
4847
  exports.BaseClient = BaseClient;
3512
4848
  exports.FetcherError = FetcherError;
4849
+ exports.FilesPlugin = FilesPlugin;
3513
4850
  exports.Operations = operationsByTag;
3514
4851
  exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
3515
4852
  exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
@@ -3518,8 +4855,10 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
3518
4855
  exports.Page = Page;
3519
4856
  exports.Query = Query;
3520
4857
  exports.RecordArray = RecordArray;
4858
+ exports.RecordColumnTypes = RecordColumnTypes;
3521
4859
  exports.Repository = Repository;
3522
4860
  exports.RestRepository = RestRepository;
4861
+ exports.SQLPlugin = SQLPlugin;
3523
4862
  exports.SchemaPlugin = SchemaPlugin;
3524
4863
  exports.SearchPlugin = SearchPlugin;
3525
4864
  exports.Serializer = Serializer;
@@ -3527,14 +4866,19 @@ exports.SimpleCache = SimpleCache;
3527
4866
  exports.XataApiClient = XataApiClient;
3528
4867
  exports.XataApiPlugin = XataApiPlugin;
3529
4868
  exports.XataError = XataError;
4869
+ exports.XataFile = XataFile;
3530
4870
  exports.XataPlugin = XataPlugin;
3531
4871
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
3532
4872
  exports.addGitBranchesEntry = addGitBranchesEntry;
3533
4873
  exports.addTableColumn = addTableColumn;
3534
4874
  exports.aggregateTable = aggregateTable;
3535
4875
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
4876
+ exports.askTable = askTable;
4877
+ exports.askTableSession = askTableSession;
3536
4878
  exports.branchTransaction = branchTransaction;
3537
4879
  exports.buildClient = buildClient;
4880
+ exports.buildPreviewBranchName = buildPreviewBranchName;
4881
+ exports.buildProviderString = buildProviderString;
3538
4882
  exports.buildWorkerRunner = buildWorkerRunner;
3539
4883
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
3540
4884
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
@@ -3542,6 +4886,7 @@ exports.compareBranchSchemas = compareBranchSchemas;
3542
4886
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3543
4887
  exports.compareMigrationRequest = compareMigrationRequest;
3544
4888
  exports.contains = contains;
4889
+ exports.copyBranch = copyBranch;
3545
4890
  exports.createBranch = createBranch;
3546
4891
  exports.createDatabase = createDatabase;
3547
4892
  exports.createMigrationRequest = createMigrationRequest;
@@ -3551,18 +4896,26 @@ exports.createWorkspace = createWorkspace;
3551
4896
  exports.deleteBranch = deleteBranch;
3552
4897
  exports.deleteColumn = deleteColumn;
3553
4898
  exports.deleteDatabase = deleteDatabase;
4899
+ exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
4900
+ exports.deleteFile = deleteFile;
4901
+ exports.deleteFileItem = deleteFileItem;
4902
+ exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
3554
4903
  exports.deleteRecord = deleteRecord;
3555
4904
  exports.deleteTable = deleteTable;
3556
4905
  exports.deleteUser = deleteUser;
3557
4906
  exports.deleteUserAPIKey = deleteUserAPIKey;
4907
+ exports.deleteUserOAuthClient = deleteUserOAuthClient;
3558
4908
  exports.deleteWorkspace = deleteWorkspace;
3559
4909
  exports.deserialize = deserialize;
3560
4910
  exports.endsWith = endsWith;
3561
4911
  exports.equals = equals;
3562
4912
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
3563
4913
  exports.exists = exists;
4914
+ exports.fileAccess = fileAccess;
3564
4915
  exports.ge = ge;
3565
4916
  exports.getAPIKey = getAPIKey;
4917
+ exports.getAuthorizationCode = getAuthorizationCode;
4918
+ exports.getBranch = getBranch;
3566
4919
  exports.getBranchDetails = getBranchDetails;
3567
4920
  exports.getBranchList = getBranchList;
3568
4921
  exports.getBranchMetadata = getBranchMetadata;
@@ -3571,23 +4924,28 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
3571
4924
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
3572
4925
  exports.getBranchStats = getBranchStats;
3573
4926
  exports.getColumn = getColumn;
3574
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
3575
- exports.getCurrentBranchName = getCurrentBranchName;
4927
+ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3576
4928
  exports.getDatabaseList = getDatabaseList;
3577
4929
  exports.getDatabaseMetadata = getDatabaseMetadata;
3578
4930
  exports.getDatabaseURL = getDatabaseURL;
4931
+ exports.getFile = getFile;
4932
+ exports.getFileItem = getFileItem;
3579
4933
  exports.getGitBranchesMapping = getGitBranchesMapping;
3580
4934
  exports.getHostUrl = getHostUrl;
3581
4935
  exports.getMigrationRequest = getMigrationRequest;
3582
4936
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
4937
+ exports.getPreviewBranch = getPreviewBranch;
3583
4938
  exports.getRecord = getRecord;
3584
4939
  exports.getTableColumns = getTableColumns;
3585
4940
  exports.getTableSchema = getTableSchema;
3586
4941
  exports.getUser = getUser;
3587
4942
  exports.getUserAPIKeys = getUserAPIKeys;
4943
+ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
4944
+ exports.getUserOAuthClients = getUserOAuthClients;
3588
4945
  exports.getWorkspace = getWorkspace;
3589
4946
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
3590
4947
  exports.getWorkspacesList = getWorkspacesList;
4948
+ exports.grantAuthorizationCode = grantAuthorizationCode;
3591
4949
  exports.greaterEquals = greaterEquals;
3592
4950
  exports.greaterThan = greaterThan;
3593
4951
  exports.greaterThanEquals = greaterThanEquals;
@@ -3606,6 +4964,8 @@ exports.isHostProviderAlias = isHostProviderAlias;
3606
4964
  exports.isHostProviderBuilder = isHostProviderBuilder;
3607
4965
  exports.isIdentifiable = isIdentifiable;
3608
4966
  exports.isNot = isNot;
4967
+ exports.isValidExpandedColumn = isValidExpandedColumn;
4968
+ exports.isValidSelectableColumns = isValidSelectableColumns;
3609
4969
  exports.isXataRecord = isXataRecord;
3610
4970
  exports.le = le;
3611
4971
  exports.lessEquals = lessEquals;
@@ -3622,23 +4982,31 @@ exports.parseProviderString = parseProviderString;
3622
4982
  exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
3623
4983
  exports.pattern = pattern;
3624
4984
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
4985
+ exports.pushBranchMigrations = pushBranchMigrations;
4986
+ exports.putFile = putFile;
4987
+ exports.putFileItem = putFileItem;
3625
4988
  exports.queryMigrationRequests = queryMigrationRequests;
3626
4989
  exports.queryTable = queryTable;
3627
4990
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
3628
4991
  exports.removeWorkspaceMember = removeWorkspaceMember;
4992
+ exports.renameDatabase = renameDatabase;
3629
4993
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
3630
4994
  exports.resolveBranch = resolveBranch;
3631
4995
  exports.searchBranch = searchBranch;
3632
4996
  exports.searchTable = searchTable;
3633
4997
  exports.serialize = serialize;
3634
4998
  exports.setTableSchema = setTableSchema;
4999
+ exports.sqlQuery = sqlQuery;
3635
5000
  exports.startsWith = startsWith;
3636
5001
  exports.summarizeTable = summarizeTable;
5002
+ exports.transformImage = transformImage;
3637
5003
  exports.updateBranchMetadata = updateBranchMetadata;
3638
5004
  exports.updateBranchSchema = updateBranchSchema;
3639
5005
  exports.updateColumn = updateColumn;
5006
+ exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
3640
5007
  exports.updateDatabaseMetadata = updateDatabaseMetadata;
3641
5008
  exports.updateMigrationRequest = updateMigrationRequest;
5009
+ exports.updateOAuthAccessToken = updateOAuthAccessToken;
3642
5010
  exports.updateRecordWithID = updateRecordWithID;
3643
5011
  exports.updateTable = updateTable;
3644
5012
  exports.updateUser = updateUser;
@@ -3646,4 +5014,5 @@ exports.updateWorkspace = updateWorkspace;
3646
5014
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
3647
5015
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
3648
5016
  exports.upsertRecordWithID = upsertRecordWithID;
5017
+ exports.vectorSearchTable = vectorSearchTable;
3649
5018
  //# sourceMappingURL=index.cjs.map