@liveblocks/client 0.17.11-debug2 → 0.17.11
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/index.js +1 -1
- package/index.mjs +6 -1363
- package/internal.mjs +30 -363
- package/package.json +1 -1
- package/chunk-ATVOU6HF.mjs +0 -2314
package/internal.mjs
CHANGED
|
@@ -1,364 +1,31 @@
|
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 assertNever = mod.assertNever;
|
|
10
|
+
export const b64decode = mod.b64decode;
|
|
11
|
+
export const comparePosition = mod.comparePosition;
|
|
12
|
+
export const deprecate = mod.deprecate;
|
|
13
|
+
export const deprecateIf = mod.deprecateIf;
|
|
14
|
+
export const errorIf = mod.errorIf;
|
|
15
|
+
export const isAppOnlyAuthToken = mod.isAppOnlyAuthToken;
|
|
16
|
+
export const isAuthToken = mod.isAuthToken;
|
|
17
|
+
export const isChildCrdt = mod.isChildCrdt;
|
|
18
|
+
export const isJsonArray = mod.isJsonArray;
|
|
19
|
+
export const isJsonObject = mod.isJsonObject;
|
|
20
|
+
export const isJsonScalar = mod.isJsonScalar;
|
|
21
|
+
export const isPlainObject = mod.isPlainObject;
|
|
22
|
+
export const isRoomAuthToken = mod.isRoomAuthToken;
|
|
23
|
+
export const isRootCrdt = mod.isRootCrdt;
|
|
24
|
+
export const isScope = mod.isScope;
|
|
25
|
+
export const lsonToJson = mod.lsonToJson;
|
|
26
|
+
export const makePosition = mod.makePosition;
|
|
27
|
+
export const nn = mod.nn;
|
|
28
|
+
export const patchImmutableObject = mod.patchImmutableObject;
|
|
29
|
+
export const patchLiveObjectKey = mod.patchLiveObjectKey;
|
|
30
|
+
export const throwUsageError = mod.throwUsageError;
|
|
31
|
+
export const tryParseJson = mod.tryParseJson;
|