@liveblocks/core 3.12.0 → 3.12.1
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 +202 -203
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -66
- package/dist/index.d.ts +102 -66
- package/dist/index.js +161 -162
- 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.12.
|
|
9
|
+
var PKG_VERSION = "3.12.1";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3082,27 +3082,32 @@ var FSM = class {
|
|
|
3082
3082
|
};
|
|
3083
3083
|
|
|
3084
3084
|
// src/protocol/ServerMsg.ts
|
|
3085
|
-
var ServerMsgCode =
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3085
|
+
var ServerMsgCode = Object.freeze({
|
|
3086
|
+
// For Presence
|
|
3087
|
+
UPDATE_PRESENCE: 100,
|
|
3088
|
+
USER_JOINED: 101,
|
|
3089
|
+
USER_LEFT: 102,
|
|
3090
|
+
BROADCASTED_EVENT: 103,
|
|
3091
|
+
ROOM_STATE: 104,
|
|
3092
|
+
// For Storage
|
|
3093
|
+
INITIAL_STORAGE_STATE: 200,
|
|
3094
|
+
UPDATE_STORAGE: 201,
|
|
3095
|
+
// For Yjs Docs
|
|
3096
|
+
UPDATE_YDOC: 300,
|
|
3097
|
+
// For Comments
|
|
3098
|
+
THREAD_CREATED: 400,
|
|
3099
|
+
THREAD_DELETED: 407,
|
|
3100
|
+
THREAD_METADATA_UPDATED: 401,
|
|
3101
|
+
THREAD_UPDATED: 408,
|
|
3102
|
+
COMMENT_CREATED: 402,
|
|
3103
|
+
COMMENT_EDITED: 403,
|
|
3104
|
+
COMMENT_DELETED: 404,
|
|
3105
|
+
COMMENT_REACTION_ADDED: 405,
|
|
3106
|
+
COMMENT_REACTION_REMOVED: 406,
|
|
3107
|
+
// Error codes
|
|
3108
|
+
REJECT_STORAGE_OP: 299
|
|
3109
|
+
// Sent if a mutation was not allowed on the server (i.e. due to permissions, limit exceeded, etc)
|
|
3110
|
+
});
|
|
3106
3111
|
|
|
3107
3112
|
// src/types/IWebSocket.ts
|
|
3108
3113
|
var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
|
|
@@ -3403,7 +3408,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
3403
3408
|
}
|
|
3404
3409
|
function waitForActorId(event) {
|
|
3405
3410
|
const serverMsg = tryParseJson(event.data);
|
|
3406
|
-
if (serverMsg?.type ===
|
|
3411
|
+
if (serverMsg?.type === ServerMsgCode.ROOM_STATE) {
|
|
3407
3412
|
didReceiveActor();
|
|
3408
3413
|
}
|
|
3409
3414
|
}
|
|
@@ -5908,28 +5913,22 @@ function asPos(str) {
|
|
|
5908
5913
|
}
|
|
5909
5914
|
|
|
5910
5915
|
// src/protocol/Op.ts
|
|
5911
|
-
var OpCode =
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
// (H)ACK
|
|
5928
|
-
opId
|
|
5929
|
-
};
|
|
5930
|
-
}
|
|
5931
|
-
function isAckOp(op) {
|
|
5932
|
-
return op.type === 5 /* DELETE_CRDT */ && op.id === "ACK";
|
|
5916
|
+
var OpCode = Object.freeze({
|
|
5917
|
+
INIT: 0,
|
|
5918
|
+
SET_PARENT_KEY: 1,
|
|
5919
|
+
CREATE_LIST: 2,
|
|
5920
|
+
UPDATE_OBJECT: 3,
|
|
5921
|
+
CREATE_OBJECT: 4,
|
|
5922
|
+
DELETE_CRDT: 5,
|
|
5923
|
+
DELETE_OBJECT_KEY: 6,
|
|
5924
|
+
CREATE_MAP: 7,
|
|
5925
|
+
CREATE_REGISTER: 8,
|
|
5926
|
+
ACK: 9
|
|
5927
|
+
// Will only appear in v8+
|
|
5928
|
+
});
|
|
5929
|
+
function isAck(op) {
|
|
5930
|
+
return op.type === OpCode.ACK || // >= v8
|
|
5931
|
+
op.type === OpCode.DELETE_CRDT && op.id === "ACK";
|
|
5933
5932
|
}
|
|
5934
5933
|
|
|
5935
5934
|
// src/crdts/AbstractCrdt.ts
|
|
@@ -6034,7 +6033,7 @@ var AbstractCrdt = class {
|
|
|
6034
6033
|
/** @internal */
|
|
6035
6034
|
_apply(op, _isLocal) {
|
|
6036
6035
|
switch (op.type) {
|
|
6037
|
-
case
|
|
6036
|
+
case OpCode.DELETE_CRDT: {
|
|
6038
6037
|
if (this.parent.type === "HasParent") {
|
|
6039
6038
|
return this.parent.node._detachChild(crdtAsLiveNode(this));
|
|
6040
6039
|
}
|
|
@@ -6138,13 +6137,12 @@ var AbstractCrdt = class {
|
|
|
6138
6137
|
};
|
|
6139
6138
|
|
|
6140
6139
|
// src/protocol/SerializedCrdt.ts
|
|
6141
|
-
var CrdtType =
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
})(CrdtType || {});
|
|
6140
|
+
var CrdtType = Object.freeze({
|
|
6141
|
+
OBJECT: 0,
|
|
6142
|
+
LIST: 1,
|
|
6143
|
+
MAP: 2,
|
|
6144
|
+
REGISTER: 3
|
|
6145
|
+
});
|
|
6148
6146
|
|
|
6149
6147
|
// src/crdts/LiveRegister.ts
|
|
6150
6148
|
var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
@@ -6171,7 +6169,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
6171
6169
|
}
|
|
6172
6170
|
return [
|
|
6173
6171
|
{
|
|
6174
|
-
type:
|
|
6172
|
+
type: OpCode.CREATE_REGISTER,
|
|
6175
6173
|
opId: pool?.generateOpId(),
|
|
6176
6174
|
id: this._id,
|
|
6177
6175
|
parentId,
|
|
@@ -6186,7 +6184,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
6186
6184
|
throw new Error("Cannot serialize LiveRegister if parent is missing");
|
|
6187
6185
|
}
|
|
6188
6186
|
return {
|
|
6189
|
-
type:
|
|
6187
|
+
type: CrdtType.REGISTER,
|
|
6190
6188
|
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
6191
6189
|
parentKey: this.parent.key,
|
|
6192
6190
|
data: this.data
|
|
@@ -6279,7 +6277,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6279
6277
|
const op = {
|
|
6280
6278
|
id: this._id,
|
|
6281
6279
|
opId: pool?.generateOpId(),
|
|
6282
|
-
type:
|
|
6280
|
+
type: OpCode.CREATE_LIST,
|
|
6283
6281
|
parentId,
|
|
6284
6282
|
parentKey
|
|
6285
6283
|
};
|
|
@@ -6566,7 +6564,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6566
6564
|
const newIndex = this._indexOfPosition(newKey);
|
|
6567
6565
|
return {
|
|
6568
6566
|
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
6569
|
-
reverse: [{ type:
|
|
6567
|
+
reverse: [{ type: OpCode.DELETE_CRDT, id }]
|
|
6570
6568
|
};
|
|
6571
6569
|
}
|
|
6572
6570
|
#applySetUndoRedo(op) {
|
|
@@ -6604,7 +6602,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6604
6602
|
this.#detachItemAssociatedToSetOperation(op.deletedId);
|
|
6605
6603
|
const newIndex = this._indexOfPosition(newKey);
|
|
6606
6604
|
return {
|
|
6607
|
-
reverse: [{ type:
|
|
6605
|
+
reverse: [{ type: OpCode.DELETE_CRDT, id }],
|
|
6608
6606
|
modified: makeUpdate(this, [insertDelta(newIndex, child)])
|
|
6609
6607
|
};
|
|
6610
6608
|
}
|
|
@@ -6780,7 +6778,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6780
6778
|
modified: makeUpdate(this, [moveDelta(previousIndex, newIndex, child)]),
|
|
6781
6779
|
reverse: [
|
|
6782
6780
|
{
|
|
6783
|
-
type:
|
|
6781
|
+
type: OpCode.SET_PARENT_KEY,
|
|
6784
6782
|
id: nn(child._id),
|
|
6785
6783
|
parentKey: previousKey
|
|
6786
6784
|
}
|
|
@@ -6807,7 +6805,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6807
6805
|
throw new Error("Cannot serialize LiveList if parent is missing");
|
|
6808
6806
|
}
|
|
6809
6807
|
return {
|
|
6810
|
-
type:
|
|
6808
|
+
type: CrdtType.LIST,
|
|
6811
6809
|
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
6812
6810
|
parentKey: this.parent.key
|
|
6813
6811
|
};
|
|
@@ -6849,7 +6847,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6849
6847
|
value._attach(id, this._pool);
|
|
6850
6848
|
this._pool.dispatch(
|
|
6851
6849
|
value._toOps(this._id, position, this._pool),
|
|
6852
|
-
[{ type:
|
|
6850
|
+
[{ type: OpCode.DELETE_CRDT, id }],
|
|
6853
6851
|
/* @__PURE__ */ new Map([
|
|
6854
6852
|
[this._id, makeUpdate(this, [insertDelta(index, value)])]
|
|
6855
6853
|
])
|
|
@@ -6898,7 +6896,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6898
6896
|
this._pool.dispatch(
|
|
6899
6897
|
[
|
|
6900
6898
|
{
|
|
6901
|
-
type:
|
|
6899
|
+
type: OpCode.SET_PARENT_KEY,
|
|
6902
6900
|
id: nn(item._id),
|
|
6903
6901
|
opId: this._pool.generateOpId(),
|
|
6904
6902
|
parentKey: position
|
|
@@ -6906,7 +6904,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6906
6904
|
],
|
|
6907
6905
|
[
|
|
6908
6906
|
{
|
|
6909
|
-
type:
|
|
6907
|
+
type: OpCode.SET_PARENT_KEY,
|
|
6910
6908
|
id: nn(item._id),
|
|
6911
6909
|
parentKey: previousPosition
|
|
6912
6910
|
}
|
|
@@ -6943,7 +6941,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6943
6941
|
{
|
|
6944
6942
|
id: childRecordId,
|
|
6945
6943
|
opId: this._pool.generateOpId(),
|
|
6946
|
-
type:
|
|
6944
|
+
type: OpCode.DELETE_CRDT
|
|
6947
6945
|
}
|
|
6948
6946
|
],
|
|
6949
6947
|
item._toOps(nn(this._id), item._getParentKeyOrThrow()),
|
|
@@ -6963,7 +6961,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6963
6961
|
const childId = item._id;
|
|
6964
6962
|
if (childId) {
|
|
6965
6963
|
ops.push({
|
|
6966
|
-
type:
|
|
6964
|
+
type: OpCode.DELETE_CRDT,
|
|
6967
6965
|
id: childId,
|
|
6968
6966
|
opId: this._pool.generateOpId()
|
|
6969
6967
|
});
|
|
@@ -7259,7 +7257,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7259
7257
|
const op = {
|
|
7260
7258
|
id: this._id,
|
|
7261
7259
|
opId: pool?.generateOpId(),
|
|
7262
|
-
type:
|
|
7260
|
+
type: OpCode.CREATE_MAP,
|
|
7263
7261
|
parentId,
|
|
7264
7262
|
parentKey
|
|
7265
7263
|
};
|
|
@@ -7323,7 +7321,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7323
7321
|
reverse = previousValue._toOps(thisId, key);
|
|
7324
7322
|
previousValue._detach();
|
|
7325
7323
|
} else {
|
|
7326
|
-
reverse = [{ type:
|
|
7324
|
+
reverse = [{ type: OpCode.DELETE_CRDT, id }];
|
|
7327
7325
|
}
|
|
7328
7326
|
child._setParentLink(this, key);
|
|
7329
7327
|
child._attach(id, this._pool);
|
|
@@ -7375,7 +7373,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7375
7373
|
throw new Error("Cannot serialize LiveMap if parent is missing");
|
|
7376
7374
|
}
|
|
7377
7375
|
return {
|
|
7378
|
-
type:
|
|
7376
|
+
type: CrdtType.MAP,
|
|
7379
7377
|
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
7380
7378
|
parentKey: this.parent.key
|
|
7381
7379
|
};
|
|
@@ -7420,7 +7418,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7420
7418
|
this.#unacknowledgedSet.set(key, nn(ops[0].opId));
|
|
7421
7419
|
this._pool.dispatch(
|
|
7422
7420
|
item._toOps(this._id, key, this._pool),
|
|
7423
|
-
oldValue ? oldValue._toOps(this._id, key) : [{ type:
|
|
7421
|
+
oldValue ? oldValue._toOps(this._id, key) : [{ type: OpCode.DELETE_CRDT, id }],
|
|
7424
7422
|
storageUpdates
|
|
7425
7423
|
);
|
|
7426
7424
|
}
|
|
@@ -7468,7 +7466,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7468
7466
|
this._pool.dispatch(
|
|
7469
7467
|
[
|
|
7470
7468
|
{
|
|
7471
|
-
type:
|
|
7469
|
+
type: OpCode.DELETE_CRDT,
|
|
7472
7470
|
id: item._id,
|
|
7473
7471
|
opId: this._pool.generateOpId()
|
|
7474
7472
|
}
|
|
@@ -7645,7 +7643,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7645
7643
|
const opId = pool?.generateOpId();
|
|
7646
7644
|
const ops = [];
|
|
7647
7645
|
const op = {
|
|
7648
|
-
type:
|
|
7646
|
+
type: OpCode.CREATE_OBJECT,
|
|
7649
7647
|
id: this._id,
|
|
7650
7648
|
opId,
|
|
7651
7649
|
parentId,
|
|
@@ -7722,11 +7720,11 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7722
7720
|
reverse = previousValue._toOps(thisId, key);
|
|
7723
7721
|
previousValue._detach();
|
|
7724
7722
|
} else if (previousValue === void 0) {
|
|
7725
|
-
reverse = [{ type:
|
|
7723
|
+
reverse = [{ type: OpCode.DELETE_OBJECT_KEY, id: thisId, key }];
|
|
7726
7724
|
} else {
|
|
7727
7725
|
reverse = [
|
|
7728
7726
|
{
|
|
7729
|
-
type:
|
|
7727
|
+
type: OpCode.UPDATE_OBJECT,
|
|
7730
7728
|
id: thisId,
|
|
7731
7729
|
data: { [key]: previousValue }
|
|
7732
7730
|
}
|
|
@@ -7782,9 +7780,9 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7782
7780
|
}
|
|
7783
7781
|
/** @internal */
|
|
7784
7782
|
_apply(op, isLocal) {
|
|
7785
|
-
if (op.type ===
|
|
7783
|
+
if (op.type === OpCode.UPDATE_OBJECT) {
|
|
7786
7784
|
return this.#applyUpdate(op, isLocal);
|
|
7787
|
-
} else if (op.type ===
|
|
7785
|
+
} else if (op.type === OpCode.DELETE_OBJECT_KEY) {
|
|
7788
7786
|
return this.#applyDeleteObjectKey(op, isLocal);
|
|
7789
7787
|
}
|
|
7790
7788
|
return super._apply(op, isLocal);
|
|
@@ -7799,14 +7797,14 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7799
7797
|
}
|
|
7800
7798
|
if (this.parent.type === "HasParent" && this.parent.node._id) {
|
|
7801
7799
|
return {
|
|
7802
|
-
type:
|
|
7800
|
+
type: CrdtType.OBJECT,
|
|
7803
7801
|
parentId: this.parent.node._id,
|
|
7804
7802
|
parentKey: this.parent.key,
|
|
7805
7803
|
data
|
|
7806
7804
|
};
|
|
7807
7805
|
} else {
|
|
7808
7806
|
return {
|
|
7809
|
-
type:
|
|
7807
|
+
type: CrdtType.OBJECT,
|
|
7810
7808
|
data
|
|
7811
7809
|
};
|
|
7812
7810
|
}
|
|
@@ -7816,7 +7814,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7816
7814
|
const id = nn(this._id);
|
|
7817
7815
|
const reverse = [];
|
|
7818
7816
|
const reverseUpdate = {
|
|
7819
|
-
type:
|
|
7817
|
+
type: OpCode.UPDATE_OBJECT,
|
|
7820
7818
|
id,
|
|
7821
7819
|
data: {}
|
|
7822
7820
|
};
|
|
@@ -7828,7 +7826,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7828
7826
|
} else if (oldValue !== void 0) {
|
|
7829
7827
|
reverseUpdate.data[key] = oldValue;
|
|
7830
7828
|
} else if (oldValue === void 0) {
|
|
7831
|
-
reverse.push({ type:
|
|
7829
|
+
reverse.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
|
|
7832
7830
|
}
|
|
7833
7831
|
}
|
|
7834
7832
|
const updateDelta = {};
|
|
@@ -7885,7 +7883,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7885
7883
|
} else if (oldValue !== void 0) {
|
|
7886
7884
|
reverse = [
|
|
7887
7885
|
{
|
|
7888
|
-
type:
|
|
7886
|
+
type: OpCode.UPDATE_OBJECT,
|
|
7889
7887
|
id,
|
|
7890
7888
|
data: { [key]: oldValue }
|
|
7891
7889
|
}
|
|
@@ -7952,7 +7950,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7952
7950
|
} else {
|
|
7953
7951
|
reverse = [
|
|
7954
7952
|
{
|
|
7955
|
-
type:
|
|
7953
|
+
type: OpCode.UPDATE_OBJECT,
|
|
7956
7954
|
data: { [keyAsString]: oldValue },
|
|
7957
7955
|
id: this._id
|
|
7958
7956
|
}
|
|
@@ -7971,7 +7969,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
7971
7969
|
this._pool.dispatch(
|
|
7972
7970
|
[
|
|
7973
7971
|
{
|
|
7974
|
-
type:
|
|
7972
|
+
type: OpCode.DELETE_OBJECT_KEY,
|
|
7975
7973
|
key: keyAsString,
|
|
7976
7974
|
id: this._id,
|
|
7977
7975
|
opId: this._pool.generateOpId()
|
|
@@ -8036,7 +8034,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
8036
8034
|
const updatedProps = {};
|
|
8037
8035
|
const reverseUpdateOp = {
|
|
8038
8036
|
id: this._id,
|
|
8039
|
-
type:
|
|
8037
|
+
type: OpCode.UPDATE_OBJECT,
|
|
8040
8038
|
data: {}
|
|
8041
8039
|
};
|
|
8042
8040
|
const updateDelta = {};
|
|
@@ -8050,7 +8048,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
8050
8048
|
reverseOps.push(...oldValue._toOps(this._id, key));
|
|
8051
8049
|
oldValue._detach();
|
|
8052
8050
|
} else if (oldValue === void 0) {
|
|
8053
|
-
reverseOps.push({ type:
|
|
8051
|
+
reverseOps.push({ type: OpCode.DELETE_OBJECT_KEY, id: this._id, key });
|
|
8054
8052
|
} else {
|
|
8055
8053
|
reverseUpdateOp.data[key] = oldValue;
|
|
8056
8054
|
}
|
|
@@ -8080,7 +8078,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
8080
8078
|
ops.unshift({
|
|
8081
8079
|
opId,
|
|
8082
8080
|
id: this._id,
|
|
8083
|
-
type:
|
|
8081
|
+
type: OpCode.UPDATE_OBJECT,
|
|
8084
8082
|
data: updatedProps
|
|
8085
8083
|
});
|
|
8086
8084
|
}
|
|
@@ -8137,13 +8135,13 @@ function creationOpToLiveNode(op) {
|
|
|
8137
8135
|
}
|
|
8138
8136
|
function creationOpToLson(op) {
|
|
8139
8137
|
switch (op.type) {
|
|
8140
|
-
case
|
|
8138
|
+
case OpCode.CREATE_REGISTER:
|
|
8141
8139
|
return op.data;
|
|
8142
|
-
case
|
|
8140
|
+
case OpCode.CREATE_OBJECT:
|
|
8143
8141
|
return new LiveObject(op.data);
|
|
8144
|
-
case
|
|
8142
|
+
case OpCode.CREATE_MAP:
|
|
8145
8143
|
return new LiveMap();
|
|
8146
|
-
case
|
|
8144
|
+
case OpCode.CREATE_LIST:
|
|
8147
8145
|
return new LiveList([]);
|
|
8148
8146
|
default:
|
|
8149
8147
|
return assertNever(op, "Unknown creation Op");
|
|
@@ -8160,16 +8158,16 @@ function isSameNodeOrChildOf(node, parent) {
|
|
|
8160
8158
|
}
|
|
8161
8159
|
function deserialize([id, crdt], parentToChildren, pool) {
|
|
8162
8160
|
switch (crdt.type) {
|
|
8163
|
-
case
|
|
8161
|
+
case CrdtType.OBJECT: {
|
|
8164
8162
|
return LiveObject._deserialize([id, crdt], parentToChildren, pool);
|
|
8165
8163
|
}
|
|
8166
|
-
case
|
|
8164
|
+
case CrdtType.LIST: {
|
|
8167
8165
|
return LiveList._deserialize([id, crdt], parentToChildren, pool);
|
|
8168
8166
|
}
|
|
8169
|
-
case
|
|
8167
|
+
case CrdtType.MAP: {
|
|
8170
8168
|
return LiveMap._deserialize([id, crdt], parentToChildren, pool);
|
|
8171
8169
|
}
|
|
8172
|
-
case
|
|
8170
|
+
case CrdtType.REGISTER: {
|
|
8173
8171
|
return LiveRegister._deserialize([id, crdt], parentToChildren, pool);
|
|
8174
8172
|
}
|
|
8175
8173
|
default: {
|
|
@@ -8179,16 +8177,16 @@ function deserialize([id, crdt], parentToChildren, pool) {
|
|
|
8179
8177
|
}
|
|
8180
8178
|
function deserializeToLson([id, crdt], parentToChildren, pool) {
|
|
8181
8179
|
switch (crdt.type) {
|
|
8182
|
-
case
|
|
8180
|
+
case CrdtType.OBJECT: {
|
|
8183
8181
|
return LiveObject._deserialize([id, crdt], parentToChildren, pool);
|
|
8184
8182
|
}
|
|
8185
|
-
case
|
|
8183
|
+
case CrdtType.LIST: {
|
|
8186
8184
|
return LiveList._deserialize([id, crdt], parentToChildren, pool);
|
|
8187
8185
|
}
|
|
8188
|
-
case
|
|
8186
|
+
case CrdtType.MAP: {
|
|
8189
8187
|
return LiveMap._deserialize([id, crdt], parentToChildren, pool);
|
|
8190
8188
|
}
|
|
8191
|
-
case
|
|
8189
|
+
case CrdtType.REGISTER: {
|
|
8192
8190
|
return crdt.data;
|
|
8193
8191
|
}
|
|
8194
8192
|
default: {
|
|
@@ -8238,7 +8236,7 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8238
8236
|
currentItems.forEach((_, id) => {
|
|
8239
8237
|
if (!newItems.get(id)) {
|
|
8240
8238
|
ops.push({
|
|
8241
|
-
type:
|
|
8239
|
+
type: OpCode.DELETE_CRDT,
|
|
8242
8240
|
id
|
|
8243
8241
|
});
|
|
8244
8242
|
}
|
|
@@ -8246,10 +8244,10 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8246
8244
|
newItems.forEach((crdt, id) => {
|
|
8247
8245
|
const currentCrdt = currentItems.get(id);
|
|
8248
8246
|
if (currentCrdt) {
|
|
8249
|
-
if (crdt.type ===
|
|
8250
|
-
if (currentCrdt.type !==
|
|
8247
|
+
if (crdt.type === CrdtType.OBJECT) {
|
|
8248
|
+
if (currentCrdt.type !== CrdtType.OBJECT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data)) {
|
|
8251
8249
|
ops.push({
|
|
8252
|
-
type:
|
|
8250
|
+
type: OpCode.UPDATE_OBJECT,
|
|
8253
8251
|
id,
|
|
8254
8252
|
data: crdt.data
|
|
8255
8253
|
});
|
|
@@ -8257,47 +8255,47 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8257
8255
|
}
|
|
8258
8256
|
if (crdt.parentKey !== currentCrdt.parentKey) {
|
|
8259
8257
|
ops.push({
|
|
8260
|
-
type:
|
|
8258
|
+
type: OpCode.SET_PARENT_KEY,
|
|
8261
8259
|
id,
|
|
8262
8260
|
parentKey: nn(crdt.parentKey, "Parent key must not be missing")
|
|
8263
8261
|
});
|
|
8264
8262
|
}
|
|
8265
8263
|
} else {
|
|
8266
8264
|
switch (crdt.type) {
|
|
8267
|
-
case
|
|
8265
|
+
case CrdtType.REGISTER:
|
|
8268
8266
|
ops.push({
|
|
8269
|
-
type:
|
|
8267
|
+
type: OpCode.CREATE_REGISTER,
|
|
8270
8268
|
id,
|
|
8271
8269
|
parentId: crdt.parentId,
|
|
8272
8270
|
parentKey: crdt.parentKey,
|
|
8273
8271
|
data: crdt.data
|
|
8274
8272
|
});
|
|
8275
8273
|
break;
|
|
8276
|
-
case
|
|
8274
|
+
case CrdtType.LIST:
|
|
8277
8275
|
ops.push({
|
|
8278
|
-
type:
|
|
8276
|
+
type: OpCode.CREATE_LIST,
|
|
8279
8277
|
id,
|
|
8280
8278
|
parentId: crdt.parentId,
|
|
8281
8279
|
parentKey: crdt.parentKey
|
|
8282
8280
|
});
|
|
8283
8281
|
break;
|
|
8284
|
-
case
|
|
8282
|
+
case CrdtType.OBJECT:
|
|
8285
8283
|
if (crdt.parentId === void 0 || crdt.parentKey === void 0) {
|
|
8286
8284
|
throw new Error(
|
|
8287
8285
|
"Internal error. Cannot serialize storage root into an operation"
|
|
8288
8286
|
);
|
|
8289
8287
|
}
|
|
8290
8288
|
ops.push({
|
|
8291
|
-
type:
|
|
8289
|
+
type: OpCode.CREATE_OBJECT,
|
|
8292
8290
|
id,
|
|
8293
8291
|
parentId: crdt.parentId,
|
|
8294
8292
|
parentKey: crdt.parentKey,
|
|
8295
8293
|
data: crdt.data
|
|
8296
8294
|
});
|
|
8297
8295
|
break;
|
|
8298
|
-
case
|
|
8296
|
+
case CrdtType.MAP:
|
|
8299
8297
|
ops.push({
|
|
8300
|
-
type:
|
|
8298
|
+
type: OpCode.CREATE_MAP,
|
|
8301
8299
|
id,
|
|
8302
8300
|
parentId: crdt.parentId,
|
|
8303
8301
|
parentKey: crdt.parentKey
|
|
@@ -8454,15 +8452,17 @@ function isJsonObject(data) {
|
|
|
8454
8452
|
}
|
|
8455
8453
|
|
|
8456
8454
|
// src/protocol/ClientMsg.ts
|
|
8457
|
-
var ClientMsgCode =
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8455
|
+
var ClientMsgCode = Object.freeze({
|
|
8456
|
+
// For Presence
|
|
8457
|
+
UPDATE_PRESENCE: 100,
|
|
8458
|
+
BROADCAST_EVENT: 103,
|
|
8459
|
+
// For Storage
|
|
8460
|
+
FETCH_STORAGE: 200,
|
|
8461
|
+
UPDATE_STORAGE: 201,
|
|
8462
|
+
// For Yjs support
|
|
8463
|
+
FETCH_YDOC: 300,
|
|
8464
|
+
UPDATE_YDOC: 301
|
|
8465
|
+
});
|
|
8466
8466
|
|
|
8467
8467
|
// src/refs/ManagedOthers.ts
|
|
8468
8468
|
function makeUser(conn, presence) {
|
|
@@ -8970,7 +8970,7 @@ function createRoom(options, config) {
|
|
|
8970
8970
|
}
|
|
8971
8971
|
function* chunkMessages(messages) {
|
|
8972
8972
|
if (messages.length < 2) {
|
|
8973
|
-
if (messages[0].type ===
|
|
8973
|
+
if (messages[0].type === ClientMsgCode.UPDATE_STORAGE) {
|
|
8974
8974
|
yield* chunkOps(messages[0]);
|
|
8975
8975
|
return;
|
|
8976
8976
|
} else {
|
|
@@ -9210,7 +9210,7 @@ function createRoom(options, config) {
|
|
|
9210
9210
|
);
|
|
9211
9211
|
output.reverse.pushLeft(applyOpResult.reverse);
|
|
9212
9212
|
}
|
|
9213
|
-
if (op.type ===
|
|
9213
|
+
if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
|
|
9214
9214
|
createdNodeIds.add(nn(op.id));
|
|
9215
9215
|
}
|
|
9216
9216
|
}
|
|
@@ -9226,20 +9226,20 @@ function createRoom(options, config) {
|
|
|
9226
9226
|
};
|
|
9227
9227
|
}
|
|
9228
9228
|
function applyOp(op, source) {
|
|
9229
|
-
if (
|
|
9229
|
+
if (isAck(op)) {
|
|
9230
9230
|
return { modified: false };
|
|
9231
9231
|
}
|
|
9232
9232
|
switch (op.type) {
|
|
9233
|
-
case
|
|
9234
|
-
case
|
|
9235
|
-
case
|
|
9233
|
+
case OpCode.DELETE_OBJECT_KEY:
|
|
9234
|
+
case OpCode.UPDATE_OBJECT:
|
|
9235
|
+
case OpCode.DELETE_CRDT: {
|
|
9236
9236
|
const node = context.pool.nodes.get(op.id);
|
|
9237
9237
|
if (node === void 0) {
|
|
9238
9238
|
return { modified: false };
|
|
9239
9239
|
}
|
|
9240
9240
|
return node._apply(op, source === 0 /* UNDOREDO_RECONNECT */);
|
|
9241
9241
|
}
|
|
9242
|
-
case
|
|
9242
|
+
case OpCode.SET_PARENT_KEY: {
|
|
9243
9243
|
const node = context.pool.nodes.get(op.id);
|
|
9244
9244
|
if (node === void 0) {
|
|
9245
9245
|
return { modified: false };
|
|
@@ -9253,10 +9253,10 @@ function createRoom(options, config) {
|
|
|
9253
9253
|
}
|
|
9254
9254
|
return { modified: false };
|
|
9255
9255
|
}
|
|
9256
|
-
case
|
|
9257
|
-
case
|
|
9258
|
-
case
|
|
9259
|
-
case
|
|
9256
|
+
case OpCode.CREATE_OBJECT:
|
|
9257
|
+
case OpCode.CREATE_LIST:
|
|
9258
|
+
case OpCode.CREATE_MAP:
|
|
9259
|
+
case OpCode.CREATE_REGISTER: {
|
|
9260
9260
|
if (op.parentId === void 0) {
|
|
9261
9261
|
return { modified: false };
|
|
9262
9262
|
}
|
|
@@ -9340,7 +9340,7 @@ function createRoom(options, config) {
|
|
|
9340
9340
|
});
|
|
9341
9341
|
context.idFactory = makeIdFactory(message.actor);
|
|
9342
9342
|
notifySelfChanged();
|
|
9343
|
-
if (message.meta
|
|
9343
|
+
if (message.meta.showBrand === true) {
|
|
9344
9344
|
injectBrandBadge(config.badgeLocation ?? "bottom-right");
|
|
9345
9345
|
}
|
|
9346
9346
|
for (const connectionId of context.others.connectionIds()) {
|
|
@@ -9378,7 +9378,7 @@ function createRoom(options, config) {
|
|
|
9378
9378
|
message.scopes
|
|
9379
9379
|
);
|
|
9380
9380
|
context.buffer.messages.push({
|
|
9381
|
-
type:
|
|
9381
|
+
type: ClientMsgCode.UPDATE_PRESENCE,
|
|
9382
9382
|
data: context.myPresence.get(),
|
|
9383
9383
|
targetActor: message.actor
|
|
9384
9384
|
});
|
|
@@ -9410,7 +9410,7 @@ function createRoom(options, config) {
|
|
|
9410
9410
|
const inOps = Array.from(offlineOps.values());
|
|
9411
9411
|
const result = applyOps(inOps, true);
|
|
9412
9412
|
messages.push({
|
|
9413
|
-
type:
|
|
9413
|
+
type: ClientMsgCode.UPDATE_STORAGE,
|
|
9414
9414
|
ops: result.ops
|
|
9415
9415
|
});
|
|
9416
9416
|
notify(result.updates);
|
|
@@ -9430,21 +9430,21 @@ function createRoom(options, config) {
|
|
|
9430
9430
|
};
|
|
9431
9431
|
for (const message of messages) {
|
|
9432
9432
|
switch (message.type) {
|
|
9433
|
-
case
|
|
9433
|
+
case ServerMsgCode.USER_JOINED: {
|
|
9434
9434
|
const userJoinedUpdate = onUserJoinedMessage(message);
|
|
9435
9435
|
if (userJoinedUpdate) {
|
|
9436
9436
|
updates.others.push(userJoinedUpdate);
|
|
9437
9437
|
}
|
|
9438
9438
|
break;
|
|
9439
9439
|
}
|
|
9440
|
-
case
|
|
9440
|
+
case ServerMsgCode.UPDATE_PRESENCE: {
|
|
9441
9441
|
const othersPresenceUpdate = onUpdatePresenceMessage(message);
|
|
9442
9442
|
if (othersPresenceUpdate) {
|
|
9443
9443
|
updates.others.push(othersPresenceUpdate);
|
|
9444
9444
|
}
|
|
9445
9445
|
break;
|
|
9446
9446
|
}
|
|
9447
|
-
case
|
|
9447
|
+
case ServerMsgCode.BROADCASTED_EVENT: {
|
|
9448
9448
|
const others = context.others.get();
|
|
9449
9449
|
eventHub.customEvent.notify({
|
|
9450
9450
|
connectionId: message.actor,
|
|
@@ -9453,27 +9453,27 @@ function createRoom(options, config) {
|
|
|
9453
9453
|
});
|
|
9454
9454
|
break;
|
|
9455
9455
|
}
|
|
9456
|
-
case
|
|
9456
|
+
case ServerMsgCode.USER_LEFT: {
|
|
9457
9457
|
const event2 = onUserLeftMessage(message);
|
|
9458
9458
|
if (event2) {
|
|
9459
9459
|
updates.others.push(event2);
|
|
9460
9460
|
}
|
|
9461
9461
|
break;
|
|
9462
9462
|
}
|
|
9463
|
-
case
|
|
9463
|
+
case ServerMsgCode.UPDATE_YDOC: {
|
|
9464
9464
|
eventHub.ydoc.notify(message);
|
|
9465
9465
|
break;
|
|
9466
9466
|
}
|
|
9467
|
-
case
|
|
9467
|
+
case ServerMsgCode.ROOM_STATE: {
|
|
9468
9468
|
updates.others.push(onRoomStateMessage(message));
|
|
9469
9469
|
break;
|
|
9470
9470
|
}
|
|
9471
|
-
case
|
|
9471
|
+
case ServerMsgCode.INITIAL_STORAGE_STATE: {
|
|
9472
9472
|
processInitialStorage(message);
|
|
9473
9473
|
break;
|
|
9474
9474
|
}
|
|
9475
9475
|
// Write event
|
|
9476
|
-
case
|
|
9476
|
+
case ServerMsgCode.UPDATE_STORAGE: {
|
|
9477
9477
|
const applyResult = applyOps(message.ops, false);
|
|
9478
9478
|
for (const [key, value] of applyResult.updates.storageUpdates) {
|
|
9479
9479
|
updates.storageUpdates.set(
|
|
@@ -9487,7 +9487,7 @@ function createRoom(options, config) {
|
|
|
9487
9487
|
// longer in sync with the client. Trying to synchronize the client again by
|
|
9488
9488
|
// rolling back particular Ops may be hard/impossible. It's fine to not try and
|
|
9489
9489
|
// accept the out-of-sync reality and throw an error.
|
|
9490
|
-
case
|
|
9490
|
+
case ServerMsgCode.REJECT_STORAGE_OP: {
|
|
9491
9491
|
errorWithTitle(
|
|
9492
9492
|
"Storage mutation rejection error",
|
|
9493
9493
|
message.reason
|
|
@@ -9499,15 +9499,15 @@ function createRoom(options, config) {
|
|
|
9499
9499
|
}
|
|
9500
9500
|
break;
|
|
9501
9501
|
}
|
|
9502
|
-
case
|
|
9503
|
-
case
|
|
9504
|
-
case
|
|
9505
|
-
case
|
|
9506
|
-
case
|
|
9507
|
-
case
|
|
9508
|
-
case
|
|
9509
|
-
case
|
|
9510
|
-
case
|
|
9502
|
+
case ServerMsgCode.THREAD_CREATED:
|
|
9503
|
+
case ServerMsgCode.THREAD_DELETED:
|
|
9504
|
+
case ServerMsgCode.THREAD_METADATA_UPDATED:
|
|
9505
|
+
case ServerMsgCode.THREAD_UPDATED:
|
|
9506
|
+
case ServerMsgCode.COMMENT_REACTION_ADDED:
|
|
9507
|
+
case ServerMsgCode.COMMENT_REACTION_REMOVED:
|
|
9508
|
+
case ServerMsgCode.COMMENT_CREATED:
|
|
9509
|
+
case ServerMsgCode.COMMENT_EDITED:
|
|
9510
|
+
case ServerMsgCode.COMMENT_DELETED: {
|
|
9511
9511
|
eventHub.comments.notify(message);
|
|
9512
9512
|
break;
|
|
9513
9513
|
}
|
|
@@ -9557,14 +9557,14 @@ function createRoom(options, config) {
|
|
|
9557
9557
|
if (context.buffer.presenceUpdates) {
|
|
9558
9558
|
messages.push(
|
|
9559
9559
|
context.buffer.presenceUpdates.type === "full" ? {
|
|
9560
|
-
type:
|
|
9560
|
+
type: ClientMsgCode.UPDATE_PRESENCE,
|
|
9561
9561
|
// Populating the `targetActor` field turns this message into
|
|
9562
9562
|
// a Full Presence™ update message (not a patch), which will get
|
|
9563
9563
|
// interpreted by other clients as such.
|
|
9564
9564
|
targetActor: -1,
|
|
9565
9565
|
data: context.buffer.presenceUpdates.data
|
|
9566
9566
|
} : {
|
|
9567
|
-
type:
|
|
9567
|
+
type: ClientMsgCode.UPDATE_PRESENCE,
|
|
9568
9568
|
data: context.buffer.presenceUpdates.data
|
|
9569
9569
|
}
|
|
9570
9570
|
);
|
|
@@ -9574,7 +9574,7 @@ function createRoom(options, config) {
|
|
|
9574
9574
|
}
|
|
9575
9575
|
if (context.buffer.storageOperations.length > 0) {
|
|
9576
9576
|
messages.push({
|
|
9577
|
-
type:
|
|
9577
|
+
type: ClientMsgCode.UPDATE_STORAGE,
|
|
9578
9578
|
ops: context.buffer.storageOperations
|
|
9579
9579
|
});
|
|
9580
9580
|
}
|
|
@@ -9582,7 +9582,7 @@ function createRoom(options, config) {
|
|
|
9582
9582
|
}
|
|
9583
9583
|
function updateYDoc(update, guid, isV2) {
|
|
9584
9584
|
const clientMsg = {
|
|
9585
|
-
type:
|
|
9585
|
+
type: ClientMsgCode.UPDATE_YDOC,
|
|
9586
9586
|
update,
|
|
9587
9587
|
guid,
|
|
9588
9588
|
v2: isV2
|
|
@@ -9598,7 +9598,7 @@ function createRoom(options, config) {
|
|
|
9598
9598
|
return;
|
|
9599
9599
|
}
|
|
9600
9600
|
context.buffer.messages.push({
|
|
9601
|
-
type:
|
|
9601
|
+
type: ClientMsgCode.BROADCAST_EVENT,
|
|
9602
9602
|
event
|
|
9603
9603
|
});
|
|
9604
9604
|
flushNowOrSoon();
|
|
@@ -9623,14 +9623,14 @@ function createRoom(options, config) {
|
|
|
9623
9623
|
async function streamStorage() {
|
|
9624
9624
|
if (!managedSocket.authValue) return;
|
|
9625
9625
|
const items = await httpClient.streamStorage({ roomId });
|
|
9626
|
-
processInitialStorage({ type:
|
|
9626
|
+
processInitialStorage({ type: ServerMsgCode.INITIAL_STORAGE_STATE, items });
|
|
9627
9627
|
}
|
|
9628
9628
|
function refreshStorage(options2) {
|
|
9629
9629
|
const messages = context.buffer.messages;
|
|
9630
9630
|
if (config.unstable_streamData) {
|
|
9631
9631
|
void streamStorage();
|
|
9632
|
-
} else if (!messages.some((msg) => msg.type ===
|
|
9633
|
-
messages.push({ type:
|
|
9632
|
+
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
9633
|
+
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
9634
9634
|
}
|
|
9635
9635
|
if (options2.flush) {
|
|
9636
9636
|
flushNowOrSoon();
|
|
@@ -9668,10 +9668,10 @@ function createRoom(options, config) {
|
|
|
9668
9668
|
}
|
|
9669
9669
|
function fetchYDoc(vector, guid, isV2) {
|
|
9670
9670
|
if (!context.buffer.messages.find((m) => {
|
|
9671
|
-
return m.type ===
|
|
9671
|
+
return m.type === ClientMsgCode.FETCH_YDOC && m.vector === vector && m.guid === guid && m.v2 === isV2;
|
|
9672
9672
|
})) {
|
|
9673
9673
|
context.buffer.messages.push({
|
|
9674
|
-
type:
|
|
9674
|
+
type: ClientMsgCode.FETCH_YDOC,
|
|
9675
9675
|
vector,
|
|
9676
9676
|
guid,
|
|
9677
9677
|
v2: isV2
|
|
@@ -11445,7 +11445,6 @@ export {
|
|
|
11445
11445
|
SortedList,
|
|
11446
11446
|
TextEditorType,
|
|
11447
11447
|
WebsocketCloseCodes,
|
|
11448
|
-
ackOp,
|
|
11449
11448
|
asPos,
|
|
11450
11449
|
assert,
|
|
11451
11450
|
assertNever,
|