@xata.io/client 0.0.0-alpha.vfbd878f → 0.0.0-alpha.vfbe46c7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -24,13 +24,11 @@ const defaultTrace = async (_name, fn, _options) => {
24
24
  return await fn({
25
25
  setAttributes: () => {
26
26
  return;
27
- },
28
- onError: () => {
29
- return;
30
27
  }
31
28
  });
32
29
  };
33
30
  const TraceAttributes = {
31
+ KIND: "xata.trace.kind",
34
32
  VERSION: "xata.sdk.version",
35
33
  TABLE: "xata.table",
36
34
  HTTP_REQUEST_ID: "http.request_id",
@@ -174,7 +172,7 @@ function getFetchImplementation(userFetch) {
174
172
  return fetchImpl;
175
173
  }
176
174
 
177
- const VERSION = "0.0.0-alpha.vfbd878f";
175
+ const VERSION = "0.0.0-alpha.vfbe46c7";
178
176
 
179
177
  class ErrorWithCause extends Error {
180
178
  constructor(message, options) {
@@ -225,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
225
223
  }, {});
226
224
  const query = new URLSearchParams(cleanQueryParams).toString();
227
225
  const queryString = query.length > 0 ? `?${query}` : "";
228
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
226
+ const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
227
+ return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
228
+ }, {});
229
+ return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
229
230
  };
230
231
  function buildBaseUrl({
231
232
  path,
@@ -233,10 +234,10 @@ function buildBaseUrl({
233
234
  apiUrl,
234
235
  pathParams
235
236
  }) {
236
- if (!pathParams?.workspace)
237
+ if (pathParams?.workspace === void 0)
237
238
  return `${apiUrl}${path}`;
238
239
  const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
239
- return url.replace("{workspaceId}", pathParams.workspace);
240
+ return url.replace("{workspaceId}", String(pathParams.workspace));
240
241
  }
241
242
  function hostHeader(url) {
242
243
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -254,11 +255,12 @@ async function fetch$1({
254
255
  apiKey,
255
256
  apiUrl,
256
257
  workspacesApiUrl,
257
- trace
258
+ trace,
259
+ signal
258
260
  }) {
259
261
  return trace(
260
262
  `${method.toUpperCase()} ${path}`,
261
- async ({ setAttributes, onError }) => {
263
+ async ({ setAttributes }) => {
262
264
  const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
263
265
  const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
264
266
  const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
@@ -275,7 +277,8 @@ async function fetch$1({
275
277
  ...headers,
276
278
  ...hostHeader(fullUrl),
277
279
  Authorization: `Bearer ${apiKey}`
278
- }
280
+ },
281
+ signal
279
282
  });
280
283
  if (response.status === 204) {
281
284
  return {};
@@ -283,6 +286,7 @@ async function fetch$1({
283
286
  const { host, protocol } = parseUrl(response.url);
284
287
  const requestId = response.headers?.get("x-request-id") ?? void 0;
285
288
  setAttributes({
289
+ [TraceAttributes.KIND]: "http",
286
290
  [TraceAttributes.HTTP_REQUEST_ID]: requestId,
287
291
  [TraceAttributes.HTTP_STATUS_CODE]: response.status,
288
292
  [TraceAttributes.HTTP_HOST]: host,
@@ -295,9 +299,7 @@ async function fetch$1({
295
299
  }
296
300
  throw new FetcherError(response.status, jsonResponse, requestId);
297
301
  } catch (error) {
298
- const fetcherError = new FetcherError(response.status, error, requestId);
299
- onError(fetcherError.message);
300
- throw fetcherError;
302
+ throw new FetcherError(response.status, error, requestId);
301
303
  }
302
304
  },
303
305
  { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
@@ -312,217 +314,302 @@ function parseUrl(url) {
312
314
  }
313
315
  }
314
316
 
315
- const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
316
- const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
317
- const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
318
- const getUserAPIKeys = (variables) => fetch$1({
317
+ const getUser = (variables, signal) => fetch$1({ url: "/user", method: "get", ...variables, signal });
318
+ const updateUser = (variables, signal) => fetch$1({
319
+ url: "/user",
320
+ method: "put",
321
+ ...variables,
322
+ signal
323
+ });
324
+ const deleteUser = (variables, signal) => fetch$1({ url: "/user", method: "delete", ...variables, signal });
325
+ const getUserAPIKeys = (variables, signal) => fetch$1({
319
326
  url: "/user/keys",
320
327
  method: "get",
321
- ...variables
328
+ ...variables,
329
+ signal
322
330
  });
323
- const createUserAPIKey = (variables) => fetch$1({
331
+ const createUserAPIKey = (variables, signal) => fetch$1({
324
332
  url: "/user/keys/{keyName}",
325
333
  method: "post",
326
- ...variables
334
+ ...variables,
335
+ signal
327
336
  });
328
- const deleteUserAPIKey = (variables) => fetch$1({
337
+ const deleteUserAPIKey = (variables, signal) => fetch$1({
329
338
  url: "/user/keys/{keyName}",
330
339
  method: "delete",
331
- ...variables
340
+ ...variables,
341
+ signal
332
342
  });
333
- const createWorkspace = (variables) => fetch$1({
343
+ const createWorkspace = (variables, signal) => fetch$1({
334
344
  url: "/workspaces",
335
345
  method: "post",
336
- ...variables
346
+ ...variables,
347
+ signal
337
348
  });
338
- const getWorkspacesList = (variables) => fetch$1({
349
+ const getWorkspacesList = (variables, signal) => fetch$1({
339
350
  url: "/workspaces",
340
351
  method: "get",
341
- ...variables
352
+ ...variables,
353
+ signal
342
354
  });
343
- const getWorkspace = (variables) => fetch$1({
355
+ const getWorkspace = (variables, signal) => fetch$1({
344
356
  url: "/workspaces/{workspaceId}",
345
357
  method: "get",
346
- ...variables
358
+ ...variables,
359
+ signal
347
360
  });
348
- const updateWorkspace = (variables) => fetch$1({
361
+ const updateWorkspace = (variables, signal) => fetch$1({
349
362
  url: "/workspaces/{workspaceId}",
350
363
  method: "put",
351
- ...variables
364
+ ...variables,
365
+ signal
352
366
  });
353
- const deleteWorkspace = (variables) => fetch$1({
367
+ const deleteWorkspace = (variables, signal) => fetch$1({
354
368
  url: "/workspaces/{workspaceId}",
355
369
  method: "delete",
356
- ...variables
370
+ ...variables,
371
+ signal
357
372
  });
358
- const getWorkspaceMembersList = (variables) => fetch$1({
373
+ const getWorkspaceMembersList = (variables, signal) => fetch$1({
359
374
  url: "/workspaces/{workspaceId}/members",
360
375
  method: "get",
361
- ...variables
376
+ ...variables,
377
+ signal
362
378
  });
363
- const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
364
- const removeWorkspaceMember = (variables) => fetch$1({
379
+ const updateWorkspaceMemberRole = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
380
+ const removeWorkspaceMember = (variables, signal) => fetch$1({
365
381
  url: "/workspaces/{workspaceId}/members/{userId}",
366
382
  method: "delete",
367
- ...variables
383
+ ...variables,
384
+ signal
368
385
  });
369
- const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
370
- const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
371
- const cancelWorkspaceMemberInvite = (variables) => fetch$1({
386
+ const inviteWorkspaceMember = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
387
+ const updateWorkspaceMemberInvite = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
388
+ const cancelWorkspaceMemberInvite = (variables, signal) => fetch$1({
372
389
  url: "/workspaces/{workspaceId}/invites/{inviteId}",
373
390
  method: "delete",
374
- ...variables
391
+ ...variables,
392
+ signal
375
393
  });
376
- const resendWorkspaceMemberInvite = (variables) => fetch$1({
394
+ const resendWorkspaceMemberInvite = (variables, signal) => fetch$1({
377
395
  url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
378
396
  method: "post",
379
- ...variables
397
+ ...variables,
398
+ signal
380
399
  });
381
- const acceptWorkspaceMemberInvite = (variables) => fetch$1({
400
+ const acceptWorkspaceMemberInvite = (variables, signal) => fetch$1({
382
401
  url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
383
402
  method: "post",
384
- ...variables
403
+ ...variables,
404
+ signal
385
405
  });
386
- const getDatabaseList = (variables) => fetch$1({
406
+ const getDatabaseList = (variables, signal) => fetch$1({
387
407
  url: "/dbs",
388
408
  method: "get",
389
- ...variables
409
+ ...variables,
410
+ signal
390
411
  });
391
- const getBranchList = (variables) => fetch$1({
412
+ const getBranchList = (variables, signal) => fetch$1({
392
413
  url: "/dbs/{dbName}",
393
414
  method: "get",
394
- ...variables
415
+ ...variables,
416
+ signal
395
417
  });
396
- const createDatabase = (variables) => fetch$1({
418
+ const createDatabase = (variables, signal) => fetch$1({
397
419
  url: "/dbs/{dbName}",
398
420
  method: "put",
399
- ...variables
421
+ ...variables,
422
+ signal
400
423
  });
401
- const deleteDatabase = (variables) => fetch$1({
424
+ const deleteDatabase = (variables, signal) => fetch$1({
402
425
  url: "/dbs/{dbName}",
403
426
  method: "delete",
404
- ...variables
427
+ ...variables,
428
+ signal
405
429
  });
406
- const getDatabaseMetadata = (variables) => fetch$1({
430
+ const getDatabaseMetadata = (variables, signal) => fetch$1({
407
431
  url: "/dbs/{dbName}/metadata",
408
432
  method: "get",
409
- ...variables
433
+ ...variables,
434
+ signal
410
435
  });
411
- const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
412
- const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
413
- const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
414
- const resolveBranch = (variables) => fetch$1({
436
+ const updateDatabaseMetadata = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
437
+ const getGitBranchesMapping = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
438
+ const addGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
439
+ const removeGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
440
+ const resolveBranch = (variables, signal) => fetch$1({
415
441
  url: "/dbs/{dbName}/resolveBranch",
416
442
  method: "get",
417
- ...variables
443
+ ...variables,
444
+ signal
445
+ });
446
+ const queryMigrationRequests = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
447
+ const createMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
448
+ const getMigrationRequest = (variables, signal) => fetch$1({
449
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
450
+ method: "get",
451
+ ...variables,
452
+ signal
453
+ });
454
+ const updateMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
455
+ const listMigrationRequestsCommits = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
456
+ const compareMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
457
+ const getMigrationRequestIsMerged = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
458
+ const mergeMigrationRequest = (variables, signal) => fetch$1({
459
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
460
+ method: "post",
461
+ ...variables,
462
+ signal
418
463
  });
419
- const getBranchDetails = (variables) => fetch$1({
464
+ const getBranchDetails = (variables, signal) => fetch$1({
420
465
  url: "/db/{dbBranchName}",
421
466
  method: "get",
422
- ...variables
467
+ ...variables,
468
+ signal
423
469
  });
424
- const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
425
- const deleteBranch = (variables) => fetch$1({
470
+ const createBranch = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
471
+ const deleteBranch = (variables, signal) => fetch$1({
426
472
  url: "/db/{dbBranchName}",
427
473
  method: "delete",
428
- ...variables
474
+ ...variables,
475
+ signal
429
476
  });
430
- const updateBranchMetadata = (variables) => fetch$1({
477
+ const updateBranchMetadata = (variables, signal) => fetch$1({
431
478
  url: "/db/{dbBranchName}/metadata",
432
479
  method: "put",
433
- ...variables
480
+ ...variables,
481
+ signal
434
482
  });
435
- const getBranchMetadata = (variables) => fetch$1({
483
+ const getBranchMetadata = (variables, signal) => fetch$1({
436
484
  url: "/db/{dbBranchName}/metadata",
437
485
  method: "get",
438
- ...variables
486
+ ...variables,
487
+ signal
439
488
  });
440
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
441
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
442
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
443
- const getBranchStats = (variables) => fetch$1({
489
+ const getBranchMigrationHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
490
+ const executeBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
491
+ const getBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
492
+ const compareBranchWithUserSchema = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
493
+ const compareBranchSchemas = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
494
+ const updateBranchSchema = (variables, signal) => fetch$1({
495
+ url: "/db/{dbBranchName}/schema/update",
496
+ method: "post",
497
+ ...variables,
498
+ signal
499
+ });
500
+ const previewBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
501
+ const applyBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
502
+ const getBranchSchemaHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
503
+ const getBranchStats = (variables, signal) => fetch$1({
444
504
  url: "/db/{dbBranchName}/stats",
445
505
  method: "get",
446
- ...variables
506
+ ...variables,
507
+ signal
447
508
  });
448
- const createTable = (variables) => fetch$1({
509
+ const createTable = (variables, signal) => fetch$1({
449
510
  url: "/db/{dbBranchName}/tables/{tableName}",
450
511
  method: "put",
451
- ...variables
512
+ ...variables,
513
+ signal
452
514
  });
453
- const deleteTable = (variables) => fetch$1({
515
+ const deleteTable = (variables, signal) => fetch$1({
454
516
  url: "/db/{dbBranchName}/tables/{tableName}",
455
517
  method: "delete",
456
- ...variables
518
+ ...variables,
519
+ signal
457
520
  });
458
- const updateTable = (variables) => fetch$1({
521
+ const updateTable = (variables, signal) => fetch$1({
459
522
  url: "/db/{dbBranchName}/tables/{tableName}",
460
523
  method: "patch",
461
- ...variables
524
+ ...variables,
525
+ signal
462
526
  });
463
- const getTableSchema = (variables) => fetch$1({
527
+ const getTableSchema = (variables, signal) => fetch$1({
464
528
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
465
529
  method: "get",
466
- ...variables
530
+ ...variables,
531
+ signal
467
532
  });
468
- const setTableSchema = (variables) => fetch$1({
533
+ const setTableSchema = (variables, signal) => fetch$1({
469
534
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
470
535
  method: "put",
471
- ...variables
536
+ ...variables,
537
+ signal
472
538
  });
473
- const getTableColumns = (variables) => fetch$1({
539
+ const getTableColumns = (variables, signal) => fetch$1({
474
540
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
475
541
  method: "get",
476
- ...variables
542
+ ...variables,
543
+ signal
477
544
  });
478
- const addTableColumn = (variables) => fetch$1({
545
+ const addTableColumn = (variables, signal) => fetch$1({
479
546
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
480
547
  method: "post",
481
- ...variables
548
+ ...variables,
549
+ signal
482
550
  });
483
- const getColumn = (variables) => fetch$1({
551
+ const getColumn = (variables, signal) => fetch$1({
484
552
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
485
553
  method: "get",
486
- ...variables
554
+ ...variables,
555
+ signal
487
556
  });
488
- const deleteColumn = (variables) => fetch$1({
557
+ const deleteColumn = (variables, signal) => fetch$1({
489
558
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
490
559
  method: "delete",
491
- ...variables
560
+ ...variables,
561
+ signal
492
562
  });
493
- const updateColumn = (variables) => fetch$1({
563
+ const updateColumn = (variables, signal) => fetch$1({
494
564
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
495
565
  method: "patch",
496
- ...variables
566
+ ...variables,
567
+ signal
497
568
  });
498
- const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
499
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
500
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
501
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
502
- const deleteRecord = (variables) => fetch$1({
569
+ const insertRecord = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
570
+ const insertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
571
+ const updateRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
572
+ const upsertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
573
+ const deleteRecord = (variables, signal) => fetch$1({
503
574
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
504
575
  method: "delete",
505
- ...variables
576
+ ...variables,
577
+ signal
506
578
  });
507
- const getRecord = (variables) => fetch$1({
579
+ const getRecord = (variables, signal) => fetch$1({
508
580
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
509
581
  method: "get",
510
- ...variables
582
+ ...variables,
583
+ signal
511
584
  });
512
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
513
- const queryTable = (variables) => fetch$1({
585
+ const bulkInsertTableRecords = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
586
+ const queryTable = (variables, signal) => fetch$1({
514
587
  url: "/db/{dbBranchName}/tables/{tableName}/query",
515
588
  method: "post",
516
- ...variables
589
+ ...variables,
590
+ signal
517
591
  });
518
- const searchTable = (variables) => fetch$1({
592
+ const searchTable = (variables, signal) => fetch$1({
519
593
  url: "/db/{dbBranchName}/tables/{tableName}/search",
520
594
  method: "post",
521
- ...variables
595
+ ...variables,
596
+ signal
522
597
  });
523
- const searchBranch = (variables) => fetch$1({
598
+ const searchBranch = (variables, signal) => fetch$1({
524
599
  url: "/db/{dbBranchName}/search",
525
600
  method: "post",
601
+ ...variables,
602
+ signal
603
+ });
604
+ const summarizeTable = (variables, signal) => fetch$1({
605
+ url: "/db/{dbBranchName}/tables/{tableName}/summarize",
606
+ method: "post",
607
+ ...variables,
608
+ signal
609
+ });
610
+ const aggregateTable = (variables) => fetch$1({
611
+ url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
612
+ method: "post",
526
613
  ...variables
527
614
  });
528
615
  const operationsByTag = {
@@ -547,6 +634,7 @@ const operationsByTag = {
547
634
  createDatabase,
548
635
  deleteDatabase,
549
636
  getDatabaseMetadata,
637
+ updateDatabaseMetadata,
550
638
  getGitBranchesMapping,
551
639
  addGitBranchesEntry,
552
640
  removeGitBranchesEntry,
@@ -559,10 +647,28 @@ const operationsByTag = {
559
647
  deleteBranch,
560
648
  updateBranchMetadata,
561
649
  getBranchMetadata,
650
+ getBranchStats
651
+ },
652
+ migrationRequests: {
653
+ queryMigrationRequests,
654
+ createMigrationRequest,
655
+ getMigrationRequest,
656
+ updateMigrationRequest,
657
+ listMigrationRequestsCommits,
658
+ compareMigrationRequest,
659
+ getMigrationRequestIsMerged,
660
+ mergeMigrationRequest
661
+ },
662
+ branchSchema: {
562
663
  getBranchMigrationHistory,
563
664
  executeBranchMigrationPlan,
564
665
  getBranchMigrationPlan,
565
- getBranchStats
666
+ compareBranchWithUserSchema,
667
+ compareBranchSchemas,
668
+ updateBranchSchema,
669
+ previewBranchSchemaEdit,
670
+ applyBranchSchemaEdit,
671
+ getBranchSchemaHistory
566
672
  },
567
673
  table: {
568
674
  createTable,
@@ -586,7 +692,9 @@ const operationsByTag = {
586
692
  bulkInsertTableRecords,
587
693
  queryTable,
588
694
  searchTable,
589
- searchBranch
695
+ searchBranch,
696
+ summarizeTable,
697
+ aggregateTable
590
698
  }
591
699
  };
592
700
 
@@ -614,6 +722,15 @@ function isHostProviderAlias(alias) {
614
722
  function isHostProviderBuilder(builder) {
615
723
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
616
724
  }
725
+ function parseProviderString(provider = "production") {
726
+ if (isHostProviderAlias(provider)) {
727
+ return provider;
728
+ }
729
+ const [main, workspaces] = provider.split(",");
730
+ if (!main || !workspaces)
731
+ return null;
732
+ return { main, workspaces };
733
+ }
617
734
 
618
735
  var __accessCheck$7 = (obj, member, msg) => {
619
736
  if (!member.has(obj))
@@ -682,6 +799,16 @@ class XataApiClient {
682
799
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
683
800
  return __privateGet$7(this, _namespaces).records;
684
801
  }
802
+ get migrationRequests() {
803
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
804
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
805
+ return __privateGet$7(this, _namespaces).migrationRequests;
806
+ }
807
+ get branchSchema() {
808
+ if (!__privateGet$7(this, _namespaces).branchSchema)
809
+ __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
810
+ return __privateGet$7(this, _namespaces).branchSchema;
811
+ }
685
812
  }
686
813
  _extraProps = new WeakMap();
687
814
  _namespaces = new WeakMap();
@@ -827,6 +954,13 @@ class DatabaseApi {
827
954
  ...this.extraProps
828
955
  });
829
956
  }
957
+ updateDatabaseMetadata(workspace, dbName, options = {}) {
958
+ return operationsByTag.database.updateDatabaseMetadata({
959
+ pathParams: { workspace, dbName },
960
+ body: options,
961
+ ...this.extraProps
962
+ });
963
+ }
830
964
  getGitBranchesMapping(workspace, dbName) {
831
965
  return operationsByTag.database.getGitBranchesMapping({
832
966
  pathParams: { workspace, dbName },
@@ -898,27 +1032,6 @@ class BranchApi {
898
1032
  ...this.extraProps
899
1033
  });
900
1034
  }
901
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
902
- return operationsByTag.branch.getBranchMigrationHistory({
903
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
904
- body: options,
905
- ...this.extraProps
906
- });
907
- }
908
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
909
- return operationsByTag.branch.executeBranchMigrationPlan({
910
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
911
- body: migrationPlan,
912
- ...this.extraProps
913
- });
914
- }
915
- getBranchMigrationPlan(workspace, database, branch, schema) {
916
- return operationsByTag.branch.getBranchMigrationPlan({
917
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
918
- body: schema,
919
- ...this.extraProps
920
- });
921
- }
922
1035
  getBranchStats(workspace, database, branch) {
923
1036
  return operationsByTag.branch.getBranchStats({
924
1037
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -1074,6 +1187,145 @@ class RecordsApi {
1074
1187
  ...this.extraProps
1075
1188
  });
1076
1189
  }
1190
+ summarizeTable(workspace, database, branch, tableName, query) {
1191
+ return operationsByTag.records.summarizeTable({
1192
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1193
+ body: query,
1194
+ ...this.extraProps
1195
+ });
1196
+ }
1197
+ aggregateTable(workspace, database, branch, tableName, query) {
1198
+ return operationsByTag.records.aggregateTable({
1199
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1200
+ body: query,
1201
+ ...this.extraProps
1202
+ });
1203
+ }
1204
+ }
1205
+ class MigrationRequestsApi {
1206
+ constructor(extraProps) {
1207
+ this.extraProps = extraProps;
1208
+ }
1209
+ queryMigrationRequests(workspace, database, options = {}) {
1210
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1211
+ pathParams: { workspace, dbName: database },
1212
+ body: options,
1213
+ ...this.extraProps
1214
+ });
1215
+ }
1216
+ createMigrationRequest(workspace, database, options) {
1217
+ return operationsByTag.migrationRequests.createMigrationRequest({
1218
+ pathParams: { workspace, dbName: database },
1219
+ body: options,
1220
+ ...this.extraProps
1221
+ });
1222
+ }
1223
+ getMigrationRequest(workspace, database, migrationRequest) {
1224
+ return operationsByTag.migrationRequests.getMigrationRequest({
1225
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1226
+ ...this.extraProps
1227
+ });
1228
+ }
1229
+ updateMigrationRequest(workspace, database, migrationRequest, options) {
1230
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1231
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1232
+ body: options,
1233
+ ...this.extraProps
1234
+ });
1235
+ }
1236
+ listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1237
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1238
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1239
+ body: options,
1240
+ ...this.extraProps
1241
+ });
1242
+ }
1243
+ compareMigrationRequest(workspace, database, migrationRequest) {
1244
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1245
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1246
+ ...this.extraProps
1247
+ });
1248
+ }
1249
+ getMigrationRequestIsMerged(workspace, database, migrationRequest) {
1250
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1251
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1252
+ ...this.extraProps
1253
+ });
1254
+ }
1255
+ mergeMigrationRequest(workspace, database, migrationRequest) {
1256
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1257
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1258
+ ...this.extraProps
1259
+ });
1260
+ }
1261
+ }
1262
+ class BranchSchemaApi {
1263
+ constructor(extraProps) {
1264
+ this.extraProps = extraProps;
1265
+ }
1266
+ getBranchMigrationHistory(workspace, database, branch, options = {}) {
1267
+ return operationsByTag.branchSchema.getBranchMigrationHistory({
1268
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1269
+ body: options,
1270
+ ...this.extraProps
1271
+ });
1272
+ }
1273
+ executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1274
+ return operationsByTag.branchSchema.executeBranchMigrationPlan({
1275
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1276
+ body: migrationPlan,
1277
+ ...this.extraProps
1278
+ });
1279
+ }
1280
+ getBranchMigrationPlan(workspace, database, branch, schema) {
1281
+ return operationsByTag.branchSchema.getBranchMigrationPlan({
1282
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1283
+ body: schema,
1284
+ ...this.extraProps
1285
+ });
1286
+ }
1287
+ compareBranchWithUserSchema(workspace, database, branch, schema) {
1288
+ return operationsByTag.branchSchema.compareBranchWithUserSchema({
1289
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1290
+ body: { schema },
1291
+ ...this.extraProps
1292
+ });
1293
+ }
1294
+ compareBranchSchemas(workspace, database, branch, branchName, schema) {
1295
+ return operationsByTag.branchSchema.compareBranchSchemas({
1296
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1297
+ body: { schema },
1298
+ ...this.extraProps
1299
+ });
1300
+ }
1301
+ updateBranchSchema(workspace, database, branch, migration) {
1302
+ return operationsByTag.branchSchema.updateBranchSchema({
1303
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1304
+ body: migration,
1305
+ ...this.extraProps
1306
+ });
1307
+ }
1308
+ previewBranchSchemaEdit(workspace, database, branch, migration) {
1309
+ return operationsByTag.branchSchema.previewBranchSchemaEdit({
1310
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1311
+ body: migration,
1312
+ ...this.extraProps
1313
+ });
1314
+ }
1315
+ applyBranchSchemaEdit(workspace, database, branch, edits) {
1316
+ return operationsByTag.branchSchema.applyBranchSchemaEdit({
1317
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1318
+ body: { edits },
1319
+ ...this.extraProps
1320
+ });
1321
+ }
1322
+ getBranchSchemaHistory(workspace, database, branch, options = {}) {
1323
+ return operationsByTag.branchSchema.getBranchSchemaHistory({
1324
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1325
+ body: options,
1326
+ ...this.extraProps
1327
+ });
1328
+ }
1077
1329
  }
1078
1330
 
1079
1331
  class XataApiPlugin {
@@ -1199,9 +1451,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1199
1451
  setter ? setter.call(obj, value) : member.set(obj, value);
1200
1452
  return value;
1201
1453
  };
1202
- var _table$1, _repository, _data;
1454
+ var __privateMethod$3 = (obj, member, method) => {
1455
+ __accessCheck$5(obj, member, "access private method");
1456
+ return method;
1457
+ };
1458
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1203
1459
  const _Query = class {
1204
1460
  constructor(repository, table, data, rawParent) {
1461
+ __privateAdd$5(this, _cleanFilterConstraint);
1205
1462
  __privateAdd$5(this, _table$1, void 0);
1206
1463
  __privateAdd$5(this, _repository, void 0);
1207
1464
  __privateAdd$5(this, _data, { filter: {} });
@@ -1258,11 +1515,14 @@ const _Query = class {
1258
1515
  }
1259
1516
  filter(a, b) {
1260
1517
  if (arguments.length === 1) {
1261
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1518
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1519
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1520
+ }));
1262
1521
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1263
1522
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1264
1523
  } else {
1265
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1524
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
1525
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1266
1526
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1267
1527
  }
1268
1528
  }
@@ -1300,11 +1560,20 @@ const _Query = class {
1300
1560
  }
1301
1561
  }
1302
1562
  async getMany(options = {}) {
1303
- const page = await this.getPaginated(options);
1563
+ const { pagination = {}, ...rest } = options;
1564
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
1565
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
1566
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
1567
+ const results = [...page.records];
1568
+ while (page.hasNextPage() && results.length < size) {
1569
+ page = await page.nextPage();
1570
+ results.push(...page.records);
1571
+ }
1304
1572
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1305
1573
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1306
1574
  }
1307
- return page.records;
1575
+ const array = new RecordArray(page, results.slice(0, size));
1576
+ return array;
1308
1577
  }
1309
1578
  async getAll(options = {}) {
1310
1579
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1318,6 +1587,12 @@ const _Query = class {
1318
1587
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1319
1588
  return records[0] ?? null;
1320
1589
  }
1590
+ async getFirstOrThrow(options = {}) {
1591
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
1592
+ if (records[0] === void 0)
1593
+ throw new Error("No results found.");
1594
+ return records[0];
1595
+ }
1321
1596
  cache(ttl) {
1322
1597
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1323
1598
  }
@@ -1341,6 +1616,17 @@ let Query = _Query;
1341
1616
  _table$1 = new WeakMap();
1342
1617
  _repository = new WeakMap();
1343
1618
  _data = new WeakMap();
1619
+ _cleanFilterConstraint = new WeakSet();
1620
+ cleanFilterConstraint_fn = function(column, value) {
1621
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1622
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1623
+ return { $includes: value };
1624
+ }
1625
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
1626
+ return value.id;
1627
+ }
1628
+ return value;
1629
+ };
1344
1630
  function cleanParent(data, parent) {
1345
1631
  if (isCursorPaginationOptions(data.pagination)) {
1346
1632
  return { ...parent, sorting: void 0, filter: void 0 };
@@ -1407,7 +1693,11 @@ class Repository extends Query {
1407
1693
  }
1408
1694
  class RestRepository extends Query {
1409
1695
  constructor(options) {
1410
- super(null, options.table, {});
1696
+ super(
1697
+ null,
1698
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
1699
+ {}
1700
+ );
1411
1701
  __privateAdd$4(this, _insertRecordWithoutId);
1412
1702
  __privateAdd$4(this, _insertRecordWithId);
1413
1703
  __privateAdd$4(this, _bulkInsertTableRecords);
@@ -1433,6 +1723,7 @@ class RestRepository extends Query {
1433
1723
  return trace(name, fn, {
1434
1724
  ...options2,
1435
1725
  [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1726
+ [TraceAttributes.KIND]: "sdk-operation",
1436
1727
  [TraceAttributes.VERSION]: VERSION
1437
1728
  });
1438
1729
  });
@@ -1493,7 +1784,7 @@ class RestRepository extends Query {
1493
1784
  ...fetchProps
1494
1785
  });
1495
1786
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1496
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1787
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1497
1788
  } catch (e) {
1498
1789
  if (isObject(e) && e.status === 404) {
1499
1790
  return null;
@@ -1504,6 +1795,25 @@ class RestRepository extends Query {
1504
1795
  return null;
1505
1796
  });
1506
1797
  }
1798
+ async readOrThrow(a, b) {
1799
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
1800
+ const result = await this.read(a, b);
1801
+ if (Array.isArray(result)) {
1802
+ const missingIds = compact(
1803
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1804
+ );
1805
+ if (missingIds.length > 0) {
1806
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1807
+ }
1808
+ return result;
1809
+ }
1810
+ if (result === null) {
1811
+ const id = extractId(a) ?? "unknown";
1812
+ throw new Error(`Record with id ${id} not found`);
1813
+ }
1814
+ return result;
1815
+ });
1816
+ }
1507
1817
  async update(a, b, c) {
1508
1818
  return __privateGet$4(this, _trace).call(this, "update", async () => {
1509
1819
  if (Array.isArray(a)) {
@@ -1526,6 +1836,25 @@ class RestRepository extends Query {
1526
1836
  throw new Error("Invalid arguments for update method");
1527
1837
  });
1528
1838
  }
1839
+ async updateOrThrow(a, b, c) {
1840
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
1841
+ const result = await this.update(a, b, c);
1842
+ if (Array.isArray(result)) {
1843
+ const missingIds = compact(
1844
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1845
+ );
1846
+ if (missingIds.length > 0) {
1847
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1848
+ }
1849
+ return result;
1850
+ }
1851
+ if (result === null) {
1852
+ const id = extractId(a) ?? "unknown";
1853
+ throw new Error(`Record with id ${id} not found`);
1854
+ }
1855
+ return result;
1856
+ });
1857
+ }
1529
1858
  async createOrUpdate(a, b, c) {
1530
1859
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1531
1860
  if (Array.isArray(a)) {
@@ -1567,6 +1896,24 @@ class RestRepository extends Query {
1567
1896
  throw new Error("Invalid arguments for delete method");
1568
1897
  });
1569
1898
  }
1899
+ async deleteOrThrow(a, b) {
1900
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
1901
+ const result = await this.delete(a, b);
1902
+ if (Array.isArray(result)) {
1903
+ const missingIds = compact(
1904
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1905
+ );
1906
+ if (missingIds.length > 0) {
1907
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1908
+ }
1909
+ return result;
1910
+ } else if (result === null) {
1911
+ const id = extractId(a) ?? "unknown";
1912
+ throw new Error(`Record with id ${id} not found`);
1913
+ }
1914
+ return result;
1915
+ });
1916
+ }
1570
1917
  async search(query, options = {}) {
1571
1918
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1572
1919
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1583,7 +1930,18 @@ class RestRepository extends Query {
1583
1930
  ...fetchProps
1584
1931
  });
1585
1932
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1586
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1933
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1934
+ });
1935
+ }
1936
+ async aggregate(aggs, filter) {
1937
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
1938
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1939
+ const result = await aggregateTable({
1940
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1941
+ body: { aggs, filter },
1942
+ ...fetchProps
1943
+ });
1944
+ return result;
1587
1945
  });
1588
1946
  }
1589
1947
  async query(query) {
@@ -1593,7 +1951,7 @@ class RestRepository extends Query {
1593
1951
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1594
1952
  const data = query.getQueryOptions();
1595
1953
  const body = {
1596
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1954
+ filter: cleanFilter(data.filter),
1597
1955
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1598
1956
  page: data.pagination,
1599
1957
  columns: data.columns
@@ -1605,7 +1963,9 @@ class RestRepository extends Query {
1605
1963
  ...fetchProps
1606
1964
  });
1607
1965
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1608
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1966
+ const records = objects.map(
1967
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
1968
+ );
1609
1969
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1610
1970
  return new Page(query, meta, records);
1611
1971
  });
@@ -1632,7 +1992,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1632
1992
  ...fetchProps
1633
1993
  });
1634
1994
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1635
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1995
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1636
1996
  };
1637
1997
  _insertRecordWithId = new WeakSet();
1638
1998
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
@@ -1650,7 +2010,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1650
2010
  ...fetchProps
1651
2011
  });
1652
2012
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1653
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2013
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1654
2014
  };
1655
2015
  _bulkInsertTableRecords = new WeakSet();
1656
2016
  bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
@@ -1666,7 +2026,7 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1666
2026
  throw new Error("Request included columns but server didn't include them");
1667
2027
  }
1668
2028
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1669
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
2029
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
1670
2030
  };
1671
2031
  _updateRecordWithID = new WeakSet();
1672
2032
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1680,7 +2040,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1680
2040
  ...fetchProps
1681
2041
  });
1682
2042
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1683
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2043
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1684
2044
  } catch (e) {
1685
2045
  if (isObject(e) && e.status === 404) {
1686
2046
  return null;
@@ -1698,7 +2058,7 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1698
2058
  ...fetchProps
1699
2059
  });
1700
2060
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1701
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2061
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1702
2062
  };
1703
2063
  _deleteRecord = new WeakSet();
1704
2064
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
@@ -1710,7 +2070,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1710
2070
  ...fetchProps
1711
2071
  });
1712
2072
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1713
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
2073
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1714
2074
  } catch (e) {
1715
2075
  if (isObject(e) && e.status === 404) {
1716
2076
  return null;
@@ -1753,7 +2113,7 @@ const transformObjectLinks = (object) => {
1753
2113
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1754
2114
  }, {});
1755
2115
  };
1756
- const initObject = (db, schemaTables, table, object) => {
2116
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1757
2117
  const result = {};
1758
2118
  const { xata, ...rest } = object ?? {};
1759
2119
  Object.assign(result, rest);
@@ -1761,6 +2121,8 @@ const initObject = (db, schemaTables, table, object) => {
1761
2121
  if (!columns)
1762
2122
  console.error(`Table ${table} not found in schema`);
1763
2123
  for (const column of columns ?? []) {
2124
+ if (!isValidColumn(selectedColumns, column))
2125
+ continue;
1764
2126
  const value = result[column.name];
1765
2127
  switch (column.type) {
1766
2128
  case "datetime": {
@@ -1777,10 +2139,28 @@ const initObject = (db, schemaTables, table, object) => {
1777
2139
  if (!linkTable) {
1778
2140
  console.error(`Failed to parse link for field ${column.name}`);
1779
2141
  } else if (isObject(value)) {
1780
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2142
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2143
+ if (item === column.name) {
2144
+ return [...acc, "*"];
2145
+ }
2146
+ if (item.startsWith(`${column.name}.`)) {
2147
+ const [, ...path] = item.split(".");
2148
+ return [...acc, path.join(".")];
2149
+ }
2150
+ return acc;
2151
+ }, []);
2152
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2153
+ } else {
2154
+ result[column.name] = null;
1781
2155
  }
1782
2156
  break;
1783
2157
  }
2158
+ default:
2159
+ result[column.name] = value ?? null;
2160
+ if (column.notNull === true && value === null) {
2161
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2162
+ }
2163
+ break;
1784
2164
  }
1785
2165
  }
1786
2166
  result.read = function(columns2) {
@@ -1811,6 +2191,21 @@ function extractId(value) {
1811
2191
  return value.id;
1812
2192
  return void 0;
1813
2193
  }
2194
+ function cleanFilter(filter) {
2195
+ if (!filter)
2196
+ return void 0;
2197
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2198
+ return values.length > 0 ? filter : void 0;
2199
+ }
2200
+ function isValidColumn(columns, column) {
2201
+ if (columns.includes("*"))
2202
+ return true;
2203
+ if (column.type === "link") {
2204
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2205
+ return linkColumns.length > 0;
2206
+ }
2207
+ return columns.includes(column.name);
2208
+ }
1814
2209
 
1815
2210
  var __accessCheck$3 = (obj, member, msg) => {
1816
2211
  if (!member.has(obj))
@@ -1976,7 +2371,7 @@ class SearchPlugin extends XataPlugin {
1976
2371
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1977
2372
  return records.map((record) => {
1978
2373
  const { table = "orphan" } = record.xata;
1979
- return { table, record: initObject(this.db, schemaTables, table, record) };
2374
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1980
2375
  });
1981
2376
  },
1982
2377
  byTable: async (query, options = {}) => {
@@ -1985,7 +2380,7 @@ class SearchPlugin extends XataPlugin {
1985
2380
  return records.reduce((acc, record) => {
1986
2381
  const { table = "orphan" } = record.xata;
1987
2382
  const items = acc[table] ?? [];
1988
- const item = initObject(this.db, schemaTables, table, record);
2383
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1989
2384
  return { ...acc, [table]: [...items, item] };
1990
2385
  }, {});
1991
2386
  }
@@ -2183,7 +2578,7 @@ const buildClient = (plugins) => {
2183
2578
  apiUrl: "",
2184
2579
  workspacesApiUrl: (path, params) => {
2185
2580
  const hasBranch = params.dbBranchName ?? params.branch;
2186
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2581
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2187
2582
  return databaseURL + newPath;
2188
2583
  },
2189
2584
  trace
@@ -2320,13 +2715,19 @@ exports.XataPlugin = XataPlugin;
2320
2715
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2321
2716
  exports.addGitBranchesEntry = addGitBranchesEntry;
2322
2717
  exports.addTableColumn = addTableColumn;
2718
+ exports.aggregateTable = aggregateTable;
2719
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
2323
2720
  exports.buildClient = buildClient;
2324
2721
  exports.buildWorkerRunner = buildWorkerRunner;
2325
2722
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2326
2723
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2724
+ exports.compareBranchSchemas = compareBranchSchemas;
2725
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
2726
+ exports.compareMigrationRequest = compareMigrationRequest;
2327
2727
  exports.contains = contains;
2328
2728
  exports.createBranch = createBranch;
2329
2729
  exports.createDatabase = createDatabase;
2730
+ exports.createMigrationRequest = createMigrationRequest;
2330
2731
  exports.createTable = createTable;
2331
2732
  exports.createUserAPIKey = createUserAPIKey;
2332
2733
  exports.createWorkspace = createWorkspace;
@@ -2350,6 +2751,7 @@ exports.getBranchList = getBranchList;
2350
2751
  exports.getBranchMetadata = getBranchMetadata;
2351
2752
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2352
2753
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
2754
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2353
2755
  exports.getBranchStats = getBranchStats;
2354
2756
  exports.getColumn = getColumn;
2355
2757
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
@@ -2358,6 +2760,9 @@ exports.getDatabaseList = getDatabaseList;
2358
2760
  exports.getDatabaseMetadata = getDatabaseMetadata;
2359
2761
  exports.getDatabaseURL = getDatabaseURL;
2360
2762
  exports.getGitBranchesMapping = getGitBranchesMapping;
2763
+ exports.getHostUrl = getHostUrl;
2764
+ exports.getMigrationRequest = getMigrationRequest;
2765
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2361
2766
  exports.getRecord = getRecord;
2362
2767
  exports.getTableColumns = getTableColumns;
2363
2768
  exports.getTableSchema = getTableSchema;
@@ -2380,6 +2785,8 @@ exports.insertRecordWithID = insertRecordWithID;
2380
2785
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2381
2786
  exports.is = is;
2382
2787
  exports.isCursorPaginationOptions = isCursorPaginationOptions;
2788
+ exports.isHostProviderAlias = isHostProviderAlias;
2789
+ exports.isHostProviderBuilder = isHostProviderBuilder;
2383
2790
  exports.isIdentifiable = isIdentifiable;
2384
2791
  exports.isNot = isNot;
2385
2792
  exports.isXataRecord = isXataRecord;
@@ -2387,11 +2794,16 @@ exports.le = le;
2387
2794
  exports.lessEquals = lessEquals;
2388
2795
  exports.lessThan = lessThan;
2389
2796
  exports.lessThanEquals = lessThanEquals;
2797
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
2390
2798
  exports.lt = lt;
2391
2799
  exports.lte = lte;
2800
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2392
2801
  exports.notExists = notExists;
2393
2802
  exports.operationsByTag = operationsByTag;
2803
+ exports.parseProviderString = parseProviderString;
2394
2804
  exports.pattern = pattern;
2805
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
2806
+ exports.queryMigrationRequests = queryMigrationRequests;
2395
2807
  exports.queryTable = queryTable;
2396
2808
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2397
2809
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2402,8 +2814,12 @@ exports.searchTable = searchTable;
2402
2814
  exports.serialize = serialize;
2403
2815
  exports.setTableSchema = setTableSchema;
2404
2816
  exports.startsWith = startsWith;
2817
+ exports.summarizeTable = summarizeTable;
2405
2818
  exports.updateBranchMetadata = updateBranchMetadata;
2819
+ exports.updateBranchSchema = updateBranchSchema;
2406
2820
  exports.updateColumn = updateColumn;
2821
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
2822
+ exports.updateMigrationRequest = updateMigrationRequest;
2407
2823
  exports.updateRecordWithID = updateRecordWithID;
2408
2824
  exports.updateTable = updateTable;
2409
2825
  exports.updateUser = updateUser;