@liveblocks/core 2.12.1-emails1 → 2.12.1-test2

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 CHANGED
@@ -5,6 +5,19 @@
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
+
8
21
  /**
9
22
  * Represents an indefinitely deep arbitrary JSON data structure. There are
10
23
  * four types that make up the Json family:
@@ -28,6 +41,219 @@ declare function isJsonScalar(data: Json): data is JsonScalar;
28
41
  declare function isJsonArray(data: Json): data is JsonArray;
29
42
  declare function isJsonObject(data: Json): data is JsonObject;
30
43
 
44
+ /**
45
+ * Represents some constraints for user info. Basically read this as: "any JSON
46
+ * object is fine, but _if_ it has a name field, it _must_ be a string."
47
+ * (Ditto for avatar.)
48
+ */
49
+ declare type IUserInfo = {
50
+ [key: string]: Json | undefined;
51
+ name?: string;
52
+ avatar?: string;
53
+ };
54
+ /**
55
+ * This type is used by clients to define the metadata for a user.
56
+ */
57
+ declare type BaseUserMeta = {
58
+ /**
59
+ * The id of the user that has been set in the authentication endpoint.
60
+ * Useful to get additional information about the connected user.
61
+ */
62
+ id?: string;
63
+ /**
64
+ * Additional user information that has been set in the authentication endpoint.
65
+ */
66
+ info?: IUserInfo;
67
+ };
68
+
69
+ declare enum Permission {
70
+ Read = "room:read",
71
+ Write = "room:write",
72
+ PresenceWrite = "room:presence:write",
73
+ CommentsWrite = "comments:write",
74
+ CommentsRead = "comments:read"
75
+ }
76
+
77
+ declare type Callback<T> = (event: T) => void;
78
+ declare type UnsubscribeCallback = () => void;
79
+ declare type Observable<T> = {
80
+ /**
81
+ * Register a callback function to be called whenever the event source emits
82
+ * an event.
83
+ */
84
+ subscribe(callback: Callback<T>): UnsubscribeCallback;
85
+ /**
86
+ * Register a one-time callback function to be called whenever the event
87
+ * source emits an event. After the event fires, the callback is
88
+ * auto-unsubscribed.
89
+ */
90
+ subscribeOnce(callback: Callback<T>): UnsubscribeCallback;
91
+ /**
92
+ * Returns a promise that will resolve when an event is emitted by this
93
+ * event source. Optionally, specify a predicate that has to match. The first
94
+ * event matching that predicate will then resolve the promise.
95
+ */
96
+ waitUntil(predicate?: (event: T) => boolean): Promise<T>;
97
+ };
98
+ declare type EventSource<T> = Observable<T> & {
99
+ /**
100
+ * Notify all subscribers about the event.
101
+ */
102
+ notify(event: T): void;
103
+ /**
104
+ * Returns the number of active subscribers.
105
+ */
106
+ count(): number;
107
+ /**
108
+ * Pauses event delivery until unpaused. Any .notify() calls made while
109
+ * paused will get buffered into memory and emitted later.
110
+ */
111
+ pause(): void;
112
+ /**
113
+ * Emits all in-memory buffered events, and unpauses. Any .notify() calls
114
+ * made after this will be synchronously delivered again.
115
+ */
116
+ unpause(): void;
117
+ /**
118
+ * Observable instance, which can be used to subscribe to this event source
119
+ * in a readonly fashion. Safe to publicly expose.
120
+ */
121
+ observable: Observable<T>;
122
+ };
123
+ /**
124
+ * makeEventSource allows you to generate a subscribe/notify pair of functions
125
+ * to make subscribing easy and to get notified about events.
126
+ *
127
+ * The events are anonymous, so you can use it to define events, like so:
128
+ *
129
+ * const event1 = makeEventSource();
130
+ * const event2 = makeEventSource();
131
+ *
132
+ * event1.subscribe(foo);
133
+ * event1.subscribe(bar);
134
+ * event2.subscribe(qux);
135
+ *
136
+ * // Unsubscription is pretty standard
137
+ * const unsub = event2.subscribe(foo);
138
+ * unsub();
139
+ *
140
+ * event1.notify(); // Now foo and bar will get called
141
+ * event2.notify(); // Now qux will get called (but foo will not, since it's unsubscribed)
142
+ *
143
+ */
144
+ declare function makeEventSource<T>(): EventSource<T>;
145
+
146
+ interface IWebSocketEvent {
147
+ type: string;
148
+ }
149
+ interface IWebSocketCloseEvent extends IWebSocketEvent {
150
+ readonly code: WebsocketCloseCodes;
151
+ readonly wasClean: boolean;
152
+ readonly reason: string;
153
+ }
154
+ interface IWebSocketMessageEvent extends IWebSocketEvent {
155
+ readonly data: string | Buffer | ArrayBuffer | readonly Buffer[];
156
+ }
157
+ interface IWebSocketInstance {
158
+ readonly CONNECTING: number;
159
+ readonly OPEN: number;
160
+ readonly CLOSING: number;
161
+ readonly CLOSED: number;
162
+ readonly readyState: number;
163
+ addEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
164
+ addEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
165
+ addEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
166
+ removeEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
167
+ removeEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
168
+ removeEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
169
+ close(): void;
170
+ send(data: string): void;
171
+ }
172
+ /**
173
+ * Either the browser-based WebSocket API or Node.js' WebSocket API (from the
174
+ * 'ws' package).
175
+ *
176
+ * This type defines the minimal WebSocket API that Liveblocks needs from
177
+ * a WebSocket implementation, and is a minimal subset of the browser-based
178
+ * WebSocket APIs and Node.js' WebSocket API so that both implementations are
179
+ * assignable to this type.
180
+ */
181
+ interface IWebSocket {
182
+ new (address: string): IWebSocketInstance;
183
+ }
184
+ /**
185
+ * The following ranges will be respected by the client:
186
+ *
187
+ * 10xx: client will reauthorize (just like 41xx)
188
+ * 40xx: client will disconnect
189
+ * 41xx: client will reauthorize
190
+ * 42xx: client will retry without reauthorizing (currently not used)
191
+ *
192
+ */
193
+ declare enum WebsocketCloseCodes {
194
+ /** Normal close of connection, the connection fulfilled its purpose. */
195
+ CLOSE_NORMAL = 1000,
196
+ /** Unexpected error happened with the network/infra level. In spirit akin to HTTP 503 */
197
+ CLOSE_ABNORMAL = 1006,
198
+ /** Unexpected error happened. In spirit akin to HTTP 500 */
199
+ UNEXPECTED_CONDITION = 1011,
200
+ /** Please back off for now, but try again in a few moments */
201
+ TRY_AGAIN_LATER = 1013,
202
+ /** Message wasn't understood, disconnect */
203
+ INVALID_MESSAGE_FORMAT = 4000,
204
+ /** Server refused to allow connection. Re-authorizing won't help. Disconnect. In spirit akin to HTTP 403 */
205
+ NOT_ALLOWED = 4001,
206
+ /** Unused */
207
+ MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
208
+ /** Unused */
209
+ MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
210
+ /** Unused */
211
+ MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
212
+ /** Room is full, disconnect */
213
+ MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
214
+ /** The room's ID was updated, disconnect */
215
+ ROOM_ID_UPDATED = 4006,
216
+ /** The server kicked the connection from the room. */
217
+ KICKED = 4100,
218
+ /** The auth token is expired, reauthorize to get a fresh one. In spirit akin to HTTP 401 */
219
+ TOKEN_EXPIRED = 4109,
220
+ /** Disconnect immediately */
221
+ CLOSE_WITHOUT_RETRY = 4999
222
+ }
223
+
224
+ /**
225
+ * Returns a human-readable status indicating the current connection status of
226
+ * a Room, as returned by `room.getStatus()`. Can be used to implement
227
+ * a connection status badge.
228
+ */
229
+ declare type Status = "initial" | "connecting" | "connected" | "reconnecting" | "disconnected";
230
+ /**
231
+ * Used to report about app-level reconnection issues.
232
+ *
233
+ * Normal (quick) reconnects won't be reported as a "lost connection". Instead,
234
+ * the application will only get an event if the reconnection attempts by the
235
+ * client are taking (much) longer than usual. Definitely a situation you want
236
+ * to inform your users about, for example, by throwing a toast message on
237
+ * screen, or show a "trying to reconnect" banner.
238
+ */
239
+ declare type LostConnectionEvent = "lost" | "restored" | "failed";
240
+ /**
241
+ * Arbitrary record that will be used as the authentication "authValue". It's the
242
+ * value that is returned by calling the authentication delegate, and will get
243
+ * passed to the connection factory delegate. This value will be remembered by
244
+ * the connection manager, but its value will not be interpreted, so it can be
245
+ * any value (except null).
246
+ */
247
+ declare type BaseAuthResult = NonNullable<Json>;
248
+ declare class LiveblocksError extends Error {
249
+ code: number;
250
+ }
251
+ declare type Delegates<T extends BaseAuthResult> = {
252
+ authenticate: () => Promise<T>;
253
+ createSocket: (authValue: T) => IWebSocketInstance;
254
+ canZombie: () => boolean;
255
+ };
256
+
31
257
  declare enum OpCode {
32
258
  INIT = 0,
33
259
  SET_PARENT_KEY = 1,
@@ -206,77 +432,27 @@ declare type PlainLsonList = {
206
432
  };
207
433
  declare type PlainLson = PlainLsonObject | PlainLsonMap | PlainLsonList | Json;
208
434
 
209
- declare type LiveObjectUpdateDelta<O extends {
210
- [key: string]: unknown;
211
- }> = {
212
- [K in keyof O]?: UpdateDelta | undefined;
213
- };
214
435
  /**
215
- * A LiveObject notification that is sent in-client to any subscribers whenever
216
- * one or more of the entries inside the LiveObject instance have changed.
436
+ * Helper type to convert any valid Lson type to the equivalent Json type.
437
+ *
438
+ * Examples:
439
+ *
440
+ * ToImmutable<42> // 42
441
+ * ToImmutable<'hi'> // 'hi'
442
+ * ToImmutable<number> // number
443
+ * ToImmutable<string> // string
444
+ * ToImmutable<string | LiveList<number>> // string | readonly number[]
445
+ * ToImmutable<LiveMap<string, LiveList<number>>>
446
+ * // ReadonlyMap<string, readonly number[]>
447
+ * ToImmutable<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
448
+ * // { readonly a: null, readonly b: readonly string[], readonly c?: number }
449
+ *
217
450
  */
218
- declare type LiveObjectUpdates<TData extends LsonObject> = {
219
- type: "LiveObject";
220
- node: LiveObject<TData>;
221
- updates: LiveObjectUpdateDelta<TData>;
222
- };
451
+ 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 ? {
452
+ readonly [K in keyof L]: ToImmutable<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
453
+ } : L extends Json ? L : never;
223
454
  /**
224
- * The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
225
- * Keys should be a string, and values should be serializable to JSON.
226
- * If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
227
- */
228
- declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
229
- constructor(obj?: O);
230
- /**
231
- * Transform the LiveObject into a javascript object
232
- */
233
- toObject(): O;
234
- /**
235
- * Adds or updates a property with a specified key and a value.
236
- * @param key The key of the property to add
237
- * @param value The value of the property to add
238
- */
239
- set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
240
- /**
241
- * Returns a specified property from the LiveObject.
242
- * @param key The key of the property to get
243
- */
244
- get<TKey extends keyof O>(key: TKey): O[TKey];
245
- /**
246
- * Deletes a key from the LiveObject
247
- * @param key The key of the property to delete
248
- */
249
- delete(key: keyof O): void;
250
- /**
251
- * Adds or updates multiple properties at once with an object.
252
- * @param patch The object used to overrides properties
253
- */
254
- update(patch: Partial<O>): void;
255
- toImmutable(): ToImmutable<O>;
256
- clone(): LiveObject<O>;
257
- }
258
-
259
- /**
260
- * Helper type to convert any valid Lson type to the equivalent Json type.
261
- *
262
- * Examples:
263
- *
264
- * ToImmutable<42> // 42
265
- * ToImmutable<'hi'> // 'hi'
266
- * ToImmutable<number> // number
267
- * ToImmutable<string> // string
268
- * ToImmutable<string | LiveList<number>> // string | readonly number[]
269
- * ToImmutable<LiveMap<string, LiveList<number>>>
270
- * // ReadonlyMap<string, readonly number[]>
271
- * ToImmutable<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
272
- * // { readonly a: null, readonly b: readonly string[], readonly c?: number }
273
- *
274
- */
275
- 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 ? {
276
- readonly [K in keyof L]: ToImmutable<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
277
- } : L extends Json ? L : never;
278
- /**
279
- * Returns PlainLson for a given Json or LiveStructure, suitable for calling the storage init api
455
+ * Returns PlainLson for a given Json or LiveStructure, suitable for calling the storage init api
280
456
  */
281
457
  declare function toPlainLson(lson: Lson): PlainLson;
282
458
 
@@ -554,6 +730,56 @@ declare type ToJson<T extends Lson | LsonObject> = T extends Json ? T : T extend
554
730
  [K in KS]: ToJson<V>;
555
731
  } : never;
556
732
 
733
+ declare type LiveObjectUpdateDelta<O extends {
734
+ [key: string]: unknown;
735
+ }> = {
736
+ [K in keyof O]?: UpdateDelta | undefined;
737
+ };
738
+ /**
739
+ * A LiveObject notification that is sent in-client to any subscribers whenever
740
+ * one or more of the entries inside the LiveObject instance have changed.
741
+ */
742
+ declare type LiveObjectUpdates<TData extends LsonObject> = {
743
+ type: "LiveObject";
744
+ node: LiveObject<TData>;
745
+ updates: LiveObjectUpdateDelta<TData>;
746
+ };
747
+ /**
748
+ * The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
749
+ * Keys should be a string, and values should be serializable to JSON.
750
+ * If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
751
+ */
752
+ declare class LiveObject<O extends LsonObject> extends AbstractCrdt {
753
+ constructor(obj?: O);
754
+ /**
755
+ * Transform the LiveObject into a javascript object
756
+ */
757
+ toObject(): O;
758
+ /**
759
+ * Adds or updates a property with a specified key and a value.
760
+ * @param key The key of the property to add
761
+ * @param value The value of the property to add
762
+ */
763
+ set<TKey extends keyof O>(key: TKey, value: O[TKey]): void;
764
+ /**
765
+ * Returns a specified property from the LiveObject.
766
+ * @param key The key of the property to get
767
+ */
768
+ get<TKey extends keyof O>(key: TKey): O[TKey];
769
+ /**
770
+ * Deletes a key from the LiveObject
771
+ * @param key The key of the property to delete
772
+ */
773
+ delete(key: keyof O): void;
774
+ /**
775
+ * Adds or updates multiple properties at once with an object.
776
+ * @param patch The object used to overrides properties
777
+ */
778
+ update(patch: Partial<O>): void;
779
+ toImmutable(): ToImmutable<O>;
780
+ clone(): LiveObject<O>;
781
+ }
782
+
557
783
  declare type DateToString<T> = {
558
784
  [P in keyof T]: T[P] extends Date ? string : T[P] extends Date | null ? string | null : T[P] extends Date | undefined ? string | undefined : T[P];
559
785
  };
@@ -620,31 +846,6 @@ declare type BaseRoomInfo = {
620
846
  url?: string;
621
847
  };
622
848
 
623
- /**
624
- * Represents some constraints for user info. Basically read this as: "any JSON
625
- * object is fine, but _if_ it has a name field, it _must_ be a string."
626
- * (Ditto for avatar.)
627
- */
628
- declare type IUserInfo = {
629
- [key: string]: Json | undefined;
630
- name?: string;
631
- avatar?: string;
632
- };
633
- /**
634
- * This type is used by clients to define the metadata for a user.
635
- */
636
- declare type BaseUserMeta = {
637
- /**
638
- * The id of the user that has been set in the authentication endpoint.
639
- * Useful to get additional information about the connected user.
640
- */
641
- id?: string;
642
- /**
643
- * Additional user information that has been set in the authentication endpoint.
644
- */
645
- info?: IUserInfo;
646
- };
647
-
648
849
  declare type BaseMetadata = Record<string, string | boolean | number | undefined>;
649
850
  declare type CommentReaction = {
650
851
  emoji: string;
@@ -812,301 +1013,62 @@ declare global {
812
1013
  }
813
1014
  declare type ExtendableTypes = "Presence" | "Storage" | "UserMeta" | "RoomEvent" | "ThreadMetadata" | "RoomInfo" | "ActivitiesData";
814
1015
  declare type MakeErrorString<K extends ExtendableTypes, Reason extends string = "does not match its requirements"> = `The type you provided for '${K}' ${Reason}. To learn how to fix this, see https://liveblocks.io/docs/errors/${K}`;
815
- declare type GetOverride<K extends ExtendableTypes, B, Reason extends string = "does not match its requirements"> = GetOverrideOrErrorValue<K, B, MakeErrorString<K, Reason>>;
816
- declare type GetOverrideOrErrorValue<K extends ExtendableTypes, B, ErrorType> = unknown extends Liveblocks[K] ? B : Liveblocks[K] extends B ? Liveblocks[K] : ErrorType;
817
- declare type DP = GetOverride<"Presence", JsonObject, "is not a valid JSON object">;
818
- declare type DS = GetOverride<"Storage", LsonObject, "is not a valid LSON value">;
819
- declare type DU = GetOverrideOrErrorValue<"UserMeta", BaseUserMeta, Record<"id" | "info", MakeErrorString<"UserMeta">>>;
820
- declare type DE = GetOverride<"RoomEvent", Json, "is not a valid JSON value">;
821
- declare type DM = GetOverride<"ThreadMetadata", BaseMetadata>;
822
- declare type DRI = GetOverride<"RoomInfo", BaseRoomInfo>;
823
- declare type DAD = GetOverrideOrErrorValue<"ActivitiesData", BaseActivitiesData, {
824
- [K in keyof Liveblocks["ActivitiesData"]]: "At least one of the custom notification kinds you provided for 'ActivitiesData' does not match its requirements. To learn how to fix this, see https://liveblocks.io/docs/errors/ActivitiesData";
825
- }>;
826
- declare type KDAD = keyof DAD extends `$${string}` ? keyof DAD : "Custom notification kinds must start with '$' but your custom 'ActivitiesData' type contains at least one kind which doesn't. To learn how to fix this, see https://liveblocks.io/docs/errors/ActivitiesData";
827
-
828
- /**
829
- * Use this symbol to brand an object property as internal.
830
- *
831
- * @example
832
- * Object.defineProperty(
833
- * {
834
- * public,
835
- * [kInternal]: {
836
- * private
837
- * },
838
- * },
839
- * kInternal,
840
- * {
841
- * enumerable: false,
842
- * }
843
- * );
844
- */
845
- declare const kInternal: unique symbol;
846
-
847
- declare type RenameDataField<T, TFieldName extends string> = T extends any ? {
848
- [K in keyof T as K extends "data" ? TFieldName : K]: T[K];
849
- } : never;
850
- declare type AsyncLoading<F extends string = "data"> = RenameDataField<{
851
- readonly isLoading: true;
852
- readonly data?: never;
853
- readonly error?: never;
854
- }, F>;
855
- declare type AsyncSuccess<T, F extends string = "data"> = RenameDataField<{
856
- readonly isLoading: false;
857
- readonly data: T;
858
- readonly error?: never;
859
- }, F>;
860
- declare type AsyncError<F extends string = "data"> = RenameDataField<{
861
- readonly isLoading: false;
862
- readonly data?: never;
863
- readonly error: Error;
864
- }, F>;
865
- declare type AsyncResult<T, F extends string = "data"> = AsyncLoading<F> | AsyncSuccess<T, F> | AsyncError<F>;
866
-
867
- declare type Callback<T> = (event: T) => void;
868
- declare type UnsubscribeCallback = () => void;
869
- declare type Observable<T> = {
870
- /**
871
- * Register a callback function to be called whenever the event source emits
872
- * an event.
873
- */
874
- subscribe(callback: Callback<T>): UnsubscribeCallback;
875
- /**
876
- * Register a one-time callback function to be called whenever the event
877
- * source emits an event. After the event fires, the callback is
878
- * auto-unsubscribed.
879
- */
880
- subscribeOnce(callback: Callback<T>): UnsubscribeCallback;
881
- /**
882
- * Returns a promise that will resolve when an event is emitted by this
883
- * event source. Optionally, specify a predicate that has to match. The first
884
- * event matching that predicate will then resolve the promise.
885
- */
886
- waitUntil(predicate?: (event: T) => boolean): Promise<T>;
887
- };
888
- declare type EventSource<T> = Observable<T> & {
889
- /**
890
- * Notify all subscribers about the event.
891
- */
892
- notify(event: T): void;
893
- /**
894
- * Returns the number of active subscribers.
895
- */
896
- count(): number;
897
- /**
898
- * Pauses event delivery until unpaused. Any .notify() calls made while
899
- * paused will get buffered into memory and emitted later.
900
- */
901
- pause(): void;
902
- /**
903
- * Emits all in-memory buffered events, and unpauses. Any .notify() calls
904
- * made after this will be synchronously delivered again.
905
- */
906
- unpause(): void;
907
- /**
908
- * Observable instance, which can be used to subscribe to this event source
909
- * in a readonly fashion. Safe to publicly expose.
910
- */
911
- observable: Observable<T>;
912
- };
913
- /**
914
- * makeEventSource allows you to generate a subscribe/notify pair of functions
915
- * to make subscribing easy and to get notified about events.
916
- *
917
- * The events are anonymous, so you can use it to define events, like so:
918
- *
919
- * const event1 = makeEventSource();
920
- * const event2 = makeEventSource();
921
- *
922
- * event1.subscribe(foo);
923
- * event1.subscribe(bar);
924
- * event2.subscribe(qux);
925
- *
926
- * // Unsubscription is pretty standard
927
- * const unsub = event2.subscribe(foo);
928
- * unsub();
929
- *
930
- * event1.notify(); // Now foo and bar will get called
931
- * event2.notify(); // Now qux will get called (but foo will not, since it's unsubscribed)
932
- *
933
- */
934
- declare function makeEventSource<T>(): EventSource<T>;
935
-
936
- declare type BatchStore<O, I> = Observable<void> & {
937
- get: (input: I) => Promise<void>;
938
- getState: (input: I) => AsyncResult<O> | undefined;
939
- invalidate: (inputs?: I[]) => void;
940
- };
941
-
942
- /**
943
- * A Store is just a mini Zustand store.
944
- */
945
- declare type Store<T> = {
946
- get: () => Readonly<T>;
947
- set: (callback: (currentState: Readonly<T>) => Readonly<T>) => void;
948
- subscribe: (callback: () => void) => () => void;
949
- batch: (callback: () => void) => void;
950
- };
951
- /**
952
- * Create a store for an immutable state. Close to Zustand's vanilla store conceptually but with less features.
953
- */
954
- declare function createStore<T>(initialState: T): Store<T>;
955
-
956
- /**
957
- * Back-port of TypeScript 5.4's built-in NoInfer utility type.
958
- * See https://stackoverflow.com/a/56688073/148872
959
- */
960
- declare type NoInfr<A> = [A][A extends any ? 0 : never];
961
-
962
- /**
963
- * This helper type is effectively a no-op, but will force TypeScript to
964
- * "evaluate" any named helper types in its definition. This can sometimes make
965
- * API signatures clearer in IDEs.
966
- *
967
- * For example, in:
968
- *
969
- * type Payload<T> = { data: T };
970
- *
971
- * let r1: Payload<string>;
972
- * let r2: Resolve<Payload<string>>;
973
- *
974
- * The inferred type of `r1` is going to be `Payload<string>` which shows up in
975
- * editor hints, and it may be unclear what's inside if you don't know the
976
- * definition of `Payload`.
977
- *
978
- * The inferred type of `r2` is going to be `{ data: string }`, which may be
979
- * more helpful.
980
- *
981
- * This trick comes from:
982
- * https://effectivetypescript.com/2022/02/25/gentips-4-display/
983
- */
984
- declare type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
985
- [K in keyof T]: T[K];
986
- };
987
-
988
- declare type CustomAuthenticationResult = {
989
- token: string;
990
- error?: never;
991
- } | {
992
- token?: never;
993
- error: "forbidden";
994
- reason: string;
995
- } | {
996
- token?: never;
997
- error: string;
998
- reason: string;
999
- };
1000
-
1001
- interface IWebSocketEvent {
1002
- type: string;
1003
- }
1004
- interface IWebSocketCloseEvent extends IWebSocketEvent {
1005
- readonly code: WebsocketCloseCodes;
1006
- readonly wasClean: boolean;
1007
- readonly reason: string;
1008
- }
1009
- interface IWebSocketMessageEvent extends IWebSocketEvent {
1010
- readonly data: string | Buffer | ArrayBuffer | readonly Buffer[];
1011
- }
1012
- interface IWebSocketInstance {
1013
- readonly CONNECTING: number;
1014
- readonly OPEN: number;
1015
- readonly CLOSING: number;
1016
- readonly CLOSED: number;
1017
- readonly readyState: number;
1018
- addEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
1019
- addEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
1020
- addEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
1021
- removeEventListener(type: "close", listener: (this: IWebSocketInstance, ev: IWebSocketCloseEvent) => unknown): void;
1022
- removeEventListener(type: "message", listener: (this: IWebSocketInstance, ev: IWebSocketMessageEvent) => unknown): void;
1023
- removeEventListener(type: "open" | "error", listener: (this: IWebSocketInstance, ev: IWebSocketEvent) => unknown): void;
1024
- close(): void;
1025
- send(data: string): void;
1026
- }
1027
- /**
1028
- * Either the browser-based WebSocket API or Node.js' WebSocket API (from the
1029
- * 'ws' package).
1030
- *
1031
- * This type defines the minimal WebSocket API that Liveblocks needs from
1032
- * a WebSocket implementation, and is a minimal subset of the browser-based
1033
- * WebSocket APIs and Node.js' WebSocket API so that both implementations are
1034
- * assignable to this type.
1035
- */
1036
- interface IWebSocket {
1037
- new (address: string): IWebSocketInstance;
1038
- }
1039
- /**
1040
- * The following ranges will be respected by the client:
1041
- *
1042
- * 10xx: client will reauthorize (just like 41xx)
1043
- * 40xx: client will disconnect
1044
- * 41xx: client will reauthorize
1045
- * 42xx: client will retry without reauthorizing (currently not used)
1046
- *
1047
- */
1048
- declare enum WebsocketCloseCodes {
1049
- /** Normal close of connection, the connection fulfilled its purpose. */
1050
- CLOSE_NORMAL = 1000,
1051
- /** Unexpected error happened with the network/infra level. In spirit akin to HTTP 503 */
1052
- CLOSE_ABNORMAL = 1006,
1053
- /** Unexpected error happened. In spirit akin to HTTP 500 */
1054
- UNEXPECTED_CONDITION = 1011,
1055
- /** Please back off for now, but try again in a few moments */
1056
- TRY_AGAIN_LATER = 1013,
1057
- /** Message wasn't understood, disconnect */
1058
- INVALID_MESSAGE_FORMAT = 4000,
1059
- /** Server refused to allow connection. Re-authorizing won't help. Disconnect. In spirit akin to HTTP 403 */
1060
- NOT_ALLOWED = 4001,
1061
- /** Unused */
1062
- MAX_NUMBER_OF_MESSAGES_PER_SECONDS = 4002,
1063
- /** Unused */
1064
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS = 4003,
1065
- /** Unused */
1066
- MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP = 4004,
1067
- /** Room is full, disconnect */
1068
- MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM = 4005,
1069
- /** The room's ID was updated, disconnect */
1070
- ROOM_ID_UPDATED = 4006,
1071
- /** The server kicked the connection from the room. */
1072
- KICKED = 4100,
1073
- /** The auth token is expired, reauthorize to get a fresh one. In spirit akin to HTTP 401 */
1074
- TOKEN_EXPIRED = 4109,
1075
- /** Disconnect immediately */
1076
- CLOSE_WITHOUT_RETRY = 4999
1077
- }
1016
+ declare type GetOverride<K extends ExtendableTypes, B, Reason extends string = "does not match its requirements"> = GetOverrideOrErrorValue<K, B, MakeErrorString<K, Reason>>;
1017
+ declare type GetOverrideOrErrorValue<K extends ExtendableTypes, B, ErrorType> = unknown extends Liveblocks[K] ? B : Liveblocks[K] extends B ? Liveblocks[K] : ErrorType;
1018
+ declare type DP = GetOverride<"Presence", JsonObject, "is not a valid JSON object">;
1019
+ declare type DS = GetOverride<"Storage", LsonObject, "is not a valid LSON value">;
1020
+ declare type DU = GetOverrideOrErrorValue<"UserMeta", BaseUserMeta, Record<"id" | "info", MakeErrorString<"UserMeta">>>;
1021
+ declare type DE = GetOverride<"RoomEvent", Json, "is not a valid JSON value">;
1022
+ declare type DM = GetOverride<"ThreadMetadata", BaseMetadata>;
1023
+ declare type DRI = GetOverride<"RoomInfo", BaseRoomInfo>;
1024
+ declare type DAD = GetOverrideOrErrorValue<"ActivitiesData", BaseActivitiesData, {
1025
+ [K in keyof Liveblocks["ActivitiesData"]]: "At least one of the custom notification kinds you provided for 'ActivitiesData' does not match its requirements. To learn how to fix this, see https://liveblocks.io/docs/errors/ActivitiesData";
1026
+ }>;
1027
+ declare type KDAD = keyof DAD extends `$${string}` ? keyof DAD : "Custom notification kinds must start with '$' but your custom 'ActivitiesData' type contains at least one kind which doesn't. To learn how to fix this, see https://liveblocks.io/docs/errors/ActivitiesData";
1078
1028
 
1079
1029
  /**
1080
- * Returns a human-readable status indicating the current connection status of
1081
- * a Room, as returned by `room.getStatus()`. Can be used to implement
1082
- * a connection status badge.
1083
- */
1084
- declare type Status = "initial" | "connecting" | "connected" | "reconnecting" | "disconnected";
1085
- /**
1086
- * Used to report about app-level reconnection issues.
1030
+ * Use this symbol to brand an object property as internal.
1087
1031
  *
1088
- * Normal (quick) reconnects won't be reported as a "lost connection". Instead,
1089
- * the application will only get an event if the reconnection attempts by the
1090
- * client are taking (much) longer than usual. Definitely a situation you want
1091
- * to inform your users about, for example, by throwing a toast message on
1092
- * screen, or show a "trying to reconnect" banner.
1093
- */
1094
- declare type LostConnectionEvent = "lost" | "restored" | "failed";
1095
- /**
1096
- * Arbitrary record that will be used as the authentication "authValue". It's the
1097
- * value that is returned by calling the authentication delegate, and will get
1098
- * passed to the connection factory delegate. This value will be remembered by
1099
- * the connection manager, but its value will not be interpreted, so it can be
1100
- * any value (except null).
1032
+ * @example
1033
+ * Object.defineProperty(
1034
+ * {
1035
+ * public,
1036
+ * [kInternal]: {
1037
+ * private
1038
+ * },
1039
+ * },
1040
+ * kInternal,
1041
+ * {
1042
+ * enumerable: false,
1043
+ * }
1044
+ * );
1101
1045
  */
1102
- declare type BaseAuthResult = NonNullable<Json>;
1103
- declare class LiveblocksError extends Error {
1104
- code: number;
1105
- }
1106
- declare type Delegates<T extends BaseAuthResult> = {
1107
- authenticate: () => Promise<T>;
1108
- createSocket: (authValue: T) => IWebSocketInstance;
1109
- canZombie: () => boolean;
1046
+ declare const kInternal: unique symbol;
1047
+
1048
+ declare type RenameDataField<T, TFieldName extends string> = T extends any ? {
1049
+ [K in keyof T as K extends "data" ? TFieldName : K]: T[K];
1050
+ } : never;
1051
+ declare type AsyncLoading<F extends string = "data"> = RenameDataField<{
1052
+ readonly isLoading: true;
1053
+ readonly data?: never;
1054
+ readonly error?: never;
1055
+ }, F>;
1056
+ declare type AsyncSuccess<T, F extends string = "data"> = RenameDataField<{
1057
+ readonly isLoading: false;
1058
+ readonly data: T;
1059
+ readonly error?: never;
1060
+ }, F>;
1061
+ declare type AsyncError<F extends string = "data"> = RenameDataField<{
1062
+ readonly isLoading: false;
1063
+ readonly data?: never;
1064
+ readonly error: Error;
1065
+ }, F>;
1066
+ declare type AsyncResult<T, F extends string = "data"> = AsyncLoading<F> | AsyncSuccess<T, F> | AsyncError<F>;
1067
+
1068
+ declare type BatchStore<O, I> = Observable<void> & {
1069
+ get: (input: I) => Promise<void>;
1070
+ getState: (input: I) => AsyncResult<O> | undefined;
1071
+ invalidate: (inputs?: I[]) => void;
1110
1072
  };
1111
1073
 
1112
1074
  declare enum ClientMsgCode {
@@ -1500,6 +1462,32 @@ declare namespace DevToolsTreeNode {
1500
1462
  export type { DevToolsTreeNode_CustomEventTreeNode as CustomEventTreeNode, DevToolsTreeNode_JsonTreeNode as JsonTreeNode, DevToolsTreeNode_LiveTreeNode as LiveTreeNode, DevToolsTreeNode_LsonTreeNode as LsonTreeNode, DevToolsTreeNode_TreeNode as TreeNode, DevToolsTreeNode_UserTreeNode as UserTreeNode };
1501
1463
  }
1502
1464
 
1465
+ /**
1466
+ * This helper type is effectively a no-op, but will force TypeScript to
1467
+ * "evaluate" any named helper types in its definition. This can sometimes make
1468
+ * API signatures clearer in IDEs.
1469
+ *
1470
+ * For example, in:
1471
+ *
1472
+ * type Payload<T> = { data: T };
1473
+ *
1474
+ * let r1: Payload<string>;
1475
+ * let r2: Resolve<Payload<string>>;
1476
+ *
1477
+ * The inferred type of `r1` is going to be `Payload<string>` which shows up in
1478
+ * editor hints, and it may be unclear what's inside if you don't know the
1479
+ * definition of `Payload`.
1480
+ *
1481
+ * The inferred type of `r2` is going to be `{ data: string }`, which may be
1482
+ * more helpful.
1483
+ *
1484
+ * This trick comes from:
1485
+ * https://effectivetypescript.com/2022/02/25/gentips-4-display/
1486
+ */
1487
+ declare type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
1488
+ [K in keyof T]: T[K];
1489
+ };
1490
+
1503
1491
  /**
1504
1492
  * Represents a user connected in a room. Treated as immutable.
1505
1493
  */
@@ -2064,6 +2052,7 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
2064
2052
  inboxNotifications: InboxNotificationData[];
2065
2053
  requestedAt: Date;
2066
2054
  nextCursor: string | null;
2055
+ permissionHints: Record<string, Permission[]>;
2067
2056
  }>;
2068
2057
  /**
2069
2058
  * Returns the updated and deleted threads and their associated inbox notifications since the requested date.
@@ -2083,6 +2072,7 @@ declare type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extend
2083
2072
  deleted: InboxNotificationDeleteInfo[];
2084
2073
  };
2085
2074
  requestedAt: Date;
2075
+ permissionHints: Record<string, Permission[]>;
2086
2076
  }>;
2087
2077
  /**
2088
2078
  * Returns a thread and the associated inbox notification if it exists.
@@ -2351,24 +2341,261 @@ declare type OptionalTupleUnless<C, T extends any[]> = Record<string, never> ext
2351
2341
  C
2352
2342
  ] extends [never] ? OptionalTuple<T> : T;
2353
2343
 
2354
- declare type GetInboxNotificationsOptions = {
2355
- cursor?: string;
2356
- };
2357
- declare type GetInboxNotificationsSinceOptions = {
2358
- since: Date;
2359
- signal?: AbortSignal;
2360
- };
2361
- declare type GetUserThreadsOptions<M extends BaseMetadata> = {
2362
- cursor?: string;
2363
- query?: {
2364
- resolved?: boolean;
2365
- metadata?: Partial<QueryMetadata<M>>;
2366
- };
2367
- };
2368
- declare type GetUserThreadsSinceOptions = {
2369
- since: Date;
2370
- signal?: AbortSignal;
2344
+ interface RoomHttpApi<M extends BaseMetadata> {
2345
+ getThreads(options: {
2346
+ roomId: string;
2347
+ cursor?: string;
2348
+ query?: {
2349
+ resolved?: boolean;
2350
+ metadata?: Partial<QueryMetadata<M>>;
2351
+ };
2352
+ }): Promise<{
2353
+ threads: ThreadData<M>[];
2354
+ inboxNotifications: InboxNotificationData[];
2355
+ requestedAt: Date;
2356
+ nextCursor: string | null;
2357
+ permissionHints: Record<string, Permission[]>;
2358
+ }>;
2359
+ getThreadsSince(options: {
2360
+ roomId: string;
2361
+ since: Date;
2362
+ signal?: AbortSignal;
2363
+ }): Promise<{
2364
+ threads: {
2365
+ updated: ThreadData<M>[];
2366
+ deleted: ThreadDeleteInfo[];
2367
+ };
2368
+ inboxNotifications: {
2369
+ updated: InboxNotificationData[];
2370
+ deleted: InboxNotificationDeleteInfo[];
2371
+ };
2372
+ requestedAt: Date;
2373
+ permissionHints: Record<string, Permission[]>;
2374
+ }>;
2375
+ createThread({ roomId, metadata, body, commentId, threadId, attachmentIds, }: {
2376
+ roomId: string;
2377
+ threadId?: string;
2378
+ commentId?: string;
2379
+ metadata: M | undefined;
2380
+ body: CommentBody;
2381
+ attachmentIds?: string[];
2382
+ }): Promise<ThreadData<M>>;
2383
+ getThread(options: {
2384
+ roomId: string;
2385
+ threadId: string;
2386
+ }): Promise<{
2387
+ thread?: ThreadData<M>;
2388
+ inboxNotification?: InboxNotificationData;
2389
+ }>;
2390
+ deleteThread({ roomId, threadId, }: {
2391
+ roomId: string;
2392
+ threadId: string;
2393
+ }): Promise<void>;
2394
+ editThreadMetadata({ roomId, metadata, threadId, }: {
2395
+ roomId: string;
2396
+ metadata: Patchable<M>;
2397
+ threadId: string;
2398
+ }): Promise<M>;
2399
+ createComment({ roomId, threadId, commentId, body, attachmentIds, }: {
2400
+ roomId: string;
2401
+ threadId: string;
2402
+ commentId?: string;
2403
+ body: CommentBody;
2404
+ attachmentIds?: string[];
2405
+ }): Promise<CommentData>;
2406
+ editComment({ roomId, threadId, commentId, body, attachmentIds, }: {
2407
+ roomId: string;
2408
+ threadId: string;
2409
+ commentId: string;
2410
+ body: CommentBody;
2411
+ attachmentIds?: string[];
2412
+ }): Promise<CommentData>;
2413
+ deleteComment({ roomId, threadId, commentId, }: {
2414
+ roomId: string;
2415
+ threadId: string;
2416
+ commentId: string;
2417
+ }): Promise<void>;
2418
+ addReaction({ roomId, threadId, commentId, emoji, }: {
2419
+ roomId: string;
2420
+ threadId: string;
2421
+ commentId: string;
2422
+ emoji: string;
2423
+ }): Promise<CommentUserReaction>;
2424
+ removeReaction({ roomId, threadId, commentId, emoji, }: {
2425
+ roomId: string;
2426
+ threadId: string;
2427
+ commentId: string;
2428
+ emoji: string;
2429
+ }): Promise<void>;
2430
+ markThreadAsResolved({ roomId, threadId, }: {
2431
+ roomId: string;
2432
+ threadId: string;
2433
+ }): Promise<void>;
2434
+ markThreadAsUnresolved({ roomId, threadId, }: {
2435
+ roomId: string;
2436
+ threadId: string;
2437
+ }): Promise<void>;
2438
+ markRoomInboxNotificationAsRead({ roomId, inboxNotificationId, }: {
2439
+ roomId: string;
2440
+ inboxNotificationId: string;
2441
+ }): Promise<string>;
2442
+ getNotificationSettings({ roomId, signal, }: {
2443
+ roomId: string;
2444
+ signal?: AbortSignal;
2445
+ }): Promise<RoomNotificationSettings>;
2446
+ updateNotificationSettings({ roomId, settings, }: {
2447
+ roomId: string;
2448
+ settings: Partial<RoomNotificationSettings>;
2449
+ }): Promise<RoomNotificationSettings>;
2450
+ getAttachmentUrl(options: {
2451
+ roomId: string;
2452
+ attachmentId: string;
2453
+ }): Promise<string>;
2454
+ uploadAttachment({ roomId, attachment, signal, }: {
2455
+ roomId: string;
2456
+ attachment: CommentLocalAttachment;
2457
+ signal?: AbortSignal;
2458
+ }): Promise<CommentAttachment>;
2459
+ getOrCreateAttachmentUrlsStore(roomId: string): BatchStore<string, string>;
2460
+ createTextMention({ roomId, userId, mentionId, }: {
2461
+ roomId: string;
2462
+ userId: string;
2463
+ mentionId: string;
2464
+ }): Promise<void>;
2465
+ deleteTextMention({ roomId, mentionId, }: {
2466
+ roomId: string;
2467
+ mentionId: string;
2468
+ }): Promise<void>;
2469
+ getTextVersion({ roomId, versionId, }: {
2470
+ roomId: string;
2471
+ versionId: string;
2472
+ }): Promise<Response>;
2473
+ createTextVersion({ roomId }: {
2474
+ roomId: string;
2475
+ }): Promise<void>;
2476
+ reportTextEditor({ roomId, type, rootKey, }: {
2477
+ roomId: string;
2478
+ type: TextEditorType;
2479
+ rootKey: string;
2480
+ }): Promise<void>;
2481
+ listTextVersions({ roomId }: {
2482
+ roomId: string;
2483
+ }): Promise<{
2484
+ versions: {
2485
+ type: "historyVersion";
2486
+ kind: "yjs";
2487
+ id: string;
2488
+ authors: {
2489
+ id: string;
2490
+ }[];
2491
+ createdAt: Date;
2492
+ }[];
2493
+ requestedAt: Date;
2494
+ }>;
2495
+ listTextVersionsSince({ roomId, since, signal, }: {
2496
+ roomId: string;
2497
+ since: Date;
2498
+ signal?: AbortSignal;
2499
+ }): Promise<{
2500
+ versions: {
2501
+ type: "historyVersion";
2502
+ kind: "yjs";
2503
+ id: string;
2504
+ authors: {
2505
+ id: string;
2506
+ }[];
2507
+ createdAt: Date;
2508
+ }[];
2509
+ requestedAt: Date;
2510
+ }>;
2511
+ streamStorage(options: {
2512
+ roomId: string;
2513
+ }): Promise<IdTuple<SerializedCrdt>[]>;
2514
+ sendMessages<P extends JsonObject, E extends Json>(options: {
2515
+ roomId: string;
2516
+ nonce: string | undefined;
2517
+ messages: ClientMsg<P, E>[];
2518
+ }): Promise<Response>;
2519
+ }
2520
+ interface NotificationHttpApi<M extends BaseMetadata> {
2521
+ getInboxNotifications(options?: {
2522
+ cursor?: string;
2523
+ }): Promise<{
2524
+ inboxNotifications: InboxNotificationData[];
2525
+ threads: ThreadData<M>[];
2526
+ nextCursor: string | null;
2527
+ requestedAt: Date;
2528
+ }>;
2529
+ getInboxNotificationsSince(options: {
2530
+ since: Date;
2531
+ signal?: AbortSignal;
2532
+ }): Promise<{
2533
+ inboxNotifications: {
2534
+ updated: InboxNotificationData[];
2535
+ deleted: InboxNotificationDeleteInfo[];
2536
+ };
2537
+ threads: {
2538
+ updated: ThreadData<M>[];
2539
+ deleted: ThreadDeleteInfo[];
2540
+ };
2541
+ requestedAt: Date;
2542
+ }>;
2543
+ getUnreadInboxNotificationsCount(): Promise<number>;
2544
+ markAllInboxNotificationsAsRead(): Promise<void>;
2545
+ markInboxNotificationAsRead(inboxNotificationId: string): Promise<void>;
2546
+ deleteAllInboxNotifications(): Promise<void>;
2547
+ deleteInboxNotification(inboxNotificationId: string): Promise<void>;
2548
+ }
2549
+ interface LiveblocksHttpApi<M extends BaseMetadata> extends RoomHttpApi<M>, NotificationHttpApi<M> {
2550
+ getUserThreads_experimental(options?: {
2551
+ cursor?: string;
2552
+ query?: {
2553
+ resolved?: boolean;
2554
+ metadata?: Partial<QueryMetadata<M>>;
2555
+ };
2556
+ }): Promise<{
2557
+ threads: ThreadData<M>[];
2558
+ inboxNotifications: InboxNotificationData[];
2559
+ nextCursor: string | null;
2560
+ requestedAt: Date;
2561
+ permissionHints: Record<string, Permission[]>;
2562
+ }>;
2563
+ getUserThreadsSince_experimental(options: {
2564
+ since: Date;
2565
+ signal?: AbortSignal;
2566
+ }): Promise<{
2567
+ inboxNotifications: {
2568
+ updated: InboxNotificationData[];
2569
+ deleted: InboxNotificationDeleteInfo[];
2570
+ };
2571
+ threads: {
2572
+ updated: ThreadData<M>[];
2573
+ deleted: ThreadDeleteInfo[];
2574
+ };
2575
+ requestedAt: Date;
2576
+ permissionHints: Record<string, Permission[]>;
2577
+ }>;
2578
+ }
2579
+
2580
+ /**
2581
+ * A Store is just a mini Zustand store.
2582
+ */
2583
+ declare type Store<T> = {
2584
+ get: () => Readonly<T>;
2585
+ set: (callback: (currentState: Readonly<T>) => Readonly<T>) => void;
2586
+ subscribe: (callback: () => void) => () => void;
2587
+ batch: (callback: () => void) => void;
2371
2588
  };
2589
+ /**
2590
+ * Create a store for an immutable state. Close to Zustand's vanilla store conceptually but with less features.
2591
+ */
2592
+ declare function createStore<T>(initialState: T): Store<T>;
2593
+
2594
+ /**
2595
+ * Back-port of TypeScript 5.4's built-in NoInfer utility type.
2596
+ * See https://stackoverflow.com/a/56688073/148872
2597
+ */
2598
+ declare type NoInfr<A> = [A][A extends any ? 0 : never];
2372
2599
 
2373
2600
  declare type OptionalPromise<T> = T | Promise<T>;
2374
2601
 
@@ -2441,29 +2668,13 @@ declare type InternalSyncStatus = SyncStatus | "has-local-changes";
2441
2668
  * will probably happen if you do.
2442
2669
  */
2443
2670
  declare type PrivateClientApi<U extends BaseUserMeta, M extends BaseMetadata> = {
2444
- readonly currentUserIdStore: Store<string | null>;
2671
+ readonly currentUserIdStore: Store<string | undefined>;
2445
2672
  readonly mentionSuggestionsCache: Map<string, string[]>;
2446
2673
  readonly resolveMentionSuggestions: ClientOptions<U>["resolveMentionSuggestions"];
2447
2674
  readonly usersStore: BatchStore<U["info"] | undefined, string>;
2448
2675
  readonly roomsInfoStore: BatchStore<DRI | undefined, string>;
2449
2676
  readonly getRoomIds: () => string[];
2450
- readonly getUserThreads_experimental: (options: GetUserThreadsOptions<M>) => Promise<{
2451
- threads: ThreadData<M>[];
2452
- inboxNotifications: InboxNotificationData[];
2453
- nextCursor: string | null;
2454
- requestedAt: Date;
2455
- }>;
2456
- readonly getUserThreadsSince_experimental: (options: GetUserThreadsSinceOptions) => Promise<{
2457
- inboxNotifications: {
2458
- updated: InboxNotificationData[];
2459
- deleted: InboxNotificationDeleteInfo[];
2460
- };
2461
- threads: {
2462
- updated: ThreadData<M>[];
2463
- deleted: ThreadDeleteInfo[];
2464
- };
2465
- requestedAt: Date;
2466
- }>;
2677
+ readonly httpClient: LiveblocksHttpApi<M>;
2467
2678
  as<M2 extends BaseMetadata>(): Client<U, M2>;
2468
2679
  createSyncSource(): SyncSource;
2469
2680
  };
@@ -2485,7 +2696,9 @@ declare type NotificationsApi<M extends BaseMetadata> = {
2485
2696
  * const data = await client.getInboxNotifications(); // Fetch initial page (of 20 inbox notifications)
2486
2697
  * const data = await client.getInboxNotifications({ cursor: nextCursor }); // Fetch next page (= next 20 inbox notifications)
2487
2698
  */
2488
- getInboxNotifications(options?: GetInboxNotificationsOptions): Promise<{
2699
+ getInboxNotifications(options?: {
2700
+ cursor?: string;
2701
+ }): Promise<{
2489
2702
  inboxNotifications: InboxNotificationData[];
2490
2703
  threads: ThreadData<M>[];
2491
2704
  nextCursor: string | null;
@@ -2510,7 +2723,10 @@ declare type NotificationsApi<M extends BaseMetadata> = {
2510
2723
  * requestedAt,
2511
2724
  * } = await client.getInboxNotificationsSince({ since: result.requestedAt }});
2512
2725
  */
2513
- getInboxNotificationsSince(options: GetInboxNotificationsSinceOptions): Promise<{
2726
+ getInboxNotificationsSince(options: {
2727
+ since: Date;
2728
+ signal?: AbortSignal;
2729
+ }): Promise<{
2514
2730
  inboxNotifications: {
2515
2731
  updated: InboxNotificationData[];
2516
2732
  deleted: InboxNotificationDeleteInfo[];
@@ -2962,6 +3178,7 @@ declare function Promise_withResolvers<T>(): {
2962
3178
 
2963
3179
  declare function createThreadId(): string;
2964
3180
  declare function createCommentId(): string;
3181
+ declare function createCommentAttachmentId(): string;
2965
3182
  declare function createInboxNotificationId(): string;
2966
3183
 
2967
3184
  /**
@@ -3427,4 +3644,4 @@ declare const CommentsApiError: typeof HttpError;
3427
3644
  /** @deprecated Use HttpError instead. */
3428
3645
  declare const NotificationsApiError: typeof HttpError;
3429
3646
 
3430
- export { type AckOp, type ActivityData, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type BaseActivitiesData, type BaseAuthResult, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, CommentsApiError, type CommentsEventServerMsg, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type DistributiveOmit, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type GetThreadsOptions, type GetUserThreadsOptions, type History, type HistoryVersion, HttpError, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IYjsProvider, type IdTuple, type Immutable, type InboxNotificationCustomData, type InboxNotificationCustomDataPlain, type InboxNotificationData, type InboxNotificationDataPlain, type InboxNotificationDeleteInfo, type InboxNotificationTextMentionData, type InboxNotificationTextMentionDataPlain, type InboxNotificationThreadData, type InboxNotificationThreadDataPlain, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LostConnectionEvent, type Lson, type LsonObject, type NoInfr, type NodeMap, NotificationsApiError, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalPromise, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialUnless, type Patchable, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type Poller, type PrivateClientApi, type PrivateRoomApi, Promise_withResolvers, type QueryMetadata, type QueryParams, type RejectedStorageOpServerMsg, type Resolve, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomEventMessage, type RoomNotificationSettings, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, SortedList, type Status, type StorageStatus, type StorageUpdate, type Store, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToThreadData, createClient, createCommentId, createInboxNotificationId, createStore, createThreadId, deprecate, deprecateIf, detectDupes, errorIf, freeze, generateCommentUrl, getMentionedIdsFromCommentBody, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, kInternal, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, raise, resolveUsersInCommentBody, shallow, stringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, url, urljoin, wait, withTimeout };
3647
+ export { type AckOp, type ActivityData, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type BaseActivitiesData, type BaseAuthResult, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, CommentsApiError, type CommentsEventServerMsg, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type DistributiveOmit, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type GetThreadsOptions, type History, type HistoryVersion, HttpError, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IYjsProvider, type IdTuple, type Immutable, type InboxNotificationCustomData, type InboxNotificationCustomDataPlain, type InboxNotificationData, type InboxNotificationDataPlain, type InboxNotificationDeleteInfo, type InboxNotificationTextMentionData, type InboxNotificationTextMentionDataPlain, type InboxNotificationThreadData, type InboxNotificationThreadDataPlain, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LostConnectionEvent, type Lson, type LsonObject, type NoInfr, type NodeMap, NotificationsApiError, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalPromise, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialUnless, type Patchable, Permission, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type Poller, type PrivateClientApi, type PrivateRoomApi, Promise_withResolvers, type QueryMetadata, type QueryParams, type RejectedStorageOpServerMsg, type Resolve, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomEventMessage, type RoomNotificationSettings, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, SortedList, type Status, type StorageStatus, type StorageUpdate, type Store, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToThreadData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createStore, createThreadId, deprecate, deprecateIf, detectDupes, errorIf, freeze, generateCommentUrl, getMentionedIdsFromCommentBody, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, kInternal, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, raise, resolveUsersInCommentBody, shallow, stringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, url, urljoin, wait, withTimeout };