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

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