@liveblocks/client 0.13.1 → 0.14.0

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.
@@ -12,7 +12,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
12
12
  var _LiveList_items, _LiveListIterator_innerIterator;
13
13
  import { AbstractCrdt } from "./AbstractCrdt";
14
14
  import { deserialize, selfOrRegister, selfOrRegisterValue } from "./utils";
15
- import { OpType, } from "./live";
15
+ import { OpType, CrdtType, } from "./live";
16
16
  import { makePosition, compare } from "./position";
17
17
  /**
18
18
  * The LiveList class represents an ordered collection of items that is synchorinized across clients.
@@ -51,7 +51,7 @@ export class LiveList extends AbstractCrdt {
51
51
  /**
52
52
  * INTERNAL
53
53
  */
54
- _serialize(parentId, parentKey) {
54
+ _serialize(parentId, parentKey, doc) {
55
55
  if (this._id == null) {
56
56
  throw new Error("Cannot serialize item is not attached");
57
57
  }
@@ -61,13 +61,14 @@ export class LiveList extends AbstractCrdt {
61
61
  const ops = [];
62
62
  const op = {
63
63
  id: this._id,
64
+ opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
64
65
  type: OpType.CreateList,
65
66
  parentId,
66
67
  parentKey,
67
68
  };
68
69
  ops.push(op);
69
70
  for (const [value, key] of __classPrivateFieldGet(this, _LiveList_items, "f")) {
70
- ops.push(...value._serialize(this._id, key));
71
+ ops.push(...value._serialize(this._id, key, doc));
71
72
  }
72
73
  return ops;
73
74
  }
@@ -92,7 +93,7 @@ export class LiveList extends AbstractCrdt {
92
93
  /**
93
94
  * INTERNAL
94
95
  */
95
- _attachChild(id, key, child) {
96
+ _attachChild(id, key, child, isLocal) {
96
97
  var _a;
97
98
  if (this._doc == null) {
98
99
  throw new Error("Can't attach child if doc is not present");
@@ -100,11 +101,24 @@ export class LiveList extends AbstractCrdt {
100
101
  child._attach(id, this._doc);
101
102
  child._setParentLink(this, key);
102
103
  const index = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === key);
103
- // Assign a temporary position until we get the fix from the backend
104
+ let newKey = key;
105
+ // If there is a conflict
104
106
  if (index !== -1) {
105
- __classPrivateFieldGet(this, _LiveList_items, "f")[index][1] = makePosition(key, (_a = __classPrivateFieldGet(this, _LiveList_items, "f")[index + 1]) === null || _a === void 0 ? void 0 : _a[1]);
107
+ if (isLocal) {
108
+ // If change is local => assign a temporary position to newly attached child
109
+ let before = __classPrivateFieldGet(this, _LiveList_items, "f")[index] ? __classPrivateFieldGet(this, _LiveList_items, "f")[index][1] : undefined;
110
+ let after = __classPrivateFieldGet(this, _LiveList_items, "f")[index + 1]
111
+ ? __classPrivateFieldGet(this, _LiveList_items, "f")[index + 1][1]
112
+ : undefined;
113
+ newKey = makePosition(before, after);
114
+ child._setParentLink(this, newKey);
115
+ }
116
+ else {
117
+ // If change is remote => assign a temporary position to existing child until we get the fix from the backend
118
+ __classPrivateFieldGet(this, _LiveList_items, "f")[index][1] = makePosition(key, (_a = __classPrivateFieldGet(this, _LiveList_items, "f")[index + 1]) === null || _a === void 0 ? void 0 : _a[1]);
119
+ }
106
120
  }
107
- __classPrivateFieldGet(this, _LiveList_items, "f").push([child, key]);
121
+ __classPrivateFieldGet(this, _LiveList_items, "f").push([child, newKey]);
108
122
  __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => compare(itemA[1], itemB[1]));
109
123
  return { reverse: [{ type: OpType.DeleteCrdt, id }], modified: this };
110
124
  }
@@ -138,8 +152,19 @@ export class LiveList extends AbstractCrdt {
138
152
  /**
139
153
  * INTERNAL
140
154
  */
141
- _apply(op) {
142
- return super._apply(op);
155
+ _apply(op, isLocal) {
156
+ return super._apply(op, isLocal);
157
+ }
158
+ /**
159
+ * INTERNAL
160
+ */
161
+ _toSerializedCrdt() {
162
+ var _a;
163
+ return {
164
+ type: CrdtType.List,
165
+ parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
166
+ parentKey: this._parentKey,
167
+ };
143
168
  }
144
169
  /**
145
170
  * Returns the number of elements.
@@ -173,7 +198,7 @@ export class LiveList extends AbstractCrdt {
173
198
  if (this._doc && this._id) {
174
199
  const id = this._doc.generateId();
175
200
  value._attach(id, this._doc);
176
- this._doc.dispatch(value._serialize(this._id, position), [{ type: OpType.DeleteCrdt, id }], [this]);
201
+ this._doc.dispatch(value._serialize(this._id, position, this._doc), [{ type: OpType.DeleteCrdt, id }], [this]);
177
202
  }
178
203
  }
179
204
  /**
@@ -219,6 +244,7 @@ export class LiveList extends AbstractCrdt {
219
244
  {
220
245
  type: OpType.SetParentKey,
221
246
  id: item[0]._id,
247
+ opId: this._doc.generateOpId(),
222
248
  parentKey: position,
223
249
  },
224
250
  ], [
@@ -247,12 +273,35 @@ export class LiveList extends AbstractCrdt {
247
273
  this._doc.dispatch([
248
274
  {
249
275
  id: childRecordId,
276
+ opId: this._doc.generateOpId(),
250
277
  type: OpType.DeleteCrdt,
251
278
  },
252
279
  ], item[0]._serialize(this._id, item[1]), [this]);
253
280
  }
254
281
  }
255
282
  }
283
+ clear() {
284
+ if (this._doc) {
285
+ let ops = [];
286
+ let reverseOps = [];
287
+ for (const item of __classPrivateFieldGet(this, _LiveList_items, "f")) {
288
+ item[0]._detach();
289
+ const childId = item[0]._id;
290
+ if (childId) {
291
+ ops.push({ id: childId, type: OpType.DeleteCrdt });
292
+ reverseOps.push(...item[0]._serialize(this._id, item[1]));
293
+ }
294
+ }
295
+ __classPrivateFieldSet(this, _LiveList_items, [], "f");
296
+ this._doc.dispatch(ops, reverseOps, [this]);
297
+ }
298
+ else {
299
+ for (const item of __classPrivateFieldGet(this, _LiveList_items, "f")) {
300
+ item[0]._detach();
301
+ }
302
+ __classPrivateFieldSet(this, _LiveList_items, [], "f");
303
+ }
304
+ }
256
305
  /**
257
306
  * Returns an Array of all the elements in the LiveList.
258
307
  */
@@ -1,5 +1,5 @@
1
1
  import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
- import { Op, SerializedCrdtWithId } from "./live";
2
+ import { Op, SerializedCrdtWithId, SerializedCrdt } from "./live";
3
3
  /**
4
4
  * The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
5
5
  * Keys should be a string, and values should be serializable to JSON.
@@ -11,7 +11,7 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
11
11
  /**
12
12
  * INTERNAL
13
13
  */
14
- _serialize(parentId?: string, parentKey?: string): Op[];
14
+ _serialize(parentId?: string, parentKey?: string, doc?: Doc): Op[];
15
15
  /**
16
16
  * INTERNAL
17
17
  */
@@ -23,7 +23,7 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
23
23
  /**
24
24
  * INTERNAL
25
25
  */
26
- _attachChild(id: string, key: TKey, child: AbstractCrdt): ApplyResult;
26
+ _attachChild(id: string, key: TKey, child: AbstractCrdt, isLocal: boolean): ApplyResult;
27
27
  /**
28
28
  * INTERNAL
29
29
  */
@@ -32,6 +32,10 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
32
32
  * INTERNAL
33
33
  */
34
34
  _detachChild(child: AbstractCrdt): void;
35
+ /**
36
+ * INTERNAL
37
+ */
38
+ _toSerializedCrdt(): SerializedCrdt;
35
39
  /**
36
40
  * Returns a specified element from the LiveMap.
37
41
  * @param key The key of the element to return.
@@ -38,7 +38,7 @@ export class LiveMap extends AbstractCrdt {
38
38
  /**
39
39
  * INTERNAL
40
40
  */
41
- _serialize(parentId, parentKey) {
41
+ _serialize(parentId, parentKey, doc) {
42
42
  if (this._id == null) {
43
43
  throw new Error("Cannot serialize item is not attached");
44
44
  }
@@ -48,13 +48,14 @@ export class LiveMap extends AbstractCrdt {
48
48
  const ops = [];
49
49
  const op = {
50
50
  id: this._id,
51
+ opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
51
52
  type: OpType.CreateMap,
52
53
  parentId,
53
54
  parentKey,
54
55
  };
55
56
  ops.push(op);
56
57
  for (const [key, value] of __classPrivateFieldGet(this, _LiveMap_map, "f")) {
57
- ops.push(...value._serialize(this._id, key));
58
+ ops.push(...value._serialize(this._id, key, doc));
58
59
  }
59
60
  return ops;
60
61
  }
@@ -96,7 +97,7 @@ export class LiveMap extends AbstractCrdt {
96
97
  /**
97
98
  * INTERNAL
98
99
  */
99
- _attachChild(id, key, child) {
100
+ _attachChild(id, key, child, isLocal) {
100
101
  if (this._doc == null) {
101
102
  throw new Error("Can't attach child if doc is not present");
102
103
  }
@@ -134,6 +135,17 @@ export class LiveMap extends AbstractCrdt {
134
135
  }
135
136
  child._detach();
136
137
  }
138
+ /**
139
+ * INTERNAL
140
+ */
141
+ _toSerializedCrdt() {
142
+ var _a;
143
+ return {
144
+ type: CrdtType.Map,
145
+ parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
146
+ parentKey: this._parentKey,
147
+ };
148
+ }
137
149
  /**
138
150
  * Returns a specified element from the LiveMap.
139
151
  * @param key The key of the element to return.
@@ -162,7 +174,7 @@ export class LiveMap extends AbstractCrdt {
162
174
  if (this._doc && this._id) {
163
175
  const id = this._doc.generateId();
164
176
  item._attach(id, this._doc);
165
- this._doc.dispatch(item._serialize(this._id, key), oldValue
177
+ this._doc.dispatch(item._serialize(this._id, key, this._doc), oldValue
166
178
  ? oldValue._serialize(this._id, key)
167
179
  : [{ type: OpType.DeleteCrdt, id }], [this]);
168
180
  }
@@ -192,7 +204,13 @@ export class LiveMap extends AbstractCrdt {
192
204
  }
193
205
  item._detach();
194
206
  if (this._doc && item._id) {
195
- this._doc.dispatch([{ type: OpType.DeleteCrdt, id: item._id }], item._serialize(this._id, key), [this]);
207
+ this._doc.dispatch([
208
+ {
209
+ type: OpType.DeleteCrdt,
210
+ id: item._id,
211
+ opId: this._doc.generateOpId(),
212
+ },
213
+ ], item._serialize(this._id, key), [this]);
196
214
  }
197
215
  __classPrivateFieldGet(this, _LiveMap_map, "f").delete(key);
198
216
  return true;
@@ -1,5 +1,5 @@
1
1
  import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
- import { Op, SerializedCrdtWithId } from "./live";
2
+ import { Op, SerializedCrdt, SerializedCrdtWithId } from "./live";
3
3
  /**
4
4
  * The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
5
5
  * Keys should be a string, and values should be serializable to JSON.
@@ -11,13 +11,15 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
11
11
  /**
12
12
  * INTERNAL
13
13
  */
14
- _serialize(parentId?: string, parentKey?: string): Op[];
14
+ _serialize(parentId?: string, parentKey?: string, doc?: Doc): Op[];
15
15
  /**
16
16
  * INTERNAL
17
17
  */
18
- static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveObject<{
19
- [key: string]: any;
20
- }>;
18
+ static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveObject<Record<string, any>>;
19
+ /**
20
+ * INTERNAL
21
+ */
22
+ static _deserializeChildren(object: LiveObject, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveObject<Record<string, any>>;
21
23
  /**
22
24
  * INTERNAL
23
25
  */
@@ -25,11 +27,15 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
25
27
  /**
26
28
  * INTERNAL
27
29
  */
28
- _attachChild(id: string, key: keyof T, child: AbstractCrdt): ApplyResult;
30
+ _attachChild(id: string, key: keyof T, child: AbstractCrdt, isLocal: boolean): ApplyResult;
29
31
  /**
30
32
  * INTERNAL
31
33
  */
32
34
  _detachChild(child: AbstractCrdt): void;
35
+ /**
36
+ * INTERNAL
37
+ */
38
+ _detachChildren(): void;
33
39
  /**
34
40
  * INTERNAL
35
41
  */
@@ -37,7 +43,11 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
37
43
  /**
38
44
  * INTERNAL
39
45
  */
40
- _apply(op: Op): ApplyResult;
46
+ _apply(op: Op, isLocal: boolean): ApplyResult;
47
+ /**
48
+ * INTERNAL
49
+ */
50
+ _toSerializedCrdt(): SerializedCrdt;
41
51
  /**
42
52
  * Transform the LiveObject into a javascript object
43
53
  */
@@ -35,13 +35,14 @@ export class LiveObject extends AbstractCrdt {
35
35
  /**
36
36
  * INTERNAL
37
37
  */
38
- _serialize(parentId, parentKey) {
38
+ _serialize(parentId, parentKey, doc) {
39
39
  if (this._id == null) {
40
40
  throw new Error("Cannot serialize item is not attached");
41
41
  }
42
42
  const ops = [];
43
43
  const op = {
44
44
  id: this._id,
45
+ opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
45
46
  type: OpType.CreateObject,
46
47
  parentId,
47
48
  parentKey,
@@ -50,7 +51,7 @@ export class LiveObject extends AbstractCrdt {
50
51
  ops.push(op);
51
52
  for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
52
53
  if (value instanceof AbstractCrdt) {
53
- ops.push(...value._serialize(this._id, key));
54
+ ops.push(...value._serialize(this._id, key, doc));
54
55
  }
55
56
  else {
56
57
  op.data[key] = value;
@@ -67,7 +68,13 @@ export class LiveObject extends AbstractCrdt {
67
68
  }
68
69
  const object = new LiveObject(item.data);
69
70
  object._attach(id, doc);
70
- const children = parentToChildren.get(id);
71
+ return this._deserializeChildren(object, parentToChildren, doc);
72
+ }
73
+ /**
74
+ * INTERNAL
75
+ */
76
+ static _deserializeChildren(object, parentToChildren, doc) {
77
+ const children = parentToChildren.get(object._id);
71
78
  if (children == null) {
72
79
  return object;
73
80
  }
@@ -96,7 +103,7 @@ export class LiveObject extends AbstractCrdt {
96
103
  /**
97
104
  * INTERNAL
98
105
  */
99
- _attachChild(id, key, child) {
106
+ _attachChild(id, key, child, isLocal) {
100
107
  if (this._doc == null) {
101
108
  throw new Error("Can't attach child if doc is not present");
102
109
  }
@@ -138,6 +145,15 @@ export class LiveObject extends AbstractCrdt {
138
145
  child._detach();
139
146
  }
140
147
  }
148
+ /**
149
+ * INTERNAL
150
+ */
151
+ _detachChildren() {
152
+ for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
153
+ __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
154
+ value._detach();
155
+ }
156
+ }
141
157
  /**
142
158
  * INTERNAL
143
159
  */
@@ -152,14 +168,26 @@ export class LiveObject extends AbstractCrdt {
152
168
  /**
153
169
  * INTERNAL
154
170
  */
155
- _apply(op) {
171
+ _apply(op, isLocal) {
156
172
  if (op.type === OpType.UpdateObject) {
157
- return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyUpdate).call(this, op);
173
+ return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyUpdate).call(this, op, isLocal);
158
174
  }
159
175
  else if (op.type === OpType.DeleteObjectKey) {
160
176
  return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyDeleteObjectKey).call(this, op);
161
177
  }
162
- return super._apply(op);
178
+ return super._apply(op, isLocal);
179
+ }
180
+ /**
181
+ * INTERNAL
182
+ */
183
+ _toSerializedCrdt() {
184
+ var _a;
185
+ return {
186
+ type: CrdtType.Object,
187
+ parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
188
+ parentKey: this._parentKey,
189
+ data: this.toObject(),
190
+ };
163
191
  }
164
192
  /**
165
193
  * Transform the LiveObject into a javascript object
@@ -215,7 +243,14 @@ export class LiveObject extends AbstractCrdt {
215
243
  ];
216
244
  }
217
245
  __classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString);
218
- this._doc.dispatch([{ type: OpType.DeleteObjectKey, key: keyAsString, id: this._id }], reverse, [this]);
246
+ this._doc.dispatch([
247
+ {
248
+ type: OpType.DeleteObjectKey,
249
+ key: keyAsString,
250
+ id: this._id,
251
+ opId: this._doc.generateOpId(),
252
+ },
253
+ ], reverse, [this]);
219
254
  }
220
255
  /**
221
256
  * Adds or updates multiple properties at once with an object.
@@ -262,7 +297,7 @@ export class LiveObject extends AbstractCrdt {
262
297
  if (newValue instanceof AbstractCrdt) {
263
298
  newValue._setParentLink(this, key);
264
299
  newValue._attach(this._doc.generateId(), this._doc);
265
- ops.push(...newValue._serialize(this._id, key));
300
+ ops.push(...newValue._serialize(this._id, key, this._doc));
266
301
  }
267
302
  else {
268
303
  updatedProps[key] = newValue;
@@ -283,7 +318,7 @@ export class LiveObject extends AbstractCrdt {
283
318
  this._doc.dispatch(ops, reverseOps, [this]);
284
319
  }
285
320
  }
286
- _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _LiveObject_instances = new WeakSet(), _LiveObject_applyUpdate = function _LiveObject_applyUpdate(op) {
321
+ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _LiveObject_instances = new WeakSet(), _LiveObject_applyUpdate = function _LiveObject_applyUpdate(op, isLocal) {
287
322
  let isModified = false;
288
323
  const reverse = [];
289
324
  const reverseUpdate = {
@@ -305,11 +340,6 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
305
340
  reverse.push({ type: OpType.DeleteObjectKey, id: this._id, key });
306
341
  }
307
342
  }
308
- let isLocal = false;
309
- if (op.opId == null) {
310
- isLocal = true;
311
- op.opId = this._doc.generateOpId();
312
- }
313
343
  for (const key in op.data) {
314
344
  if (isLocal) {
315
345
  __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, op.opId);
@@ -1,5 +1,5 @@
1
1
  import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
- import { SerializedCrdtWithId, Op } from "./live";
2
+ import { SerializedCrdtWithId, Op, SerializedCrdt } from "./live";
3
3
  /**
4
4
  * INTERNAL
5
5
  */
@@ -14,8 +14,12 @@ export declare class LiveRegister<TValue = any> extends AbstractCrdt {
14
14
  /**
15
15
  * INTERNAL
16
16
  */
17
- _serialize(parentId: string, parentKey: string): Op[];
18
- _attachChild(id: string, key: string, crdt: AbstractCrdt): ApplyResult;
17
+ _serialize(parentId: string, parentKey: string, doc?: Doc): Op[];
18
+ /**
19
+ * INTERNAL
20
+ */
21
+ _toSerializedCrdt(): SerializedCrdt;
22
+ _attachChild(id: string, key: string, crdt: AbstractCrdt, isLocal: boolean): ApplyResult;
19
23
  _detachChild(crdt: AbstractCrdt): void;
20
- _apply(op: Op): ApplyResult;
24
+ _apply(op: Op, isLocal: boolean): ApplyResult;
21
25
  }
@@ -11,7 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _LiveRegister_data;
13
13
  import { AbstractCrdt } from "./AbstractCrdt";
14
- import { CrdtType, OpType } from "./live";
14
+ import { CrdtType, OpType, } from "./live";
15
15
  /**
16
16
  * INTERNAL
17
17
  */
@@ -38,13 +38,14 @@ export class LiveRegister extends AbstractCrdt {
38
38
  /**
39
39
  * INTERNAL
40
40
  */
41
- _serialize(parentId, parentKey) {
41
+ _serialize(parentId, parentKey, doc) {
42
42
  if (this._id == null || parentId == null || parentKey == null) {
43
43
  throw new Error("Cannot serialize register if parentId or parentKey is undefined");
44
44
  }
45
45
  return [
46
46
  {
47
47
  type: OpType.CreateRegister,
48
+ opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
48
49
  id: this._id,
49
50
  parentId,
50
51
  parentKey,
@@ -52,14 +53,26 @@ export class LiveRegister extends AbstractCrdt {
52
53
  },
53
54
  ];
54
55
  }
55
- _attachChild(id, key, crdt) {
56
+ /**
57
+ * INTERNAL
58
+ */
59
+ _toSerializedCrdt() {
60
+ var _a;
61
+ return {
62
+ type: CrdtType.Register,
63
+ parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
64
+ parentKey: this._parentKey,
65
+ data: this.data,
66
+ };
67
+ }
68
+ _attachChild(id, key, crdt, isLocal) {
56
69
  throw new Error("Method not implemented.");
57
70
  }
58
71
  _detachChild(crdt) {
59
72
  throw new Error("Method not implemented.");
60
73
  }
61
- _apply(op) {
62
- return super._apply(op);
74
+ _apply(op, isLocal) {
75
+ return super._apply(op, isLocal);
63
76
  }
64
77
  }
65
78
  _LiveRegister_data = new WeakMap();
@@ -1,5 +1,5 @@
1
1
  export { LiveObject } from "./LiveObject";
2
2
  export { LiveMap } from "./LiveMap";
3
3
  export { LiveList } from "./LiveList";
4
- export type { Others, Presence, Room, Client, User } from "./types";
4
+ export type { Others, Presence, Room, Client, User, BroadcastOptions, } from "./types";
5
5
  export { createClient } from "./client";
package/lib/esm/live.d.ts CHANGED
@@ -122,6 +122,7 @@ export declare type UpdateObjectOp = {
122
122
  };
123
123
  };
124
124
  export declare type CreateObjectOp = {
125
+ opId?: string;
125
126
  id: string;
126
127
  type: OpType.CreateObject;
127
128
  parentId?: string;
@@ -131,18 +132,21 @@ export declare type CreateObjectOp = {
131
132
  };
132
133
  };
133
134
  export declare type CreateListOp = {
135
+ opId?: string;
134
136
  id: string;
135
137
  type: OpType.CreateList;
136
138
  parentId: string;
137
139
  parentKey: string;
138
140
  };
139
141
  export declare type CreateMapOp = {
142
+ opId?: string;
140
143
  id: string;
141
144
  type: OpType.CreateMap;
142
145
  parentId: string;
143
146
  parentKey: string;
144
147
  };
145
148
  export declare type CreateRegisterOp = {
149
+ opId?: string;
146
150
  id: string;
147
151
  type: OpType.CreateRegister;
148
152
  parentId: string;
@@ -150,15 +154,18 @@ export declare type CreateRegisterOp = {
150
154
  data: any;
151
155
  };
152
156
  export declare type DeleteCrdtOp = {
157
+ opId?: string;
153
158
  id: string;
154
159
  type: OpType.DeleteCrdt;
155
160
  };
156
161
  export declare type SetParentKeyOp = {
162
+ opId?: string;
157
163
  id: string;
158
164
  type: OpType.SetParentKey;
159
165
  parentKey: string;
160
166
  };
161
167
  export declare type DeleteObjectKeyOp = {
168
+ opId?: string;
162
169
  id: string;
163
170
  type: OpType.DeleteObjectKey;
164
171
  key: string;
package/lib/esm/room.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Others, Presence, ClientOptions, Room, MyPresenceCallback, OthersEventCallback, AuthEndpoint, EventCallback, User, Connection, ErrorCallback, AuthenticationToken, ConnectionCallback, StorageCallback, StorageUpdate } from "./types";
1
+ import { Others, Presence, ClientOptions, Room, MyPresenceCallback, OthersEventCallback, AuthEndpoint, EventCallback, User, Connection, ErrorCallback, AuthenticationToken, ConnectionCallback, StorageCallback, StorageUpdate, BroadcastOptions } from "./types";
2
2
  import { ClientMessage, Op } from "./live";
3
3
  import { LiveMap } from "./LiveMap";
4
4
  import { LiveObject } from "./LiveObject";
@@ -11,6 +11,7 @@ declare type HistoryItem = Array<Op | {
11
11
  declare type IdFactory = () => string;
12
12
  export declare type State = {
13
13
  connection: Connection;
14
+ lastConnectionId: number | null;
14
15
  socket: WebSocket | null;
15
16
  lastFlushTime: number;
16
17
  buffer: {
@@ -62,6 +63,7 @@ export declare type State = {
62
63
  nodes: Set<AbstractCrdt>;
63
64
  };
64
65
  };
66
+ offlineOperations: Map<string, Op>;
65
67
  };
66
68
  export declare type Effects = {
67
69
  authenticate(): void;
@@ -89,6 +91,12 @@ export declare function makeStateMachine(state: State, context: Context, mockedE
89
91
  authenticationSuccess: (token: AuthenticationToken, socket: WebSocket) => void;
90
92
  heartbeat: () => void;
91
93
  onNavigatorOnline: () => void;
94
+ simulateSocketClose: () => void;
95
+ simulateSendCloseEvent: (event: {
96
+ code: number;
97
+ wasClean: boolean;
98
+ reason: any;
99
+ }) => void;
92
100
  onVisibilityChange: (visibilityState: VisibilityState) => void;
93
101
  getUndoStack: () => HistoryItem[];
94
102
  getItemsCount: () => number;
@@ -118,7 +126,7 @@ export declare function makeStateMachine(state: State, context: Context, mockedE
118
126
  updatePresence: <T_4 extends Presence>(overrides: Partial<T_4>, options?: {
119
127
  addToHistory: boolean;
120
128
  } | undefined) => void;
121
- broadcastEvent: (event: any) => void;
129
+ broadcastEvent: (event: any, options?: BroadcastOptions) => void;
122
130
  batch: (callback: () => void) => void;
123
131
  undo: () => void;
124
132
  redo: () => void;