@xata.io/client 0.0.0-alpha.vfd1a215 → 0.0.0-alpha.vfd68d20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -38,6 +38,9 @@ function isString(value) {
38
38
  function isStringArray(value) {
39
39
  return isDefined(value) && Array.isArray(value) && value.every(isString);
40
40
  }
41
+ function isNumber(value) {
42
+ return isDefined(value) && typeof value === "number";
43
+ }
41
44
  function toBase64(value) {
42
45
  try {
43
46
  return btoa(value);
@@ -46,6 +49,17 @@ function toBase64(value) {
46
49
  return buf.from(value).toString("base64");
47
50
  }
48
51
  }
52
+ function deepMerge(a, b) {
53
+ const result = { ...a };
54
+ for (const [key, value] of Object.entries(b)) {
55
+ if (isObject(value) && isObject(result[key])) {
56
+ result[key] = deepMerge(result[key], value);
57
+ } else {
58
+ result[key] = value;
59
+ }
60
+ }
61
+ return result;
62
+ }
49
63
 
50
64
  function getEnvironment() {
51
65
  try {
@@ -80,6 +94,25 @@ function getEnvironment() {
80
94
  fallbackBranch: getGlobalFallbackBranch()
81
95
  };
82
96
  }
97
+ function getEnableBrowserVariable() {
98
+ try {
99
+ if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
100
+ return process.env.XATA_ENABLE_BROWSER === "true";
101
+ }
102
+ } catch (err) {
103
+ }
104
+ try {
105
+ if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
106
+ return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
107
+ }
108
+ } catch (err) {
109
+ }
110
+ try {
111
+ return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
112
+ } catch (err) {
113
+ return void 0;
114
+ }
115
+ }
83
116
  function getGlobalApiKey() {
84
117
  try {
85
118
  return XATA_API_KEY;
@@ -150,7 +183,7 @@ function getFetchImplementation(userFetch) {
150
183
  return fetchImpl;
151
184
  }
152
185
 
153
- const VERSION = "0.0.0-alpha.vfd1a215";
186
+ const VERSION = "0.0.0-alpha.vfd68d20";
154
187
 
155
188
  class ErrorWithCause extends Error {
156
189
  constructor(message, options) {
@@ -207,15 +240,18 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
207
240
  return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
208
241
  };
209
242
  function buildBaseUrl({
243
+ endpoint,
210
244
  path,
211
245
  workspacesApiUrl,
212
246
  apiUrl,
213
- pathParams
247
+ pathParams = {}
214
248
  }) {
215
- if (pathParams?.workspace === void 0)
216
- return `${apiUrl}${path}`;
217
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
218
- return url.replace("{workspaceId}", String(pathParams.workspace));
249
+ if (endpoint === "dataPlane") {
250
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
251
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
252
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
253
+ }
254
+ return `${apiUrl}${path}`;
219
255
  }
220
256
  function hostHeader(url) {
221
257
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -231,14 +267,19 @@ async function fetch$1({
231
267
  queryParams,
232
268
  fetchImpl,
233
269
  apiKey,
270
+ endpoint,
234
271
  apiUrl,
235
272
  workspacesApiUrl,
236
- trace
273
+ trace,
274
+ signal,
275
+ clientID,
276
+ sessionID,
277
+ fetchOptions = {}
237
278
  }) {
238
279
  return trace(
239
280
  `${method.toUpperCase()} ${path}`,
240
281
  async ({ setAttributes }) => {
241
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
282
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
242
283
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
243
284
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
244
285
  setAttributes({
@@ -246,15 +287,19 @@ async function fetch$1({
246
287
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
247
288
  });
248
289
  const response = await fetchImpl(url, {
290
+ ...fetchOptions,
249
291
  method: method.toUpperCase(),
250
292
  body: body ? JSON.stringify(body) : void 0,
251
293
  headers: {
252
294
  "Content-Type": "application/json",
253
295
  "User-Agent": `Xata client-ts/${VERSION}`,
296
+ "X-Xata-Client-ID": clientID ?? "",
297
+ "X-Xata-Session-ID": sessionID ?? "",
254
298
  ...headers,
255
299
  ...hostHeader(fullUrl),
256
300
  Authorization: `Bearer ${apiKey}`
257
- }
301
+ },
302
+ signal
258
303
  });
259
304
  if (response.status === 204) {
260
305
  return {};
@@ -290,271 +335,163 @@ function parseUrl(url) {
290
335
  }
291
336
  }
292
337
 
293
- const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
294
- const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
295
- const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
296
- const getUserAPIKeys = (variables) => fetch$1({
297
- url: "/user/keys",
298
- method: "get",
299
- ...variables
300
- });
301
- const createUserAPIKey = (variables) => fetch$1({
302
- url: "/user/keys/{keyName}",
303
- method: "post",
304
- ...variables
305
- });
306
- const deleteUserAPIKey = (variables) => fetch$1({
307
- url: "/user/keys/{keyName}",
308
- method: "delete",
309
- ...variables
310
- });
311
- const createWorkspace = (variables) => fetch$1({
312
- url: "/workspaces",
313
- method: "post",
314
- ...variables
315
- });
316
- const getWorkspacesList = (variables) => fetch$1({
317
- url: "/workspaces",
318
- method: "get",
319
- ...variables
320
- });
321
- const getWorkspace = (variables) => fetch$1({
322
- url: "/workspaces/{workspaceId}",
323
- method: "get",
324
- ...variables
325
- });
326
- const updateWorkspace = (variables) => fetch$1({
327
- url: "/workspaces/{workspaceId}",
328
- method: "put",
329
- ...variables
330
- });
331
- const deleteWorkspace = (variables) => fetch$1({
332
- url: "/workspaces/{workspaceId}",
333
- method: "delete",
334
- ...variables
335
- });
336
- const getWorkspaceMembersList = (variables) => fetch$1({
337
- url: "/workspaces/{workspaceId}/members",
338
- method: "get",
339
- ...variables
340
- });
341
- const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
342
- const removeWorkspaceMember = (variables) => fetch$1({
343
- url: "/workspaces/{workspaceId}/members/{userId}",
344
- method: "delete",
345
- ...variables
346
- });
347
- const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
348
- const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
349
- const cancelWorkspaceMemberInvite = (variables) => fetch$1({
350
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
351
- method: "delete",
352
- ...variables
353
- });
354
- const resendWorkspaceMemberInvite = (variables) => fetch$1({
355
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
356
- method: "post",
357
- ...variables
358
- });
359
- const acceptWorkspaceMemberInvite = (variables) => fetch$1({
360
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
361
- method: "post",
362
- ...variables
363
- });
364
- const getDatabaseList = (variables) => fetch$1({
365
- url: "/dbs",
366
- method: "get",
367
- ...variables
368
- });
369
- const getBranchList = (variables) => fetch$1({
370
- url: "/dbs/{dbName}",
371
- method: "get",
372
- ...variables
373
- });
374
- const createDatabase = (variables) => fetch$1({
375
- url: "/dbs/{dbName}",
376
- method: "put",
377
- ...variables
378
- });
379
- const deleteDatabase = (variables) => fetch$1({
338
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
339
+
340
+ const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
341
+ const getBranchList = (variables, signal) => dataPlaneFetch({
380
342
  url: "/dbs/{dbName}",
381
- method: "delete",
382
- ...variables
383
- });
384
- const getDatabaseMetadata = (variables) => fetch$1({
385
- url: "/dbs/{dbName}/metadata",
386
- method: "get",
387
- ...variables
388
- });
389
- const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
390
- const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
391
- const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
392
- const resolveBranch = (variables) => fetch$1({
393
- url: "/dbs/{dbName}/resolveBranch",
394
- method: "get",
395
- ...variables
396
- });
397
- const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
398
- const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
399
- const getMigrationRequest = (variables) => fetch$1({
400
- url: "/dbs/{dbName}/migrations/{mrNumber}",
401
343
  method: "get",
402
- ...variables
344
+ ...variables,
345
+ signal
403
346
  });
404
- const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
405
- const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
406
- const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
407
- const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
408
- const mergeMigrationRequest = (variables) => fetch$1({
409
- url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
410
- method: "post",
411
- ...variables
412
- });
413
- const getBranchDetails = (variables) => fetch$1({
347
+ const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
348
+ const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
349
+ const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
350
+ const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
351
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
414
352
  url: "/db/{dbBranchName}",
415
353
  method: "get",
416
- ...variables
354
+ ...variables,
355
+ signal
417
356
  });
418
- const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
419
- const deleteBranch = (variables) => fetch$1({
357
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
358
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
420
359
  url: "/db/{dbBranchName}",
421
360
  method: "delete",
422
- ...variables
361
+ ...variables,
362
+ signal
423
363
  });
424
- const updateBranchMetadata = (variables) => fetch$1({
364
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
425
365
  url: "/db/{dbBranchName}/metadata",
426
366
  method: "put",
427
- ...variables
367
+ ...variables,
368
+ signal
428
369
  });
429
- const getBranchMetadata = (variables) => fetch$1({
370
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
430
371
  url: "/db/{dbBranchName}/metadata",
431
372
  method: "get",
432
- ...variables
433
- });
434
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
435
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
436
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
437
- const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
438
- const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
439
- const updateBranchSchema = (variables) => fetch$1({
440
- url: "/db/{dbBranchName}/schema/update",
441
- method: "post",
442
- ...variables
373
+ ...variables,
374
+ signal
443
375
  });
444
- const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
445
- const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
446
- const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
447
- const getBranchStats = (variables) => fetch$1({
376
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
448
377
  url: "/db/{dbBranchName}/stats",
449
378
  method: "get",
450
- ...variables
379
+ ...variables,
380
+ signal
451
381
  });
452
- const createTable = (variables) => fetch$1({
382
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
383
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
384
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
385
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
386
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
387
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
388
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
389
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
390
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
391
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
392
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
393
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
394
+ method: "get",
395
+ ...variables,
396
+ signal
397
+ });
398
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
399
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
400
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
401
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
402
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
403
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
404
+ method: "post",
405
+ ...variables,
406
+ signal
407
+ });
408
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
409
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
410
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
411
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
412
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
413
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
414
+ const createTable = (variables, signal) => dataPlaneFetch({
453
415
  url: "/db/{dbBranchName}/tables/{tableName}",
454
416
  method: "put",
455
- ...variables
417
+ ...variables,
418
+ signal
456
419
  });
457
- const deleteTable = (variables) => fetch$1({
420
+ const deleteTable = (variables, signal) => dataPlaneFetch({
458
421
  url: "/db/{dbBranchName}/tables/{tableName}",
459
422
  method: "delete",
460
- ...variables
461
- });
462
- const updateTable = (variables) => fetch$1({
463
- url: "/db/{dbBranchName}/tables/{tableName}",
464
- method: "patch",
465
- ...variables
423
+ ...variables,
424
+ signal
466
425
  });
467
- const getTableSchema = (variables) => fetch$1({
426
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
427
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
468
428
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
469
429
  method: "get",
470
- ...variables
471
- });
472
- const setTableSchema = (variables) => fetch$1({
473
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
474
- method: "put",
475
- ...variables
430
+ ...variables,
431
+ signal
476
432
  });
477
- const getTableColumns = (variables) => fetch$1({
433
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
434
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
478
435
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
479
436
  method: "get",
480
- ...variables
481
- });
482
- const addTableColumn = (variables) => fetch$1({
483
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
484
- method: "post",
485
- ...variables
437
+ ...variables,
438
+ signal
486
439
  });
487
- const getColumn = (variables) => fetch$1({
440
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
441
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
442
+ );
443
+ const getColumn = (variables, signal) => dataPlaneFetch({
488
444
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
489
445
  method: "get",
490
- ...variables
446
+ ...variables,
447
+ signal
491
448
  });
492
- const deleteColumn = (variables) => fetch$1({
449
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
450
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
493
451
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
494
452
  method: "delete",
495
- ...variables
453
+ ...variables,
454
+ signal
496
455
  });
497
- const updateColumn = (variables) => fetch$1({
498
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
499
- method: "patch",
500
- ...variables
501
- });
502
- const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
503
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
504
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
505
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
506
- const deleteRecord = (variables) => fetch$1({
507
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
508
- method: "delete",
509
- ...variables
510
- });
511
- const getRecord = (variables) => fetch$1({
456
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
457
+ const getRecord = (variables, signal) => dataPlaneFetch({
512
458
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
513
459
  method: "get",
514
- ...variables
460
+ ...variables,
461
+ signal
515
462
  });
516
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
517
- const queryTable = (variables) => fetch$1({
463
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
464
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
465
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
466
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
467
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
468
+ const queryTable = (variables, signal) => dataPlaneFetch({
518
469
  url: "/db/{dbBranchName}/tables/{tableName}/query",
519
470
  method: "post",
520
- ...variables
471
+ ...variables,
472
+ signal
521
473
  });
522
- const searchTable = (variables) => fetch$1({
523
- url: "/db/{dbBranchName}/tables/{tableName}/search",
474
+ const searchBranch = (variables, signal) => dataPlaneFetch({
475
+ url: "/db/{dbBranchName}/search",
524
476
  method: "post",
525
- ...variables
477
+ ...variables,
478
+ signal
526
479
  });
527
- const searchBranch = (variables) => fetch$1({
528
- url: "/db/{dbBranchName}/search",
480
+ const searchTable = (variables, signal) => dataPlaneFetch({
481
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
529
482
  method: "post",
530
- ...variables
483
+ ...variables,
484
+ signal
531
485
  });
532
- const operationsByTag = {
533
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
534
- workspaces: {
535
- createWorkspace,
536
- getWorkspacesList,
537
- getWorkspace,
538
- updateWorkspace,
539
- deleteWorkspace,
540
- getWorkspaceMembersList,
541
- updateWorkspaceMemberRole,
542
- removeWorkspaceMember,
543
- inviteWorkspaceMember,
544
- updateWorkspaceMemberInvite,
545
- cancelWorkspaceMemberInvite,
546
- resendWorkspaceMemberInvite,
547
- acceptWorkspaceMemberInvite
548
- },
486
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
487
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
488
+ const operationsByTag$2 = {
549
489
  database: {
550
- getDatabaseList,
551
- createDatabase,
552
- deleteDatabase,
553
- getDatabaseMetadata,
554
- getGitBranchesMapping,
555
- addGitBranchesEntry,
556
- removeGitBranchesEntry,
557
- resolveBranch
490
+ dEPRECATEDgetDatabaseList,
491
+ dEPRECATEDcreateDatabase,
492
+ dEPRECATEDdeleteDatabase,
493
+ dEPRECATEDgetDatabaseMetadata,
494
+ dEPRECATEDupdateDatabaseMetadata
558
495
  },
559
496
  branch: {
560
497
  getBranchList,
@@ -563,10 +500,35 @@ const operationsByTag = {
563
500
  deleteBranch,
564
501
  updateBranchMetadata,
565
502
  getBranchMetadata,
566
- getBranchStats
503
+ getBranchStats,
504
+ getGitBranchesMapping,
505
+ addGitBranchesEntry,
506
+ removeGitBranchesEntry,
507
+ resolveBranch
508
+ },
509
+ migrations: {
510
+ getBranchMigrationHistory,
511
+ getBranchMigrationPlan,
512
+ executeBranchMigrationPlan,
513
+ getBranchSchemaHistory,
514
+ compareBranchWithUserSchema,
515
+ compareBranchSchemas,
516
+ updateBranchSchema,
517
+ previewBranchSchemaEdit,
518
+ applyBranchSchemaEdit
519
+ },
520
+ records: {
521
+ branchTransaction,
522
+ insertRecord,
523
+ getRecord,
524
+ insertRecordWithID,
525
+ updateRecordWithID,
526
+ upsertRecordWithID,
527
+ deleteRecord,
528
+ bulkInsertTableRecords
567
529
  },
568
530
  migrationRequests: {
569
- listMigrationRequests,
531
+ queryMigrationRequests,
570
532
  createMigrationRequest,
571
533
  getMigrationRequest,
572
534
  updateMigrationRequest,
@@ -575,17 +537,6 @@ const operationsByTag = {
575
537
  getMigrationRequestIsMerged,
576
538
  mergeMigrationRequest
577
539
  },
578
- branchSchema: {
579
- getBranchMigrationHistory,
580
- executeBranchMigrationPlan,
581
- getBranchMigrationPlan,
582
- compareBranchWithUserSchema,
583
- compareBranchSchemas,
584
- updateBranchSchema,
585
- previewBranchSchemaEdit,
586
- applyBranchSchemaEdit,
587
- getBranchSchemaHistory
588
- },
589
540
  table: {
590
541
  createTable,
591
542
  deleteTable,
@@ -595,23 +546,146 @@ const operationsByTag = {
595
546
  getTableColumns,
596
547
  addTableColumn,
597
548
  getColumn,
598
- deleteColumn,
599
- updateColumn
549
+ updateColumn,
550
+ deleteColumn
600
551
  },
601
- records: {
602
- insertRecord,
603
- insertRecordWithID,
604
- updateRecordWithID,
605
- upsertRecordWithID,
606
- deleteRecord,
607
- getRecord,
608
- bulkInsertTableRecords,
609
- queryTable,
610
- searchTable,
611
- searchBranch
552
+ searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
553
+ };
554
+
555
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
556
+
557
+ const getUser = (variables, signal) => controlPlaneFetch({
558
+ url: "/user",
559
+ method: "get",
560
+ ...variables,
561
+ signal
562
+ });
563
+ const updateUser = (variables, signal) => controlPlaneFetch({
564
+ url: "/user",
565
+ method: "put",
566
+ ...variables,
567
+ signal
568
+ });
569
+ const deleteUser = (variables, signal) => controlPlaneFetch({
570
+ url: "/user",
571
+ method: "delete",
572
+ ...variables,
573
+ signal
574
+ });
575
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
576
+ url: "/user/keys",
577
+ method: "get",
578
+ ...variables,
579
+ signal
580
+ });
581
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
582
+ url: "/user/keys/{keyName}",
583
+ method: "post",
584
+ ...variables,
585
+ signal
586
+ });
587
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
588
+ url: "/user/keys/{keyName}",
589
+ method: "delete",
590
+ ...variables,
591
+ signal
592
+ });
593
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
594
+ url: "/workspaces",
595
+ method: "get",
596
+ ...variables,
597
+ signal
598
+ });
599
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
600
+ url: "/workspaces",
601
+ method: "post",
602
+ ...variables,
603
+ signal
604
+ });
605
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
606
+ url: "/workspaces/{workspaceId}",
607
+ method: "get",
608
+ ...variables,
609
+ signal
610
+ });
611
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
612
+ url: "/workspaces/{workspaceId}",
613
+ method: "put",
614
+ ...variables,
615
+ signal
616
+ });
617
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
618
+ url: "/workspaces/{workspaceId}",
619
+ method: "delete",
620
+ ...variables,
621
+ signal
622
+ });
623
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
624
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
625
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
626
+ url: "/workspaces/{workspaceId}/members/{userId}",
627
+ method: "delete",
628
+ ...variables,
629
+ signal
630
+ });
631
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
632
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
633
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
634
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
635
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
636
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
637
+ url: "/workspaces/{workspaceId}/dbs",
638
+ method: "get",
639
+ ...variables,
640
+ signal
641
+ });
642
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
643
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
644
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
645
+ method: "delete",
646
+ ...variables,
647
+ signal
648
+ });
649
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
650
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
651
+ const listRegions = (variables, signal) => controlPlaneFetch({
652
+ url: "/workspaces/{workspaceId}/regions",
653
+ method: "get",
654
+ ...variables,
655
+ signal
656
+ });
657
+ const operationsByTag$1 = {
658
+ users: { getUser, updateUser, deleteUser },
659
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
660
+ workspaces: {
661
+ getWorkspacesList,
662
+ createWorkspace,
663
+ getWorkspace,
664
+ updateWorkspace,
665
+ deleteWorkspace,
666
+ getWorkspaceMembersList,
667
+ updateWorkspaceMemberRole,
668
+ removeWorkspaceMember
669
+ },
670
+ invites: {
671
+ inviteWorkspaceMember,
672
+ updateWorkspaceMemberInvite,
673
+ cancelWorkspaceMemberInvite,
674
+ acceptWorkspaceMemberInvite,
675
+ resendWorkspaceMemberInvite
676
+ },
677
+ databases: {
678
+ getDatabaseList,
679
+ createDatabase,
680
+ deleteDatabase,
681
+ getDatabaseMetadata,
682
+ updateDatabaseMetadata,
683
+ listRegions
612
684
  }
613
685
  };
614
686
 
687
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
688
+
615
689
  function getHostUrl(provider, type) {
616
690
  if (isHostProviderAlias(provider)) {
617
691
  return providers[provider][type];
@@ -623,11 +697,11 @@ function getHostUrl(provider, type) {
623
697
  const providers = {
624
698
  production: {
625
699
  main: "https://api.xata.io",
626
- workspaces: "https://{workspaceId}.xata.sh"
700
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
627
701
  },
628
702
  staging: {
629
703
  main: "https://staging.xatabase.co",
630
- workspaces: "https://{workspaceId}.staging.xatabase.co"
704
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
631
705
  }
632
706
  };
633
707
  function isHostProviderAlias(alias) {
@@ -636,6 +710,25 @@ function isHostProviderAlias(alias) {
636
710
  function isHostProviderBuilder(builder) {
637
711
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
638
712
  }
713
+ function parseProviderString(provider = "production") {
714
+ if (isHostProviderAlias(provider)) {
715
+ return provider;
716
+ }
717
+ const [main, workspaces] = provider.split(",");
718
+ if (!main || !workspaces)
719
+ return null;
720
+ return { main, workspaces };
721
+ }
722
+ function parseWorkspacesUrlParts(url) {
723
+ if (!isString(url))
724
+ return null;
725
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
726
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
727
+ const match = url.match(regex) || url.match(regexStaging);
728
+ if (!match)
729
+ return null;
730
+ return { workspace: match[1], region: match[2] ?? "eu-west-1" };
731
+ }
639
732
 
640
733
  var __accessCheck$7 = (obj, member, msg) => {
641
734
  if (!member.has(obj))
@@ -679,21 +772,41 @@ class XataApiClient {
679
772
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
680
773
  return __privateGet$7(this, _namespaces).user;
681
774
  }
775
+ get authentication() {
776
+ if (!__privateGet$7(this, _namespaces).authentication)
777
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
778
+ return __privateGet$7(this, _namespaces).authentication;
779
+ }
682
780
  get workspaces() {
683
781
  if (!__privateGet$7(this, _namespaces).workspaces)
684
782
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
685
783
  return __privateGet$7(this, _namespaces).workspaces;
686
784
  }
687
- get databases() {
688
- if (!__privateGet$7(this, _namespaces).databases)
689
- __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
690
- return __privateGet$7(this, _namespaces).databases;
785
+ get invites() {
786
+ if (!__privateGet$7(this, _namespaces).invites)
787
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
788
+ return __privateGet$7(this, _namespaces).invites;
789
+ }
790
+ get database() {
791
+ if (!__privateGet$7(this, _namespaces).database)
792
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
793
+ return __privateGet$7(this, _namespaces).database;
691
794
  }
692
795
  get branches() {
693
796
  if (!__privateGet$7(this, _namespaces).branches)
694
797
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
695
798
  return __privateGet$7(this, _namespaces).branches;
696
799
  }
800
+ get migrations() {
801
+ if (!__privateGet$7(this, _namespaces).migrations)
802
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
803
+ return __privateGet$7(this, _namespaces).migrations;
804
+ }
805
+ get migrationRequests() {
806
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
807
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
808
+ return __privateGet$7(this, _namespaces).migrationRequests;
809
+ }
697
810
  get tables() {
698
811
  if (!__privateGet$7(this, _namespaces).tables)
699
812
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -704,15 +817,10 @@ class XataApiClient {
704
817
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
705
818
  return __privateGet$7(this, _namespaces).records;
706
819
  }
707
- get migrationRequests() {
708
- if (!__privateGet$7(this, _namespaces).migrationRequests)
709
- __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
710
- return __privateGet$7(this, _namespaces).migrationRequests;
711
- }
712
- get branchSchema() {
713
- if (!__privateGet$7(this, _namespaces).branchSchema)
714
- __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
715
- return __privateGet$7(this, _namespaces).branchSchema;
820
+ get searchAndFilter() {
821
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
822
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
823
+ return __privateGet$7(this, _namespaces).searchAndFilter;
716
824
  }
717
825
  }
718
826
  _extraProps = new WeakMap();
@@ -724,24 +832,29 @@ class UserApi {
724
832
  getUser() {
725
833
  return operationsByTag.users.getUser({ ...this.extraProps });
726
834
  }
727
- updateUser(user) {
835
+ updateUser({ user }) {
728
836
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
729
837
  }
730
838
  deleteUser() {
731
839
  return operationsByTag.users.deleteUser({ ...this.extraProps });
732
840
  }
841
+ }
842
+ class AuthenticationApi {
843
+ constructor(extraProps) {
844
+ this.extraProps = extraProps;
845
+ }
733
846
  getUserAPIKeys() {
734
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
847
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
735
848
  }
736
- createUserAPIKey(keyName) {
737
- return operationsByTag.users.createUserAPIKey({
738
- pathParams: { keyName },
849
+ createUserAPIKey({ name }) {
850
+ return operationsByTag.authentication.createUserAPIKey({
851
+ pathParams: { keyName: name },
739
852
  ...this.extraProps
740
853
  });
741
854
  }
742
- deleteUserAPIKey(keyName) {
743
- return operationsByTag.users.deleteUserAPIKey({
744
- pathParams: { keyName },
855
+ deleteUserAPIKey({ name }) {
856
+ return operationsByTag.authentication.deleteUserAPIKey({
857
+ pathParams: { keyName: name },
745
858
  ...this.extraProps
746
859
  });
747
860
  }
@@ -750,189 +863,248 @@ class WorkspaceApi {
750
863
  constructor(extraProps) {
751
864
  this.extraProps = extraProps;
752
865
  }
753
- createWorkspace(workspaceMeta) {
866
+ getWorkspacesList() {
867
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
868
+ }
869
+ createWorkspace({ data }) {
754
870
  return operationsByTag.workspaces.createWorkspace({
755
- body: workspaceMeta,
871
+ body: data,
756
872
  ...this.extraProps
757
873
  });
758
874
  }
759
- getWorkspacesList() {
760
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
761
- }
762
- getWorkspace(workspaceId) {
875
+ getWorkspace({ workspace }) {
763
876
  return operationsByTag.workspaces.getWorkspace({
764
- pathParams: { workspaceId },
877
+ pathParams: { workspaceId: workspace },
765
878
  ...this.extraProps
766
879
  });
767
880
  }
768
- updateWorkspace(workspaceId, workspaceMeta) {
881
+ updateWorkspace({
882
+ workspace,
883
+ update
884
+ }) {
769
885
  return operationsByTag.workspaces.updateWorkspace({
770
- pathParams: { workspaceId },
771
- body: workspaceMeta,
886
+ pathParams: { workspaceId: workspace },
887
+ body: update,
772
888
  ...this.extraProps
773
889
  });
774
890
  }
775
- deleteWorkspace(workspaceId) {
891
+ deleteWorkspace({ workspace }) {
776
892
  return operationsByTag.workspaces.deleteWorkspace({
777
- pathParams: { workspaceId },
893
+ pathParams: { workspaceId: workspace },
778
894
  ...this.extraProps
779
895
  });
780
896
  }
781
- getWorkspaceMembersList(workspaceId) {
897
+ getWorkspaceMembersList({ workspace }) {
782
898
  return operationsByTag.workspaces.getWorkspaceMembersList({
783
- pathParams: { workspaceId },
899
+ pathParams: { workspaceId: workspace },
784
900
  ...this.extraProps
785
901
  });
786
902
  }
787
- updateWorkspaceMemberRole(workspaceId, userId, role) {
903
+ updateWorkspaceMemberRole({
904
+ workspace,
905
+ user,
906
+ role
907
+ }) {
788
908
  return operationsByTag.workspaces.updateWorkspaceMemberRole({
789
- pathParams: { workspaceId, userId },
909
+ pathParams: { workspaceId: workspace, userId: user },
790
910
  body: { role },
791
911
  ...this.extraProps
792
912
  });
793
913
  }
794
- removeWorkspaceMember(workspaceId, userId) {
914
+ removeWorkspaceMember({
915
+ workspace,
916
+ user
917
+ }) {
795
918
  return operationsByTag.workspaces.removeWorkspaceMember({
796
- pathParams: { workspaceId, userId },
919
+ pathParams: { workspaceId: workspace, userId: user },
797
920
  ...this.extraProps
798
921
  });
799
922
  }
800
- inviteWorkspaceMember(workspaceId, email, role) {
801
- return operationsByTag.workspaces.inviteWorkspaceMember({
802
- pathParams: { workspaceId },
923
+ }
924
+ class InvitesApi {
925
+ constructor(extraProps) {
926
+ this.extraProps = extraProps;
927
+ }
928
+ inviteWorkspaceMember({
929
+ workspace,
930
+ email,
931
+ role
932
+ }) {
933
+ return operationsByTag.invites.inviteWorkspaceMember({
934
+ pathParams: { workspaceId: workspace },
803
935
  body: { email, role },
804
936
  ...this.extraProps
805
937
  });
806
938
  }
807
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
808
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
809
- pathParams: { workspaceId, inviteId },
939
+ updateWorkspaceMemberInvite({
940
+ workspace,
941
+ invite,
942
+ role
943
+ }) {
944
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
945
+ pathParams: { workspaceId: workspace, inviteId: invite },
810
946
  body: { role },
811
947
  ...this.extraProps
812
948
  });
813
949
  }
814
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
815
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
816
- pathParams: { workspaceId, inviteId },
950
+ cancelWorkspaceMemberInvite({
951
+ workspace,
952
+ invite
953
+ }) {
954
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
955
+ pathParams: { workspaceId: workspace, inviteId: invite },
817
956
  ...this.extraProps
818
957
  });
819
958
  }
820
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
821
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
822
- pathParams: { workspaceId, inviteId },
959
+ acceptWorkspaceMemberInvite({
960
+ workspace,
961
+ key
962
+ }) {
963
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
964
+ pathParams: { workspaceId: workspace, inviteKey: key },
823
965
  ...this.extraProps
824
966
  });
825
967
  }
826
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
827
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
828
- pathParams: { workspaceId, inviteKey },
968
+ resendWorkspaceMemberInvite({
969
+ workspace,
970
+ invite
971
+ }) {
972
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
973
+ pathParams: { workspaceId: workspace, inviteId: invite },
829
974
  ...this.extraProps
830
975
  });
831
976
  }
832
977
  }
833
- class DatabaseApi {
978
+ class BranchApi {
834
979
  constructor(extraProps) {
835
980
  this.extraProps = extraProps;
836
981
  }
837
- getDatabaseList(workspace) {
838
- return operationsByTag.database.getDatabaseList({
839
- pathParams: { workspace },
840
- ...this.extraProps
841
- });
842
- }
843
- createDatabase(workspace, dbName, options = {}) {
844
- return operationsByTag.database.createDatabase({
845
- pathParams: { workspace, dbName },
846
- body: options,
847
- ...this.extraProps
848
- });
849
- }
850
- deleteDatabase(workspace, dbName) {
851
- return operationsByTag.database.deleteDatabase({
852
- pathParams: { workspace, dbName },
853
- ...this.extraProps
854
- });
855
- }
856
- getDatabaseMetadata(workspace, dbName) {
857
- return operationsByTag.database.getDatabaseMetadata({
858
- pathParams: { workspace, dbName },
982
+ getBranchList({
983
+ workspace,
984
+ region,
985
+ database
986
+ }) {
987
+ return operationsByTag.branch.getBranchList({
988
+ pathParams: { workspace, region, dbName: database },
859
989
  ...this.extraProps
860
990
  });
861
991
  }
862
- getGitBranchesMapping(workspace, dbName) {
863
- return operationsByTag.database.getGitBranchesMapping({
864
- pathParams: { workspace, dbName },
992
+ getBranchDetails({
993
+ workspace,
994
+ region,
995
+ database,
996
+ branch
997
+ }) {
998
+ return operationsByTag.branch.getBranchDetails({
999
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
865
1000
  ...this.extraProps
866
1001
  });
867
1002
  }
868
- addGitBranchesEntry(workspace, dbName, body) {
869
- return operationsByTag.database.addGitBranchesEntry({
870
- pathParams: { workspace, dbName },
871
- body,
1003
+ createBranch({
1004
+ workspace,
1005
+ region,
1006
+ database,
1007
+ branch,
1008
+ from,
1009
+ metadata
1010
+ }) {
1011
+ return operationsByTag.branch.createBranch({
1012
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1013
+ body: { from, metadata },
872
1014
  ...this.extraProps
873
1015
  });
874
1016
  }
875
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
876
- return operationsByTag.database.removeGitBranchesEntry({
877
- pathParams: { workspace, dbName },
878
- queryParams: { gitBranch },
1017
+ deleteBranch({
1018
+ workspace,
1019
+ region,
1020
+ database,
1021
+ branch
1022
+ }) {
1023
+ return operationsByTag.branch.deleteBranch({
1024
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
879
1025
  ...this.extraProps
880
1026
  });
881
1027
  }
882
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
883
- return operationsByTag.database.resolveBranch({
884
- pathParams: { workspace, dbName },
885
- queryParams: { gitBranch, fallbackBranch },
1028
+ updateBranchMetadata({
1029
+ workspace,
1030
+ region,
1031
+ database,
1032
+ branch,
1033
+ metadata
1034
+ }) {
1035
+ return operationsByTag.branch.updateBranchMetadata({
1036
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1037
+ body: metadata,
886
1038
  ...this.extraProps
887
1039
  });
888
1040
  }
889
- }
890
- class BranchApi {
891
- constructor(extraProps) {
892
- this.extraProps = extraProps;
893
- }
894
- getBranchList(workspace, dbName) {
895
- return operationsByTag.branch.getBranchList({
896
- pathParams: { workspace, dbName },
1041
+ getBranchMetadata({
1042
+ workspace,
1043
+ region,
1044
+ database,
1045
+ branch
1046
+ }) {
1047
+ return operationsByTag.branch.getBranchMetadata({
1048
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
897
1049
  ...this.extraProps
898
1050
  });
899
1051
  }
900
- getBranchDetails(workspace, database, branch) {
901
- return operationsByTag.branch.getBranchDetails({
902
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1052
+ getBranchStats({
1053
+ workspace,
1054
+ region,
1055
+ database,
1056
+ branch
1057
+ }) {
1058
+ return operationsByTag.branch.getBranchStats({
1059
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
903
1060
  ...this.extraProps
904
1061
  });
905
1062
  }
906
- createBranch(workspace, database, branch, from, options = {}) {
907
- return operationsByTag.branch.createBranch({
908
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
909
- queryParams: isString(from) ? { from } : void 0,
910
- body: options,
1063
+ getGitBranchesMapping({
1064
+ workspace,
1065
+ region,
1066
+ database
1067
+ }) {
1068
+ return operationsByTag.branch.getGitBranchesMapping({
1069
+ pathParams: { workspace, region, dbName: database },
911
1070
  ...this.extraProps
912
1071
  });
913
1072
  }
914
- deleteBranch(workspace, database, branch) {
915
- return operationsByTag.branch.deleteBranch({
916
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1073
+ addGitBranchesEntry({
1074
+ workspace,
1075
+ region,
1076
+ database,
1077
+ gitBranch,
1078
+ xataBranch
1079
+ }) {
1080
+ return operationsByTag.branch.addGitBranchesEntry({
1081
+ pathParams: { workspace, region, dbName: database },
1082
+ body: { gitBranch, xataBranch },
917
1083
  ...this.extraProps
918
1084
  });
919
1085
  }
920
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
921
- return operationsByTag.branch.updateBranchMetadata({
922
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
923
- body: metadata,
924
- ...this.extraProps
925
- });
926
- }
927
- getBranchMetadata(workspace, database, branch) {
928
- return operationsByTag.branch.getBranchMetadata({
929
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1086
+ removeGitBranchesEntry({
1087
+ workspace,
1088
+ region,
1089
+ database,
1090
+ gitBranch
1091
+ }) {
1092
+ return operationsByTag.branch.removeGitBranchesEntry({
1093
+ pathParams: { workspace, region, dbName: database },
1094
+ queryParams: { gitBranch },
930
1095
  ...this.extraProps
931
1096
  });
932
1097
  }
933
- getBranchStats(workspace, database, branch) {
934
- return operationsByTag.branch.getBranchStats({
935
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1098
+ resolveBranch({
1099
+ workspace,
1100
+ region,
1101
+ database,
1102
+ gitBranch,
1103
+ fallbackBranch
1104
+ }) {
1105
+ return operationsByTag.branch.resolveBranch({
1106
+ pathParams: { workspace, region, dbName: database },
1107
+ queryParams: { gitBranch, fallbackBranch },
936
1108
  ...this.extraProps
937
1109
  });
938
1110
  }
@@ -941,67 +1113,134 @@ class TableApi {
941
1113
  constructor(extraProps) {
942
1114
  this.extraProps = extraProps;
943
1115
  }
944
- createTable(workspace, database, branch, tableName) {
1116
+ createTable({
1117
+ workspace,
1118
+ region,
1119
+ database,
1120
+ branch,
1121
+ table
1122
+ }) {
945
1123
  return operationsByTag.table.createTable({
946
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1124
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
947
1125
  ...this.extraProps
948
1126
  });
949
1127
  }
950
- deleteTable(workspace, database, branch, tableName) {
1128
+ deleteTable({
1129
+ workspace,
1130
+ region,
1131
+ database,
1132
+ branch,
1133
+ table
1134
+ }) {
951
1135
  return operationsByTag.table.deleteTable({
952
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1136
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
953
1137
  ...this.extraProps
954
1138
  });
955
1139
  }
956
- updateTable(workspace, database, branch, tableName, options) {
1140
+ updateTable({
1141
+ workspace,
1142
+ region,
1143
+ database,
1144
+ branch,
1145
+ table,
1146
+ update
1147
+ }) {
957
1148
  return operationsByTag.table.updateTable({
958
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
959
- body: options,
1149
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1150
+ body: update,
960
1151
  ...this.extraProps
961
1152
  });
962
1153
  }
963
- getTableSchema(workspace, database, branch, tableName) {
1154
+ getTableSchema({
1155
+ workspace,
1156
+ region,
1157
+ database,
1158
+ branch,
1159
+ table
1160
+ }) {
964
1161
  return operationsByTag.table.getTableSchema({
965
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1162
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
966
1163
  ...this.extraProps
967
1164
  });
968
1165
  }
969
- setTableSchema(workspace, database, branch, tableName, options) {
1166
+ setTableSchema({
1167
+ workspace,
1168
+ region,
1169
+ database,
1170
+ branch,
1171
+ table,
1172
+ schema
1173
+ }) {
970
1174
  return operationsByTag.table.setTableSchema({
971
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
972
- body: options,
1175
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1176
+ body: schema,
973
1177
  ...this.extraProps
974
1178
  });
975
1179
  }
976
- getTableColumns(workspace, database, branch, tableName) {
1180
+ getTableColumns({
1181
+ workspace,
1182
+ region,
1183
+ database,
1184
+ branch,
1185
+ table
1186
+ }) {
977
1187
  return operationsByTag.table.getTableColumns({
978
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1188
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
979
1189
  ...this.extraProps
980
1190
  });
981
1191
  }
982
- addTableColumn(workspace, database, branch, tableName, column) {
1192
+ addTableColumn({
1193
+ workspace,
1194
+ region,
1195
+ database,
1196
+ branch,
1197
+ table,
1198
+ column
1199
+ }) {
983
1200
  return operationsByTag.table.addTableColumn({
984
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1201
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
985
1202
  body: column,
986
1203
  ...this.extraProps
987
1204
  });
988
1205
  }
989
- getColumn(workspace, database, branch, tableName, columnName) {
1206
+ getColumn({
1207
+ workspace,
1208
+ region,
1209
+ database,
1210
+ branch,
1211
+ table,
1212
+ column
1213
+ }) {
990
1214
  return operationsByTag.table.getColumn({
991
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1215
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
992
1216
  ...this.extraProps
993
1217
  });
994
1218
  }
995
- deleteColumn(workspace, database, branch, tableName, columnName) {
996
- return operationsByTag.table.deleteColumn({
997
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1219
+ updateColumn({
1220
+ workspace,
1221
+ region,
1222
+ database,
1223
+ branch,
1224
+ table,
1225
+ column,
1226
+ update
1227
+ }) {
1228
+ return operationsByTag.table.updateColumn({
1229
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1230
+ body: update,
998
1231
  ...this.extraProps
999
1232
  });
1000
1233
  }
1001
- updateColumn(workspace, database, branch, tableName, columnName, options) {
1002
- return operationsByTag.table.updateColumn({
1003
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1004
- body: options,
1234
+ deleteColumn({
1235
+ workspace,
1236
+ region,
1237
+ database,
1238
+ branch,
1239
+ table,
1240
+ column
1241
+ }) {
1242
+ return operationsByTag.table.deleteColumn({
1243
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1005
1244
  ...this.extraProps
1006
1245
  });
1007
1246
  }
@@ -1010,78 +1249,215 @@ class RecordsApi {
1010
1249
  constructor(extraProps) {
1011
1250
  this.extraProps = extraProps;
1012
1251
  }
1013
- insertRecord(workspace, database, branch, tableName, record, options = {}) {
1252
+ insertRecord({
1253
+ workspace,
1254
+ region,
1255
+ database,
1256
+ branch,
1257
+ table,
1258
+ record,
1259
+ columns
1260
+ }) {
1014
1261
  return operationsByTag.records.insertRecord({
1015
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1016
- queryParams: options,
1262
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1263
+ queryParams: { columns },
1017
1264
  body: record,
1018
1265
  ...this.extraProps
1019
1266
  });
1020
1267
  }
1021
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1268
+ getRecord({
1269
+ workspace,
1270
+ region,
1271
+ database,
1272
+ branch,
1273
+ table,
1274
+ id,
1275
+ columns
1276
+ }) {
1277
+ return operationsByTag.records.getRecord({
1278
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1279
+ queryParams: { columns },
1280
+ ...this.extraProps
1281
+ });
1282
+ }
1283
+ insertRecordWithID({
1284
+ workspace,
1285
+ region,
1286
+ database,
1287
+ branch,
1288
+ table,
1289
+ id,
1290
+ record,
1291
+ columns,
1292
+ createOnly,
1293
+ ifVersion
1294
+ }) {
1022
1295
  return operationsByTag.records.insertRecordWithID({
1023
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1024
- queryParams: options,
1296
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1297
+ queryParams: { columns, createOnly, ifVersion },
1025
1298
  body: record,
1026
1299
  ...this.extraProps
1027
1300
  });
1028
1301
  }
1029
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1302
+ updateRecordWithID({
1303
+ workspace,
1304
+ region,
1305
+ database,
1306
+ branch,
1307
+ table,
1308
+ id,
1309
+ record,
1310
+ columns,
1311
+ ifVersion
1312
+ }) {
1030
1313
  return operationsByTag.records.updateRecordWithID({
1031
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1032
- queryParams: options,
1314
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1315
+ queryParams: { columns, ifVersion },
1033
1316
  body: record,
1034
1317
  ...this.extraProps
1035
1318
  });
1036
1319
  }
1037
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1320
+ upsertRecordWithID({
1321
+ workspace,
1322
+ region,
1323
+ database,
1324
+ branch,
1325
+ table,
1326
+ id,
1327
+ record,
1328
+ columns,
1329
+ ifVersion
1330
+ }) {
1038
1331
  return operationsByTag.records.upsertRecordWithID({
1039
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1040
- queryParams: options,
1332
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1333
+ queryParams: { columns, ifVersion },
1041
1334
  body: record,
1042
1335
  ...this.extraProps
1043
1336
  });
1044
1337
  }
1045
- deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
1338
+ deleteRecord({
1339
+ workspace,
1340
+ region,
1341
+ database,
1342
+ branch,
1343
+ table,
1344
+ id,
1345
+ columns
1346
+ }) {
1046
1347
  return operationsByTag.records.deleteRecord({
1047
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1048
- queryParams: options,
1049
- ...this.extraProps
1050
- });
1051
- }
1052
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
1053
- return operationsByTag.records.getRecord({
1054
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1055
- queryParams: options,
1348
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1349
+ queryParams: { columns },
1056
1350
  ...this.extraProps
1057
1351
  });
1058
1352
  }
1059
- bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
1353
+ bulkInsertTableRecords({
1354
+ workspace,
1355
+ region,
1356
+ database,
1357
+ branch,
1358
+ table,
1359
+ records,
1360
+ columns
1361
+ }) {
1060
1362
  return operationsByTag.records.bulkInsertTableRecords({
1061
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1062
- queryParams: options,
1363
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1364
+ queryParams: { columns },
1063
1365
  body: { records },
1064
1366
  ...this.extraProps
1065
1367
  });
1066
1368
  }
1067
- queryTable(workspace, database, branch, tableName, query) {
1068
- return operationsByTag.records.queryTable({
1069
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1070
- body: query,
1071
- ...this.extraProps
1072
- });
1073
- }
1074
- searchTable(workspace, database, branch, tableName, query) {
1075
- return operationsByTag.records.searchTable({
1076
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1077
- body: query,
1078
- ...this.extraProps
1079
- });
1369
+ }
1370
+ class SearchAndFilterApi {
1371
+ constructor(extraProps) {
1372
+ this.extraProps = extraProps;
1080
1373
  }
1081
- searchBranch(workspace, database, branch, query) {
1082
- return operationsByTag.records.searchBranch({
1083
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1084
- body: query,
1374
+ queryTable({
1375
+ workspace,
1376
+ region,
1377
+ database,
1378
+ branch,
1379
+ table,
1380
+ filter,
1381
+ sort,
1382
+ page,
1383
+ columns,
1384
+ consistency
1385
+ }) {
1386
+ return operationsByTag.searchAndFilter.queryTable({
1387
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1388
+ body: { filter, sort, page, columns, consistency },
1389
+ ...this.extraProps
1390
+ });
1391
+ }
1392
+ searchTable({
1393
+ workspace,
1394
+ region,
1395
+ database,
1396
+ branch,
1397
+ table,
1398
+ query,
1399
+ fuzziness,
1400
+ target,
1401
+ prefix,
1402
+ filter,
1403
+ highlight,
1404
+ boosters
1405
+ }) {
1406
+ return operationsByTag.searchAndFilter.searchTable({
1407
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1408
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
1409
+ ...this.extraProps
1410
+ });
1411
+ }
1412
+ searchBranch({
1413
+ workspace,
1414
+ region,
1415
+ database,
1416
+ branch,
1417
+ tables,
1418
+ query,
1419
+ fuzziness,
1420
+ prefix,
1421
+ highlight
1422
+ }) {
1423
+ return operationsByTag.searchAndFilter.searchBranch({
1424
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1425
+ body: { tables, query, fuzziness, prefix, highlight },
1426
+ ...this.extraProps
1427
+ });
1428
+ }
1429
+ summarizeTable({
1430
+ workspace,
1431
+ region,
1432
+ database,
1433
+ branch,
1434
+ table,
1435
+ filter,
1436
+ columns,
1437
+ summaries,
1438
+ sort,
1439
+ summariesFilter,
1440
+ page,
1441
+ consistency
1442
+ }) {
1443
+ return operationsByTag.searchAndFilter.summarizeTable({
1444
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1445
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1446
+ ...this.extraProps
1447
+ });
1448
+ }
1449
+ aggregateTable({
1450
+ workspace,
1451
+ region,
1452
+ database,
1453
+ branch,
1454
+ table,
1455
+ filter,
1456
+ aggs
1457
+ }) {
1458
+ return operationsByTag.searchAndFilter.aggregateTable({
1459
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1460
+ body: { filter, aggs },
1085
1461
  ...this.extraProps
1086
1462
  });
1087
1463
  }
@@ -1090,123 +1466,281 @@ class MigrationRequestsApi {
1090
1466
  constructor(extraProps) {
1091
1467
  this.extraProps = extraProps;
1092
1468
  }
1093
- listMigrationRequests(workspace, database, options = {}) {
1094
- return operationsByTag.migrationRequests.listMigrationRequests({
1095
- pathParams: { workspace, dbName: database },
1096
- body: options,
1097
- ...this.extraProps
1098
- });
1099
- }
1100
- createMigrationRequest(workspace, database, options) {
1469
+ queryMigrationRequests({
1470
+ workspace,
1471
+ region,
1472
+ database,
1473
+ filter,
1474
+ sort,
1475
+ page,
1476
+ columns
1477
+ }) {
1478
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1479
+ pathParams: { workspace, region, dbName: database },
1480
+ body: { filter, sort, page, columns },
1481
+ ...this.extraProps
1482
+ });
1483
+ }
1484
+ createMigrationRequest({
1485
+ workspace,
1486
+ region,
1487
+ database,
1488
+ migration
1489
+ }) {
1101
1490
  return operationsByTag.migrationRequests.createMigrationRequest({
1102
- pathParams: { workspace, dbName: database },
1103
- body: options,
1491
+ pathParams: { workspace, region, dbName: database },
1492
+ body: migration,
1104
1493
  ...this.extraProps
1105
1494
  });
1106
1495
  }
1107
- getMigrationRequest(workspace, database, migrationRequest) {
1496
+ getMigrationRequest({
1497
+ workspace,
1498
+ region,
1499
+ database,
1500
+ migrationRequest
1501
+ }) {
1108
1502
  return operationsByTag.migrationRequests.getMigrationRequest({
1109
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1503
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1110
1504
  ...this.extraProps
1111
1505
  });
1112
1506
  }
1113
- updateMigrationRequest(workspace, database, migrationRequest, options) {
1507
+ updateMigrationRequest({
1508
+ workspace,
1509
+ region,
1510
+ database,
1511
+ migrationRequest,
1512
+ update
1513
+ }) {
1114
1514
  return operationsByTag.migrationRequests.updateMigrationRequest({
1115
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1116
- body: options,
1515
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1516
+ body: update,
1117
1517
  ...this.extraProps
1118
1518
  });
1119
1519
  }
1120
- listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1520
+ listMigrationRequestsCommits({
1521
+ workspace,
1522
+ region,
1523
+ database,
1524
+ migrationRequest,
1525
+ page
1526
+ }) {
1121
1527
  return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1122
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1123
- body: options,
1528
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1529
+ body: { page },
1124
1530
  ...this.extraProps
1125
1531
  });
1126
1532
  }
1127
- compareMigrationRequest(workspace, database, migrationRequest) {
1533
+ compareMigrationRequest({
1534
+ workspace,
1535
+ region,
1536
+ database,
1537
+ migrationRequest
1538
+ }) {
1128
1539
  return operationsByTag.migrationRequests.compareMigrationRequest({
1129
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1540
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1130
1541
  ...this.extraProps
1131
1542
  });
1132
1543
  }
1133
- getMigrationRequestIsMerged(workspace, database, migrationRequest) {
1544
+ getMigrationRequestIsMerged({
1545
+ workspace,
1546
+ region,
1547
+ database,
1548
+ migrationRequest
1549
+ }) {
1134
1550
  return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1135
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1551
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1136
1552
  ...this.extraProps
1137
1553
  });
1138
1554
  }
1139
- mergeMigrationRequest(workspace, database, migrationRequest) {
1555
+ mergeMigrationRequest({
1556
+ workspace,
1557
+ region,
1558
+ database,
1559
+ migrationRequest
1560
+ }) {
1140
1561
  return operationsByTag.migrationRequests.mergeMigrationRequest({
1141
- pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1562
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1142
1563
  ...this.extraProps
1143
1564
  });
1144
1565
  }
1145
1566
  }
1146
- class BranchSchemaApi {
1567
+ class MigrationsApi {
1147
1568
  constructor(extraProps) {
1148
1569
  this.extraProps = extraProps;
1149
1570
  }
1150
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
1151
- return operationsByTag.branchSchema.getBranchMigrationHistory({
1152
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1153
- body: options,
1571
+ getBranchMigrationHistory({
1572
+ workspace,
1573
+ region,
1574
+ database,
1575
+ branch,
1576
+ limit,
1577
+ startFrom
1578
+ }) {
1579
+ return operationsByTag.migrations.getBranchMigrationHistory({
1580
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1581
+ body: { limit, startFrom },
1582
+ ...this.extraProps
1583
+ });
1584
+ }
1585
+ getBranchMigrationPlan({
1586
+ workspace,
1587
+ region,
1588
+ database,
1589
+ branch,
1590
+ schema
1591
+ }) {
1592
+ return operationsByTag.migrations.getBranchMigrationPlan({
1593
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1594
+ body: schema,
1154
1595
  ...this.extraProps
1155
1596
  });
1156
1597
  }
1157
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1158
- return operationsByTag.branchSchema.executeBranchMigrationPlan({
1159
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1160
- body: migrationPlan,
1598
+ executeBranchMigrationPlan({
1599
+ workspace,
1600
+ region,
1601
+ database,
1602
+ branch,
1603
+ plan
1604
+ }) {
1605
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1606
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1607
+ body: plan,
1161
1608
  ...this.extraProps
1162
1609
  });
1163
1610
  }
1164
- getBranchMigrationPlan(workspace, database, branch, schema) {
1165
- return operationsByTag.branchSchema.getBranchMigrationPlan({
1166
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1167
- body: schema,
1611
+ getBranchSchemaHistory({
1612
+ workspace,
1613
+ region,
1614
+ database,
1615
+ branch,
1616
+ page
1617
+ }) {
1618
+ return operationsByTag.migrations.getBranchSchemaHistory({
1619
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1620
+ body: { page },
1168
1621
  ...this.extraProps
1169
1622
  });
1170
1623
  }
1171
- compareBranchWithUserSchema(workspace, database, branch, schema) {
1172
- return operationsByTag.branchSchema.compareBranchWithUserSchema({
1173
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1624
+ compareBranchWithUserSchema({
1625
+ workspace,
1626
+ region,
1627
+ database,
1628
+ branch,
1629
+ schema
1630
+ }) {
1631
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1632
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1174
1633
  body: { schema },
1175
1634
  ...this.extraProps
1176
1635
  });
1177
1636
  }
1178
- compareBranchSchemas(workspace, database, branch, branchName, schema) {
1179
- return operationsByTag.branchSchema.compareBranchSchemas({
1180
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1637
+ compareBranchSchemas({
1638
+ workspace,
1639
+ region,
1640
+ database,
1641
+ branch,
1642
+ compare,
1643
+ schema
1644
+ }) {
1645
+ return operationsByTag.migrations.compareBranchSchemas({
1646
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1181
1647
  body: { schema },
1182
1648
  ...this.extraProps
1183
1649
  });
1184
1650
  }
1185
- updateBranchSchema(workspace, database, branch, migration) {
1186
- return operationsByTag.branchSchema.updateBranchSchema({
1187
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1651
+ updateBranchSchema({
1652
+ workspace,
1653
+ region,
1654
+ database,
1655
+ branch,
1656
+ migration
1657
+ }) {
1658
+ return operationsByTag.migrations.updateBranchSchema({
1659
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1188
1660
  body: migration,
1189
1661
  ...this.extraProps
1190
1662
  });
1191
1663
  }
1192
- previewBranchSchemaEdit(workspace, database, branch, migration) {
1193
- return operationsByTag.branchSchema.previewBranchSchemaEdit({
1194
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1195
- body: migration,
1664
+ previewBranchSchemaEdit({
1665
+ workspace,
1666
+ region,
1667
+ database,
1668
+ branch,
1669
+ data
1670
+ }) {
1671
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1672
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1673
+ body: data,
1196
1674
  ...this.extraProps
1197
1675
  });
1198
1676
  }
1199
- applyBranchSchemaEdit(workspace, database, branch, edits) {
1200
- return operationsByTag.branchSchema.applyBranchSchemaEdit({
1201
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1677
+ applyBranchSchemaEdit({
1678
+ workspace,
1679
+ region,
1680
+ database,
1681
+ branch,
1682
+ edits
1683
+ }) {
1684
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1685
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1202
1686
  body: { edits },
1203
1687
  ...this.extraProps
1204
1688
  });
1205
1689
  }
1206
- getBranchSchemaHistory(workspace, database, branch, options = {}) {
1207
- return operationsByTag.branchSchema.getBranchSchemaHistory({
1208
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1209
- body: options,
1690
+ }
1691
+ class DatabaseApi {
1692
+ constructor(extraProps) {
1693
+ this.extraProps = extraProps;
1694
+ }
1695
+ getDatabaseList({ workspace }) {
1696
+ return operationsByTag.databases.getDatabaseList({
1697
+ pathParams: { workspaceId: workspace },
1698
+ ...this.extraProps
1699
+ });
1700
+ }
1701
+ createDatabase({
1702
+ workspace,
1703
+ database,
1704
+ data
1705
+ }) {
1706
+ return operationsByTag.databases.createDatabase({
1707
+ pathParams: { workspaceId: workspace, dbName: database },
1708
+ body: data,
1709
+ ...this.extraProps
1710
+ });
1711
+ }
1712
+ deleteDatabase({
1713
+ workspace,
1714
+ database
1715
+ }) {
1716
+ return operationsByTag.databases.deleteDatabase({
1717
+ pathParams: { workspaceId: workspace, dbName: database },
1718
+ ...this.extraProps
1719
+ });
1720
+ }
1721
+ getDatabaseMetadata({
1722
+ workspace,
1723
+ database
1724
+ }) {
1725
+ return operationsByTag.databases.getDatabaseMetadata({
1726
+ pathParams: { workspaceId: workspace, dbName: database },
1727
+ ...this.extraProps
1728
+ });
1729
+ }
1730
+ updateDatabaseMetadata({
1731
+ workspace,
1732
+ database,
1733
+ metadata
1734
+ }) {
1735
+ return operationsByTag.databases.updateDatabaseMetadata({
1736
+ pathParams: { workspaceId: workspace, dbName: database },
1737
+ body: metadata,
1738
+ ...this.extraProps
1739
+ });
1740
+ }
1741
+ listRegions({ workspace }) {
1742
+ return operationsByTag.databases.listRegions({
1743
+ pathParams: { workspaceId: workspace },
1210
1744
  ...this.extraProps
1211
1745
  });
1212
1746
  }
@@ -1222,6 +1756,20 @@ class XataApiPlugin {
1222
1756
  class XataPlugin {
1223
1757
  }
1224
1758
 
1759
+ function generateUUID() {
1760
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1761
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1762
+ return v.toString(16);
1763
+ });
1764
+ }
1765
+
1766
+ function cleanFilter(filter) {
1767
+ if (!filter)
1768
+ return void 0;
1769
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1770
+ return values.length > 0 ? filter : void 0;
1771
+ }
1772
+
1225
1773
  var __accessCheck$6 = (obj, member, msg) => {
1226
1774
  if (!member.has(obj))
1227
1775
  throw TypeError("Cannot " + msg);
@@ -1254,11 +1802,11 @@ class Page {
1254
1802
  async previousPage(size, offset) {
1255
1803
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1256
1804
  }
1257
- async firstPage(size, offset) {
1258
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1805
+ async startPage(size, offset) {
1806
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1259
1807
  }
1260
- async lastPage(size, offset) {
1261
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1808
+ async endPage(size, offset) {
1809
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1262
1810
  }
1263
1811
  hasNextPage() {
1264
1812
  return this.meta.page.more;
@@ -1270,7 +1818,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1270
1818
  const PAGINATION_MAX_OFFSET = 800;
1271
1819
  const PAGINATION_DEFAULT_OFFSET = 0;
1272
1820
  function isCursorPaginationOptions(options) {
1273
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1821
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1274
1822
  }
1275
1823
  const _RecordArray = class extends Array {
1276
1824
  constructor(...args) {
@@ -1302,12 +1850,12 @@ const _RecordArray = class extends Array {
1302
1850
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1303
1851
  return new _RecordArray(newPage);
1304
1852
  }
1305
- async firstPage(size, offset) {
1306
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1853
+ async startPage(size, offset) {
1854
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1307
1855
  return new _RecordArray(newPage);
1308
1856
  }
1309
- async lastPage(size, offset) {
1310
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1857
+ async endPage(size, offset) {
1858
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1311
1859
  return new _RecordArray(newPage);
1312
1860
  }
1313
1861
  hasNextPage() {
@@ -1335,9 +1883,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1335
1883
  setter ? setter.call(obj, value) : member.set(obj, value);
1336
1884
  return value;
1337
1885
  };
1338
- var _table$1, _repository, _data;
1886
+ var __privateMethod$3 = (obj, member, method) => {
1887
+ __accessCheck$5(obj, member, "access private method");
1888
+ return method;
1889
+ };
1890
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1339
1891
  const _Query = class {
1340
1892
  constructor(repository, table, data, rawParent) {
1893
+ __privateAdd$5(this, _cleanFilterConstraint);
1341
1894
  __privateAdd$5(this, _table$1, void 0);
1342
1895
  __privateAdd$5(this, _repository, void 0);
1343
1896
  __privateAdd$5(this, _data, { filter: {} });
@@ -1356,9 +1909,10 @@ const _Query = class {
1356
1909
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1357
1910
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1358
1911
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1359
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1912
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1360
1913
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1361
1914
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1915
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1362
1916
  this.any = this.any.bind(this);
1363
1917
  this.all = this.all.bind(this);
1364
1918
  this.not = this.not.bind(this);
@@ -1394,22 +1948,17 @@ const _Query = class {
1394
1948
  }
1395
1949
  filter(a, b) {
1396
1950
  if (arguments.length === 1) {
1397
- const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
1951
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1952
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1953
+ }));
1398
1954
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1399
1955
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1400
1956
  } else {
1401
- const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
1957
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
1402
1958
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1403
1959
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1404
1960
  }
1405
1961
  }
1406
- defaultFilter(column, value) {
1407
- const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1408
- if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1409
- return { $includes: value };
1410
- }
1411
- return value;
1412
- }
1413
1962
  sort(column, direction = "asc") {
1414
1963
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1415
1964
  const sort = [...originalSort, { column, direction }];
@@ -1444,11 +1993,20 @@ const _Query = class {
1444
1993
  }
1445
1994
  }
1446
1995
  async getMany(options = {}) {
1447
- const page = await this.getPaginated(options);
1996
+ const { pagination = {}, ...rest } = options;
1997
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
1998
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
1999
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
2000
+ const results = [...page.records];
2001
+ while (page.hasNextPage() && results.length < size) {
2002
+ page = await page.nextPage();
2003
+ results.push(...page.records);
2004
+ }
1448
2005
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1449
2006
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1450
2007
  }
1451
- return page.records;
2008
+ const array = new RecordArray(page, results.slice(0, size));
2009
+ return array;
1452
2010
  }
1453
2011
  async getAll(options = {}) {
1454
2012
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1462,19 +2020,35 @@ const _Query = class {
1462
2020
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1463
2021
  return records[0] ?? null;
1464
2022
  }
2023
+ async getFirstOrThrow(options = {}) {
2024
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2025
+ if (records[0] === void 0)
2026
+ throw new Error("No results found.");
2027
+ return records[0];
2028
+ }
2029
+ async summarize(params = {}) {
2030
+ const { summaries, summariesFilter, ...options } = params;
2031
+ const query = new _Query(
2032
+ __privateGet$5(this, _repository),
2033
+ __privateGet$5(this, _table$1),
2034
+ options,
2035
+ __privateGet$5(this, _data)
2036
+ );
2037
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2038
+ }
1465
2039
  cache(ttl) {
1466
2040
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1467
2041
  }
1468
2042
  nextPage(size, offset) {
1469
- return this.firstPage(size, offset);
2043
+ return this.startPage(size, offset);
1470
2044
  }
1471
2045
  previousPage(size, offset) {
1472
- return this.firstPage(size, offset);
2046
+ return this.startPage(size, offset);
1473
2047
  }
1474
- firstPage(size, offset) {
2048
+ startPage(size, offset) {
1475
2049
  return this.getPaginated({ pagination: { size, offset } });
1476
2050
  }
1477
- lastPage(size, offset) {
2051
+ endPage(size, offset) {
1478
2052
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
1479
2053
  }
1480
2054
  hasNextPage() {
@@ -1485,9 +2059,20 @@ let Query = _Query;
1485
2059
  _table$1 = new WeakMap();
1486
2060
  _repository = new WeakMap();
1487
2061
  _data = new WeakMap();
2062
+ _cleanFilterConstraint = new WeakSet();
2063
+ cleanFilterConstraint_fn = function(column, value) {
2064
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2065
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2066
+ return { $includes: value };
2067
+ }
2068
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
2069
+ return value.id;
2070
+ }
2071
+ return value;
2072
+ };
1488
2073
  function cleanParent(data, parent) {
1489
2074
  if (isCursorPaginationOptions(data.pagination)) {
1490
- return { ...parent, sorting: void 0, filter: void 0 };
2075
+ return { ...parent, sort: void 0, filter: void 0 };
1491
2076
  }
1492
2077
  return parent;
1493
2078
  }
@@ -1572,10 +2157,13 @@ class RestRepository extends Query {
1572
2157
  __privateAdd$4(this, _schemaTables$2, void 0);
1573
2158
  __privateAdd$4(this, _trace, void 0);
1574
2159
  __privateSet$4(this, _table, options.table);
1575
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1576
2160
  __privateSet$4(this, _db, options.db);
1577
2161
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1578
2162
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2163
+ __privateSet$4(this, _getFetchProps, async () => {
2164
+ const props = await options.pluginOptions.getFetchProps();
2165
+ return { ...props, sessionID: generateUUID() };
2166
+ });
1579
2167
  const trace = options.pluginOptions.trace ?? defaultTrace;
1580
2168
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1581
2169
  return trace(name, fn, {
@@ -1586,8 +2174,9 @@ class RestRepository extends Query {
1586
2174
  });
1587
2175
  });
1588
2176
  }
1589
- async create(a, b, c) {
2177
+ async create(a, b, c, d) {
1590
2178
  return __privateGet$4(this, _trace).call(this, "create", async () => {
2179
+ const ifVersion = parseIfVersion(b, c, d);
1591
2180
  if (Array.isArray(a)) {
1592
2181
  if (a.length === 0)
1593
2182
  return [];
@@ -1598,13 +2187,13 @@ class RestRepository extends Query {
1598
2187
  if (a === "")
1599
2188
  throw new Error("The id can't be empty");
1600
2189
  const columns = isStringArray(c) ? c : void 0;
1601
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
2190
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
1602
2191
  }
1603
2192
  if (isObject(a) && isString(a.id)) {
1604
2193
  if (a.id === "")
1605
2194
  throw new Error("The id can't be empty");
1606
2195
  const columns = isStringArray(b) ? b : void 0;
1607
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2196
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
1608
2197
  }
1609
2198
  if (isObject(a)) {
1610
2199
  const columns = isStringArray(b) ? b : void 0;
@@ -1635,6 +2224,7 @@ class RestRepository extends Query {
1635
2224
  pathParams: {
1636
2225
  workspace: "{workspaceId}",
1637
2226
  dbBranchName: "{dbBranch}",
2227
+ region: "{region}",
1638
2228
  tableName: __privateGet$4(this, _table),
1639
2229
  recordId: id
1640
2230
  },
@@ -1642,7 +2232,7 @@ class RestRepository extends Query {
1642
2232
  ...fetchProps
1643
2233
  });
1644
2234
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1645
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2235
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1646
2236
  } catch (e) {
1647
2237
  if (isObject(e) && e.status === 404) {
1648
2238
  return null;
@@ -1653,8 +2243,28 @@ class RestRepository extends Query {
1653
2243
  return null;
1654
2244
  });
1655
2245
  }
1656
- async update(a, b, c) {
2246
+ async readOrThrow(a, b) {
2247
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
2248
+ const result = await this.read(a, b);
2249
+ if (Array.isArray(result)) {
2250
+ const missingIds = compact(
2251
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2252
+ );
2253
+ if (missingIds.length > 0) {
2254
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2255
+ }
2256
+ return result;
2257
+ }
2258
+ if (result === null) {
2259
+ const id = extractId(a) ?? "unknown";
2260
+ throw new Error(`Record with id ${id} not found`);
2261
+ }
2262
+ return result;
2263
+ });
2264
+ }
2265
+ async update(a, b, c, d) {
1657
2266
  return __privateGet$4(this, _trace).call(this, "update", async () => {
2267
+ const ifVersion = parseIfVersion(b, c, d);
1658
2268
  if (Array.isArray(a)) {
1659
2269
  if (a.length === 0)
1660
2270
  return [];
@@ -1666,17 +2276,37 @@ class RestRepository extends Query {
1666
2276
  }
1667
2277
  if (isString(a) && isObject(b)) {
1668
2278
  const columns = isStringArray(c) ? c : void 0;
1669
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
2279
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1670
2280
  }
1671
2281
  if (isObject(a) && isString(a.id)) {
1672
2282
  const columns = isStringArray(b) ? b : void 0;
1673
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2283
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1674
2284
  }
1675
2285
  throw new Error("Invalid arguments for update method");
1676
2286
  });
1677
2287
  }
1678
- async createOrUpdate(a, b, c) {
2288
+ async updateOrThrow(a, b, c, d) {
2289
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
2290
+ const result = await this.update(a, b, c, d);
2291
+ if (Array.isArray(result)) {
2292
+ const missingIds = compact(
2293
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2294
+ );
2295
+ if (missingIds.length > 0) {
2296
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2297
+ }
2298
+ return result;
2299
+ }
2300
+ if (result === null) {
2301
+ const id = extractId(a) ?? "unknown";
2302
+ throw new Error(`Record with id ${id} not found`);
2303
+ }
2304
+ return result;
2305
+ });
2306
+ }
2307
+ async createOrUpdate(a, b, c, d) {
1679
2308
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2309
+ const ifVersion = parseIfVersion(b, c, d);
1680
2310
  if (Array.isArray(a)) {
1681
2311
  if (a.length === 0)
1682
2312
  return [];
@@ -1688,15 +2318,35 @@ class RestRepository extends Query {
1688
2318
  }
1689
2319
  if (isString(a) && isObject(b)) {
1690
2320
  const columns = isStringArray(c) ? c : void 0;
1691
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
2321
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
1692
2322
  }
1693
2323
  if (isObject(a) && isString(a.id)) {
1694
2324
  const columns = isStringArray(c) ? c : void 0;
1695
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
2325
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
1696
2326
  }
1697
2327
  throw new Error("Invalid arguments for createOrUpdate method");
1698
2328
  });
1699
2329
  }
2330
+ async createOrReplace(a, b, c, d) {
2331
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2332
+ const ifVersion = parseIfVersion(b, c, d);
2333
+ if (Array.isArray(a)) {
2334
+ if (a.length === 0)
2335
+ return [];
2336
+ const columns = isStringArray(b) ? b : ["*"];
2337
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2338
+ }
2339
+ if (isString(a) && isObject(b)) {
2340
+ const columns = isStringArray(c) ? c : void 0;
2341
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2342
+ }
2343
+ if (isObject(a) && isString(a.id)) {
2344
+ const columns = isStringArray(c) ? c : void 0;
2345
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2346
+ }
2347
+ throw new Error("Invalid arguments for createOrReplace method");
2348
+ });
2349
+ }
1700
2350
  async delete(a, b) {
1701
2351
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1702
2352
  if (Array.isArray(a)) {
@@ -1716,11 +2366,34 @@ class RestRepository extends Query {
1716
2366
  throw new Error("Invalid arguments for delete method");
1717
2367
  });
1718
2368
  }
2369
+ async deleteOrThrow(a, b) {
2370
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
2371
+ const result = await this.delete(a, b);
2372
+ if (Array.isArray(result)) {
2373
+ const missingIds = compact(
2374
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2375
+ );
2376
+ if (missingIds.length > 0) {
2377
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2378
+ }
2379
+ return result;
2380
+ } else if (result === null) {
2381
+ const id = extractId(a) ?? "unknown";
2382
+ throw new Error(`Record with id ${id} not found`);
2383
+ }
2384
+ return result;
2385
+ });
2386
+ }
1719
2387
  async search(query, options = {}) {
1720
2388
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1721
2389
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1722
2390
  const { records } = await searchTable({
1723
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2391
+ pathParams: {
2392
+ workspace: "{workspaceId}",
2393
+ dbBranchName: "{dbBranch}",
2394
+ region: "{region}",
2395
+ tableName: __privateGet$4(this, _table)
2396
+ },
1724
2397
  body: {
1725
2398
  query,
1726
2399
  fuzziness: options.fuzziness,
@@ -1732,7 +2405,23 @@ class RestRepository extends Query {
1732
2405
  ...fetchProps
1733
2406
  });
1734
2407
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1735
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2408
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2409
+ });
2410
+ }
2411
+ async aggregate(aggs, filter) {
2412
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2413
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2414
+ const result = await aggregateTable({
2415
+ pathParams: {
2416
+ workspace: "{workspaceId}",
2417
+ dbBranchName: "{dbBranch}",
2418
+ region: "{region}",
2419
+ tableName: __privateGet$4(this, _table)
2420
+ },
2421
+ body: { aggs, filter },
2422
+ ...fetchProps
2423
+ });
2424
+ return result;
1736
2425
  });
1737
2426
  }
1738
2427
  async query(query) {
@@ -1741,24 +2430,55 @@ class RestRepository extends Query {
1741
2430
  if (cacheQuery)
1742
2431
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1743
2432
  const data = query.getQueryOptions();
1744
- const body = {
1745
- filter: cleanFilter(data.filter),
1746
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1747
- page: data.pagination,
1748
- columns: data.columns
1749
- };
1750
2433
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1751
2434
  const { meta, records: objects } = await queryTable({
1752
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1753
- body,
2435
+ pathParams: {
2436
+ workspace: "{workspaceId}",
2437
+ dbBranchName: "{dbBranch}",
2438
+ region: "{region}",
2439
+ tableName: __privateGet$4(this, _table)
2440
+ },
2441
+ body: {
2442
+ filter: cleanFilter(data.filter),
2443
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2444
+ page: data.pagination,
2445
+ columns: data.columns ?? ["*"]
2446
+ },
2447
+ fetchOptions: data.fetchOptions,
1754
2448
  ...fetchProps
1755
2449
  });
1756
2450
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1757
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
2451
+ const records = objects.map(
2452
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2453
+ );
1758
2454
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1759
2455
  return new Page(query, meta, records);
1760
2456
  });
1761
2457
  }
2458
+ async summarizeTable(query, summaries, summariesFilter) {
2459
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2460
+ const data = query.getQueryOptions();
2461
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2462
+ const result = await summarizeTable({
2463
+ pathParams: {
2464
+ workspace: "{workspaceId}",
2465
+ dbBranchName: "{dbBranch}",
2466
+ region: "{region}",
2467
+ tableName: __privateGet$4(this, _table)
2468
+ },
2469
+ body: {
2470
+ filter: cleanFilter(data.filter),
2471
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2472
+ columns: data.columns,
2473
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2474
+ summaries,
2475
+ summariesFilter
2476
+ },
2477
+ ...fetchProps
2478
+ });
2479
+ return result;
2480
+ });
2481
+ }
1762
2482
  }
1763
2483
  _table = new WeakMap();
1764
2484
  _getFetchProps = new WeakMap();
@@ -1774,6 +2494,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1774
2494
  pathParams: {
1775
2495
  workspace: "{workspaceId}",
1776
2496
  dbBranchName: "{dbBranch}",
2497
+ region: "{region}",
1777
2498
  tableName: __privateGet$4(this, _table)
1778
2499
  },
1779
2500
  queryParams: { columns },
@@ -1781,32 +2502,38 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1781
2502
  ...fetchProps
1782
2503
  });
1783
2504
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1784
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2505
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1785
2506
  };
1786
2507
  _insertRecordWithId = new WeakSet();
1787
- insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
2508
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
1788
2509
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1789
2510
  const record = transformObjectLinks(object);
1790
2511
  const response = await insertRecordWithID({
1791
2512
  pathParams: {
1792
2513
  workspace: "{workspaceId}",
1793
2514
  dbBranchName: "{dbBranch}",
2515
+ region: "{region}",
1794
2516
  tableName: __privateGet$4(this, _table),
1795
2517
  recordId
1796
2518
  },
1797
2519
  body: record,
1798
- queryParams: { createOnly: true, columns },
2520
+ queryParams: { createOnly, columns, ifVersion },
1799
2521
  ...fetchProps
1800
2522
  });
1801
2523
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1802
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2524
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1803
2525
  };
1804
2526
  _bulkInsertTableRecords = new WeakSet();
1805
2527
  bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1806
2528
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1807
2529
  const records = objects.map((object) => transformObjectLinks(object));
1808
2530
  const response = await bulkInsertTableRecords({
1809
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2531
+ pathParams: {
2532
+ workspace: "{workspaceId}",
2533
+ dbBranchName: "{dbBranch}",
2534
+ region: "{region}",
2535
+ tableName: __privateGet$4(this, _table)
2536
+ },
1810
2537
  queryParams: { columns },
1811
2538
  body: { records },
1812
2539
  ...fetchProps
@@ -1815,21 +2542,27 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1815
2542
  throw new Error("Request included columns but server didn't include them");
1816
2543
  }
1817
2544
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1818
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2545
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
1819
2546
  };
1820
2547
  _updateRecordWithID = new WeakSet();
1821
- updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2548
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1822
2549
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1823
2550
  const record = transformObjectLinks(object);
1824
2551
  try {
1825
2552
  const response = await updateRecordWithID({
1826
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1827
- queryParams: { columns },
2553
+ pathParams: {
2554
+ workspace: "{workspaceId}",
2555
+ dbBranchName: "{dbBranch}",
2556
+ region: "{region}",
2557
+ tableName: __privateGet$4(this, _table),
2558
+ recordId
2559
+ },
2560
+ queryParams: { columns, ifVersion },
1828
2561
  body: record,
1829
2562
  ...fetchProps
1830
2563
  });
1831
2564
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1832
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2565
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1833
2566
  } catch (e) {
1834
2567
  if (isObject(e) && e.status === 404) {
1835
2568
  return null;
@@ -1838,28 +2571,40 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1838
2571
  }
1839
2572
  };
1840
2573
  _upsertRecordWithID = new WeakSet();
1841
- upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
2574
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1842
2575
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1843
2576
  const response = await upsertRecordWithID({
1844
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1845
- queryParams: { columns },
2577
+ pathParams: {
2578
+ workspace: "{workspaceId}",
2579
+ dbBranchName: "{dbBranch}",
2580
+ region: "{region}",
2581
+ tableName: __privateGet$4(this, _table),
2582
+ recordId
2583
+ },
2584
+ queryParams: { columns, ifVersion },
1846
2585
  body: object,
1847
2586
  ...fetchProps
1848
2587
  });
1849
2588
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1850
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2589
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1851
2590
  };
1852
2591
  _deleteRecord = new WeakSet();
1853
2592
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
1854
2593
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1855
2594
  try {
1856
2595
  const response = await deleteRecord({
1857
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2596
+ pathParams: {
2597
+ workspace: "{workspaceId}",
2598
+ dbBranchName: "{dbBranch}",
2599
+ region: "{region}",
2600
+ tableName: __privateGet$4(this, _table),
2601
+ recordId
2602
+ },
1858
2603
  queryParams: { columns },
1859
2604
  ...fetchProps
1860
2605
  });
1861
2606
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1862
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2607
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1863
2608
  } catch (e) {
1864
2609
  if (isObject(e) && e.status === 404) {
1865
2610
  return null;
@@ -1889,7 +2634,7 @@ getSchemaTables_fn$1 = async function() {
1889
2634
  return __privateGet$4(this, _schemaTables$2);
1890
2635
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1891
2636
  const { schema } = await getBranchDetails({
1892
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2637
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1893
2638
  ...fetchProps
1894
2639
  });
1895
2640
  __privateSet$4(this, _schemaTables$2, schema.tables);
@@ -1902,7 +2647,7 @@ const transformObjectLinks = (object) => {
1902
2647
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1903
2648
  }, {});
1904
2649
  };
1905
- const initObject = (db, schemaTables, table, object) => {
2650
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1906
2651
  const result = {};
1907
2652
  const { xata, ...rest } = object ?? {};
1908
2653
  Object.assign(result, rest);
@@ -1910,6 +2655,8 @@ const initObject = (db, schemaTables, table, object) => {
1910
2655
  if (!columns)
1911
2656
  console.error(`Table ${table} not found in schema`);
1912
2657
  for (const column of columns ?? []) {
2658
+ if (!isValidColumn(selectedColumns, column))
2659
+ continue;
1913
2660
  const value = result[column.name];
1914
2661
  switch (column.type) {
1915
2662
  case "datetime": {
@@ -1926,17 +2673,42 @@ const initObject = (db, schemaTables, table, object) => {
1926
2673
  if (!linkTable) {
1927
2674
  console.error(`Failed to parse link for field ${column.name}`);
1928
2675
  } else if (isObject(value)) {
1929
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2676
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2677
+ if (item === column.name) {
2678
+ return [...acc, "*"];
2679
+ }
2680
+ if (item.startsWith(`${column.name}.`)) {
2681
+ const [, ...path] = item.split(".");
2682
+ return [...acc, path.join(".")];
2683
+ }
2684
+ return acc;
2685
+ }, []);
2686
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2687
+ } else {
2688
+ result[column.name] = null;
1930
2689
  }
1931
2690
  break;
1932
2691
  }
2692
+ default:
2693
+ result[column.name] = value ?? null;
2694
+ if (column.notNull === true && value === null) {
2695
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2696
+ }
2697
+ break;
1933
2698
  }
1934
2699
  }
1935
2700
  result.read = function(columns2) {
1936
2701
  return db[table].read(result["id"], columns2);
1937
2702
  };
1938
- result.update = function(data, columns2) {
1939
- return db[table].update(result["id"], data, columns2);
2703
+ result.update = function(data, b, c) {
2704
+ const columns2 = isStringArray(b) ? b : ["*"];
2705
+ const ifVersion = parseIfVersion(b, c);
2706
+ return db[table].update(result["id"], data, columns2, { ifVersion });
2707
+ };
2708
+ result.replace = function(data, b, c) {
2709
+ const columns2 = isStringArray(b) ? b : ["*"];
2710
+ const ifVersion = parseIfVersion(b, c);
2711
+ return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
1940
2712
  };
1941
2713
  result.delete = function() {
1942
2714
  return db[table].delete(result["id"]);
@@ -1944,7 +2716,7 @@ const initObject = (db, schemaTables, table, object) => {
1944
2716
  result.getMetadata = function() {
1945
2717
  return xata;
1946
2718
  };
1947
- for (const prop of ["read", "update", "delete", "getMetadata"]) {
2719
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
1948
2720
  Object.defineProperty(result, prop, { enumerable: false });
1949
2721
  }
1950
2722
  Object.freeze(result);
@@ -1960,11 +2732,22 @@ function extractId(value) {
1960
2732
  return value.id;
1961
2733
  return void 0;
1962
2734
  }
1963
- function cleanFilter(filter) {
1964
- if (!filter)
1965
- return void 0;
1966
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1967
- return values.length > 0 ? filter : void 0;
2735
+ function isValidColumn(columns, column) {
2736
+ if (columns.includes("*"))
2737
+ return true;
2738
+ if (column.type === "link") {
2739
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2740
+ return linkColumns.length > 0;
2741
+ }
2742
+ return columns.includes(column.name);
2743
+ }
2744
+ function parseIfVersion(...args) {
2745
+ for (const arg of args) {
2746
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
2747
+ return arg.ifVersion;
2748
+ }
2749
+ }
2750
+ return void 0;
1968
2751
  }
1969
2752
 
1970
2753
  var __accessCheck$3 = (obj, member, msg) => {
@@ -2131,7 +2914,7 @@ class SearchPlugin extends XataPlugin {
2131
2914
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
2132
2915
  return records.map((record) => {
2133
2916
  const { table = "orphan" } = record.xata;
2134
- return { table, record: initObject(this.db, schemaTables, table, record) };
2917
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
2135
2918
  });
2136
2919
  },
2137
2920
  byTable: async (query, options = {}) => {
@@ -2140,7 +2923,7 @@ class SearchPlugin extends XataPlugin {
2140
2923
  return records.reduce((acc, record) => {
2141
2924
  const { table = "orphan" } = record.xata;
2142
2925
  const items = acc[table] ?? [];
2143
- const item = initObject(this.db, schemaTables, table, record);
2926
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
2144
2927
  return { ...acc, [table]: [...items, item] };
2145
2928
  }, {});
2146
2929
  }
@@ -2153,7 +2936,7 @@ search_fn = async function(query, options, getFetchProps) {
2153
2936
  const fetchProps = await getFetchProps();
2154
2937
  const { tables, fuzziness, highlight, prefix } = options ?? {};
2155
2938
  const { records } = await searchBranch({
2156
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2939
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2157
2940
  body: { tables, query, fuzziness, prefix, highlight },
2158
2941
  ...fetchProps
2159
2942
  });
@@ -2165,7 +2948,7 @@ getSchemaTables_fn = async function(getFetchProps) {
2165
2948
  return __privateGet$1(this, _schemaTables);
2166
2949
  const fetchProps = await getFetchProps();
2167
2950
  const { schema } = await getBranchDetails({
2168
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2951
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2169
2952
  ...fetchProps
2170
2953
  });
2171
2954
  __privateSet$1(this, _schemaTables, schema.tables);
@@ -2203,14 +2986,17 @@ async function resolveXataBranch(gitBranch, options) {
2203
2986
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2204
2987
  );
2205
2988
  const [protocol, , host, , dbName] = databaseURL.split("/");
2206
- const [workspace] = host.split(".");
2989
+ const urlParts = parseWorkspacesUrlParts(host);
2990
+ if (!urlParts)
2991
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
2992
+ const { workspace, region } = urlParts;
2207
2993
  const { fallbackBranch } = getEnvironment();
2208
2994
  const { branch } = await resolveBranch({
2209
2995
  apiKey,
2210
2996
  apiUrl: databaseURL,
2211
2997
  fetchImpl: getFetchImplementation(options?.fetchImpl),
2212
2998
  workspacesApiUrl: `${protocol}//${host}`,
2213
- pathParams: { dbName, workspace },
2999
+ pathParams: { dbName, workspace, region },
2214
3000
  queryParams: { gitBranch, fallbackBranch },
2215
3001
  trace: defaultTrace
2216
3002
  });
@@ -2228,15 +3014,17 @@ async function getDatabaseBranch(branch, options) {
2228
3014
  "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2229
3015
  );
2230
3016
  const [protocol, , host, , database] = databaseURL.split("/");
2231
- const [workspace] = host.split(".");
2232
- const dbBranchName = `${database}:${branch}`;
3017
+ const urlParts = parseWorkspacesUrlParts(host);
3018
+ if (!urlParts)
3019
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3020
+ const { workspace, region } = urlParts;
2233
3021
  try {
2234
3022
  return await getBranchDetails({
2235
3023
  apiKey,
2236
3024
  apiUrl: databaseURL,
2237
3025
  fetchImpl: getFetchImplementation(options?.fetchImpl),
2238
3026
  workspacesApiUrl: `${protocol}//${host}`,
2239
- pathParams: { dbBranchName, workspace },
3027
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
2240
3028
  trace: defaultTrace
2241
3029
  });
2242
3030
  } catch (err) {
@@ -2315,6 +3103,13 @@ const buildClient = (plugins) => {
2315
3103
  return { databaseURL, branch };
2316
3104
  }
2317
3105
  }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3106
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3107
+ const isBrowser = typeof window !== "undefined";
3108
+ if (isBrowser && !enableBrowser) {
3109
+ throw new Error(
3110
+ "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."
3111
+ );
3112
+ }
2318
3113
  const fetch = getFetchImplementation(options?.fetch);
2319
3114
  const databaseURL = options?.databaseURL || getDatabaseURL();
2320
3115
  const apiKey = options?.apiKey || getAPIKey();
@@ -2327,8 +3122,8 @@ const buildClient = (plugins) => {
2327
3122
  if (!databaseURL) {
2328
3123
  throw new Error("Option databaseURL is required");
2329
3124
  }
2330
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2331
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
3125
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
3126
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
2332
3127
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2333
3128
  if (!branchValue)
2334
3129
  throw new Error("Unable to resolve branch value");
@@ -2341,7 +3136,8 @@ const buildClient = (plugins) => {
2341
3136
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2342
3137
  return databaseURL + newPath;
2343
3138
  },
2344
- trace
3139
+ trace,
3140
+ clientID
2345
3141
  };
2346
3142
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2347
3143
  if (__privateGet(this, _branch))
@@ -2453,5 +3249,5 @@ class XataError extends Error {
2453
3249
  }
2454
3250
  }
2455
3251
 
2456
- export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateBranchSchema, updateColumn, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
3252
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, dEPRECATEDcreateDatabase, dEPRECATEDdeleteDatabase, dEPRECATEDgetDatabaseList, dEPRECATEDgetDatabaseMetadata, dEPRECATEDupdateDatabaseMetadata, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2457
3253
  //# sourceMappingURL=index.mjs.map