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

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