@liveblocks/client 0.15.0-alpha.2 → 0.15.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.
- package/lib/esm/index.js +2991 -5
- package/lib/esm/index.mjs +2991 -0
- package/lib/esm/internal.js +149 -0
- package/lib/esm/internal.mjs +149 -0
- package/lib/{esm/types.d.ts → index.d.ts} +255 -50
- package/lib/index.js +4237 -0
- package/lib/{esm/live.d.ts → internal.d.ts} +46 -34
- package/lib/internal.js +193 -0
- package/package.json +36 -9
- package/lib/cjs/AbstractCrdt.d.ts +0 -67
- package/lib/cjs/AbstractCrdt.js +0 -95
- package/lib/cjs/LiveList.d.ts +0 -144
- package/lib/cjs/LiveList.js +0 -527
- package/lib/cjs/LiveMap.d.ts +0 -91
- package/lib/cjs/LiveMap.js +0 -322
- package/lib/cjs/LiveObject.d.ts +0 -80
- package/lib/cjs/LiveObject.js +0 -453
- package/lib/cjs/LiveRegister.d.ts +0 -29
- package/lib/cjs/LiveRegister.js +0 -88
- package/lib/cjs/authentication.d.ts +0 -3
- package/lib/cjs/authentication.js +0 -71
- package/lib/cjs/client.d.ts +0 -27
- package/lib/cjs/client.js +0 -80
- package/lib/cjs/immutable.d.ts +0 -9
- package/lib/cjs/immutable.js +0 -291
- package/lib/cjs/index.d.ts +0 -6
- package/lib/cjs/index.js +0 -18
- package/lib/cjs/live.d.ts +0 -181
- package/lib/cjs/live.js +0 -49
- package/lib/cjs/position.d.ts +0 -6
- package/lib/cjs/position.js +0 -113
- package/lib/cjs/room.d.ts +0 -159
- package/lib/cjs/room.js +0 -1094
- package/lib/cjs/types.d.ts +0 -489
- package/lib/cjs/types.js +0 -2
- package/lib/cjs/utils.d.ts +0 -11
- package/lib/cjs/utils.js +0 -175
- package/lib/esm/AbstractCrdt.d.ts +0 -67
- package/lib/esm/AbstractCrdt.js +0 -91
- package/lib/esm/LiveList.d.ts +0 -144
- package/lib/esm/LiveList.js +0 -523
- package/lib/esm/LiveMap.d.ts +0 -91
- package/lib/esm/LiveMap.js +0 -318
- package/lib/esm/LiveObject.d.ts +0 -80
- package/lib/esm/LiveObject.js +0 -449
- package/lib/esm/LiveRegister.d.ts +0 -29
- package/lib/esm/LiveRegister.js +0 -84
- package/lib/esm/authentication.d.ts +0 -3
- package/lib/esm/authentication.js +0 -66
- package/lib/esm/client.d.ts +0 -27
- package/lib/esm/client.js +0 -76
- package/lib/esm/immutable.d.ts +0 -9
- package/lib/esm/immutable.js +0 -282
- package/lib/esm/index.d.ts +0 -6
- package/lib/esm/live.js +0 -46
- package/lib/esm/position.d.ts +0 -6
- package/lib/esm/position.js +0 -106
- package/lib/esm/room.d.ts +0 -159
- package/lib/esm/room.js +0 -1069
- package/lib/esm/types.js +0 -1
- package/lib/esm/utils.d.ts +0 -11
- package/lib/esm/utils.js +0 -164
package/lib/esm/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/esm/utils.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AbstractCrdt, Doc } from "./AbstractCrdt";
|
|
2
|
-
import { SerializedCrdtWithId, Op, SerializedCrdt } from "./live";
|
|
3
|
-
import { StorageUpdate } from "./types";
|
|
4
|
-
export declare function remove<T>(array: T[], item: T): void;
|
|
5
|
-
export declare function isSameNodeOrChildOf(node: AbstractCrdt, parent: AbstractCrdt): boolean;
|
|
6
|
-
export declare function deserialize(entry: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): AbstractCrdt;
|
|
7
|
-
export declare function isCrdt(obj: any): obj is AbstractCrdt;
|
|
8
|
-
export declare function selfOrRegisterValue(obj: AbstractCrdt): any;
|
|
9
|
-
export declare function selfOrRegister(obj: any): AbstractCrdt;
|
|
10
|
-
export declare function getTreesDiffOperations(currentItems: Map<string, SerializedCrdt>, newItems: Map<string, SerializedCrdt>): Op[];
|
|
11
|
-
export declare function mergeStorageUpdates(first: StorageUpdate | undefined, second: StorageUpdate): StorageUpdate;
|
package/lib/esm/utils.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { CrdtType, OpType, } from "./live";
|
|
2
|
-
import { LiveList } from "./LiveList";
|
|
3
|
-
import { LiveMap } from "./LiveMap";
|
|
4
|
-
import { LiveObject } from "./LiveObject";
|
|
5
|
-
import { LiveRegister } from "./LiveRegister";
|
|
6
|
-
export function remove(array, item) {
|
|
7
|
-
for (let i = 0; i < array.length; i++) {
|
|
8
|
-
if (array[i] === item) {
|
|
9
|
-
array.splice(i, 1);
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function isSameNodeOrChildOf(node, parent) {
|
|
15
|
-
if (node === parent) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
if (node._parent) {
|
|
19
|
-
return isSameNodeOrChildOf(node._parent, parent);
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
export function deserialize(entry, parentToChildren, doc) {
|
|
24
|
-
switch (entry[1].type) {
|
|
25
|
-
case CrdtType.Object: {
|
|
26
|
-
return LiveObject._deserialize(entry, parentToChildren, doc);
|
|
27
|
-
}
|
|
28
|
-
case CrdtType.List: {
|
|
29
|
-
return LiveList._deserialize(entry, parentToChildren, doc);
|
|
30
|
-
}
|
|
31
|
-
case CrdtType.Map: {
|
|
32
|
-
return LiveMap._deserialize(entry, parentToChildren, doc);
|
|
33
|
-
}
|
|
34
|
-
case CrdtType.Register: {
|
|
35
|
-
return LiveRegister._deserialize(entry, parentToChildren, doc);
|
|
36
|
-
}
|
|
37
|
-
default: {
|
|
38
|
-
throw new Error("Unexpected CRDT type");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export function isCrdt(obj) {
|
|
43
|
-
return (obj instanceof LiveObject ||
|
|
44
|
-
obj instanceof LiveMap ||
|
|
45
|
-
obj instanceof LiveList ||
|
|
46
|
-
obj instanceof LiveRegister);
|
|
47
|
-
}
|
|
48
|
-
export function selfOrRegisterValue(obj) {
|
|
49
|
-
if (obj instanceof LiveRegister) {
|
|
50
|
-
return obj.data;
|
|
51
|
-
}
|
|
52
|
-
return obj;
|
|
53
|
-
}
|
|
54
|
-
export function selfOrRegister(obj) {
|
|
55
|
-
if (obj instanceof LiveObject ||
|
|
56
|
-
obj instanceof LiveMap ||
|
|
57
|
-
obj instanceof LiveList) {
|
|
58
|
-
return obj;
|
|
59
|
-
}
|
|
60
|
-
else if (obj instanceof LiveRegister) {
|
|
61
|
-
throw new Error("Internal error. LiveRegister should not be created from selfOrRegister");
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return new LiveRegister(obj);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
export function getTreesDiffOperations(currentItems, newItems) {
|
|
68
|
-
const ops = [];
|
|
69
|
-
currentItems.forEach((_, id) => {
|
|
70
|
-
if (!newItems.get(id)) {
|
|
71
|
-
// Delete crdt
|
|
72
|
-
ops.push({
|
|
73
|
-
type: OpType.DeleteCrdt,
|
|
74
|
-
id: id,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
newItems.forEach((crdt, id) => {
|
|
79
|
-
const currentCrdt = currentItems.get(id);
|
|
80
|
-
if (currentCrdt) {
|
|
81
|
-
if (crdt.type === CrdtType.Object) {
|
|
82
|
-
if (JSON.stringify(crdt.data) !==
|
|
83
|
-
JSON.stringify(currentCrdt.data)) {
|
|
84
|
-
ops.push({
|
|
85
|
-
type: OpType.UpdateObject,
|
|
86
|
-
id: id,
|
|
87
|
-
data: crdt.data,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (crdt.parentKey !== currentCrdt.parentKey) {
|
|
92
|
-
ops.push({
|
|
93
|
-
type: OpType.SetParentKey,
|
|
94
|
-
id: id,
|
|
95
|
-
parentKey: crdt.parentKey,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
// new Crdt
|
|
101
|
-
switch (crdt.type) {
|
|
102
|
-
case CrdtType.Register:
|
|
103
|
-
ops.push({
|
|
104
|
-
type: OpType.CreateRegister,
|
|
105
|
-
id: id,
|
|
106
|
-
parentId: crdt.parentId,
|
|
107
|
-
parentKey: crdt.parentKey,
|
|
108
|
-
data: crdt.data,
|
|
109
|
-
});
|
|
110
|
-
break;
|
|
111
|
-
case CrdtType.List:
|
|
112
|
-
ops.push({
|
|
113
|
-
type: OpType.CreateList,
|
|
114
|
-
id: id,
|
|
115
|
-
parentId: crdt.parentId,
|
|
116
|
-
parentKey: crdt.parentKey,
|
|
117
|
-
});
|
|
118
|
-
break;
|
|
119
|
-
case CrdtType.Object:
|
|
120
|
-
ops.push({
|
|
121
|
-
type: OpType.CreateObject,
|
|
122
|
-
id: id,
|
|
123
|
-
parentId: crdt.parentId,
|
|
124
|
-
parentKey: crdt.parentKey,
|
|
125
|
-
data: crdt.data,
|
|
126
|
-
});
|
|
127
|
-
break;
|
|
128
|
-
case CrdtType.Map:
|
|
129
|
-
ops.push({
|
|
130
|
-
type: OpType.CreateMap,
|
|
131
|
-
id: id,
|
|
132
|
-
parentId: crdt.parentId,
|
|
133
|
-
parentKey: crdt.parentKey,
|
|
134
|
-
});
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return ops;
|
|
140
|
-
}
|
|
141
|
-
export function mergeStorageUpdates(first, second) {
|
|
142
|
-
if (!first) {
|
|
143
|
-
return second;
|
|
144
|
-
}
|
|
145
|
-
if (second.type === "LiveObject") {
|
|
146
|
-
const updates = first.updates;
|
|
147
|
-
for (const [key, value] of Object.entries(second.updates)) {
|
|
148
|
-
updates[key] = value;
|
|
149
|
-
}
|
|
150
|
-
return Object.assign(Object.assign({}, second), { updates: updates });
|
|
151
|
-
}
|
|
152
|
-
else if (second.type === "LiveMap") {
|
|
153
|
-
const updates = first.updates;
|
|
154
|
-
for (const [key, value] of Object.entries(second.updates)) {
|
|
155
|
-
updates[key] = value;
|
|
156
|
-
}
|
|
157
|
-
return Object.assign(Object.assign({}, second), { updates: updates });
|
|
158
|
-
}
|
|
159
|
-
else if (second.type === "LiveList") {
|
|
160
|
-
const updates = first.updates;
|
|
161
|
-
return Object.assign(Object.assign({}, second), { updates: updates.concat(second.updates) });
|
|
162
|
-
}
|
|
163
|
-
return second;
|
|
164
|
-
}
|