@liveblocks/core 3.20.0-exp5 → 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 +645 -1348
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -191
- package/dist/index.d.ts +88 -191
- package/dist/index.js +550 -1253
- 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,95 +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
|
-
#posKey(parentId, parentKey) {
|
|
5808
|
-
return `${parentId}
|
|
5809
|
-
${parentKey}`;
|
|
5810
|
-
}
|
|
5811
|
-
get size() {
|
|
5812
|
-
return this.#byOpId.size;
|
|
5813
|
-
}
|
|
5814
|
-
/**
|
|
5815
|
-
* Mark the given Op as still unacknowledged.
|
|
5816
|
-
*/
|
|
5817
|
-
add(op) {
|
|
5818
|
-
this.#byOpId.set(op.opId, op);
|
|
5819
|
-
if (isCreateOp(op)) {
|
|
5820
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5821
|
-
let atPosition = this.#createOpsByPosition.get(posKey);
|
|
5822
|
-
if (atPosition === void 0) {
|
|
5823
|
-
atPosition = /* @__PURE__ */ new Map();
|
|
5824
|
-
this.#createOpsByPosition.set(posKey, atPosition);
|
|
5825
|
-
}
|
|
5826
|
-
atPosition.set(op.opId, op);
|
|
5827
|
-
let inParent = this.#createOpsByParent.get(op.parentId);
|
|
5828
|
-
if (inParent === void 0) {
|
|
5829
|
-
inParent = /* @__PURE__ */ new Map();
|
|
5830
|
-
this.#createOpsByParent.set(op.parentId, inParent);
|
|
5831
|
-
}
|
|
5832
|
-
inParent.set(op.opId, op);
|
|
5833
|
-
}
|
|
5834
|
-
}
|
|
5835
|
-
/**
|
|
5836
|
-
* Drop the op with the given opId from the set, because the server has
|
|
5837
|
-
* acknowledged it (confirmed our own op, or signalled it was seen but
|
|
5838
|
-
* ignored).
|
|
5839
|
-
*/
|
|
5840
|
-
delete(opId) {
|
|
5841
|
-
const op = this.#byOpId.get(opId);
|
|
5842
|
-
if (op === void 0) {
|
|
5843
|
-
return;
|
|
5844
|
-
}
|
|
5845
|
-
this.#byOpId.delete(opId);
|
|
5846
|
-
if (isCreateOp(op)) {
|
|
5847
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5848
|
-
const atPosition = this.#createOpsByPosition.get(posKey);
|
|
5849
|
-
atPosition?.delete(opId);
|
|
5850
|
-
if (atPosition !== void 0 && atPosition.size === 0) {
|
|
5851
|
-
this.#createOpsByPosition.delete(posKey);
|
|
5852
|
-
}
|
|
5853
|
-
const inParent = this.#createOpsByParent.get(op.parentId);
|
|
5854
|
-
inParent?.delete(opId);
|
|
5855
|
-
if (inParent !== void 0 && inParent.size === 0) {
|
|
5856
|
-
this.#createOpsByParent.delete(op.parentId);
|
|
5857
|
-
}
|
|
5858
|
-
}
|
|
5859
|
-
}
|
|
5860
|
-
/**
|
|
5861
|
-
* The still-unacknowledged Create ops with the given `parentId` and
|
|
5862
|
-
* `parentKey` (targeting one exact position), in dispatch order. O(1) lookup.
|
|
5863
|
-
* Empty if none.
|
|
5864
|
-
*/
|
|
5865
|
-
getByParentIdAndKey(parentId, parentKey) {
|
|
5866
|
-
return this.#createOpsByPosition.get(this.#posKey(parentId, parentKey))?.values() ?? [];
|
|
5867
|
-
}
|
|
5868
|
-
/**
|
|
5869
|
-
* The still-unacknowledged Create ops with the given `parentId` (across all
|
|
5870
|
-
* positions), in dispatch order. O(1) lookup. Empty if none.
|
|
5871
|
-
*/
|
|
5872
|
-
getByParentId(parentId) {
|
|
5873
|
-
return this.#createOpsByParent.get(parentId)?.values() ?? [];
|
|
5874
|
-
}
|
|
5875
|
-
/** All still-unacknowledged ops, in dispatch order. */
|
|
5876
|
-
values() {
|
|
5877
|
-
return this.#byOpId.values();
|
|
5878
|
-
}
|
|
5879
|
-
};
|
|
5880
|
-
|
|
5881
5983
|
// src/crdts/AbstractCrdt.ts
|
|
5882
5984
|
function createManagedPool(roomId, options) {
|
|
5883
5985
|
const {
|
|
5884
5986
|
getCurrentConnectionId,
|
|
5885
5987
|
onDispatch,
|
|
5886
|
-
isStorageWritable = () => true
|
|
5887
|
-
unacknowledgedOps = new UnacknowledgedOps()
|
|
5988
|
+
isStorageWritable = () => true
|
|
5888
5989
|
} = options;
|
|
5889
5990
|
let clock = 0;
|
|
5890
5991
|
let opClock = 0;
|
|
@@ -5906,8 +6007,7 @@ function createManagedPool(roomId, options) {
|
|
|
5906
6007
|
"Cannot write to storage with a read only user, please ensure the user has write permissions"
|
|
5907
6008
|
);
|
|
5908
6009
|
}
|
|
5909
|
-
}
|
|
5910
|
-
unacknowledgedOps
|
|
6010
|
+
}
|
|
5911
6011
|
};
|
|
5912
6012
|
}
|
|
5913
6013
|
function crdtAsLiveNode(value) {
|
|
@@ -6189,9 +6289,11 @@ function childNodeLt(a, b) {
|
|
|
6189
6289
|
var LiveList = class _LiveList extends AbstractCrdt {
|
|
6190
6290
|
#items;
|
|
6191
6291
|
#implicitlyDeletedItems;
|
|
6292
|
+
#unacknowledgedSets;
|
|
6192
6293
|
constructor(items) {
|
|
6193
6294
|
super();
|
|
6194
6295
|
this.#implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
|
|
6296
|
+
this.#unacknowledgedSets = /* @__PURE__ */ new Map();
|
|
6195
6297
|
const nodes = [];
|
|
6196
6298
|
let lastPos;
|
|
6197
6299
|
for (const item of items) {
|
|
@@ -6221,13 +6323,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6221
6323
|
}
|
|
6222
6324
|
/**
|
|
6223
6325
|
* @internal
|
|
6224
|
-
*
|
|
6225
|
-
*
|
|
6226
|
-
*
|
|
6227
|
-
* 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
|
|
6228
6329
|
*
|
|
6229
|
-
* This is quite unintuitive and should disappear as soon as
|
|
6230
|
-
* explicit LiveList.Set operation
|
|
6330
|
+
* This is quite unintuitive and should disappear as soon as
|
|
6331
|
+
* we introduce an explicit LiveList.Set operation
|
|
6231
6332
|
*/
|
|
6232
6333
|
_toOps(parentId, parentKey) {
|
|
6233
6334
|
if (this._id === void 0) {
|
|
@@ -6243,9 +6344,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6243
6344
|
ops.push(op);
|
|
6244
6345
|
for (const item of this.#items) {
|
|
6245
6346
|
const parentKey2 = item._getParentKeyOrThrow();
|
|
6246
|
-
const childOps =
|
|
6347
|
+
const childOps = HACK_addIntentAndDeletedIdToOperation(
|
|
6247
6348
|
item._toOps(this._id, parentKey2),
|
|
6248
|
-
|
|
6349
|
+
void 0
|
|
6249
6350
|
);
|
|
6250
6351
|
for (const childOp of childOps) {
|
|
6251
6352
|
ops.push(childOp);
|
|
@@ -6287,28 +6388,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6287
6388
|
(item) => item._getParentKeyOrThrow() === position
|
|
6288
6389
|
);
|
|
6289
6390
|
}
|
|
6290
|
-
/**
|
|
6291
|
-
* The opId of this list's still-unacknowledged "set" op at the given position,
|
|
6292
|
-
* or undefined if none. Derived from the room's unacknowledgedOps (the single
|
|
6293
|
-
* source of truth) rather than tracked in a per-instance map. The pool's
|
|
6294
|
-
* position index already scopes to this list's (parentId, position); the last
|
|
6295
|
-
* match wins, matching the original last-write-wins map semantics.
|
|
6296
|
-
*/
|
|
6297
|
-
#unacknowledgedSetOpIdAt(position) {
|
|
6298
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6299
|
-
return void 0;
|
|
6300
|
-
}
|
|
6301
|
-
let opId;
|
|
6302
|
-
for (const op of this._pool.unacknowledgedOps.getByParentIdAndKey(
|
|
6303
|
-
this._id,
|
|
6304
|
-
position
|
|
6305
|
-
)) {
|
|
6306
|
-
if (op.intent === "set") {
|
|
6307
|
-
opId = op.opId;
|
|
6308
|
-
}
|
|
6309
|
-
}
|
|
6310
|
-
return opId;
|
|
6311
|
-
}
|
|
6312
6391
|
/** @internal */
|
|
6313
6392
|
_attach(id, pool) {
|
|
6314
6393
|
super._attach(id, pool);
|
|
@@ -6389,9 +6468,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6389
6468
|
if (deletedDelta) {
|
|
6390
6469
|
delta.push(deletedDelta);
|
|
6391
6470
|
}
|
|
6392
|
-
const unacknowledgedOpId = this.#
|
|
6393
|
-
if (unacknowledgedOpId !== void 0
|
|
6394
|
-
|
|
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
|
+
}
|
|
6395
6478
|
}
|
|
6396
6479
|
const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
|
|
6397
6480
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
@@ -6472,7 +6555,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6472
6555
|
}
|
|
6473
6556
|
return result.modified.updates[0];
|
|
6474
6557
|
}
|
|
6475
|
-
#applyRemoteInsert(op
|
|
6558
|
+
#applyRemoteInsert(op) {
|
|
6476
6559
|
if (this._pool === void 0) {
|
|
6477
6560
|
throw new Error("Can't attach child if managed pool is not present");
|
|
6478
6561
|
}
|
|
@@ -6482,82 +6565,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6482
6565
|
this.#shiftItemPosition(existingItemIndex, key);
|
|
6483
6566
|
}
|
|
6484
6567
|
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
6485
|
-
const bumpDeltas = fromSnapshot ? [] : this.#bumpUnackedPushesAbove(key);
|
|
6486
6568
|
return {
|
|
6487
|
-
modified: makeUpdate(this, [
|
|
6488
|
-
insertDelta(newIndex, newItem),
|
|
6489
|
-
...bumpDeltas
|
|
6490
|
-
]),
|
|
6569
|
+
modified: makeUpdate(this, [insertDelta(newIndex, newItem)]),
|
|
6491
6570
|
reverse: []
|
|
6492
6571
|
};
|
|
6493
6572
|
}
|
|
6494
|
-
/**
|
|
6495
|
-
* This list's own still-unacknowledged pushed items (their `intent: "push"`
|
|
6496
|
-
* Create op is still pending in the room's unacknowledgedOps). Derived from
|
|
6497
|
-
* the single source of truth, so an item drops out the instant its op is
|
|
6498
|
-
* acked, with no per-instance membership to leak. Yielded in push order.
|
|
6499
|
-
*
|
|
6500
|
-
* Restricted to items currently in `#items`: a pushed node whose op is still
|
|
6501
|
-
* pending may have been pulled out of the list (e.g. implicitly deleted by a
|
|
6502
|
-
* remote set, or removed by an undo) while still living in the pool, and such
|
|
6503
|
-
* a node must not be repositioned.
|
|
6504
|
-
*/
|
|
6505
|
-
*#unackedPushNodes() {
|
|
6506
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6507
|
-
return;
|
|
6508
|
-
}
|
|
6509
|
-
for (const op of this._pool.unacknowledgedOps.getByParentId(this._id)) {
|
|
6510
|
-
if (op.intent !== "push") {
|
|
6511
|
-
continue;
|
|
6512
|
-
}
|
|
6513
|
-
const node = this._pool.getNode(op.id);
|
|
6514
|
-
if (node !== void 0 && this.#items.includes(node)) {
|
|
6515
|
-
yield node;
|
|
6516
|
-
}
|
|
6517
|
-
}
|
|
6518
|
-
}
|
|
6519
|
-
/**
|
|
6520
|
-
* Optimistic no-flip for pushed items. When a remote op lands at or below my
|
|
6521
|
-
* still-unacked pushed items, those items must end up *after* it: FIFO plus
|
|
6522
|
-
* the room's serial processing guarantee the remote was processed first, so
|
|
6523
|
-
* my unacked pushes belong behind it. Re-chain the whole unacked-push block,
|
|
6524
|
-
* in push order, to sit after the highest confirmed sibling, so it keeps
|
|
6525
|
-
* rendering as a contiguous tail instead of getting interleaved. Local-only;
|
|
6526
|
-
* the real acks overwrite these keys with the (identical) server keys.
|
|
6527
|
-
*/
|
|
6528
|
-
#bumpUnackedPushesAbove(remoteKey) {
|
|
6529
|
-
const pending = new Set(this.#unackedPushNodes());
|
|
6530
|
-
if (pending.size === 0) {
|
|
6531
|
-
return [];
|
|
6532
|
-
}
|
|
6533
|
-
let minPending;
|
|
6534
|
-
for (const node of pending) {
|
|
6535
|
-
const pos = node._parentPos;
|
|
6536
|
-
if (minPending === void 0 || pos < minPending) {
|
|
6537
|
-
minPending = pos;
|
|
6538
|
-
}
|
|
6539
|
-
}
|
|
6540
|
-
if (remoteKey < nn(minPending)) {
|
|
6541
|
-
return [];
|
|
6542
|
-
}
|
|
6543
|
-
let base;
|
|
6544
|
-
for (const item of this.#items) {
|
|
6545
|
-
if (!pending.has(item)) {
|
|
6546
|
-
base = item._parentPos;
|
|
6547
|
-
}
|
|
6548
|
-
}
|
|
6549
|
-
const deltas = [];
|
|
6550
|
-
for (const node of pending) {
|
|
6551
|
-
const previousIndex = this.#items.findIndex((item) => item === node);
|
|
6552
|
-
base = makePosition(base);
|
|
6553
|
-
this.#updateItemPosition(node, base);
|
|
6554
|
-
const index = this.#items.findIndex((item) => item === node);
|
|
6555
|
-
if (index !== previousIndex) {
|
|
6556
|
-
deltas.push(moveDelta(previousIndex, index, node));
|
|
6557
|
-
}
|
|
6558
|
-
}
|
|
6559
|
-
return deltas;
|
|
6560
|
-
}
|
|
6561
6573
|
#applyInsertAck(op) {
|
|
6562
6574
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
6563
6575
|
const key = asPos(op.parentKey);
|
|
@@ -6638,6 +6650,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6638
6650
|
if (this._pool?.getNode(id) !== void 0) {
|
|
6639
6651
|
return { modified: false };
|
|
6640
6652
|
}
|
|
6653
|
+
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
6641
6654
|
const indexOfItemWithSameKey = this._indexOfPosition(key);
|
|
6642
6655
|
child._attach(id, nn(this._pool));
|
|
6643
6656
|
child._setParentLink(this, key);
|
|
@@ -6647,9 +6660,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6647
6660
|
existingItem._detach();
|
|
6648
6661
|
this.#items.remove(existingItem);
|
|
6649
6662
|
this.#items.add(child);
|
|
6650
|
-
const reverse =
|
|
6663
|
+
const reverse = HACK_addIntentAndDeletedIdToOperation(
|
|
6651
6664
|
existingItem._toOps(nn(this._id), key),
|
|
6652
|
-
"set",
|
|
6653
6665
|
op.id
|
|
6654
6666
|
);
|
|
6655
6667
|
const delta = [setDelta(indexOfItemWithSameKey, child)];
|
|
@@ -6674,7 +6686,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6674
6686
|
}
|
|
6675
6687
|
}
|
|
6676
6688
|
/** @internal */
|
|
6677
|
-
_attachChild(op, source
|
|
6689
|
+
_attachChild(op, source) {
|
|
6678
6690
|
if (this._pool === void 0) {
|
|
6679
6691
|
throw new Error("Can't attach child if managed pool is not present");
|
|
6680
6692
|
}
|
|
@@ -6689,7 +6701,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6689
6701
|
}
|
|
6690
6702
|
} else {
|
|
6691
6703
|
if (source === 1 /* THEIRS */) {
|
|
6692
|
-
result = this.#applyRemoteInsert(op
|
|
6704
|
+
result = this.#applyRemoteInsert(op);
|
|
6693
6705
|
} else if (source === 2 /* OURS */) {
|
|
6694
6706
|
result = this.#applyInsertAck(op);
|
|
6695
6707
|
} else {
|
|
@@ -6892,7 +6904,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6892
6904
|
* @param element The element to add to the end of the LiveList.
|
|
6893
6905
|
*/
|
|
6894
6906
|
push(element) {
|
|
6895
|
-
|
|
6907
|
+
this._pool?.assertStorageIsWritable();
|
|
6908
|
+
return this.insert(element, this.length);
|
|
6896
6909
|
}
|
|
6897
6910
|
/**
|
|
6898
6911
|
* Inserts one element at a specified index.
|
|
@@ -6900,15 +6913,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6900
6913
|
* @param index The index at which you want to insert the element.
|
|
6901
6914
|
*/
|
|
6902
6915
|
insert(element, index) {
|
|
6903
|
-
return this.#injectAt(element, index, "insert");
|
|
6904
|
-
}
|
|
6905
|
-
/**
|
|
6906
|
-
* Shared implementation of `insert` and `push`. A `"push"` intent leaves the
|
|
6907
|
-
* client-computed position untouched (so optimistic rendering is unchanged),
|
|
6908
|
-
* but tags the Op so the server appends it to the true end of the list
|
|
6909
|
-
* instead of resolving its position against the client's stale view.
|
|
6910
|
-
*/
|
|
6911
|
-
#injectAt(element, index, intent) {
|
|
6912
6916
|
this._pool?.assertStorageIsWritable();
|
|
6913
6917
|
if (index < 0 || index > this.#items.length) {
|
|
6914
6918
|
throw new Error(
|
|
@@ -6924,9 +6928,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6924
6928
|
if (this._pool && this._id) {
|
|
6925
6929
|
const id = this._pool.generateId();
|
|
6926
6930
|
value._attach(id, this._pool);
|
|
6927
|
-
const ops = value._toOpsWithOpId(this._id, position, this._pool);
|
|
6928
6931
|
this._pool.dispatch(
|
|
6929
|
-
|
|
6932
|
+
value._toOpsWithOpId(this._id, position, this._pool),
|
|
6930
6933
|
[{ type: OpCode.DELETE_CRDT, id }],
|
|
6931
6934
|
/* @__PURE__ */ new Map([
|
|
6932
6935
|
[this._id, makeUpdate(this, [insertDelta(index, value)])]
|
|
@@ -7084,14 +7087,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7084
7087
|
value._attach(id, this._pool);
|
|
7085
7088
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7086
7089
|
storageUpdates.set(this._id, makeUpdate(this, [setDelta(index, value)]));
|
|
7087
|
-
const ops =
|
|
7090
|
+
const ops = HACK_addIntentAndDeletedIdToOperation(
|
|
7088
7091
|
value._toOpsWithOpId(this._id, position, this._pool),
|
|
7089
|
-
"set",
|
|
7090
7092
|
existingId
|
|
7091
7093
|
);
|
|
7092
|
-
|
|
7094
|
+
this.#unacknowledgedSets.set(position, nn(ops[0].opId));
|
|
7095
|
+
const reverseOps = HACK_addIntentAndDeletedIdToOperation(
|
|
7093
7096
|
existingItem._toOps(this._id, position),
|
|
7094
|
-
"set",
|
|
7095
7097
|
id
|
|
7096
7098
|
);
|
|
7097
7099
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
@@ -7292,11 +7294,15 @@ function moveDelta(previousIndex, index, item) {
|
|
|
7292
7294
|
previousIndex
|
|
7293
7295
|
};
|
|
7294
7296
|
}
|
|
7295
|
-
function
|
|
7297
|
+
function HACK_addIntentAndDeletedIdToOperation(ops, deletedId) {
|
|
7296
7298
|
return ops.map((op, index) => {
|
|
7297
7299
|
if (index === 0) {
|
|
7298
7300
|
const firstOp = op;
|
|
7299
|
-
return {
|
|
7301
|
+
return {
|
|
7302
|
+
...firstOp,
|
|
7303
|
+
intent: "set",
|
|
7304
|
+
deletedId
|
|
7305
|
+
};
|
|
7300
7306
|
} else {
|
|
7301
7307
|
return op;
|
|
7302
7308
|
}
|
|
@@ -7948,7 +7954,6 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7948
7954
|
const id = nn(this._id);
|
|
7949
7955
|
const parentKey = nn(child._parentKey);
|
|
7950
7956
|
const reverse = child._toOps(id, parentKey);
|
|
7951
|
-
const deletedItem = liveNodeToLson(child);
|
|
7952
7957
|
for (const [key, value] of this.#synced) {
|
|
7953
7958
|
if (value === child) {
|
|
7954
7959
|
this.#synced.delete(key);
|
|
@@ -7960,7 +7965,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7960
7965
|
node: this,
|
|
7961
7966
|
type: "LiveObject",
|
|
7962
7967
|
updates: {
|
|
7963
|
-
[parentKey]: { type: "delete"
|
|
7968
|
+
[parentKey]: { type: "delete" }
|
|
7964
7969
|
}
|
|
7965
7970
|
};
|
|
7966
7971
|
return { modified: storageUpdate, reverse };
|
|
@@ -8447,583 +8452,9 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
8447
8452
|
}
|
|
8448
8453
|
};
|
|
8449
8454
|
|
|
8450
|
-
// src/crdts/
|
|
8451
|
-
function
|
|
8452
|
-
|
|
8453
|
-
return true;
|
|
8454
|
-
}
|
|
8455
|
-
if (left === void 0 || right === void 0) {
|
|
8456
|
-
return false;
|
|
8457
|
-
}
|
|
8458
|
-
const leftKeys = Object.keys(left);
|
|
8459
|
-
const rightKeys = Object.keys(right);
|
|
8460
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
8461
|
-
return false;
|
|
8462
|
-
}
|
|
8463
|
-
for (const key of leftKeys) {
|
|
8464
|
-
if (left[key] !== right[key]) {
|
|
8465
|
-
return false;
|
|
8466
|
-
}
|
|
8467
|
-
}
|
|
8468
|
-
return true;
|
|
8469
|
-
}
|
|
8470
|
-
function cloneAttributes(attributes) {
|
|
8471
|
-
return attributes === void 0 ? void 0 : freeze({ ...attributes });
|
|
8472
|
-
}
|
|
8473
|
-
function normalizeSegments(segments) {
|
|
8474
|
-
const normalized = [];
|
|
8475
|
-
for (const segment of segments) {
|
|
8476
|
-
if (segment.text.length === 0) {
|
|
8477
|
-
continue;
|
|
8478
|
-
}
|
|
8479
|
-
const last = normalized.at(-1);
|
|
8480
|
-
const attributes = cloneAttributes(segment.attributes);
|
|
8481
|
-
if (last !== void 0 && attributesEqual(last.attributes, attributes)) {
|
|
8482
|
-
last.text += segment.text;
|
|
8483
|
-
} else {
|
|
8484
|
-
normalized.push({ text: segment.text, attributes });
|
|
8485
|
-
}
|
|
8486
|
-
}
|
|
8487
|
-
return normalized;
|
|
8488
|
-
}
|
|
8489
|
-
function dataToSegments(data) {
|
|
8490
|
-
return normalizeSegments(
|
|
8491
|
-
data.map(([text, attributes]) => ({
|
|
8492
|
-
text,
|
|
8493
|
-
attributes
|
|
8494
|
-
}))
|
|
8495
|
-
);
|
|
8496
|
-
}
|
|
8497
|
-
function segmentsToData(segments) {
|
|
8498
|
-
return segments.map(
|
|
8499
|
-
(segment) => segment.attributes === void 0 ? [segment.text] : [segment.text, { ...segment.attributes }]
|
|
8500
|
-
);
|
|
8501
|
-
}
|
|
8502
|
-
function textLength(segments) {
|
|
8503
|
-
return segments.reduce((sum, segment) => sum + segment.text.length, 0);
|
|
8504
|
-
}
|
|
8505
|
-
function splitSegmentsAt(segments, index) {
|
|
8506
|
-
const result = [];
|
|
8507
|
-
let offset = 0;
|
|
8508
|
-
for (const segment of segments) {
|
|
8509
|
-
const end = offset + segment.text.length;
|
|
8510
|
-
if (index > offset && index < end) {
|
|
8511
|
-
const before2 = segment.text.slice(0, index - offset);
|
|
8512
|
-
const after2 = segment.text.slice(index - offset);
|
|
8513
|
-
result.push({ text: before2, attributes: segment.attributes });
|
|
8514
|
-
result.push({ text: after2, attributes: segment.attributes });
|
|
8515
|
-
} else {
|
|
8516
|
-
result.push({ text: segment.text, attributes: segment.attributes });
|
|
8517
|
-
}
|
|
8518
|
-
offset = end;
|
|
8519
|
-
}
|
|
8520
|
-
return result;
|
|
8521
|
-
}
|
|
8522
|
-
function clipRange(index, length, contentLength) {
|
|
8523
|
-
const clippedIndex = Math.max(0, Math.min(index, contentLength));
|
|
8524
|
-
const clippedEnd = Math.max(
|
|
8525
|
-
clippedIndex,
|
|
8526
|
-
Math.min(index + length, contentLength)
|
|
8527
|
-
);
|
|
8528
|
-
return { index: clippedIndex, length: clippedEnd - clippedIndex };
|
|
8529
|
-
}
|
|
8530
|
-
function applyInsert(segments, index, text, attributes) {
|
|
8531
|
-
if (text.length === 0) {
|
|
8532
|
-
return normalizeSegments(segments);
|
|
8533
|
-
}
|
|
8534
|
-
const split = splitSegmentsAt(segments, index);
|
|
8535
|
-
const result = [];
|
|
8536
|
-
let offset = 0;
|
|
8537
|
-
let inserted = false;
|
|
8538
|
-
for (const segment of split) {
|
|
8539
|
-
if (!inserted && offset === index) {
|
|
8540
|
-
result.push({ text, attributes });
|
|
8541
|
-
inserted = true;
|
|
8542
|
-
}
|
|
8543
|
-
result.push(segment);
|
|
8544
|
-
offset += segment.text.length;
|
|
8545
|
-
}
|
|
8546
|
-
if (!inserted) {
|
|
8547
|
-
result.push({ text, attributes });
|
|
8548
|
-
}
|
|
8549
|
-
return normalizeSegments(result);
|
|
8550
|
-
}
|
|
8551
|
-
function extractDeletedSegments(segments, index, length) {
|
|
8552
|
-
const split = splitSegmentsAt(
|
|
8553
|
-
splitSegmentsAt(segments, index),
|
|
8554
|
-
index + length
|
|
8555
|
-
);
|
|
8556
|
-
const deleted = [];
|
|
8557
|
-
let offset = 0;
|
|
8558
|
-
for (const segment of split) {
|
|
8559
|
-
const end = offset + segment.text.length;
|
|
8560
|
-
if (offset >= index && end <= index + length) {
|
|
8561
|
-
deleted.push({
|
|
8562
|
-
text: segment.text,
|
|
8563
|
-
attributes: segment.attributes
|
|
8564
|
-
});
|
|
8565
|
-
}
|
|
8566
|
-
offset = end;
|
|
8567
|
-
}
|
|
8568
|
-
return normalizeSegments(deleted);
|
|
8569
|
-
}
|
|
8570
|
-
function applyDelete(segments, index, length) {
|
|
8571
|
-
const deletedSegments = extractDeletedSegments(segments, index, length);
|
|
8572
|
-
const split = splitSegmentsAt(
|
|
8573
|
-
splitSegmentsAt(segments, index),
|
|
8574
|
-
index + length
|
|
8575
|
-
);
|
|
8576
|
-
const result = [];
|
|
8577
|
-
let offset = 0;
|
|
8578
|
-
let deletedText = "";
|
|
8579
|
-
for (const segment of split) {
|
|
8580
|
-
const end = offset + segment.text.length;
|
|
8581
|
-
if (offset >= index && end <= index + length) {
|
|
8582
|
-
deletedText += segment.text;
|
|
8583
|
-
} else {
|
|
8584
|
-
result.push(segment);
|
|
8585
|
-
}
|
|
8586
|
-
offset = end;
|
|
8587
|
-
}
|
|
8588
|
-
return {
|
|
8589
|
-
segments: normalizeSegments(result),
|
|
8590
|
-
deletedText,
|
|
8591
|
-
deletedSegments
|
|
8592
|
-
};
|
|
8593
|
-
}
|
|
8594
|
-
function applyFormat(segments, index, length, attributes) {
|
|
8595
|
-
const split = splitSegmentsAt(
|
|
8596
|
-
splitSegmentsAt(segments, index),
|
|
8597
|
-
index + length
|
|
8598
|
-
);
|
|
8599
|
-
const result = [];
|
|
8600
|
-
let offset = 0;
|
|
8601
|
-
for (const segment of split) {
|
|
8602
|
-
const end = offset + segment.text.length;
|
|
8603
|
-
if (offset >= index && end <= index + length) {
|
|
8604
|
-
const nextAttributes = {
|
|
8605
|
-
...segment.attributes ?? {}
|
|
8606
|
-
};
|
|
8607
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
8608
|
-
if (value === null) {
|
|
8609
|
-
delete nextAttributes[key];
|
|
8610
|
-
} else {
|
|
8611
|
-
nextAttributes[key] = value;
|
|
8612
|
-
}
|
|
8613
|
-
}
|
|
8614
|
-
result.push({
|
|
8615
|
-
text: segment.text,
|
|
8616
|
-
attributes: Object.keys(nextAttributes).length === 0 ? void 0 : freeze(nextAttributes)
|
|
8617
|
-
});
|
|
8618
|
-
} else {
|
|
8619
|
-
result.push(segment);
|
|
8620
|
-
}
|
|
8621
|
-
offset = end;
|
|
8622
|
-
}
|
|
8623
|
-
return normalizeSegments(result);
|
|
8624
|
-
}
|
|
8625
|
-
function formatReverseOperations(segments, index, length, patch) {
|
|
8626
|
-
const split = splitSegmentsAt(
|
|
8627
|
-
splitSegmentsAt(segments, index),
|
|
8628
|
-
index + length
|
|
8629
|
-
);
|
|
8630
|
-
const result = [];
|
|
8631
|
-
let offset = 0;
|
|
8632
|
-
for (const segment of split) {
|
|
8633
|
-
const end = offset + segment.text.length;
|
|
8634
|
-
if (offset >= index && end <= index + length) {
|
|
8635
|
-
const attributes = {};
|
|
8636
|
-
for (const key of Object.keys(patch)) {
|
|
8637
|
-
attributes[key] = segment.attributes?.[key] ?? null;
|
|
8638
|
-
}
|
|
8639
|
-
result.push({
|
|
8640
|
-
type: "format",
|
|
8641
|
-
index: offset,
|
|
8642
|
-
length: segment.text.length,
|
|
8643
|
-
attributes
|
|
8644
|
-
});
|
|
8645
|
-
}
|
|
8646
|
-
offset = end;
|
|
8647
|
-
}
|
|
8648
|
-
return result;
|
|
8649
|
-
}
|
|
8650
|
-
function mapIndexThroughOperation(index, op) {
|
|
8651
|
-
if (op.type === "insert") {
|
|
8652
|
-
return op.index <= index ? index + op.text.length : index;
|
|
8653
|
-
} else if (op.type === "delete") {
|
|
8654
|
-
if (op.index >= index) {
|
|
8655
|
-
return index;
|
|
8656
|
-
}
|
|
8657
|
-
return Math.max(op.index, index - op.length);
|
|
8658
|
-
} else {
|
|
8659
|
-
return index;
|
|
8660
|
-
}
|
|
8661
|
-
}
|
|
8662
|
-
function mapTextIndexThroughOperations(index, ops) {
|
|
8663
|
-
let mapped = index;
|
|
8664
|
-
for (const op of ops) {
|
|
8665
|
-
mapped = mapIndexThroughOperation(mapped, op);
|
|
8666
|
-
}
|
|
8667
|
-
return mapped;
|
|
8668
|
-
}
|
|
8669
|
-
function rebaseTextOperations(ops, acceptedOps) {
|
|
8670
|
-
return ops.map((op) => {
|
|
8671
|
-
if (op.type === "insert") {
|
|
8672
|
-
return {
|
|
8673
|
-
...op,
|
|
8674
|
-
index: mapTextIndexThroughOperations(op.index, acceptedOps)
|
|
8675
|
-
};
|
|
8676
|
-
} else if (op.type === "delete" || op.type === "format") {
|
|
8677
|
-
const start = mapTextIndexThroughOperations(op.index, acceptedOps);
|
|
8678
|
-
const end = mapTextIndexThroughOperations(
|
|
8679
|
-
op.index + op.length,
|
|
8680
|
-
acceptedOps
|
|
8681
|
-
);
|
|
8682
|
-
return { ...op, index: start, length: Math.max(0, end - start) };
|
|
8683
|
-
} else {
|
|
8684
|
-
return op;
|
|
8685
|
-
}
|
|
8686
|
-
});
|
|
8687
|
-
}
|
|
8688
|
-
function applyTextOperationsToSegments(segments, ops) {
|
|
8689
|
-
let next = [...segments];
|
|
8690
|
-
for (const op of ops) {
|
|
8691
|
-
if (op.type === "insert") {
|
|
8692
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8693
|
-
next = applyInsert(next, index, op.text, op.attributes);
|
|
8694
|
-
} else if (op.type === "delete") {
|
|
8695
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8696
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8697
|
-
next = applyDelete(next, clipped.index, clipped.length).segments;
|
|
8698
|
-
} else {
|
|
8699
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8700
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8701
|
-
next = applyFormat(next, clipped.index, clipped.length, op.attributes);
|
|
8702
|
-
}
|
|
8703
|
-
}
|
|
8704
|
-
return next;
|
|
8705
|
-
}
|
|
8706
|
-
function applyLiveTextOperations(data, ops) {
|
|
8707
|
-
return segmentsToData(
|
|
8708
|
-
applyTextOperationsToSegments(dataToSegments(data), ops)
|
|
8709
|
-
);
|
|
8710
|
-
}
|
|
8711
|
-
function invertTextOperations(segments, ops) {
|
|
8712
|
-
let shadow = [...segments];
|
|
8713
|
-
const reverse = [];
|
|
8714
|
-
for (const op of ops) {
|
|
8715
|
-
if (op.type === "insert") {
|
|
8716
|
-
shadow = applyInsert(shadow, op.index, op.text, op.attributes);
|
|
8717
|
-
reverse.unshift({
|
|
8718
|
-
type: "delete",
|
|
8719
|
-
index: op.index,
|
|
8720
|
-
length: op.text.length
|
|
8721
|
-
});
|
|
8722
|
-
} else if (op.type === "delete") {
|
|
8723
|
-
const deletedSegments = extractDeletedSegments(
|
|
8724
|
-
shadow,
|
|
8725
|
-
op.index,
|
|
8726
|
-
op.length
|
|
8727
|
-
);
|
|
8728
|
-
shadow = applyDelete(shadow, op.index, op.length).segments;
|
|
8729
|
-
const inserts = [];
|
|
8730
|
-
let insertIndex = op.index;
|
|
8731
|
-
for (const segment of deletedSegments) {
|
|
8732
|
-
inserts.push({
|
|
8733
|
-
type: "insert",
|
|
8734
|
-
index: insertIndex,
|
|
8735
|
-
text: segment.text,
|
|
8736
|
-
attributes: segment.attributes
|
|
8737
|
-
});
|
|
8738
|
-
insertIndex += segment.text.length;
|
|
8739
|
-
}
|
|
8740
|
-
for (let index = inserts.length - 1; index >= 0; index--) {
|
|
8741
|
-
reverse.unshift(inserts[index]);
|
|
8742
|
-
}
|
|
8743
|
-
} else {
|
|
8744
|
-
const inverse = formatReverseOperations(
|
|
8745
|
-
shadow,
|
|
8746
|
-
op.index,
|
|
8747
|
-
op.length,
|
|
8748
|
-
op.attributes
|
|
8749
|
-
);
|
|
8750
|
-
shadow = applyFormat(shadow, op.index, op.length, op.attributes);
|
|
8751
|
-
reverse.unshift(...inverse.reverse());
|
|
8752
|
-
}
|
|
8753
|
-
}
|
|
8754
|
-
return reverse;
|
|
8755
|
-
}
|
|
8756
|
-
|
|
8757
|
-
// src/crdts/LiveText.ts
|
|
8758
|
-
var LiveText = class _LiveText extends AbstractCrdt {
|
|
8759
|
-
#segments;
|
|
8760
|
-
#version;
|
|
8761
|
-
#pendingOps;
|
|
8762
|
-
constructor(textOrData = "", version = 0) {
|
|
8763
|
-
super();
|
|
8764
|
-
this.#segments = typeof textOrData === "string" ? textOrData.length === 0 ? [] : [{ text: textOrData }] : dataToSegments(textOrData);
|
|
8765
|
-
this.#version = version;
|
|
8766
|
-
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8767
|
-
}
|
|
8768
|
-
get version() {
|
|
8769
|
-
return this.#version;
|
|
8770
|
-
}
|
|
8771
|
-
get length() {
|
|
8772
|
-
return this.toString().length;
|
|
8773
|
-
}
|
|
8774
|
-
/** @internal */
|
|
8775
|
-
static _deserialize([id, item], _parentToChildren, pool) {
|
|
8776
|
-
const text = new _LiveText(item.data, item.version);
|
|
8777
|
-
text._attach(id, pool);
|
|
8778
|
-
return text;
|
|
8779
|
-
}
|
|
8780
|
-
/** @internal */
|
|
8781
|
-
_toOps(parentId, parentKey) {
|
|
8782
|
-
if (this._id === void 0) {
|
|
8783
|
-
throw new Error("Cannot serialize LiveText if it is not attached");
|
|
8784
|
-
}
|
|
8785
|
-
return [
|
|
8786
|
-
{
|
|
8787
|
-
type: OpCode.CREATE_TEXT,
|
|
8788
|
-
id: this._id,
|
|
8789
|
-
parentId,
|
|
8790
|
-
parentKey,
|
|
8791
|
-
data: this.toJSON(),
|
|
8792
|
-
version: this.#version
|
|
8793
|
-
}
|
|
8794
|
-
];
|
|
8795
|
-
}
|
|
8796
|
-
/** @internal */
|
|
8797
|
-
_serialize() {
|
|
8798
|
-
if (this.parent.type !== "HasParent") {
|
|
8799
|
-
throw new Error("Cannot serialize LiveText if parent is missing");
|
|
8800
|
-
}
|
|
8801
|
-
return {
|
|
8802
|
-
type: CrdtType.TEXT,
|
|
8803
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8804
|
-
parentKey: this.parent.key,
|
|
8805
|
-
data: this.toJSON(),
|
|
8806
|
-
version: this.#version
|
|
8807
|
-
};
|
|
8808
|
-
}
|
|
8809
|
-
/** @internal */
|
|
8810
|
-
_attachChild(_op) {
|
|
8811
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8812
|
-
}
|
|
8813
|
-
/** @internal */
|
|
8814
|
-
_detachChild(_crdt) {
|
|
8815
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8816
|
-
}
|
|
8817
|
-
/** @internal */
|
|
8818
|
-
_apply(op, isLocal) {
|
|
8819
|
-
if (op.type !== OpCode.UPDATE_TEXT) {
|
|
8820
|
-
return super._apply(op, isLocal);
|
|
8821
|
-
}
|
|
8822
|
-
if (isLocal) {
|
|
8823
|
-
this.#pendingOps.set(nn(op.opId), op.ops);
|
|
8824
|
-
return this.#applyOperations(op.ops, op.version ?? this.#version);
|
|
8825
|
-
}
|
|
8826
|
-
if (op.opId !== void 0) {
|
|
8827
|
-
const pending2 = this.#pendingOps.get(op.opId);
|
|
8828
|
-
this.#pendingOps.delete(op.opId);
|
|
8829
|
-
const otherPending = Array.from(this.#pendingOps.values()).flat();
|
|
8830
|
-
if (pending2 !== void 0 && otherPending.length > 0) {
|
|
8831
|
-
this.#segments = applyTextOperationsToSegments(
|
|
8832
|
-
this.#segments,
|
|
8833
|
-
invertTextOperations(this.#segments, pending2)
|
|
8834
|
-
);
|
|
8835
|
-
const ops2 = rebaseTextOperations(op.ops, otherPending);
|
|
8836
|
-
return this.#applyOperations(
|
|
8837
|
-
ops2,
|
|
8838
|
-
op.version ?? Math.max(this.#version, op.baseVersion + 1)
|
|
8839
|
-
);
|
|
8840
|
-
}
|
|
8841
|
-
this.#version = op.version ?? Math.max(this.#version, op.baseVersion + 1);
|
|
8842
|
-
return { modified: false };
|
|
8843
|
-
}
|
|
8844
|
-
const pending = Array.from(this.#pendingOps.values()).flat();
|
|
8845
|
-
const ops = pending.length > 0 ? rebaseTextOperations(op.ops, pending) : op.ops;
|
|
8846
|
-
return this.#applyOperations(ops, op.version ?? this.#version + 1);
|
|
8847
|
-
}
|
|
8848
|
-
insert(index, text, attributes) {
|
|
8849
|
-
const clippedIndex = Math.max(0, Math.min(index, this.length));
|
|
8850
|
-
this.#dispatch([{ type: "insert", index: clippedIndex, text, attributes }]);
|
|
8851
|
-
}
|
|
8852
|
-
delete(index, length) {
|
|
8853
|
-
const clipped = clipRange(index, length, this.length);
|
|
8854
|
-
if (clipped.length === 0) {
|
|
8855
|
-
return;
|
|
8856
|
-
}
|
|
8857
|
-
this.#dispatch([
|
|
8858
|
-
{ type: "delete", index: clipped.index, length: clipped.length }
|
|
8859
|
-
]);
|
|
8860
|
-
}
|
|
8861
|
-
replace(index, length, text, attributes) {
|
|
8862
|
-
const clipped = clipRange(index, length, this.length);
|
|
8863
|
-
const ops = [];
|
|
8864
|
-
if (clipped.length > 0) {
|
|
8865
|
-
ops.push({
|
|
8866
|
-
type: "delete",
|
|
8867
|
-
index: clipped.index,
|
|
8868
|
-
length: clipped.length
|
|
8869
|
-
});
|
|
8870
|
-
}
|
|
8871
|
-
if (text.length > 0) {
|
|
8872
|
-
ops.push({ type: "insert", index: clipped.index, text, attributes });
|
|
8873
|
-
}
|
|
8874
|
-
this.#dispatch(ops);
|
|
8875
|
-
}
|
|
8876
|
-
format(index, length, attributes) {
|
|
8877
|
-
const clipped = clipRange(index, length, this.length);
|
|
8878
|
-
if (clipped.length === 0) {
|
|
8879
|
-
return;
|
|
8880
|
-
}
|
|
8881
|
-
this.#dispatch([
|
|
8882
|
-
{
|
|
8883
|
-
type: "format",
|
|
8884
|
-
index: clipped.index,
|
|
8885
|
-
length: clipped.length,
|
|
8886
|
-
attributes
|
|
8887
|
-
}
|
|
8888
|
-
]);
|
|
8889
|
-
}
|
|
8890
|
-
#dispatch(ops) {
|
|
8891
|
-
if (ops.length === 0) {
|
|
8892
|
-
return;
|
|
8893
|
-
}
|
|
8894
|
-
this._pool?.assertStorageIsWritable();
|
|
8895
|
-
const baseVersion = this.#version;
|
|
8896
|
-
const reverse = this._pool !== void 0 && this._id !== void 0 ? this.#invertOperations(ops) : [];
|
|
8897
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8898
|
-
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8899
|
-
const opId = this._pool.generateOpId();
|
|
8900
|
-
this.#pendingOps.set(opId, ops);
|
|
8901
|
-
this._pool.dispatch(
|
|
8902
|
-
[
|
|
8903
|
-
{
|
|
8904
|
-
type: OpCode.UPDATE_TEXT,
|
|
8905
|
-
id: this._id,
|
|
8906
|
-
opId,
|
|
8907
|
-
baseVersion,
|
|
8908
|
-
ops: [...ops]
|
|
8909
|
-
}
|
|
8910
|
-
],
|
|
8911
|
-
reverse,
|
|
8912
|
-
/* @__PURE__ */ new Map([
|
|
8913
|
-
[
|
|
8914
|
-
this._id,
|
|
8915
|
-
{
|
|
8916
|
-
type: "LiveText",
|
|
8917
|
-
node: this,
|
|
8918
|
-
version: this.#version,
|
|
8919
|
-
updates: changes
|
|
8920
|
-
}
|
|
8921
|
-
]
|
|
8922
|
-
])
|
|
8923
|
-
);
|
|
8924
|
-
}
|
|
8925
|
-
}
|
|
8926
|
-
#applyOperations(ops, version) {
|
|
8927
|
-
const reverse = this.#invertOperations(ops);
|
|
8928
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8929
|
-
this.#version = Math.max(this.#version, version);
|
|
8930
|
-
return {
|
|
8931
|
-
reverse,
|
|
8932
|
-
modified: {
|
|
8933
|
-
type: "LiveText",
|
|
8934
|
-
node: this,
|
|
8935
|
-
version: this.#version,
|
|
8936
|
-
updates: changes
|
|
8937
|
-
}
|
|
8938
|
-
};
|
|
8939
|
-
}
|
|
8940
|
-
#applyOperationsLocally(ops) {
|
|
8941
|
-
const changes = [];
|
|
8942
|
-
for (const op of ops) {
|
|
8943
|
-
if (op.type === "insert") {
|
|
8944
|
-
this.#segments = applyInsert(
|
|
8945
|
-
this.#segments,
|
|
8946
|
-
op.index,
|
|
8947
|
-
op.text,
|
|
8948
|
-
op.attributes
|
|
8949
|
-
);
|
|
8950
|
-
changes.push({
|
|
8951
|
-
type: "insert",
|
|
8952
|
-
index: op.index,
|
|
8953
|
-
text: op.text,
|
|
8954
|
-
attributes: op.attributes
|
|
8955
|
-
});
|
|
8956
|
-
} else if (op.type === "delete") {
|
|
8957
|
-
const result = applyDelete(this.#segments, op.index, op.length);
|
|
8958
|
-
this.#segments = result.segments;
|
|
8959
|
-
changes.push({
|
|
8960
|
-
type: "delete",
|
|
8961
|
-
index: op.index,
|
|
8962
|
-
length: op.length,
|
|
8963
|
-
deletedText: result.deletedText
|
|
8964
|
-
});
|
|
8965
|
-
} else {
|
|
8966
|
-
this.#segments = applyFormat(
|
|
8967
|
-
this.#segments,
|
|
8968
|
-
op.index,
|
|
8969
|
-
op.length,
|
|
8970
|
-
op.attributes
|
|
8971
|
-
);
|
|
8972
|
-
changes.push({
|
|
8973
|
-
type: "format",
|
|
8974
|
-
index: op.index,
|
|
8975
|
-
length: op.length,
|
|
8976
|
-
attributes: op.attributes
|
|
8977
|
-
});
|
|
8978
|
-
}
|
|
8979
|
-
}
|
|
8980
|
-
this.invalidate();
|
|
8981
|
-
return changes;
|
|
8982
|
-
}
|
|
8983
|
-
#invertOperations(ops) {
|
|
8984
|
-
return [
|
|
8985
|
-
{
|
|
8986
|
-
type: OpCode.UPDATE_TEXT,
|
|
8987
|
-
id: nn(this._id),
|
|
8988
|
-
baseVersion: this.#version,
|
|
8989
|
-
ops: invertTextOperations(this.#segments, ops)
|
|
8990
|
-
}
|
|
8991
|
-
];
|
|
8992
|
-
}
|
|
8993
|
-
toString() {
|
|
8994
|
-
return this.#segments.map((segment) => segment.text).join("");
|
|
8995
|
-
}
|
|
8996
|
-
toJSON() {
|
|
8997
|
-
return super.toJSON();
|
|
8998
|
-
}
|
|
8999
|
-
/** @internal */
|
|
9000
|
-
_toJSON() {
|
|
9001
|
-
return segmentsToData(this.#segments);
|
|
9002
|
-
}
|
|
9003
|
-
/** @internal */
|
|
9004
|
-
_toTreeNode(key) {
|
|
9005
|
-
return {
|
|
9006
|
-
type: "LiveText",
|
|
9007
|
-
id: this._id ?? nanoid(),
|
|
9008
|
-
key,
|
|
9009
|
-
payload: [
|
|
9010
|
-
{
|
|
9011
|
-
type: "Json",
|
|
9012
|
-
id: `${this._id ?? nanoid()}:text`,
|
|
9013
|
-
key: "text",
|
|
9014
|
-
payload: this.toString()
|
|
9015
|
-
}
|
|
9016
|
-
]
|
|
9017
|
-
};
|
|
9018
|
-
}
|
|
9019
|
-
clone() {
|
|
9020
|
-
return new _LiveText(this.toJSON(), this.#version);
|
|
9021
|
-
}
|
|
9022
|
-
};
|
|
9023
|
-
|
|
9024
|
-
// src/crdts/liveblocks-helpers.ts
|
|
9025
|
-
function creationOpToLiveNode(op) {
|
|
9026
|
-
return lsonToLiveNode(creationOpToLson(op));
|
|
8455
|
+
// src/crdts/liveblocks-helpers.ts
|
|
8456
|
+
function creationOpToLiveNode(op) {
|
|
8457
|
+
return lsonToLiveNode(creationOpToLson(op));
|
|
9027
8458
|
}
|
|
9028
8459
|
function creationOpToLson(op) {
|
|
9029
8460
|
switch (op.type) {
|
|
@@ -9035,8 +8466,6 @@ function creationOpToLson(op) {
|
|
|
9035
8466
|
return new LiveMap();
|
|
9036
8467
|
case OpCode.CREATE_LIST:
|
|
9037
8468
|
return new LiveList([]);
|
|
9038
|
-
case OpCode.CREATE_TEXT:
|
|
9039
|
-
return new LiveText(op.data, op.version);
|
|
9040
8469
|
default:
|
|
9041
8470
|
return assertNever(op, "Unknown creation Op");
|
|
9042
8471
|
}
|
|
@@ -9059,8 +8488,6 @@ function deserialize(node, parentToChildren, pool) {
|
|
|
9059
8488
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9060
8489
|
} else if (isRegisterStorageNode(node)) {
|
|
9061
8490
|
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
9062
|
-
} else if (isTextStorageNode(node)) {
|
|
9063
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9064
8491
|
} else {
|
|
9065
8492
|
throw new Error("Unexpected CRDT type");
|
|
9066
8493
|
}
|
|
@@ -9074,14 +8501,12 @@ function deserializeToLson(node, parentToChildren, pool) {
|
|
|
9074
8501
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9075
8502
|
} else if (isRegisterStorageNode(node)) {
|
|
9076
8503
|
return node[1].data;
|
|
9077
|
-
} else if (isTextStorageNode(node)) {
|
|
9078
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9079
8504
|
} else {
|
|
9080
8505
|
throw new Error("Unexpected CRDT type");
|
|
9081
8506
|
}
|
|
9082
8507
|
}
|
|
9083
8508
|
function isLiveStructure(value) {
|
|
9084
|
-
return isLiveList(value) || isLiveMap(value) || isLiveObject(value)
|
|
8509
|
+
return isLiveList(value) || isLiveMap(value) || isLiveObject(value);
|
|
9085
8510
|
}
|
|
9086
8511
|
function isLiveNode(value) {
|
|
9087
8512
|
return isLiveStructure(value) || isLiveRegister(value);
|
|
@@ -9095,9 +8520,6 @@ function isLiveMap(value) {
|
|
|
9095
8520
|
function isLiveObject(value) {
|
|
9096
8521
|
return value instanceof LiveObject;
|
|
9097
8522
|
}
|
|
9098
|
-
function isLiveText(value) {
|
|
9099
|
-
return value instanceof LiveText;
|
|
9100
|
-
}
|
|
9101
8523
|
function isLiveRegister(value) {
|
|
9102
8524
|
return value instanceof LiveRegister;
|
|
9103
8525
|
}
|
|
@@ -9107,73 +8529,19 @@ function cloneLson(value) {
|
|
|
9107
8529
|
function liveNodeToLson(obj) {
|
|
9108
8530
|
if (obj instanceof LiveRegister) {
|
|
9109
8531
|
return obj.data;
|
|
9110
|
-
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject
|
|
8532
|
+
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject) {
|
|
9111
8533
|
return obj;
|
|
9112
8534
|
} else {
|
|
9113
8535
|
return assertNever(obj, "Unknown AbstractCrdt");
|
|
9114
8536
|
}
|
|
9115
8537
|
}
|
|
9116
8538
|
function lsonToLiveNode(value) {
|
|
9117
|
-
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList
|
|
8539
|
+
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList) {
|
|
9118
8540
|
return value;
|
|
9119
8541
|
} else {
|
|
9120
8542
|
return new LiveRegister(value);
|
|
9121
8543
|
}
|
|
9122
8544
|
}
|
|
9123
|
-
function dumpPool(pool) {
|
|
9124
|
-
const rows = Array.from(pool.nodes.values(), (node) => {
|
|
9125
|
-
const parent = node.parent;
|
|
9126
|
-
const parentId = parent.type === "HasParent" ? parent.node._id ?? "?" : parent.type === "Orphaned" ? "<orphaned>" : "-";
|
|
9127
|
-
let value;
|
|
9128
|
-
if (node instanceof LiveRegister) {
|
|
9129
|
-
value = stringifyOrLog(node.data);
|
|
9130
|
-
} else if (node instanceof LiveList) {
|
|
9131
|
-
value = "<LiveList>";
|
|
9132
|
-
} else if (node instanceof LiveMap) {
|
|
9133
|
-
value = "<LiveMap>";
|
|
9134
|
-
} else {
|
|
9135
|
-
value = "<LiveObject>";
|
|
9136
|
-
}
|
|
9137
|
-
return { id: nn(node._id), parentId, key: node._parentKey ?? "", value };
|
|
9138
|
-
});
|
|
9139
|
-
rows.sort((a, b) => {
|
|
9140
|
-
if (a.parentId !== b.parentId) return a.parentId < b.parentId ? -1 : 1;
|
|
9141
|
-
if (a.key !== b.key) return a.key < b.key ? -1 : 1;
|
|
9142
|
-
return 0;
|
|
9143
|
-
});
|
|
9144
|
-
return rows.map(
|
|
9145
|
-
(r) => ` ${r.id} parent=${r.parentId} key=${r.key || "\u2014"} ${r.value}`
|
|
9146
|
-
).join("\n");
|
|
9147
|
-
}
|
|
9148
|
-
function isJsonEq(a, b) {
|
|
9149
|
-
if (a === b) {
|
|
9150
|
-
return true;
|
|
9151
|
-
}
|
|
9152
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
9153
|
-
return false;
|
|
9154
|
-
}
|
|
9155
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
9156
|
-
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
9157
|
-
return false;
|
|
9158
|
-
}
|
|
9159
|
-
for (let i = 0; i < a.length; i++) {
|
|
9160
|
-
if (!isJsonEq(a[i], b[i])) {
|
|
9161
|
-
return false;
|
|
9162
|
-
}
|
|
9163
|
-
}
|
|
9164
|
-
return true;
|
|
9165
|
-
}
|
|
9166
|
-
const aKeys = Object.keys(a);
|
|
9167
|
-
if (aKeys.length !== Object.keys(b).length) {
|
|
9168
|
-
return false;
|
|
9169
|
-
}
|
|
9170
|
-
for (const key of aKeys) {
|
|
9171
|
-
if (!isJsonEq(a[key], b[key])) {
|
|
9172
|
-
return false;
|
|
9173
|
-
}
|
|
9174
|
-
}
|
|
9175
|
-
return true;
|
|
9176
|
-
}
|
|
9177
8545
|
function getTreesDiffOperations(currentItems, newItems) {
|
|
9178
8546
|
const ops = [];
|
|
9179
8547
|
currentItems.forEach((_, id) => {
|
|
@@ -9185,61 +8553,11 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9185
8553
|
const currentCrdt = currentItems.get(id);
|
|
9186
8554
|
if (currentCrdt) {
|
|
9187
8555
|
if (crdt.type === CrdtType.OBJECT) {
|
|
9188
|
-
if (currentCrdt.type !== CrdtType.OBJECT) {
|
|
9189
|
-
ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
|
|
9190
|
-
} else {
|
|
9191
|
-
const changed = /* @__PURE__ */ new Map();
|
|
9192
|
-
for (const key of Object.keys(crdt.data)) {
|
|
9193
|
-
const value = crdt.data[key];
|
|
9194
|
-
if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
|
|
9195
|
-
changed.set(key, value);
|
|
9196
|
-
}
|
|
9197
|
-
}
|
|
9198
|
-
if (changed.size > 0) {
|
|
9199
|
-
ops.push({
|
|
9200
|
-
type: OpCode.UPDATE_OBJECT,
|
|
9201
|
-
id,
|
|
9202
|
-
data: Object.fromEntries(changed)
|
|
9203
|
-
});
|
|
9204
|
-
}
|
|
9205
|
-
for (const key of Object.keys(currentCrdt.data)) {
|
|
9206
|
-
if (!(key in crdt.data)) {
|
|
9207
|
-
ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
9208
|
-
}
|
|
9209
|
-
}
|
|
9210
|
-
}
|
|
9211
|
-
}
|
|
9212
|
-
if (crdt.type === CrdtType.TEXT) {
|
|
9213
|
-
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)) {
|
|
9214
8557
|
ops.push({
|
|
9215
|
-
type: OpCode.
|
|
8558
|
+
type: OpCode.UPDATE_OBJECT,
|
|
9216
8559
|
id,
|
|
9217
|
-
|
|
9218
|
-
version: crdt.version,
|
|
9219
|
-
ops: [
|
|
9220
|
-
{
|
|
9221
|
-
type: "delete",
|
|
9222
|
-
index: 0,
|
|
9223
|
-
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9224
|
-
(sum, segment) => sum + segment[0].length,
|
|
9225
|
-
0
|
|
9226
|
-
) : 0
|
|
9227
|
-
},
|
|
9228
|
-
...crdt.data.map((segment, index, items) => {
|
|
9229
|
-
const [text, attributes] = segment;
|
|
9230
|
-
const insertIndex = items.slice(0, index).reduce((sum, item) => sum + item[0].length, 0);
|
|
9231
|
-
return attributes === void 0 ? {
|
|
9232
|
-
type: "insert",
|
|
9233
|
-
index: insertIndex,
|
|
9234
|
-
text
|
|
9235
|
-
} : {
|
|
9236
|
-
type: "insert",
|
|
9237
|
-
index: insertIndex,
|
|
9238
|
-
text,
|
|
9239
|
-
attributes
|
|
9240
|
-
};
|
|
9241
|
-
})
|
|
9242
|
-
]
|
|
8560
|
+
data: crdt.data
|
|
9243
8561
|
});
|
|
9244
8562
|
}
|
|
9245
8563
|
}
|
|
@@ -9291,16 +8609,6 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9291
8609
|
parentKey: crdt.parentKey
|
|
9292
8610
|
});
|
|
9293
8611
|
break;
|
|
9294
|
-
case CrdtType.TEXT:
|
|
9295
|
-
ops.push({
|
|
9296
|
-
type: OpCode.CREATE_TEXT,
|
|
9297
|
-
id,
|
|
9298
|
-
parentId: crdt.parentId,
|
|
9299
|
-
parentKey: crdt.parentKey,
|
|
9300
|
-
data: crdt.data,
|
|
9301
|
-
version: crdt.version
|
|
9302
|
-
});
|
|
9303
|
-
break;
|
|
9304
8612
|
}
|
|
9305
8613
|
}
|
|
9306
8614
|
});
|
|
@@ -9333,12 +8641,6 @@ function mergeListStorageUpdates(first, second) {
|
|
|
9333
8641
|
updates: updates.concat(second.updates)
|
|
9334
8642
|
};
|
|
9335
8643
|
}
|
|
9336
|
-
function mergeTextStorageUpdates(first, second) {
|
|
9337
|
-
return {
|
|
9338
|
-
...second,
|
|
9339
|
-
updates: first.updates.concat(second.updates)
|
|
9340
|
-
};
|
|
9341
|
-
}
|
|
9342
8644
|
function mergeStorageUpdates(first, second) {
|
|
9343
8645
|
if (first === void 0) {
|
|
9344
8646
|
return second;
|
|
@@ -9349,8 +8651,6 @@ function mergeStorageUpdates(first, second) {
|
|
|
9349
8651
|
return mergeMapStorageUpdates(first, second);
|
|
9350
8652
|
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
9351
8653
|
return mergeListStorageUpdates(first, second);
|
|
9352
|
-
} else if (first.type === "LiveText" && second.type === "LiveText") {
|
|
9353
|
-
return mergeTextStorageUpdates(first, second);
|
|
9354
8654
|
} else {
|
|
9355
8655
|
}
|
|
9356
8656
|
return second;
|
|
@@ -9937,14 +9237,14 @@ var ClientMsgCode = Object.freeze({
|
|
|
9937
9237
|
// src/refs/ManagedOthers.ts
|
|
9938
9238
|
function makeUser(conn, presence) {
|
|
9939
9239
|
const { connectionId, id, info } = conn;
|
|
9940
|
-
const canWrite =
|
|
9240
|
+
const canWrite = hasPermissionCapability(conn.scopes, "storage", "write");
|
|
9941
9241
|
return freeze(
|
|
9942
9242
|
compactObject({
|
|
9943
9243
|
connectionId,
|
|
9944
9244
|
id,
|
|
9945
9245
|
info,
|
|
9946
9246
|
canWrite,
|
|
9947
|
-
canComment:
|
|
9247
|
+
canComment: hasPermissionCapability(conn.scopes, "comments", "write"),
|
|
9948
9248
|
isReadOnly: !canWrite,
|
|
9949
9249
|
// Deprecated, kept for backward-compatibility
|
|
9950
9250
|
presence
|
|
@@ -10251,7 +9551,6 @@ function createRoom(options, config) {
|
|
|
10251
9551
|
delegates,
|
|
10252
9552
|
config.enableDebugLogging
|
|
10253
9553
|
);
|
|
10254
|
-
const unacknowledgedOps = new UnacknowledgedOps();
|
|
10255
9554
|
const context = {
|
|
10256
9555
|
buffer: {
|
|
10257
9556
|
flushTimerID: void 0,
|
|
@@ -10279,15 +9578,14 @@ function createRoom(options, config) {
|
|
|
10279
9578
|
pool: createManagedPool(roomId, {
|
|
10280
9579
|
getCurrentConnectionId,
|
|
10281
9580
|
onDispatch,
|
|
10282
|
-
isStorageWritable
|
|
10283
|
-
unacknowledgedOps
|
|
9581
|
+
isStorageWritable
|
|
10284
9582
|
}),
|
|
10285
9583
|
root: void 0,
|
|
10286
9584
|
undoStack: [],
|
|
10287
9585
|
redoStack: [],
|
|
10288
9586
|
pausedHistory: null,
|
|
10289
9587
|
activeBatch: null,
|
|
10290
|
-
unacknowledgedOps
|
|
9588
|
+
unacknowledgedOps: /* @__PURE__ */ new Map()
|
|
10291
9589
|
};
|
|
10292
9590
|
const nodeMapBuffer = makeNodeMapBuffer();
|
|
10293
9591
|
const stopwatch = config.enableDebugLogging ? makeStopWatch() : void 0;
|
|
@@ -10400,7 +9698,7 @@ function createRoom(options, config) {
|
|
|
10400
9698
|
}
|
|
10401
9699
|
function isStorageWritable() {
|
|
10402
9700
|
const scopes = context.dynamicSessionInfoSig.get()?.scopes;
|
|
10403
|
-
return scopes !== void 0 ?
|
|
9701
|
+
return scopes !== void 0 ? hasPermissionCapability(scopes, "storage", "write") : true;
|
|
10404
9702
|
}
|
|
10405
9703
|
const eventHub = {
|
|
10406
9704
|
status: makeEventSource(),
|
|
@@ -10461,14 +9759,22 @@ function createRoom(options, config) {
|
|
|
10461
9759
|
if (staticSession === null || dynamicSession === null) {
|
|
10462
9760
|
return null;
|
|
10463
9761
|
} else {
|
|
10464
|
-
const canWrite =
|
|
9762
|
+
const canWrite = hasPermissionCapability(
|
|
9763
|
+
dynamicSession.scopes,
|
|
9764
|
+
"storage",
|
|
9765
|
+
"write"
|
|
9766
|
+
);
|
|
10465
9767
|
return {
|
|
10466
9768
|
connectionId: dynamicSession.actor,
|
|
10467
9769
|
id: staticSession.userId,
|
|
10468
9770
|
info: staticSession.userInfo,
|
|
10469
9771
|
presence: myPresence,
|
|
10470
9772
|
canWrite,
|
|
10471
|
-
canComment:
|
|
9773
|
+
canComment: hasPermissionCapability(
|
|
9774
|
+
dynamicSession.scopes,
|
|
9775
|
+
"comments",
|
|
9776
|
+
"write"
|
|
9777
|
+
)
|
|
10472
9778
|
};
|
|
10473
9779
|
}
|
|
10474
9780
|
}
|
|
@@ -10495,11 +9801,7 @@ function createRoom(options, config) {
|
|
|
10495
9801
|
currentItems.set(id, crdt._serialize());
|
|
10496
9802
|
}
|
|
10497
9803
|
const ops = getTreesDiffOperations(currentItems, nodes);
|
|
10498
|
-
const result = applyRemoteOps(
|
|
10499
|
-
ops,
|
|
10500
|
-
/* fromSnapshot */
|
|
10501
|
-
true
|
|
10502
|
-
);
|
|
9804
|
+
const result = applyRemoteOps(ops);
|
|
10503
9805
|
notify(result.updates);
|
|
10504
9806
|
} else {
|
|
10505
9807
|
context.root = LiveObject._fromItems(
|
|
@@ -10581,16 +9883,15 @@ function createRoom(options, config) {
|
|
|
10581
9883
|
);
|
|
10582
9884
|
return { opsToEmit: opsWithOpIds, reverse, updates };
|
|
10583
9885
|
}
|
|
10584
|
-
function applyRemoteOps(ops
|
|
9886
|
+
function applyRemoteOps(ops) {
|
|
10585
9887
|
return applyOps(
|
|
10586
9888
|
[],
|
|
10587
9889
|
ops,
|
|
10588
9890
|
/* isLocal */
|
|
10589
|
-
false
|
|
10590
|
-
fromSnapshot
|
|
9891
|
+
false
|
|
10591
9892
|
);
|
|
10592
9893
|
}
|
|
10593
|
-
function applyOps(pframes, ops, isLocal
|
|
9894
|
+
function applyOps(pframes, ops, isLocal) {
|
|
10594
9895
|
const output = {
|
|
10595
9896
|
reverse: new Deque(),
|
|
10596
9897
|
storageUpdates: /* @__PURE__ */ new Map(),
|
|
@@ -10626,7 +9927,7 @@ function createRoom(options, config) {
|
|
|
10626
9927
|
} else {
|
|
10627
9928
|
source = 1 /* THEIRS */;
|
|
10628
9929
|
}
|
|
10629
|
-
const applyOpResult = applyOp(op, source
|
|
9930
|
+
const applyOpResult = applyOp(op, source);
|
|
10630
9931
|
if (applyOpResult.modified) {
|
|
10631
9932
|
const nodeId = applyOpResult.modified.node._id;
|
|
10632
9933
|
if (!(nodeId && createdNodeIds.has(nodeId))) {
|
|
@@ -10639,7 +9940,7 @@ function createRoom(options, config) {
|
|
|
10639
9940
|
);
|
|
10640
9941
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
10641
9942
|
}
|
|
10642
|
-
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) {
|
|
10643
9944
|
createdNodeIds.add(op.id);
|
|
10644
9945
|
}
|
|
10645
9946
|
}
|
|
@@ -10652,14 +9953,13 @@ function createRoom(options, config) {
|
|
|
10652
9953
|
}
|
|
10653
9954
|
};
|
|
10654
9955
|
}
|
|
10655
|
-
function applyOp(op, source
|
|
9956
|
+
function applyOp(op, source) {
|
|
10656
9957
|
if (isIgnoredOp(op)) {
|
|
10657
9958
|
return { modified: false };
|
|
10658
9959
|
}
|
|
10659
9960
|
switch (op.type) {
|
|
10660
9961
|
case OpCode.DELETE_OBJECT_KEY:
|
|
10661
9962
|
case OpCode.UPDATE_OBJECT:
|
|
10662
|
-
case OpCode.UPDATE_TEXT:
|
|
10663
9963
|
case OpCode.DELETE_CRDT: {
|
|
10664
9964
|
const node = context.pool.nodes.get(op.id);
|
|
10665
9965
|
if (node === void 0) {
|
|
@@ -10684,7 +9984,6 @@ function createRoom(options, config) {
|
|
|
10684
9984
|
case OpCode.CREATE_OBJECT:
|
|
10685
9985
|
case OpCode.CREATE_LIST:
|
|
10686
9986
|
case OpCode.CREATE_MAP:
|
|
10687
|
-
case OpCode.CREATE_TEXT:
|
|
10688
9987
|
case OpCode.CREATE_REGISTER: {
|
|
10689
9988
|
if (op.parentId === void 0) {
|
|
10690
9989
|
return { modified: false };
|
|
@@ -10693,7 +9992,7 @@ function createRoom(options, config) {
|
|
|
10693
9992
|
if (parentNode === void 0) {
|
|
10694
9993
|
return { modified: false };
|
|
10695
9994
|
}
|
|
10696
|
-
return parentNode._attachChild(op, source
|
|
9995
|
+
return parentNode._attachChild(op, source);
|
|
10697
9996
|
}
|
|
10698
9997
|
}
|
|
10699
9998
|
}
|
|
@@ -10833,11 +10132,12 @@ function createRoom(options, config) {
|
|
|
10833
10132
|
}
|
|
10834
10133
|
}
|
|
10835
10134
|
function applyAndSendOfflineOps(unackedOps) {
|
|
10836
|
-
if (unackedOps.
|
|
10135
|
+
if (unackedOps.size === 0) {
|
|
10837
10136
|
return;
|
|
10838
10137
|
}
|
|
10839
10138
|
const messages = [];
|
|
10840
|
-
const
|
|
10139
|
+
const inOps = Array.from(unackedOps.values());
|
|
10140
|
+
const result = applyLocalOps(inOps);
|
|
10841
10141
|
messages.push({
|
|
10842
10142
|
type: ClientMsgCode.UPDATE_STORAGE,
|
|
10843
10143
|
ops: result.opsToEmit
|
|
@@ -11061,7 +10361,7 @@ function createRoom(options, config) {
|
|
|
11061
10361
|
const storageOps = context.buffer.storageOperations;
|
|
11062
10362
|
if (storageOps.length > 0) {
|
|
11063
10363
|
for (const op of storageOps) {
|
|
11064
|
-
context.unacknowledgedOps.
|
|
10364
|
+
context.unacknowledgedOps.set(op.opId, op);
|
|
11065
10365
|
}
|
|
11066
10366
|
notifyStorageStatus();
|
|
11067
10367
|
}
|
|
@@ -11288,9 +10588,9 @@ function createRoom(options, config) {
|
|
|
11288
10588
|
}
|
|
11289
10589
|
}
|
|
11290
10590
|
function processInitialStorage(nodes) {
|
|
11291
|
-
const
|
|
10591
|
+
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
11292
10592
|
createOrUpdateRootFromMessage(nodes);
|
|
11293
|
-
applyAndSendOfflineOps(
|
|
10593
|
+
applyAndSendOfflineOps(unacknowledgedOps);
|
|
11294
10594
|
_resolveStoragePromise?.();
|
|
11295
10595
|
notifyStorageStatus();
|
|
11296
10596
|
eventHub.storageDidLoad.notify();
|
|
@@ -11879,11 +11179,6 @@ function createRoom(options, config) {
|
|
|
11879
11179
|
connect: () => managedSocket.connect(),
|
|
11880
11180
|
reconnect: () => managedSocket.reconnect(),
|
|
11881
11181
|
disconnect: () => managedSocket.disconnect(),
|
|
11882
|
-
_dump: () => {
|
|
11883
|
-
const n = context.pool.nodes.size;
|
|
11884
|
-
return `Room "${roomId}" (${n} node${n === 1 ? "" : "s"}):
|
|
11885
|
-
${dumpPool(context.pool)}`;
|
|
11886
|
-
},
|
|
11887
11182
|
destroy: () => {
|
|
11888
11183
|
pendingFeedsRequests.forEach(
|
|
11889
11184
|
(request) => request.reject(new Error("Room destroyed"))
|
|
@@ -12075,7 +11370,11 @@ function isRoomEventName(value) {
|
|
|
12075
11370
|
}
|
|
12076
11371
|
function makeAuthDelegateForRoom(roomId, authManager) {
|
|
12077
11372
|
return async () => {
|
|
12078
|
-
return authManager.getAuthValue({
|
|
11373
|
+
return authManager.getAuthValue({
|
|
11374
|
+
roomId,
|
|
11375
|
+
resource: "presence",
|
|
11376
|
+
access: "read"
|
|
11377
|
+
});
|
|
12079
11378
|
};
|
|
12080
11379
|
}
|
|
12081
11380
|
function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
|
|
@@ -12165,7 +11464,9 @@ function createClient(options) {
|
|
|
12165
11464
|
),
|
|
12166
11465
|
authenticate: async () => {
|
|
12167
11466
|
const resp = await authManager.getAuthValue({
|
|
12168
|
-
|
|
11467
|
+
// TODO: Should we have permissions for AI Copilots?
|
|
11468
|
+
resource: "personal",
|
|
11469
|
+
access: "write"
|
|
12169
11470
|
});
|
|
12170
11471
|
if (resp.type === "public") {
|
|
12171
11472
|
throw new StopRetrying(
|
|
@@ -12391,7 +11692,6 @@ function createClient(options) {
|
|
|
12391
11692
|
{
|
|
12392
11693
|
enterRoom,
|
|
12393
11694
|
getRoom,
|
|
12394
|
-
_dump: () => Array.from(roomsById.values(), ({ room }) => room._dump()).join("\n\n"),
|
|
12395
11695
|
logout,
|
|
12396
11696
|
// Public inbox notifications API
|
|
12397
11697
|
getInboxNotifications: httpClient.getInboxNotifications,
|
|
@@ -12844,12 +12144,6 @@ function toPlainLson(lson) {
|
|
|
12844
12144
|
liveblocksType: "LiveList",
|
|
12845
12145
|
data: [...lson].map((item) => toPlainLson(item))
|
|
12846
12146
|
};
|
|
12847
|
-
} else if (lson instanceof LiveText) {
|
|
12848
|
-
return {
|
|
12849
|
-
liveblocksType: "LiveText",
|
|
12850
|
-
data: lson.toJSON(),
|
|
12851
|
-
version: lson.version
|
|
12852
|
-
};
|
|
12853
12147
|
} else {
|
|
12854
12148
|
return lson;
|
|
12855
12149
|
}
|
|
@@ -13031,7 +12325,6 @@ export {
|
|
|
13031
12325
|
LiveList,
|
|
13032
12326
|
LiveMap,
|
|
13033
12327
|
LiveObject,
|
|
13034
|
-
LiveText,
|
|
13035
12328
|
LiveblocksError,
|
|
13036
12329
|
MENTION_CHARACTER,
|
|
13037
12330
|
MutableSignal,
|
|
@@ -13043,7 +12336,6 @@ export {
|
|
|
13043
12336
|
SortedList,
|
|
13044
12337
|
TextEditorType,
|
|
13045
12338
|
WebsocketCloseCodes,
|
|
13046
|
-
applyLiveTextOperations,
|
|
13047
12339
|
asPos,
|
|
13048
12340
|
assert,
|
|
13049
12341
|
assertNever,
|
|
@@ -13070,7 +12362,6 @@ export {
|
|
|
13070
12362
|
createManagedPool,
|
|
13071
12363
|
createNotificationSettings,
|
|
13072
12364
|
createThreadId,
|
|
13073
|
-
deepLiveify,
|
|
13074
12365
|
defineAiTool,
|
|
13075
12366
|
deprecate,
|
|
13076
12367
|
deprecateIf,
|
|
@@ -13081,7 +12372,10 @@ export {
|
|
|
13081
12372
|
freeze,
|
|
13082
12373
|
generateUrl,
|
|
13083
12374
|
getMentionsFromCommentBody,
|
|
12375
|
+
getRoomPermissionConflicts,
|
|
13084
12376
|
getSubscriptionKey,
|
|
12377
|
+
hasPermissionCapability,
|
|
12378
|
+
hasPermissionCapabilityAccess,
|
|
13085
12379
|
html,
|
|
13086
12380
|
htmlSafe,
|
|
13087
12381
|
isCommentBodyLink,
|
|
@@ -13100,7 +12394,6 @@ export {
|
|
|
13100
12394
|
isRegisterStorageNode,
|
|
13101
12395
|
isRootStorageNode,
|
|
13102
12396
|
isStartsWithOperator,
|
|
13103
|
-
isTextStorageNode,
|
|
13104
12397
|
isUrl,
|
|
13105
12398
|
kInternal,
|
|
13106
12399
|
keys,
|
|
@@ -13113,8 +12406,12 @@ export {
|
|
|
13113
12406
|
nanoid,
|
|
13114
12407
|
nn,
|
|
13115
12408
|
nodeStreamToCompactNodes,
|
|
12409
|
+
normalizeRoomAccessesInput,
|
|
12410
|
+
normalizeRoomAccessesUpdateInput,
|
|
12411
|
+
normalizeRoomPermissionInput,
|
|
13116
12412
|
objectToQuery,
|
|
13117
12413
|
patchNotificationSettings,
|
|
12414
|
+
permissionCapabilitiesFromScopes,
|
|
13118
12415
|
raise,
|
|
13119
12416
|
resolveMentionsInCommentBody,
|
|
13120
12417
|
sanitizeUrl,
|