@xata.io/client 0.0.0-alpha.vf87d751 → 0.0.0-alpha.vf88f0fd

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