@pluv/io 0.21.1 → 0.23.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 +80 -0
- package/dist/index.d.mts +93 -91
- package/dist/index.d.ts +93 -91
- package/dist/index.js +150 -151
- package/dist/index.mjs +150 -151
- package/package.json +5 -5
- package/src/AbstractPlatform.ts +6 -6
- package/src/AbstractWebSocket.ts +1 -0
- package/src/IORoom.ts +60 -49
- package/src/PluvIO.ts +16 -178
- package/src/PluvRouter.ts +1 -3
- package/src/PluvServer.ts +161 -22
- package/src/createIO.ts +3 -7
- package/src/types.ts +33 -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.23.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.23.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
|
-
[32mCJS[39m [1mdist/index.js [22m[32m39.
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in
|
|
17
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m37.
|
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m39.65 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 159ms
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m37.48 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 160ms
|
|
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 2147ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m24.62 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m24.62 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.23.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c01b16f: **BREAKING**
|
|
8
|
+
|
|
9
|
+
Moved `getInitialStorage`, `onRoomDeleted` and `onStorageUpdated` from `createIO` to `PluvIO.server`.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createIO } from "@pluv/io";
|
|
13
|
+
|
|
14
|
+
// Before
|
|
15
|
+
const io = createIO({
|
|
16
|
+
// ...
|
|
17
|
+
getInitialStorage: (event) => {
|
|
18
|
+
// ...
|
|
19
|
+
},
|
|
20
|
+
onRoomDeleted: (event) => {
|
|
21
|
+
// ...
|
|
22
|
+
},
|
|
23
|
+
onStorageUpdated: (event) => {
|
|
24
|
+
// ...
|
|
25
|
+
},
|
|
26
|
+
// ...
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const ioServer = io.server({
|
|
30
|
+
// ...
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// After
|
|
34
|
+
const io = createIO({
|
|
35
|
+
// ...
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const ioServer = io.server({
|
|
39
|
+
// ...
|
|
40
|
+
getInitialStorage: (event) => {
|
|
41
|
+
// ...
|
|
42
|
+
},
|
|
43
|
+
onRoomDeleted: (event) => {
|
|
44
|
+
// ...
|
|
45
|
+
},
|
|
46
|
+
onStorageUpdated: (event) => {
|
|
47
|
+
// ...
|
|
48
|
+
},
|
|
49
|
+
// ...
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Added a new listener `onRoomMessage` to `PluvIO.server` to listen to events that are sent within a room.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const ioServer = io.server({
|
|
57
|
+
// ...
|
|
58
|
+
onRoomMessage: (event) => {
|
|
59
|
+
console.log(event.message);
|
|
60
|
+
console.log(event.user);
|
|
61
|
+
},
|
|
62
|
+
// ...
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- @pluv/crdt@0.23.0
|
|
69
|
+
- @pluv/types@0.23.0
|
|
70
|
+
|
|
71
|
+
## 0.22.0
|
|
72
|
+
|
|
73
|
+
### Minor Changes
|
|
74
|
+
|
|
75
|
+
- 650e577: \* Fix `@pluv/platform-cloudflare` causing frequent disconnects due to incorrect heartbeat handling.
|
|
76
|
+
- Updated default `mode` of `@pluv/platform-cloudflare` back to `"detached"` (i.e. use Cloudflare Worker Hibernation API by default).
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- @pluv/crdt@0.22.0
|
|
81
|
+
- @pluv/types@0.22.0
|
|
82
|
+
|
|
3
83
|
## 0.21.1
|
|
4
84
|
|
|
5
85
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, BaseIOAuthorize,
|
|
1
|
+
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, BaseIOAuthorize, IORouterLike, InferIOAuthorizeUser, Id, Maybe, InferEventMessage, InferEventsOutput, IOLike, InferIOOutput, BaseUser, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { AbstractCrdtDoc, AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
4
4
|
|
|
@@ -61,6 +61,7 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
|
|
|
61
61
|
abstract get readyState(): 0 | 1 | 2 | 3;
|
|
62
62
|
abstract get sessionId(): string;
|
|
63
63
|
abstract get state(): WebSocketSerializedState;
|
|
64
|
+
abstract set state(state: WebSocketSerializedState);
|
|
64
65
|
constructor(webSocket: TWebSocket, config: AbstractWebSocketConfig);
|
|
65
66
|
/**
|
|
66
67
|
* TODO
|
|
@@ -81,6 +82,45 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
|
|
|
81
82
|
sendMessage<TMessage extends IOEventMessage<any> = IOEventMessage<any>>(data: TMessage): void;
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
86
|
+
broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
87
|
+
input?: InputZodLike<TInput>;
|
|
88
|
+
self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
89
|
+
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
90
|
+
}
|
|
91
|
+
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
92
|
+
private _broadcast;
|
|
93
|
+
private _input;
|
|
94
|
+
private _self;
|
|
95
|
+
private _sync;
|
|
96
|
+
get config(): {
|
|
97
|
+
broadcast: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
98
|
+
input: InputZodLike<TInput> | null;
|
|
99
|
+
resolver: () => EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TOutput>;
|
|
100
|
+
self: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
101
|
+
sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
102
|
+
};
|
|
103
|
+
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
104
|
+
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
105
|
+
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
106
|
+
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
107
|
+
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
108
|
+
private _resolver;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
|
|
112
|
+
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
113
|
+
};
|
|
114
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TRoot extends TRouters[0]["_events"] = {}> = TRouters extends [
|
|
115
|
+
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
116
|
+
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
117
|
+
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
118
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
119
|
+
readonly _events: TEvents;
|
|
120
|
+
constructor(events: TEvents);
|
|
121
|
+
static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
122
|
+
}
|
|
123
|
+
|
|
84
124
|
declare global {
|
|
85
125
|
var console: {
|
|
86
126
|
log: (...data: any[]) => void;
|
|
@@ -138,14 +178,20 @@ type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
|
138
178
|
room: string;
|
|
139
179
|
} & InferRoomContextType<TPlatform>;
|
|
140
180
|
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
141
|
-
interface PluvIOListeners<TPlatform extends AbstractPlatform
|
|
142
|
-
onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
143
|
-
|
|
181
|
+
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
182
|
+
onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
183
|
+
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
184
|
+
onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
144
185
|
}
|
|
145
|
-
type IORoomListenerEvent<TPlatform extends AbstractPlatform
|
|
146
|
-
|
|
186
|
+
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
187
|
+
context: TContext & InferRoomContextType<TPlatform>;
|
|
147
188
|
encodedState: string | null;
|
|
148
|
-
|
|
189
|
+
room: string;
|
|
190
|
+
};
|
|
191
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
|
|
192
|
+
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
193
|
+
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
194
|
+
};
|
|
149
195
|
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
150
196
|
|
|
151
197
|
type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage<TIO, TEvent> & {
|
|
@@ -171,17 +217,17 @@ interface ConvertWebSocketConfig {
|
|
|
171
217
|
room: string;
|
|
172
218
|
}
|
|
173
219
|
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TPlatformContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
|
|
220
|
+
protected readonly _ioContext: TPlatformContext | undefined;
|
|
221
|
+
protected readonly _roomContext: TRoomContext | undefined;
|
|
174
222
|
private _initialized;
|
|
175
|
-
readonly _ioContext: TPlatformContext | undefined;
|
|
176
|
-
readonly _roomContext: TRoomContext | undefined;
|
|
177
|
-
abstract readonly _registrationMode: WebSocketRegistrationMode;
|
|
178
223
|
persistance: AbstractPersistance;
|
|
179
224
|
pubSub: AbstractPubSub;
|
|
225
|
+
abstract readonly _registrationMode: WebSocketRegistrationMode;
|
|
180
226
|
constructor(config?: AbstractPlatformConfig<TPlatformContext, TRoomContext>);
|
|
181
227
|
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
182
228
|
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
|
|
183
229
|
abstract getLastPing(webSocket: AbstractWebSocket): number | null;
|
|
184
|
-
abstract getSerializedState(webSocket:
|
|
230
|
+
abstract getSerializedState(webSocket: InferWebSocketSource<TWebSocket>): WebSocketSerializedState | null;
|
|
185
231
|
abstract getSessionId(webSocket: InferWebSocketSource<TWebSocket>): string | null;
|
|
186
232
|
abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
|
|
187
233
|
abstract initialize(config: AbstractPlatformConfig<TPlatformContext, TRoomContext>): this;
|
|
@@ -210,52 +256,14 @@ interface AuthorizeModule {
|
|
|
210
256
|
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
211
257
|
}
|
|
212
258
|
|
|
213
|
-
interface
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
self?: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
217
|
-
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
218
|
-
}
|
|
219
|
-
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
220
|
-
private _broadcast;
|
|
221
|
-
private _input;
|
|
222
|
-
private _self;
|
|
223
|
-
private _sync;
|
|
224
|
-
get config(): {
|
|
225
|
-
broadcast: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
226
|
-
input: InputZodLike<TInput> | null;
|
|
227
|
-
resolver: () => EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TOutput>;
|
|
228
|
-
self: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
229
|
-
sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
230
|
-
};
|
|
231
|
-
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
232
|
-
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
233
|
-
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
234
|
-
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
235
|
-
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferRoomContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
236
|
-
private _resolver;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
|
|
240
|
-
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
241
|
-
};
|
|
242
|
-
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TRoot extends TRouters[0]["_events"] = {}> = TRouters extends [
|
|
243
|
-
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
244
|
-
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
245
|
-
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
246
|
-
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
247
|
-
readonly _events: TEvents;
|
|
248
|
-
constructor(events: TEvents);
|
|
249
|
-
static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
interface IORoomListeners<TPlatform extends AbstractPlatform> {
|
|
253
|
-
onDestroy: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
259
|
+
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
260
|
+
onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
261
|
+
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
254
262
|
}
|
|
255
263
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
256
264
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
257
265
|
};
|
|
258
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform>> & {
|
|
266
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
259
267
|
authorize?: TAuthorize;
|
|
260
268
|
context: TContext & InferRoomContextType<TPlatform>;
|
|
261
269
|
crdt?: {
|
|
@@ -269,17 +277,17 @@ interface WebsocketRegisterOptions {
|
|
|
269
277
|
token?: string | null;
|
|
270
278
|
}
|
|
271
279
|
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
280
|
+
readonly id: string;
|
|
281
|
+
readonly _authorize: TAuthorize | null;
|
|
282
|
+
private _doc;
|
|
283
|
+
private _uninitialize;
|
|
272
284
|
private readonly _context;
|
|
273
285
|
private readonly _debug;
|
|
274
286
|
private readonly _docFactory;
|
|
287
|
+
private readonly _listeners;
|
|
275
288
|
private readonly _platform;
|
|
276
|
-
private
|
|
277
|
-
private
|
|
278
|
-
private _sessions;
|
|
279
|
-
private _uninitialize;
|
|
280
|
-
readonly _authorize: TAuthorize | null;
|
|
281
|
-
readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
282
|
-
readonly id: string;
|
|
289
|
+
private readonly _router;
|
|
290
|
+
private readonly _sessions;
|
|
283
291
|
get _events(): TEvents;
|
|
284
292
|
get broadcast(): BroadcastProxy<this>;
|
|
285
293
|
constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
@@ -311,13 +319,14 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
311
319
|
}
|
|
312
320
|
|
|
313
321
|
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;
|
|
314
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform>> & {
|
|
322
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
315
323
|
authorize?: TAuthorize;
|
|
316
324
|
context?: TContext;
|
|
317
325
|
crdt?: {
|
|
318
326
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
319
327
|
};
|
|
320
328
|
debug?: boolean;
|
|
329
|
+
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
321
330
|
platform: TPlatform;
|
|
322
331
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
323
332
|
};
|
|
@@ -327,19 +336,20 @@ type GetRoomOptions<TPlatform extends AbstractPlatform> = keyof InferRoomContext
|
|
|
327
336
|
debug?: boolean;
|
|
328
337
|
} & InferRoomContextType<TPlatform>>];
|
|
329
338
|
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
330
|
-
|
|
339
|
+
_listeners: PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>;
|
|
340
|
+
readonly version: string;
|
|
331
341
|
readonly _authorize: TAuthorize | null;
|
|
332
|
-
readonly
|
|
333
|
-
readonly
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
readonly
|
|
337
|
-
readonly
|
|
338
|
-
readonly
|
|
339
|
-
readonly _router
|
|
340
|
-
readonly _version: string;
|
|
342
|
+
private readonly _baseRouter;
|
|
343
|
+
private readonly _context;
|
|
344
|
+
private readonly _crdt;
|
|
345
|
+
private readonly _debug;
|
|
346
|
+
private readonly _getInitialStorage;
|
|
347
|
+
private readonly _platform;
|
|
348
|
+
private readonly _rooms;
|
|
349
|
+
private readonly _router;
|
|
341
350
|
get _events(): TEvents;
|
|
342
351
|
get _registrationMode(): WebSocketRegistrationMode;
|
|
352
|
+
private get _procedure();
|
|
343
353
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
344
354
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
345
355
|
getRoom(room: string, ...options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
@@ -347,49 +357,41 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
347
357
|
private _purgeEmptyRooms;
|
|
348
358
|
}
|
|
349
359
|
|
|
350
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> =
|
|
360
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> = {
|
|
351
361
|
authorize?: TAuthorize;
|
|
352
362
|
context?: TContext;
|
|
353
363
|
crdt?: {
|
|
354
364
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
355
365
|
};
|
|
356
366
|
debug?: boolean;
|
|
357
|
-
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
358
367
|
platform: TPlatform;
|
|
359
368
|
};
|
|
360
|
-
|
|
369
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
370
|
+
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
361
371
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
362
|
-
}
|
|
363
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}>
|
|
364
|
-
|
|
372
|
+
};
|
|
373
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> {
|
|
374
|
+
readonly version: string;
|
|
365
375
|
readonly _authorize: TAuthorize | null;
|
|
366
|
-
readonly _context
|
|
367
|
-
readonly _crdt
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
readonly _debug: boolean;
|
|
371
|
-
readonly _getInitialStorage: GetInitialStorageFn<TPlatform> | null;
|
|
372
|
-
readonly _listeners: PluvIOListeners<TPlatform>;
|
|
373
|
-
readonly _platform: TPlatform;
|
|
374
|
-
readonly _version: string;
|
|
375
|
-
get _events(): {};
|
|
376
|
-
get _registrationMode(): WebSocketRegistrationMode;
|
|
376
|
+
private readonly _context;
|
|
377
|
+
private readonly _crdt;
|
|
378
|
+
private readonly _debug;
|
|
379
|
+
private readonly _platform;
|
|
377
380
|
get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
|
|
378
381
|
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>);
|
|
379
|
-
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<
|
|
382
|
+
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<TAuthorize>, TPlatform>): Promise<string>;
|
|
380
383
|
mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
381
384
|
router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
382
385
|
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
383
386
|
}
|
|
384
387
|
|
|
385
|
-
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> =
|
|
388
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
386
389
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
|
|
387
390
|
context?: TContext;
|
|
388
391
|
crdt?: {
|
|
389
392
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
390
393
|
};
|
|
391
394
|
debug?: boolean;
|
|
392
|
-
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
393
395
|
platform: TPlatform;
|
|
394
396
|
};
|
|
395
397
|
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>, TContext>;
|