@pluv/io 0.30.2 → 0.31.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 +85 -0
- package/dist/index.d.mts +37 -35
- package/dist/index.d.ts +37 -35
- package/dist/index.js +14 -13
- package/dist/index.mjs +14 -13
- package/package.json +5 -5
- package/src/AbstractPlatform.ts +9 -15
- package/src/IORoom.ts +25 -14
- package/src/PluvIO.ts +4 -4
- package/src/PluvProcedure.ts +3 -3
- package/src/PluvRouter.ts +4 -4
- package/src/PluvServer.ts +5 -5
- package/src/authorize.ts +2 -2
- package/src/createIO.ts +5 -9
- package/src/index.ts +1 -1
- package/src/types.ts +6 -5
- 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.31.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.31.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
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m39.
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
17
|
-
[32mCJS[39m [1mdist/index.js [22m[32m42.
|
|
18
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m39.94 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 134ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m42.12 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 135ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m25.
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m25.
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 2340ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m25.65 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m25.65 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,90 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.31.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b3c31d7: **BREAKING**
|
|
8
|
+
|
|
9
|
+
Fixed platform context types. This will require additional properties when registering a websocket and creating authorization tokens. See example below:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// @pluv/platform-node example
|
|
13
|
+
|
|
14
|
+
import { platformNode } from "@pluv/platform-node";
|
|
15
|
+
import { createIO } from "@pluv/io";
|
|
16
|
+
import type { IncomingMessage } from "node:http";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
|
|
19
|
+
const io = createIO({
|
|
20
|
+
// If using a function authorize parameter, `req` is now available as a param
|
|
21
|
+
authorize: ({ req }) => ({
|
|
22
|
+
required: true,
|
|
23
|
+
secret: "MY-CUSTOM-SECRET",
|
|
24
|
+
user: z.object({
|
|
25
|
+
id: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
}),
|
|
28
|
+
platformNode(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Before
|
|
32
|
+
io.createToken({
|
|
33
|
+
room: "my-custom-room",
|
|
34
|
+
user: { id: "abc123" },
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// After
|
|
38
|
+
io.createToken({
|
|
39
|
+
room: "my-custom-room",
|
|
40
|
+
user: { id: "abc123" },
|
|
41
|
+
|
|
42
|
+
// Previously not required, but now required
|
|
43
|
+
req: req as IncomingMessage,
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// @pluv/platform-cloudflare example
|
|
49
|
+
|
|
50
|
+
import { platformCloudflare } from "@pluv/platform-cloudflare";
|
|
51
|
+
import { createIO } from "@pluv/io";
|
|
52
|
+
import { z } from "zod";
|
|
53
|
+
|
|
54
|
+
const io = createIO({
|
|
55
|
+
// If using a function authorize parameter, `env` and `request` are now available as params
|
|
56
|
+
authorize: ({ env, request }) => ({
|
|
57
|
+
required: true,
|
|
58
|
+
secret: "MY-CUSTOM-SECRET",
|
|
59
|
+
user: z.object({
|
|
60
|
+
id: z.string(),
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
platformCloudflare(),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Before
|
|
67
|
+
io.createToken({
|
|
68
|
+
room: "my-custom-room",
|
|
69
|
+
user: { id: "abc123" },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// After
|
|
73
|
+
io.createToken({
|
|
74
|
+
room: "my-custom-room",
|
|
75
|
+
user: { id: "abc123" },
|
|
76
|
+
|
|
77
|
+
// Previously not required, but now required
|
|
78
|
+
env: env as Env,
|
|
79
|
+
request: request as Request,
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- @pluv/crdt@0.31.0
|
|
86
|
+
- @pluv/types@0.31.0
|
|
87
|
+
|
|
3
88
|
## 0.30.2
|
|
4
89
|
|
|
5
90
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -82,13 +82,13 @@ 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,
|
|
85
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
86
86
|
broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
87
87
|
input?: InputZodLike<TInput>;
|
|
88
88
|
self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
89
89
|
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
90
90
|
}
|
|
91
|
-
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
91
|
+
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
92
92
|
private _broadcast;
|
|
93
93
|
private _input;
|
|
94
94
|
private _self;
|
|
@@ -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 IOAuthorize<any, any,
|
|
105
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
|
|
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 IOAuthorize<any, any,
|
|
108
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, 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 IOAuthorize<any, any,
|
|
112
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
113
113
|
readonly _defs: {
|
|
114
114
|
events: TEvents;
|
|
115
115
|
};
|
|
@@ -126,8 +126,8 @@ interface CrdtLibraryType {
|
|
|
126
126
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
127
127
|
kind: "loro" | "yjs";
|
|
128
128
|
}
|
|
129
|
-
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
130
|
-
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
129
|
+
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<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>;
|
|
130
|
+
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
131
131
|
context: TContext;
|
|
132
132
|
doc: AbstractCrdtDoc<any>;
|
|
133
133
|
room: string;
|
|
@@ -178,17 +178,17 @@ type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
|
178
178
|
room: string;
|
|
179
179
|
} & InferRoomContextType<TPlatform>;
|
|
180
180
|
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
181
|
-
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
181
|
+
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
182
182
|
onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
183
183
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
184
184
|
onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
185
185
|
}
|
|
186
|
-
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
186
|
+
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
187
187
|
context: TContext & InferRoomContextType<TPlatform>;
|
|
188
188
|
encodedState: string | null;
|
|
189
189
|
room: string;
|
|
190
190
|
};
|
|
191
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
191
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
|
|
192
192
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
193
193
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
194
194
|
};
|
|
@@ -206,31 +206,31 @@ declare abstract class AbstractPubSub {
|
|
|
206
206
|
type WebSocketRegistrationMode = "attached" | "detached";
|
|
207
207
|
type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
|
|
208
208
|
type InferPlatformWebSocketSource<TPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
|
|
209
|
-
type
|
|
210
|
-
type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any,
|
|
211
|
-
type AbstractPlatformConfig<
|
|
212
|
-
context?:
|
|
209
|
+
type InferInitContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
|
|
210
|
+
type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, any, infer IRoomContext> ? IRoomContext : never;
|
|
211
|
+
type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
|
|
212
|
+
context?: TRoomContext;
|
|
213
213
|
persistence?: AbstractPersistence;
|
|
214
214
|
pubSub?: AbstractPubSub;
|
|
215
215
|
};
|
|
216
216
|
interface ConvertWebSocketConfig {
|
|
217
217
|
room: string;
|
|
218
218
|
}
|
|
219
|
-
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket,
|
|
220
|
-
protected readonly
|
|
219
|
+
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
|
|
220
|
+
protected readonly _initContext: TInitContext | undefined;
|
|
221
221
|
protected readonly _roomContext: TRoomContext | undefined;
|
|
222
222
|
private _initialized;
|
|
223
223
|
persistence: AbstractPersistence;
|
|
224
224
|
pubSub: AbstractPubSub;
|
|
225
225
|
abstract readonly _registrationMode: WebSocketRegistrationMode;
|
|
226
|
-
constructor(config?: AbstractPlatformConfig<
|
|
226
|
+
constructor(config?: AbstractPlatformConfig<TRoomContext>);
|
|
227
227
|
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
228
228
|
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
|
|
229
229
|
abstract getLastPing(webSocket: AbstractWebSocket): number | null;
|
|
230
230
|
abstract getSerializedState(webSocket: InferWebSocketSource<TWebSocket>): WebSocketSerializedState | null;
|
|
231
231
|
abstract getSessionId(webSocket: InferWebSocketSource<TWebSocket>): string | null;
|
|
232
232
|
abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
|
|
233
|
-
abstract initialize(config: AbstractPlatformConfig<
|
|
233
|
+
abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
|
|
234
234
|
abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
235
235
|
abstract randomUUID(): string;
|
|
236
236
|
abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
|
|
@@ -246,7 +246,7 @@ type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform>
|
|
|
246
246
|
maxAge?: number;
|
|
247
247
|
room: string;
|
|
248
248
|
user: TUser;
|
|
249
|
-
} &
|
|
249
|
+
} & InferInitContextType<TPlatform>;
|
|
250
250
|
interface AuthorizeParams {
|
|
251
251
|
platform: AbstractPlatform;
|
|
252
252
|
secret: string;
|
|
@@ -260,14 +260,14 @@ declare const authorize: (params: AuthorizeParams) => {
|
|
|
260
260
|
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
261
261
|
};
|
|
262
262
|
|
|
263
|
-
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
263
|
+
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
264
264
|
onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
265
265
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
266
266
|
}
|
|
267
267
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
268
268
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
269
269
|
};
|
|
270
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
270
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
271
271
|
authorize?: TAuthorize;
|
|
272
272
|
context: TContext & InferRoomContextType<TPlatform>;
|
|
273
273
|
crdt?: {
|
|
@@ -277,10 +277,10 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
277
277
|
platform: TPlatform;
|
|
278
278
|
router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
279
279
|
};
|
|
280
|
-
|
|
280
|
+
type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
281
281
|
token?: string | null;
|
|
282
|
-
}
|
|
283
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
282
|
+
} & InferInitContextType<TPlatform>;
|
|
283
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
284
284
|
readonly id: string;
|
|
285
285
|
private _doc;
|
|
286
286
|
private _uninitialize;
|
|
@@ -310,7 +310,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
310
310
|
onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
|
|
311
311
|
onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
|
|
312
312
|
onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => Promise<void>;
|
|
313
|
-
register(webSocket: InferPlatformWebSocketSource<TPlatform>, options
|
|
313
|
+
register(webSocket: InferPlatformWebSocketSource<TPlatform>, ...options: keyof InferInitContextType<TPlatform> extends never ? [{
|
|
314
|
+
token?: string;
|
|
315
|
+
}?] : [WebsocketRegisterConfig<TPlatform>]): Promise<void>;
|
|
314
316
|
private _broadcast;
|
|
315
317
|
private _emitQuitters;
|
|
316
318
|
private _emitRegistered;
|
|
@@ -335,7 +337,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
335
337
|
}
|
|
336
338
|
|
|
337
339
|
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;
|
|
338
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
340
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
339
341
|
authorize?: TAuthorize;
|
|
340
342
|
context?: TContext;
|
|
341
343
|
crdt?: {
|
|
@@ -346,11 +348,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
346
348
|
platform: TPlatform;
|
|
347
349
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
348
350
|
};
|
|
349
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
351
|
+
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
350
352
|
debug?: boolean;
|
|
351
353
|
};
|
|
352
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
353
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
354
|
+
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<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>>];
|
|
355
|
+
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
354
356
|
readonly version: string;
|
|
355
357
|
private readonly _authorize;
|
|
356
358
|
private readonly _baseRouter;
|
|
@@ -379,18 +381,18 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
379
381
|
private _logDebug;
|
|
380
382
|
}
|
|
381
383
|
|
|
382
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
384
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject> = {
|
|
383
385
|
authorize?: TAuthorize;
|
|
384
386
|
context?: TContext;
|
|
385
387
|
crdt?: CrdtLibraryType;
|
|
386
388
|
debug?: boolean;
|
|
387
389
|
platform: TPlatform;
|
|
388
390
|
};
|
|
389
|
-
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
391
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
390
392
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
391
393
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
392
394
|
};
|
|
393
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
395
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> {
|
|
394
396
|
readonly version: string;
|
|
395
397
|
private readonly _authorize;
|
|
396
398
|
private readonly _context;
|
|
@@ -406,12 +408,12 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
406
408
|
}
|
|
407
409
|
|
|
408
410
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
409
|
-
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired,
|
|
411
|
+
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
410
412
|
context?: TContext;
|
|
411
413
|
crdt?: CrdtLibraryType;
|
|
412
414
|
debug?: boolean;
|
|
413
415
|
platform: TPlatform;
|
|
414
416
|
};
|
|
415
|
-
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,
|
|
417
|
+
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, InferInitContextType<TPlatform>>, TContext>;
|
|
416
418
|
|
|
417
|
-
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 InferIORoom, type
|
|
419
|
+
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 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -82,13 +82,13 @@ 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,
|
|
85
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
86
86
|
broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
87
87
|
input?: InputZodLike<TInput>;
|
|
88
88
|
self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
89
89
|
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
90
90
|
}
|
|
91
|
-
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
91
|
+
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
92
92
|
private _broadcast;
|
|
93
93
|
private _input;
|
|
94
94
|
private _self;
|
|
@@ -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 IOAuthorize<any, any,
|
|
105
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
|
|
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 IOAuthorize<any, any,
|
|
108
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, 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 IOAuthorize<any, any,
|
|
112
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
113
113
|
readonly _defs: {
|
|
114
114
|
events: TEvents;
|
|
115
115
|
};
|
|
@@ -126,8 +126,8 @@ interface CrdtLibraryType {
|
|
|
126
126
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
127
127
|
kind: "loro" | "yjs";
|
|
128
128
|
}
|
|
129
|
-
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
130
|
-
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
129
|
+
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<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>;
|
|
130
|
+
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
131
131
|
context: TContext;
|
|
132
132
|
doc: AbstractCrdtDoc<any>;
|
|
133
133
|
room: string;
|
|
@@ -178,17 +178,17 @@ type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
|
178
178
|
room: string;
|
|
179
179
|
} & InferRoomContextType<TPlatform>;
|
|
180
180
|
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
181
|
-
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
181
|
+
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
182
182
|
onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
183
183
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
184
184
|
onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
185
185
|
}
|
|
186
|
-
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
186
|
+
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
187
187
|
context: TContext & InferRoomContextType<TPlatform>;
|
|
188
188
|
encodedState: string | null;
|
|
189
189
|
room: string;
|
|
190
190
|
};
|
|
191
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
191
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
|
|
192
192
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
193
193
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
194
194
|
};
|
|
@@ -206,31 +206,31 @@ declare abstract class AbstractPubSub {
|
|
|
206
206
|
type WebSocketRegistrationMode = "attached" | "detached";
|
|
207
207
|
type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
|
|
208
208
|
type InferPlatformWebSocketSource<TPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
|
|
209
|
-
type
|
|
210
|
-
type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any,
|
|
211
|
-
type AbstractPlatformConfig<
|
|
212
|
-
context?:
|
|
209
|
+
type InferInitContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
|
|
210
|
+
type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, any, infer IRoomContext> ? IRoomContext : never;
|
|
211
|
+
type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
|
|
212
|
+
context?: TRoomContext;
|
|
213
213
|
persistence?: AbstractPersistence;
|
|
214
214
|
pubSub?: AbstractPubSub;
|
|
215
215
|
};
|
|
216
216
|
interface ConvertWebSocketConfig {
|
|
217
217
|
room: string;
|
|
218
218
|
}
|
|
219
|
-
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket,
|
|
220
|
-
protected readonly
|
|
219
|
+
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
|
|
220
|
+
protected readonly _initContext: TInitContext | undefined;
|
|
221
221
|
protected readonly _roomContext: TRoomContext | undefined;
|
|
222
222
|
private _initialized;
|
|
223
223
|
persistence: AbstractPersistence;
|
|
224
224
|
pubSub: AbstractPubSub;
|
|
225
225
|
abstract readonly _registrationMode: WebSocketRegistrationMode;
|
|
226
|
-
constructor(config?: AbstractPlatformConfig<
|
|
226
|
+
constructor(config?: AbstractPlatformConfig<TRoomContext>);
|
|
227
227
|
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
228
228
|
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
|
|
229
229
|
abstract getLastPing(webSocket: AbstractWebSocket): number | null;
|
|
230
230
|
abstract getSerializedState(webSocket: InferWebSocketSource<TWebSocket>): WebSocketSerializedState | null;
|
|
231
231
|
abstract getSessionId(webSocket: InferWebSocketSource<TWebSocket>): string | null;
|
|
232
232
|
abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
|
|
233
|
-
abstract initialize(config: AbstractPlatformConfig<
|
|
233
|
+
abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
|
|
234
234
|
abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
235
235
|
abstract randomUUID(): string;
|
|
236
236
|
abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
|
|
@@ -246,7 +246,7 @@ type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform>
|
|
|
246
246
|
maxAge?: number;
|
|
247
247
|
room: string;
|
|
248
248
|
user: TUser;
|
|
249
|
-
} &
|
|
249
|
+
} & InferInitContextType<TPlatform>;
|
|
250
250
|
interface AuthorizeParams {
|
|
251
251
|
platform: AbstractPlatform;
|
|
252
252
|
secret: string;
|
|
@@ -260,14 +260,14 @@ declare const authorize: (params: AuthorizeParams) => {
|
|
|
260
260
|
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
261
261
|
};
|
|
262
262
|
|
|
263
|
-
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
263
|
+
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
264
264
|
onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
265
265
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
266
266
|
}
|
|
267
267
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
268
268
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
269
269
|
};
|
|
270
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
270
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
271
271
|
authorize?: TAuthorize;
|
|
272
272
|
context: TContext & InferRoomContextType<TPlatform>;
|
|
273
273
|
crdt?: {
|
|
@@ -277,10 +277,10 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
277
277
|
platform: TPlatform;
|
|
278
278
|
router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
279
279
|
};
|
|
280
|
-
|
|
280
|
+
type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
281
281
|
token?: string | null;
|
|
282
|
-
}
|
|
283
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
282
|
+
} & InferInitContextType<TPlatform>;
|
|
283
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
284
284
|
readonly id: string;
|
|
285
285
|
private _doc;
|
|
286
286
|
private _uninitialize;
|
|
@@ -310,7 +310,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
310
310
|
onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
|
|
311
311
|
onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
|
|
312
312
|
onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => Promise<void>;
|
|
313
|
-
register(webSocket: InferPlatformWebSocketSource<TPlatform>, options
|
|
313
|
+
register(webSocket: InferPlatformWebSocketSource<TPlatform>, ...options: keyof InferInitContextType<TPlatform> extends never ? [{
|
|
314
|
+
token?: string;
|
|
315
|
+
}?] : [WebsocketRegisterConfig<TPlatform>]): Promise<void>;
|
|
314
316
|
private _broadcast;
|
|
315
317
|
private _emitQuitters;
|
|
316
318
|
private _emitRegistered;
|
|
@@ -335,7 +337,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
335
337
|
}
|
|
336
338
|
|
|
337
339
|
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;
|
|
338
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
340
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
339
341
|
authorize?: TAuthorize;
|
|
340
342
|
context?: TContext;
|
|
341
343
|
crdt?: {
|
|
@@ -346,11 +348,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
346
348
|
platform: TPlatform;
|
|
347
349
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
348
350
|
};
|
|
349
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
351
|
+
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
350
352
|
debug?: boolean;
|
|
351
353
|
};
|
|
352
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
353
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
354
|
+
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<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>>];
|
|
355
|
+
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
354
356
|
readonly version: string;
|
|
355
357
|
private readonly _authorize;
|
|
356
358
|
private readonly _baseRouter;
|
|
@@ -379,18 +381,18 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
379
381
|
private _logDebug;
|
|
380
382
|
}
|
|
381
383
|
|
|
382
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
384
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends JsonObject> = {
|
|
383
385
|
authorize?: TAuthorize;
|
|
384
386
|
context?: TContext;
|
|
385
387
|
crdt?: CrdtLibraryType;
|
|
386
388
|
debug?: boolean;
|
|
387
389
|
platform: TPlatform;
|
|
388
390
|
};
|
|
389
|
-
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
391
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
390
392
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
391
393
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
392
394
|
};
|
|
393
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
395
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> {
|
|
394
396
|
readonly version: string;
|
|
395
397
|
private readonly _authorize;
|
|
396
398
|
private readonly _context;
|
|
@@ -406,12 +408,12 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
406
408
|
}
|
|
407
409
|
|
|
408
410
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
409
|
-
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired,
|
|
411
|
+
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
410
412
|
context?: TContext;
|
|
411
413
|
crdt?: CrdtLibraryType;
|
|
412
414
|
debug?: boolean;
|
|
413
415
|
platform: TPlatform;
|
|
414
416
|
};
|
|
415
|
-
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,
|
|
417
|
+
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, InferInitContextType<TPlatform>>, TContext>;
|
|
416
418
|
|
|
417
|
-
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 InferIORoom, type
|
|
419
|
+
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 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 };
|
package/dist/index.js
CHANGED
|
@@ -220,7 +220,6 @@ var AbstractPlatform = class {
|
|
|
220
220
|
this._initialized = false;
|
|
221
221
|
const { context, persistence, pubSub } = config;
|
|
222
222
|
this._meta = config._meta;
|
|
223
|
-
context && (this._ioContext = context);
|
|
224
223
|
context && (this._roomContext = context);
|
|
225
224
|
this.persistence = persistence != null ? persistence : new Persistence();
|
|
226
225
|
this.pubSub = pubSub != null ? pubSub : new PubSub();
|
|
@@ -495,9 +494,11 @@ var IORoom = class {
|
|
|
495
494
|
});
|
|
496
495
|
return this._onMessage(wsSession);
|
|
497
496
|
}
|
|
498
|
-
register(
|
|
499
|
-
return __async(this,
|
|
500
|
-
|
|
497
|
+
register(webSocket, ...options) {
|
|
498
|
+
return __async(this, null, function* () {
|
|
499
|
+
var _a, _b;
|
|
500
|
+
const _options = (_a = options[0]) != null ? _a : {};
|
|
501
|
+
const token = (_b = _options.token) != null ? _b : null;
|
|
501
502
|
const sessionId = this._platform.getSessionId(webSocket);
|
|
502
503
|
const sessionExists = typeof sessionId === "string" && this._sessions.has(sessionId);
|
|
503
504
|
if (sessionExists) return;
|
|
@@ -505,12 +506,12 @@ var IORoom = class {
|
|
|
505
506
|
this._initialize();
|
|
506
507
|
yield this._initialized;
|
|
507
508
|
}
|
|
508
|
-
const user = yield this._getAuthorizedUser(token);
|
|
509
|
-
const ioAuthorize = this._getIOAuthorize();
|
|
509
|
+
const user = yield this._getAuthorizedUser(token, _options);
|
|
510
|
+
const ioAuthorize = this._getIOAuthorize(_options);
|
|
510
511
|
const isUnauthorized = !!(ioAuthorize == null ? void 0 : ioAuthorize.required) && !user;
|
|
511
512
|
const isTokenInUse = !!user && (yield this._getSessions().then((sessions) => sessions.some((session) => {
|
|
512
|
-
var
|
|
513
|
-
return ((
|
|
513
|
+
var _a2;
|
|
514
|
+
return ((_a2 = session.user) == null ? void 0 : _a2.id) === user.id;
|
|
514
515
|
})));
|
|
515
516
|
const pluvWs = this._platform.convertWebSocket(webSocket, { room: this.id });
|
|
516
517
|
this._logDebug(`${import_kleur.default.blue(`Registering connection for room ${this.id}:`)} ${pluvWs.sessionId}`);
|
|
@@ -594,10 +595,10 @@ var IORoom = class {
|
|
|
594
595
|
const sessions = Array.from(this._sessions.values());
|
|
595
596
|
return (_b = sessions.find((pluvWs) => pluvWs.webSocket === webSocket)) != null ? _b : null;
|
|
596
597
|
}
|
|
597
|
-
_getAuthorizedUser(token) {
|
|
598
|
+
_getAuthorizedUser(token, options) {
|
|
598
599
|
return __async(this, null, function* () {
|
|
599
600
|
var _a;
|
|
600
|
-
const ioAuthorize = this._getIOAuthorize();
|
|
601
|
+
const ioAuthorize = this._getIOAuthorize(options);
|
|
601
602
|
if (!ioAuthorize) return null;
|
|
602
603
|
if (!token) return null;
|
|
603
604
|
const payload = yield authorize({
|
|
@@ -631,9 +632,9 @@ var IORoom = class {
|
|
|
631
632
|
return doc;
|
|
632
633
|
});
|
|
633
634
|
}
|
|
634
|
-
_getIOAuthorize() {
|
|
635
|
+
_getIOAuthorize(options) {
|
|
635
636
|
if (typeof this._authorize === "function") {
|
|
636
|
-
return this._authorize(
|
|
637
|
+
return this._authorize(options);
|
|
637
638
|
}
|
|
638
639
|
return this._authorize;
|
|
639
640
|
}
|
|
@@ -931,7 +932,7 @@ var IORoom = class {
|
|
|
931
932
|
};
|
|
932
933
|
|
|
933
934
|
// src/version.generated.ts
|
|
934
|
-
var version = "0.
|
|
935
|
+
var version = "0.31.0";
|
|
935
936
|
|
|
936
937
|
// src/PluvServer.ts
|
|
937
938
|
var PluvServer = class {
|
package/dist/index.mjs
CHANGED
|
@@ -178,7 +178,6 @@ var AbstractPlatform = class {
|
|
|
178
178
|
this._initialized = false;
|
|
179
179
|
const { context, persistence, pubSub } = config;
|
|
180
180
|
this._meta = config._meta;
|
|
181
|
-
context && (this._ioContext = context);
|
|
182
181
|
context && (this._roomContext = context);
|
|
183
182
|
this.persistence = persistence != null ? persistence : new Persistence();
|
|
184
183
|
this.pubSub = pubSub != null ? pubSub : new PubSub();
|
|
@@ -453,9 +452,11 @@ var IORoom = class {
|
|
|
453
452
|
});
|
|
454
453
|
return this._onMessage(wsSession);
|
|
455
454
|
}
|
|
456
|
-
register(
|
|
457
|
-
return __async(this,
|
|
458
|
-
|
|
455
|
+
register(webSocket, ...options) {
|
|
456
|
+
return __async(this, null, function* () {
|
|
457
|
+
var _a, _b;
|
|
458
|
+
const _options = (_a = options[0]) != null ? _a : {};
|
|
459
|
+
const token = (_b = _options.token) != null ? _b : null;
|
|
459
460
|
const sessionId = this._platform.getSessionId(webSocket);
|
|
460
461
|
const sessionExists = typeof sessionId === "string" && this._sessions.has(sessionId);
|
|
461
462
|
if (sessionExists) return;
|
|
@@ -463,12 +464,12 @@ var IORoom = class {
|
|
|
463
464
|
this._initialize();
|
|
464
465
|
yield this._initialized;
|
|
465
466
|
}
|
|
466
|
-
const user = yield this._getAuthorizedUser(token);
|
|
467
|
-
const ioAuthorize = this._getIOAuthorize();
|
|
467
|
+
const user = yield this._getAuthorizedUser(token, _options);
|
|
468
|
+
const ioAuthorize = this._getIOAuthorize(_options);
|
|
468
469
|
const isUnauthorized = !!(ioAuthorize == null ? void 0 : ioAuthorize.required) && !user;
|
|
469
470
|
const isTokenInUse = !!user && (yield this._getSessions().then((sessions) => sessions.some((session) => {
|
|
470
|
-
var
|
|
471
|
-
return ((
|
|
471
|
+
var _a2;
|
|
472
|
+
return ((_a2 = session.user) == null ? void 0 : _a2.id) === user.id;
|
|
472
473
|
})));
|
|
473
474
|
const pluvWs = this._platform.convertWebSocket(webSocket, { room: this.id });
|
|
474
475
|
this._logDebug(`${colors.blue(`Registering connection for room ${this.id}:`)} ${pluvWs.sessionId}`);
|
|
@@ -552,10 +553,10 @@ var IORoom = class {
|
|
|
552
553
|
const sessions = Array.from(this._sessions.values());
|
|
553
554
|
return (_b = sessions.find((pluvWs) => pluvWs.webSocket === webSocket)) != null ? _b : null;
|
|
554
555
|
}
|
|
555
|
-
_getAuthorizedUser(token) {
|
|
556
|
+
_getAuthorizedUser(token, options) {
|
|
556
557
|
return __async(this, null, function* () {
|
|
557
558
|
var _a;
|
|
558
|
-
const ioAuthorize = this._getIOAuthorize();
|
|
559
|
+
const ioAuthorize = this._getIOAuthorize(options);
|
|
559
560
|
if (!ioAuthorize) return null;
|
|
560
561
|
if (!token) return null;
|
|
561
562
|
const payload = yield authorize({
|
|
@@ -589,9 +590,9 @@ var IORoom = class {
|
|
|
589
590
|
return doc;
|
|
590
591
|
});
|
|
591
592
|
}
|
|
592
|
-
_getIOAuthorize() {
|
|
593
|
+
_getIOAuthorize(options) {
|
|
593
594
|
if (typeof this._authorize === "function") {
|
|
594
|
-
return this._authorize(
|
|
595
|
+
return this._authorize(options);
|
|
595
596
|
}
|
|
596
597
|
return this._authorize;
|
|
597
598
|
}
|
|
@@ -889,7 +890,7 @@ var IORoom = class {
|
|
|
889
890
|
};
|
|
890
891
|
|
|
891
892
|
// src/version.generated.ts
|
|
892
|
-
var version = "0.
|
|
893
|
+
var version = "0.31.0";
|
|
893
894
|
|
|
894
895
|
// src/PluvServer.ts
|
|
895
896
|
var PluvServer = class {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "@pluv/io server-side websocket manager",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"jose": "^5.9.3",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.4",
|
|
24
|
-
"@pluv/crdt": "^0.
|
|
25
|
-
"@pluv/types": "^0.
|
|
24
|
+
"@pluv/crdt": "^0.31.0",
|
|
25
|
+
"@pluv/types": "^0.31.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
30
|
"tsup": "^8.3.0",
|
|
31
31
|
"typescript": "^5.6.2",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"eslint-config-pluv": "^0.31.0",
|
|
33
|
+
"@pluv/tsconfig": "^0.31.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/AbstractPlatform.ts
CHANGED
|
@@ -13,19 +13,14 @@ export type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> =
|
|
|
13
13
|
export type InferPlatformWebSocketSource<TPlatform> =
|
|
14
14
|
TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? InferWebSocketSource<IAbstractWebSocket> : never;
|
|
15
15
|
|
|
16
|
-
export type
|
|
17
|
-
TPlatform extends AbstractPlatform<any, infer
|
|
16
|
+
export type InferInitContextType<TPlatform extends AbstractPlatform> =
|
|
17
|
+
TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
|
|
18
18
|
|
|
19
19
|
export type InferRoomContextType<TPlatform extends AbstractPlatform> =
|
|
20
|
-
TPlatform extends AbstractPlatform<any,
|
|
21
|
-
? IPlatformContext & IRoomContext
|
|
22
|
-
: never;
|
|
20
|
+
TPlatform extends AbstractPlatform<any, any, infer IRoomContext> ? IRoomContext : never;
|
|
23
21
|
|
|
24
|
-
export type AbstractPlatformConfig<
|
|
25
|
-
|
|
26
|
-
TRoomContext extends Record<string, any> = {},
|
|
27
|
-
> = {
|
|
28
|
-
context?: TPlatformContext & TRoomContext;
|
|
22
|
+
export type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
|
|
23
|
+
context?: TRoomContext;
|
|
29
24
|
persistence?: AbstractPersistence;
|
|
30
25
|
pubSub?: AbstractPubSub;
|
|
31
26
|
};
|
|
@@ -36,10 +31,10 @@ export interface ConvertWebSocketConfig {
|
|
|
36
31
|
|
|
37
32
|
export abstract class AbstractPlatform<
|
|
38
33
|
TWebSocket extends AbstractWebSocket = AbstractWebSocket,
|
|
39
|
-
|
|
34
|
+
TInitContext extends Record<string, any> = {},
|
|
40
35
|
TRoomContext extends Record<string, any> = {},
|
|
41
36
|
> {
|
|
42
|
-
protected readonly
|
|
37
|
+
protected readonly _initContext: TInitContext | undefined;
|
|
43
38
|
protected readonly _roomContext: TRoomContext | undefined;
|
|
44
39
|
|
|
45
40
|
private _initialized: boolean = false;
|
|
@@ -49,11 +44,10 @@ export abstract class AbstractPlatform<
|
|
|
49
44
|
|
|
50
45
|
public abstract readonly _registrationMode: WebSocketRegistrationMode;
|
|
51
46
|
|
|
52
|
-
constructor(config: AbstractPlatformConfig<
|
|
47
|
+
constructor(config: AbstractPlatformConfig<TRoomContext> = {}) {
|
|
53
48
|
const { context, persistence, pubSub } = config;
|
|
54
49
|
|
|
55
50
|
(this as any)._meta = (config as any)._meta;
|
|
56
|
-
context && (this._ioContext = context);
|
|
57
51
|
context && (this._roomContext = context);
|
|
58
52
|
|
|
59
53
|
this.persistence = persistence ?? new Persistence();
|
|
@@ -75,7 +69,7 @@ export abstract class AbstractPlatform<
|
|
|
75
69
|
|
|
76
70
|
public abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
|
|
77
71
|
|
|
78
|
-
public abstract initialize(config: AbstractPlatformConfig<
|
|
72
|
+
public abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
|
|
79
73
|
|
|
80
74
|
public abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
81
75
|
|
package/src/IORoom.ts
CHANGED
|
@@ -18,7 +18,12 @@ import type {
|
|
|
18
18
|
Maybe,
|
|
19
19
|
} from "@pluv/types";
|
|
20
20
|
import colors from "kleur";
|
|
21
|
-
import type {
|
|
21
|
+
import type {
|
|
22
|
+
AbstractPlatform,
|
|
23
|
+
InferInitContextType,
|
|
24
|
+
InferPlatformWebSocketSource,
|
|
25
|
+
InferRoomContextType,
|
|
26
|
+
} from "./AbstractPlatform";
|
|
22
27
|
import { AbstractCloseEvent, AbstractErrorEvent, AbstractMessageEvent, AbstractWebSocket } from "./AbstractWebSocket";
|
|
23
28
|
import type { PluvRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
24
29
|
import { authorize } from "./authorize";
|
|
@@ -42,7 +47,7 @@ interface BroadcastParams<TIO extends IORoom<any, any, any, any>> {
|
|
|
42
47
|
|
|
43
48
|
export interface IORoomListeners<
|
|
44
49
|
TPlatform extends AbstractPlatform<any>,
|
|
45
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
50
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
46
51
|
TContext extends JsonObject,
|
|
47
52
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
48
53
|
> {
|
|
@@ -59,7 +64,7 @@ export type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent ex
|
|
|
59
64
|
|
|
60
65
|
export type IORoomConfig<
|
|
61
66
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
62
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
67
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
63
68
|
TContext extends JsonObject = {},
|
|
64
69
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
65
70
|
> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
@@ -76,13 +81,13 @@ interface SendMessageSender {
|
|
|
76
81
|
user: JsonObject | null;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
export
|
|
84
|
+
export type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
80
85
|
token?: string | null;
|
|
81
|
-
}
|
|
86
|
+
} & InferInitContextType<TPlatform>;
|
|
82
87
|
|
|
83
88
|
export class IORoom<
|
|
84
89
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
85
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
90
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
86
91
|
TContext extends Record<string, any> = {},
|
|
87
92
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
88
93
|
> implements IOLike<TAuthorize, TEvents>
|
|
@@ -234,9 +239,12 @@ export class IORoom<
|
|
|
234
239
|
|
|
235
240
|
public async register(
|
|
236
241
|
webSocket: InferPlatformWebSocketSource<TPlatform>,
|
|
237
|
-
options:
|
|
242
|
+
...options: keyof InferInitContextType<TPlatform> extends never
|
|
243
|
+
? [{ token?: string }?]
|
|
244
|
+
: [WebsocketRegisterConfig<TPlatform>]
|
|
238
245
|
): Promise<void> {
|
|
239
|
-
const
|
|
246
|
+
const _options = (options[0] ?? {}) as WebsocketRegisterConfig<TPlatform>;
|
|
247
|
+
const token = _options.token ?? null;
|
|
240
248
|
|
|
241
249
|
const sessionId = this._platform.getSessionId(webSocket);
|
|
242
250
|
const sessionExists = typeof sessionId === "string" && this._sessions.has(sessionId);
|
|
@@ -248,8 +256,8 @@ export class IORoom<
|
|
|
248
256
|
await this._initialized;
|
|
249
257
|
}
|
|
250
258
|
|
|
251
|
-
const user = await this._getAuthorizedUser(token);
|
|
252
|
-
const ioAuthorize = this._getIOAuthorize();
|
|
259
|
+
const user = await this._getAuthorizedUser(token, _options);
|
|
260
|
+
const ioAuthorize = this._getIOAuthorize(_options);
|
|
253
261
|
const isUnauthorized = !!ioAuthorize?.required && !user;
|
|
254
262
|
|
|
255
263
|
// There is an attempt for multiple of the same identities. Probably malicious.
|
|
@@ -362,8 +370,11 @@ export class IORoom<
|
|
|
362
370
|
return sessions.find((pluvWs) => pluvWs.webSocket === webSocket) ?? null;
|
|
363
371
|
}
|
|
364
372
|
|
|
365
|
-
private async _getAuthorizedUser(
|
|
366
|
-
|
|
373
|
+
private async _getAuthorizedUser(
|
|
374
|
+
token: Maybe<string>,
|
|
375
|
+
options: WebsocketRegisterConfig<TPlatform>,
|
|
376
|
+
): Promise<InferIOAuthorizeUser<InferIOAuthorize<this>>> {
|
|
377
|
+
const ioAuthorize = this._getIOAuthorize(options);
|
|
367
378
|
|
|
368
379
|
if (!ioAuthorize) return null as InferIOAuthorizeUser<InferIOAuthorize<this>>;
|
|
369
380
|
if (!token) return null as InferIOAuthorizeUser<InferIOAuthorize<this>>;
|
|
@@ -406,9 +417,9 @@ export class IORoom<
|
|
|
406
417
|
return doc;
|
|
407
418
|
}
|
|
408
419
|
|
|
409
|
-
private _getIOAuthorize() {
|
|
420
|
+
private _getIOAuthorize(options: WebsocketRegisterConfig<TPlatform>) {
|
|
410
421
|
if (typeof this._authorize === "function") {
|
|
411
|
-
return this._authorize(
|
|
422
|
+
return this._authorize(options);
|
|
412
423
|
}
|
|
413
424
|
|
|
414
425
|
return this._authorize as {
|
package/src/PluvIO.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import { noop } from "@pluv/crdt";
|
|
3
3
|
import type { BaseIOAuthorize, IOAuthorize, InferIOAuthorizeUser, JsonObject } from "@pluv/types";
|
|
4
|
-
import type { AbstractPlatform,
|
|
4
|
+
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
5
5
|
import { PluvProcedure } from "./PluvProcedure";
|
|
6
6
|
import type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
7
7
|
import { PluvRouter } from "./PluvRouter";
|
|
@@ -13,7 +13,7 @@ import { __PLUV_VERSION } from "./version";
|
|
|
13
13
|
|
|
14
14
|
export type PluvIOConfig<
|
|
15
15
|
TPlatform extends AbstractPlatform<any>,
|
|
16
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
16
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
17
17
|
TContext extends JsonObject,
|
|
18
18
|
> = {
|
|
19
19
|
authorize?: TAuthorize;
|
|
@@ -25,7 +25,7 @@ export type PluvIOConfig<
|
|
|
25
25
|
|
|
26
26
|
export type ServerConfig<
|
|
27
27
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
28
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
28
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
29
29
|
TContext extends JsonObject = {},
|
|
30
30
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
31
31
|
> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
@@ -35,7 +35,7 @@ export type ServerConfig<
|
|
|
35
35
|
|
|
36
36
|
export class PluvIO<
|
|
37
37
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
38
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
38
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
39
39
|
TContext extends JsonObject = {},
|
|
40
40
|
> {
|
|
41
41
|
public readonly version: string = __PLUV_VERSION as any;
|
package/src/PluvProcedure.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { EventRecord, IOAuthorize, InputZodLike, JsonObject, ProcedureLike } from "@pluv/types";
|
|
2
|
-
import type { AbstractPlatform, InferRoomContextType } from "./AbstractPlatform";
|
|
2
|
+
import type { AbstractPlatform, InferInitContextType, InferRoomContextType } from "./AbstractPlatform";
|
|
3
3
|
import type { EventResolver, MergeEventRecords } from "./types";
|
|
4
4
|
|
|
5
5
|
export interface PluvProcedureConfig<
|
|
6
6
|
TPlatform extends AbstractPlatform<any>,
|
|
7
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
7
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
8
8
|
TContext extends JsonObject,
|
|
9
9
|
TInput extends JsonObject = {},
|
|
10
10
|
TOutput extends EventRecord<string, any> = {},
|
|
@@ -29,7 +29,7 @@ export interface PluvProcedureConfig<
|
|
|
29
29
|
|
|
30
30
|
export class PluvProcedure<
|
|
31
31
|
TPlatform extends AbstractPlatform<any>,
|
|
32
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
32
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
33
33
|
TContext extends JsonObject,
|
|
34
34
|
TInput extends JsonObject = {},
|
|
35
35
|
TOutput extends EventRecord<string, any> = {},
|
package/src/PluvRouter.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { BaseIOAuthorize, IOAuthorize, IORouterLike, JsonObject } from "@pluv/types";
|
|
2
|
-
import type { AbstractPlatform,
|
|
2
|
+
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
3
3
|
import type { PluvProcedure } from "./PluvProcedure";
|
|
4
4
|
|
|
5
5
|
export type PluvRouterEventConfig<
|
|
6
6
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
7
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
7
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
8
8
|
TContext extends JsonObject = {},
|
|
9
9
|
> = { [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config"> };
|
|
10
10
|
|
|
11
11
|
export type MergedRouter<
|
|
12
12
|
TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [],
|
|
13
13
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
14
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
14
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
15
15
|
TContext extends JsonObject = {},
|
|
16
16
|
TRoot extends TRouters[0]["_defs"]["events"] = {},
|
|
17
17
|
> = TRouters extends [
|
|
@@ -23,7 +23,7 @@ export type MergedRouter<
|
|
|
23
23
|
|
|
24
24
|
export class PluvRouter<
|
|
25
25
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
26
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
26
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
27
27
|
TContext extends JsonObject = {},
|
|
28
28
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
29
29
|
> implements IORouterLike<TEvents>
|
package/src/PluvServer.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
Maybe,
|
|
12
12
|
} from "@pluv/types";
|
|
13
13
|
import colors from "kleur";
|
|
14
|
-
import type { AbstractPlatform,
|
|
14
|
+
import type { AbstractPlatform, InferInitContextType, InferRoomContextType } from "./AbstractPlatform";
|
|
15
15
|
import type { IORoomListeners } from "./IORoom";
|
|
16
16
|
import { IORoom } from "./IORoom";
|
|
17
17
|
import { PluvProcedure } from "./PluvProcedure";
|
|
@@ -30,7 +30,7 @@ export type InferIORoom<TServer extends PluvServer<any, any, any, any>> =
|
|
|
30
30
|
|
|
31
31
|
export type PluvServerConfig<
|
|
32
32
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
33
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
33
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
34
34
|
TContext extends JsonObject = {},
|
|
35
35
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
36
36
|
> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
@@ -45,7 +45,7 @@ export type PluvServerConfig<
|
|
|
45
45
|
|
|
46
46
|
type BaseCreateRoomOptions<
|
|
47
47
|
TPlatform extends AbstractPlatform<any>,
|
|
48
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
48
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
49
49
|
TContext extends JsonObject,
|
|
50
50
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
51
51
|
> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
@@ -54,7 +54,7 @@ type BaseCreateRoomOptions<
|
|
|
54
54
|
|
|
55
55
|
export type CreateRoomOptions<
|
|
56
56
|
TPlatform extends AbstractPlatform<any>,
|
|
57
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
57
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
58
58
|
TContext extends JsonObject,
|
|
59
59
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
60
60
|
> = keyof InferRoomContextType<TPlatform> extends never
|
|
@@ -63,7 +63,7 @@ export type CreateRoomOptions<
|
|
|
63
63
|
|
|
64
64
|
export class PluvServer<
|
|
65
65
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
66
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
66
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
67
67
|
TContext extends JsonObject = {},
|
|
68
68
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
69
69
|
> implements IORouterLike<TEvents>
|
package/src/authorize.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import hkdf from "@panva/hkdf";
|
|
2
2
|
import type { BaseUser } from "@pluv/types";
|
|
3
3
|
import { EncryptJWT, jwtDecrypt } from "jose";
|
|
4
|
-
import type { AbstractPlatform,
|
|
4
|
+
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
5
5
|
|
|
6
6
|
const DEFAULT_MAX_AGE_MS = 60_000;
|
|
7
7
|
|
|
@@ -19,7 +19,7 @@ export type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPl
|
|
|
19
19
|
maxAge?: number;
|
|
20
20
|
room: string;
|
|
21
21
|
user: TUser;
|
|
22
|
-
} &
|
|
22
|
+
} & InferInitContextType<TPlatform>;
|
|
23
23
|
|
|
24
24
|
export interface AuthorizeParams {
|
|
25
25
|
platform: AbstractPlatform;
|
package/src/createIO.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BaseUser, IOAuthorize, JsonObject } from "@pluv/types";
|
|
2
|
-
import type { AbstractPlatform,
|
|
2
|
+
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
3
3
|
import { PluvIO } from "./PluvIO";
|
|
4
|
-
import { CrdtLibraryType } from "./types";
|
|
4
|
+
import type { CrdtLibraryType } from "./types";
|
|
5
5
|
|
|
6
6
|
export type CreateIOParams<
|
|
7
7
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
@@ -9,7 +9,7 @@ export type CreateIOParams<
|
|
|
9
9
|
TAuthorizeUser extends BaseUser = BaseUser,
|
|
10
10
|
TAuthorizeRequired extends boolean = false,
|
|
11
11
|
> = {
|
|
12
|
-
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired,
|
|
12
|
+
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
13
13
|
context?: TContext;
|
|
14
14
|
crdt?: CrdtLibraryType;
|
|
15
15
|
debug?: boolean;
|
|
@@ -23,16 +23,12 @@ export const createIO = <
|
|
|
23
23
|
TAuthorizeRequired extends boolean = false,
|
|
24
24
|
>(
|
|
25
25
|
params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>,
|
|
26
|
-
): PluvIO<
|
|
27
|
-
TPlatform,
|
|
28
|
-
IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>,
|
|
29
|
-
TContext
|
|
30
|
-
> => {
|
|
26
|
+
): PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>, TContext> => {
|
|
31
27
|
const { authorize, context, crdt, debug, platform } = params;
|
|
32
28
|
|
|
33
29
|
return new PluvIO<
|
|
34
30
|
TPlatform,
|
|
35
|
-
IOAuthorize<TAuthorizeUser, TAuthorizeRequired,
|
|
31
|
+
IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>,
|
|
36
32
|
TContext
|
|
37
33
|
>({
|
|
38
34
|
authorize,
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
} from "@pluv/types";
|
|
14
14
|
import type {
|
|
15
15
|
AbstractPlatform,
|
|
16
|
+
InferInitContextType,
|
|
16
17
|
InferPlatformWebSocketSource,
|
|
17
18
|
InferPlatformWebSocketType,
|
|
18
19
|
InferRoomContextType,
|
|
@@ -33,7 +34,7 @@ export interface CrdtLibraryType {
|
|
|
33
34
|
|
|
34
35
|
export type EventResolver<
|
|
35
36
|
TPlatform extends AbstractPlatform = AbstractPlatform,
|
|
36
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
37
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
37
38
|
TContext extends Record<string, any> = {},
|
|
38
39
|
TInput extends JsonObject = {},
|
|
39
40
|
TOutput extends EventRecord<string, any> = {},
|
|
@@ -41,7 +42,7 @@ export type EventResolver<
|
|
|
41
42
|
|
|
42
43
|
export interface EventResolverContext<
|
|
43
44
|
TPlatform extends AbstractPlatform = AbstractPlatform,
|
|
44
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
45
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
45
46
|
TContext extends Record<string, any> = {},
|
|
46
47
|
> {
|
|
47
48
|
context: TContext;
|
|
@@ -111,7 +112,7 @@ export type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (
|
|
|
111
112
|
|
|
112
113
|
export interface PluvIOListeners<
|
|
113
114
|
TPlatform extends AbstractPlatform<any>,
|
|
114
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
115
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
115
116
|
TContext extends JsonObject,
|
|
116
117
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
117
118
|
> {
|
|
@@ -122,7 +123,7 @@ export interface PluvIOListeners<
|
|
|
122
123
|
|
|
123
124
|
export type IORoomListenerEvent<
|
|
124
125
|
TPlatform extends AbstractPlatform<any>,
|
|
125
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
126
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
126
127
|
TContext extends JsonObject,
|
|
127
128
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
128
129
|
> = {
|
|
@@ -133,7 +134,7 @@ export type IORoomListenerEvent<
|
|
|
133
134
|
|
|
134
135
|
export type IORoomMessageEvent<
|
|
135
136
|
TPlatform extends AbstractPlatform<any>,
|
|
136
|
-
TAuthorize extends IOAuthorize<any, any,
|
|
137
|
+
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
137
138
|
TContext extends JsonObject,
|
|
138
139
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
139
140
|
> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.31.0'
|