@xata.io/client 0.0.0-alpha.vf6f2567 → 0.0.0-alpha.vf70b95a

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