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

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