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

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