@xata.io/client 0.0.0-alpha.vf79e7d8 → 0.0.0-alpha.vf7b8bd4

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