@xata.io/client 0.0.0-alpha.vf166c7e → 0.0.0-alpha.vf181bf6b5770b15d42125b2728f3bf80a87e6333

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.21.6";
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.1";
306
532
 
307
533
  class ErrorWithCause extends Error {
308
534
  constructor(message, options) {
@@ -378,6 +604,18 @@ function hostHeader(url) {
378
604
  const { groups } = pattern.exec(url) ?? {};
379
605
  return groups?.host ? { Host: groups.host } : {};
380
606
  }
607
+ async function parseBody(body, headers) {
608
+ if (!isDefined(body))
609
+ return void 0;
610
+ if (isBlob(body) || typeof body.text === "function") {
611
+ return body;
612
+ }
613
+ const { "Content-Type": contentType } = headers ?? {};
614
+ if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
615
+ return JSON.stringify(body);
616
+ }
617
+ return body;
618
+ }
381
619
  const defaultClientID = generateUUID();
382
620
  async function fetch$1({
383
621
  url: path,
@@ -386,7 +624,7 @@ async function fetch$1({
386
624
  headers: customHeaders,
387
625
  pathParams,
388
626
  queryParams,
389
- fetchImpl,
627
+ fetch: fetch2,
390
628
  apiKey,
391
629
  endpoint,
392
630
  apiUrl,
@@ -396,9 +634,11 @@ async function fetch$1({
396
634
  clientID,
397
635
  sessionID,
398
636
  clientName,
399
- fetchOptions = {}
637
+ xataAgentExtra,
638
+ fetchOptions = {},
639
+ rawResponse = false
400
640
  }) {
401
- pool.setFetch(fetchImpl);
641
+ pool.setFetch(fetch2);
402
642
  return await trace(
403
643
  `${method.toUpperCase()} ${path}`,
404
644
  async ({ setAttributes }) => {
@@ -412,9 +652,10 @@ async function fetch$1({
412
652
  const xataAgent = compact([
413
653
  ["client", "TS_SDK"],
414
654
  ["version", VERSION],
415
- isDefined(clientName) ? ["service", clientName] : void 0
655
+ isDefined(clientName) ? ["service", clientName] : void 0,
656
+ ...Object.entries(xataAgentExtra ?? {})
416
657
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
417
- const headers = {
658
+ const headers = compactObject({
418
659
  "Accept-Encoding": "identity",
419
660
  "Content-Type": "application/json",
420
661
  "X-Xata-Client-ID": clientID ?? defaultClientID,
@@ -423,11 +664,11 @@ async function fetch$1({
423
664
  ...customHeaders,
424
665
  ...hostHeader(fullUrl),
425
666
  Authorization: `Bearer ${apiKey}`
426
- };
667
+ });
427
668
  const response = await pool.request(url, {
428
669
  ...fetchOptions,
429
670
  method: method.toUpperCase(),
430
- body: body ? JSON.stringify(body) : void 0,
671
+ body: await parseBody(body, headers),
431
672
  headers,
432
673
  signal
433
674
  });
@@ -438,8 +679,12 @@ async function fetch$1({
438
679
  [TraceAttributes.HTTP_REQUEST_ID]: requestId,
439
680
  [TraceAttributes.HTTP_STATUS_CODE]: response.status,
440
681
  [TraceAttributes.HTTP_HOST]: host,
441
- [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
682
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
683
+ [TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
442
684
  });
685
+ const message = response.headers?.get("x-xata-message");
686
+ if (message)
687
+ console.warn(message);
443
688
  if (response.status === 204) {
444
689
  return {};
445
690
  }
@@ -447,7 +692,7 @@ async function fetch$1({
447
692
  throw new FetcherError(response.status, "Rate limit exceeded", requestId);
448
693
  }
449
694
  try {
450
- const jsonResponse = await response.json();
695
+ const jsonResponse = rawResponse ? await response.blob() : await response.json();
451
696
  if (response.ok) {
452
697
  return jsonResponse;
453
698
  }
@@ -459,6 +704,59 @@ async function fetch$1({
459
704
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
460
705
  );
461
706
  }
707
+ function fetchSSERequest({
708
+ url: path,
709
+ method,
710
+ body,
711
+ headers: customHeaders,
712
+ pathParams,
713
+ queryParams,
714
+ fetch: fetch2,
715
+ apiKey,
716
+ endpoint,
717
+ apiUrl,
718
+ workspacesApiUrl,
719
+ onMessage,
720
+ onError,
721
+ onClose,
722
+ signal,
723
+ clientID,
724
+ sessionID,
725
+ clientName,
726
+ xataAgentExtra
727
+ }) {
728
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
729
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
730
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
731
+ void fetchEventSource(url, {
732
+ method,
733
+ body: JSON.stringify(body),
734
+ fetch: fetch2,
735
+ signal,
736
+ headers: {
737
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
738
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
739
+ "X-Xata-Agent": compact([
740
+ ["client", "TS_SDK"],
741
+ ["version", VERSION],
742
+ isDefined(clientName) ? ["service", clientName] : void 0,
743
+ ...Object.entries(xataAgentExtra ?? {})
744
+ ]).map(([key, value]) => `${key}=${value}`).join("; "),
745
+ ...customHeaders,
746
+ Authorization: `Bearer ${apiKey}`,
747
+ "Content-Type": "application/json"
748
+ },
749
+ onmessage(ev) {
750
+ onMessage?.(JSON.parse(ev.data));
751
+ },
752
+ onerror(ev) {
753
+ onError?.(JSON.parse(ev.data));
754
+ },
755
+ onclose() {
756
+ onClose?.();
757
+ }
758
+ });
759
+ }
462
760
  function parseUrl(url) {
463
761
  try {
464
762
  const { host, protocol } = new URL(url);
@@ -470,6 +768,19 @@ function parseUrl(url) {
470
768
 
471
769
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
472
770
 
771
+ const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
772
+ const pgRollStatus = (variables, signal) => dataPlaneFetch({
773
+ url: "/db/{dbBranchName}/pgroll/status",
774
+ method: "get",
775
+ ...variables,
776
+ signal
777
+ });
778
+ const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
779
+ url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
780
+ method: "get",
781
+ ...variables,
782
+ signal
783
+ });
473
784
  const getBranchList = (variables, signal) => dataPlaneFetch({
474
785
  url: "/dbs/{dbName}",
475
786
  method: "get",
@@ -489,6 +800,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
489
800
  ...variables,
490
801
  signal
491
802
  });
803
+ const getSchema = (variables, signal) => dataPlaneFetch({
804
+ url: "/db/{dbBranchName}/schema",
805
+ method: "get",
806
+ ...variables,
807
+ signal
808
+ });
809
+ const copyBranch = (variables, signal) => dataPlaneFetch({
810
+ url: "/db/{dbBranchName}/copy",
811
+ method: "post",
812
+ ...variables,
813
+ signal
814
+ });
492
815
  const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
493
816
  url: "/db/{dbBranchName}/metadata",
494
817
  method: "put",
@@ -514,7 +837,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
514
837
  const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
515
838
  const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
516
839
  const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
517
- const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
518
840
  const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
519
841
  const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
520
842
  const getMigrationRequest = (variables, signal) => dataPlaneFetch({
@@ -539,6 +861,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
539
861
  const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
540
862
  const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
541
863
  const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
864
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
542
865
  const createTable = (variables, signal) => dataPlaneFetch({
543
866
  url: "/db/{dbBranchName}/tables/{tableName}",
544
867
  method: "put",
@@ -581,7 +904,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
581
904
  ...variables,
582
905
  signal
583
906
  });
907
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
584
908
  const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
909
+ const getFileItem = (variables, signal) => dataPlaneFetch({
910
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
911
+ method: "get",
912
+ ...variables,
913
+ signal
914
+ });
915
+ const putFileItem = (variables, signal) => dataPlaneFetch({
916
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
917
+ method: "put",
918
+ ...variables,
919
+ signal
920
+ });
921
+ const deleteFileItem = (variables, signal) => dataPlaneFetch({
922
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
923
+ method: "delete",
924
+ ...variables,
925
+ signal
926
+ });
927
+ const getFile = (variables, signal) => dataPlaneFetch({
928
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
929
+ method: "get",
930
+ ...variables,
931
+ signal
932
+ });
933
+ const putFile = (variables, signal) => dataPlaneFetch({
934
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
935
+ method: "put",
936
+ ...variables,
937
+ signal
938
+ });
939
+ const deleteFile = (variables, signal) => dataPlaneFetch({
940
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
941
+ method: "delete",
942
+ ...variables,
943
+ signal
944
+ });
585
945
  const getRecord = (variables, signal) => dataPlaneFetch({
586
946
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
587
947
  method: "get",
@@ -611,14 +971,38 @@ const searchTable = (variables, signal) => dataPlaneFetch({
611
971
  ...variables,
612
972
  signal
613
973
  });
974
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
975
+ const askTable = (variables, signal) => dataPlaneFetch({
976
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
977
+ method: "post",
978
+ ...variables,
979
+ signal
980
+ });
981
+ const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
614
982
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
615
983
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
984
+ const fileAccess = (variables, signal) => dataPlaneFetch({
985
+ url: "/file/{fileId}",
986
+ method: "get",
987
+ ...variables,
988
+ signal
989
+ });
990
+ const sqlQuery = (variables, signal) => dataPlaneFetch({
991
+ url: "/db/{dbBranchName}/sql",
992
+ method: "post",
993
+ ...variables,
994
+ signal
995
+ });
616
996
  const operationsByTag$2 = {
617
997
  branch: {
998
+ applyMigration,
999
+ pgRollStatus,
1000
+ pgRollJobStatus,
618
1001
  getBranchList,
619
1002
  getBranchDetails,
620
1003
  createBranch,
621
1004
  deleteBranch,
1005
+ copyBranch,
622
1006
  updateBranchMetadata,
623
1007
  getBranchMetadata,
624
1008
  getBranchStats,
@@ -628,6 +1012,7 @@ const operationsByTag$2 = {
628
1012
  resolveBranch
629
1013
  },
630
1014
  migrations: {
1015
+ getSchema,
631
1016
  getBranchMigrationHistory,
632
1017
  getBranchMigrationPlan,
633
1018
  executeBranchMigrationPlan,
@@ -636,17 +1021,8 @@ const operationsByTag$2 = {
636
1021
  compareBranchSchemas,
637
1022
  updateBranchSchema,
638
1023
  previewBranchSchemaEdit,
639
- applyBranchSchemaEdit
640
- },
641
- records: {
642
- branchTransaction,
643
- insertRecord,
644
- getRecord,
645
- insertRecordWithID,
646
- updateRecordWithID,
647
- upsertRecordWithID,
648
- deleteRecord,
649
- bulkInsertTableRecords
1024
+ applyBranchSchemaEdit,
1025
+ pushBranchMigrations
650
1026
  },
651
1027
  migrationRequests: {
652
1028
  queryMigrationRequests,
@@ -670,11 +1046,34 @@ const operationsByTag$2 = {
670
1046
  updateColumn,
671
1047
  deleteColumn
672
1048
  },
673
- searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
1049
+ records: {
1050
+ branchTransaction,
1051
+ insertRecord,
1052
+ getRecord,
1053
+ insertRecordWithID,
1054
+ updateRecordWithID,
1055
+ upsertRecordWithID,
1056
+ deleteRecord,
1057
+ bulkInsertTableRecords
1058
+ },
1059
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
1060
+ searchAndFilter: {
1061
+ queryTable,
1062
+ searchBranch,
1063
+ searchTable,
1064
+ vectorSearchTable,
1065
+ askTable,
1066
+ askTableSession,
1067
+ summarizeTable,
1068
+ aggregateTable
1069
+ },
1070
+ sql: { sqlQuery }
674
1071
  };
675
1072
 
676
1073
  const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
677
1074
 
1075
+ const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
1076
+ const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
678
1077
  const getUser = (variables, signal) => controlPlaneFetch({
679
1078
  url: "/user",
680
1079
  method: "get",
@@ -711,6 +1110,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
711
1110
  ...variables,
712
1111
  signal
713
1112
  });
1113
+ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
1114
+ url: "/user/oauth/clients",
1115
+ method: "get",
1116
+ ...variables,
1117
+ signal
1118
+ });
1119
+ const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
1120
+ url: "/user/oauth/clients/{clientId}",
1121
+ method: "delete",
1122
+ ...variables,
1123
+ signal
1124
+ });
1125
+ const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
1126
+ url: "/user/oauth/tokens",
1127
+ method: "get",
1128
+ ...variables,
1129
+ signal
1130
+ });
1131
+ const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
1132
+ url: "/user/oauth/tokens/{token}",
1133
+ method: "delete",
1134
+ ...variables,
1135
+ signal
1136
+ });
1137
+ const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
714
1138
  const getWorkspacesList = (variables, signal) => controlPlaneFetch({
715
1139
  url: "/workspaces",
716
1140
  method: "get",
@@ -754,6 +1178,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
754
1178
  const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
755
1179
  const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
756
1180
  const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
1181
+ const listClusters = (variables, signal) => controlPlaneFetch({
1182
+ url: "/workspaces/{workspaceId}/clusters",
1183
+ method: "get",
1184
+ ...variables,
1185
+ signal
1186
+ });
1187
+ const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
1188
+ const getCluster = (variables, signal) => controlPlaneFetch({
1189
+ url: "/workspaces/{workspaceId}/clusters/{clusterId}",
1190
+ method: "get",
1191
+ ...variables,
1192
+ signal
1193
+ });
1194
+ const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
757
1195
  const getDatabaseList = (variables, signal) => controlPlaneFetch({
758
1196
  url: "/workspaces/{workspaceId}/dbs",
759
1197
  method: "get",
@@ -769,6 +1207,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
769
1207
  });
770
1208
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
771
1209
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1210
+ const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
1211
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
1212
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
1213
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
772
1214
  const listRegions = (variables, signal) => controlPlaneFetch({
773
1215
  url: "/workspaces/{workspaceId}/regions",
774
1216
  method: "get",
@@ -776,6 +1218,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
776
1218
  signal
777
1219
  });
778
1220
  const operationsByTag$1 = {
1221
+ oAuth: {
1222
+ getAuthorizationCode,
1223
+ grantAuthorizationCode,
1224
+ getUserOAuthClients,
1225
+ deleteUserOAuthClient,
1226
+ getUserOAuthAccessTokens,
1227
+ deleteOAuthAccessToken,
1228
+ updateOAuthAccessToken
1229
+ },
779
1230
  users: { getUser, updateUser, deleteUser },
780
1231
  authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
781
1232
  workspaces: {
@@ -795,12 +1246,17 @@ const operationsByTag$1 = {
795
1246
  acceptWorkspaceMemberInvite,
796
1247
  resendWorkspaceMemberInvite
797
1248
  },
1249
+ xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
798
1250
  databases: {
799
1251
  getDatabaseList,
800
1252
  createDatabase,
801
1253
  deleteDatabase,
802
1254
  getDatabaseMetadata,
803
1255
  updateDatabaseMetadata,
1256
+ renameDatabase,
1257
+ getDatabaseGithubSettings,
1258
+ updateDatabaseGithubSettings,
1259
+ deleteDatabaseGithubSettings,
804
1260
  listRegions
805
1261
  }
806
1262
  };
@@ -821,8 +1277,12 @@ const providers = {
821
1277
  workspaces: "https://{workspaceId}.{region}.xata.sh"
822
1278
  },
823
1279
  staging: {
824
- main: "https://staging.xatabase.co",
825
- workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
1280
+ main: "https://api.staging-xata.dev",
1281
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
1282
+ },
1283
+ dev: {
1284
+ main: "https://api.dev-xata.dev",
1285
+ workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
826
1286
  }
827
1287
  };
828
1288
  function isHostProviderAlias(alias) {
@@ -840,40 +1300,26 @@ function parseProviderString(provider = "production") {
840
1300
  return null;
841
1301
  return { main, workspaces };
842
1302
  }
1303
+ function buildProviderString(provider) {
1304
+ if (isHostProviderAlias(provider))
1305
+ return provider;
1306
+ return `${provider.main},${provider.workspaces}`;
1307
+ }
843
1308
  function parseWorkspacesUrlParts(url) {
844
1309
  if (!isString(url))
845
1310
  return null;
846
1311
  const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
847
- const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
848
- const match = url.match(regex) || url.match(regexStaging);
1312
+ const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
1313
+ const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
1314
+ const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
1315
+ const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
849
1316
  if (!match)
850
1317
  return null;
851
1318
  return { workspace: match[1], region: match[2] };
852
1319
  }
853
1320
 
854
- var __accessCheck$7 = (obj, member, msg) => {
855
- if (!member.has(obj))
856
- throw TypeError("Cannot " + msg);
857
- };
858
- var __privateGet$7 = (obj, member, getter) => {
859
- __accessCheck$7(obj, member, "read from private field");
860
- return getter ? getter.call(obj) : member.get(obj);
861
- };
862
- var __privateAdd$7 = (obj, member, value) => {
863
- if (member.has(obj))
864
- throw TypeError("Cannot add the same private member more than once");
865
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
866
- };
867
- var __privateSet$7 = (obj, member, value, setter) => {
868
- __accessCheck$7(obj, member, "write to private field");
869
- setter ? setter.call(obj, value) : member.set(obj, value);
870
- return value;
871
- };
872
- var _extraProps, _namespaces;
873
- class XataApiClient {
1321
+ const buildApiClient = () => class {
874
1322
  constructor(options = {}) {
875
- __privateAdd$7(this, _extraProps, void 0);
876
- __privateAdd$7(this, _namespaces, {});
877
1323
  const provider = options.host ?? "production";
878
1324
  const apiKey = options.apiKey ?? getAPIKey();
879
1325
  const trace = options.trace ?? defaultTrace;
@@ -881,1023 +1327,237 @@ class XataApiClient {
881
1327
  if (!apiKey) {
882
1328
  throw new Error("Could not resolve a valid apiKey");
883
1329
  }
884
- __privateSet$7(this, _extraProps, {
1330
+ const extraProps = {
885
1331
  apiUrl: getHostUrl(provider, "main"),
886
1332
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
887
- fetchImpl: getFetchImplementation(options.fetch),
1333
+ fetch: getFetchImplementation(options.fetch),
888
1334
  apiKey,
889
1335
  trace,
890
1336
  clientName: options.clientName,
1337
+ xataAgentExtra: options.xataAgentExtra,
891
1338
  clientID
1339
+ };
1340
+ return new Proxy(this, {
1341
+ get: (_target, namespace) => {
1342
+ if (operationsByTag[namespace] === void 0) {
1343
+ return void 0;
1344
+ }
1345
+ return new Proxy(
1346
+ {},
1347
+ {
1348
+ get: (_target2, operation) => {
1349
+ if (operationsByTag[namespace][operation] === void 0) {
1350
+ return void 0;
1351
+ }
1352
+ const method = operationsByTag[namespace][operation];
1353
+ return async (params) => {
1354
+ return await method({ ...params, ...extraProps });
1355
+ };
1356
+ }
1357
+ }
1358
+ );
1359
+ }
892
1360
  });
893
1361
  }
894
- get user() {
895
- if (!__privateGet$7(this, _namespaces).user)
896
- __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
897
- return __privateGet$7(this, _namespaces).user;
898
- }
899
- get authentication() {
900
- if (!__privateGet$7(this, _namespaces).authentication)
901
- __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
902
- return __privateGet$7(this, _namespaces).authentication;
903
- }
904
- get workspaces() {
905
- if (!__privateGet$7(this, _namespaces).workspaces)
906
- __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
907
- return __privateGet$7(this, _namespaces).workspaces;
908
- }
909
- get invites() {
910
- if (!__privateGet$7(this, _namespaces).invites)
911
- __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
912
- return __privateGet$7(this, _namespaces).invites;
913
- }
914
- get database() {
915
- if (!__privateGet$7(this, _namespaces).database)
916
- __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
917
- return __privateGet$7(this, _namespaces).database;
918
- }
919
- get branches() {
920
- if (!__privateGet$7(this, _namespaces).branches)
921
- __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
922
- return __privateGet$7(this, _namespaces).branches;
923
- }
924
- get migrations() {
925
- if (!__privateGet$7(this, _namespaces).migrations)
926
- __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
927
- return __privateGet$7(this, _namespaces).migrations;
928
- }
929
- get migrationRequests() {
930
- if (!__privateGet$7(this, _namespaces).migrationRequests)
931
- __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
932
- return __privateGet$7(this, _namespaces).migrationRequests;
933
- }
934
- get tables() {
935
- if (!__privateGet$7(this, _namespaces).tables)
936
- __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
937
- return __privateGet$7(this, _namespaces).tables;
938
- }
939
- get records() {
940
- if (!__privateGet$7(this, _namespaces).records)
941
- __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
942
- return __privateGet$7(this, _namespaces).records;
943
- }
944
- get searchAndFilter() {
945
- if (!__privateGet$7(this, _namespaces).searchAndFilter)
946
- __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
947
- return __privateGet$7(this, _namespaces).searchAndFilter;
948
- }
949
- }
950
- _extraProps = new WeakMap();
951
- _namespaces = new WeakMap();
952
- class UserApi {
953
- constructor(extraProps) {
954
- this.extraProps = extraProps;
955
- }
956
- getUser() {
957
- return operationsByTag.users.getUser({ ...this.extraProps });
958
- }
959
- updateUser({ user }) {
960
- return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
961
- }
962
- deleteUser() {
963
- return operationsByTag.users.deleteUser({ ...this.extraProps });
964
- }
965
- }
966
- class AuthenticationApi {
967
- constructor(extraProps) {
968
- this.extraProps = extraProps;
969
- }
970
- getUserAPIKeys() {
971
- return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
972
- }
973
- createUserAPIKey({ name }) {
974
- return operationsByTag.authentication.createUserAPIKey({
975
- pathParams: { keyName: name },
976
- ...this.extraProps
977
- });
978
- }
979
- deleteUserAPIKey({ name }) {
980
- return operationsByTag.authentication.deleteUserAPIKey({
981
- pathParams: { keyName: name },
982
- ...this.extraProps
983
- });
984
- }
985
- }
986
- class WorkspaceApi {
987
- constructor(extraProps) {
988
- this.extraProps = extraProps;
989
- }
990
- getWorkspacesList() {
991
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
992
- }
993
- createWorkspace({ data }) {
994
- return operationsByTag.workspaces.createWorkspace({
995
- body: data,
996
- ...this.extraProps
997
- });
998
- }
999
- getWorkspace({ workspace }) {
1000
- return operationsByTag.workspaces.getWorkspace({
1001
- pathParams: { workspaceId: workspace },
1002
- ...this.extraProps
1003
- });
1004
- }
1005
- updateWorkspace({
1006
- workspace,
1007
- update
1008
- }) {
1009
- return operationsByTag.workspaces.updateWorkspace({
1010
- pathParams: { workspaceId: workspace },
1011
- body: update,
1012
- ...this.extraProps
1013
- });
1014
- }
1015
- deleteWorkspace({ workspace }) {
1016
- return operationsByTag.workspaces.deleteWorkspace({
1017
- pathParams: { workspaceId: workspace },
1018
- ...this.extraProps
1019
- });
1020
- }
1021
- getWorkspaceMembersList({ workspace }) {
1022
- return operationsByTag.workspaces.getWorkspaceMembersList({
1023
- pathParams: { workspaceId: workspace },
1024
- ...this.extraProps
1025
- });
1026
- }
1027
- updateWorkspaceMemberRole({
1028
- workspace,
1029
- user,
1030
- role
1031
- }) {
1032
- return operationsByTag.workspaces.updateWorkspaceMemberRole({
1033
- pathParams: { workspaceId: workspace, userId: user },
1034
- body: { role },
1035
- ...this.extraProps
1036
- });
1037
- }
1038
- removeWorkspaceMember({
1039
- workspace,
1040
- user
1041
- }) {
1042
- return operationsByTag.workspaces.removeWorkspaceMember({
1043
- pathParams: { workspaceId: workspace, userId: user },
1044
- ...this.extraProps
1045
- });
1046
- }
1047
- }
1048
- class InvitesApi {
1049
- constructor(extraProps) {
1050
- this.extraProps = extraProps;
1051
- }
1052
- inviteWorkspaceMember({
1053
- workspace,
1054
- email,
1055
- role
1056
- }) {
1057
- return operationsByTag.invites.inviteWorkspaceMember({
1058
- pathParams: { workspaceId: workspace },
1059
- body: { email, role },
1060
- ...this.extraProps
1061
- });
1062
- }
1063
- updateWorkspaceMemberInvite({
1064
- workspace,
1065
- invite,
1066
- role
1067
- }) {
1068
- return operationsByTag.invites.updateWorkspaceMemberInvite({
1069
- pathParams: { workspaceId: workspace, inviteId: invite },
1070
- body: { role },
1071
- ...this.extraProps
1072
- });
1073
- }
1074
- cancelWorkspaceMemberInvite({
1075
- workspace,
1076
- invite
1077
- }) {
1078
- return operationsByTag.invites.cancelWorkspaceMemberInvite({
1079
- pathParams: { workspaceId: workspace, inviteId: invite },
1080
- ...this.extraProps
1081
- });
1082
- }
1083
- acceptWorkspaceMemberInvite({
1084
- workspace,
1085
- key
1086
- }) {
1087
- return operationsByTag.invites.acceptWorkspaceMemberInvite({
1088
- pathParams: { workspaceId: workspace, inviteKey: key },
1089
- ...this.extraProps
1090
- });
1091
- }
1092
- resendWorkspaceMemberInvite({
1093
- workspace,
1094
- invite
1095
- }) {
1096
- return operationsByTag.invites.resendWorkspaceMemberInvite({
1097
- pathParams: { workspaceId: workspace, inviteId: invite },
1098
- ...this.extraProps
1099
- });
1100
- }
1101
- }
1102
- class BranchApi {
1103
- constructor(extraProps) {
1104
- this.extraProps = extraProps;
1105
- }
1106
- getBranchList({
1107
- workspace,
1108
- region,
1109
- database
1110
- }) {
1111
- return operationsByTag.branch.getBranchList({
1112
- pathParams: { workspace, region, dbName: database },
1113
- ...this.extraProps
1114
- });
1115
- }
1116
- getBranchDetails({
1117
- workspace,
1118
- region,
1119
- database,
1120
- branch
1121
- }) {
1122
- return operationsByTag.branch.getBranchDetails({
1123
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1124
- ...this.extraProps
1125
- });
1126
- }
1127
- createBranch({
1128
- workspace,
1129
- region,
1130
- database,
1131
- branch,
1132
- from,
1133
- metadata
1134
- }) {
1135
- return operationsByTag.branch.createBranch({
1136
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1137
- body: { from, metadata },
1138
- ...this.extraProps
1139
- });
1140
- }
1141
- deleteBranch({
1142
- workspace,
1143
- region,
1144
- database,
1145
- branch
1146
- }) {
1147
- return operationsByTag.branch.deleteBranch({
1148
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1149
- ...this.extraProps
1150
- });
1151
- }
1152
- updateBranchMetadata({
1153
- workspace,
1154
- region,
1155
- database,
1156
- branch,
1157
- metadata
1158
- }) {
1159
- return operationsByTag.branch.updateBranchMetadata({
1160
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1161
- body: metadata,
1162
- ...this.extraProps
1163
- });
1164
- }
1165
- getBranchMetadata({
1166
- workspace,
1167
- region,
1168
- database,
1169
- branch
1170
- }) {
1171
- return operationsByTag.branch.getBranchMetadata({
1172
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1173
- ...this.extraProps
1174
- });
1175
- }
1176
- getBranchStats({
1177
- workspace,
1178
- region,
1179
- database,
1180
- branch
1181
- }) {
1182
- return operationsByTag.branch.getBranchStats({
1183
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1184
- ...this.extraProps
1185
- });
1186
- }
1187
- getGitBranchesMapping({
1188
- workspace,
1189
- region,
1190
- database
1191
- }) {
1192
- return operationsByTag.branch.getGitBranchesMapping({
1193
- pathParams: { workspace, region, dbName: database },
1194
- ...this.extraProps
1195
- });
1196
- }
1197
- addGitBranchesEntry({
1198
- workspace,
1199
- region,
1200
- database,
1201
- gitBranch,
1202
- xataBranch
1203
- }) {
1204
- return operationsByTag.branch.addGitBranchesEntry({
1205
- pathParams: { workspace, region, dbName: database },
1206
- body: { gitBranch, xataBranch },
1207
- ...this.extraProps
1208
- });
1209
- }
1210
- removeGitBranchesEntry({
1211
- workspace,
1212
- region,
1213
- database,
1214
- gitBranch
1215
- }) {
1216
- return operationsByTag.branch.removeGitBranchesEntry({
1217
- pathParams: { workspace, region, dbName: database },
1218
- queryParams: { gitBranch },
1219
- ...this.extraProps
1220
- });
1221
- }
1222
- resolveBranch({
1223
- workspace,
1224
- region,
1225
- database,
1226
- gitBranch,
1227
- fallbackBranch
1228
- }) {
1229
- return operationsByTag.branch.resolveBranch({
1230
- pathParams: { workspace, region, dbName: database },
1231
- queryParams: { gitBranch, fallbackBranch },
1232
- ...this.extraProps
1233
- });
1234
- }
1362
+ };
1363
+ class XataApiClient extends buildApiClient() {
1235
1364
  }
1236
- class TableApi {
1237
- constructor(extraProps) {
1238
- this.extraProps = extraProps;
1239
- }
1240
- createTable({
1241
- workspace,
1242
- region,
1243
- database,
1244
- branch,
1245
- table
1246
- }) {
1247
- return operationsByTag.table.createTable({
1248
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1249
- ...this.extraProps
1250
- });
1251
- }
1252
- deleteTable({
1253
- workspace,
1254
- region,
1255
- database,
1256
- branch,
1257
- table
1258
- }) {
1259
- return operationsByTag.table.deleteTable({
1260
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1261
- ...this.extraProps
1262
- });
1263
- }
1264
- updateTable({
1265
- workspace,
1266
- region,
1267
- database,
1268
- branch,
1269
- table,
1270
- update
1271
- }) {
1272
- return operationsByTag.table.updateTable({
1273
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1274
- body: update,
1275
- ...this.extraProps
1276
- });
1277
- }
1278
- getTableSchema({
1279
- workspace,
1280
- region,
1281
- database,
1282
- branch,
1283
- table
1284
- }) {
1285
- return operationsByTag.table.getTableSchema({
1286
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1287
- ...this.extraProps
1288
- });
1289
- }
1290
- setTableSchema({
1291
- workspace,
1292
- region,
1293
- database,
1294
- branch,
1295
- table,
1296
- schema
1297
- }) {
1298
- return operationsByTag.table.setTableSchema({
1299
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1300
- body: schema,
1301
- ...this.extraProps
1302
- });
1303
- }
1304
- getTableColumns({
1305
- workspace,
1306
- region,
1307
- database,
1308
- branch,
1309
- table
1310
- }) {
1311
- return operationsByTag.table.getTableColumns({
1312
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1313
- ...this.extraProps
1314
- });
1315
- }
1316
- addTableColumn({
1317
- workspace,
1318
- region,
1319
- database,
1320
- branch,
1321
- table,
1322
- column
1323
- }) {
1324
- return operationsByTag.table.addTableColumn({
1325
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1326
- body: column,
1327
- ...this.extraProps
1328
- });
1329
- }
1330
- getColumn({
1331
- workspace,
1332
- region,
1333
- database,
1334
- branch,
1335
- table,
1336
- column
1337
- }) {
1338
- return operationsByTag.table.getColumn({
1339
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1340
- ...this.extraProps
1341
- });
1342
- }
1343
- updateColumn({
1344
- workspace,
1345
- region,
1346
- database,
1347
- branch,
1348
- table,
1349
- column,
1350
- update
1351
- }) {
1352
- return operationsByTag.table.updateColumn({
1353
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1354
- body: update,
1355
- ...this.extraProps
1356
- });
1357
- }
1358
- deleteColumn({
1359
- workspace,
1360
- region,
1361
- database,
1362
- branch,
1363
- table,
1364
- column
1365
- }) {
1366
- return operationsByTag.table.deleteColumn({
1367
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1368
- ...this.extraProps
1369
- });
1365
+
1366
+ class XataApiPlugin {
1367
+ build(options) {
1368
+ return new XataApiClient(options);
1370
1369
  }
1371
1370
  }
1372
- class RecordsApi {
1373
- constructor(extraProps) {
1374
- this.extraProps = extraProps;
1375
- }
1376
- insertRecord({
1377
- workspace,
1378
- region,
1379
- database,
1380
- branch,
1381
- table,
1382
- record,
1383
- columns
1384
- }) {
1385
- return operationsByTag.records.insertRecord({
1386
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1387
- queryParams: { columns },
1388
- body: record,
1389
- ...this.extraProps
1390
- });
1391
- }
1392
- getRecord({
1393
- workspace,
1394
- region,
1395
- database,
1396
- branch,
1397
- table,
1398
- id,
1399
- columns
1400
- }) {
1401
- return operationsByTag.records.getRecord({
1402
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1403
- queryParams: { columns },
1404
- ...this.extraProps
1405
- });
1406
- }
1407
- insertRecordWithID({
1408
- workspace,
1409
- region,
1410
- database,
1411
- branch,
1412
- table,
1413
- id,
1414
- record,
1415
- columns,
1416
- createOnly,
1417
- ifVersion
1418
- }) {
1419
- return operationsByTag.records.insertRecordWithID({
1420
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1421
- queryParams: { columns, createOnly, ifVersion },
1422
- body: record,
1423
- ...this.extraProps
1424
- });
1425
- }
1426
- updateRecordWithID({
1427
- workspace,
1428
- region,
1429
- database,
1430
- branch,
1431
- table,
1432
- id,
1433
- record,
1434
- columns,
1435
- ifVersion
1436
- }) {
1437
- return operationsByTag.records.updateRecordWithID({
1438
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1439
- queryParams: { columns, ifVersion },
1440
- body: record,
1441
- ...this.extraProps
1442
- });
1443
- }
1444
- upsertRecordWithID({
1445
- workspace,
1446
- region,
1447
- database,
1448
- branch,
1449
- table,
1450
- id,
1451
- record,
1452
- columns,
1453
- ifVersion
1454
- }) {
1455
- return operationsByTag.records.upsertRecordWithID({
1456
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1457
- queryParams: { columns, ifVersion },
1458
- body: record,
1459
- ...this.extraProps
1460
- });
1461
- }
1462
- deleteRecord({
1463
- workspace,
1464
- region,
1465
- database,
1466
- branch,
1467
- table,
1468
- id,
1469
- columns
1470
- }) {
1471
- return operationsByTag.records.deleteRecord({
1472
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1473
- queryParams: { columns },
1474
- ...this.extraProps
1475
- });
1476
- }
1477
- bulkInsertTableRecords({
1478
- workspace,
1479
- region,
1480
- database,
1481
- branch,
1482
- table,
1483
- records,
1484
- columns
1485
- }) {
1486
- return operationsByTag.records.bulkInsertTableRecords({
1487
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1488
- queryParams: { columns },
1489
- body: { records },
1490
- ...this.extraProps
1491
- });
1492
- }
1493
- branchTransaction({
1494
- workspace,
1495
- region,
1496
- database,
1497
- branch,
1498
- operations
1499
- }) {
1500
- return operationsByTag.records.branchTransaction({
1501
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1502
- body: { operations },
1503
- ...this.extraProps
1504
- });
1505
- }
1371
+
1372
+ class XataPlugin {
1506
1373
  }
1507
- class SearchAndFilterApi {
1508
- constructor(extraProps) {
1509
- this.extraProps = extraProps;
1510
- }
1511
- queryTable({
1512
- workspace,
1513
- region,
1514
- database,
1515
- branch,
1516
- table,
1517
- filter,
1518
- sort,
1519
- page,
1520
- columns,
1521
- consistency
1522
- }) {
1523
- return operationsByTag.searchAndFilter.queryTable({
1524
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1525
- body: { filter, sort, page, columns, consistency },
1526
- ...this.extraProps
1527
- });
1528
- }
1529
- searchTable({
1530
- workspace,
1531
- region,
1532
- database,
1533
- branch,
1534
- table,
1535
- query,
1536
- fuzziness,
1537
- target,
1538
- prefix,
1539
- filter,
1540
- highlight,
1541
- boosters
1542
- }) {
1543
- return operationsByTag.searchAndFilter.searchTable({
1544
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1545
- body: { query, fuzziness, target, prefix, filter, highlight, boosters },
1546
- ...this.extraProps
1547
- });
1548
- }
1549
- searchBranch({
1550
- workspace,
1551
- region,
1552
- database,
1553
- branch,
1554
- tables,
1555
- query,
1556
- fuzziness,
1557
- prefix,
1558
- highlight
1559
- }) {
1560
- return operationsByTag.searchAndFilter.searchBranch({
1561
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1562
- body: { tables, query, fuzziness, prefix, highlight },
1563
- ...this.extraProps
1564
- });
1565
- }
1566
- summarizeTable({
1567
- workspace,
1568
- region,
1569
- database,
1570
- branch,
1571
- table,
1572
- filter,
1573
- columns,
1574
- summaries,
1575
- sort,
1576
- summariesFilter,
1577
- page,
1578
- consistency
1579
- }) {
1580
- return operationsByTag.searchAndFilter.summarizeTable({
1581
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1582
- body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1583
- ...this.extraProps
1584
- });
1585
- }
1586
- aggregateTable({
1587
- workspace,
1588
- region,
1589
- database,
1590
- branch,
1591
- table,
1592
- filter,
1593
- aggs
1594
- }) {
1595
- return operationsByTag.searchAndFilter.aggregateTable({
1596
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1597
- body: { filter, aggs },
1598
- ...this.extraProps
1599
- });
1600
- }
1374
+
1375
+ function buildTransformString(transformations) {
1376
+ return transformations.flatMap(
1377
+ (t) => Object.entries(t).map(([key, value]) => {
1378
+ if (key === "trim") {
1379
+ const { left = 0, top = 0, right = 0, bottom = 0 } = value;
1380
+ return `${key}=${[top, right, bottom, left].join(";")}`;
1381
+ }
1382
+ if (key === "gravity" && typeof value === "object") {
1383
+ const { x = 0.5, y = 0.5 } = value;
1384
+ return `${key}=${[x, y].join("x")}`;
1385
+ }
1386
+ return `${key}=${value}`;
1387
+ })
1388
+ ).join(",");
1601
1389
  }
1602
- class MigrationRequestsApi {
1603
- constructor(extraProps) {
1604
- this.extraProps = extraProps;
1605
- }
1606
- queryMigrationRequests({
1607
- workspace,
1608
- region,
1609
- database,
1610
- filter,
1611
- sort,
1612
- page,
1613
- columns
1614
- }) {
1615
- return operationsByTag.migrationRequests.queryMigrationRequests({
1616
- pathParams: { workspace, region, dbName: database },
1617
- body: { filter, sort, page, columns },
1618
- ...this.extraProps
1619
- });
1620
- }
1621
- createMigrationRequest({
1622
- workspace,
1623
- region,
1624
- database,
1625
- migration
1626
- }) {
1627
- return operationsByTag.migrationRequests.createMigrationRequest({
1628
- pathParams: { workspace, region, dbName: database },
1629
- body: migration,
1630
- ...this.extraProps
1631
- });
1632
- }
1633
- getMigrationRequest({
1634
- workspace,
1635
- region,
1636
- database,
1637
- migrationRequest
1638
- }) {
1639
- return operationsByTag.migrationRequests.getMigrationRequest({
1640
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1641
- ...this.extraProps
1642
- });
1643
- }
1644
- updateMigrationRequest({
1645
- workspace,
1646
- region,
1647
- database,
1648
- migrationRequest,
1649
- update
1650
- }) {
1651
- return operationsByTag.migrationRequests.updateMigrationRequest({
1652
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1653
- body: update,
1654
- ...this.extraProps
1655
- });
1656
- }
1657
- listMigrationRequestsCommits({
1658
- workspace,
1659
- region,
1660
- database,
1661
- migrationRequest,
1662
- page
1663
- }) {
1664
- return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1665
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1666
- body: { page },
1667
- ...this.extraProps
1668
- });
1669
- }
1670
- compareMigrationRequest({
1671
- workspace,
1672
- region,
1673
- database,
1674
- migrationRequest
1675
- }) {
1676
- return operationsByTag.migrationRequests.compareMigrationRequest({
1677
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1678
- ...this.extraProps
1679
- });
1680
- }
1681
- getMigrationRequestIsMerged({
1682
- workspace,
1683
- region,
1684
- database,
1685
- migrationRequest
1686
- }) {
1687
- return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1688
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1689
- ...this.extraProps
1690
- });
1691
- }
1692
- mergeMigrationRequest({
1693
- workspace,
1694
- region,
1695
- database,
1696
- migrationRequest
1697
- }) {
1698
- return operationsByTag.migrationRequests.mergeMigrationRequest({
1699
- pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1700
- ...this.extraProps
1701
- });
1702
- }
1390
+ function transformImage(url, ...transformations) {
1391
+ if (!isDefined(url))
1392
+ return void 0;
1393
+ const newTransformations = buildTransformString(transformations);
1394
+ const { hostname, pathname, search } = new URL(url);
1395
+ const pathParts = pathname.split("/");
1396
+ const transformIndex = pathParts.findIndex((part) => part === "transform");
1397
+ const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
1398
+ const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
1399
+ const path = pathParts.join("/");
1400
+ return `https://${hostname}${transform}${path}${search}`;
1703
1401
  }
1704
- class MigrationsApi {
1705
- constructor(extraProps) {
1706
- this.extraProps = extraProps;
1707
- }
1708
- getBranchMigrationHistory({
1709
- workspace,
1710
- region,
1711
- database,
1712
- branch,
1713
- limit,
1714
- startFrom
1715
- }) {
1716
- return operationsByTag.migrations.getBranchMigrationHistory({
1717
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1718
- body: { limit, startFrom },
1719
- ...this.extraProps
1720
- });
1721
- }
1722
- getBranchMigrationPlan({
1723
- workspace,
1724
- region,
1725
- database,
1726
- branch,
1727
- schema
1728
- }) {
1729
- return operationsByTag.migrations.getBranchMigrationPlan({
1730
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1731
- body: schema,
1732
- ...this.extraProps
1733
- });
1734
- }
1735
- executeBranchMigrationPlan({
1736
- workspace,
1737
- region,
1738
- database,
1739
- branch,
1740
- plan
1741
- }) {
1742
- return operationsByTag.migrations.executeBranchMigrationPlan({
1743
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1744
- body: plan,
1745
- ...this.extraProps
1746
- });
1747
- }
1748
- getBranchSchemaHistory({
1749
- workspace,
1750
- region,
1751
- database,
1752
- branch,
1753
- page
1754
- }) {
1755
- return operationsByTag.migrations.getBranchSchemaHistory({
1756
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1757
- body: { page },
1758
- ...this.extraProps
1759
- });
1760
- }
1761
- compareBranchWithUserSchema({
1762
- workspace,
1763
- region,
1764
- database,
1765
- branch,
1766
- schema
1767
- }) {
1768
- return operationsByTag.migrations.compareBranchWithUserSchema({
1769
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1770
- body: { schema },
1771
- ...this.extraProps
1772
- });
1773
- }
1774
- compareBranchSchemas({
1775
- workspace,
1776
- region,
1777
- database,
1778
- branch,
1779
- compare,
1780
- schema
1781
- }) {
1782
- return operationsByTag.migrations.compareBranchSchemas({
1783
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1784
- body: { schema },
1785
- ...this.extraProps
1786
- });
1402
+
1403
+ class XataFile {
1404
+ constructor(file) {
1405
+ this.id = file.id;
1406
+ this.name = file.name;
1407
+ this.mediaType = file.mediaType;
1408
+ this.base64Content = file.base64Content;
1409
+ this.enablePublicUrl = file.enablePublicUrl;
1410
+ this.signedUrlTimeout = file.signedUrlTimeout;
1411
+ this.size = file.size;
1412
+ this.version = file.version;
1413
+ this.url = file.url;
1414
+ this.signedUrl = file.signedUrl;
1415
+ this.attributes = file.attributes;
1416
+ }
1417
+ static fromBuffer(buffer, options = {}) {
1418
+ const base64Content = buffer.toString("base64");
1419
+ return new XataFile({ ...options, base64Content });
1420
+ }
1421
+ toBuffer() {
1422
+ if (!this.base64Content) {
1423
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1424
+ }
1425
+ return Buffer.from(this.base64Content, "base64");
1787
1426
  }
1788
- updateBranchSchema({
1789
- workspace,
1790
- region,
1791
- database,
1792
- branch,
1793
- migration
1794
- }) {
1795
- return operationsByTag.migrations.updateBranchSchema({
1796
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1797
- body: migration,
1798
- ...this.extraProps
1799
- });
1427
+ static fromArrayBuffer(arrayBuffer, options = {}) {
1428
+ const uint8Array = new Uint8Array(arrayBuffer);
1429
+ return this.fromUint8Array(uint8Array, options);
1800
1430
  }
1801
- previewBranchSchemaEdit({
1802
- workspace,
1803
- region,
1804
- database,
1805
- branch,
1806
- data
1807
- }) {
1808
- return operationsByTag.migrations.previewBranchSchemaEdit({
1809
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1810
- body: data,
1811
- ...this.extraProps
1812
- });
1431
+ toArrayBuffer() {
1432
+ if (!this.base64Content) {
1433
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1434
+ }
1435
+ const binary = atob(this.base64Content);
1436
+ return new ArrayBuffer(binary.length);
1813
1437
  }
1814
- applyBranchSchemaEdit({
1815
- workspace,
1816
- region,
1817
- database,
1818
- branch,
1819
- edits
1820
- }) {
1821
- return operationsByTag.migrations.applyBranchSchemaEdit({
1822
- pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1823
- body: { edits },
1824
- ...this.extraProps
1825
- });
1438
+ static fromUint8Array(uint8Array, options = {}) {
1439
+ let binary = "";
1440
+ for (let i = 0; i < uint8Array.byteLength; i++) {
1441
+ binary += String.fromCharCode(uint8Array[i]);
1442
+ }
1443
+ const base64Content = btoa(binary);
1444
+ return new XataFile({ ...options, base64Content });
1826
1445
  }
1827
- }
1828
- class DatabaseApi {
1829
- constructor(extraProps) {
1830
- this.extraProps = extraProps;
1446
+ toUint8Array() {
1447
+ if (!this.base64Content) {
1448
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1449
+ }
1450
+ const binary = atob(this.base64Content);
1451
+ const uint8Array = new Uint8Array(binary.length);
1452
+ for (let i = 0; i < binary.length; i++) {
1453
+ uint8Array[i] = binary.charCodeAt(i);
1454
+ }
1455
+ return uint8Array;
1831
1456
  }
1832
- getDatabaseList({ workspace }) {
1833
- return operationsByTag.databases.getDatabaseList({
1834
- pathParams: { workspaceId: workspace },
1835
- ...this.extraProps
1836
- });
1457
+ static async fromBlob(file, options = {}) {
1458
+ const name = options.name ?? file.name;
1459
+ const mediaType = file.type;
1460
+ const arrayBuffer = await file.arrayBuffer();
1461
+ return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
1837
1462
  }
1838
- createDatabase({
1839
- workspace,
1840
- database,
1841
- data
1842
- }) {
1843
- return operationsByTag.databases.createDatabase({
1844
- pathParams: { workspaceId: workspace, dbName: database },
1845
- body: data,
1846
- ...this.extraProps
1847
- });
1463
+ toBlob() {
1464
+ if (!this.base64Content) {
1465
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1466
+ }
1467
+ const binary = atob(this.base64Content);
1468
+ const uint8Array = new Uint8Array(binary.length);
1469
+ for (let i = 0; i < binary.length; i++) {
1470
+ uint8Array[i] = binary.charCodeAt(i);
1471
+ }
1472
+ return new Blob([uint8Array], { type: this.mediaType });
1848
1473
  }
1849
- deleteDatabase({
1850
- workspace,
1851
- database
1852
- }) {
1853
- return operationsByTag.databases.deleteDatabase({
1854
- pathParams: { workspaceId: workspace, dbName: database },
1855
- ...this.extraProps
1856
- });
1474
+ static fromString(string, options = {}) {
1475
+ const base64Content = btoa(string);
1476
+ return new XataFile({ ...options, base64Content });
1857
1477
  }
1858
- getDatabaseMetadata({
1859
- workspace,
1860
- database
1861
- }) {
1862
- return operationsByTag.databases.getDatabaseMetadata({
1863
- pathParams: { workspaceId: workspace, dbName: database },
1864
- ...this.extraProps
1865
- });
1478
+ toString() {
1479
+ if (!this.base64Content) {
1480
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1481
+ }
1482
+ return atob(this.base64Content);
1866
1483
  }
1867
- updateDatabaseMetadata({
1868
- workspace,
1869
- database,
1870
- metadata
1871
- }) {
1872
- return operationsByTag.databases.updateDatabaseMetadata({
1873
- pathParams: { workspaceId: workspace, dbName: database },
1874
- body: metadata,
1875
- ...this.extraProps
1876
- });
1484
+ static fromBase64(base64Content, options = {}) {
1485
+ return new XataFile({ ...options, base64Content });
1877
1486
  }
1878
- listRegions({ workspace }) {
1879
- return operationsByTag.databases.listRegions({
1880
- pathParams: { workspaceId: workspace },
1881
- ...this.extraProps
1882
- });
1487
+ toBase64() {
1488
+ if (!this.base64Content) {
1489
+ throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
1490
+ }
1491
+ return this.base64Content;
1883
1492
  }
1884
- }
1885
-
1886
- class XataApiPlugin {
1887
- async build(options) {
1888
- const { fetchImpl, apiKey } = await options.getFetchProps();
1889
- return new XataApiClient({ fetch: fetchImpl, apiKey });
1493
+ transform(...options) {
1494
+ return {
1495
+ url: transformImage(this.url, ...options),
1496
+ signedUrl: transformImage(this.signedUrl, ...options),
1497
+ metadataUrl: transformImage(this.url, ...options, { format: "json" }),
1498
+ metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
1499
+ };
1890
1500
  }
1891
1501
  }
1892
-
1893
- class XataPlugin {
1894
- }
1502
+ const parseInputFileEntry = async (entry) => {
1503
+ if (!isDefined(entry))
1504
+ return null;
1505
+ const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
1506
+ return compactObject({
1507
+ id,
1508
+ // Name cannot be an empty string in our API
1509
+ name: name ? name : void 0,
1510
+ mediaType,
1511
+ base64Content,
1512
+ enablePublicUrl,
1513
+ signedUrlTimeout
1514
+ });
1515
+ };
1895
1516
 
1896
1517
  function cleanFilter(filter) {
1897
- if (!filter)
1518
+ if (!isDefined(filter))
1898
1519
  return void 0;
1899
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1900
- return values.length > 0 ? filter : void 0;
1520
+ if (!isObject(filter))
1521
+ return filter;
1522
+ const values = Object.fromEntries(
1523
+ Object.entries(filter).reduce((acc, [key, value]) => {
1524
+ if (!isDefined(value))
1525
+ return acc;
1526
+ if (Array.isArray(value)) {
1527
+ const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
1528
+ if (clean.length === 0)
1529
+ return acc;
1530
+ return [...acc, [key, clean]];
1531
+ }
1532
+ if (isObject(value)) {
1533
+ const clean = cleanFilter(value);
1534
+ if (!isDefined(clean))
1535
+ return acc;
1536
+ return [...acc, [key, clean]];
1537
+ }
1538
+ return [...acc, [key, value]];
1539
+ }, [])
1540
+ );
1541
+ return Object.keys(values).length > 0 ? values : void 0;
1542
+ }
1543
+
1544
+ function stringifyJson(value) {
1545
+ if (!isDefined(value))
1546
+ return value;
1547
+ if (isString(value))
1548
+ return value;
1549
+ try {
1550
+ return JSON.stringify(value);
1551
+ } catch (e) {
1552
+ return value;
1553
+ }
1554
+ }
1555
+ function parseJson(value) {
1556
+ try {
1557
+ return JSON.parse(value);
1558
+ } catch (e) {
1559
+ return value;
1560
+ }
1901
1561
  }
1902
1562
 
1903
1563
  var __accessCheck$6 = (obj, member, msg) => {
@@ -1926,31 +1586,59 @@ class Page {
1926
1586
  this.meta = meta;
1927
1587
  this.records = new RecordArray(this, records);
1928
1588
  }
1589
+ /**
1590
+ * Retrieves the next page of results.
1591
+ * @param size Maximum number of results to be retrieved.
1592
+ * @param offset Number of results to skip when retrieving the results.
1593
+ * @returns The next page or results.
1594
+ */
1929
1595
  async nextPage(size, offset) {
1930
1596
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
1931
1597
  }
1598
+ /**
1599
+ * Retrieves the previous page of results.
1600
+ * @param size Maximum number of results to be retrieved.
1601
+ * @param offset Number of results to skip when retrieving the results.
1602
+ * @returns The previous page or results.
1603
+ */
1932
1604
  async previousPage(size, offset) {
1933
1605
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1934
1606
  }
1607
+ /**
1608
+ * Retrieves the start page of results.
1609
+ * @param size Maximum number of results to be retrieved.
1610
+ * @param offset Number of results to skip when retrieving the results.
1611
+ * @returns The start page or results.
1612
+ */
1935
1613
  async startPage(size, offset) {
1936
1614
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1937
1615
  }
1616
+ /**
1617
+ * Retrieves the end page of results.
1618
+ * @param size Maximum number of results to be retrieved.
1619
+ * @param offset Number of results to skip when retrieving the results.
1620
+ * @returns The end page or results.
1621
+ */
1938
1622
  async endPage(size, offset) {
1939
1623
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1940
1624
  }
1625
+ /**
1626
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
1627
+ * @returns Whether or not there will be additional results in the next page of results.
1628
+ */
1941
1629
  hasNextPage() {
1942
1630
  return this.meta.page.more;
1943
1631
  }
1944
1632
  }
1945
1633
  _query = new WeakMap();
1946
- const PAGINATION_MAX_SIZE = 200;
1634
+ const PAGINATION_MAX_SIZE = 1e3;
1947
1635
  const PAGINATION_DEFAULT_SIZE = 20;
1948
- const PAGINATION_MAX_OFFSET = 800;
1636
+ const PAGINATION_MAX_OFFSET = 49e3;
1949
1637
  const PAGINATION_DEFAULT_OFFSET = 0;
1950
1638
  function isCursorPaginationOptions(options) {
1951
1639
  return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1952
1640
  }
1953
- const _RecordArray = class extends Array {
1641
+ const _RecordArray = class _RecordArray extends Array {
1954
1642
  constructor(...args) {
1955
1643
  super(..._RecordArray.parseConstructorParams(...args));
1956
1644
  __privateAdd$6(this, _page, void 0);
@@ -1969,31 +1657,60 @@ const _RecordArray = class extends Array {
1969
1657
  toArray() {
1970
1658
  return new Array(...this);
1971
1659
  }
1660
+ toSerializable() {
1661
+ return JSON.parse(this.toString());
1662
+ }
1663
+ toString() {
1664
+ return JSON.stringify(this.toArray());
1665
+ }
1972
1666
  map(callbackfn, thisArg) {
1973
1667
  return this.toArray().map(callbackfn, thisArg);
1974
1668
  }
1669
+ /**
1670
+ * Retrieve next page of records
1671
+ *
1672
+ * @returns A new array of objects
1673
+ */
1975
1674
  async nextPage(size, offset) {
1976
1675
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1977
1676
  return new _RecordArray(newPage);
1978
1677
  }
1678
+ /**
1679
+ * Retrieve previous page of records
1680
+ *
1681
+ * @returns A new array of objects
1682
+ */
1979
1683
  async previousPage(size, offset) {
1980
1684
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1981
1685
  return new _RecordArray(newPage);
1982
1686
  }
1687
+ /**
1688
+ * Retrieve start page of records
1689
+ *
1690
+ * @returns A new array of objects
1691
+ */
1983
1692
  async startPage(size, offset) {
1984
1693
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1985
1694
  return new _RecordArray(newPage);
1986
1695
  }
1696
+ /**
1697
+ * Retrieve end page of records
1698
+ *
1699
+ * @returns A new array of objects
1700
+ */
1987
1701
  async endPage(size, offset) {
1988
1702
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1989
1703
  return new _RecordArray(newPage);
1990
1704
  }
1705
+ /**
1706
+ * @returns Boolean indicating if there is a next page
1707
+ */
1991
1708
  hasNextPage() {
1992
1709
  return __privateGet$6(this, _page).meta.page.more;
1993
1710
  }
1994
1711
  };
1995
- let RecordArray = _RecordArray;
1996
1712
  _page = new WeakMap();
1713
+ let RecordArray = _RecordArray;
1997
1714
 
1998
1715
  var __accessCheck$5 = (obj, member, msg) => {
1999
1716
  if (!member.has(obj))
@@ -2018,13 +1735,14 @@ var __privateMethod$3 = (obj, member, method) => {
2018
1735
  return method;
2019
1736
  };
2020
1737
  var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
2021
- const _Query = class {
1738
+ const _Query = class _Query {
2022
1739
  constructor(repository, table, data, rawParent) {
2023
1740
  __privateAdd$5(this, _cleanFilterConstraint);
2024
1741
  __privateAdd$5(this, _table$1, void 0);
2025
1742
  __privateAdd$5(this, _repository, void 0);
2026
1743
  __privateAdd$5(this, _data, { filter: {} });
2027
- this.meta = { page: { cursor: "start", more: true } };
1744
+ // Implements pagination
1745
+ this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
2028
1746
  this.records = new RecordArray(this, []);
2029
1747
  __privateSet$5(this, _table$1, table);
2030
1748
  if (repository) {
@@ -2061,18 +1779,38 @@ const _Query = class {
2061
1779
  const key = JSON.stringify({ columns, filter, sort, pagination });
2062
1780
  return toBase64(key);
2063
1781
  }
1782
+ /**
1783
+ * Builds a new query object representing a logical OR between the given subqueries.
1784
+ * @param queries An array of subqueries.
1785
+ * @returns A new Query object.
1786
+ */
2064
1787
  any(...queries) {
2065
1788
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2066
1789
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2067
1790
  }
1791
+ /**
1792
+ * Builds a new query object representing a logical AND between the given subqueries.
1793
+ * @param queries An array of subqueries.
1794
+ * @returns A new Query object.
1795
+ */
2068
1796
  all(...queries) {
2069
1797
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2070
1798
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2071
1799
  }
1800
+ /**
1801
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
1802
+ * @param queries An array of subqueries.
1803
+ * @returns A new Query object.
1804
+ */
2072
1805
  not(...queries) {
2073
1806
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2074
1807
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2075
1808
  }
1809
+ /**
1810
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
1811
+ * @param queries An array of subqueries.
1812
+ * @returns A new Query object.
1813
+ */
2076
1814
  none(...queries) {
2077
1815
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2078
1816
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2095,6 +1833,11 @@ const _Query = class {
2095
1833
  const sort = [...originalSort, { column, direction }];
2096
1834
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2097
1835
  }
1836
+ /**
1837
+ * Builds a new query specifying the set of columns to be returned in the query response.
1838
+ * @param columns Array of column names to be returned by the query.
1839
+ * @returns A new Query object.
1840
+ */
2098
1841
  select(columns) {
2099
1842
  return new _Query(
2100
1843
  __privateGet$5(this, _repository),
@@ -2107,6 +1850,12 @@ const _Query = class {
2107
1850
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2108
1851
  return __privateGet$5(this, _repository).query(query);
2109
1852
  }
1853
+ /**
1854
+ * Get results in an iterator
1855
+ *
1856
+ * @async
1857
+ * @returns Async interable of results
1858
+ */
2110
1859
  async *[Symbol.asyncIterator]() {
2111
1860
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2112
1861
  yield record;
@@ -2167,26 +1916,53 @@ const _Query = class {
2167
1916
  );
2168
1917
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2169
1918
  }
1919
+ /**
1920
+ * Builds a new query object adding a cache TTL in milliseconds.
1921
+ * @param ttl The cache TTL in milliseconds.
1922
+ * @returns A new Query object.
1923
+ */
2170
1924
  cache(ttl) {
2171
1925
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2172
1926
  }
1927
+ /**
1928
+ * Retrieve next page of records
1929
+ *
1930
+ * @returns A new page object.
1931
+ */
2173
1932
  nextPage(size, offset) {
2174
1933
  return this.startPage(size, offset);
2175
1934
  }
1935
+ /**
1936
+ * Retrieve previous page of records
1937
+ *
1938
+ * @returns A new page object
1939
+ */
2176
1940
  previousPage(size, offset) {
2177
1941
  return this.startPage(size, offset);
2178
1942
  }
1943
+ /**
1944
+ * Retrieve start page of records
1945
+ *
1946
+ * @returns A new page object
1947
+ */
2179
1948
  startPage(size, offset) {
2180
1949
  return this.getPaginated({ pagination: { size, offset } });
2181
1950
  }
1951
+ /**
1952
+ * Retrieve last page of records
1953
+ *
1954
+ * @returns A new page object
1955
+ */
2182
1956
  endPage(size, offset) {
2183
1957
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2184
1958
  }
1959
+ /**
1960
+ * @returns Boolean indicating if there is a next page
1961
+ */
2185
1962
  hasNextPage() {
2186
1963
  return this.meta.page.more;
2187
1964
  }
2188
1965
  };
2189
- let Query = _Query;
2190
1966
  _table$1 = new WeakMap();
2191
1967
  _repository = new WeakMap();
2192
1968
  _data = new WeakMap();
@@ -2201,6 +1977,7 @@ cleanFilterConstraint_fn = function(column, value) {
2201
1977
  }
2202
1978
  return value;
2203
1979
  };
1980
+ let Query = _Query;
2204
1981
  function cleanParent(data, parent) {
2205
1982
  if (isCursorPaginationOptions(data.pagination)) {
2206
1983
  return { ...parent, sort: void 0, filter: void 0 };
@@ -2208,6 +1985,22 @@ function cleanParent(data, parent) {
2208
1985
  return parent;
2209
1986
  }
2210
1987
 
1988
+ const RecordColumnTypes = [
1989
+ "bool",
1990
+ "int",
1991
+ "float",
1992
+ "string",
1993
+ "text",
1994
+ "email",
1995
+ "multiple",
1996
+ "link",
1997
+ "object",
1998
+ "datetime",
1999
+ "vector",
2000
+ "file[]",
2001
+ "file",
2002
+ "json"
2003
+ ];
2211
2004
  function isIdentifiable(x) {
2212
2005
  return isObject(x) && isString(x?.id);
2213
2006
  }
@@ -2217,11 +2010,33 @@ function isXataRecord(x) {
2217
2010
  return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
2218
2011
  }
2219
2012
 
2013
+ function isValidExpandedColumn(column) {
2014
+ return isObject(column) && isString(column.name);
2015
+ }
2016
+ function isValidSelectableColumns(columns) {
2017
+ if (!Array.isArray(columns)) {
2018
+ return false;
2019
+ }
2020
+ return columns.every((column) => {
2021
+ if (typeof column === "string") {
2022
+ return true;
2023
+ }
2024
+ if (typeof column === "object") {
2025
+ return isValidExpandedColumn(column);
2026
+ }
2027
+ return false;
2028
+ });
2029
+ }
2030
+
2220
2031
  function isSortFilterString(value) {
2221
2032
  return isString(value);
2222
2033
  }
2223
2034
  function isSortFilterBase(filter) {
2224
- return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
2035
+ return isObject(filter) && Object.entries(filter).every(([key, value]) => {
2036
+ if (key === "*")
2037
+ return value === "random";
2038
+ return value === "asc" || value === "desc";
2039
+ });
2225
2040
  }
2226
2041
  function isSortFilterObject(filter) {
2227
2042
  return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
@@ -2262,7 +2077,7 @@ var __privateMethod$2 = (obj, member, method) => {
2262
2077
  __accessCheck$4(obj, member, "access private method");
2263
2078
  return method;
2264
2079
  };
2265
- 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;
2080
+ 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;
2266
2081
  const BULK_OPERATION_MAX_SIZE = 1e3;
2267
2082
  class Repository extends Query {
2268
2083
  }
@@ -2284,6 +2099,7 @@ class RestRepository extends Query {
2284
2099
  __privateAdd$4(this, _setCacheQuery);
2285
2100
  __privateAdd$4(this, _getCacheQuery);
2286
2101
  __privateAdd$4(this, _getSchemaTables$1);
2102
+ __privateAdd$4(this, _transformObjectToApi);
2287
2103
  __privateAdd$4(this, _table, void 0);
2288
2104
  __privateAdd$4(this, _getFetchProps, void 0);
2289
2105
  __privateAdd$4(this, _db, void 0);
@@ -2294,10 +2110,7 @@ class RestRepository extends Query {
2294
2110
  __privateSet$4(this, _db, options.db);
2295
2111
  __privateSet$4(this, _cache, options.pluginOptions.cache);
2296
2112
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2297
- __privateSet$4(this, _getFetchProps, async () => {
2298
- const props = await options.pluginOptions.getFetchProps();
2299
- return { ...props, sessionID: generateUUID() };
2300
- });
2113
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
2301
2114
  const trace = options.pluginOptions.trace ?? defaultTrace;
2302
2115
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2303
2116
  return trace(name, fn, {
@@ -2315,24 +2128,24 @@ class RestRepository extends Query {
2315
2128
  if (a.length === 0)
2316
2129
  return [];
2317
2130
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2318
- const columns = isStringArray(b) ? b : ["*"];
2131
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2319
2132
  const result = await this.read(ids, columns);
2320
2133
  return result;
2321
2134
  }
2322
2135
  if (isString(a) && isObject(b)) {
2323
2136
  if (a === "")
2324
2137
  throw new Error("The id can't be empty");
2325
- const columns = isStringArray(c) ? c : void 0;
2138
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2326
2139
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2327
2140
  }
2328
2141
  if (isObject(a) && isString(a.id)) {
2329
2142
  if (a.id === "")
2330
2143
  throw new Error("The id can't be empty");
2331
- const columns = isStringArray(b) ? b : void 0;
2144
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2332
2145
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2333
2146
  }
2334
2147
  if (isObject(a)) {
2335
- const columns = isStringArray(b) ? b : void 0;
2148
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2336
2149
  return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2337
2150
  }
2338
2151
  throw new Error("Invalid arguments for create method");
@@ -2340,7 +2153,7 @@ class RestRepository extends Query {
2340
2153
  }
2341
2154
  async read(a, b) {
2342
2155
  return __privateGet$4(this, _trace).call(this, "read", async () => {
2343
- const columns = isStringArray(b) ? b : ["*"];
2156
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2344
2157
  if (Array.isArray(a)) {
2345
2158
  if (a.length === 0)
2346
2159
  return [];
@@ -2354,7 +2167,6 @@ class RestRepository extends Query {
2354
2167
  }
2355
2168
  const id = extractId(a);
2356
2169
  if (id) {
2357
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2358
2170
  try {
2359
2171
  const response = await getRecord({
2360
2172
  pathParams: {
@@ -2365,10 +2177,16 @@ class RestRepository extends Query {
2365
2177
  recordId: id
2366
2178
  },
2367
2179
  queryParams: { columns },
2368
- ...fetchProps
2180
+ ...__privateGet$4(this, _getFetchProps).call(this)
2369
2181
  });
2370
2182
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2371
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2183
+ return initObject(
2184
+ __privateGet$4(this, _db),
2185
+ schemaTables,
2186
+ __privateGet$4(this, _table),
2187
+ response,
2188
+ columns
2189
+ );
2372
2190
  } catch (e) {
2373
2191
  if (isObject(e) && e.status === 404) {
2374
2192
  return null;
@@ -2410,17 +2228,17 @@ class RestRepository extends Query {
2410
2228
  ifVersion,
2411
2229
  upsert: false
2412
2230
  });
2413
- const columns = isStringArray(b) ? b : ["*"];
2231
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2414
2232
  const result = await this.read(a, columns);
2415
2233
  return result;
2416
2234
  }
2417
2235
  try {
2418
2236
  if (isString(a) && isObject(b)) {
2419
- const columns = isStringArray(c) ? c : void 0;
2237
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2420
2238
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2421
2239
  }
2422
2240
  if (isObject(a) && isString(a.id)) {
2423
- const columns = isStringArray(b) ? b : void 0;
2241
+ const columns = isValidSelectableColumns(b) ? b : void 0;
2424
2242
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2425
2243
  }
2426
2244
  } catch (error) {
@@ -2460,17 +2278,27 @@ class RestRepository extends Query {
2460
2278
  ifVersion,
2461
2279
  upsert: true
2462
2280
  });
2463
- const columns = isStringArray(b) ? b : ["*"];
2281
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2464
2282
  const result = await this.read(a, columns);
2465
2283
  return result;
2466
2284
  }
2467
2285
  if (isString(a) && isObject(b)) {
2468
- const columns = isStringArray(c) ? c : void 0;
2469
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2286
+ if (a === "")
2287
+ throw new Error("The id can't be empty");
2288
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2289
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2470
2290
  }
2471
2291
  if (isObject(a) && isString(a.id)) {
2472
- const columns = isStringArray(c) ? c : void 0;
2473
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2292
+ if (a.id === "")
2293
+ throw new Error("The id can't be empty");
2294
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2295
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2296
+ }
2297
+ if (!isDefined(a) && isObject(b)) {
2298
+ return await this.create(b, c);
2299
+ }
2300
+ if (isObject(a) && !isDefined(a.id)) {
2301
+ return await this.create(a, b);
2474
2302
  }
2475
2303
  throw new Error("Invalid arguments for createOrUpdate method");
2476
2304
  });
@@ -2482,17 +2310,27 @@ class RestRepository extends Query {
2482
2310
  if (a.length === 0)
2483
2311
  return [];
2484
2312
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2485
- const columns = isStringArray(b) ? b : ["*"];
2313
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2486
2314
  const result = await this.read(ids, columns);
2487
2315
  return result;
2488
2316
  }
2489
2317
  if (isString(a) && isObject(b)) {
2490
- const columns = isStringArray(c) ? c : void 0;
2491
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2318
+ if (a === "")
2319
+ throw new Error("The id can't be empty");
2320
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2321
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2492
2322
  }
2493
2323
  if (isObject(a) && isString(a.id)) {
2494
- const columns = isStringArray(c) ? c : void 0;
2495
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2324
+ if (a.id === "")
2325
+ throw new Error("The id can't be empty");
2326
+ const columns = isValidSelectableColumns(c) ? c : void 0;
2327
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2328
+ }
2329
+ if (!isDefined(a) && isObject(b)) {
2330
+ return await this.create(b, c);
2331
+ }
2332
+ if (isObject(a) && !isDefined(a.id)) {
2333
+ return await this.create(a, b);
2496
2334
  }
2497
2335
  throw new Error("Invalid arguments for createOrReplace method");
2498
2336
  });
@@ -2509,7 +2347,7 @@ class RestRepository extends Query {
2509
2347
  return o.id;
2510
2348
  throw new Error("Invalid arguments for delete method");
2511
2349
  });
2512
- const columns = isStringArray(b) ? b : ["*"];
2350
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
2513
2351
  const result = await this.read(a, columns);
2514
2352
  await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2515
2353
  return result;
@@ -2543,8 +2381,7 @@ class RestRepository extends Query {
2543
2381
  }
2544
2382
  async search(query, options = {}) {
2545
2383
  return __privateGet$4(this, _trace).call(this, "search", async () => {
2546
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2547
- const { records } = await searchTable({
2384
+ const { records, totalCount } = await searchTable({
2548
2385
  pathParams: {
2549
2386
  workspace: "{workspaceId}",
2550
2387
  dbBranchName: "{dbBranch}",
@@ -2561,15 +2398,42 @@ class RestRepository extends Query {
2561
2398
  page: options.page,
2562
2399
  target: options.target
2563
2400
  },
2564
- ...fetchProps
2401
+ ...__privateGet$4(this, _getFetchProps).call(this)
2402
+ });
2403
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2404
+ return {
2405
+ records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
2406
+ totalCount
2407
+ };
2408
+ });
2409
+ }
2410
+ async vectorSearch(column, query, options) {
2411
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2412
+ const { records, totalCount } = await vectorSearchTable({
2413
+ pathParams: {
2414
+ workspace: "{workspaceId}",
2415
+ dbBranchName: "{dbBranch}",
2416
+ region: "{region}",
2417
+ tableName: __privateGet$4(this, _table)
2418
+ },
2419
+ body: {
2420
+ column,
2421
+ queryVector: query,
2422
+ similarityFunction: options?.similarityFunction,
2423
+ size: options?.size,
2424
+ filter: options?.filter
2425
+ },
2426
+ ...__privateGet$4(this, _getFetchProps).call(this)
2565
2427
  });
2566
2428
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2567
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2429
+ return {
2430
+ records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
2431
+ totalCount
2432
+ };
2568
2433
  });
2569
2434
  }
2570
2435
  async aggregate(aggs, filter) {
2571
2436
  return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2572
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2573
2437
  const result = await aggregateTable({
2574
2438
  pathParams: {
2575
2439
  workspace: "{workspaceId}",
@@ -2578,7 +2442,7 @@ class RestRepository extends Query {
2578
2442
  tableName: __privateGet$4(this, _table)
2579
2443
  },
2580
2444
  body: { aggs, filter },
2581
- ...fetchProps
2445
+ ...__privateGet$4(this, _getFetchProps).call(this)
2582
2446
  });
2583
2447
  return result;
2584
2448
  });
@@ -2589,7 +2453,6 @@ class RestRepository extends Query {
2589
2453
  if (cacheQuery)
2590
2454
  return new Page(query, cacheQuery.meta, cacheQuery.records);
2591
2455
  const data = query.getQueryOptions();
2592
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2593
2456
  const { meta, records: objects } = await queryTable({
2594
2457
  pathParams: {
2595
2458
  workspace: "{workspaceId}",
@@ -2605,11 +2468,17 @@ class RestRepository extends Query {
2605
2468
  consistency: data.consistency
2606
2469
  },
2607
2470
  fetchOptions: data.fetchOptions,
2608
- ...fetchProps
2471
+ ...__privateGet$4(this, _getFetchProps).call(this)
2609
2472
  });
2610
2473
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2611
2474
  const records = objects.map(
2612
- (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2475
+ (record) => initObject(
2476
+ __privateGet$4(this, _db),
2477
+ schemaTables,
2478
+ __privateGet$4(this, _table),
2479
+ record,
2480
+ data.columns ?? ["*"]
2481
+ )
2613
2482
  );
2614
2483
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
2615
2484
  return new Page(query, meta, records);
@@ -2618,7 +2487,6 @@ class RestRepository extends Query {
2618
2487
  async summarizeTable(query, summaries, summariesFilter) {
2619
2488
  return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2620
2489
  const data = query.getQueryOptions();
2621
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2622
2490
  const result = await summarizeTable({
2623
2491
  pathParams: {
2624
2492
  workspace: "{workspaceId}",
@@ -2635,11 +2503,50 @@ class RestRepository extends Query {
2635
2503
  summaries,
2636
2504
  summariesFilter
2637
2505
  },
2638
- ...fetchProps
2506
+ ...__privateGet$4(this, _getFetchProps).call(this)
2639
2507
  });
2640
- return result;
2508
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2509
+ return {
2510
+ ...result,
2511
+ summaries: result.summaries.map(
2512
+ (summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
2513
+ )
2514
+ };
2641
2515
  });
2642
2516
  }
2517
+ ask(question, options) {
2518
+ const questionParam = options?.sessionId ? { message: question } : { question };
2519
+ const params = {
2520
+ pathParams: {
2521
+ workspace: "{workspaceId}",
2522
+ dbBranchName: "{dbBranch}",
2523
+ region: "{region}",
2524
+ tableName: __privateGet$4(this, _table),
2525
+ sessionId: options?.sessionId
2526
+ },
2527
+ body: {
2528
+ ...questionParam,
2529
+ rules: options?.rules,
2530
+ searchType: options?.searchType,
2531
+ search: options?.searchType === "keyword" ? options?.search : void 0,
2532
+ vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
2533
+ },
2534
+ ...__privateGet$4(this, _getFetchProps).call(this)
2535
+ };
2536
+ if (options?.onMessage) {
2537
+ fetchSSERequest({
2538
+ endpoint: "dataPlane",
2539
+ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
2540
+ method: "POST",
2541
+ onMessage: (message) => {
2542
+ options.onMessage?.({ answer: message.text, records: message.records });
2543
+ },
2544
+ ...params
2545
+ });
2546
+ } else {
2547
+ return askTableSession(params);
2548
+ }
2549
+ }
2643
2550
  }
2644
2551
  _table = new WeakMap();
2645
2552
  _getFetchProps = new WeakMap();
@@ -2649,8 +2556,7 @@ _schemaTables$2 = new WeakMap();
2649
2556
  _trace = new WeakMap();
2650
2557
  _insertRecordWithoutId = new WeakSet();
2651
2558
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2652
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2653
- const record = transformObjectLinks(object);
2559
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2654
2560
  const response = await insertRecord({
2655
2561
  pathParams: {
2656
2562
  workspace: "{workspaceId}",
@@ -2660,15 +2566,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2660
2566
  },
2661
2567
  queryParams: { columns },
2662
2568
  body: record,
2663
- ...fetchProps
2569
+ ...__privateGet$4(this, _getFetchProps).call(this)
2664
2570
  });
2665
2571
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2666
2572
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2667
2573
  };
2668
2574
  _insertRecordWithId = new WeakSet();
2669
2575
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2670
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2671
- const record = transformObjectLinks(object);
2576
+ if (!recordId)
2577
+ return null;
2578
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2672
2579
  const response = await insertRecordWithID({
2673
2580
  pathParams: {
2674
2581
  workspace: "{workspaceId}",
@@ -2679,30 +2586,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
2679
2586
  },
2680
2587
  body: record,
2681
2588
  queryParams: { createOnly, columns, ifVersion },
2682
- ...fetchProps
2589
+ ...__privateGet$4(this, _getFetchProps).call(this)
2683
2590
  });
2684
2591
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2685
2592
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2686
2593
  };
2687
2594
  _insertRecords = new WeakSet();
2688
2595
  insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2689
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2690
- const chunkedOperations = chunk(
2691
- objects.map((object) => ({
2692
- insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2693
- })),
2694
- BULK_OPERATION_MAX_SIZE
2695
- );
2596
+ const operations = await promiseMap(objects, async (object) => {
2597
+ const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2598
+ return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
2599
+ });
2600
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2696
2601
  const ids = [];
2697
- for (const operations of chunkedOperations) {
2602
+ for (const operations2 of chunkedOperations) {
2698
2603
  const { results } = await branchTransaction({
2699
2604
  pathParams: {
2700
2605
  workspace: "{workspaceId}",
2701
2606
  dbBranchName: "{dbBranch}",
2702
2607
  region: "{region}"
2703
2608
  },
2704
- body: { operations },
2705
- ...fetchProps
2609
+ body: { operations: operations2 },
2610
+ ...__privateGet$4(this, _getFetchProps).call(this)
2706
2611
  });
2707
2612
  for (const result of results) {
2708
2613
  if (result.operation === "insert") {
@@ -2716,8 +2621,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2716
2621
  };
2717
2622
  _updateRecordWithID = new WeakSet();
2718
2623
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2719
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2720
- const { id: _id, ...record } = transformObjectLinks(object);
2624
+ if (!recordId)
2625
+ return null;
2626
+ const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2721
2627
  try {
2722
2628
  const response = await updateRecordWithID({
2723
2629
  pathParams: {
@@ -2729,7 +2635,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2729
2635
  },
2730
2636
  queryParams: { columns, ifVersion },
2731
2637
  body: record,
2732
- ...fetchProps
2638
+ ...__privateGet$4(this, _getFetchProps).call(this)
2733
2639
  });
2734
2640
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2735
2641
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2742,23 +2648,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2742
2648
  };
2743
2649
  _updateRecords = new WeakSet();
2744
2650
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2745
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2746
- const chunkedOperations = chunk(
2747
- objects.map(({ id, ...object }) => ({
2748
- update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2749
- })),
2750
- BULK_OPERATION_MAX_SIZE
2751
- );
2651
+ const operations = await promiseMap(objects, async ({ id, ...object }) => {
2652
+ const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2653
+ return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
2654
+ });
2655
+ const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2752
2656
  const ids = [];
2753
- for (const operations of chunkedOperations) {
2657
+ for (const operations2 of chunkedOperations) {
2754
2658
  const { results } = await branchTransaction({
2755
2659
  pathParams: {
2756
2660
  workspace: "{workspaceId}",
2757
2661
  dbBranchName: "{dbBranch}",
2758
2662
  region: "{region}"
2759
2663
  },
2760
- body: { operations },
2761
- ...fetchProps
2664
+ body: { operations: operations2 },
2665
+ ...__privateGet$4(this, _getFetchProps).call(this)
2762
2666
  });
2763
2667
  for (const result of results) {
2764
2668
  if (result.operation === "update") {
@@ -2772,7 +2676,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2772
2676
  };
2773
2677
  _upsertRecordWithID = new WeakSet();
2774
2678
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2775
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2679
+ if (!recordId)
2680
+ return null;
2776
2681
  const response = await upsertRecordWithID({
2777
2682
  pathParams: {
2778
2683
  workspace: "{workspaceId}",
@@ -2783,14 +2688,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2783
2688
  },
2784
2689
  queryParams: { columns, ifVersion },
2785
2690
  body: object,
2786
- ...fetchProps
2691
+ ...__privateGet$4(this, _getFetchProps).call(this)
2787
2692
  });
2788
2693
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2789
2694
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2790
2695
  };
2791
2696
  _deleteRecord = new WeakSet();
2792
2697
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
2793
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2698
+ if (!recordId)
2699
+ return null;
2794
2700
  try {
2795
2701
  const response = await deleteRecord({
2796
2702
  pathParams: {
@@ -2801,7 +2707,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2801
2707
  recordId
2802
2708
  },
2803
2709
  queryParams: { columns },
2804
- ...fetchProps
2710
+ ...__privateGet$4(this, _getFetchProps).call(this)
2805
2711
  });
2806
2712
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2807
2713
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -2814,9 +2720,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2814
2720
  };
2815
2721
  _deleteRecords = new WeakSet();
2816
2722
  deleteRecords_fn = async function(recordIds) {
2817
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2818
2723
  const chunkedOperations = chunk(
2819
- recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2724
+ compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2820
2725
  BULK_OPERATION_MAX_SIZE
2821
2726
  );
2822
2727
  for (const operations of chunkedOperations) {
@@ -2827,21 +2732,22 @@ deleteRecords_fn = async function(recordIds) {
2827
2732
  region: "{region}"
2828
2733
  },
2829
2734
  body: { operations },
2830
- ...fetchProps
2735
+ ...__privateGet$4(this, _getFetchProps).call(this)
2831
2736
  });
2832
2737
  }
2833
2738
  };
2834
2739
  _setCacheQuery = new WeakSet();
2835
2740
  setCacheQuery_fn = async function(query, meta, records) {
2836
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2741
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
2837
2742
  };
2838
2743
  _getCacheQuery = new WeakSet();
2839
2744
  getCacheQuery_fn = async function(query) {
2840
2745
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2841
- const result = await __privateGet$4(this, _cache).get(key);
2746
+ const result = await __privateGet$4(this, _cache)?.get(key);
2842
2747
  if (!result)
2843
2748
  return null;
2844
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
2749
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
2750
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2845
2751
  if (ttl < 0)
2846
2752
  return null;
2847
2753
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2851,20 +2757,47 @@ _getSchemaTables$1 = new WeakSet();
2851
2757
  getSchemaTables_fn$1 = async function() {
2852
2758
  if (__privateGet$4(this, _schemaTables$2))
2853
2759
  return __privateGet$4(this, _schemaTables$2);
2854
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2855
2760
  const { schema } = await getBranchDetails({
2856
2761
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2857
- ...fetchProps
2762
+ ...__privateGet$4(this, _getFetchProps).call(this)
2858
2763
  });
2859
2764
  __privateSet$4(this, _schemaTables$2, schema.tables);
2860
2765
  return schema.tables;
2861
2766
  };
2862
- const transformObjectLinks = (object) => {
2863
- return Object.entries(object).reduce((acc, [key, value]) => {
2767
+ _transformObjectToApi = new WeakSet();
2768
+ transformObjectToApi_fn = async function(object) {
2769
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2770
+ const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
2771
+ if (!schema)
2772
+ throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
2773
+ const result = {};
2774
+ for (const [key, value] of Object.entries(object)) {
2864
2775
  if (key === "xata")
2865
- return acc;
2866
- return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
2867
- }, {});
2776
+ continue;
2777
+ const type = schema.columns.find((column) => column.name === key)?.type;
2778
+ switch (type) {
2779
+ case "link": {
2780
+ result[key] = isIdentifiable(value) ? value.id : value;
2781
+ break;
2782
+ }
2783
+ case "datetime": {
2784
+ result[key] = value instanceof Date ? value.toISOString() : value;
2785
+ break;
2786
+ }
2787
+ case `file`:
2788
+ result[key] = await parseInputFileEntry(value);
2789
+ break;
2790
+ case "file[]":
2791
+ result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
2792
+ break;
2793
+ case "json":
2794
+ result[key] = stringifyJson(value);
2795
+ break;
2796
+ default:
2797
+ result[key] = value;
2798
+ }
2799
+ }
2800
+ return result;
2868
2801
  };
2869
2802
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2870
2803
  const data = {};
@@ -2896,18 +2829,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2896
2829
  if (item === column.name) {
2897
2830
  return [...acc, "*"];
2898
2831
  }
2899
- if (item.startsWith(`${column.name}.`)) {
2832
+ if (isString(item) && item.startsWith(`${column.name}.`)) {
2900
2833
  const [, ...path] = item.split(".");
2901
2834
  return [...acc, path.join(".")];
2902
2835
  }
2903
2836
  return acc;
2904
2837
  }, []);
2905
- data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2838
+ data[column.name] = initObject(
2839
+ db,
2840
+ schemaTables,
2841
+ linkTable,
2842
+ value,
2843
+ selectedLinkColumns
2844
+ );
2906
2845
  } else {
2907
2846
  data[column.name] = null;
2908
2847
  }
2909
2848
  break;
2910
2849
  }
2850
+ case "file":
2851
+ data[column.name] = isDefined(value) ? new XataFile(value) : null;
2852
+ break;
2853
+ case "file[]":
2854
+ data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
2855
+ break;
2856
+ case "json":
2857
+ data[column.name] = parseJson(value);
2858
+ break;
2911
2859
  default:
2912
2860
  data[column.name] = value ?? null;
2913
2861
  if (column.notNull === true && value === null) {
@@ -2917,26 +2865,36 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2917
2865
  }
2918
2866
  }
2919
2867
  const record = { ...data };
2868
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2920
2869
  record.read = function(columns2) {
2921
2870
  return db[table].read(record["id"], columns2);
2922
2871
  };
2923
2872
  record.update = function(data2, b, c) {
2924
- const columns2 = isStringArray(b) ? b : ["*"];
2873
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2925
2874
  const ifVersion = parseIfVersion(b, c);
2926
2875
  return db[table].update(record["id"], data2, columns2, { ifVersion });
2927
2876
  };
2928
2877
  record.replace = function(data2, b, c) {
2929
- const columns2 = isStringArray(b) ? b : ["*"];
2878
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2930
2879
  const ifVersion = parseIfVersion(b, c);
2931
2880
  return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2932
2881
  };
2933
2882
  record.delete = function() {
2934
2883
  return db[table].delete(record["id"]);
2935
2884
  };
2885
+ if (metadata !== void 0) {
2886
+ record.xata = Object.freeze(metadata);
2887
+ }
2936
2888
  record.getMetadata = function() {
2937
- return xata;
2889
+ return record.xata;
2890
+ };
2891
+ record.toSerializable = function() {
2892
+ return JSON.parse(JSON.stringify(record));
2893
+ };
2894
+ record.toString = function() {
2895
+ return JSON.stringify(record);
2938
2896
  };
2939
- for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
2897
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
2940
2898
  Object.defineProperty(record, prop, { enumerable: false });
2941
2899
  }
2942
2900
  Object.freeze(record);
@@ -2952,11 +2910,7 @@ function extractId(value) {
2952
2910
  function isValidColumn(columns, column) {
2953
2911
  if (columns.includes("*"))
2954
2912
  return true;
2955
- if (column.type === "link") {
2956
- const linkColumns = columns.filter((item) => item.startsWith(column.name));
2957
- return linkColumns.length > 0;
2958
- }
2959
- return columns.includes(column.name);
2913
+ return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
2960
2914
  }
2961
2915
  function parseIfVersion(...args) {
2962
2916
  for (const arg of args) {
@@ -3033,10 +2987,12 @@ const notExists = (column) => ({ $notExists: column });
3033
2987
  const startsWith = (value) => ({ $startsWith: value });
3034
2988
  const endsWith = (value) => ({ $endsWith: value });
3035
2989
  const pattern = (value) => ({ $pattern: value });
2990
+ const iPattern = (value) => ({ $iPattern: value });
3036
2991
  const is = (value) => ({ $is: value });
3037
2992
  const equals = is;
3038
2993
  const isNot = (value) => ({ $isNot: value });
3039
2994
  const contains = (value) => ({ $contains: value });
2995
+ const iContains = (value) => ({ $iContains: value });
3040
2996
  const includes = (value) => ({ $includes: value });
3041
2997
  const includesAll = (value) => ({ $includesAll: value });
3042
2998
  const includesNone = (value) => ({ $includesNone: value });
@@ -3092,6 +3048,80 @@ class SchemaPlugin extends XataPlugin {
3092
3048
  _tables = new WeakMap();
3093
3049
  _schemaTables$1 = new WeakMap();
3094
3050
 
3051
+ class FilesPlugin extends XataPlugin {
3052
+ build(pluginOptions) {
3053
+ return {
3054
+ download: async (location) => {
3055
+ const { table, record, column, fileId = "" } = location ?? {};
3056
+ return await getFileItem({
3057
+ pathParams: {
3058
+ workspace: "{workspaceId}",
3059
+ dbBranchName: "{dbBranch}",
3060
+ region: "{region}",
3061
+ tableName: table ?? "",
3062
+ recordId: record ?? "",
3063
+ columnName: column ?? "",
3064
+ fileId
3065
+ },
3066
+ ...pluginOptions,
3067
+ rawResponse: true
3068
+ });
3069
+ },
3070
+ upload: async (location, file, options) => {
3071
+ const { table, record, column, fileId = "" } = location ?? {};
3072
+ const resolvedFile = await file;
3073
+ const contentType = options?.mediaType || getContentType(resolvedFile);
3074
+ const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
3075
+ return await putFileItem({
3076
+ ...pluginOptions,
3077
+ pathParams: {
3078
+ workspace: "{workspaceId}",
3079
+ dbBranchName: "{dbBranch}",
3080
+ region: "{region}",
3081
+ tableName: table ?? "",
3082
+ recordId: record ?? "",
3083
+ columnName: column ?? "",
3084
+ fileId
3085
+ },
3086
+ body,
3087
+ headers: { "Content-Type": contentType }
3088
+ });
3089
+ },
3090
+ delete: async (location) => {
3091
+ const { table, record, column, fileId = "" } = location ?? {};
3092
+ return await deleteFileItem({
3093
+ pathParams: {
3094
+ workspace: "{workspaceId}",
3095
+ dbBranchName: "{dbBranch}",
3096
+ region: "{region}",
3097
+ tableName: table ?? "",
3098
+ recordId: record ?? "",
3099
+ columnName: column ?? "",
3100
+ fileId
3101
+ },
3102
+ ...pluginOptions
3103
+ });
3104
+ }
3105
+ };
3106
+ }
3107
+ }
3108
+ function getContentType(file) {
3109
+ if (typeof file === "string") {
3110
+ return "text/plain";
3111
+ }
3112
+ if ("mediaType" in file && file.mediaType !== void 0) {
3113
+ return file.mediaType;
3114
+ }
3115
+ if (isBlob(file)) {
3116
+ return file.type;
3117
+ }
3118
+ try {
3119
+ return file.type;
3120
+ } catch (e) {
3121
+ }
3122
+ return "application/octet-stream";
3123
+ }
3124
+
3095
3125
  var __accessCheck$1 = (obj, member, msg) => {
3096
3126
  if (!member.has(obj))
3097
3127
  throw TypeError("Cannot " + msg);
@@ -3124,63 +3154,137 @@ class SearchPlugin extends XataPlugin {
3124
3154
  __privateAdd$1(this, _schemaTables, void 0);
3125
3155
  __privateSet$1(this, _schemaTables, schemaTables);
3126
3156
  }
3127
- build({ getFetchProps }) {
3157
+ build(pluginOptions) {
3128
3158
  return {
3129
3159
  all: async (query, options = {}) => {
3130
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3131
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3132
- return records.map((record) => {
3133
- const { table = "orphan" } = record.xata;
3134
- return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3135
- });
3160
+ const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3161
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3162
+ return {
3163
+ totalCount,
3164
+ records: records.map((record) => {
3165
+ const { table = "orphan" } = record.xata;
3166
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
3167
+ })
3168
+ };
3136
3169
  },
3137
3170
  byTable: async (query, options = {}) => {
3138
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3139
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3140
- return records.reduce((acc, record) => {
3171
+ const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3172
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
3173
+ const records = rawRecords.reduce((acc, record) => {
3141
3174
  const { table = "orphan" } = record.xata;
3142
3175
  const items = acc[table] ?? [];
3143
3176
  const item = initObject(this.db, schemaTables, table, record, ["*"]);
3144
3177
  return { ...acc, [table]: [...items, item] };
3145
3178
  }, {});
3179
+ return { totalCount, records };
3146
3180
  }
3147
3181
  };
3148
3182
  }
3149
3183
  }
3150
3184
  _schemaTables = new WeakMap();
3151
3185
  _search = new WeakSet();
3152
- search_fn = async function(query, options, getFetchProps) {
3153
- const fetchProps = await getFetchProps();
3186
+ search_fn = async function(query, options, pluginOptions) {
3154
3187
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3155
- const { records } = await searchBranch({
3188
+ const { records, totalCount } = await searchBranch({
3156
3189
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3190
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3157
3191
  body: { tables, query, fuzziness, prefix, highlight, page },
3158
- ...fetchProps
3192
+ ...pluginOptions
3159
3193
  });
3160
- return records;
3194
+ return { records, totalCount };
3161
3195
  };
3162
3196
  _getSchemaTables = new WeakSet();
3163
- getSchemaTables_fn = async function(getFetchProps) {
3197
+ getSchemaTables_fn = async function(pluginOptions) {
3164
3198
  if (__privateGet$1(this, _schemaTables))
3165
3199
  return __privateGet$1(this, _schemaTables);
3166
- const fetchProps = await getFetchProps();
3167
3200
  const { schema } = await getBranchDetails({
3168
3201
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3169
- ...fetchProps
3202
+ ...pluginOptions
3170
3203
  });
3171
3204
  __privateSet$1(this, _schemaTables, schema.tables);
3172
3205
  return schema.tables;
3173
3206
  };
3174
3207
 
3208
+ function escapeElement(elementRepresentation) {
3209
+ const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
3210
+ return '"' + escaped + '"';
3211
+ }
3212
+ function arrayString(val) {
3213
+ let result = "{";
3214
+ for (let i = 0; i < val.length; i++) {
3215
+ if (i > 0) {
3216
+ result = result + ",";
3217
+ }
3218
+ if (val[i] === null || typeof val[i] === "undefined") {
3219
+ result = result + "NULL";
3220
+ } else if (Array.isArray(val[i])) {
3221
+ result = result + arrayString(val[i]);
3222
+ } else if (val[i] instanceof Buffer) {
3223
+ result += "\\\\x" + val[i].toString("hex");
3224
+ } else {
3225
+ result += escapeElement(prepareValue(val[i]));
3226
+ }
3227
+ }
3228
+ result = result + "}";
3229
+ return result;
3230
+ }
3231
+ function prepareValue(value) {
3232
+ if (!isDefined(value))
3233
+ return null;
3234
+ if (value instanceof Date) {
3235
+ return value.toISOString();
3236
+ }
3237
+ if (Array.isArray(value)) {
3238
+ return arrayString(value);
3239
+ }
3240
+ if (isObject(value)) {
3241
+ return JSON.stringify(value);
3242
+ }
3243
+ try {
3244
+ return value.toString();
3245
+ } catch (e) {
3246
+ return value;
3247
+ }
3248
+ }
3249
+ function prepareParams(param1, param2) {
3250
+ if (isString(param1)) {
3251
+ return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
3252
+ }
3253
+ if (isStringArray(param1)) {
3254
+ const statement = param1.reduce((acc, curr, index) => {
3255
+ return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
3256
+ }, "");
3257
+ return { statement, params: param2?.map((value) => prepareValue(value)) };
3258
+ }
3259
+ if (isObject(param1)) {
3260
+ const { statement, params, consistency } = param1;
3261
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency };
3262
+ }
3263
+ throw new Error("Invalid query");
3264
+ }
3265
+
3266
+ class SQLPlugin extends XataPlugin {
3267
+ build(pluginOptions) {
3268
+ return async (param1, ...param2) => {
3269
+ const { statement, params, consistency } = prepareParams(param1, param2);
3270
+ const { records, warning } = await sqlQuery({
3271
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3272
+ body: { statement, params, consistency },
3273
+ ...pluginOptions
3274
+ });
3275
+ return { records, warning };
3276
+ };
3277
+ }
3278
+ }
3279
+
3175
3280
  class TransactionPlugin extends XataPlugin {
3176
- build({ getFetchProps }) {
3281
+ build(pluginOptions) {
3177
3282
  return {
3178
3283
  run: async (operations) => {
3179
- const fetchProps = await getFetchProps();
3180
3284
  const response = await branchTransaction({
3181
3285
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3182
3286
  body: { operations },
3183
- ...fetchProps
3287
+ ...pluginOptions
3184
3288
  });
3185
3289
  return response;
3186
3290
  }
@@ -3188,90 +3292,6 @@ class TransactionPlugin extends XataPlugin {
3188
3292
  }
3189
3293
  }
3190
3294
 
3191
- const isBranchStrategyBuilder = (strategy) => {
3192
- return typeof strategy === "function";
3193
- };
3194
-
3195
- async function getCurrentBranchName(options) {
3196
- const { branch, envBranch } = getEnvironment();
3197
- if (branch)
3198
- return branch;
3199
- const gitBranch = envBranch || await getGitBranch();
3200
- return resolveXataBranch(gitBranch, options);
3201
- }
3202
- async function getCurrentBranchDetails(options) {
3203
- const branch = await getCurrentBranchName(options);
3204
- return getDatabaseBranch(branch, options);
3205
- }
3206
- async function resolveXataBranch(gitBranch, options) {
3207
- const databaseURL = options?.databaseURL || getDatabaseURL();
3208
- const apiKey = options?.apiKey || getAPIKey();
3209
- if (!databaseURL)
3210
- throw new Error(
3211
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3212
- );
3213
- if (!apiKey)
3214
- throw new Error(
3215
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3216
- );
3217
- const [protocol, , host, , dbName] = databaseURL.split("/");
3218
- const urlParts = parseWorkspacesUrlParts(host);
3219
- if (!urlParts)
3220
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3221
- const { workspace, region } = urlParts;
3222
- const { fallbackBranch } = getEnvironment();
3223
- const { branch } = await resolveBranch({
3224
- apiKey,
3225
- apiUrl: databaseURL,
3226
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3227
- workspacesApiUrl: `${protocol}//${host}`,
3228
- pathParams: { dbName, workspace, region },
3229
- queryParams: { gitBranch, fallbackBranch },
3230
- trace: defaultTrace,
3231
- clientName: options?.clientName
3232
- });
3233
- return branch;
3234
- }
3235
- async function getDatabaseBranch(branch, options) {
3236
- const databaseURL = options?.databaseURL || getDatabaseURL();
3237
- const apiKey = options?.apiKey || getAPIKey();
3238
- if (!databaseURL)
3239
- throw new Error(
3240
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3241
- );
3242
- if (!apiKey)
3243
- throw new Error(
3244
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3245
- );
3246
- const [protocol, , host, , database] = databaseURL.split("/");
3247
- const urlParts = parseWorkspacesUrlParts(host);
3248
- if (!urlParts)
3249
- throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3250
- const { workspace, region } = urlParts;
3251
- try {
3252
- return await getBranchDetails({
3253
- apiKey,
3254
- apiUrl: databaseURL,
3255
- fetchImpl: getFetchImplementation(options?.fetchImpl),
3256
- workspacesApiUrl: `${protocol}//${host}`,
3257
- pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3258
- trace: defaultTrace
3259
- });
3260
- } catch (err) {
3261
- if (isObject(err) && err.status === 404)
3262
- return null;
3263
- throw err;
3264
- }
3265
- }
3266
- function getDatabaseURL() {
3267
- try {
3268
- const { databaseURL } = getEnvironment();
3269
- return databaseURL;
3270
- } catch (err) {
3271
- return void 0;
3272
- }
3273
- }
3274
-
3275
3295
  var __accessCheck = (obj, member, msg) => {
3276
3296
  if (!member.has(obj))
3277
3297
  throw TypeError("Cannot " + msg);
@@ -3295,46 +3315,41 @@ var __privateMethod = (obj, member, method) => {
3295
3315
  return method;
3296
3316
  };
3297
3317
  const buildClient = (plugins) => {
3298
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3318
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
3299
3319
  return _a = class {
3300
3320
  constructor(options = {}, schemaTables) {
3301
3321
  __privateAdd(this, _parseOptions);
3302
3322
  __privateAdd(this, _getFetchProps);
3303
- __privateAdd(this, _evaluateBranch);
3304
- __privateAdd(this, _branch, void 0);
3305
3323
  __privateAdd(this, _options, void 0);
3306
3324
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3307
3325
  __privateSet(this, _options, safeOptions);
3308
3326
  const pluginOptions = {
3309
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3327
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3310
3328
  cache: safeOptions.cache,
3311
- trace: safeOptions.trace
3329
+ host: safeOptions.host
3312
3330
  };
3313
3331
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3314
3332
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3315
3333
  const transactions = new TransactionPlugin().build(pluginOptions);
3334
+ const sql = new SQLPlugin().build(pluginOptions);
3335
+ const files = new FilesPlugin().build(pluginOptions);
3316
3336
  this.db = db;
3317
3337
  this.search = search;
3318
3338
  this.transactions = transactions;
3339
+ this.sql = sql;
3340
+ this.files = files;
3319
3341
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
3320
3342
  if (namespace === void 0)
3321
3343
  continue;
3322
- const result = namespace.build(pluginOptions);
3323
- if (result instanceof Promise) {
3324
- void result.then((namespace2) => {
3325
- this[key] = namespace2;
3326
- });
3327
- } else {
3328
- this[key] = result;
3329
- }
3344
+ this[key] = namespace.build(pluginOptions);
3330
3345
  }
3331
3346
  }
3332
3347
  async getConfig() {
3333
3348
  const databaseURL = __privateGet(this, _options).databaseURL;
3334
- const branch = await __privateGet(this, _options).branch();
3349
+ const branch = __privateGet(this, _options).branch;
3335
3350
  return { databaseURL, branch };
3336
3351
  }
3337
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3352
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3338
3353
  const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3339
3354
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3340
3355
  if (isBrowser && !enableBrowser) {
@@ -3348,60 +3363,72 @@ const buildClient = (plugins) => {
3348
3363
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3349
3364
  const trace = options?.trace ?? defaultTrace;
3350
3365
  const clientName = options?.clientName;
3351
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3352
- apiKey,
3353
- databaseURL,
3354
- fetchImpl: options?.fetch,
3355
- clientName: options?.clientName
3356
- });
3366
+ const host = options?.host ?? "production";
3367
+ const xataAgentExtra = options?.xataAgentExtra;
3357
3368
  if (!apiKey) {
3358
3369
  throw new Error("Option apiKey is required");
3359
3370
  }
3360
3371
  if (!databaseURL) {
3361
3372
  throw new Error("Option databaseURL is required");
3362
3373
  }
3363
- return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
3364
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3374
+ const envBranch = getBranch();
3375
+ const previewBranch = getPreviewBranch();
3376
+ const branch = options?.branch || previewBranch || envBranch || "main";
3377
+ if (!!previewBranch && branch !== previewBranch) {
3378
+ console.warn(
3379
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
3380
+ );
3381
+ } else if (!!envBranch && branch !== envBranch) {
3382
+ console.warn(
3383
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3384
+ );
3385
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
3386
+ console.warn(
3387
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3388
+ );
3389
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
3390
+ console.warn(
3391
+ `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.`
3392
+ );
3393
+ }
3394
+ return {
3395
+ fetch,
3396
+ databaseURL,
3397
+ apiKey,
3398
+ branch,
3399
+ cache,
3400
+ trace,
3401
+ host,
3402
+ clientID: generateUUID(),
3403
+ enableBrowser,
3404
+ clientName,
3405
+ xataAgentExtra
3406
+ };
3407
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3365
3408
  fetch,
3366
3409
  apiKey,
3367
3410
  databaseURL,
3368
3411
  branch,
3369
3412
  trace,
3370
3413
  clientID,
3371
- clientName
3414
+ clientName,
3415
+ xataAgentExtra
3372
3416
  }) {
3373
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3374
- if (!branchValue)
3375
- throw new Error("Unable to resolve branch value");
3376
3417
  return {
3377
- fetchImpl: fetch,
3418
+ fetch,
3378
3419
  apiKey,
3379
3420
  apiUrl: "",
3421
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3380
3422
  workspacesApiUrl: (path, params) => {
3381
3423
  const hasBranch = params.dbBranchName ?? params.branch;
3382
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
3424
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
3383
3425
  return databaseURL + newPath;
3384
3426
  },
3385
3427
  trace,
3386
3428
  clientID,
3387
- clientName
3388
- };
3389
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3390
- if (__privateGet(this, _branch))
3391
- return __privateGet(this, _branch);
3392
- if (param === void 0)
3393
- return void 0;
3394
- const strategies = Array.isArray(param) ? [...param] : [param];
3395
- const evaluateBranch = async (strategy) => {
3396
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3429
+ clientName,
3430
+ xataAgentExtra
3397
3431
  };
3398
- for await (const strategy of strategies) {
3399
- const branch = await evaluateBranch(strategy);
3400
- if (branch) {
3401
- __privateSet(this, _branch, branch);
3402
- return branch;
3403
- }
3404
- }
3405
3432
  }, _a;
3406
3433
  };
3407
3434
  class BaseClient extends buildClient() {
@@ -3474,21 +3501,6 @@ const deserialize = (json) => {
3474
3501
  return defaultSerializer.fromJSON(json);
3475
3502
  };
3476
3503
 
3477
- function buildWorkerRunner(config) {
3478
- return function xataWorker(name, worker) {
3479
- return async (...args) => {
3480
- const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
3481
- const result = await fetch(url, {
3482
- method: "POST",
3483
- headers: { "Content-Type": "application/json" },
3484
- body: serialize({ args })
3485
- });
3486
- const text = await result.text();
3487
- return deserialize(text);
3488
- };
3489
- };
3490
- }
3491
-
3492
3504
  class XataError extends Error {
3493
3505
  constructor(message, status) {
3494
3506
  super(message);
@@ -3498,6 +3510,7 @@ class XataError extends Error {
3498
3510
 
3499
3511
  exports.BaseClient = BaseClient;
3500
3512
  exports.FetcherError = FetcherError;
3513
+ exports.FilesPlugin = FilesPlugin;
3501
3514
  exports.Operations = operationsByTag;
3502
3515
  exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
3503
3516
  exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
@@ -3506,31 +3519,41 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
3506
3519
  exports.Page = Page;
3507
3520
  exports.Query = Query;
3508
3521
  exports.RecordArray = RecordArray;
3522
+ exports.RecordColumnTypes = RecordColumnTypes;
3509
3523
  exports.Repository = Repository;
3510
3524
  exports.RestRepository = RestRepository;
3525
+ exports.SQLPlugin = SQLPlugin;
3511
3526
  exports.SchemaPlugin = SchemaPlugin;
3512
3527
  exports.SearchPlugin = SearchPlugin;
3513
3528
  exports.Serializer = Serializer;
3514
3529
  exports.SimpleCache = SimpleCache;
3530
+ exports.TransactionPlugin = TransactionPlugin;
3515
3531
  exports.XataApiClient = XataApiClient;
3516
3532
  exports.XataApiPlugin = XataApiPlugin;
3517
3533
  exports.XataError = XataError;
3534
+ exports.XataFile = XataFile;
3518
3535
  exports.XataPlugin = XataPlugin;
3519
3536
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
3520
3537
  exports.addGitBranchesEntry = addGitBranchesEntry;
3521
3538
  exports.addTableColumn = addTableColumn;
3522
3539
  exports.aggregateTable = aggregateTable;
3523
3540
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3541
+ exports.applyMigration = applyMigration;
3542
+ exports.askTable = askTable;
3543
+ exports.askTableSession = askTableSession;
3524
3544
  exports.branchTransaction = branchTransaction;
3525
3545
  exports.buildClient = buildClient;
3526
- exports.buildWorkerRunner = buildWorkerRunner;
3546
+ exports.buildPreviewBranchName = buildPreviewBranchName;
3547
+ exports.buildProviderString = buildProviderString;
3527
3548
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
3528
3549
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
3529
3550
  exports.compareBranchSchemas = compareBranchSchemas;
3530
3551
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3531
3552
  exports.compareMigrationRequest = compareMigrationRequest;
3532
3553
  exports.contains = contains;
3554
+ exports.copyBranch = copyBranch;
3533
3555
  exports.createBranch = createBranch;
3556
+ exports.createCluster = createCluster;
3534
3557
  exports.createDatabase = createDatabase;
3535
3558
  exports.createMigrationRequest = createMigrationRequest;
3536
3559
  exports.createTable = createTable;
@@ -3539,18 +3562,26 @@ exports.createWorkspace = createWorkspace;
3539
3562
  exports.deleteBranch = deleteBranch;
3540
3563
  exports.deleteColumn = deleteColumn;
3541
3564
  exports.deleteDatabase = deleteDatabase;
3565
+ exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
3566
+ exports.deleteFile = deleteFile;
3567
+ exports.deleteFileItem = deleteFileItem;
3568
+ exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
3542
3569
  exports.deleteRecord = deleteRecord;
3543
3570
  exports.deleteTable = deleteTable;
3544
3571
  exports.deleteUser = deleteUser;
3545
3572
  exports.deleteUserAPIKey = deleteUserAPIKey;
3573
+ exports.deleteUserOAuthClient = deleteUserOAuthClient;
3546
3574
  exports.deleteWorkspace = deleteWorkspace;
3547
3575
  exports.deserialize = deserialize;
3548
3576
  exports.endsWith = endsWith;
3549
3577
  exports.equals = equals;
3550
3578
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
3551
3579
  exports.exists = exists;
3580
+ exports.fileAccess = fileAccess;
3552
3581
  exports.ge = ge;
3553
3582
  exports.getAPIKey = getAPIKey;
3583
+ exports.getAuthorizationCode = getAuthorizationCode;
3584
+ exports.getBranch = getBranch;
3554
3585
  exports.getBranchDetails = getBranchDetails;
3555
3586
  exports.getBranchList = getBranchList;
3556
3587
  exports.getBranchMetadata = getBranchMetadata;
@@ -3558,29 +3589,38 @@ exports.getBranchMigrationHistory = getBranchMigrationHistory;
3558
3589
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
3559
3590
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
3560
3591
  exports.getBranchStats = getBranchStats;
3592
+ exports.getCluster = getCluster;
3561
3593
  exports.getColumn = getColumn;
3562
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
3563
- exports.getCurrentBranchName = getCurrentBranchName;
3594
+ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3564
3595
  exports.getDatabaseList = getDatabaseList;
3565
3596
  exports.getDatabaseMetadata = getDatabaseMetadata;
3566
3597
  exports.getDatabaseURL = getDatabaseURL;
3598
+ exports.getFile = getFile;
3599
+ exports.getFileItem = getFileItem;
3567
3600
  exports.getGitBranchesMapping = getGitBranchesMapping;
3568
3601
  exports.getHostUrl = getHostUrl;
3569
3602
  exports.getMigrationRequest = getMigrationRequest;
3570
3603
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
3604
+ exports.getPreviewBranch = getPreviewBranch;
3571
3605
  exports.getRecord = getRecord;
3606
+ exports.getSchema = getSchema;
3572
3607
  exports.getTableColumns = getTableColumns;
3573
3608
  exports.getTableSchema = getTableSchema;
3574
3609
  exports.getUser = getUser;
3575
3610
  exports.getUserAPIKeys = getUserAPIKeys;
3611
+ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
3612
+ exports.getUserOAuthClients = getUserOAuthClients;
3576
3613
  exports.getWorkspace = getWorkspace;
3577
3614
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
3578
3615
  exports.getWorkspacesList = getWorkspacesList;
3616
+ exports.grantAuthorizationCode = grantAuthorizationCode;
3579
3617
  exports.greaterEquals = greaterEquals;
3580
3618
  exports.greaterThan = greaterThan;
3581
3619
  exports.greaterThanEquals = greaterThanEquals;
3582
3620
  exports.gt = gt;
3583
3621
  exports.gte = gte;
3622
+ exports.iContains = iContains;
3623
+ exports.iPattern = iPattern;
3584
3624
  exports.includes = includes;
3585
3625
  exports.includesAll = includesAll;
3586
3626
  exports.includesAny = includesAny;
@@ -3594,11 +3634,14 @@ exports.isHostProviderAlias = isHostProviderAlias;
3594
3634
  exports.isHostProviderBuilder = isHostProviderBuilder;
3595
3635
  exports.isIdentifiable = isIdentifiable;
3596
3636
  exports.isNot = isNot;
3637
+ exports.isValidExpandedColumn = isValidExpandedColumn;
3638
+ exports.isValidSelectableColumns = isValidSelectableColumns;
3597
3639
  exports.isXataRecord = isXataRecord;
3598
3640
  exports.le = le;
3599
3641
  exports.lessEquals = lessEquals;
3600
3642
  exports.lessThan = lessThan;
3601
3643
  exports.lessThanEquals = lessThanEquals;
3644
+ exports.listClusters = listClusters;
3602
3645
  exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3603
3646
  exports.listRegions = listRegions;
3604
3647
  exports.lt = lt;
@@ -3609,24 +3652,35 @@ exports.operationsByTag = operationsByTag;
3609
3652
  exports.parseProviderString = parseProviderString;
3610
3653
  exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
3611
3654
  exports.pattern = pattern;
3655
+ exports.pgRollJobStatus = pgRollJobStatus;
3656
+ exports.pgRollStatus = pgRollStatus;
3612
3657
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3658
+ exports.pushBranchMigrations = pushBranchMigrations;
3659
+ exports.putFile = putFile;
3660
+ exports.putFileItem = putFileItem;
3613
3661
  exports.queryMigrationRequests = queryMigrationRequests;
3614
3662
  exports.queryTable = queryTable;
3615
3663
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
3616
3664
  exports.removeWorkspaceMember = removeWorkspaceMember;
3665
+ exports.renameDatabase = renameDatabase;
3617
3666
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
3618
3667
  exports.resolveBranch = resolveBranch;
3619
3668
  exports.searchBranch = searchBranch;
3620
3669
  exports.searchTable = searchTable;
3621
3670
  exports.serialize = serialize;
3622
3671
  exports.setTableSchema = setTableSchema;
3672
+ exports.sqlQuery = sqlQuery;
3623
3673
  exports.startsWith = startsWith;
3624
3674
  exports.summarizeTable = summarizeTable;
3675
+ exports.transformImage = transformImage;
3625
3676
  exports.updateBranchMetadata = updateBranchMetadata;
3626
3677
  exports.updateBranchSchema = updateBranchSchema;
3678
+ exports.updateCluster = updateCluster;
3627
3679
  exports.updateColumn = updateColumn;
3680
+ exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
3628
3681
  exports.updateDatabaseMetadata = updateDatabaseMetadata;
3629
3682
  exports.updateMigrationRequest = updateMigrationRequest;
3683
+ exports.updateOAuthAccessToken = updateOAuthAccessToken;
3630
3684
  exports.updateRecordWithID = updateRecordWithID;
3631
3685
  exports.updateTable = updateTable;
3632
3686
  exports.updateUser = updateUser;
@@ -3634,4 +3688,5 @@ exports.updateWorkspace = updateWorkspace;
3634
3688
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
3635
3689
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
3636
3690
  exports.upsertRecordWithID = upsertRecordWithID;
3691
+ exports.vectorSearchTable = vectorSearchTable;
3637
3692
  //# sourceMappingURL=index.cjs.map