@liveblocks/core 3.20.0-exp5 → 3.20.0-perm1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +645 -1348
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -191
- package/dist/index.d.ts +88 -191
- package/dist/index.js +550 -1253
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.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,95 +5980,12 @@ function asPos(str) {
|
|
|
5796
5980
|
return isPos(str) ? str : convertToPos(str);
|
|
5797
5981
|
}
|
|
5798
5982
|
|
|
5799
|
-
// src/crdts/UnacknowledgedOps.ts
|
|
5800
|
-
var UnacknowledgedOps = class {
|
|
5801
|
-
// opId -> op
|
|
5802
|
-
#byOpId = /* @__PURE__ */ new Map();
|
|
5803
|
-
// position -> (opId -> Create op)
|
|
5804
|
-
#createOpsByPosition = /* @__PURE__ */ new Map();
|
|
5805
|
-
// parentId -> (opId -> Create op)
|
|
5806
|
-
#createOpsByParent = /* @__PURE__ */ new Map();
|
|
5807
|
-
#posKey(parentId, parentKey) {
|
|
5808
|
-
return `${parentId}
|
|
5809
|
-
${parentKey}`;
|
|
5810
|
-
}
|
|
5811
|
-
get size() {
|
|
5812
|
-
return this.#byOpId.size;
|
|
5813
|
-
}
|
|
5814
|
-
/**
|
|
5815
|
-
* Mark the given Op as still unacknowledged.
|
|
5816
|
-
*/
|
|
5817
|
-
add(op) {
|
|
5818
|
-
this.#byOpId.set(op.opId, op);
|
|
5819
|
-
if (isCreateOp(op)) {
|
|
5820
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5821
|
-
let atPosition = this.#createOpsByPosition.get(posKey);
|
|
5822
|
-
if (atPosition === void 0) {
|
|
5823
|
-
atPosition = /* @__PURE__ */ new Map();
|
|
5824
|
-
this.#createOpsByPosition.set(posKey, atPosition);
|
|
5825
|
-
}
|
|
5826
|
-
atPosition.set(op.opId, op);
|
|
5827
|
-
let inParent = this.#createOpsByParent.get(op.parentId);
|
|
5828
|
-
if (inParent === void 0) {
|
|
5829
|
-
inParent = /* @__PURE__ */ new Map();
|
|
5830
|
-
this.#createOpsByParent.set(op.parentId, inParent);
|
|
5831
|
-
}
|
|
5832
|
-
inParent.set(op.opId, op);
|
|
5833
|
-
}
|
|
5834
|
-
}
|
|
5835
|
-
/**
|
|
5836
|
-
* Drop the op with the given opId from the set, because the server has
|
|
5837
|
-
* acknowledged it (confirmed our own op, or signalled it was seen but
|
|
5838
|
-
* ignored).
|
|
5839
|
-
*/
|
|
5840
|
-
delete(opId) {
|
|
5841
|
-
const op = this.#byOpId.get(opId);
|
|
5842
|
-
if (op === void 0) {
|
|
5843
|
-
return;
|
|
5844
|
-
}
|
|
5845
|
-
this.#byOpId.delete(opId);
|
|
5846
|
-
if (isCreateOp(op)) {
|
|
5847
|
-
const posKey = this.#posKey(op.parentId, op.parentKey);
|
|
5848
|
-
const atPosition = this.#createOpsByPosition.get(posKey);
|
|
5849
|
-
_optionalChain([atPosition, 'optionalAccess', _111 => _111.delete, 'call', _112 => _112(opId)]);
|
|
5850
|
-
if (atPosition !== void 0 && atPosition.size === 0) {
|
|
5851
|
-
this.#createOpsByPosition.delete(posKey);
|
|
5852
|
-
}
|
|
5853
|
-
const inParent = this.#createOpsByParent.get(op.parentId);
|
|
5854
|
-
_optionalChain([inParent, 'optionalAccess', _113 => _113.delete, 'call', _114 => _114(opId)]);
|
|
5855
|
-
if (inParent !== void 0 && inParent.size === 0) {
|
|
5856
|
-
this.#createOpsByParent.delete(op.parentId);
|
|
5857
|
-
}
|
|
5858
|
-
}
|
|
5859
|
-
}
|
|
5860
|
-
/**
|
|
5861
|
-
* The still-unacknowledged Create ops with the given `parentId` and
|
|
5862
|
-
* `parentKey` (targeting one exact position), in dispatch order. O(1) lookup.
|
|
5863
|
-
* Empty if none.
|
|
5864
|
-
*/
|
|
5865
|
-
getByParentIdAndKey(parentId, parentKey) {
|
|
5866
|
-
return _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()]), () => ( []));
|
|
5867
|
-
}
|
|
5868
|
-
/**
|
|
5869
|
-
* The still-unacknowledged Create ops with the given `parentId` (across all
|
|
5870
|
-
* positions), in dispatch order. O(1) lookup. Empty if none.
|
|
5871
|
-
*/
|
|
5872
|
-
getByParentId(parentId) {
|
|
5873
|
-
return _nullishCoalesce(_optionalChain([this, 'access', _120 => _120.#createOpsByParent, 'access', _121 => _121.get, 'call', _122 => _122(parentId), 'optionalAccess', _123 => _123.values, 'call', _124 => _124()]), () => ( []));
|
|
5874
|
-
}
|
|
5875
|
-
/** All still-unacknowledged ops, in dispatch order. */
|
|
5876
|
-
values() {
|
|
5877
|
-
return this.#byOpId.values();
|
|
5878
|
-
}
|
|
5879
|
-
};
|
|
5880
|
-
|
|
5881
5983
|
// src/crdts/AbstractCrdt.ts
|
|
5882
5984
|
function createManagedPool(roomId, options) {
|
|
5883
5985
|
const {
|
|
5884
5986
|
getCurrentConnectionId,
|
|
5885
5987
|
onDispatch,
|
|
5886
|
-
isStorageWritable = () => true
|
|
5887
|
-
unacknowledgedOps = new UnacknowledgedOps()
|
|
5988
|
+
isStorageWritable = () => true
|
|
5888
5989
|
} = options;
|
|
5889
5990
|
let clock = 0;
|
|
5890
5991
|
let opClock = 0;
|
|
@@ -5898,7 +5999,7 @@ function createManagedPool(roomId, options) {
|
|
|
5898
5999
|
generateId: () => `${getCurrentConnectionId()}:${clock++}`,
|
|
5899
6000
|
generateOpId: () => `${getCurrentConnectionId()}:${opClock++}`,
|
|
5900
6001
|
dispatch(ops, reverse, storageUpdates) {
|
|
5901
|
-
_optionalChain([onDispatch, 'optionalCall',
|
|
6002
|
+
_optionalChain([onDispatch, 'optionalCall', _111 => _111(ops, reverse, storageUpdates)]);
|
|
5902
6003
|
},
|
|
5903
6004
|
assertStorageIsWritable: () => {
|
|
5904
6005
|
if (!isStorageWritable()) {
|
|
@@ -5906,8 +6007,7 @@ function createManagedPool(roomId, options) {
|
|
|
5906
6007
|
"Cannot write to storage with a read only user, please ensure the user has write permissions"
|
|
5907
6008
|
);
|
|
5908
6009
|
}
|
|
5909
|
-
}
|
|
5910
|
-
unacknowledgedOps
|
|
6010
|
+
}
|
|
5911
6011
|
};
|
|
5912
6012
|
}
|
|
5913
6013
|
function crdtAsLiveNode(value) {
|
|
@@ -6189,9 +6289,11 @@ function childNodeLt(a, b) {
|
|
|
6189
6289
|
var LiveList = class _LiveList extends AbstractCrdt {
|
|
6190
6290
|
#items;
|
|
6191
6291
|
#implicitlyDeletedItems;
|
|
6292
|
+
#unacknowledgedSets;
|
|
6192
6293
|
constructor(items) {
|
|
6193
6294
|
super();
|
|
6194
6295
|
this.#implicitlyDeletedItems = /* @__PURE__ */ new WeakSet();
|
|
6296
|
+
this.#unacknowledgedSets = /* @__PURE__ */ new Map();
|
|
6195
6297
|
const nodes = [];
|
|
6196
6298
|
let lastPos;
|
|
6197
6299
|
for (const item of items) {
|
|
@@ -6221,13 +6323,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6221
6323
|
}
|
|
6222
6324
|
/**
|
|
6223
6325
|
* @internal
|
|
6224
|
-
*
|
|
6225
|
-
*
|
|
6226
|
-
*
|
|
6227
|
-
* items (flicker, https://github.com/liveblocks/liveblocks/pull/1177).
|
|
6326
|
+
* This function assumes that the resulting ops will be sent to the server if they have an 'opId'
|
|
6327
|
+
* so we mutate _unacknowledgedSets to avoid potential flickering
|
|
6328
|
+
* https://github.com/liveblocks/liveblocks/pull/1177
|
|
6228
6329
|
*
|
|
6229
|
-
* This is quite unintuitive and should disappear as soon as
|
|
6230
|
-
* explicit LiveList.Set operation
|
|
6330
|
+
* This is quite unintuitive and should disappear as soon as
|
|
6331
|
+
* we introduce an explicit LiveList.Set operation
|
|
6231
6332
|
*/
|
|
6232
6333
|
_toOps(parentId, parentKey) {
|
|
6233
6334
|
if (this._id === void 0) {
|
|
@@ -6243,9 +6344,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6243
6344
|
ops.push(op);
|
|
6244
6345
|
for (const item of this.#items) {
|
|
6245
6346
|
const parentKey2 = item._getParentKeyOrThrow();
|
|
6246
|
-
const childOps =
|
|
6347
|
+
const childOps = HACK_addIntentAndDeletedIdToOperation(
|
|
6247
6348
|
item._toOps(this._id, parentKey2),
|
|
6248
|
-
|
|
6349
|
+
void 0
|
|
6249
6350
|
);
|
|
6250
6351
|
for (const childOp of childOps) {
|
|
6251
6352
|
ops.push(childOp);
|
|
@@ -6287,28 +6388,6 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6287
6388
|
(item) => item._getParentKeyOrThrow() === position
|
|
6288
6389
|
);
|
|
6289
6390
|
}
|
|
6290
|
-
/**
|
|
6291
|
-
* The opId of this list's still-unacknowledged "set" op at the given position,
|
|
6292
|
-
* or undefined if none. Derived from the room's unacknowledgedOps (the single
|
|
6293
|
-
* source of truth) rather than tracked in a per-instance map. The pool's
|
|
6294
|
-
* position index already scopes to this list's (parentId, position); the last
|
|
6295
|
-
* match wins, matching the original last-write-wins map semantics.
|
|
6296
|
-
*/
|
|
6297
|
-
#unacknowledgedSetOpIdAt(position) {
|
|
6298
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6299
|
-
return void 0;
|
|
6300
|
-
}
|
|
6301
|
-
let opId;
|
|
6302
|
-
for (const op of this._pool.unacknowledgedOps.getByParentIdAndKey(
|
|
6303
|
-
this._id,
|
|
6304
|
-
position
|
|
6305
|
-
)) {
|
|
6306
|
-
if (op.intent === "set") {
|
|
6307
|
-
opId = op.opId;
|
|
6308
|
-
}
|
|
6309
|
-
}
|
|
6310
|
-
return opId;
|
|
6311
|
-
}
|
|
6312
6391
|
/** @internal */
|
|
6313
6392
|
_attach(id, pool) {
|
|
6314
6393
|
super._attach(id, pool);
|
|
@@ -6389,9 +6468,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6389
6468
|
if (deletedDelta) {
|
|
6390
6469
|
delta.push(deletedDelta);
|
|
6391
6470
|
}
|
|
6392
|
-
const unacknowledgedOpId = this.#
|
|
6393
|
-
if (unacknowledgedOpId !== void 0
|
|
6394
|
-
|
|
6471
|
+
const unacknowledgedOpId = this.#unacknowledgedSets.get(op.parentKey);
|
|
6472
|
+
if (unacknowledgedOpId !== void 0) {
|
|
6473
|
+
if (unacknowledgedOpId !== op.opId) {
|
|
6474
|
+
return delta.length === 0 ? { modified: false } : { modified: makeUpdate(this, delta), reverse: [] };
|
|
6475
|
+
} else {
|
|
6476
|
+
this.#unacknowledgedSets.delete(op.parentKey);
|
|
6477
|
+
}
|
|
6395
6478
|
}
|
|
6396
6479
|
const indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey);
|
|
6397
6480
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
@@ -6472,7 +6555,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6472
6555
|
}
|
|
6473
6556
|
return result.modified.updates[0];
|
|
6474
6557
|
}
|
|
6475
|
-
#applyRemoteInsert(op
|
|
6558
|
+
#applyRemoteInsert(op) {
|
|
6476
6559
|
if (this._pool === void 0) {
|
|
6477
6560
|
throw new Error("Can't attach child if managed pool is not present");
|
|
6478
6561
|
}
|
|
@@ -6482,82 +6565,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6482
6565
|
this.#shiftItemPosition(existingItemIndex, key);
|
|
6483
6566
|
}
|
|
6484
6567
|
const { newItem, newIndex } = this.#createAttachItemAndSort(op, key);
|
|
6485
|
-
const bumpDeltas = fromSnapshot ? [] : this.#bumpUnackedPushesAbove(key);
|
|
6486
6568
|
return {
|
|
6487
|
-
modified: makeUpdate(this, [
|
|
6488
|
-
insertDelta(newIndex, newItem),
|
|
6489
|
-
...bumpDeltas
|
|
6490
|
-
]),
|
|
6569
|
+
modified: makeUpdate(this, [insertDelta(newIndex, newItem)]),
|
|
6491
6570
|
reverse: []
|
|
6492
6571
|
};
|
|
6493
6572
|
}
|
|
6494
|
-
/**
|
|
6495
|
-
* This list's own still-unacknowledged pushed items (their `intent: "push"`
|
|
6496
|
-
* Create op is still pending in the room's unacknowledgedOps). Derived from
|
|
6497
|
-
* the single source of truth, so an item drops out the instant its op is
|
|
6498
|
-
* acked, with no per-instance membership to leak. Yielded in push order.
|
|
6499
|
-
*
|
|
6500
|
-
* Restricted to items currently in `#items`: a pushed node whose op is still
|
|
6501
|
-
* pending may have been pulled out of the list (e.g. implicitly deleted by a
|
|
6502
|
-
* remote set, or removed by an undo) while still living in the pool, and such
|
|
6503
|
-
* a node must not be repositioned.
|
|
6504
|
-
*/
|
|
6505
|
-
*#unackedPushNodes() {
|
|
6506
|
-
if (this._pool === void 0 || this._id === void 0) {
|
|
6507
|
-
return;
|
|
6508
|
-
}
|
|
6509
|
-
for (const op of this._pool.unacknowledgedOps.getByParentId(this._id)) {
|
|
6510
|
-
if (op.intent !== "push") {
|
|
6511
|
-
continue;
|
|
6512
|
-
}
|
|
6513
|
-
const node = this._pool.getNode(op.id);
|
|
6514
|
-
if (node !== void 0 && this.#items.includes(node)) {
|
|
6515
|
-
yield node;
|
|
6516
|
-
}
|
|
6517
|
-
}
|
|
6518
|
-
}
|
|
6519
|
-
/**
|
|
6520
|
-
* Optimistic no-flip for pushed items. When a remote op lands at or below my
|
|
6521
|
-
* still-unacked pushed items, those items must end up *after* it: FIFO plus
|
|
6522
|
-
* the room's serial processing guarantee the remote was processed first, so
|
|
6523
|
-
* my unacked pushes belong behind it. Re-chain the whole unacked-push block,
|
|
6524
|
-
* in push order, to sit after the highest confirmed sibling, so it keeps
|
|
6525
|
-
* rendering as a contiguous tail instead of getting interleaved. Local-only;
|
|
6526
|
-
* the real acks overwrite these keys with the (identical) server keys.
|
|
6527
|
-
*/
|
|
6528
|
-
#bumpUnackedPushesAbove(remoteKey) {
|
|
6529
|
-
const pending = new Set(this.#unackedPushNodes());
|
|
6530
|
-
if (pending.size === 0) {
|
|
6531
|
-
return [];
|
|
6532
|
-
}
|
|
6533
|
-
let minPending;
|
|
6534
|
-
for (const node of pending) {
|
|
6535
|
-
const pos = node._parentPos;
|
|
6536
|
-
if (minPending === void 0 || pos < minPending) {
|
|
6537
|
-
minPending = pos;
|
|
6538
|
-
}
|
|
6539
|
-
}
|
|
6540
|
-
if (remoteKey < nn(minPending)) {
|
|
6541
|
-
return [];
|
|
6542
|
-
}
|
|
6543
|
-
let base;
|
|
6544
|
-
for (const item of this.#items) {
|
|
6545
|
-
if (!pending.has(item)) {
|
|
6546
|
-
base = item._parentPos;
|
|
6547
|
-
}
|
|
6548
|
-
}
|
|
6549
|
-
const deltas = [];
|
|
6550
|
-
for (const node of pending) {
|
|
6551
|
-
const previousIndex = this.#items.findIndex((item) => item === node);
|
|
6552
|
-
base = makePosition(base);
|
|
6553
|
-
this.#updateItemPosition(node, base);
|
|
6554
|
-
const index = this.#items.findIndex((item) => item === node);
|
|
6555
|
-
if (index !== previousIndex) {
|
|
6556
|
-
deltas.push(moveDelta(previousIndex, index, node));
|
|
6557
|
-
}
|
|
6558
|
-
}
|
|
6559
|
-
return deltas;
|
|
6560
|
-
}
|
|
6561
6573
|
#applyInsertAck(op) {
|
|
6562
6574
|
const existingItem = this.#items.find((item) => item._id === op.id);
|
|
6563
6575
|
const key = asPos(op.parentKey);
|
|
@@ -6612,7 +6624,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6612
6624
|
#applyInsertUndoRedo(op) {
|
|
6613
6625
|
const { id, parentKey: key } = op;
|
|
6614
6626
|
const child = creationOpToLiveNode(op);
|
|
6615
|
-
if (_optionalChain([this, 'access',
|
|
6627
|
+
if (_optionalChain([this, 'access', _112 => _112._pool, 'optionalAccess', _113 => _113.getNode, 'call', _114 => _114(id)]) !== void 0) {
|
|
6616
6628
|
return { modified: false };
|
|
6617
6629
|
}
|
|
6618
6630
|
child._attach(id, nn(this._pool));
|
|
@@ -6620,8 +6632,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6620
6632
|
const existingItemIndex = this._indexOfPosition(key);
|
|
6621
6633
|
let newKey = key;
|
|
6622
6634
|
if (existingItemIndex !== -1) {
|
|
6623
|
-
const before2 = _optionalChain([this, 'access',
|
|
6624
|
-
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]);
|
|
6625
6637
|
newKey = makePosition(before2, after2);
|
|
6626
6638
|
child._setParentLink(this, newKey);
|
|
6627
6639
|
}
|
|
@@ -6635,9 +6647,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6635
6647
|
#applySetUndoRedo(op) {
|
|
6636
6648
|
const { id, parentKey: key } = op;
|
|
6637
6649
|
const child = creationOpToLiveNode(op);
|
|
6638
|
-
if (_optionalChain([this, 'access',
|
|
6650
|
+
if (_optionalChain([this, 'access', _123 => _123._pool, 'optionalAccess', _124 => _124.getNode, 'call', _125 => _125(id)]) !== void 0) {
|
|
6639
6651
|
return { modified: false };
|
|
6640
6652
|
}
|
|
6653
|
+
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
6641
6654
|
const indexOfItemWithSameKey = this._indexOfPosition(key);
|
|
6642
6655
|
child._attach(id, nn(this._pool));
|
|
6643
6656
|
child._setParentLink(this, key);
|
|
@@ -6647,9 +6660,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6647
6660
|
existingItem._detach();
|
|
6648
6661
|
this.#items.remove(existingItem);
|
|
6649
6662
|
this.#items.add(child);
|
|
6650
|
-
const reverse =
|
|
6663
|
+
const reverse = HACK_addIntentAndDeletedIdToOperation(
|
|
6651
6664
|
existingItem._toOps(nn(this._id), key),
|
|
6652
|
-
"set",
|
|
6653
6665
|
op.id
|
|
6654
6666
|
);
|
|
6655
6667
|
const delta = [setDelta(indexOfItemWithSameKey, child)];
|
|
@@ -6674,7 +6686,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6674
6686
|
}
|
|
6675
6687
|
}
|
|
6676
6688
|
/** @internal */
|
|
6677
|
-
_attachChild(op, source
|
|
6689
|
+
_attachChild(op, source) {
|
|
6678
6690
|
if (this._pool === void 0) {
|
|
6679
6691
|
throw new Error("Can't attach child if managed pool is not present");
|
|
6680
6692
|
}
|
|
@@ -6689,7 +6701,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6689
6701
|
}
|
|
6690
6702
|
} else {
|
|
6691
6703
|
if (source === 1 /* THEIRS */) {
|
|
6692
|
-
result = this.#applyRemoteInsert(op
|
|
6704
|
+
result = this.#applyRemoteInsert(op);
|
|
6693
6705
|
} else if (source === 2 /* OURS */) {
|
|
6694
6706
|
result = this.#applyInsertAck(op);
|
|
6695
6707
|
} else {
|
|
@@ -6756,7 +6768,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6756
6768
|
} else {
|
|
6757
6769
|
this.#updateItemPositionAt(
|
|
6758
6770
|
existingItemIndex,
|
|
6759
|
-
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]))
|
|
6760
6772
|
);
|
|
6761
6773
|
const previousIndex = this.#items.findIndex((item) => item === child);
|
|
6762
6774
|
this.#updateItemPosition(child, newKey);
|
|
@@ -6783,7 +6795,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6783
6795
|
this,
|
|
6784
6796
|
makePosition(
|
|
6785
6797
|
newKey,
|
|
6786
|
-
_optionalChain([this, 'access',
|
|
6798
|
+
_optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131.at, 'call', _132 => _132(existingItemIndex + 1), 'optionalAccess', _133 => _133._parentPos])
|
|
6787
6799
|
)
|
|
6788
6800
|
);
|
|
6789
6801
|
this.#items.reposition(existingItem);
|
|
@@ -6807,7 +6819,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6807
6819
|
existingItemIndex,
|
|
6808
6820
|
makePosition(
|
|
6809
6821
|
newKey,
|
|
6810
|
-
_optionalChain([this, 'access',
|
|
6822
|
+
_optionalChain([this, 'access', _134 => _134.#items, 'access', _135 => _135.at, 'call', _136 => _136(existingItemIndex + 1), 'optionalAccess', _137 => _137._parentPos])
|
|
6811
6823
|
)
|
|
6812
6824
|
);
|
|
6813
6825
|
}
|
|
@@ -6835,7 +6847,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6835
6847
|
if (existingItemIndex !== -1) {
|
|
6836
6848
|
actualNewKey = makePosition(
|
|
6837
6849
|
newKey,
|
|
6838
|
-
_optionalChain([this, 'access',
|
|
6850
|
+
_optionalChain([this, 'access', _138 => _138.#items, 'access', _139 => _139.at, 'call', _140 => _140(existingItemIndex + 1), 'optionalAccess', _141 => _141._parentPos])
|
|
6839
6851
|
);
|
|
6840
6852
|
}
|
|
6841
6853
|
this.#updateItemPosition(child, actualNewKey);
|
|
@@ -6892,7 +6904,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6892
6904
|
* @param element The element to add to the end of the LiveList.
|
|
6893
6905
|
*/
|
|
6894
6906
|
push(element) {
|
|
6895
|
-
|
|
6907
|
+
_optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
|
|
6908
|
+
return this.insert(element, this.length);
|
|
6896
6909
|
}
|
|
6897
6910
|
/**
|
|
6898
6911
|
* Inserts one element at a specified index.
|
|
@@ -6900,23 +6913,14 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6900
6913
|
* @param index The index at which you want to insert the element.
|
|
6901
6914
|
*/
|
|
6902
6915
|
insert(element, index) {
|
|
6903
|
-
|
|
6904
|
-
}
|
|
6905
|
-
/**
|
|
6906
|
-
* Shared implementation of `insert` and `push`. A `"push"` intent leaves the
|
|
6907
|
-
* client-computed position untouched (so optimistic rendering is unchanged),
|
|
6908
|
-
* but tags the Op so the server appends it to the true end of the list
|
|
6909
|
-
* instead of resolving its position against the client's stale view.
|
|
6910
|
-
*/
|
|
6911
|
-
#injectAt(element, index, intent) {
|
|
6912
|
-
_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()]);
|
|
6913
6917
|
if (index < 0 || index > this.#items.length) {
|
|
6914
6918
|
throw new Error(
|
|
6915
6919
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
6916
6920
|
);
|
|
6917
6921
|
}
|
|
6918
|
-
const before2 = _optionalChain([this, 'access',
|
|
6919
|
-
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]);
|
|
6920
6924
|
const position = makePosition(before2, after2);
|
|
6921
6925
|
const value = lsonToLiveNode(element);
|
|
6922
6926
|
value._setParentLink(this, position);
|
|
@@ -6924,9 +6928,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6924
6928
|
if (this._pool && this._id) {
|
|
6925
6929
|
const id = this._pool.generateId();
|
|
6926
6930
|
value._attach(id, this._pool);
|
|
6927
|
-
const ops = value._toOpsWithOpId(this._id, position, this._pool);
|
|
6928
6931
|
this._pool.dispatch(
|
|
6929
|
-
|
|
6932
|
+
value._toOpsWithOpId(this._id, position, this._pool),
|
|
6930
6933
|
[{ type: OpCode.DELETE_CRDT, id }],
|
|
6931
6934
|
/* @__PURE__ */ new Map([
|
|
6932
6935
|
[this._id, makeUpdate(this, [insertDelta(index, value)])]
|
|
@@ -6940,7 +6943,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6940
6943
|
* @param targetIndex The index where the element should be after moving.
|
|
6941
6944
|
*/
|
|
6942
6945
|
move(index, targetIndex) {
|
|
6943
|
-
_optionalChain([this, 'access',
|
|
6946
|
+
_optionalChain([this, 'access', _156 => _156._pool, 'optionalAccess', _157 => _157.assertStorageIsWritable, 'call', _158 => _158()]);
|
|
6944
6947
|
if (targetIndex < 0) {
|
|
6945
6948
|
throw new Error("targetIndex cannot be less than 0");
|
|
6946
6949
|
}
|
|
@@ -6958,11 +6961,11 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6958
6961
|
let beforePosition = null;
|
|
6959
6962
|
let afterPosition = null;
|
|
6960
6963
|
if (index < targetIndex) {
|
|
6961
|
-
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]);
|
|
6962
6965
|
beforePosition = this.#items.at(targetIndex)._parentPos;
|
|
6963
6966
|
} else {
|
|
6964
6967
|
afterPosition = this.#items.at(targetIndex)._parentPos;
|
|
6965
|
-
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]);
|
|
6966
6969
|
}
|
|
6967
6970
|
const position = makePosition(beforePosition, afterPosition);
|
|
6968
6971
|
const item = this.#items.at(index);
|
|
@@ -6997,7 +7000,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6997
7000
|
* @param index The index of the element to delete
|
|
6998
7001
|
*/
|
|
6999
7002
|
delete(index) {
|
|
7000
|
-
_optionalChain([this, 'access',
|
|
7003
|
+
_optionalChain([this, 'access', _167 => _167._pool, 'optionalAccess', _168 => _168.assertStorageIsWritable, 'call', _169 => _169()]);
|
|
7001
7004
|
if (index < 0 || index >= this.#items.length) {
|
|
7002
7005
|
throw new Error(
|
|
7003
7006
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -7030,7 +7033,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7030
7033
|
}
|
|
7031
7034
|
}
|
|
7032
7035
|
clear() {
|
|
7033
|
-
_optionalChain([this, 'access',
|
|
7036
|
+
_optionalChain([this, 'access', _170 => _170._pool, 'optionalAccess', _171 => _171.assertStorageIsWritable, 'call', _172 => _172()]);
|
|
7034
7037
|
if (this._pool) {
|
|
7035
7038
|
const ops = [];
|
|
7036
7039
|
const reverseOps = [];
|
|
@@ -7064,7 +7067,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7064
7067
|
}
|
|
7065
7068
|
}
|
|
7066
7069
|
set(index, item) {
|
|
7067
|
-
_optionalChain([this, 'access',
|
|
7070
|
+
_optionalChain([this, 'access', _173 => _173._pool, 'optionalAccess', _174 => _174.assertStorageIsWritable, 'call', _175 => _175()]);
|
|
7068
7071
|
if (index < 0 || index >= this.#items.length) {
|
|
7069
7072
|
throw new Error(
|
|
7070
7073
|
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -7084,14 +7087,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7084
7087
|
value._attach(id, this._pool);
|
|
7085
7088
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7086
7089
|
storageUpdates.set(this._id, makeUpdate(this, [setDelta(index, value)]));
|
|
7087
|
-
const ops =
|
|
7090
|
+
const ops = HACK_addIntentAndDeletedIdToOperation(
|
|
7088
7091
|
value._toOpsWithOpId(this._id, position, this._pool),
|
|
7089
|
-
"set",
|
|
7090
7092
|
existingId
|
|
7091
7093
|
);
|
|
7092
|
-
|
|
7094
|
+
this.#unacknowledgedSets.set(position, nn(ops[0].opId));
|
|
7095
|
+
const reverseOps = HACK_addIntentAndDeletedIdToOperation(
|
|
7093
7096
|
existingItem._toOps(this._id, position),
|
|
7094
|
-
"set",
|
|
7095
7097
|
id
|
|
7096
7098
|
);
|
|
7097
7099
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
@@ -7223,7 +7225,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7223
7225
|
#shiftItemPosition(index, key) {
|
|
7224
7226
|
const shiftedPosition = makePosition(
|
|
7225
7227
|
key,
|
|
7226
|
-
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
|
|
7227
7229
|
);
|
|
7228
7230
|
this.#updateItemPositionAt(index, shiftedPosition);
|
|
7229
7231
|
}
|
|
@@ -7292,11 +7294,15 @@ function moveDelta(previousIndex, index, item) {
|
|
|
7292
7294
|
previousIndex
|
|
7293
7295
|
};
|
|
7294
7296
|
}
|
|
7295
|
-
function
|
|
7297
|
+
function HACK_addIntentAndDeletedIdToOperation(ops, deletedId) {
|
|
7296
7298
|
return ops.map((op, index) => {
|
|
7297
7299
|
if (index === 0) {
|
|
7298
7300
|
const firstOp = op;
|
|
7299
|
-
return {
|
|
7301
|
+
return {
|
|
7302
|
+
...firstOp,
|
|
7303
|
+
intent: "set",
|
|
7304
|
+
deletedId
|
|
7305
|
+
};
|
|
7300
7306
|
} else {
|
|
7301
7307
|
return op;
|
|
7302
7308
|
}
|
|
@@ -7472,7 +7478,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7472
7478
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
7473
7479
|
*/
|
|
7474
7480
|
set(key, value) {
|
|
7475
|
-
_optionalChain([this, 'access',
|
|
7481
|
+
_optionalChain([this, 'access', _180 => _180._pool, 'optionalAccess', _181 => _181.assertStorageIsWritable, 'call', _182 => _182()]);
|
|
7476
7482
|
const oldValue = this.#map.get(key);
|
|
7477
7483
|
if (oldValue) {
|
|
7478
7484
|
oldValue._detach();
|
|
@@ -7518,7 +7524,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7518
7524
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
7519
7525
|
*/
|
|
7520
7526
|
delete(key) {
|
|
7521
|
-
_optionalChain([this, 'access',
|
|
7527
|
+
_optionalChain([this, 'access', _183 => _183._pool, 'optionalAccess', _184 => _184.assertStorageIsWritable, 'call', _185 => _185()]);
|
|
7522
7528
|
const item = this.#map.get(key);
|
|
7523
7529
|
if (item === void 0) {
|
|
7524
7530
|
return false;
|
|
@@ -7948,7 +7954,6 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7948
7954
|
const id = nn(this._id);
|
|
7949
7955
|
const parentKey = nn(child._parentKey);
|
|
7950
7956
|
const reverse = child._toOps(id, parentKey);
|
|
7951
|
-
const deletedItem = liveNodeToLson(child);
|
|
7952
7957
|
for (const [key, value] of this.#synced) {
|
|
7953
7958
|
if (value === child) {
|
|
7954
7959
|
this.#synced.delete(key);
|
|
@@ -7960,7 +7965,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7960
7965
|
node: this,
|
|
7961
7966
|
type: "LiveObject",
|
|
7962
7967
|
updates: {
|
|
7963
|
-
[parentKey]: { type: "delete"
|
|
7968
|
+
[parentKey]: { type: "delete" }
|
|
7964
7969
|
}
|
|
7965
7970
|
};
|
|
7966
7971
|
return { modified: storageUpdate, reverse };
|
|
@@ -8130,20 +8135,20 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8130
8135
|
* Caveat: this method will not add changes to the undo/redo stack.
|
|
8131
8136
|
*/
|
|
8132
8137
|
setLocal(key, value) {
|
|
8133
|
-
_optionalChain([this, 'access',
|
|
8138
|
+
_optionalChain([this, 'access', _186 => _186._pool, 'optionalAccess', _187 => _187.assertStorageIsWritable, 'call', _188 => _188()]);
|
|
8134
8139
|
const deleteResult = this.#prepareDelete(key);
|
|
8135
8140
|
this.#local.set(key, value);
|
|
8136
8141
|
this.invalidate();
|
|
8137
8142
|
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8138
|
-
const ops = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess',
|
|
8139
|
-
const reverse = _nullishCoalesce(_optionalChain([deleteResult, 'optionalAccess',
|
|
8140
|
-
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()));
|
|
8141
8146
|
const existing = storageUpdates.get(this._id);
|
|
8142
8147
|
storageUpdates.set(this._id, {
|
|
8143
8148
|
node: this,
|
|
8144
8149
|
type: "LiveObject",
|
|
8145
8150
|
updates: {
|
|
8146
|
-
..._optionalChain([existing, 'optionalAccess',
|
|
8151
|
+
..._optionalChain([existing, 'optionalAccess', _192 => _192.updates]),
|
|
8147
8152
|
[key]: { type: "update" }
|
|
8148
8153
|
}
|
|
8149
8154
|
});
|
|
@@ -8163,7 +8168,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8163
8168
|
* #synced or pool/id are unavailable. Does NOT dispatch.
|
|
8164
8169
|
*/
|
|
8165
8170
|
#prepareDelete(key) {
|
|
8166
|
-
_optionalChain([this, 'access',
|
|
8171
|
+
_optionalChain([this, 'access', _193 => _193._pool, 'optionalAccess', _194 => _194.assertStorageIsWritable, 'call', _195 => _195()]);
|
|
8167
8172
|
const k = key;
|
|
8168
8173
|
if (this.#local.has(k) && !this.#synced.has(k)) {
|
|
8169
8174
|
const oldValue2 = this.#local.get(k);
|
|
@@ -8239,7 +8244,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8239
8244
|
const result = this.#prepareDelete(key);
|
|
8240
8245
|
if (result) {
|
|
8241
8246
|
const [ops, reverse, storageUpdates] = result;
|
|
8242
|
-
_optionalChain([this, 'access',
|
|
8247
|
+
_optionalChain([this, 'access', _196 => _196._pool, 'optionalAccess', _197 => _197.dispatch, 'call', _198 => _198(ops, reverse, storageUpdates)]);
|
|
8243
8248
|
}
|
|
8244
8249
|
}
|
|
8245
8250
|
/**
|
|
@@ -8247,7 +8252,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8247
8252
|
* @param patch The object used to overrides properties
|
|
8248
8253
|
*/
|
|
8249
8254
|
update(patch) {
|
|
8250
|
-
_optionalChain([this, 'access',
|
|
8255
|
+
_optionalChain([this, 'access', _199 => _199._pool, 'optionalAccess', _200 => _200.assertStorageIsWritable, 'call', _201 => _201()]);
|
|
8251
8256
|
if (_LiveObject.detectLargeObjects) {
|
|
8252
8257
|
const data = {};
|
|
8253
8258
|
for (const [key, value] of this.#synced) {
|
|
@@ -8447,580 +8452,6 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8447
8452
|
}
|
|
8448
8453
|
}, _class2.__initStatic(), _class2);
|
|
8449
8454
|
|
|
8450
|
-
// src/crdts/liveTextOps.ts
|
|
8451
|
-
function attributesEqual(left, right) {
|
|
8452
|
-
if (left === right) {
|
|
8453
|
-
return true;
|
|
8454
|
-
}
|
|
8455
|
-
if (left === void 0 || right === void 0) {
|
|
8456
|
-
return false;
|
|
8457
|
-
}
|
|
8458
|
-
const leftKeys = Object.keys(left);
|
|
8459
|
-
const rightKeys = Object.keys(right);
|
|
8460
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
8461
|
-
return false;
|
|
8462
|
-
}
|
|
8463
|
-
for (const key of leftKeys) {
|
|
8464
|
-
if (left[key] !== right[key]) {
|
|
8465
|
-
return false;
|
|
8466
|
-
}
|
|
8467
|
-
}
|
|
8468
|
-
return true;
|
|
8469
|
-
}
|
|
8470
|
-
function cloneAttributes(attributes) {
|
|
8471
|
-
return attributes === void 0 ? void 0 : freeze({ ...attributes });
|
|
8472
|
-
}
|
|
8473
|
-
function normalizeSegments(segments) {
|
|
8474
|
-
const normalized = [];
|
|
8475
|
-
for (const segment of segments) {
|
|
8476
|
-
if (segment.text.length === 0) {
|
|
8477
|
-
continue;
|
|
8478
|
-
}
|
|
8479
|
-
const last = normalized.at(-1);
|
|
8480
|
-
const attributes = cloneAttributes(segment.attributes);
|
|
8481
|
-
if (last !== void 0 && attributesEqual(last.attributes, attributes)) {
|
|
8482
|
-
last.text += segment.text;
|
|
8483
|
-
} else {
|
|
8484
|
-
normalized.push({ text: segment.text, attributes });
|
|
8485
|
-
}
|
|
8486
|
-
}
|
|
8487
|
-
return normalized;
|
|
8488
|
-
}
|
|
8489
|
-
function dataToSegments(data) {
|
|
8490
|
-
return normalizeSegments(
|
|
8491
|
-
data.map(([text, attributes]) => ({
|
|
8492
|
-
text,
|
|
8493
|
-
attributes
|
|
8494
|
-
}))
|
|
8495
|
-
);
|
|
8496
|
-
}
|
|
8497
|
-
function segmentsToData(segments) {
|
|
8498
|
-
return segments.map(
|
|
8499
|
-
(segment) => segment.attributes === void 0 ? [segment.text] : [segment.text, { ...segment.attributes }]
|
|
8500
|
-
);
|
|
8501
|
-
}
|
|
8502
|
-
function textLength(segments) {
|
|
8503
|
-
return segments.reduce((sum, segment) => sum + segment.text.length, 0);
|
|
8504
|
-
}
|
|
8505
|
-
function splitSegmentsAt(segments, index) {
|
|
8506
|
-
const result = [];
|
|
8507
|
-
let offset = 0;
|
|
8508
|
-
for (const segment of segments) {
|
|
8509
|
-
const end = offset + segment.text.length;
|
|
8510
|
-
if (index > offset && index < end) {
|
|
8511
|
-
const before2 = segment.text.slice(0, index - offset);
|
|
8512
|
-
const after2 = segment.text.slice(index - offset);
|
|
8513
|
-
result.push({ text: before2, attributes: segment.attributes });
|
|
8514
|
-
result.push({ text: after2, attributes: segment.attributes });
|
|
8515
|
-
} else {
|
|
8516
|
-
result.push({ text: segment.text, attributes: segment.attributes });
|
|
8517
|
-
}
|
|
8518
|
-
offset = end;
|
|
8519
|
-
}
|
|
8520
|
-
return result;
|
|
8521
|
-
}
|
|
8522
|
-
function clipRange(index, length, contentLength) {
|
|
8523
|
-
const clippedIndex = Math.max(0, Math.min(index, contentLength));
|
|
8524
|
-
const clippedEnd = Math.max(
|
|
8525
|
-
clippedIndex,
|
|
8526
|
-
Math.min(index + length, contentLength)
|
|
8527
|
-
);
|
|
8528
|
-
return { index: clippedIndex, length: clippedEnd - clippedIndex };
|
|
8529
|
-
}
|
|
8530
|
-
function applyInsert(segments, index, text, attributes) {
|
|
8531
|
-
if (text.length === 0) {
|
|
8532
|
-
return normalizeSegments(segments);
|
|
8533
|
-
}
|
|
8534
|
-
const split = splitSegmentsAt(segments, index);
|
|
8535
|
-
const result = [];
|
|
8536
|
-
let offset = 0;
|
|
8537
|
-
let inserted = false;
|
|
8538
|
-
for (const segment of split) {
|
|
8539
|
-
if (!inserted && offset === index) {
|
|
8540
|
-
result.push({ text, attributes });
|
|
8541
|
-
inserted = true;
|
|
8542
|
-
}
|
|
8543
|
-
result.push(segment);
|
|
8544
|
-
offset += segment.text.length;
|
|
8545
|
-
}
|
|
8546
|
-
if (!inserted) {
|
|
8547
|
-
result.push({ text, attributes });
|
|
8548
|
-
}
|
|
8549
|
-
return normalizeSegments(result);
|
|
8550
|
-
}
|
|
8551
|
-
function extractDeletedSegments(segments, index, length) {
|
|
8552
|
-
const split = splitSegmentsAt(
|
|
8553
|
-
splitSegmentsAt(segments, index),
|
|
8554
|
-
index + length
|
|
8555
|
-
);
|
|
8556
|
-
const deleted = [];
|
|
8557
|
-
let offset = 0;
|
|
8558
|
-
for (const segment of split) {
|
|
8559
|
-
const end = offset + segment.text.length;
|
|
8560
|
-
if (offset >= index && end <= index + length) {
|
|
8561
|
-
deleted.push({
|
|
8562
|
-
text: segment.text,
|
|
8563
|
-
attributes: segment.attributes
|
|
8564
|
-
});
|
|
8565
|
-
}
|
|
8566
|
-
offset = end;
|
|
8567
|
-
}
|
|
8568
|
-
return normalizeSegments(deleted);
|
|
8569
|
-
}
|
|
8570
|
-
function applyDelete(segments, index, length) {
|
|
8571
|
-
const deletedSegments = extractDeletedSegments(segments, index, length);
|
|
8572
|
-
const split = splitSegmentsAt(
|
|
8573
|
-
splitSegmentsAt(segments, index),
|
|
8574
|
-
index + length
|
|
8575
|
-
);
|
|
8576
|
-
const result = [];
|
|
8577
|
-
let offset = 0;
|
|
8578
|
-
let deletedText = "";
|
|
8579
|
-
for (const segment of split) {
|
|
8580
|
-
const end = offset + segment.text.length;
|
|
8581
|
-
if (offset >= index && end <= index + length) {
|
|
8582
|
-
deletedText += segment.text;
|
|
8583
|
-
} else {
|
|
8584
|
-
result.push(segment);
|
|
8585
|
-
}
|
|
8586
|
-
offset = end;
|
|
8587
|
-
}
|
|
8588
|
-
return {
|
|
8589
|
-
segments: normalizeSegments(result),
|
|
8590
|
-
deletedText,
|
|
8591
|
-
deletedSegments
|
|
8592
|
-
};
|
|
8593
|
-
}
|
|
8594
|
-
function applyFormat(segments, index, length, attributes) {
|
|
8595
|
-
const split = splitSegmentsAt(
|
|
8596
|
-
splitSegmentsAt(segments, index),
|
|
8597
|
-
index + length
|
|
8598
|
-
);
|
|
8599
|
-
const result = [];
|
|
8600
|
-
let offset = 0;
|
|
8601
|
-
for (const segment of split) {
|
|
8602
|
-
const end = offset + segment.text.length;
|
|
8603
|
-
if (offset >= index && end <= index + length) {
|
|
8604
|
-
const nextAttributes = {
|
|
8605
|
-
..._nullishCoalesce(segment.attributes, () => ( {}))
|
|
8606
|
-
};
|
|
8607
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
8608
|
-
if (value === null) {
|
|
8609
|
-
delete nextAttributes[key];
|
|
8610
|
-
} else {
|
|
8611
|
-
nextAttributes[key] = value;
|
|
8612
|
-
}
|
|
8613
|
-
}
|
|
8614
|
-
result.push({
|
|
8615
|
-
text: segment.text,
|
|
8616
|
-
attributes: Object.keys(nextAttributes).length === 0 ? void 0 : freeze(nextAttributes)
|
|
8617
|
-
});
|
|
8618
|
-
} else {
|
|
8619
|
-
result.push(segment);
|
|
8620
|
-
}
|
|
8621
|
-
offset = end;
|
|
8622
|
-
}
|
|
8623
|
-
return normalizeSegments(result);
|
|
8624
|
-
}
|
|
8625
|
-
function formatReverseOperations(segments, index, length, patch) {
|
|
8626
|
-
const split = splitSegmentsAt(
|
|
8627
|
-
splitSegmentsAt(segments, index),
|
|
8628
|
-
index + length
|
|
8629
|
-
);
|
|
8630
|
-
const result = [];
|
|
8631
|
-
let offset = 0;
|
|
8632
|
-
for (const segment of split) {
|
|
8633
|
-
const end = offset + segment.text.length;
|
|
8634
|
-
if (offset >= index && end <= index + length) {
|
|
8635
|
-
const attributes = {};
|
|
8636
|
-
for (const key of Object.keys(patch)) {
|
|
8637
|
-
attributes[key] = _nullishCoalesce(_optionalChain([segment, 'access', _213 => _213.attributes, 'optionalAccess', _214 => _214[key]]), () => ( null));
|
|
8638
|
-
}
|
|
8639
|
-
result.push({
|
|
8640
|
-
type: "format",
|
|
8641
|
-
index: offset,
|
|
8642
|
-
length: segment.text.length,
|
|
8643
|
-
attributes
|
|
8644
|
-
});
|
|
8645
|
-
}
|
|
8646
|
-
offset = end;
|
|
8647
|
-
}
|
|
8648
|
-
return result;
|
|
8649
|
-
}
|
|
8650
|
-
function mapIndexThroughOperation(index, op) {
|
|
8651
|
-
if (op.type === "insert") {
|
|
8652
|
-
return op.index <= index ? index + op.text.length : index;
|
|
8653
|
-
} else if (op.type === "delete") {
|
|
8654
|
-
if (op.index >= index) {
|
|
8655
|
-
return index;
|
|
8656
|
-
}
|
|
8657
|
-
return Math.max(op.index, index - op.length);
|
|
8658
|
-
} else {
|
|
8659
|
-
return index;
|
|
8660
|
-
}
|
|
8661
|
-
}
|
|
8662
|
-
function mapTextIndexThroughOperations(index, ops) {
|
|
8663
|
-
let mapped = index;
|
|
8664
|
-
for (const op of ops) {
|
|
8665
|
-
mapped = mapIndexThroughOperation(mapped, op);
|
|
8666
|
-
}
|
|
8667
|
-
return mapped;
|
|
8668
|
-
}
|
|
8669
|
-
function rebaseTextOperations(ops, acceptedOps) {
|
|
8670
|
-
return ops.map((op) => {
|
|
8671
|
-
if (op.type === "insert") {
|
|
8672
|
-
return {
|
|
8673
|
-
...op,
|
|
8674
|
-
index: mapTextIndexThroughOperations(op.index, acceptedOps)
|
|
8675
|
-
};
|
|
8676
|
-
} else if (op.type === "delete" || op.type === "format") {
|
|
8677
|
-
const start = mapTextIndexThroughOperations(op.index, acceptedOps);
|
|
8678
|
-
const end = mapTextIndexThroughOperations(
|
|
8679
|
-
op.index + op.length,
|
|
8680
|
-
acceptedOps
|
|
8681
|
-
);
|
|
8682
|
-
return { ...op, index: start, length: Math.max(0, end - start) };
|
|
8683
|
-
} else {
|
|
8684
|
-
return op;
|
|
8685
|
-
}
|
|
8686
|
-
});
|
|
8687
|
-
}
|
|
8688
|
-
function applyTextOperationsToSegments(segments, ops) {
|
|
8689
|
-
let next = [...segments];
|
|
8690
|
-
for (const op of ops) {
|
|
8691
|
-
if (op.type === "insert") {
|
|
8692
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8693
|
-
next = applyInsert(next, index, op.text, op.attributes);
|
|
8694
|
-
} else if (op.type === "delete") {
|
|
8695
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8696
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8697
|
-
next = applyDelete(next, clipped.index, clipped.length).segments;
|
|
8698
|
-
} else {
|
|
8699
|
-
const index = Math.max(0, Math.min(op.index, textLength(next)));
|
|
8700
|
-
const clipped = clipRange(index, op.length, textLength(next));
|
|
8701
|
-
next = applyFormat(next, clipped.index, clipped.length, op.attributes);
|
|
8702
|
-
}
|
|
8703
|
-
}
|
|
8704
|
-
return next;
|
|
8705
|
-
}
|
|
8706
|
-
function applyLiveTextOperations(data, ops) {
|
|
8707
|
-
return segmentsToData(
|
|
8708
|
-
applyTextOperationsToSegments(dataToSegments(data), ops)
|
|
8709
|
-
);
|
|
8710
|
-
}
|
|
8711
|
-
function invertTextOperations(segments, ops) {
|
|
8712
|
-
let shadow = [...segments];
|
|
8713
|
-
const reverse = [];
|
|
8714
|
-
for (const op of ops) {
|
|
8715
|
-
if (op.type === "insert") {
|
|
8716
|
-
shadow = applyInsert(shadow, op.index, op.text, op.attributes);
|
|
8717
|
-
reverse.unshift({
|
|
8718
|
-
type: "delete",
|
|
8719
|
-
index: op.index,
|
|
8720
|
-
length: op.text.length
|
|
8721
|
-
});
|
|
8722
|
-
} else if (op.type === "delete") {
|
|
8723
|
-
const deletedSegments = extractDeletedSegments(
|
|
8724
|
-
shadow,
|
|
8725
|
-
op.index,
|
|
8726
|
-
op.length
|
|
8727
|
-
);
|
|
8728
|
-
shadow = applyDelete(shadow, op.index, op.length).segments;
|
|
8729
|
-
const inserts = [];
|
|
8730
|
-
let insertIndex = op.index;
|
|
8731
|
-
for (const segment of deletedSegments) {
|
|
8732
|
-
inserts.push({
|
|
8733
|
-
type: "insert",
|
|
8734
|
-
index: insertIndex,
|
|
8735
|
-
text: segment.text,
|
|
8736
|
-
attributes: segment.attributes
|
|
8737
|
-
});
|
|
8738
|
-
insertIndex += segment.text.length;
|
|
8739
|
-
}
|
|
8740
|
-
for (let index = inserts.length - 1; index >= 0; index--) {
|
|
8741
|
-
reverse.unshift(inserts[index]);
|
|
8742
|
-
}
|
|
8743
|
-
} else {
|
|
8744
|
-
const inverse = formatReverseOperations(
|
|
8745
|
-
shadow,
|
|
8746
|
-
op.index,
|
|
8747
|
-
op.length,
|
|
8748
|
-
op.attributes
|
|
8749
|
-
);
|
|
8750
|
-
shadow = applyFormat(shadow, op.index, op.length, op.attributes);
|
|
8751
|
-
reverse.unshift(...inverse.reverse());
|
|
8752
|
-
}
|
|
8753
|
-
}
|
|
8754
|
-
return reverse;
|
|
8755
|
-
}
|
|
8756
|
-
|
|
8757
|
-
// src/crdts/LiveText.ts
|
|
8758
|
-
var LiveText = class _LiveText extends AbstractCrdt {
|
|
8759
|
-
#segments;
|
|
8760
|
-
#version;
|
|
8761
|
-
#pendingOps;
|
|
8762
|
-
constructor(textOrData = "", version = 0) {
|
|
8763
|
-
super();
|
|
8764
|
-
this.#segments = typeof textOrData === "string" ? textOrData.length === 0 ? [] : [{ text: textOrData }] : dataToSegments(textOrData);
|
|
8765
|
-
this.#version = version;
|
|
8766
|
-
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8767
|
-
}
|
|
8768
|
-
get version() {
|
|
8769
|
-
return this.#version;
|
|
8770
|
-
}
|
|
8771
|
-
get length() {
|
|
8772
|
-
return this.toString().length;
|
|
8773
|
-
}
|
|
8774
|
-
/** @internal */
|
|
8775
|
-
static _deserialize([id, item], _parentToChildren, pool) {
|
|
8776
|
-
const text = new _LiveText(item.data, item.version);
|
|
8777
|
-
text._attach(id, pool);
|
|
8778
|
-
return text;
|
|
8779
|
-
}
|
|
8780
|
-
/** @internal */
|
|
8781
|
-
_toOps(parentId, parentKey) {
|
|
8782
|
-
if (this._id === void 0) {
|
|
8783
|
-
throw new Error("Cannot serialize LiveText if it is not attached");
|
|
8784
|
-
}
|
|
8785
|
-
return [
|
|
8786
|
-
{
|
|
8787
|
-
type: OpCode.CREATE_TEXT,
|
|
8788
|
-
id: this._id,
|
|
8789
|
-
parentId,
|
|
8790
|
-
parentKey,
|
|
8791
|
-
data: this.toJSON(),
|
|
8792
|
-
version: this.#version
|
|
8793
|
-
}
|
|
8794
|
-
];
|
|
8795
|
-
}
|
|
8796
|
-
/** @internal */
|
|
8797
|
-
_serialize() {
|
|
8798
|
-
if (this.parent.type !== "HasParent") {
|
|
8799
|
-
throw new Error("Cannot serialize LiveText if parent is missing");
|
|
8800
|
-
}
|
|
8801
|
-
return {
|
|
8802
|
-
type: CrdtType.TEXT,
|
|
8803
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8804
|
-
parentKey: this.parent.key,
|
|
8805
|
-
data: this.toJSON(),
|
|
8806
|
-
version: this.#version
|
|
8807
|
-
};
|
|
8808
|
-
}
|
|
8809
|
-
/** @internal */
|
|
8810
|
-
_attachChild(_op) {
|
|
8811
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8812
|
-
}
|
|
8813
|
-
/** @internal */
|
|
8814
|
-
_detachChild(_crdt) {
|
|
8815
|
-
throw new Error("LiveText cannot contain child nodes");
|
|
8816
|
-
}
|
|
8817
|
-
/** @internal */
|
|
8818
|
-
_apply(op, isLocal) {
|
|
8819
|
-
if (op.type !== OpCode.UPDATE_TEXT) {
|
|
8820
|
-
return super._apply(op, isLocal);
|
|
8821
|
-
}
|
|
8822
|
-
if (isLocal) {
|
|
8823
|
-
this.#pendingOps.set(nn(op.opId), op.ops);
|
|
8824
|
-
return this.#applyOperations(op.ops, _nullishCoalesce(op.version, () => ( this.#version)));
|
|
8825
|
-
}
|
|
8826
|
-
if (op.opId !== void 0) {
|
|
8827
|
-
const pending2 = this.#pendingOps.get(op.opId);
|
|
8828
|
-
this.#pendingOps.delete(op.opId);
|
|
8829
|
-
const otherPending = Array.from(this.#pendingOps.values()).flat();
|
|
8830
|
-
if (pending2 !== void 0 && otherPending.length > 0) {
|
|
8831
|
-
this.#segments = applyTextOperationsToSegments(
|
|
8832
|
-
this.#segments,
|
|
8833
|
-
invertTextOperations(this.#segments, pending2)
|
|
8834
|
-
);
|
|
8835
|
-
const ops2 = rebaseTextOperations(op.ops, otherPending);
|
|
8836
|
-
return this.#applyOperations(
|
|
8837
|
-
ops2,
|
|
8838
|
-
_nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)))
|
|
8839
|
-
);
|
|
8840
|
-
}
|
|
8841
|
-
this.#version = _nullishCoalesce(op.version, () => ( Math.max(this.#version, op.baseVersion + 1)));
|
|
8842
|
-
return { modified: false };
|
|
8843
|
-
}
|
|
8844
|
-
const pending = Array.from(this.#pendingOps.values()).flat();
|
|
8845
|
-
const ops = pending.length > 0 ? rebaseTextOperations(op.ops, pending) : op.ops;
|
|
8846
|
-
return this.#applyOperations(ops, _nullishCoalesce(op.version, () => ( this.#version + 1)));
|
|
8847
|
-
}
|
|
8848
|
-
insert(index, text, attributes) {
|
|
8849
|
-
const clippedIndex = Math.max(0, Math.min(index, this.length));
|
|
8850
|
-
this.#dispatch([{ type: "insert", index: clippedIndex, text, attributes }]);
|
|
8851
|
-
}
|
|
8852
|
-
delete(index, length) {
|
|
8853
|
-
const clipped = clipRange(index, length, this.length);
|
|
8854
|
-
if (clipped.length === 0) {
|
|
8855
|
-
return;
|
|
8856
|
-
}
|
|
8857
|
-
this.#dispatch([
|
|
8858
|
-
{ type: "delete", index: clipped.index, length: clipped.length }
|
|
8859
|
-
]);
|
|
8860
|
-
}
|
|
8861
|
-
replace(index, length, text, attributes) {
|
|
8862
|
-
const clipped = clipRange(index, length, this.length);
|
|
8863
|
-
const ops = [];
|
|
8864
|
-
if (clipped.length > 0) {
|
|
8865
|
-
ops.push({
|
|
8866
|
-
type: "delete",
|
|
8867
|
-
index: clipped.index,
|
|
8868
|
-
length: clipped.length
|
|
8869
|
-
});
|
|
8870
|
-
}
|
|
8871
|
-
if (text.length > 0) {
|
|
8872
|
-
ops.push({ type: "insert", index: clipped.index, text, attributes });
|
|
8873
|
-
}
|
|
8874
|
-
this.#dispatch(ops);
|
|
8875
|
-
}
|
|
8876
|
-
format(index, length, attributes) {
|
|
8877
|
-
const clipped = clipRange(index, length, this.length);
|
|
8878
|
-
if (clipped.length === 0) {
|
|
8879
|
-
return;
|
|
8880
|
-
}
|
|
8881
|
-
this.#dispatch([
|
|
8882
|
-
{
|
|
8883
|
-
type: "format",
|
|
8884
|
-
index: clipped.index,
|
|
8885
|
-
length: clipped.length,
|
|
8886
|
-
attributes
|
|
8887
|
-
}
|
|
8888
|
-
]);
|
|
8889
|
-
}
|
|
8890
|
-
#dispatch(ops) {
|
|
8891
|
-
if (ops.length === 0) {
|
|
8892
|
-
return;
|
|
8893
|
-
}
|
|
8894
|
-
_optionalChain([this, 'access', _215 => _215._pool, 'optionalAccess', _216 => _216.assertStorageIsWritable, 'call', _217 => _217()]);
|
|
8895
|
-
const baseVersion = this.#version;
|
|
8896
|
-
const reverse = this._pool !== void 0 && this._id !== void 0 ? this.#invertOperations(ops) : [];
|
|
8897
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8898
|
-
if (this._pool !== void 0 && this._id !== void 0) {
|
|
8899
|
-
const opId = this._pool.generateOpId();
|
|
8900
|
-
this.#pendingOps.set(opId, ops);
|
|
8901
|
-
this._pool.dispatch(
|
|
8902
|
-
[
|
|
8903
|
-
{
|
|
8904
|
-
type: OpCode.UPDATE_TEXT,
|
|
8905
|
-
id: this._id,
|
|
8906
|
-
opId,
|
|
8907
|
-
baseVersion,
|
|
8908
|
-
ops: [...ops]
|
|
8909
|
-
}
|
|
8910
|
-
],
|
|
8911
|
-
reverse,
|
|
8912
|
-
/* @__PURE__ */ new Map([
|
|
8913
|
-
[
|
|
8914
|
-
this._id,
|
|
8915
|
-
{
|
|
8916
|
-
type: "LiveText",
|
|
8917
|
-
node: this,
|
|
8918
|
-
version: this.#version,
|
|
8919
|
-
updates: changes
|
|
8920
|
-
}
|
|
8921
|
-
]
|
|
8922
|
-
])
|
|
8923
|
-
);
|
|
8924
|
-
}
|
|
8925
|
-
}
|
|
8926
|
-
#applyOperations(ops, version) {
|
|
8927
|
-
const reverse = this.#invertOperations(ops);
|
|
8928
|
-
const changes = this.#applyOperationsLocally(ops);
|
|
8929
|
-
this.#version = Math.max(this.#version, version);
|
|
8930
|
-
return {
|
|
8931
|
-
reverse,
|
|
8932
|
-
modified: {
|
|
8933
|
-
type: "LiveText",
|
|
8934
|
-
node: this,
|
|
8935
|
-
version: this.#version,
|
|
8936
|
-
updates: changes
|
|
8937
|
-
}
|
|
8938
|
-
};
|
|
8939
|
-
}
|
|
8940
|
-
#applyOperationsLocally(ops) {
|
|
8941
|
-
const changes = [];
|
|
8942
|
-
for (const op of ops) {
|
|
8943
|
-
if (op.type === "insert") {
|
|
8944
|
-
this.#segments = applyInsert(
|
|
8945
|
-
this.#segments,
|
|
8946
|
-
op.index,
|
|
8947
|
-
op.text,
|
|
8948
|
-
op.attributes
|
|
8949
|
-
);
|
|
8950
|
-
changes.push({
|
|
8951
|
-
type: "insert",
|
|
8952
|
-
index: op.index,
|
|
8953
|
-
text: op.text,
|
|
8954
|
-
attributes: op.attributes
|
|
8955
|
-
});
|
|
8956
|
-
} else if (op.type === "delete") {
|
|
8957
|
-
const result = applyDelete(this.#segments, op.index, op.length);
|
|
8958
|
-
this.#segments = result.segments;
|
|
8959
|
-
changes.push({
|
|
8960
|
-
type: "delete",
|
|
8961
|
-
index: op.index,
|
|
8962
|
-
length: op.length,
|
|
8963
|
-
deletedText: result.deletedText
|
|
8964
|
-
});
|
|
8965
|
-
} else {
|
|
8966
|
-
this.#segments = applyFormat(
|
|
8967
|
-
this.#segments,
|
|
8968
|
-
op.index,
|
|
8969
|
-
op.length,
|
|
8970
|
-
op.attributes
|
|
8971
|
-
);
|
|
8972
|
-
changes.push({
|
|
8973
|
-
type: "format",
|
|
8974
|
-
index: op.index,
|
|
8975
|
-
length: op.length,
|
|
8976
|
-
attributes: op.attributes
|
|
8977
|
-
});
|
|
8978
|
-
}
|
|
8979
|
-
}
|
|
8980
|
-
this.invalidate();
|
|
8981
|
-
return changes;
|
|
8982
|
-
}
|
|
8983
|
-
#invertOperations(ops) {
|
|
8984
|
-
return [
|
|
8985
|
-
{
|
|
8986
|
-
type: OpCode.UPDATE_TEXT,
|
|
8987
|
-
id: nn(this._id),
|
|
8988
|
-
baseVersion: this.#version,
|
|
8989
|
-
ops: invertTextOperations(this.#segments, ops)
|
|
8990
|
-
}
|
|
8991
|
-
];
|
|
8992
|
-
}
|
|
8993
|
-
toString() {
|
|
8994
|
-
return this.#segments.map((segment) => segment.text).join("");
|
|
8995
|
-
}
|
|
8996
|
-
toJSON() {
|
|
8997
|
-
return super.toJSON();
|
|
8998
|
-
}
|
|
8999
|
-
/** @internal */
|
|
9000
|
-
_toJSON() {
|
|
9001
|
-
return segmentsToData(this.#segments);
|
|
9002
|
-
}
|
|
9003
|
-
/** @internal */
|
|
9004
|
-
_toTreeNode(key) {
|
|
9005
|
-
return {
|
|
9006
|
-
type: "LiveText",
|
|
9007
|
-
id: _nullishCoalesce(this._id, () => ( nanoid())),
|
|
9008
|
-
key,
|
|
9009
|
-
payload: [
|
|
9010
|
-
{
|
|
9011
|
-
type: "Json",
|
|
9012
|
-
id: `${_nullishCoalesce(this._id, () => ( nanoid()))}:text`,
|
|
9013
|
-
key: "text",
|
|
9014
|
-
payload: this.toString()
|
|
9015
|
-
}
|
|
9016
|
-
]
|
|
9017
|
-
};
|
|
9018
|
-
}
|
|
9019
|
-
clone() {
|
|
9020
|
-
return new _LiveText(this.toJSON(), this.#version);
|
|
9021
|
-
}
|
|
9022
|
-
};
|
|
9023
|
-
|
|
9024
8455
|
// src/crdts/liveblocks-helpers.ts
|
|
9025
8456
|
function creationOpToLiveNode(op) {
|
|
9026
8457
|
return lsonToLiveNode(creationOpToLson(op));
|
|
@@ -9035,8 +8466,6 @@ function creationOpToLson(op) {
|
|
|
9035
8466
|
return new LiveMap();
|
|
9036
8467
|
case OpCode.CREATE_LIST:
|
|
9037
8468
|
return new LiveList([]);
|
|
9038
|
-
case OpCode.CREATE_TEXT:
|
|
9039
|
-
return new LiveText(op.data, op.version);
|
|
9040
8469
|
default:
|
|
9041
8470
|
return assertNever(op, "Unknown creation Op");
|
|
9042
8471
|
}
|
|
@@ -9059,8 +8488,6 @@ function deserialize(node, parentToChildren, pool) {
|
|
|
9059
8488
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9060
8489
|
} else if (isRegisterStorageNode(node)) {
|
|
9061
8490
|
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
9062
|
-
} else if (isTextStorageNode(node)) {
|
|
9063
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9064
8491
|
} else {
|
|
9065
8492
|
throw new Error("Unexpected CRDT type");
|
|
9066
8493
|
}
|
|
@@ -9074,14 +8501,12 @@ function deserializeToLson(node, parentToChildren, pool) {
|
|
|
9074
8501
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9075
8502
|
} else if (isRegisterStorageNode(node)) {
|
|
9076
8503
|
return node[1].data;
|
|
9077
|
-
} else if (isTextStorageNode(node)) {
|
|
9078
|
-
return LiveText._deserialize(node, parentToChildren, pool);
|
|
9079
8504
|
} else {
|
|
9080
8505
|
throw new Error("Unexpected CRDT type");
|
|
9081
8506
|
}
|
|
9082
8507
|
}
|
|
9083
8508
|
function isLiveStructure(value) {
|
|
9084
|
-
return isLiveList(value) || isLiveMap(value) || isLiveObject(value)
|
|
8509
|
+
return isLiveList(value) || isLiveMap(value) || isLiveObject(value);
|
|
9085
8510
|
}
|
|
9086
8511
|
function isLiveNode(value) {
|
|
9087
8512
|
return isLiveStructure(value) || isLiveRegister(value);
|
|
@@ -9095,9 +8520,6 @@ function isLiveMap(value) {
|
|
|
9095
8520
|
function isLiveObject(value) {
|
|
9096
8521
|
return value instanceof LiveObject;
|
|
9097
8522
|
}
|
|
9098
|
-
function isLiveText(value) {
|
|
9099
|
-
return value instanceof LiveText;
|
|
9100
|
-
}
|
|
9101
8523
|
function isLiveRegister(value) {
|
|
9102
8524
|
return value instanceof LiveRegister;
|
|
9103
8525
|
}
|
|
@@ -9107,73 +8529,19 @@ function cloneLson(value) {
|
|
|
9107
8529
|
function liveNodeToLson(obj) {
|
|
9108
8530
|
if (obj instanceof LiveRegister) {
|
|
9109
8531
|
return obj.data;
|
|
9110
|
-
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject
|
|
8532
|
+
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject) {
|
|
9111
8533
|
return obj;
|
|
9112
8534
|
} else {
|
|
9113
8535
|
return assertNever(obj, "Unknown AbstractCrdt");
|
|
9114
8536
|
}
|
|
9115
8537
|
}
|
|
9116
8538
|
function lsonToLiveNode(value) {
|
|
9117
|
-
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList
|
|
8539
|
+
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList) {
|
|
9118
8540
|
return value;
|
|
9119
8541
|
} else {
|
|
9120
8542
|
return new LiveRegister(value);
|
|
9121
8543
|
}
|
|
9122
8544
|
}
|
|
9123
|
-
function dumpPool(pool) {
|
|
9124
|
-
const rows = Array.from(pool.nodes.values(), (node) => {
|
|
9125
|
-
const parent = node.parent;
|
|
9126
|
-
const parentId = parent.type === "HasParent" ? _nullishCoalesce(parent.node._id, () => ( "?")) : parent.type === "Orphaned" ? "<orphaned>" : "-";
|
|
9127
|
-
let value;
|
|
9128
|
-
if (node instanceof LiveRegister) {
|
|
9129
|
-
value = stringifyOrLog(node.data);
|
|
9130
|
-
} else if (node instanceof LiveList) {
|
|
9131
|
-
value = "<LiveList>";
|
|
9132
|
-
} else if (node instanceof LiveMap) {
|
|
9133
|
-
value = "<LiveMap>";
|
|
9134
|
-
} else {
|
|
9135
|
-
value = "<LiveObject>";
|
|
9136
|
-
}
|
|
9137
|
-
return { id: nn(node._id), parentId, key: _nullishCoalesce(node._parentKey, () => ( "")), value };
|
|
9138
|
-
});
|
|
9139
|
-
rows.sort((a, b) => {
|
|
9140
|
-
if (a.parentId !== b.parentId) return a.parentId < b.parentId ? -1 : 1;
|
|
9141
|
-
if (a.key !== b.key) return a.key < b.key ? -1 : 1;
|
|
9142
|
-
return 0;
|
|
9143
|
-
});
|
|
9144
|
-
return rows.map(
|
|
9145
|
-
(r) => ` ${r.id} parent=${r.parentId} key=${r.key || "\u2014"} ${r.value}`
|
|
9146
|
-
).join("\n");
|
|
9147
|
-
}
|
|
9148
|
-
function isJsonEq(a, b) {
|
|
9149
|
-
if (a === b) {
|
|
9150
|
-
return true;
|
|
9151
|
-
}
|
|
9152
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
9153
|
-
return false;
|
|
9154
|
-
}
|
|
9155
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
9156
|
-
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
9157
|
-
return false;
|
|
9158
|
-
}
|
|
9159
|
-
for (let i = 0; i < a.length; i++) {
|
|
9160
|
-
if (!isJsonEq(a[i], b[i])) {
|
|
9161
|
-
return false;
|
|
9162
|
-
}
|
|
9163
|
-
}
|
|
9164
|
-
return true;
|
|
9165
|
-
}
|
|
9166
|
-
const aKeys = Object.keys(a);
|
|
9167
|
-
if (aKeys.length !== Object.keys(b).length) {
|
|
9168
|
-
return false;
|
|
9169
|
-
}
|
|
9170
|
-
for (const key of aKeys) {
|
|
9171
|
-
if (!isJsonEq(a[key], b[key])) {
|
|
9172
|
-
return false;
|
|
9173
|
-
}
|
|
9174
|
-
}
|
|
9175
|
-
return true;
|
|
9176
|
-
}
|
|
9177
8545
|
function getTreesDiffOperations(currentItems, newItems) {
|
|
9178
8546
|
const ops = [];
|
|
9179
8547
|
currentItems.forEach((_, id) => {
|
|
@@ -9185,61 +8553,11 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9185
8553
|
const currentCrdt = currentItems.get(id);
|
|
9186
8554
|
if (currentCrdt) {
|
|
9187
8555
|
if (crdt.type === CrdtType.OBJECT) {
|
|
9188
|
-
if (currentCrdt.type !== CrdtType.OBJECT) {
|
|
9189
|
-
ops.push({ type: OpCode.UPDATE_OBJECT, id, data: crdt.data });
|
|
9190
|
-
} else {
|
|
9191
|
-
const changed = /* @__PURE__ */ new Map();
|
|
9192
|
-
for (const key of Object.keys(crdt.data)) {
|
|
9193
|
-
const value = crdt.data[key];
|
|
9194
|
-
if (value !== void 0 && !isJsonEq(value, currentCrdt.data[key])) {
|
|
9195
|
-
changed.set(key, value);
|
|
9196
|
-
}
|
|
9197
|
-
}
|
|
9198
|
-
if (changed.size > 0) {
|
|
9199
|
-
ops.push({
|
|
9200
|
-
type: OpCode.UPDATE_OBJECT,
|
|
9201
|
-
id,
|
|
9202
|
-
data: Object.fromEntries(changed)
|
|
9203
|
-
});
|
|
9204
|
-
}
|
|
9205
|
-
for (const key of Object.keys(currentCrdt.data)) {
|
|
9206
|
-
if (!(key in crdt.data)) {
|
|
9207
|
-
ops.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
9208
|
-
}
|
|
9209
|
-
}
|
|
9210
|
-
}
|
|
9211
|
-
}
|
|
9212
|
-
if (crdt.type === CrdtType.TEXT) {
|
|
9213
|
-
if (currentCrdt.type !== CrdtType.TEXT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data) || crdt.version !== currentCrdt.version) {
|
|
8556
|
+
if (currentCrdt.type !== CrdtType.OBJECT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data)) {
|
|
9214
8557
|
ops.push({
|
|
9215
|
-
type: OpCode.
|
|
8558
|
+
type: OpCode.UPDATE_OBJECT,
|
|
9216
8559
|
id,
|
|
9217
|
-
|
|
9218
|
-
version: crdt.version,
|
|
9219
|
-
ops: [
|
|
9220
|
-
{
|
|
9221
|
-
type: "delete",
|
|
9222
|
-
index: 0,
|
|
9223
|
-
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9224
|
-
(sum, segment) => sum + segment[0].length,
|
|
9225
|
-
0
|
|
9226
|
-
) : 0
|
|
9227
|
-
},
|
|
9228
|
-
...crdt.data.map((segment, index, items) => {
|
|
9229
|
-
const [text, attributes] = segment;
|
|
9230
|
-
const insertIndex = items.slice(0, index).reduce((sum, item) => sum + item[0].length, 0);
|
|
9231
|
-
return attributes === void 0 ? {
|
|
9232
|
-
type: "insert",
|
|
9233
|
-
index: insertIndex,
|
|
9234
|
-
text
|
|
9235
|
-
} : {
|
|
9236
|
-
type: "insert",
|
|
9237
|
-
index: insertIndex,
|
|
9238
|
-
text,
|
|
9239
|
-
attributes
|
|
9240
|
-
};
|
|
9241
|
-
})
|
|
9242
|
-
]
|
|
8560
|
+
data: crdt.data
|
|
9243
8561
|
});
|
|
9244
8562
|
}
|
|
9245
8563
|
}
|
|
@@ -9291,16 +8609,6 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9291
8609
|
parentKey: crdt.parentKey
|
|
9292
8610
|
});
|
|
9293
8611
|
break;
|
|
9294
|
-
case CrdtType.TEXT:
|
|
9295
|
-
ops.push({
|
|
9296
|
-
type: OpCode.CREATE_TEXT,
|
|
9297
|
-
id,
|
|
9298
|
-
parentId: crdt.parentId,
|
|
9299
|
-
parentKey: crdt.parentKey,
|
|
9300
|
-
data: crdt.data,
|
|
9301
|
-
version: crdt.version
|
|
9302
|
-
});
|
|
9303
|
-
break;
|
|
9304
8612
|
}
|
|
9305
8613
|
}
|
|
9306
8614
|
});
|
|
@@ -9333,12 +8641,6 @@ function mergeListStorageUpdates(first, second) {
|
|
|
9333
8641
|
updates: updates.concat(second.updates)
|
|
9334
8642
|
};
|
|
9335
8643
|
}
|
|
9336
|
-
function mergeTextStorageUpdates(first, second) {
|
|
9337
|
-
return {
|
|
9338
|
-
...second,
|
|
9339
|
-
updates: first.updates.concat(second.updates)
|
|
9340
|
-
};
|
|
9341
|
-
}
|
|
9342
8644
|
function mergeStorageUpdates(first, second) {
|
|
9343
8645
|
if (first === void 0) {
|
|
9344
8646
|
return second;
|
|
@@ -9349,8 +8651,6 @@ function mergeStorageUpdates(first, second) {
|
|
|
9349
8651
|
return mergeMapStorageUpdates(first, second);
|
|
9350
8652
|
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
9351
8653
|
return mergeListStorageUpdates(first, second);
|
|
9352
|
-
} else if (first.type === "LiveText" && second.type === "LiveText") {
|
|
9353
|
-
return mergeTextStorageUpdates(first, second);
|
|
9354
8654
|
} else {
|
|
9355
8655
|
}
|
|
9356
8656
|
return second;
|
|
@@ -9369,7 +8669,7 @@ function sendToPanel(message, options) {
|
|
|
9369
8669
|
...message,
|
|
9370
8670
|
source: "liveblocks-devtools-client"
|
|
9371
8671
|
};
|
|
9372
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
8672
|
+
if (!(_optionalChain([options, 'optionalAccess', _202 => _202.force]) || _bridgeActive)) {
|
|
9373
8673
|
return;
|
|
9374
8674
|
}
|
|
9375
8675
|
window.postMessage(fullMsg, "*");
|
|
@@ -9377,7 +8677,7 @@ function sendToPanel(message, options) {
|
|
|
9377
8677
|
var eventSource = makeEventSource();
|
|
9378
8678
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
9379
8679
|
window.addEventListener("message", (event) => {
|
|
9380
|
-
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") {
|
|
9381
8681
|
eventSource.notify(event.data);
|
|
9382
8682
|
} else {
|
|
9383
8683
|
}
|
|
@@ -9519,7 +8819,7 @@ function fullSync(room) {
|
|
|
9519
8819
|
msg: "room::sync::full",
|
|
9520
8820
|
roomId: room.id,
|
|
9521
8821
|
status: room.getStatus(),
|
|
9522
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
8822
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _205 => _205.toTreeNode, 'call', _206 => _206("root"), 'access', _207 => _207.payload]), () => ( null)),
|
|
9523
8823
|
me,
|
|
9524
8824
|
others
|
|
9525
8825
|
});
|
|
@@ -9937,14 +9237,14 @@ var ClientMsgCode = Object.freeze({
|
|
|
9937
9237
|
// src/refs/ManagedOthers.ts
|
|
9938
9238
|
function makeUser(conn, presence) {
|
|
9939
9239
|
const { connectionId, id, info } = conn;
|
|
9940
|
-
const canWrite =
|
|
9240
|
+
const canWrite = hasPermissionCapability(conn.scopes, "storage", "write");
|
|
9941
9241
|
return freeze(
|
|
9942
9242
|
compactObject({
|
|
9943
9243
|
connectionId,
|
|
9944
9244
|
id,
|
|
9945
9245
|
info,
|
|
9946
9246
|
canWrite,
|
|
9947
|
-
canComment:
|
|
9247
|
+
canComment: hasPermissionCapability(conn.scopes, "comments", "write"),
|
|
9948
9248
|
isReadOnly: !canWrite,
|
|
9949
9249
|
// Deprecated, kept for backward-compatibility
|
|
9950
9250
|
presence
|
|
@@ -10198,15 +9498,15 @@ function installBackgroundTabSpy() {
|
|
|
10198
9498
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
10199
9499
|
const inBackgroundSince = { current: null };
|
|
10200
9500
|
function onVisibilityChange() {
|
|
10201
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
9501
|
+
if (_optionalChain([doc, 'optionalAccess', _208 => _208.visibilityState]) === "hidden") {
|
|
10202
9502
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
10203
9503
|
} else {
|
|
10204
9504
|
inBackgroundSince.current = null;
|
|
10205
9505
|
}
|
|
10206
9506
|
}
|
|
10207
|
-
_optionalChain([doc, 'optionalAccess',
|
|
9507
|
+
_optionalChain([doc, 'optionalAccess', _209 => _209.addEventListener, 'call', _210 => _210("visibilitychange", onVisibilityChange)]);
|
|
10208
9508
|
const unsub = () => {
|
|
10209
|
-
_optionalChain([doc, 'optionalAccess',
|
|
9509
|
+
_optionalChain([doc, 'optionalAccess', _211 => _211.removeEventListener, 'call', _212 => _212("visibilitychange", onVisibilityChange)]);
|
|
10210
9510
|
};
|
|
10211
9511
|
return [inBackgroundSince, unsub];
|
|
10212
9512
|
}
|
|
@@ -10251,7 +9551,6 @@ function createRoom(options, config) {
|
|
|
10251
9551
|
delegates,
|
|
10252
9552
|
config.enableDebugLogging
|
|
10253
9553
|
);
|
|
10254
|
-
const unacknowledgedOps = new UnacknowledgedOps();
|
|
10255
9554
|
const context = {
|
|
10256
9555
|
buffer: {
|
|
10257
9556
|
flushTimerID: void 0,
|
|
@@ -10279,15 +9578,14 @@ function createRoom(options, config) {
|
|
|
10279
9578
|
pool: createManagedPool(roomId, {
|
|
10280
9579
|
getCurrentConnectionId,
|
|
10281
9580
|
onDispatch,
|
|
10282
|
-
isStorageWritable
|
|
10283
|
-
unacknowledgedOps
|
|
9581
|
+
isStorageWritable
|
|
10284
9582
|
}),
|
|
10285
9583
|
root: void 0,
|
|
10286
9584
|
undoStack: [],
|
|
10287
9585
|
redoStack: [],
|
|
10288
9586
|
pausedHistory: null,
|
|
10289
9587
|
activeBatch: null,
|
|
10290
|
-
unacknowledgedOps
|
|
9588
|
+
unacknowledgedOps: /* @__PURE__ */ new Map()
|
|
10291
9589
|
};
|
|
10292
9590
|
const nodeMapBuffer = makeNodeMapBuffer();
|
|
10293
9591
|
const stopwatch = config.enableDebugLogging ? makeStopWatch() : void 0;
|
|
@@ -10399,8 +9697,8 @@ function createRoom(options, config) {
|
|
|
10399
9697
|
}
|
|
10400
9698
|
}
|
|
10401
9699
|
function isStorageWritable() {
|
|
10402
|
-
const scopes = _optionalChain([context, 'access',
|
|
10403
|
-
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;
|
|
10404
9702
|
}
|
|
10405
9703
|
const eventHub = {
|
|
10406
9704
|
status: makeEventSource(),
|
|
@@ -10461,14 +9759,22 @@ function createRoom(options, config) {
|
|
|
10461
9759
|
if (staticSession === null || dynamicSession === null) {
|
|
10462
9760
|
return null;
|
|
10463
9761
|
} else {
|
|
10464
|
-
const canWrite =
|
|
9762
|
+
const canWrite = hasPermissionCapability(
|
|
9763
|
+
dynamicSession.scopes,
|
|
9764
|
+
"storage",
|
|
9765
|
+
"write"
|
|
9766
|
+
);
|
|
10465
9767
|
return {
|
|
10466
9768
|
connectionId: dynamicSession.actor,
|
|
10467
9769
|
id: staticSession.userId,
|
|
10468
9770
|
info: staticSession.userInfo,
|
|
10469
9771
|
presence: myPresence,
|
|
10470
9772
|
canWrite,
|
|
10471
|
-
canComment:
|
|
9773
|
+
canComment: hasPermissionCapability(
|
|
9774
|
+
dynamicSession.scopes,
|
|
9775
|
+
"comments",
|
|
9776
|
+
"write"
|
|
9777
|
+
)
|
|
10472
9778
|
};
|
|
10473
9779
|
}
|
|
10474
9780
|
}
|
|
@@ -10495,11 +9801,7 @@ function createRoom(options, config) {
|
|
|
10495
9801
|
currentItems.set(id, crdt._serialize());
|
|
10496
9802
|
}
|
|
10497
9803
|
const ops = getTreesDiffOperations(currentItems, nodes);
|
|
10498
|
-
const result = applyRemoteOps(
|
|
10499
|
-
ops,
|
|
10500
|
-
/* fromSnapshot */
|
|
10501
|
-
true
|
|
10502
|
-
);
|
|
9804
|
+
const result = applyRemoteOps(ops);
|
|
10503
9805
|
notify(result.updates);
|
|
10504
9806
|
} else {
|
|
10505
9807
|
context.root = LiveObject._fromItems(
|
|
@@ -10507,7 +9809,7 @@ function createRoom(options, config) {
|
|
|
10507
9809
|
context.pool
|
|
10508
9810
|
);
|
|
10509
9811
|
}
|
|
10510
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
9812
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _217 => _217.get, 'call', _218 => _218(), 'optionalAccess', _219 => _219.canWrite]), () => ( true));
|
|
10511
9813
|
const root = context.root;
|
|
10512
9814
|
disableHistory(() => {
|
|
10513
9815
|
for (const key in context.initialStorage) {
|
|
@@ -10581,16 +9883,15 @@ function createRoom(options, config) {
|
|
|
10581
9883
|
);
|
|
10582
9884
|
return { opsToEmit: opsWithOpIds, reverse, updates };
|
|
10583
9885
|
}
|
|
10584
|
-
function applyRemoteOps(ops
|
|
9886
|
+
function applyRemoteOps(ops) {
|
|
10585
9887
|
return applyOps(
|
|
10586
9888
|
[],
|
|
10587
9889
|
ops,
|
|
10588
9890
|
/* isLocal */
|
|
10589
|
-
false
|
|
10590
|
-
fromSnapshot
|
|
9891
|
+
false
|
|
10591
9892
|
);
|
|
10592
9893
|
}
|
|
10593
|
-
function applyOps(pframes, ops, isLocal
|
|
9894
|
+
function applyOps(pframes, ops, isLocal) {
|
|
10594
9895
|
const output = {
|
|
10595
9896
|
reverse: new Deque(),
|
|
10596
9897
|
storageUpdates: /* @__PURE__ */ new Map(),
|
|
@@ -10626,7 +9927,7 @@ function createRoom(options, config) {
|
|
|
10626
9927
|
} else {
|
|
10627
9928
|
source = 1 /* THEIRS */;
|
|
10628
9929
|
}
|
|
10629
|
-
const applyOpResult = applyOp(op, source
|
|
9930
|
+
const applyOpResult = applyOp(op, source);
|
|
10630
9931
|
if (applyOpResult.modified) {
|
|
10631
9932
|
const nodeId = applyOpResult.modified.node._id;
|
|
10632
9933
|
if (!(nodeId && createdNodeIds.has(nodeId))) {
|
|
@@ -10639,7 +9940,7 @@ function createRoom(options, config) {
|
|
|
10639
9940
|
);
|
|
10640
9941
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
10641
9942
|
}
|
|
10642
|
-
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT
|
|
9943
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
10643
9944
|
createdNodeIds.add(op.id);
|
|
10644
9945
|
}
|
|
10645
9946
|
}
|
|
@@ -10652,14 +9953,13 @@ function createRoom(options, config) {
|
|
|
10652
9953
|
}
|
|
10653
9954
|
};
|
|
10654
9955
|
}
|
|
10655
|
-
function applyOp(op, source
|
|
9956
|
+
function applyOp(op, source) {
|
|
10656
9957
|
if (isIgnoredOp(op)) {
|
|
10657
9958
|
return { modified: false };
|
|
10658
9959
|
}
|
|
10659
9960
|
switch (op.type) {
|
|
10660
9961
|
case OpCode.DELETE_OBJECT_KEY:
|
|
10661
9962
|
case OpCode.UPDATE_OBJECT:
|
|
10662
|
-
case OpCode.UPDATE_TEXT:
|
|
10663
9963
|
case OpCode.DELETE_CRDT: {
|
|
10664
9964
|
const node = context.pool.nodes.get(op.id);
|
|
10665
9965
|
if (node === void 0) {
|
|
@@ -10684,7 +9984,6 @@ function createRoom(options, config) {
|
|
|
10684
9984
|
case OpCode.CREATE_OBJECT:
|
|
10685
9985
|
case OpCode.CREATE_LIST:
|
|
10686
9986
|
case OpCode.CREATE_MAP:
|
|
10687
|
-
case OpCode.CREATE_TEXT:
|
|
10688
9987
|
case OpCode.CREATE_REGISTER: {
|
|
10689
9988
|
if (op.parentId === void 0) {
|
|
10690
9989
|
return { modified: false };
|
|
@@ -10693,7 +9992,7 @@ function createRoom(options, config) {
|
|
|
10693
9992
|
if (parentNode === void 0) {
|
|
10694
9993
|
return { modified: false };
|
|
10695
9994
|
}
|
|
10696
|
-
return parentNode._attachChild(op, source
|
|
9995
|
+
return parentNode._attachChild(op, source);
|
|
10697
9996
|
}
|
|
10698
9997
|
}
|
|
10699
9998
|
}
|
|
@@ -10715,7 +10014,7 @@ function createRoom(options, config) {
|
|
|
10715
10014
|
}
|
|
10716
10015
|
context.myPresence.patch(patch);
|
|
10717
10016
|
if (context.activeBatch) {
|
|
10718
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10017
|
+
if (_optionalChain([options2, 'optionalAccess', _220 => _220.addToHistory])) {
|
|
10719
10018
|
context.activeBatch.reverseOps.pushLeft({
|
|
10720
10019
|
type: "presence",
|
|
10721
10020
|
data: oldValues
|
|
@@ -10724,7 +10023,7 @@ function createRoom(options, config) {
|
|
|
10724
10023
|
context.activeBatch.updates.presence = true;
|
|
10725
10024
|
} else {
|
|
10726
10025
|
flushNowOrSoon();
|
|
10727
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
10026
|
+
if (_optionalChain([options2, 'optionalAccess', _221 => _221.addToHistory])) {
|
|
10728
10027
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
10729
10028
|
}
|
|
10730
10029
|
notify({ presence: true });
|
|
@@ -10833,11 +10132,12 @@ function createRoom(options, config) {
|
|
|
10833
10132
|
}
|
|
10834
10133
|
}
|
|
10835
10134
|
function applyAndSendOfflineOps(unackedOps) {
|
|
10836
|
-
if (unackedOps.
|
|
10135
|
+
if (unackedOps.size === 0) {
|
|
10837
10136
|
return;
|
|
10838
10137
|
}
|
|
10839
10138
|
const messages = [];
|
|
10840
|
-
const
|
|
10139
|
+
const inOps = Array.from(unackedOps.values());
|
|
10140
|
+
const result = applyLocalOps(inOps);
|
|
10841
10141
|
messages.push({
|
|
10842
10142
|
type: ClientMsgCode.UPDATE_STORAGE,
|
|
10843
10143
|
ops: result.opsToEmit
|
|
@@ -10901,11 +10201,11 @@ function createRoom(options, config) {
|
|
|
10901
10201
|
break;
|
|
10902
10202
|
}
|
|
10903
10203
|
case ServerMsgCode.STORAGE_CHUNK:
|
|
10904
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
10204
|
+
_optionalChain([stopwatch, 'optionalAccess', _222 => _222.lap, 'call', _223 => _223()]);
|
|
10905
10205
|
nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
|
|
10906
10206
|
break;
|
|
10907
10207
|
case ServerMsgCode.STORAGE_STREAM_END: {
|
|
10908
|
-
const timing = _optionalChain([stopwatch, 'optionalAccess',
|
|
10208
|
+
const timing = _optionalChain([stopwatch, 'optionalAccess', _224 => _224.stop, 'call', _225 => _225()]);
|
|
10909
10209
|
if (timing) {
|
|
10910
10210
|
const ms = (v) => `${v.toFixed(1)}ms`;
|
|
10911
10211
|
const rest = timing.laps.slice(1);
|
|
@@ -11040,11 +10340,11 @@ function createRoom(options, config) {
|
|
|
11040
10340
|
} else if (pendingFeedsRequests.has(requestId)) {
|
|
11041
10341
|
const pending = pendingFeedsRequests.get(requestId);
|
|
11042
10342
|
pendingFeedsRequests.delete(requestId);
|
|
11043
|
-
_optionalChain([pending, 'optionalAccess',
|
|
10343
|
+
_optionalChain([pending, 'optionalAccess', _226 => _226.reject, 'call', _227 => _227(err)]);
|
|
11044
10344
|
} else if (pendingFeedMessagesRequests.has(requestId)) {
|
|
11045
10345
|
const pending = pendingFeedMessagesRequests.get(requestId);
|
|
11046
10346
|
pendingFeedMessagesRequests.delete(requestId);
|
|
11047
|
-
_optionalChain([pending, 'optionalAccess',
|
|
10347
|
+
_optionalChain([pending, 'optionalAccess', _228 => _228.reject, 'call', _229 => _229(err)]);
|
|
11048
10348
|
}
|
|
11049
10349
|
eventHub.feeds.notify(message);
|
|
11050
10350
|
break;
|
|
@@ -11061,7 +10361,7 @@ function createRoom(options, config) {
|
|
|
11061
10361
|
const storageOps = context.buffer.storageOperations;
|
|
11062
10362
|
if (storageOps.length > 0) {
|
|
11063
10363
|
for (const op of storageOps) {
|
|
11064
|
-
context.unacknowledgedOps.
|
|
10364
|
+
context.unacknowledgedOps.set(op.opId, op);
|
|
11065
10365
|
}
|
|
11066
10366
|
notifyStorageStatus();
|
|
11067
10367
|
}
|
|
@@ -11198,10 +10498,10 @@ function createRoom(options, config) {
|
|
|
11198
10498
|
timeoutId,
|
|
11199
10499
|
kind,
|
|
11200
10500
|
feedId,
|
|
11201
|
-
messageId: _optionalChain([options2, 'optionalAccess',
|
|
11202
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
10501
|
+
messageId: _optionalChain([options2, 'optionalAccess', _230 => _230.messageId]),
|
|
10502
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _231 => _231.expectedClientMessageId])
|
|
11203
10503
|
});
|
|
11204
|
-
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess',
|
|
10504
|
+
if (kind === "add-message" && _optionalChain([options2, 'optionalAccess', _232 => _232.expectedClientMessageId]) === void 0) {
|
|
11205
10505
|
const q = _nullishCoalesce(pendingAddMessageFifoByFeed.get(feedId), () => ( []));
|
|
11206
10506
|
q.push(requestId);
|
|
11207
10507
|
pendingAddMessageFifoByFeed.set(feedId, q);
|
|
@@ -11252,10 +10552,10 @@ function createRoom(options, config) {
|
|
|
11252
10552
|
}
|
|
11253
10553
|
if (!matched) {
|
|
11254
10554
|
const q = pendingAddMessageFifoByFeed.get(message.feedId);
|
|
11255
|
-
const headId = _optionalChain([q, 'optionalAccess',
|
|
10555
|
+
const headId = _optionalChain([q, 'optionalAccess', _233 => _233[0]]);
|
|
11256
10556
|
if (headId !== void 0) {
|
|
11257
10557
|
const pending = pendingFeedMutations.get(headId);
|
|
11258
|
-
if (_optionalChain([pending, 'optionalAccess',
|
|
10558
|
+
if (_optionalChain([pending, 'optionalAccess', _234 => _234.kind]) === "add-message" && pending.expectedClientMessageId === void 0) {
|
|
11259
10559
|
settleFeedMutation(headId, "ok");
|
|
11260
10560
|
}
|
|
11261
10561
|
}
|
|
@@ -11288,10 +10588,10 @@ function createRoom(options, config) {
|
|
|
11288
10588
|
}
|
|
11289
10589
|
}
|
|
11290
10590
|
function processInitialStorage(nodes) {
|
|
11291
|
-
const
|
|
10591
|
+
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
11292
10592
|
createOrUpdateRootFromMessage(nodes);
|
|
11293
|
-
applyAndSendOfflineOps(
|
|
11294
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
10593
|
+
applyAndSendOfflineOps(unacknowledgedOps);
|
|
10594
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _235 => _235()]);
|
|
11295
10595
|
notifyStorageStatus();
|
|
11296
10596
|
eventHub.storageDidLoad.notify();
|
|
11297
10597
|
}
|
|
@@ -11309,7 +10609,7 @@ function createRoom(options, config) {
|
|
|
11309
10609
|
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
11310
10610
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
11311
10611
|
nodeMapBuffer.take();
|
|
11312
|
-
_optionalChain([stopwatch, 'optionalAccess',
|
|
10612
|
+
_optionalChain([stopwatch, 'optionalAccess', _236 => _236.start, 'call', _237 => _237()]);
|
|
11313
10613
|
}
|
|
11314
10614
|
if (options2.flush) {
|
|
11315
10615
|
flushNowOrSoon();
|
|
@@ -11365,10 +10665,10 @@ function createRoom(options, config) {
|
|
|
11365
10665
|
const message = {
|
|
11366
10666
|
type: ClientMsgCode.FETCH_FEEDS,
|
|
11367
10667
|
requestId,
|
|
11368
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
11369
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
11370
|
-
limit: _optionalChain([options2, 'optionalAccess',
|
|
11371
|
-
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])
|
|
11372
10672
|
};
|
|
11373
10673
|
context.buffer.messages.push(message);
|
|
11374
10674
|
flushNowOrSoon();
|
|
@@ -11388,9 +10688,9 @@ function createRoom(options, config) {
|
|
|
11388
10688
|
type: ClientMsgCode.FETCH_FEED_MESSAGES,
|
|
11389
10689
|
requestId,
|
|
11390
10690
|
feedId,
|
|
11391
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
11392
|
-
since: _optionalChain([options2, 'optionalAccess',
|
|
11393
|
-
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])
|
|
11394
10694
|
};
|
|
11395
10695
|
context.buffer.messages.push(message);
|
|
11396
10696
|
flushNowOrSoon();
|
|
@@ -11409,8 +10709,8 @@ function createRoom(options, config) {
|
|
|
11409
10709
|
type: ClientMsgCode.ADD_FEED,
|
|
11410
10710
|
requestId,
|
|
11411
10711
|
feedId,
|
|
11412
|
-
metadata: _optionalChain([options2, 'optionalAccess',
|
|
11413
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
10712
|
+
metadata: _optionalChain([options2, 'optionalAccess', _245 => _245.metadata]),
|
|
10713
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _246 => _246.createdAt])
|
|
11414
10714
|
};
|
|
11415
10715
|
context.buffer.messages.push(message);
|
|
11416
10716
|
flushNowOrSoon();
|
|
@@ -11444,15 +10744,15 @@ function createRoom(options, config) {
|
|
|
11444
10744
|
function addFeedMessage(feedId, data, options2) {
|
|
11445
10745
|
const requestId = nanoid();
|
|
11446
10746
|
const promise = registerFeedMutation(requestId, "add-message", feedId, {
|
|
11447
|
-
expectedClientMessageId: _optionalChain([options2, 'optionalAccess',
|
|
10747
|
+
expectedClientMessageId: _optionalChain([options2, 'optionalAccess', _247 => _247.id])
|
|
11448
10748
|
});
|
|
11449
10749
|
const message = {
|
|
11450
10750
|
type: ClientMsgCode.ADD_FEED_MESSAGE,
|
|
11451
10751
|
requestId,
|
|
11452
10752
|
feedId,
|
|
11453
10753
|
data,
|
|
11454
|
-
id: _optionalChain([options2, 'optionalAccess',
|
|
11455
|
-
createdAt: _optionalChain([options2, 'optionalAccess',
|
|
10754
|
+
id: _optionalChain([options2, 'optionalAccess', _248 => _248.id]),
|
|
10755
|
+
createdAt: _optionalChain([options2, 'optionalAccess', _249 => _249.createdAt])
|
|
11456
10756
|
};
|
|
11457
10757
|
context.buffer.messages.push(message);
|
|
11458
10758
|
flushNowOrSoon();
|
|
@@ -11469,7 +10769,7 @@ function createRoom(options, config) {
|
|
|
11469
10769
|
feedId,
|
|
11470
10770
|
messageId,
|
|
11471
10771
|
data,
|
|
11472
|
-
updatedAt: _optionalChain([options2, 'optionalAccess',
|
|
10772
|
+
updatedAt: _optionalChain([options2, 'optionalAccess', _250 => _250.updatedAt])
|
|
11473
10773
|
};
|
|
11474
10774
|
context.buffer.messages.push(message);
|
|
11475
10775
|
flushNowOrSoon();
|
|
@@ -11676,8 +10976,8 @@ function createRoom(options, config) {
|
|
|
11676
10976
|
async function getThreads(options2) {
|
|
11677
10977
|
return httpClient.getThreads({
|
|
11678
10978
|
roomId,
|
|
11679
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
11680
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10979
|
+
query: _optionalChain([options2, 'optionalAccess', _251 => _251.query]),
|
|
10980
|
+
cursor: _optionalChain([options2, 'optionalAccess', _252 => _252.cursor])
|
|
11681
10981
|
});
|
|
11682
10982
|
}
|
|
11683
10983
|
async function getThread(threadId) {
|
|
@@ -11799,7 +11099,7 @@ function createRoom(options, config) {
|
|
|
11799
11099
|
function getSubscriptionSettings(options2) {
|
|
11800
11100
|
return httpClient.getSubscriptionSettings({
|
|
11801
11101
|
roomId,
|
|
11802
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
11102
|
+
signal: _optionalChain([options2, 'optionalAccess', _253 => _253.signal])
|
|
11803
11103
|
});
|
|
11804
11104
|
}
|
|
11805
11105
|
function updateSubscriptionSettings(settings) {
|
|
@@ -11821,7 +11121,7 @@ function createRoom(options, config) {
|
|
|
11821
11121
|
{
|
|
11822
11122
|
[kInternal]: {
|
|
11823
11123
|
get presenceBuffer() {
|
|
11824
|
-
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)));
|
|
11825
11125
|
},
|
|
11826
11126
|
// prettier-ignore
|
|
11827
11127
|
get undoStack() {
|
|
@@ -11836,9 +11136,9 @@ function createRoom(options, config) {
|
|
|
11836
11136
|
return context.yjsProvider;
|
|
11837
11137
|
},
|
|
11838
11138
|
setYjsProvider(newProvider) {
|
|
11839
|
-
_optionalChain([context, 'access',
|
|
11139
|
+
_optionalChain([context, 'access', _257 => _257.yjsProvider, 'optionalAccess', _258 => _258.off, 'call', _259 => _259("status", yjsStatusDidChange)]);
|
|
11840
11140
|
context.yjsProvider = newProvider;
|
|
11841
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
11141
|
+
_optionalChain([newProvider, 'optionalAccess', _260 => _260.on, 'call', _261 => _261("status", yjsStatusDidChange)]);
|
|
11842
11142
|
context.yjsProviderDidChange.notify();
|
|
11843
11143
|
},
|
|
11844
11144
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -11879,11 +11179,6 @@ function createRoom(options, config) {
|
|
|
11879
11179
|
connect: () => managedSocket.connect(),
|
|
11880
11180
|
reconnect: () => managedSocket.reconnect(),
|
|
11881
11181
|
disconnect: () => managedSocket.disconnect(),
|
|
11882
|
-
_dump: () => {
|
|
11883
|
-
const n = context.pool.nodes.size;
|
|
11884
|
-
return `Room "${roomId}" (${n} node${n === 1 ? "" : "s"}):
|
|
11885
|
-
${dumpPool(context.pool)}`;
|
|
11886
|
-
},
|
|
11887
11182
|
destroy: () => {
|
|
11888
11183
|
pendingFeedsRequests.forEach(
|
|
11889
11184
|
(request) => request.reject(new Error("Room destroyed"))
|
|
@@ -11896,7 +11191,7 @@ ${dumpPool(context.pool)}`;
|
|
|
11896
11191
|
source.dispose();
|
|
11897
11192
|
}
|
|
11898
11193
|
eventHub.roomWillDestroy.notify();
|
|
11899
|
-
_optionalChain([context, 'access',
|
|
11194
|
+
_optionalChain([context, 'access', _262 => _262.yjsProvider, 'optionalAccess', _263 => _263.off, 'call', _264 => _264("status", yjsStatusDidChange)]);
|
|
11900
11195
|
syncSourceForStorage.destroy();
|
|
11901
11196
|
syncSourceForYjs.destroy();
|
|
11902
11197
|
uninstallBgTabSpy();
|
|
@@ -12056,7 +11351,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
12056
11351
|
}
|
|
12057
11352
|
if (isLiveNode(first)) {
|
|
12058
11353
|
const node = first;
|
|
12059
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
11354
|
+
if (_optionalChain([options, 'optionalAccess', _265 => _265.isDeep])) {
|
|
12060
11355
|
const storageCallback = second;
|
|
12061
11356
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
12062
11357
|
} else {
|
|
@@ -12075,7 +11370,11 @@ function isRoomEventName(value) {
|
|
|
12075
11370
|
}
|
|
12076
11371
|
function makeAuthDelegateForRoom(roomId, authManager) {
|
|
12077
11372
|
return async () => {
|
|
12078
|
-
return authManager.getAuthValue({
|
|
11373
|
+
return authManager.getAuthValue({
|
|
11374
|
+
roomId,
|
|
11375
|
+
resource: "presence",
|
|
11376
|
+
access: "read"
|
|
11377
|
+
});
|
|
12079
11378
|
};
|
|
12080
11379
|
}
|
|
12081
11380
|
function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
|
|
@@ -12124,7 +11423,7 @@ function getBaseUrl(baseUrl) {
|
|
|
12124
11423
|
function isLocalhost(url2) {
|
|
12125
11424
|
try {
|
|
12126
11425
|
return new URL(url2).hostname === "localhost";
|
|
12127
|
-
} catch (
|
|
11426
|
+
} catch (e11) {
|
|
12128
11427
|
return false;
|
|
12129
11428
|
}
|
|
12130
11429
|
}
|
|
@@ -12142,8 +11441,8 @@ function createClient(options) {
|
|
|
12142
11441
|
const authManager = createAuthManager(options, (token) => {
|
|
12143
11442
|
currentUserId.set(() => token.uid);
|
|
12144
11443
|
});
|
|
12145
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
12146
|
-
_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)]);
|
|
12147
11446
|
const httpClient = createApiClient({
|
|
12148
11447
|
baseUrl,
|
|
12149
11448
|
fetchPolyfill,
|
|
@@ -12161,11 +11460,13 @@ function createClient(options) {
|
|
|
12161
11460
|
delegates: {
|
|
12162
11461
|
createSocket: makeCreateSocketDelegateForAi(
|
|
12163
11462
|
baseUrl,
|
|
12164
|
-
_optionalChain([clientOptions, 'access',
|
|
11463
|
+
_optionalChain([clientOptions, 'access', _271 => _271.polyfills, 'optionalAccess', _272 => _272.WebSocket])
|
|
12165
11464
|
),
|
|
12166
11465
|
authenticate: async () => {
|
|
12167
11466
|
const resp = await authManager.getAuthValue({
|
|
12168
|
-
|
|
11467
|
+
// TODO: Should we have permissions for AI Copilots?
|
|
11468
|
+
resource: "personal",
|
|
11469
|
+
access: "write"
|
|
12169
11470
|
});
|
|
12170
11471
|
if (resp.type === "public") {
|
|
12171
11472
|
throw new StopRetrying(
|
|
@@ -12231,7 +11532,7 @@ function createClient(options) {
|
|
|
12231
11532
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
12232
11533
|
roomId,
|
|
12233
11534
|
baseUrl,
|
|
12234
|
-
_optionalChain([clientOptions, 'access',
|
|
11535
|
+
_optionalChain([clientOptions, 'access', _273 => _273.polyfills, 'optionalAccess', _274 => _274.WebSocket])
|
|
12235
11536
|
),
|
|
12236
11537
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
12237
11538
|
})),
|
|
@@ -12254,7 +11555,7 @@ function createClient(options) {
|
|
|
12254
11555
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
12255
11556
|
if (shouldConnect) {
|
|
12256
11557
|
if (typeof atob === "undefined") {
|
|
12257
|
-
if (_optionalChain([clientOptions, 'access',
|
|
11558
|
+
if (_optionalChain([clientOptions, 'access', _275 => _275.polyfills, 'optionalAccess', _276 => _276.atob]) === void 0) {
|
|
12258
11559
|
throw new Error(
|
|
12259
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"
|
|
12260
11561
|
);
|
|
@@ -12266,7 +11567,7 @@ function createClient(options) {
|
|
|
12266
11567
|
return leaseRoom(newRoomDetails);
|
|
12267
11568
|
}
|
|
12268
11569
|
function getRoom(roomId) {
|
|
12269
|
-
const room = _optionalChain([roomsById, 'access',
|
|
11570
|
+
const room = _optionalChain([roomsById, 'access', _277 => _277.get, 'call', _278 => _278(roomId), 'optionalAccess', _279 => _279.room]);
|
|
12270
11571
|
return room ? room : null;
|
|
12271
11572
|
}
|
|
12272
11573
|
function logout() {
|
|
@@ -12282,7 +11583,7 @@ function createClient(options) {
|
|
|
12282
11583
|
const batchedResolveUsers = new Batch(
|
|
12283
11584
|
async (batchedUserIds) => {
|
|
12284
11585
|
const userIds = batchedUserIds.flat();
|
|
12285
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
11586
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _280 => _280({ userIds })]);
|
|
12286
11587
|
warnOnceIf(
|
|
12287
11588
|
!resolveUsers,
|
|
12288
11589
|
"Set the resolveUsers option in createClient to specify user info."
|
|
@@ -12299,7 +11600,7 @@ function createClient(options) {
|
|
|
12299
11600
|
const batchedResolveRoomsInfo = new Batch(
|
|
12300
11601
|
async (batchedRoomIds) => {
|
|
12301
11602
|
const roomIds = batchedRoomIds.flat();
|
|
12302
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
11603
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _281 => _281({ roomIds })]);
|
|
12303
11604
|
warnOnceIf(
|
|
12304
11605
|
!resolveRoomsInfo,
|
|
12305
11606
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
@@ -12316,7 +11617,7 @@ function createClient(options) {
|
|
|
12316
11617
|
const batchedResolveGroupsInfo = new Batch(
|
|
12317
11618
|
async (batchedGroupIds) => {
|
|
12318
11619
|
const groupIds = batchedGroupIds.flat();
|
|
12319
|
-
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall',
|
|
11620
|
+
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _282 => _282({ groupIds })]);
|
|
12320
11621
|
warnOnceIf(
|
|
12321
11622
|
!resolveGroupsInfo,
|
|
12322
11623
|
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
@@ -12375,7 +11676,7 @@ function createClient(options) {
|
|
|
12375
11676
|
}
|
|
12376
11677
|
};
|
|
12377
11678
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
12378
|
-
_optionalChain([win, 'optionalAccess',
|
|
11679
|
+
_optionalChain([win, 'optionalAccess', _283 => _283.addEventListener, 'call', _284 => _284("beforeunload", maybePreventClose)]);
|
|
12379
11680
|
}
|
|
12380
11681
|
async function getNotificationSettings(options2) {
|
|
12381
11682
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -12391,7 +11692,6 @@ function createClient(options) {
|
|
|
12391
11692
|
{
|
|
12392
11693
|
enterRoom,
|
|
12393
11694
|
getRoom,
|
|
12394
|
-
_dump: () => Array.from(roomsById.values(), ({ room }) => room._dump()).join("\n\n"),
|
|
12395
11695
|
logout,
|
|
12396
11696
|
// Public inbox notifications API
|
|
12397
11697
|
getInboxNotifications: httpClient.getInboxNotifications,
|
|
@@ -12503,7 +11803,7 @@ var commentBodyElementsTypes = {
|
|
|
12503
11803
|
mention: "inline"
|
|
12504
11804
|
};
|
|
12505
11805
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
12506
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
11806
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _285 => _285.content])) {
|
|
12507
11807
|
return;
|
|
12508
11808
|
}
|
|
12509
11809
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -12513,13 +11813,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
12513
11813
|
for (const block of body.content) {
|
|
12514
11814
|
if (type === "all" || type === "block") {
|
|
12515
11815
|
if (guard(block)) {
|
|
12516
|
-
_optionalChain([visitor, 'optionalCall',
|
|
11816
|
+
_optionalChain([visitor, 'optionalCall', _286 => _286(block)]);
|
|
12517
11817
|
}
|
|
12518
11818
|
}
|
|
12519
11819
|
if (type === "all" || type === "inline") {
|
|
12520
11820
|
for (const inline of block.children) {
|
|
12521
11821
|
if (guard(inline)) {
|
|
12522
|
-
_optionalChain([visitor, 'optionalCall',
|
|
11822
|
+
_optionalChain([visitor, 'optionalCall', _287 => _287(inline)]);
|
|
12523
11823
|
}
|
|
12524
11824
|
}
|
|
12525
11825
|
}
|
|
@@ -12689,7 +11989,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
12689
11989
|
text: ({ element }) => element.text,
|
|
12690
11990
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
12691
11991
|
mention: ({ element, user, group }) => {
|
|
12692
|
-
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
11992
|
+
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _288 => _288.name]), () => ( _optionalChain([group, 'optionalAccess', _289 => _289.name]))), () => ( element.id))}`;
|
|
12693
11993
|
}
|
|
12694
11994
|
};
|
|
12695
11995
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -12719,7 +12019,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
12719
12019
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
12720
12020
|
},
|
|
12721
12021
|
mention: ({ element, user, group }) => {
|
|
12722
|
-
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>`;
|
|
12723
12023
|
}
|
|
12724
12024
|
};
|
|
12725
12025
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -12749,20 +12049,20 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
12749
12049
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
12750
12050
|
},
|
|
12751
12051
|
mention: ({ element, user, group }) => {
|
|
12752
|
-
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))}`;
|
|
12753
12053
|
}
|
|
12754
12054
|
};
|
|
12755
12055
|
async function stringifyCommentBody(body, options) {
|
|
12756
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12757
|
-
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")));
|
|
12758
12058
|
const elements = {
|
|
12759
12059
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
12760
|
-
..._optionalChain([options, 'optionalAccess',
|
|
12060
|
+
..._optionalChain([options, 'optionalAccess', _298 => _298.elements])
|
|
12761
12061
|
};
|
|
12762
12062
|
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
12763
12063
|
body,
|
|
12764
|
-
_optionalChain([options, 'optionalAccess',
|
|
12765
|
-
_optionalChain([options, 'optionalAccess',
|
|
12064
|
+
_optionalChain([options, 'optionalAccess', _299 => _299.resolveUsers]),
|
|
12065
|
+
_optionalChain([options, 'optionalAccess', _300 => _300.resolveGroupsInfo])
|
|
12766
12066
|
);
|
|
12767
12067
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
12768
12068
|
switch (block.type) {
|
|
@@ -12844,12 +12144,6 @@ function toPlainLson(lson) {
|
|
|
12844
12144
|
liveblocksType: "LiveList",
|
|
12845
12145
|
data: [...lson].map((item) => toPlainLson(item))
|
|
12846
12146
|
};
|
|
12847
|
-
} else if (lson instanceof LiveText) {
|
|
12848
|
-
return {
|
|
12849
|
-
liveblocksType: "LiveText",
|
|
12850
|
-
data: lson.toJSON(),
|
|
12851
|
-
version: lson.version
|
|
12852
|
-
};
|
|
12853
12147
|
} else {
|
|
12854
12148
|
return lson;
|
|
12855
12149
|
}
|
|
@@ -12903,9 +12197,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
12903
12197
|
const startTime = performance.now();
|
|
12904
12198
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
12905
12199
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
12906
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
12200
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _301 => _301.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
12907
12201
|
const context = {
|
|
12908
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
12202
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _302 => _302.visibilityState]) !== "hidden",
|
|
12909
12203
|
lastSuccessfulPollAt: startTime,
|
|
12910
12204
|
count: 0,
|
|
12911
12205
|
backoff: 0
|
|
@@ -12986,11 +12280,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
12986
12280
|
pollNowIfStale();
|
|
12987
12281
|
}
|
|
12988
12282
|
function onVisibilityChange() {
|
|
12989
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
12283
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _303 => _303.visibilityState]) !== "hidden");
|
|
12990
12284
|
}
|
|
12991
|
-
_optionalChain([doc, 'optionalAccess',
|
|
12992
|
-
_optionalChain([win, 'optionalAccess',
|
|
12993
|
-
_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)]);
|
|
12994
12288
|
fsm.start();
|
|
12995
12289
|
return {
|
|
12996
12290
|
inc,
|
|
@@ -13131,5 +12425,8 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
13131
12425
|
|
|
13132
12426
|
|
|
13133
12427
|
|
|
13134
|
-
|
|
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;
|
|
13135
12432
|
//# sourceMappingURL=index.cjs.map
|