@liveblocks/client 0.18.1 → 0.18.3-test1

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 DELETED
@@ -1,445 +0,0 @@
1
- import { e as JsonObject, J as Json, B as BaseUserMeta, g as Lson, h as LsonObject, c as LiveObject, S as StorageUpdate } from './index-2601cea5.js';
2
- export { j as LiveNode, k as Resolve, l as RoomInitializers, m as ToImmutable, T as ToJson, W as WebsocketCloseCodes, i as asArrayWithLegacyMethods, n as isJsonArray, o as isJsonObject, p as isJsonScalar } from './index-2601cea5.js';
3
-
4
- declare enum OpCode {
5
- INIT = 0,
6
- SET_PARENT_KEY = 1,
7
- CREATE_LIST = 2,
8
- UPDATE_OBJECT = 3,
9
- CREATE_OBJECT = 4,
10
- DELETE_CRDT = 5,
11
- DELETE_OBJECT_KEY = 6,
12
- CREATE_MAP = 7,
13
- CREATE_REGISTER = 8
14
- }
15
- /**
16
- * These operations are the payload for {@link UpdateStorageServerMsg} messages
17
- * only.
18
- */
19
- declare type Op = CreateOp | UpdateObjectOp | DeleteCrdtOp | SetParentKeyOp | DeleteObjectKeyOp;
20
- declare type CreateOp = CreateRootObjectOp | CreateChildOp;
21
- declare type CreateChildOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp;
22
- declare type UpdateObjectOp = {
23
- opId?: string;
24
- id: string;
25
- type: OpCode.UPDATE_OBJECT;
26
- data: Partial<JsonObject>;
27
- };
28
- declare type CreateObjectOp = {
29
- opId?: string;
30
- id: string;
31
- intent?: "set";
32
- deletedId?: string;
33
- type: OpCode.CREATE_OBJECT;
34
- parentId: string;
35
- parentKey: string;
36
- data: JsonObject;
37
- };
38
- declare type CreateRootObjectOp = {
39
- opId?: string;
40
- id: string;
41
- type: OpCode.CREATE_OBJECT;
42
- data: JsonObject;
43
- parentId?: never;
44
- parentKey?: never;
45
- };
46
- declare type CreateListOp = {
47
- opId?: string;
48
- id: string;
49
- intent?: "set";
50
- deletedId?: string;
51
- type: OpCode.CREATE_LIST;
52
- parentId: string;
53
- parentKey: string;
54
- };
55
- declare type CreateMapOp = {
56
- opId?: string;
57
- id: string;
58
- intent?: "set";
59
- deletedId?: string;
60
- type: OpCode.CREATE_MAP;
61
- parentId: string;
62
- parentKey: string;
63
- };
64
- declare type CreateRegisterOp = {
65
- opId?: string;
66
- id: string;
67
- intent?: "set";
68
- deletedId?: string;
69
- type: OpCode.CREATE_REGISTER;
70
- parentId: string;
71
- parentKey: string;
72
- data: Json;
73
- };
74
- declare type DeleteCrdtOp = {
75
- opId?: string;
76
- id: string;
77
- type: OpCode.DELETE_CRDT;
78
- };
79
- declare type SetParentKeyOp = {
80
- opId?: string;
81
- id: string;
82
- type: OpCode.SET_PARENT_KEY;
83
- parentKey: string;
84
- };
85
- declare type DeleteObjectKeyOp = {
86
- opId?: string;
87
- id: string;
88
- type: OpCode.DELETE_OBJECT_KEY;
89
- key: string;
90
- };
91
-
92
- declare enum ClientMsgCode {
93
- UPDATE_PRESENCE = 100,
94
- BROADCAST_EVENT = 103,
95
- FETCH_STORAGE = 200,
96
- UPDATE_STORAGE = 201
97
- }
98
- /**
99
- * Messages that can be sent from the client to the server.
100
- */
101
- declare type ClientMsg<TPresence extends JsonObject, TRoomEvent extends Json> = BroadcastEventClientMsg<TRoomEvent> | UpdatePresenceClientMsg<TPresence> | UpdateStorageClientMsg | FetchStorageClientMsg;
102
- declare type BroadcastEventClientMsg<TRoomEvent extends Json> = {
103
- type: ClientMsgCode.BROADCAST_EVENT;
104
- event: TRoomEvent;
105
- };
106
- declare type UpdatePresenceClientMsg<TPresence extends JsonObject> = {
107
- type: ClientMsgCode.UPDATE_PRESENCE;
108
- /**
109
- * Set this to any number to signify that this is a Full Presence™
110
- * update, not a patch.
111
- *
112
- * The numeric value itself no longer has specific meaning. Historically,
113
- * this field was intended so that clients could ignore these broadcasted
114
- * full presence messages, but it turned out that getting a full presence
115
- * "keyframe" from time to time was useful.
116
- *
117
- * So nowadays, the presence (pun intended) of this `targetActor` field
118
- * is a backward-compatible way of expressing that the `data` contains
119
- * all presence fields, and isn't a partial "patch".
120
- */
121
- targetActor: number;
122
- data: TPresence;
123
- } | {
124
- type: ClientMsgCode.UPDATE_PRESENCE;
125
- /**
126
- * Absence of the `targetActor` field signifies that this is a Partial
127
- * Presence™ "patch".
128
- */
129
- targetActor?: undefined;
130
- data: Partial<TPresence>;
131
- };
132
- declare type UpdateStorageClientMsg = {
133
- type: ClientMsgCode.UPDATE_STORAGE;
134
- ops: Op[];
135
- };
136
- declare type FetchStorageClientMsg = {
137
- type: ClientMsgCode.FETCH_STORAGE;
138
- };
139
-
140
- declare type IdTuple<T> = [id: string, value: T];
141
- declare enum CrdtType {
142
- OBJECT = 0,
143
- LIST = 1,
144
- MAP = 2,
145
- REGISTER = 3
146
- }
147
- declare type SerializedCrdt = SerializedRootObject | SerializedChild;
148
- declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister;
149
- declare type SerializedRootObject = {
150
- type: CrdtType.OBJECT;
151
- data: JsonObject;
152
- parentId?: never;
153
- parentKey?: never;
154
- };
155
- declare type SerializedObject = {
156
- type: CrdtType.OBJECT;
157
- parentId: string;
158
- parentKey: string;
159
- data: JsonObject;
160
- };
161
- declare type SerializedList = {
162
- type: CrdtType.LIST;
163
- parentId: string;
164
- parentKey: string;
165
- };
166
- declare type SerializedMap = {
167
- type: CrdtType.MAP;
168
- parentId: string;
169
- parentKey: string;
170
- };
171
- declare type SerializedRegister = {
172
- type: CrdtType.REGISTER;
173
- parentId: string;
174
- parentKey: string;
175
- data: Json;
176
- };
177
- declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject;
178
- declare function isChildCrdt(crdt: SerializedCrdt): crdt is SerializedChild;
179
-
180
- /**
181
- * Lookup table for nodes (= SerializedCrdt values) by their IDs.
182
- */
183
- declare type NodeMap = Map<string, // Node ID
184
- SerializedCrdt>;
185
- /**
186
- * Reverse lookup table for all child nodes (= list of SerializedCrdt values)
187
- * by their parent node's IDs.
188
- */
189
- declare type ParentToChildNodeMap = Map<string, // Parent's node ID
190
- IdTuple<SerializedChild>[]>;
191
-
192
- declare enum ServerMsgCode {
193
- UPDATE_PRESENCE = 100,
194
- USER_JOINED = 101,
195
- USER_LEFT = 102,
196
- BROADCASTED_EVENT = 103,
197
- ROOM_STATE = 104,
198
- INITIAL_STORAGE_STATE = 200,
199
- UPDATE_STORAGE = 201
200
- }
201
- /**
202
- * Messages that can be sent from the server to the client.
203
- */
204
- declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg;
205
- /**
206
- * Sent by the WebSocket server and broadcasted to all clients to announce that
207
- * a User updated their presence. For example, when a user moves their cursor.
208
- *
209
- * In most cases, the data payload will only include the fields from the
210
- * Presence that have been changed since the last announcement. However, after
211
- * a new user joins a room, a "full presence" will be announced so the newly
212
- * connected user will get each other's user full presence at least once. In
213
- * those cases, the `targetActor` field indicates the newly connected client,
214
- * so all other existing clients can ignore this broadcasted message.
215
- */
216
- declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = {
217
- type: ServerMsgCode.UPDATE_PRESENCE;
218
- /**
219
- * The User whose Presence has changed.
220
- */
221
- actor: number;
222
- /**
223
- * When set, signifies that this is a Full Presence™ update, not a patch.
224
- *
225
- * The numeric value itself no longer has specific meaning. Historically,
226
- * this field was intended so that clients could ignore these broadcasted
227
- * full presence messages, but it turned out that getting a full presence
228
- * "keyframe" from time to time was useful.
229
- *
230
- * So nowadays, the presence (pun intended) of this `targetActor` field
231
- * is a backward-compatible way of expressing that the `data` contains
232
- * all presence fields, and isn't a partial "patch".
233
- */
234
- targetActor: number;
235
- /**
236
- * The partial or full Presence of a User. If the `targetActor` field is set,
237
- * this will be the full Presence, otherwise it only contain the fields that
238
- * have changed since the last broadcast.
239
- */
240
- data: TPresence;
241
- } | {
242
- type: ServerMsgCode.UPDATE_PRESENCE;
243
- /**
244
- * The User whose Presence has changed.
245
- */
246
- actor: number;
247
- /**
248
- * Not set for partial presence updates.
249
- */
250
- targetActor?: undefined;
251
- /**
252
- * A partial Presence patch to apply to the User. It will only contain the
253
- * fields that have changed since the last broadcast.
254
- */
255
- data: Partial<TPresence>;
256
- };
257
- /**
258
- * Sent by the WebSocket server and broadcasted to all clients to announce that
259
- * a new User has joined the Room.
260
- */
261
- declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
262
- type: ServerMsgCode.USER_JOINED;
263
- actor: number;
264
- /**
265
- * The id of the User that has been set in the authentication endpoint.
266
- * Useful to get additional information about the connected user.
267
- */
268
- id: TUserMeta["id"];
269
- /**
270
- * Additional user information that has been set in the authentication
271
- * endpoint.
272
- */
273
- info: TUserMeta["info"];
274
- };
275
- /**
276
- * Sent by the WebSocket server and broadcasted to all clients to announce that
277
- * a new User has left the Room.
278
- */
279
- declare type UserLeftServerMsg = {
280
- type: ServerMsgCode.USER_LEFT;
281
- actor: number;
282
- };
283
- /**
284
- * Sent by the WebSocket server and broadcasted to all clients to announce that
285
- * a User broadcasted an Event to everyone in the Room.
286
- */
287
- declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
288
- type: ServerMsgCode.BROADCASTED_EVENT;
289
- /**
290
- * The User who broadcasted the Event.
291
- */
292
- actor: number;
293
- /**
294
- * The arbitrary payload of the Event. This can be any JSON value. Clients
295
- * will have to manually verify/decode this event.
296
- */
297
- event: TRoomEvent;
298
- };
299
- /**
300
- * Sent by the WebSocket server to a single client in response to the client
301
- * joining the Room, to provide the initial state of the Room. The payload
302
- * includes a list of all other Users that already are in the Room.
303
- */
304
- declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
305
- type: ServerMsgCode.ROOM_STATE;
306
- users: {
307
- [actor: number]: TUserMeta;
308
- };
309
- };
310
- /**
311
- * Sent by the WebSocket server to a single client in response to the client
312
- * joining the Room, to provide the initial Storage state of the Room. The
313
- * payload includes the entire Storage document.
314
- */
315
- declare type InitialDocumentStateServerMsg = {
316
- type: ServerMsgCode.INITIAL_STORAGE_STATE;
317
- items: IdTuple<SerializedCrdt>[];
318
- };
319
- /**
320
- * Sent by the WebSocket server and broadcasted to all clients to announce that
321
- * a change occurred in the Storage document.
322
- *
323
- * The payload of this message contains a list of Ops (aka incremental
324
- * mutations to make to the initially loaded document).
325
- */
326
- declare type UpdateStorageServerMsg = {
327
- type: ServerMsgCode.UPDATE_STORAGE;
328
- ops: Op[];
329
- };
330
-
331
- /**
332
- * Helper function that can be used to implement exhaustive switch statements
333
- * with TypeScript. Example usage:
334
- *
335
- * type Fruit = "🍎" | "🍌";
336
- *
337
- * switch (fruit) {
338
- * case "🍎":
339
- * case "🍌":
340
- * return doSomething();
341
- *
342
- * default:
343
- * return assertNever(fruit, "Unknown fruit");
344
- * }
345
- *
346
- * If now the Fruit union is extended (i.e. add "🍒"), TypeScript will catch
347
- * this *statically*, rather than at runtime, and force you to handle the
348
- * 🍒 case.
349
- */
350
- declare function assertNever(_value: never, errmsg: string): never;
351
- /**
352
- * Asserts that a given value is non-nullable. This is similar to TypeScript's
353
- * `!` operator, but will throw an error at runtime (dev-mode only) indicating
354
- * an incorrect assumption.
355
- *
356
- * Instead of:
357
- *
358
- * foo!.bar
359
- *
360
- * Use:
361
- *
362
- * nn(foo).bar
363
- *
364
- */
365
- declare function nn<T>(value: T, errmsg?: string): NonNullable<T>;
366
-
367
- declare const SCOPES: readonly ["websocket:presence", "websocket:storage", "room:read", "room:write", "rooms:read", "rooms:write"];
368
- declare type Scope = typeof SCOPES[number];
369
- declare type AppOnlyAuthToken = {
370
- appId: string;
371
- roomId?: never;
372
- scopes: string[];
373
- };
374
- declare type RoomAuthToken = {
375
- appId: string;
376
- roomId: string;
377
- scopes: string[];
378
- actor: number;
379
- maxConnectionsPerRoom?: number;
380
- id?: string;
381
- info?: Json;
382
- };
383
- declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
384
- declare function isScope(value: unknown): value is Scope;
385
- declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
386
- declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
387
- declare function isAuthToken(data: JsonObject): data is AuthToken;
388
-
389
- /**
390
- * Tools to help with the controlled deprecation of public APIs.
391
- *
392
- * First warn, then error, then remove eventually.
393
- */
394
- /**
395
- * Displays a deprecation warning in the dev console. Only in dev mode, and
396
- * only once per message/key. In production, this is a no-op.
397
- */
398
- declare function deprecate(message: string, key?: string): void;
399
- /**
400
- * Conditionally displays a deprecation warning in the dev
401
- * console if the first argument is truthy. Only in dev mode, and
402
- * only once per message/key. In production, this is a no-op.
403
- */
404
- declare function deprecateIf(condition: unknown, message: string, key?: string): void;
405
- /**
406
- * Throws a deprecation error in the dev console.
407
- *
408
- * Only triggers in dev mode. In production, this is a no-op.
409
- */
410
- declare function throwUsageError(message: string): void;
411
- /**
412
- * Conditionally throws a usage error in the dev console if the first argument
413
- * is truthy. Use this to "escalate" usage patterns that in previous versions
414
- * we already warned about with deprecation warnings.
415
- *
416
- * Only has effect in dev mode. In production, this is a no-op.
417
- */
418
- declare function errorIf(condition: unknown, message: string): void;
419
-
420
- declare function lsonToJson(value: Lson): Json;
421
- declare function patchLiveObjectKey<O extends LsonObject, K extends keyof O, V extends Lson>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void;
422
- declare function legacy_patchImmutableObject<S extends JsonObject>(state: S, updates: StorageUpdate[]): S;
423
-
424
- declare function makePosition(before?: string, after?: string): string;
425
- declare function comparePosition(posA: string, posB: string): number;
426
-
427
- /**
428
- * Freezes the given argument, but only in development builds. In production
429
- * builds, this is a no-op for performance reasons.
430
- */
431
- declare const freeze: typeof Object.freeze;
432
- declare function isPlainObject(blob: unknown): blob is {
433
- [key: string]: unknown;
434
- };
435
- /**
436
- * Alternative to JSON.parse() that will not throw in production. If the passed
437
- * string cannot be parsed, this will return `undefined`.
438
- */
439
- declare function tryParseJson(rawMessage: string): Json | undefined;
440
- /**
441
- * Decode base64 string.
442
- */
443
- declare function b64decode(b64value: string): string;
444
-
445
- export { AppOnlyAuthToken, AuthToken, BroadcastEventClientMsg, BroadcastedEventServerMsg, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, IdTuple, InitialDocumentStateServerMsg, NodeMap, Op, OpCode, ParentToChildNodeMap, RoomAuthToken, RoomStateServerMsg, Scope, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UserJoinServerMsg, UserLeftServerMsg, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, freeze, isAppOnlyAuthToken, isAuthToken, isChildCrdt, isPlainObject, isRoomAuthToken, isRootCrdt, isScope, legacy_patchImmutableObject, lsonToJson, makePosition, nn, patchLiveObjectKey, throwUsageError, tryParseJson };