@pluv/io 0.33.0 → 0.34.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 +9 -9
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +89 -47
- package/dist/index.d.ts +89 -47
- package/dist/index.js +43 -37
- package/dist/index.mjs +40 -34
- package/package.json +5 -5
- package/src/AbstractPlatform.ts +9 -4
- package/src/IORoom.ts +15 -25
- package/src/PluvIO.ts +30 -13
- package/src/PluvRouter.ts +5 -4
- package/src/PluvServer.ts +54 -30
- package/src/createIO.ts +15 -6
- package/src/index.ts +3 -1
- package/src/types.ts +73 -6
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.
|
|
2
|
+
> @pluv/io@0.34.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.
|
|
6
|
+
> @pluv/io@0.34.0 version /home/runner/work/pluv/pluv/packages/io
|
|
7
7
|
> genversion ./src/version.generated.ts --esm
|
|
8
8
|
|
|
9
9
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
[34mCLI[39m Target: es6
|
|
13
13
|
[34mESM[39m Build start
|
|
14
14
|
[34mCJS[39m Build start
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m45.55 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 105ms
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m43.38 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 123ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 2664ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m30.12 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m30.12 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.34.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 70af3b2: Updated `@pluv/io` to have a `handleMode` internally that determines if connections are handled by the `PluvServer` or by the platform itself (i.e. outside of the `PluvServer`). The internals of `@pluv/platform-node` and `@pluv/platform-cloudflare` have been updated with the required changes for this.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 0c920ea: Fix the `onUserDisconnected` event not triggering.
|
|
12
|
+
- @pluv/crdt@0.34.0
|
|
13
|
+
- @pluv/types@0.34.0
|
|
14
|
+
|
|
3
15
|
## 0.33.0
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike,
|
|
1
|
+
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, IORouterLike, BaseIOAuthorize, InferIOAuthorizeUser, Id, Maybe, BaseUser, UndefinedProps, InferEventMessage, InferEventsOutput, IOLike, InferIOOutput, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { AbstractCrdtDocFactory, AbstractCrdtDoc } from '@pluv/crdt';
|
|
4
4
|
|
|
@@ -102,14 +102,14 @@ declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize
|
|
|
102
102
|
private _resolver;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
105
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}> = {
|
|
106
106
|
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
107
107
|
};
|
|
108
|
-
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
108
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [
|
|
109
109
|
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
110
110
|
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
111
111
|
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_defs"]["events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
112
|
-
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
112
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
113
113
|
readonly _defs: {
|
|
114
114
|
events: TEvents;
|
|
115
115
|
};
|
|
@@ -180,19 +180,52 @@ type GetInitialStorageEvent<TContext extends Record<string, any>> = {
|
|
|
180
180
|
room: string;
|
|
181
181
|
};
|
|
182
182
|
type GetInitialStorageFn<TContext extends Record<string, any>> = (event: GetInitialStorageEvent<TContext>) => MaybePromise<Maybe<string>>;
|
|
183
|
-
|
|
183
|
+
type HandleMode = "io" | "fetch";
|
|
184
|
+
type WebSocketRegistrationMode = "attached" | "detached";
|
|
185
|
+
interface PlatformConfig {
|
|
186
|
+
authorize: {
|
|
187
|
+
required?: boolean;
|
|
188
|
+
secret?: boolean;
|
|
189
|
+
};
|
|
190
|
+
requireAuth?: boolean;
|
|
191
|
+
handleMode: HandleMode;
|
|
192
|
+
registrationMode: WebSocketRegistrationMode;
|
|
193
|
+
listeners: {
|
|
194
|
+
onRoomDeleted?: boolean;
|
|
195
|
+
onRoomMessage?: boolean;
|
|
196
|
+
onStorageUpdated?: boolean;
|
|
197
|
+
onUserConnected?: boolean;
|
|
198
|
+
onUserDisconnected?: boolean;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
type ResolvedPluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any, TRequired extends boolean = false> = {
|
|
202
|
+
user: InputZodLike<TUser>;
|
|
203
|
+
required?: TRequired;
|
|
204
|
+
} & UndefinedProps<{
|
|
205
|
+
secret?: string;
|
|
206
|
+
}, Exclude<"secret", InferPlatformAuthorizeProperties<TPlatform>>>;
|
|
207
|
+
type PluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any, TRequired extends boolean = false, TContext extends Record<string, unknown> = {}> = ResolvedPluvIOAuthorize<TPlatform, TUser, TRequired> | ((context: TContext) => ResolvedPluvIOAuthorize<TPlatform, TUser, TRequired>);
|
|
208
|
+
type BasePluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
184
209
|
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
185
210
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
186
211
|
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
187
212
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
188
213
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
189
|
-
}
|
|
214
|
+
};
|
|
215
|
+
type PluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = UndefinedProps<BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, Exclude<keyof BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, InferPlatformListeners<TPlatform>>>;
|
|
216
|
+
type InferPlatformConfig<TPlatform extends AbstractPlatform<any, any, any, any>> = TPlatform extends AbstractPlatform<any, any, any, infer IConfig> ? IConfig : never;
|
|
217
|
+
type InferPlatformAuthorizeProperties<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
218
|
+
[P in keyof PlatformConfig["authorize"] as InferPlatformConfig<TPlatform>["authorize"][P] extends true | undefined ? P : never]: true;
|
|
219
|
+
};
|
|
220
|
+
type InferPlatformListeners<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
221
|
+
[P in keyof PlatformConfig["listeners"] as InferPlatformConfig<TPlatform>["listeners"][P] extends true | undefined ? P : never]: true;
|
|
222
|
+
};
|
|
190
223
|
type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
191
224
|
context: TContext;
|
|
192
225
|
encodedState: string | null;
|
|
193
226
|
room: string;
|
|
194
227
|
};
|
|
195
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends
|
|
228
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TContext> & {
|
|
196
229
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
197
230
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
198
231
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
@@ -219,7 +252,29 @@ declare abstract class AbstractPubSub {
|
|
|
219
252
|
abstract unsubscribe(subscriptionId: number): void;
|
|
220
253
|
}
|
|
221
254
|
|
|
222
|
-
|
|
255
|
+
interface JWT<TUser extends BaseUser> {
|
|
256
|
+
room: string;
|
|
257
|
+
sub: string;
|
|
258
|
+
user: TUser;
|
|
259
|
+
}
|
|
260
|
+
type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
|
|
261
|
+
maxAge?: number;
|
|
262
|
+
room: string;
|
|
263
|
+
user: TUser;
|
|
264
|
+
} & InferInitContextType<TPlatform>;
|
|
265
|
+
interface AuthorizeParams {
|
|
266
|
+
platform: AbstractPlatform;
|
|
267
|
+
secret: string;
|
|
268
|
+
}
|
|
269
|
+
interface AuthorizeModule {
|
|
270
|
+
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
271
|
+
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
272
|
+
}
|
|
273
|
+
declare const authorize: (params: AuthorizeParams) => {
|
|
274
|
+
decode: <TUser extends BaseUser>(jwt: string) => Promise<JWT<TUser> | null>;
|
|
275
|
+
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
276
|
+
};
|
|
277
|
+
|
|
223
278
|
type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
|
|
224
279
|
type InferPlatformWebSocketSource<TPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
|
|
225
280
|
type InferInitContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
|
|
@@ -232,13 +287,16 @@ type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
|
|
|
232
287
|
interface ConvertWebSocketConfig {
|
|
233
288
|
room: string;
|
|
234
289
|
}
|
|
235
|
-
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
|
|
290
|
+
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}, TConfig extends PlatformConfig = PlatformConfig> {
|
|
236
291
|
protected readonly _initContext: TInitContext | undefined;
|
|
237
292
|
protected readonly _roomContext: TRoomContext | undefined;
|
|
238
293
|
private _initialized;
|
|
239
294
|
persistence: AbstractPersistence;
|
|
240
295
|
pubSub: AbstractPubSub;
|
|
241
|
-
|
|
296
|
+
readonly _createToken?: (params: JWTEncodeParams<any, any>) => Promise<string>;
|
|
297
|
+
_fetch?: (req: any) => Promise<any>;
|
|
298
|
+
abstract readonly _config: TConfig;
|
|
299
|
+
abstract readonly _name: string;
|
|
242
300
|
constructor(config?: AbstractPlatformConfig<TRoomContext>);
|
|
243
301
|
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
244
302
|
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
|
|
@@ -250,33 +308,11 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = A
|
|
|
250
308
|
abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
251
309
|
abstract randomUUID(): string;
|
|
252
310
|
abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
|
|
311
|
+
validateConfig(config: any): void;
|
|
253
312
|
protected _initialize(): this;
|
|
254
313
|
}
|
|
255
314
|
|
|
256
|
-
interface
|
|
257
|
-
room: string;
|
|
258
|
-
sub: string;
|
|
259
|
-
user: TUser;
|
|
260
|
-
}
|
|
261
|
-
type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
|
|
262
|
-
maxAge?: number;
|
|
263
|
-
room: string;
|
|
264
|
-
user: TUser;
|
|
265
|
-
} & InferInitContextType<TPlatform>;
|
|
266
|
-
interface AuthorizeParams {
|
|
267
|
-
platform: AbstractPlatform;
|
|
268
|
-
secret: string;
|
|
269
|
-
}
|
|
270
|
-
interface AuthorizeModule {
|
|
271
|
-
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
272
|
-
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
273
|
-
}
|
|
274
|
-
declare const authorize: (params: AuthorizeParams) => {
|
|
275
|
-
decode: <TUser extends BaseUser>(jwt: string) => Promise<JWT<TUser> | null>;
|
|
276
|
-
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
315
|
+
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
280
316
|
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
281
317
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
282
318
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -285,7 +321,7 @@ interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize ex
|
|
|
285
321
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
286
322
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
287
323
|
};
|
|
288
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
324
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
289
325
|
authorize?: TAuthorize;
|
|
290
326
|
context: TContext;
|
|
291
327
|
crdt?: {
|
|
@@ -299,7 +335,7 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
299
335
|
type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
300
336
|
token?: string | null;
|
|
301
337
|
} & InferInitContextType<TPlatform>;
|
|
302
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
338
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
303
339
|
readonly id: string;
|
|
304
340
|
private _doc;
|
|
305
341
|
private _uninitialize;
|
|
@@ -367,7 +403,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
367
403
|
}
|
|
368
404
|
|
|
369
405
|
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;
|
|
370
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
406
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
371
407
|
authorize?: TAuthorize;
|
|
372
408
|
context?: PluvContext<TPlatform, TContext>;
|
|
373
409
|
crdt?: {
|
|
@@ -378,11 +414,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
378
414
|
platform: TPlatform;
|
|
379
415
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
380
416
|
};
|
|
381
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends
|
|
417
|
+
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
382
418
|
debug?: boolean;
|
|
383
419
|
};
|
|
384
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends
|
|
385
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
420
|
+
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>];
|
|
421
|
+
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
386
422
|
readonly version: string;
|
|
387
423
|
private readonly _authorize;
|
|
388
424
|
private readonly _baseRouter;
|
|
@@ -392,6 +428,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
392
428
|
private readonly _getInitialStorage;
|
|
393
429
|
private readonly _platform;
|
|
394
430
|
private readonly _router;
|
|
431
|
+
get fetch(): (req: any) => Promise<any>;
|
|
395
432
|
/**
|
|
396
433
|
* @ignore
|
|
397
434
|
* @readonly
|
|
@@ -407,22 +444,26 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
407
444
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
408
445
|
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
409
446
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
447
|
+
private _getIOAuthorize;
|
|
410
448
|
private _getListeners;
|
|
411
449
|
private _logDebug;
|
|
412
450
|
}
|
|
413
451
|
|
|
414
452
|
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = {
|
|
415
|
-
authorize?: TAuthorize;
|
|
416
453
|
context?: PluvContext<TPlatform, TContext>;
|
|
417
454
|
crdt?: CrdtLibraryType;
|
|
418
455
|
debug?: boolean;
|
|
419
456
|
platform: TPlatform;
|
|
420
|
-
}
|
|
421
|
-
|
|
457
|
+
} & (InferPlatformConfig<TPlatform>["requireAuth"] extends true ? {
|
|
458
|
+
authorize: TAuthorize;
|
|
459
|
+
} : {
|
|
460
|
+
authorize?: TAuthorize;
|
|
461
|
+
});
|
|
462
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
422
463
|
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
423
464
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
424
465
|
};
|
|
425
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
466
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}> {
|
|
426
467
|
readonly version: string;
|
|
427
468
|
private readonly _authorize;
|
|
428
469
|
private readonly _context;
|
|
@@ -435,15 +476,16 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
435
476
|
mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
436
477
|
router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
437
478
|
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
479
|
+
private _getIOAuthorize;
|
|
438
480
|
}
|
|
439
481
|
|
|
440
482
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
441
|
-
authorize?:
|
|
483
|
+
authorize?: PluvIOAuthorize<TPlatform, TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
442
484
|
context?: PluvContext<TPlatform, TContext>;
|
|
443
485
|
crdt?: CrdtLibraryType;
|
|
444
486
|
debug?: boolean;
|
|
445
487
|
platform: TPlatform;
|
|
446
488
|
};
|
|
447
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform,
|
|
489
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}, PlatformConfig>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>, TContext>;
|
|
448
490
|
|
|
449
|
-
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
|
491
|
+
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type HandleMode, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, type PlatformConfig, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike,
|
|
1
|
+
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, IORouterLike, BaseIOAuthorize, InferIOAuthorizeUser, Id, Maybe, BaseUser, UndefinedProps, InferEventMessage, InferEventsOutput, IOLike, InferIOOutput, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { AbstractCrdtDocFactory, AbstractCrdtDoc } from '@pluv/crdt';
|
|
4
4
|
|
|
@@ -102,14 +102,14 @@ declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize
|
|
|
102
102
|
private _resolver;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
105
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}> = {
|
|
106
106
|
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
107
107
|
};
|
|
108
|
-
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
108
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [
|
|
109
109
|
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
110
110
|
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
111
111
|
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_defs"]["events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
112
|
-
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
112
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
113
113
|
readonly _defs: {
|
|
114
114
|
events: TEvents;
|
|
115
115
|
};
|
|
@@ -180,19 +180,52 @@ type GetInitialStorageEvent<TContext extends Record<string, any>> = {
|
|
|
180
180
|
room: string;
|
|
181
181
|
};
|
|
182
182
|
type GetInitialStorageFn<TContext extends Record<string, any>> = (event: GetInitialStorageEvent<TContext>) => MaybePromise<Maybe<string>>;
|
|
183
|
-
|
|
183
|
+
type HandleMode = "io" | "fetch";
|
|
184
|
+
type WebSocketRegistrationMode = "attached" | "detached";
|
|
185
|
+
interface PlatformConfig {
|
|
186
|
+
authorize: {
|
|
187
|
+
required?: boolean;
|
|
188
|
+
secret?: boolean;
|
|
189
|
+
};
|
|
190
|
+
requireAuth?: boolean;
|
|
191
|
+
handleMode: HandleMode;
|
|
192
|
+
registrationMode: WebSocketRegistrationMode;
|
|
193
|
+
listeners: {
|
|
194
|
+
onRoomDeleted?: boolean;
|
|
195
|
+
onRoomMessage?: boolean;
|
|
196
|
+
onStorageUpdated?: boolean;
|
|
197
|
+
onUserConnected?: boolean;
|
|
198
|
+
onUserDisconnected?: boolean;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
type ResolvedPluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any, TRequired extends boolean = false> = {
|
|
202
|
+
user: InputZodLike<TUser>;
|
|
203
|
+
required?: TRequired;
|
|
204
|
+
} & UndefinedProps<{
|
|
205
|
+
secret?: string;
|
|
206
|
+
}, Exclude<"secret", InferPlatformAuthorizeProperties<TPlatform>>>;
|
|
207
|
+
type PluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any, TRequired extends boolean = false, TContext extends Record<string, unknown> = {}> = ResolvedPluvIOAuthorize<TPlatform, TUser, TRequired> | ((context: TContext) => ResolvedPluvIOAuthorize<TPlatform, TUser, TRequired>);
|
|
208
|
+
type BasePluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
184
209
|
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
185
210
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
186
211
|
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
187
212
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
188
213
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
189
|
-
}
|
|
214
|
+
};
|
|
215
|
+
type PluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = UndefinedProps<BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, Exclude<keyof BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, InferPlatformListeners<TPlatform>>>;
|
|
216
|
+
type InferPlatformConfig<TPlatform extends AbstractPlatform<any, any, any, any>> = TPlatform extends AbstractPlatform<any, any, any, infer IConfig> ? IConfig : never;
|
|
217
|
+
type InferPlatformAuthorizeProperties<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
218
|
+
[P in keyof PlatformConfig["authorize"] as InferPlatformConfig<TPlatform>["authorize"][P] extends true | undefined ? P : never]: true;
|
|
219
|
+
};
|
|
220
|
+
type InferPlatformListeners<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
221
|
+
[P in keyof PlatformConfig["listeners"] as InferPlatformConfig<TPlatform>["listeners"][P] extends true | undefined ? P : never]: true;
|
|
222
|
+
};
|
|
190
223
|
type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
191
224
|
context: TContext;
|
|
192
225
|
encodedState: string | null;
|
|
193
226
|
room: string;
|
|
194
227
|
};
|
|
195
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends
|
|
228
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TContext> & {
|
|
196
229
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
197
230
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
198
231
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
@@ -219,7 +252,29 @@ declare abstract class AbstractPubSub {
|
|
|
219
252
|
abstract unsubscribe(subscriptionId: number): void;
|
|
220
253
|
}
|
|
221
254
|
|
|
222
|
-
|
|
255
|
+
interface JWT<TUser extends BaseUser> {
|
|
256
|
+
room: string;
|
|
257
|
+
sub: string;
|
|
258
|
+
user: TUser;
|
|
259
|
+
}
|
|
260
|
+
type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
|
|
261
|
+
maxAge?: number;
|
|
262
|
+
room: string;
|
|
263
|
+
user: TUser;
|
|
264
|
+
} & InferInitContextType<TPlatform>;
|
|
265
|
+
interface AuthorizeParams {
|
|
266
|
+
platform: AbstractPlatform;
|
|
267
|
+
secret: string;
|
|
268
|
+
}
|
|
269
|
+
interface AuthorizeModule {
|
|
270
|
+
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
271
|
+
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
272
|
+
}
|
|
273
|
+
declare const authorize: (params: AuthorizeParams) => {
|
|
274
|
+
decode: <TUser extends BaseUser>(jwt: string) => Promise<JWT<TUser> | null>;
|
|
275
|
+
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
276
|
+
};
|
|
277
|
+
|
|
223
278
|
type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
|
|
224
279
|
type InferPlatformWebSocketSource<TPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
|
|
225
280
|
type InferInitContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
|
|
@@ -232,13 +287,16 @@ type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
|
|
|
232
287
|
interface ConvertWebSocketConfig {
|
|
233
288
|
room: string;
|
|
234
289
|
}
|
|
235
|
-
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
|
|
290
|
+
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}, TConfig extends PlatformConfig = PlatformConfig> {
|
|
236
291
|
protected readonly _initContext: TInitContext | undefined;
|
|
237
292
|
protected readonly _roomContext: TRoomContext | undefined;
|
|
238
293
|
private _initialized;
|
|
239
294
|
persistence: AbstractPersistence;
|
|
240
295
|
pubSub: AbstractPubSub;
|
|
241
|
-
|
|
296
|
+
readonly _createToken?: (params: JWTEncodeParams<any, any>) => Promise<string>;
|
|
297
|
+
_fetch?: (req: any) => Promise<any>;
|
|
298
|
+
abstract readonly _config: TConfig;
|
|
299
|
+
abstract readonly _name: string;
|
|
242
300
|
constructor(config?: AbstractPlatformConfig<TRoomContext>);
|
|
243
301
|
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
244
302
|
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
|
|
@@ -250,33 +308,11 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = A
|
|
|
250
308
|
abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
251
309
|
abstract randomUUID(): string;
|
|
252
310
|
abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
|
|
311
|
+
validateConfig(config: any): void;
|
|
253
312
|
protected _initialize(): this;
|
|
254
313
|
}
|
|
255
314
|
|
|
256
|
-
interface
|
|
257
|
-
room: string;
|
|
258
|
-
sub: string;
|
|
259
|
-
user: TUser;
|
|
260
|
-
}
|
|
261
|
-
type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
|
|
262
|
-
maxAge?: number;
|
|
263
|
-
room: string;
|
|
264
|
-
user: TUser;
|
|
265
|
-
} & InferInitContextType<TPlatform>;
|
|
266
|
-
interface AuthorizeParams {
|
|
267
|
-
platform: AbstractPlatform;
|
|
268
|
-
secret: string;
|
|
269
|
-
}
|
|
270
|
-
interface AuthorizeModule {
|
|
271
|
-
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
272
|
-
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
273
|
-
}
|
|
274
|
-
declare const authorize: (params: AuthorizeParams) => {
|
|
275
|
-
decode: <TUser extends BaseUser>(jwt: string) => Promise<JWT<TUser> | null>;
|
|
276
|
-
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
315
|
+
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
280
316
|
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
281
317
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
282
318
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -285,7 +321,7 @@ interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize ex
|
|
|
285
321
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
286
322
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
287
323
|
};
|
|
288
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
324
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
289
325
|
authorize?: TAuthorize;
|
|
290
326
|
context: TContext;
|
|
291
327
|
crdt?: {
|
|
@@ -299,7 +335,7 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
299
335
|
type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
300
336
|
token?: string | null;
|
|
301
337
|
} & InferInitContextType<TPlatform>;
|
|
302
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
338
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
303
339
|
readonly id: string;
|
|
304
340
|
private _doc;
|
|
305
341
|
private _uninitialize;
|
|
@@ -367,7 +403,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
367
403
|
}
|
|
368
404
|
|
|
369
405
|
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;
|
|
370
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
406
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
371
407
|
authorize?: TAuthorize;
|
|
372
408
|
context?: PluvContext<TPlatform, TContext>;
|
|
373
409
|
crdt?: {
|
|
@@ -378,11 +414,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
378
414
|
platform: TPlatform;
|
|
379
415
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
380
416
|
};
|
|
381
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends
|
|
417
|
+
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
382
418
|
debug?: boolean;
|
|
383
419
|
};
|
|
384
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends
|
|
385
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
420
|
+
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>];
|
|
421
|
+
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
386
422
|
readonly version: string;
|
|
387
423
|
private readonly _authorize;
|
|
388
424
|
private readonly _baseRouter;
|
|
@@ -392,6 +428,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
392
428
|
private readonly _getInitialStorage;
|
|
393
429
|
private readonly _platform;
|
|
394
430
|
private readonly _router;
|
|
431
|
+
get fetch(): (req: any) => Promise<any>;
|
|
395
432
|
/**
|
|
396
433
|
* @ignore
|
|
397
434
|
* @readonly
|
|
@@ -407,22 +444,26 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
407
444
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
408
445
|
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
409
446
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
447
|
+
private _getIOAuthorize;
|
|
410
448
|
private _getListeners;
|
|
411
449
|
private _logDebug;
|
|
412
450
|
}
|
|
413
451
|
|
|
414
452
|
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = {
|
|
415
|
-
authorize?: TAuthorize;
|
|
416
453
|
context?: PluvContext<TPlatform, TContext>;
|
|
417
454
|
crdt?: CrdtLibraryType;
|
|
418
455
|
debug?: boolean;
|
|
419
456
|
platform: TPlatform;
|
|
420
|
-
}
|
|
421
|
-
|
|
457
|
+
} & (InferPlatformConfig<TPlatform>["requireAuth"] extends true ? {
|
|
458
|
+
authorize: TAuthorize;
|
|
459
|
+
} : {
|
|
460
|
+
authorize?: TAuthorize;
|
|
461
|
+
});
|
|
462
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
422
463
|
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
423
464
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
424
465
|
};
|
|
425
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends
|
|
466
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}> {
|
|
426
467
|
readonly version: string;
|
|
427
468
|
private readonly _authorize;
|
|
428
469
|
private readonly _context;
|
|
@@ -435,15 +476,16 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
435
476
|
mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
436
477
|
router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
437
478
|
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
479
|
+
private _getIOAuthorize;
|
|
438
480
|
}
|
|
439
481
|
|
|
440
482
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
441
|
-
authorize?:
|
|
483
|
+
authorize?: PluvIOAuthorize<TPlatform, TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
442
484
|
context?: PluvContext<TPlatform, TContext>;
|
|
443
485
|
crdt?: CrdtLibraryType;
|
|
444
486
|
debug?: boolean;
|
|
445
487
|
platform: TPlatform;
|
|
446
488
|
};
|
|
447
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform,
|
|
489
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}, PlatformConfig>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>, TContext>;
|
|
448
490
|
|
|
449
|
-
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|
|
491
|
+
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type HandleMode, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, type PlatformConfig, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|