@pluv/io 0.30.2 → 0.32.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 +132 -0
- package/dist/index.d.mts +53 -49
- package/dist/index.d.ts +53 -49
- package/dist/index.js +24 -21
- package/dist/index.mjs +24 -21
- package/package.json +5 -5
- package/src/AbstractPlatform.ts +9 -15
- package/src/IORoom.ts +36 -29
- package/src/PluvIO.ts +11 -11
- package/src/PluvProcedure.ts +13 -43
- package/src/PluvRouter.ts +8 -8
- package/src/PluvServer.ts +16 -17
- package/src/authorize.ts +2 -2
- package/src/createIO.ts +9 -13
- package/src/index.ts +1 -1
- package/src/types.ts +15 -10
- 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.32.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.32.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.90 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 156ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m42.08 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 159ms
|
|
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 2329ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m25.82 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m25.82 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,137 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.32.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cde5305: **BREAKING**
|
|
8
|
+
|
|
9
|
+
Update `createIO`'s `context` property to allow lazy initialization as a function. The `context` also no-longer contains platform-specific values by default. See example below:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createIO } from "@pluv/io";
|
|
13
|
+
import { platformCloudflare } from "@pluv/platform-cloudflare";
|
|
14
|
+
import { Database } from "./database";
|
|
15
|
+
|
|
16
|
+
// Before
|
|
17
|
+
const io = createIO({
|
|
18
|
+
platform: platformCloudflare(),
|
|
19
|
+
context: {
|
|
20
|
+
// Maybe you need to access `env` for Cloudflare, but it's not accessible
|
|
21
|
+
// here
|
|
22
|
+
db: new Database(env.DATABASE_URL),
|
|
23
|
+
// ^ Does not exist
|
|
24
|
+
|
|
25
|
+
// Even though it's not specified in this `context`, Cloudflare's
|
|
26
|
+
// env and state values were previously available where context
|
|
27
|
+
// was referenced
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// After
|
|
32
|
+
const io = createIO({
|
|
33
|
+
platform: platformCloudfare(),
|
|
34
|
+
context: ({ env, state }) => ({
|
|
35
|
+
db: new Database(env.DATABASE_URL),
|
|
36
|
+
// ^ Now accessible
|
|
37
|
+
|
|
38
|
+
// Now these must be forwarded to use them
|
|
39
|
+
env,
|
|
40
|
+
state,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- @pluv/crdt@0.32.0
|
|
48
|
+
- @pluv/types@0.32.0
|
|
49
|
+
|
|
50
|
+
## 0.31.0
|
|
51
|
+
|
|
52
|
+
### Minor Changes
|
|
53
|
+
|
|
54
|
+
- b3c31d7: **BREAKING**
|
|
55
|
+
|
|
56
|
+
Fixed platform context types. This will require additional properties when registering a websocket and creating authorization tokens. See example below:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// @pluv/platform-node example
|
|
60
|
+
|
|
61
|
+
import { platformNode } from "@pluv/platform-node";
|
|
62
|
+
import { createIO } from "@pluv/io";
|
|
63
|
+
import type { IncomingMessage } from "node:http";
|
|
64
|
+
import { z } from "zod";
|
|
65
|
+
|
|
66
|
+
const io = createIO({
|
|
67
|
+
// If using a function authorize parameter, `req` is now available as a param
|
|
68
|
+
authorize: ({ req }) => ({
|
|
69
|
+
required: true,
|
|
70
|
+
secret: "MY-CUSTOM-SECRET",
|
|
71
|
+
user: z.object({
|
|
72
|
+
id: z.string(),
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
platformNode(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Before
|
|
79
|
+
io.createToken({
|
|
80
|
+
room: "my-custom-room",
|
|
81
|
+
user: { id: "abc123" },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// After
|
|
85
|
+
io.createToken({
|
|
86
|
+
room: "my-custom-room",
|
|
87
|
+
user: { id: "abc123" },
|
|
88
|
+
|
|
89
|
+
// Previously not required, but now required
|
|
90
|
+
req: req as IncomingMessage,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
// @pluv/platform-cloudflare example
|
|
96
|
+
|
|
97
|
+
import { platformCloudflare } from "@pluv/platform-cloudflare";
|
|
98
|
+
import { createIO } from "@pluv/io";
|
|
99
|
+
import { z } from "zod";
|
|
100
|
+
|
|
101
|
+
const io = createIO({
|
|
102
|
+
// If using a function authorize parameter, `env` and `request` are now available as params
|
|
103
|
+
authorize: ({ env, request }) => ({
|
|
104
|
+
required: true,
|
|
105
|
+
secret: "MY-CUSTOM-SECRET",
|
|
106
|
+
user: z.object({
|
|
107
|
+
id: z.string(),
|
|
108
|
+
}),
|
|
109
|
+
}),
|
|
110
|
+
platformCloudflare(),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Before
|
|
114
|
+
io.createToken({
|
|
115
|
+
room: "my-custom-room",
|
|
116
|
+
user: { id: "abc123" },
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// After
|
|
120
|
+
io.createToken({
|
|
121
|
+
room: "my-custom-room",
|
|
122
|
+
user: { id: "abc123" },
|
|
123
|
+
|
|
124
|
+
// Previously not required, but now required
|
|
125
|
+
env: env as Env,
|
|
126
|
+
request: request as Request,
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- @pluv/crdt@0.31.0
|
|
133
|
+
- @pluv/types@0.31.0
|
|
134
|
+
|
|
3
135
|
## 0.30.2
|
|
4
136
|
|
|
5
137
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -82,34 +82,34 @@ 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,
|
|
86
|
-
broadcast?: EventResolver<TPlatform, TAuthorize, TContext
|
|
85
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
86
|
+
broadcast?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
87
87
|
input?: InputZodLike<TInput>;
|
|
88
|
-
self?: EventResolver<TPlatform, TAuthorize, TContext
|
|
88
|
+
self?: EventResolver<TPlatform, TAuthorize, TContext, 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 Record<string, any>, 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;
|
|
95
95
|
private _sync;
|
|
96
96
|
get config(): ProcedureLike<TInput, TOutput>["config"];
|
|
97
97
|
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
98
|
-
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext
|
|
98
|
+
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
99
99
|
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
100
|
-
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext
|
|
101
|
-
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext
|
|
100
|
+
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
101
|
+
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
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 Record<string, any> = {}> = {
|
|
106
106
|
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
107
107
|
};
|
|
108
|
-
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends 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 Record<string, any> = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [
|
|
109
109
|
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
110
110
|
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
111
111
|
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_defs"]["events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
112
|
-
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
112
|
+
declare class PluvRouter<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 IORouterLike<TEvents> {
|
|
113
113
|
readonly _defs: {
|
|
114
114
|
events: TEvents;
|
|
115
115
|
};
|
|
@@ -122,12 +122,13 @@ declare global {
|
|
|
122
122
|
log: (...data: any[]) => void;
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> = TContext | ((params: InferRoomContextType<TPlatform>) => TContext);
|
|
125
126
|
interface CrdtLibraryType {
|
|
126
127
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
127
128
|
kind: "loro" | "yjs";
|
|
128
129
|
}
|
|
129
|
-
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
130
|
-
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any,
|
|
130
|
+
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>;
|
|
131
|
+
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
131
132
|
context: TContext;
|
|
132
133
|
doc: AbstractCrdtDoc<any>;
|
|
133
134
|
room: string;
|
|
@@ -176,19 +177,19 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
|
|
|
176
177
|
}> : Id<TRoot>;
|
|
177
178
|
type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
178
179
|
room: string;
|
|
179
|
-
}
|
|
180
|
+
};
|
|
180
181
|
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
181
|
-
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
182
|
+
interface PluvIOListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
182
183
|
onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
183
184
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
184
185
|
onStorageUpdated: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
185
186
|
}
|
|
186
|
-
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
187
|
-
context: TContext
|
|
187
|
+
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
188
|
+
context: TContext;
|
|
188
189
|
encodedState: string | null;
|
|
189
190
|
room: string;
|
|
190
191
|
};
|
|
191
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
192
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
|
|
192
193
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
193
194
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
194
195
|
};
|
|
@@ -206,31 +207,31 @@ declare abstract class AbstractPubSub {
|
|
|
206
207
|
type WebSocketRegistrationMode = "attached" | "detached";
|
|
207
208
|
type InferPlatformWebSocketType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<infer IAbstractWebSocket> ? IAbstractWebSocket : never;
|
|
208
209
|
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?:
|
|
210
|
+
type InferInitContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, infer IInitContext> ? IInitContext : never;
|
|
211
|
+
type InferRoomContextType<TPlatform extends AbstractPlatform> = TPlatform extends AbstractPlatform<any, any, infer IRoomContext> ? IRoomContext : never;
|
|
212
|
+
type AbstractPlatformConfig<TRoomContext extends Record<string, any> = {}> = {
|
|
213
|
+
context?: TRoomContext;
|
|
213
214
|
persistence?: AbstractPersistence;
|
|
214
215
|
pubSub?: AbstractPubSub;
|
|
215
216
|
};
|
|
216
217
|
interface ConvertWebSocketConfig {
|
|
217
218
|
room: string;
|
|
218
219
|
}
|
|
219
|
-
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket,
|
|
220
|
-
protected readonly
|
|
220
|
+
declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = AbstractWebSocket, TInitContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
|
|
221
|
+
protected readonly _initContext: TInitContext | undefined;
|
|
221
222
|
protected readonly _roomContext: TRoomContext | undefined;
|
|
222
223
|
private _initialized;
|
|
223
224
|
persistence: AbstractPersistence;
|
|
224
225
|
pubSub: AbstractPubSub;
|
|
225
226
|
abstract readonly _registrationMode: WebSocketRegistrationMode;
|
|
226
|
-
constructor(config?: AbstractPlatformConfig<
|
|
227
|
+
constructor(config?: AbstractPlatformConfig<TRoomContext>);
|
|
227
228
|
abstract acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
|
|
228
229
|
abstract convertWebSocket(webSocket: InferWebSocketSource<TWebSocket>, config: ConvertWebSocketConfig): AbstractWebSocket;
|
|
229
230
|
abstract getLastPing(webSocket: AbstractWebSocket): number | null;
|
|
230
231
|
abstract getSerializedState(webSocket: InferWebSocketSource<TWebSocket>): WebSocketSerializedState | null;
|
|
231
232
|
abstract getSessionId(webSocket: InferWebSocketSource<TWebSocket>): string | null;
|
|
232
233
|
abstract getWebSockets(): readonly InferWebSocketSource<TWebSocket>[];
|
|
233
|
-
abstract initialize(config: AbstractPlatformConfig<
|
|
234
|
+
abstract initialize(config: AbstractPlatformConfig<TRoomContext>): this;
|
|
234
235
|
abstract parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
235
236
|
abstract randomUUID(): string;
|
|
236
237
|
abstract setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): void;
|
|
@@ -246,7 +247,7 @@ type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform>
|
|
|
246
247
|
maxAge?: number;
|
|
247
248
|
room: string;
|
|
248
249
|
user: TUser;
|
|
249
|
-
} &
|
|
250
|
+
} & InferInitContextType<TPlatform>;
|
|
250
251
|
interface AuthorizeParams {
|
|
251
252
|
platform: AbstractPlatform;
|
|
252
253
|
secret: string;
|
|
@@ -260,27 +261,28 @@ declare const authorize: (params: AuthorizeParams) => {
|
|
|
260
261
|
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
261
262
|
};
|
|
262
263
|
|
|
263
|
-
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
264
|
+
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
264
265
|
onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
265
266
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
266
267
|
}
|
|
267
268
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
268
269
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
269
270
|
};
|
|
270
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
271
|
+
type IORoomConfig<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> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
271
272
|
authorize?: TAuthorize;
|
|
272
|
-
context: TContext
|
|
273
|
+
context: TContext;
|
|
273
274
|
crdt?: {
|
|
274
275
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
275
276
|
};
|
|
276
277
|
debug: boolean;
|
|
277
278
|
platform: TPlatform;
|
|
279
|
+
roomContext: InferRoomContextType<TPlatform>;
|
|
278
280
|
router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
279
281
|
};
|
|
280
|
-
|
|
282
|
+
type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
281
283
|
token?: string | null;
|
|
282
|
-
}
|
|
283
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
284
|
+
} & InferInitContextType<TPlatform>;
|
|
285
|
+
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
286
|
readonly id: string;
|
|
285
287
|
private _doc;
|
|
286
288
|
private _uninitialize;
|
|
@@ -299,7 +301,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
299
301
|
*/
|
|
300
302
|
get _defs(): {
|
|
301
303
|
authorize: TAuthorize | null;
|
|
302
|
-
context: TContext
|
|
304
|
+
context: TContext;
|
|
303
305
|
events: TEvents;
|
|
304
306
|
platform: TPlatform;
|
|
305
307
|
};
|
|
@@ -310,7 +312,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
310
312
|
onClose(webSocket: WebSocketType<TPlatform>): (event: AbstractCloseEvent) => Promise<void>;
|
|
311
313
|
onError(webSocket: WebSocketType<TPlatform>): (event: AbstractErrorEvent) => Promise<void>;
|
|
312
314
|
onMessage(webSocket: WebSocketType<TPlatform>): (event: AbstractMessageEvent) => Promise<void>;
|
|
313
|
-
register(webSocket: InferPlatformWebSocketSource<TPlatform>, options
|
|
315
|
+
register(webSocket: InferPlatformWebSocketSource<TPlatform>, ...options: keyof InferInitContextType<TPlatform> extends never ? [{
|
|
316
|
+
token?: string;
|
|
317
|
+
}?] : [WebsocketRegisterConfig<TPlatform>]): Promise<void>;
|
|
314
318
|
private _broadcast;
|
|
315
319
|
private _emitQuitters;
|
|
316
320
|
private _emitRegistered;
|
|
@@ -335,9 +339,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
335
339
|
}
|
|
336
340
|
|
|
337
341
|
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,
|
|
342
|
+
type PluvServerConfig<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> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
339
343
|
authorize?: TAuthorize;
|
|
340
|
-
context?: TContext
|
|
344
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
341
345
|
crdt?: {
|
|
342
346
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
343
347
|
};
|
|
@@ -346,11 +350,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
346
350
|
platform: TPlatform;
|
|
347
351
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
348
352
|
};
|
|
349
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
353
|
+
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
350
354
|
debug?: boolean;
|
|
351
355
|
};
|
|
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,
|
|
356
|
+
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>];
|
|
357
|
+
declare class PluvServer<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 IORouterLike<TEvents> {
|
|
354
358
|
readonly version: string;
|
|
355
359
|
private readonly _authorize;
|
|
356
360
|
private readonly _baseRouter;
|
|
@@ -367,7 +371,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
367
371
|
*/
|
|
368
372
|
get _defs(): {
|
|
369
373
|
authorize: TAuthorize | null;
|
|
370
|
-
context: TContext
|
|
374
|
+
context: PluvContext<TPlatform, TContext>;
|
|
371
375
|
events: TEvents;
|
|
372
376
|
platform: TPlatform;
|
|
373
377
|
};
|
|
@@ -379,18 +383,18 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
379
383
|
private _logDebug;
|
|
380
384
|
}
|
|
381
385
|
|
|
382
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
386
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = {
|
|
383
387
|
authorize?: TAuthorize;
|
|
384
|
-
context?: TContext
|
|
388
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
385
389
|
crdt?: CrdtLibraryType;
|
|
386
390
|
debug?: boolean;
|
|
387
391
|
platform: TPlatform;
|
|
388
392
|
};
|
|
389
|
-
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
393
|
+
type ServerConfig<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> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
390
394
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
391
395
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
392
396
|
};
|
|
393
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any,
|
|
397
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
394
398
|
readonly version: string;
|
|
395
399
|
private readonly _authorize;
|
|
396
400
|
private readonly _context;
|
|
@@ -405,13 +409,13 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
405
409
|
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
406
410
|
}
|
|
407
411
|
|
|
408
|
-
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends
|
|
409
|
-
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired,
|
|
410
|
-
context?: TContext
|
|
412
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
413
|
+
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
414
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
411
415
|
crdt?: CrdtLibraryType;
|
|
412
416
|
debug?: boolean;
|
|
413
417
|
platform: TPlatform;
|
|
414
418
|
};
|
|
415
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends
|
|
419
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>, TContext>;
|
|
416
420
|
|
|
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
|
|
421
|
+
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 };
|