@xata.io/client 0.0.0-alpha.vf73045e → 0.0.0-alpha.vf7400f4

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