@xata.io/client 0.0.0-alpha.vf7fccd9 → 0.0.0-alpha.vf85aa00

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