@xata.io/client 0.0.0-alpha.vf3111df → 0.0.0-alpha.vf331c3f

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,18 +195,114 @@ 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;
169
224
  if (!fetchImpl) {
170
225
  throw new Error(
171
- `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
226
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
172
227
  );
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
+ };
176
297
 
177
- const VERSION = "0.0.0-alpha.vf3111df";
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
+ }
304
+
305
+ const VERSION = "0.21.6";
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,98 @@ 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
+ fetchOptions = {}
258
400
  }) {
259
- return trace(
401
+ pool.setFetch(fetchImpl);
402
+ return await trace(
260
403
  `${method.toUpperCase()} ${path}`,
261
- async ({ setAttributes, onError }) => {
262
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
404
+ async ({ setAttributes }) => {
405
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
263
406
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
264
407
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
265
408
  setAttributes({
266
409
  [TraceAttributes.HTTP_URL]: url,
267
410
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
268
411
  });
269
- const response = await fetchImpl(url, {
412
+ const xataAgent = compact([
413
+ ["client", "TS_SDK"],
414
+ ["version", VERSION],
415
+ isDefined(clientName) ? ["service", clientName] : void 0
416
+ ]).map(([key, value]) => `${key}=${value}`).join("; ");
417
+ const headers = {
418
+ "Accept-Encoding": "identity",
419
+ "Content-Type": "application/json",
420
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
421
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
422
+ "X-Xata-Agent": xataAgent,
423
+ ...customHeaders,
424
+ ...hostHeader(fullUrl),
425
+ Authorization: `Bearer ${apiKey}`
426
+ };
427
+ const response = await pool.request(url, {
428
+ ...fetchOptions,
270
429
  method: method.toUpperCase(),
271
430
  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
- }
431
+ headers,
432
+ signal
279
433
  });
280
- if (response.status === 204) {
281
- return {};
282
- }
283
434
  const { host, protocol } = parseUrl(response.url);
284
435
  const requestId = response.headers?.get("x-request-id") ?? void 0;
285
436
  setAttributes({
437
+ [TraceAttributes.KIND]: "http",
286
438
  [TraceAttributes.HTTP_REQUEST_ID]: requestId,
287
439
  [TraceAttributes.HTTP_STATUS_CODE]: response.status,
288
440
  [TraceAttributes.HTTP_HOST]: host,
289
441
  [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
290
442
  });
443
+ if (response.status === 204) {
444
+ return {};
445
+ }
446
+ if (response.status === 429) {
447
+ throw new FetcherError(response.status, "Rate limit exceeded", requestId);
448
+ }
291
449
  try {
292
450
  const jsonResponse = await response.json();
293
451
  if (response.ok) {
@@ -295,9 +453,7 @@ async function fetch$1({
295
453
  }
296
454
  throw new FetcherError(response.status, jsonResponse, requestId);
297
455
  } catch (error) {
298
- const fetcherError = new FetcherError(response.status, error, requestId);
299
- onError(fetcherError.message);
300
- throw fetcherError;
456
+ throw new FetcherError(response.status, error, requestId);
301
457
  }
302
458
  },
303
459
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
@@ -312,246 +468,152 @@ function parseUrl(url) {
312
468
  }
313
469
  }
314
470
 
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({
471
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
472
+
473
+ const getBranchList = (variables, signal) => dataPlaneFetch({
402
474
  url: "/dbs/{dbName}",
403
- method: "delete",
404
- ...variables
405
- });
406
- const getDatabaseMetadata = (variables) => fetch$1({
407
- url: "/dbs/{dbName}/metadata",
408
475
  method: "get",
409
- ...variables
476
+ ...variables,
477
+ signal
410
478
  });
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
- method: "get",
417
- ...variables
418
- });
419
- const getBranchDetails = (variables) => fetch$1({
479
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
420
480
  url: "/db/{dbBranchName}",
421
481
  method: "get",
422
- ...variables
482
+ ...variables,
483
+ signal
423
484
  });
424
- const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
425
- const deleteBranch = (variables) => fetch$1({
485
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
486
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
426
487
  url: "/db/{dbBranchName}",
427
488
  method: "delete",
428
- ...variables
489
+ ...variables,
490
+ signal
429
491
  });
430
- const updateBranchMetadata = (variables) => fetch$1({
492
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
431
493
  url: "/db/{dbBranchName}/metadata",
432
494
  method: "put",
433
- ...variables
495
+ ...variables,
496
+ signal
434
497
  });
435
- const getBranchMetadata = (variables) => fetch$1({
498
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
436
499
  url: "/db/{dbBranchName}/metadata",
437
500
  method: "get",
438
- ...variables
501
+ ...variables,
502
+ signal
439
503
  });
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({
504
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
444
505
  url: "/db/{dbBranchName}/stats",
445
506
  method: "get",
446
- ...variables
507
+ ...variables,
508
+ signal
509
+ });
510
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
511
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
512
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
513
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
514
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
515
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
516
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
517
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
518
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
519
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
520
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
521
+ method: "get",
522
+ ...variables,
523
+ signal
524
+ });
525
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
526
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
527
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
528
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
529
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
530
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
531
+ method: "post",
532
+ ...variables,
533
+ signal
447
534
  });
448
- const createTable = (variables) => fetch$1({
535
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
536
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
537
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
538
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
539
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
540
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
541
+ const createTable = (variables, signal) => dataPlaneFetch({
449
542
  url: "/db/{dbBranchName}/tables/{tableName}",
450
543
  method: "put",
451
- ...variables
544
+ ...variables,
545
+ signal
452
546
  });
453
- const deleteTable = (variables) => fetch$1({
547
+ const deleteTable = (variables, signal) => dataPlaneFetch({
454
548
  url: "/db/{dbBranchName}/tables/{tableName}",
455
549
  method: "delete",
456
- ...variables
550
+ ...variables,
551
+ signal
457
552
  });
458
- const updateTable = (variables) => fetch$1({
459
- url: "/db/{dbBranchName}/tables/{tableName}",
460
- method: "patch",
461
- ...variables
462
- });
463
- const getTableSchema = (variables) => fetch$1({
553
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
554
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
464
555
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
465
556
  method: "get",
466
- ...variables
467
- });
468
- const setTableSchema = (variables) => fetch$1({
469
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
470
- method: "put",
471
- ...variables
557
+ ...variables,
558
+ signal
472
559
  });
473
- const getTableColumns = (variables) => fetch$1({
560
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
561
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
474
562
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
475
563
  method: "get",
476
- ...variables
564
+ ...variables,
565
+ signal
477
566
  });
478
- const addTableColumn = (variables) => fetch$1({
479
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
480
- method: "post",
481
- ...variables
482
- });
483
- const getColumn = (variables) => fetch$1({
567
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
568
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
569
+ );
570
+ const getColumn = (variables, signal) => dataPlaneFetch({
484
571
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
485
572
  method: "get",
486
- ...variables
573
+ ...variables,
574
+ signal
487
575
  });
488
- const deleteColumn = (variables) => fetch$1({
576
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
577
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
489
578
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
490
579
  method: "delete",
491
- ...variables
580
+ ...variables,
581
+ signal
492
582
  });
493
- const updateColumn = (variables) => fetch$1({
494
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
495
- method: "patch",
496
- ...variables
497
- });
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({
583
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
584
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
585
+ const getRecord = (variables, signal) => dataPlaneFetch({
508
586
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
509
587
  method: "get",
510
- ...variables
588
+ ...variables,
589
+ signal
511
590
  });
512
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
513
- const queryTable = (variables) => fetch$1({
591
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
592
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
593
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
594
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
595
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
596
+ const queryTable = (variables, signal) => dataPlaneFetch({
514
597
  url: "/db/{dbBranchName}/tables/{tableName}/query",
515
598
  method: "post",
516
- ...variables
599
+ ...variables,
600
+ signal
517
601
  });
518
- const searchTable = (variables) => fetch$1({
519
- url: "/db/{dbBranchName}/tables/{tableName}/search",
602
+ const searchBranch = (variables, signal) => dataPlaneFetch({
603
+ url: "/db/{dbBranchName}/search",
520
604
  method: "post",
521
- ...variables
605
+ ...variables,
606
+ signal
522
607
  });
523
- const searchBranch = (variables) => fetch$1({
524
- url: "/db/{dbBranchName}/search",
608
+ const searchTable = (variables, signal) => dataPlaneFetch({
609
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
525
610
  method: "post",
526
- ...variables
611
+ ...variables,
612
+ signal
527
613
  });
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
- },
614
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
615
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
616
+ const operationsByTag$2 = {
555
617
  branch: {
556
618
  getBranchList,
557
619
  getBranchDetails,
@@ -559,10 +621,32 @@ const operationsByTag = {
559
621
  deleteBranch,
560
622
  updateBranchMetadata,
561
623
  getBranchMetadata,
624
+ getBranchStats,
625
+ getGitBranchesMapping,
626
+ addGitBranchesEntry,
627
+ removeGitBranchesEntry,
628
+ resolveBranch
629
+ },
630
+ migrations: {
562
631
  getBranchMigrationHistory,
563
- executeBranchMigrationPlan,
564
632
  getBranchMigrationPlan,
565
- getBranchStats
633
+ executeBranchMigrationPlan,
634
+ getBranchSchemaHistory,
635
+ compareBranchWithUserSchema,
636
+ compareBranchSchemas,
637
+ updateBranchSchema,
638
+ previewBranchSchemaEdit,
639
+ applyBranchSchemaEdit
640
+ },
641
+ migrationRequests: {
642
+ queryMigrationRequests,
643
+ createMigrationRequest,
644
+ getMigrationRequest,
645
+ updateMigrationRequest,
646
+ listMigrationRequestsCommits,
647
+ compareMigrationRequest,
648
+ getMigrationRequestIsMerged,
649
+ mergeMigrationRequest
566
650
  },
567
651
  table: {
568
652
  createTable,
@@ -573,27 +657,160 @@ const operationsByTag = {
573
657
  getTableColumns,
574
658
  addTableColumn,
575
659
  getColumn,
576
- deleteColumn,
577
- updateColumn
660
+ updateColumn,
661
+ deleteColumn
578
662
  },
579
663
  records: {
664
+ branchTransaction,
580
665
  insertRecord,
666
+ getRecord,
581
667
  insertRecordWithID,
582
668
  updateRecordWithID,
583
669
  upsertRecordWithID,
584
670
  deleteRecord,
585
- getRecord,
586
- bulkInsertTableRecords,
587
- queryTable,
588
- searchTable,
589
- searchBranch
671
+ bulkInsertTableRecords
672
+ },
673
+ searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
674
+ };
675
+
676
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
677
+
678
+ const getUser = (variables, signal) => controlPlaneFetch({
679
+ url: "/user",
680
+ method: "get",
681
+ ...variables,
682
+ signal
683
+ });
684
+ const updateUser = (variables, signal) => controlPlaneFetch({
685
+ url: "/user",
686
+ method: "put",
687
+ ...variables,
688
+ signal
689
+ });
690
+ const deleteUser = (variables, signal) => controlPlaneFetch({
691
+ url: "/user",
692
+ method: "delete",
693
+ ...variables,
694
+ signal
695
+ });
696
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
697
+ url: "/user/keys",
698
+ method: "get",
699
+ ...variables,
700
+ signal
701
+ });
702
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
703
+ url: "/user/keys/{keyName}",
704
+ method: "post",
705
+ ...variables,
706
+ signal
707
+ });
708
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
709
+ url: "/user/keys/{keyName}",
710
+ method: "delete",
711
+ ...variables,
712
+ signal
713
+ });
714
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
715
+ url: "/workspaces",
716
+ method: "get",
717
+ ...variables,
718
+ signal
719
+ });
720
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
721
+ url: "/workspaces",
722
+ method: "post",
723
+ ...variables,
724
+ signal
725
+ });
726
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
727
+ url: "/workspaces/{workspaceId}",
728
+ method: "get",
729
+ ...variables,
730
+ signal
731
+ });
732
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
733
+ url: "/workspaces/{workspaceId}",
734
+ method: "put",
735
+ ...variables,
736
+ signal
737
+ });
738
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
739
+ url: "/workspaces/{workspaceId}",
740
+ method: "delete",
741
+ ...variables,
742
+ signal
743
+ });
744
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
745
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
746
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
747
+ url: "/workspaces/{workspaceId}/members/{userId}",
748
+ method: "delete",
749
+ ...variables,
750
+ signal
751
+ });
752
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
753
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
754
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
755
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
756
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
757
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
758
+ url: "/workspaces/{workspaceId}/dbs",
759
+ method: "get",
760
+ ...variables,
761
+ signal
762
+ });
763
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
764
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
765
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
766
+ method: "delete",
767
+ ...variables,
768
+ signal
769
+ });
770
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
771
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
772
+ const listRegions = (variables, signal) => controlPlaneFetch({
773
+ url: "/workspaces/{workspaceId}/regions",
774
+ method: "get",
775
+ ...variables,
776
+ signal
777
+ });
778
+ const operationsByTag$1 = {
779
+ users: { getUser, updateUser, deleteUser },
780
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
781
+ workspaces: {
782
+ getWorkspacesList,
783
+ createWorkspace,
784
+ getWorkspace,
785
+ updateWorkspace,
786
+ deleteWorkspace,
787
+ getWorkspaceMembersList,
788
+ updateWorkspaceMemberRole,
789
+ removeWorkspaceMember
790
+ },
791
+ invites: {
792
+ inviteWorkspaceMember,
793
+ updateWorkspaceMemberInvite,
794
+ cancelWorkspaceMemberInvite,
795
+ acceptWorkspaceMemberInvite,
796
+ resendWorkspaceMemberInvite
797
+ },
798
+ databases: {
799
+ getDatabaseList,
800
+ createDatabase,
801
+ deleteDatabase,
802
+ getDatabaseMetadata,
803
+ updateDatabaseMetadata,
804
+ listRegions
590
805
  }
591
806
  };
592
807
 
808
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
809
+
593
810
  function getHostUrl(provider, type) {
594
- if (isValidAlias(provider)) {
811
+ if (isHostProviderAlias(provider)) {
595
812
  return providers[provider][type];
596
- } else if (isValidBuilder(provider)) {
813
+ } else if (isHostProviderBuilder(provider)) {
597
814
  return provider[type];
598
815
  }
599
816
  throw new Error("Invalid API provider");
@@ -601,19 +818,38 @@ function getHostUrl(provider, type) {
601
818
  const providers = {
602
819
  production: {
603
820
  main: "https://api.xata.io",
604
- workspaces: "https://{workspaceId}.xata.sh"
821
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
605
822
  },
606
823
  staging: {
607
824
  main: "https://staging.xatabase.co",
608
- workspaces: "https://{workspaceId}.staging.xatabase.co"
825
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
609
826
  }
610
827
  };
611
- function isValidAlias(alias) {
828
+ function isHostProviderAlias(alias) {
612
829
  return isString(alias) && Object.keys(providers).includes(alias);
613
830
  }
614
- function isValidBuilder(builder) {
831
+ function isHostProviderBuilder(builder) {
615
832
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
616
833
  }
834
+ function parseProviderString(provider = "production") {
835
+ if (isHostProviderAlias(provider)) {
836
+ return provider;
837
+ }
838
+ const [main, workspaces] = provider.split(",");
839
+ if (!main || !workspaces)
840
+ return null;
841
+ return { main, workspaces };
842
+ }
843
+ function parseWorkspacesUrlParts(url) {
844
+ if (!isString(url))
845
+ return null;
846
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
847
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
848
+ const match = url.match(regex) || url.match(regexStaging);
849
+ if (!match)
850
+ return null;
851
+ return { workspace: match[1], region: match[2] };
852
+ }
617
853
 
618
854
  var __accessCheck$7 = (obj, member, msg) => {
619
855
  if (!member.has(obj))
@@ -641,6 +877,7 @@ class XataApiClient {
641
877
  const provider = options.host ?? "production";
642
878
  const apiKey = options.apiKey ?? getAPIKey();
643
879
  const trace = options.trace ?? defaultTrace;
880
+ const clientID = generateUUID();
644
881
  if (!apiKey) {
645
882
  throw new Error("Could not resolve a valid apiKey");
646
883
  }
@@ -649,7 +886,9 @@ class XataApiClient {
649
886
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
650
887
  fetchImpl: getFetchImplementation(options.fetch),
651
888
  apiKey,
652
- trace
889
+ trace,
890
+ clientName: options.clientName,
891
+ clientID
653
892
  });
654
893
  }
655
894
  get user() {
@@ -657,21 +896,41 @@ class XataApiClient {
657
896
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
658
897
  return __privateGet$7(this, _namespaces).user;
659
898
  }
899
+ get authentication() {
900
+ if (!__privateGet$7(this, _namespaces).authentication)
901
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
902
+ return __privateGet$7(this, _namespaces).authentication;
903
+ }
660
904
  get workspaces() {
661
905
  if (!__privateGet$7(this, _namespaces).workspaces)
662
906
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
663
907
  return __privateGet$7(this, _namespaces).workspaces;
664
908
  }
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;
909
+ get invites() {
910
+ if (!__privateGet$7(this, _namespaces).invites)
911
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
912
+ return __privateGet$7(this, _namespaces).invites;
913
+ }
914
+ get database() {
915
+ if (!__privateGet$7(this, _namespaces).database)
916
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
917
+ return __privateGet$7(this, _namespaces).database;
669
918
  }
670
919
  get branches() {
671
920
  if (!__privateGet$7(this, _namespaces).branches)
672
921
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
673
922
  return __privateGet$7(this, _namespaces).branches;
674
923
  }
924
+ get migrations() {
925
+ if (!__privateGet$7(this, _namespaces).migrations)
926
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
927
+ return __privateGet$7(this, _namespaces).migrations;
928
+ }
929
+ get migrationRequests() {
930
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
931
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
932
+ return __privateGet$7(this, _namespaces).migrationRequests;
933
+ }
675
934
  get tables() {
676
935
  if (!__privateGet$7(this, _namespaces).tables)
677
936
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -682,6 +941,11 @@ class XataApiClient {
682
941
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
683
942
  return __privateGet$7(this, _namespaces).records;
684
943
  }
944
+ get searchAndFilter() {
945
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
946
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
947
+ return __privateGet$7(this, _namespaces).searchAndFilter;
948
+ }
685
949
  }
686
950
  _extraProps = new WeakMap();
687
951
  _namespaces = new WeakMap();
@@ -692,24 +956,29 @@ class UserApi {
692
956
  getUser() {
693
957
  return operationsByTag.users.getUser({ ...this.extraProps });
694
958
  }
695
- updateUser(user) {
959
+ updateUser({ user }) {
696
960
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
697
961
  }
698
962
  deleteUser() {
699
963
  return operationsByTag.users.deleteUser({ ...this.extraProps });
700
964
  }
965
+ }
966
+ class AuthenticationApi {
967
+ constructor(extraProps) {
968
+ this.extraProps = extraProps;
969
+ }
701
970
  getUserAPIKeys() {
702
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
971
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
703
972
  }
704
- createUserAPIKey(keyName) {
705
- return operationsByTag.users.createUserAPIKey({
706
- pathParams: { keyName },
973
+ createUserAPIKey({ name }) {
974
+ return operationsByTag.authentication.createUserAPIKey({
975
+ pathParams: { keyName: name },
707
976
  ...this.extraProps
708
977
  });
709
978
  }
710
- deleteUserAPIKey(keyName) {
711
- return operationsByTag.users.deleteUserAPIKey({
712
- pathParams: { keyName },
979
+ deleteUserAPIKey({ name }) {
980
+ return operationsByTag.authentication.deleteUserAPIKey({
981
+ pathParams: { keyName: name },
713
982
  ...this.extraProps
714
983
  });
715
984
  }
@@ -718,359 +987,897 @@ class WorkspaceApi {
718
987
  constructor(extraProps) {
719
988
  this.extraProps = extraProps;
720
989
  }
721
- createWorkspace(workspaceMeta) {
990
+ getWorkspacesList() {
991
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
992
+ }
993
+ createWorkspace({ data }) {
722
994
  return operationsByTag.workspaces.createWorkspace({
723
- body: workspaceMeta,
995
+ body: data,
724
996
  ...this.extraProps
725
997
  });
726
998
  }
727
- getWorkspacesList() {
728
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
729
- }
730
- getWorkspace(workspaceId) {
999
+ getWorkspace({ workspace }) {
731
1000
  return operationsByTag.workspaces.getWorkspace({
732
- pathParams: { workspaceId },
1001
+ pathParams: { workspaceId: workspace },
733
1002
  ...this.extraProps
734
1003
  });
735
1004
  }
736
- updateWorkspace(workspaceId, workspaceMeta) {
737
- return operationsByTag.workspaces.updateWorkspace({
738
- pathParams: { workspaceId },
739
- body: workspaceMeta,
1005
+ updateWorkspace({
1006
+ workspace,
1007
+ update
1008
+ }) {
1009
+ return operationsByTag.workspaces.updateWorkspace({
1010
+ pathParams: { workspaceId: workspace },
1011
+ body: update,
1012
+ ...this.extraProps
1013
+ });
1014
+ }
1015
+ deleteWorkspace({ workspace }) {
1016
+ return operationsByTag.workspaces.deleteWorkspace({
1017
+ pathParams: { workspaceId: workspace },
1018
+ ...this.extraProps
1019
+ });
1020
+ }
1021
+ getWorkspaceMembersList({ workspace }) {
1022
+ return operationsByTag.workspaces.getWorkspaceMembersList({
1023
+ pathParams: { workspaceId: workspace },
1024
+ ...this.extraProps
1025
+ });
1026
+ }
1027
+ updateWorkspaceMemberRole({
1028
+ workspace,
1029
+ user,
1030
+ role
1031
+ }) {
1032
+ return operationsByTag.workspaces.updateWorkspaceMemberRole({
1033
+ pathParams: { workspaceId: workspace, userId: user },
1034
+ body: { role },
1035
+ ...this.extraProps
1036
+ });
1037
+ }
1038
+ removeWorkspaceMember({
1039
+ workspace,
1040
+ user
1041
+ }) {
1042
+ return operationsByTag.workspaces.removeWorkspaceMember({
1043
+ pathParams: { workspaceId: workspace, userId: user },
1044
+ ...this.extraProps
1045
+ });
1046
+ }
1047
+ }
1048
+ class InvitesApi {
1049
+ constructor(extraProps) {
1050
+ this.extraProps = extraProps;
1051
+ }
1052
+ inviteWorkspaceMember({
1053
+ workspace,
1054
+ email,
1055
+ role
1056
+ }) {
1057
+ return operationsByTag.invites.inviteWorkspaceMember({
1058
+ pathParams: { workspaceId: workspace },
1059
+ body: { email, role },
1060
+ ...this.extraProps
1061
+ });
1062
+ }
1063
+ updateWorkspaceMemberInvite({
1064
+ workspace,
1065
+ invite,
1066
+ role
1067
+ }) {
1068
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
1069
+ pathParams: { workspaceId: workspace, inviteId: invite },
1070
+ body: { role },
1071
+ ...this.extraProps
1072
+ });
1073
+ }
1074
+ cancelWorkspaceMemberInvite({
1075
+ workspace,
1076
+ invite
1077
+ }) {
1078
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
1079
+ pathParams: { workspaceId: workspace, inviteId: invite },
1080
+ ...this.extraProps
1081
+ });
1082
+ }
1083
+ acceptWorkspaceMemberInvite({
1084
+ workspace,
1085
+ key
1086
+ }) {
1087
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
1088
+ pathParams: { workspaceId: workspace, inviteKey: key },
1089
+ ...this.extraProps
1090
+ });
1091
+ }
1092
+ resendWorkspaceMemberInvite({
1093
+ workspace,
1094
+ invite
1095
+ }) {
1096
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
1097
+ pathParams: { workspaceId: workspace, inviteId: invite },
1098
+ ...this.extraProps
1099
+ });
1100
+ }
1101
+ }
1102
+ class BranchApi {
1103
+ constructor(extraProps) {
1104
+ this.extraProps = extraProps;
1105
+ }
1106
+ getBranchList({
1107
+ workspace,
1108
+ region,
1109
+ database
1110
+ }) {
1111
+ return operationsByTag.branch.getBranchList({
1112
+ pathParams: { workspace, region, dbName: database },
1113
+ ...this.extraProps
1114
+ });
1115
+ }
1116
+ getBranchDetails({
1117
+ workspace,
1118
+ region,
1119
+ database,
1120
+ branch
1121
+ }) {
1122
+ return operationsByTag.branch.getBranchDetails({
1123
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1124
+ ...this.extraProps
1125
+ });
1126
+ }
1127
+ createBranch({
1128
+ workspace,
1129
+ region,
1130
+ database,
1131
+ branch,
1132
+ from,
1133
+ metadata
1134
+ }) {
1135
+ return operationsByTag.branch.createBranch({
1136
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1137
+ body: { from, metadata },
1138
+ ...this.extraProps
1139
+ });
1140
+ }
1141
+ deleteBranch({
1142
+ workspace,
1143
+ region,
1144
+ database,
1145
+ branch
1146
+ }) {
1147
+ return operationsByTag.branch.deleteBranch({
1148
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1149
+ ...this.extraProps
1150
+ });
1151
+ }
1152
+ updateBranchMetadata({
1153
+ workspace,
1154
+ region,
1155
+ database,
1156
+ branch,
1157
+ metadata
1158
+ }) {
1159
+ return operationsByTag.branch.updateBranchMetadata({
1160
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1161
+ body: metadata,
1162
+ ...this.extraProps
1163
+ });
1164
+ }
1165
+ getBranchMetadata({
1166
+ workspace,
1167
+ region,
1168
+ database,
1169
+ branch
1170
+ }) {
1171
+ return operationsByTag.branch.getBranchMetadata({
1172
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1173
+ ...this.extraProps
1174
+ });
1175
+ }
1176
+ getBranchStats({
1177
+ workspace,
1178
+ region,
1179
+ database,
1180
+ branch
1181
+ }) {
1182
+ return operationsByTag.branch.getBranchStats({
1183
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1184
+ ...this.extraProps
1185
+ });
1186
+ }
1187
+ getGitBranchesMapping({
1188
+ workspace,
1189
+ region,
1190
+ database
1191
+ }) {
1192
+ return operationsByTag.branch.getGitBranchesMapping({
1193
+ pathParams: { workspace, region, dbName: database },
1194
+ ...this.extraProps
1195
+ });
1196
+ }
1197
+ addGitBranchesEntry({
1198
+ workspace,
1199
+ region,
1200
+ database,
1201
+ gitBranch,
1202
+ xataBranch
1203
+ }) {
1204
+ return operationsByTag.branch.addGitBranchesEntry({
1205
+ pathParams: { workspace, region, dbName: database },
1206
+ body: { gitBranch, xataBranch },
1207
+ ...this.extraProps
1208
+ });
1209
+ }
1210
+ removeGitBranchesEntry({
1211
+ workspace,
1212
+ region,
1213
+ database,
1214
+ gitBranch
1215
+ }) {
1216
+ return operationsByTag.branch.removeGitBranchesEntry({
1217
+ pathParams: { workspace, region, dbName: database },
1218
+ queryParams: { gitBranch },
1219
+ ...this.extraProps
1220
+ });
1221
+ }
1222
+ resolveBranch({
1223
+ workspace,
1224
+ region,
1225
+ database,
1226
+ gitBranch,
1227
+ fallbackBranch
1228
+ }) {
1229
+ return operationsByTag.branch.resolveBranch({
1230
+ pathParams: { workspace, region, dbName: database },
1231
+ queryParams: { gitBranch, fallbackBranch },
1232
+ ...this.extraProps
1233
+ });
1234
+ }
1235
+ }
1236
+ class TableApi {
1237
+ constructor(extraProps) {
1238
+ this.extraProps = extraProps;
1239
+ }
1240
+ createTable({
1241
+ workspace,
1242
+ region,
1243
+ database,
1244
+ branch,
1245
+ table
1246
+ }) {
1247
+ return operationsByTag.table.createTable({
1248
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
740
1249
  ...this.extraProps
741
1250
  });
742
1251
  }
743
- deleteWorkspace(workspaceId) {
744
- return operationsByTag.workspaces.deleteWorkspace({
745
- pathParams: { workspaceId },
1252
+ deleteTable({
1253
+ workspace,
1254
+ region,
1255
+ database,
1256
+ branch,
1257
+ table
1258
+ }) {
1259
+ return operationsByTag.table.deleteTable({
1260
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
746
1261
  ...this.extraProps
747
1262
  });
748
1263
  }
749
- getWorkspaceMembersList(workspaceId) {
750
- return operationsByTag.workspaces.getWorkspaceMembersList({
751
- pathParams: { workspaceId },
1264
+ updateTable({
1265
+ workspace,
1266
+ region,
1267
+ database,
1268
+ branch,
1269
+ table,
1270
+ update
1271
+ }) {
1272
+ return operationsByTag.table.updateTable({
1273
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1274
+ body: update,
752
1275
  ...this.extraProps
753
1276
  });
754
1277
  }
755
- updateWorkspaceMemberRole(workspaceId, userId, role) {
756
- return operationsByTag.workspaces.updateWorkspaceMemberRole({
757
- pathParams: { workspaceId, userId },
758
- body: { role },
1278
+ getTableSchema({
1279
+ workspace,
1280
+ region,
1281
+ database,
1282
+ branch,
1283
+ table
1284
+ }) {
1285
+ return operationsByTag.table.getTableSchema({
1286
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
759
1287
  ...this.extraProps
760
1288
  });
761
1289
  }
762
- removeWorkspaceMember(workspaceId, userId) {
763
- return operationsByTag.workspaces.removeWorkspaceMember({
764
- pathParams: { workspaceId, userId },
1290
+ setTableSchema({
1291
+ workspace,
1292
+ region,
1293
+ database,
1294
+ branch,
1295
+ table,
1296
+ schema
1297
+ }) {
1298
+ return operationsByTag.table.setTableSchema({
1299
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1300
+ body: schema,
765
1301
  ...this.extraProps
766
1302
  });
767
1303
  }
768
- inviteWorkspaceMember(workspaceId, email, role) {
769
- return operationsByTag.workspaces.inviteWorkspaceMember({
770
- pathParams: { workspaceId },
771
- body: { email, role },
1304
+ getTableColumns({
1305
+ workspace,
1306
+ region,
1307
+ database,
1308
+ branch,
1309
+ table
1310
+ }) {
1311
+ return operationsByTag.table.getTableColumns({
1312
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
772
1313
  ...this.extraProps
773
1314
  });
774
1315
  }
775
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
776
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
777
- pathParams: { workspaceId, inviteId },
778
- body: { role },
1316
+ addTableColumn({
1317
+ workspace,
1318
+ region,
1319
+ database,
1320
+ branch,
1321
+ table,
1322
+ column
1323
+ }) {
1324
+ return operationsByTag.table.addTableColumn({
1325
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1326
+ body: column,
779
1327
  ...this.extraProps
780
1328
  });
781
1329
  }
782
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
783
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
784
- pathParams: { workspaceId, inviteId },
1330
+ getColumn({
1331
+ workspace,
1332
+ region,
1333
+ database,
1334
+ branch,
1335
+ table,
1336
+ column
1337
+ }) {
1338
+ return operationsByTag.table.getColumn({
1339
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
785
1340
  ...this.extraProps
786
1341
  });
787
1342
  }
788
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
789
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
790
- pathParams: { workspaceId, inviteId },
1343
+ updateColumn({
1344
+ workspace,
1345
+ region,
1346
+ database,
1347
+ branch,
1348
+ table,
1349
+ column,
1350
+ update
1351
+ }) {
1352
+ return operationsByTag.table.updateColumn({
1353
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1354
+ body: update,
791
1355
  ...this.extraProps
792
1356
  });
793
1357
  }
794
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
795
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
796
- pathParams: { workspaceId, inviteKey },
1358
+ deleteColumn({
1359
+ workspace,
1360
+ region,
1361
+ database,
1362
+ branch,
1363
+ table,
1364
+ column
1365
+ }) {
1366
+ return operationsByTag.table.deleteColumn({
1367
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
797
1368
  ...this.extraProps
798
1369
  });
799
1370
  }
800
1371
  }
801
- class DatabaseApi {
1372
+ class RecordsApi {
802
1373
  constructor(extraProps) {
803
1374
  this.extraProps = extraProps;
804
1375
  }
805
- getDatabaseList(workspace) {
806
- return operationsByTag.database.getDatabaseList({
807
- pathParams: { workspace },
1376
+ insertRecord({
1377
+ workspace,
1378
+ region,
1379
+ database,
1380
+ branch,
1381
+ table,
1382
+ record,
1383
+ columns
1384
+ }) {
1385
+ return operationsByTag.records.insertRecord({
1386
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1387
+ queryParams: { columns },
1388
+ body: record,
808
1389
  ...this.extraProps
809
1390
  });
810
1391
  }
811
- createDatabase(workspace, dbName, options = {}) {
812
- return operationsByTag.database.createDatabase({
813
- pathParams: { workspace, dbName },
814
- body: options,
1392
+ getRecord({
1393
+ workspace,
1394
+ region,
1395
+ database,
1396
+ branch,
1397
+ table,
1398
+ id,
1399
+ columns
1400
+ }) {
1401
+ return operationsByTag.records.getRecord({
1402
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1403
+ queryParams: { columns },
815
1404
  ...this.extraProps
816
1405
  });
817
1406
  }
818
- deleteDatabase(workspace, dbName) {
819
- return operationsByTag.database.deleteDatabase({
820
- pathParams: { workspace, dbName },
1407
+ insertRecordWithID({
1408
+ workspace,
1409
+ region,
1410
+ database,
1411
+ branch,
1412
+ table,
1413
+ id,
1414
+ record,
1415
+ columns,
1416
+ createOnly,
1417
+ ifVersion
1418
+ }) {
1419
+ return operationsByTag.records.insertRecordWithID({
1420
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1421
+ queryParams: { columns, createOnly, ifVersion },
1422
+ body: record,
821
1423
  ...this.extraProps
822
1424
  });
823
1425
  }
824
- getDatabaseMetadata(workspace, dbName) {
825
- return operationsByTag.database.getDatabaseMetadata({
826
- pathParams: { workspace, dbName },
1426
+ updateRecordWithID({
1427
+ workspace,
1428
+ region,
1429
+ database,
1430
+ branch,
1431
+ table,
1432
+ id,
1433
+ record,
1434
+ columns,
1435
+ ifVersion
1436
+ }) {
1437
+ return operationsByTag.records.updateRecordWithID({
1438
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1439
+ queryParams: { columns, ifVersion },
1440
+ body: record,
827
1441
  ...this.extraProps
828
1442
  });
829
1443
  }
830
- getGitBranchesMapping(workspace, dbName) {
831
- return operationsByTag.database.getGitBranchesMapping({
832
- pathParams: { workspace, dbName },
1444
+ upsertRecordWithID({
1445
+ workspace,
1446
+ region,
1447
+ database,
1448
+ branch,
1449
+ table,
1450
+ id,
1451
+ record,
1452
+ columns,
1453
+ ifVersion
1454
+ }) {
1455
+ return operationsByTag.records.upsertRecordWithID({
1456
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1457
+ queryParams: { columns, ifVersion },
1458
+ body: record,
833
1459
  ...this.extraProps
834
1460
  });
835
1461
  }
836
- addGitBranchesEntry(workspace, dbName, body) {
837
- return operationsByTag.database.addGitBranchesEntry({
838
- pathParams: { workspace, dbName },
839
- body,
1462
+ deleteRecord({
1463
+ workspace,
1464
+ region,
1465
+ database,
1466
+ branch,
1467
+ table,
1468
+ id,
1469
+ columns
1470
+ }) {
1471
+ return operationsByTag.records.deleteRecord({
1472
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1473
+ queryParams: { columns },
840
1474
  ...this.extraProps
841
1475
  });
842
1476
  }
843
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
844
- return operationsByTag.database.removeGitBranchesEntry({
845
- pathParams: { workspace, dbName },
846
- queryParams: { gitBranch },
1477
+ bulkInsertTableRecords({
1478
+ workspace,
1479
+ region,
1480
+ database,
1481
+ branch,
1482
+ table,
1483
+ records,
1484
+ columns
1485
+ }) {
1486
+ return operationsByTag.records.bulkInsertTableRecords({
1487
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1488
+ queryParams: { columns },
1489
+ body: { records },
847
1490
  ...this.extraProps
848
1491
  });
849
1492
  }
850
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
851
- return operationsByTag.database.resolveBranch({
852
- pathParams: { workspace, dbName },
853
- queryParams: { gitBranch, fallbackBranch },
1493
+ branchTransaction({
1494
+ workspace,
1495
+ region,
1496
+ database,
1497
+ branch,
1498
+ operations
1499
+ }) {
1500
+ return operationsByTag.records.branchTransaction({
1501
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1502
+ body: { operations },
854
1503
  ...this.extraProps
855
1504
  });
856
1505
  }
857
1506
  }
858
- class BranchApi {
1507
+ class SearchAndFilterApi {
859
1508
  constructor(extraProps) {
860
1509
  this.extraProps = extraProps;
861
1510
  }
862
- getBranchList(workspace, dbName) {
863
- return operationsByTag.branch.getBranchList({
864
- pathParams: { workspace, dbName },
1511
+ queryTable({
1512
+ workspace,
1513
+ region,
1514
+ database,
1515
+ branch,
1516
+ table,
1517
+ filter,
1518
+ sort,
1519
+ page,
1520
+ columns,
1521
+ consistency
1522
+ }) {
1523
+ return operationsByTag.searchAndFilter.queryTable({
1524
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1525
+ body: { filter, sort, page, columns, consistency },
865
1526
  ...this.extraProps
866
1527
  });
867
1528
  }
868
- getBranchDetails(workspace, database, branch) {
869
- return operationsByTag.branch.getBranchDetails({
870
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1529
+ searchTable({
1530
+ workspace,
1531
+ region,
1532
+ database,
1533
+ branch,
1534
+ table,
1535
+ query,
1536
+ fuzziness,
1537
+ target,
1538
+ prefix,
1539
+ filter,
1540
+ highlight,
1541
+ boosters
1542
+ }) {
1543
+ return operationsByTag.searchAndFilter.searchTable({
1544
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1545
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
871
1546
  ...this.extraProps
872
1547
  });
873
1548
  }
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,
1549
+ searchBranch({
1550
+ workspace,
1551
+ region,
1552
+ database,
1553
+ branch,
1554
+ tables,
1555
+ query,
1556
+ fuzziness,
1557
+ prefix,
1558
+ highlight
1559
+ }) {
1560
+ return operationsByTag.searchAndFilter.searchBranch({
1561
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1562
+ body: { tables, query, fuzziness, prefix, highlight },
879
1563
  ...this.extraProps
880
1564
  });
881
1565
  }
882
- deleteBranch(workspace, database, branch) {
883
- return operationsByTag.branch.deleteBranch({
884
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1566
+ summarizeTable({
1567
+ workspace,
1568
+ region,
1569
+ database,
1570
+ branch,
1571
+ table,
1572
+ filter,
1573
+ columns,
1574
+ summaries,
1575
+ sort,
1576
+ summariesFilter,
1577
+ page,
1578
+ consistency
1579
+ }) {
1580
+ return operationsByTag.searchAndFilter.summarizeTable({
1581
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1582
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
885
1583
  ...this.extraProps
886
1584
  });
887
1585
  }
888
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
889
- return operationsByTag.branch.updateBranchMetadata({
890
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
891
- body: metadata,
1586
+ aggregateTable({
1587
+ workspace,
1588
+ region,
1589
+ database,
1590
+ branch,
1591
+ table,
1592
+ filter,
1593
+ aggs
1594
+ }) {
1595
+ return operationsByTag.searchAndFilter.aggregateTable({
1596
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1597
+ body: { filter, aggs },
892
1598
  ...this.extraProps
893
1599
  });
894
1600
  }
895
- getBranchMetadata(workspace, database, branch) {
896
- return operationsByTag.branch.getBranchMetadata({
897
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
898
- ...this.extraProps
899
- });
1601
+ }
1602
+ class MigrationRequestsApi {
1603
+ constructor(extraProps) {
1604
+ this.extraProps = extraProps;
900
1605
  }
901
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
902
- return operationsByTag.branch.getBranchMigrationHistory({
903
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
904
- body: options,
1606
+ queryMigrationRequests({
1607
+ workspace,
1608
+ region,
1609
+ database,
1610
+ filter,
1611
+ sort,
1612
+ page,
1613
+ columns
1614
+ }) {
1615
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1616
+ pathParams: { workspace, region, dbName: database },
1617
+ body: { filter, sort, page, columns },
905
1618
  ...this.extraProps
906
1619
  });
907
1620
  }
908
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
909
- return operationsByTag.branch.executeBranchMigrationPlan({
910
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
911
- body: migrationPlan,
1621
+ createMigrationRequest({
1622
+ workspace,
1623
+ region,
1624
+ database,
1625
+ migration
1626
+ }) {
1627
+ return operationsByTag.migrationRequests.createMigrationRequest({
1628
+ pathParams: { workspace, region, dbName: database },
1629
+ body: migration,
912
1630
  ...this.extraProps
913
1631
  });
914
1632
  }
915
- getBranchMigrationPlan(workspace, database, branch, schema) {
916
- return operationsByTag.branch.getBranchMigrationPlan({
917
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
918
- body: schema,
1633
+ getMigrationRequest({
1634
+ workspace,
1635
+ region,
1636
+ database,
1637
+ migrationRequest
1638
+ }) {
1639
+ return operationsByTag.migrationRequests.getMigrationRequest({
1640
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
919
1641
  ...this.extraProps
920
1642
  });
921
1643
  }
922
- getBranchStats(workspace, database, branch) {
923
- return operationsByTag.branch.getBranchStats({
924
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1644
+ updateMigrationRequest({
1645
+ workspace,
1646
+ region,
1647
+ database,
1648
+ migrationRequest,
1649
+ update
1650
+ }) {
1651
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1652
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1653
+ body: update,
925
1654
  ...this.extraProps
926
1655
  });
927
1656
  }
928
- }
929
- class TableApi {
930
- constructor(extraProps) {
931
- this.extraProps = extraProps;
932
- }
933
- createTable(workspace, database, branch, tableName) {
934
- return operationsByTag.table.createTable({
935
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1657
+ listMigrationRequestsCommits({
1658
+ workspace,
1659
+ region,
1660
+ database,
1661
+ migrationRequest,
1662
+ page
1663
+ }) {
1664
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1665
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1666
+ body: { page },
936
1667
  ...this.extraProps
937
1668
  });
938
1669
  }
939
- deleteTable(workspace, database, branch, tableName) {
940
- return operationsByTag.table.deleteTable({
941
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1670
+ compareMigrationRequest({
1671
+ workspace,
1672
+ region,
1673
+ database,
1674
+ migrationRequest
1675
+ }) {
1676
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1677
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
942
1678
  ...this.extraProps
943
1679
  });
944
1680
  }
945
- updateTable(workspace, database, branch, tableName, options) {
946
- return operationsByTag.table.updateTable({
947
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
948
- body: options,
1681
+ getMigrationRequestIsMerged({
1682
+ workspace,
1683
+ region,
1684
+ database,
1685
+ migrationRequest
1686
+ }) {
1687
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1688
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
949
1689
  ...this.extraProps
950
1690
  });
951
1691
  }
952
- getTableSchema(workspace, database, branch, tableName) {
953
- return operationsByTag.table.getTableSchema({
954
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1692
+ mergeMigrationRequest({
1693
+ workspace,
1694
+ region,
1695
+ database,
1696
+ migrationRequest
1697
+ }) {
1698
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1699
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
955
1700
  ...this.extraProps
956
1701
  });
957
1702
  }
958
- setTableSchema(workspace, database, branch, tableName, options) {
959
- return operationsByTag.table.setTableSchema({
960
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
961
- body: options,
962
- ...this.extraProps
963
- });
1703
+ }
1704
+ class MigrationsApi {
1705
+ constructor(extraProps) {
1706
+ this.extraProps = extraProps;
964
1707
  }
965
- getTableColumns(workspace, database, branch, tableName) {
966
- return operationsByTag.table.getTableColumns({
967
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1708
+ getBranchMigrationHistory({
1709
+ workspace,
1710
+ region,
1711
+ database,
1712
+ branch,
1713
+ limit,
1714
+ startFrom
1715
+ }) {
1716
+ return operationsByTag.migrations.getBranchMigrationHistory({
1717
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1718
+ body: { limit, startFrom },
968
1719
  ...this.extraProps
969
1720
  });
970
1721
  }
971
- addTableColumn(workspace, database, branch, tableName, column) {
972
- return operationsByTag.table.addTableColumn({
973
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
974
- body: column,
1722
+ getBranchMigrationPlan({
1723
+ workspace,
1724
+ region,
1725
+ database,
1726
+ branch,
1727
+ schema
1728
+ }) {
1729
+ return operationsByTag.migrations.getBranchMigrationPlan({
1730
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1731
+ body: schema,
975
1732
  ...this.extraProps
976
1733
  });
977
1734
  }
978
- getColumn(workspace, database, branch, tableName, columnName) {
979
- return operationsByTag.table.getColumn({
980
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1735
+ executeBranchMigrationPlan({
1736
+ workspace,
1737
+ region,
1738
+ database,
1739
+ branch,
1740
+ plan
1741
+ }) {
1742
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1743
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1744
+ body: plan,
981
1745
  ...this.extraProps
982
1746
  });
983
1747
  }
984
- deleteColumn(workspace, database, branch, tableName, columnName) {
985
- return operationsByTag.table.deleteColumn({
986
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1748
+ getBranchSchemaHistory({
1749
+ workspace,
1750
+ region,
1751
+ database,
1752
+ branch,
1753
+ page
1754
+ }) {
1755
+ return operationsByTag.migrations.getBranchSchemaHistory({
1756
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1757
+ body: { page },
987
1758
  ...this.extraProps
988
1759
  });
989
1760
  }
990
- updateColumn(workspace, database, branch, tableName, columnName, options) {
991
- return operationsByTag.table.updateColumn({
992
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
993
- body: options,
1761
+ compareBranchWithUserSchema({
1762
+ workspace,
1763
+ region,
1764
+ database,
1765
+ branch,
1766
+ schema
1767
+ }) {
1768
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1769
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1770
+ body: { schema },
994
1771
  ...this.extraProps
995
1772
  });
996
1773
  }
997
- }
998
- class RecordsApi {
999
- constructor(extraProps) {
1000
- this.extraProps = extraProps;
1001
- }
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,
1774
+ compareBranchSchemas({
1775
+ workspace,
1776
+ region,
1777
+ database,
1778
+ branch,
1779
+ compare,
1780
+ schema
1781
+ }) {
1782
+ return operationsByTag.migrations.compareBranchSchemas({
1783
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1784
+ body: { schema },
1007
1785
  ...this.extraProps
1008
1786
  });
1009
1787
  }
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,
1788
+ updateBranchSchema({
1789
+ workspace,
1790
+ region,
1791
+ database,
1792
+ branch,
1793
+ migration
1794
+ }) {
1795
+ return operationsByTag.migrations.updateBranchSchema({
1796
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1797
+ body: migration,
1015
1798
  ...this.extraProps
1016
1799
  });
1017
1800
  }
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,
1801
+ previewBranchSchemaEdit({
1802
+ workspace,
1803
+ region,
1804
+ database,
1805
+ branch,
1806
+ data
1807
+ }) {
1808
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1809
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1810
+ body: data,
1023
1811
  ...this.extraProps
1024
1812
  });
1025
1813
  }
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,
1814
+ applyBranchSchemaEdit({
1815
+ workspace,
1816
+ region,
1817
+ database,
1818
+ branch,
1819
+ edits
1820
+ }) {
1821
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1822
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1823
+ body: { edits },
1031
1824
  ...this.extraProps
1032
1825
  });
1033
1826
  }
1034
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
1035
- return operationsByTag.records.deleteRecord({
1036
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1037
- queryParams: options,
1827
+ }
1828
+ class DatabaseApi {
1829
+ constructor(extraProps) {
1830
+ this.extraProps = extraProps;
1831
+ }
1832
+ getDatabaseList({ workspace }) {
1833
+ return operationsByTag.databases.getDatabaseList({
1834
+ pathParams: { workspaceId: workspace },
1038
1835
  ...this.extraProps
1039
1836
  });
1040
1837
  }
1041
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
1042
- return operationsByTag.records.getRecord({
1043
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1044
- queryParams: options,
1838
+ createDatabase({
1839
+ workspace,
1840
+ database,
1841
+ data
1842
+ }) {
1843
+ return operationsByTag.databases.createDatabase({
1844
+ pathParams: { workspaceId: workspace, dbName: database },
1845
+ body: data,
1045
1846
  ...this.extraProps
1046
1847
  });
1047
1848
  }
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 },
1849
+ deleteDatabase({
1850
+ workspace,
1851
+ database
1852
+ }) {
1853
+ return operationsByTag.databases.deleteDatabase({
1854
+ pathParams: { workspaceId: workspace, dbName: database },
1053
1855
  ...this.extraProps
1054
1856
  });
1055
1857
  }
1056
- queryTable(workspace, database, branch, tableName, query) {
1057
- return operationsByTag.records.queryTable({
1058
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1059
- body: query,
1858
+ getDatabaseMetadata({
1859
+ workspace,
1860
+ database
1861
+ }) {
1862
+ return operationsByTag.databases.getDatabaseMetadata({
1863
+ pathParams: { workspaceId: workspace, dbName: database },
1060
1864
  ...this.extraProps
1061
1865
  });
1062
1866
  }
1063
- searchTable(workspace, database, branch, tableName, query) {
1064
- return operationsByTag.records.searchTable({
1065
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1066
- body: query,
1867
+ updateDatabaseMetadata({
1868
+ workspace,
1869
+ database,
1870
+ metadata
1871
+ }) {
1872
+ return operationsByTag.databases.updateDatabaseMetadata({
1873
+ pathParams: { workspaceId: workspace, dbName: database },
1874
+ body: metadata,
1067
1875
  ...this.extraProps
1068
1876
  });
1069
1877
  }
1070
- searchBranch(workspace, database, branch, query) {
1071
- return operationsByTag.records.searchBranch({
1072
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1073
- body: query,
1878
+ listRegions({ workspace }) {
1879
+ return operationsByTag.databases.listRegions({
1880
+ pathParams: { workspaceId: workspace },
1074
1881
  ...this.extraProps
1075
1882
  });
1076
1883
  }
@@ -1086,6 +1893,13 @@ class XataApiPlugin {
1086
1893
  class XataPlugin {
1087
1894
  }
1088
1895
 
1896
+ function cleanFilter(filter) {
1897
+ if (!filter)
1898
+ return void 0;
1899
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1900
+ return values.length > 0 ? filter : void 0;
1901
+ }
1902
+
1089
1903
  var __accessCheck$6 = (obj, member, msg) => {
1090
1904
  if (!member.has(obj))
1091
1905
  throw TypeError("Cannot " + msg);
@@ -1118,11 +1932,11 @@ class Page {
1118
1932
  async previousPage(size, offset) {
1119
1933
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1120
1934
  }
1121
- async firstPage(size, offset) {
1122
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1935
+ async startPage(size, offset) {
1936
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1123
1937
  }
1124
- async lastPage(size, offset) {
1125
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1938
+ async endPage(size, offset) {
1939
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1126
1940
  }
1127
1941
  hasNextPage() {
1128
1942
  return this.meta.page.more;
@@ -1134,7 +1948,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1134
1948
  const PAGINATION_MAX_OFFSET = 800;
1135
1949
  const PAGINATION_DEFAULT_OFFSET = 0;
1136
1950
  function isCursorPaginationOptions(options) {
1137
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1951
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1138
1952
  }
1139
1953
  const _RecordArray = class extends Array {
1140
1954
  constructor(...args) {
@@ -1155,6 +1969,9 @@ const _RecordArray = class extends Array {
1155
1969
  toArray() {
1156
1970
  return new Array(...this);
1157
1971
  }
1972
+ toJSON() {
1973
+ return JSON.parse(JSON.stringify(this.toArray()));
1974
+ }
1158
1975
  map(callbackfn, thisArg) {
1159
1976
  return this.toArray().map(callbackfn, thisArg);
1160
1977
  }
@@ -1166,12 +1983,12 @@ const _RecordArray = class extends Array {
1166
1983
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1167
1984
  return new _RecordArray(newPage);
1168
1985
  }
1169
- async firstPage(size, offset) {
1170
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1986
+ async startPage(size, offset) {
1987
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1171
1988
  return new _RecordArray(newPage);
1172
1989
  }
1173
- async lastPage(size, offset) {
1174
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1990
+ async endPage(size, offset) {
1991
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1175
1992
  return new _RecordArray(newPage);
1176
1993
  }
1177
1994
  hasNextPage() {
@@ -1199,9 +2016,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1199
2016
  setter ? setter.call(obj, value) : member.set(obj, value);
1200
2017
  return value;
1201
2018
  };
1202
- var _table$1, _repository, _data;
2019
+ var __privateMethod$3 = (obj, member, method) => {
2020
+ __accessCheck$5(obj, member, "access private method");
2021
+ return method;
2022
+ };
2023
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1203
2024
  const _Query = class {
1204
2025
  constructor(repository, table, data, rawParent) {
2026
+ __privateAdd$5(this, _cleanFilterConstraint);
1205
2027
  __privateAdd$5(this, _table$1, void 0);
1206
2028
  __privateAdd$5(this, _repository, void 0);
1207
2029
  __privateAdd$5(this, _data, { filter: {} });
@@ -1220,9 +2042,11 @@ const _Query = class {
1220
2042
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1221
2043
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1222
2044
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1223
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
2045
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2046
+ __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
1224
2047
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1225
2048
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2049
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1226
2050
  this.any = this.any.bind(this);
1227
2051
  this.all = this.all.bind(this);
1228
2052
  this.not = this.not.bind(this);
@@ -1258,11 +2082,14 @@ const _Query = class {
1258
2082
  }
1259
2083
  filter(a, b) {
1260
2084
  if (arguments.length === 1) {
1261
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
2085
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
2086
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
2087
+ }));
1262
2088
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1263
2089
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1264
2090
  } else {
1265
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
2091
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
2092
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1266
2093
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1267
2094
  }
1268
2095
  }
@@ -1300,11 +2127,20 @@ const _Query = class {
1300
2127
  }
1301
2128
  }
1302
2129
  async getMany(options = {}) {
1303
- const page = await this.getPaginated(options);
2130
+ const { pagination = {}, ...rest } = options;
2131
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
2132
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
2133
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
2134
+ const results = [...page.records];
2135
+ while (page.hasNextPage() && results.length < size) {
2136
+ page = await page.nextPage();
2137
+ results.push(...page.records);
2138
+ }
1304
2139
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1305
2140
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1306
2141
  }
1307
- return page.records;
2142
+ const array = new RecordArray(page, results.slice(0, size));
2143
+ return array;
1308
2144
  }
1309
2145
  async getAll(options = {}) {
1310
2146
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1318,19 +2154,35 @@ const _Query = class {
1318
2154
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1319
2155
  return records[0] ?? null;
1320
2156
  }
2157
+ async getFirstOrThrow(options = {}) {
2158
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2159
+ if (records[0] === void 0)
2160
+ throw new Error("No results found.");
2161
+ return records[0];
2162
+ }
2163
+ async summarize(params = {}) {
2164
+ const { summaries, summariesFilter, ...options } = params;
2165
+ const query = new _Query(
2166
+ __privateGet$5(this, _repository),
2167
+ __privateGet$5(this, _table$1),
2168
+ options,
2169
+ __privateGet$5(this, _data)
2170
+ );
2171
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2172
+ }
1321
2173
  cache(ttl) {
1322
2174
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1323
2175
  }
1324
2176
  nextPage(size, offset) {
1325
- return this.firstPage(size, offset);
2177
+ return this.startPage(size, offset);
1326
2178
  }
1327
2179
  previousPage(size, offset) {
1328
- return this.firstPage(size, offset);
2180
+ return this.startPage(size, offset);
1329
2181
  }
1330
- firstPage(size, offset) {
2182
+ startPage(size, offset) {
1331
2183
  return this.getPaginated({ pagination: { size, offset } });
1332
2184
  }
1333
- lastPage(size, offset) {
2185
+ endPage(size, offset) {
1334
2186
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1335
2187
  }
1336
2188
  hasNextPage() {
@@ -1341,9 +2193,20 @@ let Query = _Query;
1341
2193
  _table$1 = new WeakMap();
1342
2194
  _repository = new WeakMap();
1343
2195
  _data = new WeakMap();
2196
+ _cleanFilterConstraint = new WeakSet();
2197
+ cleanFilterConstraint_fn = function(column, value) {
2198
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2199
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2200
+ return { $includes: value };
2201
+ }
2202
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
2203
+ return value.id;
2204
+ }
2205
+ return value;
2206
+ };
1344
2207
  function cleanParent(data, parent) {
1345
2208
  if (isCursorPaginationOptions(data.pagination)) {
1346
- return { ...parent, sorting: void 0, filter: void 0 };
2209
+ return { ...parent, sort: void 0, filter: void 0 };
1347
2210
  }
1348
2211
  return parent;
1349
2212
  }
@@ -1402,18 +2265,25 @@ var __privateMethod$2 = (obj, member, method) => {
1402
2265
  __accessCheck$4(obj, member, "access private method");
1403
2266
  return method;
1404
2267
  };
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;
2268
+ 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;
2269
+ const BULK_OPERATION_MAX_SIZE = 1e3;
1406
2270
  class Repository extends Query {
1407
2271
  }
1408
2272
  class RestRepository extends Query {
1409
2273
  constructor(options) {
1410
- super(null, options.table, {});
2274
+ super(
2275
+ null,
2276
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
2277
+ {}
2278
+ );
1411
2279
  __privateAdd$4(this, _insertRecordWithoutId);
1412
2280
  __privateAdd$4(this, _insertRecordWithId);
1413
- __privateAdd$4(this, _bulkInsertTableRecords);
2281
+ __privateAdd$4(this, _insertRecords);
1414
2282
  __privateAdd$4(this, _updateRecordWithID);
2283
+ __privateAdd$4(this, _updateRecords);
1415
2284
  __privateAdd$4(this, _upsertRecordWithID);
1416
2285
  __privateAdd$4(this, _deleteRecord);
2286
+ __privateAdd$4(this, _deleteRecords);
1417
2287
  __privateAdd$4(this, _setCacheQuery);
1418
2288
  __privateAdd$4(this, _getCacheQuery);
1419
2289
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1424,38 +2294,45 @@ class RestRepository extends Query {
1424
2294
  __privateAdd$4(this, _schemaTables$2, void 0);
1425
2295
  __privateAdd$4(this, _trace, void 0);
1426
2296
  __privateSet$4(this, _table, options.table);
1427
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1428
2297
  __privateSet$4(this, _db, options.db);
1429
2298
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1430
2299
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2300
+ __privateSet$4(this, _getFetchProps, async () => {
2301
+ const props = await options.pluginOptions.getFetchProps();
2302
+ return { ...props, sessionID: generateUUID() };
2303
+ });
1431
2304
  const trace = options.pluginOptions.trace ?? defaultTrace;
1432
2305
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1433
2306
  return trace(name, fn, {
1434
2307
  ...options2,
1435
2308
  [TraceAttributes.TABLE]: __privateGet$4(this, _table),
2309
+ [TraceAttributes.KIND]: "sdk-operation",
1436
2310
  [TraceAttributes.VERSION]: VERSION
1437
2311
  });
1438
2312
  });
1439
2313
  }
1440
- async create(a, b, c) {
2314
+ async create(a, b, c, d) {
1441
2315
  return __privateGet$4(this, _trace).call(this, "create", async () => {
2316
+ const ifVersion = parseIfVersion(b, c, d);
1442
2317
  if (Array.isArray(a)) {
1443
2318
  if (a.length === 0)
1444
2319
  return [];
1445
- const columns = isStringArray(b) ? b : void 0;
1446
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2320
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2321
+ const columns = isStringArray(b) ? b : ["*"];
2322
+ const result = await this.read(ids, columns);
2323
+ return result;
1447
2324
  }
1448
2325
  if (isString(a) && isObject(b)) {
1449
2326
  if (a === "")
1450
2327
  throw new Error("The id can't be empty");
1451
2328
  const columns = isStringArray(c) ? c : void 0;
1452
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
2329
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
1453
2330
  }
1454
2331
  if (isObject(a) && isString(a.id)) {
1455
2332
  if (a.id === "")
1456
2333
  throw new Error("The id can't be empty");
1457
2334
  const columns = isStringArray(b) ? b : void 0;
1458
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2335
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
1459
2336
  }
1460
2337
  if (isObject(a)) {
1461
2338
  const columns = isStringArray(b) ? b : void 0;
@@ -1470,22 +2347,23 @@ class RestRepository extends Query {
1470
2347
  if (Array.isArray(a)) {
1471
2348
  if (a.length === 0)
1472
2349
  return [];
1473
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1474
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
2350
+ const ids = a.map((item) => extractId(item));
2351
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1475
2352
  const dictionary = finalObjects.reduce((acc, object) => {
1476
2353
  acc[object.id] = object;
1477
2354
  return acc;
1478
2355
  }, {});
1479
- return ids.map((id2) => dictionary[id2] ?? null);
2356
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1480
2357
  }
1481
- const id = isString(a) ? a : a.id;
1482
- if (isString(id)) {
2358
+ const id = extractId(a);
2359
+ if (id) {
1483
2360
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1484
2361
  try {
1485
2362
  const response = await getRecord({
1486
2363
  pathParams: {
1487
2364
  workspace: "{workspaceId}",
1488
2365
  dbBranchName: "{dbBranch}",
2366
+ region: "{region}",
1489
2367
  tableName: __privateGet$4(this, _table),
1490
2368
  recordId: id
1491
2369
  },
@@ -1493,7 +2371,7 @@ class RestRepository extends Query {
1493
2371
  ...fetchProps
1494
2372
  });
1495
2373
  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);
2374
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1497
2375
  } catch (e) {
1498
2376
  if (isObject(e) && e.status === 404) {
1499
2377
  return null;
@@ -1504,89 +2382,208 @@ class RestRepository extends Query {
1504
2382
  return null;
1505
2383
  });
1506
2384
  }
1507
- async update(a, b, c) {
2385
+ async readOrThrow(a, b) {
2386
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
2387
+ const result = await this.read(a, b);
2388
+ if (Array.isArray(result)) {
2389
+ const missingIds = compact(
2390
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2391
+ );
2392
+ if (missingIds.length > 0) {
2393
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2394
+ }
2395
+ return result;
2396
+ }
2397
+ if (result === null) {
2398
+ const id = extractId(a) ?? "unknown";
2399
+ throw new Error(`Record with id ${id} not found`);
2400
+ }
2401
+ return result;
2402
+ });
2403
+ }
2404
+ async update(a, b, c, d) {
1508
2405
  return __privateGet$4(this, _trace).call(this, "update", async () => {
2406
+ const ifVersion = parseIfVersion(b, c, d);
1509
2407
  if (Array.isArray(a)) {
1510
2408
  if (a.length === 0)
1511
2409
  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");
2410
+ const existing = await this.read(a, ["id"]);
2411
+ const updates = a.filter((_item, index) => existing[index] !== null);
2412
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2413
+ ifVersion,
2414
+ upsert: false
2415
+ });
2416
+ const columns = isStringArray(b) ? b : ["*"];
2417
+ const result = await this.read(a, columns);
2418
+ return result;
2419
+ }
2420
+ try {
2421
+ if (isString(a) && isObject(b)) {
2422
+ const columns = isStringArray(c) ? c : void 0;
2423
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2424
+ }
2425
+ if (isObject(a) && isString(a.id)) {
2426
+ const columns = isStringArray(b) ? b : void 0;
2427
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2428
+ }
2429
+ } catch (error) {
2430
+ if (error.status === 422)
2431
+ return null;
2432
+ throw error;
2433
+ }
2434
+ throw new Error("Invalid arguments for update method");
2435
+ });
2436
+ }
2437
+ async updateOrThrow(a, b, c, d) {
2438
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
2439
+ const result = await this.update(a, b, c, d);
2440
+ if (Array.isArray(result)) {
2441
+ const missingIds = compact(
2442
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2443
+ );
2444
+ if (missingIds.length > 0) {
2445
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1514
2446
  }
2447
+ return result;
2448
+ }
2449
+ if (result === null) {
2450
+ const id = extractId(a) ?? "unknown";
2451
+ throw new Error(`Record with id ${id} not found`);
2452
+ }
2453
+ return result;
2454
+ });
2455
+ }
2456
+ async createOrUpdate(a, b, c, d) {
2457
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2458
+ const ifVersion = parseIfVersion(b, c, d);
2459
+ if (Array.isArray(a)) {
2460
+ if (a.length === 0)
2461
+ return [];
2462
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2463
+ ifVersion,
2464
+ upsert: true
2465
+ });
1515
2466
  const columns = isStringArray(b) ? b : ["*"];
1516
- return Promise.all(a.map((object) => this.update(object, columns)));
2467
+ const result = await this.read(a, columns);
2468
+ return result;
1517
2469
  }
1518
2470
  if (isString(a) && isObject(b)) {
1519
2471
  const columns = isStringArray(c) ? c : void 0;
1520
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
2472
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1521
2473
  }
1522
2474
  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);
2475
+ const columns = isStringArray(c) ? c : void 0;
2476
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1525
2477
  }
1526
- throw new Error("Invalid arguments for update method");
2478
+ throw new Error("Invalid arguments for createOrUpdate method");
1527
2479
  });
1528
2480
  }
1529
- async createOrUpdate(a, b, c) {
1530
- return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2481
+ async createOrReplace(a, b, c, d) {
2482
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2483
+ const ifVersion = parseIfVersion(b, c, d);
1531
2484
  if (Array.isArray(a)) {
1532
2485
  if (a.length === 0)
1533
2486
  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
- }
2487
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
1537
2488
  const columns = isStringArray(b) ? b : ["*"];
1538
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
2489
+ const result = await this.read(ids, columns);
2490
+ return result;
1539
2491
  }
1540
2492
  if (isString(a) && isObject(b)) {
1541
2493
  const columns = isStringArray(c) ? c : void 0;
1542
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
2494
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
1543
2495
  }
1544
2496
  if (isObject(a) && isString(a.id)) {
1545
2497
  const columns = isStringArray(c) ? c : void 0;
1546
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2498
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
1547
2499
  }
1548
- throw new Error("Invalid arguments for createOrUpdate method");
2500
+ throw new Error("Invalid arguments for createOrReplace method");
1549
2501
  });
1550
2502
  }
1551
- async delete(a) {
2503
+ async delete(a, b) {
1552
2504
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1553
2505
  if (Array.isArray(a)) {
1554
2506
  if (a.length === 0)
1555
- 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
- await Promise.all(a.map((id) => this.delete(id)));
1560
- return;
2507
+ return [];
2508
+ const ids = a.map((o) => {
2509
+ if (isString(o))
2510
+ return o;
2511
+ if (isString(o.id))
2512
+ return o.id;
2513
+ throw new Error("Invalid arguments for delete method");
2514
+ });
2515
+ const columns = isStringArray(b) ? b : ["*"];
2516
+ const result = await this.read(a, columns);
2517
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2518
+ return result;
1561
2519
  }
1562
2520
  if (isString(a)) {
1563
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1564
- return;
2521
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1565
2522
  }
1566
2523
  if (isObject(a) && isString(a.id)) {
1567
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1568
- return;
2524
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1569
2525
  }
1570
2526
  throw new Error("Invalid arguments for delete method");
1571
2527
  });
1572
2528
  }
2529
+ async deleteOrThrow(a, b) {
2530
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
2531
+ const result = await this.delete(a, b);
2532
+ if (Array.isArray(result)) {
2533
+ const missingIds = compact(
2534
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2535
+ );
2536
+ if (missingIds.length > 0) {
2537
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2538
+ }
2539
+ return result;
2540
+ } else if (result === null) {
2541
+ const id = extractId(a) ?? "unknown";
2542
+ throw new Error(`Record with id ${id} not found`);
2543
+ }
2544
+ return result;
2545
+ });
2546
+ }
1573
2547
  async search(query, options = {}) {
1574
2548
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1575
2549
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1576
2550
  const { records } = await searchTable({
1577
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2551
+ pathParams: {
2552
+ workspace: "{workspaceId}",
2553
+ dbBranchName: "{dbBranch}",
2554
+ region: "{region}",
2555
+ tableName: __privateGet$4(this, _table)
2556
+ },
1578
2557
  body: {
1579
2558
  query,
1580
2559
  fuzziness: options.fuzziness,
1581
2560
  prefix: options.prefix,
1582
2561
  highlight: options.highlight,
1583
2562
  filter: options.filter,
1584
- boosters: options.boosters
2563
+ boosters: options.boosters,
2564
+ page: options.page,
2565
+ target: options.target
1585
2566
  },
1586
2567
  ...fetchProps
1587
2568
  });
1588
2569
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1589
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2570
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2571
+ });
2572
+ }
2573
+ async aggregate(aggs, filter) {
2574
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2575
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2576
+ const result = await aggregateTable({
2577
+ pathParams: {
2578
+ workspace: "{workspaceId}",
2579
+ dbBranchName: "{dbBranch}",
2580
+ region: "{region}",
2581
+ tableName: __privateGet$4(this, _table)
2582
+ },
2583
+ body: { aggs, filter },
2584
+ ...fetchProps
2585
+ });
2586
+ return result;
1590
2587
  });
1591
2588
  }
1592
2589
  async query(query) {
@@ -1595,24 +2592,57 @@ class RestRepository extends Query {
1595
2592
  if (cacheQuery)
1596
2593
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1597
2594
  const data = query.getQueryOptions();
1598
- const body = {
1599
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1600
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1601
- page: data.pagination,
1602
- columns: data.columns
1603
- };
1604
2595
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1605
2596
  const { meta, records: objects } = await queryTable({
1606
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1607
- body,
2597
+ pathParams: {
2598
+ workspace: "{workspaceId}",
2599
+ dbBranchName: "{dbBranch}",
2600
+ region: "{region}",
2601
+ tableName: __privateGet$4(this, _table)
2602
+ },
2603
+ body: {
2604
+ filter: cleanFilter(data.filter),
2605
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2606
+ page: data.pagination,
2607
+ columns: data.columns ?? ["*"],
2608
+ consistency: data.consistency
2609
+ },
2610
+ fetchOptions: data.fetchOptions,
1608
2611
  ...fetchProps
1609
2612
  });
1610
2613
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1611
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
2614
+ const records = objects.map(
2615
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2616
+ );
1612
2617
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1613
2618
  return new Page(query, meta, records);
1614
2619
  });
1615
2620
  }
2621
+ async summarizeTable(query, summaries, summariesFilter) {
2622
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2623
+ const data = query.getQueryOptions();
2624
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2625
+ const result = await summarizeTable({
2626
+ pathParams: {
2627
+ workspace: "{workspaceId}",
2628
+ dbBranchName: "{dbBranch}",
2629
+ region: "{region}",
2630
+ tableName: __privateGet$4(this, _table)
2631
+ },
2632
+ body: {
2633
+ filter: cleanFilter(data.filter),
2634
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2635
+ columns: data.columns,
2636
+ consistency: data.consistency,
2637
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2638
+ summaries,
2639
+ summariesFilter
2640
+ },
2641
+ ...fetchProps
2642
+ });
2643
+ return result;
2644
+ });
2645
+ }
1616
2646
  }
1617
2647
  _table = new WeakMap();
1618
2648
  _getFetchProps = new WeakMap();
@@ -1628,6 +2658,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1628
2658
  pathParams: {
1629
2659
  workspace: "{workspaceId}",
1630
2660
  dbBranchName: "{dbBranch}",
2661
+ region: "{region}",
1631
2662
  tableName: __privateGet$4(this, _table)
1632
2663
  },
1633
2664
  queryParams: { columns },
@@ -1635,74 +2666,173 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1635
2666
  ...fetchProps
1636
2667
  });
1637
2668
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1638
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2669
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1639
2670
  };
1640
2671
  _insertRecordWithId = new WeakSet();
1641
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
2672
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
1642
2673
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1643
2674
  const record = transformObjectLinks(object);
1644
2675
  const response = await insertRecordWithID({
1645
2676
  pathParams: {
1646
2677
  workspace: "{workspaceId}",
1647
2678
  dbBranchName: "{dbBranch}",
2679
+ region: "{region}",
1648
2680
  tableName: __privateGet$4(this, _table),
1649
2681
  recordId
1650
2682
  },
1651
2683
  body: record,
1652
- queryParams: { createOnly: true, columns },
2684
+ queryParams: { createOnly, columns, ifVersion },
1653
2685
  ...fetchProps
1654
2686
  });
1655
2687
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1656
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2688
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1657
2689
  };
1658
- _bulkInsertTableRecords = new WeakSet();
1659
- bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
2690
+ _insertRecords = new WeakSet();
2691
+ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
1660
2692
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1661
- const records = objects.map((object) => transformObjectLinks(object));
1662
- const response = await bulkInsertTableRecords({
1663
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1664
- queryParams: { columns },
1665
- body: { records },
1666
- ...fetchProps
1667
- });
1668
- if (!isResponseWithRecords(response)) {
1669
- throw new Error("Request included columns but server didn't include them");
2693
+ const chunkedOperations = chunk(
2694
+ objects.map((object) => ({
2695
+ insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2696
+ })),
2697
+ BULK_OPERATION_MAX_SIZE
2698
+ );
2699
+ const ids = [];
2700
+ for (const operations of chunkedOperations) {
2701
+ const { results } = await branchTransaction({
2702
+ pathParams: {
2703
+ workspace: "{workspaceId}",
2704
+ dbBranchName: "{dbBranch}",
2705
+ region: "{region}"
2706
+ },
2707
+ body: { operations },
2708
+ ...fetchProps
2709
+ });
2710
+ for (const result of results) {
2711
+ if (result.operation === "insert") {
2712
+ ids.push(result.id);
2713
+ } else {
2714
+ ids.push(null);
2715
+ }
2716
+ }
1670
2717
  }
1671
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1672
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2718
+ return ids;
1673
2719
  };
1674
2720
  _updateRecordWithID = new WeakSet();
1675
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2721
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1676
2722
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1677
- const record = transformObjectLinks(object);
1678
- const response = await updateRecordWithID({
1679
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1680
- queryParams: { columns },
1681
- body: record,
1682
- ...fetchProps
1683
- });
1684
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1685
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2723
+ const { id: _id, ...record } = transformObjectLinks(object);
2724
+ try {
2725
+ const response = await updateRecordWithID({
2726
+ pathParams: {
2727
+ workspace: "{workspaceId}",
2728
+ dbBranchName: "{dbBranch}",
2729
+ region: "{region}",
2730
+ tableName: __privateGet$4(this, _table),
2731
+ recordId
2732
+ },
2733
+ queryParams: { columns, ifVersion },
2734
+ body: record,
2735
+ ...fetchProps
2736
+ });
2737
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2738
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2739
+ } catch (e) {
2740
+ if (isObject(e) && e.status === 404) {
2741
+ return null;
2742
+ }
2743
+ throw e;
2744
+ }
2745
+ };
2746
+ _updateRecords = new WeakSet();
2747
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2748
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2749
+ const chunkedOperations = chunk(
2750
+ objects.map(({ id, ...object }) => ({
2751
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2752
+ })),
2753
+ BULK_OPERATION_MAX_SIZE
2754
+ );
2755
+ const ids = [];
2756
+ for (const operations of chunkedOperations) {
2757
+ const { results } = await branchTransaction({
2758
+ pathParams: {
2759
+ workspace: "{workspaceId}",
2760
+ dbBranchName: "{dbBranch}",
2761
+ region: "{region}"
2762
+ },
2763
+ body: { operations },
2764
+ ...fetchProps
2765
+ });
2766
+ for (const result of results) {
2767
+ if (result.operation === "update") {
2768
+ ids.push(result.id);
2769
+ } else {
2770
+ ids.push(null);
2771
+ }
2772
+ }
2773
+ }
2774
+ return ids;
1686
2775
  };
1687
2776
  _upsertRecordWithID = new WeakSet();
1688
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2777
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1689
2778
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1690
2779
  const response = await upsertRecordWithID({
1691
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1692
- queryParams: { columns },
2780
+ pathParams: {
2781
+ workspace: "{workspaceId}",
2782
+ dbBranchName: "{dbBranch}",
2783
+ region: "{region}",
2784
+ tableName: __privateGet$4(this, _table),
2785
+ recordId
2786
+ },
2787
+ queryParams: { columns, ifVersion },
1693
2788
  body: object,
1694
2789
  ...fetchProps
1695
2790
  });
1696
2791
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1697
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2792
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1698
2793
  };
1699
2794
  _deleteRecord = new WeakSet();
1700
- deleteRecord_fn = async function(recordId) {
2795
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1701
2796
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1702
- await deleteRecord({
1703
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1704
- ...fetchProps
1705
- });
2797
+ try {
2798
+ const response = await deleteRecord({
2799
+ pathParams: {
2800
+ workspace: "{workspaceId}",
2801
+ dbBranchName: "{dbBranch}",
2802
+ region: "{region}",
2803
+ tableName: __privateGet$4(this, _table),
2804
+ recordId
2805
+ },
2806
+ queryParams: { columns },
2807
+ ...fetchProps
2808
+ });
2809
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2810
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2811
+ } catch (e) {
2812
+ if (isObject(e) && e.status === 404) {
2813
+ return null;
2814
+ }
2815
+ throw e;
2816
+ }
2817
+ };
2818
+ _deleteRecords = new WeakSet();
2819
+ deleteRecords_fn = async function(recordIds) {
2820
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2821
+ const chunkedOperations = chunk(
2822
+ recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2823
+ BULK_OPERATION_MAX_SIZE
2824
+ );
2825
+ for (const operations of chunkedOperations) {
2826
+ await branchTransaction({
2827
+ pathParams: {
2828
+ workspace: "{workspaceId}",
2829
+ dbBranchName: "{dbBranch}",
2830
+ region: "{region}"
2831
+ },
2832
+ body: { operations },
2833
+ ...fetchProps
2834
+ });
2835
+ }
1706
2836
  };
1707
2837
  _setCacheQuery = new WeakSet();
1708
2838
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1726,7 +2856,7 @@ getSchemaTables_fn$1 = async function() {
1726
2856
  return __privateGet$4(this, _schemaTables$2);
1727
2857
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1728
2858
  const { schema } = await getBranchDetails({
1729
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2859
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1730
2860
  ...fetchProps
1731
2861
  });
1732
2862
  __privateSet$4(this, _schemaTables$2, schema.tables);
@@ -1739,22 +2869,24 @@ const transformObjectLinks = (object) => {
1739
2869
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1740
2870
  }, {});
1741
2871
  };
1742
- const initObject = (db, schemaTables, table, object) => {
1743
- const result = {};
2872
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2873
+ const data = {};
1744
2874
  const { xata, ...rest } = object ?? {};
1745
- Object.assign(result, rest);
2875
+ Object.assign(data, rest);
1746
2876
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1747
2877
  if (!columns)
1748
2878
  console.error(`Table ${table} not found in schema`);
1749
2879
  for (const column of columns ?? []) {
1750
- const value = result[column.name];
2880
+ if (!isValidColumn(selectedColumns, column))
2881
+ continue;
2882
+ const value = data[column.name];
1751
2883
  switch (column.type) {
1752
2884
  case "datetime": {
1753
- const date = value !== void 0 ? new Date(value) : void 0;
1754
- if (date && isNaN(date.getTime())) {
2885
+ const date = value !== void 0 ? new Date(value) : null;
2886
+ if (date !== null && isNaN(date.getTime())) {
1755
2887
  console.error(`Failed to parse date ${value} for field ${column.name}`);
1756
- } else if (date) {
1757
- result[column.name] = date;
2888
+ } else {
2889
+ data[column.name] = date;
1758
2890
  }
1759
2891
  break;
1760
2892
  }
@@ -1763,32 +2895,82 @@ const initObject = (db, schemaTables, table, object) => {
1763
2895
  if (!linkTable) {
1764
2896
  console.error(`Failed to parse link for field ${column.name}`);
1765
2897
  } else if (isObject(value)) {
1766
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2898
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2899
+ if (item === column.name) {
2900
+ return [...acc, "*"];
2901
+ }
2902
+ if (item.startsWith(`${column.name}.`)) {
2903
+ const [, ...path] = item.split(".");
2904
+ return [...acc, path.join(".")];
2905
+ }
2906
+ return acc;
2907
+ }, []);
2908
+ data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2909
+ } else {
2910
+ data[column.name] = null;
1767
2911
  }
1768
2912
  break;
1769
2913
  }
2914
+ default:
2915
+ data[column.name] = value ?? null;
2916
+ if (column.notNull === true && value === null) {
2917
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2918
+ }
2919
+ break;
1770
2920
  }
1771
2921
  }
1772
- result.read = function(columns2) {
1773
- return db[table].read(result["id"], columns2);
2922
+ const record = { ...data };
2923
+ record.read = function(columns2) {
2924
+ return db[table].read(record["id"], columns2);
1774
2925
  };
1775
- result.update = function(data, columns2) {
1776
- return db[table].update(result["id"], data, columns2);
2926
+ record.update = function(data2, b, c) {
2927
+ const columns2 = isStringArray(b) ? b : ["*"];
2928
+ const ifVersion = parseIfVersion(b, c);
2929
+ return db[table].update(record["id"], data2, columns2, { ifVersion });
1777
2930
  };
1778
- result.delete = function() {
1779
- return db[table].delete(result["id"]);
2931
+ record.replace = function(data2, b, c) {
2932
+ const columns2 = isStringArray(b) ? b : ["*"];
2933
+ const ifVersion = parseIfVersion(b, c);
2934
+ return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
1780
2935
  };
1781
- result.getMetadata = function() {
2936
+ record.delete = function() {
2937
+ return db[table].delete(record["id"]);
2938
+ };
2939
+ record.getMetadata = function() {
1782
2940
  return xata;
1783
2941
  };
1784
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
1785
- Object.defineProperty(result, prop, { enumerable: false });
2942
+ record.toJSON = function() {
2943
+ return JSON.parse(JSON.stringify(transformObjectLinks(data)));
2944
+ };
2945
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toJSON"]) {
2946
+ Object.defineProperty(record, prop, { enumerable: false });
1786
2947
  }
1787
- Object.freeze(result);
1788
- return result;
2948
+ Object.freeze(record);
2949
+ return record;
1789
2950
  };
1790
- function isResponseWithRecords(value) {
1791
- return isObject(value) && Array.isArray(value.records);
2951
+ function extractId(value) {
2952
+ if (isString(value))
2953
+ return value;
2954
+ if (isObject(value) && isString(value.id))
2955
+ return value.id;
2956
+ return void 0;
2957
+ }
2958
+ function isValidColumn(columns, column) {
2959
+ if (columns.includes("*"))
2960
+ return true;
2961
+ if (column.type === "link") {
2962
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2963
+ return linkColumns.length > 0;
2964
+ }
2965
+ return columns.includes(column.name);
2966
+ }
2967
+ function parseIfVersion(...args) {
2968
+ for (const arg of args) {
2969
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
2970
+ return arg.ifVersion;
2971
+ }
2972
+ }
2973
+ return void 0;
1792
2974
  }
1793
2975
 
1794
2976
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1840,18 +3022,25 @@ class SimpleCache {
1840
3022
  }
1841
3023
  _map = new WeakMap();
1842
3024
 
1843
- const gt = (value) => ({ $gt: value });
1844
- const ge = (value) => ({ $ge: value });
1845
- const gte = (value) => ({ $ge: value });
1846
- const lt = (value) => ({ $lt: value });
1847
- const lte = (value) => ({ $le: value });
1848
- const le = (value) => ({ $le: value });
3025
+ const greaterThan = (value) => ({ $gt: value });
3026
+ const gt = greaterThan;
3027
+ const greaterThanEquals = (value) => ({ $ge: value });
3028
+ const greaterEquals = greaterThanEquals;
3029
+ const gte = greaterThanEquals;
3030
+ const ge = greaterThanEquals;
3031
+ const lessThan = (value) => ({ $lt: value });
3032
+ const lt = lessThan;
3033
+ const lessThanEquals = (value) => ({ $le: value });
3034
+ const lessEquals = lessThanEquals;
3035
+ const lte = lessThanEquals;
3036
+ const le = lessThanEquals;
1849
3037
  const exists = (column) => ({ $exists: column });
1850
3038
  const notExists = (column) => ({ $notExists: column });
1851
3039
  const startsWith = (value) => ({ $startsWith: value });
1852
3040
  const endsWith = (value) => ({ $endsWith: value });
1853
3041
  const pattern = (value) => ({ $pattern: value });
1854
3042
  const is = (value) => ({ $is: value });
3043
+ const equals = is;
1855
3044
  const isNot = (value) => ({ $isNot: value });
1856
3045
  const contains = (value) => ({ $contains: value });
1857
3046
  const includes = (value) => ({ $includes: value });
@@ -1948,7 +3137,7 @@ class SearchPlugin extends XataPlugin {
1948
3137
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1949
3138
  return records.map((record) => {
1950
3139
  const { table = "orphan" } = record.xata;
1951
- return { table, record: initObject(this.db, schemaTables, table, record) };
3140
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1952
3141
  });
1953
3142
  },
1954
3143
  byTable: async (query, options = {}) => {
@@ -1957,7 +3146,7 @@ class SearchPlugin extends XataPlugin {
1957
3146
  return records.reduce((acc, record) => {
1958
3147
  const { table = "orphan" } = record.xata;
1959
3148
  const items = acc[table] ?? [];
1960
- const item = initObject(this.db, schemaTables, table, record);
3149
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1961
3150
  return { ...acc, [table]: [...items, item] };
1962
3151
  }, {});
1963
3152
  }
@@ -1968,10 +3157,10 @@ _schemaTables = new WeakMap();
1968
3157
  _search = new WeakSet();
1969
3158
  search_fn = async function(query, options, getFetchProps) {
1970
3159
  const fetchProps = await getFetchProps();
1971
- const { tables, fuzziness, highlight, prefix } = options ?? {};
3160
+ const { tables, fuzziness, highlight, prefix, page } = options ?? {};
1972
3161
  const { records } = await searchBranch({
1973
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1974
- body: { tables, query, fuzziness, prefix, highlight },
3162
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3163
+ body: { tables, query, fuzziness, prefix, highlight, page },
1975
3164
  ...fetchProps
1976
3165
  });
1977
3166
  return records;
@@ -1982,25 +3171,37 @@ getSchemaTables_fn = async function(getFetchProps) {
1982
3171
  return __privateGet$1(this, _schemaTables);
1983
3172
  const fetchProps = await getFetchProps();
1984
3173
  const { schema } = await getBranchDetails({
1985
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
3174
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1986
3175
  ...fetchProps
1987
3176
  });
1988
3177
  __privateSet$1(this, _schemaTables, schema.tables);
1989
3178
  return schema.tables;
1990
3179
  };
1991
3180
 
3181
+ class TransactionPlugin extends XataPlugin {
3182
+ build({ getFetchProps }) {
3183
+ return {
3184
+ run: async (operations) => {
3185
+ const fetchProps = await getFetchProps();
3186
+ const response = await branchTransaction({
3187
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3188
+ body: { operations },
3189
+ ...fetchProps
3190
+ });
3191
+ return response;
3192
+ }
3193
+ };
3194
+ }
3195
+ }
3196
+
1992
3197
  const isBranchStrategyBuilder = (strategy) => {
1993
3198
  return typeof strategy === "function";
1994
3199
  };
1995
3200
 
1996
3201
  async function getCurrentBranchName(options) {
1997
3202
  const { branch, envBranch } = getEnvironment();
1998
- if (branch) {
1999
- const details = await getDatabaseBranch(branch, options);
2000
- if (details)
2001
- return branch;
2002
- console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
2003
- }
3203
+ if (branch)
3204
+ return branch;
2004
3205
  const gitBranch = envBranch || await getGitBranch();
2005
3206
  return resolveXataBranch(gitBranch, options);
2006
3207
  }
@@ -2020,16 +3221,20 @@ async function resolveXataBranch(gitBranch, options) {
2020
3221
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2021
3222
  );
2022
3223
  const [protocol, , host, , dbName] = databaseURL.split("/");
2023
- const [workspace] = host.split(".");
3224
+ const urlParts = parseWorkspacesUrlParts(host);
3225
+ if (!urlParts)
3226
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3227
+ const { workspace, region } = urlParts;
2024
3228
  const { fallbackBranch } = getEnvironment();
2025
3229
  const { branch } = await resolveBranch({
2026
3230
  apiKey,
2027
3231
  apiUrl: databaseURL,
2028
3232
  fetchImpl: getFetchImplementation(options?.fetchImpl),
2029
3233
  workspacesApiUrl: `${protocol}//${host}`,
2030
- pathParams: { dbName, workspace },
3234
+ pathParams: { dbName, workspace, region },
2031
3235
  queryParams: { gitBranch, fallbackBranch },
2032
- trace: defaultTrace
3236
+ trace: defaultTrace,
3237
+ clientName: options?.clientName
2033
3238
  });
2034
3239
  return branch;
2035
3240
  }
@@ -2045,15 +3250,17 @@ async function getDatabaseBranch(branch, options) {
2045
3250
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2046
3251
  );
2047
3252
  const [protocol, , host, , database] = databaseURL.split("/");
2048
- const [workspace] = host.split(".");
2049
- const dbBranchName = `${database}:${branch}`;
3253
+ const urlParts = parseWorkspacesUrlParts(host);
3254
+ if (!urlParts)
3255
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3256
+ const { workspace, region } = urlParts;
2050
3257
  try {
2051
3258
  return await getBranchDetails({
2052
3259
  apiKey,
2053
3260
  apiUrl: databaseURL,
2054
3261
  fetchImpl: getFetchImplementation(options?.fetchImpl),
2055
3262
  workspacesApiUrl: `${protocol}//${host}`,
2056
- pathParams: { dbBranchName, workspace },
3263
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
2057
3264
  trace: defaultTrace
2058
3265
  });
2059
3266
  } catch (err) {
@@ -2111,8 +3318,10 @@ const buildClient = (plugins) => {
2111
3318
  };
2112
3319
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2113
3320
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3321
+ const transactions = new TransactionPlugin().build(pluginOptions);
2114
3322
  this.db = db;
2115
3323
  this.search = search;
3324
+ this.transactions = transactions;
2116
3325
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
2117
3326
  if (namespace === void 0)
2118
3327
  continue;
@@ -2132,17 +3341,41 @@ const buildClient = (plugins) => {
2132
3341
  return { databaseURL, branch };
2133
3342
  }
2134
3343
  }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3344
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3345
+ const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3346
+ if (isBrowser && !enableBrowser) {
3347
+ throw new Error(
3348
+ "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."
3349
+ );
3350
+ }
2135
3351
  const fetch = getFetchImplementation(options?.fetch);
2136
3352
  const databaseURL = options?.databaseURL || getDatabaseURL();
2137
3353
  const apiKey = options?.apiKey || getAPIKey();
2138
3354
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2139
3355
  const trace = options?.trace ?? defaultTrace;
2140
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2141
- if (!databaseURL || !apiKey) {
2142
- throw new Error("Options databaseURL and apiKey are required");
3356
+ const clientName = options?.clientName;
3357
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3358
+ apiKey,
3359
+ databaseURL,
3360
+ fetchImpl: options?.fetch,
3361
+ clientName: options?.clientName
3362
+ });
3363
+ if (!apiKey) {
3364
+ throw new Error("Option apiKey is required");
2143
3365
  }
2144
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2145
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
3366
+ if (!databaseURL) {
3367
+ throw new Error("Option databaseURL is required");
3368
+ }
3369
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
3370
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3371
+ fetch,
3372
+ apiKey,
3373
+ databaseURL,
3374
+ branch,
3375
+ trace,
3376
+ clientID,
3377
+ clientName
3378
+ }) {
2146
3379
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2147
3380
  if (!branchValue)
2148
3381
  throw new Error("Unable to resolve branch value");
@@ -2152,10 +3385,12 @@ const buildClient = (plugins) => {
2152
3385
  apiUrl: "",
2153
3386
  workspacesApiUrl: (path, params) => {
2154
3387
  const hasBranch = params.dbBranchName ?? params.branch;
2155
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
3388
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2156
3389
  return databaseURL + newPath;
2157
3390
  },
2158
- trace
3391
+ trace,
3392
+ clientID,
3393
+ clientName
2159
3394
  };
2160
3395
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2161
3396
  if (__privateGet(this, _branch))
@@ -2246,7 +3481,7 @@ const deserialize = (json) => {
2246
3481
  };
2247
3482
 
2248
3483
  function buildWorkerRunner(config) {
2249
- return function xataWorker(name, _worker) {
3484
+ return function xataWorker(name, worker) {
2250
3485
  return async (...args) => {
2251
3486
  const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2252
3487
  const result = await fetch(url, {
@@ -2268,6 +3503,7 @@ class XataError extends Error {
2268
3503
  }
2269
3504
 
2270
3505
  exports.BaseClient = BaseClient;
3506
+ exports.FetcherError = FetcherError;
2271
3507
  exports.Operations = operationsByTag;
2272
3508
  exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
2273
3509
  exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
@@ -2289,13 +3525,20 @@ exports.XataPlugin = XataPlugin;
2289
3525
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2290
3526
  exports.addGitBranchesEntry = addGitBranchesEntry;
2291
3527
  exports.addTableColumn = addTableColumn;
3528
+ exports.aggregateTable = aggregateTable;
3529
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3530
+ exports.branchTransaction = branchTransaction;
2292
3531
  exports.buildClient = buildClient;
2293
3532
  exports.buildWorkerRunner = buildWorkerRunner;
2294
3533
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2295
3534
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
3535
+ exports.compareBranchSchemas = compareBranchSchemas;
3536
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3537
+ exports.compareMigrationRequest = compareMigrationRequest;
2296
3538
  exports.contains = contains;
2297
3539
  exports.createBranch = createBranch;
2298
3540
  exports.createDatabase = createDatabase;
3541
+ exports.createMigrationRequest = createMigrationRequest;
2299
3542
  exports.createTable = createTable;
2300
3543
  exports.createUserAPIKey = createUserAPIKey;
2301
3544
  exports.createWorkspace = createWorkspace;
@@ -2309,6 +3552,7 @@ exports.deleteUserAPIKey = deleteUserAPIKey;
2309
3552
  exports.deleteWorkspace = deleteWorkspace;
2310
3553
  exports.deserialize = deserialize;
2311
3554
  exports.endsWith = endsWith;
3555
+ exports.equals = equals;
2312
3556
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2313
3557
  exports.exists = exists;
2314
3558
  exports.ge = ge;
@@ -2318,6 +3562,7 @@ exports.getBranchList = getBranchList;
2318
3562
  exports.getBranchMetadata = getBranchMetadata;
2319
3563
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2320
3564
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
3565
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2321
3566
  exports.getBranchStats = getBranchStats;
2322
3567
  exports.getColumn = getColumn;
2323
3568
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
@@ -2326,6 +3571,9 @@ exports.getDatabaseList = getDatabaseList;
2326
3571
  exports.getDatabaseMetadata = getDatabaseMetadata;
2327
3572
  exports.getDatabaseURL = getDatabaseURL;
2328
3573
  exports.getGitBranchesMapping = getGitBranchesMapping;
3574
+ exports.getHostUrl = getHostUrl;
3575
+ exports.getMigrationRequest = getMigrationRequest;
3576
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2329
3577
  exports.getRecord = getRecord;
2330
3578
  exports.getTableColumns = getTableColumns;
2331
3579
  exports.getTableSchema = getTableSchema;
@@ -2334,6 +3582,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2334
3582
  exports.getWorkspace = getWorkspace;
2335
3583
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2336
3584
  exports.getWorkspacesList = getWorkspacesList;
3585
+ exports.greaterEquals = greaterEquals;
3586
+ exports.greaterThan = greaterThan;
3587
+ exports.greaterThanEquals = greaterThanEquals;
2337
3588
  exports.gt = gt;
2338
3589
  exports.gte = gte;
2339
3590
  exports.includes = includes;
@@ -2345,15 +3596,27 @@ exports.insertRecordWithID = insertRecordWithID;
2345
3596
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2346
3597
  exports.is = is;
2347
3598
  exports.isCursorPaginationOptions = isCursorPaginationOptions;
3599
+ exports.isHostProviderAlias = isHostProviderAlias;
3600
+ exports.isHostProviderBuilder = isHostProviderBuilder;
2348
3601
  exports.isIdentifiable = isIdentifiable;
2349
3602
  exports.isNot = isNot;
2350
3603
  exports.isXataRecord = isXataRecord;
2351
3604
  exports.le = le;
3605
+ exports.lessEquals = lessEquals;
3606
+ exports.lessThan = lessThan;
3607
+ exports.lessThanEquals = lessThanEquals;
3608
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3609
+ exports.listRegions = listRegions;
2352
3610
  exports.lt = lt;
2353
3611
  exports.lte = lte;
3612
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2354
3613
  exports.notExists = notExists;
2355
3614
  exports.operationsByTag = operationsByTag;
3615
+ exports.parseProviderString = parseProviderString;
3616
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
2356
3617
  exports.pattern = pattern;
3618
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3619
+ exports.queryMigrationRequests = queryMigrationRequests;
2357
3620
  exports.queryTable = queryTable;
2358
3621
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2359
3622
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2364,8 +3627,12 @@ exports.searchTable = searchTable;
2364
3627
  exports.serialize = serialize;
2365
3628
  exports.setTableSchema = setTableSchema;
2366
3629
  exports.startsWith = startsWith;
3630
+ exports.summarizeTable = summarizeTable;
2367
3631
  exports.updateBranchMetadata = updateBranchMetadata;
3632
+ exports.updateBranchSchema = updateBranchSchema;
2368
3633
  exports.updateColumn = updateColumn;
3634
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
3635
+ exports.updateMigrationRequest = updateMigrationRequest;
2369
3636
  exports.updateRecordWithID = updateRecordWithID;
2370
3637
  exports.updateTable = updateTable;
2371
3638
  exports.updateUser = updateUser;