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

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
@@ -1,36 +1,15 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopNamespace(e) {
6
- if (e && e.__esModule) return e;
7
- var n = Object.create(null);
8
- if (e) {
9
- Object.keys(e).forEach(function (k) {
10
- if (k !== 'default') {
11
- var d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: function () { return e[k]; }
15
- });
16
- }
17
- });
18
- }
19
- n["default"] = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- const defaultTrace = async (_name, fn, _options) => {
3
+ const defaultTrace = async (name, fn, _options) => {
24
4
  return await fn({
5
+ name,
25
6
  setAttributes: () => {
26
7
  return;
27
- },
28
- onError: () => {
29
- return;
30
8
  }
31
9
  });
32
10
  };
33
11
  const TraceAttributes = {
12
+ KIND: "xata.trace.kind",
34
13
  VERSION: "xata.sdk.version",
35
14
  TABLE: "xata.table",
36
15
  HTTP_REQUEST_ID: "http.request_id",
@@ -62,6 +41,21 @@ function isString(value) {
62
41
  function isStringArray(value) {
63
42
  return isDefined(value) && Array.isArray(value) && value.every(isString);
64
43
  }
44
+ function isNumber(value) {
45
+ return isDefined(value) && typeof value === "number";
46
+ }
47
+ function parseNumber(value) {
48
+ if (isNumber(value)) {
49
+ return value;
50
+ }
51
+ if (isString(value)) {
52
+ const parsed = Number(value);
53
+ if (!Number.isNaN(parsed)) {
54
+ return parsed;
55
+ }
56
+ }
57
+ return void 0;
58
+ }
65
59
  function toBase64(value) {
66
60
  try {
67
61
  return btoa(value);
@@ -70,10 +64,31 @@ function toBase64(value) {
70
64
  return buf.from(value).toString("base64");
71
65
  }
72
66
  }
67
+ function deepMerge(a, b) {
68
+ const result = { ...a };
69
+ for (const [key, value] of Object.entries(b)) {
70
+ if (isObject(value) && isObject(result[key])) {
71
+ result[key] = deepMerge(result[key], value);
72
+ } else {
73
+ result[key] = value;
74
+ }
75
+ }
76
+ return result;
77
+ }
78
+ function chunk(array, chunkSize) {
79
+ const result = [];
80
+ for (let i = 0; i < array.length; i += chunkSize) {
81
+ result.push(array.slice(i, i + chunkSize));
82
+ }
83
+ return result;
84
+ }
85
+ async function timeout(ms) {
86
+ return new Promise((resolve) => setTimeout(resolve, ms));
87
+ }
73
88
 
74
89
  function getEnvironment() {
75
90
  try {
76
- if (isObject(process) && isObject(process.env)) {
91
+ if (isDefined(process) && isDefined(process.env)) {
77
92
  return {
78
93
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
79
94
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
@@ -104,6 +119,25 @@ function getEnvironment() {
104
119
  fallbackBranch: getGlobalFallbackBranch()
105
120
  };
106
121
  }
122
+ function getEnableBrowserVariable() {
123
+ try {
124
+ if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
125
+ return process.env.XATA_ENABLE_BROWSER === "true";
126
+ }
127
+ } catch (err) {
128
+ }
129
+ try {
130
+ if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
131
+ return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
132
+ }
133
+ } catch (err) {
134
+ }
135
+ try {
136
+ return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
137
+ } catch (err) {
138
+ return void 0;
139
+ }
140
+ }
107
141
  function getGlobalApiKey() {
108
142
  try {
109
143
  return XATA_API_KEY;
@@ -141,8 +175,6 @@ async function getGitBranch() {
141
175
  if (typeof require === "function") {
142
176
  return require(nodeModule).execSync(fullCmd, execOptions).trim();
143
177
  }
144
- const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
145
- return execSync(fullCmd, execOptions).toString().trim();
146
178
  } catch (err) {
147
179
  }
148
180
  try {
@@ -163,6 +195,29 @@ function getAPIKey() {
163
195
  }
164
196
  }
165
197
 
198
+ var __accessCheck$8 = (obj, member, msg) => {
199
+ if (!member.has(obj))
200
+ throw TypeError("Cannot " + msg);
201
+ };
202
+ var __privateGet$8 = (obj, member, getter) => {
203
+ __accessCheck$8(obj, member, "read from private field");
204
+ return getter ? getter.call(obj) : member.get(obj);
205
+ };
206
+ var __privateAdd$8 = (obj, member, value) => {
207
+ if (member.has(obj))
208
+ throw TypeError("Cannot add the same private member more than once");
209
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
210
+ };
211
+ var __privateSet$8 = (obj, member, value, setter) => {
212
+ __accessCheck$8(obj, member, "write to private field");
213
+ setter ? setter.call(obj, value) : member.set(obj, value);
214
+ return value;
215
+ };
216
+ var __privateMethod$4 = (obj, member, method) => {
217
+ __accessCheck$8(obj, member, "access private method");
218
+ return method;
219
+ };
220
+ var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
166
221
  function getFetchImplementation(userFetch) {
167
222
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
168
223
  const fetchImpl = userFetch ?? globalFetch;
@@ -173,8 +228,81 @@ function getFetchImplementation(userFetch) {
173
228
  }
174
229
  return fetchImpl;
175
230
  }
231
+ class ApiRequestPool {
232
+ 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);
239
+ this.running = 0;
240
+ this.started = 0;
241
+ }
242
+ setFetch(fetch2) {
243
+ __privateSet$8(this, _fetch, fetch2);
244
+ }
245
+ getFetch() {
246
+ if (!__privateGet$8(this, _fetch)) {
247
+ throw new Error("Fetch not set");
248
+ }
249
+ return __privateGet$8(this, _fetch);
250
+ }
251
+ request(url, options) {
252
+ const start = new Date();
253
+ const fetch2 = this.getFetch();
254
+ const runRequest = async (stalled = false) => {
255
+ const response = await fetch2(url, options);
256
+ if (response.status === 429) {
257
+ const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
258
+ await timeout(rateLimitReset * 1e3);
259
+ return await runRequest(true);
260
+ }
261
+ 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`);
264
+ }
265
+ return response;
266
+ };
267
+ return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
268
+ return await runRequest();
269
+ });
270
+ }
271
+ }
272
+ _fetch = new WeakMap();
273
+ _queue = new WeakMap();
274
+ _concurrency = new WeakMap();
275
+ _enqueue = new WeakSet();
276
+ enqueue_fn = function(task) {
277
+ const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
278
+ this.started--;
279
+ this.running++;
280
+ }).then(() => task()).finally(() => {
281
+ this.running--;
282
+ const next = __privateGet$8(this, _queue).shift();
283
+ if (next !== void 0) {
284
+ this.started++;
285
+ next();
286
+ }
287
+ });
288
+ if (this.running + this.started < __privateGet$8(this, _concurrency)) {
289
+ const next = __privateGet$8(this, _queue).shift();
290
+ if (next !== void 0) {
291
+ this.started++;
292
+ next();
293
+ }
294
+ }
295
+ return promise;
296
+ };
297
+
298
+ function generateUUID() {
299
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
300
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
301
+ return v.toString(16);
302
+ });
303
+ }
176
304
 
177
- const VERSION = "0.0.0-alpha.vfbd878f";
305
+ const VERSION = "0.22.1";
178
306
 
179
307
  class ErrorWithCause extends Error {
180
308
  constructor(message, options) {
@@ -185,7 +313,7 @@ class FetcherError extends ErrorWithCause {
185
313
  constructor(status, data, requestId) {
186
314
  super(getMessage(data));
187
315
  this.status = status;
188
- this.errors = isBulkError(data) ? data.errors : void 0;
316
+ this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
189
317
  this.requestId = requestId;
190
318
  if (data instanceof Error) {
191
319
  this.stack = data.stack;
@@ -217,6 +345,7 @@ function getMessage(data) {
217
345
  }
218
346
  }
219
347
 
348
+ const pool = new ApiRequestPool();
220
349
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
221
350
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
222
351
  if (value === void 0 || value === null)
@@ -225,69 +354,100 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
225
354
  }, {});
226
355
  const query = new URLSearchParams(cleanQueryParams).toString();
227
356
  const queryString = query.length > 0 ? `?${query}` : "";
228
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
357
+ const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
358
+ return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
359
+ }, {});
360
+ return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
229
361
  };
230
362
  function buildBaseUrl({
363
+ endpoint,
231
364
  path,
232
365
  workspacesApiUrl,
233
366
  apiUrl,
234
- pathParams
367
+ pathParams = {}
235
368
  }) {
236
- if (!pathParams?.workspace)
237
- return `${apiUrl}${path}`;
238
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
239
- return url.replace("{workspaceId}", pathParams.workspace);
369
+ if (endpoint === "dataPlane") {
370
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
371
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
372
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
373
+ }
374
+ return `${apiUrl}${path}`;
240
375
  }
241
376
  function hostHeader(url) {
242
377
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
243
378
  const { groups } = pattern.exec(url) ?? {};
244
379
  return groups?.host ? { Host: groups.host } : {};
245
380
  }
381
+ const defaultClientID = generateUUID();
246
382
  async function fetch$1({
247
383
  url: path,
248
384
  method,
249
385
  body,
250
- headers,
386
+ headers: customHeaders,
251
387
  pathParams,
252
388
  queryParams,
253
389
  fetchImpl,
254
390
  apiKey,
391
+ endpoint,
255
392
  apiUrl,
256
393
  workspacesApiUrl,
257
- trace
394
+ trace,
395
+ signal,
396
+ clientID,
397
+ sessionID,
398
+ clientName,
399
+ xataAgentExtra,
400
+ fetchOptions = {}
258
401
  }) {
259
- return trace(
402
+ pool.setFetch(fetchImpl);
403
+ return await trace(
260
404
  `${method.toUpperCase()} ${path}`,
261
- async ({ setAttributes, onError }) => {
262
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
405
+ async ({ setAttributes }) => {
406
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
263
407
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
264
408
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
265
409
  setAttributes({
266
410
  [TraceAttributes.HTTP_URL]: url,
267
411
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
268
412
  });
269
- const response = await fetchImpl(url, {
413
+ const xataAgent = compact([
414
+ ["client", "TS_SDK"],
415
+ ["version", VERSION],
416
+ isDefined(clientName) ? ["service", clientName] : void 0,
417
+ ...Object.entries(xataAgentExtra ?? {})
418
+ ]).map(([key, value]) => `${key}=${value}`).join("; ");
419
+ const headers = {
420
+ "Accept-Encoding": "identity",
421
+ "Content-Type": "application/json",
422
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
423
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
424
+ "X-Xata-Agent": xataAgent,
425
+ ...customHeaders,
426
+ ...hostHeader(fullUrl),
427
+ Authorization: `Bearer ${apiKey}`
428
+ };
429
+ const response = await pool.request(url, {
430
+ ...fetchOptions,
270
431
  method: method.toUpperCase(),
271
432
  body: body ? JSON.stringify(body) : void 0,
272
- headers: {
273
- "Content-Type": "application/json",
274
- "User-Agent": `Xata client-ts/${VERSION}`,
275
- ...headers,
276
- ...hostHeader(fullUrl),
277
- Authorization: `Bearer ${apiKey}`
278
- }
433
+ headers,
434
+ signal
279
435
  });
280
- if (response.status === 204) {
281
- return {};
282
- }
283
436
  const { host, protocol } = parseUrl(response.url);
284
437
  const requestId = response.headers?.get("x-request-id") ?? void 0;
285
438
  setAttributes({
439
+ [TraceAttributes.KIND]: "http",
286
440
  [TraceAttributes.HTTP_REQUEST_ID]: requestId,
287
441
  [TraceAttributes.HTTP_STATUS_CODE]: response.status,
288
442
  [TraceAttributes.HTTP_HOST]: host,
289
443
  [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
290
444
  });
445
+ if (response.status === 204) {
446
+ return {};
447
+ }
448
+ if (response.status === 429) {
449
+ throw new FetcherError(response.status, "Rate limit exceeded", requestId);
450
+ }
291
451
  try {
292
452
  const jsonResponse = await response.json();
293
453
  if (response.ok) {
@@ -295,9 +455,7 @@ async function fetch$1({
295
455
  }
296
456
  throw new FetcherError(response.status, jsonResponse, requestId);
297
457
  } catch (error) {
298
- const fetcherError = new FetcherError(response.status, error, requestId);
299
- onError(fetcherError.message);
300
- throw fetcherError;
458
+ throw new FetcherError(response.status, error, requestId);
301
459
  }
302
460
  },
303
461
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
@@ -312,246 +470,153 @@ function parseUrl(url) {
312
470
  }
313
471
  }
314
472
 
315
- const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
316
- const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
317
- const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
318
- const getUserAPIKeys = (variables) => fetch$1({
319
- url: "/user/keys",
320
- method: "get",
321
- ...variables
322
- });
323
- const createUserAPIKey = (variables) => fetch$1({
324
- url: "/user/keys/{keyName}",
325
- method: "post",
326
- ...variables
327
- });
328
- const deleteUserAPIKey = (variables) => fetch$1({
329
- url: "/user/keys/{keyName}",
330
- method: "delete",
331
- ...variables
332
- });
333
- const createWorkspace = (variables) => fetch$1({
334
- url: "/workspaces",
335
- method: "post",
336
- ...variables
337
- });
338
- const getWorkspacesList = (variables) => fetch$1({
339
- url: "/workspaces",
340
- method: "get",
341
- ...variables
342
- });
343
- const getWorkspace = (variables) => fetch$1({
344
- url: "/workspaces/{workspaceId}",
345
- method: "get",
346
- ...variables
347
- });
348
- const updateWorkspace = (variables) => fetch$1({
349
- url: "/workspaces/{workspaceId}",
350
- method: "put",
351
- ...variables
352
- });
353
- const deleteWorkspace = (variables) => fetch$1({
354
- url: "/workspaces/{workspaceId}",
355
- method: "delete",
356
- ...variables
357
- });
358
- const getWorkspaceMembersList = (variables) => fetch$1({
359
- url: "/workspaces/{workspaceId}/members",
360
- method: "get",
361
- ...variables
362
- });
363
- const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
364
- const removeWorkspaceMember = (variables) => fetch$1({
365
- url: "/workspaces/{workspaceId}/members/{userId}",
366
- method: "delete",
367
- ...variables
368
- });
369
- const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
370
- const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
371
- const cancelWorkspaceMemberInvite = (variables) => fetch$1({
372
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
373
- method: "delete",
374
- ...variables
375
- });
376
- const resendWorkspaceMemberInvite = (variables) => fetch$1({
377
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
378
- method: "post",
379
- ...variables
380
- });
381
- const acceptWorkspaceMemberInvite = (variables) => fetch$1({
382
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
383
- method: "post",
384
- ...variables
385
- });
386
- const getDatabaseList = (variables) => fetch$1({
387
- url: "/dbs",
388
- method: "get",
389
- ...variables
390
- });
391
- const getBranchList = (variables) => fetch$1({
392
- url: "/dbs/{dbName}",
393
- method: "get",
394
- ...variables
395
- });
396
- const createDatabase = (variables) => fetch$1({
397
- url: "/dbs/{dbName}",
398
- method: "put",
399
- ...variables
400
- });
401
- const deleteDatabase = (variables) => fetch$1({
473
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
474
+
475
+ const getBranchList = (variables, signal) => dataPlaneFetch({
402
476
  url: "/dbs/{dbName}",
403
- method: "delete",
404
- ...variables
405
- });
406
- const getDatabaseMetadata = (variables) => fetch$1({
407
- url: "/dbs/{dbName}/metadata",
408
- method: "get",
409
- ...variables
410
- });
411
- const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
412
- const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
413
- const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
414
- const resolveBranch = (variables) => fetch$1({
415
- url: "/dbs/{dbName}/resolveBranch",
416
477
  method: "get",
417
- ...variables
478
+ ...variables,
479
+ signal
418
480
  });
419
- const getBranchDetails = (variables) => fetch$1({
481
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
420
482
  url: "/db/{dbBranchName}",
421
483
  method: "get",
422
- ...variables
484
+ ...variables,
485
+ signal
423
486
  });
424
- const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
425
- const deleteBranch = (variables) => fetch$1({
487
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
488
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
426
489
  url: "/db/{dbBranchName}",
427
490
  method: "delete",
428
- ...variables
491
+ ...variables,
492
+ signal
429
493
  });
430
- const updateBranchMetadata = (variables) => fetch$1({
494
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
431
495
  url: "/db/{dbBranchName}/metadata",
432
496
  method: "put",
433
- ...variables
497
+ ...variables,
498
+ signal
434
499
  });
435
- const getBranchMetadata = (variables) => fetch$1({
500
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
436
501
  url: "/db/{dbBranchName}/metadata",
437
502
  method: "get",
438
- ...variables
503
+ ...variables,
504
+ signal
439
505
  });
440
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
441
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
442
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
443
- const getBranchStats = (variables) => fetch$1({
506
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
444
507
  url: "/db/{dbBranchName}/stats",
445
508
  method: "get",
446
- ...variables
509
+ ...variables,
510
+ signal
447
511
  });
448
- const createTable = (variables) => fetch$1({
512
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
513
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
514
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
515
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
516
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
517
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
518
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
519
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
520
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
521
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
522
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
523
+ method: "get",
524
+ ...variables,
525
+ signal
526
+ });
527
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
528
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
529
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
530
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
531
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
532
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
533
+ method: "post",
534
+ ...variables,
535
+ signal
536
+ });
537
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
538
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
539
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
540
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
541
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
542
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
543
+ const createTable = (variables, signal) => dataPlaneFetch({
449
544
  url: "/db/{dbBranchName}/tables/{tableName}",
450
545
  method: "put",
451
- ...variables
546
+ ...variables,
547
+ signal
452
548
  });
453
- const deleteTable = (variables) => fetch$1({
549
+ const deleteTable = (variables, signal) => dataPlaneFetch({
454
550
  url: "/db/{dbBranchName}/tables/{tableName}",
455
551
  method: "delete",
456
- ...variables
457
- });
458
- const updateTable = (variables) => fetch$1({
459
- url: "/db/{dbBranchName}/tables/{tableName}",
460
- method: "patch",
461
- ...variables
552
+ ...variables,
553
+ signal
462
554
  });
463
- const getTableSchema = (variables) => fetch$1({
555
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
556
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
464
557
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
465
558
  method: "get",
466
- ...variables
559
+ ...variables,
560
+ signal
467
561
  });
468
- const setTableSchema = (variables) => fetch$1({
469
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
470
- method: "put",
471
- ...variables
472
- });
473
- const getTableColumns = (variables) => fetch$1({
562
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
563
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
474
564
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
475
565
  method: "get",
476
- ...variables
477
- });
478
- const addTableColumn = (variables) => fetch$1({
479
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
480
- method: "post",
481
- ...variables
566
+ ...variables,
567
+ signal
482
568
  });
483
- const getColumn = (variables) => fetch$1({
569
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
570
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
571
+ );
572
+ const getColumn = (variables, signal) => dataPlaneFetch({
484
573
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
485
574
  method: "get",
486
- ...variables
575
+ ...variables,
576
+ signal
487
577
  });
488
- const deleteColumn = (variables) => fetch$1({
578
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
579
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
489
580
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
490
581
  method: "delete",
491
- ...variables
492
- });
493
- const updateColumn = (variables) => fetch$1({
494
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
495
- method: "patch",
496
- ...variables
582
+ ...variables,
583
+ signal
497
584
  });
498
- const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
499
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
500
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
501
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
502
- const deleteRecord = (variables) => fetch$1({
503
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
504
- method: "delete",
505
- ...variables
506
- });
507
- const getRecord = (variables) => fetch$1({
585
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
586
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
587
+ const getRecord = (variables, signal) => dataPlaneFetch({
508
588
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
509
589
  method: "get",
510
- ...variables
590
+ ...variables,
591
+ signal
511
592
  });
512
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
513
- const queryTable = (variables) => fetch$1({
593
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
594
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
595
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
596
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
597
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
598
+ const queryTable = (variables, signal) => dataPlaneFetch({
514
599
  url: "/db/{dbBranchName}/tables/{tableName}/query",
515
600
  method: "post",
516
- ...variables
601
+ ...variables,
602
+ signal
517
603
  });
518
- const searchTable = (variables) => fetch$1({
519
- url: "/db/{dbBranchName}/tables/{tableName}/search",
604
+ const searchBranch = (variables, signal) => dataPlaneFetch({
605
+ url: "/db/{dbBranchName}/search",
520
606
  method: "post",
521
- ...variables
607
+ ...variables,
608
+ signal
522
609
  });
523
- const searchBranch = (variables) => fetch$1({
524
- url: "/db/{dbBranchName}/search",
610
+ const searchTable = (variables, signal) => dataPlaneFetch({
611
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
525
612
  method: "post",
526
- ...variables
613
+ ...variables,
614
+ signal
527
615
  });
528
- const operationsByTag = {
529
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
530
- workspaces: {
531
- createWorkspace,
532
- getWorkspacesList,
533
- getWorkspace,
534
- updateWorkspace,
535
- deleteWorkspace,
536
- getWorkspaceMembersList,
537
- updateWorkspaceMemberRole,
538
- removeWorkspaceMember,
539
- inviteWorkspaceMember,
540
- updateWorkspaceMemberInvite,
541
- cancelWorkspaceMemberInvite,
542
- resendWorkspaceMemberInvite,
543
- acceptWorkspaceMemberInvite
544
- },
545
- database: {
546
- getDatabaseList,
547
- createDatabase,
548
- deleteDatabase,
549
- getDatabaseMetadata,
550
- getGitBranchesMapping,
551
- addGitBranchesEntry,
552
- removeGitBranchesEntry,
553
- resolveBranch
554
- },
616
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
617
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
618
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
619
+ const operationsByTag$2 = {
555
620
  branch: {
556
621
  getBranchList,
557
622
  getBranchDetails,
@@ -559,10 +624,32 @@ const operationsByTag = {
559
624
  deleteBranch,
560
625
  updateBranchMetadata,
561
626
  getBranchMetadata,
627
+ getBranchStats,
628
+ getGitBranchesMapping,
629
+ addGitBranchesEntry,
630
+ removeGitBranchesEntry,
631
+ resolveBranch
632
+ },
633
+ migrations: {
562
634
  getBranchMigrationHistory,
563
- executeBranchMigrationPlan,
564
635
  getBranchMigrationPlan,
565
- getBranchStats
636
+ executeBranchMigrationPlan,
637
+ getBranchSchemaHistory,
638
+ compareBranchWithUserSchema,
639
+ compareBranchSchemas,
640
+ updateBranchSchema,
641
+ previewBranchSchemaEdit,
642
+ applyBranchSchemaEdit
643
+ },
644
+ migrationRequests: {
645
+ queryMigrationRequests,
646
+ createMigrationRequest,
647
+ getMigrationRequest,
648
+ updateMigrationRequest,
649
+ listMigrationRequestsCommits,
650
+ compareMigrationRequest,
651
+ getMigrationRequestIsMerged,
652
+ mergeMigrationRequest
566
653
  },
567
654
  table: {
568
655
  createTable,
@@ -573,23 +660,162 @@ const operationsByTag = {
573
660
  getTableColumns,
574
661
  addTableColumn,
575
662
  getColumn,
576
- deleteColumn,
577
- updateColumn
663
+ updateColumn,
664
+ deleteColumn
578
665
  },
579
666
  records: {
667
+ branchTransaction,
580
668
  insertRecord,
669
+ getRecord,
581
670
  insertRecordWithID,
582
671
  updateRecordWithID,
583
672
  upsertRecordWithID,
584
673
  deleteRecord,
585
- getRecord,
586
- bulkInsertTableRecords,
587
- queryTable,
588
- searchTable,
589
- searchBranch
674
+ bulkInsertTableRecords
675
+ },
676
+ searchAndFilter: { queryTable, searchBranch, searchTable, vectorSearchTable, summarizeTable, aggregateTable }
677
+ };
678
+
679
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
680
+
681
+ const getUser = (variables, signal) => controlPlaneFetch({
682
+ url: "/user",
683
+ method: "get",
684
+ ...variables,
685
+ signal
686
+ });
687
+ const updateUser = (variables, signal) => controlPlaneFetch({
688
+ url: "/user",
689
+ method: "put",
690
+ ...variables,
691
+ signal
692
+ });
693
+ const deleteUser = (variables, signal) => controlPlaneFetch({
694
+ url: "/user",
695
+ method: "delete",
696
+ ...variables,
697
+ signal
698
+ });
699
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
700
+ url: "/user/keys",
701
+ method: "get",
702
+ ...variables,
703
+ signal
704
+ });
705
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
706
+ url: "/user/keys/{keyName}",
707
+ method: "post",
708
+ ...variables,
709
+ signal
710
+ });
711
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
712
+ url: "/user/keys/{keyName}",
713
+ method: "delete",
714
+ ...variables,
715
+ signal
716
+ });
717
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
718
+ url: "/workspaces",
719
+ method: "get",
720
+ ...variables,
721
+ signal
722
+ });
723
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
724
+ url: "/workspaces",
725
+ method: "post",
726
+ ...variables,
727
+ signal
728
+ });
729
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
730
+ url: "/workspaces/{workspaceId}",
731
+ method: "get",
732
+ ...variables,
733
+ signal
734
+ });
735
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
736
+ url: "/workspaces/{workspaceId}",
737
+ method: "put",
738
+ ...variables,
739
+ signal
740
+ });
741
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
742
+ url: "/workspaces/{workspaceId}",
743
+ method: "delete",
744
+ ...variables,
745
+ signal
746
+ });
747
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
748
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
749
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
750
+ url: "/workspaces/{workspaceId}/members/{userId}",
751
+ method: "delete",
752
+ ...variables,
753
+ signal
754
+ });
755
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
756
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
757
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
758
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
759
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
760
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
761
+ url: "/workspaces/{workspaceId}/dbs",
762
+ method: "get",
763
+ ...variables,
764
+ signal
765
+ });
766
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
767
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
768
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
769
+ method: "delete",
770
+ ...variables,
771
+ signal
772
+ });
773
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
774
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
775
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
776
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
777
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
778
+ const listRegions = (variables, signal) => controlPlaneFetch({
779
+ url: "/workspaces/{workspaceId}/regions",
780
+ method: "get",
781
+ ...variables,
782
+ signal
783
+ });
784
+ const operationsByTag$1 = {
785
+ users: { getUser, updateUser, deleteUser },
786
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
787
+ workspaces: {
788
+ getWorkspacesList,
789
+ createWorkspace,
790
+ getWorkspace,
791
+ updateWorkspace,
792
+ deleteWorkspace,
793
+ getWorkspaceMembersList,
794
+ updateWorkspaceMemberRole,
795
+ removeWorkspaceMember
796
+ },
797
+ invites: {
798
+ inviteWorkspaceMember,
799
+ updateWorkspaceMemberInvite,
800
+ cancelWorkspaceMemberInvite,
801
+ acceptWorkspaceMemberInvite,
802
+ resendWorkspaceMemberInvite
803
+ },
804
+ databases: {
805
+ getDatabaseList,
806
+ createDatabase,
807
+ deleteDatabase,
808
+ getDatabaseMetadata,
809
+ updateDatabaseMetadata,
810
+ getDatabaseGithubSettings,
811
+ updateDatabaseGithubSettings,
812
+ deleteDatabaseGithubSettings,
813
+ listRegions
590
814
  }
591
815
  };
592
816
 
817
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
818
+
593
819
  function getHostUrl(provider, type) {
594
820
  if (isHostProviderAlias(provider)) {
595
821
  return providers[provider][type];
@@ -601,11 +827,11 @@ function getHostUrl(provider, type) {
601
827
  const providers = {
602
828
  production: {
603
829
  main: "https://api.xata.io",
604
- workspaces: "https://{workspaceId}.xata.sh"
830
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
605
831
  },
606
832
  staging: {
607
- main: "https://staging.xatabase.co",
608
- workspaces: "https://{workspaceId}.staging.xatabase.co"
833
+ main: "https://api.staging-xata.dev",
834
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
609
835
  }
610
836
  };
611
837
  function isHostProviderAlias(alias) {
@@ -614,6 +840,27 @@ function isHostProviderAlias(alias) {
614
840
  function isHostProviderBuilder(builder) {
615
841
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
616
842
  }
843
+ function parseProviderString(provider = "production") {
844
+ if (isHostProviderAlias(provider)) {
845
+ return provider;
846
+ }
847
+ const [main, workspaces] = provider.split(",");
848
+ if (!main || !workspaces)
849
+ return null;
850
+ return { main, workspaces };
851
+ }
852
+ function parseWorkspacesUrlParts(url) {
853
+ if (!isString(url))
854
+ return null;
855
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
856
+ const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
857
+ const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
858
+ const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
859
+ const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
860
+ if (!match)
861
+ return null;
862
+ return { workspace: match[1], region: match[2] };
863
+ }
617
864
 
618
865
  var __accessCheck$7 = (obj, member, msg) => {
619
866
  if (!member.has(obj))
@@ -641,6 +888,7 @@ class XataApiClient {
641
888
  const provider = options.host ?? "production";
642
889
  const apiKey = options.apiKey ?? getAPIKey();
643
890
  const trace = options.trace ?? defaultTrace;
891
+ const clientID = generateUUID();
644
892
  if (!apiKey) {
645
893
  throw new Error("Could not resolve a valid apiKey");
646
894
  }
@@ -649,7 +897,10 @@ class XataApiClient {
649
897
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
650
898
  fetchImpl: getFetchImplementation(options.fetch),
651
899
  apiKey,
652
- trace
900
+ trace,
901
+ clientName: options.clientName,
902
+ xataAgentExtra: options.xataAgentExtra,
903
+ clientID
653
904
  });
654
905
  }
655
906
  get user() {
@@ -657,21 +908,41 @@ class XataApiClient {
657
908
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
658
909
  return __privateGet$7(this, _namespaces).user;
659
910
  }
911
+ get authentication() {
912
+ if (!__privateGet$7(this, _namespaces).authentication)
913
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
914
+ return __privateGet$7(this, _namespaces).authentication;
915
+ }
660
916
  get workspaces() {
661
917
  if (!__privateGet$7(this, _namespaces).workspaces)
662
918
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
663
919
  return __privateGet$7(this, _namespaces).workspaces;
664
920
  }
665
- get databases() {
666
- if (!__privateGet$7(this, _namespaces).databases)
667
- __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
668
- return __privateGet$7(this, _namespaces).databases;
921
+ get invites() {
922
+ if (!__privateGet$7(this, _namespaces).invites)
923
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
924
+ return __privateGet$7(this, _namespaces).invites;
925
+ }
926
+ get database() {
927
+ if (!__privateGet$7(this, _namespaces).database)
928
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
929
+ return __privateGet$7(this, _namespaces).database;
669
930
  }
670
931
  get branches() {
671
932
  if (!__privateGet$7(this, _namespaces).branches)
672
933
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
673
934
  return __privateGet$7(this, _namespaces).branches;
674
935
  }
936
+ get migrations() {
937
+ if (!__privateGet$7(this, _namespaces).migrations)
938
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
939
+ return __privateGet$7(this, _namespaces).migrations;
940
+ }
941
+ get migrationRequests() {
942
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
943
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
944
+ return __privateGet$7(this, _namespaces).migrationRequests;
945
+ }
675
946
  get tables() {
676
947
  if (!__privateGet$7(this, _namespaces).tables)
677
948
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -682,6 +953,11 @@ class XataApiClient {
682
953
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
683
954
  return __privateGet$7(this, _namespaces).records;
684
955
  }
956
+ get searchAndFilter() {
957
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
958
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
959
+ return __privateGet$7(this, _namespaces).searchAndFilter;
960
+ }
685
961
  }
686
962
  _extraProps = new WeakMap();
687
963
  _namespaces = new WeakMap();
@@ -692,24 +968,29 @@ class UserApi {
692
968
  getUser() {
693
969
  return operationsByTag.users.getUser({ ...this.extraProps });
694
970
  }
695
- updateUser(user) {
971
+ updateUser({ user }) {
696
972
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
697
973
  }
698
974
  deleteUser() {
699
975
  return operationsByTag.users.deleteUser({ ...this.extraProps });
700
976
  }
977
+ }
978
+ class AuthenticationApi {
979
+ constructor(extraProps) {
980
+ this.extraProps = extraProps;
981
+ }
701
982
  getUserAPIKeys() {
702
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
983
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
703
984
  }
704
- createUserAPIKey(keyName) {
705
- return operationsByTag.users.createUserAPIKey({
706
- pathParams: { keyName },
985
+ createUserAPIKey({ name }) {
986
+ return operationsByTag.authentication.createUserAPIKey({
987
+ pathParams: { keyName: name },
707
988
  ...this.extraProps
708
989
  });
709
990
  }
710
- deleteUserAPIKey(keyName) {
711
- return operationsByTag.users.deleteUserAPIKey({
712
- pathParams: { keyName },
991
+ deleteUserAPIKey({ name }) {
992
+ return operationsByTag.authentication.deleteUserAPIKey({
993
+ pathParams: { keyName: name },
713
994
  ...this.extraProps
714
995
  });
715
996
  }
@@ -718,359 +999,929 @@ class WorkspaceApi {
718
999
  constructor(extraProps) {
719
1000
  this.extraProps = extraProps;
720
1001
  }
721
- createWorkspace(workspaceMeta) {
1002
+ getWorkspacesList() {
1003
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
1004
+ }
1005
+ createWorkspace({ data }) {
722
1006
  return operationsByTag.workspaces.createWorkspace({
723
- body: workspaceMeta,
1007
+ body: data,
724
1008
  ...this.extraProps
725
1009
  });
726
1010
  }
727
- getWorkspacesList() {
728
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
729
- }
730
- getWorkspace(workspaceId) {
1011
+ getWorkspace({ workspace }) {
731
1012
  return operationsByTag.workspaces.getWorkspace({
732
- pathParams: { workspaceId },
1013
+ pathParams: { workspaceId: workspace },
733
1014
  ...this.extraProps
734
1015
  });
735
1016
  }
736
- updateWorkspace(workspaceId, workspaceMeta) {
1017
+ updateWorkspace({
1018
+ workspace,
1019
+ update
1020
+ }) {
737
1021
  return operationsByTag.workspaces.updateWorkspace({
738
- pathParams: { workspaceId },
739
- body: workspaceMeta,
1022
+ pathParams: { workspaceId: workspace },
1023
+ body: update,
740
1024
  ...this.extraProps
741
1025
  });
742
1026
  }
743
- deleteWorkspace(workspaceId) {
1027
+ deleteWorkspace({ workspace }) {
744
1028
  return operationsByTag.workspaces.deleteWorkspace({
745
- pathParams: { workspaceId },
1029
+ pathParams: { workspaceId: workspace },
1030
+ ...this.extraProps
1031
+ });
1032
+ }
1033
+ getWorkspaceMembersList({ workspace }) {
1034
+ return operationsByTag.workspaces.getWorkspaceMembersList({
1035
+ pathParams: { workspaceId: workspace },
1036
+ ...this.extraProps
1037
+ });
1038
+ }
1039
+ updateWorkspaceMemberRole({
1040
+ workspace,
1041
+ user,
1042
+ role
1043
+ }) {
1044
+ return operationsByTag.workspaces.updateWorkspaceMemberRole({
1045
+ pathParams: { workspaceId: workspace, userId: user },
1046
+ body: { role },
1047
+ ...this.extraProps
1048
+ });
1049
+ }
1050
+ removeWorkspaceMember({
1051
+ workspace,
1052
+ user
1053
+ }) {
1054
+ return operationsByTag.workspaces.removeWorkspaceMember({
1055
+ pathParams: { workspaceId: workspace, userId: user },
1056
+ ...this.extraProps
1057
+ });
1058
+ }
1059
+ }
1060
+ class InvitesApi {
1061
+ constructor(extraProps) {
1062
+ this.extraProps = extraProps;
1063
+ }
1064
+ inviteWorkspaceMember({
1065
+ workspace,
1066
+ email,
1067
+ role
1068
+ }) {
1069
+ return operationsByTag.invites.inviteWorkspaceMember({
1070
+ pathParams: { workspaceId: workspace },
1071
+ body: { email, role },
1072
+ ...this.extraProps
1073
+ });
1074
+ }
1075
+ updateWorkspaceMemberInvite({
1076
+ workspace,
1077
+ invite,
1078
+ role
1079
+ }) {
1080
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
1081
+ pathParams: { workspaceId: workspace, inviteId: invite },
1082
+ body: { role },
1083
+ ...this.extraProps
1084
+ });
1085
+ }
1086
+ cancelWorkspaceMemberInvite({
1087
+ workspace,
1088
+ invite
1089
+ }) {
1090
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
1091
+ pathParams: { workspaceId: workspace, inviteId: invite },
1092
+ ...this.extraProps
1093
+ });
1094
+ }
1095
+ acceptWorkspaceMemberInvite({
1096
+ workspace,
1097
+ key
1098
+ }) {
1099
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
1100
+ pathParams: { workspaceId: workspace, inviteKey: key },
1101
+ ...this.extraProps
1102
+ });
1103
+ }
1104
+ resendWorkspaceMemberInvite({
1105
+ workspace,
1106
+ invite
1107
+ }) {
1108
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
1109
+ pathParams: { workspaceId: workspace, inviteId: invite },
1110
+ ...this.extraProps
1111
+ });
1112
+ }
1113
+ }
1114
+ class BranchApi {
1115
+ constructor(extraProps) {
1116
+ this.extraProps = extraProps;
1117
+ }
1118
+ getBranchList({
1119
+ workspace,
1120
+ region,
1121
+ database
1122
+ }) {
1123
+ return operationsByTag.branch.getBranchList({
1124
+ pathParams: { workspace, region, dbName: database },
1125
+ ...this.extraProps
1126
+ });
1127
+ }
1128
+ getBranchDetails({
1129
+ workspace,
1130
+ region,
1131
+ database,
1132
+ branch
1133
+ }) {
1134
+ return operationsByTag.branch.getBranchDetails({
1135
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1136
+ ...this.extraProps
1137
+ });
1138
+ }
1139
+ createBranch({
1140
+ workspace,
1141
+ region,
1142
+ database,
1143
+ branch,
1144
+ from,
1145
+ metadata
1146
+ }) {
1147
+ return operationsByTag.branch.createBranch({
1148
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1149
+ body: { from, metadata },
1150
+ ...this.extraProps
1151
+ });
1152
+ }
1153
+ deleteBranch({
1154
+ workspace,
1155
+ region,
1156
+ database,
1157
+ branch
1158
+ }) {
1159
+ return operationsByTag.branch.deleteBranch({
1160
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1161
+ ...this.extraProps
1162
+ });
1163
+ }
1164
+ updateBranchMetadata({
1165
+ workspace,
1166
+ region,
1167
+ database,
1168
+ branch,
1169
+ metadata
1170
+ }) {
1171
+ return operationsByTag.branch.updateBranchMetadata({
1172
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1173
+ body: metadata,
1174
+ ...this.extraProps
1175
+ });
1176
+ }
1177
+ getBranchMetadata({
1178
+ workspace,
1179
+ region,
1180
+ database,
1181
+ branch
1182
+ }) {
1183
+ return operationsByTag.branch.getBranchMetadata({
1184
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1185
+ ...this.extraProps
1186
+ });
1187
+ }
1188
+ getBranchStats({
1189
+ workspace,
1190
+ region,
1191
+ database,
1192
+ branch
1193
+ }) {
1194
+ return operationsByTag.branch.getBranchStats({
1195
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1196
+ ...this.extraProps
1197
+ });
1198
+ }
1199
+ getGitBranchesMapping({
1200
+ workspace,
1201
+ region,
1202
+ database
1203
+ }) {
1204
+ return operationsByTag.branch.getGitBranchesMapping({
1205
+ pathParams: { workspace, region, dbName: database },
1206
+ ...this.extraProps
1207
+ });
1208
+ }
1209
+ addGitBranchesEntry({
1210
+ workspace,
1211
+ region,
1212
+ database,
1213
+ gitBranch,
1214
+ xataBranch
1215
+ }) {
1216
+ return operationsByTag.branch.addGitBranchesEntry({
1217
+ pathParams: { workspace, region, dbName: database },
1218
+ body: { gitBranch, xataBranch },
1219
+ ...this.extraProps
1220
+ });
1221
+ }
1222
+ removeGitBranchesEntry({
1223
+ workspace,
1224
+ region,
1225
+ database,
1226
+ gitBranch
1227
+ }) {
1228
+ return operationsByTag.branch.removeGitBranchesEntry({
1229
+ pathParams: { workspace, region, dbName: database },
1230
+ queryParams: { gitBranch },
1231
+ ...this.extraProps
1232
+ });
1233
+ }
1234
+ resolveBranch({
1235
+ workspace,
1236
+ region,
1237
+ database,
1238
+ gitBranch,
1239
+ fallbackBranch
1240
+ }) {
1241
+ return operationsByTag.branch.resolveBranch({
1242
+ pathParams: { workspace, region, dbName: database },
1243
+ queryParams: { gitBranch, fallbackBranch },
1244
+ ...this.extraProps
1245
+ });
1246
+ }
1247
+ }
1248
+ class TableApi {
1249
+ constructor(extraProps) {
1250
+ this.extraProps = extraProps;
1251
+ }
1252
+ createTable({
1253
+ workspace,
1254
+ region,
1255
+ database,
1256
+ branch,
1257
+ table
1258
+ }) {
1259
+ return operationsByTag.table.createTable({
1260
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1261
+ ...this.extraProps
1262
+ });
1263
+ }
1264
+ deleteTable({
1265
+ workspace,
1266
+ region,
1267
+ database,
1268
+ branch,
1269
+ table
1270
+ }) {
1271
+ return operationsByTag.table.deleteTable({
1272
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
746
1273
  ...this.extraProps
747
1274
  });
748
1275
  }
749
- getWorkspaceMembersList(workspaceId) {
750
- return operationsByTag.workspaces.getWorkspaceMembersList({
751
- pathParams: { workspaceId },
1276
+ updateTable({
1277
+ workspace,
1278
+ region,
1279
+ database,
1280
+ branch,
1281
+ table,
1282
+ update
1283
+ }) {
1284
+ return operationsByTag.table.updateTable({
1285
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1286
+ body: update,
752
1287
  ...this.extraProps
753
1288
  });
754
1289
  }
755
- updateWorkspaceMemberRole(workspaceId, userId, role) {
756
- return operationsByTag.workspaces.updateWorkspaceMemberRole({
757
- pathParams: { workspaceId, userId },
758
- body: { role },
1290
+ getTableSchema({
1291
+ workspace,
1292
+ region,
1293
+ database,
1294
+ branch,
1295
+ table
1296
+ }) {
1297
+ return operationsByTag.table.getTableSchema({
1298
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
759
1299
  ...this.extraProps
760
1300
  });
761
1301
  }
762
- removeWorkspaceMember(workspaceId, userId) {
763
- return operationsByTag.workspaces.removeWorkspaceMember({
764
- pathParams: { workspaceId, userId },
1302
+ setTableSchema({
1303
+ workspace,
1304
+ region,
1305
+ database,
1306
+ branch,
1307
+ table,
1308
+ schema
1309
+ }) {
1310
+ return operationsByTag.table.setTableSchema({
1311
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1312
+ body: schema,
765
1313
  ...this.extraProps
766
1314
  });
767
1315
  }
768
- inviteWorkspaceMember(workspaceId, email, role) {
769
- return operationsByTag.workspaces.inviteWorkspaceMember({
770
- pathParams: { workspaceId },
771
- body: { email, role },
1316
+ getTableColumns({
1317
+ workspace,
1318
+ region,
1319
+ database,
1320
+ branch,
1321
+ table
1322
+ }) {
1323
+ return operationsByTag.table.getTableColumns({
1324
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
772
1325
  ...this.extraProps
773
1326
  });
774
1327
  }
775
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
776
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
777
- pathParams: { workspaceId, inviteId },
778
- body: { role },
1328
+ addTableColumn({
1329
+ workspace,
1330
+ region,
1331
+ database,
1332
+ branch,
1333
+ table,
1334
+ column
1335
+ }) {
1336
+ return operationsByTag.table.addTableColumn({
1337
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1338
+ body: column,
779
1339
  ...this.extraProps
780
1340
  });
781
1341
  }
782
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
783
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
784
- pathParams: { workspaceId, inviteId },
1342
+ getColumn({
1343
+ workspace,
1344
+ region,
1345
+ database,
1346
+ branch,
1347
+ table,
1348
+ column
1349
+ }) {
1350
+ return operationsByTag.table.getColumn({
1351
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
785
1352
  ...this.extraProps
786
1353
  });
787
1354
  }
788
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
789
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
790
- pathParams: { workspaceId, inviteId },
1355
+ updateColumn({
1356
+ workspace,
1357
+ region,
1358
+ database,
1359
+ branch,
1360
+ table,
1361
+ column,
1362
+ update
1363
+ }) {
1364
+ return operationsByTag.table.updateColumn({
1365
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1366
+ body: update,
791
1367
  ...this.extraProps
792
1368
  });
793
1369
  }
794
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
795
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
796
- pathParams: { workspaceId, inviteKey },
1370
+ deleteColumn({
1371
+ workspace,
1372
+ region,
1373
+ database,
1374
+ branch,
1375
+ table,
1376
+ column
1377
+ }) {
1378
+ return operationsByTag.table.deleteColumn({
1379
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
797
1380
  ...this.extraProps
798
1381
  });
799
1382
  }
800
1383
  }
801
- class DatabaseApi {
1384
+ class RecordsApi {
802
1385
  constructor(extraProps) {
803
1386
  this.extraProps = extraProps;
804
1387
  }
805
- getDatabaseList(workspace) {
806
- return operationsByTag.database.getDatabaseList({
807
- pathParams: { workspace },
1388
+ insertRecord({
1389
+ workspace,
1390
+ region,
1391
+ database,
1392
+ branch,
1393
+ table,
1394
+ record,
1395
+ columns
1396
+ }) {
1397
+ return operationsByTag.records.insertRecord({
1398
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1399
+ queryParams: { columns },
1400
+ body: record,
808
1401
  ...this.extraProps
809
1402
  });
810
1403
  }
811
- createDatabase(workspace, dbName, options = {}) {
812
- return operationsByTag.database.createDatabase({
813
- pathParams: { workspace, dbName },
814
- body: options,
1404
+ getRecord({
1405
+ workspace,
1406
+ region,
1407
+ database,
1408
+ branch,
1409
+ table,
1410
+ id,
1411
+ columns
1412
+ }) {
1413
+ return operationsByTag.records.getRecord({
1414
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1415
+ queryParams: { columns },
815
1416
  ...this.extraProps
816
1417
  });
817
1418
  }
818
- deleteDatabase(workspace, dbName) {
819
- return operationsByTag.database.deleteDatabase({
820
- pathParams: { workspace, dbName },
1419
+ insertRecordWithID({
1420
+ workspace,
1421
+ region,
1422
+ database,
1423
+ branch,
1424
+ table,
1425
+ id,
1426
+ record,
1427
+ columns,
1428
+ createOnly,
1429
+ ifVersion
1430
+ }) {
1431
+ return operationsByTag.records.insertRecordWithID({
1432
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1433
+ queryParams: { columns, createOnly, ifVersion },
1434
+ body: record,
821
1435
  ...this.extraProps
822
1436
  });
823
1437
  }
824
- getDatabaseMetadata(workspace, dbName) {
825
- return operationsByTag.database.getDatabaseMetadata({
826
- pathParams: { workspace, dbName },
1438
+ updateRecordWithID({
1439
+ workspace,
1440
+ region,
1441
+ database,
1442
+ branch,
1443
+ table,
1444
+ id,
1445
+ record,
1446
+ columns,
1447
+ ifVersion
1448
+ }) {
1449
+ return operationsByTag.records.updateRecordWithID({
1450
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1451
+ queryParams: { columns, ifVersion },
1452
+ body: record,
827
1453
  ...this.extraProps
828
1454
  });
829
1455
  }
830
- getGitBranchesMapping(workspace, dbName) {
831
- return operationsByTag.database.getGitBranchesMapping({
832
- pathParams: { workspace, dbName },
1456
+ upsertRecordWithID({
1457
+ workspace,
1458
+ region,
1459
+ database,
1460
+ branch,
1461
+ table,
1462
+ id,
1463
+ record,
1464
+ columns,
1465
+ ifVersion
1466
+ }) {
1467
+ return operationsByTag.records.upsertRecordWithID({
1468
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1469
+ queryParams: { columns, ifVersion },
1470
+ body: record,
833
1471
  ...this.extraProps
834
1472
  });
835
1473
  }
836
- addGitBranchesEntry(workspace, dbName, body) {
837
- return operationsByTag.database.addGitBranchesEntry({
838
- pathParams: { workspace, dbName },
839
- body,
1474
+ deleteRecord({
1475
+ workspace,
1476
+ region,
1477
+ database,
1478
+ branch,
1479
+ table,
1480
+ id,
1481
+ columns
1482
+ }) {
1483
+ return operationsByTag.records.deleteRecord({
1484
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1485
+ queryParams: { columns },
840
1486
  ...this.extraProps
841
1487
  });
842
1488
  }
843
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
844
- return operationsByTag.database.removeGitBranchesEntry({
845
- pathParams: { workspace, dbName },
846
- queryParams: { gitBranch },
1489
+ bulkInsertTableRecords({
1490
+ workspace,
1491
+ region,
1492
+ database,
1493
+ branch,
1494
+ table,
1495
+ records,
1496
+ columns
1497
+ }) {
1498
+ return operationsByTag.records.bulkInsertTableRecords({
1499
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1500
+ queryParams: { columns },
1501
+ body: { records },
847
1502
  ...this.extraProps
848
1503
  });
849
1504
  }
850
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
851
- return operationsByTag.database.resolveBranch({
852
- pathParams: { workspace, dbName },
853
- queryParams: { gitBranch, fallbackBranch },
1505
+ branchTransaction({
1506
+ workspace,
1507
+ region,
1508
+ database,
1509
+ branch,
1510
+ operations
1511
+ }) {
1512
+ return operationsByTag.records.branchTransaction({
1513
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1514
+ body: { operations },
854
1515
  ...this.extraProps
855
1516
  });
856
1517
  }
857
1518
  }
858
- class BranchApi {
1519
+ class SearchAndFilterApi {
859
1520
  constructor(extraProps) {
860
1521
  this.extraProps = extraProps;
861
1522
  }
862
- getBranchList(workspace, dbName) {
863
- return operationsByTag.branch.getBranchList({
864
- pathParams: { workspace, dbName },
1523
+ queryTable({
1524
+ workspace,
1525
+ region,
1526
+ database,
1527
+ branch,
1528
+ table,
1529
+ filter,
1530
+ sort,
1531
+ page,
1532
+ columns,
1533
+ consistency
1534
+ }) {
1535
+ return operationsByTag.searchAndFilter.queryTable({
1536
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1537
+ body: { filter, sort, page, columns, consistency },
865
1538
  ...this.extraProps
866
1539
  });
867
1540
  }
868
- getBranchDetails(workspace, database, branch) {
869
- return operationsByTag.branch.getBranchDetails({
870
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1541
+ searchTable({
1542
+ workspace,
1543
+ region,
1544
+ database,
1545
+ branch,
1546
+ table,
1547
+ query,
1548
+ fuzziness,
1549
+ target,
1550
+ prefix,
1551
+ filter,
1552
+ highlight,
1553
+ boosters
1554
+ }) {
1555
+ return operationsByTag.searchAndFilter.searchTable({
1556
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1557
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
871
1558
  ...this.extraProps
872
1559
  });
873
1560
  }
874
- createBranch(workspace, database, branch, from, options = {}) {
875
- return operationsByTag.branch.createBranch({
876
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
877
- queryParams: isString(from) ? { from } : void 0,
878
- body: options,
1561
+ searchBranch({
1562
+ workspace,
1563
+ region,
1564
+ database,
1565
+ branch,
1566
+ tables,
1567
+ query,
1568
+ fuzziness,
1569
+ prefix,
1570
+ highlight
1571
+ }) {
1572
+ return operationsByTag.searchAndFilter.searchBranch({
1573
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1574
+ body: { tables, query, fuzziness, prefix, highlight },
879
1575
  ...this.extraProps
880
1576
  });
881
1577
  }
882
- deleteBranch(workspace, database, branch) {
883
- return operationsByTag.branch.deleteBranch({
884
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1578
+ summarizeTable({
1579
+ workspace,
1580
+ region,
1581
+ database,
1582
+ branch,
1583
+ table,
1584
+ filter,
1585
+ columns,
1586
+ summaries,
1587
+ sort,
1588
+ summariesFilter,
1589
+ page,
1590
+ consistency
1591
+ }) {
1592
+ return operationsByTag.searchAndFilter.summarizeTable({
1593
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1594
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
885
1595
  ...this.extraProps
886
1596
  });
887
1597
  }
888
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
889
- return operationsByTag.branch.updateBranchMetadata({
890
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
891
- body: metadata,
1598
+ aggregateTable({
1599
+ workspace,
1600
+ region,
1601
+ database,
1602
+ branch,
1603
+ table,
1604
+ filter,
1605
+ aggs
1606
+ }) {
1607
+ return operationsByTag.searchAndFilter.aggregateTable({
1608
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1609
+ body: { filter, aggs },
892
1610
  ...this.extraProps
893
1611
  });
894
1612
  }
895
- getBranchMetadata(workspace, database, branch) {
896
- return operationsByTag.branch.getBranchMetadata({
897
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1613
+ }
1614
+ class MigrationRequestsApi {
1615
+ constructor(extraProps) {
1616
+ this.extraProps = extraProps;
1617
+ }
1618
+ queryMigrationRequests({
1619
+ workspace,
1620
+ region,
1621
+ database,
1622
+ filter,
1623
+ sort,
1624
+ page,
1625
+ columns
1626
+ }) {
1627
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1628
+ pathParams: { workspace, region, dbName: database },
1629
+ body: { filter, sort, page, columns },
898
1630
  ...this.extraProps
899
1631
  });
900
1632
  }
901
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
902
- return operationsByTag.branch.getBranchMigrationHistory({
903
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
904
- body: options,
1633
+ createMigrationRequest({
1634
+ workspace,
1635
+ region,
1636
+ database,
1637
+ migration
1638
+ }) {
1639
+ return operationsByTag.migrationRequests.createMigrationRequest({
1640
+ pathParams: { workspace, region, dbName: database },
1641
+ body: migration,
905
1642
  ...this.extraProps
906
1643
  });
907
1644
  }
908
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
909
- return operationsByTag.branch.executeBranchMigrationPlan({
910
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
911
- body: migrationPlan,
1645
+ getMigrationRequest({
1646
+ workspace,
1647
+ region,
1648
+ database,
1649
+ migrationRequest
1650
+ }) {
1651
+ return operationsByTag.migrationRequests.getMigrationRequest({
1652
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
912
1653
  ...this.extraProps
913
1654
  });
914
1655
  }
915
- getBranchMigrationPlan(workspace, database, branch, schema) {
916
- return operationsByTag.branch.getBranchMigrationPlan({
917
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
918
- body: schema,
1656
+ updateMigrationRequest({
1657
+ workspace,
1658
+ region,
1659
+ database,
1660
+ migrationRequest,
1661
+ update
1662
+ }) {
1663
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1664
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1665
+ body: update,
919
1666
  ...this.extraProps
920
1667
  });
921
1668
  }
922
- getBranchStats(workspace, database, branch) {
923
- return operationsByTag.branch.getBranchStats({
924
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1669
+ listMigrationRequestsCommits({
1670
+ workspace,
1671
+ region,
1672
+ database,
1673
+ migrationRequest,
1674
+ page
1675
+ }) {
1676
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1677
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1678
+ body: { page },
925
1679
  ...this.extraProps
926
1680
  });
927
1681
  }
928
- }
929
- class TableApi {
930
- constructor(extraProps) {
931
- this.extraProps = extraProps;
1682
+ compareMigrationRequest({
1683
+ workspace,
1684
+ region,
1685
+ database,
1686
+ migrationRequest
1687
+ }) {
1688
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1689
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1690
+ ...this.extraProps
1691
+ });
932
1692
  }
933
- createTable(workspace, database, branch, tableName) {
934
- return operationsByTag.table.createTable({
935
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1693
+ getMigrationRequestIsMerged({
1694
+ workspace,
1695
+ region,
1696
+ database,
1697
+ migrationRequest
1698
+ }) {
1699
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1700
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
936
1701
  ...this.extraProps
937
1702
  });
938
1703
  }
939
- deleteTable(workspace, database, branch, tableName) {
940
- return operationsByTag.table.deleteTable({
941
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1704
+ mergeMigrationRequest({
1705
+ workspace,
1706
+ region,
1707
+ database,
1708
+ migrationRequest
1709
+ }) {
1710
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1711
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
942
1712
  ...this.extraProps
943
1713
  });
944
1714
  }
945
- updateTable(workspace, database, branch, tableName, options) {
946
- return operationsByTag.table.updateTable({
947
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
948
- body: options,
1715
+ }
1716
+ class MigrationsApi {
1717
+ constructor(extraProps) {
1718
+ this.extraProps = extraProps;
1719
+ }
1720
+ getBranchMigrationHistory({
1721
+ workspace,
1722
+ region,
1723
+ database,
1724
+ branch,
1725
+ limit,
1726
+ startFrom
1727
+ }) {
1728
+ return operationsByTag.migrations.getBranchMigrationHistory({
1729
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1730
+ body: { limit, startFrom },
949
1731
  ...this.extraProps
950
1732
  });
951
1733
  }
952
- getTableSchema(workspace, database, branch, tableName) {
953
- return operationsByTag.table.getTableSchema({
954
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1734
+ getBranchMigrationPlan({
1735
+ workspace,
1736
+ region,
1737
+ database,
1738
+ branch,
1739
+ schema
1740
+ }) {
1741
+ return operationsByTag.migrations.getBranchMigrationPlan({
1742
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1743
+ body: schema,
955
1744
  ...this.extraProps
956
1745
  });
957
1746
  }
958
- setTableSchema(workspace, database, branch, tableName, options) {
959
- return operationsByTag.table.setTableSchema({
960
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
961
- body: options,
1747
+ executeBranchMigrationPlan({
1748
+ workspace,
1749
+ region,
1750
+ database,
1751
+ branch,
1752
+ plan
1753
+ }) {
1754
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1755
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1756
+ body: plan,
962
1757
  ...this.extraProps
963
1758
  });
964
1759
  }
965
- getTableColumns(workspace, database, branch, tableName) {
966
- return operationsByTag.table.getTableColumns({
967
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1760
+ getBranchSchemaHistory({
1761
+ workspace,
1762
+ region,
1763
+ database,
1764
+ branch,
1765
+ page
1766
+ }) {
1767
+ return operationsByTag.migrations.getBranchSchemaHistory({
1768
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1769
+ body: { page },
968
1770
  ...this.extraProps
969
1771
  });
970
1772
  }
971
- addTableColumn(workspace, database, branch, tableName, column) {
972
- return operationsByTag.table.addTableColumn({
973
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
974
- body: column,
1773
+ compareBranchWithUserSchema({
1774
+ workspace,
1775
+ region,
1776
+ database,
1777
+ branch,
1778
+ schema,
1779
+ schemaOperations,
1780
+ branchOperations
1781
+ }) {
1782
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1783
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1784
+ body: { schema, schemaOperations, branchOperations },
975
1785
  ...this.extraProps
976
1786
  });
977
1787
  }
978
- getColumn(workspace, database, branch, tableName, columnName) {
979
- return operationsByTag.table.getColumn({
980
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1788
+ compareBranchSchemas({
1789
+ workspace,
1790
+ region,
1791
+ database,
1792
+ branch,
1793
+ compare,
1794
+ sourceBranchOperations,
1795
+ targetBranchOperations
1796
+ }) {
1797
+ return operationsByTag.migrations.compareBranchSchemas({
1798
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1799
+ body: { sourceBranchOperations, targetBranchOperations },
981
1800
  ...this.extraProps
982
1801
  });
983
1802
  }
984
- deleteColumn(workspace, database, branch, tableName, columnName) {
985
- return operationsByTag.table.deleteColumn({
986
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1803
+ updateBranchSchema({
1804
+ workspace,
1805
+ region,
1806
+ database,
1807
+ branch,
1808
+ migration
1809
+ }) {
1810
+ return operationsByTag.migrations.updateBranchSchema({
1811
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1812
+ body: migration,
987
1813
  ...this.extraProps
988
1814
  });
989
1815
  }
990
- updateColumn(workspace, database, branch, tableName, columnName, options) {
991
- return operationsByTag.table.updateColumn({
992
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
993
- body: options,
1816
+ previewBranchSchemaEdit({
1817
+ workspace,
1818
+ region,
1819
+ database,
1820
+ branch,
1821
+ data
1822
+ }) {
1823
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1824
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1825
+ body: data,
1826
+ ...this.extraProps
1827
+ });
1828
+ }
1829
+ applyBranchSchemaEdit({
1830
+ workspace,
1831
+ region,
1832
+ database,
1833
+ branch,
1834
+ edits
1835
+ }) {
1836
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1837
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1838
+ body: { edits },
994
1839
  ...this.extraProps
995
1840
  });
996
1841
  }
997
1842
  }
998
- class RecordsApi {
1843
+ class DatabaseApi {
999
1844
  constructor(extraProps) {
1000
1845
  this.extraProps = extraProps;
1001
1846
  }
1002
- insertRecord(workspace, database, branch, tableName, record, options = {}) {
1003
- return operationsByTag.records.insertRecord({
1004
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1005
- queryParams: options,
1006
- body: record,
1007
- ...this.extraProps
1008
- });
1009
- }
1010
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1011
- return operationsByTag.records.insertRecordWithID({
1012
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1013
- queryParams: options,
1014
- body: record,
1847
+ getDatabaseList({ workspace }) {
1848
+ return operationsByTag.databases.getDatabaseList({
1849
+ pathParams: { workspaceId: workspace },
1015
1850
  ...this.extraProps
1016
1851
  });
1017
1852
  }
1018
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1019
- return operationsByTag.records.updateRecordWithID({
1020
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1021
- queryParams: options,
1022
- body: record,
1853
+ createDatabase({
1854
+ workspace,
1855
+ database,
1856
+ data
1857
+ }) {
1858
+ return operationsByTag.databases.createDatabase({
1859
+ pathParams: { workspaceId: workspace, dbName: database },
1860
+ body: data,
1023
1861
  ...this.extraProps
1024
1862
  });
1025
1863
  }
1026
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1027
- return operationsByTag.records.upsertRecordWithID({
1028
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1029
- queryParams: options,
1030
- body: record,
1864
+ deleteDatabase({
1865
+ workspace,
1866
+ database
1867
+ }) {
1868
+ return operationsByTag.databases.deleteDatabase({
1869
+ pathParams: { workspaceId: workspace, dbName: database },
1031
1870
  ...this.extraProps
1032
1871
  });
1033
1872
  }
1034
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
1035
- return operationsByTag.records.deleteRecord({
1036
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1037
- queryParams: options,
1873
+ getDatabaseMetadata({
1874
+ workspace,
1875
+ database
1876
+ }) {
1877
+ return operationsByTag.databases.getDatabaseMetadata({
1878
+ pathParams: { workspaceId: workspace, dbName: database },
1038
1879
  ...this.extraProps
1039
1880
  });
1040
1881
  }
1041
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
1042
- return operationsByTag.records.getRecord({
1043
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1044
- queryParams: options,
1882
+ updateDatabaseMetadata({
1883
+ workspace,
1884
+ database,
1885
+ metadata
1886
+ }) {
1887
+ return operationsByTag.databases.updateDatabaseMetadata({
1888
+ pathParams: { workspaceId: workspace, dbName: database },
1889
+ body: metadata,
1045
1890
  ...this.extraProps
1046
1891
  });
1047
1892
  }
1048
- bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
1049
- return operationsByTag.records.bulkInsertTableRecords({
1050
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1051
- queryParams: options,
1052
- body: { records },
1893
+ getDatabaseGithubSettings({
1894
+ workspace,
1895
+ database
1896
+ }) {
1897
+ return operationsByTag.databases.getDatabaseGithubSettings({
1898
+ pathParams: { workspaceId: workspace, dbName: database },
1053
1899
  ...this.extraProps
1054
1900
  });
1055
1901
  }
1056
- queryTable(workspace, database, branch, tableName, query) {
1057
- return operationsByTag.records.queryTable({
1058
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1059
- body: query,
1902
+ updateDatabaseGithubSettings({
1903
+ workspace,
1904
+ database,
1905
+ settings
1906
+ }) {
1907
+ return operationsByTag.databases.updateDatabaseGithubSettings({
1908
+ pathParams: { workspaceId: workspace, dbName: database },
1909
+ body: settings,
1060
1910
  ...this.extraProps
1061
1911
  });
1062
1912
  }
1063
- searchTable(workspace, database, branch, tableName, query) {
1064
- return operationsByTag.records.searchTable({
1065
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1066
- body: query,
1913
+ deleteDatabaseGithubSettings({
1914
+ workspace,
1915
+ database
1916
+ }) {
1917
+ return operationsByTag.databases.deleteDatabaseGithubSettings({
1918
+ pathParams: { workspaceId: workspace, dbName: database },
1067
1919
  ...this.extraProps
1068
1920
  });
1069
1921
  }
1070
- searchBranch(workspace, database, branch, query) {
1071
- return operationsByTag.records.searchBranch({
1072
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1073
- body: query,
1922
+ listRegions({ workspace }) {
1923
+ return operationsByTag.databases.listRegions({
1924
+ pathParams: { workspaceId: workspace },
1074
1925
  ...this.extraProps
1075
1926
  });
1076
1927
  }
@@ -1086,6 +1937,13 @@ class XataApiPlugin {
1086
1937
  class XataPlugin {
1087
1938
  }
1088
1939
 
1940
+ function cleanFilter(filter) {
1941
+ if (!filter)
1942
+ return void 0;
1943
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1944
+ return values.length > 0 ? filter : void 0;
1945
+ }
1946
+
1089
1947
  var __accessCheck$6 = (obj, member, msg) => {
1090
1948
  if (!member.has(obj))
1091
1949
  throw TypeError("Cannot " + msg);
@@ -1118,11 +1976,11 @@ class Page {
1118
1976
  async previousPage(size, offset) {
1119
1977
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1120
1978
  }
1121
- async firstPage(size, offset) {
1122
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1979
+ async startPage(size, offset) {
1980
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1123
1981
  }
1124
- async lastPage(size, offset) {
1125
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1982
+ async endPage(size, offset) {
1983
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1126
1984
  }
1127
1985
  hasNextPage() {
1128
1986
  return this.meta.page.more;
@@ -1134,7 +1992,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1134
1992
  const PAGINATION_MAX_OFFSET = 800;
1135
1993
  const PAGINATION_DEFAULT_OFFSET = 0;
1136
1994
  function isCursorPaginationOptions(options) {
1137
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1995
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1138
1996
  }
1139
1997
  const _RecordArray = class extends Array {
1140
1998
  constructor(...args) {
@@ -1155,6 +2013,12 @@ const _RecordArray = class extends Array {
1155
2013
  toArray() {
1156
2014
  return new Array(...this);
1157
2015
  }
2016
+ toSerializable() {
2017
+ return JSON.parse(this.toString());
2018
+ }
2019
+ toString() {
2020
+ return JSON.stringify(this.toArray());
2021
+ }
1158
2022
  map(callbackfn, thisArg) {
1159
2023
  return this.toArray().map(callbackfn, thisArg);
1160
2024
  }
@@ -1166,12 +2030,12 @@ const _RecordArray = class extends Array {
1166
2030
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1167
2031
  return new _RecordArray(newPage);
1168
2032
  }
1169
- async firstPage(size, offset) {
1170
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
2033
+ async startPage(size, offset) {
2034
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1171
2035
  return new _RecordArray(newPage);
1172
2036
  }
1173
- async lastPage(size, offset) {
1174
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
2037
+ async endPage(size, offset) {
2038
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1175
2039
  return new _RecordArray(newPage);
1176
2040
  }
1177
2041
  hasNextPage() {
@@ -1199,9 +2063,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1199
2063
  setter ? setter.call(obj, value) : member.set(obj, value);
1200
2064
  return value;
1201
2065
  };
1202
- var _table$1, _repository, _data;
2066
+ var __privateMethod$3 = (obj, member, method) => {
2067
+ __accessCheck$5(obj, member, "access private method");
2068
+ return method;
2069
+ };
2070
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1203
2071
  const _Query = class {
1204
2072
  constructor(repository, table, data, rawParent) {
2073
+ __privateAdd$5(this, _cleanFilterConstraint);
1205
2074
  __privateAdd$5(this, _table$1, void 0);
1206
2075
  __privateAdd$5(this, _repository, void 0);
1207
2076
  __privateAdd$5(this, _data, { filter: {} });
@@ -1220,9 +2089,11 @@ const _Query = class {
1220
2089
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1221
2090
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1222
2091
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1223
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
2092
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2093
+ __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
1224
2094
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1225
2095
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2096
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1226
2097
  this.any = this.any.bind(this);
1227
2098
  this.all = this.all.bind(this);
1228
2099
  this.not = this.not.bind(this);
@@ -1258,11 +2129,14 @@ const _Query = class {
1258
2129
  }
1259
2130
  filter(a, b) {
1260
2131
  if (arguments.length === 1) {
1261
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
2132
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
2133
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
2134
+ }));
1262
2135
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1263
2136
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1264
2137
  } else {
1265
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
2138
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
2139
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1266
2140
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1267
2141
  }
1268
2142
  }
@@ -1300,11 +2174,20 @@ const _Query = class {
1300
2174
  }
1301
2175
  }
1302
2176
  async getMany(options = {}) {
1303
- const page = await this.getPaginated(options);
2177
+ const { pagination = {}, ...rest } = options;
2178
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
2179
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
2180
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
2181
+ const results = [...page.records];
2182
+ while (page.hasNextPage() && results.length < size) {
2183
+ page = await page.nextPage();
2184
+ results.push(...page.records);
2185
+ }
1304
2186
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1305
2187
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1306
2188
  }
1307
- return page.records;
2189
+ const array = new RecordArray(page, results.slice(0, size));
2190
+ return array;
1308
2191
  }
1309
2192
  async getAll(options = {}) {
1310
2193
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1318,19 +2201,35 @@ const _Query = class {
1318
2201
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1319
2202
  return records[0] ?? null;
1320
2203
  }
2204
+ async getFirstOrThrow(options = {}) {
2205
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2206
+ if (records[0] === void 0)
2207
+ throw new Error("No results found.");
2208
+ return records[0];
2209
+ }
2210
+ async summarize(params = {}) {
2211
+ const { summaries, summariesFilter, ...options } = params;
2212
+ const query = new _Query(
2213
+ __privateGet$5(this, _repository),
2214
+ __privateGet$5(this, _table$1),
2215
+ options,
2216
+ __privateGet$5(this, _data)
2217
+ );
2218
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2219
+ }
1321
2220
  cache(ttl) {
1322
2221
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1323
2222
  }
1324
2223
  nextPage(size, offset) {
1325
- return this.firstPage(size, offset);
2224
+ return this.startPage(size, offset);
1326
2225
  }
1327
2226
  previousPage(size, offset) {
1328
- return this.firstPage(size, offset);
2227
+ return this.startPage(size, offset);
1329
2228
  }
1330
- firstPage(size, offset) {
2229
+ startPage(size, offset) {
1331
2230
  return this.getPaginated({ pagination: { size, offset } });
1332
2231
  }
1333
- lastPage(size, offset) {
2232
+ endPage(size, offset) {
1334
2233
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1335
2234
  }
1336
2235
  hasNextPage() {
@@ -1341,9 +2240,20 @@ let Query = _Query;
1341
2240
  _table$1 = new WeakMap();
1342
2241
  _repository = new WeakMap();
1343
2242
  _data = new WeakMap();
2243
+ _cleanFilterConstraint = new WeakSet();
2244
+ cleanFilterConstraint_fn = function(column, value) {
2245
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2246
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2247
+ return { $includes: value };
2248
+ }
2249
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
2250
+ return value.id;
2251
+ }
2252
+ return value;
2253
+ };
1344
2254
  function cleanParent(data, parent) {
1345
2255
  if (isCursorPaginationOptions(data.pagination)) {
1346
- return { ...parent, sorting: void 0, filter: void 0 };
2256
+ return { ...parent, sort: void 0, filter: void 0 };
1347
2257
  }
1348
2258
  return parent;
1349
2259
  }
@@ -1402,18 +2312,25 @@ var __privateMethod$2 = (obj, member, method) => {
1402
2312
  __accessCheck$4(obj, member, "access private method");
1403
2313
  return method;
1404
2314
  };
1405
- var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
2315
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
2316
+ const BULK_OPERATION_MAX_SIZE = 1e3;
1406
2317
  class Repository extends Query {
1407
2318
  }
1408
2319
  class RestRepository extends Query {
1409
2320
  constructor(options) {
1410
- super(null, options.table, {});
2321
+ super(
2322
+ null,
2323
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
2324
+ {}
2325
+ );
1411
2326
  __privateAdd$4(this, _insertRecordWithoutId);
1412
2327
  __privateAdd$4(this, _insertRecordWithId);
1413
- __privateAdd$4(this, _bulkInsertTableRecords);
2328
+ __privateAdd$4(this, _insertRecords);
1414
2329
  __privateAdd$4(this, _updateRecordWithID);
2330
+ __privateAdd$4(this, _updateRecords);
1415
2331
  __privateAdd$4(this, _upsertRecordWithID);
1416
2332
  __privateAdd$4(this, _deleteRecord);
2333
+ __privateAdd$4(this, _deleteRecords);
1417
2334
  __privateAdd$4(this, _setCacheQuery);
1418
2335
  __privateAdd$4(this, _getCacheQuery);
1419
2336
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1424,38 +2341,45 @@ class RestRepository extends Query {
1424
2341
  __privateAdd$4(this, _schemaTables$2, void 0);
1425
2342
  __privateAdd$4(this, _trace, void 0);
1426
2343
  __privateSet$4(this, _table, options.table);
1427
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1428
2344
  __privateSet$4(this, _db, options.db);
1429
2345
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1430
2346
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2347
+ __privateSet$4(this, _getFetchProps, async () => {
2348
+ const props = await options.pluginOptions.getFetchProps();
2349
+ return { ...props, sessionID: generateUUID() };
2350
+ });
1431
2351
  const trace = options.pluginOptions.trace ?? defaultTrace;
1432
2352
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1433
2353
  return trace(name, fn, {
1434
2354
  ...options2,
1435
2355
  [TraceAttributes.TABLE]: __privateGet$4(this, _table),
2356
+ [TraceAttributes.KIND]: "sdk-operation",
1436
2357
  [TraceAttributes.VERSION]: VERSION
1437
2358
  });
1438
2359
  });
1439
2360
  }
1440
- async create(a, b, c) {
2361
+ async create(a, b, c, d) {
1441
2362
  return __privateGet$4(this, _trace).call(this, "create", async () => {
2363
+ const ifVersion = parseIfVersion(b, c, d);
1442
2364
  if (Array.isArray(a)) {
1443
2365
  if (a.length === 0)
1444
2366
  return [];
1445
- const columns = isStringArray(b) ? b : void 0;
1446
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2367
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2368
+ const columns = isStringArray(b) ? b : ["*"];
2369
+ const result = await this.read(ids, columns);
2370
+ return result;
1447
2371
  }
1448
2372
  if (isString(a) && isObject(b)) {
1449
2373
  if (a === "")
1450
2374
  throw new Error("The id can't be empty");
1451
2375
  const columns = isStringArray(c) ? c : void 0;
1452
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
2376
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
1453
2377
  }
1454
2378
  if (isObject(a) && isString(a.id)) {
1455
2379
  if (a.id === "")
1456
2380
  throw new Error("The id can't be empty");
1457
2381
  const columns = isStringArray(b) ? b : void 0;
1458
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2382
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
1459
2383
  }
1460
2384
  if (isObject(a)) {
1461
2385
  const columns = isStringArray(b) ? b : void 0;
@@ -1486,6 +2410,7 @@ class RestRepository extends Query {
1486
2410
  pathParams: {
1487
2411
  workspace: "{workspaceId}",
1488
2412
  dbBranchName: "{dbBranch}",
2413
+ region: "{region}",
1489
2414
  tableName: __privateGet$4(this, _table),
1490
2415
  recordId: id
1491
2416
  },
@@ -1493,7 +2418,7 @@ class RestRepository extends Query {
1493
2418
  ...fetchProps
1494
2419
  });
1495
2420
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1496
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2421
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1497
2422
  } catch (e) {
1498
2423
  if (isObject(e) && e.status === 404) {
1499
2424
  return null;
@@ -1504,48 +2429,122 @@ class RestRepository extends Query {
1504
2429
  return null;
1505
2430
  });
1506
2431
  }
1507
- async update(a, b, c) {
2432
+ async readOrThrow(a, b) {
2433
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
2434
+ const result = await this.read(a, b);
2435
+ if (Array.isArray(result)) {
2436
+ const missingIds = compact(
2437
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2438
+ );
2439
+ if (missingIds.length > 0) {
2440
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2441
+ }
2442
+ return result;
2443
+ }
2444
+ if (result === null) {
2445
+ const id = extractId(a) ?? "unknown";
2446
+ throw new Error(`Record with id ${id} not found`);
2447
+ }
2448
+ return result;
2449
+ });
2450
+ }
2451
+ async update(a, b, c, d) {
1508
2452
  return __privateGet$4(this, _trace).call(this, "update", async () => {
2453
+ const ifVersion = parseIfVersion(b, c, d);
1509
2454
  if (Array.isArray(a)) {
1510
2455
  if (a.length === 0)
1511
2456
  return [];
1512
- if (a.length > 100) {
1513
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2457
+ const existing = await this.read(a, ["id"]);
2458
+ const updates = a.filter((_item, index) => existing[index] !== null);
2459
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2460
+ ifVersion,
2461
+ upsert: false
2462
+ });
2463
+ const columns = isStringArray(b) ? b : ["*"];
2464
+ const result = await this.read(a, columns);
2465
+ return result;
2466
+ }
2467
+ try {
2468
+ if (isString(a) && isObject(b)) {
2469
+ const columns = isStringArray(c) ? c : void 0;
2470
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2471
+ }
2472
+ if (isObject(a) && isString(a.id)) {
2473
+ const columns = isStringArray(b) ? b : void 0;
2474
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2475
+ }
2476
+ } catch (error) {
2477
+ if (error.status === 422)
2478
+ return null;
2479
+ throw error;
2480
+ }
2481
+ throw new Error("Invalid arguments for update method");
2482
+ });
2483
+ }
2484
+ async updateOrThrow(a, b, c, d) {
2485
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
2486
+ const result = await this.update(a, b, c, d);
2487
+ if (Array.isArray(result)) {
2488
+ const missingIds = compact(
2489
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2490
+ );
2491
+ if (missingIds.length > 0) {
2492
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1514
2493
  }
2494
+ return result;
2495
+ }
2496
+ if (result === null) {
2497
+ const id = extractId(a) ?? "unknown";
2498
+ throw new Error(`Record with id ${id} not found`);
2499
+ }
2500
+ return result;
2501
+ });
2502
+ }
2503
+ async createOrUpdate(a, b, c, d) {
2504
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2505
+ const ifVersion = parseIfVersion(b, c, d);
2506
+ if (Array.isArray(a)) {
2507
+ if (a.length === 0)
2508
+ return [];
2509
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2510
+ ifVersion,
2511
+ upsert: true
2512
+ });
1515
2513
  const columns = isStringArray(b) ? b : ["*"];
1516
- return Promise.all(a.map((object) => this.update(object, columns)));
2514
+ const result = await this.read(a, columns);
2515
+ return result;
1517
2516
  }
1518
2517
  if (isString(a) && isObject(b)) {
1519
2518
  const columns = isStringArray(c) ? c : void 0;
1520
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
2519
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1521
2520
  }
1522
2521
  if (isObject(a) && isString(a.id)) {
1523
- const columns = isStringArray(b) ? b : void 0;
1524
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2522
+ const columns = isStringArray(c) ? c : void 0;
2523
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1525
2524
  }
1526
- throw new Error("Invalid arguments for update method");
2525
+ throw new Error("Invalid arguments for createOrUpdate method");
1527
2526
  });
1528
2527
  }
1529
- async createOrUpdate(a, b, c) {
1530
- return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2528
+ async createOrReplace(a, b, c, d) {
2529
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2530
+ const ifVersion = parseIfVersion(b, c, d);
1531
2531
  if (Array.isArray(a)) {
1532
2532
  if (a.length === 0)
1533
2533
  return [];
1534
- if (a.length > 100) {
1535
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1536
- }
2534
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
1537
2535
  const columns = isStringArray(b) ? b : ["*"];
1538
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
2536
+ const result = await this.read(ids, columns);
2537
+ return result;
1539
2538
  }
1540
2539
  if (isString(a) && isObject(b)) {
1541
2540
  const columns = isStringArray(c) ? c : void 0;
1542
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
2541
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
1543
2542
  }
1544
2543
  if (isObject(a) && isString(a.id)) {
1545
2544
  const columns = isStringArray(c) ? c : void 0;
1546
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2545
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
1547
2546
  }
1548
- throw new Error("Invalid arguments for createOrUpdate method");
2547
+ throw new Error("Invalid arguments for createOrReplace method");
1549
2548
  });
1550
2549
  }
1551
2550
  async delete(a, b) {
@@ -1553,10 +2552,17 @@ class RestRepository extends Query {
1553
2552
  if (Array.isArray(a)) {
1554
2553
  if (a.length === 0)
1555
2554
  return [];
1556
- if (a.length > 100) {
1557
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1558
- }
1559
- return Promise.all(a.map((id) => this.delete(id, b)));
2555
+ const ids = a.map((o) => {
2556
+ if (isString(o))
2557
+ return o;
2558
+ if (isString(o.id))
2559
+ return o.id;
2560
+ throw new Error("Invalid arguments for delete method");
2561
+ });
2562
+ const columns = isStringArray(b) ? b : ["*"];
2563
+ const result = await this.read(a, columns);
2564
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2565
+ return result;
1560
2566
  }
1561
2567
  if (isString(a)) {
1562
2568
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
@@ -1567,23 +2573,87 @@ class RestRepository extends Query {
1567
2573
  throw new Error("Invalid arguments for delete method");
1568
2574
  });
1569
2575
  }
2576
+ async deleteOrThrow(a, b) {
2577
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
2578
+ const result = await this.delete(a, b);
2579
+ if (Array.isArray(result)) {
2580
+ const missingIds = compact(
2581
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2582
+ );
2583
+ if (missingIds.length > 0) {
2584
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2585
+ }
2586
+ return result;
2587
+ } else if (result === null) {
2588
+ const id = extractId(a) ?? "unknown";
2589
+ throw new Error(`Record with id ${id} not found`);
2590
+ }
2591
+ return result;
2592
+ });
2593
+ }
1570
2594
  async search(query, options = {}) {
1571
2595
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1572
2596
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1573
2597
  const { records } = await searchTable({
1574
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2598
+ pathParams: {
2599
+ workspace: "{workspaceId}",
2600
+ dbBranchName: "{dbBranch}",
2601
+ region: "{region}",
2602
+ tableName: __privateGet$4(this, _table)
2603
+ },
1575
2604
  body: {
1576
2605
  query,
1577
2606
  fuzziness: options.fuzziness,
1578
2607
  prefix: options.prefix,
1579
2608
  highlight: options.highlight,
1580
2609
  filter: options.filter,
1581
- boosters: options.boosters
2610
+ boosters: options.boosters,
2611
+ page: options.page,
2612
+ target: options.target
2613
+ },
2614
+ ...fetchProps
2615
+ });
2616
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2617
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2618
+ });
2619
+ }
2620
+ async vectorSearch(column, query, options) {
2621
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2622
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2623
+ const { records } = await vectorSearchTable({
2624
+ pathParams: {
2625
+ workspace: "{workspaceId}",
2626
+ dbBranchName: "{dbBranch}",
2627
+ region: "{region}",
2628
+ tableName: __privateGet$4(this, _table)
2629
+ },
2630
+ body: {
2631
+ column,
2632
+ queryVector: query,
2633
+ similarityFunction: options?.similarityFunction,
2634
+ size: options?.size,
2635
+ filter: options?.filter
1582
2636
  },
1583
2637
  ...fetchProps
1584
2638
  });
1585
2639
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1586
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2640
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2641
+ });
2642
+ }
2643
+ async aggregate(aggs, filter) {
2644
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2645
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2646
+ const result = await aggregateTable({
2647
+ pathParams: {
2648
+ workspace: "{workspaceId}",
2649
+ dbBranchName: "{dbBranch}",
2650
+ region: "{region}",
2651
+ tableName: __privateGet$4(this, _table)
2652
+ },
2653
+ body: { aggs, filter },
2654
+ ...fetchProps
2655
+ });
2656
+ return result;
1587
2657
  });
1588
2658
  }
1589
2659
  async query(query) {
@@ -1592,24 +2662,57 @@ class RestRepository extends Query {
1592
2662
  if (cacheQuery)
1593
2663
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1594
2664
  const data = query.getQueryOptions();
1595
- const body = {
1596
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1597
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1598
- page: data.pagination,
1599
- columns: data.columns
1600
- };
1601
2665
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1602
2666
  const { meta, records: objects } = await queryTable({
1603
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1604
- body,
2667
+ pathParams: {
2668
+ workspace: "{workspaceId}",
2669
+ dbBranchName: "{dbBranch}",
2670
+ region: "{region}",
2671
+ tableName: __privateGet$4(this, _table)
2672
+ },
2673
+ body: {
2674
+ filter: cleanFilter(data.filter),
2675
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2676
+ page: data.pagination,
2677
+ columns: data.columns ?? ["*"],
2678
+ consistency: data.consistency
2679
+ },
2680
+ fetchOptions: data.fetchOptions,
1605
2681
  ...fetchProps
1606
2682
  });
1607
2683
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1608
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
2684
+ const records = objects.map(
2685
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2686
+ );
1609
2687
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1610
2688
  return new Page(query, meta, records);
1611
2689
  });
1612
2690
  }
2691
+ async summarizeTable(query, summaries, summariesFilter) {
2692
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2693
+ const data = query.getQueryOptions();
2694
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2695
+ const result = await summarizeTable({
2696
+ pathParams: {
2697
+ workspace: "{workspaceId}",
2698
+ dbBranchName: "{dbBranch}",
2699
+ region: "{region}",
2700
+ tableName: __privateGet$4(this, _table)
2701
+ },
2702
+ body: {
2703
+ filter: cleanFilter(data.filter),
2704
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2705
+ columns: data.columns,
2706
+ consistency: data.consistency,
2707
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2708
+ summaries,
2709
+ summariesFilter
2710
+ },
2711
+ ...fetchProps
2712
+ });
2713
+ return result;
2714
+ });
2715
+ }
1613
2716
  }
1614
2717
  _table = new WeakMap();
1615
2718
  _getFetchProps = new WeakMap();
@@ -1625,6 +2728,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1625
2728
  pathParams: {
1626
2729
  workspace: "{workspaceId}",
1627
2730
  dbBranchName: "{dbBranch}",
2731
+ region: "{region}",
1628
2732
  tableName: __privateGet$4(this, _table)
1629
2733
  },
1630
2734
  queryParams: { columns },
@@ -1632,55 +2736,76 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1632
2736
  ...fetchProps
1633
2737
  });
1634
2738
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1635
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2739
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1636
2740
  };
1637
2741
  _insertRecordWithId = new WeakSet();
1638
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
2742
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
1639
2743
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1640
2744
  const record = transformObjectLinks(object);
1641
2745
  const response = await insertRecordWithID({
1642
2746
  pathParams: {
1643
2747
  workspace: "{workspaceId}",
1644
2748
  dbBranchName: "{dbBranch}",
2749
+ region: "{region}",
1645
2750
  tableName: __privateGet$4(this, _table),
1646
2751
  recordId
1647
2752
  },
1648
2753
  body: record,
1649
- queryParams: { createOnly: true, columns },
2754
+ queryParams: { createOnly, columns, ifVersion },
1650
2755
  ...fetchProps
1651
2756
  });
1652
2757
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1653
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2758
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1654
2759
  };
1655
- _bulkInsertTableRecords = new WeakSet();
1656
- bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
2760
+ _insertRecords = new WeakSet();
2761
+ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
1657
2762
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1658
- const records = objects.map((object) => transformObjectLinks(object));
1659
- const response = await bulkInsertTableRecords({
1660
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1661
- queryParams: { columns },
1662
- body: { records },
1663
- ...fetchProps
1664
- });
1665
- if (!isResponseWithRecords(response)) {
1666
- throw new Error("Request included columns but server didn't include them");
2763
+ const chunkedOperations = chunk(
2764
+ objects.map((object) => ({
2765
+ insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2766
+ })),
2767
+ BULK_OPERATION_MAX_SIZE
2768
+ );
2769
+ const ids = [];
2770
+ for (const operations of chunkedOperations) {
2771
+ const { results } = await branchTransaction({
2772
+ pathParams: {
2773
+ workspace: "{workspaceId}",
2774
+ dbBranchName: "{dbBranch}",
2775
+ region: "{region}"
2776
+ },
2777
+ body: { operations },
2778
+ ...fetchProps
2779
+ });
2780
+ for (const result of results) {
2781
+ if (result.operation === "insert") {
2782
+ ids.push(result.id);
2783
+ } else {
2784
+ ids.push(null);
2785
+ }
2786
+ }
1667
2787
  }
1668
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1669
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2788
+ return ids;
1670
2789
  };
1671
2790
  _updateRecordWithID = new WeakSet();
1672
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2791
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1673
2792
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1674
- const record = transformObjectLinks(object);
2793
+ const { id: _id, ...record } = transformObjectLinks(object);
1675
2794
  try {
1676
2795
  const response = await updateRecordWithID({
1677
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1678
- queryParams: { columns },
2796
+ pathParams: {
2797
+ workspace: "{workspaceId}",
2798
+ dbBranchName: "{dbBranch}",
2799
+ region: "{region}",
2800
+ tableName: __privateGet$4(this, _table),
2801
+ recordId
2802
+ },
2803
+ queryParams: { columns, ifVersion },
1679
2804
  body: record,
1680
2805
  ...fetchProps
1681
2806
  });
1682
2807
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1683
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2808
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1684
2809
  } catch (e) {
1685
2810
  if (isObject(e) && e.status === 404) {
1686
2811
  return null;
@@ -1688,29 +2813,71 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1688
2813
  throw e;
1689
2814
  }
1690
2815
  };
2816
+ _updateRecords = new WeakSet();
2817
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2818
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2819
+ const chunkedOperations = chunk(
2820
+ objects.map(({ id, ...object }) => ({
2821
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2822
+ })),
2823
+ BULK_OPERATION_MAX_SIZE
2824
+ );
2825
+ const ids = [];
2826
+ for (const operations of chunkedOperations) {
2827
+ const { results } = await branchTransaction({
2828
+ pathParams: {
2829
+ workspace: "{workspaceId}",
2830
+ dbBranchName: "{dbBranch}",
2831
+ region: "{region}"
2832
+ },
2833
+ body: { operations },
2834
+ ...fetchProps
2835
+ });
2836
+ for (const result of results) {
2837
+ if (result.operation === "update") {
2838
+ ids.push(result.id);
2839
+ } else {
2840
+ ids.push(null);
2841
+ }
2842
+ }
2843
+ }
2844
+ return ids;
2845
+ };
1691
2846
  _upsertRecordWithID = new WeakSet();
1692
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2847
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1693
2848
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1694
2849
  const response = await upsertRecordWithID({
1695
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1696
- queryParams: { columns },
2850
+ pathParams: {
2851
+ workspace: "{workspaceId}",
2852
+ dbBranchName: "{dbBranch}",
2853
+ region: "{region}",
2854
+ tableName: __privateGet$4(this, _table),
2855
+ recordId
2856
+ },
2857
+ queryParams: { columns, ifVersion },
1697
2858
  body: object,
1698
2859
  ...fetchProps
1699
2860
  });
1700
2861
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1701
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2862
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1702
2863
  };
1703
2864
  _deleteRecord = new WeakSet();
1704
2865
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
1705
2866
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1706
2867
  try {
1707
2868
  const response = await deleteRecord({
1708
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2869
+ pathParams: {
2870
+ workspace: "{workspaceId}",
2871
+ dbBranchName: "{dbBranch}",
2872
+ region: "{region}",
2873
+ tableName: __privateGet$4(this, _table),
2874
+ recordId
2875
+ },
1709
2876
  queryParams: { columns },
1710
2877
  ...fetchProps
1711
2878
  });
1712
2879
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1713
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2880
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1714
2881
  } catch (e) {
1715
2882
  if (isObject(e) && e.status === 404) {
1716
2883
  return null;
@@ -1718,6 +2885,25 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1718
2885
  throw e;
1719
2886
  }
1720
2887
  };
2888
+ _deleteRecords = new WeakSet();
2889
+ deleteRecords_fn = async function(recordIds) {
2890
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2891
+ const chunkedOperations = chunk(
2892
+ recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2893
+ BULK_OPERATION_MAX_SIZE
2894
+ );
2895
+ for (const operations of chunkedOperations) {
2896
+ await branchTransaction({
2897
+ pathParams: {
2898
+ workspace: "{workspaceId}",
2899
+ dbBranchName: "{dbBranch}",
2900
+ region: "{region}"
2901
+ },
2902
+ body: { operations },
2903
+ ...fetchProps
2904
+ });
2905
+ }
2906
+ };
1721
2907
  _setCacheQuery = new WeakSet();
1722
2908
  setCacheQuery_fn = async function(query, meta, records) {
1723
2909
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1740,7 +2926,7 @@ getSchemaTables_fn$1 = async function() {
1740
2926
  return __privateGet$4(this, _schemaTables$2);
1741
2927
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1742
2928
  const { schema } = await getBranchDetails({
1743
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2929
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1744
2930
  ...fetchProps
1745
2931
  });
1746
2932
  __privateSet$4(this, _schemaTables$2, schema.tables);
@@ -1753,22 +2939,24 @@ const transformObjectLinks = (object) => {
1753
2939
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1754
2940
  }, {});
1755
2941
  };
1756
- const initObject = (db, schemaTables, table, object) => {
1757
- const result = {};
2942
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2943
+ const data = {};
1758
2944
  const { xata, ...rest } = object ?? {};
1759
- Object.assign(result, rest);
2945
+ Object.assign(data, rest);
1760
2946
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1761
2947
  if (!columns)
1762
2948
  console.error(`Table ${table} not found in schema`);
1763
2949
  for (const column of columns ?? []) {
1764
- const value = result[column.name];
2950
+ if (!isValidColumn(selectedColumns, column))
2951
+ continue;
2952
+ const value = data[column.name];
1765
2953
  switch (column.type) {
1766
2954
  case "datetime": {
1767
- const date = value !== void 0 ? new Date(value) : void 0;
1768
- if (date && isNaN(date.getTime())) {
2955
+ const date = value !== void 0 ? new Date(value) : null;
2956
+ if (date !== null && isNaN(date.getTime())) {
1769
2957
  console.error(`Failed to parse date ${value} for field ${column.name}`);
1770
- } else if (date) {
1771
- result[column.name] = date;
2958
+ } else {
2959
+ data[column.name] = date;
1772
2960
  }
1773
2961
  break;
1774
2962
  }
@@ -1777,33 +2965,62 @@ const initObject = (db, schemaTables, table, object) => {
1777
2965
  if (!linkTable) {
1778
2966
  console.error(`Failed to parse link for field ${column.name}`);
1779
2967
  } else if (isObject(value)) {
1780
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2968
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2969
+ if (item === column.name) {
2970
+ return [...acc, "*"];
2971
+ }
2972
+ if (item.startsWith(`${column.name}.`)) {
2973
+ const [, ...path] = item.split(".");
2974
+ return [...acc, path.join(".")];
2975
+ }
2976
+ return acc;
2977
+ }, []);
2978
+ data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2979
+ } else {
2980
+ data[column.name] = null;
1781
2981
  }
1782
2982
  break;
1783
2983
  }
2984
+ default:
2985
+ data[column.name] = value ?? null;
2986
+ if (column.notNull === true && value === null) {
2987
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2988
+ }
2989
+ break;
1784
2990
  }
1785
2991
  }
1786
- result.read = function(columns2) {
1787
- return db[table].read(result["id"], columns2);
2992
+ const record = { ...data };
2993
+ record.read = function(columns2) {
2994
+ return db[table].read(record["id"], columns2);
1788
2995
  };
1789
- result.update = function(data, columns2) {
1790
- return db[table].update(result["id"], data, columns2);
2996
+ record.update = function(data2, b, c) {
2997
+ const columns2 = isStringArray(b) ? b : ["*"];
2998
+ const ifVersion = parseIfVersion(b, c);
2999
+ return db[table].update(record["id"], data2, columns2, { ifVersion });
1791
3000
  };
1792
- result.delete = function() {
1793
- return db[table].delete(result["id"]);
3001
+ record.replace = function(data2, b, c) {
3002
+ const columns2 = isStringArray(b) ? b : ["*"];
3003
+ const ifVersion = parseIfVersion(b, c);
3004
+ return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
1794
3005
  };
1795
- result.getMetadata = function() {
3006
+ record.delete = function() {
3007
+ return db[table].delete(record["id"]);
3008
+ };
3009
+ record.getMetadata = function() {
1796
3010
  return xata;
1797
3011
  };
1798
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
1799
- Object.defineProperty(result, prop, { enumerable: false });
3012
+ record.toSerializable = function() {
3013
+ return JSON.parse(JSON.stringify(transformObjectLinks(data)));
3014
+ };
3015
+ record.toString = function() {
3016
+ return JSON.stringify(transformObjectLinks(data));
3017
+ };
3018
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3019
+ Object.defineProperty(record, prop, { enumerable: false });
1800
3020
  }
1801
- Object.freeze(result);
1802
- return result;
3021
+ Object.freeze(record);
3022
+ return record;
1803
3023
  };
1804
- function isResponseWithRecords(value) {
1805
- return isObject(value) && Array.isArray(value.records);
1806
- }
1807
3024
  function extractId(value) {
1808
3025
  if (isString(value))
1809
3026
  return value;
@@ -1811,6 +3028,23 @@ function extractId(value) {
1811
3028
  return value.id;
1812
3029
  return void 0;
1813
3030
  }
3031
+ function isValidColumn(columns, column) {
3032
+ if (columns.includes("*"))
3033
+ return true;
3034
+ if (column.type === "link") {
3035
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
3036
+ return linkColumns.length > 0;
3037
+ }
3038
+ return columns.includes(column.name);
3039
+ }
3040
+ function parseIfVersion(...args) {
3041
+ for (const arg of args) {
3042
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
3043
+ return arg.ifVersion;
3044
+ }
3045
+ }
3046
+ return void 0;
3047
+ }
1814
3048
 
1815
3049
  var __accessCheck$3 = (obj, member, msg) => {
1816
3050
  if (!member.has(obj))
@@ -1976,7 +3210,7 @@ class SearchPlugin extends XataPlugin {
1976
3210
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1977
3211
  return records.map((record) => {
1978
3212
  const { table = "orphan" } = record.xata;
1979
- return { table, record: initObject(this.db, schemaTables, table, record) };
3213
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1980
3214
  });
1981
3215
  },
1982
3216
  byTable: async (query, options = {}) => {
@@ -1985,7 +3219,7 @@ class SearchPlugin extends XataPlugin {
1985
3219
  return records.reduce((acc, record) => {
1986
3220
  const { table = "orphan" } = record.xata;
1987
3221
  const items = acc[table] ?? [];
1988
- const item = initObject(this.db, schemaTables, table, record);
3222
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1989
3223
  return { ...acc, [table]: [...items, item] };
1990
3224
  }, {});
1991
3225
  }
@@ -1996,10 +3230,10 @@ _schemaTables = new WeakMap();
1996
3230
  _search = new WeakSet();
1997
3231
  search_fn = async function(query, options, getFetchProps) {
1998
3232
  const fetchProps = await getFetchProps();
1999
- const { tables, fuzziness, highlight, prefix } = options ?? {};
3233
+ const { tables, fuzziness, highlight, prefix, page } = options ?? {};
2000
3234
  const { records } = await searchBranch({
2001
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2002
- body: { tables, query, fuzziness, prefix, highlight },
3235
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3236
+ body: { tables, query, fuzziness, prefix, highlight, page },
2003
3237
  ...fetchProps
2004
3238
  });
2005
3239
  return records;
@@ -2010,25 +3244,37 @@ getSchemaTables_fn = async function(getFetchProps) {
2010
3244
  return __privateGet$1(this, _schemaTables);
2011
3245
  const fetchProps = await getFetchProps();
2012
3246
  const { schema } = await getBranchDetails({
2013
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
3247
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2014
3248
  ...fetchProps
2015
3249
  });
2016
3250
  __privateSet$1(this, _schemaTables, schema.tables);
2017
3251
  return schema.tables;
2018
3252
  };
2019
3253
 
3254
+ class TransactionPlugin extends XataPlugin {
3255
+ build({ getFetchProps }) {
3256
+ return {
3257
+ run: async (operations) => {
3258
+ const fetchProps = await getFetchProps();
3259
+ const response = await branchTransaction({
3260
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3261
+ body: { operations },
3262
+ ...fetchProps
3263
+ });
3264
+ return response;
3265
+ }
3266
+ };
3267
+ }
3268
+ }
3269
+
2020
3270
  const isBranchStrategyBuilder = (strategy) => {
2021
3271
  return typeof strategy === "function";
2022
3272
  };
2023
3273
 
2024
3274
  async function getCurrentBranchName(options) {
2025
3275
  const { branch, envBranch } = getEnvironment();
2026
- if (branch) {
2027
- const details = await getDatabaseBranch(branch, options);
2028
- if (details)
2029
- return branch;
2030
- console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
2031
- }
3276
+ if (branch)
3277
+ return branch;
2032
3278
  const gitBranch = envBranch || await getGitBranch();
2033
3279
  return resolveXataBranch(gitBranch, options);
2034
3280
  }
@@ -2048,16 +3294,21 @@ async function resolveXataBranch(gitBranch, options) {
2048
3294
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2049
3295
  );
2050
3296
  const [protocol, , host, , dbName] = databaseURL.split("/");
2051
- const [workspace] = host.split(".");
3297
+ const urlParts = parseWorkspacesUrlParts(host);
3298
+ if (!urlParts)
3299
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3300
+ const { workspace, region } = urlParts;
2052
3301
  const { fallbackBranch } = getEnvironment();
2053
3302
  const { branch } = await resolveBranch({
2054
3303
  apiKey,
2055
3304
  apiUrl: databaseURL,
2056
3305
  fetchImpl: getFetchImplementation(options?.fetchImpl),
2057
3306
  workspacesApiUrl: `${protocol}//${host}`,
2058
- pathParams: { dbName, workspace },
3307
+ pathParams: { dbName, workspace, region },
2059
3308
  queryParams: { gitBranch, fallbackBranch },
2060
- trace: defaultTrace
3309
+ trace: defaultTrace,
3310
+ clientName: options?.clientName,
3311
+ xataAgentExtra: options?.xataAgentExtra
2061
3312
  });
2062
3313
  return branch;
2063
3314
  }
@@ -2073,15 +3324,17 @@ async function getDatabaseBranch(branch, options) {
2073
3324
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2074
3325
  );
2075
3326
  const [protocol, , host, , database] = databaseURL.split("/");
2076
- const [workspace] = host.split(".");
2077
- const dbBranchName = `${database}:${branch}`;
3327
+ const urlParts = parseWorkspacesUrlParts(host);
3328
+ if (!urlParts)
3329
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3330
+ const { workspace, region } = urlParts;
2078
3331
  try {
2079
3332
  return await getBranchDetails({
2080
3333
  apiKey,
2081
3334
  apiUrl: databaseURL,
2082
3335
  fetchImpl: getFetchImplementation(options?.fetchImpl),
2083
3336
  workspacesApiUrl: `${protocol}//${host}`,
2084
- pathParams: { dbBranchName, workspace },
3337
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
2085
3338
  trace: defaultTrace
2086
3339
  });
2087
3340
  } catch (err) {
@@ -2139,8 +3392,10 @@ const buildClient = (plugins) => {
2139
3392
  };
2140
3393
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2141
3394
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3395
+ const transactions = new TransactionPlugin().build(pluginOptions);
2142
3396
  this.db = db;
2143
3397
  this.search = search;
3398
+ this.transactions = transactions;
2144
3399
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
2145
3400
  if (namespace === void 0)
2146
3401
  continue;
@@ -2160,20 +3415,55 @@ const buildClient = (plugins) => {
2160
3415
  return { databaseURL, branch };
2161
3416
  }
2162
3417
  }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3418
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3419
+ const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3420
+ if (isBrowser && !enableBrowser) {
3421
+ throw new Error(
3422
+ "You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
3423
+ );
3424
+ }
2163
3425
  const fetch = getFetchImplementation(options?.fetch);
2164
3426
  const databaseURL = options?.databaseURL || getDatabaseURL();
2165
3427
  const apiKey = options?.apiKey || getAPIKey();
2166
3428
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2167
3429
  const trace = options?.trace ?? defaultTrace;
2168
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
3430
+ const clientName = options?.clientName;
3431
+ const xataAgentExtra = options?.xataAgentExtra;
3432
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3433
+ apiKey,
3434
+ databaseURL,
3435
+ fetchImpl: options?.fetch,
3436
+ clientName,
3437
+ xataAgentExtra
3438
+ });
2169
3439
  if (!apiKey) {
2170
3440
  throw new Error("Option apiKey is required");
2171
3441
  }
2172
3442
  if (!databaseURL) {
2173
3443
  throw new Error("Option databaseURL is required");
2174
3444
  }
2175
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2176
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
3445
+ return {
3446
+ fetch,
3447
+ databaseURL,
3448
+ apiKey,
3449
+ branch,
3450
+ cache,
3451
+ trace,
3452
+ clientID: generateUUID(),
3453
+ enableBrowser,
3454
+ clientName,
3455
+ xataAgentExtra
3456
+ };
3457
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3458
+ fetch,
3459
+ apiKey,
3460
+ databaseURL,
3461
+ branch,
3462
+ trace,
3463
+ clientID,
3464
+ clientName,
3465
+ xataAgentExtra
3466
+ }) {
2177
3467
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2178
3468
  if (!branchValue)
2179
3469
  throw new Error("Unable to resolve branch value");
@@ -2183,10 +3473,13 @@ const buildClient = (plugins) => {
2183
3473
  apiUrl: "",
2184
3474
  workspacesApiUrl: (path, params) => {
2185
3475
  const hasBranch = params.dbBranchName ?? params.branch;
2186
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
3476
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2187
3477
  return databaseURL + newPath;
2188
3478
  },
2189
- trace
3479
+ trace,
3480
+ clientID,
3481
+ clientName,
3482
+ xataAgentExtra
2190
3483
  };
2191
3484
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2192
3485
  if (__privateGet(this, _branch))
@@ -2277,7 +3570,7 @@ const deserialize = (json) => {
2277
3570
  };
2278
3571
 
2279
3572
  function buildWorkerRunner(config) {
2280
- return function xataWorker(name, _worker) {
3573
+ return function xataWorker(name, worker) {
2281
3574
  return async (...args) => {
2282
3575
  const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2283
3576
  const result = await fetch(url, {
@@ -2299,6 +3592,7 @@ class XataError extends Error {
2299
3592
  }
2300
3593
 
2301
3594
  exports.BaseClient = BaseClient;
3595
+ exports.FetcherError = FetcherError;
2302
3596
  exports.Operations = operationsByTag;
2303
3597
  exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
2304
3598
  exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
@@ -2320,19 +3614,27 @@ exports.XataPlugin = XataPlugin;
2320
3614
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2321
3615
  exports.addGitBranchesEntry = addGitBranchesEntry;
2322
3616
  exports.addTableColumn = addTableColumn;
3617
+ exports.aggregateTable = aggregateTable;
3618
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3619
+ exports.branchTransaction = branchTransaction;
2323
3620
  exports.buildClient = buildClient;
2324
3621
  exports.buildWorkerRunner = buildWorkerRunner;
2325
3622
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2326
3623
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
3624
+ exports.compareBranchSchemas = compareBranchSchemas;
3625
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3626
+ exports.compareMigrationRequest = compareMigrationRequest;
2327
3627
  exports.contains = contains;
2328
3628
  exports.createBranch = createBranch;
2329
3629
  exports.createDatabase = createDatabase;
3630
+ exports.createMigrationRequest = createMigrationRequest;
2330
3631
  exports.createTable = createTable;
2331
3632
  exports.createUserAPIKey = createUserAPIKey;
2332
3633
  exports.createWorkspace = createWorkspace;
2333
3634
  exports.deleteBranch = deleteBranch;
2334
3635
  exports.deleteColumn = deleteColumn;
2335
3636
  exports.deleteDatabase = deleteDatabase;
3637
+ exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
2336
3638
  exports.deleteRecord = deleteRecord;
2337
3639
  exports.deleteTable = deleteTable;
2338
3640
  exports.deleteUser = deleteUser;
@@ -2350,14 +3652,19 @@ exports.getBranchList = getBranchList;
2350
3652
  exports.getBranchMetadata = getBranchMetadata;
2351
3653
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2352
3654
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
3655
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2353
3656
  exports.getBranchStats = getBranchStats;
2354
3657
  exports.getColumn = getColumn;
2355
3658
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
2356
3659
  exports.getCurrentBranchName = getCurrentBranchName;
3660
+ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
2357
3661
  exports.getDatabaseList = getDatabaseList;
2358
3662
  exports.getDatabaseMetadata = getDatabaseMetadata;
2359
3663
  exports.getDatabaseURL = getDatabaseURL;
2360
3664
  exports.getGitBranchesMapping = getGitBranchesMapping;
3665
+ exports.getHostUrl = getHostUrl;
3666
+ exports.getMigrationRequest = getMigrationRequest;
3667
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2361
3668
  exports.getRecord = getRecord;
2362
3669
  exports.getTableColumns = getTableColumns;
2363
3670
  exports.getTableSchema = getTableSchema;
@@ -2380,6 +3687,8 @@ exports.insertRecordWithID = insertRecordWithID;
2380
3687
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2381
3688
  exports.is = is;
2382
3689
  exports.isCursorPaginationOptions = isCursorPaginationOptions;
3690
+ exports.isHostProviderAlias = isHostProviderAlias;
3691
+ exports.isHostProviderBuilder = isHostProviderBuilder;
2383
3692
  exports.isIdentifiable = isIdentifiable;
2384
3693
  exports.isNot = isNot;
2385
3694
  exports.isXataRecord = isXataRecord;
@@ -2387,11 +3696,18 @@ exports.le = le;
2387
3696
  exports.lessEquals = lessEquals;
2388
3697
  exports.lessThan = lessThan;
2389
3698
  exports.lessThanEquals = lessThanEquals;
3699
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3700
+ exports.listRegions = listRegions;
2390
3701
  exports.lt = lt;
2391
3702
  exports.lte = lte;
3703
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2392
3704
  exports.notExists = notExists;
2393
3705
  exports.operationsByTag = operationsByTag;
3706
+ exports.parseProviderString = parseProviderString;
3707
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
2394
3708
  exports.pattern = pattern;
3709
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3710
+ exports.queryMigrationRequests = queryMigrationRequests;
2395
3711
  exports.queryTable = queryTable;
2396
3712
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2397
3713
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2402,8 +3718,13 @@ exports.searchTable = searchTable;
2402
3718
  exports.serialize = serialize;
2403
3719
  exports.setTableSchema = setTableSchema;
2404
3720
  exports.startsWith = startsWith;
3721
+ exports.summarizeTable = summarizeTable;
2405
3722
  exports.updateBranchMetadata = updateBranchMetadata;
3723
+ exports.updateBranchSchema = updateBranchSchema;
2406
3724
  exports.updateColumn = updateColumn;
3725
+ exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
3726
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
3727
+ exports.updateMigrationRequest = updateMigrationRequest;
2407
3728
  exports.updateRecordWithID = updateRecordWithID;
2408
3729
  exports.updateTable = updateTable;
2409
3730
  exports.updateUser = updateUser;
@@ -2411,4 +3732,5 @@ exports.updateWorkspace = updateWorkspace;
2411
3732
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
2412
3733
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
2413
3734
  exports.upsertRecordWithID = upsertRecordWithID;
3735
+ exports.vectorSearchTable = vectorSearchTable;
2414
3736
  //# sourceMappingURL=index.cjs.map