@liveblocks/core 3.12.0 → 3.12.1-enums1

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.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.0";
9
+ var PKG_VERSION = "3.12.1-enums1";
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 = /* @__PURE__ */ ((ServerMsgCode2) => {
3086
- ServerMsgCode2[ServerMsgCode2["UPDATE_PRESENCE"] = 100] = "UPDATE_PRESENCE";
3087
- ServerMsgCode2[ServerMsgCode2["USER_JOINED"] = 101] = "USER_JOINED";
3088
- ServerMsgCode2[ServerMsgCode2["USER_LEFT"] = 102] = "USER_LEFT";
3089
- ServerMsgCode2[ServerMsgCode2["BROADCASTED_EVENT"] = 103] = "BROADCASTED_EVENT";
3090
- ServerMsgCode2[ServerMsgCode2["ROOM_STATE"] = 104] = "ROOM_STATE";
3091
- ServerMsgCode2[ServerMsgCode2["INITIAL_STORAGE_STATE"] = 200] = "INITIAL_STORAGE_STATE";
3092
- ServerMsgCode2[ServerMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
3093
- ServerMsgCode2[ServerMsgCode2["UPDATE_YDOC"] = 300] = "UPDATE_YDOC";
3094
- ServerMsgCode2[ServerMsgCode2["THREAD_CREATED"] = 400] = "THREAD_CREATED";
3095
- ServerMsgCode2[ServerMsgCode2["THREAD_DELETED"] = 407] = "THREAD_DELETED";
3096
- ServerMsgCode2[ServerMsgCode2["THREAD_METADATA_UPDATED"] = 401] = "THREAD_METADATA_UPDATED";
3097
- ServerMsgCode2[ServerMsgCode2["THREAD_UPDATED"] = 408] = "THREAD_UPDATED";
3098
- ServerMsgCode2[ServerMsgCode2["COMMENT_CREATED"] = 402] = "COMMENT_CREATED";
3099
- ServerMsgCode2[ServerMsgCode2["COMMENT_EDITED"] = 403] = "COMMENT_EDITED";
3100
- ServerMsgCode2[ServerMsgCode2["COMMENT_DELETED"] = 404] = "COMMENT_DELETED";
3101
- ServerMsgCode2[ServerMsgCode2["COMMENT_REACTION_ADDED"] = 405] = "COMMENT_REACTION_ADDED";
3102
- ServerMsgCode2[ServerMsgCode2["COMMENT_REACTION_REMOVED"] = 406] = "COMMENT_REACTION_REMOVED";
3103
- ServerMsgCode2[ServerMsgCode2["REJECT_STORAGE_OP"] = 299] = "REJECT_STORAGE_OP";
3104
- return ServerMsgCode2;
3105
- })(ServerMsgCode || {});
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 === 104 /* ROOM_STATE */) {
3411
+ if (serverMsg?.type === ServerMsgCode.ROOM_STATE) {
3407
3412
  didReceiveActor();
3408
3413
  }
3409
3414
  }
@@ -5908,28 +5913,27 @@ function asPos(str) {
5908
5913
  }
5909
5914
 
5910
5915
  // src/protocol/Op.ts
5911
- var OpCode = /* @__PURE__ */ ((OpCode2) => {
5912
- OpCode2[OpCode2["INIT"] = 0] = "INIT";
5913
- OpCode2[OpCode2["SET_PARENT_KEY"] = 1] = "SET_PARENT_KEY";
5914
- OpCode2[OpCode2["CREATE_LIST"] = 2] = "CREATE_LIST";
5915
- OpCode2[OpCode2["UPDATE_OBJECT"] = 3] = "UPDATE_OBJECT";
5916
- OpCode2[OpCode2["CREATE_OBJECT"] = 4] = "CREATE_OBJECT";
5917
- OpCode2[OpCode2["DELETE_CRDT"] = 5] = "DELETE_CRDT";
5918
- OpCode2[OpCode2["DELETE_OBJECT_KEY"] = 6] = "DELETE_OBJECT_KEY";
5919
- OpCode2[OpCode2["CREATE_MAP"] = 7] = "CREATE_MAP";
5920
- OpCode2[OpCode2["CREATE_REGISTER"] = 8] = "CREATE_REGISTER";
5921
- return OpCode2;
5922
- })(OpCode || {});
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
+ });
5923
5927
  function ackOp(opId) {
5924
5928
  return {
5925
- type: 5 /* DELETE_CRDT */,
5929
+ type: OpCode.DELETE_CRDT,
5926
5930
  id: "ACK",
5927
5931
  // (H)ACK
5928
5932
  opId
5929
5933
  };
5930
5934
  }
5931
5935
  function isAckOp(op) {
5932
- return op.type === 5 /* DELETE_CRDT */ && op.id === "ACK";
5936
+ return op.type === OpCode.DELETE_CRDT && op.id === "ACK";
5933
5937
  }
5934
5938
 
5935
5939
  // src/crdts/AbstractCrdt.ts
@@ -6034,7 +6038,7 @@ var AbstractCrdt = class {
6034
6038
  /** @internal */
6035
6039
  _apply(op, _isLocal) {
6036
6040
  switch (op.type) {
6037
- case 5 /* DELETE_CRDT */: {
6041
+ case OpCode.DELETE_CRDT: {
6038
6042
  if (this.parent.type === "HasParent") {
6039
6043
  return this.parent.node._detachChild(crdtAsLiveNode(this));
6040
6044
  }
@@ -6138,13 +6142,12 @@ var AbstractCrdt = class {
6138
6142
  };
6139
6143
 
6140
6144
  // src/protocol/SerializedCrdt.ts
6141
- var CrdtType = /* @__PURE__ */ ((CrdtType2) => {
6142
- CrdtType2[CrdtType2["OBJECT"] = 0] = "OBJECT";
6143
- CrdtType2[CrdtType2["LIST"] = 1] = "LIST";
6144
- CrdtType2[CrdtType2["MAP"] = 2] = "MAP";
6145
- CrdtType2[CrdtType2["REGISTER"] = 3] = "REGISTER";
6146
- return CrdtType2;
6147
- })(CrdtType || {});
6145
+ var CrdtType = Object.freeze({
6146
+ OBJECT: 0,
6147
+ LIST: 1,
6148
+ MAP: 2,
6149
+ REGISTER: 3
6150
+ });
6148
6151
 
6149
6152
  // src/crdts/LiveRegister.ts
6150
6153
  var LiveRegister = class _LiveRegister extends AbstractCrdt {
@@ -6171,7 +6174,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
6171
6174
  }
6172
6175
  return [
6173
6176
  {
6174
- type: 8 /* CREATE_REGISTER */,
6177
+ type: OpCode.CREATE_REGISTER,
6175
6178
  opId: pool?.generateOpId(),
6176
6179
  id: this._id,
6177
6180
  parentId,
@@ -6186,7 +6189,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
6186
6189
  throw new Error("Cannot serialize LiveRegister if parent is missing");
6187
6190
  }
6188
6191
  return {
6189
- type: 3 /* REGISTER */,
6192
+ type: CrdtType.REGISTER,
6190
6193
  parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
6191
6194
  parentKey: this.parent.key,
6192
6195
  data: this.data
@@ -6279,7 +6282,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6279
6282
  const op = {
6280
6283
  id: this._id,
6281
6284
  opId: pool?.generateOpId(),
6282
- type: 2 /* CREATE_LIST */,
6285
+ type: OpCode.CREATE_LIST,
6283
6286
  parentId,
6284
6287
  parentKey
6285
6288
  };
@@ -6566,7 +6569,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6566
6569
  const newIndex = this._indexOfPosition(newKey);
6567
6570
  return {
6568
6571
  modified: makeUpdate(this, [insertDelta(newIndex, child)]),
6569
- reverse: [{ type: 5 /* DELETE_CRDT */, id }]
6572
+ reverse: [{ type: OpCode.DELETE_CRDT, id }]
6570
6573
  };
6571
6574
  }
6572
6575
  #applySetUndoRedo(op) {
@@ -6604,7 +6607,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6604
6607
  this.#detachItemAssociatedToSetOperation(op.deletedId);
6605
6608
  const newIndex = this._indexOfPosition(newKey);
6606
6609
  return {
6607
- reverse: [{ type: 5 /* DELETE_CRDT */, id }],
6610
+ reverse: [{ type: OpCode.DELETE_CRDT, id }],
6608
6611
  modified: makeUpdate(this, [insertDelta(newIndex, child)])
6609
6612
  };
6610
6613
  }
@@ -6780,7 +6783,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6780
6783
  modified: makeUpdate(this, [moveDelta(previousIndex, newIndex, child)]),
6781
6784
  reverse: [
6782
6785
  {
6783
- type: 1 /* SET_PARENT_KEY */,
6786
+ type: OpCode.SET_PARENT_KEY,
6784
6787
  id: nn(child._id),
6785
6788
  parentKey: previousKey
6786
6789
  }
@@ -6807,7 +6810,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6807
6810
  throw new Error("Cannot serialize LiveList if parent is missing");
6808
6811
  }
6809
6812
  return {
6810
- type: 1 /* LIST */,
6813
+ type: CrdtType.LIST,
6811
6814
  parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
6812
6815
  parentKey: this.parent.key
6813
6816
  };
@@ -6849,7 +6852,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6849
6852
  value._attach(id, this._pool);
6850
6853
  this._pool.dispatch(
6851
6854
  value._toOps(this._id, position, this._pool),
6852
- [{ type: 5 /* DELETE_CRDT */, id }],
6855
+ [{ type: OpCode.DELETE_CRDT, id }],
6853
6856
  /* @__PURE__ */ new Map([
6854
6857
  [this._id, makeUpdate(this, [insertDelta(index, value)])]
6855
6858
  ])
@@ -6898,7 +6901,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6898
6901
  this._pool.dispatch(
6899
6902
  [
6900
6903
  {
6901
- type: 1 /* SET_PARENT_KEY */,
6904
+ type: OpCode.SET_PARENT_KEY,
6902
6905
  id: nn(item._id),
6903
6906
  opId: this._pool.generateOpId(),
6904
6907
  parentKey: position
@@ -6906,7 +6909,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6906
6909
  ],
6907
6910
  [
6908
6911
  {
6909
- type: 1 /* SET_PARENT_KEY */,
6912
+ type: OpCode.SET_PARENT_KEY,
6910
6913
  id: nn(item._id),
6911
6914
  parentKey: previousPosition
6912
6915
  }
@@ -6943,7 +6946,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6943
6946
  {
6944
6947
  id: childRecordId,
6945
6948
  opId: this._pool.generateOpId(),
6946
- type: 5 /* DELETE_CRDT */
6949
+ type: OpCode.DELETE_CRDT
6947
6950
  }
6948
6951
  ],
6949
6952
  item._toOps(nn(this._id), item._getParentKeyOrThrow()),
@@ -6963,7 +6966,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
6963
6966
  const childId = item._id;
6964
6967
  if (childId) {
6965
6968
  ops.push({
6966
- type: 5 /* DELETE_CRDT */,
6969
+ type: OpCode.DELETE_CRDT,
6967
6970
  id: childId,
6968
6971
  opId: this._pool.generateOpId()
6969
6972
  });
@@ -7259,7 +7262,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7259
7262
  const op = {
7260
7263
  id: this._id,
7261
7264
  opId: pool?.generateOpId(),
7262
- type: 7 /* CREATE_MAP */,
7265
+ type: OpCode.CREATE_MAP,
7263
7266
  parentId,
7264
7267
  parentKey
7265
7268
  };
@@ -7323,7 +7326,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7323
7326
  reverse = previousValue._toOps(thisId, key);
7324
7327
  previousValue._detach();
7325
7328
  } else {
7326
- reverse = [{ type: 5 /* DELETE_CRDT */, id }];
7329
+ reverse = [{ type: OpCode.DELETE_CRDT, id }];
7327
7330
  }
7328
7331
  child._setParentLink(this, key);
7329
7332
  child._attach(id, this._pool);
@@ -7375,7 +7378,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7375
7378
  throw new Error("Cannot serialize LiveMap if parent is missing");
7376
7379
  }
7377
7380
  return {
7378
- type: 2 /* MAP */,
7381
+ type: CrdtType.MAP,
7379
7382
  parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
7380
7383
  parentKey: this.parent.key
7381
7384
  };
@@ -7420,7 +7423,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7420
7423
  this.#unacknowledgedSet.set(key, nn(ops[0].opId));
7421
7424
  this._pool.dispatch(
7422
7425
  item._toOps(this._id, key, this._pool),
7423
- oldValue ? oldValue._toOps(this._id, key) : [{ type: 5 /* DELETE_CRDT */, id }],
7426
+ oldValue ? oldValue._toOps(this._id, key) : [{ type: OpCode.DELETE_CRDT, id }],
7424
7427
  storageUpdates
7425
7428
  );
7426
7429
  }
@@ -7468,7 +7471,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
7468
7471
  this._pool.dispatch(
7469
7472
  [
7470
7473
  {
7471
- type: 5 /* DELETE_CRDT */,
7474
+ type: OpCode.DELETE_CRDT,
7472
7475
  id: item._id,
7473
7476
  opId: this._pool.generateOpId()
7474
7477
  }
@@ -7645,7 +7648,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7645
7648
  const opId = pool?.generateOpId();
7646
7649
  const ops = [];
7647
7650
  const op = {
7648
- type: 4 /* CREATE_OBJECT */,
7651
+ type: OpCode.CREATE_OBJECT,
7649
7652
  id: this._id,
7650
7653
  opId,
7651
7654
  parentId,
@@ -7722,11 +7725,11 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7722
7725
  reverse = previousValue._toOps(thisId, key);
7723
7726
  previousValue._detach();
7724
7727
  } else if (previousValue === void 0) {
7725
- reverse = [{ type: 6 /* DELETE_OBJECT_KEY */, id: thisId, key }];
7728
+ reverse = [{ type: OpCode.DELETE_OBJECT_KEY, id: thisId, key }];
7726
7729
  } else {
7727
7730
  reverse = [
7728
7731
  {
7729
- type: 3 /* UPDATE_OBJECT */,
7732
+ type: OpCode.UPDATE_OBJECT,
7730
7733
  id: thisId,
7731
7734
  data: { [key]: previousValue }
7732
7735
  }
@@ -7782,9 +7785,9 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7782
7785
  }
7783
7786
  /** @internal */
7784
7787
  _apply(op, isLocal) {
7785
- if (op.type === 3 /* UPDATE_OBJECT */) {
7788
+ if (op.type === OpCode.UPDATE_OBJECT) {
7786
7789
  return this.#applyUpdate(op, isLocal);
7787
- } else if (op.type === 6 /* DELETE_OBJECT_KEY */) {
7790
+ } else if (op.type === OpCode.DELETE_OBJECT_KEY) {
7788
7791
  return this.#applyDeleteObjectKey(op, isLocal);
7789
7792
  }
7790
7793
  return super._apply(op, isLocal);
@@ -7799,14 +7802,14 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7799
7802
  }
7800
7803
  if (this.parent.type === "HasParent" && this.parent.node._id) {
7801
7804
  return {
7802
- type: 0 /* OBJECT */,
7805
+ type: CrdtType.OBJECT,
7803
7806
  parentId: this.parent.node._id,
7804
7807
  parentKey: this.parent.key,
7805
7808
  data
7806
7809
  };
7807
7810
  } else {
7808
7811
  return {
7809
- type: 0 /* OBJECT */,
7812
+ type: CrdtType.OBJECT,
7810
7813
  data
7811
7814
  };
7812
7815
  }
@@ -7816,7 +7819,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7816
7819
  const id = nn(this._id);
7817
7820
  const reverse = [];
7818
7821
  const reverseUpdate = {
7819
- type: 3 /* UPDATE_OBJECT */,
7822
+ type: OpCode.UPDATE_OBJECT,
7820
7823
  id,
7821
7824
  data: {}
7822
7825
  };
@@ -7828,7 +7831,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7828
7831
  } else if (oldValue !== void 0) {
7829
7832
  reverseUpdate.data[key] = oldValue;
7830
7833
  } else if (oldValue === void 0) {
7831
- reverse.push({ type: 6 /* DELETE_OBJECT_KEY */, id, key });
7834
+ reverse.push({ type: OpCode.DELETE_OBJECT_KEY, id, key });
7832
7835
  }
7833
7836
  }
7834
7837
  const updateDelta = {};
@@ -7885,7 +7888,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7885
7888
  } else if (oldValue !== void 0) {
7886
7889
  reverse = [
7887
7890
  {
7888
- type: 3 /* UPDATE_OBJECT */,
7891
+ type: OpCode.UPDATE_OBJECT,
7889
7892
  id,
7890
7893
  data: { [key]: oldValue }
7891
7894
  }
@@ -7952,7 +7955,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7952
7955
  } else {
7953
7956
  reverse = [
7954
7957
  {
7955
- type: 3 /* UPDATE_OBJECT */,
7958
+ type: OpCode.UPDATE_OBJECT,
7956
7959
  data: { [keyAsString]: oldValue },
7957
7960
  id: this._id
7958
7961
  }
@@ -7971,7 +7974,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
7971
7974
  this._pool.dispatch(
7972
7975
  [
7973
7976
  {
7974
- type: 6 /* DELETE_OBJECT_KEY */,
7977
+ type: OpCode.DELETE_OBJECT_KEY,
7975
7978
  key: keyAsString,
7976
7979
  id: this._id,
7977
7980
  opId: this._pool.generateOpId()
@@ -8036,7 +8039,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
8036
8039
  const updatedProps = {};
8037
8040
  const reverseUpdateOp = {
8038
8041
  id: this._id,
8039
- type: 3 /* UPDATE_OBJECT */,
8042
+ type: OpCode.UPDATE_OBJECT,
8040
8043
  data: {}
8041
8044
  };
8042
8045
  const updateDelta = {};
@@ -8050,7 +8053,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
8050
8053
  reverseOps.push(...oldValue._toOps(this._id, key));
8051
8054
  oldValue._detach();
8052
8055
  } else if (oldValue === void 0) {
8053
- reverseOps.push({ type: 6 /* DELETE_OBJECT_KEY */, id: this._id, key });
8056
+ reverseOps.push({ type: OpCode.DELETE_OBJECT_KEY, id: this._id, key });
8054
8057
  } else {
8055
8058
  reverseUpdateOp.data[key] = oldValue;
8056
8059
  }
@@ -8080,7 +8083,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
8080
8083
  ops.unshift({
8081
8084
  opId,
8082
8085
  id: this._id,
8083
- type: 3 /* UPDATE_OBJECT */,
8086
+ type: OpCode.UPDATE_OBJECT,
8084
8087
  data: updatedProps
8085
8088
  });
8086
8089
  }
@@ -8137,13 +8140,13 @@ function creationOpToLiveNode(op) {
8137
8140
  }
8138
8141
  function creationOpToLson(op) {
8139
8142
  switch (op.type) {
8140
- case 8 /* CREATE_REGISTER */:
8143
+ case OpCode.CREATE_REGISTER:
8141
8144
  return op.data;
8142
- case 4 /* CREATE_OBJECT */:
8145
+ case OpCode.CREATE_OBJECT:
8143
8146
  return new LiveObject(op.data);
8144
- case 7 /* CREATE_MAP */:
8147
+ case OpCode.CREATE_MAP:
8145
8148
  return new LiveMap();
8146
- case 2 /* CREATE_LIST */:
8149
+ case OpCode.CREATE_LIST:
8147
8150
  return new LiveList([]);
8148
8151
  default:
8149
8152
  return assertNever(op, "Unknown creation Op");
@@ -8160,16 +8163,16 @@ function isSameNodeOrChildOf(node, parent) {
8160
8163
  }
8161
8164
  function deserialize([id, crdt], parentToChildren, pool) {
8162
8165
  switch (crdt.type) {
8163
- case 0 /* OBJECT */: {
8166
+ case CrdtType.OBJECT: {
8164
8167
  return LiveObject._deserialize([id, crdt], parentToChildren, pool);
8165
8168
  }
8166
- case 1 /* LIST */: {
8169
+ case CrdtType.LIST: {
8167
8170
  return LiveList._deserialize([id, crdt], parentToChildren, pool);
8168
8171
  }
8169
- case 2 /* MAP */: {
8172
+ case CrdtType.MAP: {
8170
8173
  return LiveMap._deserialize([id, crdt], parentToChildren, pool);
8171
8174
  }
8172
- case 3 /* REGISTER */: {
8175
+ case CrdtType.REGISTER: {
8173
8176
  return LiveRegister._deserialize([id, crdt], parentToChildren, pool);
8174
8177
  }
8175
8178
  default: {
@@ -8179,16 +8182,16 @@ function deserialize([id, crdt], parentToChildren, pool) {
8179
8182
  }
8180
8183
  function deserializeToLson([id, crdt], parentToChildren, pool) {
8181
8184
  switch (crdt.type) {
8182
- case 0 /* OBJECT */: {
8185
+ case CrdtType.OBJECT: {
8183
8186
  return LiveObject._deserialize([id, crdt], parentToChildren, pool);
8184
8187
  }
8185
- case 1 /* LIST */: {
8188
+ case CrdtType.LIST: {
8186
8189
  return LiveList._deserialize([id, crdt], parentToChildren, pool);
8187
8190
  }
8188
- case 2 /* MAP */: {
8191
+ case CrdtType.MAP: {
8189
8192
  return LiveMap._deserialize([id, crdt], parentToChildren, pool);
8190
8193
  }
8191
- case 3 /* REGISTER */: {
8194
+ case CrdtType.REGISTER: {
8192
8195
  return crdt.data;
8193
8196
  }
8194
8197
  default: {
@@ -8238,7 +8241,7 @@ function getTreesDiffOperations(currentItems, newItems) {
8238
8241
  currentItems.forEach((_, id) => {
8239
8242
  if (!newItems.get(id)) {
8240
8243
  ops.push({
8241
- type: 5 /* DELETE_CRDT */,
8244
+ type: OpCode.DELETE_CRDT,
8242
8245
  id
8243
8246
  });
8244
8247
  }
@@ -8246,10 +8249,10 @@ function getTreesDiffOperations(currentItems, newItems) {
8246
8249
  newItems.forEach((crdt, id) => {
8247
8250
  const currentCrdt = currentItems.get(id);
8248
8251
  if (currentCrdt) {
8249
- if (crdt.type === 0 /* OBJECT */) {
8250
- if (currentCrdt.type !== 0 /* OBJECT */ || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data)) {
8252
+ if (crdt.type === CrdtType.OBJECT) {
8253
+ if (currentCrdt.type !== CrdtType.OBJECT || stringifyOrLog(crdt.data) !== stringifyOrLog(currentCrdt.data)) {
8251
8254
  ops.push({
8252
- type: 3 /* UPDATE_OBJECT */,
8255
+ type: OpCode.UPDATE_OBJECT,
8253
8256
  id,
8254
8257
  data: crdt.data
8255
8258
  });
@@ -8257,47 +8260,47 @@ function getTreesDiffOperations(currentItems, newItems) {
8257
8260
  }
8258
8261
  if (crdt.parentKey !== currentCrdt.parentKey) {
8259
8262
  ops.push({
8260
- type: 1 /* SET_PARENT_KEY */,
8263
+ type: OpCode.SET_PARENT_KEY,
8261
8264
  id,
8262
8265
  parentKey: nn(crdt.parentKey, "Parent key must not be missing")
8263
8266
  });
8264
8267
  }
8265
8268
  } else {
8266
8269
  switch (crdt.type) {
8267
- case 3 /* REGISTER */:
8270
+ case CrdtType.REGISTER:
8268
8271
  ops.push({
8269
- type: 8 /* CREATE_REGISTER */,
8272
+ type: OpCode.CREATE_REGISTER,
8270
8273
  id,
8271
8274
  parentId: crdt.parentId,
8272
8275
  parentKey: crdt.parentKey,
8273
8276
  data: crdt.data
8274
8277
  });
8275
8278
  break;
8276
- case 1 /* LIST */:
8279
+ case CrdtType.LIST:
8277
8280
  ops.push({
8278
- type: 2 /* CREATE_LIST */,
8281
+ type: OpCode.CREATE_LIST,
8279
8282
  id,
8280
8283
  parentId: crdt.parentId,
8281
8284
  parentKey: crdt.parentKey
8282
8285
  });
8283
8286
  break;
8284
- case 0 /* OBJECT */:
8287
+ case CrdtType.OBJECT:
8285
8288
  if (crdt.parentId === void 0 || crdt.parentKey === void 0) {
8286
8289
  throw new Error(
8287
8290
  "Internal error. Cannot serialize storage root into an operation"
8288
8291
  );
8289
8292
  }
8290
8293
  ops.push({
8291
- type: 4 /* CREATE_OBJECT */,
8294
+ type: OpCode.CREATE_OBJECT,
8292
8295
  id,
8293
8296
  parentId: crdt.parentId,
8294
8297
  parentKey: crdt.parentKey,
8295
8298
  data: crdt.data
8296
8299
  });
8297
8300
  break;
8298
- case 2 /* MAP */:
8301
+ case CrdtType.MAP:
8299
8302
  ops.push({
8300
- type: 7 /* CREATE_MAP */,
8303
+ type: OpCode.CREATE_MAP,
8301
8304
  id,
8302
8305
  parentId: crdt.parentId,
8303
8306
  parentKey: crdt.parentKey
@@ -8454,15 +8457,17 @@ function isJsonObject(data) {
8454
8457
  }
8455
8458
 
8456
8459
  // src/protocol/ClientMsg.ts
8457
- var ClientMsgCode = /* @__PURE__ */ ((ClientMsgCode2) => {
8458
- ClientMsgCode2[ClientMsgCode2["UPDATE_PRESENCE"] = 100] = "UPDATE_PRESENCE";
8459
- ClientMsgCode2[ClientMsgCode2["BROADCAST_EVENT"] = 103] = "BROADCAST_EVENT";
8460
- ClientMsgCode2[ClientMsgCode2["FETCH_STORAGE"] = 200] = "FETCH_STORAGE";
8461
- ClientMsgCode2[ClientMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
8462
- ClientMsgCode2[ClientMsgCode2["FETCH_YDOC"] = 300] = "FETCH_YDOC";
8463
- ClientMsgCode2[ClientMsgCode2["UPDATE_YDOC"] = 301] = "UPDATE_YDOC";
8464
- return ClientMsgCode2;
8465
- })(ClientMsgCode || {});
8460
+ var ClientMsgCode = Object.freeze({
8461
+ // For Presence
8462
+ UPDATE_PRESENCE: 100,
8463
+ BROADCAST_EVENT: 103,
8464
+ // For Storage
8465
+ FETCH_STORAGE: 200,
8466
+ UPDATE_STORAGE: 201,
8467
+ // For Yjs support
8468
+ FETCH_YDOC: 300,
8469
+ UPDATE_YDOC: 301
8470
+ });
8466
8471
 
8467
8472
  // src/refs/ManagedOthers.ts
8468
8473
  function makeUser(conn, presence) {
@@ -8970,7 +8975,7 @@ function createRoom(options, config) {
8970
8975
  }
8971
8976
  function* chunkMessages(messages) {
8972
8977
  if (messages.length < 2) {
8973
- if (messages[0].type === 201 /* UPDATE_STORAGE */) {
8978
+ if (messages[0].type === ClientMsgCode.UPDATE_STORAGE) {
8974
8979
  yield* chunkOps(messages[0]);
8975
8980
  return;
8976
8981
  } else {
@@ -9210,7 +9215,7 @@ function createRoom(options, config) {
9210
9215
  );
9211
9216
  output.reverse.pushLeft(applyOpResult.reverse);
9212
9217
  }
9213
- if (op.type === 2 /* CREATE_LIST */ || op.type === 7 /* CREATE_MAP */ || op.type === 4 /* CREATE_OBJECT */) {
9218
+ if (op.type === OpCode.CREATE_LIST || op.type === OpCode.CREATE_MAP || op.type === OpCode.CREATE_OBJECT) {
9214
9219
  createdNodeIds.add(nn(op.id));
9215
9220
  }
9216
9221
  }
@@ -9230,16 +9235,16 @@ function createRoom(options, config) {
9230
9235
  return { modified: false };
9231
9236
  }
9232
9237
  switch (op.type) {
9233
- case 6 /* DELETE_OBJECT_KEY */:
9234
- case 3 /* UPDATE_OBJECT */:
9235
- case 5 /* DELETE_CRDT */: {
9238
+ case OpCode.DELETE_OBJECT_KEY:
9239
+ case OpCode.UPDATE_OBJECT:
9240
+ case OpCode.DELETE_CRDT: {
9236
9241
  const node = context.pool.nodes.get(op.id);
9237
9242
  if (node === void 0) {
9238
9243
  return { modified: false };
9239
9244
  }
9240
9245
  return node._apply(op, source === 0 /* UNDOREDO_RECONNECT */);
9241
9246
  }
9242
- case 1 /* SET_PARENT_KEY */: {
9247
+ case OpCode.SET_PARENT_KEY: {
9243
9248
  const node = context.pool.nodes.get(op.id);
9244
9249
  if (node === void 0) {
9245
9250
  return { modified: false };
@@ -9253,10 +9258,10 @@ function createRoom(options, config) {
9253
9258
  }
9254
9259
  return { modified: false };
9255
9260
  }
9256
- case 4 /* CREATE_OBJECT */:
9257
- case 2 /* CREATE_LIST */:
9258
- case 7 /* CREATE_MAP */:
9259
- case 8 /* CREATE_REGISTER */: {
9261
+ case OpCode.CREATE_OBJECT:
9262
+ case OpCode.CREATE_LIST:
9263
+ case OpCode.CREATE_MAP:
9264
+ case OpCode.CREATE_REGISTER: {
9260
9265
  if (op.parentId === void 0) {
9261
9266
  return { modified: false };
9262
9267
  }
@@ -9340,7 +9345,7 @@ function createRoom(options, config) {
9340
9345
  });
9341
9346
  context.idFactory = makeIdFactory(message.actor);
9342
9347
  notifySelfChanged();
9343
- if (message.meta?.showBrand === true) {
9348
+ if (message.meta.showBrand === true) {
9344
9349
  injectBrandBadge(config.badgeLocation ?? "bottom-right");
9345
9350
  }
9346
9351
  for (const connectionId of context.others.connectionIds()) {
@@ -9378,7 +9383,7 @@ function createRoom(options, config) {
9378
9383
  message.scopes
9379
9384
  );
9380
9385
  context.buffer.messages.push({
9381
- type: 100 /* UPDATE_PRESENCE */,
9386
+ type: ClientMsgCode.UPDATE_PRESENCE,
9382
9387
  data: context.myPresence.get(),
9383
9388
  targetActor: message.actor
9384
9389
  });
@@ -9410,7 +9415,7 @@ function createRoom(options, config) {
9410
9415
  const inOps = Array.from(offlineOps.values());
9411
9416
  const result = applyOps(inOps, true);
9412
9417
  messages.push({
9413
- type: 201 /* UPDATE_STORAGE */,
9418
+ type: ClientMsgCode.UPDATE_STORAGE,
9414
9419
  ops: result.ops
9415
9420
  });
9416
9421
  notify(result.updates);
@@ -9430,21 +9435,21 @@ function createRoom(options, config) {
9430
9435
  };
9431
9436
  for (const message of messages) {
9432
9437
  switch (message.type) {
9433
- case 101 /* USER_JOINED */: {
9438
+ case ServerMsgCode.USER_JOINED: {
9434
9439
  const userJoinedUpdate = onUserJoinedMessage(message);
9435
9440
  if (userJoinedUpdate) {
9436
9441
  updates.others.push(userJoinedUpdate);
9437
9442
  }
9438
9443
  break;
9439
9444
  }
9440
- case 100 /* UPDATE_PRESENCE */: {
9445
+ case ServerMsgCode.UPDATE_PRESENCE: {
9441
9446
  const othersPresenceUpdate = onUpdatePresenceMessage(message);
9442
9447
  if (othersPresenceUpdate) {
9443
9448
  updates.others.push(othersPresenceUpdate);
9444
9449
  }
9445
9450
  break;
9446
9451
  }
9447
- case 103 /* BROADCASTED_EVENT */: {
9452
+ case ServerMsgCode.BROADCASTED_EVENT: {
9448
9453
  const others = context.others.get();
9449
9454
  eventHub.customEvent.notify({
9450
9455
  connectionId: message.actor,
@@ -9453,27 +9458,27 @@ function createRoom(options, config) {
9453
9458
  });
9454
9459
  break;
9455
9460
  }
9456
- case 102 /* USER_LEFT */: {
9461
+ case ServerMsgCode.USER_LEFT: {
9457
9462
  const event2 = onUserLeftMessage(message);
9458
9463
  if (event2) {
9459
9464
  updates.others.push(event2);
9460
9465
  }
9461
9466
  break;
9462
9467
  }
9463
- case 300 /* UPDATE_YDOC */: {
9468
+ case ServerMsgCode.UPDATE_YDOC: {
9464
9469
  eventHub.ydoc.notify(message);
9465
9470
  break;
9466
9471
  }
9467
- case 104 /* ROOM_STATE */: {
9472
+ case ServerMsgCode.ROOM_STATE: {
9468
9473
  updates.others.push(onRoomStateMessage(message));
9469
9474
  break;
9470
9475
  }
9471
- case 200 /* INITIAL_STORAGE_STATE */: {
9476
+ case ServerMsgCode.INITIAL_STORAGE_STATE: {
9472
9477
  processInitialStorage(message);
9473
9478
  break;
9474
9479
  }
9475
9480
  // Write event
9476
- case 201 /* UPDATE_STORAGE */: {
9481
+ case ServerMsgCode.UPDATE_STORAGE: {
9477
9482
  const applyResult = applyOps(message.ops, false);
9478
9483
  for (const [key, value] of applyResult.updates.storageUpdates) {
9479
9484
  updates.storageUpdates.set(
@@ -9487,7 +9492,7 @@ function createRoom(options, config) {
9487
9492
  // longer in sync with the client. Trying to synchronize the client again by
9488
9493
  // rolling back particular Ops may be hard/impossible. It's fine to not try and
9489
9494
  // accept the out-of-sync reality and throw an error.
9490
- case 299 /* REJECT_STORAGE_OP */: {
9495
+ case ServerMsgCode.REJECT_STORAGE_OP: {
9491
9496
  errorWithTitle(
9492
9497
  "Storage mutation rejection error",
9493
9498
  message.reason
@@ -9499,15 +9504,15 @@ function createRoom(options, config) {
9499
9504
  }
9500
9505
  break;
9501
9506
  }
9502
- case 400 /* THREAD_CREATED */:
9503
- case 407 /* THREAD_DELETED */:
9504
- case 401 /* THREAD_METADATA_UPDATED */:
9505
- case 408 /* THREAD_UPDATED */:
9506
- case 405 /* COMMENT_REACTION_ADDED */:
9507
- case 406 /* COMMENT_REACTION_REMOVED */:
9508
- case 402 /* COMMENT_CREATED */:
9509
- case 403 /* COMMENT_EDITED */:
9510
- case 404 /* COMMENT_DELETED */: {
9507
+ case ServerMsgCode.THREAD_CREATED:
9508
+ case ServerMsgCode.THREAD_DELETED:
9509
+ case ServerMsgCode.THREAD_METADATA_UPDATED:
9510
+ case ServerMsgCode.THREAD_UPDATED:
9511
+ case ServerMsgCode.COMMENT_REACTION_ADDED:
9512
+ case ServerMsgCode.COMMENT_REACTION_REMOVED:
9513
+ case ServerMsgCode.COMMENT_CREATED:
9514
+ case ServerMsgCode.COMMENT_EDITED:
9515
+ case ServerMsgCode.COMMENT_DELETED: {
9511
9516
  eventHub.comments.notify(message);
9512
9517
  break;
9513
9518
  }
@@ -9557,14 +9562,14 @@ function createRoom(options, config) {
9557
9562
  if (context.buffer.presenceUpdates) {
9558
9563
  messages.push(
9559
9564
  context.buffer.presenceUpdates.type === "full" ? {
9560
- type: 100 /* UPDATE_PRESENCE */,
9565
+ type: ClientMsgCode.UPDATE_PRESENCE,
9561
9566
  // Populating the `targetActor` field turns this message into
9562
9567
  // a Full Presence™ update message (not a patch), which will get
9563
9568
  // interpreted by other clients as such.
9564
9569
  targetActor: -1,
9565
9570
  data: context.buffer.presenceUpdates.data
9566
9571
  } : {
9567
- type: 100 /* UPDATE_PRESENCE */,
9572
+ type: ClientMsgCode.UPDATE_PRESENCE,
9568
9573
  data: context.buffer.presenceUpdates.data
9569
9574
  }
9570
9575
  );
@@ -9574,7 +9579,7 @@ function createRoom(options, config) {
9574
9579
  }
9575
9580
  if (context.buffer.storageOperations.length > 0) {
9576
9581
  messages.push({
9577
- type: 201 /* UPDATE_STORAGE */,
9582
+ type: ClientMsgCode.UPDATE_STORAGE,
9578
9583
  ops: context.buffer.storageOperations
9579
9584
  });
9580
9585
  }
@@ -9582,7 +9587,7 @@ function createRoom(options, config) {
9582
9587
  }
9583
9588
  function updateYDoc(update, guid, isV2) {
9584
9589
  const clientMsg = {
9585
- type: 301 /* UPDATE_YDOC */,
9590
+ type: ClientMsgCode.UPDATE_YDOC,
9586
9591
  update,
9587
9592
  guid,
9588
9593
  v2: isV2
@@ -9598,7 +9603,7 @@ function createRoom(options, config) {
9598
9603
  return;
9599
9604
  }
9600
9605
  context.buffer.messages.push({
9601
- type: 103 /* BROADCAST_EVENT */,
9606
+ type: ClientMsgCode.BROADCAST_EVENT,
9602
9607
  event
9603
9608
  });
9604
9609
  flushNowOrSoon();
@@ -9623,14 +9628,14 @@ function createRoom(options, config) {
9623
9628
  async function streamStorage() {
9624
9629
  if (!managedSocket.authValue) return;
9625
9630
  const items = await httpClient.streamStorage({ roomId });
9626
- processInitialStorage({ type: 200 /* INITIAL_STORAGE_STATE */, items });
9631
+ processInitialStorage({ type: ServerMsgCode.INITIAL_STORAGE_STATE, items });
9627
9632
  }
9628
9633
  function refreshStorage(options2) {
9629
9634
  const messages = context.buffer.messages;
9630
9635
  if (config.unstable_streamData) {
9631
9636
  void streamStorage();
9632
- } else if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
9633
- messages.push({ type: 200 /* FETCH_STORAGE */ });
9637
+ } else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
9638
+ messages.push({ type: ClientMsgCode.FETCH_STORAGE });
9634
9639
  }
9635
9640
  if (options2.flush) {
9636
9641
  flushNowOrSoon();
@@ -9668,10 +9673,10 @@ function createRoom(options, config) {
9668
9673
  }
9669
9674
  function fetchYDoc(vector, guid, isV2) {
9670
9675
  if (!context.buffer.messages.find((m) => {
9671
- return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid && m.v2 === isV2;
9676
+ return m.type === ClientMsgCode.FETCH_YDOC && m.vector === vector && m.guid === guid && m.v2 === isV2;
9672
9677
  })) {
9673
9678
  context.buffer.messages.push({
9674
- type: 300 /* FETCH_YDOC */,
9679
+ type: ClientMsgCode.FETCH_YDOC,
9675
9680
  vector,
9676
9681
  guid,
9677
9682
  v2: isV2