@xata.io/client 0.0.0-alpha.vfbde008 → 0.0.0-alpha.vfc08a49f5b2f1e93114c76b97e7da90408e84709

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
@@ -18,7 +18,8 @@ const TraceAttributes = {
18
18
  HTTP_METHOD: "http.method",
19
19
  HTTP_URL: "http.url",
20
20
  HTTP_ROUTE: "http.route",
21
- HTTP_TARGET: "http.target"
21
+ HTTP_TARGET: "http.target",
22
+ CLOUDFLARE_RAY_ID: "cf.ray"
22
23
  };
23
24
 
24
25
  function notEmpty(value) {
@@ -27,8 +28,18 @@ function notEmpty(value) {
27
28
  function compact(arr) {
28
29
  return arr.filter(notEmpty);
29
30
  }
31
+ function compactObject(obj) {
32
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
33
+ }
34
+ function isBlob(value) {
35
+ try {
36
+ return value instanceof Blob;
37
+ } catch (error) {
38
+ return false;
39
+ }
40
+ }
30
41
  function isObject(value) {
31
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
42
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
32
43
  }
33
44
  function isDefined(value) {
34
45
  return value !== null && value !== void 0;
@@ -83,6 +94,27 @@ function chunk(array, chunkSize) {
83
94
  async function timeout(ms) {
84
95
  return new Promise((resolve) => setTimeout(resolve, ms));
85
96
  }
97
+ function timeoutWithCancel(ms) {
98
+ let timeoutId;
99
+ const promise = new Promise((resolve) => {
100
+ timeoutId = setTimeout(() => {
101
+ resolve();
102
+ }, ms);
103
+ });
104
+ return {
105
+ cancel: () => clearTimeout(timeoutId),
106
+ promise
107
+ };
108
+ }
109
+ function promiseMap(inputValues, mapper) {
110
+ const reducer = (acc$, inputValue) => acc$.then(
111
+ (acc) => mapper(inputValue).then((result) => {
112
+ acc.push(result);
113
+ return acc;
114
+ })
115
+ );
116
+ return inputValues.reduce(reducer, Promise.resolve([]));
117
+ }
86
118
 
87
119
  function getEnvironment() {
88
120
  try {
@@ -91,8 +123,10 @@ function getEnvironment() {
91
123
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
92
124
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
93
125
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
94
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
95
- fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
126
+ deployPreview: process.env.XATA_PREVIEW,
127
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
128
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
129
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
96
130
  };
97
131
  }
98
132
  } catch (err) {
@@ -103,8 +137,10 @@ function getEnvironment() {
103
137
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
104
138
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
105
139
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
106
- envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
107
- fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
140
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
141
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
142
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
143
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
108
144
  };
109
145
  }
110
146
  } catch (err) {
@@ -113,8 +149,10 @@ function getEnvironment() {
113
149
  apiKey: getGlobalApiKey(),
114
150
  databaseURL: getGlobalDatabaseURL(),
115
151
  branch: getGlobalBranch(),
116
- envBranch: void 0,
117
- fallbackBranch: getGlobalFallbackBranch()
152
+ deployPreview: void 0,
153
+ deployPreviewBranch: void 0,
154
+ vercelGitCommitRef: void 0,
155
+ vercelGitRepoOwner: void 0
118
156
  };
119
157
  }
120
158
  function getEnableBrowserVariable() {
@@ -157,107 +195,123 @@ function getGlobalBranch() {
157
195
  return void 0;
158
196
  }
159
197
  }
160
- function getGlobalFallbackBranch() {
198
+ function getDatabaseURL() {
161
199
  try {
162
- return XATA_FALLBACK_BRANCH;
200
+ const { databaseURL } = getEnvironment();
201
+ return databaseURL;
163
202
  } catch (err) {
164
203
  return void 0;
165
204
  }
166
205
  }
167
- async function getGitBranch() {
168
- const cmd = ["git", "branch", "--show-current"];
169
- const fullCmd = cmd.join(" ");
170
- const nodeModule = ["child", "process"].join("_");
171
- const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
206
+ function getAPIKey() {
172
207
  try {
173
- const { execSync } = await import(nodeModule);
174
- return execSync(fullCmd, execOptions).toString().trim();
208
+ const { apiKey } = getEnvironment();
209
+ return apiKey;
175
210
  } catch (err) {
211
+ return void 0;
176
212
  }
213
+ }
214
+ function getBranch() {
177
215
  try {
178
- if (isObject(Deno)) {
179
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
180
- return new TextDecoder().decode(await process2.output()).trim();
181
- }
216
+ const { branch } = getEnvironment();
217
+ return branch;
182
218
  } catch (err) {
219
+ return void 0;
183
220
  }
184
221
  }
185
-
186
- function getAPIKey() {
222
+ function buildPreviewBranchName({ org, branch }) {
223
+ return `preview-${org}-${branch}`;
224
+ }
225
+ function getPreviewBranch() {
187
226
  try {
188
- const { apiKey } = getEnvironment();
189
- return apiKey;
227
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
228
+ if (deployPreviewBranch)
229
+ return deployPreviewBranch;
230
+ switch (deployPreview) {
231
+ case "vercel": {
232
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
233
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
234
+ return void 0;
235
+ }
236
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
237
+ }
238
+ }
239
+ return void 0;
190
240
  } catch (err) {
191
241
  return void 0;
192
242
  }
193
243
  }
194
244
 
195
- var __accessCheck$8 = (obj, member, msg) => {
245
+ var __accessCheck$7 = (obj, member, msg) => {
196
246
  if (!member.has(obj))
197
247
  throw TypeError("Cannot " + msg);
198
248
  };
199
- var __privateGet$8 = (obj, member, getter) => {
200
- __accessCheck$8(obj, member, "read from private field");
249
+ var __privateGet$7 = (obj, member, getter) => {
250
+ __accessCheck$7(obj, member, "read from private field");
201
251
  return getter ? getter.call(obj) : member.get(obj);
202
252
  };
203
- var __privateAdd$8 = (obj, member, value) => {
253
+ var __privateAdd$7 = (obj, member, value) => {
204
254
  if (member.has(obj))
205
255
  throw TypeError("Cannot add the same private member more than once");
206
256
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
207
257
  };
208
- var __privateSet$8 = (obj, member, value, setter) => {
209
- __accessCheck$8(obj, member, "write to private field");
258
+ var __privateSet$7 = (obj, member, value, setter) => {
259
+ __accessCheck$7(obj, member, "write to private field");
210
260
  setter ? setter.call(obj, value) : member.set(obj, value);
211
261
  return value;
212
262
  };
213
263
  var __privateMethod$4 = (obj, member, method) => {
214
- __accessCheck$8(obj, member, "access private method");
264
+ __accessCheck$7(obj, member, "access private method");
215
265
  return method;
216
266
  };
217
267
  var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
268
+ const REQUEST_TIMEOUT = 5 * 60 * 1e3;
218
269
  function getFetchImplementation(userFetch) {
219
270
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
220
- const fetchImpl = userFetch ?? globalFetch;
271
+ const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
272
+ const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
221
273
  if (!fetchImpl) {
222
- throw new Error(
223
- `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
224
- );
274
+ throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
225
275
  }
226
276
  return fetchImpl;
227
277
  }
228
278
  class ApiRequestPool {
229
279
  constructor(concurrency = 10) {
230
- __privateAdd$8(this, _enqueue);
231
- __privateAdd$8(this, _fetch, void 0);
232
- __privateAdd$8(this, _queue, void 0);
233
- __privateAdd$8(this, _concurrency, void 0);
234
- __privateSet$8(this, _queue, []);
235
- __privateSet$8(this, _concurrency, concurrency);
280
+ __privateAdd$7(this, _enqueue);
281
+ __privateAdd$7(this, _fetch, void 0);
282
+ __privateAdd$7(this, _queue, void 0);
283
+ __privateAdd$7(this, _concurrency, void 0);
284
+ __privateSet$7(this, _queue, []);
285
+ __privateSet$7(this, _concurrency, concurrency);
236
286
  this.running = 0;
237
287
  this.started = 0;
238
288
  }
239
289
  setFetch(fetch2) {
240
- __privateSet$8(this, _fetch, fetch2);
290
+ __privateSet$7(this, _fetch, fetch2);
241
291
  }
242
292
  getFetch() {
243
- if (!__privateGet$8(this, _fetch)) {
293
+ if (!__privateGet$7(this, _fetch)) {
244
294
  throw new Error("Fetch not set");
245
295
  }
246
- return __privateGet$8(this, _fetch);
296
+ return __privateGet$7(this, _fetch);
247
297
  }
248
298
  request(url, options) {
249
- const start = new Date();
250
- const fetch2 = this.getFetch();
299
+ const start = /* @__PURE__ */ new Date();
300
+ const fetchImpl = this.getFetch();
251
301
  const runRequest = async (stalled = false) => {
252
- const response = await fetch2(url, options);
302
+ const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
303
+ const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
304
+ if (!response) {
305
+ throw new Error("Request timed out");
306
+ }
253
307
  if (response.status === 429) {
254
308
  const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
255
309
  await timeout(rateLimitReset * 1e3);
256
310
  return await runRequest(true);
257
311
  }
258
312
  if (stalled) {
259
- const stalledTime = new Date().getTime() - start.getTime();
260
- console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
313
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
314
+ console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
261
315
  }
262
316
  return response;
263
317
  };
@@ -271,19 +325,19 @@ _queue = new WeakMap();
271
325
  _concurrency = new WeakMap();
272
326
  _enqueue = new WeakSet();
273
327
  enqueue_fn = function(task) {
274
- const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
328
+ const promise = new Promise((resolve) => __privateGet$7(this, _queue).push(resolve)).finally(() => {
275
329
  this.started--;
276
330
  this.running++;
277
331
  }).then(() => task()).finally(() => {
278
332
  this.running--;
279
- const next = __privateGet$8(this, _queue).shift();
333
+ const next = __privateGet$7(this, _queue).shift();
280
334
  if (next !== void 0) {
281
335
  this.started++;
282
336
  next();
283
337
  }
284
338
  });
285
- if (this.running + this.started < __privateGet$8(this, _concurrency)) {
286
- const next = __privateGet$8(this, _queue).shift();
339
+ if (this.running + this.started < __privateGet$7(this, _concurrency)) {
340
+ const next = __privateGet$7(this, _queue).shift();
287
341
  if (next !== void 0) {
288
342
  this.started++;
289
343
  next();
@@ -299,7 +353,180 @@ function generateUUID() {
299
353
  });
300
354
  }
301
355
 
302
- const VERSION = "0.22.1";
356
+ async function getBytes(stream, onChunk) {
357
+ const reader = stream.getReader();
358
+ let result;
359
+ while (!(result = await reader.read()).done) {
360
+ onChunk(result.value);
361
+ }
362
+ }
363
+ function getLines(onLine) {
364
+ let buffer;
365
+ let position;
366
+ let fieldLength;
367
+ let discardTrailingNewline = false;
368
+ return function onChunk(arr) {
369
+ if (buffer === void 0) {
370
+ buffer = arr;
371
+ position = 0;
372
+ fieldLength = -1;
373
+ } else {
374
+ buffer = concat(buffer, arr);
375
+ }
376
+ const bufLength = buffer.length;
377
+ let lineStart = 0;
378
+ while (position < bufLength) {
379
+ if (discardTrailingNewline) {
380
+ if (buffer[position] === 10 /* NewLine */) {
381
+ lineStart = ++position;
382
+ }
383
+ discardTrailingNewline = false;
384
+ }
385
+ let lineEnd = -1;
386
+ for (; position < bufLength && lineEnd === -1; ++position) {
387
+ switch (buffer[position]) {
388
+ case 58 /* Colon */:
389
+ if (fieldLength === -1) {
390
+ fieldLength = position - lineStart;
391
+ }
392
+ break;
393
+ case 13 /* CarriageReturn */:
394
+ discardTrailingNewline = true;
395
+ case 10 /* NewLine */:
396
+ lineEnd = position;
397
+ break;
398
+ }
399
+ }
400
+ if (lineEnd === -1) {
401
+ break;
402
+ }
403
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
404
+ lineStart = position;
405
+ fieldLength = -1;
406
+ }
407
+ if (lineStart === bufLength) {
408
+ buffer = void 0;
409
+ } else if (lineStart !== 0) {
410
+ buffer = buffer.subarray(lineStart);
411
+ position -= lineStart;
412
+ }
413
+ };
414
+ }
415
+ function getMessages(onId, onRetry, onMessage) {
416
+ let message = newMessage();
417
+ const decoder = new TextDecoder();
418
+ return function onLine(line, fieldLength) {
419
+ if (line.length === 0) {
420
+ onMessage?.(message);
421
+ message = newMessage();
422
+ } else if (fieldLength > 0) {
423
+ const field = decoder.decode(line.subarray(0, fieldLength));
424
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
425
+ const value = decoder.decode(line.subarray(valueOffset));
426
+ switch (field) {
427
+ case "data":
428
+ message.data = message.data ? message.data + "\n" + value : value;
429
+ break;
430
+ case "event":
431
+ message.event = value;
432
+ break;
433
+ case "id":
434
+ onId(message.id = value);
435
+ break;
436
+ case "retry":
437
+ const retry = parseInt(value, 10);
438
+ if (!isNaN(retry)) {
439
+ onRetry(message.retry = retry);
440
+ }
441
+ break;
442
+ }
443
+ }
444
+ };
445
+ }
446
+ function concat(a, b) {
447
+ const res = new Uint8Array(a.length + b.length);
448
+ res.set(a);
449
+ res.set(b, a.length);
450
+ return res;
451
+ }
452
+ function newMessage() {
453
+ return {
454
+ data: "",
455
+ event: "",
456
+ id: "",
457
+ retry: void 0
458
+ };
459
+ }
460
+ const EventStreamContentType = "text/event-stream";
461
+ const LastEventId = "last-event-id";
462
+ function fetchEventSource(input, {
463
+ signal: inputSignal,
464
+ headers: inputHeaders,
465
+ onopen: inputOnOpen,
466
+ onmessage,
467
+ onclose,
468
+ onerror,
469
+ fetch: inputFetch,
470
+ ...rest
471
+ }) {
472
+ return new Promise((resolve, reject) => {
473
+ const headers = { ...inputHeaders };
474
+ if (!headers.accept) {
475
+ headers.accept = EventStreamContentType;
476
+ }
477
+ let curRequestController;
478
+ function dispose() {
479
+ curRequestController.abort();
480
+ }
481
+ inputSignal?.addEventListener("abort", () => {
482
+ dispose();
483
+ resolve();
484
+ });
485
+ const fetchImpl = inputFetch ?? fetch;
486
+ const onopen = inputOnOpen ?? defaultOnOpen;
487
+ async function create() {
488
+ curRequestController = new AbortController();
489
+ try {
490
+ const response = await fetchImpl(input, {
491
+ ...rest,
492
+ headers,
493
+ signal: curRequestController.signal
494
+ });
495
+ await onopen(response);
496
+ await getBytes(
497
+ response.body,
498
+ getLines(
499
+ getMessages(
500
+ (id) => {
501
+ if (id) {
502
+ headers[LastEventId] = id;
503
+ } else {
504
+ delete headers[LastEventId];
505
+ }
506
+ },
507
+ (_retry) => {
508
+ },
509
+ onmessage
510
+ )
511
+ )
512
+ );
513
+ onclose?.();
514
+ dispose();
515
+ resolve();
516
+ } catch (err) {
517
+ }
518
+ }
519
+ create();
520
+ });
521
+ }
522
+ function defaultOnOpen(response) {
523
+ const contentType = response.headers?.get("content-type");
524
+ if (!contentType?.startsWith(EventStreamContentType)) {
525
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
526
+ }
527
+ }
528
+
529
+ const VERSION = "0.28.4";
303
530
 
304
531
  class ErrorWithCause extends Error {
305
532
  constructor(message, options) {
@@ -342,6 +569,67 @@ function getMessage(data) {
342
569
  }
343
570
  }
344
571
 
572
+ function getHostUrl(provider, type) {
573
+ if (isHostProviderAlias(provider)) {
574
+ return providers[provider][type];
575
+ } else if (isHostProviderBuilder(provider)) {
576
+ return provider[type];
577
+ }
578
+ throw new Error("Invalid API provider");
579
+ }
580
+ const providers = {
581
+ production: {
582
+ main: "https://api.xata.io",
583
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
584
+ },
585
+ staging: {
586
+ main: "https://api.staging-xata.dev",
587
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
588
+ },
589
+ dev: {
590
+ main: "https://api.dev-xata.dev",
591
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
592
+ },
593
+ local: {
594
+ main: "http://localhost:6001",
595
+ workspaces: "http://{workspaceId}.{region}.localhost:6001"
596
+ }
597
+ };
598
+ function isHostProviderAlias(alias) {
599
+ return isString(alias) && Object.keys(providers).includes(alias);
600
+ }
601
+ function isHostProviderBuilder(builder) {
602
+ return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
603
+ }
604
+ function parseProviderString(provider = "production") {
605
+ if (isHostProviderAlias(provider)) {
606
+ return provider;
607
+ }
608
+ const [main, workspaces] = provider.split(",");
609
+ if (!main || !workspaces)
610
+ return null;
611
+ return { main, workspaces };
612
+ }
613
+ function buildProviderString(provider) {
614
+ if (isHostProviderAlias(provider))
615
+ return provider;
616
+ return `${provider.main},${provider.workspaces}`;
617
+ }
618
+ function parseWorkspacesUrlParts(url) {
619
+ if (!isString(url))
620
+ return null;
621
+ const matches = {
622
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
623
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
624
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
625
+ local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
626
+ };
627
+ const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
628
+ if (!isHostProviderAlias(host) || !match)
629
+ return null;
630
+ return { workspace: match[1], region: match[2], host };
631
+ }
632
+
345
633
  const pool = new ApiRequestPool();
346
634
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
347
635
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
@@ -357,6 +645,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
357
645
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
358
646
  };
359
647
  function buildBaseUrl({
648
+ method,
360
649
  endpoint,
361
650
  path,
362
651
  workspacesApiUrl,
@@ -364,7 +653,24 @@ function buildBaseUrl({
364
653
  pathParams = {}
365
654
  }) {
366
655
  if (endpoint === "dataPlane") {
367
- const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
656
+ let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
657
+ if (method.toUpperCase() === "PUT" && [
658
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
659
+ "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
660
+ ].includes(path)) {
661
+ const { host } = parseWorkspacesUrlParts(url) ?? {};
662
+ switch (host) {
663
+ case "production":
664
+ url = url.replace("xata.sh", "upload.xata.sh");
665
+ break;
666
+ case "staging":
667
+ url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
668
+ break;
669
+ case "dev":
670
+ url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
671
+ break;
672
+ }
673
+ }
368
674
  const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
369
675
  return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
370
676
  }
@@ -375,6 +681,18 @@ function hostHeader(url) {
375
681
  const { groups } = pattern.exec(url) ?? {};
376
682
  return groups?.host ? { Host: groups.host } : {};
377
683
  }
684
+ async function parseBody(body, headers) {
685
+ if (!isDefined(body))
686
+ return void 0;
687
+ if (isBlob(body) || typeof body.text === "function") {
688
+ return body;
689
+ }
690
+ const { "Content-Type": contentType } = headers ?? {};
691
+ if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
692
+ return JSON.stringify(body);
693
+ }
694
+ return body;
695
+ }
378
696
  const defaultClientID = generateUUID();
379
697
  async function fetch$1({
380
698
  url: path,
@@ -383,7 +701,7 @@ async function fetch$1({
383
701
  headers: customHeaders,
384
702
  pathParams,
385
703
  queryParams,
386
- fetchImpl,
704
+ fetch: fetch2,
387
705
  apiKey,
388
706
  endpoint,
389
707
  apiUrl,
@@ -394,15 +712,16 @@ async function fetch$1({
394
712
  sessionID,
395
713
  clientName,
396
714
  xataAgentExtra,
397
- fetchOptions = {}
715
+ fetchOptions = {},
716
+ rawResponse = false
398
717
  }) {
399
- pool.setFetch(fetchImpl);
718
+ pool.setFetch(fetch2);
400
719
  return await trace(
401
720
  `${method.toUpperCase()} ${path}`,
402
721
  async ({ setAttributes }) => {
403
- const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
722
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
404
723
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
405
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
724
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
406
725
  setAttributes({
407
726
  [TraceAttributes.HTTP_URL]: url,
408
727
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
@@ -413,7 +732,7 @@ async function fetch$1({
413
732
  isDefined(clientName) ? ["service", clientName] : void 0,
414
733
  ...Object.entries(xataAgentExtra ?? {})
415
734
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
416
- const headers = {
735
+ const headers = compactObject({
417
736
  "Accept-Encoding": "identity",
418
737
  "Content-Type": "application/json",
419
738
  "X-Xata-Client-ID": clientID ?? defaultClientID,
@@ -422,11 +741,11 @@ async function fetch$1({
422
741
  ...customHeaders,
423
742
  ...hostHeader(fullUrl),
424
743
  Authorization: `Bearer ${apiKey}`
425
- };
744
+ });
426
745
  const response = await pool.request(url, {
427
746
  ...fetchOptions,
428
747
  method: method.toUpperCase(),
429
- body: body ? JSON.stringify(body) : void 0,
748
+ body: await parseBody(body, headers),
430
749
  headers,
431
750
  signal
432
751
  });
@@ -437,8 +756,12 @@ async function fetch$1({
437
756
  [TraceAttributes.HTTP_REQUEST_ID]: requestId,
438
757
  [TraceAttributes.HTTP_STATUS_CODE]: response.status,
439
758
  [TraceAttributes.HTTP_HOST]: host,
440
- [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
759
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
760
+ [TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
441
761
  });
762
+ const message = response.headers?.get("x-xata-message");
763
+ if (message)
764
+ console.warn(message);
442
765
  if (response.status === 204) {
443
766
  return {};
444
767
  }
@@ -446,7 +769,7 @@ async function fetch$1({
446
769
  throw new FetcherError(response.status, "Rate limit exceeded", requestId);
447
770
  }
448
771
  try {
449
- const jsonResponse = await response.json();
772
+ const jsonResponse = rawResponse ? await response.blob() : await response.json();
450
773
  if (response.ok) {
451
774
  return jsonResponse;
452
775
  }
@@ -458,6 +781,59 @@ async function fetch$1({
458
781
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
459
782
  );
460
783
  }
784
+ function fetchSSERequest({
785
+ url: path,
786
+ method,
787
+ body,
788
+ headers: customHeaders,
789
+ pathParams,
790
+ queryParams,
791
+ fetch: fetch2,
792
+ apiKey,
793
+ endpoint,
794
+ apiUrl,
795
+ workspacesApiUrl,
796
+ onMessage,
797
+ onError,
798
+ onClose,
799
+ signal,
800
+ clientID,
801
+ sessionID,
802
+ clientName,
803
+ xataAgentExtra
804
+ }) {
805
+ const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
806
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
807
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
808
+ void fetchEventSource(url, {
809
+ method,
810
+ body: JSON.stringify(body),
811
+ fetch: fetch2,
812
+ signal,
813
+ headers: {
814
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
815
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
816
+ "X-Xata-Agent": compact([
817
+ ["client", "TS_SDK"],
818
+ ["version", VERSION],
819
+ isDefined(clientName) ? ["service", clientName] : void 0,
820
+ ...Object.entries(xataAgentExtra ?? {})
821
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
822
+ ...customHeaders,
823
+ Authorization: `Bearer ${apiKey}`,
824
+ "Content-Type": "application/json"
825
+ },
826
+ onmessage(ev) {
827
+ onMessage?.(JSON.parse(ev.data));
828
+ },
829
+ onerror(ev) {
830
+ onError?.(JSON.parse(ev.data));
831
+ },
832
+ onclose() {
833
+ onClose?.();
834
+ }
835
+ });
836
+ }
461
837
  function parseUrl(url) {
462
838
  try {
463
839
  const { host, protocol } = new URL(url);
@@ -469,6 +845,20 @@ function parseUrl(url) {
469
845
 
470
846
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
471
847
 
848
+ const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
849
+ const pgRollStatus = (variables, signal) => dataPlaneFetch({
850
+ url: "/db/{dbBranchName}/pgroll/status",
851
+ method: "get",
852
+ ...variables,
853
+ signal
854
+ });
855
+ const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
856
+ url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
857
+ method: "get",
858
+ ...variables,
859
+ signal
860
+ });
861
+ const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
472
862
  const getBranchList = (variables, signal) => dataPlaneFetch({
473
863
  url: "/dbs/{dbName}",
474
864
  method: "get",
@@ -488,6 +878,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
488
878
  ...variables,
489
879
  signal
490
880
  });
881
+ const getSchema = (variables, signal) => dataPlaneFetch({
882
+ url: "/db/{dbBranchName}/schema",
883
+ method: "get",
884
+ ...variables,
885
+ signal
886
+ });
887
+ const copyBranch = (variables, signal) => dataPlaneFetch({
888
+ url: "/db/{dbBranchName}/copy",
889
+ method: "post",
890
+ ...variables,
891
+ signal
892
+ });
491
893
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
492
894
  url: "/db/{dbBranchName}/metadata",
493
895
  method: "put",
@@ -537,6 +939,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
537
939
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
538
940
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
539
941
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
942
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
540
943
  const createTable = (variables, signal) => dataPlaneFetch({
541
944
  url: "/db/{dbBranchName}/tables/{tableName}",
542
945
  method: "put",
@@ -581,6 +984,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
581
984
  });
582
985
  const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
583
986
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
987
+ const getFileItem = (variables, signal) => dataPlaneFetch({
988
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
989
+ method: "get",
990
+ ...variables,
991
+ signal
992
+ });
993
+ const putFileItem = (variables, signal) => dataPlaneFetch({
994
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
995
+ method: "put",
996
+ ...variables,
997
+ signal
998
+ });
999
+ const deleteFileItem = (variables, signal) => dataPlaneFetch({
1000
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
1001
+ method: "delete",
1002
+ ...variables,
1003
+ signal
1004
+ });
1005
+ const getFile = (variables, signal) => dataPlaneFetch({
1006
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
1007
+ method: "get",
1008
+ ...variables,
1009
+ signal
1010
+ });
1011
+ const putFile = (variables, signal) => dataPlaneFetch({
1012
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
1013
+ method: "put",
1014
+ ...variables,
1015
+ signal
1016
+ });
1017
+ const deleteFile = (variables, signal) => dataPlaneFetch({
1018
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
1019
+ method: "delete",
1020
+ ...variables,
1021
+ signal
1022
+ });
584
1023
  const getRecord = (variables, signal) => dataPlaneFetch({
585
1024
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
586
1025
  method: "get",
@@ -611,14 +1050,44 @@ const searchTable = (variables, signal) => dataPlaneFetch({
611
1050
  signal
612
1051
  });
613
1052
  const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
1053
+ const askTable = (variables, signal) => dataPlaneFetch({
1054
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
1055
+ method: "post",
1056
+ ...variables,
1057
+ signal
1058
+ });
1059
+ const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
614
1060
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
615
1061
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
1062
+ const fileAccess = (variables, signal) => dataPlaneFetch({
1063
+ url: "/file/{fileId}",
1064
+ method: "get",
1065
+ ...variables,
1066
+ signal
1067
+ });
1068
+ const fileUpload = (variables, signal) => dataPlaneFetch({
1069
+ url: "/file/{fileId}",
1070
+ method: "put",
1071
+ ...variables,
1072
+ signal
1073
+ });
1074
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
1075
+ url: "/db/{dbBranchName}/sql",
1076
+ method: "post",
1077
+ ...variables,
1078
+ signal
1079
+ });
616
1080
  const operationsByTag$2 = {
617
1081
  branch: {
1082
+ applyMigration,
1083
+ pgRollStatus,
1084
+ pgRollJobStatus,
1085
+ pgRollMigrationHistory,
618
1086
  getBranchList,
619
1087
  getBranchDetails,
620
1088
  createBranch,
621
1089
  deleteBranch,
1090
+ copyBranch,
622
1091
  updateBranchMetadata,
623
1092
  getBranchMetadata,
624
1093
  getBranchStats,
@@ -628,6 +1097,7 @@ const operationsByTag$2 = {
628
1097
  resolveBranch
629
1098
  },
630
1099
  migrations: {
1100
+ getSchema,
631
1101
  getBranchMigrationHistory,
632
1102
  getBranchMigrationPlan,
633
1103
  executeBranchMigrationPlan,
@@ -636,7 +1106,8 @@ const operationsByTag$2 = {
636
1106
  compareBranchSchemas,
637
1107
  updateBranchSchema,
638
1108
  previewBranchSchemaEdit,
639
- applyBranchSchemaEdit
1109
+ applyBranchSchemaEdit,
1110
+ pushBranchMigrations
640
1111
  },
641
1112
  migrationRequests: {
642
1113
  queryMigrationRequests,
@@ -670,11 +1141,24 @@ const operationsByTag$2 = {
670
1141
  deleteRecord,
671
1142
  bulkInsertTableRecords
672
1143
  },
673
- searchAndFilter: { queryTable, searchBranch, searchTable, vectorSearchTable, summarizeTable, aggregateTable }
1144
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
1145
+ searchAndFilter: {
1146
+ queryTable,
1147
+ searchBranch,
1148
+ searchTable,
1149
+ vectorSearchTable,
1150
+ askTable,
1151
+ askTableSession,
1152
+ summarizeTable,
1153
+ aggregateTable
1154
+ },
1155
+ sql: { sqlQuery }
674
1156
  };
675
1157
 
676
1158
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
677
1159
 
1160
+ const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
1161
+ const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
678
1162
  const getUser = (variables, signal) => controlPlaneFetch({
679
1163
  url: "/user",
680
1164
  method: "get",
@@ -711,6 +1195,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
711
1195
  ...variables,
712
1196
  signal
713
1197
  });
1198
+ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
1199
+ url: "/user/oauth/clients",
1200
+ method: "get",
1201
+ ...variables,
1202
+ signal
1203
+ });
1204
+ const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
1205
+ url: "/user/oauth/clients/{clientId}",
1206
+ method: "delete",
1207
+ ...variables,
1208
+ signal
1209
+ });
1210
+ const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
1211
+ url: "/user/oauth/tokens",
1212
+ method: "get",
1213
+ ...variables,
1214
+ signal
1215
+ });
1216
+ const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
1217
+ url: "/user/oauth/tokens/{token}",
1218
+ method: "delete",
1219
+ ...variables,
1220
+ signal
1221
+ });
1222
+ const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
714
1223
  const getWorkspacesList = (variables, signal) => controlPlaneFetch({
715
1224
  url: "/workspaces",
716
1225
  method: "get",
@@ -754,6 +1263,15 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
754
1263
  const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
755
1264
  const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
756
1265
  const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
1266
+ const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
1267
+ const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
1268
+ const getCluster = (variables, signal) => controlPlaneFetch({
1269
+ url: "/workspaces/{workspaceId}/clusters/{clusterId}",
1270
+ method: "get",
1271
+ ...variables,
1272
+ signal
1273
+ });
1274
+ const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
757
1275
  const getDatabaseList = (variables, signal) => controlPlaneFetch({
758
1276
  url: "/workspaces/{workspaceId}/dbs",
759
1277
  method: "get",
@@ -769,6 +1287,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
769
1287
  });
770
1288
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
771
1289
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1290
+ const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
772
1291
  const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
773
1292
  const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
774
1293
  const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
@@ -779,6 +1298,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
779
1298
  signal
780
1299
  });
781
1300
  const operationsByTag$1 = {
1301
+ oAuth: {
1302
+ getAuthorizationCode,
1303
+ grantAuthorizationCode,
1304
+ getUserOAuthClients,
1305
+ deleteUserOAuthClient,
1306
+ getUserOAuthAccessTokens,
1307
+ deleteOAuthAccessToken,
1308
+ updateOAuthAccessToken
1309
+ },
782
1310
  users: { getUser, updateUser, deleteUser },
783
1311
  authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
784
1312
  workspaces: {
@@ -798,12 +1326,14 @@ const operationsByTag$1 = {
798
1326
  acceptWorkspaceMemberInvite,
799
1327
  resendWorkspaceMemberInvite
800
1328
  },
1329
+ xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
801
1330
  databases: {
802
1331
  getDatabaseList,
803
1332
  createDatabase,
804
1333
  deleteDatabase,
805
1334
  getDatabaseMetadata,
806
1335
  updateDatabaseMetadata,
1336
+ renameDatabase,
807
1337
  getDatabaseGithubSettings,
808
1338
  updateDatabaseGithubSettings,
809
1339
  deleteDatabaseGithubSettings,
@@ -813,75 +1343,8 @@ const operationsByTag$1 = {
813
1343
 
814
1344
  const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
815
1345
 
816
- function getHostUrl(provider, type) {
817
- if (isHostProviderAlias(provider)) {
818
- return providers[provider][type];
819
- } else if (isHostProviderBuilder(provider)) {
820
- return provider[type];
821
- }
822
- throw new Error("Invalid API provider");
823
- }
824
- const providers = {
825
- production: {
826
- main: "https://api.xata.io",
827
- workspaces: "https://{workspaceId}.{region}.xata.sh"
828
- },
829
- staging: {
830
- main: "https://api.staging-xata.dev",
831
- workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
832
- }
833
- };
834
- function isHostProviderAlias(alias) {
835
- return isString(alias) && Object.keys(providers).includes(alias);
836
- }
837
- function isHostProviderBuilder(builder) {
838
- return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
839
- }
840
- function parseProviderString(provider = "production") {
841
- if (isHostProviderAlias(provider)) {
842
- return provider;
843
- }
844
- const [main, workspaces] = provider.split(",");
845
- if (!main || !workspaces)
846
- return null;
847
- return { main, workspaces };
848
- }
849
- function parseWorkspacesUrlParts(url) {
850
- if (!isString(url))
851
- return null;
852
- const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
853
- const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
854
- const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
855
- const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
856
- const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
857
- if (!match)
858
- return null;
859
- return { workspace: match[1], region: match[2] };
860
- }
861
-
862
- var __accessCheck$7 = (obj, member, msg) => {
863
- if (!member.has(obj))
864
- throw TypeError("Cannot " + msg);
865
- };
866
- var __privateGet$7 = (obj, member, getter) => {
867
- __accessCheck$7(obj, member, "read from private field");
868
- return getter ? getter.call(obj) : member.get(obj);
869
- };
870
- var __privateAdd$7 = (obj, member, value) => {
871
- if (member.has(obj))
872
- throw TypeError("Cannot add the same private member more than once");
873
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
874
- };
875
- var __privateSet$7 = (obj, member, value, setter) => {
876
- __accessCheck$7(obj, member, "write to private field");
877
- setter ? setter.call(obj, value) : member.set(obj, value);
878
- return value;
879
- };
880
- var _extraProps, _namespaces;
881
- class XataApiClient {
1346
+ const buildApiClient = () => class {
882
1347
  constructor(options = {}) {
883
- __privateAdd$7(this, _extraProps, void 0);
884
- __privateAdd$7(this, _namespaces, {});
885
1348
  const provider = options.host ?? "production";
886
1349
  const apiKey = options.apiKey ?? getAPIKey();
887
1350
  const trace = options.trace ?? defaultTrace;
@@ -889,1056 +1352,240 @@ class XataApiClient {
889
1352
  if (!apiKey) {
890
1353
  throw new Error("Could not resolve a valid apiKey");
891
1354
  }
892
- __privateSet$7(this, _extraProps, {
1355
+ const extraProps = {
893
1356
  apiUrl: getHostUrl(provider, "main"),
894
1357
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
895
- fetchImpl: getFetchImplementation(options.fetch),
1358
+ fetch: getFetchImplementation(options.fetch),
896
1359
  apiKey,
897
1360
  trace,
898
1361
  clientName: options.clientName,
899
1362
  xataAgentExtra: options.xataAgentExtra,
900
1363
  clientID
1364
+ };
1365
+ return new Proxy(this, {
1366
+ get: (_target, namespace) => {
1367
+ if (operationsByTag[namespace] === void 0) {
1368
+ return void 0;
1369
+ }
1370
+ return new Proxy(
1371
+ {},
1372
+ {
1373
+ get: (_target2, operation) => {
1374
+ if (operationsByTag[namespace][operation] === void 0) {
1375
+ return void 0;
1376
+ }
1377
+ const method = operationsByTag[namespace][operation];
1378
+ return async (params) => {
1379
+ return await method({ ...params, ...extraProps });
1380
+ };
1381
+ }
1382
+ }
1383
+ );
1384
+ }
901
1385
  });
902
1386
  }
903
- get user() {
904
- if (!__privateGet$7(this, _namespaces).user)
905
- __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
906
- return __privateGet$7(this, _namespaces).user;
907
- }
908
- get authentication() {
909
- if (!__privateGet$7(this, _namespaces).authentication)
910
- __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
911
- return __privateGet$7(this, _namespaces).authentication;
912
- }
913
- get workspaces() {
914
- if (!__privateGet$7(this, _namespaces).workspaces)
915
- __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
916
- return __privateGet$7(this, _namespaces).workspaces;
917
- }
918
- get invites() {
919
- if (!__privateGet$7(this, _namespaces).invites)
920
- __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
921
- return __privateGet$7(this, _namespaces).invites;
922
- }
923
- get database() {
924
- if (!__privateGet$7(this, _namespaces).database)
925
- __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
926
- return __privateGet$7(this, _namespaces).database;
927
- }
928
- get branches() {
929
- if (!__privateGet$7(this, _namespaces).branches)
930
- __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
931
- return __privateGet$7(this, _namespaces).branches;
932
- }
933
- get migrations() {
934
- if (!__privateGet$7(this, _namespaces).migrations)
935
- __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
936
- return __privateGet$7(this, _namespaces).migrations;
937
- }
938
- get migrationRequests() {
939
- if (!__privateGet$7(this, _namespaces).migrationRequests)
940
- __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
941
- return __privateGet$7(this, _namespaces).migrationRequests;
942
- }
943
- get tables() {
944
- if (!__privateGet$7(this, _namespaces).tables)
945
- __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
946
- return __privateGet$7(this, _namespaces).tables;
947
- }
948
- get records() {
949
- if (!__privateGet$7(this, _namespaces).records)
950
- __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
951
- return __privateGet$7(this, _namespaces).records;
952
- }
953
- get searchAndFilter() {
954
- if (!__privateGet$7(this, _namespaces).searchAndFilter)
955
- __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
956
- return __privateGet$7(this, _namespaces).searchAndFilter;
957
- }
958
- }
959
- _extraProps = new WeakMap();
960
- _namespaces = new WeakMap();
961
- class UserApi {
962
- constructor(extraProps) {
963
- this.extraProps = extraProps;
964
- }
965
- getUser() {
966
- return operationsByTag.users.getUser({ ...this.extraProps });
967
- }
968
- updateUser({ user }) {
969
- return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
970
- }
971
- deleteUser() {
972
- return operationsByTag.users.deleteUser({ ...this.extraProps });
973
- }
974
- }
975
- class AuthenticationApi {
976
- constructor(extraProps) {
977
- this.extraProps = extraProps;
978
- }
979
- getUserAPIKeys() {
980
- return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
981
- }
982
- createUserAPIKey({ name }) {
983
- return operationsByTag.authentication.createUserAPIKey({
984
- pathParams: { keyName: name },
985
- ...this.extraProps
986
- });
987
- }
988
- deleteUserAPIKey({ name }) {
989
- return operationsByTag.authentication.deleteUserAPIKey({
990
- pathParams: { keyName: name },
991
- ...this.extraProps
992
- });
993
- }
994
- }
995
- class WorkspaceApi {
996
- constructor(extraProps) {
997
- this.extraProps = extraProps;
998
- }
999
- getWorkspacesList() {
1000
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
1001
- }
1002
- createWorkspace({ data }) {
1003
- return operationsByTag.workspaces.createWorkspace({
1004
- body: data,
1005
- ...this.extraProps
1006
- });
1007
- }
1008
- getWorkspace({ workspace }) {
1009
- return operationsByTag.workspaces.getWorkspace({
1010
- pathParams: { workspaceId: workspace },
1011
- ...this.extraProps
1012
- });
1013
- }
1014
- updateWorkspace({
1015
- workspace,
1016
- update
1017
- }) {
1018
- return operationsByTag.workspaces.updateWorkspace({
1019
- pathParams: { workspaceId: workspace },
1020
- body: update,
1021
- ...this.extraProps
1022
- });
1023
- }
1024
- deleteWorkspace({ workspace }) {
1025
- return operationsByTag.workspaces.deleteWorkspace({
1026
- pathParams: { workspaceId: workspace },
1027
- ...this.extraProps
1028
- });
1029
- }
1030
- getWorkspaceMembersList({ workspace }) {
1031
- return operationsByTag.workspaces.getWorkspaceMembersList({
1032
- pathParams: { workspaceId: workspace },
1033
- ...this.extraProps
1034
- });
1035
- }
1036
- updateWorkspaceMemberRole({
1037
- workspace,
1038
- user,
1039
- role
1040
- }) {
1041
- return operationsByTag.workspaces.updateWorkspaceMemberRole({
1042
- pathParams: { workspaceId: workspace, userId: user },
1043
- body: { role },
1044
- ...this.extraProps
1045
- });
1046
- }
1047
- removeWorkspaceMember({
1048
- workspace,
1049
- user
1050
- }) {
1051
- return operationsByTag.workspaces.removeWorkspaceMember({
1052
- pathParams: { workspaceId: workspace, userId: user },
1053
- ...this.extraProps
1054
- });
1055
- }
1056
- }
1057
- class InvitesApi {
1058
- constructor(extraProps) {
1059
- this.extraProps = extraProps;
1060
- }
1061
- inviteWorkspaceMember({
1062
- workspace,
1063
- email,
1064
- role
1065
- }) {
1066
- return operationsByTag.invites.inviteWorkspaceMember({
1067
- pathParams: { workspaceId: workspace },
1068
- body: { email, role },
1069
- ...this.extraProps
1070
- });
1071
- }
1072
- updateWorkspaceMemberInvite({
1073
- workspace,
1074
- invite,
1075
- role
1076
- }) {
1077
- return operationsByTag.invites.updateWorkspaceMemberInvite({
1078
- pathParams: { workspaceId: workspace, inviteId: invite },
1079
- body: { role },
1080
- ...this.extraProps
1081
- });
1082
- }
1083
- cancelWorkspaceMemberInvite({
1084
- workspace,
1085
- invite
1086
- }) {
1087
- return operationsByTag.invites.cancelWorkspaceMemberInvite({
1088
- pathParams: { workspaceId: workspace, inviteId: invite },
1089
- ...this.extraProps
1090
- });
1091
- }
1092
- acceptWorkspaceMemberInvite({
1093
- workspace,
1094
- key
1095
- }) {
1096
- return operationsByTag.invites.acceptWorkspaceMemberInvite({
1097
- pathParams: { workspaceId: workspace, inviteKey: key },
1098
- ...this.extraProps
1099
- });
1100
- }
1101
- resendWorkspaceMemberInvite({
1102
- workspace,
1103
- invite
1104
- }) {
1105
- return operationsByTag.invites.resendWorkspaceMemberInvite({
1106
- pathParams: { workspaceId: workspace, inviteId: invite },
1107
- ...this.extraProps
1108
- });
1109
- }
1110
- }
1111
- class BranchApi {
1112
- constructor(extraProps) {
1113
- this.extraProps = extraProps;
1114
- }
1115
- getBranchList({
1116
- workspace,
1117
- region,
1118
- database
1119
- }) {
1120
- return operationsByTag.branch.getBranchList({
1121
- pathParams: { workspace, region, dbName: database },
1122
- ...this.extraProps
1123
- });
1124
- }
1125
- getBranchDetails({
1126
- workspace,
1127
- region,
1128
- database,
1129
- branch
1130
- }) {
1131
- return operationsByTag.branch.getBranchDetails({
1132
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1133
- ...this.extraProps
1134
- });
1135
- }
1136
- createBranch({
1137
- workspace,
1138
- region,
1139
- database,
1140
- branch,
1141
- from,
1142
- metadata
1143
- }) {
1144
- return operationsByTag.branch.createBranch({
1145
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1146
- body: { from, metadata },
1147
- ...this.extraProps
1148
- });
1149
- }
1150
- deleteBranch({
1151
- workspace,
1152
- region,
1153
- database,
1154
- branch
1155
- }) {
1156
- return operationsByTag.branch.deleteBranch({
1157
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1158
- ...this.extraProps
1159
- });
1160
- }
1161
- updateBranchMetadata({
1162
- workspace,
1163
- region,
1164
- database,
1165
- branch,
1166
- metadata
1167
- }) {
1168
- return operationsByTag.branch.updateBranchMetadata({
1169
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1170
- body: metadata,
1171
- ...this.extraProps
1172
- });
1173
- }
1174
- getBranchMetadata({
1175
- workspace,
1176
- region,
1177
- database,
1178
- branch
1179
- }) {
1180
- return operationsByTag.branch.getBranchMetadata({
1181
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1182
- ...this.extraProps
1183
- });
1184
- }
1185
- getBranchStats({
1186
- workspace,
1187
- region,
1188
- database,
1189
- branch
1190
- }) {
1191
- return operationsByTag.branch.getBranchStats({
1192
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1193
- ...this.extraProps
1194
- });
1195
- }
1196
- getGitBranchesMapping({
1197
- workspace,
1198
- region,
1199
- database
1200
- }) {
1201
- return operationsByTag.branch.getGitBranchesMapping({
1202
- pathParams: { workspace, region, dbName: database },
1203
- ...this.extraProps
1204
- });
1205
- }
1206
- addGitBranchesEntry({
1207
- workspace,
1208
- region,
1209
- database,
1210
- gitBranch,
1211
- xataBranch
1212
- }) {
1213
- return operationsByTag.branch.addGitBranchesEntry({
1214
- pathParams: { workspace, region, dbName: database },
1215
- body: { gitBranch, xataBranch },
1216
- ...this.extraProps
1217
- });
1218
- }
1219
- removeGitBranchesEntry({
1220
- workspace,
1221
- region,
1222
- database,
1223
- gitBranch
1224
- }) {
1225
- return operationsByTag.branch.removeGitBranchesEntry({
1226
- pathParams: { workspace, region, dbName: database },
1227
- queryParams: { gitBranch },
1228
- ...this.extraProps
1229
- });
1230
- }
1231
- resolveBranch({
1232
- workspace,
1233
- region,
1234
- database,
1235
- gitBranch,
1236
- fallbackBranch
1237
- }) {
1238
- return operationsByTag.branch.resolveBranch({
1239
- pathParams: { workspace, region, dbName: database },
1240
- queryParams: { gitBranch, fallbackBranch },
1241
- ...this.extraProps
1242
- });
1243
- }
1244
- }
1245
- class TableApi {
1246
- constructor(extraProps) {
1247
- this.extraProps = extraProps;
1248
- }
1249
- createTable({
1250
- workspace,
1251
- region,
1252
- database,
1253
- branch,
1254
- table
1255
- }) {
1256
- return operationsByTag.table.createTable({
1257
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1258
- ...this.extraProps
1259
- });
1260
- }
1261
- deleteTable({
1262
- workspace,
1263
- region,
1264
- database,
1265
- branch,
1266
- table
1267
- }) {
1268
- return operationsByTag.table.deleteTable({
1269
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1270
- ...this.extraProps
1271
- });
1272
- }
1273
- updateTable({
1274
- workspace,
1275
- region,
1276
- database,
1277
- branch,
1278
- table,
1279
- update
1280
- }) {
1281
- return operationsByTag.table.updateTable({
1282
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1283
- body: update,
1284
- ...this.extraProps
1285
- });
1286
- }
1287
- getTableSchema({
1288
- workspace,
1289
- region,
1290
- database,
1291
- branch,
1292
- table
1293
- }) {
1294
- return operationsByTag.table.getTableSchema({
1295
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1296
- ...this.extraProps
1297
- });
1298
- }
1299
- setTableSchema({
1300
- workspace,
1301
- region,
1302
- database,
1303
- branch,
1304
- table,
1305
- schema
1306
- }) {
1307
- return operationsByTag.table.setTableSchema({
1308
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1309
- body: schema,
1310
- ...this.extraProps
1311
- });
1312
- }
1313
- getTableColumns({
1314
- workspace,
1315
- region,
1316
- database,
1317
- branch,
1318
- table
1319
- }) {
1320
- return operationsByTag.table.getTableColumns({
1321
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1322
- ...this.extraProps
1323
- });
1324
- }
1325
- addTableColumn({
1326
- workspace,
1327
- region,
1328
- database,
1329
- branch,
1330
- table,
1331
- column
1332
- }) {
1333
- return operationsByTag.table.addTableColumn({
1334
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1335
- body: column,
1336
- ...this.extraProps
1337
- });
1338
- }
1339
- getColumn({
1340
- workspace,
1341
- region,
1342
- database,
1343
- branch,
1344
- table,
1345
- column
1346
- }) {
1347
- return operationsByTag.table.getColumn({
1348
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1349
- ...this.extraProps
1350
- });
1351
- }
1352
- updateColumn({
1353
- workspace,
1354
- region,
1355
- database,
1356
- branch,
1357
- table,
1358
- column,
1359
- update
1360
- }) {
1361
- return operationsByTag.table.updateColumn({
1362
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1363
- body: update,
1364
- ...this.extraProps
1365
- });
1366
- }
1367
- deleteColumn({
1368
- workspace,
1369
- region,
1370
- database,
1371
- branch,
1372
- table,
1373
- column
1374
- }) {
1375
- return operationsByTag.table.deleteColumn({
1376
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1377
- ...this.extraProps
1378
- });
1379
- }
1380
- }
1381
- class RecordsApi {
1382
- constructor(extraProps) {
1383
- this.extraProps = extraProps;
1384
- }
1385
- insertRecord({
1386
- workspace,
1387
- region,
1388
- database,
1389
- branch,
1390
- table,
1391
- record,
1392
- columns
1393
- }) {
1394
- return operationsByTag.records.insertRecord({
1395
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1396
- queryParams: { columns },
1397
- body: record,
1398
- ...this.extraProps
1399
- });
1400
- }
1401
- getRecord({
1402
- workspace,
1403
- region,
1404
- database,
1405
- branch,
1406
- table,
1407
- id,
1408
- columns
1409
- }) {
1410
- return operationsByTag.records.getRecord({
1411
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1412
- queryParams: { columns },
1413
- ...this.extraProps
1414
- });
1415
- }
1416
- insertRecordWithID({
1417
- workspace,
1418
- region,
1419
- database,
1420
- branch,
1421
- table,
1422
- id,
1423
- record,
1424
- columns,
1425
- createOnly,
1426
- ifVersion
1427
- }) {
1428
- return operationsByTag.records.insertRecordWithID({
1429
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1430
- queryParams: { columns, createOnly, ifVersion },
1431
- body: record,
1432
- ...this.extraProps
1433
- });
1434
- }
1435
- updateRecordWithID({
1436
- workspace,
1437
- region,
1438
- database,
1439
- branch,
1440
- table,
1441
- id,
1442
- record,
1443
- columns,
1444
- ifVersion
1445
- }) {
1446
- return operationsByTag.records.updateRecordWithID({
1447
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1448
- queryParams: { columns, ifVersion },
1449
- body: record,
1450
- ...this.extraProps
1451
- });
1452
- }
1453
- upsertRecordWithID({
1454
- workspace,
1455
- region,
1456
- database,
1457
- branch,
1458
- table,
1459
- id,
1460
- record,
1461
- columns,
1462
- ifVersion
1463
- }) {
1464
- return operationsByTag.records.upsertRecordWithID({
1465
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1466
- queryParams: { columns, ifVersion },
1467
- body: record,
1468
- ...this.extraProps
1469
- });
1470
- }
1471
- deleteRecord({
1472
- workspace,
1473
- region,
1474
- database,
1475
- branch,
1476
- table,
1477
- id,
1478
- columns
1479
- }) {
1480
- return operationsByTag.records.deleteRecord({
1481
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1482
- queryParams: { columns },
1483
- ...this.extraProps
1484
- });
1485
- }
1486
- bulkInsertTableRecords({
1487
- workspace,
1488
- region,
1489
- database,
1490
- branch,
1491
- table,
1492
- records,
1493
- columns
1494
- }) {
1495
- return operationsByTag.records.bulkInsertTableRecords({
1496
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1497
- queryParams: { columns },
1498
- body: { records },
1499
- ...this.extraProps
1500
- });
1501
- }
1502
- branchTransaction({
1503
- workspace,
1504
- region,
1505
- database,
1506
- branch,
1507
- operations
1508
- }) {
1509
- return operationsByTag.records.branchTransaction({
1510
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1511
- body: { operations },
1512
- ...this.extraProps
1513
- });
1514
- }
1515
- }
1516
- class SearchAndFilterApi {
1517
- constructor(extraProps) {
1518
- this.extraProps = extraProps;
1519
- }
1520
- queryTable({
1521
- workspace,
1522
- region,
1523
- database,
1524
- branch,
1525
- table,
1526
- filter,
1527
- sort,
1528
- page,
1529
- columns,
1530
- consistency
1531
- }) {
1532
- return operationsByTag.searchAndFilter.queryTable({
1533
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1534
- body: { filter, sort, page, columns, consistency },
1535
- ...this.extraProps
1536
- });
1537
- }
1538
- searchTable({
1539
- workspace,
1540
- region,
1541
- database,
1542
- branch,
1543
- table,
1544
- query,
1545
- fuzziness,
1546
- target,
1547
- prefix,
1548
- filter,
1549
- highlight,
1550
- boosters
1551
- }) {
1552
- return operationsByTag.searchAndFilter.searchTable({
1553
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1554
- body: { query, fuzziness, target, prefix, filter, highlight, boosters },
1555
- ...this.extraProps
1556
- });
1557
- }
1558
- searchBranch({
1559
- workspace,
1560
- region,
1561
- database,
1562
- branch,
1563
- tables,
1564
- query,
1565
- fuzziness,
1566
- prefix,
1567
- highlight
1568
- }) {
1569
- return operationsByTag.searchAndFilter.searchBranch({
1570
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1571
- body: { tables, query, fuzziness, prefix, highlight },
1572
- ...this.extraProps
1573
- });
1574
- }
1575
- summarizeTable({
1576
- workspace,
1577
- region,
1578
- database,
1579
- branch,
1580
- table,
1581
- filter,
1582
- columns,
1583
- summaries,
1584
- sort,
1585
- summariesFilter,
1586
- page,
1587
- consistency
1588
- }) {
1589
- return operationsByTag.searchAndFilter.summarizeTable({
1590
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1591
- body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1592
- ...this.extraProps
1593
- });
1594
- }
1595
- aggregateTable({
1596
- workspace,
1597
- region,
1598
- database,
1599
- branch,
1600
- table,
1601
- filter,
1602
- aggs
1603
- }) {
1604
- return operationsByTag.searchAndFilter.aggregateTable({
1605
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1606
- body: { filter, aggs },
1607
- ...this.extraProps
1608
- });
1609
- }
1610
- }
1611
- class MigrationRequestsApi {
1612
- constructor(extraProps) {
1613
- this.extraProps = extraProps;
1614
- }
1615
- queryMigrationRequests({
1616
- workspace,
1617
- region,
1618
- database,
1619
- filter,
1620
- sort,
1621
- page,
1622
- columns
1623
- }) {
1624
- return operationsByTag.migrationRequests.queryMigrationRequests({
1625
- pathParams: { workspace, region, dbName: database },
1626
- body: { filter, sort, page, columns },
1627
- ...this.extraProps
1628
- });
1629
- }
1630
- createMigrationRequest({
1631
- workspace,
1632
- region,
1633
- database,
1634
- migration
1635
- }) {
1636
- return operationsByTag.migrationRequests.createMigrationRequest({
1637
- pathParams: { workspace, region, dbName: database },
1638
- body: migration,
1639
- ...this.extraProps
1640
- });
1641
- }
1642
- getMigrationRequest({
1643
- workspace,
1644
- region,
1645
- database,
1646
- migrationRequest
1647
- }) {
1648
- return operationsByTag.migrationRequests.getMigrationRequest({
1649
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1650
- ...this.extraProps
1651
- });
1652
- }
1653
- updateMigrationRequest({
1654
- workspace,
1655
- region,
1656
- database,
1657
- migrationRequest,
1658
- update
1659
- }) {
1660
- return operationsByTag.migrationRequests.updateMigrationRequest({
1661
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1662
- body: update,
1663
- ...this.extraProps
1664
- });
1665
- }
1666
- listMigrationRequestsCommits({
1667
- workspace,
1668
- region,
1669
- database,
1670
- migrationRequest,
1671
- page
1672
- }) {
1673
- return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1674
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1675
- body: { page },
1676
- ...this.extraProps
1677
- });
1678
- }
1679
- compareMigrationRequest({
1680
- workspace,
1681
- region,
1682
- database,
1683
- migrationRequest
1684
- }) {
1685
- return operationsByTag.migrationRequests.compareMigrationRequest({
1686
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1687
- ...this.extraProps
1688
- });
1689
- }
1690
- getMigrationRequestIsMerged({
1691
- workspace,
1692
- region,
1693
- database,
1694
- migrationRequest
1695
- }) {
1696
- return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1697
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1698
- ...this.extraProps
1699
- });
1700
- }
1701
- mergeMigrationRequest({
1702
- workspace,
1703
- region,
1704
- database,
1705
- migrationRequest
1706
- }) {
1707
- return operationsByTag.migrationRequests.mergeMigrationRequest({
1708
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1709
- ...this.extraProps
1710
- });
1711
- }
1712
- }
1713
- class MigrationsApi {
1714
- constructor(extraProps) {
1715
- this.extraProps = extraProps;
1716
- }
1717
- getBranchMigrationHistory({
1718
- workspace,
1719
- region,
1720
- database,
1721
- branch,
1722
- limit,
1723
- startFrom
1724
- }) {
1725
- return operationsByTag.migrations.getBranchMigrationHistory({
1726
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1727
- body: { limit, startFrom },
1728
- ...this.extraProps
1729
- });
1730
- }
1731
- getBranchMigrationPlan({
1732
- workspace,
1733
- region,
1734
- database,
1735
- branch,
1736
- schema
1737
- }) {
1738
- return operationsByTag.migrations.getBranchMigrationPlan({
1739
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1740
- body: schema,
1741
- ...this.extraProps
1742
- });
1743
- }
1744
- executeBranchMigrationPlan({
1745
- workspace,
1746
- region,
1747
- database,
1748
- branch,
1749
- plan
1750
- }) {
1751
- return operationsByTag.migrations.executeBranchMigrationPlan({
1752
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1753
- body: plan,
1754
- ...this.extraProps
1755
- });
1756
- }
1757
- getBranchSchemaHistory({
1758
- workspace,
1759
- region,
1760
- database,
1761
- branch,
1762
- page
1763
- }) {
1764
- return operationsByTag.migrations.getBranchSchemaHistory({
1765
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1766
- body: { page },
1767
- ...this.extraProps
1768
- });
1769
- }
1770
- compareBranchWithUserSchema({
1771
- workspace,
1772
- region,
1773
- database,
1774
- branch,
1775
- schema,
1776
- schemaOperations,
1777
- branchOperations
1778
- }) {
1779
- return operationsByTag.migrations.compareBranchWithUserSchema({
1780
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1781
- body: { schema, schemaOperations, branchOperations },
1782
- ...this.extraProps
1783
- });
1784
- }
1785
- compareBranchSchemas({
1786
- workspace,
1787
- region,
1788
- database,
1789
- branch,
1790
- compare,
1791
- sourceBranchOperations,
1792
- targetBranchOperations
1793
- }) {
1794
- return operationsByTag.migrations.compareBranchSchemas({
1795
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1796
- body: { sourceBranchOperations, targetBranchOperations },
1797
- ...this.extraProps
1798
- });
1799
- }
1800
- updateBranchSchema({
1801
- workspace,
1802
- region,
1803
- database,
1804
- branch,
1805
- migration
1806
- }) {
1807
- return operationsByTag.migrations.updateBranchSchema({
1808
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1809
- body: migration,
1810
- ...this.extraProps
1811
- });
1812
- }
1813
- previewBranchSchemaEdit({
1814
- workspace,
1815
- region,
1816
- database,
1817
- branch,
1818
- data
1819
- }) {
1820
- return operationsByTag.migrations.previewBranchSchemaEdit({
1821
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1822
- body: data,
1823
- ...this.extraProps
1824
- });
1825
- }
1826
- applyBranchSchemaEdit({
1827
- workspace,
1828
- region,
1829
- database,
1830
- branch,
1831
- edits
1832
- }) {
1833
- return operationsByTag.migrations.applyBranchSchemaEdit({
1834
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1835
- body: { edits },
1836
- ...this.extraProps
1837
- });
1838
- }
1387
+ };
1388
+ class XataApiClient extends buildApiClient() {
1839
1389
  }
1840
- class DatabaseApi {
1841
- constructor(extraProps) {
1842
- this.extraProps = extraProps;
1390
+
1391
+ class XataApiPlugin {
1392
+ build(options) {
1393
+ return new XataApiClient(options);
1843
1394
  }
1844
- getDatabaseList({ workspace }) {
1845
- return operationsByTag.databases.getDatabaseList({
1846
- pathParams: { workspaceId: workspace },
1847
- ...this.extraProps
1848
- });
1395
+ }
1396
+
1397
+ class XataPlugin {
1398
+ }
1399
+
1400
+ function buildTransformString(transformations) {
1401
+ return transformations.flatMap(
1402
+ (t) => Object.entries(t).map(([key, value]) => {
1403
+ if (key === "trim") {
1404
+ const { left = 0, top = 0, right = 0, bottom = 0 } = value;
1405
+ return `${key}=${[top, right, bottom, left].join(";")}`;
1406
+ }
1407
+ if (key === "gravity" && typeof value === "object") {
1408
+ const { x = 0.5, y = 0.5 } = value;
1409
+ return `${key}=${[x, y].join("x")}`;
1410
+ }
1411
+ return `${key}=${value}`;
1412
+ })
1413
+ ).join(",");
1414
+ }
1415
+ function transformImage(url, ...transformations) {
1416
+ if (!isDefined(url))
1417
+ return void 0;
1418
+ const newTransformations = buildTransformString(transformations);
1419
+ const { hostname, pathname, search } = new URL(url);
1420
+ const pathParts = pathname.split("/");
1421
+ const transformIndex = pathParts.findIndex((part) => part === "transform");
1422
+ const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
1423
+ const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
1424
+ const path = pathParts.join("/");
1425
+ return `https://${hostname}${transform}${path}${search}`;
1426
+ }
1427
+
1428
+ class XataFile {
1429
+ constructor(file) {
1430
+ this.id = file.id;
1431
+ this.name = file.name;
1432
+ this.mediaType = file.mediaType;
1433
+ this.base64Content = file.base64Content;
1434
+ this.enablePublicUrl = file.enablePublicUrl;
1435
+ this.signedUrlTimeout = file.signedUrlTimeout;
1436
+ this.uploadUrlTimeout = file.uploadUrlTimeout;
1437
+ this.size = file.size;
1438
+ this.version = file.version;
1439
+ this.url = file.url;
1440
+ this.signedUrl = file.signedUrl;
1441
+ this.uploadUrl = file.uploadUrl;
1442
+ this.attributes = file.attributes;
1443
+ }
1444
+ static fromBuffer(buffer, options = {}) {
1445
+ const base64Content = buffer.toString("base64");
1446
+ return new XataFile({ ...options, base64Content });
1447
+ }
1448
+ toBuffer() {
1449
+ if (!this.base64Content) {
1450
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1451
+ }
1452
+ return Buffer.from(this.base64Content, "base64");
1849
1453
  }
1850
- createDatabase({
1851
- workspace,
1852
- database,
1853
- data
1854
- }) {
1855
- return operationsByTag.databases.createDatabase({
1856
- pathParams: { workspaceId: workspace, dbName: database },
1857
- body: data,
1858
- ...this.extraProps
1859
- });
1454
+ static fromArrayBuffer(arrayBuffer, options = {}) {
1455
+ const uint8Array = new Uint8Array(arrayBuffer);
1456
+ return this.fromUint8Array(uint8Array, options);
1860
1457
  }
1861
- deleteDatabase({
1862
- workspace,
1863
- database
1864
- }) {
1865
- return operationsByTag.databases.deleteDatabase({
1866
- pathParams: { workspaceId: workspace, dbName: database },
1867
- ...this.extraProps
1868
- });
1458
+ toArrayBuffer() {
1459
+ if (!this.base64Content) {
1460
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1461
+ }
1462
+ const binary = atob(this.base64Content);
1463
+ return new ArrayBuffer(binary.length);
1869
1464
  }
1870
- getDatabaseMetadata({
1871
- workspace,
1872
- database
1873
- }) {
1874
- return operationsByTag.databases.getDatabaseMetadata({
1875
- pathParams: { workspaceId: workspace, dbName: database },
1876
- ...this.extraProps
1877
- });
1465
+ static fromUint8Array(uint8Array, options = {}) {
1466
+ let binary = "";
1467
+ for (let i = 0; i < uint8Array.byteLength; i++) {
1468
+ binary += String.fromCharCode(uint8Array[i]);
1469
+ }
1470
+ const base64Content = btoa(binary);
1471
+ return new XataFile({ ...options, base64Content });
1878
1472
  }
1879
- updateDatabaseMetadata({
1880
- workspace,
1881
- database,
1882
- metadata
1883
- }) {
1884
- return operationsByTag.databases.updateDatabaseMetadata({
1885
- pathParams: { workspaceId: workspace, dbName: database },
1886
- body: metadata,
1887
- ...this.extraProps
1888
- });
1473
+ toUint8Array() {
1474
+ if (!this.base64Content) {
1475
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1476
+ }
1477
+ const binary = atob(this.base64Content);
1478
+ const uint8Array = new Uint8Array(binary.length);
1479
+ for (let i = 0; i < binary.length; i++) {
1480
+ uint8Array[i] = binary.charCodeAt(i);
1481
+ }
1482
+ return uint8Array;
1889
1483
  }
1890
- getDatabaseGithubSettings({
1891
- workspace,
1892
- database
1893
- }) {
1894
- return operationsByTag.databases.getDatabaseGithubSettings({
1895
- pathParams: { workspaceId: workspace, dbName: database },
1896
- ...this.extraProps
1897
- });
1484
+ static async fromBlob(file, options = {}) {
1485
+ const name = options.name ?? file.name;
1486
+ const mediaType = file.type;
1487
+ const arrayBuffer = await file.arrayBuffer();
1488
+ return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
1898
1489
  }
1899
- updateDatabaseGithubSettings({
1900
- workspace,
1901
- database,
1902
- settings
1903
- }) {
1904
- return operationsByTag.databases.updateDatabaseGithubSettings({
1905
- pathParams: { workspaceId: workspace, dbName: database },
1906
- body: settings,
1907
- ...this.extraProps
1908
- });
1490
+ toBlob() {
1491
+ if (!this.base64Content) {
1492
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1493
+ }
1494
+ const binary = atob(this.base64Content);
1495
+ const uint8Array = new Uint8Array(binary.length);
1496
+ for (let i = 0; i < binary.length; i++) {
1497
+ uint8Array[i] = binary.charCodeAt(i);
1498
+ }
1499
+ return new Blob([uint8Array], { type: this.mediaType });
1909
1500
  }
1910
- deleteDatabaseGithubSettings({
1911
- workspace,
1912
- database
1913
- }) {
1914
- return operationsByTag.databases.deleteDatabaseGithubSettings({
1915
- pathParams: { workspaceId: workspace, dbName: database },
1916
- ...this.extraProps
1917
- });
1501
+ static fromString(string, options = {}) {
1502
+ const base64Content = btoa(string);
1503
+ return new XataFile({ ...options, base64Content });
1918
1504
  }
1919
- listRegions({ workspace }) {
1920
- return operationsByTag.databases.listRegions({
1921
- pathParams: { workspaceId: workspace },
1922
- ...this.extraProps
1923
- });
1505
+ toString() {
1506
+ if (!this.base64Content) {
1507
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1508
+ }
1509
+ return atob(this.base64Content);
1924
1510
  }
1925
- }
1926
-
1927
- class XataApiPlugin {
1928
- async build(options) {
1929
- const { fetchImpl, apiKey } = await options.getFetchProps();
1930
- return new XataApiClient({ fetch: fetchImpl, apiKey });
1511
+ static fromBase64(base64Content, options = {}) {
1512
+ return new XataFile({ ...options, base64Content });
1513
+ }
1514
+ toBase64() {
1515
+ if (!this.base64Content) {
1516
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1517
+ }
1518
+ return this.base64Content;
1519
+ }
1520
+ transform(...options) {
1521
+ return {
1522
+ url: transformImage(this.url, ...options),
1523
+ signedUrl: transformImage(this.signedUrl, ...options),
1524
+ metadataUrl: transformImage(this.url, ...options, { format: "json" }),
1525
+ metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
1526
+ };
1931
1527
  }
1932
1528
  }
1933
-
1934
- class XataPlugin {
1935
- }
1529
+ const parseInputFileEntry = async (entry) => {
1530
+ if (!isDefined(entry))
1531
+ return null;
1532
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
1533
+ return compactObject({
1534
+ id,
1535
+ // Name cannot be an empty string in our API
1536
+ name: name ? name : void 0,
1537
+ mediaType,
1538
+ base64Content,
1539
+ enablePublicUrl,
1540
+ signedUrlTimeout,
1541
+ uploadUrlTimeout
1542
+ });
1543
+ };
1936
1544
 
1937
1545
  function cleanFilter(filter) {
1938
- if (!filter)
1546
+ if (!isDefined(filter))
1939
1547
  return void 0;
1940
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1941
- return values.length > 0 ? filter : void 0;
1548
+ if (!isObject(filter))
1549
+ return filter;
1550
+ const values = Object.fromEntries(
1551
+ Object.entries(filter).reduce((acc, [key, value]) => {
1552
+ if (!isDefined(value))
1553
+ return acc;
1554
+ if (Array.isArray(value)) {
1555
+ const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
1556
+ if (clean.length === 0)
1557
+ return acc;
1558
+ return [...acc, [key, clean]];
1559
+ }
1560
+ if (isObject(value)) {
1561
+ const clean = cleanFilter(value);
1562
+ if (!isDefined(clean))
1563
+ return acc;
1564
+ return [...acc, [key, clean]];
1565
+ }
1566
+ return [...acc, [key, value]];
1567
+ }, [])
1568
+ );
1569
+ return Object.keys(values).length > 0 ? values : void 0;
1570
+ }
1571
+
1572
+ function stringifyJson(value) {
1573
+ if (!isDefined(value))
1574
+ return value;
1575
+ if (isString(value))
1576
+ return value;
1577
+ try {
1578
+ return JSON.stringify(value);
1579
+ } catch (e) {
1580
+ return value;
1581
+ }
1582
+ }
1583
+ function parseJson(value) {
1584
+ try {
1585
+ return JSON.parse(value);
1586
+ } catch (e) {
1587
+ return value;
1588
+ }
1942
1589
  }
1943
1590
 
1944
1591
  var __accessCheck$6 = (obj, member, msg) => {
@@ -1967,31 +1614,59 @@ class Page {
1967
1614
  this.meta = meta;
1968
1615
  this.records = new RecordArray(this, records);
1969
1616
  }
1617
+ /**
1618
+ * Retrieves the next page of results.
1619
+ * @param size Maximum number of results to be retrieved.
1620
+ * @param offset Number of results to skip when retrieving the results.
1621
+ * @returns The next page or results.
1622
+ */
1970
1623
  async nextPage(size, offset) {
1971
1624
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
1972
1625
  }
1626
+ /**
1627
+ * Retrieves the previous page of results.
1628
+ * @param size Maximum number of results to be retrieved.
1629
+ * @param offset Number of results to skip when retrieving the results.
1630
+ * @returns The previous page or results.
1631
+ */
1973
1632
  async previousPage(size, offset) {
1974
1633
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1975
1634
  }
1635
+ /**
1636
+ * Retrieves the start page of results.
1637
+ * @param size Maximum number of results to be retrieved.
1638
+ * @param offset Number of results to skip when retrieving the results.
1639
+ * @returns The start page or results.
1640
+ */
1976
1641
  async startPage(size, offset) {
1977
1642
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1978
1643
  }
1644
+ /**
1645
+ * Retrieves the end page of results.
1646
+ * @param size Maximum number of results to be retrieved.
1647
+ * @param offset Number of results to skip when retrieving the results.
1648
+ * @returns The end page or results.
1649
+ */
1979
1650
  async endPage(size, offset) {
1980
1651
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1981
1652
  }
1653
+ /**
1654
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
1655
+ * @returns Whether or not there will be additional results in the next page of results.
1656
+ */
1982
1657
  hasNextPage() {
1983
1658
  return this.meta.page.more;
1984
1659
  }
1985
1660
  }
1986
1661
  _query = new WeakMap();
1987
- const PAGINATION_MAX_SIZE = 200;
1662
+ const PAGINATION_MAX_SIZE = 1e3;
1988
1663
  const PAGINATION_DEFAULT_SIZE = 20;
1989
- const PAGINATION_MAX_OFFSET = 800;
1664
+ const PAGINATION_MAX_OFFSET = 49e3;
1990
1665
  const PAGINATION_DEFAULT_OFFSET = 0;
1991
1666
  function isCursorPaginationOptions(options) {
1992
1667
  return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1993
1668
  }
1994
- const _RecordArray = class extends Array {
1669
+ const _RecordArray = class _RecordArray extends Array {
1995
1670
  constructor(...args) {
1996
1671
  super(..._RecordArray.parseConstructorParams(...args));
1997
1672
  __privateAdd$6(this, _page, void 0);
@@ -2019,28 +1694,51 @@ const _RecordArray = class extends Array {
2019
1694
  map(callbackfn, thisArg) {
2020
1695
  return this.toArray().map(callbackfn, thisArg);
2021
1696
  }
1697
+ /**
1698
+ * Retrieve next page of records
1699
+ *
1700
+ * @returns A new array of objects
1701
+ */
2022
1702
  async nextPage(size, offset) {
2023
1703
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
2024
1704
  return new _RecordArray(newPage);
2025
1705
  }
1706
+ /**
1707
+ * Retrieve previous page of records
1708
+ *
1709
+ * @returns A new array of objects
1710
+ */
2026
1711
  async previousPage(size, offset) {
2027
1712
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
2028
1713
  return new _RecordArray(newPage);
2029
1714
  }
1715
+ /**
1716
+ * Retrieve start page of records
1717
+ *
1718
+ * @returns A new array of objects
1719
+ */
2030
1720
  async startPage(size, offset) {
2031
1721
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
2032
1722
  return new _RecordArray(newPage);
2033
1723
  }
1724
+ /**
1725
+ * Retrieve end page of records
1726
+ *
1727
+ * @returns A new array of objects
1728
+ */
2034
1729
  async endPage(size, offset) {
2035
1730
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
2036
1731
  return new _RecordArray(newPage);
2037
1732
  }
1733
+ /**
1734
+ * @returns Boolean indicating if there is a next page
1735
+ */
2038
1736
  hasNextPage() {
2039
1737
  return __privateGet$6(this, _page).meta.page.more;
2040
1738
  }
2041
1739
  };
2042
- let RecordArray = _RecordArray;
2043
1740
  _page = new WeakMap();
1741
+ let RecordArray = _RecordArray;
2044
1742
 
2045
1743
  var __accessCheck$5 = (obj, member, msg) => {
2046
1744
  if (!member.has(obj))
@@ -2065,13 +1763,14 @@ var __privateMethod$3 = (obj, member, method) => {
2065
1763
  return method;
2066
1764
  };
2067
1765
  var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
2068
- const _Query = class {
1766
+ const _Query = class _Query {
2069
1767
  constructor(repository, table, data, rawParent) {
2070
1768
  __privateAdd$5(this, _cleanFilterConstraint);
2071
1769
  __privateAdd$5(this, _table$1, void 0);
2072
1770
  __privateAdd$5(this, _repository, void 0);
2073
1771
  __privateAdd$5(this, _data, { filter: {} });
2074
- this.meta = { page: { cursor: "start", more: true } };
1772
+ // Implements pagination
1773
+ this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
2075
1774
  this.records = new RecordArray(this, []);
2076
1775
  __privateSet$5(this, _table$1, table);
2077
1776
  if (repository) {
@@ -2108,18 +1807,38 @@ const _Query = class {
2108
1807
  const key = JSON.stringify({ columns, filter, sort, pagination });
2109
1808
  return toBase64(key);
2110
1809
  }
1810
+ /**
1811
+ * Builds a new query object representing a logical OR between the given subqueries.
1812
+ * @param queries An array of subqueries.
1813
+ * @returns A new Query object.
1814
+ */
2111
1815
  any(...queries) {
2112
1816
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2113
1817
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2114
1818
  }
1819
+ /**
1820
+ * Builds a new query object representing a logical AND between the given subqueries.
1821
+ * @param queries An array of subqueries.
1822
+ * @returns A new Query object.
1823
+ */
2115
1824
  all(...queries) {
2116
1825
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2117
1826
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2118
1827
  }
1828
+ /**
1829
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
1830
+ * @param queries An array of subqueries.
1831
+ * @returns A new Query object.
1832
+ */
2119
1833
  not(...queries) {
2120
1834
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2121
1835
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2122
1836
  }
1837
+ /**
1838
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
1839
+ * @param queries An array of subqueries.
1840
+ * @returns A new Query object.
1841
+ */
2123
1842
  none(...queries) {
2124
1843
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2125
1844
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2142,6 +1861,11 @@ const _Query = class {
2142
1861
  const sort = [...originalSort, { column, direction }];
2143
1862
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2144
1863
  }
1864
+ /**
1865
+ * Builds a new query specifying the set of columns to be returned in the query response.
1866
+ * @param columns Array of column names to be returned by the query.
1867
+ * @returns A new Query object.
1868
+ */
2145
1869
  select(columns) {
2146
1870
  return new _Query(
2147
1871
  __privateGet$5(this, _repository),
@@ -2154,6 +1878,12 @@ const _Query = class {
2154
1878
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2155
1879
  return __privateGet$5(this, _repository).query(query);
2156
1880
  }
1881
+ /**
1882
+ * Get results in an iterator
1883
+ *
1884
+ * @async
1885
+ * @returns Async interable of results
1886
+ */
2157
1887
  async *[Symbol.asyncIterator]() {
2158
1888
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2159
1889
  yield record;
@@ -2214,26 +1944,53 @@ const _Query = class {
2214
1944
  );
2215
1945
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2216
1946
  }
1947
+ /**
1948
+ * Builds a new query object adding a cache TTL in milliseconds.
1949
+ * @param ttl The cache TTL in milliseconds.
1950
+ * @returns A new Query object.
1951
+ */
2217
1952
  cache(ttl) {
2218
1953
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2219
1954
  }
1955
+ /**
1956
+ * Retrieve next page of records
1957
+ *
1958
+ * @returns A new page object.
1959
+ */
2220
1960
  nextPage(size, offset) {
2221
1961
  return this.startPage(size, offset);
2222
1962
  }
1963
+ /**
1964
+ * Retrieve previous page of records
1965
+ *
1966
+ * @returns A new page object
1967
+ */
2223
1968
  previousPage(size, offset) {
2224
1969
  return this.startPage(size, offset);
2225
1970
  }
1971
+ /**
1972
+ * Retrieve start page of records
1973
+ *
1974
+ * @returns A new page object
1975
+ */
2226
1976
  startPage(size, offset) {
2227
1977
  return this.getPaginated({ pagination: { size, offset } });
2228
1978
  }
1979
+ /**
1980
+ * Retrieve last page of records
1981
+ *
1982
+ * @returns A new page object
1983
+ */
2229
1984
  endPage(size, offset) {
2230
1985
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2231
1986
  }
1987
+ /**
1988
+ * @returns Boolean indicating if there is a next page
1989
+ */
2232
1990
  hasNextPage() {
2233
1991
  return this.meta.page.more;
2234
1992
  }
2235
1993
  };
2236
- let Query = _Query;
2237
1994
  _table$1 = new WeakMap();
2238
1995
  _repository = new WeakMap();
2239
1996
  _data = new WeakMap();
@@ -2248,6 +2005,7 @@ cleanFilterConstraint_fn = function(column, value) {
2248
2005
  }
2249
2006
  return value;
2250
2007
  };
2008
+ let Query = _Query;
2251
2009
  function cleanParent(data, parent) {
2252
2010
  if (isCursorPaginationOptions(data.pagination)) {
2253
2011
  return { ...parent, sort: void 0, filter: void 0 };
@@ -2255,6 +2013,21 @@ function cleanParent(data, parent) {
2255
2013
  return parent;
2256
2014
  }
2257
2015
 
2016
+ const RecordColumnTypes = [
2017
+ "bool",
2018
+ "int",
2019
+ "float",
2020
+ "string",
2021
+ "text",
2022
+ "email",
2023
+ "multiple",
2024
+ "link",
2025
+ "datetime",
2026
+ "vector",
2027
+ "file[]",
2028
+ "file",
2029
+ "json"
2030
+ ];
2258
2031
  function isIdentifiable(x) {
2259
2032
  return isObject(x) && isString(x?.id);
2260
2033
  }
@@ -2264,11 +2037,33 @@ function isXataRecord(x) {
2264
2037
  return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
2265
2038
  }
2266
2039
 
2040
+ function isValidExpandedColumn(column) {
2041
+ return isObject(column) && isString(column.name);
2042
+ }
2043
+ function isValidSelectableColumns(columns) {
2044
+ if (!Array.isArray(columns)) {
2045
+ return false;
2046
+ }
2047
+ return columns.every((column) => {
2048
+ if (typeof column === "string") {
2049
+ return true;
2050
+ }
2051
+ if (typeof column === "object") {
2052
+ return isValidExpandedColumn(column);
2053
+ }
2054
+ return false;
2055
+ });
2056
+ }
2057
+
2267
2058
  function isSortFilterString(value) {
2268
2059
  return isString(value);
2269
2060
  }
2270
2061
  function isSortFilterBase(filter) {
2271
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
2062
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
2063
+ if (key === "*")
2064
+ return value === "random";
2065
+ return value === "asc" || value === "desc";
2066
+ });
2272
2067
  }
2273
2068
  function isSortFilterObject(filter) {
2274
2069
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2309,7 +2104,7 @@ var __privateMethod$2 = (obj, member, method) => {
2309
2104
  __accessCheck$4(obj, member, "access private method");
2310
2105
  return method;
2311
2106
  };
2312
- 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;
2107
+ 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, _transformObjectToApi, transformObjectToApi_fn;
2313
2108
  const BULK_OPERATION_MAX_SIZE = 1e3;
2314
2109
  class Repository extends Query {
2315
2110
  }
@@ -2331,6 +2126,7 @@ class RestRepository extends Query {
2331
2126
  __privateAdd$4(this, _setCacheQuery);
2332
2127
  __privateAdd$4(this, _getCacheQuery);
2333
2128
  __privateAdd$4(this, _getSchemaTables$1);
2129
+ __privateAdd$4(this, _transformObjectToApi);
2334
2130
  __privateAdd$4(this, _table, void 0);
2335
2131
  __privateAdd$4(this, _getFetchProps, void 0);
2336
2132
  __privateAdd$4(this, _db, void 0);
@@ -2341,10 +2137,7 @@ class RestRepository extends Query {
2341
2137
  __privateSet$4(this, _db, options.db);
2342
2138
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2343
2139
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2344
- __privateSet$4(this, _getFetchProps, async () => {
2345
- const props = await options.pluginOptions.getFetchProps();
2346
- return { ...props, sessionID: generateUUID() };
2347
- });
2140
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2348
2141
  const trace = options.pluginOptions.trace ?? defaultTrace;
2349
2142
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2350
2143
  return trace(name, fn, {
@@ -2362,24 +2155,24 @@ class RestRepository extends Query {
2362
2155
  if (a.length === 0)
2363
2156
  return [];
2364
2157
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2365
- const columns = isStringArray(b) ? b : ["*"];
2158
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2366
2159
  const result = await this.read(ids, columns);
2367
2160
  return result;
2368
2161
  }
2369
2162
  if (isString(a) && isObject(b)) {
2370
2163
  if (a === "")
2371
2164
  throw new Error("The id can't be empty");
2372
- const columns = isStringArray(c) ? c : void 0;
2165
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2373
2166
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2374
2167
  }
2375
2168
  if (isObject(a) && isString(a.id)) {
2376
2169
  if (a.id === "")
2377
2170
  throw new Error("The id can't be empty");
2378
- const columns = isStringArray(b) ? b : void 0;
2171
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2379
2172
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2380
2173
  }
2381
2174
  if (isObject(a)) {
2382
- const columns = isStringArray(b) ? b : void 0;
2175
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2383
2176
  return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2384
2177
  }
2385
2178
  throw new Error("Invalid arguments for create method");
@@ -2387,7 +2180,7 @@ class RestRepository extends Query {
2387
2180
  }
2388
2181
  async read(a, b) {
2389
2182
  return __privateGet$4(this, _trace).call(this, "read", async () => {
2390
- const columns = isStringArray(b) ? b : ["*"];
2183
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2391
2184
  if (Array.isArray(a)) {
2392
2185
  if (a.length === 0)
2393
2186
  return [];
@@ -2401,7 +2194,6 @@ class RestRepository extends Query {
2401
2194
  }
2402
2195
  const id = extractId(a);
2403
2196
  if (id) {
2404
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2405
2197
  try {
2406
2198
  const response = await getRecord({
2407
2199
  pathParams: {
@@ -2412,10 +2204,16 @@ class RestRepository extends Query {
2412
2204
  recordId: id
2413
2205
  },
2414
2206
  queryParams: { columns },
2415
- ...fetchProps
2207
+ ...__privateGet$4(this, _getFetchProps).call(this)
2416
2208
  });
2417
2209
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2418
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2210
+ return initObject(
2211
+ __privateGet$4(this, _db),
2212
+ schemaTables,
2213
+ __privateGet$4(this, _table),
2214
+ response,
2215
+ columns
2216
+ );
2419
2217
  } catch (e) {
2420
2218
  if (isObject(e) && e.status === 404) {
2421
2219
  return null;
@@ -2457,17 +2255,17 @@ class RestRepository extends Query {
2457
2255
  ifVersion,
2458
2256
  upsert: false
2459
2257
  });
2460
- const columns = isStringArray(b) ? b : ["*"];
2258
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2461
2259
  const result = await this.read(a, columns);
2462
2260
  return result;
2463
2261
  }
2464
2262
  try {
2465
2263
  if (isString(a) && isObject(b)) {
2466
- const columns = isStringArray(c) ? c : void 0;
2264
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2467
2265
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2468
2266
  }
2469
2267
  if (isObject(a) && isString(a.id)) {
2470
- const columns = isStringArray(b) ? b : void 0;
2268
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2471
2269
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2472
2270
  }
2473
2271
  } catch (error) {
@@ -2507,17 +2305,27 @@ class RestRepository extends Query {
2507
2305
  ifVersion,
2508
2306
  upsert: true
2509
2307
  });
2510
- const columns = isStringArray(b) ? b : ["*"];
2308
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2511
2309
  const result = await this.read(a, columns);
2512
2310
  return result;
2513
2311
  }
2514
2312
  if (isString(a) && isObject(b)) {
2515
- const columns = isStringArray(c) ? c : void 0;
2516
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2313
+ if (a === "")
2314
+ throw new Error("The id can't be empty");
2315
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2316
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2517
2317
  }
2518
2318
  if (isObject(a) && isString(a.id)) {
2519
- const columns = isStringArray(c) ? c : void 0;
2520
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2319
+ if (a.id === "")
2320
+ throw new Error("The id can't be empty");
2321
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2322
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2323
+ }
2324
+ if (!isDefined(a) && isObject(b)) {
2325
+ return await this.create(b, c);
2326
+ }
2327
+ if (isObject(a) && !isDefined(a.id)) {
2328
+ return await this.create(a, b);
2521
2329
  }
2522
2330
  throw new Error("Invalid arguments for createOrUpdate method");
2523
2331
  });
@@ -2529,17 +2337,27 @@ class RestRepository extends Query {
2529
2337
  if (a.length === 0)
2530
2338
  return [];
2531
2339
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2532
- const columns = isStringArray(b) ? b : ["*"];
2340
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2533
2341
  const result = await this.read(ids, columns);
2534
2342
  return result;
2535
2343
  }
2536
2344
  if (isString(a) && isObject(b)) {
2537
- const columns = isStringArray(c) ? c : void 0;
2538
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2345
+ if (a === "")
2346
+ throw new Error("The id can't be empty");
2347
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2348
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2539
2349
  }
2540
2350
  if (isObject(a) && isString(a.id)) {
2541
- const columns = isStringArray(c) ? c : void 0;
2542
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2351
+ if (a.id === "")
2352
+ throw new Error("The id can't be empty");
2353
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2354
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2355
+ }
2356
+ if (!isDefined(a) && isObject(b)) {
2357
+ return await this.create(b, c);
2358
+ }
2359
+ if (isObject(a) && !isDefined(a.id)) {
2360
+ return await this.create(a, b);
2543
2361
  }
2544
2362
  throw new Error("Invalid arguments for createOrReplace method");
2545
2363
  });
@@ -2556,7 +2374,7 @@ class RestRepository extends Query {
2556
2374
  return o.id;
2557
2375
  throw new Error("Invalid arguments for delete method");
2558
2376
  });
2559
- const columns = isStringArray(b) ? b : ["*"];
2377
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2560
2378
  const result = await this.read(a, columns);
2561
2379
  await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2562
2380
  return result;
@@ -2590,8 +2408,7 @@ class RestRepository extends Query {
2590
2408
  }
2591
2409
  async search(query, options = {}) {
2592
2410
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2593
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2594
- const { records } = await searchTable({
2411
+ const { records, totalCount } = await searchTable({
2595
2412
  pathParams: {
2596
2413
  workspace: "{workspaceId}",
2597
2414
  dbBranchName: "{dbBranch}",
@@ -2608,16 +2425,18 @@ class RestRepository extends Query {
2608
2425
  page: options.page,
2609
2426
  target: options.target
2610
2427
  },
2611
- ...fetchProps
2428
+ ...__privateGet$4(this, _getFetchProps).call(this)
2612
2429
  });
2613
2430
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2614
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2431
+ return {
2432
+ records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
2433
+ totalCount
2434
+ };
2615
2435
  });
2616
2436
  }
2617
2437
  async vectorSearch(column, query, options) {
2618
2438
  return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2619
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2620
- const { records } = await vectorSearchTable({
2439
+ const { records, totalCount } = await vectorSearchTable({
2621
2440
  pathParams: {
2622
2441
  workspace: "{workspaceId}",
2623
2442
  dbBranchName: "{dbBranch}",
@@ -2631,15 +2450,17 @@ class RestRepository extends Query {
2631
2450
  size: options?.size,
2632
2451
  filter: options?.filter
2633
2452
  },
2634
- ...fetchProps
2453
+ ...__privateGet$4(this, _getFetchProps).call(this)
2635
2454
  });
2636
2455
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2637
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2456
+ return {
2457
+ records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
2458
+ totalCount
2459
+ };
2638
2460
  });
2639
2461
  }
2640
2462
  async aggregate(aggs, filter) {
2641
2463
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2642
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2643
2464
  const result = await aggregateTable({
2644
2465
  pathParams: {
2645
2466
  workspace: "{workspaceId}",
@@ -2648,7 +2469,7 @@ class RestRepository extends Query {
2648
2469
  tableName: __privateGet$4(this, _table)
2649
2470
  },
2650
2471
  body: { aggs, filter },
2651
- ...fetchProps
2472
+ ...__privateGet$4(this, _getFetchProps).call(this)
2652
2473
  });
2653
2474
  return result;
2654
2475
  });
@@ -2659,7 +2480,6 @@ class RestRepository extends Query {
2659
2480
  if (cacheQuery)
2660
2481
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2661
2482
  const data = query.getQueryOptions();
2662
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2663
2483
  const { meta, records: objects } = await queryTable({
2664
2484
  pathParams: {
2665
2485
  workspace: "{workspaceId}",
@@ -2675,11 +2495,17 @@ class RestRepository extends Query {
2675
2495
  consistency: data.consistency
2676
2496
  },
2677
2497
  fetchOptions: data.fetchOptions,
2678
- ...fetchProps
2498
+ ...__privateGet$4(this, _getFetchProps).call(this)
2679
2499
  });
2680
2500
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2681
2501
  const records = objects.map(
2682
- (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2502
+ (record) => initObject(
2503
+ __privateGet$4(this, _db),
2504
+ schemaTables,
2505
+ __privateGet$4(this, _table),
2506
+ record,
2507
+ data.columns ?? ["*"]
2508
+ )
2683
2509
  );
2684
2510
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
2685
2511
  return new Page(query, meta, records);
@@ -2688,7 +2514,6 @@ class RestRepository extends Query {
2688
2514
  async summarizeTable(query, summaries, summariesFilter) {
2689
2515
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2690
2516
  const data = query.getQueryOptions();
2691
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2692
2517
  const result = await summarizeTable({
2693
2518
  pathParams: {
2694
2519
  workspace: "{workspaceId}",
@@ -2705,11 +2530,50 @@ class RestRepository extends Query {
2705
2530
  summaries,
2706
2531
  summariesFilter
2707
2532
  },
2708
- ...fetchProps
2533
+ ...__privateGet$4(this, _getFetchProps).call(this)
2709
2534
  });
2710
- return result;
2535
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2536
+ return {
2537
+ ...result,
2538
+ summaries: result.summaries.map(
2539
+ (summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
2540
+ )
2541
+ };
2711
2542
  });
2712
2543
  }
2544
+ ask(question, options) {
2545
+ const questionParam = options?.sessionId ? { message: question } : { question };
2546
+ const params = {
2547
+ pathParams: {
2548
+ workspace: "{workspaceId}",
2549
+ dbBranchName: "{dbBranch}",
2550
+ region: "{region}",
2551
+ tableName: __privateGet$4(this, _table),
2552
+ sessionId: options?.sessionId
2553
+ },
2554
+ body: {
2555
+ ...questionParam,
2556
+ rules: options?.rules,
2557
+ searchType: options?.searchType,
2558
+ search: options?.searchType === "keyword" ? options?.search : void 0,
2559
+ vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
2560
+ },
2561
+ ...__privateGet$4(this, _getFetchProps).call(this)
2562
+ };
2563
+ if (options?.onMessage) {
2564
+ fetchSSERequest({
2565
+ endpoint: "dataPlane",
2566
+ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
2567
+ method: "POST",
2568
+ onMessage: (message) => {
2569
+ options.onMessage?.({ answer: message.text, records: message.records });
2570
+ },
2571
+ ...params
2572
+ });
2573
+ } else {
2574
+ return askTableSession(params);
2575
+ }
2576
+ }
2713
2577
  }
2714
2578
  _table = new WeakMap();
2715
2579
  _getFetchProps = new WeakMap();
@@ -2719,8 +2583,7 @@ _schemaTables$2 = new WeakMap();
2719
2583
  _trace = new WeakMap();
2720
2584
  _insertRecordWithoutId = new WeakSet();
2721
2585
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2722
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2723
- const record = transformObjectLinks(object);
2586
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2724
2587
  const response = await insertRecord({
2725
2588
  pathParams: {
2726
2589
  workspace: "{workspaceId}",
@@ -2730,15 +2593,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2730
2593
  },
2731
2594
  queryParams: { columns },
2732
2595
  body: record,
2733
- ...fetchProps
2596
+ ...__privateGet$4(this, _getFetchProps).call(this)
2734
2597
  });
2735
2598
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2736
2599
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2737
2600
  };
2738
2601
  _insertRecordWithId = new WeakSet();
2739
2602
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2740
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2741
- const record = transformObjectLinks(object);
2603
+ if (!recordId)
2604
+ return null;
2605
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2742
2606
  const response = await insertRecordWithID({
2743
2607
  pathParams: {
2744
2608
  workspace: "{workspaceId}",
@@ -2749,30 +2613,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2749
2613
  },
2750
2614
  body: record,
2751
2615
  queryParams: { createOnly, columns, ifVersion },
2752
- ...fetchProps
2616
+ ...__privateGet$4(this, _getFetchProps).call(this)
2753
2617
  });
2754
2618
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2755
2619
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2756
2620
  };
2757
2621
  _insertRecords = new WeakSet();
2758
2622
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2759
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2760
- const chunkedOperations = chunk(
2761
- objects.map((object) => ({
2762
- insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2763
- })),
2764
- BULK_OPERATION_MAX_SIZE
2765
- );
2623
+ const operations = await promiseMap(objects, async (object) => {
2624
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2625
+ return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
2626
+ });
2627
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2766
2628
  const ids = [];
2767
- for (const operations of chunkedOperations) {
2629
+ for (const operations2 of chunkedOperations) {
2768
2630
  const { results } = await branchTransaction({
2769
2631
  pathParams: {
2770
2632
  workspace: "{workspaceId}",
2771
2633
  dbBranchName: "{dbBranch}",
2772
2634
  region: "{region}"
2773
2635
  },
2774
- body: { operations },
2775
- ...fetchProps
2636
+ body: { operations: operations2 },
2637
+ ...__privateGet$4(this, _getFetchProps).call(this)
2776
2638
  });
2777
2639
  for (const result of results) {
2778
2640
  if (result.operation === "insert") {
@@ -2786,8 +2648,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2786
2648
  };
2787
2649
  _updateRecordWithID = new WeakSet();
2788
2650
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2789
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2790
- const { id: _id, ...record } = transformObjectLinks(object);
2651
+ if (!recordId)
2652
+ return null;
2653
+ const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2791
2654
  try {
2792
2655
  const response = await updateRecordWithID({
2793
2656
  pathParams: {
@@ -2799,7 +2662,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2799
2662
  },
2800
2663
  queryParams: { columns, ifVersion },
2801
2664
  body: record,
2802
- ...fetchProps
2665
+ ...__privateGet$4(this, _getFetchProps).call(this)
2803
2666
  });
2804
2667
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2805
2668
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2812,23 +2675,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2812
2675
  };
2813
2676
  _updateRecords = new WeakSet();
2814
2677
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2815
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2816
- const chunkedOperations = chunk(
2817
- objects.map(({ id, ...object }) => ({
2818
- update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2819
- })),
2820
- BULK_OPERATION_MAX_SIZE
2821
- );
2678
+ const operations = await promiseMap(objects, async ({ id, ...object }) => {
2679
+ const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2680
+ return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
2681
+ });
2682
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2822
2683
  const ids = [];
2823
- for (const operations of chunkedOperations) {
2684
+ for (const operations2 of chunkedOperations) {
2824
2685
  const { results } = await branchTransaction({
2825
2686
  pathParams: {
2826
2687
  workspace: "{workspaceId}",
2827
2688
  dbBranchName: "{dbBranch}",
2828
2689
  region: "{region}"
2829
2690
  },
2830
- body: { operations },
2831
- ...fetchProps
2691
+ body: { operations: operations2 },
2692
+ ...__privateGet$4(this, _getFetchProps).call(this)
2832
2693
  });
2833
2694
  for (const result of results) {
2834
2695
  if (result.operation === "update") {
@@ -2842,7 +2703,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2842
2703
  };
2843
2704
  _upsertRecordWithID = new WeakSet();
2844
2705
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2845
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2706
+ if (!recordId)
2707
+ return null;
2846
2708
  const response = await upsertRecordWithID({
2847
2709
  pathParams: {
2848
2710
  workspace: "{workspaceId}",
@@ -2853,14 +2715,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2853
2715
  },
2854
2716
  queryParams: { columns, ifVersion },
2855
2717
  body: object,
2856
- ...fetchProps
2718
+ ...__privateGet$4(this, _getFetchProps).call(this)
2857
2719
  });
2858
2720
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2859
2721
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2860
2722
  };
2861
2723
  _deleteRecord = new WeakSet();
2862
2724
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2863
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2725
+ if (!recordId)
2726
+ return null;
2864
2727
  try {
2865
2728
  const response = await deleteRecord({
2866
2729
  pathParams: {
@@ -2871,7 +2734,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2871
2734
  recordId
2872
2735
  },
2873
2736
  queryParams: { columns },
2874
- ...fetchProps
2737
+ ...__privateGet$4(this, _getFetchProps).call(this)
2875
2738
  });
2876
2739
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2877
2740
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2884,9 +2747,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2884
2747
  };
2885
2748
  _deleteRecords = new WeakSet();
2886
2749
  deleteRecords_fn = async function(recordIds) {
2887
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2888
2750
  const chunkedOperations = chunk(
2889
- recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2751
+ compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2890
2752
  BULK_OPERATION_MAX_SIZE
2891
2753
  );
2892
2754
  for (const operations of chunkedOperations) {
@@ -2897,21 +2759,22 @@ deleteRecords_fn = async function(recordIds) {
2897
2759
  region: "{region}"
2898
2760
  },
2899
2761
  body: { operations },
2900
- ...fetchProps
2762
+ ...__privateGet$4(this, _getFetchProps).call(this)
2901
2763
  });
2902
2764
  }
2903
2765
  };
2904
2766
  _setCacheQuery = new WeakSet();
2905
2767
  setCacheQuery_fn = async function(query, meta, records) {
2906
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2768
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
2907
2769
  };
2908
2770
  _getCacheQuery = new WeakSet();
2909
2771
  getCacheQuery_fn = async function(query) {
2910
2772
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2911
- const result = await __privateGet$4(this, _cache).get(key);
2773
+ const result = await __privateGet$4(this, _cache)?.get(key);
2912
2774
  if (!result)
2913
2775
  return null;
2914
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
2776
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
2777
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2915
2778
  if (ttl < 0)
2916
2779
  return null;
2917
2780
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2921,20 +2784,47 @@ _getSchemaTables$1 = new WeakSet();
2921
2784
  getSchemaTables_fn$1 = async function() {
2922
2785
  if (__privateGet$4(this, _schemaTables$2))
2923
2786
  return __privateGet$4(this, _schemaTables$2);
2924
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2925
2787
  const { schema } = await getBranchDetails({
2926
2788
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2927
- ...fetchProps
2789
+ ...__privateGet$4(this, _getFetchProps).call(this)
2928
2790
  });
2929
2791
  __privateSet$4(this, _schemaTables$2, schema.tables);
2930
2792
  return schema.tables;
2931
2793
  };
2932
- const transformObjectLinks = (object) => {
2933
- return Object.entries(object).reduce((acc, [key, value]) => {
2794
+ _transformObjectToApi = new WeakSet();
2795
+ transformObjectToApi_fn = async function(object) {
2796
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2797
+ const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
2798
+ if (!schema)
2799
+ throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
2800
+ const result = {};
2801
+ for (const [key, value] of Object.entries(object)) {
2934
2802
  if (key === "xata")
2935
- return acc;
2936
- return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
2937
- }, {});
2803
+ continue;
2804
+ const type = schema.columns.find((column) => column.name === key)?.type;
2805
+ switch (type) {
2806
+ case "link": {
2807
+ result[key] = isIdentifiable(value) ? value.id : value;
2808
+ break;
2809
+ }
2810
+ case "datetime": {
2811
+ result[key] = value instanceof Date ? value.toISOString() : value;
2812
+ break;
2813
+ }
2814
+ case `file`:
2815
+ result[key] = await parseInputFileEntry(value);
2816
+ break;
2817
+ case "file[]":
2818
+ result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
2819
+ break;
2820
+ case "json":
2821
+ result[key] = stringifyJson(value);
2822
+ break;
2823
+ default:
2824
+ result[key] = value;
2825
+ }
2826
+ }
2827
+ return result;
2938
2828
  };
2939
2829
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2940
2830
  const data = {};
@@ -2966,18 +2856,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2966
2856
  if (item === column.name) {
2967
2857
  return [...acc, "*"];
2968
2858
  }
2969
- if (item.startsWith(`${column.name}.`)) {
2859
+ if (isString(item) && item.startsWith(`${column.name}.`)) {
2970
2860
  const [, ...path] = item.split(".");
2971
2861
  return [...acc, path.join(".")];
2972
2862
  }
2973
2863
  return acc;
2974
2864
  }, []);
2975
- data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2865
+ data[column.name] = initObject(
2866
+ db,
2867
+ schemaTables,
2868
+ linkTable,
2869
+ value,
2870
+ selectedLinkColumns
2871
+ );
2976
2872
  } else {
2977
2873
  data[column.name] = null;
2978
2874
  }
2979
2875
  break;
2980
2876
  }
2877
+ case "file":
2878
+ data[column.name] = isDefined(value) ? new XataFile(value) : null;
2879
+ break;
2880
+ case "file[]":
2881
+ data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
2882
+ break;
2883
+ case "json":
2884
+ data[column.name] = parseJson(value);
2885
+ break;
2981
2886
  default:
2982
2887
  data[column.name] = value ?? null;
2983
2888
  if (column.notNull === true && value === null) {
@@ -2987,30 +2892,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2987
2892
  }
2988
2893
  }
2989
2894
  const record = { ...data };
2895
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2990
2896
  record.read = function(columns2) {
2991
2897
  return db[table].read(record["id"], columns2);
2992
2898
  };
2993
2899
  record.update = function(data2, b, c) {
2994
- const columns2 = isStringArray(b) ? b : ["*"];
2900
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2995
2901
  const ifVersion = parseIfVersion(b, c);
2996
2902
  return db[table].update(record["id"], data2, columns2, { ifVersion });
2997
2903
  };
2998
2904
  record.replace = function(data2, b, c) {
2999
- const columns2 = isStringArray(b) ? b : ["*"];
2905
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
3000
2906
  const ifVersion = parseIfVersion(b, c);
3001
2907
  return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
3002
2908
  };
3003
2909
  record.delete = function() {
3004
2910
  return db[table].delete(record["id"]);
3005
2911
  };
2912
+ if (metadata !== void 0) {
2913
+ record.xata = Object.freeze(metadata);
2914
+ }
3006
2915
  record.getMetadata = function() {
3007
- return xata;
2916
+ return record.xata;
3008
2917
  };
3009
2918
  record.toSerializable = function() {
3010
- return JSON.parse(JSON.stringify(transformObjectLinks(data)));
2919
+ return JSON.parse(JSON.stringify(record));
3011
2920
  };
3012
2921
  record.toString = function() {
3013
- return JSON.stringify(transformObjectLinks(data));
2922
+ return JSON.stringify(record);
3014
2923
  };
3015
2924
  for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3016
2925
  Object.defineProperty(record, prop, { enumerable: false });
@@ -3028,11 +2937,7 @@ function extractId(value) {
3028
2937
  function isValidColumn(columns, column) {
3029
2938
  if (columns.includes("*"))
3030
2939
  return true;
3031
- if (column.type === "link") {
3032
- const linkColumns = columns.filter((item) => item.startsWith(column.name));
3033
- return linkColumns.length > 0;
3034
- }
3035
- return columns.includes(column.name);
2940
+ return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
3036
2941
  }
3037
2942
  function parseIfVersion(...args) {
3038
2943
  for (const arg of args) {
@@ -3109,10 +3014,12 @@ const notExists = (column) => ({ $notExists: column });
3109
3014
  const startsWith = (value) => ({ $startsWith: value });
3110
3015
  const endsWith = (value) => ({ $endsWith: value });
3111
3016
  const pattern = (value) => ({ $pattern: value });
3017
+ const iPattern = (value) => ({ $iPattern: value });
3112
3018
  const is = (value) => ({ $is: value });
3113
3019
  const equals = is;
3114
3020
  const isNot = (value) => ({ $isNot: value });
3115
3021
  const contains = (value) => ({ $contains: value });
3022
+ const iContains = (value) => ({ $iContains: value });
3116
3023
  const includes = (value) => ({ $includes: value });
3117
3024
  const includesAll = (value) => ({ $includesAll: value });
3118
3025
  const includesNone = (value) => ({ $includesNone: value });
@@ -3168,6 +3075,80 @@ class SchemaPlugin extends XataPlugin {
3168
3075
  _tables = new WeakMap();
3169
3076
  _schemaTables$1 = new WeakMap();
3170
3077
 
3078
+ class FilesPlugin extends XataPlugin {
3079
+ build(pluginOptions) {
3080
+ return {
3081
+ download: async (location) => {
3082
+ const { table, record, column, fileId = "" } = location ?? {};
3083
+ return await getFileItem({
3084
+ pathParams: {
3085
+ workspace: "{workspaceId}",
3086
+ dbBranchName: "{dbBranch}",
3087
+ region: "{region}",
3088
+ tableName: table ?? "",
3089
+ recordId: record ?? "",
3090
+ columnName: column ?? "",
3091
+ fileId
3092
+ },
3093
+ ...pluginOptions,
3094
+ rawResponse: true
3095
+ });
3096
+ },
3097
+ upload: async (location, file, options) => {
3098
+ const { table, record, column, fileId = "" } = location ?? {};
3099
+ const resolvedFile = await file;
3100
+ const contentType = options?.mediaType || getContentType(resolvedFile);
3101
+ const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
3102
+ return await putFileItem({
3103
+ ...pluginOptions,
3104
+ pathParams: {
3105
+ workspace: "{workspaceId}",
3106
+ dbBranchName: "{dbBranch}",
3107
+ region: "{region}",
3108
+ tableName: table ?? "",
3109
+ recordId: record ?? "",
3110
+ columnName: column ?? "",
3111
+ fileId
3112
+ },
3113
+ body,
3114
+ headers: { "Content-Type": contentType }
3115
+ });
3116
+ },
3117
+ delete: async (location) => {
3118
+ const { table, record, column, fileId = "" } = location ?? {};
3119
+ return await deleteFileItem({
3120
+ pathParams: {
3121
+ workspace: "{workspaceId}",
3122
+ dbBranchName: "{dbBranch}",
3123
+ region: "{region}",
3124
+ tableName: table ?? "",
3125
+ recordId: record ?? "",
3126
+ columnName: column ?? "",
3127
+ fileId
3128
+ },
3129
+ ...pluginOptions
3130
+ });
3131
+ }
3132
+ };
3133
+ }
3134
+ }
3135
+ function getContentType(file) {
3136
+ if (typeof file === "string") {
3137
+ return "text/plain";
3138
+ }
3139
+ if ("mediaType" in file && file.mediaType !== void 0) {
3140
+ return file.mediaType;
3141
+ }
3142
+ if (isBlob(file)) {
3143
+ return file.type;
3144
+ }
3145
+ try {
3146
+ return file.type;
3147
+ } catch (e) {
3148
+ }
3149
+ return "application/octet-stream";
3150
+ }
3151
+
3171
3152
  var __accessCheck$1 = (obj, member, msg) => {
3172
3153
  if (!member.has(obj))
3173
3154
  throw TypeError("Cannot " + msg);
@@ -3200,63 +3181,137 @@ class SearchPlugin extends XataPlugin {
3200
3181
  __privateAdd$1(this, _schemaTables, void 0);
3201
3182
  __privateSet$1(this, _schemaTables, schemaTables);
3202
3183
  }
3203
- build({ getFetchProps }) {
3184
+ build(pluginOptions) {
3204
3185
  return {
3205
3186
  all: async (query, options = {}) => {
3206
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3207
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3208
- return records.map((record) => {
3209
- const { table = "orphan" } = record.xata;
3210
- return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3211
- });
3187
+ const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3188
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3189
+ return {
3190
+ totalCount,
3191
+ records: records.map((record) => {
3192
+ const { table = "orphan" } = record.xata;
3193
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3194
+ })
3195
+ };
3212
3196
  },
3213
3197
  byTable: async (query, options = {}) => {
3214
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3215
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3216
- return records.reduce((acc, record) => {
3198
+ const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3199
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3200
+ const records = rawRecords.reduce((acc, record) => {
3217
3201
  const { table = "orphan" } = record.xata;
3218
3202
  const items = acc[table] ?? [];
3219
3203
  const item = initObject(this.db, schemaTables, table, record, ["*"]);
3220
3204
  return { ...acc, [table]: [...items, item] };
3221
3205
  }, {});
3206
+ return { totalCount, records };
3222
3207
  }
3223
3208
  };
3224
3209
  }
3225
3210
  }
3226
3211
  _schemaTables = new WeakMap();
3227
3212
  _search = new WeakSet();
3228
- search_fn = async function(query, options, getFetchProps) {
3229
- const fetchProps = await getFetchProps();
3213
+ search_fn = async function(query, options, pluginOptions) {
3230
3214
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3231
- const { records } = await searchBranch({
3215
+ const { records, totalCount } = await searchBranch({
3232
3216
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3217
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3233
3218
  body: { tables, query, fuzziness, prefix, highlight, page },
3234
- ...fetchProps
3219
+ ...pluginOptions
3235
3220
  });
3236
- return records;
3221
+ return { records, totalCount };
3237
3222
  };
3238
3223
  _getSchemaTables = new WeakSet();
3239
- getSchemaTables_fn = async function(getFetchProps) {
3224
+ getSchemaTables_fn = async function(pluginOptions) {
3240
3225
  if (__privateGet$1(this, _schemaTables))
3241
3226
  return __privateGet$1(this, _schemaTables);
3242
- const fetchProps = await getFetchProps();
3243
3227
  const { schema } = await getBranchDetails({
3244
3228
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3245
- ...fetchProps
3229
+ ...pluginOptions
3246
3230
  });
3247
3231
  __privateSet$1(this, _schemaTables, schema.tables);
3248
3232
  return schema.tables;
3249
3233
  };
3250
3234
 
3235
+ function escapeElement(elementRepresentation) {
3236
+ const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
3237
+ return '"' + escaped + '"';
3238
+ }
3239
+ function arrayString(val) {
3240
+ let result = "{";
3241
+ for (let i = 0; i < val.length; i++) {
3242
+ if (i > 0) {
3243
+ result = result + ",";
3244
+ }
3245
+ if (val[i] === null || typeof val[i] === "undefined") {
3246
+ result = result + "NULL";
3247
+ } else if (Array.isArray(val[i])) {
3248
+ result = result + arrayString(val[i]);
3249
+ } else if (val[i] instanceof Buffer) {
3250
+ result += "\\\\x" + val[i].toString("hex");
3251
+ } else {
3252
+ result += escapeElement(prepareValue(val[i]));
3253
+ }
3254
+ }
3255
+ result = result + "}";
3256
+ return result;
3257
+ }
3258
+ function prepareValue(value) {
3259
+ if (!isDefined(value))
3260
+ return null;
3261
+ if (value instanceof Date) {
3262
+ return value.toISOString();
3263
+ }
3264
+ if (Array.isArray(value)) {
3265
+ return arrayString(value);
3266
+ }
3267
+ if (isObject(value)) {
3268
+ return JSON.stringify(value);
3269
+ }
3270
+ try {
3271
+ return value.toString();
3272
+ } catch (e) {
3273
+ return value;
3274
+ }
3275
+ }
3276
+ function prepareParams(param1, param2) {
3277
+ if (isString(param1)) {
3278
+ return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
3279
+ }
3280
+ if (isStringArray(param1)) {
3281
+ const statement = param1.reduce((acc, curr, index) => {
3282
+ return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
3283
+ }, "");
3284
+ return { statement, params: param2?.map((value) => prepareValue(value)) };
3285
+ }
3286
+ if (isObject(param1)) {
3287
+ const { statement, params, consistency } = param1;
3288
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency };
3289
+ }
3290
+ throw new Error("Invalid query");
3291
+ }
3292
+
3293
+ class SQLPlugin extends XataPlugin {
3294
+ build(pluginOptions) {
3295
+ return async (param1, ...param2) => {
3296
+ const { statement, params, consistency } = prepareParams(param1, param2);
3297
+ const { records, warning, columns } = await sqlQuery({
3298
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3299
+ body: { statement, params, consistency },
3300
+ ...pluginOptions
3301
+ });
3302
+ return { records, warning, columns };
3303
+ };
3304
+ }
3305
+ }
3306
+
3251
3307
  class TransactionPlugin extends XataPlugin {
3252
- build({ getFetchProps }) {
3308
+ build(pluginOptions) {
3253
3309
  return {
3254
3310
  run: async (operations) => {
3255
- const fetchProps = await getFetchProps();
3256
3311
  const response = await branchTransaction({
3257
3312
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3258
3313
  body: { operations },
3259
- ...fetchProps
3314
+ ...pluginOptions
3260
3315
  });
3261
3316
  return response;
3262
3317
  }
@@ -3264,91 +3319,6 @@ class TransactionPlugin extends XataPlugin {
3264
3319
  }
3265
3320
  }
3266
3321
 
3267
- const isBranchStrategyBuilder = (strategy) => {
3268
- return typeof strategy === "function";
3269
- };
3270
-
3271
- async function getCurrentBranchName(options) {
3272
- const { branch, envBranch } = getEnvironment();
3273
- if (branch)
3274
- return branch;
3275
- const gitBranch = envBranch || await getGitBranch();
3276
- return resolveXataBranch(gitBranch, options);
3277
- }
3278
- async function getCurrentBranchDetails(options) {
3279
- const branch = await getCurrentBranchName(options);
3280
- return getDatabaseBranch(branch, options);
3281
- }
3282
- async function resolveXataBranch(gitBranch, options) {
3283
- const databaseURL = options?.databaseURL || getDatabaseURL();
3284
- const apiKey = options?.apiKey || getAPIKey();
3285
- if (!databaseURL)
3286
- throw new Error(
3287
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3288
- );
3289
- if (!apiKey)
3290
- throw new Error(
3291
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3292
- );
3293
- const [protocol, , host, , dbName] = databaseURL.split("/");
3294
- const urlParts = parseWorkspacesUrlParts(host);
3295
- if (!urlParts)
3296
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3297
- const { workspace, region } = urlParts;
3298
- const { fallbackBranch } = getEnvironment();
3299
- const { branch } = await resolveBranch({
3300
- apiKey,
3301
- apiUrl: databaseURL,
3302
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3303
- workspacesApiUrl: `${protocol}//${host}`,
3304
- pathParams: { dbName, workspace, region },
3305
- queryParams: { gitBranch, fallbackBranch },
3306
- trace: defaultTrace,
3307
- clientName: options?.clientName,
3308
- xataAgentExtra: options?.xataAgentExtra
3309
- });
3310
- return branch;
3311
- }
3312
- async function getDatabaseBranch(branch, options) {
3313
- const databaseURL = options?.databaseURL || getDatabaseURL();
3314
- const apiKey = options?.apiKey || getAPIKey();
3315
- if (!databaseURL)
3316
- throw new Error(
3317
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3318
- );
3319
- if (!apiKey)
3320
- throw new Error(
3321
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3322
- );
3323
- const [protocol, , host, , database] = databaseURL.split("/");
3324
- const urlParts = parseWorkspacesUrlParts(host);
3325
- if (!urlParts)
3326
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3327
- const { workspace, region } = urlParts;
3328
- try {
3329
- return await getBranchDetails({
3330
- apiKey,
3331
- apiUrl: databaseURL,
3332
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3333
- workspacesApiUrl: `${protocol}//${host}`,
3334
- pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3335
- trace: defaultTrace
3336
- });
3337
- } catch (err) {
3338
- if (isObject(err) && err.status === 404)
3339
- return null;
3340
- throw err;
3341
- }
3342
- }
3343
- function getDatabaseURL() {
3344
- try {
3345
- const { databaseURL } = getEnvironment();
3346
- return databaseURL;
3347
- } catch (err) {
3348
- return void 0;
3349
- }
3350
- }
3351
-
3352
3322
  var __accessCheck = (obj, member, msg) => {
3353
3323
  if (!member.has(obj))
3354
3324
  throw TypeError("Cannot " + msg);
@@ -3372,46 +3342,41 @@ var __privateMethod = (obj, member, method) => {
3372
3342
  return method;
3373
3343
  };
3374
3344
  const buildClient = (plugins) => {
3375
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3345
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3376
3346
  return _a = class {
3377
3347
  constructor(options = {}, schemaTables) {
3378
3348
  __privateAdd(this, _parseOptions);
3379
3349
  __privateAdd(this, _getFetchProps);
3380
- __privateAdd(this, _evaluateBranch);
3381
- __privateAdd(this, _branch, void 0);
3382
3350
  __privateAdd(this, _options, void 0);
3383
3351
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3384
3352
  __privateSet(this, _options, safeOptions);
3385
3353
  const pluginOptions = {
3386
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3354
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3387
3355
  cache: safeOptions.cache,
3388
- trace: safeOptions.trace
3356
+ host: safeOptions.host
3389
3357
  };
3390
3358
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3391
3359
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3392
3360
  const transactions = new TransactionPlugin().build(pluginOptions);
3361
+ const sql = new SQLPlugin().build(pluginOptions);
3362
+ const files = new FilesPlugin().build(pluginOptions);
3393
3363
  this.db = db;
3394
3364
  this.search = search;
3395
3365
  this.transactions = transactions;
3366
+ this.sql = sql;
3367
+ this.files = files;
3396
3368
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3397
3369
  if (namespace === void 0)
3398
3370
  continue;
3399
- const result = namespace.build(pluginOptions);
3400
- if (result instanceof Promise) {
3401
- void result.then((namespace2) => {
3402
- this[key] = namespace2;
3403
- });
3404
- } else {
3405
- this[key] = result;
3406
- }
3371
+ this[key] = namespace.build(pluginOptions);
3407
3372
  }
3408
3373
  }
3409
3374
  async getConfig() {
3410
3375
  const databaseURL = __privateGet(this, _options).databaseURL;
3411
- const branch = await __privateGet(this, _options).branch();
3376
+ const branch = __privateGet(this, _options).branch;
3412
3377
  return { databaseURL, branch };
3413
3378
  }
3414
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3379
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3415
3380
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3416
3381
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3417
3382
  if (isBrowser && !enableBrowser) {
@@ -3425,20 +3390,34 @@ const buildClient = (plugins) => {
3425
3390
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3426
3391
  const trace = options?.trace ?? defaultTrace;
3427
3392
  const clientName = options?.clientName;
3393
+ const host = options?.host ?? "production";
3428
3394
  const xataAgentExtra = options?.xataAgentExtra;
3429
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3430
- apiKey,
3431
- databaseURL,
3432
- fetchImpl: options?.fetch,
3433
- clientName,
3434
- xataAgentExtra
3435
- });
3436
3395
  if (!apiKey) {
3437
3396
  throw new Error("Option apiKey is required");
3438
3397
  }
3439
3398
  if (!databaseURL) {
3440
3399
  throw new Error("Option databaseURL is required");
3441
3400
  }
3401
+ const envBranch = getBranch();
3402
+ const previewBranch = getPreviewBranch();
3403
+ const branch = options?.branch || previewBranch || envBranch || "main";
3404
+ if (!!previewBranch && branch !== previewBranch) {
3405
+ console.warn(
3406
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
3407
+ );
3408
+ } else if (!!envBranch && branch !== envBranch) {
3409
+ console.warn(
3410
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3411
+ );
3412
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
3413
+ console.warn(
3414
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3415
+ );
3416
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
3417
+ console.warn(
3418
+ `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.`
3419
+ );
3420
+ }
3442
3421
  return {
3443
3422
  fetch,
3444
3423
  databaseURL,
@@ -3446,12 +3425,13 @@ const buildClient = (plugins) => {
3446
3425
  branch,
3447
3426
  cache,
3448
3427
  trace,
3428
+ host,
3449
3429
  clientID: generateUUID(),
3450
3430
  enableBrowser,
3451
3431
  clientName,
3452
3432
  xataAgentExtra
3453
3433
  };
3454
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3434
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3455
3435
  fetch,
3456
3436
  apiKey,
3457
3437
  databaseURL,
@@ -3461,16 +3441,14 @@ const buildClient = (plugins) => {
3461
3441
  clientName,
3462
3442
  xataAgentExtra
3463
3443
  }) {
3464
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3465
- if (!branchValue)
3466
- throw new Error("Unable to resolve branch value");
3467
3444
  return {
3468
- fetchImpl: fetch,
3445
+ fetch,
3469
3446
  apiKey,
3470
3447
  apiUrl: "",
3448
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3471
3449
  workspacesApiUrl: (path, params) => {
3472
3450
  const hasBranch = params.dbBranchName ?? params.branch;
3473
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
3451
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3474
3452
  return databaseURL + newPath;
3475
3453
  },
3476
3454
  trace,
@@ -3478,22 +3456,6 @@ const buildClient = (plugins) => {
3478
3456
  clientName,
3479
3457
  xataAgentExtra
3480
3458
  };
3481
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3482
- if (__privateGet(this, _branch))
3483
- return __privateGet(this, _branch);
3484
- if (param === void 0)
3485
- return void 0;
3486
- const strategies = Array.isArray(param) ? [...param] : [param];
3487
- const evaluateBranch = async (strategy) => {
3488
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3489
- };
3490
- for await (const strategy of strategies) {
3491
- const branch = await evaluateBranch(strategy);
3492
- if (branch) {
3493
- __privateSet(this, _branch, branch);
3494
- return branch;
3495
- }
3496
- }
3497
3459
  }, _a;
3498
3460
  };
3499
3461
  class BaseClient extends buildClient() {
@@ -3566,21 +3528,6 @@ const deserialize = (json) => {
3566
3528
  return defaultSerializer.fromJSON(json);
3567
3529
  };
3568
3530
 
3569
- function buildWorkerRunner(config) {
3570
- return function xataWorker(name, worker) {
3571
- return async (...args) => {
3572
- const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
3573
- const result = await fetch(url, {
3574
- method: "POST",
3575
- headers: { "Content-Type": "application/json" },
3576
- body: serialize({ args })
3577
- });
3578
- const text = await result.text();
3579
- return deserialize(text);
3580
- };
3581
- };
3582
- }
3583
-
3584
3531
  class XataError extends Error {
3585
3532
  constructor(message, status) {
3586
3533
  super(message);
@@ -3588,5 +3535,5 @@ class XataError extends Error {
3588
3535
  }
3589
3536
  }
3590
3537
 
3591
- 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, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, 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, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
3538
+ export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollMigrationHistory, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
3592
3539
  //# sourceMappingURL=index.mjs.map