@liveblocks/client 0.17.7 → 0.17.10-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.built-by-link-script +1 -0
- package/chunk-QLMVHHAZ.js +3592 -0
- package/index-0007883d.d.ts +793 -0
- package/index.d.ts +7 -27
- package/index.js +2007 -1269
- package/index.mjs +1 -1114
- package/internal.d.ts +198 -307
- package/internal.js +526 -309
- package/internal.mjs +29 -281
- package/package.json +1 -1
- package/shared.d.ts +0 -855
- package/shared.js +0 -2655
- package/shared.mjs +0 -2069
package/shared.js
DELETED
|
@@ -1,2655 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function _defineProperties(target, props) {
|
|
3
|
-
for (var i = 0; i < props.length; i++) {
|
|
4
|
-
var descriptor = props[i];
|
|
5
|
-
(descriptor.enumerable = descriptor.enumerable || !1),
|
|
6
|
-
(descriptor.configurable = !0),
|
|
7
|
-
"value" in descriptor && (descriptor.writable = !0),
|
|
8
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
12
|
-
return (
|
|
13
|
-
protoProps && _defineProperties(Constructor.prototype, protoProps),
|
|
14
|
-
staticProps && _defineProperties(Constructor, staticProps),
|
|
15
|
-
Object.defineProperty(Constructor, "prototype", { writable: !1 }),
|
|
16
|
-
Constructor
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
function _extends() {
|
|
20
|
-
return (
|
|
21
|
-
(_extends =
|
|
22
|
-
Object.assign ||
|
|
23
|
-
function (target) {
|
|
24
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
25
|
-
var source = arguments[i];
|
|
26
|
-
for (var key in source)
|
|
27
|
-
Object.prototype.hasOwnProperty.call(source, key) &&
|
|
28
|
-
(target[key] = source[key]);
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
}),
|
|
32
|
-
_extends.apply(this, arguments)
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
function _inheritsLoose(subClass, superClass) {
|
|
36
|
-
(subClass.prototype = Object.create(superClass.prototype)),
|
|
37
|
-
(subClass.prototype.constructor = subClass),
|
|
38
|
-
_setPrototypeOf(subClass, superClass);
|
|
39
|
-
}
|
|
40
|
-
function _getPrototypeOf(o) {
|
|
41
|
-
return (
|
|
42
|
-
(_getPrototypeOf = Object.setPrototypeOf
|
|
43
|
-
? Object.getPrototypeOf
|
|
44
|
-
: function (o) {
|
|
45
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
46
|
-
}),
|
|
47
|
-
_getPrototypeOf(o)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
function _setPrototypeOf(o, p) {
|
|
51
|
-
return (
|
|
52
|
-
(_setPrototypeOf =
|
|
53
|
-
Object.setPrototypeOf ||
|
|
54
|
-
function (o, p) {
|
|
55
|
-
return (o.__proto__ = p), o;
|
|
56
|
-
}),
|
|
57
|
-
_setPrototypeOf(o, p)
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
function _isNativeReflectConstruct() {
|
|
61
|
-
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
|
|
62
|
-
if (Reflect.construct.sham) return !1;
|
|
63
|
-
if ("function" == typeof Proxy) return !0;
|
|
64
|
-
try {
|
|
65
|
-
return (
|
|
66
|
-
Boolean.prototype.valueOf.call(
|
|
67
|
-
Reflect.construct(Boolean, [], function () {})
|
|
68
|
-
),
|
|
69
|
-
!0
|
|
70
|
-
);
|
|
71
|
-
} catch (e) {
|
|
72
|
-
return !1;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function _construct(Parent, args, Class) {
|
|
76
|
-
return (
|
|
77
|
-
(_construct = _isNativeReflectConstruct()
|
|
78
|
-
? Reflect.construct
|
|
79
|
-
: function (Parent, args, Class) {
|
|
80
|
-
var a = [null];
|
|
81
|
-
a.push.apply(a, args);
|
|
82
|
-
var instance = new (Function.bind.apply(Parent, a))();
|
|
83
|
-
return Class && _setPrototypeOf(instance, Class.prototype), instance;
|
|
84
|
-
}),
|
|
85
|
-
_construct.apply(null, arguments)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
function _wrapNativeSuper(Class) {
|
|
89
|
-
var _cache = "function" == typeof Map ? new Map() : void 0;
|
|
90
|
-
return (
|
|
91
|
-
(_wrapNativeSuper = function (Class) {
|
|
92
|
-
if (
|
|
93
|
-
null === Class ||
|
|
94
|
-
((fn = Class),
|
|
95
|
-
-1 === Function.toString.call(fn).indexOf("[native code]"))
|
|
96
|
-
)
|
|
97
|
-
return Class;
|
|
98
|
-
var fn;
|
|
99
|
-
if ("function" != typeof Class)
|
|
100
|
-
throw new TypeError(
|
|
101
|
-
"Super expression must either be null or a function"
|
|
102
|
-
);
|
|
103
|
-
if (void 0 !== _cache) {
|
|
104
|
-
if (_cache.has(Class)) return _cache.get(Class);
|
|
105
|
-
_cache.set(Class, Wrapper);
|
|
106
|
-
}
|
|
107
|
-
function Wrapper() {
|
|
108
|
-
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
109
|
-
}
|
|
110
|
-
return (
|
|
111
|
-
(Wrapper.prototype = Object.create(Class.prototype, {
|
|
112
|
-
constructor: {
|
|
113
|
-
value: Wrapper,
|
|
114
|
-
enumerable: !1,
|
|
115
|
-
writable: !0,
|
|
116
|
-
configurable: !0,
|
|
117
|
-
},
|
|
118
|
-
})),
|
|
119
|
-
_setPrototypeOf(Wrapper, Class)
|
|
120
|
-
);
|
|
121
|
-
}),
|
|
122
|
-
_wrapNativeSuper(Class)
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
126
|
-
if (null == source) return {};
|
|
127
|
-
var key,
|
|
128
|
-
i,
|
|
129
|
-
target = {},
|
|
130
|
-
sourceKeys = Object.keys(source);
|
|
131
|
-
for (i = 0; i < sourceKeys.length; i++)
|
|
132
|
-
(key = sourceKeys[i]),
|
|
133
|
-
excluded.indexOf(key) >= 0 || (target[key] = source[key]);
|
|
134
|
-
return target;
|
|
135
|
-
}
|
|
136
|
-
function _assertThisInitialized(self) {
|
|
137
|
-
if (void 0 === self)
|
|
138
|
-
throw new ReferenceError(
|
|
139
|
-
"this hasn't been initialised - super() hasn't been called"
|
|
140
|
-
);
|
|
141
|
-
return self;
|
|
142
|
-
}
|
|
143
|
-
function _arrayLikeToArray(arr, len) {
|
|
144
|
-
(null == len || len > arr.length) && (len = arr.length);
|
|
145
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
146
|
-
return arr2;
|
|
147
|
-
}
|
|
148
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
149
|
-
var it =
|
|
150
|
-
("undefined" != typeof Symbol && o[Symbol.iterator]) || o["@@iterator"];
|
|
151
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
152
|
-
if (
|
|
153
|
-
Array.isArray(o) ||
|
|
154
|
-
(it = (function (o, minLen) {
|
|
155
|
-
if (o) {
|
|
156
|
-
if ("string" == typeof o) return _arrayLikeToArray(o, minLen);
|
|
157
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
158
|
-
return (
|
|
159
|
-
"Object" === n && o.constructor && (n = o.constructor.name),
|
|
160
|
-
"Map" === n || "Set" === n
|
|
161
|
-
? Array.from(o)
|
|
162
|
-
: "Arguments" === n ||
|
|
163
|
-
/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)
|
|
164
|
-
? _arrayLikeToArray(o, minLen)
|
|
165
|
-
: void 0
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
})(o)) ||
|
|
169
|
-
(allowArrayLike && o && "number" == typeof o.length)
|
|
170
|
-
) {
|
|
171
|
-
it && (o = it);
|
|
172
|
-
var i = 0;
|
|
173
|
-
return function () {
|
|
174
|
-
return i >= o.length ? { done: !0 } : { done: !1, value: o[i++] };
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
throw new TypeError(
|
|
178
|
-
"Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
var ClientMsgCode,
|
|
182
|
-
OpCode,
|
|
183
|
-
CrdtType,
|
|
184
|
-
ServerMsgCode,
|
|
185
|
-
WebsocketCloseCodes,
|
|
186
|
-
OpSource,
|
|
187
|
-
_emittedDeprecationWarnings = new Set();
|
|
188
|
-
function deprecate(message, key) {
|
|
189
|
-
void 0 === key && (key = message),
|
|
190
|
-
"production" !== process.env.NODE_ENV &&
|
|
191
|
-
(_emittedDeprecationWarnings.has(key) ||
|
|
192
|
-
(_emittedDeprecationWarnings.add(key),
|
|
193
|
-
console.error("DEPRECATION WARNING: " + message)));
|
|
194
|
-
}
|
|
195
|
-
function throwUsageError(message) {
|
|
196
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
197
|
-
var usageError = new Error(message);
|
|
198
|
-
throw ((usageError.name = "Usage error"), usageError);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function errorIf(condition, message) {
|
|
202
|
-
"production" !== process.env.NODE_ENV &&
|
|
203
|
-
condition &&
|
|
204
|
-
throwUsageError(message);
|
|
205
|
-
}
|
|
206
|
-
function assertNever(_value, errmsg) {
|
|
207
|
-
throw new Error(errmsg);
|
|
208
|
-
}
|
|
209
|
-
function nn(value, errmsg) {
|
|
210
|
-
return (
|
|
211
|
-
void 0 === errmsg && (errmsg = "Expected value to be non-nullable"),
|
|
212
|
-
(function (condition, errmsg) {
|
|
213
|
-
if ("production" !== process.env.NODE_ENV && !condition) {
|
|
214
|
-
var err = new Error(errmsg);
|
|
215
|
-
throw ((err.name = "Assertion failure"), err);
|
|
216
|
-
}
|
|
217
|
-
})(null != value, errmsg),
|
|
218
|
-
value
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
function isChildCrdt(crdt) {
|
|
222
|
-
return void 0 !== crdt.parentId && void 0 !== crdt.parentKey;
|
|
223
|
-
}
|
|
224
|
-
function HasParent(node, key) {
|
|
225
|
-
return Object.freeze({ type: "HasParent", node: node, key: key });
|
|
226
|
-
}
|
|
227
|
-
(exports.ClientMsgCode = void 0),
|
|
228
|
-
((ClientMsgCode = exports.ClientMsgCode || (exports.ClientMsgCode = {}))[
|
|
229
|
-
(ClientMsgCode.UPDATE_PRESENCE = 100)
|
|
230
|
-
] = "UPDATE_PRESENCE"),
|
|
231
|
-
(ClientMsgCode[(ClientMsgCode.BROADCAST_EVENT = 103)] = "BROADCAST_EVENT"),
|
|
232
|
-
(ClientMsgCode[(ClientMsgCode.FETCH_STORAGE = 200)] = "FETCH_STORAGE"),
|
|
233
|
-
(ClientMsgCode[(ClientMsgCode.UPDATE_STORAGE = 201)] = "UPDATE_STORAGE"),
|
|
234
|
-
(exports.OpCode = void 0),
|
|
235
|
-
((OpCode = exports.OpCode || (exports.OpCode = {}))[(OpCode.INIT = 0)] =
|
|
236
|
-
"INIT"),
|
|
237
|
-
(OpCode[(OpCode.SET_PARENT_KEY = 1)] = "SET_PARENT_KEY"),
|
|
238
|
-
(OpCode[(OpCode.CREATE_LIST = 2)] = "CREATE_LIST"),
|
|
239
|
-
(OpCode[(OpCode.UPDATE_OBJECT = 3)] = "UPDATE_OBJECT"),
|
|
240
|
-
(OpCode[(OpCode.CREATE_OBJECT = 4)] = "CREATE_OBJECT"),
|
|
241
|
-
(OpCode[(OpCode.DELETE_CRDT = 5)] = "DELETE_CRDT"),
|
|
242
|
-
(OpCode[(OpCode.DELETE_OBJECT_KEY = 6)] = "DELETE_OBJECT_KEY"),
|
|
243
|
-
(OpCode[(OpCode.CREATE_MAP = 7)] = "CREATE_MAP"),
|
|
244
|
-
(OpCode[(OpCode.CREATE_REGISTER = 8)] = "CREATE_REGISTER"),
|
|
245
|
-
(exports.CrdtType = void 0),
|
|
246
|
-
((CrdtType = exports.CrdtType || (exports.CrdtType = {}))[
|
|
247
|
-
(CrdtType.OBJECT = 0)
|
|
248
|
-
] = "OBJECT"),
|
|
249
|
-
(CrdtType[(CrdtType.LIST = 1)] = "LIST"),
|
|
250
|
-
(CrdtType[(CrdtType.MAP = 2)] = "MAP"),
|
|
251
|
-
(CrdtType[(CrdtType.REGISTER = 3)] = "REGISTER"),
|
|
252
|
-
(exports.ServerMsgCode = void 0),
|
|
253
|
-
((ServerMsgCode = exports.ServerMsgCode || (exports.ServerMsgCode = {}))[
|
|
254
|
-
(ServerMsgCode.UPDATE_PRESENCE = 100)
|
|
255
|
-
] = "UPDATE_PRESENCE"),
|
|
256
|
-
(ServerMsgCode[(ServerMsgCode.USER_JOINED = 101)] = "USER_JOINED"),
|
|
257
|
-
(ServerMsgCode[(ServerMsgCode.USER_LEFT = 102)] = "USER_LEFT"),
|
|
258
|
-
(ServerMsgCode[(ServerMsgCode.BROADCASTED_EVENT = 103)] =
|
|
259
|
-
"BROADCASTED_EVENT"),
|
|
260
|
-
(ServerMsgCode[(ServerMsgCode.ROOM_STATE = 104)] = "ROOM_STATE"),
|
|
261
|
-
(ServerMsgCode[(ServerMsgCode.INITIAL_STORAGE_STATE = 200)] =
|
|
262
|
-
"INITIAL_STORAGE_STATE"),
|
|
263
|
-
(ServerMsgCode[(ServerMsgCode.UPDATE_STORAGE = 201)] = "UPDATE_STORAGE"),
|
|
264
|
-
(exports.WebsocketCloseCodes = void 0),
|
|
265
|
-
((WebsocketCloseCodes =
|
|
266
|
-
exports.WebsocketCloseCodes || (exports.WebsocketCloseCodes = {}))[
|
|
267
|
-
(WebsocketCloseCodes.CLOSE_ABNORMAL = 1006)
|
|
268
|
-
] = "CLOSE_ABNORMAL"),
|
|
269
|
-
(WebsocketCloseCodes[(WebsocketCloseCodes.INVALID_MESSAGE_FORMAT = 4e3)] =
|
|
270
|
-
"INVALID_MESSAGE_FORMAT"),
|
|
271
|
-
(WebsocketCloseCodes[(WebsocketCloseCodes.NOT_ALLOWED = 4001)] =
|
|
272
|
-
"NOT_ALLOWED"),
|
|
273
|
-
(WebsocketCloseCodes[
|
|
274
|
-
(WebsocketCloseCodes.MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002)
|
|
275
|
-
] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS"),
|
|
276
|
-
(WebsocketCloseCodes[
|
|
277
|
-
(WebsocketCloseCodes.MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003)
|
|
278
|
-
] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"),
|
|
279
|
-
(WebsocketCloseCodes[
|
|
280
|
-
(WebsocketCloseCodes.MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004)
|
|
281
|
-
] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"),
|
|
282
|
-
(WebsocketCloseCodes[
|
|
283
|
-
(WebsocketCloseCodes.MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005)
|
|
284
|
-
] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"),
|
|
285
|
-
(WebsocketCloseCodes[(WebsocketCloseCodes.CLOSE_WITHOUT_RETRY = 4999)] =
|
|
286
|
-
"CLOSE_WITHOUT_RETRY"),
|
|
287
|
-
(exports.OpSource = void 0),
|
|
288
|
-
((OpSource = exports.OpSource || (exports.OpSource = {}))[
|
|
289
|
-
(OpSource.UNDOREDO_RECONNECT = 0)
|
|
290
|
-
] = "UNDOREDO_RECONNECT"),
|
|
291
|
-
(OpSource[(OpSource.REMOTE = 1)] = "REMOTE"),
|
|
292
|
-
(OpSource[(OpSource.ACK = 2)] = "ACK");
|
|
293
|
-
var NoParent = Object.freeze({ type: "NoParent" });
|
|
294
|
-
function Orphaned(oldKey) {
|
|
295
|
-
return Object.freeze({ type: "Orphaned", oldKey: oldKey });
|
|
296
|
-
}
|
|
297
|
-
var _Symbol$iterator$1,
|
|
298
|
-
_Symbol$iterator2,
|
|
299
|
-
AbstractCrdt = (function () {
|
|
300
|
-
function AbstractCrdt() {
|
|
301
|
-
(this.__doc = void 0), (this.__id = void 0), (this._parent = NoParent);
|
|
302
|
-
}
|
|
303
|
-
var _proto = AbstractCrdt.prototype;
|
|
304
|
-
return (
|
|
305
|
-
(_proto._getParentKeyOrThrow = function () {
|
|
306
|
-
switch (this.parent.type) {
|
|
307
|
-
case "HasParent":
|
|
308
|
-
return this.parent.key;
|
|
309
|
-
case "NoParent":
|
|
310
|
-
throw new Error("Parent key is missing");
|
|
311
|
-
case "Orphaned":
|
|
312
|
-
return this.parent.oldKey;
|
|
313
|
-
default:
|
|
314
|
-
return assertNever(this.parent, "Unknown state");
|
|
315
|
-
}
|
|
316
|
-
}),
|
|
317
|
-
(_proto._apply = function (op, _isLocal) {
|
|
318
|
-
return op.type === exports.OpCode.DELETE_CRDT &&
|
|
319
|
-
"HasParent" === this.parent.type
|
|
320
|
-
? this.parent.node._detachChild(this)
|
|
321
|
-
: { modified: !1 };
|
|
322
|
-
}),
|
|
323
|
-
(_proto._setParentLink = function (newParentNode, newParentKey) {
|
|
324
|
-
switch (this.parent.type) {
|
|
325
|
-
case "HasParent":
|
|
326
|
-
if (this.parent.node !== newParentNode)
|
|
327
|
-
throw new Error("Cannot attach parent if it already exist");
|
|
328
|
-
return void (this._parent = HasParent(newParentNode, newParentKey));
|
|
329
|
-
case "Orphaned":
|
|
330
|
-
case "NoParent":
|
|
331
|
-
return void (this._parent = HasParent(newParentNode, newParentKey));
|
|
332
|
-
default:
|
|
333
|
-
return assertNever(this.parent, "Unknown state");
|
|
334
|
-
}
|
|
335
|
-
}),
|
|
336
|
-
(_proto._attach = function (id, doc) {
|
|
337
|
-
if (this.__id || this.__doc)
|
|
338
|
-
throw new Error("Cannot attach if CRDT is already attached");
|
|
339
|
-
doc.addItem(id, this), (this.__id = id), (this.__doc = doc);
|
|
340
|
-
}),
|
|
341
|
-
(_proto._detach = function () {
|
|
342
|
-
switch (
|
|
343
|
-
(this.__doc && this.__id && this.__doc.deleteItem(this.__id),
|
|
344
|
-
this.parent.type)
|
|
345
|
-
) {
|
|
346
|
-
case "HasParent":
|
|
347
|
-
this._parent = Orphaned(this.parent.key);
|
|
348
|
-
break;
|
|
349
|
-
case "NoParent":
|
|
350
|
-
this._parent = NoParent;
|
|
351
|
-
break;
|
|
352
|
-
case "Orphaned":
|
|
353
|
-
this._parent = Orphaned(this.parent.oldKey);
|
|
354
|
-
break;
|
|
355
|
-
default:
|
|
356
|
-
assertNever(this.parent, "Unknown state");
|
|
357
|
-
}
|
|
358
|
-
this.__doc = void 0;
|
|
359
|
-
}),
|
|
360
|
-
_createClass(AbstractCrdt, [
|
|
361
|
-
{
|
|
362
|
-
key: "_doc",
|
|
363
|
-
get: function () {
|
|
364
|
-
return this.__doc;
|
|
365
|
-
},
|
|
366
|
-
},
|
|
367
|
-
{
|
|
368
|
-
key: "roomId",
|
|
369
|
-
get: function () {
|
|
370
|
-
return this.__doc ? this.__doc.roomId : null;
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
{
|
|
374
|
-
key: "_id",
|
|
375
|
-
get: function () {
|
|
376
|
-
return this.__id;
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
key: "parent",
|
|
381
|
-
get: function () {
|
|
382
|
-
return this._parent;
|
|
383
|
-
},
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
key: "_parentNode",
|
|
387
|
-
get: function () {
|
|
388
|
-
switch (this.parent.type) {
|
|
389
|
-
case "HasParent":
|
|
390
|
-
return this.parent.node;
|
|
391
|
-
case "NoParent":
|
|
392
|
-
case "Orphaned":
|
|
393
|
-
return null;
|
|
394
|
-
default:
|
|
395
|
-
return assertNever(this.parent, "Unknown state");
|
|
396
|
-
}
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
key: "_parentKey",
|
|
401
|
-
get: function () {
|
|
402
|
-
switch (this.parent.type) {
|
|
403
|
-
case "HasParent":
|
|
404
|
-
return this.parent.key;
|
|
405
|
-
case "NoParent":
|
|
406
|
-
return null;
|
|
407
|
-
case "Orphaned":
|
|
408
|
-
return this.parent.oldKey;
|
|
409
|
-
default:
|
|
410
|
-
return assertNever(this.parent, "Unknown state");
|
|
411
|
-
}
|
|
412
|
-
},
|
|
413
|
-
},
|
|
414
|
-
]),
|
|
415
|
-
AbstractCrdt
|
|
416
|
-
);
|
|
417
|
-
})(),
|
|
418
|
-
LiveRegister = (function (_AbstractCrdt) {
|
|
419
|
-
function LiveRegister(data) {
|
|
420
|
-
var _this;
|
|
421
|
-
return (
|
|
422
|
-
((_this = _AbstractCrdt.call(this) || this)._data = void 0),
|
|
423
|
-
(_this._data = data),
|
|
424
|
-
_this
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
_inheritsLoose(LiveRegister, _AbstractCrdt),
|
|
428
|
-
(LiveRegister._deserialize = function (_ref, _parentToChildren, doc) {
|
|
429
|
-
var id = _ref[0],
|
|
430
|
-
register = new LiveRegister(_ref[1].data);
|
|
431
|
-
return register._attach(id, doc), register;
|
|
432
|
-
});
|
|
433
|
-
var _proto = LiveRegister.prototype;
|
|
434
|
-
return (
|
|
435
|
-
(_proto._serialize = function (parentId, parentKey, doc) {
|
|
436
|
-
if (null == this._id || null == parentId || null == parentKey)
|
|
437
|
-
throw new Error(
|
|
438
|
-
"Cannot serialize register if parentId or parentKey is undefined"
|
|
439
|
-
);
|
|
440
|
-
return [
|
|
441
|
-
{
|
|
442
|
-
type: exports.OpCode.CREATE_REGISTER,
|
|
443
|
-
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
444
|
-
id: this._id,
|
|
445
|
-
parentId: parentId,
|
|
446
|
-
parentKey: parentKey,
|
|
447
|
-
data: this.data,
|
|
448
|
-
},
|
|
449
|
-
];
|
|
450
|
-
}),
|
|
451
|
-
(_proto._toSerializedCrdt = function () {
|
|
452
|
-
if ("HasParent" !== this.parent.type)
|
|
453
|
-
throw new Error("Cannot serialize LiveRegister if parent is missing");
|
|
454
|
-
return {
|
|
455
|
-
type: exports.CrdtType.REGISTER,
|
|
456
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
457
|
-
parentKey: this.parent.key,
|
|
458
|
-
data: this.data,
|
|
459
|
-
};
|
|
460
|
-
}),
|
|
461
|
-
(_proto._attachChild = function (_op) {
|
|
462
|
-
throw new Error("Method not implemented.");
|
|
463
|
-
}),
|
|
464
|
-
(_proto._detachChild = function (_crdt) {
|
|
465
|
-
throw new Error("Method not implemented.");
|
|
466
|
-
}),
|
|
467
|
-
(_proto._apply = function (op, isLocal) {
|
|
468
|
-
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
469
|
-
}),
|
|
470
|
-
_createClass(LiveRegister, [
|
|
471
|
-
{
|
|
472
|
-
key: "data",
|
|
473
|
-
get: function () {
|
|
474
|
-
return this._data;
|
|
475
|
-
},
|
|
476
|
-
},
|
|
477
|
-
]),
|
|
478
|
-
LiveRegister
|
|
479
|
-
);
|
|
480
|
-
})(AbstractCrdt);
|
|
481
|
-
function makePosition(before, after) {
|
|
482
|
-
return null != before && null != after
|
|
483
|
-
? pos(makePositionFromCodes(posCodes(before), posCodes(after)))
|
|
484
|
-
: null != before
|
|
485
|
-
? (function (before) {
|
|
486
|
-
for (
|
|
487
|
-
var result = [], beforeCodes = posCodes(before), i = 0;
|
|
488
|
-
i < beforeCodes.length;
|
|
489
|
-
i++
|
|
490
|
-
) {
|
|
491
|
-
var code = beforeCodes[i];
|
|
492
|
-
if (126 !== code) {
|
|
493
|
-
result.push(code + 1);
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
if ((result.push(code), beforeCodes.length - 1 === i)) {
|
|
497
|
-
result.push(33);
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return pos(result);
|
|
502
|
-
})(before)
|
|
503
|
-
: null != after
|
|
504
|
-
? (function (after) {
|
|
505
|
-
for (
|
|
506
|
-
var result = [], afterCodes = posCodes(after), i = 0;
|
|
507
|
-
i < afterCodes.length;
|
|
508
|
-
i++
|
|
509
|
-
) {
|
|
510
|
-
var code = afterCodes[i];
|
|
511
|
-
if (!(code <= 33)) {
|
|
512
|
-
result.push(code - 1);
|
|
513
|
-
break;
|
|
514
|
-
}
|
|
515
|
-
if ((result.push(32), afterCodes.length - 1 === i)) {
|
|
516
|
-
result.push(126);
|
|
517
|
-
break;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
return pos(result);
|
|
521
|
-
})(after)
|
|
522
|
-
: pos([33]);
|
|
523
|
-
}
|
|
524
|
-
function makePositionFromCodes(before, after) {
|
|
525
|
-
for (var index = 0, result = []; ; ) {
|
|
526
|
-
var beforeDigit = before[index] || 32,
|
|
527
|
-
afterDigit = after[index] || 126;
|
|
528
|
-
if (beforeDigit > afterDigit)
|
|
529
|
-
throw new Error(
|
|
530
|
-
"Impossible to generate position between " + before + " and " + after
|
|
531
|
-
);
|
|
532
|
-
if (beforeDigit !== afterDigit) {
|
|
533
|
-
if (afterDigit - beforeDigit == 1) {
|
|
534
|
-
result.push(beforeDigit),
|
|
535
|
-
result.push.apply(
|
|
536
|
-
result,
|
|
537
|
-
makePositionFromCodes(before.slice(index + 1), [])
|
|
538
|
-
);
|
|
539
|
-
break;
|
|
540
|
-
}
|
|
541
|
-
var mid = (afterDigit + beforeDigit) >> 1;
|
|
542
|
-
result.push(mid);
|
|
543
|
-
break;
|
|
544
|
-
}
|
|
545
|
-
result.push(beforeDigit), index++;
|
|
546
|
-
}
|
|
547
|
-
return result;
|
|
548
|
-
}
|
|
549
|
-
function posCodes(str) {
|
|
550
|
-
for (var codes = [], i = 0; i < str.length; i++)
|
|
551
|
-
codes.push(str.charCodeAt(i));
|
|
552
|
-
return codes;
|
|
553
|
-
}
|
|
554
|
-
function pos(codes) {
|
|
555
|
-
return String.fromCharCode.apply(String, codes);
|
|
556
|
-
}
|
|
557
|
-
function comparePosition(posA, posB) {
|
|
558
|
-
for (
|
|
559
|
-
var aCodes = posCodes(posA),
|
|
560
|
-
bCodes = posCodes(posB),
|
|
561
|
-
maxLength = Math.max(aCodes.length, bCodes.length),
|
|
562
|
-
i = 0;
|
|
563
|
-
i < maxLength;
|
|
564
|
-
i++
|
|
565
|
-
) {
|
|
566
|
-
var a = null == aCodes[i] ? 32 : aCodes[i],
|
|
567
|
-
b = null == bCodes[i] ? 32 : bCodes[i];
|
|
568
|
-
if (a !== b) return a - b;
|
|
569
|
-
}
|
|
570
|
-
throw new Error(
|
|
571
|
-
'Impossible to compare similar position "' + posA + '" and "' + posB + '"'
|
|
572
|
-
);
|
|
573
|
-
}
|
|
574
|
-
function compareNodePosition(itemA, itemB) {
|
|
575
|
-
return comparePosition(
|
|
576
|
-
itemA._getParentKeyOrThrow(),
|
|
577
|
-
itemB._getParentKeyOrThrow()
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
|
-
_Symbol$iterator$1 = Symbol.iterator;
|
|
581
|
-
var LiveList = (function (_AbstractCrdt) {
|
|
582
|
-
function LiveList(items) {
|
|
583
|
-
var _this;
|
|
584
|
-
void 0 === items && (items = []),
|
|
585
|
-
((_this = _AbstractCrdt.call(this) || this)._items = void 0),
|
|
586
|
-
(_this._implicitlyDeletedItems = void 0),
|
|
587
|
-
(_this._unacknowledgedSets = void 0),
|
|
588
|
-
(_this._items = []),
|
|
589
|
-
(_this._implicitlyDeletedItems = new Set()),
|
|
590
|
-
(_this._unacknowledgedSets = new Map());
|
|
591
|
-
for (var position = void 0, i = 0; i < items.length; i++) {
|
|
592
|
-
var newPosition = makePosition(position),
|
|
593
|
-
item = lsonToLiveNode(items[i]);
|
|
594
|
-
item._setParentLink(_assertThisInitialized(_this), newPosition),
|
|
595
|
-
_this._items.push(item),
|
|
596
|
-
(position = newPosition);
|
|
597
|
-
}
|
|
598
|
-
return _this;
|
|
599
|
-
}
|
|
600
|
-
_inheritsLoose(LiveList, _AbstractCrdt),
|
|
601
|
-
(LiveList._deserialize = function (_ref, parentToChildren, doc) {
|
|
602
|
-
var id = _ref[0],
|
|
603
|
-
list = new LiveList();
|
|
604
|
-
list._attach(id, doc);
|
|
605
|
-
var children = parentToChildren.get(id);
|
|
606
|
-
if (null == children) return list;
|
|
607
|
-
for (
|
|
608
|
-
var _step, _iterator = _createForOfIteratorHelperLoose(children);
|
|
609
|
-
!(_step = _iterator()).done;
|
|
610
|
-
|
|
611
|
-
) {
|
|
612
|
-
var _step$value = _step.value,
|
|
613
|
-
_id = _step$value[0],
|
|
614
|
-
crdt = _step$value[1],
|
|
615
|
-
child = deserialize([_id, crdt], parentToChildren, doc);
|
|
616
|
-
child._setParentLink(list, crdt.parentKey), list._insertAndSort(child);
|
|
617
|
-
}
|
|
618
|
-
return list;
|
|
619
|
-
});
|
|
620
|
-
var _proto = LiveList.prototype;
|
|
621
|
-
return (
|
|
622
|
-
(_proto._serialize = function (parentId, parentKey, doc) {
|
|
623
|
-
if (null == this._id)
|
|
624
|
-
throw new Error("Cannot serialize item is not attached");
|
|
625
|
-
var ops = [],
|
|
626
|
-
op = {
|
|
627
|
-
id: this._id,
|
|
628
|
-
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
629
|
-
type: exports.OpCode.CREATE_LIST,
|
|
630
|
-
parentId: parentId,
|
|
631
|
-
parentKey: parentKey,
|
|
632
|
-
};
|
|
633
|
-
ops.push(op);
|
|
634
|
-
for (
|
|
635
|
-
var _step2, _iterator2 = _createForOfIteratorHelperLoose(this._items);
|
|
636
|
-
!(_step2 = _iterator2()).done;
|
|
637
|
-
|
|
638
|
-
) {
|
|
639
|
-
var item = _step2.value;
|
|
640
|
-
ops.push.apply(
|
|
641
|
-
ops,
|
|
642
|
-
item._serialize(this._id, item._getParentKeyOrThrow(), doc)
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
return ops;
|
|
646
|
-
}),
|
|
647
|
-
(_proto._insertAndSort = function (item) {
|
|
648
|
-
this._items.push(item), this._sortItems();
|
|
649
|
-
}),
|
|
650
|
-
(_proto._sortItems = function () {
|
|
651
|
-
this._items.sort(compareNodePosition);
|
|
652
|
-
}),
|
|
653
|
-
(_proto._indexOfPosition = function (position) {
|
|
654
|
-
return this._items.findIndex(function (item) {
|
|
655
|
-
return item._getParentKeyOrThrow() === position;
|
|
656
|
-
});
|
|
657
|
-
}),
|
|
658
|
-
(_proto._attach = function (id, doc) {
|
|
659
|
-
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
660
|
-
for (
|
|
661
|
-
var _step3, _iterator3 = _createForOfIteratorHelperLoose(this._items);
|
|
662
|
-
!(_step3 = _iterator3()).done;
|
|
663
|
-
|
|
664
|
-
) {
|
|
665
|
-
_step3.value._attach(doc.generateId(), doc);
|
|
666
|
-
}
|
|
667
|
-
}),
|
|
668
|
-
(_proto._detach = function () {
|
|
669
|
-
_AbstractCrdt.prototype._detach.call(this);
|
|
670
|
-
for (
|
|
671
|
-
var _step4, _iterator4 = _createForOfIteratorHelperLoose(this._items);
|
|
672
|
-
!(_step4 = _iterator4()).done;
|
|
673
|
-
|
|
674
|
-
) {
|
|
675
|
-
_step4.value._detach();
|
|
676
|
-
}
|
|
677
|
-
}),
|
|
678
|
-
(_proto._applySetRemote = function (op) {
|
|
679
|
-
if (null == this._doc)
|
|
680
|
-
throw new Error("Can't attach child if doc is not present");
|
|
681
|
-
var id = op.id,
|
|
682
|
-
key = op.parentKey,
|
|
683
|
-
child = creationOpToLiveNode(op);
|
|
684
|
-
child._attach(id, this._doc), child._setParentLink(this, key);
|
|
685
|
-
var deletedId = op.deletedId,
|
|
686
|
-
indexOfItemWithSamePosition = this._indexOfPosition(key);
|
|
687
|
-
if (-1 !== indexOfItemWithSamePosition) {
|
|
688
|
-
var itemWithSamePosition = this._items[indexOfItemWithSamePosition];
|
|
689
|
-
if (itemWithSamePosition._id === deletedId)
|
|
690
|
-
return (
|
|
691
|
-
itemWithSamePosition._detach(),
|
|
692
|
-
(this._items[indexOfItemWithSamePosition] = child),
|
|
693
|
-
{
|
|
694
|
-
modified: makeUpdate(this, [
|
|
695
|
-
setDelta(indexOfItemWithSamePosition, child),
|
|
696
|
-
]),
|
|
697
|
-
reverse: [],
|
|
698
|
-
}
|
|
699
|
-
);
|
|
700
|
-
this._implicitlyDeletedItems.add(itemWithSamePosition),
|
|
701
|
-
(this._items[indexOfItemWithSamePosition] = child);
|
|
702
|
-
var delta = [setDelta(indexOfItemWithSamePosition, child)],
|
|
703
|
-
_deleteDelta = this._detachItemAssociatedToSetOperation(op.deletedId);
|
|
704
|
-
return (
|
|
705
|
-
_deleteDelta && delta.push(_deleteDelta),
|
|
706
|
-
{ modified: makeUpdate(this, delta), reverse: [] }
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
|
-
var updates = [],
|
|
710
|
-
_deleteDelta2 = this._detachItemAssociatedToSetOperation(op.deletedId);
|
|
711
|
-
return (
|
|
712
|
-
_deleteDelta2 && updates.push(_deleteDelta2),
|
|
713
|
-
this._insertAndSort(child),
|
|
714
|
-
updates.push(insertDelta(this._indexOfPosition(key), child)),
|
|
715
|
-
{ reverse: [], modified: makeUpdate(this, updates) }
|
|
716
|
-
);
|
|
717
|
-
}),
|
|
718
|
-
(_proto._applySetAck = function (op) {
|
|
719
|
-
if (null == this._doc)
|
|
720
|
-
throw new Error("Can't attach child if doc is not present");
|
|
721
|
-
var delta = [],
|
|
722
|
-
deletedDelta = this._detachItemAssociatedToSetOperation(op.deletedId);
|
|
723
|
-
deletedDelta && delta.push(deletedDelta);
|
|
724
|
-
var unacknowledgedOpId = this._unacknowledgedSets.get(op.parentKey);
|
|
725
|
-
if (null != unacknowledgedOpId) {
|
|
726
|
-
if (unacknowledgedOpId !== op.opId)
|
|
727
|
-
return 0 === delta.length
|
|
728
|
-
? { modified: !1 }
|
|
729
|
-
: { modified: makeUpdate(this, delta), reverse: [] };
|
|
730
|
-
this._unacknowledgedSets.delete(op.parentKey);
|
|
731
|
-
}
|
|
732
|
-
var indexOfItemWithSamePosition = this._indexOfPosition(op.parentKey),
|
|
733
|
-
existingItem = this._items.find(function (item) {
|
|
734
|
-
return item._id === op.id;
|
|
735
|
-
});
|
|
736
|
-
if (null != existingItem) {
|
|
737
|
-
if (existingItem._parentKey === op.parentKey)
|
|
738
|
-
return {
|
|
739
|
-
modified: delta.length > 0 && makeUpdate(this, delta),
|
|
740
|
-
reverse: [],
|
|
741
|
-
};
|
|
742
|
-
-1 !== indexOfItemWithSamePosition &&
|
|
743
|
-
(this._implicitlyDeletedItems.add(
|
|
744
|
-
this._items[indexOfItemWithSamePosition]
|
|
745
|
-
),
|
|
746
|
-
this._items.splice(indexOfItemWithSamePosition, 1),
|
|
747
|
-
delta.push(deleteDelta(indexOfItemWithSamePosition)));
|
|
748
|
-
var previousIndex = this._items.indexOf(existingItem);
|
|
749
|
-
existingItem._setParentLink(this, op.parentKey), this._sortItems();
|
|
750
|
-
var newIndex = this._items.indexOf(existingItem);
|
|
751
|
-
return (
|
|
752
|
-
newIndex !== previousIndex &&
|
|
753
|
-
delta.push(moveDelta(previousIndex, newIndex, existingItem)),
|
|
754
|
-
{ modified: delta.length > 0 && makeUpdate(this, delta), reverse: [] }
|
|
755
|
-
);
|
|
756
|
-
}
|
|
757
|
-
var orphan = this._doc.getItem(op.id);
|
|
758
|
-
if (orphan && this._implicitlyDeletedItems.has(orphan)) {
|
|
759
|
-
orphan._setParentLink(this, op.parentKey),
|
|
760
|
-
this._implicitlyDeletedItems.delete(orphan),
|
|
761
|
-
this._insertAndSort(orphan);
|
|
762
|
-
var recreatedItemIndex = this._items.indexOf(orphan);
|
|
763
|
-
return {
|
|
764
|
-
modified: makeUpdate(
|
|
765
|
-
this,
|
|
766
|
-
[
|
|
767
|
-
-1 === indexOfItemWithSamePosition
|
|
768
|
-
? insertDelta(recreatedItemIndex, orphan)
|
|
769
|
-
: setDelta(recreatedItemIndex, orphan),
|
|
770
|
-
].concat(delta)
|
|
771
|
-
),
|
|
772
|
-
reverse: [],
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
-1 !== indexOfItemWithSamePosition &&
|
|
776
|
-
this._items.splice(indexOfItemWithSamePosition, 1);
|
|
777
|
-
var _this$_createAttachIt = this._createAttachItemAndSort(
|
|
778
|
-
op,
|
|
779
|
-
op.parentKey
|
|
780
|
-
),
|
|
781
|
-
newItem = _this$_createAttachIt.newItem,
|
|
782
|
-
_newIndex = _this$_createAttachIt.newIndex;
|
|
783
|
-
return {
|
|
784
|
-
modified: makeUpdate(
|
|
785
|
-
this,
|
|
786
|
-
[
|
|
787
|
-
-1 === indexOfItemWithSamePosition
|
|
788
|
-
? insertDelta(_newIndex, newItem)
|
|
789
|
-
: setDelta(_newIndex, newItem),
|
|
790
|
-
].concat(delta)
|
|
791
|
-
),
|
|
792
|
-
reverse: [],
|
|
793
|
-
};
|
|
794
|
-
}),
|
|
795
|
-
(_proto._detachItemAssociatedToSetOperation = function (deletedId) {
|
|
796
|
-
if (null == deletedId || null == this._doc) return null;
|
|
797
|
-
var deletedItem = this._doc.getItem(deletedId);
|
|
798
|
-
if (null == deletedItem) return null;
|
|
799
|
-
var result = this._detachChild(deletedItem);
|
|
800
|
-
return !1 === result.modified ? null : result.modified.updates[0];
|
|
801
|
-
}),
|
|
802
|
-
(_proto._applyRemoteInsert = function (op) {
|
|
803
|
-
if (null == this._doc)
|
|
804
|
-
throw new Error("Can't attach child if doc is not present");
|
|
805
|
-
var key = op.parentKey,
|
|
806
|
-
existingItemIndex = this._indexOfPosition(key);
|
|
807
|
-
-1 !== existingItemIndex &&
|
|
808
|
-
this._shiftItemPosition(existingItemIndex, key);
|
|
809
|
-
var _this$_createAttachIt2 = this._createAttachItemAndSort(op, key),
|
|
810
|
-
newItem = _this$_createAttachIt2.newItem;
|
|
811
|
-
return {
|
|
812
|
-
modified: makeUpdate(this, [
|
|
813
|
-
insertDelta(_this$_createAttachIt2.newIndex, newItem),
|
|
814
|
-
]),
|
|
815
|
-
reverse: [],
|
|
816
|
-
};
|
|
817
|
-
}),
|
|
818
|
-
(_proto._applyInsertAck = function (op) {
|
|
819
|
-
var existingItem = this._items.find(function (item) {
|
|
820
|
-
return item._id === op.id;
|
|
821
|
-
}),
|
|
822
|
-
key = op.parentKey,
|
|
823
|
-
itemIndexAtPosition = this._indexOfPosition(key);
|
|
824
|
-
if (existingItem) {
|
|
825
|
-
if (existingItem._parentKey === key) return { modified: !1 };
|
|
826
|
-
var oldPositionIndex = this._items.indexOf(existingItem);
|
|
827
|
-
-1 !== itemIndexAtPosition &&
|
|
828
|
-
this._shiftItemPosition(itemIndexAtPosition, key),
|
|
829
|
-
existingItem._setParentLink(this, key),
|
|
830
|
-
this._sortItems();
|
|
831
|
-
var newIndex = this._indexOfPosition(key);
|
|
832
|
-
return newIndex === oldPositionIndex
|
|
833
|
-
? { modified: !1 }
|
|
834
|
-
: {
|
|
835
|
-
modified: makeUpdate(this, [
|
|
836
|
-
moveDelta(oldPositionIndex, newIndex, existingItem),
|
|
837
|
-
]),
|
|
838
|
-
reverse: [],
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
var orphan = nn(this._doc).getItem(op.id);
|
|
842
|
-
if (orphan && this._implicitlyDeletedItems.has(orphan))
|
|
843
|
-
return (
|
|
844
|
-
orphan._setParentLink(this, key),
|
|
845
|
-
this._implicitlyDeletedItems.delete(orphan),
|
|
846
|
-
this._insertAndSort(orphan),
|
|
847
|
-
{
|
|
848
|
-
modified: makeUpdate(this, [
|
|
849
|
-
insertDelta(this._indexOfPosition(key), orphan),
|
|
850
|
-
]),
|
|
851
|
-
reverse: [],
|
|
852
|
-
}
|
|
853
|
-
);
|
|
854
|
-
-1 !== itemIndexAtPosition &&
|
|
855
|
-
this._shiftItemPosition(itemIndexAtPosition, key);
|
|
856
|
-
var _this$_createAttachIt3 = this._createAttachItemAndSort(op, key),
|
|
857
|
-
newItem = _this$_createAttachIt3.newItem;
|
|
858
|
-
return {
|
|
859
|
-
modified: makeUpdate(this, [
|
|
860
|
-
insertDelta(_this$_createAttachIt3.newIndex, newItem),
|
|
861
|
-
]),
|
|
862
|
-
reverse: [],
|
|
863
|
-
};
|
|
864
|
-
}),
|
|
865
|
-
(_proto._applyInsertUndoRedo = function (op) {
|
|
866
|
-
var _this$_doc,
|
|
867
|
-
id = op.id,
|
|
868
|
-
key = op.parentKey,
|
|
869
|
-
child = creationOpToLiveNode(op);
|
|
870
|
-
if (
|
|
871
|
-
void 0 !==
|
|
872
|
-
(null == (_this$_doc = this._doc) ? void 0 : _this$_doc.getItem(id))
|
|
873
|
-
)
|
|
874
|
-
return { modified: !1 };
|
|
875
|
-
child._attach(id, nn(this._doc)), child._setParentLink(this, key);
|
|
876
|
-
var existingItemIndex = this._indexOfPosition(key),
|
|
877
|
-
newKey = key;
|
|
878
|
-
-1 !== existingItemIndex &&
|
|
879
|
-
((newKey = makePosition(
|
|
880
|
-
this._items[existingItemIndex]
|
|
881
|
-
? this._items[existingItemIndex]._getParentKeyOrThrow()
|
|
882
|
-
: void 0,
|
|
883
|
-
this._items[existingItemIndex + 1]
|
|
884
|
-
? this._items[existingItemIndex + 1]._getParentKeyOrThrow()
|
|
885
|
-
: void 0
|
|
886
|
-
)),
|
|
887
|
-
child._setParentLink(this, newKey));
|
|
888
|
-
return (
|
|
889
|
-
this._insertAndSort(child),
|
|
890
|
-
{
|
|
891
|
-
modified: makeUpdate(this, [
|
|
892
|
-
insertDelta(this._indexOfPosition(newKey), child),
|
|
893
|
-
]),
|
|
894
|
-
reverse: [{ type: exports.OpCode.DELETE_CRDT, id: id }],
|
|
895
|
-
}
|
|
896
|
-
);
|
|
897
|
-
}),
|
|
898
|
-
(_proto._applySetUndoRedo = function (op) {
|
|
899
|
-
var _this$_doc2,
|
|
900
|
-
id = op.id,
|
|
901
|
-
key = op.parentKey,
|
|
902
|
-
child = creationOpToLiveNode(op);
|
|
903
|
-
if (
|
|
904
|
-
void 0 !==
|
|
905
|
-
(null == (_this$_doc2 = this._doc) ? void 0 : _this$_doc2.getItem(id))
|
|
906
|
-
)
|
|
907
|
-
return { modified: !1 };
|
|
908
|
-
this._unacknowledgedSets.set(key, nn(op.opId));
|
|
909
|
-
var indexOfItemWithSameKey = this._indexOfPosition(key);
|
|
910
|
-
child._attach(id, nn(this._doc)), child._setParentLink(this, key);
|
|
911
|
-
var newKey = key;
|
|
912
|
-
if (-1 !== indexOfItemWithSameKey) {
|
|
913
|
-
var existingItem = this._items[indexOfItemWithSameKey];
|
|
914
|
-
existingItem._detach(), (this._items[indexOfItemWithSameKey] = child);
|
|
915
|
-
var reverse = existingItem._serialize(nn(this._id), key, this._doc);
|
|
916
|
-
addIntentAndDeletedIdToOperation(reverse, op.id);
|
|
917
|
-
var delta = [setDelta(indexOfItemWithSameKey, child)],
|
|
918
|
-
deletedDelta = this._detachItemAssociatedToSetOperation(op.deletedId);
|
|
919
|
-
return (
|
|
920
|
-
deletedDelta && delta.push(deletedDelta),
|
|
921
|
-
{ modified: makeUpdate(this, delta), reverse: reverse }
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
this._insertAndSort(child),
|
|
925
|
-
this._detachItemAssociatedToSetOperation(op.deletedId);
|
|
926
|
-
var newIndex = this._indexOfPosition(newKey);
|
|
927
|
-
return {
|
|
928
|
-
reverse: [{ type: exports.OpCode.DELETE_CRDT, id: id }],
|
|
929
|
-
modified: makeUpdate(this, [insertDelta(newIndex, child)]),
|
|
930
|
-
};
|
|
931
|
-
}),
|
|
932
|
-
(_proto._attachChild = function (op, source) {
|
|
933
|
-
if (null == this._doc)
|
|
934
|
-
throw new Error("Can't attach child if doc is not present");
|
|
935
|
-
if ("set" === op.intent) {
|
|
936
|
-
if (source === exports.OpSource.REMOTE) return this._applySetRemote(op);
|
|
937
|
-
if (source === exports.OpSource.UNDOREDO_RECONNECT)
|
|
938
|
-
return this._applySetUndoRedo(op);
|
|
939
|
-
if (source === exports.OpSource.ACK) return this._applySetAck(op);
|
|
940
|
-
}
|
|
941
|
-
return source === exports.OpSource.REMOTE
|
|
942
|
-
? this._applyRemoteInsert(op)
|
|
943
|
-
: source === exports.OpSource.ACK
|
|
944
|
-
? this._applyInsertAck(op)
|
|
945
|
-
: this._applyInsertUndoRedo(op);
|
|
946
|
-
}),
|
|
947
|
-
(_proto._detachChild = function (child) {
|
|
948
|
-
if (child) {
|
|
949
|
-
var parentKey = nn(child._parentKey),
|
|
950
|
-
reverse = child._serialize(nn(this._id), parentKey, this._doc),
|
|
951
|
-
indexToDelete = this._items.indexOf(child);
|
|
952
|
-
return -1 === indexToDelete
|
|
953
|
-
? { modified: !1 }
|
|
954
|
-
: (this._items.splice(indexToDelete, 1),
|
|
955
|
-
child._detach(),
|
|
956
|
-
{
|
|
957
|
-
modified: makeUpdate(this, [deleteDelta(indexToDelete)]),
|
|
958
|
-
reverse: reverse,
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
return { modified: !1 };
|
|
962
|
-
}),
|
|
963
|
-
(_proto._applySetChildKeyRemote = function (newKey, child) {
|
|
964
|
-
if (this._implicitlyDeletedItems.has(child))
|
|
965
|
-
return (
|
|
966
|
-
this._implicitlyDeletedItems.delete(child),
|
|
967
|
-
child._setParentLink(this, newKey),
|
|
968
|
-
this._insertAndSort(child),
|
|
969
|
-
{
|
|
970
|
-
modified: makeUpdate(this, [
|
|
971
|
-
insertDelta(this._items.indexOf(child), child),
|
|
972
|
-
]),
|
|
973
|
-
reverse: [],
|
|
974
|
-
}
|
|
975
|
-
);
|
|
976
|
-
if (newKey === child._parentKey) return { modified: !1 };
|
|
977
|
-
var _this$_items,
|
|
978
|
-
existingItemIndex = this._indexOfPosition(newKey);
|
|
979
|
-
if (-1 === existingItemIndex) {
|
|
980
|
-
var previousIndex = this._items.indexOf(child);
|
|
981
|
-
child._setParentLink(this, newKey), this._sortItems();
|
|
982
|
-
var _newIndex4 = this._items.indexOf(child);
|
|
983
|
-
return _newIndex4 === previousIndex
|
|
984
|
-
? { modified: !1 }
|
|
985
|
-
: {
|
|
986
|
-
modified: makeUpdate(this, [
|
|
987
|
-
moveDelta(previousIndex, _newIndex4, child),
|
|
988
|
-
]),
|
|
989
|
-
reverse: [],
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
this._items[existingItemIndex]._setParentLink(
|
|
993
|
-
this,
|
|
994
|
-
makePosition(
|
|
995
|
-
newKey,
|
|
996
|
-
null == (_this$_items = this._items[existingItemIndex + 1])
|
|
997
|
-
? void 0
|
|
998
|
-
: _this$_items._getParentKeyOrThrow()
|
|
999
|
-
)
|
|
1000
|
-
);
|
|
1001
|
-
var _previousIndex = this._items.indexOf(child);
|
|
1002
|
-
child._setParentLink(this, newKey), this._sortItems();
|
|
1003
|
-
var _newIndex5 = this._items.indexOf(child);
|
|
1004
|
-
return _newIndex5 === _previousIndex
|
|
1005
|
-
? { modified: !1 }
|
|
1006
|
-
: {
|
|
1007
|
-
modified: makeUpdate(this, [
|
|
1008
|
-
moveDelta(_previousIndex, _newIndex5, child),
|
|
1009
|
-
]),
|
|
1010
|
-
reverse: [],
|
|
1011
|
-
};
|
|
1012
|
-
}),
|
|
1013
|
-
(_proto._applySetChildKeyAck = function (newKey, child) {
|
|
1014
|
-
var previousKey = nn(child._parentKey);
|
|
1015
|
-
if (this._implicitlyDeletedItems.has(child)) {
|
|
1016
|
-
var _this$_items2,
|
|
1017
|
-
existingItemIndex = this._indexOfPosition(newKey);
|
|
1018
|
-
if (
|
|
1019
|
-
(this._implicitlyDeletedItems.delete(child), -1 !== existingItemIndex)
|
|
1020
|
-
)
|
|
1021
|
-
this._items[existingItemIndex]._setParentLink(
|
|
1022
|
-
this,
|
|
1023
|
-
makePosition(
|
|
1024
|
-
newKey,
|
|
1025
|
-
null == (_this$_items2 = this._items[existingItemIndex + 1])
|
|
1026
|
-
? void 0
|
|
1027
|
-
: _this$_items2._getParentKeyOrThrow()
|
|
1028
|
-
)
|
|
1029
|
-
);
|
|
1030
|
-
return (
|
|
1031
|
-
child._setParentLink(this, newKey),
|
|
1032
|
-
this._insertAndSort(child),
|
|
1033
|
-
{ modified: !1 }
|
|
1034
|
-
);
|
|
1035
|
-
}
|
|
1036
|
-
if (newKey === previousKey) return { modified: !1 };
|
|
1037
|
-
var _this$_items3,
|
|
1038
|
-
previousIndex = this._items.indexOf(child),
|
|
1039
|
-
_existingItemIndex = this._indexOfPosition(newKey);
|
|
1040
|
-
-1 !== _existingItemIndex &&
|
|
1041
|
-
this._items[_existingItemIndex]._setParentLink(
|
|
1042
|
-
this,
|
|
1043
|
-
makePosition(
|
|
1044
|
-
newKey,
|
|
1045
|
-
null == (_this$_items3 = this._items[_existingItemIndex + 1])
|
|
1046
|
-
? void 0
|
|
1047
|
-
: _this$_items3._getParentKeyOrThrow()
|
|
1048
|
-
)
|
|
1049
|
-
),
|
|
1050
|
-
child._setParentLink(this, newKey),
|
|
1051
|
-
this._sortItems();
|
|
1052
|
-
var newIndex = this._items.indexOf(child);
|
|
1053
|
-
return previousIndex === newIndex
|
|
1054
|
-
? { modified: !1 }
|
|
1055
|
-
: {
|
|
1056
|
-
modified: makeUpdate(this, [
|
|
1057
|
-
moveDelta(previousIndex, newIndex, child),
|
|
1058
|
-
]),
|
|
1059
|
-
reverse: [],
|
|
1060
|
-
};
|
|
1061
|
-
}),
|
|
1062
|
-
(_proto._applySetChildKeyUndoRedo = function (newKey, child) {
|
|
1063
|
-
var _this$_items4,
|
|
1064
|
-
previousKey = nn(child._parentKey),
|
|
1065
|
-
previousIndex = this._items.indexOf(child),
|
|
1066
|
-
existingItemIndex = this._indexOfPosition(newKey);
|
|
1067
|
-
-1 !== existingItemIndex &&
|
|
1068
|
-
this._items[existingItemIndex]._setParentLink(
|
|
1069
|
-
this,
|
|
1070
|
-
makePosition(
|
|
1071
|
-
newKey,
|
|
1072
|
-
null == (_this$_items4 = this._items[existingItemIndex + 1])
|
|
1073
|
-
? void 0
|
|
1074
|
-
: _this$_items4._getParentKeyOrThrow()
|
|
1075
|
-
)
|
|
1076
|
-
);
|
|
1077
|
-
child._setParentLink(this, newKey), this._sortItems();
|
|
1078
|
-
var newIndex = this._items.indexOf(child);
|
|
1079
|
-
return previousIndex === newIndex
|
|
1080
|
-
? { modified: !1 }
|
|
1081
|
-
: {
|
|
1082
|
-
modified: makeUpdate(this, [
|
|
1083
|
-
moveDelta(previousIndex, newIndex, child),
|
|
1084
|
-
]),
|
|
1085
|
-
reverse: [
|
|
1086
|
-
{
|
|
1087
|
-
type: exports.OpCode.SET_PARENT_KEY,
|
|
1088
|
-
id: nn(child._id),
|
|
1089
|
-
parentKey: previousKey,
|
|
1090
|
-
},
|
|
1091
|
-
],
|
|
1092
|
-
};
|
|
1093
|
-
}),
|
|
1094
|
-
(_proto._setChildKey = function (newKey, child, source) {
|
|
1095
|
-
return source === exports.OpSource.REMOTE
|
|
1096
|
-
? this._applySetChildKeyRemote(newKey, child)
|
|
1097
|
-
: source === exports.OpSource.ACK
|
|
1098
|
-
? this._applySetChildKeyAck(newKey, child)
|
|
1099
|
-
: this._applySetChildKeyUndoRedo(newKey, child);
|
|
1100
|
-
}),
|
|
1101
|
-
(_proto._apply = function (op, isLocal) {
|
|
1102
|
-
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
1103
|
-
}),
|
|
1104
|
-
(_proto._toSerializedCrdt = function () {
|
|
1105
|
-
if ("HasParent" !== this.parent.type)
|
|
1106
|
-
throw new Error("Cannot serialize LiveList if parent is missing");
|
|
1107
|
-
return {
|
|
1108
|
-
type: exports.CrdtType.LIST,
|
|
1109
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
1110
|
-
parentKey: this.parent.key,
|
|
1111
|
-
};
|
|
1112
|
-
}),
|
|
1113
|
-
(_proto.push = function (element) {
|
|
1114
|
-
return this.insert(element, this.length);
|
|
1115
|
-
}),
|
|
1116
|
-
(_proto.insert = function (element, index) {
|
|
1117
|
-
if (index < 0 || index > this._items.length)
|
|
1118
|
-
throw new Error(
|
|
1119
|
-
'Cannot insert list item at index "' +
|
|
1120
|
-
index +
|
|
1121
|
-
'". index should be between 0 and ' +
|
|
1122
|
-
this._items.length
|
|
1123
|
-
);
|
|
1124
|
-
var position = makePosition(
|
|
1125
|
-
this._items[index - 1]
|
|
1126
|
-
? this._items[index - 1]._getParentKeyOrThrow()
|
|
1127
|
-
: void 0,
|
|
1128
|
-
this._items[index]
|
|
1129
|
-
? this._items[index]._getParentKeyOrThrow()
|
|
1130
|
-
: void 0
|
|
1131
|
-
),
|
|
1132
|
-
value = lsonToLiveNode(element);
|
|
1133
|
-
if (
|
|
1134
|
-
(value._setParentLink(this, position),
|
|
1135
|
-
this._insertAndSort(value),
|
|
1136
|
-
this._doc && this._id)
|
|
1137
|
-
) {
|
|
1138
|
-
var id = this._doc.generateId();
|
|
1139
|
-
value._attach(id, this._doc),
|
|
1140
|
-
this._doc.dispatch(
|
|
1141
|
-
value._serialize(this._id, position, this._doc),
|
|
1142
|
-
[{ type: exports.OpCode.DELETE_CRDT, id: id }],
|
|
1143
|
-
new Map([[this._id, makeUpdate(this, [insertDelta(index, value)])]])
|
|
1144
|
-
);
|
|
1145
|
-
}
|
|
1146
|
-
}),
|
|
1147
|
-
(_proto.move = function (index, targetIndex) {
|
|
1148
|
-
if (targetIndex < 0) throw new Error("targetIndex cannot be less than 0");
|
|
1149
|
-
if (targetIndex >= this._items.length)
|
|
1150
|
-
throw new Error(
|
|
1151
|
-
"targetIndex cannot be greater or equal than the list length"
|
|
1152
|
-
);
|
|
1153
|
-
if (index < 0) throw new Error("index cannot be less than 0");
|
|
1154
|
-
if (index >= this._items.length)
|
|
1155
|
-
throw new Error(
|
|
1156
|
-
"index cannot be greater or equal than the list length"
|
|
1157
|
-
);
|
|
1158
|
-
var beforePosition = null,
|
|
1159
|
-
afterPosition = null;
|
|
1160
|
-
index < targetIndex
|
|
1161
|
-
? ((afterPosition =
|
|
1162
|
-
targetIndex === this._items.length - 1
|
|
1163
|
-
? void 0
|
|
1164
|
-
: this._items[targetIndex + 1]._getParentKeyOrThrow()),
|
|
1165
|
-
(beforePosition = this._items[targetIndex]._getParentKeyOrThrow()))
|
|
1166
|
-
: ((afterPosition = this._items[targetIndex]._getParentKeyOrThrow()),
|
|
1167
|
-
(beforePosition =
|
|
1168
|
-
0 === targetIndex
|
|
1169
|
-
? void 0
|
|
1170
|
-
: this._items[targetIndex - 1]._getParentKeyOrThrow()));
|
|
1171
|
-
var position = makePosition(beforePosition, afterPosition),
|
|
1172
|
-
item = this._items[index],
|
|
1173
|
-
previousPosition = item._getParentKeyOrThrow();
|
|
1174
|
-
if (
|
|
1175
|
-
(item._setParentLink(this, position),
|
|
1176
|
-
this._sortItems(),
|
|
1177
|
-
this._doc && this._id)
|
|
1178
|
-
) {
|
|
1179
|
-
var storageUpdates = new Map([
|
|
1180
|
-
[this._id, makeUpdate(this, [moveDelta(index, targetIndex, item)])],
|
|
1181
|
-
]);
|
|
1182
|
-
this._doc.dispatch(
|
|
1183
|
-
[
|
|
1184
|
-
{
|
|
1185
|
-
type: exports.OpCode.SET_PARENT_KEY,
|
|
1186
|
-
id: nn(item._id),
|
|
1187
|
-
opId: this._doc.generateOpId(),
|
|
1188
|
-
parentKey: position,
|
|
1189
|
-
},
|
|
1190
|
-
],
|
|
1191
|
-
[
|
|
1192
|
-
{
|
|
1193
|
-
type: exports.OpCode.SET_PARENT_KEY,
|
|
1194
|
-
id: nn(item._id),
|
|
1195
|
-
parentKey: previousPosition,
|
|
1196
|
-
},
|
|
1197
|
-
],
|
|
1198
|
-
storageUpdates
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
}),
|
|
1202
|
-
(_proto.delete = function (index) {
|
|
1203
|
-
if (index < 0 || index >= this._items.length)
|
|
1204
|
-
throw new Error(
|
|
1205
|
-
'Cannot delete list item at index "' +
|
|
1206
|
-
index +
|
|
1207
|
-
'". index should be between 0 and ' +
|
|
1208
|
-
(this._items.length - 1)
|
|
1209
|
-
);
|
|
1210
|
-
var item = this._items[index];
|
|
1211
|
-
if ((item._detach(), this._items.splice(index, 1), this._doc)) {
|
|
1212
|
-
var childRecordId = item._id;
|
|
1213
|
-
if (childRecordId) {
|
|
1214
|
-
var storageUpdates = new Map();
|
|
1215
|
-
storageUpdates.set(
|
|
1216
|
-
nn(this._id),
|
|
1217
|
-
makeUpdate(this, [deleteDelta(index)])
|
|
1218
|
-
),
|
|
1219
|
-
this._doc.dispatch(
|
|
1220
|
-
[
|
|
1221
|
-
{
|
|
1222
|
-
id: childRecordId,
|
|
1223
|
-
opId: this._doc.generateOpId(),
|
|
1224
|
-
type: exports.OpCode.DELETE_CRDT,
|
|
1225
|
-
},
|
|
1226
|
-
],
|
|
1227
|
-
item._serialize(nn(this._id), item._getParentKeyOrThrow()),
|
|
1228
|
-
storageUpdates
|
|
1229
|
-
);
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
}),
|
|
1233
|
-
(_proto.clear = function () {
|
|
1234
|
-
if (this._doc) {
|
|
1235
|
-
for (
|
|
1236
|
-
var _step5,
|
|
1237
|
-
ops = [],
|
|
1238
|
-
reverseOps = [],
|
|
1239
|
-
updateDelta = [],
|
|
1240
|
-
_iterator5 = _createForOfIteratorHelperLoose(this._items);
|
|
1241
|
-
!(_step5 = _iterator5()).done;
|
|
1242
|
-
|
|
1243
|
-
) {
|
|
1244
|
-
var item = _step5.value;
|
|
1245
|
-
item._detach();
|
|
1246
|
-
var childId = item._id;
|
|
1247
|
-
childId &&
|
|
1248
|
-
(ops.push({
|
|
1249
|
-
type: exports.OpCode.DELETE_CRDT,
|
|
1250
|
-
id: childId,
|
|
1251
|
-
opId: this._doc.generateOpId(),
|
|
1252
|
-
}),
|
|
1253
|
-
reverseOps.push.apply(
|
|
1254
|
-
reverseOps,
|
|
1255
|
-
item._serialize(nn(this._id), item._getParentKeyOrThrow())
|
|
1256
|
-
),
|
|
1257
|
-
updateDelta.push(deleteDelta(0)));
|
|
1258
|
-
}
|
|
1259
|
-
this._items = [];
|
|
1260
|
-
var storageUpdates = new Map();
|
|
1261
|
-
storageUpdates.set(nn(this._id), makeUpdate(this, updateDelta)),
|
|
1262
|
-
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
1263
|
-
} else {
|
|
1264
|
-
for (
|
|
1265
|
-
var _step6, _iterator6 = _createForOfIteratorHelperLoose(this._items);
|
|
1266
|
-
!(_step6 = _iterator6()).done;
|
|
1267
|
-
|
|
1268
|
-
) {
|
|
1269
|
-
_step6.value._detach();
|
|
1270
|
-
}
|
|
1271
|
-
this._items = [];
|
|
1272
|
-
}
|
|
1273
|
-
}),
|
|
1274
|
-
(_proto.set = function (index, item) {
|
|
1275
|
-
if (index < 0 || index >= this._items.length)
|
|
1276
|
-
throw new Error(
|
|
1277
|
-
'Cannot set list item at index "' +
|
|
1278
|
-
index +
|
|
1279
|
-
'". index should be between 0 and ' +
|
|
1280
|
-
(this._items.length - 1)
|
|
1281
|
-
);
|
|
1282
|
-
var existingItem = this._items[index],
|
|
1283
|
-
position = existingItem._getParentKeyOrThrow(),
|
|
1284
|
-
existingId = existingItem._id;
|
|
1285
|
-
existingItem._detach();
|
|
1286
|
-
var value = lsonToLiveNode(item);
|
|
1287
|
-
if (
|
|
1288
|
-
(value._setParentLink(this, position),
|
|
1289
|
-
(this._items[index] = value),
|
|
1290
|
-
this._doc && this._id)
|
|
1291
|
-
) {
|
|
1292
|
-
var id = this._doc.generateId();
|
|
1293
|
-
value._attach(id, this._doc);
|
|
1294
|
-
var storageUpdates = new Map();
|
|
1295
|
-
storageUpdates.set(
|
|
1296
|
-
this._id,
|
|
1297
|
-
makeUpdate(this, [setDelta(index, value)])
|
|
1298
|
-
);
|
|
1299
|
-
var ops = value._serialize(this._id, position, this._doc);
|
|
1300
|
-
addIntentAndDeletedIdToOperation(ops, existingId),
|
|
1301
|
-
this._unacknowledgedSets.set(position, nn(ops[0].opId));
|
|
1302
|
-
var reverseOps = existingItem._serialize(this._id, position, void 0);
|
|
1303
|
-
addIntentAndDeletedIdToOperation(reverseOps, id),
|
|
1304
|
-
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
1305
|
-
}
|
|
1306
|
-
}),
|
|
1307
|
-
(_proto.toArray = function () {
|
|
1308
|
-
return this._items.map(function (entry) {
|
|
1309
|
-
return liveNodeToLson(entry);
|
|
1310
|
-
});
|
|
1311
|
-
}),
|
|
1312
|
-
(_proto.every = function (predicate) {
|
|
1313
|
-
return this.toArray().every(predicate);
|
|
1314
|
-
}),
|
|
1315
|
-
(_proto.filter = function (predicate) {
|
|
1316
|
-
return this.toArray().filter(predicate);
|
|
1317
|
-
}),
|
|
1318
|
-
(_proto.find = function (predicate) {
|
|
1319
|
-
return this.toArray().find(predicate);
|
|
1320
|
-
}),
|
|
1321
|
-
(_proto.findIndex = function (predicate) {
|
|
1322
|
-
return this.toArray().findIndex(predicate);
|
|
1323
|
-
}),
|
|
1324
|
-
(_proto.forEach = function (callbackfn) {
|
|
1325
|
-
return this.toArray().forEach(callbackfn);
|
|
1326
|
-
}),
|
|
1327
|
-
(_proto.get = function (index) {
|
|
1328
|
-
if (!(index < 0 || index >= this._items.length))
|
|
1329
|
-
return liveNodeToLson(this._items[index]);
|
|
1330
|
-
}),
|
|
1331
|
-
(_proto.indexOf = function (searchElement, fromIndex) {
|
|
1332
|
-
return this.toArray().indexOf(searchElement, fromIndex);
|
|
1333
|
-
}),
|
|
1334
|
-
(_proto.lastIndexOf = function (searchElement, fromIndex) {
|
|
1335
|
-
return this.toArray().lastIndexOf(searchElement, fromIndex);
|
|
1336
|
-
}),
|
|
1337
|
-
(_proto.map = function (callback) {
|
|
1338
|
-
return this._items.map(function (entry, i) {
|
|
1339
|
-
return callback(liveNodeToLson(entry), i);
|
|
1340
|
-
});
|
|
1341
|
-
}),
|
|
1342
|
-
(_proto.some = function (predicate) {
|
|
1343
|
-
return this.toArray().some(predicate);
|
|
1344
|
-
}),
|
|
1345
|
-
(_proto[_Symbol$iterator$1] = function () {
|
|
1346
|
-
return new LiveListIterator(this._items);
|
|
1347
|
-
}),
|
|
1348
|
-
(_proto._createAttachItemAndSort = function (op, key) {
|
|
1349
|
-
var newItem = creationOpToLiveNode(op);
|
|
1350
|
-
return (
|
|
1351
|
-
newItem._attach(op.id, nn(this._doc)),
|
|
1352
|
-
newItem._setParentLink(this, key),
|
|
1353
|
-
this._insertAndSort(newItem),
|
|
1354
|
-
{ newItem: newItem, newIndex: this._indexOfPosition(key) }
|
|
1355
|
-
);
|
|
1356
|
-
}),
|
|
1357
|
-
(_proto._shiftItemPosition = function (index, key) {
|
|
1358
|
-
var _this$_items5,
|
|
1359
|
-
shiftedPosition = makePosition(
|
|
1360
|
-
key,
|
|
1361
|
-
this._items.length > index + 1
|
|
1362
|
-
? null == (_this$_items5 = this._items[index + 1])
|
|
1363
|
-
? void 0
|
|
1364
|
-
: _this$_items5._getParentKeyOrThrow()
|
|
1365
|
-
: void 0
|
|
1366
|
-
);
|
|
1367
|
-
this._items[index]._setParentLink(this, shiftedPosition);
|
|
1368
|
-
}),
|
|
1369
|
-
_createClass(LiveList, [
|
|
1370
|
-
{
|
|
1371
|
-
key: "length",
|
|
1372
|
-
get: function () {
|
|
1373
|
-
return this._items.length;
|
|
1374
|
-
},
|
|
1375
|
-
},
|
|
1376
|
-
]),
|
|
1377
|
-
LiveList
|
|
1378
|
-
);
|
|
1379
|
-
})(AbstractCrdt);
|
|
1380
|
-
_Symbol$iterator2 = Symbol.iterator;
|
|
1381
|
-
var _Symbol$iterator,
|
|
1382
|
-
LiveListIterator = (function () {
|
|
1383
|
-
function LiveListIterator(items) {
|
|
1384
|
-
(this._innerIterator = void 0),
|
|
1385
|
-
(this._innerIterator = items[Symbol.iterator]());
|
|
1386
|
-
}
|
|
1387
|
-
var _proto2 = LiveListIterator.prototype;
|
|
1388
|
-
return (
|
|
1389
|
-
(_proto2[_Symbol$iterator2] = function () {
|
|
1390
|
-
return this;
|
|
1391
|
-
}),
|
|
1392
|
-
(_proto2.next = function () {
|
|
1393
|
-
var result = this._innerIterator.next();
|
|
1394
|
-
return result.done
|
|
1395
|
-
? { done: !0, value: void 0 }
|
|
1396
|
-
: { value: liveNodeToLson(result.value) };
|
|
1397
|
-
}),
|
|
1398
|
-
LiveListIterator
|
|
1399
|
-
);
|
|
1400
|
-
})();
|
|
1401
|
-
function makeUpdate(liveList, deltaUpdates) {
|
|
1402
|
-
return { node: liveList, type: "LiveList", updates: deltaUpdates };
|
|
1403
|
-
}
|
|
1404
|
-
function setDelta(index, item) {
|
|
1405
|
-
return {
|
|
1406
|
-
index: index,
|
|
1407
|
-
type: "set",
|
|
1408
|
-
item: item instanceof LiveRegister ? item.data : item,
|
|
1409
|
-
};
|
|
1410
|
-
}
|
|
1411
|
-
function deleteDelta(index) {
|
|
1412
|
-
return { index: index, type: "delete" };
|
|
1413
|
-
}
|
|
1414
|
-
function insertDelta(index, item) {
|
|
1415
|
-
return {
|
|
1416
|
-
index: index,
|
|
1417
|
-
type: "insert",
|
|
1418
|
-
item: item instanceof LiveRegister ? item.data : item,
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
function moveDelta(previousIndex, index, item) {
|
|
1422
|
-
return {
|
|
1423
|
-
index: index,
|
|
1424
|
-
type: "move",
|
|
1425
|
-
previousIndex: previousIndex,
|
|
1426
|
-
item: item instanceof LiveRegister ? item.data : item,
|
|
1427
|
-
};
|
|
1428
|
-
}
|
|
1429
|
-
function addIntentAndDeletedIdToOperation(ops, deletedId) {
|
|
1430
|
-
if (0 === ops.length)
|
|
1431
|
-
throw new Error(
|
|
1432
|
-
"Internal error. Serialized LiveStructure should have at least 1 operation"
|
|
1433
|
-
);
|
|
1434
|
-
var firstOp = ops[0];
|
|
1435
|
-
(firstOp.intent = "set"), (firstOp.deletedId = deletedId);
|
|
1436
|
-
}
|
|
1437
|
-
_Symbol$iterator = Symbol.iterator;
|
|
1438
|
-
var LiveMap = (function (_AbstractCrdt) {
|
|
1439
|
-
function LiveMap(entries) {
|
|
1440
|
-
var _this;
|
|
1441
|
-
if (
|
|
1442
|
-
(((_this = _AbstractCrdt.call(this) || this)._map = void 0),
|
|
1443
|
-
(_this.unacknowledgedSet = void 0),
|
|
1444
|
-
errorIf(
|
|
1445
|
-
null === entries,
|
|
1446
|
-
"Support for calling `new LiveMap(null)` will be removed in @liveblocks/client 0.18. Please call as `new LiveMap()`, or `new LiveMap([])`."
|
|
1447
|
-
),
|
|
1448
|
-
(_this.unacknowledgedSet = new Map()),
|
|
1449
|
-
entries)
|
|
1450
|
-
) {
|
|
1451
|
-
for (
|
|
1452
|
-
var _step,
|
|
1453
|
-
mappedEntries = [],
|
|
1454
|
-
_iterator = _createForOfIteratorHelperLoose(entries);
|
|
1455
|
-
!(_step = _iterator()).done;
|
|
1456
|
-
|
|
1457
|
-
) {
|
|
1458
|
-
var entry = _step.value,
|
|
1459
|
-
_value = lsonToLiveNode(entry[1]);
|
|
1460
|
-
_value._setParentLink(_assertThisInitialized(_this), entry[0]),
|
|
1461
|
-
mappedEntries.push([entry[0], _value]);
|
|
1462
|
-
}
|
|
1463
|
-
_this._map = new Map(mappedEntries);
|
|
1464
|
-
} else _this._map = new Map();
|
|
1465
|
-
return _this;
|
|
1466
|
-
}
|
|
1467
|
-
_inheritsLoose(LiveMap, _AbstractCrdt);
|
|
1468
|
-
var _proto = LiveMap.prototype;
|
|
1469
|
-
return (
|
|
1470
|
-
(_proto._serialize = function (parentId, parentKey, doc) {
|
|
1471
|
-
if (null == this._id)
|
|
1472
|
-
throw new Error("Cannot serialize item is not attached");
|
|
1473
|
-
var ops = [],
|
|
1474
|
-
op = {
|
|
1475
|
-
id: this._id,
|
|
1476
|
-
opId: null == doc ? void 0 : doc.generateOpId(),
|
|
1477
|
-
type: exports.OpCode.CREATE_MAP,
|
|
1478
|
-
parentId: parentId,
|
|
1479
|
-
parentKey: parentKey,
|
|
1480
|
-
};
|
|
1481
|
-
ops.push(op);
|
|
1482
|
-
for (
|
|
1483
|
-
var _step2, _iterator2 = _createForOfIteratorHelperLoose(this._map);
|
|
1484
|
-
!(_step2 = _iterator2()).done;
|
|
1485
|
-
|
|
1486
|
-
) {
|
|
1487
|
-
var _step2$value = _step2.value,
|
|
1488
|
-
_key2 = _step2$value[0],
|
|
1489
|
-
_value2 = _step2$value[1];
|
|
1490
|
-
ops.push.apply(ops, _value2._serialize(this._id, _key2, doc));
|
|
1491
|
-
}
|
|
1492
|
-
return ops;
|
|
1493
|
-
}),
|
|
1494
|
-
(LiveMap._deserialize = function (_ref, parentToChildren, doc) {
|
|
1495
|
-
var id = _ref[0];
|
|
1496
|
-
_ref[1];
|
|
1497
|
-
var map = new LiveMap();
|
|
1498
|
-
map._attach(id, doc);
|
|
1499
|
-
var children = parentToChildren.get(id);
|
|
1500
|
-
if (null == children) return map;
|
|
1501
|
-
for (
|
|
1502
|
-
var _step3, _iterator3 = _createForOfIteratorHelperLoose(children);
|
|
1503
|
-
!(_step3 = _iterator3()).done;
|
|
1504
|
-
|
|
1505
|
-
) {
|
|
1506
|
-
var _step3$value = _step3.value,
|
|
1507
|
-
_id = _step3$value[0],
|
|
1508
|
-
crdt = _step3$value[1],
|
|
1509
|
-
child = deserialize([_id, crdt], parentToChildren, doc);
|
|
1510
|
-
child._setParentLink(map, crdt.parentKey),
|
|
1511
|
-
map._map.set(crdt.parentKey, child);
|
|
1512
|
-
}
|
|
1513
|
-
return map;
|
|
1514
|
-
}),
|
|
1515
|
-
(_proto._attach = function (id, doc) {
|
|
1516
|
-
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1517
|
-
for (
|
|
1518
|
-
var _step4, _iterator4 = _createForOfIteratorHelperLoose(this._map);
|
|
1519
|
-
!(_step4 = _iterator4()).done;
|
|
1520
|
-
|
|
1521
|
-
) {
|
|
1522
|
-
var _step4$value = _step4.value;
|
|
1523
|
-
_step4$value[0];
|
|
1524
|
-
var _value3 = _step4$value[1];
|
|
1525
|
-
isLiveNode(_value3) && _value3._attach(doc.generateId(), doc);
|
|
1526
|
-
}
|
|
1527
|
-
}),
|
|
1528
|
-
(_proto._attachChild = function (op, source) {
|
|
1529
|
-
var _updates;
|
|
1530
|
-
if (null == this._doc)
|
|
1531
|
-
throw new Error("Can't attach child if doc is not present");
|
|
1532
|
-
var id = op.id,
|
|
1533
|
-
parentKey = op.parentKey,
|
|
1534
|
-
opId = op.opId,
|
|
1535
|
-
key = parentKey,
|
|
1536
|
-
child = creationOpToLiveNode(op);
|
|
1537
|
-
if (void 0 !== this._doc.getItem(id)) return { modified: !1 };
|
|
1538
|
-
if (source === exports.OpSource.ACK) {
|
|
1539
|
-
var lastUpdateOpId = this.unacknowledgedSet.get(key);
|
|
1540
|
-
if (lastUpdateOpId === opId)
|
|
1541
|
-
return this.unacknowledgedSet.delete(key), { modified: !1 };
|
|
1542
|
-
if (null != lastUpdateOpId) return { modified: !1 };
|
|
1543
|
-
} else
|
|
1544
|
-
source === exports.OpSource.REMOTE &&
|
|
1545
|
-
this.unacknowledgedSet.delete(key);
|
|
1546
|
-
var reverse,
|
|
1547
|
-
previousValue = this._map.get(key);
|
|
1548
|
-
if (previousValue) {
|
|
1549
|
-
var thisId = nn(this._id);
|
|
1550
|
-
(reverse = previousValue._serialize(thisId, key)),
|
|
1551
|
-
previousValue._detach();
|
|
1552
|
-
} else reverse = [{ type: exports.OpCode.DELETE_CRDT, id: id }];
|
|
1553
|
-
return (
|
|
1554
|
-
child._setParentLink(this, key),
|
|
1555
|
-
child._attach(id, this._doc),
|
|
1556
|
-
this._map.set(key, child),
|
|
1557
|
-
{
|
|
1558
|
-
modified: {
|
|
1559
|
-
node: this,
|
|
1560
|
-
type: "LiveMap",
|
|
1561
|
-
updates:
|
|
1562
|
-
((_updates = {}),
|
|
1563
|
-
(_updates[key] = { type: "update" }),
|
|
1564
|
-
_updates),
|
|
1565
|
-
},
|
|
1566
|
-
reverse: reverse,
|
|
1567
|
-
}
|
|
1568
|
-
);
|
|
1569
|
-
}),
|
|
1570
|
-
(_proto._detach = function () {
|
|
1571
|
-
_AbstractCrdt.prototype._detach.call(this);
|
|
1572
|
-
for (
|
|
1573
|
-
var _step5,
|
|
1574
|
-
_iterator5 = _createForOfIteratorHelperLoose(this._map.values());
|
|
1575
|
-
!(_step5 = _iterator5()).done;
|
|
1576
|
-
|
|
1577
|
-
) {
|
|
1578
|
-
_step5.value._detach();
|
|
1579
|
-
}
|
|
1580
|
-
}),
|
|
1581
|
-
(_proto._detachChild = function (child) {
|
|
1582
|
-
for (
|
|
1583
|
-
var _updates2,
|
|
1584
|
-
_step6,
|
|
1585
|
-
id = nn(this._id),
|
|
1586
|
-
parentKey = nn(child._parentKey),
|
|
1587
|
-
reverse = child._serialize(id, parentKey, this._doc),
|
|
1588
|
-
_iterator6 = _createForOfIteratorHelperLoose(this._map);
|
|
1589
|
-
!(_step6 = _iterator6()).done;
|
|
1590
|
-
|
|
1591
|
-
) {
|
|
1592
|
-
var _step6$value = _step6.value,
|
|
1593
|
-
_key3 = _step6$value[0];
|
|
1594
|
-
_step6$value[1] === child && this._map.delete(_key3);
|
|
1595
|
-
}
|
|
1596
|
-
return (
|
|
1597
|
-
child._detach(),
|
|
1598
|
-
{
|
|
1599
|
-
modified: {
|
|
1600
|
-
node: this,
|
|
1601
|
-
type: "LiveMap",
|
|
1602
|
-
updates:
|
|
1603
|
-
((_updates2 = {}),
|
|
1604
|
-
(_updates2[parentKey] = { type: "delete" }),
|
|
1605
|
-
_updates2),
|
|
1606
|
-
},
|
|
1607
|
-
reverse: reverse,
|
|
1608
|
-
}
|
|
1609
|
-
);
|
|
1610
|
-
}),
|
|
1611
|
-
(_proto._toSerializedCrdt = function () {
|
|
1612
|
-
if ("HasParent" !== this.parent.type)
|
|
1613
|
-
throw new Error("Cannot serialize LiveMap if parent is missing");
|
|
1614
|
-
return {
|
|
1615
|
-
type: exports.CrdtType.MAP,
|
|
1616
|
-
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
1617
|
-
parentKey: this.parent.key,
|
|
1618
|
-
};
|
|
1619
|
-
}),
|
|
1620
|
-
(_proto.get = function (key) {
|
|
1621
|
-
var value = this._map.get(key);
|
|
1622
|
-
if (null != value) return liveNodeToLson(value);
|
|
1623
|
-
}),
|
|
1624
|
-
(_proto.set = function (key, value) {
|
|
1625
|
-
var oldValue = this._map.get(key);
|
|
1626
|
-
oldValue && oldValue._detach();
|
|
1627
|
-
var item = lsonToLiveNode(value);
|
|
1628
|
-
if (
|
|
1629
|
-
(item._setParentLink(this, key),
|
|
1630
|
-
this._map.set(key, item),
|
|
1631
|
-
this._doc && this._id)
|
|
1632
|
-
) {
|
|
1633
|
-
var _updates3,
|
|
1634
|
-
id = this._doc.generateId();
|
|
1635
|
-
item._attach(id, this._doc);
|
|
1636
|
-
var storageUpdates = new Map();
|
|
1637
|
-
storageUpdates.set(this._id, {
|
|
1638
|
-
node: this,
|
|
1639
|
-
type: "LiveMap",
|
|
1640
|
-
updates:
|
|
1641
|
-
((_updates3 = {}),
|
|
1642
|
-
(_updates3[key] = { type: "update" }),
|
|
1643
|
-
_updates3),
|
|
1644
|
-
});
|
|
1645
|
-
var ops = item._serialize(this._id, key, this._doc);
|
|
1646
|
-
this.unacknowledgedSet.set(key, nn(ops[0].opId)),
|
|
1647
|
-
this._doc.dispatch(
|
|
1648
|
-
item._serialize(this._id, key, this._doc),
|
|
1649
|
-
oldValue
|
|
1650
|
-
? oldValue._serialize(this._id, key)
|
|
1651
|
-
: [{ type: exports.OpCode.DELETE_CRDT, id: id }],
|
|
1652
|
-
storageUpdates
|
|
1653
|
-
);
|
|
1654
|
-
}
|
|
1655
|
-
}),
|
|
1656
|
-
(_proto.has = function (key) {
|
|
1657
|
-
return this._map.has(key);
|
|
1658
|
-
}),
|
|
1659
|
-
(_proto.delete = function (key) {
|
|
1660
|
-
var item = this._map.get(key);
|
|
1661
|
-
if (null == item) return !1;
|
|
1662
|
-
if ((item._detach(), this._map.delete(key), this._doc && item._id)) {
|
|
1663
|
-
var _updates4,
|
|
1664
|
-
thisId = nn(this._id),
|
|
1665
|
-
storageUpdates = new Map();
|
|
1666
|
-
storageUpdates.set(thisId, {
|
|
1667
|
-
node: this,
|
|
1668
|
-
type: "LiveMap",
|
|
1669
|
-
updates:
|
|
1670
|
-
((_updates4 = {}),
|
|
1671
|
-
(_updates4[key] = { type: "delete" }),
|
|
1672
|
-
_updates4),
|
|
1673
|
-
}),
|
|
1674
|
-
this._doc.dispatch(
|
|
1675
|
-
[
|
|
1676
|
-
{
|
|
1677
|
-
type: exports.OpCode.DELETE_CRDT,
|
|
1678
|
-
id: item._id,
|
|
1679
|
-
opId: this._doc.generateOpId(),
|
|
1680
|
-
},
|
|
1681
|
-
],
|
|
1682
|
-
item._serialize(thisId, key),
|
|
1683
|
-
storageUpdates
|
|
1684
|
-
);
|
|
1685
|
-
}
|
|
1686
|
-
return !0;
|
|
1687
|
-
}),
|
|
1688
|
-
(_proto.entries = function () {
|
|
1689
|
-
var _ref2,
|
|
1690
|
-
innerIterator = this._map.entries();
|
|
1691
|
-
return (
|
|
1692
|
-
((_ref2 = {})[Symbol.iterator] = function () {
|
|
1693
|
-
return this;
|
|
1694
|
-
}),
|
|
1695
|
-
(_ref2.next = function () {
|
|
1696
|
-
var iteratorValue = innerIterator.next();
|
|
1697
|
-
return iteratorValue.done
|
|
1698
|
-
? { done: !0, value: void 0 }
|
|
1699
|
-
: {
|
|
1700
|
-
value: [
|
|
1701
|
-
iteratorValue.value[0],
|
|
1702
|
-
liveNodeToLson(iteratorValue.value[1]),
|
|
1703
|
-
],
|
|
1704
|
-
};
|
|
1705
|
-
}),
|
|
1706
|
-
_ref2
|
|
1707
|
-
);
|
|
1708
|
-
}),
|
|
1709
|
-
(_proto[_Symbol$iterator] = function () {
|
|
1710
|
-
return this.entries();
|
|
1711
|
-
}),
|
|
1712
|
-
(_proto.keys = function () {
|
|
1713
|
-
return this._map.keys();
|
|
1714
|
-
}),
|
|
1715
|
-
(_proto.values = function () {
|
|
1716
|
-
var _ref3,
|
|
1717
|
-
innerIterator = this._map.values();
|
|
1718
|
-
return (
|
|
1719
|
-
((_ref3 = {})[Symbol.iterator] = function () {
|
|
1720
|
-
return this;
|
|
1721
|
-
}),
|
|
1722
|
-
(_ref3.next = function () {
|
|
1723
|
-
var iteratorValue = innerIterator.next();
|
|
1724
|
-
return iteratorValue.done
|
|
1725
|
-
? { done: !0, value: void 0 }
|
|
1726
|
-
: { value: liveNodeToLson(iteratorValue.value) };
|
|
1727
|
-
}),
|
|
1728
|
-
_ref3
|
|
1729
|
-
);
|
|
1730
|
-
}),
|
|
1731
|
-
(_proto.forEach = function (callback) {
|
|
1732
|
-
for (
|
|
1733
|
-
var _step7, _iterator7 = _createForOfIteratorHelperLoose(this);
|
|
1734
|
-
!(_step7 = _iterator7()).done;
|
|
1735
|
-
|
|
1736
|
-
) {
|
|
1737
|
-
var entry = _step7.value;
|
|
1738
|
-
callback(entry[1], entry[0], this);
|
|
1739
|
-
}
|
|
1740
|
-
}),
|
|
1741
|
-
_createClass(LiveMap, [
|
|
1742
|
-
{
|
|
1743
|
-
key: "size",
|
|
1744
|
-
get: function () {
|
|
1745
|
-
return this._map.size;
|
|
1746
|
-
},
|
|
1747
|
-
},
|
|
1748
|
-
]),
|
|
1749
|
-
LiveMap
|
|
1750
|
-
);
|
|
1751
|
-
})(AbstractCrdt),
|
|
1752
|
-
LiveObject = (function (_AbstractCrdt) {
|
|
1753
|
-
function LiveObject(obj) {
|
|
1754
|
-
var _this;
|
|
1755
|
-
for (var key in (void 0 === obj && (obj = {}),
|
|
1756
|
-
((_this = _AbstractCrdt.call(this) || this)._map = void 0),
|
|
1757
|
-
(_this._propToLastUpdate = void 0),
|
|
1758
|
-
(_this._propToLastUpdate = new Map()),
|
|
1759
|
-
obj)) {
|
|
1760
|
-
var value = obj[key];
|
|
1761
|
-
void 0 !== value &&
|
|
1762
|
-
isLiveNode(value) &&
|
|
1763
|
-
value._setParentLink(_assertThisInitialized(_this), key);
|
|
1764
|
-
}
|
|
1765
|
-
return (_this._map = new Map(Object.entries(obj))), _this;
|
|
1766
|
-
}
|
|
1767
|
-
_inheritsLoose(LiveObject, _AbstractCrdt);
|
|
1768
|
-
var _proto = LiveObject.prototype;
|
|
1769
|
-
return (
|
|
1770
|
-
(_proto._serialize = function (parentId, parentKey, doc) {
|
|
1771
|
-
if (null == this._id)
|
|
1772
|
-
throw new Error("Cannot serialize item is not attached");
|
|
1773
|
-
var opId = null == doc ? void 0 : doc.generateOpId(),
|
|
1774
|
-
ops = [],
|
|
1775
|
-
op =
|
|
1776
|
-
void 0 !== parentId && void 0 !== parentKey
|
|
1777
|
-
? {
|
|
1778
|
-
type: exports.OpCode.CREATE_OBJECT,
|
|
1779
|
-
id: this._id,
|
|
1780
|
-
opId: opId,
|
|
1781
|
-
parentId: parentId,
|
|
1782
|
-
parentKey: parentKey,
|
|
1783
|
-
data: {},
|
|
1784
|
-
}
|
|
1785
|
-
: {
|
|
1786
|
-
type: exports.OpCode.CREATE_OBJECT,
|
|
1787
|
-
id: this._id,
|
|
1788
|
-
opId: opId,
|
|
1789
|
-
data: {},
|
|
1790
|
-
};
|
|
1791
|
-
ops.push(op);
|
|
1792
|
-
for (
|
|
1793
|
-
var _step, _iterator = _createForOfIteratorHelperLoose(this._map);
|
|
1794
|
-
!(_step = _iterator()).done;
|
|
1795
|
-
|
|
1796
|
-
) {
|
|
1797
|
-
var _step$value = _step.value,
|
|
1798
|
-
key = _step$value[0],
|
|
1799
|
-
value = _step$value[1];
|
|
1800
|
-
isLiveNode(value)
|
|
1801
|
-
? ops.push.apply(ops, value._serialize(this._id, key, doc))
|
|
1802
|
-
: (op.data[key] = value);
|
|
1803
|
-
}
|
|
1804
|
-
return ops;
|
|
1805
|
-
}),
|
|
1806
|
-
(LiveObject._deserialize = function (_ref, parentToChildren, doc) {
|
|
1807
|
-
var id = _ref[0],
|
|
1808
|
-
liveObj = new LiveObject(_ref[1].data);
|
|
1809
|
-
return (
|
|
1810
|
-
liveObj._attach(id, doc),
|
|
1811
|
-
this._deserializeChildren(liveObj, parentToChildren, doc)
|
|
1812
|
-
);
|
|
1813
|
-
}),
|
|
1814
|
-
(LiveObject._deserializeChildren = function (
|
|
1815
|
-
liveObj,
|
|
1816
|
-
parentToChildren,
|
|
1817
|
-
doc
|
|
1818
|
-
) {
|
|
1819
|
-
var children = parentToChildren.get(nn(liveObj._id));
|
|
1820
|
-
if (null == children) return liveObj;
|
|
1821
|
-
for (
|
|
1822
|
-
var _step2, _iterator2 = _createForOfIteratorHelperLoose(children);
|
|
1823
|
-
!(_step2 = _iterator2()).done;
|
|
1824
|
-
|
|
1825
|
-
) {
|
|
1826
|
-
var _step2$value = _step2.value,
|
|
1827
|
-
id = _step2$value[0],
|
|
1828
|
-
crdt = _step2$value[1],
|
|
1829
|
-
child = deserializeToLson([id, crdt], parentToChildren, doc);
|
|
1830
|
-
isLiveStructure(child) &&
|
|
1831
|
-
child._setParentLink(liveObj, crdt.parentKey),
|
|
1832
|
-
liveObj._map.set(crdt.parentKey, child);
|
|
1833
|
-
}
|
|
1834
|
-
return liveObj;
|
|
1835
|
-
}),
|
|
1836
|
-
(_proto._attach = function (id, doc) {
|
|
1837
|
-
_AbstractCrdt.prototype._attach.call(this, id, doc);
|
|
1838
|
-
for (
|
|
1839
|
-
var _step3, _iterator3 = _createForOfIteratorHelperLoose(this._map);
|
|
1840
|
-
!(_step3 = _iterator3()).done;
|
|
1841
|
-
|
|
1842
|
-
) {
|
|
1843
|
-
var _step3$value = _step3.value;
|
|
1844
|
-
_step3$value[0];
|
|
1845
|
-
var value = _step3$value[1];
|
|
1846
|
-
isLiveNode(value) && value._attach(doc.generateId(), doc);
|
|
1847
|
-
}
|
|
1848
|
-
}),
|
|
1849
|
-
(_proto._attachChild = function (op, source) {
|
|
1850
|
-
var _updates;
|
|
1851
|
-
if (null == this._doc)
|
|
1852
|
-
throw new Error("Can't attach child if doc is not present");
|
|
1853
|
-
var id = op.id,
|
|
1854
|
-
opId = op.opId,
|
|
1855
|
-
key = op.parentKey,
|
|
1856
|
-
child = creationOpToLson(op);
|
|
1857
|
-
if (void 0 !== this._doc.getItem(id))
|
|
1858
|
-
return (
|
|
1859
|
-
this._propToLastUpdate.get(key) === opId &&
|
|
1860
|
-
this._propToLastUpdate.delete(key),
|
|
1861
|
-
{ modified: !1 }
|
|
1862
|
-
);
|
|
1863
|
-
if (source === exports.OpSource.UNDOREDO_RECONNECT)
|
|
1864
|
-
this._propToLastUpdate.set(key, nn(opId));
|
|
1865
|
-
else if (void 0 !== this._propToLastUpdate.get(key))
|
|
1866
|
-
return this._propToLastUpdate.get(key) === opId
|
|
1867
|
-
? (this._propToLastUpdate.delete(key), { modified: !1 })
|
|
1868
|
-
: { modified: !1 };
|
|
1869
|
-
var reverse,
|
|
1870
|
-
thisId = nn(this._id),
|
|
1871
|
-
previousValue = this._map.get(key);
|
|
1872
|
-
if (isLiveNode(previousValue))
|
|
1873
|
-
(reverse = previousValue._serialize(thisId, key)),
|
|
1874
|
-
previousValue._detach();
|
|
1875
|
-
else if (void 0 === previousValue)
|
|
1876
|
-
reverse = [
|
|
1877
|
-
{ type: exports.OpCode.DELETE_OBJECT_KEY, id: thisId, key: key },
|
|
1878
|
-
];
|
|
1879
|
-
else {
|
|
1880
|
-
var _data;
|
|
1881
|
-
reverse = [
|
|
1882
|
-
{
|
|
1883
|
-
type: exports.OpCode.UPDATE_OBJECT,
|
|
1884
|
-
id: thisId,
|
|
1885
|
-
data: ((_data = {}), (_data[key] = previousValue), _data),
|
|
1886
|
-
},
|
|
1887
|
-
];
|
|
1888
|
-
}
|
|
1889
|
-
return (
|
|
1890
|
-
this._map.set(key, child),
|
|
1891
|
-
isLiveStructure(child) &&
|
|
1892
|
-
(child._setParentLink(this, key), child._attach(id, this._doc)),
|
|
1893
|
-
{
|
|
1894
|
-
reverse: reverse,
|
|
1895
|
-
modified: {
|
|
1896
|
-
node: this,
|
|
1897
|
-
type: "LiveObject",
|
|
1898
|
-
updates:
|
|
1899
|
-
((_updates = {}),
|
|
1900
|
-
(_updates[key] = { type: "update" }),
|
|
1901
|
-
_updates),
|
|
1902
|
-
},
|
|
1903
|
-
}
|
|
1904
|
-
);
|
|
1905
|
-
}),
|
|
1906
|
-
(_proto._detachChild = function (child) {
|
|
1907
|
-
if (child) {
|
|
1908
|
-
for (
|
|
1909
|
-
var _updates2,
|
|
1910
|
-
_step4,
|
|
1911
|
-
id = nn(this._id),
|
|
1912
|
-
_parentKey = nn(child._parentKey),
|
|
1913
|
-
reverse = child._serialize(id, _parentKey, this._doc),
|
|
1914
|
-
_iterator4 = _createForOfIteratorHelperLoose(this._map);
|
|
1915
|
-
!(_step4 = _iterator4()).done;
|
|
1916
|
-
|
|
1917
|
-
) {
|
|
1918
|
-
var _step4$value = _step4.value,
|
|
1919
|
-
key = _step4$value[0];
|
|
1920
|
-
_step4$value[1] === child && this._map.delete(key);
|
|
1921
|
-
}
|
|
1922
|
-
return (
|
|
1923
|
-
child._detach(),
|
|
1924
|
-
{
|
|
1925
|
-
modified: {
|
|
1926
|
-
node: this,
|
|
1927
|
-
type: "LiveObject",
|
|
1928
|
-
updates:
|
|
1929
|
-
((_updates2 = {}),
|
|
1930
|
-
(_updates2[_parentKey] = { type: "delete" }),
|
|
1931
|
-
_updates2),
|
|
1932
|
-
},
|
|
1933
|
-
reverse: reverse,
|
|
1934
|
-
}
|
|
1935
|
-
);
|
|
1936
|
-
}
|
|
1937
|
-
return { modified: !1 };
|
|
1938
|
-
}),
|
|
1939
|
-
(_proto._detach = function () {
|
|
1940
|
-
_AbstractCrdt.prototype._detach.call(this);
|
|
1941
|
-
for (
|
|
1942
|
-
var _step5,
|
|
1943
|
-
_iterator5 = _createForOfIteratorHelperLoose(this._map.values());
|
|
1944
|
-
!(_step5 = _iterator5()).done;
|
|
1945
|
-
|
|
1946
|
-
) {
|
|
1947
|
-
var value = _step5.value;
|
|
1948
|
-
isLiveNode(value) && value._detach();
|
|
1949
|
-
}
|
|
1950
|
-
}),
|
|
1951
|
-
(_proto._apply = function (op, isLocal) {
|
|
1952
|
-
return op.type === exports.OpCode.UPDATE_OBJECT
|
|
1953
|
-
? this._applyUpdate(op, isLocal)
|
|
1954
|
-
: op.type === exports.OpCode.DELETE_OBJECT_KEY
|
|
1955
|
-
? this._applyDeleteObjectKey(op)
|
|
1956
|
-
: _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
1957
|
-
}),
|
|
1958
|
-
(_proto._toSerializedCrdt = function () {
|
|
1959
|
-
for (
|
|
1960
|
-
var _step6,
|
|
1961
|
-
data = {},
|
|
1962
|
-
_iterator6 = _createForOfIteratorHelperLoose(this._map);
|
|
1963
|
-
!(_step6 = _iterator6()).done;
|
|
1964
|
-
|
|
1965
|
-
) {
|
|
1966
|
-
var _step6$value = _step6.value,
|
|
1967
|
-
key = _step6$value[0],
|
|
1968
|
-
value = _step6$value[1];
|
|
1969
|
-
isLiveNode(value) || (data[key] = value);
|
|
1970
|
-
}
|
|
1971
|
-
return "HasParent" === this.parent.type && this.parent.node._id
|
|
1972
|
-
? {
|
|
1973
|
-
type: exports.CrdtType.OBJECT,
|
|
1974
|
-
parentId: this.parent.node._id,
|
|
1975
|
-
parentKey: this.parent.key,
|
|
1976
|
-
data: data,
|
|
1977
|
-
}
|
|
1978
|
-
: { type: exports.CrdtType.OBJECT, data: data };
|
|
1979
|
-
}),
|
|
1980
|
-
(_proto._applyUpdate = function (op, isLocal) {
|
|
1981
|
-
var isModified = !1,
|
|
1982
|
-
id = nn(this._id),
|
|
1983
|
-
reverse = [],
|
|
1984
|
-
reverseUpdate = {
|
|
1985
|
-
type: exports.OpCode.UPDATE_OBJECT,
|
|
1986
|
-
id: id,
|
|
1987
|
-
data: {},
|
|
1988
|
-
};
|
|
1989
|
-
for (var key in (reverse.push(reverseUpdate), op.data)) {
|
|
1990
|
-
var oldValue = this._map.get(key);
|
|
1991
|
-
isLiveNode(oldValue)
|
|
1992
|
-
? (reverse.push.apply(reverse, oldValue._serialize(id, key)),
|
|
1993
|
-
oldValue._detach())
|
|
1994
|
-
: void 0 !== oldValue
|
|
1995
|
-
? (reverseUpdate.data[key] = oldValue)
|
|
1996
|
-
: void 0 === oldValue &&
|
|
1997
|
-
reverse.push({
|
|
1998
|
-
type: exports.OpCode.DELETE_OBJECT_KEY,
|
|
1999
|
-
id: id,
|
|
2000
|
-
key: key,
|
|
2001
|
-
});
|
|
2002
|
-
}
|
|
2003
|
-
var updateDelta = {};
|
|
2004
|
-
for (var _key2 in op.data) {
|
|
2005
|
-
var value = op.data[_key2];
|
|
2006
|
-
if (void 0 !== value) {
|
|
2007
|
-
if (isLocal) this._propToLastUpdate.set(_key2, nn(op.opId));
|
|
2008
|
-
else {
|
|
2009
|
-
if (null != this._propToLastUpdate.get(_key2)) {
|
|
2010
|
-
if (this._propToLastUpdate.get(_key2) === op.opId) {
|
|
2011
|
-
this._propToLastUpdate.delete(_key2);
|
|
2012
|
-
continue;
|
|
2013
|
-
}
|
|
2014
|
-
continue;
|
|
2015
|
-
}
|
|
2016
|
-
isModified = !0;
|
|
2017
|
-
}
|
|
2018
|
-
var _oldValue = this._map.get(_key2);
|
|
2019
|
-
isLiveNode(_oldValue) && _oldValue._detach(),
|
|
2020
|
-
(isModified = !0),
|
|
2021
|
-
(updateDelta[_key2] = { type: "update" }),
|
|
2022
|
-
this._map.set(_key2, value);
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
return (
|
|
2026
|
-
0 !== Object.keys(reverseUpdate.data).length &&
|
|
2027
|
-
reverse.unshift(reverseUpdate),
|
|
2028
|
-
isModified
|
|
2029
|
-
? {
|
|
2030
|
-
modified: {
|
|
2031
|
-
node: this,
|
|
2032
|
-
type: "LiveObject",
|
|
2033
|
-
updates: updateDelta,
|
|
2034
|
-
},
|
|
2035
|
-
reverse: reverse,
|
|
2036
|
-
}
|
|
2037
|
-
: { modified: !1 }
|
|
2038
|
-
);
|
|
2039
|
-
}),
|
|
2040
|
-
(_proto._applyDeleteObjectKey = function (op) {
|
|
2041
|
-
var _updates3,
|
|
2042
|
-
key = op.key;
|
|
2043
|
-
if (!1 === this._map.has(key)) return { modified: !1 };
|
|
2044
|
-
if (void 0 !== this._propToLastUpdate.get(key)) return { modified: !1 };
|
|
2045
|
-
var oldValue = this._map.get(key),
|
|
2046
|
-
id = nn(this._id),
|
|
2047
|
-
reverse = [];
|
|
2048
|
-
if (isLiveNode(oldValue))
|
|
2049
|
-
(reverse = oldValue._serialize(id, op.key)), oldValue._detach();
|
|
2050
|
-
else if (void 0 !== oldValue) {
|
|
2051
|
-
var _data2;
|
|
2052
|
-
reverse = [
|
|
2053
|
-
{
|
|
2054
|
-
type: exports.OpCode.UPDATE_OBJECT,
|
|
2055
|
-
id: id,
|
|
2056
|
-
data: ((_data2 = {}), (_data2[key] = oldValue), _data2),
|
|
2057
|
-
},
|
|
2058
|
-
];
|
|
2059
|
-
}
|
|
2060
|
-
return (
|
|
2061
|
-
this._map.delete(key),
|
|
2062
|
-
{
|
|
2063
|
-
modified: {
|
|
2064
|
-
node: this,
|
|
2065
|
-
type: "LiveObject",
|
|
2066
|
-
updates:
|
|
2067
|
-
((_updates3 = {}),
|
|
2068
|
-
(_updates3[op.key] = { type: "delete" }),
|
|
2069
|
-
_updates3),
|
|
2070
|
-
},
|
|
2071
|
-
reverse: reverse,
|
|
2072
|
-
}
|
|
2073
|
-
);
|
|
2074
|
-
}),
|
|
2075
|
-
(_proto.toObject = function () {
|
|
2076
|
-
return (function (iterable) {
|
|
2077
|
-
for (
|
|
2078
|
-
var _step3,
|
|
2079
|
-
obj = {},
|
|
2080
|
-
_iterator3 = _createForOfIteratorHelperLoose(iterable);
|
|
2081
|
-
!(_step3 = _iterator3()).done;
|
|
2082
|
-
|
|
2083
|
-
) {
|
|
2084
|
-
var _step3$value = _step3.value,
|
|
2085
|
-
_key4 = _step3$value[0],
|
|
2086
|
-
val = _step3$value[1];
|
|
2087
|
-
obj[_key4] = val;
|
|
2088
|
-
}
|
|
2089
|
-
return obj;
|
|
2090
|
-
})(this._map);
|
|
2091
|
-
}),
|
|
2092
|
-
(_proto.set = function (key, value) {
|
|
2093
|
-
var _this$update;
|
|
2094
|
-
this.update((((_this$update = {})[key] = value), _this$update));
|
|
2095
|
-
}),
|
|
2096
|
-
(_proto.get = function (key) {
|
|
2097
|
-
return this._map.get(key);
|
|
2098
|
-
}),
|
|
2099
|
-
(_proto.delete = function (key) {
|
|
2100
|
-
var _updates4,
|
|
2101
|
-
keyAsString = key,
|
|
2102
|
-
oldValue = this._map.get(keyAsString);
|
|
2103
|
-
if (void 0 !== oldValue) {
|
|
2104
|
-
if (null == this._doc || null == this._id)
|
|
2105
|
-
return (
|
|
2106
|
-
isLiveNode(oldValue) && oldValue._detach(),
|
|
2107
|
-
void this._map.delete(keyAsString)
|
|
2108
|
-
);
|
|
2109
|
-
var reverse, _data3;
|
|
2110
|
-
if (isLiveNode(oldValue))
|
|
2111
|
-
oldValue._detach(),
|
|
2112
|
-
(reverse = oldValue._serialize(this._id, keyAsString));
|
|
2113
|
-
else
|
|
2114
|
-
reverse = [
|
|
2115
|
-
{
|
|
2116
|
-
type: exports.OpCode.UPDATE_OBJECT,
|
|
2117
|
-
data: ((_data3 = {}), (_data3[keyAsString] = oldValue), _data3),
|
|
2118
|
-
id: this._id,
|
|
2119
|
-
},
|
|
2120
|
-
];
|
|
2121
|
-
this._map.delete(keyAsString);
|
|
2122
|
-
var storageUpdates = new Map();
|
|
2123
|
-
storageUpdates.set(this._id, {
|
|
2124
|
-
node: this,
|
|
2125
|
-
type: "LiveObject",
|
|
2126
|
-
updates:
|
|
2127
|
-
((_updates4 = {}),
|
|
2128
|
-
(_updates4[key] = { type: "delete" }),
|
|
2129
|
-
_updates4),
|
|
2130
|
-
}),
|
|
2131
|
-
this._doc.dispatch(
|
|
2132
|
-
[
|
|
2133
|
-
{
|
|
2134
|
-
type: exports.OpCode.DELETE_OBJECT_KEY,
|
|
2135
|
-
key: keyAsString,
|
|
2136
|
-
id: this._id,
|
|
2137
|
-
opId: this._doc.generateOpId(),
|
|
2138
|
-
},
|
|
2139
|
-
],
|
|
2140
|
-
reverse,
|
|
2141
|
-
storageUpdates
|
|
2142
|
-
);
|
|
2143
|
-
}
|
|
2144
|
-
}),
|
|
2145
|
-
(_proto.update = function (overrides) {
|
|
2146
|
-
var _this2 = this;
|
|
2147
|
-
if (null != this._doc && null != this._id) {
|
|
2148
|
-
var ops = [],
|
|
2149
|
-
reverseOps = [],
|
|
2150
|
-
opId = this._doc.generateOpId(),
|
|
2151
|
-
updatedProps = {},
|
|
2152
|
-
reverseUpdateOp = {
|
|
2153
|
-
id: this._id,
|
|
2154
|
-
type: exports.OpCode.UPDATE_OBJECT,
|
|
2155
|
-
data: {},
|
|
2156
|
-
},
|
|
2157
|
-
updateDelta = {};
|
|
2158
|
-
for (var _key3 in overrides) {
|
|
2159
|
-
var _newValue = overrides[_key3];
|
|
2160
|
-
if (void 0 !== _newValue) {
|
|
2161
|
-
var _oldValue2 = this._map.get(_key3);
|
|
2162
|
-
if (
|
|
2163
|
-
(isLiveNode(_oldValue2)
|
|
2164
|
-
? (reverseOps.push.apply(
|
|
2165
|
-
reverseOps,
|
|
2166
|
-
_oldValue2._serialize(this._id, _key3)
|
|
2167
|
-
),
|
|
2168
|
-
_oldValue2._detach())
|
|
2169
|
-
: void 0 === _oldValue2
|
|
2170
|
-
? reverseOps.push({
|
|
2171
|
-
type: exports.OpCode.DELETE_OBJECT_KEY,
|
|
2172
|
-
id: this._id,
|
|
2173
|
-
key: _key3,
|
|
2174
|
-
})
|
|
2175
|
-
: (reverseUpdateOp.data[_key3] = _oldValue2),
|
|
2176
|
-
isLiveNode(_newValue))
|
|
2177
|
-
) {
|
|
2178
|
-
_newValue._setParentLink(this, _key3),
|
|
2179
|
-
_newValue._attach(this._doc.generateId(), this._doc);
|
|
2180
|
-
var newAttachChildOps = _newValue._serialize(
|
|
2181
|
-
this._id,
|
|
2182
|
-
_key3,
|
|
2183
|
-
this._doc
|
|
2184
|
-
),
|
|
2185
|
-
createCrdtOp = newAttachChildOps.find(function (op) {
|
|
2186
|
-
return op.parentId === _this2._id;
|
|
2187
|
-
});
|
|
2188
|
-
createCrdtOp &&
|
|
2189
|
-
this._propToLastUpdate.set(_key3, nn(createCrdtOp.opId)),
|
|
2190
|
-
ops.push.apply(ops, newAttachChildOps);
|
|
2191
|
-
} else
|
|
2192
|
-
(updatedProps[_key3] = _newValue),
|
|
2193
|
-
this._propToLastUpdate.set(_key3, opId);
|
|
2194
|
-
this._map.set(_key3, _newValue),
|
|
2195
|
-
(updateDelta[_key3] = { type: "update" });
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
0 !== Object.keys(reverseUpdateOp.data).length &&
|
|
2199
|
-
reverseOps.unshift(reverseUpdateOp),
|
|
2200
|
-
0 !== Object.keys(updatedProps).length &&
|
|
2201
|
-
ops.unshift({
|
|
2202
|
-
opId: opId,
|
|
2203
|
-
id: this._id,
|
|
2204
|
-
type: exports.OpCode.UPDATE_OBJECT,
|
|
2205
|
-
data: updatedProps,
|
|
2206
|
-
});
|
|
2207
|
-
var storageUpdates = new Map();
|
|
2208
|
-
storageUpdates.set(this._id, {
|
|
2209
|
-
node: this,
|
|
2210
|
-
type: "LiveObject",
|
|
2211
|
-
updates: updateDelta,
|
|
2212
|
-
}),
|
|
2213
|
-
this._doc.dispatch(ops, reverseOps, storageUpdates);
|
|
2214
|
-
} else
|
|
2215
|
-
for (var key in overrides) {
|
|
2216
|
-
var newValue = overrides[key];
|
|
2217
|
-
if (void 0 !== newValue) {
|
|
2218
|
-
var oldValue = this._map.get(key);
|
|
2219
|
-
isLiveNode(oldValue) && oldValue._detach(),
|
|
2220
|
-
isLiveNode(newValue) && newValue._setParentLink(this, key),
|
|
2221
|
-
this._map.set(key, newValue);
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
}),
|
|
2225
|
-
LiveObject
|
|
2226
|
-
);
|
|
2227
|
-
})(AbstractCrdt);
|
|
2228
|
-
function creationOpToLiveNode(op) {
|
|
2229
|
-
return lsonToLiveNode(creationOpToLson(op));
|
|
2230
|
-
}
|
|
2231
|
-
function creationOpToLson(op) {
|
|
2232
|
-
switch (op.type) {
|
|
2233
|
-
case exports.OpCode.CREATE_REGISTER:
|
|
2234
|
-
return op.data;
|
|
2235
|
-
case exports.OpCode.CREATE_OBJECT:
|
|
2236
|
-
return new LiveObject(op.data);
|
|
2237
|
-
case exports.OpCode.CREATE_MAP:
|
|
2238
|
-
return new LiveMap();
|
|
2239
|
-
case exports.OpCode.CREATE_LIST:
|
|
2240
|
-
return new LiveList();
|
|
2241
|
-
default:
|
|
2242
|
-
return assertNever(0, "Unknown creation Op");
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
function deserialize(_ref, parentToChildren, doc) {
|
|
2246
|
-
var id = _ref[0],
|
|
2247
|
-
crdt = _ref[1];
|
|
2248
|
-
switch (crdt.type) {
|
|
2249
|
-
case exports.CrdtType.OBJECT:
|
|
2250
|
-
return LiveObject._deserialize([id, crdt], parentToChildren, doc);
|
|
2251
|
-
case exports.CrdtType.LIST:
|
|
2252
|
-
return LiveList._deserialize([id, crdt], parentToChildren, doc);
|
|
2253
|
-
case exports.CrdtType.MAP:
|
|
2254
|
-
return LiveMap._deserialize([id, crdt], parentToChildren, doc);
|
|
2255
|
-
case exports.CrdtType.REGISTER:
|
|
2256
|
-
return LiveRegister._deserialize([id, crdt], parentToChildren, doc);
|
|
2257
|
-
default:
|
|
2258
|
-
throw new Error("Unexpected CRDT type");
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
function deserializeToLson(_ref2, parentToChildren, doc) {
|
|
2262
|
-
var id = _ref2[0],
|
|
2263
|
-
crdt = _ref2[1];
|
|
2264
|
-
switch (crdt.type) {
|
|
2265
|
-
case exports.CrdtType.OBJECT:
|
|
2266
|
-
return LiveObject._deserialize([id, crdt], parentToChildren, doc);
|
|
2267
|
-
case exports.CrdtType.LIST:
|
|
2268
|
-
return LiveList._deserialize([id, crdt], parentToChildren, doc);
|
|
2269
|
-
case exports.CrdtType.MAP:
|
|
2270
|
-
return LiveMap._deserialize([id, crdt], parentToChildren, doc);
|
|
2271
|
-
case exports.CrdtType.REGISTER:
|
|
2272
|
-
return crdt.data;
|
|
2273
|
-
default:
|
|
2274
|
-
throw new Error("Unexpected CRDT type");
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
function isLiveStructure(value) {
|
|
2278
|
-
return (
|
|
2279
|
-
isLiveList(value) ||
|
|
2280
|
-
(function (value) {
|
|
2281
|
-
return value instanceof LiveMap;
|
|
2282
|
-
})(value) ||
|
|
2283
|
-
isLiveObject(value)
|
|
2284
|
-
);
|
|
2285
|
-
}
|
|
2286
|
-
function isLiveNode(value) {
|
|
2287
|
-
return (
|
|
2288
|
-
isLiveStructure(value) ||
|
|
2289
|
-
(function (value) {
|
|
2290
|
-
return value instanceof LiveRegister;
|
|
2291
|
-
})(value)
|
|
2292
|
-
);
|
|
2293
|
-
}
|
|
2294
|
-
function isLiveList(value) {
|
|
2295
|
-
return value instanceof LiveList;
|
|
2296
|
-
}
|
|
2297
|
-
function isLiveObject(value) {
|
|
2298
|
-
return value instanceof LiveObject;
|
|
2299
|
-
}
|
|
2300
|
-
function liveNodeToLson(obj) {
|
|
2301
|
-
return obj instanceof LiveRegister
|
|
2302
|
-
? obj.data
|
|
2303
|
-
: obj instanceof LiveList ||
|
|
2304
|
-
obj instanceof LiveMap ||
|
|
2305
|
-
obj instanceof LiveObject
|
|
2306
|
-
? obj
|
|
2307
|
-
: assertNever(0, "Unknown AbstractCrdt");
|
|
2308
|
-
}
|
|
2309
|
-
function lsonToLiveNode(value) {
|
|
2310
|
-
return value instanceof LiveObject ||
|
|
2311
|
-
value instanceof LiveMap ||
|
|
2312
|
-
value instanceof LiveList
|
|
2313
|
-
? value
|
|
2314
|
-
: new LiveRegister(value);
|
|
2315
|
-
}
|
|
2316
|
-
function isPlain(value) {
|
|
2317
|
-
var type = typeof value;
|
|
2318
|
-
return (
|
|
2319
|
-
null == value ||
|
|
2320
|
-
"string" === type ||
|
|
2321
|
-
"boolean" === type ||
|
|
2322
|
-
"number" === type ||
|
|
2323
|
-
Array.isArray(value) ||
|
|
2324
|
-
isPlainObject(value)
|
|
2325
|
-
);
|
|
2326
|
-
}
|
|
2327
|
-
function isPlainObject(blob) {
|
|
2328
|
-
return (
|
|
2329
|
-
null !== blob &&
|
|
2330
|
-
"object" == typeof blob &&
|
|
2331
|
-
"[object Object]" === Object.prototype.toString.call(blob)
|
|
2332
|
-
);
|
|
2333
|
-
}
|
|
2334
|
-
function entries(obj) {
|
|
2335
|
-
return Object.entries(obj);
|
|
2336
|
-
}
|
|
2337
|
-
function tryParseJson(rawMessage) {
|
|
2338
|
-
try {
|
|
2339
|
-
return JSON.parse(rawMessage);
|
|
2340
|
-
} catch (e) {
|
|
2341
|
-
return;
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
function b64decode(b64value) {
|
|
2345
|
-
try {
|
|
2346
|
-
var formattedValue = b64value.replace(/-/g, "+").replace(/_/g, "/");
|
|
2347
|
-
return decodeURIComponent(
|
|
2348
|
-
atob(formattedValue)
|
|
2349
|
-
.split("")
|
|
2350
|
-
.map(function (c) {
|
|
2351
|
-
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
2352
|
-
})
|
|
2353
|
-
.join("")
|
|
2354
|
-
);
|
|
2355
|
-
} catch (err) {
|
|
2356
|
-
return atob(b64value);
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
var _excluded = ["maxConnections"],
|
|
2360
|
-
SCOPES = [
|
|
2361
|
-
"websocket:presence",
|
|
2362
|
-
"websocket:storage",
|
|
2363
|
-
"room:read",
|
|
2364
|
-
"room:write",
|
|
2365
|
-
"rooms:read",
|
|
2366
|
-
"rooms:write",
|
|
2367
|
-
];
|
|
2368
|
-
function isStringList(value) {
|
|
2369
|
-
return (
|
|
2370
|
-
Array.isArray(value) &&
|
|
2371
|
-
value.every(function (i) {
|
|
2372
|
-
return "string" == typeof i;
|
|
2373
|
-
})
|
|
2374
|
-
);
|
|
2375
|
-
}
|
|
2376
|
-
function isAppOnlyAuthToken(data) {
|
|
2377
|
-
return (
|
|
2378
|
-
"string" == typeof data.appId &&
|
|
2379
|
-
void 0 === data.roomId &&
|
|
2380
|
-
isStringList(data.scopes)
|
|
2381
|
-
);
|
|
2382
|
-
}
|
|
2383
|
-
function isRoomAuthToken(data) {
|
|
2384
|
-
return (
|
|
2385
|
-
"string" == typeof data.appId &&
|
|
2386
|
-
"string" == typeof data.roomId &&
|
|
2387
|
-
"number" == typeof data.actor &&
|
|
2388
|
-
(void 0 === data.id || "string" == typeof data.id) &&
|
|
2389
|
-
isStringList(data.scopes) &&
|
|
2390
|
-
(void 0 === data.maxConnectionsPerRoom ||
|
|
2391
|
-
"number" == typeof data.maxConnectionsPerRoom)
|
|
2392
|
-
);
|
|
2393
|
-
}
|
|
2394
|
-
function parseJwtToken(token) {
|
|
2395
|
-
var tokenParts = token.split(".");
|
|
2396
|
-
if (3 !== tokenParts.length)
|
|
2397
|
-
throw new Error("Authentication error: invalid JWT token");
|
|
2398
|
-
var data = tryParseJson(b64decode(tokenParts[1]));
|
|
2399
|
-
if (
|
|
2400
|
-
data &&
|
|
2401
|
-
(function (data) {
|
|
2402
|
-
if (!isPlainObject(data)) return !1;
|
|
2403
|
-
var iat = data.iat,
|
|
2404
|
-
exp = data.exp;
|
|
2405
|
-
return "number" == typeof iat && "number" == typeof exp;
|
|
2406
|
-
})(data)
|
|
2407
|
-
)
|
|
2408
|
-
return data;
|
|
2409
|
-
throw new Error("Authentication error: missing JWT metadata");
|
|
2410
|
-
}
|
|
2411
|
-
function isJsonScalar(data) {
|
|
2412
|
-
return (
|
|
2413
|
-
null === data ||
|
|
2414
|
-
"string" == typeof data ||
|
|
2415
|
-
"number" == typeof data ||
|
|
2416
|
-
"boolean" == typeof data
|
|
2417
|
-
);
|
|
2418
|
-
}
|
|
2419
|
-
function isJsonArray(data) {
|
|
2420
|
-
return Array.isArray(data);
|
|
2421
|
-
}
|
|
2422
|
-
(exports.LiveList = LiveList),
|
|
2423
|
-
(exports.LiveMap = LiveMap),
|
|
2424
|
-
(exports.LiveObject = LiveObject),
|
|
2425
|
-
(exports.LiveRegister = LiveRegister),
|
|
2426
|
-
(exports._createForOfIteratorHelperLoose = _createForOfIteratorHelperLoose),
|
|
2427
|
-
(exports._extends = _extends),
|
|
2428
|
-
(exports._inheritsLoose = _inheritsLoose),
|
|
2429
|
-
(exports._objectWithoutPropertiesLoose = _objectWithoutPropertiesLoose),
|
|
2430
|
-
(exports._wrapNativeSuper = _wrapNativeSuper),
|
|
2431
|
-
(exports.assertNever = assertNever),
|
|
2432
|
-
(exports.b64decode = b64decode),
|
|
2433
|
-
(exports.compact = function (items) {
|
|
2434
|
-
return items.filter(function (item) {
|
|
2435
|
-
return null != item;
|
|
2436
|
-
});
|
|
2437
|
-
}),
|
|
2438
|
-
(exports.comparePosition = comparePosition),
|
|
2439
|
-
(exports.deprecate = deprecate),
|
|
2440
|
-
(exports.deprecateIf = function (condition, message, key) {
|
|
2441
|
-
void 0 === key && (key = message),
|
|
2442
|
-
"production" !== process.env.NODE_ENV &&
|
|
2443
|
-
condition &&
|
|
2444
|
-
deprecate(message, key);
|
|
2445
|
-
}),
|
|
2446
|
-
(exports.errorIf = errorIf),
|
|
2447
|
-
(exports.findNonSerializableValue = function findNonSerializableValue(
|
|
2448
|
-
value,
|
|
2449
|
-
path
|
|
2450
|
-
) {
|
|
2451
|
-
if ((void 0 === path && (path = ""), !isPlain))
|
|
2452
|
-
return { path: path || "root", value: value };
|
|
2453
|
-
if ("object" != typeof value || null === value) return !1;
|
|
2454
|
-
for (
|
|
2455
|
-
var _i = 0, _Object$entries = Object.entries(value);
|
|
2456
|
-
_i < _Object$entries.length;
|
|
2457
|
-
_i++
|
|
2458
|
-
) {
|
|
2459
|
-
var _Object$entries$_i = _Object$entries[_i],
|
|
2460
|
-
_key3 = _Object$entries$_i[0],
|
|
2461
|
-
nestedValue = _Object$entries$_i[1],
|
|
2462
|
-
nestedPath = path ? path + "." + _key3 : _key3;
|
|
2463
|
-
if (!isPlain(nestedValue))
|
|
2464
|
-
return { path: nestedPath, value: nestedValue };
|
|
2465
|
-
if ("object" == typeof nestedValue) {
|
|
2466
|
-
var nonSerializableNestedValue = findNonSerializableValue(
|
|
2467
|
-
nestedValue,
|
|
2468
|
-
nestedPath
|
|
2469
|
-
);
|
|
2470
|
-
if (nonSerializableNestedValue) return nonSerializableNestedValue;
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
return !1;
|
|
2474
|
-
}),
|
|
2475
|
-
(exports.getTreesDiffOperations = function (currentItems, newItems) {
|
|
2476
|
-
var ops = [];
|
|
2477
|
-
return (
|
|
2478
|
-
currentItems.forEach(function (_, id) {
|
|
2479
|
-
newItems.get(id) ||
|
|
2480
|
-
ops.push({ type: exports.OpCode.DELETE_CRDT, id: id });
|
|
2481
|
-
}),
|
|
2482
|
-
newItems.forEach(function (crdt, id) {
|
|
2483
|
-
var currentCrdt = currentItems.get(id);
|
|
2484
|
-
if (currentCrdt)
|
|
2485
|
-
crdt.type === exports.CrdtType.OBJECT &&
|
|
2486
|
-
((currentCrdt.type === exports.CrdtType.OBJECT &&
|
|
2487
|
-
JSON.stringify(crdt.data) === JSON.stringify(currentCrdt.data)) ||
|
|
2488
|
-
ops.push({
|
|
2489
|
-
type: exports.OpCode.UPDATE_OBJECT,
|
|
2490
|
-
id: id,
|
|
2491
|
-
data: crdt.data,
|
|
2492
|
-
})),
|
|
2493
|
-
crdt.parentKey !== currentCrdt.parentKey &&
|
|
2494
|
-
ops.push({
|
|
2495
|
-
type: exports.OpCode.SET_PARENT_KEY,
|
|
2496
|
-
id: id,
|
|
2497
|
-
parentKey: nn(crdt.parentKey, "Parent key must not be missing"),
|
|
2498
|
-
});
|
|
2499
|
-
else
|
|
2500
|
-
switch (crdt.type) {
|
|
2501
|
-
case exports.CrdtType.REGISTER:
|
|
2502
|
-
ops.push({
|
|
2503
|
-
type: exports.OpCode.CREATE_REGISTER,
|
|
2504
|
-
id: id,
|
|
2505
|
-
parentId: crdt.parentId,
|
|
2506
|
-
parentKey: crdt.parentKey,
|
|
2507
|
-
data: crdt.data,
|
|
2508
|
-
});
|
|
2509
|
-
break;
|
|
2510
|
-
case exports.CrdtType.LIST:
|
|
2511
|
-
ops.push({
|
|
2512
|
-
type: exports.OpCode.CREATE_LIST,
|
|
2513
|
-
id: id,
|
|
2514
|
-
parentId: crdt.parentId,
|
|
2515
|
-
parentKey: crdt.parentKey,
|
|
2516
|
-
});
|
|
2517
|
-
break;
|
|
2518
|
-
case exports.CrdtType.OBJECT:
|
|
2519
|
-
ops.push(
|
|
2520
|
-
crdt.parentId
|
|
2521
|
-
? {
|
|
2522
|
-
type: exports.OpCode.CREATE_OBJECT,
|
|
2523
|
-
id: id,
|
|
2524
|
-
parentId: crdt.parentId,
|
|
2525
|
-
parentKey: crdt.parentKey,
|
|
2526
|
-
data: crdt.data,
|
|
2527
|
-
}
|
|
2528
|
-
: {
|
|
2529
|
-
type: exports.OpCode.CREATE_OBJECT,
|
|
2530
|
-
id: id,
|
|
2531
|
-
data: crdt.data,
|
|
2532
|
-
}
|
|
2533
|
-
);
|
|
2534
|
-
break;
|
|
2535
|
-
case exports.CrdtType.MAP:
|
|
2536
|
-
ops.push({
|
|
2537
|
-
type: exports.OpCode.CREATE_MAP,
|
|
2538
|
-
id: id,
|
|
2539
|
-
parentId: crdt.parentId,
|
|
2540
|
-
parentKey: crdt.parentKey,
|
|
2541
|
-
});
|
|
2542
|
-
}
|
|
2543
|
-
}),
|
|
2544
|
-
ops
|
|
2545
|
-
);
|
|
2546
|
-
}),
|
|
2547
|
-
(exports.isAppOnlyAuthToken = isAppOnlyAuthToken),
|
|
2548
|
-
(exports.isAuthToken = function (data) {
|
|
2549
|
-
return isAppOnlyAuthToken(data) || isRoomAuthToken(data);
|
|
2550
|
-
}),
|
|
2551
|
-
(exports.isChildCrdt = isChildCrdt),
|
|
2552
|
-
(exports.isJsonArray = isJsonArray),
|
|
2553
|
-
(exports.isJsonObject = function (data) {
|
|
2554
|
-
return !isJsonScalar(data) && !isJsonArray(data);
|
|
2555
|
-
}),
|
|
2556
|
-
(exports.isJsonScalar = isJsonScalar),
|
|
2557
|
-
(exports.isLiveList = isLiveList),
|
|
2558
|
-
(exports.isLiveNode = isLiveNode),
|
|
2559
|
-
(exports.isLiveObject = isLiveObject),
|
|
2560
|
-
(exports.isPlainObject = isPlainObject),
|
|
2561
|
-
(exports.isRoomAuthToken = isRoomAuthToken),
|
|
2562
|
-
(exports.isRoomEventName = function (value) {
|
|
2563
|
-
return (
|
|
2564
|
-
"my-presence" === value ||
|
|
2565
|
-
"others" === value ||
|
|
2566
|
-
"event" === value ||
|
|
2567
|
-
"error" === value ||
|
|
2568
|
-
"connection" === value
|
|
2569
|
-
);
|
|
2570
|
-
}),
|
|
2571
|
-
(exports.isRootCrdt = function (crdt) {
|
|
2572
|
-
return crdt.type === exports.CrdtType.OBJECT && !isChildCrdt(crdt);
|
|
2573
|
-
}),
|
|
2574
|
-
(exports.isSameNodeOrChildOf = function isSameNodeOrChildOf(node, parent) {
|
|
2575
|
-
return (
|
|
2576
|
-
node === parent ||
|
|
2577
|
-
("HasParent" === node.parent.type &&
|
|
2578
|
-
isSameNodeOrChildOf(node.parent.node, parent))
|
|
2579
|
-
);
|
|
2580
|
-
}),
|
|
2581
|
-
(exports.isScope = function (value) {
|
|
2582
|
-
return SCOPES.includes(value);
|
|
2583
|
-
}),
|
|
2584
|
-
(exports.isTokenExpired = function (token) {
|
|
2585
|
-
var now = Date.now() / 1e3;
|
|
2586
|
-
return now > token.exp - 300 || now < token.iat + 300;
|
|
2587
|
-
}),
|
|
2588
|
-
(exports.makePosition = makePosition),
|
|
2589
|
-
(exports.mergeStorageUpdates = function (first, second) {
|
|
2590
|
-
return first
|
|
2591
|
-
? "LiveObject" === first.type && "LiveObject" === second.type
|
|
2592
|
-
? (function (first, second) {
|
|
2593
|
-
for (
|
|
2594
|
-
var _step,
|
|
2595
|
-
updates = first.updates,
|
|
2596
|
-
_iterator = _createForOfIteratorHelperLoose(
|
|
2597
|
-
entries(second.updates)
|
|
2598
|
-
);
|
|
2599
|
-
!(_step = _iterator()).done;
|
|
2600
|
-
|
|
2601
|
-
) {
|
|
2602
|
-
var _step$value = _step.value,
|
|
2603
|
-
_key = _step$value[0],
|
|
2604
|
-
value = _step$value[1];
|
|
2605
|
-
updates[_key] = value;
|
|
2606
|
-
}
|
|
2607
|
-
return _extends({}, second, { updates: updates });
|
|
2608
|
-
})(first, second)
|
|
2609
|
-
: "LiveMap" === first.type && "LiveMap" === second.type
|
|
2610
|
-
? (function (first, second) {
|
|
2611
|
-
for (
|
|
2612
|
-
var _step2,
|
|
2613
|
-
updates = first.updates,
|
|
2614
|
-
_iterator2 = _createForOfIteratorHelperLoose(
|
|
2615
|
-
entries(second.updates)
|
|
2616
|
-
);
|
|
2617
|
-
!(_step2 = _iterator2()).done;
|
|
2618
|
-
|
|
2619
|
-
) {
|
|
2620
|
-
var _step2$value = _step2.value,
|
|
2621
|
-
_key2 = _step2$value[0],
|
|
2622
|
-
value = _step2$value[1];
|
|
2623
|
-
updates[_key2] = value;
|
|
2624
|
-
}
|
|
2625
|
-
return _extends({}, second, { updates: updates });
|
|
2626
|
-
})(first, second)
|
|
2627
|
-
: "LiveList" === first.type && "LiveList" === second.type
|
|
2628
|
-
? (function (first, second) {
|
|
2629
|
-
return _extends({}, second, {
|
|
2630
|
-
updates: first.updates.concat(second.updates),
|
|
2631
|
-
});
|
|
2632
|
-
})(first, second)
|
|
2633
|
-
: second
|
|
2634
|
-
: second;
|
|
2635
|
-
}),
|
|
2636
|
-
(exports.nn = nn),
|
|
2637
|
-
(exports.parseRoomAuthToken = function (tokenString) {
|
|
2638
|
-
var data = parseJwtToken(tokenString);
|
|
2639
|
-
if (data && isRoomAuthToken(data))
|
|
2640
|
-
return (
|
|
2641
|
-
data.maxConnections, _objectWithoutPropertiesLoose(data, _excluded)
|
|
2642
|
-
);
|
|
2643
|
-
throw new Error(
|
|
2644
|
-
"Authentication error: we expected a room token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
|
|
2645
|
-
);
|
|
2646
|
-
}),
|
|
2647
|
-
(exports.remove = function (array, item) {
|
|
2648
|
-
for (var i = 0; i < array.length; i++)
|
|
2649
|
-
if (array[i] === item) {
|
|
2650
|
-
array.splice(i, 1);
|
|
2651
|
-
break;
|
|
2652
|
-
}
|
|
2653
|
-
}),
|
|
2654
|
-
(exports.throwUsageError = throwUsageError),
|
|
2655
|
-
(exports.tryParseJson = tryParseJson);
|