@liveblocks/core 3.13.0-vincent3 → 3.13.1-hackathon
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 +502 -322
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +331 -212
- package/dist/index.d.ts +331 -212
- package/dist/index.js +434 -254
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.13.
|
|
9
|
+
var PKG_VERSION = "3.13.1-hackathon";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -251,6 +251,19 @@ function findLastIndex(arr, predicate) {
|
|
|
251
251
|
}
|
|
252
252
|
return -1;
|
|
253
253
|
}
|
|
254
|
+
function partition(iterable, predicate) {
|
|
255
|
+
const good = [];
|
|
256
|
+
const bad = [];
|
|
257
|
+
let index = 0;
|
|
258
|
+
for (const item of iterable) {
|
|
259
|
+
if (predicate(item, index++)) {
|
|
260
|
+
good.push(item);
|
|
261
|
+
} else {
|
|
262
|
+
bad.push(item);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return [good, bad];
|
|
266
|
+
}
|
|
254
267
|
|
|
255
268
|
// src/lib/signals.ts
|
|
256
269
|
var kSinks = Symbol("kSinks");
|
|
@@ -1606,6 +1619,7 @@ function createApiClient({
|
|
|
1606
1619
|
comment: {
|
|
1607
1620
|
id: commentId,
|
|
1608
1621
|
body: options.body,
|
|
1622
|
+
metadata: options.commentMetadata,
|
|
1609
1623
|
attachmentIds: options.attachmentIds
|
|
1610
1624
|
},
|
|
1611
1625
|
metadata: options.metadata
|
|
@@ -1659,6 +1673,16 @@ function createApiClient({
|
|
|
1659
1673
|
options.metadata
|
|
1660
1674
|
);
|
|
1661
1675
|
}
|
|
1676
|
+
async function editCommentMetadata(options) {
|
|
1677
|
+
return await httpClient.post(
|
|
1678
|
+
url`/v2/c/rooms/${options.roomId}/threads/${options.threadId}/comments/${options.commentId}/metadata`,
|
|
1679
|
+
await authManager.getAuthValue({
|
|
1680
|
+
requestedScope: "comments:read",
|
|
1681
|
+
roomId: options.roomId
|
|
1682
|
+
}),
|
|
1683
|
+
options.metadata
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1662
1686
|
async function createComment(options) {
|
|
1663
1687
|
const commentId = _nullishCoalesce(options.commentId, () => ( createCommentId()));
|
|
1664
1688
|
const comment = await httpClient.post(
|
|
@@ -1670,6 +1694,7 @@ function createApiClient({
|
|
|
1670
1694
|
{
|
|
1671
1695
|
id: commentId,
|
|
1672
1696
|
body: options.body,
|
|
1697
|
+
metadata: options.metadata,
|
|
1673
1698
|
attachmentIds: options.attachmentIds
|
|
1674
1699
|
}
|
|
1675
1700
|
);
|
|
@@ -1684,7 +1709,8 @@ function createApiClient({
|
|
|
1684
1709
|
}),
|
|
1685
1710
|
{
|
|
1686
1711
|
body: options.body,
|
|
1687
|
-
attachmentIds: options.attachmentIds
|
|
1712
|
+
attachmentIds: options.attachmentIds,
|
|
1713
|
+
metadata: options.metadata
|
|
1688
1714
|
}
|
|
1689
1715
|
);
|
|
1690
1716
|
return convertToCommentData(comment);
|
|
@@ -2426,6 +2452,7 @@ function createApiClient({
|
|
|
2426
2452
|
editThreadMetadata,
|
|
2427
2453
|
createComment,
|
|
2428
2454
|
editComment,
|
|
2455
|
+
editCommentMetadata,
|
|
2429
2456
|
deleteComment,
|
|
2430
2457
|
addReaction,
|
|
2431
2458
|
removeReaction,
|
|
@@ -3090,12 +3117,7 @@ var ServerMsgCode = Object.freeze({
|
|
|
3090
3117
|
BROADCASTED_EVENT: 103,
|
|
3091
3118
|
ROOM_STATE: 104,
|
|
3092
3119
|
// For Storage
|
|
3093
|
-
|
|
3094
|
-
// Only sent in V7
|
|
3095
|
-
STORAGE_CHUNK: 210,
|
|
3096
|
-
// Used in V8+
|
|
3097
|
-
STORAGE_STREAM_END: 211,
|
|
3098
|
-
// Used in V8+
|
|
3120
|
+
STORAGE_STATE: 200,
|
|
3099
3121
|
UPDATE_STORAGE: 201,
|
|
3100
3122
|
// For Yjs Docs
|
|
3101
3123
|
UPDATE_YDOC: 300,
|
|
@@ -3109,6 +3131,10 @@ var ServerMsgCode = Object.freeze({
|
|
|
3109
3131
|
COMMENT_DELETED: 404,
|
|
3110
3132
|
COMMENT_REACTION_ADDED: 405,
|
|
3111
3133
|
COMMENT_REACTION_REMOVED: 406,
|
|
3134
|
+
COMMENT_METADATA_UPDATED: 409,
|
|
3135
|
+
// For Agent Sessions
|
|
3136
|
+
AGENT_SESSIONS: 501,
|
|
3137
|
+
AGENT_MESSAGES: 503,
|
|
3112
3138
|
// Error codes
|
|
3113
3139
|
REJECT_STORAGE_OP: 299
|
|
3114
3140
|
// Sent if a mutation was not allowed on the server (i.e. due to permissions, limit exceeded, etc)
|
|
@@ -6094,6 +6120,19 @@ var AbstractCrdt = class {
|
|
|
6094
6120
|
}
|
|
6095
6121
|
this.#pool = void 0;
|
|
6096
6122
|
}
|
|
6123
|
+
/**
|
|
6124
|
+
* Serializes this CRDT and all its children into a list of creation ops
|
|
6125
|
+
* with opIds. Used for forward operations that will be sent over the wire
|
|
6126
|
+
* immediately. Each op gets a unique opId for server acknowledgement.
|
|
6127
|
+
*
|
|
6128
|
+
* @internal
|
|
6129
|
+
*/
|
|
6130
|
+
_toOpsWithOpId(parentId, parentKey, pool) {
|
|
6131
|
+
return this._toOps(parentId, parentKey).map((op) => ({
|
|
6132
|
+
opId: pool.generateOpId(),
|
|
6133
|
+
...op
|
|
6134
|
+
}));
|
|
6135
|
+
}
|
|
6097
6136
|
/** This caches the result of the last .toImmutable() call for this Live node. */
|
|
6098
6137
|
#cachedImmutable;
|
|
6099
6138
|
#cachedTreeNodeKey;
|
|
@@ -6145,57 +6184,6 @@ var CrdtType = Object.freeze({
|
|
|
6145
6184
|
MAP: 2,
|
|
6146
6185
|
REGISTER: 3
|
|
6147
6186
|
});
|
|
6148
|
-
function isRootNode(node) {
|
|
6149
|
-
return node[0] === "root";
|
|
6150
|
-
}
|
|
6151
|
-
function isRootCrdt(id, _) {
|
|
6152
|
-
return id === "root";
|
|
6153
|
-
}
|
|
6154
|
-
function* compactNodesToNodeStream(nodes) {
|
|
6155
|
-
for (const node of nodes) {
|
|
6156
|
-
const id = node[0];
|
|
6157
|
-
if (isRootNode(node)) {
|
|
6158
|
-
yield [id, { type: CrdtType.OBJECT, data: node[1] }];
|
|
6159
|
-
continue;
|
|
6160
|
-
}
|
|
6161
|
-
switch (node[1]) {
|
|
6162
|
-
case CrdtType.OBJECT:
|
|
6163
|
-
yield [id, { type: CrdtType.OBJECT, parentId: node[2], parentKey: node[3], data: node[4] }];
|
|
6164
|
-
break;
|
|
6165
|
-
case CrdtType.LIST:
|
|
6166
|
-
yield [id, { type: CrdtType.LIST, parentId: node[2], parentKey: node[3] }];
|
|
6167
|
-
break;
|
|
6168
|
-
case CrdtType.MAP:
|
|
6169
|
-
yield [id, { type: CrdtType.MAP, parentId: node[2], parentKey: node[3] }];
|
|
6170
|
-
break;
|
|
6171
|
-
case CrdtType.REGISTER:
|
|
6172
|
-
yield [id, { type: CrdtType.REGISTER, parentId: node[2], parentKey: node[3], data: node[4] }];
|
|
6173
|
-
break;
|
|
6174
|
-
}
|
|
6175
|
-
}
|
|
6176
|
-
}
|
|
6177
|
-
function* nodeStreamToCompactNodes(nodes) {
|
|
6178
|
-
for (const [id, node] of nodes) {
|
|
6179
|
-
switch (node.type) {
|
|
6180
|
-
case CrdtType.OBJECT:
|
|
6181
|
-
if (isRootCrdt(id, node)) {
|
|
6182
|
-
yield [id, node.data];
|
|
6183
|
-
} else {
|
|
6184
|
-
yield [id, CrdtType.OBJECT, node.parentId, node.parentKey, node.data];
|
|
6185
|
-
}
|
|
6186
|
-
break;
|
|
6187
|
-
case CrdtType.LIST:
|
|
6188
|
-
yield [id, CrdtType.LIST, node.parentId, node.parentKey];
|
|
6189
|
-
break;
|
|
6190
|
-
case CrdtType.MAP:
|
|
6191
|
-
yield [id, CrdtType.MAP, node.parentId, node.parentKey];
|
|
6192
|
-
break;
|
|
6193
|
-
case CrdtType.REGISTER:
|
|
6194
|
-
yield [id, CrdtType.REGISTER, node.parentId, node.parentKey, node.data];
|
|
6195
|
-
break;
|
|
6196
|
-
}
|
|
6197
|
-
}
|
|
6198
|
-
}
|
|
6199
6187
|
|
|
6200
6188
|
// src/crdts/LiveRegister.ts
|
|
6201
6189
|
var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
@@ -6214,7 +6202,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
6214
6202
|
return register;
|
|
6215
6203
|
}
|
|
6216
6204
|
/** @internal */
|
|
6217
|
-
_toOps(parentId, parentKey
|
|
6205
|
+
_toOps(parentId, parentKey) {
|
|
6218
6206
|
if (this._id === void 0) {
|
|
6219
6207
|
throw new Error(
|
|
6220
6208
|
"Cannot serialize register if parentId or parentKey is undefined"
|
|
@@ -6223,7 +6211,6 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
6223
6211
|
return [
|
|
6224
6212
|
{
|
|
6225
6213
|
type: OpCode.CREATE_REGISTER,
|
|
6226
|
-
opId: _optionalChain([pool, 'optionalAccess', _115 => _115.generateOpId, 'call', _116 => _116()]),
|
|
6227
6214
|
id: this._id,
|
|
6228
6215
|
parentId,
|
|
6229
6216
|
parentKey,
|
|
@@ -6322,14 +6309,13 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6322
6309
|
* This is quite unintuitive and should disappear as soon as
|
|
6323
6310
|
* we introduce an explicit LiveList.Set operation
|
|
6324
6311
|
*/
|
|
6325
|
-
_toOps(parentId, parentKey
|
|
6312
|
+
_toOps(parentId, parentKey) {
|
|
6326
6313
|
if (this._id === void 0) {
|
|
6327
6314
|
throw new Error("Cannot serialize item is not attached");
|
|
6328
6315
|
}
|
|
6329
6316
|
const ops = [];
|
|
6330
6317
|
const op = {
|
|
6331
6318
|
id: this._id,
|
|
6332
|
-
opId: _optionalChain([pool, 'optionalAccess', _117 => _117.generateOpId, 'call', _118 => _118()]),
|
|
6333
6319
|
type: OpCode.CREATE_LIST,
|
|
6334
6320
|
parentId,
|
|
6335
6321
|
parentKey
|
|
@@ -6338,13 +6324,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6338
6324
|
for (const item of this.#items) {
|
|
6339
6325
|
const parentKey2 = item._getParentKeyOrThrow();
|
|
6340
6326
|
const childOps = HACK_addIntentAndDeletedIdToOperation(
|
|
6341
|
-
item._toOps(this._id, parentKey2
|
|
6327
|
+
item._toOps(this._id, parentKey2),
|
|
6342
6328
|
void 0
|
|
6343
6329
|
);
|
|
6344
|
-
const childOpId = childOps[0].opId;
|
|
6345
|
-
if (childOpId !== void 0) {
|
|
6346
|
-
this.#unacknowledgedSets.set(parentKey2, childOpId);
|
|
6347
|
-
}
|
|
6348
6330
|
ops.push(...childOps);
|
|
6349
6331
|
}
|
|
6350
6332
|
return ops;
|
|
@@ -6600,7 +6582,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6600
6582
|
#applyInsertUndoRedo(op) {
|
|
6601
6583
|
const { id, parentKey: key } = op;
|
|
6602
6584
|
const child = creationOpToLiveNode(op);
|
|
6603
|
-
if (_optionalChain([this, 'access',
|
|
6585
|
+
if (_optionalChain([this, 'access', _115 => _115._pool, 'optionalAccess', _116 => _116.getNode, 'call', _117 => _117(id)]) !== void 0) {
|
|
6604
6586
|
return { modified: false };
|
|
6605
6587
|
}
|
|
6606
6588
|
child._attach(id, nn(this._pool));
|
|
@@ -6608,8 +6590,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6608
6590
|
const existingItemIndex = this._indexOfPosition(key);
|
|
6609
6591
|
let newKey = key;
|
|
6610
6592
|
if (existingItemIndex !== -1) {
|
|
6611
|
-
const before2 = _optionalChain([this, 'access',
|
|
6612
|
-
const after2 = _optionalChain([this, 'access',
|
|
6593
|
+
const before2 = _optionalChain([this, 'access', _118 => _118.#items, 'access', _119 => _119[existingItemIndex], 'optionalAccess', _120 => _120._parentPos]);
|
|
6594
|
+
const after2 = _optionalChain([this, 'access', _121 => _121.#items, 'access', _122 => _122[existingItemIndex + 1], 'optionalAccess', _123 => _123._parentPos]);
|
|
6613
6595
|
newKey = makePosition(before2, after2);
|
|
6614
6596
|
child._setParentLink(this, newKey);
|
|
6615
6597
|
}
|
|
@@ -6623,7 +6605,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6623
6605
|
#applySetUndoRedo(op) {
|
|
6624
6606
|
const { id, parentKey: key } = op;
|
|
6625
6607
|
const child = creationOpToLiveNode(op);
|
|
6626
|
-
if (_optionalChain([this, 'access',
|
|
6608
|
+
if (_optionalChain([this, 'access', _124 => _124._pool, 'optionalAccess', _125 => _125.getNode, 'call', _126 => _126(id)]) !== void 0) {
|
|
6627
6609
|
return { modified: false };
|
|
6628
6610
|
}
|
|
6629
6611
|
this.#unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -6636,7 +6618,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6636
6618
|
existingItem._detach();
|
|
6637
6619
|
this.#items[indexOfItemWithSameKey] = child;
|
|
6638
6620
|
const reverse = HACK_addIntentAndDeletedIdToOperation(
|
|
6639
|
-
existingItem._toOps(nn(this._id), key
|
|
6621
|
+
existingItem._toOps(nn(this._id), key),
|
|
6640
6622
|
op.id
|
|
6641
6623
|
);
|
|
6642
6624
|
const delta = [setDelta(indexOfItemWithSameKey, child)];
|
|
@@ -6692,7 +6674,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6692
6674
|
_detachChild(child) {
|
|
6693
6675
|
if (child) {
|
|
6694
6676
|
const parentKey = nn(child._parentKey);
|
|
6695
|
-
const reverse = child._toOps(nn(this._id), parentKey
|
|
6677
|
+
const reverse = child._toOps(nn(this._id), parentKey);
|
|
6696
6678
|
const indexToDelete = this.#items.indexOf(child);
|
|
6697
6679
|
if (indexToDelete === -1) {
|
|
6698
6680
|
return {
|
|
@@ -6744,7 +6726,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6744
6726
|
} else {
|
|
6745
6727
|
this.#items[existingItemIndex]._setParentLink(
|
|
6746
6728
|
this,
|
|
6747
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6729
|
+
makePosition(newKey, _optionalChain([this, 'access', _127 => _127.#items, 'access', _128 => _128[existingItemIndex + 1], 'optionalAccess', _129 => _129._parentPos]))
|
|
6748
6730
|
);
|
|
6749
6731
|
const previousIndex = this.#items.indexOf(child);
|
|
6750
6732
|
child._setParentLink(this, newKey);
|
|
@@ -6769,7 +6751,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6769
6751
|
if (existingItemIndex !== -1) {
|
|
6770
6752
|
this.#items[existingItemIndex]._setParentLink(
|
|
6771
6753
|
this,
|
|
6772
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6754
|
+
makePosition(newKey, _optionalChain([this, 'access', _130 => _130.#items, 'access', _131 => _131[existingItemIndex + 1], 'optionalAccess', _132 => _132._parentPos]))
|
|
6773
6755
|
);
|
|
6774
6756
|
}
|
|
6775
6757
|
child._setParentLink(this, newKey);
|
|
@@ -6788,7 +6770,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6788
6770
|
if (existingItemIndex !== -1) {
|
|
6789
6771
|
this.#items[existingItemIndex]._setParentLink(
|
|
6790
6772
|
this,
|
|
6791
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
6773
|
+
makePosition(newKey, _optionalChain([this, 'access', _133 => _133.#items, 'access', _134 => _134[existingItemIndex + 1], 'optionalAccess', _135 => _135._parentPos]))
|
|
6792
6774
|
);
|
|
6793
6775
|
}
|
|
6794
6776
|
child._setParentLink(this, newKey);
|
|
@@ -6816,7 +6798,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6816
6798
|
if (existingItemIndex !== -1) {
|
|
6817
6799
|
actualNewKey = makePosition(
|
|
6818
6800
|
newKey,
|
|
6819
|
-
_optionalChain([this, 'access',
|
|
6801
|
+
_optionalChain([this, 'access', _136 => _136.#items, 'access', _137 => _137[existingItemIndex + 1], 'optionalAccess', _138 => _138._parentPos])
|
|
6820
6802
|
);
|
|
6821
6803
|
}
|
|
6822
6804
|
child._setParentLink(this, actualNewKey);
|
|
@@ -6874,7 +6856,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6874
6856
|
* @param element The element to add to the end of the LiveList.
|
|
6875
6857
|
*/
|
|
6876
6858
|
push(element) {
|
|
6877
|
-
_optionalChain([this, 'access',
|
|
6859
|
+
_optionalChain([this, 'access', _139 => _139._pool, 'optionalAccess', _140 => _140.assertStorageIsWritable, 'call', _141 => _141()]);
|
|
6878
6860
|
return this.insert(element, this.length);
|
|
6879
6861
|
}
|
|
6880
6862
|
/**
|
|
@@ -6883,7 +6865,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6883
6865
|
* @param index The index at which you want to insert the element.
|
|
6884
6866
|
*/
|
|
6885
6867
|
insert(element, index) {
|
|
6886
|
-
_optionalChain([this, 'access',
|
|
6868
|
+
_optionalChain([this, 'access', _142 => _142._pool, 'optionalAccess', _143 => _143.assertStorageIsWritable, 'call', _144 => _144()]);
|
|
6887
6869
|
if (index < 0 || index > this.#items.length) {
|
|
6888
6870
|
throw new Error(
|
|
6889
6871
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
|
|
@@ -6899,7 +6881,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6899
6881
|
const id = this._pool.generateId();
|
|
6900
6882
|
value._attach(id, this._pool);
|
|
6901
6883
|
this._pool.dispatch(
|
|
6902
|
-
value.
|
|
6884
|
+
value._toOpsWithOpId(this._id, position, this._pool),
|
|
6903
6885
|
[{ type: OpCode.DELETE_CRDT, id }],
|
|
6904
6886
|
/* @__PURE__ */ new Map([
|
|
6905
6887
|
[this._id, makeUpdate(this, [insertDelta(index, value)])]
|
|
@@ -6913,7 +6895,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6913
6895
|
* @param targetIndex The index where the element should be after moving.
|
|
6914
6896
|
*/
|
|
6915
6897
|
move(index, targetIndex) {
|
|
6916
|
-
_optionalChain([this, 'access',
|
|
6898
|
+
_optionalChain([this, 'access', _145 => _145._pool, 'optionalAccess', _146 => _146.assertStorageIsWritable, 'call', _147 => _147()]);
|
|
6917
6899
|
if (targetIndex < 0) {
|
|
6918
6900
|
throw new Error("targetIndex cannot be less than 0");
|
|
6919
6901
|
}
|
|
@@ -6971,7 +6953,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6971
6953
|
* @param index The index of the element to delete
|
|
6972
6954
|
*/
|
|
6973
6955
|
delete(index) {
|
|
6974
|
-
_optionalChain([this, 'access',
|
|
6956
|
+
_optionalChain([this, 'access', _148 => _148._pool, 'optionalAccess', _149 => _149.assertStorageIsWritable, 'call', _150 => _150()]);
|
|
6975
6957
|
if (index < 0 || index >= this.#items.length) {
|
|
6976
6958
|
throw new Error(
|
|
6977
6959
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -7004,7 +6986,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7004
6986
|
}
|
|
7005
6987
|
}
|
|
7006
6988
|
clear() {
|
|
7007
|
-
_optionalChain([this, 'access',
|
|
6989
|
+
_optionalChain([this, 'access', _151 => _151._pool, 'optionalAccess', _152 => _152.assertStorageIsWritable, 'call', _153 => _153()]);
|
|
7008
6990
|
if (this._pool) {
|
|
7009
6991
|
const ops = [];
|
|
7010
6992
|
const reverseOps = [];
|
|
@@ -7038,7 +7020,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7038
7020
|
}
|
|
7039
7021
|
}
|
|
7040
7022
|
set(index, item) {
|
|
7041
|
-
_optionalChain([this, 'access',
|
|
7023
|
+
_optionalChain([this, 'access', _154 => _154._pool, 'optionalAccess', _155 => _155.assertStorageIsWritable, 'call', _156 => _156()]);
|
|
7042
7024
|
if (index < 0 || index >= this.#items.length) {
|
|
7043
7025
|
throw new Error(
|
|
7044
7026
|
`Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
|
|
@@ -7058,12 +7040,12 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7058
7040
|
const storageUpdates = /* @__PURE__ */ new Map();
|
|
7059
7041
|
storageUpdates.set(this._id, makeUpdate(this, [setDelta(index, value)]));
|
|
7060
7042
|
const ops = HACK_addIntentAndDeletedIdToOperation(
|
|
7061
|
-
value.
|
|
7043
|
+
value._toOpsWithOpId(this._id, position, this._pool),
|
|
7062
7044
|
existingId
|
|
7063
7045
|
);
|
|
7064
7046
|
this.#unacknowledgedSets.set(position, nn(ops[0].opId));
|
|
7065
7047
|
const reverseOps = HACK_addIntentAndDeletedIdToOperation(
|
|
7066
|
-
existingItem._toOps(this._id, position
|
|
7048
|
+
existingItem._toOps(this._id, position),
|
|
7067
7049
|
id
|
|
7068
7050
|
);
|
|
7069
7051
|
this._pool.dispatch(ops, reverseOps, storageUpdates);
|
|
@@ -7184,7 +7166,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
7184
7166
|
#shiftItemPosition(index, key) {
|
|
7185
7167
|
const shiftedPosition = makePosition(
|
|
7186
7168
|
key,
|
|
7187
|
-
this.#items.length > index + 1 ? _optionalChain([this, 'access',
|
|
7169
|
+
this.#items.length > index + 1 ? _optionalChain([this, 'access', _157 => _157.#items, 'access', _158 => _158[index + 1], 'optionalAccess', _159 => _159._parentPos]) : void 0
|
|
7188
7170
|
);
|
|
7189
7171
|
this.#items[index]._setParentLink(this, shiftedPosition);
|
|
7190
7172
|
}
|
|
@@ -7302,21 +7284,20 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7302
7284
|
}
|
|
7303
7285
|
}
|
|
7304
7286
|
/** @internal */
|
|
7305
|
-
_toOps(parentId, parentKey
|
|
7287
|
+
_toOps(parentId, parentKey) {
|
|
7306
7288
|
if (this._id === void 0) {
|
|
7307
7289
|
throw new Error("Cannot serialize item is not attached");
|
|
7308
7290
|
}
|
|
7309
7291
|
const ops = [];
|
|
7310
7292
|
const op = {
|
|
7311
7293
|
id: this._id,
|
|
7312
|
-
opId: _optionalChain([pool, 'optionalAccess', _164 => _164.generateOpId, 'call', _165 => _165()]),
|
|
7313
7294
|
type: OpCode.CREATE_MAP,
|
|
7314
7295
|
parentId,
|
|
7315
7296
|
parentKey
|
|
7316
7297
|
};
|
|
7317
7298
|
ops.push(op);
|
|
7318
7299
|
for (const [key, value] of this.#map) {
|
|
7319
|
-
ops.push(...value._toOps(this._id, key
|
|
7300
|
+
ops.push(...value._toOps(this._id, key));
|
|
7320
7301
|
}
|
|
7321
7302
|
return ops;
|
|
7322
7303
|
}
|
|
@@ -7400,7 +7381,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7400
7381
|
_detachChild(child) {
|
|
7401
7382
|
const id = nn(this._id);
|
|
7402
7383
|
const parentKey = nn(child._parentKey);
|
|
7403
|
-
const reverse = child._toOps(id, parentKey
|
|
7384
|
+
const reverse = child._toOps(id, parentKey);
|
|
7404
7385
|
for (const [key, value] of this.#map) {
|
|
7405
7386
|
if (value === child) {
|
|
7406
7387
|
this.#map.delete(key);
|
|
@@ -7449,7 +7430,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7449
7430
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
7450
7431
|
*/
|
|
7451
7432
|
set(key, value) {
|
|
7452
|
-
_optionalChain([this, 'access',
|
|
7433
|
+
_optionalChain([this, 'access', _160 => _160._pool, 'optionalAccess', _161 => _161.assertStorageIsWritable, 'call', _162 => _162()]);
|
|
7453
7434
|
const oldValue = this.#map.get(key);
|
|
7454
7435
|
if (oldValue) {
|
|
7455
7436
|
oldValue._detach();
|
|
@@ -7467,10 +7448,10 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7467
7448
|
type: "LiveMap",
|
|
7468
7449
|
updates: { [key]: { type: "update" } }
|
|
7469
7450
|
});
|
|
7470
|
-
const ops = item.
|
|
7451
|
+
const ops = item._toOpsWithOpId(this._id, key, this._pool);
|
|
7471
7452
|
this.#unacknowledgedSet.set(key, nn(ops[0].opId));
|
|
7472
7453
|
this._pool.dispatch(
|
|
7473
|
-
|
|
7454
|
+
ops,
|
|
7474
7455
|
oldValue ? oldValue._toOps(this._id, key) : [{ type: OpCode.DELETE_CRDT, id }],
|
|
7475
7456
|
storageUpdates
|
|
7476
7457
|
);
|
|
@@ -7495,7 +7476,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7495
7476
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
7496
7477
|
*/
|
|
7497
7478
|
delete(key) {
|
|
7498
|
-
_optionalChain([this, 'access',
|
|
7479
|
+
_optionalChain([this, 'access', _163 => _163._pool, 'optionalAccess', _164 => _164.assertStorageIsWritable, 'call', _165 => _165()]);
|
|
7499
7480
|
const item = this.#map.get(key);
|
|
7500
7481
|
if (item === void 0) {
|
|
7501
7482
|
return false;
|
|
@@ -7630,12 +7611,25 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7630
7611
|
|
|
7631
7612
|
// src/crdts/LiveObject.ts
|
|
7632
7613
|
var MAX_LIVE_OBJECT_SIZE = 128 * 1024;
|
|
7633
|
-
function
|
|
7614
|
+
function isRootCrdt(id, _) {
|
|
7634
7615
|
return id === "root";
|
|
7635
7616
|
}
|
|
7636
7617
|
var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
7637
7618
|
#map;
|
|
7638
|
-
|
|
7619
|
+
/**
|
|
7620
|
+
* Tracks unacknowledged local changes per property to preserve optimistic
|
|
7621
|
+
* updates. Maps property keys to their pending operation IDs.
|
|
7622
|
+
*
|
|
7623
|
+
* INVARIANT: Only locally-generated opIds are ever stored here. Remote opIds
|
|
7624
|
+
* are only compared against (to detect ACKs), never stored.
|
|
7625
|
+
*
|
|
7626
|
+
* When a local change is made, the opId is stored here. When a remote op
|
|
7627
|
+
* arrives for the same key:
|
|
7628
|
+
* - If no entry exists → apply remote op
|
|
7629
|
+
* - If opId matches → it's an ACK, clear the entry
|
|
7630
|
+
* - If opId differs → ignore remote op to preserve optimistic update
|
|
7631
|
+
*/
|
|
7632
|
+
#unackedOpsByKey;
|
|
7639
7633
|
/**
|
|
7640
7634
|
* Enable or disable detection of too large LiveObjects.
|
|
7641
7635
|
* When enabled, throws an error if LiveObject static data exceeds 128KB, which
|
|
@@ -7650,7 +7644,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7650
7644
|
const parentToChildren = /* @__PURE__ */ new Map();
|
|
7651
7645
|
let root = null;
|
|
7652
7646
|
for (const [id, crdt] of items) {
|
|
7653
|
-
if (
|
|
7647
|
+
if (isRootCrdt(id, crdt)) {
|
|
7654
7648
|
root = crdt;
|
|
7655
7649
|
} else {
|
|
7656
7650
|
const tuple = [id, crdt];
|
|
@@ -7668,8 +7662,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7668
7662
|
return [root, parentToChildren];
|
|
7669
7663
|
}
|
|
7670
7664
|
/** @private Do not use this API directly */
|
|
7671
|
-
static _fromItems(
|
|
7672
|
-
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(
|
|
7665
|
+
static _fromItems(items, pool) {
|
|
7666
|
+
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(items);
|
|
7673
7667
|
return _LiveObject._deserialize(
|
|
7674
7668
|
["root", root],
|
|
7675
7669
|
parentToChildren,
|
|
@@ -7678,7 +7672,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7678
7672
|
}
|
|
7679
7673
|
constructor(obj = {}) {
|
|
7680
7674
|
super();
|
|
7681
|
-
this.#
|
|
7675
|
+
this.#unackedOpsByKey = /* @__PURE__ */ new Map();
|
|
7682
7676
|
const o = compactObject(obj);
|
|
7683
7677
|
for (const key of Object.keys(o)) {
|
|
7684
7678
|
const value = o[key];
|
|
@@ -7689,16 +7683,14 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7689
7683
|
this.#map = new Map(Object.entries(o));
|
|
7690
7684
|
}
|
|
7691
7685
|
/** @internal */
|
|
7692
|
-
_toOps(parentId, parentKey
|
|
7686
|
+
_toOps(parentId, parentKey) {
|
|
7693
7687
|
if (this._id === void 0) {
|
|
7694
7688
|
throw new Error("Cannot serialize item is not attached");
|
|
7695
7689
|
}
|
|
7696
|
-
const opId = _optionalChain([pool, 'optionalAccess', _172 => _172.generateOpId, 'call', _173 => _173()]);
|
|
7697
7690
|
const ops = [];
|
|
7698
7691
|
const op = {
|
|
7699
7692
|
type: OpCode.CREATE_OBJECT,
|
|
7700
7693
|
id: this._id,
|
|
7701
|
-
opId,
|
|
7702
7694
|
parentId,
|
|
7703
7695
|
parentKey,
|
|
7704
7696
|
data: {}
|
|
@@ -7706,7 +7698,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7706
7698
|
ops.push(op);
|
|
7707
7699
|
for (const [key, value] of this.#map) {
|
|
7708
7700
|
if (isLiveNode(value)) {
|
|
7709
|
-
ops.push(...value._toOps(this._id, key
|
|
7701
|
+
ops.push(...value._toOps(this._id, key));
|
|
7710
7702
|
} else {
|
|
7711
7703
|
op.data[key] = value;
|
|
7712
7704
|
}
|
|
@@ -7752,16 +7744,16 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7752
7744
|
const { id, opId, parentKey: key } = op;
|
|
7753
7745
|
const child = creationOpToLson(op);
|
|
7754
7746
|
if (this._pool.getNode(id) !== void 0) {
|
|
7755
|
-
if (this.#
|
|
7756
|
-
this.#
|
|
7747
|
+
if (this.#unackedOpsByKey.get(key) === opId) {
|
|
7748
|
+
this.#unackedOpsByKey.delete(key);
|
|
7757
7749
|
}
|
|
7758
7750
|
return { modified: false };
|
|
7759
7751
|
}
|
|
7760
7752
|
if (source === 0 /* LOCAL */) {
|
|
7761
|
-
this.#
|
|
7762
|
-
} else if (this.#
|
|
7763
|
-
} else if (this.#
|
|
7764
|
-
this.#
|
|
7753
|
+
this.#unackedOpsByKey.set(key, nn(opId));
|
|
7754
|
+
} else if (this.#unackedOpsByKey.get(key) === void 0) {
|
|
7755
|
+
} else if (this.#unackedOpsByKey.get(key) === opId) {
|
|
7756
|
+
this.#unackedOpsByKey.delete(key);
|
|
7765
7757
|
return { modified: false };
|
|
7766
7758
|
} else {
|
|
7767
7759
|
return { modified: false };
|
|
@@ -7803,7 +7795,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7803
7795
|
if (child) {
|
|
7804
7796
|
const id = nn(this._id);
|
|
7805
7797
|
const parentKey = nn(child._parentKey);
|
|
7806
|
-
const reverse = child._toOps(id, parentKey
|
|
7798
|
+
const reverse = child._toOps(id, parentKey);
|
|
7807
7799
|
for (const [key, value] of this.#map) {
|
|
7808
7800
|
if (value === child) {
|
|
7809
7801
|
this.#map.delete(key);
|
|
@@ -7889,11 +7881,11 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7889
7881
|
continue;
|
|
7890
7882
|
}
|
|
7891
7883
|
if (isLocal) {
|
|
7892
|
-
this.#
|
|
7893
|
-
} else if (this.#
|
|
7884
|
+
this.#unackedOpsByKey.set(key, nn(op.opId));
|
|
7885
|
+
} else if (this.#unackedOpsByKey.get(key) === void 0) {
|
|
7894
7886
|
isModified = true;
|
|
7895
|
-
} else if (this.#
|
|
7896
|
-
this.#
|
|
7887
|
+
} else if (this.#unackedOpsByKey.get(key) === op.opId) {
|
|
7888
|
+
this.#unackedOpsByKey.delete(key);
|
|
7897
7889
|
continue;
|
|
7898
7890
|
} else {
|
|
7899
7891
|
continue;
|
|
@@ -7925,7 +7917,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7925
7917
|
if (oldValue === void 0) {
|
|
7926
7918
|
return { modified: false };
|
|
7927
7919
|
}
|
|
7928
|
-
if (!isLocal && this.#
|
|
7920
|
+
if (!isLocal && this.#unackedOpsByKey.get(key) !== void 0) {
|
|
7929
7921
|
return { modified: false };
|
|
7930
7922
|
}
|
|
7931
7923
|
const id = nn(this._id);
|
|
@@ -7967,7 +7959,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7967
7959
|
* @param value The value of the property to add
|
|
7968
7960
|
*/
|
|
7969
7961
|
set(key, value) {
|
|
7970
|
-
_optionalChain([this, 'access',
|
|
7962
|
+
_optionalChain([this, 'access', _166 => _166._pool, 'optionalAccess', _167 => _167.assertStorageIsWritable, 'call', _168 => _168()]);
|
|
7971
7963
|
this.update({ [key]: value });
|
|
7972
7964
|
}
|
|
7973
7965
|
/**
|
|
@@ -7982,7 +7974,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7982
7974
|
* @param key The key of the property to delete
|
|
7983
7975
|
*/
|
|
7984
7976
|
delete(key) {
|
|
7985
|
-
_optionalChain([this, 'access',
|
|
7977
|
+
_optionalChain([this, 'access', _169 => _169._pool, 'optionalAccess', _170 => _170.assertStorageIsWritable, 'call', _171 => _171()]);
|
|
7986
7978
|
const keyAsString = key;
|
|
7987
7979
|
const oldValue = this.#map.get(keyAsString);
|
|
7988
7980
|
if (oldValue === void 0) {
|
|
@@ -8037,7 +8029,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8037
8029
|
* @param patch The object used to overrides properties
|
|
8038
8030
|
*/
|
|
8039
8031
|
update(patch) {
|
|
8040
|
-
_optionalChain([this, 'access',
|
|
8032
|
+
_optionalChain([this, 'access', _172 => _172._pool, 'optionalAccess', _173 => _173.assertStorageIsWritable, 'call', _174 => _174()]);
|
|
8041
8033
|
if (_LiveObject.detectLargeObjects) {
|
|
8042
8034
|
const data = {};
|
|
8043
8035
|
for (const [key, value] of this.#map) {
|
|
@@ -8108,17 +8100,21 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
8108
8100
|
if (isLiveNode(newValue)) {
|
|
8109
8101
|
newValue._setParentLink(this, key);
|
|
8110
8102
|
newValue._attach(this._pool.generateId(), this._pool);
|
|
8111
|
-
const newAttachChildOps = newValue.
|
|
8103
|
+
const newAttachChildOps = newValue._toOpsWithOpId(
|
|
8104
|
+
this._id,
|
|
8105
|
+
key,
|
|
8106
|
+
this._pool
|
|
8107
|
+
);
|
|
8112
8108
|
const createCrdtOp = newAttachChildOps.find(
|
|
8113
8109
|
(op) => op.parentId === this._id
|
|
8114
8110
|
);
|
|
8115
8111
|
if (createCrdtOp) {
|
|
8116
|
-
this.#
|
|
8112
|
+
this.#unackedOpsByKey.set(key, nn(createCrdtOp.opId));
|
|
8117
8113
|
}
|
|
8118
8114
|
ops.push(...newAttachChildOps);
|
|
8119
8115
|
} else {
|
|
8120
8116
|
updatedProps[key] = newValue;
|
|
8121
|
-
this.#
|
|
8117
|
+
this.#unackedOpsByKey.set(key, opId);
|
|
8122
8118
|
}
|
|
8123
8119
|
this.#map.set(key, newValue);
|
|
8124
8120
|
this.invalidate();
|
|
@@ -8288,7 +8284,10 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8288
8284
|
const ops = [];
|
|
8289
8285
|
currentItems.forEach((_, id) => {
|
|
8290
8286
|
if (!newItems.get(id)) {
|
|
8291
|
-
ops.push({
|
|
8287
|
+
ops.push({
|
|
8288
|
+
type: OpCode.DELETE_CRDT,
|
|
8289
|
+
id
|
|
8290
|
+
});
|
|
8292
8291
|
}
|
|
8293
8292
|
});
|
|
8294
8293
|
newItems.forEach((crdt, id) => {
|
|
@@ -8511,7 +8510,10 @@ var ClientMsgCode = Object.freeze({
|
|
|
8511
8510
|
UPDATE_STORAGE: 201,
|
|
8512
8511
|
// For Yjs support
|
|
8513
8512
|
FETCH_YDOC: 300,
|
|
8514
|
-
UPDATE_YDOC: 301
|
|
8513
|
+
UPDATE_YDOC: 301,
|
|
8514
|
+
// For Agent Sessions
|
|
8515
|
+
FETCH_AGENT_SESSIONS: 500,
|
|
8516
|
+
FETCH_AGENT_MESSAGES: 502
|
|
8515
8517
|
});
|
|
8516
8518
|
|
|
8517
8519
|
// src/refs/ManagedOthers.ts
|
|
@@ -8713,6 +8715,8 @@ function defaultMessageFromContext(context) {
|
|
|
8713
8715
|
return "Could not delete thread";
|
|
8714
8716
|
case "EDIT_THREAD_METADATA_ERROR":
|
|
8715
8717
|
return "Could not edit thread metadata";
|
|
8718
|
+
case "EDIT_COMMENT_METADATA_ERROR":
|
|
8719
|
+
return "Could not edit comment metadata";
|
|
8716
8720
|
case "MARK_THREAD_AS_RESOLVED_ERROR":
|
|
8717
8721
|
return "Could not mark thread as resolved";
|
|
8718
8722
|
case "MARK_THREAD_AS_UNRESOLVED_ERROR":
|
|
@@ -8774,33 +8778,18 @@ function installBackgroundTabSpy() {
|
|
|
8774
8778
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
8775
8779
|
const inBackgroundSince = { current: null };
|
|
8776
8780
|
function onVisibilityChange() {
|
|
8777
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
8781
|
+
if (_optionalChain([doc, 'optionalAccess', _175 => _175.visibilityState]) === "hidden") {
|
|
8778
8782
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
8779
8783
|
} else {
|
|
8780
8784
|
inBackgroundSince.current = null;
|
|
8781
8785
|
}
|
|
8782
8786
|
}
|
|
8783
|
-
_optionalChain([doc, 'optionalAccess',
|
|
8787
|
+
_optionalChain([doc, 'optionalAccess', _176 => _176.addEventListener, 'call', _177 => _177("visibilitychange", onVisibilityChange)]);
|
|
8784
8788
|
const unsub = () => {
|
|
8785
|
-
_optionalChain([doc, 'optionalAccess',
|
|
8789
|
+
_optionalChain([doc, 'optionalAccess', _178 => _178.removeEventListener, 'call', _179 => _179("visibilitychange", onVisibilityChange)]);
|
|
8786
8790
|
};
|
|
8787
8791
|
return [inBackgroundSince, unsub];
|
|
8788
8792
|
}
|
|
8789
|
-
function makePartialNodeMap() {
|
|
8790
|
-
let map = /* @__PURE__ */ new Map();
|
|
8791
|
-
return {
|
|
8792
|
-
append(chunk2) {
|
|
8793
|
-
for (const [id, node] of chunk2) {
|
|
8794
|
-
map.set(id, node);
|
|
8795
|
-
}
|
|
8796
|
-
},
|
|
8797
|
-
clear() {
|
|
8798
|
-
const result = map;
|
|
8799
|
-
map = /* @__PURE__ */ new Map();
|
|
8800
|
-
return result;
|
|
8801
|
-
}
|
|
8802
|
-
};
|
|
8803
|
-
}
|
|
8804
8793
|
function createRoom(options, config) {
|
|
8805
8794
|
const roomId = config.roomId;
|
|
8806
8795
|
const initialPresence = options.initialPresence;
|
|
@@ -8861,7 +8850,6 @@ function createRoom(options, config) {
|
|
|
8861
8850
|
activeBatch: null,
|
|
8862
8851
|
unacknowledgedOps: /* @__PURE__ */ new Map()
|
|
8863
8852
|
};
|
|
8864
|
-
const partialNodes = makePartialNodeMap();
|
|
8865
8853
|
let lastTokenKey;
|
|
8866
8854
|
function onStatusDidChange(newStatus) {
|
|
8867
8855
|
const authValue = managedSocket.authValue;
|
|
@@ -8966,7 +8954,7 @@ function createRoom(options, config) {
|
|
|
8966
8954
|
}
|
|
8967
8955
|
}
|
|
8968
8956
|
function isStorageWritable() {
|
|
8969
|
-
const scopes = _optionalChain([context, 'access',
|
|
8957
|
+
const scopes = _optionalChain([context, 'access', _180 => _180.dynamicSessionInfoSig, 'access', _181 => _181.get, 'call', _182 => _182(), 'optionalAccess', _183 => _183.scopes]);
|
|
8970
8958
|
return scopes !== void 0 ? canWriteStorage(scopes) : true;
|
|
8971
8959
|
}
|
|
8972
8960
|
const eventHub = {
|
|
@@ -8983,6 +8971,7 @@ function createRoom(options, config) {
|
|
|
8983
8971
|
storageStatus: makeEventSource(),
|
|
8984
8972
|
ydoc: makeEventSource(),
|
|
8985
8973
|
comments: makeEventSource(),
|
|
8974
|
+
agentSessions: makeEventSource(),
|
|
8986
8975
|
roomWillDestroy: makeEventSource()
|
|
8987
8976
|
};
|
|
8988
8977
|
async function createTextMention(mentionId, mention) {
|
|
@@ -9097,7 +9086,7 @@ function createRoom(options, config) {
|
|
|
9097
9086
|
// be stuck in "synchronizing" forever).
|
|
9098
9087
|
case "experimental-fallback-to-http": {
|
|
9099
9088
|
warn("Message is too large for websockets, so sending over HTTP instead");
|
|
9100
|
-
const nonce = _nullishCoalesce(_optionalChain([context, 'access',
|
|
9089
|
+
const nonce = _nullishCoalesce(_optionalChain([context, 'access', _184 => _184.dynamicSessionInfoSig, 'access', _185 => _185.get, 'call', _186 => _186(), 'optionalAccess', _187 => _187.nonce]), () => ( raise("Session is not authorized to send message over HTTP")));
|
|
9101
9090
|
void httpClient.sendMessagesOverHTTP({ roomId, nonce, messages }).then((resp) => {
|
|
9102
9091
|
if (!resp.ok && resp.status === 403) {
|
|
9103
9092
|
managedSocket.reconnect();
|
|
@@ -9143,13 +9132,16 @@ function createRoom(options, config) {
|
|
|
9143
9132
|
self,
|
|
9144
9133
|
(me) => me !== null ? userToTreeNode("Me", me) : null
|
|
9145
9134
|
);
|
|
9146
|
-
function createOrUpdateRootFromMessage(
|
|
9135
|
+
function createOrUpdateRootFromMessage(message) {
|
|
9136
|
+
if (message.items.length === 0) {
|
|
9137
|
+
throw new Error("Internal error: cannot load storage without items");
|
|
9138
|
+
}
|
|
9147
9139
|
if (context.root !== void 0) {
|
|
9148
|
-
updateRoot(
|
|
9140
|
+
updateRoot(message.items);
|
|
9149
9141
|
} else {
|
|
9150
|
-
context.root = LiveObject._fromItems(
|
|
9142
|
+
context.root = LiveObject._fromItems(message.items, context.pool);
|
|
9151
9143
|
}
|
|
9152
|
-
const canWrite = _nullishCoalesce(_optionalChain([self, 'access',
|
|
9144
|
+
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _188 => _188.get, 'call', _189 => _189(), 'optionalAccess', _190 => _190.canWrite]), () => ( true));
|
|
9153
9145
|
const stackSizeBefore = context.undoStack.length;
|
|
9154
9146
|
for (const key in context.initialStorage) {
|
|
9155
9147
|
if (context.root.get(key) === void 0) {
|
|
@@ -9164,10 +9156,7 @@ function createRoom(options, config) {
|
|
|
9164
9156
|
}
|
|
9165
9157
|
context.undoStack.length = stackSizeBefore;
|
|
9166
9158
|
}
|
|
9167
|
-
function updateRoot(
|
|
9168
|
-
if (nodes.size === 0) {
|
|
9169
|
-
throw new Error("Internal error: cannot load storage without items");
|
|
9170
|
-
}
|
|
9159
|
+
function updateRoot(items) {
|
|
9171
9160
|
if (context.root === void 0) {
|
|
9172
9161
|
return;
|
|
9173
9162
|
}
|
|
@@ -9175,26 +9164,22 @@ function createRoom(options, config) {
|
|
|
9175
9164
|
for (const [id, node] of context.pool.nodes) {
|
|
9176
9165
|
currentItems.set(id, node._serialize());
|
|
9177
9166
|
}
|
|
9178
|
-
const ops = getTreesDiffOperations(currentItems,
|
|
9179
|
-
const result =
|
|
9180
|
-
ops,
|
|
9181
|
-
/* isLocal */
|
|
9182
|
-
false
|
|
9183
|
-
);
|
|
9167
|
+
const ops = getTreesDiffOperations(currentItems, new Map(items));
|
|
9168
|
+
const result = applyRemoteOps(ops);
|
|
9184
9169
|
notify(result.updates);
|
|
9185
9170
|
}
|
|
9186
|
-
function _addToRealUndoStack(
|
|
9171
|
+
function _addToRealUndoStack(frames) {
|
|
9187
9172
|
if (context.undoStack.length >= 50) {
|
|
9188
9173
|
context.undoStack.shift();
|
|
9189
9174
|
}
|
|
9190
|
-
context.undoStack.push(
|
|
9175
|
+
context.undoStack.push(frames);
|
|
9191
9176
|
onHistoryChange();
|
|
9192
9177
|
}
|
|
9193
|
-
function addToUndoStack(
|
|
9178
|
+
function addToUndoStack(frames) {
|
|
9194
9179
|
if (context.pausedHistory !== null) {
|
|
9195
|
-
context.pausedHistory.pushLeft(
|
|
9180
|
+
context.pausedHistory.pushLeft(frames);
|
|
9196
9181
|
} else {
|
|
9197
|
-
_addToRealUndoStack(
|
|
9182
|
+
_addToRealUndoStack(frames);
|
|
9198
9183
|
}
|
|
9199
9184
|
}
|
|
9200
9185
|
function notify(updates) {
|
|
@@ -9225,69 +9210,85 @@ function createRoom(options, config) {
|
|
|
9225
9210
|
"Internal. Tried to get connection id but connection was never open"
|
|
9226
9211
|
);
|
|
9227
9212
|
}
|
|
9228
|
-
function
|
|
9213
|
+
function applyLocalOps(frames) {
|
|
9214
|
+
const [pframes, ops] = partition(
|
|
9215
|
+
frames,
|
|
9216
|
+
(f) => f.type === "presence"
|
|
9217
|
+
);
|
|
9218
|
+
const opsWithOpIds = ops.map(
|
|
9219
|
+
(op) => op.opId === void 0 ? { ...op, opId: context.pool.generateOpId() } : op
|
|
9220
|
+
);
|
|
9221
|
+
const { reverse, updates } = applyOps(
|
|
9222
|
+
pframes,
|
|
9223
|
+
opsWithOpIds,
|
|
9224
|
+
/* isLocal */
|
|
9225
|
+
true
|
|
9226
|
+
);
|
|
9227
|
+
return { opsToEmit: opsWithOpIds, reverse, updates };
|
|
9228
|
+
}
|
|
9229
|
+
function applyRemoteOps(ops) {
|
|
9230
|
+
return applyOps(
|
|
9231
|
+
[],
|
|
9232
|
+
ops,
|
|
9233
|
+
/* isLocal */
|
|
9234
|
+
false
|
|
9235
|
+
);
|
|
9236
|
+
}
|
|
9237
|
+
function applyOps(pframes, ops, isLocal) {
|
|
9229
9238
|
const output = {
|
|
9230
9239
|
reverse: new Deque(),
|
|
9231
9240
|
storageUpdates: /* @__PURE__ */ new Map(),
|
|
9232
9241
|
presence: false
|
|
9233
9242
|
};
|
|
9234
|
-
const
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9243
|
+
for (const pf of pframes) {
|
|
9244
|
+
const reverse = {
|
|
9245
|
+
type: "presence",
|
|
9246
|
+
data: {}
|
|
9247
|
+
};
|
|
9248
|
+
for (const key in pf.data) {
|
|
9249
|
+
reverse.data[key] = context.myPresence.get()[key];
|
|
9250
|
+
}
|
|
9251
|
+
context.myPresence.patch(pf.data);
|
|
9252
|
+
if (context.buffer.presenceUpdates === null) {
|
|
9253
|
+
context.buffer.presenceUpdates = { type: "partial", data: pf.data };
|
|
9238
9254
|
} else {
|
|
9239
|
-
|
|
9255
|
+
for (const key in pf.data) {
|
|
9256
|
+
context.buffer.presenceUpdates.data[key] = pf.data[key];
|
|
9257
|
+
}
|
|
9240
9258
|
}
|
|
9241
|
-
|
|
9259
|
+
output.reverse.pushLeft(reverse);
|
|
9260
|
+
output.presence = true;
|
|
9261
|
+
}
|
|
9262
|
+
const createdNodeIds = /* @__PURE__ */ new Set();
|
|
9242
9263
|
for (const op of ops) {
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
reverse.data[key] = context.myPresence.get()[key];
|
|
9250
|
-
}
|
|
9251
|
-
context.myPresence.patch(op.data);
|
|
9252
|
-
if (context.buffer.presenceUpdates === null) {
|
|
9253
|
-
context.buffer.presenceUpdates = { type: "partial", data: op.data };
|
|
9254
|
-
} else {
|
|
9255
|
-
for (const key in op.data) {
|
|
9256
|
-
context.buffer.presenceUpdates.data[key] = op.data[key];
|
|
9257
|
-
}
|
|
9258
|
-
}
|
|
9259
|
-
output.reverse.pushLeft(reverse);
|
|
9260
|
-
output.presence = true;
|
|
9264
|
+
let source;
|
|
9265
|
+
if (isLocal) {
|
|
9266
|
+
source = 0 /* LOCAL */;
|
|
9267
|
+
} else if (op.opId !== void 0) {
|
|
9268
|
+
context.unacknowledgedOps.delete(op.opId);
|
|
9269
|
+
source = 2 /* OURS */;
|
|
9261
9270
|
} else {
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9271
|
+
source = 1 /* THEIRS */;
|
|
9272
|
+
}
|
|
9273
|
+
const applyOpResult = applyOp(op, source);
|
|
9274
|
+
if (applyOpResult.modified) {
|
|
9275
|
+
const nodeId = applyOpResult.modified.node._id;
|
|
9276
|
+
if (!(nodeId && createdNodeIds.has(nodeId))) {
|
|
9277
|
+
output.storageUpdates.set(
|
|
9278
|
+
nn(applyOpResult.modified.node._id),
|
|
9279
|
+
mergeStorageUpdates(
|
|
9280
|
+
output.storageUpdates.get(nn(applyOpResult.modified.node._id)),
|
|
9281
|
+
applyOpResult.modified
|
|
9282
|
+
)
|
|
9283
|
+
);
|
|
9284
|
+
output.reverse.pushLeft(applyOpResult.reverse);
|
|
9269
9285
|
}
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
const nodeId = applyOpResult.modified.node._id;
|
|
9273
|
-
if (!(nodeId && createdNodeIds.has(nodeId))) {
|
|
9274
|
-
output.storageUpdates.set(
|
|
9275
|
-
nn(applyOpResult.modified.node._id),
|
|
9276
|
-
mergeStorageUpdates(
|
|
9277
|
-
output.storageUpdates.get(nn(applyOpResult.modified.node._id)),
|
|
9278
|
-
applyOpResult.modified
|
|
9279
|
-
)
|
|
9280
|
-
);
|
|
9281
|
-
output.reverse.pushLeft(applyOpResult.reverse);
|
|
9282
|
-
}
|
|
9283
|
-
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
9284
|
-
createdNodeIds.add(nn(op.id));
|
|
9285
|
-
}
|
|
9286
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
9287
|
+
createdNodeIds.add(op.id);
|
|
9286
9288
|
}
|
|
9287
9289
|
}
|
|
9288
9290
|
}
|
|
9289
9291
|
return {
|
|
9290
|
-
ops,
|
|
9291
9292
|
reverse: Array.from(output.reverse),
|
|
9292
9293
|
updates: {
|
|
9293
9294
|
storageUpdates: output.storageUpdates,
|
|
@@ -9356,7 +9357,7 @@ function createRoom(options, config) {
|
|
|
9356
9357
|
}
|
|
9357
9358
|
context.myPresence.patch(patch);
|
|
9358
9359
|
if (context.activeBatch) {
|
|
9359
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
9360
|
+
if (_optionalChain([options2, 'optionalAccess', _191 => _191.addToHistory])) {
|
|
9360
9361
|
context.activeBatch.reverseOps.pushLeft({
|
|
9361
9362
|
type: "presence",
|
|
9362
9363
|
data: oldValues
|
|
@@ -9365,7 +9366,7 @@ function createRoom(options, config) {
|
|
|
9365
9366
|
context.activeBatch.updates.presence = true;
|
|
9366
9367
|
} else {
|
|
9367
9368
|
flushNowOrSoon();
|
|
9368
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
9369
|
+
if (_optionalChain([options2, 'optionalAccess', _192 => _192.addToHistory])) {
|
|
9369
9370
|
addToUndoStack([{ type: "presence", data: oldValues }]);
|
|
9370
9371
|
}
|
|
9371
9372
|
notify({ presence: true });
|
|
@@ -9472,20 +9473,16 @@ function createRoom(options, config) {
|
|
|
9472
9473
|
return compact([parseServerMessage(data)]);
|
|
9473
9474
|
}
|
|
9474
9475
|
}
|
|
9475
|
-
function
|
|
9476
|
-
if (
|
|
9476
|
+
function applyAndSendOfflineOps(unackedOps) {
|
|
9477
|
+
if (unackedOps.size === 0) {
|
|
9477
9478
|
return;
|
|
9478
9479
|
}
|
|
9479
9480
|
const messages = [];
|
|
9480
|
-
const inOps = Array.from(
|
|
9481
|
-
const result =
|
|
9482
|
-
inOps,
|
|
9483
|
-
/* isLocal */
|
|
9484
|
-
true
|
|
9485
|
-
);
|
|
9481
|
+
const inOps = Array.from(unackedOps.values());
|
|
9482
|
+
const result = applyLocalOps(inOps);
|
|
9486
9483
|
messages.push({
|
|
9487
9484
|
type: ClientMsgCode.UPDATE_STORAGE,
|
|
9488
|
-
ops: result.
|
|
9485
|
+
ops: result.opsToEmit
|
|
9489
9486
|
});
|
|
9490
9487
|
notify(result.updates);
|
|
9491
9488
|
sendMessages(messages);
|
|
@@ -9542,18 +9539,12 @@ function createRoom(options, config) {
|
|
|
9542
9539
|
updates.others.push(onRoomStateMessage(message));
|
|
9543
9540
|
break;
|
|
9544
9541
|
}
|
|
9545
|
-
case ServerMsgCode.
|
|
9546
|
-
|
|
9547
|
-
break;
|
|
9548
|
-
case ServerMsgCode.STORAGE_STREAM_END:
|
|
9549
|
-
processInitialStorage(partialNodes.clear());
|
|
9542
|
+
case ServerMsgCode.STORAGE_STATE: {
|
|
9543
|
+
processInitialStorage(message);
|
|
9550
9544
|
break;
|
|
9545
|
+
}
|
|
9551
9546
|
case ServerMsgCode.UPDATE_STORAGE: {
|
|
9552
|
-
const applyResult =
|
|
9553
|
-
message.ops,
|
|
9554
|
-
/* isLocal */
|
|
9555
|
-
false
|
|
9556
|
-
);
|
|
9547
|
+
const applyResult = applyRemoteOps(message.ops);
|
|
9557
9548
|
for (const [key, value] of applyResult.updates.storageUpdates) {
|
|
9558
9549
|
updates.storageUpdates.set(
|
|
9559
9550
|
key,
|
|
@@ -9586,12 +9577,50 @@ function createRoom(options, config) {
|
|
|
9586
9577
|
case ServerMsgCode.COMMENT_REACTION_REMOVED:
|
|
9587
9578
|
case ServerMsgCode.COMMENT_CREATED:
|
|
9588
9579
|
case ServerMsgCode.COMMENT_EDITED:
|
|
9589
|
-
case ServerMsgCode.COMMENT_DELETED:
|
|
9580
|
+
case ServerMsgCode.COMMENT_DELETED:
|
|
9581
|
+
case ServerMsgCode.COMMENT_METADATA_UPDATED: {
|
|
9590
9582
|
eventHub.comments.notify(message);
|
|
9591
9583
|
break;
|
|
9592
9584
|
}
|
|
9593
|
-
case ServerMsgCode.
|
|
9594
|
-
|
|
9585
|
+
case ServerMsgCode.AGENT_SESSIONS: {
|
|
9586
|
+
const agentSessionsMsg = message;
|
|
9587
|
+
if (agentSessionsMsg.operation === "list") {
|
|
9588
|
+
for (const [
|
|
9589
|
+
requestId,
|
|
9590
|
+
{ resolve }
|
|
9591
|
+
] of pendingAgentSessionsRequests) {
|
|
9592
|
+
resolve({
|
|
9593
|
+
sessions: agentSessionsMsg.sessions,
|
|
9594
|
+
nextCursor: agentSessionsMsg.nextCursor
|
|
9595
|
+
});
|
|
9596
|
+
pendingAgentSessionsRequests.delete(requestId);
|
|
9597
|
+
break;
|
|
9598
|
+
}
|
|
9599
|
+
}
|
|
9600
|
+
eventHub.agentSessions.notify(agentSessionsMsg);
|
|
9601
|
+
break;
|
|
9602
|
+
}
|
|
9603
|
+
case ServerMsgCode.AGENT_MESSAGES: {
|
|
9604
|
+
const agentMessagesMsg = message;
|
|
9605
|
+
if (agentMessagesMsg.operation === "list") {
|
|
9606
|
+
for (const [
|
|
9607
|
+
requestId,
|
|
9608
|
+
{ resolve }
|
|
9609
|
+
] of pendingAgentMessagesRequests) {
|
|
9610
|
+
const parsedRequestId = JSON.parse(requestId);
|
|
9611
|
+
if (parsedRequestId.sessionId === agentMessagesMsg.sessionId) {
|
|
9612
|
+
resolve({
|
|
9613
|
+
messages: agentMessagesMsg.messages,
|
|
9614
|
+
nextCursor: agentMessagesMsg.nextCursor
|
|
9615
|
+
});
|
|
9616
|
+
pendingAgentMessagesRequests.delete(requestId);
|
|
9617
|
+
break;
|
|
9618
|
+
}
|
|
9619
|
+
}
|
|
9620
|
+
}
|
|
9621
|
+
eventHub.agentSessions.notify(agentMessagesMsg);
|
|
9622
|
+
break;
|
|
9623
|
+
}
|
|
9595
9624
|
default:
|
|
9596
9625
|
break;
|
|
9597
9626
|
}
|
|
@@ -9602,7 +9631,7 @@ function createRoom(options, config) {
|
|
|
9602
9631
|
const storageOps = context.buffer.storageOperations;
|
|
9603
9632
|
if (storageOps.length > 0) {
|
|
9604
9633
|
for (const op of storageOps) {
|
|
9605
|
-
context.unacknowledgedOps.set(
|
|
9634
|
+
context.unacknowledgedOps.set(op.opId, op);
|
|
9606
9635
|
}
|
|
9607
9636
|
notifyStorageStatus();
|
|
9608
9637
|
}
|
|
@@ -9693,18 +9722,20 @@ function createRoom(options, config) {
|
|
|
9693
9722
|
}
|
|
9694
9723
|
let _getStorage$ = null;
|
|
9695
9724
|
let _resolveStoragePromise = null;
|
|
9696
|
-
|
|
9725
|
+
const pendingAgentSessionsRequests = /* @__PURE__ */ new Map();
|
|
9726
|
+
const pendingAgentMessagesRequests = /* @__PURE__ */ new Map();
|
|
9727
|
+
function processInitialStorage(message) {
|
|
9697
9728
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
9698
|
-
createOrUpdateRootFromMessage(
|
|
9699
|
-
|
|
9700
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
9729
|
+
createOrUpdateRootFromMessage(message);
|
|
9730
|
+
applyAndSendOfflineOps(unacknowledgedOps);
|
|
9731
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _193 => _193()]);
|
|
9701
9732
|
notifyStorageStatus();
|
|
9702
9733
|
eventHub.storageDidLoad.notify();
|
|
9703
9734
|
}
|
|
9704
9735
|
async function streamStorage() {
|
|
9705
9736
|
if (!managedSocket.authValue) return;
|
|
9706
|
-
const
|
|
9707
|
-
processInitialStorage(
|
|
9737
|
+
const items = await httpClient.streamStorage({ roomId });
|
|
9738
|
+
processInitialStorage({ type: ServerMsgCode.STORAGE_STATE, items });
|
|
9708
9739
|
}
|
|
9709
9740
|
function refreshStorage(options2) {
|
|
9710
9741
|
const messages = context.buffer.messages;
|
|
@@ -9712,7 +9743,6 @@ function createRoom(options, config) {
|
|
|
9712
9743
|
void streamStorage();
|
|
9713
9744
|
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
9714
9745
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
9715
|
-
partialNodes.clear();
|
|
9716
9746
|
}
|
|
9717
9747
|
if (options2.flush) {
|
|
9718
9748
|
flushNowOrSoon();
|
|
@@ -9761,27 +9791,80 @@ function createRoom(options, config) {
|
|
|
9761
9791
|
}
|
|
9762
9792
|
flushNowOrSoon();
|
|
9763
9793
|
}
|
|
9794
|
+
async function fetchAgentSessions(options2) {
|
|
9795
|
+
const requestId = JSON.stringify({
|
|
9796
|
+
cursor: _optionalChain([options2, 'optionalAccess', _194 => _194.cursor]),
|
|
9797
|
+
since: _optionalChain([options2, 'optionalAccess', _195 => _195.since]),
|
|
9798
|
+
limit: _optionalChain([options2, 'optionalAccess', _196 => _196.limit]),
|
|
9799
|
+
metadata: _optionalChain([options2, 'optionalAccess', _197 => _197.metadata])
|
|
9800
|
+
});
|
|
9801
|
+
const { promise, resolve, reject } = Promise_withResolvers();
|
|
9802
|
+
pendingAgentSessionsRequests.set(requestId, { resolve, reject });
|
|
9803
|
+
const message = {
|
|
9804
|
+
type: ClientMsgCode.FETCH_AGENT_SESSIONS,
|
|
9805
|
+
cursor: _optionalChain([options2, 'optionalAccess', _198 => _198.cursor]),
|
|
9806
|
+
since: _optionalChain([options2, 'optionalAccess', _199 => _199.since]),
|
|
9807
|
+
limit: _optionalChain([options2, 'optionalAccess', _200 => _200.limit]),
|
|
9808
|
+
metadata: _optionalChain([options2, 'optionalAccess', _201 => _201.metadata])
|
|
9809
|
+
};
|
|
9810
|
+
context.buffer.messages.push(message);
|
|
9811
|
+
flushNowOrSoon();
|
|
9812
|
+
setTimeout(() => {
|
|
9813
|
+
if (pendingAgentSessionsRequests.has(requestId)) {
|
|
9814
|
+
pendingAgentSessionsRequests.delete(requestId);
|
|
9815
|
+
reject(new Error("Agent sessions fetch timeout"));
|
|
9816
|
+
}
|
|
9817
|
+
}, 3e4);
|
|
9818
|
+
return promise;
|
|
9819
|
+
}
|
|
9820
|
+
async function fetchAgentMessages(sessionId, options2) {
|
|
9821
|
+
const requestId = JSON.stringify({
|
|
9822
|
+
sessionId,
|
|
9823
|
+
cursor: _optionalChain([options2, 'optionalAccess', _202 => _202.cursor]),
|
|
9824
|
+
since: _optionalChain([options2, 'optionalAccess', _203 => _203.since]),
|
|
9825
|
+
limit: _optionalChain([options2, 'optionalAccess', _204 => _204.limit])
|
|
9826
|
+
});
|
|
9827
|
+
const existingRequest = pendingAgentMessagesRequests.get(requestId);
|
|
9828
|
+
if (existingRequest) {
|
|
9829
|
+
return new Promise((resolve2, reject2) => {
|
|
9830
|
+
existingRequest.resolve = resolve2;
|
|
9831
|
+
existingRequest.reject = reject2;
|
|
9832
|
+
});
|
|
9833
|
+
}
|
|
9834
|
+
const { promise, resolve, reject } = Promise_withResolvers();
|
|
9835
|
+
pendingAgentMessagesRequests.set(requestId, { resolve, reject });
|
|
9836
|
+
const message = {
|
|
9837
|
+
type: ClientMsgCode.FETCH_AGENT_MESSAGES,
|
|
9838
|
+
sessionId,
|
|
9839
|
+
cursor: _optionalChain([options2, 'optionalAccess', _205 => _205.cursor]),
|
|
9840
|
+
since: _optionalChain([options2, 'optionalAccess', _206 => _206.since]),
|
|
9841
|
+
limit: _optionalChain([options2, 'optionalAccess', _207 => _207.limit])
|
|
9842
|
+
};
|
|
9843
|
+
context.buffer.messages.push(message);
|
|
9844
|
+
flushNowOrSoon();
|
|
9845
|
+
setTimeout(() => {
|
|
9846
|
+
if (pendingAgentMessagesRequests.has(requestId)) {
|
|
9847
|
+
pendingAgentMessagesRequests.delete(requestId);
|
|
9848
|
+
reject(new Error("Agent messages fetch timeout"));
|
|
9849
|
+
}
|
|
9850
|
+
}, 3e4);
|
|
9851
|
+
return promise;
|
|
9852
|
+
}
|
|
9764
9853
|
function undo() {
|
|
9765
9854
|
if (context.activeBatch) {
|
|
9766
9855
|
throw new Error("undo is not allowed during a batch");
|
|
9767
9856
|
}
|
|
9768
|
-
const
|
|
9769
|
-
if (
|
|
9857
|
+
const frames = context.undoStack.pop();
|
|
9858
|
+
if (frames === void 0) {
|
|
9770
9859
|
return;
|
|
9771
9860
|
}
|
|
9772
9861
|
context.pausedHistory = null;
|
|
9773
|
-
const result =
|
|
9774
|
-
historyOps,
|
|
9775
|
-
/* isLocal */
|
|
9776
|
-
true
|
|
9777
|
-
);
|
|
9862
|
+
const result = applyLocalOps(frames);
|
|
9778
9863
|
notify(result.updates);
|
|
9779
9864
|
context.redoStack.push(result.reverse);
|
|
9780
9865
|
onHistoryChange();
|
|
9781
|
-
for (const op of result.
|
|
9782
|
-
|
|
9783
|
-
context.buffer.storageOperations.push(op);
|
|
9784
|
-
}
|
|
9866
|
+
for (const op of result.opsToEmit) {
|
|
9867
|
+
context.buffer.storageOperations.push(op);
|
|
9785
9868
|
}
|
|
9786
9869
|
flushNowOrSoon();
|
|
9787
9870
|
}
|
|
@@ -9789,23 +9872,17 @@ function createRoom(options, config) {
|
|
|
9789
9872
|
if (context.activeBatch) {
|
|
9790
9873
|
throw new Error("redo is not allowed during a batch");
|
|
9791
9874
|
}
|
|
9792
|
-
const
|
|
9793
|
-
if (
|
|
9875
|
+
const frames = context.redoStack.pop();
|
|
9876
|
+
if (frames === void 0) {
|
|
9794
9877
|
return;
|
|
9795
9878
|
}
|
|
9796
9879
|
context.pausedHistory = null;
|
|
9797
|
-
const result =
|
|
9798
|
-
historyOps,
|
|
9799
|
-
/* isLocal */
|
|
9800
|
-
true
|
|
9801
|
-
);
|
|
9880
|
+
const result = applyLocalOps(frames);
|
|
9802
9881
|
notify(result.updates);
|
|
9803
9882
|
context.undoStack.push(result.reverse);
|
|
9804
9883
|
onHistoryChange();
|
|
9805
|
-
for (const op of result.
|
|
9806
|
-
|
|
9807
|
-
context.buffer.storageOperations.push(op);
|
|
9808
|
-
}
|
|
9884
|
+
for (const op of result.opsToEmit) {
|
|
9885
|
+
context.buffer.storageOperations.push(op);
|
|
9809
9886
|
}
|
|
9810
9887
|
flushNowOrSoon();
|
|
9811
9888
|
}
|
|
@@ -9852,10 +9929,10 @@ function createRoom(options, config) {
|
|
|
9852
9929
|
}
|
|
9853
9930
|
}
|
|
9854
9931
|
function resumeHistory() {
|
|
9855
|
-
const
|
|
9932
|
+
const frames = context.pausedHistory;
|
|
9856
9933
|
context.pausedHistory = null;
|
|
9857
|
-
if (
|
|
9858
|
-
_addToRealUndoStack(Array.from(
|
|
9934
|
+
if (frames !== null && frames.length > 0) {
|
|
9935
|
+
_addToRealUndoStack(Array.from(frames));
|
|
9859
9936
|
}
|
|
9860
9937
|
}
|
|
9861
9938
|
const syncSourceForStorage = config.createSyncSource();
|
|
@@ -9915,6 +9992,7 @@ function createRoom(options, config) {
|
|
|
9915
9992
|
storageStatus: eventHub.storageStatus.observable,
|
|
9916
9993
|
ydoc: eventHub.ydoc.observable,
|
|
9917
9994
|
comments: eventHub.comments.observable,
|
|
9995
|
+
agentSessions: eventHub.agentSessions.observable,
|
|
9918
9996
|
roomWillDestroy: eventHub.roomWillDestroy.observable
|
|
9919
9997
|
};
|
|
9920
9998
|
async function getThreadsSince(options2) {
|
|
@@ -9927,8 +10005,8 @@ function createRoom(options, config) {
|
|
|
9927
10005
|
async function getThreads(options2) {
|
|
9928
10006
|
return httpClient.getThreads({
|
|
9929
10007
|
roomId,
|
|
9930
|
-
query: _optionalChain([options2, 'optionalAccess',
|
|
9931
|
-
cursor: _optionalChain([options2, 'optionalAccess',
|
|
10008
|
+
query: _optionalChain([options2, 'optionalAccess', _208 => _208.query]),
|
|
10009
|
+
cursor: _optionalChain([options2, 'optionalAccess', _209 => _209.cursor])
|
|
9932
10010
|
});
|
|
9933
10011
|
}
|
|
9934
10012
|
async function getThread(threadId) {
|
|
@@ -9941,6 +10019,7 @@ function createRoom(options, config) {
|
|
|
9941
10019
|
commentId: options2.commentId,
|
|
9942
10020
|
metadata: options2.metadata,
|
|
9943
10021
|
body: options2.body,
|
|
10022
|
+
commentMetadata: options2.commentMetadata,
|
|
9944
10023
|
attachmentIds: options2.attachmentIds
|
|
9945
10024
|
});
|
|
9946
10025
|
}
|
|
@@ -9953,6 +10032,18 @@ function createRoom(options, config) {
|
|
|
9953
10032
|
}) {
|
|
9954
10033
|
return httpClient.editThreadMetadata({ roomId, threadId, metadata });
|
|
9955
10034
|
}
|
|
10035
|
+
async function editCommentMetadata({
|
|
10036
|
+
threadId,
|
|
10037
|
+
commentId,
|
|
10038
|
+
metadata
|
|
10039
|
+
}) {
|
|
10040
|
+
return httpClient.editCommentMetadata({
|
|
10041
|
+
roomId,
|
|
10042
|
+
threadId,
|
|
10043
|
+
commentId,
|
|
10044
|
+
metadata
|
|
10045
|
+
});
|
|
10046
|
+
}
|
|
9956
10047
|
async function markThreadAsResolved(threadId) {
|
|
9957
10048
|
return httpClient.markThreadAsResolved({ roomId, threadId });
|
|
9958
10049
|
}
|
|
@@ -9974,6 +10065,7 @@ function createRoom(options, config) {
|
|
|
9974
10065
|
threadId: options2.threadId,
|
|
9975
10066
|
commentId: options2.commentId,
|
|
9976
10067
|
body: options2.body,
|
|
10068
|
+
metadata: options2.metadata,
|
|
9977
10069
|
attachmentIds: options2.attachmentIds
|
|
9978
10070
|
});
|
|
9979
10071
|
}
|
|
@@ -9983,6 +10075,7 @@ function createRoom(options, config) {
|
|
|
9983
10075
|
threadId: options2.threadId,
|
|
9984
10076
|
commentId: options2.commentId,
|
|
9985
10077
|
body: options2.body,
|
|
10078
|
+
metadata: options2.metadata,
|
|
9986
10079
|
attachmentIds: options2.attachmentIds
|
|
9987
10080
|
});
|
|
9988
10081
|
}
|
|
@@ -10035,7 +10128,7 @@ function createRoom(options, config) {
|
|
|
10035
10128
|
function getSubscriptionSettings(options2) {
|
|
10036
10129
|
return httpClient.getSubscriptionSettings({
|
|
10037
10130
|
roomId,
|
|
10038
|
-
signal: _optionalChain([options2, 'optionalAccess',
|
|
10131
|
+
signal: _optionalChain([options2, 'optionalAccess', _210 => _210.signal])
|
|
10039
10132
|
});
|
|
10040
10133
|
}
|
|
10041
10134
|
function updateSubscriptionSettings(settings) {
|
|
@@ -10057,7 +10150,7 @@ function createRoom(options, config) {
|
|
|
10057
10150
|
{
|
|
10058
10151
|
[kInternal]: {
|
|
10059
10152
|
get presenceBuffer() {
|
|
10060
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
10153
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _211 => _211.buffer, 'access', _212 => _212.presenceUpdates, 'optionalAccess', _213 => _213.data]), () => ( null)));
|
|
10061
10154
|
},
|
|
10062
10155
|
// prettier-ignore
|
|
10063
10156
|
get undoStack() {
|
|
@@ -10072,9 +10165,9 @@ function createRoom(options, config) {
|
|
|
10072
10165
|
return context.yjsProvider;
|
|
10073
10166
|
},
|
|
10074
10167
|
setYjsProvider(newProvider) {
|
|
10075
|
-
_optionalChain([context, 'access',
|
|
10168
|
+
_optionalChain([context, 'access', _214 => _214.yjsProvider, 'optionalAccess', _215 => _215.off, 'call', _216 => _216("status", yjsStatusDidChange)]);
|
|
10076
10169
|
context.yjsProvider = newProvider;
|
|
10077
|
-
_optionalChain([newProvider, 'optionalAccess',
|
|
10170
|
+
_optionalChain([newProvider, 'optionalAccess', _217 => _217.on, 'call', _218 => _218("status", yjsStatusDidChange)]);
|
|
10078
10171
|
context.yjsProviderDidChange.notify();
|
|
10079
10172
|
},
|
|
10080
10173
|
yjsProviderDidChange: context.yjsProviderDidChange.observable,
|
|
@@ -10108,7 +10201,7 @@ function createRoom(options, config) {
|
|
|
10108
10201
|
id: roomId,
|
|
10109
10202
|
subscribe: makeClassicSubscribeFn(
|
|
10110
10203
|
roomId,
|
|
10111
|
-
|
|
10204
|
+
eventHub,
|
|
10112
10205
|
config.errorEventSource
|
|
10113
10206
|
),
|
|
10114
10207
|
connect: () => managedSocket.connect(),
|
|
@@ -10120,7 +10213,7 @@ function createRoom(options, config) {
|
|
|
10120
10213
|
source.dispose();
|
|
10121
10214
|
}
|
|
10122
10215
|
eventHub.roomWillDestroy.notify();
|
|
10123
|
-
_optionalChain([context, 'access',
|
|
10216
|
+
_optionalChain([context, 'access', _219 => _219.yjsProvider, 'optionalAccess', _220 => _220.off, 'call', _221 => _221("status", yjsStatusDidChange)]);
|
|
10124
10217
|
syncSourceForStorage.destroy();
|
|
10125
10218
|
syncSourceForYjs.destroy();
|
|
10126
10219
|
uninstallBgTabSpy();
|
|
@@ -10143,6 +10236,8 @@ function createRoom(options, config) {
|
|
|
10143
10236
|
resume: resumeHistory
|
|
10144
10237
|
},
|
|
10145
10238
|
fetchYDoc,
|
|
10239
|
+
fetchAgentSessions,
|
|
10240
|
+
fetchAgentMessages,
|
|
10146
10241
|
getStorage,
|
|
10147
10242
|
getStorageSnapshot,
|
|
10148
10243
|
getStorageStatus,
|
|
@@ -10170,6 +10265,7 @@ function createRoom(options, config) {
|
|
|
10170
10265
|
unsubscribeFromThread,
|
|
10171
10266
|
createComment,
|
|
10172
10267
|
editComment,
|
|
10268
|
+
editCommentMetadata,
|
|
10173
10269
|
deleteComment,
|
|
10174
10270
|
addReaction,
|
|
10175
10271
|
removeReaction,
|
|
@@ -10270,7 +10366,7 @@ function makeClassicSubscribeFn(roomId, events, errorEvents) {
|
|
|
10270
10366
|
}
|
|
10271
10367
|
if (isLiveNode(first)) {
|
|
10272
10368
|
const node = first;
|
|
10273
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
10369
|
+
if (_optionalChain([options, 'optionalAccess', _222 => _222.isDeep])) {
|
|
10274
10370
|
const storageCallback = second;
|
|
10275
10371
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
10276
10372
|
} else {
|
|
@@ -10302,7 +10398,7 @@ function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill, eng
|
|
|
10302
10398
|
}
|
|
10303
10399
|
const url2 = new URL(baseUrl);
|
|
10304
10400
|
url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
|
|
10305
|
-
url2.pathname = "/
|
|
10401
|
+
url2.pathname = "/v7";
|
|
10306
10402
|
url2.searchParams.set("roomId", roomId);
|
|
10307
10403
|
if (authValue.type === "secret") {
|
|
10308
10404
|
url2.searchParams.set("tok", authValue.token.raw);
|
|
@@ -10353,8 +10449,8 @@ function createClient(options) {
|
|
|
10353
10449
|
const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
|
|
10354
10450
|
currentUserId.set(() => userId);
|
|
10355
10451
|
});
|
|
10356
|
-
const fetchPolyfill = _optionalChain([clientOptions, 'access',
|
|
10357
|
-
_optionalChain([globalThis, 'access',
|
|
10452
|
+
const fetchPolyfill = _optionalChain([clientOptions, 'access', _223 => _223.polyfills, 'optionalAccess', _224 => _224.fetch]) || /* istanbul ignore next */
|
|
10453
|
+
_optionalChain([globalThis, 'access', _225 => _225.fetch, 'optionalAccess', _226 => _226.bind, 'call', _227 => _227(globalThis)]);
|
|
10358
10454
|
const httpClient = createApiClient({
|
|
10359
10455
|
baseUrl,
|
|
10360
10456
|
fetchPolyfill,
|
|
@@ -10372,7 +10468,7 @@ function createClient(options) {
|
|
|
10372
10468
|
delegates: {
|
|
10373
10469
|
createSocket: makeCreateSocketDelegateForAi(
|
|
10374
10470
|
baseUrl,
|
|
10375
|
-
_optionalChain([clientOptions, 'access',
|
|
10471
|
+
_optionalChain([clientOptions, 'access', _228 => _228.polyfills, 'optionalAccess', _229 => _229.WebSocket])
|
|
10376
10472
|
),
|
|
10377
10473
|
authenticate: async () => {
|
|
10378
10474
|
const resp = await authManager.getAuthValue({
|
|
@@ -10434,7 +10530,7 @@ function createClient(options) {
|
|
|
10434
10530
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
10435
10531
|
roomId,
|
|
10436
10532
|
baseUrl,
|
|
10437
|
-
_optionalChain([clientOptions, 'access',
|
|
10533
|
+
_optionalChain([clientOptions, 'access', _230 => _230.polyfills, 'optionalAccess', _231 => _231.WebSocket]),
|
|
10438
10534
|
options2.engine
|
|
10439
10535
|
),
|
|
10440
10536
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
@@ -10459,7 +10555,7 @@ function createClient(options) {
|
|
|
10459
10555
|
const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
|
|
10460
10556
|
if (shouldConnect) {
|
|
10461
10557
|
if (typeof atob === "undefined") {
|
|
10462
|
-
if (_optionalChain([clientOptions, 'access',
|
|
10558
|
+
if (_optionalChain([clientOptions, 'access', _232 => _232.polyfills, 'optionalAccess', _233 => _233.atob]) === void 0) {
|
|
10463
10559
|
throw new Error(
|
|
10464
10560
|
"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"
|
|
10465
10561
|
);
|
|
@@ -10471,7 +10567,7 @@ function createClient(options) {
|
|
|
10471
10567
|
return leaseRoom(newRoomDetails);
|
|
10472
10568
|
}
|
|
10473
10569
|
function getRoom(roomId) {
|
|
10474
|
-
const room = _optionalChain([roomsById, 'access',
|
|
10570
|
+
const room = _optionalChain([roomsById, 'access', _234 => _234.get, 'call', _235 => _235(roomId), 'optionalAccess', _236 => _236.room]);
|
|
10475
10571
|
return room ? room : null;
|
|
10476
10572
|
}
|
|
10477
10573
|
function logout() {
|
|
@@ -10487,7 +10583,7 @@ function createClient(options) {
|
|
|
10487
10583
|
const batchedResolveUsers = new Batch(
|
|
10488
10584
|
async (batchedUserIds) => {
|
|
10489
10585
|
const userIds = batchedUserIds.flat();
|
|
10490
|
-
const users = await _optionalChain([resolveUsers, 'optionalCall',
|
|
10586
|
+
const users = await _optionalChain([resolveUsers, 'optionalCall', _237 => _237({ userIds })]);
|
|
10491
10587
|
warnOnceIf(
|
|
10492
10588
|
!resolveUsers,
|
|
10493
10589
|
"Set the resolveUsers option in createClient to specify user info."
|
|
@@ -10504,7 +10600,7 @@ function createClient(options) {
|
|
|
10504
10600
|
const batchedResolveRoomsInfo = new Batch(
|
|
10505
10601
|
async (batchedRoomIds) => {
|
|
10506
10602
|
const roomIds = batchedRoomIds.flat();
|
|
10507
|
-
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall',
|
|
10603
|
+
const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _238 => _238({ roomIds })]);
|
|
10508
10604
|
warnOnceIf(
|
|
10509
10605
|
!resolveRoomsInfo,
|
|
10510
10606
|
"Set the resolveRoomsInfo option in createClient to specify room info."
|
|
@@ -10521,7 +10617,7 @@ function createClient(options) {
|
|
|
10521
10617
|
const batchedResolveGroupsInfo = new Batch(
|
|
10522
10618
|
async (batchedGroupIds) => {
|
|
10523
10619
|
const groupIds = batchedGroupIds.flat();
|
|
10524
|
-
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall',
|
|
10620
|
+
const groupsInfo = await _optionalChain([resolveGroupsInfo, 'optionalCall', _239 => _239({ groupIds })]);
|
|
10525
10621
|
warnOnceIf(
|
|
10526
10622
|
!resolveGroupsInfo,
|
|
10527
10623
|
"Set the resolveGroupsInfo option in createClient to specify group info."
|
|
@@ -10577,7 +10673,7 @@ function createClient(options) {
|
|
|
10577
10673
|
}
|
|
10578
10674
|
};
|
|
10579
10675
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
10580
|
-
_optionalChain([win, 'optionalAccess',
|
|
10676
|
+
_optionalChain([win, 'optionalAccess', _240 => _240.addEventListener, 'call', _241 => _241("beforeunload", maybePreventClose)]);
|
|
10581
10677
|
}
|
|
10582
10678
|
async function getNotificationSettings(options2) {
|
|
10583
10679
|
const plainSettings = await httpClient.getNotificationSettings(options2);
|
|
@@ -10704,7 +10800,7 @@ var commentBodyElementsTypes = {
|
|
|
10704
10800
|
mention: "inline"
|
|
10705
10801
|
};
|
|
10706
10802
|
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
10707
|
-
if (!body || !_optionalChain([body, 'optionalAccess',
|
|
10803
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _242 => _242.content])) {
|
|
10708
10804
|
return;
|
|
10709
10805
|
}
|
|
10710
10806
|
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
@@ -10714,13 +10810,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
|
10714
10810
|
for (const block of body.content) {
|
|
10715
10811
|
if (type === "all" || type === "block") {
|
|
10716
10812
|
if (guard(block)) {
|
|
10717
|
-
_optionalChain([visitor, 'optionalCall',
|
|
10813
|
+
_optionalChain([visitor, 'optionalCall', _243 => _243(block)]);
|
|
10718
10814
|
}
|
|
10719
10815
|
}
|
|
10720
10816
|
if (type === "all" || type === "inline") {
|
|
10721
10817
|
for (const inline of block.children) {
|
|
10722
10818
|
if (guard(inline)) {
|
|
10723
|
-
_optionalChain([visitor, 'optionalCall',
|
|
10819
|
+
_optionalChain([visitor, 'optionalCall', _244 => _244(inline)]);
|
|
10724
10820
|
}
|
|
10725
10821
|
}
|
|
10726
10822
|
}
|
|
@@ -10890,7 +10986,7 @@ var stringifyCommentBodyPlainElements = {
|
|
|
10890
10986
|
text: ({ element }) => element.text,
|
|
10891
10987
|
link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
|
|
10892
10988
|
mention: ({ element, user, group }) => {
|
|
10893
|
-
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
10989
|
+
return `@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _245 => _245.name]), () => ( _optionalChain([group, 'optionalAccess', _246 => _246.name]))), () => ( element.id))}`;
|
|
10894
10990
|
}
|
|
10895
10991
|
};
|
|
10896
10992
|
var stringifyCommentBodyHtmlElements = {
|
|
@@ -10920,7 +11016,7 @@ var stringifyCommentBodyHtmlElements = {
|
|
|
10920
11016
|
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.text ? html`${element.text}` : element.url}</a>`;
|
|
10921
11017
|
},
|
|
10922
11018
|
mention: ({ element, user, group }) => {
|
|
10923
|
-
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess',
|
|
11019
|
+
return html`<span data-mention>@${_optionalChain([user, 'optionalAccess', _247 => _247.name]) ? html`${_optionalChain([user, 'optionalAccess', _248 => _248.name])}` : _optionalChain([group, 'optionalAccess', _249 => _249.name]) ? html`${_optionalChain([group, 'optionalAccess', _250 => _250.name])}` : element.id}</span>`;
|
|
10924
11020
|
}
|
|
10925
11021
|
};
|
|
10926
11022
|
var stringifyCommentBodyMarkdownElements = {
|
|
@@ -10950,20 +11046,20 @@ var stringifyCommentBodyMarkdownElements = {
|
|
|
10950
11046
|
return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
|
|
10951
11047
|
},
|
|
10952
11048
|
mention: ({ element, user, group }) => {
|
|
10953
|
-
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess',
|
|
11049
|
+
return markdown`@${_nullishCoalesce(_nullishCoalesce(_optionalChain([user, 'optionalAccess', _251 => _251.name]), () => ( _optionalChain([group, 'optionalAccess', _252 => _252.name]))), () => ( element.id))}`;
|
|
10954
11050
|
}
|
|
10955
11051
|
};
|
|
10956
11052
|
async function stringifyCommentBody(body, options) {
|
|
10957
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
10958
|
-
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
11053
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _253 => _253.format]), () => ( "plain"));
|
|
11054
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _254 => _254.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
10959
11055
|
const elements = {
|
|
10960
11056
|
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
10961
|
-
..._optionalChain([options, 'optionalAccess',
|
|
11057
|
+
..._optionalChain([options, 'optionalAccess', _255 => _255.elements])
|
|
10962
11058
|
};
|
|
10963
11059
|
const { users: resolvedUsers, groups: resolvedGroupsInfo } = await resolveMentionsInCommentBody(
|
|
10964
11060
|
body,
|
|
10965
|
-
_optionalChain([options, 'optionalAccess',
|
|
10966
|
-
_optionalChain([options, 'optionalAccess',
|
|
11061
|
+
_optionalChain([options, 'optionalAccess', _256 => _256.resolveUsers]),
|
|
11062
|
+
_optionalChain([options, 'optionalAccess', _257 => _257.resolveGroupsInfo])
|
|
10967
11063
|
);
|
|
10968
11064
|
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
10969
11065
|
switch (block.type) {
|
|
@@ -11094,9 +11190,9 @@ function lsonToJson(value) {
|
|
|
11094
11190
|
}
|
|
11095
11191
|
return value;
|
|
11096
11192
|
}
|
|
11097
|
-
function
|
|
11193
|
+
function _deepLiveify(value) {
|
|
11098
11194
|
if (Array.isArray(value)) {
|
|
11099
|
-
return new LiveList(value.map(
|
|
11195
|
+
return new LiveList(value.map(_deepLiveify));
|
|
11100
11196
|
} else if (isPlainObject(value)) {
|
|
11101
11197
|
const init = {};
|
|
11102
11198
|
for (const key in value) {
|
|
@@ -11104,7 +11200,7 @@ function deepLiveify(value) {
|
|
|
11104
11200
|
if (val === void 0) {
|
|
11105
11201
|
continue;
|
|
11106
11202
|
}
|
|
11107
|
-
init[key] =
|
|
11203
|
+
init[key] = _deepLiveify(val);
|
|
11108
11204
|
}
|
|
11109
11205
|
return new LiveObject(init);
|
|
11110
11206
|
} else {
|
|
@@ -11141,7 +11237,7 @@ function patchLiveList(liveList, prev, next) {
|
|
|
11141
11237
|
if (i > prevEnd) {
|
|
11142
11238
|
if (i <= nextEnd) {
|
|
11143
11239
|
while (i <= nextEnd) {
|
|
11144
|
-
liveList.insert(
|
|
11240
|
+
liveList.insert(_deepLiveify(next[i]), i);
|
|
11145
11241
|
i++;
|
|
11146
11242
|
}
|
|
11147
11243
|
}
|
|
@@ -11159,12 +11255,12 @@ function patchLiveList(liveList, prev, next) {
|
|
|
11159
11255
|
if (isLiveObject(liveListNode) && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
11160
11256
|
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
11161
11257
|
} else {
|
|
11162
|
-
liveList.set(i,
|
|
11258
|
+
liveList.set(i, _deepLiveify(nextNode));
|
|
11163
11259
|
}
|
|
11164
11260
|
i++;
|
|
11165
11261
|
}
|
|
11166
11262
|
while (i <= nextEnd) {
|
|
11167
|
-
liveList.insert(
|
|
11263
|
+
liveList.insert(_deepLiveify(next[i]), i);
|
|
11168
11264
|
i++;
|
|
11169
11265
|
}
|
|
11170
11266
|
let localI = i;
|
|
@@ -11191,7 +11287,7 @@ Only serializable value can be synced with Liveblocks.`
|
|
|
11191
11287
|
if (next === void 0) {
|
|
11192
11288
|
liveObject.delete(key);
|
|
11193
11289
|
} else if (value === void 0) {
|
|
11194
|
-
liveObject.set(key,
|
|
11290
|
+
liveObject.set(key, _deepLiveify(next));
|
|
11195
11291
|
} else if (prev === next) {
|
|
11196
11292
|
return;
|
|
11197
11293
|
} else if (isLiveList(value) && Array.isArray(prev) && Array.isArray(next)) {
|
|
@@ -11199,7 +11295,7 @@ Only serializable value can be synced with Liveblocks.`
|
|
|
11199
11295
|
} else if (isLiveObject(value) && isPlainObject(prev) && isPlainObject(next)) {
|
|
11200
11296
|
patchLiveObject(value, prev, next);
|
|
11201
11297
|
} else {
|
|
11202
|
-
liveObject.set(key,
|
|
11298
|
+
liveObject.set(key, _deepLiveify(next));
|
|
11203
11299
|
}
|
|
11204
11300
|
}
|
|
11205
11301
|
function patchLiveObject(root, prev, next) {
|
|
@@ -11250,12 +11346,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
11250
11346
|
}
|
|
11251
11347
|
const newState = Object.assign({}, state);
|
|
11252
11348
|
for (const key in update.updates) {
|
|
11253
|
-
if (_optionalChain([update, 'access',
|
|
11349
|
+
if (_optionalChain([update, 'access', _258 => _258.updates, 'access', _259 => _259[key], 'optionalAccess', _260 => _260.type]) === "update") {
|
|
11254
11350
|
const val = update.node.get(key);
|
|
11255
11351
|
if (val !== void 0) {
|
|
11256
11352
|
newState[key] = lsonToJson(val);
|
|
11257
11353
|
}
|
|
11258
|
-
} else if (_optionalChain([update, 'access',
|
|
11354
|
+
} else if (_optionalChain([update, 'access', _261 => _261.updates, 'access', _262 => _262[key], 'optionalAccess', _263 => _263.type]) === "delete") {
|
|
11259
11355
|
delete newState[key];
|
|
11260
11356
|
}
|
|
11261
11357
|
}
|
|
@@ -11316,12 +11412,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
11316
11412
|
}
|
|
11317
11413
|
const newState = Object.assign({}, state);
|
|
11318
11414
|
for (const key in update.updates) {
|
|
11319
|
-
if (_optionalChain([update, 'access',
|
|
11415
|
+
if (_optionalChain([update, 'access', _264 => _264.updates, 'access', _265 => _265[key], 'optionalAccess', _266 => _266.type]) === "update") {
|
|
11320
11416
|
const value = update.node.get(key);
|
|
11321
11417
|
if (value !== void 0) {
|
|
11322
11418
|
newState[key] = lsonToJson(value);
|
|
11323
11419
|
}
|
|
11324
|
-
} else if (_optionalChain([update, 'access',
|
|
11420
|
+
} else if (_optionalChain([update, 'access', _267 => _267.updates, 'access', _268 => _268[key], 'optionalAccess', _269 => _269.type]) === "delete") {
|
|
11325
11421
|
delete newState[key];
|
|
11326
11422
|
}
|
|
11327
11423
|
}
|
|
@@ -11401,9 +11497,9 @@ function makePoller(callback, intervalMs, options) {
|
|
|
11401
11497
|
const startTime = performance.now();
|
|
11402
11498
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
11403
11499
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
11404
|
-
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
11500
|
+
const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _270 => _270.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
|
|
11405
11501
|
const context = {
|
|
11406
|
-
inForeground: _optionalChain([doc, 'optionalAccess',
|
|
11502
|
+
inForeground: _optionalChain([doc, 'optionalAccess', _271 => _271.visibilityState]) !== "hidden",
|
|
11407
11503
|
lastSuccessfulPollAt: startTime,
|
|
11408
11504
|
count: 0,
|
|
11409
11505
|
backoff: 0
|
|
@@ -11484,11 +11580,11 @@ function makePoller(callback, intervalMs, options) {
|
|
|
11484
11580
|
pollNowIfStale();
|
|
11485
11581
|
}
|
|
11486
11582
|
function onVisibilityChange() {
|
|
11487
|
-
setInForeground(_optionalChain([doc, 'optionalAccess',
|
|
11583
|
+
setInForeground(_optionalChain([doc, 'optionalAccess', _272 => _272.visibilityState]) !== "hidden");
|
|
11488
11584
|
}
|
|
11489
|
-
_optionalChain([doc, 'optionalAccess',
|
|
11490
|
-
_optionalChain([win, 'optionalAccess',
|
|
11491
|
-
_optionalChain([win, 'optionalAccess',
|
|
11585
|
+
_optionalChain([doc, 'optionalAccess', _273 => _273.addEventListener, 'call', _274 => _274("visibilitychange", onVisibilityChange)]);
|
|
11586
|
+
_optionalChain([win, 'optionalAccess', _275 => _275.addEventListener, 'call', _276 => _276("online", onVisibilityChange)]);
|
|
11587
|
+
_optionalChain([win, 'optionalAccess', _277 => _277.addEventListener, 'call', _278 => _278("focus", pollNowIfStale)]);
|
|
11492
11588
|
fsm.start();
|
|
11493
11589
|
return {
|
|
11494
11590
|
inc,
|
|
@@ -11500,6 +11596,90 @@ function makePoller(callback, intervalMs, options) {
|
|
|
11500
11596
|
};
|
|
11501
11597
|
}
|
|
11502
11598
|
|
|
11599
|
+
// src/mutations.ts
|
|
11600
|
+
function generateOpsFromJson(nodes, mutation, actorId = 1) {
|
|
11601
|
+
const capturedOps = [];
|
|
11602
|
+
const pool = createManagedPool("mutation-temp", {
|
|
11603
|
+
getCurrentConnectionId: () => actorId,
|
|
11604
|
+
onDispatch: (ops) => {
|
|
11605
|
+
capturedOps.push(...ops);
|
|
11606
|
+
}
|
|
11607
|
+
});
|
|
11608
|
+
const root = LiveObject._fromItems(nodes, pool);
|
|
11609
|
+
if (isPlainObject(mutation)) {
|
|
11610
|
+
applyMutationToLiveObject(root, mutation);
|
|
11611
|
+
} else {
|
|
11612
|
+
throw new Error(
|
|
11613
|
+
"Root mutation must be an object. Use a nested key to update specific values."
|
|
11614
|
+
);
|
|
11615
|
+
}
|
|
11616
|
+
return capturedOps;
|
|
11617
|
+
}
|
|
11618
|
+
function applyMutationToLiveObject(target, mutation) {
|
|
11619
|
+
for (const key in mutation) {
|
|
11620
|
+
const mutationValue = mutation[key];
|
|
11621
|
+
if (mutationValue === void 0) {
|
|
11622
|
+
continue;
|
|
11623
|
+
}
|
|
11624
|
+
const existingValue = target.get(key);
|
|
11625
|
+
if (isLiveNode(mutationValue)) {
|
|
11626
|
+
target.set(key, mutationValue);
|
|
11627
|
+
continue;
|
|
11628
|
+
}
|
|
11629
|
+
if (isLiveObject(existingValue) && isPlainObject(mutationValue)) {
|
|
11630
|
+
applyMutationToLiveObject(
|
|
11631
|
+
existingValue,
|
|
11632
|
+
mutationValue
|
|
11633
|
+
);
|
|
11634
|
+
} else if (isLiveMap(existingValue) && isPlainObject(mutationValue)) {
|
|
11635
|
+
applyMutationToLiveMap(existingValue, mutationValue);
|
|
11636
|
+
} else if (isLiveList(existingValue) && Array.isArray(mutationValue)) {
|
|
11637
|
+
applyMutationToLiveList(existingValue, mutationValue);
|
|
11638
|
+
} else if (existingValue === void 0 && isPlainObject(mutationValue)) {
|
|
11639
|
+
const convertedValue = _deepLiveify(mutationValue);
|
|
11640
|
+
target.set(key, convertedValue);
|
|
11641
|
+
} else {
|
|
11642
|
+
target.set(key, mutationValue);
|
|
11643
|
+
}
|
|
11644
|
+
}
|
|
11645
|
+
}
|
|
11646
|
+
function applyMutationToLiveMap(target, mutation) {
|
|
11647
|
+
for (const key in mutation) {
|
|
11648
|
+
const mutationValue = mutation[key];
|
|
11649
|
+
if (mutationValue === void 0) {
|
|
11650
|
+
continue;
|
|
11651
|
+
}
|
|
11652
|
+
const existingValue = target.get(key);
|
|
11653
|
+
if (isLiveNode(mutationValue)) {
|
|
11654
|
+
target.set(key, mutationValue);
|
|
11655
|
+
continue;
|
|
11656
|
+
}
|
|
11657
|
+
if (isLiveObject(existingValue) && isPlainObject(mutationValue)) {
|
|
11658
|
+
applyMutationToLiveObject(
|
|
11659
|
+
existingValue,
|
|
11660
|
+
mutationValue
|
|
11661
|
+
);
|
|
11662
|
+
} else if (isLiveMap(existingValue) && isPlainObject(mutationValue)) {
|
|
11663
|
+
applyMutationToLiveMap(existingValue, mutationValue);
|
|
11664
|
+
} else if (isLiveList(existingValue) && Array.isArray(mutationValue)) {
|
|
11665
|
+
applyMutationToLiveList(existingValue, mutationValue);
|
|
11666
|
+
} else if (existingValue === void 0 && isPlainObject(mutationValue)) {
|
|
11667
|
+
const convertedValue = _deepLiveify(mutationValue);
|
|
11668
|
+
target.set(key, convertedValue);
|
|
11669
|
+
} else {
|
|
11670
|
+
const newValue = isLiveNode(mutationValue) ? mutationValue : mutationValue;
|
|
11671
|
+
target.set(key, newValue);
|
|
11672
|
+
}
|
|
11673
|
+
}
|
|
11674
|
+
}
|
|
11675
|
+
function applyMutationToLiveList(target, mutation) {
|
|
11676
|
+
target.clear();
|
|
11677
|
+
for (const item of mutation) {
|
|
11678
|
+
const liveItem = isLiveNode(item) ? item : item;
|
|
11679
|
+
target.push(liveItem);
|
|
11680
|
+
}
|
|
11681
|
+
}
|
|
11682
|
+
|
|
11503
11683
|
// src/protocol/Subscriptions.ts
|
|
11504
11684
|
function getSubscriptionKey(subscription, subjectId) {
|
|
11505
11685
|
if (typeof subscription === "string") {
|
|
@@ -11621,5 +11801,5 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
11621
11801
|
|
|
11622
11802
|
|
|
11623
11803
|
|
|
11624
|
-
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MENTION_CHARACTER = MENTION_CHARACTER; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isPlainObject = isPlainObject; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.
|
|
11804
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MENTION_CHARACTER = MENTION_CHARACTER; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateOpsFromJson = generateOpsFromJson; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isPlainObject = isPlainObject; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveMentionsInCommentBody = resolveMentionsInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
|
|
11625
11805
|
//# sourceMappingURL=index.cjs.map
|