@xata.io/client 0.0.0-alpha.vecd13ea → 0.0.0-alpha.vecd237a

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
  }
@@ -38,6 +39,21 @@ function isString(value) {
38
39
  function isStringArray(value) {
39
40
  return isDefined(value) && Array.isArray(value) && value.every(isString);
40
41
  }
42
+ function isNumber(value) {
43
+ return isDefined(value) && typeof value === "number";
44
+ }
45
+ function parseNumber(value) {
46
+ if (isNumber(value)) {
47
+ return value;
48
+ }
49
+ if (isString(value)) {
50
+ const parsed = Number(value);
51
+ if (!Number.isNaN(parsed)) {
52
+ return parsed;
53
+ }
54
+ }
55
+ return void 0;
56
+ }
41
57
  function toBase64(value) {
42
58
  try {
43
59
  return btoa(value);
@@ -46,16 +62,39 @@ function toBase64(value) {
46
62
  return buf.from(value).toString("base64");
47
63
  }
48
64
  }
65
+ function deepMerge(a, b) {
66
+ const result = { ...a };
67
+ for (const [key, value] of Object.entries(b)) {
68
+ if (isObject(value) && isObject(result[key])) {
69
+ result[key] = deepMerge(result[key], value);
70
+ } else {
71
+ result[key] = value;
72
+ }
73
+ }
74
+ return result;
75
+ }
76
+ function chunk(array, chunkSize) {
77
+ const result = [];
78
+ for (let i = 0; i < array.length; i += chunkSize) {
79
+ result.push(array.slice(i, i + chunkSize));
80
+ }
81
+ return result;
82
+ }
83
+ async function timeout(ms) {
84
+ return new Promise((resolve) => setTimeout(resolve, ms));
85
+ }
49
86
 
50
87
  function getEnvironment() {
51
88
  try {
52
- if (isObject(process) && isObject(process.env)) {
89
+ if (isDefined(process) && isDefined(process.env)) {
53
90
  return {
54
91
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
55
92
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
56
93
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
57
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
58
- 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
59
98
  };
60
99
  }
61
100
  } catch (err) {
@@ -66,8 +105,10 @@ function getEnvironment() {
66
105
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
67
106
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
68
107
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
69
- envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
70
- 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")
71
112
  };
72
113
  }
73
114
  } catch (err) {
@@ -76,10 +117,31 @@ function getEnvironment() {
76
117
  apiKey: getGlobalApiKey(),
77
118
  databaseURL: getGlobalDatabaseURL(),
78
119
  branch: getGlobalBranch(),
79
- envBranch: void 0,
80
- fallbackBranch: getGlobalFallbackBranch()
120
+ deployPreview: void 0,
121
+ deployPreviewBranch: void 0,
122
+ vercelGitCommitRef: void 0,
123
+ vercelGitRepoOwner: void 0
81
124
  };
82
125
  }
126
+ function getEnableBrowserVariable() {
127
+ try {
128
+ if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
129
+ return process.env.XATA_ENABLE_BROWSER === "true";
130
+ }
131
+ } catch (err) {
132
+ }
133
+ try {
134
+ if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
135
+ return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
136
+ }
137
+ } catch (err) {
138
+ }
139
+ try {
140
+ return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
141
+ } catch (err) {
142
+ return void 0;
143
+ }
144
+ }
83
145
  function getGlobalApiKey() {
84
146
  try {
85
147
  return XATA_API_KEY;
@@ -101,44 +163,76 @@ function getGlobalBranch() {
101
163
  return void 0;
102
164
  }
103
165
  }
104
- function getGlobalFallbackBranch() {
166
+ function getDatabaseURL() {
105
167
  try {
106
- return XATA_FALLBACK_BRANCH;
168
+ const { databaseURL } = getEnvironment();
169
+ return databaseURL;
107
170
  } catch (err) {
108
171
  return void 0;
109
172
  }
110
173
  }
111
- async function getGitBranch() {
112
- const cmd = ["git", "branch", "--show-current"];
113
- const fullCmd = cmd.join(" ");
114
- const nodeModule = ["child", "process"].join("_");
115
- const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
174
+ function getAPIKey() {
116
175
  try {
117
- if (typeof require === "function") {
118
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
119
- }
120
- const { execSync } = await import(nodeModule);
121
- return execSync(fullCmd, execOptions).toString().trim();
176
+ const { apiKey } = getEnvironment();
177
+ return apiKey;
122
178
  } catch (err) {
179
+ return void 0;
123
180
  }
181
+ }
182
+ function getBranch() {
124
183
  try {
125
- if (isObject(Deno)) {
126
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
127
- return new TextDecoder().decode(await process2.output()).trim();
128
- }
184
+ const { branch } = getEnvironment();
185
+ return branch ?? "main";
129
186
  } catch (err) {
187
+ return void 0;
130
188
  }
131
189
  }
132
-
133
- function getAPIKey() {
190
+ function buildPreviewBranchName({ org, branch }) {
191
+ return `preview-${org}-${branch}`;
192
+ }
193
+ function getPreviewBranch() {
134
194
  try {
135
- const { apiKey } = getEnvironment();
136
- 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;
137
208
  } catch (err) {
138
209
  return void 0;
139
210
  }
140
211
  }
141
212
 
213
+ var __accessCheck$8 = (obj, member, msg) => {
214
+ if (!member.has(obj))
215
+ throw TypeError("Cannot " + msg);
216
+ };
217
+ var __privateGet$8 = (obj, member, getter) => {
218
+ __accessCheck$8(obj, member, "read from private field");
219
+ return getter ? getter.call(obj) : member.get(obj);
220
+ };
221
+ var __privateAdd$8 = (obj, member, value) => {
222
+ if (member.has(obj))
223
+ throw TypeError("Cannot add the same private member more than once");
224
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
225
+ };
226
+ var __privateSet$8 = (obj, member, value, setter) => {
227
+ __accessCheck$8(obj, member, "write to private field");
228
+ setter ? setter.call(obj, value) : member.set(obj, value);
229
+ return value;
230
+ };
231
+ var __privateMethod$4 = (obj, member, method) => {
232
+ __accessCheck$8(obj, member, "access private method");
233
+ return method;
234
+ };
235
+ var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
142
236
  function getFetchImplementation(userFetch) {
143
237
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
144
238
  const fetchImpl = userFetch ?? globalFetch;
@@ -149,8 +243,254 @@ function getFetchImplementation(userFetch) {
149
243
  }
150
244
  return fetchImpl;
151
245
  }
246
+ class ApiRequestPool {
247
+ constructor(concurrency = 10) {
248
+ __privateAdd$8(this, _enqueue);
249
+ __privateAdd$8(this, _fetch, void 0);
250
+ __privateAdd$8(this, _queue, void 0);
251
+ __privateAdd$8(this, _concurrency, void 0);
252
+ __privateSet$8(this, _queue, []);
253
+ __privateSet$8(this, _concurrency, concurrency);
254
+ this.running = 0;
255
+ this.started = 0;
256
+ }
257
+ setFetch(fetch2) {
258
+ __privateSet$8(this, _fetch, fetch2);
259
+ }
260
+ getFetch() {
261
+ if (!__privateGet$8(this, _fetch)) {
262
+ throw new Error("Fetch not set");
263
+ }
264
+ return __privateGet$8(this, _fetch);
265
+ }
266
+ request(url, options) {
267
+ const start = new Date();
268
+ const fetch2 = this.getFetch();
269
+ const runRequest = async (stalled = false) => {
270
+ const response = await fetch2(url, options);
271
+ if (response.status === 429) {
272
+ const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
273
+ await timeout(rateLimitReset * 1e3);
274
+ return await runRequest(true);
275
+ }
276
+ if (stalled) {
277
+ const stalledTime = new Date().getTime() - start.getTime();
278
+ console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
279
+ }
280
+ return response;
281
+ };
282
+ return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
283
+ return await runRequest();
284
+ });
285
+ }
286
+ }
287
+ _fetch = new WeakMap();
288
+ _queue = new WeakMap();
289
+ _concurrency = new WeakMap();
290
+ _enqueue = new WeakSet();
291
+ enqueue_fn = function(task) {
292
+ const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
293
+ this.started--;
294
+ this.running++;
295
+ }).then(() => task()).finally(() => {
296
+ this.running--;
297
+ const next = __privateGet$8(this, _queue).shift();
298
+ if (next !== void 0) {
299
+ this.started++;
300
+ next();
301
+ }
302
+ });
303
+ if (this.running + this.started < __privateGet$8(this, _concurrency)) {
304
+ const next = __privateGet$8(this, _queue).shift();
305
+ if (next !== void 0) {
306
+ this.started++;
307
+ next();
308
+ }
309
+ }
310
+ return promise;
311
+ };
312
+
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
+ }
152
492
 
153
- const VERSION = "0.0.0-alpha.vecd13ea";
493
+ const VERSION = "0.23.2";
154
494
 
155
495
  class ErrorWithCause extends Error {
156
496
  constructor(message, options) {
@@ -161,7 +501,7 @@ class FetcherError extends ErrorWithCause {
161
501
  constructor(status, data, requestId) {
162
502
  super(getMessage(data));
163
503
  this.status = status;
164
- this.errors = isBulkError(data) ? data.errors : void 0;
504
+ this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
165
505
  this.requestId = requestId;
166
506
  if (data instanceof Error) {
167
507
  this.stack = data.stack;
@@ -193,6 +533,7 @@ function getMessage(data) {
193
533
  }
194
534
  }
195
535
 
536
+ const pool = new ApiRequestPool();
196
537
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
197
538
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
198
539
  if (value === void 0 || value === null)
@@ -207,60 +548,79 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
207
548
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
208
549
  };
209
550
  function buildBaseUrl({
551
+ endpoint,
210
552
  path,
211
553
  workspacesApiUrl,
212
554
  apiUrl,
213
- pathParams
555
+ pathParams = {}
214
556
  }) {
215
- if (pathParams?.workspace === void 0)
216
- return `${apiUrl}${path}`;
217
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
218
- return url.replace("{workspaceId}", String(pathParams.workspace));
557
+ if (endpoint === "dataPlane") {
558
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
559
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
560
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
561
+ }
562
+ return `${apiUrl}${path}`;
219
563
  }
220
564
  function hostHeader(url) {
221
565
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
222
566
  const { groups } = pattern.exec(url) ?? {};
223
567
  return groups?.host ? { Host: groups.host } : {};
224
568
  }
569
+ const defaultClientID = generateUUID();
225
570
  async function fetch$1({
226
571
  url: path,
227
572
  method,
228
573
  body,
229
- headers,
574
+ headers: customHeaders,
230
575
  pathParams,
231
576
  queryParams,
232
- fetchImpl,
577
+ fetch: fetch2,
233
578
  apiKey,
579
+ endpoint,
234
580
  apiUrl,
235
581
  workspacesApiUrl,
236
582
  trace,
237
- signal
583
+ signal,
584
+ clientID,
585
+ sessionID,
586
+ clientName,
587
+ xataAgentExtra,
588
+ fetchOptions = {}
238
589
  }) {
239
- return trace(
590
+ pool.setFetch(fetch2);
591
+ return await trace(
240
592
  `${method.toUpperCase()} ${path}`,
241
593
  async ({ setAttributes }) => {
242
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
594
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
243
595
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
244
596
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
245
597
  setAttributes({
246
598
  [TraceAttributes.HTTP_URL]: url,
247
599
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
248
600
  });
249
- const response = await fetchImpl(url, {
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
+ };
617
+ const response = await pool.request(url, {
618
+ ...fetchOptions,
250
619
  method: method.toUpperCase(),
251
620
  body: body ? JSON.stringify(body) : void 0,
252
- headers: {
253
- "Content-Type": "application/json",
254
- "User-Agent": `Xata client-ts/${VERSION}`,
255
- ...headers,
256
- ...hostHeader(fullUrl),
257
- Authorization: `Bearer ${apiKey}`
258
- },
621
+ headers,
259
622
  signal
260
623
  });
261
- if (response.status === 204) {
262
- return {};
263
- }
264
624
  const { host, protocol } = parseUrl(response.url);
265
625
  const requestId = response.headers?.get("x-request-id") ?? void 0;
266
626
  setAttributes({
@@ -270,6 +630,12 @@ async function fetch$1({
270
630
  [TraceAttributes.HTTP_HOST]: host,
271
631
  [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
272
632
  });
633
+ if (response.status === 204) {
634
+ return {};
635
+ }
636
+ if (response.status === 429) {
637
+ throw new FetcherError(response.status, "Rate limit exceeded", requestId);
638
+ }
273
639
  try {
274
640
  const jsonResponse = await response.json();
275
641
  if (response.ok) {
@@ -283,6 +649,59 @@ async function fetch$1({
283
649
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
284
650
  );
285
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
+ }
286
705
  function parseUrl(url) {
287
706
  try {
288
707
  const { host, protocol } = new URL(url);
@@ -292,391 +711,375 @@ function parseUrl(url) {
292
711
  }
293
712
  }
294
713
 
295
- const getUser = (variables, signal) => fetch$1({ url: "/user", method: "get", ...variables, signal });
296
- const updateUser = (variables, signal) => fetch$1({
297
- url: "/user",
298
- method: "put",
299
- ...variables,
300
- signal
301
- });
302
- const deleteUser = (variables, signal) => fetch$1({ url: "/user", method: "delete", ...variables, signal });
303
- const getUserAPIKeys = (variables, signal) => fetch$1({
304
- url: "/user/keys",
714
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
715
+
716
+ const getBranchList = (variables, signal) => dataPlaneFetch({
717
+ url: "/dbs/{dbName}",
305
718
  method: "get",
306
719
  ...variables,
307
720
  signal
308
721
  });
309
- const createUserAPIKey = (variables, signal) => fetch$1({
310
- url: "/user/keys/{keyName}",
311
- method: "post",
722
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
723
+ url: "/db/{dbBranchName}",
724
+ method: "get",
312
725
  ...variables,
313
726
  signal
314
727
  });
315
- const deleteUserAPIKey = (variables, signal) => fetch$1({
316
- url: "/user/keys/{keyName}",
728
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
729
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
730
+ url: "/db/{dbBranchName}",
317
731
  method: "delete",
318
732
  ...variables,
319
733
  signal
320
734
  });
321
- const createWorkspace = (variables, signal) => fetch$1({
322
- url: "/workspaces",
735
+ const copyBranch = (variables, signal) => dataPlaneFetch({
736
+ url: "/db/{dbBranchName}/copy",
323
737
  method: "post",
324
738
  ...variables,
325
739
  signal
326
740
  });
327
- const getWorkspacesList = (variables, signal) => fetch$1({
328
- url: "/workspaces",
329
- method: "get",
330
- ...variables,
331
- signal
332
- });
333
- const getWorkspace = (variables, signal) => fetch$1({
334
- url: "/workspaces/{workspaceId}",
335
- method: "get",
336
- ...variables,
337
- signal
338
- });
339
- const updateWorkspace = (variables, signal) => fetch$1({
340
- url: "/workspaces/{workspaceId}",
741
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
742
+ url: "/db/{dbBranchName}/metadata",
341
743
  method: "put",
342
744
  ...variables,
343
745
  signal
344
746
  });
345
- const deleteWorkspace = (variables, signal) => fetch$1({
346
- url: "/workspaces/{workspaceId}",
347
- method: "delete",
348
- ...variables,
349
- signal
350
- });
351
- const getWorkspaceMembersList = (variables, signal) => fetch$1({
352
- url: "/workspaces/{workspaceId}/members",
747
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
748
+ url: "/db/{dbBranchName}/metadata",
353
749
  method: "get",
354
750
  ...variables,
355
751
  signal
356
752
  });
357
- const updateWorkspaceMemberRole = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
358
- const removeWorkspaceMember = (variables, signal) => fetch$1({
359
- url: "/workspaces/{workspaceId}/members/{userId}",
360
- method: "delete",
361
- ...variables,
362
- signal
363
- });
364
- const inviteWorkspaceMember = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
365
- const updateWorkspaceMemberInvite = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
366
- const cancelWorkspaceMemberInvite = (variables, signal) => fetch$1({
367
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
368
- method: "delete",
369
- ...variables,
370
- signal
371
- });
372
- const resendWorkspaceMemberInvite = (variables, signal) => fetch$1({
373
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
374
- method: "post",
375
- ...variables,
376
- signal
377
- });
378
- const acceptWorkspaceMemberInvite = (variables, signal) => fetch$1({
379
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
380
- method: "post",
753
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
754
+ url: "/db/{dbBranchName}/stats",
755
+ method: "get",
381
756
  ...variables,
382
757
  signal
383
758
  });
384
- const getDatabaseList = (variables, signal) => fetch$1({
385
- url: "/dbs",
759
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
760
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
761
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
762
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
763
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
764
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
765
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
766
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
767
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
768
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
769
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
386
770
  method: "get",
387
771
  ...variables,
388
772
  signal
389
773
  });
390
- const getBranchList = (variables, signal) => fetch$1({
391
- url: "/dbs/{dbName}",
392
- method: "get",
774
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
775
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
776
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
777
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
778
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
779
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
780
+ method: "post",
393
781
  ...variables,
394
782
  signal
395
783
  });
396
- const createDatabase = (variables, signal) => fetch$1({
397
- url: "/dbs/{dbName}",
784
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
785
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
786
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
787
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
788
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
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 });
791
+ const createTable = (variables, signal) => dataPlaneFetch({
792
+ url: "/db/{dbBranchName}/tables/{tableName}",
398
793
  method: "put",
399
794
  ...variables,
400
795
  signal
401
796
  });
402
- const deleteDatabase = (variables, signal) => fetch$1({
403
- url: "/dbs/{dbName}",
797
+ const deleteTable = (variables, signal) => dataPlaneFetch({
798
+ url: "/db/{dbBranchName}/tables/{tableName}",
404
799
  method: "delete",
405
800
  ...variables,
406
801
  signal
407
802
  });
408
- const getDatabaseMetadata = (variables, signal) => fetch$1({
409
- url: "/dbs/{dbName}/metadata",
803
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
804
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
805
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
410
806
  method: "get",
411
807
  ...variables,
412
808
  signal
413
809
  });
414
- const updateDatabaseMetadata = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
415
- const getGitBranchesMapping = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
416
- const addGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
417
- const removeGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
418
- const resolveBranch = (variables, signal) => fetch$1({
419
- url: "/dbs/{dbName}/resolveBranch",
810
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
811
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
812
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
420
813
  method: "get",
421
814
  ...variables,
422
815
  signal
423
816
  });
424
- const queryMigrationRequests = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
425
- const createMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
426
- const getMigrationRequest = (variables, signal) => fetch$1({
427
- url: "/dbs/{dbName}/migrations/{mrNumber}",
817
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
818
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
819
+ );
820
+ const getColumn = (variables, signal) => dataPlaneFetch({
821
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
428
822
  method: "get",
429
823
  ...variables,
430
824
  signal
431
825
  });
432
- const updateMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
433
- const listMigrationRequestsCommits = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
434
- const compareMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
435
- const getMigrationRequestIsMerged = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
436
- const mergeMigrationRequest = (variables, signal) => fetch$1({
437
- url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
438
- method: "post",
826
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
827
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
828
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
829
+ method: "delete",
439
830
  ...variables,
440
831
  signal
441
832
  });
442
- const getBranchDetails = (variables, signal) => fetch$1({
443
- url: "/db/{dbBranchName}",
833
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
834
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
835
+ const getRecord = (variables, signal) => dataPlaneFetch({
836
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
444
837
  method: "get",
445
838
  ...variables,
446
839
  signal
447
840
  });
448
- const createBranch = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
449
- const deleteBranch = (variables, signal) => fetch$1({
450
- url: "/db/{dbBranchName}",
451
- method: "delete",
841
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
842
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
843
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
844
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
845
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
846
+ const queryTable = (variables, signal) => dataPlaneFetch({
847
+ url: "/db/{dbBranchName}/tables/{tableName}/query",
848
+ method: "post",
452
849
  ...variables,
453
850
  signal
454
851
  });
455
- const updateBranchMetadata = (variables, signal) => fetch$1({
456
- url: "/db/{dbBranchName}/metadata",
457
- method: "put",
852
+ const searchBranch = (variables, signal) => dataPlaneFetch({
853
+ url: "/db/{dbBranchName}/search",
854
+ method: "post",
458
855
  ...variables,
459
856
  signal
460
857
  });
461
- const getBranchMetadata = (variables, signal) => fetch$1({
462
- url: "/db/{dbBranchName}/metadata",
463
- method: "get",
858
+ const searchTable = (variables, signal) => dataPlaneFetch({
859
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
860
+ method: "post",
464
861
  ...variables,
465
862
  signal
466
863
  });
467
- const getBranchMigrationHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
468
- const executeBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
469
- const getBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
470
- const compareBranchWithUserSchema = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
471
- const compareBranchSchemas = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
472
- const updateBranchSchema = (variables, signal) => fetch$1({
473
- url: "/db/{dbBranchName}/schema/update",
864
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
865
+ const askTable = (variables, signal) => dataPlaneFetch({
866
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
474
867
  method: "post",
475
868
  ...variables,
476
869
  signal
477
870
  });
478
- const previewBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
479
- const applyBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
480
- const getBranchSchemaHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
481
- const getBranchStats = (variables, signal) => fetch$1({
482
- url: "/db/{dbBranchName}/stats",
871
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
872
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
873
+ const operationsByTag$2 = {
874
+ branch: {
875
+ getBranchList,
876
+ getBranchDetails,
877
+ createBranch,
878
+ deleteBranch,
879
+ copyBranch,
880
+ updateBranchMetadata,
881
+ getBranchMetadata,
882
+ getBranchStats,
883
+ getGitBranchesMapping,
884
+ addGitBranchesEntry,
885
+ removeGitBranchesEntry,
886
+ resolveBranch
887
+ },
888
+ migrations: {
889
+ getBranchMigrationHistory,
890
+ getBranchMigrationPlan,
891
+ executeBranchMigrationPlan,
892
+ getBranchSchemaHistory,
893
+ compareBranchWithUserSchema,
894
+ compareBranchSchemas,
895
+ updateBranchSchema,
896
+ previewBranchSchemaEdit,
897
+ applyBranchSchemaEdit,
898
+ pushBranchMigrations
899
+ },
900
+ migrationRequests: {
901
+ queryMigrationRequests,
902
+ createMigrationRequest,
903
+ getMigrationRequest,
904
+ updateMigrationRequest,
905
+ listMigrationRequestsCommits,
906
+ compareMigrationRequest,
907
+ getMigrationRequestIsMerged,
908
+ mergeMigrationRequest
909
+ },
910
+ table: {
911
+ createTable,
912
+ deleteTable,
913
+ updateTable,
914
+ getTableSchema,
915
+ setTableSchema,
916
+ getTableColumns,
917
+ addTableColumn,
918
+ getColumn,
919
+ updateColumn,
920
+ deleteColumn
921
+ },
922
+ records: {
923
+ branchTransaction,
924
+ insertRecord,
925
+ getRecord,
926
+ insertRecordWithID,
927
+ updateRecordWithID,
928
+ upsertRecordWithID,
929
+ deleteRecord,
930
+ bulkInsertTableRecords
931
+ },
932
+ searchAndFilter: {
933
+ queryTable,
934
+ searchBranch,
935
+ searchTable,
936
+ vectorSearchTable,
937
+ askTable,
938
+ summarizeTable,
939
+ aggregateTable
940
+ }
941
+ };
942
+
943
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
944
+
945
+ const getUser = (variables, signal) => controlPlaneFetch({
946
+ url: "/user",
483
947
  method: "get",
484
948
  ...variables,
485
949
  signal
486
950
  });
487
- const createTable = (variables, signal) => fetch$1({
488
- url: "/db/{dbBranchName}/tables/{tableName}",
951
+ const updateUser = (variables, signal) => controlPlaneFetch({
952
+ url: "/user",
489
953
  method: "put",
490
954
  ...variables,
491
955
  signal
492
956
  });
493
- const deleteTable = (variables, signal) => fetch$1({
494
- url: "/db/{dbBranchName}/tables/{tableName}",
957
+ const deleteUser = (variables, signal) => controlPlaneFetch({
958
+ url: "/user",
495
959
  method: "delete",
496
960
  ...variables,
497
961
  signal
498
962
  });
499
- const updateTable = (variables, signal) => fetch$1({
500
- url: "/db/{dbBranchName}/tables/{tableName}",
501
- method: "patch",
963
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
964
+ url: "/user/keys",
965
+ method: "get",
502
966
  ...variables,
503
967
  signal
504
968
  });
505
- const getTableSchema = (variables, signal) => fetch$1({
506
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
507
- method: "get",
969
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
970
+ url: "/user/keys/{keyName}",
971
+ method: "post",
508
972
  ...variables,
509
973
  signal
510
974
  });
511
- const setTableSchema = (variables, signal) => fetch$1({
512
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
513
- method: "put",
975
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
976
+ url: "/user/keys/{keyName}",
977
+ method: "delete",
514
978
  ...variables,
515
979
  signal
516
980
  });
517
- const getTableColumns = (variables, signal) => fetch$1({
518
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
981
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
982
+ url: "/workspaces",
519
983
  method: "get",
520
984
  ...variables,
521
985
  signal
522
986
  });
523
- const addTableColumn = (variables, signal) => fetch$1({
524
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
987
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
988
+ url: "/workspaces",
525
989
  method: "post",
526
990
  ...variables,
527
991
  signal
528
992
  });
529
- const getColumn = (variables, signal) => fetch$1({
530
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
993
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
994
+ url: "/workspaces/{workspaceId}",
531
995
  method: "get",
532
996
  ...variables,
533
997
  signal
534
998
  });
535
- const deleteColumn = (variables, signal) => fetch$1({
536
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
537
- method: "delete",
999
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
1000
+ url: "/workspaces/{workspaceId}",
1001
+ method: "put",
538
1002
  ...variables,
539
1003
  signal
540
1004
  });
541
- const updateColumn = (variables, signal) => fetch$1({
542
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
543
- method: "patch",
1005
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
1006
+ url: "/workspaces/{workspaceId}",
1007
+ method: "delete",
544
1008
  ...variables,
545
1009
  signal
546
1010
  });
547
- const insertRecord = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
548
- const insertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
549
- const updateRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
550
- const upsertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
551
- const deleteRecord = (variables, signal) => fetch$1({
552
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
1011
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
1012
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
1013
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
1014
+ url: "/workspaces/{workspaceId}/members/{userId}",
553
1015
  method: "delete",
554
1016
  ...variables,
555
1017
  signal
556
1018
  });
557
- const getRecord = (variables, signal) => fetch$1({
558
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
1019
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
1020
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
1021
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
1022
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
1023
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
1024
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
1025
+ url: "/workspaces/{workspaceId}/dbs",
559
1026
  method: "get",
560
1027
  ...variables,
561
1028
  signal
562
1029
  });
563
- const bulkInsertTableRecords = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
564
- const queryTable = (variables, signal) => fetch$1({
565
- url: "/db/{dbBranchName}/tables/{tableName}/query",
566
- method: "post",
567
- ...variables,
568
- signal
569
- });
570
- const searchTable = (variables, signal) => fetch$1({
571
- url: "/db/{dbBranchName}/tables/{tableName}/search",
572
- method: "post",
573
- ...variables,
574
- signal
575
- });
576
- const searchBranch = (variables, signal) => fetch$1({
577
- url: "/db/{dbBranchName}/search",
578
- method: "post",
579
- ...variables,
580
- signal
581
- });
582
- const summarizeTable = (variables, signal) => fetch$1({
583
- url: "/db/{dbBranchName}/tables/{tableName}/summarize",
584
- method: "post",
1030
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
1031
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
1032
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
1033
+ method: "delete",
585
1034
  ...variables,
586
1035
  signal
587
1036
  });
588
- const aggregateTable = (variables, signal) => fetch$1({
589
- url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
590
- method: "post",
1037
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
1038
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1039
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
1040
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
1041
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
1042
+ const listRegions = (variables, signal) => controlPlaneFetch({
1043
+ url: "/workspaces/{workspaceId}/regions",
1044
+ method: "get",
591
1045
  ...variables,
592
1046
  signal
593
1047
  });
594
- const operationsByTag = {
595
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
1048
+ const operationsByTag$1 = {
1049
+ users: { getUser, updateUser, deleteUser },
1050
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
596
1051
  workspaces: {
597
- createWorkspace,
598
1052
  getWorkspacesList,
1053
+ createWorkspace,
599
1054
  getWorkspace,
600
1055
  updateWorkspace,
601
1056
  deleteWorkspace,
602
1057
  getWorkspaceMembersList,
603
1058
  updateWorkspaceMemberRole,
604
- removeWorkspaceMember,
1059
+ removeWorkspaceMember
1060
+ },
1061
+ invites: {
605
1062
  inviteWorkspaceMember,
606
1063
  updateWorkspaceMemberInvite,
607
1064
  cancelWorkspaceMemberInvite,
608
- resendWorkspaceMemberInvite,
609
- acceptWorkspaceMemberInvite
1065
+ acceptWorkspaceMemberInvite,
1066
+ resendWorkspaceMemberInvite
610
1067
  },
611
- database: {
1068
+ databases: {
612
1069
  getDatabaseList,
613
1070
  createDatabase,
614
1071
  deleteDatabase,
615
1072
  getDatabaseMetadata,
616
1073
  updateDatabaseMetadata,
617
- getGitBranchesMapping,
618
- addGitBranchesEntry,
619
- removeGitBranchesEntry,
620
- resolveBranch
621
- },
622
- branch: {
623
- getBranchList,
624
- getBranchDetails,
625
- createBranch,
626
- deleteBranch,
627
- updateBranchMetadata,
628
- getBranchMetadata,
629
- getBranchStats
630
- },
631
- migrationRequests: {
632
- queryMigrationRequests,
633
- createMigrationRequest,
634
- getMigrationRequest,
635
- updateMigrationRequest,
636
- listMigrationRequestsCommits,
637
- compareMigrationRequest,
638
- getMigrationRequestIsMerged,
639
- mergeMigrationRequest
640
- },
641
- branchSchema: {
642
- getBranchMigrationHistory,
643
- executeBranchMigrationPlan,
644
- getBranchMigrationPlan,
645
- compareBranchWithUserSchema,
646
- compareBranchSchemas,
647
- updateBranchSchema,
648
- previewBranchSchemaEdit,
649
- applyBranchSchemaEdit,
650
- getBranchSchemaHistory
651
- },
652
- table: {
653
- createTable,
654
- deleteTable,
655
- updateTable,
656
- getTableSchema,
657
- setTableSchema,
658
- getTableColumns,
659
- addTableColumn,
660
- getColumn,
661
- deleteColumn,
662
- updateColumn
663
- },
664
- records: {
665
- insertRecord,
666
- insertRecordWithID,
667
- updateRecordWithID,
668
- upsertRecordWithID,
669
- deleteRecord,
670
- getRecord,
671
- bulkInsertTableRecords,
672
- queryTable,
673
- searchTable,
674
- searchBranch,
675
- summarizeTable,
676
- aggregateTable
1074
+ getDatabaseGithubSettings,
1075
+ updateDatabaseGithubSettings,
1076
+ deleteDatabaseGithubSettings,
1077
+ listRegions
677
1078
  }
678
1079
  };
679
1080
 
1081
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
1082
+
680
1083
  function getHostUrl(provider, type) {
681
1084
  if (isHostProviderAlias(provider)) {
682
1085
  return providers[provider][type];
@@ -688,11 +1091,15 @@ function getHostUrl(provider, type) {
688
1091
  const providers = {
689
1092
  production: {
690
1093
  main: "https://api.xata.io",
691
- workspaces: "https://{workspaceId}.xata.sh"
1094
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
692
1095
  },
693
1096
  staging: {
694
- main: "https://staging.xatabase.co",
695
- workspaces: "https://{workspaceId}.staging.xatabase.co"
1097
+ main: "https://api.staging-xata.dev",
1098
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1099
+ },
1100
+ dev: {
1101
+ main: "https://api.dev-xata.dev",
1102
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
696
1103
  }
697
1104
  };
698
1105
  function isHostProviderAlias(alias) {
@@ -710,6 +1117,23 @@ function parseProviderString(provider = "production") {
710
1117
  return null;
711
1118
  return { main, workspaces };
712
1119
  }
1120
+ function buildProviderString(provider) {
1121
+ if (isHostProviderAlias(provider))
1122
+ return provider;
1123
+ return `${provider.main},${provider.workspaces}`;
1124
+ }
1125
+ function parseWorkspacesUrlParts(url) {
1126
+ if (!isString(url))
1127
+ return null;
1128
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
1129
+ const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1130
+ const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1131
+ const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1132
+ const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
1133
+ if (!match)
1134
+ return null;
1135
+ return { workspace: match[1], region: match[2] };
1136
+ }
713
1137
 
714
1138
  var __accessCheck$7 = (obj, member, msg) => {
715
1139
  if (!member.has(obj))
@@ -737,15 +1161,19 @@ class XataApiClient {
737
1161
  const provider = options.host ?? "production";
738
1162
  const apiKey = options.apiKey ?? getAPIKey();
739
1163
  const trace = options.trace ?? defaultTrace;
1164
+ const clientID = generateUUID();
740
1165
  if (!apiKey) {
741
1166
  throw new Error("Could not resolve a valid apiKey");
742
1167
  }
743
1168
  __privateSet$7(this, _extraProps, {
744
1169
  apiUrl: getHostUrl(provider, "main"),
745
1170
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
746
- fetchImpl: getFetchImplementation(options.fetch),
1171
+ fetch: getFetchImplementation(options.fetch),
747
1172
  apiKey,
748
- trace
1173
+ trace,
1174
+ clientName: options.clientName,
1175
+ xataAgentExtra: options.xataAgentExtra,
1176
+ clientID
749
1177
  });
750
1178
  }
751
1179
  get user() {
@@ -753,21 +1181,41 @@ class XataApiClient {
753
1181
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
754
1182
  return __privateGet$7(this, _namespaces).user;
755
1183
  }
1184
+ get authentication() {
1185
+ if (!__privateGet$7(this, _namespaces).authentication)
1186
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
1187
+ return __privateGet$7(this, _namespaces).authentication;
1188
+ }
756
1189
  get workspaces() {
757
1190
  if (!__privateGet$7(this, _namespaces).workspaces)
758
1191
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
759
1192
  return __privateGet$7(this, _namespaces).workspaces;
760
1193
  }
761
- get databases() {
762
- if (!__privateGet$7(this, _namespaces).databases)
763
- __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
764
- return __privateGet$7(this, _namespaces).databases;
1194
+ get invites() {
1195
+ if (!__privateGet$7(this, _namespaces).invites)
1196
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
1197
+ return __privateGet$7(this, _namespaces).invites;
1198
+ }
1199
+ get database() {
1200
+ if (!__privateGet$7(this, _namespaces).database)
1201
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
1202
+ return __privateGet$7(this, _namespaces).database;
765
1203
  }
766
1204
  get branches() {
767
1205
  if (!__privateGet$7(this, _namespaces).branches)
768
1206
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
769
1207
  return __privateGet$7(this, _namespaces).branches;
770
1208
  }
1209
+ get migrations() {
1210
+ if (!__privateGet$7(this, _namespaces).migrations)
1211
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
1212
+ return __privateGet$7(this, _namespaces).migrations;
1213
+ }
1214
+ get migrationRequests() {
1215
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
1216
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
1217
+ return __privateGet$7(this, _namespaces).migrationRequests;
1218
+ }
771
1219
  get tables() {
772
1220
  if (!__privateGet$7(this, _namespaces).tables)
773
1221
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -778,15 +1226,10 @@ class XataApiClient {
778
1226
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
779
1227
  return __privateGet$7(this, _namespaces).records;
780
1228
  }
781
- get migrationRequests() {
782
- if (!__privateGet$7(this, _namespaces).migrationRequests)
783
- __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
784
- return __privateGet$7(this, _namespaces).migrationRequests;
785
- }
786
- get branchSchema() {
787
- if (!__privateGet$7(this, _namespaces).branchSchema)
788
- __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
789
- return __privateGet$7(this, _namespaces).branchSchema;
1229
+ get searchAndFilter() {
1230
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
1231
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
1232
+ return __privateGet$7(this, _namespaces).searchAndFilter;
790
1233
  }
791
1234
  }
792
1235
  _extraProps = new WeakMap();
@@ -798,24 +1241,29 @@ class UserApi {
798
1241
  getUser() {
799
1242
  return operationsByTag.users.getUser({ ...this.extraProps });
800
1243
  }
801
- updateUser(user) {
1244
+ updateUser({ user }) {
802
1245
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
803
1246
  }
804
1247
  deleteUser() {
805
1248
  return operationsByTag.users.deleteUser({ ...this.extraProps });
806
1249
  }
1250
+ }
1251
+ class AuthenticationApi {
1252
+ constructor(extraProps) {
1253
+ this.extraProps = extraProps;
1254
+ }
807
1255
  getUserAPIKeys() {
808
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
1256
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
809
1257
  }
810
- createUserAPIKey(keyName) {
811
- return operationsByTag.users.createUserAPIKey({
812
- pathParams: { keyName },
1258
+ createUserAPIKey({ name }) {
1259
+ return operationsByTag.authentication.createUserAPIKey({
1260
+ pathParams: { keyName: name },
813
1261
  ...this.extraProps
814
1262
  });
815
1263
  }
816
- deleteUserAPIKey(keyName) {
817
- return operationsByTag.users.deleteUserAPIKey({
818
- pathParams: { keyName },
1264
+ deleteUserAPIKey({ name }) {
1265
+ return operationsByTag.authentication.deleteUserAPIKey({
1266
+ pathParams: { keyName: name },
819
1267
  ...this.extraProps
820
1268
  });
821
1269
  }
@@ -824,196 +1272,262 @@ class WorkspaceApi {
824
1272
  constructor(extraProps) {
825
1273
  this.extraProps = extraProps;
826
1274
  }
827
- createWorkspace(workspaceMeta) {
1275
+ getWorkspacesList() {
1276
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
1277
+ }
1278
+ createWorkspace({ data }) {
828
1279
  return operationsByTag.workspaces.createWorkspace({
829
- body: workspaceMeta,
1280
+ body: data,
830
1281
  ...this.extraProps
831
1282
  });
832
1283
  }
833
- getWorkspacesList() {
834
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
835
- }
836
- getWorkspace(workspaceId) {
1284
+ getWorkspace({ workspace }) {
837
1285
  return operationsByTag.workspaces.getWorkspace({
838
- pathParams: { workspaceId },
1286
+ pathParams: { workspaceId: workspace },
839
1287
  ...this.extraProps
840
1288
  });
841
1289
  }
842
- updateWorkspace(workspaceId, workspaceMeta) {
1290
+ updateWorkspace({
1291
+ workspace,
1292
+ update
1293
+ }) {
843
1294
  return operationsByTag.workspaces.updateWorkspace({
844
- pathParams: { workspaceId },
845
- body: workspaceMeta,
1295
+ pathParams: { workspaceId: workspace },
1296
+ body: update,
846
1297
  ...this.extraProps
847
1298
  });
848
1299
  }
849
- deleteWorkspace(workspaceId) {
1300
+ deleteWorkspace({ workspace }) {
850
1301
  return operationsByTag.workspaces.deleteWorkspace({
851
- pathParams: { workspaceId },
1302
+ pathParams: { workspaceId: workspace },
852
1303
  ...this.extraProps
853
1304
  });
854
1305
  }
855
- getWorkspaceMembersList(workspaceId) {
1306
+ getWorkspaceMembersList({ workspace }) {
856
1307
  return operationsByTag.workspaces.getWorkspaceMembersList({
857
- pathParams: { workspaceId },
1308
+ pathParams: { workspaceId: workspace },
858
1309
  ...this.extraProps
859
1310
  });
860
1311
  }
861
- updateWorkspaceMemberRole(workspaceId, userId, role) {
1312
+ updateWorkspaceMemberRole({
1313
+ workspace,
1314
+ user,
1315
+ role
1316
+ }) {
862
1317
  return operationsByTag.workspaces.updateWorkspaceMemberRole({
863
- pathParams: { workspaceId, userId },
1318
+ pathParams: { workspaceId: workspace, userId: user },
864
1319
  body: { role },
865
1320
  ...this.extraProps
866
1321
  });
867
1322
  }
868
- removeWorkspaceMember(workspaceId, userId) {
1323
+ removeWorkspaceMember({
1324
+ workspace,
1325
+ user
1326
+ }) {
869
1327
  return operationsByTag.workspaces.removeWorkspaceMember({
870
- pathParams: { workspaceId, userId },
1328
+ pathParams: { workspaceId: workspace, userId: user },
871
1329
  ...this.extraProps
872
1330
  });
873
1331
  }
874
- inviteWorkspaceMember(workspaceId, email, role) {
875
- return operationsByTag.workspaces.inviteWorkspaceMember({
876
- pathParams: { workspaceId },
1332
+ }
1333
+ class InvitesApi {
1334
+ constructor(extraProps) {
1335
+ this.extraProps = extraProps;
1336
+ }
1337
+ inviteWorkspaceMember({
1338
+ workspace,
1339
+ email,
1340
+ role
1341
+ }) {
1342
+ return operationsByTag.invites.inviteWorkspaceMember({
1343
+ pathParams: { workspaceId: workspace },
877
1344
  body: { email, role },
878
1345
  ...this.extraProps
879
1346
  });
880
1347
  }
881
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
882
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
883
- pathParams: { workspaceId, inviteId },
1348
+ updateWorkspaceMemberInvite({
1349
+ workspace,
1350
+ invite,
1351
+ role
1352
+ }) {
1353
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
1354
+ pathParams: { workspaceId: workspace, inviteId: invite },
884
1355
  body: { role },
885
1356
  ...this.extraProps
886
1357
  });
887
1358
  }
888
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
889
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
890
- pathParams: { workspaceId, inviteId },
1359
+ cancelWorkspaceMemberInvite({
1360
+ workspace,
1361
+ invite
1362
+ }) {
1363
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
1364
+ pathParams: { workspaceId: workspace, inviteId: invite },
891
1365
  ...this.extraProps
892
1366
  });
893
1367
  }
894
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
895
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
896
- pathParams: { workspaceId, inviteId },
1368
+ acceptWorkspaceMemberInvite({
1369
+ workspace,
1370
+ key
1371
+ }) {
1372
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
1373
+ pathParams: { workspaceId: workspace, inviteKey: key },
897
1374
  ...this.extraProps
898
1375
  });
899
1376
  }
900
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
901
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
902
- pathParams: { workspaceId, inviteKey },
1377
+ resendWorkspaceMemberInvite({
1378
+ workspace,
1379
+ invite
1380
+ }) {
1381
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
1382
+ pathParams: { workspaceId: workspace, inviteId: invite },
903
1383
  ...this.extraProps
904
1384
  });
905
1385
  }
906
1386
  }
907
- class DatabaseApi {
1387
+ class BranchApi {
908
1388
  constructor(extraProps) {
909
1389
  this.extraProps = extraProps;
910
1390
  }
911
- getDatabaseList(workspace) {
912
- return operationsByTag.database.getDatabaseList({
913
- pathParams: { workspace },
914
- ...this.extraProps
915
- });
916
- }
917
- createDatabase(workspace, dbName, options = {}) {
918
- return operationsByTag.database.createDatabase({
919
- pathParams: { workspace, dbName },
920
- body: options,
921
- ...this.extraProps
922
- });
923
- }
924
- deleteDatabase(workspace, dbName) {
925
- return operationsByTag.database.deleteDatabase({
926
- pathParams: { workspace, dbName },
927
- ...this.extraProps
928
- });
929
- }
930
- getDatabaseMetadata(workspace, dbName) {
931
- return operationsByTag.database.getDatabaseMetadata({
932
- pathParams: { workspace, dbName },
933
- ...this.extraProps
934
- });
935
- }
936
- updateDatabaseMetadata(workspace, dbName, options = {}) {
937
- return operationsByTag.database.updateDatabaseMetadata({
938
- pathParams: { workspace, dbName },
939
- body: options,
1391
+ getBranchList({
1392
+ workspace,
1393
+ region,
1394
+ database
1395
+ }) {
1396
+ return operationsByTag.branch.getBranchList({
1397
+ pathParams: { workspace, region, dbName: database },
940
1398
  ...this.extraProps
941
1399
  });
942
1400
  }
943
- getGitBranchesMapping(workspace, dbName) {
944
- return operationsByTag.database.getGitBranchesMapping({
945
- pathParams: { workspace, dbName },
1401
+ getBranchDetails({
1402
+ workspace,
1403
+ region,
1404
+ database,
1405
+ branch
1406
+ }) {
1407
+ return operationsByTag.branch.getBranchDetails({
1408
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
946
1409
  ...this.extraProps
947
1410
  });
948
1411
  }
949
- addGitBranchesEntry(workspace, dbName, body) {
950
- return operationsByTag.database.addGitBranchesEntry({
951
- pathParams: { workspace, dbName },
952
- body,
1412
+ createBranch({
1413
+ workspace,
1414
+ region,
1415
+ database,
1416
+ branch,
1417
+ from,
1418
+ metadata
1419
+ }) {
1420
+ return operationsByTag.branch.createBranch({
1421
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1422
+ body: { from, metadata },
953
1423
  ...this.extraProps
954
1424
  });
955
1425
  }
956
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
957
- return operationsByTag.database.removeGitBranchesEntry({
958
- pathParams: { workspace, dbName },
959
- queryParams: { gitBranch },
1426
+ deleteBranch({
1427
+ workspace,
1428
+ region,
1429
+ database,
1430
+ branch
1431
+ }) {
1432
+ return operationsByTag.branch.deleteBranch({
1433
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
960
1434
  ...this.extraProps
961
1435
  });
962
1436
  }
963
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
964
- return operationsByTag.database.resolveBranch({
965
- pathParams: { workspace, dbName },
966
- queryParams: { gitBranch, fallbackBranch },
1437
+ copyBranch({
1438
+ workspace,
1439
+ region,
1440
+ database,
1441
+ branch,
1442
+ destinationBranch,
1443
+ limit
1444
+ }) {
1445
+ return operationsByTag.branch.copyBranch({
1446
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1447
+ body: { destinationBranch, limit },
967
1448
  ...this.extraProps
968
1449
  });
969
1450
  }
970
- }
971
- class BranchApi {
972
- constructor(extraProps) {
973
- this.extraProps = extraProps;
974
- }
975
- getBranchList(workspace, dbName) {
976
- return operationsByTag.branch.getBranchList({
977
- pathParams: { workspace, dbName },
1451
+ updateBranchMetadata({
1452
+ workspace,
1453
+ region,
1454
+ database,
1455
+ branch,
1456
+ metadata
1457
+ }) {
1458
+ return operationsByTag.branch.updateBranchMetadata({
1459
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1460
+ body: metadata,
978
1461
  ...this.extraProps
979
1462
  });
980
1463
  }
981
- getBranchDetails(workspace, database, branch) {
982
- return operationsByTag.branch.getBranchDetails({
983
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1464
+ getBranchMetadata({
1465
+ workspace,
1466
+ region,
1467
+ database,
1468
+ branch
1469
+ }) {
1470
+ return operationsByTag.branch.getBranchMetadata({
1471
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
984
1472
  ...this.extraProps
985
1473
  });
986
1474
  }
987
- createBranch(workspace, database, branch, from, options = {}) {
988
- return operationsByTag.branch.createBranch({
989
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
990
- queryParams: isString(from) ? { from } : void 0,
991
- body: options,
1475
+ getBranchStats({
1476
+ workspace,
1477
+ region,
1478
+ database,
1479
+ branch
1480
+ }) {
1481
+ return operationsByTag.branch.getBranchStats({
1482
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
992
1483
  ...this.extraProps
993
1484
  });
994
1485
  }
995
- deleteBranch(workspace, database, branch) {
996
- return operationsByTag.branch.deleteBranch({
997
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1486
+ getGitBranchesMapping({
1487
+ workspace,
1488
+ region,
1489
+ database
1490
+ }) {
1491
+ return operationsByTag.branch.getGitBranchesMapping({
1492
+ pathParams: { workspace, region, dbName: database },
998
1493
  ...this.extraProps
999
1494
  });
1000
1495
  }
1001
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
1002
- return operationsByTag.branch.updateBranchMetadata({
1003
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1004
- body: metadata,
1496
+ addGitBranchesEntry({
1497
+ workspace,
1498
+ region,
1499
+ database,
1500
+ gitBranch,
1501
+ xataBranch
1502
+ }) {
1503
+ return operationsByTag.branch.addGitBranchesEntry({
1504
+ pathParams: { workspace, region, dbName: database },
1505
+ body: { gitBranch, xataBranch },
1005
1506
  ...this.extraProps
1006
1507
  });
1007
1508
  }
1008
- getBranchMetadata(workspace, database, branch) {
1009
- return operationsByTag.branch.getBranchMetadata({
1010
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1509
+ removeGitBranchesEntry({
1510
+ workspace,
1511
+ region,
1512
+ database,
1513
+ gitBranch
1514
+ }) {
1515
+ return operationsByTag.branch.removeGitBranchesEntry({
1516
+ pathParams: { workspace, region, dbName: database },
1517
+ queryParams: { gitBranch },
1011
1518
  ...this.extraProps
1012
1519
  });
1013
1520
  }
1014
- getBranchStats(workspace, database, branch) {
1015
- return operationsByTag.branch.getBranchStats({
1016
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1521
+ resolveBranch({
1522
+ workspace,
1523
+ region,
1524
+ database,
1525
+ gitBranch,
1526
+ fallbackBranch
1527
+ }) {
1528
+ return operationsByTag.branch.resolveBranch({
1529
+ pathParams: { workspace, region, dbName: database },
1530
+ queryParams: { gitBranch, fallbackBranch },
1017
1531
  ...this.extraProps
1018
1532
  });
1019
1533
  }
@@ -1022,67 +1536,134 @@ class TableApi {
1022
1536
  constructor(extraProps) {
1023
1537
  this.extraProps = extraProps;
1024
1538
  }
1025
- createTable(workspace, database, branch, tableName) {
1539
+ createTable({
1540
+ workspace,
1541
+ region,
1542
+ database,
1543
+ branch,
1544
+ table
1545
+ }) {
1026
1546
  return operationsByTag.table.createTable({
1027
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1547
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1028
1548
  ...this.extraProps
1029
1549
  });
1030
1550
  }
1031
- deleteTable(workspace, database, branch, tableName) {
1551
+ deleteTable({
1552
+ workspace,
1553
+ region,
1554
+ database,
1555
+ branch,
1556
+ table
1557
+ }) {
1032
1558
  return operationsByTag.table.deleteTable({
1033
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1559
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1034
1560
  ...this.extraProps
1035
1561
  });
1036
1562
  }
1037
- updateTable(workspace, database, branch, tableName, options) {
1563
+ updateTable({
1564
+ workspace,
1565
+ region,
1566
+ database,
1567
+ branch,
1568
+ table,
1569
+ update
1570
+ }) {
1038
1571
  return operationsByTag.table.updateTable({
1039
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1040
- body: options,
1572
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1573
+ body: update,
1041
1574
  ...this.extraProps
1042
1575
  });
1043
1576
  }
1044
- getTableSchema(workspace, database, branch, tableName) {
1577
+ getTableSchema({
1578
+ workspace,
1579
+ region,
1580
+ database,
1581
+ branch,
1582
+ table
1583
+ }) {
1045
1584
  return operationsByTag.table.getTableSchema({
1046
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1585
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1047
1586
  ...this.extraProps
1048
1587
  });
1049
1588
  }
1050
- setTableSchema(workspace, database, branch, tableName, options) {
1589
+ setTableSchema({
1590
+ workspace,
1591
+ region,
1592
+ database,
1593
+ branch,
1594
+ table,
1595
+ schema
1596
+ }) {
1051
1597
  return operationsByTag.table.setTableSchema({
1052
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1053
- body: options,
1598
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1599
+ body: schema,
1054
1600
  ...this.extraProps
1055
1601
  });
1056
1602
  }
1057
- getTableColumns(workspace, database, branch, tableName) {
1603
+ getTableColumns({
1604
+ workspace,
1605
+ region,
1606
+ database,
1607
+ branch,
1608
+ table
1609
+ }) {
1058
1610
  return operationsByTag.table.getTableColumns({
1059
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1611
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1060
1612
  ...this.extraProps
1061
1613
  });
1062
1614
  }
1063
- addTableColumn(workspace, database, branch, tableName, column) {
1615
+ addTableColumn({
1616
+ workspace,
1617
+ region,
1618
+ database,
1619
+ branch,
1620
+ table,
1621
+ column
1622
+ }) {
1064
1623
  return operationsByTag.table.addTableColumn({
1065
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1624
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1066
1625
  body: column,
1067
1626
  ...this.extraProps
1068
1627
  });
1069
1628
  }
1070
- getColumn(workspace, database, branch, tableName, columnName) {
1629
+ getColumn({
1630
+ workspace,
1631
+ region,
1632
+ database,
1633
+ branch,
1634
+ table,
1635
+ column
1636
+ }) {
1071
1637
  return operationsByTag.table.getColumn({
1072
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1638
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1073
1639
  ...this.extraProps
1074
1640
  });
1075
1641
  }
1076
- deleteColumn(workspace, database, branch, tableName, columnName) {
1077
- return operationsByTag.table.deleteColumn({
1078
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1642
+ updateColumn({
1643
+ workspace,
1644
+ region,
1645
+ database,
1646
+ branch,
1647
+ table,
1648
+ column,
1649
+ update
1650
+ }) {
1651
+ return operationsByTag.table.updateColumn({
1652
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1653
+ body: update,
1079
1654
  ...this.extraProps
1080
1655
  });
1081
1656
  }
1082
- updateColumn(workspace, database, branch, tableName, columnName, options) {
1083
- return operationsByTag.table.updateColumn({
1084
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1085
- body: options,
1657
+ deleteColumn({
1658
+ workspace,
1659
+ region,
1660
+ database,
1661
+ branch,
1662
+ table,
1663
+ column
1664
+ }) {
1665
+ return operationsByTag.table.deleteColumn({
1666
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1086
1667
  ...this.extraProps
1087
1668
  });
1088
1669
  }
@@ -1091,92 +1672,260 @@ class RecordsApi {
1091
1672
  constructor(extraProps) {
1092
1673
  this.extraProps = extraProps;
1093
1674
  }
1094
- insertRecord(workspace, database, branch, tableName, record, options = {}) {
1675
+ insertRecord({
1676
+ workspace,
1677
+ region,
1678
+ database,
1679
+ branch,
1680
+ table,
1681
+ record,
1682
+ columns
1683
+ }) {
1095
1684
  return operationsByTag.records.insertRecord({
1096
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1097
- queryParams: options,
1685
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1686
+ queryParams: { columns },
1098
1687
  body: record,
1099
1688
  ...this.extraProps
1100
1689
  });
1101
1690
  }
1102
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1691
+ getRecord({
1692
+ workspace,
1693
+ region,
1694
+ database,
1695
+ branch,
1696
+ table,
1697
+ id,
1698
+ columns
1699
+ }) {
1700
+ return operationsByTag.records.getRecord({
1701
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1702
+ queryParams: { columns },
1703
+ ...this.extraProps
1704
+ });
1705
+ }
1706
+ insertRecordWithID({
1707
+ workspace,
1708
+ region,
1709
+ database,
1710
+ branch,
1711
+ table,
1712
+ id,
1713
+ record,
1714
+ columns,
1715
+ createOnly,
1716
+ ifVersion
1717
+ }) {
1103
1718
  return operationsByTag.records.insertRecordWithID({
1104
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1105
- queryParams: options,
1719
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1720
+ queryParams: { columns, createOnly, ifVersion },
1106
1721
  body: record,
1107
1722
  ...this.extraProps
1108
1723
  });
1109
1724
  }
1110
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1725
+ updateRecordWithID({
1726
+ workspace,
1727
+ region,
1728
+ database,
1729
+ branch,
1730
+ table,
1731
+ id,
1732
+ record,
1733
+ columns,
1734
+ ifVersion
1735
+ }) {
1111
1736
  return operationsByTag.records.updateRecordWithID({
1112
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1113
- queryParams: options,
1737
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1738
+ queryParams: { columns, ifVersion },
1114
1739
  body: record,
1115
1740
  ...this.extraProps
1116
1741
  });
1117
1742
  }
1118
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1743
+ upsertRecordWithID({
1744
+ workspace,
1745
+ region,
1746
+ database,
1747
+ branch,
1748
+ table,
1749
+ id,
1750
+ record,
1751
+ columns,
1752
+ ifVersion
1753
+ }) {
1119
1754
  return operationsByTag.records.upsertRecordWithID({
1120
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1121
- queryParams: options,
1755
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1756
+ queryParams: { columns, ifVersion },
1122
1757
  body: record,
1123
1758
  ...this.extraProps
1124
1759
  });
1125
1760
  }
1126
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
1761
+ deleteRecord({
1762
+ workspace,
1763
+ region,
1764
+ database,
1765
+ branch,
1766
+ table,
1767
+ id,
1768
+ columns
1769
+ }) {
1127
1770
  return operationsByTag.records.deleteRecord({
1128
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1129
- queryParams: options,
1130
- ...this.extraProps
1131
- });
1132
- }
1133
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
1134
- return operationsByTag.records.getRecord({
1135
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1136
- queryParams: options,
1771
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1772
+ queryParams: { columns },
1137
1773
  ...this.extraProps
1138
1774
  });
1139
1775
  }
1140
- bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
1776
+ bulkInsertTableRecords({
1777
+ workspace,
1778
+ region,
1779
+ database,
1780
+ branch,
1781
+ table,
1782
+ records,
1783
+ columns
1784
+ }) {
1141
1785
  return operationsByTag.records.bulkInsertTableRecords({
1142
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1143
- queryParams: options,
1786
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1787
+ queryParams: { columns },
1144
1788
  body: { records },
1145
1789
  ...this.extraProps
1146
1790
  });
1147
1791
  }
1148
- queryTable(workspace, database, branch, tableName, query) {
1149
- return operationsByTag.records.queryTable({
1150
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1151
- body: query,
1152
- ...this.extraProps
1153
- });
1154
- }
1155
- searchTable(workspace, database, branch, tableName, query) {
1156
- return operationsByTag.records.searchTable({
1157
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1158
- body: query,
1159
- ...this.extraProps
1160
- });
1161
- }
1162
- searchBranch(workspace, database, branch, query) {
1163
- return operationsByTag.records.searchBranch({
1164
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1165
- body: query,
1792
+ branchTransaction({
1793
+ workspace,
1794
+ region,
1795
+ database,
1796
+ branch,
1797
+ operations
1798
+ }) {
1799
+ return operationsByTag.records.branchTransaction({
1800
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1801
+ body: { operations },
1166
1802
  ...this.extraProps
1167
1803
  });
1168
1804
  }
1169
- summarizeTable(workspace, database, branch, tableName, query) {
1170
- return operationsByTag.records.summarizeTable({
1171
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1172
- body: query,
1173
- ...this.extraProps
1174
- });
1805
+ }
1806
+ class SearchAndFilterApi {
1807
+ constructor(extraProps) {
1808
+ this.extraProps = extraProps;
1175
1809
  }
1176
- aggregateTable(workspace, database, branch, tableName, query) {
1177
- return operationsByTag.records.aggregateTable({
1178
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1179
- body: query,
1810
+ queryTable({
1811
+ workspace,
1812
+ region,
1813
+ database,
1814
+ branch,
1815
+ table,
1816
+ filter,
1817
+ sort,
1818
+ page,
1819
+ columns,
1820
+ consistency
1821
+ }) {
1822
+ return operationsByTag.searchAndFilter.queryTable({
1823
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1824
+ body: { filter, sort, page, columns, consistency },
1825
+ ...this.extraProps
1826
+ });
1827
+ }
1828
+ searchTable({
1829
+ workspace,
1830
+ region,
1831
+ database,
1832
+ branch,
1833
+ table,
1834
+ query,
1835
+ fuzziness,
1836
+ target,
1837
+ prefix,
1838
+ filter,
1839
+ highlight,
1840
+ boosters
1841
+ }) {
1842
+ return operationsByTag.searchAndFilter.searchTable({
1843
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1844
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
1845
+ ...this.extraProps
1846
+ });
1847
+ }
1848
+ searchBranch({
1849
+ workspace,
1850
+ region,
1851
+ database,
1852
+ branch,
1853
+ tables,
1854
+ query,
1855
+ fuzziness,
1856
+ prefix,
1857
+ highlight
1858
+ }) {
1859
+ return operationsByTag.searchAndFilter.searchBranch({
1860
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1861
+ body: { tables, query, fuzziness, prefix, highlight },
1862
+ ...this.extraProps
1863
+ });
1864
+ }
1865
+ vectorSearchTable({
1866
+ workspace,
1867
+ region,
1868
+ database,
1869
+ branch,
1870
+ table,
1871
+ queryVector,
1872
+ column,
1873
+ similarityFunction,
1874
+ size,
1875
+ filter
1876
+ }) {
1877
+ return operationsByTag.searchAndFilter.vectorSearchTable({
1878
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1879
+ body: { queryVector, column, similarityFunction, size, filter },
1880
+ ...this.extraProps
1881
+ });
1882
+ }
1883
+ askTable({
1884
+ workspace,
1885
+ region,
1886
+ database,
1887
+ branch,
1888
+ table,
1889
+ options
1890
+ }) {
1891
+ return operationsByTag.searchAndFilter.askTable({
1892
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1893
+ body: { ...options },
1894
+ ...this.extraProps
1895
+ });
1896
+ }
1897
+ summarizeTable({
1898
+ workspace,
1899
+ region,
1900
+ database,
1901
+ branch,
1902
+ table,
1903
+ filter,
1904
+ columns,
1905
+ summaries,
1906
+ sort,
1907
+ summariesFilter,
1908
+ page,
1909
+ consistency
1910
+ }) {
1911
+ return operationsByTag.searchAndFilter.summarizeTable({
1912
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1913
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1914
+ ...this.extraProps
1915
+ });
1916
+ }
1917
+ aggregateTable({
1918
+ workspace,
1919
+ region,
1920
+ database,
1921
+ branch,
1922
+ table,
1923
+ filter,
1924
+ aggs
1925
+ }) {
1926
+ return operationsByTag.searchAndFilter.aggregateTable({
1927
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1928
+ body: { filter, aggs },
1180
1929
  ...this.extraProps
1181
1930
  });
1182
1931
  }
@@ -1185,132 +1934,334 @@ class MigrationRequestsApi {
1185
1934
  constructor(extraProps) {
1186
1935
  this.extraProps = extraProps;
1187
1936
  }
1188
- queryMigrationRequests(workspace, database, options = {}) {
1937
+ queryMigrationRequests({
1938
+ workspace,
1939
+ region,
1940
+ database,
1941
+ filter,
1942
+ sort,
1943
+ page,
1944
+ columns
1945
+ }) {
1189
1946
  return operationsByTag.migrationRequests.queryMigrationRequests({
1190
- pathParams: { workspace, dbName: database },
1191
- body: options,
1947
+ pathParams: { workspace, region, dbName: database },
1948
+ body: { filter, sort, page, columns },
1192
1949
  ...this.extraProps
1193
1950
  });
1194
1951
  }
1195
- createMigrationRequest(workspace, database, options) {
1952
+ createMigrationRequest({
1953
+ workspace,
1954
+ region,
1955
+ database,
1956
+ migration
1957
+ }) {
1196
1958
  return operationsByTag.migrationRequests.createMigrationRequest({
1197
- pathParams: { workspace, dbName: database },
1198
- body: options,
1959
+ pathParams: { workspace, region, dbName: database },
1960
+ body: migration,
1199
1961
  ...this.extraProps
1200
1962
  });
1201
1963
  }
1202
- getMigrationRequest(workspace, database, migrationRequest) {
1964
+ getMigrationRequest({
1965
+ workspace,
1966
+ region,
1967
+ database,
1968
+ migrationRequest
1969
+ }) {
1203
1970
  return operationsByTag.migrationRequests.getMigrationRequest({
1204
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1971
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1205
1972
  ...this.extraProps
1206
1973
  });
1207
1974
  }
1208
- updateMigrationRequest(workspace, database, migrationRequest, options) {
1975
+ updateMigrationRequest({
1976
+ workspace,
1977
+ region,
1978
+ database,
1979
+ migrationRequest,
1980
+ update
1981
+ }) {
1209
1982
  return operationsByTag.migrationRequests.updateMigrationRequest({
1210
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1211
- body: options,
1983
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1984
+ body: update,
1212
1985
  ...this.extraProps
1213
1986
  });
1214
1987
  }
1215
- listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1988
+ listMigrationRequestsCommits({
1989
+ workspace,
1990
+ region,
1991
+ database,
1992
+ migrationRequest,
1993
+ page
1994
+ }) {
1216
1995
  return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1217
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1218
- body: options,
1996
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1997
+ body: { page },
1219
1998
  ...this.extraProps
1220
1999
  });
1221
2000
  }
1222
- compareMigrationRequest(workspace, database, migrationRequest) {
2001
+ compareMigrationRequest({
2002
+ workspace,
2003
+ region,
2004
+ database,
2005
+ migrationRequest
2006
+ }) {
1223
2007
  return operationsByTag.migrationRequests.compareMigrationRequest({
1224
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
2008
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1225
2009
  ...this.extraProps
1226
2010
  });
1227
2011
  }
1228
- getMigrationRequestIsMerged(workspace, database, migrationRequest) {
2012
+ getMigrationRequestIsMerged({
2013
+ workspace,
2014
+ region,
2015
+ database,
2016
+ migrationRequest
2017
+ }) {
1229
2018
  return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1230
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
2019
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1231
2020
  ...this.extraProps
1232
2021
  });
1233
2022
  }
1234
- mergeMigrationRequest(workspace, database, migrationRequest) {
2023
+ mergeMigrationRequest({
2024
+ workspace,
2025
+ region,
2026
+ database,
2027
+ migrationRequest
2028
+ }) {
1235
2029
  return operationsByTag.migrationRequests.mergeMigrationRequest({
1236
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
2030
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1237
2031
  ...this.extraProps
1238
2032
  });
1239
2033
  }
1240
2034
  }
1241
- class BranchSchemaApi {
2035
+ class MigrationsApi {
1242
2036
  constructor(extraProps) {
1243
2037
  this.extraProps = extraProps;
1244
2038
  }
1245
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
1246
- return operationsByTag.branchSchema.getBranchMigrationHistory({
1247
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1248
- body: options,
2039
+ getBranchMigrationHistory({
2040
+ workspace,
2041
+ region,
2042
+ database,
2043
+ branch,
2044
+ limit,
2045
+ startFrom
2046
+ }) {
2047
+ return operationsByTag.migrations.getBranchMigrationHistory({
2048
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2049
+ body: { limit, startFrom },
2050
+ ...this.extraProps
2051
+ });
2052
+ }
2053
+ getBranchMigrationPlan({
2054
+ workspace,
2055
+ region,
2056
+ database,
2057
+ branch,
2058
+ schema
2059
+ }) {
2060
+ return operationsByTag.migrations.getBranchMigrationPlan({
2061
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2062
+ body: schema,
2063
+ ...this.extraProps
2064
+ });
2065
+ }
2066
+ executeBranchMigrationPlan({
2067
+ workspace,
2068
+ region,
2069
+ database,
2070
+ branch,
2071
+ plan
2072
+ }) {
2073
+ return operationsByTag.migrations.executeBranchMigrationPlan({
2074
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2075
+ body: plan,
2076
+ ...this.extraProps
2077
+ });
2078
+ }
2079
+ getBranchSchemaHistory({
2080
+ workspace,
2081
+ region,
2082
+ database,
2083
+ branch,
2084
+ page
2085
+ }) {
2086
+ return operationsByTag.migrations.getBranchSchemaHistory({
2087
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2088
+ body: { page },
2089
+ ...this.extraProps
2090
+ });
2091
+ }
2092
+ compareBranchWithUserSchema({
2093
+ workspace,
2094
+ region,
2095
+ database,
2096
+ branch,
2097
+ schema,
2098
+ schemaOperations,
2099
+ branchOperations
2100
+ }) {
2101
+ return operationsByTag.migrations.compareBranchWithUserSchema({
2102
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2103
+ body: { schema, schemaOperations, branchOperations },
2104
+ ...this.extraProps
2105
+ });
2106
+ }
2107
+ compareBranchSchemas({
2108
+ workspace,
2109
+ region,
2110
+ database,
2111
+ branch,
2112
+ compare,
2113
+ sourceBranchOperations,
2114
+ targetBranchOperations
2115
+ }) {
2116
+ return operationsByTag.migrations.compareBranchSchemas({
2117
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
2118
+ body: { sourceBranchOperations, targetBranchOperations },
2119
+ ...this.extraProps
2120
+ });
2121
+ }
2122
+ updateBranchSchema({
2123
+ workspace,
2124
+ region,
2125
+ database,
2126
+ branch,
2127
+ migration
2128
+ }) {
2129
+ return operationsByTag.migrations.updateBranchSchema({
2130
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2131
+ body: migration,
1249
2132
  ...this.extraProps
1250
2133
  });
1251
2134
  }
1252
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1253
- return operationsByTag.branchSchema.executeBranchMigrationPlan({
1254
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1255
- body: migrationPlan,
2135
+ previewBranchSchemaEdit({
2136
+ workspace,
2137
+ region,
2138
+ database,
2139
+ branch,
2140
+ data
2141
+ }) {
2142
+ return operationsByTag.migrations.previewBranchSchemaEdit({
2143
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2144
+ body: data,
1256
2145
  ...this.extraProps
1257
2146
  });
1258
2147
  }
1259
- getBranchMigrationPlan(workspace, database, branch, schema) {
1260
- return operationsByTag.branchSchema.getBranchMigrationPlan({
1261
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1262
- body: schema,
2148
+ applyBranchSchemaEdit({
2149
+ workspace,
2150
+ region,
2151
+ database,
2152
+ branch,
2153
+ edits
2154
+ }) {
2155
+ return operationsByTag.migrations.applyBranchSchemaEdit({
2156
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2157
+ body: { edits },
1263
2158
  ...this.extraProps
1264
2159
  });
1265
2160
  }
1266
- compareBranchWithUserSchema(workspace, database, branch, schema) {
1267
- return operationsByTag.branchSchema.compareBranchWithUserSchema({
1268
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1269
- body: { schema },
2161
+ pushBranchMigrations({
2162
+ workspace,
2163
+ region,
2164
+ database,
2165
+ branch,
2166
+ migrations
2167
+ }) {
2168
+ return operationsByTag.migrations.pushBranchMigrations({
2169
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
2170
+ body: { migrations },
1270
2171
  ...this.extraProps
1271
2172
  });
1272
2173
  }
1273
- compareBranchSchemas(workspace, database, branch, branchName, schema) {
1274
- return operationsByTag.branchSchema.compareBranchSchemas({
1275
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1276
- body: { schema },
2174
+ }
2175
+ class DatabaseApi {
2176
+ constructor(extraProps) {
2177
+ this.extraProps = extraProps;
2178
+ }
2179
+ getDatabaseList({ workspace }) {
2180
+ return operationsByTag.databases.getDatabaseList({
2181
+ pathParams: { workspaceId: workspace },
1277
2182
  ...this.extraProps
1278
2183
  });
1279
2184
  }
1280
- updateBranchSchema(workspace, database, branch, migration) {
1281
- return operationsByTag.branchSchema.updateBranchSchema({
1282
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1283
- body: migration,
2185
+ createDatabase({
2186
+ workspace,
2187
+ database,
2188
+ data
2189
+ }) {
2190
+ return operationsByTag.databases.createDatabase({
2191
+ pathParams: { workspaceId: workspace, dbName: database },
2192
+ body: data,
1284
2193
  ...this.extraProps
1285
2194
  });
1286
2195
  }
1287
- previewBranchSchemaEdit(workspace, database, branch, migration) {
1288
- return operationsByTag.branchSchema.previewBranchSchemaEdit({
1289
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1290
- body: migration,
2196
+ deleteDatabase({
2197
+ workspace,
2198
+ database
2199
+ }) {
2200
+ return operationsByTag.databases.deleteDatabase({
2201
+ pathParams: { workspaceId: workspace, dbName: database },
1291
2202
  ...this.extraProps
1292
2203
  });
1293
2204
  }
1294
- applyBranchSchemaEdit(workspace, database, branch, edits) {
1295
- return operationsByTag.branchSchema.applyBranchSchemaEdit({
1296
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1297
- body: { edits },
2205
+ getDatabaseMetadata({
2206
+ workspace,
2207
+ database
2208
+ }) {
2209
+ return operationsByTag.databases.getDatabaseMetadata({
2210
+ pathParams: { workspaceId: workspace, dbName: database },
2211
+ ...this.extraProps
2212
+ });
2213
+ }
2214
+ updateDatabaseMetadata({
2215
+ workspace,
2216
+ database,
2217
+ metadata
2218
+ }) {
2219
+ return operationsByTag.databases.updateDatabaseMetadata({
2220
+ pathParams: { workspaceId: workspace, dbName: database },
2221
+ body: metadata,
2222
+ ...this.extraProps
2223
+ });
2224
+ }
2225
+ getDatabaseGithubSettings({
2226
+ workspace,
2227
+ database
2228
+ }) {
2229
+ return operationsByTag.databases.getDatabaseGithubSettings({
2230
+ pathParams: { workspaceId: workspace, dbName: database },
2231
+ ...this.extraProps
2232
+ });
2233
+ }
2234
+ updateDatabaseGithubSettings({
2235
+ workspace,
2236
+ database,
2237
+ settings
2238
+ }) {
2239
+ return operationsByTag.databases.updateDatabaseGithubSettings({
2240
+ pathParams: { workspaceId: workspace, dbName: database },
2241
+ body: settings,
1298
2242
  ...this.extraProps
1299
2243
  });
1300
2244
  }
1301
- getBranchSchemaHistory(workspace, database, branch, options = {}) {
1302
- return operationsByTag.branchSchema.getBranchSchemaHistory({
1303
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1304
- body: options,
2245
+ deleteDatabaseGithubSettings({
2246
+ workspace,
2247
+ database
2248
+ }) {
2249
+ return operationsByTag.databases.deleteDatabaseGithubSettings({
2250
+ pathParams: { workspaceId: workspace, dbName: database },
2251
+ ...this.extraProps
2252
+ });
2253
+ }
2254
+ listRegions({ workspace }) {
2255
+ return operationsByTag.databases.listRegions({
2256
+ pathParams: { workspaceId: workspace },
1305
2257
  ...this.extraProps
1306
2258
  });
1307
2259
  }
1308
2260
  }
1309
2261
 
1310
2262
  class XataApiPlugin {
1311
- async build(options) {
1312
- const { fetchImpl, apiKey } = await options.getFetchProps();
1313
- return new XataApiClient({ fetch: fetchImpl, apiKey });
2263
+ build(options) {
2264
+ return new XataApiClient(options);
1314
2265
  }
1315
2266
  }
1316
2267
 
@@ -1356,11 +2307,11 @@ class Page {
1356
2307
  async previousPage(size, offset) {
1357
2308
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1358
2309
  }
1359
- async firstPage(size, offset) {
1360
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
2310
+ async startPage(size, offset) {
2311
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1361
2312
  }
1362
- async lastPage(size, offset) {
1363
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
2313
+ async endPage(size, offset) {
2314
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1364
2315
  }
1365
2316
  hasNextPage() {
1366
2317
  return this.meta.page.more;
@@ -1372,7 +2323,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1372
2323
  const PAGINATION_MAX_OFFSET = 800;
1373
2324
  const PAGINATION_DEFAULT_OFFSET = 0;
1374
2325
  function isCursorPaginationOptions(options) {
1375
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
2326
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1376
2327
  }
1377
2328
  const _RecordArray = class extends Array {
1378
2329
  constructor(...args) {
@@ -1393,6 +2344,12 @@ const _RecordArray = class extends Array {
1393
2344
  toArray() {
1394
2345
  return new Array(...this);
1395
2346
  }
2347
+ toSerializable() {
2348
+ return JSON.parse(this.toString());
2349
+ }
2350
+ toString() {
2351
+ return JSON.stringify(this.toArray());
2352
+ }
1396
2353
  map(callbackfn, thisArg) {
1397
2354
  return this.toArray().map(callbackfn, thisArg);
1398
2355
  }
@@ -1404,12 +2361,12 @@ const _RecordArray = class extends Array {
1404
2361
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1405
2362
  return new _RecordArray(newPage);
1406
2363
  }
1407
- async firstPage(size, offset) {
1408
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
2364
+ async startPage(size, offset) {
2365
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1409
2366
  return new _RecordArray(newPage);
1410
2367
  }
1411
- async lastPage(size, offset) {
1412
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
2368
+ async endPage(size, offset) {
2369
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1413
2370
  return new _RecordArray(newPage);
1414
2371
  }
1415
2372
  hasNextPage() {
@@ -1464,8 +2421,10 @@ const _Query = class {
1464
2421
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1465
2422
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1466
2423
  __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2424
+ __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
1467
2425
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1468
2426
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2427
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1469
2428
  this.any = this.any.bind(this);
1470
2429
  this.all = this.all.bind(this);
1471
2430
  this.not = this.not.bind(this);
@@ -1593,15 +2552,15 @@ const _Query = class {
1593
2552
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1594
2553
  }
1595
2554
  nextPage(size, offset) {
1596
- return this.firstPage(size, offset);
2555
+ return this.startPage(size, offset);
1597
2556
  }
1598
2557
  previousPage(size, offset) {
1599
- return this.firstPage(size, offset);
2558
+ return this.startPage(size, offset);
1600
2559
  }
1601
- firstPage(size, offset) {
2560
+ startPage(size, offset) {
1602
2561
  return this.getPaginated({ pagination: { size, offset } });
1603
2562
  }
1604
- lastPage(size, offset) {
2563
+ endPage(size, offset) {
1605
2564
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1606
2565
  }
1607
2566
  hasNextPage() {
@@ -1625,7 +2584,7 @@ cleanFilterConstraint_fn = function(column, value) {
1625
2584
  };
1626
2585
  function cleanParent(data, parent) {
1627
2586
  if (isCursorPaginationOptions(data.pagination)) {
1628
- return { ...parent, sorting: void 0, filter: void 0 };
2587
+ return { ...parent, sort: void 0, filter: void 0 };
1629
2588
  }
1630
2589
  return parent;
1631
2590
  }
@@ -1684,7 +2643,8 @@ var __privateMethod$2 = (obj, member, method) => {
1684
2643
  __accessCheck$4(obj, member, "access private method");
1685
2644
  return method;
1686
2645
  };
1687
- var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
2646
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
2647
+ const BULK_OPERATION_MAX_SIZE = 1e3;
1688
2648
  class Repository extends Query {
1689
2649
  }
1690
2650
  class RestRepository extends Query {
@@ -1696,10 +2656,12 @@ class RestRepository extends Query {
1696
2656
  );
1697
2657
  __privateAdd$4(this, _insertRecordWithoutId);
1698
2658
  __privateAdd$4(this, _insertRecordWithId);
1699
- __privateAdd$4(this, _bulkInsertTableRecords);
2659
+ __privateAdd$4(this, _insertRecords);
1700
2660
  __privateAdd$4(this, _updateRecordWithID);
2661
+ __privateAdd$4(this, _updateRecords);
1701
2662
  __privateAdd$4(this, _upsertRecordWithID);
1702
2663
  __privateAdd$4(this, _deleteRecord);
2664
+ __privateAdd$4(this, _deleteRecords);
1703
2665
  __privateAdd$4(this, _setCacheQuery);
1704
2666
  __privateAdd$4(this, _getCacheQuery);
1705
2667
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1710,10 +2672,10 @@ class RestRepository extends Query {
1710
2672
  __privateAdd$4(this, _schemaTables$2, void 0);
1711
2673
  __privateAdd$4(this, _trace, void 0);
1712
2674
  __privateSet$4(this, _table, options.table);
1713
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1714
2675
  __privateSet$4(this, _db, options.db);
1715
2676
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1716
2677
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2678
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
1717
2679
  const trace = options.pluginOptions.trace ?? defaultTrace;
1718
2680
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1719
2681
  return trace(name, fn, {
@@ -1724,25 +2686,28 @@ class RestRepository extends Query {
1724
2686
  });
1725
2687
  });
1726
2688
  }
1727
- async create(a, b, c) {
2689
+ async create(a, b, c, d) {
1728
2690
  return __privateGet$4(this, _trace).call(this, "create", async () => {
2691
+ const ifVersion = parseIfVersion(b, c, d);
1729
2692
  if (Array.isArray(a)) {
1730
2693
  if (a.length === 0)
1731
2694
  return [];
1732
- const columns = isStringArray(b) ? b : void 0;
1733
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2695
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2696
+ const columns = isStringArray(b) ? b : ["*"];
2697
+ const result = await this.read(ids, columns);
2698
+ return result;
1734
2699
  }
1735
2700
  if (isString(a) && isObject(b)) {
1736
2701
  if (a === "")
1737
2702
  throw new Error("The id can't be empty");
1738
2703
  const columns = isStringArray(c) ? c : void 0;
1739
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
2704
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
1740
2705
  }
1741
2706
  if (isObject(a) && isString(a.id)) {
1742
2707
  if (a.id === "")
1743
2708
  throw new Error("The id can't be empty");
1744
2709
  const columns = isStringArray(b) ? b : void 0;
1745
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2710
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
1746
2711
  }
1747
2712
  if (isObject(a)) {
1748
2713
  const columns = isStringArray(b) ? b : void 0;
@@ -1767,17 +2732,17 @@ class RestRepository extends Query {
1767
2732
  }
1768
2733
  const id = extractId(a);
1769
2734
  if (id) {
1770
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1771
2735
  try {
1772
2736
  const response = await getRecord({
1773
2737
  pathParams: {
1774
2738
  workspace: "{workspaceId}",
1775
2739
  dbBranchName: "{dbBranch}",
2740
+ region: "{region}",
1776
2741
  tableName: __privateGet$4(this, _table),
1777
2742
  recordId: id
1778
2743
  },
1779
2744
  queryParams: { columns },
1780
- ...fetchProps
2745
+ ...__privateGet$4(this, _getFetchProps).call(this)
1781
2746
  });
1782
2747
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1783
2748
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -1810,31 +2775,42 @@ class RestRepository extends Query {
1810
2775
  return result;
1811
2776
  });
1812
2777
  }
1813
- async update(a, b, c) {
2778
+ async update(a, b, c, d) {
1814
2779
  return __privateGet$4(this, _trace).call(this, "update", async () => {
2780
+ const ifVersion = parseIfVersion(b, c, d);
1815
2781
  if (Array.isArray(a)) {
1816
2782
  if (a.length === 0)
1817
2783
  return [];
1818
- if (a.length > 100) {
1819
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1820
- }
2784
+ const existing = await this.read(a, ["id"]);
2785
+ const updates = a.filter((_item, index) => existing[index] !== null);
2786
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2787
+ ifVersion,
2788
+ upsert: false
2789
+ });
1821
2790
  const columns = isStringArray(b) ? b : ["*"];
1822
- return Promise.all(a.map((object) => this.update(object, columns)));
1823
- }
1824
- if (isString(a) && isObject(b)) {
1825
- const columns = isStringArray(c) ? c : void 0;
1826
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
2791
+ const result = await this.read(a, columns);
2792
+ return result;
1827
2793
  }
1828
- if (isObject(a) && isString(a.id)) {
1829
- const columns = isStringArray(b) ? b : void 0;
1830
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2794
+ try {
2795
+ if (isString(a) && isObject(b)) {
2796
+ const columns = isStringArray(c) ? c : void 0;
2797
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2798
+ }
2799
+ if (isObject(a) && isString(a.id)) {
2800
+ const columns = isStringArray(b) ? b : void 0;
2801
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2802
+ }
2803
+ } catch (error) {
2804
+ if (error.status === 422)
2805
+ return null;
2806
+ throw error;
1831
2807
  }
1832
2808
  throw new Error("Invalid arguments for update method");
1833
2809
  });
1834
2810
  }
1835
- async updateOrThrow(a, b, c) {
2811
+ async updateOrThrow(a, b, c, d) {
1836
2812
  return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
1837
- const result = await this.update(a, b, c);
2813
+ const result = await this.update(a, b, c, d);
1838
2814
  if (Array.isArray(result)) {
1839
2815
  const missingIds = compact(
1840
2816
  a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
@@ -1851,37 +2827,69 @@ class RestRepository extends Query {
1851
2827
  return result;
1852
2828
  });
1853
2829
  }
1854
- async createOrUpdate(a, b, c) {
2830
+ async createOrUpdate(a, b, c, d) {
1855
2831
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2832
+ const ifVersion = parseIfVersion(b, c, d);
1856
2833
  if (Array.isArray(a)) {
1857
2834
  if (a.length === 0)
1858
2835
  return [];
1859
- if (a.length > 100) {
1860
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1861
- }
2836
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2837
+ ifVersion,
2838
+ upsert: true
2839
+ });
1862
2840
  const columns = isStringArray(b) ? b : ["*"];
1863
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
2841
+ const result = await this.read(a, columns);
2842
+ return result;
1864
2843
  }
1865
2844
  if (isString(a) && isObject(b)) {
1866
2845
  const columns = isStringArray(c) ? c : void 0;
1867
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
2846
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1868
2847
  }
1869
2848
  if (isObject(a) && isString(a.id)) {
1870
2849
  const columns = isStringArray(c) ? c : void 0;
1871
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2850
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1872
2851
  }
1873
2852
  throw new Error("Invalid arguments for createOrUpdate method");
1874
2853
  });
1875
2854
  }
2855
+ async createOrReplace(a, b, c, d) {
2856
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2857
+ const ifVersion = parseIfVersion(b, c, d);
2858
+ if (Array.isArray(a)) {
2859
+ if (a.length === 0)
2860
+ return [];
2861
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2862
+ const columns = isStringArray(b) ? b : ["*"];
2863
+ const result = await this.read(ids, columns);
2864
+ return result;
2865
+ }
2866
+ if (isString(a) && isObject(b)) {
2867
+ const columns = isStringArray(c) ? c : void 0;
2868
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2869
+ }
2870
+ if (isObject(a) && isString(a.id)) {
2871
+ const columns = isStringArray(c) ? c : void 0;
2872
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2873
+ }
2874
+ throw new Error("Invalid arguments for createOrReplace method");
2875
+ });
2876
+ }
1876
2877
  async delete(a, b) {
1877
2878
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1878
2879
  if (Array.isArray(a)) {
1879
2880
  if (a.length === 0)
1880
2881
  return [];
1881
- if (a.length > 100) {
1882
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1883
- }
1884
- return Promise.all(a.map((id) => this.delete(id, b)));
2882
+ const ids = a.map((o) => {
2883
+ if (isString(o))
2884
+ return o;
2885
+ if (isString(o.id))
2886
+ return o.id;
2887
+ throw new Error("Invalid arguments for delete method");
2888
+ });
2889
+ const columns = isStringArray(b) ? b : ["*"];
2890
+ const result = await this.read(a, columns);
2891
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2892
+ return result;
1885
2893
  }
1886
2894
  if (isString(a)) {
1887
2895
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
@@ -1912,18 +2920,46 @@ class RestRepository extends Query {
1912
2920
  }
1913
2921
  async search(query, options = {}) {
1914
2922
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1915
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1916
2923
  const { records } = await searchTable({
1917
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2924
+ pathParams: {
2925
+ workspace: "{workspaceId}",
2926
+ dbBranchName: "{dbBranch}",
2927
+ region: "{region}",
2928
+ tableName: __privateGet$4(this, _table)
2929
+ },
1918
2930
  body: {
1919
2931
  query,
1920
2932
  fuzziness: options.fuzziness,
1921
2933
  prefix: options.prefix,
1922
2934
  highlight: options.highlight,
1923
2935
  filter: options.filter,
1924
- boosters: options.boosters
2936
+ boosters: options.boosters,
2937
+ page: options.page,
2938
+ target: options.target
2939
+ },
2940
+ ...__privateGet$4(this, _getFetchProps).call(this)
2941
+ });
2942
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2943
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2944
+ });
2945
+ }
2946
+ async vectorSearch(column, query, options) {
2947
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2948
+ const { records } = await vectorSearchTable({
2949
+ pathParams: {
2950
+ workspace: "{workspaceId}",
2951
+ dbBranchName: "{dbBranch}",
2952
+ region: "{region}",
2953
+ tableName: __privateGet$4(this, _table)
2954
+ },
2955
+ body: {
2956
+ column,
2957
+ queryVector: query,
2958
+ similarityFunction: options?.similarityFunction,
2959
+ size: options?.size,
2960
+ filter: options?.filter
1925
2961
  },
1926
- ...fetchProps
2962
+ ...__privateGet$4(this, _getFetchProps).call(this)
1927
2963
  });
1928
2964
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1929
2965
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
@@ -1931,11 +2967,15 @@ class RestRepository extends Query {
1931
2967
  }
1932
2968
  async aggregate(aggs, filter) {
1933
2969
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
1934
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1935
2970
  const result = await aggregateTable({
1936
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2971
+ pathParams: {
2972
+ workspace: "{workspaceId}",
2973
+ dbBranchName: "{dbBranch}",
2974
+ region: "{region}",
2975
+ tableName: __privateGet$4(this, _table)
2976
+ },
1937
2977
  body: { aggs, filter },
1938
- ...fetchProps
2978
+ ...__privateGet$4(this, _getFetchProps).call(this)
1939
2979
  });
1940
2980
  return result;
1941
2981
  });
@@ -1946,16 +2986,22 @@ class RestRepository extends Query {
1946
2986
  if (cacheQuery)
1947
2987
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1948
2988
  const data = query.getQueryOptions();
1949
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1950
2989
  const { meta, records: objects } = await queryTable({
1951
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2990
+ pathParams: {
2991
+ workspace: "{workspaceId}",
2992
+ dbBranchName: "{dbBranch}",
2993
+ region: "{region}",
2994
+ tableName: __privateGet$4(this, _table)
2995
+ },
1952
2996
  body: {
1953
2997
  filter: cleanFilter(data.filter),
1954
2998
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1955
2999
  page: data.pagination,
1956
- columns: data.columns ?? ["*"]
3000
+ columns: data.columns ?? ["*"],
3001
+ consistency: data.consistency
1957
3002
  },
1958
- ...fetchProps
3003
+ fetchOptions: data.fetchOptions,
3004
+ ...__privateGet$4(this, _getFetchProps).call(this)
1959
3005
  });
1960
3006
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1961
3007
  const records = objects.map(
@@ -1968,21 +3014,55 @@ class RestRepository extends Query {
1968
3014
  async summarizeTable(query, summaries, summariesFilter) {
1969
3015
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
1970
3016
  const data = query.getQueryOptions();
1971
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1972
3017
  const result = await summarizeTable({
1973
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
3018
+ pathParams: {
3019
+ workspace: "{workspaceId}",
3020
+ dbBranchName: "{dbBranch}",
3021
+ region: "{region}",
3022
+ tableName: __privateGet$4(this, _table)
3023
+ },
1974
3024
  body: {
1975
3025
  filter: cleanFilter(data.filter),
1976
3026
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1977
3027
  columns: data.columns,
3028
+ consistency: data.consistency,
3029
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
1978
3030
  summaries,
1979
3031
  summariesFilter
1980
3032
  },
1981
- ...fetchProps
3033
+ ...__privateGet$4(this, _getFetchProps).call(this)
1982
3034
  });
1983
3035
  return result;
1984
3036
  });
1985
3037
  }
3038
+ ask(question, options) {
3039
+ const params = {
3040
+ pathParams: {
3041
+ workspace: "{workspaceId}",
3042
+ dbBranchName: "{dbBranch}",
3043
+ region: "{region}",
3044
+ tableName: __privateGet$4(this, _table)
3045
+ },
3046
+ body: {
3047
+ question,
3048
+ ...options
3049
+ },
3050
+ ...__privateGet$4(this, _getFetchProps).call(this)
3051
+ };
3052
+ if (options?.onMessage) {
3053
+ fetchSSERequest({
3054
+ endpoint: "dataPlane",
3055
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
3056
+ method: "POST",
3057
+ onMessage: (message) => {
3058
+ options.onMessage?.({ answer: message.text, records: message.records });
3059
+ },
3060
+ ...params
3061
+ });
3062
+ } else {
3063
+ return askTable(params);
3064
+ }
3065
+ }
1986
3066
  }
1987
3067
  _table = new WeakMap();
1988
3068
  _getFetchProps = new WeakMap();
@@ -1992,65 +3072,83 @@ _schemaTables$2 = new WeakMap();
1992
3072
  _trace = new WeakMap();
1993
3073
  _insertRecordWithoutId = new WeakSet();
1994
3074
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1995
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1996
3075
  const record = transformObjectLinks(object);
1997
3076
  const response = await insertRecord({
1998
3077
  pathParams: {
1999
3078
  workspace: "{workspaceId}",
2000
3079
  dbBranchName: "{dbBranch}",
3080
+ region: "{region}",
2001
3081
  tableName: __privateGet$4(this, _table)
2002
3082
  },
2003
3083
  queryParams: { columns },
2004
3084
  body: record,
2005
- ...fetchProps
3085
+ ...__privateGet$4(this, _getFetchProps).call(this)
2006
3086
  });
2007
3087
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2008
3088
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2009
3089
  };
2010
3090
  _insertRecordWithId = new WeakSet();
2011
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
2012
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
3091
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2013
3092
  const record = transformObjectLinks(object);
2014
3093
  const response = await insertRecordWithID({
2015
3094
  pathParams: {
2016
3095
  workspace: "{workspaceId}",
2017
3096
  dbBranchName: "{dbBranch}",
3097
+ region: "{region}",
2018
3098
  tableName: __privateGet$4(this, _table),
2019
3099
  recordId
2020
3100
  },
2021
3101
  body: record,
2022
- queryParams: { createOnly: true, columns },
2023
- ...fetchProps
3102
+ queryParams: { createOnly, columns, ifVersion },
3103
+ ...__privateGet$4(this, _getFetchProps).call(this)
2024
3104
  });
2025
3105
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2026
3106
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2027
3107
  };
2028
- _bulkInsertTableRecords = new WeakSet();
2029
- bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
2030
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2031
- const records = objects.map((object) => transformObjectLinks(object));
2032
- const response = await bulkInsertTableRecords({
2033
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2034
- queryParams: { columns },
2035
- body: { records },
2036
- ...fetchProps
2037
- });
2038
- if (!isResponseWithRecords(response)) {
2039
- throw new Error("Request included columns but server didn't include them");
3108
+ _insertRecords = new WeakSet();
3109
+ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
3110
+ const chunkedOperations = chunk(
3111
+ objects.map((object) => ({
3112
+ insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
3113
+ })),
3114
+ BULK_OPERATION_MAX_SIZE
3115
+ );
3116
+ const ids = [];
3117
+ for (const operations of chunkedOperations) {
3118
+ const { results } = await branchTransaction({
3119
+ pathParams: {
3120
+ workspace: "{workspaceId}",
3121
+ dbBranchName: "{dbBranch}",
3122
+ region: "{region}"
3123
+ },
3124
+ body: { operations },
3125
+ ...__privateGet$4(this, _getFetchProps).call(this)
3126
+ });
3127
+ for (const result of results) {
3128
+ if (result.operation === "insert") {
3129
+ ids.push(result.id);
3130
+ } else {
3131
+ ids.push(null);
3132
+ }
3133
+ }
2040
3134
  }
2041
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2042
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
3135
+ return ids;
2043
3136
  };
2044
3137
  _updateRecordWithID = new WeakSet();
2045
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2046
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2047
- const record = transformObjectLinks(object);
3138
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
3139
+ const { id: _id, ...record } = transformObjectLinks(object);
2048
3140
  try {
2049
3141
  const response = await updateRecordWithID({
2050
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2051
- queryParams: { columns },
3142
+ pathParams: {
3143
+ workspace: "{workspaceId}",
3144
+ dbBranchName: "{dbBranch}",
3145
+ region: "{region}",
3146
+ tableName: __privateGet$4(this, _table),
3147
+ recordId
3148
+ },
3149
+ queryParams: { columns, ifVersion },
2052
3150
  body: record,
2053
- ...fetchProps
3151
+ ...__privateGet$4(this, _getFetchProps).call(this)
2054
3152
  });
2055
3153
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2056
3154
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2061,26 +3159,65 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2061
3159
  throw e;
2062
3160
  }
2063
3161
  };
3162
+ _updateRecords = new WeakSet();
3163
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
3164
+ const chunkedOperations = chunk(
3165
+ objects.map(({ id, ...object }) => ({
3166
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
3167
+ })),
3168
+ BULK_OPERATION_MAX_SIZE
3169
+ );
3170
+ const ids = [];
3171
+ for (const operations of chunkedOperations) {
3172
+ const { results } = await branchTransaction({
3173
+ pathParams: {
3174
+ workspace: "{workspaceId}",
3175
+ dbBranchName: "{dbBranch}",
3176
+ region: "{region}"
3177
+ },
3178
+ body: { operations },
3179
+ ...__privateGet$4(this, _getFetchProps).call(this)
3180
+ });
3181
+ for (const result of results) {
3182
+ if (result.operation === "update") {
3183
+ ids.push(result.id);
3184
+ } else {
3185
+ ids.push(null);
3186
+ }
3187
+ }
3188
+ }
3189
+ return ids;
3190
+ };
2064
3191
  _upsertRecordWithID = new WeakSet();
2065
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2066
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
3192
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2067
3193
  const response = await upsertRecordWithID({
2068
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2069
- queryParams: { columns },
3194
+ pathParams: {
3195
+ workspace: "{workspaceId}",
3196
+ dbBranchName: "{dbBranch}",
3197
+ region: "{region}",
3198
+ tableName: __privateGet$4(this, _table),
3199
+ recordId
3200
+ },
3201
+ queryParams: { columns, ifVersion },
2070
3202
  body: object,
2071
- ...fetchProps
3203
+ ...__privateGet$4(this, _getFetchProps).call(this)
2072
3204
  });
2073
3205
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2074
3206
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2075
3207
  };
2076
3208
  _deleteRecord = new WeakSet();
2077
3209
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2078
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2079
3210
  try {
2080
3211
  const response = await deleteRecord({
2081
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
3212
+ pathParams: {
3213
+ workspace: "{workspaceId}",
3214
+ dbBranchName: "{dbBranch}",
3215
+ region: "{region}",
3216
+ tableName: __privateGet$4(this, _table),
3217
+ recordId
3218
+ },
2082
3219
  queryParams: { columns },
2083
- ...fetchProps
3220
+ ...__privateGet$4(this, _getFetchProps).call(this)
2084
3221
  });
2085
3222
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2086
3223
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2091,17 +3228,36 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2091
3228
  throw e;
2092
3229
  }
2093
3230
  };
3231
+ _deleteRecords = new WeakSet();
3232
+ deleteRecords_fn = async function(recordIds) {
3233
+ const chunkedOperations = chunk(
3234
+ recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
3235
+ BULK_OPERATION_MAX_SIZE
3236
+ );
3237
+ for (const operations of chunkedOperations) {
3238
+ await branchTransaction({
3239
+ pathParams: {
3240
+ workspace: "{workspaceId}",
3241
+ dbBranchName: "{dbBranch}",
3242
+ region: "{region}"
3243
+ },
3244
+ body: { operations },
3245
+ ...__privateGet$4(this, _getFetchProps).call(this)
3246
+ });
3247
+ }
3248
+ };
2094
3249
  _setCacheQuery = new WeakSet();
2095
3250
  setCacheQuery_fn = async function(query, meta, records) {
2096
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
3251
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2097
3252
  };
2098
3253
  _getCacheQuery = new WeakSet();
2099
3254
  getCacheQuery_fn = async function(query) {
2100
3255
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2101
- const result = await __privateGet$4(this, _cache).get(key);
3256
+ const result = await __privateGet$4(this, _cache)?.get(key);
2102
3257
  if (!result)
2103
3258
  return null;
2104
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
3259
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
3260
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2105
3261
  if (ttl < 0)
2106
3262
  return null;
2107
3263
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2111,10 +3267,9 @@ _getSchemaTables$1 = new WeakSet();
2111
3267
  getSchemaTables_fn$1 = async function() {
2112
3268
  if (__privateGet$4(this, _schemaTables$2))
2113
3269
  return __privateGet$4(this, _schemaTables$2);
2114
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2115
3270
  const { schema } = await getBranchDetails({
2116
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2117
- ...fetchProps
3271
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3272
+ ...__privateGet$4(this, _getFetchProps).call(this)
2118
3273
  });
2119
3274
  __privateSet$4(this, _schemaTables$2, schema.tables);
2120
3275
  return schema.tables;
@@ -2127,23 +3282,23 @@ const transformObjectLinks = (object) => {
2127
3282
  }, {});
2128
3283
  };
2129
3284
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2130
- const result = {};
3285
+ const data = {};
2131
3286
  const { xata, ...rest } = object ?? {};
2132
- Object.assign(result, rest);
3287
+ Object.assign(data, rest);
2133
3288
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2134
3289
  if (!columns)
2135
3290
  console.error(`Table ${table} not found in schema`);
2136
3291
  for (const column of columns ?? []) {
2137
3292
  if (!isValidColumn(selectedColumns, column))
2138
3293
  continue;
2139
- const value = result[column.name];
3294
+ const value = data[column.name];
2140
3295
  switch (column.type) {
2141
3296
  case "datetime": {
2142
- const date = value !== void 0 ? new Date(value) : void 0;
2143
- if (date && isNaN(date.getTime())) {
3297
+ const date = value !== void 0 ? new Date(value) : null;
3298
+ if (date !== null && isNaN(date.getTime())) {
2144
3299
  console.error(`Failed to parse date ${value} for field ${column.name}`);
2145
- } else if (date) {
2146
- result[column.name] = date;
3300
+ } else {
3301
+ data[column.name] = date;
2147
3302
  }
2148
3303
  break;
2149
3304
  }
@@ -2162,41 +3317,52 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2162
3317
  }
2163
3318
  return acc;
2164
3319
  }, []);
2165
- result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
3320
+ data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2166
3321
  } else {
2167
- result[column.name] = null;
3322
+ data[column.name] = null;
2168
3323
  }
2169
3324
  break;
2170
3325
  }
2171
3326
  default:
2172
- result[column.name] = value ?? null;
3327
+ data[column.name] = value ?? null;
2173
3328
  if (column.notNull === true && value === null) {
2174
3329
  console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2175
3330
  }
2176
3331
  break;
2177
3332
  }
2178
3333
  }
2179
- result.read = function(columns2) {
2180
- return db[table].read(result["id"], columns2);
3334
+ const record = { ...data };
3335
+ record.read = function(columns2) {
3336
+ return db[table].read(record["id"], columns2);
3337
+ };
3338
+ record.update = function(data2, b, c) {
3339
+ const columns2 = isStringArray(b) ? b : ["*"];
3340
+ const ifVersion = parseIfVersion(b, c);
3341
+ return db[table].update(record["id"], data2, columns2, { ifVersion });
2181
3342
  };
2182
- result.update = function(data, columns2) {
2183
- return db[table].update(result["id"], data, columns2);
3343
+ record.replace = function(data2, b, c) {
3344
+ const columns2 = isStringArray(b) ? b : ["*"];
3345
+ const ifVersion = parseIfVersion(b, c);
3346
+ return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2184
3347
  };
2185
- result.delete = function() {
2186
- return db[table].delete(result["id"]);
3348
+ record.delete = function() {
3349
+ return db[table].delete(record["id"]);
2187
3350
  };
2188
- result.getMetadata = function() {
3351
+ record.getMetadata = function() {
2189
3352
  return xata;
2190
3353
  };
2191
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
2192
- Object.defineProperty(result, prop, { enumerable: false });
3354
+ record.toSerializable = function() {
3355
+ return JSON.parse(JSON.stringify(transformObjectLinks(data)));
3356
+ };
3357
+ record.toString = function() {
3358
+ return JSON.stringify(transformObjectLinks(data));
3359
+ };
3360
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3361
+ Object.defineProperty(record, prop, { enumerable: false });
2193
3362
  }
2194
- Object.freeze(result);
2195
- return result;
3363
+ Object.freeze(record);
3364
+ return record;
2196
3365
  };
2197
- function isResponseWithRecords(value) {
2198
- return isObject(value) && Array.isArray(value.records);
2199
- }
2200
3366
  function extractId(value) {
2201
3367
  if (isString(value))
2202
3368
  return value;
@@ -2213,6 +3379,14 @@ function isValidColumn(columns, column) {
2213
3379
  }
2214
3380
  return columns.includes(column.name);
2215
3381
  }
3382
+ function parseIfVersion(...args) {
3383
+ for (const arg of args) {
3384
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
3385
+ return arg.ifVersion;
3386
+ }
3387
+ }
3388
+ return void 0;
3389
+ }
2216
3390
 
2217
3391
  var __accessCheck$3 = (obj, member, msg) => {
2218
3392
  if (!member.has(obj))
@@ -2371,19 +3545,19 @@ class SearchPlugin extends XataPlugin {
2371
3545
  __privateAdd$1(this, _schemaTables, void 0);
2372
3546
  __privateSet$1(this, _schemaTables, schemaTables);
2373
3547
  }
2374
- build({ getFetchProps }) {
3548
+ build(pluginOptions) {
2375
3549
  return {
2376
3550
  all: async (query, options = {}) => {
2377
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2378
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3551
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3552
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
2379
3553
  return records.map((record) => {
2380
3554
  const { table = "orphan" } = record.xata;
2381
3555
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
2382
3556
  });
2383
3557
  },
2384
3558
  byTable: async (query, options = {}) => {
2385
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2386
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3559
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3560
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
2387
3561
  return records.reduce((acc, record) => {
2388
3562
  const { table = "orphan" } = record.xata;
2389
3563
  const items = acc[table] ?? [];
@@ -2396,108 +3570,39 @@ class SearchPlugin extends XataPlugin {
2396
3570
  }
2397
3571
  _schemaTables = new WeakMap();
2398
3572
  _search = new WeakSet();
2399
- search_fn = async function(query, options, getFetchProps) {
2400
- const fetchProps = await getFetchProps();
2401
- const { tables, fuzziness, highlight, prefix } = options ?? {};
3573
+ search_fn = async function(query, options, pluginOptions) {
3574
+ const { tables, fuzziness, highlight, prefix, page } = options ?? {};
2402
3575
  const { records } = await searchBranch({
2403
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2404
- body: { tables, query, fuzziness, prefix, highlight },
2405
- ...fetchProps
3576
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3577
+ body: { tables, query, fuzziness, prefix, highlight, page },
3578
+ ...pluginOptions
2406
3579
  });
2407
3580
  return records;
2408
3581
  };
2409
3582
  _getSchemaTables = new WeakSet();
2410
- getSchemaTables_fn = async function(getFetchProps) {
3583
+ getSchemaTables_fn = async function(pluginOptions) {
2411
3584
  if (__privateGet$1(this, _schemaTables))
2412
3585
  return __privateGet$1(this, _schemaTables);
2413
- const fetchProps = await getFetchProps();
2414
3586
  const { schema } = await getBranchDetails({
2415
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2416
- ...fetchProps
3587
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3588
+ ...pluginOptions
2417
3589
  });
2418
3590
  __privateSet$1(this, _schemaTables, schema.tables);
2419
3591
  return schema.tables;
2420
3592
  };
2421
3593
 
2422
- const isBranchStrategyBuilder = (strategy) => {
2423
- return typeof strategy === "function";
2424
- };
2425
-
2426
- async function getCurrentBranchName(options) {
2427
- const { branch, envBranch } = getEnvironment();
2428
- if (branch) {
2429
- const details = await getDatabaseBranch(branch, options);
2430
- if (details)
2431
- return branch;
2432
- console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
2433
- }
2434
- const gitBranch = envBranch || await getGitBranch();
2435
- return resolveXataBranch(gitBranch, options);
2436
- }
2437
- async function getCurrentBranchDetails(options) {
2438
- const branch = await getCurrentBranchName(options);
2439
- return getDatabaseBranch(branch, options);
2440
- }
2441
- async function resolveXataBranch(gitBranch, options) {
2442
- const databaseURL = options?.databaseURL || getDatabaseURL();
2443
- const apiKey = options?.apiKey || getAPIKey();
2444
- if (!databaseURL)
2445
- throw new Error(
2446
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2447
- );
2448
- if (!apiKey)
2449
- throw new Error(
2450
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2451
- );
2452
- const [protocol, , host, , dbName] = databaseURL.split("/");
2453
- const [workspace] = host.split(".");
2454
- const { fallbackBranch } = getEnvironment();
2455
- const { branch } = await resolveBranch({
2456
- apiKey,
2457
- apiUrl: databaseURL,
2458
- fetchImpl: getFetchImplementation(options?.fetchImpl),
2459
- workspacesApiUrl: `${protocol}//${host}`,
2460
- pathParams: { dbName, workspace },
2461
- queryParams: { gitBranch, fallbackBranch },
2462
- trace: defaultTrace
2463
- });
2464
- return branch;
2465
- }
2466
- async function getDatabaseBranch(branch, options) {
2467
- const databaseURL = options?.databaseURL || getDatabaseURL();
2468
- const apiKey = options?.apiKey || getAPIKey();
2469
- if (!databaseURL)
2470
- throw new Error(
2471
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2472
- );
2473
- if (!apiKey)
2474
- throw new Error(
2475
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2476
- );
2477
- const [protocol, , host, , database] = databaseURL.split("/");
2478
- const [workspace] = host.split(".");
2479
- const dbBranchName = `${database}:${branch}`;
2480
- try {
2481
- return await getBranchDetails({
2482
- apiKey,
2483
- apiUrl: databaseURL,
2484
- fetchImpl: getFetchImplementation(options?.fetchImpl),
2485
- workspacesApiUrl: `${protocol}//${host}`,
2486
- pathParams: { dbBranchName, workspace },
2487
- trace: defaultTrace
2488
- });
2489
- } catch (err) {
2490
- if (isObject(err) && err.status === 404)
2491
- return null;
2492
- throw err;
2493
- }
2494
- }
2495
- function getDatabaseURL() {
2496
- try {
2497
- const { databaseURL } = getEnvironment();
2498
- return databaseURL;
2499
- } catch (err) {
2500
- return void 0;
3594
+ class TransactionPlugin extends XataPlugin {
3595
+ build(pluginOptions) {
3596
+ return {
3597
+ run: async (operations) => {
3598
+ const response = await branchTransaction({
3599
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3600
+ body: { operations },
3601
+ ...pluginOptions
3602
+ });
3603
+ return response;
3604
+ }
3605
+ };
2501
3606
  }
2502
3607
  }
2503
3608
 
@@ -2524,88 +3629,117 @@ var __privateMethod = (obj, member, method) => {
2524
3629
  return method;
2525
3630
  };
2526
3631
  const buildClient = (plugins) => {
2527
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3632
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
2528
3633
  return _a = class {
2529
3634
  constructor(options = {}, schemaTables) {
2530
3635
  __privateAdd(this, _parseOptions);
2531
3636
  __privateAdd(this, _getFetchProps);
2532
- __privateAdd(this, _evaluateBranch);
2533
- __privateAdd(this, _branch, void 0);
2534
3637
  __privateAdd(this, _options, void 0);
2535
3638
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
2536
3639
  __privateSet(this, _options, safeOptions);
2537
3640
  const pluginOptions = {
2538
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3641
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2539
3642
  cache: safeOptions.cache,
2540
- trace: safeOptions.trace
3643
+ host: safeOptions.host
2541
3644
  };
2542
3645
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2543
3646
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3647
+ const transactions = new TransactionPlugin().build(pluginOptions);
2544
3648
  this.db = db;
2545
3649
  this.search = search;
3650
+ this.transactions = transactions;
2546
3651
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
2547
3652
  if (namespace === void 0)
2548
3653
  continue;
2549
- const result = namespace.build(pluginOptions);
2550
- if (result instanceof Promise) {
2551
- void result.then((namespace2) => {
2552
- this[key] = namespace2;
2553
- });
2554
- } else {
2555
- this[key] = result;
2556
- }
3654
+ this[key] = namespace.build(pluginOptions);
2557
3655
  }
2558
3656
  }
2559
3657
  async getConfig() {
2560
3658
  const databaseURL = __privateGet(this, _options).databaseURL;
2561
- const branch = await __privateGet(this, _options).branch();
3659
+ const branch = __privateGet(this, _options).branch;
2562
3660
  return { databaseURL, branch };
2563
3661
  }
2564
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3662
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3663
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3664
+ const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3665
+ if (isBrowser && !enableBrowser) {
3666
+ throw new Error(
3667
+ "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."
3668
+ );
3669
+ }
2565
3670
  const fetch = getFetchImplementation(options?.fetch);
2566
3671
  const databaseURL = options?.databaseURL || getDatabaseURL();
2567
3672
  const apiKey = options?.apiKey || getAPIKey();
2568
3673
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2569
3674
  const trace = options?.trace ?? defaultTrace;
2570
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
3675
+ const clientName = options?.clientName;
3676
+ const host = options?.host ?? "production";
3677
+ const xataAgentExtra = options?.xataAgentExtra;
2571
3678
  if (!apiKey) {
2572
3679
  throw new Error("Option apiKey is required");
2573
3680
  }
2574
3681
  if (!databaseURL) {
2575
3682
  throw new Error("Option databaseURL is required");
2576
3683
  }
2577
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2578
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2579
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2580
- if (!branchValue)
2581
- throw new Error("Unable to resolve branch value");
3684
+ const envBranch = getBranch();
3685
+ const previewBranch = getPreviewBranch();
3686
+ const branch = options?.branch || previewBranch || envBranch || "main";
3687
+ if (!!previewBranch && branch !== previewBranch) {
3688
+ console.warn(
3689
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
3690
+ );
3691
+ } else if (!!envBranch && branch !== envBranch) {
3692
+ console.warn(
3693
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3694
+ );
3695
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
3696
+ console.warn(
3697
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3698
+ );
3699
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
3700
+ console.warn(
3701
+ `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.`
3702
+ );
3703
+ } else {
3704
+ console.log(`Using branch ${branch}`);
3705
+ }
3706
+ return {
3707
+ fetch,
3708
+ databaseURL,
3709
+ apiKey,
3710
+ branch,
3711
+ cache,
3712
+ trace,
3713
+ host,
3714
+ clientID: generateUUID(),
3715
+ enableBrowser,
3716
+ clientName,
3717
+ xataAgentExtra
3718
+ };
3719
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3720
+ fetch,
3721
+ apiKey,
3722
+ databaseURL,
3723
+ branch,
3724
+ trace,
3725
+ clientID,
3726
+ clientName,
3727
+ xataAgentExtra
3728
+ }) {
2582
3729
  return {
2583
- fetchImpl: fetch,
3730
+ fetch,
2584
3731
  apiKey,
2585
3732
  apiUrl: "",
2586
3733
  workspacesApiUrl: (path, params) => {
2587
3734
  const hasBranch = params.dbBranchName ?? params.branch;
2588
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
3735
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
2589
3736
  return databaseURL + newPath;
2590
3737
  },
2591
- trace
2592
- };
2593
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2594
- if (__privateGet(this, _branch))
2595
- return __privateGet(this, _branch);
2596
- if (param === void 0)
2597
- return void 0;
2598
- const strategies = Array.isArray(param) ? [...param] : [param];
2599
- const evaluateBranch = async (strategy) => {
2600
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3738
+ trace,
3739
+ clientID,
3740
+ clientName,
3741
+ xataAgentExtra
2601
3742
  };
2602
- for await (const strategy of strategies) {
2603
- const branch = await evaluateBranch(strategy);
2604
- if (branch) {
2605
- __privateSet(this, _branch, branch);
2606
- return branch;
2607
- }
2608
- }
2609
3743
  }, _a;
2610
3744
  };
2611
3745
  class BaseClient extends buildClient() {
@@ -2679,7 +3813,7 @@ const deserialize = (json) => {
2679
3813
  };
2680
3814
 
2681
3815
  function buildWorkerRunner(config) {
2682
- return function xataWorker(name, _worker) {
3816
+ return function xataWorker(name, worker) {
2683
3817
  return async (...args) => {
2684
3818
  const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2685
3819
  const result = await fetch(url, {
@@ -2700,5 +3834,5 @@ class XataError extends Error {
2700
3834
  }
2701
3835
  }
2702
3836
 
2703
- 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, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, 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, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, 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 };
3837
+ 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, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, 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, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
2704
3838
  //# sourceMappingURL=index.mjs.map