@xata.io/client 0.0.0-alpha.vfbbe3c7 → 0.0.0-alpha.vfbde008

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