@pluv/io 0.22.0 → 0.24.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.
@@ -1,9 +1,9 @@
1
1
 
2
- > @pluv/io@0.22.0 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@0.24.0 build /home/runner/work/pluv/pluv/packages/io
3
3
  > pnpm run version && tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
 
6
- > @pluv/io@0.22.0 version /home/runner/work/pluv/pluv/packages/io
6
+ > @pluv/io@0.24.0 version /home/runner/work/pluv/pluv/packages/io
7
7
  > genversion ./src/version.generated.ts --esm
8
8
 
9
9
  CLI Building entry: src/index.ts
@@ -12,11 +12,11 @@
12
12
  CLI Target: es6
13
13
  ESM Build start
14
14
  CJS Build start
15
- ESM dist/index.mjs 37.62 KB
16
- ESM ⚡️ Build success in 125ms
17
- CJS dist/index.js 39.79 KB
18
- CJS ⚡️ Build success in 126ms
15
+ ESM dist/index.mjs 38.86 KB
16
+ ESM ⚡️ Build success in 112ms
17
+ CJS dist/index.js 41.00 KB
18
+ CJS ⚡️ Build success in 111ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 2342ms
21
- DTS dist/index.d.mts 23.57 KB
22
- DTS dist/index.d.ts 23.57 KB
20
+ DTS ⚡️ Build success in 2161ms
21
+ DTS dist/index.d.mts 25.28 KB
22
+ DTS dist/index.d.ts 25.28 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,201 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6ac8a46: \* Fixed errors thrown when using Cloudflare's websocket hibernation API caused by rooms being re-used between different instances of DurableObjects.
8
+
9
+ - Add configurable `onDelete` and `onMessage` event listeners that can be set when rooms are created.
10
+
11
+ **BREAKING**
12
+
13
+ - Changed `PluvServer.getRoom` to `PluvServer.createRoom`. This means `PluvServer` only handles room creation. Room management must now be handled manually. This mainly affects manually creating rooms with `@pluv/platform-node`, and will likely not affect you if you are either using `createPluvHandler` on any platform, or if you are using `@pluv/platform-cloudflare`.
14
+
15
+ ```ts
16
+ // For @pluv/platform-node
17
+
18
+ // Before
19
+
20
+ import { createIO } from "@pluv/io";
21
+
22
+ const io = createIO(/* ... */);
23
+ const ioServer = io.server(/* ... */);
24
+
25
+ const roomId = "my-room-id";
26
+ const room = ioServer.getRoom(roomId);
27
+
28
+ // After
29
+
30
+ import { createIO, type InferIORoom } from "@pluv/io";
31
+
32
+ const io = createIO(/* ... */);
33
+ const ioServer = io.server(/* ... */);
34
+
35
+ const rooms = new Map<string, InferIORoom<typeof ioServer>>();
36
+
37
+ const roomId = "my-room-id";
38
+ const room = ioServer.createRoom(roomId, {
39
+ // Use new onDelete event listener
40
+ onDelete: (event) => {
41
+ rooms.delete(event.room);
42
+ },
43
+ });
44
+
45
+ rooms.set(roomId, room);
46
+ ```
47
+
48
+ - c26986d: Fixed websocket messages getting lost after the Cloudflare Worker Durable Object wakes up from hibernation.
49
+
50
+ **BREAKING**
51
+
52
+ Updated `onMessage`, `onClose` and `onError` to all return `Promise.void` instead of `void`.
53
+
54
+ ```ts
55
+ // Before
56
+
57
+ const io = createIO(/* ... */);
58
+ const ioServer = io.server(/* ... */);
59
+
60
+ class RoomDurableObject implements DurableObject {
61
+ public webSocketClose(ws: WebSocket, code: number, reason: string): void {
62
+ const handler = this._room.onClose(ws);
63
+
64
+ // Previously returned `void`
65
+ handler({ code, reason });
66
+ }
67
+
68
+ public webSocketError(ws: WebSocket, error: unknown): void {
69
+ const handler = this._room.onError(ws);
70
+ const eventError =
71
+ error instanceof Error ? error : new Error("Internal Error");
72
+
73
+ // Previously returned `void`
74
+ handler({ error: eventError, message: eventError.message });
75
+ }
76
+
77
+ public webSocketMessage(
78
+ ws: WebSocket,
79
+ message: string | ArrayBuffer,
80
+ ): void {
81
+ const handler = this._room.onMessage(ws);
82
+
83
+ // Previously returned `void`
84
+ handler({ data: message });
85
+ }
86
+ }
87
+
88
+ // After
89
+
90
+ const io = createIO(/* ... */);
91
+ const ioServer = io.server(/* ... */);
92
+
93
+ class RoomDurableObject implements DurableObject {
94
+ public async webSocketClose(
95
+ ws: WebSocket,
96
+ code: number,
97
+ reason: string,
98
+ ): Promise<void> {
99
+ const handler = this._room.onClose(ws);
100
+
101
+ // Handler must now be awaited
102
+ await handler({ code, reason });
103
+ }
104
+
105
+ public async webSocketError(ws: WebSocket, error: unknown): Promise<void> {
106
+ const handler = this._room.onError(ws);
107
+ const eventError =
108
+ error instanceof Error ? error : new Error("Internal Error");
109
+
110
+ // Handler must now be awaited
111
+ await handler({ error: eventError, message: eventError.message });
112
+ }
113
+
114
+ public async webSocketMessage(
115
+ ws: WebSocket,
116
+ message: string | ArrayBuffer,
117
+ ): Promise<void> {
118
+ const handler = this._room.onMessage(ws);
119
+
120
+ // Handler must now be awaited
121
+ await handler({ data: message });
122
+ }
123
+ }
124
+ ```
125
+
126
+ ### Patch Changes
127
+
128
+ - @pluv/crdt@0.24.0
129
+ - @pluv/types@0.24.0
130
+
131
+ ## 0.23.0
132
+
133
+ ### Minor Changes
134
+
135
+ - c01b16f: **BREAKING**
136
+
137
+ Moved `getInitialStorage`, `onRoomDeleted` and `onStorageUpdated` from `createIO` to `PluvIO.server`.
138
+
139
+ ```ts
140
+ import { createIO } from "@pluv/io";
141
+
142
+ // Before
143
+ const io = createIO({
144
+ // ...
145
+ getInitialStorage: (event) => {
146
+ // ...
147
+ },
148
+ onRoomDeleted: (event) => {
149
+ // ...
150
+ },
151
+ onStorageUpdated: (event) => {
152
+ // ...
153
+ },
154
+ // ...
155
+ });
156
+
157
+ const ioServer = io.server({
158
+ // ...
159
+ });
160
+
161
+ // After
162
+ const io = createIO({
163
+ // ...
164
+ });
165
+
166
+ const ioServer = io.server({
167
+ // ...
168
+ getInitialStorage: (event) => {
169
+ // ...
170
+ },
171
+ onRoomDeleted: (event) => {
172
+ // ...
173
+ },
174
+ onStorageUpdated: (event) => {
175
+ // ...
176
+ },
177
+ // ...
178
+ });
179
+ ```
180
+
181
+ Added a new listener `onRoomMessage` to `PluvIO.server` to listen to events that are sent within a room.
182
+
183
+ ```ts
184
+ const ioServer = io.server({
185
+ // ...
186
+ onRoomMessage: (event) => {
187
+ console.log(event.message);
188
+ console.log(event.user);
189
+ },
190
+ // ...
191
+ });
192
+ ```
193
+
194
+ ### Patch Changes
195
+
196
+ - @pluv/crdt@0.23.0
197
+ - @pluv/types@0.23.0
198
+
3
199
  ## 0.22.0
4
200
 
5
201
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, BaseIOAuthorize, InferIOAuthorizeUser, EventRecord, Id, Maybe, IOLike, InferIOOutput, BaseUser, InputZodLike, IORouterLike, InferIOInput, InferIOAuthorize } from '@pluv/types';
1
+ import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, BaseIOAuthorize, IORouterLike, InferIOAuthorizeUser, Id, Maybe, InferEventMessage, InferEventsOutput, IOLike, InferIOOutput, BaseUser, 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
 
@@ -82,6 +82,45 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
82
82
  sendMessage<TMessage extends IOEventMessage<any> = IOEventMessage<any>>(data: TMessage): void;
83
83
  }
84
84
 
85
+ interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
86
+ broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
87
+ input?: InputZodLike<TInput>;
88
+ self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
89
+ sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
90
+ }
91
+ 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" | "" = ""> {
92
+ private _broadcast;
93
+ private _input;
94
+ private _self;
95
+ private _sync;
96
+ get config(): {
97
+ broadcast: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
98
+ input: InputZodLike<TInput> | null;
99
+ resolver: () => EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TOutput>;
100
+ self: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
101
+ sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
102
+ };
103
+ constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
104
+ 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">;
105
+ input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
106
+ 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">;
107
+ 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">;
108
+ private _resolver;
109
+ }
110
+
111
+ type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
112
+ [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
113
+ };
114
+ 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 [
115
+ infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
116
+ ...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
117
+ ] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
118
+ 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> {
119
+ readonly _events: TEvents;
120
+ constructor(events: TEvents);
121
+ static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
122
+ }
123
+
85
124
  declare global {
86
125
  var console: {
87
126
  log: (...data: any[]) => void;
@@ -139,14 +178,20 @@ type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
139
178
  room: string;
140
179
  } & InferRoomContextType<TPlatform>;
141
180
  type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
142
- interface PluvIOListeners<TPlatform extends AbstractPlatform> {
143
- onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
144
- onStorageUpdated: (event: IORoomListenerEvent<TPlatform>) => void;
181
+ interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
182
+ onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
183
+ onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
184
+ onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
145
185
  }
146
- type IORoomListenerEvent<TPlatform extends AbstractPlatform> = {
147
- room: string;
186
+ type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
187
+ context: TContext & InferRoomContextType<TPlatform>;
148
188
  encodedState: string | null;
149
- } & InferRoomContextType<TPlatform>;
189
+ room: string;
190
+ };
191
+ type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
192
+ message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
193
+ user?: InferIOAuthorizeUser<TAuthorize>;
194
+ };
150
195
  type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
151
196
 
152
197
  type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage<TIO, TEvent> & {
@@ -172,12 +217,12 @@ interface ConvertWebSocketConfig {
172
217
  room: string;
173
218
  }
174
219
  declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TPlatformContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
220
+ protected readonly _ioContext: TPlatformContext | undefined;
221
+ protected readonly _roomContext: TRoomContext | undefined;
175
222
  private _initialized;
176
- readonly _ioContext: TPlatformContext | undefined;
177
- readonly _roomContext: TRoomContext | undefined;
178
- abstract readonly _registrationMode: WebSocketRegistrationMode;
179
223
  persistance: AbstractPersistance;
180
224
  pubSub: AbstractPubSub;
225
+ abstract readonly _registrationMode: WebSocketRegistrationMode;
181
226
  constructor(config?: AbstractPlatformConfig<TPlatformContext, TRoomContext>);
182
227
  abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
183
228
  abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
@@ -211,52 +256,14 @@ interface AuthorizeModule {
211
256
  encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
212
257
  }
213
258
 
214
- interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
215
- broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
216
- input?: InputZodLike<TInput>;
217
- self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
218
- sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
219
- }
220
- 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" | "" = ""> {
221
- private _broadcast;
222
- private _input;
223
- private _self;
224
- private _sync;
225
- get config(): {
226
- broadcast: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
227
- input: InputZodLike<TInput> | null;
228
- resolver: () => EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TOutput>;
229
- self: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
230
- sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
231
- };
232
- constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
233
- 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">;
234
- input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
235
- 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">;
236
- 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">;
237
- private _resolver;
238
- }
239
-
240
- type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
241
- [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
242
- };
243
- 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 [
244
- infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
245
- ...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
246
- ] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
247
- 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> {
248
- readonly _events: TEvents;
249
- constructor(events: TEvents);
250
- static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
251
- }
252
-
253
- interface IORoomListeners<TPlatform extends AbstractPlatform> {
254
- onDestroy: (event: IORoomListenerEvent<TPlatform>) => void;
259
+ interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
260
+ onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
261
+ onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
255
262
  }
256
263
  type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
257
264
  [event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
258
265
  };
259
- 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>> & {
266
+ 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, TAuthorize, TContext, TEvents>> & {
260
267
  authorize?: TAuthorize;
261
268
  context: TContext & InferRoomContextType<TPlatform>;
262
269
  crdt?: {
@@ -270,35 +277,37 @@ interface WebsocketRegisterOptions {
270
277
  token?: string | null;
271
278
  }
272
279
  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> {
280
+ readonly id: string;
281
+ readonly _authorize: TAuthorize | null;
282
+ private _doc;
283
+ private _uninitialize;
273
284
  private readonly _context;
274
285
  private readonly _debug;
275
286
  private readonly _docFactory;
287
+ private readonly _listeners;
276
288
  private readonly _platform;
277
- private _doc;
278
- private _listeners;
279
- private _sessions;
280
- private _uninitialize;
281
- readonly _authorize: TAuthorize | null;
282
- readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
283
- readonly id: string;
289
+ private readonly _router;
290
+ private readonly _sessions;
284
291
  get _events(): TEvents;
285
292
  get broadcast(): BroadcastProxy<this>;
293
+ private get _initialized();
286
294
  constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
287
295
  getSize(): number;
288
- onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => void;
289
- onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => void;
290
- onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => void;
296
+ onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
297
+ onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
298
+ onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => Promise<void>;
291
299
  register(webSocket: InferPlatformWebSocketSource<TPlatform>, options?: WebsocketRegisterOptions): Promise<void>;
292
300
  private _broadcast;
293
301
  private _emitQuitters;
294
302
  private _emitRegistered;
295
303
  private _ensureDetached;
296
304
  private _getAbstractWs;
297
- private _getSession;
298
305
  private _getAuthorizedUser;
306
+ private _getInitialDoc;
299
307
  private _getIOAuthorize;
300
308
  private _getProcedure;
301
309
  private _getProcedureInputs;
310
+ private _getSession;
302
311
  private _getSessions;
303
312
  private _initialize;
304
313
  private _logDebug;
@@ -312,87 +321,78 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
312
321
  }
313
322
 
314
323
  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;
315
- 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>> & {
324
+ 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, TAuthorize, TContext, TEvents>> & {
316
325
  authorize?: TAuthorize;
317
326
  context?: TContext;
318
327
  crdt?: {
319
328
  doc: (value: any) => AbstractCrdtDocFactory<any>;
320
329
  };
321
330
  debug?: boolean;
331
+ getInitialStorage?: GetInitialStorageFn<TPlatform>;
322
332
  platform: TPlatform;
323
333
  router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
324
334
  };
325
- type GetRoomOptions<TPlatform extends AbstractPlatform> = keyof InferRoomContextType<TPlatform> extends never ? [{
335
+ type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
326
336
  debug?: boolean;
327
- }] | [] : [Id<{
328
- debug?: boolean;
329
- } & InferRoomContextType<TPlatform>>];
337
+ };
338
+ type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>];
330
339
  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> {
331
- private _rooms;
340
+ _listeners: PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>;
341
+ readonly version: string;
332
342
  readonly _authorize: TAuthorize | null;
333
- readonly _context: TContext;
334
- readonly _crdt: {
335
- doc: (value: any) => AbstractCrdtDocFactory<any>;
336
- };
337
- readonly _debug: boolean;
338
- readonly _listeners: PluvIOListeners<TPlatform>;
339
- readonly _platform: TPlatform;
340
- readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
341
- readonly _version: string;
343
+ private readonly _baseRouter;
344
+ private readonly _context;
345
+ private readonly _crdt;
346
+ private readonly _debug;
347
+ private readonly _getInitialStorage;
348
+ private readonly _platform;
349
+ private readonly _router;
342
350
  get _events(): TEvents;
343
351
  get _registrationMode(): WebSocketRegistrationMode;
352
+ private get _procedure();
344
353
  constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
354
+ createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
345
355
  createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
346
- getRoom(room: string, ...options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
347
356
  private _logDebug;
348
- private _purgeEmptyRooms;
349
357
  }
350
358
 
351
- type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> = Partial<PluvIOListeners<TPlatform>> & {
359
+ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> = {
352
360
  authorize?: TAuthorize;
353
361
  context?: TContext;
354
362
  crdt?: {
355
363
  doc: (value: any) => AbstractCrdtDocFactory<any>;
356
364
  };
357
365
  debug?: boolean;
358
- getInitialStorage?: GetInitialStorageFn<TPlatform>;
359
366
  platform: TPlatform;
360
367
  };
361
- 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> = {}> {
368
+ type ServerConfig<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, TAuthorize, TContext, TEvents>> & {
369
+ getInitialStorage?: GetInitialStorageFn<TPlatform>;
362
370
  router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
363
- }
364
- declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> implements IOLike<TAuthorize, {}> {
365
- private _router;
371
+ };
372
+ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> {
373
+ readonly version: string;
366
374
  readonly _authorize: TAuthorize | null;
367
- readonly _context: TContext;
368
- readonly _crdt: {
369
- doc: (value: any) => AbstractCrdtDocFactory<any>;
370
- };
371
- readonly _debug: boolean;
372
- readonly _getInitialStorage: GetInitialStorageFn<TPlatform> | null;
373
- readonly _listeners: PluvIOListeners<TPlatform>;
374
- readonly _platform: TPlatform;
375
- readonly _version: string;
376
- get _events(): {};
377
- get _registrationMode(): WebSocketRegistrationMode;
375
+ private readonly _context;
376
+ private readonly _crdt;
377
+ private readonly _debug;
378
+ private readonly _platform;
378
379
  get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
379
380
  constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>);
380
- createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
381
+ createToken(params: JWTEncodeParams<InferIOAuthorizeUser<TAuthorize>, TPlatform>): Promise<string>;
381
382
  mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
382
383
  router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
383
384
  server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
384
385
  }
385
386
 
386
- type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = Partial<PluvIOListeners<TPlatform>> & {
387
+ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
387
388
  authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
388
389
  context?: TContext;
389
390
  crdt?: {
390
391
  doc: (value: any) => AbstractCrdtDocFactory<any>;
391
392
  };
392
393
  debug?: boolean;
393
- getInitialStorage?: GetInitialStorageFn<TPlatform>;
394
394
  platform: TPlatform;
395
395
  };
396
396
  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>;
397
397
 
398
- 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 };
398
+ 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 CreateRoomOptions, 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 };