@liveblocks/client 0.17.0-test1 → 0.17.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.
package/internal.d.ts CHANGED
@@ -1,50 +1,119 @@
1
1
  import {
2
- d as JsonObject,
2
+ e as JsonObject,
3
3
  J as Json,
4
- h as Op,
5
- I as IdTuple,
6
- i as SerializedCrdt,
7
- f as Lson,
8
- g as LsonObject,
4
+ B as BaseUserMeta,
5
+ g as Lson,
6
+ h as LsonObject,
9
7
  c as LiveObject,
10
8
  S as StorageUpdate,
11
9
  } from "./shared.js";
12
10
  export {
13
- G as CrdtType,
14
- j as CreateChildOp,
15
- k as CreateListOp,
16
- l as CreateMapOp,
17
- m as CreateObjectOp,
18
- n as CreateOp,
19
- o as CreateRegisterOp,
20
- p as CreateRootObjectOp,
21
- D as DeleteCrdtOp,
22
- q as DeleteObjectKeyOp,
23
- I as IdTuple,
24
- r as LiveNode,
25
- N as NodeMap,
26
- h as Op,
27
- K as OpCode,
28
- s as ParentToChildNodeMap,
29
- t as Resolve,
30
- u as RoomInitializers,
31
- v as SerializedChild,
32
- i as SerializedCrdt,
33
- w as SerializedList,
34
- x as SerializedMap,
35
- y as SerializedObject,
36
- z as SerializedRegister,
37
- A as SerializedRootObject,
38
- E as SetParentKeyOp,
39
- F as UpdateObjectOp,
11
+ i as LiveNode,
12
+ j as Resolve,
13
+ k as RoomInitializers,
40
14
  W as WebsocketCloseCodes,
41
- V as isChildCrdt,
42
- M as isJsonArray,
43
- Q as isJsonObject,
44
- T as isJsonScalar,
45
- X as isRootCrdt,
15
+ l as isJsonArray,
16
+ m as isJsonObject,
17
+ n as isJsonScalar,
46
18
  } from "./shared.js";
47
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
+
48
117
  declare enum ClientMsgCode {
49
118
  UPDATE_PRESENCE = 100,
50
119
  BROADCAST_EVENT = 103,
@@ -54,14 +123,14 @@ declare enum ClientMsgCode {
54
123
  /**
55
124
  * Messages that can be sent from the client to the server.
56
125
  */
57
- declare type ClientMsg<TPresence extends JsonObject> =
58
- | BroadcastEventClientMsg
126
+ declare type ClientMsg<TPresence extends JsonObject, TRoomEvent extends Json> =
127
+ | BroadcastEventClientMsg<TRoomEvent>
59
128
  | UpdatePresenceClientMsg<TPresence>
60
129
  | UpdateStorageClientMsg
61
130
  | FetchStorageClientMsg;
62
- declare type BroadcastEventClientMsg = {
131
+ declare type BroadcastEventClientMsg<TRoomEvent extends Json> = {
63
132
  type: ClientMsgCode.BROADCAST_EVENT;
64
- event: Json;
133
+ event: TRoomEvent;
65
134
  };
66
135
  declare type UpdatePresenceClientMsg<TPresence extends JsonObject> = {
67
136
  type: ClientMsgCode.UPDATE_PRESENCE;
@@ -76,6 +145,66 @@ declare type FetchStorageClientMsg = {
76
145
  type: ClientMsgCode.FETCH_STORAGE;
77
146
  };
78
147
 
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
+
192
+ /**
193
+ * Lookup table for nodes (= SerializedCrdt values) by their IDs.
194
+ */
195
+ declare type NodeMap = Map<
196
+ string, // Node ID
197
+ SerializedCrdt
198
+ >;
199
+ /**
200
+ * Reverse lookup table for all child nodes (= list of SerializedCrdt values)
201
+ * by their parent node's IDs.
202
+ */
203
+ declare type ParentToChildNodeMap = Map<
204
+ string, // Parent's node ID
205
+ IdTuple<SerializedChild>[]
206
+ >;
207
+
79
208
  declare enum ServerMsgCode {
80
209
  UPDATE_PRESENCE = 100,
81
210
  USER_JOINED = 101,
@@ -88,12 +217,16 @@ declare enum ServerMsgCode {
88
217
  /**
89
218
  * Messages that can be sent from the server to the client.
90
219
  */
91
- declare type ServerMsg<TPresence extends JsonObject> =
220
+ declare type ServerMsg<
221
+ TPresence extends JsonObject,
222
+ TUserMeta extends BaseUserMeta,
223
+ TRoomEvent extends Json
224
+ > =
92
225
  | UpdatePresenceServerMsg<TPresence>
93
- | UserJoinServerMsg
226
+ | UserJoinServerMsg<TUserMeta>
94
227
  | UserLeftServerMsg
95
- | BroadcastedEventServerMsg
96
- | RoomStateServerMsg
228
+ | BroadcastedEventServerMsg<TRoomEvent>
229
+ | RoomStateServerMsg<TUserMeta>
97
230
  | InitialDocumentStateServerMsg
98
231
  | UpdateStorageServerMsg;
99
232
  /**
@@ -130,19 +263,19 @@ declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
130
263
  * Sent by the WebSocket server and broadcasted to all clients to announce that
131
264
  * a new User has joined the Room.
132
265
  */
133
- declare type UserJoinServerMsg = {
266
+ declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
134
267
  type: ServerMsgCode.USER_JOINED;
135
268
  actor: number;
136
269
  /**
137
270
  * The id of the User that has been set in the authentication endpoint.
138
271
  * Useful to get additional information about the connected user.
139
272
  */
140
- id?: string;
273
+ id: TUserMeta["id"];
141
274
  /**
142
275
  * Additional user information that has been set in the authentication
143
276
  * endpoint.
144
277
  */
145
- info?: Json;
278
+ info: TUserMeta["info"];
146
279
  };
147
280
  /**
148
281
  * Sent by the WebSocket server and broadcasted to all clients to announce that
@@ -156,7 +289,7 @@ declare type UserLeftServerMsg = {
156
289
  * Sent by the WebSocket server and broadcasted to all clients to announce that
157
290
  * a User broadcasted an Event to everyone in the Room.
158
291
  */
159
- declare type BroadcastedEventServerMsg = {
292
+ declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
160
293
  type: ServerMsgCode.BROADCASTED_EVENT;
161
294
  /**
162
295
  * The User who broadcasted the Event.
@@ -166,20 +299,17 @@ declare type BroadcastedEventServerMsg = {
166
299
  * The arbitrary payload of the Event. This can be any JSON value. Clients
167
300
  * will have to manually verify/decode this event.
168
301
  */
169
- event: Json;
302
+ event: TRoomEvent;
170
303
  };
171
304
  /**
172
305
  * Sent by the WebSocket server to a single client in response to the client
173
306
  * joining the Room, to provide the initial state of the Room. The payload
174
307
  * includes a list of all other Users that already are in the Room.
175
308
  */
176
- declare type RoomStateServerMsg = {
309
+ declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
177
310
  type: ServerMsgCode.ROOM_STATE;
178
311
  users: {
179
- [actor: number]: {
180
- id?: string;
181
- info?: Json;
182
- };
312
+ [actor: number]: TUserMeta;
183
313
  };
184
314
  };
185
315
  /**
@@ -263,15 +393,10 @@ declare type RoomAuthToken = {
263
393
  info?: Json;
264
394
  };
265
395
  declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
266
- interface JwtMetadata extends JsonObject {
267
- iat: number;
268
- exp: number;
269
- }
270
396
  declare function isScope(value: unknown): value is Scope;
271
397
  declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
272
398
  declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
273
399
  declare function isAuthToken(data: JsonObject): data is AuthToken;
274
- declare function parseAuthToken(token: string): AuthToken & JwtMetadata;
275
400
 
276
401
  /**
277
402
  * Tools to help with the controlled deprecation of public APIs.
@@ -342,13 +467,37 @@ export {
342
467
  BroadcastedEventServerMsg,
343
468
  ClientMsg,
344
469
  ClientMsgCode,
470
+ CrdtType,
471
+ CreateChildOp,
472
+ CreateListOp,
473
+ CreateMapOp,
474
+ CreateObjectOp,
475
+ CreateOp,
476
+ CreateRegisterOp,
477
+ CreateRootObjectOp,
478
+ DeleteCrdtOp,
479
+ DeleteObjectKeyOp,
345
480
  FetchStorageClientMsg,
481
+ IdTuple,
346
482
  InitialDocumentStateServerMsg,
483
+ NodeMap,
484
+ Op,
485
+ OpCode,
486
+ ParentToChildNodeMap,
347
487
  RoomAuthToken,
348
488
  RoomStateServerMsg,
349
489
  Scope,
490
+ SerializedChild,
491
+ SerializedCrdt,
492
+ SerializedList,
493
+ SerializedMap,
494
+ SerializedObject,
495
+ SerializedRegister,
496
+ SerializedRootObject,
350
497
  ServerMsg,
351
498
  ServerMsgCode,
499
+ SetParentKeyOp,
500
+ UpdateObjectOp,
352
501
  UpdatePresenceClientMsg,
353
502
  UpdatePresenceServerMsg,
354
503
  UpdateStorageClientMsg,
@@ -363,13 +512,14 @@ export {
363
512
  errorIf,
364
513
  isAppOnlyAuthToken,
365
514
  isAuthToken,
515
+ isChildCrdt,
366
516
  isPlainObject,
367
517
  isRoomAuthToken,
518
+ isRootCrdt,
368
519
  isScope,
369
520
  lsonToJson,
370
521
  makePosition,
371
522
  nn,
372
- parseAuthToken,
373
523
  patchImmutableObject,
374
524
  patchLiveObjectKey,
375
525
  throwUsageError,
package/internal.js CHANGED
@@ -310,7 +310,6 @@ Object.defineProperty(exports, "ClientMsgCode", {
310
310
  (exports.isScope = Json.isScope),
311
311
  (exports.makePosition = Json.makePosition),
312
312
  (exports.nn = Json.nn),
313
- (exports.parseAuthToken = Json.parseAuthToken),
314
313
  (exports.throwUsageError = Json.throwUsageError),
315
314
  (exports.tryParseJson = Json.tryParseJson),
316
315
  (exports.lsonToJson = lsonToJson),
package/internal.mjs CHANGED
@@ -1,38 +1,37 @@
1
1
  import {
2
2
  L as LiveObject,
3
- o as LiveList,
4
- q as LiveMap,
5
- s as LiveRegister,
6
- a as isPlainObject,
7
- u as findNonSerializableValue,
8
- e as isLiveList,
9
- v as isLiveObject,
3
+ q as LiveList,
4
+ s as LiveMap,
5
+ u as LiveRegister,
6
+ b as isPlainObject,
7
+ v as findNonSerializableValue,
8
+ f as isLiveList,
9
+ w as isLiveObject,
10
10
  } from "./shared.mjs";
11
11
  export {
12
12
  C as ClientMsgCode,
13
13
  I as CrdtType,
14
- d as OpCode,
14
+ e as OpCode,
15
15
  S as ServerMsgCode,
16
16
  W as WebsocketCloseCodes,
17
- w as assertNever,
17
+ x as assertNever,
18
18
  M as b64decode,
19
19
  G as comparePosition,
20
20
  D as deprecate,
21
21
  E as deprecateIf,
22
- l as errorIf,
23
- x as isAppOnlyAuthToken,
24
- y as isAuthToken,
22
+ o as errorIf,
23
+ y as isAppOnlyAuthToken,
24
+ z as isAuthToken,
25
25
  K as isChildCrdt,
26
- f as isJsonArray,
27
- k as isJsonObject,
26
+ h as isJsonArray,
27
+ l as isJsonObject,
28
28
  J as isJsonScalar,
29
- a as isPlainObject,
30
- z as isRoomAuthToken,
31
- j as isRootCrdt,
32
- A as isScope,
29
+ b as isPlainObject,
30
+ A as isRoomAuthToken,
31
+ k as isRootCrdt,
32
+ B as isScope,
33
33
  H as makePosition,
34
34
  n as nn,
35
- B as parseAuthToken,
36
35
  F as throwUsageError,
37
36
  t as tryParseJson,
38
37
  } from "./shared.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.17.0-test1",
3
+ "version": "0.17.1",
4
4
  "description": "A client that lets you interact with Liveblocks servers.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",