@liveblocks/core 3.20.0-exp6 → 3.20.0-perm1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +635 -1361
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -200
- package/dist/index.d.ts +88 -200
- package/dist/index.js +537 -1263
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
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 = "cjs";
|
|
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 (e8) {
|
|
@@ -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 (e9) {
|
|
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) => _nullishCoalesce(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: _optionalChain([options, 'optionalAccess', _22 => _22.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: _optionalChain([options, 'optionalAccess', _25 => _25.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: _optionalChain([options, 'optionalAccess', _26 => _26.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: _optionalChain([options, 'optionalAccess', _28 => _28.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
|
|
@@ -2645,7 +2565,7 @@ var HttpClient = class {
|
|
|
2645
2565
|
let body;
|
|
2646
2566
|
try {
|
|
2647
2567
|
body = await response.json();
|
|
2648
|
-
} catch (
|
|
2568
|
+
} catch (e9) {
|
|
2649
2569
|
body = {};
|
|
2650
2570
|
}
|
|
2651
2571
|
return body;
|
|
@@ -3845,7 +3765,7 @@ var ManagedSocket = class {
|
|
|
3845
3765
|
getStatus() {
|
|
3846
3766
|
try {
|
|
3847
3767
|
return toNewConnectionStatus(this.#machine);
|
|
3848
|
-
} catch (
|
|
3768
|
+
} catch (e10) {
|
|
3849
3769
|
return "initial";
|
|
3850
3770
|
}
|
|
3851
3771
|
}
|
|
@@ -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] = _nullishCoalesce(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 = _nullishCoalesce(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
|
+
_nullishCoalesce(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
|
+
);
|
|
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;
|
|
5251
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
|
+
_nullishCoalesce(cachedToken.permissions, () => ( [])),
|
|
5621
|
+
request.roomId
|
|
5622
|
+
);
|
|
5623
|
+
return capabilities !== void 0 && hasPermissionCapabilityAccess(
|
|
5624
|
+
capabilities,
|
|
5625
|
+
request.resource,
|
|
5626
|
+
request.access
|
|
5627
|
+
);
|
|
5628
|
+
}
|
|
5422
5629
|
function prepareAuthentication(authOptions) {
|
|
5423
5630
|
const { publicApiKey, authEndpoint } = authOptions;
|
|
5424
5631
|
if (authEndpoint !== void 0 && publicApiKey !== void 0) {
|
|
@@ -5511,24 +5718,18 @@ var OpCode = Object.freeze({
|
|
|
5511
5718
|
DELETE_CRDT: 5,
|
|
5512
5719
|
DELETE_OBJECT_KEY: 6,
|
|
5513
5720
|
CREATE_MAP: 7,
|
|
5514
|
-
CREATE_REGISTER: 8
|
|
5515
|
-
CREATE_TEXT: 9,
|
|
5516
|
-
UPDATE_TEXT: 10
|
|
5721
|
+
CREATE_REGISTER: 8
|
|
5517
5722
|
});
|
|
5518
5723
|
function isIgnoredOp(op) {
|
|
5519
5724
|
return op.type === OpCode.DELETE_CRDT && op.id === "ACK";
|
|
5520
5725
|
}
|
|
5521
|
-
function isCreateOp(op) {
|
|
5522
|
-
return op.type === OpCode.CREATE_OBJECT || op.type === OpCode.CREATE_REGISTER || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_LIST;
|
|
5523
|
-
}
|
|
5524
5726
|
|
|
5525
5727
|
// src/protocol/StorageNode.ts
|
|
5526
5728
|
var CrdtType = Object.freeze({
|
|
5527
5729
|
OBJECT: 0,
|
|
5528
5730
|
LIST: 1,
|
|
5529
5731
|
MAP: 2,
|
|
5530
|
-
REGISTER: 3
|
|
5531
|
-
TEXT: 4
|
|
5732
|
+
REGISTER: 3
|
|
5532
5733
|
});
|
|
5533
5734
|
function isRootStorageNode(node) {
|
|
5534
5735
|
return node[0] === "root";
|
|
@@ -5545,9 +5746,6 @@ function isMapStorageNode(node) {
|
|
|
5545
5746
|
function isRegisterStorageNode(node) {
|
|
5546
5747
|
return node[1].type === CrdtType.REGISTER;
|
|
5547
5748
|
}
|
|
5548
|
-
function isTextStorageNode(node) {
|
|
5549
|
-
return node[1].type === CrdtType.TEXT;
|
|
5550
|
-
}
|
|
5551
5749
|
function isCompactRootNode(node) {
|
|
5552
5750
|
return node[0] === "root";
|
|
5553
5751
|
}
|
|
@@ -5570,9 +5768,6 @@ function* compactNodesToNodeStream(compactNodes) {
|
|
|
5570
5768
|
case CrdtType.REGISTER:
|
|
5571
5769
|
yield [cnode[0], { type: CrdtType.REGISTER, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
5572
5770
|
break;
|
|
5573
|
-
case CrdtType.TEXT:
|
|
5574
|
-
yield [cnode[0], { type: CrdtType.TEXT, parentId: cnode[2], parentKey: cnode[3], data: cnode[4], version: cnode[5] }];
|
|
5575
|
-
break;
|
|
5576
5771
|
default:
|
|
5577
5772
|
}
|
|
5578
5773
|
}
|
|
@@ -5601,17 +5796,6 @@ function* nodeStreamToCompactNodes(nodes) {
|
|
|
5601
5796
|
const id = node[0];
|
|
5602
5797
|
const crdt = node[1];
|
|
5603
5798
|
yield [id, CrdtType.REGISTER, crdt.parentId, crdt.parentKey, crdt.data];
|
|
5604
|
-
} else if (isTextStorageNode(node)) {
|
|
5605
|
-
const id = node[0];
|
|
5606
|
-
const crdt = node[1];
|
|
5607
|
-
yield [
|
|
5608
|
-
id,
|
|
5609
|
-
CrdtType.TEXT,
|
|
5610
|
-
crdt.parentId,
|
|
5611
|
-
crdt.parentKey,
|
|
5612
|
-
crdt.data,
|
|
5613
|
-
crdt.version
|
|
5614
|
-
];
|
|
5615
5799
|
} else {
|
|
5616
5800
|
}
|
|
5617
5801
|
}
|
|
@@ -5796,112 +5980,12 @@ function asPos(str) {
|
|
|
5796
5980
|
return isPos(str) ? str : convertToPos(str);
|
|
5797
5981
|
}
|
|
5798
5982
|
|
|
5799
|
-
// src/crdts/UnacknowledgedOps.ts
|
|
5800
|
-
var UnacknowledgedOps = class {
|
|
5801
|
-
// opId -> op
|
|
5802
|
-
#byOpId = /* @__PURE__ */ new Map();
|
|
5803
|
-
// position -> (opId -> Create op)
|
|
5804
|
-
#createOpsByPosition = /* @__PURE__ */ new Map();
|
|
5805
|
-
// parentId -> (opId -> Create op)
|
|
5806
|
-
#createOpsByParent = /* @__PURE__ */ new Map();
|
|
5807
|
-
// opIds of pending ops that were in flight when a connection died, so the
|
|
5808
|
-
// server may already have processed them. See isPossiblyStored().
|
|
5809
|
-
#possiblyStoredOpIds = /* @__PURE__ */ new Set();
|
|
5810
|
-
#posKey(parentId, parentKey) {
|
|
5811
|
-
return `${parentId}
|
|
5812
|
-
${parentKey}`;
|
|
5813
|
-
}
|
|
5814
|
-
get size() {
|
|
5815
|
-
return this.#byOpId.size;
|
|
5816
|
-
}
|
|
5817
|
-
/**
|
|
5818
|
-
* Mark the given Op as still unacknowledged.
|
|
5819
|
-
*/
|
|
5820
|
-
add(op) {
|
|
5821
|
-
this.#byOpId.set(op.opId, op);
|
|
5822
|
-
if (isCreateOp(op)) {
|
|
5823
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5824
|
-
let atPosition = this.#createOpsByPosition.get(posKey);
|
|
5825
|
-
if (atPosition === void 0) {
|
|
5826
|
-
atPosition = /* @__PURE__ */ new Map();
|
|
5827
|
-
this.#createOpsByPosition.set(posKey, atPosition);
|
|
5828
|
-
}
|
|
5829
|
-
atPosition.set(op.opId, op);
|
|
5830
|
-
let inParent = this.#createOpsByParent.get(op.parentId);
|
|
5831
|
-
if (inParent === void 0) {
|
|
5832
|
-
inParent = /* @__PURE__ */ new Map();
|
|
5833
|
-
this.#createOpsByParent.set(op.parentId, inParent);
|
|
5834
|
-
}
|
|
5835
|
-
inParent.set(op.opId, op);
|
|
5836
|
-
}
|
|
5837
|
-
}
|
|
5838
|
-
/**
|
|
5839
|
-
* Drop the op with the given opId from the set, because the server has
|
|
5840
|
-
* acknowledged it (confirmed our own op, or signalled it was seen but
|
|
5841
|
-
* ignored).
|
|
5842
|
-
*/
|
|
5843
|
-
delete(opId) {
|
|
5844
|
-
const op = this.#byOpId.get(opId);
|
|
5845
|
-
if (op === void 0) {
|
|
5846
|
-
return;
|
|
5847
|
-
}
|
|
5848
|
-
this.#byOpId.delete(opId);
|
|
5849
|
-
this.#possiblyStoredOpIds.delete(opId);
|
|
5850
|
-
if (isCreateOp(op)) {
|
|
5851
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5852
|
-
const atPosition = this.#createOpsByPosition.get(posKey);
|
|
5853
|
-
_optionalChain([atPosition, 'optionalAccess', _111 => _111.delete, 'call', _112 => _112(opId)]);
|
|
5854
|
-
if (atPosition !== void 0 && atPosition.size === 0) {
|
|
5855
|
-
this.#createOpsByPosition.delete(posKey);
|
|
5856
|
-
}
|
|
5857
|
-
const inParent = this.#createOpsByParent.get(op.parentId);
|
|
5858
|
-
_optionalChain([inParent, 'optionalAccess', _113 => _113.delete, 'call', _114 => _114(opId)]);
|
|
5859
|
-
if (inParent !== void 0 && inParent.size === 0) {
|
|
5860
|
-
this.#createOpsByParent.delete(op.parentId);
|
|
5861
|
-
}
|
|
5862
|
-
}
|
|
5863
|
-
}
|
|
5864
|
-
/**
|
|
5865
|
-
* The still-unacknowledged Create ops with the given `parentId` and
|
|
5866
|
-
* `parentKey` (targeting one exact position), in dispatch order. O(1) lookup.
|
|
5867
|
-
* Empty if none.
|
|
5868
|
-
*/
|
|
5869
|
-
getByParentIdAndKey(parentId, parentKey) {
|
|
5870
|
-
return _nullishCoalesce(_optionalChain([this, 'access', _115 => _115.#createOpsByPosition, 'access', _116 => _116.get, 'call', _117 => _117(this.#posKey(parentId, parentKey)), 'optionalAccess', _118 => _118.values, 'call', _119 => _119()]), () => ( []));
|
|
5871
|
-
}
|
|
5872
|
-
/**
|
|
5873
|
-
* The still-unacknowledged Create ops with the given `parentId` (across all
|
|
5874
|
-
* positions), in dispatch order. O(1) lookup. Empty if none.
|
|
5875
|
-
*/
|
|
5876
|
-
getByParentId(parentId) {
|
|
5877
|
-
return _nullishCoalesce(_optionalChain([this, 'access', _120 => _120.#createOpsByParent, 'access', _121 => _121.get, 'call', _122 => _122(parentId), 'optionalAccess', _123 => _123.values, 'call', _124 => _124()]), () => ( []));
|
|
5878
|
-
}
|
|
5879
|
-
/** All still-unacknowledged ops, in dispatch order. */
|
|
5880
|
-
values() {
|
|
5881
|
-
return this.#byOpId.values();
|
|
5882
|
-
}
|
|
5883
|
-
isPossiblyStored(opId) {
|
|
5884
|
-
return this.#possiblyStoredOpIds.has(opId);
|
|
5885
|
-
}
|
|
5886
|
-
/**
|
|
5887
|
-
* Mark every currently pending op as possibly stored on the server. Called
|
|
5888
|
-
* when the connection dies: all of these ops were in flight, and their
|
|
5889
|
-
* (possibly lost) acks would have been the only way to know their fate.
|
|
5890
|
-
*/
|
|
5891
|
-
markAllAsPossiblyStored() {
|
|
5892
|
-
for (const opId of this.#byOpId.keys()) {
|
|
5893
|
-
this.#possiblyStoredOpIds.add(opId);
|
|
5894
|
-
}
|
|
5895
|
-
}
|
|
5896
|
-
};
|
|
5897
|
-
|
|
5898
5983
|
// src/crdts/AbstractCrdt.ts
|
|
5899
5984
|
function createManagedPool(roomId, options) {
|
|
5900
5985
|
const {
|
|
5901
5986
|
getCurrentConnectionId,
|
|
5902
5987
|
onDispatch,
|
|
5903
|
-
isStorageWritable = () => true
|
|
5904
|
-
unacknowledgedOps = new UnacknowledgedOps()
|
|
5988
|
+
isStorageWritable = () => true
|
|
5905
5989
|
} = options;
|
|
5906
5990
|
let clock = 0;
|
|
5907
5991
|
let opClock = 0;
|
|
@@ -5915,7 +5999,7 @@ function createManagedPool(roomId, options) {
|
|
|
5915
5999
|
generateId: () => `${getCurrentConnectionId()}:${clock++}`,
|
|
5916
6000
|
generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
|
|
5917
6001
|
dispatch(ops, reverse, storageUpdates) {
|
|
5918
|
-
_optionalChain([onDispatch, 'optionalCall',
|
|
6002
|
+
_optionalChain([onDispatch, 'optionalCall', _111 => _111(ops, reverse, storageUpdates)]);
|
|
5919
6003
|
},
|
|
5920
6004
|
assertStorageIsWritable: () => {
|
|
5921
6005
|
if (!isStorageWritable()) {
|
|
@@ -5923,8 +6007,7 @@ function createManagedPool(roomId, options) {
|
|
|
5923
6007
|
"Cannot write to storage with a read only user, please ensure the user has write permissions"
|
|
5924
6008
|
);
|
|
5925
6009
|
}
|
|
5926
|
-
}
|
|
5927
|
-
unacknowledgedOps
|
|
6010
|
+
}
|
|
5928
6011
|
};
|
|
5929
6012
|
}
|
|
5930
6013
|
function crdtAsLiveNode(value) {
|
|
@@ -6206,9 +6289,11 @@ function childNodeLt(a, b) {
|
|
|
6206
6289
|
var LiveList = class _LiveList extends AbstractCrdt {
|
|
6207
6290
|
#items;
|
|
6208
6291
|
#implicitlyDeletedItems;
|
|
6292
|
+
#unacknowledgedSets;
|
|
6209
6293
|
constructor(items) {
|
|
6210
6294
|
super();
|
|
6211
6295
|
this.#implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
|
|
6296
|
+
this.#unacknowledgedSets = /* @__PURE__ */ new Map();
|
|
6212
6297
|
const nodes = [];
|
|
6213
6298
|
let lastPos;
|
|
6214
6299
|
for (const item of items) {
|
|
@@ -6238,13 +6323,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6238
6323
|
}
|
|
6239
6324
|
/**
|
|
6240
6325
|
* @internal
|
|
6241
|
-
*
|
|
6242
|
-
*
|
|
6243
|
-
*
|
|
6244
|
-
* items (flicker, https://github.com/liveblocks/liveblocks/pull/1177).
|
|
6326
|
+
* This function assumes that the resulting ops will be sent to the server if they have an 'opId'
|
|
6327
|
+
* so we mutate _unacknowledgedSets to avoid potential flickering
|
|
6328
|
+
* https://github.com/liveblocks/liveblocks/pull/1177
|
|
6245
6329
|
*
|
|
6246
|
-
* This is quite unintuitive and should disappear as soon as
|
|
6247
|
-
* explicit LiveList.Set operation
|
|
6330
|
+
* This is quite unintuitive and should disappear as soon as
|
|
6331
|
+
* we introduce an explicit LiveList.Set operation
|
|
6248
6332
|
*/
|
|
6249
6333
|
_toOps(parentId, parentKey) {
|
|
6250
6334
|
if (this._id === void 0) {
|
|
@@ -6260,9 +6344,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6260
6344
|
ops.push(op);
|
|
6261
6345
|
for (const item of this.#items) {
|
|
6262
6346
|
const parentKey2 = item._getParentKeyOrThrow();
|
|
6263
|
-
const childOps =
|
|
6347
|
+
const childOps = HACK_addIntentAndDeletedIdToOperation(
|
|
6264
6348
|
item._toOps(this._id, parentKey2),
|
|
6265
|
-
|
|
6349
|
+
void 0
|
|
6266
6350
|
);
|
|
6267
6351
|
for (const childOp of childOps) {
|
|
6268
6352
|
ops.push(childOp);
|
|
@@ -6304,28 +6388,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6304
6388
|
(item) => item._getParentKeyOrThrow() === position
|
|
6305
6389
|
);
|
|
6306
6390
|
}
|
|
6307
|
-
/**
|
|
6308
|
-
* The opId of this list's still-unacknowledged "set" op at the given position,
|
|
6309
|
-
* or undefined if none. Derived from the room's unacknowledgedOps (the single
|
|
6310
|
-
* source of truth) rather than tracked in a per-instance map. The pool's
|
|
6311
|
-
* position index already scopes to this list's (parentId, position); the last
|
|
6312
|
-
* match wins, matching the original last-write-wins map semantics.
|
|
6313
|
-
*/
|
|
6314
|
-
#unacknowledgedSetOpIdAt(position) {
|
|
6315
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6316
|
-
return void 0;
|
|
6317
|
-
}
|
|
6318
|
-
let opId;
|
|
6319
|
-
for (const op of this._pool.unacknowledgedOps.getByParentIdAndKey(
|
|
6320
|
-
this._id,
|
|
6321
|
-
position
|
|
6322
|
-
)) {
|
|
6323
|
-
if (op.intent === "set") {
|
|
6324
|
-
opId = op.opId;
|
|
6325
|
-
}
|
|
6326
|
-
}
|
|
6327
|
-
return opId;
|
|
6328
|
-
}
|
|
6329
6391
|
/** @internal */
|
|
6330
6392
|
_attach(id, pool) {
|
|
6331
6393
|
super._attach(id, pool);
|
|
@@ -6406,9 +6468,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6406
6468
|
if (deletedDelta) {
|
|
6407
6469
|
delta.push(deletedDelta);
|
|
6408
6470
|
}
|
|
6409
|
-
const unacknowledgedOpId = this.#
|
|
6410
|
-
if (unacknowledgedOpId !== void 0
|
|
6411
|
-
|
|
6471
|
+
const unacknowledgedOpId = this.#unacknowledgedSets.get(op.parentKey);
|
|
6472
|
+
if (unacknowledgedOpId !== void 0) {
|
|
6473
|
+
if (unacknowledgedOpId !== op.opId) {
|
|
6474
|
+
return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
|
|
6475
|
+
} else {
|
|
6476
|
+
this.#unacknowledgedSets.delete(op.parentKey);
|
|
6477
|
+
}
|
|
6412
6478
|
}
|
|
6413
6479
|
const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
|
|
6414
6480
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
@@ -6499,92 +6565,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6499
6565
|
this.#shiftItemPosition(existingItemIndex, key);
|
|
6500
6566
|
}
|
|
6501
6567
|
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
6502
|
-
const bumpDeltas = this.#bumpUnackedPushesAbove(key);
|
|
6503
6568
|
return {
|
|
6504
|
-
modified: makeUpdate(this, [
|
|
6505
|
-
insertDelta(newIndex, newItem),
|
|
6506
|
-
...bumpDeltas
|
|
6507
|
-
]),
|
|
6569
|
+
modified: makeUpdate(this, [insertDelta(newIndex, newItem)]),
|
|
6508
6570
|
reverse: []
|
|
6509
6571
|
};
|
|
6510
6572
|
}
|
|
6511
|
-
/**
|
|
6512
|
-
* This list's own still-unacknowledged pushed items (their `intent: "push"`
|
|
6513
|
-
* Create op is still pending in the room's unacknowledgedOps). Derived from
|
|
6514
|
-
* the single source of truth, so an item drops out the instant its op is
|
|
6515
|
-
* acked, with no per-instance membership to leak. Yielded in push order.
|
|
6516
|
-
*
|
|
6517
|
-
* Excludes ops that may already be stored on the server (they were in
|
|
6518
|
-
* flight when a connection died, so their fate is unknown): the bump
|
|
6519
|
-
* prediction assumes the server has not processed the op yet, which is only
|
|
6520
|
-
* guaranteed for ops sent on the current connection. For these excluded
|
|
6521
|
-
* ops, the server's (re-)ack states the authoritative position; predicting
|
|
6522
|
-
* locally could produce a wrong position that no ack would correct.
|
|
6523
|
-
*
|
|
6524
|
-
* Restricted to items currently in `#items`: a pushed node whose op is still
|
|
6525
|
-
* pending may have been pulled out of the list (e.g. implicitly deleted by a
|
|
6526
|
-
* remote set, or removed by an undo) while still living in the pool, and such
|
|
6527
|
-
* a node must not be repositioned.
|
|
6528
|
-
*/
|
|
6529
|
-
*#unackedPushNodes() {
|
|
6530
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6531
|
-
return;
|
|
6532
|
-
}
|
|
6533
|
-
for (const op of this._pool.unacknowledgedOps.getByParentId(this._id)) {
|
|
6534
|
-
if (op.intent !== "push") {
|
|
6535
|
-
continue;
|
|
6536
|
-
}
|
|
6537
|
-
if (this._pool.unacknowledgedOps.isPossiblyStored(op.opId)) {
|
|
6538
|
-
continue;
|
|
6539
|
-
}
|
|
6540
|
-
const node = this._pool.getNode(op.id);
|
|
6541
|
-
if (node !== void 0 && this.#items.includes(node)) {
|
|
6542
|
-
yield node;
|
|
6543
|
-
}
|
|
6544
|
-
}
|
|
6545
|
-
}
|
|
6546
|
-
/**
|
|
6547
|
-
* Optimistic no-flip for pushed items. When a remote op lands at or below my
|
|
6548
|
-
* still-unacked pushed items, those items must end up *after* it: FIFO plus
|
|
6549
|
-
* the room's serial processing guarantee the remote was processed first, so
|
|
6550
|
-
* my unacked pushes belong behind it. Re-chain the whole unacked-push block,
|
|
6551
|
-
* in push order, to sit after the highest confirmed sibling, so it keeps
|
|
6552
|
-
* rendering as a contiguous tail instead of getting interleaved. Local-only;
|
|
6553
|
-
* the real acks overwrite these keys with the (identical) server keys.
|
|
6554
|
-
*/
|
|
6555
|
-
#bumpUnackedPushesAbove(remoteKey) {
|
|
6556
|
-
const pending = new Set(this.#unackedPushNodes());
|
|
6557
|
-
if (pending.size === 0) {
|
|
6558
|
-
return [];
|
|
6559
|
-
}
|
|
6560
|
-
let minPending;
|
|
6561
|
-
for (const node of pending) {
|
|
6562
|
-
const pos = node._parentPos;
|
|
6563
|
-
if (minPending === void 0 || pos < minPending) {
|
|
6564
|
-
minPending = pos;
|
|
6565
|
-
}
|
|
6566
|
-
}
|
|
6567
|
-
if (remoteKey < nn(minPending)) {
|
|
6568
|
-
return [];
|
|
6569
|
-
}
|
|
6570
|
-
let base;
|
|
6571
|
-
for (const item of this.#items) {
|
|
6572
|
-
if (!pending.has(item)) {
|
|
6573
|
-
base = item._parentPos;
|
|
6574
|
-
}
|
|
6575
|
-
}
|
|
6576
|
-
const deltas = [];
|
|
6577
|
-
for (const node of pending) {
|
|
6578
|
-
const previousIndex = this.#items.findIndex((item) => item === node);
|
|
6579
|
-
base = makePosition(base);
|
|
6580
|
-
this.#updateItemPosition(node, base);
|
|
6581
|
-
const index = this.#items.findIndex((item) => item === node);
|
|
6582
|
-
if (index !== previousIndex) {
|
|
6583
|
-
deltas.push(moveDelta(previousIndex, index, node));
|
|
6584
|
-
}
|
|
6585
|
-
}
|
|
6586
|
-
return deltas;
|
|
6587
|
-
}
|
|
6588
6573
|
#applyInsertAck(op) {
|
|
6589
6574
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
6590
6575
|
const key = asPos(op.parentKey);
|
|
@@ -6639,7 +6624,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6639
6624
|
#applyInsertUndoRedo(op) {
|
|
6640
6625
|
const { id, parentKey: key } = op;
|
|
6641
6626
|
const child = creationOpToLiveNode(op);
|
|
6642
|
-
if (_optionalChain([this, 'access',
|
|
6627
|
+
if (_optionalChain([this, 'access', _112 => _112._pool, 'optionalAccess', _113 => _113.getNode, 'call', _114 => _114(id)]) !== void 0) {
|
|
6643
6628
|
return { modified: false };
|
|
6644
6629
|
}
|
|
6645
6630
|
child._attach(id, nn(this._pool));
|
|
@@ -6647,8 +6632,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6647
6632
|
const existingItemIndex = this._indexOfPosition(key);
|
|
6648
6633
|
let newKey = key;
|
|
6649
6634
|
if (existingItemIndex !== -1) {
|
|
6650
|
-
const before2 = _optionalChain([this, 'access',
|
|
6651
|
-
const after2 = _optionalChain([this, 'access',
|
|
6635
|
+
const before2 = _optionalChain([this, 'access', _115 => _115.#items, 'access', _116 => _116.at, 'call', _117 => _117(existingItemIndex), 'optionalAccess', _118 => _118._parentPos]);
|
|
6636
|
+
const after2 = _optionalChain([this, 'access', _119 => _119.#items, 'access', _120 => _120.at, 'call', _121 => _121(existingItemIndex + 1), 'optionalAccess', _122 => _122._parentPos]);
|
|
6652
6637
|
newKey = makePosition(before2, after2);
|
|
6653
6638
|
child._setParentLink(this, newKey);
|
|
6654
6639
|
}
|
|
@@ -6662,9 +6647,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6662
6647
|
#applySetUndoRedo(op) {
|
|
6663
6648
|
const { id, parentKey: key } = op;
|
|
6664
6649
|
const child = creationOpToLiveNode(op);
|
|
6665
|
-
if (_optionalChain([this, 'access',
|
|
6650
|
+
if (_optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.getNode, 'call', _125 => _125(id)]) !== void 0) {
|
|
6666
6651
|
return { modified: false };
|
|
6667
6652
|
}
|
|
6653
|
+
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
6668
6654
|
const indexOfItemWithSameKey = this._indexOfPosition(key);
|
|
6669
6655
|
child._attach(id, nn(this._pool));
|
|
6670
6656
|
child._setParentLink(this, key);
|
|
@@ -6674,9 +6660,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6674
6660
|
existingItem._detach();
|
|
6675
6661
|
this.#items.remove(existingItem);
|
|
6676
6662
|
this.#items.add(child);
|
|
6677
|
-
const reverse =
|
|
6663
|
+
const reverse = HACK_addIntentAndDeletedIdToOperation(
|
|
6678
6664
|
existingItem._toOps(nn(this._id), key),
|
|
6679
|
-
"set",
|
|
6680
6665
|
op.id
|
|
6681
6666
|
);
|
|
6682
6667
|
const delta = [setDelta(indexOfItemWithSameKey, child)];
|
|
@@ -6783,7 +6768,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6783
6768
|
} else {
|
|
6784
6769
|
this.#updateItemPositionAt(
|
|
6785
6770
|
existingItemIndex,
|
|
6786
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6771
|
+
makePosition(newKey, _optionalChain([this, 'access', _126 => _126.#items, 'access', _127 => _127.at, 'call', _128 => _128(existingItemIndex + 1), 'optionalAccess', _129 => _129._parentPos]))
|
|
6787
6772
|
);
|
|
6788
6773
|
const previousIndex = this.#items.findIndex((item) => item === child);
|
|
6789
6774
|
this.#updateItemPosition(child, newKey);
|
|
@@ -6810,7 +6795,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6810
6795
|
this,
|
|
6811
6796
|
makePosition(
|
|
6812
6797
|
newKey,
|
|
6813
|
-
_optionalChain([this, 'access',
|
|
6798
|
+
_optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131.at, 'call', _132 => _132(existingItemIndex + 1), 'optionalAccess', _133 => _133._parentPos])
|
|
6814
6799
|
)
|
|
6815
6800
|
);
|
|
6816
6801
|
this.#items.reposition(existingItem);
|
|
@@ -6834,7 +6819,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6834
6819
|
existingItemIndex,
|
|
6835
6820
|
makePosition(
|
|
6836
6821
|
newKey,
|
|
6837
|
-
_optionalChain([this, 'access',
|
|
6822
|
+
_optionalChain([this, 'access', _134 => _134.#items, 'access', _135 => _135.at, 'call', _136 => _136(existingItemIndex + 1), 'optionalAccess', _137 => _137._parentPos])
|
|
6838
6823
|
)
|
|
6839
6824
|
);
|
|
6840
6825
|
}
|
|
@@ -6862,7 +6847,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6862
6847
|
if (existingItemIndex !== -1) {
|
|
6863
6848
|
actualNewKey = makePosition(
|
|
6864
6849
|
newKey,
|
|
6865
|
-
_optionalChain([this, 'access',
|
|
6850
|
+
_optionalChain([this, 'access', _138 => _138.#items, 'access', _139 => _139.at, 'call', _140 => _140(existingItemIndex + 1), 'optionalAccess', _141 => _141._parentPos])
|
|
6866
6851
|
);
|
|
6867
6852
|
}
|
|
6868
6853
|
this.#updateItemPosition(child, actualNewKey);
|
|
@@ -6919,7 +6904,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6919
6904
|
* @param element The element to add to the end of the LiveList.
|
|
6920
6905
|
*/
|
|
6921
6906
|
push(element) {
|
|
6922
|
-
|
|
6907
|
+
_optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
|
|
6908
|
+
return this.insert(element, this.length);
|
|
6923
6909
|
}
|
|
6924
6910
|
/**
|
|
6925
6911
|
* Inserts one element at a specified index.
|
|
@@ -6927,23 +6913,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6927
6913
|
* @param index The index at which you want to insert the element.
|
|
6928
6914
|
*/
|
|
6929
6915
|
insert(element, index) {
|
|
6930
|
-
|
|
6931
|
-
}
|
|
6932
|
-
/**
|
|
6933
|
-
* Shared implementation of `insert` and `push`. A `"push"` intent leaves the
|
|
6934
|
-
* client-computed position untouched (so optimistic rendering is unchanged),
|
|
6935
|
-
* but tags the Op so the server appends it to the true end of the list
|
|
6936
|
-
* instead of resolving its position against the client's stale view.
|
|
6937
|
-
*/
|
|
6938
|
-
#injectAt(element, index, intent) {
|
|
6939
|
-
_optionalChain([this, 'access', _156 => _156._pool, 'optionalAccess', _157 => _157.assertStorageIsWritable, 'call', _158 => _158()]);
|
|
6916
|
+
_optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
|
|
6940
6917
|
if (index < 0 || index > this.#items.length) {
|
|
6941
6918
|
throw new Error(
|
|
6942
6919
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
6943
6920
|
);
|
|
6944
6921
|
}
|
|
6945
|
-
const before2 = _optionalChain([this, 'access',
|
|
6946
|
-
const after2 = _optionalChain([this, 'access',
|
|
6922
|
+
const before2 = _optionalChain([this, 'access', _148 => _148.#items, 'access', _149 => _149.at, 'call', _150 => _150(index - 1), 'optionalAccess', _151 => _151._parentPos]);
|
|
6923
|
+
const after2 = _optionalChain([this, 'access', _152 => _152.#items, 'access', _153 => _153.at, 'call', _154 => _154(index), 'optionalAccess', _155 => _155._parentPos]);
|
|
6947
6924
|
const position = makePosition(before2, after2);
|
|
6948
6925
|
const value = lsonToLiveNode(element);
|
|
6949
6926
|
value._setParentLink(this, position);
|
|
@@ -6951,9 +6928,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6951
6928
|
if (this._pool && this._id) {
|
|
6952
6929
|
const id = this._pool.generateId();
|
|
6953
6930
|
value._attach(id, this._pool);
|
|
6954
|
-
const ops = value._toOpsWithOpId(this._id, position, this._pool);
|
|
6955
6931
|
this._pool.dispatch(
|
|
6956
|
-
|
|
6932
|
+
value._toOpsWithOpId(this._id, position, this._pool),
|
|
6957
6933
|
[{ type: OpCode.DELETE_CRDT, id }],
|
|
6958
6934
|
/* @__PURE__ */ new Map([
|
|
6959
6935
|
[this._id, makeUpdate(this, [insertDelta(index, value)])]
|
|
@@ -6967,7 +6943,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6967
6943
|
* @param targetIndex The index where the element should be after moving.
|
|
6968
6944
|
*/
|
|
6969
6945
|
move(index, targetIndex) {
|
|
6970
|
-
_optionalChain([this, 'access',
|
|
6946
|
+
_optionalChain([this, 'access', _156 => _156._pool, 'optionalAccess', _157 => _157.assertStorageIsWritable, 'call', _158 => _158()]);
|
|
6971
6947
|
if (targetIndex < 0) {
|
|
6972
6948
|
throw new Error("targetIndex cannot be less than 0");
|
|
6973
6949
|
}
|
|
@@ -6985,11 +6961,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6985
6961
|
let beforePosition = null;
|
|
6986
6962
|
let afterPosition = null;
|
|
6987
6963
|
if (index < targetIndex) {
|
|
6988
|
-
afterPosition = targetIndex === this.#items.length - 1 ? void 0 : _optionalChain([this, 'access',
|
|
6964
|
+
afterPosition = targetIndex === this.#items.length - 1 ? void 0 : _optionalChain([this, 'access', _159 => _159.#items, 'access', _160 => _160.at, 'call', _161 => _161(targetIndex + 1), 'optionalAccess', _162 => _162._parentPos]);
|
|
6989
6965
|
beforePosition = this.#items.at(targetIndex)._parentPos;
|
|
6990
6966
|
} else {
|
|
6991
6967
|
afterPosition = this.#items.at(targetIndex)._parentPos;
|
|
6992
|
-
beforePosition = targetIndex === 0 ? void 0 : _optionalChain([this, 'access',
|
|
6968
|
+
beforePosition = targetIndex === 0 ? void 0 : _optionalChain([this, 'access', _163 => _163.#items, 'access', _164 => _164.at, 'call', _165 => _165(targetIndex - 1), 'optionalAccess', _166 => _166._parentPos]);
|
|
6993
6969
|
}
|
|
6994
6970
|
const position = makePosition(beforePosition, afterPosition);
|
|
6995
6971
|
const item = this.#items.at(index);
|
|
@@ -7024,7 +7000,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7024
7000
|
* @param index The index of the element to delete
|
|
7025
7001
|
*/
|
|
7026
7002
|
delete(index) {
|
|
7027
|
-
_optionalChain([this, 'access',
|
|
7003
|
+
_optionalChain([this, 'access', _167 => _167._pool, 'optionalAccess', _168 => _168.assertStorageIsWritable, 'call', _169 => _169()]);
|
|
7028
7004
|
if (index < 0 || index >= this.#items.length) {
|
|
7029
7005
|
throw new Error(
|
|
7030
7006
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -7057,7 +7033,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7057
7033
|
}
|
|
7058
7034
|
}
|
|
7059
7035
|
clear() {
|
|
7060
|
-
_optionalChain([this, 'access',
|
|
7036
|
+
_optionalChain([this, 'access', _170 => _170._pool, 'optionalAccess', _171 => _171.assertStorageIsWritable, 'call', _172 => _172()]);
|
|
7061
7037
|
if (this._pool) {
|
|
7062
7038
|
const ops = [];
|
|
7063
7039
|
const reverseOps = [];
|
|
@@ -7091,7 +7067,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7091
7067
|
}
|
|
7092
7068
|
}
|
|
7093
7069
|
set(index, item) {
|
|
7094
|
-
_optionalChain([this, 'access',
|
|
7070
|
+
_optionalChain([this, 'access', _173 => _173._pool, 'optionalAccess', _174 => _174.assertStorageIsWritable, 'call', _175 => _175()]);
|
|
7095
7071
|
if (index < 0 || index >= this.#items.length) {
|
|
7096
7072
|
throw new Error(
|
|
7097
7073
|
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -7111,14 +7087,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7111
7087
|
value._attach(id, this._pool);
|
|
7112
7088
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7113
7089
|
storageUpdates.set(this._id, makeUpdate(this, [setDelta(index, value)]));
|
|
7114
|
-
const ops =
|
|
7090
|
+
const ops = HACK_addIntentAndDeletedIdToOperation(
|
|
7115
7091
|
value._toOpsWithOpId(this._id, position, this._pool),
|
|
7116
|
-
"set",
|
|
7117
7092
|
existingId
|
|
7118
7093
|
);
|
|
7119
|
-
|
|
7094
|
+
this.#unacknowledgedSets.set(position, nn(ops[0].opId));
|
|
7095
|
+
const reverseOps = HACK_addIntentAndDeletedIdToOperation(
|
|
7120
7096
|
existingItem._toOps(this._id, position),
|
|
7121
|
-
"set",
|
|
7122
7097
|
id
|
|
7123
7098
|
);
|
|
7124
7099
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
@@ -7250,7 +7225,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7250
7225
|
#shiftItemPosition(index, key) {
|
|
7251
7226
|
const shiftedPosition = makePosition(
|
|
7252
7227
|
key,
|
|
7253
|
-
this.#items.length > index + 1 ? _optionalChain([this, 'access',
|
|
7228
|
+
this.#items.length > index + 1 ? _optionalChain([this, 'access', _176 => _176.#items, 'access', _177 => _177.at, 'call', _178 => _178(index + 1), 'optionalAccess', _179 => _179._parentPos]) : void 0
|
|
7254
7229
|
);
|
|
7255
7230
|
this.#updateItemPositionAt(index, shiftedPosition);
|
|
7256
7231
|
}
|
|
@@ -7319,11 +7294,15 @@ function moveDelta(previousIndex, index, item) {
|
|
|
7319
7294
|
previousIndex
|
|
7320
7295
|
};
|
|
7321
7296
|
}
|
|
7322
|
-
function
|
|
7297
|
+
function HACK_addIntentAndDeletedIdToOperation(ops, deletedId) {
|
|
7323
7298
|
return ops.map((op, index) => {
|
|
7324
7299
|
if (index === 0) {
|
|
7325
7300
|
const firstOp = op;
|
|
7326
|
-
return {
|
|
7301
|
+
return {
|
|
7302
|
+
...firstOp,
|
|
7303
|
+
intent: "set",
|
|
7304
|
+
deletedId
|
|
7305
|
+
};
|
|
7327
7306
|
} else {
|
|
7328
7307
|
return op;
|
|
7329
7308
|
}
|
|
@@ -7499,7 +7478,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7499
7478
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
7500
7479
|
*/
|
|
7501
7480
|
set(key, value) {
|
|
7502
|
-
_optionalChain([this, 'access',
|
|
7481
|
+
_optionalChain([this, 'access', _180 => _180._pool, 'optionalAccess', _181 => _181.assertStorageIsWritable, 'call', _182 => _182()]);
|
|
7503
7482
|
const oldValue = this.#map.get(key);
|
|
7504
7483
|
if (oldValue) {
|
|
7505
7484
|
oldValue._detach();
|
|
@@ -7545,7 +7524,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7545
7524
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
7546
7525
|
*/
|
|
7547
7526
|
delete(key) {
|
|
7548
|
-
_optionalChain([this, 'access',
|
|
7527
|
+
_optionalChain([this, 'access', _183 => _183._pool, 'optionalAccess', _184 => _184.assertStorageIsWritable, 'call', _185 => _185()]);
|
|
7549
7528
|
const item = this.#map.get(key);
|
|
7550
7529
|
if (item === void 0) {
|
|
7551
7530
|
return false;
|
|
@@ -7975,7 +7954,6 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7975
7954
|
const id = nn(this._id);
|
|
7976
7955
|
const parentKey = nn(child._parentKey);
|
|
7977
7956
|
const reverse = child._toOps(id, parentKey);
|
|
7978
|
-
const deletedItem = liveNodeToLson(child);
|
|
7979
7957
|
for (const [key, value] of this.#synced) {
|
|
7980
7958
|
if (value === child) {
|
|
7981
7959
|
this.#synced.delete(key);
|
|
@@ -7987,7 +7965,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7987
7965
|
node: this,
|
|
7988
7966
|
type: "LiveObject",
|
|
7989
7967
|
updates: {
|
|
7990
|
-
[parentKey]: { type: "delete"
|
|
7968
|
+
[parentKey]: { type: "delete" }
|
|
7991
7969
|
}
|
|
7992
7970
|
};
|
|
7993
7971
|
return { modified: storageUpdate, reverse };
|
|
@@ -8157,20 +8135,20 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8157
8135
|
* Caveat: this method will not add changes to the undo/redo stack.
|
|
8158
8136
|
*/
|
|
8159
8137
|
setLocal(key, value) {
|
|
8160
|
-
_optionalChain([this, 'access',
|
|
8138
|
+
_optionalChain([this, 'access', _186 => _186._pool, 'optionalAccess', _187 => _187.assertStorageIsWritable, 'call', _188 => _188()]);
|
|
8161
8139
|
const deleteResult = this.#prepareDelete(key);
|
|
8162
8140
|
this.#local.set(key, value);
|
|
8163
8141
|
this.invalidate();
|
|
8164
8142
|
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8165
|
-
const ops = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess',
|
|
8166
|
-
const reverse = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess',
|
|
8167
|
-
const storageUpdates = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess',
|
|
8143
|
+
const ops = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _189 => _189[0]]), () => ( []));
|
|
8144
|
+
const reverse = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _190 => _190[1]]), () => ( []));
|
|
8145
|
+
const storageUpdates = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess', _191 => _191[2]]), () => ( /* @__PURE__ */ new Map()));
|
|
8168
8146
|
const existing = storageUpdates.get(this._id);
|
|
8169
8147
|
storageUpdates.set(this._id, {
|
|
8170
8148
|
node: this,
|
|
8171
8149
|
type: "LiveObject",
|
|
8172
8150
|
updates: {
|
|
8173
|
-
..._optionalChain([existing, 'optionalAccess',
|
|
8151
|
+
..._optionalChain([existing, 'optionalAccess', _192 => _192.updates]),
|
|
8174
8152
|
[key]: { type: "update" }
|
|
8175
8153
|
}
|
|
8176
8154
|
});
|
|
@@ -8190,7 +8168,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8190
8168
|
* #synced or pool/id are unavailable. Does NOT dispatch.
|
|
8191
8169
|
*/
|
|
8192
8170
|
#prepareDelete(key) {
|
|
8193
|
-
_optionalChain([this, 'access',
|
|
8171
|
+
_optionalChain([this, 'access', _193 => _193._pool, 'optionalAccess', _194 => _194.assertStorageIsWritable, 'call', _195 => _195()]);
|
|
8194
8172
|
const k = key;
|
|
8195
8173
|
if (this.#local.has(k) && !this.#synced.has(k)) {
|
|
8196
8174
|
const oldValue2 = this.#local.get(k);
|
|
@@ -8266,7 +8244,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8266
8244
|
const result = this.#prepareDelete(key);
|
|
8267
8245
|
if (result) {
|
|
8268
8246
|
const [ops, reverse, storageUpdates] = result;
|
|
8269
|
-
_optionalChain([this, 'access',
|
|
8247
|
+
_optionalChain([this, 'access', _196 => _196._pool, 'optionalAccess', _197 => _197.dispatch, 'call', _198 => _198(ops, reverse, storageUpdates)]);
|
|
8270
8248
|
}
|
|
8271
8249
|
}
|
|
8272
8250
|
/**
|
|
@@ -8274,7 +8252,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8274
8252
|
* @param patch The object used to overrides properties
|
|
8275
8253
|
*/
|
|
8276
8254
|
update(patch) {
|
|
8277
|
-
_optionalChain([this, 'access',
|
|
8255
|
+
_optionalChain([this, 'access', _199 => _199._pool, 'optionalAccess', _200 => _200.assertStorageIsWritable, 'call', _201 => _201()]);
|
|
8278
8256
|
if (_LiveObject.detectLargeObjects) {
|
|
8279
8257
|
const data = {};
|
|
8280
8258
|
for (const [key, value] of this.#synced) {
|
|
@@ -8474,580 +8452,6 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8474
8452
|
}
|
|
8475
8453
|
}, _class2.__initStatic(), _class2);
|
|
8476
8454
|
|
|
8477
|
-
// src/crdts/liveTextOps.ts
|
|
8478
|
-
function attributesEqual(left, right) {
|
|
8479
|
-
if (left === right) {
|
|
8480
|
-
return true;
|
|
8481
|
-
}
|
|
8482
|
-
if (left === void 0 || right === void 0) {
|
|
8483
|
-
return false;
|
|
8484
|
-
}
|
|
8485
|
-
const leftKeys = Object.keys(left);
|
|
8486
|
-
const rightKeys = Object.keys(right);
|
|
8487
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
8488
|
-
return false;
|
|
8489
|
-
}
|
|
8490
|
-
for (const key of leftKeys) {
|
|
8491
|
-
if (left[key] !== right[key]) {
|
|
8492
|
-
return false;
|
|
8493
|
-
}
|
|
8494
|
-
}
|
|
8495
|
-
return true;
|
|
8496
|
-
}
|
|
8497
|
-
function cloneAttributes(attributes) {
|
|
8498
|
-
return attributes === void 0 ? void 0 : freeze({ ...attributes });
|
|
8499
|
-
}
|
|
8500
|
-
function normalizeSegments(segments) {
|
|
8501
|
-
const normalized = [];
|
|
8502
|
-
for (const segment of segments) {
|
|
8503
|
-
if (segment.text.length === 0) {
|
|
8504
|
-
continue;
|
|
8505
|
-
}
|
|
8506
|
-
const last = normalized.at(-1);
|
|
8507
|
-
const attributes = cloneAttributes(segment.attributes);
|
|
8508
|
-
if (last !== void 0 && attributesEqual(last.attributes, attributes)) {
|
|
8509
|
-
last.text += segment.text;
|
|
8510
|
-
} else {
|
|
8511
|
-
normalized.push({ text: segment.text, attributes });
|
|
8512
|
-
}
|
|
8513
|
-
}
|
|
8514
|
-
return normalized;
|
|
8515
|
-
}
|
|
8516
|
-
function dataToSegments(data) {
|
|
8517
|
-
return normalizeSegments(
|
|
8518
|
-
data.map(([text, attributes]) => ({
|
|
8519
|
-
text,
|
|
8520
|
-
attributes
|
|
8521
|
-
}))
|
|
8522
|
-
);
|
|
8523
|
-
}
|
|
8524
|
-
function segmentsToData(segments) {
|
|
8525
|
-
return segments.map(
|
|
8526
|
-
(segment) => segment.attributes === void 0 ? [segment.text] : [segment.text, { ...segment.attributes }]
|
|
8527
|
-
);
|
|
8528
|
-
}
|
|
8529
|
-
function textLength(segments) {
|
|
8530
|
-
return segments.reduce((sum, segment) => sum + segment.text.length, 0);
|
|
8531
|
-
}
|
|
8532
|
-
function splitSegmentsAt(segments, index) {
|
|
8533
|
-
const result = [];
|
|
8534
|
-
let offset = 0;
|
|
8535
|
-
for (const segment of segments) {
|
|
8536
|
-
const end = offset + segment.text.length;
|
|
8537
|
-
if (index > offset && index < end) {
|
|
8538
|
-
const before2 = segment.text.slice(0, index - offset);
|
|
8539
|
-
const after2 = segment.text.slice(index - offset);
|
|
8540
|
-
result.push({ text: before2, attributes: segment.attributes });
|
|
8541
|
-
result.push({ text: after2, attributes: segment.attributes });
|
|
8542
|
-
} else {
|
|
8543
|
-
result.push({ text: segment.text, attributes: segment.attributes });
|
|
8544
|
-
}
|
|
8545
|
-
offset = end;
|
|
8546
|
-
}
|
|
8547
|
-
return result;
|
|
8548
|
-
}
|
|
8549
|
-
function clipRange(index, length, contentLength) {
|
|
8550
|
-
const clippedIndex = Math.max(0, Math.min(index, contentLength));
|
|
8551
|
-
const clippedEnd = Math.max(
|
|
8552
|
-
clippedIndex,
|
|
8553
|
-
Math.min(index + length, contentLength)
|
|
8554
|
-
);
|
|
8555
|
-
return { index: clippedIndex, length: clippedEnd - clippedIndex };
|
|
8556
|
-
}
|
|
8557
|
-
function applyInsert(segments, index, text, attributes) {
|
|
8558
|
-
if (text.length === 0) {
|
|
8559
|
-
return normalizeSegments(segments);
|
|
8560
|
-
}
|
|
8561
|
-
const split = splitSegmentsAt(segments, index);
|
|
8562
|
-
const result = [];
|
|
8563
|
-
let offset = 0;
|
|
8564
|
-
let inserted = false;
|
|
8565
|
-
for (const segment of split) {
|
|
8566
|
-
if (!inserted && offset === index) {
|
|
8567
|
-
result.push({ text, attributes });
|
|
8568
|
-
inserted = true;
|
|
8569
|
-
}
|
|
8570
|
-
result.push(segment);
|
|
8571
|
-
offset += segment.text.length;
|
|
8572
|
-
}
|
|
8573
|
-
if (!inserted) {
|
|
8574
|
-
result.push({ text, attributes });
|
|
8575
|
-
}
|
|
8576
|
-
return normalizeSegments(result);
|
|
8577
|
-
}
|
|
8578
|
-
function extractDeletedSegments(segments, index, length) {
|
|
8579
|
-
const split = splitSegmentsAt(
|
|
8580
|
-
splitSegmentsAt(segments, index),
|
|
8581
|
-
index + length
|
|
8582
|
-
);
|
|
8583
|
-
const deleted = [];
|
|
8584
|
-
let offset = 0;
|
|
8585
|
-
for (const segment of split) {
|
|
8586
|
-
const end = offset + segment.text.length;
|
|
8587
|
-
if (offset >= index && end <= index + length) {
|
|
8588
|
-
deleted.push({
|
|
8589
|
-
text: segment.text,
|
|
8590
|
-
attributes: segment.attributes
|
|
8591
|
-
});
|
|
8592
|
-
}
|
|
8593
|
-
offset = end;
|
|
8594
|
-
}
|
|
8595
|
-
return normalizeSegments(deleted);
|
|
8596
|
-
}
|
|
8597
|
-
function applyDelete(segments, index, length) {
|
|
8598
|
-
const deletedSegments = extractDeletedSegments(segments, index, length);
|
|
8599
|
-
const split = splitSegmentsAt(
|
|
8600
|
-
splitSegmentsAt(segments, index),
|
|
8601
|
-
index + length
|
|
8602
|
-
);
|
|
8603
|
-
const result = [];
|
|
8604
|
-
let offset = 0;
|
|
8605
|
-
let deletedText = "";
|
|
8606
|
-
for (const segment of split) {
|
|
8607
|
-
const end = offset + segment.text.length;
|
|
8608
|
-
if (offset >= index && end <= index + length) {
|
|
8609
|
-
deletedText += segment.text;
|
|
8610
|
-
} else {
|
|
8611
|
-
result.push(segment);
|
|
8612
|
-
}
|
|
8613
|
-
offset = end;
|
|
8614
|
-
}
|
|
8615
|
-
return {
|
|
8616
|
-
segments: normalizeSegments(result),
|
|
8617
|
-
deletedText,
|
|
8618
|
-
deletedSegments
|
|
8619
|
-
};
|
|
8620
|
-
}
|
|
8621
|
-
function applyFormat(segments, index, length, attributes) {
|
|
8622
|
-
const split = splitSegmentsAt(
|
|
8623
|
-
splitSegmentsAt(segments, index),
|
|
8624
|
-
index + length
|
|
8625
|
-
);
|
|
8626
|
-
const result = [];
|
|
8627
|
-
let offset = 0;
|
|
8628
|
-
for (const segment of split) {
|
|
8629
|
-
const end = offset + segment.text.length;
|
|
8630
|
-
if (offset >= index && end <= index + length) {
|
|
8631
|
-
const nextAttributes = {
|
|
8632
|
-
..._nullishCoalesce(segment.attributes, () => ( {}))
|
|
8633
|
-
};
|
|
8634
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
8635
|
-
if (value === null) {
|
|
8636
|
-
delete nextAttributes[key];
|
|
8637
|
-
} else {
|
|
8638
|
-
nextAttributes[key] = value;
|
|
8639
|
-
}
|
|
8640
|
-
}
|
|
8641
|
-
result.push({
|
|
8642
|
-
text: segment.text,
|
|
8643
|
-
attributes: Object.keys(nextAttributes).length === 0 ? void 0 : freeze(nextAttributes)
|
|
8644
|
-
});
|
|
8645
|
-
} else {
|
|
8646
|
-
result.push(segment);
|
|
8647
|
-
}
|
|
8648
|
-
offset = end;
|
|
8649
|
-
}
|
|
8650
|
-
return normalizeSegments(result);
|
|
8651
|
-
}
|
|
8652
|
-
function formatReverseOperations(segments, index, length, patch) {
|
|
8653
|
-
const split = splitSegmentsAt(
|
|
8654
|
-
splitSegmentsAt(segments, index),
|
|
8655
|
-
index + length
|
|
8656
|
-
);
|
|
8657
|
-
const result = [];
|
|
8658
|
-
let offset = 0;
|
|
8659
|
-
for (const segment of split) {
|
|
8660
|
-
const end = offset + segment.text.length;
|
|
8661
|
-
if (offset >= index && end <= index + length) {
|
|
8662
|
-
const attributes = {};
|
|
8663
|
-
for (const key of Object.keys(patch)) {
|
|
8664
|
-
attributes[key] = _nullishCoalesce(_optionalChain([segment, 'access', _213 => _213.attributes, 'optionalAccess', _214 => _214[key]]), () => ( null));
|
|
8665
|
-
}
|
|
8666
|
-
result.push({
|
|
8667
|
-
type: "format",
|
|
8668
|
-
index: offset,
|
|
8669
|
-
length: segment.text.length,
|
|
8670
|
-
attributes
|
|
8671
|
-
});
|
|
8672
|
-
}
|
|
8673
|
-
offset = end;
|
|
8674
|
-
}
|
|
8675
|
-
return result;
|
|
8676
|
-
}
|
|
8677
|
-
function mapIndexThroughOperation(index, op) {
|
|
8678
|
-
if (op.type === "insert") {
|
|
8679
|
-
return op.index <= index ? index + op.text.length : index;
|
|
8680
|
-
} else if (op.type === "delete") {
|
|
8681
|
-
if (op.index >= index) {
|
|
8682
|
-
return index;
|
|
8683
|
-
}
|
|
8684
|
-
return Math.max(op.index, index - op.length);
|
|
8685
|
-
} else {
|
|
8686
|
-
return index;
|
|
8687
|
-
}
|
|
8688
|
-
}
|
|
8689
|
-
function mapTextIndexThroughOperations(index, ops) {
|
|
8690
|
-
let mapped = index;
|
|
8691
|
-
for (const op of ops) {
|
|
8692
|
-
mapped = mapIndexThroughOperation(mapped, op);
|
|
8693
|
-
}
|
|
8694
|
-
return mapped;
|
|
8695
|
-
}
|
|
8696
|
-
function rebaseTextOperations(ops, acceptedOps) {
|
|
8697
|
-
return ops.map((op) => {
|
|
8698
|
-
if (op.type === "insert") {
|
|
8699
|
-
return {
|
|
8700
|
-
...op,
|
|
8701
|
-
index: mapTextIndexThroughOperations(op.index, acceptedOps)
|
|
8702
|
-
};
|
|
8703
|
-
} else if (op.type === "delete" || op.type === "format") {
|
|
8704
|
-
const start = mapTextIndexThroughOperations(op.index, acceptedOps);
|
|
8705
|
-
const end = mapTextIndexThroughOperations(
|
|
8706
|
-
op.index + op.length,
|
|
8707
|
-
acceptedOps
|
|
8708
|
-
);
|
|
8709
|
-
return { ...op, index: start, length: Math.max(0, end - start) };
|
|
8710
|
-
} else {
|
|
8711
|
-
return op;
|
|
8712
|
-
}
|
|
8713
|
-
});
|
|
8714
|
-
}
|
|
8715
|
-
function applyTextOperationsToSegments(segments, ops) {
|
|
8716
|
-
let next = [...segments];
|
|
8717
|
-
for (const op of ops) {
|
|
8718
|
-
if (op.type === "insert") {
|
|
8719
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8720
|
-
next = applyInsert(next, index, op.text, op.attributes);
|
|
8721
|
-
} else if (op.type === "delete") {
|
|
8722
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8723
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8724
|
-
next = applyDelete(next, clipped.index, clipped.length).segments;
|
|
8725
|
-
} else {
|
|
8726
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8727
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8728
|
-
next = applyFormat(next, clipped.index, clipped.length, op.attributes);
|
|
8729
|
-
}
|
|
8730
|
-
}
|
|
8731
|
-
return next;
|
|
8732
|
-
}
|
|
8733
|
-
function applyLiveTextOperations(data, ops) {
|
|
8734
|
-
return segmentsToData(
|
|
8735
|
-
applyTextOperationsToSegments(dataToSegments(data), ops)
|
|
8736
|
-
);
|
|
8737
|
-
}
|
|
8738
|
-
function invertTextOperations(segments, ops) {
|
|
8739
|
-
let shadow = [...segments];
|
|
8740
|
-
const reverse = [];
|
|
8741
|
-
for (const op of ops) {
|
|
8742
|
-
if (op.type === "insert") {
|
|
8743
|
-
shadow = applyInsert(shadow, op.index, op.text, op.attributes);
|
|
8744
|
-
reverse.unshift({
|
|
8745
|
-
type: "delete",
|
|
8746
|
-
index: op.index,
|
|
8747
|
-
length: op.text.length
|
|
8748
|
-
});
|
|
8749
|
-
} else if (op.type === "delete") {
|
|
8750
|
-
const deletedSegments = extractDeletedSegments(
|
|
8751
|
-
shadow,
|
|
8752
|
-
op.index,
|
|
8753
|
-
op.length
|
|
8754
|
-
);
|
|
8755
|
-
shadow = applyDelete(shadow, op.index, op.length).segments;
|
|
8756
|
-
const inserts = [];
|
|
8757
|
-
let insertIndex = op.index;
|
|
8758
|
-
for (const segment of deletedSegments) {
|
|
8759
|
-
inserts.push({
|
|
8760
|
-
type: "insert",
|
|
8761
|
-
index: insertIndex,
|
|
8762
|
-
text: segment.text,
|
|
8763
|
-
attributes: segment.attributes
|
|
8764
|
-
});
|
|
8765
|
-
insertIndex += segment.text.length;
|
|
8766
|
-
}
|
|
8767
|
-
for (let index = inserts.length - 1; index >= 0; index--) {
|
|
8768
|
-
reverse.unshift(inserts[index]);
|
|
8769
|
-
}
|
|
8770
|
-
} else {
|
|
8771
|
-
const inverse = formatReverseOperations(
|
|
8772
|
-
shadow,
|
|
8773
|
-
op.index,
|
|
8774
|
-
op.length,
|
|
8775
|
-
op.attributes
|
|
8776
|
-
);
|
|
8777
|
-
shadow = applyFormat(shadow, op.index, op.length, op.attributes);
|
|
8778
|
-
reverse.unshift(...inverse.reverse());
|
|
8779
|
-
}
|
|
8780
|
-
}
|
|
8781
|
-
return reverse;
|
|
8782
|
-
}
|
|
8783
|
-
|
|
8784
|
-
// src/crdts/LiveText.ts
|
|
8785
|
-
var LiveText = class _LiveText extends AbstractCrdt {
|
|
8786
|
-
#segments;
|
|
8787
|
-
#version;
|
|
8788
|
-
#pendingOps;
|
|
8789
|
-
constructor(textOrData = "", version = 0) {
|
|
8790
|
-
super();
|
|
8791
|
-
this.#segments = typeof textOrData === "string" ? textOrData.length === 0 ? [] : [{ text: textOrData }] : dataToSegments(textOrData);
|
|
8792
|
-
this.#version = version;
|
|
8793
|
-
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8794
|
-
}
|
|
8795
|
-
get version() {
|
|
8796
|
-
return this.#version;
|
|
8797
|
-
}
|
|
8798
|
-
get length() {
|
|
8799
|
-
return this.toString().length;
|
|
8800
|
-
}
|
|
8801
|
-
/** @internal */
|
|
8802
|
-
static _deserialize([id, item], _parentToChildren, pool) {
|
|
8803
|
-
const text = new _LiveText(item.data, item.version);
|
|
8804
|
-
text._attach(id, pool);
|
|
8805
|
-
return text;
|
|
8806
|
-
}
|
|
8807
|
-
/** @internal */
|
|
8808
|
-
_toOps(parentId, parentKey) {
|
|
8809
|
-
if (this._id === void 0) {
|
|
8810
|
-
throw new Error("Cannot serialize LiveText if it is not attached");
|
|
8811
|
-
}
|
|
8812
|
-
return [
|
|
8813
|
-
{
|
|
8814
|
-
type: OpCode.CREATE_TEXT,
|
|
8815
|
-
id: this._id,
|
|
8816
|
-
parentId,
|
|
8817
|
-
parentKey,
|
|
8818
|
-
data: this.toJSON(),
|
|
8819
|
-
version: this.#version
|
|
8820
|
-
}
|
|
8821
|
-
];
|
|
8822
|
-
}
|
|
8823
|
-
/** @internal */
|
|
8824
|
-
_serialize() {
|
|
8825
|
-
if (this.parent.type !== "HasParent") {
|
|
8826
|
-
throw new Error("Cannot serialize LiveText if parent is missing");
|
|
8827
|
-
}
|
|
8828
|
-
return {
|
|
8829
|
-
type: CrdtType.TEXT,
|
|
8830
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8831
|
-
parentKey: this.parent.key,
|
|
8832
|
-
data: this.toJSON(),
|
|
8833
|
-
version: this.#version
|
|
8834
|
-
};
|
|
8835
|
-
}
|
|
8836
|
-
/** @internal */
|
|
8837
|
-
_attachChild(_op) {
|
|
8838
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8839
|
-
}
|
|
8840
|
-
/** @internal */
|
|
8841
|
-
_detachChild(_crdt) {
|
|
8842
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8843
|
-
}
|
|
8844
|
-
/** @internal */
|
|
8845
|
-
_apply(op, isLocal) {
|
|
8846
|
-
if (op.type !== OpCode.UPDATE_TEXT) {
|
|
8847
|
-
return super._apply(op, isLocal);
|
|
8848
|
-
}
|
|
8849
|
-
if (isLocal) {
|
|
8850
|
-
this.#pendingOps.set(nn(op.opId), op.ops);
|
|
8851
|
-
return this.#applyOperations(op.ops, _nullishCoalesce(op.version, () => ( this.#version)));
|
|
8852
|
-
}
|
|
8853
|
-
if (op.opId !== void 0) {
|
|
8854
|
-
const pending2 = this.#pendingOps.get(op.opId);
|
|
8855
|
-
this.#pendingOps.delete(op.opId);
|
|
8856
|
-
const otherPending = Array.from(this.#pendingOps.values()).flat();
|
|
8857
|
-
if (pending2 !== void 0 && otherPending.length > 0) {
|
|
8858
|
-
this.#segments = applyTextOperationsToSegments(
|
|
8859
|
-
this.#segments,
|
|
8860
|
-
invertTextOperations(this.#segments, pending2)
|
|
8861
|
-
);
|
|
8862
|
-
const ops2 = rebaseTextOperations(op.ops, otherPending);
|
|
8863
|
-
return this.#applyOperations(
|
|
8864
|
-
ops2,
|
|
8865
|
-
_nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)))
|
|
8866
|
-
);
|
|
8867
|
-
}
|
|
8868
|
-
this.#version = _nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)));
|
|
8869
|
-
return { modified: false };
|
|
8870
|
-
}
|
|
8871
|
-
const pending = Array.from(this.#pendingOps.values()).flat();
|
|
8872
|
-
const ops = pending.length > 0 ? rebaseTextOperations(op.ops, pending) : op.ops;
|
|
8873
|
-
return this.#applyOperations(ops, _nullishCoalesce(op.version, () => ( this.#version + 1)));
|
|
8874
|
-
}
|
|
8875
|
-
insert(index, text, attributes) {
|
|
8876
|
-
const clippedIndex = Math.max(0, Math.min(index, this.length));
|
|
8877
|
-
this.#dispatch([{ type: "insert", index: clippedIndex, text, attributes }]);
|
|
8878
|
-
}
|
|
8879
|
-
delete(index, length) {
|
|
8880
|
-
const clipped = clipRange(index, length, this.length);
|
|
8881
|
-
if (clipped.length === 0) {
|
|
8882
|
-
return;
|
|
8883
|
-
}
|
|
8884
|
-
this.#dispatch([
|
|
8885
|
-
{ type: "delete", index: clipped.index, length: clipped.length }
|
|
8886
|
-
]);
|
|
8887
|
-
}
|
|
8888
|
-
replace(index, length, text, attributes) {
|
|
8889
|
-
const clipped = clipRange(index, length, this.length);
|
|
8890
|
-
const ops = [];
|
|
8891
|
-
if (clipped.length > 0) {
|
|
8892
|
-
ops.push({
|
|
8893
|
-
type: "delete",
|
|
8894
|
-
index: clipped.index,
|
|
8895
|
-
length: clipped.length
|
|
8896
|
-
});
|
|
8897
|
-
}
|
|
8898
|
-
if (text.length > 0) {
|
|
8899
|
-
ops.push({ type: "insert", index: clipped.index, text, attributes });
|
|
8900
|
-
}
|
|
8901
|
-
this.#dispatch(ops);
|
|
8902
|
-
}
|
|
8903
|
-
format(index, length, attributes) {
|
|
8904
|
-
const clipped = clipRange(index, length, this.length);
|
|
8905
|
-
if (clipped.length === 0) {
|
|
8906
|
-
return;
|
|
8907
|
-
}
|
|
8908
|
-
this.#dispatch([
|
|
8909
|
-
{
|
|
8910
|
-
type: "format",
|
|
8911
|
-
index: clipped.index,
|
|
8912
|
-
length: clipped.length,
|
|
8913
|
-
attributes
|
|
8914
|
-
}
|
|
8915
|
-
]);
|
|
8916
|
-
}
|
|
8917
|
-
#dispatch(ops) {
|
|
8918
|
-
if (ops.length === 0) {
|
|
8919
|
-
return;
|
|
8920
|
-
}
|
|
8921
|
-
_optionalChain([this, 'access', _215 => _215._pool, 'optionalAccess', _216 => _216.assertStorageIsWritable, 'call', _217 => _217()]);
|
|
8922
|
-
const baseVersion = this.#version;
|
|
8923
|
-
const reverse = this._pool !== void 0 && this._id !== void 0 ? this.#invertOperations(ops) : [];
|
|
8924
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8925
|
-
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8926
|
-
const opId = this._pool.generateOpId();
|
|
8927
|
-
this.#pendingOps.set(opId, ops);
|
|
8928
|
-
this._pool.dispatch(
|
|
8929
|
-
[
|
|
8930
|
-
{
|
|
8931
|
-
type: OpCode.UPDATE_TEXT,
|
|
8932
|
-
id: this._id,
|
|
8933
|
-
opId,
|
|
8934
|
-
baseVersion,
|
|
8935
|
-
ops: [...ops]
|
|
8936
|
-
}
|
|
8937
|
-
],
|
|
8938
|
-
reverse,
|
|
8939
|
-
/* @__PURE__ */ new Map([
|
|
8940
|
-
[
|
|
8941
|
-
this._id,
|
|
8942
|
-
{
|
|
8943
|
-
type: "LiveText",
|
|
8944
|
-
node: this,
|
|
8945
|
-
version: this.#version,
|
|
8946
|
-
updates: changes
|
|
8947
|
-
}
|
|
8948
|
-
]
|
|
8949
|
-
])
|
|
8950
|
-
);
|
|
8951
|
-
}
|
|
8952
|
-
}
|
|
8953
|
-
#applyOperations(ops, version) {
|
|
8954
|
-
const reverse = this.#invertOperations(ops);
|
|
8955
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8956
|
-
this.#version = Math.max(this.#version, version);
|
|
8957
|
-
return {
|
|
8958
|
-
reverse,
|
|
8959
|
-
modified: {
|
|
8960
|
-
type: "LiveText",
|
|
8961
|
-
node: this,
|
|
8962
|
-
version: this.#version,
|
|
8963
|
-
updates: changes
|
|
8964
|
-
}
|
|
8965
|
-
};
|
|
8966
|
-
}
|
|
8967
|
-
#applyOperationsLocally(ops) {
|
|
8968
|
-
const changes = [];
|
|
8969
|
-
for (const op of ops) {
|
|
8970
|
-
if (op.type === "insert") {
|
|
8971
|
-
this.#segments = applyInsert(
|
|
8972
|
-
this.#segments,
|
|
8973
|
-
op.index,
|
|
8974
|
-
op.text,
|
|
8975
|
-
op.attributes
|
|
8976
|
-
);
|
|
8977
|
-
changes.push({
|
|
8978
|
-
type: "insert",
|
|
8979
|
-
index: op.index,
|
|
8980
|
-
text: op.text,
|
|
8981
|
-
attributes: op.attributes
|
|
8982
|
-
});
|
|
8983
|
-
} else if (op.type === "delete") {
|
|
8984
|
-
const result = applyDelete(this.#segments, op.index, op.length);
|
|
8985
|
-
this.#segments = result.segments;
|
|
8986
|
-
changes.push({
|
|
8987
|
-
type: "delete",
|
|
8988
|
-
index: op.index,
|
|
8989
|
-
length: op.length,
|
|
8990
|
-
deletedText: result.deletedText
|
|
8991
|
-
});
|
|
8992
|
-
} else {
|
|
8993
|
-
this.#segments = applyFormat(
|
|
8994
|
-
this.#segments,
|
|
8995
|
-
op.index,
|
|
8996
|
-
op.length,
|
|
8997
|
-
op.attributes
|
|
8998
|
-
);
|
|
8999
|
-
changes.push({
|
|
9000
|
-
type: "format",
|
|
9001
|
-
index: op.index,
|
|
9002
|
-
length: op.length,
|
|
9003
|
-
attributes: op.attributes
|
|
9004
|
-
});
|
|
9005
|
-
}
|
|
9006
|
-
}
|
|
9007
|
-
this.invalidate();
|
|
9008
|
-
return changes;
|
|
9009
|
-
}
|
|
9010
|
-
#invertOperations(ops) {
|
|
9011
|
-
return [
|
|
9012
|
-
{
|
|
9013
|
-
type: OpCode.UPDATE_TEXT,
|
|
9014
|
-
id: nn(this._id),
|
|
9015
|
-
baseVersion: this.#version,
|
|
9016
|
-
ops: invertTextOperations(this.#segments, ops)
|
|
9017
|
-
}
|
|
9018
|
-
];
|
|
9019
|
-
}
|
|
9020
|
-
toString() {
|
|
9021
|
-
return this.#segments.map((segment) => segment.text).join("");
|
|
9022
|
-
}
|
|
9023
|
-
toJSON() {
|
|
9024
|
-
return super.toJSON();
|
|
9025
|
-
}
|
|
9026
|
-
/** @internal */
|
|
9027
|
-
_toJSON() {
|
|
9028
|
-
return segmentsToData(this.#segments);
|
|
9029
|
-
}
|
|
9030
|
-
/** @internal */
|
|
9031
|
-
_toTreeNode(key) {
|
|
9032
|
-
return {
|
|
9033
|
-
type: "LiveText",
|
|
9034
|
-
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
9035
|
-
key,
|
|
9036
|
-
payload: [
|
|
9037
|
-
{
|
|
9038
|
-
type: "Json",
|
|
9039
|
-
id: `${_nullishCoalesce(this._id, () => ( nanoid()))}:text`,
|
|
9040
|
-
key: "text",
|
|
9041
|
-
payload: this.toString()
|
|
9042
|
-
}
|
|
9043
|
-
]
|
|
9044
|
-
};
|
|
9045
|
-
}
|
|
9046
|
-
clone() {
|
|
9047
|
-
return new _LiveText(this.toJSON(), this.#version);
|
|
9048
|
-
}
|
|
9049
|
-
};
|
|
9050
|
-
|
|
9051
8455
|
// src/crdts/liveblocks-helpers.ts
|
|
9052
8456
|
function creationOpToLiveNode(op) {
|
|
9053
8457
|
return lsonToLiveNode(creationOpToLson(op));
|
|
@@ -9062,8 +8466,6 @@ function creationOpToLson(op) {
|
|
|
9062
8466
|
return new LiveMap();
|
|
9063
8467
|
case OpCode.CREATE_LIST:
|
|
9064
8468
|
return new LiveList([]);
|
|
9065
|
-
case OpCode.CREATE_TEXT:
|
|
9066
|
-
return new LiveText(op.data, op.version);
|
|
9067
8469
|
default:
|
|
9068
8470
|
return assertNever(op, "Unknown creation Op");
|
|
9069
8471
|
}
|
|
@@ -9086,8 +8488,6 @@ function deserialize(node, parentToChildren, pool) {
|
|
|
9086
8488
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9087
8489
|
} else if (isRegisterStorageNode(node)) {
|
|
9088
8490
|
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
9089
|
-
} else if (isTextStorageNode(node)) {
|
|
9090
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9091
8491
|
} else {
|
|
9092
8492
|
throw new Error("Unexpected CRDT type");
|
|
9093
8493
|
}
|
|
@@ -9101,14 +8501,12 @@ function deserializeToLson(node, parentToChildren, pool) {
|
|
|
9101
8501
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9102
8502
|
} else if (isRegisterStorageNode(node)) {
|
|
9103
8503
|
return node[1].data;
|
|
9104
|
-
} else if (isTextStorageNode(node)) {
|
|
9105
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9106
8504
|
} else {
|
|
9107
8505
|
throw new Error("Unexpected CRDT type");
|
|
9108
8506
|
}
|
|
9109
8507
|
}
|
|
9110
8508
|
function isLiveStructure(value) {
|
|
9111
|
-
return isLiveList(value) || isLiveMap(value) || isLiveObject(value)
|
|
8509
|
+
return isLiveList(value) || isLiveMap(value) || isLiveObject(value);
|
|
9112
8510
|
}
|
|
9113
8511
|
function isLiveNode(value) {
|
|
9114
8512
|
return isLiveStructure(value) || isLiveRegister(value);
|
|
@@ -9122,9 +8520,6 @@ function isLiveMap(value) {
|
|
|
9122
8520
|
function isLiveObject(value) {
|
|
9123
8521
|
return value instanceof LiveObject;
|
|
9124
8522
|
}
|
|
9125
|
-
function isLiveText(value) {
|
|
9126
|
-
return value instanceof LiveText;
|
|
9127
|
-
}
|
|
9128
8523
|
function isLiveRegister(value) {
|
|
9129
8524
|
return value instanceof LiveRegister;
|
|
9130
8525
|
}
|
|
@@ -9134,73 +8529,19 @@ function cloneLson(value) {
|
|
|
9134
8529
|
function liveNodeToLson(obj) {
|
|
9135
8530
|
if (obj instanceof LiveRegister) {
|
|
9136
8531
|
return obj.data;
|
|
9137
|
-
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject
|
|
8532
|
+
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject) {
|
|
9138
8533
|
return obj;
|
|
9139
8534
|
} else {
|
|
9140
8535
|
return assertNever(obj, "Unknown AbstractCrdt");
|
|
9141
8536
|
}
|
|
9142
8537
|
}
|
|
9143
8538
|
function lsonToLiveNode(value) {
|
|
9144
|
-
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList
|
|
8539
|
+
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList) {
|
|
9145
8540
|
return value;
|
|
9146
8541
|
} else {
|
|
9147
8542
|
return new LiveRegister(value);
|
|
9148
8543
|
}
|
|
9149
8544
|
}
|
|
9150
|
-
function dumpPool(pool) {
|
|
9151
|
-
const rows = Array.from(pool.nodes.values(), (node) => {
|
|
9152
|
-
const parent = node.parent;
|
|
9153
|
-
const parentId = parent.type === "HasParent" ? _nullishCoalesce(parent.node._id, () => ( "?")) : parent.type === "Orphaned" ? "<orphaned>" : "-";
|
|
9154
|
-
let value;
|
|
9155
|
-
if (node instanceof LiveRegister) {
|
|
9156
|
-
value = stringifyOrLog(node.data);
|
|
9157
|
-
} else if (node instanceof LiveList) {
|
|
9158
|
-
value = "<LiveList>";
|
|
9159
|
-
} else if (node instanceof LiveMap) {
|
|
9160
|
-
value = "<LiveMap>";
|
|
9161
|
-
} else {
|
|
9162
|
-
value = "<LiveObject>";
|
|
9163
|
-
}
|
|
9164
|
-
return { id: nn(node._id), parentId, key: _nullishCoalesce(node._parentKey, () => ( "")), value };
|
|
9165
|
-
});
|
|
9166
|
-
rows.sort((a, b) => {
|
|
9167
|
-
if (a.parentId !== b.parentId) return a.parentId < b.parentId ? -1 : 1;
|
|
9168
|
-
if (a.key !== b.key) return a.key < b.key ? -1 : 1;
|
|
9169
|
-
return 0;
|
|
9170
|
-
});
|
|
9171
|
-
return rows.map(
|
|
9172
|
-
(r) => ` ${r.id} parent=${r.parentId} key=${r.key || "\u2014"} ${r.value}`
|
|
9173
|
-
).join("\n");
|
|
9174
|
-
}
|
|
9175
|
-
function isJsonEq(a, b) {
|
|
9176
|
-
if (a === b) {
|
|
9177
|
-
return true;
|
|
9178
|
-
}
|
|
9179
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
9180
|
-
return false;
|
|
9181
|
-
}
|
|
9182
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
9183
|
-
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
9184
|
-
return false;
|
|
9185
|
-
}
|
|
9186
|
-
for (let i = 0; i < a.length; i++) {
|
|
9187
|
-
if (!isJsonEq(a[i], b[i])) {
|
|
9188
|
-
return false;
|
|
9189
|
-
}
|
|
9190
|
-
}
|
|
9191
|
-
return true;
|
|
9192
|
-
}
|
|
9193
|
-
const aKeys = Object.keys(a);
|
|
9194
|
-
if (aKeys.length !== Object.keys(b).length) {
|
|
9195
|
-
return false;
|
|
9196
|
-
}
|
|
9197
|
-
for (const key of aKeys) {
|
|
9198
|
-
if (!isJsonEq(a[key], b[key])) {
|
|
9199
|
-
return false;
|
|
9200
|
-
}
|
|
9201
|
-
}
|
|
9202
|
-
return true;
|
|
9203
|
-
}
|
|
9204
8545
|
function getTreesDiffOperations(currentItems, newItems) {
|
|
9205
8546
|
const ops = [];
|
|
9206
8547
|
currentItems.forEach((_, id) => {
|
|
@@ -9212,61 +8553,11 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9212
8553
|
const currentCrdt = currentItems.get(id);
|
|
9213
8554
|
if (currentCrdt) {
|
|
9214
8555
|
if (crdt.type === CrdtType.OBJECT) {
|
|
9215
|
-
if (currentCrdt.type !== CrdtType.OBJECT) {
|
|
9216
|
-
ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
|
|
9217
|
-
} else {
|
|
9218
|
-
const changed = /* @__PURE__ */ new Map();
|
|
9219
|
-
for (const key of Object.keys(crdt.data)) {
|
|
9220
|
-
const value = crdt.data[key];
|
|
9221
|
-
if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
|
|
9222
|
-
changed.set(key, value);
|
|
9223
|
-
}
|
|
9224
|
-
}
|
|
9225
|
-
if (changed.size > 0) {
|
|
9226
|
-
ops.push({
|
|
9227
|
-
type: OpCode.UPDATE_OBJECT,
|
|
9228
|
-
id,
|
|
9229
|
-
data: Object.fromEntries(changed)
|
|
9230
|
-
});
|
|
9231
|
-
}
|
|
9232
|
-
for (const key of Object.keys(currentCrdt.data)) {
|
|
9233
|
-
if (!(key in crdt.data)) {
|
|
9234
|
-
ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
9235
|
-
}
|
|
9236
|
-
}
|
|
9237
|
-
}
|
|
9238
|
-
}
|
|
9239
|
-
if (crdt.type === CrdtType.TEXT) {
|
|
9240
|
-
if (currentCrdt.type !== CrdtType.TEXT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data) || crdt.version !== currentCrdt.version) {
|
|
8556
|
+
if (currentCrdt.type !== CrdtType.OBJECT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data)) {
|
|
9241
8557
|
ops.push({
|
|
9242
|
-
type: OpCode.
|
|
8558
|
+
type: OpCode.UPDATE_OBJECT,
|
|
9243
8559
|
id,
|
|
9244
|
-
|
|
9245
|
-
version: crdt.version,
|
|
9246
|
-
ops: [
|
|
9247
|
-
{
|
|
9248
|
-
type: "delete",
|
|
9249
|
-
index: 0,
|
|
9250
|
-
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9251
|
-
(sum, segment) => sum + segment[0].length,
|
|
9252
|
-
0
|
|
9253
|
-
) : 0
|
|
9254
|
-
},
|
|
9255
|
-
...crdt.data.map((segment, index, items) => {
|
|
9256
|
-
const [text, attributes] = segment;
|
|
9257
|
-
const insertIndex = items.slice(0, index).reduce((sum, item) => sum + item[0].length, 0);
|
|
9258
|
-
return attributes === void 0 ? {
|
|
9259
|
-
type: "insert",
|
|
9260
|
-
index: insertIndex,
|
|
9261
|
-
text
|
|
9262
|
-
} : {
|
|
9263
|
-
type: "insert",
|
|
9264
|
-
index: insertIndex,
|
|
9265
|
-
text,
|
|
9266
|
-
attributes
|
|
9267
|
-
};
|
|
9268
|
-
})
|
|
9269
|
-
]
|
|
8560
|
+
data: crdt.data
|
|
9270
8561
|
});
|
|
9271
8562
|
}
|
|
9272
8563
|
}
|
|
@@ -9318,16 +8609,6 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9318
8609
|
parentKey: crdt.parentKey
|
|
9319
8610
|
});
|
|
9320
8611
|
break;
|
|
9321
|
-
case CrdtType.TEXT:
|
|
9322
|
-
ops.push({
|
|
9323
|
-
type: OpCode.CREATE_TEXT,
|
|
9324
|
-
id,
|
|
9325
|
-
parentId: crdt.parentId,
|
|
9326
|
-
parentKey: crdt.parentKey,
|
|
9327
|
-
data: crdt.data,
|
|
9328
|
-
version: crdt.version
|
|
9329
|
-
});
|
|
9330
|
-
break;
|
|
9331
8612
|
}
|
|
9332
8613
|
}
|
|
9333
8614
|
});
|
|
@@ -9360,12 +8641,6 @@ function mergeListStorageUpdates(first, second) {
|
|
|
9360
8641
|
updates: updates.concat(second.updates)
|
|
9361
8642
|
};
|
|
9362
8643
|
}
|
|
9363
|
-
function mergeTextStorageUpdates(first, second) {
|
|
9364
|
-
return {
|
|
9365
|
-
...second,
|
|
9366
|
-
updates: first.updates.concat(second.updates)
|
|
9367
|
-
};
|
|
9368
|
-
}
|
|
9369
8644
|
function mergeStorageUpdates(first, second) {
|
|
9370
8645
|
if (first === void 0) {
|
|
9371
8646
|
return second;
|
|
@@ -9376,8 +8651,6 @@ function mergeStorageUpdates(first, second) {
|
|
|
9376
8651
|
return mergeMapStorageUpdates(first, second);
|
|
9377
8652
|
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
9378
8653
|
return mergeListStorageUpdates(first, second);
|
|
9379
|
-
} else if (first.type === "LiveText" && second.type === "LiveText") {
|
|
9380
|
-
return mergeTextStorageUpdates(first, second);
|
|
9381
8654
|
} else {
|
|
9382
8655
|
}
|
|
9383
8656
|
return second;
|
|
@@ -9396,7 +8669,7 @@ function sendToPanel(message, options) {
|
|
|
9396
8669
|
...message,
|
|
9397
8670
|
source: "liveblocks-devtools-client"
|
|
9398
8671
|
};
|
|
9399
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
8672
|
+
if (!(_optionalChain([options, 'optionalAccess', _202 => _202.force]) || _bridgeActive)) {
|
|
9400
8673
|
return;
|
|
9401
8674
|
}
|
|
9402
8675
|
window.postMessage(fullMsg, "*");
|
|
@@ -9404,7 +8677,7 @@ function sendToPanel(message, options) {
|
|
|
9404
8677
|
var eventSource = makeEventSource();
|
|
9405
8678
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
9406
8679
|
window.addEventListener("message", (event) => {
|
|
9407
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
8680
|
+
if (event.source === window && _optionalChain([event, 'access', _203 => _203.data, 'optionalAccess', _204 => _204.source]) === "liveblocks-devtools-panel") {
|
|
9408
8681
|
eventSource.notify(event.data);
|
|
9409
8682
|
} else {
|
|
9410
8683
|
}
|
|
@@ -9546,7 +8819,7 @@ function fullSync(room) {
|
|
|
9546
8819
|
msg: "room::sync::full",
|
|
9547
8820
|
roomId: room.id,
|
|
9548
8821
|
status: room.getStatus(),
|
|
9549
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
8822
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _205 => _205.toTreeNode, 'call', _206 => _206("root"), 'access', _207 => _207.payload]), () => ( null)),
|
|
9550
8823
|
me,
|
|
9551
8824
|
others
|
|
9552
8825
|
});
|
|
@@ -9964,14 +9237,14 @@ var ClientMsgCode = Object.freeze({
|
|
|
9964
9237
|
// src/refs/ManagedOthers.ts
|
|
9965
9238
|
function makeUser(conn, presence) {
|
|
9966
9239
|
const { connectionId, id, info } = conn;
|
|
9967
|
-
const canWrite =
|
|
9240
|
+
const canWrite = hasPermissionCapability(conn.scopes, "storage", "write");
|
|
9968
9241
|
return freeze(
|
|
9969
9242
|
compactObject({
|
|
9970
9243
|
connectionId,
|
|
9971
9244
|
id,
|
|
9972
9245
|
info,
|
|
9973
9246
|
canWrite,
|
|
9974
|
-
canComment:
|
|
9247
|
+
canComment: hasPermissionCapability(conn.scopes, "comments", "write"),
|
|
9975
9248
|
isReadOnly: !canWrite,
|
|
9976
9249
|
// Deprecated, kept for backward-compatibility
|
|
9977
9250
|
presence
|
|
@@ -10225,15 +9498,15 @@ function installBackgroundTabSpy() {
|
|
|
10225
9498
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
10226
9499
|
const inBackgroundSince = { current: null };
|
|
10227
9500
|
function onVisibilityChange() {
|
|
10228
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
9501
|
+
if (_optionalChain([doc, 'optionalAccess', _208 => _208.visibilityState]) === "hidden") {
|
|
10229
9502
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
10230
9503
|
} else {
|
|
10231
9504
|
inBackgroundSince.current = null;
|
|
10232
9505
|
}
|
|
10233
9506
|
}
|
|
10234
|
-
_optionalChain([doc, 'optionalAccess',
|
|
9507
|
+
_optionalChain([doc, 'optionalAccess', _209 => _209.addEventListener, 'call', _210 => _210("visibilitychange", onVisibilityChange)]);
|
|
10235
9508
|
const unsub = () => {
|
|
10236
|
-
_optionalChain([doc, 'optionalAccess',
|
|
9509
|
+
_optionalChain([doc, 'optionalAccess', _211 => _211.removeEventListener, 'call', _212 => _212("visibilitychange", onVisibilityChange)]);
|
|
10237
9510
|
};
|
|
10238
9511
|
return [inBackgroundSince, unsub];
|
|
10239
9512
|
}
|
|
@@ -10278,7 +9551,6 @@ function createRoom(options, config) {
|
|
|
10278
9551
|
delegates,
|
|
10279
9552
|
config.enableDebugLogging
|
|
10280
9553
|
);
|
|
10281
|
-
const unacknowledgedOps = new UnacknowledgedOps();
|
|
10282
9554
|
const context = {
|
|
10283
9555
|
buffer: {
|
|
10284
9556
|
flushTimerID: void 0,
|
|
@@ -10306,15 +9578,14 @@ function createRoom(options, config) {
|
|
|
10306
9578
|
pool: createManagedPool(roomId, {
|
|
10307
9579
|
getCurrentConnectionId,
|
|
10308
9580
|
onDispatch,
|
|
10309
|
-
isStorageWritable
|
|
10310
|
-
unacknowledgedOps
|
|
9581
|
+
isStorageWritable
|
|
10311
9582
|
}),
|
|
10312
9583
|
root: void 0,
|
|
10313
9584
|
undoStack: [],
|
|
10314
9585
|
redoStack: [],
|
|
10315
9586
|
pausedHistory: null,
|
|
10316
9587
|
activeBatch: null,
|
|
10317
|
-
unacknowledgedOps
|
|
9588
|
+
unacknowledgedOps: /* @__PURE__ */ new Map()
|
|
10318
9589
|
};
|
|
10319
9590
|
const nodeMapBuffer = makeNodeMapBuffer();
|
|
10320
9591
|
const stopwatch = config.enableDebugLogging ? makeStopWatch() : void 0;
|
|
@@ -10381,7 +9652,6 @@ function createRoom(options, config) {
|
|
|
10381
9652
|
}
|
|
10382
9653
|
function onDidDisconnect() {
|
|
10383
9654
|
clearTimeout(context.buffer.flushTimerID);
|
|
10384
|
-
context.unacknowledgedOps.markAllAsPossiblyStored();
|
|
10385
9655
|
}
|
|
10386
9656
|
managedSocket.events.onMessage.subscribe(handleServerMessage);
|
|
10387
9657
|
managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
|
|
@@ -10427,8 +9697,8 @@ function createRoom(options, config) {
|
|
|
10427
9697
|
}
|
|
10428
9698
|
}
|
|
10429
9699
|
function isStorageWritable() {
|
|
10430
|
-
const scopes = _optionalChain([context, 'access',
|
|
10431
|
-
return scopes !== void 0 ?
|
|
9700
|
+
const scopes = _optionalChain([context, 'access', _213 => _213.dynamicSessionInfoSig, 'access', _214 => _214.get, 'call', _215 => _215(), 'optionalAccess', _216 => _216.scopes]);
|
|
9701
|
+
return scopes !== void 0 ? hasPermissionCapability(scopes, "storage", "write") : true;
|
|
10432
9702
|
}
|
|
10433
9703
|
const eventHub = {
|
|
10434
9704
|
status: makeEventSource(),
|
|
@@ -10489,14 +9759,22 @@ function createRoom(options, config) {
|
|
|
10489
9759
|
if (staticSession === null || dynamicSession === null) {
|
|
10490
9760
|
return null;
|
|
10491
9761
|
} else {
|
|
10492
|
-
const canWrite =
|
|
9762
|
+
const canWrite = hasPermissionCapability(
|
|
9763
|
+
dynamicSession.scopes,
|
|
9764
|
+
"storage",
|
|
9765
|
+
"write"
|
|
9766
|
+
);
|
|
10493
9767
|
return {
|
|
10494
9768
|
connectionId: dynamicSession.actor,
|
|
10495
9769
|
id: staticSession.userId,
|
|
10496
9770
|
info: staticSession.userInfo,
|
|
10497
9771
|
presence: myPresence,
|
|
10498
9772
|
canWrite,
|
|
10499
|
-
canComment:
|
|
9773
|
+
canComment: hasPermissionCapability(
|
|
9774
|
+
dynamicSession.scopes,
|
|
9775
|
+
"comments",
|
|
9776
|
+
"write"
|
|
9777
|
+
)
|
|
10500
9778
|
};
|
|
10501
9779
|
}
|
|
10502
9780
|
}
|
|
@@ -10531,7 +9809,7 @@ function createRoom(options, config) {
|
|
|
10531
9809
|
context.pool
|
|
10532
9810
|
);
|
|
10533
9811
|
}
|
|
10534
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
9812
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _217 => _217.get, 'call', _218 => _218(), 'optionalAccess', _219 => _219.canWrite]), () => ( true));
|
|
10535
9813
|
const root = context.root;
|
|
10536
9814
|
disableHistory(() => {
|
|
10537
9815
|
for (const key in context.initialStorage) {
|
|
@@ -10662,7 +9940,7 @@ function createRoom(options, config) {
|
|
|
10662
9940
|
);
|
|
10663
9941
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
10664
9942
|
}
|
|
10665
|
-
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT
|
|
9943
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
10666
9944
|
createdNodeIds.add(op.id);
|
|
10667
9945
|
}
|
|
10668
9946
|
}
|
|
@@ -10682,7 +9960,6 @@ function createRoom(options, config) {
|
|
|
10682
9960
|
switch (op.type) {
|
|
10683
9961
|
case OpCode.DELETE_OBJECT_KEY:
|
|
10684
9962
|
case OpCode.UPDATE_OBJECT:
|
|
10685
|
-
case OpCode.UPDATE_TEXT:
|
|
10686
9963
|
case OpCode.DELETE_CRDT: {
|
|
10687
9964
|
const node = context.pool.nodes.get(op.id);
|
|
10688
9965
|
if (node === void 0) {
|
|
@@ -10707,7 +9984,6 @@ function createRoom(options, config) {
|
|
|
10707
9984
|
case OpCode.CREATE_OBJECT:
|
|
10708
9985
|
case OpCode.CREATE_LIST:
|
|
10709
9986
|
case OpCode.CREATE_MAP:
|
|
10710
|
-
case OpCode.CREATE_TEXT:
|
|
10711
9987
|
case OpCode.CREATE_REGISTER: {
|
|
10712
9988
|
if (op.parentId === void 0) {
|
|
10713
9989
|
return { modified: false };
|
|
@@ -10738,7 +10014,7 @@ function createRoom(options, config) {
|
|
|
10738
10014
|
}
|
|
10739
10015
|
context.myPresence.patch(patch);
|
|
10740
10016
|
if (context.activeBatch) {
|
|
10741
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10017
|
+
if (_optionalChain([options2, 'optionalAccess', _220 => _220.addToHistory])) {
|
|
10742
10018
|
context.activeBatch.reverseOps.pushLeft({
|
|
10743
10019
|
type: "presence",
|
|
10744
10020
|
data: oldValues
|
|
@@ -10747,7 +10023,7 @@ function createRoom(options, config) {
|
|
|
10747
10023
|
context.activeBatch.updates.presence = true;
|
|
10748
10024
|
} else {
|
|
10749
10025
|
flushNowOrSoon();
|
|
10750
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10026
|
+
if (_optionalChain([options2, 'optionalAccess', _221 => _221.addToHistory])) {
|
|
10751
10027
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
10752
10028
|
}
|
|
10753
10029
|
notify({ presence: true });
|
|
@@ -10856,11 +10132,12 @@ function createRoom(options, config) {
|
|
|
10856
10132
|
}
|
|
10857
10133
|
}
|
|
10858
10134
|
function applyAndSendOfflineOps(unackedOps) {
|
|
10859
|
-
if (unackedOps.
|
|
10135
|
+
if (unackedOps.size === 0) {
|
|
10860
10136
|
return;
|
|
10861
10137
|
}
|
|
10862
10138
|
const messages = [];
|
|
10863
|
-
const
|
|
10139
|
+
const inOps = Array.from(unackedOps.values());
|
|
10140
|
+
const result = applyLocalOps(inOps);
|
|
10864
10141
|
messages.push({
|
|
10865
10142
|
type: ClientMsgCode.UPDATE_STORAGE,
|
|
10866
10143
|
ops: result.opsToEmit
|
|
@@ -10924,11 +10201,11 @@ function createRoom(options, config) {
|
|
|
10924
10201
|
break;
|
|
10925
10202
|
}
|
|
10926
10203
|
case ServerMsgCode.STORAGE_CHUNK:
|
|
10927
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
10204
|
+
_optionalChain([stopwatch, 'optionalAccess', _222 => _222.lap, 'call', _223 => _223()]);
|
|
10928
10205
|
nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
|
|
10929
10206
|
break;
|
|
10930
10207
|
case ServerMsgCode.STORAGE_STREAM_END: {
|
|
10931
|
-
const timing = _optionalChain([stopwatch, 'optionalAccess',
|
|
10208
|
+
const timing = _optionalChain([stopwatch, 'optionalAccess', _224 => _224.stop, 'call', _225 => _225()]);
|
|
10932
10209
|
if (timing) {
|
|
10933
10210
|
const ms = (v) => `${v.toFixed(1)}ms`;
|
|
10934
10211
|
const rest = timing.laps.slice(1);
|
|
@@ -11063,11 +10340,11 @@ function createRoom(options, config) {
|
|
|
11063
10340
|
} else if (pendingFeedsRequests.has(requestId)) {
|
|
11064
10341
|
const pending = pendingFeedsRequests.get(requestId);
|
|
11065
10342
|
pendingFeedsRequests.delete(requestId);
|
|
11066
|
-
_optionalChain([pending, 'optionalAccess',
|
|
10343
|
+
_optionalChain([pending, 'optionalAccess', _226 => _226.reject, 'call', _227 => _227(err)]);
|
|
11067
10344
|
} else if (pendingFeedMessagesRequests.has(requestId)) {
|
|
11068
10345
|
const pending = pendingFeedMessagesRequests.get(requestId);
|
|
11069
10346
|
pendingFeedMessagesRequests.delete(requestId);
|
|
11070
|
-
_optionalChain([pending, 'optionalAccess',
|
|
10347
|
+
_optionalChain([pending, 'optionalAccess', _228 => _228.reject, 'call', _229 => _229(err)]);
|
|
11071
10348
|
}
|
|
11072
10349
|
eventHub.feeds.notify(message);
|
|
11073
10350
|
break;
|
|
@@ -11084,7 +10361,7 @@ function createRoom(options, config) {
|
|
|
11084
10361
|
const storageOps = context.buffer.storageOperations;
|
|
11085
10362
|
if (storageOps.length > 0) {
|
|
11086
10363
|
for (const op of storageOps) {
|
|
11087
|
-
context.unacknowledgedOps.
|
|
10364
|
+
context.unacknowledgedOps.set(op.opId, op);
|
|
11088
10365
|
}
|
|
11089
10366
|
notifyStorageStatus();
|
|
11090
10367
|
}
|
|
@@ -11221,10 +10498,10 @@ function createRoom(options, config) {
|
|
|
11221
10498
|
timeoutId,
|
|
11222
10499
|
kind,
|
|
11223
10500
|
feedId,
|
|
11224
|
-
messageId: _optionalChain([options2, 'optionalAccess',
|
|
11225
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
10501
|
+
messageId: _optionalChain([options2, 'optionalAccess', _230 => _230.messageId]),
|
|
10502
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _231 => _231.expectedClientMessageId])
|
|
11226
10503
|
});
|
|
11227
|
-
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess',
|
|
10504
|
+
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess', _232 => _232.expectedClientMessageId]) === void 0) {
|
|
11228
10505
|
const q = _nullishCoalesce(pendingAddMessageFifoByFeed.get(feedId), () => ( []));
|
|
11229
10506
|
q.push(requestId);
|
|
11230
10507
|
pendingAddMessageFifoByFeed.set(feedId, q);
|
|
@@ -11275,10 +10552,10 @@ function createRoom(options, config) {
|
|
|
11275
10552
|
}
|
|
11276
10553
|
if (!matched) {
|
|
11277
10554
|
const q = pendingAddMessageFifoByFeed.get(message.feedId);
|
|
11278
|
-
const headId = _optionalChain([q, 'optionalAccess',
|
|
10555
|
+
const headId = _optionalChain([q, 'optionalAccess', _233 => _233[0]]);
|
|
11279
10556
|
if (headId !== void 0) {
|
|
11280
10557
|
const pending = pendingFeedMutations.get(headId);
|
|
11281
|
-
if (_optionalChain([pending, 'optionalAccess',
|
|
10558
|
+
if (_optionalChain([pending, 'optionalAccess', _234 => _234.kind]) === "add-message" && pending.expectedClientMessageId === void 0) {
|
|
11282
10559
|
settleFeedMutation(headId, "ok");
|
|
11283
10560
|
}
|
|
11284
10561
|
}
|
|
@@ -11311,10 +10588,10 @@ function createRoom(options, config) {
|
|
|
11311
10588
|
}
|
|
11312
10589
|
}
|
|
11313
10590
|
function processInitialStorage(nodes) {
|
|
11314
|
-
const
|
|
10591
|
+
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
11315
10592
|
createOrUpdateRootFromMessage(nodes);
|
|
11316
|
-
applyAndSendOfflineOps(
|
|
11317
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
10593
|
+
applyAndSendOfflineOps(unacknowledgedOps);
|
|
10594
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _235 => _235()]);
|
|
11318
10595
|
notifyStorageStatus();
|
|
11319
10596
|
eventHub.storageDidLoad.notify();
|
|
11320
10597
|
}
|
|
@@ -11332,7 +10609,7 @@ function createRoom(options, config) {
|
|
|
11332
10609
|
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
11333
10610
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
11334
10611
|
nodeMapBuffer.take();
|
|
11335
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
10612
|
+
_optionalChain([stopwatch, 'optionalAccess', _236 => _236.start, 'call', _237 => _237()]);
|
|
11336
10613
|
}
|
|
11337
10614
|
if (options2.flush) {
|
|
11338
10615
|
flushNowOrSoon();
|
|
@@ -11388,10 +10665,10 @@ function createRoom(options, config) {
|
|
|
11388
10665
|
const message = {
|
|
11389
10666
|
type: ClientMsgCode.FETCH_FEEDS,
|
|
11390
10667
|
requestId,
|
|
11391
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
11392
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
11393
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
11394
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
10668
|
+
cursor: _optionalChain([options2, 'optionalAccess', _238 => _238.cursor]),
|
|
10669
|
+
since: _optionalChain([options2, 'optionalAccess', _239 => _239.since]),
|
|
10670
|
+
limit: _optionalChain([options2, 'optionalAccess', _240 => _240.limit]),
|
|
10671
|
+
metadata: _optionalChain([options2, 'optionalAccess', _241 => _241.metadata])
|
|
11395
10672
|
};
|
|
11396
10673
|
context.buffer.messages.push(message);
|
|
11397
10674
|
flushNowOrSoon();
|
|
@@ -11411,9 +10688,9 @@ function createRoom(options, config) {
|
|
|
11411
10688
|
type: ClientMsgCode.FETCH_FEED_MESSAGES,
|
|
11412
10689
|
requestId,
|
|
11413
10690
|
feedId,
|
|
11414
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
11415
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
11416
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
10691
|
+
cursor: _optionalChain([options2, 'optionalAccess', _242 => _242.cursor]),
|
|
10692
|
+
since: _optionalChain([options2, 'optionalAccess', _243 => _243.since]),
|
|
10693
|
+
limit: _optionalChain([options2, 'optionalAccess', _244 => _244.limit])
|
|
11417
10694
|
};
|
|
11418
10695
|
context.buffer.messages.push(message);
|
|
11419
10696
|
flushNowOrSoon();
|
|
@@ -11432,8 +10709,8 @@ function createRoom(options, config) {
|
|
|
11432
10709
|
type: ClientMsgCode.ADD_FEED,
|
|
11433
10710
|
requestId,
|
|
11434
10711
|
feedId,
|
|
11435
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
11436
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
10712
|
+
metadata: _optionalChain([options2, 'optionalAccess', _245 => _245.metadata]),
|
|
10713
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _246 => _246.createdAt])
|
|
11437
10714
|
};
|
|
11438
10715
|
context.buffer.messages.push(message);
|
|
11439
10716
|
flushNowOrSoon();
|
|
@@ -11467,15 +10744,15 @@ function createRoom(options, config) {
|
|
|
11467
10744
|
function addFeedMessage(feedId, data, options2) {
|
|
11468
10745
|
const requestId = nanoid();
|
|
11469
10746
|
const promise = registerFeedMutation(requestId, "add-message", feedId, {
|
|
11470
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
10747
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _247 => _247.id])
|
|
11471
10748
|
});
|
|
11472
10749
|
const message = {
|
|
11473
10750
|
type: ClientMsgCode.ADD_FEED_MESSAGE,
|
|
11474
10751
|
requestId,
|
|
11475
10752
|
feedId,
|
|
11476
10753
|
data,
|
|
11477
|
-
id: _optionalChain([options2, 'optionalAccess',
|
|
11478
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
10754
|
+
id: _optionalChain([options2, 'optionalAccess', _248 => _248.id]),
|
|
10755
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _249 => _249.createdAt])
|
|
11479
10756
|
};
|
|
11480
10757
|
context.buffer.messages.push(message);
|
|
11481
10758
|
flushNowOrSoon();
|
|
@@ -11492,7 +10769,7 @@ function createRoom(options, config) {
|
|
|
11492
10769
|
feedId,
|
|
11493
10770
|
messageId,
|
|
11494
10771
|
data,
|
|
11495
|
-
updatedAt: _optionalChain([options2, 'optionalAccess',
|
|
10772
|
+
updatedAt: _optionalChain([options2, 'optionalAccess', _250 => _250.updatedAt])
|
|
11496
10773
|
};
|
|
11497
10774
|
context.buffer.messages.push(message);
|
|
11498
10775
|
flushNowOrSoon();
|
|
@@ -11699,8 +10976,8 @@ function createRoom(options, config) {
|
|
|
11699
10976
|
async function getThreads(options2) {
|
|
11700
10977
|
return httpClient.getThreads({
|
|
11701
10978
|
roomId,
|
|
11702
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
11703
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10979
|
+
query: _optionalChain([options2, 'optionalAccess', _251 => _251.query]),
|
|
10980
|
+
cursor: _optionalChain([options2, 'optionalAccess', _252 => _252.cursor])
|
|
11704
10981
|
});
|
|
11705
10982
|
}
|
|
11706
10983
|
async function getThread(threadId) {
|
|
@@ -11822,7 +11099,7 @@ function createRoom(options, config) {
|
|
|
11822
11099
|
function getSubscriptionSettings(options2) {
|
|
11823
11100
|
return httpClient.getSubscriptionSettings({
|
|
11824
11101
|
roomId,
|
|
11825
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
11102
|
+
signal: _optionalChain([options2, 'optionalAccess', _253 => _253.signal])
|
|
11826
11103
|
});
|
|
11827
11104
|
}
|
|
11828
11105
|
function updateSubscriptionSettings(settings) {
|
|
@@ -11844,7 +11121,7 @@ function createRoom(options, config) {
|
|
|
11844
11121
|
{
|
|
11845
11122
|
[kInternal]: {
|
|
11846
11123
|
get presenceBuffer() {
|
|
11847
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
11124
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _254 => _254.buffer, 'access', _255 => _255.presenceUpdates, 'optionalAccess', _256 => _256.data]), () => ( null)));
|
|
11848
11125
|
},
|
|
11849
11126
|
// prettier-ignore
|
|
11850
11127
|
get undoStack() {
|
|
@@ -11859,9 +11136,9 @@ function createRoom(options, config) {
|
|
|
11859
11136
|
return context.yjsProvider;
|
|
11860
11137
|
},
|
|
11861
11138
|
setYjsProvider(newProvider) {
|
|
11862
|
-
_optionalChain([context, 'access',
|
|
11139
|
+
_optionalChain([context, 'access', _257 => _257.yjsProvider, 'optionalAccess', _258 => _258.off, 'call', _259 => _259("status", yjsStatusDidChange)]);
|
|
11863
11140
|
context.yjsProvider = newProvider;
|
|
11864
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
11141
|
+
_optionalChain([newProvider, 'optionalAccess', _260 => _260.on, 'call', _261 => _261("status", yjsStatusDidChange)]);
|
|
11865
11142
|
context.yjsProviderDidChange.notify();
|
|
11866
11143
|
},
|
|
11867
11144
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -11902,11 +11179,6 @@ function createRoom(options, config) {
|
|
|
11902
11179
|
connect: () => managedSocket.connect(),
|
|
11903
11180
|
reconnect: () => managedSocket.reconnect(),
|
|
11904
11181
|
disconnect: () => managedSocket.disconnect(),
|
|
11905
|
-
_dump: () => {
|
|
11906
|
-
const n = context.pool.nodes.size;
|
|
11907
|
-
return `Room "${roomId}" (${n} node${n === 1 ? "" : "s"}):
|
|
11908
|
-
${dumpPool(context.pool)}`;
|
|
11909
|
-
},
|
|
11910
11182
|
destroy: () => {
|
|
11911
11183
|
pendingFeedsRequests.forEach(
|
|
11912
11184
|
(request) => request.reject(new Error("Room destroyed"))
|
|
@@ -11919,7 +11191,7 @@ ${dumpPool(context.pool)}`;
|
|
|
11919
11191
|
source.dispose();
|
|
11920
11192
|
}
|
|
11921
11193
|
eventHub.roomWillDestroy.notify();
|
|
11922
|
-
_optionalChain([context, 'access',
|
|
11194
|
+
_optionalChain([context, 'access', _262 => _262.yjsProvider, 'optionalAccess', _263 => _263.off, 'call', _264 => _264("status", yjsStatusDidChange)]);
|
|
11923
11195
|
syncSourceForStorage.destroy();
|
|
11924
11196
|
syncSourceForYjs.destroy();
|
|
11925
11197
|
uninstallBgTabSpy();
|
|
@@ -12079,7 +11351,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
12079
11351
|
}
|
|
12080
11352
|
if (isLiveNode(first)) {
|
|
12081
11353
|
const node = first;
|
|
12082
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
11354
|
+
if (_optionalChain([options, 'optionalAccess', _265 => _265.isDeep])) {
|
|
12083
11355
|
const storageCallback = second;
|
|
12084
11356
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
12085
11357
|
} else {
|
|
@@ -12098,7 +11370,11 @@ function isRoomEventName(value) {
|
|
|
12098
11370
|
}
|
|
12099
11371
|
function makeAuthDelegateForRoom(roomId, authManager) {
|
|
12100
11372
|
return async () => {
|
|
12101
|
-
return authManager.getAuthValue({
|
|
11373
|
+
return authManager.getAuthValue({
|
|
11374
|
+
roomId,
|
|
11375
|
+
resource: "presence",
|
|
11376
|
+
access: "read"
|
|
11377
|
+
});
|
|
12102
11378
|
};
|
|
12103
11379
|
}
|
|
12104
11380
|
function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
|
|
@@ -12147,7 +11423,7 @@ function getBaseUrl(baseUrl) {
|
|
|
12147
11423
|
function isLocalhost(url2) {
|
|
12148
11424
|
try {
|
|
12149
11425
|
return new URL(url2).hostname === "localhost";
|
|
12150
|
-
} catch (
|
|
11426
|
+
} catch (e11) {
|
|
12151
11427
|
return false;
|
|
12152
11428
|
}
|
|
12153
11429
|
}
|
|
@@ -12165,8 +11441,8 @@ function createClient(options) {
|
|
|
12165
11441
|
const authManager = createAuthManager(options, (token) => {
|
|
12166
11442
|
currentUserId.set(() => token.uid);
|
|
12167
11443
|
});
|
|
12168
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
12169
|
-
_optionalChain([globalThis, 'access',
|
|
11444
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _266 => _266.polyfills, 'optionalAccess', _267 => _267.fetch]) || /* istanbul ignore next */
|
|
11445
|
+
_optionalChain([globalThis, 'access', _268 => _268.fetch, 'optionalAccess', _269 => _269.bind, 'call', _270 => _270(globalThis)]);
|
|
12170
11446
|
const httpClient = createApiClient({
|
|
12171
11447
|
baseUrl,
|
|
12172
11448
|
fetchPolyfill,
|
|
@@ -12184,11 +11460,13 @@ function createClient(options) {
|
|
|
12184
11460
|
delegates: {
|
|
12185
11461
|
createSocket: makeCreateSocketDelegateForAi(
|
|
12186
11462
|
baseUrl,
|
|
12187
|
-
_optionalChain([clientOptions, 'access',
|
|
11463
|
+
_optionalChain([clientOptions, 'access', _271 => _271.polyfills, 'optionalAccess', _272 => _272.WebSocket])
|
|
12188
11464
|
),
|
|
12189
11465
|
authenticate: async () => {
|
|
12190
11466
|
const resp = await authManager.getAuthValue({
|
|
12191
|
-
|
|
11467
|
+
// TODO: Should we have permissions for AI Copilots?
|
|
11468
|
+
resource: "personal",
|
|
11469
|
+
access: "write"
|
|
12192
11470
|
});
|
|
12193
11471
|
if (resp.type === "public") {
|
|
12194
11472
|
throw new StopRetrying(
|
|
@@ -12254,7 +11532,7 @@ function createClient(options) {
|
|
|
12254
11532
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
12255
11533
|
roomId,
|
|
12256
11534
|
baseUrl,
|
|
12257
|
-
_optionalChain([clientOptions, 'access',
|
|
11535
|
+
_optionalChain([clientOptions, 'access', _273 => _273.polyfills, 'optionalAccess', _274 => _274.WebSocket])
|
|
12258
11536
|
),
|
|
12259
11537
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
12260
11538
|
})),
|
|
@@ -12277,7 +11555,7 @@ function createClient(options) {
|
|
|
12277
11555
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
12278
11556
|
if (shouldConnect) {
|
|
12279
11557
|
if (typeof atob === "undefined") {
|
|
12280
|
-
if (_optionalChain([clientOptions, 'access',
|
|
11558
|
+
if (_optionalChain([clientOptions, 'access', _275 => _275.polyfills, 'optionalAccess', _276 => _276.atob]) === void 0) {
|
|
12281
11559
|
throw new Error(
|
|
12282
11560
|
"You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
|
|
12283
11561
|
);
|
|
@@ -12289,7 +11567,7 @@ function createClient(options) {
|
|
|
12289
11567
|
return leaseRoom(newRoomDetails);
|
|
12290
11568
|
}
|
|
12291
11569
|
function getRoom(roomId) {
|
|
12292
|
-
const room = _optionalChain([roomsById, 'access',
|
|
11570
|
+
const room = _optionalChain([roomsById, 'access', _277 => _277.get, 'call', _278 => _278(roomId), 'optionalAccess', _279 => _279.room]);
|
|
12293
11571
|
return room ? room : null;
|
|
12294
11572
|
}
|
|
12295
11573
|
function logout() {
|
|
@@ -12305,7 +11583,7 @@ function createClient(options) {
|
|
|
12305
11583
|
const batchedResolveUsers = new Batch(
|
|
12306
11584
|
async (batchedUserIds) => {
|
|
12307
11585
|
const userIds = batchedUserIds.flat();
|
|
12308
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
11586
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _280 => _280({ userIds })]);
|
|
12309
11587
|
warnOnceIf(
|
|
12310
11588
|
!resolveUsers,
|
|
12311
11589
|
"Set the resolveUsers option in createClient to specify user info."
|
|
@@ -12322,7 +11600,7 @@ function createClient(options) {
|
|
|
12322
11600
|
const batchedResolveRoomsInfo = new Batch(
|
|
12323
11601
|
async (batchedRoomIds) => {
|
|
12324
11602
|
const roomIds = batchedRoomIds.flat();
|
|
12325
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
11603
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _281 => _281({ roomIds })]);
|
|
12326
11604
|
warnOnceIf(
|
|
12327
11605
|
!resolveRoomsInfo,
|
|
12328
11606
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
@@ -12339,7 +11617,7 @@ function createClient(options) {
|
|
|
12339
11617
|
const batchedResolveGroupsInfo = new Batch(
|
|
12340
11618
|
async (batchedGroupIds) => {
|
|
12341
11619
|
const groupIds = batchedGroupIds.flat();
|
|
12342
|
-
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall',
|
|
11620
|
+
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _282 => _282({ groupIds })]);
|
|
12343
11621
|
warnOnceIf(
|
|
12344
11622
|
!resolveGroupsInfo,
|
|
12345
11623
|
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
@@ -12398,7 +11676,7 @@ function createClient(options) {
|
|
|
12398
11676
|
}
|
|
12399
11677
|
};
|
|
12400
11678
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
12401
|
-
_optionalChain([win, 'optionalAccess',
|
|
11679
|
+
_optionalChain([win, 'optionalAccess', _283 => _283.addEventListener, 'call', _284 => _284("beforeunload", maybePreventClose)]);
|
|
12402
11680
|
}
|
|
12403
11681
|
async function getNotificationSettings(options2) {
|
|
12404
11682
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -12414,7 +11692,6 @@ function createClient(options) {
|
|
|
12414
11692
|
{
|
|
12415
11693
|
enterRoom,
|
|
12416
11694
|
getRoom,
|
|
12417
|
-
_dump: () => Array.from(roomsById.values(), ({ room }) => room._dump()).join("\n\n"),
|
|
12418
11695
|
logout,
|
|
12419
11696
|
// Public inbox notifications API
|
|
12420
11697
|
getInboxNotifications: httpClient.getInboxNotifications,
|
|
@@ -12526,7 +11803,7 @@ var commentBodyElementsTypes = {
|
|
|
12526
11803
|
mention: "inline"
|
|
12527
11804
|
};
|
|
12528
11805
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
12529
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
11806
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _285 => _285.content])) {
|
|
12530
11807
|
return;
|
|
12531
11808
|
}
|
|
12532
11809
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -12536,13 +11813,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
12536
11813
|
for (const block of body.content) {
|
|
12537
11814
|
if (type === "all" || type === "block") {
|
|
12538
11815
|
if (guard(block)) {
|
|
12539
|
-
_optionalChain([visitor, 'optionalCall',
|
|
11816
|
+
_optionalChain([visitor, 'optionalCall', _286 => _286(block)]);
|
|
12540
11817
|
}
|
|
12541
11818
|
}
|
|
12542
11819
|
if (type === "all" || type === "inline") {
|
|
12543
11820
|
for (const inline of block.children) {
|
|
12544
11821
|
if (guard(inline)) {
|
|
12545
|
-
_optionalChain([visitor, 'optionalCall',
|
|
11822
|
+
_optionalChain([visitor, 'optionalCall', _287 => _287(inline)]);
|
|
12546
11823
|
}
|
|
12547
11824
|
}
|
|
12548
11825
|
}
|
|
@@ -12712,7 +11989,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
12712
11989
|
text: ({ element }) => element.text,
|
|
12713
11990
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
12714
11991
|
mention: ({ element, user, group }) => {
|
|
12715
|
-
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
11992
|
+
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _288 => _288.name]), () => ( _optionalChain([group, 'optionalAccess', _289 => _289.name]))), () => ( element.id))}`;
|
|
12716
11993
|
}
|
|
12717
11994
|
};
|
|
12718
11995
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -12742,7 +12019,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
12742
12019
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
12743
12020
|
},
|
|
12744
12021
|
mention: ({ element, user, group }) => {
|
|
12745
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
12022
|
+
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _290 => _290.name]) ? html`${_optionalChain([user, 'optionalAccess', _291 => _291.name])}` : _optionalChain([group, 'optionalAccess', _292 => _292.name]) ? html`${_optionalChain([group, 'optionalAccess', _293 => _293.name])}` : element.id}</span>`;
|
|
12746
12023
|
}
|
|
12747
12024
|
};
|
|
12748
12025
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -12772,20 +12049,20 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
12772
12049
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
12773
12050
|
},
|
|
12774
12051
|
mention: ({ element, user, group }) => {
|
|
12775
|
-
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
12052
|
+
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _294 => _294.name]), () => ( _optionalChain([group, 'optionalAccess', _295 => _295.name]))), () => ( element.id))}`;
|
|
12776
12053
|
}
|
|
12777
12054
|
};
|
|
12778
12055
|
async function stringifyCommentBody(body, options) {
|
|
12779
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12780
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12056
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _296 => _296.format]), () => ( "plain"));
|
|
12057
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _297 => _297.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
12781
12058
|
const elements = {
|
|
12782
12059
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
12783
|
-
..._optionalChain([options, 'optionalAccess',
|
|
12060
|
+
..._optionalChain([options, 'optionalAccess', _298 => _298.elements])
|
|
12784
12061
|
};
|
|
12785
12062
|
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
12786
12063
|
body,
|
|
12787
|
-
_optionalChain([options, 'optionalAccess',
|
|
12788
|
-
_optionalChain([options, 'optionalAccess',
|
|
12064
|
+
_optionalChain([options, 'optionalAccess', _299 => _299.resolveUsers]),
|
|
12065
|
+
_optionalChain([options, 'optionalAccess', _300 => _300.resolveGroupsInfo])
|
|
12789
12066
|
);
|
|
12790
12067
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
12791
12068
|
switch (block.type) {
|
|
@@ -12867,12 +12144,6 @@ function toPlainLson(lson) {
|
|
|
12867
12144
|
liveblocksType: "LiveList",
|
|
12868
12145
|
data: [...lson].map((item) => toPlainLson(item))
|
|
12869
12146
|
};
|
|
12870
|
-
} else if (lson instanceof LiveText) {
|
|
12871
|
-
return {
|
|
12872
|
-
liveblocksType: "LiveText",
|
|
12873
|
-
data: lson.toJSON(),
|
|
12874
|
-
version: lson.version
|
|
12875
|
-
};
|
|
12876
12147
|
} else {
|
|
12877
12148
|
return lson;
|
|
12878
12149
|
}
|
|
@@ -12926,9 +12197,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
12926
12197
|
const startTime = performance.now();
|
|
12927
12198
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
12928
12199
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
12929
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12200
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _301 => _301.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
12930
12201
|
const context = {
|
|
12931
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
12202
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _302 => _302.visibilityState]) !== "hidden",
|
|
12932
12203
|
lastSuccessfulPollAt: startTime,
|
|
12933
12204
|
count: 0,
|
|
12934
12205
|
backoff: 0
|
|
@@ -13009,11 +12280,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
13009
12280
|
pollNowIfStale();
|
|
13010
12281
|
}
|
|
13011
12282
|
function onVisibilityChange() {
|
|
13012
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
12283
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _303 => _303.visibilityState]) !== "hidden");
|
|
13013
12284
|
}
|
|
13014
|
-
_optionalChain([doc, 'optionalAccess',
|
|
13015
|
-
_optionalChain([win, 'optionalAccess',
|
|
13016
|
-
_optionalChain([win, 'optionalAccess',
|
|
12285
|
+
_optionalChain([doc, 'optionalAccess', _304 => _304.addEventListener, 'call', _305 => _305("visibilitychange", onVisibilityChange)]);
|
|
12286
|
+
_optionalChain([win, 'optionalAccess', _306 => _306.addEventListener, 'call', _307 => _307("online", onVisibilityChange)]);
|
|
12287
|
+
_optionalChain([win, 'optionalAccess', _308 => _308.addEventListener, 'call', _309 => _309("focus", pollNowIfStale)]);
|
|
13017
12288
|
fsm.start();
|
|
13018
12289
|
return {
|
|
13019
12290
|
inc,
|
|
@@ -13154,5 +12425,8 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
13154
12425
|
|
|
13155
12426
|
|
|
13156
12427
|
|
|
13157
|
-
|
|
12428
|
+
|
|
12429
|
+
|
|
12430
|
+
|
|
12431
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.FeedRequestErrorCode = FeedRequestErrorCode; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MENTION_CHARACTER = MENTION_CHARACTER; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactNodesToNodeStream = compactNodesToNodeStream; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getRoomPermissionConflicts = getRoomPermissionConflicts; exports.getSubscriptionKey = getSubscriptionKey; exports.hasPermissionCapability = hasPermissionCapability; exports.hasPermissionCapabilityAccess = hasPermissionCapabilityAccess; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isListStorageNode = isListStorageNode; exports.isLiveNode = isLiveNode; exports.isMapStorageNode = isMapStorageNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isObjectStorageNode = isObjectStorageNode; exports.isPlainObject = isPlainObject; exports.isRegisterStorageNode = isRegisterStorageNode; exports.isRootStorageNode = isRootStorageNode; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.nodeStreamToCompactNodes = nodeStreamToCompactNodes; exports.normalizeRoomAccessesInput = normalizeRoomAccessesInput; exports.normalizeRoomAccessesUpdateInput = normalizeRoomAccessesUpdateInput; exports.normalizeRoomPermissionInput = normalizeRoomPermissionInput; exports.objectToQuery = objectToQuery; exports.patchNotificationSettings = patchNotificationSettings; exports.permissionCapabilitiesFromScopes = permissionCapabilitiesFromScopes; exports.raise = raise; exports.resolveMentionsInCommentBody = resolveMentionsInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
|
|
13158
12432
|
//# sourceMappingURL=index.cjs.map
|