@pluv/io 0.17.2 → 0.18.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.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JsonObject, MaybePromise, IOEventMessage, EventRecord, InputZodLike, Id, IOLike, InferIOOutput, IOAuthorize, BaseIOAuthorize, InferIOInput, BaseUser, InferIOAuthorizeUser, InferIOAuthorize, Spread, InferIOOutputBroadcast, InferIOOutputSelf, InferIOOutputSync, Maybe, BaseClientEventRecord, BaseIOEventRecord } from '@pluv/types';
1
+ import { JsonObject, MaybePromise, IOEventMessage, IOAuthorize, BaseIOAuthorize, InferIOAuthorizeUser, EventRecord, Id, Maybe, IOLike, InferIOOutput, InputZodLike, IORouterLike, InferIOInput, BaseUser, InferIOAuthorize } from '@pluv/types';
2
2
  export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
3
3
  import { AbstractCrdtDoc, AbstractCrdtDocFactory } from '@pluv/crdt';
4
4
 
@@ -35,7 +35,7 @@ type EventType = keyof AbstractEventMap;
35
35
  interface AbstractWebSocketHandleErrorParams {
36
36
  error: unknown;
37
37
  message?: string;
38
- session?: WebSocketSession;
38
+ session?: WebSocketSession<any>;
39
39
  }
40
40
  type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEventMap[TType]) => MaybePromise<void>;
41
41
  interface AbstractWebSocketConfig {
@@ -80,13 +80,8 @@ declare global {
80
80
  log: (...data: any[]) => void;
81
81
  };
82
82
  }
83
- interface EventConfig<TPlatform extends AbstractPlatform = AbstractPlatform, TContext extends Record<string, any> = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}, TResultSelf extends EventRecord<string, any> = {}, TResultSync extends EventRecord<string, any> = {}> {
84
- input?: InputZodLike<TData>;
85
- resolver: EventResolver<TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TData, TResultBroadcast> | EventResolverObject<TPlatform, TContext, TData, TResultBroadcast, TResultSelf, TResultSync>;
86
- }
87
- type SyncEventResolver<TContext extends Record<string, any> = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}> = (data: TData, context: EventResolverContext<TContext>) => MaybePromise<TResultBroadcast | void>;
88
- type EventResolver<TContext extends Record<string, any> = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}> = (data: TData, context: EventResolverContext<TContext>) => MaybePromise<TResultBroadcast | void>;
89
- interface EventResolverContext<TContext extends Record<string, any> = {}> {
83
+ type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<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>;
84
+ interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
90
85
  context: TContext;
91
86
  doc: AbstractCrdtDoc<any>;
92
87
  room: string;
@@ -102,17 +97,9 @@ interface EventResolverContext<TContext extends Record<string, any> = {}> {
102
97
  * @author leedavidcs
103
98
  * @date December 25, 2022
104
99
  */
105
- session: WebSocketSession | null;
106
- sessions: Map<string, WebSocketSession>;
100
+ session: WebSocketSession<TAuthorize> | null;
101
+ sessions: Map<string, WebSocketSession<TAuthorize>>;
107
102
  }
108
- type EventResolverObject<TPlatform extends AbstractPlatform = AbstractPlatform, TContext extends Record<string, any> = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}, TResultSelf extends EventRecord<string, any> = {}, TResultSync extends EventRecord<string, any> = {}> = {
109
- broadcast?: EventResolver<TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TData, TResultBroadcast>;
110
- self?: EventResolver<TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TData, TResultSelf>;
111
- sync?: SyncEventResolver<TContext, TData, TResultSync>;
112
- };
113
- type InferEventConfig<TPlatform extends AbstractPlatform = AbstractPlatform, TContext extends Record<string, any> = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = {
114
- [P in keyof TInput]: P extends string ? Id<EventConfig<TPlatform, TContext, TInput[P], TOutputBroadcast, TOutputSelf, TOutputSync>> : never;
115
- };
116
103
  type SendMessageOptions = {
117
104
  type?: "broadcast";
118
105
  sessionIds?: readonly string[];
@@ -124,15 +111,33 @@ type SendMessageOptions = {
124
111
  interface WebSocketSessionTimers {
125
112
  ping: number;
126
113
  }
127
- interface WebSocketSession {
114
+ interface WebSocketSession<TAuthorize extends IOAuthorize<any, any, any> = BaseIOAuthorize> {
128
115
  id: string;
129
116
  presence: JsonObject | null;
130
117
  quit: boolean;
131
118
  room: string;
132
119
  timers: WebSocketSessionTimers;
133
120
  webSocket: AbstractWebSocket;
134
- user: JsonObject | null;
121
+ user: InferIOAuthorizeUser<TAuthorize>;
122
+ }
123
+ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot extends EventRecord<string, any> = {}> = TEventRecords extends [
124
+ infer IHead extends EventRecord<string, any>,
125
+ ...infer ITail extends EventRecord<string, any>[]
126
+ ] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
127
+ [P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
128
+ }> : Id<TRoot>;
129
+ type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
130
+ room: string;
131
+ } & InferPlatformRoomContextType<TPlatform>;
132
+ type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
133
+ interface PluvIOListeners<TPlatform extends AbstractPlatform> {
134
+ onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
135
+ onStorageUpdated: (event: IORoomListenerEvent<TPlatform>) => void;
135
136
  }
137
+ type IORoomListenerEvent<TPlatform extends AbstractPlatform> = {
138
+ room: string;
139
+ encodedState: string;
140
+ } & InferPlatformRoomContextType<TPlatform>;
136
141
 
137
142
  type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage<TIO, TEvent> & {
138
143
  options?: SendMessageOptions;
@@ -165,27 +170,65 @@ declare abstract class AbstractPlatform<TWebSocket = any, TIOContext extends Rec
165
170
  abstract randomUUID(): string;
166
171
  }
167
172
 
168
- type IORoomListenerEvent<TPlatform extends AbstractPlatform> = {
169
- room: string;
170
- encodedState: string;
171
- } & InferPlatformRoomContextType<TPlatform>;
173
+ interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
174
+ broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
175
+ input?: InputZodLike<TInput>;
176
+ self?: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
177
+ sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
178
+ }
179
+ declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
180
+ private _broadcast;
181
+ private _input;
182
+ private _self;
183
+ private _sync;
184
+ get config(): {
185
+ broadcast: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
186
+ input: InputZodLike<TInput> | null;
187
+ resolver: () => EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TOutput>;
188
+ self: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
189
+ sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
190
+ };
191
+ constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
192
+ broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
193
+ 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 & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
195
+ sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
196
+ private _resolver;
197
+ }
198
+
199
+ type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
200
+ [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
201
+ };
202
+ type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TRoot extends TRouters[0]["_events"] = {}> = TRouters extends [
203
+ infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
204
+ ...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
205
+ ] ? 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, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
207
+ readonly _events: TEvents;
208
+ constructor(events: TEvents);
209
+ static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
210
+ }
211
+
172
212
  interface IORoomListeners<TPlatform extends AbstractPlatform> {
173
213
  onDestroy: (event: IORoomListenerEvent<TPlatform>) => void;
174
214
  }
175
- type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = Partial<IORoomListeners<TPlatform>> & {
215
+ type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
216
+ [event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
217
+ };
218
+ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform>> & {
176
219
  authorize?: TAuthorize;
177
220
  context: TContext & InferPlatformRoomContextType<TPlatform>;
178
221
  crdt?: {
179
222
  doc: (value: any) => AbstractCrdtDocFactory<any>;
180
223
  };
181
224
  debug: boolean;
182
- events: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
183
225
  platform: TPlatform;
226
+ router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
184
227
  };
185
228
  type WebsocketRegisterOptions<TPlatform extends AbstractPlatform> = {
186
229
  token?: string | null;
187
230
  } & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>;
188
- declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> implements IOLike<TAuthorize, TInput, TOutputBroadcast, TOutputSelf, TOutputSync> {
231
+ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
189
232
  private readonly _context;
190
233
  private readonly _debug;
191
234
  private readonly _docFactory;
@@ -195,10 +238,11 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
195
238
  private _sessions;
196
239
  private _uninitialize;
197
240
  readonly _authorize: TAuthorize | null;
198
- readonly _events: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
241
+ readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
199
242
  readonly id: string;
200
- constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>);
201
- broadcast<TEvent extends keyof InferIOInput<this>>(event: TEvent, data: Id<InferIOInput<this>[TEvent]>): Promise<void>;
243
+ get _events(): TEvents;
244
+ get broadcast(): BroadcastProxy<this>;
245
+ constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
202
246
  getSize(): number;
203
247
  register(webSocket: InferPlatformWebSocketType<TPlatform>, options: WebsocketRegisterOptions<TPlatform>): Promise<void>;
204
248
  private _broadcast;
@@ -206,9 +250,8 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
206
250
  private _emitRegistered;
207
251
  private _getIOAuthorize;
208
252
  private _getAuthorizedUser;
209
- private _getEventConfig;
210
- private _getEventInputs;
211
- private _getEventResolverObject;
253
+ private _getProcedure;
254
+ private _getProcedureInputs;
212
255
  private _initialize;
213
256
  private _logDebug;
214
257
  private _onClose;
@@ -239,32 +282,21 @@ interface AuthorizeModule {
239
282
  encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
240
283
  }
241
284
 
242
- type InferIOContext<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<any, any, infer IContext, any, any, any, any> ? IContext : never;
243
- type InferIOPlatform<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<infer IPlatform, any, any, any, any, any, any> ? IPlatform : never;
244
- type InferIORoom<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<infer IPlatform, infer IAuthorize, infer IContext, infer IInput, infer IOutputBroadcast, infer IOutputSelf, infer IOutputSync> ? IORoom<IPlatform, IAuthorize, IContext, IInput, IOutputBroadcast, IOutputSelf, IOutputSync> : never;
245
- type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
246
- room: string;
247
- } & InferPlatformRoomContextType<TPlatform>;
248
- type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
249
- interface PluvIOListeners<TPlatform extends AbstractPlatform> {
250
- onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
251
- onStorageUpdated: (event: IORoomListenerEvent<TPlatform>) => void;
252
- }
253
- type PluvIOConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> | null = null, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = Partial<PluvIOListeners<TPlatform>> & {
285
+ 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, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform>> & {
254
287
  authorize?: TAuthorize;
255
288
  context?: TContext;
256
289
  crdt?: {
257
290
  doc: (value: any) => AbstractCrdtDocFactory<any>;
258
291
  };
259
292
  debug?: boolean;
260
- events?: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
261
- getInitialStorage?: GetInitialStorageFn<TPlatform>;
262
293
  platform: TPlatform;
294
+ router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
263
295
  };
264
296
  type GetRoomOptions<TPlatform extends AbstractPlatform> = {
265
297
  debug?: boolean;
266
298
  } & InferPlatformRoomContextType<TPlatform>;
267
- declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> implements IOLike<TAuthorize, TInput, TOutputBroadcast, TOutputSelf, TOutputSync> {
299
+ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
268
300
  private _rooms;
269
301
  readonly _authorize: TAuthorize | null;
270
302
  readonly _context: TContext;
@@ -272,20 +304,52 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
272
304
  doc: (value: any) => AbstractCrdtDocFactory<any>;
273
305
  };
274
306
  readonly _debug: boolean;
275
- readonly _events: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
276
- readonly _getInitialStorage: GetInitialStorageFn<TPlatform> | null;
277
307
  readonly _listeners: PluvIOListeners<TPlatform>;
278
308
  readonly _platform: TPlatform;
309
+ readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
279
310
  readonly _version: string;
280
- constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>);
311
+ get _events(): TEvents;
312
+ constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
281
313
  createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
282
- event<TEvent extends string, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}, TResultSelf extends EventRecord<string, any> = {}, TResultSync extends EventRecord<string, any> = {}>(event: TEvent, config: EventConfig<TPlatform, TContext, TData, TResultBroadcast, TResultSelf, TResultSync>): PluvIO<TPlatform, TAuthorize, TContext, Spread<[TInput, EventRecord<TEvent, TData>]>, Spread<[TOutputBroadcast, TResultBroadcast]>, Spread<[TOutputSelf, TResultSelf]>, Spread<[TOutputSync, TResultSync]>>;
283
- getRoom(room: string, options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
284
- static merge<TIO1 extends PluvIO, TIO2 extends PluvIO>(first: TIO1, second: TIO2): PluvIO<InferIOPlatform<TIO1>, InferIOAuthorize<TIO1>, InferIOContext<TIO1>, Spread<[InferIOInput<TIO1>, InferIOInput<TIO2>]>, Spread<[InferIOOutputBroadcast<TIO1>, InferIOOutputBroadcast<TIO2>]>, Spread<[InferIOOutputSelf<TIO1>, InferIOOutputSelf<TIO2>]>, Spread<[InferIOOutputSync<TIO1>, InferIOOutputSync<TIO2>]>>;
314
+ getRoom(room: string, options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
285
315
  private _logDebug;
286
316
  private _purgeEmptyRooms;
287
317
  }
288
318
 
319
+ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>, TContext extends JsonObject> = Partial<PluvIOListeners<TPlatform>> & {
320
+ authorize?: TAuthorize;
321
+ context?: TContext;
322
+ crdt?: {
323
+ doc: (value: any) => AbstractCrdtDocFactory<any>;
324
+ };
325
+ debug?: boolean;
326
+ getInitialStorage?: GetInitialStorageFn<TPlatform>;
327
+ platform: TPlatform;
328
+ };
329
+ interface ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> {
330
+ router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
331
+ }
332
+ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> implements IOLike<TAuthorize, {}> {
333
+ private _router;
334
+ readonly _authorize: TAuthorize | null;
335
+ readonly _context: TContext;
336
+ readonly _crdt: {
337
+ doc: (value: any) => AbstractCrdtDocFactory<any>;
338
+ };
339
+ readonly _debug: boolean;
340
+ readonly _getInitialStorage: GetInitialStorageFn<TPlatform> | null;
341
+ readonly _listeners: PluvIOListeners<TPlatform>;
342
+ readonly _platform: TPlatform;
343
+ readonly _version: string;
344
+ get _events(): {};
345
+ get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
346
+ constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>);
347
+ createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
348
+ mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
349
+ router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
350
+ server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
351
+ }
352
+
289
353
  type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = Partial<PluvIOListeners<TPlatform>> & {
290
354
  authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformRoomContextType<TPlatform>>;
291
355
  context?: TContext;
@@ -296,6 +360,6 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
296
360
  getInitialStorage?: GetInitialStorageFn<TPlatform>;
297
361
  platform: TPlatform;
298
362
  };
299
- 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, InferPlatformRoomContextType<TPlatform>>, TContext, BaseClientEventRecord, BaseIOEventRecord<IOAuthorize<TAuthorizeUser, TAuthorizeRequired>>>;
363
+ 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, InferPlatformRoomContextType<TPlatform>>, TContext>;
300
364
 
301
- 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 InferPlatformEventContextType, type InferPlatformRoomContextType, type InferPlatformWebSocketType, type JWT, type JWTEncodeParams, PluvIO, type PluvIOConfig, createIO };
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 InferPlatformEventContextType, type InferPlatformRoomContextType, type InferPlatformWebSocketType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, createIO };