@xata.io/client 0.0.0-alpha.vf54f8ba → 0.0.0-alpha.vf59e81b

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,27 +1,8 @@
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
8
  }
@@ -60,6 +41,21 @@ function isString(value) {
60
41
  function isStringArray(value) {
61
42
  return isDefined(value) && Array.isArray(value) && value.every(isString);
62
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
+ }
63
59
  function toBase64(value) {
64
60
  try {
65
61
  return btoa(value);
@@ -68,10 +64,31 @@ function toBase64(value) {
68
64
  return buf.from(value).toString("base64");
69
65
  }
70
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
+ }
71
88
 
72
89
  function getEnvironment() {
73
90
  try {
74
- if (isObject(process) && isObject(process.env)) {
91
+ if (isDefined(process) && isDefined(process.env)) {
75
92
  return {
76
93
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
77
94
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
@@ -102,6 +119,25 @@ function getEnvironment() {
102
119
  fallbackBranch: getGlobalFallbackBranch()
103
120
  };
104
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
+ }
105
141
  function getGlobalApiKey() {
106
142
  try {
107
143
  return XATA_API_KEY;
@@ -130,28 +166,14 @@ function getGlobalFallbackBranch() {
130
166
  return void 0;
131
167
  }
132
168
  }
133
- async function getGitBranch() {
134
- const cmd = ["git", "branch", "--show-current"];
135
- const fullCmd = cmd.join(" ");
136
- const nodeModule = ["child", "process"].join("_");
137
- const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
138
- try {
139
- if (typeof require === "function") {
140
- return require(nodeModule).execSync(fullCmd, execOptions).trim();
141
- }
142
- const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
143
- return execSync(fullCmd, execOptions).toString().trim();
144
- } catch (err) {
145
- }
169
+ function getDatabaseURL() {
146
170
  try {
147
- if (isObject(Deno)) {
148
- const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
149
- return new TextDecoder().decode(await process2.output()).trim();
150
- }
171
+ const { databaseURL } = getEnvironment();
172
+ return databaseURL;
151
173
  } catch (err) {
174
+ return void 0;
152
175
  }
153
176
  }
154
-
155
177
  function getAPIKey() {
156
178
  try {
157
179
  const { apiKey } = getEnvironment();
@@ -161,6 +183,29 @@ function getAPIKey() {
161
183
  }
162
184
  }
163
185
 
186
+ var __accessCheck$8 = (obj, member, msg) => {
187
+ if (!member.has(obj))
188
+ throw TypeError("Cannot " + msg);
189
+ };
190
+ var __privateGet$8 = (obj, member, getter) => {
191
+ __accessCheck$8(obj, member, "read from private field");
192
+ return getter ? getter.call(obj) : member.get(obj);
193
+ };
194
+ var __privateAdd$8 = (obj, member, value) => {
195
+ if (member.has(obj))
196
+ throw TypeError("Cannot add the same private member more than once");
197
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
198
+ };
199
+ var __privateSet$8 = (obj, member, value, setter) => {
200
+ __accessCheck$8(obj, member, "write to private field");
201
+ setter ? setter.call(obj, value) : member.set(obj, value);
202
+ return value;
203
+ };
204
+ var __privateMethod$4 = (obj, member, method) => {
205
+ __accessCheck$8(obj, member, "access private method");
206
+ return method;
207
+ };
208
+ var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
164
209
  function getFetchImplementation(userFetch) {
165
210
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
166
211
  const fetchImpl = userFetch ?? globalFetch;
@@ -171,8 +216,81 @@ function getFetchImplementation(userFetch) {
171
216
  }
172
217
  return fetchImpl;
173
218
  }
219
+ class ApiRequestPool {
220
+ constructor(concurrency = 10) {
221
+ __privateAdd$8(this, _enqueue);
222
+ __privateAdd$8(this, _fetch, void 0);
223
+ __privateAdd$8(this, _queue, void 0);
224
+ __privateAdd$8(this, _concurrency, void 0);
225
+ __privateSet$8(this, _queue, []);
226
+ __privateSet$8(this, _concurrency, concurrency);
227
+ this.running = 0;
228
+ this.started = 0;
229
+ }
230
+ setFetch(fetch2) {
231
+ __privateSet$8(this, _fetch, fetch2);
232
+ }
233
+ getFetch() {
234
+ if (!__privateGet$8(this, _fetch)) {
235
+ throw new Error("Fetch not set");
236
+ }
237
+ return __privateGet$8(this, _fetch);
238
+ }
239
+ request(url, options) {
240
+ const start = new Date();
241
+ const fetch2 = this.getFetch();
242
+ const runRequest = async (stalled = false) => {
243
+ const response = await fetch2(url, options);
244
+ if (response.status === 429) {
245
+ const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
246
+ await timeout(rateLimitReset * 1e3);
247
+ return await runRequest(true);
248
+ }
249
+ if (stalled) {
250
+ const stalledTime = new Date().getTime() - start.getTime();
251
+ console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
252
+ }
253
+ return response;
254
+ };
255
+ return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
256
+ return await runRequest();
257
+ });
258
+ }
259
+ }
260
+ _fetch = new WeakMap();
261
+ _queue = new WeakMap();
262
+ _concurrency = new WeakMap();
263
+ _enqueue = new WeakSet();
264
+ enqueue_fn = function(task) {
265
+ const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
266
+ this.started--;
267
+ this.running++;
268
+ }).then(() => task()).finally(() => {
269
+ this.running--;
270
+ const next = __privateGet$8(this, _queue).shift();
271
+ if (next !== void 0) {
272
+ this.started++;
273
+ next();
274
+ }
275
+ });
276
+ if (this.running + this.started < __privateGet$8(this, _concurrency)) {
277
+ const next = __privateGet$8(this, _queue).shift();
278
+ if (next !== void 0) {
279
+ this.started++;
280
+ next();
281
+ }
282
+ }
283
+ return promise;
284
+ };
285
+
286
+ function generateUUID() {
287
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
288
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
289
+ return v.toString(16);
290
+ });
291
+ }
174
292
 
175
- const VERSION = "0.0.0-alpha.vf54f8ba";
293
+ const VERSION = "0.21.6";
176
294
 
177
295
  class ErrorWithCause extends Error {
178
296
  constructor(message, options) {
@@ -183,7 +301,7 @@ class FetcherError extends ErrorWithCause {
183
301
  constructor(status, data, requestId) {
184
302
  super(getMessage(data));
185
303
  this.status = status;
186
- this.errors = isBulkError(data) ? data.errors : void 0;
304
+ this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
187
305
  this.requestId = requestId;
188
306
  if (data instanceof Error) {
189
307
  this.stack = data.stack;
@@ -215,6 +333,7 @@ function getMessage(data) {
215
333
  }
216
334
  }
217
335
 
336
+ const pool = new ApiRequestPool();
218
337
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
219
338
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
220
339
  if (value === void 0 || value === null)
@@ -229,60 +348,77 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
229
348
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
230
349
  };
231
350
  function buildBaseUrl({
351
+ endpoint,
232
352
  path,
233
353
  workspacesApiUrl,
234
354
  apiUrl,
235
- pathParams
355
+ pathParams = {}
236
356
  }) {
237
- if (pathParams?.workspace === void 0 || !path.startsWith("/db"))
238
- return `${apiUrl}${path}`;
239
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
240
- return url.replace("{workspaceId}", String(pathParams.workspace));
357
+ if (endpoint === "dataPlane") {
358
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
359
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
360
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
361
+ }
362
+ return `${apiUrl}${path}`;
241
363
  }
242
364
  function hostHeader(url) {
243
365
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
244
366
  const { groups } = pattern.exec(url) ?? {};
245
367
  return groups?.host ? { Host: groups.host } : {};
246
368
  }
369
+ const defaultClientID = generateUUID();
247
370
  async function fetch$1({
248
371
  url: path,
249
372
  method,
250
373
  body,
251
- headers,
374
+ headers: customHeaders,
252
375
  pathParams,
253
376
  queryParams,
254
377
  fetchImpl,
255
378
  apiKey,
379
+ endpoint,
256
380
  apiUrl,
257
381
  workspacesApiUrl,
258
382
  trace,
259
- signal
383
+ signal,
384
+ clientID,
385
+ sessionID,
386
+ clientName,
387
+ fetchOptions = {}
260
388
  }) {
261
- return trace(
389
+ pool.setFetch(fetchImpl);
390
+ return await trace(
262
391
  `${method.toUpperCase()} ${path}`,
263
392
  async ({ setAttributes }) => {
264
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
393
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
265
394
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
266
395
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
267
396
  setAttributes({
268
397
  [TraceAttributes.HTTP_URL]: url,
269
398
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
270
399
  });
271
- const response = await fetchImpl(url, {
400
+ const xataAgent = compact([
401
+ ["client", "TS_SDK"],
402
+ ["version", VERSION],
403
+ isDefined(clientName) ? ["service", clientName] : void 0
404
+ ]).map(([key, value]) => `${key}=${value}`).join("; ");
405
+ const headers = {
406
+ "Accept-Encoding": "identity",
407
+ "Content-Type": "application/json",
408
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
409
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
410
+ "X-Xata-Agent": xataAgent,
411
+ ...customHeaders,
412
+ ...hostHeader(fullUrl),
413
+ Authorization: `Bearer ${apiKey}`
414
+ };
415
+ const response = await pool.request(url, {
416
+ ...fetchOptions,
272
417
  method: method.toUpperCase(),
273
418
  body: body ? JSON.stringify(body) : void 0,
274
- headers: {
275
- "Content-Type": "application/json",
276
- "User-Agent": `Xata client-ts/${VERSION}`,
277
- ...headers,
278
- ...hostHeader(fullUrl),
279
- Authorization: `Bearer ${apiKey}`
280
- },
419
+ headers,
281
420
  signal
282
421
  });
283
- if (response.status === 204) {
284
- return {};
285
- }
286
422
  const { host, protocol } = parseUrl(response.url);
287
423
  const requestId = response.headers?.get("x-request-id") ?? void 0;
288
424
  setAttributes({
@@ -292,6 +428,12 @@ async function fetch$1({
292
428
  [TraceAttributes.HTTP_HOST]: host,
293
429
  [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
294
430
  });
431
+ if (response.status === 204) {
432
+ return {};
433
+ }
434
+ if (response.status === 429) {
435
+ throw new FetcherError(response.status, "Rate limit exceeded", requestId);
436
+ }
295
437
  try {
296
438
  const jsonResponse = await response.json();
297
439
  if (response.ok) {
@@ -314,415 +456,345 @@ function parseUrl(url) {
314
456
  }
315
457
  }
316
458
 
317
- const getUser = (variables, signal) => fetch$1({ url: "/user", method: "get", ...variables, signal });
318
- const updateUser = (variables, signal) => fetch$1({
319
- url: "/user",
320
- method: "put",
321
- ...variables,
322
- signal
323
- });
324
- const deleteUser = (variables, signal) => fetch$1({ url: "/user", method: "delete", ...variables, signal });
325
- const getUserAPIKeys = (variables, signal) => fetch$1({
326
- url: "/user/keys",
459
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
460
+
461
+ const getBranchList = (variables, signal) => dataPlaneFetch({
462
+ url: "/dbs/{dbName}",
327
463
  method: "get",
328
464
  ...variables,
329
465
  signal
330
466
  });
331
- const createUserAPIKey = (variables, signal) => fetch$1({
332
- url: "/user/keys/{keyName}",
333
- method: "post",
467
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
468
+ url: "/db/{dbBranchName}",
469
+ method: "get",
334
470
  ...variables,
335
471
  signal
336
472
  });
337
- const deleteUserAPIKey = (variables, signal) => fetch$1({
338
- url: "/user/keys/{keyName}",
473
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
474
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
475
+ url: "/db/{dbBranchName}",
339
476
  method: "delete",
340
477
  ...variables,
341
478
  signal
342
479
  });
343
- const createWorkspace = (variables, signal) => fetch$1({
344
- url: "/workspaces",
345
- method: "post",
480
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
481
+ url: "/db/{dbBranchName}/metadata",
482
+ method: "put",
346
483
  ...variables,
347
484
  signal
348
485
  });
349
- const getWorkspacesList = (variables, signal) => fetch$1({
350
- url: "/workspaces",
486
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
487
+ url: "/db/{dbBranchName}/metadata",
351
488
  method: "get",
352
489
  ...variables,
353
490
  signal
354
491
  });
355
- const getWorkspace = (variables, signal) => fetch$1({
356
- url: "/workspaces/{workspaceId}",
492
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
493
+ url: "/db/{dbBranchName}/stats",
357
494
  method: "get",
358
495
  ...variables,
359
496
  signal
360
497
  });
361
- const updateWorkspace = (variables, signal) => fetch$1({
362
- url: "/workspaces/{workspaceId}",
363
- method: "put",
364
- ...variables,
365
- signal
366
- });
367
- const deleteWorkspace = (variables, signal) => fetch$1({
368
- url: "/workspaces/{workspaceId}",
369
- method: "delete",
370
- ...variables,
371
- signal
372
- });
373
- const getWorkspaceMembersList = (variables, signal) => fetch$1({
374
- url: "/workspaces/{workspaceId}/members",
498
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
499
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
500
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
501
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
502
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
503
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
504
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
505
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
506
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
507
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
508
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
375
509
  method: "get",
376
510
  ...variables,
377
511
  signal
378
512
  });
379
- const updateWorkspaceMemberRole = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
380
- const removeWorkspaceMember = (variables, signal) => fetch$1({
381
- url: "/workspaces/{workspaceId}/members/{userId}",
382
- method: "delete",
383
- ...variables,
384
- signal
385
- });
386
- const inviteWorkspaceMember = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
387
- const updateWorkspaceMemberInvite = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
388
- const cancelWorkspaceMemberInvite = (variables, signal) => fetch$1({
389
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
390
- method: "delete",
391
- ...variables,
392
- signal
393
- });
394
- const resendWorkspaceMemberInvite = (variables, signal) => fetch$1({
395
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
396
- method: "post",
397
- ...variables,
398
- signal
399
- });
400
- const acceptWorkspaceMemberInvite = (variables, signal) => fetch$1({
401
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
513
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
514
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
515
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
516
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
517
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
518
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
402
519
  method: "post",
403
520
  ...variables,
404
521
  signal
405
522
  });
406
- const getDatabaseList = (variables, signal) => fetch$1({
407
- url: "/dbs",
408
- method: "get",
409
- ...variables,
410
- signal
411
- });
412
- const getBranchList = (variables, signal) => fetch$1({
413
- url: "/dbs/{dbName}",
414
- method: "get",
415
- ...variables,
416
- signal
417
- });
418
- const createDatabase = (variables, signal) => fetch$1({
419
- url: "/dbs/{dbName}",
523
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
524
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
525
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
526
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
527
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
528
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
529
+ const createTable = (variables, signal) => dataPlaneFetch({
530
+ url: "/db/{dbBranchName}/tables/{tableName}",
420
531
  method: "put",
421
532
  ...variables,
422
533
  signal
423
534
  });
424
- const deleteDatabase = (variables, signal) => fetch$1({
425
- url: "/dbs/{dbName}",
535
+ const deleteTable = (variables, signal) => dataPlaneFetch({
536
+ url: "/db/{dbBranchName}/tables/{tableName}",
426
537
  method: "delete",
427
538
  ...variables,
428
539
  signal
429
540
  });
430
- const getDatabaseMetadata = (variables, signal) => fetch$1({
431
- url: "/dbs/{dbName}/metadata",
541
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
542
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
543
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
432
544
  method: "get",
433
545
  ...variables,
434
546
  signal
435
547
  });
436
- const updateDatabaseMetadata = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
437
- const getGitBranchesMapping = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
438
- const addGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
439
- const removeGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
440
- const resolveBranch = (variables, signal) => fetch$1({
441
- url: "/dbs/{dbName}/resolveBranch",
548
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
549
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
550
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
442
551
  method: "get",
443
552
  ...variables,
444
553
  signal
445
554
  });
446
- const queryMigrationRequests = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
447
- const createMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
448
- const getMigrationRequest = (variables, signal) => fetch$1({
449
- url: "/dbs/{dbName}/migrations/{mrNumber}",
555
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
556
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
557
+ );
558
+ const getColumn = (variables, signal) => dataPlaneFetch({
559
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
450
560
  method: "get",
451
561
  ...variables,
452
562
  signal
453
563
  });
454
- const updateMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
455
- const listMigrationRequestsCommits = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
456
- const compareMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
457
- const getMigrationRequestIsMerged = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
458
- const mergeMigrationRequest = (variables, signal) => fetch$1({
459
- url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
460
- method: "post",
564
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
565
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
566
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
567
+ method: "delete",
461
568
  ...variables,
462
569
  signal
463
570
  });
464
- const getBranchDetails = (variables, signal) => fetch$1({
465
- url: "/db/{dbBranchName}",
571
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
572
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
573
+ const getRecord = (variables, signal) => dataPlaneFetch({
574
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
466
575
  method: "get",
467
576
  ...variables,
468
577
  signal
469
578
  });
470
- const createBranch = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
471
- const deleteBranch = (variables, signal) => fetch$1({
472
- url: "/db/{dbBranchName}",
473
- method: "delete",
474
- ...variables,
475
- signal
476
- });
477
- const updateBranchMetadata = (variables, signal) => fetch$1({
478
- url: "/db/{dbBranchName}/metadata",
479
- method: "put",
579
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
580
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
581
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
582
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
583
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
584
+ const queryTable = (variables, signal) => dataPlaneFetch({
585
+ url: "/db/{dbBranchName}/tables/{tableName}/query",
586
+ method: "post",
480
587
  ...variables,
481
588
  signal
482
589
  });
483
- const getBranchMetadata = (variables, signal) => fetch$1({
484
- url: "/db/{dbBranchName}/metadata",
485
- method: "get",
590
+ const searchBranch = (variables, signal) => dataPlaneFetch({
591
+ url: "/db/{dbBranchName}/search",
592
+ method: "post",
486
593
  ...variables,
487
594
  signal
488
595
  });
489
- const getBranchMigrationHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
490
- const executeBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
491
- const getBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
492
- const compareBranchWithUserSchema = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
493
- const compareBranchSchemas = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
494
- const updateBranchSchema = (variables, signal) => fetch$1({
495
- url: "/db/{dbBranchName}/schema/update",
596
+ const searchTable = (variables, signal) => dataPlaneFetch({
597
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
496
598
  method: "post",
497
599
  ...variables,
498
600
  signal
499
601
  });
500
- const previewBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
501
- const applyBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
502
- const getBranchSchemaHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
503
- const getBranchStats = (variables, signal) => fetch$1({
504
- url: "/db/{dbBranchName}/stats",
602
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
603
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
604
+ const operationsByTag$2 = {
605
+ branch: {
606
+ getBranchList,
607
+ getBranchDetails,
608
+ createBranch,
609
+ deleteBranch,
610
+ updateBranchMetadata,
611
+ getBranchMetadata,
612
+ getBranchStats,
613
+ getGitBranchesMapping,
614
+ addGitBranchesEntry,
615
+ removeGitBranchesEntry,
616
+ resolveBranch
617
+ },
618
+ migrations: {
619
+ getBranchMigrationHistory,
620
+ getBranchMigrationPlan,
621
+ executeBranchMigrationPlan,
622
+ getBranchSchemaHistory,
623
+ compareBranchWithUserSchema,
624
+ compareBranchSchemas,
625
+ updateBranchSchema,
626
+ previewBranchSchemaEdit,
627
+ applyBranchSchemaEdit
628
+ },
629
+ migrationRequests: {
630
+ queryMigrationRequests,
631
+ createMigrationRequest,
632
+ getMigrationRequest,
633
+ updateMigrationRequest,
634
+ listMigrationRequestsCommits,
635
+ compareMigrationRequest,
636
+ getMigrationRequestIsMerged,
637
+ mergeMigrationRequest
638
+ },
639
+ table: {
640
+ createTable,
641
+ deleteTable,
642
+ updateTable,
643
+ getTableSchema,
644
+ setTableSchema,
645
+ getTableColumns,
646
+ addTableColumn,
647
+ getColumn,
648
+ updateColumn,
649
+ deleteColumn
650
+ },
651
+ records: {
652
+ branchTransaction,
653
+ insertRecord,
654
+ getRecord,
655
+ insertRecordWithID,
656
+ updateRecordWithID,
657
+ upsertRecordWithID,
658
+ deleteRecord,
659
+ bulkInsertTableRecords
660
+ },
661
+ searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
662
+ };
663
+
664
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
665
+
666
+ const getUser = (variables, signal) => controlPlaneFetch({
667
+ url: "/user",
505
668
  method: "get",
506
669
  ...variables,
507
670
  signal
508
671
  });
509
- const createTable = (variables, signal) => fetch$1({
510
- url: "/db/{dbBranchName}/tables/{tableName}",
672
+ const updateUser = (variables, signal) => controlPlaneFetch({
673
+ url: "/user",
511
674
  method: "put",
512
675
  ...variables,
513
676
  signal
514
677
  });
515
- const deleteTable = (variables, signal) => fetch$1({
516
- url: "/db/{dbBranchName}/tables/{tableName}",
678
+ const deleteUser = (variables, signal) => controlPlaneFetch({
679
+ url: "/user",
517
680
  method: "delete",
518
681
  ...variables,
519
682
  signal
520
683
  });
521
- const updateTable = (variables, signal) => fetch$1({
522
- url: "/db/{dbBranchName}/tables/{tableName}",
523
- method: "patch",
524
- ...variables,
525
- signal
526
- });
527
- const getTableSchema = (variables, signal) => fetch$1({
528
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
529
- method: "get",
530
- ...variables,
531
- signal
532
- });
533
- const setTableSchema = (variables, signal) => fetch$1({
534
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
535
- method: "put",
536
- ...variables,
537
- signal
538
- });
539
- const getTableColumns = (variables, signal) => fetch$1({
540
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
684
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
685
+ url: "/user/keys",
541
686
  method: "get",
542
687
  ...variables,
543
688
  signal
544
689
  });
545
- const addTableColumn = (variables, signal) => fetch$1({
546
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
690
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
691
+ url: "/user/keys/{keyName}",
547
692
  method: "post",
548
693
  ...variables,
549
694
  signal
550
695
  });
551
- const getColumn = (variables, signal) => fetch$1({
552
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
553
- method: "get",
554
- ...variables,
555
- signal
556
- });
557
- const deleteColumn = (variables, signal) => fetch$1({
558
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
559
- method: "delete",
560
- ...variables,
561
- signal
562
- });
563
- const updateColumn = (variables, signal) => fetch$1({
564
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
565
- method: "patch",
566
- ...variables,
567
- signal
568
- });
569
- const insertRecord = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
570
- const insertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
571
- const updateRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
572
- const upsertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
573
- const deleteRecord = (variables, signal) => fetch$1({
574
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
696
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
697
+ url: "/user/keys/{keyName}",
575
698
  method: "delete",
576
699
  ...variables,
577
700
  signal
578
701
  });
579
- const getRecord = (variables, signal) => fetch$1({
580
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
702
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
703
+ url: "/workspaces",
581
704
  method: "get",
582
705
  ...variables,
583
706
  signal
584
707
  });
585
- const bulkInsertTableRecords = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
586
- const queryTable = (variables, signal) => fetch$1({
587
- url: "/db/{dbBranchName}/tables/{tableName}/query",
708
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
709
+ url: "/workspaces",
588
710
  method: "post",
589
711
  ...variables,
590
712
  signal
591
713
  });
592
- const searchTable = (variables, signal) => fetch$1({
593
- url: "/db/{dbBranchName}/tables/{tableName}/search",
594
- method: "post",
714
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
715
+ url: "/workspaces/{workspaceId}",
716
+ method: "get",
595
717
  ...variables,
596
718
  signal
597
719
  });
598
- const searchBranch = (variables, signal) => fetch$1({
599
- url: "/db/{dbBranchName}/search",
600
- method: "post",
720
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
721
+ url: "/workspaces/{workspaceId}",
722
+ method: "put",
601
723
  ...variables,
602
724
  signal
603
725
  });
604
- const summarizeTable = (variables, signal) => fetch$1({
605
- url: "/db/{dbBranchName}/tables/{tableName}/summarize",
606
- method: "post",
726
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
727
+ url: "/workspaces/{workspaceId}",
728
+ method: "delete",
607
729
  ...variables,
608
730
  signal
609
731
  });
610
- const aggregateTable = (variables, signal) => fetch$1({
611
- url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
612
- method: "post",
732
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
733
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
734
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
735
+ url: "/workspaces/{workspaceId}/members/{userId}",
736
+ method: "delete",
613
737
  ...variables,
614
738
  signal
615
739
  });
616
- const cPGetDatabaseList = (variables, signal) => fetch$1({
740
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
741
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
742
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
743
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
744
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
745
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
617
746
  url: "/workspaces/{workspaceId}/dbs",
618
747
  method: "get",
619
748
  ...variables,
620
749
  signal
621
750
  });
622
- const cPCreateDatabase = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
623
- const cPDeleteDatabase = (variables, signal) => fetch$1({
751
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
752
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
624
753
  url: "/workspaces/{workspaceId}/dbs/{dbName}",
625
754
  method: "delete",
626
755
  ...variables,
627
756
  signal
628
757
  });
629
- const cPGetCPDatabaseMetadata = (variables, signal) => fetch$1(
630
- { url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "get", ...variables, signal }
631
- );
632
- const cPUpdateCPDatabaseMetadata = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
633
- const operationsByTag = {
634
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
758
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
759
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
760
+ const listRegions = (variables, signal) => controlPlaneFetch({
761
+ url: "/workspaces/{workspaceId}/regions",
762
+ method: "get",
763
+ ...variables,
764
+ signal
765
+ });
766
+ const operationsByTag$1 = {
767
+ users: { getUser, updateUser, deleteUser },
768
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
635
769
  workspaces: {
636
- createWorkspace,
637
770
  getWorkspacesList,
771
+ createWorkspace,
638
772
  getWorkspace,
639
773
  updateWorkspace,
640
774
  deleteWorkspace,
641
775
  getWorkspaceMembersList,
642
776
  updateWorkspaceMemberRole,
643
- removeWorkspaceMember,
777
+ removeWorkspaceMember
778
+ },
779
+ invites: {
644
780
  inviteWorkspaceMember,
645
781
  updateWorkspaceMemberInvite,
646
782
  cancelWorkspaceMemberInvite,
647
- resendWorkspaceMemberInvite,
648
- acceptWorkspaceMemberInvite
783
+ acceptWorkspaceMemberInvite,
784
+ resendWorkspaceMemberInvite
649
785
  },
650
- database: {
786
+ databases: {
651
787
  getDatabaseList,
652
788
  createDatabase,
653
789
  deleteDatabase,
654
790
  getDatabaseMetadata,
655
791
  updateDatabaseMetadata,
656
- getGitBranchesMapping,
657
- addGitBranchesEntry,
658
- removeGitBranchesEntry,
659
- resolveBranch
660
- },
661
- branch: {
662
- getBranchList,
663
- getBranchDetails,
664
- createBranch,
665
- deleteBranch,
666
- updateBranchMetadata,
667
- getBranchMetadata,
668
- getBranchStats
669
- },
670
- migrationRequests: {
671
- queryMigrationRequests,
672
- createMigrationRequest,
673
- getMigrationRequest,
674
- updateMigrationRequest,
675
- listMigrationRequestsCommits,
676
- compareMigrationRequest,
677
- getMigrationRequestIsMerged,
678
- mergeMigrationRequest
679
- },
680
- branchSchema: {
681
- getBranchMigrationHistory,
682
- executeBranchMigrationPlan,
683
- getBranchMigrationPlan,
684
- compareBranchWithUserSchema,
685
- compareBranchSchemas,
686
- updateBranchSchema,
687
- previewBranchSchemaEdit,
688
- applyBranchSchemaEdit,
689
- getBranchSchemaHistory
690
- },
691
- table: {
692
- createTable,
693
- deleteTable,
694
- updateTable,
695
- getTableSchema,
696
- setTableSchema,
697
- getTableColumns,
698
- addTableColumn,
699
- getColumn,
700
- deleteColumn,
701
- updateColumn
702
- },
703
- records: {
704
- insertRecord,
705
- insertRecordWithID,
706
- updateRecordWithID,
707
- upsertRecordWithID,
708
- deleteRecord,
709
- getRecord,
710
- bulkInsertTableRecords,
711
- queryTable,
712
- searchTable,
713
- searchBranch,
714
- summarizeTable,
715
- aggregateTable
716
- },
717
- databases: {
718
- cPGetDatabaseList,
719
- cPCreateDatabase,
720
- cPDeleteDatabase,
721
- cPGetCPDatabaseMetadata,
722
- cPUpdateCPDatabaseMetadata
792
+ listRegions
723
793
  }
724
794
  };
725
795
 
796
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
797
+
726
798
  function getHostUrl(provider, type) {
727
799
  if (isHostProviderAlias(provider)) {
728
800
  return providers[provider][type];
@@ -734,11 +806,11 @@ function getHostUrl(provider, type) {
734
806
  const providers = {
735
807
  production: {
736
808
  main: "https://api.xata.io",
737
- workspaces: "https://{workspaceId}.xata.sh"
809
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
738
810
  },
739
811
  staging: {
740
812
  main: "https://staging.xatabase.co",
741
- workspaces: "https://{workspaceId}.staging.xatabase.co"
813
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
742
814
  }
743
815
  };
744
816
  function isHostProviderAlias(alias) {
@@ -756,6 +828,16 @@ function parseProviderString(provider = "production") {
756
828
  return null;
757
829
  return { main, workspaces };
758
830
  }
831
+ function parseWorkspacesUrlParts(url) {
832
+ if (!isString(url))
833
+ return null;
834
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
835
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
836
+ const match = url.match(regex) || url.match(regexStaging);
837
+ if (!match)
838
+ return null;
839
+ return { workspace: match[1], region: match[2] };
840
+ }
759
841
 
760
842
  var __accessCheck$7 = (obj, member, msg) => {
761
843
  if (!member.has(obj))
@@ -783,6 +865,7 @@ class XataApiClient {
783
865
  const provider = options.host ?? "production";
784
866
  const apiKey = options.apiKey ?? getAPIKey();
785
867
  const trace = options.trace ?? defaultTrace;
868
+ const clientID = generateUUID();
786
869
  if (!apiKey) {
787
870
  throw new Error("Could not resolve a valid apiKey");
788
871
  }
@@ -791,7 +874,9 @@ class XataApiClient {
791
874
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
792
875
  fetchImpl: getFetchImplementation(options.fetch),
793
876
  apiKey,
794
- trace
877
+ trace,
878
+ clientName: options.clientName,
879
+ clientID
795
880
  });
796
881
  }
797
882
  get user() {
@@ -799,21 +884,41 @@ class XataApiClient {
799
884
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
800
885
  return __privateGet$7(this, _namespaces).user;
801
886
  }
887
+ get authentication() {
888
+ if (!__privateGet$7(this, _namespaces).authentication)
889
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
890
+ return __privateGet$7(this, _namespaces).authentication;
891
+ }
802
892
  get workspaces() {
803
893
  if (!__privateGet$7(this, _namespaces).workspaces)
804
894
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
805
895
  return __privateGet$7(this, _namespaces).workspaces;
806
896
  }
807
- get databases() {
808
- if (!__privateGet$7(this, _namespaces).databases)
809
- __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
810
- return __privateGet$7(this, _namespaces).databases;
897
+ get invites() {
898
+ if (!__privateGet$7(this, _namespaces).invites)
899
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
900
+ return __privateGet$7(this, _namespaces).invites;
901
+ }
902
+ get database() {
903
+ if (!__privateGet$7(this, _namespaces).database)
904
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
905
+ return __privateGet$7(this, _namespaces).database;
811
906
  }
812
907
  get branches() {
813
908
  if (!__privateGet$7(this, _namespaces).branches)
814
909
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
815
910
  return __privateGet$7(this, _namespaces).branches;
816
911
  }
912
+ get migrations() {
913
+ if (!__privateGet$7(this, _namespaces).migrations)
914
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
915
+ return __privateGet$7(this, _namespaces).migrations;
916
+ }
917
+ get migrationRequests() {
918
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
919
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
920
+ return __privateGet$7(this, _namespaces).migrationRequests;
921
+ }
817
922
  get tables() {
818
923
  if (!__privateGet$7(this, _namespaces).tables)
819
924
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -824,15 +929,10 @@ class XataApiClient {
824
929
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
825
930
  return __privateGet$7(this, _namespaces).records;
826
931
  }
827
- get migrationRequests() {
828
- if (!__privateGet$7(this, _namespaces).migrationRequests)
829
- __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
830
- return __privateGet$7(this, _namespaces).migrationRequests;
831
- }
832
- get branchSchema() {
833
- if (!__privateGet$7(this, _namespaces).branchSchema)
834
- __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
835
- return __privateGet$7(this, _namespaces).branchSchema;
932
+ get searchAndFilter() {
933
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
934
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
935
+ return __privateGet$7(this, _namespaces).searchAndFilter;
836
936
  }
837
937
  }
838
938
  _extraProps = new WeakMap();
@@ -844,24 +944,29 @@ class UserApi {
844
944
  getUser() {
845
945
  return operationsByTag.users.getUser({ ...this.extraProps });
846
946
  }
847
- updateUser(user) {
947
+ updateUser({ user }) {
848
948
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
849
949
  }
850
950
  deleteUser() {
851
951
  return operationsByTag.users.deleteUser({ ...this.extraProps });
852
952
  }
953
+ }
954
+ class AuthenticationApi {
955
+ constructor(extraProps) {
956
+ this.extraProps = extraProps;
957
+ }
853
958
  getUserAPIKeys() {
854
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
959
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
855
960
  }
856
- createUserAPIKey(keyName) {
857
- return operationsByTag.users.createUserAPIKey({
858
- pathParams: { keyName },
961
+ createUserAPIKey({ name }) {
962
+ return operationsByTag.authentication.createUserAPIKey({
963
+ pathParams: { keyName: name },
859
964
  ...this.extraProps
860
965
  });
861
966
  }
862
- deleteUserAPIKey(keyName) {
863
- return operationsByTag.users.deleteUserAPIKey({
864
- pathParams: { keyName },
967
+ deleteUserAPIKey({ name }) {
968
+ return operationsByTag.authentication.deleteUserAPIKey({
969
+ pathParams: { keyName: name },
865
970
  ...this.extraProps
866
971
  });
867
972
  }
@@ -870,146 +975,114 @@ class WorkspaceApi {
870
975
  constructor(extraProps) {
871
976
  this.extraProps = extraProps;
872
977
  }
873
- createWorkspace(workspaceMeta) {
874
- return operationsByTag.workspaces.createWorkspace({
875
- body: workspaceMeta,
876
- ...this.extraProps
877
- });
878
- }
879
978
  getWorkspacesList() {
880
979
  return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
881
980
  }
882
- getWorkspace(workspaceId) {
883
- return operationsByTag.workspaces.getWorkspace({
884
- pathParams: { workspaceId },
885
- ...this.extraProps
886
- });
887
- }
888
- updateWorkspace(workspaceId, workspaceMeta) {
889
- return operationsByTag.workspaces.updateWorkspace({
890
- pathParams: { workspaceId },
891
- body: workspaceMeta,
892
- ...this.extraProps
893
- });
894
- }
895
- deleteWorkspace(workspaceId) {
896
- return operationsByTag.workspaces.deleteWorkspace({
897
- pathParams: { workspaceId },
898
- ...this.extraProps
899
- });
900
- }
901
- getWorkspaceMembersList(workspaceId) {
902
- return operationsByTag.workspaces.getWorkspaceMembersList({
903
- pathParams: { workspaceId },
904
- ...this.extraProps
905
- });
906
- }
907
- updateWorkspaceMemberRole(workspaceId, userId, role) {
908
- return operationsByTag.workspaces.updateWorkspaceMemberRole({
909
- pathParams: { workspaceId, userId },
910
- body: { role },
911
- ...this.extraProps
912
- });
913
- }
914
- removeWorkspaceMember(workspaceId, userId) {
915
- return operationsByTag.workspaces.removeWorkspaceMember({
916
- pathParams: { workspaceId, userId },
917
- ...this.extraProps
918
- });
919
- }
920
- inviteWorkspaceMember(workspaceId, email, role) {
921
- return operationsByTag.workspaces.inviteWorkspaceMember({
922
- pathParams: { workspaceId },
923
- body: { email, role },
924
- ...this.extraProps
925
- });
926
- }
927
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
928
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
929
- pathParams: { workspaceId, inviteId },
930
- body: { role },
981
+ createWorkspace({ data }) {
982
+ return operationsByTag.workspaces.createWorkspace({
983
+ body: data,
931
984
  ...this.extraProps
932
985
  });
933
986
  }
934
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
935
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
936
- pathParams: { workspaceId, inviteId },
987
+ getWorkspace({ workspace }) {
988
+ return operationsByTag.workspaces.getWorkspace({
989
+ pathParams: { workspaceId: workspace },
937
990
  ...this.extraProps
938
991
  });
939
992
  }
940
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
941
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
942
- pathParams: { workspaceId, inviteId },
993
+ updateWorkspace({
994
+ workspace,
995
+ update
996
+ }) {
997
+ return operationsByTag.workspaces.updateWorkspace({
998
+ pathParams: { workspaceId: workspace },
999
+ body: update,
943
1000
  ...this.extraProps
944
1001
  });
945
1002
  }
946
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
947
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
948
- pathParams: { workspaceId, inviteKey },
1003
+ deleteWorkspace({ workspace }) {
1004
+ return operationsByTag.workspaces.deleteWorkspace({
1005
+ pathParams: { workspaceId: workspace },
949
1006
  ...this.extraProps
950
1007
  });
951
1008
  }
952
- }
953
- class DatabaseApi {
954
- constructor(extraProps) {
955
- this.extraProps = extraProps;
956
- }
957
- getDatabaseList(workspace) {
958
- return operationsByTag.database.getDatabaseList({
959
- pathParams: { workspace },
1009
+ getWorkspaceMembersList({ workspace }) {
1010
+ return operationsByTag.workspaces.getWorkspaceMembersList({
1011
+ pathParams: { workspaceId: workspace },
960
1012
  ...this.extraProps
961
1013
  });
962
1014
  }
963
- createDatabase(workspace, dbName, options = {}) {
964
- return operationsByTag.database.createDatabase({
965
- pathParams: { workspace, dbName },
966
- body: options,
1015
+ updateWorkspaceMemberRole({
1016
+ workspace,
1017
+ user,
1018
+ role
1019
+ }) {
1020
+ return operationsByTag.workspaces.updateWorkspaceMemberRole({
1021
+ pathParams: { workspaceId: workspace, userId: user },
1022
+ body: { role },
967
1023
  ...this.extraProps
968
1024
  });
969
1025
  }
970
- deleteDatabase(workspace, dbName) {
971
- return operationsByTag.database.deleteDatabase({
972
- pathParams: { workspace, dbName },
1026
+ removeWorkspaceMember({
1027
+ workspace,
1028
+ user
1029
+ }) {
1030
+ return operationsByTag.workspaces.removeWorkspaceMember({
1031
+ pathParams: { workspaceId: workspace, userId: user },
973
1032
  ...this.extraProps
974
1033
  });
975
1034
  }
976
- getDatabaseMetadata(workspace, dbName) {
977
- return operationsByTag.database.getDatabaseMetadata({
978
- pathParams: { workspace, dbName },
979
- ...this.extraProps
980
- });
1035
+ }
1036
+ class InvitesApi {
1037
+ constructor(extraProps) {
1038
+ this.extraProps = extraProps;
981
1039
  }
982
- updateDatabaseMetadata(workspace, dbName, options = {}) {
983
- return operationsByTag.database.updateDatabaseMetadata({
984
- pathParams: { workspace, dbName },
985
- body: options,
1040
+ inviteWorkspaceMember({
1041
+ workspace,
1042
+ email,
1043
+ role
1044
+ }) {
1045
+ return operationsByTag.invites.inviteWorkspaceMember({
1046
+ pathParams: { workspaceId: workspace },
1047
+ body: { email, role },
986
1048
  ...this.extraProps
987
1049
  });
988
1050
  }
989
- getGitBranchesMapping(workspace, dbName) {
990
- return operationsByTag.database.getGitBranchesMapping({
991
- pathParams: { workspace, dbName },
1051
+ updateWorkspaceMemberInvite({
1052
+ workspace,
1053
+ invite,
1054
+ role
1055
+ }) {
1056
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
1057
+ pathParams: { workspaceId: workspace, inviteId: invite },
1058
+ body: { role },
992
1059
  ...this.extraProps
993
1060
  });
994
1061
  }
995
- addGitBranchesEntry(workspace, dbName, body) {
996
- return operationsByTag.database.addGitBranchesEntry({
997
- pathParams: { workspace, dbName },
998
- body,
1062
+ cancelWorkspaceMemberInvite({
1063
+ workspace,
1064
+ invite
1065
+ }) {
1066
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
1067
+ pathParams: { workspaceId: workspace, inviteId: invite },
999
1068
  ...this.extraProps
1000
1069
  });
1001
1070
  }
1002
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
1003
- return operationsByTag.database.removeGitBranchesEntry({
1004
- pathParams: { workspace, dbName },
1005
- queryParams: { gitBranch },
1071
+ acceptWorkspaceMemberInvite({
1072
+ workspace,
1073
+ key
1074
+ }) {
1075
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
1076
+ pathParams: { workspaceId: workspace, inviteKey: key },
1006
1077
  ...this.extraProps
1007
1078
  });
1008
1079
  }
1009
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
1010
- return operationsByTag.database.resolveBranch({
1011
- pathParams: { workspace, dbName },
1012
- queryParams: { gitBranch, fallbackBranch },
1080
+ resendWorkspaceMemberInvite({
1081
+ workspace,
1082
+ invite
1083
+ }) {
1084
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
1085
+ pathParams: { workspaceId: workspace, inviteId: invite },
1013
1086
  ...this.extraProps
1014
1087
  });
1015
1088
  }
@@ -1018,48 +1091,132 @@ class BranchApi {
1018
1091
  constructor(extraProps) {
1019
1092
  this.extraProps = extraProps;
1020
1093
  }
1021
- getBranchList(workspace, dbName) {
1094
+ getBranchList({
1095
+ workspace,
1096
+ region,
1097
+ database
1098
+ }) {
1022
1099
  return operationsByTag.branch.getBranchList({
1023
- pathParams: { workspace, dbName },
1100
+ pathParams: { workspace, region, dbName: database },
1024
1101
  ...this.extraProps
1025
1102
  });
1026
1103
  }
1027
- getBranchDetails(workspace, database, branch) {
1104
+ getBranchDetails({
1105
+ workspace,
1106
+ region,
1107
+ database,
1108
+ branch
1109
+ }) {
1028
1110
  return operationsByTag.branch.getBranchDetails({
1029
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1111
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1030
1112
  ...this.extraProps
1031
1113
  });
1032
1114
  }
1033
- createBranch(workspace, database, branch, from, options = {}) {
1115
+ createBranch({
1116
+ workspace,
1117
+ region,
1118
+ database,
1119
+ branch,
1120
+ from,
1121
+ metadata
1122
+ }) {
1034
1123
  return operationsByTag.branch.createBranch({
1035
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1036
- queryParams: isString(from) ? { from } : void 0,
1037
- body: options,
1124
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1125
+ body: { from, metadata },
1038
1126
  ...this.extraProps
1039
1127
  });
1040
1128
  }
1041
- deleteBranch(workspace, database, branch) {
1129
+ deleteBranch({
1130
+ workspace,
1131
+ region,
1132
+ database,
1133
+ branch
1134
+ }) {
1042
1135
  return operationsByTag.branch.deleteBranch({
1043
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1136
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1044
1137
  ...this.extraProps
1045
1138
  });
1046
1139
  }
1047
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
1140
+ updateBranchMetadata({
1141
+ workspace,
1142
+ region,
1143
+ database,
1144
+ branch,
1145
+ metadata
1146
+ }) {
1048
1147
  return operationsByTag.branch.updateBranchMetadata({
1049
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1148
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1050
1149
  body: metadata,
1051
1150
  ...this.extraProps
1052
1151
  });
1053
1152
  }
1054
- getBranchMetadata(workspace, database, branch) {
1153
+ getBranchMetadata({
1154
+ workspace,
1155
+ region,
1156
+ database,
1157
+ branch
1158
+ }) {
1055
1159
  return operationsByTag.branch.getBranchMetadata({
1056
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1160
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1057
1161
  ...this.extraProps
1058
1162
  });
1059
1163
  }
1060
- getBranchStats(workspace, database, branch) {
1164
+ getBranchStats({
1165
+ workspace,
1166
+ region,
1167
+ database,
1168
+ branch
1169
+ }) {
1061
1170
  return operationsByTag.branch.getBranchStats({
1062
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1171
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1172
+ ...this.extraProps
1173
+ });
1174
+ }
1175
+ getGitBranchesMapping({
1176
+ workspace,
1177
+ region,
1178
+ database
1179
+ }) {
1180
+ return operationsByTag.branch.getGitBranchesMapping({
1181
+ pathParams: { workspace, region, dbName: database },
1182
+ ...this.extraProps
1183
+ });
1184
+ }
1185
+ addGitBranchesEntry({
1186
+ workspace,
1187
+ region,
1188
+ database,
1189
+ gitBranch,
1190
+ xataBranch
1191
+ }) {
1192
+ return operationsByTag.branch.addGitBranchesEntry({
1193
+ pathParams: { workspace, region, dbName: database },
1194
+ body: { gitBranch, xataBranch },
1195
+ ...this.extraProps
1196
+ });
1197
+ }
1198
+ removeGitBranchesEntry({
1199
+ workspace,
1200
+ region,
1201
+ database,
1202
+ gitBranch
1203
+ }) {
1204
+ return operationsByTag.branch.removeGitBranchesEntry({
1205
+ pathParams: { workspace, region, dbName: database },
1206
+ queryParams: { gitBranch },
1207
+ ...this.extraProps
1208
+ });
1209
+ }
1210
+ resolveBranch({
1211
+ workspace,
1212
+ region,
1213
+ database,
1214
+ gitBranch,
1215
+ fallbackBranch
1216
+ }) {
1217
+ return operationsByTag.branch.resolveBranch({
1218
+ pathParams: { workspace, region, dbName: database },
1219
+ queryParams: { gitBranch, fallbackBranch },
1063
1220
  ...this.extraProps
1064
1221
  });
1065
1222
  }
@@ -1068,67 +1225,134 @@ class TableApi {
1068
1225
  constructor(extraProps) {
1069
1226
  this.extraProps = extraProps;
1070
1227
  }
1071
- createTable(workspace, database, branch, tableName) {
1228
+ createTable({
1229
+ workspace,
1230
+ region,
1231
+ database,
1232
+ branch,
1233
+ table
1234
+ }) {
1072
1235
  return operationsByTag.table.createTable({
1073
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1236
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1074
1237
  ...this.extraProps
1075
1238
  });
1076
1239
  }
1077
- deleteTable(workspace, database, branch, tableName) {
1240
+ deleteTable({
1241
+ workspace,
1242
+ region,
1243
+ database,
1244
+ branch,
1245
+ table
1246
+ }) {
1078
1247
  return operationsByTag.table.deleteTable({
1079
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1248
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1080
1249
  ...this.extraProps
1081
1250
  });
1082
1251
  }
1083
- updateTable(workspace, database, branch, tableName, options) {
1252
+ updateTable({
1253
+ workspace,
1254
+ region,
1255
+ database,
1256
+ branch,
1257
+ table,
1258
+ update
1259
+ }) {
1084
1260
  return operationsByTag.table.updateTable({
1085
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1086
- body: options,
1261
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1262
+ body: update,
1087
1263
  ...this.extraProps
1088
1264
  });
1089
1265
  }
1090
- getTableSchema(workspace, database, branch, tableName) {
1266
+ getTableSchema({
1267
+ workspace,
1268
+ region,
1269
+ database,
1270
+ branch,
1271
+ table
1272
+ }) {
1091
1273
  return operationsByTag.table.getTableSchema({
1092
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1274
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1093
1275
  ...this.extraProps
1094
1276
  });
1095
1277
  }
1096
- setTableSchema(workspace, database, branch, tableName, options) {
1278
+ setTableSchema({
1279
+ workspace,
1280
+ region,
1281
+ database,
1282
+ branch,
1283
+ table,
1284
+ schema
1285
+ }) {
1097
1286
  return operationsByTag.table.setTableSchema({
1098
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1099
- body: options,
1287
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1288
+ body: schema,
1100
1289
  ...this.extraProps
1101
1290
  });
1102
1291
  }
1103
- getTableColumns(workspace, database, branch, tableName) {
1292
+ getTableColumns({
1293
+ workspace,
1294
+ region,
1295
+ database,
1296
+ branch,
1297
+ table
1298
+ }) {
1104
1299
  return operationsByTag.table.getTableColumns({
1105
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1300
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1106
1301
  ...this.extraProps
1107
1302
  });
1108
1303
  }
1109
- addTableColumn(workspace, database, branch, tableName, column) {
1304
+ addTableColumn({
1305
+ workspace,
1306
+ region,
1307
+ database,
1308
+ branch,
1309
+ table,
1310
+ column
1311
+ }) {
1110
1312
  return operationsByTag.table.addTableColumn({
1111
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1313
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1112
1314
  body: column,
1113
1315
  ...this.extraProps
1114
1316
  });
1115
1317
  }
1116
- getColumn(workspace, database, branch, tableName, columnName) {
1318
+ getColumn({
1319
+ workspace,
1320
+ region,
1321
+ database,
1322
+ branch,
1323
+ table,
1324
+ column
1325
+ }) {
1117
1326
  return operationsByTag.table.getColumn({
1118
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1327
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1119
1328
  ...this.extraProps
1120
1329
  });
1121
1330
  }
1122
- deleteColumn(workspace, database, branch, tableName, columnName) {
1123
- return operationsByTag.table.deleteColumn({
1124
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1331
+ updateColumn({
1332
+ workspace,
1333
+ region,
1334
+ database,
1335
+ branch,
1336
+ table,
1337
+ column,
1338
+ update
1339
+ }) {
1340
+ return operationsByTag.table.updateColumn({
1341
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1342
+ body: update,
1125
1343
  ...this.extraProps
1126
1344
  });
1127
1345
  }
1128
- updateColumn(workspace, database, branch, tableName, columnName, options) {
1129
- return operationsByTag.table.updateColumn({
1130
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1131
- body: options,
1346
+ deleteColumn({
1347
+ workspace,
1348
+ region,
1349
+ database,
1350
+ branch,
1351
+ table,
1352
+ column
1353
+ }) {
1354
+ return operationsByTag.table.deleteColumn({
1355
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1132
1356
  ...this.extraProps
1133
1357
  });
1134
1358
  }
@@ -1137,85 +1361,228 @@ class RecordsApi {
1137
1361
  constructor(extraProps) {
1138
1362
  this.extraProps = extraProps;
1139
1363
  }
1140
- insertRecord(workspace, database, branch, tableName, record, options = {}) {
1364
+ insertRecord({
1365
+ workspace,
1366
+ region,
1367
+ database,
1368
+ branch,
1369
+ table,
1370
+ record,
1371
+ columns
1372
+ }) {
1141
1373
  return operationsByTag.records.insertRecord({
1142
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1143
- queryParams: options,
1374
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1375
+ queryParams: { columns },
1144
1376
  body: record,
1145
1377
  ...this.extraProps
1146
1378
  });
1147
1379
  }
1148
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1380
+ getRecord({
1381
+ workspace,
1382
+ region,
1383
+ database,
1384
+ branch,
1385
+ table,
1386
+ id,
1387
+ columns
1388
+ }) {
1389
+ return operationsByTag.records.getRecord({
1390
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1391
+ queryParams: { columns },
1392
+ ...this.extraProps
1393
+ });
1394
+ }
1395
+ insertRecordWithID({
1396
+ workspace,
1397
+ region,
1398
+ database,
1399
+ branch,
1400
+ table,
1401
+ id,
1402
+ record,
1403
+ columns,
1404
+ createOnly,
1405
+ ifVersion
1406
+ }) {
1149
1407
  return operationsByTag.records.insertRecordWithID({
1150
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1151
- queryParams: options,
1408
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1409
+ queryParams: { columns, createOnly, ifVersion },
1152
1410
  body: record,
1153
1411
  ...this.extraProps
1154
1412
  });
1155
1413
  }
1156
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1414
+ updateRecordWithID({
1415
+ workspace,
1416
+ region,
1417
+ database,
1418
+ branch,
1419
+ table,
1420
+ id,
1421
+ record,
1422
+ columns,
1423
+ ifVersion
1424
+ }) {
1157
1425
  return operationsByTag.records.updateRecordWithID({
1158
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1159
- queryParams: options,
1426
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1427
+ queryParams: { columns, ifVersion },
1160
1428
  body: record,
1161
1429
  ...this.extraProps
1162
1430
  });
1163
1431
  }
1164
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1432
+ upsertRecordWithID({
1433
+ workspace,
1434
+ region,
1435
+ database,
1436
+ branch,
1437
+ table,
1438
+ id,
1439
+ record,
1440
+ columns,
1441
+ ifVersion
1442
+ }) {
1165
1443
  return operationsByTag.records.upsertRecordWithID({
1166
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1167
- queryParams: options,
1444
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1445
+ queryParams: { columns, ifVersion },
1168
1446
  body: record,
1169
1447
  ...this.extraProps
1170
1448
  });
1171
1449
  }
1172
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
1450
+ deleteRecord({
1451
+ workspace,
1452
+ region,
1453
+ database,
1454
+ branch,
1455
+ table,
1456
+ id,
1457
+ columns
1458
+ }) {
1173
1459
  return operationsByTag.records.deleteRecord({
1174
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1175
- queryParams: options,
1176
- ...this.extraProps
1177
- });
1178
- }
1179
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
1180
- return operationsByTag.records.getRecord({
1181
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1182
- queryParams: options,
1460
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1461
+ queryParams: { columns },
1183
1462
  ...this.extraProps
1184
1463
  });
1185
1464
  }
1186
- bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
1465
+ bulkInsertTableRecords({
1466
+ workspace,
1467
+ region,
1468
+ database,
1469
+ branch,
1470
+ table,
1471
+ records,
1472
+ columns
1473
+ }) {
1187
1474
  return operationsByTag.records.bulkInsertTableRecords({
1188
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1189
- queryParams: options,
1475
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1476
+ queryParams: { columns },
1190
1477
  body: { records },
1191
1478
  ...this.extraProps
1192
1479
  });
1193
1480
  }
1194
- queryTable(workspace, database, branch, tableName, query) {
1195
- return operationsByTag.records.queryTable({
1196
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1197
- body: query,
1198
- ...this.extraProps
1199
- });
1200
- }
1201
- searchTable(workspace, database, branch, tableName, query) {
1202
- return operationsByTag.records.searchTable({
1203
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1204
- body: query,
1481
+ branchTransaction({
1482
+ workspace,
1483
+ region,
1484
+ database,
1485
+ branch,
1486
+ operations
1487
+ }) {
1488
+ return operationsByTag.records.branchTransaction({
1489
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1490
+ body: { operations },
1205
1491
  ...this.extraProps
1206
1492
  });
1207
1493
  }
1208
- searchBranch(workspace, database, branch, query) {
1209
- return operationsByTag.records.searchBranch({
1210
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1211
- body: query,
1212
- ...this.extraProps
1213
- });
1494
+ }
1495
+ class SearchAndFilterApi {
1496
+ constructor(extraProps) {
1497
+ this.extraProps = extraProps;
1214
1498
  }
1215
- summarizeTable(workspace, database, branch, tableName, query) {
1216
- return operationsByTag.records.summarizeTable({
1217
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1218
- body: query,
1499
+ queryTable({
1500
+ workspace,
1501
+ region,
1502
+ database,
1503
+ branch,
1504
+ table,
1505
+ filter,
1506
+ sort,
1507
+ page,
1508
+ columns,
1509
+ consistency
1510
+ }) {
1511
+ return operationsByTag.searchAndFilter.queryTable({
1512
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1513
+ body: { filter, sort, page, columns, consistency },
1514
+ ...this.extraProps
1515
+ });
1516
+ }
1517
+ searchTable({
1518
+ workspace,
1519
+ region,
1520
+ database,
1521
+ branch,
1522
+ table,
1523
+ query,
1524
+ fuzziness,
1525
+ target,
1526
+ prefix,
1527
+ filter,
1528
+ highlight,
1529
+ boosters
1530
+ }) {
1531
+ return operationsByTag.searchAndFilter.searchTable({
1532
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1533
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
1534
+ ...this.extraProps
1535
+ });
1536
+ }
1537
+ searchBranch({
1538
+ workspace,
1539
+ region,
1540
+ database,
1541
+ branch,
1542
+ tables,
1543
+ query,
1544
+ fuzziness,
1545
+ prefix,
1546
+ highlight
1547
+ }) {
1548
+ return operationsByTag.searchAndFilter.searchBranch({
1549
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1550
+ body: { tables, query, fuzziness, prefix, highlight },
1551
+ ...this.extraProps
1552
+ });
1553
+ }
1554
+ summarizeTable({
1555
+ workspace,
1556
+ region,
1557
+ database,
1558
+ branch,
1559
+ table,
1560
+ filter,
1561
+ columns,
1562
+ summaries,
1563
+ sort,
1564
+ summariesFilter,
1565
+ page,
1566
+ consistency
1567
+ }) {
1568
+ return operationsByTag.searchAndFilter.summarizeTable({
1569
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1570
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1571
+ ...this.extraProps
1572
+ });
1573
+ }
1574
+ aggregateTable({
1575
+ workspace,
1576
+ region,
1577
+ database,
1578
+ branch,
1579
+ table,
1580
+ filter,
1581
+ aggs
1582
+ }) {
1583
+ return operationsByTag.searchAndFilter.aggregateTable({
1584
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1585
+ body: { filter, aggs },
1219
1586
  ...this.extraProps
1220
1587
  });
1221
1588
  }
@@ -1224,131 +1591,289 @@ class MigrationRequestsApi {
1224
1591
  constructor(extraProps) {
1225
1592
  this.extraProps = extraProps;
1226
1593
  }
1227
- queryMigrationRequests(workspace, database, options = {}) {
1594
+ queryMigrationRequests({
1595
+ workspace,
1596
+ region,
1597
+ database,
1598
+ filter,
1599
+ sort,
1600
+ page,
1601
+ columns
1602
+ }) {
1228
1603
  return operationsByTag.migrationRequests.queryMigrationRequests({
1229
- pathParams: { workspace, dbName: database },
1230
- body: options,
1604
+ pathParams: { workspace, region, dbName: database },
1605
+ body: { filter, sort, page, columns },
1231
1606
  ...this.extraProps
1232
1607
  });
1233
1608
  }
1234
- createMigrationRequest(workspace, database, options) {
1609
+ createMigrationRequest({
1610
+ workspace,
1611
+ region,
1612
+ database,
1613
+ migration
1614
+ }) {
1235
1615
  return operationsByTag.migrationRequests.createMigrationRequest({
1236
- pathParams: { workspace, dbName: database },
1237
- body: options,
1616
+ pathParams: { workspace, region, dbName: database },
1617
+ body: migration,
1238
1618
  ...this.extraProps
1239
1619
  });
1240
1620
  }
1241
- getMigrationRequest(workspace, database, migrationRequest) {
1621
+ getMigrationRequest({
1622
+ workspace,
1623
+ region,
1624
+ database,
1625
+ migrationRequest
1626
+ }) {
1242
1627
  return operationsByTag.migrationRequests.getMigrationRequest({
1243
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1628
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1244
1629
  ...this.extraProps
1245
1630
  });
1246
1631
  }
1247
- updateMigrationRequest(workspace, database, migrationRequest, options) {
1632
+ updateMigrationRequest({
1633
+ workspace,
1634
+ region,
1635
+ database,
1636
+ migrationRequest,
1637
+ update
1638
+ }) {
1248
1639
  return operationsByTag.migrationRequests.updateMigrationRequest({
1249
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1250
- body: options,
1640
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1641
+ body: update,
1251
1642
  ...this.extraProps
1252
1643
  });
1253
1644
  }
1254
- listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1645
+ listMigrationRequestsCommits({
1646
+ workspace,
1647
+ region,
1648
+ database,
1649
+ migrationRequest,
1650
+ page
1651
+ }) {
1255
1652
  return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1256
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1257
- body: options,
1653
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1654
+ body: { page },
1258
1655
  ...this.extraProps
1259
1656
  });
1260
1657
  }
1261
- compareMigrationRequest(workspace, database, migrationRequest) {
1658
+ compareMigrationRequest({
1659
+ workspace,
1660
+ region,
1661
+ database,
1662
+ migrationRequest
1663
+ }) {
1262
1664
  return operationsByTag.migrationRequests.compareMigrationRequest({
1263
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1665
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1264
1666
  ...this.extraProps
1265
1667
  });
1266
1668
  }
1267
- getMigrationRequestIsMerged(workspace, database, migrationRequest) {
1669
+ getMigrationRequestIsMerged({
1670
+ workspace,
1671
+ region,
1672
+ database,
1673
+ migrationRequest
1674
+ }) {
1268
1675
  return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1269
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1676
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1270
1677
  ...this.extraProps
1271
1678
  });
1272
1679
  }
1273
- mergeMigrationRequest(workspace, database, migrationRequest) {
1680
+ mergeMigrationRequest({
1681
+ workspace,
1682
+ region,
1683
+ database,
1684
+ migrationRequest
1685
+ }) {
1274
1686
  return operationsByTag.migrationRequests.mergeMigrationRequest({
1275
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1687
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1276
1688
  ...this.extraProps
1277
1689
  });
1278
1690
  }
1279
1691
  }
1280
- class BranchSchemaApi {
1692
+ class MigrationsApi {
1281
1693
  constructor(extraProps) {
1282
1694
  this.extraProps = extraProps;
1283
1695
  }
1284
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
1285
- return operationsByTag.branchSchema.getBranchMigrationHistory({
1286
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1287
- body: options,
1696
+ getBranchMigrationHistory({
1697
+ workspace,
1698
+ region,
1699
+ database,
1700
+ branch,
1701
+ limit,
1702
+ startFrom
1703
+ }) {
1704
+ return operationsByTag.migrations.getBranchMigrationHistory({
1705
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1706
+ body: { limit, startFrom },
1707
+ ...this.extraProps
1708
+ });
1709
+ }
1710
+ getBranchMigrationPlan({
1711
+ workspace,
1712
+ region,
1713
+ database,
1714
+ branch,
1715
+ schema
1716
+ }) {
1717
+ return operationsByTag.migrations.getBranchMigrationPlan({
1718
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1719
+ body: schema,
1288
1720
  ...this.extraProps
1289
1721
  });
1290
1722
  }
1291
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1292
- return operationsByTag.branchSchema.executeBranchMigrationPlan({
1293
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1294
- body: migrationPlan,
1723
+ executeBranchMigrationPlan({
1724
+ workspace,
1725
+ region,
1726
+ database,
1727
+ branch,
1728
+ plan
1729
+ }) {
1730
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1731
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1732
+ body: plan,
1295
1733
  ...this.extraProps
1296
1734
  });
1297
1735
  }
1298
- getBranchMigrationPlan(workspace, database, branch, schema) {
1299
- return operationsByTag.branchSchema.getBranchMigrationPlan({
1300
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1301
- body: schema,
1736
+ getBranchSchemaHistory({
1737
+ workspace,
1738
+ region,
1739
+ database,
1740
+ branch,
1741
+ page
1742
+ }) {
1743
+ return operationsByTag.migrations.getBranchSchemaHistory({
1744
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1745
+ body: { page },
1302
1746
  ...this.extraProps
1303
1747
  });
1304
1748
  }
1305
- compareBranchWithUserSchema(workspace, database, branch, schema) {
1306
- return operationsByTag.branchSchema.compareBranchWithUserSchema({
1307
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1749
+ compareBranchWithUserSchema({
1750
+ workspace,
1751
+ region,
1752
+ database,
1753
+ branch,
1754
+ schema
1755
+ }) {
1756
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1757
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1308
1758
  body: { schema },
1309
1759
  ...this.extraProps
1310
1760
  });
1311
1761
  }
1312
- compareBranchSchemas(workspace, database, branch, branchName, schema) {
1313
- return operationsByTag.branchSchema.compareBranchSchemas({
1314
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1762
+ compareBranchSchemas({
1763
+ workspace,
1764
+ region,
1765
+ database,
1766
+ branch,
1767
+ compare,
1768
+ schema
1769
+ }) {
1770
+ return operationsByTag.migrations.compareBranchSchemas({
1771
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1315
1772
  body: { schema },
1316
1773
  ...this.extraProps
1317
1774
  });
1318
1775
  }
1319
- updateBranchSchema(workspace, database, branch, migration) {
1320
- return operationsByTag.branchSchema.updateBranchSchema({
1321
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1776
+ updateBranchSchema({
1777
+ workspace,
1778
+ region,
1779
+ database,
1780
+ branch,
1781
+ migration
1782
+ }) {
1783
+ return operationsByTag.migrations.updateBranchSchema({
1784
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1322
1785
  body: migration,
1323
1786
  ...this.extraProps
1324
1787
  });
1325
1788
  }
1326
- previewBranchSchemaEdit(workspace, database, branch, migration) {
1327
- return operationsByTag.branchSchema.previewBranchSchemaEdit({
1328
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1329
- body: migration,
1789
+ previewBranchSchemaEdit({
1790
+ workspace,
1791
+ region,
1792
+ database,
1793
+ branch,
1794
+ data
1795
+ }) {
1796
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1797
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1798
+ body: data,
1330
1799
  ...this.extraProps
1331
1800
  });
1332
1801
  }
1333
- applyBranchSchemaEdit(workspace, database, branch, edits) {
1334
- return operationsByTag.branchSchema.applyBranchSchemaEdit({
1335
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1802
+ applyBranchSchemaEdit({
1803
+ workspace,
1804
+ region,
1805
+ database,
1806
+ branch,
1807
+ edits
1808
+ }) {
1809
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1810
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1336
1811
  body: { edits },
1337
1812
  ...this.extraProps
1338
1813
  });
1339
1814
  }
1340
- getBranchSchemaHistory(workspace, database, branch, options = {}) {
1341
- return operationsByTag.branchSchema.getBranchSchemaHistory({
1342
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1343
- body: options,
1815
+ }
1816
+ class DatabaseApi {
1817
+ constructor(extraProps) {
1818
+ this.extraProps = extraProps;
1819
+ }
1820
+ getDatabaseList({ workspace }) {
1821
+ return operationsByTag.databases.getDatabaseList({
1822
+ pathParams: { workspaceId: workspace },
1823
+ ...this.extraProps
1824
+ });
1825
+ }
1826
+ createDatabase({
1827
+ workspace,
1828
+ database,
1829
+ data
1830
+ }) {
1831
+ return operationsByTag.databases.createDatabase({
1832
+ pathParams: { workspaceId: workspace, dbName: database },
1833
+ body: data,
1834
+ ...this.extraProps
1835
+ });
1836
+ }
1837
+ deleteDatabase({
1838
+ workspace,
1839
+ database
1840
+ }) {
1841
+ return operationsByTag.databases.deleteDatabase({
1842
+ pathParams: { workspaceId: workspace, dbName: database },
1843
+ ...this.extraProps
1844
+ });
1845
+ }
1846
+ getDatabaseMetadata({
1847
+ workspace,
1848
+ database
1849
+ }) {
1850
+ return operationsByTag.databases.getDatabaseMetadata({
1851
+ pathParams: { workspaceId: workspace, dbName: database },
1852
+ ...this.extraProps
1853
+ });
1854
+ }
1855
+ updateDatabaseMetadata({
1856
+ workspace,
1857
+ database,
1858
+ metadata
1859
+ }) {
1860
+ return operationsByTag.databases.updateDatabaseMetadata({
1861
+ pathParams: { workspaceId: workspace, dbName: database },
1862
+ body: metadata,
1863
+ ...this.extraProps
1864
+ });
1865
+ }
1866
+ listRegions({ workspace }) {
1867
+ return operationsByTag.databases.listRegions({
1868
+ pathParams: { workspaceId: workspace },
1344
1869
  ...this.extraProps
1345
1870
  });
1346
1871
  }
1347
1872
  }
1348
1873
 
1349
1874
  class XataApiPlugin {
1350
- async build(options) {
1351
- const { fetchImpl, apiKey } = await options.getFetchProps();
1875
+ build(options) {
1876
+ const { fetchImpl, apiKey } = options.getFetchProps();
1352
1877
  return new XataApiClient({ fetch: fetchImpl, apiKey });
1353
1878
  }
1354
1879
  }
@@ -1356,6 +1881,13 @@ class XataApiPlugin {
1356
1881
  class XataPlugin {
1357
1882
  }
1358
1883
 
1884
+ function cleanFilter(filter) {
1885
+ if (!filter)
1886
+ return void 0;
1887
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1888
+ return values.length > 0 ? filter : void 0;
1889
+ }
1890
+
1359
1891
  var __accessCheck$6 = (obj, member, msg) => {
1360
1892
  if (!member.has(obj))
1361
1893
  throw TypeError("Cannot " + msg);
@@ -1388,11 +1920,11 @@ class Page {
1388
1920
  async previousPage(size, offset) {
1389
1921
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1390
1922
  }
1391
- async firstPage(size, offset) {
1392
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1923
+ async startPage(size, offset) {
1924
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1393
1925
  }
1394
- async lastPage(size, offset) {
1395
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1926
+ async endPage(size, offset) {
1927
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1396
1928
  }
1397
1929
  hasNextPage() {
1398
1930
  return this.meta.page.more;
@@ -1404,7 +1936,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1404
1936
  const PAGINATION_MAX_OFFSET = 800;
1405
1937
  const PAGINATION_DEFAULT_OFFSET = 0;
1406
1938
  function isCursorPaginationOptions(options) {
1407
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1939
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1408
1940
  }
1409
1941
  const _RecordArray = class extends Array {
1410
1942
  constructor(...args) {
@@ -1425,6 +1957,12 @@ const _RecordArray = class extends Array {
1425
1957
  toArray() {
1426
1958
  return new Array(...this);
1427
1959
  }
1960
+ toSerializable() {
1961
+ return JSON.parse(this.toString());
1962
+ }
1963
+ toString() {
1964
+ return JSON.stringify(this.toArray());
1965
+ }
1428
1966
  map(callbackfn, thisArg) {
1429
1967
  return this.toArray().map(callbackfn, thisArg);
1430
1968
  }
@@ -1436,12 +1974,12 @@ const _RecordArray = class extends Array {
1436
1974
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1437
1975
  return new _RecordArray(newPage);
1438
1976
  }
1439
- async firstPage(size, offset) {
1440
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1977
+ async startPage(size, offset) {
1978
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1441
1979
  return new _RecordArray(newPage);
1442
1980
  }
1443
- async lastPage(size, offset) {
1444
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1981
+ async endPage(size, offset) {
1982
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1445
1983
  return new _RecordArray(newPage);
1446
1984
  }
1447
1985
  hasNextPage() {
@@ -1495,9 +2033,11 @@ const _Query = class {
1495
2033
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1496
2034
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1497
2035
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1498
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
2036
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2037
+ __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
1499
2038
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1500
2039
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2040
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1501
2041
  this.any = this.any.bind(this);
1502
2042
  this.all = this.all.bind(this);
1503
2043
  this.not = this.not.bind(this);
@@ -1611,19 +2151,29 @@ const _Query = class {
1611
2151
  throw new Error("No results found.");
1612
2152
  return records[0];
1613
2153
  }
2154
+ async summarize(params = {}) {
2155
+ const { summaries, summariesFilter, ...options } = params;
2156
+ const query = new _Query(
2157
+ __privateGet$5(this, _repository),
2158
+ __privateGet$5(this, _table$1),
2159
+ options,
2160
+ __privateGet$5(this, _data)
2161
+ );
2162
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2163
+ }
1614
2164
  cache(ttl) {
1615
2165
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1616
2166
  }
1617
2167
  nextPage(size, offset) {
1618
- return this.firstPage(size, offset);
2168
+ return this.startPage(size, offset);
1619
2169
  }
1620
2170
  previousPage(size, offset) {
1621
- return this.firstPage(size, offset);
2171
+ return this.startPage(size, offset);
1622
2172
  }
1623
- firstPage(size, offset) {
2173
+ startPage(size, offset) {
1624
2174
  return this.getPaginated({ pagination: { size, offset } });
1625
2175
  }
1626
- lastPage(size, offset) {
2176
+ endPage(size, offset) {
1627
2177
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1628
2178
  }
1629
2179
  hasNextPage() {
@@ -1647,7 +2197,7 @@ cleanFilterConstraint_fn = function(column, value) {
1647
2197
  };
1648
2198
  function cleanParent(data, parent) {
1649
2199
  if (isCursorPaginationOptions(data.pagination)) {
1650
- return { ...parent, sorting: void 0, filter: void 0 };
2200
+ return { ...parent, sort: void 0, filter: void 0 };
1651
2201
  }
1652
2202
  return parent;
1653
2203
  }
@@ -1706,7 +2256,8 @@ var __privateMethod$2 = (obj, member, method) => {
1706
2256
  __accessCheck$4(obj, member, "access private method");
1707
2257
  return method;
1708
2258
  };
1709
- 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;
2259
+ 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;
2260
+ const BULK_OPERATION_MAX_SIZE = 1e3;
1710
2261
  class Repository extends Query {
1711
2262
  }
1712
2263
  class RestRepository extends Query {
@@ -1718,10 +2269,12 @@ class RestRepository extends Query {
1718
2269
  );
1719
2270
  __privateAdd$4(this, _insertRecordWithoutId);
1720
2271
  __privateAdd$4(this, _insertRecordWithId);
1721
- __privateAdd$4(this, _bulkInsertTableRecords);
2272
+ __privateAdd$4(this, _insertRecords);
1722
2273
  __privateAdd$4(this, _updateRecordWithID);
2274
+ __privateAdd$4(this, _updateRecords);
1723
2275
  __privateAdd$4(this, _upsertRecordWithID);
1724
2276
  __privateAdd$4(this, _deleteRecord);
2277
+ __privateAdd$4(this, _deleteRecords);
1725
2278
  __privateAdd$4(this, _setCacheQuery);
1726
2279
  __privateAdd$4(this, _getCacheQuery);
1727
2280
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1732,10 +2285,13 @@ class RestRepository extends Query {
1732
2285
  __privateAdd$4(this, _schemaTables$2, void 0);
1733
2286
  __privateAdd$4(this, _trace, void 0);
1734
2287
  __privateSet$4(this, _table, options.table);
1735
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1736
2288
  __privateSet$4(this, _db, options.db);
1737
2289
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1738
2290
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2291
+ __privateSet$4(this, _getFetchProps, async () => {
2292
+ const props = await options.pluginOptions.getFetchProps();
2293
+ return { ...props, sessionID: generateUUID() };
2294
+ });
1739
2295
  const trace = options.pluginOptions.trace ?? defaultTrace;
1740
2296
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1741
2297
  return trace(name, fn, {
@@ -1746,25 +2302,28 @@ class RestRepository extends Query {
1746
2302
  });
1747
2303
  });
1748
2304
  }
1749
- async create(a, b, c) {
2305
+ async create(a, b, c, d) {
1750
2306
  return __privateGet$4(this, _trace).call(this, "create", async () => {
2307
+ const ifVersion = parseIfVersion(b, c, d);
1751
2308
  if (Array.isArray(a)) {
1752
2309
  if (a.length === 0)
1753
2310
  return [];
1754
- const columns = isStringArray(b) ? b : void 0;
1755
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2311
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2312
+ const columns = isStringArray(b) ? b : ["*"];
2313
+ const result = await this.read(ids, columns);
2314
+ return result;
1756
2315
  }
1757
2316
  if (isString(a) && isObject(b)) {
1758
2317
  if (a === "")
1759
2318
  throw new Error("The id can't be empty");
1760
2319
  const columns = isStringArray(c) ? c : void 0;
1761
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
2320
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
1762
2321
  }
1763
2322
  if (isObject(a) && isString(a.id)) {
1764
2323
  if (a.id === "")
1765
2324
  throw new Error("The id can't be empty");
1766
2325
  const columns = isStringArray(b) ? b : void 0;
1767
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2326
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
1768
2327
  }
1769
2328
  if (isObject(a)) {
1770
2329
  const columns = isStringArray(b) ? b : void 0;
@@ -1795,6 +2354,7 @@ class RestRepository extends Query {
1795
2354
  pathParams: {
1796
2355
  workspace: "{workspaceId}",
1797
2356
  dbBranchName: "{dbBranch}",
2357
+ region: "{region}",
1798
2358
  tableName: __privateGet$4(this, _table),
1799
2359
  recordId: id
1800
2360
  },
@@ -1832,31 +2392,42 @@ class RestRepository extends Query {
1832
2392
  return result;
1833
2393
  });
1834
2394
  }
1835
- async update(a, b, c) {
2395
+ async update(a, b, c, d) {
1836
2396
  return __privateGet$4(this, _trace).call(this, "update", async () => {
2397
+ const ifVersion = parseIfVersion(b, c, d);
1837
2398
  if (Array.isArray(a)) {
1838
2399
  if (a.length === 0)
1839
2400
  return [];
1840
- if (a.length > 100) {
1841
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1842
- }
2401
+ const existing = await this.read(a, ["id"]);
2402
+ const updates = a.filter((_item, index) => existing[index] !== null);
2403
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2404
+ ifVersion,
2405
+ upsert: false
2406
+ });
1843
2407
  const columns = isStringArray(b) ? b : ["*"];
1844
- return Promise.all(a.map((object) => this.update(object, columns)));
1845
- }
1846
- if (isString(a) && isObject(b)) {
1847
- const columns = isStringArray(c) ? c : void 0;
1848
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
2408
+ const result = await this.read(a, columns);
2409
+ return result;
1849
2410
  }
1850
- if (isObject(a) && isString(a.id)) {
1851
- const columns = isStringArray(b) ? b : void 0;
1852
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2411
+ try {
2412
+ if (isString(a) && isObject(b)) {
2413
+ const columns = isStringArray(c) ? c : void 0;
2414
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2415
+ }
2416
+ if (isObject(a) && isString(a.id)) {
2417
+ const columns = isStringArray(b) ? b : void 0;
2418
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2419
+ }
2420
+ } catch (error) {
2421
+ if (error.status === 422)
2422
+ return null;
2423
+ throw error;
1853
2424
  }
1854
2425
  throw new Error("Invalid arguments for update method");
1855
2426
  });
1856
2427
  }
1857
- async updateOrThrow(a, b, c) {
2428
+ async updateOrThrow(a, b, c, d) {
1858
2429
  return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
1859
- const result = await this.update(a, b, c);
2430
+ const result = await this.update(a, b, c, d);
1860
2431
  if (Array.isArray(result)) {
1861
2432
  const missingIds = compact(
1862
2433
  a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
@@ -1873,37 +2444,69 @@ class RestRepository extends Query {
1873
2444
  return result;
1874
2445
  });
1875
2446
  }
1876
- async createOrUpdate(a, b, c) {
2447
+ async createOrUpdate(a, b, c, d) {
1877
2448
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2449
+ const ifVersion = parseIfVersion(b, c, d);
1878
2450
  if (Array.isArray(a)) {
1879
2451
  if (a.length === 0)
1880
2452
  return [];
1881
- if (a.length > 100) {
1882
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1883
- }
2453
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2454
+ ifVersion,
2455
+ upsert: true
2456
+ });
1884
2457
  const columns = isStringArray(b) ? b : ["*"];
1885
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
2458
+ const result = await this.read(a, columns);
2459
+ return result;
1886
2460
  }
1887
2461
  if (isString(a) && isObject(b)) {
1888
2462
  const columns = isStringArray(c) ? c : void 0;
1889
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
2463
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1890
2464
  }
1891
2465
  if (isObject(a) && isString(a.id)) {
1892
2466
  const columns = isStringArray(c) ? c : void 0;
1893
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2467
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1894
2468
  }
1895
2469
  throw new Error("Invalid arguments for createOrUpdate method");
1896
2470
  });
1897
2471
  }
2472
+ async createOrReplace(a, b, c, d) {
2473
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2474
+ const ifVersion = parseIfVersion(b, c, d);
2475
+ if (Array.isArray(a)) {
2476
+ if (a.length === 0)
2477
+ return [];
2478
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2479
+ const columns = isStringArray(b) ? b : ["*"];
2480
+ const result = await this.read(ids, columns);
2481
+ return result;
2482
+ }
2483
+ if (isString(a) && isObject(b)) {
2484
+ const columns = isStringArray(c) ? c : void 0;
2485
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2486
+ }
2487
+ if (isObject(a) && isString(a.id)) {
2488
+ const columns = isStringArray(c) ? c : void 0;
2489
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2490
+ }
2491
+ throw new Error("Invalid arguments for createOrReplace method");
2492
+ });
2493
+ }
1898
2494
  async delete(a, b) {
1899
2495
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1900
2496
  if (Array.isArray(a)) {
1901
2497
  if (a.length === 0)
1902
2498
  return [];
1903
- if (a.length > 100) {
1904
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1905
- }
1906
- return Promise.all(a.map((id) => this.delete(id, b)));
2499
+ const ids = a.map((o) => {
2500
+ if (isString(o))
2501
+ return o;
2502
+ if (isString(o.id))
2503
+ return o.id;
2504
+ throw new Error("Invalid arguments for delete method");
2505
+ });
2506
+ const columns = isStringArray(b) ? b : ["*"];
2507
+ const result = await this.read(a, columns);
2508
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2509
+ return result;
1907
2510
  }
1908
2511
  if (isString(a)) {
1909
2512
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
@@ -1936,14 +2539,21 @@ class RestRepository extends Query {
1936
2539
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1937
2540
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1938
2541
  const { records } = await searchTable({
1939
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2542
+ pathParams: {
2543
+ workspace: "{workspaceId}",
2544
+ dbBranchName: "{dbBranch}",
2545
+ region: "{region}",
2546
+ tableName: __privateGet$4(this, _table)
2547
+ },
1940
2548
  body: {
1941
2549
  query,
1942
2550
  fuzziness: options.fuzziness,
1943
2551
  prefix: options.prefix,
1944
2552
  highlight: options.highlight,
1945
2553
  filter: options.filter,
1946
- boosters: options.boosters
2554
+ boosters: options.boosters,
2555
+ page: options.page,
2556
+ target: options.target
1947
2557
  },
1948
2558
  ...fetchProps
1949
2559
  });
@@ -1951,22 +2561,44 @@ class RestRepository extends Query {
1951
2561
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1952
2562
  });
1953
2563
  }
2564
+ async aggregate(aggs, filter) {
2565
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2566
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2567
+ const result = await aggregateTable({
2568
+ pathParams: {
2569
+ workspace: "{workspaceId}",
2570
+ dbBranchName: "{dbBranch}",
2571
+ region: "{region}",
2572
+ tableName: __privateGet$4(this, _table)
2573
+ },
2574
+ body: { aggs, filter },
2575
+ ...fetchProps
2576
+ });
2577
+ return result;
2578
+ });
2579
+ }
1954
2580
  async query(query) {
1955
2581
  return __privateGet$4(this, _trace).call(this, "query", async () => {
1956
2582
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1957
2583
  if (cacheQuery)
1958
2584
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1959
2585
  const data = query.getQueryOptions();
1960
- const body = {
1961
- filter: cleanFilter(data.filter),
1962
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1963
- page: data.pagination,
1964
- columns: data.columns
1965
- };
1966
2586
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1967
2587
  const { meta, records: objects } = await queryTable({
1968
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1969
- body,
2588
+ pathParams: {
2589
+ workspace: "{workspaceId}",
2590
+ dbBranchName: "{dbBranch}",
2591
+ region: "{region}",
2592
+ tableName: __privateGet$4(this, _table)
2593
+ },
2594
+ body: {
2595
+ filter: cleanFilter(data.filter),
2596
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2597
+ page: data.pagination,
2598
+ columns: data.columns ?? ["*"],
2599
+ consistency: data.consistency
2600
+ },
2601
+ fetchOptions: data.fetchOptions,
1970
2602
  ...fetchProps
1971
2603
  });
1972
2604
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
@@ -1977,6 +2609,31 @@ class RestRepository extends Query {
1977
2609
  return new Page(query, meta, records);
1978
2610
  });
1979
2611
  }
2612
+ async summarizeTable(query, summaries, summariesFilter) {
2613
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2614
+ const data = query.getQueryOptions();
2615
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2616
+ const result = await summarizeTable({
2617
+ pathParams: {
2618
+ workspace: "{workspaceId}",
2619
+ dbBranchName: "{dbBranch}",
2620
+ region: "{region}",
2621
+ tableName: __privateGet$4(this, _table)
2622
+ },
2623
+ body: {
2624
+ filter: cleanFilter(data.filter),
2625
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2626
+ columns: data.columns,
2627
+ consistency: data.consistency,
2628
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2629
+ summaries,
2630
+ summariesFilter
2631
+ },
2632
+ ...fetchProps
2633
+ });
2634
+ return result;
2635
+ });
2636
+ }
1980
2637
  }
1981
2638
  _table = new WeakMap();
1982
2639
  _getFetchProps = new WeakMap();
@@ -1992,6 +2649,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1992
2649
  pathParams: {
1993
2650
  workspace: "{workspaceId}",
1994
2651
  dbBranchName: "{dbBranch}",
2652
+ region: "{region}",
1995
2653
  tableName: __privateGet$4(this, _table)
1996
2654
  },
1997
2655
  queryParams: { columns },
@@ -2002,47 +2660,68 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2002
2660
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2003
2661
  };
2004
2662
  _insertRecordWithId = new WeakSet();
2005
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
2663
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2006
2664
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2007
2665
  const record = transformObjectLinks(object);
2008
2666
  const response = await insertRecordWithID({
2009
2667
  pathParams: {
2010
2668
  workspace: "{workspaceId}",
2011
2669
  dbBranchName: "{dbBranch}",
2670
+ region: "{region}",
2012
2671
  tableName: __privateGet$4(this, _table),
2013
2672
  recordId
2014
2673
  },
2015
2674
  body: record,
2016
- queryParams: { createOnly: true, columns },
2675
+ queryParams: { createOnly, columns, ifVersion },
2017
2676
  ...fetchProps
2018
2677
  });
2019
2678
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2020
2679
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2021
2680
  };
2022
- _bulkInsertTableRecords = new WeakSet();
2023
- bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
2681
+ _insertRecords = new WeakSet();
2682
+ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2024
2683
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2025
- const records = objects.map((object) => transformObjectLinks(object));
2026
- const response = await bulkInsertTableRecords({
2027
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2028
- queryParams: { columns },
2029
- body: { records },
2030
- ...fetchProps
2031
- });
2032
- if (!isResponseWithRecords(response)) {
2033
- throw new Error("Request included columns but server didn't include them");
2684
+ const chunkedOperations = chunk(
2685
+ objects.map((object) => ({
2686
+ insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2687
+ })),
2688
+ BULK_OPERATION_MAX_SIZE
2689
+ );
2690
+ const ids = [];
2691
+ for (const operations of chunkedOperations) {
2692
+ const { results } = await branchTransaction({
2693
+ pathParams: {
2694
+ workspace: "{workspaceId}",
2695
+ dbBranchName: "{dbBranch}",
2696
+ region: "{region}"
2697
+ },
2698
+ body: { operations },
2699
+ ...fetchProps
2700
+ });
2701
+ for (const result of results) {
2702
+ if (result.operation === "insert") {
2703
+ ids.push(result.id);
2704
+ } else {
2705
+ ids.push(null);
2706
+ }
2707
+ }
2034
2708
  }
2035
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2036
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
2709
+ return ids;
2037
2710
  };
2038
2711
  _updateRecordWithID = new WeakSet();
2039
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2712
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2040
2713
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2041
- const record = transformObjectLinks(object);
2714
+ const { id: _id, ...record } = transformObjectLinks(object);
2042
2715
  try {
2043
2716
  const response = await updateRecordWithID({
2044
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2045
- queryParams: { columns },
2717
+ pathParams: {
2718
+ workspace: "{workspaceId}",
2719
+ dbBranchName: "{dbBranch}",
2720
+ region: "{region}",
2721
+ tableName: __privateGet$4(this, _table),
2722
+ recordId
2723
+ },
2724
+ queryParams: { columns, ifVersion },
2046
2725
  body: record,
2047
2726
  ...fetchProps
2048
2727
  });
@@ -2055,12 +2734,48 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2055
2734
  throw e;
2056
2735
  }
2057
2736
  };
2737
+ _updateRecords = new WeakSet();
2738
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2739
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2740
+ const chunkedOperations = chunk(
2741
+ objects.map(({ id, ...object }) => ({
2742
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2743
+ })),
2744
+ BULK_OPERATION_MAX_SIZE
2745
+ );
2746
+ const ids = [];
2747
+ for (const operations of chunkedOperations) {
2748
+ const { results } = await branchTransaction({
2749
+ pathParams: {
2750
+ workspace: "{workspaceId}",
2751
+ dbBranchName: "{dbBranch}",
2752
+ region: "{region}"
2753
+ },
2754
+ body: { operations },
2755
+ ...fetchProps
2756
+ });
2757
+ for (const result of results) {
2758
+ if (result.operation === "update") {
2759
+ ids.push(result.id);
2760
+ } else {
2761
+ ids.push(null);
2762
+ }
2763
+ }
2764
+ }
2765
+ return ids;
2766
+ };
2058
2767
  _upsertRecordWithID = new WeakSet();
2059
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2768
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2060
2769
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2061
2770
  const response = await upsertRecordWithID({
2062
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2063
- queryParams: { columns },
2771
+ pathParams: {
2772
+ workspace: "{workspaceId}",
2773
+ dbBranchName: "{dbBranch}",
2774
+ region: "{region}",
2775
+ tableName: __privateGet$4(this, _table),
2776
+ recordId
2777
+ },
2778
+ queryParams: { columns, ifVersion },
2064
2779
  body: object,
2065
2780
  ...fetchProps
2066
2781
  });
@@ -2072,7 +2787,13 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2072
2787
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2073
2788
  try {
2074
2789
  const response = await deleteRecord({
2075
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2790
+ pathParams: {
2791
+ workspace: "{workspaceId}",
2792
+ dbBranchName: "{dbBranch}",
2793
+ region: "{region}",
2794
+ tableName: __privateGet$4(this, _table),
2795
+ recordId
2796
+ },
2076
2797
  queryParams: { columns },
2077
2798
  ...fetchProps
2078
2799
  });
@@ -2085,17 +2806,37 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2085
2806
  throw e;
2086
2807
  }
2087
2808
  };
2809
+ _deleteRecords = new WeakSet();
2810
+ deleteRecords_fn = async function(recordIds) {
2811
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2812
+ const chunkedOperations = chunk(
2813
+ recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2814
+ BULK_OPERATION_MAX_SIZE
2815
+ );
2816
+ for (const operations of chunkedOperations) {
2817
+ await branchTransaction({
2818
+ pathParams: {
2819
+ workspace: "{workspaceId}",
2820
+ dbBranchName: "{dbBranch}",
2821
+ region: "{region}"
2822
+ },
2823
+ body: { operations },
2824
+ ...fetchProps
2825
+ });
2826
+ }
2827
+ };
2088
2828
  _setCacheQuery = new WeakSet();
2089
2829
  setCacheQuery_fn = async function(query, meta, records) {
2090
- await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2830
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2091
2831
  };
2092
2832
  _getCacheQuery = new WeakSet();
2093
2833
  getCacheQuery_fn = async function(query) {
2094
2834
  const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2095
- const result = await __privateGet$4(this, _cache).get(key);
2835
+ const result = await __privateGet$4(this, _cache)?.get(key);
2096
2836
  if (!result)
2097
2837
  return null;
2098
- const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
2838
+ const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
2839
+ const { cache: ttl = defaultTTL } = query.getQueryOptions();
2099
2840
  if (ttl < 0)
2100
2841
  return null;
2101
2842
  const hasExpired = result.date.getTime() + ttl < Date.now();
@@ -2107,7 +2848,7 @@ getSchemaTables_fn$1 = async function() {
2107
2848
  return __privateGet$4(this, _schemaTables$2);
2108
2849
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2109
2850
  const { schema } = await getBranchDetails({
2110
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2851
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2111
2852
  ...fetchProps
2112
2853
  });
2113
2854
  __privateSet$4(this, _schemaTables$2, schema.tables);
@@ -2121,23 +2862,23 @@ const transformObjectLinks = (object) => {
2121
2862
  }, {});
2122
2863
  };
2123
2864
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2124
- const result = {};
2865
+ const data = {};
2125
2866
  const { xata, ...rest } = object ?? {};
2126
- Object.assign(result, rest);
2867
+ Object.assign(data, rest);
2127
2868
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2128
2869
  if (!columns)
2129
2870
  console.error(`Table ${table} not found in schema`);
2130
2871
  for (const column of columns ?? []) {
2131
2872
  if (!isValidColumn(selectedColumns, column))
2132
2873
  continue;
2133
- const value = result[column.name];
2874
+ const value = data[column.name];
2134
2875
  switch (column.type) {
2135
2876
  case "datetime": {
2136
- const date = value !== void 0 ? new Date(value) : void 0;
2137
- if (date && isNaN(date.getTime())) {
2877
+ const date = value !== void 0 ? new Date(value) : null;
2878
+ if (date !== null && isNaN(date.getTime())) {
2138
2879
  console.error(`Failed to parse date ${value} for field ${column.name}`);
2139
- } else if (date) {
2140
- result[column.name] = date;
2880
+ } else {
2881
+ data[column.name] = date;
2141
2882
  }
2142
2883
  break;
2143
2884
  }
@@ -2156,41 +2897,52 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2156
2897
  }
2157
2898
  return acc;
2158
2899
  }, []);
2159
- result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2900
+ data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2160
2901
  } else {
2161
- result[column.name] = null;
2902
+ data[column.name] = null;
2162
2903
  }
2163
2904
  break;
2164
2905
  }
2165
2906
  default:
2166
- result[column.name] = value ?? null;
2907
+ data[column.name] = value ?? null;
2167
2908
  if (column.notNull === true && value === null) {
2168
2909
  console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2169
2910
  }
2170
2911
  break;
2171
2912
  }
2172
2913
  }
2173
- result.read = function(columns2) {
2174
- return db[table].read(result["id"], columns2);
2914
+ const record = { ...data };
2915
+ record.read = function(columns2) {
2916
+ return db[table].read(record["id"], columns2);
2917
+ };
2918
+ record.update = function(data2, b, c) {
2919
+ const columns2 = isStringArray(b) ? b : ["*"];
2920
+ const ifVersion = parseIfVersion(b, c);
2921
+ return db[table].update(record["id"], data2, columns2, { ifVersion });
2175
2922
  };
2176
- result.update = function(data, columns2) {
2177
- return db[table].update(result["id"], data, columns2);
2923
+ record.replace = function(data2, b, c) {
2924
+ const columns2 = isStringArray(b) ? b : ["*"];
2925
+ const ifVersion = parseIfVersion(b, c);
2926
+ return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2178
2927
  };
2179
- result.delete = function() {
2180
- return db[table].delete(result["id"]);
2928
+ record.delete = function() {
2929
+ return db[table].delete(record["id"]);
2181
2930
  };
2182
- result.getMetadata = function() {
2931
+ record.getMetadata = function() {
2183
2932
  return xata;
2184
2933
  };
2185
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
2186
- Object.defineProperty(result, prop, { enumerable: false });
2934
+ record.toSerializable = function() {
2935
+ return JSON.parse(JSON.stringify(transformObjectLinks(data)));
2936
+ };
2937
+ record.toString = function() {
2938
+ return JSON.stringify(transformObjectLinks(data));
2939
+ };
2940
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
2941
+ Object.defineProperty(record, prop, { enumerable: false });
2187
2942
  }
2188
- Object.freeze(result);
2189
- return result;
2943
+ Object.freeze(record);
2944
+ return record;
2190
2945
  };
2191
- function isResponseWithRecords(value) {
2192
- return isObject(value) && Array.isArray(value.records);
2193
- }
2194
2946
  function extractId(value) {
2195
2947
  if (isString(value))
2196
2948
  return value;
@@ -2198,12 +2950,6 @@ function extractId(value) {
2198
2950
  return value.id;
2199
2951
  return void 0;
2200
2952
  }
2201
- function cleanFilter(filter) {
2202
- if (!filter)
2203
- return void 0;
2204
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2205
- return values.length > 0 ? filter : void 0;
2206
- }
2207
2953
  function isValidColumn(columns, column) {
2208
2954
  if (columns.includes("*"))
2209
2955
  return true;
@@ -2213,6 +2959,14 @@ function isValidColumn(columns, column) {
2213
2959
  }
2214
2960
  return columns.includes(column.name);
2215
2961
  }
2962
+ function parseIfVersion(...args) {
2963
+ for (const arg of args) {
2964
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
2965
+ return arg.ifVersion;
2966
+ }
2967
+ }
2968
+ return void 0;
2969
+ }
2216
2970
 
2217
2971
  var __accessCheck$3 = (obj, member, msg) => {
2218
2972
  if (!member.has(obj))
@@ -2398,10 +3152,10 @@ _schemaTables = new WeakMap();
2398
3152
  _search = new WeakSet();
2399
3153
  search_fn = async function(query, options, getFetchProps) {
2400
3154
  const fetchProps = await getFetchProps();
2401
- const { tables, fuzziness, highlight, prefix } = options ?? {};
3155
+ const { tables, fuzziness, highlight, prefix, page } = options ?? {};
2402
3156
  const { records } = await searchBranch({
2403
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2404
- body: { tables, query, fuzziness, prefix, highlight },
3157
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3158
+ body: { tables, query, fuzziness, prefix, highlight, page },
2405
3159
  ...fetchProps
2406
3160
  });
2407
3161
  return records;
@@ -2412,95 +3166,33 @@ getSchemaTables_fn = async function(getFetchProps) {
2412
3166
  return __privateGet$1(this, _schemaTables);
2413
3167
  const fetchProps = await getFetchProps();
2414
3168
  const { schema } = await getBranchDetails({
2415
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
3169
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2416
3170
  ...fetchProps
2417
3171
  });
2418
3172
  __privateSet$1(this, _schemaTables, schema.tables);
2419
3173
  return schema.tables;
2420
3174
  };
2421
3175
 
3176
+ class TransactionPlugin extends XataPlugin {
3177
+ build({ getFetchProps }) {
3178
+ return {
3179
+ run: async (operations) => {
3180
+ const fetchProps = await getFetchProps();
3181
+ const response = await branchTransaction({
3182
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3183
+ body: { operations },
3184
+ ...fetchProps
3185
+ });
3186
+ return response;
3187
+ }
3188
+ };
3189
+ }
3190
+ }
3191
+
2422
3192
  const isBranchStrategyBuilder = (strategy) => {
2423
3193
  return typeof strategy === "function";
2424
3194
  };
2425
3195
 
2426
- async function getCurrentBranchName(options) {
2427
- const { branch, envBranch } = getEnvironment();
2428
- if (branch) {
2429
- const details = await getDatabaseBranch(branch, options);
2430
- if (details)
2431
- return branch;
2432
- console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
2433
- }
2434
- const gitBranch = envBranch || await getGitBranch();
2435
- return resolveXataBranch(gitBranch, options);
2436
- }
2437
- async function getCurrentBranchDetails(options) {
2438
- const branch = await getCurrentBranchName(options);
2439
- return getDatabaseBranch(branch, options);
2440
- }
2441
- async function resolveXataBranch(gitBranch, options) {
2442
- const databaseURL = options?.databaseURL || getDatabaseURL();
2443
- const apiKey = options?.apiKey || getAPIKey();
2444
- if (!databaseURL)
2445
- throw new Error(
2446
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2447
- );
2448
- if (!apiKey)
2449
- throw new Error(
2450
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2451
- );
2452
- const [protocol, , host, , dbName] = databaseURL.split("/");
2453
- const [workspace] = host.split(".");
2454
- const { fallbackBranch } = getEnvironment();
2455
- const { branch } = await resolveBranch({
2456
- apiKey,
2457
- apiUrl: databaseURL,
2458
- fetchImpl: getFetchImplementation(options?.fetchImpl),
2459
- workspacesApiUrl: `${protocol}//${host}`,
2460
- pathParams: { dbName, workspace },
2461
- queryParams: { gitBranch, fallbackBranch },
2462
- trace: defaultTrace
2463
- });
2464
- return branch;
2465
- }
2466
- async function getDatabaseBranch(branch, options) {
2467
- const databaseURL = options?.databaseURL || getDatabaseURL();
2468
- const apiKey = options?.apiKey || getAPIKey();
2469
- if (!databaseURL)
2470
- throw new Error(
2471
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2472
- );
2473
- if (!apiKey)
2474
- throw new Error(
2475
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2476
- );
2477
- const [protocol, , host, , database] = databaseURL.split("/");
2478
- const [workspace] = host.split(".");
2479
- const dbBranchName = `${database}:${branch}`;
2480
- try {
2481
- return await getBranchDetails({
2482
- apiKey,
2483
- apiUrl: databaseURL,
2484
- fetchImpl: getFetchImplementation(options?.fetchImpl),
2485
- workspacesApiUrl: `${protocol}//${host}`,
2486
- pathParams: { dbBranchName, workspace },
2487
- trace: defaultTrace
2488
- });
2489
- } catch (err) {
2490
- if (isObject(err) && err.status === 404)
2491
- return null;
2492
- throw err;
2493
- }
2494
- }
2495
- function getDatabaseURL() {
2496
- try {
2497
- const { databaseURL } = getEnvironment();
2498
- return databaseURL;
2499
- } catch (err) {
2500
- return void 0;
2501
- }
2502
- }
2503
-
2504
3196
  var __accessCheck = (obj, member, msg) => {
2505
3197
  if (!member.has(obj))
2506
3198
  throw TypeError("Cannot " + msg);
@@ -2541,42 +3233,57 @@ const buildClient = (plugins) => {
2541
3233
  };
2542
3234
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2543
3235
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3236
+ const transactions = new TransactionPlugin().build(pluginOptions);
2544
3237
  this.db = db;
2545
3238
  this.search = search;
3239
+ this.transactions = transactions;
2546
3240
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
2547
3241
  if (namespace === void 0)
2548
3242
  continue;
2549
- const result = namespace.build(pluginOptions);
2550
- if (result instanceof Promise) {
2551
- void result.then((namespace2) => {
2552
- this[key] = namespace2;
2553
- });
2554
- } else {
2555
- this[key] = result;
2556
- }
3243
+ this[key] = namespace.build(pluginOptions);
2557
3244
  }
2558
3245
  }
2559
3246
  async getConfig() {
2560
3247
  const databaseURL = __privateGet(this, _options).databaseURL;
2561
- const branch = await __privateGet(this, _options).branch();
3248
+ const branch = __privateGet(this, _options).branch;
2562
3249
  return { databaseURL, branch };
2563
3250
  }
2564
3251
  }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3252
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3253
+ const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3254
+ if (isBrowser && !enableBrowser) {
3255
+ throw new Error(
3256
+ "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."
3257
+ );
3258
+ }
2565
3259
  const fetch = getFetchImplementation(options?.fetch);
2566
3260
  const databaseURL = options?.databaseURL || getDatabaseURL();
2567
3261
  const apiKey = options?.apiKey || getAPIKey();
2568
3262
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2569
3263
  const trace = options?.trace ?? defaultTrace;
2570
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
3264
+ const clientName = options?.clientName;
3265
+ const host = options?.host ?? "production";
3266
+ const branch = options?.branch !== void 0 ? __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : "main";
2571
3267
  if (!apiKey) {
2572
3268
  throw new Error("Option apiKey is required");
2573
3269
  }
2574
3270
  if (!databaseURL) {
2575
3271
  throw new Error("Option databaseURL is required");
2576
3272
  }
2577
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2578
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2579
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3273
+ return {
3274
+ fetch,
3275
+ databaseURL,
3276
+ apiKey,
3277
+ branch,
3278
+ cache,
3279
+ trace,
3280
+ host,
3281
+ clientID: generateUUID(),
3282
+ enableBrowser,
3283
+ clientName
3284
+ };
3285
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({ fetch, apiKey, databaseURL, branch, trace, clientID, clientName }) {
3286
+ const branchValue = __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2580
3287
  if (!branchValue)
2581
3288
  throw new Error("Unable to resolve branch value");
2582
3289
  return {
@@ -2588,19 +3295,21 @@ const buildClient = (plugins) => {
2588
3295
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2589
3296
  return databaseURL + newPath;
2590
3297
  },
2591
- trace
3298
+ trace,
3299
+ clientID,
3300
+ clientName
2592
3301
  };
2593
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3302
+ }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = function(param) {
2594
3303
  if (__privateGet(this, _branch))
2595
3304
  return __privateGet(this, _branch);
2596
3305
  if (param === void 0)
2597
3306
  return void 0;
2598
3307
  const strategies = Array.isArray(param) ? [...param] : [param];
2599
- const evaluateBranch = async (strategy) => {
2600
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3308
+ const evaluateBranch = (strategy) => {
3309
+ return isBranchStrategyBuilder(strategy) ? strategy() : strategy;
2601
3310
  };
2602
- for await (const strategy of strategies) {
2603
- const branch = await evaluateBranch(strategy);
3311
+ for (const strategy of strategies) {
3312
+ const branch = evaluateBranch(strategy);
2604
3313
  if (branch) {
2605
3314
  __privateSet(this, _branch, branch);
2606
3315
  return branch;
@@ -2679,7 +3388,7 @@ const deserialize = (json) => {
2679
3388
  };
2680
3389
 
2681
3390
  function buildWorkerRunner(config) {
2682
- return function xataWorker(name, _worker) {
3391
+ return function xataWorker(name, worker) {
2683
3392
  return async (...args) => {
2684
3393
  const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2685
3394
  const result = await fetch(url, {
@@ -2701,6 +3410,7 @@ class XataError extends Error {
2701
3410
  }
2702
3411
 
2703
3412
  exports.BaseClient = BaseClient;
3413
+ exports.FetcherError = FetcherError;
2704
3414
  exports.Operations = operationsByTag;
2705
3415
  exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
2706
3416
  exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
@@ -2724,14 +3434,10 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
2724
3434
  exports.addTableColumn = addTableColumn;
2725
3435
  exports.aggregateTable = aggregateTable;
2726
3436
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3437
+ exports.branchTransaction = branchTransaction;
2727
3438
  exports.buildClient = buildClient;
2728
3439
  exports.buildWorkerRunner = buildWorkerRunner;
2729
3440
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2730
- exports.cPCreateDatabase = cPCreateDatabase;
2731
- exports.cPDeleteDatabase = cPDeleteDatabase;
2732
- exports.cPGetCPDatabaseMetadata = cPGetCPDatabaseMetadata;
2733
- exports.cPGetDatabaseList = cPGetDatabaseList;
2734
- exports.cPUpdateCPDatabaseMetadata = cPUpdateCPDatabaseMetadata;
2735
3441
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2736
3442
  exports.compareBranchSchemas = compareBranchSchemas;
2737
3443
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
@@ -2766,8 +3472,6 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
2766
3472
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
2767
3473
  exports.getBranchStats = getBranchStats;
2768
3474
  exports.getColumn = getColumn;
2769
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
2770
- exports.getCurrentBranchName = getCurrentBranchName;
2771
3475
  exports.getDatabaseList = getDatabaseList;
2772
3476
  exports.getDatabaseMetadata = getDatabaseMetadata;
2773
3477
  exports.getDatabaseURL = getDatabaseURL;
@@ -2807,12 +3511,14 @@ exports.lessEquals = lessEquals;
2807
3511
  exports.lessThan = lessThan;
2808
3512
  exports.lessThanEquals = lessThanEquals;
2809
3513
  exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3514
+ exports.listRegions = listRegions;
2810
3515
  exports.lt = lt;
2811
3516
  exports.lte = lte;
2812
3517
  exports.mergeMigrationRequest = mergeMigrationRequest;
2813
3518
  exports.notExists = notExists;
2814
3519
  exports.operationsByTag = operationsByTag;
2815
3520
  exports.parseProviderString = parseProviderString;
3521
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
2816
3522
  exports.pattern = pattern;
2817
3523
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
2818
3524
  exports.queryMigrationRequests = queryMigrationRequests;