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

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