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