@liveblocks/client 0.16.4-beta2 → 0.16.4

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.js CHANGED
@@ -4,33 +4,364 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var LiveObject = require('./shared.js');
6
6
 
7
+ function lsonObjectToJson(obj) {
8
+ var result = {};
7
9
 
10
+ for (var _key in obj) {
11
+ var val = obj[_key];
12
+
13
+ if (val !== undefined) {
14
+ result[_key] = lsonToJson(val);
15
+ }
16
+ }
17
+
18
+ return result;
19
+ }
20
+
21
+ function liveObjectToJson(liveObject) {
22
+ return lsonObjectToJson(liveObject.toObject());
23
+ }
24
+
25
+ function liveMapToJson(map) {
26
+ var result = {};
27
+
28
+ for (var _iterator = LiveObject._createForOfIteratorHelperLoose(map.entries()), _step; !(_step = _iterator()).done;) {
29
+ var _step$value = _step.value,
30
+ _key2 = _step$value[0],
31
+ value = _step$value[1];
32
+ result[_key2] = lsonToJson(value);
33
+ }
34
+
35
+ return result;
36
+ }
37
+
38
+ function lsonListToJson(value) {
39
+ return value.map(lsonToJson);
40
+ }
41
+
42
+ function liveListToJson(value) {
43
+ return lsonListToJson(value.toArray());
44
+ }
45
+
46
+ function lsonToJson(value) {
47
+ if (value instanceof LiveObject.LiveObject) {
48
+ return liveObjectToJson(value);
49
+ } else if (value instanceof LiveObject.LiveList) {
50
+ return liveListToJson(value);
51
+ } else if (value instanceof LiveObject.LiveMap) {
52
+ return liveMapToJson(value);
53
+ } else if (value instanceof LiveObject.LiveRegister) {
54
+ return value.data;
55
+ } else if (value instanceof LiveObject.AbstractCrdt) {
56
+ throw new Error("Unhandled subclass of AbstractCrdt encountered");
57
+ }
58
+
59
+ if (Array.isArray(value)) {
60
+ return lsonListToJson(value);
61
+ } else if (isPlainObject(value)) {
62
+ return lsonObjectToJson(value);
63
+ }
64
+
65
+ return value;
66
+ }
67
+
68
+ function isPlainObject(obj) {
69
+ return obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
70
+ }
71
+
72
+ function anyToCrdt(obj) {
73
+ if (obj == null) {
74
+ return obj;
75
+ }
76
+
77
+ if (Array.isArray(obj)) {
78
+ return new LiveObject.LiveList(obj.map(anyToCrdt));
79
+ }
80
+
81
+ if (isPlainObject(obj)) {
82
+ var init = {};
83
+
84
+ for (var _key3 in obj) {
85
+ init[_key3] = anyToCrdt(obj[_key3]);
86
+ }
87
+
88
+ return new LiveObject.LiveObject(init);
89
+ }
90
+
91
+ return obj;
92
+ }
93
+
94
+ function patchLiveList(liveList, prev, next) {
95
+ var i = 0;
96
+ var prevEnd = prev.length - 1;
97
+ var nextEnd = next.length - 1;
98
+ var prevNode = prev[0];
99
+ var nextNode = next[0];
100
+
101
+ outer: {
102
+ while (prevNode === nextNode) {
103
+ ++i;
104
+
105
+ if (i > prevEnd || i > nextEnd) {
106
+ break outer;
107
+ }
108
+
109
+ prevNode = prev[i];
110
+ nextNode = next[i];
111
+ }
112
+
113
+ prevNode = prev[prevEnd];
114
+ nextNode = next[nextEnd];
115
+
116
+ while (prevNode === nextNode) {
117
+ prevEnd--;
118
+ nextEnd--;
119
+
120
+ if (i > prevEnd || i > nextEnd) {
121
+ break outer;
122
+ }
123
+
124
+ prevNode = prev[prevEnd];
125
+ nextNode = next[nextEnd];
126
+ }
127
+ }
128
+
129
+ if (i > prevEnd) {
130
+ if (i <= nextEnd) {
131
+ while (i <= nextEnd) {
132
+ liveList.insert(anyToCrdt(next[i]), i);
133
+ i++;
134
+ }
135
+ }
136
+ } else if (i > nextEnd) {
137
+ var localI = i;
138
+
139
+ while (localI <= prevEnd) {
140
+ liveList.delete(i);
141
+ localI++;
142
+ }
143
+ } else {
144
+ while (i <= prevEnd && i <= nextEnd) {
145
+ prevNode = prev[i];
146
+ nextNode = next[i];
147
+ var liveListNode = liveList.get(i);
148
+
149
+ if (liveListNode instanceof LiveObject.LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode)) {
150
+ patchLiveObject(liveListNode, prevNode, nextNode);
151
+ } else {
152
+ liveList.set(i, anyToCrdt(nextNode));
153
+ }
154
+
155
+ i++;
156
+ }
157
+
158
+ while (i <= nextEnd) {
159
+ liveList.insert(anyToCrdt(next[i]), i);
160
+ i++;
161
+ }
162
+
163
+ var _localI = i;
164
+
165
+ while (_localI <= prevEnd) {
166
+ liveList.delete(i);
167
+ _localI++;
168
+ }
169
+ }
170
+ }
171
+ function patchLiveObjectKey(liveObject, key, prev, next) {
172
+ if (process.env.NODE_ENV !== "production") {
173
+ var nonSerializableValue = LiveObject.findNonSerializableValue(next);
174
+
175
+ if (nonSerializableValue) {
176
+ console.error("New state path: '" + nonSerializableValue.path + "' value: '" + nonSerializableValue.value + "' is not serializable.\nOnly serializable value can be synced with Liveblocks.");
177
+ return;
178
+ }
179
+ }
180
+
181
+ var value = liveObject.get(key);
182
+
183
+ if (next === undefined) {
184
+ liveObject.delete(key);
185
+ } else if (value === undefined) {
186
+ liveObject.set(key, anyToCrdt(next));
187
+ } else if (prev === next) {
188
+ return;
189
+ } else if (value instanceof LiveObject.LiveList && Array.isArray(prev) && Array.isArray(next)) {
190
+ patchLiveList(value, prev, next);
191
+ } else if (value instanceof LiveObject.LiveObject && isPlainObject(prev) && isPlainObject(next)) {
192
+ patchLiveObject(value, prev, next);
193
+ } else {
194
+ liveObject.set(key, anyToCrdt(next));
195
+ }
196
+ }
197
+ function patchLiveObject(root, prev, next) {
198
+ var updates = {};
199
+
200
+ for (var _key4 in next) {
201
+ patchLiveObjectKey(root, _key4, prev[_key4], next[_key4]);
202
+ }
203
+
204
+ for (var _key5 in prev) {
205
+ if (next[_key5] === undefined) {
206
+ root.delete(_key5);
207
+ }
208
+ }
209
+
210
+ if (Object.keys(updates).length > 0) {
211
+ root.update(updates);
212
+ }
213
+ }
214
+
215
+ function getParentsPath(node) {
216
+ var path = [];
217
+
218
+ while (node._parentKey != null && node._parent != null) {
219
+ if (node._parent instanceof LiveObject.LiveList) {
220
+ path.push(node._parent._indexOfPosition(node._parentKey));
221
+ } else {
222
+ path.push(node._parentKey);
223
+ }
224
+
225
+ node = node._parent;
226
+ }
227
+
228
+ return path;
229
+ }
230
+
231
+ function patchImmutableObject(state, updates) {
232
+ return updates.reduce(function (state, update) {
233
+ return patchImmutableObjectWithUpdate(state, update);
234
+ }, state);
235
+ }
236
+
237
+ function patchImmutableObjectWithUpdate(state, update) {
238
+ var path = getParentsPath(update.node);
239
+ return patchImmutableNode(state, path, update);
240
+ }
241
+
242
+ function patchImmutableNode(state, path, update) {
243
+ var pathItem = path.pop();
244
+
245
+ if (pathItem === undefined) {
246
+ switch (update.type) {
247
+ case "LiveObject":
248
+ {
249
+ if (typeof state !== "object") {
250
+ throw new Error("Internal: received update on LiveObject but state was not an object");
251
+ }
252
+
253
+ var newState = Object.assign({}, state);
254
+
255
+ for (var _key6 in update.updates) {
256
+ var _update$updates$_key, _update$updates$_key2;
257
+
258
+ if (((_update$updates$_key = update.updates[_key6]) == null ? void 0 : _update$updates$_key.type) === "update") {
259
+ var val = update.node.get(_key6);
260
+
261
+ if (val !== undefined) {
262
+ newState[_key6] = lsonToJson(val);
263
+ }
264
+ } else if (((_update$updates$_key2 = update.updates[_key6]) == null ? void 0 : _update$updates$_key2.type) === "delete") {
265
+ delete newState[_key6];
266
+ }
267
+ }
268
+
269
+ return newState;
270
+ }
271
+
272
+ case "LiveList":
273
+ {
274
+ if (Array.isArray(state) === false) {
275
+ throw new Error("Internal: received update on LiveList but state was not an array");
276
+ }
277
+
278
+ var _newState = state.map(function (x) {
279
+ return x;
280
+ });
281
+
282
+ var _loop = function _loop() {
283
+ var listUpdate = _step2.value;
284
+
285
+ if (listUpdate.type === "set") {
286
+ _newState = _newState.map(function (item, index) {
287
+ return index === listUpdate.index ? listUpdate.item : item;
288
+ });
289
+ } else if (listUpdate.type === "insert") {
290
+ if (listUpdate.index === _newState.length) {
291
+ _newState.push(lsonToJson(listUpdate.item));
292
+ } else {
293
+ _newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index));
294
+ }
295
+ } else if (listUpdate.type === "delete") {
296
+ _newState.splice(listUpdate.index, 1);
297
+ } else if (listUpdate.type === "move") {
298
+ if (listUpdate.previousIndex > listUpdate.index) {
299
+ _newState = [].concat(_newState.slice(0, listUpdate.index), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1));
300
+ } else {
301
+ _newState = [].concat(_newState.slice(0, listUpdate.previousIndex), _newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1), [lsonToJson(listUpdate.item)], _newState.slice(listUpdate.index + 1));
302
+ }
303
+ }
304
+ };
305
+
306
+ for (var _iterator2 = LiveObject._createForOfIteratorHelperLoose(update.updates), _step2; !(_step2 = _iterator2()).done;) {
307
+ _loop();
308
+ }
309
+
310
+ return _newState;
311
+ }
312
+
313
+ case "LiveMap":
314
+ {
315
+ if (typeof state !== "object") {
316
+ throw new Error("Internal: received update on LiveMap but state was not an object");
317
+ }
318
+
319
+ var _newState2 = Object.assign({}, state);
320
+
321
+ for (var _key7 in update.updates) {
322
+ var _update$updates$_key3, _update$updates$_key4;
323
+
324
+ if (((_update$updates$_key3 = update.updates[_key7]) == null ? void 0 : _update$updates$_key3.type) === "update") {
325
+ _newState2[_key7] = lsonToJson(update.node.get(_key7));
326
+ } else if (((_update$updates$_key4 = update.updates[_key7]) == null ? void 0 : _update$updates$_key4.type) === "delete") {
327
+ delete _newState2[_key7];
328
+ }
329
+ }
330
+
331
+ return _newState2;
332
+ }
333
+ }
334
+ }
335
+
336
+ if (Array.isArray(state)) {
337
+ var newArray = [].concat(state);
338
+ newArray[pathItem] = patchImmutableNode(state[pathItem], path, update);
339
+ return newArray;
340
+ } else {
341
+ var _extends2;
342
+
343
+ return LiveObject._extends({}, state, (_extends2 = {}, _extends2[pathItem] = patchImmutableNode(state[pathItem], path, update), _extends2));
344
+ }
345
+ }
8
346
 
9
347
  Object.defineProperty(exports, 'ClientMessageType', {
10
- enumerable: true,
11
- get: function () { return LiveObject.ClientMessageType; }
348
+ enumerable: true,
349
+ get: function () { return LiveObject.ClientMessageType; }
12
350
  });
13
351
  Object.defineProperty(exports, 'CrdtType', {
14
- enumerable: true,
15
- get: function () { return LiveObject.CrdtType; }
352
+ enumerable: true,
353
+ get: function () { return LiveObject.CrdtType; }
16
354
  });
17
355
  Object.defineProperty(exports, 'OpType', {
18
- enumerable: true,
19
- get: function () { return LiveObject.OpType; }
356
+ enumerable: true,
357
+ get: function () { return LiveObject.OpType; }
20
358
  });
21
359
  Object.defineProperty(exports, 'ServerMessageType', {
22
- enumerable: true,
23
- get: function () { return LiveObject.ServerMessageType; }
24
- });
25
- Object.defineProperty(exports, 'WebsocketCloseCodes', {
26
- enumerable: true,
27
- get: function () { return LiveObject.WebsocketCloseCodes; }
360
+ enumerable: true,
361
+ get: function () { return LiveObject.ServerMessageType; }
28
362
  });
29
- exports.compare = LiveObject.compare;
30
363
  exports.deprecate = LiveObject.deprecate;
31
364
  exports.deprecateIf = LiveObject.deprecateIf;
32
- exports.makePosition = LiveObject.makePosition;
33
- exports.max = LiveObject.max;
34
- exports.min = LiveObject.min;
35
- exports.pos = LiveObject.pos;
36
- exports.posCodes = LiveObject.posCodes;
365
+ exports.lsonToJson = lsonToJson;
366
+ exports.patchImmutableObject = patchImmutableObject;
367
+ exports.patchLiveObjectKey = patchLiveObjectKey;
package/internal.mjs CHANGED
@@ -1 +1,320 @@
1
- export { C as ClientMessageType, n as CrdtType, O as OpType, S as ServerMessageType, W as WebsocketCloseCodes, v as compare, k as deprecate, l as deprecateIf, s as makePosition, q as max, o as min, u as pos, t as posCodes } from './shared.mjs';
1
+ import { L as LiveObject, b as LiveList, h as LiveMap, j as LiveRegister, A as AbstractCrdt, k as findNonSerializableValue } from './shared.mjs';
2
+ export { C as ClientMessageType, l as CrdtType, O as OpType, S as ServerMessageType, n as deprecate, f as deprecateIf } from './shared.mjs';
3
+
4
+ function lsonObjectToJson(obj) {
5
+ const result = {};
6
+ for (const key in obj) {
7
+ const val = obj[key];
8
+ if (val !== undefined) {
9
+ result[key] = lsonToJson(val);
10
+ }
11
+ }
12
+ return result;
13
+ }
14
+ function liveObjectToJson(liveObject) {
15
+ return lsonObjectToJson(liveObject.toObject());
16
+ }
17
+ function liveMapToJson(map) {
18
+ const result = {};
19
+ for (const [key, value] of map.entries()) {
20
+ result[key] = lsonToJson(value);
21
+ }
22
+ return result;
23
+ }
24
+ function lsonListToJson(value) {
25
+ return value.map(lsonToJson);
26
+ }
27
+ function liveListToJson(value) {
28
+ return lsonListToJson(value.toArray());
29
+ }
30
+ function lsonToJson(value) {
31
+ // ^^^^^^^^^^^^
32
+ // FIXME: Remove me later. This requires the
33
+ // addition of a concrete LiveStructure type first.
34
+ // Check for LiveStructure datastructures first
35
+ if (value instanceof LiveObject) {
36
+ return liveObjectToJson(value);
37
+ }
38
+ else if (value instanceof LiveList) {
39
+ return liveListToJson(value);
40
+ }
41
+ else if (value instanceof LiveMap) {
42
+ return liveMapToJson(value);
43
+ }
44
+ else if (value instanceof LiveRegister) {
45
+ return value.data;
46
+ }
47
+ else if (value instanceof AbstractCrdt) {
48
+ // This code path should never be taken
49
+ throw new Error("Unhandled subclass of AbstractCrdt encountered");
50
+ }
51
+ // Then for composite Lson values
52
+ if (Array.isArray(value)) {
53
+ return lsonListToJson(value);
54
+ }
55
+ else if (isPlainObject(value)) {
56
+ return lsonObjectToJson(value);
57
+ }
58
+ // Finally, if value is an LsonScalar, then it's also a valid JsonScalar
59
+ return value;
60
+ }
61
+ function isPlainObject(obj) {
62
+ return (obj !== null && Object.prototype.toString.call(obj) === "[object Object]");
63
+ }
64
+ function anyToCrdt(obj) {
65
+ // ^^^ AbstractCrdt?
66
+ if (obj == null) {
67
+ return obj;
68
+ }
69
+ if (Array.isArray(obj)) {
70
+ return new LiveList(obj.map(anyToCrdt));
71
+ }
72
+ if (isPlainObject(obj)) {
73
+ const init = {};
74
+ for (const key in obj) {
75
+ init[key] = anyToCrdt(obj[key]);
76
+ }
77
+ return new LiveObject(init);
78
+ }
79
+ return obj;
80
+ }
81
+ function patchLiveList(liveList, prev, next) {
82
+ let i = 0;
83
+ let prevEnd = prev.length - 1;
84
+ let nextEnd = next.length - 1;
85
+ let prevNode = prev[0];
86
+ let nextNode = next[0];
87
+ /**
88
+ * For A,B,C => A,B,C,D
89
+ * i = 3, prevEnd = 2, nextEnd = 3
90
+ *
91
+ * For A,B,C => B,C
92
+ * i = 2, prevEnd = 2, nextEnd = 1
93
+ *
94
+ * For B,C => A,B,C
95
+ * i = 0, pre
96
+ */
97
+ outer: {
98
+ while (prevNode === nextNode) {
99
+ ++i;
100
+ if (i > prevEnd || i > nextEnd) {
101
+ break outer;
102
+ }
103
+ prevNode = prev[i];
104
+ nextNode = next[i];
105
+ }
106
+ prevNode = prev[prevEnd];
107
+ nextNode = next[nextEnd];
108
+ while (prevNode === nextNode) {
109
+ prevEnd--;
110
+ nextEnd--;
111
+ if (i > prevEnd || i > nextEnd) {
112
+ break outer;
113
+ }
114
+ prevNode = prev[prevEnd];
115
+ nextNode = next[nextEnd];
116
+ }
117
+ }
118
+ if (i > prevEnd) {
119
+ if (i <= nextEnd) {
120
+ while (i <= nextEnd) {
121
+ liveList.insert(anyToCrdt(next[i]), i);
122
+ i++;
123
+ }
124
+ }
125
+ }
126
+ else if (i > nextEnd) {
127
+ let localI = i;
128
+ while (localI <= prevEnd) {
129
+ liveList.delete(i);
130
+ localI++;
131
+ }
132
+ }
133
+ else {
134
+ while (i <= prevEnd && i <= nextEnd) {
135
+ prevNode = prev[i];
136
+ nextNode = next[i];
137
+ const liveListNode = liveList.get(i);
138
+ if (liveListNode instanceof LiveObject &&
139
+ isPlainObject(prevNode) &&
140
+ isPlainObject(nextNode)) {
141
+ patchLiveObject(liveListNode, prevNode, nextNode);
142
+ }
143
+ else {
144
+ liveList.set(i, anyToCrdt(nextNode));
145
+ }
146
+ i++;
147
+ }
148
+ while (i <= nextEnd) {
149
+ liveList.insert(anyToCrdt(next[i]), i);
150
+ i++;
151
+ }
152
+ let localI = i;
153
+ while (localI <= prevEnd) {
154
+ liveList.delete(i);
155
+ localI++;
156
+ }
157
+ }
158
+ }
159
+ function patchLiveObjectKey(liveObject, key, prev, next) {
160
+ if (process.env.NODE_ENV !== "production") {
161
+ const nonSerializableValue = findNonSerializableValue(next);
162
+ if (nonSerializableValue) {
163
+ console.error(`New state path: '${nonSerializableValue.path}' value: '${nonSerializableValue.value}' is not serializable.\nOnly serializable value can be synced with Liveblocks.`);
164
+ return;
165
+ }
166
+ }
167
+ const value = liveObject.get(key);
168
+ if (next === undefined) {
169
+ liveObject.delete(key);
170
+ }
171
+ else if (value === undefined) {
172
+ liveObject.set(key, anyToCrdt(next));
173
+ }
174
+ else if (prev === next) {
175
+ return;
176
+ }
177
+ else if (value instanceof LiveList &&
178
+ Array.isArray(prev) &&
179
+ Array.isArray(next)) {
180
+ patchLiveList(value, prev, next);
181
+ }
182
+ else if (value instanceof LiveObject &&
183
+ isPlainObject(prev) &&
184
+ isPlainObject(next)) {
185
+ patchLiveObject(value, prev, next);
186
+ }
187
+ else {
188
+ liveObject.set(key, anyToCrdt(next));
189
+ }
190
+ }
191
+ function patchLiveObject(root, prev, next) {
192
+ const updates = {};
193
+ for (const key in next) {
194
+ patchLiveObjectKey(root, key, prev[key], next[key]);
195
+ }
196
+ for (const key in prev) {
197
+ if (next[key] === undefined) {
198
+ root.delete(key);
199
+ }
200
+ }
201
+ if (Object.keys(updates).length > 0) {
202
+ root.update(updates);
203
+ }
204
+ }
205
+ function getParentsPath(node) {
206
+ const path = [];
207
+ while (node._parentKey != null && node._parent != null) {
208
+ if (node._parent instanceof LiveList) {
209
+ path.push(node._parent._indexOfPosition(node._parentKey));
210
+ }
211
+ else {
212
+ path.push(node._parentKey);
213
+ }
214
+ node = node._parent;
215
+ }
216
+ return path;
217
+ }
218
+ function patchImmutableObject(state, updates) {
219
+ return updates.reduce((state, update) => patchImmutableObjectWithUpdate(state, update), state);
220
+ }
221
+ function patchImmutableObjectWithUpdate(state, update) {
222
+ const path = getParentsPath(update.node);
223
+ return patchImmutableNode(state, path, update);
224
+ }
225
+ function patchImmutableNode(state, path, update) {
226
+ var _a, _b, _c, _d;
227
+ const pathItem = path.pop();
228
+ if (pathItem === undefined) {
229
+ switch (update.type) {
230
+ case "LiveObject": {
231
+ if (typeof state !== "object") {
232
+ throw new Error("Internal: received update on LiveObject but state was not an object");
233
+ }
234
+ const newState = Object.assign({}, state);
235
+ for (const key in update.updates) {
236
+ if (((_a = update.updates[key]) === null || _a === void 0 ? void 0 : _a.type) === "update") {
237
+ const val = update.node.get(key);
238
+ if (val !== undefined) {
239
+ newState[key] = lsonToJson(val);
240
+ }
241
+ }
242
+ else if (((_b = update.updates[key]) === null || _b === void 0 ? void 0 : _b.type) === "delete") {
243
+ delete newState[key];
244
+ }
245
+ }
246
+ return newState;
247
+ }
248
+ case "LiveList": {
249
+ if (Array.isArray(state) === false) {
250
+ throw new Error("Internal: received update on LiveList but state was not an array");
251
+ }
252
+ let newState = state.map((x) => x);
253
+ for (const listUpdate of update.updates) {
254
+ if (listUpdate.type === "set") {
255
+ newState = newState.map((item, index) => index === listUpdate.index ? listUpdate.item : item);
256
+ }
257
+ else if (listUpdate.type === "insert") {
258
+ if (listUpdate.index === newState.length) {
259
+ newState.push(lsonToJson(listUpdate.item));
260
+ }
261
+ else {
262
+ newState = [
263
+ ...newState.slice(0, listUpdate.index),
264
+ lsonToJson(listUpdate.item),
265
+ ...newState.slice(listUpdate.index),
266
+ ];
267
+ }
268
+ }
269
+ else if (listUpdate.type === "delete") {
270
+ newState.splice(listUpdate.index, 1);
271
+ }
272
+ else if (listUpdate.type === "move") {
273
+ if (listUpdate.previousIndex > listUpdate.index) {
274
+ newState = [
275
+ ...newState.slice(0, listUpdate.index),
276
+ lsonToJson(listUpdate.item),
277
+ ...newState.slice(listUpdate.index, listUpdate.previousIndex),
278
+ ...newState.slice(listUpdate.previousIndex + 1),
279
+ ];
280
+ }
281
+ else {
282
+ newState = [
283
+ ...newState.slice(0, listUpdate.previousIndex),
284
+ ...newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1),
285
+ lsonToJson(listUpdate.item),
286
+ ...newState.slice(listUpdate.index + 1),
287
+ ];
288
+ }
289
+ }
290
+ }
291
+ return newState;
292
+ }
293
+ case "LiveMap": {
294
+ if (typeof state !== "object") {
295
+ throw new Error("Internal: received update on LiveMap but state was not an object");
296
+ }
297
+ const newState = Object.assign({}, state);
298
+ for (const key in update.updates) {
299
+ if (((_c = update.updates[key]) === null || _c === void 0 ? void 0 : _c.type) === "update") {
300
+ newState[key] = lsonToJson(update.node.get(key));
301
+ }
302
+ else if (((_d = update.updates[key]) === null || _d === void 0 ? void 0 : _d.type) === "delete") {
303
+ delete newState[key];
304
+ }
305
+ }
306
+ return newState;
307
+ }
308
+ }
309
+ }
310
+ if (Array.isArray(state)) {
311
+ const newArray = [...state];
312
+ newArray[pathItem] = patchImmutableNode(state[pathItem], path, update);
313
+ return newArray;
314
+ }
315
+ else {
316
+ return Object.assign(Object.assign({}, state), { [pathItem]: patchImmutableNode(state[pathItem], path, update) });
317
+ }
318
+ }
319
+
320
+ export { lsonToJson, patchImmutableObject, patchLiveObjectKey };