@liveblocks/client 0.16.16 → 0.17.0-beta2
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/index.d.ts +28 -8
- package/index.js +1290 -830
- package/index.mjs +1091 -782
- package/internal.d.ts +418 -276
- package/internal.js +313 -205
- package/internal.mjs +265 -171
- package/package.json +15 -10
- package/shared.d.ts +719 -650
- package/shared.js +2583 -1326
- package/shared.mjs +2000 -1204
package/internal.d.ts
CHANGED
|
@@ -1,45 +1,234 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
e as JsonObject,
|
|
3
|
+
J as Json,
|
|
4
|
+
B as BaseUserMeta,
|
|
5
|
+
g as Lson,
|
|
6
|
+
h as LsonObject,
|
|
7
|
+
c as LiveObject,
|
|
8
|
+
S as StorageUpdate,
|
|
9
|
+
} from "./shared.js";
|
|
10
|
+
export {
|
|
11
|
+
i as LiveNode,
|
|
12
|
+
j as Resolve,
|
|
13
|
+
k as RoomInitializers,
|
|
14
|
+
W as WebsocketCloseCodes,
|
|
15
|
+
l as isJsonArray,
|
|
16
|
+
m as isJsonObject,
|
|
17
|
+
n as isJsonScalar,
|
|
18
|
+
} from "./shared.js";
|
|
19
|
+
|
|
20
|
+
declare enum OpCode {
|
|
21
|
+
INIT = 0,
|
|
22
|
+
SET_PARENT_KEY = 1,
|
|
23
|
+
CREATE_LIST = 2,
|
|
24
|
+
UPDATE_OBJECT = 3,
|
|
25
|
+
CREATE_OBJECT = 4,
|
|
26
|
+
DELETE_CRDT = 5,
|
|
27
|
+
DELETE_OBJECT_KEY = 6,
|
|
28
|
+
CREATE_MAP = 7,
|
|
29
|
+
CREATE_REGISTER = 8,
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* These operations are the payload for {@link UpdateStorageServerMsg} messages
|
|
33
|
+
* only.
|
|
34
|
+
*/
|
|
35
|
+
declare type Op =
|
|
36
|
+
| CreateOp
|
|
37
|
+
| UpdateObjectOp
|
|
38
|
+
| DeleteCrdtOp
|
|
39
|
+
| SetParentKeyOp
|
|
40
|
+
| DeleteObjectKeyOp;
|
|
41
|
+
declare type CreateOp = CreateRootObjectOp | CreateChildOp;
|
|
42
|
+
declare type CreateChildOp =
|
|
43
|
+
| CreateObjectOp
|
|
44
|
+
| CreateRegisterOp
|
|
45
|
+
| CreateMapOp
|
|
46
|
+
| CreateListOp;
|
|
47
|
+
declare type UpdateObjectOp = {
|
|
48
|
+
opId?: string;
|
|
49
|
+
id: string;
|
|
50
|
+
type: OpCode.UPDATE_OBJECT;
|
|
51
|
+
data: Partial<JsonObject>;
|
|
52
|
+
};
|
|
53
|
+
declare type CreateObjectOp = {
|
|
54
|
+
opId?: string;
|
|
55
|
+
id: string;
|
|
56
|
+
intent?: "set";
|
|
57
|
+
deletedId?: string;
|
|
58
|
+
type: OpCode.CREATE_OBJECT;
|
|
59
|
+
parentId: string;
|
|
60
|
+
parentKey: string;
|
|
61
|
+
data: JsonObject;
|
|
62
|
+
};
|
|
63
|
+
declare type CreateRootObjectOp = {
|
|
64
|
+
opId?: string;
|
|
65
|
+
id: string;
|
|
66
|
+
type: OpCode.CREATE_OBJECT;
|
|
67
|
+
data: JsonObject;
|
|
68
|
+
parentId?: never;
|
|
69
|
+
parentKey?: never;
|
|
70
|
+
};
|
|
71
|
+
declare type CreateListOp = {
|
|
72
|
+
opId?: string;
|
|
73
|
+
id: string;
|
|
74
|
+
intent?: "set";
|
|
75
|
+
deletedId?: string;
|
|
76
|
+
type: OpCode.CREATE_LIST;
|
|
77
|
+
parentId: string;
|
|
78
|
+
parentKey: string;
|
|
79
|
+
};
|
|
80
|
+
declare type CreateMapOp = {
|
|
81
|
+
opId?: string;
|
|
82
|
+
id: string;
|
|
83
|
+
intent?: "set";
|
|
84
|
+
deletedId?: string;
|
|
85
|
+
type: OpCode.CREATE_MAP;
|
|
86
|
+
parentId: string;
|
|
87
|
+
parentKey: string;
|
|
88
|
+
};
|
|
89
|
+
declare type CreateRegisterOp = {
|
|
90
|
+
opId?: string;
|
|
91
|
+
id: string;
|
|
92
|
+
intent?: "set";
|
|
93
|
+
deletedId?: string;
|
|
94
|
+
type: OpCode.CREATE_REGISTER;
|
|
95
|
+
parentId: string;
|
|
96
|
+
parentKey: string;
|
|
97
|
+
data: Json;
|
|
98
|
+
};
|
|
99
|
+
declare type DeleteCrdtOp = {
|
|
100
|
+
opId?: string;
|
|
101
|
+
id: string;
|
|
102
|
+
type: OpCode.DELETE_CRDT;
|
|
103
|
+
};
|
|
104
|
+
declare type SetParentKeyOp = {
|
|
105
|
+
opId?: string;
|
|
106
|
+
id: string;
|
|
107
|
+
type: OpCode.SET_PARENT_KEY;
|
|
108
|
+
parentKey: string;
|
|
109
|
+
};
|
|
110
|
+
declare type DeleteObjectKeyOp = {
|
|
111
|
+
opId?: string;
|
|
112
|
+
id: string;
|
|
113
|
+
type: OpCode.DELETE_OBJECT_KEY;
|
|
114
|
+
key: string;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
declare enum ClientMsgCode {
|
|
118
|
+
UPDATE_PRESENCE = 100,
|
|
119
|
+
BROADCAST_EVENT = 103,
|
|
120
|
+
FETCH_STORAGE = 200,
|
|
121
|
+
UPDATE_STORAGE = 201,
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Messages that can be sent from the client to the server.
|
|
125
|
+
*/
|
|
126
|
+
declare type ClientMsg<TPresence extends JsonObject, TRoomEvent extends Json> =
|
|
127
|
+
| BroadcastEventClientMsg<TRoomEvent>
|
|
128
|
+
| UpdatePresenceClientMsg<TPresence>
|
|
129
|
+
| UpdateStorageClientMsg
|
|
130
|
+
| FetchStorageClientMsg;
|
|
131
|
+
declare type BroadcastEventClientMsg<TRoomEvent extends Json> = {
|
|
132
|
+
type: ClientMsgCode.BROADCAST_EVENT;
|
|
133
|
+
event: TRoomEvent;
|
|
134
|
+
};
|
|
135
|
+
declare type UpdatePresenceClientMsg<TPresence extends JsonObject> = {
|
|
136
|
+
type: ClientMsgCode.UPDATE_PRESENCE;
|
|
137
|
+
data: TPresence;
|
|
138
|
+
targetActor?: number;
|
|
139
|
+
};
|
|
140
|
+
declare type UpdateStorageClientMsg = {
|
|
141
|
+
type: ClientMsgCode.UPDATE_STORAGE;
|
|
142
|
+
ops: Op[];
|
|
143
|
+
};
|
|
144
|
+
declare type FetchStorageClientMsg = {
|
|
145
|
+
type: ClientMsgCode.FETCH_STORAGE;
|
|
146
|
+
};
|
|
3
147
|
|
|
4
148
|
declare type IdTuple<T> = [id: string, value: T];
|
|
149
|
+
declare enum CrdtType {
|
|
150
|
+
OBJECT = 0,
|
|
151
|
+
LIST = 1,
|
|
152
|
+
MAP = 2,
|
|
153
|
+
REGISTER = 3,
|
|
154
|
+
}
|
|
155
|
+
declare type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
156
|
+
declare type SerializedChild =
|
|
157
|
+
| SerializedObject
|
|
158
|
+
| SerializedList
|
|
159
|
+
| SerializedMap
|
|
160
|
+
| SerializedRegister;
|
|
161
|
+
declare type SerializedRootObject = {
|
|
162
|
+
type: CrdtType.OBJECT;
|
|
163
|
+
data: JsonObject;
|
|
164
|
+
parentId?: never;
|
|
165
|
+
parentKey?: never;
|
|
166
|
+
};
|
|
167
|
+
declare type SerializedObject = {
|
|
168
|
+
type: CrdtType.OBJECT;
|
|
169
|
+
parentId: string;
|
|
170
|
+
parentKey: string;
|
|
171
|
+
data: JsonObject;
|
|
172
|
+
};
|
|
173
|
+
declare type SerializedList = {
|
|
174
|
+
type: CrdtType.LIST;
|
|
175
|
+
parentId: string;
|
|
176
|
+
parentKey: string;
|
|
177
|
+
};
|
|
178
|
+
declare type SerializedMap = {
|
|
179
|
+
type: CrdtType.MAP;
|
|
180
|
+
parentId: string;
|
|
181
|
+
parentKey: string;
|
|
182
|
+
};
|
|
183
|
+
declare type SerializedRegister = {
|
|
184
|
+
type: CrdtType.REGISTER;
|
|
185
|
+
parentId: string;
|
|
186
|
+
parentKey: string;
|
|
187
|
+
data: Json;
|
|
188
|
+
};
|
|
189
|
+
declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
|
|
190
|
+
declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
|
|
191
|
+
|
|
5
192
|
/**
|
|
6
193
|
* Lookup table for nodes (= SerializedCrdt values) by their IDs.
|
|
7
194
|
*/
|
|
8
|
-
declare type NodeMap = Map<
|
|
9
|
-
|
|
195
|
+
declare type NodeMap = Map<
|
|
196
|
+
string, // Node ID
|
|
197
|
+
SerializedCrdt
|
|
198
|
+
>;
|
|
10
199
|
/**
|
|
11
200
|
* Reverse lookup table for all child nodes (= list of SerializedCrdt values)
|
|
12
201
|
* by their parent node's IDs.
|
|
13
202
|
*/
|
|
14
|
-
declare type ParentToChildNodeMap = Map<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
declare type ServerMsg<TPresence extends JsonObject> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg | UserLeftServerMsg | BroadcastedEventServerMsg | RoomStateServerMsg | InitialDocumentStateServerMsg | UpdateStorageServerMsg;
|
|
203
|
+
declare type ParentToChildNodeMap = Map<
|
|
204
|
+
string, // Parent's node ID
|
|
205
|
+
IdTuple<SerializedChild>[]
|
|
206
|
+
>;
|
|
207
|
+
|
|
20
208
|
declare enum ServerMsgCode {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
209
|
+
UPDATE_PRESENCE = 100,
|
|
210
|
+
USER_JOINED = 101,
|
|
211
|
+
USER_LEFT = 102,
|
|
212
|
+
BROADCASTED_EVENT = 103,
|
|
213
|
+
ROOM_STATE = 104,
|
|
214
|
+
INITIAL_STORAGE_STATE = 200,
|
|
215
|
+
UPDATE_STORAGE = 201,
|
|
28
216
|
}
|
|
29
217
|
/**
|
|
30
|
-
*
|
|
31
|
-
* joining the Room, to provide the initial state of the Room. The payload
|
|
32
|
-
* includes a list of all other Users that already are in the Room.
|
|
218
|
+
* Messages that can be sent from the server to the client.
|
|
33
219
|
*/
|
|
34
|
-
declare type
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
220
|
+
declare type ServerMsg<
|
|
221
|
+
TPresence extends JsonObject,
|
|
222
|
+
TUserMeta extends BaseUserMeta,
|
|
223
|
+
TRoomEvent extends Json
|
|
224
|
+
> =
|
|
225
|
+
| UpdatePresenceServerMsg<TPresence>
|
|
226
|
+
| UserJoinServerMsg<TUserMeta>
|
|
227
|
+
| UserLeftServerMsg
|
|
228
|
+
| BroadcastedEventServerMsg<TRoomEvent>
|
|
229
|
+
| RoomStateServerMsg<TUserMeta>
|
|
230
|
+
| InitialDocumentStateServerMsg
|
|
231
|
+
| UpdateStorageServerMsg;
|
|
43
232
|
/**
|
|
44
233
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
45
234
|
* a User updated their presence. For example, when a user moves their cursor.
|
|
@@ -52,65 +241,76 @@ declare type RoomStateServerMsg = {
|
|
|
52
241
|
* so all other existing clients can ignore this broadcasted message.
|
|
53
242
|
*/
|
|
54
243
|
declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
244
|
+
type: ServerMsgCode.UPDATE_PRESENCE;
|
|
245
|
+
/**
|
|
246
|
+
* The User whose Presence has changed.
|
|
247
|
+
*/
|
|
248
|
+
actor: number;
|
|
249
|
+
/**
|
|
250
|
+
* The partial or full Presence of a User. If the `targetActor` field is set,
|
|
251
|
+
* this will be the full Presence, otherwise it only contain the fields that
|
|
252
|
+
* have changed since the last broadcast.
|
|
253
|
+
*/
|
|
254
|
+
data: TPresence;
|
|
255
|
+
/**
|
|
256
|
+
* If this message was sent in response to a newly joined user, this field
|
|
257
|
+
* indicates which client this message is for. Other existing clients may
|
|
258
|
+
* ignore this message if this message isn't targeted for them.
|
|
259
|
+
*/
|
|
260
|
+
targetActor?: number;
|
|
72
261
|
};
|
|
73
262
|
/**
|
|
74
263
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
75
264
|
* a new User has joined the Room.
|
|
76
265
|
*/
|
|
77
|
-
declare type UserJoinServerMsg = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
266
|
+
declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
267
|
+
type: ServerMsgCode.USER_JOINED;
|
|
268
|
+
actor: number;
|
|
269
|
+
/**
|
|
270
|
+
* The id of the User that has been set in the authentication endpoint.
|
|
271
|
+
* Useful to get additional information about the connected user.
|
|
272
|
+
*/
|
|
273
|
+
id: TUserMeta["id"];
|
|
274
|
+
/**
|
|
275
|
+
* Additional user information that has been set in the authentication
|
|
276
|
+
* endpoint.
|
|
277
|
+
*/
|
|
278
|
+
info: TUserMeta["info"];
|
|
90
279
|
};
|
|
91
280
|
/**
|
|
92
281
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
93
282
|
* a new User has left the Room.
|
|
94
283
|
*/
|
|
95
284
|
declare type UserLeftServerMsg = {
|
|
96
|
-
|
|
97
|
-
|
|
285
|
+
type: ServerMsgCode.USER_LEFT;
|
|
286
|
+
actor: number;
|
|
98
287
|
};
|
|
99
288
|
/**
|
|
100
289
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
101
290
|
* a User broadcasted an Event to everyone in the Room.
|
|
102
291
|
*/
|
|
103
|
-
declare type BroadcastedEventServerMsg = {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
292
|
+
declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
|
|
293
|
+
type: ServerMsgCode.BROADCASTED_EVENT;
|
|
294
|
+
/**
|
|
295
|
+
* The User who broadcasted the Event.
|
|
296
|
+
*/
|
|
297
|
+
actor: number;
|
|
298
|
+
/**
|
|
299
|
+
* The arbitrary payload of the Event. This can be any JSON value. Clients
|
|
300
|
+
* will have to manually verify/decode this event.
|
|
301
|
+
*/
|
|
302
|
+
event: TRoomEvent;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Sent by the WebSocket server to a single client in response to the client
|
|
306
|
+
* joining the Room, to provide the initial state of the Room. The payload
|
|
307
|
+
* includes a list of all other Users that already are in the Room.
|
|
308
|
+
*/
|
|
309
|
+
declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
310
|
+
type: ServerMsgCode.ROOM_STATE;
|
|
311
|
+
users: {
|
|
312
|
+
[actor: number]: TUserMeta;
|
|
313
|
+
};
|
|
114
314
|
};
|
|
115
315
|
/**
|
|
116
316
|
* Sent by the WebSocket server to a single client in response to the client
|
|
@@ -118,8 +318,8 @@ declare type BroadcastedEventServerMsg = {
|
|
|
118
318
|
* payload includes the entire Storage document.
|
|
119
319
|
*/
|
|
120
320
|
declare type InitialDocumentStateServerMsg = {
|
|
121
|
-
|
|
122
|
-
|
|
321
|
+
type: ServerMsgCode.INITIAL_STORAGE_STATE;
|
|
322
|
+
items: IdTuple<SerializedCrdt>[];
|
|
123
323
|
};
|
|
124
324
|
/**
|
|
125
325
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
@@ -129,162 +329,74 @@ declare type InitialDocumentStateServerMsg = {
|
|
|
129
329
|
* mutations to make to the initially loaded document).
|
|
130
330
|
*/
|
|
131
331
|
declare type UpdateStorageServerMsg = {
|
|
132
|
-
|
|
133
|
-
|
|
332
|
+
type: ServerMsgCode.UPDATE_STORAGE;
|
|
333
|
+
ops: Op[];
|
|
134
334
|
};
|
|
335
|
+
|
|
135
336
|
/**
|
|
136
|
-
*
|
|
337
|
+
* Helper function that can be used to implement exhaustive switch statements
|
|
338
|
+
* with TypeScript. Example usage:
|
|
339
|
+
*
|
|
340
|
+
* type Fruit = "🍎" | "🍌";
|
|
341
|
+
*
|
|
342
|
+
* switch (fruit) {
|
|
343
|
+
* case "🍎":
|
|
344
|
+
* case "🍌":
|
|
345
|
+
* return doSomething();
|
|
346
|
+
*
|
|
347
|
+
* default:
|
|
348
|
+
* return assertNever(fruit, "Unknown fruit");
|
|
349
|
+
* }
|
|
350
|
+
*
|
|
351
|
+
* If now the Fruit union is extended (i.e. add "🍒"), TypeScript will catch
|
|
352
|
+
* this *statically*, rather than at runtime, and force you to handle the
|
|
353
|
+
* 🍒 case.
|
|
137
354
|
*/
|
|
138
|
-
declare
|
|
139
|
-
declare enum ClientMsgCode {
|
|
140
|
-
UPDATE_PRESENCE = 100,
|
|
141
|
-
BROADCAST_EVENT = 103,
|
|
142
|
-
FETCH_STORAGE = 200,
|
|
143
|
-
UPDATE_STORAGE = 201
|
|
144
|
-
}
|
|
145
|
-
declare type BroadcastEventClientMsg = {
|
|
146
|
-
type: ClientMsgCode.BROADCAST_EVENT;
|
|
147
|
-
event: Json;
|
|
148
|
-
};
|
|
149
|
-
declare type UpdatePresenceClientMsg<TPresence extends JsonObject> = {
|
|
150
|
-
type: ClientMsgCode.UPDATE_PRESENCE;
|
|
151
|
-
data: TPresence;
|
|
152
|
-
targetActor?: number;
|
|
153
|
-
};
|
|
154
|
-
declare type UpdateStorageClientMsg = {
|
|
155
|
-
type: ClientMsgCode.UPDATE_STORAGE;
|
|
156
|
-
ops: Op[];
|
|
157
|
-
};
|
|
158
|
-
declare type FetchStorageClientMsg = {
|
|
159
|
-
type: ClientMsgCode.FETCH_STORAGE;
|
|
160
|
-
};
|
|
161
|
-
declare enum CrdtType {
|
|
162
|
-
OBJECT = 0,
|
|
163
|
-
LIST = 1,
|
|
164
|
-
MAP = 2,
|
|
165
|
-
REGISTER = 3
|
|
166
|
-
}
|
|
167
|
-
declare type SerializedRootObject = {
|
|
168
|
-
type: CrdtType.OBJECT;
|
|
169
|
-
data: JsonObject;
|
|
170
|
-
parentId?: never;
|
|
171
|
-
parentKey?: never;
|
|
172
|
-
};
|
|
173
|
-
declare type SerializedObject = {
|
|
174
|
-
type: CrdtType.OBJECT;
|
|
175
|
-
parentId: string;
|
|
176
|
-
parentKey: string;
|
|
177
|
-
data: JsonObject;
|
|
178
|
-
};
|
|
179
|
-
declare type SerializedList = {
|
|
180
|
-
type: CrdtType.LIST;
|
|
181
|
-
parentId: string;
|
|
182
|
-
parentKey: string;
|
|
183
|
-
};
|
|
184
|
-
declare type SerializedMap = {
|
|
185
|
-
type: CrdtType.MAP;
|
|
186
|
-
parentId: string;
|
|
187
|
-
parentKey: string;
|
|
188
|
-
};
|
|
189
|
-
declare type SerializedRegister = {
|
|
190
|
-
type: CrdtType.REGISTER;
|
|
191
|
-
parentId: string;
|
|
192
|
-
parentKey: string;
|
|
193
|
-
data: Json;
|
|
194
|
-
};
|
|
195
|
-
declare type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
196
|
-
declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
|
|
197
|
-
declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
|
|
198
|
-
declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
|
|
199
|
-
declare enum OpCode {
|
|
200
|
-
INIT = 0,
|
|
201
|
-
SET_PARENT_KEY = 1,
|
|
202
|
-
CREATE_LIST = 2,
|
|
203
|
-
UPDATE_OBJECT = 3,
|
|
204
|
-
CREATE_OBJECT = 4,
|
|
205
|
-
DELETE_CRDT = 5,
|
|
206
|
-
DELETE_OBJECT_KEY = 6,
|
|
207
|
-
CREATE_MAP = 7,
|
|
208
|
-
CREATE_REGISTER = 8
|
|
209
|
-
}
|
|
355
|
+
declare function assertNever(_value: never, errmsg: string): never;
|
|
210
356
|
/**
|
|
211
|
-
*
|
|
212
|
-
* only
|
|
357
|
+
* Asserts that a given value is non-nullable. This is similar to TypeScript's
|
|
358
|
+
* `!` operator, but will throw an error at runtime (dev-mode only) indicating
|
|
359
|
+
* an incorrect assumption.
|
|
360
|
+
*
|
|
361
|
+
* Instead of:
|
|
362
|
+
*
|
|
363
|
+
* foo!.bar
|
|
364
|
+
*
|
|
365
|
+
* Use:
|
|
366
|
+
*
|
|
367
|
+
* nn(foo).bar
|
|
368
|
+
*
|
|
213
369
|
*/
|
|
214
|
-
declare
|
|
215
|
-
|
|
216
|
-
declare
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
parentKey: string;
|
|
230
|
-
data: JsonObject;
|
|
231
|
-
};
|
|
232
|
-
declare type CreateRootObjectOp = Resolve<Omit<CreateObjectOp, "parentId" | "parentKey"> & {
|
|
233
|
-
parentId?: never;
|
|
234
|
-
parentKey?: never;
|
|
235
|
-
}>;
|
|
236
|
-
declare type CreateListOp = {
|
|
237
|
-
opId?: string;
|
|
238
|
-
id: string;
|
|
239
|
-
intent?: "set";
|
|
240
|
-
type: OpCode.CREATE_LIST;
|
|
241
|
-
parentId: string;
|
|
242
|
-
parentKey: string;
|
|
243
|
-
};
|
|
244
|
-
declare type CreateMapOp = {
|
|
245
|
-
opId?: string;
|
|
246
|
-
id: string;
|
|
247
|
-
intent?: "set";
|
|
248
|
-
type: OpCode.CREATE_MAP;
|
|
249
|
-
parentId: string;
|
|
250
|
-
parentKey: string;
|
|
251
|
-
};
|
|
252
|
-
declare type CreateRegisterOp = {
|
|
253
|
-
opId?: string;
|
|
254
|
-
id: string;
|
|
255
|
-
intent?: "set";
|
|
256
|
-
type: OpCode.CREATE_REGISTER;
|
|
257
|
-
parentId: string;
|
|
258
|
-
parentKey: string;
|
|
259
|
-
data: Json;
|
|
260
|
-
};
|
|
261
|
-
declare type DeleteCrdtOp = {
|
|
262
|
-
opId?: string;
|
|
263
|
-
id: string;
|
|
264
|
-
type: OpCode.DELETE_CRDT;
|
|
265
|
-
};
|
|
266
|
-
declare type SetParentKeyOp = {
|
|
267
|
-
opId?: string;
|
|
268
|
-
id: string;
|
|
269
|
-
type: OpCode.SET_PARENT_KEY;
|
|
270
|
-
parentKey: string;
|
|
370
|
+
declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
|
|
371
|
+
|
|
372
|
+
declare const SCOPES: readonly [
|
|
373
|
+
"websocket:presence",
|
|
374
|
+
"websocket:storage",
|
|
375
|
+
"room:read",
|
|
376
|
+
"room:write",
|
|
377
|
+
"rooms:read",
|
|
378
|
+
"rooms:write"
|
|
379
|
+
];
|
|
380
|
+
declare type Scope = typeof SCOPES[number];
|
|
381
|
+
declare type AppOnlyAuthToken = {
|
|
382
|
+
appId: string;
|
|
383
|
+
roomId?: never;
|
|
384
|
+
scopes: string[];
|
|
271
385
|
};
|
|
272
|
-
declare type
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
386
|
+
declare type RoomAuthToken = {
|
|
387
|
+
appId: string;
|
|
388
|
+
roomId: string;
|
|
389
|
+
scopes: string[];
|
|
390
|
+
actor: number;
|
|
391
|
+
maxConnectionsPerRoom?: number;
|
|
392
|
+
id?: string;
|
|
393
|
+
info?: Json;
|
|
277
394
|
};
|
|
278
|
-
declare
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
|
|
284
|
-
MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
|
|
285
|
-
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
|
|
286
|
-
CLOSE_WITHOUT_RETRY = 4999
|
|
287
|
-
}
|
|
395
|
+
declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
|
|
396
|
+
declare function isScope(value: unknown): value is Scope;
|
|
397
|
+
declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
|
|
398
|
+
declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
|
|
399
|
+
declare function isAuthToken(data: JsonObject): data is AuthToken;
|
|
288
400
|
|
|
289
401
|
/**
|
|
290
402
|
* Tools to help with the controlled deprecation of public APIs.
|
|
@@ -301,7 +413,11 @@ declare function deprecate(message: string, key?: string): void;
|
|
|
301
413
|
* console if the first argument is truthy. Only in dev mode, and
|
|
302
414
|
* only once per message/key. In production, this is a no-op.
|
|
303
415
|
*/
|
|
304
|
-
declare function deprecateIf(
|
|
416
|
+
declare function deprecateIf(
|
|
417
|
+
condition: unknown,
|
|
418
|
+
message: string,
|
|
419
|
+
key?: string
|
|
420
|
+
): void;
|
|
305
421
|
/**
|
|
306
422
|
* Throws a deprecation error in the dev console.
|
|
307
423
|
*
|
|
@@ -317,61 +433,23 @@ declare function throwUsageError(message: string): void;
|
|
|
317
433
|
*/
|
|
318
434
|
declare function errorIf(condition: unknown, message: string): void;
|
|
319
435
|
|
|
320
|
-
declare
|
|
321
|
-
declare
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
scopes: string[];
|
|
331
|
-
actor: number;
|
|
332
|
-
maxConnections: number;
|
|
333
|
-
maxConnectionsPerRoom?: number;
|
|
334
|
-
id?: string;
|
|
335
|
-
info?: Json;
|
|
336
|
-
};
|
|
337
|
-
declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
|
|
338
|
-
interface JwtMetadata extends JsonObject {
|
|
339
|
-
iat: number;
|
|
340
|
-
exp: number;
|
|
341
|
-
}
|
|
342
|
-
declare function isScope(value: unknown): value is Scope;
|
|
343
|
-
declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
|
|
344
|
-
declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
|
|
345
|
-
declare function isAuthToken(data: JsonObject): data is AuthToken;
|
|
346
|
-
declare function parseAuthToken(token: string): AuthToken & JwtMetadata;
|
|
347
|
-
|
|
348
|
-
declare function lsonToJson(value: Lson | AbstractCrdt): Json;
|
|
349
|
-
declare function patchLiveObjectKey<O extends LsonObject>(liveObject: LiveObject<O>, key: keyof O, prev: unknown, next: unknown): void;
|
|
350
|
-
declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
|
|
436
|
+
declare function lsonToJson(value: Lson): Json;
|
|
437
|
+
declare function patchLiveObjectKey<
|
|
438
|
+
O extends LsonObject,
|
|
439
|
+
K extends keyof O,
|
|
440
|
+
V extends Lson
|
|
441
|
+
>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void;
|
|
442
|
+
declare function patchImmutableObject<S extends JsonObject>(
|
|
443
|
+
state: S,
|
|
444
|
+
updates: StorageUpdate[]
|
|
445
|
+
): S;
|
|
351
446
|
|
|
352
447
|
declare function makePosition(before?: string, after?: string): string;
|
|
353
448
|
declare function comparePosition(posA: string, posB: string): number;
|
|
354
449
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
*
|
|
359
|
-
* type Fruit = "🍎" | "🍌";
|
|
360
|
-
*
|
|
361
|
-
* switch (fruit) {
|
|
362
|
-
* case "🍎":
|
|
363
|
-
* case "🍌":
|
|
364
|
-
* return doSomething();
|
|
365
|
-
*
|
|
366
|
-
* default:
|
|
367
|
-
* return assertNever(fruit, "Unknown fruit");
|
|
368
|
-
* }
|
|
369
|
-
*
|
|
370
|
-
* If now the Fruit union is extended (i.e. add "🍒"), TypeScript will catch
|
|
371
|
-
* this *statically*, rather than at runtime, and force you to handle the
|
|
372
|
-
* 🍒 case.
|
|
373
|
-
*/
|
|
374
|
-
declare function assertNever(_value: never, errmsg: string): never;
|
|
450
|
+
declare function isPlainObject(blob: unknown): blob is {
|
|
451
|
+
[key: string]: unknown;
|
|
452
|
+
};
|
|
375
453
|
/**
|
|
376
454
|
* Alternative to JSON.parse() that will not throw in production. If the passed
|
|
377
455
|
* string cannot be parsed, this will return `undefined`.
|
|
@@ -382,4 +460,68 @@ declare function tryParseJson(rawMessage: string): Json | undefined;
|
|
|
382
460
|
*/
|
|
383
461
|
declare function b64decode(b64value: string): string;
|
|
384
462
|
|
|
385
|
-
export {
|
|
463
|
+
export {
|
|
464
|
+
AppOnlyAuthToken,
|
|
465
|
+
AuthToken,
|
|
466
|
+
BroadcastEventClientMsg,
|
|
467
|
+
BroadcastedEventServerMsg,
|
|
468
|
+
ClientMsg,
|
|
469
|
+
ClientMsgCode,
|
|
470
|
+
CrdtType,
|
|
471
|
+
CreateChildOp,
|
|
472
|
+
CreateListOp,
|
|
473
|
+
CreateMapOp,
|
|
474
|
+
CreateObjectOp,
|
|
475
|
+
CreateOp,
|
|
476
|
+
CreateRegisterOp,
|
|
477
|
+
CreateRootObjectOp,
|
|
478
|
+
DeleteCrdtOp,
|
|
479
|
+
DeleteObjectKeyOp,
|
|
480
|
+
FetchStorageClientMsg,
|
|
481
|
+
IdTuple,
|
|
482
|
+
InitialDocumentStateServerMsg,
|
|
483
|
+
NodeMap,
|
|
484
|
+
Op,
|
|
485
|
+
OpCode,
|
|
486
|
+
ParentToChildNodeMap,
|
|
487
|
+
RoomAuthToken,
|
|
488
|
+
RoomStateServerMsg,
|
|
489
|
+
Scope,
|
|
490
|
+
SerializedChild,
|
|
491
|
+
SerializedCrdt,
|
|
492
|
+
SerializedList,
|
|
493
|
+
SerializedMap,
|
|
494
|
+
SerializedObject,
|
|
495
|
+
SerializedRegister,
|
|
496
|
+
SerializedRootObject,
|
|
497
|
+
ServerMsg,
|
|
498
|
+
ServerMsgCode,
|
|
499
|
+
SetParentKeyOp,
|
|
500
|
+
UpdateObjectOp,
|
|
501
|
+
UpdatePresenceClientMsg,
|
|
502
|
+
UpdatePresenceServerMsg,
|
|
503
|
+
UpdateStorageClientMsg,
|
|
504
|
+
UpdateStorageServerMsg,
|
|
505
|
+
UserJoinServerMsg,
|
|
506
|
+
UserLeftServerMsg,
|
|
507
|
+
assertNever,
|
|
508
|
+
b64decode,
|
|
509
|
+
comparePosition,
|
|
510
|
+
deprecate,
|
|
511
|
+
deprecateIf,
|
|
512
|
+
errorIf,
|
|
513
|
+
isAppOnlyAuthToken,
|
|
514
|
+
isAuthToken,
|
|
515
|
+
isChildCrdt,
|
|
516
|
+
isPlainObject,
|
|
517
|
+
isRoomAuthToken,
|
|
518
|
+
isRootCrdt,
|
|
519
|
+
isScope,
|
|
520
|
+
lsonToJson,
|
|
521
|
+
makePosition,
|
|
522
|
+
nn,
|
|
523
|
+
patchImmutableObject,
|
|
524
|
+
patchLiveObjectKey,
|
|
525
|
+
throwUsageError,
|
|
526
|
+
tryParseJson,
|
|
527
|
+
};
|