@xata.io/client 0.0.0-alpha.vfeb24b1 → 0.0.0-alpha.vfecc463

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