@xata.io/client 0.0.0-alpha.vfbde008 → 0.0.0-alpha.vfc446ea

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
@@ -29,8 +29,11 @@ function notEmpty(value) {
29
29
  function compact(arr) {
30
30
  return arr.filter(notEmpty);
31
31
  }
32
+ function compactObject(obj) {
33
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
34
+ }
32
35
  function isObject(value) {
33
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
36
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
34
37
  }
35
38
  function isDefined(value) {
36
39
  return value !== null && value !== void 0;
@@ -85,6 +88,27 @@ function chunk(array, chunkSize) {
85
88
  async function timeout(ms) {
86
89
  return new Promise((resolve) => setTimeout(resolve, ms));
87
90
  }
91
+ function timeoutWithCancel(ms) {
92
+ let timeoutId;
93
+ const promise = new Promise((resolve) => {
94
+ timeoutId = setTimeout(() => {
95
+ resolve();
96
+ }, ms);
97
+ });
98
+ return {
99
+ cancel: () => clearTimeout(timeoutId),
100
+ promise
101
+ };
102
+ }
103
+ function promiseMap(inputValues, mapper) {
104
+ const reducer = (acc$, inputValue) => acc$.then(
105
+ (acc) => mapper(inputValue).then((result) => {
106
+ acc.push(result);
107
+ return acc;
108
+ })
109
+ );
110
+ return inputValues.reduce(reducer, Promise.resolve([]));
111
+ }
88
112
 
89
113
  function getEnvironment() {
90
114
  try {
@@ -93,8 +117,10 @@ function getEnvironment() {
93
117
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
94
118
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
95
119
  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()
120
+ deployPreview: process.env.XATA_PREVIEW,
121
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
122
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
123
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
98
124
  };
99
125
  }
100
126
  } catch (err) {
@@ -105,8 +131,10 @@ function getEnvironment() {
105
131
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
106
132
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
107
133
  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()
134
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
135
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
136
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
137
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
110
138
  };
111
139
  }
112
140
  } catch (err) {
@@ -115,8 +143,10 @@ function getEnvironment() {
115
143
  apiKey: getGlobalApiKey(),
116
144
  databaseURL: getGlobalDatabaseURL(),
117
145
  branch: getGlobalBranch(),
118
- envBranch: void 0,
119
- fallbackBranch: getGlobalFallbackBranch()
146
+ deployPreview: void 0,
147
+ deployPreviewBranch: void 0,
148
+ vercelGitCommitRef: void 0,
149
+ vercelGitRepoOwner: void 0
120
150
  };
121
151
  }
122
152
  function getEnableBrowserVariable() {
@@ -159,42 +189,59 @@ function getGlobalBranch() {
159
189
  return void 0;
160
190
  }
161
191
  }
162
- function getGlobalFallbackBranch() {
192
+ function getDatabaseURL() {
163
193
  try {
164
- return XATA_FALLBACK_BRANCH;
194
+ const { databaseURL } = getEnvironment();
195
+ return databaseURL;
165
196
  } catch (err) {
166
197
  return void 0;
167
198
  }
168
199
  }
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"] };
200
+ function getAPIKey() {
174
201
  try {
175
- if (typeof require === "function") {
176
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
177
- }
202
+ const { apiKey } = getEnvironment();
203
+ return apiKey;
178
204
  } catch (err) {
205
+ return void 0;
179
206
  }
207
+ }
208
+ function getBranch() {
180
209
  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
- }
210
+ const { branch } = getEnvironment();
211
+ return branch;
185
212
  } catch (err) {
213
+ return void 0;
186
214
  }
187
215
  }
188
-
189
- function getAPIKey() {
216
+ function buildPreviewBranchName({ org, branch }) {
217
+ return `preview-${org}-${branch}`;
218
+ }
219
+ function getPreviewBranch() {
190
220
  try {
191
- const { apiKey } = getEnvironment();
192
- return apiKey;
221
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
222
+ if (deployPreviewBranch)
223
+ return deployPreviewBranch;
224
+ switch (deployPreview) {
225
+ case "vercel": {
226
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
227
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
228
+ return void 0;
229
+ }
230
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
231
+ }
232
+ }
233
+ return void 0;
193
234
  } catch (err) {
194
235
  return void 0;
195
236
  }
196
237
  }
197
238
 
239
+ var __defProp$8 = Object.defineProperty;
240
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
241
+ var __publicField$8 = (obj, key, value) => {
242
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
243
+ return value;
244
+ };
198
245
  var __accessCheck$8 = (obj, member, msg) => {
199
246
  if (!member.has(obj))
200
247
  throw TypeError("Cannot " + msg);
@@ -218,6 +265,7 @@ var __privateMethod$4 = (obj, member, method) => {
218
265
  return method;
219
266
  };
220
267
  var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
268
+ const REQUEST_TIMEOUT = 3e4;
221
269
  function getFetchImplementation(userFetch) {
222
270
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
223
271
  const fetchImpl = userFetch ?? globalFetch;
@@ -234,6 +282,8 @@ class ApiRequestPool {
234
282
  __privateAdd$8(this, _fetch, void 0);
235
283
  __privateAdd$8(this, _queue, void 0);
236
284
  __privateAdd$8(this, _concurrency, void 0);
285
+ __publicField$8(this, "running");
286
+ __publicField$8(this, "started");
237
287
  __privateSet$8(this, _queue, []);
238
288
  __privateSet$8(this, _concurrency, concurrency);
239
289
  this.running = 0;
@@ -249,18 +299,22 @@ class ApiRequestPool {
249
299
  return __privateGet$8(this, _fetch);
250
300
  }
251
301
  request(url, options) {
252
- const start = new Date();
253
- const fetch2 = this.getFetch();
302
+ const start = /* @__PURE__ */ new Date();
303
+ const fetchImpl = this.getFetch();
254
304
  const runRequest = async (stalled = false) => {
255
- const response = await fetch2(url, options);
305
+ const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
306
+ const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
307
+ if (!response) {
308
+ throw new Error("Request timed out");
309
+ }
256
310
  if (response.status === 429) {
257
311
  const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
258
312
  await timeout(rateLimitReset * 1e3);
259
313
  return await runRequest(true);
260
314
  }
261
315
  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`);
316
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
317
+ console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
264
318
  }
265
319
  return response;
266
320
  };
@@ -302,16 +356,199 @@ function generateUUID() {
302
356
  });
303
357
  }
304
358
 
305
- const VERSION = "0.22.1";
359
+ async function getBytes(stream, onChunk) {
360
+ const reader = stream.getReader();
361
+ let result;
362
+ while (!(result = await reader.read()).done) {
363
+ onChunk(result.value);
364
+ }
365
+ }
366
+ function getLines(onLine) {
367
+ let buffer;
368
+ let position;
369
+ let fieldLength;
370
+ let discardTrailingNewline = false;
371
+ return function onChunk(arr) {
372
+ if (buffer === void 0) {
373
+ buffer = arr;
374
+ position = 0;
375
+ fieldLength = -1;
376
+ } else {
377
+ buffer = concat(buffer, arr);
378
+ }
379
+ const bufLength = buffer.length;
380
+ let lineStart = 0;
381
+ while (position < bufLength) {
382
+ if (discardTrailingNewline) {
383
+ if (buffer[position] === 10 /* NewLine */) {
384
+ lineStart = ++position;
385
+ }
386
+ discardTrailingNewline = false;
387
+ }
388
+ let lineEnd = -1;
389
+ for (; position < bufLength && lineEnd === -1; ++position) {
390
+ switch (buffer[position]) {
391
+ case 58 /* Colon */:
392
+ if (fieldLength === -1) {
393
+ fieldLength = position - lineStart;
394
+ }
395
+ break;
396
+ case 13 /* CarriageReturn */:
397
+ discardTrailingNewline = true;
398
+ case 10 /* NewLine */:
399
+ lineEnd = position;
400
+ break;
401
+ }
402
+ }
403
+ if (lineEnd === -1) {
404
+ break;
405
+ }
406
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
407
+ lineStart = position;
408
+ fieldLength = -1;
409
+ }
410
+ if (lineStart === bufLength) {
411
+ buffer = void 0;
412
+ } else if (lineStart !== 0) {
413
+ buffer = buffer.subarray(lineStart);
414
+ position -= lineStart;
415
+ }
416
+ };
417
+ }
418
+ function getMessages(onId, onRetry, onMessage) {
419
+ let message = newMessage();
420
+ const decoder = new TextDecoder();
421
+ return function onLine(line, fieldLength) {
422
+ if (line.length === 0) {
423
+ onMessage?.(message);
424
+ message = newMessage();
425
+ } else if (fieldLength > 0) {
426
+ const field = decoder.decode(line.subarray(0, fieldLength));
427
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
428
+ const value = decoder.decode(line.subarray(valueOffset));
429
+ switch (field) {
430
+ case "data":
431
+ message.data = message.data ? message.data + "\n" + value : value;
432
+ break;
433
+ case "event":
434
+ message.event = value;
435
+ break;
436
+ case "id":
437
+ onId(message.id = value);
438
+ break;
439
+ case "retry":
440
+ const retry = parseInt(value, 10);
441
+ if (!isNaN(retry)) {
442
+ onRetry(message.retry = retry);
443
+ }
444
+ break;
445
+ }
446
+ }
447
+ };
448
+ }
449
+ function concat(a, b) {
450
+ const res = new Uint8Array(a.length + b.length);
451
+ res.set(a);
452
+ res.set(b, a.length);
453
+ return res;
454
+ }
455
+ function newMessage() {
456
+ return {
457
+ data: "",
458
+ event: "",
459
+ id: "",
460
+ retry: void 0
461
+ };
462
+ }
463
+ const EventStreamContentType = "text/event-stream";
464
+ const LastEventId = "last-event-id";
465
+ function fetchEventSource(input, {
466
+ signal: inputSignal,
467
+ headers: inputHeaders,
468
+ onopen: inputOnOpen,
469
+ onmessage,
470
+ onclose,
471
+ onerror,
472
+ fetch: inputFetch,
473
+ ...rest
474
+ }) {
475
+ return new Promise((resolve, reject) => {
476
+ const headers = { ...inputHeaders };
477
+ if (!headers.accept) {
478
+ headers.accept = EventStreamContentType;
479
+ }
480
+ let curRequestController;
481
+ function dispose() {
482
+ curRequestController.abort();
483
+ }
484
+ inputSignal?.addEventListener("abort", () => {
485
+ dispose();
486
+ resolve();
487
+ });
488
+ const fetchImpl = inputFetch ?? fetch;
489
+ const onopen = inputOnOpen ?? defaultOnOpen;
490
+ async function create() {
491
+ curRequestController = new AbortController();
492
+ try {
493
+ const response = await fetchImpl(input, {
494
+ ...rest,
495
+ headers,
496
+ signal: curRequestController.signal
497
+ });
498
+ await onopen(response);
499
+ await getBytes(
500
+ response.body,
501
+ getLines(
502
+ getMessages(
503
+ (id) => {
504
+ if (id) {
505
+ headers[LastEventId] = id;
506
+ } else {
507
+ delete headers[LastEventId];
508
+ }
509
+ },
510
+ (_retry) => {
511
+ },
512
+ onmessage
513
+ )
514
+ )
515
+ );
516
+ onclose?.();
517
+ dispose();
518
+ resolve();
519
+ } catch (err) {
520
+ }
521
+ }
522
+ create();
523
+ });
524
+ }
525
+ function defaultOnOpen(response) {
526
+ const contentType = response.headers?.get("content-type");
527
+ if (!contentType?.startsWith(EventStreamContentType)) {
528
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
529
+ }
530
+ }
531
+
532
+ const VERSION = "0.25.2";
306
533
 
534
+ var __defProp$7 = Object.defineProperty;
535
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
536
+ var __publicField$7 = (obj, key, value) => {
537
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
538
+ return value;
539
+ };
307
540
  class ErrorWithCause extends Error {
308
541
  constructor(message, options) {
309
542
  super(message, options);
543
+ __publicField$7(this, "cause");
310
544
  }
311
545
  }
312
546
  class FetcherError extends ErrorWithCause {
313
547
  constructor(status, data, requestId) {
314
548
  super(getMessage(data));
549
+ __publicField$7(this, "status");
550
+ __publicField$7(this, "requestId");
551
+ __publicField$7(this, "errors");
315
552
  this.status = status;
316
553
  this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
317
554
  this.requestId = requestId;
@@ -378,6 +615,15 @@ function hostHeader(url) {
378
615
  const { groups } = pattern.exec(url) ?? {};
379
616
  return groups?.host ? { Host: groups.host } : {};
380
617
  }
618
+ function parseBody(body, headers) {
619
+ if (!isDefined(body))
620
+ return void 0;
621
+ const { "Content-Type": contentType } = headers ?? {};
622
+ if (String(contentType).toLowerCase() === "application/json") {
623
+ return JSON.stringify(body);
624
+ }
625
+ return body;
626
+ }
381
627
  const defaultClientID = generateUUID();
382
628
  async function fetch$1({
383
629
  url: path,
@@ -386,7 +632,7 @@ async function fetch$1({
386
632
  headers: customHeaders,
387
633
  pathParams,
388
634
  queryParams,
389
- fetchImpl,
635
+ fetch: fetch2,
390
636
  apiKey,
391
637
  endpoint,
392
638
  apiUrl,
@@ -397,9 +643,10 @@ async function fetch$1({
397
643
  sessionID,
398
644
  clientName,
399
645
  xataAgentExtra,
400
- fetchOptions = {}
646
+ fetchOptions = {},
647
+ rawResponse = false
401
648
  }) {
402
- pool.setFetch(fetchImpl);
649
+ pool.setFetch(fetch2);
403
650
  return await trace(
404
651
  `${method.toUpperCase()} ${path}`,
405
652
  async ({ setAttributes }) => {
@@ -416,7 +663,7 @@ async function fetch$1({
416
663
  isDefined(clientName) ? ["service", clientName] : void 0,
417
664
  ...Object.entries(xataAgentExtra ?? {})
418
665
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
419
- const headers = {
666
+ const headers = compactObject({
420
667
  "Accept-Encoding": "identity",
421
668
  "Content-Type": "application/json",
422
669
  "X-Xata-Client-ID": clientID ?? defaultClientID,
@@ -425,11 +672,11 @@ async function fetch$1({
425
672
  ...customHeaders,
426
673
  ...hostHeader(fullUrl),
427
674
  Authorization: `Bearer ${apiKey}`
428
- };
675
+ });
429
676
  const response = await pool.request(url, {
430
677
  ...fetchOptions,
431
678
  method: method.toUpperCase(),
432
- body: body ? JSON.stringify(body) : void 0,
679
+ body: parseBody(body, headers),
433
680
  headers,
434
681
  signal
435
682
  });
@@ -442,6 +689,9 @@ async function fetch$1({
442
689
  [TraceAttributes.HTTP_HOST]: host,
443
690
  [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
444
691
  });
692
+ const message = response.headers?.get("x-xata-message");
693
+ if (message)
694
+ console.warn(message);
445
695
  if (response.status === 204) {
446
696
  return {};
447
697
  }
@@ -449,7 +699,7 @@ async function fetch$1({
449
699
  throw new FetcherError(response.status, "Rate limit exceeded", requestId);
450
700
  }
451
701
  try {
452
- const jsonResponse = await response.json();
702
+ const jsonResponse = rawResponse ? await response.blob() : await response.json();
453
703
  if (response.ok) {
454
704
  return jsonResponse;
455
705
  }
@@ -461,6 +711,59 @@ async function fetch$1({
461
711
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
462
712
  );
463
713
  }
714
+ function fetchSSERequest({
715
+ url: path,
716
+ method,
717
+ body,
718
+ headers: customHeaders,
719
+ pathParams,
720
+ queryParams,
721
+ fetch: fetch2,
722
+ apiKey,
723
+ endpoint,
724
+ apiUrl,
725
+ workspacesApiUrl,
726
+ onMessage,
727
+ onError,
728
+ onClose,
729
+ signal,
730
+ clientID,
731
+ sessionID,
732
+ clientName,
733
+ xataAgentExtra
734
+ }) {
735
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
736
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
737
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
738
+ void fetchEventSource(url, {
739
+ method,
740
+ body: JSON.stringify(body),
741
+ fetch: fetch2,
742
+ signal,
743
+ headers: {
744
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
745
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
746
+ "X-Xata-Agent": compact([
747
+ ["client", "TS_SDK"],
748
+ ["version", VERSION],
749
+ isDefined(clientName) ? ["service", clientName] : void 0,
750
+ ...Object.entries(xataAgentExtra ?? {})
751
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
752
+ ...customHeaders,
753
+ Authorization: `Bearer ${apiKey}`,
754
+ "Content-Type": "application/json"
755
+ },
756
+ onmessage(ev) {
757
+ onMessage?.(JSON.parse(ev.data));
758
+ },
759
+ onerror(ev) {
760
+ onError?.(JSON.parse(ev.data));
761
+ },
762
+ onclose() {
763
+ onClose?.();
764
+ }
765
+ });
766
+ }
464
767
  function parseUrl(url) {
465
768
  try {
466
769
  const { host, protocol } = new URL(url);
@@ -491,6 +794,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
491
794
  ...variables,
492
795
  signal
493
796
  });
797
+ const copyBranch = (variables, signal) => dataPlaneFetch({
798
+ url: "/db/{dbBranchName}/copy",
799
+ method: "post",
800
+ ...variables,
801
+ signal
802
+ });
494
803
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
495
804
  url: "/db/{dbBranchName}/metadata",
496
805
  method: "put",
@@ -540,6 +849,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
540
849
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
541
850
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
542
851
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
852
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
543
853
  const createTable = (variables, signal) => dataPlaneFetch({
544
854
  url: "/db/{dbBranchName}/tables/{tableName}",
545
855
  method: "put",
@@ -584,6 +894,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
584
894
  });
585
895
  const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
586
896
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
897
+ const getFileItem = (variables, signal) => dataPlaneFetch({
898
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
899
+ method: "get",
900
+ ...variables,
901
+ signal
902
+ });
903
+ const putFileItem = (variables, signal) => dataPlaneFetch({
904
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
905
+ method: "put",
906
+ ...variables,
907
+ signal
908
+ });
909
+ const deleteFileItem = (variables, signal) => dataPlaneFetch({
910
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
911
+ method: "delete",
912
+ ...variables,
913
+ signal
914
+ });
915
+ const getFile = (variables, signal) => dataPlaneFetch({
916
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
917
+ method: "get",
918
+ ...variables,
919
+ signal
920
+ });
921
+ const putFile = (variables, signal) => dataPlaneFetch({
922
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
923
+ method: "put",
924
+ ...variables,
925
+ signal
926
+ });
927
+ const deleteFile = (variables, signal) => dataPlaneFetch({
928
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
929
+ method: "delete",
930
+ ...variables,
931
+ signal
932
+ });
587
933
  const getRecord = (variables, signal) => dataPlaneFetch({
588
934
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
589
935
  method: "get",
@@ -614,14 +960,34 @@ const searchTable = (variables, signal) => dataPlaneFetch({
614
960
  signal
615
961
  });
616
962
  const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
963
+ const askTable = (variables, signal) => dataPlaneFetch({
964
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
965
+ method: "post",
966
+ ...variables,
967
+ signal
968
+ });
969
+ const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
617
970
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
618
971
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
972
+ const fileAccess = (variables, signal) => dataPlaneFetch({
973
+ url: "/file/{fileId}",
974
+ method: "get",
975
+ ...variables,
976
+ signal
977
+ });
978
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
979
+ url: "/db/{dbBranchName}/sql",
980
+ method: "post",
981
+ ...variables,
982
+ signal
983
+ });
619
984
  const operationsByTag$2 = {
620
985
  branch: {
621
986
  getBranchList,
622
987
  getBranchDetails,
623
988
  createBranch,
624
989
  deleteBranch,
990
+ copyBranch,
625
991
  updateBranchMetadata,
626
992
  getBranchMetadata,
627
993
  getBranchStats,
@@ -639,7 +1005,8 @@ const operationsByTag$2 = {
639
1005
  compareBranchSchemas,
640
1006
  updateBranchSchema,
641
1007
  previewBranchSchemaEdit,
642
- applyBranchSchemaEdit
1008
+ applyBranchSchemaEdit,
1009
+ pushBranchMigrations
643
1010
  },
644
1011
  migrationRequests: {
645
1012
  queryMigrationRequests,
@@ -673,11 +1040,24 @@ const operationsByTag$2 = {
673
1040
  deleteRecord,
674
1041
  bulkInsertTableRecords
675
1042
  },
676
- searchAndFilter: { queryTable, searchBranch, searchTable, vectorSearchTable, summarizeTable, aggregateTable }
1043
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1044
+ searchAndFilter: {
1045
+ queryTable,
1046
+ searchBranch,
1047
+ searchTable,
1048
+ vectorSearchTable,
1049
+ askTable,
1050
+ askTableSession,
1051
+ summarizeTable,
1052
+ aggregateTable
1053
+ },
1054
+ sql: { sqlQuery }
677
1055
  };
678
1056
 
679
1057
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
680
1058
 
1059
+ const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
1060
+ const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
681
1061
  const getUser = (variables, signal) => controlPlaneFetch({
682
1062
  url: "/user",
683
1063
  method: "get",
@@ -714,6 +1094,25 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
714
1094
  ...variables,
715
1095
  signal
716
1096
  });
1097
+ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
1098
+ url: "/user/oauth/clients",
1099
+ method: "get",
1100
+ ...variables,
1101
+ signal
1102
+ });
1103
+ const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
1104
+ url: "/user/oauth/tokens",
1105
+ method: "get",
1106
+ ...variables,
1107
+ signal
1108
+ });
1109
+ const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
1110
+ url: "/user/oauth/tokens/{token}",
1111
+ method: "delete",
1112
+ ...variables,
1113
+ signal
1114
+ });
1115
+ const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
717
1116
  const getWorkspacesList = (variables, signal) => controlPlaneFetch({
718
1117
  url: "/workspaces",
719
1118
  method: "get",
@@ -772,6 +1171,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
772
1171
  });
773
1172
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
774
1173
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1174
+ const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
775
1175
  const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
776
1176
  const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
777
1177
  const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
@@ -782,8 +1182,9 @@ const listRegions = (variables, signal) => controlPlaneFetch({
782
1182
  signal
783
1183
  });
784
1184
  const operationsByTag$1 = {
1185
+ authOther: { getAuthorizationCode, grantAuthorizationCode, deleteOAuthAccessToken, updateOAuthAccessToken },
785
1186
  users: { getUser, updateUser, deleteUser },
786
- authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
1187
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey, getUserOAuthClients, getUserOAuthAccessTokens },
787
1188
  workspaces: {
788
1189
  getWorkspacesList,
789
1190
  createWorkspace,
@@ -807,6 +1208,7 @@ const operationsByTag$1 = {
807
1208
  deleteDatabase,
808
1209
  getDatabaseMetadata,
809
1210
  updateDatabaseMetadata,
1211
+ renameDatabase,
810
1212
  getDatabaseGithubSettings,
811
1213
  updateDatabaseGithubSettings,
812
1214
  deleteDatabaseGithubSettings,
@@ -832,6 +1234,10 @@ const providers = {
832
1234
  staging: {
833
1235
  main: "https://api.staging-xata.dev",
834
1236
  workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1237
+ },
1238
+ dev: {
1239
+ main: "https://api.dev-xata.dev",
1240
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
835
1241
  }
836
1242
  };
837
1243
  function isHostProviderAlias(alias) {
@@ -849,6 +1255,11 @@ function parseProviderString(provider = "production") {
849
1255
  return null;
850
1256
  return { main, workspaces };
851
1257
  }
1258
+ function buildProviderString(provider) {
1259
+ if (isHostProviderAlias(provider))
1260
+ return provider;
1261
+ return `${provider.main},${provider.workspaces}`;
1262
+ }
852
1263
  function parseWorkspacesUrlParts(url) {
853
1264
  if (!isString(url))
854
1265
  return null;
@@ -895,7 +1306,7 @@ class XataApiClient {
895
1306
  __privateSet$7(this, _extraProps, {
896
1307
  apiUrl: getHostUrl(provider, "main"),
897
1308
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
898
- fetchImpl: getFetchImplementation(options.fetch),
1309
+ fetch: getFetchImplementation(options.fetch),
899
1310
  apiKey,
900
1311
  trace,
901
1312
  clientName: options.clientName,
@@ -953,6 +1364,11 @@ class XataApiClient {
953
1364
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
954
1365
  return __privateGet$7(this, _namespaces).records;
955
1366
  }
1367
+ get files() {
1368
+ if (!__privateGet$7(this, _namespaces).files)
1369
+ __privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
1370
+ return __privateGet$7(this, _namespaces).files;
1371
+ }
956
1372
  get searchAndFilter() {
957
1373
  if (!__privateGet$7(this, _namespaces).searchAndFilter)
958
1374
  __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
@@ -1161,6 +1577,20 @@ class BranchApi {
1161
1577
  ...this.extraProps
1162
1578
  });
1163
1579
  }
1580
+ copyBranch({
1581
+ workspace,
1582
+ region,
1583
+ database,
1584
+ branch,
1585
+ destinationBranch,
1586
+ limit
1587
+ }) {
1588
+ return operationsByTag.branch.copyBranch({
1589
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1590
+ body: { destinationBranch, limit },
1591
+ ...this.extraProps
1592
+ });
1593
+ }
1164
1594
  updateBranchMetadata({
1165
1595
  workspace,
1166
1596
  region,
@@ -1516,6 +1946,164 @@ class RecordsApi {
1516
1946
  });
1517
1947
  }
1518
1948
  }
1949
+ class FilesApi {
1950
+ constructor(extraProps) {
1951
+ this.extraProps = extraProps;
1952
+ }
1953
+ getFileItem({
1954
+ workspace,
1955
+ region,
1956
+ database,
1957
+ branch,
1958
+ table,
1959
+ record,
1960
+ column,
1961
+ fileId
1962
+ }) {
1963
+ return operationsByTag.files.getFileItem({
1964
+ pathParams: {
1965
+ workspace,
1966
+ region,
1967
+ dbBranchName: `${database}:${branch}`,
1968
+ tableName: table,
1969
+ recordId: record,
1970
+ columnName: column,
1971
+ fileId
1972
+ },
1973
+ ...this.extraProps
1974
+ });
1975
+ }
1976
+ putFileItem({
1977
+ workspace,
1978
+ region,
1979
+ database,
1980
+ branch,
1981
+ table,
1982
+ record,
1983
+ column,
1984
+ fileId,
1985
+ file
1986
+ }) {
1987
+ return operationsByTag.files.putFileItem({
1988
+ pathParams: {
1989
+ workspace,
1990
+ region,
1991
+ dbBranchName: `${database}:${branch}`,
1992
+ tableName: table,
1993
+ recordId: record,
1994
+ columnName: column,
1995
+ fileId
1996
+ },
1997
+ // @ts-ignore
1998
+ body: file,
1999
+ ...this.extraProps
2000
+ });
2001
+ }
2002
+ deleteFileItem({
2003
+ workspace,
2004
+ region,
2005
+ database,
2006
+ branch,
2007
+ table,
2008
+ record,
2009
+ column,
2010
+ fileId
2011
+ }) {
2012
+ return operationsByTag.files.deleteFileItem({
2013
+ pathParams: {
2014
+ workspace,
2015
+ region,
2016
+ dbBranchName: `${database}:${branch}`,
2017
+ tableName: table,
2018
+ recordId: record,
2019
+ columnName: column,
2020
+ fileId
2021
+ },
2022
+ ...this.extraProps
2023
+ });
2024
+ }
2025
+ getFile({
2026
+ workspace,
2027
+ region,
2028
+ database,
2029
+ branch,
2030
+ table,
2031
+ record,
2032
+ column
2033
+ }) {
2034
+ return operationsByTag.files.getFile({
2035
+ pathParams: {
2036
+ workspace,
2037
+ region,
2038
+ dbBranchName: `${database}:${branch}`,
2039
+ tableName: table,
2040
+ recordId: record,
2041
+ columnName: column
2042
+ },
2043
+ ...this.extraProps
2044
+ });
2045
+ }
2046
+ putFile({
2047
+ workspace,
2048
+ region,
2049
+ database,
2050
+ branch,
2051
+ table,
2052
+ record,
2053
+ column,
2054
+ file
2055
+ }) {
2056
+ return operationsByTag.files.putFile({
2057
+ pathParams: {
2058
+ workspace,
2059
+ region,
2060
+ dbBranchName: `${database}:${branch}`,
2061
+ tableName: table,
2062
+ recordId: record,
2063
+ columnName: column
2064
+ },
2065
+ body: file,
2066
+ ...this.extraProps
2067
+ });
2068
+ }
2069
+ deleteFile({
2070
+ workspace,
2071
+ region,
2072
+ database,
2073
+ branch,
2074
+ table,
2075
+ record,
2076
+ column
2077
+ }) {
2078
+ return operationsByTag.files.deleteFile({
2079
+ pathParams: {
2080
+ workspace,
2081
+ region,
2082
+ dbBranchName: `${database}:${branch}`,
2083
+ tableName: table,
2084
+ recordId: record,
2085
+ columnName: column
2086
+ },
2087
+ ...this.extraProps
2088
+ });
2089
+ }
2090
+ fileAccess({
2091
+ workspace,
2092
+ region,
2093
+ fileId,
2094
+ verify
2095
+ }) {
2096
+ return operationsByTag.files.fileAccess({
2097
+ pathParams: {
2098
+ workspace,
2099
+ region,
2100
+ fileId
2101
+ },
2102
+ queryParams: { verify },
2103
+ ...this.extraProps
2104
+ });
2105
+ }
2106
+ }
1519
2107
  class SearchAndFilterApi {
1520
2108
  constructor(extraProps) {
1521
2109
  this.extraProps = extraProps;
@@ -1575,6 +2163,53 @@ class SearchAndFilterApi {
1575
2163
  ...this.extraProps
1576
2164
  });
1577
2165
  }
2166
+ vectorSearchTable({
2167
+ workspace,
2168
+ region,
2169
+ database,
2170
+ branch,
2171
+ table,
2172
+ queryVector,
2173
+ column,
2174
+ similarityFunction,
2175
+ size,
2176
+ filter
2177
+ }) {
2178
+ return operationsByTag.searchAndFilter.vectorSearchTable({
2179
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2180
+ body: { queryVector, column, similarityFunction, size, filter },
2181
+ ...this.extraProps
2182
+ });
2183
+ }
2184
+ askTable({
2185
+ workspace,
2186
+ region,
2187
+ database,
2188
+ branch,
2189
+ table,
2190
+ options
2191
+ }) {
2192
+ return operationsByTag.searchAndFilter.askTable({
2193
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2194
+ body: { ...options },
2195
+ ...this.extraProps
2196
+ });
2197
+ }
2198
+ askTableSession({
2199
+ workspace,
2200
+ region,
2201
+ database,
2202
+ branch,
2203
+ table,
2204
+ sessionId,
2205
+ message
2206
+ }) {
2207
+ return operationsByTag.searchAndFilter.askTableSession({
2208
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
2209
+ body: { message },
2210
+ ...this.extraProps
2211
+ });
2212
+ }
1578
2213
  summarizeTable({
1579
2214
  workspace,
1580
2215
  region,
@@ -1839,6 +2474,19 @@ class MigrationsApi {
1839
2474
  ...this.extraProps
1840
2475
  });
1841
2476
  }
2477
+ pushBranchMigrations({
2478
+ workspace,
2479
+ region,
2480
+ database,
2481
+ branch,
2482
+ migrations
2483
+ }) {
2484
+ return operationsByTag.migrations.pushBranchMigrations({
2485
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2486
+ body: { migrations },
2487
+ ...this.extraProps
2488
+ });
2489
+ }
1842
2490
  }
1843
2491
  class DatabaseApi {
1844
2492
  constructor(extraProps) {
@@ -1853,11 +2501,13 @@ class DatabaseApi {
1853
2501
  createDatabase({
1854
2502
  workspace,
1855
2503
  database,
1856
- data
2504
+ data,
2505
+ headers
1857
2506
  }) {
1858
2507
  return operationsByTag.databases.createDatabase({
1859
2508
  pathParams: { workspaceId: workspace, dbName: database },
1860
2509
  body: data,
2510
+ headers,
1861
2511
  ...this.extraProps
1862
2512
  });
1863
2513
  }
@@ -1890,6 +2540,17 @@ class DatabaseApi {
1890
2540
  ...this.extraProps
1891
2541
  });
1892
2542
  }
2543
+ renameDatabase({
2544
+ workspace,
2545
+ database,
2546
+ newName
2547
+ }) {
2548
+ return operationsByTag.databases.renameDatabase({
2549
+ pathParams: { workspaceId: workspace, dbName: database },
2550
+ body: { newName },
2551
+ ...this.extraProps
2552
+ });
2553
+ }
1893
2554
  getDatabaseGithubSettings({
1894
2555
  workspace,
1895
2556
  database
@@ -1928,22 +2589,269 @@ class DatabaseApi {
1928
2589
  }
1929
2590
 
1930
2591
  class XataApiPlugin {
1931
- async build(options) {
1932
- const { fetchImpl, apiKey } = await options.getFetchProps();
1933
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2592
+ build(options) {
2593
+ return new XataApiClient(options);
1934
2594
  }
1935
2595
  }
1936
2596
 
1937
2597
  class XataPlugin {
1938
2598
  }
1939
2599
 
2600
+ class FilesPlugin extends XataPlugin {
2601
+ build(pluginOptions) {
2602
+ return {
2603
+ download: async (location) => {
2604
+ const { table, record, column, fileId = "" } = location ?? {};
2605
+ return await getFileItem({
2606
+ pathParams: {
2607
+ workspace: "{workspaceId}",
2608
+ dbBranchName: "{dbBranch}",
2609
+ region: "{region}",
2610
+ tableName: table ?? "",
2611
+ recordId: record ?? "",
2612
+ columnName: column ?? "",
2613
+ fileId
2614
+ },
2615
+ ...pluginOptions,
2616
+ rawResponse: true
2617
+ });
2618
+ },
2619
+ upload: async (location, file) => {
2620
+ const { table, record, column, fileId = "" } = location ?? {};
2621
+ return await putFileItem({
2622
+ pathParams: {
2623
+ workspace: "{workspaceId}",
2624
+ dbBranchName: "{dbBranch}",
2625
+ region: "{region}",
2626
+ tableName: table ?? "",
2627
+ recordId: record ?? "",
2628
+ columnName: column ?? "",
2629
+ fileId
2630
+ },
2631
+ body: file,
2632
+ ...pluginOptions
2633
+ });
2634
+ },
2635
+ delete: async (location) => {
2636
+ const { table, record, column, fileId = "" } = location ?? {};
2637
+ return await deleteFileItem({
2638
+ pathParams: {
2639
+ workspace: "{workspaceId}",
2640
+ dbBranchName: "{dbBranch}",
2641
+ region: "{region}",
2642
+ tableName: table ?? "",
2643
+ recordId: record ?? "",
2644
+ columnName: column ?? "",
2645
+ fileId
2646
+ },
2647
+ ...pluginOptions
2648
+ });
2649
+ }
2650
+ };
2651
+ }
2652
+ }
2653
+
2654
+ function buildTransformString(transformations) {
2655
+ return transformations.flatMap(
2656
+ (t) => Object.entries(t).map(([key, value]) => {
2657
+ if (key === "trim") {
2658
+ const { left = 0, top = 0, right = 0, bottom = 0 } = value;
2659
+ return `${key}=${[top, right, bottom, left].join(";")}`;
2660
+ }
2661
+ if (key === "gravity" && typeof value === "object") {
2662
+ const { x = 0.5, y = 0.5 } = value;
2663
+ return `${key}=${[x, y].join("x")}`;
2664
+ }
2665
+ return `${key}=${value}`;
2666
+ })
2667
+ ).join(",");
2668
+ }
2669
+ function transformImage(url, transformations) {
2670
+ if (!isDefined(url))
2671
+ return void 0;
2672
+ const transformationsString = buildTransformString(transformations);
2673
+ const { hostname, pathname, search } = new URL(url);
2674
+ return `https://${hostname}/transform/${transformationsString}${pathname}${search}`;
2675
+ }
2676
+
2677
+ var __defProp$6 = Object.defineProperty;
2678
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2679
+ var __publicField$6 = (obj, key, value) => {
2680
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
2681
+ return value;
2682
+ };
2683
+ class XataFile {
2684
+ constructor(file) {
2685
+ /**
2686
+ * Name of this file.
2687
+ */
2688
+ __publicField$6(this, "name");
2689
+ /**
2690
+ * Media type of this file.
2691
+ */
2692
+ __publicField$6(this, "mediaType");
2693
+ /**
2694
+ * Base64 encoded content of this file.
2695
+ */
2696
+ __publicField$6(this, "base64Content");
2697
+ /**
2698
+ * Whether to enable public url for this file.
2699
+ */
2700
+ __publicField$6(this, "enablePublicUrl");
2701
+ /**
2702
+ * Timeout for the signed url.
2703
+ */
2704
+ __publicField$6(this, "signedUrlTimeout");
2705
+ /**
2706
+ * Size of this file.
2707
+ */
2708
+ __publicField$6(this, "size");
2709
+ /**
2710
+ * Version of this file.
2711
+ */
2712
+ __publicField$6(this, "version");
2713
+ /**
2714
+ * Url of this file.
2715
+ */
2716
+ __publicField$6(this, "url");
2717
+ /**
2718
+ * Signed url of this file.
2719
+ */
2720
+ __publicField$6(this, "signedUrl");
2721
+ /**
2722
+ * Attributes of this file.
2723
+ */
2724
+ __publicField$6(this, "attributes");
2725
+ this.name = file.name;
2726
+ this.mediaType = file.mediaType || "application/octet-stream";
2727
+ this.base64Content = file.base64Content;
2728
+ this.enablePublicUrl = file.enablePublicUrl;
2729
+ this.signedUrlTimeout = file.signedUrlTimeout;
2730
+ this.size = file.size;
2731
+ this.version = file.version;
2732
+ this.url = file.url;
2733
+ this.signedUrl = file.signedUrl;
2734
+ this.attributes = file.attributes;
2735
+ }
2736
+ static fromBuffer(buffer, options = {}) {
2737
+ const base64Content = buffer.toString("base64");
2738
+ return new XataFile({ ...options, base64Content });
2739
+ }
2740
+ toBuffer() {
2741
+ if (!this.base64Content) {
2742
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2743
+ }
2744
+ return Buffer.from(this.base64Content, "base64");
2745
+ }
2746
+ static fromArrayBuffer(arrayBuffer, options = {}) {
2747
+ const uint8Array = new Uint8Array(arrayBuffer);
2748
+ return this.fromUint8Array(uint8Array, options);
2749
+ }
2750
+ toArrayBuffer() {
2751
+ if (!this.base64Content) {
2752
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2753
+ }
2754
+ const binary = atob(this.base64Content);
2755
+ return new ArrayBuffer(binary.length);
2756
+ }
2757
+ static fromUint8Array(uint8Array, options = {}) {
2758
+ let binary = "";
2759
+ for (let i = 0; i < uint8Array.byteLength; i++) {
2760
+ binary += String.fromCharCode(uint8Array[i]);
2761
+ }
2762
+ const base64Content = btoa(binary);
2763
+ return new XataFile({ ...options, base64Content });
2764
+ }
2765
+ toUint8Array() {
2766
+ if (!this.base64Content) {
2767
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2768
+ }
2769
+ const binary = atob(this.base64Content);
2770
+ const uint8Array = new Uint8Array(binary.length);
2771
+ for (let i = 0; i < binary.length; i++) {
2772
+ uint8Array[i] = binary.charCodeAt(i);
2773
+ }
2774
+ return uint8Array;
2775
+ }
2776
+ static async fromBlob(file, options = {}) {
2777
+ const name = options.name ?? file.name;
2778
+ const mediaType = file.type;
2779
+ const arrayBuffer = await file.arrayBuffer();
2780
+ return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
2781
+ }
2782
+ toBlob() {
2783
+ if (!this.base64Content) {
2784
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2785
+ }
2786
+ const arrayBuffer = this.toArrayBuffer();
2787
+ return new Blob([arrayBuffer], { type: this.mediaType });
2788
+ }
2789
+ static fromString(string, options = {}) {
2790
+ const base64Content = btoa(string);
2791
+ return new XataFile({ ...options, base64Content });
2792
+ }
2793
+ toString() {
2794
+ if (!this.base64Content) {
2795
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2796
+ }
2797
+ return atob(this.base64Content);
2798
+ }
2799
+ static fromBase64(base64Content, options = {}) {
2800
+ return new XataFile({ ...options, base64Content });
2801
+ }
2802
+ toBase64() {
2803
+ if (!this.base64Content) {
2804
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2805
+ }
2806
+ return this.base64Content;
2807
+ }
2808
+ transform(...options) {
2809
+ return {
2810
+ url: transformImage(this.url, options),
2811
+ signedUrl: transformImage(this.signedUrl, options)
2812
+ };
2813
+ }
2814
+ }
2815
+ const parseInputFileEntry = async (entry) => {
2816
+ if (!isDefined(entry))
2817
+ return null;
2818
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
2819
+ return compactObject({ id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout });
2820
+ };
2821
+
1940
2822
  function cleanFilter(filter) {
1941
- if (!filter)
2823
+ if (!isDefined(filter))
1942
2824
  return void 0;
1943
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1944
- return values.length > 0 ? filter : void 0;
2825
+ if (!isObject(filter))
2826
+ return filter;
2827
+ const values = Object.fromEntries(
2828
+ Object.entries(filter).reduce((acc, [key, value]) => {
2829
+ if (!isDefined(value))
2830
+ return acc;
2831
+ if (Array.isArray(value)) {
2832
+ const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
2833
+ if (clean.length === 0)
2834
+ return acc;
2835
+ return [...acc, [key, clean]];
2836
+ }
2837
+ if (isObject(value)) {
2838
+ const clean = cleanFilter(value);
2839
+ if (!isDefined(clean))
2840
+ return acc;
2841
+ return [...acc, [key, clean]];
2842
+ }
2843
+ return [...acc, [key, value]];
2844
+ }, [])
2845
+ );
2846
+ return Object.keys(values).length > 0 ? values : void 0;
1945
2847
  }
1946
2848
 
2849
+ var __defProp$5 = Object.defineProperty;
2850
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2851
+ var __publicField$5 = (obj, key, value) => {
2852
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2853
+ return value;
2854
+ };
1947
2855
  var __accessCheck$6 = (obj, member, msg) => {
1948
2856
  if (!member.has(obj))
1949
2857
  throw TypeError("Cannot " + msg);
@@ -1966,22 +2874,58 @@ var _query, _page;
1966
2874
  class Page {
1967
2875
  constructor(query, meta, records = []) {
1968
2876
  __privateAdd$6(this, _query, void 0);
2877
+ /**
2878
+ * Page metadata, required to retrieve additional records.
2879
+ */
2880
+ __publicField$5(this, "meta");
2881
+ /**
2882
+ * The set of results for this page.
2883
+ */
2884
+ __publicField$5(this, "records");
1969
2885
  __privateSet$6(this, _query, query);
1970
2886
  this.meta = meta;
1971
2887
  this.records = new RecordArray(this, records);
1972
2888
  }
2889
+ /**
2890
+ * Retrieves the next page of results.
2891
+ * @param size Maximum number of results to be retrieved.
2892
+ * @param offset Number of results to skip when retrieving the results.
2893
+ * @returns The next page or results.
2894
+ */
1973
2895
  async nextPage(size, offset) {
1974
2896
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
1975
2897
  }
2898
+ /**
2899
+ * Retrieves the previous page of results.
2900
+ * @param size Maximum number of results to be retrieved.
2901
+ * @param offset Number of results to skip when retrieving the results.
2902
+ * @returns The previous page or results.
2903
+ */
1976
2904
  async previousPage(size, offset) {
1977
2905
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1978
2906
  }
2907
+ /**
2908
+ * Retrieves the start page of results.
2909
+ * @param size Maximum number of results to be retrieved.
2910
+ * @param offset Number of results to skip when retrieving the results.
2911
+ * @returns The start page or results.
2912
+ */
1979
2913
  async startPage(size, offset) {
1980
2914
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1981
2915
  }
2916
+ /**
2917
+ * Retrieves the end page of results.
2918
+ * @param size Maximum number of results to be retrieved.
2919
+ * @param offset Number of results to skip when retrieving the results.
2920
+ * @returns The end page or results.
2921
+ */
1982
2922
  async endPage(size, offset) {
1983
2923
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1984
2924
  }
2925
+ /**
2926
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
2927
+ * @returns Whether or not there will be additional results in the next page of results.
2928
+ */
1985
2929
  hasNextPage() {
1986
2930
  return this.meta.page.more;
1987
2931
  }
@@ -1994,7 +2938,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
1994
2938
  function isCursorPaginationOptions(options) {
1995
2939
  return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1996
2940
  }
1997
- const _RecordArray = class extends Array {
2941
+ const _RecordArray = class _RecordArray extends Array {
1998
2942
  constructor(...args) {
1999
2943
  super(..._RecordArray.parseConstructorParams(...args));
2000
2944
  __privateAdd$6(this, _page, void 0);
@@ -2022,29 +2966,58 @@ const _RecordArray = class extends Array {
2022
2966
  map(callbackfn, thisArg) {
2023
2967
  return this.toArray().map(callbackfn, thisArg);
2024
2968
  }
2969
+ /**
2970
+ * Retrieve next page of records
2971
+ *
2972
+ * @returns A new array of objects
2973
+ */
2025
2974
  async nextPage(size, offset) {
2026
2975
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
2027
2976
  return new _RecordArray(newPage);
2028
2977
  }
2978
+ /**
2979
+ * Retrieve previous page of records
2980
+ *
2981
+ * @returns A new array of objects
2982
+ */
2029
2983
  async previousPage(size, offset) {
2030
2984
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
2031
2985
  return new _RecordArray(newPage);
2032
2986
  }
2987
+ /**
2988
+ * Retrieve start page of records
2989
+ *
2990
+ * @returns A new array of objects
2991
+ */
2033
2992
  async startPage(size, offset) {
2034
2993
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
2035
2994
  return new _RecordArray(newPage);
2036
2995
  }
2996
+ /**
2997
+ * Retrieve end page of records
2998
+ *
2999
+ * @returns A new array of objects
3000
+ */
2037
3001
  async endPage(size, offset) {
2038
3002
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
2039
3003
  return new _RecordArray(newPage);
2040
3004
  }
3005
+ /**
3006
+ * @returns Boolean indicating if there is a next page
3007
+ */
2041
3008
  hasNextPage() {
2042
3009
  return __privateGet$6(this, _page).meta.page.more;
2043
3010
  }
2044
3011
  };
2045
- let RecordArray = _RecordArray;
2046
3012
  _page = new WeakMap();
3013
+ let RecordArray = _RecordArray;
2047
3014
 
3015
+ var __defProp$4 = Object.defineProperty;
3016
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3017
+ var __publicField$4 = (obj, key, value) => {
3018
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3019
+ return value;
3020
+ };
2048
3021
  var __accessCheck$5 = (obj, member, msg) => {
2049
3022
  if (!member.has(obj))
2050
3023
  throw TypeError("Cannot " + msg);
@@ -2068,14 +3041,15 @@ var __privateMethod$3 = (obj, member, method) => {
2068
3041
  return method;
2069
3042
  };
2070
3043
  var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
2071
- const _Query = class {
3044
+ const _Query = class _Query {
2072
3045
  constructor(repository, table, data, rawParent) {
2073
3046
  __privateAdd$5(this, _cleanFilterConstraint);
2074
3047
  __privateAdd$5(this, _table$1, void 0);
2075
3048
  __privateAdd$5(this, _repository, void 0);
2076
3049
  __privateAdd$5(this, _data, { filter: {} });
2077
- this.meta = { page: { cursor: "start", more: true } };
2078
- this.records = new RecordArray(this, []);
3050
+ // Implements pagination
3051
+ __publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
3052
+ __publicField$4(this, "records", new RecordArray(this, []));
2079
3053
  __privateSet$5(this, _table$1, table);
2080
3054
  if (repository) {
2081
3055
  __privateSet$5(this, _repository, repository);
@@ -2111,18 +3085,38 @@ const _Query = class {
2111
3085
  const key = JSON.stringify({ columns, filter, sort, pagination });
2112
3086
  return toBase64(key);
2113
3087
  }
3088
+ /**
3089
+ * Builds a new query object representing a logical OR between the given subqueries.
3090
+ * @param queries An array of subqueries.
3091
+ * @returns A new Query object.
3092
+ */
2114
3093
  any(...queries) {
2115
3094
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2116
3095
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2117
3096
  }
3097
+ /**
3098
+ * Builds a new query object representing a logical AND between the given subqueries.
3099
+ * @param queries An array of subqueries.
3100
+ * @returns A new Query object.
3101
+ */
2118
3102
  all(...queries) {
2119
3103
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2120
3104
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2121
3105
  }
3106
+ /**
3107
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
3108
+ * @param queries An array of subqueries.
3109
+ * @returns A new Query object.
3110
+ */
2122
3111
  not(...queries) {
2123
3112
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2124
3113
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2125
3114
  }
3115
+ /**
3116
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
3117
+ * @param queries An array of subqueries.
3118
+ * @returns A new Query object.
3119
+ */
2126
3120
  none(...queries) {
2127
3121
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2128
3122
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2145,6 +3139,11 @@ const _Query = class {
2145
3139
  const sort = [...originalSort, { column, direction }];
2146
3140
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2147
3141
  }
3142
+ /**
3143
+ * Builds a new query specifying the set of columns to be returned in the query response.
3144
+ * @param columns Array of column names to be returned by the query.
3145
+ * @returns A new Query object.
3146
+ */
2148
3147
  select(columns) {
2149
3148
  return new _Query(
2150
3149
  __privateGet$5(this, _repository),
@@ -2157,6 +3156,12 @@ const _Query = class {
2157
3156
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2158
3157
  return __privateGet$5(this, _repository).query(query);
2159
3158
  }
3159
+ /**
3160
+ * Get results in an iterator
3161
+ *
3162
+ * @async
3163
+ * @returns Async interable of results
3164
+ */
2160
3165
  async *[Symbol.asyncIterator]() {
2161
3166
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2162
3167
  yield record;
@@ -2217,26 +3222,53 @@ const _Query = class {
2217
3222
  );
2218
3223
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2219
3224
  }
3225
+ /**
3226
+ * Builds a new query object adding a cache TTL in milliseconds.
3227
+ * @param ttl The cache TTL in milliseconds.
3228
+ * @returns A new Query object.
3229
+ */
2220
3230
  cache(ttl) {
2221
3231
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2222
3232
  }
3233
+ /**
3234
+ * Retrieve next page of records
3235
+ *
3236
+ * @returns A new page object.
3237
+ */
2223
3238
  nextPage(size, offset) {
2224
3239
  return this.startPage(size, offset);
2225
3240
  }
3241
+ /**
3242
+ * Retrieve previous page of records
3243
+ *
3244
+ * @returns A new page object
3245
+ */
2226
3246
  previousPage(size, offset) {
2227
3247
  return this.startPage(size, offset);
2228
3248
  }
3249
+ /**
3250
+ * Retrieve start page of records
3251
+ *
3252
+ * @returns A new page object
3253
+ */
2229
3254
  startPage(size, offset) {
2230
3255
  return this.getPaginated({ pagination: { size, offset } });
2231
3256
  }
3257
+ /**
3258
+ * Retrieve last page of records
3259
+ *
3260
+ * @returns A new page object
3261
+ */
2232
3262
  endPage(size, offset) {
2233
3263
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2234
3264
  }
3265
+ /**
3266
+ * @returns Boolean indicating if there is a next page
3267
+ */
2235
3268
  hasNextPage() {
2236
3269
  return this.meta.page.more;
2237
3270
  }
2238
3271
  };
2239
- let Query = _Query;
2240
3272
  _table$1 = new WeakMap();
2241
3273
  _repository = new WeakMap();
2242
3274
  _data = new WeakMap();
@@ -2251,6 +3283,7 @@ cleanFilterConstraint_fn = function(column, value) {
2251
3283
  }
2252
3284
  return value;
2253
3285
  };
3286
+ let Query = _Query;
2254
3287
  function cleanParent(data, parent) {
2255
3288
  if (isCursorPaginationOptions(data.pagination)) {
2256
3289
  return { ...parent, sort: void 0, filter: void 0 };
@@ -2258,6 +3291,21 @@ function cleanParent(data, parent) {
2258
3291
  return parent;
2259
3292
  }
2260
3293
 
3294
+ const RecordColumnTypes = [
3295
+ "bool",
3296
+ "int",
3297
+ "float",
3298
+ "string",
3299
+ "text",
3300
+ "email",
3301
+ "multiple",
3302
+ "link",
3303
+ "object",
3304
+ "datetime",
3305
+ "vector",
3306
+ "file[]",
3307
+ "file"
3308
+ ];
2261
3309
  function isIdentifiable(x) {
2262
3310
  return isObject(x) && isString(x?.id);
2263
3311
  }
@@ -2271,7 +3319,11 @@ function isSortFilterString(value) {
2271
3319
  return isString(value);
2272
3320
  }
2273
3321
  function isSortFilterBase(filter) {
2274
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
3322
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
3323
+ if (key === "*")
3324
+ return value === "random";
3325
+ return value === "asc" || value === "desc";
3326
+ });
2275
3327
  }
2276
3328
  function isSortFilterObject(filter) {
2277
3329
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2312,7 +3364,7 @@ var __privateMethod$2 = (obj, member, method) => {
2312
3364
  __accessCheck$4(obj, member, "access private method");
2313
3365
  return method;
2314
3366
  };
2315
- 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;
3367
+ 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;
2316
3368
  const BULK_OPERATION_MAX_SIZE = 1e3;
2317
3369
  class Repository extends Query {
2318
3370
  }
@@ -2334,6 +3386,7 @@ class RestRepository extends Query {
2334
3386
  __privateAdd$4(this, _setCacheQuery);
2335
3387
  __privateAdd$4(this, _getCacheQuery);
2336
3388
  __privateAdd$4(this, _getSchemaTables$1);
3389
+ __privateAdd$4(this, _transformObjectToApi);
2337
3390
  __privateAdd$4(this, _table, void 0);
2338
3391
  __privateAdd$4(this, _getFetchProps, void 0);
2339
3392
  __privateAdd$4(this, _db, void 0);
@@ -2344,10 +3397,7 @@ class RestRepository extends Query {
2344
3397
  __privateSet$4(this, _db, options.db);
2345
3398
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2346
3399
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2347
- __privateSet$4(this, _getFetchProps, async () => {
2348
- const props = await options.pluginOptions.getFetchProps();
2349
- return { ...props, sessionID: generateUUID() };
2350
- });
3400
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2351
3401
  const trace = options.pluginOptions.trace ?? defaultTrace;
2352
3402
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2353
3403
  return trace(name, fn, {
@@ -2404,7 +3454,6 @@ class RestRepository extends Query {
2404
3454
  }
2405
3455
  const id = extractId(a);
2406
3456
  if (id) {
2407
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2408
3457
  try {
2409
3458
  const response = await getRecord({
2410
3459
  pathParams: {
@@ -2415,7 +3464,7 @@ class RestRepository extends Query {
2415
3464
  recordId: id
2416
3465
  },
2417
3466
  queryParams: { columns },
2418
- ...fetchProps
3467
+ ...__privateGet$4(this, _getFetchProps).call(this)
2419
3468
  });
2420
3469
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2421
3470
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2515,12 +3564,22 @@ class RestRepository extends Query {
2515
3564
  return result;
2516
3565
  }
2517
3566
  if (isString(a) && isObject(b)) {
3567
+ if (a === "")
3568
+ throw new Error("The id can't be empty");
2518
3569
  const columns = isStringArray(c) ? c : void 0;
2519
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3570
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2520
3571
  }
2521
3572
  if (isObject(a) && isString(a.id)) {
3573
+ if (a.id === "")
3574
+ throw new Error("The id can't be empty");
2522
3575
  const columns = isStringArray(c) ? c : void 0;
2523
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3576
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3577
+ }
3578
+ if (!isDefined(a) && isObject(b)) {
3579
+ return await this.create(b, c);
3580
+ }
3581
+ if (isObject(a) && !isDefined(a.id)) {
3582
+ return await this.create(a, b);
2524
3583
  }
2525
3584
  throw new Error("Invalid arguments for createOrUpdate method");
2526
3585
  });
@@ -2537,12 +3596,22 @@ class RestRepository extends Query {
2537
3596
  return result;
2538
3597
  }
2539
3598
  if (isString(a) && isObject(b)) {
3599
+ if (a === "")
3600
+ throw new Error("The id can't be empty");
2540
3601
  const columns = isStringArray(c) ? c : void 0;
2541
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
3602
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2542
3603
  }
2543
3604
  if (isObject(a) && isString(a.id)) {
3605
+ if (a.id === "")
3606
+ throw new Error("The id can't be empty");
2544
3607
  const columns = isStringArray(c) ? c : void 0;
2545
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3608
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3609
+ }
3610
+ if (!isDefined(a) && isObject(b)) {
3611
+ return await this.create(b, c);
3612
+ }
3613
+ if (isObject(a) && !isDefined(a.id)) {
3614
+ return await this.create(a, b);
2546
3615
  }
2547
3616
  throw new Error("Invalid arguments for createOrReplace method");
2548
3617
  });
@@ -2593,7 +3662,6 @@ class RestRepository extends Query {
2593
3662
  }
2594
3663
  async search(query, options = {}) {
2595
3664
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2596
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2597
3665
  const { records } = await searchTable({
2598
3666
  pathParams: {
2599
3667
  workspace: "{workspaceId}",
@@ -2611,7 +3679,7 @@ class RestRepository extends Query {
2611
3679
  page: options.page,
2612
3680
  target: options.target
2613
3681
  },
2614
- ...fetchProps
3682
+ ...__privateGet$4(this, _getFetchProps).call(this)
2615
3683
  });
2616
3684
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2617
3685
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2619,7 +3687,6 @@ class RestRepository extends Query {
2619
3687
  }
2620
3688
  async vectorSearch(column, query, options) {
2621
3689
  return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2622
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2623
3690
  const { records } = await vectorSearchTable({
2624
3691
  pathParams: {
2625
3692
  workspace: "{workspaceId}",
@@ -2634,7 +3701,7 @@ class RestRepository extends Query {
2634
3701
  size: options?.size,
2635
3702
  filter: options?.filter
2636
3703
  },
2637
- ...fetchProps
3704
+ ...__privateGet$4(this, _getFetchProps).call(this)
2638
3705
  });
2639
3706
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2640
3707
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2642,7 +3709,6 @@ class RestRepository extends Query {
2642
3709
  }
2643
3710
  async aggregate(aggs, filter) {
2644
3711
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2645
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2646
3712
  const result = await aggregateTable({
2647
3713
  pathParams: {
2648
3714
  workspace: "{workspaceId}",
@@ -2651,7 +3717,7 @@ class RestRepository extends Query {
2651
3717
  tableName: __privateGet$4(this, _table)
2652
3718
  },
2653
3719
  body: { aggs, filter },
2654
- ...fetchProps
3720
+ ...__privateGet$4(this, _getFetchProps).call(this)
2655
3721
  });
2656
3722
  return result;
2657
3723
  });
@@ -2662,7 +3728,6 @@ class RestRepository extends Query {
2662
3728
  if (cacheQuery)
2663
3729
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2664
3730
  const data = query.getQueryOptions();
2665
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2666
3731
  const { meta, records: objects } = await queryTable({
2667
3732
  pathParams: {
2668
3733
  workspace: "{workspaceId}",
@@ -2678,7 +3743,7 @@ class RestRepository extends Query {
2678
3743
  consistency: data.consistency
2679
3744
  },
2680
3745
  fetchOptions: data.fetchOptions,
2681
- ...fetchProps
3746
+ ...__privateGet$4(this, _getFetchProps).call(this)
2682
3747
  });
2683
3748
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2684
3749
  const records = objects.map(
@@ -2691,7 +3756,6 @@ class RestRepository extends Query {
2691
3756
  async summarizeTable(query, summaries, summariesFilter) {
2692
3757
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2693
3758
  const data = query.getQueryOptions();
2694
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2695
3759
  const result = await summarizeTable({
2696
3760
  pathParams: {
2697
3761
  workspace: "{workspaceId}",
@@ -2708,11 +3772,44 @@ class RestRepository extends Query {
2708
3772
  summaries,
2709
3773
  summariesFilter
2710
3774
  },
2711
- ...fetchProps
3775
+ ...__privateGet$4(this, _getFetchProps).call(this)
2712
3776
  });
2713
3777
  return result;
2714
3778
  });
2715
3779
  }
3780
+ ask(question, options) {
3781
+ const questionParam = options?.sessionId ? { message: question } : { question };
3782
+ const params = {
3783
+ pathParams: {
3784
+ workspace: "{workspaceId}",
3785
+ dbBranchName: "{dbBranch}",
3786
+ region: "{region}",
3787
+ tableName: __privateGet$4(this, _table),
3788
+ sessionId: options?.sessionId
3789
+ },
3790
+ body: {
3791
+ ...questionParam,
3792
+ rules: options?.rules,
3793
+ searchType: options?.searchType,
3794
+ search: options?.searchType === "keyword" ? options?.search : void 0,
3795
+ vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
3796
+ },
3797
+ ...__privateGet$4(this, _getFetchProps).call(this)
3798
+ };
3799
+ if (options?.onMessage) {
3800
+ fetchSSERequest({
3801
+ endpoint: "dataPlane",
3802
+ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
3803
+ method: "POST",
3804
+ onMessage: (message) => {
3805
+ options.onMessage?.({ answer: message.text, records: message.records });
3806
+ },
3807
+ ...params
3808
+ });
3809
+ } else {
3810
+ return askTableSession(params);
3811
+ }
3812
+ }
2716
3813
  }
2717
3814
  _table = new WeakMap();
2718
3815
  _getFetchProps = new WeakMap();
@@ -2722,8 +3819,7 @@ _schemaTables$2 = new WeakMap();
2722
3819
  _trace = new WeakMap();
2723
3820
  _insertRecordWithoutId = new WeakSet();
2724
3821
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2725
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2726
- const record = transformObjectLinks(object);
3822
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2727
3823
  const response = await insertRecord({
2728
3824
  pathParams: {
2729
3825
  workspace: "{workspaceId}",
@@ -2733,15 +3829,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2733
3829
  },
2734
3830
  queryParams: { columns },
2735
3831
  body: record,
2736
- ...fetchProps
3832
+ ...__privateGet$4(this, _getFetchProps).call(this)
2737
3833
  });
2738
3834
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2739
3835
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2740
3836
  };
2741
3837
  _insertRecordWithId = new WeakSet();
2742
3838
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2743
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2744
- const record = transformObjectLinks(object);
3839
+ if (!recordId)
3840
+ return null;
3841
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2745
3842
  const response = await insertRecordWithID({
2746
3843
  pathParams: {
2747
3844
  workspace: "{workspaceId}",
@@ -2752,30 +3849,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2752
3849
  },
2753
3850
  body: record,
2754
3851
  queryParams: { createOnly, columns, ifVersion },
2755
- ...fetchProps
3852
+ ...__privateGet$4(this, _getFetchProps).call(this)
2756
3853
  });
2757
3854
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2758
3855
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2759
3856
  };
2760
3857
  _insertRecords = new WeakSet();
2761
3858
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2762
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2763
- const chunkedOperations = chunk(
2764
- objects.map((object) => ({
2765
- insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2766
- })),
2767
- BULK_OPERATION_MAX_SIZE
2768
- );
3859
+ const operations = await promiseMap(objects, async (object) => {
3860
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3861
+ return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
3862
+ });
3863
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2769
3864
  const ids = [];
2770
- for (const operations of chunkedOperations) {
3865
+ for (const operations2 of chunkedOperations) {
2771
3866
  const { results } = await branchTransaction({
2772
3867
  pathParams: {
2773
3868
  workspace: "{workspaceId}",
2774
3869
  dbBranchName: "{dbBranch}",
2775
3870
  region: "{region}"
2776
3871
  },
2777
- body: { operations },
2778
- ...fetchProps
3872
+ body: { operations: operations2 },
3873
+ ...__privateGet$4(this, _getFetchProps).call(this)
2779
3874
  });
2780
3875
  for (const result of results) {
2781
3876
  if (result.operation === "insert") {
@@ -2789,8 +3884,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2789
3884
  };
2790
3885
  _updateRecordWithID = new WeakSet();
2791
3886
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2792
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2793
- const { id: _id, ...record } = transformObjectLinks(object);
3887
+ if (!recordId)
3888
+ return null;
3889
+ const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2794
3890
  try {
2795
3891
  const response = await updateRecordWithID({
2796
3892
  pathParams: {
@@ -2802,7 +3898,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2802
3898
  },
2803
3899
  queryParams: { columns, ifVersion },
2804
3900
  body: record,
2805
- ...fetchProps
3901
+ ...__privateGet$4(this, _getFetchProps).call(this)
2806
3902
  });
2807
3903
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2808
3904
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2815,23 +3911,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2815
3911
  };
2816
3912
  _updateRecords = new WeakSet();
2817
3913
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2818
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2819
- const chunkedOperations = chunk(
2820
- objects.map(({ id, ...object }) => ({
2821
- update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2822
- })),
2823
- BULK_OPERATION_MAX_SIZE
2824
- );
3914
+ const operations = await promiseMap(objects, async ({ id, ...object }) => {
3915
+ const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
3916
+ return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
3917
+ });
3918
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2825
3919
  const ids = [];
2826
- for (const operations of chunkedOperations) {
3920
+ for (const operations2 of chunkedOperations) {
2827
3921
  const { results } = await branchTransaction({
2828
3922
  pathParams: {
2829
3923
  workspace: "{workspaceId}",
2830
3924
  dbBranchName: "{dbBranch}",
2831
3925
  region: "{region}"
2832
3926
  },
2833
- body: { operations },
2834
- ...fetchProps
3927
+ body: { operations: operations2 },
3928
+ ...__privateGet$4(this, _getFetchProps).call(this)
2835
3929
  });
2836
3930
  for (const result of results) {
2837
3931
  if (result.operation === "update") {
@@ -2845,7 +3939,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2845
3939
  };
2846
3940
  _upsertRecordWithID = new WeakSet();
2847
3941
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2848
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
3942
+ if (!recordId)
3943
+ return null;
2849
3944
  const response = await upsertRecordWithID({
2850
3945
  pathParams: {
2851
3946
  workspace: "{workspaceId}",
@@ -2856,14 +3951,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2856
3951
  },
2857
3952
  queryParams: { columns, ifVersion },
2858
3953
  body: object,
2859
- ...fetchProps
3954
+ ...__privateGet$4(this, _getFetchProps).call(this)
2860
3955
  });
2861
3956
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2862
3957
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2863
3958
  };
2864
3959
  _deleteRecord = new WeakSet();
2865
3960
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2866
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
3961
+ if (!recordId)
3962
+ return null;
2867
3963
  try {
2868
3964
  const response = await deleteRecord({
2869
3965
  pathParams: {
@@ -2874,7 +3970,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2874
3970
  recordId
2875
3971
  },
2876
3972
  queryParams: { columns },
2877
- ...fetchProps
3973
+ ...__privateGet$4(this, _getFetchProps).call(this)
2878
3974
  });
2879
3975
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2880
3976
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2887,9 +3983,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2887
3983
  };
2888
3984
  _deleteRecords = new WeakSet();
2889
3985
  deleteRecords_fn = async function(recordIds) {
2890
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2891
3986
  const chunkedOperations = chunk(
2892
- recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
3987
+ compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2893
3988
  BULK_OPERATION_MAX_SIZE
2894
3989
  );
2895
3990
  for (const operations of chunkedOperations) {
@@ -2900,21 +3995,22 @@ deleteRecords_fn = async function(recordIds) {
2900
3995
  region: "{region}"
2901
3996
  },
2902
3997
  body: { operations },
2903
- ...fetchProps
3998
+ ...__privateGet$4(this, _getFetchProps).call(this)
2904
3999
  });
2905
4000
  }
2906
4001
  };
2907
4002
  _setCacheQuery = new WeakSet();
2908
4003
  setCacheQuery_fn = async function(query, meta, records) {
2909
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
4004
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
2910
4005
  };
2911
4006
  _getCacheQuery = new WeakSet();
2912
4007
  getCacheQuery_fn = async function(query) {
2913
4008
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2914
- const result = await __privateGet$4(this, _cache).get(key);
4009
+ const result = await __privateGet$4(this, _cache)?.get(key);
2915
4010
  if (!result)
2916
4011
  return null;
2917
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
4012
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
4013
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2918
4014
  if (ttl < 0)
2919
4015
  return null;
2920
4016
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2924,15 +4020,46 @@ _getSchemaTables$1 = new WeakSet();
2924
4020
  getSchemaTables_fn$1 = async function() {
2925
4021
  if (__privateGet$4(this, _schemaTables$2))
2926
4022
  return __privateGet$4(this, _schemaTables$2);
2927
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2928
4023
  const { schema } = await getBranchDetails({
2929
4024
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2930
- ...fetchProps
4025
+ ...__privateGet$4(this, _getFetchProps).call(this)
2931
4026
  });
2932
4027
  __privateSet$4(this, _schemaTables$2, schema.tables);
2933
4028
  return schema.tables;
2934
4029
  };
2935
- const transformObjectLinks = (object) => {
4030
+ _transformObjectToApi = new WeakSet();
4031
+ transformObjectToApi_fn = async function(object) {
4032
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
4033
+ const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
4034
+ if (!schema)
4035
+ throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
4036
+ const result = {};
4037
+ for (const [key, value] of Object.entries(object)) {
4038
+ if (key === "xata")
4039
+ continue;
4040
+ const type = schema.columns.find((column) => column.name === key)?.type;
4041
+ switch (type) {
4042
+ case "link": {
4043
+ result[key] = isIdentifiable(value) ? value.id : value;
4044
+ break;
4045
+ }
4046
+ case "datetime": {
4047
+ result[key] = value instanceof Date ? value.toISOString() : value;
4048
+ break;
4049
+ }
4050
+ case `file`:
4051
+ result[key] = await parseInputFileEntry(value);
4052
+ break;
4053
+ case "file[]":
4054
+ result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
4055
+ break;
4056
+ default:
4057
+ result[key] = value;
4058
+ }
4059
+ }
4060
+ return result;
4061
+ };
4062
+ const removeLinksFromObject = (object) => {
2936
4063
  return Object.entries(object).reduce((acc, [key, value]) => {
2937
4064
  if (key === "xata")
2938
4065
  return acc;
@@ -2981,6 +4108,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2981
4108
  }
2982
4109
  break;
2983
4110
  }
4111
+ case "file":
4112
+ data[column.name] = isDefined(value) ? new XataFile(value) : null;
4113
+ break;
4114
+ case "file[]":
4115
+ data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
4116
+ break;
2984
4117
  default:
2985
4118
  data[column.name] = value ?? null;
2986
4119
  if (column.notNull === true && value === null) {
@@ -2990,6 +4123,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2990
4123
  }
2991
4124
  }
2992
4125
  const record = { ...data };
4126
+ const serializable = { xata, ...removeLinksFromObject(data) };
4127
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2993
4128
  record.read = function(columns2) {
2994
4129
  return db[table].read(record["id"], columns2);
2995
4130
  };
@@ -3006,14 +4141,15 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3006
4141
  record.delete = function() {
3007
4142
  return db[table].delete(record["id"]);
3008
4143
  };
4144
+ record.xata = Object.freeze(metadata);
3009
4145
  record.getMetadata = function() {
3010
- return xata;
4146
+ return record.xata;
3011
4147
  };
3012
4148
  record.toSerializable = function() {
3013
- return JSON.parse(JSON.stringify(transformObjectLinks(data)));
4149
+ return JSON.parse(JSON.stringify(serializable));
3014
4150
  };
3015
4151
  record.toString = function() {
3016
- return JSON.stringify(transformObjectLinks(data));
4152
+ return JSON.stringify(serializable);
3017
4153
  };
3018
4154
  for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3019
4155
  Object.defineProperty(record, prop, { enumerable: false });
@@ -3031,11 +4167,7 @@ function extractId(value) {
3031
4167
  function isValidColumn(columns, column) {
3032
4168
  if (columns.includes("*"))
3033
4169
  return true;
3034
- if (column.type === "link") {
3035
- const linkColumns = columns.filter((item) => item.startsWith(column.name));
3036
- return linkColumns.length > 0;
3037
- }
3038
- return columns.includes(column.name);
4170
+ return columns.filter((item) => item.startsWith(column.name)).length > 0;
3039
4171
  }
3040
4172
  function parseIfVersion(...args) {
3041
4173
  for (const arg of args) {
@@ -3046,6 +4178,12 @@ function parseIfVersion(...args) {
3046
4178
  return void 0;
3047
4179
  }
3048
4180
 
4181
+ var __defProp$3 = Object.defineProperty;
4182
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4183
+ var __publicField$3 = (obj, key, value) => {
4184
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
4185
+ return value;
4186
+ };
3049
4187
  var __accessCheck$3 = (obj, member, msg) => {
3050
4188
  if (!member.has(obj))
3051
4189
  throw TypeError("Cannot " + msg);
@@ -3068,6 +4206,8 @@ var _map;
3068
4206
  class SimpleCache {
3069
4207
  constructor(options = {}) {
3070
4208
  __privateAdd$3(this, _map, void 0);
4209
+ __publicField$3(this, "capacity");
4210
+ __publicField$3(this, "defaultQueryTTL");
3071
4211
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
3072
4212
  this.capacity = options.max ?? 500;
3073
4213
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
@@ -3203,19 +4343,19 @@ class SearchPlugin extends XataPlugin {
3203
4343
  __privateAdd$1(this, _schemaTables, void 0);
3204
4344
  __privateSet$1(this, _schemaTables, schemaTables);
3205
4345
  }
3206
- build({ getFetchProps }) {
4346
+ build(pluginOptions) {
3207
4347
  return {
3208
4348
  all: async (query, options = {}) => {
3209
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3210
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
4349
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4350
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3211
4351
  return records.map((record) => {
3212
4352
  const { table = "orphan" } = record.xata;
3213
4353
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3214
4354
  });
3215
4355
  },
3216
4356
  byTable: async (query, options = {}) => {
3217
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3218
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
4357
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4358
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3219
4359
  return records.reduce((acc, record) => {
3220
4360
  const { table = "orphan" } = record.xata;
3221
4361
  const items = acc[table] ?? [];
@@ -3228,38 +4368,108 @@ class SearchPlugin extends XataPlugin {
3228
4368
  }
3229
4369
  _schemaTables = new WeakMap();
3230
4370
  _search = new WeakSet();
3231
- search_fn = async function(query, options, getFetchProps) {
3232
- const fetchProps = await getFetchProps();
4371
+ search_fn = async function(query, options, pluginOptions) {
3233
4372
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3234
4373
  const { records } = await searchBranch({
3235
4374
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4375
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3236
4376
  body: { tables, query, fuzziness, prefix, highlight, page },
3237
- ...fetchProps
4377
+ ...pluginOptions
3238
4378
  });
3239
4379
  return records;
3240
4380
  };
3241
4381
  _getSchemaTables = new WeakSet();
3242
- getSchemaTables_fn = async function(getFetchProps) {
4382
+ getSchemaTables_fn = async function(pluginOptions) {
3243
4383
  if (__privateGet$1(this, _schemaTables))
3244
4384
  return __privateGet$1(this, _schemaTables);
3245
- const fetchProps = await getFetchProps();
3246
4385
  const { schema } = await getBranchDetails({
3247
4386
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3248
- ...fetchProps
4387
+ ...pluginOptions
3249
4388
  });
3250
4389
  __privateSet$1(this, _schemaTables, schema.tables);
3251
4390
  return schema.tables;
3252
4391
  };
3253
4392
 
4393
+ function escapeElement(elementRepresentation) {
4394
+ const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
4395
+ return '"' + escaped + '"';
4396
+ }
4397
+ function arrayString(val) {
4398
+ let result = "{";
4399
+ for (let i = 0; i < val.length; i++) {
4400
+ if (i > 0) {
4401
+ result = result + ",";
4402
+ }
4403
+ if (val[i] === null || typeof val[i] === "undefined") {
4404
+ result = result + "NULL";
4405
+ } else if (Array.isArray(val[i])) {
4406
+ result = result + arrayString(val[i]);
4407
+ } else if (val[i] instanceof Buffer) {
4408
+ result += "\\\\x" + val[i].toString("hex");
4409
+ } else {
4410
+ result += escapeElement(prepareValue(val[i]));
4411
+ }
4412
+ }
4413
+ result = result + "}";
4414
+ return result;
4415
+ }
4416
+ function prepareValue(value) {
4417
+ if (!isDefined(value))
4418
+ return null;
4419
+ if (value instanceof Date) {
4420
+ return value.toISOString();
4421
+ }
4422
+ if (Array.isArray(value)) {
4423
+ return arrayString(value);
4424
+ }
4425
+ if (isObject(value)) {
4426
+ return JSON.stringify(value);
4427
+ }
4428
+ try {
4429
+ return value.toString();
4430
+ } catch (e) {
4431
+ return value;
4432
+ }
4433
+ }
4434
+ function prepareParams(param1, param2) {
4435
+ if (isString(param1)) {
4436
+ return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
4437
+ }
4438
+ if (isStringArray(param1)) {
4439
+ const statement = param1.reduce((acc, curr, index) => {
4440
+ return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
4441
+ }, "");
4442
+ return { statement, params: param2?.map((value) => prepareValue(value)) };
4443
+ }
4444
+ if (isObject(param1)) {
4445
+ const { statement, params, consistency } = param1;
4446
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency };
4447
+ }
4448
+ throw new Error("Invalid query");
4449
+ }
4450
+
4451
+ class SQLPlugin extends XataPlugin {
4452
+ build(pluginOptions) {
4453
+ return async (param1, ...param2) => {
4454
+ const { statement, params, consistency } = prepareParams(param1, param2);
4455
+ const { records, warning } = await sqlQuery({
4456
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4457
+ body: { statement, params, consistency },
4458
+ ...pluginOptions
4459
+ });
4460
+ return { records, warning };
4461
+ };
4462
+ }
4463
+ }
4464
+
3254
4465
  class TransactionPlugin extends XataPlugin {
3255
- build({ getFetchProps }) {
4466
+ build(pluginOptions) {
3256
4467
  return {
3257
4468
  run: async (operations) => {
3258
- const fetchProps = await getFetchProps();
3259
4469
  const response = await branchTransaction({
3260
4470
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3261
4471
  body: { operations },
3262
- ...fetchProps
4472
+ ...pluginOptions
3263
4473
  });
3264
4474
  return response;
3265
4475
  }
@@ -3267,91 +4477,12 @@ class TransactionPlugin extends XataPlugin {
3267
4477
  }
3268
4478
  }
3269
4479
 
3270
- const isBranchStrategyBuilder = (strategy) => {
3271
- return typeof strategy === "function";
4480
+ var __defProp$2 = Object.defineProperty;
4481
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4482
+ var __publicField$2 = (obj, key, value) => {
4483
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
4484
+ return value;
3272
4485
  };
3273
-
3274
- async function getCurrentBranchName(options) {
3275
- const { branch, envBranch } = getEnvironment();
3276
- if (branch)
3277
- return branch;
3278
- const gitBranch = envBranch || await getGitBranch();
3279
- return resolveXataBranch(gitBranch, options);
3280
- }
3281
- async function getCurrentBranchDetails(options) {
3282
- const branch = await getCurrentBranchName(options);
3283
- return getDatabaseBranch(branch, options);
3284
- }
3285
- async function resolveXataBranch(gitBranch, options) {
3286
- const databaseURL = options?.databaseURL || getDatabaseURL();
3287
- const apiKey = options?.apiKey || getAPIKey();
3288
- if (!databaseURL)
3289
- throw new Error(
3290
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3291
- );
3292
- if (!apiKey)
3293
- throw new Error(
3294
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3295
- );
3296
- const [protocol, , host, , dbName] = databaseURL.split("/");
3297
- const urlParts = parseWorkspacesUrlParts(host);
3298
- if (!urlParts)
3299
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3300
- const { workspace, region } = urlParts;
3301
- const { fallbackBranch } = getEnvironment();
3302
- const { branch } = await resolveBranch({
3303
- apiKey,
3304
- apiUrl: databaseURL,
3305
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3306
- workspacesApiUrl: `${protocol}//${host}`,
3307
- pathParams: { dbName, workspace, region },
3308
- queryParams: { gitBranch, fallbackBranch },
3309
- trace: defaultTrace,
3310
- clientName: options?.clientName,
3311
- xataAgentExtra: options?.xataAgentExtra
3312
- });
3313
- return branch;
3314
- }
3315
- async function getDatabaseBranch(branch, options) {
3316
- const databaseURL = options?.databaseURL || getDatabaseURL();
3317
- const apiKey = options?.apiKey || getAPIKey();
3318
- if (!databaseURL)
3319
- throw new Error(
3320
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3321
- );
3322
- if (!apiKey)
3323
- throw new Error(
3324
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3325
- );
3326
- const [protocol, , host, , database] = databaseURL.split("/");
3327
- const urlParts = parseWorkspacesUrlParts(host);
3328
- if (!urlParts)
3329
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3330
- const { workspace, region } = urlParts;
3331
- try {
3332
- return await getBranchDetails({
3333
- apiKey,
3334
- apiUrl: databaseURL,
3335
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3336
- workspacesApiUrl: `${protocol}//${host}`,
3337
- pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3338
- trace: defaultTrace
3339
- });
3340
- } catch (err) {
3341
- if (isObject(err) && err.status === 404)
3342
- return null;
3343
- throw err;
3344
- }
3345
- }
3346
- function getDatabaseURL() {
3347
- try {
3348
- const { databaseURL } = getEnvironment();
3349
- return databaseURL;
3350
- } catch (err) {
3351
- return void 0;
3352
- }
3353
- }
3354
-
3355
4486
  var __accessCheck = (obj, member, msg) => {
3356
4487
  if (!member.has(obj))
3357
4488
  throw TypeError("Cannot " + msg);
@@ -3375,46 +4506,46 @@ var __privateMethod = (obj, member, method) => {
3375
4506
  return method;
3376
4507
  };
3377
4508
  const buildClient = (plugins) => {
3378
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
4509
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3379
4510
  return _a = class {
3380
4511
  constructor(options = {}, schemaTables) {
3381
4512
  __privateAdd(this, _parseOptions);
3382
4513
  __privateAdd(this, _getFetchProps);
3383
- __privateAdd(this, _evaluateBranch);
3384
- __privateAdd(this, _branch, void 0);
3385
4514
  __privateAdd(this, _options, void 0);
4515
+ __publicField$2(this, "db");
4516
+ __publicField$2(this, "search");
4517
+ __publicField$2(this, "transactions");
4518
+ __publicField$2(this, "sql");
4519
+ __publicField$2(this, "files");
3386
4520
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3387
4521
  __privateSet(this, _options, safeOptions);
3388
4522
  const pluginOptions = {
3389
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
4523
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3390
4524
  cache: safeOptions.cache,
3391
- trace: safeOptions.trace
4525
+ host: safeOptions.host
3392
4526
  };
3393
4527
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3394
4528
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3395
4529
  const transactions = new TransactionPlugin().build(pluginOptions);
4530
+ const sql = new SQLPlugin().build(pluginOptions);
4531
+ const files = new FilesPlugin().build(pluginOptions);
3396
4532
  this.db = db;
3397
4533
  this.search = search;
3398
4534
  this.transactions = transactions;
4535
+ this.sql = sql;
4536
+ this.files = files;
3399
4537
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3400
4538
  if (namespace === void 0)
3401
4539
  continue;
3402
- const result = namespace.build(pluginOptions);
3403
- if (result instanceof Promise) {
3404
- void result.then((namespace2) => {
3405
- this[key] = namespace2;
3406
- });
3407
- } else {
3408
- this[key] = result;
3409
- }
4540
+ this[key] = namespace.build(pluginOptions);
3410
4541
  }
3411
4542
  }
3412
4543
  async getConfig() {
3413
4544
  const databaseURL = __privateGet(this, _options).databaseURL;
3414
- const branch = await __privateGet(this, _options).branch();
4545
+ const branch = __privateGet(this, _options).branch;
3415
4546
  return { databaseURL, branch };
3416
4547
  }
3417
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
4548
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3418
4549
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3419
4550
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3420
4551
  if (isBrowser && !enableBrowser) {
@@ -3428,20 +4559,34 @@ const buildClient = (plugins) => {
3428
4559
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3429
4560
  const trace = options?.trace ?? defaultTrace;
3430
4561
  const clientName = options?.clientName;
4562
+ const host = options?.host ?? "production";
3431
4563
  const xataAgentExtra = options?.xataAgentExtra;
3432
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3433
- apiKey,
3434
- databaseURL,
3435
- fetchImpl: options?.fetch,
3436
- clientName,
3437
- xataAgentExtra
3438
- });
3439
4564
  if (!apiKey) {
3440
4565
  throw new Error("Option apiKey is required");
3441
4566
  }
3442
4567
  if (!databaseURL) {
3443
4568
  throw new Error("Option databaseURL is required");
3444
4569
  }
4570
+ const envBranch = getBranch();
4571
+ const previewBranch = getPreviewBranch();
4572
+ const branch = options?.branch || previewBranch || envBranch || "main";
4573
+ if (!!previewBranch && branch !== previewBranch) {
4574
+ console.warn(
4575
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
4576
+ );
4577
+ } else if (!!envBranch && branch !== envBranch) {
4578
+ console.warn(
4579
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4580
+ );
4581
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
4582
+ console.warn(
4583
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4584
+ );
4585
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
4586
+ console.warn(
4587
+ `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.`
4588
+ );
4589
+ }
3445
4590
  return {
3446
4591
  fetch,
3447
4592
  databaseURL,
@@ -3449,12 +4594,13 @@ const buildClient = (plugins) => {
3449
4594
  branch,
3450
4595
  cache,
3451
4596
  trace,
4597
+ host,
3452
4598
  clientID: generateUUID(),
3453
4599
  enableBrowser,
3454
4600
  clientName,
3455
4601
  xataAgentExtra
3456
4602
  };
3457
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
4603
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3458
4604
  fetch,
3459
4605
  apiKey,
3460
4606
  databaseURL,
@@ -3464,16 +4610,14 @@ const buildClient = (plugins) => {
3464
4610
  clientName,
3465
4611
  xataAgentExtra
3466
4612
  }) {
3467
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3468
- if (!branchValue)
3469
- throw new Error("Unable to resolve branch value");
3470
4613
  return {
3471
- fetchImpl: fetch,
4614
+ fetch,
3472
4615
  apiKey,
3473
4616
  apiUrl: "",
4617
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3474
4618
  workspacesApiUrl: (path, params) => {
3475
4619
  const hasBranch = params.dbBranchName ?? params.branch;
3476
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
4620
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3477
4621
  return databaseURL + newPath;
3478
4622
  },
3479
4623
  trace,
@@ -3481,32 +4625,22 @@ const buildClient = (plugins) => {
3481
4625
  clientName,
3482
4626
  xataAgentExtra
3483
4627
  };
3484
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3485
- if (__privateGet(this, _branch))
3486
- return __privateGet(this, _branch);
3487
- if (param === void 0)
3488
- return void 0;
3489
- const strategies = Array.isArray(param) ? [...param] : [param];
3490
- const evaluateBranch = async (strategy) => {
3491
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3492
- };
3493
- for await (const strategy of strategies) {
3494
- const branch = await evaluateBranch(strategy);
3495
- if (branch) {
3496
- __privateSet(this, _branch, branch);
3497
- return branch;
3498
- }
3499
- }
3500
4628
  }, _a;
3501
4629
  };
3502
4630
  class BaseClient extends buildClient() {
3503
4631
  }
3504
4632
 
4633
+ var __defProp$1 = Object.defineProperty;
4634
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4635
+ var __publicField$1 = (obj, key, value) => {
4636
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
4637
+ return value;
4638
+ };
3505
4639
  const META = "__";
3506
4640
  const VALUE = "___";
3507
4641
  class Serializer {
3508
4642
  constructor() {
3509
- this.classes = {};
4643
+ __publicField$1(this, "classes", {});
3510
4644
  }
3511
4645
  add(clazz) {
3512
4646
  this.classes[clazz.name] = clazz;
@@ -3584,15 +4718,23 @@ function buildWorkerRunner(config) {
3584
4718
  };
3585
4719
  }
3586
4720
 
4721
+ var __defProp = Object.defineProperty;
4722
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4723
+ var __publicField = (obj, key, value) => {
4724
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4725
+ return value;
4726
+ };
3587
4727
  class XataError extends Error {
3588
4728
  constructor(message, status) {
3589
4729
  super(message);
4730
+ __publicField(this, "status");
3590
4731
  this.status = status;
3591
4732
  }
3592
4733
  }
3593
4734
 
3594
4735
  exports.BaseClient = BaseClient;
3595
4736
  exports.FetcherError = FetcherError;
4737
+ exports.FilesPlugin = FilesPlugin;
3596
4738
  exports.Operations = operationsByTag;
3597
4739
  exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
3598
4740
  exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
@@ -3601,8 +4743,10 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
3601
4743
  exports.Page = Page;
3602
4744
  exports.Query = Query;
3603
4745
  exports.RecordArray = RecordArray;
4746
+ exports.RecordColumnTypes = RecordColumnTypes;
3604
4747
  exports.Repository = Repository;
3605
4748
  exports.RestRepository = RestRepository;
4749
+ exports.SQLPlugin = SQLPlugin;
3606
4750
  exports.SchemaPlugin = SchemaPlugin;
3607
4751
  exports.SearchPlugin = SearchPlugin;
3608
4752
  exports.Serializer = Serializer;
@@ -3610,14 +4754,19 @@ exports.SimpleCache = SimpleCache;
3610
4754
  exports.XataApiClient = XataApiClient;
3611
4755
  exports.XataApiPlugin = XataApiPlugin;
3612
4756
  exports.XataError = XataError;
4757
+ exports.XataFile = XataFile;
3613
4758
  exports.XataPlugin = XataPlugin;
3614
4759
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
3615
4760
  exports.addGitBranchesEntry = addGitBranchesEntry;
3616
4761
  exports.addTableColumn = addTableColumn;
3617
4762
  exports.aggregateTable = aggregateTable;
3618
4763
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
4764
+ exports.askTable = askTable;
4765
+ exports.askTableSession = askTableSession;
3619
4766
  exports.branchTransaction = branchTransaction;
3620
4767
  exports.buildClient = buildClient;
4768
+ exports.buildPreviewBranchName = buildPreviewBranchName;
4769
+ exports.buildProviderString = buildProviderString;
3621
4770
  exports.buildWorkerRunner = buildWorkerRunner;
3622
4771
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
3623
4772
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
@@ -3625,6 +4774,7 @@ exports.compareBranchSchemas = compareBranchSchemas;
3625
4774
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3626
4775
  exports.compareMigrationRequest = compareMigrationRequest;
3627
4776
  exports.contains = contains;
4777
+ exports.copyBranch = copyBranch;
3628
4778
  exports.createBranch = createBranch;
3629
4779
  exports.createDatabase = createDatabase;
3630
4780
  exports.createMigrationRequest = createMigrationRequest;
@@ -3635,6 +4785,9 @@ exports.deleteBranch = deleteBranch;
3635
4785
  exports.deleteColumn = deleteColumn;
3636
4786
  exports.deleteDatabase = deleteDatabase;
3637
4787
  exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
4788
+ exports.deleteFile = deleteFile;
4789
+ exports.deleteFileItem = deleteFileItem;
4790
+ exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
3638
4791
  exports.deleteRecord = deleteRecord;
3639
4792
  exports.deleteTable = deleteTable;
3640
4793
  exports.deleteUser = deleteUser;
@@ -3645,8 +4798,11 @@ exports.endsWith = endsWith;
3645
4798
  exports.equals = equals;
3646
4799
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
3647
4800
  exports.exists = exists;
4801
+ exports.fileAccess = fileAccess;
3648
4802
  exports.ge = ge;
3649
4803
  exports.getAPIKey = getAPIKey;
4804
+ exports.getAuthorizationCode = getAuthorizationCode;
4805
+ exports.getBranch = getBranch;
3650
4806
  exports.getBranchDetails = getBranchDetails;
3651
4807
  exports.getBranchList = getBranchList;
3652
4808
  exports.getBranchMetadata = getBranchMetadata;
@@ -3655,24 +4811,28 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
3655
4811
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
3656
4812
  exports.getBranchStats = getBranchStats;
3657
4813
  exports.getColumn = getColumn;
3658
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
3659
- exports.getCurrentBranchName = getCurrentBranchName;
3660
4814
  exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3661
4815
  exports.getDatabaseList = getDatabaseList;
3662
4816
  exports.getDatabaseMetadata = getDatabaseMetadata;
3663
4817
  exports.getDatabaseURL = getDatabaseURL;
4818
+ exports.getFile = getFile;
4819
+ exports.getFileItem = getFileItem;
3664
4820
  exports.getGitBranchesMapping = getGitBranchesMapping;
3665
4821
  exports.getHostUrl = getHostUrl;
3666
4822
  exports.getMigrationRequest = getMigrationRequest;
3667
4823
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
4824
+ exports.getPreviewBranch = getPreviewBranch;
3668
4825
  exports.getRecord = getRecord;
3669
4826
  exports.getTableColumns = getTableColumns;
3670
4827
  exports.getTableSchema = getTableSchema;
3671
4828
  exports.getUser = getUser;
3672
4829
  exports.getUserAPIKeys = getUserAPIKeys;
4830
+ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
4831
+ exports.getUserOAuthClients = getUserOAuthClients;
3673
4832
  exports.getWorkspace = getWorkspace;
3674
4833
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
3675
4834
  exports.getWorkspacesList = getWorkspacesList;
4835
+ exports.grantAuthorizationCode = grantAuthorizationCode;
3676
4836
  exports.greaterEquals = greaterEquals;
3677
4837
  exports.greaterThan = greaterThan;
3678
4838
  exports.greaterThanEquals = greaterThanEquals;
@@ -3707,24 +4867,31 @@ exports.parseProviderString = parseProviderString;
3707
4867
  exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
3708
4868
  exports.pattern = pattern;
3709
4869
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
4870
+ exports.pushBranchMigrations = pushBranchMigrations;
4871
+ exports.putFile = putFile;
4872
+ exports.putFileItem = putFileItem;
3710
4873
  exports.queryMigrationRequests = queryMigrationRequests;
3711
4874
  exports.queryTable = queryTable;
3712
4875
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
3713
4876
  exports.removeWorkspaceMember = removeWorkspaceMember;
4877
+ exports.renameDatabase = renameDatabase;
3714
4878
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
3715
4879
  exports.resolveBranch = resolveBranch;
3716
4880
  exports.searchBranch = searchBranch;
3717
4881
  exports.searchTable = searchTable;
3718
4882
  exports.serialize = serialize;
3719
4883
  exports.setTableSchema = setTableSchema;
4884
+ exports.sqlQuery = sqlQuery;
3720
4885
  exports.startsWith = startsWith;
3721
4886
  exports.summarizeTable = summarizeTable;
4887
+ exports.transformImage = transformImage;
3722
4888
  exports.updateBranchMetadata = updateBranchMetadata;
3723
4889
  exports.updateBranchSchema = updateBranchSchema;
3724
4890
  exports.updateColumn = updateColumn;
3725
4891
  exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
3726
4892
  exports.updateDatabaseMetadata = updateDatabaseMetadata;
3727
4893
  exports.updateMigrationRequest = updateMigrationRequest;
4894
+ exports.updateOAuthAccessToken = updateOAuthAccessToken;
3728
4895
  exports.updateRecordWithID = updateRecordWithID;
3729
4896
  exports.updateTable = updateTable;
3730
4897
  exports.updateUser = updateUser;