@pluv/io 2.3.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +34 -29
- package/dist/index.d.ts +34 -29
- package/dist/index.js +6 -6
- package/dist/index.mjs +6 -6
- package/package.json +5 -5
- package/src/IORoom.ts +10 -4
- package/src/PluvIO.ts +20 -14
- package/src/PluvServer.ts +28 -16
- package/src/createIO.ts +17 -6
- package/src/index.ts +1 -1
- package/src/types.ts +0 -5
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@
|
|
2
|
+
> @pluv/io@3.1.0 build /home/runner/work/pluv/pluv/packages/io
|
|
3
3
|
> pnpm run version && tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @pluv/io@
|
|
6
|
+
> @pluv/io@3.1.0 version /home/runner/work/pluv/pluv/packages/io
|
|
7
7
|
> genversion ./src/version.generated.ts --esm
|
|
8
8
|
|
|
9
9
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
[34mCLI[39m Target: es6
|
|
13
13
|
[34mESM[39m Build start
|
|
14
14
|
[34mCJS[39m Build start
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m52.48 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 177ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m54.65 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 177ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 4363ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m33.31 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m33.31 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a40f4dc: Fixed `getInitialStorage` not being required when `crdt` is provided.
|
|
8
|
+
- @pluv/crdt@3.1.0
|
|
9
|
+
- @pluv/types@3.1.0
|
|
10
|
+
|
|
11
|
+
## 3.0.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- @pluv/crdt@3.0.0
|
|
16
|
+
- @pluv/types@3.0.0
|
|
17
|
+
|
|
3
18
|
## 2.3.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractCrdtDocFactory, CrdtLibraryType as CrdtLibraryType$1, NoopCrdtDocFactory } from '@pluv/crdt';
|
|
2
|
+
export { CrdtLibraryType } from '@pluv/crdt';
|
|
3
|
+
import { JsonObject, IOAuthorize, InferIOAuthorizeUser, MaybePromise, IOEventMessage, EventRecord, ProcedureLike, InputZodLike, IORouterLike, BaseUser, UndefinedProps, CrdtDocLike, Id, InferEventMessage, InferEventsOutput, Maybe, IOLike, InferIOOutput, CrdtLibraryType, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
4
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
|
-
import { AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
4
5
|
|
|
5
6
|
declare abstract class AbstractPersistence {
|
|
6
7
|
abstract addUser(room: string, connectionId: string, user: JsonObject | null): Promise<void>;
|
|
@@ -121,10 +122,6 @@ declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> = TContext | ((params: InferRoomContextType<TPlatform>) => TContext);
|
|
124
|
-
interface CrdtLibraryType {
|
|
125
|
-
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
126
|
-
kind: "loro" | "yjs";
|
|
127
|
-
}
|
|
128
125
|
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
129
126
|
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
127
|
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}> {
|
|
@@ -337,7 +334,7 @@ interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize ex
|
|
|
337
334
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
338
335
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
339
336
|
}
|
|
340
|
-
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
337
|
+
type BroadcastProxy<TIO extends IORoom<any, any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
341
338
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
342
339
|
};
|
|
343
340
|
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
@@ -354,13 +351,14 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
354
351
|
type WebSocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
355
352
|
token?: string | null;
|
|
356
353
|
} & InferInitContextType<TPlatform>;
|
|
357
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
354
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
358
355
|
readonly id: string;
|
|
359
356
|
private _doc;
|
|
360
357
|
private _lastGarbageCollectMs;
|
|
361
358
|
private _uninitialize;
|
|
362
359
|
private readonly _authorize;
|
|
363
360
|
private readonly _context;
|
|
361
|
+
private readonly _crdt;
|
|
364
362
|
private readonly _debug;
|
|
365
363
|
private readonly _docFactory;
|
|
366
364
|
private readonly _listeners;
|
|
@@ -376,6 +374,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
376
374
|
get _defs(): {
|
|
377
375
|
authorize: TAuthorize;
|
|
378
376
|
context: TContext;
|
|
377
|
+
crdt: TCrdt;
|
|
379
378
|
events: TEvents;
|
|
380
379
|
platform: TPlatform;
|
|
381
380
|
};
|
|
@@ -433,27 +432,30 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
433
432
|
private _sendSyncMessage;
|
|
434
433
|
}
|
|
435
434
|
|
|
436
|
-
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;
|
|
437
|
-
type PluvServerConfig<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> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
435
|
+
type InferIORoom<TServer extends PluvServer<any, any, any, any, any>> = TServer extends PluvServer<infer IPlatform, infer IAuthorize, infer IContext, infer ICrdt, infer IEvents> ? IORoom<IPlatform, IAuthorize, IContext, ICrdt, IEvents> : never;
|
|
436
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
438
437
|
authorize?: TAuthorize;
|
|
439
438
|
context?: PluvContext<TPlatform, TContext>;
|
|
440
439
|
crdt?: {
|
|
441
440
|
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
442
441
|
};
|
|
443
442
|
debug?: boolean;
|
|
444
|
-
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
445
443
|
limits: PluvIOLimits;
|
|
446
444
|
io: PluvIO<TPlatform, TAuthorize, TContext>;
|
|
447
445
|
platform: () => TPlatform;
|
|
448
446
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
449
|
-
}
|
|
447
|
+
} & (TCrdt extends CrdtLibraryType$1<NoopCrdtDocFactory> ? {
|
|
448
|
+
getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage";
|
|
449
|
+
} : {
|
|
450
|
+
getInitialStorage: GetInitialStorageFn<TContext>;
|
|
451
|
+
});
|
|
450
452
|
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>> & {
|
|
451
453
|
debug?: boolean;
|
|
452
454
|
};
|
|
453
455
|
type CreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [
|
|
454
456
|
Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>
|
|
455
457
|
];
|
|
456
|
-
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> {
|
|
458
|
+
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> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
457
459
|
readonly version: string;
|
|
458
460
|
private readonly _config;
|
|
459
461
|
get fetch(): (...args: any[]) => Promise<any>;
|
|
@@ -465,34 +467,37 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = Abstract
|
|
|
465
467
|
get _defs(): {
|
|
466
468
|
authorize: TAuthorize;
|
|
467
469
|
context: TContext;
|
|
470
|
+
crdt: TCrdt;
|
|
468
471
|
events: TEvents;
|
|
469
472
|
platform: TPlatform;
|
|
470
473
|
};
|
|
471
474
|
private get _baseRouter();
|
|
472
475
|
private get _procedure();
|
|
473
476
|
private get _router();
|
|
474
|
-
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
475
|
-
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
477
|
+
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>);
|
|
478
|
+
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
476
479
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
477
480
|
private _getListeners;
|
|
478
481
|
private _logDebug;
|
|
479
482
|
}
|
|
480
483
|
|
|
481
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = {
|
|
484
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>> = {
|
|
482
485
|
authorize?: TAuthorize;
|
|
483
486
|
context?: PluvContext<TPlatform, TContext>;
|
|
484
|
-
crdt?:
|
|
487
|
+
crdt?: TCrdt;
|
|
485
488
|
debug?: boolean;
|
|
486
489
|
limits?: PluvIOLimits;
|
|
487
490
|
platform: () => TPlatform;
|
|
488
491
|
};
|
|
489
|
-
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> & {
|
|
490
|
-
getInitialStorage?:
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
|
|
492
|
+
type ResolvedServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & PluvIORouter<TPlatform, TAuthorize, TContext, TEvents> & (TCrdt extends CrdtLibraryType$1<NoopCrdtDocFactory> ? {
|
|
493
|
+
getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage";
|
|
494
|
+
} : {
|
|
495
|
+
getInitialStorage: GetInitialStorageFn<TContext>;
|
|
496
|
+
});
|
|
497
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = {
|
|
498
|
+
[P in keyof ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents> as ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P] extends undefined ? never : P]: ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P];
|
|
494
499
|
};
|
|
495
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}> {
|
|
500
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>> {
|
|
496
501
|
readonly version: string;
|
|
497
502
|
private readonly _authorize;
|
|
498
503
|
private readonly _context;
|
|
@@ -501,22 +506,22 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
501
506
|
private readonly _limits;
|
|
502
507
|
private readonly _platform;
|
|
503
508
|
get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
|
|
504
|
-
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>);
|
|
509
|
+
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TCrdt>);
|
|
505
510
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<TAuthorize>, TPlatform>): Promise<string>;
|
|
506
511
|
mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
507
512
|
router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
508
|
-
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
513
|
+
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
509
514
|
private _getIOAuthorize;
|
|
510
515
|
}
|
|
511
516
|
|
|
512
|
-
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null> = {
|
|
517
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>> = {
|
|
513
518
|
authorize?: PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>;
|
|
514
519
|
context?: PluvContext<TPlatform, TContext>;
|
|
515
|
-
crdt?:
|
|
520
|
+
crdt?: TCrdt;
|
|
516
521
|
debug?: boolean;
|
|
517
522
|
limits?: PluvIOLimits;
|
|
518
523
|
platform: () => TPlatform;
|
|
519
524
|
};
|
|
520
|
-
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>;
|
|
525
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>>(params: CreateIOParams<TPlatform, TContext, TUser, TCrdt>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>, TContext, TCrdt>;
|
|
521
526
|
|
|
522
|
-
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
|
|
527
|
+
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 CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type HandleMode, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, type PlatformConfig, type PluvContext, PluvIO, type PluvIOAuthorize, type PluvIOConfig, type PluvIOLimits, 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
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractCrdtDocFactory, CrdtLibraryType as CrdtLibraryType$1, NoopCrdtDocFactory } from '@pluv/crdt';
|
|
2
|
+
export { CrdtLibraryType } from '@pluv/crdt';
|
|
3
|
+
import { JsonObject, IOAuthorize, InferIOAuthorizeUser, MaybePromise, IOEventMessage, EventRecord, ProcedureLike, InputZodLike, IORouterLike, BaseUser, UndefinedProps, CrdtDocLike, Id, InferEventMessage, InferEventsOutput, Maybe, IOLike, InferIOOutput, CrdtLibraryType, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
4
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
|
-
import { AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
4
5
|
|
|
5
6
|
declare abstract class AbstractPersistence {
|
|
6
7
|
abstract addUser(room: string, connectionId: string, user: JsonObject | null): Promise<void>;
|
|
@@ -121,10 +122,6 @@ declare class PluvRouter<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> = TContext | ((params: InferRoomContextType<TPlatform>) => TContext);
|
|
124
|
-
interface CrdtLibraryType {
|
|
125
|
-
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
126
|
-
kind: "loro" | "yjs";
|
|
127
|
-
}
|
|
128
125
|
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
129
126
|
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
127
|
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}> {
|
|
@@ -337,7 +334,7 @@ interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize ex
|
|
|
337
334
|
onUserConnected: (event: IOUserConnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
338
335
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
339
336
|
}
|
|
340
|
-
type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
337
|
+
type BroadcastProxy<TIO extends IORoom<any, any, any, any, any>> = (<TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => Promise<void>) & {
|
|
341
338
|
[event in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>>[event]) => Promise<void>;
|
|
342
339
|
};
|
|
343
340
|
type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
@@ -354,13 +351,14 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
354
351
|
type WebSocketRegisterConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>> = {
|
|
355
352
|
token?: string | null;
|
|
356
353
|
} & InferInitContextType<TPlatform>;
|
|
357
|
-
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TEvents> {
|
|
354
|
+
declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = null, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
358
355
|
readonly id: string;
|
|
359
356
|
private _doc;
|
|
360
357
|
private _lastGarbageCollectMs;
|
|
361
358
|
private _uninitialize;
|
|
362
359
|
private readonly _authorize;
|
|
363
360
|
private readonly _context;
|
|
361
|
+
private readonly _crdt;
|
|
364
362
|
private readonly _debug;
|
|
365
363
|
private readonly _docFactory;
|
|
366
364
|
private readonly _listeners;
|
|
@@ -376,6 +374,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
376
374
|
get _defs(): {
|
|
377
375
|
authorize: TAuthorize;
|
|
378
376
|
context: TContext;
|
|
377
|
+
crdt: TCrdt;
|
|
379
378
|
events: TEvents;
|
|
380
379
|
platform: TPlatform;
|
|
381
380
|
};
|
|
@@ -433,27 +432,30 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
433
432
|
private _sendSyncMessage;
|
|
434
433
|
}
|
|
435
434
|
|
|
436
|
-
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;
|
|
437
|
-
type PluvServerConfig<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> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
435
|
+
type InferIORoom<TServer extends PluvServer<any, any, any, any, any>> = TServer extends PluvServer<infer IPlatform, infer IAuthorize, infer IContext, infer ICrdt, infer IEvents> ? IORoom<IPlatform, IAuthorize, IContext, ICrdt, IEvents> : never;
|
|
436
|
+
type PluvServerConfig<TPlatform extends AbstractPlatform<any, any> = AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
438
437
|
authorize?: TAuthorize;
|
|
439
438
|
context?: PluvContext<TPlatform, TContext>;
|
|
440
439
|
crdt?: {
|
|
441
440
|
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
442
441
|
};
|
|
443
442
|
debug?: boolean;
|
|
444
|
-
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
445
443
|
limits: PluvIOLimits;
|
|
446
444
|
io: PluvIO<TPlatform, TAuthorize, TContext>;
|
|
447
445
|
platform: () => TPlatform;
|
|
448
446
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
449
|
-
}
|
|
447
|
+
} & (TCrdt extends CrdtLibraryType$1<NoopCrdtDocFactory> ? {
|
|
448
|
+
getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage";
|
|
449
|
+
} : {
|
|
450
|
+
getInitialStorage: GetInitialStorageFn<TContext>;
|
|
451
|
+
});
|
|
450
452
|
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>> & {
|
|
451
453
|
debug?: boolean;
|
|
452
454
|
};
|
|
453
455
|
type CreateRoomOptions<TPlatform extends AbstractPlatform<any, any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> = keyof InferRoomContextType<TPlatform> extends never ? [BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>] | [] : [
|
|
454
456
|
Id<BaseCreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents> & InferRoomContextType<TPlatform>>
|
|
455
457
|
];
|
|
456
|
-
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> {
|
|
458
|
+
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> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> implements IOLike<TAuthorize, TCrdt, TEvents> {
|
|
457
459
|
readonly version: string;
|
|
458
460
|
private readonly _config;
|
|
459
461
|
get fetch(): (...args: any[]) => Promise<any>;
|
|
@@ -465,34 +467,37 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = Abstract
|
|
|
465
467
|
get _defs(): {
|
|
466
468
|
authorize: TAuthorize;
|
|
467
469
|
context: TContext;
|
|
470
|
+
crdt: TCrdt;
|
|
468
471
|
events: TEvents;
|
|
469
472
|
platform: TPlatform;
|
|
470
473
|
};
|
|
471
474
|
private get _baseRouter();
|
|
472
475
|
private get _procedure();
|
|
473
476
|
private get _router();
|
|
474
|
-
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
475
|
-
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TEvents>;
|
|
477
|
+
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>);
|
|
478
|
+
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
476
479
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
477
480
|
private _getListeners;
|
|
478
481
|
private _logDebug;
|
|
479
482
|
}
|
|
480
483
|
|
|
481
|
-
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>> = {
|
|
484
|
+
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null, TContext extends Record<string, any>, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>> = {
|
|
482
485
|
authorize?: TAuthorize;
|
|
483
486
|
context?: PluvContext<TPlatform, TContext>;
|
|
484
|
-
crdt?:
|
|
487
|
+
crdt?: TCrdt;
|
|
485
488
|
debug?: boolean;
|
|
486
489
|
limits?: PluvIOLimits;
|
|
487
490
|
platform: () => TPlatform;
|
|
488
491
|
};
|
|
489
|
-
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> & {
|
|
490
|
-
getInitialStorage?:
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
|
|
492
|
+
type ResolvedServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & PluvIORouter<TPlatform, TAuthorize, TContext, TEvents> & (TCrdt extends CrdtLibraryType$1<NoopCrdtDocFactory> ? {
|
|
493
|
+
getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage";
|
|
494
|
+
} : {
|
|
495
|
+
getInitialStorage: GetInitialStorageFn<TContext>;
|
|
496
|
+
});
|
|
497
|
+
type ServerConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}> = {
|
|
498
|
+
[P in keyof ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents> as ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P] extends undefined ? never : P]: ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P];
|
|
494
499
|
};
|
|
495
|
-
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}> {
|
|
500
|
+
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends PluvIOAuthorize<TPlatform, any, InferInitContextType<TPlatform>> | null = any, TContext extends Record<string, any> = {}, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<any>> {
|
|
496
501
|
readonly version: string;
|
|
497
502
|
private readonly _authorize;
|
|
498
503
|
private readonly _context;
|
|
@@ -501,22 +506,22 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
501
506
|
private readonly _limits;
|
|
502
507
|
private readonly _platform;
|
|
503
508
|
get procedure(): PluvProcedure<TPlatform, TAuthorize, TContext, {}, {}>;
|
|
504
|
-
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>);
|
|
509
|
+
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TCrdt>);
|
|
505
510
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<TAuthorize>, TPlatform>): Promise<string>;
|
|
506
511
|
mergeRouters<TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[]>(...routers: TRouters): MergedRouter<TRouters>;
|
|
507
512
|
router<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>>(events: TEvents): PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
508
|
-
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TEvents>;
|
|
513
|
+
server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}>(config?: ServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>): PluvServer<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
509
514
|
private _getIOAuthorize;
|
|
510
515
|
}
|
|
511
516
|
|
|
512
|
-
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null> = {
|
|
517
|
+
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>> = {
|
|
513
518
|
authorize?: PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>;
|
|
514
519
|
context?: PluvContext<TPlatform, TContext>;
|
|
515
|
-
crdt?:
|
|
520
|
+
crdt?: TCrdt;
|
|
516
521
|
debug?: boolean;
|
|
517
522
|
limits?: PluvIOLimits;
|
|
518
523
|
platform: () => TPlatform;
|
|
519
524
|
};
|
|
520
|
-
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>;
|
|
525
|
+
declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null, TCrdt extends CrdtLibraryType$1<any> = CrdtLibraryType$1<NoopCrdtDocFactory>>(params: CreateIOParams<TPlatform, TContext, TUser, TCrdt>) => PluvIO<TPlatform, PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>, TContext, TCrdt>;
|
|
521
526
|
|
|
522
|
-
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
|
|
527
|
+
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 CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type HandleMode, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type IOStorageUpdatedEvent, type IOUserConnectedEvent, type IOUserDisconnectedEvent, type InferIORoom, type InferInitContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, type PlatformConfig, type PluvContext, PluvIO, type PluvIOAuthorize, type PluvIOConfig, type PluvIOLimits, 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
|
@@ -450,6 +450,7 @@ var IORoom = class {
|
|
|
450
450
|
} = config;
|
|
451
451
|
this.id = id;
|
|
452
452
|
this._context = context;
|
|
453
|
+
this._crdt = crdt;
|
|
453
454
|
this._debug = debug;
|
|
454
455
|
this._docFactory = crdt.doc(() => ({}));
|
|
455
456
|
this._router = router;
|
|
@@ -486,6 +487,7 @@ var IORoom = class {
|
|
|
486
487
|
return {
|
|
487
488
|
authorize: this._authorize,
|
|
488
489
|
context: this._context,
|
|
490
|
+
crdt: this._crdt,
|
|
489
491
|
events: this._router._defs.events,
|
|
490
492
|
platform: this._platform
|
|
491
493
|
};
|
|
@@ -1168,7 +1170,7 @@ var IORoom = class {
|
|
|
1168
1170
|
};
|
|
1169
1171
|
|
|
1170
1172
|
// src/version.generated.ts
|
|
1171
|
-
var version = "
|
|
1173
|
+
var version = "3.1.0";
|
|
1172
1174
|
|
|
1173
1175
|
// src/PluvServer.ts
|
|
1174
1176
|
var PluvServer = class {
|
|
@@ -1213,6 +1215,7 @@ var PluvServer = class {
|
|
|
1213
1215
|
return {
|
|
1214
1216
|
authorize: this._config.authorize,
|
|
1215
1217
|
context: this._config.context,
|
|
1218
|
+
crdt: this._config.crdt,
|
|
1216
1219
|
events: this._router._defs.events,
|
|
1217
1220
|
platform: this._config.platform()
|
|
1218
1221
|
};
|
|
@@ -1255,14 +1258,11 @@ var PluvServer = class {
|
|
|
1255
1258
|
}
|
|
1256
1259
|
};
|
|
1257
1260
|
}).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, platform, room, session }) {
|
|
1258
|
-
var _a, _b;
|
|
1259
1261
|
const oldState = yield platform.persistence.getStorageState(room);
|
|
1260
1262
|
const update = data == null ? void 0 : data.update;
|
|
1261
1263
|
if (!oldState) {
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
room
|
|
1265
|
-
});
|
|
1264
|
+
const getInitialStorage = typeof this._config.getInitialStorage === "function" ? this._config.getInitialStorage : () => null;
|
|
1265
|
+
const loadedState = yield getInitialStorage({ context, room });
|
|
1266
1266
|
if (!!loadedState) {
|
|
1267
1267
|
doc.applyEncodedState({ update: loadedState }).getEncodedState();
|
|
1268
1268
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -408,6 +408,7 @@ var IORoom = class {
|
|
|
408
408
|
} = config;
|
|
409
409
|
this.id = id;
|
|
410
410
|
this._context = context;
|
|
411
|
+
this._crdt = crdt;
|
|
411
412
|
this._debug = debug;
|
|
412
413
|
this._docFactory = crdt.doc(() => ({}));
|
|
413
414
|
this._router = router;
|
|
@@ -444,6 +445,7 @@ var IORoom = class {
|
|
|
444
445
|
return {
|
|
445
446
|
authorize: this._authorize,
|
|
446
447
|
context: this._context,
|
|
448
|
+
crdt: this._crdt,
|
|
447
449
|
events: this._router._defs.events,
|
|
448
450
|
platform: this._platform
|
|
449
451
|
};
|
|
@@ -1126,7 +1128,7 @@ var IORoom = class {
|
|
|
1126
1128
|
};
|
|
1127
1129
|
|
|
1128
1130
|
// src/version.generated.ts
|
|
1129
|
-
var version = "
|
|
1131
|
+
var version = "3.1.0";
|
|
1130
1132
|
|
|
1131
1133
|
// src/PluvServer.ts
|
|
1132
1134
|
var PluvServer = class {
|
|
@@ -1171,6 +1173,7 @@ var PluvServer = class {
|
|
|
1171
1173
|
return {
|
|
1172
1174
|
authorize: this._config.authorize,
|
|
1173
1175
|
context: this._config.context,
|
|
1176
|
+
crdt: this._config.crdt,
|
|
1174
1177
|
events: this._router._defs.events,
|
|
1175
1178
|
platform: this._config.platform()
|
|
1176
1179
|
};
|
|
@@ -1213,14 +1216,11 @@ var PluvServer = class {
|
|
|
1213
1216
|
}
|
|
1214
1217
|
};
|
|
1215
1218
|
}).self((_0, _1) => __async(this, [_0, _1], function* (data, { context, doc, platform, room, session }) {
|
|
1216
|
-
var _a, _b;
|
|
1217
1219
|
const oldState = yield platform.persistence.getStorageState(room);
|
|
1218
1220
|
const update = data == null ? void 0 : data.update;
|
|
1219
1221
|
if (!oldState) {
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
room
|
|
1223
|
-
});
|
|
1222
|
+
const getInitialStorage = typeof this._config.getInitialStorage === "function" ? this._config.getInitialStorage : () => null;
|
|
1223
|
+
const loadedState = yield getInitialStorage({ context, room });
|
|
1224
1224
|
if (!!loadedState) {
|
|
1225
1225
|
doc.applyEncodedState({ update: loadedState }).getEncodedState();
|
|
1226
1226
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
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.10.0",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.5",
|
|
24
|
-
"@pluv/crdt": "^
|
|
25
|
-
"@pluv/types": "^
|
|
24
|
+
"@pluv/crdt": "^3.1.0",
|
|
25
|
+
"@pluv/types": "^3.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^9.27.0",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
30
|
"tsup": "^8.5.0",
|
|
31
31
|
"typescript": "^5.8.3",
|
|
32
|
-
"@pluv/tsconfig": "^
|
|
33
|
-
"eslint-config-pluv": "^
|
|
32
|
+
"@pluv/tsconfig": "^3.1.0",
|
|
33
|
+
"eslint-config-pluv": "^3.1.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/IORoom.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
BaseIOEventRecord,
|
|
5
5
|
BaseUser,
|
|
6
6
|
CrdtDocLike,
|
|
7
|
+
CrdtLibraryType,
|
|
7
8
|
EventMessage,
|
|
8
9
|
IOEventMessage,
|
|
9
10
|
IOLike,
|
|
@@ -46,11 +47,11 @@ import type {
|
|
|
46
47
|
} from "./types";
|
|
47
48
|
import { oneLine } from "./utils";
|
|
48
49
|
|
|
49
|
-
type BroadcastMessage<TIO extends IORoom<any, any, any, any>> =
|
|
50
|
+
type BroadcastMessage<TIO extends IORoom<any, any, any, any, any>> =
|
|
50
51
|
| InferEventMessage<InferIOInput<TIO>>
|
|
51
52
|
| InferEventMessage<BaseIOEventRecord<InferIOAuthorize<TIO>>>;
|
|
52
53
|
|
|
53
|
-
interface BroadcastParams<TIO extends IORoom<any, any, any, any>> {
|
|
54
|
+
interface BroadcastParams<TIO extends IORoom<any, any, any, any, any>> {
|
|
54
55
|
message: BroadcastMessage<TIO>;
|
|
55
56
|
senderId?: string;
|
|
56
57
|
}
|
|
@@ -67,7 +68,7 @@ export interface IORoomListeners<
|
|
|
67
68
|
onUserDisconnected: (event: IOUserDisconnectedEvent<TPlatform, TAuthorize, TContext>) => void;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
export type BroadcastProxy<TIO extends IORoom<any, any, any, any>> = (<
|
|
71
|
+
export type BroadcastProxy<TIO extends IORoom<any, any, any, any, any>> = (<
|
|
71
72
|
TEvent extends keyof InferIOInput<TIO>,
|
|
72
73
|
>(
|
|
73
74
|
event: TEvent,
|
|
@@ -120,8 +121,9 @@ export class IORoom<
|
|
|
120
121
|
InferInitContextType<TPlatform>
|
|
121
122
|
> | null = null,
|
|
122
123
|
TContext extends Record<string, any> = {},
|
|
124
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
123
125
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
124
|
-
> implements IOLike<TAuthorize, TEvents>
|
|
126
|
+
> implements IOLike<TAuthorize, TCrdt, TEvents>
|
|
125
127
|
{
|
|
126
128
|
public readonly id: string;
|
|
127
129
|
|
|
@@ -131,6 +133,7 @@ export class IORoom<
|
|
|
131
133
|
|
|
132
134
|
private readonly _authorize: TAuthorize = null as TAuthorize;
|
|
133
135
|
private readonly _context: TContext;
|
|
136
|
+
private readonly _crdt: TCrdt;
|
|
134
137
|
private readonly _debug: boolean;
|
|
135
138
|
private readonly _docFactory: AbstractCrdtDocFactory<any, any>;
|
|
136
139
|
private readonly _listeners: IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>;
|
|
@@ -151,11 +154,13 @@ export class IORoom<
|
|
|
151
154
|
return {
|
|
152
155
|
authorize: this._authorize,
|
|
153
156
|
context: this._context,
|
|
157
|
+
crdt: this._crdt,
|
|
154
158
|
events: this._router._defs.events,
|
|
155
159
|
platform: this._platform,
|
|
156
160
|
} as {
|
|
157
161
|
authorize: TAuthorize;
|
|
158
162
|
context: TContext;
|
|
163
|
+
crdt: TCrdt;
|
|
159
164
|
events: TEvents;
|
|
160
165
|
platform: TPlatform;
|
|
161
166
|
};
|
|
@@ -201,6 +206,7 @@ export class IORoom<
|
|
|
201
206
|
this.id = id;
|
|
202
207
|
|
|
203
208
|
this._context = context;
|
|
209
|
+
this._crdt = crdt as TCrdt;
|
|
204
210
|
this._debug = debug;
|
|
205
211
|
this._docFactory = crdt.doc(() => ({}));
|
|
206
212
|
this._router = router;
|
package/src/PluvIO.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
1
|
+
import type { AbstractCrdtDocFactory, CrdtLibraryType, NoopCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import { noop } from "@pluv/crdt";
|
|
3
3
|
import type { BaseUser, IOAuthorize, InferIOAuthorizeUser } from "@pluv/types";
|
|
4
4
|
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
MAX_USER_SIZE_BYTES,
|
|
17
17
|
} from "./constants";
|
|
18
18
|
import type {
|
|
19
|
-
CrdtLibraryType,
|
|
20
19
|
GetInitialStorageFn,
|
|
21
20
|
PluvContext,
|
|
22
21
|
PluvIOAuthorize,
|
|
@@ -31,10 +30,11 @@ export type PluvIOConfig<
|
|
|
31
30
|
TPlatform extends AbstractPlatform<any>,
|
|
32
31
|
TAuthorize extends IOAuthorize<any, InferInitContextType<TPlatform>> | null,
|
|
33
32
|
TContext extends Record<string, any>,
|
|
33
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
34
34
|
> = {
|
|
35
35
|
authorize?: TAuthorize;
|
|
36
36
|
context?: PluvContext<TPlatform, TContext>;
|
|
37
|
-
crdt?:
|
|
37
|
+
crdt?: TCrdt;
|
|
38
38
|
debug?: boolean;
|
|
39
39
|
limits?: PluvIOLimits;
|
|
40
40
|
platform: () => TPlatform;
|
|
@@ -48,11 +48,13 @@ type ResolvedServerConfig<
|
|
|
48
48
|
InferInitContextType<TPlatform>
|
|
49
49
|
> | null = any,
|
|
50
50
|
TContext extends Record<string, any> = {},
|
|
51
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>,
|
|
51
52
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
52
53
|
> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> &
|
|
53
|
-
PluvIORouter<TPlatform, TAuthorize, TContext, TEvents> &
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
PluvIORouter<TPlatform, TAuthorize, TContext, TEvents> &
|
|
55
|
+
(TCrdt extends CrdtLibraryType<NoopCrdtDocFactory>
|
|
56
|
+
? { getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage" }
|
|
57
|
+
: { getInitialStorage: GetInitialStorageFn<TContext> });
|
|
56
58
|
|
|
57
59
|
export type ServerConfig<
|
|
58
60
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
@@ -62,16 +64,18 @@ export type ServerConfig<
|
|
|
62
64
|
InferInitContextType<TPlatform>
|
|
63
65
|
> | null = any,
|
|
64
66
|
TContext extends Record<string, any> = {},
|
|
67
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>,
|
|
65
68
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
66
69
|
> = {
|
|
67
70
|
[P in keyof ResolvedServerConfig<
|
|
68
71
|
TPlatform,
|
|
69
72
|
TAuthorize,
|
|
70
73
|
TContext,
|
|
74
|
+
TCrdt,
|
|
71
75
|
TEvents
|
|
72
|
-
> as ResolvedServerConfig<TPlatform, TAuthorize, TContext, TEvents>[P] extends undefined
|
|
76
|
+
> as ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P] extends undefined
|
|
73
77
|
? never
|
|
74
|
-
: P]: ResolvedServerConfig<TPlatform, TAuthorize, TContext, TEvents>[P];
|
|
78
|
+
: P]: ResolvedServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>[P];
|
|
75
79
|
};
|
|
76
80
|
|
|
77
81
|
export class PluvIO<
|
|
@@ -82,6 +86,7 @@ export class PluvIO<
|
|
|
82
86
|
InferInitContextType<TPlatform>
|
|
83
87
|
> | null = any,
|
|
84
88
|
TContext extends Record<string, any> = {},
|
|
89
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
85
90
|
> {
|
|
86
91
|
public readonly version: string = __PLUV_VERSION as any;
|
|
87
92
|
|
|
@@ -99,10 +104,10 @@ export class PluvIO<
|
|
|
99
104
|
return new PluvProcedure();
|
|
100
105
|
}
|
|
101
106
|
|
|
102
|
-
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext>) {
|
|
107
|
+
constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TCrdt>) {
|
|
103
108
|
const { authorize, context, crdt = noop, debug = false, limits, platform } = options;
|
|
104
109
|
|
|
105
|
-
this._crdt = crdt
|
|
110
|
+
this._crdt = crdt as CrdtLibraryType<any>;
|
|
106
111
|
this._debug = debug;
|
|
107
112
|
this._limits = {
|
|
108
113
|
presenceMaxSize: MAX_PRESENCE_SIZE_BYTES,
|
|
@@ -182,14 +187,15 @@ export class PluvIO<
|
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
public server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}>(
|
|
185
|
-
config: ServerConfig<TPlatform, TAuthorize, TContext, TEvents> = {} as ServerConfig<
|
|
190
|
+
config: ServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents> = {} as ServerConfig<
|
|
186
191
|
TPlatform,
|
|
187
192
|
TAuthorize,
|
|
188
193
|
TContext,
|
|
194
|
+
TCrdt,
|
|
189
195
|
TEvents
|
|
190
196
|
>,
|
|
191
|
-
): PluvServer<TPlatform, TAuthorize, TContext, TEvents> {
|
|
192
|
-
return new PluvServer<TPlatform, TAuthorize, TContext, TEvents>({
|
|
197
|
+
): PluvServer<TPlatform, TAuthorize, TContext, TCrdt, TEvents> {
|
|
198
|
+
return new PluvServer<TPlatform, TAuthorize, TContext, TCrdt, TEvents>({
|
|
193
199
|
...config,
|
|
194
200
|
authorize: this._authorize ?? undefined,
|
|
195
201
|
context: this._context,
|
|
@@ -198,7 +204,7 @@ export class PluvIO<
|
|
|
198
204
|
io: this as PluvIO<TPlatform, TAuthorize, TContext>,
|
|
199
205
|
limits: this._limits,
|
|
200
206
|
platform: this._platform,
|
|
201
|
-
} as PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>);
|
|
207
|
+
} as PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>);
|
|
202
208
|
}
|
|
203
209
|
|
|
204
210
|
private _getIOAuthorize(
|
package/src/PluvServer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
1
|
+
import type { AbstractCrdtDocFactory, CrdtLibraryType, NoopCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import { noop } from "@pluv/crdt";
|
|
3
3
|
import type {
|
|
4
4
|
IOLike,
|
|
@@ -34,9 +34,15 @@ import type {
|
|
|
34
34
|
import { oneLine, pickBy } from "./utils";
|
|
35
35
|
import { __PLUV_VERSION } from "./version";
|
|
36
36
|
|
|
37
|
-
export type InferIORoom<TServer extends PluvServer<any, any, any, any>> =
|
|
38
|
-
TServer extends PluvServer<
|
|
39
|
-
|
|
37
|
+
export type InferIORoom<TServer extends PluvServer<any, any, any, any, any>> =
|
|
38
|
+
TServer extends PluvServer<
|
|
39
|
+
infer IPlatform,
|
|
40
|
+
infer IAuthorize,
|
|
41
|
+
infer IContext,
|
|
42
|
+
infer ICrdt,
|
|
43
|
+
infer IEvents
|
|
44
|
+
>
|
|
45
|
+
? IORoom<IPlatform, IAuthorize, IContext, ICrdt, IEvents>
|
|
40
46
|
: never;
|
|
41
47
|
|
|
42
48
|
export type PluvServerConfig<
|
|
@@ -47,18 +53,20 @@ export type PluvServerConfig<
|
|
|
47
53
|
InferInitContextType<TPlatform>
|
|
48
54
|
> | null = any,
|
|
49
55
|
TContext extends Record<string, any> = {},
|
|
56
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
50
57
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
51
58
|
> = Partial<PluvIOListeners<TPlatform, TAuthorize, TContext, TEvents>> & {
|
|
52
59
|
authorize?: TAuthorize;
|
|
53
60
|
context?: PluvContext<TPlatform, TContext>;
|
|
54
61
|
crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any, any> };
|
|
55
62
|
debug?: boolean;
|
|
56
|
-
getInitialStorage?: GetInitialStorageFn<TContext>;
|
|
57
63
|
limits: PluvIOLimits;
|
|
58
64
|
io: PluvIO<TPlatform, TAuthorize, TContext>;
|
|
59
65
|
platform: () => TPlatform;
|
|
60
66
|
router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
61
|
-
}
|
|
67
|
+
} & (TCrdt extends CrdtLibraryType<NoopCrdtDocFactory>
|
|
68
|
+
? { getInitialStorage?: "[ERROR]: Must specify crdt to use getInitialStorage" }
|
|
69
|
+
: { getInitialStorage: GetInitialStorageFn<TContext> });
|
|
62
70
|
|
|
63
71
|
type BaseCreateRoomOptions<
|
|
64
72
|
TPlatform extends AbstractPlatform<any, any>,
|
|
@@ -91,13 +99,14 @@ export class PluvServer<
|
|
|
91
99
|
InferInitContextType<TPlatform>
|
|
92
100
|
> | null = any,
|
|
93
101
|
TContext extends Record<string, any> = {},
|
|
102
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>,
|
|
94
103
|
TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
|
|
95
|
-
> implements IOLike<TAuthorize, TEvents>
|
|
104
|
+
> implements IOLike<TAuthorize, TCrdt, TEvents>
|
|
96
105
|
{
|
|
97
106
|
public readonly version: string = __PLUV_VERSION as any;
|
|
98
107
|
|
|
99
108
|
private readonly _config: NonNilProps<
|
|
100
|
-
PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>
|
|
109
|
+
PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>
|
|
101
110
|
>;
|
|
102
111
|
|
|
103
112
|
public get fetch(): (...args: any[]) => Promise<any> {
|
|
@@ -122,11 +131,13 @@ export class PluvServer<
|
|
|
122
131
|
return {
|
|
123
132
|
authorize: this._config.authorize,
|
|
124
133
|
context: this._config.context,
|
|
134
|
+
crdt: this._config.crdt,
|
|
125
135
|
events: this._router._defs.events,
|
|
126
136
|
platform: this._config.platform(),
|
|
127
137
|
} as {
|
|
128
138
|
authorize: TAuthorize;
|
|
129
139
|
context: TContext;
|
|
140
|
+
crdt: TCrdt;
|
|
130
141
|
events: TEvents;
|
|
131
142
|
platform: TPlatform;
|
|
132
143
|
};
|
|
@@ -198,10 +209,11 @@ export class PluvServer<
|
|
|
198
209
|
const update = (data as any)?.update as Maybe<string>;
|
|
199
210
|
|
|
200
211
|
if (!oldState) {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
212
|
+
const getInitialStorage: GetInitialStorageFn<TContext> =
|
|
213
|
+
typeof this._config.getInitialStorage === "function"
|
|
214
|
+
? this._config.getInitialStorage
|
|
215
|
+
: () => null;
|
|
216
|
+
const loadedState = await getInitialStorage({ context, room });
|
|
205
217
|
|
|
206
218
|
if (!!loadedState) {
|
|
207
219
|
doc.applyEncodedState({ update: loadedState }).getEncodedState();
|
|
@@ -359,13 +371,13 @@ export class PluvServer<
|
|
|
359
371
|
) as PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
|
|
360
372
|
}
|
|
361
373
|
|
|
362
|
-
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>) {
|
|
374
|
+
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>) {
|
|
363
375
|
this._config = {
|
|
364
376
|
crdt: noop,
|
|
365
377
|
debug: false,
|
|
366
378
|
router: new PluvRouter<TPlatform, TAuthorize, TContext, TEvents>({} as TEvents),
|
|
367
379
|
...options,
|
|
368
|
-
} as NonNilProps<PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>>;
|
|
380
|
+
} as NonNilProps<PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>>;
|
|
369
381
|
|
|
370
382
|
const {
|
|
371
383
|
onRoomDeleted,
|
|
@@ -387,7 +399,7 @@ export class PluvServer<
|
|
|
387
399
|
public createRoom(
|
|
388
400
|
room: string,
|
|
389
401
|
...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>
|
|
390
|
-
): IORoom<TPlatform, TAuthorize, TContext, TEvents> {
|
|
402
|
+
): IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents> {
|
|
391
403
|
const { _meta, debug, onDestroy, onMessage, ...platformRoomContext } = (options[0] ??
|
|
392
404
|
{}) as CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>[0] & { _meta?: any };
|
|
393
405
|
|
|
@@ -410,7 +422,7 @@ export class PluvServer<
|
|
|
410
422
|
const listeners = this._getListeners();
|
|
411
423
|
const logDebug = this._logDebug.bind(this);
|
|
412
424
|
|
|
413
|
-
const newRoom = new IORoom<TPlatform, TAuthorize, TContext, TEvents>(room, {
|
|
425
|
+
const newRoom = new IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents>(room, {
|
|
414
426
|
...(!!_meta ? { _meta } : {}),
|
|
415
427
|
authorize: this._config.authorize ?? undefined,
|
|
416
428
|
context,
|
package/src/createIO.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import type { CrdtLibraryType, NoopCrdtDocFactory } from "@pluv/crdt";
|
|
1
2
|
import type { BaseUser } from "@pluv/types";
|
|
2
3
|
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
4
|
+
import type { PluvIOConfig } from "./PluvIO";
|
|
3
5
|
import { PluvIO } from "./PluvIO";
|
|
4
|
-
import type {
|
|
6
|
+
import type { PluvContext, PluvIOAuthorize, PluvIOLimits } from "./types";
|
|
5
7
|
|
|
6
8
|
export type CreateIOParams<
|
|
7
9
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
8
10
|
TContext extends Record<string, any> = {},
|
|
9
11
|
TUser extends BaseUser | null = null,
|
|
12
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>,
|
|
10
13
|
> = {
|
|
11
14
|
authorize?: PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>;
|
|
12
15
|
context?: PluvContext<TPlatform, TContext>;
|
|
13
|
-
crdt?:
|
|
16
|
+
crdt?: TCrdt;
|
|
14
17
|
debug?: boolean;
|
|
15
18
|
limits?: PluvIOLimits;
|
|
16
19
|
platform: () => TPlatform;
|
|
@@ -20,19 +23,22 @@ export const createIO = <
|
|
|
20
23
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
21
24
|
TContext extends Record<string, any> = {},
|
|
22
25
|
TUser extends BaseUser | null = null,
|
|
26
|
+
TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>,
|
|
23
27
|
>(
|
|
24
|
-
params: CreateIOParams<TPlatform, TContext, TUser>,
|
|
28
|
+
params: CreateIOParams<TPlatform, TContext, TUser, TCrdt>,
|
|
25
29
|
): PluvIO<
|
|
26
30
|
TPlatform,
|
|
27
31
|
PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>,
|
|
28
|
-
TContext
|
|
32
|
+
TContext,
|
|
33
|
+
TCrdt
|
|
29
34
|
> => {
|
|
30
35
|
const { authorize, context, crdt, debug, limits, platform } = params;
|
|
31
36
|
|
|
32
37
|
return new PluvIO<
|
|
33
38
|
TPlatform,
|
|
34
39
|
PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>,
|
|
35
|
-
TContext
|
|
40
|
+
TContext,
|
|
41
|
+
TCrdt
|
|
36
42
|
>({
|
|
37
43
|
authorize,
|
|
38
44
|
context,
|
|
@@ -40,5 +46,10 @@ export const createIO = <
|
|
|
40
46
|
debug,
|
|
41
47
|
limits,
|
|
42
48
|
platform,
|
|
43
|
-
}
|
|
49
|
+
} as PluvIOConfig<
|
|
50
|
+
TPlatform,
|
|
51
|
+
PluvIOAuthorize<TPlatform, TUser, InferInitContextType<TPlatform>>,
|
|
52
|
+
TContext,
|
|
53
|
+
TCrdt
|
|
54
|
+
>);
|
|
44
55
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { CrdtLibraryType } from "@pluv/crdt";
|
|
1
2
|
export type { BaseUser, EventMessage, EventRecord, IOEventMessage } from "@pluv/types";
|
|
2
3
|
export { AbstractPersistence } from "./AbstractPersistence";
|
|
3
4
|
export { AbstractPlatform } from "./AbstractPlatform";
|
|
@@ -35,7 +36,6 @@ export type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
|
35
36
|
export { PluvServer } from "./PluvServer";
|
|
36
37
|
export type { CreateRoomOptions, InferIORoom, PluvServerConfig } from "./PluvServer";
|
|
37
38
|
export type {
|
|
38
|
-
CrdtLibraryType,
|
|
39
39
|
GetInitialStorageFn,
|
|
40
40
|
HandleMode,
|
|
41
41
|
IORoomListenerEvent,
|
package/src/types.ts
CHANGED
|
@@ -28,11 +28,6 @@ export type PluvContext<TPlatform extends AbstractPlatform, TContext extends Rec
|
|
|
28
28
|
| TContext
|
|
29
29
|
| ((params: InferRoomContextType<TPlatform>) => TContext);
|
|
30
30
|
|
|
31
|
-
export interface CrdtLibraryType {
|
|
32
|
-
doc: (value: any) => AbstractCrdtDocFactory<any, any>;
|
|
33
|
-
kind: "loro" | "yjs";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
31
|
export type EventResolverKind = "broadcast" | "self" | "sync";
|
|
37
32
|
|
|
38
33
|
export type EventResolver<
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '3.1.0'
|