@revisium/client 0.3.0 → 0.4.0

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
@@ -664,17 +664,17 @@ var sdk_gen_exports = /* @__PURE__ */ __exportAll({
664
664
  branches: () => branches,
665
665
  childBranches: () => childBranches,
666
666
  childRevision: () => childRevision,
667
- createBranch: () => createBranch,
668
- createEndpoint: () => createEndpoint,
669
- createProject: () => createProject,
667
+ createBranch: () => createBranch$1,
668
+ createEndpoint: () => createEndpoint$1,
669
+ createProject: () => createProject$1,
670
670
  createRevision: () => createRevision,
671
671
  createRow: () => createRow$1,
672
672
  createRows: () => createRows$1,
673
673
  createTable: () => createTable$1,
674
674
  createUser: () => createUser,
675
- deleteBranch: () => deleteBranch,
676
- deleteEndpoint: () => deleteEndpoint,
677
- deleteProject: () => deleteProject,
675
+ deleteBranch: () => deleteBranch$1,
676
+ deleteEndpoint: () => deleteEndpoint$1,
677
+ deleteProject: () => deleteProject$1,
678
678
  deleteRow: () => deleteRow$1,
679
679
  deleteRows: () => deleteRows$1,
680
680
  deleteTable: () => deleteTable$1,
@@ -690,7 +690,7 @@ var sdk_gen_exports = /* @__PURE__ */ __exportAll({
690
690
  parentBranch: () => parentBranch,
691
691
  parentRevision: () => parentRevision,
692
692
  patchRow: () => patchRow$1,
693
- patchRows: () => patchRows,
693
+ patchRows: () => patchRows$1,
694
694
  project: () => project,
695
695
  projects: () => projects,
696
696
  readiness: () => readiness,
@@ -721,11 +721,11 @@ var sdk_gen_exports = /* @__PURE__ */ __exportAll({
721
721
  tableSchema: () => tableSchema,
722
722
  tables: () => tables,
723
723
  updatePassword: () => updatePassword,
724
- updateProject: () => updateProject,
724
+ updateProject: () => updateProject$1,
725
725
  updateRow: () => updateRow$1,
726
726
  updateRows: () => updateRows$1,
727
727
  updateTable: () => updateTable$1,
728
- uploadFile: () => uploadFile,
728
+ uploadFile: () => uploadFile$1,
729
729
  usersOrganization: () => usersOrganization,
730
730
  usersProject: () => usersProject
731
731
  });
@@ -799,7 +799,7 @@ const projects = (options) => (options.client ?? client).get({
799
799
  /**
800
800
  * Create a new project
801
801
  */
802
- const createProject = (options) => (options.client ?? client).post({
802
+ const createProject$1 = (options) => (options.client ?? client).post({
803
803
  security: [{
804
804
  scheme: "bearer",
805
805
  type: "http"
@@ -855,7 +855,7 @@ const addUserToOrganization = (options) => (options.client ?? client).post({
855
855
  /**
856
856
  * Delete a project
857
857
  */
858
- const deleteProject = (options) => (options.client ?? client).delete({
858
+ const deleteProject$1 = (options) => (options.client ?? client).delete({
859
859
  security: [{
860
860
  scheme: "bearer",
861
861
  type: "http"
@@ -877,7 +877,7 @@ const project = (options) => (options.client ?? client).get({
877
877
  /**
878
878
  * Update project settings
879
879
  */
880
- const updateProject = (options) => (options.client ?? client).put({
880
+ const updateProject$1 = (options) => (options.client ?? client).put({
881
881
  security: [{
882
882
  scheme: "bearer",
883
883
  type: "http"
@@ -951,7 +951,7 @@ const removeUserFromProject = (options) => (options.client ?? client).delete({
951
951
  /**
952
952
  * Delete a non-root branch
953
953
  */
954
- const deleteBranch = (options) => (options.client ?? client).delete({
954
+ const deleteBranch$1 = (options) => (options.client ?? client).delete({
955
955
  security: [{
956
956
  scheme: "bearer",
957
957
  type: "http"
@@ -1109,7 +1109,7 @@ const childBranches = (options) => (options.client ?? client).get({
1109
1109
  /**
1110
1110
  * Create a new branch from this revision
1111
1111
  */
1112
- const createBranch = (options) => (options.client ?? client).post({
1112
+ const createBranch$1 = (options) => (options.client ?? client).post({
1113
1113
  security: [{
1114
1114
  scheme: "bearer",
1115
1115
  type: "http"
@@ -1161,7 +1161,7 @@ const endpoints = (options) => (options.client ?? client).get({
1161
1161
  /**
1162
1162
  * Create an API endpoint for this revision
1163
1163
  */
1164
- const createEndpoint = (options) => (options.client ?? client).post({
1164
+ const createEndpoint$1 = (options) => (options.client ?? client).post({
1165
1165
  security: [{
1166
1166
  scheme: "bearer",
1167
1167
  type: "http"
@@ -1358,7 +1358,7 @@ const updateRows$1 = (options) => (options.client ?? client).put({
1358
1358
  /**
1359
1359
  * Patch multiple rows using JSON Patch
1360
1360
  */
1361
- const patchRows = (options) => (options.client ?? client).patch({
1361
+ const patchRows$1 = (options) => (options.client ?? client).patch({
1362
1362
  security: [{
1363
1363
  scheme: "bearer",
1364
1364
  type: "http"
@@ -1554,7 +1554,7 @@ const renameRow$1 = (options) => (options.client ?? client).patch({
1554
1554
  /**
1555
1555
  * Upload a file to a row field
1556
1556
  */
1557
- const uploadFile = (options) => (options.client ?? client).post({
1557
+ const uploadFile$1 = (options) => (options.client ?? client).post({
1558
1558
  ...formDataBodySerializer,
1559
1559
  security: [{
1560
1560
  scheme: "bearer",
@@ -1581,7 +1581,7 @@ const endpointRelatives = (options) => (options.client ?? client).get({
1581
1581
  /**
1582
1582
  * Delete an endpoint
1583
1583
  */
1584
- const deleteEndpoint = (options) => (options.client ?? client).delete({
1584
+ const deleteEndpoint$1 = (options) => (options.client ?? client).delete({
1585
1585
  security: [{
1586
1586
  scheme: "bearer",
1587
1587
  type: "http"
@@ -1616,7 +1616,7 @@ function unwrap(result) {
1616
1616
  }
1617
1617
  function assertDraft(ctx) {
1618
1618
  assertContext(ctx);
1619
- if (!ctx.isDraft) throw new Error("Mutations are only allowed in draft revision. Use setContext({ revision: \"draft\" }).");
1619
+ if (!ctx.isDraft) throw new Error("Mutations are only allowed in draft revision.");
1620
1620
  }
1621
1621
  function assertContext(ctx) {
1622
1622
  if (!ctx.branch.organizationId) throw new Error("Context not set. Call setContext() first.");
@@ -1624,6 +1624,223 @@ function assertContext(ctx) {
1624
1624
  async function me(client) {
1625
1625
  return unwrap(await me$1({ client }));
1626
1626
  }
1627
+ async function getProjects(ctx, options) {
1628
+ return unwrap(await projects({
1629
+ client: ctx.client,
1630
+ path: { organizationId: ctx.organizationId },
1631
+ query: {
1632
+ first: options?.first ?? 100,
1633
+ after: options?.after
1634
+ }
1635
+ }));
1636
+ }
1637
+ async function createProject(ctx, body) {
1638
+ return unwrap(await createProject$1({
1639
+ client: ctx.client,
1640
+ path: { organizationId: ctx.organizationId },
1641
+ body
1642
+ }));
1643
+ }
1644
+ async function getOrgUsers(ctx, options) {
1645
+ return unwrap(await usersOrganization({
1646
+ client: ctx.client,
1647
+ path: { organizationId: ctx.organizationId },
1648
+ query: {
1649
+ first: options?.first ?? 100,
1650
+ after: options?.after
1651
+ }
1652
+ }));
1653
+ }
1654
+ async function addOrgUser(ctx, userId, roleId) {
1655
+ unwrap(await addUserToOrganization({
1656
+ client: ctx.client,
1657
+ path: { organizationId: ctx.organizationId },
1658
+ body: {
1659
+ userId,
1660
+ roleId
1661
+ }
1662
+ }));
1663
+ }
1664
+ async function removeOrgUser(ctx, userId) {
1665
+ unwrap(await removeUserFromOrganization({
1666
+ client: ctx.client,
1667
+ path: { organizationId: ctx.organizationId },
1668
+ body: { userId }
1669
+ }));
1670
+ }
1671
+ async function getProject(ctx) {
1672
+ return unwrap(await project({
1673
+ client: ctx.client,
1674
+ path: {
1675
+ organizationId: ctx.organizationId,
1676
+ projectName: ctx.projectName
1677
+ }
1678
+ }));
1679
+ }
1680
+ async function updateProject(ctx, body) {
1681
+ unwrap(await updateProject$1({
1682
+ client: ctx.client,
1683
+ path: {
1684
+ organizationId: ctx.organizationId,
1685
+ projectName: ctx.projectName
1686
+ },
1687
+ body
1688
+ }));
1689
+ }
1690
+ async function deleteProject(ctx) {
1691
+ unwrap(await deleteProject$1({
1692
+ client: ctx.client,
1693
+ path: {
1694
+ organizationId: ctx.organizationId,
1695
+ projectName: ctx.projectName
1696
+ }
1697
+ }));
1698
+ }
1699
+ async function getBranches(ctx, options) {
1700
+ return unwrap(await branches({
1701
+ client: ctx.client,
1702
+ path: {
1703
+ organizationId: ctx.organizationId,
1704
+ projectName: ctx.projectName
1705
+ },
1706
+ query: {
1707
+ first: options?.first ?? 100,
1708
+ after: options?.after
1709
+ }
1710
+ }));
1711
+ }
1712
+ async function getRootBranch(ctx) {
1713
+ return unwrap(await rootBranch({
1714
+ client: ctx.client,
1715
+ path: {
1716
+ organizationId: ctx.organizationId,
1717
+ projectName: ctx.projectName
1718
+ }
1719
+ }));
1720
+ }
1721
+ async function getProjectUsers(ctx, options) {
1722
+ return unwrap(await usersProject({
1723
+ client: ctx.client,
1724
+ path: {
1725
+ organizationId: ctx.organizationId,
1726
+ projectName: ctx.projectName
1727
+ },
1728
+ query: {
1729
+ first: options?.first ?? 100,
1730
+ after: options?.after
1731
+ }
1732
+ }));
1733
+ }
1734
+ async function addProjectUser(ctx, userId, roleId) {
1735
+ unwrap(await addUserToProject({
1736
+ client: ctx.client,
1737
+ path: {
1738
+ organizationId: ctx.organizationId,
1739
+ projectName: ctx.projectName
1740
+ },
1741
+ body: {
1742
+ userId,
1743
+ roleId
1744
+ }
1745
+ }));
1746
+ }
1747
+ async function removeProjectUser(ctx, userId) {
1748
+ unwrap(await removeUserFromProject({
1749
+ client: ctx.client,
1750
+ path: {
1751
+ organizationId: ctx.organizationId,
1752
+ projectName: ctx.projectName,
1753
+ userId
1754
+ }
1755
+ }));
1756
+ }
1757
+ async function getBranch(client, branch$1) {
1758
+ return unwrap(await branch({
1759
+ client,
1760
+ path: {
1761
+ organizationId: branch$1.organizationId,
1762
+ projectName: branch$1.projectName,
1763
+ branchName: branch$1.branchName
1764
+ }
1765
+ }));
1766
+ }
1767
+ async function createBranch(client, revisionId, branchName) {
1768
+ return unwrap(await createBranch$1({
1769
+ client,
1770
+ path: { revisionId },
1771
+ body: { branchName }
1772
+ }));
1773
+ }
1774
+ async function deleteBranch(client, branch) {
1775
+ unwrap(await deleteBranch$1({
1776
+ client,
1777
+ path: {
1778
+ organizationId: branch.organizationId,
1779
+ projectName: branch.projectName,
1780
+ branchName: branch.branchName
1781
+ }
1782
+ }));
1783
+ }
1784
+ async function getBranchTouched(client, branch) {
1785
+ return unwrap(await branchTouched({
1786
+ client,
1787
+ path: {
1788
+ organizationId: branch.organizationId,
1789
+ projectName: branch.projectName,
1790
+ branchName: branch.branchName
1791
+ }
1792
+ }));
1793
+ }
1794
+ async function getRevisions(client, branch, options) {
1795
+ return unwrap(await revisions({
1796
+ client,
1797
+ path: {
1798
+ organizationId: branch.organizationId,
1799
+ projectName: branch.projectName,
1800
+ branchName: branch.branchName
1801
+ },
1802
+ query: {
1803
+ ...options,
1804
+ first: options?.first ?? 100
1805
+ }
1806
+ }));
1807
+ }
1808
+ async function getStartRevision(client, branch) {
1809
+ return unwrap(await startRevision({
1810
+ client,
1811
+ path: {
1812
+ organizationId: branch.organizationId,
1813
+ projectName: branch.projectName,
1814
+ branchName: branch.branchName
1815
+ }
1816
+ }));
1817
+ }
1818
+ async function fetchDraftRevisionId(client, branch) {
1819
+ return unwrap(await draftRevision({
1820
+ client,
1821
+ path: {
1822
+ organizationId: branch.organizationId,
1823
+ projectName: branch.projectName,
1824
+ branchName: branch.branchName
1825
+ }
1826
+ })).id;
1827
+ }
1828
+ async function fetchHeadRevisionId(client, branch) {
1829
+ return unwrap(await headRevision({
1830
+ client,
1831
+ path: {
1832
+ organizationId: branch.organizationId,
1833
+ projectName: branch.projectName,
1834
+ branchName: branch.branchName
1835
+ }
1836
+ })).id;
1837
+ }
1838
+ async function validateRevisionId(client, revisionId) {
1839
+ unwrap(await revision({
1840
+ client,
1841
+ path: { revisionId }
1842
+ }));
1843
+ }
1627
1844
  async function getMigrations(ctx) {
1628
1845
  assertContext(ctx);
1629
1846
  const revisionId = await ctx.getRevisionId();
@@ -1641,6 +1858,15 @@ async function applyMigrations(ctx, migrations) {
1641
1858
  body: migrations
1642
1859
  }));
1643
1860
  }
1861
+ async function applyMigrationsWithStatus(ctx, migrations) {
1862
+ assertDraft(ctx);
1863
+ const revisionId = await ctx.getRevisionId();
1864
+ return unwrap(await applyMigrations$1({
1865
+ client: ctx.client,
1866
+ path: { revisionId },
1867
+ body: migrations
1868
+ }));
1869
+ }
1644
1870
  async function getTables(ctx, options) {
1645
1871
  const revisionId = await ctx.getRevisionId();
1646
1872
  return unwrap(await tables({
@@ -1672,33 +1898,62 @@ async function getTableSchema(ctx, tableId) {
1672
1898
  }
1673
1899
  }));
1674
1900
  }
1675
- async function getRows(ctx, tableId, options) {
1901
+ async function getTableCountRows(ctx, tableId) {
1676
1902
  const revisionId = await ctx.getRevisionId();
1677
- return unwrap(await rows({
1903
+ return unwrap(await tableCountRows({
1904
+ client: ctx.client,
1905
+ path: {
1906
+ revisionId,
1907
+ tableId
1908
+ }
1909
+ }));
1910
+ }
1911
+ async function getTableForeignKeysBy(ctx, tableId, options) {
1912
+ const revisionId = await ctx.getRevisionId();
1913
+ return unwrap(await tableForeignKeysBy({
1678
1914
  client: ctx.client,
1679
1915
  path: {
1680
1916
  revisionId,
1681
1917
  tableId
1682
1918
  },
1683
- body: options ?? { first: 100 }
1919
+ query: {
1920
+ first: options?.first ?? 100,
1921
+ after: options?.after
1922
+ }
1684
1923
  }));
1685
1924
  }
1686
- async function getRow(ctx, tableId, rowId) {
1925
+ async function getTableForeignKeysTo(ctx, tableId, options) {
1687
1926
  const revisionId = await ctx.getRevisionId();
1688
- return unwrap(await row({
1927
+ return unwrap(await tableForeignKeysTo({
1689
1928
  client: ctx.client,
1690
1929
  path: {
1691
1930
  revisionId,
1692
- tableId,
1693
- rowId
1931
+ tableId
1932
+ },
1933
+ query: {
1934
+ first: options?.first ?? 100,
1935
+ after: options?.after
1694
1936
  }
1695
1937
  }));
1696
1938
  }
1697
- async function getChanges(ctx) {
1939
+ async function getTableCountForeignKeysBy(ctx, tableId) {
1698
1940
  const revisionId = await ctx.getRevisionId();
1699
- return unwrap(await revisionChanges({
1941
+ return unwrap(await tableCountForeignKeysBy({
1700
1942
  client: ctx.client,
1701
- path: { revisionId }
1943
+ path: {
1944
+ revisionId,
1945
+ tableId
1946
+ }
1947
+ }));
1948
+ }
1949
+ async function getTableCountForeignKeysTo(ctx, tableId) {
1950
+ const revisionId = await ctx.getRevisionId();
1951
+ return unwrap(await tableCountForeignKeysTo({
1952
+ client: ctx.client,
1953
+ path: {
1954
+ revisionId,
1955
+ tableId
1956
+ }
1702
1957
  }));
1703
1958
  }
1704
1959
  async function createTable(ctx, tableId, schema) {
@@ -1748,6 +2003,82 @@ async function renameTable(ctx, tableId, nextTableId) {
1748
2003
  body: { nextTableId }
1749
2004
  }));
1750
2005
  }
2006
+ async function getRows(ctx, tableId, options) {
2007
+ const revisionId = await ctx.getRevisionId();
2008
+ return unwrap(await rows({
2009
+ client: ctx.client,
2010
+ path: {
2011
+ revisionId,
2012
+ tableId
2013
+ },
2014
+ body: options ?? { first: 100 }
2015
+ }));
2016
+ }
2017
+ async function getRow(ctx, tableId, rowId) {
2018
+ const revisionId = await ctx.getRevisionId();
2019
+ return unwrap(await row({
2020
+ client: ctx.client,
2021
+ path: {
2022
+ revisionId,
2023
+ tableId,
2024
+ rowId
2025
+ }
2026
+ }));
2027
+ }
2028
+ async function getRowForeignKeysBy(ctx, tableId, rowId, foreignKeyByTableId, options) {
2029
+ const revisionId = await ctx.getRevisionId();
2030
+ return unwrap(await rowForeignKeysBy({
2031
+ client: ctx.client,
2032
+ path: {
2033
+ revisionId,
2034
+ tableId,
2035
+ rowId
2036
+ },
2037
+ query: {
2038
+ foreignKeyByTableId,
2039
+ first: options?.first ?? 100,
2040
+ after: options?.after
2041
+ }
2042
+ }));
2043
+ }
2044
+ async function getRowForeignKeysTo(ctx, tableId, rowId, foreignKeyToTableId, options) {
2045
+ const revisionId = await ctx.getRevisionId();
2046
+ return unwrap(await rowForeignKeysTo({
2047
+ client: ctx.client,
2048
+ path: {
2049
+ revisionId,
2050
+ tableId,
2051
+ rowId
2052
+ },
2053
+ query: {
2054
+ foreignKeyToTableId,
2055
+ first: options?.first ?? 100,
2056
+ after: options?.after
2057
+ }
2058
+ }));
2059
+ }
2060
+ async function getRowCountForeignKeysBy(ctx, tableId, rowId) {
2061
+ const revisionId = await ctx.getRevisionId();
2062
+ return unwrap(await rowCountForeignKeysBy({
2063
+ client: ctx.client,
2064
+ path: {
2065
+ revisionId,
2066
+ tableId,
2067
+ rowId
2068
+ }
2069
+ }));
2070
+ }
2071
+ async function getRowCountForeignKeysTo(ctx, tableId, rowId) {
2072
+ const revisionId = await ctx.getRevisionId();
2073
+ return unwrap(await rowCountForeignKeysTo({
2074
+ client: ctx.client,
2075
+ path: {
2076
+ revisionId,
2077
+ tableId,
2078
+ rowId
2079
+ }
2080
+ }));
2081
+ }
1751
2082
  async function createRow(ctx, tableId, rowId, data) {
1752
2083
  assertDraft(ctx);
1753
2084
  const revisionId = await ctx.getRevisionId();
@@ -1825,6 +2156,18 @@ async function patchRow(ctx, tableId, rowId, patches) {
1825
2156
  body: { patches }
1826
2157
  }));
1827
2158
  }
2159
+ async function patchRows(ctx, tableId, body) {
2160
+ assertDraft(ctx);
2161
+ const revisionId = await ctx.getRevisionId();
2162
+ return unwrap(await patchRows$1({
2163
+ client: ctx.client,
2164
+ path: {
2165
+ revisionId,
2166
+ tableId
2167
+ },
2168
+ body
2169
+ }));
2170
+ }
1828
2171
  async function deleteRow(ctx, tableId, rowId) {
1829
2172
  assertDraft(ctx);
1830
2173
  const revisionId = await ctx.getRevisionId();
@@ -1852,14 +2195,43 @@ async function deleteRows(ctx, tableId, rowIds) {
1852
2195
  async function renameRow(ctx, tableId, rowId, nextRowId) {
1853
2196
  assertDraft(ctx);
1854
2197
  const revisionId = await ctx.getRevisionId();
1855
- return unwrap(await renameRow$1({
2198
+ return unwrap(await renameRow$1({
2199
+ client: ctx.client,
2200
+ path: {
2201
+ revisionId,
2202
+ tableId,
2203
+ rowId
2204
+ },
2205
+ body: { nextRowId }
2206
+ }));
2207
+ }
2208
+ async function getChanges(ctx) {
2209
+ const revisionId = await ctx.getRevisionId();
2210
+ return unwrap(await revisionChanges({
2211
+ client: ctx.client,
2212
+ path: { revisionId }
2213
+ }));
2214
+ }
2215
+ async function getTableChanges(ctx, options) {
2216
+ const revisionId = await ctx.getRevisionId();
2217
+ return unwrap(await tableChanges({
2218
+ client: ctx.client,
2219
+ path: { revisionId },
2220
+ query: {
2221
+ ...options,
2222
+ first: options?.first ?? 100
2223
+ }
2224
+ }));
2225
+ }
2226
+ async function getRowChanges(ctx, options) {
2227
+ const revisionId = await ctx.getRevisionId();
2228
+ return unwrap(await rowChanges({
1856
2229
  client: ctx.client,
1857
- path: {
1858
- revisionId,
1859
- tableId,
1860
- rowId
1861
- },
1862
- body: { nextRowId }
2230
+ path: { revisionId },
2231
+ query: {
2232
+ ...options,
2233
+ first: options?.first ?? 100
2234
+ }
1863
2235
  }));
1864
2236
  }
1865
2237
  async function commit(ctx, comment) {
@@ -1885,36 +2257,51 @@ async function revertChanges(ctx) {
1885
2257
  }
1886
2258
  }));
1887
2259
  }
1888
- async function fetchDraftRevisionId(client, branch) {
1889
- return unwrap(await draftRevision({
1890
- client,
1891
- path: {
1892
- organizationId: branch.organizationId,
1893
- projectName: branch.projectName,
1894
- branchName: branch.branchName
1895
- }
1896
- })).id;
2260
+ async function getEndpoints(ctx) {
2261
+ const revisionId = await ctx.getRevisionId();
2262
+ return unwrap(await endpoints({
2263
+ client: ctx.client,
2264
+ path: { revisionId }
2265
+ }));
1897
2266
  }
1898
- async function fetchHeadRevisionId(client, branch) {
1899
- return unwrap(await headRevision({
2267
+ async function createEndpoint(ctx, body) {
2268
+ const revisionId = await ctx.getRevisionId();
2269
+ return unwrap(await createEndpoint$1({
2270
+ client: ctx.client,
2271
+ path: { revisionId },
2272
+ body
2273
+ }));
2274
+ }
2275
+ async function deleteEndpoint(client, endpointId) {
2276
+ unwrap(await deleteEndpoint$1({
1900
2277
  client,
1901
- path: {
1902
- organizationId: branch.organizationId,
1903
- projectName: branch.projectName,
1904
- branchName: branch.branchName
1905
- }
1906
- })).id;
2278
+ path: { endpointId }
2279
+ }));
1907
2280
  }
1908
- async function validateRevisionId(client, revisionId) {
1909
- unwrap(await revision({
2281
+ async function getEndpointRelatives(client, endpointId) {
2282
+ return unwrap(await endpointRelatives({
1910
2283
  client,
1911
- path: { revisionId }
2284
+ path: { endpointId }
2285
+ }));
2286
+ }
2287
+ async function uploadFile(ctx, tableId, rowId, fileId, file) {
2288
+ assertDraft(ctx);
2289
+ const revisionId = await ctx.getRevisionId();
2290
+ return unwrap(await uploadFile$1({
2291
+ client: ctx.client,
2292
+ path: {
2293
+ revisionId,
2294
+ tableId,
2295
+ rowId,
2296
+ fileId
2297
+ },
2298
+ body: { file }
1912
2299
  }));
1913
2300
  }
1914
2301
 
1915
2302
  //#endregion
1916
- //#region src/revisium-scope.ts
1917
- var RevisiumScope = class {
2303
+ //#region src/revision-scope.ts
2304
+ var RevisionScope = class {
1918
2305
  _client;
1919
2306
  _branch;
1920
2307
  _revisionMode;
@@ -1997,7 +2384,7 @@ var RevisiumScope = class {
1997
2384
  }
1998
2385
  return this._revisionId;
1999
2386
  }
2000
- get _scopeContext() {
2387
+ get context() {
2001
2388
  return {
2002
2389
  client: this._client,
2003
2390
  branch: this._branch,
@@ -2006,72 +2393,119 @@ var RevisiumScope = class {
2006
2393
  };
2007
2394
  }
2008
2395
  async getTables(options) {
2009
- return getTables(this._scopeContext, options);
2396
+ return getTables(this.context, options);
2010
2397
  }
2011
2398
  async getTable(tableId) {
2012
- return getTable(this._scopeContext, tableId);
2399
+ return getTable(this.context, tableId);
2013
2400
  }
2014
2401
  async getTableSchema(tableId) {
2015
- return getTableSchema(this._scopeContext, tableId);
2402
+ return getTableSchema(this.context, tableId);
2016
2403
  }
2017
- async getRows(tableId, options) {
2018
- return getRows(this._scopeContext, tableId, options);
2404
+ async getTableCountRows(tableId) {
2405
+ return getTableCountRows(this.context, tableId);
2019
2406
  }
2020
- async getRow(tableId, rowId) {
2021
- return getRow(this._scopeContext, tableId, rowId);
2407
+ async getTableForeignKeysBy(tableId, options) {
2408
+ return getTableForeignKeysBy(this.context, tableId, options);
2022
2409
  }
2023
- async getChanges() {
2024
- return getChanges(this._scopeContext);
2410
+ async getTableForeignKeysTo(tableId, options) {
2411
+ return getTableForeignKeysTo(this.context, tableId, options);
2025
2412
  }
2026
- async getMigrations() {
2027
- return getMigrations(this._scopeContext);
2413
+ async getTableCountForeignKeysBy(tableId) {
2414
+ return getTableCountForeignKeysBy(this.context, tableId);
2028
2415
  }
2029
- async applyMigrations(migrations) {
2030
- this.assertNotDisposed();
2031
- await applyMigrations(this._scopeContext, migrations);
2032
- this._revisionId = await fetchDraftRevisionId(this._client, this._branch);
2033
- this._stale = false;
2034
- this._owner.notifyBranchChanged(this._branchKey, this);
2416
+ async getTableCountForeignKeysTo(tableId) {
2417
+ return getTableCountForeignKeysTo(this.context, tableId);
2035
2418
  }
2036
2419
  async createTable(tableId, schema) {
2037
- return createTable(this._scopeContext, tableId, schema);
2420
+ return createTable(this.context, tableId, schema);
2038
2421
  }
2039
2422
  async updateTable(tableId, patches) {
2040
- return updateTable(this._scopeContext, tableId, patches);
2423
+ return updateTable(this.context, tableId, patches);
2041
2424
  }
2042
2425
  async deleteTable(tableId) {
2043
- return deleteTable(this._scopeContext, tableId);
2426
+ return deleteTable(this.context, tableId);
2044
2427
  }
2045
2428
  async renameTable(tableId, nextTableId) {
2046
- return renameTable(this._scopeContext, tableId, nextTableId);
2429
+ return renameTable(this.context, tableId, nextTableId);
2430
+ }
2431
+ async getRows(tableId, options) {
2432
+ return getRows(this.context, tableId, options);
2433
+ }
2434
+ async getRow(tableId, rowId) {
2435
+ return getRow(this.context, tableId, rowId);
2436
+ }
2437
+ async getRowForeignKeysBy(tableId, rowId, foreignKeyByTableId, options) {
2438
+ return getRowForeignKeysBy(this.context, tableId, rowId, foreignKeyByTableId, options);
2439
+ }
2440
+ async getRowForeignKeysTo(tableId, rowId, foreignKeyToTableId, options) {
2441
+ return getRowForeignKeysTo(this.context, tableId, rowId, foreignKeyToTableId, options);
2442
+ }
2443
+ async getRowCountForeignKeysBy(tableId, rowId) {
2444
+ return getRowCountForeignKeysBy(this.context, tableId, rowId);
2445
+ }
2446
+ async getRowCountForeignKeysTo(tableId, rowId) {
2447
+ return getRowCountForeignKeysTo(this.context, tableId, rowId);
2047
2448
  }
2048
2449
  async createRow(tableId, rowId, data) {
2049
- return createRow(this._scopeContext, tableId, rowId, data);
2450
+ return createRow(this.context, tableId, rowId, data);
2050
2451
  }
2051
2452
  async createRows(tableId, rows, options) {
2052
- return createRows(this._scopeContext, tableId, rows, options);
2453
+ return createRows(this.context, tableId, rows, options);
2053
2454
  }
2054
2455
  async updateRow(tableId, rowId, data) {
2055
- return updateRow(this._scopeContext, tableId, rowId, data);
2456
+ return updateRow(this.context, tableId, rowId, data);
2056
2457
  }
2057
2458
  async updateRows(tableId, rows, options) {
2058
- return updateRows(this._scopeContext, tableId, rows, options);
2459
+ return updateRows(this.context, tableId, rows, options);
2059
2460
  }
2060
2461
  async patchRow(tableId, rowId, patches) {
2061
- return patchRow(this._scopeContext, tableId, rowId, patches);
2462
+ return patchRow(this.context, tableId, rowId, patches);
2463
+ }
2464
+ async patchRows(tableId, body) {
2465
+ return patchRows(this.context, tableId, body);
2062
2466
  }
2063
2467
  async deleteRow(tableId, rowId) {
2064
- return deleteRow(this._scopeContext, tableId, rowId);
2468
+ return deleteRow(this.context, tableId, rowId);
2065
2469
  }
2066
2470
  async deleteRows(tableId, rowIds) {
2067
- return deleteRows(this._scopeContext, tableId, rowIds);
2471
+ return deleteRows(this.context, tableId, rowIds);
2068
2472
  }
2069
2473
  async renameRow(tableId, rowId, nextRowId) {
2070
- return renameRow(this._scopeContext, tableId, rowId, nextRowId);
2474
+ return renameRow(this.context, tableId, rowId, nextRowId);
2475
+ }
2476
+ async getChanges() {
2477
+ return getChanges(this.context);
2478
+ }
2479
+ async getTableChanges(options) {
2480
+ return getTableChanges(this.context, options);
2481
+ }
2482
+ async getRowChanges(options) {
2483
+ return getRowChanges(this.context, options);
2484
+ }
2485
+ async getMigrations() {
2486
+ return getMigrations(this.context);
2487
+ }
2488
+ async applyMigrations(migrations) {
2489
+ this.assertNotDisposed();
2490
+ await applyMigrations(this.context, migrations);
2491
+ await this._owner.refreshRevisionIds();
2492
+ this._revisionId = await fetchDraftRevisionId(this._client, this._branch);
2493
+ this._stale = false;
2494
+ this._owner.notifyBranchChanged(this._branchKey, this);
2495
+ }
2496
+ async applyMigrationsWithStatus(migrations) {
2497
+ this.assertNotDisposed();
2498
+ const result = await applyMigrationsWithStatus(this.context, migrations);
2499
+ await this._owner.refreshRevisionIds();
2500
+ this._revisionId = await fetchDraftRevisionId(this._client, this._branch);
2501
+ this._stale = false;
2502
+ this._owner.notifyBranchChanged(this._branchKey, this);
2503
+ return result;
2071
2504
  }
2072
2505
  async commit(comment) {
2073
2506
  this.assertNotDisposed();
2074
- const data = await commit(this._scopeContext, comment);
2507
+ const data = await commit(this.context, comment);
2508
+ await this._owner.refreshRevisionIds();
2075
2509
  this._revisionId = await fetchDraftRevisionId(this._client, this._branch);
2076
2510
  this._stale = false;
2077
2511
  this._owner.notifyBranchChanged(this._branchKey, this);
@@ -2079,253 +2513,308 @@ var RevisiumScope = class {
2079
2513
  }
2080
2514
  async revertChanges() {
2081
2515
  this.assertNotDisposed();
2082
- await revertChanges(this._scopeContext);
2516
+ await revertChanges(this.context);
2517
+ await this._owner.refreshRevisionIds();
2083
2518
  this._revisionId = await fetchDraftRevisionId(this._client, this._branch);
2084
2519
  this._stale = false;
2085
2520
  this._owner.notifyBranchChanged(this._branchKey, this);
2086
2521
  }
2522
+ async getEndpoints() {
2523
+ return getEndpoints(this.context);
2524
+ }
2525
+ async createEndpoint(body) {
2526
+ return createEndpoint(this.context, body);
2527
+ }
2528
+ async deleteEndpoint(endpointId) {
2529
+ this.assertNotDisposed();
2530
+ return deleteEndpoint(this._client, endpointId);
2531
+ }
2532
+ async getEndpointRelatives(endpointId) {
2533
+ this.assertNotDisposed();
2534
+ return getEndpointRelatives(this._client, endpointId);
2535
+ }
2536
+ async uploadFile(tableId, rowId, fileId, file) {
2537
+ return uploadFile(this.context, tableId, rowId, fileId, file);
2538
+ }
2087
2539
  };
2088
2540
 
2089
2541
  //#endregion
2090
- //#region src/revisium-client.ts
2091
- var RevisiumClient = class {
2092
- _client;
2093
- _baseUrl;
2094
- _organizationId = null;
2095
- _projectName = null;
2096
- _branchName = null;
2097
- _revisionId = null;
2098
- _isDraft = false;
2099
- _isAuthenticated = false;
2100
- _scopes = /* @__PURE__ */ new Map();
2101
- constructor(options) {
2102
- const url = options.baseUrl;
2103
- this._baseUrl = url.endsWith("/") ? url.slice(0, -1) : url;
2104
- this._client = createClient(createConfig({ baseUrl: this._baseUrl }));
2105
- }
2106
- get baseUrl() {
2107
- return this._baseUrl;
2542
+ //#region src/branch-scope.ts
2543
+ var BranchScope = class BranchScope {
2544
+ _headRevisionId;
2545
+ _draftRevisionId;
2546
+ _scopes = /* @__PURE__ */ new Set();
2547
+ constructor(_client, _branch, headRevisionId, draftRevisionId) {
2548
+ this._client = _client;
2549
+ this._branch = _branch;
2550
+ this._headRevisionId = headRevisionId;
2551
+ this._draftRevisionId = draftRevisionId;
2552
+ }
2553
+ static async create(client, branch) {
2554
+ const [headId, draftId] = await Promise.all([fetchHeadRevisionId(client, branch), fetchDraftRevisionId(client, branch)]);
2555
+ return new BranchScope(client, branch, headId, draftId);
2108
2556
  }
2109
2557
  get organizationId() {
2110
- return this._organizationId;
2558
+ return this._branch.organizationId;
2111
2559
  }
2112
2560
  get projectName() {
2113
- return this._projectName;
2561
+ return this._branch.projectName;
2114
2562
  }
2115
2563
  get branchName() {
2116
- return this._branchName;
2564
+ return this._branch.branchName;
2117
2565
  }
2118
- get revisionId() {
2119
- return this._revisionId;
2566
+ get headRevisionId() {
2567
+ return this._headRevisionId;
2120
2568
  }
2121
- get isDraft() {
2122
- return this._isDraft;
2569
+ get draftRevisionId() {
2570
+ return this._draftRevisionId;
2123
2571
  }
2124
2572
  get client() {
2125
2573
  return this._client;
2126
2574
  }
2127
- isAuthenticated() {
2128
- return this._isAuthenticated;
2129
- }
2130
- async login(username, password) {
2131
- const result = await login({
2575
+ draft() {
2576
+ const scope = new RevisionScope({
2132
2577
  client: this._client,
2133
- body: {
2134
- emailOrUsername: username,
2135
- password
2136
- }
2578
+ branch: this._branch,
2579
+ revisionId: this._draftRevisionId,
2580
+ isDraft: true,
2581
+ revisionMode: "draft",
2582
+ owner: this
2137
2583
  });
2138
- const data = unwrap(result);
2139
- this._client.setConfig({ auth: data.accessToken });
2140
- this._isAuthenticated = true;
2141
- }
2142
- loginWithToken(token) {
2143
- this._client.setConfig({ auth: token });
2144
- this._isAuthenticated = true;
2145
- }
2146
- async me() {
2147
- return me(this._client);
2584
+ this._scopes.add(scope);
2585
+ return scope;
2148
2586
  }
2149
- async setContext(options) {
2150
- const { organizationId, projectName, branchName = "master", revision = "draft" } = options;
2151
- this._organizationId = organizationId;
2152
- this._projectName = projectName;
2153
- this._branchName = branchName;
2154
- const branch = {
2155
- organizationId,
2156
- projectName,
2157
- branchName
2158
- };
2159
- if (revision === "draft") {
2160
- this._revisionId = await fetchDraftRevisionId(this._client, branch);
2161
- this._isDraft = true;
2162
- } else if (revision === "head") {
2163
- this._revisionId = await fetchHeadRevisionId(this._client, branch);
2164
- this._isDraft = false;
2165
- } else {
2166
- await validateRevisionId(this._client, revision);
2167
- this._revisionId = revision;
2168
- this._isDraft = false;
2169
- }
2587
+ head() {
2588
+ const scope = new RevisionScope({
2589
+ client: this._client,
2590
+ branch: this._branch,
2591
+ revisionId: this._headRevisionId,
2592
+ isDraft: false,
2593
+ revisionMode: "head",
2594
+ owner: this
2595
+ });
2596
+ this._scopes.add(scope);
2597
+ return scope;
2170
2598
  }
2171
- async withContext(options) {
2172
- const { organizationId, projectName, branchName = "master", revision = "draft" } = options;
2173
- const branch = {
2174
- organizationId,
2175
- projectName,
2176
- branchName
2177
- };
2178
- let revisionId;
2179
- let isDraft;
2180
- let revisionMode;
2181
- if (revision === "draft") {
2182
- revisionId = await fetchDraftRevisionId(this._client, branch);
2183
- isDraft = true;
2184
- revisionMode = "draft";
2185
- } else if (revision === "head") {
2186
- revisionId = await fetchHeadRevisionId(this._client, branch);
2187
- isDraft = false;
2188
- revisionMode = "head";
2189
- } else {
2190
- await validateRevisionId(this._client, revision);
2191
- revisionId = revision;
2192
- isDraft = false;
2193
- revisionMode = "explicit";
2194
- }
2195
- const scope = new RevisiumScope({
2599
+ async revision(revisionId) {
2600
+ await validateRevisionId(this._client, revisionId);
2601
+ const scope = new RevisionScope({
2196
2602
  client: this._client,
2197
- branch,
2603
+ branch: this._branch,
2198
2604
  revisionId,
2199
- isDraft,
2200
- revisionMode,
2605
+ isDraft: false,
2606
+ revisionMode: "explicit",
2201
2607
  owner: this
2202
2608
  });
2203
- const branchKey = `${organizationId}/${projectName}/${branchName}`;
2204
- let scopeSet = this._scopes.get(branchKey);
2205
- if (!scopeSet) {
2206
- scopeSet = /* @__PURE__ */ new Set();
2207
- this._scopes.set(branchKey, scopeSet);
2208
- }
2209
- scopeSet.add(scope);
2609
+ this._scopes.add(scope);
2210
2610
  return scope;
2211
2611
  }
2612
+ async get() {
2613
+ return getBranch(this._client, this._branch);
2614
+ }
2615
+ async delete() {
2616
+ return deleteBranch(this._client, this._branch);
2617
+ }
2618
+ async getTouched() {
2619
+ return getBranchTouched(this._client, this._branch);
2620
+ }
2621
+ async getRevisions(options) {
2622
+ return getRevisions(this._client, this._branch, options);
2623
+ }
2624
+ async getStartRevision() {
2625
+ return getStartRevision(this._client, this._branch);
2626
+ }
2212
2627
  notifyBranchChanged(branchKey, excludeScope) {
2213
- const scopeSet = this._scopes.get(branchKey);
2214
- if (!scopeSet) return;
2215
- for (const scope of scopeSet) if (scope !== excludeScope) scope.markStale();
2628
+ if (branchKey !== `${this._branch.organizationId}/${this._branch.projectName}/${this._branch.branchName}`) return;
2629
+ for (const scope of this._scopes) if (scope !== excludeScope) scope.markStale();
2216
2630
  }
2217
2631
  unregisterScope(scope) {
2218
- for (const [key, scopeSet] of this._scopes) {
2219
- scopeSet.delete(scope);
2220
- if (scopeSet.size === 0) this._scopes.delete(key);
2221
- }
2632
+ this._scopes.delete(scope);
2633
+ }
2634
+ async refreshRevisionIds() {
2635
+ const [headId, draftId] = await Promise.all([fetchHeadRevisionId(this._client, this._branch), fetchDraftRevisionId(this._client, this._branch)]);
2636
+ this._headRevisionId = headId;
2637
+ this._draftRevisionId = draftId;
2638
+ }
2639
+ };
2640
+
2641
+ //#endregion
2642
+ //#region src/project-scope.ts
2643
+ var ProjectScope = class {
2644
+ constructor(_client, _organizationId, _projectName) {
2645
+ this._client = _client;
2646
+ this._organizationId = _organizationId;
2647
+ this._projectName = _projectName;
2648
+ }
2649
+ get organizationId() {
2650
+ return this._organizationId;
2651
+ }
2652
+ get projectName() {
2653
+ return this._projectName;
2654
+ }
2655
+ get client() {
2656
+ return this._client;
2657
+ }
2658
+ async branch(branchName) {
2659
+ return BranchScope.create(this._client, {
2660
+ client: this._client,
2661
+ organizationId: this._organizationId,
2662
+ projectName: this._projectName,
2663
+ branchName: branchName ?? "master"
2664
+ });
2222
2665
  }
2223
- get _scopeContext() {
2666
+ get projectContext() {
2224
2667
  return {
2225
2668
  client: this._client,
2226
- branch: {
2227
- organizationId: this._organizationId ?? "",
2228
- projectName: this._projectName ?? "",
2229
- branchName: this._branchName ?? ""
2230
- },
2231
- isDraft: this._isDraft,
2232
- getRevisionId: () => {
2233
- if (this._revisionId === null) return Promise.reject(/* @__PURE__ */ new Error("Context not set. Call setContext() first."));
2234
- return Promise.resolve(this._revisionId);
2235
- }
2669
+ organizationId: this._organizationId,
2670
+ projectName: this._projectName
2236
2671
  };
2237
2672
  }
2238
- async getTables(options) {
2239
- return getTables(this._scopeContext, options);
2673
+ async get() {
2674
+ return getProject(this.projectContext);
2240
2675
  }
2241
- async getTable(tableId) {
2242
- return getTable(this._scopeContext, tableId);
2676
+ async update(body) {
2677
+ return updateProject(this.projectContext, body);
2243
2678
  }
2244
- async getTableSchema(tableId) {
2245
- return getTableSchema(this._scopeContext, tableId);
2679
+ async delete() {
2680
+ return deleteProject(this.projectContext);
2246
2681
  }
2247
- async getRows(tableId, options) {
2248
- return getRows(this._scopeContext, tableId, options);
2682
+ async getBranches(options) {
2683
+ return getBranches(this.projectContext, options);
2249
2684
  }
2250
- async getRow(tableId, rowId) {
2251
- return getRow(this._scopeContext, tableId, rowId);
2685
+ async getRootBranch() {
2686
+ return getRootBranch(this.projectContext);
2252
2687
  }
2253
- async getChanges() {
2254
- return getChanges(this._scopeContext);
2688
+ async createBranch(branchName, revisionId) {
2689
+ return createBranch(this._client, revisionId, branchName);
2255
2690
  }
2256
- async getMigrations() {
2257
- return getMigrations(this._scopeContext);
2691
+ async getUsers(options) {
2692
+ return getProjectUsers(this.projectContext, options);
2258
2693
  }
2259
- async applyMigrations(migrations) {
2260
- await applyMigrations(this._scopeContext, migrations);
2261
- await this.refreshDraftRevisionId();
2262
- this.notifyScopesOnCurrentBranch();
2694
+ async addUser(userId, roleId) {
2695
+ return addProjectUser(this.projectContext, userId, roleId);
2263
2696
  }
2264
- async createTable(tableId, schema) {
2265
- return createTable(this._scopeContext, tableId, schema);
2697
+ async removeUser(userId) {
2698
+ return removeProjectUser(this.projectContext, userId);
2266
2699
  }
2267
- async updateTable(tableId, patches) {
2268
- return updateTable(this._scopeContext, tableId, patches);
2700
+ async getEndpoints() {
2701
+ return (await this.branch()).draft().getEndpoints();
2269
2702
  }
2270
- async deleteTable(tableId) {
2271
- return deleteTable(this._scopeContext, tableId);
2703
+ async createEndpoint(body) {
2704
+ return (await this.branch()).draft().createEndpoint(body);
2272
2705
  }
2273
- async renameTable(tableId, nextTableId) {
2274
- return renameTable(this._scopeContext, tableId, nextTableId);
2706
+ async deleteEndpoint(endpointId) {
2707
+ return deleteEndpoint(this._client, endpointId);
2275
2708
  }
2276
- async createRow(tableId, rowId, data) {
2277
- return createRow(this._scopeContext, tableId, rowId, data);
2709
+ async getEndpointRelatives(endpointId) {
2710
+ return getEndpointRelatives(this._client, endpointId);
2278
2711
  }
2279
- async createRows(tableId, rows, options) {
2280
- return createRows(this._scopeContext, tableId, rows, options);
2712
+ };
2713
+
2714
+ //#endregion
2715
+ //#region src/org-scope.ts
2716
+ var OrgScope = class {
2717
+ constructor(_client, _organizationId) {
2718
+ this._client = _client;
2719
+ this._organizationId = _organizationId;
2281
2720
  }
2282
- async updateRow(tableId, rowId, data) {
2283
- return updateRow(this._scopeContext, tableId, rowId, data);
2721
+ get organizationId() {
2722
+ return this._organizationId;
2284
2723
  }
2285
- async updateRows(tableId, rows, options) {
2286
- return updateRows(this._scopeContext, tableId, rows, options);
2724
+ get client() {
2725
+ return this._client;
2287
2726
  }
2288
- async patchRow(tableId, rowId, patches) {
2289
- return patchRow(this._scopeContext, tableId, rowId, patches);
2727
+ project(projectName) {
2728
+ return new ProjectScope(this._client, this._organizationId, projectName);
2290
2729
  }
2291
- async deleteRow(tableId, rowId) {
2292
- return deleteRow(this._scopeContext, tableId, rowId);
2730
+ get orgContext() {
2731
+ return {
2732
+ client: this._client,
2733
+ organizationId: this._organizationId
2734
+ };
2293
2735
  }
2294
- async deleteRows(tableId, rowIds) {
2295
- return deleteRows(this._scopeContext, tableId, rowIds);
2736
+ async getProjects(options) {
2737
+ return getProjects(this.orgContext, options);
2296
2738
  }
2297
- async renameRow(tableId, rowId, nextRowId) {
2298
- return renameRow(this._scopeContext, tableId, rowId, nextRowId);
2739
+ async createProject(body) {
2740
+ return createProject(this.orgContext, body);
2299
2741
  }
2300
- async commit(comment) {
2301
- const data = await commit(this._scopeContext, comment);
2302
- await this.refreshDraftRevisionId();
2303
- this.notifyScopesOnCurrentBranch();
2304
- return data;
2742
+ async getUsers(options) {
2743
+ return getOrgUsers(this.orgContext, options);
2305
2744
  }
2306
- async revertChanges() {
2307
- await revertChanges(this._scopeContext);
2308
- await this.refreshDraftRevisionId();
2309
- this.notifyScopesOnCurrentBranch();
2745
+ async addUser(userId, roleId) {
2746
+ return addOrgUser(this.orgContext, userId, roleId);
2310
2747
  }
2311
- async refreshDraftRevisionId() {
2312
- this._revisionId = await fetchDraftRevisionId(this._client, {
2313
- organizationId: this._organizationId,
2314
- projectName: this._projectName,
2315
- branchName: this._branchName
2748
+ async removeUser(userId) {
2749
+ return removeOrgUser(this.orgContext, userId);
2750
+ }
2751
+ };
2752
+
2753
+ //#endregion
2754
+ //#region src/revisium-client.ts
2755
+ var RevisiumClient = class {
2756
+ _client;
2757
+ _baseUrl;
2758
+ _isAuthenticated = false;
2759
+ constructor(options) {
2760
+ const url = options.baseUrl;
2761
+ this._baseUrl = url.endsWith("/") ? url.slice(0, -1) : url;
2762
+ this._client = createClient(createConfig({ baseUrl: this._baseUrl }));
2763
+ }
2764
+ get baseUrl() {
2765
+ return this._baseUrl;
2766
+ }
2767
+ get client() {
2768
+ return this._client;
2769
+ }
2770
+ isAuthenticated() {
2771
+ return this._isAuthenticated;
2772
+ }
2773
+ async login(username, password) {
2774
+ const result = await login({
2775
+ client: this._client,
2776
+ body: {
2777
+ emailOrUsername: username,
2778
+ password
2779
+ }
2316
2780
  });
2781
+ const data = unwrap(result);
2782
+ this._client.setConfig({ auth: data.accessToken });
2783
+ this._isAuthenticated = true;
2317
2784
  }
2318
- notifyScopesOnCurrentBranch() {
2319
- if (this._organizationId && this._projectName && this._branchName) {
2320
- const branchKey = `${this._organizationId}/${this._projectName}/${this._branchName}`;
2321
- this.notifyBranchChanged(branchKey);
2322
- }
2785
+ loginWithToken(token) {
2786
+ this._client.setConfig({ auth: token });
2787
+ this._isAuthenticated = true;
2788
+ }
2789
+ async me() {
2790
+ return me(this._client);
2791
+ }
2792
+ org(organizationId) {
2793
+ return new OrgScope(this._client, organizationId);
2794
+ }
2795
+ async branch(options) {
2796
+ return BranchScope.create(this._client, {
2797
+ client: this._client,
2798
+ organizationId: options.org,
2799
+ projectName: options.project,
2800
+ branchName: options.branch ?? "master"
2801
+ });
2802
+ }
2803
+ async revision(options) {
2804
+ const bs = await this.branch(options);
2805
+ const rev = options.revision ?? "draft";
2806
+ if (rev === "draft") return bs.draft();
2807
+ if (rev === "head") return bs.head();
2808
+ return bs.revision(rev);
2323
2809
  }
2324
2810
  };
2325
2811
 
2326
2812
  //#endregion
2813
+ exports.BranchScope = BranchScope;
2814
+ exports.OrgScope = OrgScope;
2815
+ exports.ProjectScope = ProjectScope;
2816
+ exports.RevisionScope = RevisionScope;
2327
2817
  exports.RevisiumClient = RevisiumClient;
2328
- exports.RevisiumScope = RevisiumScope;
2329
2818
  exports.client = client;
2330
2819
  Object.defineProperty(exports, 'sdk', {
2331
2820
  enumerable: true,