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

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