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