@liveblocks/client 0.13.2 → 0.15.0-alpha.1

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 (41) 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 +17 -6
  4. package/lib/cjs/LiveList.js +140 -15
  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/index.d.ts → immutable.d.ts} +5 -3
  12. package/lib/cjs/{immutable/index.js → immutable.js} +77 -19
  13. package/lib/cjs/index.d.ts +2 -1
  14. package/lib/cjs/index.js +8 -1
  15. package/lib/cjs/live.d.ts +7 -0
  16. package/lib/cjs/room.d.ts +11 -3
  17. package/lib/cjs/room.js +150 -76
  18. package/lib/cjs/types.d.ts +33 -1
  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 +17 -6
  24. package/lib/esm/LiveList.js +141 -16
  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/index.d.ts → immutable.d.ts} +5 -3
  32. package/lib/esm/{immutable/index.js → immutable.js} +75 -19
  33. package/lib/esm/index.d.ts +2 -1
  34. package/lib/esm/index.js +1 -0
  35. package/lib/esm/live.d.ts +7 -0
  36. package/lib/esm/room.d.ts +11 -3
  37. package/lib/esm/room.js +151 -77
  38. package/lib/esm/types.d.ts +33 -1
  39. package/lib/esm/utils.d.ts +4 -1
  40. package/lib/esm/utils.js +99 -1
  41. package/package.json +1 -1
@@ -38,13 +38,14 @@ class LiveObject extends AbstractCrdt_1.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
  }
45
45
  const ops = [];
46
46
  const op = {
47
47
  id: this._id,
48
+ opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
48
49
  type: live_1.OpType.CreateObject,
49
50
  parentId,
50
51
  parentKey,
@@ -53,7 +54,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
53
54
  ops.push(op);
54
55
  for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
55
56
  if (value instanceof AbstractCrdt_1.AbstractCrdt) {
56
- ops.push(...value._serialize(this._id, key));
57
+ ops.push(...value._serialize(this._id, key, doc));
57
58
  }
58
59
  else {
59
60
  op.data[key] = value;
@@ -70,7 +71,13 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
70
71
  }
71
72
  const object = new LiveObject(item.data);
72
73
  object._attach(id, doc);
73
- const children = parentToChildren.get(id);
74
+ return this._deserializeChildren(object, parentToChildren, doc);
75
+ }
76
+ /**
77
+ * INTERNAL
78
+ */
79
+ static _deserializeChildren(object, parentToChildren, doc) {
80
+ const children = parentToChildren.get(object._id);
74
81
  if (children == null) {
75
82
  return object;
76
83
  }
@@ -99,7 +106,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
99
106
  /**
100
107
  * INTERNAL
101
108
  */
102
- _attachChild(id, key, child) {
109
+ _attachChild(id, key, child, isLocal) {
103
110
  if (this._doc == null) {
104
111
  throw new Error("Can't attach child if doc is not present");
105
112
  }
@@ -126,19 +133,45 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
126
133
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, child);
127
134
  child._setParentLink(this, key);
128
135
  child._attach(id, this._doc);
129
- return { reverse, modified: this };
136
+ return {
137
+ reverse,
138
+ modified: {
139
+ node: this,
140
+ type: "LiveObject",
141
+ updates: { [key]: { type: "update" } },
142
+ },
143
+ };
130
144
  }
131
145
  /**
132
146
  * INTERNAL
133
147
  */
134
148
  _detachChild(child) {
135
- for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
136
- if (value === child) {
137
- __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
138
- }
139
- }
140
149
  if (child) {
150
+ const reverse = this._serialize(this._id, child._parentKey, this._doc);
151
+ for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
152
+ if (value === child) {
153
+ __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
154
+ }
155
+ }
141
156
  child._detach();
157
+ const storageUpdate = {
158
+ node: this,
159
+ type: "LiveObject",
160
+ updates: {
161
+ [child._parentKey]: { type: "delete" },
162
+ },
163
+ };
164
+ return { modified: storageUpdate, reverse };
165
+ }
166
+ return { modified: false };
167
+ }
168
+ /**
169
+ * INTERNAL
170
+ */
171
+ _detachChildren() {
172
+ for (const [key, value] of __classPrivateFieldGet(this, _LiveObject_map, "f")) {
173
+ __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
174
+ value._detach();
142
175
  }
143
176
  }
144
177
  /**
@@ -155,14 +188,32 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
155
188
  /**
156
189
  * INTERNAL
157
190
  */
158
- _apply(op) {
191
+ _apply(op, isLocal) {
159
192
  if (op.type === live_1.OpType.UpdateObject) {
160
- return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyUpdate).call(this, op);
193
+ return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyUpdate).call(this, op, isLocal);
161
194
  }
162
195
  else if (op.type === live_1.OpType.DeleteObjectKey) {
163
196
  return __classPrivateFieldGet(this, _LiveObject_instances, "m", _LiveObject_applyDeleteObjectKey).call(this, op);
164
197
  }
165
- return super._apply(op);
198
+ return super._apply(op, isLocal);
199
+ }
200
+ /**
201
+ * INTERNAL
202
+ */
203
+ _toSerializedCrdt() {
204
+ var _a;
205
+ return {
206
+ type: live_1.CrdtType.Object,
207
+ parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
208
+ parentKey: this._parentKey,
209
+ data: this.toObject(),
210
+ };
211
+ }
212
+ /**
213
+ * INTERNAL
214
+ */
215
+ _getType() {
216
+ return "LiveObject";
166
217
  }
167
218
  /**
168
219
  * Transform the LiveObject into a javascript object
@@ -218,7 +269,20 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
218
269
  ];
219
270
  }
220
271
  __classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString);
221
- this._doc.dispatch([{ type: live_1.OpType.DeleteObjectKey, key: keyAsString, id: this._id }], reverse, [this]);
272
+ const storageUpdates = new Map();
273
+ storageUpdates.set(this._id, {
274
+ node: this,
275
+ type: "LiveObject",
276
+ updates: { [key]: { type: "delete" } },
277
+ });
278
+ this._doc.dispatch([
279
+ {
280
+ type: live_1.OpType.DeleteObjectKey,
281
+ key: keyAsString,
282
+ id: this._id,
283
+ opId: this._doc.generateOpId(),
284
+ },
285
+ ], reverse, storageUpdates);
222
286
  }
223
287
  /**
224
288
  * Adds or updates multiple properties at once with an object.
@@ -248,6 +312,7 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
248
312
  type: live_1.OpType.UpdateObject,
249
313
  data: {},
250
314
  };
315
+ const updateDelta = {};
251
316
  for (const key in overrides) {
252
317
  __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, opId);
253
318
  const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key);
@@ -265,12 +330,13 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
265
330
  if (newValue instanceof AbstractCrdt_1.AbstractCrdt) {
266
331
  newValue._setParentLink(this, key);
267
332
  newValue._attach(this._doc.generateId(), this._doc);
268
- ops.push(...newValue._serialize(this._id, key));
333
+ ops.push(...newValue._serialize(this._id, key, this._doc));
269
334
  }
270
335
  else {
271
336
  updatedProps[key] = newValue;
272
337
  }
273
338
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, newValue);
339
+ updateDelta[key] = { type: "update" };
274
340
  }
275
341
  if (Object.keys(reverseUpdateOp.data).length !== 0) {
276
342
  reverseOps.unshift(reverseUpdateOp);
@@ -283,11 +349,17 @@ class LiveObject extends AbstractCrdt_1.AbstractCrdt {
283
349
  data: updatedProps,
284
350
  });
285
351
  }
286
- this._doc.dispatch(ops, reverseOps, [this]);
352
+ const storageUpdates = new Map();
353
+ storageUpdates.set(this._id, {
354
+ node: this,
355
+ type: "LiveObject",
356
+ updates: updateDelta,
357
+ });
358
+ this._doc.dispatch(ops, reverseOps, storageUpdates);
287
359
  }
288
360
  }
289
361
  exports.LiveObject = LiveObject;
290
- _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _LiveObject_instances = new WeakSet(), _LiveObject_applyUpdate = function _LiveObject_applyUpdate(op) {
362
+ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _LiveObject_instances = new WeakSet(), _LiveObject_applyUpdate = function _LiveObject_applyUpdate(op, isLocal) {
291
363
  let isModified = false;
292
364
  const reverse = [];
293
365
  const reverseUpdate = {
@@ -309,11 +381,7 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
309
381
  reverse.push({ type: live_1.OpType.DeleteObjectKey, id: this._id, key });
310
382
  }
311
383
  }
312
- let isLocal = false;
313
- if (op.opId == null) {
314
- isLocal = true;
315
- op.opId = this._doc.generateOpId();
316
- }
384
+ let updateDelta = {};
317
385
  for (const key in op.data) {
318
386
  if (isLocal) {
319
387
  __classPrivateFieldGet(this, _LiveObject_propToLastUpdate, "f").set(key, op.opId);
@@ -336,12 +404,22 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
336
404
  oldValue._detach();
337
405
  }
338
406
  isModified = true;
407
+ updateDelta[key] = { type: "update" };
339
408
  __classPrivateFieldGet(this, _LiveObject_map, "f").set(key, op.data[key]);
340
409
  }
341
410
  if (Object.keys(reverseUpdate.data).length !== 0) {
342
411
  reverse.unshift(reverseUpdate);
343
412
  }
344
- return isModified ? { modified: this, reverse } : { modified: false };
413
+ return isModified
414
+ ? {
415
+ modified: {
416
+ node: this,
417
+ type: "LiveObject",
418
+ updates: updateDelta,
419
+ },
420
+ reverse,
421
+ }
422
+ : { modified: false };
345
423
  }, _LiveObject_applyDeleteObjectKey = function _LiveObject_applyDeleteObjectKey(op) {
346
424
  const key = op.key;
347
425
  // If property does not exist, exit without notifying
@@ -364,5 +442,12 @@ _LiveObject_map = new WeakMap(), _LiveObject_propToLastUpdate = new WeakMap(), _
364
442
  ];
365
443
  }
366
444
  __classPrivateFieldGet(this, _LiveObject_map, "f").delete(key);
367
- return { modified: this, reverse };
445
+ return {
446
+ modified: {
447
+ node: this,
448
+ type: "LiveObject",
449
+ updates: { [op.key]: { type: "delete" } },
450
+ },
451
+ reverse,
452
+ };
368
453
  };
@@ -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
  }
@@ -41,13 +41,14 @@ class LiveRegister extends AbstractCrdt_1.AbstractCrdt {
41
41
  /**
42
42
  * INTERNAL
43
43
  */
44
- _serialize(parentId, parentKey) {
44
+ _serialize(parentId, parentKey, doc) {
45
45
  if (this._id == null || parentId == null || parentKey == null) {
46
46
  throw new Error("Cannot serialize register if parentId or parentKey is undefined");
47
47
  }
48
48
  return [
49
49
  {
50
50
  type: live_1.OpType.CreateRegister,
51
+ opId: doc === null || doc === void 0 ? void 0 : doc.generateOpId(),
51
52
  id: this._id,
52
53
  parentId,
53
54
  parentKey,
@@ -55,14 +56,32 @@ class LiveRegister extends AbstractCrdt_1.AbstractCrdt {
55
56
  },
56
57
  ];
57
58
  }
58
- _attachChild(id, key, crdt) {
59
+ /**
60
+ * INTERNAL
61
+ */
62
+ _toSerializedCrdt() {
63
+ var _a;
64
+ return {
65
+ type: live_1.CrdtType.Register,
66
+ parentId: (_a = this._parent) === null || _a === void 0 ? void 0 : _a._id,
67
+ parentKey: this._parentKey,
68
+ data: this.data,
69
+ };
70
+ }
71
+ _attachChild(id, key, crdt, isLocal) {
59
72
  throw new Error("Method not implemented.");
60
73
  }
61
74
  _detachChild(crdt) {
62
75
  throw new Error("Method not implemented.");
63
76
  }
64
- _apply(op) {
65
- return super._apply(op);
77
+ _apply(op, isLocal) {
78
+ return super._apply(op, isLocal);
79
+ }
80
+ /**
81
+ * INTERNAL
82
+ */
83
+ _getType() {
84
+ return "LiveRegister";
66
85
  }
67
86
  }
68
87
  exports.LiveRegister = LiveRegister;
@@ -1,7 +1,9 @@
1
- import { LiveList } from "../LiveList";
2
- import { LiveObject } from "../LiveObject";
3
- import { StorageUpdate } from "../types";
1
+ import { LiveList } from "./LiveList";
2
+ import { LiveObject } from "./LiveObject";
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;
7
+ export declare function patchLiveObjectKey<T>(liveObject: LiveObject<T>, key: keyof T, prev: any, next: any): void;
6
8
  export declare function patchLiveObject<T extends Record<string, any>>(root: LiveObject<T>, prev: T, next: T): void;
7
9
  export declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patchImmutableObject = exports.patchLiveObject = exports.patchLiveList = exports.liveObjectToJson = void 0;
4
- const LiveList_1 = require("../LiveList");
5
- const LiveMap_1 = require("../LiveMap");
6
- const LiveObject_1 = require("../LiveObject");
3
+ exports.patchImmutableObject = exports.patchLiveObject = exports.patchLiveObjectKey = exports.patchLiveList = exports.liveNodeToJson = exports.liveObjectToJson = void 0;
4
+ const LiveList_1 = require("./LiveList");
5
+ const LiveMap_1 = require("./LiveMap");
6
+ const LiveObject_1 = require("./LiveObject");
7
+ const LiveRegister_1 = require("./LiveRegister");
7
8
  function liveObjectToJson(liveObject) {
8
9
  const result = {};
9
10
  const obj = liveObject.toObject();
@@ -34,8 +35,12 @@ function liveNodeToJson(value) {
34
35
  else if (value instanceof LiveMap_1.LiveMap) {
35
36
  return liveMapToJson(value);
36
37
  }
38
+ else if (value instanceof LiveRegister_1.LiveRegister) {
39
+ return value.data;
40
+ }
37
41
  return value;
38
42
  }
43
+ exports.liveNodeToJson = liveNodeToJson;
39
44
  function isPlainObject(obj) {
40
45
  return Object.prototype.toString.call(obj) === "[object Object]";
41
46
  }
@@ -132,21 +137,36 @@ function patchLiveList(liveList, prev, next) {
132
137
  }
133
138
  }
134
139
  exports.patchLiveList = patchLiveList;
140
+ function patchLiveObjectKey(liveObject, key, prev, next) {
141
+ const value = liveObject.get(key);
142
+ if (next === undefined) {
143
+ liveObject.delete(key);
144
+ }
145
+ else if (value === undefined) {
146
+ liveObject.set(key, anyToCrdt(next));
147
+ }
148
+ else if (prev === next) {
149
+ return;
150
+ }
151
+ else if (value instanceof LiveList_1.LiveList &&
152
+ Array.isArray(prev) &&
153
+ Array.isArray(next)) {
154
+ patchLiveList(value, prev, next);
155
+ }
156
+ else if (value instanceof LiveObject_1.LiveObject &&
157
+ isPlainObject(prev) &&
158
+ isPlainObject(next)) {
159
+ patchLiveObject(value, prev, next);
160
+ }
161
+ else {
162
+ liveObject.set(key, anyToCrdt(next));
163
+ }
164
+ }
165
+ exports.patchLiveObjectKey = patchLiveObjectKey;
135
166
  function patchLiveObject(root, prev, next) {
136
167
  const updates = {};
137
168
  for (const key in next) {
138
- if (prev[key] === next[key]) {
139
- continue;
140
- }
141
- else if (Array.isArray(prev[key]) && Array.isArray(next[key])) {
142
- patchLiveList(root.get(key), prev[key], next[key]);
143
- }
144
- else if (isPlainObject(prev[key]) && isPlainObject(next[key])) {
145
- patchLiveObject(root.get(key), prev[key], next[key]);
146
- }
147
- else {
148
- updates[key] = anyToCrdt(next[key]);
149
- }
169
+ patchLiveObjectKey(root, key, prev[key], next[key]);
150
170
  }
151
171
  for (const key in prev) {
152
172
  if (next[key] === undefined) {
@@ -180,6 +200,7 @@ function patchImmutableObjectWithUpdate(state, update) {
180
200
  return patchImmutableNode(state, path, update);
181
201
  }
182
202
  function patchImmutableNode(state, path, update) {
203
+ var _a, _b, _c, _d;
183
204
  const pathItem = path.pop();
184
205
  if (pathItem === undefined) {
185
206
  switch (update.type) {
@@ -187,19 +208,56 @@ function patchImmutableNode(state, path, update) {
187
208
  if (typeof state !== "object") {
188
209
  throw new Error("Internal: received update on LiveObject but state was not an object");
189
210
  }
190
- return liveObjectToJson(update.node);
211
+ let newState = Object.assign({}, state);
212
+ for (const key in update.updates) {
213
+ if (((_a = update.updates[key]) === null || _a === void 0 ? void 0 : _a.type) === "update") {
214
+ newState[key] = liveNodeToJson(update.node.get(key));
215
+ }
216
+ else if (((_b = update.updates[key]) === null || _b === void 0 ? void 0 : _b.type) === "delete") {
217
+ delete newState[key];
218
+ }
219
+ }
220
+ return newState;
191
221
  }
192
222
  case "LiveList": {
193
223
  if (Array.isArray(state) === false) {
194
224
  throw new Error("Internal: received update on LiveList but state was not an array");
195
225
  }
196
- return liveListToJson(update.node);
226
+ let newState = state.map((x) => x);
227
+ const newArray = update.node.toArray();
228
+ for (const listUpdate of update.updates) {
229
+ if (listUpdate.type === "insert") {
230
+ if (listUpdate.index === newState.length) {
231
+ newState.push(liveNodeToJson(newArray[listUpdate.index]));
232
+ }
233
+ else {
234
+ newState = [
235
+ ...newState.slice(0, listUpdate.index),
236
+ liveNodeToJson(newArray[listUpdate.index]),
237
+ ...newState.slice(listUpdate.index),
238
+ ];
239
+ }
240
+ }
241
+ else if (listUpdate.type === "delete") {
242
+ newState.splice(listUpdate.index, 1);
243
+ }
244
+ }
245
+ return newState;
197
246
  }
198
247
  case "LiveMap": {
199
248
  if (typeof state !== "object") {
200
249
  throw new Error("Internal: received update on LiveMap but state was not an object");
201
250
  }
202
- return liveMapToJson(update.node);
251
+ let newState = Object.assign({}, state);
252
+ for (const key in update.updates) {
253
+ if (((_c = update.updates[key]) === null || _c === void 0 ? void 0 : _c.type) === "update") {
254
+ newState[key] = liveNodeToJson(update.node.get(key));
255
+ }
256
+ else if (((_d = update.updates[key]) === null || _d === void 0 ? void 0 : _d.type) === "delete") {
257
+ delete newState[key];
258
+ }
259
+ }
260
+ return newState;
203
261
  }
204
262
  }
205
263
  }
@@ -1,5 +1,6 @@
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";
6
+ export { liveObjectToJson, liveNodeToJson, patchLiveList, patchImmutableObject, patchLiveObject, patchLiveObjectKey, } from "./immutable";
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createClient = exports.LiveList = exports.LiveMap = exports.LiveObject = void 0;
3
+ exports.patchLiveObjectKey = exports.patchLiveObject = exports.patchImmutableObject = exports.patchLiveList = exports.liveNodeToJson = exports.liveObjectToJson = exports.createClient = exports.LiveList = exports.LiveMap = exports.LiveObject = void 0;
4
4
  var LiveObject_1 = require("./LiveObject");
5
5
  Object.defineProperty(exports, "LiveObject", { enumerable: true, get: function () { return LiveObject_1.LiveObject; } });
6
6
  var LiveMap_1 = require("./LiveMap");
@@ -9,3 +9,10 @@ var LiveList_1 = require("./LiveList");
9
9
  Object.defineProperty(exports, "LiveList", { enumerable: true, get: function () { return LiveList_1.LiveList; } });
10
10
  var client_1 = require("./client");
11
11
  Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
12
+ var immutable_1 = require("./immutable");
13
+ Object.defineProperty(exports, "liveObjectToJson", { enumerable: true, get: function () { return immutable_1.liveObjectToJson; } });
14
+ Object.defineProperty(exports, "liveNodeToJson", { enumerable: true, get: function () { return immutable_1.liveNodeToJson; } });
15
+ Object.defineProperty(exports, "patchLiveList", { enumerable: true, get: function () { return immutable_1.patchLiveList; } });
16
+ Object.defineProperty(exports, "patchImmutableObject", { enumerable: true, get: function () { return immutable_1.patchImmutableObject; } });
17
+ Object.defineProperty(exports, "patchLiveObject", { enumerable: true, get: function () { return immutable_1.patchLiveObject; } });
18
+ Object.defineProperty(exports, "patchLiveObjectKey", { enumerable: true, get: function () { return immutable_1.patchLiveObjectKey; } });
package/lib/cjs/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/cjs/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: {
@@ -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;
@@ -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;