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

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;
@@ -93,8 +96,10 @@ function getEnvironment() {
93
96
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
94
97
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
95
98
  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()
99
+ deployPreview: process.env.XATA_PREVIEW,
100
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
101
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
102
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
98
103
  };
99
104
  }
100
105
  } catch (err) {
@@ -105,8 +110,10 @@ function getEnvironment() {
105
110
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
106
111
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
107
112
  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()
113
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
114
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
115
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
116
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
110
117
  };
111
118
  }
112
119
  } catch (err) {
@@ -115,8 +122,10 @@ function getEnvironment() {
115
122
  apiKey: getGlobalApiKey(),
116
123
  databaseURL: getGlobalDatabaseURL(),
117
124
  branch: getGlobalBranch(),
118
- envBranch: void 0,
119
- fallbackBranch: getGlobalFallbackBranch()
125
+ deployPreview: void 0,
126
+ deployPreviewBranch: void 0,
127
+ vercelGitCommitRef: void 0,
128
+ vercelGitRepoOwner: void 0
120
129
  };
121
130
  }
122
131
  function getEnableBrowserVariable() {
@@ -159,42 +168,59 @@ function getGlobalBranch() {
159
168
  return void 0;
160
169
  }
161
170
  }
162
- function getGlobalFallbackBranch() {
171
+ function getDatabaseURL() {
163
172
  try {
164
- return XATA_FALLBACK_BRANCH;
173
+ const { databaseURL } = getEnvironment();
174
+ return databaseURL;
165
175
  } catch (err) {
166
176
  return void 0;
167
177
  }
168
178
  }
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"] };
179
+ function getAPIKey() {
174
180
  try {
175
- if (typeof require === "function") {
176
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
177
- }
181
+ const { apiKey } = getEnvironment();
182
+ return apiKey;
178
183
  } catch (err) {
184
+ return void 0;
179
185
  }
186
+ }
187
+ function getBranch() {
180
188
  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
- }
189
+ const { branch } = getEnvironment();
190
+ return branch ?? "main";
185
191
  } catch (err) {
192
+ return void 0;
186
193
  }
187
194
  }
188
-
189
- function getAPIKey() {
195
+ function buildPreviewBranchName({ org, branch }) {
196
+ return `preview-${org}-${branch}`;
197
+ }
198
+ function getPreviewBranch() {
190
199
  try {
191
- const { apiKey } = getEnvironment();
192
- return apiKey;
200
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
201
+ if (deployPreviewBranch)
202
+ return deployPreviewBranch;
203
+ switch (deployPreview) {
204
+ case "vercel": {
205
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
206
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
207
+ return void 0;
208
+ }
209
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
210
+ }
211
+ }
212
+ return void 0;
193
213
  } catch (err) {
194
214
  return void 0;
195
215
  }
196
216
  }
197
217
 
218
+ var __defProp$7 = Object.defineProperty;
219
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
220
+ var __publicField$7 = (obj, key, value) => {
221
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
222
+ return value;
223
+ };
198
224
  var __accessCheck$8 = (obj, member, msg) => {
199
225
  if (!member.has(obj))
200
226
  throw TypeError("Cannot " + msg);
@@ -218,6 +244,7 @@ var __privateMethod$4 = (obj, member, method) => {
218
244
  return method;
219
245
  };
220
246
  var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
247
+ const REQUEST_TIMEOUT = 3e4;
221
248
  function getFetchImplementation(userFetch) {
222
249
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
223
250
  const fetchImpl = userFetch ?? globalFetch;
@@ -234,6 +261,8 @@ class ApiRequestPool {
234
261
  __privateAdd$8(this, _fetch, void 0);
235
262
  __privateAdd$8(this, _queue, void 0);
236
263
  __privateAdd$8(this, _concurrency, void 0);
264
+ __publicField$7(this, "running");
265
+ __publicField$7(this, "started");
237
266
  __privateSet$8(this, _queue, []);
238
267
  __privateSet$8(this, _concurrency, concurrency);
239
268
  this.running = 0;
@@ -249,17 +278,20 @@ class ApiRequestPool {
249
278
  return __privateGet$8(this, _fetch);
250
279
  }
251
280
  request(url, options) {
252
- const start = new Date();
281
+ const start = /* @__PURE__ */ new Date();
253
282
  const fetch2 = this.getFetch();
254
283
  const runRequest = async (stalled = false) => {
255
- const response = await fetch2(url, options);
284
+ const response = await Promise.race([fetch2(url, options), timeout(REQUEST_TIMEOUT).then(() => null)]);
285
+ if (!response) {
286
+ throw new Error("Request timed out");
287
+ }
256
288
  if (response.status === 429) {
257
289
  const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
258
290
  await timeout(rateLimitReset * 1e3);
259
291
  return await runRequest(true);
260
292
  }
261
293
  if (stalled) {
262
- const stalledTime = new Date().getTime() - start.getTime();
294
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
263
295
  console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
264
296
  }
265
297
  return response;
@@ -302,16 +334,199 @@ function generateUUID() {
302
334
  });
303
335
  }
304
336
 
305
- const VERSION = "0.22.1";
337
+ async function getBytes(stream, onChunk) {
338
+ const reader = stream.getReader();
339
+ let result;
340
+ while (!(result = await reader.read()).done) {
341
+ onChunk(result.value);
342
+ }
343
+ }
344
+ function getLines(onLine) {
345
+ let buffer;
346
+ let position;
347
+ let fieldLength;
348
+ let discardTrailingNewline = false;
349
+ return function onChunk(arr) {
350
+ if (buffer === void 0) {
351
+ buffer = arr;
352
+ position = 0;
353
+ fieldLength = -1;
354
+ } else {
355
+ buffer = concat(buffer, arr);
356
+ }
357
+ const bufLength = buffer.length;
358
+ let lineStart = 0;
359
+ while (position < bufLength) {
360
+ if (discardTrailingNewline) {
361
+ if (buffer[position] === 10 /* NewLine */) {
362
+ lineStart = ++position;
363
+ }
364
+ discardTrailingNewline = false;
365
+ }
366
+ let lineEnd = -1;
367
+ for (; position < bufLength && lineEnd === -1; ++position) {
368
+ switch (buffer[position]) {
369
+ case 58 /* Colon */:
370
+ if (fieldLength === -1) {
371
+ fieldLength = position - lineStart;
372
+ }
373
+ break;
374
+ case 13 /* CarriageReturn */:
375
+ discardTrailingNewline = true;
376
+ case 10 /* NewLine */:
377
+ lineEnd = position;
378
+ break;
379
+ }
380
+ }
381
+ if (lineEnd === -1) {
382
+ break;
383
+ }
384
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
385
+ lineStart = position;
386
+ fieldLength = -1;
387
+ }
388
+ if (lineStart === bufLength) {
389
+ buffer = void 0;
390
+ } else if (lineStart !== 0) {
391
+ buffer = buffer.subarray(lineStart);
392
+ position -= lineStart;
393
+ }
394
+ };
395
+ }
396
+ function getMessages(onId, onRetry, onMessage) {
397
+ let message = newMessage();
398
+ const decoder = new TextDecoder();
399
+ return function onLine(line, fieldLength) {
400
+ if (line.length === 0) {
401
+ onMessage?.(message);
402
+ message = newMessage();
403
+ } else if (fieldLength > 0) {
404
+ const field = decoder.decode(line.subarray(0, fieldLength));
405
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
406
+ const value = decoder.decode(line.subarray(valueOffset));
407
+ switch (field) {
408
+ case "data":
409
+ message.data = message.data ? message.data + "\n" + value : value;
410
+ break;
411
+ case "event":
412
+ message.event = value;
413
+ break;
414
+ case "id":
415
+ onId(message.id = value);
416
+ break;
417
+ case "retry":
418
+ const retry = parseInt(value, 10);
419
+ if (!isNaN(retry)) {
420
+ onRetry(message.retry = retry);
421
+ }
422
+ break;
423
+ }
424
+ }
425
+ };
426
+ }
427
+ function concat(a, b) {
428
+ const res = new Uint8Array(a.length + b.length);
429
+ res.set(a);
430
+ res.set(b, a.length);
431
+ return res;
432
+ }
433
+ function newMessage() {
434
+ return {
435
+ data: "",
436
+ event: "",
437
+ id: "",
438
+ retry: void 0
439
+ };
440
+ }
441
+ const EventStreamContentType = "text/event-stream";
442
+ const LastEventId = "last-event-id";
443
+ function fetchEventSource(input, {
444
+ signal: inputSignal,
445
+ headers: inputHeaders,
446
+ onopen: inputOnOpen,
447
+ onmessage,
448
+ onclose,
449
+ onerror,
450
+ fetch: inputFetch,
451
+ ...rest
452
+ }) {
453
+ return new Promise((resolve, reject) => {
454
+ const headers = { ...inputHeaders };
455
+ if (!headers.accept) {
456
+ headers.accept = EventStreamContentType;
457
+ }
458
+ let curRequestController;
459
+ function dispose() {
460
+ curRequestController.abort();
461
+ }
462
+ inputSignal?.addEventListener("abort", () => {
463
+ dispose();
464
+ resolve();
465
+ });
466
+ const fetchImpl = inputFetch ?? fetch;
467
+ const onopen = inputOnOpen ?? defaultOnOpen;
468
+ async function create() {
469
+ curRequestController = new AbortController();
470
+ try {
471
+ const response = await fetchImpl(input, {
472
+ ...rest,
473
+ headers,
474
+ signal: curRequestController.signal
475
+ });
476
+ await onopen(response);
477
+ await getBytes(
478
+ response.body,
479
+ getLines(
480
+ getMessages(
481
+ (id) => {
482
+ if (id) {
483
+ headers[LastEventId] = id;
484
+ } else {
485
+ delete headers[LastEventId];
486
+ }
487
+ },
488
+ (_retry) => {
489
+ },
490
+ onmessage
491
+ )
492
+ )
493
+ );
494
+ onclose?.();
495
+ dispose();
496
+ resolve();
497
+ } catch (err) {
498
+ }
499
+ }
500
+ create();
501
+ });
502
+ }
503
+ function defaultOnOpen(response) {
504
+ const contentType = response.headers?.get("content-type");
505
+ if (!contentType?.startsWith(EventStreamContentType)) {
506
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
507
+ }
508
+ }
509
+
510
+ const VERSION = "0.24.3";
306
511
 
512
+ var __defProp$6 = Object.defineProperty;
513
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
514
+ var __publicField$6 = (obj, key, value) => {
515
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
516
+ return value;
517
+ };
307
518
  class ErrorWithCause extends Error {
308
519
  constructor(message, options) {
309
520
  super(message, options);
521
+ __publicField$6(this, "cause");
310
522
  }
311
523
  }
312
524
  class FetcherError extends ErrorWithCause {
313
525
  constructor(status, data, requestId) {
314
526
  super(getMessage(data));
527
+ __publicField$6(this, "status");
528
+ __publicField$6(this, "requestId");
529
+ __publicField$6(this, "errors");
315
530
  this.status = status;
316
531
  this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
317
532
  this.requestId = requestId;
@@ -378,6 +593,15 @@ function hostHeader(url) {
378
593
  const { groups } = pattern.exec(url) ?? {};
379
594
  return groups?.host ? { Host: groups.host } : {};
380
595
  }
596
+ function parseBody(body, headers) {
597
+ if (!isDefined(body))
598
+ return void 0;
599
+ const { "Content-Type": contentType } = headers ?? {};
600
+ if (String(contentType).toLowerCase() === "application/json") {
601
+ return JSON.stringify(body);
602
+ }
603
+ return body;
604
+ }
381
605
  const defaultClientID = generateUUID();
382
606
  async function fetch$1({
383
607
  url: path,
@@ -386,7 +610,7 @@ async function fetch$1({
386
610
  headers: customHeaders,
387
611
  pathParams,
388
612
  queryParams,
389
- fetchImpl,
613
+ fetch: fetch2,
390
614
  apiKey,
391
615
  endpoint,
392
616
  apiUrl,
@@ -397,9 +621,10 @@ async function fetch$1({
397
621
  sessionID,
398
622
  clientName,
399
623
  xataAgentExtra,
400
- fetchOptions = {}
624
+ fetchOptions = {},
625
+ rawResponse = false
401
626
  }) {
402
- pool.setFetch(fetchImpl);
627
+ pool.setFetch(fetch2);
403
628
  return await trace(
404
629
  `${method.toUpperCase()} ${path}`,
405
630
  async ({ setAttributes }) => {
@@ -416,7 +641,7 @@ async function fetch$1({
416
641
  isDefined(clientName) ? ["service", clientName] : void 0,
417
642
  ...Object.entries(xataAgentExtra ?? {})
418
643
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
419
- const headers = {
644
+ const headers = compactObject({
420
645
  "Accept-Encoding": "identity",
421
646
  "Content-Type": "application/json",
422
647
  "X-Xata-Client-ID": clientID ?? defaultClientID,
@@ -425,11 +650,11 @@ async function fetch$1({
425
650
  ...customHeaders,
426
651
  ...hostHeader(fullUrl),
427
652
  Authorization: `Bearer ${apiKey}`
428
- };
653
+ });
429
654
  const response = await pool.request(url, {
430
655
  ...fetchOptions,
431
656
  method: method.toUpperCase(),
432
- body: body ? JSON.stringify(body) : void 0,
657
+ body: parseBody(body, headers),
433
658
  headers,
434
659
  signal
435
660
  });
@@ -442,6 +667,9 @@ async function fetch$1({
442
667
  [TraceAttributes.HTTP_HOST]: host,
443
668
  [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
444
669
  });
670
+ const message = response.headers?.get("x-xata-message");
671
+ if (message)
672
+ console.warn(message);
445
673
  if (response.status === 204) {
446
674
  return {};
447
675
  }
@@ -449,7 +677,7 @@ async function fetch$1({
449
677
  throw new FetcherError(response.status, "Rate limit exceeded", requestId);
450
678
  }
451
679
  try {
452
- const jsonResponse = await response.json();
680
+ const jsonResponse = rawResponse ? await response.blob() : await response.json();
453
681
  if (response.ok) {
454
682
  return jsonResponse;
455
683
  }
@@ -461,6 +689,59 @@ async function fetch$1({
461
689
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
462
690
  );
463
691
  }
692
+ function fetchSSERequest({
693
+ url: path,
694
+ method,
695
+ body,
696
+ headers: customHeaders,
697
+ pathParams,
698
+ queryParams,
699
+ fetch: fetch2,
700
+ apiKey,
701
+ endpoint,
702
+ apiUrl,
703
+ workspacesApiUrl,
704
+ onMessage,
705
+ onError,
706
+ onClose,
707
+ signal,
708
+ clientID,
709
+ sessionID,
710
+ clientName,
711
+ xataAgentExtra
712
+ }) {
713
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
714
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
715
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
716
+ void fetchEventSource(url, {
717
+ method,
718
+ body: JSON.stringify(body),
719
+ fetch: fetch2,
720
+ signal,
721
+ headers: {
722
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
723
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
724
+ "X-Xata-Agent": compact([
725
+ ["client", "TS_SDK"],
726
+ ["version", VERSION],
727
+ isDefined(clientName) ? ["service", clientName] : void 0,
728
+ ...Object.entries(xataAgentExtra ?? {})
729
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
730
+ ...customHeaders,
731
+ Authorization: `Bearer ${apiKey}`,
732
+ "Content-Type": "application/json"
733
+ },
734
+ onmessage(ev) {
735
+ onMessage?.(JSON.parse(ev.data));
736
+ },
737
+ onerror(ev) {
738
+ onError?.(JSON.parse(ev.data));
739
+ },
740
+ onclose() {
741
+ onClose?.();
742
+ }
743
+ });
744
+ }
464
745
  function parseUrl(url) {
465
746
  try {
466
747
  const { host, protocol } = new URL(url);
@@ -491,6 +772,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
491
772
  ...variables,
492
773
  signal
493
774
  });
775
+ const copyBranch = (variables, signal) => dataPlaneFetch({
776
+ url: "/db/{dbBranchName}/copy",
777
+ method: "post",
778
+ ...variables,
779
+ signal
780
+ });
494
781
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
495
782
  url: "/db/{dbBranchName}/metadata",
496
783
  method: "put",
@@ -540,6 +827,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
540
827
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
541
828
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
542
829
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
830
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
543
831
  const createTable = (variables, signal) => dataPlaneFetch({
544
832
  url: "/db/{dbBranchName}/tables/{tableName}",
545
833
  method: "put",
@@ -584,6 +872,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
584
872
  });
585
873
  const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
586
874
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
875
+ const getFileItem = (variables, signal) => dataPlaneFetch({
876
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
877
+ method: "get",
878
+ ...variables,
879
+ signal
880
+ });
881
+ const putFileItem = (variables, signal) => dataPlaneFetch({
882
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
883
+ method: "put",
884
+ ...variables,
885
+ signal
886
+ });
887
+ const deleteFileItem = (variables, signal) => dataPlaneFetch({
888
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
889
+ method: "delete",
890
+ ...variables,
891
+ signal
892
+ });
893
+ const getFile = (variables, signal) => dataPlaneFetch({
894
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
895
+ method: "get",
896
+ ...variables,
897
+ signal
898
+ });
899
+ const putFile = (variables, signal) => dataPlaneFetch({
900
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
901
+ method: "put",
902
+ ...variables,
903
+ signal
904
+ });
905
+ const deleteFile = (variables, signal) => dataPlaneFetch({
906
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
907
+ method: "delete",
908
+ ...variables,
909
+ signal
910
+ });
587
911
  const getRecord = (variables, signal) => dataPlaneFetch({
588
912
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
589
913
  method: "get",
@@ -613,15 +937,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
613
937
  ...variables,
614
938
  signal
615
939
  });
940
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
941
+ url: "/db/{dbBranchName}/sql",
942
+ method: "post",
943
+ ...variables,
944
+ signal
945
+ });
616
946
  const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
947
+ const askTable = (variables, signal) => dataPlaneFetch({
948
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
949
+ method: "post",
950
+ ...variables,
951
+ signal
952
+ });
953
+ const chatSessionMessage = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
617
954
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
618
955
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
956
+ const fileAccess = (variables, signal) => dataPlaneFetch({
957
+ url: "/file/{fileId}",
958
+ method: "get",
959
+ ...variables,
960
+ signal
961
+ });
619
962
  const operationsByTag$2 = {
620
963
  branch: {
621
964
  getBranchList,
622
965
  getBranchDetails,
623
966
  createBranch,
624
967
  deleteBranch,
968
+ copyBranch,
625
969
  updateBranchMetadata,
626
970
  getBranchMetadata,
627
971
  getBranchStats,
@@ -639,7 +983,8 @@ const operationsByTag$2 = {
639
983
  compareBranchSchemas,
640
984
  updateBranchSchema,
641
985
  previewBranchSchemaEdit,
642
- applyBranchSchemaEdit
986
+ applyBranchSchemaEdit,
987
+ pushBranchMigrations
643
988
  },
644
989
  migrationRequests: {
645
990
  queryMigrationRequests,
@@ -673,7 +1018,18 @@ const operationsByTag$2 = {
673
1018
  deleteRecord,
674
1019
  bulkInsertTableRecords
675
1020
  },
676
- searchAndFilter: { queryTable, searchBranch, searchTable, vectorSearchTable, summarizeTable, aggregateTable }
1021
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1022
+ searchAndFilter: {
1023
+ queryTable,
1024
+ searchBranch,
1025
+ searchTable,
1026
+ sqlQuery,
1027
+ vectorSearchTable,
1028
+ askTable,
1029
+ chatSessionMessage,
1030
+ summarizeTable,
1031
+ aggregateTable
1032
+ }
677
1033
  };
678
1034
 
679
1035
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
@@ -772,6 +1128,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
772
1128
  });
773
1129
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
774
1130
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1131
+ const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
775
1132
  const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
776
1133
  const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
777
1134
  const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
@@ -807,6 +1164,7 @@ const operationsByTag$1 = {
807
1164
  deleteDatabase,
808
1165
  getDatabaseMetadata,
809
1166
  updateDatabaseMetadata,
1167
+ renameDatabase,
810
1168
  getDatabaseGithubSettings,
811
1169
  updateDatabaseGithubSettings,
812
1170
  deleteDatabaseGithubSettings,
@@ -832,6 +1190,10 @@ const providers = {
832
1190
  staging: {
833
1191
  main: "https://api.staging-xata.dev",
834
1192
  workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1193
+ },
1194
+ dev: {
1195
+ main: "https://api.dev-xata.dev",
1196
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
835
1197
  }
836
1198
  };
837
1199
  function isHostProviderAlias(alias) {
@@ -849,6 +1211,11 @@ function parseProviderString(provider = "production") {
849
1211
  return null;
850
1212
  return { main, workspaces };
851
1213
  }
1214
+ function buildProviderString(provider) {
1215
+ if (isHostProviderAlias(provider))
1216
+ return provider;
1217
+ return `${provider.main},${provider.workspaces}`;
1218
+ }
852
1219
  function parseWorkspacesUrlParts(url) {
853
1220
  if (!isString(url))
854
1221
  return null;
@@ -895,7 +1262,7 @@ class XataApiClient {
895
1262
  __privateSet$7(this, _extraProps, {
896
1263
  apiUrl: getHostUrl(provider, "main"),
897
1264
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
898
- fetchImpl: getFetchImplementation(options.fetch),
1265
+ fetch: getFetchImplementation(options.fetch),
899
1266
  apiKey,
900
1267
  trace,
901
1268
  clientName: options.clientName,
@@ -953,6 +1320,11 @@ class XataApiClient {
953
1320
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
954
1321
  return __privateGet$7(this, _namespaces).records;
955
1322
  }
1323
+ get files() {
1324
+ if (!__privateGet$7(this, _namespaces).files)
1325
+ __privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
1326
+ return __privateGet$7(this, _namespaces).files;
1327
+ }
956
1328
  get searchAndFilter() {
957
1329
  if (!__privateGet$7(this, _namespaces).searchAndFilter)
958
1330
  __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
@@ -1161,6 +1533,20 @@ class BranchApi {
1161
1533
  ...this.extraProps
1162
1534
  });
1163
1535
  }
1536
+ copyBranch({
1537
+ workspace,
1538
+ region,
1539
+ database,
1540
+ branch,
1541
+ destinationBranch,
1542
+ limit
1543
+ }) {
1544
+ return operationsByTag.branch.copyBranch({
1545
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1546
+ body: { destinationBranch, limit },
1547
+ ...this.extraProps
1548
+ });
1549
+ }
1164
1550
  updateBranchMetadata({
1165
1551
  workspace,
1166
1552
  region,
@@ -1516,6 +1902,164 @@ class RecordsApi {
1516
1902
  });
1517
1903
  }
1518
1904
  }
1905
+ class FilesApi {
1906
+ constructor(extraProps) {
1907
+ this.extraProps = extraProps;
1908
+ }
1909
+ getFileItem({
1910
+ workspace,
1911
+ region,
1912
+ database,
1913
+ branch,
1914
+ table,
1915
+ record,
1916
+ column,
1917
+ fileId
1918
+ }) {
1919
+ return operationsByTag.files.getFileItem({
1920
+ pathParams: {
1921
+ workspace,
1922
+ region,
1923
+ dbBranchName: `${database}:${branch}`,
1924
+ tableName: table,
1925
+ recordId: record,
1926
+ columnName: column,
1927
+ fileId
1928
+ },
1929
+ ...this.extraProps
1930
+ });
1931
+ }
1932
+ putFileItem({
1933
+ workspace,
1934
+ region,
1935
+ database,
1936
+ branch,
1937
+ table,
1938
+ record,
1939
+ column,
1940
+ fileId,
1941
+ file
1942
+ }) {
1943
+ return operationsByTag.files.putFileItem({
1944
+ pathParams: {
1945
+ workspace,
1946
+ region,
1947
+ dbBranchName: `${database}:${branch}`,
1948
+ tableName: table,
1949
+ recordId: record,
1950
+ columnName: column,
1951
+ fileId
1952
+ },
1953
+ // @ts-ignore
1954
+ body: file,
1955
+ ...this.extraProps
1956
+ });
1957
+ }
1958
+ deleteFileItem({
1959
+ workspace,
1960
+ region,
1961
+ database,
1962
+ branch,
1963
+ table,
1964
+ record,
1965
+ column,
1966
+ fileId
1967
+ }) {
1968
+ return operationsByTag.files.deleteFileItem({
1969
+ pathParams: {
1970
+ workspace,
1971
+ region,
1972
+ dbBranchName: `${database}:${branch}`,
1973
+ tableName: table,
1974
+ recordId: record,
1975
+ columnName: column,
1976
+ fileId
1977
+ },
1978
+ ...this.extraProps
1979
+ });
1980
+ }
1981
+ getFile({
1982
+ workspace,
1983
+ region,
1984
+ database,
1985
+ branch,
1986
+ table,
1987
+ record,
1988
+ column
1989
+ }) {
1990
+ return operationsByTag.files.getFile({
1991
+ pathParams: {
1992
+ workspace,
1993
+ region,
1994
+ dbBranchName: `${database}:${branch}`,
1995
+ tableName: table,
1996
+ recordId: record,
1997
+ columnName: column
1998
+ },
1999
+ ...this.extraProps
2000
+ });
2001
+ }
2002
+ putFile({
2003
+ workspace,
2004
+ region,
2005
+ database,
2006
+ branch,
2007
+ table,
2008
+ record,
2009
+ column,
2010
+ file
2011
+ }) {
2012
+ return operationsByTag.files.putFile({
2013
+ pathParams: {
2014
+ workspace,
2015
+ region,
2016
+ dbBranchName: `${database}:${branch}`,
2017
+ tableName: table,
2018
+ recordId: record,
2019
+ columnName: column
2020
+ },
2021
+ body: file,
2022
+ ...this.extraProps
2023
+ });
2024
+ }
2025
+ deleteFile({
2026
+ workspace,
2027
+ region,
2028
+ database,
2029
+ branch,
2030
+ table,
2031
+ record,
2032
+ column
2033
+ }) {
2034
+ return operationsByTag.files.deleteFile({
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
+ fileAccess({
2047
+ workspace,
2048
+ region,
2049
+ fileId,
2050
+ verify
2051
+ }) {
2052
+ return operationsByTag.files.fileAccess({
2053
+ pathParams: {
2054
+ workspace,
2055
+ region,
2056
+ fileId
2057
+ },
2058
+ queryParams: { verify },
2059
+ ...this.extraProps
2060
+ });
2061
+ }
2062
+ }
1519
2063
  class SearchAndFilterApi {
1520
2064
  constructor(extraProps) {
1521
2065
  this.extraProps = extraProps;
@@ -1575,6 +2119,53 @@ class SearchAndFilterApi {
1575
2119
  ...this.extraProps
1576
2120
  });
1577
2121
  }
2122
+ vectorSearchTable({
2123
+ workspace,
2124
+ region,
2125
+ database,
2126
+ branch,
2127
+ table,
2128
+ queryVector,
2129
+ column,
2130
+ similarityFunction,
2131
+ size,
2132
+ filter
2133
+ }) {
2134
+ return operationsByTag.searchAndFilter.vectorSearchTable({
2135
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2136
+ body: { queryVector, column, similarityFunction, size, filter },
2137
+ ...this.extraProps
2138
+ });
2139
+ }
2140
+ askTable({
2141
+ workspace,
2142
+ region,
2143
+ database,
2144
+ branch,
2145
+ table,
2146
+ options
2147
+ }) {
2148
+ return operationsByTag.searchAndFilter.askTable({
2149
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2150
+ body: { ...options },
2151
+ ...this.extraProps
2152
+ });
2153
+ }
2154
+ chatSessionMessage({
2155
+ workspace,
2156
+ region,
2157
+ database,
2158
+ branch,
2159
+ table,
2160
+ sessionId,
2161
+ message
2162
+ }) {
2163
+ return operationsByTag.searchAndFilter.chatSessionMessage({
2164
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
2165
+ body: { message },
2166
+ ...this.extraProps
2167
+ });
2168
+ }
1578
2169
  summarizeTable({
1579
2170
  workspace,
1580
2171
  region,
@@ -1839,6 +2430,19 @@ class MigrationsApi {
1839
2430
  ...this.extraProps
1840
2431
  });
1841
2432
  }
2433
+ pushBranchMigrations({
2434
+ workspace,
2435
+ region,
2436
+ database,
2437
+ branch,
2438
+ migrations
2439
+ }) {
2440
+ return operationsByTag.migrations.pushBranchMigrations({
2441
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2442
+ body: { migrations },
2443
+ ...this.extraProps
2444
+ });
2445
+ }
1842
2446
  }
1843
2447
  class DatabaseApi {
1844
2448
  constructor(extraProps) {
@@ -1890,6 +2494,17 @@ class DatabaseApi {
1890
2494
  ...this.extraProps
1891
2495
  });
1892
2496
  }
2497
+ renameDatabase({
2498
+ workspace,
2499
+ database,
2500
+ newName
2501
+ }) {
2502
+ return operationsByTag.databases.renameDatabase({
2503
+ pathParams: { workspaceId: workspace, dbName: database },
2504
+ body: { newName },
2505
+ ...this.extraProps
2506
+ });
2507
+ }
1893
2508
  getDatabaseGithubSettings({
1894
2509
  workspace,
1895
2510
  database
@@ -1928,9 +2543,8 @@ class DatabaseApi {
1928
2543
  }
1929
2544
 
1930
2545
  class XataApiPlugin {
1931
- async build(options) {
1932
- const { fetchImpl, apiKey } = await options.getFetchProps();
1933
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2546
+ build(options) {
2547
+ return new XataApiClient(options);
1934
2548
  }
1935
2549
  }
1936
2550
 
@@ -1938,12 +2552,38 @@ class XataPlugin {
1938
2552
  }
1939
2553
 
1940
2554
  function cleanFilter(filter) {
1941
- if (!filter)
2555
+ if (!isDefined(filter))
1942
2556
  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;
2557
+ if (!isObject(filter))
2558
+ return filter;
2559
+ const values = Object.fromEntries(
2560
+ Object.entries(filter).reduce((acc, [key, value]) => {
2561
+ if (!isDefined(value))
2562
+ return acc;
2563
+ if (Array.isArray(value)) {
2564
+ const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
2565
+ if (clean.length === 0)
2566
+ return acc;
2567
+ return [...acc, [key, clean]];
2568
+ }
2569
+ if (isObject(value)) {
2570
+ const clean = cleanFilter(value);
2571
+ if (!isDefined(clean))
2572
+ return acc;
2573
+ return [...acc, [key, clean]];
2574
+ }
2575
+ return [...acc, [key, value]];
2576
+ }, [])
2577
+ );
2578
+ return Object.keys(values).length > 0 ? values : void 0;
1945
2579
  }
1946
2580
 
2581
+ var __defProp$5 = Object.defineProperty;
2582
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2583
+ var __publicField$5 = (obj, key, value) => {
2584
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2585
+ return value;
2586
+ };
1947
2587
  var __accessCheck$6 = (obj, member, msg) => {
1948
2588
  if (!member.has(obj))
1949
2589
  throw TypeError("Cannot " + msg);
@@ -1966,22 +2606,58 @@ var _query, _page;
1966
2606
  class Page {
1967
2607
  constructor(query, meta, records = []) {
1968
2608
  __privateAdd$6(this, _query, void 0);
2609
+ /**
2610
+ * Page metadata, required to retrieve additional records.
2611
+ */
2612
+ __publicField$5(this, "meta");
2613
+ /**
2614
+ * The set of results for this page.
2615
+ */
2616
+ __publicField$5(this, "records");
1969
2617
  __privateSet$6(this, _query, query);
1970
2618
  this.meta = meta;
1971
2619
  this.records = new RecordArray(this, records);
1972
2620
  }
2621
+ /**
2622
+ * Retrieves the next page of results.
2623
+ * @param size Maximum number of results to be retrieved.
2624
+ * @param offset Number of results to skip when retrieving the results.
2625
+ * @returns The next page or results.
2626
+ */
1973
2627
  async nextPage(size, offset) {
1974
2628
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
1975
2629
  }
2630
+ /**
2631
+ * Retrieves the previous page of results.
2632
+ * @param size Maximum number of results to be retrieved.
2633
+ * @param offset Number of results to skip when retrieving the results.
2634
+ * @returns The previous page or results.
2635
+ */
1976
2636
  async previousPage(size, offset) {
1977
2637
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1978
2638
  }
2639
+ /**
2640
+ * Retrieves the start page of results.
2641
+ * @param size Maximum number of results to be retrieved.
2642
+ * @param offset Number of results to skip when retrieving the results.
2643
+ * @returns The start page or results.
2644
+ */
1979
2645
  async startPage(size, offset) {
1980
2646
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1981
2647
  }
2648
+ /**
2649
+ * Retrieves the end page of results.
2650
+ * @param size Maximum number of results to be retrieved.
2651
+ * @param offset Number of results to skip when retrieving the results.
2652
+ * @returns The end page or results.
2653
+ */
1982
2654
  async endPage(size, offset) {
1983
2655
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1984
2656
  }
2657
+ /**
2658
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
2659
+ * @returns Whether or not there will be additional results in the next page of results.
2660
+ */
1985
2661
  hasNextPage() {
1986
2662
  return this.meta.page.more;
1987
2663
  }
@@ -1994,7 +2670,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
1994
2670
  function isCursorPaginationOptions(options) {
1995
2671
  return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1996
2672
  }
1997
- const _RecordArray = class extends Array {
2673
+ const _RecordArray = class _RecordArray extends Array {
1998
2674
  constructor(...args) {
1999
2675
  super(..._RecordArray.parseConstructorParams(...args));
2000
2676
  __privateAdd$6(this, _page, void 0);
@@ -2022,29 +2698,58 @@ const _RecordArray = class extends Array {
2022
2698
  map(callbackfn, thisArg) {
2023
2699
  return this.toArray().map(callbackfn, thisArg);
2024
2700
  }
2701
+ /**
2702
+ * Retrieve next page of records
2703
+ *
2704
+ * @returns A new array of objects
2705
+ */
2025
2706
  async nextPage(size, offset) {
2026
2707
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
2027
2708
  return new _RecordArray(newPage);
2028
2709
  }
2710
+ /**
2711
+ * Retrieve previous page of records
2712
+ *
2713
+ * @returns A new array of objects
2714
+ */
2029
2715
  async previousPage(size, offset) {
2030
2716
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
2031
2717
  return new _RecordArray(newPage);
2032
2718
  }
2719
+ /**
2720
+ * Retrieve start page of records
2721
+ *
2722
+ * @returns A new array of objects
2723
+ */
2033
2724
  async startPage(size, offset) {
2034
2725
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
2035
2726
  return new _RecordArray(newPage);
2036
2727
  }
2728
+ /**
2729
+ * Retrieve end page of records
2730
+ *
2731
+ * @returns A new array of objects
2732
+ */
2037
2733
  async endPage(size, offset) {
2038
2734
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
2039
2735
  return new _RecordArray(newPage);
2040
2736
  }
2737
+ /**
2738
+ * @returns Boolean indicating if there is a next page
2739
+ */
2041
2740
  hasNextPage() {
2042
2741
  return __privateGet$6(this, _page).meta.page.more;
2043
2742
  }
2044
2743
  };
2045
- let RecordArray = _RecordArray;
2046
2744
  _page = new WeakMap();
2745
+ let RecordArray = _RecordArray;
2047
2746
 
2747
+ var __defProp$4 = Object.defineProperty;
2748
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2749
+ var __publicField$4 = (obj, key, value) => {
2750
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
2751
+ return value;
2752
+ };
2048
2753
  var __accessCheck$5 = (obj, member, msg) => {
2049
2754
  if (!member.has(obj))
2050
2755
  throw TypeError("Cannot " + msg);
@@ -2068,14 +2773,15 @@ var __privateMethod$3 = (obj, member, method) => {
2068
2773
  return method;
2069
2774
  };
2070
2775
  var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
2071
- const _Query = class {
2776
+ const _Query = class _Query {
2072
2777
  constructor(repository, table, data, rawParent) {
2073
2778
  __privateAdd$5(this, _cleanFilterConstraint);
2074
2779
  __privateAdd$5(this, _table$1, void 0);
2075
2780
  __privateAdd$5(this, _repository, void 0);
2076
2781
  __privateAdd$5(this, _data, { filter: {} });
2077
- this.meta = { page: { cursor: "start", more: true } };
2078
- this.records = new RecordArray(this, []);
2782
+ // Implements pagination
2783
+ __publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
2784
+ __publicField$4(this, "records", new RecordArray(this, []));
2079
2785
  __privateSet$5(this, _table$1, table);
2080
2786
  if (repository) {
2081
2787
  __privateSet$5(this, _repository, repository);
@@ -2111,18 +2817,38 @@ const _Query = class {
2111
2817
  const key = JSON.stringify({ columns, filter, sort, pagination });
2112
2818
  return toBase64(key);
2113
2819
  }
2820
+ /**
2821
+ * Builds a new query object representing a logical OR between the given subqueries.
2822
+ * @param queries An array of subqueries.
2823
+ * @returns A new Query object.
2824
+ */
2114
2825
  any(...queries) {
2115
2826
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2116
2827
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2117
2828
  }
2829
+ /**
2830
+ * Builds a new query object representing a logical AND between the given subqueries.
2831
+ * @param queries An array of subqueries.
2832
+ * @returns A new Query object.
2833
+ */
2118
2834
  all(...queries) {
2119
2835
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2120
2836
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2121
2837
  }
2838
+ /**
2839
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
2840
+ * @param queries An array of subqueries.
2841
+ * @returns A new Query object.
2842
+ */
2122
2843
  not(...queries) {
2123
2844
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2124
2845
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2125
2846
  }
2847
+ /**
2848
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
2849
+ * @param queries An array of subqueries.
2850
+ * @returns A new Query object.
2851
+ */
2126
2852
  none(...queries) {
2127
2853
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2128
2854
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2145,6 +2871,11 @@ const _Query = class {
2145
2871
  const sort = [...originalSort, { column, direction }];
2146
2872
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2147
2873
  }
2874
+ /**
2875
+ * Builds a new query specifying the set of columns to be returned in the query response.
2876
+ * @param columns Array of column names to be returned by the query.
2877
+ * @returns A new Query object.
2878
+ */
2148
2879
  select(columns) {
2149
2880
  return new _Query(
2150
2881
  __privateGet$5(this, _repository),
@@ -2157,6 +2888,12 @@ const _Query = class {
2157
2888
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2158
2889
  return __privateGet$5(this, _repository).query(query);
2159
2890
  }
2891
+ /**
2892
+ * Get results in an iterator
2893
+ *
2894
+ * @async
2895
+ * @returns Async interable of results
2896
+ */
2160
2897
  async *[Symbol.asyncIterator]() {
2161
2898
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2162
2899
  yield record;
@@ -2217,26 +2954,53 @@ const _Query = class {
2217
2954
  );
2218
2955
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2219
2956
  }
2957
+ /**
2958
+ * Builds a new query object adding a cache TTL in milliseconds.
2959
+ * @param ttl The cache TTL in milliseconds.
2960
+ * @returns A new Query object.
2961
+ */
2220
2962
  cache(ttl) {
2221
2963
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2222
2964
  }
2965
+ /**
2966
+ * Retrieve next page of records
2967
+ *
2968
+ * @returns A new page object.
2969
+ */
2223
2970
  nextPage(size, offset) {
2224
2971
  return this.startPage(size, offset);
2225
2972
  }
2973
+ /**
2974
+ * Retrieve previous page of records
2975
+ *
2976
+ * @returns A new page object
2977
+ */
2226
2978
  previousPage(size, offset) {
2227
2979
  return this.startPage(size, offset);
2228
2980
  }
2981
+ /**
2982
+ * Retrieve start page of records
2983
+ *
2984
+ * @returns A new page object
2985
+ */
2229
2986
  startPage(size, offset) {
2230
2987
  return this.getPaginated({ pagination: { size, offset } });
2231
2988
  }
2989
+ /**
2990
+ * Retrieve last page of records
2991
+ *
2992
+ * @returns A new page object
2993
+ */
2232
2994
  endPage(size, offset) {
2233
2995
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2234
2996
  }
2997
+ /**
2998
+ * @returns Boolean indicating if there is a next page
2999
+ */
2235
3000
  hasNextPage() {
2236
3001
  return this.meta.page.more;
2237
3002
  }
2238
3003
  };
2239
- let Query = _Query;
2240
3004
  _table$1 = new WeakMap();
2241
3005
  _repository = new WeakMap();
2242
3006
  _data = new WeakMap();
@@ -2251,6 +3015,7 @@ cleanFilterConstraint_fn = function(column, value) {
2251
3015
  }
2252
3016
  return value;
2253
3017
  };
3018
+ let Query = _Query;
2254
3019
  function cleanParent(data, parent) {
2255
3020
  if (isCursorPaginationOptions(data.pagination)) {
2256
3021
  return { ...parent, sort: void 0, filter: void 0 };
@@ -2258,6 +3023,21 @@ function cleanParent(data, parent) {
2258
3023
  return parent;
2259
3024
  }
2260
3025
 
3026
+ const RecordColumnTypes = [
3027
+ "bool",
3028
+ "int",
3029
+ "float",
3030
+ "string",
3031
+ "text",
3032
+ "email",
3033
+ "multiple",
3034
+ "link",
3035
+ "object",
3036
+ "datetime",
3037
+ "vector",
3038
+ "file[]",
3039
+ "file"
3040
+ ];
2261
3041
  function isIdentifiable(x) {
2262
3042
  return isObject(x) && isString(x?.id);
2263
3043
  }
@@ -2271,7 +3051,11 @@ function isSortFilterString(value) {
2271
3051
  return isString(value);
2272
3052
  }
2273
3053
  function isSortFilterBase(filter) {
2274
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
3054
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
3055
+ if (key === "*")
3056
+ return value === "random";
3057
+ return value === "asc" || value === "desc";
3058
+ });
2275
3059
  }
2276
3060
  function isSortFilterObject(filter) {
2277
3061
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2344,10 +3128,7 @@ class RestRepository extends Query {
2344
3128
  __privateSet$4(this, _db, options.db);
2345
3129
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2346
3130
  __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
- });
3131
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2351
3132
  const trace = options.pluginOptions.trace ?? defaultTrace;
2352
3133
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2353
3134
  return trace(name, fn, {
@@ -2404,7 +3185,6 @@ class RestRepository extends Query {
2404
3185
  }
2405
3186
  const id = extractId(a);
2406
3187
  if (id) {
2407
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2408
3188
  try {
2409
3189
  const response = await getRecord({
2410
3190
  pathParams: {
@@ -2415,7 +3195,7 @@ class RestRepository extends Query {
2415
3195
  recordId: id
2416
3196
  },
2417
3197
  queryParams: { columns },
2418
- ...fetchProps
3198
+ ...__privateGet$4(this, _getFetchProps).call(this)
2419
3199
  });
2420
3200
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2421
3201
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2515,12 +3295,22 @@ class RestRepository extends Query {
2515
3295
  return result;
2516
3296
  }
2517
3297
  if (isString(a) && isObject(b)) {
3298
+ if (a === "")
3299
+ throw new Error("The id can't be empty");
2518
3300
  const columns = isStringArray(c) ? c : void 0;
2519
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3301
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2520
3302
  }
2521
3303
  if (isObject(a) && isString(a.id)) {
3304
+ if (a.id === "")
3305
+ throw new Error("The id can't be empty");
2522
3306
  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 });
3307
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3308
+ }
3309
+ if (!isDefined(a) && isObject(b)) {
3310
+ return await this.create(b, c);
3311
+ }
3312
+ if (isObject(a) && !isDefined(a.id)) {
3313
+ return await this.create(a, b);
2524
3314
  }
2525
3315
  throw new Error("Invalid arguments for createOrUpdate method");
2526
3316
  });
@@ -2537,12 +3327,22 @@ class RestRepository extends Query {
2537
3327
  return result;
2538
3328
  }
2539
3329
  if (isString(a) && isObject(b)) {
3330
+ if (a === "")
3331
+ throw new Error("The id can't be empty");
2540
3332
  const columns = isStringArray(c) ? c : void 0;
2541
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
3333
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2542
3334
  }
2543
3335
  if (isObject(a) && isString(a.id)) {
3336
+ if (a.id === "")
3337
+ throw new Error("The id can't be empty");
2544
3338
  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 });
3339
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3340
+ }
3341
+ if (!isDefined(a) && isObject(b)) {
3342
+ return await this.create(b, c);
3343
+ }
3344
+ if (isObject(a) && !isDefined(a.id)) {
3345
+ return await this.create(a, b);
2546
3346
  }
2547
3347
  throw new Error("Invalid arguments for createOrReplace method");
2548
3348
  });
@@ -2593,7 +3393,6 @@ class RestRepository extends Query {
2593
3393
  }
2594
3394
  async search(query, options = {}) {
2595
3395
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2596
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2597
3396
  const { records } = await searchTable({
2598
3397
  pathParams: {
2599
3398
  workspace: "{workspaceId}",
@@ -2611,7 +3410,7 @@ class RestRepository extends Query {
2611
3410
  page: options.page,
2612
3411
  target: options.target
2613
3412
  },
2614
- ...fetchProps
3413
+ ...__privateGet$4(this, _getFetchProps).call(this)
2615
3414
  });
2616
3415
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2617
3416
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2619,7 +3418,6 @@ class RestRepository extends Query {
2619
3418
  }
2620
3419
  async vectorSearch(column, query, options) {
2621
3420
  return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2622
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2623
3421
  const { records } = await vectorSearchTable({
2624
3422
  pathParams: {
2625
3423
  workspace: "{workspaceId}",
@@ -2634,7 +3432,7 @@ class RestRepository extends Query {
2634
3432
  size: options?.size,
2635
3433
  filter: options?.filter
2636
3434
  },
2637
- ...fetchProps
3435
+ ...__privateGet$4(this, _getFetchProps).call(this)
2638
3436
  });
2639
3437
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2640
3438
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2642,7 +3440,6 @@ class RestRepository extends Query {
2642
3440
  }
2643
3441
  async aggregate(aggs, filter) {
2644
3442
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2645
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2646
3443
  const result = await aggregateTable({
2647
3444
  pathParams: {
2648
3445
  workspace: "{workspaceId}",
@@ -2651,7 +3448,7 @@ class RestRepository extends Query {
2651
3448
  tableName: __privateGet$4(this, _table)
2652
3449
  },
2653
3450
  body: { aggs, filter },
2654
- ...fetchProps
3451
+ ...__privateGet$4(this, _getFetchProps).call(this)
2655
3452
  });
2656
3453
  return result;
2657
3454
  });
@@ -2662,7 +3459,6 @@ class RestRepository extends Query {
2662
3459
  if (cacheQuery)
2663
3460
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2664
3461
  const data = query.getQueryOptions();
2665
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2666
3462
  const { meta, records: objects } = await queryTable({
2667
3463
  pathParams: {
2668
3464
  workspace: "{workspaceId}",
@@ -2678,7 +3474,7 @@ class RestRepository extends Query {
2678
3474
  consistency: data.consistency
2679
3475
  },
2680
3476
  fetchOptions: data.fetchOptions,
2681
- ...fetchProps
3477
+ ...__privateGet$4(this, _getFetchProps).call(this)
2682
3478
  });
2683
3479
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2684
3480
  const records = objects.map(
@@ -2691,7 +3487,6 @@ class RestRepository extends Query {
2691
3487
  async summarizeTable(query, summaries, summariesFilter) {
2692
3488
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2693
3489
  const data = query.getQueryOptions();
2694
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2695
3490
  const result = await summarizeTable({
2696
3491
  pathParams: {
2697
3492
  workspace: "{workspaceId}",
@@ -2708,11 +3503,39 @@ class RestRepository extends Query {
2708
3503
  summaries,
2709
3504
  summariesFilter
2710
3505
  },
2711
- ...fetchProps
3506
+ ...__privateGet$4(this, _getFetchProps).call(this)
2712
3507
  });
2713
3508
  return result;
2714
3509
  });
2715
3510
  }
3511
+ ask(question, options) {
3512
+ const params = {
3513
+ pathParams: {
3514
+ workspace: "{workspaceId}",
3515
+ dbBranchName: "{dbBranch}",
3516
+ region: "{region}",
3517
+ tableName: __privateGet$4(this, _table)
3518
+ },
3519
+ body: {
3520
+ question,
3521
+ ...options
3522
+ },
3523
+ ...__privateGet$4(this, _getFetchProps).call(this)
3524
+ };
3525
+ if (options?.onMessage) {
3526
+ fetchSSERequest({
3527
+ endpoint: "dataPlane",
3528
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
3529
+ method: "POST",
3530
+ onMessage: (message) => {
3531
+ options.onMessage?.({ answer: message.text, records: message.records });
3532
+ },
3533
+ ...params
3534
+ });
3535
+ } else {
3536
+ return askTable(params);
3537
+ }
3538
+ }
2716
3539
  }
2717
3540
  _table = new WeakMap();
2718
3541
  _getFetchProps = new WeakMap();
@@ -2722,8 +3545,7 @@ _schemaTables$2 = new WeakMap();
2722
3545
  _trace = new WeakMap();
2723
3546
  _insertRecordWithoutId = new WeakSet();
2724
3547
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2725
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2726
- const record = transformObjectLinks(object);
3548
+ const record = removeLinksFromObject(object);
2727
3549
  const response = await insertRecord({
2728
3550
  pathParams: {
2729
3551
  workspace: "{workspaceId}",
@@ -2733,15 +3555,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2733
3555
  },
2734
3556
  queryParams: { columns },
2735
3557
  body: record,
2736
- ...fetchProps
3558
+ ...__privateGet$4(this, _getFetchProps).call(this)
2737
3559
  });
2738
3560
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2739
3561
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2740
3562
  };
2741
3563
  _insertRecordWithId = new WeakSet();
2742
3564
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2743
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2744
- const record = transformObjectLinks(object);
3565
+ if (!recordId)
3566
+ return null;
3567
+ const record = removeLinksFromObject(object);
2745
3568
  const response = await insertRecordWithID({
2746
3569
  pathParams: {
2747
3570
  workspace: "{workspaceId}",
@@ -2752,17 +3575,16 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2752
3575
  },
2753
3576
  body: record,
2754
3577
  queryParams: { createOnly, columns, ifVersion },
2755
- ...fetchProps
3578
+ ...__privateGet$4(this, _getFetchProps).call(this)
2756
3579
  });
2757
3580
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2758
3581
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2759
3582
  };
2760
3583
  _insertRecords = new WeakSet();
2761
3584
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2762
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2763
3585
  const chunkedOperations = chunk(
2764
3586
  objects.map((object) => ({
2765
- insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
3587
+ insert: { table: __privateGet$4(this, _table), record: removeLinksFromObject(object), createOnly, ifVersion }
2766
3588
  })),
2767
3589
  BULK_OPERATION_MAX_SIZE
2768
3590
  );
@@ -2775,7 +3597,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2775
3597
  region: "{region}"
2776
3598
  },
2777
3599
  body: { operations },
2778
- ...fetchProps
3600
+ ...__privateGet$4(this, _getFetchProps).call(this)
2779
3601
  });
2780
3602
  for (const result of results) {
2781
3603
  if (result.operation === "insert") {
@@ -2789,8 +3611,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2789
3611
  };
2790
3612
  _updateRecordWithID = new WeakSet();
2791
3613
  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);
3614
+ if (!recordId)
3615
+ return null;
3616
+ const { id: _id, ...record } = removeLinksFromObject(object);
2794
3617
  try {
2795
3618
  const response = await updateRecordWithID({
2796
3619
  pathParams: {
@@ -2802,7 +3625,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2802
3625
  },
2803
3626
  queryParams: { columns, ifVersion },
2804
3627
  body: record,
2805
- ...fetchProps
3628
+ ...__privateGet$4(this, _getFetchProps).call(this)
2806
3629
  });
2807
3630
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2808
3631
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2815,10 +3638,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2815
3638
  };
2816
3639
  _updateRecords = new WeakSet();
2817
3640
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2818
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2819
3641
  const chunkedOperations = chunk(
2820
3642
  objects.map(({ id, ...object }) => ({
2821
- update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
3643
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: removeLinksFromObject(object) }
2822
3644
  })),
2823
3645
  BULK_OPERATION_MAX_SIZE
2824
3646
  );
@@ -2831,7 +3653,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2831
3653
  region: "{region}"
2832
3654
  },
2833
3655
  body: { operations },
2834
- ...fetchProps
3656
+ ...__privateGet$4(this, _getFetchProps).call(this)
2835
3657
  });
2836
3658
  for (const result of results) {
2837
3659
  if (result.operation === "update") {
@@ -2845,7 +3667,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2845
3667
  };
2846
3668
  _upsertRecordWithID = new WeakSet();
2847
3669
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2848
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
3670
+ if (!recordId)
3671
+ return null;
2849
3672
  const response = await upsertRecordWithID({
2850
3673
  pathParams: {
2851
3674
  workspace: "{workspaceId}",
@@ -2856,14 +3679,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2856
3679
  },
2857
3680
  queryParams: { columns, ifVersion },
2858
3681
  body: object,
2859
- ...fetchProps
3682
+ ...__privateGet$4(this, _getFetchProps).call(this)
2860
3683
  });
2861
3684
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2862
3685
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2863
3686
  };
2864
3687
  _deleteRecord = new WeakSet();
2865
3688
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2866
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
3689
+ if (!recordId)
3690
+ return null;
2867
3691
  try {
2868
3692
  const response = await deleteRecord({
2869
3693
  pathParams: {
@@ -2874,7 +3698,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2874
3698
  recordId
2875
3699
  },
2876
3700
  queryParams: { columns },
2877
- ...fetchProps
3701
+ ...__privateGet$4(this, _getFetchProps).call(this)
2878
3702
  });
2879
3703
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2880
3704
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2887,9 +3711,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2887
3711
  };
2888
3712
  _deleteRecords = new WeakSet();
2889
3713
  deleteRecords_fn = async function(recordIds) {
2890
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2891
3714
  const chunkedOperations = chunk(
2892
- recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
3715
+ compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2893
3716
  BULK_OPERATION_MAX_SIZE
2894
3717
  );
2895
3718
  for (const operations of chunkedOperations) {
@@ -2900,21 +3723,22 @@ deleteRecords_fn = async function(recordIds) {
2900
3723
  region: "{region}"
2901
3724
  },
2902
3725
  body: { operations },
2903
- ...fetchProps
3726
+ ...__privateGet$4(this, _getFetchProps).call(this)
2904
3727
  });
2905
3728
  }
2906
3729
  };
2907
3730
  _setCacheQuery = new WeakSet();
2908
3731
  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 });
3732
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
2910
3733
  };
2911
3734
  _getCacheQuery = new WeakSet();
2912
3735
  getCacheQuery_fn = async function(query) {
2913
3736
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2914
- const result = await __privateGet$4(this, _cache).get(key);
3737
+ const result = await __privateGet$4(this, _cache)?.get(key);
2915
3738
  if (!result)
2916
3739
  return null;
2917
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
3740
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
3741
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2918
3742
  if (ttl < 0)
2919
3743
  return null;
2920
3744
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2924,15 +3748,14 @@ _getSchemaTables$1 = new WeakSet();
2924
3748
  getSchemaTables_fn$1 = async function() {
2925
3749
  if (__privateGet$4(this, _schemaTables$2))
2926
3750
  return __privateGet$4(this, _schemaTables$2);
2927
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2928
3751
  const { schema } = await getBranchDetails({
2929
3752
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2930
- ...fetchProps
3753
+ ...__privateGet$4(this, _getFetchProps).call(this)
2931
3754
  });
2932
3755
  __privateSet$4(this, _schemaTables$2, schema.tables);
2933
3756
  return schema.tables;
2934
3757
  };
2935
- const transformObjectLinks = (object) => {
3758
+ const removeLinksFromObject = (object) => {
2936
3759
  return Object.entries(object).reduce((acc, [key, value]) => {
2937
3760
  if (key === "xata")
2938
3761
  return acc;
@@ -2990,6 +3813,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2990
3813
  }
2991
3814
  }
2992
3815
  const record = { ...data };
3816
+ const serializable = { xata, ...removeLinksFromObject(data) };
3817
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2993
3818
  record.read = function(columns2) {
2994
3819
  return db[table].read(record["id"], columns2);
2995
3820
  };
@@ -3006,14 +3831,15 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3006
3831
  record.delete = function() {
3007
3832
  return db[table].delete(record["id"]);
3008
3833
  };
3834
+ record.xata = Object.freeze(metadata);
3009
3835
  record.getMetadata = function() {
3010
- return xata;
3836
+ return record.xata;
3011
3837
  };
3012
3838
  record.toSerializable = function() {
3013
- return JSON.parse(JSON.stringify(transformObjectLinks(data)));
3839
+ return JSON.parse(JSON.stringify(serializable));
3014
3840
  };
3015
3841
  record.toString = function() {
3016
- return JSON.stringify(transformObjectLinks(data));
3842
+ return JSON.stringify(serializable);
3017
3843
  };
3018
3844
  for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3019
3845
  Object.defineProperty(record, prop, { enumerable: false });
@@ -3031,11 +3857,7 @@ function extractId(value) {
3031
3857
  function isValidColumn(columns, column) {
3032
3858
  if (columns.includes("*"))
3033
3859
  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);
3860
+ return columns.filter((item) => item.startsWith(column.name)).length > 0;
3039
3861
  }
3040
3862
  function parseIfVersion(...args) {
3041
3863
  for (const arg of args) {
@@ -3046,6 +3868,12 @@ function parseIfVersion(...args) {
3046
3868
  return void 0;
3047
3869
  }
3048
3870
 
3871
+ var __defProp$3 = Object.defineProperty;
3872
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3873
+ var __publicField$3 = (obj, key, value) => {
3874
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
3875
+ return value;
3876
+ };
3049
3877
  var __accessCheck$3 = (obj, member, msg) => {
3050
3878
  if (!member.has(obj))
3051
3879
  throw TypeError("Cannot " + msg);
@@ -3068,6 +3896,8 @@ var _map;
3068
3896
  class SimpleCache {
3069
3897
  constructor(options = {}) {
3070
3898
  __privateAdd$3(this, _map, void 0);
3899
+ __publicField$3(this, "capacity");
3900
+ __publicField$3(this, "defaultQueryTTL");
3071
3901
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
3072
3902
  this.capacity = options.max ?? 500;
3073
3903
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
@@ -3203,19 +4033,19 @@ class SearchPlugin extends XataPlugin {
3203
4033
  __privateAdd$1(this, _schemaTables, void 0);
3204
4034
  __privateSet$1(this, _schemaTables, schemaTables);
3205
4035
  }
3206
- build({ getFetchProps }) {
4036
+ build(pluginOptions) {
3207
4037
  return {
3208
4038
  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);
4039
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4040
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3211
4041
  return records.map((record) => {
3212
4042
  const { table = "orphan" } = record.xata;
3213
4043
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3214
4044
  });
3215
4045
  },
3216
4046
  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);
4047
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
4048
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3219
4049
  return records.reduce((acc, record) => {
3220
4050
  const { table = "orphan" } = record.xata;
3221
4051
  const items = acc[table] ?? [];
@@ -3228,38 +4058,36 @@ class SearchPlugin extends XataPlugin {
3228
4058
  }
3229
4059
  _schemaTables = new WeakMap();
3230
4060
  _search = new WeakSet();
3231
- search_fn = async function(query, options, getFetchProps) {
3232
- const fetchProps = await getFetchProps();
4061
+ search_fn = async function(query, options, pluginOptions) {
3233
4062
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3234
4063
  const { records } = await searchBranch({
3235
4064
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4065
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3236
4066
  body: { tables, query, fuzziness, prefix, highlight, page },
3237
- ...fetchProps
4067
+ ...pluginOptions
3238
4068
  });
3239
4069
  return records;
3240
4070
  };
3241
4071
  _getSchemaTables = new WeakSet();
3242
- getSchemaTables_fn = async function(getFetchProps) {
4072
+ getSchemaTables_fn = async function(pluginOptions) {
3243
4073
  if (__privateGet$1(this, _schemaTables))
3244
4074
  return __privateGet$1(this, _schemaTables);
3245
- const fetchProps = await getFetchProps();
3246
4075
  const { schema } = await getBranchDetails({
3247
4076
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3248
- ...fetchProps
4077
+ ...pluginOptions
3249
4078
  });
3250
4079
  __privateSet$1(this, _schemaTables, schema.tables);
3251
4080
  return schema.tables;
3252
4081
  };
3253
4082
 
3254
4083
  class TransactionPlugin extends XataPlugin {
3255
- build({ getFetchProps }) {
4084
+ build(pluginOptions) {
3256
4085
  return {
3257
4086
  run: async (operations) => {
3258
- const fetchProps = await getFetchProps();
3259
4087
  const response = await branchTransaction({
3260
4088
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3261
4089
  body: { operations },
3262
- ...fetchProps
4090
+ ...pluginOptions
3263
4091
  });
3264
4092
  return response;
3265
4093
  }
@@ -3267,91 +4095,12 @@ class TransactionPlugin extends XataPlugin {
3267
4095
  }
3268
4096
  }
3269
4097
 
3270
- const isBranchStrategyBuilder = (strategy) => {
3271
- return typeof strategy === "function";
4098
+ var __defProp$2 = Object.defineProperty;
4099
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4100
+ var __publicField$2 = (obj, key, value) => {
4101
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
4102
+ return value;
3272
4103
  };
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
4104
  var __accessCheck = (obj, member, msg) => {
3356
4105
  if (!member.has(obj))
3357
4106
  throw TypeError("Cannot " + msg);
@@ -3375,20 +4124,21 @@ var __privateMethod = (obj, member, method) => {
3375
4124
  return method;
3376
4125
  };
3377
4126
  const buildClient = (plugins) => {
3378
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
4127
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3379
4128
  return _a = class {
3380
4129
  constructor(options = {}, schemaTables) {
3381
4130
  __privateAdd(this, _parseOptions);
3382
4131
  __privateAdd(this, _getFetchProps);
3383
- __privateAdd(this, _evaluateBranch);
3384
- __privateAdd(this, _branch, void 0);
3385
4132
  __privateAdd(this, _options, void 0);
4133
+ __publicField$2(this, "db");
4134
+ __publicField$2(this, "search");
4135
+ __publicField$2(this, "transactions");
3386
4136
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3387
4137
  __privateSet(this, _options, safeOptions);
3388
4138
  const pluginOptions = {
3389
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
4139
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3390
4140
  cache: safeOptions.cache,
3391
- trace: safeOptions.trace
4141
+ host: safeOptions.host
3392
4142
  };
3393
4143
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3394
4144
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -3399,22 +4149,15 @@ const buildClient = (plugins) => {
3399
4149
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3400
4150
  if (namespace === void 0)
3401
4151
  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
- }
4152
+ this[key] = namespace.build(pluginOptions);
3410
4153
  }
3411
4154
  }
3412
4155
  async getConfig() {
3413
4156
  const databaseURL = __privateGet(this, _options).databaseURL;
3414
- const branch = await __privateGet(this, _options).branch();
4157
+ const branch = __privateGet(this, _options).branch;
3415
4158
  return { databaseURL, branch };
3416
4159
  }
3417
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
4160
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3418
4161
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3419
4162
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3420
4163
  if (isBrowser && !enableBrowser) {
@@ -3428,20 +4171,34 @@ const buildClient = (plugins) => {
3428
4171
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3429
4172
  const trace = options?.trace ?? defaultTrace;
3430
4173
  const clientName = options?.clientName;
4174
+ const host = options?.host ?? "production";
3431
4175
  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
4176
  if (!apiKey) {
3440
4177
  throw new Error("Option apiKey is required");
3441
4178
  }
3442
4179
  if (!databaseURL) {
3443
4180
  throw new Error("Option databaseURL is required");
3444
4181
  }
4182
+ const envBranch = getBranch();
4183
+ const previewBranch = getPreviewBranch();
4184
+ const branch = options?.branch || previewBranch || envBranch || "main";
4185
+ if (!!previewBranch && branch !== previewBranch) {
4186
+ console.warn(
4187
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
4188
+ );
4189
+ } else if (!!envBranch && branch !== envBranch) {
4190
+ console.warn(
4191
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4192
+ );
4193
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
4194
+ console.warn(
4195
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4196
+ );
4197
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
4198
+ console.warn(
4199
+ `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.`
4200
+ );
4201
+ }
3445
4202
  return {
3446
4203
  fetch,
3447
4204
  databaseURL,
@@ -3449,12 +4206,13 @@ const buildClient = (plugins) => {
3449
4206
  branch,
3450
4207
  cache,
3451
4208
  trace,
4209
+ host,
3452
4210
  clientID: generateUUID(),
3453
4211
  enableBrowser,
3454
4212
  clientName,
3455
4213
  xataAgentExtra
3456
4214
  };
3457
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
4215
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3458
4216
  fetch,
3459
4217
  apiKey,
3460
4218
  databaseURL,
@@ -3464,16 +4222,14 @@ const buildClient = (plugins) => {
3464
4222
  clientName,
3465
4223
  xataAgentExtra
3466
4224
  }) {
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
4225
  return {
3471
- fetchImpl: fetch,
4226
+ fetch,
3472
4227
  apiKey,
3473
4228
  apiUrl: "",
4229
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3474
4230
  workspacesApiUrl: (path, params) => {
3475
4231
  const hasBranch = params.dbBranchName ?? params.branch;
3476
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
4232
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3477
4233
  return databaseURL + newPath;
3478
4234
  },
3479
4235
  trace,
@@ -3481,32 +4237,22 @@ const buildClient = (plugins) => {
3481
4237
  clientName,
3482
4238
  xataAgentExtra
3483
4239
  };
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
4240
  }, _a;
3501
4241
  };
3502
4242
  class BaseClient extends buildClient() {
3503
4243
  }
3504
4244
 
4245
+ var __defProp$1 = Object.defineProperty;
4246
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4247
+ var __publicField$1 = (obj, key, value) => {
4248
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
4249
+ return value;
4250
+ };
3505
4251
  const META = "__";
3506
4252
  const VALUE = "___";
3507
4253
  class Serializer {
3508
4254
  constructor() {
3509
- this.classes = {};
4255
+ __publicField$1(this, "classes", {});
3510
4256
  }
3511
4257
  add(clazz) {
3512
4258
  this.classes[clazz.name] = clazz;
@@ -3584,9 +4330,16 @@ function buildWorkerRunner(config) {
3584
4330
  };
3585
4331
  }
3586
4332
 
4333
+ var __defProp = Object.defineProperty;
4334
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4335
+ var __publicField = (obj, key, value) => {
4336
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4337
+ return value;
4338
+ };
3587
4339
  class XataError extends Error {
3588
4340
  constructor(message, status) {
3589
4341
  super(message);
4342
+ __publicField(this, "status");
3590
4343
  this.status = status;
3591
4344
  }
3592
4345
  }
@@ -3601,6 +4354,7 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
3601
4354
  exports.Page = Page;
3602
4355
  exports.Query = Query;
3603
4356
  exports.RecordArray = RecordArray;
4357
+ exports.RecordColumnTypes = RecordColumnTypes;
3604
4358
  exports.Repository = Repository;
3605
4359
  exports.RestRepository = RestRepository;
3606
4360
  exports.SchemaPlugin = SchemaPlugin;
@@ -3616,15 +4370,20 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
3616
4370
  exports.addTableColumn = addTableColumn;
3617
4371
  exports.aggregateTable = aggregateTable;
3618
4372
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
4373
+ exports.askTable = askTable;
3619
4374
  exports.branchTransaction = branchTransaction;
3620
4375
  exports.buildClient = buildClient;
4376
+ exports.buildPreviewBranchName = buildPreviewBranchName;
4377
+ exports.buildProviderString = buildProviderString;
3621
4378
  exports.buildWorkerRunner = buildWorkerRunner;
3622
4379
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
3623
4380
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
4381
+ exports.chatSessionMessage = chatSessionMessage;
3624
4382
  exports.compareBranchSchemas = compareBranchSchemas;
3625
4383
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3626
4384
  exports.compareMigrationRequest = compareMigrationRequest;
3627
4385
  exports.contains = contains;
4386
+ exports.copyBranch = copyBranch;
3628
4387
  exports.createBranch = createBranch;
3629
4388
  exports.createDatabase = createDatabase;
3630
4389
  exports.createMigrationRequest = createMigrationRequest;
@@ -3635,6 +4394,8 @@ exports.deleteBranch = deleteBranch;
3635
4394
  exports.deleteColumn = deleteColumn;
3636
4395
  exports.deleteDatabase = deleteDatabase;
3637
4396
  exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
4397
+ exports.deleteFile = deleteFile;
4398
+ exports.deleteFileItem = deleteFileItem;
3638
4399
  exports.deleteRecord = deleteRecord;
3639
4400
  exports.deleteTable = deleteTable;
3640
4401
  exports.deleteUser = deleteUser;
@@ -3645,8 +4406,10 @@ exports.endsWith = endsWith;
3645
4406
  exports.equals = equals;
3646
4407
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
3647
4408
  exports.exists = exists;
4409
+ exports.fileAccess = fileAccess;
3648
4410
  exports.ge = ge;
3649
4411
  exports.getAPIKey = getAPIKey;
4412
+ exports.getBranch = getBranch;
3650
4413
  exports.getBranchDetails = getBranchDetails;
3651
4414
  exports.getBranchList = getBranchList;
3652
4415
  exports.getBranchMetadata = getBranchMetadata;
@@ -3655,16 +4418,17 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
3655
4418
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
3656
4419
  exports.getBranchStats = getBranchStats;
3657
4420
  exports.getColumn = getColumn;
3658
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
3659
- exports.getCurrentBranchName = getCurrentBranchName;
3660
4421
  exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3661
4422
  exports.getDatabaseList = getDatabaseList;
3662
4423
  exports.getDatabaseMetadata = getDatabaseMetadata;
3663
4424
  exports.getDatabaseURL = getDatabaseURL;
4425
+ exports.getFile = getFile;
4426
+ exports.getFileItem = getFileItem;
3664
4427
  exports.getGitBranchesMapping = getGitBranchesMapping;
3665
4428
  exports.getHostUrl = getHostUrl;
3666
4429
  exports.getMigrationRequest = getMigrationRequest;
3667
4430
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
4431
+ exports.getPreviewBranch = getPreviewBranch;
3668
4432
  exports.getRecord = getRecord;
3669
4433
  exports.getTableColumns = getTableColumns;
3670
4434
  exports.getTableSchema = getTableSchema;
@@ -3707,16 +4471,21 @@ exports.parseProviderString = parseProviderString;
3707
4471
  exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
3708
4472
  exports.pattern = pattern;
3709
4473
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
4474
+ exports.pushBranchMigrations = pushBranchMigrations;
4475
+ exports.putFile = putFile;
4476
+ exports.putFileItem = putFileItem;
3710
4477
  exports.queryMigrationRequests = queryMigrationRequests;
3711
4478
  exports.queryTable = queryTable;
3712
4479
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
3713
4480
  exports.removeWorkspaceMember = removeWorkspaceMember;
4481
+ exports.renameDatabase = renameDatabase;
3714
4482
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
3715
4483
  exports.resolveBranch = resolveBranch;
3716
4484
  exports.searchBranch = searchBranch;
3717
4485
  exports.searchTable = searchTable;
3718
4486
  exports.serialize = serialize;
3719
4487
  exports.setTableSchema = setTableSchema;
4488
+ exports.sqlQuery = sqlQuery;
3720
4489
  exports.startsWith = startsWith;
3721
4490
  exports.summarizeTable = summarizeTable;
3722
4491
  exports.updateBranchMetadata = updateBranchMetadata;