@pluv/io 0.17.2 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +136 -0
- package/dist/index.d.mts +121 -57
- package/dist/index.d.ts +121 -57
- package/dist/index.js +300 -284
- package/dist/index.mjs +297 -284
- package/package.json +6 -6
- package/src/AbstractPersistance.ts +4 -16
- package/src/AbstractPlatform.ts +4 -14
- package/src/AbstractPubSub.ts +1 -4
- package/src/AbstractWebSocket.ts +6 -21
- package/src/IORoom.ts +117 -270
- package/src/Persistance.ts +3 -11
- package/src/PluvIO.ts +156 -473
- package/src/PluvProcedure.ts +203 -0
- package/src/PluvRouter.ts +46 -0
- package/src/PluvServer.ts +182 -0
- package/src/PubSub.ts +6 -18
- package/src/authorize.ts +5 -22
- package/src/createIO.ts +10 -49
- package/src/index.ts +9 -13
- package/src/types.ts +49 -101
- 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.18.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.18.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[
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
17
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
18
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m32.68 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 177ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m34.85 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 181ms
|
|
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 2573ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m21.67 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m21.67 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,141 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 428c21c: Added broadcast proxy as a new way to broadcast events to a room.
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
// backend
|
|
11
|
+
|
|
12
|
+
const io = createIO({
|
|
13
|
+
/* ... */
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const router = io.router({
|
|
17
|
+
SEND_MESSAGE: io.procedure
|
|
18
|
+
.input(z.object({ message: z.string() }))
|
|
19
|
+
.broadcast(({ message }) => ({ RECEIVE_MESSAGE: { message } })),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const ioServer = io.server({ router });
|
|
23
|
+
|
|
24
|
+
const room = ioServer.getRoom("MY_EXAMPLE_ROOM");
|
|
25
|
+
|
|
26
|
+
// Both of the examples below are equivalent.
|
|
27
|
+
|
|
28
|
+
room.broadcast("SEND_MESSAGE", { message: "Hello world~!" });
|
|
29
|
+
|
|
30
|
+
room.broadcast.SEND_MESSAGE({ message: "Hello world~!" });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- 329dbcd: Narrowed types for `user` within the session object of an event resolver.
|
|
34
|
+
- 99b5ca9: ## Breaking Changes
|
|
35
|
+
|
|
36
|
+
- `@pluv/io` has been updated to introduce `PluvProcedure`, `PluvRouter` and `PluvServer`. This change is intended to improve the ergonomics of declaring events and simplifying inferences of event types.
|
|
37
|
+
|
|
38
|
+
### Before:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// backend/io.ts
|
|
42
|
+
|
|
43
|
+
import { createIO } from "@pluv/io";
|
|
44
|
+
import { createPluvHandler, platformNode } from "@pluv/platform-node";
|
|
45
|
+
import { z } from "zod";
|
|
46
|
+
|
|
47
|
+
export const io = createIO({
|
|
48
|
+
platform: platformNode(),
|
|
49
|
+
})
|
|
50
|
+
.event("SEND_MESSAGE", {
|
|
51
|
+
input: z.object({ message: z.string() }),
|
|
52
|
+
resolver: ({ message }) => ({ RECEIVE_MESSAGE: { message } }),
|
|
53
|
+
})
|
|
54
|
+
.event("DOUBLE_VALUE", {
|
|
55
|
+
input: z.object({ value: z.number() }),
|
|
56
|
+
resolver: ({ value }) => ({ VALUE_DOUBLED: { value: value * 2 } }),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const Pluv = createPluvHandler({
|
|
60
|
+
io,
|
|
61
|
+
/* ... */
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// frontend/pluv.ts
|
|
67
|
+
|
|
68
|
+
import { createClient } from "@pluv/react";
|
|
69
|
+
import type { io } from "../backend/io";
|
|
70
|
+
|
|
71
|
+
const client = createClient<typeof io>({
|
|
72
|
+
/* ... */
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Now:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { createIO } from "@pluv/io";
|
|
80
|
+
import { createPluvHandler, platformNode } from "@pluv/platform-node";
|
|
81
|
+
import { z } from "zod";
|
|
82
|
+
|
|
83
|
+
const io = createIO({
|
|
84
|
+
platform: platformNode(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const router = io.router({
|
|
88
|
+
SEND_MESSAGE: io.procedure
|
|
89
|
+
.input(z.object({ message: z.string() }))
|
|
90
|
+
.broadcast(({ message }) => ({
|
|
91
|
+
RECEIVE_MESSAGE: { message },
|
|
92
|
+
})),
|
|
93
|
+
DOUBLE_VALUE: io.procedure
|
|
94
|
+
.input(z.object({ value: z.number() }))
|
|
95
|
+
.broadcast(({ value }) => ({
|
|
96
|
+
VALUE_DOUBLED: { value: value * 2 },
|
|
97
|
+
})),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export const ioServer = io.server({ router });
|
|
101
|
+
|
|
102
|
+
const Pluv = createPluvHandler({
|
|
103
|
+
io: ioServer, // <- This uses the PluvServer now
|
|
104
|
+
/* ... */
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// frontend/pluv.ts
|
|
110
|
+
|
|
111
|
+
import { createClient } from "@pluv/react";
|
|
112
|
+
import type { ioServer } from "../backend/io";
|
|
113
|
+
|
|
114
|
+
// This users the PluvServer type now
|
|
115
|
+
const client = createClient<typeof ioServer>({
|
|
116
|
+
/* ... */
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- `PluvRouter` instances can also be merged via the `mergeRouters` method, which effectively performs an `Object.assign` of the events object and returns a new `PluvRouter` with the correct types:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const router = io.mergeRouters(router1, router2);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Patch Changes
|
|
127
|
+
|
|
128
|
+
- Updated dependencies [99b5ca9]
|
|
129
|
+
- @pluv/types@0.18.0
|
|
130
|
+
- @pluv/crdt@0.18.0
|
|
131
|
+
|
|
132
|
+
## 0.17.3
|
|
133
|
+
|
|
134
|
+
### Patch Changes
|
|
135
|
+
|
|
136
|
+
- @pluv/crdt@0.17.3
|
|
137
|
+
- @pluv/types@0.17.3
|
|
138
|
+
|
|
3
139
|
## 0.17.2
|
|
4
140
|
|
|
5
141
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOEventMessage,
|
|
1
|
+
import { JsonObject, MaybePromise, IOEventMessage, IOAuthorize, BaseIOAuthorize, InferIOAuthorizeUser, EventRecord, Id, Maybe, IOLike, InferIOOutput, InputZodLike, IORouterLike, InferIOInput, BaseUser, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { AbstractCrdtDoc, AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
4
4
|
|
|
@@ -35,7 +35,7 @@ type EventType = keyof AbstractEventMap;
|
|
|
35
35
|
interface AbstractWebSocketHandleErrorParams {
|
|
36
36
|
error: unknown;
|
|
37
37
|
message?: string;
|
|
38
|
-
session?: WebSocketSession
|
|
38
|
+
session?: WebSocketSession<any>;
|
|
39
39
|
}
|
|
40
40
|
type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEventMap[TType]) => MaybePromise<void>;
|
|
41
41
|
interface AbstractWebSocketConfig {
|
|
@@ -80,13 +80,8 @@ declare global {
|
|
|
80
80
|
log: (...data: any[]) => void;
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
resolver: EventResolver<TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TData, TResultBroadcast> | EventResolverObject<TPlatform, TContext, TData, TResultBroadcast, TResultSelf, TResultSync>;
|
|
86
|
-
}
|
|
87
|
-
type SyncEventResolver<TContext extends Record<string, any> = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}> = (data: TData, context: EventResolverContext<TContext>) => MaybePromise<TResultBroadcast | void>;
|
|
88
|
-
type EventResolver<TContext extends Record<string, any> = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}> = (data: TData, context: EventResolverContext<TContext>) => MaybePromise<TResultBroadcast | void>;
|
|
89
|
-
interface EventResolverContext<TContext extends Record<string, any> = {}> {
|
|
83
|
+
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
84
|
+
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
90
85
|
context: TContext;
|
|
91
86
|
doc: AbstractCrdtDoc<any>;
|
|
92
87
|
room: string;
|
|
@@ -102,17 +97,9 @@ interface EventResolverContext<TContext extends Record<string, any> = {}> {
|
|
|
102
97
|
* @author leedavidcs
|
|
103
98
|
* @date December 25, 2022
|
|
104
99
|
*/
|
|
105
|
-
session: WebSocketSession | null;
|
|
106
|
-
sessions: Map<string, WebSocketSession
|
|
100
|
+
session: WebSocketSession<TAuthorize> | null;
|
|
101
|
+
sessions: Map<string, WebSocketSession<TAuthorize>>;
|
|
107
102
|
}
|
|
108
|
-
type EventResolverObject<TPlatform extends AbstractPlatform = AbstractPlatform, TContext extends Record<string, any> = {}, TData extends JsonObject = {}, TResultBroadcast extends EventRecord<string, any> = {}, TResultSelf extends EventRecord<string, any> = {}, TResultSync extends EventRecord<string, any> = {}> = {
|
|
109
|
-
broadcast?: EventResolver<TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TData, TResultBroadcast>;
|
|
110
|
-
self?: EventResolver<TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TData, TResultSelf>;
|
|
111
|
-
sync?: SyncEventResolver<TContext, TData, TResultSync>;
|
|
112
|
-
};
|
|
113
|
-
type InferEventConfig<TPlatform extends AbstractPlatform = AbstractPlatform, TContext extends Record<string, any> = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = {
|
|
114
|
-
[P in keyof TInput]: P extends string ? Id<EventConfig<TPlatform, TContext, TInput[P], TOutputBroadcast, TOutputSelf, TOutputSync>> : never;
|
|
115
|
-
};
|
|
116
103
|
type SendMessageOptions = {
|
|
117
104
|
type?: "broadcast";
|
|
118
105
|
sessionIds?: readonly string[];
|
|
@@ -124,15 +111,33 @@ type SendMessageOptions = {
|
|
|
124
111
|
interface WebSocketSessionTimers {
|
|
125
112
|
ping: number;
|
|
126
113
|
}
|
|
127
|
-
interface WebSocketSession {
|
|
114
|
+
interface WebSocketSession<TAuthorize extends IOAuthorize<any, any, any> = BaseIOAuthorize> {
|
|
128
115
|
id: string;
|
|
129
116
|
presence: JsonObject | null;
|
|
130
117
|
quit: boolean;
|
|
131
118
|
room: string;
|
|
132
119
|
timers: WebSocketSessionTimers;
|
|
133
120
|
webSocket: AbstractWebSocket;
|
|
134
|
-
user:
|
|
121
|
+
user: InferIOAuthorizeUser<TAuthorize>;
|
|
122
|
+
}
|
|
123
|
+
type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot extends EventRecord<string, any> = {}> = TEventRecords extends [
|
|
124
|
+
infer IHead extends EventRecord<string, any>,
|
|
125
|
+
...infer ITail extends EventRecord<string, any>[]
|
|
126
|
+
] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
|
|
127
|
+
[P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
|
|
128
|
+
}> : Id<TRoot>;
|
|
129
|
+
type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
130
|
+
room: string;
|
|
131
|
+
} & InferPlatformRoomContextType<TPlatform>;
|
|
132
|
+
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
133
|
+
interface PluvIOListeners<TPlatform extends AbstractPlatform> {
|
|
134
|
+
onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
135
|
+
onStorageUpdated: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
135
136
|
}
|
|
137
|
+
type IORoomListenerEvent<TPlatform extends AbstractPlatform> = {
|
|
138
|
+
room: string;
|
|
139
|
+
encodedState: string;
|
|
140
|
+
} & InferPlatformRoomContextType<TPlatform>;
|
|
136
141
|
|
|
137
142
|
type IOPubSubEventMessage<TIO extends IOLike, TEvent extends keyof InferIOOutput<TIO> = keyof InferIOOutput<TIO>> = IOEventMessage<TIO, TEvent> & {
|
|
138
143
|
options?: SendMessageOptions;
|
|
@@ -165,27 +170,65 @@ declare abstract class AbstractPlatform<TWebSocket = any, TIOContext extends Rec
|
|
|
165
170
|
abstract randomUUID(): string;
|
|
166
171
|
}
|
|
167
172
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
174
|
+
broadcast?: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
175
|
+
input?: InputZodLike<TInput>;
|
|
176
|
+
self?: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
177
|
+
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
178
|
+
}
|
|
179
|
+
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>, TContext extends JsonObject, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
180
|
+
private _broadcast;
|
|
181
|
+
private _input;
|
|
182
|
+
private _self;
|
|
183
|
+
private _sync;
|
|
184
|
+
get config(): {
|
|
185
|
+
broadcast: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
186
|
+
input: InputZodLike<TInput> | null;
|
|
187
|
+
resolver: () => EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TOutput>;
|
|
188
|
+
self: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, Partial<TOutput>> | null;
|
|
189
|
+
sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
190
|
+
};
|
|
191
|
+
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
192
|
+
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
193
|
+
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
194
|
+
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
195
|
+
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
196
|
+
private _resolver;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> = {
|
|
200
|
+
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
201
|
+
};
|
|
202
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TRoot extends TRouters[0]["_events"] = {}> = TRouters extends [
|
|
203
|
+
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
204
|
+
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
205
|
+
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
206
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
207
|
+
readonly _events: TEvents;
|
|
208
|
+
constructor(events: TEvents);
|
|
209
|
+
static merge<TRouters extends PluvRouter<any, any, any, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
210
|
+
}
|
|
211
|
+
|
|
172
212
|
interface IORoomListeners<TPlatform extends AbstractPlatform> {
|
|
173
213
|
onDestroy: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
174
214
|
}
|
|
175
|
-
type
|
|
215
|
+
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
216
|
+
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
217
|
+
};
|
|
218
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform>> & {
|
|
176
219
|
authorize?: TAuthorize;
|
|
177
220
|
context: TContext & InferPlatformRoomContextType<TPlatform>;
|
|
178
221
|
crdt?: {
|
|
179
222
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
180
223
|
};
|
|
181
224
|
debug: boolean;
|
|
182
|
-
events: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
183
225
|
platform: TPlatform;
|
|
226
|
+
router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
184
227
|
};
|
|
185
228
|
type WebsocketRegisterOptions<TPlatform extends AbstractPlatform> = {
|
|
186
229
|
token?: string | null;
|
|
187
230
|
} & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>;
|
|
188
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {},
|
|
231
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
189
232
|
private readonly _context;
|
|
190
233
|
private readonly _debug;
|
|
191
234
|
private readonly _docFactory;
|
|
@@ -195,10 +238,11 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
195
238
|
private _sessions;
|
|
196
239
|
private _uninitialize;
|
|
197
240
|
readonly _authorize: TAuthorize | null;
|
|
198
|
-
readonly
|
|
241
|
+
readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
199
242
|
readonly id: string;
|
|
200
|
-
|
|
201
|
-
broadcast
|
|
243
|
+
get _events(): TEvents;
|
|
244
|
+
get broadcast(): BroadcastProxy<this>;
|
|
245
|
+
constructor(id: string, config: IORoomConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
202
246
|
getSize(): number;
|
|
203
247
|
register(webSocket: InferPlatformWebSocketType<TPlatform>, options: WebsocketRegisterOptions<TPlatform>): Promise<void>;
|
|
204
248
|
private _broadcast;
|
|
@@ -206,9 +250,8 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
206
250
|
private _emitRegistered;
|
|
207
251
|
private _getIOAuthorize;
|
|
208
252
|
private _getAuthorizedUser;
|
|
209
|
-
private
|
|
210
|
-
private
|
|
211
|
-
private _getEventResolverObject;
|
|
253
|
+
private _getProcedure;
|
|
254
|
+
private _getProcedureInputs;
|
|
212
255
|
private _initialize;
|
|
213
256
|
private _logDebug;
|
|
214
257
|
private _onClose;
|
|
@@ -239,32 +282,21 @@ interface AuthorizeModule {
|
|
|
239
282
|
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
240
283
|
}
|
|
241
284
|
|
|
242
|
-
type
|
|
243
|
-
type
|
|
244
|
-
type InferIORoom<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<infer IPlatform, infer IAuthorize, infer IContext, infer IInput, infer IOutputBroadcast, infer IOutputSelf, infer IOutputSync> ? IORoom<IPlatform, IAuthorize, IContext, IInput, IOutputBroadcast, IOutputSelf, IOutputSync> : never;
|
|
245
|
-
type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
246
|
-
room: string;
|
|
247
|
-
} & InferPlatformRoomContextType<TPlatform>;
|
|
248
|
-
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
249
|
-
interface PluvIOListeners<TPlatform extends AbstractPlatform> {
|
|
250
|
-
onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
251
|
-
onStorageUpdated: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
252
|
-
}
|
|
253
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> | null = null, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> = Partial<PluvIOListeners<TPlatform>> & {
|
|
285
|
+
type InferIORoom<TServer extends PluvServer<any, any, any, any>> = TServer extends PluvServer<infer IPlatform, infer IAuthorize, infer IContext, infer IEvents> ? IORoom<IPlatform, IAuthorize, IContext, IEvents> : never;
|
|
286
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform>> & {
|
|
254
287
|
authorize?: TAuthorize;
|
|
255
288
|
context?: TContext;
|
|
256
289
|
crdt?: {
|
|
257
290
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
258
291
|
};
|
|
259
292
|
debug?: boolean;
|
|
260
|
-
events?: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
261
|
-
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
262
293
|
platform: TPlatform;
|
|
294
|
+
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
263
295
|
};
|
|
264
296
|
type GetRoomOptions<TPlatform extends AbstractPlatform> = {
|
|
265
297
|
debug?: boolean;
|
|
266
298
|
} & InferPlatformRoomContextType<TPlatform>;
|
|
267
|
-
declare class
|
|
299
|
+
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
268
300
|
private _rooms;
|
|
269
301
|
readonly _authorize: TAuthorize | null;
|
|
270
302
|
readonly _context: TContext;
|
|
@@ -272,20 +304,52 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
272
304
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
273
305
|
};
|
|
274
306
|
readonly _debug: boolean;
|
|
275
|
-
readonly _events: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
276
|
-
readonly _getInitialStorage: GetInitialStorageFn<TPlatform> | null;
|
|
277
307
|
readonly _listeners: PluvIOListeners<TPlatform>;
|
|
278
308
|
readonly _platform: TPlatform;
|
|
309
|
+
readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
279
310
|
readonly _version: string;
|
|
280
|
-
|
|
311
|
+
get _events(): TEvents;
|
|
312
|
+
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
281
313
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
282
|
-
|
|
283
|
-
getRoom(room: string, options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
284
|
-
static merge<TIO1 extends PluvIO, TIO2 extends PluvIO>(first: TIO1, second: TIO2): PluvIO<InferIOPlatform<TIO1>, InferIOAuthorize<TIO1>, InferIOContext<TIO1>, Spread<[InferIOInput<TIO1>, InferIOInput<TIO2>]>, Spread<[InferIOOutputBroadcast<TIO1>, InferIOOutputBroadcast<TIO2>]>, Spread<[InferIOOutputSelf<TIO1>, InferIOOutputSelf<TIO2>]>, Spread<[InferIOOutputSync<TIO1>, InferIOOutputSync<TIO2>]>>;
|
|
314
|
+
getRoom(room: string, options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
285
315
|
private _logDebug;
|
|
286
316
|
private _purgeEmptyRooms;
|
|
287
317
|
}
|
|
288
318
|
|
|
319
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>, TContext extends JsonObject> = Partial<PluvIOListeners<TPlatform>> & {
|
|
320
|
+
authorize?: TAuthorize;
|
|
321
|
+
context?: TContext;
|
|
322
|
+
crdt?: {
|
|
323
|
+
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
324
|
+
};
|
|
325
|
+
debug?: boolean;
|
|
326
|
+
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
327
|
+
platform: TPlatform;
|
|
328
|
+
};
|
|
329
|
+
interface ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> {
|
|
330
|
+
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
331
|
+
}
|
|
332
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends JsonObject = {}> implements IOLike<TAuthorize, {}> {
|
|
333
|
+
private _router;
|
|
334
|
+
readonly _authorize: TAuthorize | null;
|
|
335
|
+
readonly _context: TContext;
|
|
336
|
+
readonly _crdt: {
|
|
337
|
+
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
338
|
+
};
|
|
339
|
+
readonly _debug: boolean;
|
|
340
|
+
readonly _getInitialStorage: GetInitialStorageFn<TPlatform> | null;
|
|
341
|
+
readonly _listeners: PluvIOListeners<TPlatform>;
|
|
342
|
+
readonly _platform: TPlatform;
|
|
343
|
+
readonly _version: string;
|
|
344
|
+
get _events(): {};
|
|
345
|
+
get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
|
|
346
|
+
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>);
|
|
347
|
+
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
348
|
+
mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
349
|
+
router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
350
|
+
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
351
|
+
}
|
|
352
|
+
|
|
289
353
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = Partial<PluvIOListeners<TPlatform>> & {
|
|
290
354
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformRoomContextType<TPlatform>>;
|
|
291
355
|
context?: TContext;
|
|
@@ -296,6 +360,6 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
296
360
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
297
361
|
platform: TPlatform;
|
|
298
362
|
};
|
|
299
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any, {}, {}> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformRoomContextType<TPlatform>>, TContext
|
|
363
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any, {}, {}> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformRoomContextType<TPlatform>>, TContext>;
|
|
300
364
|
|
|
301
|
-
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistance, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CreateIOParams, type GetRoomOptions, type IOPubSubEventMessage, IORoom, type InferIORoom, type InferPlatformEventContextType, type InferPlatformRoomContextType, type InferPlatformWebSocketType, type JWT, type JWTEncodeParams, PluvIO, type PluvIOConfig, createIO };
|
|
365
|
+
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistance, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CreateIOParams, type GetRoomOptions, type IOPubSubEventMessage, IORoom, type InferIORoom, type InferPlatformEventContextType, type InferPlatformRoomContextType, type InferPlatformWebSocketType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, createIO };
|