@liveblocks/core 3.22.0-file1 → 3.22.0-rc1
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 +305 -577
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +216 -287
- package/dist/index.d.ts +216 -287
- package/dist/index.js +143 -415
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.22.0-
|
|
9
|
+
var PKG_VERSION = "3.22.0-rc1";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -1309,7 +1309,6 @@ var nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(
|
|
|
1309
1309
|
var THREAD_ID_PREFIX = "th";
|
|
1310
1310
|
var COMMENT_ID_PREFIX = "cm";
|
|
1311
1311
|
var COMMENT_ATTACHMENT_ID_PREFIX = "at";
|
|
1312
|
-
var STORAGE_FILE_ID_PREFIX = "fl";
|
|
1313
1312
|
var INBOX_NOTIFICATION_ID_PREFIX = "in";
|
|
1314
1313
|
function createOptimisticId(prefix) {
|
|
1315
1314
|
return `${prefix}_${nanoid()}`;
|
|
@@ -1323,9 +1322,6 @@ function createCommentId() {
|
|
|
1323
1322
|
function createCommentAttachmentId() {
|
|
1324
1323
|
return createOptimisticId(COMMENT_ATTACHMENT_ID_PREFIX);
|
|
1325
1324
|
}
|
|
1326
|
-
function createStorageFileId() {
|
|
1327
|
-
return createOptimisticId(STORAGE_FILE_ID_PREFIX);
|
|
1328
|
-
}
|
|
1329
1325
|
function createInboxNotificationId() {
|
|
1330
1326
|
return createOptimisticId(INBOX_NOTIFICATION_ID_PREFIX);
|
|
1331
1327
|
}
|
|
@@ -1571,120 +1567,6 @@ function isUrl(string) {
|
|
|
1571
1567
|
}
|
|
1572
1568
|
|
|
1573
1569
|
// src/api-client.ts
|
|
1574
|
-
var ROOM_FILE_PART_SIZE = 5 * 1024 * 1024;
|
|
1575
|
-
var ROOM_FILE_RETRY_ATTEMPTS = 10;
|
|
1576
|
-
var ROOM_FILE_RETRY_DELAYS = [
|
|
1577
|
-
2e3,
|
|
1578
|
-
2e3,
|
|
1579
|
-
2e3,
|
|
1580
|
-
2e3,
|
|
1581
|
-
2e3,
|
|
1582
|
-
2e3,
|
|
1583
|
-
2e3,
|
|
1584
|
-
2e3,
|
|
1585
|
-
2e3,
|
|
1586
|
-
2e3
|
|
1587
|
-
];
|
|
1588
|
-
async function uploadRoomFile({
|
|
1589
|
-
file,
|
|
1590
|
-
signal,
|
|
1591
|
-
abortErrorMessage,
|
|
1592
|
-
uploadSingle,
|
|
1593
|
-
createMultipartUpload,
|
|
1594
|
-
uploadMultipartPart,
|
|
1595
|
-
completeMultipartUpload,
|
|
1596
|
-
abortMultipartUpload
|
|
1597
|
-
}) {
|
|
1598
|
-
const abortError = createAbortError(abortErrorMessage);
|
|
1599
|
-
if (signal?.aborted) {
|
|
1600
|
-
throw abortError;
|
|
1601
|
-
}
|
|
1602
|
-
const handleRetryError = (err) => {
|
|
1603
|
-
if (signal?.aborted) {
|
|
1604
|
-
throw abortError;
|
|
1605
|
-
}
|
|
1606
|
-
if (err instanceof HttpError && err.status === 413) {
|
|
1607
|
-
throw err;
|
|
1608
|
-
}
|
|
1609
|
-
return false;
|
|
1610
|
-
};
|
|
1611
|
-
if (file.size <= ROOM_FILE_PART_SIZE) {
|
|
1612
|
-
return autoRetry(
|
|
1613
|
-
uploadSingle,
|
|
1614
|
-
ROOM_FILE_RETRY_ATTEMPTS,
|
|
1615
|
-
ROOM_FILE_RETRY_DELAYS,
|
|
1616
|
-
handleRetryError
|
|
1617
|
-
);
|
|
1618
|
-
}
|
|
1619
|
-
let uploadId;
|
|
1620
|
-
const uploadedParts = [];
|
|
1621
|
-
const multipartUpload = await autoRetry(
|
|
1622
|
-
createMultipartUpload,
|
|
1623
|
-
ROOM_FILE_RETRY_ATTEMPTS,
|
|
1624
|
-
ROOM_FILE_RETRY_DELAYS,
|
|
1625
|
-
handleRetryError
|
|
1626
|
-
);
|
|
1627
|
-
try {
|
|
1628
|
-
uploadId = multipartUpload.uploadId;
|
|
1629
|
-
if (signal?.aborted) {
|
|
1630
|
-
throw abortError;
|
|
1631
|
-
}
|
|
1632
|
-
const batches = chunk(splitFileIntoParts(file), 5);
|
|
1633
|
-
for (const parts of batches) {
|
|
1634
|
-
const uploadedPartsPromises = [];
|
|
1635
|
-
for (const { part, partNumber } of parts) {
|
|
1636
|
-
uploadedPartsPromises.push(
|
|
1637
|
-
autoRetry(
|
|
1638
|
-
() => uploadMultipartPart(multipartUpload.uploadId, partNumber, part),
|
|
1639
|
-
ROOM_FILE_RETRY_ATTEMPTS,
|
|
1640
|
-
ROOM_FILE_RETRY_DELAYS,
|
|
1641
|
-
handleRetryError
|
|
1642
|
-
)
|
|
1643
|
-
);
|
|
1644
|
-
}
|
|
1645
|
-
uploadedParts.push(...await Promise.all(uploadedPartsPromises));
|
|
1646
|
-
}
|
|
1647
|
-
if (signal?.aborted) {
|
|
1648
|
-
throw abortError;
|
|
1649
|
-
}
|
|
1650
|
-
return completeMultipartUpload(
|
|
1651
|
-
uploadId,
|
|
1652
|
-
uploadedParts.sort((a, b) => a.partNumber - b.partNumber)
|
|
1653
|
-
);
|
|
1654
|
-
} catch (error3) {
|
|
1655
|
-
if (uploadId && isAbortOrTimeoutError(error3)) {
|
|
1656
|
-
try {
|
|
1657
|
-
await abortMultipartUpload(uploadId);
|
|
1658
|
-
} catch {
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
throw error3;
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
function splitFileIntoParts(file) {
|
|
1665
|
-
const parts = [];
|
|
1666
|
-
let start = 0;
|
|
1667
|
-
while (start < file.size) {
|
|
1668
|
-
const end = Math.min(start + ROOM_FILE_PART_SIZE, file.size);
|
|
1669
|
-
parts.push({
|
|
1670
|
-
partNumber: parts.length + 1,
|
|
1671
|
-
part: file.slice(start, end)
|
|
1672
|
-
});
|
|
1673
|
-
start = end;
|
|
1674
|
-
}
|
|
1675
|
-
return parts;
|
|
1676
|
-
}
|
|
1677
|
-
function isAbortOrTimeoutError(error3) {
|
|
1678
|
-
return error3 instanceof Error && (error3.name === "AbortError" || error3.name === "TimeoutError");
|
|
1679
|
-
}
|
|
1680
|
-
function createAbortError(message) {
|
|
1681
|
-
if (typeof DOMException === "function") {
|
|
1682
|
-
return new DOMException(message, "AbortError");
|
|
1683
|
-
}
|
|
1684
|
-
const error3 = new Error(message);
|
|
1685
|
-
error3.name = "AbortError";
|
|
1686
|
-
return error3;
|
|
1687
|
-
}
|
|
1688
1570
|
function commentsResourceForVisibility(visibility) {
|
|
1689
1571
|
if (visibility === "private") {
|
|
1690
1572
|
return "comments:private";
|
|
@@ -2000,128 +1882,151 @@ function createApiClient({
|
|
|
2000
1882
|
}
|
|
2001
1883
|
async function uploadAttachment(options) {
|
|
2002
1884
|
const roomId = options.roomId;
|
|
1885
|
+
const abortSignal = options.signal;
|
|
2003
1886
|
const attachment = options.attachment;
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
{
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
abortMultipartUpload: async (uploadId) => {
|
|
2052
|
-
await httpClient.rawDelete(
|
|
2053
|
-
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}`,
|
|
1887
|
+
const abortError = abortSignal ? new DOMException(
|
|
1888
|
+
`Upload of attachment ${options.attachment.id} was aborted.`,
|
|
1889
|
+
"AbortError"
|
|
1890
|
+
) : void 0;
|
|
1891
|
+
if (abortSignal?.aborted) {
|
|
1892
|
+
throw abortError;
|
|
1893
|
+
}
|
|
1894
|
+
const handleRetryError = (err) => {
|
|
1895
|
+
if (abortSignal?.aborted) {
|
|
1896
|
+
throw abortError;
|
|
1897
|
+
}
|
|
1898
|
+
if (err instanceof HttpError && err.status === 413) {
|
|
1899
|
+
throw err;
|
|
1900
|
+
}
|
|
1901
|
+
return false;
|
|
1902
|
+
};
|
|
1903
|
+
const ATTACHMENT_PART_SIZE = 5 * 1024 * 1024;
|
|
1904
|
+
const RETRY_ATTEMPTS = 10;
|
|
1905
|
+
const RETRY_DELAYS = [
|
|
1906
|
+
2e3,
|
|
1907
|
+
2e3,
|
|
1908
|
+
2e3,
|
|
1909
|
+
2e3,
|
|
1910
|
+
2e3,
|
|
1911
|
+
2e3,
|
|
1912
|
+
2e3,
|
|
1913
|
+
2e3,
|
|
1914
|
+
2e3,
|
|
1915
|
+
2e3
|
|
1916
|
+
];
|
|
1917
|
+
function splitFileIntoParts(file) {
|
|
1918
|
+
const parts = [];
|
|
1919
|
+
let start = 0;
|
|
1920
|
+
while (start < file.size) {
|
|
1921
|
+
const end = Math.min(start + ATTACHMENT_PART_SIZE, file.size);
|
|
1922
|
+
parts.push({
|
|
1923
|
+
partNumber: parts.length + 1,
|
|
1924
|
+
part: file.slice(start, end)
|
|
1925
|
+
});
|
|
1926
|
+
start = end;
|
|
1927
|
+
}
|
|
1928
|
+
return parts;
|
|
1929
|
+
}
|
|
1930
|
+
if (attachment.size <= ATTACHMENT_PART_SIZE) {
|
|
1931
|
+
return autoRetry(
|
|
1932
|
+
async () => httpClient.putBlob(
|
|
1933
|
+
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/upload/${encodeURIComponent(attachment.name)}`,
|
|
2054
1934
|
await authManager.getAuthValue({
|
|
2055
1935
|
roomId,
|
|
2056
1936
|
resource: "comments",
|
|
2057
1937
|
access: "write"
|
|
2058
|
-
})
|
|
1938
|
+
}),
|
|
1939
|
+
attachment.file,
|
|
1940
|
+
{ fileSize: attachment.size },
|
|
1941
|
+
{ signal: abortSignal }
|
|
1942
|
+
),
|
|
1943
|
+
RETRY_ATTEMPTS,
|
|
1944
|
+
RETRY_DELAYS,
|
|
1945
|
+
handleRetryError
|
|
1946
|
+
);
|
|
1947
|
+
} else {
|
|
1948
|
+
let uploadId;
|
|
1949
|
+
const uploadedParts = [];
|
|
1950
|
+
const createMultiPartUpload = await autoRetry(
|
|
1951
|
+
async () => httpClient.post(
|
|
1952
|
+
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${encodeURIComponent(attachment.name)}`,
|
|
1953
|
+
await authManager.getAuthValue({
|
|
1954
|
+
roomId,
|
|
1955
|
+
resource: "comments",
|
|
1956
|
+
access: "write"
|
|
1957
|
+
}),
|
|
1958
|
+
void 0,
|
|
1959
|
+
{ signal: abortSignal },
|
|
1960
|
+
{ fileSize: attachment.size }
|
|
1961
|
+
),
|
|
1962
|
+
RETRY_ATTEMPTS,
|
|
1963
|
+
RETRY_DELAYS,
|
|
1964
|
+
handleRetryError
|
|
1965
|
+
);
|
|
1966
|
+
try {
|
|
1967
|
+
uploadId = createMultiPartUpload.uploadId;
|
|
1968
|
+
const parts = splitFileIntoParts(attachment.file);
|
|
1969
|
+
if (abortSignal?.aborted) {
|
|
1970
|
+
throw abortError;
|
|
1971
|
+
}
|
|
1972
|
+
const batches = chunk(parts, 5);
|
|
1973
|
+
for (const parts2 of batches) {
|
|
1974
|
+
const uploadedPartsPromises = [];
|
|
1975
|
+
for (const { part, partNumber } of parts2) {
|
|
1976
|
+
uploadedPartsPromises.push(
|
|
1977
|
+
autoRetry(
|
|
1978
|
+
async () => httpClient.putBlob(
|
|
1979
|
+
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${createMultiPartUpload.uploadId}/${String(partNumber)}`,
|
|
1980
|
+
await authManager.getAuthValue({
|
|
1981
|
+
roomId,
|
|
1982
|
+
resource: "comments",
|
|
1983
|
+
access: "write"
|
|
1984
|
+
}),
|
|
1985
|
+
part,
|
|
1986
|
+
void 0,
|
|
1987
|
+
{ signal: abortSignal }
|
|
1988
|
+
),
|
|
1989
|
+
RETRY_ATTEMPTS,
|
|
1990
|
+
RETRY_DELAYS,
|
|
1991
|
+
handleRetryError
|
|
1992
|
+
)
|
|
1993
|
+
);
|
|
1994
|
+
}
|
|
1995
|
+
uploadedParts.push(...await Promise.all(uploadedPartsPromises));
|
|
1996
|
+
}
|
|
1997
|
+
if (abortSignal?.aborted) {
|
|
1998
|
+
throw abortError;
|
|
1999
|
+
}
|
|
2000
|
+
const sortedUploadedParts = uploadedParts.sort(
|
|
2001
|
+
(a, b) => a.partNumber - b.partNumber
|
|
2059
2002
|
);
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
}
|
|
2063
|
-
async function uploadFile(options) {
|
|
2064
|
-
const roomId = options.roomId;
|
|
2065
|
-
const file = options.file;
|
|
2066
|
-
const fileId = createStorageFileId();
|
|
2067
|
-
return uploadRoomFile({
|
|
2068
|
-
file,
|
|
2069
|
-
signal: options.signal,
|
|
2070
|
-
abortErrorMessage: `Upload of file ${fileId} was aborted.`,
|
|
2071
|
-
uploadSingle: async () => httpClient.putBlob(
|
|
2072
|
-
url`/v2/c/rooms/${roomId}/storage-files/${fileId}/upload/${encodeURIComponent(file.name)}`,
|
|
2073
|
-
await authManager.getAuthValue({
|
|
2074
|
-
roomId,
|
|
2075
|
-
resource: "storage",
|
|
2076
|
-
access: "write"
|
|
2077
|
-
}),
|
|
2078
|
-
file,
|
|
2079
|
-
{ fileSize: file.size },
|
|
2080
|
-
{ signal: options.signal }
|
|
2081
|
-
),
|
|
2082
|
-
createMultipartUpload: async () => httpClient.post(
|
|
2083
|
-
url`/v2/c/rooms/${roomId}/storage-files/${fileId}/multipart/${encodeURIComponent(file.name)}`,
|
|
2084
|
-
await authManager.getAuthValue({
|
|
2085
|
-
roomId,
|
|
2086
|
-
resource: "storage",
|
|
2087
|
-
access: "write"
|
|
2088
|
-
}),
|
|
2089
|
-
void 0,
|
|
2090
|
-
{ signal: options.signal },
|
|
2091
|
-
{ fileSize: file.size }
|
|
2092
|
-
),
|
|
2093
|
-
uploadMultipartPart: async (uploadId, partNumber, part) => httpClient.putBlob(
|
|
2094
|
-
url`/v2/c/rooms/${roomId}/storage-files/${fileId}/multipart/${uploadId}/${String(partNumber)}`,
|
|
2095
|
-
await authManager.getAuthValue({
|
|
2096
|
-
roomId,
|
|
2097
|
-
resource: "storage",
|
|
2098
|
-
access: "write"
|
|
2099
|
-
}),
|
|
2100
|
-
part,
|
|
2101
|
-
void 0,
|
|
2102
|
-
{ signal: options.signal }
|
|
2103
|
-
),
|
|
2104
|
-
completeMultipartUpload: async (uploadId, parts) => httpClient.post(
|
|
2105
|
-
url`/v2/c/rooms/${roomId}/storage-files/${fileId}/multipart/${uploadId}/complete`,
|
|
2106
|
-
await authManager.getAuthValue({
|
|
2107
|
-
roomId,
|
|
2108
|
-
resource: "storage",
|
|
2109
|
-
access: "write"
|
|
2110
|
-
}),
|
|
2111
|
-
{ parts },
|
|
2112
|
-
{ signal: options.signal }
|
|
2113
|
-
),
|
|
2114
|
-
abortMultipartUpload: async (uploadId) => {
|
|
2115
|
-
await httpClient.rawDelete(
|
|
2116
|
-
url`/v2/c/rooms/${roomId}/storage-files/${fileId}/multipart/${uploadId}`,
|
|
2003
|
+
return httpClient.post(
|
|
2004
|
+
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}/complete`,
|
|
2117
2005
|
await authManager.getAuthValue({
|
|
2118
2006
|
roomId,
|
|
2119
|
-
resource: "
|
|
2007
|
+
resource: "comments",
|
|
2120
2008
|
access: "write"
|
|
2121
|
-
})
|
|
2009
|
+
}),
|
|
2010
|
+
{ parts: sortedUploadedParts },
|
|
2011
|
+
{ signal: abortSignal }
|
|
2122
2012
|
);
|
|
2013
|
+
} catch (error3) {
|
|
2014
|
+
if (uploadId && error3?.name && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
|
|
2015
|
+
try {
|
|
2016
|
+
await httpClient.rawDelete(
|
|
2017
|
+
url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}`,
|
|
2018
|
+
await authManager.getAuthValue({
|
|
2019
|
+
roomId,
|
|
2020
|
+
resource: "comments",
|
|
2021
|
+
access: "write"
|
|
2022
|
+
})
|
|
2023
|
+
);
|
|
2024
|
+
} catch {
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
throw error3;
|
|
2123
2028
|
}
|
|
2124
|
-
}
|
|
2029
|
+
}
|
|
2125
2030
|
}
|
|
2126
2031
|
const attachmentUrlsBatchStoresByRoom = new DefaultMap((roomId) => {
|
|
2127
2032
|
const batch2 = new Batch(
|
|
@@ -2151,34 +2056,6 @@ function createApiClient({
|
|
|
2151
2056
|
const batch2 = getOrCreateAttachmentUrlsStore(options.roomId).batch;
|
|
2152
2057
|
return batch2.get(options.attachmentId);
|
|
2153
2058
|
}
|
|
2154
|
-
const fileUrlsBatchStoresByRoom = new DefaultMap((roomId) => {
|
|
2155
|
-
const batch2 = new Batch(
|
|
2156
|
-
async (batchedFileIds) => {
|
|
2157
|
-
const fileIds = batchedFileIds.flat();
|
|
2158
|
-
const { urls } = await httpClient.post(
|
|
2159
|
-
url`/v2/c/rooms/${roomId}/storage-files/presigned-urls`,
|
|
2160
|
-
await authManager.getAuthValue({
|
|
2161
|
-
roomId,
|
|
2162
|
-
resource: "storage",
|
|
2163
|
-
access: "read"
|
|
2164
|
-
}),
|
|
2165
|
-
{ fileIds }
|
|
2166
|
-
);
|
|
2167
|
-
return urls.map(
|
|
2168
|
-
(url2) => url2 ?? new Error("There was an error while getting this file's URL")
|
|
2169
|
-
);
|
|
2170
|
-
},
|
|
2171
|
-
{ delay: 50 }
|
|
2172
|
-
);
|
|
2173
|
-
return createBatchStore(batch2);
|
|
2174
|
-
});
|
|
2175
|
-
function getOrCreateFileUrlsStore(roomId) {
|
|
2176
|
-
return fileUrlsBatchStoresByRoom.getOrCreate(roomId);
|
|
2177
|
-
}
|
|
2178
|
-
function getFileUrl(options) {
|
|
2179
|
-
const batch2 = getOrCreateFileUrlsStore(options.roomId).batch;
|
|
2180
|
-
return batch2.get(options.fileId);
|
|
2181
|
-
}
|
|
2182
2059
|
async function getSubscriptionSettings(options) {
|
|
2183
2060
|
return httpClient.get(
|
|
2184
2061
|
url`/v2/c/rooms/${options.roomId}/subscription-settings`,
|
|
@@ -2607,10 +2484,6 @@ function createApiClient({
|
|
|
2607
2484
|
getAttachmentUrl,
|
|
2608
2485
|
uploadAttachment,
|
|
2609
2486
|
getOrCreateAttachmentUrlsStore,
|
|
2610
|
-
// Room storage files
|
|
2611
|
-
getFileUrl,
|
|
2612
|
-
uploadFile,
|
|
2613
|
-
getOrCreateFileUrlsStore,
|
|
2614
2487
|
// Room storage
|
|
2615
2488
|
streamStorage,
|
|
2616
2489
|
// Notifications
|
|
@@ -5942,15 +5815,13 @@ var OpCode = Object.freeze({
|
|
|
5942
5815
|
DELETE_CRDT: 5,
|
|
5943
5816
|
DELETE_OBJECT_KEY: 6,
|
|
5944
5817
|
CREATE_MAP: 7,
|
|
5945
|
-
CREATE_REGISTER: 8
|
|
5946
|
-
// 9 and 10 are reserved for the parallel LiveText work.
|
|
5947
|
-
CREATE_FILE: 11
|
|
5818
|
+
CREATE_REGISTER: 8
|
|
5948
5819
|
});
|
|
5949
5820
|
function isIgnoredOp(op) {
|
|
5950
5821
|
return op.type === OpCode.DELETE_CRDT && op.id === "ACK";
|
|
5951
5822
|
}
|
|
5952
5823
|
function isCreateOp(op) {
|
|
5953
|
-
return op.type === OpCode.CREATE_OBJECT || op.type === OpCode.CREATE_REGISTER || op.type === OpCode.
|
|
5824
|
+
return op.type === OpCode.CREATE_OBJECT || op.type === OpCode.CREATE_REGISTER || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_LIST;
|
|
5954
5825
|
}
|
|
5955
5826
|
|
|
5956
5827
|
// src/protocol/StorageNode.ts
|
|
@@ -5958,9 +5829,7 @@ var CrdtType = Object.freeze({
|
|
|
5958
5829
|
OBJECT: 0,
|
|
5959
5830
|
LIST: 1,
|
|
5960
5831
|
MAP: 2,
|
|
5961
|
-
REGISTER: 3
|
|
5962
|
-
// 4 is reserved for the parallel LiveText work.
|
|
5963
|
-
FILE: 5
|
|
5832
|
+
REGISTER: 3
|
|
5964
5833
|
});
|
|
5965
5834
|
function isRootStorageNode(node) {
|
|
5966
5835
|
return node[0] === "root";
|
|
@@ -5977,9 +5846,6 @@ function isMapStorageNode(node) {
|
|
|
5977
5846
|
function isRegisterStorageNode(node) {
|
|
5978
5847
|
return node[1].type === CrdtType.REGISTER;
|
|
5979
5848
|
}
|
|
5980
|
-
function isFileStorageNode(node) {
|
|
5981
|
-
return node[1].type === CrdtType.FILE;
|
|
5982
|
-
}
|
|
5983
5849
|
function isCompactRootNode(node) {
|
|
5984
5850
|
return node[0] === "root";
|
|
5985
5851
|
}
|
|
@@ -6002,9 +5868,6 @@ function* compactNodesToNodeStream(compactNodes) {
|
|
|
6002
5868
|
case CrdtType.REGISTER:
|
|
6003
5869
|
yield [cnode[0], { type: CrdtType.REGISTER, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
6004
5870
|
break;
|
|
6005
|
-
case CrdtType.FILE:
|
|
6006
|
-
yield [cnode[0], { type: CrdtType.FILE, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
6007
|
-
break;
|
|
6008
5871
|
default:
|
|
6009
5872
|
}
|
|
6010
5873
|
}
|
|
@@ -6033,10 +5896,6 @@ function* nodeStreamToCompactNodes(nodes) {
|
|
|
6033
5896
|
const id = node[0];
|
|
6034
5897
|
const crdt = node[1];
|
|
6035
5898
|
yield [id, CrdtType.REGISTER, crdt.parentId, crdt.parentKey, crdt.data];
|
|
6036
|
-
} else if (isFileStorageNode(node)) {
|
|
6037
|
-
const id = node[0];
|
|
6038
|
-
const crdt = node[1];
|
|
6039
|
-
yield [id, CrdtType.FILE, crdt.parentId, crdt.parentKey, crdt.data];
|
|
6040
5899
|
} else {
|
|
6041
5900
|
}
|
|
6042
5901
|
}
|
|
@@ -6549,91 +6408,6 @@ var AbstractCrdt = class {
|
|
|
6549
6408
|
}
|
|
6550
6409
|
};
|
|
6551
6410
|
|
|
6552
|
-
// src/crdts/LiveFile.ts
|
|
6553
|
-
var LiveFile = class _LiveFile extends AbstractCrdt {
|
|
6554
|
-
#data;
|
|
6555
|
-
constructor(data) {
|
|
6556
|
-
super();
|
|
6557
|
-
this.#data = Object.freeze({ ...data });
|
|
6558
|
-
}
|
|
6559
|
-
get data() {
|
|
6560
|
-
return this.#data;
|
|
6561
|
-
}
|
|
6562
|
-
get id() {
|
|
6563
|
-
return this.#data.id;
|
|
6564
|
-
}
|
|
6565
|
-
get name() {
|
|
6566
|
-
return this.#data.name;
|
|
6567
|
-
}
|
|
6568
|
-
get size() {
|
|
6569
|
-
return this.#data.size;
|
|
6570
|
-
}
|
|
6571
|
-
get mimeType() {
|
|
6572
|
-
return this.#data.mimeType;
|
|
6573
|
-
}
|
|
6574
|
-
/** @internal */
|
|
6575
|
-
static _deserialize([id, item], _parentToChildren, pool) {
|
|
6576
|
-
const file = new _LiveFile(item.data);
|
|
6577
|
-
file._attach(id, pool);
|
|
6578
|
-
return file;
|
|
6579
|
-
}
|
|
6580
|
-
/** @internal */
|
|
6581
|
-
_toOps(parentId, parentKey) {
|
|
6582
|
-
if (this._id === void 0) {
|
|
6583
|
-
throw new Error("Cannot serialize LiveFile if parent is missing");
|
|
6584
|
-
}
|
|
6585
|
-
return [
|
|
6586
|
-
{
|
|
6587
|
-
type: OpCode.CREATE_FILE,
|
|
6588
|
-
id: this._id,
|
|
6589
|
-
parentId,
|
|
6590
|
-
parentKey,
|
|
6591
|
-
data: this.#data
|
|
6592
|
-
}
|
|
6593
|
-
];
|
|
6594
|
-
}
|
|
6595
|
-
/** @internal */
|
|
6596
|
-
_serialize() {
|
|
6597
|
-
if (this.parent.type !== "HasParent") {
|
|
6598
|
-
throw new Error("Cannot serialize LiveFile if parent is missing");
|
|
6599
|
-
}
|
|
6600
|
-
return {
|
|
6601
|
-
type: CrdtType.FILE,
|
|
6602
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
6603
|
-
parentKey: this.parent.key,
|
|
6604
|
-
data: this.#data
|
|
6605
|
-
};
|
|
6606
|
-
}
|
|
6607
|
-
/** @internal */
|
|
6608
|
-
_attachChild(_op) {
|
|
6609
|
-
throw new Error("Method not implemented.");
|
|
6610
|
-
}
|
|
6611
|
-
/** @internal */
|
|
6612
|
-
_detachChild(_crdt) {
|
|
6613
|
-
throw new Error("Method not implemented.");
|
|
6614
|
-
}
|
|
6615
|
-
/** @internal */
|
|
6616
|
-
_apply(op, isLocal) {
|
|
6617
|
-
return super._apply(op, isLocal);
|
|
6618
|
-
}
|
|
6619
|
-
/** @internal */
|
|
6620
|
-
_toTreeNode(key) {
|
|
6621
|
-
return {
|
|
6622
|
-
type: "Json",
|
|
6623
|
-
id: this._id ?? nanoid(),
|
|
6624
|
-
key,
|
|
6625
|
-
payload: this.#data
|
|
6626
|
-
};
|
|
6627
|
-
}
|
|
6628
|
-
/** @internal */
|
|
6629
|
-
_toJSON() {
|
|
6630
|
-
return this.#data;
|
|
6631
|
-
}
|
|
6632
|
-
clone() {
|
|
6633
|
-
return new _LiveFile(this.#data);
|
|
6634
|
-
}
|
|
6635
|
-
};
|
|
6636
|
-
|
|
6637
6411
|
// src/crdts/LiveRegister.ts
|
|
6638
6412
|
var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
6639
6413
|
#data;
|
|
@@ -8990,8 +8764,6 @@ function creationOpToLiveNode(op) {
|
|
|
8990
8764
|
}
|
|
8991
8765
|
function creationOpToLson(op) {
|
|
8992
8766
|
switch (op.type) {
|
|
8993
|
-
case OpCode.CREATE_FILE:
|
|
8994
|
-
return new LiveFile(op.data);
|
|
8995
8767
|
case OpCode.CREATE_REGISTER:
|
|
8996
8768
|
return op.data;
|
|
8997
8769
|
case OpCode.CREATE_OBJECT:
|
|
@@ -9022,8 +8794,6 @@ function deserialize(node, parentToChildren, pool) {
|
|
|
9022
8794
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9023
8795
|
} else if (isRegisterStorageNode(node)) {
|
|
9024
8796
|
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
9025
|
-
} else if (isFileStorageNode(node)) {
|
|
9026
|
-
return LiveFile._deserialize(node, parentToChildren, pool);
|
|
9027
8797
|
} else {
|
|
9028
8798
|
throw new Error("Unexpected CRDT type");
|
|
9029
8799
|
}
|
|
@@ -9037,14 +8807,12 @@ function deserializeToLson(node, parentToChildren, pool) {
|
|
|
9037
8807
|
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
9038
8808
|
} else if (isRegisterStorageNode(node)) {
|
|
9039
8809
|
return node[1].data;
|
|
9040
|
-
} else if (isFileStorageNode(node)) {
|
|
9041
|
-
return LiveFile._deserialize(node, parentToChildren, pool);
|
|
9042
8810
|
} else {
|
|
9043
8811
|
throw new Error("Unexpected CRDT type");
|
|
9044
8812
|
}
|
|
9045
8813
|
}
|
|
9046
8814
|
function isLiveStructure(value) {
|
|
9047
|
-
return isLiveList(value) || isLiveMap(value) || isLiveObject(value)
|
|
8815
|
+
return isLiveList(value) || isLiveMap(value) || isLiveObject(value);
|
|
9048
8816
|
}
|
|
9049
8817
|
function isLiveNode(value) {
|
|
9050
8818
|
return isLiveStructure(value) || isLiveRegister(value);
|
|
@@ -9058,9 +8826,6 @@ function isLiveMap(value) {
|
|
|
9058
8826
|
function isLiveObject(value) {
|
|
9059
8827
|
return value instanceof LiveObject;
|
|
9060
8828
|
}
|
|
9061
|
-
function isLiveFile(value) {
|
|
9062
|
-
return value instanceof LiveFile;
|
|
9063
|
-
}
|
|
9064
8829
|
function isLiveRegister(value) {
|
|
9065
8830
|
return value instanceof LiveRegister;
|
|
9066
8831
|
}
|
|
@@ -9070,14 +8835,14 @@ function cloneLson(value) {
|
|
|
9070
8835
|
function liveNodeToLson(obj) {
|
|
9071
8836
|
if (obj instanceof LiveRegister) {
|
|
9072
8837
|
return obj.data;
|
|
9073
|
-
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject
|
|
8838
|
+
} else if (obj instanceof LiveList || obj instanceof LiveMap || obj instanceof LiveObject) {
|
|
9074
8839
|
return obj;
|
|
9075
8840
|
} else {
|
|
9076
8841
|
return assertNever(obj, "Unknown AbstractCrdt");
|
|
9077
8842
|
}
|
|
9078
8843
|
}
|
|
9079
8844
|
function lsonToLiveNode(value) {
|
|
9080
|
-
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList
|
|
8845
|
+
if (value instanceof LiveObject || value instanceof LiveMap || value instanceof LiveList) {
|
|
9081
8846
|
return value;
|
|
9082
8847
|
} else {
|
|
9083
8848
|
return new LiveRegister(value);
|
|
@@ -9094,8 +8859,6 @@ function dumpPool(pool) {
|
|
|
9094
8859
|
value = "<LiveList>";
|
|
9095
8860
|
} else if (node instanceof LiveMap) {
|
|
9096
8861
|
value = "<LiveMap>";
|
|
9097
|
-
} else if (node instanceof LiveFile) {
|
|
9098
|
-
value = stringifyOrLog(node.data);
|
|
9099
8862
|
} else {
|
|
9100
8863
|
value = "<LiveObject>";
|
|
9101
8864
|
}
|
|
@@ -9192,15 +8955,6 @@ function diffNodeMap(prev, next) {
|
|
|
9192
8955
|
data: crdt.data
|
|
9193
8956
|
});
|
|
9194
8957
|
break;
|
|
9195
|
-
case CrdtType.FILE:
|
|
9196
|
-
ops.push({
|
|
9197
|
-
type: OpCode.CREATE_FILE,
|
|
9198
|
-
id,
|
|
9199
|
-
parentId: crdt.parentId,
|
|
9200
|
-
parentKey: crdt.parentKey,
|
|
9201
|
-
data: crdt.data
|
|
9202
|
-
});
|
|
9203
|
-
break;
|
|
9204
8958
|
case CrdtType.LIST:
|
|
9205
8959
|
ops.push({
|
|
9206
8960
|
type: OpCode.CREATE_LIST,
|
|
@@ -10098,9 +9852,6 @@ function defaultMessageFromContext(context) {
|
|
|
10098
9852
|
|
|
10099
9853
|
// src/room.ts
|
|
10100
9854
|
var FEEDS_TIMEOUT = 5e3;
|
|
10101
|
-
function getLiveFileId(file) {
|
|
10102
|
-
return typeof file === "string" ? file : file.id;
|
|
10103
|
-
}
|
|
10104
9855
|
function connectionAccessFromScopes(scopes) {
|
|
10105
9856
|
const roomPermissions = normalizeRoomPermissions(scopes);
|
|
10106
9857
|
const matrix = permissionMatrixFromScopes(roomPermissions);
|
|
@@ -10590,7 +10341,7 @@ function createRoom(options, config) {
|
|
|
10590
10341
|
);
|
|
10591
10342
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
10592
10343
|
}
|
|
10593
|
-
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT
|
|
10344
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
10594
10345
|
createdNodeIds.add(op.id);
|
|
10595
10346
|
}
|
|
10596
10347
|
}
|
|
@@ -10634,7 +10385,6 @@ function createRoom(options, config) {
|
|
|
10634
10385
|
case OpCode.CREATE_OBJECT:
|
|
10635
10386
|
case OpCode.CREATE_LIST:
|
|
10636
10387
|
case OpCode.CREATE_MAP:
|
|
10637
|
-
case OpCode.CREATE_FILE:
|
|
10638
10388
|
case OpCode.CREATE_REGISTER: {
|
|
10639
10389
|
if (op.parentId === void 0) {
|
|
10640
10390
|
return { modified: false };
|
|
@@ -11738,17 +11488,6 @@ function createRoom(options, config) {
|
|
|
11738
11488
|
function getAttachmentUrl(attachmentId) {
|
|
11739
11489
|
return httpClient.getAttachmentUrl({ roomId, attachmentId });
|
|
11740
11490
|
}
|
|
11741
|
-
async function uploadFile(file, options2 = {}) {
|
|
11742
|
-
const data = await httpClient.uploadFile({
|
|
11743
|
-
roomId,
|
|
11744
|
-
file,
|
|
11745
|
-
signal: options2.signal
|
|
11746
|
-
});
|
|
11747
|
-
return new LiveFile(data);
|
|
11748
|
-
}
|
|
11749
|
-
function getFileUrl(file) {
|
|
11750
|
-
return httpClient.getFileUrl({ roomId, fileId: getLiveFileId(file) });
|
|
11751
|
-
}
|
|
11752
11491
|
function getSubscriptionSettings(options2) {
|
|
11753
11492
|
return httpClient.getSubscriptionSettings({
|
|
11754
11493
|
roomId,
|
|
@@ -11822,8 +11561,7 @@ function createRoom(options, config) {
|
|
|
11822
11561
|
rawSend: (data) => managedSocket.send(data),
|
|
11823
11562
|
incomingMessage: (data) => handleServerMessage(new MessageEvent("message", { data }))
|
|
11824
11563
|
},
|
|
11825
|
-
attachmentUrlsStore: httpClient.getOrCreateAttachmentUrlsStore(roomId)
|
|
11826
|
-
fileUrlsStore: httpClient.getOrCreateFileUrlsStore(roomId)
|
|
11564
|
+
attachmentUrlsStore: httpClient.getOrCreateAttachmentUrlsStore(roomId)
|
|
11827
11565
|
},
|
|
11828
11566
|
id: roomId,
|
|
11829
11567
|
subscribe: makeClassicSubscribeFn(
|
|
@@ -11921,8 +11659,6 @@ ${dumpPool(
|
|
|
11921
11659
|
prepareAttachment,
|
|
11922
11660
|
uploadAttachment,
|
|
11923
11661
|
getAttachmentUrl,
|
|
11924
|
-
uploadFile,
|
|
11925
|
-
getFileUrl,
|
|
11926
11662
|
// Notifications
|
|
11927
11663
|
getNotificationSettings: getSubscriptionSettings,
|
|
11928
11664
|
getSubscriptionSettings,
|
|
@@ -12808,11 +12544,6 @@ function toPlainLson(lson) {
|
|
|
12808
12544
|
liveblocksType: "LiveList",
|
|
12809
12545
|
data: [...lson].map((item) => toPlainLson(item))
|
|
12810
12546
|
};
|
|
12811
|
-
} else if (lson instanceof LiveFile) {
|
|
12812
|
-
return {
|
|
12813
|
-
liveblocksType: "LiveFile",
|
|
12814
|
-
data: lson.data
|
|
12815
|
-
};
|
|
12816
12547
|
} else {
|
|
12817
12548
|
return lson;
|
|
12818
12549
|
}
|
|
@@ -12991,7 +12722,6 @@ export {
|
|
|
12991
12722
|
DerivedSignal,
|
|
12992
12723
|
FeedRequestErrorCode,
|
|
12993
12724
|
HttpError,
|
|
12994
|
-
LiveFile,
|
|
12995
12725
|
LiveList,
|
|
12996
12726
|
LiveMap,
|
|
12997
12727
|
LiveObject,
|
|
@@ -13031,7 +12761,6 @@ export {
|
|
|
13031
12761
|
createInboxNotificationId,
|
|
13032
12762
|
createManagedPool,
|
|
13033
12763
|
createNotificationSettings,
|
|
13034
|
-
createStorageFileId,
|
|
13035
12764
|
createThreadId,
|
|
13036
12765
|
deepLiveify,
|
|
13037
12766
|
defineAiTool,
|
|
@@ -13051,7 +12780,6 @@ export {
|
|
|
13051
12780
|
isCommentBodyLink,
|
|
13052
12781
|
isCommentBodyMention,
|
|
13053
12782
|
isCommentBodyText,
|
|
13054
|
-
isFileStorageNode,
|
|
13055
12783
|
isJsonArray,
|
|
13056
12784
|
isJsonObject,
|
|
13057
12785
|
isJsonScalar,
|