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