@xata.io/client 0.0.0-alpha.vf9f8ac6 → 0.0.0-alpha.vfa22996

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