@liveblocks/core 0.18.5 β 0.19.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/dist/index.d.ts +682 -676
- package/dist/index.js +881 -877
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,58 +1,228 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* type Fruit = "π" | "π";
|
|
6
|
-
*
|
|
7
|
-
* switch (fruit) {
|
|
8
|
-
* case "π":
|
|
9
|
-
* case "π":
|
|
10
|
-
* return doSomething();
|
|
2
|
+
* Represents an indefinitely deep arbitrary JSON data structure. There are
|
|
3
|
+
* four types that make up the Json family:
|
|
11
4
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
5
|
+
* - Json any legal JSON value
|
|
6
|
+
* - JsonScalar any legal JSON leaf value (no lists or objects)
|
|
7
|
+
* - JsonArray a JSON value whose outer type is an array
|
|
8
|
+
* - JsonObject a JSON value whose outer type is an object
|
|
15
9
|
*
|
|
16
|
-
* If now the Fruit union is extended (i.e. add "π"), TypeScript will catch
|
|
17
|
-
* this *statically*, rather than at runtime, and force you to handle the
|
|
18
|
-
* π case.
|
|
19
10
|
*/
|
|
20
|
-
declare
|
|
11
|
+
declare type Json = JsonScalar | JsonArray | JsonObject;
|
|
12
|
+
declare type JsonScalar = string | number | boolean | null;
|
|
13
|
+
declare type JsonArray = Json[];
|
|
14
|
+
declare type JsonObject = {
|
|
15
|
+
[key: string]: Json | undefined;
|
|
16
|
+
};
|
|
17
|
+
declare function isJsonScalar(data: Json): data is JsonScalar;
|
|
18
|
+
declare function isJsonArray(data: Json): data is JsonArray;
|
|
19
|
+
declare function isJsonObject(data: Json): data is JsonObject;
|
|
20
|
+
|
|
21
|
+
declare type AppOnlyAuthToken = {
|
|
22
|
+
appId: string;
|
|
23
|
+
roomId?: never;
|
|
24
|
+
scopes: string[];
|
|
25
|
+
};
|
|
26
|
+
declare type RoomAuthToken = {
|
|
27
|
+
appId: string;
|
|
28
|
+
roomId: string;
|
|
29
|
+
scopes: string[];
|
|
30
|
+
actor: number;
|
|
31
|
+
maxConnectionsPerRoom?: number;
|
|
32
|
+
id?: string;
|
|
33
|
+
info?: Json;
|
|
34
|
+
};
|
|
35
|
+
declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
|
|
36
|
+
declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
|
|
37
|
+
declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
|
|
38
|
+
declare function isAuthToken(data: JsonObject): data is AuthToken;
|
|
39
|
+
|
|
40
|
+
declare enum OpCode {
|
|
41
|
+
INIT = 0,
|
|
42
|
+
SET_PARENT_KEY = 1,
|
|
43
|
+
CREATE_LIST = 2,
|
|
44
|
+
UPDATE_OBJECT = 3,
|
|
45
|
+
CREATE_OBJECT = 4,
|
|
46
|
+
DELETE_CRDT = 5,
|
|
47
|
+
DELETE_OBJECT_KEY = 6,
|
|
48
|
+
CREATE_MAP = 7,
|
|
49
|
+
CREATE_REGISTER = 8
|
|
50
|
+
}
|
|
21
51
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* an incorrect assumption.
|
|
25
|
-
*
|
|
26
|
-
* Instead of:
|
|
27
|
-
*
|
|
28
|
-
* foo!.bar
|
|
29
|
-
*
|
|
30
|
-
* Use:
|
|
31
|
-
*
|
|
32
|
-
* nn(foo).bar
|
|
33
|
-
*
|
|
52
|
+
* These operations are the payload for {@link UpdateStorageServerMsg} messages
|
|
53
|
+
* only.
|
|
34
54
|
*/
|
|
35
|
-
declare
|
|
55
|
+
declare type Op = CreateOp | UpdateObjectOp | DeleteCrdtOp | SetParentKeyOp | DeleteObjectKeyOp;
|
|
56
|
+
declare type CreateOp = CreateRootObjectOp | CreateChildOp;
|
|
57
|
+
declare type CreateChildOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp;
|
|
58
|
+
declare type UpdateObjectOp = {
|
|
59
|
+
opId?: string;
|
|
60
|
+
id: string;
|
|
61
|
+
type: OpCode.UPDATE_OBJECT;
|
|
62
|
+
data: Partial<JsonObject>;
|
|
63
|
+
};
|
|
64
|
+
declare type CreateObjectOp = {
|
|
65
|
+
opId?: string;
|
|
66
|
+
id: string;
|
|
67
|
+
intent?: "set";
|
|
68
|
+
deletedId?: string;
|
|
69
|
+
type: OpCode.CREATE_OBJECT;
|
|
70
|
+
parentId: string;
|
|
71
|
+
parentKey: string;
|
|
72
|
+
data: JsonObject;
|
|
73
|
+
};
|
|
74
|
+
declare type CreateRootObjectOp = {
|
|
75
|
+
opId?: string;
|
|
76
|
+
id: string;
|
|
77
|
+
type: OpCode.CREATE_OBJECT;
|
|
78
|
+
data: JsonObject;
|
|
79
|
+
parentId?: never;
|
|
80
|
+
parentKey?: never;
|
|
81
|
+
};
|
|
82
|
+
declare type CreateListOp = {
|
|
83
|
+
opId?: string;
|
|
84
|
+
id: string;
|
|
85
|
+
intent?: "set";
|
|
86
|
+
deletedId?: string;
|
|
87
|
+
type: OpCode.CREATE_LIST;
|
|
88
|
+
parentId: string;
|
|
89
|
+
parentKey: string;
|
|
90
|
+
};
|
|
91
|
+
declare type CreateMapOp = {
|
|
92
|
+
opId?: string;
|
|
93
|
+
id: string;
|
|
94
|
+
intent?: "set";
|
|
95
|
+
deletedId?: string;
|
|
96
|
+
type: OpCode.CREATE_MAP;
|
|
97
|
+
parentId: string;
|
|
98
|
+
parentKey: string;
|
|
99
|
+
};
|
|
100
|
+
declare type CreateRegisterOp = {
|
|
101
|
+
opId?: string;
|
|
102
|
+
id: string;
|
|
103
|
+
intent?: "set";
|
|
104
|
+
deletedId?: string;
|
|
105
|
+
type: OpCode.CREATE_REGISTER;
|
|
106
|
+
parentId: string;
|
|
107
|
+
parentKey: string;
|
|
108
|
+
data: Json;
|
|
109
|
+
};
|
|
110
|
+
declare type DeleteCrdtOp = {
|
|
111
|
+
opId?: string;
|
|
112
|
+
id: string;
|
|
113
|
+
type: OpCode.DELETE_CRDT;
|
|
114
|
+
};
|
|
115
|
+
declare type SetParentKeyOp = {
|
|
116
|
+
opId?: string;
|
|
117
|
+
id: string;
|
|
118
|
+
type: OpCode.SET_PARENT_KEY;
|
|
119
|
+
parentKey: string;
|
|
120
|
+
};
|
|
121
|
+
declare type DeleteObjectKeyOp = {
|
|
122
|
+
opId?: string;
|
|
123
|
+
id: string;
|
|
124
|
+
type: OpCode.DELETE_OBJECT_KEY;
|
|
125
|
+
key: string;
|
|
126
|
+
};
|
|
36
127
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Represents an indefinitely deep arbitrary immutable data
|
|
130
|
+
* structure, as returned by the .toImmutable().
|
|
131
|
+
*/
|
|
132
|
+
declare type Immutable = Scalar | ImmutableList | ImmutableObject | ImmutableMap;
|
|
133
|
+
declare type Scalar = string | number | boolean | null;
|
|
134
|
+
declare type ImmutableList = readonly Immutable[];
|
|
135
|
+
declare type ImmutableObject = {
|
|
136
|
+
readonly [key: string]: Immutable | undefined;
|
|
42
137
|
};
|
|
138
|
+
declare type ImmutableMap = ReadonlyMap<string, Immutable>;
|
|
43
139
|
|
|
44
|
-
declare type
|
|
140
|
+
declare type UpdateDelta = {
|
|
141
|
+
type: "update";
|
|
142
|
+
} | {
|
|
143
|
+
type: "delete";
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
declare type LiveObjectUpdateDelta<O extends {
|
|
147
|
+
[key: string]: unknown;
|
|
148
|
+
}> = {
|
|
149
|
+
[K in keyof O]?: UpdateDelta | undefined;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* A LiveObject notification that is sent in-client to any subscribers whenever
|
|
153
|
+
* one or more of the entries inside the LiveObject instance have changed.
|
|
154
|
+
*/
|
|
155
|
+
declare type LiveObjectUpdates<TData extends LsonObject> = {
|
|
156
|
+
type: "LiveObject";
|
|
157
|
+
node: LiveObject<TData>;
|
|
158
|
+
updates: LiveObjectUpdateDelta<TData>;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
|
|
162
|
+
* Keys should be a string, and values should be serializable to JSON.
|
|
163
|
+
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
|
|
164
|
+
*/
|
|
165
|
+
declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
|
|
166
|
+
constructor(obj?: O);
|
|
45
167
|
/**
|
|
46
|
-
*
|
|
168
|
+
* Transform the LiveObject into a javascript object
|
|
47
169
|
*/
|
|
48
|
-
|
|
170
|
+
toObject(): O;
|
|
49
171
|
/**
|
|
50
|
-
*
|
|
172
|
+
* Adds or updates a property with a specified key and a value.
|
|
173
|
+
* @param key The key of the property to add
|
|
174
|
+
* @param value The value of the property to add
|
|
51
175
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
176
|
+
set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
|
|
177
|
+
/**
|
|
178
|
+
* Returns a specified property from the LiveObject.
|
|
179
|
+
* @param key The key of the property to get
|
|
180
|
+
*/
|
|
181
|
+
get<TKey extends keyof O>(key: TKey): O[TKey];
|
|
182
|
+
/**
|
|
183
|
+
* Deletes a key from the LiveObject
|
|
184
|
+
* @param key The key of the property to delete
|
|
185
|
+
*/
|
|
186
|
+
delete(key: keyof O): void;
|
|
187
|
+
/**
|
|
188
|
+
* Adds or updates multiple properties at once with an object.
|
|
189
|
+
* @param patch The object used to overrides properties
|
|
190
|
+
*/
|
|
191
|
+
update(patch: Partial<O>): void;
|
|
192
|
+
toImmutable(): ToImmutable<O>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Helper type to convert any valid Lson type to the equivalent Json type.
|
|
197
|
+
*
|
|
198
|
+
* Examples:
|
|
199
|
+
*
|
|
200
|
+
* ToImmutable<42> // 42
|
|
201
|
+
* ToImmutable<'hi'> // 'hi'
|
|
202
|
+
* ToImmutable<number> // number
|
|
203
|
+
* ToImmutable<string> // string
|
|
204
|
+
* ToImmutable<string | LiveList<number>> // string | readonly number[]
|
|
205
|
+
* ToImmutable<LiveMap<string, LiveList<number>>>
|
|
206
|
+
* // ReadonlyMap<string, readonly number[]>
|
|
207
|
+
* ToImmutable<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
|
|
208
|
+
* // { readonly a: null, readonly b: readonly string[], readonly c?: number }
|
|
209
|
+
*
|
|
210
|
+
*/
|
|
211
|
+
declare type ToImmutable<L extends Lson | LsonObject> = L extends LiveList<infer I> ? readonly ToImmutable<I>[] : L extends LiveObject<infer O> ? ToImmutable<O> : L extends LiveMap<infer K, infer V> ? ReadonlyMap<K, ToImmutable<V>> : L extends LsonObject ? {
|
|
212
|
+
readonly [K in keyof L]: ToImmutable<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
|
|
213
|
+
} : L extends Json ? L : never;
|
|
55
214
|
|
|
215
|
+
/**
|
|
216
|
+
* A LiveMap notification that is sent in-client to any subscribers whenever
|
|
217
|
+
* one or more of the values inside the LiveMap instance have changed.
|
|
218
|
+
*/
|
|
219
|
+
declare type LiveMapUpdates<TKey extends string, TValue extends Lson> = {
|
|
220
|
+
type: "LiveMap";
|
|
221
|
+
node: LiveMap<TKey, TValue>;
|
|
222
|
+
updates: {
|
|
223
|
+
[key: string]: UpdateDelta;
|
|
224
|
+
};
|
|
225
|
+
};
|
|
56
226
|
/**
|
|
57
227
|
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
|
|
58
228
|
* Keys should be a string, and values should be serializable to JSON.
|
|
@@ -111,141 +281,13 @@ declare class LiveMap<TKey extends string, TValue extends Lson> extends Abstract
|
|
|
111
281
|
toImmutable(): ReadonlyMap<TKey, ToImmutable<TValue>>;
|
|
112
282
|
}
|
|
113
283
|
|
|
284
|
+
declare type StorageCallback = (updates: StorageUpdate[]) => void;
|
|
114
285
|
/**
|
|
115
|
-
* The
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*/
|
|
119
|
-
declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
|
|
120
|
-
constructor(obj?: O);
|
|
121
|
-
/**
|
|
122
|
-
* Transform the LiveObject into a javascript object
|
|
123
|
-
*/
|
|
124
|
-
toObject(): O;
|
|
125
|
-
/**
|
|
126
|
-
* Adds or updates a property with a specified key and a value.
|
|
127
|
-
* @param key The key of the property to add
|
|
128
|
-
* @param value The value of the property to add
|
|
129
|
-
*/
|
|
130
|
-
set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
|
|
131
|
-
/**
|
|
132
|
-
* Returns a specified property from the LiveObject.
|
|
133
|
-
* @param key The key of the property to get
|
|
134
|
-
*/
|
|
135
|
-
get<TKey extends keyof O>(key: TKey): O[TKey];
|
|
136
|
-
/**
|
|
137
|
-
* Deletes a key from the LiveObject
|
|
138
|
-
* @param key The key of the property to delete
|
|
139
|
-
*/
|
|
140
|
-
delete(key: keyof O): void;
|
|
141
|
-
/**
|
|
142
|
-
* Adds or updates multiple properties at once with an object.
|
|
143
|
-
* @param patch The object used to overrides properties
|
|
144
|
-
*/
|
|
145
|
-
update(patch: Partial<O>): void;
|
|
146
|
-
toImmutable(): ToImmutable<O>;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Represents an indefinitely deep arbitrary JSON data structure. There are
|
|
151
|
-
* four types that make up the Json family:
|
|
152
|
-
*
|
|
153
|
-
* - Json any legal JSON value
|
|
154
|
-
* - JsonScalar any legal JSON leaf value (no lists or objects)
|
|
155
|
-
* - JsonArray a JSON value whose outer type is an array
|
|
156
|
-
* - JsonObject a JSON value whose outer type is an object
|
|
157
|
-
*
|
|
158
|
-
*/
|
|
159
|
-
declare type Json = JsonScalar | JsonArray | JsonObject;
|
|
160
|
-
declare type JsonScalar = string | number | boolean | null;
|
|
161
|
-
declare type JsonArray = Json[];
|
|
162
|
-
declare type JsonObject = {
|
|
163
|
-
[key: string]: Json | undefined;
|
|
164
|
-
};
|
|
165
|
-
declare function isJsonScalar(data: Json): data is JsonScalar;
|
|
166
|
-
declare function isJsonArray(data: Json): data is JsonArray;
|
|
167
|
-
declare function isJsonObject(data: Json): data is JsonObject;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* INTERNAL
|
|
171
|
-
*/
|
|
172
|
-
declare class LiveRegister<TValue extends Json> extends AbstractCrdt {
|
|
173
|
-
constructor(data: TValue);
|
|
174
|
-
get data(): TValue;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
declare type LiveStructure = LiveObject<LsonObject> | LiveList<Lson> | LiveMap<string, Lson>;
|
|
178
|
-
/**
|
|
179
|
-
* Think of Lson as a sibling of the Json data tree, except that the nested
|
|
180
|
-
* data structure can contain a mix of Json values and LiveStructure instances.
|
|
181
|
-
*/
|
|
182
|
-
declare type Lson = Json | LiveStructure;
|
|
183
|
-
/**
|
|
184
|
-
* LiveNode is the internal tree for managing Live data structures. The key
|
|
185
|
-
* difference with Lson is that all the Json values get represented in
|
|
186
|
-
* a LiveRegister node.
|
|
187
|
-
*/
|
|
188
|
-
declare type LiveNode = LiveStructure | LiveRegister<Json>;
|
|
189
|
-
/**
|
|
190
|
-
* A mapping of keys to Lson values. A Lson value is any valid JSON
|
|
191
|
-
* value or a Live storage data structure (LiveMap, LiveList, etc.)
|
|
192
|
-
*/
|
|
193
|
-
declare type LsonObject = {
|
|
194
|
-
[key: string]: Lson | undefined;
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Helper type to convert any valid Lson type to the equivalent Json type.
|
|
198
|
-
*
|
|
199
|
-
* Examples:
|
|
200
|
-
*
|
|
201
|
-
* ToJson<42> // 42
|
|
202
|
-
* ToJson<'hi'> // 'hi'
|
|
203
|
-
* ToJson<number> // number
|
|
204
|
-
* ToJson<string> // string
|
|
205
|
-
* ToJson<string | LiveList<number>> // string | number[]
|
|
206
|
-
* ToJson<LiveMap<string, LiveList<number>>>
|
|
207
|
-
* // { [key: string]: number[] }
|
|
208
|
-
* ToJson<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
|
|
209
|
-
* // { a: null, b: string[], c?: number }
|
|
210
|
-
*
|
|
211
|
-
*/
|
|
212
|
-
declare type ToJson<T extends Lson | LsonObject> = T extends Json ? T : T extends LsonObject ? {
|
|
213
|
-
[K in keyof T]: ToJson<Exclude<T[K], undefined>> | (undefined extends T[K] ? undefined : never);
|
|
214
|
-
} : T extends LiveList<infer I> ? ToJson<I>[] : T extends LiveObject<infer O> ? ToJson<O> : T extends LiveMap<infer KS, infer V> ? {
|
|
215
|
-
[K in KS]: ToJson<V>;
|
|
216
|
-
} : never;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Represents an indefinitely deep arbitrary immutable data
|
|
220
|
-
* structure, as returned by the .toImmutable().
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
declare type Immutable = Scalar | ImmutableList | ImmutableObject | ImmutableMap;
|
|
224
|
-
declare type Scalar = string | number | boolean | null;
|
|
225
|
-
declare type ImmutableList = readonly Immutable[];
|
|
226
|
-
declare type ImmutableObject = {
|
|
227
|
-
readonly [key: string]: Immutable | undefined;
|
|
228
|
-
};
|
|
229
|
-
declare type ImmutableMap = ReadonlyMap<string, Immutable>;
|
|
230
|
-
/**
|
|
231
|
-
* Helper type to convert any valid Lson type to the equivalent Json type.
|
|
232
|
-
*
|
|
233
|
-
* Examples:
|
|
234
|
-
*
|
|
235
|
-
* ToImmutable<42> // 42
|
|
236
|
-
* ToImmutable<'hi'> // 'hi'
|
|
237
|
-
* ToImmutable<number> // number
|
|
238
|
-
* ToImmutable<string> // string
|
|
239
|
-
* ToImmutable<string | LiveList<number>> // string | readonly number[]
|
|
240
|
-
* ToImmutable<LiveMap<string, LiveList<number>>>
|
|
241
|
-
* // { readonly [key: string]: readonly number[] }
|
|
242
|
-
* ToImmutable<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
|
|
243
|
-
* // { readonly a: null, readonly b: readonly string[], readonly c?: number }
|
|
244
|
-
*
|
|
286
|
+
* The payload of notifications sent (in-client) when LiveStructures change.
|
|
287
|
+
* Messages of this kind are not originating from the network, but are 100%
|
|
288
|
+
* in-client.
|
|
245
289
|
*/
|
|
246
|
-
declare type
|
|
247
|
-
readonly [K in keyof L]: ToImmutable<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
|
|
248
|
-
} : L extends Json ? L : never;
|
|
290
|
+
declare type StorageUpdate = LiveMapUpdates<string, Lson> | LiveObjectUpdates<LsonObject> | LiveListUpdates<Lson>;
|
|
249
291
|
|
|
250
292
|
declare abstract class AbstractCrdt {
|
|
251
293
|
get roomId(): string | null;
|
|
@@ -255,6 +297,32 @@ declare abstract class AbstractCrdt {
|
|
|
255
297
|
toImmutable(): Immutable;
|
|
256
298
|
}
|
|
257
299
|
|
|
300
|
+
declare type LiveListUpdateDelta = {
|
|
301
|
+
index: number;
|
|
302
|
+
item: Lson;
|
|
303
|
+
type: "insert";
|
|
304
|
+
} | {
|
|
305
|
+
index: number;
|
|
306
|
+
type: "delete";
|
|
307
|
+
} | {
|
|
308
|
+
index: number;
|
|
309
|
+
previousIndex: number;
|
|
310
|
+
item: Lson;
|
|
311
|
+
type: "move";
|
|
312
|
+
} | {
|
|
313
|
+
index: number;
|
|
314
|
+
item: Lson;
|
|
315
|
+
type: "set";
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* A LiveList notification that is sent in-client to any subscribers whenever
|
|
319
|
+
* one or more of the items inside the LiveList instance have changed.
|
|
320
|
+
*/
|
|
321
|
+
declare type LiveListUpdates<TItem extends Lson> = {
|
|
322
|
+
type: "LiveList";
|
|
323
|
+
node: LiveList<TItem>;
|
|
324
|
+
updates: LiveListUpdateDelta[];
|
|
325
|
+
};
|
|
258
326
|
/**
|
|
259
327
|
* The LiveList class represents an ordered collection of items that is synchronized across clients.
|
|
260
328
|
*/
|
|
@@ -357,6 +425,55 @@ declare class LiveList<TItem extends Lson> extends AbstractCrdt {
|
|
|
357
425
|
toImmutable(): readonly ToImmutable<TItem>[];
|
|
358
426
|
}
|
|
359
427
|
|
|
428
|
+
/**
|
|
429
|
+
* INTERNAL
|
|
430
|
+
*/
|
|
431
|
+
declare class LiveRegister<TValue extends Json> extends AbstractCrdt {
|
|
432
|
+
constructor(data: TValue);
|
|
433
|
+
get data(): TValue;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
declare type LiveStructure = LiveObject<LsonObject> | LiveList<Lson> | LiveMap<string, Lson>;
|
|
437
|
+
/**
|
|
438
|
+
* Think of Lson as a sibling of the Json data tree, except that the nested
|
|
439
|
+
* data structure can contain a mix of Json values and LiveStructure instances.
|
|
440
|
+
*/
|
|
441
|
+
declare type Lson = Json | LiveStructure;
|
|
442
|
+
/**
|
|
443
|
+
* LiveNode is the internal tree for managing Live data structures. The key
|
|
444
|
+
* difference with Lson is that all the Json values get represented in
|
|
445
|
+
* a LiveRegister node.
|
|
446
|
+
*/
|
|
447
|
+
declare type LiveNode = LiveStructure | LiveRegister<Json>;
|
|
448
|
+
/**
|
|
449
|
+
* A mapping of keys to Lson values. A Lson value is any valid JSON
|
|
450
|
+
* value or a Live storage data structure (LiveMap, LiveList, etc.)
|
|
451
|
+
*/
|
|
452
|
+
declare type LsonObject = {
|
|
453
|
+
[key: string]: Lson | undefined;
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Helper type to convert any valid Lson type to the equivalent Json type.
|
|
457
|
+
*
|
|
458
|
+
* Examples:
|
|
459
|
+
*
|
|
460
|
+
* ToJson<42> // 42
|
|
461
|
+
* ToJson<'hi'> // 'hi'
|
|
462
|
+
* ToJson<number> // number
|
|
463
|
+
* ToJson<string> // string
|
|
464
|
+
* ToJson<string | LiveList<number>> // string | number[]
|
|
465
|
+
* ToJson<LiveMap<string, LiveList<number>>>
|
|
466
|
+
* // { [key: string]: number[] }
|
|
467
|
+
* ToJson<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
|
|
468
|
+
* // { a: null, b: string[], c?: number }
|
|
469
|
+
*
|
|
470
|
+
*/
|
|
471
|
+
declare type ToJson<T extends Lson | LsonObject> = T extends Json ? T : T extends LsonObject ? {
|
|
472
|
+
[K in keyof T]: ToJson<Exclude<T[K], undefined>> | (undefined extends T[K] ? undefined : never);
|
|
473
|
+
} : T extends LiveList<infer I> ? ToJson<I>[] : T extends LiveObject<infer O> ? ToJson<O> : T extends LiveMap<infer KS, infer V> ? {
|
|
474
|
+
[K in KS]: ToJson<V>;
|
|
475
|
+
} : never;
|
|
476
|
+
|
|
360
477
|
/**
|
|
361
478
|
* This type is used by clients to define the metadata for a user.
|
|
362
479
|
*/
|
|
@@ -372,92 +489,37 @@ declare type BaseUserMeta = {
|
|
|
372
489
|
info?: Json;
|
|
373
490
|
};
|
|
374
491
|
|
|
375
|
-
declare
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
DELETE_OBJECT_KEY = 6,
|
|
383
|
-
CREATE_MAP = 7,
|
|
384
|
-
CREATE_REGISTER = 8
|
|
385
|
-
}
|
|
492
|
+
declare type Callback<T> = (event: T) => void;
|
|
493
|
+
declare type UnsubscribeCallback = () => void;
|
|
494
|
+
declare type Observable<T> = {
|
|
495
|
+
subscribe(callback: Callback<T>): UnsubscribeCallback;
|
|
496
|
+
subscribeOnce(callback: Callback<T>): UnsubscribeCallback;
|
|
497
|
+
};
|
|
498
|
+
|
|
386
499
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
500
|
+
* This helper type is effectively a no-op, but will force TypeScript to
|
|
501
|
+
* "evaluate" any named helper types in its definition. This can sometimes make
|
|
502
|
+
* API signatures clearer in IDEs.
|
|
503
|
+
*
|
|
504
|
+
* For example, in:
|
|
505
|
+
*
|
|
506
|
+
* type Payload<T> = { data: T };
|
|
507
|
+
*
|
|
508
|
+
* let r1: Payload<string>;
|
|
509
|
+
* let r2: Resolve<Payload<string>>;
|
|
510
|
+
*
|
|
511
|
+
* The inferred type of `r1` is going to be `Payload<string>` which shows up in
|
|
512
|
+
* editor hints, and it may be unclear what's inside if you don't know the
|
|
513
|
+
* definition of `Payload`.
|
|
514
|
+
*
|
|
515
|
+
* The inferred type of `r2` is going to be `{ data: string }`, which may be
|
|
516
|
+
* more helpful.
|
|
517
|
+
*
|
|
518
|
+
* This trick comes from:
|
|
519
|
+
* https://effectivetypescript.com/2022/02/25/gentips-4-display/
|
|
389
520
|
*/
|
|
390
|
-
declare type
|
|
391
|
-
|
|
392
|
-
declare type CreateChildOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp;
|
|
393
|
-
declare type UpdateObjectOp = {
|
|
394
|
-
opId?: string;
|
|
395
|
-
id: string;
|
|
396
|
-
type: OpCode.UPDATE_OBJECT;
|
|
397
|
-
data: Partial<JsonObject>;
|
|
398
|
-
};
|
|
399
|
-
declare type CreateObjectOp = {
|
|
400
|
-
opId?: string;
|
|
401
|
-
id: string;
|
|
402
|
-
intent?: "set";
|
|
403
|
-
deletedId?: string;
|
|
404
|
-
type: OpCode.CREATE_OBJECT;
|
|
405
|
-
parentId: string;
|
|
406
|
-
parentKey: string;
|
|
407
|
-
data: JsonObject;
|
|
408
|
-
};
|
|
409
|
-
declare type CreateRootObjectOp = {
|
|
410
|
-
opId?: string;
|
|
411
|
-
id: string;
|
|
412
|
-
type: OpCode.CREATE_OBJECT;
|
|
413
|
-
data: JsonObject;
|
|
414
|
-
parentId?: never;
|
|
415
|
-
parentKey?: never;
|
|
416
|
-
};
|
|
417
|
-
declare type CreateListOp = {
|
|
418
|
-
opId?: string;
|
|
419
|
-
id: string;
|
|
420
|
-
intent?: "set";
|
|
421
|
-
deletedId?: string;
|
|
422
|
-
type: OpCode.CREATE_LIST;
|
|
423
|
-
parentId: string;
|
|
424
|
-
parentKey: string;
|
|
425
|
-
};
|
|
426
|
-
declare type CreateMapOp = {
|
|
427
|
-
opId?: string;
|
|
428
|
-
id: string;
|
|
429
|
-
intent?: "set";
|
|
430
|
-
deletedId?: string;
|
|
431
|
-
type: OpCode.CREATE_MAP;
|
|
432
|
-
parentId: string;
|
|
433
|
-
parentKey: string;
|
|
434
|
-
};
|
|
435
|
-
declare type CreateRegisterOp = {
|
|
436
|
-
opId?: string;
|
|
437
|
-
id: string;
|
|
438
|
-
intent?: "set";
|
|
439
|
-
deletedId?: string;
|
|
440
|
-
type: OpCode.CREATE_REGISTER;
|
|
441
|
-
parentId: string;
|
|
442
|
-
parentKey: string;
|
|
443
|
-
data: Json;
|
|
444
|
-
};
|
|
445
|
-
declare type DeleteCrdtOp = {
|
|
446
|
-
opId?: string;
|
|
447
|
-
id: string;
|
|
448
|
-
type: OpCode.DELETE_CRDT;
|
|
449
|
-
};
|
|
450
|
-
declare type SetParentKeyOp = {
|
|
451
|
-
opId?: string;
|
|
452
|
-
id: string;
|
|
453
|
-
type: OpCode.SET_PARENT_KEY;
|
|
454
|
-
parentKey: string;
|
|
455
|
-
};
|
|
456
|
-
declare type DeleteObjectKeyOp = {
|
|
457
|
-
opId?: string;
|
|
458
|
-
id: string;
|
|
459
|
-
type: OpCode.DELETE_OBJECT_KEY;
|
|
460
|
-
key: string;
|
|
521
|
+
declare type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
|
|
522
|
+
[K in keyof T]: T[K];
|
|
461
523
|
};
|
|
462
524
|
|
|
463
525
|
declare enum ClientMsgCode {
|
|
@@ -508,401 +570,67 @@ declare type FetchStorageClientMsg = {
|
|
|
508
570
|
type: ClientMsgCode.FETCH_STORAGE;
|
|
509
571
|
};
|
|
510
572
|
|
|
511
|
-
declare type
|
|
512
|
-
declare enum CrdtType {
|
|
513
|
-
OBJECT = 0,
|
|
514
|
-
LIST = 1,
|
|
515
|
-
MAP = 2,
|
|
516
|
-
REGISTER = 3
|
|
517
|
-
}
|
|
518
|
-
declare type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
519
|
-
declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
|
|
520
|
-
declare type SerializedRootObject = {
|
|
521
|
-
type: CrdtType.OBJECT;
|
|
522
|
-
data: JsonObject;
|
|
523
|
-
parentId?: never;
|
|
524
|
-
parentKey?: never;
|
|
525
|
-
};
|
|
526
|
-
declare type SerializedObject = {
|
|
527
|
-
type: CrdtType.OBJECT;
|
|
528
|
-
parentId: string;
|
|
529
|
-
parentKey: string;
|
|
530
|
-
data: JsonObject;
|
|
531
|
-
};
|
|
532
|
-
declare type SerializedList = {
|
|
533
|
-
type: CrdtType.LIST;
|
|
534
|
-
parentId: string;
|
|
535
|
-
parentKey: string;
|
|
536
|
-
};
|
|
537
|
-
declare type SerializedMap = {
|
|
538
|
-
type: CrdtType.MAP;
|
|
539
|
-
parentId: string;
|
|
540
|
-
parentKey: string;
|
|
541
|
-
};
|
|
542
|
-
declare type SerializedRegister = {
|
|
543
|
-
type: CrdtType.REGISTER;
|
|
544
|
-
parentId: string;
|
|
545
|
-
parentKey: string;
|
|
546
|
-
data: Json;
|
|
547
|
-
};
|
|
548
|
-
declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
|
|
549
|
-
declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Lookup table for nodes (= SerializedCrdt values) by their IDs.
|
|
553
|
-
*/
|
|
554
|
-
declare type NodeMap = Map<string, // Node ID
|
|
555
|
-
SerializedCrdt>;
|
|
556
|
-
/**
|
|
557
|
-
* Reverse lookup table for all child nodes (= list of SerializedCrdt values)
|
|
558
|
-
* by their parent node's IDs.
|
|
559
|
-
*/
|
|
560
|
-
declare type ParentToChildNodeMap = Map<string, // Parent's node ID
|
|
561
|
-
IdTuple<SerializedChild>[]>;
|
|
562
|
-
|
|
563
|
-
declare enum ServerMsgCode {
|
|
564
|
-
UPDATE_PRESENCE = 100,
|
|
565
|
-
USER_JOINED = 101,
|
|
566
|
-
USER_LEFT = 102,
|
|
567
|
-
BROADCASTED_EVENT = 103,
|
|
568
|
-
ROOM_STATE = 104,
|
|
569
|
-
INITIAL_STORAGE_STATE = 200,
|
|
570
|
-
UPDATE_STORAGE = 201
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* Messages that can be sent from the server to the client.
|
|
574
|
-
*/
|
|
575
|
-
declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg;
|
|
576
|
-
/**
|
|
577
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
578
|
-
* a User updated their presence. For example, when a user moves their cursor.
|
|
579
|
-
*
|
|
580
|
-
* In most cases, the data payload will only include the fields from the
|
|
581
|
-
* Presence that have been changed since the last announcement. However, after
|
|
582
|
-
* a new user joins a room, a "full presence" will be announced so the newly
|
|
583
|
-
* connected user will get each other's user full presence at least once. In
|
|
584
|
-
* those cases, the `targetActor` field indicates the newly connected client,
|
|
585
|
-
* so all other existing clients can ignore this broadcasted message.
|
|
586
|
-
*/
|
|
587
|
-
declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
|
|
588
|
-
type: ServerMsgCode.UPDATE_PRESENCE;
|
|
589
|
-
/**
|
|
590
|
-
* The User whose Presence has changed.
|
|
591
|
-
*/
|
|
592
|
-
actor: number;
|
|
593
|
-
/**
|
|
594
|
-
* When set, signifies that this is a Full Presenceβ’ update, not a patch.
|
|
595
|
-
*
|
|
596
|
-
* The numeric value itself no longer has specific meaning. Historically,
|
|
597
|
-
* this field was intended so that clients could ignore these broadcasted
|
|
598
|
-
* full presence messages, but it turned out that getting a full presence
|
|
599
|
-
* "keyframe" from time to time was useful.
|
|
600
|
-
*
|
|
601
|
-
* So nowadays, the presence (pun intended) of this `targetActor` field
|
|
602
|
-
* is a backward-compatible way of expressing that the `data` contains
|
|
603
|
-
* all presence fields, and isn't a partial "patch".
|
|
604
|
-
*/
|
|
605
|
-
targetActor: number;
|
|
606
|
-
/**
|
|
607
|
-
* The partial or full Presence of a User. If the `targetActor` field is set,
|
|
608
|
-
* this will be the full Presence, otherwise it only contain the fields that
|
|
609
|
-
* have changed since the last broadcast.
|
|
610
|
-
*/
|
|
611
|
-
data: TPresence;
|
|
612
|
-
} | {
|
|
613
|
-
type: ServerMsgCode.UPDATE_PRESENCE;
|
|
614
|
-
/**
|
|
615
|
-
* The User whose Presence has changed.
|
|
616
|
-
*/
|
|
617
|
-
actor: number;
|
|
573
|
+
declare type ReadonlyArrayWithLegacyMethods<T> = readonly T[] & {
|
|
618
574
|
/**
|
|
619
|
-
*
|
|
575
|
+
* @deprecated Prefer the normal .length property on arrays.
|
|
620
576
|
*/
|
|
621
|
-
|
|
577
|
+
readonly count: number;
|
|
622
578
|
/**
|
|
623
|
-
*
|
|
624
|
-
* fields that have changed since the last broadcast.
|
|
579
|
+
* @deprecated Calling .toArray() is no longer needed
|
|
625
580
|
*/
|
|
626
|
-
|
|
581
|
+
readonly toArray: () => readonly T[];
|
|
627
582
|
};
|
|
583
|
+
declare function asArrayWithLegacyMethods<T>(arr: readonly T[]): ReadonlyArrayWithLegacyMethods<T>;
|
|
584
|
+
|
|
628
585
|
/**
|
|
629
|
-
*
|
|
630
|
-
* a new User has joined the Room.
|
|
586
|
+
* Represents a user connected in a room. Treated as immutable.
|
|
631
587
|
*/
|
|
632
|
-
declare type
|
|
633
|
-
type: ServerMsgCode.USER_JOINED;
|
|
634
|
-
actor: number;
|
|
588
|
+
declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
635
589
|
/**
|
|
636
|
-
* The id of the
|
|
637
|
-
* Useful to get additional information about the connected user.
|
|
590
|
+
* The connection id of the user. It is unique and increment at every new connection.
|
|
638
591
|
*/
|
|
639
|
-
|
|
592
|
+
readonly connectionId: number;
|
|
640
593
|
/**
|
|
641
|
-
*
|
|
642
|
-
*
|
|
594
|
+
* The id of the user that has been set in the authentication endpoint.
|
|
595
|
+
* Useful to get additional information about the connected user.
|
|
643
596
|
*/
|
|
644
|
-
|
|
597
|
+
readonly id: TUserMeta["id"];
|
|
645
598
|
/**
|
|
646
|
-
*
|
|
599
|
+
* Additional user information that has been set in the authentication endpoint.
|
|
647
600
|
*/
|
|
648
|
-
|
|
649
|
-
};
|
|
650
|
-
/**
|
|
651
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
652
|
-
* a new User has left the Room.
|
|
653
|
-
*/
|
|
654
|
-
declare type UserLeftServerMsg = {
|
|
655
|
-
type: ServerMsgCode.USER_LEFT;
|
|
656
|
-
actor: number;
|
|
657
|
-
};
|
|
658
|
-
/**
|
|
659
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
660
|
-
* a User broadcasted an Event to everyone in the Room.
|
|
661
|
-
*/
|
|
662
|
-
declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
|
|
663
|
-
type: ServerMsgCode.BROADCASTED_EVENT;
|
|
601
|
+
readonly info: TUserMeta["info"];
|
|
664
602
|
/**
|
|
665
|
-
* The
|
|
603
|
+
* The user presence.
|
|
666
604
|
*/
|
|
667
|
-
|
|
605
|
+
readonly presence: TPresence;
|
|
668
606
|
/**
|
|
669
|
-
*
|
|
670
|
-
* will have to manually verify/decode this event.
|
|
607
|
+
* False if the user can modify the room storage, true otherwise.
|
|
671
608
|
*/
|
|
672
|
-
|
|
609
|
+
readonly isReadOnly: boolean;
|
|
673
610
|
};
|
|
611
|
+
|
|
674
612
|
/**
|
|
675
|
-
*
|
|
676
|
-
* joining the Room, to provide the initial state of the Room. The payload
|
|
677
|
-
* includes a list of all other Users that already are in the Room.
|
|
613
|
+
* Represents all the other users connected in the room. Treated as immutable.
|
|
678
614
|
*/
|
|
679
|
-
declare type
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
declare type InitialDocumentStateServerMsg = {
|
|
693
|
-
type: ServerMsgCode.INITIAL_STORAGE_STATE;
|
|
694
|
-
items: IdTuple<SerializedCrdt>[];
|
|
695
|
-
};
|
|
696
|
-
/**
|
|
697
|
-
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
698
|
-
* a change occurred in the Storage document.
|
|
699
|
-
*
|
|
700
|
-
* The payload of this message contains a list of Ops (aka incremental
|
|
701
|
-
* mutations to make to the initially loaded document).
|
|
702
|
-
*/
|
|
703
|
-
declare type UpdateStorageServerMsg = {
|
|
704
|
-
type: ServerMsgCode.UPDATE_STORAGE;
|
|
705
|
-
ops: Op[];
|
|
615
|
+
declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = ReadonlyArrayWithLegacyMethods<User<TPresence, TUserMeta>>;
|
|
616
|
+
declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
617
|
+
type: "leave";
|
|
618
|
+
user: User<TPresence, TUserMeta>;
|
|
619
|
+
} | {
|
|
620
|
+
type: "enter";
|
|
621
|
+
user: User<TPresence, TUserMeta>;
|
|
622
|
+
} | {
|
|
623
|
+
type: "update";
|
|
624
|
+
user: User<TPresence, TUserMeta>;
|
|
625
|
+
updates: Partial<TPresence>;
|
|
626
|
+
} | {
|
|
627
|
+
type: "reset";
|
|
706
628
|
};
|
|
707
629
|
|
|
708
|
-
/**
|
|
709
|
-
* This helper type is effectively a no-op, but will force TypeScript to
|
|
710
|
-
* "evaluate" any named helper types in its definition. This can sometimes make
|
|
711
|
-
* API signatures clearer in IDEs.
|
|
712
|
-
*
|
|
713
|
-
* For example, in:
|
|
714
|
-
*
|
|
715
|
-
* type Payload<T> = { data: T };
|
|
716
|
-
*
|
|
717
|
-
* let r1: Payload<string>;
|
|
718
|
-
* let r2: Resolve<Payload<string>>;
|
|
719
|
-
*
|
|
720
|
-
* The inferred type of `r1` is going to be `Payload<string>` which shows up in
|
|
721
|
-
* editor hints, and it may be unclear what's inside if you don't know the
|
|
722
|
-
* definition of `Payload`.
|
|
723
|
-
*
|
|
724
|
-
* The inferred type of `r2` is going to be `{ data: string }`, which may be
|
|
725
|
-
* more helpful.
|
|
726
|
-
*
|
|
727
|
-
* This trick comes from:
|
|
728
|
-
* https://effectivetypescript.com/2022/02/25/gentips-4-display/
|
|
729
|
-
*/
|
|
730
|
-
declare type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
|
|
731
|
-
[K in keyof T]: T[K];
|
|
732
|
-
};
|
|
733
630
|
declare type CustomEvent<TRoomEvent extends Json> = {
|
|
734
631
|
connectionId: number;
|
|
735
632
|
event: TRoomEvent;
|
|
736
633
|
};
|
|
737
|
-
declare type UpdateDelta = {
|
|
738
|
-
type: "update";
|
|
739
|
-
} | {
|
|
740
|
-
type: "delete";
|
|
741
|
-
};
|
|
742
|
-
/**
|
|
743
|
-
* A LiveMap notification that is sent in-client to any subscribers whenever
|
|
744
|
-
* one or more of the values inside the LiveMap instance have changed.
|
|
745
|
-
*/
|
|
746
|
-
declare type LiveMapUpdates<TKey extends string, TValue extends Lson> = {
|
|
747
|
-
type: "LiveMap";
|
|
748
|
-
node: LiveMap<TKey, TValue>;
|
|
749
|
-
updates: {
|
|
750
|
-
[key: string]: UpdateDelta;
|
|
751
|
-
};
|
|
752
|
-
};
|
|
753
|
-
declare type LiveObjectUpdateDelta<O extends {
|
|
754
|
-
[key: string]: unknown;
|
|
755
|
-
}> = {
|
|
756
|
-
[K in keyof O]?: UpdateDelta | undefined;
|
|
757
|
-
};
|
|
758
|
-
/**
|
|
759
|
-
* A LiveObject notification that is sent in-client to any subscribers whenever
|
|
760
|
-
* one or more of the entries inside the LiveObject instance have changed.
|
|
761
|
-
*/
|
|
762
|
-
declare type LiveObjectUpdates<TData extends LsonObject> = {
|
|
763
|
-
type: "LiveObject";
|
|
764
|
-
node: LiveObject<TData>;
|
|
765
|
-
updates: LiveObjectUpdateDelta<TData>;
|
|
766
|
-
};
|
|
767
|
-
declare type LiveListUpdateDelta = {
|
|
768
|
-
index: number;
|
|
769
|
-
item: Lson;
|
|
770
|
-
type: "insert";
|
|
771
|
-
} | {
|
|
772
|
-
index: number;
|
|
773
|
-
type: "delete";
|
|
774
|
-
} | {
|
|
775
|
-
index: number;
|
|
776
|
-
previousIndex: number;
|
|
777
|
-
item: Lson;
|
|
778
|
-
type: "move";
|
|
779
|
-
} | {
|
|
780
|
-
index: number;
|
|
781
|
-
item: Lson;
|
|
782
|
-
type: "set";
|
|
783
|
-
};
|
|
784
|
-
/**
|
|
785
|
-
* A LiveList notification that is sent in-client to any subscribers whenever
|
|
786
|
-
* one or more of the items inside the LiveList instance have changed.
|
|
787
|
-
*/
|
|
788
|
-
declare type LiveListUpdates<TItem extends Lson> = {
|
|
789
|
-
type: "LiveList";
|
|
790
|
-
node: LiveList<TItem>;
|
|
791
|
-
updates: LiveListUpdateDelta[];
|
|
792
|
-
};
|
|
793
|
-
declare type BroadcastOptions = {
|
|
794
|
-
/**
|
|
795
|
-
* Whether or not event is queued if the connection is currently closed.
|
|
796
|
-
*
|
|
797
|
-
* β We are not sure if we want to support this option in the future so it might be deprecated to be replaced by something else
|
|
798
|
-
*/
|
|
799
|
-
shouldQueueEventIfNotReady: boolean;
|
|
800
|
-
};
|
|
801
|
-
/**
|
|
802
|
-
* The payload of notifications sent (in-client) when LiveStructures change.
|
|
803
|
-
* Messages of this kind are not originating from the network, but are 100%
|
|
804
|
-
* in-client.
|
|
805
|
-
*/
|
|
806
|
-
declare type StorageUpdate = LiveMapUpdates<string, Lson> | LiveObjectUpdates<LsonObject> | LiveListUpdates<Lson>;
|
|
807
|
-
declare type StorageCallback = (updates: StorageUpdate[]) => void;
|
|
808
|
-
declare type RoomInitializers<TPresence extends JsonObject, TStorage extends LsonObject> = Resolve<{
|
|
809
|
-
/**
|
|
810
|
-
* The initial Presence to use and announce when you enter the Room. The
|
|
811
|
-
* Presence is available on all users in the Room (me & others).
|
|
812
|
-
*/
|
|
813
|
-
initialPresence: TPresence | ((roomId: string) => TPresence);
|
|
814
|
-
/**
|
|
815
|
-
* The initial Storage to use when entering a new Room.
|
|
816
|
-
*/
|
|
817
|
-
initialStorage?: TStorage | ((roomId: string) => TStorage);
|
|
818
|
-
/**
|
|
819
|
-
* Whether or not the room connects to Liveblock servers. Default is true.
|
|
820
|
-
*
|
|
821
|
-
* Usually set to false when the client is used from the server to not call
|
|
822
|
-
* the authentication endpoint or connect via WebSocket.
|
|
823
|
-
*/
|
|
824
|
-
shouldInitiallyConnect?: boolean;
|
|
825
|
-
}>;
|
|
826
|
-
declare type Client = {
|
|
827
|
-
/**
|
|
828
|
-
* Gets a room. Returns null if {@link Client.enter} has not been called previously.
|
|
829
|
-
*
|
|
830
|
-
* @param roomId The id of the room
|
|
831
|
-
*/
|
|
832
|
-
getRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string): Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;
|
|
833
|
-
/**
|
|
834
|
-
* Enters a room and returns it.
|
|
835
|
-
* @param roomId The id of the room
|
|
836
|
-
* @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
|
|
837
|
-
*/
|
|
838
|
-
enter<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: RoomInitializers<TPresence, TStorage>): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
|
|
839
|
-
/**
|
|
840
|
-
* Leaves a room.
|
|
841
|
-
* @param roomId The id of the room
|
|
842
|
-
*/
|
|
843
|
-
leave(roomId: string): void;
|
|
844
|
-
};
|
|
845
|
-
/**
|
|
846
|
-
* Represents all the other users connected in the room. Treated as immutable.
|
|
847
|
-
*/
|
|
848
|
-
declare type Others<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = ReadonlyArrayWithLegacyMethods<User<TPresence, TUserMeta>>;
|
|
849
|
-
/**
|
|
850
|
-
* Represents a user connected in a room. Treated as immutable.
|
|
851
|
-
*/
|
|
852
|
-
declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
853
|
-
/**
|
|
854
|
-
* The connection id of the user. It is unique and increment at every new connection.
|
|
855
|
-
*/
|
|
856
|
-
readonly connectionId: number;
|
|
857
|
-
/**
|
|
858
|
-
* The id of the user that has been set in the authentication endpoint.
|
|
859
|
-
* Useful to get additional information about the connected user.
|
|
860
|
-
*/
|
|
861
|
-
readonly id: TUserMeta["id"];
|
|
862
|
-
/**
|
|
863
|
-
* Additional user information that has been set in the authentication endpoint.
|
|
864
|
-
*/
|
|
865
|
-
readonly info: TUserMeta["info"];
|
|
866
|
-
/**
|
|
867
|
-
* The user presence.
|
|
868
|
-
*/
|
|
869
|
-
readonly presence: TPresence;
|
|
870
|
-
/**
|
|
871
|
-
* False if the user can modify the room storage, true otherwise.
|
|
872
|
-
*/
|
|
873
|
-
readonly isReadOnly: boolean;
|
|
874
|
-
};
|
|
875
|
-
declare type AuthEndpointCallback = (room: string) => Promise<{
|
|
876
|
-
token: string;
|
|
877
|
-
}>;
|
|
878
|
-
declare type AuthEndpoint = string | AuthEndpointCallback;
|
|
879
|
-
declare type Polyfills = {
|
|
880
|
-
atob?: (data: string) => string;
|
|
881
|
-
fetch?: typeof fetch;
|
|
882
|
-
WebSocket?: any;
|
|
883
|
-
};
|
|
884
|
-
/**
|
|
885
|
-
* The authentication endpoint that is called to ensure that the current user has access to a room.
|
|
886
|
-
* Can be an url or a callback if you need to add additional headers.
|
|
887
|
-
*/
|
|
888
|
-
declare type ClientOptions = {
|
|
889
|
-
throttle?: number;
|
|
890
|
-
polyfills?: Polyfills;
|
|
891
|
-
/**
|
|
892
|
-
* Backward-compatible way to set `polyfills.fetch`.
|
|
893
|
-
*/
|
|
894
|
-
fetchPolyfill?: Polyfills["fetch"];
|
|
895
|
-
/**
|
|
896
|
-
* Backward-compatible way to set `polyfills.WebSocket`.
|
|
897
|
-
*/
|
|
898
|
-
WebSocketPolyfill?: Polyfills["WebSocket"];
|
|
899
|
-
} & ({
|
|
900
|
-
publicApiKey: string;
|
|
901
|
-
authEndpoint?: never;
|
|
902
|
-
} | {
|
|
903
|
-
publicApiKey?: never;
|
|
904
|
-
authEndpoint: AuthEndpoint;
|
|
905
|
-
});
|
|
906
634
|
declare type Connection = {
|
|
907
635
|
state: "closed";
|
|
908
636
|
} | {
|
|
@@ -925,19 +653,6 @@ declare type Connection = {
|
|
|
925
653
|
state: "failed";
|
|
926
654
|
};
|
|
927
655
|
declare type ConnectionState = Connection["state"];
|
|
928
|
-
declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
929
|
-
type: "leave";
|
|
930
|
-
user: User<TPresence, TUserMeta>;
|
|
931
|
-
} | {
|
|
932
|
-
type: "enter";
|
|
933
|
-
user: User<TPresence, TUserMeta>;
|
|
934
|
-
} | {
|
|
935
|
-
type: "update";
|
|
936
|
-
user: User<TPresence, TUserMeta>;
|
|
937
|
-
updates: Partial<TPresence>;
|
|
938
|
-
} | {
|
|
939
|
-
type: "reset";
|
|
940
|
-
};
|
|
941
656
|
interface History {
|
|
942
657
|
/**
|
|
943
658
|
* Undoes the last operation executed by the current client.
|
|
@@ -1015,6 +730,14 @@ interface HistoryEvent {
|
|
|
1015
730
|
canUndo: boolean;
|
|
1016
731
|
canRedo: boolean;
|
|
1017
732
|
}
|
|
733
|
+
declare type BroadcastOptions = {
|
|
734
|
+
/**
|
|
735
|
+
* Whether or not event is queued if the connection is currently closed.
|
|
736
|
+
*
|
|
737
|
+
* β We are not sure if we want to support this option in the future so it might be deprecated to be replaced by something else
|
|
738
|
+
*/
|
|
739
|
+
shouldQueueEventIfNotReady: boolean;
|
|
740
|
+
};
|
|
1018
741
|
declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
|
|
1019
742
|
/**
|
|
1020
743
|
* The id of the room.
|
|
@@ -1240,36 +963,74 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1240
963
|
*/
|
|
1241
964
|
batch<T>(fn: () => T): T;
|
|
1242
965
|
};
|
|
1243
|
-
declare
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
|
|
1248
|
-
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
|
|
1249
|
-
MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
|
|
1250
|
-
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
|
|
1251
|
-
CLOSE_WITHOUT_RETRY = 4999
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
declare type AppOnlyAuthToken = {
|
|
1255
|
-
appId: string;
|
|
1256
|
-
roomId?: never;
|
|
1257
|
-
scopes: string[];
|
|
966
|
+
declare type Polyfills = {
|
|
967
|
+
atob?: (data: string) => string;
|
|
968
|
+
fetch?: typeof fetch;
|
|
969
|
+
WebSocket?: any;
|
|
1258
970
|
};
|
|
1259
|
-
declare type
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
971
|
+
declare type RoomInitializers<TPresence extends JsonObject, TStorage extends LsonObject> = Resolve<{
|
|
972
|
+
/**
|
|
973
|
+
* The initial Presence to use and announce when you enter the Room. The
|
|
974
|
+
* Presence is available on all users in the Room (me & others).
|
|
975
|
+
*/
|
|
976
|
+
initialPresence: TPresence | ((roomId: string) => TPresence);
|
|
977
|
+
/**
|
|
978
|
+
* The initial Storage to use when entering a new Room.
|
|
979
|
+
*/
|
|
980
|
+
initialStorage?: TStorage | ((roomId: string) => TStorage);
|
|
981
|
+
/**
|
|
982
|
+
* Whether or not the room connects to Liveblock servers. Default is true.
|
|
983
|
+
*
|
|
984
|
+
* Usually set to false when the client is used from the server to not call
|
|
985
|
+
* the authentication endpoint or connect via WebSocket.
|
|
986
|
+
*/
|
|
987
|
+
shouldInitiallyConnect?: boolean;
|
|
988
|
+
}>;
|
|
1272
989
|
|
|
990
|
+
declare type Client = {
|
|
991
|
+
/**
|
|
992
|
+
* Gets a room. Returns null if {@link Client.enter} has not been called previously.
|
|
993
|
+
*
|
|
994
|
+
* @param roomId The id of the room
|
|
995
|
+
*/
|
|
996
|
+
getRoom<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string): Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null;
|
|
997
|
+
/**
|
|
998
|
+
* Enters a room and returns it.
|
|
999
|
+
* @param roomId The id of the room
|
|
1000
|
+
* @param options Optional. You can provide initializers for the Presence or Storage when entering the Room.
|
|
1001
|
+
*/
|
|
1002
|
+
enter<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never>(roomId: string, options: RoomInitializers<TPresence, TStorage>): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
|
|
1003
|
+
/**
|
|
1004
|
+
* Leaves a room.
|
|
1005
|
+
* @param roomId The id of the room
|
|
1006
|
+
*/
|
|
1007
|
+
leave(roomId: string): void;
|
|
1008
|
+
};
|
|
1009
|
+
declare type AuthEndpoint = string | ((room: string) => Promise<{
|
|
1010
|
+
token: string;
|
|
1011
|
+
}>);
|
|
1012
|
+
/**
|
|
1013
|
+
* The authentication endpoint that is called to ensure that the current user has access to a room.
|
|
1014
|
+
* Can be an url or a callback if you need to add additional headers.
|
|
1015
|
+
*/
|
|
1016
|
+
declare type ClientOptions = {
|
|
1017
|
+
throttle?: number;
|
|
1018
|
+
polyfills?: Polyfills;
|
|
1019
|
+
/**
|
|
1020
|
+
* Backward-compatible way to set `polyfills.fetch`.
|
|
1021
|
+
*/
|
|
1022
|
+
fetchPolyfill?: Polyfills["fetch"];
|
|
1023
|
+
/**
|
|
1024
|
+
* Backward-compatible way to set `polyfills.WebSocket`.
|
|
1025
|
+
*/
|
|
1026
|
+
WebSocketPolyfill?: Polyfills["WebSocket"];
|
|
1027
|
+
} & ({
|
|
1028
|
+
publicApiKey: string;
|
|
1029
|
+
authEndpoint?: never;
|
|
1030
|
+
} | {
|
|
1031
|
+
publicApiKey?: never;
|
|
1032
|
+
authEndpoint: AuthEndpoint;
|
|
1033
|
+
});
|
|
1273
1034
|
/**
|
|
1274
1035
|
* Create a client that will be responsible to communicate with liveblocks servers.
|
|
1275
1036
|
*
|
|
@@ -1297,6 +1058,46 @@ declare function isAuthToken(data: JsonObject): data is AuthToken;
|
|
|
1297
1058
|
*/
|
|
1298
1059
|
declare function createClient(options: ClientOptions): Client;
|
|
1299
1060
|
|
|
1061
|
+
declare function lsonToJson(value: Lson): Json;
|
|
1062
|
+
declare function patchLiveObjectKey<O extends LsonObject, K extends keyof O, V extends Json>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void;
|
|
1063
|
+
declare function legacy_patchImmutableObject<S extends JsonObject>(state: S, updates: StorageUpdate[]): S;
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Helper function that can be used to implement exhaustive switch statements
|
|
1067
|
+
* with TypeScript. Example usage:
|
|
1068
|
+
*
|
|
1069
|
+
* type Fruit = "π" | "π";
|
|
1070
|
+
*
|
|
1071
|
+
* switch (fruit) {
|
|
1072
|
+
* case "π":
|
|
1073
|
+
* case "π":
|
|
1074
|
+
* return doSomething();
|
|
1075
|
+
*
|
|
1076
|
+
* default:
|
|
1077
|
+
* return assertNever(fruit, "Unknown fruit");
|
|
1078
|
+
* }
|
|
1079
|
+
*
|
|
1080
|
+
* If now the Fruit union is extended (i.e. add "π"), TypeScript will catch
|
|
1081
|
+
* this *statically*, rather than at runtime, and force you to handle the
|
|
1082
|
+
* π case.
|
|
1083
|
+
*/
|
|
1084
|
+
declare function assertNever(_value: never, errmsg: string): never;
|
|
1085
|
+
/**
|
|
1086
|
+
* Asserts that a given value is non-nullable. This is similar to TypeScript's
|
|
1087
|
+
* `!` operator, but will throw an error at runtime (dev-mode only) indicating
|
|
1088
|
+
* an incorrect assumption.
|
|
1089
|
+
*
|
|
1090
|
+
* Instead of:
|
|
1091
|
+
*
|
|
1092
|
+
* foo!.bar
|
|
1093
|
+
*
|
|
1094
|
+
* Use:
|
|
1095
|
+
*
|
|
1096
|
+
* nn(foo).bar
|
|
1097
|
+
*
|
|
1098
|
+
*/
|
|
1099
|
+
declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
|
|
1100
|
+
|
|
1300
1101
|
/**
|
|
1301
1102
|
* Displays a deprecation warning in the dev console. Only in dev mode, and
|
|
1302
1103
|
* only once per message/key. In production, this is a no-op.
|
|
@@ -1323,9 +1124,11 @@ declare function throwUsageError(message: string): void;
|
|
|
1323
1124
|
*/
|
|
1324
1125
|
declare function errorIf(condition: unknown, message: string): void;
|
|
1325
1126
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1127
|
+
/**
|
|
1128
|
+
* Freezes the given argument, but only in development builds. In production
|
|
1129
|
+
* builds, this is a no-op for performance reasons.
|
|
1130
|
+
*/
|
|
1131
|
+
declare const freeze: typeof Object.freeze;
|
|
1329
1132
|
|
|
1330
1133
|
declare function makePosition(before?: string, after?: string): string;
|
|
1331
1134
|
declare function comparePosition(posA: string, posB: string): number;
|
|
@@ -1341,11 +1144,6 @@ declare function comparePosition(posA: string, posB: string): number;
|
|
|
1341
1144
|
*/
|
|
1342
1145
|
declare function shallow(a: unknown, b: unknown): boolean;
|
|
1343
1146
|
|
|
1344
|
-
/**
|
|
1345
|
-
* Freezes the given argument, but only in development builds. In production
|
|
1346
|
-
* builds, this is a no-op for performance reasons.
|
|
1347
|
-
*/
|
|
1348
|
-
declare const freeze: typeof Object.freeze;
|
|
1349
1147
|
declare function isPlainObject(blob: unknown): blob is {
|
|
1350
1148
|
[key: string]: unknown;
|
|
1351
1149
|
};
|
|
@@ -1359,6 +1157,214 @@ declare function tryParseJson(rawMessage: string): Json | undefined;
|
|
|
1359
1157
|
*/
|
|
1360
1158
|
declare function b64decode(b64value: string): string;
|
|
1361
1159
|
|
|
1160
|
+
declare type IdTuple<T> = [id: string, value: T];
|
|
1161
|
+
declare enum CrdtType {
|
|
1162
|
+
OBJECT = 0,
|
|
1163
|
+
LIST = 1,
|
|
1164
|
+
MAP = 2,
|
|
1165
|
+
REGISTER = 3
|
|
1166
|
+
}
|
|
1167
|
+
declare type SerializedCrdt = SerializedRootObject | SerializedChild;
|
|
1168
|
+
declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
|
|
1169
|
+
declare type SerializedRootObject = {
|
|
1170
|
+
type: CrdtType.OBJECT;
|
|
1171
|
+
data: JsonObject;
|
|
1172
|
+
parentId?: never;
|
|
1173
|
+
parentKey?: never;
|
|
1174
|
+
};
|
|
1175
|
+
declare type SerializedObject = {
|
|
1176
|
+
type: CrdtType.OBJECT;
|
|
1177
|
+
parentId: string;
|
|
1178
|
+
parentKey: string;
|
|
1179
|
+
data: JsonObject;
|
|
1180
|
+
};
|
|
1181
|
+
declare type SerializedList = {
|
|
1182
|
+
type: CrdtType.LIST;
|
|
1183
|
+
parentId: string;
|
|
1184
|
+
parentKey: string;
|
|
1185
|
+
};
|
|
1186
|
+
declare type SerializedMap = {
|
|
1187
|
+
type: CrdtType.MAP;
|
|
1188
|
+
parentId: string;
|
|
1189
|
+
parentKey: string;
|
|
1190
|
+
};
|
|
1191
|
+
declare type SerializedRegister = {
|
|
1192
|
+
type: CrdtType.REGISTER;
|
|
1193
|
+
parentId: string;
|
|
1194
|
+
parentKey: string;
|
|
1195
|
+
data: Json;
|
|
1196
|
+
};
|
|
1197
|
+
declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
|
|
1198
|
+
declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
|
|
1199
|
+
|
|
1200
|
+
declare enum ServerMsgCode {
|
|
1201
|
+
UPDATE_PRESENCE = 100,
|
|
1202
|
+
USER_JOINED = 101,
|
|
1203
|
+
USER_LEFT = 102,
|
|
1204
|
+
BROADCASTED_EVENT = 103,
|
|
1205
|
+
ROOM_STATE = 104,
|
|
1206
|
+
INITIAL_STORAGE_STATE = 200,
|
|
1207
|
+
UPDATE_STORAGE = 201
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Messages that can be sent from the server to the client.
|
|
1211
|
+
*/
|
|
1212
|
+
declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg;
|
|
1213
|
+
/**
|
|
1214
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1215
|
+
* a User updated their presence. For example, when a user moves their cursor.
|
|
1216
|
+
*
|
|
1217
|
+
* In most cases, the data payload will only include the fields from the
|
|
1218
|
+
* Presence that have been changed since the last announcement. However, after
|
|
1219
|
+
* a new user joins a room, a "full presence" will be announced so the newly
|
|
1220
|
+
* connected user will get each other's user full presence at least once. In
|
|
1221
|
+
* those cases, the `targetActor` field indicates the newly connected client,
|
|
1222
|
+
* so all other existing clients can ignore this broadcasted message.
|
|
1223
|
+
*/
|
|
1224
|
+
declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
|
|
1225
|
+
type: ServerMsgCode.UPDATE_PRESENCE;
|
|
1226
|
+
/**
|
|
1227
|
+
* The User whose Presence has changed.
|
|
1228
|
+
*/
|
|
1229
|
+
actor: number;
|
|
1230
|
+
/**
|
|
1231
|
+
* When set, signifies that this is a Full Presenceβ’ update, not a patch.
|
|
1232
|
+
*
|
|
1233
|
+
* The numeric value itself no longer has specific meaning. Historically,
|
|
1234
|
+
* this field was intended so that clients could ignore these broadcasted
|
|
1235
|
+
* full presence messages, but it turned out that getting a full presence
|
|
1236
|
+
* "keyframe" from time to time was useful.
|
|
1237
|
+
*
|
|
1238
|
+
* So nowadays, the presence (pun intended) of this `targetActor` field
|
|
1239
|
+
* is a backward-compatible way of expressing that the `data` contains
|
|
1240
|
+
* all presence fields, and isn't a partial "patch".
|
|
1241
|
+
*/
|
|
1242
|
+
targetActor: number;
|
|
1243
|
+
/**
|
|
1244
|
+
* The partial or full Presence of a User. If the `targetActor` field is set,
|
|
1245
|
+
* this will be the full Presence, otherwise it only contain the fields that
|
|
1246
|
+
* have changed since the last broadcast.
|
|
1247
|
+
*/
|
|
1248
|
+
data: TPresence;
|
|
1249
|
+
} | {
|
|
1250
|
+
type: ServerMsgCode.UPDATE_PRESENCE;
|
|
1251
|
+
/**
|
|
1252
|
+
* The User whose Presence has changed.
|
|
1253
|
+
*/
|
|
1254
|
+
actor: number;
|
|
1255
|
+
/**
|
|
1256
|
+
* Not set for partial presence updates.
|
|
1257
|
+
*/
|
|
1258
|
+
targetActor?: undefined;
|
|
1259
|
+
/**
|
|
1260
|
+
* A partial Presence patch to apply to the User. It will only contain the
|
|
1261
|
+
* fields that have changed since the last broadcast.
|
|
1262
|
+
*/
|
|
1263
|
+
data: Partial<TPresence>;
|
|
1264
|
+
};
|
|
1265
|
+
/**
|
|
1266
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1267
|
+
* a new User has joined the Room.
|
|
1268
|
+
*/
|
|
1269
|
+
declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
1270
|
+
type: ServerMsgCode.USER_JOINED;
|
|
1271
|
+
actor: number;
|
|
1272
|
+
/**
|
|
1273
|
+
* The id of the User that has been set in the authentication endpoint.
|
|
1274
|
+
* Useful to get additional information about the connected user.
|
|
1275
|
+
*/
|
|
1276
|
+
id: TUserMeta["id"];
|
|
1277
|
+
/**
|
|
1278
|
+
* Additional user information that has been set in the authentication
|
|
1279
|
+
* endpoint.
|
|
1280
|
+
*/
|
|
1281
|
+
info: TUserMeta["info"];
|
|
1282
|
+
/**
|
|
1283
|
+
* Permissions that the user has in the Room.
|
|
1284
|
+
*/
|
|
1285
|
+
scopes: string[];
|
|
1286
|
+
};
|
|
1287
|
+
/**
|
|
1288
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1289
|
+
* a new User has left the Room.
|
|
1290
|
+
*/
|
|
1291
|
+
declare type UserLeftServerMsg = {
|
|
1292
|
+
type: ServerMsgCode.USER_LEFT;
|
|
1293
|
+
actor: number;
|
|
1294
|
+
};
|
|
1295
|
+
/**
|
|
1296
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1297
|
+
* a User broadcasted an Event to everyone in the Room.
|
|
1298
|
+
*/
|
|
1299
|
+
declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
|
|
1300
|
+
type: ServerMsgCode.BROADCASTED_EVENT;
|
|
1301
|
+
/**
|
|
1302
|
+
* The User who broadcasted the Event.
|
|
1303
|
+
*/
|
|
1304
|
+
actor: number;
|
|
1305
|
+
/**
|
|
1306
|
+
* The arbitrary payload of the Event. This can be any JSON value. Clients
|
|
1307
|
+
* will have to manually verify/decode this event.
|
|
1308
|
+
*/
|
|
1309
|
+
event: TRoomEvent;
|
|
1310
|
+
};
|
|
1311
|
+
/**
|
|
1312
|
+
* Sent by the WebSocket server to a single client in response to the client
|
|
1313
|
+
* joining the Room, to provide the initial state of the Room. The payload
|
|
1314
|
+
* includes a list of all other Users that already are in the Room.
|
|
1315
|
+
*/
|
|
1316
|
+
declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
1317
|
+
type: ServerMsgCode.ROOM_STATE;
|
|
1318
|
+
users: {
|
|
1319
|
+
[actor: number]: TUserMeta & {
|
|
1320
|
+
scopes: string[];
|
|
1321
|
+
};
|
|
1322
|
+
};
|
|
1323
|
+
};
|
|
1324
|
+
/**
|
|
1325
|
+
* Sent by the WebSocket server to a single client in response to the client
|
|
1326
|
+
* joining the Room, to provide the initial Storage state of the Room. The
|
|
1327
|
+
* payload includes the entire Storage document.
|
|
1328
|
+
*/
|
|
1329
|
+
declare type InitialDocumentStateServerMsg = {
|
|
1330
|
+
type: ServerMsgCode.INITIAL_STORAGE_STATE;
|
|
1331
|
+
items: IdTuple<SerializedCrdt>[];
|
|
1332
|
+
};
|
|
1333
|
+
/**
|
|
1334
|
+
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1335
|
+
* a change occurred in the Storage document.
|
|
1336
|
+
*
|
|
1337
|
+
* The payload of this message contains a list of Ops (aka incremental
|
|
1338
|
+
* mutations to make to the initially loaded document).
|
|
1339
|
+
*/
|
|
1340
|
+
declare type UpdateStorageServerMsg = {
|
|
1341
|
+
type: ServerMsgCode.UPDATE_STORAGE;
|
|
1342
|
+
ops: Op[];
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Lookup table for nodes (= SerializedCrdt values) by their IDs.
|
|
1347
|
+
*/
|
|
1348
|
+
declare type NodeMap = Map<string, // Node ID
|
|
1349
|
+
SerializedCrdt>;
|
|
1350
|
+
/**
|
|
1351
|
+
* Reverse lookup table for all child nodes (= list of SerializedCrdt values)
|
|
1352
|
+
* by their parent node's IDs.
|
|
1353
|
+
*/
|
|
1354
|
+
declare type ParentToChildNodeMap = Map<string, // Parent's node ID
|
|
1355
|
+
IdTuple<SerializedChild>[]>;
|
|
1356
|
+
|
|
1357
|
+
declare enum WebsocketCloseCodes {
|
|
1358
|
+
CLOSE_ABNORMAL = 1006,
|
|
1359
|
+
INVALID_MESSAGE_FORMAT = 4000,
|
|
1360
|
+
NOT_ALLOWED = 4001,
|
|
1361
|
+
MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
|
|
1362
|
+
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
|
|
1363
|
+
MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
|
|
1364
|
+
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
|
|
1365
|
+
CLOSE_WITHOUT_RETRY = 4999
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1362
1368
|
/**
|
|
1363
1369
|
* PRIVATE / INTERNAL APIS
|
|
1364
1370
|
* -----------------------
|