@xata.io/client 0.0.0-alpha.vfe4ae98 → 0.0.0-alpha.vfe896b3

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