@liveblocks/core 1.2.0-comments4 → 1.2.0-comments6
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.mts +474 -488
- package/dist/index.d.ts +474 -488
- package/dist/index.js +210 -298
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +167 -255
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5,19 +5,6 @@
|
|
|
5
5
|
declare function detectDupes(pkgName: string, pkgVersion: string | false, // false if not built yet
|
|
6
6
|
pkgFormat: string | false): void;
|
|
7
7
|
|
|
8
|
-
declare type CustomAuthenticationResult = {
|
|
9
|
-
token: string;
|
|
10
|
-
error?: never;
|
|
11
|
-
} | {
|
|
12
|
-
token?: never;
|
|
13
|
-
error: "forbidden";
|
|
14
|
-
reason: string;
|
|
15
|
-
} | {
|
|
16
|
-
token?: never;
|
|
17
|
-
error: string;
|
|
18
|
-
reason: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
8
|
/**
|
|
22
9
|
* Represents an indefinitely deep arbitrary JSON data structure. There are
|
|
23
10
|
* four types that make up the Json family:
|
|
@@ -38,239 +25,6 @@ declare function isJsonScalar(data: Json): data is JsonScalar;
|
|
|
38
25
|
declare function isJsonArray(data: Json): data is JsonArray;
|
|
39
26
|
declare function isJsonObject(data: Json): data is JsonObject;
|
|
40
27
|
|
|
41
|
-
declare enum Permission {
|
|
42
|
-
Read = "room:read",
|
|
43
|
-
Write = "room:write",
|
|
44
|
-
PresenceWrite = "room:presence:write",
|
|
45
|
-
CommentsWrite = "comments:write",
|
|
46
|
-
CommentsRead = "comments:read"
|
|
47
|
-
}
|
|
48
|
-
declare type LiveblocksPermissions = Record<string, Permission[]>;
|
|
49
|
-
declare enum TokenKind {
|
|
50
|
-
SECRET_LEGACY = "sec-legacy",
|
|
51
|
-
ACCESS_TOKEN = "acc",
|
|
52
|
-
ID_TOKEN = "id"
|
|
53
|
-
}
|
|
54
|
-
declare type JwtMeta = {
|
|
55
|
-
iat: number;
|
|
56
|
-
exp: number;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Legacy Secret Token.
|
|
60
|
-
*/
|
|
61
|
-
declare type LegacySecretToken = {
|
|
62
|
-
k: TokenKind.SECRET_LEGACY;
|
|
63
|
-
roomId: string;
|
|
64
|
-
scopes: string[];
|
|
65
|
-
id?: string;
|
|
66
|
-
info?: Json;
|
|
67
|
-
[other: string]: Json | undefined;
|
|
68
|
-
} & JwtMeta;
|
|
69
|
-
/**
|
|
70
|
-
* New authorization Access Token.
|
|
71
|
-
*/
|
|
72
|
-
declare type AccessToken = {
|
|
73
|
-
k: TokenKind.ACCESS_TOKEN;
|
|
74
|
-
pid: string;
|
|
75
|
-
uid: string;
|
|
76
|
-
perms: LiveblocksPermissions;
|
|
77
|
-
ui?: Json;
|
|
78
|
-
} & JwtMeta;
|
|
79
|
-
/**
|
|
80
|
-
* New authorization ID Token.
|
|
81
|
-
*/
|
|
82
|
-
declare type IDToken = {
|
|
83
|
-
k: TokenKind.ID_TOKEN;
|
|
84
|
-
pid: string;
|
|
85
|
-
uid: string;
|
|
86
|
-
gids?: string[];
|
|
87
|
-
ui?: Json;
|
|
88
|
-
} & JwtMeta;
|
|
89
|
-
declare type AuthToken = AccessToken | IDToken | LegacySecretToken;
|
|
90
|
-
declare type ParsedAuthToken = {
|
|
91
|
-
readonly raw: string;
|
|
92
|
-
readonly parsed: AuthToken;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
declare type Callback<T> = (event: T) => void;
|
|
96
|
-
declare type UnsubscribeCallback = () => void;
|
|
97
|
-
declare type Observable<T> = {
|
|
98
|
-
/**
|
|
99
|
-
* Register a callback function to be called whenever the event source emits
|
|
100
|
-
* an event.
|
|
101
|
-
*/
|
|
102
|
-
subscribe(callback: Callback<T>): UnsubscribeCallback;
|
|
103
|
-
/**
|
|
104
|
-
* Register a one-time callback function to be called whenever the event
|
|
105
|
-
* source emits an event. After the event fires, the callback is
|
|
106
|
-
* auto-unsubscribed.
|
|
107
|
-
*/
|
|
108
|
-
subscribeOnce(callback: Callback<T>): UnsubscribeCallback;
|
|
109
|
-
/**
|
|
110
|
-
* Returns a promise that will resolve when an event is emitted by this
|
|
111
|
-
* event source. Optionally, specify a predicate that has to match. The first
|
|
112
|
-
* event matching that predicate will then resolve the promise.
|
|
113
|
-
*/
|
|
114
|
-
waitUntil(predicate?: (event: T) => boolean): Promise<T>;
|
|
115
|
-
};
|
|
116
|
-
declare type EventSource<T> = Observable<T> & {
|
|
117
|
-
/**
|
|
118
|
-
* Notify all subscribers about the event.
|
|
119
|
-
*/
|
|
120
|
-
notify(event: T): void;
|
|
121
|
-
/**
|
|
122
|
-
* Clear all registered event listeners. None of the registered functions
|
|
123
|
-
* will ever get called again. Be careful when using this API, because the
|
|
124
|
-
* subscribers may not have any idea they won't be notified anymore.
|
|
125
|
-
*/
|
|
126
|
-
clear(): void;
|
|
127
|
-
/**
|
|
128
|
-
* Returns the number of active subscribers.
|
|
129
|
-
*/
|
|
130
|
-
count(): number;
|
|
131
|
-
/**
|
|
132
|
-
* Pauses event delivery until unpaused. Any .notify() calls made while
|
|
133
|
-
* paused will get buffered into memory and emitted later.
|
|
134
|
-
*/
|
|
135
|
-
pause(): void;
|
|
136
|
-
/**
|
|
137
|
-
* Emits all in-memory buffered events, and unpauses. Any .notify() calls
|
|
138
|
-
* made after this will be synchronously delivered again.
|
|
139
|
-
*/
|
|
140
|
-
unpause(): void;
|
|
141
|
-
/**
|
|
142
|
-
* Observable instance, which can be used to subscribe to this event source
|
|
143
|
-
* in a readonly fashion. Safe to publicly expose.
|
|
144
|
-
*/
|
|
145
|
-
observable: Observable<T>;
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* makeEventSource allows you to generate a subscribe/notify pair of functions
|
|
149
|
-
* to make subscribing easy and to get notified about events.
|
|
150
|
-
*
|
|
151
|
-
* The events are anonymous, so you can use it to define events, like so:
|
|
152
|
-
*
|
|
153
|
-
* const event1 = makeEventSource();
|
|
154
|
-
* const event2 = makeEventSource();
|
|
155
|
-
*
|
|
156
|
-
* event1.subscribe(foo);
|
|
157
|
-
* event1.subscribe(bar);
|
|
158
|
-
* event2.subscribe(qux);
|
|
159
|
-
*
|
|
160
|
-
* // Unsubscription is pretty standard
|
|
161
|
-
* const unsub = event2.subscribe(foo);
|
|
162
|
-
* unsub();
|
|
163
|
-
*
|
|
164
|
-
* event1.notify(); // Now foo and bar will get called
|
|
165
|
-
* event2.notify(); // Now qux will get called (but foo will not, since it's unsubscribed)
|
|
166
|
-
*
|
|
167
|
-
*/
|
|
168
|
-
declare function makeEventSource<T>(): EventSource<T>;
|
|
169
|
-
|
|
170
|
-
interface IWebSocketEvent {
|
|
171
|
-
type: string;
|
|
172
|
-
}
|
|
173
|
-
interface IWebSocketCloseEvent extends IWebSocketEvent {
|
|
174
|
-
readonly code: number;
|
|
175
|
-
readonly wasClean: boolean;
|
|
176
|
-
readonly reason: string;
|
|
177
|
-
}
|
|
178
|
-
interface IWebSocketMessageEvent extends IWebSocketEvent {
|
|
179
|
-
readonly data: string | Buffer | ArrayBuffer | readonly Buffer[];
|
|
180
|
-
}
|
|
181
|
-
interface IWebSocketInstance {
|
|
182
|
-
readonly CONNECTING: number;
|
|
183
|
-
readonly OPEN: number;
|
|
184
|
-
readonly CLOSING: number;
|
|
185
|
-
readonly CLOSED: number;
|
|
186
|
-
readonly readyState: number;
|
|
187
|
-
addEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
|
|
188
|
-
addEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
|
|
189
|
-
addEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
|
|
190
|
-
removeEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
|
|
191
|
-
removeEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
|
|
192
|
-
removeEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
|
|
193
|
-
close(): void;
|
|
194
|
-
send(data: string): void;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Either the browser-based WebSocket API or Node.js' WebSocket API (from the
|
|
198
|
-
* 'ws' package).
|
|
199
|
-
*
|
|
200
|
-
* This type defines the minimal WebSocket API that Liveblocks needs from
|
|
201
|
-
* a WebSocket implementation, and is a minimal subset of the browser-based
|
|
202
|
-
* WebSocket APIs and Node.js' WebSocket API so that both implementations are
|
|
203
|
-
* assignable to this type.
|
|
204
|
-
*/
|
|
205
|
-
interface IWebSocket {
|
|
206
|
-
new (address: string): IWebSocketInstance;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* The following ranges will be respected by the client:
|
|
210
|
-
*
|
|
211
|
-
* 40xx: client will disconnect
|
|
212
|
-
* 41xx: client will reauthorize
|
|
213
|
-
* 42xx: client will retry without reauthorizing (currently not used)
|
|
214
|
-
*
|
|
215
|
-
*/
|
|
216
|
-
declare enum WebsocketCloseCodes {
|
|
217
|
-
/** Unexpected error happened with the network/infra level. In spirit akin to HTTP 503 */
|
|
218
|
-
CLOSE_ABNORMAL = 1006,
|
|
219
|
-
/** Unexpected error happened. In spirit akin to HTTP 500 */
|
|
220
|
-
UNEXPECTED_CONDITION = 1011,
|
|
221
|
-
/** Please back off for now, but try again in a few moments */
|
|
222
|
-
TRY_AGAIN_LATER = 1013,
|
|
223
|
-
/** Message wasn't understood, disconnect */
|
|
224
|
-
INVALID_MESSAGE_FORMAT = 4000,
|
|
225
|
-
/** Server refused to allow connection. Re-authorizing won't help. Disconnect. In spirit akin to HTTP 403 */
|
|
226
|
-
NOT_ALLOWED = 4001,
|
|
227
|
-
/** Unused */
|
|
228
|
-
MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
|
|
229
|
-
/** Unused */
|
|
230
|
-
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
|
|
231
|
-
/** Unused */
|
|
232
|
-
MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
|
|
233
|
-
/** Room is full, disconnect */
|
|
234
|
-
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
|
|
235
|
-
/** The auth token is expired, reauthorize to get a fresh one. In spirit akin to HTTP 401 */
|
|
236
|
-
TOKEN_EXPIRED = 4109,
|
|
237
|
-
/** Disconnect immediately */
|
|
238
|
-
CLOSE_WITHOUT_RETRY = 4999
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Old connection statuses, here for backward-compatibility reasons only.
|
|
243
|
-
*/
|
|
244
|
-
declare type LegacyConnectionStatus = "closed" | "authenticating" | "connecting" | "open" | "unavailable" | "failed";
|
|
245
|
-
/**
|
|
246
|
-
* Returns a human-readable status indicating the current connection status of
|
|
247
|
-
* a Room, as returned by `room.getStatus()`. Can be used to implement
|
|
248
|
-
* a connection status badge.
|
|
249
|
-
*/
|
|
250
|
-
declare type Status = "initial" | "connecting" | "connected" | "reconnecting" | "disconnected";
|
|
251
|
-
/**
|
|
252
|
-
* Used to report about app-level reconnection issues.
|
|
253
|
-
*
|
|
254
|
-
* Normal (quick) reconnects won't be reported as a "lost connection". Instead,
|
|
255
|
-
* the application will only get an event if the reconnection attempts by the
|
|
256
|
-
* client are taking (much) longer than usual. Definitely a situation you want
|
|
257
|
-
* to inform your users about, for example, by throwing a toast message on
|
|
258
|
-
* screen, or show a "trying to reconnect" banner.
|
|
259
|
-
*/
|
|
260
|
-
declare type LostConnectionEvent = "lost" | "restored" | "failed";
|
|
261
|
-
/**
|
|
262
|
-
* Arbitrary record that will be used as the authentication "authValue". It's the
|
|
263
|
-
* value that is returned by calling the authentication delegate, and will get
|
|
264
|
-
* passed to the connection factory delegate. This value will be remembered by
|
|
265
|
-
* the connection manager, but its value will not be interpreted, so it can be
|
|
266
|
-
* any value (except null).
|
|
267
|
-
*/
|
|
268
|
-
declare type BaseAuthResult = NonNullable<Json>;
|
|
269
|
-
declare type Delegates<T extends BaseAuthResult> = {
|
|
270
|
-
authenticate: () => Promise<T>;
|
|
271
|
-
createSocket: (authValue: T) => IWebSocketInstance;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
28
|
declare enum OpCode {
|
|
275
29
|
INIT = 0,
|
|
276
30
|
SET_PARENT_KEY = 1,
|
|
@@ -439,15 +193,64 @@ declare type PlainLsonList = {
|
|
|
439
193
|
};
|
|
440
194
|
declare type PlainLson = PlainLsonObject | PlainLsonMap | PlainLsonList | Json;
|
|
441
195
|
|
|
196
|
+
declare type LiveObjectUpdateDelta<O extends {
|
|
197
|
+
[key: string]: unknown;
|
|
198
|
+
}> = {
|
|
199
|
+
[K in keyof O]?: UpdateDelta | undefined;
|
|
200
|
+
};
|
|
442
201
|
/**
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
202
|
+
* A LiveObject notification that is sent in-client to any subscribers whenever
|
|
203
|
+
* one or more of the entries inside the LiveObject instance have changed.
|
|
204
|
+
*/
|
|
205
|
+
declare type LiveObjectUpdates<TData extends LsonObject> = {
|
|
206
|
+
type: "LiveObject";
|
|
207
|
+
node: LiveObject<TData>;
|
|
208
|
+
updates: LiveObjectUpdateDelta<TData>;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
|
|
212
|
+
* Keys should be a string, and values should be serializable to JSON.
|
|
213
|
+
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
|
|
214
|
+
*/
|
|
215
|
+
declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
|
|
216
|
+
constructor(obj?: O);
|
|
217
|
+
/**
|
|
218
|
+
* Transform the LiveObject into a javascript object
|
|
219
|
+
*/
|
|
220
|
+
toObject(): O;
|
|
221
|
+
/**
|
|
222
|
+
* Adds or updates a property with a specified key and a value.
|
|
223
|
+
* @param key The key of the property to add
|
|
224
|
+
* @param value The value of the property to add
|
|
225
|
+
*/
|
|
226
|
+
set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
|
|
227
|
+
/**
|
|
228
|
+
* Returns a specified property from the LiveObject.
|
|
229
|
+
* @param key The key of the property to get
|
|
230
|
+
*/
|
|
231
|
+
get<TKey extends keyof O>(key: TKey): O[TKey];
|
|
232
|
+
/**
|
|
233
|
+
* Deletes a key from the LiveObject
|
|
234
|
+
* @param key The key of the property to delete
|
|
235
|
+
*/
|
|
236
|
+
delete(key: keyof O): void;
|
|
237
|
+
/**
|
|
238
|
+
* Adds or updates multiple properties at once with an object.
|
|
239
|
+
* @param patch The object used to overrides properties
|
|
240
|
+
*/
|
|
241
|
+
update(patch: Partial<O>): void;
|
|
242
|
+
toImmutable(): ToImmutable<O>;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Helper type to convert any valid Lson type to the equivalent Json type.
|
|
247
|
+
*
|
|
248
|
+
* Examples:
|
|
249
|
+
*
|
|
250
|
+
* ToImmutable<42> // 42
|
|
251
|
+
* ToImmutable<'hi'> // 'hi'
|
|
252
|
+
* ToImmutable<number> // number
|
|
253
|
+
* ToImmutable<string> // string
|
|
451
254
|
* ToImmutable<string | LiveList<number>> // string | readonly number[]
|
|
452
255
|
* ToImmutable<LiveMap<string, LiveList<number>>>
|
|
453
256
|
* // ReadonlyMap<string, readonly number[]>
|
|
@@ -722,100 +525,395 @@ declare type LsonObject = {
|
|
|
722
525
|
* // { a: null, b: string[], c?: number }
|
|
723
526
|
*
|
|
724
527
|
*/
|
|
725
|
-
declare type ToJson<T extends Lson | LsonObject> = T extends Json ? T : T extends LsonObject ? {
|
|
726
|
-
[K in keyof T]: ToJson<Exclude<T[K], undefined>> | (undefined extends T[K] ? undefined : never);
|
|
727
|
-
} : T extends LiveList<infer I> ? ToJson<I>[] : T extends LiveObject<infer O> ? ToJson<O> : T extends LiveMap<infer KS, infer V> ? {
|
|
728
|
-
[K in KS]: ToJson<V>;
|
|
729
|
-
} : never;
|
|
528
|
+
declare type ToJson<T extends Lson | LsonObject> = T extends Json ? T : T extends LsonObject ? {
|
|
529
|
+
[K in keyof T]: ToJson<Exclude<T[K], undefined>> | (undefined extends T[K] ? undefined : never);
|
|
530
|
+
} : T extends LiveList<infer I> ? ToJson<I>[] : T extends LiveObject<infer O> ? ToJson<O> : T extends LiveMap<infer KS, infer V> ? {
|
|
531
|
+
[K in KS]: ToJson<V>;
|
|
532
|
+
} : never;
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* This helper type is effectively a no-op, but will force TypeScript to
|
|
536
|
+
* "evaluate" any named helper types in its definition. This can sometimes make
|
|
537
|
+
* API signatures clearer in IDEs.
|
|
538
|
+
*
|
|
539
|
+
* For example, in:
|
|
540
|
+
*
|
|
541
|
+
* type Payload<T> = { data: T };
|
|
542
|
+
*
|
|
543
|
+
* let r1: Payload<string>;
|
|
544
|
+
* let r2: Resolve<Payload<string>>;
|
|
545
|
+
*
|
|
546
|
+
* The inferred type of `r1` is going to be `Payload<string>` which shows up in
|
|
547
|
+
* editor hints, and it may be unclear what's inside if you don't know the
|
|
548
|
+
* definition of `Payload`.
|
|
549
|
+
*
|
|
550
|
+
* The inferred type of `r2` is going to be `{ data: string }`, which may be
|
|
551
|
+
* more helpful.
|
|
552
|
+
*
|
|
553
|
+
* This trick comes from:
|
|
554
|
+
* https://effectivetypescript.com/2022/02/25/gentips-4-display/
|
|
555
|
+
*/
|
|
556
|
+
declare type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
|
|
557
|
+
[K in keyof T]: T[K];
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
declare type CustomAuthenticationResult = {
|
|
561
|
+
token: string;
|
|
562
|
+
error?: never;
|
|
563
|
+
} | {
|
|
564
|
+
token?: never;
|
|
565
|
+
error: "forbidden";
|
|
566
|
+
reason: string;
|
|
567
|
+
} | {
|
|
568
|
+
token?: never;
|
|
569
|
+
error: string;
|
|
570
|
+
reason: string;
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
declare type BaseUserInfo = {
|
|
574
|
+
[key: string]: Json | undefined;
|
|
575
|
+
name?: string;
|
|
576
|
+
avatar?: string;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* This type is used by clients to define the metadata for a user.
|
|
580
|
+
*/
|
|
581
|
+
declare type BaseUserMeta = {
|
|
582
|
+
/**
|
|
583
|
+
* The id of the user that has been set in the authentication endpoint.
|
|
584
|
+
* Useful to get additional information about the connected user.
|
|
585
|
+
*/
|
|
586
|
+
id?: string;
|
|
587
|
+
/**
|
|
588
|
+
* Additional user information that has been set in the authentication endpoint.
|
|
589
|
+
*/
|
|
590
|
+
info?: BaseUserInfo;
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
declare enum Permission {
|
|
594
|
+
Read = "room:read",
|
|
595
|
+
Write = "room:write",
|
|
596
|
+
PresenceWrite = "room:presence:write",
|
|
597
|
+
CommentsWrite = "comments:write",
|
|
598
|
+
CommentsRead = "comments:read"
|
|
599
|
+
}
|
|
600
|
+
declare type LiveblocksPermissions = Record<string, Permission[]>;
|
|
601
|
+
declare enum TokenKind {
|
|
602
|
+
SECRET_LEGACY = "sec-legacy",
|
|
603
|
+
ACCESS_TOKEN = "acc",
|
|
604
|
+
ID_TOKEN = "id"
|
|
605
|
+
}
|
|
606
|
+
declare type JwtMeta = {
|
|
607
|
+
iat: number;
|
|
608
|
+
exp: number;
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* Legacy Secret Token.
|
|
612
|
+
*/
|
|
613
|
+
declare type LegacySecretToken = {
|
|
614
|
+
k: TokenKind.SECRET_LEGACY;
|
|
615
|
+
roomId: string;
|
|
616
|
+
scopes: string[];
|
|
617
|
+
id?: string;
|
|
618
|
+
info?: BaseUserInfo;
|
|
619
|
+
[other: string]: Json | undefined;
|
|
620
|
+
} & JwtMeta;
|
|
621
|
+
/**
|
|
622
|
+
* New authorization Access Token.
|
|
623
|
+
*/
|
|
624
|
+
declare type AccessToken = {
|
|
625
|
+
k: TokenKind.ACCESS_TOKEN;
|
|
626
|
+
pid: string;
|
|
627
|
+
uid: string;
|
|
628
|
+
perms: LiveblocksPermissions;
|
|
629
|
+
ui?: BaseUserInfo;
|
|
630
|
+
} & JwtMeta;
|
|
631
|
+
/**
|
|
632
|
+
* New authorization ID Token.
|
|
633
|
+
*/
|
|
634
|
+
declare type IDToken = {
|
|
635
|
+
k: TokenKind.ID_TOKEN;
|
|
636
|
+
pid: string;
|
|
637
|
+
uid: string;
|
|
638
|
+
gids?: string[];
|
|
639
|
+
ui?: BaseUserInfo;
|
|
640
|
+
} & JwtMeta;
|
|
641
|
+
declare type AuthToken = AccessToken | IDToken | LegacySecretToken;
|
|
642
|
+
declare type ParsedAuthToken = {
|
|
643
|
+
readonly raw: string;
|
|
644
|
+
readonly parsed: AuthToken;
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
declare type AuthValue = {
|
|
648
|
+
type: "secret";
|
|
649
|
+
token: ParsedAuthToken;
|
|
650
|
+
} | {
|
|
651
|
+
type: "public";
|
|
652
|
+
publicApiKey: string;
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
declare type BaseMetadata = Record<string, string | boolean | number>;
|
|
656
|
+
|
|
657
|
+
declare type CommentBodyBlockElement = CommentBodyParagraph;
|
|
658
|
+
declare type CommentBodyInlineElement = CommentBodyText | CommentBodyMention;
|
|
659
|
+
declare type CommentBodyElement = CommentBodyBlockElement | CommentBodyInlineElement;
|
|
660
|
+
declare type CommentBodyParagraph = {
|
|
661
|
+
type: "paragraph";
|
|
662
|
+
children: CommentBodyInlineElement[];
|
|
663
|
+
};
|
|
664
|
+
declare type CommentBodyMention = {
|
|
665
|
+
type: "mention";
|
|
666
|
+
id: string;
|
|
667
|
+
};
|
|
668
|
+
declare type CommentBodyText = {
|
|
669
|
+
bold?: boolean;
|
|
670
|
+
italic?: boolean;
|
|
671
|
+
strikethrough?: boolean;
|
|
672
|
+
code?: boolean;
|
|
673
|
+
text: string;
|
|
674
|
+
};
|
|
675
|
+
declare type CommentBody = {
|
|
676
|
+
version: 1;
|
|
677
|
+
content: CommentBodyBlockElement[];
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
declare type CommentData = {
|
|
681
|
+
type: "comment";
|
|
682
|
+
id: string;
|
|
683
|
+
threadId: string;
|
|
684
|
+
roomId: string;
|
|
685
|
+
userId: string;
|
|
686
|
+
createdAt: string;
|
|
687
|
+
editedAt?: string;
|
|
688
|
+
} & ({
|
|
689
|
+
body: CommentBody;
|
|
690
|
+
mentionedIds: string[];
|
|
691
|
+
deletedAt?: never;
|
|
692
|
+
} | {
|
|
693
|
+
body?: never;
|
|
694
|
+
mentionedIds: [];
|
|
695
|
+
deletedAt: string;
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
declare type ThreadData<ThreadMetadata extends BaseMetadata = never> = {
|
|
699
|
+
type: "thread";
|
|
700
|
+
id: string;
|
|
701
|
+
roomId: string;
|
|
702
|
+
createdAt: string;
|
|
703
|
+
updatedAt?: string;
|
|
704
|
+
comments: CommentData[];
|
|
705
|
+
metadata: [ThreadMetadata] extends [never] ? Record<string, never> : ThreadMetadata;
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
declare type Options = {
|
|
709
|
+
serverEndpoint: string;
|
|
710
|
+
};
|
|
711
|
+
declare type CommentsApi<ThreadMetadata extends BaseMetadata> = {
|
|
712
|
+
getThreads(): Promise<ThreadData<ThreadMetadata>[]>;
|
|
713
|
+
createThread(options: {
|
|
714
|
+
threadId: string;
|
|
715
|
+
commentId: string;
|
|
716
|
+
metadata: ThreadMetadata | undefined;
|
|
717
|
+
body: CommentBody;
|
|
718
|
+
}): Promise<ThreadData<ThreadMetadata>>;
|
|
719
|
+
editThreadMetadata(options: {
|
|
720
|
+
metadata: Partial<ThreadMetadata>;
|
|
721
|
+
threadId: string;
|
|
722
|
+
}): Promise<ThreadData<ThreadMetadata>>;
|
|
723
|
+
createComment(options: {
|
|
724
|
+
threadId: string;
|
|
725
|
+
commentId: string;
|
|
726
|
+
body: CommentBody;
|
|
727
|
+
}): Promise<CommentData>;
|
|
728
|
+
editComment(options: {
|
|
729
|
+
threadId: string;
|
|
730
|
+
commentId: string;
|
|
731
|
+
body: CommentBody;
|
|
732
|
+
}): Promise<CommentData>;
|
|
733
|
+
deleteComment(options: {
|
|
734
|
+
threadId: string;
|
|
735
|
+
commentId: string;
|
|
736
|
+
}): Promise<void>;
|
|
737
|
+
};
|
|
738
|
+
declare function createCommentsApi<ThreadMetadata extends BaseMetadata>(roomId: string, getAuthValue: () => Promise<AuthValue>, { serverEndpoint }: Options): CommentsApi<ThreadMetadata>;
|
|
739
|
+
|
|
740
|
+
declare type Callback<T> = (event: T) => void;
|
|
741
|
+
declare type UnsubscribeCallback = () => void;
|
|
742
|
+
declare type Observable<T> = {
|
|
743
|
+
/**
|
|
744
|
+
* Register a callback function to be called whenever the event source emits
|
|
745
|
+
* an event.
|
|
746
|
+
*/
|
|
747
|
+
subscribe(callback: Callback<T>): UnsubscribeCallback;
|
|
748
|
+
/**
|
|
749
|
+
* Register a one-time callback function to be called whenever the event
|
|
750
|
+
* source emits an event. After the event fires, the callback is
|
|
751
|
+
* auto-unsubscribed.
|
|
752
|
+
*/
|
|
753
|
+
subscribeOnce(callback: Callback<T>): UnsubscribeCallback;
|
|
754
|
+
/**
|
|
755
|
+
* Returns a promise that will resolve when an event is emitted by this
|
|
756
|
+
* event source. Optionally, specify a predicate that has to match. The first
|
|
757
|
+
* event matching that predicate will then resolve the promise.
|
|
758
|
+
*/
|
|
759
|
+
waitUntil(predicate?: (event: T) => boolean): Promise<T>;
|
|
760
|
+
};
|
|
761
|
+
declare type EventSource<T> = Observable<T> & {
|
|
762
|
+
/**
|
|
763
|
+
* Notify all subscribers about the event.
|
|
764
|
+
*/
|
|
765
|
+
notify(event: T): void;
|
|
766
|
+
/**
|
|
767
|
+
* Clear all registered event listeners. None of the registered functions
|
|
768
|
+
* will ever get called again. Be careful when using this API, because the
|
|
769
|
+
* subscribers may not have any idea they won't be notified anymore.
|
|
770
|
+
*/
|
|
771
|
+
clear(): void;
|
|
772
|
+
/**
|
|
773
|
+
* Returns the number of active subscribers.
|
|
774
|
+
*/
|
|
775
|
+
count(): number;
|
|
776
|
+
/**
|
|
777
|
+
* Pauses event delivery until unpaused. Any .notify() calls made while
|
|
778
|
+
* paused will get buffered into memory and emitted later.
|
|
779
|
+
*/
|
|
780
|
+
pause(): void;
|
|
781
|
+
/**
|
|
782
|
+
* Emits all in-memory buffered events, and unpauses. Any .notify() calls
|
|
783
|
+
* made after this will be synchronously delivered again.
|
|
784
|
+
*/
|
|
785
|
+
unpause(): void;
|
|
786
|
+
/**
|
|
787
|
+
* Observable instance, which can be used to subscribe to this event source
|
|
788
|
+
* in a readonly fashion. Safe to publicly expose.
|
|
789
|
+
*/
|
|
790
|
+
observable: Observable<T>;
|
|
791
|
+
};
|
|
792
|
+
/**
|
|
793
|
+
* makeEventSource allows you to generate a subscribe/notify pair of functions
|
|
794
|
+
* to make subscribing easy and to get notified about events.
|
|
795
|
+
*
|
|
796
|
+
* The events are anonymous, so you can use it to define events, like so:
|
|
797
|
+
*
|
|
798
|
+
* const event1 = makeEventSource();
|
|
799
|
+
* const event2 = makeEventSource();
|
|
800
|
+
*
|
|
801
|
+
* event1.subscribe(foo);
|
|
802
|
+
* event1.subscribe(bar);
|
|
803
|
+
* event2.subscribe(qux);
|
|
804
|
+
*
|
|
805
|
+
* // Unsubscription is pretty standard
|
|
806
|
+
* const unsub = event2.subscribe(foo);
|
|
807
|
+
* unsub();
|
|
808
|
+
*
|
|
809
|
+
* event1.notify(); // Now foo and bar will get called
|
|
810
|
+
* event2.notify(); // Now qux will get called (but foo will not, since it's unsubscribed)
|
|
811
|
+
*
|
|
812
|
+
*/
|
|
813
|
+
declare function makeEventSource<T>(): EventSource<T>;
|
|
814
|
+
|
|
815
|
+
interface IWebSocketEvent {
|
|
816
|
+
type: string;
|
|
817
|
+
}
|
|
818
|
+
interface IWebSocketCloseEvent extends IWebSocketEvent {
|
|
819
|
+
readonly code: number;
|
|
820
|
+
readonly wasClean: boolean;
|
|
821
|
+
readonly reason: string;
|
|
822
|
+
}
|
|
823
|
+
interface IWebSocketMessageEvent extends IWebSocketEvent {
|
|
824
|
+
readonly data: string | Buffer | ArrayBuffer | readonly Buffer[];
|
|
825
|
+
}
|
|
826
|
+
interface IWebSocketInstance {
|
|
827
|
+
readonly CONNECTING: number;
|
|
828
|
+
readonly OPEN: number;
|
|
829
|
+
readonly CLOSING: number;
|
|
830
|
+
readonly CLOSED: number;
|
|
831
|
+
readonly readyState: number;
|
|
832
|
+
addEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
|
|
833
|
+
addEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
|
|
834
|
+
addEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
|
|
835
|
+
removeEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
|
|
836
|
+
removeEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
|
|
837
|
+
removeEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
|
|
838
|
+
close(): void;
|
|
839
|
+
send(data: string): void;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Either the browser-based WebSocket API or Node.js' WebSocket API (from the
|
|
843
|
+
* 'ws' package).
|
|
844
|
+
*
|
|
845
|
+
* This type defines the minimal WebSocket API that Liveblocks needs from
|
|
846
|
+
* a WebSocket implementation, and is a minimal subset of the browser-based
|
|
847
|
+
* WebSocket APIs and Node.js' WebSocket API so that both implementations are
|
|
848
|
+
* assignable to this type.
|
|
849
|
+
*/
|
|
850
|
+
interface IWebSocket {
|
|
851
|
+
new (address: string): IWebSocketInstance;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* The following ranges will be respected by the client:
|
|
855
|
+
*
|
|
856
|
+
* 40xx: client will disconnect
|
|
857
|
+
* 41xx: client will reauthorize
|
|
858
|
+
* 42xx: client will retry without reauthorizing (currently not used)
|
|
859
|
+
*
|
|
860
|
+
*/
|
|
861
|
+
declare enum WebsocketCloseCodes {
|
|
862
|
+
/** Unexpected error happened with the network/infra level. In spirit akin to HTTP 503 */
|
|
863
|
+
CLOSE_ABNORMAL = 1006,
|
|
864
|
+
/** Unexpected error happened. In spirit akin to HTTP 500 */
|
|
865
|
+
UNEXPECTED_CONDITION = 1011,
|
|
866
|
+
/** Please back off for now, but try again in a few moments */
|
|
867
|
+
TRY_AGAIN_LATER = 1013,
|
|
868
|
+
/** Message wasn't understood, disconnect */
|
|
869
|
+
INVALID_MESSAGE_FORMAT = 4000,
|
|
870
|
+
/** Server refused to allow connection. Re-authorizing won't help. Disconnect. In spirit akin to HTTP 403 */
|
|
871
|
+
NOT_ALLOWED = 4001,
|
|
872
|
+
/** Unused */
|
|
873
|
+
MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
|
|
874
|
+
/** Unused */
|
|
875
|
+
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
|
|
876
|
+
/** Unused */
|
|
877
|
+
MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
|
|
878
|
+
/** Room is full, disconnect */
|
|
879
|
+
MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
|
|
880
|
+
/** The auth token is expired, reauthorize to get a fresh one. In spirit akin to HTTP 401 */
|
|
881
|
+
TOKEN_EXPIRED = 4109,
|
|
882
|
+
/** Disconnect immediately */
|
|
883
|
+
CLOSE_WITHOUT_RETRY = 4999
|
|
884
|
+
}
|
|
730
885
|
|
|
731
|
-
declare type LiveObjectUpdateDelta<O extends {
|
|
732
|
-
[key: string]: unknown;
|
|
733
|
-
}> = {
|
|
734
|
-
[K in keyof O]?: UpdateDelta | undefined;
|
|
735
|
-
};
|
|
736
886
|
/**
|
|
737
|
-
*
|
|
738
|
-
* one or more of the entries inside the LiveObject instance have changed.
|
|
887
|
+
* Old connection statuses, here for backward-compatibility reasons only.
|
|
739
888
|
*/
|
|
740
|
-
declare type
|
|
741
|
-
type: "LiveObject";
|
|
742
|
-
node: LiveObject<TData>;
|
|
743
|
-
updates: LiveObjectUpdateDelta<TData>;
|
|
744
|
-
};
|
|
889
|
+
declare type LegacyConnectionStatus = "closed" | "authenticating" | "connecting" | "open" | "unavailable" | "failed";
|
|
745
890
|
/**
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
*
|
|
891
|
+
* Returns a human-readable status indicating the current connection status of
|
|
892
|
+
* a Room, as returned by `room.getStatus()`. Can be used to implement
|
|
893
|
+
* a connection status badge.
|
|
749
894
|
*/
|
|
750
|
-
declare
|
|
751
|
-
constructor(obj?: O);
|
|
752
|
-
/**
|
|
753
|
-
* Transform the LiveObject into a javascript object
|
|
754
|
-
*/
|
|
755
|
-
toObject(): O;
|
|
756
|
-
/**
|
|
757
|
-
* Adds or updates a property with a specified key and a value.
|
|
758
|
-
* @param key The key of the property to add
|
|
759
|
-
* @param value The value of the property to add
|
|
760
|
-
*/
|
|
761
|
-
set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
|
|
762
|
-
/**
|
|
763
|
-
* Returns a specified property from the LiveObject.
|
|
764
|
-
* @param key The key of the property to get
|
|
765
|
-
*/
|
|
766
|
-
get<TKey extends keyof O>(key: TKey): O[TKey];
|
|
767
|
-
/**
|
|
768
|
-
* Deletes a key from the LiveObject
|
|
769
|
-
* @param key The key of the property to delete
|
|
770
|
-
*/
|
|
771
|
-
delete(key: keyof O): void;
|
|
772
|
-
/**
|
|
773
|
-
* Adds or updates multiple properties at once with an object.
|
|
774
|
-
* @param patch The object used to overrides properties
|
|
775
|
-
*/
|
|
776
|
-
update(patch: Partial<O>): void;
|
|
777
|
-
toImmutable(): ToImmutable<O>;
|
|
778
|
-
}
|
|
779
|
-
|
|
895
|
+
declare type Status = "initial" | "connecting" | "connected" | "reconnecting" | "disconnected";
|
|
780
896
|
/**
|
|
781
|
-
*
|
|
782
|
-
* "evaluate" any named helper types in its definition. This can sometimes make
|
|
783
|
-
* API signatures clearer in IDEs.
|
|
784
|
-
*
|
|
785
|
-
* For example, in:
|
|
786
|
-
*
|
|
787
|
-
* type Payload<T> = { data: T };
|
|
788
|
-
*
|
|
789
|
-
* let r1: Payload<string>;
|
|
790
|
-
* let r2: Resolve<Payload<string>>;
|
|
791
|
-
*
|
|
792
|
-
* The inferred type of `r1` is going to be `Payload<string>` which shows up in
|
|
793
|
-
* editor hints, and it may be unclear what's inside if you don't know the
|
|
794
|
-
* definition of `Payload`.
|
|
795
|
-
*
|
|
796
|
-
* The inferred type of `r2` is going to be `{ data: string }`, which may be
|
|
797
|
-
* more helpful.
|
|
897
|
+
* Used to report about app-level reconnection issues.
|
|
798
898
|
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
899
|
+
* Normal (quick) reconnects won't be reported as a "lost connection". Instead,
|
|
900
|
+
* the application will only get an event if the reconnection attempts by the
|
|
901
|
+
* client are taking (much) longer than usual. Definitely a situation you want
|
|
902
|
+
* to inform your users about, for example, by throwing a toast message on
|
|
903
|
+
* screen, or show a "trying to reconnect" banner.
|
|
801
904
|
*/
|
|
802
|
-
declare type
|
|
803
|
-
[K in keyof T]: T[K];
|
|
804
|
-
};
|
|
805
|
-
|
|
905
|
+
declare type LostConnectionEvent = "lost" | "restored" | "failed";
|
|
806
906
|
/**
|
|
807
|
-
*
|
|
907
|
+
* Arbitrary record that will be used as the authentication "authValue". It's the
|
|
908
|
+
* value that is returned by calling the authentication delegate, and will get
|
|
909
|
+
* passed to the connection factory delegate. This value will be remembered by
|
|
910
|
+
* the connection manager, but its value will not be interpreted, so it can be
|
|
911
|
+
* any value (except null).
|
|
808
912
|
*/
|
|
809
|
-
declare type
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
*/
|
|
814
|
-
id?: string;
|
|
815
|
-
/**
|
|
816
|
-
* Additional user information that has been set in the authentication endpoint.
|
|
817
|
-
*/
|
|
818
|
-
info?: Json;
|
|
913
|
+
declare type BaseAuthResult = NonNullable<Json>;
|
|
914
|
+
declare type Delegates<T extends BaseAuthResult> = {
|
|
915
|
+
authenticate: () => Promise<T>;
|
|
916
|
+
createSocket: (authValue: T) => IWebSocketInstance;
|
|
819
917
|
};
|
|
820
918
|
|
|
821
919
|
declare type IdTuple<T> = [id: string, value: T];
|
|
@@ -867,12 +965,41 @@ declare enum ServerMsgCode {
|
|
|
867
965
|
INITIAL_STORAGE_STATE = 200,
|
|
868
966
|
UPDATE_STORAGE = 201,
|
|
869
967
|
REJECT_STORAGE_OP = 299,
|
|
870
|
-
UPDATE_YDOC = 300
|
|
968
|
+
UPDATE_YDOC = 300,
|
|
969
|
+
THREAD_CREATED = 400,
|
|
970
|
+
THREAD_METADATA_UPDATED = 401,
|
|
971
|
+
COMMENT_CREATED = 402,
|
|
972
|
+
COMMENT_EDITED = 403,
|
|
973
|
+
COMMENT_DELETED = 404
|
|
871
974
|
}
|
|
872
975
|
/**
|
|
873
976
|
* Messages that can be sent from the server to the client.
|
|
874
977
|
*/
|
|
875
|
-
declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg | RejectedStorageOpServerMsg | YDocUpdate;
|
|
978
|
+
declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg | RejectedStorageOpServerMsg | YDocUpdate | CommentsEventServerMsg;
|
|
979
|
+
declare type CommentsEventServerMsg = ThreadCreatedEvent | ThreadMetadataUpdatedEvent | CommentCreatedEvent | CommentEditedEvent | CommentDeletedEvent;
|
|
980
|
+
declare type ThreadCreatedEvent = {
|
|
981
|
+
type: ServerMsgCode.THREAD_CREATED;
|
|
982
|
+
threadId: string;
|
|
983
|
+
};
|
|
984
|
+
declare type ThreadMetadataUpdatedEvent = {
|
|
985
|
+
type: ServerMsgCode.THREAD_METADATA_UPDATED;
|
|
986
|
+
threadId: string;
|
|
987
|
+
};
|
|
988
|
+
declare type CommentCreatedEvent = {
|
|
989
|
+
type: ServerMsgCode.COMMENT_CREATED;
|
|
990
|
+
threadId: string;
|
|
991
|
+
commentId: string;
|
|
992
|
+
};
|
|
993
|
+
declare type CommentEditedEvent = {
|
|
994
|
+
type: ServerMsgCode.COMMENT_EDITED;
|
|
995
|
+
threadId: string;
|
|
996
|
+
commentId: string;
|
|
997
|
+
};
|
|
998
|
+
declare type CommentDeletedEvent = {
|
|
999
|
+
type: ServerMsgCode.COMMENT_DELETED;
|
|
1000
|
+
threadId: string;
|
|
1001
|
+
commentId: string;
|
|
1002
|
+
};
|
|
876
1003
|
/**
|
|
877
1004
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
878
1005
|
* a User updated their presence. For example, when a user moves their cursor.
|
|
@@ -1078,6 +1205,10 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
|
|
|
1078
1205
|
* can only read but not mutate it.
|
|
1079
1206
|
*/
|
|
1080
1207
|
readonly canWrite: boolean;
|
|
1208
|
+
/**
|
|
1209
|
+
* True if the user can comment on a thread
|
|
1210
|
+
*/
|
|
1211
|
+
readonly canComment: boolean;
|
|
1081
1212
|
};
|
|
1082
1213
|
|
|
1083
1214
|
/**
|
|
@@ -1345,7 +1476,7 @@ declare type SubscribeFn<TPresence extends JsonObject, _TStorage extends LsonObj
|
|
|
1345
1476
|
*/
|
|
1346
1477
|
(type: "storage-status", listener: Callback<StorageStatus>): () => void;
|
|
1347
1478
|
};
|
|
1348
|
-
declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = {
|
|
1479
|
+
declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = CommentsApi<any> & {
|
|
1349
1480
|
/**
|
|
1350
1481
|
* The id of the room.
|
|
1351
1482
|
*/
|
|
@@ -1490,6 +1621,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1490
1621
|
readonly storageDidLoad: Observable<void>;
|
|
1491
1622
|
readonly storageStatus: Observable<StorageStatus>;
|
|
1492
1623
|
readonly ydoc: Observable<YDocUpdate>;
|
|
1624
|
+
readonly comments: Observable<CommentsEventServerMsg>;
|
|
1493
1625
|
};
|
|
1494
1626
|
/**
|
|
1495
1627
|
* Batches modifications made during the given function.
|
|
@@ -1544,51 +1676,6 @@ declare type RoomInitializers<TPresence extends JsonObject, TStorage extends Lso
|
|
|
1544
1676
|
shouldInitiallyConnect?: boolean;
|
|
1545
1677
|
}>;
|
|
1546
1678
|
|
|
1547
|
-
declare type AuthValue = {
|
|
1548
|
-
type: "secret";
|
|
1549
|
-
token: ParsedAuthToken;
|
|
1550
|
-
} | {
|
|
1551
|
-
type: "public";
|
|
1552
|
-
publicApiKey: string;
|
|
1553
|
-
};
|
|
1554
|
-
declare type RequestedScope = "room:read" | "comments:read";
|
|
1555
|
-
declare type AuthManager = {
|
|
1556
|
-
getAuthValue(requestedScope: RequestedScope, roomId: string): Promise<AuthValue>;
|
|
1557
|
-
};
|
|
1558
|
-
|
|
1559
|
-
declare type BaseThreadRealtimeEvent = {
|
|
1560
|
-
roomId: string;
|
|
1561
|
-
threadId: string;
|
|
1562
|
-
};
|
|
1563
|
-
declare type BaseCommentRealtimeEvent = BaseThreadRealtimeEvent & {
|
|
1564
|
-
commentId: string;
|
|
1565
|
-
};
|
|
1566
|
-
declare type ThreadCreatedRealtimeEvent = BaseThreadRealtimeEvent & {
|
|
1567
|
-
type: "threadCreated";
|
|
1568
|
-
};
|
|
1569
|
-
declare type ThreadUpdatedRealtimeEvent = BaseThreadRealtimeEvent & {
|
|
1570
|
-
type: "threadUpdated";
|
|
1571
|
-
};
|
|
1572
|
-
declare type ThreadDeletedRealtimeEvent = BaseThreadRealtimeEvent & {
|
|
1573
|
-
type: "threadDeleted";
|
|
1574
|
-
};
|
|
1575
|
-
declare type CommentCreatedRealtimeEvent = BaseCommentRealtimeEvent & {
|
|
1576
|
-
type: "commentCreated";
|
|
1577
|
-
};
|
|
1578
|
-
declare type CommentUpdatedRealtimeEvent = BaseCommentRealtimeEvent & {
|
|
1579
|
-
type: "commentEdited";
|
|
1580
|
-
};
|
|
1581
|
-
declare type CommentDeletedRealtimeEvent = BaseCommentRealtimeEvent & {
|
|
1582
|
-
type: "commentDeleted";
|
|
1583
|
-
};
|
|
1584
|
-
declare type RealtimeEvent = ThreadCreatedRealtimeEvent | ThreadUpdatedRealtimeEvent | ThreadDeletedRealtimeEvent | CommentCreatedRealtimeEvent | CommentUpdatedRealtimeEvent | CommentDeletedRealtimeEvent;
|
|
1585
|
-
|
|
1586
|
-
declare type RealtimeClient = {
|
|
1587
|
-
subscribeToEvents: (roomId: string, callback: Callback<RealtimeEvent>) => UnsubscribeCallback;
|
|
1588
|
-
error: Observable<Error>;
|
|
1589
|
-
connection: Observable<Status>;
|
|
1590
|
-
};
|
|
1591
|
-
|
|
1592
1679
|
declare type EnterOptions<TPresence extends JsonObject, TStorage extends LsonObject> = Resolve<RoomInitializers<TPresence, TStorage> & {
|
|
1593
1680
|
/**
|
|
1594
1681
|
* Only necessary when you’re using Liveblocks with React v17 or lower.
|
|
@@ -1601,10 +1688,6 @@ declare type EnterOptions<TPresence extends JsonObject, TStorage extends LsonObj
|
|
|
1601
1688
|
unstable_batchedUpdates?: (cb: () => void) => void;
|
|
1602
1689
|
}>;
|
|
1603
1690
|
declare type Client = {
|
|
1604
|
-
__internal: {
|
|
1605
|
-
getAuthValue: AuthManager["getAuthValue"];
|
|
1606
|
-
realtimeClient: RealtimeClient;
|
|
1607
|
-
};
|
|
1608
1691
|
/**
|
|
1609
1692
|
* Gets a room. Returns null if {@link Client.enter} has not been called previously.
|
|
1610
1693
|
*
|
|
@@ -2190,103 +2273,6 @@ declare namespace protocol {
|
|
|
2190
2273
|
};
|
|
2191
2274
|
}
|
|
2192
2275
|
|
|
2193
|
-
declare type BaseMetadata = Record<string, string | boolean | number>;
|
|
2194
|
-
|
|
2195
|
-
declare type CommentBodyBlockElement = CommentBodyParagraph;
|
|
2196
|
-
declare type CommentBodyInlineElement = CommentBodyText | CommentBodyMention;
|
|
2197
|
-
declare type CommentBodyElement = CommentBodyBlockElement | CommentBodyInlineElement;
|
|
2198
|
-
declare type CommentBodyParagraph = {
|
|
2199
|
-
type: "paragraph";
|
|
2200
|
-
children: CommentBodyInlineElement[];
|
|
2201
|
-
};
|
|
2202
|
-
declare type CommentBodyMention = {
|
|
2203
|
-
type: "mention";
|
|
2204
|
-
userId: string;
|
|
2205
|
-
};
|
|
2206
|
-
declare type CommentBodyText = {
|
|
2207
|
-
bold?: boolean;
|
|
2208
|
-
italic?: boolean;
|
|
2209
|
-
strikethrough?: boolean;
|
|
2210
|
-
code?: boolean;
|
|
2211
|
-
text: string;
|
|
2212
|
-
};
|
|
2213
|
-
declare type CommentBody = {
|
|
2214
|
-
version: 1;
|
|
2215
|
-
content: CommentBodyBlockElement[];
|
|
2216
|
-
};
|
|
2217
|
-
|
|
2218
|
-
declare type CommentData = {
|
|
2219
|
-
type: "comment";
|
|
2220
|
-
id: string;
|
|
2221
|
-
threadId: string;
|
|
2222
|
-
roomId: string;
|
|
2223
|
-
userId: string;
|
|
2224
|
-
createdAt: string;
|
|
2225
|
-
editedAt?: string;
|
|
2226
|
-
} & ({
|
|
2227
|
-
body: CommentBody;
|
|
2228
|
-
deletedAt?: never;
|
|
2229
|
-
} | {
|
|
2230
|
-
body?: never;
|
|
2231
|
-
deletedAt: string;
|
|
2232
|
-
});
|
|
2233
|
-
|
|
2234
|
-
declare type ThreadData<ThreadMetadata extends BaseMetadata = never> = {
|
|
2235
|
-
type: "thread";
|
|
2236
|
-
id: string;
|
|
2237
|
-
roomId: string;
|
|
2238
|
-
createdAt: string;
|
|
2239
|
-
updatedAt?: string;
|
|
2240
|
-
comments: CommentData[];
|
|
2241
|
-
metadata: [ThreadMetadata] extends [never] ? Record<string, never> : ThreadMetadata;
|
|
2242
|
-
};
|
|
2243
|
-
|
|
2244
|
-
declare type Options = {
|
|
2245
|
-
serverEndpoint: string;
|
|
2246
|
-
};
|
|
2247
|
-
declare type CommentsApi<ThreadMetadata extends BaseMetadata> = {
|
|
2248
|
-
getThreads(options: {
|
|
2249
|
-
roomId: string;
|
|
2250
|
-
}): Promise<ThreadData<ThreadMetadata>[]>;
|
|
2251
|
-
createThread(options: {
|
|
2252
|
-
roomId: string;
|
|
2253
|
-
threadId: string;
|
|
2254
|
-
commentId: string;
|
|
2255
|
-
metadata: ThreadMetadata | undefined;
|
|
2256
|
-
body: CommentBody;
|
|
2257
|
-
}): Promise<ThreadData<ThreadMetadata>>;
|
|
2258
|
-
editThreadMetadata(options: {
|
|
2259
|
-
roomId: string;
|
|
2260
|
-
metadata: Partial<ThreadMetadata>;
|
|
2261
|
-
threadId: string;
|
|
2262
|
-
}): Promise<ThreadData<ThreadMetadata>>;
|
|
2263
|
-
createComment(options: {
|
|
2264
|
-
roomId: string;
|
|
2265
|
-
threadId: string;
|
|
2266
|
-
commentId: string;
|
|
2267
|
-
body: CommentBody;
|
|
2268
|
-
}): Promise<CommentData>;
|
|
2269
|
-
editComment(options: {
|
|
2270
|
-
roomId: string;
|
|
2271
|
-
threadId: string;
|
|
2272
|
-
commentId: string;
|
|
2273
|
-
body: CommentBody;
|
|
2274
|
-
}): Promise<CommentData>;
|
|
2275
|
-
deleteComment(options: {
|
|
2276
|
-
roomId: string;
|
|
2277
|
-
threadId: string;
|
|
2278
|
-
commentId: string;
|
|
2279
|
-
}): Promise<void>;
|
|
2280
|
-
};
|
|
2281
|
-
declare function createCommentsApi<ThreadMetadata extends BaseMetadata>(client: Client, { serverEndpoint }: Options): CommentsApi<ThreadMetadata>;
|
|
2282
|
-
|
|
2283
|
-
declare type BaseUserInfo = {
|
|
2284
|
-
name?: string;
|
|
2285
|
-
avatar?: string;
|
|
2286
|
-
};
|
|
2287
|
-
|
|
2288
|
-
declare function isCommentBodyMention(element: CommentBodyElement): element is CommentBodyMention;
|
|
2289
|
-
|
|
2290
2276
|
/**
|
|
2291
2277
|
* Helper type to help users adopt to Lson types from interface definitions.
|
|
2292
2278
|
* You should only use this to wrap interfaces you don't control. For more
|
|
@@ -2299,4 +2285,4 @@ declare type EnsureJson<T> = [
|
|
|
2299
2285
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
2300
2286
|
};
|
|
2301
2287
|
|
|
2302
|
-
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata,
|
|
2288
|
+
export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, CommentBodyMention, CommentBodyParagraph, CommentData, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asArrayWithLegacyMethods, asPos, assert, assertNever, b64decode, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|