@liveblocks/client 0.15.0-alpha.3 → 0.15.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 (59) hide show
  1. package/README.md +5 -10
  2. package/lib/esm/index.js +2991 -5
  3. package/lib/esm/index.mjs +2991 -0
  4. package/lib/esm/internal.js +149 -0
  5. package/lib/esm/internal.mjs +149 -0
  6. package/lib/{esm/types.d.ts → index.d.ts} +253 -61
  7. package/lib/index.js +4237 -0
  8. package/lib/{esm/live.d.ts → internal.d.ts} +46 -34
  9. package/lib/internal.js +193 -0
  10. package/package.json +32 -10
  11. package/lib/cjs/AbstractCrdt.d.ts +0 -68
  12. package/lib/cjs/AbstractCrdt.js +0 -95
  13. package/lib/cjs/LiveList.d.ts +0 -144
  14. package/lib/cjs/LiveList.js +0 -530
  15. package/lib/cjs/LiveMap.d.ts +0 -91
  16. package/lib/cjs/LiveMap.js +0 -325
  17. package/lib/cjs/LiveObject.d.ts +0 -80
  18. package/lib/cjs/LiveObject.js +0 -485
  19. package/lib/cjs/LiveRegister.d.ts +0 -29
  20. package/lib/cjs/LiveRegister.js +0 -88
  21. package/lib/cjs/client.d.ts +0 -27
  22. package/lib/cjs/client.js +0 -123
  23. package/lib/cjs/immutable.d.ts +0 -9
  24. package/lib/cjs/immutable.js +0 -299
  25. package/lib/cjs/index.d.ts +0 -6
  26. package/lib/cjs/index.js +0 -18
  27. package/lib/cjs/live.d.ts +0 -181
  28. package/lib/cjs/live.js +0 -49
  29. package/lib/cjs/position.d.ts +0 -6
  30. package/lib/cjs/position.js +0 -113
  31. package/lib/cjs/room.d.ts +0 -159
  32. package/lib/cjs/room.js +0 -1129
  33. package/lib/cjs/types.d.ts +0 -502
  34. package/lib/cjs/types.js +0 -2
  35. package/lib/cjs/utils.d.ts +0 -15
  36. package/lib/cjs/utils.js +0 -225
  37. package/lib/esm/AbstractCrdt.d.ts +0 -68
  38. package/lib/esm/AbstractCrdt.js +0 -91
  39. package/lib/esm/LiveList.d.ts +0 -144
  40. package/lib/esm/LiveList.js +0 -526
  41. package/lib/esm/LiveMap.d.ts +0 -91
  42. package/lib/esm/LiveMap.js +0 -321
  43. package/lib/esm/LiveObject.d.ts +0 -80
  44. package/lib/esm/LiveObject.js +0 -481
  45. package/lib/esm/LiveRegister.d.ts +0 -29
  46. package/lib/esm/LiveRegister.js +0 -84
  47. package/lib/esm/client.d.ts +0 -27
  48. package/lib/esm/client.js +0 -119
  49. package/lib/esm/immutable.d.ts +0 -9
  50. package/lib/esm/immutable.js +0 -290
  51. package/lib/esm/index.d.ts +0 -6
  52. package/lib/esm/live.js +0 -46
  53. package/lib/esm/position.d.ts +0 -6
  54. package/lib/esm/position.js +0 -106
  55. package/lib/esm/room.d.ts +0 -159
  56. package/lib/esm/room.js +0 -1123
  57. package/lib/esm/types.js +0 -1
  58. package/lib/esm/utils.d.ts +0 -15
  59. package/lib/esm/utils.js +0 -213
package/lib/esm/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +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;
12
- export declare function findNonSerializableValue(value: any, path?: string): {
13
- path: string;
14
- value: any;
15
- } | false;
package/lib/esm/utils.js DELETED
@@ -1,213 +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
- }
165
- function isPlain(value) {
166
- const type = typeof value;
167
- return (type === "undefined" ||
168
- value === null ||
169
- type === "string" ||
170
- type === "boolean" ||
171
- type === "number" ||
172
- Array.isArray(value) ||
173
- isPlainObject(value));
174
- }
175
- function isPlainObject(value) {
176
- if (typeof value !== "object" || value === null)
177
- return false;
178
- let proto = Object.getPrototypeOf(value);
179
- if (proto === null)
180
- return true;
181
- let baseProto = proto;
182
- while (Object.getPrototypeOf(baseProto) !== null) {
183
- baseProto = Object.getPrototypeOf(baseProto);
184
- }
185
- return proto === baseProto;
186
- }
187
- export function findNonSerializableValue(value, path = "") {
188
- if (!isPlain) {
189
- return {
190
- path: path || "root",
191
- value: value,
192
- };
193
- }
194
- if (typeof value !== "object" || value === null) {
195
- return false;
196
- }
197
- for (const [key, nestedValue] of Object.entries(value)) {
198
- const nestedPath = path ? path + "." + key : key;
199
- if (!isPlain(nestedValue)) {
200
- return {
201
- path: nestedPath,
202
- value: nestedValue,
203
- };
204
- }
205
- if (typeof nestedValue === "object") {
206
- const nonSerializableNestedValue = findNonSerializableValue(nestedValue, nestedPath);
207
- if (nonSerializableNestedValue) {
208
- return nonSerializableNestedValue;
209
- }
210
- }
211
- }
212
- return false;
213
- }