@pluv/client 0.0.0-canary-20261027014949
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/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/index.d.mts +357 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2625 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Shoubhit Dash
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
## `@pluv/client`
|
|
2
|
+
|
|
3
|
+
> Framework agnostic frontend client for [@pluv/io](https://www.npmjs.com/package/@pluv/io)
|
|
4
|
+
|
|
5
|
+
**👉 See full documentation on [docs.pluv.io](https://docs.pluv.io/docs). 👈**
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# npm
|
|
11
|
+
npm install @pluv/client @pluv/crdt-yjs yjs
|
|
12
|
+
|
|
13
|
+
# yarn
|
|
14
|
+
yarn add @pluv/client @pluv/crdt-yjs yjs
|
|
15
|
+
|
|
16
|
+
# pnpm
|
|
17
|
+
pnpm add @pluv/client @pluv/crdt-yjs yjs
|
|
18
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { BaseUser, BroadcastProxy, ConnectionState, CrdtDocLike, EventMessage, EventNotifierSubscriptionCallback, EventRecord, IOEventMessage, IOLike, Id, InferIOInput, InferIOOutput, InferIOTreaty, JsonObject, ListUsersOptions, ListUsersResult, OperatorUser, ParticipantKind, ParticipantKindOptions, ParticipantKindsOptions, PresenceProcedureProxy, RoomEventListenerMap, RoomLike, RoomLike as RoomLike$1, RoomStats, SetKey, StandardSchemaV1, StorageProcedureProxy, SubscribeProxy, TreatyLike, UpdateMyPresenceAction, UserInfo, UserInfo as UserInfo$1, WebSocketConnection, WebSocketConnection as WebSocketConnection$1, WebSocketState } from "@pluv/types";
|
|
2
|
+
import { AbstractCrdtDocFactory, HasStorage, InferDoc, InferJson, InferSeed, InferStorage, NoopCrdtDocFactory } from "@pluv/crdt";
|
|
3
|
+
export declare abstract class AbstractStorageStore {
|
|
4
|
+
room: string;
|
|
5
|
+
constructor(room: string);
|
|
6
|
+
abstract addUpdate(update: string): Promise<void>;
|
|
7
|
+
abstract destroy(): Promise<void>;
|
|
8
|
+
abstract flatten(encodedState: string): Promise<void>;
|
|
9
|
+
abstract getShouldFlatten(): Promise<boolean>;
|
|
10
|
+
abstract getUpdates(start?: number): Promise<readonly string[]>;
|
|
11
|
+
abstract initialize(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Client snapshot. Dependent constraints (storage vs treaty) are
|
|
15
|
+
* enforced on `createClient().config()`, not inside this object type.
|
|
16
|
+
*/
|
|
17
|
+
type ClientDefs = {
|
|
18
|
+
io: IOLike;
|
|
19
|
+
treaty: TreatyLike;
|
|
20
|
+
presence: StandardSchemaV1<any, any> | undefined;
|
|
21
|
+
metadata: StandardSchemaV1<any, any> | undefined;
|
|
22
|
+
storage: AbstractCrdtDocFactory<any, any>;
|
|
23
|
+
};
|
|
24
|
+
type PatchDefs<TDefs extends ClientDefs, P extends Partial<ClientDefs>> = Omit<TDefs, keyof P> & P;
|
|
25
|
+
type InferIOLike<TIO extends IOLike> = IOLike<Pick<TIO["_defs"], "treaty" | "events">>;
|
|
26
|
+
type CrdtManagerOptions<TCrdt extends AbstractCrdtDocFactory<any, any, any, any>> = {
|
|
27
|
+
storage?: TCrdt;
|
|
28
|
+
initialStorage?: InferSeed<TCrdt>;
|
|
29
|
+
};
|
|
30
|
+
type InferSchemaInput<TSchema, TFallback extends Record<string, any> = {}> = TSchema extends StandardSchemaV1<infer I extends Record<string, any>, any> ? I : TFallback;
|
|
31
|
+
type InferSchemaOutput<TSchema, TFallback extends Record<string, any> = {}> = TSchema extends StandardSchemaV1<any, infer O extends Record<string, any>> ? O : TFallback;
|
|
32
|
+
type InferClientPresence<TDefs extends ClientDefs> = InferSchemaOutput<TDefs["presence"]>;
|
|
33
|
+
type InferClientMetadata<TDefs extends ClientDefs> = InferSchemaOutput<TDefs["metadata"]>;
|
|
34
|
+
type InferClientInput<TDefs extends ClientDefs> = InferIOInput<TDefs["io"]>;
|
|
35
|
+
type InferClientOutput<TDefs extends ClientDefs> = InferIOOutput<TDefs["io"]>;
|
|
36
|
+
interface PluvClientLimits {
|
|
37
|
+
/**
|
|
38
|
+
* @description Maximum size of presence object in bytes
|
|
39
|
+
*/
|
|
40
|
+
presenceMaxSize?: number | null;
|
|
41
|
+
}
|
|
42
|
+
type WithMetadata<TMetadata extends Record<string, any> = {}> = keyof TMetadata extends never ? {
|
|
43
|
+
metadata?: undefined;
|
|
44
|
+
} : {
|
|
45
|
+
metadata: TMetadata;
|
|
46
|
+
};
|
|
47
|
+
type UsersManagerConfig<TPresence extends Record<string, any> = {}> = {
|
|
48
|
+
initialPresence?: Record<string, any>;
|
|
49
|
+
limits: PluvClientLimits;
|
|
50
|
+
presence?: StandardSchemaV1<any, TPresence>;
|
|
51
|
+
};
|
|
52
|
+
declare global {
|
|
53
|
+
var process: {
|
|
54
|
+
env: {
|
|
55
|
+
[key: string]: string | undefined;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
interface EndpointParams<TMetadata extends JsonObject> {
|
|
60
|
+
metadata: TMetadata;
|
|
61
|
+
room: string;
|
|
62
|
+
}
|
|
63
|
+
type AuthEndpoint<TMetadata extends JsonObject> = string | ((params: EndpointParams<TMetadata>) => string | FetchOptions) | true;
|
|
64
|
+
type WsEndpoint<TMetadata extends JsonObject> = string | ((params: EndpointParams<TMetadata>) => string);
|
|
65
|
+
type FetchOptions = {
|
|
66
|
+
url: string;
|
|
67
|
+
options?: RequestInit;
|
|
68
|
+
};
|
|
69
|
+
type RoomEndpoints<TMetadata extends JsonObject> = {
|
|
70
|
+
wsEndpoint?: WsEndpoint<TMetadata>;
|
|
71
|
+
authEndpoint: AuthEndpoint<TMetadata>;
|
|
72
|
+
};
|
|
73
|
+
type PluvRoomAddon<TDefs extends ClientDefs = ClientDefs> = (input: PluvRoomAddonInput<TDefs>) => Partial<PluvRoomAddonResult>;
|
|
74
|
+
interface PluvRoomAddonInput<TDefs extends ClientDefs = ClientDefs> {
|
|
75
|
+
room: PluvRoom<TDefs>;
|
|
76
|
+
}
|
|
77
|
+
interface PluvRoomAddonResult {
|
|
78
|
+
storage: AbstractStorageStore;
|
|
79
|
+
}
|
|
80
|
+
type PluvRoomDebug<TIO extends IOLike> = Id<{
|
|
81
|
+
output: readonly (keyof InferIOOutput<TIO>)[];
|
|
82
|
+
input: readonly (keyof InferIOInput<TIO>)[];
|
|
83
|
+
}>;
|
|
84
|
+
type RoomConnectParams<TMetadata extends JsonObject = {}> = keyof TMetadata extends never ? [] : [WithMetadata<TMetadata>];
|
|
85
|
+
interface ReconnectTimeoutMsParams {
|
|
86
|
+
attempts: number;
|
|
87
|
+
}
|
|
88
|
+
type ReconnectTimeoutMs = number | ((params: ReconnectTimeoutMsParams) => number);
|
|
89
|
+
type RoomConfig<TDefs extends ClientDefs = ClientDefs> = Id<{
|
|
90
|
+
addons?: readonly PluvRoomAddon<any>[];
|
|
91
|
+
debug?: boolean | PluvRoomDebug<TDefs["io"]>;
|
|
92
|
+
limits: PluvClientLimits;
|
|
93
|
+
onAuthorizationFail?: (error: Error) => void;
|
|
94
|
+
metadata?: TDefs["metadata"];
|
|
95
|
+
reconnectTimeoutMs?: ReconnectTimeoutMs;
|
|
96
|
+
treaty: TDefs["treaty"];
|
|
97
|
+
} & RoomEndpoints<InferClientMetadata<TDefs>> & Pick<CrdtManagerOptions<TDefs["storage"]>, "initialStorage" | "storage"> & UsersManagerConfig<InferClientPresence<TDefs>>>;
|
|
98
|
+
export declare class PluvRoom<TDefs extends ClientDefs = ClientDefs> implements RoomLike$1<TDefs["io"], InferDoc<TDefs["storage"]>, InferClientPresence<TDefs>, InferStorage<TDefs["storage"]>, InferJson<TDefs["storage"]>, TDefs["treaty"]> {
|
|
99
|
+
#private;
|
|
100
|
+
readonly _endpoints: RoomEndpoints<InferClientMetadata<TDefs>>;
|
|
101
|
+
readonly id: string;
|
|
102
|
+
readonly metadata?: TDefs["metadata"];
|
|
103
|
+
private readonly _crdtManager;
|
|
104
|
+
private readonly _crdtNotifier;
|
|
105
|
+
private readonly _debug;
|
|
106
|
+
private readonly _eventNotifier;
|
|
107
|
+
private readonly _errorSubject;
|
|
108
|
+
private readonly _intervals;
|
|
109
|
+
private readonly _limits;
|
|
110
|
+
private readonly _listenerManager;
|
|
111
|
+
private readonly _listeners;
|
|
112
|
+
private readonly _reconnectTimeoutMs;
|
|
113
|
+
private readonly _requests;
|
|
114
|
+
private readonly _stateNotifier;
|
|
115
|
+
private readonly _storageStore;
|
|
116
|
+
private readonly _subscriptions;
|
|
117
|
+
private readonly _timeouts;
|
|
118
|
+
private readonly _treaty;
|
|
119
|
+
private readonly _usersManager;
|
|
120
|
+
private readonly _usersNotifier;
|
|
121
|
+
private _roomStats;
|
|
122
|
+
private _operatorStats;
|
|
123
|
+
private _lastMetadata;
|
|
124
|
+
private _seq;
|
|
125
|
+
private readonly _storageSync;
|
|
126
|
+
private _state;
|
|
127
|
+
private _windowListeners;
|
|
128
|
+
private _wsListeners;
|
|
129
|
+
private _storageProcedureNames;
|
|
130
|
+
/** Prepared commits wait here so an earlier call writes before a later one. */
|
|
131
|
+
private _storageCommits;
|
|
132
|
+
constructor(room: string, options: RoomConfig<TDefs>);
|
|
133
|
+
get webSocket(): WebSocket | null;
|
|
134
|
+
addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
|
|
135
|
+
broadcast: BroadcastProxy<TDefs["io"]>;
|
|
136
|
+
canRedo: () => boolean;
|
|
137
|
+
canUndo: () => boolean;
|
|
138
|
+
connect(...args: RoomConnectParams<InferClientMetadata<TDefs>>): Promise<void>;
|
|
139
|
+
disconnect(): Promise<void>;
|
|
140
|
+
getConnection: () => WebSocketConnection$1;
|
|
141
|
+
getDoc: () => CrdtDocLike<InferDoc<TDefs["storage"]>, InferStorage<TDefs["storage"]>, InferJson<TDefs["storage"]>>;
|
|
142
|
+
getMyPresence: () => InferClientPresence<TDefs>;
|
|
143
|
+
getMyself: () => Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>> | null;
|
|
144
|
+
getOther: (userId: string, options?: ParticipantKindOptions) => Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>> | null;
|
|
145
|
+
getOtherByConnectionId: (connectionId: string, options?: ParticipantKindsOptions) => Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>> | null;
|
|
146
|
+
getOthers: (options?: ParticipantKindsOptions) => readonly Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>>[];
|
|
147
|
+
getRoomStats: (options?: ParticipantKindsOptions) => RoomStats;
|
|
148
|
+
getStorage: <TKey extends keyof InferStorage<TDefs["storage"]>>(type: TKey) => InferStorage<TDefs["storage"]>[TKey] | null;
|
|
149
|
+
getStorageJson(): InferJson<TDefs["storage"]> | null;
|
|
150
|
+
getStorageJson<TKey extends keyof InferJson<TDefs["storage"]>>(type: TKey): InferJson<TDefs["storage"]>[TKey] | null;
|
|
151
|
+
getStorageLoaded: () => boolean;
|
|
152
|
+
listUsers: (options?: ListUsersOptions) => Promise<ListUsersResult<TDefs["io"]>>;
|
|
153
|
+
presence: PresenceProcedureProxy<TDefs["treaty"]["_defs"]["procedures"]["presence"]>;
|
|
154
|
+
redo: () => void;
|
|
155
|
+
storage: StorageProcedureProxy<TDefs["treaty"]["_defs"]["procedures"]["storage"]>;
|
|
156
|
+
subscribe: SubscribeProxy<TDefs["io"], InferClientPresence<TDefs>, InferJson<TDefs["storage"]>>;
|
|
157
|
+
transact: (fn: (storage: InferStorage<TDefs["storage"]>) => void, origin?: string) => void;
|
|
158
|
+
undo: () => void;
|
|
159
|
+
updateMyPresence: (presence: UpdateMyPresenceAction<InferClientPresence<TDefs>>) => Promise<void>;
|
|
160
|
+
private _applyMyPresence;
|
|
161
|
+
private _addToStorageStore;
|
|
162
|
+
private _attachWindowListeners;
|
|
163
|
+
private _attachWsListeners;
|
|
164
|
+
private _clearInterval;
|
|
165
|
+
private _clearTimeout;
|
|
166
|
+
private _closeWs;
|
|
167
|
+
private _detachWindowListeners;
|
|
168
|
+
private _detachWsListeners;
|
|
169
|
+
private _emitSharedTypes;
|
|
170
|
+
private _event;
|
|
171
|
+
private _flattenStorageStore;
|
|
172
|
+
private _getAddon;
|
|
173
|
+
private _getAuthFetchOptions;
|
|
174
|
+
private _getAuthorization;
|
|
175
|
+
private _getWsEndpoint;
|
|
176
|
+
private _handleExit;
|
|
177
|
+
private _handlePresenceUpdatedMessage;
|
|
178
|
+
private _handleReceiveOthers;
|
|
179
|
+
private _handleRegisteredMessage;
|
|
180
|
+
private _handleStorageReceivedMessage;
|
|
181
|
+
private _handleStorageUpdatedMessage;
|
|
182
|
+
private _handleStorageDiffMessage;
|
|
183
|
+
private _handleStorageResyncMessage;
|
|
184
|
+
private _applyRemoteStorage;
|
|
185
|
+
private _noteUnchangedStorage;
|
|
186
|
+
private _settleStorageDiff;
|
|
187
|
+
private _requestStorageDiff;
|
|
188
|
+
private _handleSyncStateReceived;
|
|
189
|
+
private _handleRoomError;
|
|
190
|
+
private _handleRoomStats;
|
|
191
|
+
private _handleUsersPage;
|
|
192
|
+
private _handleUserJoinedMessage;
|
|
193
|
+
private _heartbeat;
|
|
194
|
+
private _logDebug;
|
|
195
|
+
private _observeCrdt;
|
|
196
|
+
private _onAuthorizationFail;
|
|
197
|
+
private _onClose;
|
|
198
|
+
/**
|
|
199
|
+
* TODO
|
|
200
|
+
* @description Handle websocket errors in a meaningful way, should they occur
|
|
201
|
+
* @date August 19, 2022
|
|
202
|
+
*/
|
|
203
|
+
private _onError;
|
|
204
|
+
private _onMessage;
|
|
205
|
+
private _onOpen;
|
|
206
|
+
private _onNavigatorOffline;
|
|
207
|
+
private _onNavigatorOnline;
|
|
208
|
+
private _onVisibilityChange;
|
|
209
|
+
private _onWindowFocus;
|
|
210
|
+
private _other;
|
|
211
|
+
private _parseMessage;
|
|
212
|
+
private _pollReconnect;
|
|
213
|
+
private _reconnect;
|
|
214
|
+
private _runPresenceProcedure;
|
|
215
|
+
private _runStorageProcedure;
|
|
216
|
+
private _sendMessage;
|
|
217
|
+
private _setMetadata;
|
|
218
|
+
private _setRoomStats;
|
|
219
|
+
private _notifyOther;
|
|
220
|
+
private _deleteOtherNotifier;
|
|
221
|
+
private _updateState;
|
|
222
|
+
}
|
|
223
|
+
type InferMetadata<TClient extends PluvClient<any>> = TClient extends PluvClient<infer TDefs> ? InferSchemaOutput<TDefs["metadata"]> : never;
|
|
224
|
+
type PluvClientOptions<TDefs extends ClientDefs> = RoomEndpoints<InferClientMetadata<TDefs>> & {
|
|
225
|
+
debug?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* @description Configurable limits defined for client-side validation. You should only set
|
|
228
|
+
* this if you control the server and have changed the limits there.
|
|
229
|
+
*/
|
|
230
|
+
limits?: PluvClientLimits;
|
|
231
|
+
metadata?: TDefs["metadata"];
|
|
232
|
+
treaty: TDefs["treaty"];
|
|
233
|
+
} & (HasStorage<TDefs["treaty"]["storage"]> extends true ? {
|
|
234
|
+
initialStorage?: InferSeed<TDefs["storage"]>;
|
|
235
|
+
} : {
|
|
236
|
+
initialStorage?: "[ERROR]: Must provide storage on treaty to use initialStorage";
|
|
237
|
+
});
|
|
238
|
+
type CreateRoomOptions<TDefs extends ClientDefs = ClientDefs> = {
|
|
239
|
+
addons?: readonly PluvRoomAddon<any>[];
|
|
240
|
+
debug?: boolean | PluvRoomDebug<TDefs["io"]>;
|
|
241
|
+
initialPresence?: InferSchemaInput<TDefs["presence"]>;
|
|
242
|
+
initialStorage?: InferSeed<TDefs["storage"]>;
|
|
243
|
+
onAuthorizationFail?: (error: Error) => void;
|
|
244
|
+
reconnectTimeoutMs?: ReconnectTimeoutMs;
|
|
245
|
+
};
|
|
246
|
+
type EnterRoomParams<TMetadata extends Record<string, any> = {}> = keyof TMetadata extends never ? [] : [WithMetadata<TMetadata>];
|
|
247
|
+
type ConfiguredClientDefs<TIO extends IOLike, TTreaty extends TreatyLike, TMetadataSchema extends StandardSchemaV1<any, any> | undefined> = {
|
|
248
|
+
io: InferIOLike<TIO>;
|
|
249
|
+
treaty: TTreaty;
|
|
250
|
+
presence: TTreaty["presence"];
|
|
251
|
+
metadata: TMetadataSchema;
|
|
252
|
+
storage: TTreaty["storage"] extends AbstractCrdtDocFactory<any, any, any, any> ? TTreaty["storage"] : NoopCrdtDocFactory;
|
|
253
|
+
};
|
|
254
|
+
export declare class PluvClient<TDefs extends ClientDefs = ClientDefs> {
|
|
255
|
+
readonly metadata?: TDefs["metadata"];
|
|
256
|
+
private readonly _authEndpoint;
|
|
257
|
+
private readonly _debug;
|
|
258
|
+
private readonly _initialStorage?;
|
|
259
|
+
private readonly _limits;
|
|
260
|
+
private readonly _rooms;
|
|
261
|
+
private readonly _treaty;
|
|
262
|
+
private readonly _wsEndpoint;
|
|
263
|
+
get _defs(): {
|
|
264
|
+
initialStorage: InferSeed<TDefs["storage"]> | undefined;
|
|
265
|
+
storage: import("@pluv/types").CrdtDocFactory<any, any, any, any> | undefined;
|
|
266
|
+
treaty: TDefs["treaty"];
|
|
267
|
+
};
|
|
268
|
+
constructor(options: PluvClientOptions<TDefs>);
|
|
269
|
+
createRoom: (room: string, options?: CreateRoomOptions<TDefs>) => PluvRoom<TDefs>;
|
|
270
|
+
enter: (room: string | PluvRoom<TDefs>, ...args: EnterRoomParams<InferSchemaInput<TDefs["metadata"]>>) => Promise<PluvRoom<TDefs>>;
|
|
271
|
+
getRoom: (room: string) => PluvRoom<TDefs> | null;
|
|
272
|
+
getRooms: () => readonly PluvRoom<TDefs>[];
|
|
273
|
+
leave: (room: string | PluvRoom<any>) => Promise<void>;
|
|
274
|
+
private _logDebug;
|
|
275
|
+
}
|
|
276
|
+
interface CreateClientBuilder<TIO extends IOLike> {
|
|
277
|
+
config: <TTreaty extends InferIOTreaty<TIO>, TMetadataSchema extends StandardSchemaV1<any, any> | undefined = undefined>(options: PluvClientOptions<ConfiguredClientDefs<TIO, TTreaty, TMetadataSchema>>) => PluvClient<ConfiguredClientDefs<TIO, TTreaty, TMetadataSchema>>;
|
|
278
|
+
}
|
|
279
|
+
export declare const createClient: <TIO extends IOLike = any>() => CreateClientBuilder<TIO>;
|
|
280
|
+
type MockedRoomEvents<TDefs extends ClientDefs = ClientDefs> = Partial<{ [P in keyof InferClientInput<TDefs>]: (data: Id<InferClientInput<TDefs>[P]>) => Partial<InferClientOutput<TDefs>>; }>;
|
|
281
|
+
type MockedRoomConfig<TDefs extends ClientDefs = ClientDefs> = {
|
|
282
|
+
events?: MockedRoomEvents<TDefs>;
|
|
283
|
+
limits?: PluvClientLimits;
|
|
284
|
+
myself?: {
|
|
285
|
+
connectionId?: string;
|
|
286
|
+
data: UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>["data"];
|
|
287
|
+
kind?: ParticipantKind;
|
|
288
|
+
operator?: OperatorUser | null;
|
|
289
|
+
};
|
|
290
|
+
treaty: TDefs["treaty"];
|
|
291
|
+
} & Pick<CrdtManagerOptions<TDefs["storage"]>, "initialStorage" | "storage"> & Omit<UsersManagerConfig<InferClientPresence<TDefs>>, "limits">;
|
|
292
|
+
export declare class MockedRoom<TDefs extends ClientDefs = ClientDefs> implements RoomLike$1<TDefs["io"], InferDoc<TDefs["storage"]>, InferClientPresence<TDefs>, InferStorage<TDefs["storage"]>, InferJson<TDefs["storage"]>, TDefs["treaty"]> {
|
|
293
|
+
#private;
|
|
294
|
+
readonly id: string;
|
|
295
|
+
private readonly _crdtManager;
|
|
296
|
+
private readonly _crdtNotifier;
|
|
297
|
+
private readonly _eventNotifier;
|
|
298
|
+
private readonly _errorSubject;
|
|
299
|
+
private readonly _events?;
|
|
300
|
+
private readonly _limits;
|
|
301
|
+
private readonly _usersNotifier;
|
|
302
|
+
private readonly _treaty;
|
|
303
|
+
private _seq;
|
|
304
|
+
/** Prepared commits wait here so an earlier call writes before a later one. */
|
|
305
|
+
private _storageCommits;
|
|
306
|
+
private _state;
|
|
307
|
+
private readonly _stateNotifier;
|
|
308
|
+
private readonly _subscriptions;
|
|
309
|
+
private readonly _usersManager;
|
|
310
|
+
constructor(room: string, options: MockedRoomConfig<TDefs>);
|
|
311
|
+
addEventListener<TKind extends keyof RoomEventListenerMap>(kind: TKind, handler: RoomEventListenerMap[TKind]): () => void;
|
|
312
|
+
broadcast: BroadcastProxy<TDefs["io"]>;
|
|
313
|
+
canRedo: () => boolean;
|
|
314
|
+
canUndo: () => boolean;
|
|
315
|
+
getConnection: () => WebSocketConnection$1;
|
|
316
|
+
getDoc(): CrdtDocLike<InferDoc<TDefs["storage"]>, InferStorage<TDefs["storage"]>, InferJson<TDefs["storage"]>>;
|
|
317
|
+
getMyPresence: () => InferClientPresence<TDefs>;
|
|
318
|
+
getMyself: () => Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>> | null;
|
|
319
|
+
getOther: (userId: string, options?: ParticipantKindOptions) => Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>> | null;
|
|
320
|
+
getOtherByConnectionId: (connectionId: string, options?: ParticipantKindsOptions) => Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>> | null;
|
|
321
|
+
getOthers: (options?: ParticipantKindsOptions) => readonly Id<UserInfo$1<TDefs["io"], InferClientPresence<TDefs>>>[];
|
|
322
|
+
/**
|
|
323
|
+
* Occupancy of mocked people currently tracked in this room. Empty until
|
|
324
|
+
* occupants exist (`setMyself` / extra connections); MockedRoomProvider
|
|
325
|
+
* does not seed them.
|
|
326
|
+
*/
|
|
327
|
+
getRoomStats: (options?: ParticipantKindsOptions) => RoomStats;
|
|
328
|
+
getStorage: <TKey extends keyof InferStorage<TDefs["storage"]>>(type: TKey) => InferStorage<TDefs["storage"]>[TKey] | null;
|
|
329
|
+
getStorageJson(): InferJson<TDefs["storage"]> | null;
|
|
330
|
+
getStorageJson<TKey extends keyof InferJson<TDefs["storage"]>>(type: TKey): InferJson<TDefs["storage"]>[TKey] | null;
|
|
331
|
+
getStorageLoaded(): boolean;
|
|
332
|
+
/**
|
|
333
|
+
* Identity page of mocked people currently tracked in this room. Empty until
|
|
334
|
+
* occupants exist; MockedRoomProvider does not seed them. Not a real
|
|
335
|
+
* listUsers protocol (no limit/cursor paging).
|
|
336
|
+
*/
|
|
337
|
+
listUsers: (options?: ListUsersOptions) => Promise<ListUsersResult<TDefs["io"]>>;
|
|
338
|
+
presence: PresenceProcedureProxy<TDefs["treaty"]["_defs"]["procedures"]["presence"]>;
|
|
339
|
+
redo: () => void;
|
|
340
|
+
storage: StorageProcedureProxy<TDefs["treaty"]["_defs"]["procedures"]["storage"]>;
|
|
341
|
+
storageRoot: (fn: (value: InferJson<TDefs["storage"]>) => void) => (() => void);
|
|
342
|
+
subscribe: SubscribeProxy<TDefs["io"], InferClientPresence<TDefs>, InferJson<TDefs["storage"]>>;
|
|
343
|
+
transact: (fn: (storage: InferStorage<TDefs["storage"]>) => void, origin?: string) => void;
|
|
344
|
+
undo: () => void;
|
|
345
|
+
updateMyPresence: (presence: UpdateMyPresenceAction<InferClientPresence<TDefs>>) => void;
|
|
346
|
+
private _applyMyPresence;
|
|
347
|
+
private _event;
|
|
348
|
+
private _observeCrdt;
|
|
349
|
+
private _publishRoomStats;
|
|
350
|
+
private _other;
|
|
351
|
+
private _runPresenceProcedure;
|
|
352
|
+
private _runStorageProcedure;
|
|
353
|
+
private _simulateEvent;
|
|
354
|
+
}
|
|
355
|
+
export declare function parsePluvSchema<TData>(schema: StandardSchemaV1<any, TData>, data: unknown): TData;
|
|
356
|
+
export { type BaseUser, type ClientDefs, ConnectionState, type CreateClientBuilder, type CreateRoomOptions, type EnterRoomParams, type EventMessage, type EventNotifierSubscriptionCallback, type EventRecord, type IOEventMessage, type InferClientInput, type InferClientMetadata, type InferClientOutput, type InferClientPresence, type InferIOLike, type InferMetadata, type InferSchemaInput, type InferSchemaOutput, type MockedRoomConfig, type MockedRoomEvents, type PatchDefs, type PluvClientOptions, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, type RoomConnectParams, type RoomEndpoints, type RoomLike, type SetKey, type UserInfo, type WebSocketConnection, type WebSocketState };
|
|
357
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["WebSocketConnection","UserInfo","RoomLike","UserInfo","WebSocketConnection","RoomLike"],"sources":["../src/AbstractStorageStore.ts","../src/ClientDefs.ts","../src/infer.ts","../src/CrdtManager.ts","../src/types.ts","../src/UsersManager.ts","../src/PluvRoom.ts","../src/PluvClient.ts","../src/createClient.ts","../src/MockedRoom.ts","../src/utils/parsePluvSchema.ts"],"mappings":";;8BAAsB;EACX;EAEP,YAAY;WAII,UAAU,iBAAiB;WAE3B,WAAW;WAEX,QAAQ,uBAAuB;WAE/B,oBAAoB;WAEpB,WAAW,iBAAiB;WAE5B,cAAc;;;;;;KCRtB;EACR,IAAI;EACJ,QAAQ;EACR,UAAU;EACV,UAAU;EACV,SAAS;;KAGD,UAAU,cAAc,YAAY,UAAU,QAAQ,eAAe,KAC7E,aACM,KAEN;KCnBQ,YAAY,YAAY,UAAU,OAAO,KAAK;KCC9C,mBAAmB,cAAc;EACzC,UAAU;EACV,iBAAiB,UAAU;;KCQnB,iBAAiB,SAAS,kBAAkB,4BACpD,gBAAgB,uBAAuB,UAAU,4BAA4B,IAAI;KAEzE,kBAAkB,SAAS,kBAAkB,4BACrD,gBAAgB,4BAA4B,UAAU,uBAAuB,IAAI;KAEzE,oBAAoB,cAAc,cAAc,kBAAkB;KAClE,oBAAoB,cAAc,cAAc,kBAAkB;KAClE,iBAAiB,cAAc,cAAc,aAAa;KAC1D,kBAAkB,cAAc,cAAc,cAAc;UAavD;;;;EAIb;;KAGQ,aAAa,kBAAkB,kCAAkC;EACrE;;EACA,UAAU;;KCxBN,mBAAmB,kBAAkB;EAC7C,kBAAkB;EAClB,QAAQ;EACR,WAAW,sBAAsB;;QC2D7B;MACA;IACA;OACK;;;;UAkCI,eAAe,kBAAkB;EAC9C,UAAU;EACV;;KAEQ,aAAa,kBAAkB,yBAEnC,QAAQ,eAAe,wBAAwB;KAE3C,WAAW,kBAAkB,yBAEjC,QAAQ,eAAe;KAE1B;EAAiB;EAAa,UAAU;;KAEjC,cAAc,kBAAkB;EACxC,aAAa,WAAW;EACxB,cAAc,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