@liveblocks/client 0.16.12 → 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 } 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,159 +147,42 @@ declare type UpdateStorageServerMsg = {
132
147
  type: ServerMsgCode.UPDATE_STORAGE;
133
148
  ops: Op[];
134
149
  };
150
+
135
151
  /**
136
- * Messages that can be sent from the client to the server.
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.
137
169
  */
138
- declare type ClientMsg<TPresence extends JsonObject> = BroadcastEventClientMsg | UpdatePresenceClientMsg<TPresence> | UpdateStorageClientMsg | FetchStorageClientMsg;
139
- declare enum ClientMsgCode {
140
- UPDATE_PRESENCE = 100,
141
- BROADCAST_EVENT = 103,
142
- FETCH_STORAGE = 200,
143
- UPDATE_STORAGE = 201
144
- }
145
- declare type BroadcastEventClientMsg = {
146
- type: ClientMsgCode.BROADCAST_EVENT;
147
- event: Json;
148
- };
149
- declare type UpdatePresenceClientMsg<TPresence extends JsonObject> = {
150
- type: ClientMsgCode.UPDATE_PRESENCE;
151
- data: TPresence;
152
- targetActor?: number;
153
- };
154
- declare type UpdateStorageClientMsg = {
155
- type: ClientMsgCode.UPDATE_STORAGE;
156
- ops: Op[];
157
- };
158
- declare type FetchStorageClientMsg = {
159
- type: ClientMsgCode.FETCH_STORAGE;
160
- };
161
- declare enum CrdtType {
162
- OBJECT = 0,
163
- LIST = 1,
164
- MAP = 2,
165
- REGISTER = 3
166
- }
167
- declare type SerializedRootObject = {
168
- type: CrdtType.OBJECT;
169
- data: JsonObject;
170
- parentId?: never;
171
- parentKey?: never;
172
- };
173
- declare type SerializedObject = {
174
- type: CrdtType.OBJECT;
175
- parentId: string;
176
- parentKey: string;
177
- data: JsonObject;
178
- };
179
- declare type SerializedList = {
180
- type: CrdtType.LIST;
181
- parentId: string;
182
- parentKey: string;
183
- };
184
- declare type SerializedMap = {
185
- type: CrdtType.MAP;
186
- parentId: string;
187
- parentKey: string;
188
- };
189
- declare type SerializedRegister = {
190
- type: CrdtType.REGISTER;
191
- parentId: string;
192
- parentKey: string;
193
- data: Json;
194
- };
195
- declare type SerializedCrdt = SerializedRootObject | SerializedChild;
196
- declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
197
- declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
198
- declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
199
- declare enum OpCode {
200
- INIT = 0,
201
- SET_PARENT_KEY = 1,
202
- CREATE_LIST = 2,
203
- UPDATE_OBJECT = 3,
204
- CREATE_OBJECT = 4,
205
- DELETE_CRDT = 5,
206
- DELETE_OBJECT_KEY = 6,
207
- CREATE_MAP = 7,
208
- CREATE_REGISTER = 8
209
- }
170
+ declare function assertNever(_value: never, errmsg: string): never;
210
171
  /**
211
- * These operations are the payload for {@link UpdateStorageServerMsg} messages
212
- * only.
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
+ *
213
184
  */
214
- declare type Op = CreateOp | UpdateObjectOp | DeleteCrdtOp | SetParentKeyOp | DeleteObjectKeyOp;
215
- declare type CreateOp = CreateRootObjectOp | CreateChildOp;
216
- declare type CreateChildOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp;
217
- declare type UpdateObjectOp = {
218
- opId?: string;
219
- id: string;
220
- type: OpCode.UPDATE_OBJECT;
221
- data: Partial<JsonObject>;
222
- };
223
- declare type CreateObjectOp = {
224
- opId?: string;
225
- id: string;
226
- intent?: "set";
227
- type: OpCode.CREATE_OBJECT;
228
- parentId: string;
229
- parentKey: string;
230
- data: JsonObject;
231
- };
232
- declare type CreateRootObjectOp = Resolve<Omit<CreateObjectOp, "parentId" | "parentKey"> & {
233
- parentId?: never;
234
- parentKey?: never;
235
- }>;
236
- declare type CreateListOp = {
237
- opId?: string;
238
- id: string;
239
- intent?: "set";
240
- type: OpCode.CREATE_LIST;
241
- parentId: string;
242
- parentKey: string;
243
- };
244
- declare type CreateMapOp = {
245
- opId?: string;
246
- id: string;
247
- intent?: "set";
248
- type: OpCode.CREATE_MAP;
249
- parentId: string;
250
- parentKey: string;
251
- };
252
- declare type CreateRegisterOp = {
253
- opId?: string;
254
- id: string;
255
- intent?: "set";
256
- type: OpCode.CREATE_REGISTER;
257
- parentId: string;
258
- parentKey: string;
259
- data: Json;
260
- };
261
- declare type DeleteCrdtOp = {
262
- opId?: string;
263
- id: string;
264
- type: OpCode.DELETE_CRDT;
265
- };
266
- declare type SetParentKeyOp = {
267
- opId?: string;
268
- id: string;
269
- type: OpCode.SET_PARENT_KEY;
270
- parentKey: string;
271
- };
272
- declare type DeleteObjectKeyOp = {
273
- opId?: string;
274
- id: string;
275
- type: OpCode.DELETE_OBJECT_KEY;
276
- key: string;
277
- };
278
- declare enum WebsocketCloseCodes {
279
- CLOSE_ABNORMAL = 1006,
280
- INVALID_MESSAGE_FORMAT = 4000,
281
- NOT_ALLOWED = 4001,
282
- MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
283
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
284
- MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
285
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
286
- CLOSE_WITHOUT_RETRY = 4999
287
- }
185
+ declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
288
186
 
289
187
  /**
290
188
  * Tools to help with the controlled deprecation of public APIs.
@@ -317,33 +215,13 @@ declare function throwUsageError(message: string): void;
317
215
  */
318
216
  declare function errorIf(condition: unknown, message: string): void;
319
217
 
320
- declare function lsonToJson(value: Lson | AbstractCrdt): Json;
218
+ declare function lsonToJson(value: Lson): Json;
321
219
  declare function patchLiveObjectKey<O extends LsonObject>(liveObject: LiveObject<O>, key: keyof O, prev: unknown, next: unknown): void;
322
220
  declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
323
221
 
324
222
  declare function makePosition(before?: string, after?: string): string;
325
223
  declare function comparePosition(posA: string, posB: string): number;
326
224
 
327
- /**
328
- * Helper function that can be used to implement exhaustive switch statements
329
- * with TypeScript. Example usage:
330
- *
331
- * type Fruit = "🍎" | "🍌";
332
- *
333
- * switch (fruit) {
334
- * case "🍎":
335
- * case "🍌":
336
- * return doSomething();
337
- *
338
- * default:
339
- * return assertNever(fruit, "Unknown fruit");
340
- * }
341
- *
342
- * If now the Fruit union is extended (i.e. add "🍒"), TypeScript will catch
343
- * this *statically*, rather than at runtime, and force you to handle the
344
- * 🍒 case.
345
- */
346
- declare function assertNever(_value: never, errmsg: string): never;
347
225
  /**
348
226
  * Alternative to JSON.parse() that will not throw in production. If the passed
349
227
  * string cannot be parsed, this will return `undefined`.
@@ -354,4 +232,4 @@ declare function tryParseJson(rawMessage: string): Json | undefined;
354
232
  */
355
233
  declare function b64decode(b64value: string): string;
356
234
 
357
- export { BroadcastEventClientMsg, ClientMsg, 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, UpdatePresenceClientMsg, UpdateStorageClientMsg, UserJoinServerMsg, WebsocketCloseCodes, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, isChildCrdt, isRootCrdt, lsonToJson, makePosition, patchImmutableObject, patchLiveObjectKey, throwUsageError, tryParseJson };
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
  }
@@ -169,14 +167,14 @@ Object.defineProperty(exports, "ClientMsgCode", {
169
167
  exports.comparePosition = LiveObject.comparePosition, exports.deprecate = LiveObject.deprecate,
170
168
  exports.deprecateIf = LiveObject.deprecateIf, exports.errorIf = LiveObject.errorIf,
171
169
  exports.isChildCrdt = LiveObject.isChildCrdt, exports.isRootCrdt = LiveObject.isRootCrdt,
172
- exports.makePosition = LiveObject.makePosition, exports.throwUsageError = LiveObject.throwUsageError,
170
+ exports.makePosition = LiveObject.makePosition, exports.nn = LiveObject.nn, exports.throwUsageError = LiveObject.throwUsageError,
173
171
  exports.tryParseJson = LiveObject.tryParseJson, exports.lsonToJson = lsonToJson,
174
172
  exports.patchImmutableObject = function(state, updates) {
175
173
  return updates.reduce((function(state, update) {
176
174
  return function(state, update) {
177
175
  var path = function(node) {
178
- 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),
179
- 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;
180
178
  return path;
181
179
  }(update.node);
182
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, x as b64decode, s as comparePosition, n as deprecate, h as deprecateIf, o as errorIf, v as isChildCrdt, f as isRootCrdt, u as makePosition, p as throwUsageError, t as tryParseJson } 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.12",
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
  },