@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/.turbo/turbo-build.log +14 -16
- package/CHANGELOG.md +28 -0
- package/dist/index.d.mts +286 -284
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1740 -1865
- package/dist/index.mjs.map +1 -0
- package/package.json +17 -13
- package/src/infer.ts +4 -2
- package/tsdown.config.ts +14 -0
- package/dist/index.d.ts +0 -354
- package/dist/index.js +0 -1944
package/dist/index.d.mts
CHANGED
|
@@ -1,354 +1,356 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
21
|
+
io: (io: TIO) => TIO;
|
|
21
22
|
};
|
|
22
|
-
declare const infer: <TIO extends IOLike<any, any, any>>(callback: InferCallback<TIO>) => InferCallback<TIO
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
+
metadata?: undefined;
|
|
50
47
|
} : {
|
|
51
|
-
|
|
48
|
+
metadata: TMetadata;
|
|
52
49
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
94
|
+
var process: {
|
|
95
|
+
env: {
|
|
96
|
+
[key: string]: string | undefined;
|
|
99
97
|
};
|
|
98
|
+
};
|
|
100
99
|
}
|
|
101
100
|
interface EndpointParams<TMetadata extends JsonObject> {
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
109
|
-
|
|
107
|
+
url: string;
|
|
108
|
+
options?: RequestInit;
|
|
110
109
|
};
|
|
111
110
|
type RoomEndpoints<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject> = {
|
|
112
|
-
|
|
113
|
-
} & (InferIOAuthorizeUser<InferIOAuthorize<TIO>> extends BaseUser ? {
|
|
114
|
-
|
|
111
|
+
wsEndpoint?: WsEndpoint<TMetadata>;
|
|
112
|
+
} & (InferIOAuthorizeUser<InferIOAuthorize<TIO>> extends BaseUser$1 ? {
|
|
113
|
+
authEndpoint: AuthEndpoint<TMetadata>;
|
|
115
114
|
} : {
|
|
116
|
-
|
|
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
|
-
|
|
119
|
+
room: PluvRoom<TIO, TMetadata, TPresence, TCrdt>;
|
|
121
120
|
}
|
|
122
121
|
interface PluvRoomAddonResult {
|
|
123
|
-
|
|
122
|
+
storage: AbstractStorageStore;
|
|
124
123
|
}
|
|
125
124
|
type PluvRoomDebug<TIO extends IOLike> = Id<{
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
255
|
+
initialStorage?: "[ERROR]: Must provide crdt to createIO to use storage";
|
|
256
256
|
} : {
|
|
257
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
296
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
346
|
-
|
|
346
|
+
authEndpoint: AuthEndpoint<TMetadata>;
|
|
347
|
+
publicKey: string;
|
|
347
348
|
}
|
|
348
349
|
declare const register: <TMetadata extends JsonObject>(params: RegisterParams<TMetadata>) => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|