@liveblocks/client 0.17.7 → 0.17.10-debug

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.mjs CHANGED
@@ -1,282 +1,30 @@
1
- import {
2
- L as LiveObject,
3
- q as LiveList,
4
- s as LiveMap,
5
- u as LiveRegister,
6
- b as isPlainObject,
7
- v as findNonSerializableValue,
8
- f as isLiveList,
9
- w as isLiveObject,
10
- } from "./shared.mjs";
11
1
  export {
12
- C as ClientMsgCode,
13
- I as CrdtType,
14
- e as OpCode,
15
- S as ServerMsgCode,
16
- W as WebsocketCloseCodes,
17
- x as assertNever,
18
- M as b64decode,
19
- G as comparePosition,
20
- D as deprecate,
21
- E as deprecateIf,
22
- o as errorIf,
23
- y as isAppOnlyAuthToken,
24
- z as isAuthToken,
25
- K as isChildCrdt,
26
- h as isJsonArray,
27
- l as isJsonObject,
28
- J as isJsonScalar,
29
- b as isPlainObject,
30
- A as isRoomAuthToken,
31
- k as isRootCrdt,
32
- B as isScope,
33
- H as makePosition,
34
- n as nn,
35
- F as throwUsageError,
36
- t as tryParseJson,
37
- } from "./shared.mjs";
38
- function lsonObjectToJson(obj) {
39
- const result = {};
40
- for (const key in obj) {
41
- const val = obj[key];
42
- void 0 !== val && (result[key] = lsonToJson(val));
43
- }
44
- return result;
45
- }
46
- function lsonListToJson(value) {
47
- return value.map(lsonToJson);
48
- }
49
- function lsonToJson(value) {
50
- return value instanceof LiveObject
51
- ? lsonObjectToJson(value.toObject())
52
- : value instanceof LiveList
53
- ? (function (value) {
54
- return lsonListToJson(value.toArray());
55
- })(value)
56
- : value instanceof LiveMap
57
- ? (function (map) {
58
- const result = {};
59
- for (const [key, value] of map.entries())
60
- result[key] = lsonToJson(value);
61
- return result;
62
- })(value)
63
- : value instanceof LiveRegister
64
- ? value.data
65
- : Array.isArray(value)
66
- ? lsonListToJson(value)
67
- : isPlainObject(value)
68
- ? lsonObjectToJson(value)
69
- : value;
70
- }
71
- function deepLiveify(value) {
72
- if (Array.isArray(value)) return new LiveList(value.map(deepLiveify));
73
- if (isPlainObject(value)) {
74
- const init = {};
75
- for (const key in value) {
76
- const val = value[key];
77
- void 0 !== val && (init[key] = deepLiveify(val));
78
- }
79
- return new LiveObject(init);
80
- }
81
- return value;
82
- }
83
- function patchLiveObjectKey(liveObject, key, prev, next) {
84
- if ("production" !== process.env.NODE_ENV) {
85
- const nonSerializableValue = findNonSerializableValue(next);
86
- if (nonSerializableValue)
87
- return void console.error(
88
- `New state path: '${nonSerializableValue.path}' value: '${nonSerializableValue.value}' is not serializable.\nOnly serializable value can be synced with Liveblocks.`
89
- );
90
- }
91
- const value = liveObject.get(key);
92
- if (void 0 === next) liveObject.delete(key);
93
- else if (void 0 === value) liveObject.set(key, deepLiveify(next));
94
- else {
95
- if (prev === next) return;
96
- isLiveList(value) && Array.isArray(prev) && Array.isArray(next)
97
- ? (function (liveList, prev, next) {
98
- let i = 0,
99
- prevEnd = prev.length - 1,
100
- nextEnd = next.length - 1,
101
- prevNode = prev[0],
102
- nextNode = next[0];
103
- outer: {
104
- for (; prevNode === nextNode; ) {
105
- if ((++i, i > prevEnd || i > nextEnd)) break outer;
106
- (prevNode = prev[i]), (nextNode = next[i]);
107
- }
108
- for (
109
- prevNode = prev[prevEnd], nextNode = next[nextEnd];
110
- prevNode === nextNode;
111
-
112
- ) {
113
- if ((prevEnd--, nextEnd--, i > prevEnd || i > nextEnd))
114
- break outer;
115
- (prevNode = prev[prevEnd]), (nextNode = next[nextEnd]);
116
- }
117
- }
118
- if (i > prevEnd) {
119
- if (i <= nextEnd)
120
- for (; i <= nextEnd; )
121
- liveList.insert(deepLiveify(next[i]), i), i++;
122
- } else if (i > nextEnd) {
123
- let localI = i;
124
- for (; localI <= prevEnd; ) liveList.delete(i), localI++;
125
- } else {
126
- for (; i <= prevEnd && i <= nextEnd; ) {
127
- (prevNode = prev[i]), (nextNode = next[i]);
128
- const liveListNode = liveList.get(i);
129
- isLiveObject(liveListNode) &&
130
- isPlainObject(prevNode) &&
131
- isPlainObject(nextNode)
132
- ? patchLiveObject(liveListNode, prevNode, nextNode)
133
- : liveList.set(i, deepLiveify(nextNode)),
134
- i++;
135
- }
136
- for (; i <= nextEnd; )
137
- liveList.insert(deepLiveify(next[i]), i), i++;
138
- let localI = i;
139
- for (; localI <= prevEnd; ) liveList.delete(i), localI++;
140
- }
141
- })(value, prev, next)
142
- : isLiveObject(value) && isPlainObject(prev) && isPlainObject(next)
143
- ? patchLiveObject(value, prev, next)
144
- : liveObject.set(key, deepLiveify(next));
145
- }
146
- }
147
- function patchLiveObject(root, prev, next) {
148
- const updates = {};
149
- for (const key in next) patchLiveObjectKey(root, key, prev[key], next[key]);
150
- for (const key in prev) void 0 === next[key] && root.delete(key);
151
- Object.keys(updates).length > 0 && root.update(updates);
152
- }
153
- function patchImmutableObject(state, updates) {
154
- return updates.reduce(
155
- (state, update) =>
156
- (function (state, update) {
157
- const path = (function (node) {
158
- const path = [];
159
- for (; "HasParent" === node.parent.type; )
160
- isLiveList(node.parent.node)
161
- ? path.push(node.parent.node._indexOfPosition(node.parent.key))
162
- : path.push(node.parent.key),
163
- (node = node.parent.node);
164
- return path;
165
- })(update.node);
166
- return patchImmutableNode(state, path, update);
167
- })(state, update),
168
- state
169
- );
170
- }
171
- function patchImmutableNode(state, path, update) {
172
- var _a, _b, _c, _d;
173
- const pathItem = path.pop();
174
- if (void 0 === pathItem)
175
- switch (update.type) {
176
- case "LiveObject": {
177
- if (null === state || "object" != typeof state || Array.isArray(state))
178
- throw new Error(
179
- "Internal: received update on LiveObject but state was not an object"
180
- );
181
- const newState = Object.assign({}, state);
182
- for (const key in update.updates)
183
- if (
184
- "update" ===
185
- (null === (_a = update.updates[key]) || void 0 === _a
186
- ? void 0
187
- : _a.type)
188
- ) {
189
- const val = update.node.get(key);
190
- void 0 !== val && (newState[key] = lsonToJson(val));
191
- } else
192
- "delete" ===
193
- (null === (_b = update.updates[key]) || void 0 === _b
194
- ? void 0
195
- : _b.type) && delete newState[key];
196
- return newState;
197
- }
198
- case "LiveList": {
199
- if (!Array.isArray(state))
200
- throw new Error(
201
- "Internal: received update on LiveList but state was not an array"
202
- );
203
- let newState = state.map((x) => x);
204
- for (const listUpdate of update.updates)
205
- "set" === listUpdate.type
206
- ? (newState = newState.map((item, index) =>
207
- index === listUpdate.index ? lsonToJson(listUpdate.item) : item
208
- ))
209
- : "insert" === listUpdate.type
210
- ? listUpdate.index === newState.length
211
- ? newState.push(lsonToJson(listUpdate.item))
212
- : (newState = [
213
- ...newState.slice(0, listUpdate.index),
214
- lsonToJson(listUpdate.item),
215
- ...newState.slice(listUpdate.index),
216
- ])
217
- : "delete" === listUpdate.type
218
- ? newState.splice(listUpdate.index, 1)
219
- : "move" === listUpdate.type &&
220
- (newState =
221
- listUpdate.previousIndex > listUpdate.index
222
- ? [
223
- ...newState.slice(0, listUpdate.index),
224
- lsonToJson(listUpdate.item),
225
- ...newState.slice(
226
- listUpdate.index,
227
- listUpdate.previousIndex
228
- ),
229
- ...newState.slice(listUpdate.previousIndex + 1),
230
- ]
231
- : [
232
- ...newState.slice(0, listUpdate.previousIndex),
233
- ...newState.slice(
234
- listUpdate.previousIndex + 1,
235
- listUpdate.index + 1
236
- ),
237
- lsonToJson(listUpdate.item),
238
- ...newState.slice(listUpdate.index + 1),
239
- ]);
240
- return newState;
241
- }
242
- case "LiveMap": {
243
- if (null === state || "object" != typeof state || Array.isArray(state))
244
- throw new Error(
245
- "Internal: received update on LiveMap but state was not an object"
246
- );
247
- const newState = Object.assign({}, state);
248
- for (const key in update.updates)
249
- if (
250
- "update" ===
251
- (null === (_c = update.updates[key]) || void 0 === _c
252
- ? void 0
253
- : _c.type)
254
- ) {
255
- const value = update.node.get(key);
256
- void 0 !== value && (newState[key] = lsonToJson(value));
257
- } else
258
- "delete" ===
259
- (null === (_d = update.updates[key]) || void 0 === _d
260
- ? void 0
261
- : _d.type) && delete newState[key];
262
- return newState;
263
- }
264
- }
265
- if (Array.isArray(state)) {
266
- const newArray = [...state];
267
- return (
268
- (newArray[pathItem] = patchImmutableNode(state[pathItem], path, update)),
269
- newArray
270
- );
271
- }
272
- if (null !== state && "object" == typeof state) {
273
- const node = state[pathItem];
274
- return void 0 === node
275
- ? state
276
- : Object.assign(Object.assign({}, state), {
277
- [pathItem]: patchImmutableNode(node, path, update),
278
- });
279
- }
280
- return state;
281
- }
282
- export { lsonToJson, patchImmutableObject, patchLiveObjectKey };
2
+ ClientMsgCode,
3
+ CrdtType,
4
+ OpCode,
5
+ ServerMsgCode,
6
+ WebsocketCloseCodes,
7
+ assertNever,
8
+ b64decode,
9
+ comparePosition,
10
+ deprecate,
11
+ deprecateIf,
12
+ errorIf,
13
+ isAppOnlyAuthToken,
14
+ isAuthToken,
15
+ isChildCrdt,
16
+ isJsonArray,
17
+ isJsonObject,
18
+ isJsonScalar,
19
+ isPlainObject,
20
+ isRoomAuthToken,
21
+ isRootCrdt,
22
+ isScope,
23
+ lsonToJson,
24
+ makePosition,
25
+ nn,
26
+ patchImmutableObject,
27
+ patchLiveObjectKey,
28
+ throwUsageError,
29
+ tryParseJson,
30
+ } from "./internal.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.17.7",
3
+ "version": "0.17.10-debug",
4
4
  "description": "A client that lets you interact with Liveblocks servers.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",