@xata.io/client 0.0.0-alpha.vfbe46c7 → 0.0.0-alpha.vfc4a5e4

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