@xata.io/client 0.0.0-alpha.vfc5c289 → 0.0.0-alpha.vfc99020

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