@pluv/client 3.2.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,354 +1,356 @@
1
- import { AbstractCrdtDocFactory, InferDocLike, NoopCrdtDocFactory, InferStorage, InferDoc, InferCrdtJson } from '@pluv/crdt';
2
- export { CrdtType, InferCrdtJson } from '@pluv/crdt';
3
- import { IOLike, JsonObject, EventRecord, CrdtDocLike, UserInfo, MaybePromise, Id, ProcedureLike, InputZodLike, IORouterLike, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, RoomLike, InferIOOutput, InferIOInput, RoomEventListenerMap, BroadcastProxy, WebSocketConnection, SubscribeProxy, UpdateMyPresenceAction, InferIOCrdtKind, MergeEvents } from '@pluv/types';
4
- export { BaseUser, ConnectionState, EventMessage, EventNotifierSubscriptionCallback, EventRecord, IOEventMessage, MergeEvents, RoomLike, UserInfo, WebSocketConnection, WebSocketState } from '@pluv/types';
1
+ import { BaseUser, BaseUser as BaseUser$1, BroadcastProxy, ConnectionState, CrdtDocLike, EventMessage, EventNotifierSubscriptionCallback, EventRecord, EventRecord as EventRecord$1, IOEventMessage, IOLike, IORouterLike, Id, InferIOAuthorize, InferIOAuthorizeUser, InferIOCrdt, InferIOCrdtKind, InferIOEvents, InferIOInput, InferIOOutput, InputZodLike, JsonObject, MaybePromise, MergeEvents, MergeEvents as MergeEvents$1, ProcedureLike, RoomEventListenerMap, RoomLike, RoomLike as RoomLike$1, SubscribeProxy, UpdateMyPresenceAction, UserInfo, UserInfo as UserInfo$1, WebSocketConnection, WebSocketConnection as WebSocketConnection$1, WebSocketState } from "@pluv/types";
2
+ import { AbstractCrdtDocFactory, CrdtType, InferCrdtJson, InferCrdtJson as InferCrdtJson$1, InferDoc, InferDocLike, InferStorage, NoopCrdtDocFactory } from "@pluv/crdt";
5
3
 
4
+ //#region src/AbstractStorageStore.d.ts
6
5
  declare abstract class AbstractStorageStore {
7
- room: string;
8
- constructor(room: string);
9
- abstract addUpdate(update: string): Promise<void>;
10
- abstract destroy(): Promise<void>;
11
- abstract flatten(encodedState: string): Promise<void>;
12
- abstract getShouldFlatten(): Promise<boolean>;
13
- abstract getUpdates(start?: number): Promise<readonly string[]>;
14
- abstract initialize(): Promise<void>;
6
+ room: string;
7
+ constructor(room: string);
8
+ abstract addUpdate(update: string): Promise<void>;
9
+ abstract destroy(): Promise<void>;
10
+ abstract flatten(encodedState: string): Promise<void>;
11
+ abstract getShouldFlatten(): Promise<boolean>;
12
+ abstract getUpdates(start?: number): Promise<readonly string[]>;
13
+ abstract initialize(): Promise<void>;
15
14
  }
16
-
15
+ //#endregion
16
+ //#region src/utils/identity.d.ts
17
17
  declare const identity: <T extends unknown>(x: T) => T;
18
-
18
+ //#endregion
19
+ //#region src/infer.d.ts
19
20
  type InferCallback<TIO extends IOLike<any, any, any>> = (i: typeof identity) => {
20
- io: (io: TIO) => TIO;
21
+ io: (io: TIO) => TIO;
21
22
  };
22
- declare const infer: <TIO extends IOLike<any, any, any>>(callback: InferCallback<TIO>) => InferCallback<TIO>;
23
-
24
- type EventResolver<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord<string, any>, TPresence extends Record<string, any>, TDocLike extends CrdtDocLike<any, any>> = (data: TInput, context: EventResolverContext<TIO, TPresence, TDocLike>) => MaybePromise<TOutput | void>;
23
+ declare const infer: <TIO extends IOLike<any, any, any>>(callback: InferCallback<TIO>) => InferCallback<IOLike<InferIOAuthorize<TIO>, InferIOCrdt<TIO>, InferIOEvents<TIO>>>;
24
+ //#endregion
25
+ //#region src/types.d.ts
26
+ type EventResolver<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord$1<string, any>, TPresence extends Record<string, any>, TDocLike extends CrdtDocLike<any, any>> = (data: TInput, context: EventResolverContext<TIO, TPresence, TDocLike>) => MaybePromise<TOutput | void>;
25
27
  interface EventResolverContext<TIO extends IOLike, TPresence extends Record<string, any>, TDocLike extends CrdtDocLike<any, any>> {
26
- doc: TDocLike;
27
- others: readonly UserInfo<TIO, TPresence>[];
28
- room: string;
29
- user: UserInfo<TIO, TPresence>;
28
+ doc: TDocLike;
29
+ others: readonly UserInfo$1<TIO, TPresence>[];
30
+ room: string;
31
+ user: UserInfo$1<TIO, TPresence>;
30
32
  }
31
33
  type InferMetadata<TClient extends PluvClient<any, any, any, any>> = TClient extends PluvClient<any, any, any, infer IMetadata> ? IMetadata : never;
32
- type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot extends EventRecord<string, any> = {}> = TEventRecords extends [
33
- infer IHead extends EventRecord<string, any>,
34
- ...infer ITail extends EventRecord<string, any>[]
35
- ] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
36
- [P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
37
- }> : Id<TRoot>;
34
+ type MergeEventRecords<TEventRecords extends EventRecord$1<string, any>[], TRoot extends EventRecord$1<string, any> = {}> = TEventRecords extends [infer IHead extends EventRecord$1<string, any>, ...infer ITail extends EventRecord$1<string, any>[]] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & { [P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P] }> : Id<TRoot>;
38
35
  interface PluvClientLimits {
39
- /**
40
- * @description Maximum size of presence object in bytes
41
- */
42
- presenceMaxSize?: number | null;
36
+ /**
37
+ * @description Maximum size of presence object in bytes
38
+ */
39
+ presenceMaxSize?: number | null;
43
40
  }
44
41
  interface PublicKeyParams<TMetadata extends JsonObject> {
45
- metadata: TMetadata;
42
+ metadata: TMetadata;
46
43
  }
47
44
  type PublicKey<TMetadata extends JsonObject> = string | ((params: PublicKeyParams<TMetadata>) => string);
48
45
  type WithMetadata<TMetadata extends JsonObject = {}> = keyof TMetadata extends never ? {
49
- metadata?: undefined;
46
+ metadata?: undefined;
50
47
  } : {
51
- metadata: TMetadata;
48
+ metadata: TMetadata;
52
49
  };
53
-
54
- interface PluvProcedureConfig<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord<string, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> {
55
- broadcast?: EventResolver<TIO, TInput, TOutput, TPresence, InferDocLike<TCrdt>> | null;
56
- input?: InputZodLike<TInput>;
50
+ //#endregion
51
+ //#region src/PluvProcedure.d.ts
52
+ interface PluvProcedureConfig<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord$1<string, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> {
53
+ broadcast?: EventResolver<TIO, TInput, TOutput, TPresence, InferDocLike<TCrdt>> | null;
54
+ input?: InputZodLike<TInput>;
57
55
  }
58
- declare class PluvProcedure<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord<string, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TFilled extends "input" | "broadcast" | ""> implements ProcedureLike<TInput, TOutput> {
59
- private _broadcast;
60
- private _input;
61
- get config(): ProcedureLike<TInput, TOutput>["config"];
62
- constructor(config?: PluvProcedureConfig<TIO, TInput, TOutput, TPresence, TCrdt>);
63
- broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TIO, TInput, TResult, TPresence, InferDocLike<TCrdt>>): Omit<PluvProcedure<TIO, TInput, MergeEventRecords<[TOutput, TResult]>, TPresence, TCrdt, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
64
- input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TIO, TData, {}, TPresence, TCrdt, TFilled | "input">, TFilled | "input">;
65
- private _resolver;
56
+ declare class PluvProcedure<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord$1<string, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TFilled extends "input" | "broadcast" | ""> implements ProcedureLike<TInput, TOutput> {
57
+ private _broadcast;
58
+ private _input;
59
+ get config(): ProcedureLike<TInput, TOutput>["config"];
60
+ constructor(config?: PluvProcedureConfig<TIO, TInput, TOutput, TPresence, TCrdt>);
61
+ broadcast<TResult extends EventRecord$1<string, any> = {}>(resolver: EventResolver<TIO, TInput, TResult, TPresence, InferDocLike<TCrdt>>): Omit<PluvProcedure<TIO, TInput, MergeEventRecords<[TOutput, TResult]>, TPresence, TCrdt, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
62
+ input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TIO, TData, {}, TPresence, TCrdt, TFilled | "input">, TFilled | "input">;
63
+ private _resolver;
66
64
  }
67
-
65
+ //#endregion
66
+ //#region src/CrdtManager.d.ts
68
67
  type CrdtManagerOptions<TCrdt extends AbstractCrdtDocFactory<any, any>> = {
69
- initialStorage?: TCrdt;
68
+ initialStorage?: TCrdt;
70
69
  };
71
-
70
+ //#endregion
71
+ //#region src/PluvRouter.d.ts
72
72
  type PluvRouterEventConfig<TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> = {
73
- [P: string]: Pick<PluvProcedure<TIO, any, any, TPresence, TCrdt, "">, "config">;
73
+ [P: string]: Pick<PluvProcedure<TIO, any, any, TPresence, TCrdt, "">, "config">;
74
74
  };
75
- type MergedRouter<TRouters extends PluvRouter<TIO, TPresence, TCrdt, any>[], TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TRoot extends TRouters[0]["_defs"]["events"]> = TRouters extends [
76
- infer IHead extends PluvRouter<TIO, TPresence, TCrdt, any>,
77
- ...infer ITail extends PluvRouter<TIO, TPresence, TCrdt, any>[]
78
- ] ? MergedRouter<ITail, TIO, TPresence, TCrdt, TRoot & IHead["_defs"]["events"]> : PluvRouter<TIO, TPresence, TCrdt, TRoot>;
75
+ type MergedRouter<TRouters extends PluvRouter<TIO, TPresence, TCrdt, any>[], TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TRoot extends TRouters[0]["_defs"]["events"]> = TRouters extends [infer IHead extends PluvRouter<TIO, TPresence, TCrdt, any>, ...infer ITail extends PluvRouter<TIO, TPresence, TCrdt, any>[]] ? MergedRouter<ITail, TIO, TPresence, TCrdt, TRoot & IHead["_defs"]["events"]> : PluvRouter<TIO, TPresence, TCrdt, TRoot>;
79
76
  declare class PluvRouter<TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TEvents extends PluvRouterEventConfig<TIO, TPresence, TCrdt> = {}> implements IORouterLike<TEvents> {
80
- readonly _defs: {
81
- events: TEvents;
82
- };
83
- constructor(events: TEvents);
84
- static merge<TRouters extends PluvRouter<TIO, TPresence, TCrdt, any>[], TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>>(...routers: TRouters): MergedRouter<TRouters, TIO, TPresence, TCrdt, {}>;
85
- private _isValidEventName;
77
+ readonly _defs: {
78
+ events: TEvents;
79
+ };
80
+ constructor(events: TEvents);
81
+ static merge<TRouters extends PluvRouter<TIO, TPresence, TCrdt, any>[], TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>>(...routers: TRouters): MergedRouter<TRouters, TIO, TPresence, TCrdt, {}>;
82
+ private _isValidEventName;
86
83
  }
87
-
84
+ //#endregion
85
+ //#region src/UsersManager.d.ts
88
86
  type UsersManagerConfig<TPresence extends Record<string, any> = {}> = {
89
- initialPresence?: TPresence;
90
- limits: PluvClientLimits;
91
- presence?: InputZodLike<TPresence>;
87
+ initialPresence?: TPresence;
88
+ limits: PluvClientLimits;
89
+ presence?: InputZodLike<TPresence>;
92
90
  };
93
-
91
+ //#endregion
92
+ //#region src/PluvRoom.d.ts
94
93
  declare global {
95
- var process: {
96
- env: {
97
- [key: string]: string | undefined;
98
- };
94
+ var process: {
95
+ env: {
96
+ [key: string]: string | undefined;
99
97
  };
98
+ };
100
99
  }
101
100
  interface EndpointParams<TMetadata extends JsonObject> {
102
- metadata: TMetadata;
103
- room: string;
101
+ metadata: TMetadata;
102
+ room: string;
104
103
  }
105
104
  type AuthEndpoint<TMetadata extends JsonObject> = string | ((params: EndpointParams<TMetadata>) => string | FetchOptions) | true;
106
105
  type WsEndpoint<TMetadata extends JsonObject> = string | ((params: EndpointParams<TMetadata>) => string);
107
106
  type FetchOptions = {
108
- url: string;
109
- options?: RequestInit;
107
+ url: string;
108
+ options?: RequestInit;
110
109
  };
111
110
  type RoomEndpoints<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject> = {
112
- wsEndpoint?: WsEndpoint<TMetadata>;
113
- } & (InferIOAuthorizeUser<InferIOAuthorize<TIO>> extends BaseUser ? {
114
- authEndpoint: AuthEndpoint<TMetadata>;
111
+ wsEndpoint?: WsEndpoint<TMetadata>;
112
+ } & (InferIOAuthorizeUser<InferIOAuthorize<TIO>> extends BaseUser$1 ? {
113
+ authEndpoint: AuthEndpoint<TMetadata>;
115
114
  } : {
116
- authEndpoint?: undefined;
115
+ authEndpoint?: undefined;
117
116
  });
118
117
  type PluvRoomAddon<TIO extends IOLike, TMetadata extends JsonObject, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> = (input: PluvRoomAddonInput<TIO, TMetadata, TPresence, TCrdt>) => Partial<PluvRoomAddonResult>;
119
118
  interface PluvRoomAddonInput<TIO extends IOLike, TMetadata extends JsonObject, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> {
120
- room: PluvRoom<TIO, TMetadata, TPresence, TCrdt>;
119
+ room: PluvRoom<TIO, TMetadata, TPresence, TCrdt>;
121
120
  }
122
121
  interface PluvRoomAddonResult {
123
- storage: AbstractStorageStore;
122
+ storage: AbstractStorageStore;
124
123
  }
125
124
  type PluvRoomDebug<TIO extends IOLike> = Id<{
126
- output: readonly (keyof InferIOOutput<TIO>)[];
127
- input: readonly (keyof InferIOInput<TIO>)[];
125
+ output: readonly (keyof InferIOOutput<TIO>)[];
126
+ input: readonly (keyof InferIOInput<TIO>)[];
128
127
  }>;
129
128
  type RoomConnectParams<TMetadata extends JsonObject = {}> = keyof TMetadata extends never ? [] : [WithMetadata<TMetadata>];
130
129
  interface ReconnectTimeoutMsParams {
131
- attempts: number;
130
+ attempts: number;
132
131
  }
133
132
  type ReconnectTimeoutMs = number | ((params: ReconnectTimeoutMsParams) => number);
134
133
  type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>>> = Id<{
135
- addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TCrdt>[];
136
- debug?: boolean | PluvRoomDebug<TIO>;
137
- limits: PluvClientLimits;
138
- onAuthorizationFail?: (error: Error) => void;
139
- metadata?: InputZodLike<TMetadata>;
140
- publicKey?: PublicKey<TMetadata>;
141
- reconnectTimeoutMs?: ReconnectTimeoutMs;
142
- router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
134
+ addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TCrdt>[];
135
+ debug?: boolean | PluvRoomDebug<TIO>;
136
+ limits: PluvClientLimits;
137
+ onAuthorizationFail?: (error: Error) => void;
138
+ metadata?: InputZodLike<TMetadata>;
139
+ publicKey?: PublicKey<TMetadata>;
140
+ reconnectTimeoutMs?: ReconnectTimeoutMs;
141
+ router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
143
142
  } & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TCrdt>, "initialStorage"> & UsersManagerConfig<TPresence>>;
144
- declare class PluvRoom<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject = {}, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> implements RoomLike<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
145
- #private;
146
- readonly _endpoints: RoomEndpoints<TIO, TMetadata>;
147
- readonly id: string;
148
- readonly metadata?: InputZodLike<TMetadata>;
149
- private readonly _crdtManager;
150
- private readonly _crdtNotifier;
151
- private readonly _debug;
152
- private readonly _eventNotifier;
153
- private readonly _intervals;
154
- private readonly _limits;
155
- private readonly _listenerManager;
156
- private readonly _listeners;
157
- private readonly _publicKey;
158
- private readonly _reconnectTimeoutMs;
159
- private readonly _router;
160
- private readonly _stateNotifier;
161
- private readonly _storageStore;
162
- private readonly _subscriptions;
163
- private readonly _timeouts;
164
- private readonly _usersManager;
165
- private readonly _usersNotifier;
166
- private _lastMetadata;
167
- private _state;
168
- private _windowListeners;
169
- private _wsListeners;
170
- constructor(room: string, options: RoomConfig<TIO, TMetadata, TPresence, TCrdt, TEvents>);
171
- get webSocket(): WebSocket | null;
172
- addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
173
- broadcast: BroadcastProxy<TIO, TEvents>;
174
- canRedo: () => boolean;
175
- canUndo: () => boolean;
176
- connect(...args: RoomConnectParams<TMetadata>): Promise<void>;
177
- disconnect(): Promise<void>;
178
- getConnection: () => WebSocketConnection;
179
- getDoc: () => CrdtDocLike<InferDoc<TCrdt>, InferStorage<TCrdt>>;
180
- getMyPresence: () => TPresence;
181
- getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
182
- getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
183
- getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
184
- getStorage: <TKey extends keyof InferStorage<TCrdt>>(type: TKey) => InferStorage<TCrdt>[TKey] | null;
185
- getStorageJson(): InferCrdtJson<InferStorage<TCrdt>> | null;
186
- getStorageJson<TKey extends keyof InferStorage<TCrdt>>(type: TKey): InferCrdtJson<InferStorage<TCrdt>[TKey]> | null;
187
- getStorageLoaded: () => boolean;
188
- redo: () => void;
189
- subscribe: SubscribeProxy<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
190
- transact: (fn: (storage: InferStorage<TCrdt>) => void, origin?: string) => void;
191
- undo: () => void;
192
- updateMyPresence: (presence: UpdateMyPresenceAction<TPresence>) => void;
193
- private _addToStorageStore;
194
- private _attachWindowListeners;
195
- private _attachWsListeners;
196
- private _clearInterval;
197
- private _clearTimeout;
198
- private _closeWs;
199
- private _detachWindowListeners;
200
- private _detachWsListeners;
201
- private _emitSharedTypes;
202
- private _event;
203
- private _flattenStorageStore;
204
- private _getAddon;
205
- private _getAuthFetchOptions;
206
- private _getAuthorization;
207
- private _getPublicKey;
208
- private _getWsEndpoint;
209
- private _handleExit;
210
- private _handlePresenceUpdatedMessage;
211
- private _handleReceiveOthers;
212
- private _handleRegisteredMessage;
213
- private _handleStorageReceivedMessage;
214
- private _handleStorageUpdatedMessage;
215
- private _handleSyncStateReceived;
216
- private _handleUserJoinedMessage;
217
- private _heartbeat;
218
- private _logDebug;
219
- private _observeCrdt;
220
- private _onAuthorizationFail;
221
- private _onClose;
222
- /**
223
- * TODO
224
- * @description Handle websocket errors in a meaningful way, should they occur
225
- * @date August 19, 2022
226
- */
227
- private _onError;
228
- private _onMessage;
229
- private _onOpen;
230
- private _onNavigatorOffline;
231
- private _onNavigatorOnline;
232
- private _onVisibilityChange;
233
- private _onWindowFocus;
234
- private _other;
235
- private _parseMessage;
236
- private _pollReconnect;
237
- private _reconnect;
238
- private _sendMessage;
239
- private _setMetadata;
240
- private _updateState;
143
+ declare class PluvRoom<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject = {}, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> implements RoomLike$1<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
144
+ #private;
145
+ readonly _endpoints: RoomEndpoints<TIO, TMetadata>;
146
+ readonly id: string;
147
+ readonly metadata?: InputZodLike<TMetadata>;
148
+ private readonly _crdtManager;
149
+ private readonly _crdtNotifier;
150
+ private readonly _debug;
151
+ private readonly _eventNotifier;
152
+ private readonly _intervals;
153
+ private readonly _limits;
154
+ private readonly _listenerManager;
155
+ private readonly _listeners;
156
+ private readonly _publicKey;
157
+ private readonly _reconnectTimeoutMs;
158
+ private readonly _router;
159
+ private readonly _stateNotifier;
160
+ private readonly _storageStore;
161
+ private readonly _subscriptions;
162
+ private readonly _timeouts;
163
+ private readonly _usersManager;
164
+ private readonly _usersNotifier;
165
+ private _lastMetadata;
166
+ private _state;
167
+ private _windowListeners;
168
+ private _wsListeners;
169
+ constructor(room: string, options: RoomConfig<TIO, TMetadata, TPresence, TCrdt, TEvents>);
170
+ get webSocket(): WebSocket | null;
171
+ addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
172
+ broadcast: BroadcastProxy<TIO, TEvents>;
173
+ canRedo: () => boolean;
174
+ canUndo: () => boolean;
175
+ connect(...args: RoomConnectParams<TMetadata>): Promise<void>;
176
+ disconnect(): Promise<void>;
177
+ getConnection: () => WebSocketConnection$1;
178
+ getDoc: () => CrdtDocLike<InferDoc<TCrdt>, InferStorage<TCrdt>>;
179
+ getMyPresence: () => TPresence;
180
+ getMyself: () => Id<UserInfo$1<TIO, TPresence>> | null;
181
+ getOther: (connectionId: string) => Id<UserInfo$1<TIO, TPresence>> | null;
182
+ getOthers: () => readonly Id<UserInfo$1<TIO, TPresence>>[];
183
+ getStorage: <TKey extends keyof InferStorage<TCrdt>>(type: TKey) => InferStorage<TCrdt>[TKey] | null;
184
+ getStorageJson(): InferCrdtJson$1<InferStorage<TCrdt>> | null;
185
+ getStorageJson<TKey extends keyof InferStorage<TCrdt>>(type: TKey): InferCrdtJson$1<InferStorage<TCrdt>[TKey]> | null;
186
+ getStorageLoaded: () => boolean;
187
+ redo: () => void;
188
+ subscribe: SubscribeProxy<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
189
+ transact: (fn: (storage: InferStorage<TCrdt>) => void, origin?: string) => void;
190
+ undo: () => void;
191
+ updateMyPresence: (presence: UpdateMyPresenceAction<TPresence>) => void;
192
+ private _addToStorageStore;
193
+ private _attachWindowListeners;
194
+ private _attachWsListeners;
195
+ private _clearInterval;
196
+ private _clearTimeout;
197
+ private _closeWs;
198
+ private _detachWindowListeners;
199
+ private _detachWsListeners;
200
+ private _emitSharedTypes;
201
+ private _event;
202
+ private _flattenStorageStore;
203
+ private _getAddon;
204
+ private _getAuthFetchOptions;
205
+ private _getAuthorization;
206
+ private _getPublicKey;
207
+ private _getWsEndpoint;
208
+ private _handleExit;
209
+ private _handlePresenceUpdatedMessage;
210
+ private _handleReceiveOthers;
211
+ private _handleRegisteredMessage;
212
+ private _handleStorageReceivedMessage;
213
+ private _handleStorageUpdatedMessage;
214
+ private _handleSyncStateReceived;
215
+ private _handleUserJoinedMessage;
216
+ private _heartbeat;
217
+ private _logDebug;
218
+ private _observeCrdt;
219
+ private _onAuthorizationFail;
220
+ private _onClose;
221
+ /**
222
+ * TODO
223
+ * @description Handle websocket errors in a meaningful way, should they occur
224
+ * @date August 19, 2022
225
+ */
226
+ private _onError;
227
+ private _onMessage;
228
+ private _onOpen;
229
+ private _onNavigatorOffline;
230
+ private _onNavigatorOnline;
231
+ private _onVisibilityChange;
232
+ private _onWindowFocus;
233
+ private _other;
234
+ private _parseMessage;
235
+ private _pollReconnect;
236
+ private _reconnect;
237
+ private _sendMessage;
238
+ private _setMetadata;
239
+ private _updateState;
241
240
  }
242
-
241
+ //#endregion
242
+ //#region src/PluvClient.d.ts
243
243
  type PluvClientOptions<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any>, TCrdt extends InferIOCrdtKind<TIO>, TMetadata extends JsonObject> = RoomEndpoints<TIO, TMetadata> & {
244
- debug?: boolean;
245
- /**
246
- * @description Configurable limits defined for client-side validation. You should only set
247
- * this if you control the server and have changed the limits there.
248
- */
249
- limits?: PluvClientLimits;
250
- metadata?: InputZodLike<TMetadata>;
251
- presence?: InputZodLike<TPresence>;
252
- publicKey?: PublicKey<TMetadata>;
253
- types: InferCallback<TIO>;
244
+ debug?: boolean;
245
+ /**
246
+ * @description Configurable limits defined for client-side validation. You should only set
247
+ * this if you control the server and have changed the limits there.
248
+ */
249
+ limits?: PluvClientLimits;
250
+ metadata?: InputZodLike<TMetadata>;
251
+ presence?: InputZodLike<TPresence>;
252
+ publicKey?: PublicKey<TMetadata>;
253
+ types: InferCallback<TIO>;
254
254
  } & (InferIOCrdtKind<TIO> extends NoopCrdtDocFactory ? {
255
- initialStorage?: "[ERROR]: Must provide crdt to createIO to use storage";
255
+ initialStorage?: "[ERROR]: Must provide crdt to createIO to use storage";
256
256
  } : {
257
- initialStorage?: TCrdt;
257
+ initialStorage?: TCrdt;
258
258
  });
259
259
  type CreateRoomOptions<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> = {
260
- addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, InferStorage<TCrdt>>[];
261
- debug?: boolean | PluvRoomDebug<TIO>;
262
- initialPresence?: TPresence;
263
- initialStorage?: TCrdt;
264
- onAuthorizationFail?: (error: Error) => void;
265
- reconnectTimeoutMs?: ReconnectTimeoutMs;
266
- router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
260
+ addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, InferStorage<TCrdt>>[];
261
+ debug?: boolean | PluvRoomDebug<TIO>;
262
+ initialPresence?: TPresence;
263
+ initialStorage?: TCrdt;
264
+ onAuthorizationFail?: (error: Error) => void;
265
+ reconnectTimeoutMs?: ReconnectTimeoutMs;
266
+ router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
267
267
  };
268
268
  type EnterRoomParams<TMetadata extends JsonObject = {}> = keyof TMetadata extends never ? [] : [WithMetadata<TMetadata>];
269
269
  declare class PluvClient<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any> = {}, TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>, TMetadata extends JsonObject = {}> {
270
- readonly metadata?: InputZodLike<TMetadata>;
271
- private readonly _authEndpoint;
272
- private readonly _debug;
273
- private readonly _initialStorage?;
274
- private readonly _limits;
275
- private readonly _presence?;
276
- private readonly _publicKey;
277
- private readonly _rooms;
278
- private readonly _wsEndpoint;
279
- get _defs(): {
280
- initialStorage: TCrdt | undefined;
281
- };
282
- get procedure(): PluvProcedure<TIO, {}, {}, TPresence, TCrdt, "">;
283
- constructor(options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>);
284
- createRoom: <TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}>(room: string, options?: CreateRoomOptions<TIO, TPresence, TCrdt, TMetadata, TEvents>) => PluvRoom<TIO, TMetadata, TPresence, TCrdt, TEvents>;
285
- enter: (room: string | PluvRoom<TIO, TMetadata, any, any, any>, ...args: EnterRoomParams<TMetadata>) => Promise<PluvRoom<TIO, TMetadata, TPresence, TCrdt, any>>;
286
- getRoom: (room: string) => PluvRoom<TIO, TMetadata, TPresence, TCrdt, any> | null;
287
- getRooms: () => readonly PluvRoom<TIO, TMetadata, TPresence, TCrdt, any>[];
288
- leave: (room: string | PluvRoom<TIO, any, any, any>) => Promise<void>;
289
- router<TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}>(events: TEvents): PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
290
- private _logDebug;
270
+ readonly metadata?: InputZodLike<TMetadata>;
271
+ private readonly _authEndpoint;
272
+ private readonly _debug;
273
+ private readonly _initialStorage?;
274
+ private readonly _limits;
275
+ private readonly _presence?;
276
+ private readonly _publicKey;
277
+ private readonly _rooms;
278
+ private readonly _wsEndpoint;
279
+ get _defs(): {
280
+ initialStorage: TCrdt | undefined;
281
+ };
282
+ get procedure(): PluvProcedure<TIO, {}, {}, TPresence, TCrdt, "">;
283
+ constructor(options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>);
284
+ createRoom: <TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}>(room: string, options?: CreateRoomOptions<TIO, TPresence, TCrdt, TMetadata, TEvents>) => PluvRoom<TIO, TMetadata, TPresence, TCrdt, TEvents>;
285
+ enter: (room: string | PluvRoom<TIO, TMetadata, any, any, any>, ...args: EnterRoomParams<TMetadata>) => Promise<PluvRoom<TIO, TMetadata, TPresence, TCrdt, any>>;
286
+ getRoom: (room: string) => PluvRoom<TIO, TMetadata, TPresence, TCrdt, any> | null;
287
+ getRooms: () => readonly PluvRoom<TIO, TMetadata, TPresence, TCrdt, any>[];
288
+ leave: (room: string | PluvRoom<TIO, any, any, any>) => Promise<void>;
289
+ router<TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}>(events: TEvents): PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
290
+ private _logDebug;
291
291
  }
292
-
292
+ //#endregion
293
+ //#region src/createClient.d.ts
293
294
  declare const createClient: <TIO extends IOLike<any, any, any>, TPresence extends Record<string, any> = {}, TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>, TMetadata extends JsonObject = {}>(options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>) => PluvClient<TIO, TPresence, TCrdt, TMetadata>;
294
-
295
- type MockedRoomEvents<TIO extends IOLike> = Partial<{
296
- [P in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>[P]>) => Partial<InferIOOutput<TIO>>;
297
- }>;
295
+ //#endregion
296
+ //#region src/MockedRoom.d.ts
297
+ type MockedRoomEvents<TIO extends IOLike> = Partial<{ [P in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>[P]>) => Partial<InferIOOutput<TIO>> }>;
298
298
  type MockedRoomConfig<TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>>> = {
299
- events?: MockedRoomEvents<MergeEvents<TEvents, TIO>>;
300
- limits?: PluvClientLimits;
301
- router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
299
+ events?: MockedRoomEvents<MergeEvents$1<TEvents, TIO>>;
300
+ limits?: PluvClientLimits;
301
+ router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
302
302
  } & Pick<CrdtManagerOptions<TCrdt>, "initialStorage"> & Omit<UsersManagerConfig<TPresence>, "limits">;
303
- declare class MockedRoom<TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>>> implements RoomLike<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
304
- #private;
305
- readonly id: string;
306
- private readonly _crdtManager;
307
- private readonly _crdtNotifier;
308
- private readonly _eventNotifier;
309
- private readonly _events?;
310
- private readonly _limits;
311
- private readonly _usersNotifier;
312
- private readonly _router;
313
- private _state;
314
- private readonly _stateNotifier;
315
- private readonly _subscriptions;
316
- private readonly _usersManager;
317
- constructor(room: string, options: MockedRoomConfig<TIO, TPresence, TCrdt, TEvents>);
318
- addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
319
- broadcast: BroadcastProxy<TIO, TEvents>;
320
- canRedo: () => boolean;
321
- canUndo: () => boolean;
322
- getConnection: () => WebSocketConnection;
323
- getDoc(): CrdtDocLike<InferDoc<TCrdt>, InferStorage<TCrdt>>;
324
- getMyPresence: () => TPresence;
325
- getMyself: () => Id<UserInfo<TIO, TPresence>> | null;
326
- getOther: (connectionId: string) => Id<UserInfo<TIO, TPresence>> | null;
327
- getOthers: () => readonly Id<UserInfo<TIO, TPresence>>[];
328
- getStorage: <TKey extends keyof InferStorage<TCrdt>>(type: TKey) => InferStorage<TCrdt>[TKey] | null;
329
- getStorageJson(): InferCrdtJson<InferStorage<TCrdt>> | null;
330
- getStorageJson<TKey extends keyof InferStorage<TCrdt>>(type: TKey): InferCrdtJson<InferStorage<TCrdt>[TKey]> | null;
331
- getStorageLoaded(): boolean;
332
- redo: () => void;
333
- storageRoot: (fn: (value: { [P in keyof InferStorage<TCrdt>]: InferCrdtJson<InferStorage<TCrdt>[P]>; }) => void) => (() => void);
334
- subscribe: SubscribeProxy<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
335
- transact: (fn: (storage: InferStorage<TCrdt>) => void, origin?: string) => void;
336
- undo: () => void;
337
- updateMyPresence: (presence: UpdateMyPresenceAction<TPresence>) => void;
338
- private _event;
339
- private _observeCrdt;
340
- private _other;
341
- private _simulateEvent;
303
+ declare class MockedRoom<TIO extends IOLike, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>>> implements RoomLike$1<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
304
+ #private;
305
+ readonly id: string;
306
+ private readonly _crdtManager;
307
+ private readonly _crdtNotifier;
308
+ private readonly _eventNotifier;
309
+ private readonly _events?;
310
+ private readonly _limits;
311
+ private readonly _usersNotifier;
312
+ private readonly _router;
313
+ private _state;
314
+ private readonly _stateNotifier;
315
+ private readonly _subscriptions;
316
+ private readonly _usersManager;
317
+ constructor(room: string, options: MockedRoomConfig<TIO, TPresence, TCrdt, TEvents>);
318
+ addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
319
+ broadcast: BroadcastProxy<TIO, TEvents>;
320
+ canRedo: () => boolean;
321
+ canUndo: () => boolean;
322
+ getConnection: () => WebSocketConnection$1;
323
+ getDoc(): CrdtDocLike<InferDoc<TCrdt>, InferStorage<TCrdt>>;
324
+ getMyPresence: () => TPresence;
325
+ getMyself: () => Id<UserInfo$1<TIO, TPresence>> | null;
326
+ getOther: (connectionId: string) => Id<UserInfo$1<TIO, TPresence>> | null;
327
+ getOthers: () => readonly Id<UserInfo$1<TIO, TPresence>>[];
328
+ getStorage: <TKey extends keyof InferStorage<TCrdt>>(type: TKey) => InferStorage<TCrdt>[TKey] | null;
329
+ getStorageJson(): InferCrdtJson$1<InferStorage<TCrdt>> | null;
330
+ getStorageJson<TKey extends keyof InferStorage<TCrdt>>(type: TKey): InferCrdtJson$1<InferStorage<TCrdt>[TKey]> | null;
331
+ getStorageLoaded(): boolean;
332
+ redo: () => void;
333
+ storageRoot: (fn: (value: { [P in keyof InferStorage<TCrdt>]: InferCrdtJson$1<InferStorage<TCrdt>[P]> }) => void) => (() => void);
334
+ subscribe: SubscribeProxy<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
335
+ transact: (fn: (storage: InferStorage<TCrdt>) => void, origin?: string) => void;
336
+ undo: () => void;
337
+ updateMyPresence: (presence: UpdateMyPresenceAction<TPresence>) => void;
338
+ private _event;
339
+ private _observeCrdt;
340
+ private _other;
341
+ private _simulateEvent;
342
342
  }
343
-
343
+ //#endregion
344
+ //#region src/register.d.ts
344
345
  interface RegisterParams<TMetadata extends JsonObject> {
345
- authEndpoint: AuthEndpoint<TMetadata>;
346
- publicKey: string;
346
+ authEndpoint: AuthEndpoint<TMetadata>;
347
+ publicKey: string;
347
348
  }
348
349
  declare const register: <TMetadata extends JsonObject>(params: RegisterParams<TMetadata>) => {
349
- authEndpoint: AuthEndpoint<TMetadata>;
350
- publicKey: string;
351
- wsEndpoint: (params: EndpointParams<TMetadata>) => string;
350
+ authEndpoint: AuthEndpoint<TMetadata>;
351
+ publicKey: string;
352
+ wsEndpoint: (params: EndpointParams<TMetadata>) => string;
352
353
  };
353
-
354
- export { AbstractStorageStore, type CreateRoomOptions, type EnterRoomParams, type InferCallback, type InferMetadata, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type PublicKey, type PublicKeyParams, type RegisterParams, type RoomConnectParams, type RoomEndpoints, createClient, infer, register };
354
+ //#endregion
355
+ export { AbstractStorageStore, type BaseUser, ConnectionState, type CrdtType, type CreateRoomOptions, type EnterRoomParams, type EventMessage, type EventNotifierSubscriptionCallback, type EventRecord, type IOEventMessage, type InferCallback, type InferCrdtJson, type InferMetadata, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type PluvRouter, type PluvRouterEventConfig, type PublicKey, type PublicKeyParams, type RegisterParams, type RoomConnectParams, type RoomEndpoints, type RoomLike, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
356
+ //# sourceMappingURL=index.d.mts.map