@liveblocks/client 0.13.3 → 0.15.0-alpha.2

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.
Files changed (45) hide show
  1. package/lib/cjs/AbstractCrdt.d.ts +13 -7
  2. package/lib/cjs/AbstractCrdt.js +2 -5
  3. package/lib/cjs/LiveList.d.ts +16 -6
  4. package/lib/cjs/LiveList.js +148 -17
  5. package/lib/cjs/LiveMap.d.ts +12 -4
  6. package/lib/cjs/LiveMap.js +57 -7
  7. package/lib/cjs/LiveObject.d.ts +22 -8
  8. package/lib/cjs/LiveObject.js +109 -24
  9. package/lib/cjs/LiveRegister.d.ts +13 -5
  10. package/lib/cjs/LiveRegister.js +23 -4
  11. package/lib/cjs/immutable.d.ts +1 -0
  12. package/lib/cjs/immutable.js +64 -6
  13. package/lib/cjs/index.d.ts +1 -0
  14. package/lib/cjs/index.js +8 -1
  15. package/lib/cjs/live.d.ts +7 -0
  16. package/lib/cjs/room.d.ts +9 -1
  17. package/lib/cjs/room.js +131 -70
  18. package/lib/cjs/types.d.ts +25 -0
  19. package/lib/cjs/utils.d.ts +4 -1
  20. package/lib/cjs/utils.js +101 -1
  21. package/lib/esm/AbstractCrdt.d.ts +13 -7
  22. package/lib/esm/AbstractCrdt.js +2 -5
  23. package/lib/esm/LiveList.d.ts +16 -6
  24. package/lib/esm/LiveList.js +149 -18
  25. package/lib/esm/LiveMap.d.ts +12 -4
  26. package/lib/esm/LiveMap.js +57 -7
  27. package/lib/esm/LiveObject.d.ts +22 -8
  28. package/lib/esm/LiveObject.js +109 -24
  29. package/lib/esm/LiveRegister.d.ts +13 -5
  30. package/lib/esm/LiveRegister.js +24 -5
  31. package/lib/esm/immutable.d.ts +1 -0
  32. package/lib/esm/immutable.js +63 -6
  33. package/lib/esm/index.d.ts +1 -0
  34. package/lib/esm/index.js +1 -0
  35. package/lib/esm/live.d.ts +7 -0
  36. package/lib/esm/room.d.ts +9 -1
  37. package/lib/esm/room.js +132 -71
  38. package/lib/esm/types.d.ts +25 -0
  39. package/lib/esm/utils.d.ts +4 -1
  40. package/lib/esm/utils.js +99 -1
  41. package/package.json +2 -2
  42. package/lib/cjs/immutable/index.d.ts +0 -7
  43. package/lib/cjs/immutable/index.js +0 -214
  44. package/lib/esm/immutable/index.d.ts +0 -7
  45. package/lib/esm/immutable/index.js +0 -207
@@ -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
  }
@@ -123,19 +130,45 @@ export class LiveObject extends AbstractCrdt {
123
130
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, child);
124
131
  child._setParentLink(this, key);
125
132
  child._attach(id, this._doc);
126
- return { reverse, modified: this };
133
+ return {
134
+ reverse,
135
+ modified: {
136
+ node: this,
137
+ type: "LiveObject",
138
+ updates: { [key]: { type: "update" } },
139
+ },
140
+ };
127
141
  }
128
142
  /**
129
143
  * INTERNAL
130
144
  */
131
145
  _detachChild(child) {
132
- for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
133
- if (value === child) {
134
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
135
- }
136
- }
137
146
  if (child) {
147
+ const reverse = child._serialize(this._id, child._parentKey, this._doc);
148
+ for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
149
+ if (value === child) {
150
+ __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
151
+ }
152
+ }
138
153
  child._detach();
154
+ const storageUpdate = {
155
+ node: this,
156
+ type: "LiveObject",
157
+ updates: {
158
+ [child._parentKey]: { type: "delete" },
159
+ },
160
+ };
161
+ return { modified: storageUpdate, reverse };
162
+ }
163
+ return { modified: false };
164
+ }
165
+ /**
166
+ * INTERNAL
167
+ */
168
+ _detachChildren() {
169
+ for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
170
+ __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
171
+ value._detach();
139
172
  }
140
173
  }
141
174
  /**
@@ -152,14 +185,32 @@ export class LiveObject extends AbstractCrdt {
152
185
  /**
153
186
  * INTERNAL
154
187
  */
155
- _apply(op) {
188
+ _apply(op, isLocal) {
156
189
  if (op.type === OpType.UpdateObject) {
157
- return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyUpdate).call(this, op);
190
+ return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyUpdate).call(this, op, isLocal);
158
191
  }
159
192
  else if (op.type === OpType.DeleteObjectKey) {
160
193
  return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyDeleteObjectKey).call(this, op);
161
194
  }
162
- return super._apply(op);
195
+ return super._apply(op, isLocal);
196
+ }
197
+ /**
198
+ * INTERNAL
199
+ */
200
+ _toSerializedCrdt() {
201
+ var _a;
202
+ return {
203
+ type: CrdtType.Object,
204
+ parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
205
+ parentKey: this._parentKey,
206
+ data: this.toObject(),
207
+ };
208
+ }
209
+ /**
210
+ * INTERNAL
211
+ */
212
+ _getType() {
213
+ return "LiveObject";
163
214
  }
164
215
  /**
165
216
  * Transform the LiveObject into a javascript object
@@ -215,7 +266,20 @@ export class LiveObject extends AbstractCrdt {
215
266
  ];
216
267
  }
217
268
  __classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString);
218
- this._doc.dispatch([{ type: OpType.DeleteObjectKey, key: keyAsString, id: this._id }], reverse, [this]);
269
+ const storageUpdates = new Map();
270
+ storageUpdates.set(this._id, {
271
+ node: this,
272
+ type: "LiveObject",
273
+ updates: { [key]: { type: "delete" } },
274
+ });
275
+ this._doc.dispatch([
276
+ {
277
+ type: OpType.DeleteObjectKey,
278
+ key: keyAsString,
279
+ id: this._id,
280
+ opId: this._doc.generateOpId(),
281
+ },
282
+ ], reverse, storageUpdates);
219
283
  }
220
284
  /**
221
285
  * Adds or updates multiple properties at once with an object.
@@ -245,6 +309,7 @@ export class LiveObject extends AbstractCrdt {
245
309
  type: OpType.UpdateObject,
246
310
  data: {},
247
311
  };
312
+ const updateDelta = {};
248
313
  for (const key in overrides) {
249
314
  __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, opId);
250
315
  const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
@@ -262,12 +327,13 @@ export class LiveObject extends AbstractCrdt {
262
327
  if (newValue instanceof AbstractCrdt) {
263
328
  newValue._setParentLink(this, key);
264
329
  newValue._attach(this._doc.generateId(), this._doc);
265
- ops.push(...newValue._serialize(this._id, key));
330
+ ops.push(...newValue._serialize(this._id, key, this._doc));
266
331
  }
267
332
  else {
268
333
  updatedProps[key] = newValue;
269
334
  }
270
335
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, newValue);
336
+ updateDelta[key] = { type: "update" };
271
337
  }
272
338
  if (Object.keys(reverseUpdateOp.data).length !== 0) {
273
339
  reverseOps.unshift(reverseUpdateOp);
@@ -280,10 +346,16 @@ export class LiveObject extends AbstractCrdt {
280
346
  data: updatedProps,
281
347
  });
282
348
  }
283
- this._doc.dispatch(ops, reverseOps, [this]);
349
+ const storageUpdates = new Map();
350
+ storageUpdates.set(this._id, {
351
+ node: this,
352
+ type: "LiveObject",
353
+ updates: updateDelta,
354
+ });
355
+ this._doc.dispatch(ops, reverseOps, storageUpdates);
284
356
  }
285
357
  }
286
- _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _LiveObject_instances = new WeakSet(), _LiveObject_applyUpdate = function _LiveObject_applyUpdate(op) {
358
+ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _LiveObject_instances = new WeakSet(), _LiveObject_applyUpdate = function _LiveObject_applyUpdate(op, isLocal) {
287
359
  let isModified = false;
288
360
  const reverse = [];
289
361
  const reverseUpdate = {
@@ -305,11 +377,7 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
305
377
  reverse.push({ type: OpType.DeleteObjectKey, id: this._id, key });
306
378
  }
307
379
  }
308
- let isLocal = false;
309
- if (op.opId == null) {
310
- isLocal = true;
311
- op.opId = this._doc.generateOpId();
312
- }
380
+ let updateDelta = {};
313
381
  for (const key in op.data) {
314
382
  if (isLocal) {
315
383
  __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, op.opId);
@@ -332,12 +400,22 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
332
400
  oldValue._detach();
333
401
  }
334
402
  isModified = true;
403
+ updateDelta[key] = { type: "update" };
335
404
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, op.data[key]);
336
405
  }
337
406
  if (Object.keys(reverseUpdate.data).length !== 0) {
338
407
  reverse.unshift(reverseUpdate);
339
408
  }
340
- return isModified ? { modified: this, reverse } : { modified: false };
409
+ return isModified
410
+ ? {
411
+ modified: {
412
+ node: this,
413
+ type: "LiveObject",
414
+ updates: updateDelta,
415
+ },
416
+ reverse,
417
+ }
418
+ : { modified: false };
341
419
  }, _LiveObject_applyDeleteObjectKey = function _LiveObject_applyDeleteObjectKey(op) {
342
420
  const key = op.key;
343
421
  // If property does not exist, exit without notifying
@@ -360,5 +438,12 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
360
438
  ];
361
439
  }
362
440
  __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
363
- return { modified: this, reverse };
441
+ return {
442
+ modified: {
443
+ node: this,
444
+ type: "LiveObject",
445
+ updates: { [op.key]: { type: "delete" } },
446
+ },
447
+ reverse,
448
+ };
364
449
  };
@@ -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,16 @@ 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;
19
- _detachChild(crdt: AbstractCrdt): void;
20
- _apply(op: Op): 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;
23
+ _detachChild(crdt: AbstractCrdt): ApplyResult;
24
+ _apply(op: Op, isLocal: boolean): ApplyResult;
25
+ /**
26
+ * INTERNAL
27
+ */
28
+ _getType(): string;
21
29
  }
@@ -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,32 @@ 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);
76
+ }
77
+ /**
78
+ * INTERNAL
79
+ */
80
+ _getType() {
81
+ return "LiveRegister";
63
82
  }
64
83
  }
65
84
  _LiveRegister_data = new WeakMap();
@@ -2,6 +2,7 @@ import { LiveList } from "./LiveList";
2
2
  import { LiveObject } from "./LiveObject";
3
3
  import { StorageUpdate } from "./types";
4
4
  export declare function liveObjectToJson(liveObject: LiveObject<any>): any;
5
+ export declare function liveNodeToJson(value: any): any;
5
6
  export declare function patchLiveList<T>(liveList: LiveList<T>, prev: Array<T>, next: Array<T>): void;
6
7
  export declare function patchLiveObjectKey<T>(liveObject: LiveObject<T>, key: keyof T, prev: any, next: any): void;
7
8
  export declare function patchLiveObject<T extends Record<string, any>>(root: LiveObject<T>, prev: T, next: T): void;
@@ -21,7 +21,7 @@ function liveMapToJson(map) {
21
21
  function liveListToJson(value) {
22
22
  return value.toArray().map(liveNodeToJson);
23
23
  }
24
- function liveNodeToJson(value) {
24
+ export function liveNodeToJson(value) {
25
25
  if (value instanceof LiveObject) {
26
26
  return liveObjectToJson(value);
27
27
  }
@@ -101,8 +101,10 @@ export function patchLiveList(liveList, prev, next) {
101
101
  }
102
102
  }
103
103
  else if (i > nextEnd) {
104
- while (i <= prevEnd) {
105
- liveList.delete(i++);
104
+ let localI = i;
105
+ while (localI <= prevEnd) {
106
+ liveList.delete(i);
107
+ localI++;
106
108
  }
107
109
  }
108
110
  else {
@@ -191,6 +193,7 @@ function patchImmutableObjectWithUpdate(state, update) {
191
193
  return patchImmutableNode(state, path, update);
192
194
  }
193
195
  function patchImmutableNode(state, path, update) {
196
+ var _a, _b, _c, _d;
194
197
  const pathItem = path.pop();
195
198
  if (pathItem === undefined) {
196
199
  switch (update.type) {
@@ -198,19 +201,73 @@ function patchImmutableNode(state, path, update) {
198
201
  if (typeof state !== "object") {
199
202
  throw new Error("Internal: received update on LiveObject but state was not an object");
200
203
  }
201
- return liveObjectToJson(update.node);
204
+ let newState = Object.assign({}, state);
205
+ for (const key in update.updates) {
206
+ if (((_a = update.updates[key]) === null || _a === void 0 ? void 0 : _a.type) === "update") {
207
+ newState[key] = liveNodeToJson(update.node.get(key));
208
+ }
209
+ else if (((_b = update.updates[key]) === null || _b === void 0 ? void 0 : _b.type) === "delete") {
210
+ delete newState[key];
211
+ }
212
+ }
213
+ return newState;
202
214
  }
203
215
  case "LiveList": {
204
216
  if (Array.isArray(state) === false) {
205
217
  throw new Error("Internal: received update on LiveList but state was not an array");
206
218
  }
207
- return liveListToJson(update.node);
219
+ let newState = state.map((x) => x);
220
+ for (const listUpdate of update.updates) {
221
+ if (listUpdate.type === "insert") {
222
+ if (listUpdate.index === newState.length) {
223
+ newState.push(liveNodeToJson(listUpdate.item));
224
+ }
225
+ else {
226
+ newState = [
227
+ ...newState.slice(0, listUpdate.index),
228
+ liveNodeToJson(listUpdate.item),
229
+ ...newState.slice(listUpdate.index),
230
+ ];
231
+ }
232
+ }
233
+ else if (listUpdate.type === "delete") {
234
+ newState.splice(listUpdate.index, 1);
235
+ }
236
+ else if (listUpdate.type === "move") {
237
+ if (listUpdate.previousIndex > listUpdate.index) {
238
+ newState = [
239
+ ...newState.slice(0, listUpdate.index),
240
+ liveNodeToJson(listUpdate.item),
241
+ ...newState.slice(listUpdate.index, listUpdate.previousIndex),
242
+ ...newState.slice(listUpdate.previousIndex + 1),
243
+ ];
244
+ }
245
+ else {
246
+ newState = [
247
+ ...newState.slice(0, listUpdate.previousIndex),
248
+ ...newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1),
249
+ liveNodeToJson(listUpdate.item),
250
+ ...newState.slice(listUpdate.index + 1),
251
+ ];
252
+ }
253
+ }
254
+ }
255
+ return newState;
208
256
  }
209
257
  case "LiveMap": {
210
258
  if (typeof state !== "object") {
211
259
  throw new Error("Internal: received update on LiveMap but state was not an object");
212
260
  }
213
- return liveMapToJson(update.node);
261
+ let newState = Object.assign({}, state);
262
+ for (const key in update.updates) {
263
+ if (((_c = update.updates[key]) === null || _c === void 0 ? void 0 : _c.type) === "update") {
264
+ newState[key] = liveNodeToJson(update.node.get(key));
265
+ }
266
+ else if (((_d = update.updates[key]) === null || _d === void 0 ? void 0 : _d.type) === "delete") {
267
+ delete newState[key];
268
+ }
269
+ }
270
+ return newState;
214
271
  }
215
272
  }
216
273
  }
@@ -3,3 +3,4 @@ export { LiveMap } from "./LiveMap";
3
3
  export { LiveList } from "./LiveList";
4
4
  export type { Others, Presence, Room, Client, User, BroadcastOptions, } from "./types";
5
5
  export { createClient } from "./client";
6
+ export { liveObjectToJson, liveNodeToJson, patchLiveList, patchImmutableObject, patchLiveObject, patchLiveObjectKey, } from "./immutable";
package/lib/esm/index.js CHANGED
@@ -2,3 +2,4 @@ export { LiveObject } from "./LiveObject";
2
2
  export { LiveMap } from "./LiveMap";
3
3
  export { LiveList } from "./LiveList";
4
4
  export { createClient } from "./client";
5
+ export { liveObjectToJson, liveNodeToJson, patchLiveList, patchImmutableObject, patchLiveObject, patchLiveObjectKey, } from "./immutable";
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
@@ -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: {
@@ -59,9 +60,10 @@ export declare type State = {
59
60
  updates: {
60
61
  others: [];
61
62
  presence: boolean;
62
- nodes: Set<AbstractCrdt>;
63
+ storageUpdates: Map<string, StorageUpdate>;
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;