@xata.io/client 0.0.0-alpha.veeb7143 → 0.0.0-alpha.veec6d2a

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