@xata.io/client 0.0.0-alpha.vfef462e → 0.0.0-alpha.vff4bc47

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,17 @@ 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
+ }
49
65
 
50
66
  function getEnvironment() {
51
67
  try {
@@ -80,6 +96,25 @@ function getEnvironment() {
80
96
  fallbackBranch: getGlobalFallbackBranch()
81
97
  };
82
98
  }
99
+ function getEnableBrowserVariable() {
100
+ try {
101
+ if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
102
+ return process.env.XATA_ENABLE_BROWSER === "true";
103
+ }
104
+ } catch (err) {
105
+ }
106
+ try {
107
+ if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
108
+ return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
109
+ }
110
+ } catch (err) {
111
+ }
112
+ try {
113
+ return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
114
+ } catch (err) {
115
+ return void 0;
116
+ }
117
+ }
83
118
  function getGlobalApiKey() {
84
119
  try {
85
120
  return XATA_API_KEY;
@@ -117,7 +152,7 @@ async function getGitBranch() {
117
152
  if (typeof require === "function") {
118
153
  return require(nodeModule).execSync(fullCmd, execOptions).trim();
119
154
  }
120
- const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
155
+ const { execSync } = await import(nodeModule);
121
156
  return execSync(fullCmd, execOptions).toString().trim();
122
157
  } catch (err) {
123
158
  }
@@ -144,13 +179,13 @@ function getFetchImplementation(userFetch) {
144
179
  const fetchImpl = userFetch ?? globalFetch;
145
180
  if (!fetchImpl) {
146
181
  throw new Error(
147
- `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
182
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
148
183
  );
149
184
  }
150
185
  return fetchImpl;
151
186
  }
152
187
 
153
- const VERSION = "0.0.0-alpha.vfef462e";
188
+ const VERSION = "0.0.0-alpha.vff4bc47";
154
189
 
155
190
  class ErrorWithCause extends Error {
156
191
  constructor(message, options) {
@@ -201,18 +236,24 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
201
236
  }, {});
202
237
  const query = new URLSearchParams(cleanQueryParams).toString();
203
238
  const queryString = query.length > 0 ? `?${query}` : "";
204
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
239
+ const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
240
+ return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
241
+ }, {});
242
+ return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
205
243
  };
206
244
  function buildBaseUrl({
245
+ endpoint,
207
246
  path,
208
247
  workspacesApiUrl,
209
248
  apiUrl,
210
- pathParams
249
+ pathParams = {}
211
250
  }) {
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);
251
+ if (endpoint === "dataPlane") {
252
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
253
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
254
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
255
+ }
256
+ return `${apiUrl}${path}`;
216
257
  }
217
258
  function hostHeader(url) {
218
259
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -228,271 +269,231 @@ async function fetch$1({
228
269
  queryParams,
229
270
  fetchImpl,
230
271
  apiKey,
272
+ endpoint,
231
273
  apiUrl,
232
- workspacesApiUrl
274
+ workspacesApiUrl,
275
+ trace,
276
+ signal,
277
+ clientID,
278
+ sessionID,
279
+ fetchOptions = {}
233
280
  }) {
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;
281
+ return trace(
282
+ `${method.toUpperCase()} ${path}`,
283
+ async ({ setAttributes }) => {
284
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
285
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
286
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
287
+ setAttributes({
288
+ [TraceAttributes.HTTP_URL]: url,
289
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
290
+ });
291
+ const response = await fetchImpl(url, {
292
+ ...fetchOptions,
293
+ method: method.toUpperCase(),
294
+ body: body ? JSON.stringify(body) : void 0,
295
+ headers: {
296
+ "Content-Type": "application/json",
297
+ "User-Agent": `Xata client-ts/${VERSION}`,
298
+ "X-Xata-Client-ID": clientID ?? "",
299
+ "X-Xata-Session-ID": sessionID ?? "",
300
+ ...headers,
301
+ ...hostHeader(fullUrl),
302
+ Authorization: `Bearer ${apiKey}`
303
+ },
304
+ signal
305
+ });
306
+ if (response.status === 204) {
307
+ return {};
308
+ }
309
+ const { host, protocol } = parseUrl(response.url);
310
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
311
+ setAttributes({
312
+ [TraceAttributes.KIND]: "http",
313
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
314
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
315
+ [TraceAttributes.HTTP_HOST]: host,
316
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
317
+ });
318
+ try {
319
+ const jsonResponse = await response.json();
320
+ if (response.ok) {
321
+ return jsonResponse;
322
+ }
323
+ throw new FetcherError(response.status, jsonResponse, requestId);
324
+ } catch (error) {
325
+ throw new FetcherError(response.status, error, requestId);
326
+ }
327
+ },
328
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
329
+ );
330
+ }
331
+ function parseUrl(url) {
252
332
  try {
253
- const jsonResponse = await response.json();
254
- if (response.ok) {
255
- return jsonResponse;
256
- }
257
- throw new FetcherError(response.status, jsonResponse, requestId);
333
+ const { host, protocol } = new URL(url);
334
+ return { host, protocol };
258
335
  } catch (error) {
259
- throw new FetcherError(response.status, error, requestId);
336
+ return {};
260
337
  }
261
338
  }
262
339
 
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({
340
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
341
+
342
+ const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
343
+ const getBranchList = (variables, signal) => dataPlaneFetch({
350
344
  url: "/dbs/{dbName}",
351
- method: "delete",
352
- ...variables
353
- });
354
- const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
355
- const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
356
- const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
357
- const resolveBranch = (variables) => fetch$1({
358
- url: "/dbs/{dbName}/resolveBranch",
359
345
  method: "get",
360
- ...variables
346
+ ...variables,
347
+ signal
361
348
  });
362
- const getBranchDetails = (variables) => fetch$1({
349
+ const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
350
+ const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
351
+ const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
352
+ const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
353
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
363
354
  url: "/db/{dbBranchName}",
364
355
  method: "get",
365
- ...variables
356
+ ...variables,
357
+ signal
366
358
  });
367
- const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
368
- const deleteBranch = (variables) => fetch$1({
359
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
360
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
369
361
  url: "/db/{dbBranchName}",
370
362
  method: "delete",
371
- ...variables
363
+ ...variables,
364
+ signal
372
365
  });
373
- const updateBranchMetadata = (variables) => fetch$1({
366
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
374
367
  url: "/db/{dbBranchName}/metadata",
375
368
  method: "put",
376
- ...variables
369
+ ...variables,
370
+ signal
377
371
  });
378
- const getBranchMetadata = (variables) => fetch$1({
372
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
379
373
  url: "/db/{dbBranchName}/metadata",
380
374
  method: "get",
381
- ...variables
375
+ ...variables,
376
+ signal
382
377
  });
383
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
384
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
385
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
386
- const getBranchStats = (variables) => fetch$1({
378
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
387
379
  url: "/db/{dbBranchName}/stats",
388
380
  method: "get",
389
- ...variables
381
+ ...variables,
382
+ signal
383
+ });
384
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
385
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
386
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
387
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
388
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
389
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
390
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
391
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
392
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
393
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
394
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
395
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
396
+ method: "get",
397
+ ...variables,
398
+ signal
390
399
  });
391
- const createTable = (variables) => fetch$1({
400
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
401
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
402
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
403
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
404
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
405
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
406
+ method: "post",
407
+ ...variables,
408
+ signal
409
+ });
410
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
411
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
412
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
413
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
414
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
415
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
416
+ const createTable = (variables, signal) => dataPlaneFetch({
392
417
  url: "/db/{dbBranchName}/tables/{tableName}",
393
418
  method: "put",
394
- ...variables
419
+ ...variables,
420
+ signal
395
421
  });
396
- const deleteTable = (variables) => fetch$1({
422
+ const deleteTable = (variables, signal) => dataPlaneFetch({
397
423
  url: "/db/{dbBranchName}/tables/{tableName}",
398
424
  method: "delete",
399
- ...variables
400
- });
401
- const updateTable = (variables) => fetch$1({
402
- url: "/db/{dbBranchName}/tables/{tableName}",
403
- method: "patch",
404
- ...variables
425
+ ...variables,
426
+ signal
405
427
  });
406
- const getTableSchema = (variables) => fetch$1({
428
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
429
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
407
430
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
408
431
  method: "get",
409
- ...variables
410
- });
411
- const setTableSchema = (variables) => fetch$1({
412
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
413
- method: "put",
414
- ...variables
432
+ ...variables,
433
+ signal
415
434
  });
416
- const getTableColumns = (variables) => fetch$1({
435
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
436
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
417
437
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
418
438
  method: "get",
419
- ...variables
420
- });
421
- const addTableColumn = (variables) => fetch$1({
422
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
423
- method: "post",
424
- ...variables
439
+ ...variables,
440
+ signal
425
441
  });
426
- const getColumn = (variables) => fetch$1({
442
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
443
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
444
+ );
445
+ const getColumn = (variables, signal) => dataPlaneFetch({
427
446
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
428
447
  method: "get",
429
- ...variables
448
+ ...variables,
449
+ signal
430
450
  });
431
- const deleteColumn = (variables) => fetch$1({
451
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
452
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
432
453
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
433
454
  method: "delete",
434
- ...variables
435
- });
436
- const updateColumn = (variables) => fetch$1({
437
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
438
- method: "patch",
439
- ...variables
455
+ ...variables,
456
+ signal
440
457
  });
441
- const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
442
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
443
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
444
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
445
- const deleteRecord = (variables) => fetch$1({
446
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
447
- method: "delete",
448
- ...variables
449
- });
450
- const getRecord = (variables) => fetch$1({
458
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
459
+ const getRecord = (variables, signal) => dataPlaneFetch({
451
460
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
452
461
  method: "get",
453
- ...variables
462
+ ...variables,
463
+ signal
454
464
  });
455
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
456
- const queryTable = (variables) => fetch$1({
465
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
466
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
467
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
468
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
469
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
470
+ const queryTable = (variables, signal) => dataPlaneFetch({
457
471
  url: "/db/{dbBranchName}/tables/{tableName}/query",
458
472
  method: "post",
459
- ...variables
473
+ ...variables,
474
+ signal
460
475
  });
461
- const searchTable = (variables) => fetch$1({
462
- url: "/db/{dbBranchName}/tables/{tableName}/search",
476
+ const searchBranch = (variables, signal) => dataPlaneFetch({
477
+ url: "/db/{dbBranchName}/search",
463
478
  method: "post",
464
- ...variables
479
+ ...variables,
480
+ signal
465
481
  });
466
- const searchBranch = (variables) => fetch$1({
467
- url: "/db/{dbBranchName}/search",
482
+ const searchTable = (variables, signal) => dataPlaneFetch({
483
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
468
484
  method: "post",
469
- ...variables
485
+ ...variables,
486
+ signal
470
487
  });
471
- const operationsByTag = {
472
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
473
- workspaces: {
474
- createWorkspace,
475
- getWorkspacesList,
476
- getWorkspace,
477
- updateWorkspace,
478
- deleteWorkspace,
479
- getWorkspaceMembersList,
480
- updateWorkspaceMemberRole,
481
- removeWorkspaceMember,
482
- inviteWorkspaceMember,
483
- updateWorkspaceMemberInvite,
484
- cancelWorkspaceMemberInvite,
485
- resendWorkspaceMemberInvite,
486
- acceptWorkspaceMemberInvite
487
- },
488
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
489
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
490
+ const operationsByTag$2 = {
488
491
  database: {
489
- getDatabaseList,
490
- createDatabase,
491
- deleteDatabase,
492
- getGitBranchesMapping,
493
- addGitBranchesEntry,
494
- removeGitBranchesEntry,
495
- resolveBranch
492
+ dEPRECATEDgetDatabaseList,
493
+ dEPRECATEDcreateDatabase,
494
+ dEPRECATEDdeleteDatabase,
495
+ dEPRECATEDgetDatabaseMetadata,
496
+ dEPRECATEDupdateDatabaseMetadata
496
497
  },
497
498
  branch: {
498
499
  getBranchList,
@@ -501,10 +502,42 @@ const operationsByTag = {
501
502
  deleteBranch,
502
503
  updateBranchMetadata,
503
504
  getBranchMetadata,
505
+ getBranchStats,
506
+ getGitBranchesMapping,
507
+ addGitBranchesEntry,
508
+ removeGitBranchesEntry,
509
+ resolveBranch
510
+ },
511
+ migrations: {
504
512
  getBranchMigrationHistory,
505
- executeBranchMigrationPlan,
506
513
  getBranchMigrationPlan,
507
- getBranchStats
514
+ executeBranchMigrationPlan,
515
+ getBranchSchemaHistory,
516
+ compareBranchWithUserSchema,
517
+ compareBranchSchemas,
518
+ updateBranchSchema,
519
+ previewBranchSchemaEdit,
520
+ applyBranchSchemaEdit
521
+ },
522
+ records: {
523
+ branchTransaction,
524
+ insertRecord,
525
+ getRecord,
526
+ insertRecordWithID,
527
+ updateRecordWithID,
528
+ upsertRecordWithID,
529
+ deleteRecord,
530
+ bulkInsertTableRecords
531
+ },
532
+ migrationRequests: {
533
+ queryMigrationRequests,
534
+ createMigrationRequest,
535
+ getMigrationRequest,
536
+ updateMigrationRequest,
537
+ listMigrationRequestsCommits,
538
+ compareMigrationRequest,
539
+ getMigrationRequestIsMerged,
540
+ mergeMigrationRequest
508
541
  },
509
542
  table: {
510
543
  createTable,
@@ -515,27 +548,150 @@ const operationsByTag = {
515
548
  getTableColumns,
516
549
  addTableColumn,
517
550
  getColumn,
518
- deleteColumn,
519
- updateColumn
551
+ updateColumn,
552
+ deleteColumn
520
553
  },
521
- records: {
522
- insertRecord,
523
- insertRecordWithID,
524
- updateRecordWithID,
525
- upsertRecordWithID,
526
- deleteRecord,
527
- getRecord,
528
- bulkInsertTableRecords,
529
- queryTable,
530
- searchTable,
531
- searchBranch
554
+ searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
555
+ };
556
+
557
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
558
+
559
+ const getUser = (variables, signal) => controlPlaneFetch({
560
+ url: "/user",
561
+ method: "get",
562
+ ...variables,
563
+ signal
564
+ });
565
+ const updateUser = (variables, signal) => controlPlaneFetch({
566
+ url: "/user",
567
+ method: "put",
568
+ ...variables,
569
+ signal
570
+ });
571
+ const deleteUser = (variables, signal) => controlPlaneFetch({
572
+ url: "/user",
573
+ method: "delete",
574
+ ...variables,
575
+ signal
576
+ });
577
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
578
+ url: "/user/keys",
579
+ method: "get",
580
+ ...variables,
581
+ signal
582
+ });
583
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
584
+ url: "/user/keys/{keyName}",
585
+ method: "post",
586
+ ...variables,
587
+ signal
588
+ });
589
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
590
+ url: "/user/keys/{keyName}",
591
+ method: "delete",
592
+ ...variables,
593
+ signal
594
+ });
595
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
596
+ url: "/workspaces",
597
+ method: "get",
598
+ ...variables,
599
+ signal
600
+ });
601
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
602
+ url: "/workspaces",
603
+ method: "post",
604
+ ...variables,
605
+ signal
606
+ });
607
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
608
+ url: "/workspaces/{workspaceId}",
609
+ method: "get",
610
+ ...variables,
611
+ signal
612
+ });
613
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
614
+ url: "/workspaces/{workspaceId}",
615
+ method: "put",
616
+ ...variables,
617
+ signal
618
+ });
619
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
620
+ url: "/workspaces/{workspaceId}",
621
+ method: "delete",
622
+ ...variables,
623
+ signal
624
+ });
625
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
626
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
627
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
628
+ url: "/workspaces/{workspaceId}/members/{userId}",
629
+ method: "delete",
630
+ ...variables,
631
+ signal
632
+ });
633
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
634
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
635
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
636
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
637
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
638
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
639
+ url: "/workspaces/{workspaceId}/dbs",
640
+ method: "get",
641
+ ...variables,
642
+ signal
643
+ });
644
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
645
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
646
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
647
+ method: "delete",
648
+ ...variables,
649
+ signal
650
+ });
651
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
652
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
653
+ const listRegions = (variables, signal) => controlPlaneFetch({
654
+ url: "/workspaces/{workspaceId}/regions",
655
+ method: "get",
656
+ ...variables,
657
+ signal
658
+ });
659
+ const operationsByTag$1 = {
660
+ users: { getUser, updateUser, deleteUser },
661
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
662
+ workspaces: {
663
+ getWorkspacesList,
664
+ createWorkspace,
665
+ getWorkspace,
666
+ updateWorkspace,
667
+ deleteWorkspace,
668
+ getWorkspaceMembersList,
669
+ updateWorkspaceMemberRole,
670
+ removeWorkspaceMember
671
+ },
672
+ invites: {
673
+ inviteWorkspaceMember,
674
+ updateWorkspaceMemberInvite,
675
+ cancelWorkspaceMemberInvite,
676
+ acceptWorkspaceMemberInvite,
677
+ resendWorkspaceMemberInvite
678
+ },
679
+ databases: {
680
+ getDatabaseList,
681
+ createDatabase,
682
+ deleteDatabase,
683
+ getDatabaseMetadata,
684
+ updateDatabaseMetadata,
685
+ listRegions
532
686
  }
533
687
  };
534
688
 
689
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
690
+
535
691
  function getHostUrl(provider, type) {
536
- if (isValidAlias(provider)) {
692
+ if (isHostProviderAlias(provider)) {
537
693
  return providers[provider][type];
538
- } else if (isValidBuilder(provider)) {
694
+ } else if (isHostProviderBuilder(provider)) {
539
695
  return provider[type];
540
696
  }
541
697
  throw new Error("Invalid API provider");
@@ -543,19 +699,38 @@ function getHostUrl(provider, type) {
543
699
  const providers = {
544
700
  production: {
545
701
  main: "https://api.xata.io",
546
- workspaces: "https://{workspaceId}.xata.sh"
702
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
547
703
  },
548
704
  staging: {
549
705
  main: "https://staging.xatabase.co",
550
- workspaces: "https://{workspaceId}.staging.xatabase.co"
706
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
551
707
  }
552
708
  };
553
- function isValidAlias(alias) {
709
+ function isHostProviderAlias(alias) {
554
710
  return isString(alias) && Object.keys(providers).includes(alias);
555
711
  }
556
- function isValidBuilder(builder) {
712
+ function isHostProviderBuilder(builder) {
557
713
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
558
714
  }
715
+ function parseProviderString(provider = "production") {
716
+ if (isHostProviderAlias(provider)) {
717
+ return provider;
718
+ }
719
+ const [main, workspaces] = provider.split(",");
720
+ if (!main || !workspaces)
721
+ return null;
722
+ return { main, workspaces };
723
+ }
724
+ function parseWorkspacesUrlParts(url) {
725
+ if (!isString(url))
726
+ return null;
727
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
728
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
729
+ const match = url.match(regex) || url.match(regexStaging);
730
+ if (!match)
731
+ return null;
732
+ return { workspace: match[1], region: match[2] ?? "eu-west-1" };
733
+ }
559
734
 
560
735
  var __accessCheck$7 = (obj, member, msg) => {
561
736
  if (!member.has(obj))
@@ -581,7 +756,8 @@ class XataApiClient {
581
756
  __privateAdd$7(this, _extraProps, void 0);
582
757
  __privateAdd$7(this, _namespaces, {});
583
758
  const provider = options.host ?? "production";
584
- const apiKey = options?.apiKey ?? getAPIKey();
759
+ const apiKey = options.apiKey ?? getAPIKey();
760
+ const trace = options.trace ?? defaultTrace;
585
761
  if (!apiKey) {
586
762
  throw new Error("Could not resolve a valid apiKey");
587
763
  }
@@ -589,7 +765,8 @@ class XataApiClient {
589
765
  apiUrl: getHostUrl(provider, "main"),
590
766
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
591
767
  fetchImpl: getFetchImplementation(options.fetch),
592
- apiKey
768
+ apiKey,
769
+ trace
593
770
  });
594
771
  }
595
772
  get user() {
@@ -597,21 +774,41 @@ class XataApiClient {
597
774
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
598
775
  return __privateGet$7(this, _namespaces).user;
599
776
  }
777
+ get authentication() {
778
+ if (!__privateGet$7(this, _namespaces).authentication)
779
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
780
+ return __privateGet$7(this, _namespaces).authentication;
781
+ }
600
782
  get workspaces() {
601
783
  if (!__privateGet$7(this, _namespaces).workspaces)
602
784
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
603
785
  return __privateGet$7(this, _namespaces).workspaces;
604
786
  }
605
- get databases() {
606
- if (!__privateGet$7(this, _namespaces).databases)
607
- __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
608
- return __privateGet$7(this, _namespaces).databases;
787
+ get invites() {
788
+ if (!__privateGet$7(this, _namespaces).invites)
789
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
790
+ return __privateGet$7(this, _namespaces).invites;
791
+ }
792
+ get database() {
793
+ if (!__privateGet$7(this, _namespaces).database)
794
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
795
+ return __privateGet$7(this, _namespaces).database;
609
796
  }
610
797
  get branches() {
611
798
  if (!__privateGet$7(this, _namespaces).branches)
612
799
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
613
800
  return __privateGet$7(this, _namespaces).branches;
614
801
  }
802
+ get migrations() {
803
+ if (!__privateGet$7(this, _namespaces).migrations)
804
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
805
+ return __privateGet$7(this, _namespaces).migrations;
806
+ }
807
+ get migrationRequests() {
808
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
809
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
810
+ return __privateGet$7(this, _namespaces).migrationRequests;
811
+ }
615
812
  get tables() {
616
813
  if (!__privateGet$7(this, _namespaces).tables)
617
814
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -622,6 +819,11 @@ class XataApiClient {
622
819
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
623
820
  return __privateGet$7(this, _namespaces).records;
624
821
  }
822
+ get searchAndFilter() {
823
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
824
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
825
+ return __privateGet$7(this, _namespaces).searchAndFilter;
826
+ }
625
827
  }
626
828
  _extraProps = new WeakMap();
627
829
  _namespaces = new WeakMap();
@@ -632,24 +834,29 @@ class UserApi {
632
834
  getUser() {
633
835
  return operationsByTag.users.getUser({ ...this.extraProps });
634
836
  }
635
- updateUser(user) {
837
+ updateUser({ user }) {
636
838
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
637
839
  }
638
840
  deleteUser() {
639
841
  return operationsByTag.users.deleteUser({ ...this.extraProps });
640
842
  }
843
+ }
844
+ class AuthenticationApi {
845
+ constructor(extraProps) {
846
+ this.extraProps = extraProps;
847
+ }
641
848
  getUserAPIKeys() {
642
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
849
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
643
850
  }
644
- createUserAPIKey(keyName) {
645
- return operationsByTag.users.createUserAPIKey({
646
- pathParams: { keyName },
851
+ createUserAPIKey({ name }) {
852
+ return operationsByTag.authentication.createUserAPIKey({
853
+ pathParams: { keyName: name },
647
854
  ...this.extraProps
648
855
  });
649
856
  }
650
- deleteUserAPIKey(keyName) {
651
- return operationsByTag.users.deleteUserAPIKey({
652
- pathParams: { keyName },
857
+ deleteUserAPIKey({ name }) {
858
+ return operationsByTag.authentication.deleteUserAPIKey({
859
+ pathParams: { keyName: name },
653
860
  ...this.extraProps
654
861
  });
655
862
  }
@@ -658,353 +865,897 @@ class WorkspaceApi {
658
865
  constructor(extraProps) {
659
866
  this.extraProps = extraProps;
660
867
  }
661
- createWorkspace(workspaceMeta) {
868
+ getWorkspacesList() {
869
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
870
+ }
871
+ createWorkspace({ data }) {
662
872
  return operationsByTag.workspaces.createWorkspace({
663
- body: workspaceMeta,
873
+ body: data,
664
874
  ...this.extraProps
665
875
  });
666
876
  }
667
- getWorkspacesList() {
668
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
669
- }
670
- getWorkspace(workspaceId) {
877
+ getWorkspace({ workspace }) {
671
878
  return operationsByTag.workspaces.getWorkspace({
672
- pathParams: { workspaceId },
879
+ pathParams: { workspaceId: workspace },
673
880
  ...this.extraProps
674
881
  });
675
882
  }
676
- updateWorkspace(workspaceId, workspaceMeta) {
883
+ updateWorkspace({
884
+ workspace,
885
+ update
886
+ }) {
677
887
  return operationsByTag.workspaces.updateWorkspace({
678
- pathParams: { workspaceId },
679
- body: workspaceMeta,
888
+ pathParams: { workspaceId: workspace },
889
+ body: update,
680
890
  ...this.extraProps
681
891
  });
682
892
  }
683
- deleteWorkspace(workspaceId) {
893
+ deleteWorkspace({ workspace }) {
684
894
  return operationsByTag.workspaces.deleteWorkspace({
685
- pathParams: { workspaceId },
895
+ pathParams: { workspaceId: workspace },
686
896
  ...this.extraProps
687
897
  });
688
898
  }
689
- getWorkspaceMembersList(workspaceId) {
899
+ getWorkspaceMembersList({ workspace }) {
690
900
  return operationsByTag.workspaces.getWorkspaceMembersList({
691
- pathParams: { workspaceId },
901
+ pathParams: { workspaceId: workspace },
692
902
  ...this.extraProps
693
903
  });
694
904
  }
695
- updateWorkspaceMemberRole(workspaceId, userId, role) {
905
+ updateWorkspaceMemberRole({
906
+ workspace,
907
+ user,
908
+ role
909
+ }) {
696
910
  return operationsByTag.workspaces.updateWorkspaceMemberRole({
697
- pathParams: { workspaceId, userId },
911
+ pathParams: { workspaceId: workspace, userId: user },
698
912
  body: { role },
699
913
  ...this.extraProps
700
914
  });
701
915
  }
702
- removeWorkspaceMember(workspaceId, userId) {
916
+ removeWorkspaceMember({
917
+ workspace,
918
+ user
919
+ }) {
703
920
  return operationsByTag.workspaces.removeWorkspaceMember({
704
- pathParams: { workspaceId, userId },
921
+ pathParams: { workspaceId: workspace, userId: user },
922
+ ...this.extraProps
923
+ });
924
+ }
925
+ }
926
+ class InvitesApi {
927
+ constructor(extraProps) {
928
+ this.extraProps = extraProps;
929
+ }
930
+ inviteWorkspaceMember({
931
+ workspace,
932
+ email,
933
+ role
934
+ }) {
935
+ return operationsByTag.invites.inviteWorkspaceMember({
936
+ pathParams: { workspaceId: workspace },
937
+ body: { email, role },
938
+ ...this.extraProps
939
+ });
940
+ }
941
+ updateWorkspaceMemberInvite({
942
+ workspace,
943
+ invite,
944
+ role
945
+ }) {
946
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
947
+ pathParams: { workspaceId: workspace, inviteId: invite },
948
+ body: { role },
949
+ ...this.extraProps
950
+ });
951
+ }
952
+ cancelWorkspaceMemberInvite({
953
+ workspace,
954
+ invite
955
+ }) {
956
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
957
+ pathParams: { workspaceId: workspace, inviteId: invite },
958
+ ...this.extraProps
959
+ });
960
+ }
961
+ acceptWorkspaceMemberInvite({
962
+ workspace,
963
+ key
964
+ }) {
965
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
966
+ pathParams: { workspaceId: workspace, inviteKey: key },
967
+ ...this.extraProps
968
+ });
969
+ }
970
+ resendWorkspaceMemberInvite({
971
+ workspace,
972
+ invite
973
+ }) {
974
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
975
+ pathParams: { workspaceId: workspace, inviteId: invite },
976
+ ...this.extraProps
977
+ });
978
+ }
979
+ }
980
+ class BranchApi {
981
+ constructor(extraProps) {
982
+ this.extraProps = extraProps;
983
+ }
984
+ getBranchList({
985
+ workspace,
986
+ region,
987
+ database
988
+ }) {
989
+ return operationsByTag.branch.getBranchList({
990
+ pathParams: { workspace, region, dbName: database },
991
+ ...this.extraProps
992
+ });
993
+ }
994
+ getBranchDetails({
995
+ workspace,
996
+ region,
997
+ database,
998
+ branch
999
+ }) {
1000
+ return operationsByTag.branch.getBranchDetails({
1001
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1002
+ ...this.extraProps
1003
+ });
1004
+ }
1005
+ createBranch({
1006
+ workspace,
1007
+ region,
1008
+ database,
1009
+ branch,
1010
+ from,
1011
+ metadata
1012
+ }) {
1013
+ return operationsByTag.branch.createBranch({
1014
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1015
+ body: { from, metadata },
1016
+ ...this.extraProps
1017
+ });
1018
+ }
1019
+ deleteBranch({
1020
+ workspace,
1021
+ region,
1022
+ database,
1023
+ branch
1024
+ }) {
1025
+ return operationsByTag.branch.deleteBranch({
1026
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1027
+ ...this.extraProps
1028
+ });
1029
+ }
1030
+ updateBranchMetadata({
1031
+ workspace,
1032
+ region,
1033
+ database,
1034
+ branch,
1035
+ metadata
1036
+ }) {
1037
+ return operationsByTag.branch.updateBranchMetadata({
1038
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1039
+ body: metadata,
1040
+ ...this.extraProps
1041
+ });
1042
+ }
1043
+ getBranchMetadata({
1044
+ workspace,
1045
+ region,
1046
+ database,
1047
+ branch
1048
+ }) {
1049
+ return operationsByTag.branch.getBranchMetadata({
1050
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1051
+ ...this.extraProps
1052
+ });
1053
+ }
1054
+ getBranchStats({
1055
+ workspace,
1056
+ region,
1057
+ database,
1058
+ branch
1059
+ }) {
1060
+ return operationsByTag.branch.getBranchStats({
1061
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1062
+ ...this.extraProps
1063
+ });
1064
+ }
1065
+ getGitBranchesMapping({
1066
+ workspace,
1067
+ region,
1068
+ database
1069
+ }) {
1070
+ return operationsByTag.branch.getGitBranchesMapping({
1071
+ pathParams: { workspace, region, dbName: database },
1072
+ ...this.extraProps
1073
+ });
1074
+ }
1075
+ addGitBranchesEntry({
1076
+ workspace,
1077
+ region,
1078
+ database,
1079
+ gitBranch,
1080
+ xataBranch
1081
+ }) {
1082
+ return operationsByTag.branch.addGitBranchesEntry({
1083
+ pathParams: { workspace, region, dbName: database },
1084
+ body: { gitBranch, xataBranch },
1085
+ ...this.extraProps
1086
+ });
1087
+ }
1088
+ removeGitBranchesEntry({
1089
+ workspace,
1090
+ region,
1091
+ database,
1092
+ gitBranch
1093
+ }) {
1094
+ return operationsByTag.branch.removeGitBranchesEntry({
1095
+ pathParams: { workspace, region, dbName: database },
1096
+ queryParams: { gitBranch },
1097
+ ...this.extraProps
1098
+ });
1099
+ }
1100
+ resolveBranch({
1101
+ workspace,
1102
+ region,
1103
+ database,
1104
+ gitBranch,
1105
+ fallbackBranch
1106
+ }) {
1107
+ return operationsByTag.branch.resolveBranch({
1108
+ pathParams: { workspace, region, dbName: database },
1109
+ queryParams: { gitBranch, fallbackBranch },
1110
+ ...this.extraProps
1111
+ });
1112
+ }
1113
+ }
1114
+ class TableApi {
1115
+ constructor(extraProps) {
1116
+ this.extraProps = extraProps;
1117
+ }
1118
+ createTable({
1119
+ workspace,
1120
+ region,
1121
+ database,
1122
+ branch,
1123
+ table
1124
+ }) {
1125
+ return operationsByTag.table.createTable({
1126
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1127
+ ...this.extraProps
1128
+ });
1129
+ }
1130
+ deleteTable({
1131
+ workspace,
1132
+ region,
1133
+ database,
1134
+ branch,
1135
+ table
1136
+ }) {
1137
+ return operationsByTag.table.deleteTable({
1138
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1139
+ ...this.extraProps
1140
+ });
1141
+ }
1142
+ updateTable({
1143
+ workspace,
1144
+ region,
1145
+ database,
1146
+ branch,
1147
+ table,
1148
+ update
1149
+ }) {
1150
+ return operationsByTag.table.updateTable({
1151
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1152
+ body: update,
1153
+ ...this.extraProps
1154
+ });
1155
+ }
1156
+ getTableSchema({
1157
+ workspace,
1158
+ region,
1159
+ database,
1160
+ branch,
1161
+ table
1162
+ }) {
1163
+ return operationsByTag.table.getTableSchema({
1164
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1165
+ ...this.extraProps
1166
+ });
1167
+ }
1168
+ setTableSchema({
1169
+ workspace,
1170
+ region,
1171
+ database,
1172
+ branch,
1173
+ table,
1174
+ schema
1175
+ }) {
1176
+ return operationsByTag.table.setTableSchema({
1177
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1178
+ body: schema,
1179
+ ...this.extraProps
1180
+ });
1181
+ }
1182
+ getTableColumns({
1183
+ workspace,
1184
+ region,
1185
+ database,
1186
+ branch,
1187
+ table
1188
+ }) {
1189
+ return operationsByTag.table.getTableColumns({
1190
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1191
+ ...this.extraProps
1192
+ });
1193
+ }
1194
+ addTableColumn({
1195
+ workspace,
1196
+ region,
1197
+ database,
1198
+ branch,
1199
+ table,
1200
+ column
1201
+ }) {
1202
+ return operationsByTag.table.addTableColumn({
1203
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1204
+ body: column,
1205
+ ...this.extraProps
1206
+ });
1207
+ }
1208
+ getColumn({
1209
+ workspace,
1210
+ region,
1211
+ database,
1212
+ branch,
1213
+ table,
1214
+ column
1215
+ }) {
1216
+ return operationsByTag.table.getColumn({
1217
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1218
+ ...this.extraProps
1219
+ });
1220
+ }
1221
+ updateColumn({
1222
+ workspace,
1223
+ region,
1224
+ database,
1225
+ branch,
1226
+ table,
1227
+ column,
1228
+ update
1229
+ }) {
1230
+ return operationsByTag.table.updateColumn({
1231
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1232
+ body: update,
1233
+ ...this.extraProps
1234
+ });
1235
+ }
1236
+ deleteColumn({
1237
+ workspace,
1238
+ region,
1239
+ database,
1240
+ branch,
1241
+ table,
1242
+ column
1243
+ }) {
1244
+ return operationsByTag.table.deleteColumn({
1245
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1246
+ ...this.extraProps
1247
+ });
1248
+ }
1249
+ }
1250
+ class RecordsApi {
1251
+ constructor(extraProps) {
1252
+ this.extraProps = extraProps;
1253
+ }
1254
+ insertRecord({
1255
+ workspace,
1256
+ region,
1257
+ database,
1258
+ branch,
1259
+ table,
1260
+ record,
1261
+ columns
1262
+ }) {
1263
+ return operationsByTag.records.insertRecord({
1264
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1265
+ queryParams: { columns },
1266
+ body: record,
1267
+ ...this.extraProps
1268
+ });
1269
+ }
1270
+ getRecord({
1271
+ workspace,
1272
+ region,
1273
+ database,
1274
+ branch,
1275
+ table,
1276
+ id,
1277
+ columns
1278
+ }) {
1279
+ return operationsByTag.records.getRecord({
1280
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1281
+ queryParams: { columns },
1282
+ ...this.extraProps
1283
+ });
1284
+ }
1285
+ insertRecordWithID({
1286
+ workspace,
1287
+ region,
1288
+ database,
1289
+ branch,
1290
+ table,
1291
+ id,
1292
+ record,
1293
+ columns,
1294
+ createOnly,
1295
+ ifVersion
1296
+ }) {
1297
+ return operationsByTag.records.insertRecordWithID({
1298
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1299
+ queryParams: { columns, createOnly, ifVersion },
1300
+ body: record,
705
1301
  ...this.extraProps
706
1302
  });
707
1303
  }
708
- inviteWorkspaceMember(workspaceId, email, role) {
709
- return operationsByTag.workspaces.inviteWorkspaceMember({
710
- pathParams: { workspaceId },
711
- body: { email, role },
1304
+ updateRecordWithID({
1305
+ workspace,
1306
+ region,
1307
+ database,
1308
+ branch,
1309
+ table,
1310
+ id,
1311
+ record,
1312
+ columns,
1313
+ ifVersion
1314
+ }) {
1315
+ return operationsByTag.records.updateRecordWithID({
1316
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1317
+ queryParams: { columns, ifVersion },
1318
+ body: record,
712
1319
  ...this.extraProps
713
1320
  });
714
1321
  }
715
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
716
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
717
- pathParams: { workspaceId, inviteId },
718
- body: { role },
1322
+ upsertRecordWithID({
1323
+ workspace,
1324
+ region,
1325
+ database,
1326
+ branch,
1327
+ table,
1328
+ id,
1329
+ record,
1330
+ columns,
1331
+ ifVersion
1332
+ }) {
1333
+ return operationsByTag.records.upsertRecordWithID({
1334
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1335
+ queryParams: { columns, ifVersion },
1336
+ body: record,
719
1337
  ...this.extraProps
720
1338
  });
721
1339
  }
722
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
723
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
724
- pathParams: { workspaceId, inviteId },
1340
+ deleteRecord({
1341
+ workspace,
1342
+ region,
1343
+ database,
1344
+ branch,
1345
+ table,
1346
+ id,
1347
+ columns
1348
+ }) {
1349
+ return operationsByTag.records.deleteRecord({
1350
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1351
+ queryParams: { columns },
725
1352
  ...this.extraProps
726
1353
  });
727
1354
  }
728
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
729
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
730
- pathParams: { workspaceId, inviteId },
1355
+ bulkInsertTableRecords({
1356
+ workspace,
1357
+ region,
1358
+ database,
1359
+ branch,
1360
+ table,
1361
+ records,
1362
+ columns
1363
+ }) {
1364
+ return operationsByTag.records.bulkInsertTableRecords({
1365
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1366
+ queryParams: { columns },
1367
+ body: { records },
731
1368
  ...this.extraProps
732
1369
  });
733
1370
  }
734
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
735
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
736
- pathParams: { workspaceId, inviteKey },
1371
+ branchTransaction({
1372
+ workspace,
1373
+ region,
1374
+ database,
1375
+ branch,
1376
+ operations
1377
+ }) {
1378
+ return operationsByTag.records.branchTransaction({
1379
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1380
+ body: { operations },
737
1381
  ...this.extraProps
738
1382
  });
739
1383
  }
740
1384
  }
741
- class DatabaseApi {
1385
+ class SearchAndFilterApi {
742
1386
  constructor(extraProps) {
743
1387
  this.extraProps = extraProps;
744
1388
  }
745
- getDatabaseList(workspace) {
746
- return operationsByTag.database.getDatabaseList({
747
- pathParams: { workspace },
748
- ...this.extraProps
749
- });
750
- }
751
- createDatabase(workspace, dbName, options = {}) {
752
- return operationsByTag.database.createDatabase({
753
- pathParams: { workspace, dbName },
754
- body: options,
755
- ...this.extraProps
756
- });
757
- }
758
- deleteDatabase(workspace, dbName) {
759
- return operationsByTag.database.deleteDatabase({
760
- pathParams: { workspace, dbName },
1389
+ queryTable({
1390
+ workspace,
1391
+ region,
1392
+ database,
1393
+ branch,
1394
+ table,
1395
+ filter,
1396
+ sort,
1397
+ page,
1398
+ columns,
1399
+ consistency
1400
+ }) {
1401
+ return operationsByTag.searchAndFilter.queryTable({
1402
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1403
+ body: { filter, sort, page, columns, consistency },
761
1404
  ...this.extraProps
762
1405
  });
763
1406
  }
764
- getGitBranchesMapping(workspace, dbName) {
765
- return operationsByTag.database.getGitBranchesMapping({
766
- pathParams: { workspace, dbName },
1407
+ searchTable({
1408
+ workspace,
1409
+ region,
1410
+ database,
1411
+ branch,
1412
+ table,
1413
+ query,
1414
+ fuzziness,
1415
+ target,
1416
+ prefix,
1417
+ filter,
1418
+ highlight,
1419
+ boosters
1420
+ }) {
1421
+ return operationsByTag.searchAndFilter.searchTable({
1422
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1423
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
767
1424
  ...this.extraProps
768
1425
  });
769
1426
  }
770
- addGitBranchesEntry(workspace, dbName, body) {
771
- return operationsByTag.database.addGitBranchesEntry({
772
- pathParams: { workspace, dbName },
773
- body,
1427
+ searchBranch({
1428
+ workspace,
1429
+ region,
1430
+ database,
1431
+ branch,
1432
+ tables,
1433
+ query,
1434
+ fuzziness,
1435
+ prefix,
1436
+ highlight
1437
+ }) {
1438
+ return operationsByTag.searchAndFilter.searchBranch({
1439
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1440
+ body: { tables, query, fuzziness, prefix, highlight },
774
1441
  ...this.extraProps
775
1442
  });
776
1443
  }
777
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
778
- return operationsByTag.database.removeGitBranchesEntry({
779
- pathParams: { workspace, dbName },
780
- queryParams: { gitBranch },
1444
+ summarizeTable({
1445
+ workspace,
1446
+ region,
1447
+ database,
1448
+ branch,
1449
+ table,
1450
+ filter,
1451
+ columns,
1452
+ summaries,
1453
+ sort,
1454
+ summariesFilter,
1455
+ page,
1456
+ consistency
1457
+ }) {
1458
+ return operationsByTag.searchAndFilter.summarizeTable({
1459
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1460
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
781
1461
  ...this.extraProps
782
1462
  });
783
1463
  }
784
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
785
- return operationsByTag.database.resolveBranch({
786
- pathParams: { workspace, dbName },
787
- queryParams: { gitBranch, fallbackBranch },
1464
+ aggregateTable({
1465
+ workspace,
1466
+ region,
1467
+ database,
1468
+ branch,
1469
+ table,
1470
+ filter,
1471
+ aggs
1472
+ }) {
1473
+ return operationsByTag.searchAndFilter.aggregateTable({
1474
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1475
+ body: { filter, aggs },
788
1476
  ...this.extraProps
789
1477
  });
790
1478
  }
791
1479
  }
792
- class BranchApi {
1480
+ class MigrationRequestsApi {
793
1481
  constructor(extraProps) {
794
1482
  this.extraProps = extraProps;
795
1483
  }
796
- getBranchList(workspace, dbName) {
797
- return operationsByTag.branch.getBranchList({
798
- pathParams: { workspace, dbName },
799
- ...this.extraProps
800
- });
801
- }
802
- getBranchDetails(workspace, database, branch) {
803
- return operationsByTag.branch.getBranchDetails({
804
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
805
- ...this.extraProps
806
- });
807
- }
808
- createBranch(workspace, database, branch, from, options = {}) {
809
- return operationsByTag.branch.createBranch({
810
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
811
- queryParams: isString(from) ? { from } : void 0,
812
- body: options,
1484
+ queryMigrationRequests({
1485
+ workspace,
1486
+ region,
1487
+ database,
1488
+ filter,
1489
+ sort,
1490
+ page,
1491
+ columns
1492
+ }) {
1493
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1494
+ pathParams: { workspace, region, dbName: database },
1495
+ body: { filter, sort, page, columns },
813
1496
  ...this.extraProps
814
1497
  });
815
1498
  }
816
- deleteBranch(workspace, database, branch) {
817
- return operationsByTag.branch.deleteBranch({
818
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1499
+ createMigrationRequest({
1500
+ workspace,
1501
+ region,
1502
+ database,
1503
+ migration
1504
+ }) {
1505
+ return operationsByTag.migrationRequests.createMigrationRequest({
1506
+ pathParams: { workspace, region, dbName: database },
1507
+ body: migration,
819
1508
  ...this.extraProps
820
1509
  });
821
1510
  }
822
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
823
- return operationsByTag.branch.updateBranchMetadata({
824
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
825
- body: metadata,
1511
+ getMigrationRequest({
1512
+ workspace,
1513
+ region,
1514
+ database,
1515
+ migrationRequest
1516
+ }) {
1517
+ return operationsByTag.migrationRequests.getMigrationRequest({
1518
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
826
1519
  ...this.extraProps
827
1520
  });
828
1521
  }
829
- getBranchMetadata(workspace, database, branch) {
830
- return operationsByTag.branch.getBranchMetadata({
831
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1522
+ updateMigrationRequest({
1523
+ workspace,
1524
+ region,
1525
+ database,
1526
+ migrationRequest,
1527
+ update
1528
+ }) {
1529
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1530
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1531
+ body: update,
832
1532
  ...this.extraProps
833
1533
  });
834
1534
  }
835
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
836
- return operationsByTag.branch.getBranchMigrationHistory({
837
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
838
- body: options,
1535
+ listMigrationRequestsCommits({
1536
+ workspace,
1537
+ region,
1538
+ database,
1539
+ migrationRequest,
1540
+ page
1541
+ }) {
1542
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1543
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1544
+ body: { page },
839
1545
  ...this.extraProps
840
1546
  });
841
1547
  }
842
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
843
- return operationsByTag.branch.executeBranchMigrationPlan({
844
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
845
- body: migrationPlan,
1548
+ compareMigrationRequest({
1549
+ workspace,
1550
+ region,
1551
+ database,
1552
+ migrationRequest
1553
+ }) {
1554
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1555
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
846
1556
  ...this.extraProps
847
1557
  });
848
1558
  }
849
- getBranchMigrationPlan(workspace, database, branch, schema) {
850
- return operationsByTag.branch.getBranchMigrationPlan({
851
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
852
- body: schema,
1559
+ getMigrationRequestIsMerged({
1560
+ workspace,
1561
+ region,
1562
+ database,
1563
+ migrationRequest
1564
+ }) {
1565
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1566
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
853
1567
  ...this.extraProps
854
1568
  });
855
1569
  }
856
- getBranchStats(workspace, database, branch) {
857
- return operationsByTag.branch.getBranchStats({
858
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1570
+ mergeMigrationRequest({
1571
+ workspace,
1572
+ region,
1573
+ database,
1574
+ migrationRequest
1575
+ }) {
1576
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1577
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
859
1578
  ...this.extraProps
860
1579
  });
861
1580
  }
862
1581
  }
863
- class TableApi {
1582
+ class MigrationsApi {
864
1583
  constructor(extraProps) {
865
1584
  this.extraProps = extraProps;
866
1585
  }
867
- createTable(workspace, database, branch, tableName) {
868
- return operationsByTag.table.createTable({
869
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
870
- ...this.extraProps
871
- });
872
- }
873
- deleteTable(workspace, database, branch, tableName) {
874
- return operationsByTag.table.deleteTable({
875
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1586
+ getBranchMigrationHistory({
1587
+ workspace,
1588
+ region,
1589
+ database,
1590
+ branch,
1591
+ limit,
1592
+ startFrom
1593
+ }) {
1594
+ return operationsByTag.migrations.getBranchMigrationHistory({
1595
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1596
+ body: { limit, startFrom },
876
1597
  ...this.extraProps
877
1598
  });
878
1599
  }
879
- updateTable(workspace, database, branch, tableName, options) {
880
- return operationsByTag.table.updateTable({
881
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
882
- body: options,
1600
+ getBranchMigrationPlan({
1601
+ workspace,
1602
+ region,
1603
+ database,
1604
+ branch,
1605
+ schema
1606
+ }) {
1607
+ return operationsByTag.migrations.getBranchMigrationPlan({
1608
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1609
+ body: schema,
883
1610
  ...this.extraProps
884
1611
  });
885
1612
  }
886
- getTableSchema(workspace, database, branch, tableName) {
887
- return operationsByTag.table.getTableSchema({
888
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1613
+ executeBranchMigrationPlan({
1614
+ workspace,
1615
+ region,
1616
+ database,
1617
+ branch,
1618
+ plan
1619
+ }) {
1620
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1621
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1622
+ body: plan,
889
1623
  ...this.extraProps
890
1624
  });
891
1625
  }
892
- setTableSchema(workspace, database, branch, tableName, options) {
893
- return operationsByTag.table.setTableSchema({
894
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
895
- body: options,
1626
+ getBranchSchemaHistory({
1627
+ workspace,
1628
+ region,
1629
+ database,
1630
+ branch,
1631
+ page
1632
+ }) {
1633
+ return operationsByTag.migrations.getBranchSchemaHistory({
1634
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1635
+ body: { page },
896
1636
  ...this.extraProps
897
1637
  });
898
1638
  }
899
- getTableColumns(workspace, database, branch, tableName) {
900
- return operationsByTag.table.getTableColumns({
901
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1639
+ compareBranchWithUserSchema({
1640
+ workspace,
1641
+ region,
1642
+ database,
1643
+ branch,
1644
+ schema
1645
+ }) {
1646
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1647
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1648
+ body: { schema },
902
1649
  ...this.extraProps
903
1650
  });
904
1651
  }
905
- addTableColumn(workspace, database, branch, tableName, column) {
906
- return operationsByTag.table.addTableColumn({
907
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
908
- body: column,
1652
+ compareBranchSchemas({
1653
+ workspace,
1654
+ region,
1655
+ database,
1656
+ branch,
1657
+ compare,
1658
+ schema
1659
+ }) {
1660
+ return operationsByTag.migrations.compareBranchSchemas({
1661
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1662
+ body: { schema },
909
1663
  ...this.extraProps
910
1664
  });
911
1665
  }
912
- getColumn(workspace, database, branch, tableName, columnName) {
913
- return operationsByTag.table.getColumn({
914
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1666
+ updateBranchSchema({
1667
+ workspace,
1668
+ region,
1669
+ database,
1670
+ branch,
1671
+ migration
1672
+ }) {
1673
+ return operationsByTag.migrations.updateBranchSchema({
1674
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1675
+ body: migration,
915
1676
  ...this.extraProps
916
1677
  });
917
1678
  }
918
- deleteColumn(workspace, database, branch, tableName, columnName) {
919
- return operationsByTag.table.deleteColumn({
920
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1679
+ previewBranchSchemaEdit({
1680
+ workspace,
1681
+ region,
1682
+ database,
1683
+ branch,
1684
+ data
1685
+ }) {
1686
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1687
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1688
+ body: data,
921
1689
  ...this.extraProps
922
1690
  });
923
1691
  }
924
- updateColumn(workspace, database, branch, tableName, columnName, options) {
925
- return operationsByTag.table.updateColumn({
926
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
927
- body: options,
1692
+ applyBranchSchemaEdit({
1693
+ workspace,
1694
+ region,
1695
+ database,
1696
+ branch,
1697
+ edits
1698
+ }) {
1699
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1700
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1701
+ body: { edits },
928
1702
  ...this.extraProps
929
1703
  });
930
1704
  }
931
1705
  }
932
- class RecordsApi {
1706
+ class DatabaseApi {
933
1707
  constructor(extraProps) {
934
1708
  this.extraProps = extraProps;
935
1709
  }
936
- insertRecord(workspace, database, branch, tableName, record, options = {}) {
937
- return operationsByTag.records.insertRecord({
938
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
939
- queryParams: options,
940
- body: record,
941
- ...this.extraProps
942
- });
943
- }
944
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
945
- return operationsByTag.records.insertRecordWithID({
946
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
947
- queryParams: options,
948
- body: record,
949
- ...this.extraProps
950
- });
951
- }
952
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
953
- return operationsByTag.records.updateRecordWithID({
954
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
955
- queryParams: options,
956
- body: record,
957
- ...this.extraProps
958
- });
959
- }
960
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
961
- return operationsByTag.records.upsertRecordWithID({
962
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
963
- queryParams: options,
964
- body: record,
965
- ...this.extraProps
966
- });
967
- }
968
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
969
- return operationsByTag.records.deleteRecord({
970
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
971
- queryParams: options,
1710
+ getDatabaseList({ workspace }) {
1711
+ return operationsByTag.databases.getDatabaseList({
1712
+ pathParams: { workspaceId: workspace },
972
1713
  ...this.extraProps
973
1714
  });
974
1715
  }
975
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
976
- return operationsByTag.records.getRecord({
977
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
978
- queryParams: options,
1716
+ createDatabase({
1717
+ workspace,
1718
+ database,
1719
+ data
1720
+ }) {
1721
+ return operationsByTag.databases.createDatabase({
1722
+ pathParams: { workspaceId: workspace, dbName: database },
1723
+ body: data,
979
1724
  ...this.extraProps
980
1725
  });
981
1726
  }
982
- bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
983
- return operationsByTag.records.bulkInsertTableRecords({
984
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
985
- queryParams: options,
986
- body: { records },
1727
+ deleteDatabase({
1728
+ workspace,
1729
+ database
1730
+ }) {
1731
+ return operationsByTag.databases.deleteDatabase({
1732
+ pathParams: { workspaceId: workspace, dbName: database },
987
1733
  ...this.extraProps
988
1734
  });
989
1735
  }
990
- queryTable(workspace, database, branch, tableName, query) {
991
- return operationsByTag.records.queryTable({
992
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
993
- body: query,
1736
+ getDatabaseMetadata({
1737
+ workspace,
1738
+ database
1739
+ }) {
1740
+ return operationsByTag.databases.getDatabaseMetadata({
1741
+ pathParams: { workspaceId: workspace, dbName: database },
994
1742
  ...this.extraProps
995
1743
  });
996
1744
  }
997
- searchTable(workspace, database, branch, tableName, query) {
998
- return operationsByTag.records.searchTable({
999
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1000
- body: query,
1745
+ updateDatabaseMetadata({
1746
+ workspace,
1747
+ database,
1748
+ metadata
1749
+ }) {
1750
+ return operationsByTag.databases.updateDatabaseMetadata({
1751
+ pathParams: { workspaceId: workspace, dbName: database },
1752
+ body: metadata,
1001
1753
  ...this.extraProps
1002
1754
  });
1003
1755
  }
1004
- searchBranch(workspace, database, branch, query) {
1005
- return operationsByTag.records.searchBranch({
1006
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1007
- body: query,
1756
+ listRegions({ workspace }) {
1757
+ return operationsByTag.databases.listRegions({
1758
+ pathParams: { workspaceId: workspace },
1008
1759
  ...this.extraProps
1009
1760
  });
1010
1761
  }
@@ -1020,6 +1771,20 @@ class XataApiPlugin {
1020
1771
  class XataPlugin {
1021
1772
  }
1022
1773
 
1774
+ function generateUUID() {
1775
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1776
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1777
+ return v.toString(16);
1778
+ });
1779
+ }
1780
+
1781
+ function cleanFilter(filter) {
1782
+ if (!filter)
1783
+ return void 0;
1784
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1785
+ return values.length > 0 ? filter : void 0;
1786
+ }
1787
+
1023
1788
  var __accessCheck$6 = (obj, member, msg) => {
1024
1789
  if (!member.has(obj))
1025
1790
  throw TypeError("Cannot " + msg);
@@ -1052,11 +1817,11 @@ class Page {
1052
1817
  async previousPage(size, offset) {
1053
1818
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1054
1819
  }
1055
- async firstPage(size, offset) {
1056
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1820
+ async startPage(size, offset) {
1821
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1057
1822
  }
1058
- async lastPage(size, offset) {
1059
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1823
+ async endPage(size, offset) {
1824
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1060
1825
  }
1061
1826
  hasNextPage() {
1062
1827
  return this.meta.page.more;
@@ -1068,7 +1833,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1068
1833
  const PAGINATION_MAX_OFFSET = 800;
1069
1834
  const PAGINATION_DEFAULT_OFFSET = 0;
1070
1835
  function isCursorPaginationOptions(options) {
1071
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1836
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1072
1837
  }
1073
1838
  const _RecordArray = class extends Array {
1074
1839
  constructor(...args) {
@@ -1100,12 +1865,12 @@ const _RecordArray = class extends Array {
1100
1865
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1101
1866
  return new _RecordArray(newPage);
1102
1867
  }
1103
- async firstPage(size, offset) {
1104
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1868
+ async startPage(size, offset) {
1869
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1105
1870
  return new _RecordArray(newPage);
1106
1871
  }
1107
- async lastPage(size, offset) {
1108
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1872
+ async endPage(size, offset) {
1873
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1109
1874
  return new _RecordArray(newPage);
1110
1875
  }
1111
1876
  hasNextPage() {
@@ -1133,9 +1898,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1133
1898
  setter ? setter.call(obj, value) : member.set(obj, value);
1134
1899
  return value;
1135
1900
  };
1136
- var _table$1, _repository, _data;
1901
+ var __privateMethod$3 = (obj, member, method) => {
1902
+ __accessCheck$5(obj, member, "access private method");
1903
+ return method;
1904
+ };
1905
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1137
1906
  const _Query = class {
1138
1907
  constructor(repository, table, data, rawParent) {
1908
+ __privateAdd$5(this, _cleanFilterConstraint);
1139
1909
  __privateAdd$5(this, _table$1, void 0);
1140
1910
  __privateAdd$5(this, _repository, void 0);
1141
1911
  __privateAdd$5(this, _data, { filter: {} });
@@ -1154,9 +1924,10 @@ const _Query = class {
1154
1924
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1155
1925
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1156
1926
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1157
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1927
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1158
1928
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1159
1929
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1930
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1160
1931
  this.any = this.any.bind(this);
1161
1932
  this.all = this.all.bind(this);
1162
1933
  this.not = this.not.bind(this);
@@ -1192,15 +1963,18 @@ const _Query = class {
1192
1963
  }
1193
1964
  filter(a, b) {
1194
1965
  if (arguments.length === 1) {
1195
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1966
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1967
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1968
+ }));
1196
1969
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1197
1970
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1198
1971
  } else {
1199
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1972
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
1973
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1200
1974
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1201
1975
  }
1202
1976
  }
1203
- sort(column, direction) {
1977
+ sort(column, direction = "asc") {
1204
1978
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1205
1979
  const sort = [...originalSort, { column, direction }];
1206
1980
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
@@ -1234,11 +2008,20 @@ const _Query = class {
1234
2008
  }
1235
2009
  }
1236
2010
  async getMany(options = {}) {
1237
- const page = await this.getPaginated(options);
2011
+ const { pagination = {}, ...rest } = options;
2012
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
2013
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
2014
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
2015
+ const results = [...page.records];
2016
+ while (page.hasNextPage() && results.length < size) {
2017
+ page = await page.nextPage();
2018
+ results.push(...page.records);
2019
+ }
1238
2020
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1239
2021
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1240
2022
  }
1241
- return page.records;
2023
+ const array = new RecordArray(page, results.slice(0, size));
2024
+ return array;
1242
2025
  }
1243
2026
  async getAll(options = {}) {
1244
2027
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1252,19 +2035,35 @@ const _Query = class {
1252
2035
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1253
2036
  return records[0] ?? null;
1254
2037
  }
2038
+ async getFirstOrThrow(options = {}) {
2039
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2040
+ if (records[0] === void 0)
2041
+ throw new Error("No results found.");
2042
+ return records[0];
2043
+ }
2044
+ async summarize(params = {}) {
2045
+ const { summaries, summariesFilter, ...options } = params;
2046
+ const query = new _Query(
2047
+ __privateGet$5(this, _repository),
2048
+ __privateGet$5(this, _table$1),
2049
+ options,
2050
+ __privateGet$5(this, _data)
2051
+ );
2052
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2053
+ }
1255
2054
  cache(ttl) {
1256
2055
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1257
2056
  }
1258
2057
  nextPage(size, offset) {
1259
- return this.firstPage(size, offset);
2058
+ return this.startPage(size, offset);
1260
2059
  }
1261
2060
  previousPage(size, offset) {
1262
- return this.firstPage(size, offset);
2061
+ return this.startPage(size, offset);
1263
2062
  }
1264
- firstPage(size, offset) {
2063
+ startPage(size, offset) {
1265
2064
  return this.getPaginated({ pagination: { size, offset } });
1266
2065
  }
1267
- lastPage(size, offset) {
2066
+ endPage(size, offset) {
1268
2067
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1269
2068
  }
1270
2069
  hasNextPage() {
@@ -1275,9 +2074,20 @@ let Query = _Query;
1275
2074
  _table$1 = new WeakMap();
1276
2075
  _repository = new WeakMap();
1277
2076
  _data = new WeakMap();
2077
+ _cleanFilterConstraint = new WeakSet();
2078
+ cleanFilterConstraint_fn = function(column, value) {
2079
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2080
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2081
+ return { $includes: value };
2082
+ }
2083
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
2084
+ return value.id;
2085
+ }
2086
+ return value;
2087
+ };
1278
2088
  function cleanParent(data, parent) {
1279
2089
  if (isCursorPaginationOptions(data.pagination)) {
1280
- return { ...parent, sorting: void 0, filter: void 0 };
2090
+ return { ...parent, sort: void 0, filter: void 0 };
1281
2091
  }
1282
2092
  return parent;
1283
2093
  }
@@ -1336,18 +2146,24 @@ var __privateMethod$2 = (obj, member, method) => {
1336
2146
  __accessCheck$4(obj, member, "access private method");
1337
2147
  return method;
1338
2148
  };
1339
- 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;
2149
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_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;
1340
2150
  class Repository extends Query {
1341
2151
  }
1342
2152
  class RestRepository extends Query {
1343
2153
  constructor(options) {
1344
- super(null, options.table, {});
2154
+ super(
2155
+ null,
2156
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
2157
+ {}
2158
+ );
1345
2159
  __privateAdd$4(this, _insertRecordWithoutId);
1346
2160
  __privateAdd$4(this, _insertRecordWithId);
1347
2161
  __privateAdd$4(this, _bulkInsertTableRecords);
1348
2162
  __privateAdd$4(this, _updateRecordWithID);
2163
+ __privateAdd$4(this, _updateRecords);
1349
2164
  __privateAdd$4(this, _upsertRecordWithID);
1350
2165
  __privateAdd$4(this, _deleteRecord);
2166
+ __privateAdd$4(this, _deleteRecords);
1351
2167
  __privateAdd$4(this, _setCacheQuery);
1352
2168
  __privateAdd$4(this, _getCacheQuery);
1353
2169
  __privateAdd$4(this, _getSchemaTables$1);
@@ -1356,168 +2172,342 @@ class RestRepository extends Query {
1356
2172
  __privateAdd$4(this, _db, void 0);
1357
2173
  __privateAdd$4(this, _cache, void 0);
1358
2174
  __privateAdd$4(this, _schemaTables$2, void 0);
2175
+ __privateAdd$4(this, _trace, void 0);
1359
2176
  __privateSet$4(this, _table, options.table);
1360
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1361
2177
  __privateSet$4(this, _db, options.db);
1362
2178
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1363
2179
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2180
+ __privateSet$4(this, _getFetchProps, async () => {
2181
+ const props = await options.pluginOptions.getFetchProps();
2182
+ return { ...props, sessionID: generateUUID() };
2183
+ });
2184
+ const trace = options.pluginOptions.trace ?? defaultTrace;
2185
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2186
+ return trace(name, fn, {
2187
+ ...options2,
2188
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
2189
+ [TraceAttributes.KIND]: "sdk-operation",
2190
+ [TraceAttributes.VERSION]: VERSION
2191
+ });
2192
+ });
1364
2193
  }
1365
- async create(a, b, c) {
1366
- if (Array.isArray(a)) {
1367
- if (a.length === 0)
1368
- return [];
1369
- const columns = isStringArray(b) ? b : void 0;
1370
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1371
- }
1372
- if (isString(a) && isObject(b)) {
1373
- if (a === "")
1374
- throw new Error("The id can't be empty");
1375
- const columns = isStringArray(c) ? c : void 0;
1376
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1377
- }
1378
- if (isObject(a) && isString(a.id)) {
1379
- if (a.id === "")
1380
- throw new Error("The id can't be empty");
1381
- const columns = isStringArray(b) ? b : void 0;
1382
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1383
- }
1384
- if (isObject(a)) {
1385
- const columns = isStringArray(b) ? b : void 0;
1386
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1387
- }
1388
- throw new Error("Invalid arguments for create method");
2194
+ async create(a, b, c, d) {
2195
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
2196
+ const ifVersion = parseIfVersion(b, c, d);
2197
+ if (Array.isArray(a)) {
2198
+ if (a.length === 0)
2199
+ return [];
2200
+ const columns = isStringArray(b) ? b : void 0;
2201
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2202
+ }
2203
+ if (isString(a) && isObject(b)) {
2204
+ if (a === "")
2205
+ throw new Error("The id can't be empty");
2206
+ const columns = isStringArray(c) ? c : void 0;
2207
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2208
+ }
2209
+ if (isObject(a) && isString(a.id)) {
2210
+ if (a.id === "")
2211
+ throw new Error("The id can't be empty");
2212
+ const columns = isStringArray(b) ? b : void 0;
2213
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2214
+ }
2215
+ if (isObject(a)) {
2216
+ const columns = isStringArray(b) ? b : void 0;
2217
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2218
+ }
2219
+ throw new Error("Invalid arguments for create method");
2220
+ });
1389
2221
  }
1390
2222
  async read(a, b) {
1391
- const columns = isStringArray(b) ? b : ["*"];
1392
- if (Array.isArray(a)) {
1393
- if (a.length === 0)
1394
- return [];
1395
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1396
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1397
- const dictionary = finalObjects.reduce((acc, object) => {
1398
- acc[object.id] = object;
1399
- return acc;
1400
- }, {});
1401
- return ids.map((id2) => dictionary[id2] ?? null);
1402
- }
1403
- const id = isString(a) ? a : a.id;
1404
- if (isString(id)) {
1405
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1406
- try {
1407
- const response = await getRecord({
1408
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1409
- queryParams: { columns },
1410
- ...fetchProps
2223
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
2224
+ const columns = isStringArray(b) ? b : ["*"];
2225
+ if (Array.isArray(a)) {
2226
+ if (a.length === 0)
2227
+ return [];
2228
+ const ids = a.map((item) => extractId(item));
2229
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
2230
+ const dictionary = finalObjects.reduce((acc, object) => {
2231
+ acc[object.id] = object;
2232
+ return acc;
2233
+ }, {});
2234
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
2235
+ }
2236
+ const id = extractId(a);
2237
+ if (id) {
2238
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2239
+ try {
2240
+ const response = await getRecord({
2241
+ pathParams: {
2242
+ workspace: "{workspaceId}",
2243
+ dbBranchName: "{dbBranch}",
2244
+ region: "{region}",
2245
+ tableName: __privateGet$4(this, _table),
2246
+ recordId: id
2247
+ },
2248
+ queryParams: { columns },
2249
+ ...fetchProps
2250
+ });
2251
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2252
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2253
+ } catch (e) {
2254
+ if (isObject(e) && e.status === 404) {
2255
+ return null;
2256
+ }
2257
+ throw e;
2258
+ }
2259
+ }
2260
+ return null;
2261
+ });
2262
+ }
2263
+ async readOrThrow(a, b) {
2264
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
2265
+ const result = await this.read(a, b);
2266
+ if (Array.isArray(result)) {
2267
+ const missingIds = compact(
2268
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2269
+ );
2270
+ if (missingIds.length > 0) {
2271
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2272
+ }
2273
+ return result;
2274
+ }
2275
+ if (result === null) {
2276
+ const id = extractId(a) ?? "unknown";
2277
+ throw new Error(`Record with id ${id} not found`);
2278
+ }
2279
+ return result;
2280
+ });
2281
+ }
2282
+ async update(a, b, c, d) {
2283
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
2284
+ const ifVersion = parseIfVersion(b, c, d);
2285
+ if (Array.isArray(a)) {
2286
+ if (a.length === 0)
2287
+ return [];
2288
+ const existing = await this.read(a, ["id"]);
2289
+ const updates = a.filter((_item, index) => existing[index] !== null);
2290
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2291
+ ifVersion,
2292
+ upsert: false
1411
2293
  });
1412
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1413
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1414
- } catch (e) {
1415
- if (isObject(e) && e.status === 404) {
1416
- return null;
2294
+ const columns = isStringArray(b) ? b : ["*"];
2295
+ const result = await this.read(a, columns);
2296
+ return result;
2297
+ }
2298
+ if (isString(a) && isObject(b)) {
2299
+ const columns = isStringArray(c) ? c : void 0;
2300
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2301
+ }
2302
+ if (isObject(a) && isString(a.id)) {
2303
+ const columns = isStringArray(b) ? b : void 0;
2304
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2305
+ }
2306
+ throw new Error("Invalid arguments for update method");
2307
+ });
2308
+ }
2309
+ async updateOrThrow(a, b, c, d) {
2310
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
2311
+ const result = await this.update(a, b, c, d);
2312
+ if (Array.isArray(result)) {
2313
+ const missingIds = compact(
2314
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2315
+ );
2316
+ if (missingIds.length > 0) {
2317
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1417
2318
  }
1418
- throw e;
2319
+ return result;
1419
2320
  }
1420
- }
1421
- return null;
2321
+ if (result === null) {
2322
+ const id = extractId(a) ?? "unknown";
2323
+ throw new Error(`Record with id ${id} not found`);
2324
+ }
2325
+ return result;
2326
+ });
1422
2327
  }
1423
- async update(a, b, c) {
1424
- if (Array.isArray(a)) {
1425
- if (a.length === 0)
1426
- return [];
1427
- if (a.length > 100) {
1428
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2328
+ async createOrUpdate(a, b, c, d) {
2329
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2330
+ const ifVersion = parseIfVersion(b, c, d);
2331
+ if (Array.isArray(a)) {
2332
+ if (a.length === 0)
2333
+ return [];
2334
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2335
+ ifVersion,
2336
+ upsert: true
2337
+ });
2338
+ const columns = isStringArray(b) ? b : ["*"];
2339
+ const result = await this.read(a, columns);
2340
+ return result;
1429
2341
  }
1430
- const columns = isStringArray(b) ? b : ["*"];
1431
- return Promise.all(a.map((object) => this.update(object, columns)));
1432
- }
1433
- if (isString(a) && isObject(b)) {
1434
- const columns = isStringArray(c) ? c : void 0;
1435
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1436
- }
1437
- if (isObject(a) && isString(a.id)) {
1438
- const columns = isStringArray(b) ? b : void 0;
1439
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1440
- }
1441
- throw new Error("Invalid arguments for update method");
1442
- }
1443
- async createOrUpdate(a, b, c) {
1444
- if (Array.isArray(a)) {
1445
- if (a.length === 0)
1446
- return [];
1447
- if (a.length > 100) {
1448
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2342
+ if (isString(a) && isObject(b)) {
2343
+ const columns = isStringArray(c) ? c : void 0;
2344
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1449
2345
  }
1450
- const columns = isStringArray(b) ? b : ["*"];
1451
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1452
- }
1453
- if (isString(a) && isObject(b)) {
1454
- const columns = isStringArray(c) ? c : void 0;
1455
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1456
- }
1457
- if (isObject(a) && isString(a.id)) {
1458
- const columns = isStringArray(c) ? c : void 0;
1459
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1460
- }
1461
- throw new Error("Invalid arguments for createOrUpdate method");
1462
- }
1463
- async delete(a) {
1464
- if (Array.isArray(a)) {
1465
- if (a.length === 0)
1466
- return;
1467
- if (a.length > 100) {
1468
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
2346
+ if (isObject(a) && isString(a.id)) {
2347
+ const columns = isStringArray(c) ? c : void 0;
2348
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1469
2349
  }
1470
- await Promise.all(a.map((id) => this.delete(id)));
1471
- return;
1472
- }
1473
- if (isString(a)) {
1474
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1475
- return;
1476
- }
1477
- if (isObject(a) && isString(a.id)) {
1478
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1479
- return;
1480
- }
1481
- throw new Error("Invalid arguments for delete method");
2350
+ throw new Error("Invalid arguments for createOrUpdate method");
2351
+ });
2352
+ }
2353
+ async createOrReplace(a, b, c, d) {
2354
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2355
+ const ifVersion = parseIfVersion(b, c, d);
2356
+ if (Array.isArray(a)) {
2357
+ if (a.length === 0)
2358
+ return [];
2359
+ const columns = isStringArray(b) ? b : ["*"];
2360
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2361
+ }
2362
+ if (isString(a) && isObject(b)) {
2363
+ const columns = isStringArray(c) ? c : void 0;
2364
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2365
+ }
2366
+ if (isObject(a) && isString(a.id)) {
2367
+ const columns = isStringArray(c) ? c : void 0;
2368
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2369
+ }
2370
+ throw new Error("Invalid arguments for createOrReplace method");
2371
+ });
2372
+ }
2373
+ async delete(a, b) {
2374
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
2375
+ if (Array.isArray(a)) {
2376
+ if (a.length === 0)
2377
+ return [];
2378
+ const ids = a.map((o) => {
2379
+ if (isString(o))
2380
+ return o;
2381
+ if (isString(o.id))
2382
+ return o.id;
2383
+ throw new Error("Invalid arguments for delete method");
2384
+ });
2385
+ const columns = isStringArray(b) ? b : ["*"];
2386
+ const result = await this.read(a, columns);
2387
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2388
+ return result;
2389
+ }
2390
+ if (isString(a)) {
2391
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2392
+ }
2393
+ if (isObject(a) && isString(a.id)) {
2394
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
2395
+ }
2396
+ throw new Error("Invalid arguments for delete method");
2397
+ });
2398
+ }
2399
+ async deleteOrThrow(a, b) {
2400
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
2401
+ const result = await this.delete(a, b);
2402
+ if (Array.isArray(result)) {
2403
+ const missingIds = compact(
2404
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2405
+ );
2406
+ if (missingIds.length > 0) {
2407
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2408
+ }
2409
+ return result;
2410
+ } else if (result === null) {
2411
+ const id = extractId(a) ?? "unknown";
2412
+ throw new Error(`Record with id ${id} not found`);
2413
+ }
2414
+ return result;
2415
+ });
1482
2416
  }
1483
2417
  async search(query, options = {}) {
1484
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1485
- const { records } = await searchTable({
1486
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1487
- body: {
1488
- query,
1489
- fuzziness: options.fuzziness,
1490
- prefix: options.prefix,
1491
- highlight: options.highlight,
1492
- filter: options.filter,
1493
- boosters: options.boosters
1494
- },
1495
- ...fetchProps
2418
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
2419
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2420
+ const { records } = await searchTable({
2421
+ pathParams: {
2422
+ workspace: "{workspaceId}",
2423
+ dbBranchName: "{dbBranch}",
2424
+ region: "{region}",
2425
+ tableName: __privateGet$4(this, _table)
2426
+ },
2427
+ body: {
2428
+ query,
2429
+ fuzziness: options.fuzziness,
2430
+ prefix: options.prefix,
2431
+ highlight: options.highlight,
2432
+ filter: options.filter,
2433
+ boosters: options.boosters
2434
+ },
2435
+ ...fetchProps
2436
+ });
2437
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2438
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2439
+ });
2440
+ }
2441
+ async aggregate(aggs, filter) {
2442
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2443
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2444
+ const result = await aggregateTable({
2445
+ pathParams: {
2446
+ workspace: "{workspaceId}",
2447
+ dbBranchName: "{dbBranch}",
2448
+ region: "{region}",
2449
+ tableName: __privateGet$4(this, _table)
2450
+ },
2451
+ body: { aggs, filter },
2452
+ ...fetchProps
2453
+ });
2454
+ return result;
1496
2455
  });
1497
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1498
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1499
2456
  }
1500
2457
  async query(query) {
1501
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1502
- if (cacheQuery)
1503
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1504
- const data = query.getQueryOptions();
1505
- const body = {
1506
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1507
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1508
- page: data.pagination,
1509
- columns: data.columns
1510
- };
1511
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1512
- const { meta, records: objects } = await queryTable({
1513
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1514
- body,
1515
- ...fetchProps
2458
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
2459
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
2460
+ if (cacheQuery)
2461
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
2462
+ const data = query.getQueryOptions();
2463
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2464
+ const { meta, records: objects } = await queryTable({
2465
+ pathParams: {
2466
+ workspace: "{workspaceId}",
2467
+ dbBranchName: "{dbBranch}",
2468
+ region: "{region}",
2469
+ tableName: __privateGet$4(this, _table)
2470
+ },
2471
+ body: {
2472
+ filter: cleanFilter(data.filter),
2473
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2474
+ page: data.pagination,
2475
+ columns: data.columns ?? ["*"]
2476
+ },
2477
+ fetchOptions: data.fetchOptions,
2478
+ ...fetchProps
2479
+ });
2480
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2481
+ const records = objects.map(
2482
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2483
+ );
2484
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
2485
+ return new Page(query, meta, records);
2486
+ });
2487
+ }
2488
+ async summarizeTable(query, summaries, summariesFilter) {
2489
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2490
+ const data = query.getQueryOptions();
2491
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2492
+ const result = await summarizeTable({
2493
+ pathParams: {
2494
+ workspace: "{workspaceId}",
2495
+ dbBranchName: "{dbBranch}",
2496
+ region: "{region}",
2497
+ tableName: __privateGet$4(this, _table)
2498
+ },
2499
+ body: {
2500
+ filter: cleanFilter(data.filter),
2501
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2502
+ columns: data.columns,
2503
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2504
+ summaries,
2505
+ summariesFilter
2506
+ },
2507
+ ...fetchProps
2508
+ });
2509
+ return result;
1516
2510
  });
1517
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1518
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1519
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1520
- return new Page(query, meta, records);
1521
2511
  }
1522
2512
  }
1523
2513
  _table = new WeakMap();
@@ -1525,6 +2515,7 @@ _getFetchProps = new WeakMap();
1525
2515
  _db = new WeakMap();
1526
2516
  _cache = new WeakMap();
1527
2517
  _schemaTables$2 = new WeakMap();
2518
+ _trace = new WeakMap();
1528
2519
  _insertRecordWithoutId = new WeakSet();
1529
2520
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1530
2521
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1533,6 +2524,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1533
2524
  pathParams: {
1534
2525
  workspace: "{workspaceId}",
1535
2526
  dbBranchName: "{dbBranch}",
2527
+ region: "{region}",
1536
2528
  tableName: __privateGet$4(this, _table)
1537
2529
  },
1538
2530
  queryParams: { columns },
@@ -1540,32 +2532,38 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1540
2532
  ...fetchProps
1541
2533
  });
1542
2534
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1543
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2535
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1544
2536
  };
1545
2537
  _insertRecordWithId = new WeakSet();
1546
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
2538
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
1547
2539
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1548
2540
  const record = transformObjectLinks(object);
1549
2541
  const response = await insertRecordWithID({
1550
2542
  pathParams: {
1551
2543
  workspace: "{workspaceId}",
1552
2544
  dbBranchName: "{dbBranch}",
2545
+ region: "{region}",
1553
2546
  tableName: __privateGet$4(this, _table),
1554
2547
  recordId
1555
2548
  },
1556
2549
  body: record,
1557
- queryParams: { createOnly: true, columns },
2550
+ queryParams: { createOnly, columns, ifVersion },
1558
2551
  ...fetchProps
1559
2552
  });
1560
2553
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1561
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2554
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1562
2555
  };
1563
2556
  _bulkInsertTableRecords = new WeakSet();
1564
2557
  bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1565
2558
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1566
2559
  const records = objects.map((object) => transformObjectLinks(object));
1567
2560
  const response = await bulkInsertTableRecords({
1568
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2561
+ pathParams: {
2562
+ workspace: "{workspaceId}",
2563
+ dbBranchName: "{dbBranch}",
2564
+ region: "{region}",
2565
+ tableName: __privateGet$4(this, _table)
2566
+ },
1569
2567
  queryParams: { columns },
1570
2568
  body: { records },
1571
2569
  ...fetchProps
@@ -1574,40 +2572,106 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1574
2572
  throw new Error("Request included columns but server didn't include them");
1575
2573
  }
1576
2574
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1577
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2575
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
1578
2576
  };
1579
2577
  _updateRecordWithID = new WeakSet();
1580
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2578
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1581
2579
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1582
2580
  const record = transformObjectLinks(object);
1583
- const response = await updateRecordWithID({
1584
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1585
- queryParams: { columns },
1586
- body: record,
2581
+ try {
2582
+ const response = await updateRecordWithID({
2583
+ pathParams: {
2584
+ workspace: "{workspaceId}",
2585
+ dbBranchName: "{dbBranch}",
2586
+ region: "{region}",
2587
+ tableName: __privateGet$4(this, _table),
2588
+ recordId
2589
+ },
2590
+ queryParams: { columns, ifVersion },
2591
+ body: record,
2592
+ ...fetchProps
2593
+ });
2594
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2595
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2596
+ } catch (e) {
2597
+ if (isObject(e) && e.status === 404) {
2598
+ return null;
2599
+ }
2600
+ }
2601
+ };
2602
+ _updateRecords = new WeakSet();
2603
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2604
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2605
+ const operations = objects.map(({ id, ...fields }) => ({
2606
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields }
2607
+ }));
2608
+ const { results } = await branchTransaction({
2609
+ pathParams: {
2610
+ workspace: "{workspaceId}",
2611
+ dbBranchName: "{dbBranch}",
2612
+ region: "{region}"
2613
+ },
2614
+ body: { operations },
1587
2615
  ...fetchProps
1588
2616
  });
1589
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1590
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2617
+ return results;
1591
2618
  };
1592
2619
  _upsertRecordWithID = new WeakSet();
1593
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2620
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1594
2621
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1595
2622
  const response = await upsertRecordWithID({
1596
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1597
- queryParams: { columns },
2623
+ pathParams: {
2624
+ workspace: "{workspaceId}",
2625
+ dbBranchName: "{dbBranch}",
2626
+ region: "{region}",
2627
+ tableName: __privateGet$4(this, _table),
2628
+ recordId
2629
+ },
2630
+ queryParams: { columns, ifVersion },
1598
2631
  body: object,
1599
2632
  ...fetchProps
1600
2633
  });
1601
2634
  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);
2635
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1603
2636
  };
1604
2637
  _deleteRecord = new WeakSet();
1605
- deleteRecord_fn = async function(recordId) {
2638
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2639
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2640
+ try {
2641
+ const response = await deleteRecord({
2642
+ pathParams: {
2643
+ workspace: "{workspaceId}",
2644
+ dbBranchName: "{dbBranch}",
2645
+ region: "{region}",
2646
+ tableName: __privateGet$4(this, _table),
2647
+ recordId
2648
+ },
2649
+ queryParams: { columns },
2650
+ ...fetchProps
2651
+ });
2652
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2653
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2654
+ } catch (e) {
2655
+ if (isObject(e) && e.status === 404) {
2656
+ return null;
2657
+ }
2658
+ throw e;
2659
+ }
2660
+ };
2661
+ _deleteRecords = new WeakSet();
2662
+ deleteRecords_fn = async function(recordIds) {
1606
2663
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1607
- await deleteRecord({
1608
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2664
+ const operations = recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } }));
2665
+ const { results } = await branchTransaction({
2666
+ pathParams: {
2667
+ workspace: "{workspaceId}",
2668
+ dbBranchName: "{dbBranch}",
2669
+ region: "{region}"
2670
+ },
2671
+ body: { operations },
1609
2672
  ...fetchProps
1610
2673
  });
2674
+ return results;
1611
2675
  };
1612
2676
  _setCacheQuery = new WeakSet();
1613
2677
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1631,7 +2695,7 @@ getSchemaTables_fn$1 = async function() {
1631
2695
  return __privateGet$4(this, _schemaTables$2);
1632
2696
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1633
2697
  const { schema } = await getBranchDetails({
1634
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2698
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1635
2699
  ...fetchProps
1636
2700
  });
1637
2701
  __privateSet$4(this, _schemaTables$2, schema.tables);
@@ -1644,7 +2708,7 @@ const transformObjectLinks = (object) => {
1644
2708
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1645
2709
  }, {});
1646
2710
  };
1647
- const initObject = (db, schemaTables, table, object) => {
2711
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1648
2712
  const result = {};
1649
2713
  const { xata, ...rest } = object ?? {};
1650
2714
  Object.assign(result, rest);
@@ -1652,6 +2716,8 @@ const initObject = (db, schemaTables, table, object) => {
1652
2716
  if (!columns)
1653
2717
  console.error(`Table ${table} not found in schema`);
1654
2718
  for (const column of columns ?? []) {
2719
+ if (!isValidColumn(selectedColumns, column))
2720
+ continue;
1655
2721
  const value = result[column.name];
1656
2722
  switch (column.type) {
1657
2723
  case "datetime": {
@@ -1668,17 +2734,42 @@ const initObject = (db, schemaTables, table, object) => {
1668
2734
  if (!linkTable) {
1669
2735
  console.error(`Failed to parse link for field ${column.name}`);
1670
2736
  } else if (isObject(value)) {
1671
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2737
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2738
+ if (item === column.name) {
2739
+ return [...acc, "*"];
2740
+ }
2741
+ if (item.startsWith(`${column.name}.`)) {
2742
+ const [, ...path] = item.split(".");
2743
+ return [...acc, path.join(".")];
2744
+ }
2745
+ return acc;
2746
+ }, []);
2747
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2748
+ } else {
2749
+ result[column.name] = null;
1672
2750
  }
1673
2751
  break;
1674
2752
  }
2753
+ default:
2754
+ result[column.name] = value ?? null;
2755
+ if (column.notNull === true && value === null) {
2756
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2757
+ }
2758
+ break;
1675
2759
  }
1676
2760
  }
1677
2761
  result.read = function(columns2) {
1678
2762
  return db[table].read(result["id"], columns2);
1679
2763
  };
1680
- result.update = function(data, columns2) {
1681
- return db[table].update(result["id"], data, columns2);
2764
+ result.update = function(data, b, c) {
2765
+ const columns2 = isStringArray(b) ? b : ["*"];
2766
+ const ifVersion = parseIfVersion(b, c);
2767
+ return db[table].update(result["id"], data, columns2, { ifVersion });
2768
+ };
2769
+ result.replace = function(data, b, c) {
2770
+ const columns2 = isStringArray(b) ? b : ["*"];
2771
+ const ifVersion = parseIfVersion(b, c);
2772
+ return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
1682
2773
  };
1683
2774
  result.delete = function() {
1684
2775
  return db[table].delete(result["id"]);
@@ -1686,7 +2777,7 @@ const initObject = (db, schemaTables, table, object) => {
1686
2777
  result.getMetadata = function() {
1687
2778
  return xata;
1688
2779
  };
1689
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
2780
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
1690
2781
  Object.defineProperty(result, prop, { enumerable: false });
1691
2782
  }
1692
2783
  Object.freeze(result);
@@ -1695,6 +2786,30 @@ const initObject = (db, schemaTables, table, object) => {
1695
2786
  function isResponseWithRecords(value) {
1696
2787
  return isObject(value) && Array.isArray(value.records);
1697
2788
  }
2789
+ function extractId(value) {
2790
+ if (isString(value))
2791
+ return value;
2792
+ if (isObject(value) && isString(value.id))
2793
+ return value.id;
2794
+ return void 0;
2795
+ }
2796
+ function isValidColumn(columns, column) {
2797
+ if (columns.includes("*"))
2798
+ return true;
2799
+ if (column.type === "link") {
2800
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2801
+ return linkColumns.length > 0;
2802
+ }
2803
+ return columns.includes(column.name);
2804
+ }
2805
+ function parseIfVersion(...args) {
2806
+ for (const arg of args) {
2807
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
2808
+ return arg.ifVersion;
2809
+ }
2810
+ }
2811
+ return void 0;
2812
+ }
1698
2813
 
1699
2814
  var __accessCheck$3 = (obj, member, msg) => {
1700
2815
  if (!member.has(obj))
@@ -1745,18 +2860,25 @@ class SimpleCache {
1745
2860
  }
1746
2861
  _map = new WeakMap();
1747
2862
 
1748
- const gt = (value) => ({ $gt: value });
1749
- const ge = (value) => ({ $ge: value });
1750
- const gte = (value) => ({ $ge: value });
1751
- const lt = (value) => ({ $lt: value });
1752
- const lte = (value) => ({ $le: value });
1753
- const le = (value) => ({ $le: value });
2863
+ const greaterThan = (value) => ({ $gt: value });
2864
+ const gt = greaterThan;
2865
+ const greaterThanEquals = (value) => ({ $ge: value });
2866
+ const greaterEquals = greaterThanEquals;
2867
+ const gte = greaterThanEquals;
2868
+ const ge = greaterThanEquals;
2869
+ const lessThan = (value) => ({ $lt: value });
2870
+ const lt = lessThan;
2871
+ const lessThanEquals = (value) => ({ $le: value });
2872
+ const lessEquals = lessThanEquals;
2873
+ const lte = lessThanEquals;
2874
+ const le = lessThanEquals;
1754
2875
  const exists = (column) => ({ $exists: column });
1755
2876
  const notExists = (column) => ({ $notExists: column });
1756
2877
  const startsWith = (value) => ({ $startsWith: value });
1757
2878
  const endsWith = (value) => ({ $endsWith: value });
1758
2879
  const pattern = (value) => ({ $pattern: value });
1759
2880
  const is = (value) => ({ $is: value });
2881
+ const equals = is;
1760
2882
  const isNot = (value) => ({ $isNot: value });
1761
2883
  const contains = (value) => ({ $contains: value });
1762
2884
  const includes = (value) => ({ $includes: value });
@@ -1853,7 +2975,7 @@ class SearchPlugin extends XataPlugin {
1853
2975
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1854
2976
  return records.map((record) => {
1855
2977
  const { table = "orphan" } = record.xata;
1856
- return { table, record: initObject(this.db, schemaTables, table, record) };
2978
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1857
2979
  });
1858
2980
  },
1859
2981
  byTable: async (query, options = {}) => {
@@ -1862,7 +2984,7 @@ class SearchPlugin extends XataPlugin {
1862
2984
  return records.reduce((acc, record) => {
1863
2985
  const { table = "orphan" } = record.xata;
1864
2986
  const items = acc[table] ?? [];
1865
- const item = initObject(this.db, schemaTables, table, record);
2987
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1866
2988
  return { ...acc, [table]: [...items, item] };
1867
2989
  }, {});
1868
2990
  }
@@ -1875,7 +2997,7 @@ search_fn = async function(query, options, getFetchProps) {
1875
2997
  const fetchProps = await getFetchProps();
1876
2998
  const { tables, fuzziness, highlight, prefix } = options ?? {};
1877
2999
  const { records } = await searchBranch({
1878
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
3000
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1879
3001
  body: { tables, query, fuzziness, prefix, highlight },
1880
3002
  ...fetchProps
1881
3003
  });
@@ -1887,7 +3009,7 @@ getSchemaTables_fn = async function(getFetchProps) {
1887
3009
  return __privateGet$1(this, _schemaTables);
1888
3010
  const fetchProps = await getFetchProps();
1889
3011
  const { schema } = await getBranchDetails({
1890
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
3012
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1891
3013
  ...fetchProps
1892
3014
  });
1893
3015
  __privateSet$1(this, _schemaTables, schema.tables);
@@ -1925,15 +3047,19 @@ async function resolveXataBranch(gitBranch, options) {
1925
3047
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1926
3048
  );
1927
3049
  const [protocol, , host, , dbName] = databaseURL.split("/");
1928
- const [workspace] = host.split(".");
3050
+ const urlParts = parseWorkspacesUrlParts(host);
3051
+ if (!urlParts)
3052
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3053
+ const { workspace, region } = urlParts;
1929
3054
  const { fallbackBranch } = getEnvironment();
1930
3055
  const { branch } = await resolveBranch({
1931
3056
  apiKey,
1932
3057
  apiUrl: databaseURL,
1933
3058
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1934
3059
  workspacesApiUrl: `${protocol}//${host}`,
1935
- pathParams: { dbName, workspace },
1936
- queryParams: { gitBranch, fallbackBranch }
3060
+ pathParams: { dbName, workspace, region },
3061
+ queryParams: { gitBranch, fallbackBranch },
3062
+ trace: defaultTrace
1937
3063
  });
1938
3064
  return branch;
1939
3065
  }
@@ -1949,15 +3075,18 @@ async function getDatabaseBranch(branch, options) {
1949
3075
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1950
3076
  );
1951
3077
  const [protocol, , host, , database] = databaseURL.split("/");
1952
- const [workspace] = host.split(".");
1953
- const dbBranchName = `${database}:${branch}`;
3078
+ const urlParts = parseWorkspacesUrlParts(host);
3079
+ if (!urlParts)
3080
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3081
+ const { workspace, region } = urlParts;
1954
3082
  try {
1955
3083
  return await getBranchDetails({
1956
3084
  apiKey,
1957
3085
  apiUrl: databaseURL,
1958
3086
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1959
3087
  workspacesApiUrl: `${protocol}//${host}`,
1960
- pathParams: { dbBranchName, workspace }
3088
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3089
+ trace: defaultTrace
1961
3090
  });
1962
3091
  } catch (err) {
1963
3092
  if (isObject(err) && err.status === 404)
@@ -2009,7 +3138,8 @@ const buildClient = (plugins) => {
2009
3138
  __privateSet(this, _options, safeOptions);
2010
3139
  const pluginOptions = {
2011
3140
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2012
- cache: safeOptions.cache
3141
+ cache: safeOptions.cache,
3142
+ trace: safeOptions.trace
2013
3143
  };
2014
3144
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2015
3145
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2034,16 +3164,27 @@ const buildClient = (plugins) => {
2034
3164
  return { databaseURL, branch };
2035
3165
  }
2036
3166
  }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3167
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3168
+ const isBrowser = typeof window !== "undefined";
3169
+ if (isBrowser && !enableBrowser) {
3170
+ throw new Error(
3171
+ "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."
3172
+ );
3173
+ }
2037
3174
  const fetch = getFetchImplementation(options?.fetch);
2038
3175
  const databaseURL = options?.databaseURL || getDatabaseURL();
2039
3176
  const apiKey = options?.apiKey || getAPIKey();
2040
3177
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3178
+ const trace = options?.trace ?? defaultTrace;
2041
3179
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2042
- if (!databaseURL || !apiKey) {
2043
- throw new Error("Options databaseURL and apiKey are required");
3180
+ if (!apiKey) {
3181
+ throw new Error("Option apiKey is required");
3182
+ }
3183
+ if (!databaseURL) {
3184
+ throw new Error("Option databaseURL is required");
2044
3185
  }
2045
- return { fetch, databaseURL, apiKey, branch, cache };
2046
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
3186
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
3187
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
2047
3188
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2048
3189
  if (!branchValue)
2049
3190
  throw new Error("Unable to resolve branch value");
@@ -2053,9 +3194,11 @@ const buildClient = (plugins) => {
2053
3194
  apiUrl: "",
2054
3195
  workspacesApiUrl: (path, params) => {
2055
3196
  const hasBranch = params.dbBranchName ?? params.branch;
2056
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
3197
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2057
3198
  return databaseURL + newPath;
2058
- }
3199
+ },
3200
+ trace,
3201
+ clientID
2059
3202
  };
2060
3203
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2061
3204
  if (__privateGet(this, _branch))
@@ -2078,6 +3221,88 @@ const buildClient = (plugins) => {
2078
3221
  class BaseClient extends buildClient() {
2079
3222
  }
2080
3223
 
3224
+ const META = "__";
3225
+ const VALUE = "___";
3226
+ class Serializer {
3227
+ constructor() {
3228
+ this.classes = {};
3229
+ }
3230
+ add(clazz) {
3231
+ this.classes[clazz.name] = clazz;
3232
+ }
3233
+ toJSON(data) {
3234
+ function visit(obj) {
3235
+ if (Array.isArray(obj))
3236
+ return obj.map(visit);
3237
+ const type = typeof obj;
3238
+ if (type === "undefined")
3239
+ return { [META]: "undefined" };
3240
+ if (type === "bigint")
3241
+ return { [META]: "bigint", [VALUE]: obj.toString() };
3242
+ if (obj === null || type !== "object")
3243
+ return obj;
3244
+ const constructor = obj.constructor;
3245
+ const o = { [META]: constructor.name };
3246
+ for (const [key, value] of Object.entries(obj)) {
3247
+ o[key] = visit(value);
3248
+ }
3249
+ if (constructor === Date)
3250
+ o[VALUE] = obj.toISOString();
3251
+ if (constructor === Map)
3252
+ o[VALUE] = Object.fromEntries(obj);
3253
+ if (constructor === Set)
3254
+ o[VALUE] = [...obj];
3255
+ return o;
3256
+ }
3257
+ return JSON.stringify(visit(data));
3258
+ }
3259
+ fromJSON(json) {
3260
+ return JSON.parse(json, (key, value) => {
3261
+ if (value && typeof value === "object" && !Array.isArray(value)) {
3262
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
3263
+ const constructor = this.classes[clazz];
3264
+ if (constructor) {
3265
+ return Object.assign(Object.create(constructor.prototype), rest);
3266
+ }
3267
+ if (clazz === "Date")
3268
+ return new Date(val);
3269
+ if (clazz === "Set")
3270
+ return new Set(val);
3271
+ if (clazz === "Map")
3272
+ return new Map(Object.entries(val));
3273
+ if (clazz === "bigint")
3274
+ return BigInt(val);
3275
+ if (clazz === "undefined")
3276
+ return void 0;
3277
+ return rest;
3278
+ }
3279
+ return value;
3280
+ });
3281
+ }
3282
+ }
3283
+ const defaultSerializer = new Serializer();
3284
+ const serialize = (data) => {
3285
+ return defaultSerializer.toJSON(data);
3286
+ };
3287
+ const deserialize = (json) => {
3288
+ return defaultSerializer.fromJSON(json);
3289
+ };
3290
+
3291
+ function buildWorkerRunner(config) {
3292
+ return function xataWorker(name, _worker) {
3293
+ return async (...args) => {
3294
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
3295
+ const result = await fetch(url, {
3296
+ method: "POST",
3297
+ headers: { "Content-Type": "application/json" },
3298
+ body: serialize({ args })
3299
+ });
3300
+ const text = await result.text();
3301
+ return deserialize(text);
3302
+ };
3303
+ };
3304
+ }
3305
+
2081
3306
  class XataError extends Error {
2082
3307
  constructor(message, status) {
2083
3308
  super(message);
@@ -2098,6 +3323,7 @@ exports.Repository = Repository;
2098
3323
  exports.RestRepository = RestRepository;
2099
3324
  exports.SchemaPlugin = SchemaPlugin;
2100
3325
  exports.SearchPlugin = SearchPlugin;
3326
+ exports.Serializer = Serializer;
2101
3327
  exports.SimpleCache = SimpleCache;
2102
3328
  exports.XataApiClient = XataApiClient;
2103
3329
  exports.XataApiPlugin = XataApiPlugin;
@@ -2106,15 +3332,28 @@ exports.XataPlugin = XataPlugin;
2106
3332
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2107
3333
  exports.addGitBranchesEntry = addGitBranchesEntry;
2108
3334
  exports.addTableColumn = addTableColumn;
3335
+ exports.aggregateTable = aggregateTable;
3336
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3337
+ exports.branchTransaction = branchTransaction;
2109
3338
  exports.buildClient = buildClient;
3339
+ exports.buildWorkerRunner = buildWorkerRunner;
2110
3340
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2111
3341
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
3342
+ exports.compareBranchSchemas = compareBranchSchemas;
3343
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3344
+ exports.compareMigrationRequest = compareMigrationRequest;
2112
3345
  exports.contains = contains;
2113
3346
  exports.createBranch = createBranch;
2114
3347
  exports.createDatabase = createDatabase;
3348
+ exports.createMigrationRequest = createMigrationRequest;
2115
3349
  exports.createTable = createTable;
2116
3350
  exports.createUserAPIKey = createUserAPIKey;
2117
3351
  exports.createWorkspace = createWorkspace;
3352
+ exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
3353
+ exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
3354
+ exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
3355
+ exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
3356
+ exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
2118
3357
  exports.deleteBranch = deleteBranch;
2119
3358
  exports.deleteColumn = deleteColumn;
2120
3359
  exports.deleteDatabase = deleteDatabase;
@@ -2123,7 +3362,9 @@ exports.deleteTable = deleteTable;
2123
3362
  exports.deleteUser = deleteUser;
2124
3363
  exports.deleteUserAPIKey = deleteUserAPIKey;
2125
3364
  exports.deleteWorkspace = deleteWorkspace;
3365
+ exports.deserialize = deserialize;
2126
3366
  exports.endsWith = endsWith;
3367
+ exports.equals = equals;
2127
3368
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2128
3369
  exports.exists = exists;
2129
3370
  exports.ge = ge;
@@ -2133,13 +3374,18 @@ exports.getBranchList = getBranchList;
2133
3374
  exports.getBranchMetadata = getBranchMetadata;
2134
3375
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2135
3376
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
3377
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2136
3378
  exports.getBranchStats = getBranchStats;
2137
3379
  exports.getColumn = getColumn;
2138
3380
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
2139
3381
  exports.getCurrentBranchName = getCurrentBranchName;
2140
3382
  exports.getDatabaseList = getDatabaseList;
3383
+ exports.getDatabaseMetadata = getDatabaseMetadata;
2141
3384
  exports.getDatabaseURL = getDatabaseURL;
2142
3385
  exports.getGitBranchesMapping = getGitBranchesMapping;
3386
+ exports.getHostUrl = getHostUrl;
3387
+ exports.getMigrationRequest = getMigrationRequest;
3388
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2143
3389
  exports.getRecord = getRecord;
2144
3390
  exports.getTableColumns = getTableColumns;
2145
3391
  exports.getTableSchema = getTableSchema;
@@ -2148,6 +3394,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2148
3394
  exports.getWorkspace = getWorkspace;
2149
3395
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2150
3396
  exports.getWorkspacesList = getWorkspacesList;
3397
+ exports.greaterEquals = greaterEquals;
3398
+ exports.greaterThan = greaterThan;
3399
+ exports.greaterThanEquals = greaterThanEquals;
2151
3400
  exports.gt = gt;
2152
3401
  exports.gte = gte;
2153
3402
  exports.includes = includes;
@@ -2159,15 +3408,27 @@ exports.insertRecordWithID = insertRecordWithID;
2159
3408
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2160
3409
  exports.is = is;
2161
3410
  exports.isCursorPaginationOptions = isCursorPaginationOptions;
3411
+ exports.isHostProviderAlias = isHostProviderAlias;
3412
+ exports.isHostProviderBuilder = isHostProviderBuilder;
2162
3413
  exports.isIdentifiable = isIdentifiable;
2163
3414
  exports.isNot = isNot;
2164
3415
  exports.isXataRecord = isXataRecord;
2165
3416
  exports.le = le;
3417
+ exports.lessEquals = lessEquals;
3418
+ exports.lessThan = lessThan;
3419
+ exports.lessThanEquals = lessThanEquals;
3420
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3421
+ exports.listRegions = listRegions;
2166
3422
  exports.lt = lt;
2167
3423
  exports.lte = lte;
3424
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2168
3425
  exports.notExists = notExists;
2169
3426
  exports.operationsByTag = operationsByTag;
3427
+ exports.parseProviderString = parseProviderString;
3428
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
2170
3429
  exports.pattern = pattern;
3430
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3431
+ exports.queryMigrationRequests = queryMigrationRequests;
2171
3432
  exports.queryTable = queryTable;
2172
3433
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2173
3434
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2175,10 +3436,15 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
2175
3436
  exports.resolveBranch = resolveBranch;
2176
3437
  exports.searchBranch = searchBranch;
2177
3438
  exports.searchTable = searchTable;
3439
+ exports.serialize = serialize;
2178
3440
  exports.setTableSchema = setTableSchema;
2179
3441
  exports.startsWith = startsWith;
3442
+ exports.summarizeTable = summarizeTable;
2180
3443
  exports.updateBranchMetadata = updateBranchMetadata;
3444
+ exports.updateBranchSchema = updateBranchSchema;
2181
3445
  exports.updateColumn = updateColumn;
3446
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
3447
+ exports.updateMigrationRequest = updateMigrationRequest;
2182
3448
  exports.updateRecordWithID = updateRecordWithID;
2183
3449
  exports.updateTable = updateTable;
2184
3450
  exports.updateUser = updateUser;