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

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,26 @@
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
+ setAttributes: () => {
6
+ return;
7
+ }
8
+ });
9
+ };
10
+ const TraceAttributes = {
11
+ KIND: "xata.trace.kind",
12
+ VERSION: "xata.sdk.version",
13
+ TABLE: "xata.table",
14
+ HTTP_REQUEST_ID: "http.request_id",
15
+ HTTP_STATUS_CODE: "http.status_code",
16
+ HTTP_HOST: "http.host",
17
+ HTTP_SCHEME: "http.scheme",
18
+ HTTP_USER_AGENT: "http.user_agent",
19
+ HTTP_METHOD: "http.method",
20
+ HTTP_URL: "http.url",
21
+ HTTP_ROUTE: "http.route",
22
+ HTTP_TARGET: "http.target"
23
+ };
22
24
 
23
25
  function notEmpty(value) {
24
26
  return value !== null && value !== void 0;
@@ -38,6 +40,9 @@ function isString(value) {
38
40
  function isStringArray(value) {
39
41
  return isDefined(value) && Array.isArray(value) && value.every(isString);
40
42
  }
43
+ function isNumber(value) {
44
+ return isDefined(value) && typeof value === "number";
45
+ }
41
46
  function toBase64(value) {
42
47
  try {
43
48
  return btoa(value);
@@ -46,6 +51,24 @@ function toBase64(value) {
46
51
  return buf.from(value).toString("base64");
47
52
  }
48
53
  }
54
+ function deepMerge(a, b) {
55
+ const result = { ...a };
56
+ for (const [key, value] of Object.entries(b)) {
57
+ if (isObject(value) && isObject(result[key])) {
58
+ result[key] = deepMerge(result[key], value);
59
+ } else {
60
+ result[key] = value;
61
+ }
62
+ }
63
+ return result;
64
+ }
65
+ function chunk(array, chunkSize) {
66
+ const result = [];
67
+ for (let i = 0; i < array.length; i += chunkSize) {
68
+ result.push(array.slice(i, i + chunkSize));
69
+ }
70
+ return result;
71
+ }
49
72
 
50
73
  function getEnvironment() {
51
74
  try {
@@ -80,6 +103,25 @@ function getEnvironment() {
80
103
  fallbackBranch: getGlobalFallbackBranch()
81
104
  };
82
105
  }
106
+ function getEnableBrowserVariable() {
107
+ try {
108
+ if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
109
+ return process.env.XATA_ENABLE_BROWSER === "true";
110
+ }
111
+ } catch (err) {
112
+ }
113
+ try {
114
+ if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
115
+ return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
116
+ }
117
+ } catch (err) {
118
+ }
119
+ try {
120
+ return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
121
+ } catch (err) {
122
+ return void 0;
123
+ }
124
+ }
83
125
  function getGlobalApiKey() {
84
126
  try {
85
127
  return XATA_API_KEY;
@@ -117,7 +159,7 @@ async function getGitBranch() {
117
159
  if (typeof require === "function") {
118
160
  return require(nodeModule).execSync(fullCmd, execOptions).trim();
119
161
  }
120
- const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
162
+ const { execSync } = await import(nodeModule);
121
163
  return execSync(fullCmd, execOptions).toString().trim();
122
164
  } catch (err) {
123
165
  }
@@ -144,13 +186,13 @@ function getFetchImplementation(userFetch) {
144
186
  const fetchImpl = userFetch ?? globalFetch;
145
187
  if (!fetchImpl) {
146
188
  throw new Error(
147
- `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
189
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
148
190
  );
149
191
  }
150
192
  return fetchImpl;
151
193
  }
152
194
 
153
- const VERSION = "0.0.0-alpha.vf73045e";
195
+ const VERSION = "0.0.0-alpha.vf76843f";
154
196
 
155
197
  class ErrorWithCause extends Error {
156
198
  constructor(message, options) {
@@ -201,18 +243,24 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
201
243
  }, {});
202
244
  const query = new URLSearchParams(cleanQueryParams).toString();
203
245
  const queryString = query.length > 0 ? `?${query}` : "";
204
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
246
+ const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
247
+ return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
248
+ }, {});
249
+ return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
205
250
  };
206
251
  function buildBaseUrl({
252
+ endpoint,
207
253
  path,
208
254
  workspacesApiUrl,
209
255
  apiUrl,
210
- pathParams
256
+ pathParams = {}
211
257
  }) {
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);
258
+ if (endpoint === "dataPlane") {
259
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
260
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
261
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
262
+ }
263
+ return `${apiUrl}${path}`;
216
264
  }
217
265
  function hostHeader(url) {
218
266
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -228,277 +276,231 @@ async function fetch$1({
228
276
  queryParams,
229
277
  fetchImpl,
230
278
  apiKey,
279
+ endpoint,
231
280
  apiUrl,
232
- workspacesApiUrl
281
+ workspacesApiUrl,
282
+ trace,
283
+ signal,
284
+ clientID,
285
+ sessionID,
286
+ fetchOptions = {}
233
287
  }) {
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;
288
+ return trace(
289
+ `${method.toUpperCase()} ${path}`,
290
+ async ({ setAttributes }) => {
291
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
292
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
293
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
294
+ setAttributes({
295
+ [TraceAttributes.HTTP_URL]: url,
296
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
297
+ });
298
+ const response = await fetchImpl(url, {
299
+ ...fetchOptions,
300
+ method: method.toUpperCase(),
301
+ body: body ? JSON.stringify(body) : void 0,
302
+ headers: {
303
+ "Content-Type": "application/json",
304
+ "User-Agent": `Xata client-ts/${VERSION}`,
305
+ "X-Xata-Client-ID": clientID ?? "",
306
+ "X-Xata-Session-ID": sessionID ?? "",
307
+ ...headers,
308
+ ...hostHeader(fullUrl),
309
+ Authorization: `Bearer ${apiKey}`
310
+ },
311
+ signal
312
+ });
313
+ if (response.status === 204) {
314
+ return {};
315
+ }
316
+ const { host, protocol } = parseUrl(response.url);
317
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
318
+ setAttributes({
319
+ [TraceAttributes.KIND]: "http",
320
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
321
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
322
+ [TraceAttributes.HTTP_HOST]: host,
323
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
324
+ });
325
+ try {
326
+ const jsonResponse = await response.json();
327
+ if (response.ok) {
328
+ return jsonResponse;
329
+ }
330
+ throw new FetcherError(response.status, jsonResponse, requestId);
331
+ } catch (error) {
332
+ throw new FetcherError(response.status, error, requestId);
333
+ }
334
+ },
335
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
336
+ );
337
+ }
338
+ function parseUrl(url) {
252
339
  try {
253
- const jsonResponse = await response.json();
254
- if (response.ok) {
255
- return jsonResponse;
256
- }
257
- throw new FetcherError(response.status, jsonResponse, requestId);
340
+ const { host, protocol } = new URL(url);
341
+ return { host, protocol };
258
342
  } catch (error) {
259
- throw new FetcherError(response.status, error, requestId);
343
+ return {};
260
344
  }
261
345
  }
262
346
 
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({
347
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
348
+
349
+ const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
350
+ const getBranchList = (variables, signal) => dataPlaneFetch({
350
351
  url: "/dbs/{dbName}",
351
- method: "delete",
352
- ...variables
353
- });
354
- const getDatabaseMetadata = (variables) => fetch$1({
355
- url: "/dbs/{dbName}/metadata",
356
352
  method: "get",
357
- ...variables
353
+ ...variables,
354
+ signal
358
355
  });
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({
356
+ const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
357
+ const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
358
+ const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
359
+ const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
360
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
368
361
  url: "/db/{dbBranchName}",
369
362
  method: "get",
370
- ...variables
363
+ ...variables,
364
+ signal
371
365
  });
372
- const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
373
- const deleteBranch = (variables) => fetch$1({
366
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
367
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
374
368
  url: "/db/{dbBranchName}",
375
369
  method: "delete",
376
- ...variables
370
+ ...variables,
371
+ signal
377
372
  });
378
- const updateBranchMetadata = (variables) => fetch$1({
373
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
379
374
  url: "/db/{dbBranchName}/metadata",
380
375
  method: "put",
381
- ...variables
376
+ ...variables,
377
+ signal
382
378
  });
383
- const getBranchMetadata = (variables) => fetch$1({
379
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
384
380
  url: "/db/{dbBranchName}/metadata",
385
381
  method: "get",
386
- ...variables
382
+ ...variables,
383
+ signal
387
384
  });
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({
385
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
392
386
  url: "/db/{dbBranchName}/stats",
393
387
  method: "get",
394
- ...variables
388
+ ...variables,
389
+ signal
390
+ });
391
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
392
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
393
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
394
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
395
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
396
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
397
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
398
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
399
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
400
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
401
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
402
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
403
+ method: "get",
404
+ ...variables,
405
+ signal
406
+ });
407
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
408
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
409
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
410
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
411
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
412
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
413
+ method: "post",
414
+ ...variables,
415
+ signal
395
416
  });
396
- const createTable = (variables) => fetch$1({
417
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
418
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
419
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
420
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
421
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
422
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
423
+ const createTable = (variables, signal) => dataPlaneFetch({
397
424
  url: "/db/{dbBranchName}/tables/{tableName}",
398
425
  method: "put",
399
- ...variables
426
+ ...variables,
427
+ signal
400
428
  });
401
- const deleteTable = (variables) => fetch$1({
429
+ const deleteTable = (variables, signal) => dataPlaneFetch({
402
430
  url: "/db/{dbBranchName}/tables/{tableName}",
403
431
  method: "delete",
404
- ...variables
432
+ ...variables,
433
+ signal
405
434
  });
406
- const updateTable = (variables) => fetch$1({
407
- url: "/db/{dbBranchName}/tables/{tableName}",
408
- method: "patch",
409
- ...variables
410
- });
411
- const getTableSchema = (variables) => fetch$1({
435
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
436
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
412
437
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
413
438
  method: "get",
414
- ...variables
415
- });
416
- const setTableSchema = (variables) => fetch$1({
417
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
418
- method: "put",
419
- ...variables
439
+ ...variables,
440
+ signal
420
441
  });
421
- const getTableColumns = (variables) => fetch$1({
442
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
443
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
422
444
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
423
445
  method: "get",
424
- ...variables
446
+ ...variables,
447
+ signal
425
448
  });
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({
449
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
450
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
451
+ );
452
+ const getColumn = (variables, signal) => dataPlaneFetch({
432
453
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
433
454
  method: "get",
434
- ...variables
455
+ ...variables,
456
+ signal
435
457
  });
436
- const deleteColumn = (variables) => fetch$1({
458
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
459
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
437
460
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
438
461
  method: "delete",
439
- ...variables
462
+ ...variables,
463
+ signal
440
464
  });
441
- const updateColumn = (variables) => fetch$1({
442
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
443
- method: "patch",
444
- ...variables
445
- });
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({
465
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
466
+ const getRecord = (variables, signal) => dataPlaneFetch({
456
467
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
457
468
  method: "get",
458
- ...variables
469
+ ...variables,
470
+ signal
459
471
  });
460
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
461
- const queryTable = (variables) => fetch$1({
472
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
473
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
474
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
475
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
476
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
477
+ const queryTable = (variables, signal) => dataPlaneFetch({
462
478
  url: "/db/{dbBranchName}/tables/{tableName}/query",
463
479
  method: "post",
464
- ...variables
480
+ ...variables,
481
+ signal
465
482
  });
466
- const searchTable = (variables) => fetch$1({
467
- url: "/db/{dbBranchName}/tables/{tableName}/search",
483
+ const searchBranch = (variables, signal) => dataPlaneFetch({
484
+ url: "/db/{dbBranchName}/search",
468
485
  method: "post",
469
- ...variables
486
+ ...variables,
487
+ signal
470
488
  });
471
- const searchBranch = (variables) => fetch$1({
472
- url: "/db/{dbBranchName}/search",
489
+ const searchTable = (variables, signal) => dataPlaneFetch({
490
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
473
491
  method: "post",
474
- ...variables
492
+ ...variables,
493
+ signal
475
494
  });
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
- },
495
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
496
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
497
+ const operationsByTag$2 = {
493
498
  database: {
494
- getDatabaseList,
495
- createDatabase,
496
- deleteDatabase,
497
- getDatabaseMetadata,
498
- getGitBranchesMapping,
499
- addGitBranchesEntry,
500
- removeGitBranchesEntry,
501
- resolveBranch
499
+ dEPRECATEDgetDatabaseList,
500
+ dEPRECATEDcreateDatabase,
501
+ dEPRECATEDdeleteDatabase,
502
+ dEPRECATEDgetDatabaseMetadata,
503
+ dEPRECATEDupdateDatabaseMetadata
502
504
  },
503
505
  branch: {
504
506
  getBranchList,
@@ -507,10 +509,42 @@ const operationsByTag = {
507
509
  deleteBranch,
508
510
  updateBranchMetadata,
509
511
  getBranchMetadata,
512
+ getBranchStats,
513
+ getGitBranchesMapping,
514
+ addGitBranchesEntry,
515
+ removeGitBranchesEntry,
516
+ resolveBranch
517
+ },
518
+ migrations: {
510
519
  getBranchMigrationHistory,
511
- executeBranchMigrationPlan,
512
520
  getBranchMigrationPlan,
513
- getBranchStats
521
+ executeBranchMigrationPlan,
522
+ getBranchSchemaHistory,
523
+ compareBranchWithUserSchema,
524
+ compareBranchSchemas,
525
+ updateBranchSchema,
526
+ previewBranchSchemaEdit,
527
+ applyBranchSchemaEdit
528
+ },
529
+ records: {
530
+ branchTransaction,
531
+ insertRecord,
532
+ getRecord,
533
+ insertRecordWithID,
534
+ updateRecordWithID,
535
+ upsertRecordWithID,
536
+ deleteRecord,
537
+ bulkInsertTableRecords
538
+ },
539
+ migrationRequests: {
540
+ queryMigrationRequests,
541
+ createMigrationRequest,
542
+ getMigrationRequest,
543
+ updateMigrationRequest,
544
+ listMigrationRequestsCommits,
545
+ compareMigrationRequest,
546
+ getMigrationRequestIsMerged,
547
+ mergeMigrationRequest
514
548
  },
515
549
  table: {
516
550
  createTable,
@@ -521,27 +555,150 @@ const operationsByTag = {
521
555
  getTableColumns,
522
556
  addTableColumn,
523
557
  getColumn,
524
- deleteColumn,
525
- updateColumn
558
+ updateColumn,
559
+ deleteColumn
526
560
  },
527
- records: {
528
- insertRecord,
529
- insertRecordWithID,
530
- updateRecordWithID,
531
- upsertRecordWithID,
532
- deleteRecord,
533
- getRecord,
534
- bulkInsertTableRecords,
535
- queryTable,
536
- searchTable,
537
- searchBranch
561
+ searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
562
+ };
563
+
564
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
565
+
566
+ const getUser = (variables, signal) => controlPlaneFetch({
567
+ url: "/user",
568
+ method: "get",
569
+ ...variables,
570
+ signal
571
+ });
572
+ const updateUser = (variables, signal) => controlPlaneFetch({
573
+ url: "/user",
574
+ method: "put",
575
+ ...variables,
576
+ signal
577
+ });
578
+ const deleteUser = (variables, signal) => controlPlaneFetch({
579
+ url: "/user",
580
+ method: "delete",
581
+ ...variables,
582
+ signal
583
+ });
584
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
585
+ url: "/user/keys",
586
+ method: "get",
587
+ ...variables,
588
+ signal
589
+ });
590
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
591
+ url: "/user/keys/{keyName}",
592
+ method: "post",
593
+ ...variables,
594
+ signal
595
+ });
596
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
597
+ url: "/user/keys/{keyName}",
598
+ method: "delete",
599
+ ...variables,
600
+ signal
601
+ });
602
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
603
+ url: "/workspaces",
604
+ method: "get",
605
+ ...variables,
606
+ signal
607
+ });
608
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
609
+ url: "/workspaces",
610
+ method: "post",
611
+ ...variables,
612
+ signal
613
+ });
614
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
615
+ url: "/workspaces/{workspaceId}",
616
+ method: "get",
617
+ ...variables,
618
+ signal
619
+ });
620
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
621
+ url: "/workspaces/{workspaceId}",
622
+ method: "put",
623
+ ...variables,
624
+ signal
625
+ });
626
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
627
+ url: "/workspaces/{workspaceId}",
628
+ method: "delete",
629
+ ...variables,
630
+ signal
631
+ });
632
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
633
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
634
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
635
+ url: "/workspaces/{workspaceId}/members/{userId}",
636
+ method: "delete",
637
+ ...variables,
638
+ signal
639
+ });
640
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
641
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
642
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
643
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
644
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
645
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
646
+ url: "/workspaces/{workspaceId}/dbs",
647
+ method: "get",
648
+ ...variables,
649
+ signal
650
+ });
651
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
652
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
653
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
654
+ method: "delete",
655
+ ...variables,
656
+ signal
657
+ });
658
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
659
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
660
+ const listRegions = (variables, signal) => controlPlaneFetch({
661
+ url: "/workspaces/{workspaceId}/regions",
662
+ method: "get",
663
+ ...variables,
664
+ signal
665
+ });
666
+ const operationsByTag$1 = {
667
+ users: { getUser, updateUser, deleteUser },
668
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
669
+ workspaces: {
670
+ getWorkspacesList,
671
+ createWorkspace,
672
+ getWorkspace,
673
+ updateWorkspace,
674
+ deleteWorkspace,
675
+ getWorkspaceMembersList,
676
+ updateWorkspaceMemberRole,
677
+ removeWorkspaceMember
678
+ },
679
+ invites: {
680
+ inviteWorkspaceMember,
681
+ updateWorkspaceMemberInvite,
682
+ cancelWorkspaceMemberInvite,
683
+ acceptWorkspaceMemberInvite,
684
+ resendWorkspaceMemberInvite
685
+ },
686
+ databases: {
687
+ getDatabaseList,
688
+ createDatabase,
689
+ deleteDatabase,
690
+ getDatabaseMetadata,
691
+ updateDatabaseMetadata,
692
+ listRegions
538
693
  }
539
694
  };
540
695
 
696
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
697
+
541
698
  function getHostUrl(provider, type) {
542
- if (isValidAlias(provider)) {
699
+ if (isHostProviderAlias(provider)) {
543
700
  return providers[provider][type];
544
- } else if (isValidBuilder(provider)) {
701
+ } else if (isHostProviderBuilder(provider)) {
545
702
  return provider[type];
546
703
  }
547
704
  throw new Error("Invalid API provider");
@@ -549,19 +706,38 @@ function getHostUrl(provider, type) {
549
706
  const providers = {
550
707
  production: {
551
708
  main: "https://api.xata.io",
552
- workspaces: "https://{workspaceId}.xata.sh"
709
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
553
710
  },
554
711
  staging: {
555
712
  main: "https://staging.xatabase.co",
556
- workspaces: "https://{workspaceId}.staging.xatabase.co"
713
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
557
714
  }
558
715
  };
559
- function isValidAlias(alias) {
716
+ function isHostProviderAlias(alias) {
560
717
  return isString(alias) && Object.keys(providers).includes(alias);
561
718
  }
562
- function isValidBuilder(builder) {
719
+ function isHostProviderBuilder(builder) {
563
720
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
564
721
  }
722
+ function parseProviderString(provider = "production") {
723
+ if (isHostProviderAlias(provider)) {
724
+ return provider;
725
+ }
726
+ const [main, workspaces] = provider.split(",");
727
+ if (!main || !workspaces)
728
+ return null;
729
+ return { main, workspaces };
730
+ }
731
+ function parseWorkspacesUrlParts(url) {
732
+ if (!isString(url))
733
+ return null;
734
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
735
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
736
+ const match = url.match(regex) || url.match(regexStaging);
737
+ if (!match)
738
+ return null;
739
+ return { workspace: match[1], region: match[2] ?? "eu-west-1" };
740
+ }
565
741
 
566
742
  var __accessCheck$7 = (obj, member, msg) => {
567
743
  if (!member.has(obj))
@@ -587,7 +763,8 @@ class XataApiClient {
587
763
  __privateAdd$7(this, _extraProps, void 0);
588
764
  __privateAdd$7(this, _namespaces, {});
589
765
  const provider = options.host ?? "production";
590
- const apiKey = options?.apiKey ?? getAPIKey();
766
+ const apiKey = options.apiKey ?? getAPIKey();
767
+ const trace = options.trace ?? defaultTrace;
591
768
  if (!apiKey) {
592
769
  throw new Error("Could not resolve a valid apiKey");
593
770
  }
@@ -595,7 +772,8 @@ class XataApiClient {
595
772
  apiUrl: getHostUrl(provider, "main"),
596
773
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
597
774
  fetchImpl: getFetchImplementation(options.fetch),
598
- apiKey
775
+ apiKey,
776
+ trace
599
777
  });
600
778
  }
601
779
  get user() {
@@ -603,21 +781,41 @@ class XataApiClient {
603
781
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
604
782
  return __privateGet$7(this, _namespaces).user;
605
783
  }
784
+ get authentication() {
785
+ if (!__privateGet$7(this, _namespaces).authentication)
786
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
787
+ return __privateGet$7(this, _namespaces).authentication;
788
+ }
606
789
  get workspaces() {
607
790
  if (!__privateGet$7(this, _namespaces).workspaces)
608
791
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
609
792
  return __privateGet$7(this, _namespaces).workspaces;
610
793
  }
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;
794
+ get invites() {
795
+ if (!__privateGet$7(this, _namespaces).invites)
796
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
797
+ return __privateGet$7(this, _namespaces).invites;
798
+ }
799
+ get database() {
800
+ if (!__privateGet$7(this, _namespaces).database)
801
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
802
+ return __privateGet$7(this, _namespaces).database;
615
803
  }
616
804
  get branches() {
617
805
  if (!__privateGet$7(this, _namespaces).branches)
618
806
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
619
807
  return __privateGet$7(this, _namespaces).branches;
620
808
  }
809
+ get migrations() {
810
+ if (!__privateGet$7(this, _namespaces).migrations)
811
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
812
+ return __privateGet$7(this, _namespaces).migrations;
813
+ }
814
+ get migrationRequests() {
815
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
816
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
817
+ return __privateGet$7(this, _namespaces).migrationRequests;
818
+ }
621
819
  get tables() {
622
820
  if (!__privateGet$7(this, _namespaces).tables)
623
821
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -628,6 +826,11 @@ class XataApiClient {
628
826
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
629
827
  return __privateGet$7(this, _namespaces).records;
630
828
  }
829
+ get searchAndFilter() {
830
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
831
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
832
+ return __privateGet$7(this, _namespaces).searchAndFilter;
833
+ }
631
834
  }
632
835
  _extraProps = new WeakMap();
633
836
  _namespaces = new WeakMap();
@@ -638,24 +841,29 @@ class UserApi {
638
841
  getUser() {
639
842
  return operationsByTag.users.getUser({ ...this.extraProps });
640
843
  }
641
- updateUser(user) {
844
+ updateUser({ user }) {
642
845
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
643
846
  }
644
847
  deleteUser() {
645
848
  return operationsByTag.users.deleteUser({ ...this.extraProps });
646
849
  }
850
+ }
851
+ class AuthenticationApi {
852
+ constructor(extraProps) {
853
+ this.extraProps = extraProps;
854
+ }
647
855
  getUserAPIKeys() {
648
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
856
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
649
857
  }
650
- createUserAPIKey(keyName) {
651
- return operationsByTag.users.createUserAPIKey({
652
- pathParams: { keyName },
858
+ createUserAPIKey({ name }) {
859
+ return operationsByTag.authentication.createUserAPIKey({
860
+ pathParams: { keyName: name },
653
861
  ...this.extraProps
654
862
  });
655
863
  }
656
- deleteUserAPIKey(keyName) {
657
- return operationsByTag.users.deleteUserAPIKey({
658
- pathParams: { keyName },
864
+ deleteUserAPIKey({ name }) {
865
+ return operationsByTag.authentication.deleteUserAPIKey({
866
+ pathParams: { keyName: name },
659
867
  ...this.extraProps
660
868
  });
661
869
  }
@@ -664,359 +872,897 @@ class WorkspaceApi {
664
872
  constructor(extraProps) {
665
873
  this.extraProps = extraProps;
666
874
  }
667
- createWorkspace(workspaceMeta) {
875
+ getWorkspacesList() {
876
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
877
+ }
878
+ createWorkspace({ data }) {
668
879
  return operationsByTag.workspaces.createWorkspace({
669
- body: workspaceMeta,
880
+ body: data,
670
881
  ...this.extraProps
671
882
  });
672
883
  }
673
- getWorkspacesList() {
674
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
675
- }
676
- getWorkspace(workspaceId) {
884
+ getWorkspace({ workspace }) {
677
885
  return operationsByTag.workspaces.getWorkspace({
678
- pathParams: { workspaceId },
886
+ pathParams: { workspaceId: workspace },
679
887
  ...this.extraProps
680
888
  });
681
889
  }
682
- updateWorkspace(workspaceId, workspaceMeta) {
890
+ updateWorkspace({
891
+ workspace,
892
+ update
893
+ }) {
683
894
  return operationsByTag.workspaces.updateWorkspace({
684
- pathParams: { workspaceId },
685
- body: workspaceMeta,
895
+ pathParams: { workspaceId: workspace },
896
+ body: update,
686
897
  ...this.extraProps
687
898
  });
688
899
  }
689
- deleteWorkspace(workspaceId) {
900
+ deleteWorkspace({ workspace }) {
690
901
  return operationsByTag.workspaces.deleteWorkspace({
691
- pathParams: { workspaceId },
902
+ pathParams: { workspaceId: workspace },
692
903
  ...this.extraProps
693
904
  });
694
905
  }
695
- getWorkspaceMembersList(workspaceId) {
906
+ getWorkspaceMembersList({ workspace }) {
696
907
  return operationsByTag.workspaces.getWorkspaceMembersList({
697
- pathParams: { workspaceId },
908
+ pathParams: { workspaceId: workspace },
698
909
  ...this.extraProps
699
910
  });
700
911
  }
701
- updateWorkspaceMemberRole(workspaceId, userId, role) {
912
+ updateWorkspaceMemberRole({
913
+ workspace,
914
+ user,
915
+ role
916
+ }) {
702
917
  return operationsByTag.workspaces.updateWorkspaceMemberRole({
703
- pathParams: { workspaceId, userId },
918
+ pathParams: { workspaceId: workspace, userId: user },
704
919
  body: { role },
705
920
  ...this.extraProps
706
921
  });
707
922
  }
708
- removeWorkspaceMember(workspaceId, userId) {
923
+ removeWorkspaceMember({
924
+ workspace,
925
+ user
926
+ }) {
709
927
  return operationsByTag.workspaces.removeWorkspaceMember({
710
- pathParams: { workspaceId, userId },
928
+ pathParams: { workspaceId: workspace, userId: user },
711
929
  ...this.extraProps
712
930
  });
713
931
  }
714
- inviteWorkspaceMember(workspaceId, email, role) {
715
- return operationsByTag.workspaces.inviteWorkspaceMember({
716
- pathParams: { workspaceId },
932
+ }
933
+ class InvitesApi {
934
+ constructor(extraProps) {
935
+ this.extraProps = extraProps;
936
+ }
937
+ inviteWorkspaceMember({
938
+ workspace,
939
+ email,
940
+ role
941
+ }) {
942
+ return operationsByTag.invites.inviteWorkspaceMember({
943
+ pathParams: { workspaceId: workspace },
717
944
  body: { email, role },
718
945
  ...this.extraProps
719
946
  });
720
947
  }
721
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
722
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
723
- pathParams: { workspaceId, inviteId },
948
+ updateWorkspaceMemberInvite({
949
+ workspace,
950
+ invite,
951
+ role
952
+ }) {
953
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
954
+ pathParams: { workspaceId: workspace, inviteId: invite },
724
955
  body: { role },
725
956
  ...this.extraProps
726
957
  });
727
958
  }
728
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
729
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
730
- pathParams: { workspaceId, inviteId },
959
+ cancelWorkspaceMemberInvite({
960
+ workspace,
961
+ invite
962
+ }) {
963
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
964
+ pathParams: { workspaceId: workspace, inviteId: invite },
965
+ ...this.extraProps
966
+ });
967
+ }
968
+ acceptWorkspaceMemberInvite({
969
+ workspace,
970
+ key
971
+ }) {
972
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
973
+ pathParams: { workspaceId: workspace, inviteKey: key },
974
+ ...this.extraProps
975
+ });
976
+ }
977
+ resendWorkspaceMemberInvite({
978
+ workspace,
979
+ invite
980
+ }) {
981
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
982
+ pathParams: { workspaceId: workspace, inviteId: invite },
731
983
  ...this.extraProps
732
984
  });
733
985
  }
734
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
735
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
736
- pathParams: { workspaceId, inviteId },
986
+ }
987
+ class BranchApi {
988
+ constructor(extraProps) {
989
+ this.extraProps = extraProps;
990
+ }
991
+ getBranchList({
992
+ workspace,
993
+ region,
994
+ database
995
+ }) {
996
+ return operationsByTag.branch.getBranchList({
997
+ pathParams: { workspace, region, dbName: database },
998
+ ...this.extraProps
999
+ });
1000
+ }
1001
+ getBranchDetails({
1002
+ workspace,
1003
+ region,
1004
+ database,
1005
+ branch
1006
+ }) {
1007
+ return operationsByTag.branch.getBranchDetails({
1008
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1009
+ ...this.extraProps
1010
+ });
1011
+ }
1012
+ createBranch({
1013
+ workspace,
1014
+ region,
1015
+ database,
1016
+ branch,
1017
+ from,
1018
+ metadata
1019
+ }) {
1020
+ return operationsByTag.branch.createBranch({
1021
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1022
+ body: { from, metadata },
1023
+ ...this.extraProps
1024
+ });
1025
+ }
1026
+ deleteBranch({
1027
+ workspace,
1028
+ region,
1029
+ database,
1030
+ branch
1031
+ }) {
1032
+ return operationsByTag.branch.deleteBranch({
1033
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1034
+ ...this.extraProps
1035
+ });
1036
+ }
1037
+ updateBranchMetadata({
1038
+ workspace,
1039
+ region,
1040
+ database,
1041
+ branch,
1042
+ metadata
1043
+ }) {
1044
+ return operationsByTag.branch.updateBranchMetadata({
1045
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1046
+ body: metadata,
1047
+ ...this.extraProps
1048
+ });
1049
+ }
1050
+ getBranchMetadata({
1051
+ workspace,
1052
+ region,
1053
+ database,
1054
+ branch
1055
+ }) {
1056
+ return operationsByTag.branch.getBranchMetadata({
1057
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1058
+ ...this.extraProps
1059
+ });
1060
+ }
1061
+ getBranchStats({
1062
+ workspace,
1063
+ region,
1064
+ database,
1065
+ branch
1066
+ }) {
1067
+ return operationsByTag.branch.getBranchStats({
1068
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1069
+ ...this.extraProps
1070
+ });
1071
+ }
1072
+ getGitBranchesMapping({
1073
+ workspace,
1074
+ region,
1075
+ database
1076
+ }) {
1077
+ return operationsByTag.branch.getGitBranchesMapping({
1078
+ pathParams: { workspace, region, dbName: database },
1079
+ ...this.extraProps
1080
+ });
1081
+ }
1082
+ addGitBranchesEntry({
1083
+ workspace,
1084
+ region,
1085
+ database,
1086
+ gitBranch,
1087
+ xataBranch
1088
+ }) {
1089
+ return operationsByTag.branch.addGitBranchesEntry({
1090
+ pathParams: { workspace, region, dbName: database },
1091
+ body: { gitBranch, xataBranch },
1092
+ ...this.extraProps
1093
+ });
1094
+ }
1095
+ removeGitBranchesEntry({
1096
+ workspace,
1097
+ region,
1098
+ database,
1099
+ gitBranch
1100
+ }) {
1101
+ return operationsByTag.branch.removeGitBranchesEntry({
1102
+ pathParams: { workspace, region, dbName: database },
1103
+ queryParams: { gitBranch },
1104
+ ...this.extraProps
1105
+ });
1106
+ }
1107
+ resolveBranch({
1108
+ workspace,
1109
+ region,
1110
+ database,
1111
+ gitBranch,
1112
+ fallbackBranch
1113
+ }) {
1114
+ return operationsByTag.branch.resolveBranch({
1115
+ pathParams: { workspace, region, dbName: database },
1116
+ queryParams: { gitBranch, fallbackBranch },
1117
+ ...this.extraProps
1118
+ });
1119
+ }
1120
+ }
1121
+ class TableApi {
1122
+ constructor(extraProps) {
1123
+ this.extraProps = extraProps;
1124
+ }
1125
+ createTable({
1126
+ workspace,
1127
+ region,
1128
+ database,
1129
+ branch,
1130
+ table
1131
+ }) {
1132
+ return operationsByTag.table.createTable({
1133
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1134
+ ...this.extraProps
1135
+ });
1136
+ }
1137
+ deleteTable({
1138
+ workspace,
1139
+ region,
1140
+ database,
1141
+ branch,
1142
+ table
1143
+ }) {
1144
+ return operationsByTag.table.deleteTable({
1145
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1146
+ ...this.extraProps
1147
+ });
1148
+ }
1149
+ updateTable({
1150
+ workspace,
1151
+ region,
1152
+ database,
1153
+ branch,
1154
+ table,
1155
+ update
1156
+ }) {
1157
+ return operationsByTag.table.updateTable({
1158
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1159
+ body: update,
1160
+ ...this.extraProps
1161
+ });
1162
+ }
1163
+ getTableSchema({
1164
+ workspace,
1165
+ region,
1166
+ database,
1167
+ branch,
1168
+ table
1169
+ }) {
1170
+ return operationsByTag.table.getTableSchema({
1171
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1172
+ ...this.extraProps
1173
+ });
1174
+ }
1175
+ setTableSchema({
1176
+ workspace,
1177
+ region,
1178
+ database,
1179
+ branch,
1180
+ table,
1181
+ schema
1182
+ }) {
1183
+ return operationsByTag.table.setTableSchema({
1184
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1185
+ body: schema,
1186
+ ...this.extraProps
1187
+ });
1188
+ }
1189
+ getTableColumns({
1190
+ workspace,
1191
+ region,
1192
+ database,
1193
+ branch,
1194
+ table
1195
+ }) {
1196
+ return operationsByTag.table.getTableColumns({
1197
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1198
+ ...this.extraProps
1199
+ });
1200
+ }
1201
+ addTableColumn({
1202
+ workspace,
1203
+ region,
1204
+ database,
1205
+ branch,
1206
+ table,
1207
+ column
1208
+ }) {
1209
+ return operationsByTag.table.addTableColumn({
1210
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1211
+ body: column,
1212
+ ...this.extraProps
1213
+ });
1214
+ }
1215
+ getColumn({
1216
+ workspace,
1217
+ region,
1218
+ database,
1219
+ branch,
1220
+ table,
1221
+ column
1222
+ }) {
1223
+ return operationsByTag.table.getColumn({
1224
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1225
+ ...this.extraProps
1226
+ });
1227
+ }
1228
+ updateColumn({
1229
+ workspace,
1230
+ region,
1231
+ database,
1232
+ branch,
1233
+ table,
1234
+ column,
1235
+ update
1236
+ }) {
1237
+ return operationsByTag.table.updateColumn({
1238
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1239
+ body: update,
737
1240
  ...this.extraProps
738
1241
  });
739
1242
  }
740
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
741
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
742
- pathParams: { workspaceId, inviteKey },
1243
+ deleteColumn({
1244
+ workspace,
1245
+ region,
1246
+ database,
1247
+ branch,
1248
+ table,
1249
+ column
1250
+ }) {
1251
+ return operationsByTag.table.deleteColumn({
1252
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
743
1253
  ...this.extraProps
744
1254
  });
745
1255
  }
746
1256
  }
747
- class DatabaseApi {
1257
+ class RecordsApi {
748
1258
  constructor(extraProps) {
749
1259
  this.extraProps = extraProps;
750
1260
  }
751
- getDatabaseList(workspace) {
752
- return operationsByTag.database.getDatabaseList({
753
- pathParams: { workspace },
1261
+ insertRecord({
1262
+ workspace,
1263
+ region,
1264
+ database,
1265
+ branch,
1266
+ table,
1267
+ record,
1268
+ columns
1269
+ }) {
1270
+ return operationsByTag.records.insertRecord({
1271
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1272
+ queryParams: { columns },
1273
+ body: record,
754
1274
  ...this.extraProps
755
1275
  });
756
1276
  }
757
- createDatabase(workspace, dbName, options = {}) {
758
- return operationsByTag.database.createDatabase({
759
- pathParams: { workspace, dbName },
760
- body: options,
1277
+ getRecord({
1278
+ workspace,
1279
+ region,
1280
+ database,
1281
+ branch,
1282
+ table,
1283
+ id,
1284
+ columns
1285
+ }) {
1286
+ return operationsByTag.records.getRecord({
1287
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1288
+ queryParams: { columns },
761
1289
  ...this.extraProps
762
1290
  });
763
1291
  }
764
- deleteDatabase(workspace, dbName) {
765
- return operationsByTag.database.deleteDatabase({
766
- pathParams: { workspace, dbName },
1292
+ insertRecordWithID({
1293
+ workspace,
1294
+ region,
1295
+ database,
1296
+ branch,
1297
+ table,
1298
+ id,
1299
+ record,
1300
+ columns,
1301
+ createOnly,
1302
+ ifVersion
1303
+ }) {
1304
+ return operationsByTag.records.insertRecordWithID({
1305
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1306
+ queryParams: { columns, createOnly, ifVersion },
1307
+ body: record,
767
1308
  ...this.extraProps
768
1309
  });
769
1310
  }
770
- getDatabaseMetadata(workspace, dbName) {
771
- return operationsByTag.database.getDatabaseMetadata({
772
- pathParams: { workspace, dbName },
1311
+ updateRecordWithID({
1312
+ workspace,
1313
+ region,
1314
+ database,
1315
+ branch,
1316
+ table,
1317
+ id,
1318
+ record,
1319
+ columns,
1320
+ ifVersion
1321
+ }) {
1322
+ return operationsByTag.records.updateRecordWithID({
1323
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1324
+ queryParams: { columns, ifVersion },
1325
+ body: record,
773
1326
  ...this.extraProps
774
1327
  });
775
1328
  }
776
- getGitBranchesMapping(workspace, dbName) {
777
- return operationsByTag.database.getGitBranchesMapping({
778
- pathParams: { workspace, dbName },
1329
+ upsertRecordWithID({
1330
+ workspace,
1331
+ region,
1332
+ database,
1333
+ branch,
1334
+ table,
1335
+ id,
1336
+ record,
1337
+ columns,
1338
+ ifVersion
1339
+ }) {
1340
+ return operationsByTag.records.upsertRecordWithID({
1341
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1342
+ queryParams: { columns, ifVersion },
1343
+ body: record,
779
1344
  ...this.extraProps
780
1345
  });
781
1346
  }
782
- addGitBranchesEntry(workspace, dbName, body) {
783
- return operationsByTag.database.addGitBranchesEntry({
784
- pathParams: { workspace, dbName },
785
- body,
1347
+ deleteRecord({
1348
+ workspace,
1349
+ region,
1350
+ database,
1351
+ branch,
1352
+ table,
1353
+ id,
1354
+ columns
1355
+ }) {
1356
+ return operationsByTag.records.deleteRecord({
1357
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1358
+ queryParams: { columns },
786
1359
  ...this.extraProps
787
1360
  });
788
1361
  }
789
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
790
- return operationsByTag.database.removeGitBranchesEntry({
791
- pathParams: { workspace, dbName },
792
- queryParams: { gitBranch },
1362
+ bulkInsertTableRecords({
1363
+ workspace,
1364
+ region,
1365
+ database,
1366
+ branch,
1367
+ table,
1368
+ records,
1369
+ columns
1370
+ }) {
1371
+ return operationsByTag.records.bulkInsertTableRecords({
1372
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1373
+ queryParams: { columns },
1374
+ body: { records },
793
1375
  ...this.extraProps
794
1376
  });
795
1377
  }
796
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
797
- return operationsByTag.database.resolveBranch({
798
- pathParams: { workspace, dbName },
799
- queryParams: { gitBranch, fallbackBranch },
1378
+ branchTransaction({
1379
+ workspace,
1380
+ region,
1381
+ database,
1382
+ branch,
1383
+ operations
1384
+ }) {
1385
+ return operationsByTag.records.branchTransaction({
1386
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1387
+ body: { operations },
800
1388
  ...this.extraProps
801
1389
  });
802
1390
  }
803
1391
  }
804
- class BranchApi {
1392
+ class SearchAndFilterApi {
805
1393
  constructor(extraProps) {
806
1394
  this.extraProps = extraProps;
807
1395
  }
808
- getBranchList(workspace, dbName) {
809
- return operationsByTag.branch.getBranchList({
810
- pathParams: { workspace, dbName },
1396
+ queryTable({
1397
+ workspace,
1398
+ region,
1399
+ database,
1400
+ branch,
1401
+ table,
1402
+ filter,
1403
+ sort,
1404
+ page,
1405
+ columns,
1406
+ consistency
1407
+ }) {
1408
+ return operationsByTag.searchAndFilter.queryTable({
1409
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1410
+ body: { filter, sort, page, columns, consistency },
811
1411
  ...this.extraProps
812
1412
  });
813
1413
  }
814
- getBranchDetails(workspace, database, branch) {
815
- return operationsByTag.branch.getBranchDetails({
816
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1414
+ searchTable({
1415
+ workspace,
1416
+ region,
1417
+ database,
1418
+ branch,
1419
+ table,
1420
+ query,
1421
+ fuzziness,
1422
+ target,
1423
+ prefix,
1424
+ filter,
1425
+ highlight,
1426
+ boosters
1427
+ }) {
1428
+ return operationsByTag.searchAndFilter.searchTable({
1429
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1430
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
817
1431
  ...this.extraProps
818
1432
  });
819
1433
  }
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,
1434
+ searchBranch({
1435
+ workspace,
1436
+ region,
1437
+ database,
1438
+ branch,
1439
+ tables,
1440
+ query,
1441
+ fuzziness,
1442
+ prefix,
1443
+ highlight
1444
+ }) {
1445
+ return operationsByTag.searchAndFilter.searchBranch({
1446
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1447
+ body: { tables, query, fuzziness, prefix, highlight },
825
1448
  ...this.extraProps
826
1449
  });
827
1450
  }
828
- deleteBranch(workspace, database, branch) {
829
- return operationsByTag.branch.deleteBranch({
830
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1451
+ summarizeTable({
1452
+ workspace,
1453
+ region,
1454
+ database,
1455
+ branch,
1456
+ table,
1457
+ filter,
1458
+ columns,
1459
+ summaries,
1460
+ sort,
1461
+ summariesFilter,
1462
+ page,
1463
+ consistency
1464
+ }) {
1465
+ return operationsByTag.searchAndFilter.summarizeTable({
1466
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1467
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
831
1468
  ...this.extraProps
832
1469
  });
833
1470
  }
834
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
835
- return operationsByTag.branch.updateBranchMetadata({
836
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
837
- body: metadata,
1471
+ aggregateTable({
1472
+ workspace,
1473
+ region,
1474
+ database,
1475
+ branch,
1476
+ table,
1477
+ filter,
1478
+ aggs
1479
+ }) {
1480
+ return operationsByTag.searchAndFilter.aggregateTable({
1481
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1482
+ body: { filter, aggs },
838
1483
  ...this.extraProps
839
1484
  });
840
1485
  }
841
- getBranchMetadata(workspace, database, branch) {
842
- return operationsByTag.branch.getBranchMetadata({
843
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
844
- ...this.extraProps
845
- });
1486
+ }
1487
+ class MigrationRequestsApi {
1488
+ constructor(extraProps) {
1489
+ this.extraProps = extraProps;
846
1490
  }
847
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
848
- return operationsByTag.branch.getBranchMigrationHistory({
849
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
850
- body: options,
1491
+ queryMigrationRequests({
1492
+ workspace,
1493
+ region,
1494
+ database,
1495
+ filter,
1496
+ sort,
1497
+ page,
1498
+ columns
1499
+ }) {
1500
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1501
+ pathParams: { workspace, region, dbName: database },
1502
+ body: { filter, sort, page, columns },
851
1503
  ...this.extraProps
852
1504
  });
853
1505
  }
854
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
855
- return operationsByTag.branch.executeBranchMigrationPlan({
856
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
857
- body: migrationPlan,
1506
+ createMigrationRequest({
1507
+ workspace,
1508
+ region,
1509
+ database,
1510
+ migration
1511
+ }) {
1512
+ return operationsByTag.migrationRequests.createMigrationRequest({
1513
+ pathParams: { workspace, region, dbName: database },
1514
+ body: migration,
858
1515
  ...this.extraProps
859
1516
  });
860
1517
  }
861
- getBranchMigrationPlan(workspace, database, branch, schema) {
862
- return operationsByTag.branch.getBranchMigrationPlan({
863
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
864
- body: schema,
1518
+ getMigrationRequest({
1519
+ workspace,
1520
+ region,
1521
+ database,
1522
+ migrationRequest
1523
+ }) {
1524
+ return operationsByTag.migrationRequests.getMigrationRequest({
1525
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
865
1526
  ...this.extraProps
866
1527
  });
867
1528
  }
868
- getBranchStats(workspace, database, branch) {
869
- return operationsByTag.branch.getBranchStats({
870
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1529
+ updateMigrationRequest({
1530
+ workspace,
1531
+ region,
1532
+ database,
1533
+ migrationRequest,
1534
+ update
1535
+ }) {
1536
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1537
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1538
+ body: update,
871
1539
  ...this.extraProps
872
1540
  });
873
1541
  }
874
- }
875
- class TableApi {
876
- constructor(extraProps) {
877
- this.extraProps = extraProps;
878
- }
879
- createTable(workspace, database, branch, tableName) {
880
- return operationsByTag.table.createTable({
881
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1542
+ listMigrationRequestsCommits({
1543
+ workspace,
1544
+ region,
1545
+ database,
1546
+ migrationRequest,
1547
+ page
1548
+ }) {
1549
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1550
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1551
+ body: { page },
882
1552
  ...this.extraProps
883
1553
  });
884
1554
  }
885
- deleteTable(workspace, database, branch, tableName) {
886
- return operationsByTag.table.deleteTable({
887
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1555
+ compareMigrationRequest({
1556
+ workspace,
1557
+ region,
1558
+ database,
1559
+ migrationRequest
1560
+ }) {
1561
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1562
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
888
1563
  ...this.extraProps
889
1564
  });
890
1565
  }
891
- updateTable(workspace, database, branch, tableName, options) {
892
- return operationsByTag.table.updateTable({
893
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
894
- body: options,
1566
+ getMigrationRequestIsMerged({
1567
+ workspace,
1568
+ region,
1569
+ database,
1570
+ migrationRequest
1571
+ }) {
1572
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1573
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
895
1574
  ...this.extraProps
896
1575
  });
897
1576
  }
898
- getTableSchema(workspace, database, branch, tableName) {
899
- return operationsByTag.table.getTableSchema({
900
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1577
+ mergeMigrationRequest({
1578
+ workspace,
1579
+ region,
1580
+ database,
1581
+ migrationRequest
1582
+ }) {
1583
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1584
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
901
1585
  ...this.extraProps
902
1586
  });
903
1587
  }
904
- setTableSchema(workspace, database, branch, tableName, options) {
905
- return operationsByTag.table.setTableSchema({
906
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
907
- body: options,
908
- ...this.extraProps
909
- });
1588
+ }
1589
+ class MigrationsApi {
1590
+ constructor(extraProps) {
1591
+ this.extraProps = extraProps;
910
1592
  }
911
- getTableColumns(workspace, database, branch, tableName) {
912
- return operationsByTag.table.getTableColumns({
913
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1593
+ getBranchMigrationHistory({
1594
+ workspace,
1595
+ region,
1596
+ database,
1597
+ branch,
1598
+ limit,
1599
+ startFrom
1600
+ }) {
1601
+ return operationsByTag.migrations.getBranchMigrationHistory({
1602
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1603
+ body: { limit, startFrom },
914
1604
  ...this.extraProps
915
1605
  });
916
1606
  }
917
- addTableColumn(workspace, database, branch, tableName, column) {
918
- return operationsByTag.table.addTableColumn({
919
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
920
- body: column,
1607
+ getBranchMigrationPlan({
1608
+ workspace,
1609
+ region,
1610
+ database,
1611
+ branch,
1612
+ schema
1613
+ }) {
1614
+ return operationsByTag.migrations.getBranchMigrationPlan({
1615
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1616
+ body: schema,
921
1617
  ...this.extraProps
922
1618
  });
923
1619
  }
924
- getColumn(workspace, database, branch, tableName, columnName) {
925
- return operationsByTag.table.getColumn({
926
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1620
+ executeBranchMigrationPlan({
1621
+ workspace,
1622
+ region,
1623
+ database,
1624
+ branch,
1625
+ plan
1626
+ }) {
1627
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1628
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1629
+ body: plan,
927
1630
  ...this.extraProps
928
1631
  });
929
1632
  }
930
- deleteColumn(workspace, database, branch, tableName, columnName) {
931
- return operationsByTag.table.deleteColumn({
932
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1633
+ getBranchSchemaHistory({
1634
+ workspace,
1635
+ region,
1636
+ database,
1637
+ branch,
1638
+ page
1639
+ }) {
1640
+ return operationsByTag.migrations.getBranchSchemaHistory({
1641
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1642
+ body: { page },
933
1643
  ...this.extraProps
934
1644
  });
935
1645
  }
936
- updateColumn(workspace, database, branch, tableName, columnName, options) {
937
- return operationsByTag.table.updateColumn({
938
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
939
- body: options,
1646
+ compareBranchWithUserSchema({
1647
+ workspace,
1648
+ region,
1649
+ database,
1650
+ branch,
1651
+ schema
1652
+ }) {
1653
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1654
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1655
+ body: { schema },
940
1656
  ...this.extraProps
941
1657
  });
942
1658
  }
943
- }
944
- class RecordsApi {
945
- constructor(extraProps) {
946
- this.extraProps = extraProps;
947
- }
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,
1659
+ compareBranchSchemas({
1660
+ workspace,
1661
+ region,
1662
+ database,
1663
+ branch,
1664
+ compare,
1665
+ schema
1666
+ }) {
1667
+ return operationsByTag.migrations.compareBranchSchemas({
1668
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1669
+ body: { schema },
953
1670
  ...this.extraProps
954
1671
  });
955
1672
  }
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,
1673
+ updateBranchSchema({
1674
+ workspace,
1675
+ region,
1676
+ database,
1677
+ branch,
1678
+ migration
1679
+ }) {
1680
+ return operationsByTag.migrations.updateBranchSchema({
1681
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1682
+ body: migration,
961
1683
  ...this.extraProps
962
1684
  });
963
1685
  }
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,
1686
+ previewBranchSchemaEdit({
1687
+ workspace,
1688
+ region,
1689
+ database,
1690
+ branch,
1691
+ data
1692
+ }) {
1693
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1694
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1695
+ body: data,
969
1696
  ...this.extraProps
970
1697
  });
971
1698
  }
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,
1699
+ applyBranchSchemaEdit({
1700
+ workspace,
1701
+ region,
1702
+ database,
1703
+ branch,
1704
+ edits
1705
+ }) {
1706
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1707
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1708
+ body: { edits },
977
1709
  ...this.extraProps
978
1710
  });
979
1711
  }
980
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
981
- return operationsByTag.records.deleteRecord({
982
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
983
- queryParams: options,
1712
+ }
1713
+ class DatabaseApi {
1714
+ constructor(extraProps) {
1715
+ this.extraProps = extraProps;
1716
+ }
1717
+ getDatabaseList({ workspace }) {
1718
+ return operationsByTag.databases.getDatabaseList({
1719
+ pathParams: { workspaceId: workspace },
984
1720
  ...this.extraProps
985
1721
  });
986
1722
  }
987
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
988
- return operationsByTag.records.getRecord({
989
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
990
- queryParams: options,
1723
+ createDatabase({
1724
+ workspace,
1725
+ database,
1726
+ data
1727
+ }) {
1728
+ return operationsByTag.databases.createDatabase({
1729
+ pathParams: { workspaceId: workspace, dbName: database },
1730
+ body: data,
991
1731
  ...this.extraProps
992
1732
  });
993
1733
  }
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 },
1734
+ deleteDatabase({
1735
+ workspace,
1736
+ database
1737
+ }) {
1738
+ return operationsByTag.databases.deleteDatabase({
1739
+ pathParams: { workspaceId: workspace, dbName: database },
999
1740
  ...this.extraProps
1000
1741
  });
1001
1742
  }
1002
- queryTable(workspace, database, branch, tableName, query) {
1003
- return operationsByTag.records.queryTable({
1004
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1005
- body: query,
1743
+ getDatabaseMetadata({
1744
+ workspace,
1745
+ database
1746
+ }) {
1747
+ return operationsByTag.databases.getDatabaseMetadata({
1748
+ pathParams: { workspaceId: workspace, dbName: database },
1006
1749
  ...this.extraProps
1007
1750
  });
1008
1751
  }
1009
- searchTable(workspace, database, branch, tableName, query) {
1010
- return operationsByTag.records.searchTable({
1011
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1012
- body: query,
1752
+ updateDatabaseMetadata({
1753
+ workspace,
1754
+ database,
1755
+ metadata
1756
+ }) {
1757
+ return operationsByTag.databases.updateDatabaseMetadata({
1758
+ pathParams: { workspaceId: workspace, dbName: database },
1759
+ body: metadata,
1013
1760
  ...this.extraProps
1014
1761
  });
1015
1762
  }
1016
- searchBranch(workspace, database, branch, query) {
1017
- return operationsByTag.records.searchBranch({
1018
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1019
- body: query,
1763
+ listRegions({ workspace }) {
1764
+ return operationsByTag.databases.listRegions({
1765
+ pathParams: { workspaceId: workspace },
1020
1766
  ...this.extraProps
1021
1767
  });
1022
1768
  }
@@ -1032,6 +1778,20 @@ class XataApiPlugin {
1032
1778
  class XataPlugin {
1033
1779
  }
1034
1780
 
1781
+ function generateUUID() {
1782
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1783
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1784
+ return v.toString(16);
1785
+ });
1786
+ }
1787
+
1788
+ function cleanFilter(filter) {
1789
+ if (!filter)
1790
+ return void 0;
1791
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1792
+ return values.length > 0 ? filter : void 0;
1793
+ }
1794
+
1035
1795
  var __accessCheck$6 = (obj, member, msg) => {
1036
1796
  if (!member.has(obj))
1037
1797
  throw TypeError("Cannot " + msg);
@@ -1064,11 +1824,11 @@ class Page {
1064
1824
  async previousPage(size, offset) {
1065
1825
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1066
1826
  }
1067
- async firstPage(size, offset) {
1068
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1827
+ async startPage(size, offset) {
1828
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1069
1829
  }
1070
- async lastPage(size, offset) {
1071
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1830
+ async endPage(size, offset) {
1831
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1072
1832
  }
1073
1833
  hasNextPage() {
1074
1834
  return this.meta.page.more;
@@ -1080,7 +1840,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1080
1840
  const PAGINATION_MAX_OFFSET = 800;
1081
1841
  const PAGINATION_DEFAULT_OFFSET = 0;
1082
1842
  function isCursorPaginationOptions(options) {
1083
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1843
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1084
1844
  }
1085
1845
  const _RecordArray = class extends Array {
1086
1846
  constructor(...args) {
@@ -1112,12 +1872,12 @@ const _RecordArray = class extends Array {
1112
1872
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1113
1873
  return new _RecordArray(newPage);
1114
1874
  }
1115
- async firstPage(size, offset) {
1116
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1875
+ async startPage(size, offset) {
1876
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1117
1877
  return new _RecordArray(newPage);
1118
1878
  }
1119
- async lastPage(size, offset) {
1120
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1879
+ async endPage(size, offset) {
1880
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1121
1881
  return new _RecordArray(newPage);
1122
1882
  }
1123
1883
  hasNextPage() {
@@ -1145,9 +1905,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1145
1905
  setter ? setter.call(obj, value) : member.set(obj, value);
1146
1906
  return value;
1147
1907
  };
1148
- var _table$1, _repository, _data;
1908
+ var __privateMethod$3 = (obj, member, method) => {
1909
+ __accessCheck$5(obj, member, "access private method");
1910
+ return method;
1911
+ };
1912
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1149
1913
  const _Query = class {
1150
1914
  constructor(repository, table, data, rawParent) {
1915
+ __privateAdd$5(this, _cleanFilterConstraint);
1151
1916
  __privateAdd$5(this, _table$1, void 0);
1152
1917
  __privateAdd$5(this, _repository, void 0);
1153
1918
  __privateAdd$5(this, _data, { filter: {} });
@@ -1166,9 +1931,10 @@ const _Query = class {
1166
1931
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1167
1932
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1168
1933
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1169
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1934
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1170
1935
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1171
1936
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1937
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1172
1938
  this.any = this.any.bind(this);
1173
1939
  this.all = this.all.bind(this);
1174
1940
  this.not = this.not.bind(this);
@@ -1204,11 +1970,14 @@ const _Query = class {
1204
1970
  }
1205
1971
  filter(a, b) {
1206
1972
  if (arguments.length === 1) {
1207
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1973
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1974
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1975
+ }));
1208
1976
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1209
1977
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1210
1978
  } else {
1211
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1979
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
1980
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1212
1981
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1213
1982
  }
1214
1983
  }
@@ -1246,11 +2015,20 @@ const _Query = class {
1246
2015
  }
1247
2016
  }
1248
2017
  async getMany(options = {}) {
1249
- const page = await this.getPaginated(options);
2018
+ const { pagination = {}, ...rest } = options;
2019
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
2020
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
2021
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
2022
+ const results = [...page.records];
2023
+ while (page.hasNextPage() && results.length < size) {
2024
+ page = await page.nextPage();
2025
+ results.push(...page.records);
2026
+ }
1250
2027
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1251
2028
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1252
2029
  }
1253
- return page.records;
2030
+ const array = new RecordArray(page, results.slice(0, size));
2031
+ return array;
1254
2032
  }
1255
2033
  async getAll(options = {}) {
1256
2034
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1264,19 +2042,35 @@ const _Query = class {
1264
2042
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1265
2043
  return records[0] ?? null;
1266
2044
  }
2045
+ async getFirstOrThrow(options = {}) {
2046
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2047
+ if (records[0] === void 0)
2048
+ throw new Error("No results found.");
2049
+ return records[0];
2050
+ }
2051
+ async summarize(params = {}) {
2052
+ const { summaries, summariesFilter, ...options } = params;
2053
+ const query = new _Query(
2054
+ __privateGet$5(this, _repository),
2055
+ __privateGet$5(this, _table$1),
2056
+ options,
2057
+ __privateGet$5(this, _data)
2058
+ );
2059
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2060
+ }
1267
2061
  cache(ttl) {
1268
2062
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1269
2063
  }
1270
2064
  nextPage(size, offset) {
1271
- return this.firstPage(size, offset);
2065
+ return this.startPage(size, offset);
1272
2066
  }
1273
2067
  previousPage(size, offset) {
1274
- return this.firstPage(size, offset);
2068
+ return this.startPage(size, offset);
1275
2069
  }
1276
- firstPage(size, offset) {
2070
+ startPage(size, offset) {
1277
2071
  return this.getPaginated({ pagination: { size, offset } });
1278
2072
  }
1279
- lastPage(size, offset) {
2073
+ endPage(size, offset) {
1280
2074
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1281
2075
  }
1282
2076
  hasNextPage() {
@@ -1287,9 +2081,20 @@ let Query = _Query;
1287
2081
  _table$1 = new WeakMap();
1288
2082
  _repository = new WeakMap();
1289
2083
  _data = new WeakMap();
2084
+ _cleanFilterConstraint = new WeakSet();
2085
+ cleanFilterConstraint_fn = function(column, value) {
2086
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2087
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2088
+ return { $includes: value };
2089
+ }
2090
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
2091
+ return value.id;
2092
+ }
2093
+ return value;
2094
+ };
1290
2095
  function cleanParent(data, parent) {
1291
2096
  if (isCursorPaginationOptions(data.pagination)) {
1292
- return { ...parent, sorting: void 0, filter: void 0 };
2097
+ return { ...parent, sort: void 0, filter: void 0 };
1293
2098
  }
1294
2099
  return parent;
1295
2100
  }
@@ -1348,18 +2153,25 @@ var __privateMethod$2 = (obj, member, method) => {
1348
2153
  __accessCheck$4(obj, member, "access private method");
1349
2154
  return method;
1350
2155
  };
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;
2156
+ 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;
2157
+ const BULK_OPERATION_MAX_SIZE = 1e3;
1352
2158
  class Repository extends Query {
1353
2159
  }
1354
2160
  class RestRepository extends Query {
1355
2161
  constructor(options) {
1356
- super(null, options.table, {});
2162
+ super(
2163
+ null,
2164
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
2165
+ {}
2166
+ );
1357
2167
  __privateAdd$4(this, _insertRecordWithoutId);
1358
2168
  __privateAdd$4(this, _insertRecordWithId);
1359
- __privateAdd$4(this, _bulkInsertTableRecords);
2169
+ __privateAdd$4(this, _insertRecords);
1360
2170
  __privateAdd$4(this, _updateRecordWithID);
2171
+ __privateAdd$4(this, _updateRecords);
1361
2172
  __privateAdd$4(this, _upsertRecordWithID);
1362
2173
  __privateAdd$4(this, _deleteRecord);
2174
+ __privateAdd$4(this, _deleteRecords);
1363
2175
  __privateAdd$4(this, _setCacheQuery);
1364
2176
  __privateAdd$4(this, _getCacheQuery);
1365
2177
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1368,168 +2180,346 @@ class RestRepository extends Query {
1368
2180
  __privateAdd$4(this, _db, void 0);
1369
2181
  __privateAdd$4(this, _cache, void 0);
1370
2182
  __privateAdd$4(this, _schemaTables$2, void 0);
2183
+ __privateAdd$4(this, _trace, void 0);
1371
2184
  __privateSet$4(this, _table, options.table);
1372
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1373
2185
  __privateSet$4(this, _db, options.db);
1374
2186
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1375
2187
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2188
+ __privateSet$4(this, _getFetchProps, async () => {
2189
+ const props = await options.pluginOptions.getFetchProps();
2190
+ return { ...props, sessionID: generateUUID() };
2191
+ });
2192
+ const trace = options.pluginOptions.trace ?? defaultTrace;
2193
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2194
+ return trace(name, fn, {
2195
+ ...options2,
2196
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
2197
+ [TraceAttributes.KIND]: "sdk-operation",
2198
+ [TraceAttributes.VERSION]: VERSION
2199
+ });
2200
+ });
1376
2201
  }
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");
2202
+ async create(a, b, c, d) {
2203
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
2204
+ const ifVersion = parseIfVersion(b, c, d);
2205
+ if (Array.isArray(a)) {
2206
+ if (a.length === 0)
2207
+ return [];
2208
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2209
+ const columns = isStringArray(b) ? b : ["*"];
2210
+ const result = await this.read(ids, columns);
2211
+ return result;
2212
+ }
2213
+ if (isString(a) && isObject(b)) {
2214
+ if (a === "")
2215
+ throw new Error("The id can't be empty");
2216
+ const columns = isStringArray(c) ? c : void 0;
2217
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2218
+ }
2219
+ if (isObject(a) && isString(a.id)) {
2220
+ if (a.id === "")
2221
+ throw new Error("The id can't be empty");
2222
+ const columns = isStringArray(b) ? b : void 0;
2223
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2224
+ }
2225
+ if (isObject(a)) {
2226
+ const columns = isStringArray(b) ? b : void 0;
2227
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2228
+ }
2229
+ throw new Error("Invalid arguments for create method");
2230
+ });
1401
2231
  }
1402
2232
  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
2233
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
2234
+ const columns = isStringArray(b) ? b : ["*"];
2235
+ if (Array.isArray(a)) {
2236
+ if (a.length === 0)
2237
+ return [];
2238
+ const ids = a.map((item) => extractId(item));
2239
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
2240
+ const dictionary = finalObjects.reduce((acc, object) => {
2241
+ acc[object.id] = object;
2242
+ return acc;
2243
+ }, {});
2244
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
2245
+ }
2246
+ const id = extractId(a);
2247
+ if (id) {
2248
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2249
+ try {
2250
+ const response = await getRecord({
2251
+ pathParams: {
2252
+ workspace: "{workspaceId}",
2253
+ dbBranchName: "{dbBranch}",
2254
+ region: "{region}",
2255
+ tableName: __privateGet$4(this, _table),
2256
+ recordId: id
2257
+ },
2258
+ queryParams: { columns },
2259
+ ...fetchProps
2260
+ });
2261
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2262
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2263
+ } catch (e) {
2264
+ if (isObject(e) && e.status === 404) {
2265
+ return null;
2266
+ }
2267
+ throw e;
2268
+ }
2269
+ }
2270
+ return null;
2271
+ });
2272
+ }
2273
+ async readOrThrow(a, b) {
2274
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
2275
+ const result = await this.read(a, b);
2276
+ if (Array.isArray(result)) {
2277
+ const missingIds = compact(
2278
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2279
+ );
2280
+ if (missingIds.length > 0) {
2281
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2282
+ }
2283
+ return result;
2284
+ }
2285
+ if (result === null) {
2286
+ const id = extractId(a) ?? "unknown";
2287
+ throw new Error(`Record with id ${id} not found`);
2288
+ }
2289
+ return result;
2290
+ });
2291
+ }
2292
+ async update(a, b, c, d) {
2293
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
2294
+ const ifVersion = parseIfVersion(b, c, d);
2295
+ if (Array.isArray(a)) {
2296
+ if (a.length === 0)
2297
+ return [];
2298
+ const existing = await this.read(a, ["id"]);
2299
+ const updates = a.filter((_item, index) => existing[index] !== null);
2300
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2301
+ ifVersion,
2302
+ upsert: false
1423
2303
  });
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) {
1428
- return null;
2304
+ const columns = isStringArray(b) ? b : ["*"];
2305
+ const result = await this.read(a, columns);
2306
+ return result;
2307
+ }
2308
+ if (isString(a) && isObject(b)) {
2309
+ const columns = isStringArray(c) ? c : void 0;
2310
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2311
+ }
2312
+ if (isObject(a) && isString(a.id)) {
2313
+ const columns = isStringArray(b) ? b : void 0;
2314
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2315
+ }
2316
+ throw new Error("Invalid arguments for update method");
2317
+ });
2318
+ }
2319
+ async updateOrThrow(a, b, c, d) {
2320
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
2321
+ const result = await this.update(a, b, c, d);
2322
+ if (Array.isArray(result)) {
2323
+ const missingIds = compact(
2324
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2325
+ );
2326
+ if (missingIds.length > 0) {
2327
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1429
2328
  }
1430
- throw e;
2329
+ return result;
1431
2330
  }
1432
- }
1433
- return null;
2331
+ if (result === null) {
2332
+ const id = extractId(a) ?? "unknown";
2333
+ throw new Error(`Record with id ${id} not found`);
2334
+ }
2335
+ return result;
2336
+ });
1434
2337
  }
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");
2338
+ async createOrUpdate(a, b, c, d) {
2339
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2340
+ const ifVersion = parseIfVersion(b, c, d);
2341
+ if (Array.isArray(a)) {
2342
+ if (a.length === 0)
2343
+ return [];
2344
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2345
+ ifVersion,
2346
+ upsert: true
2347
+ });
2348
+ const columns = isStringArray(b) ? b : ["*"];
2349
+ const result = await this.read(a, columns);
2350
+ return result;
1441
2351
  }
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");
2352
+ if (isString(a) && isObject(b)) {
2353
+ const columns = isStringArray(c) ? c : void 0;
2354
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1461
2355
  }
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");
2356
+ if (isObject(a) && isString(a.id)) {
2357
+ const columns = isStringArray(c) ? c : void 0;
2358
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1481
2359
  }
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");
2360
+ throw new Error("Invalid arguments for createOrUpdate method");
2361
+ });
2362
+ }
2363
+ async createOrReplace(a, b, c, d) {
2364
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2365
+ const ifVersion = parseIfVersion(b, c, d);
2366
+ if (Array.isArray(a)) {
2367
+ if (a.length === 0)
2368
+ return [];
2369
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2370
+ const columns = isStringArray(b) ? b : ["*"];
2371
+ const result = await this.read(ids, columns);
2372
+ return result;
2373
+ }
2374
+ if (isString(a) && isObject(b)) {
2375
+ const columns = isStringArray(c) ? c : void 0;
2376
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2377
+ }
2378
+ if (isObject(a) && isString(a.id)) {
2379
+ const columns = isStringArray(c) ? c : void 0;
2380
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2381
+ }
2382
+ throw new Error("Invalid arguments for createOrReplace method");
2383
+ });
2384
+ }
2385
+ async delete(a, b) {
2386
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
2387
+ if (Array.isArray(a)) {
2388
+ if (a.length === 0)
2389
+ return [];
2390
+ const ids = a.map((o) => {
2391
+ if (isString(o))
2392
+ return o;
2393
+ if (isString(o.id))
2394
+ return o.id;
2395
+ throw new Error("Invalid arguments for delete method");
2396
+ });
2397
+ const columns = isStringArray(b) ? b : ["*"];
2398
+ const result = await this.read(a, columns);
2399
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2400
+ return result;
2401
+ }
2402
+ if (isString(a)) {
2403
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2404
+ }
2405
+ if (isObject(a) && isString(a.id)) {
2406
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
2407
+ }
2408
+ throw new Error("Invalid arguments for delete method");
2409
+ });
2410
+ }
2411
+ async deleteOrThrow(a, b) {
2412
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
2413
+ const result = await this.delete(a, b);
2414
+ if (Array.isArray(result)) {
2415
+ const missingIds = compact(
2416
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2417
+ );
2418
+ if (missingIds.length > 0) {
2419
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2420
+ }
2421
+ return result;
2422
+ } else if (result === null) {
2423
+ const id = extractId(a) ?? "unknown";
2424
+ throw new Error(`Record with id ${id} not found`);
2425
+ }
2426
+ return result;
2427
+ });
1494
2428
  }
1495
2429
  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
2430
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
2431
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2432
+ const { records } = await searchTable({
2433
+ pathParams: {
2434
+ workspace: "{workspaceId}",
2435
+ dbBranchName: "{dbBranch}",
2436
+ region: "{region}",
2437
+ tableName: __privateGet$4(this, _table)
2438
+ },
2439
+ body: {
2440
+ query,
2441
+ fuzziness: options.fuzziness,
2442
+ prefix: options.prefix,
2443
+ highlight: options.highlight,
2444
+ filter: options.filter,
2445
+ boosters: options.boosters
2446
+ },
2447
+ ...fetchProps
2448
+ });
2449
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2450
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2451
+ });
2452
+ }
2453
+ async aggregate(aggs, filter) {
2454
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2455
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2456
+ const result = await aggregateTable({
2457
+ pathParams: {
2458
+ workspace: "{workspaceId}",
2459
+ dbBranchName: "{dbBranch}",
2460
+ region: "{region}",
2461
+ tableName: __privateGet$4(this, _table)
2462
+ },
2463
+ body: { aggs, filter },
2464
+ ...fetchProps
2465
+ });
2466
+ return result;
1508
2467
  });
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
2468
  }
1512
2469
  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
2470
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
2471
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
2472
+ if (cacheQuery)
2473
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
2474
+ const data = query.getQueryOptions();
2475
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2476
+ const { meta, records: objects } = await queryTable({
2477
+ pathParams: {
2478
+ workspace: "{workspaceId}",
2479
+ dbBranchName: "{dbBranch}",
2480
+ region: "{region}",
2481
+ tableName: __privateGet$4(this, _table)
2482
+ },
2483
+ body: {
2484
+ filter: cleanFilter(data.filter),
2485
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2486
+ page: data.pagination,
2487
+ columns: data.columns ?? ["*"]
2488
+ },
2489
+ fetchOptions: data.fetchOptions,
2490
+ ...fetchProps
2491
+ });
2492
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2493
+ const records = objects.map(
2494
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2495
+ );
2496
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
2497
+ return new Page(query, meta, records);
2498
+ });
2499
+ }
2500
+ async summarizeTable(query, summaries, summariesFilter) {
2501
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2502
+ const data = query.getQueryOptions();
2503
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2504
+ const result = await summarizeTable({
2505
+ pathParams: {
2506
+ workspace: "{workspaceId}",
2507
+ dbBranchName: "{dbBranch}",
2508
+ region: "{region}",
2509
+ tableName: __privateGet$4(this, _table)
2510
+ },
2511
+ body: {
2512
+ filter: cleanFilter(data.filter),
2513
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2514
+ columns: data.columns,
2515
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2516
+ summaries,
2517
+ summariesFilter
2518
+ },
2519
+ ...fetchProps
2520
+ });
2521
+ return result;
1528
2522
  });
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
2523
  }
1534
2524
  }
1535
2525
  _table = new WeakMap();
@@ -1537,6 +2527,7 @@ _getFetchProps = new WeakMap();
1537
2527
  _db = new WeakMap();
1538
2528
  _cache = new WeakMap();
1539
2529
  _schemaTables$2 = new WeakMap();
2530
+ _trace = new WeakMap();
1540
2531
  _insertRecordWithoutId = new WeakSet();
1541
2532
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1542
2533
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1545,6 +2536,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1545
2536
  pathParams: {
1546
2537
  workspace: "{workspaceId}",
1547
2538
  dbBranchName: "{dbBranch}",
2539
+ region: "{region}",
1548
2540
  tableName: __privateGet$4(this, _table)
1549
2541
  },
1550
2542
  queryParams: { columns },
@@ -1552,74 +2544,173 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1552
2544
  ...fetchProps
1553
2545
  });
1554
2546
  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);
2547
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1556
2548
  };
1557
2549
  _insertRecordWithId = new WeakSet();
1558
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
2550
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
1559
2551
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1560
2552
  const record = transformObjectLinks(object);
1561
2553
  const response = await insertRecordWithID({
1562
2554
  pathParams: {
1563
2555
  workspace: "{workspaceId}",
1564
2556
  dbBranchName: "{dbBranch}",
2557
+ region: "{region}",
1565
2558
  tableName: __privateGet$4(this, _table),
1566
2559
  recordId
1567
2560
  },
1568
2561
  body: record,
1569
- queryParams: { createOnly: true, columns },
2562
+ queryParams: { createOnly, columns, ifVersion },
1570
2563
  ...fetchProps
1571
2564
  });
1572
2565
  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);
2566
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1574
2567
  };
1575
- _bulkInsertTableRecords = new WeakSet();
1576
- bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
2568
+ _insertRecords = new WeakSet();
2569
+ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
1577
2570
  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");
2571
+ const chunkedOperations = chunk(
2572
+ objects.map((object) => ({
2573
+ insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2574
+ })),
2575
+ BULK_OPERATION_MAX_SIZE
2576
+ );
2577
+ const ids = [];
2578
+ for (const operations of chunkedOperations) {
2579
+ const { results } = await branchTransaction({
2580
+ pathParams: {
2581
+ workspace: "{workspaceId}",
2582
+ dbBranchName: "{dbBranch}",
2583
+ region: "{region}"
2584
+ },
2585
+ body: { operations },
2586
+ ...fetchProps
2587
+ });
2588
+ for (const result of results) {
2589
+ if (result.operation === "insert") {
2590
+ ids.push(result.id);
2591
+ } else {
2592
+ ids.push(null);
2593
+ }
2594
+ }
1587
2595
  }
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));
2596
+ return ids;
1590
2597
  };
1591
2598
  _updateRecordWithID = new WeakSet();
1592
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2599
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1593
2600
  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);
2601
+ const { id: _id, ...record } = transformObjectLinks(object);
2602
+ try {
2603
+ const response = await updateRecordWithID({
2604
+ pathParams: {
2605
+ workspace: "{workspaceId}",
2606
+ dbBranchName: "{dbBranch}",
2607
+ region: "{region}",
2608
+ tableName: __privateGet$4(this, _table),
2609
+ recordId
2610
+ },
2611
+ queryParams: { columns, ifVersion },
2612
+ body: record,
2613
+ ...fetchProps
2614
+ });
2615
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2616
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2617
+ } catch (e) {
2618
+ if (isObject(e) && e.status === 404) {
2619
+ return null;
2620
+ }
2621
+ throw e;
2622
+ }
2623
+ };
2624
+ _updateRecords = new WeakSet();
2625
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2626
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2627
+ const chunkedOperations = chunk(
2628
+ objects.map(({ id, ...object }) => ({
2629
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2630
+ })),
2631
+ BULK_OPERATION_MAX_SIZE
2632
+ );
2633
+ const ids = [];
2634
+ for (const operations of chunkedOperations) {
2635
+ const { results } = await branchTransaction({
2636
+ pathParams: {
2637
+ workspace: "{workspaceId}",
2638
+ dbBranchName: "{dbBranch}",
2639
+ region: "{region}"
2640
+ },
2641
+ body: { operations },
2642
+ ...fetchProps
2643
+ });
2644
+ for (const result of results) {
2645
+ if (result.operation === "update") {
2646
+ ids.push(result.id);
2647
+ } else {
2648
+ ids.push(null);
2649
+ }
2650
+ }
2651
+ }
2652
+ return ids;
1603
2653
  };
1604
2654
  _upsertRecordWithID = new WeakSet();
1605
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2655
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1606
2656
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1607
2657
  const response = await upsertRecordWithID({
1608
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1609
- queryParams: { columns },
2658
+ pathParams: {
2659
+ workspace: "{workspaceId}",
2660
+ dbBranchName: "{dbBranch}",
2661
+ region: "{region}",
2662
+ tableName: __privateGet$4(this, _table),
2663
+ recordId
2664
+ },
2665
+ queryParams: { columns, ifVersion },
1610
2666
  body: object,
1611
2667
  ...fetchProps
1612
2668
  });
1613
2669
  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);
2670
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1615
2671
  };
1616
2672
  _deleteRecord = new WeakSet();
1617
- deleteRecord_fn = async function(recordId) {
2673
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1618
2674
  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
- });
2675
+ try {
2676
+ const response = await deleteRecord({
2677
+ pathParams: {
2678
+ workspace: "{workspaceId}",
2679
+ dbBranchName: "{dbBranch}",
2680
+ region: "{region}",
2681
+ tableName: __privateGet$4(this, _table),
2682
+ recordId
2683
+ },
2684
+ queryParams: { columns },
2685
+ ...fetchProps
2686
+ });
2687
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2688
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2689
+ } catch (e) {
2690
+ if (isObject(e) && e.status === 404) {
2691
+ return null;
2692
+ }
2693
+ throw e;
2694
+ }
2695
+ };
2696
+ _deleteRecords = new WeakSet();
2697
+ deleteRecords_fn = async function(recordIds) {
2698
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2699
+ const chunkedOperations = chunk(
2700
+ recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2701
+ BULK_OPERATION_MAX_SIZE
2702
+ );
2703
+ for (const operations of chunkedOperations) {
2704
+ await branchTransaction({
2705
+ pathParams: {
2706
+ workspace: "{workspaceId}",
2707
+ dbBranchName: "{dbBranch}",
2708
+ region: "{region}"
2709
+ },
2710
+ body: { operations },
2711
+ ...fetchProps
2712
+ });
2713
+ }
1623
2714
  };
1624
2715
  _setCacheQuery = new WeakSet();
1625
2716
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1643,7 +2734,7 @@ getSchemaTables_fn$1 = async function() {
1643
2734
  return __privateGet$4(this, _schemaTables$2);
1644
2735
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1645
2736
  const { schema } = await getBranchDetails({
1646
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2737
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1647
2738
  ...fetchProps
1648
2739
  });
1649
2740
  __privateSet$4(this, _schemaTables$2, schema.tables);
@@ -1656,7 +2747,7 @@ const transformObjectLinks = (object) => {
1656
2747
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1657
2748
  }, {});
1658
2749
  };
1659
- const initObject = (db, schemaTables, table, object) => {
2750
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1660
2751
  const result = {};
1661
2752
  const { xata, ...rest } = object ?? {};
1662
2753
  Object.assign(result, rest);
@@ -1664,6 +2755,8 @@ const initObject = (db, schemaTables, table, object) => {
1664
2755
  if (!columns)
1665
2756
  console.error(`Table ${table} not found in schema`);
1666
2757
  for (const column of columns ?? []) {
2758
+ if (!isValidColumn(selectedColumns, column))
2759
+ continue;
1667
2760
  const value = result[column.name];
1668
2761
  switch (column.type) {
1669
2762
  case "datetime": {
@@ -1680,17 +2773,42 @@ const initObject = (db, schemaTables, table, object) => {
1680
2773
  if (!linkTable) {
1681
2774
  console.error(`Failed to parse link for field ${column.name}`);
1682
2775
  } else if (isObject(value)) {
1683
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2776
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2777
+ if (item === column.name) {
2778
+ return [...acc, "*"];
2779
+ }
2780
+ if (item.startsWith(`${column.name}.`)) {
2781
+ const [, ...path] = item.split(".");
2782
+ return [...acc, path.join(".")];
2783
+ }
2784
+ return acc;
2785
+ }, []);
2786
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2787
+ } else {
2788
+ result[column.name] = null;
1684
2789
  }
1685
2790
  break;
1686
2791
  }
2792
+ default:
2793
+ result[column.name] = value ?? null;
2794
+ if (column.notNull === true && value === null) {
2795
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2796
+ }
2797
+ break;
1687
2798
  }
1688
2799
  }
1689
2800
  result.read = function(columns2) {
1690
2801
  return db[table].read(result["id"], columns2);
1691
2802
  };
1692
- result.update = function(data, columns2) {
1693
- return db[table].update(result["id"], data, columns2);
2803
+ result.update = function(data, b, c) {
2804
+ const columns2 = isStringArray(b) ? b : ["*"];
2805
+ const ifVersion = parseIfVersion(b, c);
2806
+ return db[table].update(result["id"], data, columns2, { ifVersion });
2807
+ };
2808
+ result.replace = function(data, b, c) {
2809
+ const columns2 = isStringArray(b) ? b : ["*"];
2810
+ const ifVersion = parseIfVersion(b, c);
2811
+ return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
1694
2812
  };
1695
2813
  result.delete = function() {
1696
2814
  return db[table].delete(result["id"]);
@@ -1698,14 +2816,35 @@ const initObject = (db, schemaTables, table, object) => {
1698
2816
  result.getMetadata = function() {
1699
2817
  return xata;
1700
2818
  };
1701
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
2819
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
1702
2820
  Object.defineProperty(result, prop, { enumerable: false });
1703
2821
  }
1704
2822
  Object.freeze(result);
1705
2823
  return result;
1706
2824
  };
1707
- function isResponseWithRecords(value) {
1708
- return isObject(value) && Array.isArray(value.records);
2825
+ function extractId(value) {
2826
+ if (isString(value))
2827
+ return value;
2828
+ if (isObject(value) && isString(value.id))
2829
+ return value.id;
2830
+ return void 0;
2831
+ }
2832
+ function isValidColumn(columns, column) {
2833
+ if (columns.includes("*"))
2834
+ return true;
2835
+ if (column.type === "link") {
2836
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2837
+ return linkColumns.length > 0;
2838
+ }
2839
+ return columns.includes(column.name);
2840
+ }
2841
+ function parseIfVersion(...args) {
2842
+ for (const arg of args) {
2843
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
2844
+ return arg.ifVersion;
2845
+ }
2846
+ }
2847
+ return void 0;
1709
2848
  }
1710
2849
 
1711
2850
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1757,18 +2896,25 @@ class SimpleCache {
1757
2896
  }
1758
2897
  _map = new WeakMap();
1759
2898
 
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 });
2899
+ const greaterThan = (value) => ({ $gt: value });
2900
+ const gt = greaterThan;
2901
+ const greaterThanEquals = (value) => ({ $ge: value });
2902
+ const greaterEquals = greaterThanEquals;
2903
+ const gte = greaterThanEquals;
2904
+ const ge = greaterThanEquals;
2905
+ const lessThan = (value) => ({ $lt: value });
2906
+ const lt = lessThan;
2907
+ const lessThanEquals = (value) => ({ $le: value });
2908
+ const lessEquals = lessThanEquals;
2909
+ const lte = lessThanEquals;
2910
+ const le = lessThanEquals;
1766
2911
  const exists = (column) => ({ $exists: column });
1767
2912
  const notExists = (column) => ({ $notExists: column });
1768
2913
  const startsWith = (value) => ({ $startsWith: value });
1769
2914
  const endsWith = (value) => ({ $endsWith: value });
1770
2915
  const pattern = (value) => ({ $pattern: value });
1771
2916
  const is = (value) => ({ $is: value });
2917
+ const equals = is;
1772
2918
  const isNot = (value) => ({ $isNot: value });
1773
2919
  const contains = (value) => ({ $contains: value });
1774
2920
  const includes = (value) => ({ $includes: value });
@@ -1865,7 +3011,7 @@ class SearchPlugin extends XataPlugin {
1865
3011
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1866
3012
  return records.map((record) => {
1867
3013
  const { table = "orphan" } = record.xata;
1868
- return { table, record: initObject(this.db, schemaTables, table, record) };
3014
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1869
3015
  });
1870
3016
  },
1871
3017
  byTable: async (query, options = {}) => {
@@ -1874,7 +3020,7 @@ class SearchPlugin extends XataPlugin {
1874
3020
  return records.reduce((acc, record) => {
1875
3021
  const { table = "orphan" } = record.xata;
1876
3022
  const items = acc[table] ?? [];
1877
- const item = initObject(this.db, schemaTables, table, record);
3023
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1878
3024
  return { ...acc, [table]: [...items, item] };
1879
3025
  }, {});
1880
3026
  }
@@ -1887,7 +3033,7 @@ search_fn = async function(query, options, getFetchProps) {
1887
3033
  const fetchProps = await getFetchProps();
1888
3034
  const { tables, fuzziness, highlight, prefix } = options ?? {};
1889
3035
  const { records } = await searchBranch({
1890
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
3036
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1891
3037
  body: { tables, query, fuzziness, prefix, highlight },
1892
3038
  ...fetchProps
1893
3039
  });
@@ -1899,7 +3045,7 @@ getSchemaTables_fn = async function(getFetchProps) {
1899
3045
  return __privateGet$1(this, _schemaTables);
1900
3046
  const fetchProps = await getFetchProps();
1901
3047
  const { schema } = await getBranchDetails({
1902
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
3048
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1903
3049
  ...fetchProps
1904
3050
  });
1905
3051
  __privateSet$1(this, _schemaTables, schema.tables);
@@ -1937,15 +3083,19 @@ async function resolveXataBranch(gitBranch, options) {
1937
3083
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1938
3084
  );
1939
3085
  const [protocol, , host, , dbName] = databaseURL.split("/");
1940
- const [workspace] = host.split(".");
3086
+ const urlParts = parseWorkspacesUrlParts(host);
3087
+ if (!urlParts)
3088
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3089
+ const { workspace, region } = urlParts;
1941
3090
  const { fallbackBranch } = getEnvironment();
1942
3091
  const { branch } = await resolveBranch({
1943
3092
  apiKey,
1944
3093
  apiUrl: databaseURL,
1945
3094
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1946
3095
  workspacesApiUrl: `${protocol}//${host}`,
1947
- pathParams: { dbName, workspace },
1948
- queryParams: { gitBranch, fallbackBranch }
3096
+ pathParams: { dbName, workspace, region },
3097
+ queryParams: { gitBranch, fallbackBranch },
3098
+ trace: defaultTrace
1949
3099
  });
1950
3100
  return branch;
1951
3101
  }
@@ -1961,15 +3111,18 @@ async function getDatabaseBranch(branch, options) {
1961
3111
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1962
3112
  );
1963
3113
  const [protocol, , host, , database] = databaseURL.split("/");
1964
- const [workspace] = host.split(".");
1965
- const dbBranchName = `${database}:${branch}`;
3114
+ const urlParts = parseWorkspacesUrlParts(host);
3115
+ if (!urlParts)
3116
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3117
+ const { workspace, region } = urlParts;
1966
3118
  try {
1967
3119
  return await getBranchDetails({
1968
3120
  apiKey,
1969
3121
  apiUrl: databaseURL,
1970
3122
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1971
3123
  workspacesApiUrl: `${protocol}//${host}`,
1972
- pathParams: { dbBranchName, workspace }
3124
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3125
+ trace: defaultTrace
1973
3126
  });
1974
3127
  } catch (err) {
1975
3128
  if (isObject(err) && err.status === 404)
@@ -2021,7 +3174,8 @@ const buildClient = (plugins) => {
2021
3174
  __privateSet(this, _options, safeOptions);
2022
3175
  const pluginOptions = {
2023
3176
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2024
- cache: safeOptions.cache
3177
+ cache: safeOptions.cache,
3178
+ trace: safeOptions.trace
2025
3179
  };
2026
3180
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2027
3181
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2046,16 +3200,27 @@ const buildClient = (plugins) => {
2046
3200
  return { databaseURL, branch };
2047
3201
  }
2048
3202
  }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3203
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3204
+ const isBrowser = typeof window !== "undefined";
3205
+ if (isBrowser && !enableBrowser) {
3206
+ throw new Error(
3207
+ "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."
3208
+ );
3209
+ }
2049
3210
  const fetch = getFetchImplementation(options?.fetch);
2050
3211
  const databaseURL = options?.databaseURL || getDatabaseURL();
2051
3212
  const apiKey = options?.apiKey || getAPIKey();
2052
3213
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3214
+ const trace = options?.trace ?? defaultTrace;
2053
3215
  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");
3216
+ if (!apiKey) {
3217
+ throw new Error("Option apiKey is required");
3218
+ }
3219
+ if (!databaseURL) {
3220
+ throw new Error("Option databaseURL is required");
2056
3221
  }
2057
- return { fetch, databaseURL, apiKey, branch, cache };
2058
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
3222
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
3223
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
2059
3224
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2060
3225
  if (!branchValue)
2061
3226
  throw new Error("Unable to resolve branch value");
@@ -2065,9 +3230,11 @@ const buildClient = (plugins) => {
2065
3230
  apiUrl: "",
2066
3231
  workspacesApiUrl: (path, params) => {
2067
3232
  const hasBranch = params.dbBranchName ?? params.branch;
2068
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
3233
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2069
3234
  return databaseURL + newPath;
2070
- }
3235
+ },
3236
+ trace,
3237
+ clientID
2071
3238
  };
2072
3239
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2073
3240
  if (__privateGet(this, _branch))
@@ -2201,16 +3368,28 @@ exports.XataPlugin = XataPlugin;
2201
3368
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2202
3369
  exports.addGitBranchesEntry = addGitBranchesEntry;
2203
3370
  exports.addTableColumn = addTableColumn;
3371
+ exports.aggregateTable = aggregateTable;
3372
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3373
+ exports.branchTransaction = branchTransaction;
2204
3374
  exports.buildClient = buildClient;
2205
3375
  exports.buildWorkerRunner = buildWorkerRunner;
2206
3376
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2207
3377
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
3378
+ exports.compareBranchSchemas = compareBranchSchemas;
3379
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3380
+ exports.compareMigrationRequest = compareMigrationRequest;
2208
3381
  exports.contains = contains;
2209
3382
  exports.createBranch = createBranch;
2210
3383
  exports.createDatabase = createDatabase;
3384
+ exports.createMigrationRequest = createMigrationRequest;
2211
3385
  exports.createTable = createTable;
2212
3386
  exports.createUserAPIKey = createUserAPIKey;
2213
3387
  exports.createWorkspace = createWorkspace;
3388
+ exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
3389
+ exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
3390
+ exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
3391
+ exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
3392
+ exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
2214
3393
  exports.deleteBranch = deleteBranch;
2215
3394
  exports.deleteColumn = deleteColumn;
2216
3395
  exports.deleteDatabase = deleteDatabase;
@@ -2221,6 +3400,7 @@ exports.deleteUserAPIKey = deleteUserAPIKey;
2221
3400
  exports.deleteWorkspace = deleteWorkspace;
2222
3401
  exports.deserialize = deserialize;
2223
3402
  exports.endsWith = endsWith;
3403
+ exports.equals = equals;
2224
3404
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2225
3405
  exports.exists = exists;
2226
3406
  exports.ge = ge;
@@ -2230,6 +3410,7 @@ exports.getBranchList = getBranchList;
2230
3410
  exports.getBranchMetadata = getBranchMetadata;
2231
3411
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2232
3412
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
3413
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2233
3414
  exports.getBranchStats = getBranchStats;
2234
3415
  exports.getColumn = getColumn;
2235
3416
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
@@ -2238,6 +3419,9 @@ exports.getDatabaseList = getDatabaseList;
2238
3419
  exports.getDatabaseMetadata = getDatabaseMetadata;
2239
3420
  exports.getDatabaseURL = getDatabaseURL;
2240
3421
  exports.getGitBranchesMapping = getGitBranchesMapping;
3422
+ exports.getHostUrl = getHostUrl;
3423
+ exports.getMigrationRequest = getMigrationRequest;
3424
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2241
3425
  exports.getRecord = getRecord;
2242
3426
  exports.getTableColumns = getTableColumns;
2243
3427
  exports.getTableSchema = getTableSchema;
@@ -2246,6 +3430,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2246
3430
  exports.getWorkspace = getWorkspace;
2247
3431
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2248
3432
  exports.getWorkspacesList = getWorkspacesList;
3433
+ exports.greaterEquals = greaterEquals;
3434
+ exports.greaterThan = greaterThan;
3435
+ exports.greaterThanEquals = greaterThanEquals;
2249
3436
  exports.gt = gt;
2250
3437
  exports.gte = gte;
2251
3438
  exports.includes = includes;
@@ -2257,15 +3444,27 @@ exports.insertRecordWithID = insertRecordWithID;
2257
3444
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2258
3445
  exports.is = is;
2259
3446
  exports.isCursorPaginationOptions = isCursorPaginationOptions;
3447
+ exports.isHostProviderAlias = isHostProviderAlias;
3448
+ exports.isHostProviderBuilder = isHostProviderBuilder;
2260
3449
  exports.isIdentifiable = isIdentifiable;
2261
3450
  exports.isNot = isNot;
2262
3451
  exports.isXataRecord = isXataRecord;
2263
3452
  exports.le = le;
3453
+ exports.lessEquals = lessEquals;
3454
+ exports.lessThan = lessThan;
3455
+ exports.lessThanEquals = lessThanEquals;
3456
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3457
+ exports.listRegions = listRegions;
2264
3458
  exports.lt = lt;
2265
3459
  exports.lte = lte;
3460
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2266
3461
  exports.notExists = notExists;
2267
3462
  exports.operationsByTag = operationsByTag;
3463
+ exports.parseProviderString = parseProviderString;
3464
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
2268
3465
  exports.pattern = pattern;
3466
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3467
+ exports.queryMigrationRequests = queryMigrationRequests;
2269
3468
  exports.queryTable = queryTable;
2270
3469
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2271
3470
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2276,8 +3475,12 @@ exports.searchTable = searchTable;
2276
3475
  exports.serialize = serialize;
2277
3476
  exports.setTableSchema = setTableSchema;
2278
3477
  exports.startsWith = startsWith;
3478
+ exports.summarizeTable = summarizeTable;
2279
3479
  exports.updateBranchMetadata = updateBranchMetadata;
3480
+ exports.updateBranchSchema = updateBranchSchema;
2280
3481
  exports.updateColumn = updateColumn;
3482
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
3483
+ exports.updateMigrationRequest = updateMigrationRequest;
2281
3484
  exports.updateRecordWithID = updateRecordWithID;
2282
3485
  exports.updateTable = updateTable;
2283
3486
  exports.updateUser = updateUser;