@pluv/io 0.19.0 → 0.21.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 +16 -16
- package/CHANGELOG.md +80 -0
- package/dist/index.d.mts +115 -83
- package/dist/index.d.ts +115 -83
- package/dist/index.js +323 -212
- package/dist/index.mjs +323 -212
- package/package.json +9 -9
- package/src/AbstractPlatform.ts +64 -20
- package/src/AbstractWebSocket.ts +50 -16
- package/src/IORoom.ts +262 -176
- package/src/PluvIO.ts +27 -14
- package/src/PluvProcedure.ts +11 -29
- package/src/PluvRouter.ts +4 -4
- package/src/PluvServer.ts +27 -12
- package/src/authorize.ts +2 -2
- package/src/constants.ts +1 -0
- package/src/createIO.ts +4 -4
- package/src/index.ts +7 -5
- package/src/types.ts +24 -11
- package/src/version.generated.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise,
|
|
1
|
+
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, BaseIOAuthorize, InferIOAuthorizeUser, EventRecord, Id, Maybe, IOLike, InferIOOutput, BaseUser, InputZodLike, IORouterLike, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { AbstractCrdtDoc, AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
4
4
|
|
|
@@ -24,7 +24,7 @@ type AbstractMessageEvent<T = any> = AbstractEvent & {
|
|
|
24
24
|
};
|
|
25
25
|
type AbstractErrorEvent = AbstractEvent & {
|
|
26
26
|
error: unknown;
|
|
27
|
-
message
|
|
27
|
+
message?: string;
|
|
28
28
|
};
|
|
29
29
|
interface AbstractEventMap {
|
|
30
30
|
close: AbstractCloseEvent;
|
|
@@ -35,15 +35,16 @@ type EventType = keyof AbstractEventMap;
|
|
|
35
35
|
interface AbstractWebSocketHandleErrorParams {
|
|
36
36
|
error: unknown;
|
|
37
37
|
message?: string;
|
|
38
|
+
room: string;
|
|
38
39
|
session?: WebSocketSession<any>;
|
|
39
40
|
}
|
|
40
41
|
type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEventMap[TType]) => MaybePromise<void>;
|
|
42
|
+
type InferWebSocketSource<TAbstractWebSocket extends AbstractWebSocket> = TAbstractWebSocket extends AbstractWebSocket<infer IWebSocket> ? IWebSocket : never;
|
|
41
43
|
interface AbstractWebSocketConfig {
|
|
44
|
+
persistance: AbstractPersistance;
|
|
42
45
|
room: string;
|
|
43
|
-
sessionId: string;
|
|
44
|
-
userId: string | null;
|
|
45
46
|
}
|
|
46
|
-
declare abstract class AbstractWebSocket {
|
|
47
|
+
declare abstract class AbstractWebSocket<TWebSocket = any> {
|
|
47
48
|
/** The connection is not yet open. */
|
|
48
49
|
readonly CONNECTING = 0;
|
|
49
50
|
/** The connection is open and ready to communicate. */
|
|
@@ -52,10 +53,15 @@ declare abstract class AbstractWebSocket {
|
|
|
52
53
|
readonly CLOSING = 2;
|
|
53
54
|
/** The connection is closed. */
|
|
54
55
|
readonly CLOSED = 3;
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
readonly persistance: AbstractPersistance;
|
|
57
|
+
readonly room: string;
|
|
58
|
+
readonly webSocket: TWebSocket;
|
|
59
|
+
private _user;
|
|
60
|
+
abstract set presence(presence: JsonObject | null);
|
|
57
61
|
abstract get readyState(): 0 | 1 | 2 | 3;
|
|
58
|
-
|
|
62
|
+
abstract get sessionId(): string;
|
|
63
|
+
abstract get state(): WebSocketSerializedState;
|
|
64
|
+
constructor(webSocket: TWebSocket, config: AbstractWebSocketConfig);
|
|
59
65
|
/**
|
|
60
66
|
* TODO
|
|
61
67
|
* @description Return an unsubscribe method to remove the event-listener.
|
|
@@ -68,9 +74,9 @@ declare abstract class AbstractWebSocket {
|
|
|
68
74
|
*/
|
|
69
75
|
abstract addEventListener<TType extends EventType>(type: TType, handler: AbstractListener<TType>): void;
|
|
70
76
|
abstract close(code?: number | undefined, reason?: string | undefined): void;
|
|
71
|
-
abstract initialize(): Promise<() => void>;
|
|
72
77
|
abstract send(message: ArrayBuffer | ArrayBufferView | string): void;
|
|
73
78
|
abstract terminate(): void;
|
|
79
|
+
getSession<TAuthorize extends IOAuthorize<any, any, any>>(): Promise<WebSocketSession<TAuthorize>>;
|
|
74
80
|
handleError(params: AbstractWebSocketHandleErrorParams): void;
|
|
75
81
|
sendMessage<TMessage extends IOEventMessage<any> = IOEventMessage<any>>(data: TMessage): void;
|
|
76
82
|
}
|
|
@@ -80,8 +86,8 @@ declare global {
|
|
|
80
86
|
log: (...data: any[]) => void;
|
|
81
87
|
};
|
|
82
88
|
}
|
|
83
|
-
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
84
|
-
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
89
|
+
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
90
|
+
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
85
91
|
context: TContext;
|
|
86
92
|
doc: AbstractCrdtDoc<any>;
|
|
87
93
|
room: string;
|
|
@@ -98,7 +104,7 @@ interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlat
|
|
|
98
104
|
* @date December 25, 2022
|
|
99
105
|
*/
|
|
100
106
|
session: WebSocketSession<TAuthorize> | null;
|
|
101
|
-
sessions:
|
|
107
|
+
sessions: readonly WebSocketSession<TAuthorize>[];
|
|
102
108
|
}
|
|
103
109
|
type SendMessageOptions = {
|
|
104
110
|
type?: "broadcast";
|
|
@@ -111,15 +117,17 @@ type SendMessageOptions = {
|
|
|
111
117
|
interface WebSocketSessionTimers {
|
|
112
118
|
ping: number;
|
|
113
119
|
}
|
|
114
|
-
interface
|
|
115
|
-
id: string;
|
|
120
|
+
interface WebSocketSerializedState {
|
|
116
121
|
presence: JsonObject | null;
|
|
117
122
|
quit: boolean;
|
|
118
123
|
room: string;
|
|
119
124
|
timers: WebSocketSessionTimers;
|
|
120
|
-
webSocket: AbstractWebSocket;
|
|
121
|
-
user: InferIOAuthorizeUser<TAuthorize>;
|
|
122
125
|
}
|
|
126
|
+
type WebSocketSession<TAuthorize extends IOAuthorize<any, any, any> = BaseIOAuthorize> = WebSocketSerializedState & {
|
|
127
|
+
id: string;
|
|
128
|
+
user: InferIOAuthorizeUser<TAuthorize>;
|
|
129
|
+
webSocket: AbstractWebSocket;
|
|
130
|
+
};
|
|
123
131
|
type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot extends EventRecord<string, any> = {}> = TEventRecords extends [
|
|
124
132
|
infer IHead extends EventRecord<string, any>,
|
|
125
133
|
...infer ITail extends EventRecord<string, any>[]
|
|
@@ -128,7 +136,7 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
|
|
|
128
136
|
}> : Id<TRoot>;
|
|
129
137
|
type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
130
138
|
room: string;
|
|
131
|
-
} &
|
|
139
|
+
} & InferRoomContextType<TPlatform>;
|
|
132
140
|
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
133
141
|
interface PluvIOListeners<TPlatform extends AbstractPlatform> {
|
|
134
142
|
onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
@@ -136,8 +144,9 @@ interface PluvIOListeners<TPlatform extends AbstractPlatform> {
|
|
|
136
144
|
}
|
|
137
145
|
type IORoomListenerEvent<TPlatform extends AbstractPlatform> = {
|
|
138
146
|
room: string;
|
|
139
|
-
encodedState: string;
|
|
140
|
-
} &
|
|
147
|
+
encodedState: string | null;
|
|
148
|
+
} & InferRoomContextType<TPlatform>;
|
|
149
|
+
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
141
150
|
|
|
142
151
|
type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage<TIO, TEvent> & {
|
|
143
152
|
options?: SendMessageOptions;
|
|
@@ -148,62 +157,93 @@ declare abstract class AbstractPubSub {
|
|
|
148
157
|
abstract unsubscribe(subscriptionId: number): void;
|
|
149
158
|
}
|
|
150
159
|
|
|
151
|
-
type
|
|
152
|
-
type
|
|
153
|
-
type
|
|
154
|
-
type
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
persistance
|
|
159
|
-
pubSub
|
|
160
|
+
type WebSocketRegistrationMode = "attached" | "detached";
|
|
161
|
+
type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
|
|
162
|
+
type InferPlatformWebSocketSource<TPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
|
|
163
|
+
type InferPlatformContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IPlatformContext> ? IPlatformContext : never;
|
|
164
|
+
type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IPlatformContext, infer IRoomContext> ? IPlatformContext & IRoomContext : never;
|
|
165
|
+
type AbstractPlatformConfig<TPlatformContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> = {
|
|
166
|
+
context?: TPlatformContext & TRoomContext;
|
|
167
|
+
persistance?: AbstractPersistance;
|
|
168
|
+
pubSub?: AbstractPubSub;
|
|
160
169
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
interface ConvertWebSocketConfig {
|
|
171
|
+
room: string;
|
|
172
|
+
}
|
|
173
|
+
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TPlatformContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
|
|
174
|
+
private _initialized;
|
|
175
|
+
readonly _ioContext: TPlatformContext | undefined;
|
|
164
176
|
readonly _roomContext: TRoomContext | undefined;
|
|
177
|
+
abstract readonly _registrationMode: WebSocketRegistrationMode;
|
|
165
178
|
persistance: AbstractPersistance;
|
|
166
179
|
pubSub: AbstractPubSub;
|
|
167
|
-
constructor(config?: AbstractPlatformConfig);
|
|
168
|
-
abstract
|
|
180
|
+
constructor(config?: AbstractPlatformConfig<TPlatformContext, TRoomContext>);
|
|
181
|
+
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
182
|
+
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
|
|
183
|
+
abstract getLastPing(webSocket: AbstractWebSocket): number | null;
|
|
184
|
+
abstract getSerializedState(webSocket: AbstractWebSocket): WebSocketSerializedState | null;
|
|
185
|
+
abstract getSessionId(webSocket: InferWebSocketSource<TWebSocket>): string | null;
|
|
186
|
+
abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
|
|
187
|
+
abstract initialize(config: AbstractPlatformConfig<TPlatformContext, TRoomContext>): this;
|
|
169
188
|
abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
170
189
|
abstract randomUUID(): string;
|
|
190
|
+
abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
|
|
191
|
+
protected _initialize(): this;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface JWT<TUser extends BaseUser> {
|
|
195
|
+
room: string;
|
|
196
|
+
sub: string;
|
|
197
|
+
user: TUser;
|
|
198
|
+
}
|
|
199
|
+
type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
|
|
200
|
+
maxAge?: number;
|
|
201
|
+
room: string;
|
|
202
|
+
user: TUser;
|
|
203
|
+
} & InferPlatformContextType<TPlatform>;
|
|
204
|
+
interface AuthorizeParams {
|
|
205
|
+
platform: AbstractPlatform;
|
|
206
|
+
secret: string;
|
|
207
|
+
}
|
|
208
|
+
interface AuthorizeModule {
|
|
209
|
+
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
210
|
+
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
171
211
|
}
|
|
172
212
|
|
|
173
|
-
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
174
|
-
broadcast?: EventResolver<TPlatform, TAuthorize, TContext &
|
|
213
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
214
|
+
broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
175
215
|
input?: InputZodLike<TInput>;
|
|
176
|
-
self?: EventResolver<TPlatform, TAuthorize, TContext &
|
|
216
|
+
self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
177
217
|
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
178
218
|
}
|
|
179
|
-
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
219
|
+
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
180
220
|
private _broadcast;
|
|
181
221
|
private _input;
|
|
182
222
|
private _self;
|
|
183
223
|
private _sync;
|
|
184
224
|
get config(): {
|
|
185
|
-
broadcast: EventResolver<TPlatform, TAuthorize, TContext &
|
|
225
|
+
broadcast: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
186
226
|
input: InputZodLike<TInput> | null;
|
|
187
|
-
resolver: () => EventResolver<TPlatform, TAuthorize, TContext &
|
|
188
|
-
self: EventResolver<TPlatform, TAuthorize, TContext &
|
|
227
|
+
resolver: () => EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TOutput>;
|
|
228
|
+
self: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
189
229
|
sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
190
230
|
};
|
|
191
231
|
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
192
|
-
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext &
|
|
232
|
+
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
193
233
|
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
194
|
-
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext &
|
|
195
|
-
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext &
|
|
234
|
+
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
235
|
+
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
196
236
|
private _resolver;
|
|
197
237
|
}
|
|
198
238
|
|
|
199
|
-
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
239
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
|
|
200
240
|
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
201
241
|
};
|
|
202
|
-
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
242
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TRoot extends TRouters[0]["_events"] = {}> = TRouters extends [
|
|
203
243
|
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
204
244
|
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
205
245
|
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
206
|
-
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
246
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
207
247
|
readonly _events: TEvents;
|
|
208
248
|
constructor(events: TEvents);
|
|
209
249
|
static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
@@ -215,9 +255,9 @@ interface IORoomListeners<TPlatform extends AbstractPlatform> {
|
|
|
215
255
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
216
256
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
217
257
|
};
|
|
218
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
258
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform>> & {
|
|
219
259
|
authorize?: TAuthorize;
|
|
220
|
-
context: TContext &
|
|
260
|
+
context: TContext & InferRoomContextType<TPlatform>;
|
|
221
261
|
crdt?: {
|
|
222
262
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
223
263
|
};
|
|
@@ -225,10 +265,10 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
225
265
|
platform: TPlatform;
|
|
226
266
|
router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
227
267
|
};
|
|
228
|
-
|
|
268
|
+
interface WebsocketRegisterOptions {
|
|
229
269
|
token?: string | null;
|
|
230
|
-
}
|
|
231
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
270
|
+
}
|
|
271
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
232
272
|
private readonly _context;
|
|
233
273
|
private readonly _debug;
|
|
234
274
|
private readonly _docFactory;
|
|
@@ -244,14 +284,21 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
244
284
|
get broadcast(): BroadcastProxy<this>;
|
|
245
285
|
constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
246
286
|
getSize(): number;
|
|
247
|
-
|
|
287
|
+
onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => void;
|
|
288
|
+
onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => void;
|
|
289
|
+
onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => void;
|
|
290
|
+
register(webSocket: InferPlatformWebSocketSource<TPlatform>, options?: WebsocketRegisterOptions): Promise<void>;
|
|
248
291
|
private _broadcast;
|
|
249
292
|
private _emitQuitters;
|
|
250
293
|
private _emitRegistered;
|
|
251
|
-
private
|
|
294
|
+
private _ensureDetached;
|
|
295
|
+
private _getAbstractWs;
|
|
296
|
+
private _getSession;
|
|
252
297
|
private _getAuthorizedUser;
|
|
298
|
+
private _getIOAuthorize;
|
|
253
299
|
private _getProcedure;
|
|
254
300
|
private _getProcedureInputs;
|
|
301
|
+
private _getSessions;
|
|
255
302
|
private _initialize;
|
|
256
303
|
private _logDebug;
|
|
257
304
|
private _onClose;
|
|
@@ -263,27 +310,8 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
263
310
|
private _sendSyncMessage;
|
|
264
311
|
}
|
|
265
312
|
|
|
266
|
-
interface JWT<TUser extends BaseUser> {
|
|
267
|
-
room: string;
|
|
268
|
-
sub: string;
|
|
269
|
-
user: TUser;
|
|
270
|
-
}
|
|
271
|
-
type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
|
|
272
|
-
maxAge?: number;
|
|
273
|
-
room: string;
|
|
274
|
-
user: TUser;
|
|
275
|
-
} & InferPlatformRoomContextType<TPlatform>;
|
|
276
|
-
interface AuthorizeParams {
|
|
277
|
-
platform: AbstractPlatform;
|
|
278
|
-
secret: string;
|
|
279
|
-
}
|
|
280
|
-
interface AuthorizeModule {
|
|
281
|
-
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
282
|
-
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
313
|
type InferIORoom<TServer extends PluvServer<any, any, any, any>> = TServer extends PluvServer<infer IPlatform, infer IAuthorize, infer IContext, infer IEvents> ? IORoom<IPlatform, IAuthorize, IContext, IEvents> : never;
|
|
286
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
314
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform>> & {
|
|
287
315
|
authorize?: TAuthorize;
|
|
288
316
|
context?: TContext;
|
|
289
317
|
crdt?: {
|
|
@@ -293,10 +321,12 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
293
321
|
platform: TPlatform;
|
|
294
322
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
295
323
|
};
|
|
296
|
-
type GetRoomOptions<TPlatform extends AbstractPlatform> = {
|
|
324
|
+
type GetRoomOptions<TPlatform extends AbstractPlatform> = keyof InferRoomContextType<TPlatform> extends never ? [{
|
|
325
|
+
debug?: boolean;
|
|
326
|
+
}] | [] : [Id<{
|
|
297
327
|
debug?: boolean;
|
|
298
|
-
} &
|
|
299
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
328
|
+
} & InferRoomContextType<TPlatform>>];
|
|
329
|
+
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
300
330
|
private _rooms;
|
|
301
331
|
readonly _authorize: TAuthorize | null;
|
|
302
332
|
readonly _context: TContext;
|
|
@@ -309,14 +339,15 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
309
339
|
readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
310
340
|
readonly _version: string;
|
|
311
341
|
get _events(): TEvents;
|
|
342
|
+
get _registrationMode(): WebSocketRegistrationMode;
|
|
312
343
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
313
344
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
314
|
-
getRoom(room: string, options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
345
|
+
getRoom(room: string, ...options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
315
346
|
private _logDebug;
|
|
316
347
|
private _purgeEmptyRooms;
|
|
317
348
|
}
|
|
318
349
|
|
|
319
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
350
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> = Partial<PluvIOListeners<TPlatform>> & {
|
|
320
351
|
authorize?: TAuthorize;
|
|
321
352
|
context?: TContext;
|
|
322
353
|
crdt?: {
|
|
@@ -326,10 +357,10 @@ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IO
|
|
|
326
357
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
327
358
|
platform: TPlatform;
|
|
328
359
|
};
|
|
329
|
-
interface ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
360
|
+
interface ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> {
|
|
330
361
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
331
362
|
}
|
|
332
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
363
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> implements IOLike<TAuthorize, {}> {
|
|
333
364
|
private _router;
|
|
334
365
|
readonly _authorize: TAuthorize | null;
|
|
335
366
|
readonly _context: TContext;
|
|
@@ -342,6 +373,7 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
342
373
|
readonly _platform: TPlatform;
|
|
343
374
|
readonly _version: string;
|
|
344
375
|
get _events(): {};
|
|
376
|
+
get _registrationMode(): WebSocketRegistrationMode;
|
|
345
377
|
get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
|
|
346
378
|
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>);
|
|
347
379
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
@@ -351,7 +383,7 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
351
383
|
}
|
|
352
384
|
|
|
353
385
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = Partial<PluvIOListeners<TPlatform>> & {
|
|
354
|
-
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired,
|
|
386
|
+
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
|
|
355
387
|
context?: TContext;
|
|
356
388
|
crdt?: {
|
|
357
389
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
@@ -360,6 +392,6 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
360
392
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
361
393
|
platform: TPlatform;
|
|
362
394
|
};
|
|
363
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any
|
|
395
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>, TContext>;
|
|
364
396
|
|
|
365
|
-
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistance, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CreateIOParams, type GetRoomOptions, type IOPubSubEventMessage, IORoom, type InferIORoom, type
|
|
397
|
+
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistance, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CreateIOParams, type GetRoomOptions, type IOPubSubEventMessage, IORoom, type InferIORoom, type InferPlatformContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, createIO };
|