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