@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/cjs/client.js DELETED
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createClient = void 0;
4
- const room_1 = require("./room");
5
- /**
6
- * Create a client that will be responsible to communicate with liveblocks servers.
7
- *
8
- * @example
9
- * const client = createClient({
10
- * authEndpoint: "/api/auth"
11
- * });
12
- *
13
- * // It's also possible to use a function to call your authentication endpoint.
14
- * // Useful to add additional headers or use an API wrapper (like Firebase functions)
15
- * const client = createClient({
16
- * authEndpoint: async (room) => {
17
- * const response = await fetch("/api/auth", {
18
- * method: "POST",
19
- * headers: {
20
- * Authentication: "token",
21
- * "Content-Type": "application/json"
22
- * },
23
- * body: JSON.stringify({ room })
24
- * });
25
- *
26
- * return await response.json();
27
- * }
28
- * });
29
- */
30
- function createClient(options) {
31
- const clientOptions = options;
32
- const throttleDelay = getThrottleDelayFromOptions(options);
33
- const rooms = new Map();
34
- function getRoom(roomId) {
35
- const internalRoom = rooms.get(roomId);
36
- return internalRoom ? internalRoom.room : null;
37
- }
38
- function enter(roomId, options = {}) {
39
- let internalRoom = rooms.get(roomId);
40
- if (internalRoom) {
41
- return internalRoom.room;
42
- }
43
- internalRoom = (0, room_1.createRoom)({
44
- defaultPresence: options.defaultPresence,
45
- defaultStorageRoot: options.defaultStorageRoot,
46
- }, {
47
- room: roomId,
48
- throttleDelay,
49
- WebSocketPolyfill: clientOptions.WebSocketPolyfill,
50
- fetchPolyfill: clientOptions.fetchPolyfill,
51
- liveblocksServer: clientOptions.liveblocksServer || "wss://liveblocks.net/v5",
52
- authentication: prepareAuthentication(clientOptions),
53
- });
54
- rooms.set(roomId, internalRoom);
55
- if (!options.DO_NOT_USE_withoutConnecting) {
56
- internalRoom.connect();
57
- }
58
- return internalRoom.room;
59
- }
60
- function leave(roomId) {
61
- let room = rooms.get(roomId);
62
- if (room) {
63
- room.disconnect();
64
- rooms.delete(roomId);
65
- }
66
- }
67
- if (typeof window !== "undefined") {
68
- // TODO: Expose a way to clear these
69
- window.addEventListener("online", () => {
70
- for (const [, room] of rooms) {
71
- room.onNavigatorOnline();
72
- }
73
- });
74
- }
75
- if (typeof document !== "undefined") {
76
- document.addEventListener("visibilitychange", () => {
77
- for (const [, room] of rooms) {
78
- room.onVisibilityChange(document.visibilityState);
79
- }
80
- });
81
- }
82
- return {
83
- getRoom,
84
- enter,
85
- leave,
86
- };
87
- }
88
- exports.createClient = createClient;
89
- function getThrottleDelayFromOptions(options) {
90
- if (options.throttle === undefined) {
91
- return 100;
92
- }
93
- if (typeof options.throttle !== "number" ||
94
- options.throttle < 80 ||
95
- options.throttle > 1000) {
96
- throw new Error("throttle should be a number between 80 and 1000.");
97
- }
98
- return options.throttle;
99
- }
100
- function prepareAuthentication(clientOptions) {
101
- // TODO: throw descriptive errors for invalid options
102
- if (typeof clientOptions.publicApiKey === "string") {
103
- return {
104
- type: "public",
105
- publicApiKey: clientOptions.publicApiKey,
106
- url: clientOptions.publicAuthorizeEndpoint ||
107
- "https://liveblocks.io/api/public/authorize",
108
- };
109
- }
110
- else if (typeof clientOptions.authEndpoint === "string") {
111
- return {
112
- type: "private",
113
- url: clientOptions.authEndpoint,
114
- };
115
- }
116
- else if (typeof clientOptions.authEndpoint === "function") {
117
- return {
118
- type: "custom",
119
- callback: clientOptions.authEndpoint,
120
- };
121
- }
122
- throw new Error("Invalid Liveblocks client options. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient");
123
- }
@@ -1,9 +0,0 @@
1
- import { LiveList } from "./LiveList";
2
- import { LiveObject } from "./LiveObject";
3
- import { StorageUpdate } from "./types";
4
- export declare function liveObjectToJson(liveObject: LiveObject<any>): any;
5
- export declare function liveNodeToJson(value: any): any;
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;
8
- export declare function patchLiveObject<T extends Record<string, any>>(root: LiveObject<T>, prev: T, next: T): void;
9
- export declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
@@ -1,299 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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");
8
- const utils_1 = require("./utils");
9
- function liveObjectToJson(liveObject) {
10
- const result = {};
11
- const obj = liveObject.toObject();
12
- for (const key in obj) {
13
- result[key] = liveNodeToJson(obj[key]);
14
- }
15
- return result;
16
- }
17
- exports.liveObjectToJson = liveObjectToJson;
18
- function liveMapToJson(map) {
19
- const result = {};
20
- const obj = Object.fromEntries(map);
21
- for (const key in obj) {
22
- result[key] = liveNodeToJson(obj[key]);
23
- }
24
- return result;
25
- }
26
- function liveListToJson(value) {
27
- return value.toArray().map(liveNodeToJson);
28
- }
29
- function liveNodeToJson(value) {
30
- if (value instanceof LiveObject_1.LiveObject) {
31
- return liveObjectToJson(value);
32
- }
33
- else if (value instanceof LiveList_1.LiveList) {
34
- return liveListToJson(value);
35
- }
36
- else if (value instanceof LiveMap_1.LiveMap) {
37
- return liveMapToJson(value);
38
- }
39
- else if (value instanceof LiveRegister_1.LiveRegister) {
40
- return value.data;
41
- }
42
- return value;
43
- }
44
- exports.liveNodeToJson = liveNodeToJson;
45
- function isPlainObject(obj) {
46
- return Object.prototype.toString.call(obj) === "[object Object]";
47
- }
48
- function anyToCrdt(obj) {
49
- if (obj == null) {
50
- return obj;
51
- }
52
- if (Array.isArray(obj)) {
53
- return new LiveList_1.LiveList(obj.map(anyToCrdt));
54
- }
55
- if (isPlainObject(obj)) {
56
- const init = {};
57
- for (const key in obj) {
58
- init[key] = anyToCrdt(obj[key]);
59
- }
60
- return new LiveObject_1.LiveObject(init);
61
- }
62
- return obj;
63
- }
64
- function patchLiveList(liveList, prev, next) {
65
- let i = 0;
66
- let prevEnd = prev.length - 1;
67
- let nextEnd = next.length - 1;
68
- let prevNode = prev[0];
69
- let nextNode = next[0];
70
- /**
71
- * For A,B,C => A,B,C,D
72
- * i = 3, prevEnd = 2, nextEnd = 3
73
- *
74
- * For A,B,C => B,C
75
- * i = 2, prevEnd = 2, nextEnd = 1
76
- *
77
- * For B,C => A,B,C
78
- * i = 0, pre
79
- */
80
- outer: {
81
- while (prevNode === nextNode) {
82
- ++i;
83
- if (i > prevEnd || i > nextEnd) {
84
- break outer;
85
- }
86
- prevNode = prev[i];
87
- nextNode = next[i];
88
- }
89
- prevNode = prev[prevEnd];
90
- nextNode = next[nextEnd];
91
- while (prevNode === nextNode) {
92
- prevEnd--;
93
- nextEnd--;
94
- if (i > prevEnd || i > nextEnd) {
95
- break outer;
96
- }
97
- prevNode = prev[prevEnd];
98
- nextNode = next[nextEnd];
99
- }
100
- }
101
- if (i > prevEnd) {
102
- if (i <= nextEnd) {
103
- while (i <= nextEnd) {
104
- liveList.insert(anyToCrdt(next[i]), i);
105
- i++;
106
- }
107
- }
108
- }
109
- else if (i > nextEnd) {
110
- let localI = i;
111
- while (localI <= prevEnd) {
112
- liveList.delete(i);
113
- localI++;
114
- }
115
- }
116
- else {
117
- while (i <= prevEnd && i <= nextEnd) {
118
- prevNode = prev[i];
119
- nextNode = next[i];
120
- const liveListNode = liveList.get(i);
121
- if (liveListNode instanceof LiveObject_1.LiveObject &&
122
- isPlainObject(prevNode) &&
123
- isPlainObject(nextNode)) {
124
- patchLiveObject(liveListNode, prevNode, nextNode);
125
- }
126
- else {
127
- liveList.delete(i);
128
- liveList.insert(anyToCrdt(nextNode), i);
129
- }
130
- i++;
131
- }
132
- while (i <= nextEnd) {
133
- liveList.insert(anyToCrdt(next[i]), i);
134
- i++;
135
- }
136
- while (i <= prevEnd) {
137
- liveList.delete(i);
138
- i++;
139
- }
140
- }
141
- }
142
- exports.patchLiveList = patchLiveList;
143
- function patchLiveObjectKey(liveObject, key, prev, next) {
144
- if (process.env.NODE_ENV !== "production") {
145
- const nonSerializableValue = (0, utils_1.findNonSerializableValue)(next);
146
- if (nonSerializableValue) {
147
- console.error(`New state path: '${nonSerializableValue.path}' value: '${nonSerializableValue.value}' is not serializable.\nOnly serializable value can be synced with Liveblocks.`);
148
- return;
149
- }
150
- }
151
- const value = liveObject.get(key);
152
- if (next === undefined) {
153
- liveObject.delete(key);
154
- }
155
- else if (value === undefined) {
156
- liveObject.set(key, anyToCrdt(next));
157
- }
158
- else if (prev === next) {
159
- return;
160
- }
161
- else if (value instanceof LiveList_1.LiveList &&
162
- Array.isArray(prev) &&
163
- Array.isArray(next)) {
164
- patchLiveList(value, prev, next);
165
- }
166
- else if (value instanceof LiveObject_1.LiveObject &&
167
- isPlainObject(prev) &&
168
- isPlainObject(next)) {
169
- patchLiveObject(value, prev, next);
170
- }
171
- else {
172
- liveObject.set(key, anyToCrdt(next));
173
- }
174
- }
175
- exports.patchLiveObjectKey = patchLiveObjectKey;
176
- function patchLiveObject(root, prev, next) {
177
- const updates = {};
178
- for (const key in next) {
179
- patchLiveObjectKey(root, key, prev[key], next[key]);
180
- }
181
- for (const key in prev) {
182
- if (next[key] === undefined) {
183
- root.delete(key);
184
- }
185
- }
186
- if (Object.keys(updates).length > 0) {
187
- root.update(updates);
188
- }
189
- }
190
- exports.patchLiveObject = patchLiveObject;
191
- function getParentsPath(node) {
192
- const path = [];
193
- while (node._parentKey != null && node._parent != null) {
194
- if (node._parent instanceof LiveList_1.LiveList) {
195
- path.push(node._parent._indexOfPosition(node._parentKey));
196
- }
197
- else {
198
- path.push(node._parentKey);
199
- }
200
- node = node._parent;
201
- }
202
- return path;
203
- }
204
- function patchImmutableObject(state, updates) {
205
- return updates.reduce((state, update) => patchImmutableObjectWithUpdate(state, update), state);
206
- }
207
- exports.patchImmutableObject = patchImmutableObject;
208
- function patchImmutableObjectWithUpdate(state, update) {
209
- const path = getParentsPath(update.node);
210
- return patchImmutableNode(state, path, update);
211
- }
212
- function patchImmutableNode(state, path, update) {
213
- var _a, _b, _c, _d;
214
- const pathItem = path.pop();
215
- if (pathItem === undefined) {
216
- switch (update.type) {
217
- case "LiveObject": {
218
- if (typeof state !== "object") {
219
- throw new Error("Internal: received update on LiveObject but state was not an object");
220
- }
221
- let newState = Object.assign({}, state);
222
- for (const key in update.updates) {
223
- if (((_a = update.updates[key]) === null || _a === void 0 ? void 0 : _a.type) === "update") {
224
- newState[key] = liveNodeToJson(update.node.get(key));
225
- }
226
- else if (((_b = update.updates[key]) === null || _b === void 0 ? void 0 : _b.type) === "delete") {
227
- delete newState[key];
228
- }
229
- }
230
- return newState;
231
- }
232
- case "LiveList": {
233
- if (Array.isArray(state) === false) {
234
- throw new Error("Internal: received update on LiveList but state was not an array");
235
- }
236
- let newState = state.map((x) => x);
237
- for (const listUpdate of update.updates) {
238
- if (listUpdate.type === "insert") {
239
- if (listUpdate.index === newState.length) {
240
- newState.push(liveNodeToJson(listUpdate.item));
241
- }
242
- else {
243
- newState = [
244
- ...newState.slice(0, listUpdate.index),
245
- liveNodeToJson(listUpdate.item),
246
- ...newState.slice(listUpdate.index),
247
- ];
248
- }
249
- }
250
- else if (listUpdate.type === "delete") {
251
- newState.splice(listUpdate.index, 1);
252
- }
253
- else if (listUpdate.type === "move") {
254
- if (listUpdate.previousIndex > listUpdate.index) {
255
- newState = [
256
- ...newState.slice(0, listUpdate.index),
257
- liveNodeToJson(listUpdate.item),
258
- ...newState.slice(listUpdate.index, listUpdate.previousIndex),
259
- ...newState.slice(listUpdate.previousIndex + 1),
260
- ];
261
- }
262
- else {
263
- newState = [
264
- ...newState.slice(0, listUpdate.previousIndex),
265
- ...newState.slice(listUpdate.previousIndex + 1, listUpdate.index + 1),
266
- liveNodeToJson(listUpdate.item),
267
- ...newState.slice(listUpdate.index + 1),
268
- ];
269
- }
270
- }
271
- }
272
- return newState;
273
- }
274
- case "LiveMap": {
275
- if (typeof state !== "object") {
276
- throw new Error("Internal: received update on LiveMap but state was not an object");
277
- }
278
- let newState = Object.assign({}, state);
279
- for (const key in update.updates) {
280
- if (((_c = update.updates[key]) === null || _c === void 0 ? void 0 : _c.type) === "update") {
281
- newState[key] = liveNodeToJson(update.node.get(key));
282
- }
283
- else if (((_d = update.updates[key]) === null || _d === void 0 ? void 0 : _d.type) === "delete") {
284
- delete newState[key];
285
- }
286
- }
287
- return newState;
288
- }
289
- }
290
- }
291
- if (Array.isArray(state)) {
292
- const newArray = [...state];
293
- newArray[pathItem] = patchImmutableNode(state[pathItem], path, update);
294
- return newArray;
295
- }
296
- else {
297
- return Object.assign(Object.assign({}, state), { [pathItem]: patchImmutableNode(state[pathItem], path, update) });
298
- }
299
- }
@@ -1,6 +0,0 @@
1
- export { LiveObject } from "./LiveObject";
2
- export { LiveMap } from "./LiveMap";
3
- export { LiveList } from "./LiveList";
4
- export type { Others, Presence, Room, Client, User, BroadcastOptions, } from "./types";
5
- export { createClient } from "./client";
6
- export { liveObjectToJson, liveNodeToJson, patchLiveList, patchImmutableObject, patchLiveObject, patchLiveObjectKey, } from "./immutable";
package/lib/cjs/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patchLiveObjectKey = exports.patchLiveObject = exports.patchImmutableObject = exports.patchLiveList = exports.liveNodeToJson = exports.liveObjectToJson = exports.createClient = exports.LiveList = exports.LiveMap = exports.LiveObject = void 0;
4
- var LiveObject_1 = require("./LiveObject");
5
- Object.defineProperty(exports, "LiveObject", { enumerable: true, get: function () { return LiveObject_1.LiveObject; } });
6
- var LiveMap_1 = require("./LiveMap");
7
- Object.defineProperty(exports, "LiveMap", { enumerable: true, get: function () { return LiveMap_1.LiveMap; } });
8
- var LiveList_1 = require("./LiveList");
9
- Object.defineProperty(exports, "LiveList", { enumerable: true, get: function () { return LiveList_1.LiveList; } });
10
- var client_1 = require("./client");
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 DELETED
@@ -1,181 +0,0 @@
1
- import { Presence } from "./types";
2
- export declare type ServerMessage = UpdatePresenceMessage | UserJoinMessage | UserLeftMessage | EventMessage | RoomStateMessage | InitialDocumentStateMessage | UpdateStorageMessage;
3
- export declare enum ServerMessageType {
4
- UpdatePresence = 100,
5
- UserJoined = 101,
6
- UserLeft = 102,
7
- Event = 103,
8
- RoomState = 104,
9
- InitialStorageState = 200,
10
- UpdateStorage = 201
11
- }
12
- export declare type RoomStateMessage = {
13
- type: ServerMessageType.RoomState;
14
- users: {
15
- [actor: number]: {
16
- id?: string;
17
- info?: any;
18
- };
19
- };
20
- };
21
- export declare type UpdatePresenceMessage = {
22
- type: ServerMessageType.UpdatePresence;
23
- actor: number;
24
- data: Presence;
25
- };
26
- export declare type UserJoinMessage = {
27
- type: ServerMessageType.UserJoined;
28
- actor: number;
29
- id?: string;
30
- info?: string;
31
- };
32
- export declare type UserLeftMessage = {
33
- type: ServerMessageType.UserLeft;
34
- actor: number;
35
- };
36
- export declare type EventMessage = {
37
- type: ServerMessageType.Event;
38
- actor: number;
39
- event: any;
40
- };
41
- export declare type SerializedCrdtWithId = [id: string, crdt: SerializedCrdt];
42
- export declare type InitialDocumentStateMessage = {
43
- type: ServerMessageType.InitialStorageState;
44
- items: SerializedCrdtWithId[];
45
- };
46
- export declare type UpdateStorageMessage = {
47
- type: ServerMessageType.UpdateStorage;
48
- ops: Op[];
49
- };
50
- export declare type ClientMessage = ClientEventMessage | UpdatePresenceClientMessage | UpdateStorageClientMessage | FetchStorageClientMessage;
51
- export declare enum ClientMessageType {
52
- UpdatePresence = 100,
53
- ClientEvent = 103,
54
- FetchStorage = 200,
55
- UpdateStorage = 201
56
- }
57
- export declare type ClientEventMessage = {
58
- type: ClientMessageType.ClientEvent;
59
- event: any;
60
- };
61
- export declare type UpdatePresenceClientMessage = {
62
- type: ClientMessageType.UpdatePresence;
63
- data: Presence;
64
- targetActor?: number;
65
- };
66
- export declare type UpdateStorageClientMessage = {
67
- type: ClientMessageType.UpdateStorage;
68
- ops: Op[];
69
- };
70
- export declare type FetchStorageClientMessage = {
71
- type: ClientMessageType.FetchStorage;
72
- };
73
- export declare enum CrdtType {
74
- Object = 0,
75
- List = 1,
76
- Map = 2,
77
- Register = 3
78
- }
79
- export declare type SerializedObject = {
80
- type: CrdtType.Object;
81
- parentId?: string;
82
- parentKey?: string;
83
- data: {
84
- [key: string]: any;
85
- };
86
- };
87
- export declare type SerializedList = {
88
- type: CrdtType.List;
89
- parentId: string;
90
- parentKey: string;
91
- };
92
- export declare type SerializedMap = {
93
- type: CrdtType.Map;
94
- parentId: string;
95
- parentKey: string;
96
- };
97
- export declare type SerializedRegister = {
98
- type: CrdtType.Register;
99
- parentId: string;
100
- parentKey: string;
101
- data: any;
102
- };
103
- export declare type SerializedCrdt = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
104
- export declare enum OpType {
105
- Init = 0,
106
- SetParentKey = 1,
107
- CreateList = 2,
108
- UpdateObject = 3,
109
- CreateObject = 4,
110
- DeleteCrdt = 5,
111
- DeleteObjectKey = 6,
112
- CreateMap = 7,
113
- CreateRegister = 8
114
- }
115
- export declare type Op = CreateObjectOp | UpdateObjectOp | DeleteCrdtOp | CreateListOp | SetParentKeyOp | DeleteObjectKeyOp | CreateMapOp | CreateRegisterOp;
116
- export declare type UpdateObjectOp = {
117
- opId?: string;
118
- id: string;
119
- type: OpType.UpdateObject;
120
- data: {
121
- [key: string]: any;
122
- };
123
- };
124
- export declare type CreateObjectOp = {
125
- opId?: string;
126
- id: string;
127
- type: OpType.CreateObject;
128
- parentId?: string;
129
- parentKey?: string;
130
- data: {
131
- [key: string]: any;
132
- };
133
- };
134
- export declare type CreateListOp = {
135
- opId?: string;
136
- id: string;
137
- type: OpType.CreateList;
138
- parentId: string;
139
- parentKey: string;
140
- };
141
- export declare type CreateMapOp = {
142
- opId?: string;
143
- id: string;
144
- type: OpType.CreateMap;
145
- parentId: string;
146
- parentKey: string;
147
- };
148
- export declare type CreateRegisterOp = {
149
- opId?: string;
150
- id: string;
151
- type: OpType.CreateRegister;
152
- parentId: string;
153
- parentKey: string;
154
- data: any;
155
- };
156
- export declare type DeleteCrdtOp = {
157
- opId?: string;
158
- id: string;
159
- type: OpType.DeleteCrdt;
160
- };
161
- export declare type SetParentKeyOp = {
162
- opId?: string;
163
- id: string;
164
- type: OpType.SetParentKey;
165
- parentKey: string;
166
- };
167
- export declare type DeleteObjectKeyOp = {
168
- opId?: string;
169
- id: string;
170
- type: OpType.DeleteObjectKey;
171
- key: string;
172
- };
173
- export declare enum WebsocketCloseCodes {
174
- CLOSE_ABNORMAL = 1006,
175
- INVALID_MESSAGE_FORMAT = 4000,
176
- NOT_ALLOWED = 4001,
177
- MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
178
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
179
- MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
180
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005
181
- }
package/lib/cjs/live.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebsocketCloseCodes = exports.OpType = exports.CrdtType = exports.ClientMessageType = exports.ServerMessageType = void 0;
4
- var ServerMessageType;
5
- (function (ServerMessageType) {
6
- ServerMessageType[ServerMessageType["UpdatePresence"] = 100] = "UpdatePresence";
7
- ServerMessageType[ServerMessageType["UserJoined"] = 101] = "UserJoined";
8
- ServerMessageType[ServerMessageType["UserLeft"] = 102] = "UserLeft";
9
- ServerMessageType[ServerMessageType["Event"] = 103] = "Event";
10
- ServerMessageType[ServerMessageType["RoomState"] = 104] = "RoomState";
11
- ServerMessageType[ServerMessageType["InitialStorageState"] = 200] = "InitialStorageState";
12
- ServerMessageType[ServerMessageType["UpdateStorage"] = 201] = "UpdateStorage";
13
- })(ServerMessageType = exports.ServerMessageType || (exports.ServerMessageType = {}));
14
- var ClientMessageType;
15
- (function (ClientMessageType) {
16
- ClientMessageType[ClientMessageType["UpdatePresence"] = 100] = "UpdatePresence";
17
- ClientMessageType[ClientMessageType["ClientEvent"] = 103] = "ClientEvent";
18
- ClientMessageType[ClientMessageType["FetchStorage"] = 200] = "FetchStorage";
19
- ClientMessageType[ClientMessageType["UpdateStorage"] = 201] = "UpdateStorage";
20
- })(ClientMessageType = exports.ClientMessageType || (exports.ClientMessageType = {}));
21
- var CrdtType;
22
- (function (CrdtType) {
23
- CrdtType[CrdtType["Object"] = 0] = "Object";
24
- CrdtType[CrdtType["List"] = 1] = "List";
25
- CrdtType[CrdtType["Map"] = 2] = "Map";
26
- CrdtType[CrdtType["Register"] = 3] = "Register";
27
- })(CrdtType = exports.CrdtType || (exports.CrdtType = {}));
28
- var OpType;
29
- (function (OpType) {
30
- OpType[OpType["Init"] = 0] = "Init";
31
- OpType[OpType["SetParentKey"] = 1] = "SetParentKey";
32
- OpType[OpType["CreateList"] = 2] = "CreateList";
33
- OpType[OpType["UpdateObject"] = 3] = "UpdateObject";
34
- OpType[OpType["CreateObject"] = 4] = "CreateObject";
35
- OpType[OpType["DeleteCrdt"] = 5] = "DeleteCrdt";
36
- OpType[OpType["DeleteObjectKey"] = 6] = "DeleteObjectKey";
37
- OpType[OpType["CreateMap"] = 7] = "CreateMap";
38
- OpType[OpType["CreateRegister"] = 8] = "CreateRegister";
39
- })(OpType = exports.OpType || (exports.OpType = {}));
40
- var WebsocketCloseCodes;
41
- (function (WebsocketCloseCodes) {
42
- WebsocketCloseCodes[WebsocketCloseCodes["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
43
- WebsocketCloseCodes[WebsocketCloseCodes["INVALID_MESSAGE_FORMAT"] = 4000] = "INVALID_MESSAGE_FORMAT";
44
- WebsocketCloseCodes[WebsocketCloseCodes["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
45
- WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
46
- WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
47
- WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
48
- WebsocketCloseCodes[WebsocketCloseCodes["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
49
- })(WebsocketCloseCodes = exports.WebsocketCloseCodes || (exports.WebsocketCloseCodes = {}));