@liveblocks/core 3.13.1-hackathon → 3.13.2
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 +54 -247
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -101
- package/dist/index.d.ts +3 -101
- package/dist/index.js +14 -207
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.13.
|
|
9
|
+
var PKG_VERSION = "3.13.2";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3132,9 +3132,6 @@ var ServerMsgCode = Object.freeze({
|
|
|
3132
3132
|
COMMENT_REACTION_ADDED: 405,
|
|
3133
3133
|
COMMENT_REACTION_REMOVED: 406,
|
|
3134
3134
|
COMMENT_METADATA_UPDATED: 409,
|
|
3135
|
-
// For Agent Sessions
|
|
3136
|
-
AGENT_SESSIONS: 501,
|
|
3137
|
-
AGENT_MESSAGES: 503,
|
|
3138
3135
|
// Error codes
|
|
3139
3136
|
REJECT_STORAGE_OP: 299
|
|
3140
3137
|
// Sent if a mutation was not allowed on the server (i.e. due to permissions, limit exceeded, etc)
|
|
@@ -6756,8 +6753,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6756
6753
|
}
|
|
6757
6754
|
child._setParentLink(this, newKey);
|
|
6758
6755
|
this._insertAndSort(child);
|
|
6756
|
+
const newIndex = this.#items.indexOf(child);
|
|
6759
6757
|
return {
|
|
6760
|
-
modified:
|
|
6758
|
+
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
6759
|
+
reverse: []
|
|
6761
6760
|
};
|
|
6762
6761
|
} else {
|
|
6763
6762
|
if (newKey === previousKey) {
|
|
@@ -8510,10 +8509,7 @@ var ClientMsgCode = Object.freeze({
|
|
|
8510
8509
|
UPDATE_STORAGE: 201,
|
|
8511
8510
|
// For Yjs support
|
|
8512
8511
|
FETCH_YDOC: 300,
|
|
8513
|
-
UPDATE_YDOC: 301
|
|
8514
|
-
// For Agent Sessions
|
|
8515
|
-
FETCH_AGENT_SESSIONS: 500,
|
|
8516
|
-
FETCH_AGENT_MESSAGES: 502
|
|
8512
|
+
UPDATE_YDOC: 301
|
|
8517
8513
|
});
|
|
8518
8514
|
|
|
8519
8515
|
// src/refs/ManagedOthers.ts
|
|
@@ -8971,7 +8967,6 @@ function createRoom(options, config) {
|
|
|
8971
8967
|
storageStatus: makeEventSource(),
|
|
8972
8968
|
ydoc: makeEventSource(),
|
|
8973
8969
|
comments: makeEventSource(),
|
|
8974
|
-
agentSessions: makeEventSource(),
|
|
8975
8970
|
roomWillDestroy: makeEventSource()
|
|
8976
8971
|
};
|
|
8977
8972
|
async function createTextMention(mentionId, mention) {
|
|
@@ -9582,45 +9577,6 @@ function createRoom(options, config) {
|
|
|
9582
9577
|
eventHub.comments.notify(message);
|
|
9583
9578
|
break;
|
|
9584
9579
|
}
|
|
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
|
-
}
|
|
9624
9580
|
default:
|
|
9625
9581
|
break;
|
|
9626
9582
|
}
|
|
@@ -9722,8 +9678,6 @@ function createRoom(options, config) {
|
|
|
9722
9678
|
}
|
|
9723
9679
|
let _getStorage$ = null;
|
|
9724
9680
|
let _resolveStoragePromise = null;
|
|
9725
|
-
const pendingAgentSessionsRequests = /* @__PURE__ */ new Map();
|
|
9726
|
-
const pendingAgentMessagesRequests = /* @__PURE__ */ new Map();
|
|
9727
9681
|
function processInitialStorage(message) {
|
|
9728
9682
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
9729
9683
|
createOrUpdateRootFromMessage(message);
|
|
@@ -9791,65 +9745,6 @@ function createRoom(options, config) {
|
|
|
9791
9745
|
}
|
|
9792
9746
|
flushNowOrSoon();
|
|
9793
9747
|
}
|
|
9794
|
-
async function fetchAgentSessions(options2) {
|
|
9795
|
-
const requestId = JSON.stringify({
|
|
9796
|
-
cursor: options2?.cursor,
|
|
9797
|
-
since: options2?.since,
|
|
9798
|
-
limit: options2?.limit,
|
|
9799
|
-
metadata: options2?.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: options2?.cursor,
|
|
9806
|
-
since: options2?.since,
|
|
9807
|
-
limit: options2?.limit,
|
|
9808
|
-
metadata: options2?.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: options2?.cursor,
|
|
9824
|
-
since: options2?.since,
|
|
9825
|
-
limit: options2?.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: options2?.cursor,
|
|
9840
|
-
since: options2?.since,
|
|
9841
|
-
limit: options2?.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
|
-
}
|
|
9853
9748
|
function undo() {
|
|
9854
9749
|
if (context.activeBatch) {
|
|
9855
9750
|
throw new Error("undo is not allowed during a batch");
|
|
@@ -9992,7 +9887,6 @@ function createRoom(options, config) {
|
|
|
9992
9887
|
storageStatus: eventHub.storageStatus.observable,
|
|
9993
9888
|
ydoc: eventHub.ydoc.observable,
|
|
9994
9889
|
comments: eventHub.comments.observable,
|
|
9995
|
-
agentSessions: eventHub.agentSessions.observable,
|
|
9996
9890
|
roomWillDestroy: eventHub.roomWillDestroy.observable
|
|
9997
9891
|
};
|
|
9998
9892
|
async function getThreadsSince(options2) {
|
|
@@ -10201,7 +10095,7 @@ function createRoom(options, config) {
|
|
|
10201
10095
|
id: roomId,
|
|
10202
10096
|
subscribe: makeClassicSubscribeFn(
|
|
10203
10097
|
roomId,
|
|
10204
|
-
|
|
10098
|
+
events,
|
|
10205
10099
|
config.errorEventSource
|
|
10206
10100
|
),
|
|
10207
10101
|
connect: () => managedSocket.connect(),
|
|
@@ -10236,8 +10130,6 @@ function createRoom(options, config) {
|
|
|
10236
10130
|
resume: resumeHistory
|
|
10237
10131
|
},
|
|
10238
10132
|
fetchYDoc,
|
|
10239
|
-
fetchAgentSessions,
|
|
10240
|
-
fetchAgentMessages,
|
|
10241
10133
|
getStorage,
|
|
10242
10134
|
getStorageSnapshot,
|
|
10243
10135
|
getStorageStatus,
|
|
@@ -11190,9 +11082,9 @@ function lsonToJson(value) {
|
|
|
11190
11082
|
}
|
|
11191
11083
|
return value;
|
|
11192
11084
|
}
|
|
11193
|
-
function
|
|
11085
|
+
function deepLiveify(value) {
|
|
11194
11086
|
if (Array.isArray(value)) {
|
|
11195
|
-
return new LiveList(value.map(
|
|
11087
|
+
return new LiveList(value.map(deepLiveify));
|
|
11196
11088
|
} else if (isPlainObject(value)) {
|
|
11197
11089
|
const init = {};
|
|
11198
11090
|
for (const key in value) {
|
|
@@ -11200,7 +11092,7 @@ function _deepLiveify(value) {
|
|
|
11200
11092
|
if (val === void 0) {
|
|
11201
11093
|
continue;
|
|
11202
11094
|
}
|
|
11203
|
-
init[key] =
|
|
11095
|
+
init[key] = deepLiveify(val);
|
|
11204
11096
|
}
|
|
11205
11097
|
return new LiveObject(init);
|
|
11206
11098
|
} else {
|
|
@@ -11237,7 +11129,7 @@ function patchLiveList(liveList, prev, next) {
|
|
|
11237
11129
|
if (i > prevEnd) {
|
|
11238
11130
|
if (i <= nextEnd) {
|
|
11239
11131
|
while (i <= nextEnd) {
|
|
11240
|
-
liveList.insert(
|
|
11132
|
+
liveList.insert(deepLiveify(next[i]), i);
|
|
11241
11133
|
i++;
|
|
11242
11134
|
}
|
|
11243
11135
|
}
|
|
@@ -11255,12 +11147,12 @@ function patchLiveList(liveList, prev, next) {
|
|
|
11255
11147
|
if (isLiveObject(liveListNode) && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
11256
11148
|
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
11257
11149
|
} else {
|
|
11258
|
-
liveList.set(i,
|
|
11150
|
+
liveList.set(i, deepLiveify(nextNode));
|
|
11259
11151
|
}
|
|
11260
11152
|
i++;
|
|
11261
11153
|
}
|
|
11262
11154
|
while (i <= nextEnd) {
|
|
11263
|
-
liveList.insert(
|
|
11155
|
+
liveList.insert(deepLiveify(next[i]), i);
|
|
11264
11156
|
i++;
|
|
11265
11157
|
}
|
|
11266
11158
|
let localI = i;
|
|
@@ -11287,7 +11179,7 @@ Only serializable value can be synced with Liveblocks.`
|
|
|
11287
11179
|
if (next === void 0) {
|
|
11288
11180
|
liveObject.delete(key);
|
|
11289
11181
|
} else if (value === void 0) {
|
|
11290
|
-
liveObject.set(key,
|
|
11182
|
+
liveObject.set(key, deepLiveify(next));
|
|
11291
11183
|
} else if (prev === next) {
|
|
11292
11184
|
return;
|
|
11293
11185
|
} else if (isLiveList(value) && Array.isArray(prev) && Array.isArray(next)) {
|
|
@@ -11295,7 +11187,7 @@ Only serializable value can be synced with Liveblocks.`
|
|
|
11295
11187
|
} else if (isLiveObject(value) && isPlainObject(prev) && isPlainObject(next)) {
|
|
11296
11188
|
patchLiveObject(value, prev, next);
|
|
11297
11189
|
} else {
|
|
11298
|
-
liveObject.set(key,
|
|
11190
|
+
liveObject.set(key, deepLiveify(next));
|
|
11299
11191
|
}
|
|
11300
11192
|
}
|
|
11301
11193
|
function patchLiveObject(root, prev, next) {
|
|
@@ -11596,90 +11488,6 @@ function makePoller(callback, intervalMs, options) {
|
|
|
11596
11488
|
};
|
|
11597
11489
|
}
|
|
11598
11490
|
|
|
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
|
-
|
|
11683
11491
|
// src/protocol/Subscriptions.ts
|
|
11684
11492
|
function getSubscriptionKey(subscription, subjectId) {
|
|
11685
11493
|
if (typeof subscription === "string") {
|
|
@@ -11752,7 +11560,6 @@ export {
|
|
|
11752
11560
|
errorIf,
|
|
11753
11561
|
findLastIndex,
|
|
11754
11562
|
freeze,
|
|
11755
|
-
generateOpsFromJson,
|
|
11756
11563
|
generateUrl,
|
|
11757
11564
|
getMentionsFromCommentBody,
|
|
11758
11565
|
getSubscriptionKey,
|