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

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