@xata.io/client 0.0.0-alpha.vfe9bed6 → 0.0.0-alpha.vfe9f27c

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