@pluv/io 0.34.0 → 0.35.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 +56 -0
- package/dist/index.d.mts +46 -62
- package/dist/index.d.ts +46 -62
- package/dist/index.js +9 -4
- package/dist/index.mjs +9 -4
- package/package.json +5 -5
- package/src/AbstractWebSocket.ts +4 -3
- package/src/IORoom.ts +26 -16
- package/src/PluvIO.ts +11 -15
- package/src/PluvProcedure.ts +14 -13
- package/src/PluvRouter.ts +3 -3
- package/src/PluvServer.ts +14 -11
- package/src/authorize.ts +2 -2
- package/src/createIO.ts +7 -23
- package/src/types.ts +24 -37
- 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.35.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.35.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[32m45.
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in
|
|
17
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m43.
|
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m45.71 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 171ms
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m43.53 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 172ms
|
|
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 2615ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m29.57 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m29.57 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.35.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c9073ad: **BREAKING**
|
|
8
|
+
|
|
9
|
+
Removed the `required` property on the `authorize` config when creating a `PluvIO` instance. When `authorize` is provided, the session will be required to be authorized.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Before
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
const io = createIO({
|
|
16
|
+
// ...
|
|
17
|
+
authorize: {
|
|
18
|
+
// Previously required: true to force all users to authorize
|
|
19
|
+
required: true,
|
|
20
|
+
user: z.object({
|
|
21
|
+
id: z.string(),
|
|
22
|
+
name: z.string(),
|
|
23
|
+
}),
|
|
24
|
+
secret: "sk_...",
|
|
25
|
+
},
|
|
26
|
+
// ...
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// After
|
|
30
|
+
|
|
31
|
+
const io = createIO({
|
|
32
|
+
// ...
|
|
33
|
+
authorize: {
|
|
34
|
+
// No more `required` property. Now automatically applied always if
|
|
35
|
+
// `authorize` prop is provided to `createIO`
|
|
36
|
+
user: z.object({
|
|
37
|
+
id: z.string(),
|
|
38
|
+
name: z.string(),
|
|
39
|
+
}),
|
|
40
|
+
secret: "sk_...",
|
|
41
|
+
},
|
|
42
|
+
// ...
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- @pluv/crdt@0.35.0
|
|
49
|
+
- @pluv/types@0.35.0
|
|
50
|
+
|
|
51
|
+
## 0.34.1
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- d639427: Narrow type `EventResolverContext` so that `session` is only null on `sync` event types.
|
|
56
|
+
- @pluv/crdt@0.34.1
|
|
57
|
+
- @pluv/types@0.34.1
|
|
58
|
+
|
|
3
59
|
## 0.34.0
|
|
4
60
|
|
|
5
61
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, IORouterLike,
|
|
1
|
+
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, IORouterLike, InferIOAuthorizeUser, Id, Maybe, BaseUser, UndefinedProps, InferEventMessage, InferEventsOutput, IOLike, InferIOOutput, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { AbstractCrdtDocFactory, AbstractCrdtDoc } from '@pluv/crdt';
|
|
4
4
|
|
|
@@ -77,39 +77,39 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
|
|
|
77
77
|
abstract close(code?: number | undefined, reason?: string | undefined): void;
|
|
78
78
|
abstract send(message: ArrayBuffer | ArrayBufferView | string): void;
|
|
79
79
|
abstract terminate(): void;
|
|
80
|
-
getSession<TAuthorize extends IOAuthorize<any, any
|
|
80
|
+
getSession<TAuthorize extends IOAuthorize<any, any> | null>(): Promise<WebSocketSession<TAuthorize>>;
|
|
81
81
|
handleError(params: AbstractWebSocketHandleErrorParams): void;
|
|
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,
|
|
86
|
-
broadcast?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
85
|
+
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
86
|
+
broadcast?: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
87
87
|
input?: InputZodLike<TInput>;
|
|
88
|
-
self?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
89
|
-
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
88
|
+
self?: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
89
|
+
sync?: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
90
90
|
}
|
|
91
|
-
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any,
|
|
91
|
+
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, 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, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
98
|
+
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"broadcast", 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, 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">;
|
|
100
|
+
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"self", 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<"sync", 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 PluvIOAuthorize<TPlatform, any,
|
|
105
|
+
type PluvRouterEventConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}> = {
|
|
106
106
|
[P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
|
|
107
107
|
};
|
|
108
|
-
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
108
|
+
type MergedRouter<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [], TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TRoot extends TRouters[0]["_defs"]["events"] = {}> = TRouters extends [
|
|
109
109
|
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
110
110
|
...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]
|
|
111
111
|
] ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_defs"]["events"]> : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
|
|
112
|
-
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
112
|
+
declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IORouterLike<TEvents> {
|
|
113
113
|
readonly _defs: {
|
|
114
114
|
events: TEvents;
|
|
115
115
|
};
|
|
@@ -127,24 +127,13 @@ interface CrdtLibraryType {
|
|
|
127
127
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
128
128
|
kind: "loro" | "yjs";
|
|
129
129
|
}
|
|
130
|
-
type
|
|
131
|
-
|
|
130
|
+
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
131
|
+
type EventResolver<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TKind, TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
132
|
+
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}> {
|
|
132
133
|
context: TContext;
|
|
133
134
|
doc: AbstractCrdtDoc<any>;
|
|
134
135
|
room: string;
|
|
135
|
-
|
|
136
|
-
* !HACK
|
|
137
|
-
* @description Session should only not exist when invoking the event as a
|
|
138
|
-
* "sync" event on another machine where the session doesn't exist. There must
|
|
139
|
-
* be a better way to handle this, but going to make this nullable for ease
|
|
140
|
-
* for now.
|
|
141
|
-
*
|
|
142
|
-
* `session` should not be referenced most of the time anyhow (outside of
|
|
143
|
-
* internal to this library).
|
|
144
|
-
* @author leedavidcs
|
|
145
|
-
* @date December 25, 2022
|
|
146
|
-
*/
|
|
147
|
-
session: WebSocketSession<TAuthorize> | null;
|
|
136
|
+
session: TKind extends "sync" ? WebSocketSession<TAuthorize> | null : WebSocketSession<TAuthorize>;
|
|
148
137
|
sessions: readonly WebSocketSession<TAuthorize>[];
|
|
149
138
|
}
|
|
150
139
|
type SendMessageOptions = {
|
|
@@ -164,7 +153,7 @@ interface WebSocketSerializedState {
|
|
|
164
153
|
room: string;
|
|
165
154
|
timers: WebSocketSessionTimers;
|
|
166
155
|
}
|
|
167
|
-
type WebSocketSession<TAuthorize extends IOAuthorize<any, any
|
|
156
|
+
type WebSocketSession<TAuthorize extends IOAuthorize<any, any> | null = null> = WebSocketSerializedState & {
|
|
168
157
|
id: string;
|
|
169
158
|
user: InferIOAuthorizeUser<TAuthorize>;
|
|
170
159
|
webSocket: AbstractWebSocket;
|
|
@@ -184,7 +173,6 @@ type HandleMode = "io" | "fetch";
|
|
|
184
173
|
type WebSocketRegistrationMode = "attached" | "detached";
|
|
185
174
|
interface PlatformConfig {
|
|
186
175
|
authorize: {
|
|
187
|
-
required?: boolean;
|
|
188
176
|
secret?: boolean;
|
|
189
177
|
};
|
|
190
178
|
requireAuth?: boolean;
|
|
@@ -198,21 +186,20 @@ interface PlatformConfig {
|
|
|
198
186
|
onUserDisconnected?: boolean;
|
|
199
187
|
};
|
|
200
188
|
}
|
|
201
|
-
type ResolvedPluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any
|
|
189
|
+
type ResolvedPluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any> = {
|
|
202
190
|
user: InputZodLike<TUser>;
|
|
203
|
-
required?: TRequired;
|
|
204
191
|
} & UndefinedProps<{
|
|
205
192
|
secret?: string;
|
|
206
193
|
}, Exclude<"secret", InferPlatformAuthorizeProperties<TPlatform>>>;
|
|
207
|
-
type PluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any,
|
|
208
|
-
type BasePluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
194
|
+
type PluvIOAuthorize<TPlatform extends AbstractPlatform<any, any, any, any>, TUser extends BaseUser = any, TContext extends Record<string, unknown> = {}> = ResolvedPluvIOAuthorize<TPlatform, TUser> | ((context: TContext) => ResolvedPluvIOAuthorize<TPlatform, TUser>);
|
|
195
|
+
type BasePluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = {
|
|
209
196
|
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
210
197
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
211
198
|
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
212
199
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
213
200
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
214
201
|
};
|
|
215
|
-
type PluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
202
|
+
type PluvIOListeners<TPlatform extends AbstractPlatform<any, any, any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = UndefinedProps<BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, Exclude<keyof BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>, InferPlatformListeners<TPlatform>>>;
|
|
216
203
|
type InferPlatformConfig<TPlatform extends AbstractPlatform<any, any, any, any>> = TPlatform extends AbstractPlatform<any, any, any, infer IConfig> ? IConfig : never;
|
|
217
204
|
type InferPlatformAuthorizeProperties<TPlatform extends AbstractPlatform<any, any, any, any>> = keyof {
|
|
218
205
|
[P in keyof PlatformConfig["authorize"] as InferPlatformConfig<TPlatform>["authorize"][P] extends true | undefined ? P : never]: true;
|
|
@@ -225,20 +212,20 @@ type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
|
225
212
|
encodedState: string | null;
|
|
226
213
|
room: string;
|
|
227
214
|
};
|
|
228
|
-
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
215
|
+
type IORoomMessageEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = IORoomListenerEvent<TContext> & {
|
|
229
216
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
230
217
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
231
218
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
232
219
|
};
|
|
233
|
-
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any,
|
|
220
|
+
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
234
221
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
235
222
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
236
223
|
};
|
|
237
|
-
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any,
|
|
224
|
+
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
238
225
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
239
226
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
240
227
|
};
|
|
241
|
-
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any,
|
|
228
|
+
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
242
229
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
243
230
|
};
|
|
244
231
|
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
@@ -257,10 +244,10 @@ interface JWT<TUser extends BaseUser> {
|
|
|
257
244
|
sub: string;
|
|
258
245
|
user: TUser;
|
|
259
246
|
}
|
|
260
|
-
type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
|
|
247
|
+
type JWTEncodeParams<TUser extends BaseUser | null, TPlatform extends AbstractPlatform> = {
|
|
261
248
|
maxAge?: number;
|
|
262
249
|
room: string;
|
|
263
|
-
user: TUser;
|
|
250
|
+
user: TUser extends BaseUser ? TUser : "Error: Cannot create token without authorization!";
|
|
264
251
|
} & InferInitContextType<TPlatform>;
|
|
265
252
|
interface AuthorizeParams {
|
|
266
253
|
platform: AbstractPlatform;
|
|
@@ -312,7 +299,7 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket = A
|
|
|
312
299
|
protected _initialize(): this;
|
|
313
300
|
}
|
|
314
301
|
|
|
315
|
-
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
302
|
+
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
316
303
|
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
317
304
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
318
305
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -321,7 +308,7 @@ interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize ex
|
|
|
321
308
|
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
322
309
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
323
310
|
};
|
|
324
|
-
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
311
|
+
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
325
312
|
authorize?: TAuthorize;
|
|
326
313
|
context: TContext;
|
|
327
314
|
crdt?: {
|
|
@@ -335,7 +322,7 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
335
322
|
type WebsocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
336
323
|
token?: string | null;
|
|
337
324
|
} & InferInitContextType<TPlatform>;
|
|
338
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
325
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
339
326
|
readonly id: string;
|
|
340
327
|
private _doc;
|
|
341
328
|
private _uninitialize;
|
|
@@ -353,7 +340,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
353
340
|
* @deprecated Internal use only. Changes to this will never be marked as breaking.
|
|
354
341
|
*/
|
|
355
342
|
get _defs(): {
|
|
356
|
-
authorize: TAuthorize
|
|
343
|
+
authorize: TAuthorize;
|
|
357
344
|
context: TContext;
|
|
358
345
|
events: TEvents;
|
|
359
346
|
platform: TPlatform;
|
|
@@ -403,7 +390,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
403
390
|
}
|
|
404
391
|
|
|
405
392
|
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;
|
|
406
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
393
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
407
394
|
authorize?: TAuthorize;
|
|
408
395
|
context?: PluvContext<TPlatform, TContext>;
|
|
409
396
|
crdt?: {
|
|
@@ -414,11 +401,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
414
401
|
platform: TPlatform;
|
|
415
402
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
416
403
|
};
|
|
417
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
404
|
+
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
418
405
|
debug?: boolean;
|
|
419
406
|
};
|
|
420
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
421
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
407
|
+
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, 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>>];
|
|
408
|
+
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
422
409
|
readonly version: string;
|
|
423
410
|
private readonly _authorize;
|
|
424
411
|
private readonly _baseRouter;
|
|
@@ -435,8 +422,8 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
435
422
|
* @deprecated Internal use only. Changes to this will never be marked as breaking.
|
|
436
423
|
*/
|
|
437
424
|
get _defs(): {
|
|
438
|
-
authorize: TAuthorize
|
|
439
|
-
context:
|
|
425
|
+
authorize: TAuthorize;
|
|
426
|
+
context: TContext;
|
|
440
427
|
events: TEvents;
|
|
441
428
|
platform: TPlatform;
|
|
442
429
|
};
|
|
@@ -449,21 +436,18 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
449
436
|
private _logDebug;
|
|
450
437
|
}
|
|
451
438
|
|
|
452
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any,
|
|
439
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = {
|
|
440
|
+
authorize?: TAuthorize;
|
|
453
441
|
context?: PluvContext<TPlatform, TContext>;
|
|
454
442
|
crdt?: CrdtLibraryType;
|
|
455
443
|
debug?: boolean;
|
|
456
444
|
platform: TPlatform;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
} : {
|
|
460
|
-
authorize?: TAuthorize;
|
|
461
|
-
});
|
|
462
|
-
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, any, InferInitContextType<TPlatform>> = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
445
|
+
};
|
|
446
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
463
447
|
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
464
448
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
465
449
|
};
|
|
466
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any,
|
|
450
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}> {
|
|
467
451
|
readonly version: string;
|
|
468
452
|
private readonly _authorize;
|
|
469
453
|
private readonly _context;
|
|
@@ -479,13 +463,13 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
479
463
|
private _getIOAuthorize;
|
|
480
464
|
}
|
|
481
465
|
|
|
482
|
-
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {},
|
|
483
|
-
authorize?:
|
|
466
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null> = {
|
|
467
|
+
authorize?: TAuthorize;
|
|
484
468
|
context?: PluvContext<TPlatform, TContext>;
|
|
485
469
|
crdt?: CrdtLibraryType;
|
|
486
470
|
debug?: boolean;
|
|
487
471
|
platform: TPlatform;
|
|
488
472
|
};
|
|
489
|
-
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}, PlatformConfig>, TContext extends Record<string, any> = {},
|
|
473
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}, PlatformConfig>, TContext extends Record<string, any> = {}, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null>(params: CreateIOParams<TPlatform, TContext, TAuthorize>) => PluvIO<TPlatform, TAuthorize, TContext>;
|
|
490
474
|
|
|
491
475
|
export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type HandleMode, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, type PlatformConfig, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
|