@liveblocks/core 2.7.2 → 2.8.0-beta2
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.d.mts +117 -24
- package/dist/index.d.ts +117 -24
- package/dist/index.js +261 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +236 -13
- package/dist/index.mjs.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 = "2.
|
|
9
|
+
var PKG_VERSION = "2.8.0-beta2";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -1871,8 +1871,7 @@ var Batch = class {
|
|
|
1871
1871
|
this.clearDelayTimeout();
|
|
1872
1872
|
}
|
|
1873
1873
|
};
|
|
1874
|
-
function createBatchStore(
|
|
1875
|
-
const batch = new Batch(callback, options);
|
|
1874
|
+
function createBatchStore(batch) {
|
|
1876
1875
|
const cache = /* @__PURE__ */ new Map();
|
|
1877
1876
|
const eventSource2 = makeEventSource();
|
|
1878
1877
|
function getCacheKey(args) {
|
|
@@ -4796,9 +4795,41 @@ function findNonSerializableValue(value, path = "") {
|
|
|
4796
4795
|
return false;
|
|
4797
4796
|
}
|
|
4798
4797
|
|
|
4798
|
+
// src/lib/autoRetry.ts
|
|
4799
|
+
async function autoRetry(promiseFn, maxTries, backoff, exitCondition) {
|
|
4800
|
+
const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
|
|
4801
|
+
let attempt = 0;
|
|
4802
|
+
while (true) {
|
|
4803
|
+
attempt++;
|
|
4804
|
+
const promise = promiseFn();
|
|
4805
|
+
try {
|
|
4806
|
+
return await promise;
|
|
4807
|
+
} catch (err) {
|
|
4808
|
+
if (exitCondition && exitCondition(err)) {
|
|
4809
|
+
throw err;
|
|
4810
|
+
}
|
|
4811
|
+
if (attempt >= maxTries) {
|
|
4812
|
+
throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
const delay = _nullishCoalesce(backoff[attempt - 1], () => ( fallbackBackoff));
|
|
4816
|
+
await wait(delay);
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
|
|
4820
|
+
// src/lib/chunk.ts
|
|
4821
|
+
function chunk(array, size) {
|
|
4822
|
+
const chunks = [];
|
|
4823
|
+
for (let i = 0, j = array.length; i < j; i += size) {
|
|
4824
|
+
chunks.push(array.slice(i, i + size));
|
|
4825
|
+
}
|
|
4826
|
+
return chunks;
|
|
4827
|
+
}
|
|
4828
|
+
|
|
4799
4829
|
// src/lib/createIds.ts
|
|
4800
4830
|
var THREAD_ID_PREFIX = "th";
|
|
4801
4831
|
var COMMENT_ID_PREFIX = "cm";
|
|
4832
|
+
var COMMENT_ATTACHMENT_ID_PREFIX = "at";
|
|
4802
4833
|
var INBOX_NOTIFICATION_ID_PREFIX = "in";
|
|
4803
4834
|
function createOptimisticId(prefix) {
|
|
4804
4835
|
return `${prefix}_${nanoid()}`;
|
|
@@ -4809,6 +4840,9 @@ function createThreadId() {
|
|
|
4809
4840
|
function createCommentId() {
|
|
4810
4841
|
return createOptimisticId(COMMENT_ID_PREFIX);
|
|
4811
4842
|
}
|
|
4843
|
+
function createCommentAttachmentId() {
|
|
4844
|
+
return createOptimisticId(COMMENT_ATTACHMENT_ID_PREFIX);
|
|
4845
|
+
}
|
|
4812
4846
|
function createInboxNotificationId() {
|
|
4813
4847
|
return createOptimisticId(INBOX_NOTIFICATION_ID_PREFIX);
|
|
4814
4848
|
}
|
|
@@ -5211,6 +5245,22 @@ function installBackgroundTabSpy() {
|
|
|
5211
5245
|
};
|
|
5212
5246
|
return [inBackgroundSince, unsub];
|
|
5213
5247
|
}
|
|
5248
|
+
var GET_ATTACHMENT_URLS_BATCH_DELAY = 50;
|
|
5249
|
+
var ATTACHMENT_PART_SIZE = 5 * 1024 * 1024;
|
|
5250
|
+
var ATTACHMENT_PART_BATCH_SIZE = 5;
|
|
5251
|
+
function splitFileIntoParts(file) {
|
|
5252
|
+
const parts = [];
|
|
5253
|
+
let start = 0;
|
|
5254
|
+
while (start < file.size) {
|
|
5255
|
+
const end = Math.min(start + ATTACHMENT_PART_SIZE, file.size);
|
|
5256
|
+
parts.push({
|
|
5257
|
+
partNumber: parts.length + 1,
|
|
5258
|
+
part: file.slice(start, end)
|
|
5259
|
+
});
|
|
5260
|
+
start = end;
|
|
5261
|
+
}
|
|
5262
|
+
return parts;
|
|
5263
|
+
}
|
|
5214
5264
|
var CommentsApiError = class extends Error {
|
|
5215
5265
|
constructor(message, status, details) {
|
|
5216
5266
|
super(message);
|
|
@@ -6504,7 +6554,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6504
6554
|
metadata,
|
|
6505
6555
|
body,
|
|
6506
6556
|
commentId = createCommentId(),
|
|
6507
|
-
threadId = createThreadId()
|
|
6557
|
+
threadId = createThreadId(),
|
|
6558
|
+
attachmentIds
|
|
6508
6559
|
}) {
|
|
6509
6560
|
const thread = await fetchCommentsJson("/threads", {
|
|
6510
6561
|
method: "POST",
|
|
@@ -6515,7 +6566,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6515
6566
|
id: threadId,
|
|
6516
6567
|
comment: {
|
|
6517
6568
|
id: commentId,
|
|
6518
|
-
body
|
|
6569
|
+
body,
|
|
6570
|
+
attachmentIds
|
|
6519
6571
|
},
|
|
6520
6572
|
metadata
|
|
6521
6573
|
})
|
|
@@ -6561,7 +6613,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6561
6613
|
async function createComment({
|
|
6562
6614
|
threadId,
|
|
6563
6615
|
commentId = createCommentId(),
|
|
6564
|
-
body
|
|
6616
|
+
body,
|
|
6617
|
+
attachmentIds
|
|
6565
6618
|
}) {
|
|
6566
6619
|
const comment = await fetchCommentsJson(
|
|
6567
6620
|
`/threads/${encodeURIComponent(threadId)}/comments`,
|
|
@@ -6572,7 +6625,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6572
6625
|
},
|
|
6573
6626
|
body: JSON.stringify({
|
|
6574
6627
|
id: commentId,
|
|
6575
|
-
body
|
|
6628
|
+
body,
|
|
6629
|
+
attachmentIds
|
|
6576
6630
|
})
|
|
6577
6631
|
}
|
|
6578
6632
|
);
|
|
@@ -6581,7 +6635,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6581
6635
|
async function editComment({
|
|
6582
6636
|
threadId,
|
|
6583
6637
|
commentId,
|
|
6584
|
-
body
|
|
6638
|
+
body,
|
|
6639
|
+
attachmentIds
|
|
6585
6640
|
}) {
|
|
6586
6641
|
const comment = await fetchCommentsJson(
|
|
6587
6642
|
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
@@ -6593,7 +6648,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6593
6648
|
"Content-Type": "application/json"
|
|
6594
6649
|
},
|
|
6595
6650
|
body: JSON.stringify({
|
|
6596
|
-
body
|
|
6651
|
+
body,
|
|
6652
|
+
attachmentIds
|
|
6597
6653
|
})
|
|
6598
6654
|
}
|
|
6599
6655
|
);
|
|
@@ -6645,6 +6701,165 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6645
6701
|
}
|
|
6646
6702
|
);
|
|
6647
6703
|
}
|
|
6704
|
+
function prepareAttachment(file) {
|
|
6705
|
+
return {
|
|
6706
|
+
type: "localAttachment",
|
|
6707
|
+
status: "idle",
|
|
6708
|
+
id: createCommentAttachmentId(),
|
|
6709
|
+
name: file.name,
|
|
6710
|
+
size: file.size,
|
|
6711
|
+
mimeType: file.type,
|
|
6712
|
+
file
|
|
6713
|
+
};
|
|
6714
|
+
}
|
|
6715
|
+
async function uploadAttachment(attachment, options2 = {}) {
|
|
6716
|
+
const abortSignal = options2.signal;
|
|
6717
|
+
const abortError = abortSignal ? new DOMException(
|
|
6718
|
+
`Upload of attachment ${attachment.id} was aborted.`,
|
|
6719
|
+
"AbortError"
|
|
6720
|
+
) : void 0;
|
|
6721
|
+
if (_optionalChain([abortSignal, 'optionalAccess', _142 => _142.aborted])) {
|
|
6722
|
+
throw abortError;
|
|
6723
|
+
}
|
|
6724
|
+
if (attachment.size <= ATTACHMENT_PART_SIZE) {
|
|
6725
|
+
return autoRetry(
|
|
6726
|
+
() => fetchCommentsJson(
|
|
6727
|
+
`/attachments/${encodeURIComponent(attachment.id)}/upload/${encodeURIComponent(attachment.name)}`,
|
|
6728
|
+
{
|
|
6729
|
+
method: "PUT",
|
|
6730
|
+
body: attachment.file,
|
|
6731
|
+
signal: abortSignal
|
|
6732
|
+
},
|
|
6733
|
+
{
|
|
6734
|
+
fileSize: attachment.size
|
|
6735
|
+
}
|
|
6736
|
+
),
|
|
6737
|
+
10,
|
|
6738
|
+
[2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3],
|
|
6739
|
+
() => {
|
|
6740
|
+
if (_optionalChain([abortSignal, 'optionalAccess', _143 => _143.aborted])) {
|
|
6741
|
+
throw abortError;
|
|
6742
|
+
}
|
|
6743
|
+
return false;
|
|
6744
|
+
}
|
|
6745
|
+
);
|
|
6746
|
+
} else {
|
|
6747
|
+
let uploadId;
|
|
6748
|
+
const uploadedParts = [];
|
|
6749
|
+
const createMultiPartUpload = await autoRetry(
|
|
6750
|
+
() => fetchCommentsJson(
|
|
6751
|
+
`/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(attachment.name)}`,
|
|
6752
|
+
{
|
|
6753
|
+
method: "POST",
|
|
6754
|
+
signal: abortSignal
|
|
6755
|
+
},
|
|
6756
|
+
{
|
|
6757
|
+
fileSize: attachment.size
|
|
6758
|
+
}
|
|
6759
|
+
),
|
|
6760
|
+
10,
|
|
6761
|
+
[2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3],
|
|
6762
|
+
() => {
|
|
6763
|
+
if (_optionalChain([abortSignal, 'optionalAccess', _144 => _144.aborted])) {
|
|
6764
|
+
throw abortError;
|
|
6765
|
+
}
|
|
6766
|
+
return false;
|
|
6767
|
+
}
|
|
6768
|
+
);
|
|
6769
|
+
try {
|
|
6770
|
+
uploadId = createMultiPartUpload.uploadId;
|
|
6771
|
+
const parts = splitFileIntoParts(attachment.file);
|
|
6772
|
+
if (_optionalChain([abortSignal, 'optionalAccess', _145 => _145.aborted])) {
|
|
6773
|
+
throw abortError;
|
|
6774
|
+
}
|
|
6775
|
+
const batches = chunk(parts, ATTACHMENT_PART_BATCH_SIZE);
|
|
6776
|
+
for (const parts2 of batches) {
|
|
6777
|
+
const uploadedPartsPromises = [];
|
|
6778
|
+
for (const { part, partNumber } of parts2) {
|
|
6779
|
+
uploadedPartsPromises.push(
|
|
6780
|
+
autoRetry(
|
|
6781
|
+
() => fetchCommentsJson(
|
|
6782
|
+
`/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(createMultiPartUpload.uploadId)}/${encodeURIComponent(partNumber)}`,
|
|
6783
|
+
{
|
|
6784
|
+
method: "PUT",
|
|
6785
|
+
body: part,
|
|
6786
|
+
signal: abortSignal
|
|
6787
|
+
}
|
|
6788
|
+
),
|
|
6789
|
+
10,
|
|
6790
|
+
[2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3, 2e3],
|
|
6791
|
+
() => {
|
|
6792
|
+
if (_optionalChain([abortSignal, 'optionalAccess', _146 => _146.aborted])) {
|
|
6793
|
+
throw abortError;
|
|
6794
|
+
}
|
|
6795
|
+
return false;
|
|
6796
|
+
}
|
|
6797
|
+
)
|
|
6798
|
+
);
|
|
6799
|
+
}
|
|
6800
|
+
uploadedParts.push(...await Promise.all(uploadedPartsPromises));
|
|
6801
|
+
}
|
|
6802
|
+
if (_optionalChain([abortSignal, 'optionalAccess', _147 => _147.aborted])) {
|
|
6803
|
+
throw abortError;
|
|
6804
|
+
}
|
|
6805
|
+
const sortedUploadedParts = uploadedParts.sort(
|
|
6806
|
+
(a, b) => a.partNumber - b.partNumber
|
|
6807
|
+
);
|
|
6808
|
+
return fetchCommentsJson(
|
|
6809
|
+
`/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}/complete`,
|
|
6810
|
+
{
|
|
6811
|
+
method: "POST",
|
|
6812
|
+
headers: {
|
|
6813
|
+
"Content-Type": "application/json"
|
|
6814
|
+
},
|
|
6815
|
+
body: JSON.stringify({ parts: sortedUploadedParts }),
|
|
6816
|
+
signal: abortSignal
|
|
6817
|
+
}
|
|
6818
|
+
);
|
|
6819
|
+
} catch (error3) {
|
|
6820
|
+
if (uploadId && _optionalChain([error3, 'optionalAccess', _148 => _148.name]) && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
|
|
6821
|
+
try {
|
|
6822
|
+
await fetchCommentsApi(
|
|
6823
|
+
`/attachments/${encodeURIComponent(attachment.id)}/multipart/${encodeURIComponent(uploadId)}`,
|
|
6824
|
+
void 0,
|
|
6825
|
+
{
|
|
6826
|
+
method: "DELETE"
|
|
6827
|
+
}
|
|
6828
|
+
);
|
|
6829
|
+
} catch (error4) {
|
|
6830
|
+
}
|
|
6831
|
+
}
|
|
6832
|
+
throw error3;
|
|
6833
|
+
}
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
async function getAttachmentUrls(attachmentIds) {
|
|
6837
|
+
const { urls } = await fetchCommentsJson(
|
|
6838
|
+
"/attachments/presigned-urls",
|
|
6839
|
+
{
|
|
6840
|
+
method: "POST",
|
|
6841
|
+
headers: {
|
|
6842
|
+
"Content-Type": "application/json"
|
|
6843
|
+
},
|
|
6844
|
+
body: JSON.stringify({ attachmentIds })
|
|
6845
|
+
}
|
|
6846
|
+
);
|
|
6847
|
+
return urls;
|
|
6848
|
+
}
|
|
6849
|
+
const batchedGetAttachmentUrls = new Batch(
|
|
6850
|
+
async (batchedAttachmentIds) => {
|
|
6851
|
+
const attachmentIds = batchedAttachmentIds.flat();
|
|
6852
|
+
const attachmentUrls = await getAttachmentUrls(attachmentIds);
|
|
6853
|
+
return attachmentUrls.map(
|
|
6854
|
+
(url) => _nullishCoalesce(url, () => ( new Error("There was an error while getting this attachment's URL")))
|
|
6855
|
+
);
|
|
6856
|
+
},
|
|
6857
|
+
{ delay: GET_ATTACHMENT_URLS_BATCH_DELAY }
|
|
6858
|
+
);
|
|
6859
|
+
const attachmentUrlsStore = createBatchStore(batchedGetAttachmentUrls);
|
|
6860
|
+
function getAttachmentUrl(attachmentId) {
|
|
6861
|
+
return batchedGetAttachmentUrls.get(attachmentId);
|
|
6862
|
+
}
|
|
6648
6863
|
async function fetchNotificationsJson(endpoint, options2) {
|
|
6649
6864
|
const authValue = await delegates.authenticate();
|
|
6650
6865
|
const response = await fetchClientApi(
|
|
@@ -6721,7 +6936,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6721
6936
|
{
|
|
6722
6937
|
[kInternal]: {
|
|
6723
6938
|
get presenceBuffer() {
|
|
6724
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
6939
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _149 => _149.buffer, 'access', _150 => _150.presenceUpdates, 'optionalAccess', _151 => _151.data]), () => ( null)));
|
|
6725
6940
|
},
|
|
6726
6941
|
// prettier-ignore
|
|
6727
6942
|
get undoStack() {
|
|
@@ -6760,7 +6975,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6760
6975
|
// These exist only for our E2E testing app
|
|
6761
6976
|
explicitClose: (event) => managedSocket._privateSendMachineEvent({ type: "EXPLICIT_SOCKET_CLOSE", event }),
|
|
6762
6977
|
rawSend: (data) => managedSocket.send(data)
|
|
6763
|
-
}
|
|
6978
|
+
},
|
|
6979
|
+
attachmentUrlsStore
|
|
6764
6980
|
},
|
|
6765
6981
|
id: config.roomId,
|
|
6766
6982
|
subscribe: makeClassicSubscribeFn(events),
|
|
@@ -6815,6 +7031,9 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6815
7031
|
deleteComment,
|
|
6816
7032
|
addReaction,
|
|
6817
7033
|
removeReaction,
|
|
7034
|
+
prepareAttachment,
|
|
7035
|
+
uploadAttachment,
|
|
7036
|
+
getAttachmentUrl,
|
|
6818
7037
|
// Notifications
|
|
6819
7038
|
getNotificationSettings,
|
|
6820
7039
|
updateNotificationSettings,
|
|
@@ -6901,7 +7120,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
6901
7120
|
}
|
|
6902
7121
|
if (isLiveNode(first)) {
|
|
6903
7122
|
const node = first;
|
|
6904
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
7123
|
+
if (_optionalChain([options, 'optionalAccess', _152 => _152.isDeep])) {
|
|
6905
7124
|
const storageCallback = second;
|
|
6906
7125
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
6907
7126
|
} else {
|
|
@@ -7028,12 +7247,12 @@ function createClient(options) {
|
|
|
7028
7247
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
7029
7248
|
roomId,
|
|
7030
7249
|
baseUrl,
|
|
7031
|
-
_optionalChain([clientOptions, 'access',
|
|
7250
|
+
_optionalChain([clientOptions, 'access', _153 => _153.polyfills, 'optionalAccess', _154 => _154.WebSocket])
|
|
7032
7251
|
),
|
|
7033
7252
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
7034
7253
|
})),
|
|
7035
7254
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
7036
|
-
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess',
|
|
7255
|
+
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _155 => _155.unstable_batchedUpdates]),
|
|
7037
7256
|
baseUrl,
|
|
7038
7257
|
unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
|
|
7039
7258
|
unstable_streamData: !!clientOptions.unstable_streamData
|
|
@@ -7049,7 +7268,7 @@ function createClient(options) {
|
|
|
7049
7268
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
7050
7269
|
if (shouldConnect) {
|
|
7051
7270
|
if (typeof atob === "undefined") {
|
|
7052
|
-
if (_optionalChain([clientOptions, 'access',
|
|
7271
|
+
if (_optionalChain([clientOptions, 'access', _156 => _156.polyfills, 'optionalAccess', _157 => _157.atob]) === void 0) {
|
|
7053
7272
|
throw new Error(
|
|
7054
7273
|
"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"
|
|
7055
7274
|
);
|
|
@@ -7061,7 +7280,7 @@ function createClient(options) {
|
|
|
7061
7280
|
return leaseRoom(newRoomDetails);
|
|
7062
7281
|
}
|
|
7063
7282
|
function getRoom(roomId) {
|
|
7064
|
-
const room = _optionalChain([roomsById, 'access',
|
|
7283
|
+
const room = _optionalChain([roomsById, 'access', _158 => _158.get, 'call', _159 => _159(roomId), 'optionalAccess', _160 => _160.room]);
|
|
7065
7284
|
return room ? room : null;
|
|
7066
7285
|
}
|
|
7067
7286
|
function logout() {
|
|
@@ -7085,7 +7304,7 @@ function createClient(options) {
|
|
|
7085
7304
|
getThreadsSince
|
|
7086
7305
|
} = createNotificationsApi({
|
|
7087
7306
|
baseUrl,
|
|
7088
|
-
fetcher: _optionalChain([clientOptions, 'access',
|
|
7307
|
+
fetcher: _optionalChain([clientOptions, 'access', _161 => _161.polyfills, 'optionalAccess', _162 => _162.fetch]) || /* istanbul ignore next */
|
|
7089
7308
|
fetch,
|
|
7090
7309
|
authManager,
|
|
7091
7310
|
currentUserIdStore
|
|
@@ -7095,29 +7314,31 @@ function createClient(options) {
|
|
|
7095
7314
|
() => !resolveUsers,
|
|
7096
7315
|
"Set the resolveUsers option in createClient to specify user info."
|
|
7097
7316
|
);
|
|
7098
|
-
const
|
|
7317
|
+
const batchedResolveUsers = new Batch(
|
|
7099
7318
|
async (batchedUserIds) => {
|
|
7100
7319
|
const userIds = batchedUserIds.flat();
|
|
7101
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
7320
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _163 => _163({ userIds })]);
|
|
7102
7321
|
warnIfNoResolveUsers();
|
|
7103
7322
|
return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
|
|
7104
7323
|
},
|
|
7105
7324
|
{ delay: RESOLVE_USERS_BATCH_DELAY }
|
|
7106
7325
|
);
|
|
7326
|
+
const usersStore = createBatchStore(batchedResolveUsers);
|
|
7107
7327
|
const resolveRoomsInfo = clientOptions.resolveRoomsInfo;
|
|
7108
7328
|
const warnIfNoResolveRoomsInfo = createDevelopmentWarning(
|
|
7109
7329
|
() => !resolveRoomsInfo,
|
|
7110
7330
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
7111
7331
|
);
|
|
7112
|
-
const
|
|
7332
|
+
const batchedResolveRoomsInfo = new Batch(
|
|
7113
7333
|
async (batchedRoomIds) => {
|
|
7114
7334
|
const roomIds = batchedRoomIds.flat();
|
|
7115
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
7335
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _164 => _164({ roomIds })]);
|
|
7116
7336
|
warnIfNoResolveRoomsInfo();
|
|
7117
7337
|
return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
|
|
7118
7338
|
},
|
|
7119
7339
|
{ delay: RESOLVE_ROOMS_INFO_BATCH_DELAY }
|
|
7120
7340
|
);
|
|
7341
|
+
const roomsInfoStore = createBatchStore(batchedResolveRoomsInfo);
|
|
7121
7342
|
return Object.defineProperty(
|
|
7122
7343
|
{
|
|
7123
7344
|
enterRoom,
|
|
@@ -7203,7 +7424,7 @@ function createDevelopmentWarning(condition, ...args) {
|
|
|
7203
7424
|
|
|
7204
7425
|
// src/comments/comment-body.ts
|
|
7205
7426
|
function isCommentBodyParagraph(element) {
|
|
7206
|
-
return "type" in element && element.type === "
|
|
7427
|
+
return "type" in element && element.type === "mention";
|
|
7207
7428
|
}
|
|
7208
7429
|
function isCommentBodyText(element) {
|
|
7209
7430
|
return !("type" in element) && "text" in element && typeof element.text === "string";
|
|
@@ -7227,7 +7448,7 @@ var commentBodyElementsTypes = {
|
|
|
7227
7448
|
mention: "inline"
|
|
7228
7449
|
};
|
|
7229
7450
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
7230
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
7451
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _165 => _165.content])) {
|
|
7231
7452
|
return;
|
|
7232
7453
|
}
|
|
7233
7454
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -7237,13 +7458,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
7237
7458
|
for (const block of body.content) {
|
|
7238
7459
|
if (type === "all" || type === "block") {
|
|
7239
7460
|
if (guard(block)) {
|
|
7240
|
-
_optionalChain([visitor, 'optionalCall',
|
|
7461
|
+
_optionalChain([visitor, 'optionalCall', _166 => _166(block)]);
|
|
7241
7462
|
}
|
|
7242
7463
|
}
|
|
7243
7464
|
if (type === "all" || type === "inline") {
|
|
7244
7465
|
for (const inline of block.children) {
|
|
7245
7466
|
if (guard(inline)) {
|
|
7246
|
-
_optionalChain([visitor, 'optionalCall',
|
|
7467
|
+
_optionalChain([visitor, 'optionalCall', _167 => _167(inline)]);
|
|
7247
7468
|
}
|
|
7248
7469
|
}
|
|
7249
7470
|
}
|
|
@@ -7268,7 +7489,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
|
7268
7489
|
userIds
|
|
7269
7490
|
});
|
|
7270
7491
|
for (const [index, userId] of userIds.entries()) {
|
|
7271
|
-
const user = _optionalChain([users, 'optionalAccess',
|
|
7492
|
+
const user = _optionalChain([users, 'optionalAccess', _168 => _168[index]]);
|
|
7272
7493
|
if (user) {
|
|
7273
7494
|
resolvedUsers.set(userId, user);
|
|
7274
7495
|
}
|
|
@@ -7391,7 +7612,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
7391
7612
|
text: ({ element }) => element.text,
|
|
7392
7613
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
7393
7614
|
mention: ({ element, user }) => {
|
|
7394
|
-
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
7615
|
+
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _169 => _169.name]), () => ( element.id))}`;
|
|
7395
7616
|
}
|
|
7396
7617
|
};
|
|
7397
7618
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -7421,7 +7642,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
7421
7642
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${_nullishCoalesce(element.text, () => ( element.url))}</a>`;
|
|
7422
7643
|
},
|
|
7423
7644
|
mention: ({ element, user }) => {
|
|
7424
|
-
return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
7645
|
+
return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _170 => _170.name]), () => ( element.id))}</span>`;
|
|
7425
7646
|
}
|
|
7426
7647
|
};
|
|
7427
7648
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -7451,19 +7672,19 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
7451
7672
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
7452
7673
|
},
|
|
7453
7674
|
mention: ({ element, user }) => {
|
|
7454
|
-
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
7675
|
+
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _171 => _171.name]), () => ( element.id))}`;
|
|
7455
7676
|
}
|
|
7456
7677
|
};
|
|
7457
7678
|
async function stringifyCommentBody(body, options) {
|
|
7458
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7459
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7679
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _172 => _172.format]), () => ( "plain"));
|
|
7680
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _173 => _173.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
7460
7681
|
const elements = {
|
|
7461
7682
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
7462
|
-
..._optionalChain([options, 'optionalAccess',
|
|
7683
|
+
..._optionalChain([options, 'optionalAccess', _174 => _174.elements])
|
|
7463
7684
|
};
|
|
7464
7685
|
const resolvedUsers = await resolveUsersInCommentBody(
|
|
7465
7686
|
body,
|
|
7466
|
-
_optionalChain([options, 'optionalAccess',
|
|
7687
|
+
_optionalChain([options, 'optionalAccess', _175 => _175.resolveUsers])
|
|
7467
7688
|
);
|
|
7468
7689
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
7469
7690
|
switch (block.type) {
|
|
@@ -7738,12 +7959,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
7738
7959
|
}
|
|
7739
7960
|
const newState = Object.assign({}, state);
|
|
7740
7961
|
for (const key in update.updates) {
|
|
7741
|
-
if (_optionalChain([update, 'access',
|
|
7962
|
+
if (_optionalChain([update, 'access', _176 => _176.updates, 'access', _177 => _177[key], 'optionalAccess', _178 => _178.type]) === "update") {
|
|
7742
7963
|
const val = update.node.get(key);
|
|
7743
7964
|
if (val !== void 0) {
|
|
7744
7965
|
newState[key] = lsonToJson(val);
|
|
7745
7966
|
}
|
|
7746
|
-
} else if (_optionalChain([update, 'access',
|
|
7967
|
+
} else if (_optionalChain([update, 'access', _179 => _179.updates, 'access', _180 => _180[key], 'optionalAccess', _181 => _181.type]) === "delete") {
|
|
7747
7968
|
delete newState[key];
|
|
7748
7969
|
}
|
|
7749
7970
|
}
|
|
@@ -7804,12 +8025,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
7804
8025
|
}
|
|
7805
8026
|
const newState = Object.assign({}, state);
|
|
7806
8027
|
for (const key in update.updates) {
|
|
7807
|
-
if (_optionalChain([update, 'access',
|
|
8028
|
+
if (_optionalChain([update, 'access', _182 => _182.updates, 'access', _183 => _183[key], 'optionalAccess', _184 => _184.type]) === "update") {
|
|
7808
8029
|
const value = update.node.get(key);
|
|
7809
8030
|
if (value !== void 0) {
|
|
7810
8031
|
newState[key] = lsonToJson(value);
|
|
7811
8032
|
}
|
|
7812
|
-
} else if (_optionalChain([update, 'access',
|
|
8033
|
+
} else if (_optionalChain([update, 'access', _185 => _185.updates, 'access', _186 => _186[key], 'optionalAccess', _187 => _187.type]) === "delete") {
|
|
7813
8034
|
delete newState[key];
|
|
7814
8035
|
}
|
|
7815
8036
|
}
|
|
@@ -8066,5 +8287,7 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
8066
8287
|
|
|
8067
8288
|
|
|
8068
8289
|
|
|
8069
|
-
|
|
8290
|
+
|
|
8291
|
+
|
|
8292
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createStore = createStore; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.kInternal = kInternal; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.wait = wait; exports.withTimeout = withTimeout;
|
|
8070
8293
|
//# sourceMappingURL=index.js.map
|