@pluv/io 2.1.0 → 2.2.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 +15 -0
- package/dist/index.d.mts +22 -25
- package/dist/index.d.ts +22 -25
- package/dist/index.js +126 -105
- package/dist/index.mjs +126 -105
- package/package.json +5 -5
- package/src/AbstractPlatform.ts +7 -2
- package/src/IORoom.ts +11 -5
- package/src/PluvIO.ts +9 -5
- package/src/PluvServer.ts +261 -248
- package/src/createIO.ts +1 -1
- package/src/types.ts +13 -8
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@2.1
|
|
2
|
+
> @pluv/io@2.2.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@2.1
|
|
6
|
+
> @pluv/io@2.2.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
|
-
[32mCJS[39m [1mdist/index.js [22m[32m53.
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in
|
|
17
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m51.
|
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m53.90 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 106ms
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m51.72 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 109ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m32.
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m32.
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 4113ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m32.25 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m32.25 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 2.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/crdt@2.2.1
|
|
8
|
+
- @pluv/types@2.2.1
|
|
9
|
+
|
|
10
|
+
## 2.2.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- cb660cd: Fixed multiple Cloudflare Worker Durable Objects sharing references to the same I/O methods.
|
|
15
|
+
- @pluv/crdt@2.2.0
|
|
16
|
+
- @pluv/types@2.2.0
|
|
17
|
+
|
|
3
18
|
## 2.1.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -122,15 +122,16 @@ declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
122
122
|
|
|
123
123
|
type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> = TContext | ((params: InferRoomContextType<TPlatform>) => TContext);
|
|
124
124
|
interface CrdtLibraryType {
|
|
125
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
125
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
126
126
|
kind: "loro" | "yjs";
|
|
127
127
|
}
|
|
128
128
|
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
129
129
|
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>;
|
|
130
130
|
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}> {
|
|
131
131
|
context: TContext;
|
|
132
|
-
doc: CrdtDocLike<any>;
|
|
132
|
+
doc: CrdtDocLike<any, any>;
|
|
133
133
|
garbageCollect: () => Promise<void>;
|
|
134
|
+
platform: TPlatform;
|
|
134
135
|
presence: JsonObject | null;
|
|
135
136
|
room: string;
|
|
136
137
|
session: TKind extends "sync" ? WebSocketSession<TAuthorize> | null : WebSocketSession<TAuthorize>;
|
|
@@ -214,7 +215,7 @@ interface PluvIOLimits {
|
|
|
214
215
|
userMaxSize?: number | null;
|
|
215
216
|
}
|
|
216
217
|
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>> = {
|
|
217
|
-
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
218
|
+
onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
218
219
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
219
220
|
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
220
221
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -234,25 +235,26 @@ type InferPlatformListeners<TPlatform extends AbstractPlatform<any, any, any, an
|
|
|
234
235
|
[P in keyof PlatformConfig["listeners"] as InferPlatformConfig<TPlatform>["listeners"][P] extends true | undefined ? P : never]: true;
|
|
235
236
|
};
|
|
236
237
|
type InferPlatformRouter<TPlatform extends AbstractPlatform<any, any, any, any>> = InferPlatformConfig<TPlatform>["router"];
|
|
237
|
-
type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
238
|
+
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any, any, any, any>, TContext extends Record<string, any>> = {
|
|
238
239
|
context: TContext;
|
|
239
240
|
encodedState: string | null;
|
|
241
|
+
platform: TPlatform;
|
|
240
242
|
room: string;
|
|
241
243
|
};
|
|
242
|
-
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> & {
|
|
244
|
+
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<TPlatform, TContext> & {
|
|
243
245
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
244
246
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
245
247
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
246
248
|
};
|
|
247
|
-
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
249
|
+
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
248
250
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
249
251
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
250
252
|
};
|
|
251
|
-
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
253
|
+
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
252
254
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
253
255
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
254
256
|
};
|
|
255
|
-
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
257
|
+
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
256
258
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
257
259
|
};
|
|
258
260
|
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
@@ -307,7 +309,9 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket<any
|
|
|
307
309
|
private _initialized;
|
|
308
310
|
persistence: AbstractPersistence;
|
|
309
311
|
pubSub: AbstractPubSub;
|
|
310
|
-
readonly _createToken?: (params: JWTEncodeParams<any, any>
|
|
312
|
+
readonly _createToken?: (params: JWTEncodeParams<any, any> & {
|
|
313
|
+
authorize: Maybe<ResolvedPluvIOAuthorize<any, any>>;
|
|
314
|
+
}) => Promise<string>;
|
|
311
315
|
_fetch?: (...args: any[]) => Promise<any>;
|
|
312
316
|
abstract readonly _config: TConfig;
|
|
313
317
|
abstract readonly _name: string;
|
|
@@ -327,7 +331,7 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket<any
|
|
|
327
331
|
}
|
|
328
332
|
|
|
329
333
|
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>> {
|
|
330
|
-
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
334
|
+
onDestroy: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
331
335
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
332
336
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
333
337
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -339,7 +343,7 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
339
343
|
authorize?: TAuthorize;
|
|
340
344
|
context: TContext;
|
|
341
345
|
crdt?: {
|
|
342
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
346
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
343
347
|
};
|
|
344
348
|
debug: boolean;
|
|
345
349
|
platform: TPlatform;
|
|
@@ -433,13 +437,13 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any, any> = AbstractPla
|
|
|
433
437
|
authorize?: TAuthorize;
|
|
434
438
|
context?: PluvContext<TPlatform, TContext>;
|
|
435
439
|
crdt?: {
|
|
436
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
440
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
437
441
|
};
|
|
438
442
|
debug?: boolean;
|
|
439
443
|
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
440
444
|
limits: PluvIOLimits;
|
|
441
445
|
io: PluvIO<TPlatform, TAuthorize, TContext>;
|
|
442
|
-
platform: TPlatform;
|
|
446
|
+
platform: () => TPlatform;
|
|
443
447
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
444
448
|
};
|
|
445
449
|
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any, 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>> & {
|
|
@@ -450,16 +454,7 @@ type CreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize
|
|
|
450
454
|
];
|
|
451
455
|
declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, 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> {
|
|
452
456
|
readonly version: string;
|
|
453
|
-
private readonly
|
|
454
|
-
private readonly _baseRouter;
|
|
455
|
-
private readonly _context;
|
|
456
|
-
private readonly _crdt;
|
|
457
|
-
private readonly _debug;
|
|
458
|
-
private readonly _getInitialStorage;
|
|
459
|
-
private readonly _io;
|
|
460
|
-
private readonly _limits;
|
|
461
|
-
private readonly _platform;
|
|
462
|
-
private readonly _router;
|
|
457
|
+
private readonly _config;
|
|
463
458
|
get fetch(): (...args: any[]) => Promise<any>;
|
|
464
459
|
/**
|
|
465
460
|
* @ignore
|
|
@@ -472,7 +467,9 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = Abstract
|
|
|
472
467
|
events: TEvents;
|
|
473
468
|
platform: TPlatform;
|
|
474
469
|
};
|
|
470
|
+
private get _baseRouter();
|
|
475
471
|
private get _procedure();
|
|
472
|
+
private get _router();
|
|
476
473
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
477
474
|
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
478
475
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
@@ -486,7 +483,7 @@ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IO
|
|
|
486
483
|
crdt?: CrdtLibraryType;
|
|
487
484
|
debug?: boolean;
|
|
488
485
|
limits?: PluvIOLimits;
|
|
489
|
-
platform: TPlatform;
|
|
486
|
+
platform: () => TPlatform;
|
|
490
487
|
};
|
|
491
488
|
type ResolvedServerConfig<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>> & PluvIORouter<TPlatform, TAuthorize, TContext, TEvents> & {
|
|
492
489
|
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
@@ -517,7 +514,7 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
517
514
|
crdt?: CrdtLibraryType;
|
|
518
515
|
debug?: boolean;
|
|
519
516
|
limits?: PluvIOLimits;
|
|
520
|
-
platform: TPlatform;
|
|
517
|
+
platform: () => TPlatform;
|
|
521
518
|
};
|
|
522
519
|
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null>(params: CreateIOParams<TPlatform, TContext, TUser>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>, TContext>;
|
|
523
520
|
|
package/dist/index.d.ts
CHANGED
|
@@ -122,15 +122,16 @@ declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
122
122
|
|
|
123
123
|
type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> = TContext | ((params: InferRoomContextType<TPlatform>) => TContext);
|
|
124
124
|
interface CrdtLibraryType {
|
|
125
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
125
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
126
126
|
kind: "loro" | "yjs";
|
|
127
127
|
}
|
|
128
128
|
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
129
129
|
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>;
|
|
130
130
|
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}> {
|
|
131
131
|
context: TContext;
|
|
132
|
-
doc: CrdtDocLike<any>;
|
|
132
|
+
doc: CrdtDocLike<any, any>;
|
|
133
133
|
garbageCollect: () => Promise<void>;
|
|
134
|
+
platform: TPlatform;
|
|
134
135
|
presence: JsonObject | null;
|
|
135
136
|
room: string;
|
|
136
137
|
session: TKind extends "sync" ? WebSocketSession<TAuthorize> | null : WebSocketSession<TAuthorize>;
|
|
@@ -214,7 +215,7 @@ interface PluvIOLimits {
|
|
|
214
215
|
userMaxSize?: number | null;
|
|
215
216
|
}
|
|
216
217
|
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>> = {
|
|
217
|
-
onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
|
|
218
|
+
onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
218
219
|
onRoomMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
219
220
|
onStorageUpdated: (event: IOStorageUpdatedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
220
221
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -234,25 +235,26 @@ type InferPlatformListeners<TPlatform extends AbstractPlatform<any, any, any, an
|
|
|
234
235
|
[P in keyof PlatformConfig["listeners"] as InferPlatformConfig<TPlatform>["listeners"][P] extends true | undefined ? P : never]: true;
|
|
235
236
|
};
|
|
236
237
|
type InferPlatformRouter<TPlatform extends AbstractPlatform<any, any, any, any>> = InferPlatformConfig<TPlatform>["router"];
|
|
237
|
-
type IORoomListenerEvent<TContext extends Record<string, any>> = {
|
|
238
|
+
type IORoomListenerEvent<TPlatform extends AbstractPlatform<any, any, any, any>, TContext extends Record<string, any>> = {
|
|
238
239
|
context: TContext;
|
|
239
240
|
encodedState: string | null;
|
|
241
|
+
platform: TPlatform;
|
|
240
242
|
room: string;
|
|
241
243
|
};
|
|
242
|
-
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> & {
|
|
244
|
+
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<TPlatform, TContext> & {
|
|
243
245
|
message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
|
|
244
246
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
245
247
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
246
248
|
};
|
|
247
|
-
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
249
|
+
type IOStorageUpdatedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
248
250
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
249
251
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
250
252
|
};
|
|
251
|
-
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
253
|
+
type IOUserConnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
252
254
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
253
255
|
webSocket?: InferPlatformWebSocketSource<TPlatform>;
|
|
254
256
|
};
|
|
255
|
-
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TContext> & {
|
|
257
|
+
type IOUserDisconnectedEvent<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = IORoomListenerEvent<TPlatform, TContext> & {
|
|
256
258
|
user?: InferIOAuthorizeUser<TAuthorize>;
|
|
257
259
|
};
|
|
258
260
|
type WebSocketType<TPlatform extends AbstractPlatform> = InferPlatformWebSocketType<TPlatform> | InferPlatformWebSocketSource<TPlatform>;
|
|
@@ -307,7 +309,9 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket<any
|
|
|
307
309
|
private _initialized;
|
|
308
310
|
persistence: AbstractPersistence;
|
|
309
311
|
pubSub: AbstractPubSub;
|
|
310
|
-
readonly _createToken?: (params: JWTEncodeParams<any, any>
|
|
312
|
+
readonly _createToken?: (params: JWTEncodeParams<any, any> & {
|
|
313
|
+
authorize: Maybe<ResolvedPluvIOAuthorize<any, any>>;
|
|
314
|
+
}) => Promise<string>;
|
|
311
315
|
_fetch?: (...args: any[]) => Promise<any>;
|
|
312
316
|
abstract readonly _config: TConfig;
|
|
313
317
|
abstract readonly _name: string;
|
|
@@ -327,7 +331,7 @@ declare abstract class AbstractPlatform<TWebSocket extends AbstractWebSocket<any
|
|
|
327
331
|
}
|
|
328
332
|
|
|
329
333
|
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>> {
|
|
330
|
-
onDestroy: (event: IORoomListenerEvent<TContext>) => void;
|
|
334
|
+
onDestroy: (event: IORoomListenerEvent<TPlatform, TContext>) => void;
|
|
331
335
|
onMessage: (event: IORoomMessageEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
332
336
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
333
337
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
@@ -339,7 +343,7 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
339
343
|
authorize?: TAuthorize;
|
|
340
344
|
context: TContext;
|
|
341
345
|
crdt?: {
|
|
342
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
346
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
343
347
|
};
|
|
344
348
|
debug: boolean;
|
|
345
349
|
platform: TPlatform;
|
|
@@ -433,13 +437,13 @@ type PluvServerConfig<TPlatform extends AbstractPlatform<any, any> = AbstractPla
|
|
|
433
437
|
authorize?: TAuthorize;
|
|
434
438
|
context?: PluvContext<TPlatform, TContext>;
|
|
435
439
|
crdt?: {
|
|
436
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
440
|
+
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
437
441
|
};
|
|
438
442
|
debug?: boolean;
|
|
439
443
|
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
440
444
|
limits: PluvIOLimits;
|
|
441
445
|
io: PluvIO<TPlatform, TAuthorize, TContext>;
|
|
442
|
-
platform: TPlatform;
|
|
446
|
+
platform: () => TPlatform;
|
|
443
447
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
444
448
|
};
|
|
445
449
|
type BaseCreateRoomOptions<TPlatform extends AbstractPlatform<any, 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>> & {
|
|
@@ -450,16 +454,7 @@ type CreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize
|
|
|
450
454
|
];
|
|
451
455
|
declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, 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> {
|
|
452
456
|
readonly version: string;
|
|
453
|
-
private readonly
|
|
454
|
-
private readonly _baseRouter;
|
|
455
|
-
private readonly _context;
|
|
456
|
-
private readonly _crdt;
|
|
457
|
-
private readonly _debug;
|
|
458
|
-
private readonly _getInitialStorage;
|
|
459
|
-
private readonly _io;
|
|
460
|
-
private readonly _limits;
|
|
461
|
-
private readonly _platform;
|
|
462
|
-
private readonly _router;
|
|
457
|
+
private readonly _config;
|
|
463
458
|
get fetch(): (...args: any[]) => Promise<any>;
|
|
464
459
|
/**
|
|
465
460
|
* @ignore
|
|
@@ -472,7 +467,9 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = Abstract
|
|
|
472
467
|
events: TEvents;
|
|
473
468
|
platform: TPlatform;
|
|
474
469
|
};
|
|
470
|
+
private get _baseRouter();
|
|
475
471
|
private get _procedure();
|
|
472
|
+
private get _router();
|
|
476
473
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
477
474
|
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
478
475
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
@@ -486,7 +483,7 @@ type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IO
|
|
|
486
483
|
crdt?: CrdtLibraryType;
|
|
487
484
|
debug?: boolean;
|
|
488
485
|
limits?: PluvIOLimits;
|
|
489
|
-
platform: TPlatform;
|
|
486
|
+
platform: () => TPlatform;
|
|
490
487
|
};
|
|
491
488
|
type ResolvedServerConfig<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>> & PluvIORouter<TPlatform, TAuthorize, TContext, TEvents> & {
|
|
492
489
|
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
@@ -517,7 +514,7 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
517
514
|
crdt?: CrdtLibraryType;
|
|
518
515
|
debug?: boolean;
|
|
519
516
|
limits?: PluvIOLimits;
|
|
520
|
-
platform: TPlatform;
|
|
517
|
+
platform: () => TPlatform;
|
|
521
518
|
};
|
|
522
519
|
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null>(params: CreateIOParams<TPlatform, TContext, TUser>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>, TContext>;
|
|
523
520
|
|