@xata.io/client 0.0.0-alpha.vf721f5c → 0.0.0-alpha.vf7400f4

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,25 +166,20 @@ 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"] };
169
+ function getDatabaseURL() {
138
170
  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();
171
+ const { databaseURL } = getEnvironment();
172
+ return databaseURL;
144
173
  } catch (err) {
174
+ return void 0;
145
175
  }
176
+ }
177
+ function getBranch() {
146
178
  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
- }
179
+ const { branch, envBranch } = getEnvironment();
180
+ return branch ?? envBranch;
151
181
  } catch (err) {
182
+ return void 0;
152
183
  }
153
184
  }
154
185
 
@@ -161,6 +192,29 @@ function getAPIKey() {
161
192
  }
162
193
  }
163
194
 
195
+ var __accessCheck$8 = (obj, member, msg) => {
196
+ if (!member.has(obj))
197
+ throw TypeError("Cannot " + msg);
198
+ };
199
+ var __privateGet$8 = (obj, member, getter) => {
200
+ __accessCheck$8(obj, member, "read from private field");
201
+ return getter ? getter.call(obj) : member.get(obj);
202
+ };
203
+ var __privateAdd$8 = (obj, member, value) => {
204
+ if (member.has(obj))
205
+ throw TypeError("Cannot add the same private member more than once");
206
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
207
+ };
208
+ var __privateSet$8 = (obj, member, value, setter) => {
209
+ __accessCheck$8(obj, member, "write to private field");
210
+ setter ? setter.call(obj, value) : member.set(obj, value);
211
+ return value;
212
+ };
213
+ var __privateMethod$4 = (obj, member, method) => {
214
+ __accessCheck$8(obj, member, "access private method");
215
+ return method;
216
+ };
217
+ var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
164
218
  function getFetchImplementation(userFetch) {
165
219
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
166
220
  const fetchImpl = userFetch ?? globalFetch;
@@ -171,8 +225,81 @@ function getFetchImplementation(userFetch) {
171
225
  }
172
226
  return fetchImpl;
173
227
  }
228
+ class ApiRequestPool {
229
+ constructor(concurrency = 10) {
230
+ __privateAdd$8(this, _enqueue);
231
+ __privateAdd$8(this, _fetch, void 0);
232
+ __privateAdd$8(this, _queue, void 0);
233
+ __privateAdd$8(this, _concurrency, void 0);
234
+ __privateSet$8(this, _queue, []);
235
+ __privateSet$8(this, _concurrency, concurrency);
236
+ this.running = 0;
237
+ this.started = 0;
238
+ }
239
+ setFetch(fetch2) {
240
+ __privateSet$8(this, _fetch, fetch2);
241
+ }
242
+ getFetch() {
243
+ if (!__privateGet$8(this, _fetch)) {
244
+ throw new Error("Fetch not set");
245
+ }
246
+ return __privateGet$8(this, _fetch);
247
+ }
248
+ request(url, options) {
249
+ const start = new Date();
250
+ const fetch2 = this.getFetch();
251
+ const runRequest = async (stalled = false) => {
252
+ const response = await fetch2(url, options);
253
+ if (response.status === 429) {
254
+ const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
255
+ await timeout(rateLimitReset * 1e3);
256
+ return await runRequest(true);
257
+ }
258
+ if (stalled) {
259
+ const stalledTime = new Date().getTime() - start.getTime();
260
+ console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
261
+ }
262
+ return response;
263
+ };
264
+ return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
265
+ return await runRequest();
266
+ });
267
+ }
268
+ }
269
+ _fetch = new WeakMap();
270
+ _queue = new WeakMap();
271
+ _concurrency = new WeakMap();
272
+ _enqueue = new WeakSet();
273
+ enqueue_fn = function(task) {
274
+ const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
275
+ this.started--;
276
+ this.running++;
277
+ }).then(() => task()).finally(() => {
278
+ this.running--;
279
+ const next = __privateGet$8(this, _queue).shift();
280
+ if (next !== void 0) {
281
+ this.started++;
282
+ next();
283
+ }
284
+ });
285
+ if (this.running + this.started < __privateGet$8(this, _concurrency)) {
286
+ const next = __privateGet$8(this, _queue).shift();
287
+ if (next !== void 0) {
288
+ this.started++;
289
+ next();
290
+ }
291
+ }
292
+ return promise;
293
+ };
174
294
 
175
- const VERSION = "0.0.0-alpha.vf721f5c";
295
+ function generateUUID() {
296
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
297
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
298
+ return v.toString(16);
299
+ });
300
+ }
301
+
302
+ const VERSION = "0.22.3";
176
303
 
177
304
  class ErrorWithCause extends Error {
178
305
  constructor(message, options) {
@@ -183,7 +310,7 @@ class FetcherError extends ErrorWithCause {
183
310
  constructor(status, data, requestId) {
184
311
  super(getMessage(data));
185
312
  this.status = status;
186
- this.errors = isBulkError(data) ? data.errors : void 0;
313
+ this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
187
314
  this.requestId = requestId;
188
315
  if (data instanceof Error) {
189
316
  this.stack = data.stack;
@@ -215,6 +342,7 @@ function getMessage(data) {
215
342
  }
216
343
  }
217
344
 
345
+ const pool = new ApiRequestPool();
218
346
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
219
347
  const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
220
348
  if (value === void 0 || value === null)
@@ -229,58 +357,79 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
229
357
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
230
358
  };
231
359
  function buildBaseUrl({
360
+ endpoint,
232
361
  path,
233
362
  workspacesApiUrl,
234
363
  apiUrl,
235
- pathParams
364
+ pathParams = {}
236
365
  }) {
237
- if (pathParams?.workspace === void 0)
238
- return `${apiUrl}${path}`;
239
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
240
- return url.replace("{workspaceId}", String(pathParams.workspace));
366
+ if (endpoint === "dataPlane") {
367
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
368
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
369
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
370
+ }
371
+ return `${apiUrl}${path}`;
241
372
  }
242
373
  function hostHeader(url) {
243
374
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
244
375
  const { groups } = pattern.exec(url) ?? {};
245
376
  return groups?.host ? { Host: groups.host } : {};
246
377
  }
378
+ const defaultClientID = generateUUID();
247
379
  async function fetch$1({
248
380
  url: path,
249
381
  method,
250
382
  body,
251
- headers,
383
+ headers: customHeaders,
252
384
  pathParams,
253
385
  queryParams,
254
- fetchImpl,
386
+ fetch: fetch2,
255
387
  apiKey,
388
+ endpoint,
256
389
  apiUrl,
257
390
  workspacesApiUrl,
258
- trace
391
+ trace,
392
+ signal,
393
+ clientID,
394
+ sessionID,
395
+ clientName,
396
+ xataAgentExtra,
397
+ fetchOptions = {}
259
398
  }) {
260
- return trace(
399
+ pool.setFetch(fetch2);
400
+ return await trace(
261
401
  `${method.toUpperCase()} ${path}`,
262
402
  async ({ setAttributes }) => {
263
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
403
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
264
404
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
265
405
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
266
406
  setAttributes({
267
407
  [TraceAttributes.HTTP_URL]: url,
268
408
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
269
409
  });
270
- const response = await fetchImpl(url, {
410
+ const xataAgent = compact([
411
+ ["client", "TS_SDK"],
412
+ ["version", VERSION],
413
+ isDefined(clientName) ? ["service", clientName] : void 0,
414
+ ...Object.entries(xataAgentExtra ?? {})
415
+ ]).map(([key, value]) => `${key}=${value}`).join("; ");
416
+ const headers = {
417
+ "Accept-Encoding": "identity",
418
+ "Content-Type": "application/json",
419
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
420
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
421
+ "X-Xata-Agent": xataAgent,
422
+ ...customHeaders,
423
+ ...hostHeader(fullUrl),
424
+ Authorization: `Bearer ${apiKey}`
425
+ };
426
+ const response = await pool.request(url, {
427
+ ...fetchOptions,
271
428
  method: method.toUpperCase(),
272
429
  body: body ? JSON.stringify(body) : void 0,
273
- headers: {
274
- "Content-Type": "application/json",
275
- "User-Agent": `Xata client-ts/${VERSION}`,
276
- ...headers,
277
- ...hostHeader(fullUrl),
278
- Authorization: `Bearer ${apiKey}`
279
- }
430
+ headers,
431
+ signal
280
432
  });
281
- if (response.status === 204) {
282
- return {};
283
- }
284
433
  const { host, protocol } = parseUrl(response.url);
285
434
  const requestId = response.headers?.get("x-request-id") ?? void 0;
286
435
  setAttributes({
@@ -290,6 +439,12 @@ async function fetch$1({
290
439
  [TraceAttributes.HTTP_HOST]: host,
291
440
  [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
292
441
  });
442
+ if (response.status === 204) {
443
+ return {};
444
+ }
445
+ if (response.status === 429) {
446
+ throw new FetcherError(response.status, "Rate limit exceeded", requestId);
447
+ }
293
448
  try {
294
449
  const jsonResponse = await response.json();
295
450
  if (response.ok) {
@@ -312,279 +467,159 @@ function parseUrl(url) {
312
467
  }
313
468
  }
314
469
 
315
- const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
316
- const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
317
- const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
318
- const getUserAPIKeys = (variables) => fetch$1({
319
- url: "/user/keys",
320
- method: "get",
321
- ...variables
322
- });
323
- const createUserAPIKey = (variables) => fetch$1({
324
- url: "/user/keys/{keyName}",
325
- method: "post",
326
- ...variables
327
- });
328
- const deleteUserAPIKey = (variables) => fetch$1({
329
- url: "/user/keys/{keyName}",
330
- method: "delete",
331
- ...variables
332
- });
333
- const createWorkspace = (variables) => fetch$1({
334
- url: "/workspaces",
335
- method: "post",
336
- ...variables
337
- });
338
- const getWorkspacesList = (variables) => fetch$1({
339
- url: "/workspaces",
340
- method: "get",
341
- ...variables
342
- });
343
- const getWorkspace = (variables) => fetch$1({
344
- url: "/workspaces/{workspaceId}",
345
- method: "get",
346
- ...variables
347
- });
348
- const updateWorkspace = (variables) => fetch$1({
349
- url: "/workspaces/{workspaceId}",
350
- method: "put",
351
- ...variables
352
- });
353
- const deleteWorkspace = (variables) => fetch$1({
354
- url: "/workspaces/{workspaceId}",
355
- method: "delete",
356
- ...variables
357
- });
358
- const getWorkspaceMembersList = (variables) => fetch$1({
359
- url: "/workspaces/{workspaceId}/members",
360
- method: "get",
361
- ...variables
362
- });
363
- const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
364
- const removeWorkspaceMember = (variables) => fetch$1({
365
- url: "/workspaces/{workspaceId}/members/{userId}",
366
- method: "delete",
367
- ...variables
368
- });
369
- const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
370
- const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
371
- const cancelWorkspaceMemberInvite = (variables) => fetch$1({
372
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
373
- method: "delete",
374
- ...variables
375
- });
376
- const resendWorkspaceMemberInvite = (variables) => fetch$1({
377
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
378
- method: "post",
379
- ...variables
380
- });
381
- const acceptWorkspaceMemberInvite = (variables) => fetch$1({
382
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
383
- method: "post",
384
- ...variables
385
- });
386
- const getDatabaseList = (variables) => fetch$1({
387
- url: "/dbs",
388
- method: "get",
389
- ...variables
390
- });
391
- const getBranchList = (variables) => fetch$1({
392
- url: "/dbs/{dbName}",
393
- method: "get",
394
- ...variables
395
- });
396
- const createDatabase = (variables) => fetch$1({
397
- url: "/dbs/{dbName}",
398
- method: "put",
399
- ...variables
400
- });
401
- const deleteDatabase = (variables) => fetch$1({
470
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
471
+
472
+ const getBranchList = (variables, signal) => dataPlaneFetch({
402
473
  url: "/dbs/{dbName}",
403
- method: "delete",
404
- ...variables
405
- });
406
- const getDatabaseMetadata = (variables) => fetch$1({
407
- url: "/dbs/{dbName}/metadata",
408
474
  method: "get",
409
- ...variables
410
- });
411
- const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
412
- const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
413
- const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
414
- const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
415
- const resolveBranch = (variables) => fetch$1({
416
- url: "/dbs/{dbName}/resolveBranch",
417
- method: "get",
418
- ...variables
419
- });
420
- const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
421
- const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
422
- const getMigrationRequest = (variables) => fetch$1({
423
- url: "/dbs/{dbName}/migrations/{mrNumber}",
424
- method: "get",
425
- ...variables
426
- });
427
- const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
428
- const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
429
- const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
430
- const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
431
- const mergeMigrationRequest = (variables) => fetch$1({
432
- url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
433
- method: "post",
434
- ...variables
475
+ ...variables,
476
+ signal
435
477
  });
436
- const getBranchDetails = (variables) => fetch$1({
478
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
437
479
  url: "/db/{dbBranchName}",
438
480
  method: "get",
439
- ...variables
481
+ ...variables,
482
+ signal
440
483
  });
441
- const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
442
- const deleteBranch = (variables) => fetch$1({
484
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
485
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
443
486
  url: "/db/{dbBranchName}",
444
487
  method: "delete",
445
- ...variables
488
+ ...variables,
489
+ signal
446
490
  });
447
- const updateBranchMetadata = (variables) => fetch$1({
491
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
448
492
  url: "/db/{dbBranchName}/metadata",
449
493
  method: "put",
450
- ...variables
494
+ ...variables,
495
+ signal
451
496
  });
452
- const getBranchMetadata = (variables) => fetch$1({
497
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
453
498
  url: "/db/{dbBranchName}/metadata",
454
499
  method: "get",
455
- ...variables
500
+ ...variables,
501
+ signal
456
502
  });
457
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
458
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
459
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
460
- const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
461
- const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
462
- const updateBranchSchema = (variables) => fetch$1({
463
- url: "/db/{dbBranchName}/schema/update",
464
- method: "post",
465
- ...variables
466
- });
467
- const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
468
- const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
469
- const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
470
- const getBranchStats = (variables) => fetch$1({
503
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
471
504
  url: "/db/{dbBranchName}/stats",
472
505
  method: "get",
473
- ...variables
506
+ ...variables,
507
+ signal
508
+ });
509
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
510
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
511
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
512
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
513
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
514
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
515
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
516
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
517
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
518
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
519
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
520
+ method: "get",
521
+ ...variables,
522
+ signal
474
523
  });
475
- const createTable = (variables) => fetch$1({
524
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
525
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
526
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
527
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
528
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
529
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
530
+ method: "post",
531
+ ...variables,
532
+ signal
533
+ });
534
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
535
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
536
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
537
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
538
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
539
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
540
+ const createTable = (variables, signal) => dataPlaneFetch({
476
541
  url: "/db/{dbBranchName}/tables/{tableName}",
477
542
  method: "put",
478
- ...variables
543
+ ...variables,
544
+ signal
479
545
  });
480
- const deleteTable = (variables) => fetch$1({
546
+ const deleteTable = (variables, signal) => dataPlaneFetch({
481
547
  url: "/db/{dbBranchName}/tables/{tableName}",
482
548
  method: "delete",
483
- ...variables
484
- });
485
- const updateTable = (variables) => fetch$1({
486
- url: "/db/{dbBranchName}/tables/{tableName}",
487
- method: "patch",
488
- ...variables
549
+ ...variables,
550
+ signal
489
551
  });
490
- const getTableSchema = (variables) => fetch$1({
552
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
553
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
491
554
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
492
555
  method: "get",
493
- ...variables
556
+ ...variables,
557
+ signal
494
558
  });
495
- const setTableSchema = (variables) => fetch$1({
496
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
497
- method: "put",
498
- ...variables
499
- });
500
- const getTableColumns = (variables) => fetch$1({
559
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
560
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
501
561
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
502
562
  method: "get",
503
- ...variables
504
- });
505
- const addTableColumn = (variables) => fetch$1({
506
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
507
- method: "post",
508
- ...variables
563
+ ...variables,
564
+ signal
509
565
  });
510
- const getColumn = (variables) => fetch$1({
566
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
567
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
568
+ );
569
+ const getColumn = (variables, signal) => dataPlaneFetch({
511
570
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
512
571
  method: "get",
513
- ...variables
572
+ ...variables,
573
+ signal
514
574
  });
515
- const deleteColumn = (variables) => fetch$1({
575
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
576
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
516
577
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
517
578
  method: "delete",
518
- ...variables
519
- });
520
- const updateColumn = (variables) => fetch$1({
521
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
522
- method: "patch",
523
- ...variables
524
- });
525
- const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
526
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
527
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
528
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
529
- const deleteRecord = (variables) => fetch$1({
530
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
531
- method: "delete",
532
- ...variables
579
+ ...variables,
580
+ signal
533
581
  });
534
- const getRecord = (variables) => fetch$1({
582
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
583
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
584
+ const getRecord = (variables, signal) => dataPlaneFetch({
535
585
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
536
586
  method: "get",
537
- ...variables
587
+ ...variables,
588
+ signal
538
589
  });
539
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
540
- const queryTable = (variables) => fetch$1({
590
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
591
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
592
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
593
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
594
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
595
+ const queryTable = (variables, signal) => dataPlaneFetch({
541
596
  url: "/db/{dbBranchName}/tables/{tableName}/query",
542
597
  method: "post",
543
- ...variables
598
+ ...variables,
599
+ signal
544
600
  });
545
- const searchTable = (variables) => fetch$1({
546
- url: "/db/{dbBranchName}/tables/{tableName}/search",
601
+ const searchBranch = (variables, signal) => dataPlaneFetch({
602
+ url: "/db/{dbBranchName}/search",
547
603
  method: "post",
548
- ...variables
604
+ ...variables,
605
+ signal
549
606
  });
550
- const searchBranch = (variables) => fetch$1({
551
- url: "/db/{dbBranchName}/search",
607
+ const searchTable = (variables, signal) => dataPlaneFetch({
608
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
552
609
  method: "post",
553
- ...variables
610
+ ...variables,
611
+ signal
554
612
  });
555
- const summarizeTable = (variables) => fetch$1({
556
- url: "/db/{dbBranchName}/tables/{tableName}/summarize",
613
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
614
+ const askTable = (variables, signal) => dataPlaneFetch({
615
+ url: "/db/{dbBranchName}/tables/{tableName}/ask",
557
616
  method: "post",
558
- ...variables
617
+ ...variables,
618
+ signal
559
619
  });
560
- const operationsByTag = {
561
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
562
- workspaces: {
563
- createWorkspace,
564
- getWorkspacesList,
565
- getWorkspace,
566
- updateWorkspace,
567
- deleteWorkspace,
568
- getWorkspaceMembersList,
569
- updateWorkspaceMemberRole,
570
- removeWorkspaceMember,
571
- inviteWorkspaceMember,
572
- updateWorkspaceMemberInvite,
573
- cancelWorkspaceMemberInvite,
574
- resendWorkspaceMemberInvite,
575
- acceptWorkspaceMemberInvite
576
- },
577
- database: {
578
- getDatabaseList,
579
- createDatabase,
580
- deleteDatabase,
581
- getDatabaseMetadata,
582
- updateDatabaseMetadata,
583
- getGitBranchesMapping,
584
- addGitBranchesEntry,
585
- removeGitBranchesEntry,
586
- resolveBranch
587
- },
620
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
621
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
622
+ const operationsByTag$2 = {
588
623
  branch: {
589
624
  getBranchList,
590
625
  getBranchDetails,
@@ -592,10 +627,25 @@ const operationsByTag = {
592
627
  deleteBranch,
593
628
  updateBranchMetadata,
594
629
  getBranchMetadata,
595
- getBranchStats
630
+ getBranchStats,
631
+ getGitBranchesMapping,
632
+ addGitBranchesEntry,
633
+ removeGitBranchesEntry,
634
+ resolveBranch
635
+ },
636
+ migrations: {
637
+ getBranchMigrationHistory,
638
+ getBranchMigrationPlan,
639
+ executeBranchMigrationPlan,
640
+ getBranchSchemaHistory,
641
+ compareBranchWithUserSchema,
642
+ compareBranchSchemas,
643
+ updateBranchSchema,
644
+ previewBranchSchemaEdit,
645
+ applyBranchSchemaEdit
596
646
  },
597
647
  migrationRequests: {
598
- listMigrationRequests,
648
+ queryMigrationRequests,
599
649
  createMigrationRequest,
600
650
  getMigrationRequest,
601
651
  updateMigrationRequest,
@@ -604,17 +654,6 @@ const operationsByTag = {
604
654
  getMigrationRequestIsMerged,
605
655
  mergeMigrationRequest
606
656
  },
607
- branchSchema: {
608
- getBranchMigrationHistory,
609
- executeBranchMigrationPlan,
610
- getBranchMigrationPlan,
611
- compareBranchWithUserSchema,
612
- compareBranchSchemas,
613
- updateBranchSchema,
614
- previewBranchSchemaEdit,
615
- applyBranchSchemaEdit,
616
- getBranchSchemaHistory
617
- },
618
657
  table: {
619
658
  createTable,
620
659
  deleteTable,
@@ -624,24 +663,170 @@ const operationsByTag = {
624
663
  getTableColumns,
625
664
  addTableColumn,
626
665
  getColumn,
627
- deleteColumn,
628
- updateColumn
666
+ updateColumn,
667
+ deleteColumn
629
668
  },
630
669
  records: {
670
+ branchTransaction,
631
671
  insertRecord,
672
+ getRecord,
632
673
  insertRecordWithID,
633
674
  updateRecordWithID,
634
675
  upsertRecordWithID,
635
676
  deleteRecord,
636
- getRecord,
637
- bulkInsertTableRecords,
677
+ bulkInsertTableRecords
678
+ },
679
+ searchAndFilter: {
638
680
  queryTable,
639
- searchTable,
640
681
  searchBranch,
641
- summarizeTable
682
+ searchTable,
683
+ vectorSearchTable,
684
+ askTable,
685
+ summarizeTable,
686
+ aggregateTable
642
687
  }
643
688
  };
644
689
 
690
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
691
+
692
+ const getUser = (variables, signal) => controlPlaneFetch({
693
+ url: "/user",
694
+ method: "get",
695
+ ...variables,
696
+ signal
697
+ });
698
+ const updateUser = (variables, signal) => controlPlaneFetch({
699
+ url: "/user",
700
+ method: "put",
701
+ ...variables,
702
+ signal
703
+ });
704
+ const deleteUser = (variables, signal) => controlPlaneFetch({
705
+ url: "/user",
706
+ method: "delete",
707
+ ...variables,
708
+ signal
709
+ });
710
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
711
+ url: "/user/keys",
712
+ method: "get",
713
+ ...variables,
714
+ signal
715
+ });
716
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
717
+ url: "/user/keys/{keyName}",
718
+ method: "post",
719
+ ...variables,
720
+ signal
721
+ });
722
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
723
+ url: "/user/keys/{keyName}",
724
+ method: "delete",
725
+ ...variables,
726
+ signal
727
+ });
728
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
729
+ url: "/workspaces",
730
+ method: "get",
731
+ ...variables,
732
+ signal
733
+ });
734
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
735
+ url: "/workspaces",
736
+ method: "post",
737
+ ...variables,
738
+ signal
739
+ });
740
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
741
+ url: "/workspaces/{workspaceId}",
742
+ method: "get",
743
+ ...variables,
744
+ signal
745
+ });
746
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
747
+ url: "/workspaces/{workspaceId}",
748
+ method: "put",
749
+ ...variables,
750
+ signal
751
+ });
752
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
753
+ url: "/workspaces/{workspaceId}",
754
+ method: "delete",
755
+ ...variables,
756
+ signal
757
+ });
758
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
759
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
760
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
761
+ url: "/workspaces/{workspaceId}/members/{userId}",
762
+ method: "delete",
763
+ ...variables,
764
+ signal
765
+ });
766
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
767
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
768
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
769
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
770
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
771
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
772
+ url: "/workspaces/{workspaceId}/dbs",
773
+ method: "get",
774
+ ...variables,
775
+ signal
776
+ });
777
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
778
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
779
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
780
+ method: "delete",
781
+ ...variables,
782
+ signal
783
+ });
784
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
785
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
786
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
787
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
788
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
789
+ const listRegions = (variables, signal) => controlPlaneFetch({
790
+ url: "/workspaces/{workspaceId}/regions",
791
+ method: "get",
792
+ ...variables,
793
+ signal
794
+ });
795
+ const operationsByTag$1 = {
796
+ users: { getUser, updateUser, deleteUser },
797
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
798
+ workspaces: {
799
+ getWorkspacesList,
800
+ createWorkspace,
801
+ getWorkspace,
802
+ updateWorkspace,
803
+ deleteWorkspace,
804
+ getWorkspaceMembersList,
805
+ updateWorkspaceMemberRole,
806
+ removeWorkspaceMember
807
+ },
808
+ invites: {
809
+ inviteWorkspaceMember,
810
+ updateWorkspaceMemberInvite,
811
+ cancelWorkspaceMemberInvite,
812
+ acceptWorkspaceMemberInvite,
813
+ resendWorkspaceMemberInvite
814
+ },
815
+ databases: {
816
+ getDatabaseList,
817
+ createDatabase,
818
+ deleteDatabase,
819
+ getDatabaseMetadata,
820
+ updateDatabaseMetadata,
821
+ getDatabaseGithubSettings,
822
+ updateDatabaseGithubSettings,
823
+ deleteDatabaseGithubSettings,
824
+ listRegions
825
+ }
826
+ };
827
+
828
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
829
+
645
830
  function getHostUrl(provider, type) {
646
831
  if (isHostProviderAlias(provider)) {
647
832
  return providers[provider][type];
@@ -653,11 +838,11 @@ function getHostUrl(provider, type) {
653
838
  const providers = {
654
839
  production: {
655
840
  main: "https://api.xata.io",
656
- workspaces: "https://{workspaceId}.xata.sh"
841
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
657
842
  },
658
843
  staging: {
659
- main: "https://staging.xatabase.co",
660
- workspaces: "https://{workspaceId}.staging.xatabase.co"
844
+ main: "https://api.staging-xata.dev",
845
+ workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
661
846
  }
662
847
  };
663
848
  function isHostProviderAlias(alias) {
@@ -666,6 +851,27 @@ function isHostProviderAlias(alias) {
666
851
  function isHostProviderBuilder(builder) {
667
852
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
668
853
  }
854
+ function parseProviderString(provider = "production") {
855
+ if (isHostProviderAlias(provider)) {
856
+ return provider;
857
+ }
858
+ const [main, workspaces] = provider.split(",");
859
+ if (!main || !workspaces)
860
+ return null;
861
+ return { main, workspaces };
862
+ }
863
+ function parseWorkspacesUrlParts(url) {
864
+ if (!isString(url))
865
+ return null;
866
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
867
+ const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
868
+ const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
869
+ const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
870
+ const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
871
+ if (!match)
872
+ return null;
873
+ return { workspace: match[1], region: match[2] };
874
+ }
669
875
 
670
876
  var __accessCheck$7 = (obj, member, msg) => {
671
877
  if (!member.has(obj))
@@ -693,15 +899,19 @@ class XataApiClient {
693
899
  const provider = options.host ?? "production";
694
900
  const apiKey = options.apiKey ?? getAPIKey();
695
901
  const trace = options.trace ?? defaultTrace;
902
+ const clientID = generateUUID();
696
903
  if (!apiKey) {
697
904
  throw new Error("Could not resolve a valid apiKey");
698
905
  }
699
906
  __privateSet$7(this, _extraProps, {
700
907
  apiUrl: getHostUrl(provider, "main"),
701
908
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
702
- fetchImpl: getFetchImplementation(options.fetch),
909
+ fetch: getFetchImplementation(options.fetch),
703
910
  apiKey,
704
- trace
911
+ trace,
912
+ clientName: options.clientName,
913
+ xataAgentExtra: options.xataAgentExtra,
914
+ clientID
705
915
  });
706
916
  }
707
917
  get user() {
@@ -709,21 +919,41 @@ class XataApiClient {
709
919
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
710
920
  return __privateGet$7(this, _namespaces).user;
711
921
  }
922
+ get authentication() {
923
+ if (!__privateGet$7(this, _namespaces).authentication)
924
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
925
+ return __privateGet$7(this, _namespaces).authentication;
926
+ }
712
927
  get workspaces() {
713
928
  if (!__privateGet$7(this, _namespaces).workspaces)
714
929
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
715
930
  return __privateGet$7(this, _namespaces).workspaces;
716
931
  }
717
- get databases() {
718
- if (!__privateGet$7(this, _namespaces).databases)
719
- __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
720
- return __privateGet$7(this, _namespaces).databases;
932
+ get invites() {
933
+ if (!__privateGet$7(this, _namespaces).invites)
934
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
935
+ return __privateGet$7(this, _namespaces).invites;
936
+ }
937
+ get database() {
938
+ if (!__privateGet$7(this, _namespaces).database)
939
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
940
+ return __privateGet$7(this, _namespaces).database;
721
941
  }
722
942
  get branches() {
723
943
  if (!__privateGet$7(this, _namespaces).branches)
724
944
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
725
945
  return __privateGet$7(this, _namespaces).branches;
726
946
  }
947
+ get migrations() {
948
+ if (!__privateGet$7(this, _namespaces).migrations)
949
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
950
+ return __privateGet$7(this, _namespaces).migrations;
951
+ }
952
+ get migrationRequests() {
953
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
954
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
955
+ return __privateGet$7(this, _namespaces).migrationRequests;
956
+ }
727
957
  get tables() {
728
958
  if (!__privateGet$7(this, _namespaces).tables)
729
959
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -734,15 +964,10 @@ class XataApiClient {
734
964
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
735
965
  return __privateGet$7(this, _namespaces).records;
736
966
  }
737
- get migrationRequests() {
738
- if (!__privateGet$7(this, _namespaces).migrationRequests)
739
- __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
740
- return __privateGet$7(this, _namespaces).migrationRequests;
741
- }
742
- get branchSchema() {
743
- if (!__privateGet$7(this, _namespaces).branchSchema)
744
- __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
745
- return __privateGet$7(this, _namespaces).branchSchema;
967
+ get searchAndFilter() {
968
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
969
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
970
+ return __privateGet$7(this, _namespaces).searchAndFilter;
746
971
  }
747
972
  }
748
973
  _extraProps = new WeakMap();
@@ -754,24 +979,29 @@ class UserApi {
754
979
  getUser() {
755
980
  return operationsByTag.users.getUser({ ...this.extraProps });
756
981
  }
757
- updateUser(user) {
982
+ updateUser({ user }) {
758
983
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
759
984
  }
760
985
  deleteUser() {
761
986
  return operationsByTag.users.deleteUser({ ...this.extraProps });
762
987
  }
988
+ }
989
+ class AuthenticationApi {
990
+ constructor(extraProps) {
991
+ this.extraProps = extraProps;
992
+ }
763
993
  getUserAPIKeys() {
764
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
994
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
765
995
  }
766
- createUserAPIKey(keyName) {
767
- return operationsByTag.users.createUserAPIKey({
768
- pathParams: { keyName },
996
+ createUserAPIKey({ name }) {
997
+ return operationsByTag.authentication.createUserAPIKey({
998
+ pathParams: { keyName: name },
769
999
  ...this.extraProps
770
1000
  });
771
1001
  }
772
- deleteUserAPIKey(keyName) {
773
- return operationsByTag.users.deleteUserAPIKey({
774
- pathParams: { keyName },
1002
+ deleteUserAPIKey({ name }) {
1003
+ return operationsByTag.authentication.deleteUserAPIKey({
1004
+ pathParams: { keyName: name },
775
1005
  ...this.extraProps
776
1006
  });
777
1007
  }
@@ -780,146 +1010,114 @@ class WorkspaceApi {
780
1010
  constructor(extraProps) {
781
1011
  this.extraProps = extraProps;
782
1012
  }
783
- createWorkspace(workspaceMeta) {
784
- return operationsByTag.workspaces.createWorkspace({
785
- body: workspaceMeta,
786
- ...this.extraProps
787
- });
788
- }
789
- getWorkspacesList() {
790
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
791
- }
792
- getWorkspace(workspaceId) {
793
- return operationsByTag.workspaces.getWorkspace({
794
- pathParams: { workspaceId },
795
- ...this.extraProps
796
- });
797
- }
798
- updateWorkspace(workspaceId, workspaceMeta) {
799
- return operationsByTag.workspaces.updateWorkspace({
800
- pathParams: { workspaceId },
801
- body: workspaceMeta,
802
- ...this.extraProps
803
- });
804
- }
805
- deleteWorkspace(workspaceId) {
806
- return operationsByTag.workspaces.deleteWorkspace({
807
- pathParams: { workspaceId },
808
- ...this.extraProps
809
- });
810
- }
811
- getWorkspaceMembersList(workspaceId) {
812
- return operationsByTag.workspaces.getWorkspaceMembersList({
813
- pathParams: { workspaceId },
814
- ...this.extraProps
815
- });
816
- }
817
- updateWorkspaceMemberRole(workspaceId, userId, role) {
818
- return operationsByTag.workspaces.updateWorkspaceMemberRole({
819
- pathParams: { workspaceId, userId },
820
- body: { role },
821
- ...this.extraProps
822
- });
823
- }
824
- removeWorkspaceMember(workspaceId, userId) {
825
- return operationsByTag.workspaces.removeWorkspaceMember({
826
- pathParams: { workspaceId, userId },
827
- ...this.extraProps
828
- });
829
- }
830
- inviteWorkspaceMember(workspaceId, email, role) {
831
- return operationsByTag.workspaces.inviteWorkspaceMember({
832
- pathParams: { workspaceId },
833
- body: { email, role },
834
- ...this.extraProps
835
- });
1013
+ getWorkspacesList() {
1014
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
836
1015
  }
837
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
838
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
839
- pathParams: { workspaceId, inviteId },
840
- body: { role },
1016
+ createWorkspace({ data }) {
1017
+ return operationsByTag.workspaces.createWorkspace({
1018
+ body: data,
841
1019
  ...this.extraProps
842
1020
  });
843
1021
  }
844
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
845
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
846
- pathParams: { workspaceId, inviteId },
1022
+ getWorkspace({ workspace }) {
1023
+ return operationsByTag.workspaces.getWorkspace({
1024
+ pathParams: { workspaceId: workspace },
847
1025
  ...this.extraProps
848
1026
  });
849
1027
  }
850
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
851
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
852
- pathParams: { workspaceId, inviteId },
1028
+ updateWorkspace({
1029
+ workspace,
1030
+ update
1031
+ }) {
1032
+ return operationsByTag.workspaces.updateWorkspace({
1033
+ pathParams: { workspaceId: workspace },
1034
+ body: update,
853
1035
  ...this.extraProps
854
1036
  });
855
1037
  }
856
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
857
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
858
- pathParams: { workspaceId, inviteKey },
1038
+ deleteWorkspace({ workspace }) {
1039
+ return operationsByTag.workspaces.deleteWorkspace({
1040
+ pathParams: { workspaceId: workspace },
859
1041
  ...this.extraProps
860
1042
  });
861
1043
  }
862
- }
863
- class DatabaseApi {
864
- constructor(extraProps) {
865
- this.extraProps = extraProps;
866
- }
867
- getDatabaseList(workspace) {
868
- return operationsByTag.database.getDatabaseList({
869
- pathParams: { workspace },
1044
+ getWorkspaceMembersList({ workspace }) {
1045
+ return operationsByTag.workspaces.getWorkspaceMembersList({
1046
+ pathParams: { workspaceId: workspace },
870
1047
  ...this.extraProps
871
1048
  });
872
1049
  }
873
- createDatabase(workspace, dbName, options = {}) {
874
- return operationsByTag.database.createDatabase({
875
- pathParams: { workspace, dbName },
876
- body: options,
1050
+ updateWorkspaceMemberRole({
1051
+ workspace,
1052
+ user,
1053
+ role
1054
+ }) {
1055
+ return operationsByTag.workspaces.updateWorkspaceMemberRole({
1056
+ pathParams: { workspaceId: workspace, userId: user },
1057
+ body: { role },
877
1058
  ...this.extraProps
878
1059
  });
879
1060
  }
880
- deleteDatabase(workspace, dbName) {
881
- return operationsByTag.database.deleteDatabase({
882
- pathParams: { workspace, dbName },
1061
+ removeWorkspaceMember({
1062
+ workspace,
1063
+ user
1064
+ }) {
1065
+ return operationsByTag.workspaces.removeWorkspaceMember({
1066
+ pathParams: { workspaceId: workspace, userId: user },
883
1067
  ...this.extraProps
884
1068
  });
885
1069
  }
886
- getDatabaseMetadata(workspace, dbName) {
887
- return operationsByTag.database.getDatabaseMetadata({
888
- pathParams: { workspace, dbName },
889
- ...this.extraProps
890
- });
1070
+ }
1071
+ class InvitesApi {
1072
+ constructor(extraProps) {
1073
+ this.extraProps = extraProps;
891
1074
  }
892
- updateDatabaseMetadata(workspace, dbName, options = {}) {
893
- return operationsByTag.database.updateDatabaseMetadata({
894
- pathParams: { workspace, dbName },
895
- body: options,
1075
+ inviteWorkspaceMember({
1076
+ workspace,
1077
+ email,
1078
+ role
1079
+ }) {
1080
+ return operationsByTag.invites.inviteWorkspaceMember({
1081
+ pathParams: { workspaceId: workspace },
1082
+ body: { email, role },
896
1083
  ...this.extraProps
897
1084
  });
898
1085
  }
899
- getGitBranchesMapping(workspace, dbName) {
900
- return operationsByTag.database.getGitBranchesMapping({
901
- pathParams: { workspace, dbName },
1086
+ updateWorkspaceMemberInvite({
1087
+ workspace,
1088
+ invite,
1089
+ role
1090
+ }) {
1091
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
1092
+ pathParams: { workspaceId: workspace, inviteId: invite },
1093
+ body: { role },
902
1094
  ...this.extraProps
903
1095
  });
904
1096
  }
905
- addGitBranchesEntry(workspace, dbName, body) {
906
- return operationsByTag.database.addGitBranchesEntry({
907
- pathParams: { workspace, dbName },
908
- body,
1097
+ cancelWorkspaceMemberInvite({
1098
+ workspace,
1099
+ invite
1100
+ }) {
1101
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
1102
+ pathParams: { workspaceId: workspace, inviteId: invite },
909
1103
  ...this.extraProps
910
1104
  });
911
1105
  }
912
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
913
- return operationsByTag.database.removeGitBranchesEntry({
914
- pathParams: { workspace, dbName },
915
- queryParams: { gitBranch },
1106
+ acceptWorkspaceMemberInvite({
1107
+ workspace,
1108
+ key
1109
+ }) {
1110
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
1111
+ pathParams: { workspaceId: workspace, inviteKey: key },
916
1112
  ...this.extraProps
917
1113
  });
918
1114
  }
919
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
920
- return operationsByTag.database.resolveBranch({
921
- pathParams: { workspace, dbName },
922
- queryParams: { gitBranch, fallbackBranch },
1115
+ resendWorkspaceMemberInvite({
1116
+ workspace,
1117
+ invite
1118
+ }) {
1119
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
1120
+ pathParams: { workspaceId: workspace, inviteId: invite },
923
1121
  ...this.extraProps
924
1122
  });
925
1123
  }
@@ -928,48 +1126,132 @@ class BranchApi {
928
1126
  constructor(extraProps) {
929
1127
  this.extraProps = extraProps;
930
1128
  }
931
- getBranchList(workspace, dbName) {
1129
+ getBranchList({
1130
+ workspace,
1131
+ region,
1132
+ database
1133
+ }) {
932
1134
  return operationsByTag.branch.getBranchList({
933
- pathParams: { workspace, dbName },
1135
+ pathParams: { workspace, region, dbName: database },
934
1136
  ...this.extraProps
935
1137
  });
936
1138
  }
937
- getBranchDetails(workspace, database, branch) {
1139
+ getBranchDetails({
1140
+ workspace,
1141
+ region,
1142
+ database,
1143
+ branch
1144
+ }) {
938
1145
  return operationsByTag.branch.getBranchDetails({
939
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1146
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
940
1147
  ...this.extraProps
941
1148
  });
942
1149
  }
943
- createBranch(workspace, database, branch, from, options = {}) {
1150
+ createBranch({
1151
+ workspace,
1152
+ region,
1153
+ database,
1154
+ branch,
1155
+ from,
1156
+ metadata
1157
+ }) {
944
1158
  return operationsByTag.branch.createBranch({
945
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
946
- queryParams: isString(from) ? { from } : void 0,
947
- body: options,
1159
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1160
+ body: { from, metadata },
948
1161
  ...this.extraProps
949
1162
  });
950
1163
  }
951
- deleteBranch(workspace, database, branch) {
1164
+ deleteBranch({
1165
+ workspace,
1166
+ region,
1167
+ database,
1168
+ branch
1169
+ }) {
952
1170
  return operationsByTag.branch.deleteBranch({
953
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1171
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
954
1172
  ...this.extraProps
955
1173
  });
956
1174
  }
957
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
1175
+ updateBranchMetadata({
1176
+ workspace,
1177
+ region,
1178
+ database,
1179
+ branch,
1180
+ metadata
1181
+ }) {
958
1182
  return operationsByTag.branch.updateBranchMetadata({
959
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1183
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
960
1184
  body: metadata,
961
1185
  ...this.extraProps
962
1186
  });
963
1187
  }
964
- getBranchMetadata(workspace, database, branch) {
1188
+ getBranchMetadata({
1189
+ workspace,
1190
+ region,
1191
+ database,
1192
+ branch
1193
+ }) {
965
1194
  return operationsByTag.branch.getBranchMetadata({
966
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1195
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
967
1196
  ...this.extraProps
968
1197
  });
969
1198
  }
970
- getBranchStats(workspace, database, branch) {
1199
+ getBranchStats({
1200
+ workspace,
1201
+ region,
1202
+ database,
1203
+ branch
1204
+ }) {
971
1205
  return operationsByTag.branch.getBranchStats({
972
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1206
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1207
+ ...this.extraProps
1208
+ });
1209
+ }
1210
+ getGitBranchesMapping({
1211
+ workspace,
1212
+ region,
1213
+ database
1214
+ }) {
1215
+ return operationsByTag.branch.getGitBranchesMapping({
1216
+ pathParams: { workspace, region, dbName: database },
1217
+ ...this.extraProps
1218
+ });
1219
+ }
1220
+ addGitBranchesEntry({
1221
+ workspace,
1222
+ region,
1223
+ database,
1224
+ gitBranch,
1225
+ xataBranch
1226
+ }) {
1227
+ return operationsByTag.branch.addGitBranchesEntry({
1228
+ pathParams: { workspace, region, dbName: database },
1229
+ body: { gitBranch, xataBranch },
1230
+ ...this.extraProps
1231
+ });
1232
+ }
1233
+ removeGitBranchesEntry({
1234
+ workspace,
1235
+ region,
1236
+ database,
1237
+ gitBranch
1238
+ }) {
1239
+ return operationsByTag.branch.removeGitBranchesEntry({
1240
+ pathParams: { workspace, region, dbName: database },
1241
+ queryParams: { gitBranch },
1242
+ ...this.extraProps
1243
+ });
1244
+ }
1245
+ resolveBranch({
1246
+ workspace,
1247
+ region,
1248
+ database,
1249
+ gitBranch,
1250
+ fallbackBranch
1251
+ }) {
1252
+ return operationsByTag.branch.resolveBranch({
1253
+ pathParams: { workspace, region, dbName: database },
1254
+ queryParams: { gitBranch, fallbackBranch },
973
1255
  ...this.extraProps
974
1256
  });
975
1257
  }
@@ -978,67 +1260,134 @@ class TableApi {
978
1260
  constructor(extraProps) {
979
1261
  this.extraProps = extraProps;
980
1262
  }
981
- createTable(workspace, database, branch, tableName) {
1263
+ createTable({
1264
+ workspace,
1265
+ region,
1266
+ database,
1267
+ branch,
1268
+ table
1269
+ }) {
982
1270
  return operationsByTag.table.createTable({
983
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1271
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
984
1272
  ...this.extraProps
985
1273
  });
986
1274
  }
987
- deleteTable(workspace, database, branch, tableName) {
1275
+ deleteTable({
1276
+ workspace,
1277
+ region,
1278
+ database,
1279
+ branch,
1280
+ table
1281
+ }) {
988
1282
  return operationsByTag.table.deleteTable({
989
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1283
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
990
1284
  ...this.extraProps
991
1285
  });
992
1286
  }
993
- updateTable(workspace, database, branch, tableName, options) {
1287
+ updateTable({
1288
+ workspace,
1289
+ region,
1290
+ database,
1291
+ branch,
1292
+ table,
1293
+ update
1294
+ }) {
994
1295
  return operationsByTag.table.updateTable({
995
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
996
- body: options,
1296
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1297
+ body: update,
997
1298
  ...this.extraProps
998
1299
  });
999
1300
  }
1000
- getTableSchema(workspace, database, branch, tableName) {
1301
+ getTableSchema({
1302
+ workspace,
1303
+ region,
1304
+ database,
1305
+ branch,
1306
+ table
1307
+ }) {
1001
1308
  return operationsByTag.table.getTableSchema({
1002
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1309
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1003
1310
  ...this.extraProps
1004
1311
  });
1005
1312
  }
1006
- setTableSchema(workspace, database, branch, tableName, options) {
1313
+ setTableSchema({
1314
+ workspace,
1315
+ region,
1316
+ database,
1317
+ branch,
1318
+ table,
1319
+ schema
1320
+ }) {
1007
1321
  return operationsByTag.table.setTableSchema({
1008
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1009
- body: options,
1322
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1323
+ body: schema,
1010
1324
  ...this.extraProps
1011
1325
  });
1012
1326
  }
1013
- getTableColumns(workspace, database, branch, tableName) {
1327
+ getTableColumns({
1328
+ workspace,
1329
+ region,
1330
+ database,
1331
+ branch,
1332
+ table
1333
+ }) {
1014
1334
  return operationsByTag.table.getTableColumns({
1015
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1335
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1016
1336
  ...this.extraProps
1017
1337
  });
1018
1338
  }
1019
- addTableColumn(workspace, database, branch, tableName, column) {
1339
+ addTableColumn({
1340
+ workspace,
1341
+ region,
1342
+ database,
1343
+ branch,
1344
+ table,
1345
+ column
1346
+ }) {
1020
1347
  return operationsByTag.table.addTableColumn({
1021
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1348
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1022
1349
  body: column,
1023
1350
  ...this.extraProps
1024
1351
  });
1025
1352
  }
1026
- getColumn(workspace, database, branch, tableName, columnName) {
1353
+ getColumn({
1354
+ workspace,
1355
+ region,
1356
+ database,
1357
+ branch,
1358
+ table,
1359
+ column
1360
+ }) {
1027
1361
  return operationsByTag.table.getColumn({
1028
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1362
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1029
1363
  ...this.extraProps
1030
1364
  });
1031
1365
  }
1032
- deleteColumn(workspace, database, branch, tableName, columnName) {
1033
- return operationsByTag.table.deleteColumn({
1034
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1366
+ updateColumn({
1367
+ workspace,
1368
+ region,
1369
+ database,
1370
+ branch,
1371
+ table,
1372
+ column,
1373
+ update
1374
+ }) {
1375
+ return operationsByTag.table.updateColumn({
1376
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1377
+ body: update,
1035
1378
  ...this.extraProps
1036
1379
  });
1037
1380
  }
1038
- updateColumn(workspace, database, branch, tableName, columnName, options) {
1039
- return operationsByTag.table.updateColumn({
1040
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1041
- body: options,
1381
+ deleteColumn({
1382
+ workspace,
1383
+ region,
1384
+ database,
1385
+ branch,
1386
+ table,
1387
+ column
1388
+ }) {
1389
+ return operationsByTag.table.deleteColumn({
1390
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1042
1391
  ...this.extraProps
1043
1392
  });
1044
1393
  }
@@ -1047,85 +1396,266 @@ class RecordsApi {
1047
1396
  constructor(extraProps) {
1048
1397
  this.extraProps = extraProps;
1049
1398
  }
1050
- insertRecord(workspace, database, branch, tableName, record, options = {}) {
1399
+ insertRecord({
1400
+ workspace,
1401
+ region,
1402
+ database,
1403
+ branch,
1404
+ table,
1405
+ record,
1406
+ columns
1407
+ }) {
1051
1408
  return operationsByTag.records.insertRecord({
1052
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1053
- queryParams: options,
1409
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1410
+ queryParams: { columns },
1054
1411
  body: record,
1055
1412
  ...this.extraProps
1056
1413
  });
1057
1414
  }
1058
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1415
+ getRecord({
1416
+ workspace,
1417
+ region,
1418
+ database,
1419
+ branch,
1420
+ table,
1421
+ id,
1422
+ columns
1423
+ }) {
1424
+ return operationsByTag.records.getRecord({
1425
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1426
+ queryParams: { columns },
1427
+ ...this.extraProps
1428
+ });
1429
+ }
1430
+ insertRecordWithID({
1431
+ workspace,
1432
+ region,
1433
+ database,
1434
+ branch,
1435
+ table,
1436
+ id,
1437
+ record,
1438
+ columns,
1439
+ createOnly,
1440
+ ifVersion
1441
+ }) {
1059
1442
  return operationsByTag.records.insertRecordWithID({
1060
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1061
- queryParams: options,
1443
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1444
+ queryParams: { columns, createOnly, ifVersion },
1062
1445
  body: record,
1063
1446
  ...this.extraProps
1064
1447
  });
1065
1448
  }
1066
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1449
+ updateRecordWithID({
1450
+ workspace,
1451
+ region,
1452
+ database,
1453
+ branch,
1454
+ table,
1455
+ id,
1456
+ record,
1457
+ columns,
1458
+ ifVersion
1459
+ }) {
1067
1460
  return operationsByTag.records.updateRecordWithID({
1068
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1069
- queryParams: options,
1461
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1462
+ queryParams: { columns, ifVersion },
1070
1463
  body: record,
1071
1464
  ...this.extraProps
1072
1465
  });
1073
1466
  }
1074
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1467
+ upsertRecordWithID({
1468
+ workspace,
1469
+ region,
1470
+ database,
1471
+ branch,
1472
+ table,
1473
+ id,
1474
+ record,
1475
+ columns,
1476
+ ifVersion
1477
+ }) {
1075
1478
  return operationsByTag.records.upsertRecordWithID({
1076
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1077
- queryParams: options,
1479
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1480
+ queryParams: { columns, ifVersion },
1078
1481
  body: record,
1079
1482
  ...this.extraProps
1080
1483
  });
1081
1484
  }
1082
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
1485
+ deleteRecord({
1486
+ workspace,
1487
+ region,
1488
+ database,
1489
+ branch,
1490
+ table,
1491
+ id,
1492
+ columns
1493
+ }) {
1083
1494
  return operationsByTag.records.deleteRecord({
1084
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1085
- queryParams: options,
1086
- ...this.extraProps
1087
- });
1088
- }
1089
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
1090
- return operationsByTag.records.getRecord({
1091
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1092
- queryParams: options,
1495
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1496
+ queryParams: { columns },
1093
1497
  ...this.extraProps
1094
1498
  });
1095
1499
  }
1096
- bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
1500
+ bulkInsertTableRecords({
1501
+ workspace,
1502
+ region,
1503
+ database,
1504
+ branch,
1505
+ table,
1506
+ records,
1507
+ columns
1508
+ }) {
1097
1509
  return operationsByTag.records.bulkInsertTableRecords({
1098
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1099
- queryParams: options,
1510
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1511
+ queryParams: { columns },
1100
1512
  body: { records },
1101
1513
  ...this.extraProps
1102
1514
  });
1103
1515
  }
1104
- queryTable(workspace, database, branch, tableName, query) {
1105
- return operationsByTag.records.queryTable({
1106
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1107
- body: query,
1516
+ branchTransaction({
1517
+ workspace,
1518
+ region,
1519
+ database,
1520
+ branch,
1521
+ operations
1522
+ }) {
1523
+ return operationsByTag.records.branchTransaction({
1524
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1525
+ body: { operations },
1108
1526
  ...this.extraProps
1109
1527
  });
1110
1528
  }
1111
- searchTable(workspace, database, branch, tableName, query) {
1112
- return operationsByTag.records.searchTable({
1113
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1114
- body: query,
1115
- ...this.extraProps
1116
- });
1117
- }
1118
- searchBranch(workspace, database, branch, query) {
1119
- return operationsByTag.records.searchBranch({
1120
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1121
- body: query,
1122
- ...this.extraProps
1123
- });
1529
+ }
1530
+ class SearchAndFilterApi {
1531
+ constructor(extraProps) {
1532
+ this.extraProps = extraProps;
1124
1533
  }
1125
- summarizeTable(workspace, database, branch, tableName, query) {
1126
- return operationsByTag.records.summarizeTable({
1127
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1128
- body: query,
1534
+ queryTable({
1535
+ workspace,
1536
+ region,
1537
+ database,
1538
+ branch,
1539
+ table,
1540
+ filter,
1541
+ sort,
1542
+ page,
1543
+ columns,
1544
+ consistency
1545
+ }) {
1546
+ return operationsByTag.searchAndFilter.queryTable({
1547
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1548
+ body: { filter, sort, page, columns, consistency },
1549
+ ...this.extraProps
1550
+ });
1551
+ }
1552
+ searchTable({
1553
+ workspace,
1554
+ region,
1555
+ database,
1556
+ branch,
1557
+ table,
1558
+ query,
1559
+ fuzziness,
1560
+ target,
1561
+ prefix,
1562
+ filter,
1563
+ highlight,
1564
+ boosters
1565
+ }) {
1566
+ return operationsByTag.searchAndFilter.searchTable({
1567
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1568
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
1569
+ ...this.extraProps
1570
+ });
1571
+ }
1572
+ searchBranch({
1573
+ workspace,
1574
+ region,
1575
+ database,
1576
+ branch,
1577
+ tables,
1578
+ query,
1579
+ fuzziness,
1580
+ prefix,
1581
+ highlight
1582
+ }) {
1583
+ return operationsByTag.searchAndFilter.searchBranch({
1584
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1585
+ body: { tables, query, fuzziness, prefix, highlight },
1586
+ ...this.extraProps
1587
+ });
1588
+ }
1589
+ vectorSearchTable({
1590
+ workspace,
1591
+ region,
1592
+ database,
1593
+ branch,
1594
+ table,
1595
+ queryVector,
1596
+ column,
1597
+ similarityFunction,
1598
+ size,
1599
+ filter
1600
+ }) {
1601
+ return operationsByTag.searchAndFilter.vectorSearchTable({
1602
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1603
+ body: { queryVector, column, similarityFunction, size, filter },
1604
+ ...this.extraProps
1605
+ });
1606
+ }
1607
+ askTable({
1608
+ workspace,
1609
+ region,
1610
+ database,
1611
+ branch,
1612
+ table,
1613
+ question,
1614
+ fuzziness,
1615
+ target,
1616
+ prefix,
1617
+ filter,
1618
+ boosters,
1619
+ rules
1620
+ }) {
1621
+ return operationsByTag.searchAndFilter.askTable({
1622
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1623
+ body: { question, fuzziness, target, prefix, filter, boosters, rules },
1624
+ ...this.extraProps
1625
+ });
1626
+ }
1627
+ summarizeTable({
1628
+ workspace,
1629
+ region,
1630
+ database,
1631
+ branch,
1632
+ table,
1633
+ filter,
1634
+ columns,
1635
+ summaries,
1636
+ sort,
1637
+ summariesFilter,
1638
+ page,
1639
+ consistency
1640
+ }) {
1641
+ return operationsByTag.searchAndFilter.summarizeTable({
1642
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1643
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1644
+ ...this.extraProps
1645
+ });
1646
+ }
1647
+ aggregateTable({
1648
+ workspace,
1649
+ region,
1650
+ database,
1651
+ branch,
1652
+ table,
1653
+ filter,
1654
+ aggs
1655
+ }) {
1656
+ return operationsByTag.searchAndFilter.aggregateTable({
1657
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1658
+ body: { filter, aggs },
1129
1659
  ...this.extraProps
1130
1660
  });
1131
1661
  }
@@ -1134,138 +1664,334 @@ class MigrationRequestsApi {
1134
1664
  constructor(extraProps) {
1135
1665
  this.extraProps = extraProps;
1136
1666
  }
1137
- listMigrationRequests(workspace, database, options = {}) {
1138
- return operationsByTag.migrationRequests.listMigrationRequests({
1139
- pathParams: { workspace, dbName: database },
1140
- body: options,
1141
- ...this.extraProps
1142
- });
1143
- }
1144
- createMigrationRequest(workspace, database, options) {
1667
+ queryMigrationRequests({
1668
+ workspace,
1669
+ region,
1670
+ database,
1671
+ filter,
1672
+ sort,
1673
+ page,
1674
+ columns
1675
+ }) {
1676
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1677
+ pathParams: { workspace, region, dbName: database },
1678
+ body: { filter, sort, page, columns },
1679
+ ...this.extraProps
1680
+ });
1681
+ }
1682
+ createMigrationRequest({
1683
+ workspace,
1684
+ region,
1685
+ database,
1686
+ migration
1687
+ }) {
1145
1688
  return operationsByTag.migrationRequests.createMigrationRequest({
1146
- pathParams: { workspace, dbName: database },
1147
- body: options,
1689
+ pathParams: { workspace, region, dbName: database },
1690
+ body: migration,
1148
1691
  ...this.extraProps
1149
1692
  });
1150
1693
  }
1151
- getMigrationRequest(workspace, database, migrationRequest) {
1694
+ getMigrationRequest({
1695
+ workspace,
1696
+ region,
1697
+ database,
1698
+ migrationRequest
1699
+ }) {
1152
1700
  return operationsByTag.migrationRequests.getMigrationRequest({
1153
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1701
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1154
1702
  ...this.extraProps
1155
1703
  });
1156
1704
  }
1157
- updateMigrationRequest(workspace, database, migrationRequest, options) {
1705
+ updateMigrationRequest({
1706
+ workspace,
1707
+ region,
1708
+ database,
1709
+ migrationRequest,
1710
+ update
1711
+ }) {
1158
1712
  return operationsByTag.migrationRequests.updateMigrationRequest({
1159
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1160
- body: options,
1713
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1714
+ body: update,
1161
1715
  ...this.extraProps
1162
1716
  });
1163
1717
  }
1164
- listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1718
+ listMigrationRequestsCommits({
1719
+ workspace,
1720
+ region,
1721
+ database,
1722
+ migrationRequest,
1723
+ page
1724
+ }) {
1165
1725
  return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1166
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1167
- body: options,
1726
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1727
+ body: { page },
1168
1728
  ...this.extraProps
1169
1729
  });
1170
1730
  }
1171
- compareMigrationRequest(workspace, database, migrationRequest) {
1731
+ compareMigrationRequest({
1732
+ workspace,
1733
+ region,
1734
+ database,
1735
+ migrationRequest
1736
+ }) {
1172
1737
  return operationsByTag.migrationRequests.compareMigrationRequest({
1173
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1738
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1174
1739
  ...this.extraProps
1175
1740
  });
1176
1741
  }
1177
- getMigrationRequestIsMerged(workspace, database, migrationRequest) {
1742
+ getMigrationRequestIsMerged({
1743
+ workspace,
1744
+ region,
1745
+ database,
1746
+ migrationRequest
1747
+ }) {
1178
1748
  return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1179
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1749
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1180
1750
  ...this.extraProps
1181
1751
  });
1182
1752
  }
1183
- mergeMigrationRequest(workspace, database, migrationRequest) {
1753
+ mergeMigrationRequest({
1754
+ workspace,
1755
+ region,
1756
+ database,
1757
+ migrationRequest
1758
+ }) {
1184
1759
  return operationsByTag.migrationRequests.mergeMigrationRequest({
1185
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1760
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1186
1761
  ...this.extraProps
1187
1762
  });
1188
1763
  }
1189
1764
  }
1190
- class BranchSchemaApi {
1765
+ class MigrationsApi {
1191
1766
  constructor(extraProps) {
1192
1767
  this.extraProps = extraProps;
1193
1768
  }
1194
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
1195
- return operationsByTag.branchSchema.getBranchMigrationHistory({
1196
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1197
- body: options,
1769
+ getBranchMigrationHistory({
1770
+ workspace,
1771
+ region,
1772
+ database,
1773
+ branch,
1774
+ limit,
1775
+ startFrom
1776
+ }) {
1777
+ return operationsByTag.migrations.getBranchMigrationHistory({
1778
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1779
+ body: { limit, startFrom },
1780
+ ...this.extraProps
1781
+ });
1782
+ }
1783
+ getBranchMigrationPlan({
1784
+ workspace,
1785
+ region,
1786
+ database,
1787
+ branch,
1788
+ schema
1789
+ }) {
1790
+ return operationsByTag.migrations.getBranchMigrationPlan({
1791
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1792
+ body: schema,
1198
1793
  ...this.extraProps
1199
1794
  });
1200
1795
  }
1201
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1202
- return operationsByTag.branchSchema.executeBranchMigrationPlan({
1203
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1204
- body: migrationPlan,
1796
+ executeBranchMigrationPlan({
1797
+ workspace,
1798
+ region,
1799
+ database,
1800
+ branch,
1801
+ plan
1802
+ }) {
1803
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1804
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1805
+ body: plan,
1806
+ ...this.extraProps
1807
+ });
1808
+ }
1809
+ getBranchSchemaHistory({
1810
+ workspace,
1811
+ region,
1812
+ database,
1813
+ branch,
1814
+ page
1815
+ }) {
1816
+ return operationsByTag.migrations.getBranchSchemaHistory({
1817
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1818
+ body: { page },
1819
+ ...this.extraProps
1820
+ });
1821
+ }
1822
+ compareBranchWithUserSchema({
1823
+ workspace,
1824
+ region,
1825
+ database,
1826
+ branch,
1827
+ schema,
1828
+ schemaOperations,
1829
+ branchOperations
1830
+ }) {
1831
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1832
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1833
+ body: { schema, schemaOperations, branchOperations },
1834
+ ...this.extraProps
1835
+ });
1836
+ }
1837
+ compareBranchSchemas({
1838
+ workspace,
1839
+ region,
1840
+ database,
1841
+ branch,
1842
+ compare,
1843
+ sourceBranchOperations,
1844
+ targetBranchOperations
1845
+ }) {
1846
+ return operationsByTag.migrations.compareBranchSchemas({
1847
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1848
+ body: { sourceBranchOperations, targetBranchOperations },
1849
+ ...this.extraProps
1850
+ });
1851
+ }
1852
+ updateBranchSchema({
1853
+ workspace,
1854
+ region,
1855
+ database,
1856
+ branch,
1857
+ migration
1858
+ }) {
1859
+ return operationsByTag.migrations.updateBranchSchema({
1860
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1861
+ body: migration,
1205
1862
  ...this.extraProps
1206
1863
  });
1207
1864
  }
1208
- getBranchMigrationPlan(workspace, database, branch, schema) {
1209
- return operationsByTag.branchSchema.getBranchMigrationPlan({
1210
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1211
- body: schema,
1865
+ previewBranchSchemaEdit({
1866
+ workspace,
1867
+ region,
1868
+ database,
1869
+ branch,
1870
+ data
1871
+ }) {
1872
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1873
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1874
+ body: data,
1212
1875
  ...this.extraProps
1213
1876
  });
1214
1877
  }
1215
- compareBranchWithUserSchema(workspace, database, branch, schema) {
1216
- return operationsByTag.branchSchema.compareBranchWithUserSchema({
1217
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1218
- body: { schema },
1878
+ applyBranchSchemaEdit({
1879
+ workspace,
1880
+ region,
1881
+ database,
1882
+ branch,
1883
+ edits
1884
+ }) {
1885
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1886
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1887
+ body: { edits },
1219
1888
  ...this.extraProps
1220
1889
  });
1221
1890
  }
1222
- compareBranchSchemas(workspace, database, branch, branchName, schema) {
1223
- return operationsByTag.branchSchema.compareBranchSchemas({
1224
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1225
- body: { schema },
1891
+ }
1892
+ class DatabaseApi {
1893
+ constructor(extraProps) {
1894
+ this.extraProps = extraProps;
1895
+ }
1896
+ getDatabaseList({ workspace }) {
1897
+ return operationsByTag.databases.getDatabaseList({
1898
+ pathParams: { workspaceId: workspace },
1226
1899
  ...this.extraProps
1227
1900
  });
1228
1901
  }
1229
- updateBranchSchema(workspace, database, branch, migration) {
1230
- return operationsByTag.branchSchema.updateBranchSchema({
1231
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1232
- body: migration,
1902
+ createDatabase({
1903
+ workspace,
1904
+ database,
1905
+ data
1906
+ }) {
1907
+ return operationsByTag.databases.createDatabase({
1908
+ pathParams: { workspaceId: workspace, dbName: database },
1909
+ body: data,
1233
1910
  ...this.extraProps
1234
1911
  });
1235
1912
  }
1236
- previewBranchSchemaEdit(workspace, database, branch, migration) {
1237
- return operationsByTag.branchSchema.previewBranchSchemaEdit({
1238
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1239
- body: migration,
1913
+ deleteDatabase({
1914
+ workspace,
1915
+ database
1916
+ }) {
1917
+ return operationsByTag.databases.deleteDatabase({
1918
+ pathParams: { workspaceId: workspace, dbName: database },
1240
1919
  ...this.extraProps
1241
1920
  });
1242
1921
  }
1243
- applyBranchSchemaEdit(workspace, database, branch, edits) {
1244
- return operationsByTag.branchSchema.applyBranchSchemaEdit({
1245
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1246
- body: { edits },
1922
+ getDatabaseMetadata({
1923
+ workspace,
1924
+ database
1925
+ }) {
1926
+ return operationsByTag.databases.getDatabaseMetadata({
1927
+ pathParams: { workspaceId: workspace, dbName: database },
1247
1928
  ...this.extraProps
1248
1929
  });
1249
1930
  }
1250
- getBranchSchemaHistory(workspace, database, branch, options = {}) {
1251
- return operationsByTag.branchSchema.getBranchSchemaHistory({
1252
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1253
- body: options,
1931
+ updateDatabaseMetadata({
1932
+ workspace,
1933
+ database,
1934
+ metadata
1935
+ }) {
1936
+ return operationsByTag.databases.updateDatabaseMetadata({
1937
+ pathParams: { workspaceId: workspace, dbName: database },
1938
+ body: metadata,
1939
+ ...this.extraProps
1940
+ });
1941
+ }
1942
+ getDatabaseGithubSettings({
1943
+ workspace,
1944
+ database
1945
+ }) {
1946
+ return operationsByTag.databases.getDatabaseGithubSettings({
1947
+ pathParams: { workspaceId: workspace, dbName: database },
1948
+ ...this.extraProps
1949
+ });
1950
+ }
1951
+ updateDatabaseGithubSettings({
1952
+ workspace,
1953
+ database,
1954
+ settings
1955
+ }) {
1956
+ return operationsByTag.databases.updateDatabaseGithubSettings({
1957
+ pathParams: { workspaceId: workspace, dbName: database },
1958
+ body: settings,
1959
+ ...this.extraProps
1960
+ });
1961
+ }
1962
+ deleteDatabaseGithubSettings({
1963
+ workspace,
1964
+ database
1965
+ }) {
1966
+ return operationsByTag.databases.deleteDatabaseGithubSettings({
1967
+ pathParams: { workspaceId: workspace, dbName: database },
1968
+ ...this.extraProps
1969
+ });
1970
+ }
1971
+ listRegions({ workspace }) {
1972
+ return operationsByTag.databases.listRegions({
1973
+ pathParams: { workspaceId: workspace },
1254
1974
  ...this.extraProps
1255
1975
  });
1256
1976
  }
1257
1977
  }
1258
1978
 
1259
1979
  class XataApiPlugin {
1260
- async build(options) {
1261
- const { fetchImpl, apiKey } = await options.getFetchProps();
1262
- return new XataApiClient({ fetch: fetchImpl, apiKey });
1980
+ build(options) {
1981
+ return new XataApiClient(options);
1263
1982
  }
1264
1983
  }
1265
1984
 
1266
1985
  class XataPlugin {
1267
1986
  }
1268
1987
 
1988
+ function cleanFilter(filter) {
1989
+ if (!filter)
1990
+ return void 0;
1991
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1992
+ return values.length > 0 ? filter : void 0;
1993
+ }
1994
+
1269
1995
  var __accessCheck$6 = (obj, member, msg) => {
1270
1996
  if (!member.has(obj))
1271
1997
  throw TypeError("Cannot " + msg);
@@ -1298,11 +2024,11 @@ class Page {
1298
2024
  async previousPage(size, offset) {
1299
2025
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1300
2026
  }
1301
- async firstPage(size, offset) {
1302
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
2027
+ async startPage(size, offset) {
2028
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1303
2029
  }
1304
- async lastPage(size, offset) {
1305
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
2030
+ async endPage(size, offset) {
2031
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1306
2032
  }
1307
2033
  hasNextPage() {
1308
2034
  return this.meta.page.more;
@@ -1314,7 +2040,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1314
2040
  const PAGINATION_MAX_OFFSET = 800;
1315
2041
  const PAGINATION_DEFAULT_OFFSET = 0;
1316
2042
  function isCursorPaginationOptions(options) {
1317
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
2043
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1318
2044
  }
1319
2045
  const _RecordArray = class extends Array {
1320
2046
  constructor(...args) {
@@ -1335,6 +2061,12 @@ const _RecordArray = class extends Array {
1335
2061
  toArray() {
1336
2062
  return new Array(...this);
1337
2063
  }
2064
+ toSerializable() {
2065
+ return JSON.parse(this.toString());
2066
+ }
2067
+ toString() {
2068
+ return JSON.stringify(this.toArray());
2069
+ }
1338
2070
  map(callbackfn, thisArg) {
1339
2071
  return this.toArray().map(callbackfn, thisArg);
1340
2072
  }
@@ -1346,12 +2078,12 @@ const _RecordArray = class extends Array {
1346
2078
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1347
2079
  return new _RecordArray(newPage);
1348
2080
  }
1349
- async firstPage(size, offset) {
1350
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
2081
+ async startPage(size, offset) {
2082
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1351
2083
  return new _RecordArray(newPage);
1352
2084
  }
1353
- async lastPage(size, offset) {
1354
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
2085
+ async endPage(size, offset) {
2086
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1355
2087
  return new _RecordArray(newPage);
1356
2088
  }
1357
2089
  hasNextPage() {
@@ -1405,9 +2137,11 @@ const _Query = class {
1405
2137
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1406
2138
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1407
2139
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1408
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
2140
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2141
+ __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
1409
2142
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1410
2143
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2144
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1411
2145
  this.any = this.any.bind(this);
1412
2146
  this.all = this.all.bind(this);
1413
2147
  this.not = this.not.bind(this);
@@ -1521,19 +2255,29 @@ const _Query = class {
1521
2255
  throw new Error("No results found.");
1522
2256
  return records[0];
1523
2257
  }
2258
+ async summarize(params = {}) {
2259
+ const { summaries, summariesFilter, ...options } = params;
2260
+ const query = new _Query(
2261
+ __privateGet$5(this, _repository),
2262
+ __privateGet$5(this, _table$1),
2263
+ options,
2264
+ __privateGet$5(this, _data)
2265
+ );
2266
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2267
+ }
1524
2268
  cache(ttl) {
1525
2269
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1526
2270
  }
1527
2271
  nextPage(size, offset) {
1528
- return this.firstPage(size, offset);
2272
+ return this.startPage(size, offset);
1529
2273
  }
1530
2274
  previousPage(size, offset) {
1531
- return this.firstPage(size, offset);
2275
+ return this.startPage(size, offset);
1532
2276
  }
1533
- firstPage(size, offset) {
2277
+ startPage(size, offset) {
1534
2278
  return this.getPaginated({ pagination: { size, offset } });
1535
2279
  }
1536
- lastPage(size, offset) {
2280
+ endPage(size, offset) {
1537
2281
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1538
2282
  }
1539
2283
  hasNextPage() {
@@ -1557,7 +2301,7 @@ cleanFilterConstraint_fn = function(column, value) {
1557
2301
  };
1558
2302
  function cleanParent(data, parent) {
1559
2303
  if (isCursorPaginationOptions(data.pagination)) {
1560
- return { ...parent, sorting: void 0, filter: void 0 };
2304
+ return { ...parent, sort: void 0, filter: void 0 };
1561
2305
  }
1562
2306
  return parent;
1563
2307
  }
@@ -1616,7 +2360,8 @@ var __privateMethod$2 = (obj, member, method) => {
1616
2360
  __accessCheck$4(obj, member, "access private method");
1617
2361
  return method;
1618
2362
  };
1619
- 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;
2363
+ 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;
2364
+ const BULK_OPERATION_MAX_SIZE = 1e3;
1620
2365
  class Repository extends Query {
1621
2366
  }
1622
2367
  class RestRepository extends Query {
@@ -1628,10 +2373,12 @@ class RestRepository extends Query {
1628
2373
  );
1629
2374
  __privateAdd$4(this, _insertRecordWithoutId);
1630
2375
  __privateAdd$4(this, _insertRecordWithId);
1631
- __privateAdd$4(this, _bulkInsertTableRecords);
2376
+ __privateAdd$4(this, _insertRecords);
1632
2377
  __privateAdd$4(this, _updateRecordWithID);
2378
+ __privateAdd$4(this, _updateRecords);
1633
2379
  __privateAdd$4(this, _upsertRecordWithID);
1634
2380
  __privateAdd$4(this, _deleteRecord);
2381
+ __privateAdd$4(this, _deleteRecords);
1635
2382
  __privateAdd$4(this, _setCacheQuery);
1636
2383
  __privateAdd$4(this, _getCacheQuery);
1637
2384
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1642,10 +2389,10 @@ class RestRepository extends Query {
1642
2389
  __privateAdd$4(this, _schemaTables$2, void 0);
1643
2390
  __privateAdd$4(this, _trace, void 0);
1644
2391
  __privateSet$4(this, _table, options.table);
1645
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1646
2392
  __privateSet$4(this, _db, options.db);
1647
2393
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1648
2394
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2395
+ __privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
1649
2396
  const trace = options.pluginOptions.trace ?? defaultTrace;
1650
2397
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1651
2398
  return trace(name, fn, {
@@ -1656,25 +2403,28 @@ class RestRepository extends Query {
1656
2403
  });
1657
2404
  });
1658
2405
  }
1659
- async create(a, b, c) {
2406
+ async create(a, b, c, d) {
1660
2407
  return __privateGet$4(this, _trace).call(this, "create", async () => {
2408
+ const ifVersion = parseIfVersion(b, c, d);
1661
2409
  if (Array.isArray(a)) {
1662
2410
  if (a.length === 0)
1663
2411
  return [];
1664
- const columns = isStringArray(b) ? b : void 0;
1665
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2412
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2413
+ const columns = isStringArray(b) ? b : ["*"];
2414
+ const result = await this.read(ids, columns);
2415
+ return result;
1666
2416
  }
1667
2417
  if (isString(a) && isObject(b)) {
1668
2418
  if (a === "")
1669
2419
  throw new Error("The id can't be empty");
1670
2420
  const columns = isStringArray(c) ? c : void 0;
1671
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
2421
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
1672
2422
  }
1673
2423
  if (isObject(a) && isString(a.id)) {
1674
2424
  if (a.id === "")
1675
2425
  throw new Error("The id can't be empty");
1676
2426
  const columns = isStringArray(b) ? b : void 0;
1677
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2427
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
1678
2428
  }
1679
2429
  if (isObject(a)) {
1680
2430
  const columns = isStringArray(b) ? b : void 0;
@@ -1699,17 +2449,17 @@ class RestRepository extends Query {
1699
2449
  }
1700
2450
  const id = extractId(a);
1701
2451
  if (id) {
1702
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1703
2452
  try {
1704
2453
  const response = await getRecord({
1705
2454
  pathParams: {
1706
2455
  workspace: "{workspaceId}",
1707
2456
  dbBranchName: "{dbBranch}",
2457
+ region: "{region}",
1708
2458
  tableName: __privateGet$4(this, _table),
1709
2459
  recordId: id
1710
2460
  },
1711
2461
  queryParams: { columns },
1712
- ...fetchProps
2462
+ ...__privateGet$4(this, _getFetchProps).call(this)
1713
2463
  });
1714
2464
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1715
2465
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -1742,31 +2492,42 @@ class RestRepository extends Query {
1742
2492
  return result;
1743
2493
  });
1744
2494
  }
1745
- async update(a, b, c) {
2495
+ async update(a, b, c, d) {
1746
2496
  return __privateGet$4(this, _trace).call(this, "update", async () => {
2497
+ const ifVersion = parseIfVersion(b, c, d);
1747
2498
  if (Array.isArray(a)) {
1748
2499
  if (a.length === 0)
1749
2500
  return [];
1750
- if (a.length > 100) {
1751
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1752
- }
2501
+ const existing = await this.read(a, ["id"]);
2502
+ const updates = a.filter((_item, index) => existing[index] !== null);
2503
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2504
+ ifVersion,
2505
+ upsert: false
2506
+ });
1753
2507
  const columns = isStringArray(b) ? b : ["*"];
1754
- return Promise.all(a.map((object) => this.update(object, columns)));
1755
- }
1756
- if (isString(a) && isObject(b)) {
1757
- const columns = isStringArray(c) ? c : void 0;
1758
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
2508
+ const result = await this.read(a, columns);
2509
+ return result;
1759
2510
  }
1760
- if (isObject(a) && isString(a.id)) {
1761
- const columns = isStringArray(b) ? b : void 0;
1762
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2511
+ try {
2512
+ if (isString(a) && isObject(b)) {
2513
+ const columns = isStringArray(c) ? c : void 0;
2514
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2515
+ }
2516
+ if (isObject(a) && isString(a.id)) {
2517
+ const columns = isStringArray(b) ? b : void 0;
2518
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2519
+ }
2520
+ } catch (error) {
2521
+ if (error.status === 422)
2522
+ return null;
2523
+ throw error;
1763
2524
  }
1764
2525
  throw new Error("Invalid arguments for update method");
1765
2526
  });
1766
2527
  }
1767
- async updateOrThrow(a, b, c) {
2528
+ async updateOrThrow(a, b, c, d) {
1768
2529
  return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
1769
- const result = await this.update(a, b, c);
2530
+ const result = await this.update(a, b, c, d);
1770
2531
  if (Array.isArray(result)) {
1771
2532
  const missingIds = compact(
1772
2533
  a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
@@ -1783,37 +2544,69 @@ class RestRepository extends Query {
1783
2544
  return result;
1784
2545
  });
1785
2546
  }
1786
- async createOrUpdate(a, b, c) {
2547
+ async createOrUpdate(a, b, c, d) {
1787
2548
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2549
+ const ifVersion = parseIfVersion(b, c, d);
1788
2550
  if (Array.isArray(a)) {
1789
2551
  if (a.length === 0)
1790
2552
  return [];
1791
- if (a.length > 100) {
1792
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1793
- }
2553
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2554
+ ifVersion,
2555
+ upsert: true
2556
+ });
1794
2557
  const columns = isStringArray(b) ? b : ["*"];
1795
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
2558
+ const result = await this.read(a, columns);
2559
+ return result;
1796
2560
  }
1797
2561
  if (isString(a) && isObject(b)) {
1798
2562
  const columns = isStringArray(c) ? c : void 0;
1799
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
2563
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1800
2564
  }
1801
2565
  if (isObject(a) && isString(a.id)) {
1802
2566
  const columns = isStringArray(c) ? c : void 0;
1803
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2567
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1804
2568
  }
1805
2569
  throw new Error("Invalid arguments for createOrUpdate method");
1806
2570
  });
1807
2571
  }
2572
+ async createOrReplace(a, b, c, d) {
2573
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2574
+ const ifVersion = parseIfVersion(b, c, d);
2575
+ if (Array.isArray(a)) {
2576
+ if (a.length === 0)
2577
+ return [];
2578
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2579
+ const columns = isStringArray(b) ? b : ["*"];
2580
+ const result = await this.read(ids, columns);
2581
+ return result;
2582
+ }
2583
+ if (isString(a) && isObject(b)) {
2584
+ const columns = isStringArray(c) ? c : void 0;
2585
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2586
+ }
2587
+ if (isObject(a) && isString(a.id)) {
2588
+ const columns = isStringArray(c) ? c : void 0;
2589
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2590
+ }
2591
+ throw new Error("Invalid arguments for createOrReplace method");
2592
+ });
2593
+ }
1808
2594
  async delete(a, b) {
1809
2595
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1810
2596
  if (Array.isArray(a)) {
1811
2597
  if (a.length === 0)
1812
2598
  return [];
1813
- if (a.length > 100) {
1814
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1815
- }
1816
- return Promise.all(a.map((id) => this.delete(id, b)));
2599
+ const ids = a.map((o) => {
2600
+ if (isString(o))
2601
+ return o;
2602
+ if (isString(o.id))
2603
+ return o.id;
2604
+ throw new Error("Invalid arguments for delete method");
2605
+ });
2606
+ const columns = isStringArray(b) ? b : ["*"];
2607
+ const result = await this.read(a, columns);
2608
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2609
+ return result;
1817
2610
  }
1818
2611
  if (isString(a)) {
1819
2612
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
@@ -1844,40 +2637,88 @@ class RestRepository extends Query {
1844
2637
  }
1845
2638
  async search(query, options = {}) {
1846
2639
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1847
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1848
2640
  const { records } = await searchTable({
1849
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2641
+ pathParams: {
2642
+ workspace: "{workspaceId}",
2643
+ dbBranchName: "{dbBranch}",
2644
+ region: "{region}",
2645
+ tableName: __privateGet$4(this, _table)
2646
+ },
1850
2647
  body: {
1851
2648
  query,
1852
2649
  fuzziness: options.fuzziness,
1853
2650
  prefix: options.prefix,
1854
2651
  highlight: options.highlight,
1855
2652
  filter: options.filter,
1856
- boosters: options.boosters
2653
+ boosters: options.boosters,
2654
+ page: options.page,
2655
+ target: options.target
2656
+ },
2657
+ ...__privateGet$4(this, _getFetchProps).call(this)
2658
+ });
2659
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2660
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2661
+ });
2662
+ }
2663
+ async vectorSearch(column, query, options) {
2664
+ return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
2665
+ const { records } = await vectorSearchTable({
2666
+ pathParams: {
2667
+ workspace: "{workspaceId}",
2668
+ dbBranchName: "{dbBranch}",
2669
+ region: "{region}",
2670
+ tableName: __privateGet$4(this, _table)
2671
+ },
2672
+ body: {
2673
+ column,
2674
+ queryVector: query,
2675
+ similarityFunction: options?.similarityFunction,
2676
+ size: options?.size,
2677
+ filter: options?.filter
1857
2678
  },
1858
- ...fetchProps
2679
+ ...__privateGet$4(this, _getFetchProps).call(this)
1859
2680
  });
1860
2681
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1861
2682
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1862
2683
  });
1863
2684
  }
2685
+ async aggregate(aggs, filter) {
2686
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2687
+ const result = await aggregateTable({
2688
+ pathParams: {
2689
+ workspace: "{workspaceId}",
2690
+ dbBranchName: "{dbBranch}",
2691
+ region: "{region}",
2692
+ tableName: __privateGet$4(this, _table)
2693
+ },
2694
+ body: { aggs, filter },
2695
+ ...__privateGet$4(this, _getFetchProps).call(this)
2696
+ });
2697
+ return result;
2698
+ });
2699
+ }
1864
2700
  async query(query) {
1865
2701
  return __privateGet$4(this, _trace).call(this, "query", async () => {
1866
2702
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1867
2703
  if (cacheQuery)
1868
2704
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1869
2705
  const data = query.getQueryOptions();
1870
- const body = {
1871
- filter: cleanFilter(data.filter),
1872
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1873
- page: data.pagination,
1874
- columns: data.columns
1875
- };
1876
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1877
2706
  const { meta, records: objects } = await queryTable({
1878
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1879
- body,
1880
- ...fetchProps
2707
+ pathParams: {
2708
+ workspace: "{workspaceId}",
2709
+ dbBranchName: "{dbBranch}",
2710
+ region: "{region}",
2711
+ tableName: __privateGet$4(this, _table)
2712
+ },
2713
+ body: {
2714
+ filter: cleanFilter(data.filter),
2715
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2716
+ page: data.pagination,
2717
+ columns: data.columns ?? ["*"],
2718
+ consistency: data.consistency
2719
+ },
2720
+ fetchOptions: data.fetchOptions,
2721
+ ...__privateGet$4(this, _getFetchProps).call(this)
1881
2722
  });
1882
2723
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1883
2724
  const records = objects.map(
@@ -1887,6 +2728,30 @@ class RestRepository extends Query {
1887
2728
  return new Page(query, meta, records);
1888
2729
  });
1889
2730
  }
2731
+ async summarizeTable(query, summaries, summariesFilter) {
2732
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2733
+ const data = query.getQueryOptions();
2734
+ const result = await summarizeTable({
2735
+ pathParams: {
2736
+ workspace: "{workspaceId}",
2737
+ dbBranchName: "{dbBranch}",
2738
+ region: "{region}",
2739
+ tableName: __privateGet$4(this, _table)
2740
+ },
2741
+ body: {
2742
+ filter: cleanFilter(data.filter),
2743
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2744
+ columns: data.columns,
2745
+ consistency: data.consistency,
2746
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2747
+ summaries,
2748
+ summariesFilter
2749
+ },
2750
+ ...__privateGet$4(this, _getFetchProps).call(this)
2751
+ });
2752
+ return result;
2753
+ });
2754
+ }
1890
2755
  }
1891
2756
  _table = new WeakMap();
1892
2757
  _getFetchProps = new WeakMap();
@@ -1896,65 +2761,83 @@ _schemaTables$2 = new WeakMap();
1896
2761
  _trace = new WeakMap();
1897
2762
  _insertRecordWithoutId = new WeakSet();
1898
2763
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1899
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1900
2764
  const record = transformObjectLinks(object);
1901
2765
  const response = await insertRecord({
1902
2766
  pathParams: {
1903
2767
  workspace: "{workspaceId}",
1904
2768
  dbBranchName: "{dbBranch}",
2769
+ region: "{region}",
1905
2770
  tableName: __privateGet$4(this, _table)
1906
2771
  },
1907
2772
  queryParams: { columns },
1908
2773
  body: record,
1909
- ...fetchProps
2774
+ ...__privateGet$4(this, _getFetchProps).call(this)
1910
2775
  });
1911
2776
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1912
2777
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1913
2778
  };
1914
2779
  _insertRecordWithId = new WeakSet();
1915
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1916
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2780
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
1917
2781
  const record = transformObjectLinks(object);
1918
2782
  const response = await insertRecordWithID({
1919
2783
  pathParams: {
1920
2784
  workspace: "{workspaceId}",
1921
2785
  dbBranchName: "{dbBranch}",
2786
+ region: "{region}",
1922
2787
  tableName: __privateGet$4(this, _table),
1923
2788
  recordId
1924
2789
  },
1925
2790
  body: record,
1926
- queryParams: { createOnly: true, columns },
1927
- ...fetchProps
2791
+ queryParams: { createOnly, columns, ifVersion },
2792
+ ...__privateGet$4(this, _getFetchProps).call(this)
1928
2793
  });
1929
2794
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1930
2795
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1931
2796
  };
1932
- _bulkInsertTableRecords = new WeakSet();
1933
- bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1934
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1935
- const records = objects.map((object) => transformObjectLinks(object));
1936
- const response = await bulkInsertTableRecords({
1937
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1938
- queryParams: { columns },
1939
- body: { records },
1940
- ...fetchProps
1941
- });
1942
- if (!isResponseWithRecords(response)) {
1943
- throw new Error("Request included columns but server didn't include them");
2797
+ _insertRecords = new WeakSet();
2798
+ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2799
+ const chunkedOperations = chunk(
2800
+ objects.map((object) => ({
2801
+ insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2802
+ })),
2803
+ BULK_OPERATION_MAX_SIZE
2804
+ );
2805
+ const ids = [];
2806
+ for (const operations of chunkedOperations) {
2807
+ const { results } = await branchTransaction({
2808
+ pathParams: {
2809
+ workspace: "{workspaceId}",
2810
+ dbBranchName: "{dbBranch}",
2811
+ region: "{region}"
2812
+ },
2813
+ body: { operations },
2814
+ ...__privateGet$4(this, _getFetchProps).call(this)
2815
+ });
2816
+ for (const result of results) {
2817
+ if (result.operation === "insert") {
2818
+ ids.push(result.id);
2819
+ } else {
2820
+ ids.push(null);
2821
+ }
2822
+ }
1944
2823
  }
1945
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1946
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
2824
+ return ids;
1947
2825
  };
1948
2826
  _updateRecordWithID = new WeakSet();
1949
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1950
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1951
- const record = transformObjectLinks(object);
2827
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2828
+ const { id: _id, ...record } = transformObjectLinks(object);
1952
2829
  try {
1953
2830
  const response = await updateRecordWithID({
1954
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1955
- queryParams: { columns },
2831
+ pathParams: {
2832
+ workspace: "{workspaceId}",
2833
+ dbBranchName: "{dbBranch}",
2834
+ region: "{region}",
2835
+ tableName: __privateGet$4(this, _table),
2836
+ recordId
2837
+ },
2838
+ queryParams: { columns, ifVersion },
1956
2839
  body: record,
1957
- ...fetchProps
2840
+ ...__privateGet$4(this, _getFetchProps).call(this)
1958
2841
  });
1959
2842
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1960
2843
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -1965,26 +2848,65 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1965
2848
  throw e;
1966
2849
  }
1967
2850
  };
2851
+ _updateRecords = new WeakSet();
2852
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2853
+ const chunkedOperations = chunk(
2854
+ objects.map(({ id, ...object }) => ({
2855
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2856
+ })),
2857
+ BULK_OPERATION_MAX_SIZE
2858
+ );
2859
+ const ids = [];
2860
+ for (const operations of chunkedOperations) {
2861
+ const { results } = await branchTransaction({
2862
+ pathParams: {
2863
+ workspace: "{workspaceId}",
2864
+ dbBranchName: "{dbBranch}",
2865
+ region: "{region}"
2866
+ },
2867
+ body: { operations },
2868
+ ...__privateGet$4(this, _getFetchProps).call(this)
2869
+ });
2870
+ for (const result of results) {
2871
+ if (result.operation === "update") {
2872
+ ids.push(result.id);
2873
+ } else {
2874
+ ids.push(null);
2875
+ }
2876
+ }
2877
+ }
2878
+ return ids;
2879
+ };
1968
2880
  _upsertRecordWithID = new WeakSet();
1969
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1970
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2881
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1971
2882
  const response = await upsertRecordWithID({
1972
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1973
- queryParams: { columns },
2883
+ pathParams: {
2884
+ workspace: "{workspaceId}",
2885
+ dbBranchName: "{dbBranch}",
2886
+ region: "{region}",
2887
+ tableName: __privateGet$4(this, _table),
2888
+ recordId
2889
+ },
2890
+ queryParams: { columns, ifVersion },
1974
2891
  body: object,
1975
- ...fetchProps
2892
+ ...__privateGet$4(this, _getFetchProps).call(this)
1976
2893
  });
1977
2894
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1978
2895
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1979
2896
  };
1980
2897
  _deleteRecord = new WeakSet();
1981
2898
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
1982
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1983
2899
  try {
1984
2900
  const response = await deleteRecord({
1985
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2901
+ pathParams: {
2902
+ workspace: "{workspaceId}",
2903
+ dbBranchName: "{dbBranch}",
2904
+ region: "{region}",
2905
+ tableName: __privateGet$4(this, _table),
2906
+ recordId
2907
+ },
1986
2908
  queryParams: { columns },
1987
- ...fetchProps
2909
+ ...__privateGet$4(this, _getFetchProps).call(this)
1988
2910
  });
1989
2911
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1990
2912
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
@@ -1995,6 +2917,24 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1995
2917
  throw e;
1996
2918
  }
1997
2919
  };
2920
+ _deleteRecords = new WeakSet();
2921
+ deleteRecords_fn = async function(recordIds) {
2922
+ const chunkedOperations = chunk(
2923
+ recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2924
+ BULK_OPERATION_MAX_SIZE
2925
+ );
2926
+ for (const operations of chunkedOperations) {
2927
+ await branchTransaction({
2928
+ pathParams: {
2929
+ workspace: "{workspaceId}",
2930
+ dbBranchName: "{dbBranch}",
2931
+ region: "{region}"
2932
+ },
2933
+ body: { operations },
2934
+ ...__privateGet$4(this, _getFetchProps).call(this)
2935
+ });
2936
+ }
2937
+ };
1998
2938
  _setCacheQuery = new WeakSet();
1999
2939
  setCacheQuery_fn = async function(query, meta, records) {
2000
2940
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -2015,10 +2955,9 @@ _getSchemaTables$1 = new WeakSet();
2015
2955
  getSchemaTables_fn$1 = async function() {
2016
2956
  if (__privateGet$4(this, _schemaTables$2))
2017
2957
  return __privateGet$4(this, _schemaTables$2);
2018
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2019
2958
  const { schema } = await getBranchDetails({
2020
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2021
- ...fetchProps
2959
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2960
+ ...__privateGet$4(this, _getFetchProps).call(this)
2022
2961
  });
2023
2962
  __privateSet$4(this, _schemaTables$2, schema.tables);
2024
2963
  return schema.tables;
@@ -2031,23 +2970,23 @@ const transformObjectLinks = (object) => {
2031
2970
  }, {});
2032
2971
  };
2033
2972
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2034
- const result = {};
2973
+ const data = {};
2035
2974
  const { xata, ...rest } = object ?? {};
2036
- Object.assign(result, rest);
2975
+ Object.assign(data, rest);
2037
2976
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2038
2977
  if (!columns)
2039
2978
  console.error(`Table ${table} not found in schema`);
2040
2979
  for (const column of columns ?? []) {
2041
2980
  if (!isValidColumn(selectedColumns, column))
2042
2981
  continue;
2043
- const value = result[column.name];
2982
+ const value = data[column.name];
2044
2983
  switch (column.type) {
2045
2984
  case "datetime": {
2046
- const date = value !== void 0 ? new Date(value) : void 0;
2047
- if (date && isNaN(date.getTime())) {
2985
+ const date = value !== void 0 ? new Date(value) : null;
2986
+ if (date !== null && isNaN(date.getTime())) {
2048
2987
  console.error(`Failed to parse date ${value} for field ${column.name}`);
2049
- } else if (date) {
2050
- result[column.name] = date;
2988
+ } else {
2989
+ data[column.name] = date;
2051
2990
  }
2052
2991
  break;
2053
2992
  }
@@ -2066,41 +3005,52 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2066
3005
  }
2067
3006
  return acc;
2068
3007
  }, []);
2069
- result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
3008
+ data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2070
3009
  } else {
2071
- result[column.name] = null;
3010
+ data[column.name] = null;
2072
3011
  }
2073
3012
  break;
2074
3013
  }
2075
3014
  default:
2076
- result[column.name] = value ?? null;
3015
+ data[column.name] = value ?? null;
2077
3016
  if (column.notNull === true && value === null) {
2078
3017
  console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2079
3018
  }
2080
3019
  break;
2081
3020
  }
2082
3021
  }
2083
- result.read = function(columns2) {
2084
- return db[table].read(result["id"], columns2);
3022
+ const record = { ...data };
3023
+ record.read = function(columns2) {
3024
+ return db[table].read(record["id"], columns2);
2085
3025
  };
2086
- result.update = function(data, columns2) {
2087
- return db[table].update(result["id"], data, columns2);
3026
+ record.update = function(data2, b, c) {
3027
+ const columns2 = isStringArray(b) ? b : ["*"];
3028
+ const ifVersion = parseIfVersion(b, c);
3029
+ return db[table].update(record["id"], data2, columns2, { ifVersion });
2088
3030
  };
2089
- result.delete = function() {
2090
- return db[table].delete(result["id"]);
3031
+ record.replace = function(data2, b, c) {
3032
+ const columns2 = isStringArray(b) ? b : ["*"];
3033
+ const ifVersion = parseIfVersion(b, c);
3034
+ return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2091
3035
  };
2092
- result.getMetadata = function() {
3036
+ record.delete = function() {
3037
+ return db[table].delete(record["id"]);
3038
+ };
3039
+ record.getMetadata = function() {
2093
3040
  return xata;
2094
3041
  };
2095
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
2096
- Object.defineProperty(result, prop, { enumerable: false });
3042
+ record.toSerializable = function() {
3043
+ return JSON.parse(JSON.stringify(transformObjectLinks(data)));
3044
+ };
3045
+ record.toString = function() {
3046
+ return JSON.stringify(transformObjectLinks(data));
3047
+ };
3048
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3049
+ Object.defineProperty(record, prop, { enumerable: false });
2097
3050
  }
2098
- Object.freeze(result);
2099
- return result;
3051
+ Object.freeze(record);
3052
+ return record;
2100
3053
  };
2101
- function isResponseWithRecords(value) {
2102
- return isObject(value) && Array.isArray(value.records);
2103
- }
2104
3054
  function extractId(value) {
2105
3055
  if (isString(value))
2106
3056
  return value;
@@ -2108,12 +3058,6 @@ function extractId(value) {
2108
3058
  return value.id;
2109
3059
  return void 0;
2110
3060
  }
2111
- function cleanFilter(filter) {
2112
- if (!filter)
2113
- return void 0;
2114
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2115
- return values.length > 0 ? filter : void 0;
2116
- }
2117
3061
  function isValidColumn(columns, column) {
2118
3062
  if (columns.includes("*"))
2119
3063
  return true;
@@ -2123,6 +3067,14 @@ function isValidColumn(columns, column) {
2123
3067
  }
2124
3068
  return columns.includes(column.name);
2125
3069
  }
3070
+ function parseIfVersion(...args) {
3071
+ for (const arg of args) {
3072
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
3073
+ return arg.ifVersion;
3074
+ }
3075
+ }
3076
+ return void 0;
3077
+ }
2126
3078
 
2127
3079
  var __accessCheck$3 = (obj, member, msg) => {
2128
3080
  if (!member.has(obj))
@@ -2281,19 +3233,19 @@ class SearchPlugin extends XataPlugin {
2281
3233
  __privateAdd$1(this, _schemaTables, void 0);
2282
3234
  __privateSet$1(this, _schemaTables, schemaTables);
2283
3235
  }
2284
- build({ getFetchProps }) {
3236
+ build(pluginOptions) {
2285
3237
  return {
2286
3238
  all: async (query, options = {}) => {
2287
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2288
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3239
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3240
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
2289
3241
  return records.map((record) => {
2290
3242
  const { table = "orphan" } = record.xata;
2291
3243
  return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
2292
3244
  });
2293
3245
  },
2294
3246
  byTable: async (query, options = {}) => {
2295
- const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2296
- const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
3247
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3248
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
2297
3249
  return records.reduce((acc, record) => {
2298
3250
  const { table = "orphan" } = record.xata;
2299
3251
  const items = acc[table] ?? [];
@@ -2306,108 +3258,39 @@ class SearchPlugin extends XataPlugin {
2306
3258
  }
2307
3259
  _schemaTables = new WeakMap();
2308
3260
  _search = new WeakSet();
2309
- search_fn = async function(query, options, getFetchProps) {
2310
- const fetchProps = await getFetchProps();
2311
- const { tables, fuzziness, highlight, prefix } = options ?? {};
3261
+ search_fn = async function(query, options, pluginOptions) {
3262
+ const { tables, fuzziness, highlight, prefix, page } = options ?? {};
2312
3263
  const { records } = await searchBranch({
2313
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2314
- body: { tables, query, fuzziness, prefix, highlight },
2315
- ...fetchProps
3264
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3265
+ body: { tables, query, fuzziness, prefix, highlight, page },
3266
+ ...pluginOptions
2316
3267
  });
2317
3268
  return records;
2318
3269
  };
2319
3270
  _getSchemaTables = new WeakSet();
2320
- getSchemaTables_fn = async function(getFetchProps) {
3271
+ getSchemaTables_fn = async function(pluginOptions) {
2321
3272
  if (__privateGet$1(this, _schemaTables))
2322
3273
  return __privateGet$1(this, _schemaTables);
2323
- const fetchProps = await getFetchProps();
2324
3274
  const { schema } = await getBranchDetails({
2325
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2326
- ...fetchProps
3275
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3276
+ ...pluginOptions
2327
3277
  });
2328
3278
  __privateSet$1(this, _schemaTables, schema.tables);
2329
3279
  return schema.tables;
2330
3280
  };
2331
3281
 
2332
- const isBranchStrategyBuilder = (strategy) => {
2333
- return typeof strategy === "function";
2334
- };
2335
-
2336
- async function getCurrentBranchName(options) {
2337
- const { branch, envBranch } = getEnvironment();
2338
- if (branch) {
2339
- const details = await getDatabaseBranch(branch, options);
2340
- if (details)
2341
- return branch;
2342
- console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
2343
- }
2344
- const gitBranch = envBranch || await getGitBranch();
2345
- return resolveXataBranch(gitBranch, options);
2346
- }
2347
- async function getCurrentBranchDetails(options) {
2348
- const branch = await getCurrentBranchName(options);
2349
- return getDatabaseBranch(branch, options);
2350
- }
2351
- async function resolveXataBranch(gitBranch, options) {
2352
- const databaseURL = options?.databaseURL || getDatabaseURL();
2353
- const apiKey = options?.apiKey || getAPIKey();
2354
- if (!databaseURL)
2355
- throw new Error(
2356
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2357
- );
2358
- if (!apiKey)
2359
- throw new Error(
2360
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2361
- );
2362
- const [protocol, , host, , dbName] = databaseURL.split("/");
2363
- const [workspace] = host.split(".");
2364
- const { fallbackBranch } = getEnvironment();
2365
- const { branch } = await resolveBranch({
2366
- apiKey,
2367
- apiUrl: databaseURL,
2368
- fetchImpl: getFetchImplementation(options?.fetchImpl),
2369
- workspacesApiUrl: `${protocol}//${host}`,
2370
- pathParams: { dbName, workspace },
2371
- queryParams: { gitBranch, fallbackBranch },
2372
- trace: defaultTrace
2373
- });
2374
- return branch;
2375
- }
2376
- async function getDatabaseBranch(branch, options) {
2377
- const databaseURL = options?.databaseURL || getDatabaseURL();
2378
- const apiKey = options?.apiKey || getAPIKey();
2379
- if (!databaseURL)
2380
- throw new Error(
2381
- "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2382
- );
2383
- if (!apiKey)
2384
- throw new Error(
2385
- "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2386
- );
2387
- const [protocol, , host, , database] = databaseURL.split("/");
2388
- const [workspace] = host.split(".");
2389
- const dbBranchName = `${database}:${branch}`;
2390
- try {
2391
- return await getBranchDetails({
2392
- apiKey,
2393
- apiUrl: databaseURL,
2394
- fetchImpl: getFetchImplementation(options?.fetchImpl),
2395
- workspacesApiUrl: `${protocol}//${host}`,
2396
- pathParams: { dbBranchName, workspace },
2397
- trace: defaultTrace
2398
- });
2399
- } catch (err) {
2400
- if (isObject(err) && err.status === 404)
2401
- return null;
2402
- throw err;
2403
- }
2404
- }
2405
- function getDatabaseURL() {
2406
- try {
2407
- const { databaseURL } = getEnvironment();
2408
- return databaseURL;
2409
- } catch (err) {
2410
- return void 0;
3282
+ class TransactionPlugin extends XataPlugin {
3283
+ build(pluginOptions) {
3284
+ return {
3285
+ run: async (operations) => {
3286
+ const response = await branchTransaction({
3287
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3288
+ body: { operations },
3289
+ ...pluginOptions
3290
+ });
3291
+ return response;
3292
+ }
3293
+ };
2411
3294
  }
2412
3295
  }
2413
3296
 
@@ -2434,25 +3317,24 @@ var __privateMethod = (obj, member, method) => {
2434
3317
  return method;
2435
3318
  };
2436
3319
  const buildClient = (plugins) => {
2437
- var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3320
+ var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
2438
3321
  return _a = class {
2439
3322
  constructor(options = {}, schemaTables) {
2440
3323
  __privateAdd(this, _parseOptions);
2441
3324
  __privateAdd(this, _getFetchProps);
2442
- __privateAdd(this, _evaluateBranch);
2443
- __privateAdd(this, _branch, void 0);
2444
3325
  __privateAdd(this, _options, void 0);
2445
3326
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
2446
3327
  __privateSet(this, _options, safeOptions);
2447
3328
  const pluginOptions = {
2448
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2449
- cache: safeOptions.cache,
2450
- trace: safeOptions.trace
3329
+ ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3330
+ cache: safeOptions.cache
2451
3331
  };
2452
3332
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2453
3333
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3334
+ const transactions = new TransactionPlugin().build(pluginOptions);
2454
3335
  this.db = db;
2455
3336
  this.search = search;
3337
+ this.transactions = transactions;
2456
3338
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
2457
3339
  if (namespace === void 0)
2458
3340
  continue;
@@ -2468,54 +3350,69 @@ const buildClient = (plugins) => {
2468
3350
  }
2469
3351
  async getConfig() {
2470
3352
  const databaseURL = __privateGet(this, _options).databaseURL;
2471
- const branch = await __privateGet(this, _options).branch();
3353
+ const branch = __privateGet(this, _options).branch;
2472
3354
  return { databaseURL, branch };
2473
3355
  }
2474
- }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3356
+ }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3357
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3358
+ const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3359
+ if (isBrowser && !enableBrowser) {
3360
+ throw new Error(
3361
+ "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."
3362
+ );
3363
+ }
2475
3364
  const fetch = getFetchImplementation(options?.fetch);
2476
3365
  const databaseURL = options?.databaseURL || getDatabaseURL();
3366
+ const branch = options?.branch || getBranch() || "main";
2477
3367
  const apiKey = options?.apiKey || getAPIKey();
2478
3368
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2479
3369
  const trace = options?.trace ?? defaultTrace;
2480
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
3370
+ const clientName = options?.clientName;
3371
+ const host = options?.host ?? "production";
3372
+ const xataAgentExtra = options?.xataAgentExtra;
2481
3373
  if (!apiKey) {
2482
3374
  throw new Error("Option apiKey is required");
2483
3375
  }
2484
3376
  if (!databaseURL) {
2485
3377
  throw new Error("Option databaseURL is required");
2486
3378
  }
2487
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2488
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2489
- const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2490
- if (!branchValue)
2491
- throw new Error("Unable to resolve branch value");
2492
3379
  return {
2493
- fetchImpl: fetch,
3380
+ fetch,
3381
+ databaseURL,
3382
+ apiKey,
3383
+ branch,
3384
+ cache,
3385
+ trace,
3386
+ host,
3387
+ clientID: generateUUID(),
3388
+ enableBrowser,
3389
+ clientName,
3390
+ xataAgentExtra
3391
+ };
3392
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
3393
+ fetch,
3394
+ apiKey,
3395
+ databaseURL,
3396
+ branch,
3397
+ trace,
3398
+ clientID,
3399
+ clientName,
3400
+ xataAgentExtra
3401
+ }) {
3402
+ return {
3403
+ fetch,
2494
3404
  apiKey,
2495
3405
  apiUrl: "",
2496
3406
  workspacesApiUrl: (path, params) => {
2497
3407
  const hasBranch = params.dbBranchName ?? params.branch;
2498
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
3408
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
2499
3409
  return databaseURL + newPath;
2500
3410
  },
2501
- trace
2502
- };
2503
- }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2504
- if (__privateGet(this, _branch))
2505
- return __privateGet(this, _branch);
2506
- if (param === void 0)
2507
- return void 0;
2508
- const strategies = Array.isArray(param) ? [...param] : [param];
2509
- const evaluateBranch = async (strategy) => {
2510
- return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
3411
+ trace,
3412
+ clientID,
3413
+ clientName,
3414
+ xataAgentExtra
2511
3415
  };
2512
- for await (const strategy of strategies) {
2513
- const branch = await evaluateBranch(strategy);
2514
- if (branch) {
2515
- __privateSet(this, _branch, branch);
2516
- return branch;
2517
- }
2518
- }
2519
3416
  }, _a;
2520
3417
  };
2521
3418
  class BaseClient extends buildClient() {
@@ -2589,7 +3486,7 @@ const deserialize = (json) => {
2589
3486
  };
2590
3487
 
2591
3488
  function buildWorkerRunner(config) {
2592
- return function xataWorker(name, _worker) {
3489
+ return function xataWorker(name, worker) {
2593
3490
  return async (...args) => {
2594
3491
  const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2595
3492
  const result = await fetch(url, {
@@ -2611,6 +3508,7 @@ class XataError extends Error {
2611
3508
  }
2612
3509
 
2613
3510
  exports.BaseClient = BaseClient;
3511
+ exports.FetcherError = FetcherError;
2614
3512
  exports.Operations = operationsByTag;
2615
3513
  exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
2616
3514
  exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
@@ -2632,7 +3530,10 @@ exports.XataPlugin = XataPlugin;
2632
3530
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2633
3531
  exports.addGitBranchesEntry = addGitBranchesEntry;
2634
3532
  exports.addTableColumn = addTableColumn;
3533
+ exports.aggregateTable = aggregateTable;
2635
3534
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3535
+ exports.askTable = askTable;
3536
+ exports.branchTransaction = branchTransaction;
2636
3537
  exports.buildClient = buildClient;
2637
3538
  exports.buildWorkerRunner = buildWorkerRunner;
2638
3539
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
@@ -2650,6 +3551,7 @@ exports.createWorkspace = createWorkspace;
2650
3551
  exports.deleteBranch = deleteBranch;
2651
3552
  exports.deleteColumn = deleteColumn;
2652
3553
  exports.deleteDatabase = deleteDatabase;
3554
+ exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
2653
3555
  exports.deleteRecord = deleteRecord;
2654
3556
  exports.deleteTable = deleteTable;
2655
3557
  exports.deleteUser = deleteUser;
@@ -2662,6 +3564,7 @@ exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2662
3564
  exports.exists = exists;
2663
3565
  exports.ge = ge;
2664
3566
  exports.getAPIKey = getAPIKey;
3567
+ exports.getBranch = getBranch;
2665
3568
  exports.getBranchDetails = getBranchDetails;
2666
3569
  exports.getBranchList = getBranchList;
2667
3570
  exports.getBranchMetadata = getBranchMetadata;
@@ -2670,12 +3573,12 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
2670
3573
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
2671
3574
  exports.getBranchStats = getBranchStats;
2672
3575
  exports.getColumn = getColumn;
2673
- exports.getCurrentBranchDetails = getCurrentBranchDetails;
2674
- exports.getCurrentBranchName = getCurrentBranchName;
3576
+ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
2675
3577
  exports.getDatabaseList = getDatabaseList;
2676
3578
  exports.getDatabaseMetadata = getDatabaseMetadata;
2677
3579
  exports.getDatabaseURL = getDatabaseURL;
2678
3580
  exports.getGitBranchesMapping = getGitBranchesMapping;
3581
+ exports.getHostUrl = getHostUrl;
2679
3582
  exports.getMigrationRequest = getMigrationRequest;
2680
3583
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2681
3584
  exports.getRecord = getRecord;
@@ -2700,6 +3603,8 @@ exports.insertRecordWithID = insertRecordWithID;
2700
3603
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2701
3604
  exports.is = is;
2702
3605
  exports.isCursorPaginationOptions = isCursorPaginationOptions;
3606
+ exports.isHostProviderAlias = isHostProviderAlias;
3607
+ exports.isHostProviderBuilder = isHostProviderBuilder;
2703
3608
  exports.isIdentifiable = isIdentifiable;
2704
3609
  exports.isNot = isNot;
2705
3610
  exports.isXataRecord = isXataRecord;
@@ -2707,15 +3612,18 @@ exports.le = le;
2707
3612
  exports.lessEquals = lessEquals;
2708
3613
  exports.lessThan = lessThan;
2709
3614
  exports.lessThanEquals = lessThanEquals;
2710
- exports.listMigrationRequests = listMigrationRequests;
2711
3615
  exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3616
+ exports.listRegions = listRegions;
2712
3617
  exports.lt = lt;
2713
3618
  exports.lte = lte;
2714
3619
  exports.mergeMigrationRequest = mergeMigrationRequest;
2715
3620
  exports.notExists = notExists;
2716
3621
  exports.operationsByTag = operationsByTag;
3622
+ exports.parseProviderString = parseProviderString;
3623
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
2717
3624
  exports.pattern = pattern;
2718
3625
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3626
+ exports.queryMigrationRequests = queryMigrationRequests;
2719
3627
  exports.queryTable = queryTable;
2720
3628
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2721
3629
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2730,6 +3638,7 @@ exports.summarizeTable = summarizeTable;
2730
3638
  exports.updateBranchMetadata = updateBranchMetadata;
2731
3639
  exports.updateBranchSchema = updateBranchSchema;
2732
3640
  exports.updateColumn = updateColumn;
3641
+ exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
2733
3642
  exports.updateDatabaseMetadata = updateDatabaseMetadata;
2734
3643
  exports.updateMigrationRequest = updateMigrationRequest;
2735
3644
  exports.updateRecordWithID = updateRecordWithID;
@@ -2739,4 +3648,5 @@ exports.updateWorkspace = updateWorkspace;
2739
3648
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
2740
3649
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
2741
3650
  exports.upsertRecordWithID = upsertRecordWithID;
3651
+ exports.vectorSearchTable = vectorSearchTable;
2742
3652
  //# sourceMappingURL=index.cjs.map