@liveblocks/client 0.16.2 → 0.16.4-beta2
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.d.ts +3 -727
- package/index.js +100 -2523
- package/index.mjs +1641 -0
- package/internal.d.ts +15 -19
- package/internal.js +32 -190
- package/internal.mjs +1 -0
- package/package.json +7 -18
- package/shared.d.ts +753 -0
- package/shared.js +2488 -0
- package/shared.mjs +1947 -0
- package/esm/index.js +0 -3060
- package/esm/index.mjs +0 -3060
- package/esm/internal.js +0 -150
- package/esm/internal.mjs +0 -150
package/index.js
CHANGED
|
@@ -2,2437 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < props.length; i++) {
|
|
7
|
-
var descriptor = props[i];
|
|
8
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
9
|
-
descriptor.configurable = true;
|
|
10
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
11
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
16
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
-
return Constructor;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _extends() {
|
|
22
|
-
_extends = Object.assign || function (target) {
|
|
23
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
24
|
-
var source = arguments[i];
|
|
25
|
-
|
|
26
|
-
for (var key in source) {
|
|
27
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
28
|
-
target[key] = source[key];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return _extends.apply(this, arguments);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function _inheritsLoose(subClass, superClass) {
|
|
40
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
41
|
-
subClass.prototype.constructor = subClass;
|
|
42
|
-
|
|
43
|
-
_setPrototypeOf(subClass, superClass);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function _getPrototypeOf(o) {
|
|
47
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
48
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
49
|
-
};
|
|
50
|
-
return _getPrototypeOf(o);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function _setPrototypeOf(o, p) {
|
|
54
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
55
|
-
o.__proto__ = p;
|
|
56
|
-
return o;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return _setPrototypeOf(o, p);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function _isNativeReflectConstruct() {
|
|
63
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
64
|
-
if (Reflect.construct.sham) return false;
|
|
65
|
-
if (typeof Proxy === "function") return true;
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
|
69
|
-
return true;
|
|
70
|
-
} catch (e) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function _construct(Parent, args, Class) {
|
|
76
|
-
if (_isNativeReflectConstruct()) {
|
|
77
|
-
_construct = Reflect.construct;
|
|
78
|
-
} else {
|
|
79
|
-
_construct = function _construct(Parent, args, Class) {
|
|
80
|
-
var a = [null];
|
|
81
|
-
a.push.apply(a, args);
|
|
82
|
-
var Constructor = Function.bind.apply(Parent, a);
|
|
83
|
-
var instance = new Constructor();
|
|
84
|
-
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
85
|
-
return instance;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return _construct.apply(null, arguments);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function _isNativeFunction(fn) {
|
|
93
|
-
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function _wrapNativeSuper(Class) {
|
|
97
|
-
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
98
|
-
|
|
99
|
-
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
100
|
-
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
101
|
-
|
|
102
|
-
if (typeof Class !== "function") {
|
|
103
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (typeof _cache !== "undefined") {
|
|
107
|
-
if (_cache.has(Class)) return _cache.get(Class);
|
|
108
|
-
|
|
109
|
-
_cache.set(Class, Wrapper);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function Wrapper() {
|
|
113
|
-
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
Wrapper.prototype = Object.create(Class.prototype, {
|
|
117
|
-
constructor: {
|
|
118
|
-
value: Wrapper,
|
|
119
|
-
enumerable: false,
|
|
120
|
-
writable: true,
|
|
121
|
-
configurable: true
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
return _setPrototypeOf(Wrapper, Class);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return _wrapNativeSuper(Class);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
131
|
-
if (source == null) return {};
|
|
132
|
-
var target = {};
|
|
133
|
-
var sourceKeys = Object.keys(source);
|
|
134
|
-
var key, i;
|
|
135
|
-
|
|
136
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
137
|
-
key = sourceKeys[i];
|
|
138
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
139
|
-
target[key] = source[key];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return target;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function _assertThisInitialized(self) {
|
|
146
|
-
if (self === void 0) {
|
|
147
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return self;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
154
|
-
if (!o) return;
|
|
155
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
156
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
157
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
158
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
159
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function _arrayLikeToArray(arr, len) {
|
|
163
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
164
|
-
|
|
165
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
166
|
-
|
|
167
|
-
return arr2;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
171
|
-
var it;
|
|
172
|
-
|
|
173
|
-
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
174
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
175
|
-
if (it) o = it;
|
|
176
|
-
var i = 0;
|
|
177
|
-
return function () {
|
|
178
|
-
if (i >= o.length) return {
|
|
179
|
-
done: true
|
|
180
|
-
};
|
|
181
|
-
return {
|
|
182
|
-
done: false,
|
|
183
|
-
value: o[i++]
|
|
184
|
-
};
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
it = o[Symbol.iterator]();
|
|
192
|
-
return it.next.bind(it);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
var ServerMessageType;
|
|
196
|
-
|
|
197
|
-
(function (ServerMessageType) {
|
|
198
|
-
ServerMessageType[ServerMessageType["UpdatePresence"] = 100] = "UpdatePresence";
|
|
199
|
-
ServerMessageType[ServerMessageType["UserJoined"] = 101] = "UserJoined";
|
|
200
|
-
ServerMessageType[ServerMessageType["UserLeft"] = 102] = "UserLeft";
|
|
201
|
-
ServerMessageType[ServerMessageType["Event"] = 103] = "Event";
|
|
202
|
-
ServerMessageType[ServerMessageType["RoomState"] = 104] = "RoomState";
|
|
203
|
-
ServerMessageType[ServerMessageType["InitialStorageState"] = 200] = "InitialStorageState";
|
|
204
|
-
ServerMessageType[ServerMessageType["UpdateStorage"] = 201] = "UpdateStorage";
|
|
205
|
-
})(ServerMessageType || (ServerMessageType = {}));
|
|
206
|
-
|
|
207
|
-
var ClientMessageType;
|
|
208
|
-
|
|
209
|
-
(function (ClientMessageType) {
|
|
210
|
-
ClientMessageType[ClientMessageType["UpdatePresence"] = 100] = "UpdatePresence";
|
|
211
|
-
ClientMessageType[ClientMessageType["ClientEvent"] = 103] = "ClientEvent";
|
|
212
|
-
ClientMessageType[ClientMessageType["FetchStorage"] = 200] = "FetchStorage";
|
|
213
|
-
ClientMessageType[ClientMessageType["UpdateStorage"] = 201] = "UpdateStorage";
|
|
214
|
-
})(ClientMessageType || (ClientMessageType = {}));
|
|
215
|
-
|
|
216
|
-
var CrdtType;
|
|
217
|
-
|
|
218
|
-
(function (CrdtType) {
|
|
219
|
-
CrdtType[CrdtType["Object"] = 0] = "Object";
|
|
220
|
-
CrdtType[CrdtType["List"] = 1] = "List";
|
|
221
|
-
CrdtType[CrdtType["Map"] = 2] = "Map";
|
|
222
|
-
CrdtType[CrdtType["Register"] = 3] = "Register";
|
|
223
|
-
})(CrdtType || (CrdtType = {}));
|
|
224
|
-
|
|
225
|
-
var OpType;
|
|
226
|
-
|
|
227
|
-
(function (OpType) {
|
|
228
|
-
OpType[OpType["Init"] = 0] = "Init";
|
|
229
|
-
OpType[OpType["SetParentKey"] = 1] = "SetParentKey";
|
|
230
|
-
OpType[OpType["CreateList"] = 2] = "CreateList";
|
|
231
|
-
OpType[OpType["UpdateObject"] = 3] = "UpdateObject";
|
|
232
|
-
OpType[OpType["CreateObject"] = 4] = "CreateObject";
|
|
233
|
-
OpType[OpType["DeleteCrdt"] = 5] = "DeleteCrdt";
|
|
234
|
-
OpType[OpType["DeleteObjectKey"] = 6] = "DeleteObjectKey";
|
|
235
|
-
OpType[OpType["CreateMap"] = 7] = "CreateMap";
|
|
236
|
-
OpType[OpType["CreateRegister"] = 8] = "CreateRegister";
|
|
237
|
-
})(OpType || (OpType = {}));
|
|
238
|
-
|
|
239
|
-
var WebsocketCloseCodes;
|
|
240
|
-
|
|
241
|
-
(function (WebsocketCloseCodes) {
|
|
242
|
-
WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
|
|
243
|
-
WebsocketCloseCodes[WebsocketCloseCodes["INVALID_MESSAGE_FORMAT"] = 4000] = "INVALID_MESSAGE_FORMAT";
|
|
244
|
-
WebsocketCloseCodes[WebsocketCloseCodes["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
|
|
245
|
-
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
|
|
246
|
-
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
|
|
247
|
-
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
|
|
248
|
-
WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
|
|
249
|
-
WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
|
|
250
|
-
})(WebsocketCloseCodes || (WebsocketCloseCodes = {}));
|
|
251
|
-
|
|
252
|
-
var AbstractCrdt = function () {
|
|
253
|
-
function AbstractCrdt() {}
|
|
254
|
-
|
|
255
|
-
var _proto = AbstractCrdt.prototype;
|
|
256
|
-
|
|
257
|
-
_proto._apply = function _apply(op, _isLocal) {
|
|
258
|
-
switch (op.type) {
|
|
259
|
-
case OpType.DeleteCrdt:
|
|
260
|
-
{
|
|
261
|
-
if (this._parent != null && this._parentKey != null) {
|
|
262
|
-
return this._parent._detachChild(this);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return {
|
|
266
|
-
modified: false
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return {
|
|
272
|
-
modified: false
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
_proto._setParentLink = function _setParentLink(parent, key) {
|
|
277
|
-
if (this.__parent != null && this.__parent !== parent) {
|
|
278
|
-
throw new Error("Cannot attach parent if it already exist");
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
this.__parentKey = key;
|
|
282
|
-
this.__parent = parent;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
_proto._attach = function _attach(id, doc) {
|
|
286
|
-
if (this.__id || this.__doc) {
|
|
287
|
-
throw new Error("Cannot attach if CRDT is already attached");
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
doc.addItem(id, this);
|
|
291
|
-
this.__id = id;
|
|
292
|
-
this.__doc = doc;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
_proto._detach = function _detach() {
|
|
296
|
-
if (this.__doc && this.__id) {
|
|
297
|
-
this.__doc.deleteItem(this.__id);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
this.__parent = undefined;
|
|
301
|
-
this.__doc = undefined;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
_createClass(AbstractCrdt, [{
|
|
305
|
-
key: "_doc",
|
|
306
|
-
get: function get() {
|
|
307
|
-
return this.__doc;
|
|
308
|
-
}
|
|
309
|
-
}, {
|
|
310
|
-
key: "roomId",
|
|
311
|
-
get: function get() {
|
|
312
|
-
return this.__doc ? this.__doc.roomId : null;
|
|
313
|
-
}
|
|
314
|
-
}, {
|
|
315
|
-
key: "_id",
|
|
316
|
-
get: function get() {
|
|
317
|
-
return this.__id;
|
|
318
|
-
}
|
|
319
|
-
}, {
|
|
320
|
-
key: "_parent",
|
|
321
|
-
get: function get() {
|
|
322
|
-
return this.__parent;
|
|
323
|
-
}
|
|
324
|
-
}, {
|
|
325
|
-
key: "_parentKey",
|
|
326
|
-
get: function get() {
|
|
327
|
-
return this.__parentKey;
|
|
328
|
-
}
|
|
329
|
-
}]);
|
|
330
|
-
|
|
331
|
-
return AbstractCrdt;
|
|
332
|
-
}();
|
|
333
|
-
|
|
334
|
-
var min = 32;
|
|
335
|
-
var max = 126;
|
|
336
|
-
function makePosition(before, after) {
|
|
337
|
-
if (before == null && after == null) {
|
|
338
|
-
return pos([min + 1]);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (before != null && after == null) {
|
|
342
|
-
return getNextPosition(before);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
if (before == null && after != null) {
|
|
346
|
-
return getPreviousPosition(after);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return pos(makePositionFromCodes(posCodes(before), posCodes(after)));
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function getPreviousPosition(after) {
|
|
353
|
-
var result = [];
|
|
354
|
-
var afterCodes = posCodes(after);
|
|
355
|
-
|
|
356
|
-
for (var i = 0; i < afterCodes.length; i++) {
|
|
357
|
-
var code = afterCodes[i];
|
|
358
|
-
|
|
359
|
-
if (code <= min + 1) {
|
|
360
|
-
result.push(min);
|
|
361
|
-
|
|
362
|
-
if (afterCodes.length - 1 === i) {
|
|
363
|
-
result.push(max);
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
} else {
|
|
367
|
-
result.push(code - 1);
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
return pos(result);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function getNextPosition(before) {
|
|
376
|
-
var result = [];
|
|
377
|
-
var beforeCodes = posCodes(before);
|
|
378
|
-
|
|
379
|
-
for (var i = 0; i < beforeCodes.length; i++) {
|
|
380
|
-
var code = beforeCodes[i];
|
|
381
|
-
|
|
382
|
-
if (code === max) {
|
|
383
|
-
result.push(code);
|
|
384
|
-
|
|
385
|
-
if (beforeCodes.length - 1 === i) {
|
|
386
|
-
result.push(min + 1);
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
} else {
|
|
390
|
-
result.push(code + 1);
|
|
391
|
-
break;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return pos(result);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function makePositionFromCodes(before, after) {
|
|
399
|
-
var index = 0;
|
|
400
|
-
var result = [];
|
|
401
|
-
|
|
402
|
-
while (true) {
|
|
403
|
-
var beforeDigit = before[index] || min;
|
|
404
|
-
var afterDigit = after[index] || max;
|
|
405
|
-
|
|
406
|
-
if (beforeDigit > afterDigit) {
|
|
407
|
-
throw new Error("Impossible to generate position between " + before + " and " + after);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (beforeDigit === afterDigit) {
|
|
411
|
-
result.push(beforeDigit);
|
|
412
|
-
index++;
|
|
413
|
-
continue;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (afterDigit - beforeDigit === 1) {
|
|
417
|
-
result.push(beforeDigit);
|
|
418
|
-
result.push.apply(result, makePositionFromCodes(before.slice(index + 1), []));
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
var mid = afterDigit + beforeDigit >> 1;
|
|
423
|
-
result.push(mid);
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return result;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
function posCodes(str) {
|
|
431
|
-
var codes = [];
|
|
432
|
-
|
|
433
|
-
for (var i = 0; i < str.length; i++) {
|
|
434
|
-
codes.push(str.charCodeAt(i));
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
return codes;
|
|
438
|
-
}
|
|
439
|
-
function pos(codes) {
|
|
440
|
-
return String.fromCharCode.apply(String, codes);
|
|
441
|
-
}
|
|
442
|
-
function compare(posA, posB) {
|
|
443
|
-
var aCodes = posCodes(posA);
|
|
444
|
-
var bCodes = posCodes(posB);
|
|
445
|
-
var maxLength = Math.max(aCodes.length, bCodes.length);
|
|
446
|
-
|
|
447
|
-
for (var i = 0; i < maxLength; i++) {
|
|
448
|
-
var a = aCodes[i] == null ? min : aCodes[i];
|
|
449
|
-
var b = bCodes[i] == null ? min : bCodes[i];
|
|
450
|
-
|
|
451
|
-
if (a === b) {
|
|
452
|
-
continue;
|
|
453
|
-
} else {
|
|
454
|
-
return a - b;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
throw new Error("Impossible to compare similar position \"" + posA + "\" and \"" + posB + "\"");
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
var LiveRegister = function (_AbstractCrdt) {
|
|
462
|
-
_inheritsLoose(LiveRegister, _AbstractCrdt);
|
|
463
|
-
|
|
464
|
-
function LiveRegister(data) {
|
|
465
|
-
var _this;
|
|
466
|
-
|
|
467
|
-
_this = _AbstractCrdt.call(this) || this;
|
|
468
|
-
_this._data = data;
|
|
469
|
-
return _this;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
LiveRegister._deserialize = function _deserialize(_ref, _parentToChildren, doc) {
|
|
473
|
-
var id = _ref[0],
|
|
474
|
-
item = _ref[1];
|
|
475
|
-
|
|
476
|
-
if (item.type !== CrdtType.Register) {
|
|
477
|
-
throw new Error("Tried to deserialize a map but item type is \"" + item.type + "\"");
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
var register = new LiveRegister(item.data);
|
|
481
|
-
|
|
482
|
-
register._attach(id, doc);
|
|
483
|
-
|
|
484
|
-
return register;
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
var _proto = LiveRegister.prototype;
|
|
488
|
-
|
|
489
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
490
|
-
if (this._id == null || parentId == null || parentKey == null) {
|
|
491
|
-
throw new Error("Cannot serialize register if parentId or parentKey is undefined");
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
return [{
|
|
495
|
-
type: OpType.CreateRegister,
|
|
496
|
-
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
497
|
-
id: this._id,
|
|
498
|
-
intent: intent,
|
|
499
|
-
parentId: parentId,
|
|
500
|
-
parentKey: parentKey,
|
|
501
|
-
data: this.data
|
|
502
|
-
}];
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
506
|
-
var _this$_parent;
|
|
507
|
-
|
|
508
|
-
return {
|
|
509
|
-
type: CrdtType.Register,
|
|
510
|
-
parentId: (_this$_parent = this._parent) == null ? void 0 : _this$_parent._id,
|
|
511
|
-
parentKey: this._parentKey,
|
|
512
|
-
data: this.data
|
|
513
|
-
};
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
_proto._attachChild = function _attachChild(_op, _isLocal) {
|
|
517
|
-
throw new Error("Method not implemented.");
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
_proto._detachChild = function _detachChild(_crdt) {
|
|
521
|
-
throw new Error("Method not implemented.");
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
_proto._apply = function _apply(op, isLocal) {
|
|
525
|
-
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
_createClass(LiveRegister, [{
|
|
529
|
-
key: "data",
|
|
530
|
-
get: function get() {
|
|
531
|
-
return this._data;
|
|
532
|
-
}
|
|
533
|
-
}]);
|
|
534
|
-
|
|
535
|
-
return LiveRegister;
|
|
536
|
-
}(AbstractCrdt);
|
|
537
|
-
|
|
538
|
-
var LiveList = function (_AbstractCrdt) {
|
|
539
|
-
_inheritsLoose(LiveList, _AbstractCrdt);
|
|
540
|
-
|
|
541
|
-
function LiveList(items) {
|
|
542
|
-
var _this;
|
|
543
|
-
|
|
544
|
-
if (items === void 0) {
|
|
545
|
-
items = [];
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
_this = _AbstractCrdt.call(this) || this;
|
|
549
|
-
_this._items = [];
|
|
550
|
-
var position = undefined;
|
|
551
|
-
|
|
552
|
-
for (var i = 0; i < items.length; i++) {
|
|
553
|
-
var newPosition = makePosition(position);
|
|
554
|
-
|
|
555
|
-
var _item = selfOrRegister(items[i]);
|
|
556
|
-
|
|
557
|
-
_this._items.push([_item, newPosition]);
|
|
558
|
-
|
|
559
|
-
position = newPosition;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
return _this;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
LiveList._deserialize = function _deserialize(_ref, parentToChildren, doc) {
|
|
566
|
-
var id = _ref[0];
|
|
567
|
-
var list = new LiveList([]);
|
|
568
|
-
|
|
569
|
-
list._attach(id, doc);
|
|
570
|
-
|
|
571
|
-
var children = parentToChildren.get(id);
|
|
572
|
-
|
|
573
|
-
if (children == null) {
|
|
574
|
-
return list;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
for (var _iterator = _createForOfIteratorHelperLoose(children), _step; !(_step = _iterator()).done;) {
|
|
578
|
-
var entry = _step.value;
|
|
579
|
-
var child = deserialize(entry, parentToChildren, doc);
|
|
580
|
-
|
|
581
|
-
child._setParentLink(list, entry[1].parentKey);
|
|
582
|
-
|
|
583
|
-
list._items.push([child, entry[1].parentKey]);
|
|
584
|
-
|
|
585
|
-
list._items.sort(function (itemA, itemB) {
|
|
586
|
-
return compare(itemA[1], itemB[1]);
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
return list;
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
var _proto = LiveList.prototype;
|
|
594
|
-
|
|
595
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
596
|
-
if (this._id == null) {
|
|
597
|
-
throw new Error("Cannot serialize item is not attached");
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
if (parentId == null || parentKey == null) {
|
|
601
|
-
throw new Error("Cannot serialize list if parentId or parentKey is undefined");
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
var ops = [];
|
|
605
|
-
var op = {
|
|
606
|
-
id: this._id,
|
|
607
|
-
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
608
|
-
intent: intent,
|
|
609
|
-
type: OpType.CreateList,
|
|
610
|
-
parentId: parentId,
|
|
611
|
-
parentKey: parentKey
|
|
612
|
-
};
|
|
613
|
-
ops.push(op);
|
|
614
|
-
|
|
615
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(this._items), _step2; !(_step2 = _iterator2()).done;) {
|
|
616
|
-
var _step2$value = _step2.value,
|
|
617
|
-
_value = _step2$value[0],
|
|
618
|
-
key = _step2$value[1];
|
|
619
|
-
ops.push.apply(ops, _value._serialize(this._id, key, doc));
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
return ops;
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
_proto._indexOfPosition = function _indexOfPosition(position) {
|
|
626
|
-
return this._items.findIndex(function (item) {
|
|
627
|
-
return item[1] === position;
|
|
628
|
-
});
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
_proto._attach = function _attach(id, doc) {
|
|
632
|
-
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
633
|
-
|
|
634
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(this._items), _step3; !(_step3 = _iterator3()).done;) {
|
|
635
|
-
var _step3$value = _step3.value,
|
|
636
|
-
_item2 = _step3$value[0];
|
|
637
|
-
|
|
638
|
-
_item2._attach(doc.generateId(), doc);
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
_proto._detach = function _detach() {
|
|
643
|
-
_AbstractCrdt.prototype._detach.call(this);
|
|
644
|
-
|
|
645
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(this._items), _step4; !(_step4 = _iterator4()).done;) {
|
|
646
|
-
var _step4$value = _step4.value,
|
|
647
|
-
_value2 = _step4$value[0];
|
|
648
|
-
|
|
649
|
-
_value2._detach();
|
|
650
|
-
}
|
|
651
|
-
};
|
|
652
|
-
|
|
653
|
-
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
654
|
-
if (this._doc == null) {
|
|
655
|
-
throw new Error("Can't attach child if doc is not present");
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
var id = op.id,
|
|
659
|
-
parentKey = op.parentKey,
|
|
660
|
-
intent = op.intent;
|
|
661
|
-
var key = parentKey;
|
|
662
|
-
var child = creationOpToLiveStructure(op);
|
|
663
|
-
|
|
664
|
-
if (this._doc.getItem(id) !== undefined) {
|
|
665
|
-
return {
|
|
666
|
-
modified: false
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
child._attach(id, this._doc);
|
|
671
|
-
|
|
672
|
-
child._setParentLink(this, key);
|
|
673
|
-
|
|
674
|
-
var index = this._items.findIndex(function (entry) {
|
|
675
|
-
return entry[1] === key;
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
var newKey = key;
|
|
679
|
-
|
|
680
|
-
if (index !== -1) {
|
|
681
|
-
if (intent === "set") {
|
|
682
|
-
var existingItem = this._items[index][0];
|
|
683
|
-
|
|
684
|
-
existingItem._detach();
|
|
685
|
-
|
|
686
|
-
var storageUpdate = {
|
|
687
|
-
node: this,
|
|
688
|
-
type: "LiveList",
|
|
689
|
-
updates: [{
|
|
690
|
-
index: index,
|
|
691
|
-
type: "set",
|
|
692
|
-
item: child instanceof LiveRegister ? child.data : child
|
|
693
|
-
}]
|
|
694
|
-
};
|
|
695
|
-
this._items[index][0] = child;
|
|
696
|
-
return {
|
|
697
|
-
modified: storageUpdate,
|
|
698
|
-
reverse: existingItem._serialize(this._id, key, this._doc, "set")
|
|
699
|
-
};
|
|
700
|
-
} else if (isLocal) {
|
|
701
|
-
var before = this._items[index] ? this._items[index][1] : undefined;
|
|
702
|
-
var after = this._items[index + 1] ? this._items[index + 1][1] : undefined;
|
|
703
|
-
newKey = makePosition(before, after);
|
|
704
|
-
|
|
705
|
-
child._setParentLink(this, newKey);
|
|
706
|
-
} else {
|
|
707
|
-
var _this$_items;
|
|
708
|
-
|
|
709
|
-
this._items[index][1] = makePosition(key, (_this$_items = this._items[index + 1]) == null ? void 0 : _this$_items[1]);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
this._items.push([child, newKey]);
|
|
714
|
-
|
|
715
|
-
this._items.sort(function (itemA, itemB) {
|
|
716
|
-
return compare(itemA[1], itemB[1]);
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
var newIndex = this._items.findIndex(function (entry) {
|
|
720
|
-
return entry[1] === newKey;
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
return {
|
|
724
|
-
reverse: [{
|
|
725
|
-
type: OpType.DeleteCrdt,
|
|
726
|
-
id: id
|
|
727
|
-
}],
|
|
728
|
-
modified: {
|
|
729
|
-
node: this,
|
|
730
|
-
type: "LiveList",
|
|
731
|
-
updates: [{
|
|
732
|
-
index: newIndex,
|
|
733
|
-
type: "insert",
|
|
734
|
-
item: child instanceof LiveRegister ? child.data : child
|
|
735
|
-
}]
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
_proto._detachChild = function _detachChild(child) {
|
|
741
|
-
if (child) {
|
|
742
|
-
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
743
|
-
|
|
744
|
-
var indexToDelete = this._items.findIndex(function (item) {
|
|
745
|
-
return item[0] === child;
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
this._items.splice(indexToDelete, 1);
|
|
749
|
-
|
|
750
|
-
child._detach();
|
|
751
|
-
|
|
752
|
-
var storageUpdate = {
|
|
753
|
-
node: this,
|
|
754
|
-
type: "LiveList",
|
|
755
|
-
updates: [{
|
|
756
|
-
index: indexToDelete,
|
|
757
|
-
type: "delete"
|
|
758
|
-
}]
|
|
759
|
-
};
|
|
760
|
-
return {
|
|
761
|
-
modified: storageUpdate,
|
|
762
|
-
reverse: reverse
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
return {
|
|
767
|
-
modified: false
|
|
768
|
-
};
|
|
769
|
-
};
|
|
770
|
-
|
|
771
|
-
_proto._setChildKey = function _setChildKey(key, child, previousKey) {
|
|
772
|
-
child._setParentLink(this, key);
|
|
773
|
-
|
|
774
|
-
var previousIndex = this._items.findIndex(function (entry) {
|
|
775
|
-
return entry[0]._id === child._id;
|
|
776
|
-
});
|
|
777
|
-
|
|
778
|
-
var index = this._items.findIndex(function (entry) {
|
|
779
|
-
return entry[1] === key;
|
|
780
|
-
});
|
|
781
|
-
|
|
782
|
-
if (index !== -1) {
|
|
783
|
-
var _this$_items2;
|
|
784
|
-
|
|
785
|
-
this._items[index][1] = makePosition(key, (_this$_items2 = this._items[index + 1]) == null ? void 0 : _this$_items2[1]);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
var item = this._items.find(function (item) {
|
|
789
|
-
return item[0] === child;
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
if (item) {
|
|
793
|
-
item[1] = key;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
this._items.sort(function (itemA, itemB) {
|
|
797
|
-
return compare(itemA[1], itemB[1]);
|
|
798
|
-
});
|
|
799
|
-
|
|
800
|
-
var newIndex = this._items.findIndex(function (entry) {
|
|
801
|
-
return entry[0]._id === child._id;
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
var updatesDelta = newIndex === previousIndex ? [] : [{
|
|
805
|
-
index: newIndex,
|
|
806
|
-
item: child instanceof LiveRegister ? child.data : child,
|
|
807
|
-
previousIndex: previousIndex,
|
|
808
|
-
type: "move"
|
|
809
|
-
}];
|
|
810
|
-
return {
|
|
811
|
-
modified: {
|
|
812
|
-
node: this,
|
|
813
|
-
type: "LiveList",
|
|
814
|
-
updates: updatesDelta
|
|
815
|
-
},
|
|
816
|
-
reverse: [{
|
|
817
|
-
type: OpType.SetParentKey,
|
|
818
|
-
id: item == null ? void 0 : item[0]._id,
|
|
819
|
-
parentKey: previousKey
|
|
820
|
-
}]
|
|
821
|
-
};
|
|
822
|
-
};
|
|
823
|
-
|
|
824
|
-
_proto._apply = function _apply(op, isLocal) {
|
|
825
|
-
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
826
|
-
};
|
|
827
|
-
|
|
828
|
-
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
829
|
-
var _this$_parent;
|
|
830
|
-
|
|
831
|
-
return {
|
|
832
|
-
type: CrdtType.List,
|
|
833
|
-
parentId: (_this$_parent = this._parent) == null ? void 0 : _this$_parent._id,
|
|
834
|
-
parentKey: this._parentKey
|
|
835
|
-
};
|
|
836
|
-
};
|
|
837
|
-
|
|
838
|
-
_proto.push = function push(element) {
|
|
839
|
-
return this.insert(element, this.length);
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
_proto.insert = function insert(element, index) {
|
|
843
|
-
if (index < 0 || index > this._items.length) {
|
|
844
|
-
throw new Error("Cannot insert list item at index \"\x1D" + index + "\". index should be between 0 and " + this._items.length);
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
var before = this._items[index - 1] ? this._items[index - 1][1] : undefined;
|
|
848
|
-
var after = this._items[index] ? this._items[index][1] : undefined;
|
|
849
|
-
var position = makePosition(before, after);
|
|
850
|
-
var value = selfOrRegister(element);
|
|
851
|
-
|
|
852
|
-
value._setParentLink(this, position);
|
|
853
|
-
|
|
854
|
-
this._items.push([value, position]);
|
|
855
|
-
|
|
856
|
-
this._items.sort(function (itemA, itemB) {
|
|
857
|
-
return compare(itemA[1], itemB[1]);
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
var newIndex = this._items.findIndex(function (entry) {
|
|
861
|
-
return entry[1] === position;
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
if (this._doc && this._id) {
|
|
865
|
-
var _id = this._doc.generateId();
|
|
866
|
-
|
|
867
|
-
value._attach(_id, this._doc);
|
|
868
|
-
|
|
869
|
-
var storageUpdates = new Map();
|
|
870
|
-
storageUpdates.set(this._id, {
|
|
871
|
-
node: this,
|
|
872
|
-
type: "LiveList",
|
|
873
|
-
updates: [{
|
|
874
|
-
index: newIndex,
|
|
875
|
-
item: value instanceof LiveRegister ? value.data : value,
|
|
876
|
-
type: "insert"
|
|
877
|
-
}]
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
this._doc.dispatch(value._serialize(this._id, position, this._doc), [{
|
|
881
|
-
type: OpType.DeleteCrdt,
|
|
882
|
-
id: _id
|
|
883
|
-
}], storageUpdates);
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
_proto.move = function move(index, targetIndex) {
|
|
888
|
-
if (targetIndex < 0) {
|
|
889
|
-
throw new Error("targetIndex cannot be less than 0");
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
if (targetIndex >= this._items.length) {
|
|
893
|
-
throw new Error("targetIndex cannot be greater or equal than the list length");
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
if (index < 0) {
|
|
897
|
-
throw new Error("index cannot be less than 0");
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
if (index >= this._items.length) {
|
|
901
|
-
throw new Error("index cannot be greater or equal than the list length");
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
var beforePosition = null;
|
|
905
|
-
var afterPosition = null;
|
|
906
|
-
|
|
907
|
-
if (index < targetIndex) {
|
|
908
|
-
afterPosition = targetIndex === this._items.length - 1 ? undefined : this._items[targetIndex + 1][1];
|
|
909
|
-
beforePosition = this._items[targetIndex][1];
|
|
910
|
-
} else {
|
|
911
|
-
afterPosition = this._items[targetIndex][1];
|
|
912
|
-
beforePosition = targetIndex === 0 ? undefined : this._items[targetIndex - 1][1];
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
var position = makePosition(beforePosition, afterPosition);
|
|
916
|
-
var item = this._items[index];
|
|
917
|
-
var previousPosition = item[1];
|
|
918
|
-
item[1] = position;
|
|
919
|
-
|
|
920
|
-
item[0]._setParentLink(this, position);
|
|
921
|
-
|
|
922
|
-
this._items.sort(function (itemA, itemB) {
|
|
923
|
-
return compare(itemA[1], itemB[1]);
|
|
924
|
-
});
|
|
925
|
-
|
|
926
|
-
var newIndex = this._items.findIndex(function (entry) {
|
|
927
|
-
return entry[1] === position;
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
if (this._doc && this._id) {
|
|
931
|
-
var storageUpdates = new Map();
|
|
932
|
-
storageUpdates.set(this._id, {
|
|
933
|
-
node: this,
|
|
934
|
-
type: "LiveList",
|
|
935
|
-
updates: [{
|
|
936
|
-
index: newIndex,
|
|
937
|
-
previousIndex: index,
|
|
938
|
-
item: item[0],
|
|
939
|
-
type: "move"
|
|
940
|
-
}]
|
|
941
|
-
});
|
|
942
|
-
|
|
943
|
-
this._doc.dispatch([{
|
|
944
|
-
type: OpType.SetParentKey,
|
|
945
|
-
id: item[0]._id,
|
|
946
|
-
opId: this._doc.generateOpId(),
|
|
947
|
-
parentKey: position
|
|
948
|
-
}], [{
|
|
949
|
-
type: OpType.SetParentKey,
|
|
950
|
-
id: item[0]._id,
|
|
951
|
-
parentKey: previousPosition
|
|
952
|
-
}], storageUpdates);
|
|
953
|
-
}
|
|
954
|
-
};
|
|
955
|
-
|
|
956
|
-
_proto.delete = function _delete(index) {
|
|
957
|
-
if (index < 0 || index >= this._items.length) {
|
|
958
|
-
throw new Error("Cannot delete list item at index \"\x1D" + index + "\". index should be between 0 and " + (this._items.length - 1));
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
var item = this._items[index];
|
|
962
|
-
|
|
963
|
-
item[0]._detach();
|
|
964
|
-
|
|
965
|
-
this._items.splice(index, 1);
|
|
966
|
-
|
|
967
|
-
if (this._doc) {
|
|
968
|
-
var childRecordId = item[0]._id;
|
|
969
|
-
|
|
970
|
-
if (childRecordId) {
|
|
971
|
-
var storageUpdates = new Map();
|
|
972
|
-
storageUpdates.set(this._id, {
|
|
973
|
-
node: this,
|
|
974
|
-
type: "LiveList",
|
|
975
|
-
updates: [{
|
|
976
|
-
index: index,
|
|
977
|
-
type: "delete"
|
|
978
|
-
}]
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
this._doc.dispatch([{
|
|
982
|
-
id: childRecordId,
|
|
983
|
-
opId: this._doc.generateOpId(),
|
|
984
|
-
type: OpType.DeleteCrdt
|
|
985
|
-
}], item[0]._serialize(this._id, item[1]), storageUpdates);
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
};
|
|
989
|
-
|
|
990
|
-
_proto.clear = function clear() {
|
|
991
|
-
if (this._doc) {
|
|
992
|
-
var ops = [];
|
|
993
|
-
var reverseOps = [];
|
|
994
|
-
var updateDelta = [];
|
|
995
|
-
var i = 0;
|
|
996
|
-
|
|
997
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(this._items), _step5; !(_step5 = _iterator5()).done;) {
|
|
998
|
-
var _item3 = _step5.value;
|
|
999
|
-
|
|
1000
|
-
_item3[0]._detach();
|
|
1001
|
-
|
|
1002
|
-
var childId = _item3[0]._id;
|
|
1003
|
-
|
|
1004
|
-
if (childId) {
|
|
1005
|
-
ops.push({
|
|
1006
|
-
id: childId,
|
|
1007
|
-
type: OpType.DeleteCrdt
|
|
1008
|
-
});
|
|
1009
|
-
reverseOps.push.apply(reverseOps, _item3[0]._serialize(this._id, _item3[1]));
|
|
1010
|
-
updateDelta.push({
|
|
1011
|
-
index: i,
|
|
1012
|
-
type: "delete"
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
i++;
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
this._items = [];
|
|
1020
|
-
var storageUpdates = new Map();
|
|
1021
|
-
storageUpdates.set(this._id, {
|
|
1022
|
-
node: this,
|
|
1023
|
-
type: "LiveList",
|
|
1024
|
-
updates: updateDelta
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
1028
|
-
} else {
|
|
1029
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(this._items), _step6; !(_step6 = _iterator6()).done;) {
|
|
1030
|
-
var _item4 = _step6.value;
|
|
1031
|
-
|
|
1032
|
-
_item4[0]._detach();
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
this._items = [];
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
|
|
1039
|
-
_proto.set = function set(index, item) {
|
|
1040
|
-
if (index < 0 || index >= this._items.length) {
|
|
1041
|
-
throw new Error("Cannot set list item at index \"\x1D" + index + "\". index should be between 0 and " + (this._items.length - 1));
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
var _this$_items$index = this._items[index],
|
|
1045
|
-
existingItem = _this$_items$index[0],
|
|
1046
|
-
position = _this$_items$index[1];
|
|
1047
|
-
|
|
1048
|
-
existingItem._detach();
|
|
1049
|
-
|
|
1050
|
-
var value = selfOrRegister(item);
|
|
1051
|
-
|
|
1052
|
-
value._setParentLink(this, position);
|
|
1053
|
-
|
|
1054
|
-
this._items[index][0] = value;
|
|
1055
|
-
|
|
1056
|
-
if (this._doc && this._id) {
|
|
1057
|
-
var _id2 = this._doc.generateId();
|
|
1058
|
-
|
|
1059
|
-
value._attach(_id2, this._doc);
|
|
1060
|
-
|
|
1061
|
-
var storageUpdates = new Map();
|
|
1062
|
-
storageUpdates.set(this._id, {
|
|
1063
|
-
node: this,
|
|
1064
|
-
type: "LiveList",
|
|
1065
|
-
updates: [{
|
|
1066
|
-
index: index,
|
|
1067
|
-
item: value instanceof LiveRegister ? value.data : value,
|
|
1068
|
-
type: "set"
|
|
1069
|
-
}]
|
|
1070
|
-
});
|
|
1071
|
-
|
|
1072
|
-
this._doc.dispatch(value._serialize(this._id, position, this._doc, "set"), existingItem._serialize(this._id, position, undefined, "set"), storageUpdates);
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
|
|
1076
|
-
_proto.toArray = function toArray() {
|
|
1077
|
-
return this._items.map(function (entry) {
|
|
1078
|
-
return selfOrRegisterValue(entry[0]);
|
|
1079
|
-
});
|
|
1080
|
-
};
|
|
1081
|
-
|
|
1082
|
-
_proto.every = function every(predicate) {
|
|
1083
|
-
return this.toArray().every(predicate);
|
|
1084
|
-
};
|
|
1085
|
-
|
|
1086
|
-
_proto.filter = function filter(predicate) {
|
|
1087
|
-
return this.toArray().filter(predicate);
|
|
1088
|
-
};
|
|
1089
|
-
|
|
1090
|
-
_proto.find = function find(predicate) {
|
|
1091
|
-
return this.toArray().find(predicate);
|
|
1092
|
-
};
|
|
1093
|
-
|
|
1094
|
-
_proto.findIndex = function findIndex(predicate) {
|
|
1095
|
-
return this.toArray().findIndex(predicate);
|
|
1096
|
-
};
|
|
1097
|
-
|
|
1098
|
-
_proto.forEach = function forEach(callbackfn) {
|
|
1099
|
-
return this.toArray().forEach(callbackfn);
|
|
1100
|
-
};
|
|
1101
|
-
|
|
1102
|
-
_proto.get = function get(index) {
|
|
1103
|
-
if (index < 0 || index >= this._items.length) {
|
|
1104
|
-
return undefined;
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
return selfOrRegisterValue(this._items[index][0]);
|
|
1108
|
-
};
|
|
1109
|
-
|
|
1110
|
-
_proto.indexOf = function indexOf(searchElement, fromIndex) {
|
|
1111
|
-
return this.toArray().indexOf(searchElement, fromIndex);
|
|
1112
|
-
};
|
|
1113
|
-
|
|
1114
|
-
_proto.lastIndexOf = function lastIndexOf(searchElement, fromIndex) {
|
|
1115
|
-
return this.toArray().lastIndexOf(searchElement, fromIndex);
|
|
1116
|
-
};
|
|
1117
|
-
|
|
1118
|
-
_proto.map = function map(callback) {
|
|
1119
|
-
return this._items.map(function (entry, i) {
|
|
1120
|
-
return callback(selfOrRegisterValue(entry[0]), i);
|
|
1121
|
-
});
|
|
1122
|
-
};
|
|
1123
|
-
|
|
1124
|
-
_proto.some = function some(predicate) {
|
|
1125
|
-
return this.toArray().some(predicate);
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
_proto[Symbol.iterator] = function () {
|
|
1129
|
-
return new LiveListIterator(this._items);
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
|
-
_createClass(LiveList, [{
|
|
1133
|
-
key: "length",
|
|
1134
|
-
get: function get() {
|
|
1135
|
-
return this._items.length;
|
|
1136
|
-
}
|
|
1137
|
-
}]);
|
|
1138
|
-
|
|
1139
|
-
return LiveList;
|
|
1140
|
-
}(AbstractCrdt);
|
|
1141
|
-
|
|
1142
|
-
var LiveListIterator = function () {
|
|
1143
|
-
function LiveListIterator(items) {
|
|
1144
|
-
this._innerIterator = items[Symbol.iterator]();
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
var _proto2 = LiveListIterator.prototype;
|
|
1148
|
-
|
|
1149
|
-
_proto2[Symbol.iterator] = function () {
|
|
1150
|
-
return this;
|
|
1151
|
-
};
|
|
1152
|
-
|
|
1153
|
-
_proto2.next = function next() {
|
|
1154
|
-
var result = this._innerIterator.next();
|
|
1155
|
-
|
|
1156
|
-
if (result.done) {
|
|
1157
|
-
return {
|
|
1158
|
-
done: true,
|
|
1159
|
-
value: undefined
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
return {
|
|
1164
|
-
value: selfOrRegisterValue(result.value[0])
|
|
1165
|
-
};
|
|
1166
|
-
};
|
|
1167
|
-
|
|
1168
|
-
return LiveListIterator;
|
|
1169
|
-
}();
|
|
1170
|
-
|
|
1171
|
-
var LiveMap = function (_AbstractCrdt) {
|
|
1172
|
-
_inheritsLoose(LiveMap, _AbstractCrdt);
|
|
1173
|
-
|
|
1174
|
-
function LiveMap(entries) {
|
|
1175
|
-
var _this;
|
|
1176
|
-
|
|
1177
|
-
_this = _AbstractCrdt.call(this) || this;
|
|
1178
|
-
|
|
1179
|
-
if (entries) {
|
|
1180
|
-
var mappedEntries = [];
|
|
1181
|
-
|
|
1182
|
-
for (var _iterator = _createForOfIteratorHelperLoose(entries), _step; !(_step = _iterator()).done;) {
|
|
1183
|
-
var entry = _step.value;
|
|
1184
|
-
|
|
1185
|
-
var _value = selfOrRegister(entry[1]);
|
|
1186
|
-
|
|
1187
|
-
_value._setParentLink(_assertThisInitialized(_this), entry[0]);
|
|
1188
|
-
|
|
1189
|
-
mappedEntries.push([entry[0], _value]);
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
_this._map = new Map(mappedEntries);
|
|
1193
|
-
} else {
|
|
1194
|
-
_this._map = new Map();
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
return _this;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
var _proto = LiveMap.prototype;
|
|
1201
|
-
|
|
1202
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1203
|
-
if (this._id == null) {
|
|
1204
|
-
throw new Error("Cannot serialize item is not attached");
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
if (parentId == null || parentKey == null) {
|
|
1208
|
-
throw new Error("Cannot serialize map if parentId or parentKey is undefined");
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
var ops = [];
|
|
1212
|
-
var op = {
|
|
1213
|
-
id: this._id,
|
|
1214
|
-
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1215
|
-
type: OpType.CreateMap,
|
|
1216
|
-
intent: intent,
|
|
1217
|
-
parentId: parentId,
|
|
1218
|
-
parentKey: parentKey
|
|
1219
|
-
};
|
|
1220
|
-
ops.push(op);
|
|
1221
|
-
|
|
1222
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(this._map), _step2; !(_step2 = _iterator2()).done;) {
|
|
1223
|
-
var _step2$value = _step2.value,
|
|
1224
|
-
_key2 = _step2$value[0],
|
|
1225
|
-
_value2 = _step2$value[1];
|
|
1226
|
-
ops.push.apply(ops, _value2._serialize(this._id, _key2, doc));
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
return ops;
|
|
1230
|
-
};
|
|
1231
|
-
|
|
1232
|
-
LiveMap._deserialize = function _deserialize(_ref, parentToChildren, doc) {
|
|
1233
|
-
var id = _ref[0],
|
|
1234
|
-
item = _ref[1];
|
|
1235
|
-
|
|
1236
|
-
if (item.type !== CrdtType.Map) {
|
|
1237
|
-
throw new Error("Tried to deserialize a map but item type is \"" + item.type + "\"");
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
var map = new LiveMap();
|
|
1241
|
-
|
|
1242
|
-
map._attach(id, doc);
|
|
1243
|
-
|
|
1244
|
-
var children = parentToChildren.get(id);
|
|
1245
|
-
|
|
1246
|
-
if (children == null) {
|
|
1247
|
-
return map;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(children), _step3; !(_step3 = _iterator3()).done;) {
|
|
1251
|
-
var entry = _step3.value;
|
|
1252
|
-
var crdt = entry[1];
|
|
1253
|
-
|
|
1254
|
-
if (crdt.parentKey == null) {
|
|
1255
|
-
throw new Error("Tried to deserialize a crdt but it does not have a parentKey and is not the root");
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
var child = deserialize(entry, parentToChildren, doc);
|
|
1259
|
-
|
|
1260
|
-
child._setParentLink(map, crdt.parentKey);
|
|
1261
|
-
|
|
1262
|
-
map._map.set(crdt.parentKey, child);
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
return map;
|
|
1266
|
-
};
|
|
1267
|
-
|
|
1268
|
-
_proto._attach = function _attach(id, doc) {
|
|
1269
|
-
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1270
|
-
|
|
1271
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
|
|
1272
|
-
var _step4$value = _step4.value;
|
|
1273
|
-
_step4$value[0];
|
|
1274
|
-
var _value3 = _step4$value[1];
|
|
1275
|
-
|
|
1276
|
-
if (isCrdt(_value3)) {
|
|
1277
|
-
_value3._attach(doc.generateId(), doc);
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
};
|
|
1281
|
-
|
|
1282
|
-
_proto._attachChild = function _attachChild(op, _isLocal) {
|
|
1283
|
-
var _updates;
|
|
1284
|
-
|
|
1285
|
-
if (this._doc == null) {
|
|
1286
|
-
throw new Error("Can't attach child if doc is not present");
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
var id = op.id,
|
|
1290
|
-
parentKey = op.parentKey;
|
|
1291
|
-
var key = parentKey;
|
|
1292
|
-
var child = creationOpToLiveStructure(op);
|
|
1293
|
-
|
|
1294
|
-
if (this._doc.getItem(id) !== undefined) {
|
|
1295
|
-
return {
|
|
1296
|
-
modified: false
|
|
1297
|
-
};
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
var previousValue = this._map.get(key);
|
|
1301
|
-
|
|
1302
|
-
var reverse;
|
|
1303
|
-
|
|
1304
|
-
if (previousValue) {
|
|
1305
|
-
reverse = previousValue._serialize(this._id, key);
|
|
1306
|
-
|
|
1307
|
-
previousValue._detach();
|
|
1308
|
-
} else {
|
|
1309
|
-
reverse = [{
|
|
1310
|
-
type: OpType.DeleteCrdt,
|
|
1311
|
-
id: id
|
|
1312
|
-
}];
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
child._setParentLink(this, key);
|
|
1316
|
-
|
|
1317
|
-
child._attach(id, this._doc);
|
|
1318
|
-
|
|
1319
|
-
this._map.set(key, child);
|
|
1320
|
-
|
|
1321
|
-
return {
|
|
1322
|
-
modified: {
|
|
1323
|
-
node: this,
|
|
1324
|
-
type: "LiveMap",
|
|
1325
|
-
updates: (_updates = {}, _updates[key] = {
|
|
1326
|
-
type: "update"
|
|
1327
|
-
}, _updates)
|
|
1328
|
-
},
|
|
1329
|
-
reverse: reverse
|
|
1330
|
-
};
|
|
1331
|
-
};
|
|
1332
|
-
|
|
1333
|
-
_proto._detach = function _detach() {
|
|
1334
|
-
_AbstractCrdt.prototype._detach.call(this);
|
|
1335
|
-
|
|
1336
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(this._map.values()), _step5; !(_step5 = _iterator5()).done;) {
|
|
1337
|
-
var item = _step5.value;
|
|
1338
|
-
|
|
1339
|
-
item._detach();
|
|
1340
|
-
}
|
|
1341
|
-
};
|
|
1342
|
-
|
|
1343
|
-
_proto._detachChild = function _detachChild(child) {
|
|
1344
|
-
var _updates2;
|
|
1345
|
-
|
|
1346
|
-
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
1347
|
-
|
|
1348
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(this._map), _step6; !(_step6 = _iterator6()).done;) {
|
|
1349
|
-
var _step6$value = _step6.value,
|
|
1350
|
-
_key3 = _step6$value[0],
|
|
1351
|
-
_value4 = _step6$value[1];
|
|
1352
|
-
|
|
1353
|
-
if (_value4 === child) {
|
|
1354
|
-
this._map.delete(_key3);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
child._detach();
|
|
1359
|
-
|
|
1360
|
-
var storageUpdate = {
|
|
1361
|
-
node: this,
|
|
1362
|
-
type: "LiveMap",
|
|
1363
|
-
updates: (_updates2 = {}, _updates2[child._parentKey] = {
|
|
1364
|
-
type: "delete"
|
|
1365
|
-
}, _updates2)
|
|
1366
|
-
};
|
|
1367
|
-
return {
|
|
1368
|
-
modified: storageUpdate,
|
|
1369
|
-
reverse: reverse
|
|
1370
|
-
};
|
|
1371
|
-
};
|
|
1372
|
-
|
|
1373
|
-
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
1374
|
-
var _this$_parent;
|
|
1375
|
-
|
|
1376
|
-
return {
|
|
1377
|
-
type: CrdtType.Map,
|
|
1378
|
-
parentId: (_this$_parent = this._parent) == null ? void 0 : _this$_parent._id,
|
|
1379
|
-
parentKey: this._parentKey
|
|
1380
|
-
};
|
|
1381
|
-
};
|
|
1382
|
-
|
|
1383
|
-
_proto.get = function get(key) {
|
|
1384
|
-
var value = this._map.get(key);
|
|
1385
|
-
|
|
1386
|
-
if (value == undefined) {
|
|
1387
|
-
return undefined;
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
return selfOrRegisterValue(value);
|
|
1391
|
-
};
|
|
1392
|
-
|
|
1393
|
-
_proto.set = function set(key, value) {
|
|
1394
|
-
var oldValue = this._map.get(key);
|
|
1395
|
-
|
|
1396
|
-
if (oldValue) {
|
|
1397
|
-
oldValue._detach();
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
var item = selfOrRegister(value);
|
|
1401
|
-
|
|
1402
|
-
item._setParentLink(this, key);
|
|
1403
|
-
|
|
1404
|
-
this._map.set(key, item);
|
|
1405
|
-
|
|
1406
|
-
if (this._doc && this._id) {
|
|
1407
|
-
var _updates3;
|
|
1408
|
-
|
|
1409
|
-
var id = this._doc.generateId();
|
|
1410
|
-
|
|
1411
|
-
item._attach(id, this._doc);
|
|
1412
|
-
|
|
1413
|
-
var storageUpdates = new Map();
|
|
1414
|
-
storageUpdates.set(this._id, {
|
|
1415
|
-
node: this,
|
|
1416
|
-
type: "LiveMap",
|
|
1417
|
-
updates: (_updates3 = {}, _updates3[key] = {
|
|
1418
|
-
type: "update"
|
|
1419
|
-
}, _updates3)
|
|
1420
|
-
});
|
|
1421
|
-
|
|
1422
|
-
this._doc.dispatch(item._serialize(this._id, key, this._doc), oldValue ? oldValue._serialize(this._id, key) : [{
|
|
1423
|
-
type: OpType.DeleteCrdt,
|
|
1424
|
-
id: id
|
|
1425
|
-
}], storageUpdates);
|
|
1426
|
-
}
|
|
1427
|
-
};
|
|
1428
|
-
|
|
1429
|
-
_proto.has = function has(key) {
|
|
1430
|
-
return this._map.has(key);
|
|
1431
|
-
};
|
|
1432
|
-
|
|
1433
|
-
_proto.delete = function _delete(key) {
|
|
1434
|
-
var item = this._map.get(key);
|
|
1435
|
-
|
|
1436
|
-
if (item == null) {
|
|
1437
|
-
return false;
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
item._detach();
|
|
1441
|
-
|
|
1442
|
-
this._map.delete(key);
|
|
1443
|
-
|
|
1444
|
-
if (this._doc && item._id) {
|
|
1445
|
-
var _updates4;
|
|
1446
|
-
|
|
1447
|
-
var storageUpdates = new Map();
|
|
1448
|
-
storageUpdates.set(this._id, {
|
|
1449
|
-
node: this,
|
|
1450
|
-
type: "LiveMap",
|
|
1451
|
-
updates: (_updates4 = {}, _updates4[key] = {
|
|
1452
|
-
type: "delete"
|
|
1453
|
-
}, _updates4)
|
|
1454
|
-
});
|
|
1455
|
-
|
|
1456
|
-
this._doc.dispatch([{
|
|
1457
|
-
type: OpType.DeleteCrdt,
|
|
1458
|
-
id: item._id,
|
|
1459
|
-
opId: this._doc.generateOpId()
|
|
1460
|
-
}], item._serialize(this._id, key), storageUpdates);
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
return true;
|
|
1464
|
-
};
|
|
1465
|
-
|
|
1466
|
-
_proto.entries = function entries() {
|
|
1467
|
-
var _ref2;
|
|
1468
|
-
|
|
1469
|
-
var innerIterator = this._map.entries();
|
|
1470
|
-
|
|
1471
|
-
return _ref2 = {}, _ref2[Symbol.iterator] = function () {
|
|
1472
|
-
return this;
|
|
1473
|
-
}, _ref2.next = function next() {
|
|
1474
|
-
var iteratorValue = innerIterator.next();
|
|
1475
|
-
|
|
1476
|
-
if (iteratorValue.done) {
|
|
1477
|
-
return {
|
|
1478
|
-
done: true,
|
|
1479
|
-
value: undefined
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
var entry = iteratorValue.value;
|
|
1484
|
-
return {
|
|
1485
|
-
value: [entry[0], selfOrRegisterValue(iteratorValue.value[1])]
|
|
1486
|
-
};
|
|
1487
|
-
}, _ref2;
|
|
1488
|
-
};
|
|
1489
|
-
|
|
1490
|
-
_proto[Symbol.iterator] = function () {
|
|
1491
|
-
return this.entries();
|
|
1492
|
-
};
|
|
1493
|
-
|
|
1494
|
-
_proto.keys = function keys() {
|
|
1495
|
-
return this._map.keys();
|
|
1496
|
-
};
|
|
1497
|
-
|
|
1498
|
-
_proto.values = function values() {
|
|
1499
|
-
var _ref3;
|
|
1500
|
-
|
|
1501
|
-
var innerIterator = this._map.values();
|
|
1502
|
-
|
|
1503
|
-
return _ref3 = {}, _ref3[Symbol.iterator] = function () {
|
|
1504
|
-
return this;
|
|
1505
|
-
}, _ref3.next = function next() {
|
|
1506
|
-
var iteratorValue = innerIterator.next();
|
|
1507
|
-
|
|
1508
|
-
if (iteratorValue.done) {
|
|
1509
|
-
return {
|
|
1510
|
-
done: true,
|
|
1511
|
-
value: undefined
|
|
1512
|
-
};
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
return {
|
|
1516
|
-
value: selfOrRegisterValue(iteratorValue.value)
|
|
1517
|
-
};
|
|
1518
|
-
}, _ref3;
|
|
1519
|
-
};
|
|
1520
|
-
|
|
1521
|
-
_proto.forEach = function forEach(callback) {
|
|
1522
|
-
for (var _iterator7 = _createForOfIteratorHelperLoose(this), _step7; !(_step7 = _iterator7()).done;) {
|
|
1523
|
-
var entry = _step7.value;
|
|
1524
|
-
callback(entry[1], entry[0], this);
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
|
|
1528
|
-
_createClass(LiveMap, [{
|
|
1529
|
-
key: "size",
|
|
1530
|
-
get: function get() {
|
|
1531
|
-
return this._map.size;
|
|
1532
|
-
}
|
|
1533
|
-
}]);
|
|
1534
|
-
|
|
1535
|
-
return LiveMap;
|
|
1536
|
-
}(AbstractCrdt);
|
|
1537
|
-
|
|
1538
|
-
function parseJson(rawMessage) {
|
|
1539
|
-
try {
|
|
1540
|
-
return JSON.parse(rawMessage);
|
|
1541
|
-
} catch (e) {
|
|
1542
|
-
return undefined;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
function isJsonArray(data) {
|
|
1546
|
-
return Array.isArray(data);
|
|
1547
|
-
}
|
|
1548
|
-
function isJsonObject(data) {
|
|
1549
|
-
return data !== null && typeof data === "object" && !isJsonArray(data);
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
function remove(array, item) {
|
|
1553
|
-
for (var i = 0; i < array.length; i++) {
|
|
1554
|
-
if (array[i] === item) {
|
|
1555
|
-
array.splice(i, 1);
|
|
1556
|
-
break;
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
function compact(items) {
|
|
1561
|
-
return items.filter(function (item) {
|
|
1562
|
-
return item != null;
|
|
1563
|
-
});
|
|
1564
|
-
}
|
|
1565
|
-
function creationOpToLiveStructure(op) {
|
|
1566
|
-
switch (op.type) {
|
|
1567
|
-
case OpType.CreateRegister:
|
|
1568
|
-
return new LiveRegister(op.data);
|
|
1569
|
-
|
|
1570
|
-
case OpType.CreateObject:
|
|
1571
|
-
return new LiveObject(op.data);
|
|
1572
|
-
|
|
1573
|
-
case OpType.CreateMap:
|
|
1574
|
-
return new LiveMap();
|
|
1575
|
-
|
|
1576
|
-
case OpType.CreateList:
|
|
1577
|
-
return new LiveList();
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
function isSameNodeOrChildOf(node, parent) {
|
|
1581
|
-
if (node === parent) {
|
|
1582
|
-
return true;
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
if (node._parent) {
|
|
1586
|
-
return isSameNodeOrChildOf(node._parent, parent);
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
return false;
|
|
1590
|
-
}
|
|
1591
|
-
function deserialize(entry, parentToChildren, doc) {
|
|
1592
|
-
switch (entry[1].type) {
|
|
1593
|
-
case CrdtType.Object:
|
|
1594
|
-
{
|
|
1595
|
-
return LiveObject._deserialize(entry, parentToChildren, doc);
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
case CrdtType.List:
|
|
1599
|
-
{
|
|
1600
|
-
return LiveList._deserialize(entry, parentToChildren, doc);
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
case CrdtType.Map:
|
|
1604
|
-
{
|
|
1605
|
-
return LiveMap._deserialize(entry, parentToChildren, doc);
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
case CrdtType.Register:
|
|
1609
|
-
{
|
|
1610
|
-
return LiveRegister._deserialize(entry, parentToChildren, doc);
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
default:
|
|
1614
|
-
{
|
|
1615
|
-
throw new Error("Unexpected CRDT type");
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
function isCrdt(obj) {
|
|
1620
|
-
return obj instanceof LiveObject || obj instanceof LiveMap || obj instanceof LiveList || obj instanceof LiveRegister;
|
|
1621
|
-
}
|
|
1622
|
-
function selfOrRegisterValue(obj) {
|
|
1623
|
-
if (obj instanceof LiveRegister) {
|
|
1624
|
-
return obj.data;
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
return obj;
|
|
1628
|
-
}
|
|
1629
|
-
function selfOrRegister(obj) {
|
|
1630
|
-
if (obj instanceof LiveObject || obj instanceof LiveMap || obj instanceof LiveList) {
|
|
1631
|
-
return obj;
|
|
1632
|
-
} else if (obj instanceof LiveRegister) {
|
|
1633
|
-
throw new Error("Internal error. LiveRegister should not be created from selfOrRegister");
|
|
1634
|
-
} else {
|
|
1635
|
-
return new LiveRegister(obj);
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
function getTreesDiffOperations(currentItems, newItems) {
|
|
1639
|
-
var ops = [];
|
|
1640
|
-
currentItems.forEach(function (_, id) {
|
|
1641
|
-
if (!newItems.get(id)) {
|
|
1642
|
-
ops.push({
|
|
1643
|
-
type: OpType.DeleteCrdt,
|
|
1644
|
-
id: id
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
});
|
|
1648
|
-
newItems.forEach(function (crdt, id) {
|
|
1649
|
-
var currentCrdt = currentItems.get(id);
|
|
1650
|
-
|
|
1651
|
-
if (currentCrdt) {
|
|
1652
|
-
if (crdt.type === CrdtType.Object) {
|
|
1653
|
-
if (JSON.stringify(crdt.data) !== JSON.stringify(currentCrdt.data)) {
|
|
1654
|
-
ops.push({
|
|
1655
|
-
type: OpType.UpdateObject,
|
|
1656
|
-
id: id,
|
|
1657
|
-
data: crdt.data
|
|
1658
|
-
});
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
if (crdt.parentKey !== currentCrdt.parentKey) {
|
|
1663
|
-
ops.push({
|
|
1664
|
-
type: OpType.SetParentKey,
|
|
1665
|
-
id: id,
|
|
1666
|
-
parentKey: crdt.parentKey
|
|
1667
|
-
});
|
|
1668
|
-
}
|
|
1669
|
-
} else {
|
|
1670
|
-
switch (crdt.type) {
|
|
1671
|
-
case CrdtType.Register:
|
|
1672
|
-
ops.push({
|
|
1673
|
-
type: OpType.CreateRegister,
|
|
1674
|
-
id: id,
|
|
1675
|
-
parentId: crdt.parentId,
|
|
1676
|
-
parentKey: crdt.parentKey,
|
|
1677
|
-
data: crdt.data
|
|
1678
|
-
});
|
|
1679
|
-
break;
|
|
1680
|
-
|
|
1681
|
-
case CrdtType.List:
|
|
1682
|
-
ops.push({
|
|
1683
|
-
type: OpType.CreateList,
|
|
1684
|
-
id: id,
|
|
1685
|
-
parentId: crdt.parentId,
|
|
1686
|
-
parentKey: crdt.parentKey
|
|
1687
|
-
});
|
|
1688
|
-
break;
|
|
1689
|
-
|
|
1690
|
-
case CrdtType.Object:
|
|
1691
|
-
ops.push({
|
|
1692
|
-
type: OpType.CreateObject,
|
|
1693
|
-
id: id,
|
|
1694
|
-
parentId: crdt.parentId,
|
|
1695
|
-
parentKey: crdt.parentKey,
|
|
1696
|
-
data: crdt.data
|
|
1697
|
-
});
|
|
1698
|
-
break;
|
|
1699
|
-
|
|
1700
|
-
case CrdtType.Map:
|
|
1701
|
-
ops.push({
|
|
1702
|
-
type: OpType.CreateMap,
|
|
1703
|
-
id: id,
|
|
1704
|
-
parentId: crdt.parentId,
|
|
1705
|
-
parentKey: crdt.parentKey
|
|
1706
|
-
});
|
|
1707
|
-
break;
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
});
|
|
1711
|
-
return ops;
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
function mergeObjectStorageUpdates(first, second) {
|
|
1715
|
-
var updates = first.updates;
|
|
1716
|
-
|
|
1717
|
-
for (var _iterator = _createForOfIteratorHelperLoose(entries(second.updates)), _step; !(_step = _iterator()).done;) {
|
|
1718
|
-
var _step$value = _step.value,
|
|
1719
|
-
_key = _step$value[0],
|
|
1720
|
-
value = _step$value[1];
|
|
1721
|
-
updates[_key] = value;
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
return _extends({}, second, {
|
|
1725
|
-
updates: updates
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
function mergeMapStorageUpdates(first, second) {
|
|
1730
|
-
var updates = first.updates;
|
|
1731
|
-
|
|
1732
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(entries(second.updates)), _step2; !(_step2 = _iterator2()).done;) {
|
|
1733
|
-
var _step2$value = _step2.value,
|
|
1734
|
-
_key2 = _step2$value[0],
|
|
1735
|
-
value = _step2$value[1];
|
|
1736
|
-
updates[_key2] = value;
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
return _extends({}, second, {
|
|
1740
|
-
updates: updates
|
|
1741
|
-
});
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
function mergeListStorageUpdates(first, second) {
|
|
1745
|
-
var updates = first.updates;
|
|
1746
|
-
return _extends({}, second, {
|
|
1747
|
-
updates: updates.concat(second.updates)
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
function mergeStorageUpdates(first, second) {
|
|
1752
|
-
if (!first) {
|
|
1753
|
-
return second;
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
if (first.type === "LiveObject" && second.type === "LiveObject") {
|
|
1757
|
-
return mergeObjectStorageUpdates(first, second);
|
|
1758
|
-
} else if (first.type === "LiveMap" && second.type === "LiveMap") {
|
|
1759
|
-
return mergeMapStorageUpdates(first, second);
|
|
1760
|
-
} else if (first.type === "LiveList" && second.type === "LiveList") {
|
|
1761
|
-
return mergeListStorageUpdates(first, second);
|
|
1762
|
-
} else ;
|
|
1763
|
-
|
|
1764
|
-
return second;
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
function isPlain(value) {
|
|
1768
|
-
var type = typeof value;
|
|
1769
|
-
return type === "undefined" || value === null || type === "string" || type === "boolean" || type === "number" || Array.isArray(value) || isPlainObject$1(value);
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
function isPlainObject$1(value) {
|
|
1773
|
-
if (typeof value !== "object" || value === null) return false;
|
|
1774
|
-
var proto = Object.getPrototypeOf(value);
|
|
1775
|
-
if (proto === null) return true;
|
|
1776
|
-
var baseProto = proto;
|
|
1777
|
-
|
|
1778
|
-
while (Object.getPrototypeOf(baseProto) !== null) {
|
|
1779
|
-
baseProto = Object.getPrototypeOf(baseProto);
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
return proto === baseProto;
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
function findNonSerializableValue(value, path) {
|
|
1786
|
-
if (path === void 0) {
|
|
1787
|
-
path = "";
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
if (!isPlain) {
|
|
1791
|
-
return {
|
|
1792
|
-
path: path || "root",
|
|
1793
|
-
value: value
|
|
1794
|
-
};
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
if (typeof value !== "object" || value === null) {
|
|
1798
|
-
return false;
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
for (var _i = 0, _Object$entries = Object.entries(value); _i < _Object$entries.length; _i++) {
|
|
1802
|
-
var _Object$entries$_i = _Object$entries[_i],
|
|
1803
|
-
_key3 = _Object$entries$_i[0],
|
|
1804
|
-
nestedValue = _Object$entries$_i[1];
|
|
1805
|
-
var nestedPath = path ? path + "." + _key3 : _key3;
|
|
1806
|
-
|
|
1807
|
-
if (!isPlain(nestedValue)) {
|
|
1808
|
-
return {
|
|
1809
|
-
path: nestedPath,
|
|
1810
|
-
value: nestedValue
|
|
1811
|
-
};
|
|
1812
|
-
}
|
|
1813
|
-
|
|
1814
|
-
if (typeof nestedValue === "object") {
|
|
1815
|
-
var nonSerializableNestedValue = findNonSerializableValue(nestedValue, nestedPath);
|
|
1816
|
-
|
|
1817
|
-
if (nonSerializableNestedValue) {
|
|
1818
|
-
return nonSerializableNestedValue;
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
return false;
|
|
1824
|
-
}
|
|
1825
|
-
function isTokenValid(token) {
|
|
1826
|
-
var tokenParts = token.split(".");
|
|
1827
|
-
|
|
1828
|
-
if (tokenParts.length !== 3) {
|
|
1829
|
-
return false;
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
var data = parseJson(atob(tokenParts[1]));
|
|
1833
|
-
|
|
1834
|
-
if (data === undefined || !isJsonObject(data) || typeof data.exp !== "number") {
|
|
1835
|
-
return false;
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
|
-
var now = Date.now();
|
|
1839
|
-
|
|
1840
|
-
if (now / 1000 > data.exp - 300) {
|
|
1841
|
-
return false;
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
return true;
|
|
1845
|
-
}
|
|
1846
|
-
function entries(obj) {
|
|
1847
|
-
return Object.entries(obj);
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
var LiveObject = function (_AbstractCrdt) {
|
|
1851
|
-
_inheritsLoose(LiveObject, _AbstractCrdt);
|
|
1852
|
-
|
|
1853
|
-
function LiveObject(object) {
|
|
1854
|
-
var _this;
|
|
1855
|
-
|
|
1856
|
-
if (object === void 0) {
|
|
1857
|
-
object = {};
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
_this = _AbstractCrdt.call(this) || this;
|
|
1861
|
-
_this._propToLastUpdate = new Map();
|
|
1862
|
-
|
|
1863
|
-
for (var key in object) {
|
|
1864
|
-
var value = object[key];
|
|
1865
|
-
|
|
1866
|
-
if (value instanceof AbstractCrdt) {
|
|
1867
|
-
value._setParentLink(_assertThisInitialized(_this), key);
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
_this._map = new Map(Object.entries(object));
|
|
1872
|
-
return _this;
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
var _proto = LiveObject.prototype;
|
|
1876
|
-
|
|
1877
|
-
_proto._serialize = function _serialize(parentId, parentKey, doc, intent) {
|
|
1878
|
-
if (this._id == null) {
|
|
1879
|
-
throw new Error("Cannot serialize item is not attached");
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
var ops = [];
|
|
1883
|
-
var op = {
|
|
1884
|
-
id: this._id,
|
|
1885
|
-
opId: doc == null ? void 0 : doc.generateOpId(),
|
|
1886
|
-
intent: intent,
|
|
1887
|
-
type: OpType.CreateObject,
|
|
1888
|
-
parentId: parentId,
|
|
1889
|
-
parentKey: parentKey,
|
|
1890
|
-
data: {}
|
|
1891
|
-
};
|
|
1892
|
-
ops.push(op);
|
|
1893
|
-
|
|
1894
|
-
for (var _iterator = _createForOfIteratorHelperLoose(this._map), _step; !(_step = _iterator()).done;) {
|
|
1895
|
-
var _step$value = _step.value,
|
|
1896
|
-
key = _step$value[0],
|
|
1897
|
-
value = _step$value[1];
|
|
1898
|
-
|
|
1899
|
-
if (value instanceof AbstractCrdt) {
|
|
1900
|
-
ops.push.apply(ops, value._serialize(this._id, key, doc));
|
|
1901
|
-
} else {
|
|
1902
|
-
op.data[key] = value;
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
return ops;
|
|
1907
|
-
};
|
|
1908
|
-
|
|
1909
|
-
LiveObject._deserialize = function _deserialize(_ref, parentToChildren, doc) {
|
|
1910
|
-
var id = _ref[0],
|
|
1911
|
-
item = _ref[1];
|
|
1912
|
-
|
|
1913
|
-
if (item.type !== CrdtType.Object) {
|
|
1914
|
-
throw new Error("Tried to deserialize a record but item type is \"" + item.type + "\"");
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
var object = new LiveObject(item.data);
|
|
1918
|
-
|
|
1919
|
-
object._attach(id, doc);
|
|
1920
|
-
|
|
1921
|
-
return this._deserializeChildren(object, parentToChildren, doc);
|
|
1922
|
-
};
|
|
1923
|
-
|
|
1924
|
-
LiveObject._deserializeChildren = function _deserializeChildren(object, parentToChildren, doc) {
|
|
1925
|
-
var children = parentToChildren.get(object._id);
|
|
1926
|
-
|
|
1927
|
-
if (children == null) {
|
|
1928
|
-
return object;
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1931
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(children), _step2; !(_step2 = _iterator2()).done;) {
|
|
1932
|
-
var entry = _step2.value;
|
|
1933
|
-
var crdt = entry[1];
|
|
1934
|
-
|
|
1935
|
-
if (crdt.parentKey == null) {
|
|
1936
|
-
throw new Error("Tried to deserialize a crdt but it does not have a parentKey and is not the root");
|
|
1937
|
-
}
|
|
1938
|
-
|
|
1939
|
-
var child = deserialize(entry, parentToChildren, doc);
|
|
1940
|
-
|
|
1941
|
-
child._setParentLink(object, crdt.parentKey);
|
|
1942
|
-
|
|
1943
|
-
object._map.set(crdt.parentKey, child);
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
return object;
|
|
1947
|
-
};
|
|
1948
|
-
|
|
1949
|
-
_proto._attach = function _attach(id, doc) {
|
|
1950
|
-
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1951
|
-
|
|
1952
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(this._map), _step3; !(_step3 = _iterator3()).done;) {
|
|
1953
|
-
var _step3$value = _step3.value;
|
|
1954
|
-
_step3$value[0];
|
|
1955
|
-
var value = _step3$value[1];
|
|
1956
|
-
|
|
1957
|
-
if (value instanceof AbstractCrdt) {
|
|
1958
|
-
value._attach(doc.generateId(), doc);
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
};
|
|
1962
|
-
|
|
1963
|
-
_proto._attachChild = function _attachChild(op, isLocal) {
|
|
1964
|
-
var _updates;
|
|
1965
|
-
|
|
1966
|
-
if (this._doc == null) {
|
|
1967
|
-
throw new Error("Can't attach child if doc is not present");
|
|
1968
|
-
}
|
|
1969
|
-
|
|
1970
|
-
var id = op.id,
|
|
1971
|
-
parentKey = op.parentKey,
|
|
1972
|
-
opId = op.opId;
|
|
1973
|
-
var key = parentKey;
|
|
1974
|
-
var child = creationOpToLiveStructure(op);
|
|
1975
|
-
|
|
1976
|
-
if (this._doc.getItem(id) !== undefined) {
|
|
1977
|
-
if (this._propToLastUpdate.get(key) === opId) {
|
|
1978
|
-
this._propToLastUpdate.delete(key);
|
|
1979
|
-
}
|
|
1980
|
-
|
|
1981
|
-
return {
|
|
1982
|
-
modified: false
|
|
1983
|
-
};
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
if (isLocal) {
|
|
1987
|
-
this._propToLastUpdate.set(key, opId);
|
|
1988
|
-
} else if (this._propToLastUpdate.get(key) === undefined) ; else if (this._propToLastUpdate.get(key) === opId) {
|
|
1989
|
-
this._propToLastUpdate.delete(key);
|
|
1990
|
-
|
|
1991
|
-
return {
|
|
1992
|
-
modified: false
|
|
1993
|
-
};
|
|
1994
|
-
} else {
|
|
1995
|
-
return {
|
|
1996
|
-
modified: false
|
|
1997
|
-
};
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
var previousValue = this._map.get(key);
|
|
2001
|
-
|
|
2002
|
-
var reverse;
|
|
2003
|
-
|
|
2004
|
-
if (isCrdt(previousValue)) {
|
|
2005
|
-
reverse = previousValue._serialize(this._id, key);
|
|
2006
|
-
|
|
2007
|
-
previousValue._detach();
|
|
2008
|
-
} else if (previousValue === undefined) {
|
|
2009
|
-
reverse = [{
|
|
2010
|
-
type: OpType.DeleteObjectKey,
|
|
2011
|
-
id: this._id,
|
|
2012
|
-
key: key
|
|
2013
|
-
}];
|
|
2014
|
-
} else {
|
|
2015
|
-
var _data;
|
|
2016
|
-
|
|
2017
|
-
reverse = [{
|
|
2018
|
-
type: OpType.UpdateObject,
|
|
2019
|
-
id: this._id,
|
|
2020
|
-
data: (_data = {}, _data[key] = previousValue, _data)
|
|
2021
|
-
}];
|
|
2022
|
-
}
|
|
2023
|
-
|
|
2024
|
-
this._map.set(key, child);
|
|
2025
|
-
|
|
2026
|
-
child._setParentLink(this, key);
|
|
2027
|
-
|
|
2028
|
-
child._attach(id, this._doc);
|
|
2029
|
-
|
|
2030
|
-
return {
|
|
2031
|
-
reverse: reverse,
|
|
2032
|
-
modified: {
|
|
2033
|
-
node: this,
|
|
2034
|
-
type: "LiveObject",
|
|
2035
|
-
updates: (_updates = {}, _updates[key] = {
|
|
2036
|
-
type: "update"
|
|
2037
|
-
}, _updates)
|
|
2038
|
-
}
|
|
2039
|
-
};
|
|
2040
|
-
};
|
|
2041
|
-
|
|
2042
|
-
_proto._detachChild = function _detachChild(child) {
|
|
2043
|
-
if (child) {
|
|
2044
|
-
var _updates2;
|
|
2045
|
-
|
|
2046
|
-
var reverse = child._serialize(this._id, child._parentKey, this._doc);
|
|
2047
|
-
|
|
2048
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(this._map), _step4; !(_step4 = _iterator4()).done;) {
|
|
2049
|
-
var _step4$value = _step4.value,
|
|
2050
|
-
key = _step4$value[0],
|
|
2051
|
-
value = _step4$value[1];
|
|
2052
|
-
|
|
2053
|
-
if (value === child) {
|
|
2054
|
-
this._map.delete(key);
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
child._detach();
|
|
2059
|
-
|
|
2060
|
-
var storageUpdate = {
|
|
2061
|
-
node: this,
|
|
2062
|
-
type: "LiveObject",
|
|
2063
|
-
updates: (_updates2 = {}, _updates2[child._parentKey] = {
|
|
2064
|
-
type: "delete"
|
|
2065
|
-
}, _updates2)
|
|
2066
|
-
};
|
|
2067
|
-
return {
|
|
2068
|
-
modified: storageUpdate,
|
|
2069
|
-
reverse: reverse
|
|
2070
|
-
};
|
|
2071
|
-
}
|
|
2072
|
-
|
|
2073
|
-
return {
|
|
2074
|
-
modified: false
|
|
2075
|
-
};
|
|
2076
|
-
};
|
|
2077
|
-
|
|
2078
|
-
_proto._detachChildren = function _detachChildren() {
|
|
2079
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(this._map), _step5; !(_step5 = _iterator5()).done;) {
|
|
2080
|
-
var _step5$value = _step5.value,
|
|
2081
|
-
key = _step5$value[0],
|
|
2082
|
-
value = _step5$value[1];
|
|
2083
|
-
|
|
2084
|
-
this._map.delete(key);
|
|
2085
|
-
|
|
2086
|
-
value._detach();
|
|
2087
|
-
}
|
|
2088
|
-
};
|
|
2089
|
-
|
|
2090
|
-
_proto._detach = function _detach() {
|
|
2091
|
-
_AbstractCrdt.prototype._detach.call(this);
|
|
2092
|
-
|
|
2093
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(this._map.values()), _step6; !(_step6 = _iterator6()).done;) {
|
|
2094
|
-
var value = _step6.value;
|
|
2095
|
-
|
|
2096
|
-
if (isCrdt(value)) {
|
|
2097
|
-
value._detach();
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
};
|
|
2101
|
-
|
|
2102
|
-
_proto._apply = function _apply(op, isLocal) {
|
|
2103
|
-
if (op.type === OpType.UpdateObject) {
|
|
2104
|
-
return this._applyUpdate(op, isLocal);
|
|
2105
|
-
} else if (op.type === OpType.DeleteObjectKey) {
|
|
2106
|
-
return this._applyDeleteObjectKey(op);
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
2110
|
-
};
|
|
2111
|
-
|
|
2112
|
-
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
2113
|
-
var _this$_parent;
|
|
2114
|
-
|
|
2115
|
-
var data = {};
|
|
2116
|
-
|
|
2117
|
-
for (var _iterator7 = _createForOfIteratorHelperLoose(this._map), _step7; !(_step7 = _iterator7()).done;) {
|
|
2118
|
-
var _step7$value = _step7.value,
|
|
2119
|
-
key = _step7$value[0],
|
|
2120
|
-
value = _step7$value[1];
|
|
2121
|
-
|
|
2122
|
-
if (value instanceof AbstractCrdt === false) {
|
|
2123
|
-
data[key] = value;
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
return {
|
|
2128
|
-
type: CrdtType.Object,
|
|
2129
|
-
parentId: (_this$_parent = this._parent) == null ? void 0 : _this$_parent._id,
|
|
2130
|
-
parentKey: this._parentKey,
|
|
2131
|
-
data: data
|
|
2132
|
-
};
|
|
2133
|
-
};
|
|
2134
|
-
|
|
2135
|
-
_proto._applyUpdate = function _applyUpdate(op, isLocal) {
|
|
2136
|
-
var isModified = false;
|
|
2137
|
-
var reverse = [];
|
|
2138
|
-
var reverseUpdate = {
|
|
2139
|
-
type: OpType.UpdateObject,
|
|
2140
|
-
id: this._id,
|
|
2141
|
-
data: {}
|
|
2142
|
-
};
|
|
2143
|
-
reverse.push(reverseUpdate);
|
|
2144
|
-
|
|
2145
|
-
for (var key in op.data) {
|
|
2146
|
-
var oldValue = this._map.get(key);
|
|
2147
|
-
|
|
2148
|
-
if (oldValue instanceof AbstractCrdt) {
|
|
2149
|
-
reverse.push.apply(reverse, oldValue._serialize(this._id, key));
|
|
2150
|
-
|
|
2151
|
-
oldValue._detach();
|
|
2152
|
-
} else if (oldValue !== undefined) {
|
|
2153
|
-
reverseUpdate.data[key] = oldValue;
|
|
2154
|
-
} else if (oldValue === undefined) {
|
|
2155
|
-
reverse.push({
|
|
2156
|
-
type: OpType.DeleteObjectKey,
|
|
2157
|
-
id: this._id,
|
|
2158
|
-
key: key
|
|
2159
|
-
});
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
var updateDelta = {};
|
|
2164
|
-
|
|
2165
|
-
for (var _key2 in op.data) {
|
|
2166
|
-
if (isLocal) {
|
|
2167
|
-
this._propToLastUpdate.set(_key2, op.opId);
|
|
2168
|
-
} else if (this._propToLastUpdate.get(_key2) == null) {
|
|
2169
|
-
isModified = true;
|
|
2170
|
-
} else if (this._propToLastUpdate.get(_key2) === op.opId) {
|
|
2171
|
-
this._propToLastUpdate.delete(_key2);
|
|
2172
|
-
|
|
2173
|
-
continue;
|
|
2174
|
-
} else {
|
|
2175
|
-
continue;
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
var _oldValue = this._map.get(_key2);
|
|
2179
|
-
|
|
2180
|
-
if (isCrdt(_oldValue)) {
|
|
2181
|
-
_oldValue._detach();
|
|
2182
|
-
}
|
|
2183
|
-
|
|
2184
|
-
isModified = true;
|
|
2185
|
-
updateDelta[_key2] = {
|
|
2186
|
-
type: "update"
|
|
2187
|
-
};
|
|
2188
|
-
|
|
2189
|
-
this._map.set(_key2, op.data[_key2]);
|
|
2190
|
-
}
|
|
2191
|
-
|
|
2192
|
-
if (Object.keys(reverseUpdate.data).length !== 0) {
|
|
2193
|
-
reverse.unshift(reverseUpdate);
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
return isModified ? {
|
|
2197
|
-
modified: {
|
|
2198
|
-
node: this,
|
|
2199
|
-
type: "LiveObject",
|
|
2200
|
-
updates: updateDelta
|
|
2201
|
-
},
|
|
2202
|
-
reverse: reverse
|
|
2203
|
-
} : {
|
|
2204
|
-
modified: false
|
|
2205
|
-
};
|
|
2206
|
-
};
|
|
2207
|
-
|
|
2208
|
-
_proto._applyDeleteObjectKey = function _applyDeleteObjectKey(op) {
|
|
2209
|
-
var _updates3;
|
|
2210
|
-
|
|
2211
|
-
var key = op.key;
|
|
2212
|
-
|
|
2213
|
-
if (this._map.has(key) === false) {
|
|
2214
|
-
return {
|
|
2215
|
-
modified: false
|
|
2216
|
-
};
|
|
2217
|
-
}
|
|
2218
|
-
|
|
2219
|
-
if (this._propToLastUpdate.get(key) !== undefined) {
|
|
2220
|
-
return {
|
|
2221
|
-
modified: false
|
|
2222
|
-
};
|
|
2223
|
-
}
|
|
2224
|
-
|
|
2225
|
-
var oldValue = this._map.get(key);
|
|
2226
|
-
|
|
2227
|
-
var reverse = [];
|
|
2228
|
-
|
|
2229
|
-
if (isCrdt(oldValue)) {
|
|
2230
|
-
reverse = oldValue._serialize(this._id, op.key);
|
|
2231
|
-
|
|
2232
|
-
oldValue._detach();
|
|
2233
|
-
} else if (oldValue !== undefined) {
|
|
2234
|
-
var _data2;
|
|
2235
|
-
|
|
2236
|
-
reverse = [{
|
|
2237
|
-
type: OpType.UpdateObject,
|
|
2238
|
-
id: this._id,
|
|
2239
|
-
data: (_data2 = {}, _data2[key] = oldValue, _data2)
|
|
2240
|
-
}];
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
this._map.delete(key);
|
|
2244
|
-
|
|
2245
|
-
return {
|
|
2246
|
-
modified: {
|
|
2247
|
-
node: this,
|
|
2248
|
-
type: "LiveObject",
|
|
2249
|
-
updates: (_updates3 = {}, _updates3[op.key] = {
|
|
2250
|
-
type: "delete"
|
|
2251
|
-
}, _updates3)
|
|
2252
|
-
},
|
|
2253
|
-
reverse: reverse
|
|
2254
|
-
};
|
|
2255
|
-
};
|
|
2256
|
-
|
|
2257
|
-
_proto.toObject = function toObject() {
|
|
2258
|
-
return Object.fromEntries(this._map);
|
|
2259
|
-
};
|
|
2260
|
-
|
|
2261
|
-
_proto.set = function set(key, value) {
|
|
2262
|
-
var _this$update;
|
|
2263
|
-
|
|
2264
|
-
this.update((_this$update = {}, _this$update[key] = value, _this$update));
|
|
2265
|
-
};
|
|
2266
|
-
|
|
2267
|
-
_proto.get = function get(key) {
|
|
2268
|
-
return this._map.get(key);
|
|
2269
|
-
};
|
|
2270
|
-
|
|
2271
|
-
_proto.delete = function _delete(key) {
|
|
2272
|
-
var _updates4;
|
|
2273
|
-
|
|
2274
|
-
var keyAsString = key;
|
|
2275
|
-
|
|
2276
|
-
var oldValue = this._map.get(keyAsString);
|
|
2277
|
-
|
|
2278
|
-
if (oldValue === undefined) {
|
|
2279
|
-
return;
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
if (this._doc == null || this._id == null) {
|
|
2283
|
-
if (oldValue instanceof AbstractCrdt) {
|
|
2284
|
-
oldValue._detach();
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
this._map.delete(keyAsString);
|
|
2288
|
-
|
|
2289
|
-
return;
|
|
2290
|
-
}
|
|
2291
|
-
|
|
2292
|
-
var reverse;
|
|
2293
|
-
|
|
2294
|
-
if (oldValue instanceof AbstractCrdt) {
|
|
2295
|
-
oldValue._detach();
|
|
2296
|
-
|
|
2297
|
-
reverse = oldValue._serialize(this._id, keyAsString);
|
|
2298
|
-
} else {
|
|
2299
|
-
var _data3;
|
|
2300
|
-
|
|
2301
|
-
reverse = [{
|
|
2302
|
-
type: OpType.UpdateObject,
|
|
2303
|
-
data: (_data3 = {}, _data3[keyAsString] = oldValue, _data3),
|
|
2304
|
-
id: this._id
|
|
2305
|
-
}];
|
|
2306
|
-
}
|
|
2307
|
-
|
|
2308
|
-
this._map.delete(keyAsString);
|
|
2309
|
-
|
|
2310
|
-
var storageUpdates = new Map();
|
|
2311
|
-
storageUpdates.set(this._id, {
|
|
2312
|
-
node: this,
|
|
2313
|
-
type: "LiveObject",
|
|
2314
|
-
updates: (_updates4 = {}, _updates4[key] = {
|
|
2315
|
-
type: "delete"
|
|
2316
|
-
}, _updates4)
|
|
2317
|
-
});
|
|
2318
|
-
|
|
2319
|
-
this._doc.dispatch([{
|
|
2320
|
-
type: OpType.DeleteObjectKey,
|
|
2321
|
-
key: keyAsString,
|
|
2322
|
-
id: this._id,
|
|
2323
|
-
opId: this._doc.generateOpId()
|
|
2324
|
-
}], reverse, storageUpdates);
|
|
2325
|
-
};
|
|
2326
|
-
|
|
2327
|
-
_proto.update = function update(overrides) {
|
|
2328
|
-
var _this2 = this;
|
|
2329
|
-
|
|
2330
|
-
if (this._doc == null || this._id == null) {
|
|
2331
|
-
for (var key in overrides) {
|
|
2332
|
-
var oldValue = this._map.get(key);
|
|
2333
|
-
|
|
2334
|
-
if (oldValue instanceof AbstractCrdt) {
|
|
2335
|
-
oldValue._detach();
|
|
2336
|
-
}
|
|
2337
|
-
|
|
2338
|
-
var newValue = overrides[key];
|
|
2339
|
-
|
|
2340
|
-
if (newValue instanceof AbstractCrdt) {
|
|
2341
|
-
newValue._setParentLink(this, key);
|
|
2342
|
-
}
|
|
2343
|
-
|
|
2344
|
-
this._map.set(key, newValue);
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
return;
|
|
2348
|
-
}
|
|
2349
|
-
|
|
2350
|
-
var ops = [];
|
|
2351
|
-
var reverseOps = [];
|
|
2352
|
-
|
|
2353
|
-
var opId = this._doc.generateOpId();
|
|
2354
|
-
|
|
2355
|
-
var updatedProps = {};
|
|
2356
|
-
var reverseUpdateOp = {
|
|
2357
|
-
id: this._id,
|
|
2358
|
-
type: OpType.UpdateObject,
|
|
2359
|
-
data: {}
|
|
2360
|
-
};
|
|
2361
|
-
var updateDelta = {};
|
|
2362
|
-
|
|
2363
|
-
for (var _key3 in overrides) {
|
|
2364
|
-
var _oldValue2 = this._map.get(_key3);
|
|
2365
|
-
|
|
2366
|
-
if (_oldValue2 instanceof AbstractCrdt) {
|
|
2367
|
-
reverseOps.push.apply(reverseOps, _oldValue2._serialize(this._id, _key3));
|
|
2368
|
-
|
|
2369
|
-
_oldValue2._detach();
|
|
2370
|
-
} else if (_oldValue2 === undefined) {
|
|
2371
|
-
reverseOps.push({
|
|
2372
|
-
type: OpType.DeleteObjectKey,
|
|
2373
|
-
id: this._id,
|
|
2374
|
-
key: _key3
|
|
2375
|
-
});
|
|
2376
|
-
} else {
|
|
2377
|
-
reverseUpdateOp.data[_key3] = _oldValue2;
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
var _newValue = overrides[_key3];
|
|
2381
|
-
|
|
2382
|
-
if (_newValue instanceof AbstractCrdt) {
|
|
2383
|
-
_newValue._setParentLink(this, _key3);
|
|
2384
|
-
|
|
2385
|
-
_newValue._attach(this._doc.generateId(), this._doc);
|
|
2386
|
-
|
|
2387
|
-
var newAttachChildOps = _newValue._serialize(this._id, _key3, this._doc);
|
|
2388
|
-
|
|
2389
|
-
var createCrdtOp = newAttachChildOps.find(function (op) {
|
|
2390
|
-
return op.parentId === _this2._id;
|
|
2391
|
-
});
|
|
2392
|
-
|
|
2393
|
-
if (createCrdtOp) {
|
|
2394
|
-
this._propToLastUpdate.set(_key3, createCrdtOp.opId);
|
|
2395
|
-
}
|
|
2396
|
-
|
|
2397
|
-
ops.push.apply(ops, newAttachChildOps);
|
|
2398
|
-
} else {
|
|
2399
|
-
updatedProps[_key3] = _newValue;
|
|
2400
|
-
|
|
2401
|
-
this._propToLastUpdate.set(_key3, opId);
|
|
2402
|
-
}
|
|
2403
|
-
|
|
2404
|
-
this._map.set(_key3, _newValue);
|
|
2405
|
-
|
|
2406
|
-
updateDelta[_key3] = {
|
|
2407
|
-
type: "update"
|
|
2408
|
-
};
|
|
2409
|
-
}
|
|
2410
|
-
|
|
2411
|
-
if (Object.keys(reverseUpdateOp.data).length !== 0) {
|
|
2412
|
-
reverseOps.unshift(reverseUpdateOp);
|
|
2413
|
-
}
|
|
2414
|
-
|
|
2415
|
-
if (Object.keys(updatedProps).length !== 0) {
|
|
2416
|
-
ops.unshift({
|
|
2417
|
-
opId: opId,
|
|
2418
|
-
id: this._id,
|
|
2419
|
-
type: OpType.UpdateObject,
|
|
2420
|
-
data: updatedProps
|
|
2421
|
-
});
|
|
2422
|
-
}
|
|
2423
|
-
|
|
2424
|
-
var storageUpdates = new Map();
|
|
2425
|
-
storageUpdates.set(this._id, {
|
|
2426
|
-
node: this,
|
|
2427
|
-
type: "LiveObject",
|
|
2428
|
-
updates: updateDelta
|
|
2429
|
-
});
|
|
2430
|
-
|
|
2431
|
-
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
2432
|
-
};
|
|
2433
|
-
|
|
2434
|
-
return LiveObject;
|
|
2435
|
-
}(AbstractCrdt);
|
|
5
|
+
var LiveObject = require('./shared.js');
|
|
2436
6
|
|
|
2437
7
|
var BACKOFF_RETRY_DELAYS = [250, 500, 1000, 2000, 4000, 8000, 10000];
|
|
2438
8
|
var BACKOFF_RETRY_DELAYS_SLOW = [2000, 30000, 60000, 300000];
|
|
@@ -2455,7 +25,7 @@ function makeOthers(userMap) {
|
|
|
2455
25
|
|
|
2456
26
|
var users = Object.values(userMap).map(function (user) {
|
|
2457
27
|
user._hasReceivedInitialPresence;
|
|
2458
|
-
var publicKeys = _objectWithoutPropertiesLoose(user, ["_hasReceivedInitialPresence"]);
|
|
28
|
+
var publicKeys = LiveObject._objectWithoutPropertiesLoose(user, ["_hasReceivedInitialPresence"]);
|
|
2459
29
|
|
|
2460
30
|
return publicKeys;
|
|
2461
31
|
});
|
|
@@ -2478,7 +48,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2478
48
|
authenticate: function authenticate(auth, createWebSocket) {
|
|
2479
49
|
var token = state.token;
|
|
2480
50
|
|
|
2481
|
-
if (token && isTokenValid(token)) {
|
|
51
|
+
if (token && LiveObject.isTokenValid(token)) {
|
|
2482
52
|
var parsedToken = parseToken(token);
|
|
2483
53
|
var socket = createWebSocket(token);
|
|
2484
54
|
authenticationSuccess(parsedToken, socket);
|
|
@@ -2523,7 +93,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2523
93
|
function genericSubscribe(callback) {
|
|
2524
94
|
state.listeners.storage.push(callback);
|
|
2525
95
|
return function () {
|
|
2526
|
-
return remove(state.listeners.storage, callback);
|
|
96
|
+
return LiveObject.remove(state.listeners.storage, callback);
|
|
2527
97
|
};
|
|
2528
98
|
}
|
|
2529
99
|
|
|
@@ -2531,10 +101,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2531
101
|
var cb = function cb(updates) {
|
|
2532
102
|
var relatedUpdates = [];
|
|
2533
103
|
|
|
2534
|
-
for (var _iterator = _createForOfIteratorHelperLoose(updates), _step; !(_step = _iterator()).done;) {
|
|
104
|
+
for (var _iterator = LiveObject._createForOfIteratorHelperLoose(updates), _step; !(_step = _iterator()).done;) {
|
|
2535
105
|
var update = _step.value;
|
|
2536
106
|
|
|
2537
|
-
if (options != null && options.isDeep && isSameNodeOrChildOf(update.node, crdt)) {
|
|
107
|
+
if (options != null && options.isDeep && LiveObject.isSameNodeOrChildOf(update.node, crdt)) {
|
|
2538
108
|
relatedUpdates.push(update);
|
|
2539
109
|
} else if (update.node._id === crdt._id) {
|
|
2540
110
|
innerCallback(update.node);
|
|
@@ -2571,7 +141,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2571
141
|
var parentToChildren = new Map();
|
|
2572
142
|
var root = null;
|
|
2573
143
|
|
|
2574
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(items), _step2; !(_step2 = _iterator2()).done;) {
|
|
144
|
+
for (var _iterator2 = LiveObject._createForOfIteratorHelperLoose(items), _step2; !(_step2 = _iterator2()).done;) {
|
|
2575
145
|
var tuple = _step2.value;
|
|
2576
146
|
var parentId = tuple[1].parentId;
|
|
2577
147
|
|
|
@@ -2604,7 +174,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2604
174
|
state.items.forEach(function (liveCrdt, id) {
|
|
2605
175
|
currentItems.set(id, liveCrdt._toSerializedCrdt());
|
|
2606
176
|
});
|
|
2607
|
-
var ops = getTreesDiffOperations(currentItems, new Map(items));
|
|
177
|
+
var ops = LiveObject.getTreesDiffOperations(currentItems, new Map(items));
|
|
2608
178
|
var result = apply(ops, false);
|
|
2609
179
|
notify(result.updates);
|
|
2610
180
|
}
|
|
@@ -2614,7 +184,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2614
184
|
root = _buildRootAndParentTo[0],
|
|
2615
185
|
parentToChildren = _buildRootAndParentTo[1];
|
|
2616
186
|
|
|
2617
|
-
return LiveObject._deserialize(root, parentToChildren, {
|
|
187
|
+
return LiveObject.LiveObject._deserialize(root, parentToChildren, {
|
|
2618
188
|
getItem: getItem,
|
|
2619
189
|
addItem: addItem,
|
|
2620
190
|
deleteItem: deleteItem,
|
|
@@ -2658,7 +228,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2658
228
|
(_state$batch$ops = state.batch.ops).push.apply(_state$batch$ops, ops);
|
|
2659
229
|
|
|
2660
230
|
storageUpdates.forEach(function (value, key) {
|
|
2661
|
-
state.batch.updates.storageUpdates.set(key, mergeStorageUpdates(state.batch.updates.storageUpdates.get(key), value));
|
|
231
|
+
state.batch.updates.storageUpdates.set(key, LiveObject.mergeStorageUpdates(state.batch.updates.storageUpdates.get(key), value));
|
|
2662
232
|
});
|
|
2663
233
|
|
|
2664
234
|
(_state$batch$reverseO = state.batch.reverseOps).push.apply(_state$batch$reverseO, reverse);
|
|
@@ -2683,10 +253,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2683
253
|
if (otherEvents.length > 0) {
|
|
2684
254
|
state.others = makeOthers(state.users);
|
|
2685
255
|
|
|
2686
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(otherEvents), _step3; !(_step3 = _iterator3()).done;) {
|
|
256
|
+
for (var _iterator3 = LiveObject._createForOfIteratorHelperLoose(otherEvents), _step3; !(_step3 = _iterator3()).done;) {
|
|
2687
257
|
var event = _step3.value;
|
|
2688
258
|
|
|
2689
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(state.listeners.others), _step4; !(_step4 = _iterator4()).done;) {
|
|
259
|
+
for (var _iterator4 = LiveObject._createForOfIteratorHelperLoose(state.listeners.others), _step4; !(_step4 = _iterator4()).done;) {
|
|
2690
260
|
var _listener = _step4.value;
|
|
2691
261
|
|
|
2692
262
|
_listener(state.others, event);
|
|
@@ -2695,7 +265,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2695
265
|
}
|
|
2696
266
|
|
|
2697
267
|
if (presence) {
|
|
2698
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(state.listeners["my-presence"]), _step5; !(_step5 = _iterator5()).done;) {
|
|
268
|
+
for (var _iterator5 = LiveObject._createForOfIteratorHelperLoose(state.listeners["my-presence"]), _step5; !(_step5 = _iterator5()).done;) {
|
|
2699
269
|
var _listener2 = _step5.value;
|
|
2700
270
|
|
|
2701
271
|
_listener2(state.me);
|
|
@@ -2703,7 +273,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2703
273
|
}
|
|
2704
274
|
|
|
2705
275
|
if (storageUpdates.size > 0) {
|
|
2706
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(state.listeners.storage), _step6; !(_step6 = _iterator6()).done;) {
|
|
276
|
+
for (var _iterator6 = LiveObject._createForOfIteratorHelperLoose(state.listeners.storage), _step6; !(_step6 = _iterator6()).done;) {
|
|
2707
277
|
var subscriber = _step6.value;
|
|
2708
278
|
subscriber(Array.from(storageUpdates.values()));
|
|
2709
279
|
}
|
|
@@ -2736,8 +306,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2736
306
|
presence: false
|
|
2737
307
|
}
|
|
2738
308
|
};
|
|
309
|
+
var createdNodeIds = new Set();
|
|
2739
310
|
|
|
2740
|
-
for (var _iterator7 = _createForOfIteratorHelperLoose(item), _step7; !(_step7 = _iterator7()).done;) {
|
|
311
|
+
for (var _iterator7 = LiveObject._createForOfIteratorHelperLoose(item), _step7; !(_step7 = _iterator7()).done;) {
|
|
2741
312
|
var op = _step7.value;
|
|
2742
313
|
|
|
2743
314
|
if (op.type === "presence") {
|
|
@@ -2750,13 +321,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2750
321
|
reverse.data[_key2] = state.me[_key2];
|
|
2751
322
|
}
|
|
2752
323
|
|
|
2753
|
-
state.me = _extends({}, state.me, op.data);
|
|
324
|
+
state.me = LiveObject._extends({}, state.me, op.data);
|
|
2754
325
|
|
|
2755
326
|
if (state.buffer.presence == null) {
|
|
2756
327
|
state.buffer.presence = op.data;
|
|
2757
328
|
} else {
|
|
2758
329
|
for (var _key3 in op.data) {
|
|
2759
|
-
state.buffer.presence[_key3] = op.data;
|
|
330
|
+
state.buffer.presence[_key3] = op.data[_key3];
|
|
2760
331
|
}
|
|
2761
332
|
}
|
|
2762
333
|
|
|
@@ -2770,11 +341,21 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2770
341
|
var applyOpResult = applyOp(op, isLocal);
|
|
2771
342
|
|
|
2772
343
|
if (applyOpResult.modified) {
|
|
2773
|
-
var
|
|
344
|
+
var _applyOpResult$modifi;
|
|
2774
345
|
|
|
2775
|
-
|
|
346
|
+
var parentId = (_applyOpResult$modifi = applyOpResult.modified.node._parent) == null ? void 0 : _applyOpResult$modifi._id;
|
|
2776
347
|
|
|
2777
|
-
(
|
|
348
|
+
if (!createdNodeIds.has(parentId)) {
|
|
349
|
+
var _result$reverse;
|
|
350
|
+
|
|
351
|
+
result.updates.storageUpdates.set(applyOpResult.modified.node._id, LiveObject.mergeStorageUpdates(result.updates.storageUpdates.get(applyOpResult.modified.node._id), applyOpResult.modified));
|
|
352
|
+
|
|
353
|
+
(_result$reverse = result.reverse).unshift.apply(_result$reverse, applyOpResult.reverse);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (op.type === LiveObject.OpType.CreateList || op.type === LiveObject.OpType.CreateMap || op.type === LiveObject.OpType.CreateObject) {
|
|
357
|
+
createdNodeIds.add(applyOpResult.modified.node._id);
|
|
358
|
+
}
|
|
2778
359
|
}
|
|
2779
360
|
}
|
|
2780
361
|
}
|
|
@@ -2788,9 +369,9 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2788
369
|
}
|
|
2789
370
|
|
|
2790
371
|
switch (op.type) {
|
|
2791
|
-
case OpType.DeleteObjectKey:
|
|
2792
|
-
case OpType.UpdateObject:
|
|
2793
|
-
case OpType.DeleteCrdt:
|
|
372
|
+
case LiveObject.OpType.DeleteObjectKey:
|
|
373
|
+
case LiveObject.OpType.UpdateObject:
|
|
374
|
+
case LiveObject.OpType.DeleteCrdt:
|
|
2794
375
|
{
|
|
2795
376
|
var item = state.items.get(op.id);
|
|
2796
377
|
|
|
@@ -2803,7 +384,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2803
384
|
return item._apply(op, isLocal);
|
|
2804
385
|
}
|
|
2805
386
|
|
|
2806
|
-
case OpType.SetParentKey:
|
|
387
|
+
case LiveObject.OpType.SetParentKey:
|
|
2807
388
|
{
|
|
2808
389
|
var _item = state.items.get(op.id);
|
|
2809
390
|
|
|
@@ -2813,7 +394,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2813
394
|
};
|
|
2814
395
|
}
|
|
2815
396
|
|
|
2816
|
-
if (_item._parent instanceof LiveList) {
|
|
397
|
+
if (_item._parent instanceof LiveObject.LiveList) {
|
|
2817
398
|
var previousKey = _item._parentKey;
|
|
2818
399
|
|
|
2819
400
|
if (previousKey === op.parentKey) {
|
|
@@ -2830,10 +411,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2830
411
|
};
|
|
2831
412
|
}
|
|
2832
413
|
|
|
2833
|
-
case OpType.CreateObject:
|
|
2834
|
-
case OpType.CreateList:
|
|
2835
|
-
case OpType.CreateMap:
|
|
2836
|
-
case OpType.CreateRegister:
|
|
414
|
+
case LiveObject.OpType.CreateObject:
|
|
415
|
+
case LiveObject.OpType.CreateList:
|
|
416
|
+
case LiveObject.OpType.CreateMap:
|
|
417
|
+
case LiveObject.OpType.CreateRegister:
|
|
2837
418
|
{
|
|
2838
419
|
var parent = state.items.get(op.parentId);
|
|
2839
420
|
|
|
@@ -2846,14 +427,10 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2846
427
|
return parent._attachChild(op, isLocal);
|
|
2847
428
|
}
|
|
2848
429
|
}
|
|
2849
|
-
|
|
2850
|
-
return {
|
|
2851
|
-
modified: false
|
|
2852
|
-
};
|
|
2853
430
|
}
|
|
2854
431
|
|
|
2855
432
|
function subscribe(firstParam, listener, options) {
|
|
2856
|
-
if (firstParam instanceof AbstractCrdt) {
|
|
433
|
+
if (firstParam instanceof LiveObject.AbstractCrdt) {
|
|
2857
434
|
return crdtSubscribe(firstParam, listener, options);
|
|
2858
435
|
} else if (typeof firstParam === "function") {
|
|
2859
436
|
return genericSubscribe(firstParam);
|
|
@@ -2864,7 +441,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2864
441
|
state.listeners[firstParam].push(listener);
|
|
2865
442
|
return function () {
|
|
2866
443
|
var callbacks = state.listeners[firstParam];
|
|
2867
|
-
remove(callbacks, listener);
|
|
444
|
+
LiveObject.remove(callbacks, listener);
|
|
2868
445
|
};
|
|
2869
446
|
}
|
|
2870
447
|
|
|
@@ -2876,7 +453,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2876
453
|
}
|
|
2877
454
|
|
|
2878
455
|
var callbacks = state.listeners[event];
|
|
2879
|
-
remove(callbacks, callback);
|
|
456
|
+
LiveObject.remove(callbacks, callback);
|
|
2880
457
|
}
|
|
2881
458
|
|
|
2882
459
|
function getConnectionState() {
|
|
@@ -2917,7 +494,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2917
494
|
oldValues[_key4] = state.me[_key4];
|
|
2918
495
|
}
|
|
2919
496
|
|
|
2920
|
-
state.me = _extends({}, state.me, overrides);
|
|
497
|
+
state.me = LiveObject._extends({}, state.me, overrides);
|
|
2921
498
|
|
|
2922
499
|
if (state.isBatching) {
|
|
2923
500
|
if (options != null && options.addToHistory) {
|
|
@@ -2996,7 +573,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2996
573
|
id: user.id,
|
|
2997
574
|
info: user.info,
|
|
2998
575
|
connectionId: message.actor,
|
|
2999
|
-
presence: _extends({}, user.presence, message.data),
|
|
576
|
+
presence: LiveObject._extends({}, user.presence, message.data),
|
|
3000
577
|
_hasReceivedInitialPresence: true
|
|
3001
578
|
};
|
|
3002
579
|
}
|
|
@@ -3050,7 +627,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3050
627
|
}
|
|
3051
628
|
|
|
3052
629
|
function onEvent(message) {
|
|
3053
|
-
for (var _iterator8 = _createForOfIteratorHelperLoose(state.listeners.event), _step8; !(_step8 = _iterator8()).done;) {
|
|
630
|
+
for (var _iterator8 = LiveObject._createForOfIteratorHelperLoose(state.listeners.event), _step8; !(_step8 = _iterator8()).done;) {
|
|
3054
631
|
var _listener3 = _step8.value;
|
|
3055
632
|
|
|
3056
633
|
_listener3({
|
|
@@ -3070,7 +647,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3070
647
|
|
|
3071
648
|
if (state.me) {
|
|
3072
649
|
state.buffer.messages.push({
|
|
3073
|
-
type: ClientMessageType.UpdatePresence,
|
|
650
|
+
type: LiveObject.ClientMessageType.UpdatePresence,
|
|
3074
651
|
data: state.me,
|
|
3075
652
|
targetActor: message.actor
|
|
3076
653
|
});
|
|
@@ -3084,7 +661,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3084
661
|
}
|
|
3085
662
|
|
|
3086
663
|
function parseServerMessage(data) {
|
|
3087
|
-
if (!isJsonObject(data)) {
|
|
664
|
+
if (!LiveObject.isJsonObject(data)) {
|
|
3088
665
|
return null;
|
|
3089
666
|
}
|
|
3090
667
|
|
|
@@ -3092,16 +669,16 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3092
669
|
}
|
|
3093
670
|
|
|
3094
671
|
function parseServerMessages(text) {
|
|
3095
|
-
var data = parseJson(text);
|
|
672
|
+
var data = LiveObject.parseJson(text);
|
|
3096
673
|
|
|
3097
674
|
if (data === undefined) {
|
|
3098
675
|
return null;
|
|
3099
|
-
} else if (isJsonArray(data)) {
|
|
3100
|
-
return compact(data.map(function (item) {
|
|
676
|
+
} else if (LiveObject.isJsonArray(data)) {
|
|
677
|
+
return LiveObject.compact(data.map(function (item) {
|
|
3101
678
|
return parseServerMessage(item);
|
|
3102
679
|
}));
|
|
3103
680
|
} else {
|
|
3104
|
-
return compact([parseServerMessage(data)]);
|
|
681
|
+
return LiveObject.compact([parseServerMessage(data)]);
|
|
3105
682
|
}
|
|
3106
683
|
}
|
|
3107
684
|
|
|
@@ -3122,17 +699,17 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3122
699
|
others: []
|
|
3123
700
|
};
|
|
3124
701
|
|
|
3125
|
-
for (var _iterator9 = _createForOfIteratorHelperLoose(messages), _step9; !(_step9 = _iterator9()).done;) {
|
|
702
|
+
for (var _iterator9 = LiveObject._createForOfIteratorHelperLoose(messages), _step9; !(_step9 = _iterator9()).done;) {
|
|
3126
703
|
var message = _step9.value;
|
|
3127
704
|
|
|
3128
705
|
switch (message.type) {
|
|
3129
|
-
case ServerMessageType.UserJoined:
|
|
706
|
+
case LiveObject.ServerMessageType.UserJoined:
|
|
3130
707
|
{
|
|
3131
708
|
updates.others.push(onUserJoinedMessage(message));
|
|
3132
709
|
break;
|
|
3133
710
|
}
|
|
3134
711
|
|
|
3135
|
-
case ServerMessageType.UpdatePresence:
|
|
712
|
+
case LiveObject.ServerMessageType.UpdatePresence:
|
|
3136
713
|
{
|
|
3137
714
|
var othersPresenceUpdate = onUpdatePresenceMessage(message);
|
|
3138
715
|
|
|
@@ -3143,13 +720,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3143
720
|
break;
|
|
3144
721
|
}
|
|
3145
722
|
|
|
3146
|
-
case ServerMessageType.Event:
|
|
723
|
+
case LiveObject.ServerMessageType.Event:
|
|
3147
724
|
{
|
|
3148
725
|
onEvent(message);
|
|
3149
726
|
break;
|
|
3150
727
|
}
|
|
3151
728
|
|
|
3152
|
-
case ServerMessageType.UserLeft:
|
|
729
|
+
case LiveObject.ServerMessageType.UserLeft:
|
|
3153
730
|
{
|
|
3154
731
|
var _event = onUserLeftMessage(message);
|
|
3155
732
|
|
|
@@ -3160,13 +737,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3160
737
|
break;
|
|
3161
738
|
}
|
|
3162
739
|
|
|
3163
|
-
case ServerMessageType.RoomState:
|
|
740
|
+
case LiveObject.ServerMessageType.RoomState:
|
|
3164
741
|
{
|
|
3165
742
|
updates.others.push(onRoomStateMessage(message));
|
|
3166
743
|
break;
|
|
3167
744
|
}
|
|
3168
745
|
|
|
3169
|
-
case ServerMessageType.InitialStorageState:
|
|
746
|
+
case LiveObject.ServerMessageType.InitialStorageState:
|
|
3170
747
|
{
|
|
3171
748
|
var offlineOps = new Map(state.offlineOperations);
|
|
3172
749
|
createOrUpdateRootFromMessage(message);
|
|
@@ -3175,11 +752,11 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3175
752
|
break;
|
|
3176
753
|
}
|
|
3177
754
|
|
|
3178
|
-
case ServerMessageType.UpdateStorage:
|
|
755
|
+
case LiveObject.ServerMessageType.UpdateStorage:
|
|
3179
756
|
{
|
|
3180
757
|
var applyResult = apply(message.ops, false);
|
|
3181
758
|
applyResult.updates.storageUpdates.forEach(function (value, key) {
|
|
3182
|
-
updates.storageUpdates.set(key, mergeStorageUpdates(updates.storageUpdates.get(key), value));
|
|
759
|
+
updates.storageUpdates.set(key, LiveObject.mergeStorageUpdates(updates.storageUpdates.get(key), value));
|
|
3183
760
|
});
|
|
3184
761
|
break;
|
|
3185
762
|
}
|
|
@@ -3212,7 +789,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3212
789
|
});
|
|
3213
790
|
var error = new LiveblocksError(event.reason, event.code);
|
|
3214
791
|
|
|
3215
|
-
for (var _iterator10 = _createForOfIteratorHelperLoose(state.listeners.error), _step10; !(_step10 = _iterator10()).done;) {
|
|
792
|
+
for (var _iterator10 = LiveObject._createForOfIteratorHelperLoose(state.listeners.error), _step10; !(_step10 = _iterator10()).done;) {
|
|
3216
793
|
var _listener4 = _step10.value;
|
|
3217
794
|
|
|
3218
795
|
_listener4(error);
|
|
@@ -3230,7 +807,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3230
807
|
state: "unavailable"
|
|
3231
808
|
});
|
|
3232
809
|
state.timeoutHandles.reconnect = effects.scheduleReconnect(_delay);
|
|
3233
|
-
} else if (event.code === WebsocketCloseCodes.CLOSE_WITHOUT_RETRY) {
|
|
810
|
+
} else if (event.code === LiveObject.WebsocketCloseCodes.CLOSE_WITHOUT_RETRY) {
|
|
3234
811
|
updateConnection({
|
|
3235
812
|
state: "closed"
|
|
3236
813
|
});
|
|
@@ -3253,7 +830,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3253
830
|
function updateConnection(connection) {
|
|
3254
831
|
state.connection = connection;
|
|
3255
832
|
|
|
3256
|
-
for (var _iterator11 = _createForOfIteratorHelperLoose(state.listeners.connection), _step11; !(_step11 = _iterator11()).done;) {
|
|
833
|
+
for (var _iterator11 = LiveObject._createForOfIteratorHelperLoose(state.listeners.connection), _step11; !(_step11 = _iterator11()).done;) {
|
|
3257
834
|
var _listener5 = _step11.value;
|
|
3258
835
|
|
|
3259
836
|
_listener5(connection.state);
|
|
@@ -3279,7 +856,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3279
856
|
state.intervalHandles.heartbeat = effects.startHeartbeatInterval();
|
|
3280
857
|
|
|
3281
858
|
if (state.connection.state === "connecting") {
|
|
3282
|
-
updateConnection(_extends({}, state.connection, {
|
|
859
|
+
updateConnection(LiveObject._extends({}, state.connection, {
|
|
3283
860
|
state: "open"
|
|
3284
861
|
}));
|
|
3285
862
|
state.numberOfRetry = 0;
|
|
@@ -3293,7 +870,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3293
870
|
|
|
3294
871
|
if (state.root) {
|
|
3295
872
|
state.buffer.messages.push({
|
|
3296
|
-
type: ClientMessageType.FetchStorage
|
|
873
|
+
type: LiveObject.ClientMessageType.FetchStorage
|
|
3297
874
|
});
|
|
3298
875
|
}
|
|
3299
876
|
|
|
@@ -3351,7 +928,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3351
928
|
var ops = Array.from(offlineOps.values());
|
|
3352
929
|
var result = apply(ops, true);
|
|
3353
930
|
messages.push({
|
|
3354
|
-
type: ClientMessageType.UpdateStorage,
|
|
931
|
+
type: LiveObject.ClientMessageType.UpdateStorage,
|
|
3355
932
|
ops: ops
|
|
3356
933
|
});
|
|
3357
934
|
notify(result.updates);
|
|
@@ -3403,19 +980,19 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3403
980
|
|
|
3404
981
|
if (state.buffer.presence) {
|
|
3405
982
|
messages.push({
|
|
3406
|
-
type: ClientMessageType.UpdatePresence,
|
|
983
|
+
type: LiveObject.ClientMessageType.UpdatePresence,
|
|
3407
984
|
data: state.buffer.presence
|
|
3408
985
|
});
|
|
3409
986
|
}
|
|
3410
987
|
|
|
3411
|
-
for (var _iterator12 = _createForOfIteratorHelperLoose(state.buffer.messages), _step12; !(_step12 = _iterator12()).done;) {
|
|
988
|
+
for (var _iterator12 = LiveObject._createForOfIteratorHelperLoose(state.buffer.messages), _step12; !(_step12 = _iterator12()).done;) {
|
|
3412
989
|
var event = _step12.value;
|
|
3413
990
|
messages.push(event);
|
|
3414
991
|
}
|
|
3415
992
|
|
|
3416
993
|
if (state.buffer.storageOperations.length > 0) {
|
|
3417
994
|
messages.push({
|
|
3418
|
-
type: ClientMessageType.UpdateStorage,
|
|
995
|
+
type: LiveObject.ClientMessageType.UpdateStorage,
|
|
3419
996
|
ops: state.buffer.storageOperations
|
|
3420
997
|
});
|
|
3421
998
|
}
|
|
@@ -3479,7 +1056,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3479
1056
|
}
|
|
3480
1057
|
|
|
3481
1058
|
state.buffer.messages.push({
|
|
3482
|
-
type: ClientMessageType.ClientEvent,
|
|
1059
|
+
type: LiveObject.ClientMessageType.ClientEvent,
|
|
3483
1060
|
event: event
|
|
3484
1061
|
});
|
|
3485
1062
|
tryFlushing();
|
|
@@ -3507,7 +1084,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3507
1084
|
|
|
3508
1085
|
if (_getInitialStatePromise == null) {
|
|
3509
1086
|
state.buffer.messages.push({
|
|
3510
|
-
type: ClientMessageType.FetchStorage
|
|
1087
|
+
type: LiveObject.ClientMessageType.FetchStorage
|
|
3511
1088
|
});
|
|
3512
1089
|
tryFlushing();
|
|
3513
1090
|
_getInitialStatePromise = new Promise(function (resolve) {
|
|
@@ -3538,7 +1115,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3538
1115
|
notify(result.updates);
|
|
3539
1116
|
state.redoStack.push(result.reverse);
|
|
3540
1117
|
|
|
3541
|
-
for (var _iterator13 = _createForOfIteratorHelperLoose(historyItem), _step13; !(_step13 = _iterator13()).done;) {
|
|
1118
|
+
for (var _iterator13 = LiveObject._createForOfIteratorHelperLoose(historyItem), _step13; !(_step13 = _iterator13()).done;) {
|
|
3542
1119
|
var op = _step13.value;
|
|
3543
1120
|
|
|
3544
1121
|
if (op.type !== "presence") {
|
|
@@ -3565,7 +1142,7 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3565
1142
|
notify(result.updates);
|
|
3566
1143
|
state.undoStack.push(result.reverse);
|
|
3567
1144
|
|
|
3568
|
-
for (var _iterator14 = _createForOfIteratorHelperLoose(historyItem), _step14; !(_step14 = _iterator14()).done;) {
|
|
1145
|
+
for (var _iterator14 = LiveObject._createForOfIteratorHelperLoose(historyItem), _step14; !(_step14 = _iterator14()).done;) {
|
|
3569
1146
|
var op = _step14.value;
|
|
3570
1147
|
|
|
3571
1148
|
if (op.type !== "presence") {
|
|
@@ -3769,7 +1346,7 @@ function createRoom(options, context) {
|
|
|
3769
1346
|
}
|
|
3770
1347
|
|
|
3771
1348
|
var LiveblocksError = function (_Error) {
|
|
3772
|
-
_inheritsLoose(LiveblocksError, _Error);
|
|
1349
|
+
LiveObject._inheritsLoose(LiveblocksError, _Error);
|
|
3773
1350
|
|
|
3774
1351
|
function LiveblocksError(message, code) {
|
|
3775
1352
|
var _this;
|
|
@@ -3780,7 +1357,7 @@ var LiveblocksError = function (_Error) {
|
|
|
3780
1357
|
}
|
|
3781
1358
|
|
|
3782
1359
|
return LiveblocksError;
|
|
3783
|
-
}(_wrapNativeSuper(Error));
|
|
1360
|
+
}(LiveObject._wrapNativeSuper(Error));
|
|
3784
1361
|
|
|
3785
1362
|
function parseToken(token) {
|
|
3786
1363
|
var tokenParts = token.split(".");
|
|
@@ -3789,9 +1366,9 @@ function parseToken(token) {
|
|
|
3789
1366
|
throw new Error("Authentication error. Liveblocks could not parse the response of your authentication endpoint");
|
|
3790
1367
|
}
|
|
3791
1368
|
|
|
3792
|
-
var data = parseJson(atob(tokenParts[1]));
|
|
1369
|
+
var data = LiveObject.parseJson(atob(tokenParts[1]));
|
|
3793
1370
|
|
|
3794
|
-
if (data !== undefined && isJsonObject(data) && typeof data.actor === "number" && (data.id === undefined || typeof data.id === "string")) {
|
|
1371
|
+
if (data !== undefined && LiveObject.isJsonObject(data) && typeof data.actor === "number" && (data.id === undefined || typeof data.id === "string")) {
|
|
3795
1372
|
return {
|
|
3796
1373
|
actor: data.actor,
|
|
3797
1374
|
id: data.id,
|
|
@@ -3871,14 +1448,14 @@ function fetchAuthEndpoint(fetch, endpoint, body) {
|
|
|
3871
1448
|
}
|
|
3872
1449
|
|
|
3873
1450
|
var AuthenticationError = function (_Error2) {
|
|
3874
|
-
_inheritsLoose(AuthenticationError, _Error2);
|
|
1451
|
+
LiveObject._inheritsLoose(AuthenticationError, _Error2);
|
|
3875
1452
|
|
|
3876
1453
|
function AuthenticationError(message) {
|
|
3877
1454
|
return _Error2.call(this, message) || this;
|
|
3878
1455
|
}
|
|
3879
1456
|
|
|
3880
1457
|
return AuthenticationError;
|
|
3881
|
-
}(_wrapNativeSuper(Error));
|
|
1458
|
+
}(LiveObject._wrapNativeSuper(Error));
|
|
3882
1459
|
|
|
3883
1460
|
function createClient(options) {
|
|
3884
1461
|
var clientOptions = options;
|
|
@@ -3932,7 +1509,7 @@ function createClient(options) {
|
|
|
3932
1509
|
|
|
3933
1510
|
if (typeof window !== "undefined") {
|
|
3934
1511
|
window.addEventListener("online", function () {
|
|
3935
|
-
for (var _iterator = _createForOfIteratorHelperLoose(rooms), _step; !(_step = _iterator()).done;) {
|
|
1512
|
+
for (var _iterator = LiveObject._createForOfIteratorHelperLoose(rooms), _step; !(_step = _iterator()).done;) {
|
|
3936
1513
|
var _step$value = _step.value,
|
|
3937
1514
|
room = _step$value[1];
|
|
3938
1515
|
room.onNavigatorOnline();
|
|
@@ -3942,7 +1519,7 @@ function createClient(options) {
|
|
|
3942
1519
|
|
|
3943
1520
|
if (typeof document !== "undefined") {
|
|
3944
1521
|
document.addEventListener("visibilitychange", function () {
|
|
3945
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(rooms), _step2; !(_step2 = _iterator2()).done;) {
|
|
1522
|
+
for (var _iterator2 = LiveObject._createForOfIteratorHelperLoose(rooms), _step2; !(_step2 = _iterator2()).done;) {
|
|
3946
1523
|
var _step2$value = _step2.value,
|
|
3947
1524
|
room = _step2$value[1];
|
|
3948
1525
|
room.onVisibilityChange(document.visibilityState);
|
|
@@ -4012,7 +1589,7 @@ function liveObjectToJson(liveObject) {
|
|
|
4012
1589
|
function liveMapToJson(map) {
|
|
4013
1590
|
var result = {};
|
|
4014
1591
|
|
|
4015
|
-
for (var _iterator = _createForOfIteratorHelperLoose(map.entries()), _step; !(_step = _iterator()).done;) {
|
|
1592
|
+
for (var _iterator = LiveObject._createForOfIteratorHelperLoose(map.entries()), _step; !(_step = _iterator()).done;) {
|
|
4016
1593
|
var _step$value = _step.value,
|
|
4017
1594
|
_key2 = _step$value[0],
|
|
4018
1595
|
value = _step$value[1];
|
|
@@ -4031,15 +1608,15 @@ function liveListToJson(value) {
|
|
|
4031
1608
|
}
|
|
4032
1609
|
|
|
4033
1610
|
function lsonToJson(value) {
|
|
4034
|
-
if (value instanceof LiveObject) {
|
|
1611
|
+
if (value instanceof LiveObject.LiveObject) {
|
|
4035
1612
|
return liveObjectToJson(value);
|
|
4036
|
-
} else if (value instanceof LiveList) {
|
|
1613
|
+
} else if (value instanceof LiveObject.LiveList) {
|
|
4037
1614
|
return liveListToJson(value);
|
|
4038
|
-
} else if (value instanceof LiveMap) {
|
|
1615
|
+
} else if (value instanceof LiveObject.LiveMap) {
|
|
4039
1616
|
return liveMapToJson(value);
|
|
4040
|
-
} else if (value instanceof LiveRegister) {
|
|
1617
|
+
} else if (value instanceof LiveObject.LiveRegister) {
|
|
4041
1618
|
return value.data;
|
|
4042
|
-
} else if (value instanceof AbstractCrdt) {
|
|
1619
|
+
} else if (value instanceof LiveObject.AbstractCrdt) {
|
|
4043
1620
|
throw new Error("Unhandled subclass of AbstractCrdt encountered");
|
|
4044
1621
|
}
|
|
4045
1622
|
|
|
@@ -4062,7 +1639,7 @@ function anyToCrdt(obj) {
|
|
|
4062
1639
|
}
|
|
4063
1640
|
|
|
4064
1641
|
if (Array.isArray(obj)) {
|
|
4065
|
-
return new LiveList(obj.map(anyToCrdt));
|
|
1642
|
+
return new LiveObject.LiveList(obj.map(anyToCrdt));
|
|
4066
1643
|
}
|
|
4067
1644
|
|
|
4068
1645
|
if (isPlainObject(obj)) {
|
|
@@ -4072,7 +1649,7 @@ function anyToCrdt(obj) {
|
|
|
4072
1649
|
init[_key3] = anyToCrdt(obj[_key3]);
|
|
4073
1650
|
}
|
|
4074
1651
|
|
|
4075
|
-
return new LiveObject(init);
|
|
1652
|
+
return new LiveObject.LiveObject(init);
|
|
4076
1653
|
}
|
|
4077
1654
|
|
|
4078
1655
|
return obj;
|
|
@@ -4133,7 +1710,7 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4133
1710
|
nextNode = next[i];
|
|
4134
1711
|
var liveListNode = liveList.get(i);
|
|
4135
1712
|
|
|
4136
|
-
if (liveListNode instanceof LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
1713
|
+
if (liveListNode instanceof LiveObject.LiveObject && isPlainObject(prevNode) && isPlainObject(nextNode)) {
|
|
4137
1714
|
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
4138
1715
|
} else {
|
|
4139
1716
|
liveList.set(i, anyToCrdt(nextNode));
|
|
@@ -4157,7 +1734,7 @@ function patchLiveList(liveList, prev, next) {
|
|
|
4157
1734
|
}
|
|
4158
1735
|
function patchLiveObjectKey(liveObject, key, prev, next) {
|
|
4159
1736
|
if (process.env.NODE_ENV !== "production") {
|
|
4160
|
-
var nonSerializableValue = findNonSerializableValue(next);
|
|
1737
|
+
var nonSerializableValue = LiveObject.findNonSerializableValue(next);
|
|
4161
1738
|
|
|
4162
1739
|
if (nonSerializableValue) {
|
|
4163
1740
|
console.error("New state path: '" + nonSerializableValue.path + "' value: '" + nonSerializableValue.value + "' is not serializable.\nOnly serializable value can be synced with Liveblocks.");
|
|
@@ -4173,9 +1750,9 @@ function patchLiveObjectKey(liveObject, key, prev, next) {
|
|
|
4173
1750
|
liveObject.set(key, anyToCrdt(next));
|
|
4174
1751
|
} else if (prev === next) {
|
|
4175
1752
|
return;
|
|
4176
|
-
} else if (value instanceof LiveList && Array.isArray(prev) && Array.isArray(next)) {
|
|
1753
|
+
} else if (value instanceof LiveObject.LiveList && Array.isArray(prev) && Array.isArray(next)) {
|
|
4177
1754
|
patchLiveList(value, prev, next);
|
|
4178
|
-
} else if (value instanceof LiveObject && isPlainObject(prev) && isPlainObject(next)) {
|
|
1755
|
+
} else if (value instanceof LiveObject.LiveObject && isPlainObject(prev) && isPlainObject(next)) {
|
|
4179
1756
|
patchLiveObject(value, prev, next);
|
|
4180
1757
|
} else {
|
|
4181
1758
|
liveObject.set(key, anyToCrdt(next));
|
|
@@ -4203,7 +1780,7 @@ function getParentsPath(node) {
|
|
|
4203
1780
|
var path = [];
|
|
4204
1781
|
|
|
4205
1782
|
while (node._parentKey != null && node._parent != null) {
|
|
4206
|
-
if (node._parent instanceof LiveList) {
|
|
1783
|
+
if (node._parent instanceof LiveObject.LiveList) {
|
|
4207
1784
|
path.push(node._parent._indexOfPosition(node._parentKey));
|
|
4208
1785
|
} else {
|
|
4209
1786
|
path.push(node._parentKey);
|
|
@@ -4290,7 +1867,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4290
1867
|
}
|
|
4291
1868
|
};
|
|
4292
1869
|
|
|
4293
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(update.updates), _step2; !(_step2 = _iterator2()).done;) {
|
|
1870
|
+
for (var _iterator2 = LiveObject._createForOfIteratorHelperLoose(update.updates), _step2; !(_step2 = _iterator2()).done;) {
|
|
4294
1871
|
_loop();
|
|
4295
1872
|
}
|
|
4296
1873
|
|
|
@@ -4327,7 +1904,7 @@ function patchImmutableNode(state, path, update) {
|
|
|
4327
1904
|
} else {
|
|
4328
1905
|
var _extends2;
|
|
4329
1906
|
|
|
4330
|
-
return _extends({}, state, (_extends2 = {}, _extends2[pathItem] = patchImmutableNode(state[pathItem], path, update), _extends2));
|
|
1907
|
+
return LiveObject._extends({}, state, (_extends2 = {}, _extends2[pathItem] = patchImmutableNode(state[pathItem], path, update), _extends2));
|
|
4331
1908
|
}
|
|
4332
1909
|
}
|
|
4333
1910
|
|
|
@@ -4340,8 +1917,8 @@ var internals = {
|
|
|
4340
1917
|
patchLiveObjectKey: patchLiveObjectKey
|
|
4341
1918
|
};
|
|
4342
1919
|
|
|
4343
|
-
exports.LiveList = LiveList;
|
|
4344
|
-
exports.LiveMap = LiveMap;
|
|
4345
|
-
exports.LiveObject = LiveObject;
|
|
1920
|
+
exports.LiveList = LiveObject.LiveList;
|
|
1921
|
+
exports.LiveMap = LiveObject.LiveMap;
|
|
1922
|
+
exports.LiveObject = LiveObject.LiveObject;
|
|
4346
1923
|
exports.createClient = createClient;
|
|
4347
1924
|
exports.internals = internals;
|