@xata.io/client 0.17.1 → 0.18.1

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
@@ -150,7 +150,7 @@ function getFetchImplementation(userFetch) {
150
150
  return fetchImpl;
151
151
  }
152
152
 
153
- const VERSION = "0.17.1";
153
+ const VERSION = "0.18.1";
154
154
 
155
155
  class ErrorWithCause extends Error {
156
156
  constructor(message, options) {
@@ -386,6 +386,7 @@ const getDatabaseMetadata = (variables) => fetch$1({
386
386
  method: "get",
387
387
  ...variables
388
388
  });
389
+ const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
389
390
  const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
390
391
  const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
391
392
  const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
@@ -529,6 +530,11 @@ const searchBranch = (variables) => fetch$1({
529
530
  method: "post",
530
531
  ...variables
531
532
  });
533
+ const summarizeTable = (variables) => fetch$1({
534
+ url: "/db/{dbBranchName}/tables/{tableName}/summarize",
535
+ method: "post",
536
+ ...variables
537
+ });
532
538
  const operationsByTag = {
533
539
  users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
534
540
  workspaces: {
@@ -551,6 +557,7 @@ const operationsByTag = {
551
557
  createDatabase,
552
558
  deleteDatabase,
553
559
  getDatabaseMetadata,
560
+ updateDatabaseMetadata,
554
561
  getGitBranchesMapping,
555
562
  addGitBranchesEntry,
556
563
  removeGitBranchesEntry,
@@ -608,7 +615,8 @@ const operationsByTag = {
608
615
  bulkInsertTableRecords,
609
616
  queryTable,
610
617
  searchTable,
611
- searchBranch
618
+ searchBranch,
619
+ summarizeTable
612
620
  }
613
621
  };
614
622
 
@@ -859,6 +867,13 @@ class DatabaseApi {
859
867
  ...this.extraProps
860
868
  });
861
869
  }
870
+ updateDatabaseMetadata(workspace, dbName, options = {}) {
871
+ return operationsByTag.database.updateDatabaseMetadata({
872
+ pathParams: { workspace, dbName },
873
+ body: options,
874
+ ...this.extraProps
875
+ });
876
+ }
862
877
  getGitBranchesMapping(workspace, dbName) {
863
878
  return operationsByTag.database.getGitBranchesMapping({
864
879
  pathParams: { workspace, dbName },
@@ -1085,6 +1100,13 @@ class RecordsApi {
1085
1100
  ...this.extraProps
1086
1101
  });
1087
1102
  }
1103
+ summarizeTable(workspace, database, branch, tableName, query) {
1104
+ return operationsByTag.records.summarizeTable({
1105
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1106
+ body: query,
1107
+ ...this.extraProps
1108
+ });
1109
+ }
1088
1110
  }
1089
1111
  class MigrationRequestsApi {
1090
1112
  constructor(extraProps) {
@@ -1335,9 +1357,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1335
1357
  setter ? setter.call(obj, value) : member.set(obj, value);
1336
1358
  return value;
1337
1359
  };
1338
- var _table$1, _repository, _data;
1360
+ var __privateMethod$3 = (obj, member, method) => {
1361
+ __accessCheck$5(obj, member, "access private method");
1362
+ return method;
1363
+ };
1364
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1339
1365
  const _Query = class {
1340
1366
  constructor(repository, table, data, rawParent) {
1367
+ __privateAdd$5(this, _cleanFilterConstraint);
1341
1368
  __privateAdd$5(this, _table$1, void 0);
1342
1369
  __privateAdd$5(this, _repository, void 0);
1343
1370
  __privateAdd$5(this, _data, { filter: {} });
@@ -1394,22 +1421,17 @@ const _Query = class {
1394
1421
  }
1395
1422
  filter(a, b) {
1396
1423
  if (arguments.length === 1) {
1397
- const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
1424
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1425
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1426
+ }));
1398
1427
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1399
1428
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1400
1429
  } else {
1401
- const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
1430
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
1402
1431
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1403
1432
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1404
1433
  }
1405
1434
  }
1406
- defaultFilter(column, value) {
1407
- const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1408
- if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1409
- return { $includes: value };
1410
- }
1411
- return value;
1412
- }
1413
1435
  sort(column, direction = "asc") {
1414
1436
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1415
1437
  const sort = [...originalSort, { column, direction }];
@@ -1444,11 +1466,20 @@ const _Query = class {
1444
1466
  }
1445
1467
  }
1446
1468
  async getMany(options = {}) {
1447
- const page = await this.getPaginated(options);
1469
+ const { pagination = {}, ...rest } = options;
1470
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
1471
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
1472
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
1473
+ const results = [...page.records];
1474
+ while (page.hasNextPage() && results.length < size) {
1475
+ page = await page.nextPage();
1476
+ results.push(...page.records);
1477
+ }
1448
1478
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1449
1479
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1450
1480
  }
1451
- return page.records;
1481
+ const array = new RecordArray(page, results.slice(0, size));
1482
+ return array;
1452
1483
  }
1453
1484
  async getAll(options = {}) {
1454
1485
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1462,6 +1493,12 @@ const _Query = class {
1462
1493
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1463
1494
  return records[0] ?? null;
1464
1495
  }
1496
+ async getFirstOrThrow(options = {}) {
1497
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
1498
+ if (records[0] === void 0)
1499
+ throw new Error("No results found.");
1500
+ return records[0];
1501
+ }
1465
1502
  cache(ttl) {
1466
1503
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1467
1504
  }
@@ -1485,6 +1522,17 @@ let Query = _Query;
1485
1522
  _table$1 = new WeakMap();
1486
1523
  _repository = new WeakMap();
1487
1524
  _data = new WeakMap();
1525
+ _cleanFilterConstraint = new WeakSet();
1526
+ cleanFilterConstraint_fn = function(column, value) {
1527
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1528
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1529
+ return { $includes: value };
1530
+ }
1531
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
1532
+ return value.id;
1533
+ }
1534
+ return value;
1535
+ };
1488
1536
  function cleanParent(data, parent) {
1489
1537
  if (isCursorPaginationOptions(data.pagination)) {
1490
1538
  return { ...parent, sorting: void 0, filter: void 0 };
@@ -1653,6 +1701,25 @@ class RestRepository extends Query {
1653
1701
  return null;
1654
1702
  });
1655
1703
  }
1704
+ async readOrThrow(a, b) {
1705
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
1706
+ const result = await this.read(a, b);
1707
+ if (Array.isArray(result)) {
1708
+ const missingIds = compact(
1709
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1710
+ );
1711
+ if (missingIds.length > 0) {
1712
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1713
+ }
1714
+ return result;
1715
+ }
1716
+ if (result === null) {
1717
+ const id = extractId(a) ?? "unknown";
1718
+ throw new Error(`Record with id ${id} not found`);
1719
+ }
1720
+ return result;
1721
+ });
1722
+ }
1656
1723
  async update(a, b, c) {
1657
1724
  return __privateGet$4(this, _trace).call(this, "update", async () => {
1658
1725
  if (Array.isArray(a)) {
@@ -1675,6 +1742,25 @@ class RestRepository extends Query {
1675
1742
  throw new Error("Invalid arguments for update method");
1676
1743
  });
1677
1744
  }
1745
+ async updateOrThrow(a, b, c) {
1746
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
1747
+ const result = await this.update(a, b, c);
1748
+ if (Array.isArray(result)) {
1749
+ const missingIds = compact(
1750
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1751
+ );
1752
+ if (missingIds.length > 0) {
1753
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1754
+ }
1755
+ return result;
1756
+ }
1757
+ if (result === null) {
1758
+ const id = extractId(a) ?? "unknown";
1759
+ throw new Error(`Record with id ${id} not found`);
1760
+ }
1761
+ return result;
1762
+ });
1763
+ }
1678
1764
  async createOrUpdate(a, b, c) {
1679
1765
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1680
1766
  if (Array.isArray(a)) {
@@ -1716,6 +1802,24 @@ class RestRepository extends Query {
1716
1802
  throw new Error("Invalid arguments for delete method");
1717
1803
  });
1718
1804
  }
1805
+ async deleteOrThrow(a, b) {
1806
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
1807
+ const result = await this.delete(a, b);
1808
+ if (Array.isArray(result)) {
1809
+ const missingIds = compact(
1810
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1811
+ );
1812
+ if (missingIds.length > 0) {
1813
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1814
+ }
1815
+ return result;
1816
+ } else if (result === null) {
1817
+ const id = extractId(a) ?? "unknown";
1818
+ throw new Error(`Record with id ${id} not found`);
1819
+ }
1820
+ return result;
1821
+ });
1822
+ }
1719
1823
  async search(query, options = {}) {
1720
1824
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1721
1825
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1927,9 +2031,17 @@ const initObject = (db, schemaTables, table, object) => {
1927
2031
  console.error(`Failed to parse link for field ${column.name}`);
1928
2032
  } else if (isObject(value)) {
1929
2033
  result[column.name] = initObject(db, schemaTables, linkTable, value);
2034
+ } else {
2035
+ result[column.name] = null;
1930
2036
  }
1931
2037
  break;
1932
2038
  }
2039
+ default:
2040
+ result[column.name] = value ?? null;
2041
+ if (column.notNull === true && value === null) {
2042
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2043
+ }
2044
+ break;
1933
2045
  }
1934
2046
  }
1935
2047
  result.read = function(columns2) {
@@ -2453,5 +2565,5 @@ class XataError extends Error {
2453
2565
  }
2454
2566
  }
2455
2567
 
2456
- export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateBranchSchema, updateColumn, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2568
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2457
2569
  //# sourceMappingURL=index.mjs.map