@liveblocks/core 3.20.0-exp6 → 3.20.0-perm1
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 +635 -1361
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -200
- package/dist/index.d.ts +88 -200
- package/dist/index.js +537 -1263
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.20.0-
|
|
9
|
+
var PKG_VERSION = "3.20.0-perm1";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -701,20 +701,6 @@ var SortedList = class _SortedList {
|
|
|
701
701
|
get length() {
|
|
702
702
|
return this.#data.length;
|
|
703
703
|
}
|
|
704
|
-
/**
|
|
705
|
-
* Whether the given value is present, by identity. O(log n) plus the length
|
|
706
|
-
* of any run of items that share its sort key (normally 1). Bisects on the
|
|
707
|
-
* value's own key, so it only finds values sitting at their sorted position,
|
|
708
|
-
* which is true for any item currently in the list.
|
|
709
|
-
*/
|
|
710
|
-
includes(value) {
|
|
711
|
-
for (let i = bisectRight(this.#data, value, this.#lt) - 1; i >= 0 && !this.#lt(this.#data[i], value); i--) {
|
|
712
|
-
if (this.#data[i] === value) {
|
|
713
|
-
return true;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
return false;
|
|
717
|
-
}
|
|
718
704
|
*filter(predicate) {
|
|
719
705
|
for (const item of this.#data) {
|
|
720
706
|
if (predicate(item)) {
|
|
@@ -1570,7 +1556,6 @@ function isUrl(string) {
|
|
|
1570
1556
|
function createApiClient({
|
|
1571
1557
|
baseUrl,
|
|
1572
1558
|
authManager,
|
|
1573
|
-
currentUserId,
|
|
1574
1559
|
fetchPolyfill
|
|
1575
1560
|
}) {
|
|
1576
1561
|
const httpClient = new HttpClient(baseUrl, fetchPolyfill);
|
|
@@ -1578,8 +1563,9 @@ function createApiClient({
|
|
|
1578
1563
|
const result = await httpClient.get(
|
|
1579
1564
|
url`/v2/c/rooms/${options.roomId}/threads/delta`,
|
|
1580
1565
|
await authManager.getAuthValue({
|
|
1581
|
-
|
|
1582
|
-
|
|
1566
|
+
roomId: options.roomId,
|
|
1567
|
+
resource: "comments",
|
|
1568
|
+
access: "read"
|
|
1583
1569
|
}),
|
|
1584
1570
|
{
|
|
1585
1571
|
since: options.since.toISOString()
|
|
@@ -1617,8 +1603,9 @@ function createApiClient({
|
|
|
1617
1603
|
const result = await httpClient.get(
|
|
1618
1604
|
url`/v2/c/rooms/${options.roomId}/threads`,
|
|
1619
1605
|
await authManager.getAuthValue({
|
|
1620
|
-
|
|
1621
|
-
|
|
1606
|
+
roomId: options.roomId,
|
|
1607
|
+
resource: "comments",
|
|
1608
|
+
access: "read"
|
|
1622
1609
|
}),
|
|
1623
1610
|
{
|
|
1624
1611
|
cursor: options.cursor,
|
|
@@ -1662,8 +1649,9 @@ function createApiClient({
|
|
|
1662
1649
|
const result = await httpClient.get(
|
|
1663
1650
|
url`/v2/c/rooms/${options.roomId}/threads/comments/search`,
|
|
1664
1651
|
await authManager.getAuthValue({
|
|
1665
|
-
|
|
1666
|
-
|
|
1652
|
+
roomId: options.roomId,
|
|
1653
|
+
resource: "comments",
|
|
1654
|
+
access: "read"
|
|
1667
1655
|
}),
|
|
1668
1656
|
{
|
|
1669
1657
|
text: options.query.text,
|
|
@@ -1684,8 +1672,9 @@ function createApiClient({
|
|
|
1684
1672
|
const thread = await httpClient.post(
|
|
1685
1673
|
url`/v2/c/rooms/${options.roomId}/threads`,
|
|
1686
1674
|
await authManager.getAuthValue({
|
|
1687
|
-
|
|
1688
|
-
|
|
1675
|
+
roomId: options.roomId,
|
|
1676
|
+
resource: "comments",
|
|
1677
|
+
access: "write"
|
|
1689
1678
|
}),
|
|
1690
1679
|
{
|
|
1691
1680
|
id: threadId,
|
|
@@ -1704,8 +1693,9 @@ function createApiClient({
|
|
|
1704
1693
|
await httpClient.delete(
|
|
1705
1694
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}`,
|
|
1706
1695
|
await authManager.getAuthValue({
|
|
1707
|
-
|
|
1708
|
-
|
|
1696
|
+
roomId: options.roomId,
|
|
1697
|
+
resource: "comments",
|
|
1698
|
+
access: "write"
|
|
1709
1699
|
})
|
|
1710
1700
|
);
|
|
1711
1701
|
}
|
|
@@ -1713,8 +1703,9 @@ function createApiClient({
|
|
|
1713
1703
|
const response = await httpClient.rawGet(
|
|
1714
1704
|
url`/v2/c/rooms/${options.roomId}/thread-with-notification/${options.threadId}`,
|
|
1715
1705
|
await authManager.getAuthValue({
|
|
1716
|
-
|
|
1717
|
-
|
|
1706
|
+
roomId: options.roomId,
|
|
1707
|
+
resource: "comments",
|
|
1708
|
+
access: "read"
|
|
1718
1709
|
})
|
|
1719
1710
|
);
|
|
1720
1711
|
if (response.ok) {
|
|
@@ -1740,8 +1731,9 @@ function createApiClient({
|
|
|
1740
1731
|
return await httpClient.post(
|
|
1741
1732
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/metadata`,
|
|
1742
1733
|
await authManager.getAuthValue({
|
|
1743
|
-
|
|
1744
|
-
|
|
1734
|
+
roomId: options.roomId,
|
|
1735
|
+
resource: "comments",
|
|
1736
|
+
access: "write"
|
|
1745
1737
|
}),
|
|
1746
1738
|
options.metadata
|
|
1747
1739
|
);
|
|
@@ -1750,8 +1742,9 @@ function createApiClient({
|
|
|
1750
1742
|
return await httpClient.post(
|
|
1751
1743
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments/${options.commentId}/metadata`,
|
|
1752
1744
|
await authManager.getAuthValue({
|
|
1753
|
-
|
|
1754
|
-
|
|
1745
|
+
roomId: options.roomId,
|
|
1746
|
+
resource: "comments",
|
|
1747
|
+
access: "write"
|
|
1755
1748
|
}),
|
|
1756
1749
|
options.metadata
|
|
1757
1750
|
);
|
|
@@ -1761,8 +1754,9 @@ function createApiClient({
|
|
|
1761
1754
|
const comment = await httpClient.post(
|
|
1762
1755
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments`,
|
|
1763
1756
|
await authManager.getAuthValue({
|
|
1764
|
-
|
|
1765
|
-
|
|
1757
|
+
roomId: options.roomId,
|
|
1758
|
+
resource: "comments",
|
|
1759
|
+
access: "write"
|
|
1766
1760
|
}),
|
|
1767
1761
|
{
|
|
1768
1762
|
id: commentId,
|
|
@@ -1777,8 +1771,9 @@ function createApiClient({
|
|
|
1777
1771
|
const comment = await httpClient.post(
|
|
1778
1772
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments/${options.commentId}`,
|
|
1779
1773
|
await authManager.getAuthValue({
|
|
1780
|
-
|
|
1781
|
-
|
|
1774
|
+
roomId: options.roomId,
|
|
1775
|
+
resource: "comments",
|
|
1776
|
+
access: "write"
|
|
1782
1777
|
}),
|
|
1783
1778
|
{
|
|
1784
1779
|
body: options.body,
|
|
@@ -1792,8 +1787,9 @@ function createApiClient({
|
|
|
1792
1787
|
await httpClient.delete(
|
|
1793
1788
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments/${options.commentId}`,
|
|
1794
1789
|
await authManager.getAuthValue({
|
|
1795
|
-
|
|
1796
|
-
|
|
1790
|
+
roomId: options.roomId,
|
|
1791
|
+
resource: "comments",
|
|
1792
|
+
access: "write"
|
|
1797
1793
|
})
|
|
1798
1794
|
);
|
|
1799
1795
|
}
|
|
@@ -1801,8 +1797,9 @@ function createApiClient({
|
|
|
1801
1797
|
const reaction = await httpClient.post(
|
|
1802
1798
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments/${options.commentId}/reactions`,
|
|
1803
1799
|
await authManager.getAuthValue({
|
|
1804
|
-
|
|
1805
|
-
|
|
1800
|
+
roomId: options.roomId,
|
|
1801
|
+
resource: "comments",
|
|
1802
|
+
access: "write"
|
|
1806
1803
|
}),
|
|
1807
1804
|
{ emoji: options.emoji }
|
|
1808
1805
|
);
|
|
@@ -1812,8 +1809,9 @@ function createApiClient({
|
|
|
1812
1809
|
await httpClient.delete(
|
|
1813
1810
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments/${options.commentId}/reactions/${options.emoji}`,
|
|
1814
1811
|
await authManager.getAuthValue({
|
|
1815
|
-
|
|
1816
|
-
|
|
1812
|
+
roomId: options.roomId,
|
|
1813
|
+
resource: "comments",
|
|
1814
|
+
access: "write"
|
|
1817
1815
|
})
|
|
1818
1816
|
);
|
|
1819
1817
|
}
|
|
@@ -1821,8 +1819,9 @@ function createApiClient({
|
|
|
1821
1819
|
await httpClient.post(
|
|
1822
1820
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/mark-as-resolved`,
|
|
1823
1821
|
await authManager.getAuthValue({
|
|
1824
|
-
|
|
1825
|
-
|
|
1822
|
+
roomId: options.roomId,
|
|
1823
|
+
resource: "comments",
|
|
1824
|
+
access: "write"
|
|
1826
1825
|
})
|
|
1827
1826
|
);
|
|
1828
1827
|
}
|
|
@@ -1830,8 +1829,9 @@ function createApiClient({
|
|
|
1830
1829
|
await httpClient.post(
|
|
1831
1830
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/mark-as-unresolved`,
|
|
1832
1831
|
await authManager.getAuthValue({
|
|
1833
|
-
|
|
1834
|
-
|
|
1832
|
+
roomId: options.roomId,
|
|
1833
|
+
resource: "comments",
|
|
1834
|
+
access: "write"
|
|
1835
1835
|
})
|
|
1836
1836
|
);
|
|
1837
1837
|
}
|
|
@@ -1839,8 +1839,9 @@ function createApiClient({
|
|
|
1839
1839
|
const subscription = await httpClient.post(
|
|
1840
1840
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/subscribe`,
|
|
1841
1841
|
await authManager.getAuthValue({
|
|
1842
|
-
|
|
1843
|
-
|
|
1842
|
+
roomId: options.roomId,
|
|
1843
|
+
resource: "comments",
|
|
1844
|
+
access: "read"
|
|
1844
1845
|
})
|
|
1845
1846
|
);
|
|
1846
1847
|
return convertToSubscriptionData(subscription);
|
|
@@ -1849,8 +1850,9 @@ function createApiClient({
|
|
|
1849
1850
|
await httpClient.post(
|
|
1850
1851
|
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/unsubscribe`,
|
|
1851
1852
|
await authManager.getAuthValue({
|
|
1852
|
-
|
|
1853
|
-
|
|
1853
|
+
roomId: options.roomId,
|
|
1854
|
+
resource: "comments",
|
|
1855
|
+
access: "read"
|
|
1854
1856
|
})
|
|
1855
1857
|
);
|
|
1856
1858
|
}
|
|
@@ -1906,8 +1908,9 @@ function createApiClient({
|
|
|
1906
1908
|
async () => httpClient.putBlob(
|
|
1907
1909
|
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/upload/${encodeURIComponent(attachment.name)}`,
|
|
1908
1910
|
await authManager.getAuthValue({
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
+
roomId,
|
|
1912
|
+
resource: "comments",
|
|
1913
|
+
access: "write"
|
|
1911
1914
|
}),
|
|
1912
1915
|
attachment.file,
|
|
1913
1916
|
{ fileSize: attachment.size },
|
|
@@ -1924,8 +1927,9 @@ function createApiClient({
|
|
|
1924
1927
|
async () => httpClient.post(
|
|
1925
1928
|
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${encodeURIComponent(attachment.name)}`,
|
|
1926
1929
|
await authManager.getAuthValue({
|
|
1927
|
-
|
|
1928
|
-
|
|
1930
|
+
roomId,
|
|
1931
|
+
resource: "comments",
|
|
1932
|
+
access: "write"
|
|
1929
1933
|
}),
|
|
1930
1934
|
void 0,
|
|
1931
1935
|
{ signal: abortSignal },
|
|
@@ -1950,8 +1954,9 @@ function createApiClient({
|
|
|
1950
1954
|
async () => httpClient.putBlob(
|
|
1951
1955
|
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${createMultiPartUpload.uploadId}/${String(partNumber)}`,
|
|
1952
1956
|
await authManager.getAuthValue({
|
|
1953
|
-
|
|
1954
|
-
|
|
1957
|
+
roomId,
|
|
1958
|
+
resource: "comments",
|
|
1959
|
+
access: "write"
|
|
1955
1960
|
}),
|
|
1956
1961
|
part,
|
|
1957
1962
|
void 0,
|
|
@@ -1974,8 +1979,9 @@ function createApiClient({
|
|
|
1974
1979
|
return httpClient.post(
|
|
1975
1980
|
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}/complete`,
|
|
1976
1981
|
await authManager.getAuthValue({
|
|
1977
|
-
|
|
1978
|
-
|
|
1982
|
+
roomId,
|
|
1983
|
+
resource: "comments",
|
|
1984
|
+
access: "write"
|
|
1979
1985
|
}),
|
|
1980
1986
|
{ parts: sortedUploadedParts },
|
|
1981
1987
|
{ signal: abortSignal }
|
|
@@ -1986,8 +1992,9 @@ function createApiClient({
|
|
|
1986
1992
|
await httpClient.rawDelete(
|
|
1987
1993
|
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}`,
|
|
1988
1994
|
await authManager.getAuthValue({
|
|
1989
|
-
|
|
1990
|
-
|
|
1995
|
+
roomId,
|
|
1996
|
+
resource: "comments",
|
|
1997
|
+
access: "write"
|
|
1991
1998
|
})
|
|
1992
1999
|
);
|
|
1993
2000
|
} catch {
|
|
@@ -2004,8 +2011,9 @@ function createApiClient({
|
|
|
2004
2011
|
const { urls } = await httpClient.post(
|
|
2005
2012
|
url`/v2/c/rooms/${roomId}/attachments/presigned-urls`,
|
|
2006
2013
|
await authManager.getAuthValue({
|
|
2007
|
-
|
|
2008
|
-
|
|
2014
|
+
roomId,
|
|
2015
|
+
resource: "comments",
|
|
2016
|
+
access: "read"
|
|
2009
2017
|
}),
|
|
2010
2018
|
{ attachmentIds }
|
|
2011
2019
|
);
|
|
@@ -2024,109 +2032,13 @@ function createApiClient({
|
|
|
2024
2032
|
const batch2 = getOrCreateAttachmentUrlsStore(options.roomId).batch;
|
|
2025
2033
|
return batch2.get(options.attachmentId);
|
|
2026
2034
|
}
|
|
2027
|
-
async function uploadChatAttachment(options) {
|
|
2028
|
-
const { chatId, attachment, signal } = options;
|
|
2029
|
-
const userId = currentUserId.get();
|
|
2030
|
-
if (userId === void 0) {
|
|
2031
|
-
throw new Error("Attachment upload requires an authenticated user.");
|
|
2032
|
-
}
|
|
2033
|
-
const ATTACHMENT_PART_SIZE = 5 * 1024 * 1024;
|
|
2034
|
-
if (options.attachment.file.size <= ATTACHMENT_PART_SIZE) {
|
|
2035
|
-
await httpClient.putBlob(
|
|
2036
|
-
url`/v2/c/chats/${chatId}/attachments/${attachment.id}/upload/${encodeURIComponent(attachment.file.name)}`,
|
|
2037
|
-
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
2038
|
-
attachment.file,
|
|
2039
|
-
{ fileSize: attachment.file.size },
|
|
2040
|
-
{ signal }
|
|
2041
|
-
);
|
|
2042
|
-
} else {
|
|
2043
|
-
const multipartUpload = await httpClient.post(
|
|
2044
|
-
url`/v2/c/chats/${chatId}/attachments/${attachment.id}/multipart/${encodeURIComponent(attachment.file.name)}`,
|
|
2045
|
-
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
2046
|
-
void 0,
|
|
2047
|
-
{ signal },
|
|
2048
|
-
{ fileSize: attachment.file.size }
|
|
2049
|
-
);
|
|
2050
|
-
try {
|
|
2051
|
-
const uploadedParts = [];
|
|
2052
|
-
const parts = [];
|
|
2053
|
-
let start = 0;
|
|
2054
|
-
while (start < attachment.file.size) {
|
|
2055
|
-
const end = Math.min(
|
|
2056
|
-
start + ATTACHMENT_PART_SIZE,
|
|
2057
|
-
attachment.file.size
|
|
2058
|
-
);
|
|
2059
|
-
parts.push({
|
|
2060
|
-
number: parts.length + 1,
|
|
2061
|
-
part: attachment.file.slice(start, end)
|
|
2062
|
-
});
|
|
2063
|
-
start = end;
|
|
2064
|
-
}
|
|
2065
|
-
uploadedParts.push(
|
|
2066
|
-
...await Promise.all(
|
|
2067
|
-
parts.map(async ({ number, part }) => {
|
|
2068
|
-
return await httpClient.putBlob(
|
|
2069
|
-
url`/v2/c/chats/${chatId}/attachments/${attachment.id}/multipart/${multipartUpload.uploadId}/${String(number)}`,
|
|
2070
|
-
await authManager.getAuthValue({
|
|
2071
|
-
requestedScope: "comments:read"
|
|
2072
|
-
}),
|
|
2073
|
-
part,
|
|
2074
|
-
void 0,
|
|
2075
|
-
{ signal }
|
|
2076
|
-
);
|
|
2077
|
-
})
|
|
2078
|
-
)
|
|
2079
|
-
);
|
|
2080
|
-
await httpClient.post(
|
|
2081
|
-
url`/v2/c/chats/${chatId}/attachments/${attachment.id}/multipart/${multipartUpload.uploadId}/complete`,
|
|
2082
|
-
await authManager.getAuthValue({ requestedScope: "comments:read" }),
|
|
2083
|
-
{ parts: uploadedParts.sort((a, b) => a.number - b.number) },
|
|
2084
|
-
{ signal }
|
|
2085
|
-
);
|
|
2086
|
-
} catch (err) {
|
|
2087
|
-
try {
|
|
2088
|
-
await httpClient.delete(
|
|
2089
|
-
url`/v2/c/chats/${chatId}/attachments/${attachment.id}/multipart/${multipartUpload.uploadId}`,
|
|
2090
|
-
await authManager.getAuthValue({ requestedScope: "comments:read" })
|
|
2091
|
-
);
|
|
2092
|
-
} catch {
|
|
2093
|
-
}
|
|
2094
|
-
throw err;
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
const attachmentUrlsBatchStoresByChat = new DefaultMap((chatId) => {
|
|
2099
|
-
const batch2 = new Batch(
|
|
2100
|
-
async (batchedAttachmentIds) => {
|
|
2101
|
-
const attachmentIds = batchedAttachmentIds.flat();
|
|
2102
|
-
const { urls } = await httpClient.post(
|
|
2103
|
-
url`/v2/c/chats/${chatId}/attachments/presigned-urls`,
|
|
2104
|
-
await authManager.getAuthValue({
|
|
2105
|
-
requestedScope: "comments:read"
|
|
2106
|
-
}),
|
|
2107
|
-
{ attachmentIds }
|
|
2108
|
-
);
|
|
2109
|
-
return urls.map(
|
|
2110
|
-
(url2) => url2 ?? new Error("There was an error while getting this attachment's URL")
|
|
2111
|
-
);
|
|
2112
|
-
},
|
|
2113
|
-
{ delay: 50 }
|
|
2114
|
-
);
|
|
2115
|
-
return createBatchStore(batch2);
|
|
2116
|
-
});
|
|
2117
|
-
function getOrCreateChatAttachmentUrlsStore(chatId) {
|
|
2118
|
-
return attachmentUrlsBatchStoresByChat.getOrCreate(chatId);
|
|
2119
|
-
}
|
|
2120
|
-
function getChatAttachmentUrl(options) {
|
|
2121
|
-
const batch2 = getOrCreateChatAttachmentUrlsStore(options.chatId).batch;
|
|
2122
|
-
return batch2.get(options.attachmentId);
|
|
2123
|
-
}
|
|
2124
2035
|
async function getSubscriptionSettings(options) {
|
|
2125
2036
|
return httpClient.get(
|
|
2126
2037
|
url`/v2/c/rooms/${options.roomId}/subscription-settings`,
|
|
2127
2038
|
await authManager.getAuthValue({
|
|
2128
|
-
|
|
2129
|
-
|
|
2039
|
+
roomId: options.roomId,
|
|
2040
|
+
resource: "comments",
|
|
2041
|
+
access: "read"
|
|
2130
2042
|
}),
|
|
2131
2043
|
void 0,
|
|
2132
2044
|
{
|
|
@@ -2138,8 +2050,9 @@ function createApiClient({
|
|
|
2138
2050
|
return httpClient.post(
|
|
2139
2051
|
url`/v2/c/rooms/${options.roomId}/subscription-settings`,
|
|
2140
2052
|
await authManager.getAuthValue({
|
|
2141
|
-
|
|
2142
|
-
|
|
2053
|
+
roomId: options.roomId,
|
|
2054
|
+
resource: "comments",
|
|
2055
|
+
access: "read"
|
|
2143
2056
|
}),
|
|
2144
2057
|
options.settings
|
|
2145
2058
|
);
|
|
@@ -2151,8 +2064,9 @@ function createApiClient({
|
|
|
2151
2064
|
await httpClient.post(
|
|
2152
2065
|
url`/v2/c/rooms/${roomId}/inbox-notifications/read`,
|
|
2153
2066
|
await authManager.getAuthValue({
|
|
2154
|
-
|
|
2155
|
-
|
|
2067
|
+
roomId,
|
|
2068
|
+
resource: "comments",
|
|
2069
|
+
access: "read"
|
|
2156
2070
|
}),
|
|
2157
2071
|
{ inboxNotificationIds }
|
|
2158
2072
|
);
|
|
@@ -2172,8 +2086,9 @@ function createApiClient({
|
|
|
2172
2086
|
await httpClient.rawPost(
|
|
2173
2087
|
url`/v2/c/rooms/${options.roomId}/text-mentions`,
|
|
2174
2088
|
await authManager.getAuthValue({
|
|
2175
|
-
|
|
2176
|
-
|
|
2089
|
+
roomId: options.roomId,
|
|
2090
|
+
resource: "storage",
|
|
2091
|
+
access: "write"
|
|
2177
2092
|
}),
|
|
2178
2093
|
{
|
|
2179
2094
|
userId: options.mention.kind === "user" ? options.mention.id : void 0,
|
|
@@ -2187,8 +2102,9 @@ function createApiClient({
|
|
|
2187
2102
|
await httpClient.rawDelete(
|
|
2188
2103
|
url`/v2/c/rooms/${options.roomId}/text-mentions/${options.mentionId}`,
|
|
2189
2104
|
await authManager.getAuthValue({
|
|
2190
|
-
|
|
2191
|
-
|
|
2105
|
+
roomId: options.roomId,
|
|
2106
|
+
resource: "storage",
|
|
2107
|
+
access: "write"
|
|
2192
2108
|
})
|
|
2193
2109
|
);
|
|
2194
2110
|
}
|
|
@@ -2196,8 +2112,9 @@ function createApiClient({
|
|
|
2196
2112
|
return httpClient.rawGet(
|
|
2197
2113
|
url`/v2/c/rooms/${options.roomId}/y-version/${options.versionId}`,
|
|
2198
2114
|
await authManager.getAuthValue({
|
|
2199
|
-
|
|
2200
|
-
|
|
2115
|
+
roomId: options.roomId,
|
|
2116
|
+
resource: "storage",
|
|
2117
|
+
access: "read"
|
|
2201
2118
|
})
|
|
2202
2119
|
);
|
|
2203
2120
|
}
|
|
@@ -2205,8 +2122,9 @@ function createApiClient({
|
|
|
2205
2122
|
await httpClient.rawPost(
|
|
2206
2123
|
url`/v2/c/rooms/${options.roomId}/version`,
|
|
2207
2124
|
await authManager.getAuthValue({
|
|
2208
|
-
|
|
2209
|
-
|
|
2125
|
+
roomId: options.roomId,
|
|
2126
|
+
resource: "storage",
|
|
2127
|
+
access: "write"
|
|
2210
2128
|
})
|
|
2211
2129
|
);
|
|
2212
2130
|
}
|
|
@@ -2214,8 +2132,9 @@ function createApiClient({
|
|
|
2214
2132
|
await httpClient.rawPost(
|
|
2215
2133
|
url`/v2/c/rooms/${options.roomId}/text-metadata`,
|
|
2216
2134
|
await authManager.getAuthValue({
|
|
2217
|
-
|
|
2218
|
-
|
|
2135
|
+
roomId: options.roomId,
|
|
2136
|
+
resource: "storage",
|
|
2137
|
+
access: "read"
|
|
2219
2138
|
}),
|
|
2220
2139
|
{
|
|
2221
2140
|
type: options.type,
|
|
@@ -2227,8 +2146,9 @@ function createApiClient({
|
|
|
2227
2146
|
const result = await httpClient.post(
|
|
2228
2147
|
url`/v2/c/rooms/${options.roomId}/ai/contextual-prompt`,
|
|
2229
2148
|
await authManager.getAuthValue({
|
|
2230
|
-
|
|
2231
|
-
|
|
2149
|
+
roomId: options.roomId,
|
|
2150
|
+
resource: "storage",
|
|
2151
|
+
access: "read"
|
|
2232
2152
|
}),
|
|
2233
2153
|
{
|
|
2234
2154
|
prompt: options.prompt,
|
|
@@ -2250,8 +2170,9 @@ function createApiClient({
|
|
|
2250
2170
|
const result = await httpClient.get(
|
|
2251
2171
|
url`/v2/c/rooms/${options.roomId}/versions`,
|
|
2252
2172
|
await authManager.getAuthValue({
|
|
2253
|
-
|
|
2254
|
-
|
|
2173
|
+
roomId: options.roomId,
|
|
2174
|
+
resource: "storage",
|
|
2175
|
+
access: "read"
|
|
2255
2176
|
})
|
|
2256
2177
|
);
|
|
2257
2178
|
return {
|
|
@@ -2268,8 +2189,9 @@ function createApiClient({
|
|
|
2268
2189
|
const result = await httpClient.get(
|
|
2269
2190
|
url`/v2/c/rooms/${options.roomId}/versions/delta`,
|
|
2270
2191
|
await authManager.getAuthValue({
|
|
2271
|
-
|
|
2272
|
-
|
|
2192
|
+
roomId: options.roomId,
|
|
2193
|
+
resource: "storage",
|
|
2194
|
+
access: "read"
|
|
2273
2195
|
}),
|
|
2274
2196
|
{ since: options.since.toISOString() },
|
|
2275
2197
|
{ signal: options.signal }
|
|
@@ -2288,8 +2210,9 @@ function createApiClient({
|
|
|
2288
2210
|
const result = await httpClient.rawGet(
|
|
2289
2211
|
url`/v2/c/rooms/${options.roomId}/storage`,
|
|
2290
2212
|
await authManager.getAuthValue({
|
|
2291
|
-
|
|
2292
|
-
|
|
2213
|
+
roomId: options.roomId,
|
|
2214
|
+
resource: "storage",
|
|
2215
|
+
access: "read"
|
|
2293
2216
|
})
|
|
2294
2217
|
);
|
|
2295
2218
|
return await result.json();
|
|
@@ -2302,7 +2225,7 @@ function createApiClient({
|
|
|
2302
2225
|
}
|
|
2303
2226
|
const json = await httpClient.get(
|
|
2304
2227
|
url`/v2/c/inbox-notifications`,
|
|
2305
|
-
await authManager.getAuthValue({
|
|
2228
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2306
2229
|
{
|
|
2307
2230
|
cursor: options?.cursor,
|
|
2308
2231
|
limit: PAGE_SIZE,
|
|
@@ -2328,7 +2251,7 @@ function createApiClient({
|
|
|
2328
2251
|
}
|
|
2329
2252
|
const json = await httpClient.get(
|
|
2330
2253
|
url`/v2/c/inbox-notifications/delta`,
|
|
2331
|
-
await authManager.getAuthValue({
|
|
2254
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2332
2255
|
{ since: options.since.toISOString(), query },
|
|
2333
2256
|
{ signal: options.signal }
|
|
2334
2257
|
);
|
|
@@ -2357,7 +2280,7 @@ function createApiClient({
|
|
|
2357
2280
|
}
|
|
2358
2281
|
const { count } = await httpClient.get(
|
|
2359
2282
|
url`/v2/c/inbox-notifications/count`,
|
|
2360
|
-
await authManager.getAuthValue({
|
|
2283
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2361
2284
|
{ query },
|
|
2362
2285
|
{ signal: options?.signal }
|
|
2363
2286
|
);
|
|
@@ -2366,7 +2289,7 @@ function createApiClient({
|
|
|
2366
2289
|
async function markAllInboxNotificationsAsRead() {
|
|
2367
2290
|
await httpClient.post(
|
|
2368
2291
|
url`/v2/c/inbox-notifications/read`,
|
|
2369
|
-
await authManager.getAuthValue({
|
|
2292
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2370
2293
|
{
|
|
2371
2294
|
inboxNotificationIds: "all"
|
|
2372
2295
|
}
|
|
@@ -2375,7 +2298,7 @@ function createApiClient({
|
|
|
2375
2298
|
async function markInboxNotificationsAsRead(inboxNotificationIds) {
|
|
2376
2299
|
await httpClient.post(
|
|
2377
2300
|
url`/v2/c/inbox-notifications/read`,
|
|
2378
|
-
await authManager.getAuthValue({
|
|
2301
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2379
2302
|
{
|
|
2380
2303
|
inboxNotificationIds
|
|
2381
2304
|
}
|
|
@@ -2395,19 +2318,19 @@ function createApiClient({
|
|
|
2395
2318
|
async function deleteAllInboxNotifications() {
|
|
2396
2319
|
await httpClient.delete(
|
|
2397
2320
|
url`/v2/c/inbox-notifications`,
|
|
2398
|
-
await authManager.getAuthValue({
|
|
2321
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" })
|
|
2399
2322
|
);
|
|
2400
2323
|
}
|
|
2401
2324
|
async function deleteInboxNotification(inboxNotificationId) {
|
|
2402
2325
|
await httpClient.delete(
|
|
2403
2326
|
url`/v2/c/inbox-notifications/${inboxNotificationId}`,
|
|
2404
|
-
await authManager.getAuthValue({
|
|
2327
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" })
|
|
2405
2328
|
);
|
|
2406
2329
|
}
|
|
2407
2330
|
async function getNotificationSettings(options) {
|
|
2408
2331
|
return httpClient.get(
|
|
2409
2332
|
url`/v2/c/notification-settings`,
|
|
2410
|
-
await authManager.getAuthValue({
|
|
2333
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2411
2334
|
void 0,
|
|
2412
2335
|
{ signal: options?.signal }
|
|
2413
2336
|
);
|
|
@@ -2415,7 +2338,7 @@ function createApiClient({
|
|
|
2415
2338
|
async function updateNotificationSettings(settings) {
|
|
2416
2339
|
return httpClient.post(
|
|
2417
2340
|
url`/v2/c/notification-settings`,
|
|
2418
|
-
await authManager.getAuthValue({
|
|
2341
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2419
2342
|
settings
|
|
2420
2343
|
);
|
|
2421
2344
|
}
|
|
@@ -2427,7 +2350,7 @@ function createApiClient({
|
|
|
2427
2350
|
const PAGE_SIZE = 50;
|
|
2428
2351
|
const json = await httpClient.get(
|
|
2429
2352
|
url`/v2/c/threads`,
|
|
2430
|
-
await authManager.getAuthValue({
|
|
2353
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2431
2354
|
{
|
|
2432
2355
|
cursor: options?.cursor,
|
|
2433
2356
|
query,
|
|
@@ -2448,7 +2371,7 @@ function createApiClient({
|
|
|
2448
2371
|
async function getUserThreadsSince_experimental(options) {
|
|
2449
2372
|
const json = await httpClient.get(
|
|
2450
2373
|
url`/v2/c/threads/delta`,
|
|
2451
|
-
await authManager.getAuthValue({
|
|
2374
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2452
2375
|
{ since: options.since.toISOString() },
|
|
2453
2376
|
{ signal: options.signal }
|
|
2454
2377
|
);
|
|
@@ -2477,7 +2400,8 @@ function createApiClient({
|
|
|
2477
2400
|
const { groups: plainGroups } = await httpClient.post(
|
|
2478
2401
|
url`/v2/c/groups/find`,
|
|
2479
2402
|
await authManager.getAuthValue({
|
|
2480
|
-
|
|
2403
|
+
resource: "personal",
|
|
2404
|
+
access: "write"
|
|
2481
2405
|
}),
|
|
2482
2406
|
{ groupIds }
|
|
2483
2407
|
);
|
|
@@ -2496,7 +2420,7 @@ function createApiClient({
|
|
|
2496
2420
|
async function getUrlMetadata(_url) {
|
|
2497
2421
|
const { metadata } = await httpClient.get(
|
|
2498
2422
|
url`/v2/c/urls/metadata`,
|
|
2499
|
-
await authManager.getAuthValue({
|
|
2423
|
+
await authManager.getAuthValue({ resource: "personal", access: "write" }),
|
|
2500
2424
|
{ url: _url }
|
|
2501
2425
|
);
|
|
2502
2426
|
return metadata;
|
|
@@ -2536,10 +2460,6 @@ function createApiClient({
|
|
|
2536
2460
|
getAttachmentUrl,
|
|
2537
2461
|
uploadAttachment,
|
|
2538
2462
|
getOrCreateAttachmentUrlsStore,
|
|
2539
|
-
// User attachments
|
|
2540
|
-
uploadChatAttachment,
|
|
2541
|
-
getOrCreateChatAttachmentUrlsStore,
|
|
2542
|
-
getChatAttachmentUrl,
|
|
2543
2463
|
// Room storage
|
|
2544
2464
|
streamStorage,
|
|
2545
2465
|
// Notifications
|
|
@@ -5233,22 +5153,291 @@ function createReceivingToolInvocation(invocationId, name, partialArgsText = "")
|
|
|
5233
5153
|
};
|
|
5234
5154
|
}
|
|
5235
5155
|
|
|
5236
|
-
// src/protocol/
|
|
5237
|
-
var Permission =
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5156
|
+
// src/protocol/Permissions.ts
|
|
5157
|
+
var Permission = {
|
|
5158
|
+
/**
|
|
5159
|
+
* Default permission for a room
|
|
5160
|
+
*/
|
|
5161
|
+
RoomWrite: "room:write",
|
|
5162
|
+
RoomRead: "room:read",
|
|
5163
|
+
/**
|
|
5164
|
+
* Presence (LiveRoom Websocket access)
|
|
5165
|
+
*/
|
|
5166
|
+
RoomPresenceRead: "room:presence:read",
|
|
5167
|
+
RoomPresenceNone: "room:presence:none",
|
|
5168
|
+
/**
|
|
5169
|
+
* Storage
|
|
5170
|
+
*/
|
|
5171
|
+
RoomStorageRead: "room:storage:read",
|
|
5172
|
+
RoomStorageWrite: "room:storage:write",
|
|
5173
|
+
RoomStorageNone: "room:storage:none",
|
|
5174
|
+
/**
|
|
5175
|
+
* Comments
|
|
5176
|
+
*/
|
|
5177
|
+
RoomCommentsWrite: "room:comments:write",
|
|
5178
|
+
RoomCommentsRead: "room:comments:read",
|
|
5179
|
+
RoomCommentsNone: "room:comments:none",
|
|
5180
|
+
/**
|
|
5181
|
+
* Feeds
|
|
5182
|
+
*/
|
|
5183
|
+
RoomFeedsRead: "room:feeds:read",
|
|
5184
|
+
RoomFeedsWrite: "room:feeds:write",
|
|
5185
|
+
RoomFeedsNone: "room:feeds:none",
|
|
5186
|
+
/**
|
|
5187
|
+
* Legacy
|
|
5188
|
+
*/
|
|
5189
|
+
LegacyRoomPresenceWrite: "room:presence:write",
|
|
5190
|
+
LegacyCommentsWrite: "comments:write",
|
|
5191
|
+
LegacyCommentsRead: "comments:read",
|
|
5192
|
+
LegacyFeedsWrite: "feeds:write"
|
|
5193
|
+
};
|
|
5194
|
+
var ACCESS_LEVELS = [
|
|
5195
|
+
"none",
|
|
5196
|
+
"read",
|
|
5197
|
+
"write"
|
|
5198
|
+
];
|
|
5199
|
+
var ACCESS_RANKS = {
|
|
5200
|
+
none: 0,
|
|
5201
|
+
read: 1,
|
|
5202
|
+
write: 2
|
|
5203
|
+
};
|
|
5204
|
+
var NO_PERMISSION_CAPABILITIES = {
|
|
5205
|
+
creation: "none",
|
|
5206
|
+
presence: "none",
|
|
5207
|
+
storage: "none",
|
|
5208
|
+
comments: "none",
|
|
5209
|
+
feeds: "none",
|
|
5210
|
+
personal: "write"
|
|
5211
|
+
};
|
|
5212
|
+
var RESOURCE_PERMISSIONS = {
|
|
5213
|
+
creation: {
|
|
5214
|
+
read: [Permission.RoomRead],
|
|
5215
|
+
write: [Permission.RoomWrite]
|
|
5216
|
+
},
|
|
5217
|
+
personal: {
|
|
5218
|
+
write: []
|
|
5219
|
+
},
|
|
5220
|
+
presence: {
|
|
5221
|
+
write: [Permission.LegacyRoomPresenceWrite],
|
|
5222
|
+
read: [Permission.RoomPresenceRead],
|
|
5223
|
+
none: [Permission.RoomPresenceNone]
|
|
5224
|
+
},
|
|
5225
|
+
storage: {
|
|
5226
|
+
write: [Permission.RoomStorageWrite],
|
|
5227
|
+
read: [Permission.RoomStorageRead],
|
|
5228
|
+
none: [Permission.RoomStorageNone]
|
|
5229
|
+
},
|
|
5230
|
+
comments: {
|
|
5231
|
+
write: [Permission.RoomCommentsWrite, Permission.LegacyCommentsWrite],
|
|
5232
|
+
read: [Permission.RoomCommentsRead, Permission.LegacyCommentsRead],
|
|
5233
|
+
none: [Permission.RoomCommentsNone]
|
|
5234
|
+
},
|
|
5235
|
+
feeds: {
|
|
5236
|
+
write: [Permission.RoomFeedsWrite, Permission.LegacyFeedsWrite],
|
|
5237
|
+
read: [Permission.RoomFeedsRead],
|
|
5238
|
+
none: [Permission.RoomFeedsNone]
|
|
5239
|
+
}
|
|
5240
|
+
};
|
|
5241
|
+
var DEFAULT_PERMISSION_RESOURCE = "creation";
|
|
5242
|
+
var ROOM_PERMISSION_RESOURCES = [
|
|
5243
|
+
"presence",
|
|
5244
|
+
"storage",
|
|
5245
|
+
"comments",
|
|
5246
|
+
"feeds"
|
|
5247
|
+
];
|
|
5248
|
+
function resolveResourceAccess(scopes, resource) {
|
|
5249
|
+
const permissions = RESOURCE_PERMISSIONS[resource];
|
|
5250
|
+
let resourceAccess;
|
|
5251
|
+
for (const access of ACCESS_LEVELS) {
|
|
5252
|
+
const scopedPermissions = permissions[access];
|
|
5253
|
+
if (scopedPermissions !== void 0 && scopedPermissions.some((permission) => scopes.includes(permission))) {
|
|
5254
|
+
resourceAccess = access;
|
|
5255
|
+
}
|
|
5256
|
+
}
|
|
5257
|
+
return resourceAccess;
|
|
5258
|
+
}
|
|
5259
|
+
function resolveFullPermissionCapabilities(resolved) {
|
|
5260
|
+
if (!resolved.hasDefaultPermission) {
|
|
5261
|
+
return { ...NO_PERMISSION_CAPABILITIES, ...resolved.capabilities };
|
|
5262
|
+
}
|
|
5263
|
+
const capabilities = {
|
|
5264
|
+
...NO_PERMISSION_CAPABILITIES,
|
|
5265
|
+
[DEFAULT_PERMISSION_RESOURCE]: resolved.baseAccess
|
|
5266
|
+
};
|
|
5267
|
+
for (const resource of ROOM_PERMISSION_RESOURCES) {
|
|
5268
|
+
capabilities[resource] = resolved.capabilities[resource] ?? resolved.baseAccess;
|
|
5269
|
+
}
|
|
5270
|
+
return capabilities;
|
|
5271
|
+
}
|
|
5272
|
+
function permissionCapabilitiesFromScopes(scopes) {
|
|
5273
|
+
return resolveFullPermissionCapabilities(
|
|
5274
|
+
resolvePermissionCapabilities(scopes)
|
|
5275
|
+
);
|
|
5276
|
+
}
|
|
5277
|
+
function resolvePermissionCapabilities(scopes) {
|
|
5278
|
+
const hasDefaultPermission = scopes.includes(Permission.RoomWrite) || scopes.includes(Permission.RoomRead);
|
|
5279
|
+
const baseAccess = scopes.includes(Permission.RoomWrite) ? "write" : scopes.includes(Permission.RoomRead) ? "read" : "none";
|
|
5280
|
+
const capabilities = {};
|
|
5281
|
+
for (const resource of ROOM_PERMISSION_RESOURCES) {
|
|
5282
|
+
const access = resolveResourceAccess(scopes, resource);
|
|
5283
|
+
if (access !== void 0) {
|
|
5284
|
+
capabilities[resource] = access;
|
|
5285
|
+
}
|
|
5286
|
+
}
|
|
5287
|
+
return { hasDefaultPermission, baseAccess, capabilities };
|
|
5288
|
+
}
|
|
5289
|
+
function hasPermissionCapability(scopes, resource, requiredAccess) {
|
|
5290
|
+
const access = permissionCapabilitiesFromScopes(scopes)[resource];
|
|
5291
|
+
return ACCESS_RANKS[access] >= ACCESS_RANKS[requiredAccess];
|
|
5292
|
+
}
|
|
5293
|
+
function hasPermissionCapabilityAccess(capabilities, resource, requiredAccess) {
|
|
5294
|
+
const access = capabilities[resource] ?? "none";
|
|
5295
|
+
return ACCESS_RANKS[access] >= ACCESS_RANKS[requiredAccess];
|
|
5296
|
+
}
|
|
5297
|
+
|
|
5298
|
+
// src/permissions.ts
|
|
5299
|
+
var VALID_PERMISSIONS = new Set(Object.values(Permission));
|
|
5300
|
+
var DEFAULT_PERMISSIONS = [
|
|
5301
|
+
Permission.RoomRead,
|
|
5302
|
+
Permission.RoomWrite
|
|
5303
|
+
];
|
|
5304
|
+
var ROOM_PERMISSION_OBJECT_KEYS = /* @__PURE__ */ new Set([
|
|
5305
|
+
"default",
|
|
5306
|
+
...ROOM_PERMISSION_RESOURCES
|
|
5307
|
+
]);
|
|
5308
|
+
var RESOURCE_SPECIFIC_PERMISSIONS_BY_RESOURCE = {
|
|
5309
|
+
presence: Object.values(RESOURCE_PERMISSIONS.presence).flat(),
|
|
5310
|
+
storage: Object.values(RESOURCE_PERMISSIONS.storage).flat(),
|
|
5311
|
+
comments: Object.values(RESOURCE_PERMISSIONS.comments).flat(),
|
|
5312
|
+
feeds: Object.values(RESOURCE_PERMISSIONS.feeds).flat()
|
|
5313
|
+
};
|
|
5314
|
+
var RESOURCE_SPECIFIC_PERMISSIONS = ROOM_PERMISSION_RESOURCES.flatMap(
|
|
5315
|
+
(resource) => RESOURCE_SPECIFIC_PERMISSIONS_BY_RESOURCE[resource]
|
|
5316
|
+
);
|
|
5317
|
+
function permissionForAccessLevel(resource, access) {
|
|
5318
|
+
const levels = RESOURCE_PERMISSIONS[resource];
|
|
5319
|
+
const permissions = levels[access];
|
|
5320
|
+
if (permissions === void 0 || permissions.length === 0) {
|
|
5321
|
+
throw new Error(
|
|
5322
|
+
`Invalid permission level for ${resource}: ${String(access)}`
|
|
5323
|
+
);
|
|
5324
|
+
}
|
|
5325
|
+
return permissions[0];
|
|
5326
|
+
}
|
|
5327
|
+
function resolveRoomPermissionCapabilities(permissions, roomId) {
|
|
5328
|
+
const matchedPermissions = permissions.filter(
|
|
5329
|
+
(permission) => resourceMatchesRoomId(permission.resource, roomId)
|
|
5330
|
+
);
|
|
5331
|
+
if (matchedPermissions.length === 0) {
|
|
5332
|
+
return void 0;
|
|
5333
|
+
}
|
|
5334
|
+
let hasDefaultPermission = false;
|
|
5335
|
+
let baseAccess = "none";
|
|
5336
|
+
const explicitCapabilities = {};
|
|
5337
|
+
for (const permission of matchedPermissions) {
|
|
5338
|
+
const resolved = resolvePermissionCapabilities(permission.scopes);
|
|
5339
|
+
if (resolved.hasDefaultPermission) {
|
|
5340
|
+
hasDefaultPermission = true;
|
|
5341
|
+
baseAccess = strongestAccess(baseAccess, resolved.baseAccess);
|
|
5342
|
+
}
|
|
5343
|
+
for (const resource of ROOM_PERMISSION_RESOURCES) {
|
|
5344
|
+
const access = resolved.capabilities[resource];
|
|
5345
|
+
if (access !== void 0) {
|
|
5346
|
+
explicitCapabilities[resource] = strongestAccess(
|
|
5347
|
+
explicitCapabilities[resource] ?? "none",
|
|
5348
|
+
access
|
|
5349
|
+
);
|
|
5350
|
+
}
|
|
5351
|
+
}
|
|
5352
|
+
}
|
|
5353
|
+
return resolveFullPermissionCapabilities({
|
|
5354
|
+
hasDefaultPermission,
|
|
5355
|
+
baseAccess,
|
|
5356
|
+
capabilities: explicitCapabilities
|
|
5357
|
+
});
|
|
5358
|
+
}
|
|
5359
|
+
function isRoomPermissionArray(input) {
|
|
5360
|
+
return Array.isArray(input);
|
|
5361
|
+
}
|
|
5362
|
+
function normalizeRoomPermissionInput(input) {
|
|
5363
|
+
if (isRoomPermissionArray(input)) {
|
|
5364
|
+
return input.map((permission) => {
|
|
5365
|
+
if (!VALID_PERMISSIONS.has(permission)) {
|
|
5366
|
+
throw new Error(`Not a valid permission: ${permission}`);
|
|
5367
|
+
}
|
|
5368
|
+
return permission;
|
|
5369
|
+
});
|
|
5370
|
+
}
|
|
5371
|
+
return normalizeRoomPermissionObject(input);
|
|
5372
|
+
}
|
|
5373
|
+
function normalizeRoomPermissionObject(objectInput) {
|
|
5374
|
+
for (const key of Object.keys(objectInput)) {
|
|
5375
|
+
if (!ROOM_PERMISSION_OBJECT_KEYS.has(key)) {
|
|
5376
|
+
throw new Error(`Unknown permission field: ${key}`);
|
|
5377
|
+
}
|
|
5378
|
+
}
|
|
5379
|
+
const permissions = [];
|
|
5380
|
+
if (objectInput.default !== void 0) {
|
|
5381
|
+
permissions.push(
|
|
5382
|
+
permissionForAccessLevel(DEFAULT_PERMISSION_RESOURCE, objectInput.default)
|
|
5383
|
+
);
|
|
5384
|
+
}
|
|
5385
|
+
for (const resource of ROOM_PERMISSION_RESOURCES) {
|
|
5386
|
+
const access = objectInput[resource];
|
|
5387
|
+
if (access !== void 0) {
|
|
5388
|
+
permissions.push(permissionForAccessLevel(resource, access));
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
if (permissions.length === 0) {
|
|
5392
|
+
throw new Error("Permission object cannot be empty");
|
|
5393
|
+
}
|
|
5394
|
+
return permissions;
|
|
5395
|
+
}
|
|
5396
|
+
function normalizeRoomAccessesInput(input) {
|
|
5397
|
+
if (input === void 0) {
|
|
5398
|
+
return void 0;
|
|
5399
|
+
}
|
|
5400
|
+
return Object.fromEntries(
|
|
5401
|
+
Object.entries(input).map(([id, permissions]) => [
|
|
5402
|
+
id,
|
|
5403
|
+
normalizeRoomPermissionInput(permissions)
|
|
5404
|
+
])
|
|
5405
|
+
);
|
|
5406
|
+
}
|
|
5407
|
+
function normalizeRoomAccessesUpdateInput(input) {
|
|
5408
|
+
if (input === void 0) {
|
|
5409
|
+
return void 0;
|
|
5410
|
+
}
|
|
5411
|
+
return Object.fromEntries(
|
|
5412
|
+
Object.entries(input).map(([id, permissions]) => [
|
|
5413
|
+
id,
|
|
5414
|
+
permissions === null ? null : normalizeRoomPermissionInput(permissions)
|
|
5415
|
+
])
|
|
5416
|
+
);
|
|
5251
5417
|
}
|
|
5418
|
+
function getRoomPermissionConflicts(permission) {
|
|
5419
|
+
if (DEFAULT_PERMISSIONS.includes(permission)) {
|
|
5420
|
+
return [...DEFAULT_PERMISSIONS, ...RESOURCE_SPECIFIC_PERMISSIONS];
|
|
5421
|
+
}
|
|
5422
|
+
for (const resource of ROOM_PERMISSION_RESOURCES) {
|
|
5423
|
+
const permissions = RESOURCE_SPECIFIC_PERMISSIONS_BY_RESOURCE[resource];
|
|
5424
|
+
if (permissions.includes(permission)) {
|
|
5425
|
+
return permissions;
|
|
5426
|
+
}
|
|
5427
|
+
}
|
|
5428
|
+
return [];
|
|
5429
|
+
}
|
|
5430
|
+
function strongestAccess(left, right) {
|
|
5431
|
+
return ACCESS_RANKS[right] > ACCESS_RANKS[left] ? right : left;
|
|
5432
|
+
}
|
|
5433
|
+
function resourceMatchesRoomId(resource, roomId) {
|
|
5434
|
+
if (resource.includes("*")) {
|
|
5435
|
+
return roomId.startsWith(resource.replace("*", ""));
|
|
5436
|
+
}
|
|
5437
|
+
return resource === roomId;
|
|
5438
|
+
}
|
|
5439
|
+
|
|
5440
|
+
// src/protocol/AuthToken.ts
|
|
5252
5441
|
function isValidAuthTokenPayload(data) {
|
|
5253
5442
|
return isPlainObject(data) && (data.k === "acc" /* ACCESS_TOKEN */ || data.k === "id" /* ID_TOKEN */);
|
|
5254
5443
|
}
|
|
@@ -5287,47 +5476,22 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5287
5476
|
const authentication = prepareAuthentication(authOptions);
|
|
5288
5477
|
const seenTokens = /* @__PURE__ */ new Set();
|
|
5289
5478
|
const tokens = [];
|
|
5290
|
-
const expiryTimes = [];
|
|
5291
5479
|
const requestPromises = /* @__PURE__ */ new Map();
|
|
5292
5480
|
function reset() {
|
|
5293
5481
|
seenTokens.clear();
|
|
5294
5482
|
tokens.length = 0;
|
|
5295
|
-
expiryTimes.length = 0;
|
|
5296
5483
|
requestPromises.clear();
|
|
5297
5484
|
}
|
|
5298
|
-
function hasCorrespondingScopes(requestedScope, scopes) {
|
|
5299
|
-
if (requestedScope === "comments:read") {
|
|
5300
|
-
return scopes.includes("comments:read" /* CommentsRead */) || scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:read" /* Read */) || scopes.includes("room:write" /* Write */);
|
|
5301
|
-
} else if (requestedScope === "room:read") {
|
|
5302
|
-
return scopes.includes("room:read" /* Read */) || scopes.includes("room:write" /* Write */);
|
|
5303
|
-
}
|
|
5304
|
-
return false;
|
|
5305
|
-
}
|
|
5306
5485
|
function getCachedToken(requestOptions) {
|
|
5307
5486
|
const now2 = Math.ceil(Date.now() / 1e3);
|
|
5308
5487
|
for (let i = tokens.length - 1; i >= 0; i--) {
|
|
5309
|
-
const
|
|
5310
|
-
|
|
5311
|
-
if (expiresAt <= now2) {
|
|
5488
|
+
const cachedToken = tokens[i];
|
|
5489
|
+
if (cachedToken.expiresAt <= now2) {
|
|
5312
5490
|
tokens.splice(i, 1);
|
|
5313
|
-
expiryTimes.splice(i, 1);
|
|
5314
5491
|
continue;
|
|
5315
5492
|
}
|
|
5316
|
-
if (
|
|
5317
|
-
return token;
|
|
5318
|
-
} else if (token.parsed.k === "acc" /* ACCESS_TOKEN */) {
|
|
5319
|
-
if (!requestOptions.roomId && Object.entries(token.parsed.perms).length === 0) {
|
|
5320
|
-
return token;
|
|
5321
|
-
}
|
|
5322
|
-
for (const [resource, scopes] of Object.entries(token.parsed.perms)) {
|
|
5323
|
-
if (!requestOptions.roomId) {
|
|
5324
|
-
if (resource.includes("*") && hasCorrespondingScopes(requestOptions.requestedScope, scopes)) {
|
|
5325
|
-
return token;
|
|
5326
|
-
}
|
|
5327
|
-
} else if (resource.includes("*") && requestOptions.roomId.startsWith(resource.replace("*", "")) || requestOptions.roomId === resource && hasCorrespondingScopes(requestOptions.requestedScope, scopes)) {
|
|
5328
|
-
return token;
|
|
5329
|
-
}
|
|
5330
|
-
}
|
|
5493
|
+
if (cachedTokenSatisfiesRequest(cachedToken, requestOptions)) {
|
|
5494
|
+
return cachedToken.token;
|
|
5331
5495
|
}
|
|
5332
5496
|
}
|
|
5333
5497
|
return void 0;
|
|
@@ -5385,11 +5549,12 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5385
5549
|
return { type: "secret", token: cachedToken };
|
|
5386
5550
|
}
|
|
5387
5551
|
let currentPromise;
|
|
5388
|
-
|
|
5389
|
-
|
|
5552
|
+
const requestKey = getAuthRequestKey(requestOptions);
|
|
5553
|
+
if (requestKey !== void 0) {
|
|
5554
|
+
currentPromise = requestPromises.get(requestKey);
|
|
5390
5555
|
if (currentPromise === void 0) {
|
|
5391
5556
|
currentPromise = makeAuthRequest(requestOptions);
|
|
5392
|
-
requestPromises.set(
|
|
5557
|
+
requestPromises.set(requestKey, currentPromise);
|
|
5393
5558
|
}
|
|
5394
5559
|
} else {
|
|
5395
5560
|
currentPromise = requestPromises.get("liveblocks-user-token");
|
|
@@ -5403,12 +5568,12 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5403
5568
|
const BUFFER = 30;
|
|
5404
5569
|
const expiresAt = Math.floor(Date.now() / 1e3) + (token.parsed.exp - token.parsed.iat) - BUFFER;
|
|
5405
5570
|
seenTokens.add(token.raw);
|
|
5406
|
-
|
|
5407
|
-
|
|
5571
|
+
const cachedToken2 = makeCachedToken(token, expiresAt);
|
|
5572
|
+
tokens.push(cachedToken2);
|
|
5408
5573
|
return { type: "secret", token };
|
|
5409
5574
|
} finally {
|
|
5410
|
-
if (
|
|
5411
|
-
requestPromises.delete(
|
|
5575
|
+
if (requestKey !== void 0) {
|
|
5576
|
+
requestPromises.delete(requestKey);
|
|
5412
5577
|
} else {
|
|
5413
5578
|
requestPromises.delete("liveblocks-user-token");
|
|
5414
5579
|
}
|
|
@@ -5419,6 +5584,48 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5419
5584
|
getAuthValue
|
|
5420
5585
|
};
|
|
5421
5586
|
}
|
|
5587
|
+
function getAuthRequestKey(request) {
|
|
5588
|
+
if (request.roomId === void 0) {
|
|
5589
|
+
return void 0;
|
|
5590
|
+
}
|
|
5591
|
+
return `${request.roomId}:${request.resource}:${request.access}`;
|
|
5592
|
+
}
|
|
5593
|
+
function makeCachedToken(token, expiresAt) {
|
|
5594
|
+
if (token.parsed.k === "acc" /* ACCESS_TOKEN */) {
|
|
5595
|
+
return {
|
|
5596
|
+
token,
|
|
5597
|
+
expiresAt,
|
|
5598
|
+
permissions: getAuthTokenPermissionScopes(token.parsed.perms)
|
|
5599
|
+
};
|
|
5600
|
+
}
|
|
5601
|
+
return { token, expiresAt };
|
|
5602
|
+
}
|
|
5603
|
+
function getAuthTokenPermissionScopes(permissions) {
|
|
5604
|
+
return Object.entries(permissions).map(([resource, scopes]) => ({
|
|
5605
|
+
resource,
|
|
5606
|
+
scopes
|
|
5607
|
+
}));
|
|
5608
|
+
}
|
|
5609
|
+
function cachedTokenSatisfiesRequest(cachedToken, request) {
|
|
5610
|
+
if (cachedToken.token.parsed.k === "id" /* ID_TOKEN */) {
|
|
5611
|
+
return true;
|
|
5612
|
+
}
|
|
5613
|
+
if (request.resource === "personal") {
|
|
5614
|
+
return true;
|
|
5615
|
+
}
|
|
5616
|
+
if (request.roomId === void 0) {
|
|
5617
|
+
return false;
|
|
5618
|
+
}
|
|
5619
|
+
const capabilities = resolveRoomPermissionCapabilities(
|
|
5620
|
+
cachedToken.permissions ?? [],
|
|
5621
|
+
request.roomId
|
|
5622
|
+
);
|
|
5623
|
+
return capabilities !== void 0 && hasPermissionCapabilityAccess(
|
|
5624
|
+
capabilities,
|
|
5625
|
+
request.resource,
|
|
5626
|
+
request.access
|
|
5627
|
+
);
|
|
5628
|
+
}
|
|
5422
5629
|
function prepareAuthentication(authOptions) {
|
|
5423
5630
|
const { publicApiKey, authEndpoint } = authOptions;
|
|
5424
5631
|
if (authEndpoint !== void 0 && publicApiKey !== void 0) {
|
|
@@ -5511,24 +5718,18 @@ var OpCode = Object.freeze({
|
|
|
5511
5718
|
DELETE_CRDT: 5,
|
|
5512
5719
|
DELETE_OBJECT_KEY: 6,
|
|
5513
5720
|
CREATE_MAP: 7,
|
|
5514
|
-
CREATE_REGISTER: 8
|
|
5515
|
-
CREATE_TEXT: 9,
|
|
5516
|
-
UPDATE_TEXT: 10
|
|
5721
|
+
CREATE_REGISTER: 8
|
|
5517
5722
|
});
|
|
5518
5723
|
function isIgnoredOp(op) {
|
|
5519
5724
|
return op.type === OpCode.DELETE_CRDT && op.id === "ACK";
|
|
5520
5725
|
}
|
|
5521
|
-
function isCreateOp(op) {
|
|
5522
|
-
return op.type === OpCode.CREATE_OBJECT || op.type === OpCode.CREATE_REGISTER || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_LIST;
|
|
5523
|
-
}
|
|
5524
5726
|
|
|
5525
5727
|
// src/protocol/StorageNode.ts
|
|
5526
5728
|
var CrdtType = Object.freeze({
|
|
5527
5729
|
OBJECT: 0,
|
|
5528
5730
|
LIST: 1,
|
|
5529
5731
|
MAP: 2,
|
|
5530
|
-
REGISTER: 3
|
|
5531
|
-
TEXT: 4
|
|
5732
|
+
REGISTER: 3
|
|
5532
5733
|
});
|
|
5533
5734
|
function isRootStorageNode(node) {
|
|
5534
5735
|
return node[0] === "root";
|
|
@@ -5545,9 +5746,6 @@ function isMapStorageNode(node) {
|
|
|
5545
5746
|
function isRegisterStorageNode(node) {
|
|
5546
5747
|
return node[1].type === CrdtType.REGISTER;
|
|
5547
5748
|
}
|
|
5548
|
-
function isTextStorageNode(node) {
|
|
5549
|
-
return node[1].type === CrdtType.TEXT;
|
|
5550
|
-
}
|
|
5551
5749
|
function isCompactRootNode(node) {
|
|
5552
5750
|
return node[0] === "root";
|
|
5553
5751
|
}
|
|
@@ -5570,9 +5768,6 @@ function* compactNodesToNodeStream(compactNodes) {
|
|
|
5570
5768
|
case CrdtType.REGISTER:
|
|
5571
5769
|
yield [cnode[0], { type: CrdtType.REGISTER, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
5572
5770
|
break;
|
|
5573
|
-
case CrdtType.TEXT:
|
|
5574
|
-
yield [cnode[0], { type: CrdtType.TEXT, parentId: cnode[2], parentKey: cnode[3], data: cnode[4], version: cnode[5] }];
|
|
5575
|
-
break;
|
|
5576
5771
|
default:
|
|
5577
5772
|
}
|
|
5578
5773
|
}
|
|
@@ -5601,17 +5796,6 @@ function* nodeStreamToCompactNodes(nodes) {
|
|
|
5601
5796
|
const id = node[0];
|
|
5602
5797
|
const crdt = node[1];
|
|
5603
5798
|
yield [id, CrdtType.REGISTER, crdt.parentId, crdt.parentKey, crdt.data];
|
|
5604
|
-
} else if (isTextStorageNode(node)) {
|
|
5605
|
-
const id = node[0];
|
|
5606
|
-
const crdt = node[1];
|
|
5607
|
-
yield [
|
|
5608
|
-
id,
|
|
5609
|
-
CrdtType.TEXT,
|
|
5610
|
-
crdt.parentId,
|
|
5611
|
-
crdt.parentKey,
|
|
5612
|
-
crdt.data,
|
|
5613
|
-
crdt.version
|
|
5614
|
-
];
|
|
5615
5799
|
} else {
|
|
5616
5800
|
}
|
|
5617
5801
|
}
|
|
@@ -5796,112 +5980,12 @@ function asPos(str) {
|
|
|
5796
5980
|
return isPos(str) ? str : convertToPos(str);
|
|
5797
5981
|
}
|
|
5798
5982
|
|
|
5799
|
-
// src/crdts/UnacknowledgedOps.ts
|
|
5800
|
-
var UnacknowledgedOps = class {
|
|
5801
|
-
// opId -> op
|
|
5802
|
-
#byOpId = /* @__PURE__ */ new Map();
|
|
5803
|
-
// position -> (opId -> Create op)
|
|
5804
|
-
#createOpsByPosition = /* @__PURE__ */ new Map();
|
|
5805
|
-
// parentId -> (opId -> Create op)
|
|
5806
|
-
#createOpsByParent = /* @__PURE__ */ new Map();
|
|
5807
|
-
// opIds of pending ops that were in flight when a connection died, so the
|
|
5808
|
-
// server may already have processed them. See isPossiblyStored().
|
|
5809
|
-
#possiblyStoredOpIds = /* @__PURE__ */ new Set();
|
|
5810
|
-
#posKey(parentId, parentKey) {
|
|
5811
|
-
return `${parentId}
|
|
5812
|
-
${parentKey}`;
|
|
5813
|
-
}
|
|
5814
|
-
get size() {
|
|
5815
|
-
return this.#byOpId.size;
|
|
5816
|
-
}
|
|
5817
|
-
/**
|
|
5818
|
-
* Mark the given Op as still unacknowledged.
|
|
5819
|
-
*/
|
|
5820
|
-
add(op) {
|
|
5821
|
-
this.#byOpId.set(op.opId, op);
|
|
5822
|
-
if (isCreateOp(op)) {
|
|
5823
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5824
|
-
let atPosition = this.#createOpsByPosition.get(posKey);
|
|
5825
|
-
if (atPosition === void 0) {
|
|
5826
|
-
atPosition = /* @__PURE__ */ new Map();
|
|
5827
|
-
this.#createOpsByPosition.set(posKey, atPosition);
|
|
5828
|
-
}
|
|
5829
|
-
atPosition.set(op.opId, op);
|
|
5830
|
-
let inParent = this.#createOpsByParent.get(op.parentId);
|
|
5831
|
-
if (inParent === void 0) {
|
|
5832
|
-
inParent = /* @__PURE__ */ new Map();
|
|
5833
|
-
this.#createOpsByParent.set(op.parentId, inParent);
|
|
5834
|
-
}
|
|
5835
|
-
inParent.set(op.opId, op);
|
|
5836
|
-
}
|
|
5837
|
-
}
|
|
5838
|
-
/**
|
|
5839
|
-
* Drop the op with the given opId from the set, because the server has
|
|
5840
|
-
* acknowledged it (confirmed our own op, or signalled it was seen but
|
|
5841
|
-
* ignored).
|
|
5842
|
-
*/
|
|
5843
|
-
delete(opId) {
|
|
5844
|
-
const op = this.#byOpId.get(opId);
|
|
5845
|
-
if (op === void 0) {
|
|
5846
|
-
return;
|
|
5847
|
-
}
|
|
5848
|
-
this.#byOpId.delete(opId);
|
|
5849
|
-
this.#possiblyStoredOpIds.delete(opId);
|
|
5850
|
-
if (isCreateOp(op)) {
|
|
5851
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5852
|
-
const atPosition = this.#createOpsByPosition.get(posKey);
|
|
5853
|
-
atPosition?.delete(opId);
|
|
5854
|
-
if (atPosition !== void 0 && atPosition.size === 0) {
|
|
5855
|
-
this.#createOpsByPosition.delete(posKey);
|
|
5856
|
-
}
|
|
5857
|
-
const inParent = this.#createOpsByParent.get(op.parentId);
|
|
5858
|
-
inParent?.delete(opId);
|
|
5859
|
-
if (inParent !== void 0 && inParent.size === 0) {
|
|
5860
|
-
this.#createOpsByParent.delete(op.parentId);
|
|
5861
|
-
}
|
|
5862
|
-
}
|
|
5863
|
-
}
|
|
5864
|
-
/**
|
|
5865
|
-
* The still-unacknowledged Create ops with the given `parentId` and
|
|
5866
|
-
* `parentKey` (targeting one exact position), in dispatch order. O(1) lookup.
|
|
5867
|
-
* Empty if none.
|
|
5868
|
-
*/
|
|
5869
|
-
getByParentIdAndKey(parentId, parentKey) {
|
|
5870
|
-
return this.#createOpsByPosition.get(this.#posKey(parentId, parentKey))?.values() ?? [];
|
|
5871
|
-
}
|
|
5872
|
-
/**
|
|
5873
|
-
* The still-unacknowledged Create ops with the given `parentId` (across all
|
|
5874
|
-
* positions), in dispatch order. O(1) lookup. Empty if none.
|
|
5875
|
-
*/
|
|
5876
|
-
getByParentId(parentId) {
|
|
5877
|
-
return this.#createOpsByParent.get(parentId)?.values() ?? [];
|
|
5878
|
-
}
|
|
5879
|
-
/** All still-unacknowledged ops, in dispatch order. */
|
|
5880
|
-
values() {
|
|
5881
|
-
return this.#byOpId.values();
|
|
5882
|
-
}
|
|
5883
|
-
isPossiblyStored(opId) {
|
|
5884
|
-
return this.#possiblyStoredOpIds.has(opId);
|
|
5885
|
-
}
|
|
5886
|
-
/**
|
|
5887
|
-
* Mark every currently pending op as possibly stored on the server. Called
|
|
5888
|
-
* when the connection dies: all of these ops were in flight, and their
|
|
5889
|
-
* (possibly lost) acks would have been the only way to know their fate.
|
|
5890
|
-
*/
|
|
5891
|
-
markAllAsPossiblyStored() {
|
|
5892
|
-
for (const opId of this.#byOpId.keys()) {
|
|
5893
|
-
this.#possiblyStoredOpIds.add(opId);
|
|
5894
|
-
}
|
|
5895
|
-
}
|
|
5896
|
-
};
|
|
5897
|
-
|
|
5898
5983
|
// src/crdts/AbstractCrdt.ts
|
|
5899
5984
|
function createManagedPool(roomId, options) {
|
|
5900
5985
|
const {
|
|
5901
5986
|
getCurrentConnectionId,
|
|
5902
5987
|
onDispatch,
|
|
5903
|
-
isStorageWritable = () => true
|
|
5904
|
-
unacknowledgedOps = new UnacknowledgedOps()
|
|
5988
|
+
isStorageWritable = () => true
|
|
5905
5989
|
} = options;
|
|
5906
5990
|
let clock = 0;
|
|
5907
5991
|
let opClock = 0;
|
|
@@ -5923,8 +6007,7 @@ function createManagedPool(roomId, options) {
|
|
|
5923
6007
|
"Cannot write to storage with a read only user, please ensure the user has write permissions"
|
|
5924
6008
|
);
|
|
5925
6009
|
}
|
|
5926
|
-
}
|
|
5927
|
-
unacknowledgedOps
|
|
6010
|
+
}
|
|
5928
6011
|
};
|
|
5929
6012
|
}
|
|
5930
6013
|
function crdtAsLiveNode(value) {
|
|
@@ -6206,9 +6289,11 @@ function childNodeLt(a, b) {
|
|
|
6206
6289
|
var LiveList = class _LiveList extends AbstractCrdt {
|
|
6207
6290
|
#items;
|
|
6208
6291
|
#implicitlyDeletedItems;
|
|
6292
|
+
#unacknowledgedSets;
|
|
6209
6293
|
constructor(items) {
|
|
6210
6294
|
super();
|
|
6211
6295
|
this.#implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
|
|
6296
|
+
this.#unacknowledgedSets = /* @__PURE__ */ new Map();
|
|
6212
6297
|
const nodes = [];
|
|
6213
6298
|
let lastPos;
|
|
6214
6299
|
for (const item of items) {
|
|
@@ -6238,13 +6323,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6238
6323
|
}
|
|
6239
6324
|
/**
|
|
6240
6325
|
* @internal
|
|
6241
|
-
*
|
|
6242
|
-
*
|
|
6243
|
-
*
|
|
6244
|
-
* items (flicker, https://github.com/liveblocks/liveblocks/pull/1177).
|
|
6326
|
+
* This function assumes that the resulting ops will be sent to the server if they have an 'opId'
|
|
6327
|
+
* so we mutate _unacknowledgedSets to avoid potential flickering
|
|
6328
|
+
* https://github.com/liveblocks/liveblocks/pull/1177
|
|
6245
6329
|
*
|
|
6246
|
-
* This is quite unintuitive and should disappear as soon as
|
|
6247
|
-
* explicit LiveList.Set operation
|
|
6330
|
+
* This is quite unintuitive and should disappear as soon as
|
|
6331
|
+
* we introduce an explicit LiveList.Set operation
|
|
6248
6332
|
*/
|
|
6249
6333
|
_toOps(parentId, parentKey) {
|
|
6250
6334
|
if (this._id === void 0) {
|
|
@@ -6260,9 +6344,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6260
6344
|
ops.push(op);
|
|
6261
6345
|
for (const item of this.#items) {
|
|
6262
6346
|
const parentKey2 = item._getParentKeyOrThrow();
|
|
6263
|
-
const childOps =
|
|
6347
|
+
const childOps = HACK_addIntentAndDeletedIdToOperation(
|
|
6264
6348
|
item._toOps(this._id, parentKey2),
|
|
6265
|
-
|
|
6349
|
+
void 0
|
|
6266
6350
|
);
|
|
6267
6351
|
for (const childOp of childOps) {
|
|
6268
6352
|
ops.push(childOp);
|
|
@@ -6304,28 +6388,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6304
6388
|
(item) => item._getParentKeyOrThrow() === position
|
|
6305
6389
|
);
|
|
6306
6390
|
}
|
|
6307
|
-
/**
|
|
6308
|
-
* The opId of this list's still-unacknowledged "set" op at the given position,
|
|
6309
|
-
* or undefined if none. Derived from the room's unacknowledgedOps (the single
|
|
6310
|
-
* source of truth) rather than tracked in a per-instance map. The pool's
|
|
6311
|
-
* position index already scopes to this list's (parentId, position); the last
|
|
6312
|
-
* match wins, matching the original last-write-wins map semantics.
|
|
6313
|
-
*/
|
|
6314
|
-
#unacknowledgedSetOpIdAt(position) {
|
|
6315
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6316
|
-
return void 0;
|
|
6317
|
-
}
|
|
6318
|
-
let opId;
|
|
6319
|
-
for (const op of this._pool.unacknowledgedOps.getByParentIdAndKey(
|
|
6320
|
-
this._id,
|
|
6321
|
-
position
|
|
6322
|
-
)) {
|
|
6323
|
-
if (op.intent === "set") {
|
|
6324
|
-
opId = op.opId;
|
|
6325
|
-
}
|
|
6326
|
-
}
|
|
6327
|
-
return opId;
|
|
6328
|
-
}
|
|
6329
6391
|
/** @internal */
|
|
6330
6392
|
_attach(id, pool) {
|
|
6331
6393
|
super._attach(id, pool);
|
|
@@ -6406,9 +6468,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6406
6468
|
if (deletedDelta) {
|
|
6407
6469
|
delta.push(deletedDelta);
|
|
6408
6470
|
}
|
|
6409
|
-
const unacknowledgedOpId = this.#
|
|
6410
|
-
if (unacknowledgedOpId !== void 0
|
|
6411
|
-
|
|
6471
|
+
const unacknowledgedOpId = this.#unacknowledgedSets.get(op.parentKey);
|
|
6472
|
+
if (unacknowledgedOpId !== void 0) {
|
|
6473
|
+
if (unacknowledgedOpId !== op.opId) {
|
|
6474
|
+
return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
|
|
6475
|
+
} else {
|
|
6476
|
+
this.#unacknowledgedSets.delete(op.parentKey);
|
|
6477
|
+
}
|
|
6412
6478
|
}
|
|
6413
6479
|
const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
|
|
6414
6480
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
@@ -6499,92 +6565,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6499
6565
|
this.#shiftItemPosition(existingItemIndex, key);
|
|
6500
6566
|
}
|
|
6501
6567
|
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
6502
|
-
const bumpDeltas = this.#bumpUnackedPushesAbove(key);
|
|
6503
6568
|
return {
|
|
6504
|
-
modified: makeUpdate(this, [
|
|
6505
|
-
insertDelta(newIndex, newItem),
|
|
6506
|
-
...bumpDeltas
|
|
6507
|
-
]),
|
|
6569
|
+
modified: makeUpdate(this, [insertDelta(newIndex, newItem)]),
|
|
6508
6570
|
reverse: []
|
|
6509
6571
|
};
|
|
6510
6572
|
}
|
|
6511
|
-
/**
|
|
6512
|
-
* This list's own still-unacknowledged pushed items (their `intent: "push"`
|
|
6513
|
-
* Create op is still pending in the room's unacknowledgedOps). Derived from
|
|
6514
|
-
* the single source of truth, so an item drops out the instant its op is
|
|
6515
|
-
* acked, with no per-instance membership to leak. Yielded in push order.
|
|
6516
|
-
*
|
|
6517
|
-
* Excludes ops that may already be stored on the server (they were in
|
|
6518
|
-
* flight when a connection died, so their fate is unknown): the bump
|
|
6519
|
-
* prediction assumes the server has not processed the op yet, which is only
|
|
6520
|
-
* guaranteed for ops sent on the current connection. For these excluded
|
|
6521
|
-
* ops, the server's (re-)ack states the authoritative position; predicting
|
|
6522
|
-
* locally could produce a wrong position that no ack would correct.
|
|
6523
|
-
*
|
|
6524
|
-
* Restricted to items currently in `#items`: a pushed node whose op is still
|
|
6525
|
-
* pending may have been pulled out of the list (e.g. implicitly deleted by a
|
|
6526
|
-
* remote set, or removed by an undo) while still living in the pool, and such
|
|
6527
|
-
* a node must not be repositioned.
|
|
6528
|
-
*/
|
|
6529
|
-
*#unackedPushNodes() {
|
|
6530
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6531
|
-
return;
|
|
6532
|
-
}
|
|
6533
|
-
for (const op of this._pool.unacknowledgedOps.getByParentId(this._id)) {
|
|
6534
|
-
if (op.intent !== "push") {
|
|
6535
|
-
continue;
|
|
6536
|
-
}
|
|
6537
|
-
if (this._pool.unacknowledgedOps.isPossiblyStored(op.opId)) {
|
|
6538
|
-
continue;
|
|
6539
|
-
}
|
|
6540
|
-
const node = this._pool.getNode(op.id);
|
|
6541
|
-
if (node !== void 0 && this.#items.includes(node)) {
|
|
6542
|
-
yield node;
|
|
6543
|
-
}
|
|
6544
|
-
}
|
|
6545
|
-
}
|
|
6546
|
-
/**
|
|
6547
|
-
* Optimistic no-flip for pushed items. When a remote op lands at or below my
|
|
6548
|
-
* still-unacked pushed items, those items must end up *after* it: FIFO plus
|
|
6549
|
-
* the room's serial processing guarantee the remote was processed first, so
|
|
6550
|
-
* my unacked pushes belong behind it. Re-chain the whole unacked-push block,
|
|
6551
|
-
* in push order, to sit after the highest confirmed sibling, so it keeps
|
|
6552
|
-
* rendering as a contiguous tail instead of getting interleaved. Local-only;
|
|
6553
|
-
* the real acks overwrite these keys with the (identical) server keys.
|
|
6554
|
-
*/
|
|
6555
|
-
#bumpUnackedPushesAbove(remoteKey) {
|
|
6556
|
-
const pending = new Set(this.#unackedPushNodes());
|
|
6557
|
-
if (pending.size === 0) {
|
|
6558
|
-
return [];
|
|
6559
|
-
}
|
|
6560
|
-
let minPending;
|
|
6561
|
-
for (const node of pending) {
|
|
6562
|
-
const pos = node._parentPos;
|
|
6563
|
-
if (minPending === void 0 || pos < minPending) {
|
|
6564
|
-
minPending = pos;
|
|
6565
|
-
}
|
|
6566
|
-
}
|
|
6567
|
-
if (remoteKey < nn(minPending)) {
|
|
6568
|
-
return [];
|
|
6569
|
-
}
|
|
6570
|
-
let base;
|
|
6571
|
-
for (const item of this.#items) {
|
|
6572
|
-
if (!pending.has(item)) {
|
|
6573
|
-
base = item._parentPos;
|
|
6574
|
-
}
|
|
6575
|
-
}
|
|
6576
|
-
const deltas = [];
|
|
6577
|
-
for (const node of pending) {
|
|
6578
|
-
const previousIndex = this.#items.findIndex((item) => item === node);
|
|
6579
|
-
base = makePosition(base);
|
|
6580
|
-
this.#updateItemPosition(node, base);
|
|
6581
|
-
const index = this.#items.findIndex((item) => item === node);
|
|
6582
|
-
if (index !== previousIndex) {
|
|
6583
|
-
deltas.push(moveDelta(previousIndex, index, node));
|
|
6584
|
-
}
|
|
6585
|
-
}
|
|
6586
|
-
return deltas;
|
|
6587
|
-
}
|
|
6588
6573
|
#applyInsertAck(op) {
|
|
6589
6574
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
6590
6575
|
const key = asPos(op.parentKey);
|
|
@@ -6665,6 +6650,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6665
6650
|
if (this._pool?.getNode(id) !== void 0) {
|
|
6666
6651
|
return { modified: false };
|
|
6667
6652
|
}
|
|
6653
|
+
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
6668
6654
|
const indexOfItemWithSameKey = this._indexOfPosition(key);
|
|
6669
6655
|
child._attach(id, nn(this._pool));
|
|
6670
6656
|
child._setParentLink(this, key);
|
|
@@ -6674,9 +6660,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6674
6660
|
existingItem._detach();
|
|
6675
6661
|
this.#items.remove(existingItem);
|
|
6676
6662
|
this.#items.add(child);
|
|
6677
|
-
const reverse =
|
|
6663
|
+
const reverse = HACK_addIntentAndDeletedIdToOperation(
|
|
6678
6664
|
existingItem._toOps(nn(this._id), key),
|
|
6679
|
-
"set",
|
|
6680
6665
|
op.id
|
|
6681
6666
|
);
|
|
6682
6667
|
const delta = [setDelta(indexOfItemWithSameKey, child)];
|
|
@@ -6919,7 +6904,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6919
6904
|
* @param element The element to add to the end of the LiveList.
|
|
6920
6905
|
*/
|
|
6921
6906
|
push(element) {
|
|
6922
|
-
|
|
6907
|
+
this._pool?.assertStorageIsWritable();
|
|
6908
|
+
return this.insert(element, this.length);
|
|
6923
6909
|
}
|
|
6924
6910
|
/**
|
|
6925
6911
|
* Inserts one element at a specified index.
|
|
@@ -6927,15 +6913,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6927
6913
|
* @param index The index at which you want to insert the element.
|
|
6928
6914
|
*/
|
|
6929
6915
|
insert(element, index) {
|
|
6930
|
-
return this.#injectAt(element, index, "insert");
|
|
6931
|
-
}
|
|
6932
|
-
/**
|
|
6933
|
-
* Shared implementation of `insert` and `push`. A `"push"` intent leaves the
|
|
6934
|
-
* client-computed position untouched (so optimistic rendering is unchanged),
|
|
6935
|
-
* but tags the Op so the server appends it to the true end of the list
|
|
6936
|
-
* instead of resolving its position against the client's stale view.
|
|
6937
|
-
*/
|
|
6938
|
-
#injectAt(element, index, intent) {
|
|
6939
6916
|
this._pool?.assertStorageIsWritable();
|
|
6940
6917
|
if (index < 0 || index > this.#items.length) {
|
|
6941
6918
|
throw new Error(
|
|
@@ -6951,9 +6928,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6951
6928
|
if (this._pool && this._id) {
|
|
6952
6929
|
const id = this._pool.generateId();
|
|
6953
6930
|
value._attach(id, this._pool);
|
|
6954
|
-
const ops = value._toOpsWithOpId(this._id, position, this._pool);
|
|
6955
6931
|
this._pool.dispatch(
|
|
6956
|
-
|
|
6932
|
+
value._toOpsWithOpId(this._id, position, this._pool),
|
|
6957
6933
|
[{ type: OpCode.DELETE_CRDT, id }],
|
|
6958
6934
|
/* @__PURE__ */ new Map([
|
|
6959
6935
|
[this._id, makeUpdate(this, [insertDelta(index, value)])]
|
|
@@ -7111,14 +7087,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7111
7087
|
value._attach(id, this._pool);
|
|
7112
7088
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7113
7089
|
storageUpdates.set(this._id, makeUpdate(this, [setDelta(index, value)]));
|
|
7114
|
-
const ops =
|
|
7090
|
+
const ops = HACK_addIntentAndDeletedIdToOperation(
|
|
7115
7091
|
value._toOpsWithOpId(this._id, position, this._pool),
|
|
7116
|
-
"set",
|
|
7117
7092
|
existingId
|
|
7118
7093
|
);
|
|
7119
|
-
|
|
7094
|
+
this.#unacknowledgedSets.set(position, nn(ops[0].opId));
|
|
7095
|
+
const reverseOps = HACK_addIntentAndDeletedIdToOperation(
|
|
7120
7096
|
existingItem._toOps(this._id, position),
|
|
7121
|
-
"set",
|
|
7122
7097
|
id
|
|
7123
7098
|
);
|
|
7124
7099
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
@@ -7319,11 +7294,15 @@ function moveDelta(previousIndex, index, item) {
|
|
|
7319
7294
|
previousIndex
|
|
7320
7295
|
};
|
|
7321
7296
|
}
|
|
7322
|
-
function
|
|
7297
|
+
function HACK_addIntentAndDeletedIdToOperation(ops, deletedId) {
|
|
7323
7298
|
return ops.map((op, index) => {
|
|
7324
7299
|
if (index === 0) {
|
|
7325
7300
|
const firstOp = op;
|
|
7326
|
-
return {
|
|
7301
|
+
return {
|
|
7302
|
+
...firstOp,
|
|
7303
|
+
intent: "set",
|
|
7304
|
+
deletedId
|
|
7305
|
+
};
|
|
7327
7306
|
} else {
|
|
7328
7307
|
return op;
|
|
7329
7308
|
}
|
|
@@ -7975,7 +7954,6 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7975
7954
|
const id = nn(this._id);
|
|
7976
7955
|
const parentKey = nn(child._parentKey);
|
|
7977
7956
|
const reverse = child._toOps(id, parentKey);
|
|
7978
|
-
const deletedItem = liveNodeToLson(child);
|
|
7979
7957
|
for (const [key, value] of this.#synced) {
|
|
7980
7958
|
if (value === child) {
|
|
7981
7959
|
this.#synced.delete(key);
|
|
@@ -7987,7 +7965,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7987
7965
|
node: this,
|
|
7988
7966
|
type: "LiveObject",
|
|
7989
7967
|
updates: {
|
|
7990
|
-
[parentKey]: { type: "delete"
|
|
7968
|
+
[parentKey]: { type: "delete" }
|
|
7991
7969
|
}
|
|
7992
7970
|
};
|
|
7993
7971
|
return { modified: storageUpdate, reverse };
|
|
@@ -8474,580 +8452,6 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
8474
8452
|
}
|
|
8475
8453
|
};
|
|
8476
8454
|
|
|
8477
|
-
// src/crdts/liveTextOps.ts
|
|
8478
|
-
function attributesEqual(left, right) {
|
|
8479
|
-
if (left === right) {
|
|
8480
|
-
return true;
|
|
8481
|
-
}
|
|
8482
|
-
if (left === void 0 || right === void 0) {
|
|
8483
|
-
return false;
|
|
8484
|
-
}
|
|
8485
|
-
const leftKeys = Object.keys(left);
|
|
8486
|
-
const rightKeys = Object.keys(right);
|
|
8487
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
8488
|
-
return false;
|
|
8489
|
-
}
|
|
8490
|
-
for (const key of leftKeys) {
|
|
8491
|
-
if (left[key] !== right[key]) {
|
|
8492
|
-
return false;
|
|
8493
|
-
}
|
|
8494
|
-
}
|
|
8495
|
-
return true;
|
|
8496
|
-
}
|
|
8497
|
-
function cloneAttributes(attributes) {
|
|
8498
|
-
return attributes === void 0 ? void 0 : freeze({ ...attributes });
|
|
8499
|
-
}
|
|
8500
|
-
function normalizeSegments(segments) {
|
|
8501
|
-
const normalized = [];
|
|
8502
|
-
for (const segment of segments) {
|
|
8503
|
-
if (segment.text.length === 0) {
|
|
8504
|
-
continue;
|
|
8505
|
-
}
|
|
8506
|
-
const last = normalized.at(-1);
|
|
8507
|
-
const attributes = cloneAttributes(segment.attributes);
|
|
8508
|
-
if (last !== void 0 && attributesEqual(last.attributes, attributes)) {
|
|
8509
|
-
last.text += segment.text;
|
|
8510
|
-
} else {
|
|
8511
|
-
normalized.push({ text: segment.text, attributes });
|
|
8512
|
-
}
|
|
8513
|
-
}
|
|
8514
|
-
return normalized;
|
|
8515
|
-
}
|
|
8516
|
-
function dataToSegments(data) {
|
|
8517
|
-
return normalizeSegments(
|
|
8518
|
-
data.map(([text, attributes]) => ({
|
|
8519
|
-
text,
|
|
8520
|
-
attributes
|
|
8521
|
-
}))
|
|
8522
|
-
);
|
|
8523
|
-
}
|
|
8524
|
-
function segmentsToData(segments) {
|
|
8525
|
-
return segments.map(
|
|
8526
|
-
(segment) => segment.attributes === void 0 ? [segment.text] : [segment.text, { ...segment.attributes }]
|
|
8527
|
-
);
|
|
8528
|
-
}
|
|
8529
|
-
function textLength(segments) {
|
|
8530
|
-
return segments.reduce((sum, segment) => sum + segment.text.length, 0);
|
|
8531
|
-
}
|
|
8532
|
-
function splitSegmentsAt(segments, index) {
|
|
8533
|
-
const result = [];
|
|
8534
|
-
let offset = 0;
|
|
8535
|
-
for (const segment of segments) {
|
|
8536
|
-
const end = offset + segment.text.length;
|
|
8537
|
-
if (index > offset && index < end) {
|
|
8538
|
-
const before2 = segment.text.slice(0, index - offset);
|
|
8539
|
-
const after2 = segment.text.slice(index - offset);
|
|
8540
|
-
result.push({ text: before2, attributes: segment.attributes });
|
|
8541
|
-
result.push({ text: after2, attributes: segment.attributes });
|
|
8542
|
-
} else {
|
|
8543
|
-
result.push({ text: segment.text, attributes: segment.attributes });
|
|
8544
|
-
}
|
|
8545
|
-
offset = end;
|
|
8546
|
-
}
|
|
8547
|
-
return result;
|
|
8548
|
-
}
|
|
8549
|
-
function clipRange(index, length, contentLength) {
|
|
8550
|
-
const clippedIndex = Math.max(0, Math.min(index, contentLength));
|
|
8551
|
-
const clippedEnd = Math.max(
|
|
8552
|
-
clippedIndex,
|
|
8553
|
-
Math.min(index + length, contentLength)
|
|
8554
|
-
);
|
|
8555
|
-
return { index: clippedIndex, length: clippedEnd - clippedIndex };
|
|
8556
|
-
}
|
|
8557
|
-
function applyInsert(segments, index, text, attributes) {
|
|
8558
|
-
if (text.length === 0) {
|
|
8559
|
-
return normalizeSegments(segments);
|
|
8560
|
-
}
|
|
8561
|
-
const split = splitSegmentsAt(segments, index);
|
|
8562
|
-
const result = [];
|
|
8563
|
-
let offset = 0;
|
|
8564
|
-
let inserted = false;
|
|
8565
|
-
for (const segment of split) {
|
|
8566
|
-
if (!inserted && offset === index) {
|
|
8567
|
-
result.push({ text, attributes });
|
|
8568
|
-
inserted = true;
|
|
8569
|
-
}
|
|
8570
|
-
result.push(segment);
|
|
8571
|
-
offset += segment.text.length;
|
|
8572
|
-
}
|
|
8573
|
-
if (!inserted) {
|
|
8574
|
-
result.push({ text, attributes });
|
|
8575
|
-
}
|
|
8576
|
-
return normalizeSegments(result);
|
|
8577
|
-
}
|
|
8578
|
-
function extractDeletedSegments(segments, index, length) {
|
|
8579
|
-
const split = splitSegmentsAt(
|
|
8580
|
-
splitSegmentsAt(segments, index),
|
|
8581
|
-
index + length
|
|
8582
|
-
);
|
|
8583
|
-
const deleted = [];
|
|
8584
|
-
let offset = 0;
|
|
8585
|
-
for (const segment of split) {
|
|
8586
|
-
const end = offset + segment.text.length;
|
|
8587
|
-
if (offset >= index && end <= index + length) {
|
|
8588
|
-
deleted.push({
|
|
8589
|
-
text: segment.text,
|
|
8590
|
-
attributes: segment.attributes
|
|
8591
|
-
});
|
|
8592
|
-
}
|
|
8593
|
-
offset = end;
|
|
8594
|
-
}
|
|
8595
|
-
return normalizeSegments(deleted);
|
|
8596
|
-
}
|
|
8597
|
-
function applyDelete(segments, index, length) {
|
|
8598
|
-
const deletedSegments = extractDeletedSegments(segments, index, length);
|
|
8599
|
-
const split = splitSegmentsAt(
|
|
8600
|
-
splitSegmentsAt(segments, index),
|
|
8601
|
-
index + length
|
|
8602
|
-
);
|
|
8603
|
-
const result = [];
|
|
8604
|
-
let offset = 0;
|
|
8605
|
-
let deletedText = "";
|
|
8606
|
-
for (const segment of split) {
|
|
8607
|
-
const end = offset + segment.text.length;
|
|
8608
|
-
if (offset >= index && end <= index + length) {
|
|
8609
|
-
deletedText += segment.text;
|
|
8610
|
-
} else {
|
|
8611
|
-
result.push(segment);
|
|
8612
|
-
}
|
|
8613
|
-
offset = end;
|
|
8614
|
-
}
|
|
8615
|
-
return {
|
|
8616
|
-
segments: normalizeSegments(result),
|
|
8617
|
-
deletedText,
|
|
8618
|
-
deletedSegments
|
|
8619
|
-
};
|
|
8620
|
-
}
|
|
8621
|
-
function applyFormat(segments, index, length, attributes) {
|
|
8622
|
-
const split = splitSegmentsAt(
|
|
8623
|
-
splitSegmentsAt(segments, index),
|
|
8624
|
-
index + length
|
|
8625
|
-
);
|
|
8626
|
-
const result = [];
|
|
8627
|
-
let offset = 0;
|
|
8628
|
-
for (const segment of split) {
|
|
8629
|
-
const end = offset + segment.text.length;
|
|
8630
|
-
if (offset >= index && end <= index + length) {
|
|
8631
|
-
const nextAttributes = {
|
|
8632
|
-
...segment.attributes ?? {}
|
|
8633
|
-
};
|
|
8634
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
8635
|
-
if (value === null) {
|
|
8636
|
-
delete nextAttributes[key];
|
|
8637
|
-
} else {
|
|
8638
|
-
nextAttributes[key] = value;
|
|
8639
|
-
}
|
|
8640
|
-
}
|
|
8641
|
-
result.push({
|
|
8642
|
-
text: segment.text,
|
|
8643
|
-
attributes: Object.keys(nextAttributes).length === 0 ? void 0 : freeze(nextAttributes)
|
|
8644
|
-
});
|
|
8645
|
-
} else {
|
|
8646
|
-
result.push(segment);
|
|
8647
|
-
}
|
|
8648
|
-
offset = end;
|
|
8649
|
-
}
|
|
8650
|
-
return normalizeSegments(result);
|
|
8651
|
-
}
|
|
8652
|
-
function formatReverseOperations(segments, index, length, patch) {
|
|
8653
|
-
const split = splitSegmentsAt(
|
|
8654
|
-
splitSegmentsAt(segments, index),
|
|
8655
|
-
index + length
|
|
8656
|
-
);
|
|
8657
|
-
const result = [];
|
|
8658
|
-
let offset = 0;
|
|
8659
|
-
for (const segment of split) {
|
|
8660
|
-
const end = offset + segment.text.length;
|
|
8661
|
-
if (offset >= index && end <= index + length) {
|
|
8662
|
-
const attributes = {};
|
|
8663
|
-
for (const key of Object.keys(patch)) {
|
|
8664
|
-
attributes[key] = segment.attributes?.[key] ?? null;
|
|
8665
|
-
}
|
|
8666
|
-
result.push({
|
|
8667
|
-
type: "format",
|
|
8668
|
-
index: offset,
|
|
8669
|
-
length: segment.text.length,
|
|
8670
|
-
attributes
|
|
8671
|
-
});
|
|
8672
|
-
}
|
|
8673
|
-
offset = end;
|
|
8674
|
-
}
|
|
8675
|
-
return result;
|
|
8676
|
-
}
|
|
8677
|
-
function mapIndexThroughOperation(index, op) {
|
|
8678
|
-
if (op.type === "insert") {
|
|
8679
|
-
return op.index <= index ? index + op.text.length : index;
|
|
8680
|
-
} else if (op.type === "delete") {
|
|
8681
|
-
if (op.index >= index) {
|
|
8682
|
-
return index;
|
|
8683
|
-
}
|
|
8684
|
-
return Math.max(op.index, index - op.length);
|
|
8685
|
-
} else {
|
|
8686
|
-
return index;
|
|
8687
|
-
}
|
|
8688
|
-
}
|
|
8689
|
-
function mapTextIndexThroughOperations(index, ops) {
|
|
8690
|
-
let mapped = index;
|
|
8691
|
-
for (const op of ops) {
|
|
8692
|
-
mapped = mapIndexThroughOperation(mapped, op);
|
|
8693
|
-
}
|
|
8694
|
-
return mapped;
|
|
8695
|
-
}
|
|
8696
|
-
function rebaseTextOperations(ops, acceptedOps) {
|
|
8697
|
-
return ops.map((op) => {
|
|
8698
|
-
if (op.type === "insert") {
|
|
8699
|
-
return {
|
|
8700
|
-
...op,
|
|
8701
|
-
index: mapTextIndexThroughOperations(op.index, acceptedOps)
|
|
8702
|
-
};
|
|
8703
|
-
} else if (op.type === "delete" || op.type === "format") {
|
|
8704
|
-
const start = mapTextIndexThroughOperations(op.index, acceptedOps);
|
|
8705
|
-
const end = mapTextIndexThroughOperations(
|
|
8706
|
-
op.index + op.length,
|
|
8707
|
-
acceptedOps
|
|
8708
|
-
);
|
|
8709
|
-
return { ...op, index: start, length: Math.max(0, end - start) };
|
|
8710
|
-
} else {
|
|
8711
|
-
return op;
|
|
8712
|
-
}
|
|
8713
|
-
});
|
|
8714
|
-
}
|
|
8715
|
-
function applyTextOperationsToSegments(segments, ops) {
|
|
8716
|
-
let next = [...segments];
|
|
8717
|
-
for (const op of ops) {
|
|
8718
|
-
if (op.type === "insert") {
|
|
8719
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8720
|
-
next = applyInsert(next, index, op.text, op.attributes);
|
|
8721
|
-
} else if (op.type === "delete") {
|
|
8722
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8723
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8724
|
-
next = applyDelete(next, clipped.index, clipped.length).segments;
|
|
8725
|
-
} else {
|
|
8726
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8727
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8728
|
-
next = applyFormat(next, clipped.index, clipped.length, op.attributes);
|
|
8729
|
-
}
|
|
8730
|
-
}
|
|
8731
|
-
return next;
|
|
8732
|
-
}
|
|
8733
|
-
function applyLiveTextOperations(data, ops) {
|
|
8734
|
-
return segmentsToData(
|
|
8735
|
-
applyTextOperationsToSegments(dataToSegments(data), ops)
|
|
8736
|
-
);
|
|
8737
|
-
}
|
|
8738
|
-
function invertTextOperations(segments, ops) {
|
|
8739
|
-
let shadow = [...segments];
|
|
8740
|
-
const reverse = [];
|
|
8741
|
-
for (const op of ops) {
|
|
8742
|
-
if (op.type === "insert") {
|
|
8743
|
-
shadow = applyInsert(shadow, op.index, op.text, op.attributes);
|
|
8744
|
-
reverse.unshift({
|
|
8745
|
-
type: "delete",
|
|
8746
|
-
index: op.index,
|
|
8747
|
-
length: op.text.length
|
|
8748
|
-
});
|
|
8749
|
-
} else if (op.type === "delete") {
|
|
8750
|
-
const deletedSegments = extractDeletedSegments(
|
|
8751
|
-
shadow,
|
|
8752
|
-
op.index,
|
|
8753
|
-
op.length
|
|
8754
|
-
);
|
|
8755
|
-
shadow = applyDelete(shadow, op.index, op.length).segments;
|
|
8756
|
-
const inserts = [];
|
|
8757
|
-
let insertIndex = op.index;
|
|
8758
|
-
for (const segment of deletedSegments) {
|
|
8759
|
-
inserts.push({
|
|
8760
|
-
type: "insert",
|
|
8761
|
-
index: insertIndex,
|
|
8762
|
-
text: segment.text,
|
|
8763
|
-
attributes: segment.attributes
|
|
8764
|
-
});
|
|
8765
|
-
insertIndex += segment.text.length;
|
|
8766
|
-
}
|
|
8767
|
-
for (let index = inserts.length - 1; index >= 0; index--) {
|
|
8768
|
-
reverse.unshift(inserts[index]);
|
|
8769
|
-
}
|
|
8770
|
-
} else {
|
|
8771
|
-
const inverse = formatReverseOperations(
|
|
8772
|
-
shadow,
|
|
8773
|
-
op.index,
|
|
8774
|
-
op.length,
|
|
8775
|
-
op.attributes
|
|
8776
|
-
);
|
|
8777
|
-
shadow = applyFormat(shadow, op.index, op.length, op.attributes);
|
|
8778
|
-
reverse.unshift(...inverse.reverse());
|
|
8779
|
-
}
|
|
8780
|
-
}
|
|
8781
|
-
return reverse;
|
|
8782
|
-
}
|
|
8783
|
-
|
|
8784
|
-
// src/crdts/LiveText.ts
|
|
8785
|
-
var LiveText = class _LiveText extends AbstractCrdt {
|
|
8786
|
-
#segments;
|
|
8787
|
-
#version;
|
|
8788
|
-
#pendingOps;
|
|
8789
|
-
constructor(textOrData = "", version = 0) {
|
|
8790
|
-
super();
|
|
8791
|
-
this.#segments = typeof textOrData === "string" ? textOrData.length === 0 ? [] : [{ text: textOrData }] : dataToSegments(textOrData);
|
|
8792
|
-
this.#version = version;
|
|
8793
|
-
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8794
|
-
}
|
|
8795
|
-
get version() {
|
|
8796
|
-
return this.#version;
|
|
8797
|
-
}
|
|
8798
|
-
get length() {
|
|
8799
|
-
return this.toString().length;
|
|
8800
|
-
}
|
|
8801
|
-
/** @internal */
|
|
8802
|
-
static _deserialize([id, item], _parentToChildren, pool) {
|
|
8803
|
-
const text = new _LiveText(item.data, item.version);
|
|
8804
|
-
text._attach(id, pool);
|
|
8805
|
-
return text;
|
|
8806
|
-
}
|
|
8807
|
-
/** @internal */
|
|
8808
|
-
_toOps(parentId, parentKey) {
|
|
8809
|
-
if (this._id === void 0) {
|
|
8810
|
-
throw new Error("Cannot serialize LiveText if it is not attached");
|
|
8811
|
-
}
|
|
8812
|
-
return [
|
|
8813
|
-
{
|
|
8814
|
-
type: OpCode.CREATE_TEXT,
|
|
8815
|
-
id: this._id,
|
|
8816
|
-
parentId,
|
|
8817
|
-
parentKey,
|
|
8818
|
-
data: this.toJSON(),
|
|
8819
|
-
version: this.#version
|
|
8820
|
-
}
|
|
8821
|
-
];
|
|
8822
|
-
}
|
|
8823
|
-
/** @internal */
|
|
8824
|
-
_serialize() {
|
|
8825
|
-
if (this.parent.type !== "HasParent") {
|
|
8826
|
-
throw new Error("Cannot serialize LiveText if parent is missing");
|
|
8827
|
-
}
|
|
8828
|
-
return {
|
|
8829
|
-
type: CrdtType.TEXT,
|
|
8830
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8831
|
-
parentKey: this.parent.key,
|
|
8832
|
-
data: this.toJSON(),
|
|
8833
|
-
version: this.#version
|
|
8834
|
-
};
|
|
8835
|
-
}
|
|
8836
|
-
/** @internal */
|
|
8837
|
-
_attachChild(_op) {
|
|
8838
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8839
|
-
}
|
|
8840
|
-
/** @internal */
|
|
8841
|
-
_detachChild(_crdt) {
|
|
8842
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8843
|
-
}
|
|
8844
|
-
/** @internal */
|
|
8845
|
-
_apply(op, isLocal) {
|
|
8846
|
-
if (op.type !== OpCode.UPDATE_TEXT) {
|
|
8847
|
-
return super._apply(op, isLocal);
|
|
8848
|
-
}
|
|
8849
|
-
if (isLocal) {
|
|
8850
|
-
this.#pendingOps.set(nn(op.opId), op.ops);
|
|
8851
|
-
return this.#applyOperations(op.ops, op.version ?? this.#version);
|
|
8852
|
-
}
|
|
8853
|
-
if (op.opId !== void 0) {
|
|
8854
|
-
const pending2 = this.#pendingOps.get(op.opId);
|
|
8855
|
-
this.#pendingOps.delete(op.opId);
|
|
8856
|
-
const otherPending = Array.from(this.#pendingOps.values()).flat();
|
|
8857
|
-
if (pending2 !== void 0 && otherPending.length > 0) {
|
|
8858
|
-
this.#segments = applyTextOperationsToSegments(
|
|
8859
|
-
this.#segments,
|
|
8860
|
-
invertTextOperations(this.#segments, pending2)
|
|
8861
|
-
);
|
|
8862
|
-
const ops2 = rebaseTextOperations(op.ops, otherPending);
|
|
8863
|
-
return this.#applyOperations(
|
|
8864
|
-
ops2,
|
|
8865
|
-
op.version ?? Math.max(this.#version, op.baseVersion + 1)
|
|
8866
|
-
);
|
|
8867
|
-
}
|
|
8868
|
-
this.#version = op.version ?? Math.max(this.#version, op.baseVersion + 1);
|
|
8869
|
-
return { modified: false };
|
|
8870
|
-
}
|
|
8871
|
-
const pending = Array.from(this.#pendingOps.values()).flat();
|
|
8872
|
-
const ops = pending.length > 0 ? rebaseTextOperations(op.ops, pending) : op.ops;
|
|
8873
|
-
return this.#applyOperations(ops, op.version ?? this.#version + 1);
|
|
8874
|
-
}
|
|
8875
|
-
insert(index, text, attributes) {
|
|
8876
|
-
const clippedIndex = Math.max(0, Math.min(index, this.length));
|
|
8877
|
-
this.#dispatch([{ type: "insert", index: clippedIndex, text, attributes }]);
|
|
8878
|
-
}
|
|
8879
|
-
delete(index, length) {
|
|
8880
|
-
const clipped = clipRange(index, length, this.length);
|
|
8881
|
-
if (clipped.length === 0) {
|
|
8882
|
-
return;
|
|
8883
|
-
}
|
|
8884
|
-
this.#dispatch([
|
|
8885
|
-
{ type: "delete", index: clipped.index, length: clipped.length }
|
|
8886
|
-
]);
|
|
8887
|
-
}
|
|
8888
|
-
replace(index, length, text, attributes) {
|
|
8889
|
-
const clipped = clipRange(index, length, this.length);
|
|
8890
|
-
const ops = [];
|
|
8891
|
-
if (clipped.length > 0) {
|
|
8892
|
-
ops.push({
|
|
8893
|
-
type: "delete",
|
|
8894
|
-
index: clipped.index,
|
|
8895
|
-
length: clipped.length
|
|
8896
|
-
});
|
|
8897
|
-
}
|
|
8898
|
-
if (text.length > 0) {
|
|
8899
|
-
ops.push({ type: "insert", index: clipped.index, text, attributes });
|
|
8900
|
-
}
|
|
8901
|
-
this.#dispatch(ops);
|
|
8902
|
-
}
|
|
8903
|
-
format(index, length, attributes) {
|
|
8904
|
-
const clipped = clipRange(index, length, this.length);
|
|
8905
|
-
if (clipped.length === 0) {
|
|
8906
|
-
return;
|
|
8907
|
-
}
|
|
8908
|
-
this.#dispatch([
|
|
8909
|
-
{
|
|
8910
|
-
type: "format",
|
|
8911
|
-
index: clipped.index,
|
|
8912
|
-
length: clipped.length,
|
|
8913
|
-
attributes
|
|
8914
|
-
}
|
|
8915
|
-
]);
|
|
8916
|
-
}
|
|
8917
|
-
#dispatch(ops) {
|
|
8918
|
-
if (ops.length === 0) {
|
|
8919
|
-
return;
|
|
8920
|
-
}
|
|
8921
|
-
this._pool?.assertStorageIsWritable();
|
|
8922
|
-
const baseVersion = this.#version;
|
|
8923
|
-
const reverse = this._pool !== void 0 && this._id !== void 0 ? this.#invertOperations(ops) : [];
|
|
8924
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8925
|
-
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8926
|
-
const opId = this._pool.generateOpId();
|
|
8927
|
-
this.#pendingOps.set(opId, ops);
|
|
8928
|
-
this._pool.dispatch(
|
|
8929
|
-
[
|
|
8930
|
-
{
|
|
8931
|
-
type: OpCode.UPDATE_TEXT,
|
|
8932
|
-
id: this._id,
|
|
8933
|
-
opId,
|
|
8934
|
-
baseVersion,
|
|
8935
|
-
ops: [...ops]
|
|
8936
|
-
}
|
|
8937
|
-
],
|
|
8938
|
-
reverse,
|
|
8939
|
-
/* @__PURE__ */ new Map([
|
|
8940
|
-
[
|
|
8941
|
-
this._id,
|
|
8942
|
-
{
|
|
8943
|
-
type: "LiveText",
|
|
8944
|
-
node: this,
|
|
8945
|
-
version: this.#version,
|
|
8946
|
-
updates: changes
|
|
8947
|
-
}
|
|
8948
|
-
]
|
|
8949
|
-
])
|
|
8950
|
-
);
|
|
8951
|
-
}
|
|
8952
|
-
}
|
|
8953
|
-
#applyOperations(ops, version) {
|
|
8954
|
-
const reverse = this.#invertOperations(ops);
|
|
8955
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8956
|
-
this.#version = Math.max(this.#version, version);
|
|
8957
|
-
return {
|
|
8958
|
-
reverse,
|
|
8959
|
-
modified: {
|
|
8960
|
-
type: "LiveText",
|
|
8961
|
-
node: this,
|
|
8962
|
-
version: this.#version,
|
|
8963
|
-
updates: changes
|
|
8964
|
-
}
|
|
8965
|
-
};
|
|
8966
|
-
}
|
|
8967
|
-
#applyOperationsLocally(ops) {
|
|
8968
|
-
const changes = [];
|
|
8969
|
-
for (const op of ops) {
|
|
8970
|
-
if (op.type === "insert") {
|
|
8971
|
-
this.#segments = applyInsert(
|
|
8972
|
-
this.#segments,
|
|
8973
|
-
op.index,
|
|
8974
|
-
op.text,
|
|
8975
|
-
op.attributes
|
|
8976
|
-
);
|
|
8977
|
-
changes.push({
|
|
8978
|
-
type: "insert",
|
|
8979
|
-
index: op.index,
|
|
8980
|
-
text: op.text,
|
|
8981
|
-
attributes: op.attributes
|
|
8982
|
-
});
|
|
8983
|
-
} else if (op.type === "delete") {
|
|
8984
|
-
const result = applyDelete(this.#segments, op.index, op.length);
|
|
8985
|
-
this.#segments = result.segments;
|
|
8986
|
-
changes.push({
|
|
8987
|
-
type: "delete",
|
|
8988
|
-
index: op.index,
|
|
8989
|
-
length: op.length,
|
|
8990
|
-
deletedText: result.deletedText
|
|
8991
|
-
});
|
|
8992
|
-
} else {
|
|
8993
|
-
this.#segments = applyFormat(
|
|
8994
|
-
this.#segments,
|
|
8995
|
-
op.index,
|
|
8996
|
-
op.length,
|
|
8997
|
-
op.attributes
|
|
8998
|
-
);
|
|
8999
|
-
changes.push({
|
|
9000
|
-
type: "format",
|
|
9001
|
-
index: op.index,
|
|
9002
|
-
length: op.length,
|
|
9003
|
-
attributes: op.attributes
|
|
9004
|
-
});
|
|
9005
|
-
}
|
|
9006
|
-
}
|
|
9007
|
-
this.invalidate();
|
|
9008
|
-
return changes;
|
|
9009
|
-
}
|
|
9010
|
-
#invertOperations(ops) {
|
|
9011
|
-
return [
|
|
9012
|
-
{
|
|
9013
|
-
type: OpCode.UPDATE_TEXT,
|
|
9014
|
-
id: nn(this._id),
|
|
9015
|
-
baseVersion: this.#version,
|
|
9016
|
-
ops: invertTextOperations(this.#segments, ops)
|
|
9017
|
-
}
|
|
9018
|
-
];
|
|
9019
|
-
}
|
|
9020
|
-
toString() {
|
|
9021
|
-
return this.#segments.map((segment) => segment.text).join("");
|
|
9022
|
-
}
|
|
9023
|
-
toJSON() {
|
|
9024
|
-
return super.toJSON();
|
|
9025
|
-
}
|
|
9026
|
-
/** @internal */
|
|
9027
|
-
_toJSON() {
|
|
9028
|
-
return segmentsToData(this.#segments);
|
|
9029
|
-
}
|
|
9030
|
-
/** @internal */
|
|
9031
|
-
_toTreeNode(key) {
|
|
9032
|
-
return {
|
|
9033
|
-
type: "LiveText",
|
|
9034
|
-
id: this._id ?? nanoid(),
|
|
9035
|
-
key,
|
|
9036
|
-
payload: [
|
|
9037
|
-
{
|
|
9038
|
-
type: "Json",
|
|
9039
|
-
id: `${this._id ?? nanoid()}:text`,
|
|
9040
|
-
key: "text",
|
|
9041
|
-
payload: this.toString()
|
|
9042
|
-
}
|
|
9043
|
-
]
|
|
9044
|
-
};
|
|
9045
|
-
}
|
|
9046
|
-
clone() {
|
|
9047
|
-
return new _LiveText(this.toJSON(), this.#version);
|
|
9048
|
-
}
|
|
9049
|
-
};
|
|
9050
|
-
|
|
9051
8455
|
// src/crdts/liveblocks-helpers.ts
|
|
9052
8456
|
function creationOpToLiveNode(op) {
|
|
9053
8457
|
return lsonToLiveNode(creationOpToLson(op));
|
|
@@ -9062,8 +8466,6 @@ function creationOpToLson(op) {
|
|
|
9062
8466
|
return new LiveMap();
|
|
9063
8467
|
case OpCode.CREATE_LIST:
|
|
9064
8468
|
return new LiveList([]);
|
|
9065
|
-
case OpCode.CREATE_TEXT:
|
|
9066
|
-
return new LiveText(op.data, op.version);
|
|
9067
8469
|
default:
|
|
9068
8470
|
return assertNever(op, "Unknown creation Op");
|
|
9069
8471
|
}
|
|
@@ -9086,8 +8488,6 @@ function deserialize(node, parentToChildren, pool) {
|
|
|
9086
8488
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9087
8489
|
} else if (isRegisterStorageNode(node)) {
|
|
9088
8490
|
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
9089
|
-
} else if (isTextStorageNode(node)) {
|
|
9090
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9091
8491
|
} else {
|
|
9092
8492
|
throw new Error("Unexpected CRDT type");
|
|
9093
8493
|
}
|
|
@@ -9101,14 +8501,12 @@ function deserializeToLson(node, parentToChildren, pool) {
|
|
|
9101
8501
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9102
8502
|
} else if (isRegisterStorageNode(node)) {
|
|
9103
8503
|
return node[1].data;
|
|
9104
|
-
} else if (isTextStorageNode(node)) {
|
|
9105
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9106
8504
|
} else {
|
|
9107
8505
|
throw new Error("Unexpected CRDT type");
|
|
9108
8506
|
}
|
|
9109
8507
|
}
|
|
9110
8508
|
function isLiveStructure(value) {
|
|
9111
|
-
return isLiveList(value) || isLiveMap(value) || isLiveObject(value)
|
|
8509
|
+
return isLiveList(value) || isLiveMap(value) || isLiveObject(value);
|
|
9112
8510
|
}
|
|
9113
8511
|
function isLiveNode(value) {
|
|
9114
8512
|
return isLiveStructure(value) || isLiveRegister(value);
|
|
@@ -9122,9 +8520,6 @@ function isLiveMap(value) {
|
|
|
9122
8520
|
function isLiveObject(value) {
|
|
9123
8521
|
return value instanceof LiveObject;
|
|
9124
8522
|
}
|
|
9125
|
-
function isLiveText(value) {
|
|
9126
|
-
return value instanceof LiveText;
|
|
9127
|
-
}
|
|
9128
8523
|
function isLiveRegister(value) {
|
|
9129
8524
|
return value instanceof LiveRegister;
|
|
9130
8525
|
}
|
|
@@ -9134,73 +8529,19 @@ function cloneLson(value) {
|
|
|
9134
8529
|
function liveNodeToLson(obj) {
|
|
9135
8530
|
if (obj instanceof LiveRegister) {
|
|
9136
8531
|
return obj.data;
|
|
9137
|
-
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject
|
|
8532
|
+
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject) {
|
|
9138
8533
|
return obj;
|
|
9139
8534
|
} else {
|
|
9140
8535
|
return assertNever(obj, "Unknown AbstractCrdt");
|
|
9141
8536
|
}
|
|
9142
8537
|
}
|
|
9143
8538
|
function lsonToLiveNode(value) {
|
|
9144
|
-
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList
|
|
8539
|
+
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList) {
|
|
9145
8540
|
return value;
|
|
9146
8541
|
} else {
|
|
9147
8542
|
return new LiveRegister(value);
|
|
9148
8543
|
}
|
|
9149
8544
|
}
|
|
9150
|
-
function dumpPool(pool) {
|
|
9151
|
-
const rows = Array.from(pool.nodes.values(), (node) => {
|
|
9152
|
-
const parent = node.parent;
|
|
9153
|
-
const parentId = parent.type === "HasParent" ? parent.node._id ?? "?" : parent.type === "Orphaned" ? "<orphaned>" : "-";
|
|
9154
|
-
let value;
|
|
9155
|
-
if (node instanceof LiveRegister) {
|
|
9156
|
-
value = stringifyOrLog(node.data);
|
|
9157
|
-
} else if (node instanceof LiveList) {
|
|
9158
|
-
value = "<LiveList>";
|
|
9159
|
-
} else if (node instanceof LiveMap) {
|
|
9160
|
-
value = "<LiveMap>";
|
|
9161
|
-
} else {
|
|
9162
|
-
value = "<LiveObject>";
|
|
9163
|
-
}
|
|
9164
|
-
return { id: nn(node._id), parentId, key: node._parentKey ?? "", value };
|
|
9165
|
-
});
|
|
9166
|
-
rows.sort((a, b) => {
|
|
9167
|
-
if (a.parentId !== b.parentId) return a.parentId < b.parentId ? -1 : 1;
|
|
9168
|
-
if (a.key !== b.key) return a.key < b.key ? -1 : 1;
|
|
9169
|
-
return 0;
|
|
9170
|
-
});
|
|
9171
|
-
return rows.map(
|
|
9172
|
-
(r) => ` ${r.id} parent=${r.parentId} key=${r.key || "\u2014"} ${r.value}`
|
|
9173
|
-
).join("\n");
|
|
9174
|
-
}
|
|
9175
|
-
function isJsonEq(a, b) {
|
|
9176
|
-
if (a === b) {
|
|
9177
|
-
return true;
|
|
9178
|
-
}
|
|
9179
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
9180
|
-
return false;
|
|
9181
|
-
}
|
|
9182
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
9183
|
-
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
9184
|
-
return false;
|
|
9185
|
-
}
|
|
9186
|
-
for (let i = 0; i < a.length; i++) {
|
|
9187
|
-
if (!isJsonEq(a[i], b[i])) {
|
|
9188
|
-
return false;
|
|
9189
|
-
}
|
|
9190
|
-
}
|
|
9191
|
-
return true;
|
|
9192
|
-
}
|
|
9193
|
-
const aKeys = Object.keys(a);
|
|
9194
|
-
if (aKeys.length !== Object.keys(b).length) {
|
|
9195
|
-
return false;
|
|
9196
|
-
}
|
|
9197
|
-
for (const key of aKeys) {
|
|
9198
|
-
if (!isJsonEq(a[key], b[key])) {
|
|
9199
|
-
return false;
|
|
9200
|
-
}
|
|
9201
|
-
}
|
|
9202
|
-
return true;
|
|
9203
|
-
}
|
|
9204
8545
|
function getTreesDiffOperations(currentItems, newItems) {
|
|
9205
8546
|
const ops = [];
|
|
9206
8547
|
currentItems.forEach((_, id) => {
|
|
@@ -9212,61 +8553,11 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9212
8553
|
const currentCrdt = currentItems.get(id);
|
|
9213
8554
|
if (currentCrdt) {
|
|
9214
8555
|
if (crdt.type === CrdtType.OBJECT) {
|
|
9215
|
-
if (currentCrdt.type !== CrdtType.OBJECT) {
|
|
9216
|
-
ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
|
|
9217
|
-
} else {
|
|
9218
|
-
const changed = /* @__PURE__ */ new Map();
|
|
9219
|
-
for (const key of Object.keys(crdt.data)) {
|
|
9220
|
-
const value = crdt.data[key];
|
|
9221
|
-
if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
|
|
9222
|
-
changed.set(key, value);
|
|
9223
|
-
}
|
|
9224
|
-
}
|
|
9225
|
-
if (changed.size > 0) {
|
|
9226
|
-
ops.push({
|
|
9227
|
-
type: OpCode.UPDATE_OBJECT,
|
|
9228
|
-
id,
|
|
9229
|
-
data: Object.fromEntries(changed)
|
|
9230
|
-
});
|
|
9231
|
-
}
|
|
9232
|
-
for (const key of Object.keys(currentCrdt.data)) {
|
|
9233
|
-
if (!(key in crdt.data)) {
|
|
9234
|
-
ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
9235
|
-
}
|
|
9236
|
-
}
|
|
9237
|
-
}
|
|
9238
|
-
}
|
|
9239
|
-
if (crdt.type === CrdtType.TEXT) {
|
|
9240
|
-
if (currentCrdt.type !== CrdtType.TEXT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data) || crdt.version !== currentCrdt.version) {
|
|
8556
|
+
if (currentCrdt.type !== CrdtType.OBJECT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data)) {
|
|
9241
8557
|
ops.push({
|
|
9242
|
-
type: OpCode.
|
|
8558
|
+
type: OpCode.UPDATE_OBJECT,
|
|
9243
8559
|
id,
|
|
9244
|
-
|
|
9245
|
-
version: crdt.version,
|
|
9246
|
-
ops: [
|
|
9247
|
-
{
|
|
9248
|
-
type: "delete",
|
|
9249
|
-
index: 0,
|
|
9250
|
-
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9251
|
-
(sum, segment) => sum + segment[0].length,
|
|
9252
|
-
0
|
|
9253
|
-
) : 0
|
|
9254
|
-
},
|
|
9255
|
-
...crdt.data.map((segment, index, items) => {
|
|
9256
|
-
const [text, attributes] = segment;
|
|
9257
|
-
const insertIndex = items.slice(0, index).reduce((sum, item) => sum + item[0].length, 0);
|
|
9258
|
-
return attributes === void 0 ? {
|
|
9259
|
-
type: "insert",
|
|
9260
|
-
index: insertIndex,
|
|
9261
|
-
text
|
|
9262
|
-
} : {
|
|
9263
|
-
type: "insert",
|
|
9264
|
-
index: insertIndex,
|
|
9265
|
-
text,
|
|
9266
|
-
attributes
|
|
9267
|
-
};
|
|
9268
|
-
})
|
|
9269
|
-
]
|
|
8560
|
+
data: crdt.data
|
|
9270
8561
|
});
|
|
9271
8562
|
}
|
|
9272
8563
|
}
|
|
@@ -9318,16 +8609,6 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9318
8609
|
parentKey: crdt.parentKey
|
|
9319
8610
|
});
|
|
9320
8611
|
break;
|
|
9321
|
-
case CrdtType.TEXT:
|
|
9322
|
-
ops.push({
|
|
9323
|
-
type: OpCode.CREATE_TEXT,
|
|
9324
|
-
id,
|
|
9325
|
-
parentId: crdt.parentId,
|
|
9326
|
-
parentKey: crdt.parentKey,
|
|
9327
|
-
data: crdt.data,
|
|
9328
|
-
version: crdt.version
|
|
9329
|
-
});
|
|
9330
|
-
break;
|
|
9331
8612
|
}
|
|
9332
8613
|
}
|
|
9333
8614
|
});
|
|
@@ -9360,12 +8641,6 @@ function mergeListStorageUpdates(first, second) {
|
|
|
9360
8641
|
updates: updates.concat(second.updates)
|
|
9361
8642
|
};
|
|
9362
8643
|
}
|
|
9363
|
-
function mergeTextStorageUpdates(first, second) {
|
|
9364
|
-
return {
|
|
9365
|
-
...second,
|
|
9366
|
-
updates: first.updates.concat(second.updates)
|
|
9367
|
-
};
|
|
9368
|
-
}
|
|
9369
8644
|
function mergeStorageUpdates(first, second) {
|
|
9370
8645
|
if (first === void 0) {
|
|
9371
8646
|
return second;
|
|
@@ -9376,8 +8651,6 @@ function mergeStorageUpdates(first, second) {
|
|
|
9376
8651
|
return mergeMapStorageUpdates(first, second);
|
|
9377
8652
|
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
9378
8653
|
return mergeListStorageUpdates(first, second);
|
|
9379
|
-
} else if (first.type === "LiveText" && second.type === "LiveText") {
|
|
9380
|
-
return mergeTextStorageUpdates(first, second);
|
|
9381
8654
|
} else {
|
|
9382
8655
|
}
|
|
9383
8656
|
return second;
|
|
@@ -9964,14 +9237,14 @@ var ClientMsgCode = Object.freeze({
|
|
|
9964
9237
|
// src/refs/ManagedOthers.ts
|
|
9965
9238
|
function makeUser(conn, presence) {
|
|
9966
9239
|
const { connectionId, id, info } = conn;
|
|
9967
|
-
const canWrite =
|
|
9240
|
+
const canWrite = hasPermissionCapability(conn.scopes, "storage", "write");
|
|
9968
9241
|
return freeze(
|
|
9969
9242
|
compactObject({
|
|
9970
9243
|
connectionId,
|
|
9971
9244
|
id,
|
|
9972
9245
|
info,
|
|
9973
9246
|
canWrite,
|
|
9974
|
-
canComment:
|
|
9247
|
+
canComment: hasPermissionCapability(conn.scopes, "comments", "write"),
|
|
9975
9248
|
isReadOnly: !canWrite,
|
|
9976
9249
|
// Deprecated, kept for backward-compatibility
|
|
9977
9250
|
presence
|
|
@@ -10278,7 +9551,6 @@ function createRoom(options, config) {
|
|
|
10278
9551
|
delegates,
|
|
10279
9552
|
config.enableDebugLogging
|
|
10280
9553
|
);
|
|
10281
|
-
const unacknowledgedOps = new UnacknowledgedOps();
|
|
10282
9554
|
const context = {
|
|
10283
9555
|
buffer: {
|
|
10284
9556
|
flushTimerID: void 0,
|
|
@@ -10306,15 +9578,14 @@ function createRoom(options, config) {
|
|
|
10306
9578
|
pool: createManagedPool(roomId, {
|
|
10307
9579
|
getCurrentConnectionId,
|
|
10308
9580
|
onDispatch,
|
|
10309
|
-
isStorageWritable
|
|
10310
|
-
unacknowledgedOps
|
|
9581
|
+
isStorageWritable
|
|
10311
9582
|
}),
|
|
10312
9583
|
root: void 0,
|
|
10313
9584
|
undoStack: [],
|
|
10314
9585
|
redoStack: [],
|
|
10315
9586
|
pausedHistory: null,
|
|
10316
9587
|
activeBatch: null,
|
|
10317
|
-
unacknowledgedOps
|
|
9588
|
+
unacknowledgedOps: /* @__PURE__ */ new Map()
|
|
10318
9589
|
};
|
|
10319
9590
|
const nodeMapBuffer = makeNodeMapBuffer();
|
|
10320
9591
|
const stopwatch = config.enableDebugLogging ? makeStopWatch() : void 0;
|
|
@@ -10381,7 +9652,6 @@ function createRoom(options, config) {
|
|
|
10381
9652
|
}
|
|
10382
9653
|
function onDidDisconnect() {
|
|
10383
9654
|
clearTimeout(context.buffer.flushTimerID);
|
|
10384
|
-
context.unacknowledgedOps.markAllAsPossiblyStored();
|
|
10385
9655
|
}
|
|
10386
9656
|
managedSocket.events.onMessage.subscribe(handleServerMessage);
|
|
10387
9657
|
managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
|
|
@@ -10428,7 +9698,7 @@ function createRoom(options, config) {
|
|
|
10428
9698
|
}
|
|
10429
9699
|
function isStorageWritable() {
|
|
10430
9700
|
const scopes = context.dynamicSessionInfoSig.get()?.scopes;
|
|
10431
|
-
return scopes !== void 0 ?
|
|
9701
|
+
return scopes !== void 0 ? hasPermissionCapability(scopes, "storage", "write") : true;
|
|
10432
9702
|
}
|
|
10433
9703
|
const eventHub = {
|
|
10434
9704
|
status: makeEventSource(),
|
|
@@ -10489,14 +9759,22 @@ function createRoom(options, config) {
|
|
|
10489
9759
|
if (staticSession === null || dynamicSession === null) {
|
|
10490
9760
|
return null;
|
|
10491
9761
|
} else {
|
|
10492
|
-
const canWrite =
|
|
9762
|
+
const canWrite = hasPermissionCapability(
|
|
9763
|
+
dynamicSession.scopes,
|
|
9764
|
+
"storage",
|
|
9765
|
+
"write"
|
|
9766
|
+
);
|
|
10493
9767
|
return {
|
|
10494
9768
|
connectionId: dynamicSession.actor,
|
|
10495
9769
|
id: staticSession.userId,
|
|
10496
9770
|
info: staticSession.userInfo,
|
|
10497
9771
|
presence: myPresence,
|
|
10498
9772
|
canWrite,
|
|
10499
|
-
canComment:
|
|
9773
|
+
canComment: hasPermissionCapability(
|
|
9774
|
+
dynamicSession.scopes,
|
|
9775
|
+
"comments",
|
|
9776
|
+
"write"
|
|
9777
|
+
)
|
|
10500
9778
|
};
|
|
10501
9779
|
}
|
|
10502
9780
|
}
|
|
@@ -10662,7 +9940,7 @@ function createRoom(options, config) {
|
|
|
10662
9940
|
);
|
|
10663
9941
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
10664
9942
|
}
|
|
10665
|
-
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT
|
|
9943
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
10666
9944
|
createdNodeIds.add(op.id);
|
|
10667
9945
|
}
|
|
10668
9946
|
}
|
|
@@ -10682,7 +9960,6 @@ function createRoom(options, config) {
|
|
|
10682
9960
|
switch (op.type) {
|
|
10683
9961
|
case OpCode.DELETE_OBJECT_KEY:
|
|
10684
9962
|
case OpCode.UPDATE_OBJECT:
|
|
10685
|
-
case OpCode.UPDATE_TEXT:
|
|
10686
9963
|
case OpCode.DELETE_CRDT: {
|
|
10687
9964
|
const node = context.pool.nodes.get(op.id);
|
|
10688
9965
|
if (node === void 0) {
|
|
@@ -10707,7 +9984,6 @@ function createRoom(options, config) {
|
|
|
10707
9984
|
case OpCode.CREATE_OBJECT:
|
|
10708
9985
|
case OpCode.CREATE_LIST:
|
|
10709
9986
|
case OpCode.CREATE_MAP:
|
|
10710
|
-
case OpCode.CREATE_TEXT:
|
|
10711
9987
|
case OpCode.CREATE_REGISTER: {
|
|
10712
9988
|
if (op.parentId === void 0) {
|
|
10713
9989
|
return { modified: false };
|
|
@@ -10856,11 +10132,12 @@ function createRoom(options, config) {
|
|
|
10856
10132
|
}
|
|
10857
10133
|
}
|
|
10858
10134
|
function applyAndSendOfflineOps(unackedOps) {
|
|
10859
|
-
if (unackedOps.
|
|
10135
|
+
if (unackedOps.size === 0) {
|
|
10860
10136
|
return;
|
|
10861
10137
|
}
|
|
10862
10138
|
const messages = [];
|
|
10863
|
-
const
|
|
10139
|
+
const inOps = Array.from(unackedOps.values());
|
|
10140
|
+
const result = applyLocalOps(inOps);
|
|
10864
10141
|
messages.push({
|
|
10865
10142
|
type: ClientMsgCode.UPDATE_STORAGE,
|
|
10866
10143
|
ops: result.opsToEmit
|
|
@@ -11084,7 +10361,7 @@ function createRoom(options, config) {
|
|
|
11084
10361
|
const storageOps = context.buffer.storageOperations;
|
|
11085
10362
|
if (storageOps.length > 0) {
|
|
11086
10363
|
for (const op of storageOps) {
|
|
11087
|
-
context.unacknowledgedOps.
|
|
10364
|
+
context.unacknowledgedOps.set(op.opId, op);
|
|
11088
10365
|
}
|
|
11089
10366
|
notifyStorageStatus();
|
|
11090
10367
|
}
|
|
@@ -11311,9 +10588,9 @@ function createRoom(options, config) {
|
|
|
11311
10588
|
}
|
|
11312
10589
|
}
|
|
11313
10590
|
function processInitialStorage(nodes) {
|
|
11314
|
-
const
|
|
10591
|
+
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
11315
10592
|
createOrUpdateRootFromMessage(nodes);
|
|
11316
|
-
applyAndSendOfflineOps(
|
|
10593
|
+
applyAndSendOfflineOps(unacknowledgedOps);
|
|
11317
10594
|
_resolveStoragePromise?.();
|
|
11318
10595
|
notifyStorageStatus();
|
|
11319
10596
|
eventHub.storageDidLoad.notify();
|
|
@@ -11902,11 +11179,6 @@ function createRoom(options, config) {
|
|
|
11902
11179
|
connect: () => managedSocket.connect(),
|
|
11903
11180
|
reconnect: () => managedSocket.reconnect(),
|
|
11904
11181
|
disconnect: () => managedSocket.disconnect(),
|
|
11905
|
-
_dump: () => {
|
|
11906
|
-
const n = context.pool.nodes.size;
|
|
11907
|
-
return `Room "${roomId}" (${n} node${n === 1 ? "" : "s"}):
|
|
11908
|
-
${dumpPool(context.pool)}`;
|
|
11909
|
-
},
|
|
11910
11182
|
destroy: () => {
|
|
11911
11183
|
pendingFeedsRequests.forEach(
|
|
11912
11184
|
(request) => request.reject(new Error("Room destroyed"))
|
|
@@ -12098,7 +11370,11 @@ function isRoomEventName(value) {
|
|
|
12098
11370
|
}
|
|
12099
11371
|
function makeAuthDelegateForRoom(roomId, authManager) {
|
|
12100
11372
|
return async () => {
|
|
12101
|
-
return authManager.getAuthValue({
|
|
11373
|
+
return authManager.getAuthValue({
|
|
11374
|
+
roomId,
|
|
11375
|
+
resource: "presence",
|
|
11376
|
+
access: "read"
|
|
11377
|
+
});
|
|
12102
11378
|
};
|
|
12103
11379
|
}
|
|
12104
11380
|
function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
|
|
@@ -12188,7 +11464,9 @@ function createClient(options) {
|
|
|
12188
11464
|
),
|
|
12189
11465
|
authenticate: async () => {
|
|
12190
11466
|
const resp = await authManager.getAuthValue({
|
|
12191
|
-
|
|
11467
|
+
// TODO: Should we have permissions for AI Copilots?
|
|
11468
|
+
resource: "personal",
|
|
11469
|
+
access: "write"
|
|
12192
11470
|
});
|
|
12193
11471
|
if (resp.type === "public") {
|
|
12194
11472
|
throw new StopRetrying(
|
|
@@ -12414,7 +11692,6 @@ function createClient(options) {
|
|
|
12414
11692
|
{
|
|
12415
11693
|
enterRoom,
|
|
12416
11694
|
getRoom,
|
|
12417
|
-
_dump: () => Array.from(roomsById.values(), ({ room }) => room._dump()).join("\n\n"),
|
|
12418
11695
|
logout,
|
|
12419
11696
|
// Public inbox notifications API
|
|
12420
11697
|
getInboxNotifications: httpClient.getInboxNotifications,
|
|
@@ -12867,12 +12144,6 @@ function toPlainLson(lson) {
|
|
|
12867
12144
|
liveblocksType: "LiveList",
|
|
12868
12145
|
data: [...lson].map((item) => toPlainLson(item))
|
|
12869
12146
|
};
|
|
12870
|
-
} else if (lson instanceof LiveText) {
|
|
12871
|
-
return {
|
|
12872
|
-
liveblocksType: "LiveText",
|
|
12873
|
-
data: lson.toJSON(),
|
|
12874
|
-
version: lson.version
|
|
12875
|
-
};
|
|
12876
12147
|
} else {
|
|
12877
12148
|
return lson;
|
|
12878
12149
|
}
|
|
@@ -13054,7 +12325,6 @@ export {
|
|
|
13054
12325
|
LiveList,
|
|
13055
12326
|
LiveMap,
|
|
13056
12327
|
LiveObject,
|
|
13057
|
-
LiveText,
|
|
13058
12328
|
LiveblocksError,
|
|
13059
12329
|
MENTION_CHARACTER,
|
|
13060
12330
|
MutableSignal,
|
|
@@ -13066,7 +12336,6 @@ export {
|
|
|
13066
12336
|
SortedList,
|
|
13067
12337
|
TextEditorType,
|
|
13068
12338
|
WebsocketCloseCodes,
|
|
13069
|
-
applyLiveTextOperations,
|
|
13070
12339
|
asPos,
|
|
13071
12340
|
assert,
|
|
13072
12341
|
assertNever,
|
|
@@ -13093,7 +12362,6 @@ export {
|
|
|
13093
12362
|
createManagedPool,
|
|
13094
12363
|
createNotificationSettings,
|
|
13095
12364
|
createThreadId,
|
|
13096
|
-
deepLiveify,
|
|
13097
12365
|
defineAiTool,
|
|
13098
12366
|
deprecate,
|
|
13099
12367
|
deprecateIf,
|
|
@@ -13104,7 +12372,10 @@ export {
|
|
|
13104
12372
|
freeze,
|
|
13105
12373
|
generateUrl,
|
|
13106
12374
|
getMentionsFromCommentBody,
|
|
12375
|
+
getRoomPermissionConflicts,
|
|
13107
12376
|
getSubscriptionKey,
|
|
12377
|
+
hasPermissionCapability,
|
|
12378
|
+
hasPermissionCapabilityAccess,
|
|
13108
12379
|
html,
|
|
13109
12380
|
htmlSafe,
|
|
13110
12381
|
isCommentBodyLink,
|
|
@@ -13123,7 +12394,6 @@ export {
|
|
|
13123
12394
|
isRegisterStorageNode,
|
|
13124
12395
|
isRootStorageNode,
|
|
13125
12396
|
isStartsWithOperator,
|
|
13126
|
-
isTextStorageNode,
|
|
13127
12397
|
isUrl,
|
|
13128
12398
|
kInternal,
|
|
13129
12399
|
keys,
|
|
@@ -13136,8 +12406,12 @@ export {
|
|
|
13136
12406
|
nanoid,
|
|
13137
12407
|
nn,
|
|
13138
12408
|
nodeStreamToCompactNodes,
|
|
12409
|
+
normalizeRoomAccessesInput,
|
|
12410
|
+
normalizeRoomAccessesUpdateInput,
|
|
12411
|
+
normalizeRoomPermissionInput,
|
|
13139
12412
|
objectToQuery,
|
|
13140
12413
|
patchNotificationSettings,
|
|
12414
|
+
permissionCapabilitiesFromScopes,
|
|
13141
12415
|
raise,
|
|
13142
12416
|
resolveMentionsInCommentBody,
|
|
13143
12417
|
sanitizeUrl,
|