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