@xata.io/client 0.0.0-alpha.vfa22996 → 0.0.0-alpha.vfa37ea7

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
@@ -1,5 +1,6 @@
1
- const defaultTrace = async (_name, fn, _options) => {
1
+ const defaultTrace = async (name, fn, _options) => {
2
2
  return await fn({
3
+ name,
3
4
  setAttributes: () => {
4
5
  return;
5
6
  }
@@ -90,8 +91,10 @@ function getEnvironment() {
90
91
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
91
92
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
92
93
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
93
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
94
- fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
94
+ deployPreview: process.env.XATA_PREVIEW,
95
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
96
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
97
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
95
98
  };
96
99
  }
97
100
  } catch (err) {
@@ -102,8 +105,10 @@ function getEnvironment() {
102
105
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
103
106
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
104
107
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
105
- envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
106
- fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
108
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
109
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
110
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
111
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
107
112
  };
108
113
  }
109
114
  } catch (err) {
@@ -112,8 +117,10 @@ function getEnvironment() {
112
117
  apiKey: getGlobalApiKey(),
113
118
  databaseURL: getGlobalDatabaseURL(),
114
119
  branch: getGlobalBranch(),
115
- envBranch: void 0,
116
- fallbackBranch: getGlobalFallbackBranch()
120
+ deployPreview: void 0,
121
+ deployPreviewBranch: void 0,
122
+ vercelGitCommitRef: void 0,
123
+ vercelGitRepoOwner: void 0
117
124
  };
118
125
  }
119
126
  function getEnableBrowserVariable() {
@@ -156,39 +163,48 @@ function getGlobalBranch() {
156
163
  return void 0;
157
164
  }
158
165
  }
159
- function getGlobalFallbackBranch() {
166
+ function getDatabaseURL() {
160
167
  try {
161
- return XATA_FALLBACK_BRANCH;
168
+ const { databaseURL } = getEnvironment();
169
+ return databaseURL;
162
170
  } catch (err) {
163
171
  return void 0;
164
172
  }
165
173
  }
166
- async function getGitBranch() {
167
- const cmd = ["git", "branch", "--show-current"];
168
- const fullCmd = cmd.join(" ");
169
- const nodeModule = ["child", "process"].join("_");
170
- const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
174
+ function getAPIKey() {
171
175
  try {
172
- if (typeof require === "function") {
173
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
174
- }
175
- const { execSync } = await import(nodeModule);
176
- return execSync(fullCmd, execOptions).toString().trim();
176
+ const { apiKey } = getEnvironment();
177
+ return apiKey;
177
178
  } catch (err) {
179
+ return void 0;
178
180
  }
181
+ }
182
+ function getBranch() {
179
183
  try {
180
- if (isObject(Deno)) {
181
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
182
- return new TextDecoder().decode(await process2.output()).trim();
183
- }
184
+ const { branch } = getEnvironment();
185
+ return branch ?? "main";
184
186
  } catch (err) {
187
+ return void 0;
185
188
  }
186
189
  }
187
-
188
- function getAPIKey() {
190
+ function buildPreviewBranchName({ org, branch }) {
191
+ return `preview-${org}-${branch}`;
192
+ }
193
+ function getPreviewBranch() {
189
194
  try {
190
- const { apiKey } = getEnvironment();
191
- return apiKey;
195
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
196
+ if (deployPreviewBranch)
197
+ return deployPreviewBranch;
198
+ switch (deployPreview) {
199
+ case "vercel": {
200
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
201
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
202
+ return void 0;
203
+ }
204
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
205
+ }
206
+ }
207
+ return void 0;
192
208
  } catch (err) {
193
209
  return void 0;
194
210
  }
@@ -248,7 +264,7 @@ class ApiRequestPool {
248
264
  return __privateGet$8(this, _fetch);
249
265
  }
250
266
  request(url, options) {
251
- const start = new Date();
267
+ const start = /* @__PURE__ */ new Date();
252
268
  const fetch2 = this.getFetch();
253
269
  const runRequest = async (stalled = false) => {
254
270
  const response = await fetch2(url, options);
@@ -258,7 +274,7 @@ class ApiRequestPool {
258
274
  return await runRequest(true);
259
275
  }
260
276
  if (stalled) {
261
- const stalledTime = new Date().getTime() - start.getTime();
277
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
262
278
  console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
263
279
  }
264
280
  return response;
@@ -294,7 +310,187 @@ enqueue_fn = function(task) {
294
310
  return promise;
295
311
  };
296
312
 
297
- const VERSION = "0.0.0-alpha.vfa22996";
313
+ function generateUUID() {
314
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
315
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
316
+ return v.toString(16);
317
+ });
318
+ }
319
+
320
+ async function getBytes(stream, onChunk) {
321
+ const reader = stream.getReader();
322
+ let result;
323
+ while (!(result = await reader.read()).done) {
324
+ onChunk(result.value);
325
+ }
326
+ }
327
+ function getLines(onLine) {
328
+ let buffer;
329
+ let position;
330
+ let fieldLength;
331
+ let discardTrailingNewline = false;
332
+ return function onChunk(arr) {
333
+ if (buffer === void 0) {
334
+ buffer = arr;
335
+ position = 0;
336
+ fieldLength = -1;
337
+ } else {
338
+ buffer = concat(buffer, arr);
339
+ }
340
+ const bufLength = buffer.length;
341
+ let lineStart = 0;
342
+ while (position < bufLength) {
343
+ if (discardTrailingNewline) {
344
+ if (buffer[position] === 10 /* NewLine */) {
345
+ lineStart = ++position;
346
+ }
347
+ discardTrailingNewline = false;
348
+ }
349
+ let lineEnd = -1;
350
+ for (; position < bufLength && lineEnd === -1; ++position) {
351
+ switch (buffer[position]) {
352
+ case 58 /* Colon */:
353
+ if (fieldLength === -1) {
354
+ fieldLength = position - lineStart;
355
+ }
356
+ break;
357
+ case 13 /* CarriageReturn */:
358
+ discardTrailingNewline = true;
359
+ case 10 /* NewLine */:
360
+ lineEnd = position;
361
+ break;
362
+ }
363
+ }
364
+ if (lineEnd === -1) {
365
+ break;
366
+ }
367
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
368
+ lineStart = position;
369
+ fieldLength = -1;
370
+ }
371
+ if (lineStart === bufLength) {
372
+ buffer = void 0;
373
+ } else if (lineStart !== 0) {
374
+ buffer = buffer.subarray(lineStart);
375
+ position -= lineStart;
376
+ }
377
+ };
378
+ }
379
+ function getMessages(onId, onRetry, onMessage) {
380
+ let message = newMessage();
381
+ const decoder = new TextDecoder();
382
+ return function onLine(line, fieldLength) {
383
+ if (line.length === 0) {
384
+ onMessage?.(message);
385
+ message = newMessage();
386
+ } else if (fieldLength > 0) {
387
+ const field = decoder.decode(line.subarray(0, fieldLength));
388
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
389
+ const value = decoder.decode(line.subarray(valueOffset));
390
+ switch (field) {
391
+ case "data":
392
+ message.data = message.data ? message.data + "\n" + value : value;
393
+ break;
394
+ case "event":
395
+ message.event = value;
396
+ break;
397
+ case "id":
398
+ onId(message.id = value);
399
+ break;
400
+ case "retry":
401
+ const retry = parseInt(value, 10);
402
+ if (!isNaN(retry)) {
403
+ onRetry(message.retry = retry);
404
+ }
405
+ break;
406
+ }
407
+ }
408
+ };
409
+ }
410
+ function concat(a, b) {
411
+ const res = new Uint8Array(a.length + b.length);
412
+ res.set(a);
413
+ res.set(b, a.length);
414
+ return res;
415
+ }
416
+ function newMessage() {
417
+ return {
418
+ data: "",
419
+ event: "",
420
+ id: "",
421
+ retry: void 0
422
+ };
423
+ }
424
+ const EventStreamContentType = "text/event-stream";
425
+ const LastEventId = "last-event-id";
426
+ function fetchEventSource(input, {
427
+ signal: inputSignal,
428
+ headers: inputHeaders,
429
+ onopen: inputOnOpen,
430
+ onmessage,
431
+ onclose,
432
+ onerror,
433
+ fetch: inputFetch,
434
+ ...rest
435
+ }) {
436
+ return new Promise((resolve, reject) => {
437
+ const headers = { ...inputHeaders };
438
+ if (!headers.accept) {
439
+ headers.accept = EventStreamContentType;
440
+ }
441
+ let curRequestController;
442
+ function dispose() {
443
+ curRequestController.abort();
444
+ }
445
+ inputSignal?.addEventListener("abort", () => {
446
+ dispose();
447
+ resolve();
448
+ });
449
+ const fetchImpl = inputFetch ?? fetch;
450
+ const onopen = inputOnOpen ?? defaultOnOpen;
451
+ async function create() {
452
+ curRequestController = new AbortController();
453
+ try {
454
+ const response = await fetchImpl(input, {
455
+ ...rest,
456
+ headers,
457
+ signal: curRequestController.signal
458
+ });
459
+ await onopen(response);
460
+ await getBytes(
461
+ response.body,
462
+ getLines(
463
+ getMessages(
464
+ (id) => {
465
+ if (id) {
466
+ headers[LastEventId] = id;
467
+ } else {
468
+ delete headers[LastEventId];
469
+ }
470
+ },
471
+ (_retry) => {
472
+ },
473
+ onmessage
474
+ )
475
+ )
476
+ );
477
+ onclose?.();
478
+ dispose();
479
+ resolve();
480
+ } catch (err) {
481
+ }
482
+ }
483
+ create();
484
+ });
485
+ }
486
+ function defaultOnOpen(response) {
487
+ const contentType = response.headers?.get("content-type");
488
+ if (!contentType?.startsWith(EventStreamContentType)) {
489
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
490
+ }
491
+ }
492
+
493
+ const VERSION = "0.24.0";
298
494
 
299
495
  class ErrorWithCause extends Error {
300
496
  constructor(message, options) {
@@ -305,7 +501,7 @@ class FetcherError extends ErrorWithCause {
305
501
  constructor(status, data, requestId) {
306
502
  super(getMessage(data));
307
503
  this.status = status;
308
- this.errors = isBulkError(data) ? data.errors : void 0;
504
+ this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
309
505
  this.requestId = requestId;
310
506
  if (data instanceof Error) {
311
507
  this.stack = data.stack;
@@ -370,14 +566,15 @@ function hostHeader(url) {
370
566
  const { groups } = pattern.exec(url) ?? {};
371
567
  return groups?.host ? { Host: groups.host } : {};
372
568
  }
569
+ const defaultClientID = generateUUID();
373
570
  async function fetch$1({
374
571
  url: path,
375
572
  method,
376
573
  body,
377
- headers,
574
+ headers: customHeaders,
378
575
  pathParams,
379
576
  queryParams,
380
- fetchImpl,
577
+ fetch: fetch2,
381
578
  apiKey,
382
579
  endpoint,
383
580
  apiUrl,
@@ -386,9 +583,11 @@ async function fetch$1({
386
583
  signal,
387
584
  clientID,
388
585
  sessionID,
586
+ clientName,
587
+ xataAgentExtra,
389
588
  fetchOptions = {}
390
589
  }) {
391
- pool.setFetch(fetchImpl);
590
+ pool.setFetch(fetch2);
392
591
  return await trace(
393
592
  `${method.toUpperCase()} ${path}`,
394
593
  async ({ setAttributes }) => {
@@ -399,19 +598,27 @@ async function fetch$1({
399
598
  [TraceAttributes.HTTP_URL]: url,
400
599
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
401
600
  });
601
+ const xataAgent = compact([
602
+ ["client", "TS_SDK"],
603
+ ["version", VERSION],
604
+ isDefined(clientName) ? ["service", clientName] : void 0,
605
+ ...Object.entries(xataAgentExtra ?? {})
606
+ ]).map(([key, value]) => `${key}=${value}`).join("; ");
607
+ const headers = {
608
+ "Accept-Encoding": "identity",
609
+ "Content-Type": "application/json",
610
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
611
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
612
+ "X-Xata-Agent": xataAgent,
613
+ ...customHeaders,
614
+ ...hostHeader(fullUrl),
615
+ Authorization: `Bearer ${apiKey}`
616
+ };
402
617
  const response = await pool.request(url, {
403
618
  ...fetchOptions,
404
619
  method: method.toUpperCase(),
405
620
  body: body ? JSON.stringify(body) : void 0,
406
- headers: {
407
- "Content-Type": "application/json",
408
- "User-Agent": `Xata client-ts/${VERSION}`,
409
- "X-Xata-Client-ID": clientID ?? "",
410
- "X-Xata-Session-ID": sessionID ?? "",
411
- ...headers,
412
- ...hostHeader(fullUrl),
413
- Authorization: `Bearer ${apiKey}`
414
- },
621
+ headers,
415
622
  signal
416
623
  });
417
624
  const { host, protocol } = parseUrl(response.url);
@@ -442,6 +649,59 @@ async function fetch$1({
442
649
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
443
650
  );
444
651
  }
652
+ function fetchSSERequest({
653
+ url: path,
654
+ method,
655
+ body,
656
+ headers: customHeaders,
657
+ pathParams,
658
+ queryParams,
659
+ fetch: fetch2,
660
+ apiKey,
661
+ endpoint,
662
+ apiUrl,
663
+ workspacesApiUrl,
664
+ onMessage,
665
+ onError,
666
+ onClose,
667
+ signal,
668
+ clientID,
669
+ sessionID,
670
+ clientName,
671
+ xataAgentExtra
672
+ }) {
673
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
674
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
675
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
676
+ void fetchEventSource(url, {
677
+ method,
678
+ body: JSON.stringify(body),
679
+ fetch: fetch2,
680
+ signal,
681
+ headers: {
682
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
683
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
684
+ "X-Xata-Agent": compact([
685
+ ["client", "TS_SDK"],
686
+ ["version", VERSION],
687
+ isDefined(clientName) ? ["service", clientName] : void 0,
688
+ ...Object.entries(xataAgentExtra ?? {})
689
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
690
+ ...customHeaders,
691
+ Authorization: `Bearer ${apiKey}`,
692
+ "Content-Type": "application/json"
693
+ },
694
+ onmessage(ev) {
695
+ onMessage?.(JSON.parse(ev.data));
696
+ },
697
+ onerror(ev) {
698
+ onError?.(JSON.parse(ev.data));
699
+ },
700
+ onclose() {
701
+ onClose?.();
702
+ }
703
+ });
704
+ }
445
705
  function parseUrl(url) {
446
706
  try {
447
707
  const { host, protocol } = new URL(url);
@@ -453,17 +713,12 @@ function parseUrl(url) {
453
713
 
454
714
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
455
715
 
456
- const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
457
716
  const getBranchList = (variables, signal) => dataPlaneFetch({
458
717
  url: "/dbs/{dbName}",
459
718
  method: "get",
460
719
  ...variables,
461
720
  signal
462
721
  });
463
- const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
464
- const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
465
- const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
466
- const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
467
722
  const getBranchDetails = (variables, signal) => dataPlaneFetch({
468
723
  url: "/db/{dbBranchName}",
469
724
  method: "get",
@@ -477,6 +732,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
477
732
  ...variables,
478
733
  signal
479
734
  });
735
+ const copyBranch = (variables, signal) => dataPlaneFetch({
736
+ url: "/db/{dbBranchName}/copy",
737
+ method: "post",
738
+ ...variables,
739
+ signal
740
+ });
480
741
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
481
742
  url: "/db/{dbBranchName}/metadata",
482
743
  method: "put",
@@ -502,7 +763,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
502
763
  const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
503
764
  const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
504
765
  const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
505
- const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
506
766
  const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
507
767
  const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
508
768
  const getMigrationRequest = (variables, signal) => dataPlaneFetch({
@@ -527,6 +787,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
527
787
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
528
788
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
529
789
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
790
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
530
791
  const createTable = (variables, signal) => dataPlaneFetch({
531
792
  url: "/db/{dbBranchName}/tables/{tableName}",
532
793
  method: "put",
@@ -569,7 +830,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
569
830
  ...variables,
570
831
  signal
571
832
  });
833
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
572
834
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
835
+ const getFileItem = (variables, signal) => dataPlaneFetch({
836
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
837
+ method: "get",
838
+ ...variables,
839
+ signal
840
+ });
841
+ const putFileItem = (variables, signal) => dataPlaneFetch({
842
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
843
+ method: "put",
844
+ ...variables,
845
+ signal
846
+ });
847
+ const deleteFileItem = (variables, signal) => dataPlaneFetch({
848
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
849
+ method: "delete",
850
+ ...variables,
851
+ signal
852
+ });
853
+ const getFile = (variables, signal) => dataPlaneFetch({
854
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
855
+ method: "get",
856
+ ...variables,
857
+ signal
858
+ });
859
+ const putFile = (variables, signal) => dataPlaneFetch({
860
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
861
+ method: "put",
862
+ ...variables,
863
+ signal
864
+ });
865
+ const deleteFile = (variables, signal) => dataPlaneFetch({
866
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
867
+ method: "delete",
868
+ ...variables,
869
+ signal
870
+ });
573
871
  const getRecord = (variables, signal) => dataPlaneFetch({
574
872
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
575
873
  method: "get",
@@ -599,21 +897,34 @@ const searchTable = (variables, signal) => dataPlaneFetch({
599
897
  ...variables,
600
898
  signal
601
899
  });
900
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
901
+ url: "/db/{dbBranchName}/sql",
902
+ method: "post",
903
+ ...variables,
904
+ signal
905
+ });
906
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
907
+ const askTable = (variables, signal) => dataPlaneFetch({
908
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
909
+ method: "post",
910
+ ...variables,
911
+ signal
912
+ });
602
913
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
603
914
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
915
+ const fileAccess = (variables, signal) => dataPlaneFetch({
916
+ url: "/file/{fileId}",
917
+ method: "get",
918
+ ...variables,
919
+ signal
920
+ });
604
921
  const operationsByTag$2 = {
605
- database: {
606
- dEPRECATEDgetDatabaseList,
607
- dEPRECATEDcreateDatabase,
608
- dEPRECATEDdeleteDatabase,
609
- dEPRECATEDgetDatabaseMetadata,
610
- dEPRECATEDupdateDatabaseMetadata
611
- },
612
922
  branch: {
613
923
  getBranchList,
614
924
  getBranchDetails,
615
925
  createBranch,
616
926
  deleteBranch,
927
+ copyBranch,
617
928
  updateBranchMetadata,
618
929
  getBranchMetadata,
619
930
  getBranchStats,
@@ -631,17 +942,8 @@ const operationsByTag$2 = {
631
942
  compareBranchSchemas,
632
943
  updateBranchSchema,
633
944
  previewBranchSchemaEdit,
634
- applyBranchSchemaEdit
635
- },
636
- records: {
637
- branchTransaction,
638
- insertRecord,
639
- getRecord,
640
- insertRecordWithID,
641
- updateRecordWithID,
642
- upsertRecordWithID,
643
- deleteRecord,
644
- bulkInsertTableRecords
945
+ applyBranchSchemaEdit,
946
+ pushBranchMigrations
645
947
  },
646
948
  migrationRequests: {
647
949
  queryMigrationRequests,
@@ -665,7 +967,27 @@ const operationsByTag$2 = {
665
967
  updateColumn,
666
968
  deleteColumn
667
969
  },
668
- searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
970
+ records: {
971
+ branchTransaction,
972
+ insertRecord,
973
+ getRecord,
974
+ insertRecordWithID,
975
+ updateRecordWithID,
976
+ upsertRecordWithID,
977
+ deleteRecord,
978
+ bulkInsertTableRecords
979
+ },
980
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
981
+ searchAndFilter: {
982
+ queryTable,
983
+ searchBranch,
984
+ searchTable,
985
+ sqlQuery,
986
+ vectorSearchTable,
987
+ askTable,
988
+ summarizeTable,
989
+ aggregateTable
990
+ }
669
991
  };
670
992
 
671
993
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
@@ -764,6 +1086,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
764
1086
  });
765
1087
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
766
1088
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1089
+ const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
1090
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
1091
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
1092
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
767
1093
  const listRegions = (variables, signal) => controlPlaneFetch({
768
1094
  url: "/workspaces/{workspaceId}/regions",
769
1095
  method: "get",
@@ -796,6 +1122,10 @@ const operationsByTag$1 = {
796
1122
  deleteDatabase,
797
1123
  getDatabaseMetadata,
798
1124
  updateDatabaseMetadata,
1125
+ renameDatabase,
1126
+ getDatabaseGithubSettings,
1127
+ updateDatabaseGithubSettings,
1128
+ deleteDatabaseGithubSettings,
799
1129
  listRegions
800
1130
  }
801
1131
  };
@@ -816,8 +1146,12 @@ const providers = {
816
1146
  workspaces: "https://{workspaceId}.{region}.xata.sh"
817
1147
  },
818
1148
  staging: {
819
- main: "https://staging.xatabase.co",
820
- workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
1149
+ main: "https://api.staging-xata.dev",
1150
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1151
+ },
1152
+ dev: {
1153
+ main: "https://api.dev-xata.dev",
1154
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
821
1155
  }
822
1156
  };
823
1157
  function isHostProviderAlias(alias) {
@@ -835,15 +1169,22 @@ function parseProviderString(provider = "production") {
835
1169
  return null;
836
1170
  return { main, workspaces };
837
1171
  }
1172
+ function buildProviderString(provider) {
1173
+ if (isHostProviderAlias(provider))
1174
+ return provider;
1175
+ return `${provider.main},${provider.workspaces}`;
1176
+ }
838
1177
  function parseWorkspacesUrlParts(url) {
839
1178
  if (!isString(url))
840
1179
  return null;
841
- const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
842
- const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
843
- const match = url.match(regex) || url.match(regexStaging);
1180
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
1181
+ const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1182
+ const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1183
+ const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1184
+ const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
844
1185
  if (!match)
845
1186
  return null;
846
- return { workspace: match[1], region: match[2] ?? "eu-west-1" };
1187
+ return { workspace: match[1], region: match[2] };
847
1188
  }
848
1189
 
849
1190
  var __accessCheck$7 = (obj, member, msg) => {
@@ -872,15 +1213,19 @@ class XataApiClient {
872
1213
  const provider = options.host ?? "production";
873
1214
  const apiKey = options.apiKey ?? getAPIKey();
874
1215
  const trace = options.trace ?? defaultTrace;
1216
+ const clientID = generateUUID();
875
1217
  if (!apiKey) {
876
1218
  throw new Error("Could not resolve a valid apiKey");
877
1219
  }
878
1220
  __privateSet$7(this, _extraProps, {
879
1221
  apiUrl: getHostUrl(provider, "main"),
880
1222
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
881
- fetchImpl: getFetchImplementation(options.fetch),
1223
+ fetch: getFetchImplementation(options.fetch),
882
1224
  apiKey,
883
- trace
1225
+ trace,
1226
+ clientName: options.clientName,
1227
+ xataAgentExtra: options.xataAgentExtra,
1228
+ clientID
884
1229
  });
885
1230
  }
886
1231
  get user() {
@@ -933,6 +1278,11 @@ class XataApiClient {
933
1278
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
934
1279
  return __privateGet$7(this, _namespaces).records;
935
1280
  }
1281
+ get files() {
1282
+ if (!__privateGet$7(this, _namespaces).files)
1283
+ __privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
1284
+ return __privateGet$7(this, _namespaces).files;
1285
+ }
936
1286
  get searchAndFilter() {
937
1287
  if (!__privateGet$7(this, _namespaces).searchAndFilter)
938
1288
  __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
@@ -1141,6 +1491,20 @@ class BranchApi {
1141
1491
  ...this.extraProps
1142
1492
  });
1143
1493
  }
1494
+ copyBranch({
1495
+ workspace,
1496
+ region,
1497
+ database,
1498
+ branch,
1499
+ destinationBranch,
1500
+ limit
1501
+ }) {
1502
+ return operationsByTag.branch.copyBranch({
1503
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1504
+ body: { destinationBranch, limit },
1505
+ ...this.extraProps
1506
+ });
1507
+ }
1144
1508
  updateBranchMetadata({
1145
1509
  workspace,
1146
1510
  region,
@@ -1496,6 +1860,164 @@ class RecordsApi {
1496
1860
  });
1497
1861
  }
1498
1862
  }
1863
+ class FilesApi {
1864
+ constructor(extraProps) {
1865
+ this.extraProps = extraProps;
1866
+ }
1867
+ getFileItem({
1868
+ workspace,
1869
+ region,
1870
+ database,
1871
+ branch,
1872
+ table,
1873
+ record,
1874
+ column,
1875
+ fileId
1876
+ }) {
1877
+ return operationsByTag.files.getFileItem({
1878
+ pathParams: {
1879
+ workspace,
1880
+ region,
1881
+ dbBranchName: `${database}:${branch}`,
1882
+ tableName: table,
1883
+ recordId: record,
1884
+ columnName: column,
1885
+ fileId
1886
+ },
1887
+ ...this.extraProps
1888
+ });
1889
+ }
1890
+ putFileItem({
1891
+ workspace,
1892
+ region,
1893
+ database,
1894
+ branch,
1895
+ table,
1896
+ record,
1897
+ column,
1898
+ fileId,
1899
+ file
1900
+ }) {
1901
+ return operationsByTag.files.putFileItem({
1902
+ pathParams: {
1903
+ workspace,
1904
+ region,
1905
+ dbBranchName: `${database}:${branch}`,
1906
+ tableName: table,
1907
+ recordId: record,
1908
+ columnName: column,
1909
+ fileId
1910
+ },
1911
+ // @ts-ignore
1912
+ body: file,
1913
+ ...this.extraProps
1914
+ });
1915
+ }
1916
+ deleteFileItem({
1917
+ workspace,
1918
+ region,
1919
+ database,
1920
+ branch,
1921
+ table,
1922
+ record,
1923
+ column,
1924
+ fileId
1925
+ }) {
1926
+ return operationsByTag.files.deleteFileItem({
1927
+ pathParams: {
1928
+ workspace,
1929
+ region,
1930
+ dbBranchName: `${database}:${branch}`,
1931
+ tableName: table,
1932
+ recordId: record,
1933
+ columnName: column,
1934
+ fileId
1935
+ },
1936
+ ...this.extraProps
1937
+ });
1938
+ }
1939
+ getFile({
1940
+ workspace,
1941
+ region,
1942
+ database,
1943
+ branch,
1944
+ table,
1945
+ record,
1946
+ column
1947
+ }) {
1948
+ return operationsByTag.files.getFile({
1949
+ pathParams: {
1950
+ workspace,
1951
+ region,
1952
+ dbBranchName: `${database}:${branch}`,
1953
+ tableName: table,
1954
+ recordId: record,
1955
+ columnName: column
1956
+ },
1957
+ ...this.extraProps
1958
+ });
1959
+ }
1960
+ putFile({
1961
+ workspace,
1962
+ region,
1963
+ database,
1964
+ branch,
1965
+ table,
1966
+ record,
1967
+ column,
1968
+ file
1969
+ }) {
1970
+ return operationsByTag.files.putFile({
1971
+ pathParams: {
1972
+ workspace,
1973
+ region,
1974
+ dbBranchName: `${database}:${branch}`,
1975
+ tableName: table,
1976
+ recordId: record,
1977
+ columnName: column
1978
+ },
1979
+ body: file,
1980
+ ...this.extraProps
1981
+ });
1982
+ }
1983
+ deleteFile({
1984
+ workspace,
1985
+ region,
1986
+ database,
1987
+ branch,
1988
+ table,
1989
+ record,
1990
+ column
1991
+ }) {
1992
+ return operationsByTag.files.deleteFile({
1993
+ pathParams: {
1994
+ workspace,
1995
+ region,
1996
+ dbBranchName: `${database}:${branch}`,
1997
+ tableName: table,
1998
+ recordId: record,
1999
+ columnName: column
2000
+ },
2001
+ ...this.extraProps
2002
+ });
2003
+ }
2004
+ fileAccess({
2005
+ workspace,
2006
+ region,
2007
+ fileId,
2008
+ verify
2009
+ }) {
2010
+ return operationsByTag.files.fileAccess({
2011
+ pathParams: {
2012
+ workspace,
2013
+ region,
2014
+ fileId
2015
+ },
2016
+ queryParams: { verify },
2017
+ ...this.extraProps
2018
+ });
2019
+ }
2020
+ }
1499
2021
  class SearchAndFilterApi {
1500
2022
  constructor(extraProps) {
1501
2023
  this.extraProps = extraProps;
@@ -1555,6 +2077,38 @@ class SearchAndFilterApi {
1555
2077
  ...this.extraProps
1556
2078
  });
1557
2079
  }
2080
+ vectorSearchTable({
2081
+ workspace,
2082
+ region,
2083
+ database,
2084
+ branch,
2085
+ table,
2086
+ queryVector,
2087
+ column,
2088
+ similarityFunction,
2089
+ size,
2090
+ filter
2091
+ }) {
2092
+ return operationsByTag.searchAndFilter.vectorSearchTable({
2093
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2094
+ body: { queryVector, column, similarityFunction, size, filter },
2095
+ ...this.extraProps
2096
+ });
2097
+ }
2098
+ askTable({
2099
+ workspace,
2100
+ region,
2101
+ database,
2102
+ branch,
2103
+ table,
2104
+ options
2105
+ }) {
2106
+ return operationsByTag.searchAndFilter.askTable({
2107
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
2108
+ body: { ...options },
2109
+ ...this.extraProps
2110
+ });
2111
+ }
1558
2112
  summarizeTable({
1559
2113
  workspace,
1560
2114
  region,
@@ -1755,11 +2309,13 @@ class MigrationsApi {
1755
2309
  region,
1756
2310
  database,
1757
2311
  branch,
1758
- schema
2312
+ schema,
2313
+ schemaOperations,
2314
+ branchOperations
1759
2315
  }) {
1760
2316
  return operationsByTag.migrations.compareBranchWithUserSchema({
1761
2317
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1762
- body: { schema },
2318
+ body: { schema, schemaOperations, branchOperations },
1763
2319
  ...this.extraProps
1764
2320
  });
1765
2321
  }
@@ -1769,11 +2325,12 @@ class MigrationsApi {
1769
2325
  database,
1770
2326
  branch,
1771
2327
  compare,
1772
- schema
2328
+ sourceBranchOperations,
2329
+ targetBranchOperations
1773
2330
  }) {
1774
2331
  return operationsByTag.migrations.compareBranchSchemas({
1775
2332
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1776
- body: { schema },
2333
+ body: { sourceBranchOperations, targetBranchOperations },
1777
2334
  ...this.extraProps
1778
2335
  });
1779
2336
  }
@@ -1816,6 +2373,19 @@ class MigrationsApi {
1816
2373
  ...this.extraProps
1817
2374
  });
1818
2375
  }
2376
+ pushBranchMigrations({
2377
+ workspace,
2378
+ region,
2379
+ database,
2380
+ branch,
2381
+ migrations
2382
+ }) {
2383
+ return operationsByTag.migrations.pushBranchMigrations({
2384
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2385
+ body: { migrations },
2386
+ ...this.extraProps
2387
+ });
2388
+ }
1819
2389
  }
1820
2390
  class DatabaseApi {
1821
2391
  constructor(extraProps) {
@@ -1867,6 +2437,46 @@ class DatabaseApi {
1867
2437
  ...this.extraProps
1868
2438
  });
1869
2439
  }
2440
+ renameDatabase({
2441
+ workspace,
2442
+ database,
2443
+ newName
2444
+ }) {
2445
+ return operationsByTag.databases.renameDatabase({
2446
+ pathParams: { workspaceId: workspace, dbName: database },
2447
+ body: { newName },
2448
+ ...this.extraProps
2449
+ });
2450
+ }
2451
+ getDatabaseGithubSettings({
2452
+ workspace,
2453
+ database
2454
+ }) {
2455
+ return operationsByTag.databases.getDatabaseGithubSettings({
2456
+ pathParams: { workspaceId: workspace, dbName: database },
2457
+ ...this.extraProps
2458
+ });
2459
+ }
2460
+ updateDatabaseGithubSettings({
2461
+ workspace,
2462
+ database,
2463
+ settings
2464
+ }) {
2465
+ return operationsByTag.databases.updateDatabaseGithubSettings({
2466
+ pathParams: { workspaceId: workspace, dbName: database },
2467
+ body: settings,
2468
+ ...this.extraProps
2469
+ });
2470
+ }
2471
+ deleteDatabaseGithubSettings({
2472
+ workspace,
2473
+ database
2474
+ }) {
2475
+ return operationsByTag.databases.deleteDatabaseGithubSettings({
2476
+ pathParams: { workspaceId: workspace, dbName: database },
2477
+ ...this.extraProps
2478
+ });
2479
+ }
1870
2480
  listRegions({ workspace }) {
1871
2481
  return operationsByTag.databases.listRegions({
1872
2482
  pathParams: { workspaceId: workspace },
@@ -1876,22 +2486,14 @@ class DatabaseApi {
1876
2486
  }
1877
2487
 
1878
2488
  class XataApiPlugin {
1879
- async build(options) {
1880
- const { fetchImpl, apiKey } = await options.getFetchProps();
1881
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2489
+ build(options) {
2490
+ return new XataApiClient(options);
1882
2491
  }
1883
2492
  }
1884
2493
 
1885
2494
  class XataPlugin {
1886
2495
  }
1887
2496
 
1888
- function generateUUID() {
1889
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1890
- const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1891
- return v.toString(16);
1892
- });
1893
- }
1894
-
1895
2497
  function cleanFilter(filter) {
1896
2498
  if (!filter)
1897
2499
  return void 0;
@@ -1925,18 +2527,46 @@ class Page {
1925
2527
  this.meta = meta;
1926
2528
  this.records = new RecordArray(this, records);
1927
2529
  }
2530
+ /**
2531
+ * Retrieves the next page of results.
2532
+ * @param size Maximum number of results to be retrieved.
2533
+ * @param offset Number of results to skip when retrieving the results.
2534
+ * @returns The next page or results.
2535
+ */
1928
2536
  async nextPage(size, offset) {
1929
2537
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
1930
2538
  }
2539
+ /**
2540
+ * Retrieves the previous page of results.
2541
+ * @param size Maximum number of results to be retrieved.
2542
+ * @param offset Number of results to skip when retrieving the results.
2543
+ * @returns The previous page or results.
2544
+ */
1931
2545
  async previousPage(size, offset) {
1932
2546
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1933
2547
  }
2548
+ /**
2549
+ * Retrieves the start page of results.
2550
+ * @param size Maximum number of results to be retrieved.
2551
+ * @param offset Number of results to skip when retrieving the results.
2552
+ * @returns The start page or results.
2553
+ */
1934
2554
  async startPage(size, offset) {
1935
2555
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1936
2556
  }
2557
+ /**
2558
+ * Retrieves the end page of results.
2559
+ * @param size Maximum number of results to be retrieved.
2560
+ * @param offset Number of results to skip when retrieving the results.
2561
+ * @returns The end page or results.
2562
+ */
1937
2563
  async endPage(size, offset) {
1938
2564
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1939
2565
  }
2566
+ /**
2567
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
2568
+ * @returns Whether or not there will be additional results in the next page of results.
2569
+ */
1940
2570
  hasNextPage() {
1941
2571
  return this.meta.page.more;
1942
2572
  }
@@ -1968,25 +2598,54 @@ const _RecordArray = class extends Array {
1968
2598
  toArray() {
1969
2599
  return new Array(...this);
1970
2600
  }
2601
+ toSerializable() {
2602
+ return JSON.parse(this.toString());
2603
+ }
2604
+ toString() {
2605
+ return JSON.stringify(this.toArray());
2606
+ }
1971
2607
  map(callbackfn, thisArg) {
1972
2608
  return this.toArray().map(callbackfn, thisArg);
1973
2609
  }
2610
+ /**
2611
+ * Retrieve next page of records
2612
+ *
2613
+ * @returns A new array of objects
2614
+ */
1974
2615
  async nextPage(size, offset) {
1975
2616
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1976
2617
  return new _RecordArray(newPage);
1977
2618
  }
2619
+ /**
2620
+ * Retrieve previous page of records
2621
+ *
2622
+ * @returns A new array of objects
2623
+ */
1978
2624
  async previousPage(size, offset) {
1979
2625
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1980
2626
  return new _RecordArray(newPage);
1981
2627
  }
2628
+ /**
2629
+ * Retrieve start page of records
2630
+ *
2631
+ * @returns A new array of objects
2632
+ */
1982
2633
  async startPage(size, offset) {
1983
2634
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1984
2635
  return new _RecordArray(newPage);
1985
2636
  }
2637
+ /**
2638
+ * Retrieve end page of records
2639
+ *
2640
+ * @returns A new array of objects
2641
+ */
1986
2642
  async endPage(size, offset) {
1987
2643
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1988
2644
  return new _RecordArray(newPage);
1989
2645
  }
2646
+ /**
2647
+ * @returns Boolean indicating if there is a next page
2648
+ */
1990
2649
  hasNextPage() {
1991
2650
  return __privateGet$6(this, _page).meta.page.more;
1992
2651
  }
@@ -2023,7 +2682,8 @@ const _Query = class {
2023
2682
  __privateAdd$5(this, _table$1, void 0);
2024
2683
  __privateAdd$5(this, _repository, void 0);
2025
2684
  __privateAdd$5(this, _data, { filter: {} });
2026
- this.meta = { page: { cursor: "start", more: true } };
2685
+ // Implements pagination
2686
+ this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
2027
2687
  this.records = new RecordArray(this, []);
2028
2688
  __privateSet$5(this, _table$1, table);
2029
2689
  if (repository) {
@@ -2039,6 +2699,7 @@ const _Query = class {
2039
2699
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
2040
2700
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
2041
2701
  __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2702
+ __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
2042
2703
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
2043
2704
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2044
2705
  __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
@@ -2059,18 +2720,38 @@ const _Query = class {
2059
2720
  const key = JSON.stringify({ columns, filter, sort, pagination });
2060
2721
  return toBase64(key);
2061
2722
  }
2723
+ /**
2724
+ * Builds a new query object representing a logical OR between the given subqueries.
2725
+ * @param queries An array of subqueries.
2726
+ * @returns A new Query object.
2727
+ */
2062
2728
  any(...queries) {
2063
2729
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2064
2730
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2065
2731
  }
2732
+ /**
2733
+ * Builds a new query object representing a logical AND between the given subqueries.
2734
+ * @param queries An array of subqueries.
2735
+ * @returns A new Query object.
2736
+ */
2066
2737
  all(...queries) {
2067
2738
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2068
2739
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2069
2740
  }
2741
+ /**
2742
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
2743
+ * @param queries An array of subqueries.
2744
+ * @returns A new Query object.
2745
+ */
2070
2746
  not(...queries) {
2071
2747
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2072
2748
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2073
2749
  }
2750
+ /**
2751
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
2752
+ * @param queries An array of subqueries.
2753
+ * @returns A new Query object.
2754
+ */
2074
2755
  none(...queries) {
2075
2756
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2076
2757
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2093,6 +2774,11 @@ const _Query = class {
2093
2774
  const sort = [...originalSort, { column, direction }];
2094
2775
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2095
2776
  }
2777
+ /**
2778
+ * Builds a new query specifying the set of columns to be returned in the query response.
2779
+ * @param columns Array of column names to be returned by the query.
2780
+ * @returns A new Query object.
2781
+ */
2096
2782
  select(columns) {
2097
2783
  return new _Query(
2098
2784
  __privateGet$5(this, _repository),
@@ -2105,6 +2791,12 @@ const _Query = class {
2105
2791
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2106
2792
  return __privateGet$5(this, _repository).query(query);
2107
2793
  }
2794
+ /**
2795
+ * Get results in an iterator
2796
+ *
2797
+ * @async
2798
+ * @returns Async interable of results
2799
+ */
2108
2800
  async *[Symbol.asyncIterator]() {
2109
2801
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2110
2802
  yield record;
@@ -2165,21 +2857,49 @@ const _Query = class {
2165
2857
  );
2166
2858
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2167
2859
  }
2860
+ /**
2861
+ * Builds a new query object adding a cache TTL in milliseconds.
2862
+ * @param ttl The cache TTL in milliseconds.
2863
+ * @returns A new Query object.
2864
+ */
2168
2865
  cache(ttl) {
2169
2866
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2170
2867
  }
2868
+ /**
2869
+ * Retrieve next page of records
2870
+ *
2871
+ * @returns A new page object.
2872
+ */
2171
2873
  nextPage(size, offset) {
2172
2874
  return this.startPage(size, offset);
2173
2875
  }
2876
+ /**
2877
+ * Retrieve previous page of records
2878
+ *
2879
+ * @returns A new page object
2880
+ */
2174
2881
  previousPage(size, offset) {
2175
2882
  return this.startPage(size, offset);
2176
2883
  }
2884
+ /**
2885
+ * Retrieve start page of records
2886
+ *
2887
+ * @returns A new page object
2888
+ */
2177
2889
  startPage(size, offset) {
2178
2890
  return this.getPaginated({ pagination: { size, offset } });
2179
2891
  }
2892
+ /**
2893
+ * Retrieve last page of records
2894
+ *
2895
+ * @returns A new page object
2896
+ */
2180
2897
  endPage(size, offset) {
2181
2898
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2182
2899
  }
2900
+ /**
2901
+ * @returns Boolean indicating if there is a next page
2902
+ */
2183
2903
  hasNextPage() {
2184
2904
  return this.meta.page.more;
2185
2905
  }
@@ -2219,7 +2939,11 @@ function isSortFilterString(value) {
2219
2939
  return isString(value);
2220
2940
  }
2221
2941
  function isSortFilterBase(filter) {
2222
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
2942
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
2943
+ if (key === "*")
2944
+ return value === "random";
2945
+ return value === "asc" || value === "desc";
2946
+ });
2223
2947
  }
2224
2948
  function isSortFilterObject(filter) {
2225
2949
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2292,10 +3016,7 @@ class RestRepository extends Query {
2292
3016
  __privateSet$4(this, _db, options.db);
2293
3017
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2294
3018
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2295
- __privateSet$4(this, _getFetchProps, async () => {
2296
- const props = await options.pluginOptions.getFetchProps();
2297
- return { ...props, sessionID: generateUUID() };
2298
- });
3019
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2299
3020
  const trace = options.pluginOptions.trace ?? defaultTrace;
2300
3021
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2301
3022
  return trace(name, fn, {
@@ -2352,7 +3073,6 @@ class RestRepository extends Query {
2352
3073
  }
2353
3074
  const id = extractId(a);
2354
3075
  if (id) {
2355
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2356
3076
  try {
2357
3077
  const response = await getRecord({
2358
3078
  pathParams: {
@@ -2363,7 +3083,7 @@ class RestRepository extends Query {
2363
3083
  recordId: id
2364
3084
  },
2365
3085
  queryParams: { columns },
2366
- ...fetchProps
3086
+ ...__privateGet$4(this, _getFetchProps).call(this)
2367
3087
  });
2368
3088
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2369
3089
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2412,13 +3132,19 @@ class RestRepository extends Query {
2412
3132
  const result = await this.read(a, columns);
2413
3133
  return result;
2414
3134
  }
2415
- if (isString(a) && isObject(b)) {
2416
- const columns = isStringArray(c) ? c : void 0;
2417
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2418
- }
2419
- if (isObject(a) && isString(a.id)) {
2420
- const columns = isStringArray(b) ? b : void 0;
2421
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3135
+ try {
3136
+ if (isString(a) && isObject(b)) {
3137
+ const columns = isStringArray(c) ? c : void 0;
3138
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3139
+ }
3140
+ if (isObject(a) && isString(a.id)) {
3141
+ const columns = isStringArray(b) ? b : void 0;
3142
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3143
+ }
3144
+ } catch (error) {
3145
+ if (error.status === 422)
3146
+ return null;
3147
+ throw error;
2422
3148
  }
2423
3149
  throw new Error("Invalid arguments for update method");
2424
3150
  });
@@ -2535,7 +3261,6 @@ class RestRepository extends Query {
2535
3261
  }
2536
3262
  async search(query, options = {}) {
2537
3263
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2538
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2539
3264
  const { records } = await searchTable({
2540
3265
  pathParams: {
2541
3266
  workspace: "{workspaceId}",
@@ -2549,9 +3274,33 @@ class RestRepository extends Query {
2549
3274
  prefix: options.prefix,
2550
3275
  highlight: options.highlight,
2551
3276
  filter: options.filter,
2552
- boosters: options.boosters
3277
+ boosters: options.boosters,
3278
+ page: options.page,
3279
+ target: options.target
3280
+ },
3281
+ ...__privateGet$4(this, _getFetchProps).call(this)
3282
+ });
3283
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3284
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
3285
+ });
3286
+ }
3287
+ async vectorSearch(column, query, options) {
3288
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
3289
+ const { records } = await vectorSearchTable({
3290
+ pathParams: {
3291
+ workspace: "{workspaceId}",
3292
+ dbBranchName: "{dbBranch}",
3293
+ region: "{region}",
3294
+ tableName: __privateGet$4(this, _table)
2553
3295
  },
2554
- ...fetchProps
3296
+ body: {
3297
+ column,
3298
+ queryVector: query,
3299
+ similarityFunction: options?.similarityFunction,
3300
+ size: options?.size,
3301
+ filter: options?.filter
3302
+ },
3303
+ ...__privateGet$4(this, _getFetchProps).call(this)
2555
3304
  });
2556
3305
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2557
3306
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -2559,7 +3308,6 @@ class RestRepository extends Query {
2559
3308
  }
2560
3309
  async aggregate(aggs, filter) {
2561
3310
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2562
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2563
3311
  const result = await aggregateTable({
2564
3312
  pathParams: {
2565
3313
  workspace: "{workspaceId}",
@@ -2568,7 +3316,7 @@ class RestRepository extends Query {
2568
3316
  tableName: __privateGet$4(this, _table)
2569
3317
  },
2570
3318
  body: { aggs, filter },
2571
- ...fetchProps
3319
+ ...__privateGet$4(this, _getFetchProps).call(this)
2572
3320
  });
2573
3321
  return result;
2574
3322
  });
@@ -2579,7 +3327,6 @@ class RestRepository extends Query {
2579
3327
  if (cacheQuery)
2580
3328
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2581
3329
  const data = query.getQueryOptions();
2582
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2583
3330
  const { meta, records: objects } = await queryTable({
2584
3331
  pathParams: {
2585
3332
  workspace: "{workspaceId}",
@@ -2591,10 +3338,11 @@ class RestRepository extends Query {
2591
3338
  filter: cleanFilter(data.filter),
2592
3339
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2593
3340
  page: data.pagination,
2594
- columns: data.columns ?? ["*"]
3341
+ columns: data.columns ?? ["*"],
3342
+ consistency: data.consistency
2595
3343
  },
2596
3344
  fetchOptions: data.fetchOptions,
2597
- ...fetchProps
3345
+ ...__privateGet$4(this, _getFetchProps).call(this)
2598
3346
  });
2599
3347
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2600
3348
  const records = objects.map(
@@ -2607,7 +3355,6 @@ class RestRepository extends Query {
2607
3355
  async summarizeTable(query, summaries, summariesFilter) {
2608
3356
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2609
3357
  const data = query.getQueryOptions();
2610
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2611
3358
  const result = await summarizeTable({
2612
3359
  pathParams: {
2613
3360
  workspace: "{workspaceId}",
@@ -2619,15 +3366,44 @@ class RestRepository extends Query {
2619
3366
  filter: cleanFilter(data.filter),
2620
3367
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2621
3368
  columns: data.columns,
3369
+ consistency: data.consistency,
2622
3370
  page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2623
3371
  summaries,
2624
3372
  summariesFilter
2625
3373
  },
2626
- ...fetchProps
3374
+ ...__privateGet$4(this, _getFetchProps).call(this)
2627
3375
  });
2628
3376
  return result;
2629
3377
  });
2630
3378
  }
3379
+ ask(question, options) {
3380
+ const params = {
3381
+ pathParams: {
3382
+ workspace: "{workspaceId}",
3383
+ dbBranchName: "{dbBranch}",
3384
+ region: "{region}",
3385
+ tableName: __privateGet$4(this, _table)
3386
+ },
3387
+ body: {
3388
+ question,
3389
+ ...options
3390
+ },
3391
+ ...__privateGet$4(this, _getFetchProps).call(this)
3392
+ };
3393
+ if (options?.onMessage) {
3394
+ fetchSSERequest({
3395
+ endpoint: "dataPlane",
3396
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
3397
+ method: "POST",
3398
+ onMessage: (message) => {
3399
+ options.onMessage?.({ answer: message.text, records: message.records });
3400
+ },
3401
+ ...params
3402
+ });
3403
+ } else {
3404
+ return askTable(params);
3405
+ }
3406
+ }
2631
3407
  }
2632
3408
  _table = new WeakMap();
2633
3409
  _getFetchProps = new WeakMap();
@@ -2637,7 +3413,6 @@ _schemaTables$2 = new WeakMap();
2637
3413
  _trace = new WeakMap();
2638
3414
  _insertRecordWithoutId = new WeakSet();
2639
3415
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2640
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2641
3416
  const record = transformObjectLinks(object);
2642
3417
  const response = await insertRecord({
2643
3418
  pathParams: {
@@ -2648,14 +3423,13 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2648
3423
  },
2649
3424
  queryParams: { columns },
2650
3425
  body: record,
2651
- ...fetchProps
3426
+ ...__privateGet$4(this, _getFetchProps).call(this)
2652
3427
  });
2653
3428
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2654
3429
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2655
3430
  };
2656
3431
  _insertRecordWithId = new WeakSet();
2657
3432
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2658
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2659
3433
  const record = transformObjectLinks(object);
2660
3434
  const response = await insertRecordWithID({
2661
3435
  pathParams: {
@@ -2667,14 +3441,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2667
3441
  },
2668
3442
  body: record,
2669
3443
  queryParams: { createOnly, columns, ifVersion },
2670
- ...fetchProps
3444
+ ...__privateGet$4(this, _getFetchProps).call(this)
2671
3445
  });
2672
3446
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2673
3447
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2674
3448
  };
2675
3449
  _insertRecords = new WeakSet();
2676
3450
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2677
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2678
3451
  const chunkedOperations = chunk(
2679
3452
  objects.map((object) => ({
2680
3453
  insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
@@ -2690,7 +3463,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2690
3463
  region: "{region}"
2691
3464
  },
2692
3465
  body: { operations },
2693
- ...fetchProps
3466
+ ...__privateGet$4(this, _getFetchProps).call(this)
2694
3467
  });
2695
3468
  for (const result of results) {
2696
3469
  if (result.operation === "insert") {
@@ -2704,7 +3477,6 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2704
3477
  };
2705
3478
  _updateRecordWithID = new WeakSet();
2706
3479
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2707
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2708
3480
  const { id: _id, ...record } = transformObjectLinks(object);
2709
3481
  try {
2710
3482
  const response = await updateRecordWithID({
@@ -2717,7 +3489,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2717
3489
  },
2718
3490
  queryParams: { columns, ifVersion },
2719
3491
  body: record,
2720
- ...fetchProps
3492
+ ...__privateGet$4(this, _getFetchProps).call(this)
2721
3493
  });
2722
3494
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2723
3495
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2730,7 +3502,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2730
3502
  };
2731
3503
  _updateRecords = new WeakSet();
2732
3504
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2733
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2734
3505
  const chunkedOperations = chunk(
2735
3506
  objects.map(({ id, ...object }) => ({
2736
3507
  update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
@@ -2746,7 +3517,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2746
3517
  region: "{region}"
2747
3518
  },
2748
3519
  body: { operations },
2749
- ...fetchProps
3520
+ ...__privateGet$4(this, _getFetchProps).call(this)
2750
3521
  });
2751
3522
  for (const result of results) {
2752
3523
  if (result.operation === "update") {
@@ -2760,7 +3531,6 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2760
3531
  };
2761
3532
  _upsertRecordWithID = new WeakSet();
2762
3533
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2763
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2764
3534
  const response = await upsertRecordWithID({
2765
3535
  pathParams: {
2766
3536
  workspace: "{workspaceId}",
@@ -2771,14 +3541,13 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2771
3541
  },
2772
3542
  queryParams: { columns, ifVersion },
2773
3543
  body: object,
2774
- ...fetchProps
3544
+ ...__privateGet$4(this, _getFetchProps).call(this)
2775
3545
  });
2776
3546
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2777
3547
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2778
3548
  };
2779
3549
  _deleteRecord = new WeakSet();
2780
3550
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2781
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2782
3551
  try {
2783
3552
  const response = await deleteRecord({
2784
3553
  pathParams: {
@@ -2789,7 +3558,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2789
3558
  recordId
2790
3559
  },
2791
3560
  queryParams: { columns },
2792
- ...fetchProps
3561
+ ...__privateGet$4(this, _getFetchProps).call(this)
2793
3562
  });
2794
3563
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2795
3564
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2802,7 +3571,6 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2802
3571
  };
2803
3572
  _deleteRecords = new WeakSet();
2804
3573
  deleteRecords_fn = async function(recordIds) {
2805
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2806
3574
  const chunkedOperations = chunk(
2807
3575
  recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2808
3576
  BULK_OPERATION_MAX_SIZE
@@ -2815,21 +3583,22 @@ deleteRecords_fn = async function(recordIds) {
2815
3583
  region: "{region}"
2816
3584
  },
2817
3585
  body: { operations },
2818
- ...fetchProps
3586
+ ...__privateGet$4(this, _getFetchProps).call(this)
2819
3587
  });
2820
3588
  }
2821
3589
  };
2822
3590
  _setCacheQuery = new WeakSet();
2823
3591
  setCacheQuery_fn = async function(query, meta, records) {
2824
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
3592
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
2825
3593
  };
2826
3594
  _getCacheQuery = new WeakSet();
2827
3595
  getCacheQuery_fn = async function(query) {
2828
3596
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2829
- const result = await __privateGet$4(this, _cache).get(key);
3597
+ const result = await __privateGet$4(this, _cache)?.get(key);
2830
3598
  if (!result)
2831
3599
  return null;
2832
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
3600
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
3601
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2833
3602
  if (ttl < 0)
2834
3603
  return null;
2835
3604
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2839,10 +3608,9 @@ _getSchemaTables$1 = new WeakSet();
2839
3608
  getSchemaTables_fn$1 = async function() {
2840
3609
  if (__privateGet$4(this, _schemaTables$2))
2841
3610
  return __privateGet$4(this, _schemaTables$2);
2842
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2843
3611
  const { schema } = await getBranchDetails({
2844
3612
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2845
- ...fetchProps
3613
+ ...__privateGet$4(this, _getFetchProps).call(this)
2846
3614
  });
2847
3615
  __privateSet$4(this, _schemaTables$2, schema.tables);
2848
3616
  return schema.tables;
@@ -2855,23 +3623,23 @@ const transformObjectLinks = (object) => {
2855
3623
  }, {});
2856
3624
  };
2857
3625
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2858
- const result = {};
3626
+ const data = {};
2859
3627
  const { xata, ...rest } = object ?? {};
2860
- Object.assign(result, rest);
3628
+ Object.assign(data, rest);
2861
3629
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2862
3630
  if (!columns)
2863
3631
  console.error(`Table ${table} not found in schema`);
2864
3632
  for (const column of columns ?? []) {
2865
3633
  if (!isValidColumn(selectedColumns, column))
2866
3634
  continue;
2867
- const value = result[column.name];
3635
+ const value = data[column.name];
2868
3636
  switch (column.type) {
2869
3637
  case "datetime": {
2870
3638
  const date = value !== void 0 ? new Date(value) : null;
2871
3639
  if (date !== null && isNaN(date.getTime())) {
2872
3640
  console.error(`Failed to parse date ${value} for field ${column.name}`);
2873
3641
  } else {
2874
- result[column.name] = date;
3642
+ data[column.name] = date;
2875
3643
  }
2876
3644
  break;
2877
3645
  }
@@ -2890,44 +3658,54 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2890
3658
  }
2891
3659
  return acc;
2892
3660
  }, []);
2893
- result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
3661
+ data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2894
3662
  } else {
2895
- result[column.name] = null;
3663
+ data[column.name] = null;
2896
3664
  }
2897
3665
  break;
2898
3666
  }
2899
3667
  default:
2900
- result[column.name] = value ?? null;
3668
+ data[column.name] = value ?? null;
2901
3669
  if (column.notNull === true && value === null) {
2902
3670
  console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2903
3671
  }
2904
3672
  break;
2905
3673
  }
2906
3674
  }
2907
- result.read = function(columns2) {
2908
- return db[table].read(result["id"], columns2);
3675
+ const record = { ...data };
3676
+ const serializable = { xata, ...transformObjectLinks(data) };
3677
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
3678
+ record.read = function(columns2) {
3679
+ return db[table].read(record["id"], columns2);
2909
3680
  };
2910
- result.update = function(data, b, c) {
3681
+ record.update = function(data2, b, c) {
2911
3682
  const columns2 = isStringArray(b) ? b : ["*"];
2912
3683
  const ifVersion = parseIfVersion(b, c);
2913
- return db[table].update(result["id"], data, columns2, { ifVersion });
3684
+ return db[table].update(record["id"], data2, columns2, { ifVersion });
2914
3685
  };
2915
- result.replace = function(data, b, c) {
3686
+ record.replace = function(data2, b, c) {
2916
3687
  const columns2 = isStringArray(b) ? b : ["*"];
2917
3688
  const ifVersion = parseIfVersion(b, c);
2918
- return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
3689
+ return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
3690
+ };
3691
+ record.delete = function() {
3692
+ return db[table].delete(record["id"]);
2919
3693
  };
2920
- result.delete = function() {
2921
- return db[table].delete(result["id"]);
3694
+ record.xata = metadata;
3695
+ record.getMetadata = function() {
3696
+ return metadata;
2922
3697
  };
2923
- result.getMetadata = function() {
2924
- return xata;
3698
+ record.toSerializable = function() {
3699
+ return JSON.parse(JSON.stringify(serializable));
2925
3700
  };
2926
- for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
2927
- Object.defineProperty(result, prop, { enumerable: false });
3701
+ record.toString = function() {
3702
+ return JSON.stringify(transformObjectLinks(serializable));
3703
+ };
3704
+ for (const prop of ["read", "update", "replace", "delete", "xata", "getMetadata", "toSerializable", "toString"]) {
3705
+ Object.defineProperty(record, prop, { enumerable: false });
2928
3706
  }
2929
- Object.freeze(result);
2930
- return result;
3707
+ Object.freeze(record);
3708
+ return record;
2931
3709
  };
2932
3710
  function extractId(value) {
2933
3711
  if (isString(value))
@@ -3111,19 +3889,19 @@ class SearchPlugin extends XataPlugin {
3111
3889
  __privateAdd$1(this, _schemaTables, void 0);
3112
3890
  __privateSet$1(this, _schemaTables, schemaTables);
3113
3891
  }
3114
- build({ getFetchProps }) {
3892
+ build(pluginOptions) {
3115
3893
  return {
3116
3894
  all: async (query, options = {}) => {
3117
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3118
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3895
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3896
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3119
3897
  return records.map((record) => {
3120
3898
  const { table = "orphan" } = record.xata;
3121
3899
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3122
3900
  });
3123
3901
  },
3124
3902
  byTable: async (query, options = {}) => {
3125
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3126
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3903
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3904
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3127
3905
  return records.reduce((acc, record) => {
3128
3906
  const { table = "orphan" } = record.xata;
3129
3907
  const items = acc[table] ?? [];
@@ -3136,38 +3914,36 @@ class SearchPlugin extends XataPlugin {
3136
3914
  }
3137
3915
  _schemaTables = new WeakMap();
3138
3916
  _search = new WeakSet();
3139
- search_fn = async function(query, options, getFetchProps) {
3140
- const fetchProps = await getFetchProps();
3141
- const { tables, fuzziness, highlight, prefix } = options ?? {};
3917
+ search_fn = async function(query, options, pluginOptions) {
3918
+ const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3142
3919
  const { records } = await searchBranch({
3143
3920
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3144
- body: { tables, query, fuzziness, prefix, highlight },
3145
- ...fetchProps
3921
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3922
+ body: { tables, query, fuzziness, prefix, highlight, page },
3923
+ ...pluginOptions
3146
3924
  });
3147
3925
  return records;
3148
3926
  };
3149
3927
  _getSchemaTables = new WeakSet();
3150
- getSchemaTables_fn = async function(getFetchProps) {
3928
+ getSchemaTables_fn = async function(pluginOptions) {
3151
3929
  if (__privateGet$1(this, _schemaTables))
3152
3930
  return __privateGet$1(this, _schemaTables);
3153
- const fetchProps = await getFetchProps();
3154
3931
  const { schema } = await getBranchDetails({
3155
3932
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3156
- ...fetchProps
3933
+ ...pluginOptions
3157
3934
  });
3158
3935
  __privateSet$1(this, _schemaTables, schema.tables);
3159
3936
  return schema.tables;
3160
3937
  };
3161
3938
 
3162
3939
  class TransactionPlugin extends XataPlugin {
3163
- build({ getFetchProps }) {
3940
+ build(pluginOptions) {
3164
3941
  return {
3165
3942
  run: async (operations) => {
3166
- const fetchProps = await getFetchProps();
3167
3943
  const response = await branchTransaction({
3168
3944
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3169
3945
  body: { operations },
3170
- ...fetchProps
3946
+ ...pluginOptions
3171
3947
  });
3172
3948
  return response;
3173
3949
  }
@@ -3175,93 +3951,6 @@ class TransactionPlugin extends XataPlugin {
3175
3951
  }
3176
3952
  }
3177
3953
 
3178
- const isBranchStrategyBuilder = (strategy) => {
3179
- return typeof strategy === "function";
3180
- };
3181
-
3182
- async function getCurrentBranchName(options) {
3183
- const { branch, envBranch } = getEnvironment();
3184
- if (branch) {
3185
- const details = await getDatabaseBranch(branch, options);
3186
- if (details)
3187
- return branch;
3188
- console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
3189
- }
3190
- const gitBranch = envBranch || await getGitBranch();
3191
- return resolveXataBranch(gitBranch, options);
3192
- }
3193
- async function getCurrentBranchDetails(options) {
3194
- const branch = await getCurrentBranchName(options);
3195
- return getDatabaseBranch(branch, options);
3196
- }
3197
- async function resolveXataBranch(gitBranch, options) {
3198
- const databaseURL = options?.databaseURL || getDatabaseURL();
3199
- const apiKey = options?.apiKey || getAPIKey();
3200
- if (!databaseURL)
3201
- throw new Error(
3202
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3203
- );
3204
- if (!apiKey)
3205
- throw new Error(
3206
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3207
- );
3208
- const [protocol, , host, , dbName] = databaseURL.split("/");
3209
- const urlParts = parseWorkspacesUrlParts(host);
3210
- if (!urlParts)
3211
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3212
- const { workspace, region } = urlParts;
3213
- const { fallbackBranch } = getEnvironment();
3214
- const { branch } = await resolveBranch({
3215
- apiKey,
3216
- apiUrl: databaseURL,
3217
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3218
- workspacesApiUrl: `${protocol}//${host}`,
3219
- pathParams: { dbName, workspace, region },
3220
- queryParams: { gitBranch, fallbackBranch },
3221
- trace: defaultTrace
3222
- });
3223
- return branch;
3224
- }
3225
- async function getDatabaseBranch(branch, options) {
3226
- const databaseURL = options?.databaseURL || getDatabaseURL();
3227
- const apiKey = options?.apiKey || getAPIKey();
3228
- if (!databaseURL)
3229
- throw new Error(
3230
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3231
- );
3232
- if (!apiKey)
3233
- throw new Error(
3234
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3235
- );
3236
- const [protocol, , host, , database] = databaseURL.split("/");
3237
- const urlParts = parseWorkspacesUrlParts(host);
3238
- if (!urlParts)
3239
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3240
- const { workspace, region } = urlParts;
3241
- try {
3242
- return await getBranchDetails({
3243
- apiKey,
3244
- apiUrl: databaseURL,
3245
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3246
- workspacesApiUrl: `${protocol}//${host}`,
3247
- pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3248
- trace: defaultTrace
3249
- });
3250
- } catch (err) {
3251
- if (isObject(err) && err.status === 404)
3252
- return null;
3253
- throw err;
3254
- }
3255
- }
3256
- function getDatabaseURL() {
3257
- try {
3258
- const { databaseURL } = getEnvironment();
3259
- return databaseURL;
3260
- } catch (err) {
3261
- return void 0;
3262
- }
3263
- }
3264
-
3265
3954
  var __accessCheck = (obj, member, msg) => {
3266
3955
  if (!member.has(obj))
3267
3956
  throw TypeError("Cannot " + msg);
@@ -3285,20 +3974,18 @@ var __privateMethod = (obj, member, method) => {
3285
3974
  return method;
3286
3975
  };
3287
3976
  const buildClient = (plugins) => {
3288
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3977
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3289
3978
  return _a = class {
3290
3979
  constructor(options = {}, schemaTables) {
3291
3980
  __privateAdd(this, _parseOptions);
3292
3981
  __privateAdd(this, _getFetchProps);
3293
- __privateAdd(this, _evaluateBranch);
3294
- __privateAdd(this, _branch, void 0);
3295
3982
  __privateAdd(this, _options, void 0);
3296
3983
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3297
3984
  __privateSet(this, _options, safeOptions);
3298
3985
  const pluginOptions = {
3299
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3986
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3300
3987
  cache: safeOptions.cache,
3301
- trace: safeOptions.trace
3988
+ host: safeOptions.host
3302
3989
  };
3303
3990
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3304
3991
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -3309,24 +3996,17 @@ const buildClient = (plugins) => {
3309
3996
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3310
3997
  if (namespace === void 0)
3311
3998
  continue;
3312
- const result = namespace.build(pluginOptions);
3313
- if (result instanceof Promise) {
3314
- void result.then((namespace2) => {
3315
- this[key] = namespace2;
3316
- });
3317
- } else {
3318
- this[key] = result;
3319
- }
3999
+ this[key] = namespace.build(pluginOptions);
3320
4000
  }
3321
4001
  }
3322
4002
  async getConfig() {
3323
4003
  const databaseURL = __privateGet(this, _options).databaseURL;
3324
- const branch = await __privateGet(this, _options).branch();
4004
+ const branch = __privateGet(this, _options).branch;
3325
4005
  return { databaseURL, branch };
3326
4006
  }
3327
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
4007
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3328
4008
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3329
- const isBrowser = typeof window !== "undefined";
4009
+ const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3330
4010
  if (isBrowser && !enableBrowser) {
3331
4011
  throw new Error(
3332
4012
  "You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
@@ -3337,46 +4017,73 @@ const buildClient = (plugins) => {
3337
4017
  const apiKey = options?.apiKey || getAPIKey();
3338
4018
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3339
4019
  const trace = options?.trace ?? defaultTrace;
3340
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
4020
+ const clientName = options?.clientName;
4021
+ const host = options?.host ?? "production";
4022
+ const xataAgentExtra = options?.xataAgentExtra;
3341
4023
  if (!apiKey) {
3342
4024
  throw new Error("Option apiKey is required");
3343
4025
  }
3344
4026
  if (!databaseURL) {
3345
4027
  throw new Error("Option databaseURL is required");
3346
4028
  }
3347
- return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
3348
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
3349
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3350
- if (!branchValue)
3351
- throw new Error("Unable to resolve branch value");
4029
+ const envBranch = getBranch();
4030
+ const previewBranch = getPreviewBranch();
4031
+ const branch = options?.branch || previewBranch || envBranch || "main";
4032
+ if (!!previewBranch && branch !== previewBranch) {
4033
+ console.warn(
4034
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
4035
+ );
4036
+ } else if (!!envBranch && branch !== envBranch) {
4037
+ console.warn(
4038
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4039
+ );
4040
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
4041
+ console.warn(
4042
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
4043
+ );
4044
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
4045
+ console.warn(
4046
+ `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.`
4047
+ );
4048
+ }
3352
4049
  return {
3353
- fetchImpl: fetch,
4050
+ fetch,
4051
+ databaseURL,
4052
+ apiKey,
4053
+ branch,
4054
+ cache,
4055
+ trace,
4056
+ host,
4057
+ clientID: generateUUID(),
4058
+ enableBrowser,
4059
+ clientName,
4060
+ xataAgentExtra
4061
+ };
4062
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
4063
+ fetch,
4064
+ apiKey,
4065
+ databaseURL,
4066
+ branch,
4067
+ trace,
4068
+ clientID,
4069
+ clientName,
4070
+ xataAgentExtra
4071
+ }) {
4072
+ return {
4073
+ fetch,
3354
4074
  apiKey,
3355
4075
  apiUrl: "",
4076
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3356
4077
  workspacesApiUrl: (path, params) => {
3357
4078
  const hasBranch = params.dbBranchName ?? params.branch;
3358
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
4079
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3359
4080
  return databaseURL + newPath;
3360
4081
  },
3361
4082
  trace,
3362
- clientID
4083
+ clientID,
4084
+ clientName,
4085
+ xataAgentExtra
3363
4086
  };
3364
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3365
- if (__privateGet(this, _branch))
3366
- return __privateGet(this, _branch);
3367
- if (param === void 0)
3368
- return void 0;
3369
- const strategies = Array.isArray(param) ? [...param] : [param];
3370
- const evaluateBranch = async (strategy) => {
3371
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3372
- };
3373
- for await (const strategy of strategies) {
3374
- const branch = await evaluateBranch(strategy);
3375
- if (branch) {
3376
- __privateSet(this, _branch, branch);
3377
- return branch;
3378
- }
3379
- }
3380
4087
  }, _a;
3381
4088
  };
3382
4089
  class BaseClient extends buildClient() {
@@ -3450,7 +4157,7 @@ const deserialize = (json) => {
3450
4157
  };
3451
4158
 
3452
4159
  function buildWorkerRunner(config) {
3453
- return function xataWorker(name, _worker) {
4160
+ return function xataWorker(name, worker) {
3454
4161
  return async (...args) => {
3455
4162
  const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
3456
4163
  const result = await fetch(url, {
@@ -3471,5 +4178,5 @@ class XataError extends Error {
3471
4178
  }
3472
4179
  }
3473
4180
 
3474
- export { BaseClient, 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, dEPRECATEDcreateDatabase, dEPRECATEDdeleteDatabase, dEPRECATEDgetDatabaseList, dEPRECATEDgetDatabaseMetadata, dEPRECATEDupdateDatabaseMetadata, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, 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, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
4181
+ 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, askTable, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, 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 };
3475
4182
  //# sourceMappingURL=index.mjs.map