@pluv/io 0.31.0 → 0.32.1
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 +54 -0
- package/dist/index.d.mts +34 -32
- package/dist/index.d.ts +34 -32
- package/dist/index.js +11 -9
- package/dist/index.mjs +11 -9
- package/package.json +5 -5
- package/src/IORoom.ts +11 -15
- package/src/PluvIO.ts +7 -7
- package/src/PluvProcedure.ts +11 -41
- package/src/PluvRouter.ts +4 -4
- package/src/PluvServer.ts +11 -12
- package/src/createIO.ts +5 -5
- package/src/types.ts +9 -5
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.
|
|
2
|
+
> @pluv/io@0.32.1 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.1 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 145ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m42.08 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 160ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m25.
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m25.
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 2517ms
|
|
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,59 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.32.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/crdt@0.32.1
|
|
8
|
+
- @pluv/types@0.32.1
|
|
9
|
+
|
|
10
|
+
## 0.32.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- cde5305: **BREAKING**
|
|
15
|
+
|
|
16
|
+
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:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { createIO } from "@pluv/io";
|
|
20
|
+
import { platformCloudflare } from "@pluv/platform-cloudflare";
|
|
21
|
+
import { Database } from "./database";
|
|
22
|
+
|
|
23
|
+
// Before
|
|
24
|
+
const io = createIO({
|
|
25
|
+
platform: platformCloudflare(),
|
|
26
|
+
context: {
|
|
27
|
+
// Maybe you need to access `env` for Cloudflare, but it's not accessible
|
|
28
|
+
// here
|
|
29
|
+
db: new Database(env.DATABASE_URL),
|
|
30
|
+
// ^ Does not exist
|
|
31
|
+
|
|
32
|
+
// Even though it's not specified in this `context`, Cloudflare's
|
|
33
|
+
// env and state values were previously available where context
|
|
34
|
+
// was referenced
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// After
|
|
39
|
+
const io = createIO({
|
|
40
|
+
platform: platformCloudfare(),
|
|
41
|
+
context: ({ env, state }) => ({
|
|
42
|
+
db: new Database(env.DATABASE_URL),
|
|
43
|
+
// ^ Now accessible
|
|
44
|
+
|
|
45
|
+
// Now these must be forwarded to use them
|
|
46
|
+
env,
|
|
47
|
+
state,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- @pluv/crdt@0.32.0
|
|
55
|
+
- @pluv/types@0.32.0
|
|
56
|
+
|
|
3
57
|
## 0.31.0
|
|
4
58
|
|
|
5
59
|
### Minor 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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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,6 +122,7 @@ 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";
|
|
@@ -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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>>, TContext extends
|
|
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
|
};
|
|
@@ -260,21 +261,22 @@ 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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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>> = {
|
|
@@ -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
|
};
|
|
@@ -337,9 +339,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
337
339
|
}
|
|
338
340
|
|
|
339
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;
|
|
340
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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>> & {
|
|
341
343
|
authorize?: TAuthorize;
|
|
342
|
-
context?: TContext
|
|
344
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
343
345
|
crdt?: {
|
|
344
346
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
345
347
|
};
|
|
@@ -348,11 +350,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
348
350
|
platform: TPlatform;
|
|
349
351
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
350
352
|
};
|
|
351
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends
|
|
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>> & {
|
|
352
354
|
debug?: boolean;
|
|
353
355
|
};
|
|
354
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends
|
|
355
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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> {
|
|
356
358
|
readonly version: string;
|
|
357
359
|
private readonly _authorize;
|
|
358
360
|
private readonly _baseRouter;
|
|
@@ -369,7 +371,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
369
371
|
*/
|
|
370
372
|
get _defs(): {
|
|
371
373
|
authorize: TAuthorize | null;
|
|
372
|
-
context: TContext
|
|
374
|
+
context: PluvContext<TPlatform, TContext>;
|
|
373
375
|
events: TEvents;
|
|
374
376
|
platform: TPlatform;
|
|
375
377
|
};
|
|
@@ -381,18 +383,18 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
381
383
|
private _logDebug;
|
|
382
384
|
}
|
|
383
385
|
|
|
384
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends
|
|
386
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = {
|
|
385
387
|
authorize?: TAuthorize;
|
|
386
|
-
context?: TContext
|
|
388
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
387
389
|
crdt?: CrdtLibraryType;
|
|
388
390
|
debug?: boolean;
|
|
389
391
|
platform: TPlatform;
|
|
390
392
|
};
|
|
391
|
-
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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>> & {
|
|
392
394
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
393
395
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
394
396
|
};
|
|
395
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
397
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
396
398
|
readonly version: string;
|
|
397
399
|
private readonly _authorize;
|
|
398
400
|
private readonly _context;
|
|
@@ -407,13 +409,13 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
407
409
|
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
408
410
|
}
|
|
409
411
|
|
|
410
|
-
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends
|
|
412
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
411
413
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
412
|
-
context?: TContext
|
|
414
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
413
415
|
crdt?: CrdtLibraryType;
|
|
414
416
|
debug?: boolean;
|
|
415
417
|
platform: TPlatform;
|
|
416
418
|
};
|
|
417
|
-
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>;
|
|
418
420
|
|
|
419
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 };
|
package/dist/index.d.ts
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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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,6 +122,7 @@ 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";
|
|
@@ -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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>>, TContext extends
|
|
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
|
};
|
|
@@ -260,21 +261,22 @@ 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, InferInitContextType<TPlatform>>, TContext extends
|
|
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, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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>> = {
|
|
@@ -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
|
};
|
|
@@ -337,9 +339,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
337
339
|
}
|
|
338
340
|
|
|
339
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;
|
|
340
|
-
type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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>> & {
|
|
341
343
|
authorize?: TAuthorize;
|
|
342
|
-
context?: TContext
|
|
344
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
343
345
|
crdt?: {
|
|
344
346
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
345
347
|
};
|
|
@@ -348,11 +350,11 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform
|
|
|
348
350
|
platform: TPlatform;
|
|
349
351
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
350
352
|
};
|
|
351
|
-
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends
|
|
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>> & {
|
|
352
354
|
debug?: boolean;
|
|
353
355
|
};
|
|
354
|
-
type CreateRoomOptions<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends
|
|
355
|
-
declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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> {
|
|
356
358
|
readonly version: string;
|
|
357
359
|
private readonly _authorize;
|
|
358
360
|
private readonly _baseRouter;
|
|
@@ -369,7 +371,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
369
371
|
*/
|
|
370
372
|
get _defs(): {
|
|
371
373
|
authorize: TAuthorize | null;
|
|
372
|
-
context: TContext
|
|
374
|
+
context: PluvContext<TPlatform, TContext>;
|
|
373
375
|
events: TEvents;
|
|
374
376
|
platform: TPlatform;
|
|
375
377
|
};
|
|
@@ -381,18 +383,18 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
381
383
|
private _logDebug;
|
|
382
384
|
}
|
|
383
385
|
|
|
384
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends
|
|
386
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>> = {
|
|
385
387
|
authorize?: TAuthorize;
|
|
386
|
-
context?: TContext
|
|
388
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
387
389
|
crdt?: CrdtLibraryType;
|
|
388
390
|
debug?: boolean;
|
|
389
391
|
platform: TPlatform;
|
|
390
392
|
};
|
|
391
|
-
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
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>> & {
|
|
392
394
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
393
395
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
394
396
|
};
|
|
395
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends
|
|
397
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
396
398
|
readonly version: string;
|
|
397
399
|
private readonly _authorize;
|
|
398
400
|
private readonly _context;
|
|
@@ -407,13 +409,13 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
407
409
|
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
408
410
|
}
|
|
409
411
|
|
|
410
|
-
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends
|
|
412
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
411
413
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
412
|
-
context?: TContext
|
|
414
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
413
415
|
crdt?: CrdtLibraryType;
|
|
414
416
|
debug?: boolean;
|
|
415
417
|
platform: TPlatform;
|
|
416
418
|
};
|
|
417
|
-
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>;
|
|
418
420
|
|
|
419
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 };
|
package/dist/index.js
CHANGED
|
@@ -407,6 +407,7 @@ var IORoom = class {
|
|
|
407
407
|
onDestroy,
|
|
408
408
|
onMessage,
|
|
409
409
|
platform,
|
|
410
|
+
roomContext,
|
|
410
411
|
router
|
|
411
412
|
} = config;
|
|
412
413
|
this.id = id;
|
|
@@ -414,7 +415,7 @@ var IORoom = class {
|
|
|
414
415
|
this._debug = debug;
|
|
415
416
|
this._docFactory = crdt.doc(() => ({}));
|
|
416
417
|
this._router = router;
|
|
417
|
-
this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context }));
|
|
418
|
+
this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context: roomContext }));
|
|
418
419
|
this._listeners = {
|
|
419
420
|
onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event),
|
|
420
421
|
onMessage: (event) => onMessage == null ? void 0 : onMessage(event)
|
|
@@ -754,7 +755,7 @@ var IORoom = class {
|
|
|
754
755
|
this._getSessions()
|
|
755
756
|
]);
|
|
756
757
|
const doc = yield this._doc;
|
|
757
|
-
const
|
|
758
|
+
const eventContext = {
|
|
758
759
|
context: this._context,
|
|
759
760
|
doc,
|
|
760
761
|
room: this.id,
|
|
@@ -796,11 +797,10 @@ var IORoom = class {
|
|
|
796
797
|
});
|
|
797
798
|
return;
|
|
798
799
|
}
|
|
799
|
-
const extendedContext = __spreadProps(__spreadValues({}, baseContext), { context: __spreadValues({}, this._context) });
|
|
800
800
|
yield Promise.all([
|
|
801
|
-
(_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs,
|
|
802
|
-
(_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs,
|
|
803
|
-
(_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs,
|
|
801
|
+
(_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs, eventContext),
|
|
802
|
+
(_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs, eventContext),
|
|
803
|
+
(_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs, eventContext)
|
|
804
804
|
]).then((_0) => __async(this, [_0], function* ([broadcast, self, sync]) {
|
|
805
805
|
const handleBroadcast = () => __async(this, null, function* () {
|
|
806
806
|
if (!broadcast) return;
|
|
@@ -932,7 +932,7 @@ var IORoom = class {
|
|
|
932
932
|
};
|
|
933
933
|
|
|
934
934
|
// src/version.generated.ts
|
|
935
|
-
var version = "0.
|
|
935
|
+
var version = "0.32.1";
|
|
936
936
|
|
|
937
937
|
// src/PluvServer.ts
|
|
938
938
|
var PluvServer = class {
|
|
@@ -1069,10 +1069,11 @@ var PluvServer = class {
|
|
|
1069
1069
|
var _a, _c;
|
|
1070
1070
|
const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
|
|
1071
1071
|
if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
|
|
1072
|
-
const roomContext =
|
|
1072
|
+
const roomContext = platformRoomContext;
|
|
1073
|
+
const context = typeof this._context === "function" ? this._context(roomContext) : this._context;
|
|
1073
1074
|
const newRoom = new IORoom(room, __spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), {
|
|
1074
1075
|
authorize: (_c = this._authorize) != null ? _c : void 0,
|
|
1075
|
-
context
|
|
1076
|
+
context,
|
|
1076
1077
|
crdt: this._crdt,
|
|
1077
1078
|
debug: debug != null ? debug : this._debug,
|
|
1078
1079
|
onDestroy: (event) => __async(this, null, function* () {
|
|
@@ -1087,6 +1088,7 @@ var PluvServer = class {
|
|
|
1087
1088
|
yield Promise.resolve(this._getListeners().onRoomMessage(event));
|
|
1088
1089
|
}),
|
|
1089
1090
|
platform: this._platform,
|
|
1091
|
+
roomContext,
|
|
1090
1092
|
router: this._router
|
|
1091
1093
|
}));
|
|
1092
1094
|
this._logDebug(`${import_kleur2.default.blue("Created room:")} ${room}`);
|
package/dist/index.mjs
CHANGED
|
@@ -365,6 +365,7 @@ var IORoom = class {
|
|
|
365
365
|
onDestroy,
|
|
366
366
|
onMessage,
|
|
367
367
|
platform,
|
|
368
|
+
roomContext,
|
|
368
369
|
router
|
|
369
370
|
} = config;
|
|
370
371
|
this.id = id;
|
|
@@ -372,7 +373,7 @@ var IORoom = class {
|
|
|
372
373
|
this._debug = debug;
|
|
373
374
|
this._docFactory = crdt.doc(() => ({}));
|
|
374
375
|
this._router = router;
|
|
375
|
-
this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context }));
|
|
376
|
+
this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { context: roomContext }));
|
|
376
377
|
this._listeners = {
|
|
377
378
|
onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event),
|
|
378
379
|
onMessage: (event) => onMessage == null ? void 0 : onMessage(event)
|
|
@@ -712,7 +713,7 @@ var IORoom = class {
|
|
|
712
713
|
this._getSessions()
|
|
713
714
|
]);
|
|
714
715
|
const doc = yield this._doc;
|
|
715
|
-
const
|
|
716
|
+
const eventContext = {
|
|
716
717
|
context: this._context,
|
|
717
718
|
doc,
|
|
718
719
|
room: this.id,
|
|
@@ -754,11 +755,10 @@ var IORoom = class {
|
|
|
754
755
|
});
|
|
755
756
|
return;
|
|
756
757
|
}
|
|
757
|
-
const extendedContext = __spreadProps(__spreadValues({}, baseContext), { context: __spreadValues({}, this._context) });
|
|
758
758
|
yield Promise.all([
|
|
759
|
-
(_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs,
|
|
760
|
-
(_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs,
|
|
761
|
-
(_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs,
|
|
759
|
+
(_b = (_a = procedure.config).broadcast) == null ? void 0 : _b.call(_a, inputs, eventContext),
|
|
760
|
+
(_d = (_c = procedure.config).self) == null ? void 0 : _d.call(_c, inputs, eventContext),
|
|
761
|
+
(_f = (_e = procedure.config).sync) == null ? void 0 : _f.call(_e, inputs, eventContext)
|
|
762
762
|
]).then((_0) => __async(this, [_0], function* ([broadcast, self, sync]) {
|
|
763
763
|
const handleBroadcast = () => __async(this, null, function* () {
|
|
764
764
|
if (!broadcast) return;
|
|
@@ -890,7 +890,7 @@ var IORoom = class {
|
|
|
890
890
|
};
|
|
891
891
|
|
|
892
892
|
// src/version.generated.ts
|
|
893
|
-
var version = "0.
|
|
893
|
+
var version = "0.32.1";
|
|
894
894
|
|
|
895
895
|
// src/PluvServer.ts
|
|
896
896
|
var PluvServer = class {
|
|
@@ -1027,10 +1027,11 @@ var PluvServer = class {
|
|
|
1027
1027
|
var _a, _c;
|
|
1028
1028
|
const _b = (_a = options[0]) != null ? _a : {}, { _meta, debug, onDestroy, onMessage } = _b, platformRoomContext = __objRest(_b, ["_meta", "debug", "onDestroy", "onMessage"]);
|
|
1029
1029
|
if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
|
|
1030
|
-
const roomContext =
|
|
1030
|
+
const roomContext = platformRoomContext;
|
|
1031
|
+
const context = typeof this._context === "function" ? this._context(roomContext) : this._context;
|
|
1031
1032
|
const newRoom = new IORoom(room, __spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), {
|
|
1032
1033
|
authorize: (_c = this._authorize) != null ? _c : void 0,
|
|
1033
|
-
context
|
|
1034
|
+
context,
|
|
1034
1035
|
crdt: this._crdt,
|
|
1035
1036
|
debug: debug != null ? debug : this._debug,
|
|
1036
1037
|
onDestroy: (event) => __async(this, null, function* () {
|
|
@@ -1045,6 +1046,7 @@ var PluvServer = class {
|
|
|
1045
1046
|
yield Promise.resolve(this._getListeners().onRoomMessage(event));
|
|
1046
1047
|
}),
|
|
1047
1048
|
platform: this._platform,
|
|
1049
|
+
roomContext,
|
|
1048
1050
|
router: this._router
|
|
1049
1051
|
}));
|
|
1050
1052
|
this._logDebug(`${colors2.blue("Created room:")} ${room}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"description": "@pluv/io server-side websocket manager",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"jose": "^5.9.3",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.4",
|
|
24
|
-
"@pluv/crdt": "^0.
|
|
25
|
-
"@pluv/types": "^0.
|
|
24
|
+
"@pluv/crdt": "^0.32.1",
|
|
25
|
+
"@pluv/types": "^0.32.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
30
|
"tsup": "^8.3.0",
|
|
31
31
|
"typescript": "^5.6.2",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"@pluv/tsconfig": "^0.32.1",
|
|
33
|
+
"eslint-config-pluv": "^0.32.1"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/IORoom.ts
CHANGED
|
@@ -48,7 +48,7 @@ interface BroadcastParams<TIO extends IORoom<any, any, any, any>> {
|
|
|
48
48
|
export interface IORoomListeners<
|
|
49
49
|
TPlatform extends AbstractPlatform<any>,
|
|
50
50
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
51
|
-
TContext extends
|
|
51
|
+
TContext extends Record<string, any>,
|
|
52
52
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
53
53
|
> {
|
|
54
54
|
onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
@@ -65,14 +65,15 @@ export type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent ex
|
|
|
65
65
|
export type IORoomConfig<
|
|
66
66
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
67
67
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
68
|
-
TContext extends
|
|
68
|
+
TContext extends Record<string, any> = {},
|
|
69
69
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
70
70
|
> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
71
71
|
authorize?: TAuthorize;
|
|
72
|
-
context: TContext
|
|
72
|
+
context: TContext;
|
|
73
73
|
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
74
74
|
debug: boolean;
|
|
75
75
|
platform: TPlatform;
|
|
76
|
+
roomContext: InferRoomContextType<TPlatform>;
|
|
76
77
|
router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
77
78
|
};
|
|
78
79
|
|
|
@@ -98,7 +99,7 @@ export class IORoom<
|
|
|
98
99
|
private _uninitialize: Promise<() => Promise<void>> | null = null;
|
|
99
100
|
|
|
100
101
|
private readonly _authorize: TAuthorize | null = null;
|
|
101
|
-
private readonly _context: TContext
|
|
102
|
+
private readonly _context: TContext;
|
|
102
103
|
private readonly _debug: boolean;
|
|
103
104
|
private readonly _docFactory: AbstractCrdtDocFactory<any>;
|
|
104
105
|
private readonly _listeners: IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>;
|
|
@@ -151,6 +152,7 @@ export class IORoom<
|
|
|
151
152
|
onDestroy,
|
|
152
153
|
onMessage,
|
|
153
154
|
platform,
|
|
155
|
+
roomContext,
|
|
154
156
|
router,
|
|
155
157
|
} = config as IORoomConfig<TPlatform, TAuthorize, TContext, TEvents> & { _meta?: any };
|
|
156
158
|
|
|
@@ -160,7 +162,7 @@ export class IORoom<
|
|
|
160
162
|
this._debug = debug;
|
|
161
163
|
this._docFactory = crdt.doc(() => ({}));
|
|
162
164
|
this._router = router;
|
|
163
|
-
this._platform = platform.initialize({ ...(!!_meta ? { _meta } : {}), context });
|
|
165
|
+
this._platform = platform.initialize({ ...(!!_meta ? { _meta } : {}), context: roomContext });
|
|
164
166
|
|
|
165
167
|
this._listeners = {
|
|
166
168
|
onDestroy: (event) => onDestroy?.(event),
|
|
@@ -577,7 +579,7 @@ export class IORoom<
|
|
|
577
579
|
]);
|
|
578
580
|
|
|
579
581
|
const doc = await this._doc;
|
|
580
|
-
const
|
|
582
|
+
const eventContext: EventResolverContext<TPlatform, TAuthorize, TContext> = {
|
|
581
583
|
context: this._context,
|
|
582
584
|
doc,
|
|
583
585
|
room: this.id,
|
|
@@ -633,16 +635,10 @@ export class IORoom<
|
|
|
633
635
|
return;
|
|
634
636
|
}
|
|
635
637
|
|
|
636
|
-
const extendedContext: EventResolverContext<
|
|
637
|
-
TPlatform,
|
|
638
|
-
TAuthorize,
|
|
639
|
-
TContext & InferRoomContextType<TPlatform>
|
|
640
|
-
> = { ...baseContext, context: { ...this._context } };
|
|
641
|
-
|
|
642
638
|
await Promise.all([
|
|
643
|
-
procedure.config.broadcast?.(inputs,
|
|
644
|
-
procedure.config.self?.(inputs,
|
|
645
|
-
procedure.config.sync?.(inputs,
|
|
639
|
+
procedure.config.broadcast?.(inputs, eventContext),
|
|
640
|
+
procedure.config.self?.(inputs, eventContext),
|
|
641
|
+
procedure.config.sync?.(inputs, eventContext),
|
|
646
642
|
]).then(async ([broadcast, self, sync]) => {
|
|
647
643
|
const handleBroadcast = async () => {
|
|
648
644
|
if (!broadcast) return;
|
package/src/PluvIO.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import { noop } from "@pluv/crdt";
|
|
3
|
-
import type { BaseIOAuthorize, IOAuthorize, InferIOAuthorizeUser
|
|
3
|
+
import type { BaseIOAuthorize, IOAuthorize, InferIOAuthorizeUser } from "@pluv/types";
|
|
4
4
|
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
5
5
|
import { PluvProcedure } from "./PluvProcedure";
|
|
6
6
|
import type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
@@ -8,16 +8,16 @@ import { PluvRouter } from "./PluvRouter";
|
|
|
8
8
|
import { PluvServer } from "./PluvServer";
|
|
9
9
|
import type { JWTEncodeParams } from "./authorize";
|
|
10
10
|
import { authorize } from "./authorize";
|
|
11
|
-
import type { CrdtLibraryType, GetInitialStorageFn, PluvIOListeners } from "./types";
|
|
11
|
+
import type { CrdtLibraryType, GetInitialStorageFn, PluvContext, PluvIOListeners } from "./types";
|
|
12
12
|
import { __PLUV_VERSION } from "./version";
|
|
13
13
|
|
|
14
14
|
export type PluvIOConfig<
|
|
15
15
|
TPlatform extends AbstractPlatform<any>,
|
|
16
16
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
17
|
-
TContext extends
|
|
17
|
+
TContext extends Record<string, any>,
|
|
18
18
|
> = {
|
|
19
19
|
authorize?: TAuthorize;
|
|
20
|
-
context?: TContext
|
|
20
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
21
21
|
crdt?: CrdtLibraryType;
|
|
22
22
|
debug?: boolean;
|
|
23
23
|
platform: TPlatform;
|
|
@@ -26,7 +26,7 @@ export type PluvIOConfig<
|
|
|
26
26
|
export type ServerConfig<
|
|
27
27
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
28
28
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
29
|
-
TContext extends
|
|
29
|
+
TContext extends Record<string, any> = {},
|
|
30
30
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
31
31
|
> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
32
32
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
@@ -36,12 +36,12 @@ export type ServerConfig<
|
|
|
36
36
|
export class PluvIO<
|
|
37
37
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
38
38
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
39
|
-
TContext extends
|
|
39
|
+
TContext extends Record<string, any> = {},
|
|
40
40
|
> {
|
|
41
41
|
public readonly version: string = __PLUV_VERSION as any;
|
|
42
42
|
|
|
43
43
|
private readonly _authorize: TAuthorize | null = null;
|
|
44
|
-
private readonly _context: TContext = {} as TContext
|
|
44
|
+
private readonly _context: PluvContext<TPlatform, TContext> = {} as PluvContext<TPlatform, TContext>;
|
|
45
45
|
private readonly _crdt: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
46
46
|
private readonly _debug: boolean;
|
|
47
47
|
private readonly _platform: TPlatform;
|
package/src/PluvProcedure.ts
CHANGED
|
@@ -1,55 +1,31 @@
|
|
|
1
1
|
import type { EventRecord, IOAuthorize, InputZodLike, JsonObject, ProcedureLike } from "@pluv/types";
|
|
2
|
-
import type { AbstractPlatform, InferInitContextType
|
|
2
|
+
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
3
3
|
import type { EventResolver, MergeEventRecords } from "./types";
|
|
4
4
|
|
|
5
5
|
export interface PluvProcedureConfig<
|
|
6
6
|
TPlatform extends AbstractPlatform<any>,
|
|
7
7
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
8
|
-
TContext extends
|
|
8
|
+
TContext extends Record<string, any>,
|
|
9
9
|
TInput extends JsonObject = {},
|
|
10
10
|
TOutput extends EventRecord<string, any> = {},
|
|
11
11
|
> {
|
|
12
|
-
broadcast?: EventResolver<
|
|
13
|
-
TPlatform,
|
|
14
|
-
TAuthorize,
|
|
15
|
-
TContext & InferRoomContextType<TPlatform>,
|
|
16
|
-
TInput,
|
|
17
|
-
Partial<TOutput>
|
|
18
|
-
> | null;
|
|
12
|
+
broadcast?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
19
13
|
input?: InputZodLike<TInput>;
|
|
20
|
-
self?: EventResolver<
|
|
21
|
-
TPlatform,
|
|
22
|
-
TAuthorize,
|
|
23
|
-
TContext & InferRoomContextType<TPlatform>,
|
|
24
|
-
TInput,
|
|
25
|
-
Partial<TOutput>
|
|
26
|
-
> | null;
|
|
14
|
+
self?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
27
15
|
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
28
16
|
}
|
|
29
17
|
|
|
30
18
|
export class PluvProcedure<
|
|
31
19
|
TPlatform extends AbstractPlatform<any>,
|
|
32
20
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
33
|
-
TContext extends
|
|
21
|
+
TContext extends Record<string, any>,
|
|
34
22
|
TInput extends JsonObject = {},
|
|
35
23
|
TOutput extends EventRecord<string, any> = {},
|
|
36
24
|
TFilled extends "input" | "broadcast" | "self" | "sync" | "" = "",
|
|
37
25
|
> {
|
|
38
|
-
private _broadcast: EventResolver<
|
|
39
|
-
TPlatform,
|
|
40
|
-
TAuthorize,
|
|
41
|
-
TContext & InferRoomContextType<TPlatform>,
|
|
42
|
-
TInput,
|
|
43
|
-
Partial<TOutput>
|
|
44
|
-
> | null = null;
|
|
26
|
+
private _broadcast: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
|
|
45
27
|
private _input: InputZodLike<TInput> | null = null;
|
|
46
|
-
private _self: EventResolver<
|
|
47
|
-
TPlatform,
|
|
48
|
-
TAuthorize,
|
|
49
|
-
TContext & InferRoomContextType<TPlatform>,
|
|
50
|
-
TInput,
|
|
51
|
-
Partial<TOutput>
|
|
52
|
-
> | null = null;
|
|
28
|
+
private _self: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
|
|
53
29
|
private _sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
|
|
54
30
|
|
|
55
31
|
public get config(): ProcedureLike<TInput, TOutput>["config"] {
|
|
@@ -72,7 +48,7 @@ export class PluvProcedure<
|
|
|
72
48
|
}
|
|
73
49
|
|
|
74
50
|
public broadcast<TResult extends EventRecord<string, any> = {}>(
|
|
75
|
-
resolver: EventResolver<TPlatform, TAuthorize, TContext
|
|
51
|
+
resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
76
52
|
): Omit<
|
|
77
53
|
PluvProcedure<
|
|
78
54
|
TPlatform,
|
|
@@ -108,7 +84,7 @@ export class PluvProcedure<
|
|
|
108
84
|
}
|
|
109
85
|
|
|
110
86
|
public self<TResult extends EventRecord<string, any> = {}>(
|
|
111
|
-
resolver: EventResolver<TPlatform, TAuthorize, TContext
|
|
87
|
+
resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
112
88
|
): Omit<
|
|
113
89
|
PluvProcedure<
|
|
114
90
|
TPlatform,
|
|
@@ -138,7 +114,7 @@ export class PluvProcedure<
|
|
|
138
114
|
}
|
|
139
115
|
|
|
140
116
|
public sync<TResult extends EventRecord<string, any> = {}>(
|
|
141
|
-
resolver: EventResolver<TPlatform, TAuthorize, TContext
|
|
117
|
+
resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
142
118
|
): Omit<
|
|
143
119
|
PluvProcedure<
|
|
144
120
|
TPlatform,
|
|
@@ -167,13 +143,7 @@ export class PluvProcedure<
|
|
|
167
143
|
});
|
|
168
144
|
}
|
|
169
145
|
|
|
170
|
-
private _resolver(): EventResolver<
|
|
171
|
-
TPlatform,
|
|
172
|
-
TAuthorize,
|
|
173
|
-
TContext & InferRoomContextType<TPlatform>,
|
|
174
|
-
TInput,
|
|
175
|
-
TOutput
|
|
176
|
-
> {
|
|
146
|
+
private _resolver(): EventResolver<TPlatform, TAuthorize, TContext, TInput, TOutput> {
|
|
177
147
|
return (data, context) => {
|
|
178
148
|
return {
|
|
179
149
|
...this._broadcast?.(data, context),
|
package/src/PluvRouter.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { BaseIOAuthorize, IOAuthorize, IORouterLike
|
|
1
|
+
import type { BaseIOAuthorize, IOAuthorize, IORouterLike } from "@pluv/types";
|
|
2
2
|
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
3
3
|
import type { PluvProcedure } from "./PluvProcedure";
|
|
4
4
|
|
|
5
5
|
export type PluvRouterEventConfig<
|
|
6
6
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
7
7
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
8
|
-
TContext extends
|
|
8
|
+
TContext extends Record<string, any> = {},
|
|
9
9
|
> = { [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config"> };
|
|
10
10
|
|
|
11
11
|
export type MergedRouter<
|
|
12
12
|
TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [],
|
|
13
13
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
14
14
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
15
|
-
TContext extends
|
|
15
|
+
TContext extends Record<string, any> = {},
|
|
16
16
|
TRoot extends TRouters[0]["_defs"]["events"] = {},
|
|
17
17
|
> = TRouters extends [
|
|
18
18
|
infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
|
|
@@ -24,7 +24,7 @@ export type MergedRouter<
|
|
|
24
24
|
export class PluvRouter<
|
|
25
25
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
26
26
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
27
|
-
TContext extends
|
|
27
|
+
TContext extends Record<string, any> = {},
|
|
28
28
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
29
29
|
> implements IORouterLike<TEvents>
|
|
30
30
|
{
|
package/src/PluvServer.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { PluvRouter } from "./PluvRouter";
|
|
|
20
20
|
import type { JWTEncodeParams } from "./authorize";
|
|
21
21
|
import { authorize } from "./authorize";
|
|
22
22
|
import { PING_TIMEOUT_MS } from "./constants";
|
|
23
|
-
import type { GetInitialStorageFn, PluvIOListeners } from "./types";
|
|
23
|
+
import type { GetInitialStorageFn, PluvContext, PluvIOListeners } from "./types";
|
|
24
24
|
import { __PLUV_VERSION } from "./version";
|
|
25
25
|
|
|
26
26
|
export type InferIORoom<TServer extends PluvServer<any, any, any, any>> =
|
|
@@ -31,11 +31,11 @@ export type InferIORoom<TServer extends PluvServer<any, any, any, any>> =
|
|
|
31
31
|
export type PluvServerConfig<
|
|
32
32
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
33
33
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
34
|
-
TContext extends
|
|
34
|
+
TContext extends Record<string, any> = {},
|
|
35
35
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
36
36
|
> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
37
37
|
authorize?: TAuthorize;
|
|
38
|
-
context?: TContext
|
|
38
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
39
39
|
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
40
40
|
debug?: boolean;
|
|
41
41
|
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
@@ -46,7 +46,7 @@ export type PluvServerConfig<
|
|
|
46
46
|
type BaseCreateRoomOptions<
|
|
47
47
|
TPlatform extends AbstractPlatform<any>,
|
|
48
48
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
49
|
-
TContext extends
|
|
49
|
+
TContext extends Record<string, any>,
|
|
50
50
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
51
51
|
> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
52
52
|
debug?: boolean;
|
|
@@ -55,7 +55,7 @@ type BaseCreateRoomOptions<
|
|
|
55
55
|
export type CreateRoomOptions<
|
|
56
56
|
TPlatform extends AbstractPlatform<any>,
|
|
57
57
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
58
|
-
TContext extends
|
|
58
|
+
TContext extends Record<string, any>,
|
|
59
59
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
60
60
|
> = keyof InferRoomContextType<TPlatform> extends never
|
|
61
61
|
? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | []
|
|
@@ -64,7 +64,7 @@ export type CreateRoomOptions<
|
|
|
64
64
|
export class PluvServer<
|
|
65
65
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
66
66
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
67
|
-
TContext extends
|
|
67
|
+
TContext extends Record<string, any> = {},
|
|
68
68
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
69
69
|
> implements IORouterLike<TEvents>
|
|
70
70
|
{
|
|
@@ -188,7 +188,7 @@ export class PluvServer<
|
|
|
188
188
|
return { $STORAGE_UPDATED: { state: encodedState } };
|
|
189
189
|
}),
|
|
190
190
|
});
|
|
191
|
-
private readonly _context: TContext = {} as TContext
|
|
191
|
+
private readonly _context: PluvContext<TPlatform, TContext> = {} as PluvContext<TPlatform, TContext>;
|
|
192
192
|
private readonly _crdt: { doc: (value: any) => AbstractCrdtDocFactory<any> };
|
|
193
193
|
private readonly _debug: boolean;
|
|
194
194
|
private readonly _getInitialStorage: GetInitialStorageFn<TPlatform> | null = null;
|
|
@@ -261,15 +261,13 @@ export class PluvServer<
|
|
|
261
261
|
|
|
262
262
|
if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) throw new Error("Unsupported room name");
|
|
263
263
|
|
|
264
|
-
const roomContext =
|
|
265
|
-
|
|
266
|
-
...platformRoomContext,
|
|
267
|
-
} as TContext & InferRoomContextType<TPlatform>;
|
|
264
|
+
const roomContext = platformRoomContext as InferRoomContextType<TPlatform>;
|
|
265
|
+
const context: TContext = typeof this._context === "function" ? this._context(roomContext) : this._context;
|
|
268
266
|
|
|
269
267
|
const newRoom = new IORoom<TPlatform, TAuthorize, TContext, TEvents>(room, {
|
|
270
268
|
...(!!_meta ? { _meta } : {}),
|
|
271
269
|
authorize: this._authorize ?? undefined,
|
|
272
|
-
context
|
|
270
|
+
context,
|
|
273
271
|
crdt: this._crdt,
|
|
274
272
|
debug: debug ?? this._debug,
|
|
275
273
|
onDestroy: async (event) => {
|
|
@@ -286,6 +284,7 @@ export class PluvServer<
|
|
|
286
284
|
await Promise.resolve(this._getListeners().onRoomMessage(event));
|
|
287
285
|
},
|
|
288
286
|
platform: this._platform,
|
|
287
|
+
roomContext,
|
|
289
288
|
router: this._router,
|
|
290
289
|
});
|
|
291
290
|
|
package/src/createIO.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { BaseUser, IOAuthorize
|
|
1
|
+
import type { BaseUser, IOAuthorize } from "@pluv/types";
|
|
2
2
|
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
3
3
|
import { PluvIO } from "./PluvIO";
|
|
4
|
-
import type { CrdtLibraryType } from "./types";
|
|
4
|
+
import type { CrdtLibraryType, PluvContext } from "./types";
|
|
5
5
|
|
|
6
6
|
export type CreateIOParams<
|
|
7
7
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
8
|
-
TContext extends
|
|
8
|
+
TContext extends Record<string, any> = {},
|
|
9
9
|
TAuthorizeUser extends BaseUser = BaseUser,
|
|
10
10
|
TAuthorizeRequired extends boolean = false,
|
|
11
11
|
> = {
|
|
12
12
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferInitContextType<TPlatform>>;
|
|
13
|
-
context?: TContext
|
|
13
|
+
context?: PluvContext<TPlatform, TContext>;
|
|
14
14
|
crdt?: CrdtLibraryType;
|
|
15
15
|
debug?: boolean;
|
|
16
16
|
platform: TPlatform;
|
|
@@ -18,7 +18,7 @@ export type CreateIOParams<
|
|
|
18
18
|
|
|
19
19
|
export const createIO = <
|
|
20
20
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
21
|
-
TContext extends
|
|
21
|
+
TContext extends Record<string, any> = {},
|
|
22
22
|
TAuthorizeUser extends BaseUser = BaseUser,
|
|
23
23
|
TAuthorizeRequired extends boolean = false,
|
|
24
24
|
>(
|
package/src/types.ts
CHANGED
|
@@ -27,6 +27,10 @@ declare global {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> =
|
|
31
|
+
| TContext
|
|
32
|
+
| ((params: InferRoomContextType<TPlatform>) => TContext);
|
|
33
|
+
|
|
30
34
|
export interface CrdtLibraryType {
|
|
31
35
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
32
36
|
kind: "loro" | "yjs";
|
|
@@ -104,7 +108,7 @@ export type MergeEventRecords<
|
|
|
104
108
|
|
|
105
109
|
type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
106
110
|
room: string;
|
|
107
|
-
}
|
|
111
|
+
};
|
|
108
112
|
|
|
109
113
|
export type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (
|
|
110
114
|
event: GetInitialStorageEvent<TPlatform>,
|
|
@@ -113,7 +117,7 @@ export type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (
|
|
|
113
117
|
export interface PluvIOListeners<
|
|
114
118
|
TPlatform extends AbstractPlatform<any>,
|
|
115
119
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
116
|
-
TContext extends
|
|
120
|
+
TContext extends Record<string, any>,
|
|
117
121
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
118
122
|
> {
|
|
119
123
|
onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
@@ -124,10 +128,10 @@ export interface PluvIOListeners<
|
|
|
124
128
|
export type IORoomListenerEvent<
|
|
125
129
|
TPlatform extends AbstractPlatform<any>,
|
|
126
130
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
127
|
-
TContext extends
|
|
131
|
+
TContext extends Record<string, any>,
|
|
128
132
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
129
133
|
> = {
|
|
130
|
-
context: TContext
|
|
134
|
+
context: TContext;
|
|
131
135
|
encodedState: string | null;
|
|
132
136
|
room: string;
|
|
133
137
|
};
|
|
@@ -135,7 +139,7 @@ export type IORoomListenerEvent<
|
|
|
135
139
|
export type IORoomMessageEvent<
|
|
136
140
|
TPlatform extends AbstractPlatform<any>,
|
|
137
141
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
|
|
138
|
-
TContext extends
|
|
142
|
+
TContext extends Record<string, any>,
|
|
139
143
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
|
|
140
144
|
> = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
|
|
141
145
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.32.1'
|