@liveblocks/client 0.16.10 → 0.16.13

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/internal.d.ts CHANGED
@@ -1,22 +1,33 @@
1
- import { d as JsonObject, J as Json, g as Resolve, e as Lson, A as AbstractCrdt, f as LsonObject, L as LiveObject, S as StorageUpdate } from './shared';
2
- export { g as Resolve, h as RoomInitializers, p as parseJson } from './shared';
1
+ import { d as JsonObject, J as Json, h as Op, I as IdTuple, i as SerializedCrdt, f as Lson, g as LsonObject, c as LiveObject, S as StorageUpdate } from './shared';
2
+ export { G as CrdtType, j as CreateChildOp, k as CreateListOp, l as CreateMapOp, m as CreateObjectOp, n as CreateOp, o as CreateRegisterOp, p as CreateRootObjectOp, D as DeleteCrdtOp, q as DeleteObjectKeyOp, I as IdTuple, r as LiveNode, N as NodeMap, h as Op, K as OpCode, s as ParentToChildNodeMap, t as Resolve, u as RoomInitializers, v as SerializedChild, i as SerializedCrdt, w as SerializedList, x as SerializedMap, y as SerializedObject, z as SerializedRegister, A as SerializedRootObject, E as SetParentKeyOp, F as UpdateObjectOp, W as WebsocketCloseCodes, M as isChildCrdt, Q as isRootCrdt } from './shared';
3
3
 
4
- declare type IdTuple<T> = [id: string, value: T];
5
- /**
6
- * Lookup table for nodes (= SerializedCrdt values) by their IDs.
7
- */
8
- declare type NodeMap = Map<string, // Node ID
9
- SerializedCrdt>;
10
- /**
11
- * Reverse lookup table for all child nodes (= list of SerializedCrdt values)
12
- * by their parent node's IDs.
13
- */
14
- declare type ParentToChildNodeMap = Map<string, // Parent's node ID
15
- IdTuple<SerializedChild>[]>;
4
+ declare enum ClientMsgCode {
5
+ UPDATE_PRESENCE = 100,
6
+ BROADCAST_EVENT = 103,
7
+ FETCH_STORAGE = 200,
8
+ UPDATE_STORAGE = 201
9
+ }
16
10
  /**
17
- * Messages that can be sent from the server to the client.
11
+ * Messages that can be sent from the client to the server.
18
12
  */
19
- declare type ServerMsg<TPresence extends JsonObject> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg | UserLeftServerMsg | BroadcastedEventServerMsg | RoomStateServerMsg | InitialDocumentStateServerMsg | UpdateStorageServerMsg;
13
+ declare type ClientMsg<TPresence extends JsonObject> = BroadcastEventClientMsg | UpdatePresenceClientMsg<TPresence> | UpdateStorageClientMsg | FetchStorageClientMsg;
14
+ declare type BroadcastEventClientMsg = {
15
+ type: ClientMsgCode.BROADCAST_EVENT;
16
+ event: Json;
17
+ };
18
+ declare type UpdatePresenceClientMsg<TPresence extends JsonObject> = {
19
+ type: ClientMsgCode.UPDATE_PRESENCE;
20
+ data: TPresence;
21
+ targetActor?: number;
22
+ };
23
+ declare type UpdateStorageClientMsg = {
24
+ type: ClientMsgCode.UPDATE_STORAGE;
25
+ ops: Op[];
26
+ };
27
+ declare type FetchStorageClientMsg = {
28
+ type: ClientMsgCode.FETCH_STORAGE;
29
+ };
30
+
20
31
  declare enum ServerMsgCode {
21
32
  UPDATE_PRESENCE = 100,
22
33
  USER_JOINED = 101,
@@ -27,19 +38,9 @@ declare enum ServerMsgCode {
27
38
  UPDATE_STORAGE = 201
28
39
  }
29
40
  /**
30
- * Sent by the WebSocket server to a single client in response to the client
31
- * joining the Room, to provide the initial state of the Room. The payload
32
- * includes a list of all other Users that already are in the Room.
41
+ * Messages that can be sent from the server to the client.
33
42
  */
34
- declare type RoomStateServerMsg = {
35
- type: ServerMsgCode.ROOM_STATE;
36
- users: {
37
- [actor: number]: {
38
- id?: string;
39
- info?: Json;
40
- };
41
- };
42
- };
43
+ declare type ServerMsg<TPresence extends JsonObject> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg | UserLeftServerMsg | BroadcastedEventServerMsg | RoomStateServerMsg | InitialDocumentStateServerMsg | UpdateStorageServerMsg;
43
44
  /**
44
45
  * Sent by the WebSocket server and broadcasted to all clients to announce that
45
46
  * a User updated their presence. For example, when a user moves their cursor.
@@ -112,6 +113,20 @@ declare type BroadcastedEventServerMsg = {
112
113
  */
113
114
  event: Json;
114
115
  };
116
+ /**
117
+ * Sent by the WebSocket server to a single client in response to the client
118
+ * joining the Room, to provide the initial state of the Room. The payload
119
+ * includes a list of all other Users that already are in the Room.
120
+ */
121
+ declare type RoomStateServerMsg = {
122
+ type: ServerMsgCode.ROOM_STATE;
123
+ users: {
124
+ [actor: number]: {
125
+ id?: string;
126
+ info?: Json;
127
+ };
128
+ };
129
+ };
115
130
  /**
116
131
  * Sent by the WebSocket server to a single client in response to the client
117
132
  * joining the Room, to provide the initial Storage state of the Room. The
@@ -132,142 +147,42 @@ declare type UpdateStorageServerMsg = {
132
147
  type: ServerMsgCode.UPDATE_STORAGE;
133
148
  ops: Op[];
134
149
  };
135
- declare enum ClientMsgCode {
136
- UPDATE_PRESENCE = 100,
137
- BROADCAST_EVENT = 103,
138
- FETCH_STORAGE = 200,
139
- UPDATE_STORAGE = 201
140
- }
141
- declare type FetchStorageClientMsg = {
142
- type: ClientMsgCode.FETCH_STORAGE;
143
- };
144
- declare enum CrdtType {
145
- OBJECT = 0,
146
- LIST = 1,
147
- MAP = 2,
148
- REGISTER = 3
149
- }
150
- declare type SerializedRootObject = {
151
- type: CrdtType.OBJECT;
152
- data: JsonObject;
153
- parentId?: never;
154
- parentKey?: never;
155
- };
156
- declare type SerializedObject = {
157
- type: CrdtType.OBJECT;
158
- parentId: string;
159
- parentKey: string;
160
- data: JsonObject;
161
- };
162
- declare type SerializedList = {
163
- type: CrdtType.LIST;
164
- parentId: string;
165
- parentKey: string;
166
- };
167
- declare type SerializedMap = {
168
- type: CrdtType.MAP;
169
- parentId: string;
170
- parentKey: string;
171
- };
172
- declare type SerializedRegister = {
173
- type: CrdtType.REGISTER;
174
- parentId: string;
175
- parentKey: string;
176
- data: Json;
177
- };
178
- declare type SerializedCrdt = SerializedRootObject | SerializedChild;
179
- declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
180
- declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
181
- declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
182
- declare enum OpCode {
183
- INIT = 0,
184
- SET_PARENT_KEY = 1,
185
- CREATE_LIST = 2,
186
- UPDATE_OBJECT = 3,
187
- CREATE_OBJECT = 4,
188
- DELETE_CRDT = 5,
189
- DELETE_OBJECT_KEY = 6,
190
- CREATE_MAP = 7,
191
- CREATE_REGISTER = 8
192
- }
150
+
193
151
  /**
194
- * These operations are the payload for {@link UpdateStorageServerMsg} messages
195
- * only.
152
+ * Helper function that can be used to implement exhaustive switch statements
153
+ * with TypeScript. Example usage:
154
+ *
155
+ * type Fruit = "🍎" | "🍌";
156
+ *
157
+ * switch (fruit) {
158
+ * case "🍎":
159
+ * case "🍌":
160
+ * return doSomething();
161
+ *
162
+ * default:
163
+ * return assertNever(fruit, "Unknown fruit");
164
+ * }
165
+ *
166
+ * If now the Fruit union is extended (i.e. add "🍒"), TypeScript will catch
167
+ * this *statically*, rather than at runtime, and force you to handle the
168
+ * 🍒 case.
196
169
  */
197
- declare type Op = CreateOp | UpdateObjectOp | DeleteCrdtOp | SetParentKeyOp | DeleteObjectKeyOp;
198
- declare type CreateOp = CreateRootObjectOp | CreateChildOp;
199
- declare type CreateChildOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp;
200
- declare type UpdateObjectOp = {
201
- opId?: string;
202
- id: string;
203
- type: OpCode.UPDATE_OBJECT;
204
- data: Partial<JsonObject>;
205
- };
206
- declare type CreateObjectOp = {
207
- opId?: string;
208
- id: string;
209
- intent?: "set";
210
- type: OpCode.CREATE_OBJECT;
211
- parentId: string;
212
- parentKey: string;
213
- data: JsonObject;
214
- };
215
- declare type CreateRootObjectOp = Resolve<Omit<CreateObjectOp, "parentId" | "parentKey"> & {
216
- parentId?: never;
217
- parentKey?: never;
218
- }>;
219
- declare type CreateListOp = {
220
- opId?: string;
221
- id: string;
222
- intent?: "set";
223
- type: OpCode.CREATE_LIST;
224
- parentId: string;
225
- parentKey: string;
226
- };
227
- declare type CreateMapOp = {
228
- opId?: string;
229
- id: string;
230
- intent?: "set";
231
- type: OpCode.CREATE_MAP;
232
- parentId: string;
233
- parentKey: string;
234
- };
235
- declare type CreateRegisterOp = {
236
- opId?: string;
237
- id: string;
238
- intent?: "set";
239
- type: OpCode.CREATE_REGISTER;
240
- parentId: string;
241
- parentKey: string;
242
- data: Json;
243
- };
244
- declare type DeleteCrdtOp = {
245
- opId?: string;
246
- id: string;
247
- type: OpCode.DELETE_CRDT;
248
- };
249
- declare type SetParentKeyOp = {
250
- opId?: string;
251
- id: string;
252
- type: OpCode.SET_PARENT_KEY;
253
- parentKey: string;
254
- };
255
- declare type DeleteObjectKeyOp = {
256
- opId?: string;
257
- id: string;
258
- type: OpCode.DELETE_OBJECT_KEY;
259
- key: string;
260
- };
261
- declare enum WebsocketCloseCodes {
262
- CLOSE_ABNORMAL = 1006,
263
- INVALID_MESSAGE_FORMAT = 4000,
264
- NOT_ALLOWED = 4001,
265
- MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
266
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
267
- MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
268
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
269
- CLOSE_WITHOUT_RETRY = 4999
270
- }
170
+ declare function assertNever(_value: never, errmsg: string): never;
171
+ /**
172
+ * Asserts that a given value is non-nullable. This is similar to TypeScript's
173
+ * `!` operator, but will throw an error at runtime (dev-mode only) indicating
174
+ * an incorrect assumption.
175
+ *
176
+ * Instead of:
177
+ *
178
+ * foo!.bar
179
+ *
180
+ * Use:
181
+ *
182
+ * nn(foo).bar
183
+ *
184
+ */
185
+ declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
271
186
 
272
187
  /**
273
188
  * Tools to help with the controlled deprecation of public APIs.
@@ -300,7 +215,7 @@ declare function throwUsageError(message: string): void;
300
215
  */
301
216
  declare function errorIf(condition: unknown, message: string): void;
302
217
 
303
- declare function lsonToJson(value: Lson | AbstractCrdt): Json;
218
+ declare function lsonToJson(value: Lson): Json;
304
219
  declare function patchLiveObjectKey<O extends LsonObject>(liveObject: LiveObject<O>, key: keyof O, prev: unknown, next: unknown): void;
305
220
  declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
306
221
 
@@ -308,24 +223,13 @@ declare function makePosition(before?: string, after?: string): string;
308
223
  declare function comparePosition(posA: string, posB: string): number;
309
224
 
310
225
  /**
311
- * Helper function that can be used to implement exhaustive switch statements
312
- * with TypeScript. Example usage:
313
- *
314
- * type Fruit = "🍎" | "🍌";
315
- *
316
- * switch (fruit) {
317
- * case "🍎":
318
- * case "🍌":
319
- * return doSomething();
320
- *
321
- * default:
322
- * return assertNever(fruit, "Unknown fruit");
323
- * }
324
- *
325
- * If now the Fruit union is extended (i.e. add "🍒"), TypeScript will catch
326
- * this *statically*, rather than at runtime, and force you to handle the
327
- * 🍒 case.
226
+ * Alternative to JSON.parse() that will not throw in production. If the passed
227
+ * string cannot be parsed, this will return `undefined`.
328
228
  */
329
- declare function assertNever(_value: never, errmsg: string): never;
229
+ declare function tryParseJson(rawMessage: string): Json | undefined;
230
+ /**
231
+ * Decode base64 string.
232
+ */
233
+ declare function b64decode(b64value: string): string;
330
234
 
331
- export { ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateRegisterOp, CreateRootObjectOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, IdTuple, InitialDocumentStateServerMsg, NodeMap, Op, OpCode, ParentToChildNodeMap, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, UpdateObjectOp, UserJoinServerMsg, WebsocketCloseCodes, assertNever, comparePosition, deprecate, deprecateIf, errorIf, isChildCrdt, isRootCrdt, lsonToJson, makePosition, patchImmutableObject, patchLiveObjectKey, throwUsageError };
235
+ export { BroadcastEventClientMsg, BroadcastedEventServerMsg, ClientMsg, ClientMsgCode, FetchStorageClientMsg, InitialDocumentStateServerMsg, RoomStateServerMsg, ServerMsg, ServerMsgCode, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UserJoinServerMsg, UserLeftServerMsg, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, lsonToJson, makePosition, nn, patchImmutableObject, patchLiveObjectKey, throwUsageError, tryParseJson };
package/internal.js CHANGED
@@ -20,20 +20,15 @@ function lsonListToJson(value) {
20
20
  }
21
21
 
22
22
  function lsonToJson(value) {
23
- if (value instanceof LiveObject.LiveObject) return lsonObjectToJson(value.toObject());
24
- if (value instanceof LiveObject.LiveList) return function(value) {
23
+ return value instanceof LiveObject.LiveObject ? lsonObjectToJson(value.toObject()) : value instanceof LiveObject.LiveList ? function(value) {
25
24
  return lsonListToJson(value.toArray());
26
- }(value);
27
- if (value instanceof LiveObject.LiveMap) return function(map) {
25
+ }(value) : value instanceof LiveObject.LiveMap ? function(map) {
28
26
  for (var _step, result = {}, _iterator = LiveObject._createForOfIteratorHelperLoose(map.entries()); !(_step = _iterator()).done; ) {
29
27
  var _step$value = _step.value, _key2 = _step$value[0], value = _step$value[1];
30
28
  result[_key2] = lsonToJson(value);
31
29
  }
32
30
  return result;
33
- }(value);
34
- if (value instanceof LiveObject.LiveRegister) return value.data;
35
- if (value instanceof LiveObject.AbstractCrdt) throw new Error("Unhandled subclass of AbstractCrdt encountered");
36
- return Array.isArray(value) ? lsonListToJson(value) : isPlainObject(value) ? lsonObjectToJson(value) : value;
31
+ }(value) : value instanceof LiveObject.LiveRegister ? value.data : Array.isArray(value) ? lsonListToJson(value) : isPlainObject(value) ? lsonObjectToJson(value) : value;
37
32
  }
38
33
 
39
34
  function isPlainObject(obj) {
@@ -59,7 +54,7 @@ function patchLiveObjectKey(liveObject, key, prev, next) {
59
54
  var value = liveObject.get(key);
60
55
  if (void 0 === next) liveObject.delete(key); else if (void 0 === value) liveObject.set(key, anyToCrdt(next)); else {
61
56
  if (prev === next) return;
62
- value instanceof LiveObject.LiveList && Array.isArray(prev) && Array.isArray(next) ? function(liveList, prev, next) {
57
+ LiveObject.isLiveList(value) && Array.isArray(prev) && Array.isArray(next) ? function(liveList, prev, next) {
63
58
  var i = 0, prevEnd = prev.length - 1, nextEnd = next.length - 1, prevNode = prev[0], nextNode = next[0];
64
59
  outer: {
65
60
  for (;prevNode === nextNode; ) {
@@ -79,13 +74,13 @@ function patchLiveObjectKey(liveObject, key, prev, next) {
79
74
  for (;i <= prevEnd && i <= nextEnd; ) {
80
75
  prevNode = prev[i], nextNode = next[i];
81
76
  var liveListNode = liveList.get(i);
82
- liveListNode instanceof LiveObject.LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode) ? patchLiveObject(liveListNode, prevNode, nextNode) : liveList.set(i, anyToCrdt(nextNode)),
77
+ LiveObject.isLiveObject(liveListNode) && isPlainObject(prevNode) && isPlainObject(nextNode) ? patchLiveObject(liveListNode, prevNode, nextNode) : liveList.set(i, anyToCrdt(nextNode)),
83
78
  i++;
84
79
  }
85
80
  for (;i <= nextEnd; ) liveList.insert(anyToCrdt(next[i]), i), i++;
86
81
  for (var _localI = i; _localI <= prevEnd; ) liveList.delete(i), _localI++;
87
82
  }
88
- }(value, prev, next) : value instanceof LiveObject.LiveObject && isPlainObject(prev) && isPlainObject(next) ? patchLiveObject(value, prev, next) : liveObject.set(key, anyToCrdt(next));
83
+ }(value, prev, next) : LiveObject.isLiveObject(value) && isPlainObject(prev) && isPlainObject(next) ? patchLiveObject(value, prev, next) : liveObject.set(key, anyToCrdt(next));
89
84
  }
90
85
  }
91
86
 
@@ -128,7 +123,10 @@ function patchImmutableNode(state, path, update) {
128
123
  var _newState2 = Object.assign({}, state);
129
124
  for (var _key7 in update.updates) {
130
125
  var _update$updates$_key3, _update$updates$_key4;
131
- "update" === (null == (_update$updates$_key3 = update.updates[_key7]) ? void 0 : _update$updates$_key3.type) ? _newState2[_key7] = lsonToJson(update.node.get(_key7)) : "delete" === (null == (_update$updates$_key4 = update.updates[_key7]) ? void 0 : _update$updates$_key4.type) && delete _newState2[_key7];
126
+ if ("update" === (null == (_update$updates$_key3 = update.updates[_key7]) ? void 0 : _update$updates$_key3.type)) {
127
+ var value = update.node.get(_key7);
128
+ void 0 !== value && (_newState2[_key7] = lsonToJson(value));
129
+ } else "delete" === (null == (_update$updates$_key4 = update.updates[_key7]) ? void 0 : _update$updates$_key4.type) && delete _newState2[_key7];
132
130
  }
133
131
  return _newState2;
134
132
  }
@@ -165,17 +163,18 @@ Object.defineProperty(exports, "ClientMsgCode", {
165
163
  get: function() {
166
164
  return LiveObject.WebsocketCloseCodes;
167
165
  }
168
- }), exports.assertNever = LiveObject.assertNever, exports.comparePosition = LiveObject.comparePosition,
169
- exports.deprecate = LiveObject.deprecate, exports.deprecateIf = LiveObject.deprecateIf,
170
- exports.errorIf = LiveObject.errorIf, exports.isChildCrdt = LiveObject.isChildCrdt,
171
- exports.isRootCrdt = LiveObject.isRootCrdt, exports.makePosition = LiveObject.makePosition,
172
- exports.parseJson = LiveObject.parseJson, exports.throwUsageError = LiveObject.throwUsageError,
173
- exports.lsonToJson = lsonToJson, exports.patchImmutableObject = function(state, updates) {
166
+ }), exports.assertNever = LiveObject.assertNever, exports.b64decode = LiveObject.b64decode,
167
+ exports.comparePosition = LiveObject.comparePosition, exports.deprecate = LiveObject.deprecate,
168
+ exports.deprecateIf = LiveObject.deprecateIf, exports.errorIf = LiveObject.errorIf,
169
+ exports.isChildCrdt = LiveObject.isChildCrdt, exports.isRootCrdt = LiveObject.isRootCrdt,
170
+ exports.makePosition = LiveObject.makePosition, exports.nn = LiveObject.nn, exports.throwUsageError = LiveObject.throwUsageError,
171
+ exports.tryParseJson = LiveObject.tryParseJson, exports.lsonToJson = lsonToJson,
172
+ exports.patchImmutableObject = function(state, updates) {
174
173
  return updates.reduce((function(state, update) {
175
174
  return function(state, update) {
176
175
  var path = function(node) {
177
- for (var path = []; null != node._parentKey && null != node._parent; ) node._parent instanceof LiveObject.LiveList ? path.push(node._parent._indexOfPosition(node._parentKey)) : path.push(node._parentKey),
178
- node = node._parent;
176
+ for (var path = []; "HasParent" === node.parent.type; ) LiveObject.isLiveList(node.parent.node) ? path.push(node.parent.node._indexOfPosition(node.parent.key)) : path.push(node.parent.key),
177
+ node = node.parent.node;
179
178
  return path;
180
179
  }(update.node);
181
180
  return patchImmutableNode(state, path, update);
package/internal.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { L as LiveObject, b as LiveList, j as LiveMap, k as LiveRegister, A as AbstractCrdt, l as findNonSerializableValue } from "./shared.mjs";
1
+ import { L as LiveObject, o as LiveList, p as LiveMap, q as LiveRegister, s as findNonSerializableValue, d as isLiveList, u as isLiveObject } from "./shared.mjs";
2
2
 
3
- export { C as ClientMsgCode, q as CrdtType, O as OpCode, S as ServerMsgCode, W as WebsocketCloseCodes, w as assertNever, s as comparePosition, n as deprecate, h as deprecateIf, o as errorIf, v as isChildCrdt, f as isRootCrdt, u as makePosition, p as parseJson, t as throwUsageError } from "./shared.mjs";
3
+ export { C as ClientMsgCode, B as CrdtType, c as OpCode, S as ServerMsgCode, W as WebsocketCloseCodes, v as assertNever, h as b64decode, z as comparePosition, w as deprecate, x as deprecateIf, l as errorIf, D as isChildCrdt, k as isRootCrdt, A as makePosition, n as nn, y as throwUsageError, t as tryParseJson } from "./shared.mjs";
4
4
 
5
5
  function lsonObjectToJson(obj) {
6
6
  const result = {};
@@ -16,18 +16,13 @@ function lsonListToJson(value) {
16
16
  }
17
17
 
18
18
  function lsonToJson(value) {
19
- if (value instanceof LiveObject) return lsonObjectToJson(value.toObject());
20
- if (value instanceof LiveList) return function(value) {
19
+ return value instanceof LiveObject ? lsonObjectToJson(value.toObject()) : value instanceof LiveList ? function(value) {
21
20
  return lsonListToJson(value.toArray());
22
- }(value);
23
- if (value instanceof LiveMap) return function(map) {
21
+ }(value) : value instanceof LiveMap ? function(map) {
24
22
  const result = {};
25
23
  for (const [key, value] of map.entries()) result[key] = lsonToJson(value);
26
24
  return result;
27
- }(value);
28
- if (value instanceof LiveRegister) return value.data;
29
- if (value instanceof AbstractCrdt) throw new Error("Unhandled subclass of AbstractCrdt encountered");
30
- return Array.isArray(value) ? lsonListToJson(value) : isPlainObject(value) ? lsonObjectToJson(value) : value;
25
+ }(value) : value instanceof LiveRegister ? value.data : Array.isArray(value) ? lsonListToJson(value) : isPlainObject(value) ? lsonObjectToJson(value) : value;
31
26
  }
32
27
 
33
28
  function isPlainObject(obj) {
@@ -53,7 +48,7 @@ function patchLiveObjectKey(liveObject, key, prev, next) {
53
48
  const value = liveObject.get(key);
54
49
  if (void 0 === next) liveObject.delete(key); else if (void 0 === value) liveObject.set(key, anyToCrdt(next)); else {
55
50
  if (prev === next) return;
56
- value instanceof LiveList && Array.isArray(prev) && Array.isArray(next) ? function(liveList, prev, next) {
51
+ isLiveList(value) && Array.isArray(prev) && Array.isArray(next) ? function(liveList, prev, next) {
57
52
  let i = 0, prevEnd = prev.length - 1, nextEnd = next.length - 1, prevNode = prev[0], nextNode = next[0];
58
53
  outer: {
59
54
  for (;prevNode === nextNode; ) {
@@ -75,14 +70,14 @@ function patchLiveObjectKey(liveObject, key, prev, next) {
75
70
  for (;i <= prevEnd && i <= nextEnd; ) {
76
71
  prevNode = prev[i], nextNode = next[i];
77
72
  const liveListNode = liveList.get(i);
78
- liveListNode instanceof LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode) ? patchLiveObject(liveListNode, prevNode, nextNode) : liveList.set(i, anyToCrdt(nextNode)),
73
+ isLiveObject(liveListNode) && isPlainObject(prevNode) && isPlainObject(nextNode) ? patchLiveObject(liveListNode, prevNode, nextNode) : liveList.set(i, anyToCrdt(nextNode)),
79
74
  i++;
80
75
  }
81
76
  for (;i <= nextEnd; ) liveList.insert(anyToCrdt(next[i]), i), i++;
82
77
  let localI = i;
83
78
  for (;localI <= prevEnd; ) liveList.delete(i), localI++;
84
79
  }
85
- }(value, prev, next) : value instanceof LiveObject && isPlainObject(prev) && isPlainObject(next) ? patchLiveObject(value, prev, next) : liveObject.set(key, anyToCrdt(next));
80
+ }(value, prev, next) : isLiveObject(value) && isPlainObject(prev) && isPlainObject(next) ? patchLiveObject(value, prev, next) : liveObject.set(key, anyToCrdt(next));
86
81
  }
87
82
  }
88
83
 
@@ -97,8 +92,8 @@ function patchImmutableObject(state, updates) {
97
92
  return updates.reduce(((state, update) => function(state, update) {
98
93
  const path = function(node) {
99
94
  const path = [];
100
- for (;null != node._parentKey && null != node._parent; ) node._parent instanceof LiveList ? path.push(node._parent._indexOfPosition(node._parentKey)) : path.push(node._parentKey),
101
- node = node._parent;
95
+ for (;"HasParent" === node.parent.type; ) isLiveList(node.parent.node) ? path.push(node.parent.node._indexOfPosition(node.parent.key)) : path.push(node.parent.key),
96
+ node = node.parent.node;
102
97
  return path;
103
98
  }(update.node);
104
99
  return patchImmutableNode(state, path, update);
@@ -132,7 +127,10 @@ function patchImmutableNode(state, path, update) {
132
127
  {
133
128
  if ("object" != typeof state) throw new Error("Internal: received update on LiveMap but state was not an object");
134
129
  const newState = Object.assign({}, state);
135
- for (const key in update.updates) "update" === (null === (_c = update.updates[key]) || void 0 === _c ? void 0 : _c.type) ? newState[key] = lsonToJson(update.node.get(key)) : "delete" === (null === (_d = update.updates[key]) || void 0 === _d ? void 0 : _d.type) && delete newState[key];
130
+ for (const key in update.updates) if ("update" === (null === (_c = update.updates[key]) || void 0 === _c ? void 0 : _c.type)) {
131
+ const value = update.node.get(key);
132
+ void 0 !== value && (newState[key] = lsonToJson(value));
133
+ } else "delete" === (null === (_d = update.updates[key]) || void 0 === _d ? void 0 : _d.type) && delete newState[key];
136
134
  return newState;
137
135
  }
138
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.16.10",
3
+ "version": "0.16.13",
4
4
  "description": "A client that lets you interact with Liveblocks servers.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -33,8 +33,9 @@
33
33
  "build": "rollup -c && cp ./package.json ./README.md ./lib",
34
34
  "format": "eslint --fix src/ test/ && prettier --write src/ test/",
35
35
  "lint": "eslint src/ test/",
36
- "test": "jest --watch",
37
- "test-ci": "jest"
36
+ "test": "jest --watch --silent --verbose --config=./jest.config.js",
37
+ "test-ci": "jest --silent --verbose",
38
+ "test-e2e": "jest --silent --verbose --config=./jest.config.e2e.js"
38
39
  },
39
40
  "license": "Apache-2.0",
40
41
  "devDependencies": {
@@ -45,23 +46,26 @@
45
46
  "@rollup/plugin-node-resolve": "^13.1.3",
46
47
  "@rollup/plugin-replace": "^4.0.0",
47
48
  "@rollup/plugin-typescript": "^8.3.1",
48
- "@types/jest": "^26.0.21",
49
+ "@types/jest": "^26.0.24",
49
50
  "@types/node-fetch": "^2.6.1",
50
- "@types/ws": "^8.2.2",
51
- "@typescript-eslint/eslint-plugin": "^5.17.0",
52
- "@typescript-eslint/parser": "^5.17.0",
51
+ "@types/ws": "^8.5.3",
52
+ "@typescript-eslint/eslint-plugin": "^5.26.0",
53
+ "@typescript-eslint/parser": "^5.26.0",
54
+ "dotenv": "^16.0.0",
53
55
  "eslint": "^8.12.0",
54
56
  "eslint-plugin-import": "^2.26.0",
55
57
  "eslint-plugin-simple-import-sort": "^7.0.0",
56
- "jest": "^26.6.3",
58
+ "jest": "^28.0.3",
57
59
  "jest-each": "^27.5.1",
60
+ "jest-environment-jsdom": "^28.1.0",
58
61
  "msw": "^0.39.1",
59
62
  "node-fetch": "2.6.7",
63
+ "regenerator-runtime": "^0.13.9",
60
64
  "rollup": "^2.68.0",
61
65
  "rollup-plugin-command": "^1.1.3",
62
66
  "rollup-plugin-dts": "^4.1.0",
63
67
  "rollup-plugin-terser": "^7.0.2",
64
- "typescript": "^4.4.0",
68
+ "typescript": "^4.7.2",
65
69
  "whatwg-fetch": "^3.6.2",
66
70
  "ws": "^8.5.0"
67
71
  },