@liveblocks/client 0.17.11-debug2 → 0.18.0-beta1

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,5 +1,5 @@
1
- import { e as JsonObject, J as Json, B as BaseUserMeta, g as Lson, h as LsonObject, c as LiveObject, S as StorageUpdate } from './index-0007883d.js';
2
- export { i as LiveNode, j as Resolve, k as RoomInitializers, W as WebsocketCloseCodes, l as isJsonArray, m as isJsonObject, n as isJsonScalar } from './index-0007883d.js';
1
+ import { i as JsonObject, J as Json, B as BaseUserMeta, k as Lson, l as LsonObject, c as LiveObject, S as StorageUpdate } from './index-f955942f.js';
2
+ export { n as LiveNode, o as Resolve, p as RoomInitializers, q as ToImmutable, T as ToJson, W as WebsocketCloseCodes, m as asArrayWithLegacyMethods, r as isJsonArray, s as isJsonObject, t as isJsonScalar } from './index-f955942f.js';
3
3
 
4
4
  declare enum OpCode {
5
5
  INIT = 0,
@@ -219,18 +219,40 @@ declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
219
219
  * The User whose Presence has changed.
220
220
  */
221
221
  actor: number;
222
+ /**
223
+ * When set, signifies that this is a Full Presence™ update, not a patch.
224
+ *
225
+ * The numeric value itself no longer has specific meaning. Historically,
226
+ * this field was intended so that clients could ignore these broadcasted
227
+ * full presence messages, but it turned out that getting a full presence
228
+ * "keyframe" from time to time was useful.
229
+ *
230
+ * So nowadays, the presence (pun intended) of this `targetActor` field
231
+ * is a backward-compatible way of expressing that the `data` contains
232
+ * all presence fields, and isn't a partial "patch".
233
+ */
234
+ targetActor: number;
222
235
  /**
223
236
  * The partial or full Presence of a User. If the `targetActor` field is set,
224
237
  * this will be the full Presence, otherwise it only contain the fields that
225
238
  * have changed since the last broadcast.
226
239
  */
227
240
  data: TPresence;
241
+ } | {
242
+ type: ServerMsgCode.UPDATE_PRESENCE;
243
+ /**
244
+ * The User whose Presence has changed.
245
+ */
246
+ actor: number;
228
247
  /**
229
- * If this message was sent in response to a newly joined user, this field
230
- * indicates which client this message is for. Other existing clients may
231
- * ignore this message if this message isn't targeted for them.
248
+ * Not set for partial presence updates.
232
249
  */
233
- targetActor?: number;
250
+ targetActor?: undefined;
251
+ /**
252
+ * A partial Presence patch to apply to the User. It will only contain the
253
+ * fields that have changed since the last broadcast.
254
+ */
255
+ data: Partial<TPresence>;
234
256
  };
235
257
  /**
236
258
  * Sent by the WebSocket server and broadcasted to all clients to announce that
@@ -397,11 +419,16 @@ declare function errorIf(condition: unknown, message: string): void;
397
419
 
398
420
  declare function lsonToJson(value: Lson): Json;
399
421
  declare function patchLiveObjectKey<O extends LsonObject, K extends keyof O, V extends Lson>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void;
400
- declare function patchImmutableObject<S extends JsonObject>(state: S, updates: StorageUpdate[]): S;
422
+ declare function legacy_patchImmutableObject<S extends JsonObject>(state: S, updates: StorageUpdate[]): S;
401
423
 
402
424
  declare function makePosition(before?: string, after?: string): string;
403
425
  declare function comparePosition(posA: string, posB: string): number;
404
426
 
427
+ /**
428
+ * Freezes the given argument, but only in development builds. In production
429
+ * builds, this is a no-op for performance reasons.
430
+ */
431
+ declare const freeze: typeof Object.freeze;
405
432
  declare function isPlainObject(blob: unknown): blob is {
406
433
  [key: string]: unknown;
407
434
  };
@@ -415,4 +442,4 @@ declare function tryParseJson(rawMessage: string): Json | undefined;
415
442
  */
416
443
  declare function b64decode(b64value: string): string;
417
444
 
418
- export { AppOnlyAuthToken, AuthToken, BroadcastEventClientMsg, BroadcastedEventServerMsg, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, IdTuple, InitialDocumentStateServerMsg, NodeMap, Op, OpCode, ParentToChildNodeMap, RoomAuthToken, RoomStateServerMsg, Scope, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UserJoinServerMsg, UserLeftServerMsg, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, isAppOnlyAuthToken, isAuthToken, isChildCrdt, isPlainObject, isRoomAuthToken, isRootCrdt, isScope, lsonToJson, makePosition, nn, patchImmutableObject, patchLiveObjectKey, throwUsageError, tryParseJson };
445
+ export { AppOnlyAuthToken, AuthToken, BroadcastEventClientMsg, BroadcastedEventServerMsg, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, IdTuple, InitialDocumentStateServerMsg, NodeMap, Op, OpCode, ParentToChildNodeMap, RoomAuthToken, RoomStateServerMsg, Scope, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UserJoinServerMsg, UserLeftServerMsg, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, freeze, isAppOnlyAuthToken, isAuthToken, isChildCrdt, isPlainObject, isRoomAuthToken, isRootCrdt, isScope, legacy_patchImmutableObject, lsonToJson, makePosition, nn, patchLiveObjectKey, throwUsageError, tryParseJson };
package/internal.js CHANGED
@@ -148,7 +148,7 @@ function _optionalChain(ops) {
148
148
  }
149
149
  return value;
150
150
  }
151
- var _chunkQLMVHHAZjs = require("./chunk-QLMVHHAZ.js");
151
+ var _chunkZNCSOBAXjs = require("./chunk-ZNCSOBAX.js");
152
152
  // src/immutable.ts
153
153
  function lsonObjectToJson(obj) {
154
154
  var result = {};
@@ -194,26 +194,26 @@ function liveListToJson(value) {
194
194
  return lsonListToJson(value.toArray());
195
195
  }
196
196
  function lsonToJson(value) {
197
- if (_instanceof(value, _chunkQLMVHHAZjs.LiveObject)) {
197
+ if (_instanceof(value, _chunkZNCSOBAXjs.LiveObject)) {
198
198
  return liveObjectToJson(value);
199
- } else if (_instanceof(value, _chunkQLMVHHAZjs.LiveList)) {
199
+ } else if (_instanceof(value, _chunkZNCSOBAXjs.LiveList)) {
200
200
  return liveListToJson(value);
201
- } else if (_instanceof(value, _chunkQLMVHHAZjs.LiveMap)) {
201
+ } else if (_instanceof(value, _chunkZNCSOBAXjs.LiveMap)) {
202
202
  return liveMapToJson(value);
203
- } else if (_instanceof(value, _chunkQLMVHHAZjs.LiveRegister)) {
203
+ } else if (_instanceof(value, _chunkZNCSOBAXjs.LiveRegister)) {
204
204
  return value.data;
205
205
  }
206
206
  if (Array.isArray(value)) {
207
207
  return lsonListToJson(value);
208
- } else if (_chunkQLMVHHAZjs.isPlainObject.call(void 0, value)) {
208
+ } else if (_chunkZNCSOBAXjs.isPlainObject.call(void 0, value)) {
209
209
  return lsonObjectToJson(value);
210
210
  }
211
211
  return value;
212
212
  }
213
213
  function deepLiveify(value) {
214
214
  if (Array.isArray(value)) {
215
- return new (0, _chunkQLMVHHAZjs.LiveList)(value.map(deepLiveify));
216
- } else if (_chunkQLMVHHAZjs.isPlainObject.call(void 0, value)) {
215
+ return new (0, _chunkZNCSOBAXjs.LiveList)(value.map(deepLiveify));
216
+ } else if (_chunkZNCSOBAXjs.isPlainObject.call(void 0, value)) {
217
217
  var init = {};
218
218
  for(var key in value){
219
219
  var val = value[key];
@@ -222,7 +222,7 @@ function deepLiveify(value) {
222
222
  }
223
223
  init[key] = deepLiveify(val);
224
224
  }
225
- return new (0, _chunkQLMVHHAZjs.LiveObject)(init);
225
+ return new (0, _chunkZNCSOBAXjs.LiveObject)(init);
226
226
  } else {
227
227
  return value;
228
228
  }
@@ -272,7 +272,7 @@ function patchLiveList(liveList, prev, next) {
272
272
  prevNode = prev[i];
273
273
  nextNode = next[i];
274
274
  var liveListNode = liveList.get(i);
275
- if (_chunkQLMVHHAZjs.isLiveObject.call(void 0, liveListNode) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, prevNode) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, nextNode)) {
275
+ if (_chunkZNCSOBAXjs.isLiveObject.call(void 0, liveListNode) && _chunkZNCSOBAXjs.isPlainObject.call(void 0, prevNode) && _chunkZNCSOBAXjs.isPlainObject.call(void 0, nextNode)) {
276
276
  patchLiveObject(liveListNode, prevNode, nextNode);
277
277
  } else {
278
278
  liveList.set(i, deepLiveify(nextNode));
@@ -292,7 +292,7 @@ function patchLiveList(liveList, prev, next) {
292
292
  }
293
293
  function patchLiveObjectKey(liveObject, key, prev, next) {
294
294
  if (process.env.NODE_ENV !== "production") {
295
- var nonSerializableValue = _chunkQLMVHHAZjs.findNonSerializableValue.call(void 0, next);
295
+ var nonSerializableValue = _chunkZNCSOBAXjs.findNonSerializableValue.call(void 0, next);
296
296
  if (nonSerializableValue) {
297
297
  console.error("New state path: '".concat(nonSerializableValue.path, "' value: '").concat(nonSerializableValue.value, "' is not serializable.\nOnly serializable value can be synced with Liveblocks."));
298
298
  return;
@@ -305,9 +305,9 @@ function patchLiveObjectKey(liveObject, key, prev, next) {
305
305
  liveObject.set(key, deepLiveify(next));
306
306
  } else if (prev === next) {
307
307
  return;
308
- } else if (_chunkQLMVHHAZjs.isLiveList.call(void 0, value) && Array.isArray(prev) && Array.isArray(next)) {
308
+ } else if (_chunkZNCSOBAXjs.isLiveList.call(void 0, value) && Array.isArray(prev) && Array.isArray(next)) {
309
309
  patchLiveList(value, prev, next);
310
- } else if (_chunkQLMVHHAZjs.isLiveObject.call(void 0, value) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, prev) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, next)) {
310
+ } else if (_chunkZNCSOBAXjs.isLiveObject.call(void 0, value) && _chunkZNCSOBAXjs.isPlainObject.call(void 0, prev) && _chunkZNCSOBAXjs.isPlainObject.call(void 0, next)) {
311
311
  patchLiveObject(value, prev, next);
312
312
  } else {
313
313
  liveObject.set(key, deepLiveify(next));
@@ -330,7 +330,7 @@ function patchLiveObject(root, prev, next) {
330
330
  function getParentsPath(node) {
331
331
  var path = [];
332
332
  while(node.parent.type === "HasParent"){
333
- if (_chunkQLMVHHAZjs.isLiveList.call(void 0, node.parent.node)) {
333
+ if (_chunkZNCSOBAXjs.isLiveList.call(void 0, node.parent.node)) {
334
334
  path.push(node.parent.node._indexOfPosition(node.parent.key));
335
335
  } else {
336
336
  path.push(node.parent.key);
@@ -339,16 +339,16 @@ function getParentsPath(node) {
339
339
  }
340
340
  return path;
341
341
  }
342
- function patchImmutableObject(state, updates) {
342
+ function legacy_patchImmutableObject(state, updates) {
343
343
  return updates.reduce(function(state2, update) {
344
- return patchImmutableObjectWithUpdate(state2, update);
344
+ return legacy_patchImmutableObjectWithUpdate(state2, update);
345
345
  }, state);
346
346
  }
347
- function patchImmutableObjectWithUpdate(state, update) {
347
+ function legacy_patchImmutableObjectWithUpdate(state, update) {
348
348
  var path = getParentsPath(update.node);
349
- return patchImmutableNode(state, path, update);
349
+ return legacy_patchImmutableNode(state, path, update);
350
350
  }
351
- function patchImmutableNode(state, path, update) {
351
+ function legacy_patchImmutableNode(state, path, update) {
352
352
  var pathItem = path.pop();
353
353
  if (pathItem === void 0) {
354
354
  switch(update.type){
@@ -505,44 +505,46 @@ function patchImmutableNode(state, path, update) {
505
505
  }
506
506
  if (Array.isArray(state)) {
507
507
  var newArray = _toConsumableArray(state);
508
- newArray[pathItem] = patchImmutableNode(state[pathItem], path, update);
508
+ newArray[pathItem] = legacy_patchImmutableNode(state[pathItem], path, update);
509
509
  return newArray;
510
510
  } else if (state !== null && typeof state === "object") {
511
511
  var node = state[pathItem];
512
512
  if (node === void 0) {
513
513
  return state;
514
514
  } else {
515
- return _objectSpreadProps(_objectSpread({}, state), _defineProperty({}, pathItem, patchImmutableNode(node, path, update)));
515
+ return _objectSpreadProps(_objectSpread({}, state), _defineProperty({}, pathItem, legacy_patchImmutableNode(node, path, update)));
516
516
  }
517
517
  } else {
518
518
  return state;
519
519
  }
520
520
  }
521
- exports.ClientMsgCode = _chunkQLMVHHAZjs.ClientMsgCode;
522
- exports.CrdtType = _chunkQLMVHHAZjs.CrdtType;
523
- exports.OpCode = _chunkQLMVHHAZjs.OpCode;
524
- exports.ServerMsgCode = _chunkQLMVHHAZjs.ServerMsgCode;
525
- exports.WebsocketCloseCodes = _chunkQLMVHHAZjs.WebsocketCloseCodes;
526
- exports.assertNever = _chunkQLMVHHAZjs.assertNever;
527
- exports.b64decode = _chunkQLMVHHAZjs.b64decode;
528
- exports.comparePosition = _chunkQLMVHHAZjs.comparePosition;
529
- exports.deprecate = _chunkQLMVHHAZjs.deprecate;
530
- exports.deprecateIf = _chunkQLMVHHAZjs.deprecateIf;
531
- exports.errorIf = _chunkQLMVHHAZjs.errorIf;
532
- exports.isAppOnlyAuthToken = _chunkQLMVHHAZjs.isAppOnlyAuthToken;
533
- exports.isAuthToken = _chunkQLMVHHAZjs.isAuthToken;
534
- exports.isChildCrdt = _chunkQLMVHHAZjs.isChildCrdt;
535
- exports.isJsonArray = _chunkQLMVHHAZjs.isJsonArray;
536
- exports.isJsonObject = _chunkQLMVHHAZjs.isJsonObject;
537
- exports.isJsonScalar = _chunkQLMVHHAZjs.isJsonScalar;
538
- exports.isPlainObject = _chunkQLMVHHAZjs.isPlainObject;
539
- exports.isRoomAuthToken = _chunkQLMVHHAZjs.isRoomAuthToken;
540
- exports.isRootCrdt = _chunkQLMVHHAZjs.isRootCrdt;
541
- exports.isScope = _chunkQLMVHHAZjs.isScope;
521
+ exports.ClientMsgCode = _chunkZNCSOBAXjs.ClientMsgCode;
522
+ exports.CrdtType = _chunkZNCSOBAXjs.CrdtType;
523
+ exports.OpCode = _chunkZNCSOBAXjs.OpCode;
524
+ exports.ServerMsgCode = _chunkZNCSOBAXjs.ServerMsgCode;
525
+ exports.WebsocketCloseCodes = _chunkZNCSOBAXjs.WebsocketCloseCodes;
526
+ exports.asArrayWithLegacyMethods = _chunkZNCSOBAXjs.asArrayWithLegacyMethods;
527
+ exports.assertNever = _chunkZNCSOBAXjs.assertNever;
528
+ exports.b64decode = _chunkZNCSOBAXjs.b64decode;
529
+ exports.comparePosition = _chunkZNCSOBAXjs.comparePosition;
530
+ exports.deprecate = _chunkZNCSOBAXjs.deprecate;
531
+ exports.deprecateIf = _chunkZNCSOBAXjs.deprecateIf;
532
+ exports.errorIf = _chunkZNCSOBAXjs.errorIf;
533
+ exports.freeze = _chunkZNCSOBAXjs.freeze;
534
+ exports.isAppOnlyAuthToken = _chunkZNCSOBAXjs.isAppOnlyAuthToken;
535
+ exports.isAuthToken = _chunkZNCSOBAXjs.isAuthToken;
536
+ exports.isChildCrdt = _chunkZNCSOBAXjs.isChildCrdt;
537
+ exports.isJsonArray = _chunkZNCSOBAXjs.isJsonArray;
538
+ exports.isJsonObject = _chunkZNCSOBAXjs.isJsonObject;
539
+ exports.isJsonScalar = _chunkZNCSOBAXjs.isJsonScalar;
540
+ exports.isPlainObject = _chunkZNCSOBAXjs.isPlainObject;
541
+ exports.isRoomAuthToken = _chunkZNCSOBAXjs.isRoomAuthToken;
542
+ exports.isRootCrdt = _chunkZNCSOBAXjs.isRootCrdt;
543
+ exports.isScope = _chunkZNCSOBAXjs.isScope;
544
+ exports.legacy_patchImmutableObject = legacy_patchImmutableObject;
542
545
  exports.lsonToJson = lsonToJson;
543
- exports.makePosition = _chunkQLMVHHAZjs.makePosition;
544
- exports.nn = _chunkQLMVHHAZjs.nn;
545
- exports.patchImmutableObject = patchImmutableObject;
546
+ exports.makePosition = _chunkZNCSOBAXjs.makePosition;
547
+ exports.nn = _chunkZNCSOBAXjs.nn;
546
548
  exports.patchLiveObjectKey = patchLiveObjectKey;
547
- exports.throwUsageError = _chunkQLMVHHAZjs.throwUsageError;
548
- exports.tryParseJson = _chunkQLMVHHAZjs.tryParseJson;
549
+ exports.throwUsageError = _chunkZNCSOBAXjs.throwUsageError;
550
+ exports.tryParseJson = _chunkZNCSOBAXjs.tryParseJson;
package/internal.mjs CHANGED
@@ -1,364 +1,33 @@
1
- import {
2
- ClientMsgCode,
3
- CrdtType,
4
- LiveList,
5
- LiveMap,
6
- LiveObject,
7
- LiveRegister,
8
- OpCode,
9
- ServerMsgCode,
10
- WebsocketCloseCodes,
11
- assertNever,
12
- b64decode,
13
- comparePosition,
14
- deprecate,
15
- deprecateIf,
16
- errorIf,
17
- findNonSerializableValue,
18
- isAppOnlyAuthToken,
19
- isAuthToken,
20
- isChildCrdt,
21
- isJsonArray,
22
- isJsonObject,
23
- isJsonScalar,
24
- isLiveList,
25
- isLiveObject,
26
- isPlainObject,
27
- isRoomAuthToken,
28
- isRootCrdt,
29
- isScope,
30
- makePosition,
31
- nn,
32
- throwUsageError,
33
- tryParseJson
34
- } from "./chunk-ATVOU6HF.mjs";
1
+ import mod from "./internal.js";
35
2
 
36
- // src/immutable.ts
37
- function lsonObjectToJson(obj) {
38
- const result = {};
39
- for (const key in obj) {
40
- const val = obj[key];
41
- if (val !== void 0) {
42
- result[key] = lsonToJson(val);
43
- }
44
- }
45
- return result;
46
- }
47
- function liveObjectToJson(liveObject) {
48
- return lsonObjectToJson(liveObject.toObject());
49
- }
50
- function liveMapToJson(map) {
51
- const result = {};
52
- for (const [key, value] of map.entries()) {
53
- result[key] = lsonToJson(value);
54
- }
55
- return result;
56
- }
57
- function lsonListToJson(value) {
58
- return value.map(lsonToJson);
59
- }
60
- function liveListToJson(value) {
61
- return lsonListToJson(value.toArray());
62
- }
63
- function lsonToJson(value) {
64
- if (value instanceof LiveObject) {
65
- return liveObjectToJson(value);
66
- } else if (value instanceof LiveList) {
67
- return liveListToJson(value);
68
- } else if (value instanceof LiveMap) {
69
- return liveMapToJson(value);
70
- } else if (value instanceof LiveRegister) {
71
- return value.data;
72
- }
73
- if (Array.isArray(value)) {
74
- return lsonListToJson(value);
75
- } else if (isPlainObject(value)) {
76
- return lsonObjectToJson(value);
77
- }
78
- return value;
79
- }
80
- function deepLiveify(value) {
81
- if (Array.isArray(value)) {
82
- return new LiveList(value.map(deepLiveify));
83
- } else if (isPlainObject(value)) {
84
- const init = {};
85
- for (const key in value) {
86
- const val = value[key];
87
- if (val === void 0) {
88
- continue;
89
- }
90
- init[key] = deepLiveify(val);
91
- }
92
- return new LiveObject(init);
93
- } else {
94
- return value;
95
- }
96
- }
97
- function patchLiveList(liveList, prev, next) {
98
- let i = 0;
99
- let prevEnd = prev.length - 1;
100
- let nextEnd = next.length - 1;
101
- let prevNode = prev[0];
102
- let nextNode = next[0];
103
- outer: {
104
- while (prevNode === nextNode) {
105
- ++i;
106
- if (i > prevEnd || i > nextEnd) {
107
- break outer;
108
- }
109
- prevNode = prev[i];
110
- nextNode = next[i];
111
- }
112
- prevNode = prev[prevEnd];
113
- nextNode = next[nextEnd];
114
- while (prevNode === nextNode) {
115
- prevEnd--;
116
- nextEnd--;
117
- if (i > prevEnd || i > nextEnd) {
118
- break outer;
119
- }
120
- prevNode = prev[prevEnd];
121
- nextNode = next[nextEnd];
122
- }
123
- }
124
- if (i > prevEnd) {
125
- if (i <= nextEnd) {
126
- while (i <= nextEnd) {
127
- liveList.insert(deepLiveify(next[i]), i);
128
- i++;
129
- }
130
- }
131
- } else if (i > nextEnd) {
132
- let localI = i;
133
- while (localI <= prevEnd) {
134
- liveList.delete(i);
135
- localI++;
136
- }
137
- } else {
138
- while (i <= prevEnd && i <= nextEnd) {
139
- prevNode = prev[i];
140
- nextNode = next[i];
141
- const liveListNode = liveList.get(i);
142
- if (isLiveObject(liveListNode) && isPlainObject(prevNode) && isPlainObject(nextNode)) {
143
- patchLiveObject(liveListNode, prevNode, nextNode);
144
- } else {
145
- liveList.set(i, deepLiveify(nextNode));
146
- }
147
- i++;
148
- }
149
- while (i <= nextEnd) {
150
- liveList.insert(deepLiveify(next[i]), i);
151
- i++;
152
- }
153
- let localI = i;
154
- while (localI <= prevEnd) {
155
- liveList.delete(i);
156
- localI++;
157
- }
158
- }
159
- }
160
- function patchLiveObjectKey(liveObject, key, prev, next) {
161
- if (process.env.NODE_ENV !== "production") {
162
- const nonSerializableValue = findNonSerializableValue(next);
163
- if (nonSerializableValue) {
164
- console.error(
165
- `New state path: '${nonSerializableValue.path}' value: '${nonSerializableValue.value}' is not serializable.
166
- Only serializable value can be synced with Liveblocks.`
167
- );
168
- return;
169
- }
170
- }
171
- const value = liveObject.get(key);
172
- if (next === void 0) {
173
- liveObject.delete(key);
174
- } else if (value === void 0) {
175
- liveObject.set(key, deepLiveify(next));
176
- } else if (prev === next) {
177
- return;
178
- } else if (isLiveList(value) && Array.isArray(prev) && Array.isArray(next)) {
179
- patchLiveList(value, prev, next);
180
- } else if (isLiveObject(value) && isPlainObject(prev) && isPlainObject(next)) {
181
- patchLiveObject(value, prev, next);
182
- } else {
183
- liveObject.set(key, deepLiveify(next));
184
- }
185
- }
186
- function patchLiveObject(root, prev, next) {
187
- const updates = {};
188
- for (const key in next) {
189
- patchLiveObjectKey(root, key, prev[key], next[key]);
190
- }
191
- for (const key in prev) {
192
- if (next[key] === void 0) {
193
- root.delete(key);
194
- }
195
- }
196
- if (Object.keys(updates).length > 0) {
197
- root.update(updates);
198
- }
199
- }
200
- function getParentsPath(node) {
201
- const path = [];
202
- while (node.parent.type === "HasParent") {
203
- if (isLiveList(node.parent.node)) {
204
- path.push(node.parent.node._indexOfPosition(node.parent.key));
205
- } else {
206
- path.push(node.parent.key);
207
- }
208
- node = node.parent.node;
209
- }
210
- return path;
211
- }
212
- function patchImmutableObject(state, updates) {
213
- return updates.reduce(
214
- (state2, update) => patchImmutableObjectWithUpdate(state2, update),
215
- state
216
- );
217
- }
218
- function patchImmutableObjectWithUpdate(state, update) {
219
- const path = getParentsPath(update.node);
220
- return patchImmutableNode(state, path, update);
221
- }
222
- function patchImmutableNode(state, path, update) {
223
- const pathItem = path.pop();
224
- if (pathItem === void 0) {
225
- switch (update.type) {
226
- case "LiveObject": {
227
- if (state === null || typeof state !== "object" || Array.isArray(state)) {
228
- throw new Error(
229
- "Internal: received update on LiveObject but state was not an object"
230
- );
231
- }
232
- const newState = Object.assign({}, state);
233
- for (const key in update.updates) {
234
- if (update.updates[key]?.type === "update") {
235
- const val = update.node.get(key);
236
- if (val !== void 0) {
237
- newState[key] = lsonToJson(val);
238
- }
239
- } else if (update.updates[key]?.type === "delete") {
240
- delete newState[key];
241
- }
242
- }
243
- return newState;
244
- }
245
- case "LiveList": {
246
- if (!Array.isArray(state)) {
247
- throw new Error(
248
- "Internal: received update on LiveList but state was not an array"
249
- );
250
- }
251
- let newState = state.map((x) => x);
252
- for (const listUpdate of update.updates) {
253
- if (listUpdate.type === "set") {
254
- newState = newState.map(
255
- (item, index) => index === listUpdate.index ? lsonToJson(listUpdate.item) : item
256
- );
257
- } else if (listUpdate.type === "insert") {
258
- if (listUpdate.index === newState.length) {
259
- newState.push(lsonToJson(listUpdate.item));
260
- } else {
261
- newState = [
262
- ...newState.slice(0, listUpdate.index),
263
- lsonToJson(listUpdate.item),
264
- ...newState.slice(listUpdate.index)
265
- ];
266
- }
267
- } else if (listUpdate.type === "delete") {
268
- newState.splice(listUpdate.index, 1);
269
- } else if (listUpdate.type === "move") {
270
- if (listUpdate.previousIndex > listUpdate.index) {
271
- newState = [
272
- ...newState.slice(0, listUpdate.index),
273
- lsonToJson(listUpdate.item),
274
- ...newState.slice(listUpdate.index, listUpdate.previousIndex),
275
- ...newState.slice(listUpdate.previousIndex + 1)
276
- ];
277
- } else {
278
- newState = [
279
- ...newState.slice(0, listUpdate.previousIndex),
280
- ...newState.slice(
281
- listUpdate.previousIndex + 1,
282
- listUpdate.index + 1
283
- ),
284
- lsonToJson(listUpdate.item),
285
- ...newState.slice(listUpdate.index + 1)
286
- ];
287
- }
288
- }
289
- }
290
- return newState;
291
- }
292
- case "LiveMap": {
293
- if (state === null || typeof state !== "object" || Array.isArray(state)) {
294
- throw new Error(
295
- "Internal: received update on LiveMap but state was not an object"
296
- );
297
- }
298
- const newState = Object.assign({}, state);
299
- for (const key in update.updates) {
300
- if (update.updates[key]?.type === "update") {
301
- const value = update.node.get(key);
302
- if (value !== void 0) {
303
- newState[key] = lsonToJson(value);
304
- }
305
- } else if (update.updates[key]?.type === "delete") {
306
- delete newState[key];
307
- }
308
- }
309
- return newState;
310
- }
311
- }
312
- }
313
- if (Array.isArray(state)) {
314
- const newArray = [...state];
315
- newArray[pathItem] = patchImmutableNode(
316
- state[pathItem],
317
- path,
318
- update
319
- );
320
- return newArray;
321
- } else if (state !== null && typeof state === "object") {
322
- const node = state[pathItem];
323
- if (node === void 0) {
324
- return state;
325
- } else {
326
- return {
327
- ...state,
328
- [pathItem]: patchImmutableNode(node, path, update)
329
- };
330
- }
331
- } else {
332
- return state;
333
- }
334
- }
335
- export {
336
- ClientMsgCode,
337
- CrdtType,
338
- OpCode,
339
- ServerMsgCode,
340
- WebsocketCloseCodes,
341
- assertNever,
342
- b64decode,
343
- comparePosition,
344
- deprecate,
345
- deprecateIf,
346
- errorIf,
347
- isAppOnlyAuthToken,
348
- isAuthToken,
349
- isChildCrdt,
350
- isJsonArray,
351
- isJsonObject,
352
- isJsonScalar,
353
- isPlainObject,
354
- isRoomAuthToken,
355
- isRootCrdt,
356
- isScope,
357
- lsonToJson,
358
- makePosition,
359
- nn,
360
- patchImmutableObject,
361
- patchLiveObjectKey,
362
- throwUsageError,
363
- tryParseJson
364
- };
3
+ export default mod;
4
+ export const ClientMsgCode = mod.ClientMsgCode;
5
+ export const CrdtType = mod.CrdtType;
6
+ export const OpCode = mod.OpCode;
7
+ export const ServerMsgCode = mod.ServerMsgCode;
8
+ export const WebsocketCloseCodes = mod.WebsocketCloseCodes;
9
+ export const asArrayWithLegacyMethods = mod.asArrayWithLegacyMethods;
10
+ export const assertNever = mod.assertNever;
11
+ export const b64decode = mod.b64decode;
12
+ export const comparePosition = mod.comparePosition;
13
+ export const deprecate = mod.deprecate;
14
+ export const deprecateIf = mod.deprecateIf;
15
+ export const errorIf = mod.errorIf;
16
+ export const freeze = mod.freeze;
17
+ export const isAppOnlyAuthToken = mod.isAppOnlyAuthToken;
18
+ export const isAuthToken = mod.isAuthToken;
19
+ export const isChildCrdt = mod.isChildCrdt;
20
+ export const isJsonArray = mod.isJsonArray;
21
+ export const isJsonObject = mod.isJsonObject;
22
+ export const isJsonScalar = mod.isJsonScalar;
23
+ export const isPlainObject = mod.isPlainObject;
24
+ export const isRoomAuthToken = mod.isRoomAuthToken;
25
+ export const isRootCrdt = mod.isRootCrdt;
26
+ export const isScope = mod.isScope;
27
+ export const legacy_patchImmutableObject = mod.legacy_patchImmutableObject;
28
+ export const lsonToJson = mod.lsonToJson;
29
+ export const makePosition = mod.makePosition;
30
+ export const nn = mod.nn;
31
+ export const patchLiveObjectKey = mod.patchLiveObjectKey;
32
+ export const throwUsageError = mod.throwUsageError;
33
+ export const tryParseJson = mod.tryParseJson;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.17.11-debug2",
3
+ "version": "0.18.0-beta1",
4
4
  "description": "A client that lets you interact with Liveblocks servers.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",