@xata.io/client 0.0.0-alpha.vf603f80 → 0.0.0-alpha.vf6b372c

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
  }
@@ -13,6 +35,12 @@ function isDefined(value) {
13
35
  function isString(value) {
14
36
  return isDefined(value) && typeof value === "string";
15
37
  }
38
+ function isStringArray(value) {
39
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
40
+ }
41
+ function isNumber(value) {
42
+ return isDefined(value) && typeof value === "number";
43
+ }
16
44
  function toBase64(value) {
17
45
  try {
18
46
  return btoa(value);
@@ -21,6 +49,17 @@ function toBase64(value) {
21
49
  return buf.from(value).toString("base64");
22
50
  }
23
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
+ }
24
63
 
25
64
  function getEnvironment() {
26
65
  try {
@@ -118,12 +157,14 @@ function getFetchImplementation(userFetch) {
118
157
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
119
158
  const fetchImpl = userFetch ?? globalFetch;
120
159
  if (!fetchImpl) {
121
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
160
+ throw new Error(
161
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
162
+ );
122
163
  }
123
164
  return fetchImpl;
124
165
  }
125
166
 
126
- const VERSION = "0.0.0-alpha.vf603f80";
167
+ const VERSION = "0.0.0-alpha.vf6b372c";
127
168
 
128
169
  class ErrorWithCause extends Error {
129
170
  constructor(message, options) {
@@ -174,18 +215,24 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
174
215
  }, {});
175
216
  const query = new URLSearchParams(cleanQueryParams).toString();
176
217
  const queryString = query.length > 0 ? `?${query}` : "";
177
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
218
+ const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
219
+ return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
220
+ }, {});
221
+ return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
178
222
  };
179
223
  function buildBaseUrl({
224
+ endpoint,
180
225
  path,
181
226
  workspacesApiUrl,
182
227
  apiUrl,
183
- pathParams
228
+ pathParams = {}
184
229
  }) {
185
- if (!pathParams?.workspace)
186
- return `${apiUrl}${path}`;
187
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
188
- return url.replace("{workspaceId}", pathParams.workspace);
230
+ if (endpoint === "dataPlane") {
231
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
232
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
233
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
234
+ }
235
+ return `${apiUrl}${path}`;
189
236
  }
190
237
  function hostHeader(url) {
191
238
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -201,280 +248,238 @@ async function fetch$1({
201
248
  queryParams,
202
249
  fetchImpl,
203
250
  apiKey,
251
+ endpoint,
204
252
  apiUrl,
205
- workspacesApiUrl
253
+ workspacesApiUrl,
254
+ trace,
255
+ signal,
256
+ clientID,
257
+ sessionID
206
258
  }) {
207
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
208
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
209
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
210
- const response = await fetchImpl(url, {
211
- method: method.toUpperCase(),
212
- body: body ? JSON.stringify(body) : void 0,
213
- headers: {
214
- "Content-Type": "application/json",
215
- "User-Agent": `Xata client-ts/${VERSION}`,
216
- ...headers,
217
- ...hostHeader(fullUrl),
218
- Authorization: `Bearer ${apiKey}`
219
- }
220
- });
221
- if (response.status === 204) {
222
- return {};
223
- }
224
- const requestId = response.headers?.get("x-request-id") ?? void 0;
259
+ return trace(
260
+ `${method.toUpperCase()} ${path}`,
261
+ async ({ setAttributes }) => {
262
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
263
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
264
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
265
+ setAttributes({
266
+ [TraceAttributes.HTTP_URL]: url,
267
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
268
+ });
269
+ const response = await fetchImpl(url, {
270
+ method: method.toUpperCase(),
271
+ body: body ? JSON.stringify(body) : void 0,
272
+ headers: {
273
+ "Content-Type": "application/json",
274
+ "User-Agent": `Xata client-ts/${VERSION}`,
275
+ "X-Xata-Client-ID": clientID ?? "",
276
+ "X-Xata-Session-ID": sessionID ?? "",
277
+ ...headers,
278
+ ...hostHeader(fullUrl),
279
+ Authorization: `Bearer ${apiKey}`
280
+ },
281
+ signal
282
+ });
283
+ if (response.status === 204) {
284
+ return {};
285
+ }
286
+ const { host, protocol } = parseUrl(response.url);
287
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
288
+ setAttributes({
289
+ [TraceAttributes.KIND]: "http",
290
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
291
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
292
+ [TraceAttributes.HTTP_HOST]: host,
293
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
294
+ });
295
+ try {
296
+ const jsonResponse = await response.json();
297
+ if (response.ok) {
298
+ return jsonResponse;
299
+ }
300
+ throw new FetcherError(response.status, jsonResponse, requestId);
301
+ } catch (error) {
302
+ throw new FetcherError(response.status, error, requestId);
303
+ }
304
+ },
305
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
306
+ );
307
+ }
308
+ function parseUrl(url) {
225
309
  try {
226
- const jsonResponse = await response.json();
227
- if (response.ok) {
228
- return jsonResponse;
229
- }
230
- throw new FetcherError(response.status, jsonResponse, requestId);
310
+ const { host, protocol } = new URL(url);
311
+ return { host, protocol };
231
312
  } catch (error) {
232
- throw new FetcherError(response.status, error, requestId);
313
+ return {};
233
314
  }
234
315
  }
235
316
 
236
- const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
237
- const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
238
- const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
239
- const getUserAPIKeys = (variables) => fetch$1({
240
- url: "/user/keys",
241
- method: "get",
242
- ...variables
243
- });
244
- const createUserAPIKey = (variables) => fetch$1({
245
- url: "/user/keys/{keyName}",
246
- method: "post",
247
- ...variables
248
- });
249
- const deleteUserAPIKey = (variables) => fetch$1({
250
- url: "/user/keys/{keyName}",
251
- method: "delete",
252
- ...variables
253
- });
254
- const createWorkspace = (variables) => fetch$1({
255
- url: "/workspaces",
256
- method: "post",
257
- ...variables
258
- });
259
- const getWorkspacesList = (variables) => fetch$1({
260
- url: "/workspaces",
261
- method: "get",
262
- ...variables
263
- });
264
- const getWorkspace = (variables) => fetch$1({
265
- url: "/workspaces/{workspaceId}",
266
- method: "get",
267
- ...variables
268
- });
269
- const updateWorkspace = (variables) => fetch$1({
270
- url: "/workspaces/{workspaceId}",
271
- method: "put",
272
- ...variables
273
- });
274
- const deleteWorkspace = (variables) => fetch$1({
275
- url: "/workspaces/{workspaceId}",
276
- method: "delete",
277
- ...variables
278
- });
279
- const getWorkspaceMembersList = (variables) => fetch$1({
280
- url: "/workspaces/{workspaceId}/members",
281
- method: "get",
282
- ...variables
283
- });
284
- const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
285
- const removeWorkspaceMember = (variables) => fetch$1({
286
- url: "/workspaces/{workspaceId}/members/{userId}",
287
- method: "delete",
288
- ...variables
289
- });
290
- const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
291
- const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
292
- const cancelWorkspaceMemberInvite = (variables) => fetch$1({
293
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
294
- method: "delete",
295
- ...variables
296
- });
297
- const resendWorkspaceMemberInvite = (variables) => fetch$1({
298
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
299
- method: "post",
300
- ...variables
301
- });
302
- const acceptWorkspaceMemberInvite = (variables) => fetch$1({
303
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
304
- method: "post",
305
- ...variables
306
- });
307
- const getDatabaseList = (variables) => fetch$1({
317
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
318
+
319
+ const getDatabaseList = (variables, signal) => dataPlaneFetch({
308
320
  url: "/dbs",
309
321
  method: "get",
310
- ...variables
322
+ ...variables,
323
+ signal
311
324
  });
312
- const getBranchList = (variables) => fetch$1({
325
+ const getBranchList = (variables, signal) => dataPlaneFetch({
313
326
  url: "/dbs/{dbName}",
314
327
  method: "get",
315
- ...variables
316
- });
317
- const createDatabase = (variables) => fetch$1({
318
- url: "/dbs/{dbName}",
319
- method: "put",
320
- ...variables
328
+ ...variables,
329
+ signal
321
330
  });
322
- const deleteDatabase = (variables) => fetch$1({
331
+ const createDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
332
+ const deleteDatabase = (variables, signal) => dataPlaneFetch({
323
333
  url: "/dbs/{dbName}",
324
334
  method: "delete",
325
- ...variables
335
+ ...variables,
336
+ signal
326
337
  });
327
- const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
328
- const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
329
- const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
330
- const resolveBranch = (variables) => fetch$1({
331
- url: "/dbs/{dbName}/resolveBranch",
338
+ const getDatabaseMetadata = (variables, signal) => dataPlaneFetch({
339
+ url: "/dbs/{dbName}/metadata",
332
340
  method: "get",
333
- ...variables
341
+ ...variables,
342
+ signal
334
343
  });
335
- const getBranchDetails = (variables) => fetch$1({
344
+ const updateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
345
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
336
346
  url: "/db/{dbBranchName}",
337
347
  method: "get",
338
- ...variables
348
+ ...variables,
349
+ signal
339
350
  });
340
- const createBranch = (variables) => fetch$1({
341
- url: "/db/{dbBranchName}",
342
- method: "put",
343
- ...variables
344
- });
345
- const deleteBranch = (variables) => fetch$1({
351
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
352
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
346
353
  url: "/db/{dbBranchName}",
347
354
  method: "delete",
348
- ...variables
355
+ ...variables,
356
+ signal
349
357
  });
350
- const updateBranchMetadata = (variables) => fetch$1({
358
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
351
359
  url: "/db/{dbBranchName}/metadata",
352
360
  method: "put",
353
- ...variables
361
+ ...variables,
362
+ signal
354
363
  });
355
- const getBranchMetadata = (variables) => fetch$1({
364
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
356
365
  url: "/db/{dbBranchName}/metadata",
357
366
  method: "get",
358
- ...variables
367
+ ...variables,
368
+ signal
359
369
  });
360
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
361
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
362
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
363
- const getBranchStats = (variables) => fetch$1({
370
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
364
371
  url: "/db/{dbBranchName}/stats",
365
372
  method: "get",
366
- ...variables
373
+ ...variables,
374
+ signal
375
+ });
376
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
377
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
378
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
379
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
380
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
381
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
382
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
383
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
384
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
385
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
386
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
387
+ method: "get",
388
+ ...variables,
389
+ signal
390
+ });
391
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
392
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
393
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
394
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
395
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
396
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
397
+ method: "post",
398
+ ...variables,
399
+ signal
367
400
  });
368
- const createTable = (variables) => fetch$1({
401
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
402
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
403
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
404
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
405
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
406
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
407
+ const createTable = (variables, signal) => dataPlaneFetch({
369
408
  url: "/db/{dbBranchName}/tables/{tableName}",
370
409
  method: "put",
371
- ...variables
410
+ ...variables,
411
+ signal
372
412
  });
373
- const deleteTable = (variables) => fetch$1({
413
+ const deleteTable = (variables, signal) => dataPlaneFetch({
374
414
  url: "/db/{dbBranchName}/tables/{tableName}",
375
415
  method: "delete",
376
- ...variables
416
+ ...variables,
417
+ signal
377
418
  });
378
- const updateTable = (variables) => fetch$1({
379
- url: "/db/{dbBranchName}/tables/{tableName}",
380
- method: "patch",
381
- ...variables
382
- });
383
- const getTableSchema = (variables) => fetch$1({
419
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
420
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
384
421
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
385
422
  method: "get",
386
- ...variables
387
- });
388
- const setTableSchema = (variables) => fetch$1({
389
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
390
- method: "put",
391
- ...variables
423
+ ...variables,
424
+ signal
392
425
  });
393
- const getTableColumns = (variables) => fetch$1({
426
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
427
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
394
428
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
395
429
  method: "get",
396
- ...variables
430
+ ...variables,
431
+ signal
397
432
  });
398
- const addTableColumn = (variables) => fetch$1({
399
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
400
- method: "post",
401
- ...variables
402
- });
403
- const getColumn = (variables) => fetch$1({
433
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
434
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
435
+ );
436
+ const getColumn = (variables, signal) => dataPlaneFetch({
404
437
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
405
438
  method: "get",
406
- ...variables
439
+ ...variables,
440
+ signal
407
441
  });
408
- const deleteColumn = (variables) => fetch$1({
442
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
443
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
409
444
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
410
445
  method: "delete",
411
- ...variables
412
- });
413
- const updateColumn = (variables) => fetch$1({
414
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
415
- method: "patch",
416
- ...variables
417
- });
418
- const insertRecord = (variables) => fetch$1({
419
- url: "/db/{dbBranchName}/tables/{tableName}/data",
420
- method: "post",
421
- ...variables
446
+ ...variables,
447
+ signal
422
448
  });
423
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
424
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
425
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
426
- const deleteRecord = (variables) => fetch$1({
427
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
428
- method: "delete",
429
- ...variables
430
- });
431
- const getRecord = (variables) => fetch$1({
449
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
450
+ const getRecord = (variables, signal) => dataPlaneFetch({
432
451
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
433
452
  method: "get",
434
- ...variables
453
+ ...variables,
454
+ signal
435
455
  });
436
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
437
- const queryTable = (variables) => fetch$1({
456
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
457
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
458
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
459
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
460
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
461
+ const queryTable = (variables, signal) => dataPlaneFetch({
438
462
  url: "/db/{dbBranchName}/tables/{tableName}/query",
439
463
  method: "post",
440
- ...variables
464
+ ...variables,
465
+ signal
441
466
  });
442
- const searchTable = (variables) => fetch$1({
443
- url: "/db/{dbBranchName}/tables/{tableName}/search",
467
+ const searchBranch = (variables, signal) => dataPlaneFetch({
468
+ url: "/db/{dbBranchName}/search",
444
469
  method: "post",
445
- ...variables
470
+ ...variables,
471
+ signal
446
472
  });
447
- const searchBranch = (variables) => fetch$1({
448
- url: "/db/{dbBranchName}/search",
473
+ const searchTable = (variables, signal) => dataPlaneFetch({
474
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
449
475
  method: "post",
450
- ...variables
476
+ ...variables,
477
+ signal
451
478
  });
452
- const operationsByTag = {
453
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
454
- workspaces: {
455
- createWorkspace,
456
- getWorkspacesList,
457
- getWorkspace,
458
- updateWorkspace,
459
- deleteWorkspace,
460
- getWorkspaceMembersList,
461
- updateWorkspaceMemberRole,
462
- removeWorkspaceMember,
463
- inviteWorkspaceMember,
464
- updateWorkspaceMemberInvite,
465
- cancelWorkspaceMemberInvite,
466
- resendWorkspaceMemberInvite,
467
- acceptWorkspaceMemberInvite
468
- },
469
- database: {
470
- getDatabaseList,
471
- createDatabase,
472
- deleteDatabase,
473
- getGitBranchesMapping,
474
- addGitBranchesEntry,
475
- removeGitBranchesEntry,
476
- resolveBranch
477
- },
479
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
480
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
481
+ const operationsByTag$2 = {
482
+ database: { getDatabaseList, createDatabase, deleteDatabase, getDatabaseMetadata, updateDatabaseMetadata },
478
483
  branch: {
479
484
  getBranchList,
480
485
  getBranchDetails,
@@ -482,10 +487,32 @@ const operationsByTag = {
482
487
  deleteBranch,
483
488
  updateBranchMetadata,
484
489
  getBranchMetadata,
490
+ getBranchStats,
491
+ getGitBranchesMapping,
492
+ addGitBranchesEntry,
493
+ removeGitBranchesEntry,
494
+ resolveBranch
495
+ },
496
+ migrations: {
485
497
  getBranchMigrationHistory,
486
- executeBranchMigrationPlan,
487
498
  getBranchMigrationPlan,
488
- getBranchStats
499
+ executeBranchMigrationPlan,
500
+ getBranchSchemaHistory,
501
+ compareBranchWithUserSchema,
502
+ compareBranchSchemas,
503
+ updateBranchSchema,
504
+ previewBranchSchemaEdit,
505
+ applyBranchSchemaEdit
506
+ },
507
+ migrationRequests: {
508
+ queryMigrationRequests,
509
+ createMigrationRequest,
510
+ getMigrationRequest,
511
+ updateMigrationRequest,
512
+ listMigrationRequestsCommits,
513
+ compareMigrationRequest,
514
+ getMigrationRequestIsMerged,
515
+ mergeMigrationRequest
489
516
  },
490
517
  table: {
491
518
  createTable,
@@ -496,27 +523,154 @@ const operationsByTag = {
496
523
  getTableColumns,
497
524
  addTableColumn,
498
525
  getColumn,
499
- deleteColumn,
500
- updateColumn
526
+ updateColumn,
527
+ deleteColumn
501
528
  },
502
529
  records: {
503
530
  insertRecord,
531
+ getRecord,
504
532
  insertRecordWithID,
505
533
  updateRecordWithID,
506
534
  upsertRecordWithID,
507
535
  deleteRecord,
508
- getRecord,
509
- bulkInsertTableRecords,
510
- queryTable,
511
- searchTable,
512
- searchBranch
536
+ bulkInsertTableRecords
537
+ },
538
+ searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
539
+ };
540
+
541
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
542
+
543
+ const getUser = (variables, signal) => controlPlaneFetch({
544
+ url: "/user",
545
+ method: "get",
546
+ ...variables,
547
+ signal
548
+ });
549
+ const updateUser = (variables, signal) => controlPlaneFetch({
550
+ url: "/user",
551
+ method: "put",
552
+ ...variables,
553
+ signal
554
+ });
555
+ const deleteUser = (variables, signal) => controlPlaneFetch({
556
+ url: "/user",
557
+ method: "delete",
558
+ ...variables,
559
+ signal
560
+ });
561
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
562
+ url: "/user/keys",
563
+ method: "get",
564
+ ...variables,
565
+ signal
566
+ });
567
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
568
+ url: "/user/keys/{keyName}",
569
+ method: "post",
570
+ ...variables,
571
+ signal
572
+ });
573
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
574
+ url: "/user/keys/{keyName}",
575
+ method: "delete",
576
+ ...variables,
577
+ signal
578
+ });
579
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
580
+ url: "/workspaces",
581
+ method: "get",
582
+ ...variables,
583
+ signal
584
+ });
585
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
586
+ url: "/workspaces",
587
+ method: "post",
588
+ ...variables,
589
+ signal
590
+ });
591
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
592
+ url: "/workspaces/{workspaceId}",
593
+ method: "get",
594
+ ...variables,
595
+ signal
596
+ });
597
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
598
+ url: "/workspaces/{workspaceId}",
599
+ method: "put",
600
+ ...variables,
601
+ signal
602
+ });
603
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
604
+ url: "/workspaces/{workspaceId}",
605
+ method: "delete",
606
+ ...variables,
607
+ signal
608
+ });
609
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
610
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
611
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
612
+ url: "/workspaces/{workspaceId}/members/{userId}",
613
+ method: "delete",
614
+ ...variables,
615
+ signal
616
+ });
617
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
618
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
619
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
620
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
621
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
622
+ const cPGetDatabaseList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs", method: "get", ...variables, signal });
623
+ const cPCreateDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
624
+ const cPDeleteDatabase = (variables, signal) => controlPlaneFetch({
625
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
626
+ method: "delete",
627
+ ...variables,
628
+ signal
629
+ });
630
+ const cPGetCPDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
631
+ const cPUpdateCPDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
632
+ const listRegions = (variables, signal) => controlPlaneFetch({
633
+ url: "/workspaces/{workspaceId}/regions",
634
+ method: "get",
635
+ ...variables,
636
+ signal
637
+ });
638
+ const operationsByTag$1 = {
639
+ users: { getUser, updateUser, deleteUser },
640
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
641
+ workspaces: {
642
+ getWorkspacesList,
643
+ createWorkspace,
644
+ getWorkspace,
645
+ updateWorkspace,
646
+ deleteWorkspace,
647
+ getWorkspaceMembersList,
648
+ updateWorkspaceMemberRole,
649
+ removeWorkspaceMember
650
+ },
651
+ invites: {
652
+ inviteWorkspaceMember,
653
+ updateWorkspaceMemberInvite,
654
+ cancelWorkspaceMemberInvite,
655
+ acceptWorkspaceMemberInvite,
656
+ resendWorkspaceMemberInvite
657
+ },
658
+ databases: {
659
+ cPGetDatabaseList,
660
+ cPCreateDatabase,
661
+ cPDeleteDatabase,
662
+ cPGetCPDatabaseMetadata,
663
+ cPUpdateCPDatabaseMetadata,
664
+ listRegions
513
665
  }
514
666
  };
515
667
 
668
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
669
+
516
670
  function getHostUrl(provider, type) {
517
- if (isValidAlias(provider)) {
671
+ if (isHostProviderAlias(provider)) {
518
672
  return providers[provider][type];
519
- } else if (isValidBuilder(provider)) {
673
+ } else if (isHostProviderBuilder(provider)) {
520
674
  return provider[type];
521
675
  }
522
676
  throw new Error("Invalid API provider");
@@ -524,19 +678,38 @@ function getHostUrl(provider, type) {
524
678
  const providers = {
525
679
  production: {
526
680
  main: "https://api.xata.io",
527
- workspaces: "https://{workspaceId}.xata.sh"
681
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
528
682
  },
529
683
  staging: {
530
684
  main: "https://staging.xatabase.co",
531
- workspaces: "https://{workspaceId}.staging.xatabase.co"
685
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
532
686
  }
533
687
  };
534
- function isValidAlias(alias) {
688
+ function isHostProviderAlias(alias) {
535
689
  return isString(alias) && Object.keys(providers).includes(alias);
536
690
  }
537
- function isValidBuilder(builder) {
691
+ function isHostProviderBuilder(builder) {
538
692
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
539
693
  }
694
+ function parseProviderString(provider = "production") {
695
+ if (isHostProviderAlias(provider)) {
696
+ return provider;
697
+ }
698
+ const [main, workspaces] = provider.split(",");
699
+ if (!main || !workspaces)
700
+ return null;
701
+ return { main, workspaces };
702
+ }
703
+ function parseWorkspacesUrlParts(url) {
704
+ if (!isString(url))
705
+ return null;
706
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
707
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
708
+ const match = url.match(regex) || url.match(regexStaging);
709
+ if (!match)
710
+ return null;
711
+ return { workspace: match[1], region: match[2] ?? "eu-west-1" };
712
+ }
540
713
 
541
714
  var __accessCheck$7 = (obj, member, msg) => {
542
715
  if (!member.has(obj))
@@ -562,7 +735,8 @@ class XataApiClient {
562
735
  __privateAdd$7(this, _extraProps, void 0);
563
736
  __privateAdd$7(this, _namespaces, {});
564
737
  const provider = options.host ?? "production";
565
- const apiKey = options?.apiKey ?? getAPIKey();
738
+ const apiKey = options.apiKey ?? getAPIKey();
739
+ const trace = options.trace ?? defaultTrace;
566
740
  if (!apiKey) {
567
741
  throw new Error("Could not resolve a valid apiKey");
568
742
  }
@@ -570,7 +744,8 @@ class XataApiClient {
570
744
  apiUrl: getHostUrl(provider, "main"),
571
745
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
572
746
  fetchImpl: getFetchImplementation(options.fetch),
573
- apiKey
747
+ apiKey,
748
+ trace
574
749
  });
575
750
  }
576
751
  get user() {
@@ -578,21 +753,41 @@ class XataApiClient {
578
753
  __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
579
754
  return __privateGet$7(this, _namespaces).user;
580
755
  }
756
+ get authentication() {
757
+ if (!__privateGet$7(this, _namespaces).authentication)
758
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
759
+ return __privateGet$7(this, _namespaces).authentication;
760
+ }
581
761
  get workspaces() {
582
762
  if (!__privateGet$7(this, _namespaces).workspaces)
583
763
  __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
584
764
  return __privateGet$7(this, _namespaces).workspaces;
585
765
  }
586
- get databases() {
587
- if (!__privateGet$7(this, _namespaces).databases)
588
- __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
589
- return __privateGet$7(this, _namespaces).databases;
766
+ get invites() {
767
+ if (!__privateGet$7(this, _namespaces).invites)
768
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
769
+ return __privateGet$7(this, _namespaces).invites;
770
+ }
771
+ get database() {
772
+ if (!__privateGet$7(this, _namespaces).database)
773
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
774
+ return __privateGet$7(this, _namespaces).database;
590
775
  }
591
776
  get branches() {
592
777
  if (!__privateGet$7(this, _namespaces).branches)
593
778
  __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
594
779
  return __privateGet$7(this, _namespaces).branches;
595
780
  }
781
+ get migrations() {
782
+ if (!__privateGet$7(this, _namespaces).migrations)
783
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
784
+ return __privateGet$7(this, _namespaces).migrations;
785
+ }
786
+ get migrationRequests() {
787
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
788
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
789
+ return __privateGet$7(this, _namespaces).migrationRequests;
790
+ }
596
791
  get tables() {
597
792
  if (!__privateGet$7(this, _namespaces).tables)
598
793
  __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
@@ -603,6 +798,11 @@ class XataApiClient {
603
798
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
604
799
  return __privateGet$7(this, _namespaces).records;
605
800
  }
801
+ get searchAndFilter() {
802
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
803
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
804
+ return __privateGet$7(this, _namespaces).searchAndFilter;
805
+ }
606
806
  }
607
807
  _extraProps = new WeakMap();
608
808
  _namespaces = new WeakMap();
@@ -613,24 +813,29 @@ class UserApi {
613
813
  getUser() {
614
814
  return operationsByTag.users.getUser({ ...this.extraProps });
615
815
  }
616
- updateUser(user) {
816
+ updateUser({ user }) {
617
817
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
618
818
  }
619
819
  deleteUser() {
620
820
  return operationsByTag.users.deleteUser({ ...this.extraProps });
621
821
  }
822
+ }
823
+ class AuthenticationApi {
824
+ constructor(extraProps) {
825
+ this.extraProps = extraProps;
826
+ }
622
827
  getUserAPIKeys() {
623
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
828
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
624
829
  }
625
- createUserAPIKey(keyName) {
626
- return operationsByTag.users.createUserAPIKey({
627
- pathParams: { keyName },
830
+ createUserAPIKey({ name }) {
831
+ return operationsByTag.authentication.createUserAPIKey({
832
+ pathParams: { keyName: name },
628
833
  ...this.extraProps
629
834
  });
630
835
  }
631
- deleteUserAPIKey(keyName) {
632
- return operationsByTag.users.deleteUserAPIKey({
633
- pathParams: { keyName },
836
+ deleteUserAPIKey({ name }) {
837
+ return operationsByTag.authentication.deleteUserAPIKey({
838
+ pathParams: { keyName: name },
634
839
  ...this.extraProps
635
840
  });
636
841
  }
@@ -639,349 +844,882 @@ class WorkspaceApi {
639
844
  constructor(extraProps) {
640
845
  this.extraProps = extraProps;
641
846
  }
642
- createWorkspace(workspaceMeta) {
847
+ getWorkspacesList() {
848
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
849
+ }
850
+ createWorkspace({ data }) {
643
851
  return operationsByTag.workspaces.createWorkspace({
644
- body: workspaceMeta,
852
+ body: data,
645
853
  ...this.extraProps
646
854
  });
647
855
  }
648
- getWorkspacesList() {
649
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
650
- }
651
- getWorkspace(workspaceId) {
856
+ getWorkspace({ workspace }) {
652
857
  return operationsByTag.workspaces.getWorkspace({
653
- pathParams: { workspaceId },
858
+ pathParams: { workspaceId: workspace },
654
859
  ...this.extraProps
655
860
  });
656
861
  }
657
- updateWorkspace(workspaceId, workspaceMeta) {
862
+ updateWorkspace({
863
+ workspace,
864
+ update
865
+ }) {
658
866
  return operationsByTag.workspaces.updateWorkspace({
659
- pathParams: { workspaceId },
660
- body: workspaceMeta,
867
+ pathParams: { workspaceId: workspace },
868
+ body: update,
661
869
  ...this.extraProps
662
870
  });
663
871
  }
664
- deleteWorkspace(workspaceId) {
872
+ deleteWorkspace({ workspace }) {
665
873
  return operationsByTag.workspaces.deleteWorkspace({
666
- pathParams: { workspaceId },
874
+ pathParams: { workspaceId: workspace },
667
875
  ...this.extraProps
668
876
  });
669
877
  }
670
- getWorkspaceMembersList(workspaceId) {
878
+ getWorkspaceMembersList({ workspace }) {
671
879
  return operationsByTag.workspaces.getWorkspaceMembersList({
672
- pathParams: { workspaceId },
880
+ pathParams: { workspaceId: workspace },
673
881
  ...this.extraProps
674
882
  });
675
883
  }
676
- updateWorkspaceMemberRole(workspaceId, userId, role) {
884
+ updateWorkspaceMemberRole({
885
+ workspace,
886
+ user,
887
+ role
888
+ }) {
677
889
  return operationsByTag.workspaces.updateWorkspaceMemberRole({
678
- pathParams: { workspaceId, userId },
890
+ pathParams: { workspaceId: workspace, userId: user },
679
891
  body: { role },
680
892
  ...this.extraProps
681
893
  });
682
894
  }
683
- removeWorkspaceMember(workspaceId, userId) {
895
+ removeWorkspaceMember({
896
+ workspace,
897
+ user
898
+ }) {
684
899
  return operationsByTag.workspaces.removeWorkspaceMember({
685
- pathParams: { workspaceId, userId },
900
+ pathParams: { workspaceId: workspace, userId: user },
686
901
  ...this.extraProps
687
902
  });
688
903
  }
689
- inviteWorkspaceMember(workspaceId, email, role) {
690
- return operationsByTag.workspaces.inviteWorkspaceMember({
691
- pathParams: { workspaceId },
904
+ }
905
+ class InvitesApi {
906
+ constructor(extraProps) {
907
+ this.extraProps = extraProps;
908
+ }
909
+ inviteWorkspaceMember({
910
+ workspace,
911
+ email,
912
+ role
913
+ }) {
914
+ return operationsByTag.invites.inviteWorkspaceMember({
915
+ pathParams: { workspaceId: workspace },
692
916
  body: { email, role },
693
917
  ...this.extraProps
694
918
  });
695
919
  }
696
- updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
697
- return operationsByTag.workspaces.updateWorkspaceMemberInvite({
698
- pathParams: { workspaceId, inviteId },
920
+ updateWorkspaceMemberInvite({
921
+ workspace,
922
+ invite,
923
+ role
924
+ }) {
925
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
926
+ pathParams: { workspaceId: workspace, inviteId: invite },
699
927
  body: { role },
700
928
  ...this.extraProps
701
929
  });
702
930
  }
703
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
704
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
705
- pathParams: { workspaceId, inviteId },
931
+ cancelWorkspaceMemberInvite({
932
+ workspace,
933
+ invite
934
+ }) {
935
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
936
+ pathParams: { workspaceId: workspace, inviteId: invite },
937
+ ...this.extraProps
938
+ });
939
+ }
940
+ acceptWorkspaceMemberInvite({
941
+ workspace,
942
+ key
943
+ }) {
944
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
945
+ pathParams: { workspaceId: workspace, inviteKey: key },
946
+ ...this.extraProps
947
+ });
948
+ }
949
+ resendWorkspaceMemberInvite({
950
+ workspace,
951
+ invite
952
+ }) {
953
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
954
+ pathParams: { workspaceId: workspace, inviteId: invite },
955
+ ...this.extraProps
956
+ });
957
+ }
958
+ }
959
+ class BranchApi {
960
+ constructor(extraProps) {
961
+ this.extraProps = extraProps;
962
+ }
963
+ getBranchList({
964
+ workspace,
965
+ region,
966
+ database
967
+ }) {
968
+ return operationsByTag.branch.getBranchList({
969
+ pathParams: { workspace, region, dbName: database },
970
+ ...this.extraProps
971
+ });
972
+ }
973
+ getBranchDetails({
974
+ workspace,
975
+ region,
976
+ database,
977
+ branch
978
+ }) {
979
+ return operationsByTag.branch.getBranchDetails({
980
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
981
+ ...this.extraProps
982
+ });
983
+ }
984
+ createBranch({
985
+ workspace,
986
+ region,
987
+ database,
988
+ branch,
989
+ from,
990
+ metadata
991
+ }) {
992
+ return operationsByTag.branch.createBranch({
993
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
994
+ body: { from, metadata },
995
+ ...this.extraProps
996
+ });
997
+ }
998
+ deleteBranch({
999
+ workspace,
1000
+ region,
1001
+ database,
1002
+ branch
1003
+ }) {
1004
+ return operationsByTag.branch.deleteBranch({
1005
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1006
+ ...this.extraProps
1007
+ });
1008
+ }
1009
+ updateBranchMetadata({
1010
+ workspace,
1011
+ region,
1012
+ database,
1013
+ branch,
1014
+ metadata
1015
+ }) {
1016
+ return operationsByTag.branch.updateBranchMetadata({
1017
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1018
+ body: metadata,
1019
+ ...this.extraProps
1020
+ });
1021
+ }
1022
+ getBranchMetadata({
1023
+ workspace,
1024
+ region,
1025
+ database,
1026
+ branch
1027
+ }) {
1028
+ return operationsByTag.branch.getBranchMetadata({
1029
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1030
+ ...this.extraProps
1031
+ });
1032
+ }
1033
+ getBranchStats({
1034
+ workspace,
1035
+ region,
1036
+ database,
1037
+ branch
1038
+ }) {
1039
+ return operationsByTag.branch.getBranchStats({
1040
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1041
+ ...this.extraProps
1042
+ });
1043
+ }
1044
+ getGitBranchesMapping({
1045
+ workspace,
1046
+ region,
1047
+ database
1048
+ }) {
1049
+ return operationsByTag.branch.getGitBranchesMapping({
1050
+ pathParams: { workspace, region, dbName: database },
1051
+ ...this.extraProps
1052
+ });
1053
+ }
1054
+ addGitBranchesEntry({
1055
+ workspace,
1056
+ region,
1057
+ database,
1058
+ gitBranch,
1059
+ xataBranch
1060
+ }) {
1061
+ return operationsByTag.branch.addGitBranchesEntry({
1062
+ pathParams: { workspace, region, dbName: database },
1063
+ body: { gitBranch, xataBranch },
1064
+ ...this.extraProps
1065
+ });
1066
+ }
1067
+ removeGitBranchesEntry({
1068
+ workspace,
1069
+ region,
1070
+ database,
1071
+ gitBranch
1072
+ }) {
1073
+ return operationsByTag.branch.removeGitBranchesEntry({
1074
+ pathParams: { workspace, region, dbName: database },
1075
+ queryParams: { gitBranch },
1076
+ ...this.extraProps
1077
+ });
1078
+ }
1079
+ resolveBranch({
1080
+ workspace,
1081
+ region,
1082
+ database,
1083
+ gitBranch,
1084
+ fallbackBranch
1085
+ }) {
1086
+ return operationsByTag.branch.resolveBranch({
1087
+ pathParams: { workspace, region, dbName: database },
1088
+ queryParams: { gitBranch, fallbackBranch },
706
1089
  ...this.extraProps
707
1090
  });
708
1091
  }
709
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
710
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
711
- pathParams: { workspaceId, inviteId },
1092
+ }
1093
+ class TableApi {
1094
+ constructor(extraProps) {
1095
+ this.extraProps = extraProps;
1096
+ }
1097
+ createTable({
1098
+ workspace,
1099
+ region,
1100
+ database,
1101
+ branch,
1102
+ table
1103
+ }) {
1104
+ return operationsByTag.table.createTable({
1105
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1106
+ ...this.extraProps
1107
+ });
1108
+ }
1109
+ deleteTable({
1110
+ workspace,
1111
+ region,
1112
+ database,
1113
+ branch,
1114
+ table
1115
+ }) {
1116
+ return operationsByTag.table.deleteTable({
1117
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1118
+ ...this.extraProps
1119
+ });
1120
+ }
1121
+ updateTable({
1122
+ workspace,
1123
+ region,
1124
+ database,
1125
+ branch,
1126
+ table,
1127
+ update
1128
+ }) {
1129
+ return operationsByTag.table.updateTable({
1130
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1131
+ body: update,
1132
+ ...this.extraProps
1133
+ });
1134
+ }
1135
+ getTableSchema({
1136
+ workspace,
1137
+ region,
1138
+ database,
1139
+ branch,
1140
+ table
1141
+ }) {
1142
+ return operationsByTag.table.getTableSchema({
1143
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1144
+ ...this.extraProps
1145
+ });
1146
+ }
1147
+ setTableSchema({
1148
+ workspace,
1149
+ region,
1150
+ database,
1151
+ branch,
1152
+ table,
1153
+ schema
1154
+ }) {
1155
+ return operationsByTag.table.setTableSchema({
1156
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1157
+ body: schema,
1158
+ ...this.extraProps
1159
+ });
1160
+ }
1161
+ getTableColumns({
1162
+ workspace,
1163
+ region,
1164
+ database,
1165
+ branch,
1166
+ table
1167
+ }) {
1168
+ return operationsByTag.table.getTableColumns({
1169
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1170
+ ...this.extraProps
1171
+ });
1172
+ }
1173
+ addTableColumn({
1174
+ workspace,
1175
+ region,
1176
+ database,
1177
+ branch,
1178
+ table,
1179
+ column
1180
+ }) {
1181
+ return operationsByTag.table.addTableColumn({
1182
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1183
+ body: column,
1184
+ ...this.extraProps
1185
+ });
1186
+ }
1187
+ getColumn({
1188
+ workspace,
1189
+ region,
1190
+ database,
1191
+ branch,
1192
+ table,
1193
+ column
1194
+ }) {
1195
+ return operationsByTag.table.getColumn({
1196
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1197
+ ...this.extraProps
1198
+ });
1199
+ }
1200
+ updateColumn({
1201
+ workspace,
1202
+ region,
1203
+ database,
1204
+ branch,
1205
+ table,
1206
+ column,
1207
+ update
1208
+ }) {
1209
+ return operationsByTag.table.updateColumn({
1210
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1211
+ body: update,
1212
+ ...this.extraProps
1213
+ });
1214
+ }
1215
+ deleteColumn({
1216
+ workspace,
1217
+ region,
1218
+ database,
1219
+ branch,
1220
+ table,
1221
+ column
1222
+ }) {
1223
+ return operationsByTag.table.deleteColumn({
1224
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1225
+ ...this.extraProps
1226
+ });
1227
+ }
1228
+ }
1229
+ class RecordsApi {
1230
+ constructor(extraProps) {
1231
+ this.extraProps = extraProps;
1232
+ }
1233
+ insertRecord({
1234
+ workspace,
1235
+ region,
1236
+ database,
1237
+ branch,
1238
+ table,
1239
+ record,
1240
+ columns
1241
+ }) {
1242
+ return operationsByTag.records.insertRecord({
1243
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1244
+ queryParams: { columns },
1245
+ body: record,
1246
+ ...this.extraProps
1247
+ });
1248
+ }
1249
+ getRecord({
1250
+ workspace,
1251
+ region,
1252
+ database,
1253
+ branch,
1254
+ table,
1255
+ id,
1256
+ columns
1257
+ }) {
1258
+ return operationsByTag.records.getRecord({
1259
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1260
+ queryParams: { columns },
1261
+ ...this.extraProps
1262
+ });
1263
+ }
1264
+ insertRecordWithID({
1265
+ workspace,
1266
+ region,
1267
+ database,
1268
+ branch,
1269
+ table,
1270
+ id,
1271
+ record,
1272
+ columns,
1273
+ createOnly,
1274
+ ifVersion
1275
+ }) {
1276
+ return operationsByTag.records.insertRecordWithID({
1277
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1278
+ queryParams: { columns, createOnly, ifVersion },
1279
+ body: record,
1280
+ ...this.extraProps
1281
+ });
1282
+ }
1283
+ updateRecordWithID({
1284
+ workspace,
1285
+ region,
1286
+ database,
1287
+ branch,
1288
+ table,
1289
+ id,
1290
+ record,
1291
+ columns,
1292
+ ifVersion
1293
+ }) {
1294
+ return operationsByTag.records.updateRecordWithID({
1295
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1296
+ queryParams: { columns, ifVersion },
1297
+ body: record,
1298
+ ...this.extraProps
1299
+ });
1300
+ }
1301
+ upsertRecordWithID({
1302
+ workspace,
1303
+ region,
1304
+ database,
1305
+ branch,
1306
+ table,
1307
+ id,
1308
+ record,
1309
+ columns,
1310
+ ifVersion
1311
+ }) {
1312
+ return operationsByTag.records.upsertRecordWithID({
1313
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1314
+ queryParams: { columns, ifVersion },
1315
+ body: record,
1316
+ ...this.extraProps
1317
+ });
1318
+ }
1319
+ deleteRecord({
1320
+ workspace,
1321
+ region,
1322
+ database,
1323
+ branch,
1324
+ table,
1325
+ id,
1326
+ columns
1327
+ }) {
1328
+ return operationsByTag.records.deleteRecord({
1329
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1330
+ queryParams: { columns },
712
1331
  ...this.extraProps
713
1332
  });
714
1333
  }
715
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
716
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
717
- pathParams: { workspaceId, inviteKey },
1334
+ bulkInsertTableRecords({
1335
+ workspace,
1336
+ region,
1337
+ database,
1338
+ branch,
1339
+ table,
1340
+ records,
1341
+ columns
1342
+ }) {
1343
+ return operationsByTag.records.bulkInsertTableRecords({
1344
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1345
+ queryParams: { columns },
1346
+ body: { records },
718
1347
  ...this.extraProps
719
1348
  });
720
1349
  }
721
1350
  }
722
- class DatabaseApi {
1351
+ class SearchAndFilterApi {
723
1352
  constructor(extraProps) {
724
1353
  this.extraProps = extraProps;
725
1354
  }
726
- getDatabaseList(workspace) {
727
- return operationsByTag.database.getDatabaseList({
728
- pathParams: { workspace },
729
- ...this.extraProps
730
- });
731
- }
732
- createDatabase(workspace, dbName, options = {}) {
733
- return operationsByTag.database.createDatabase({
734
- pathParams: { workspace, dbName },
735
- body: options,
736
- ...this.extraProps
737
- });
738
- }
739
- deleteDatabase(workspace, dbName) {
740
- return operationsByTag.database.deleteDatabase({
741
- pathParams: { workspace, dbName },
1355
+ queryTable({
1356
+ workspace,
1357
+ region,
1358
+ database,
1359
+ branch,
1360
+ table,
1361
+ filter,
1362
+ sort,
1363
+ page,
1364
+ columns
1365
+ }) {
1366
+ return operationsByTag.searchAndFilter.queryTable({
1367
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1368
+ body: { filter, sort, page, columns },
742
1369
  ...this.extraProps
743
1370
  });
744
1371
  }
745
- getGitBranchesMapping(workspace, dbName) {
746
- return operationsByTag.database.getGitBranchesMapping({
747
- pathParams: { workspace, dbName },
1372
+ searchTable({
1373
+ workspace,
1374
+ region,
1375
+ database,
1376
+ branch,
1377
+ table,
1378
+ query,
1379
+ fuzziness,
1380
+ target,
1381
+ prefix,
1382
+ filter,
1383
+ highlight,
1384
+ boosters
1385
+ }) {
1386
+ return operationsByTag.searchAndFilter.searchTable({
1387
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1388
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
748
1389
  ...this.extraProps
749
1390
  });
750
1391
  }
751
- addGitBranchesEntry(workspace, dbName, body) {
752
- return operationsByTag.database.addGitBranchesEntry({
753
- pathParams: { workspace, dbName },
754
- body,
1392
+ searchBranch({
1393
+ workspace,
1394
+ region,
1395
+ database,
1396
+ branch,
1397
+ tables,
1398
+ query,
1399
+ fuzziness,
1400
+ prefix,
1401
+ highlight
1402
+ }) {
1403
+ return operationsByTag.searchAndFilter.searchBranch({
1404
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1405
+ body: { tables, query, fuzziness, prefix, highlight },
755
1406
  ...this.extraProps
756
1407
  });
757
1408
  }
758
- removeGitBranchesEntry(workspace, dbName, gitBranch) {
759
- return operationsByTag.database.removeGitBranchesEntry({
760
- pathParams: { workspace, dbName },
761
- queryParams: { gitBranch },
1409
+ summarizeTable({
1410
+ workspace,
1411
+ region,
1412
+ database,
1413
+ branch,
1414
+ table,
1415
+ filter,
1416
+ columns,
1417
+ summaries,
1418
+ sort,
1419
+ summariesFilter,
1420
+ page
1421
+ }) {
1422
+ return operationsByTag.searchAndFilter.summarizeTable({
1423
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1424
+ body: { filter, columns, summaries, sort, summariesFilter, page },
762
1425
  ...this.extraProps
763
1426
  });
764
1427
  }
765
- resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
766
- return operationsByTag.database.resolveBranch({
767
- pathParams: { workspace, dbName },
768
- queryParams: { gitBranch, fallbackBranch },
1428
+ aggregateTable({
1429
+ workspace,
1430
+ region,
1431
+ database,
1432
+ branch,
1433
+ table,
1434
+ filter,
1435
+ aggs
1436
+ }) {
1437
+ return operationsByTag.searchAndFilter.aggregateTable({
1438
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1439
+ body: { filter, aggs },
769
1440
  ...this.extraProps
770
1441
  });
771
1442
  }
772
1443
  }
773
- class BranchApi {
1444
+ class MigrationRequestsApi {
774
1445
  constructor(extraProps) {
775
1446
  this.extraProps = extraProps;
776
1447
  }
777
- getBranchList(workspace, dbName) {
778
- return operationsByTag.branch.getBranchList({
779
- pathParams: { workspace, dbName },
780
- ...this.extraProps
781
- });
782
- }
783
- getBranchDetails(workspace, database, branch) {
784
- return operationsByTag.branch.getBranchDetails({
785
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
786
- ...this.extraProps
787
- });
788
- }
789
- createBranch(workspace, database, branch, from, options = {}) {
790
- return operationsByTag.branch.createBranch({
791
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
792
- queryParams: isString(from) ? { from } : void 0,
793
- body: options,
1448
+ queryMigrationRequests({
1449
+ workspace,
1450
+ region,
1451
+ database,
1452
+ filter,
1453
+ sort,
1454
+ page,
1455
+ columns
1456
+ }) {
1457
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1458
+ pathParams: { workspace, region, dbName: database },
1459
+ body: { filter, sort, page, columns },
794
1460
  ...this.extraProps
795
1461
  });
796
1462
  }
797
- deleteBranch(workspace, database, branch) {
798
- return operationsByTag.branch.deleteBranch({
799
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1463
+ createMigrationRequest({
1464
+ workspace,
1465
+ region,
1466
+ database,
1467
+ migration
1468
+ }) {
1469
+ return operationsByTag.migrationRequests.createMigrationRequest({
1470
+ pathParams: { workspace, region, dbName: database },
1471
+ body: migration,
800
1472
  ...this.extraProps
801
1473
  });
802
1474
  }
803
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
804
- return operationsByTag.branch.updateBranchMetadata({
805
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
806
- body: metadata,
1475
+ getMigrationRequest({
1476
+ workspace,
1477
+ region,
1478
+ database,
1479
+ migrationRequest
1480
+ }) {
1481
+ return operationsByTag.migrationRequests.getMigrationRequest({
1482
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
807
1483
  ...this.extraProps
808
1484
  });
809
1485
  }
810
- getBranchMetadata(workspace, database, branch) {
811
- return operationsByTag.branch.getBranchMetadata({
812
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1486
+ updateMigrationRequest({
1487
+ workspace,
1488
+ region,
1489
+ database,
1490
+ migrationRequest,
1491
+ update
1492
+ }) {
1493
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1494
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1495
+ body: update,
813
1496
  ...this.extraProps
814
1497
  });
815
1498
  }
816
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
817
- return operationsByTag.branch.getBranchMigrationHistory({
818
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
819
- body: options,
1499
+ listMigrationRequestsCommits({
1500
+ workspace,
1501
+ region,
1502
+ database,
1503
+ migrationRequest,
1504
+ page
1505
+ }) {
1506
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1507
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1508
+ body: { page },
820
1509
  ...this.extraProps
821
1510
  });
822
1511
  }
823
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
824
- return operationsByTag.branch.executeBranchMigrationPlan({
825
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
826
- body: migrationPlan,
1512
+ compareMigrationRequest({
1513
+ workspace,
1514
+ region,
1515
+ database,
1516
+ migrationRequest
1517
+ }) {
1518
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1519
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
827
1520
  ...this.extraProps
828
1521
  });
829
1522
  }
830
- getBranchMigrationPlan(workspace, database, branch, schema) {
831
- return operationsByTag.branch.getBranchMigrationPlan({
832
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
833
- body: schema,
1523
+ getMigrationRequestIsMerged({
1524
+ workspace,
1525
+ region,
1526
+ database,
1527
+ migrationRequest
1528
+ }) {
1529
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1530
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
834
1531
  ...this.extraProps
835
1532
  });
836
1533
  }
837
- getBranchStats(workspace, database, branch) {
838
- return operationsByTag.branch.getBranchStats({
839
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1534
+ mergeMigrationRequest({
1535
+ workspace,
1536
+ region,
1537
+ database,
1538
+ migrationRequest
1539
+ }) {
1540
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1541
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
840
1542
  ...this.extraProps
841
1543
  });
842
1544
  }
843
1545
  }
844
- class TableApi {
1546
+ class MigrationsApi {
845
1547
  constructor(extraProps) {
846
1548
  this.extraProps = extraProps;
847
1549
  }
848
- createTable(workspace, database, branch, tableName) {
849
- return operationsByTag.table.createTable({
850
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
851
- ...this.extraProps
852
- });
853
- }
854
- deleteTable(workspace, database, branch, tableName) {
855
- return operationsByTag.table.deleteTable({
856
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1550
+ getBranchMigrationHistory({
1551
+ workspace,
1552
+ region,
1553
+ database,
1554
+ branch,
1555
+ limit,
1556
+ startFrom
1557
+ }) {
1558
+ return operationsByTag.migrations.getBranchMigrationHistory({
1559
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1560
+ body: { limit, startFrom },
857
1561
  ...this.extraProps
858
1562
  });
859
1563
  }
860
- updateTable(workspace, database, branch, tableName, options) {
861
- return operationsByTag.table.updateTable({
862
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
863
- body: options,
1564
+ getBranchMigrationPlan({
1565
+ workspace,
1566
+ region,
1567
+ database,
1568
+ branch,
1569
+ schema
1570
+ }) {
1571
+ return operationsByTag.migrations.getBranchMigrationPlan({
1572
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1573
+ body: schema,
864
1574
  ...this.extraProps
865
1575
  });
866
1576
  }
867
- getTableSchema(workspace, database, branch, tableName) {
868
- return operationsByTag.table.getTableSchema({
869
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1577
+ executeBranchMigrationPlan({
1578
+ workspace,
1579
+ region,
1580
+ database,
1581
+ branch,
1582
+ plan
1583
+ }) {
1584
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1585
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1586
+ body: plan,
870
1587
  ...this.extraProps
871
1588
  });
872
1589
  }
873
- setTableSchema(workspace, database, branch, tableName, options) {
874
- return operationsByTag.table.setTableSchema({
875
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
876
- body: options,
1590
+ getBranchSchemaHistory({
1591
+ workspace,
1592
+ region,
1593
+ database,
1594
+ branch,
1595
+ page
1596
+ }) {
1597
+ return operationsByTag.migrations.getBranchSchemaHistory({
1598
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1599
+ body: { page },
877
1600
  ...this.extraProps
878
1601
  });
879
1602
  }
880
- getTableColumns(workspace, database, branch, tableName) {
881
- return operationsByTag.table.getTableColumns({
882
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1603
+ compareBranchWithUserSchema({
1604
+ workspace,
1605
+ region,
1606
+ database,
1607
+ branch,
1608
+ schema
1609
+ }) {
1610
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1611
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1612
+ body: { schema },
883
1613
  ...this.extraProps
884
1614
  });
885
1615
  }
886
- addTableColumn(workspace, database, branch, tableName, column) {
887
- return operationsByTag.table.addTableColumn({
888
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
889
- body: column,
1616
+ compareBranchSchemas({
1617
+ workspace,
1618
+ region,
1619
+ database,
1620
+ branch,
1621
+ compare,
1622
+ schema
1623
+ }) {
1624
+ return operationsByTag.migrations.compareBranchSchemas({
1625
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1626
+ body: { schema },
890
1627
  ...this.extraProps
891
1628
  });
892
1629
  }
893
- getColumn(workspace, database, branch, tableName, columnName) {
894
- return operationsByTag.table.getColumn({
895
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1630
+ updateBranchSchema({
1631
+ workspace,
1632
+ region,
1633
+ database,
1634
+ branch,
1635
+ migration
1636
+ }) {
1637
+ return operationsByTag.migrations.updateBranchSchema({
1638
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1639
+ body: migration,
896
1640
  ...this.extraProps
897
1641
  });
898
1642
  }
899
- deleteColumn(workspace, database, branch, tableName, columnName) {
900
- return operationsByTag.table.deleteColumn({
901
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1643
+ previewBranchSchemaEdit({
1644
+ workspace,
1645
+ region,
1646
+ database,
1647
+ branch,
1648
+ data
1649
+ }) {
1650
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1651
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1652
+ body: data,
902
1653
  ...this.extraProps
903
1654
  });
904
1655
  }
905
- updateColumn(workspace, database, branch, tableName, columnName, options) {
906
- return operationsByTag.table.updateColumn({
907
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
908
- body: options,
1656
+ applyBranchSchemaEdit({
1657
+ workspace,
1658
+ region,
1659
+ database,
1660
+ branch,
1661
+ edits
1662
+ }) {
1663
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1664
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1665
+ body: { edits },
909
1666
  ...this.extraProps
910
1667
  });
911
1668
  }
912
1669
  }
913
- class RecordsApi {
1670
+ class DatabaseApi {
914
1671
  constructor(extraProps) {
915
1672
  this.extraProps = extraProps;
916
1673
  }
917
- insertRecord(workspace, database, branch, tableName, record) {
918
- return operationsByTag.records.insertRecord({
919
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
920
- body: record,
921
- ...this.extraProps
922
- });
923
- }
924
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
925
- return operationsByTag.records.insertRecordWithID({
926
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
927
- queryParams: options,
928
- body: record,
929
- ...this.extraProps
930
- });
931
- }
932
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
933
- return operationsByTag.records.updateRecordWithID({
934
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
935
- queryParams: options,
936
- body: record,
937
- ...this.extraProps
938
- });
939
- }
940
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
941
- return operationsByTag.records.upsertRecordWithID({
942
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
943
- queryParams: options,
944
- body: record,
945
- ...this.extraProps
946
- });
947
- }
948
- deleteRecord(workspace, database, branch, tableName, recordId) {
949
- return operationsByTag.records.deleteRecord({
950
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1674
+ getDatabaseList({ workspace }) {
1675
+ return operationsByTag.databases.cPGetDatabaseList({
1676
+ pathParams: { workspaceId: workspace },
951
1677
  ...this.extraProps
952
1678
  });
953
1679
  }
954
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
955
- return operationsByTag.records.getRecord({
956
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1680
+ createDatabase({
1681
+ workspace,
1682
+ database,
1683
+ data
1684
+ }) {
1685
+ return operationsByTag.databases.cPCreateDatabase({
1686
+ pathParams: { workspaceId: workspace, dbName: database },
1687
+ body: data,
957
1688
  ...this.extraProps
958
1689
  });
959
1690
  }
960
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
961
- return operationsByTag.records.bulkInsertTableRecords({
962
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
963
- body: { records },
1691
+ deleteDatabase({
1692
+ workspace,
1693
+ database
1694
+ }) {
1695
+ return operationsByTag.databases.cPDeleteDatabase({
1696
+ pathParams: { workspaceId: workspace, dbName: database },
964
1697
  ...this.extraProps
965
1698
  });
966
1699
  }
967
- queryTable(workspace, database, branch, tableName, query) {
968
- return operationsByTag.records.queryTable({
969
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
970
- body: query,
1700
+ getDatabaseMetadata({
1701
+ workspace,
1702
+ database
1703
+ }) {
1704
+ return operationsByTag.databases.cPGetCPDatabaseMetadata({
1705
+ pathParams: { workspaceId: workspace, dbName: database },
971
1706
  ...this.extraProps
972
1707
  });
973
1708
  }
974
- searchTable(workspace, database, branch, tableName, query) {
975
- return operationsByTag.records.searchTable({
976
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
977
- body: query,
1709
+ updateDatabaseMetadata({
1710
+ workspace,
1711
+ database,
1712
+ metadata
1713
+ }) {
1714
+ return operationsByTag.databases.cPUpdateCPDatabaseMetadata({
1715
+ pathParams: { workspaceId: workspace, dbName: database },
1716
+ body: metadata,
978
1717
  ...this.extraProps
979
1718
  });
980
1719
  }
981
- searchBranch(workspace, database, branch, query) {
982
- return operationsByTag.records.searchBranch({
983
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
984
- body: query,
1720
+ listRegions({ workspace }) {
1721
+ return operationsByTag.databases.listRegions({
1722
+ pathParams: { workspaceId: workspace },
985
1723
  ...this.extraProps
986
1724
  });
987
1725
  }
@@ -997,6 +1735,20 @@ class XataApiPlugin {
997
1735
  class XataPlugin {
998
1736
  }
999
1737
 
1738
+ function generateUUID() {
1739
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1740
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1741
+ return v.toString(16);
1742
+ });
1743
+ }
1744
+
1745
+ function cleanFilter(filter) {
1746
+ if (!filter)
1747
+ return void 0;
1748
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1749
+ return values.length > 0 ? filter : void 0;
1750
+ }
1751
+
1000
1752
  var __accessCheck$6 = (obj, member, msg) => {
1001
1753
  if (!member.has(obj))
1002
1754
  throw TypeError("Cannot " + msg);
@@ -1110,9 +1862,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1110
1862
  setter ? setter.call(obj, value) : member.set(obj, value);
1111
1863
  return value;
1112
1864
  };
1113
- var _table$1, _repository, _data;
1865
+ var __privateMethod$3 = (obj, member, method) => {
1866
+ __accessCheck$5(obj, member, "access private method");
1867
+ return method;
1868
+ };
1869
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1114
1870
  const _Query = class {
1115
1871
  constructor(repository, table, data, rawParent) {
1872
+ __privateAdd$5(this, _cleanFilterConstraint);
1116
1873
  __privateAdd$5(this, _table$1, void 0);
1117
1874
  __privateAdd$5(this, _repository, void 0);
1118
1875
  __privateAdd$5(this, _data, { filter: {} });
@@ -1131,7 +1888,7 @@ const _Query = class {
1131
1888
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1132
1889
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1133
1890
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1134
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1891
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1135
1892
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1136
1893
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1137
1894
  this.any = this.any.bind(this);
@@ -1169,21 +1926,29 @@ const _Query = class {
1169
1926
  }
1170
1927
  filter(a, b) {
1171
1928
  if (arguments.length === 1) {
1172
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1929
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1930
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1931
+ }));
1173
1932
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1174
1933
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1175
1934
  } else {
1176
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1935
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
1936
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1177
1937
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1178
1938
  }
1179
1939
  }
1180
- sort(column, direction) {
1940
+ sort(column, direction = "asc") {
1181
1941
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1182
1942
  const sort = [...originalSort, { column, direction }];
1183
1943
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1184
1944
  }
1185
1945
  select(columns) {
1186
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
1946
+ return new _Query(
1947
+ __privateGet$5(this, _repository),
1948
+ __privateGet$5(this, _table$1),
1949
+ { columns },
1950
+ __privateGet$5(this, _data)
1951
+ );
1187
1952
  }
1188
1953
  getPaginated(options = {}) {
1189
1954
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
@@ -1206,11 +1971,20 @@ const _Query = class {
1206
1971
  }
1207
1972
  }
1208
1973
  async getMany(options = {}) {
1209
- const page = await this.getPaginated(options);
1974
+ const { pagination = {}, ...rest } = options;
1975
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
1976
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
1977
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
1978
+ const results = [...page.records];
1979
+ while (page.hasNextPage() && results.length < size) {
1980
+ page = await page.nextPage();
1981
+ results.push(...page.records);
1982
+ }
1210
1983
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1211
1984
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1212
1985
  }
1213
- return page.records;
1986
+ const array = new RecordArray(page, results.slice(0, size));
1987
+ return array;
1214
1988
  }
1215
1989
  async getAll(options = {}) {
1216
1990
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1224,6 +1998,22 @@ const _Query = class {
1224
1998
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1225
1999
  return records[0] ?? null;
1226
2000
  }
2001
+ async getFirstOrThrow(options = {}) {
2002
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2003
+ if (records[0] === void 0)
2004
+ throw new Error("No results found.");
2005
+ return records[0];
2006
+ }
2007
+ async summarize(params = {}) {
2008
+ const { summaries, summariesFilter, ...options } = params;
2009
+ const query = new _Query(
2010
+ __privateGet$5(this, _repository),
2011
+ __privateGet$5(this, _table$1),
2012
+ options,
2013
+ __privateGet$5(this, _data)
2014
+ );
2015
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2016
+ }
1227
2017
  cache(ttl) {
1228
2018
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1229
2019
  }
@@ -1247,9 +2037,20 @@ let Query = _Query;
1247
2037
  _table$1 = new WeakMap();
1248
2038
  _repository = new WeakMap();
1249
2039
  _data = new WeakMap();
2040
+ _cleanFilterConstraint = new WeakSet();
2041
+ cleanFilterConstraint_fn = function(column, value) {
2042
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2043
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2044
+ return { $includes: value };
2045
+ }
2046
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
2047
+ return value.id;
2048
+ }
2049
+ return value;
2050
+ };
1250
2051
  function cleanParent(data, parent) {
1251
2052
  if (isCursorPaginationOptions(data.pagination)) {
1252
- return { ...parent, sorting: void 0, filter: void 0 };
2053
+ return { ...parent, sort: void 0, filter: void 0 };
1253
2054
  }
1254
2055
  return parent;
1255
2056
  }
@@ -1308,318 +2109,486 @@ var __privateMethod$2 = (obj, member, method) => {
1308
2109
  __accessCheck$4(obj, member, "access private method");
1309
2110
  return method;
1310
2111
  };
1311
- var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
2112
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _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;
1312
2113
  class Repository extends Query {
1313
2114
  }
1314
2115
  class RestRepository extends Query {
1315
2116
  constructor(options) {
1316
- super(null, options.table, {});
2117
+ super(
2118
+ null,
2119
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
2120
+ {}
2121
+ );
1317
2122
  __privateAdd$4(this, _insertRecordWithoutId);
1318
2123
  __privateAdd$4(this, _insertRecordWithId);
1319
2124
  __privateAdd$4(this, _bulkInsertTableRecords);
1320
2125
  __privateAdd$4(this, _updateRecordWithID);
1321
2126
  __privateAdd$4(this, _upsertRecordWithID);
1322
2127
  __privateAdd$4(this, _deleteRecord);
1323
- __privateAdd$4(this, _invalidateCache);
1324
- __privateAdd$4(this, _setCacheRecord);
1325
- __privateAdd$4(this, _getCacheRecord);
1326
2128
  __privateAdd$4(this, _setCacheQuery);
1327
2129
  __privateAdd$4(this, _getCacheQuery);
1328
2130
  __privateAdd$4(this, _getSchemaTables$1);
1329
2131
  __privateAdd$4(this, _table, void 0);
1330
2132
  __privateAdd$4(this, _getFetchProps, void 0);
2133
+ __privateAdd$4(this, _db, void 0);
1331
2134
  __privateAdd$4(this, _cache, void 0);
1332
2135
  __privateAdd$4(this, _schemaTables$2, void 0);
2136
+ __privateAdd$4(this, _trace, void 0);
1333
2137
  __privateSet$4(this, _table, options.table);
1334
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1335
- this.db = options.db;
2138
+ __privateSet$4(this, _db, options.db);
1336
2139
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1337
2140
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
2141
+ __privateSet$4(this, _getFetchProps, async () => {
2142
+ const props = await options.pluginOptions.getFetchProps();
2143
+ return { ...props, sessionID: generateUUID() };
2144
+ });
2145
+ const trace = options.pluginOptions.trace ?? defaultTrace;
2146
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2147
+ return trace(name, fn, {
2148
+ ...options2,
2149
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
2150
+ [TraceAttributes.KIND]: "sdk-operation",
2151
+ [TraceAttributes.VERSION]: VERSION
2152
+ });
2153
+ });
1338
2154
  }
1339
- async create(a, b) {
1340
- if (Array.isArray(a)) {
1341
- if (a.length === 0)
1342
- return [];
1343
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1344
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1345
- return records;
1346
- }
1347
- if (isString(a) && isObject(b)) {
1348
- if (a === "")
1349
- throw new Error("The id can't be empty");
1350
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1351
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1352
- return record;
1353
- }
1354
- if (isObject(a) && isString(a.id)) {
1355
- if (a.id === "")
1356
- throw new Error("The id can't be empty");
1357
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1358
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1359
- return record;
1360
- }
1361
- if (isObject(a)) {
1362
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1363
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1364
- return record;
1365
- }
1366
- throw new Error("Invalid arguments for create method");
1367
- }
1368
- async read(a) {
1369
- if (Array.isArray(a)) {
1370
- if (a.length === 0)
1371
- return [];
1372
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1373
- return this.getAll({ filter: { id: { $any: ids } } });
1374
- }
1375
- const id = isString(a) ? a : a.id;
1376
- if (isString(id)) {
1377
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1378
- if (cacheRecord)
1379
- return cacheRecord;
1380
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1381
- try {
1382
- const response = await getRecord({
1383
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1384
- ...fetchProps
1385
- });
1386
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1387
- return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1388
- } catch (e) {
1389
- if (isObject(e) && e.status === 404) {
1390
- return null;
2155
+ async create(a, b, c, d) {
2156
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
2157
+ const ifVersion = parseIfVersion(b, c, d);
2158
+ if (Array.isArray(a)) {
2159
+ if (a.length === 0)
2160
+ return [];
2161
+ const columns = isStringArray(b) ? b : void 0;
2162
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2163
+ }
2164
+ if (isString(a) && isObject(b)) {
2165
+ if (a === "")
2166
+ throw new Error("The id can't be empty");
2167
+ const columns = isStringArray(c) ? c : void 0;
2168
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2169
+ }
2170
+ if (isObject(a) && isString(a.id)) {
2171
+ if (a.id === "")
2172
+ throw new Error("The id can't be empty");
2173
+ const columns = isStringArray(b) ? b : void 0;
2174
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2175
+ }
2176
+ if (isObject(a)) {
2177
+ const columns = isStringArray(b) ? b : void 0;
2178
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2179
+ }
2180
+ throw new Error("Invalid arguments for create method");
2181
+ });
2182
+ }
2183
+ async read(a, b) {
2184
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
2185
+ const columns = isStringArray(b) ? b : ["*"];
2186
+ if (Array.isArray(a)) {
2187
+ if (a.length === 0)
2188
+ return [];
2189
+ const ids = a.map((item) => extractId(item));
2190
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
2191
+ const dictionary = finalObjects.reduce((acc, object) => {
2192
+ acc[object.id] = object;
2193
+ return acc;
2194
+ }, {});
2195
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
2196
+ }
2197
+ const id = extractId(a);
2198
+ if (id) {
2199
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2200
+ try {
2201
+ const response = await getRecord({
2202
+ pathParams: {
2203
+ workspace: "{workspaceId}",
2204
+ dbBranchName: "{dbBranch}",
2205
+ region: "{region}",
2206
+ tableName: __privateGet$4(this, _table),
2207
+ recordId: id
2208
+ },
2209
+ queryParams: { columns },
2210
+ ...fetchProps
2211
+ });
2212
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2213
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2214
+ } catch (e) {
2215
+ if (isObject(e) && e.status === 404) {
2216
+ return null;
2217
+ }
2218
+ throw e;
1391
2219
  }
1392
- throw e;
1393
2220
  }
1394
- }
2221
+ return null;
2222
+ });
1395
2223
  }
1396
- async update(a, b) {
1397
- if (Array.isArray(a)) {
1398
- if (a.length === 0)
1399
- return [];
1400
- if (a.length > 100) {
1401
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2224
+ async readOrThrow(a, b) {
2225
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
2226
+ const result = await this.read(a, b);
2227
+ if (Array.isArray(result)) {
2228
+ const missingIds = compact(
2229
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2230
+ );
2231
+ if (missingIds.length > 0) {
2232
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2233
+ }
2234
+ return result;
1402
2235
  }
1403
- return Promise.all(a.map((object) => this.update(object)));
1404
- }
1405
- if (isString(a) && isObject(b)) {
1406
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1407
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1408
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1409
- return record;
1410
- }
1411
- if (isObject(a) && isString(a.id)) {
1412
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1413
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1414
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1415
- return record;
1416
- }
1417
- throw new Error("Invalid arguments for update method");
1418
- }
1419
- async createOrUpdate(a, b) {
1420
- if (Array.isArray(a)) {
1421
- if (a.length === 0)
1422
- return [];
1423
- if (a.length > 100) {
1424
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2236
+ if (result === null) {
2237
+ const id = extractId(a) ?? "unknown";
2238
+ throw new Error(`Record with id ${id} not found`);
1425
2239
  }
1426
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1427
- }
1428
- if (isString(a) && isObject(b)) {
1429
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1430
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1431
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1432
- return record;
1433
- }
1434
- if (isObject(a) && isString(a.id)) {
1435
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1436
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1437
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1438
- return record;
1439
- }
1440
- throw new Error("Invalid arguments for createOrUpdate method");
1441
- }
1442
- async delete(a) {
1443
- if (Array.isArray(a)) {
1444
- if (a.length === 0)
1445
- return;
1446
- if (a.length > 100) {
1447
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
2240
+ return result;
2241
+ });
2242
+ }
2243
+ async update(a, b, c, d) {
2244
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
2245
+ const ifVersion = parseIfVersion(b, c, d);
2246
+ if (Array.isArray(a)) {
2247
+ if (a.length === 0)
2248
+ return [];
2249
+ if (a.length > 100) {
2250
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2251
+ }
2252
+ const columns = isStringArray(b) ? b : ["*"];
2253
+ return Promise.all(a.map((object) => this.update(object, columns)));
1448
2254
  }
1449
- await Promise.all(a.map((id) => this.delete(id)));
1450
- return;
1451
- }
1452
- if (isString(a)) {
1453
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1454
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1455
- return;
1456
- }
1457
- if (isObject(a) && isString(a.id)) {
1458
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1459
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1460
- return;
1461
- }
1462
- throw new Error("Invalid arguments for delete method");
2255
+ if (isString(a) && isObject(b)) {
2256
+ const columns = isStringArray(c) ? c : void 0;
2257
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2258
+ }
2259
+ if (isObject(a) && isString(a.id)) {
2260
+ const columns = isStringArray(b) ? b : void 0;
2261
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2262
+ }
2263
+ throw new Error("Invalid arguments for update method");
2264
+ });
2265
+ }
2266
+ async updateOrThrow(a, b, c, d) {
2267
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
2268
+ const result = await this.update(a, b, c, d);
2269
+ if (Array.isArray(result)) {
2270
+ const missingIds = compact(
2271
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2272
+ );
2273
+ if (missingIds.length > 0) {
2274
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2275
+ }
2276
+ return result;
2277
+ }
2278
+ if (result === null) {
2279
+ const id = extractId(a) ?? "unknown";
2280
+ throw new Error(`Record with id ${id} not found`);
2281
+ }
2282
+ return result;
2283
+ });
2284
+ }
2285
+ async createOrUpdate(a, b, c, d) {
2286
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2287
+ const ifVersion = parseIfVersion(b, c, d);
2288
+ if (Array.isArray(a)) {
2289
+ if (a.length === 0)
2290
+ return [];
2291
+ if (a.length > 100) {
2292
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2293
+ }
2294
+ const columns = isStringArray(b) ? b : ["*"];
2295
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
2296
+ }
2297
+ if (isString(a) && isObject(b)) {
2298
+ const columns = isStringArray(c) ? c : void 0;
2299
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2300
+ }
2301
+ if (isObject(a) && isString(a.id)) {
2302
+ const columns = isStringArray(c) ? c : void 0;
2303
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2304
+ }
2305
+ throw new Error("Invalid arguments for createOrUpdate method");
2306
+ });
2307
+ }
2308
+ async createOrReplace(a, b, c, d) {
2309
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2310
+ const ifVersion = parseIfVersion(b, c, d);
2311
+ if (Array.isArray(a)) {
2312
+ if (a.length === 0)
2313
+ return [];
2314
+ const columns = isStringArray(b) ? b : ["*"];
2315
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
2316
+ }
2317
+ if (isString(a) && isObject(b)) {
2318
+ const columns = isStringArray(c) ? c : void 0;
2319
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2320
+ }
2321
+ if (isObject(a) && isString(a.id)) {
2322
+ const columns = isStringArray(c) ? c : void 0;
2323
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2324
+ }
2325
+ throw new Error("Invalid arguments for createOrReplace method");
2326
+ });
2327
+ }
2328
+ async delete(a, b) {
2329
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
2330
+ if (Array.isArray(a)) {
2331
+ if (a.length === 0)
2332
+ return [];
2333
+ if (a.length > 100) {
2334
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
2335
+ }
2336
+ return Promise.all(a.map((id) => this.delete(id, b)));
2337
+ }
2338
+ if (isString(a)) {
2339
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2340
+ }
2341
+ if (isObject(a) && isString(a.id)) {
2342
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
2343
+ }
2344
+ throw new Error("Invalid arguments for delete method");
2345
+ });
2346
+ }
2347
+ async deleteOrThrow(a, b) {
2348
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
2349
+ const result = await this.delete(a, b);
2350
+ if (Array.isArray(result)) {
2351
+ const missingIds = compact(
2352
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2353
+ );
2354
+ if (missingIds.length > 0) {
2355
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2356
+ }
2357
+ return result;
2358
+ } else if (result === null) {
2359
+ const id = extractId(a) ?? "unknown";
2360
+ throw new Error(`Record with id ${id} not found`);
2361
+ }
2362
+ return result;
2363
+ });
1463
2364
  }
1464
2365
  async search(query, options = {}) {
1465
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1466
- const { records } = await searchTable({
1467
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1468
- body: {
1469
- query,
1470
- fuzziness: options.fuzziness,
1471
- highlight: options.highlight,
1472
- filter: options.filter
1473
- },
1474
- ...fetchProps
2366
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
2367
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2368
+ const { records } = await searchTable({
2369
+ pathParams: {
2370
+ workspace: "{workspaceId}",
2371
+ dbBranchName: "{dbBranch}",
2372
+ region: "{region}",
2373
+ tableName: __privateGet$4(this, _table)
2374
+ },
2375
+ body: {
2376
+ query,
2377
+ fuzziness: options.fuzziness,
2378
+ prefix: options.prefix,
2379
+ highlight: options.highlight,
2380
+ filter: options.filter,
2381
+ boosters: options.boosters
2382
+ },
2383
+ ...fetchProps
2384
+ });
2385
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2386
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2387
+ });
2388
+ }
2389
+ async aggregate(aggs, filter) {
2390
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2391
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2392
+ const result = await aggregateTable({
2393
+ pathParams: {
2394
+ workspace: "{workspaceId}",
2395
+ dbBranchName: "{dbBranch}",
2396
+ region: "{region}",
2397
+ tableName: __privateGet$4(this, _table)
2398
+ },
2399
+ body: { aggs, filter },
2400
+ ...fetchProps
2401
+ });
2402
+ return result;
1475
2403
  });
1476
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1477
- return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1478
2404
  }
1479
2405
  async query(query) {
1480
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1481
- if (cacheQuery)
1482
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1483
- const data = query.getQueryOptions();
1484
- const body = {
1485
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1486
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1487
- page: data.pagination,
1488
- columns: data.columns
1489
- };
1490
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1491
- const { meta, records: objects } = await queryTable({
1492
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1493
- body,
1494
- ...fetchProps
2406
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
2407
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
2408
+ if (cacheQuery)
2409
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
2410
+ const data = query.getQueryOptions();
2411
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2412
+ const { meta, records: objects } = await queryTable({
2413
+ pathParams: {
2414
+ workspace: "{workspaceId}",
2415
+ dbBranchName: "{dbBranch}",
2416
+ region: "{region}",
2417
+ tableName: __privateGet$4(this, _table)
2418
+ },
2419
+ body: {
2420
+ filter: cleanFilter(data.filter),
2421
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2422
+ page: data.pagination,
2423
+ columns: data.columns ?? ["*"]
2424
+ },
2425
+ ...fetchProps
2426
+ });
2427
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2428
+ const records = objects.map(
2429
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2430
+ );
2431
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
2432
+ return new Page(query, meta, records);
2433
+ });
2434
+ }
2435
+ async summarizeTable(query, summaries, summariesFilter) {
2436
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2437
+ const data = query.getQueryOptions();
2438
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2439
+ const result = await summarizeTable({
2440
+ pathParams: {
2441
+ workspace: "{workspaceId}",
2442
+ dbBranchName: "{dbBranch}",
2443
+ region: "{region}",
2444
+ tableName: __privateGet$4(this, _table)
2445
+ },
2446
+ body: {
2447
+ filter: cleanFilter(data.filter),
2448
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2449
+ columns: data.columns,
2450
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2451
+ summaries,
2452
+ summariesFilter
2453
+ },
2454
+ ...fetchProps
2455
+ });
2456
+ return result;
1495
2457
  });
1496
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1497
- const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
1498
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1499
- return new Page(query, meta, records);
1500
2458
  }
1501
2459
  }
1502
2460
  _table = new WeakMap();
1503
2461
  _getFetchProps = new WeakMap();
2462
+ _db = new WeakMap();
1504
2463
  _cache = new WeakMap();
1505
2464
  _schemaTables$2 = new WeakMap();
2465
+ _trace = new WeakMap();
1506
2466
  _insertRecordWithoutId = new WeakSet();
1507
- insertRecordWithoutId_fn = async function(object) {
2467
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1508
2468
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1509
2469
  const record = transformObjectLinks(object);
1510
2470
  const response = await insertRecord({
1511
2471
  pathParams: {
1512
2472
  workspace: "{workspaceId}",
1513
2473
  dbBranchName: "{dbBranch}",
2474
+ region: "{region}",
1514
2475
  tableName: __privateGet$4(this, _table)
1515
2476
  },
2477
+ queryParams: { columns },
1516
2478
  body: record,
1517
2479
  ...fetchProps
1518
2480
  });
1519
- const finalObject = await this.read(response.id);
1520
- if (!finalObject) {
1521
- throw new Error("The server failed to save the record");
1522
- }
1523
- return finalObject;
2481
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2482
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1524
2483
  };
1525
2484
  _insertRecordWithId = new WeakSet();
1526
- insertRecordWithId_fn = async function(recordId, object) {
2485
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
1527
2486
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1528
2487
  const record = transformObjectLinks(object);
1529
2488
  const response = await insertRecordWithID({
1530
2489
  pathParams: {
1531
2490
  workspace: "{workspaceId}",
1532
2491
  dbBranchName: "{dbBranch}",
2492
+ region: "{region}",
1533
2493
  tableName: __privateGet$4(this, _table),
1534
2494
  recordId
1535
2495
  },
1536
2496
  body: record,
1537
- queryParams: { createOnly: true },
2497
+ queryParams: { createOnly, columns, ifVersion },
1538
2498
  ...fetchProps
1539
2499
  });
1540
- const finalObject = await this.read(response.id);
1541
- if (!finalObject) {
1542
- throw new Error("The server failed to save the record");
1543
- }
1544
- return finalObject;
2500
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2501
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1545
2502
  };
1546
2503
  _bulkInsertTableRecords = new WeakSet();
1547
- bulkInsertTableRecords_fn = async function(objects) {
2504
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1548
2505
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1549
2506
  const records = objects.map((object) => transformObjectLinks(object));
1550
- const { recordIDs } = await bulkInsertTableRecords({
1551
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2507
+ const response = await bulkInsertTableRecords({
2508
+ pathParams: {
2509
+ workspace: "{workspaceId}",
2510
+ dbBranchName: "{dbBranch}",
2511
+ region: "{region}",
2512
+ tableName: __privateGet$4(this, _table)
2513
+ },
2514
+ queryParams: { columns },
1552
2515
  body: { records },
1553
2516
  ...fetchProps
1554
2517
  });
1555
- const finalObjects = await this.read(recordIDs);
1556
- if (finalObjects.length !== objects.length) {
1557
- throw new Error("The server failed to save some records");
2518
+ if (!isResponseWithRecords(response)) {
2519
+ throw new Error("Request included columns but server didn't include them");
1558
2520
  }
1559
- const dictionary = finalObjects.reduce((acc, object) => {
1560
- acc[object.id] = object;
1561
- return acc;
1562
- }, {});
1563
- return recordIDs.map((id) => dictionary[id]);
2521
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2522
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
1564
2523
  };
1565
2524
  _updateRecordWithID = new WeakSet();
1566
- updateRecordWithID_fn = async function(recordId, object) {
2525
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1567
2526
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1568
2527
  const record = transformObjectLinks(object);
1569
- const response = await updateRecordWithID({
1570
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1571
- body: record,
1572
- ...fetchProps
1573
- });
1574
- const item = await this.read(response.id);
1575
- if (!item)
1576
- throw new Error("The server failed to save the record");
1577
- return item;
2528
+ try {
2529
+ const response = await updateRecordWithID({
2530
+ pathParams: {
2531
+ workspace: "{workspaceId}",
2532
+ dbBranchName: "{dbBranch}",
2533
+ region: "{region}",
2534
+ tableName: __privateGet$4(this, _table),
2535
+ recordId
2536
+ },
2537
+ queryParams: { columns, ifVersion },
2538
+ body: record,
2539
+ ...fetchProps
2540
+ });
2541
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2542
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2543
+ } catch (e) {
2544
+ if (isObject(e) && e.status === 404) {
2545
+ return null;
2546
+ }
2547
+ throw e;
2548
+ }
1578
2549
  };
1579
2550
  _upsertRecordWithID = new WeakSet();
1580
- upsertRecordWithID_fn = async function(recordId, object) {
2551
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
1581
2552
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1582
2553
  const response = await upsertRecordWithID({
1583
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
2554
+ pathParams: {
2555
+ workspace: "{workspaceId}",
2556
+ dbBranchName: "{dbBranch}",
2557
+ region: "{region}",
2558
+ tableName: __privateGet$4(this, _table),
2559
+ recordId
2560
+ },
2561
+ queryParams: { columns, ifVersion },
1584
2562
  body: object,
1585
2563
  ...fetchProps
1586
2564
  });
1587
- const item = await this.read(response.id);
1588
- if (!item)
1589
- throw new Error("The server failed to save the record");
1590
- return item;
2565
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2566
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1591
2567
  };
1592
2568
  _deleteRecord = new WeakSet();
1593
- deleteRecord_fn = async function(recordId) {
2569
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1594
2570
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1595
- await deleteRecord({
1596
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1597
- ...fetchProps
1598
- });
1599
- };
1600
- _invalidateCache = new WeakSet();
1601
- invalidateCache_fn = async function(recordId) {
1602
- await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1603
- const cacheItems = await __privateGet$4(this, _cache).getAll();
1604
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1605
- for (const [key, value] of queries) {
1606
- const ids = getIds(value);
1607
- if (ids.includes(recordId))
1608
- await __privateGet$4(this, _cache).delete(key);
2571
+ try {
2572
+ const response = await deleteRecord({
2573
+ pathParams: {
2574
+ workspace: "{workspaceId}",
2575
+ dbBranchName: "{dbBranch}",
2576
+ region: "{region}",
2577
+ tableName: __privateGet$4(this, _table),
2578
+ recordId
2579
+ },
2580
+ queryParams: { columns },
2581
+ ...fetchProps
2582
+ });
2583
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2584
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2585
+ } catch (e) {
2586
+ if (isObject(e) && e.status === 404) {
2587
+ return null;
2588
+ }
2589
+ throw e;
1609
2590
  }
1610
2591
  };
1611
- _setCacheRecord = new WeakSet();
1612
- setCacheRecord_fn = async function(record) {
1613
- if (!__privateGet$4(this, _cache).cacheRecords)
1614
- return;
1615
- await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1616
- };
1617
- _getCacheRecord = new WeakSet();
1618
- getCacheRecord_fn = async function(recordId) {
1619
- if (!__privateGet$4(this, _cache).cacheRecords)
1620
- return null;
1621
- return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1622
- };
1623
2592
  _setCacheQuery = new WeakSet();
1624
2593
  setCacheQuery_fn = async function(query, meta, records) {
1625
2594
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1642,7 +2611,7 @@ getSchemaTables_fn$1 = async function() {
1642
2611
  return __privateGet$4(this, _schemaTables$2);
1643
2612
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1644
2613
  const { schema } = await getBranchDetails({
1645
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2614
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1646
2615
  ...fetchProps
1647
2616
  });
1648
2617
  __privateSet$4(this, _schemaTables$2, schema.tables);
@@ -1655,7 +2624,7 @@ const transformObjectLinks = (object) => {
1655
2624
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1656
2625
  }, {});
1657
2626
  };
1658
- const initObject = (db, schemaTables, table, object) => {
2627
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1659
2628
  const result = {};
1660
2629
  const { xata, ...rest } = object ?? {};
1661
2630
  Object.assign(result, rest);
@@ -1663,6 +2632,8 @@ const initObject = (db, schemaTables, table, object) => {
1663
2632
  if (!columns)
1664
2633
  console.error(`Table ${table} not found in schema`);
1665
2634
  for (const column of columns ?? []) {
2635
+ if (!isValidColumn(selectedColumns, column))
2636
+ continue;
1666
2637
  const value = result[column.name];
1667
2638
  switch (column.type) {
1668
2639
  case "datetime": {
@@ -1679,17 +2650,42 @@ const initObject = (db, schemaTables, table, object) => {
1679
2650
  if (!linkTable) {
1680
2651
  console.error(`Failed to parse link for field ${column.name}`);
1681
2652
  } else if (isObject(value)) {
1682
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2653
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2654
+ if (item === column.name) {
2655
+ return [...acc, "*"];
2656
+ }
2657
+ if (item.startsWith(`${column.name}.`)) {
2658
+ const [, ...path] = item.split(".");
2659
+ return [...acc, path.join(".")];
2660
+ }
2661
+ return acc;
2662
+ }, []);
2663
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2664
+ } else {
2665
+ result[column.name] = null;
1683
2666
  }
1684
2667
  break;
1685
2668
  }
2669
+ default:
2670
+ result[column.name] = value ?? null;
2671
+ if (column.notNull === true && value === null) {
2672
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2673
+ }
2674
+ break;
1686
2675
  }
1687
2676
  }
1688
- result.read = function() {
1689
- return db[table].read(result["id"]);
2677
+ result.read = function(columns2) {
2678
+ return db[table].read(result["id"], columns2);
1690
2679
  };
1691
- result.update = function(data) {
1692
- return db[table].update(result["id"], data);
2680
+ result.update = function(data, b, c) {
2681
+ const columns2 = isStringArray(b) ? b : ["*"];
2682
+ const ifVersion = parseIfVersion(b, c);
2683
+ return db[table].update(result["id"], data, columns2, { ifVersion });
2684
+ };
2685
+ result.replace = function(data, b, c) {
2686
+ const columns2 = isStringArray(b) ? b : ["*"];
2687
+ const ifVersion = parseIfVersion(b, c);
2688
+ return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
1693
2689
  };
1694
2690
  result.delete = function() {
1695
2691
  return db[table].delete(result["id"]);
@@ -1703,14 +2699,32 @@ const initObject = (db, schemaTables, table, object) => {
1703
2699
  Object.freeze(result);
1704
2700
  return result;
1705
2701
  };
1706
- function getIds(value) {
1707
- if (Array.isArray(value)) {
1708
- return value.map((item) => getIds(item)).flat();
2702
+ function isResponseWithRecords(value) {
2703
+ return isObject(value) && Array.isArray(value.records);
2704
+ }
2705
+ function extractId(value) {
2706
+ if (isString(value))
2707
+ return value;
2708
+ if (isObject(value) && isString(value.id))
2709
+ return value.id;
2710
+ return void 0;
2711
+ }
2712
+ function isValidColumn(columns, column) {
2713
+ if (columns.includes("*"))
2714
+ return true;
2715
+ if (column.type === "link") {
2716
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2717
+ return linkColumns.length > 0;
2718
+ }
2719
+ return columns.includes(column.name);
2720
+ }
2721
+ function parseIfVersion(...args) {
2722
+ for (const arg of args) {
2723
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
2724
+ return arg.ifVersion;
2725
+ }
1709
2726
  }
1710
- if (!isObject(value))
1711
- return [];
1712
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1713
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
2727
+ return void 0;
1714
2728
  }
1715
2729
 
1716
2730
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1737,7 +2751,6 @@ class SimpleCache {
1737
2751
  __privateAdd$3(this, _map, void 0);
1738
2752
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1739
2753
  this.capacity = options.max ?? 500;
1740
- this.cacheRecords = options.cacheRecords ?? true;
1741
2754
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1742
2755
  }
1743
2756
  async getAll() {
@@ -1763,18 +2776,25 @@ class SimpleCache {
1763
2776
  }
1764
2777
  _map = new WeakMap();
1765
2778
 
1766
- const gt = (value) => ({ $gt: value });
1767
- const ge = (value) => ({ $ge: value });
1768
- const gte = (value) => ({ $ge: value });
1769
- const lt = (value) => ({ $lt: value });
1770
- const lte = (value) => ({ $le: value });
1771
- const le = (value) => ({ $le: value });
2779
+ const greaterThan = (value) => ({ $gt: value });
2780
+ const gt = greaterThan;
2781
+ const greaterThanEquals = (value) => ({ $ge: value });
2782
+ const greaterEquals = greaterThanEquals;
2783
+ const gte = greaterThanEquals;
2784
+ const ge = greaterThanEquals;
2785
+ const lessThan = (value) => ({ $lt: value });
2786
+ const lt = lessThan;
2787
+ const lessThanEquals = (value) => ({ $le: value });
2788
+ const lessEquals = lessThanEquals;
2789
+ const lte = lessThanEquals;
2790
+ const le = lessThanEquals;
1772
2791
  const exists = (column) => ({ $exists: column });
1773
2792
  const notExists = (column) => ({ $notExists: column });
1774
2793
  const startsWith = (value) => ({ $startsWith: value });
1775
2794
  const endsWith = (value) => ({ $endsWith: value });
1776
2795
  const pattern = (value) => ({ $pattern: value });
1777
2796
  const is = (value) => ({ $is: value });
2797
+ const equals = is;
1778
2798
  const isNot = (value) => ({ $isNot: value });
1779
2799
  const contains = (value) => ({ $contains: value });
1780
2800
  const includes = (value) => ({ $includes: value });
@@ -1809,16 +2829,19 @@ class SchemaPlugin extends XataPlugin {
1809
2829
  __privateSet$2(this, _schemaTables$1, schemaTables);
1810
2830
  }
1811
2831
  build(pluginOptions) {
1812
- const db = new Proxy({}, {
1813
- get: (_target, table) => {
1814
- if (!isString(table))
1815
- throw new Error("Invalid table name");
1816
- if (__privateGet$2(this, _tables)[table] === void 0) {
1817
- __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
2832
+ const db = new Proxy(
2833
+ {},
2834
+ {
2835
+ get: (_target, table) => {
2836
+ if (!isString(table))
2837
+ throw new Error("Invalid table name");
2838
+ if (__privateGet$2(this, _tables)[table] === void 0) {
2839
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
2840
+ }
2841
+ return __privateGet$2(this, _tables)[table];
1818
2842
  }
1819
- return __privateGet$2(this, _tables)[table];
1820
2843
  }
1821
- });
2844
+ );
1822
2845
  const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1823
2846
  for (const table of tableNames) {
1824
2847
  db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
@@ -1868,7 +2891,7 @@ class SearchPlugin extends XataPlugin {
1868
2891
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1869
2892
  return records.map((record) => {
1870
2893
  const { table = "orphan" } = record.xata;
1871
- return { table, record: initObject(this.db, schemaTables, table, record) };
2894
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1872
2895
  });
1873
2896
  },
1874
2897
  byTable: async (query, options = {}) => {
@@ -1877,7 +2900,7 @@ class SearchPlugin extends XataPlugin {
1877
2900
  return records.reduce((acc, record) => {
1878
2901
  const { table = "orphan" } = record.xata;
1879
2902
  const items = acc[table] ?? [];
1880
- const item = initObject(this.db, schemaTables, table, record);
2903
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1881
2904
  return { ...acc, [table]: [...items, item] };
1882
2905
  }, {});
1883
2906
  }
@@ -1888,10 +2911,10 @@ _schemaTables = new WeakMap();
1888
2911
  _search = new WeakSet();
1889
2912
  search_fn = async function(query, options, getFetchProps) {
1890
2913
  const fetchProps = await getFetchProps();
1891
- const { tables, fuzziness, highlight } = options ?? {};
2914
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1892
2915
  const { records } = await searchBranch({
1893
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1894
- body: { tables, query, fuzziness, highlight },
2916
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2917
+ body: { tables, query, fuzziness, prefix, highlight },
1895
2918
  ...fetchProps
1896
2919
  });
1897
2920
  return records;
@@ -1902,7 +2925,7 @@ getSchemaTables_fn = async function(getFetchProps) {
1902
2925
  return __privateGet$1(this, _schemaTables);
1903
2926
  const fetchProps = await getFetchProps();
1904
2927
  const { schema } = await getBranchDetails({
1905
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2928
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1906
2929
  ...fetchProps
1907
2930
  });
1908
2931
  __privateSet$1(this, _schemaTables, schema.tables);
@@ -1932,19 +2955,27 @@ async function resolveXataBranch(gitBranch, options) {
1932
2955
  const databaseURL = options?.databaseURL || getDatabaseURL();
1933
2956
  const apiKey = options?.apiKey || getAPIKey();
1934
2957
  if (!databaseURL)
1935
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
2958
+ throw new Error(
2959
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2960
+ );
1936
2961
  if (!apiKey)
1937
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
2962
+ throw new Error(
2963
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2964
+ );
1938
2965
  const [protocol, , host, , dbName] = databaseURL.split("/");
1939
- const [workspace] = host.split(".");
2966
+ const urlParts = parseWorkspacesUrlParts(host);
2967
+ if (!urlParts)
2968
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
2969
+ const { workspace, region } = urlParts;
1940
2970
  const { fallbackBranch } = getEnvironment();
1941
2971
  const { branch } = await resolveBranch({
1942
2972
  apiKey,
1943
2973
  apiUrl: databaseURL,
1944
2974
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1945
2975
  workspacesApiUrl: `${protocol}//${host}`,
1946
- pathParams: { dbName, workspace },
1947
- queryParams: { gitBranch, fallbackBranch }
2976
+ pathParams: { dbName, workspace, region },
2977
+ queryParams: { gitBranch, fallbackBranch },
2978
+ trace: defaultTrace
1948
2979
  });
1949
2980
  return branch;
1950
2981
  }
@@ -1952,19 +2983,26 @@ async function getDatabaseBranch(branch, options) {
1952
2983
  const databaseURL = options?.databaseURL || getDatabaseURL();
1953
2984
  const apiKey = options?.apiKey || getAPIKey();
1954
2985
  if (!databaseURL)
1955
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
2986
+ throw new Error(
2987
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2988
+ );
1956
2989
  if (!apiKey)
1957
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
2990
+ throw new Error(
2991
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2992
+ );
1958
2993
  const [protocol, , host, , database] = databaseURL.split("/");
1959
- const [workspace] = host.split(".");
1960
- const dbBranchName = `${database}:${branch}`;
2994
+ const urlParts = parseWorkspacesUrlParts(host);
2995
+ if (!urlParts)
2996
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
2997
+ const { workspace, region } = urlParts;
1961
2998
  try {
1962
2999
  return await getBranchDetails({
1963
3000
  apiKey,
1964
3001
  apiUrl: databaseURL,
1965
3002
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1966
3003
  workspacesApiUrl: `${protocol}//${host}`,
1967
- pathParams: { dbBranchName, workspace }
3004
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3005
+ trace: defaultTrace
1968
3006
  });
1969
3007
  } catch (err) {
1970
3008
  if (isObject(err) && err.status === 404)
@@ -2004,17 +3042,20 @@ var __privateMethod = (obj, member, method) => {
2004
3042
  return method;
2005
3043
  };
2006
3044
  const buildClient = (plugins) => {
2007
- var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3045
+ var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
2008
3046
  return _a = class {
2009
3047
  constructor(options = {}, schemaTables) {
2010
3048
  __privateAdd(this, _parseOptions);
2011
3049
  __privateAdd(this, _getFetchProps);
2012
3050
  __privateAdd(this, _evaluateBranch);
2013
3051
  __privateAdd(this, _branch, void 0);
3052
+ __privateAdd(this, _options, void 0);
2014
3053
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3054
+ __privateSet(this, _options, safeOptions);
2015
3055
  const pluginOptions = {
2016
3056
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2017
- cache: safeOptions.cache
3057
+ cache: safeOptions.cache,
3058
+ trace: safeOptions.trace
2018
3059
  };
2019
3060
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2020
3061
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2033,22 +3074,26 @@ const buildClient = (plugins) => {
2033
3074
  }
2034
3075
  }
2035
3076
  }
2036
- }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3077
+ async getConfig() {
3078
+ const databaseURL = __privateGet(this, _options).databaseURL;
3079
+ const branch = await __privateGet(this, _options).branch();
3080
+ return { databaseURL, branch };
3081
+ }
3082
+ }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2037
3083
  const fetch = getFetchImplementation(options?.fetch);
2038
3084
  const databaseURL = options?.databaseURL || getDatabaseURL();
2039
3085
  const apiKey = options?.apiKey || getAPIKey();
2040
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
3086
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3087
+ const trace = options?.trace ?? defaultTrace;
2041
3088
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2042
- if (!databaseURL || !apiKey) {
2043
- throw new Error("Options databaseURL and apiKey are required");
3089
+ if (!apiKey) {
3090
+ throw new Error("Option apiKey is required");
2044
3091
  }
2045
- return { fetch, databaseURL, apiKey, branch, cache };
2046
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
2047
- fetch,
2048
- apiKey,
2049
- databaseURL,
2050
- branch
2051
- }) {
3092
+ if (!databaseURL) {
3093
+ throw new Error("Option databaseURL is required");
3094
+ }
3095
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID() };
3096
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
2052
3097
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2053
3098
  if (!branchValue)
2054
3099
  throw new Error("Unable to resolve branch value");
@@ -2058,9 +3103,11 @@ const buildClient = (plugins) => {
2058
3103
  apiUrl: "",
2059
3104
  workspacesApiUrl: (path, params) => {
2060
3105
  const hasBranch = params.dbBranchName ?? params.branch;
2061
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
3106
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2062
3107
  return databaseURL + newPath;
2063
- }
3108
+ },
3109
+ trace,
3110
+ clientID
2064
3111
  };
2065
3112
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2066
3113
  if (__privateGet(this, _branch))
@@ -2142,25 +3189,25 @@ class Serializer {
2142
3189
  });
2143
3190
  }
2144
3191
  }
2145
- const serialize = () => {
2146
- throw new Error("Not implemented");
3192
+ const defaultSerializer = new Serializer();
3193
+ const serialize = (data) => {
3194
+ return defaultSerializer.toJSON(data);
2147
3195
  };
2148
- const deserialize = () => {
2149
- throw new Error("Not implemented");
3196
+ const deserialize = (json) => {
3197
+ return defaultSerializer.fromJSON(json);
2150
3198
  };
2151
3199
 
2152
3200
  function buildWorkerRunner(config) {
2153
3201
  return function xataWorker(name, _worker) {
2154
3202
  return async (...args) => {
2155
- const result = await fetch("http://localhost:64749", {
3203
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
3204
+ const result = await fetch(url, {
2156
3205
  method: "POST",
2157
3206
  headers: { "Content-Type": "application/json" },
2158
- body: JSON.stringify({
2159
- name,
2160
- payload: args
2161
- })
3207
+ body: serialize({ args })
2162
3208
  });
2163
- return result.json();
3209
+ const text = await result.text();
3210
+ return deserialize(text);
2164
3211
  };
2165
3212
  };
2166
3213
  }
@@ -2172,5 +3219,5 @@ class XataError extends Error {
2172
3219
  }
2173
3220
  }
2174
3221
 
2175
- 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, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, 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, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
3222
+ 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, buildClient, buildWorkerRunner, bulkInsertTableRecords, cPCreateDatabase, cPDeleteDatabase, cPGetCPDatabaseMetadata, cPGetDatabaseList, cPUpdateCPDatabaseMetadata, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, 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 };
2176
3223
  //# sourceMappingURL=index.mjs.map