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