@liveblocks/core 2.5.1 → 2.6.0
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 +168 -170
- package/dist/index.d.ts +168 -170
- package/dist/index.js +412 -420
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +403 -411
- 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.6.0";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -5172,297 +5172,6 @@ var CommentsApiError = class extends Error {
|
|
|
5172
5172
|
this.details = details;
|
|
5173
5173
|
}
|
|
5174
5174
|
};
|
|
5175
|
-
function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
|
|
5176
|
-
async function fetchCommentsApi(endpoint, params, options) {
|
|
5177
|
-
const authValue = await getAuthValue();
|
|
5178
|
-
return fetchClientApi(roomId, endpoint, authValue, options, params);
|
|
5179
|
-
}
|
|
5180
|
-
async function fetchJson(endpoint, options, params) {
|
|
5181
|
-
const response = await fetchCommentsApi(endpoint, params, options);
|
|
5182
|
-
if (!response.ok) {
|
|
5183
|
-
if (response.status >= 400 && response.status < 600) {
|
|
5184
|
-
let error3;
|
|
5185
|
-
try {
|
|
5186
|
-
const errorBody = await response.json();
|
|
5187
|
-
error3 = new CommentsApiError(
|
|
5188
|
-
errorBody.message,
|
|
5189
|
-
response.status,
|
|
5190
|
-
errorBody
|
|
5191
|
-
);
|
|
5192
|
-
} catch (e5) {
|
|
5193
|
-
error3 = new CommentsApiError(response.statusText, response.status);
|
|
5194
|
-
}
|
|
5195
|
-
throw error3;
|
|
5196
|
-
}
|
|
5197
|
-
}
|
|
5198
|
-
let body;
|
|
5199
|
-
try {
|
|
5200
|
-
body = await response.json();
|
|
5201
|
-
} catch (e6) {
|
|
5202
|
-
body = {};
|
|
5203
|
-
}
|
|
5204
|
-
return body;
|
|
5205
|
-
}
|
|
5206
|
-
async function getThreadsSince(options) {
|
|
5207
|
-
const response = await fetchCommentsApi(
|
|
5208
|
-
"/threads",
|
|
5209
|
-
{
|
|
5210
|
-
since: _optionalChain([options, 'optionalAccess', _119 => _119.since, 'optionalAccess', _120 => _120.toISOString, 'call', _121 => _121()])
|
|
5211
|
-
},
|
|
5212
|
-
{
|
|
5213
|
-
headers: {
|
|
5214
|
-
"Content-Type": "application/json"
|
|
5215
|
-
}
|
|
5216
|
-
}
|
|
5217
|
-
);
|
|
5218
|
-
if (response.ok) {
|
|
5219
|
-
const json = await response.json();
|
|
5220
|
-
return {
|
|
5221
|
-
threads: {
|
|
5222
|
-
updated: json.data.map(convertToThreadData),
|
|
5223
|
-
deleted: json.deletedThreads.map(convertToThreadDeleteInfo)
|
|
5224
|
-
},
|
|
5225
|
-
inboxNotifications: {
|
|
5226
|
-
updated: json.inboxNotifications.map(convertToInboxNotificationData),
|
|
5227
|
-
deleted: json.deletedInboxNotifications.map(
|
|
5228
|
-
convertToInboxNotificationDeleteInfo
|
|
5229
|
-
)
|
|
5230
|
-
},
|
|
5231
|
-
requestedAt: new Date(json.meta.requestedAt)
|
|
5232
|
-
};
|
|
5233
|
-
} else if (response.status === 404) {
|
|
5234
|
-
return {
|
|
5235
|
-
threads: {
|
|
5236
|
-
updated: [],
|
|
5237
|
-
deleted: []
|
|
5238
|
-
},
|
|
5239
|
-
inboxNotifications: {
|
|
5240
|
-
updated: [],
|
|
5241
|
-
deleted: []
|
|
5242
|
-
},
|
|
5243
|
-
requestedAt: /* @__PURE__ */ new Date()
|
|
5244
|
-
};
|
|
5245
|
-
} else {
|
|
5246
|
-
throw new Error("There was an error while getting threads.");
|
|
5247
|
-
}
|
|
5248
|
-
}
|
|
5249
|
-
async function getThreads(options) {
|
|
5250
|
-
let query;
|
|
5251
|
-
if (_optionalChain([options, 'optionalAccess', _122 => _122.query])) {
|
|
5252
|
-
query = objectToQuery(options.query);
|
|
5253
|
-
}
|
|
5254
|
-
const response = await fetchCommentsApi(
|
|
5255
|
-
"/threads",
|
|
5256
|
-
{
|
|
5257
|
-
query
|
|
5258
|
-
},
|
|
5259
|
-
{
|
|
5260
|
-
headers: {
|
|
5261
|
-
"Content-Type": "application/json"
|
|
5262
|
-
}
|
|
5263
|
-
}
|
|
5264
|
-
);
|
|
5265
|
-
if (response.ok) {
|
|
5266
|
-
const json = await response.json();
|
|
5267
|
-
return {
|
|
5268
|
-
threads: json.data.map(convertToThreadData),
|
|
5269
|
-
inboxNotifications: json.inboxNotifications.map(
|
|
5270
|
-
convertToInboxNotificationData
|
|
5271
|
-
),
|
|
5272
|
-
requestedAt: new Date(json.meta.requestedAt)
|
|
5273
|
-
};
|
|
5274
|
-
} else if (response.status === 404) {
|
|
5275
|
-
return {
|
|
5276
|
-
threads: [],
|
|
5277
|
-
inboxNotifications: [],
|
|
5278
|
-
deletedThreads: [],
|
|
5279
|
-
deletedInboxNotifications: [],
|
|
5280
|
-
requestedAt: /* @__PURE__ */ new Date()
|
|
5281
|
-
};
|
|
5282
|
-
} else {
|
|
5283
|
-
throw new Error("There was an error while getting threads.");
|
|
5284
|
-
}
|
|
5285
|
-
}
|
|
5286
|
-
async function getThread(threadId) {
|
|
5287
|
-
const response = await fetchCommentsApi(
|
|
5288
|
-
`/thread-with-notification/${threadId}`
|
|
5289
|
-
);
|
|
5290
|
-
if (response.ok) {
|
|
5291
|
-
const json = await response.json();
|
|
5292
|
-
return {
|
|
5293
|
-
thread: convertToThreadData(json.thread),
|
|
5294
|
-
inboxNotification: json.inboxNotification ? convertToInboxNotificationData(json.inboxNotification) : void 0
|
|
5295
|
-
};
|
|
5296
|
-
} else if (response.status === 404) {
|
|
5297
|
-
return {
|
|
5298
|
-
thread: void 0,
|
|
5299
|
-
inboxNotification: void 0
|
|
5300
|
-
};
|
|
5301
|
-
} else {
|
|
5302
|
-
throw new Error(`There was an error while getting thread ${threadId}.`);
|
|
5303
|
-
}
|
|
5304
|
-
}
|
|
5305
|
-
async function createThread({
|
|
5306
|
-
metadata,
|
|
5307
|
-
body,
|
|
5308
|
-
commentId = createCommentId(),
|
|
5309
|
-
threadId = createThreadId()
|
|
5310
|
-
}) {
|
|
5311
|
-
const thread = await fetchJson("/threads", {
|
|
5312
|
-
method: "POST",
|
|
5313
|
-
headers: {
|
|
5314
|
-
"Content-Type": "application/json"
|
|
5315
|
-
},
|
|
5316
|
-
body: JSON.stringify({
|
|
5317
|
-
id: threadId,
|
|
5318
|
-
comment: {
|
|
5319
|
-
id: commentId,
|
|
5320
|
-
body
|
|
5321
|
-
},
|
|
5322
|
-
metadata
|
|
5323
|
-
})
|
|
5324
|
-
});
|
|
5325
|
-
return convertToThreadData(thread);
|
|
5326
|
-
}
|
|
5327
|
-
async function deleteThread(threadId) {
|
|
5328
|
-
await fetchJson(`/threads/${encodeURIComponent(threadId)}`, {
|
|
5329
|
-
method: "DELETE"
|
|
5330
|
-
});
|
|
5331
|
-
}
|
|
5332
|
-
async function editThreadMetadata({
|
|
5333
|
-
metadata,
|
|
5334
|
-
threadId
|
|
5335
|
-
}) {
|
|
5336
|
-
return await fetchJson(
|
|
5337
|
-
`/threads/${encodeURIComponent(threadId)}/metadata`,
|
|
5338
|
-
{
|
|
5339
|
-
method: "POST",
|
|
5340
|
-
headers: {
|
|
5341
|
-
"Content-Type": "application/json"
|
|
5342
|
-
},
|
|
5343
|
-
body: JSON.stringify(metadata)
|
|
5344
|
-
}
|
|
5345
|
-
);
|
|
5346
|
-
}
|
|
5347
|
-
async function markThreadAsResolved(threadId) {
|
|
5348
|
-
await fetchJson(
|
|
5349
|
-
`/threads/${encodeURIComponent(threadId)}/mark-as-resolved`,
|
|
5350
|
-
{
|
|
5351
|
-
method: "POST"
|
|
5352
|
-
}
|
|
5353
|
-
);
|
|
5354
|
-
}
|
|
5355
|
-
async function markThreadAsUnresolved(threadId) {
|
|
5356
|
-
await fetchJson(
|
|
5357
|
-
`/threads/${encodeURIComponent(threadId)}/mark-as-unresolved`,
|
|
5358
|
-
{
|
|
5359
|
-
method: "POST"
|
|
5360
|
-
}
|
|
5361
|
-
);
|
|
5362
|
-
}
|
|
5363
|
-
async function createComment({
|
|
5364
|
-
threadId,
|
|
5365
|
-
commentId = createCommentId(),
|
|
5366
|
-
body
|
|
5367
|
-
}) {
|
|
5368
|
-
const comment = await fetchJson(
|
|
5369
|
-
`/threads/${encodeURIComponent(threadId)}/comments`,
|
|
5370
|
-
{
|
|
5371
|
-
method: "POST",
|
|
5372
|
-
headers: {
|
|
5373
|
-
"Content-Type": "application/json"
|
|
5374
|
-
},
|
|
5375
|
-
body: JSON.stringify({
|
|
5376
|
-
id: commentId,
|
|
5377
|
-
body
|
|
5378
|
-
})
|
|
5379
|
-
}
|
|
5380
|
-
);
|
|
5381
|
-
return convertToCommentData(comment);
|
|
5382
|
-
}
|
|
5383
|
-
async function editComment({
|
|
5384
|
-
threadId,
|
|
5385
|
-
commentId,
|
|
5386
|
-
body
|
|
5387
|
-
}) {
|
|
5388
|
-
const comment = await fetchJson(
|
|
5389
|
-
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
5390
|
-
commentId
|
|
5391
|
-
)}`,
|
|
5392
|
-
{
|
|
5393
|
-
method: "POST",
|
|
5394
|
-
headers: {
|
|
5395
|
-
"Content-Type": "application/json"
|
|
5396
|
-
},
|
|
5397
|
-
body: JSON.stringify({
|
|
5398
|
-
body
|
|
5399
|
-
})
|
|
5400
|
-
}
|
|
5401
|
-
);
|
|
5402
|
-
return convertToCommentData(comment);
|
|
5403
|
-
}
|
|
5404
|
-
async function deleteComment2({
|
|
5405
|
-
threadId,
|
|
5406
|
-
commentId
|
|
5407
|
-
}) {
|
|
5408
|
-
await fetchJson(
|
|
5409
|
-
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
5410
|
-
commentId
|
|
5411
|
-
)}`,
|
|
5412
|
-
{
|
|
5413
|
-
method: "DELETE"
|
|
5414
|
-
}
|
|
5415
|
-
);
|
|
5416
|
-
}
|
|
5417
|
-
async function addReaction2({
|
|
5418
|
-
threadId,
|
|
5419
|
-
commentId,
|
|
5420
|
-
emoji
|
|
5421
|
-
}) {
|
|
5422
|
-
const reaction = await fetchJson(
|
|
5423
|
-
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
5424
|
-
commentId
|
|
5425
|
-
)}/reactions`,
|
|
5426
|
-
{
|
|
5427
|
-
method: "POST",
|
|
5428
|
-
headers: {
|
|
5429
|
-
"Content-Type": "application/json"
|
|
5430
|
-
},
|
|
5431
|
-
body: JSON.stringify({ emoji })
|
|
5432
|
-
}
|
|
5433
|
-
);
|
|
5434
|
-
return convertToCommentUserReaction(reaction);
|
|
5435
|
-
}
|
|
5436
|
-
async function removeReaction2({
|
|
5437
|
-
threadId,
|
|
5438
|
-
commentId,
|
|
5439
|
-
emoji
|
|
5440
|
-
}) {
|
|
5441
|
-
await fetchJson(
|
|
5442
|
-
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
5443
|
-
commentId
|
|
5444
|
-
)}/reactions/${encodeURIComponent(emoji)}`,
|
|
5445
|
-
{
|
|
5446
|
-
method: "DELETE"
|
|
5447
|
-
}
|
|
5448
|
-
);
|
|
5449
|
-
}
|
|
5450
|
-
return {
|
|
5451
|
-
getThreads,
|
|
5452
|
-
getThreadsSince,
|
|
5453
|
-
getThread,
|
|
5454
|
-
createThread,
|
|
5455
|
-
deleteThread,
|
|
5456
|
-
editThreadMetadata,
|
|
5457
|
-
markThreadAsResolved,
|
|
5458
|
-
markThreadAsUnresolved,
|
|
5459
|
-
createComment,
|
|
5460
|
-
editComment,
|
|
5461
|
-
deleteComment: deleteComment2,
|
|
5462
|
-
addReaction: addReaction2,
|
|
5463
|
-
removeReaction: removeReaction2
|
|
5464
|
-
};
|
|
5465
|
-
}
|
|
5466
5175
|
var MARK_INBOX_NOTIFICATIONS_AS_READ_BATCH_DELAY2 = 50;
|
|
5467
5176
|
function createRoom(options, config) {
|
|
5468
5177
|
const initialPresence = options.initialPresence;
|
|
@@ -5654,7 +5363,7 @@ function createRoom(options, config) {
|
|
|
5654
5363
|
}
|
|
5655
5364
|
},
|
|
5656
5365
|
assertStorageIsWritable: () => {
|
|
5657
|
-
const scopes = _optionalChain([context, 'access',
|
|
5366
|
+
const scopes = _optionalChain([context, 'access', _119 => _119.dynamicSessionInfo, 'access', _120 => _120.current, 'optionalAccess', _121 => _121.scopes]);
|
|
5658
5367
|
if (scopes === void 0) {
|
|
5659
5368
|
return;
|
|
5660
5369
|
}
|
|
@@ -5688,12 +5397,12 @@ function createRoom(options, config) {
|
|
|
5688
5397
|
`/v2/c/rooms/${encodeURIComponent(roomId)}${endpoint}`,
|
|
5689
5398
|
params
|
|
5690
5399
|
);
|
|
5691
|
-
const fetcher = _optionalChain([config, 'access',
|
|
5400
|
+
const fetcher = _optionalChain([config, 'access', _122 => _122.polyfills, 'optionalAccess', _123 => _123.fetch]) || /* istanbul ignore next */
|
|
5692
5401
|
fetch;
|
|
5693
5402
|
return await fetcher(url, {
|
|
5694
5403
|
...options2,
|
|
5695
5404
|
headers: {
|
|
5696
|
-
..._optionalChain([options2, 'optionalAccess',
|
|
5405
|
+
..._optionalChain([options2, 'optionalAccess', _124 => _124.headers]),
|
|
5697
5406
|
Authorization: `Bearer ${getAuthBearerHeaderFromAuthValue(authValue)}`
|
|
5698
5407
|
}
|
|
5699
5408
|
});
|
|
@@ -5766,7 +5475,7 @@ function createRoom(options, config) {
|
|
|
5766
5475
|
}
|
|
5767
5476
|
function sendMessages(messages) {
|
|
5768
5477
|
const serializedPayload = JSON.stringify(messages);
|
|
5769
|
-
const nonce = _optionalChain([context, 'access',
|
|
5478
|
+
const nonce = _optionalChain([context, 'access', _125 => _125.dynamicSessionInfo, 'access', _126 => _126.current, 'optionalAccess', _127 => _127.nonce]);
|
|
5770
5479
|
if (config.unstable_fallbackToHTTP && nonce) {
|
|
5771
5480
|
const size = new TextEncoder().encode(serializedPayload).length;
|
|
5772
5481
|
if (size > MAX_SOCKET_MESSAGE_SIZE) {
|
|
@@ -5828,7 +5537,7 @@ function createRoom(options, config) {
|
|
|
5828
5537
|
} else {
|
|
5829
5538
|
context.root = LiveObject._fromItems(message.items, pool);
|
|
5830
5539
|
}
|
|
5831
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
5540
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _128 => _128.current, 'optionalAccess', _129 => _129.canWrite]), () => ( true));
|
|
5832
5541
|
const stackSizeBefore = context.undoStack.length;
|
|
5833
5542
|
for (const key in context.initialStorage) {
|
|
5834
5543
|
if (context.root.get(key) === void 0) {
|
|
@@ -6033,7 +5742,7 @@ function createRoom(options, config) {
|
|
|
6033
5742
|
}
|
|
6034
5743
|
context.myPresence.patch(patch);
|
|
6035
5744
|
if (context.activeBatch) {
|
|
6036
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5745
|
+
if (_optionalChain([options2, 'optionalAccess', _130 => _130.addToHistory])) {
|
|
6037
5746
|
context.activeBatch.reverseOps.unshift({
|
|
6038
5747
|
type: "presence",
|
|
6039
5748
|
data: oldValues
|
|
@@ -6043,7 +5752,7 @@ function createRoom(options, config) {
|
|
|
6043
5752
|
} else {
|
|
6044
5753
|
flushNowOrSoon();
|
|
6045
5754
|
batchUpdates(() => {
|
|
6046
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5755
|
+
if (_optionalChain([options2, 'optionalAccess', _131 => _131.addToHistory])) {
|
|
6047
5756
|
addToUndoStack(
|
|
6048
5757
|
[{ type: "presence", data: oldValues }],
|
|
6049
5758
|
doNotBatchUpdates
|
|
@@ -6241,7 +5950,7 @@ function createRoom(options, config) {
|
|
|
6241
5950
|
if (process.env.NODE_ENV !== "production") {
|
|
6242
5951
|
const traces = /* @__PURE__ */ new Set();
|
|
6243
5952
|
for (const opId of message.opIds) {
|
|
6244
|
-
const trace = _optionalChain([context, 'access',
|
|
5953
|
+
const trace = _optionalChain([context, 'access', _132 => _132.opStackTraces, 'optionalAccess', _133 => _133.get, 'call', _134 => _134(opId)]);
|
|
6245
5954
|
if (trace) {
|
|
6246
5955
|
traces.add(trace);
|
|
6247
5956
|
}
|
|
@@ -6375,7 +6084,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6375
6084
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
6376
6085
|
createOrUpdateRootFromMessage(message, doNotBatchUpdates);
|
|
6377
6086
|
applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
|
|
6378
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
6087
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _135 => _135()]);
|
|
6379
6088
|
notifyStorageStatus();
|
|
6380
6089
|
eventHub.storageDidLoad.notify();
|
|
6381
6090
|
}
|
|
@@ -6466,137 +6175,406 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6466
6175
|
if (context.activeBatch) {
|
|
6467
6176
|
throw new Error("redo is not allowed during a batch");
|
|
6468
6177
|
}
|
|
6469
|
-
const historyOps = context.redoStack.pop();
|
|
6470
|
-
if (historyOps === void 0) {
|
|
6471
|
-
return;
|
|
6178
|
+
const historyOps = context.redoStack.pop();
|
|
6179
|
+
if (historyOps === void 0) {
|
|
6180
|
+
return;
|
|
6181
|
+
}
|
|
6182
|
+
context.pausedHistory = null;
|
|
6183
|
+
const result = applyOps(historyOps, true);
|
|
6184
|
+
batchUpdates(() => {
|
|
6185
|
+
notify(result.updates, doNotBatchUpdates);
|
|
6186
|
+
context.undoStack.push(result.reverse);
|
|
6187
|
+
onHistoryChange(doNotBatchUpdates);
|
|
6188
|
+
});
|
|
6189
|
+
for (const op of result.ops) {
|
|
6190
|
+
if (op.type !== "presence") {
|
|
6191
|
+
context.buffer.storageOperations.push(op);
|
|
6192
|
+
}
|
|
6193
|
+
}
|
|
6194
|
+
flushNowOrSoon();
|
|
6195
|
+
}
|
|
6196
|
+
function clear() {
|
|
6197
|
+
context.undoStack.length = 0;
|
|
6198
|
+
context.redoStack.length = 0;
|
|
6199
|
+
}
|
|
6200
|
+
function batch(callback) {
|
|
6201
|
+
if (context.activeBatch) {
|
|
6202
|
+
return callback();
|
|
6203
|
+
}
|
|
6204
|
+
let returnValue = void 0;
|
|
6205
|
+
batchUpdates(() => {
|
|
6206
|
+
context.activeBatch = {
|
|
6207
|
+
ops: [],
|
|
6208
|
+
updates: {
|
|
6209
|
+
storageUpdates: /* @__PURE__ */ new Map(),
|
|
6210
|
+
presence: false,
|
|
6211
|
+
others: []
|
|
6212
|
+
},
|
|
6213
|
+
reverseOps: []
|
|
6214
|
+
};
|
|
6215
|
+
try {
|
|
6216
|
+
returnValue = callback();
|
|
6217
|
+
} finally {
|
|
6218
|
+
const currentBatch = context.activeBatch;
|
|
6219
|
+
context.activeBatch = null;
|
|
6220
|
+
if (currentBatch.reverseOps.length > 0) {
|
|
6221
|
+
addToUndoStack(currentBatch.reverseOps, doNotBatchUpdates);
|
|
6222
|
+
}
|
|
6223
|
+
if (currentBatch.ops.length > 0) {
|
|
6224
|
+
context.redoStack.length = 0;
|
|
6225
|
+
}
|
|
6226
|
+
if (currentBatch.ops.length > 0) {
|
|
6227
|
+
dispatchOps(currentBatch.ops);
|
|
6228
|
+
}
|
|
6229
|
+
notify(currentBatch.updates, doNotBatchUpdates);
|
|
6230
|
+
flushNowOrSoon();
|
|
6231
|
+
}
|
|
6232
|
+
});
|
|
6233
|
+
return returnValue;
|
|
6234
|
+
}
|
|
6235
|
+
function pauseHistory() {
|
|
6236
|
+
if (context.pausedHistory === null) {
|
|
6237
|
+
context.pausedHistory = [];
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
function resumeHistory() {
|
|
6241
|
+
const historyOps = context.pausedHistory;
|
|
6242
|
+
context.pausedHistory = null;
|
|
6243
|
+
if (historyOps !== null && historyOps.length > 0) {
|
|
6244
|
+
_addToRealUndoStack(historyOps, batchUpdates);
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
function getStorageStatus() {
|
|
6248
|
+
if (context.root === void 0) {
|
|
6249
|
+
return _getStorage$ === null ? "not-loaded" : "loading";
|
|
6250
|
+
} else {
|
|
6251
|
+
return context.unacknowledgedOps.size === 0 ? "synchronized" : "synchronizing";
|
|
6252
|
+
}
|
|
6253
|
+
}
|
|
6254
|
+
let _lastStorageStatus = getStorageStatus();
|
|
6255
|
+
function notifyStorageStatus() {
|
|
6256
|
+
const storageStatus = getStorageStatus();
|
|
6257
|
+
if (_lastStorageStatus !== storageStatus) {
|
|
6258
|
+
_lastStorageStatus = storageStatus;
|
|
6259
|
+
eventHub.storageStatus.notify(storageStatus);
|
|
6260
|
+
}
|
|
6261
|
+
}
|
|
6262
|
+
function isPresenceReady() {
|
|
6263
|
+
return self.current !== null;
|
|
6264
|
+
}
|
|
6265
|
+
async function waitUntilPresenceReady() {
|
|
6266
|
+
while (!isPresenceReady()) {
|
|
6267
|
+
const { promise, resolve } = Promise_withResolvers();
|
|
6268
|
+
const unsub1 = events.self.subscribeOnce(resolve);
|
|
6269
|
+
const unsub2 = events.status.subscribeOnce(resolve);
|
|
6270
|
+
await promise;
|
|
6271
|
+
unsub1();
|
|
6272
|
+
unsub2();
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6275
|
+
function isStorageReady() {
|
|
6276
|
+
return getStorageSnapshot() !== null;
|
|
6277
|
+
}
|
|
6278
|
+
async function waitUntilStorageReady() {
|
|
6279
|
+
while (!isStorageReady()) {
|
|
6280
|
+
await getStorage();
|
|
6281
|
+
}
|
|
6282
|
+
}
|
|
6283
|
+
const others_forDevTools = new DerivedRef(
|
|
6284
|
+
context.others,
|
|
6285
|
+
(others) => others.map((other, index) => userToTreeNode(`Other ${index}`, other))
|
|
6286
|
+
);
|
|
6287
|
+
const events = {
|
|
6288
|
+
status: eventHub.status.observable,
|
|
6289
|
+
lostConnection: eventHub.lostConnection.observable,
|
|
6290
|
+
customEvent: eventHub.customEvent.observable,
|
|
6291
|
+
others: eventHub.others.observable,
|
|
6292
|
+
self: eventHub.self.observable,
|
|
6293
|
+
myPresence: eventHub.myPresence.observable,
|
|
6294
|
+
error: eventHub.error.observable,
|
|
6295
|
+
/** @deprecated */
|
|
6296
|
+
storage: eventHub.storageBatch.observable,
|
|
6297
|
+
storageBatch: eventHub.storageBatch.observable,
|
|
6298
|
+
history: eventHub.history.observable,
|
|
6299
|
+
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
6300
|
+
storageStatus: eventHub.storageStatus.observable,
|
|
6301
|
+
ydoc: eventHub.ydoc.observable,
|
|
6302
|
+
comments: eventHub.comments.observable
|
|
6303
|
+
};
|
|
6304
|
+
async function fetchCommentsApi(endpoint, params, options2) {
|
|
6305
|
+
const authValue = await delegates.authenticate();
|
|
6306
|
+
return fetchClientApi(config.roomId, endpoint, authValue, options2, params);
|
|
6307
|
+
}
|
|
6308
|
+
async function fetchCommentsJson(endpoint, options2, params) {
|
|
6309
|
+
const response = await fetchCommentsApi(endpoint, params, options2);
|
|
6310
|
+
if (!response.ok) {
|
|
6311
|
+
if (response.status >= 400 && response.status < 600) {
|
|
6312
|
+
let error3;
|
|
6313
|
+
try {
|
|
6314
|
+
const errorBody = await response.json();
|
|
6315
|
+
error3 = new CommentsApiError(
|
|
6316
|
+
errorBody.message,
|
|
6317
|
+
response.status,
|
|
6318
|
+
errorBody
|
|
6319
|
+
);
|
|
6320
|
+
} catch (e5) {
|
|
6321
|
+
error3 = new CommentsApiError(response.statusText, response.status);
|
|
6322
|
+
}
|
|
6323
|
+
throw error3;
|
|
6324
|
+
}
|
|
6325
|
+
}
|
|
6326
|
+
let body;
|
|
6327
|
+
try {
|
|
6328
|
+
body = await response.json();
|
|
6329
|
+
} catch (e6) {
|
|
6330
|
+
body = {};
|
|
6331
|
+
}
|
|
6332
|
+
return body;
|
|
6333
|
+
}
|
|
6334
|
+
async function getThreadsSince(options2) {
|
|
6335
|
+
const response = await fetchCommentsApi(
|
|
6336
|
+
"/threads",
|
|
6337
|
+
{
|
|
6338
|
+
since: _optionalChain([options2, 'optionalAccess', _136 => _136.since, 'optionalAccess', _137 => _137.toISOString, 'call', _138 => _138()])
|
|
6339
|
+
},
|
|
6340
|
+
{
|
|
6341
|
+
headers: {
|
|
6342
|
+
"Content-Type": "application/json"
|
|
6343
|
+
}
|
|
6344
|
+
}
|
|
6345
|
+
);
|
|
6346
|
+
if (response.ok) {
|
|
6347
|
+
const json = await response.json();
|
|
6348
|
+
return {
|
|
6349
|
+
threads: {
|
|
6350
|
+
updated: json.data.map(convertToThreadData),
|
|
6351
|
+
deleted: json.deletedThreads.map(convertToThreadDeleteInfo)
|
|
6352
|
+
},
|
|
6353
|
+
inboxNotifications: {
|
|
6354
|
+
updated: json.inboxNotifications.map(convertToInboxNotificationData),
|
|
6355
|
+
deleted: json.deletedInboxNotifications.map(
|
|
6356
|
+
convertToInboxNotificationDeleteInfo
|
|
6357
|
+
)
|
|
6358
|
+
},
|
|
6359
|
+
requestedAt: new Date(json.meta.requestedAt)
|
|
6360
|
+
};
|
|
6361
|
+
} else if (response.status === 404) {
|
|
6362
|
+
return {
|
|
6363
|
+
threads: {
|
|
6364
|
+
updated: [],
|
|
6365
|
+
deleted: []
|
|
6366
|
+
},
|
|
6367
|
+
inboxNotifications: {
|
|
6368
|
+
updated: [],
|
|
6369
|
+
deleted: []
|
|
6370
|
+
},
|
|
6371
|
+
requestedAt: /* @__PURE__ */ new Date()
|
|
6372
|
+
};
|
|
6373
|
+
} else {
|
|
6374
|
+
throw new Error("There was an error while getting threads.");
|
|
6375
|
+
}
|
|
6376
|
+
}
|
|
6377
|
+
async function getThreads(options2) {
|
|
6378
|
+
let query;
|
|
6379
|
+
if (_optionalChain([options2, 'optionalAccess', _139 => _139.query])) {
|
|
6380
|
+
query = objectToQuery(options2.query);
|
|
6381
|
+
}
|
|
6382
|
+
const response = await fetchCommentsApi(
|
|
6383
|
+
"/threads",
|
|
6384
|
+
{
|
|
6385
|
+
query
|
|
6386
|
+
},
|
|
6387
|
+
{
|
|
6388
|
+
headers: {
|
|
6389
|
+
"Content-Type": "application/json"
|
|
6390
|
+
}
|
|
6391
|
+
}
|
|
6392
|
+
);
|
|
6393
|
+
if (response.ok) {
|
|
6394
|
+
const json = await response.json();
|
|
6395
|
+
return {
|
|
6396
|
+
threads: json.data.map(convertToThreadData),
|
|
6397
|
+
inboxNotifications: json.inboxNotifications.map(
|
|
6398
|
+
convertToInboxNotificationData
|
|
6399
|
+
),
|
|
6400
|
+
requestedAt: new Date(json.meta.requestedAt)
|
|
6401
|
+
};
|
|
6402
|
+
} else if (response.status === 404) {
|
|
6403
|
+
return {
|
|
6404
|
+
threads: [],
|
|
6405
|
+
inboxNotifications: [],
|
|
6406
|
+
deletedThreads: [],
|
|
6407
|
+
deletedInboxNotifications: [],
|
|
6408
|
+
requestedAt: /* @__PURE__ */ new Date()
|
|
6409
|
+
};
|
|
6410
|
+
} else {
|
|
6411
|
+
throw new Error("There was an error while getting threads.");
|
|
6412
|
+
}
|
|
6413
|
+
}
|
|
6414
|
+
async function getThread(threadId) {
|
|
6415
|
+
const response = await fetchCommentsApi(
|
|
6416
|
+
`/thread-with-notification/${threadId}`
|
|
6417
|
+
);
|
|
6418
|
+
if (response.ok) {
|
|
6419
|
+
const json = await response.json();
|
|
6420
|
+
return {
|
|
6421
|
+
thread: convertToThreadData(json.thread),
|
|
6422
|
+
inboxNotification: json.inboxNotification ? convertToInboxNotificationData(json.inboxNotification) : void 0
|
|
6423
|
+
};
|
|
6424
|
+
} else if (response.status === 404) {
|
|
6425
|
+
return {
|
|
6426
|
+
thread: void 0,
|
|
6427
|
+
inboxNotification: void 0
|
|
6428
|
+
};
|
|
6429
|
+
} else {
|
|
6430
|
+
throw new Error(`There was an error while getting thread ${threadId}.`);
|
|
6472
6431
|
}
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6432
|
+
}
|
|
6433
|
+
async function createThread({
|
|
6434
|
+
metadata,
|
|
6435
|
+
body,
|
|
6436
|
+
commentId = createCommentId(),
|
|
6437
|
+
threadId = createThreadId()
|
|
6438
|
+
}) {
|
|
6439
|
+
const thread = await fetchCommentsJson("/threads", {
|
|
6440
|
+
method: "POST",
|
|
6441
|
+
headers: {
|
|
6442
|
+
"Content-Type": "application/json"
|
|
6443
|
+
},
|
|
6444
|
+
body: JSON.stringify({
|
|
6445
|
+
id: threadId,
|
|
6446
|
+
comment: {
|
|
6447
|
+
id: commentId,
|
|
6448
|
+
body
|
|
6449
|
+
},
|
|
6450
|
+
metadata
|
|
6451
|
+
})
|
|
6479
6452
|
});
|
|
6480
|
-
|
|
6481
|
-
if (op.type !== "presence") {
|
|
6482
|
-
context.buffer.storageOperations.push(op);
|
|
6483
|
-
}
|
|
6484
|
-
}
|
|
6485
|
-
flushNowOrSoon();
|
|
6453
|
+
return convertToThreadData(thread);
|
|
6486
6454
|
}
|
|
6487
|
-
function
|
|
6488
|
-
|
|
6489
|
-
|
|
6455
|
+
async function deleteThread(threadId) {
|
|
6456
|
+
await fetchCommentsJson(`/threads/${encodeURIComponent(threadId)}`, {
|
|
6457
|
+
method: "DELETE"
|
|
6458
|
+
});
|
|
6490
6459
|
}
|
|
6491
|
-
function
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
presence: false,
|
|
6502
|
-
others: []
|
|
6460
|
+
async function editThreadMetadata({
|
|
6461
|
+
metadata,
|
|
6462
|
+
threadId
|
|
6463
|
+
}) {
|
|
6464
|
+
return await fetchCommentsJson(
|
|
6465
|
+
`/threads/${encodeURIComponent(threadId)}/metadata`,
|
|
6466
|
+
{
|
|
6467
|
+
method: "POST",
|
|
6468
|
+
headers: {
|
|
6469
|
+
"Content-Type": "application/json"
|
|
6503
6470
|
},
|
|
6504
|
-
|
|
6505
|
-
};
|
|
6506
|
-
try {
|
|
6507
|
-
returnValue = callback();
|
|
6508
|
-
} finally {
|
|
6509
|
-
const currentBatch = context.activeBatch;
|
|
6510
|
-
context.activeBatch = null;
|
|
6511
|
-
if (currentBatch.reverseOps.length > 0) {
|
|
6512
|
-
addToUndoStack(currentBatch.reverseOps, doNotBatchUpdates);
|
|
6513
|
-
}
|
|
6514
|
-
if (currentBatch.ops.length > 0) {
|
|
6515
|
-
context.redoStack.length = 0;
|
|
6516
|
-
}
|
|
6517
|
-
if (currentBatch.ops.length > 0) {
|
|
6518
|
-
dispatchOps(currentBatch.ops);
|
|
6519
|
-
}
|
|
6520
|
-
notify(currentBatch.updates, doNotBatchUpdates);
|
|
6521
|
-
flushNowOrSoon();
|
|
6471
|
+
body: JSON.stringify(metadata)
|
|
6522
6472
|
}
|
|
6523
|
-
|
|
6524
|
-
return returnValue;
|
|
6525
|
-
}
|
|
6526
|
-
function pauseHistory() {
|
|
6527
|
-
if (context.pausedHistory === null) {
|
|
6528
|
-
context.pausedHistory = [];
|
|
6529
|
-
}
|
|
6473
|
+
);
|
|
6530
6474
|
}
|
|
6531
|
-
function
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6475
|
+
async function markThreadAsResolved(threadId) {
|
|
6476
|
+
await fetchCommentsJson(
|
|
6477
|
+
`/threads/${encodeURIComponent(threadId)}/mark-as-resolved`,
|
|
6478
|
+
{
|
|
6479
|
+
method: "POST"
|
|
6480
|
+
}
|
|
6481
|
+
);
|
|
6537
6482
|
}
|
|
6538
|
-
function
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6483
|
+
async function markThreadAsUnresolved(threadId) {
|
|
6484
|
+
await fetchCommentsJson(
|
|
6485
|
+
`/threads/${encodeURIComponent(threadId)}/mark-as-unresolved`,
|
|
6486
|
+
{
|
|
6487
|
+
method: "POST"
|
|
6488
|
+
}
|
|
6489
|
+
);
|
|
6544
6490
|
}
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6491
|
+
async function createComment({
|
|
6492
|
+
threadId,
|
|
6493
|
+
commentId = createCommentId(),
|
|
6494
|
+
body
|
|
6495
|
+
}) {
|
|
6496
|
+
const comment = await fetchCommentsJson(
|
|
6497
|
+
`/threads/${encodeURIComponent(threadId)}/comments`,
|
|
6498
|
+
{
|
|
6499
|
+
method: "POST",
|
|
6500
|
+
headers: {
|
|
6501
|
+
"Content-Type": "application/json"
|
|
6502
|
+
},
|
|
6503
|
+
body: JSON.stringify({
|
|
6504
|
+
id: commentId,
|
|
6505
|
+
body
|
|
6506
|
+
})
|
|
6507
|
+
}
|
|
6508
|
+
);
|
|
6509
|
+
return convertToCommentData(comment);
|
|
6552
6510
|
}
|
|
6553
|
-
function
|
|
6554
|
-
|
|
6511
|
+
async function editComment({
|
|
6512
|
+
threadId,
|
|
6513
|
+
commentId,
|
|
6514
|
+
body
|
|
6515
|
+
}) {
|
|
6516
|
+
const comment = await fetchCommentsJson(
|
|
6517
|
+
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
6518
|
+
commentId
|
|
6519
|
+
)}`,
|
|
6520
|
+
{
|
|
6521
|
+
method: "POST",
|
|
6522
|
+
headers: {
|
|
6523
|
+
"Content-Type": "application/json"
|
|
6524
|
+
},
|
|
6525
|
+
body: JSON.stringify({
|
|
6526
|
+
body
|
|
6527
|
+
})
|
|
6528
|
+
}
|
|
6529
|
+
);
|
|
6530
|
+
return convertToCommentData(comment);
|
|
6555
6531
|
}
|
|
6556
|
-
async function
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6532
|
+
async function deleteComment2({
|
|
6533
|
+
threadId,
|
|
6534
|
+
commentId
|
|
6535
|
+
}) {
|
|
6536
|
+
await fetchCommentsJson(
|
|
6537
|
+
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
6538
|
+
commentId
|
|
6539
|
+
)}`,
|
|
6540
|
+
{
|
|
6541
|
+
method: "DELETE"
|
|
6542
|
+
}
|
|
6543
|
+
);
|
|
6565
6544
|
}
|
|
6566
|
-
function
|
|
6567
|
-
|
|
6545
|
+
async function addReaction2({
|
|
6546
|
+
threadId,
|
|
6547
|
+
commentId,
|
|
6548
|
+
emoji
|
|
6549
|
+
}) {
|
|
6550
|
+
const reaction = await fetchCommentsJson(
|
|
6551
|
+
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
6552
|
+
commentId
|
|
6553
|
+
)}/reactions`,
|
|
6554
|
+
{
|
|
6555
|
+
method: "POST",
|
|
6556
|
+
headers: {
|
|
6557
|
+
"Content-Type": "application/json"
|
|
6558
|
+
},
|
|
6559
|
+
body: JSON.stringify({ emoji })
|
|
6560
|
+
}
|
|
6561
|
+
);
|
|
6562
|
+
return convertToCommentUserReaction(reaction);
|
|
6568
6563
|
}
|
|
6569
|
-
async function
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6564
|
+
async function removeReaction2({
|
|
6565
|
+
threadId,
|
|
6566
|
+
commentId,
|
|
6567
|
+
emoji
|
|
6568
|
+
}) {
|
|
6569
|
+
await fetchCommentsJson(
|
|
6570
|
+
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
6571
|
+
commentId
|
|
6572
|
+
)}/reactions/${encodeURIComponent(emoji)}`,
|
|
6573
|
+
{
|
|
6574
|
+
method: "DELETE"
|
|
6575
|
+
}
|
|
6576
|
+
);
|
|
6573
6577
|
}
|
|
6574
|
-
const others_forDevTools = new DerivedRef(
|
|
6575
|
-
context.others,
|
|
6576
|
-
(others) => others.map((other, index) => userToTreeNode(`Other ${index}`, other))
|
|
6577
|
-
);
|
|
6578
|
-
const events = {
|
|
6579
|
-
status: eventHub.status.observable,
|
|
6580
|
-
lostConnection: eventHub.lostConnection.observable,
|
|
6581
|
-
customEvent: eventHub.customEvent.observable,
|
|
6582
|
-
others: eventHub.others.observable,
|
|
6583
|
-
self: eventHub.self.observable,
|
|
6584
|
-
myPresence: eventHub.myPresence.observable,
|
|
6585
|
-
error: eventHub.error.observable,
|
|
6586
|
-
/** @deprecated */
|
|
6587
|
-
storage: eventHub.storageBatch.observable,
|
|
6588
|
-
storageBatch: eventHub.storageBatch.observable,
|
|
6589
|
-
history: eventHub.history.observable,
|
|
6590
|
-
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
6591
|
-
storageStatus: eventHub.storageStatus.observable,
|
|
6592
|
-
ydoc: eventHub.ydoc.observable,
|
|
6593
|
-
comments: eventHub.comments.observable
|
|
6594
|
-
};
|
|
6595
|
-
const commentsApi = createCommentsApi(
|
|
6596
|
-
config.roomId,
|
|
6597
|
-
delegates.authenticate,
|
|
6598
|
-
fetchClientApi
|
|
6599
|
-
);
|
|
6600
6578
|
async function fetchNotificationsJson(endpoint, options2) {
|
|
6601
6579
|
const authValue = await delegates.authenticate();
|
|
6602
6580
|
const response = await fetchClientApi(
|
|
@@ -6747,10 +6725,24 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6747
6725
|
// Presence
|
|
6748
6726
|
getPresence: () => context.myPresence.current,
|
|
6749
6727
|
getOthers: () => context.others.current,
|
|
6728
|
+
// Comments
|
|
6729
|
+
getThreads,
|
|
6730
|
+
getThreadsSince,
|
|
6731
|
+
getThread,
|
|
6732
|
+
createThread,
|
|
6733
|
+
deleteThread,
|
|
6734
|
+
editThreadMetadata,
|
|
6735
|
+
markThreadAsResolved,
|
|
6736
|
+
markThreadAsUnresolved,
|
|
6737
|
+
createComment,
|
|
6738
|
+
editComment,
|
|
6739
|
+
deleteComment: deleteComment2,
|
|
6740
|
+
addReaction: addReaction2,
|
|
6741
|
+
removeReaction: removeReaction2,
|
|
6742
|
+
// Notifications
|
|
6750
6743
|
getNotificationSettings,
|
|
6751
6744
|
updateNotificationSettings,
|
|
6752
|
-
markInboxNotificationAsRead
|
|
6753
|
-
...commentsApi
|
|
6745
|
+
markInboxNotificationAsRead
|
|
6754
6746
|
},
|
|
6755
6747
|
// Explictly make the internal field non-enumerable, to avoid aggressive
|
|
6756
6748
|
// freezing when used with Immer
|