@xata.io/client 0.0.0-alpha.vf481c73 → 0.0.0-alpha.vf4e6746

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