@xata.io/client 0.0.0-alpha.vfc692f9 → 0.0.0-alpha.vfca6c5f

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