@xata.io/client 0.0.0-alpha.vfe4a947 → 0.0.0-alpha.vfe4b459

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