@pluv/io 0.17.2 → 0.18.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.
@@ -0,0 +1,203 @@
1
+ import type { EventRecord, IOAuthorize, InputZodLike, JsonObject } from "@pluv/types";
2
+ import type { AbstractPlatform, InferPlatformEventContextType, InferPlatformRoomContextType } from "./AbstractPlatform";
3
+ import type { EventResolver, MergeEventRecords } from "./types";
4
+
5
+ export interface PluvProcedureConfig<
6
+ TPlatform extends AbstractPlatform<any>,
7
+ TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>,
8
+ TContext extends JsonObject,
9
+ TInput extends JsonObject = {},
10
+ TOutput extends EventRecord<string, any> = {},
11
+ > {
12
+ broadcast?: EventResolver<
13
+ TPlatform,
14
+ TAuthorize,
15
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
16
+ TInput,
17
+ Partial<TOutput>
18
+ > | null;
19
+ input?: InputZodLike<TInput>;
20
+ self?: EventResolver<
21
+ TPlatform,
22
+ TAuthorize,
23
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
24
+ TInput,
25
+ Partial<TOutput>
26
+ > | null;
27
+ sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
28
+ }
29
+
30
+ export class PluvProcedure<
31
+ TPlatform extends AbstractPlatform<any>,
32
+ TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>>,
33
+ TContext extends JsonObject,
34
+ TInput extends JsonObject = {},
35
+ TOutput extends EventRecord<string, any> = {},
36
+ TFilled extends "input" | "broadcast" | "self" | "sync" | "" = "",
37
+ > {
38
+ private _broadcast: EventResolver<
39
+ TPlatform,
40
+ TAuthorize,
41
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
42
+ TInput,
43
+ Partial<TOutput>
44
+ > | null = null;
45
+ private _input: InputZodLike<TInput> | null = null;
46
+ private _self: EventResolver<
47
+ TPlatform,
48
+ TAuthorize,
49
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
50
+ TInput,
51
+ Partial<TOutput>
52
+ > | null = null;
53
+ private _sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
54
+
55
+ public get config() {
56
+ return {
57
+ broadcast: this._broadcast?.bind(this) ?? null,
58
+ input: this._input ?? null,
59
+ resolver: this._resolver,
60
+ self: this._self?.bind(this) ?? null,
61
+ sync: this._sync?.bind(this) ?? null,
62
+ };
63
+ }
64
+
65
+ constructor(config: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput> = {}) {
66
+ const { broadcast, input, self, sync } = config;
67
+
68
+ this._broadcast = broadcast ?? null;
69
+ this._input = input ?? null;
70
+ this._self = self ?? null;
71
+ this._sync = sync ?? null;
72
+ }
73
+
74
+ public broadcast<TResult extends EventRecord<string, any> = {}>(
75
+ resolver: EventResolver<
76
+ TPlatform,
77
+ TAuthorize,
78
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
79
+ TInput,
80
+ TResult
81
+ >,
82
+ ): Omit<
83
+ PluvProcedure<
84
+ TPlatform,
85
+ TAuthorize,
86
+ TContext,
87
+ TInput,
88
+ MergeEventRecords<[TOutput, TResult]>,
89
+ TFilled | "input" | "broadcast"
90
+ >,
91
+ TFilled | "input" | "broadcast"
92
+ > {
93
+ const { broadcast } = this.config;
94
+
95
+ if (!!broadcast) throw new Error("Broadcast was already defined for this procedure");
96
+
97
+ return new PluvProcedure<
98
+ TPlatform,
99
+ TAuthorize,
100
+ TContext,
101
+ TInput,
102
+ MergeEventRecords<[TOutput, TResult]>,
103
+ TFilled | "input" | "broadcast"
104
+ >({
105
+ ...(this.config as any),
106
+ broadcast: resolver as any,
107
+ });
108
+ }
109
+
110
+ public input<TData extends JsonObject>(
111
+ input: InputZodLike<TData>,
112
+ ): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input"> {
113
+ return new PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">({ input });
114
+ }
115
+
116
+ public self<TResult extends EventRecord<string, any> = {}>(
117
+ resolver: EventResolver<
118
+ TPlatform,
119
+ TAuthorize,
120
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
121
+ TInput,
122
+ TResult
123
+ >,
124
+ ): Omit<
125
+ PluvProcedure<
126
+ TPlatform,
127
+ TAuthorize,
128
+ TContext,
129
+ TInput,
130
+ MergeEventRecords<[TOutput, TResult]>,
131
+ TFilled | "input" | "self"
132
+ >,
133
+ TFilled | "input" | "self"
134
+ > {
135
+ const { self } = this.config;
136
+
137
+ if (!!self) throw new Error("Self was already defined for this procedure");
138
+
139
+ return new PluvProcedure<
140
+ TPlatform,
141
+ TAuthorize,
142
+ TContext,
143
+ TInput,
144
+ MergeEventRecords<[TOutput, TResult]>,
145
+ TFilled | "input" | "self"
146
+ >({
147
+ ...(this.config as any),
148
+ self: resolver as any,
149
+ });
150
+ }
151
+
152
+ public sync<TResult extends EventRecord<string, any> = {}>(
153
+ resolver: EventResolver<
154
+ TPlatform,
155
+ TAuthorize,
156
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
157
+ TInput,
158
+ TResult
159
+ >,
160
+ ): Omit<
161
+ PluvProcedure<
162
+ TPlatform,
163
+ TAuthorize,
164
+ TContext,
165
+ TInput,
166
+ MergeEventRecords<[TOutput, TResult]>,
167
+ TFilled | "input" | "sync"
168
+ >,
169
+ TFilled | "input" | "sync"
170
+ > {
171
+ const { sync } = this.config;
172
+
173
+ if (!!sync) throw new Error("Sync was already defined for this procedure");
174
+
175
+ return new PluvProcedure<
176
+ TPlatform,
177
+ TAuthorize,
178
+ TContext,
179
+ TInput,
180
+ MergeEventRecords<[TOutput, TResult]>,
181
+ TFilled | "input" | "sync"
182
+ >({
183
+ ...(this.config as any),
184
+ sync: resolver as any,
185
+ });
186
+ }
187
+
188
+ private _resolver(): EventResolver<
189
+ TPlatform,
190
+ TAuthorize,
191
+ TContext & InferPlatformRoomContextType<TPlatform> & InferPlatformEventContextType<TPlatform>,
192
+ TInput,
193
+ TOutput
194
+ > {
195
+ return (data, context) => {
196
+ return {
197
+ ...this._broadcast?.(data, context),
198
+ ...this._self?.(data, context),
199
+ ...this._sync?.(data, context),
200
+ } as TOutput;
201
+ };
202
+ }
203
+ }
@@ -0,0 +1,46 @@
1
+ import type { BaseIOAuthorize, IOAuthorize, IORouterLike, JsonObject } from "@pluv/types";
2
+ import type { AbstractPlatform, InferPlatformRoomContextType } from "./AbstractPlatform";
3
+ import type { PluvProcedure } from "./PluvProcedure";
4
+
5
+ export type PluvRouterEventConfig<
6
+ TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
7
+ TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize,
8
+ TContext extends JsonObject = {},
9
+ > = {
10
+ [P: string]: Pick<PluvProcedure<TPlatform, TAuthorize, TContext, any, any>, "config">;
11
+ };
12
+
13
+ export type MergedRouter<
14
+ TRouters extends PluvRouter<TPlatform, TAuthorize, TContext, any>[] = [],
15
+ TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
16
+ TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize,
17
+ TContext extends JsonObject = {},
18
+ TRoot extends TRouters[0]["_events"] = {},
19
+ > = TRouters extends [
20
+ infer IHead extends PluvRouter<TPlatform, TAuthorize, TContext, any>,
21
+ ...infer ITail extends PluvRouter<TPlatform, TAuthorize, TContext, any>[],
22
+ ]
23
+ ? MergedRouter<ITail, TPlatform, TAuthorize, TContext, TRoot & IHead["_events"]>
24
+ : PluvRouter<TPlatform, TAuthorize, TContext, TRoot>;
25
+
26
+ export class PluvRouter<
27
+ TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
28
+ TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize,
29
+ TContext extends JsonObject = {},
30
+ TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
31
+ > implements IORouterLike<TEvents>
32
+ {
33
+ readonly _events: TEvents = {} as TEvents;
34
+
35
+ constructor(events: TEvents) {
36
+ this._events = events;
37
+ }
38
+
39
+ public static merge<TRouters extends PluvRouter<any, any, any, any>[]>(
40
+ ...routers: TRouters
41
+ ): MergedRouter<TRouters> {
42
+ const events = Object.assign(Object.create(null), ...routers.map((router) => router._events));
43
+
44
+ return new PluvRouter<any, any, any, any>(events) as MergedRouter<TRouters>;
45
+ }
46
+ }
@@ -0,0 +1,182 @@
1
+ import type { AbstractCrdtDocFactory } from "@pluv/crdt";
2
+ import { noop } from "@pluv/crdt";
3
+ import type {
4
+ BaseIOAuthorize,
5
+ IOAuthorize,
6
+ IORouterLike,
7
+ InferIOAuthorize,
8
+ InferIOAuthorizeUser,
9
+ JsonObject,
10
+ } from "@pluv/types";
11
+ import colors from "kleur";
12
+ import type { AbstractPlatform, InferPlatformRoomContextType } from "./AbstractPlatform";
13
+ import { IORoom } from "./IORoom";
14
+ import type { PluvRouterEventConfig } from "./PluvRouter";
15
+ import { PluvRouter } from "./PluvRouter";
16
+ import type { JWTEncodeParams } from "./authorize";
17
+ import { authorize } from "./authorize";
18
+ import type { IORoomListenerEvent, PluvIOListeners } from "./types";
19
+ import { __PLUV_VERSION } from "./version";
20
+
21
+ export type InferIORoom<TServer extends PluvServer<any, any, any, any>> =
22
+ TServer extends PluvServer<infer IPlatform, infer IAuthorize, infer IContext, infer IEvents>
23
+ ? IORoom<IPlatform, IAuthorize, IContext, IEvents>
24
+ : never;
25
+
26
+ export type PluvServerConfig<
27
+ TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
28
+ TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize,
29
+ TContext extends JsonObject = {},
30
+ TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
31
+ > = Partial<PluvIOListeners<TPlatform>> & {
32
+ authorize?: TAuthorize;
33
+ context?: TContext;
34
+ crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
35
+ debug?: boolean;
36
+ platform: TPlatform;
37
+ router?: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
38
+ };
39
+
40
+ export type GetRoomOptions<TPlatform extends AbstractPlatform> = {
41
+ debug?: boolean;
42
+ } & InferPlatformRoomContextType<TPlatform>;
43
+
44
+ export class PluvServer<
45
+ TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
46
+ TAuthorize extends IOAuthorize<any, any, InferPlatformRoomContextType<TPlatform>> = BaseIOAuthorize,
47
+ TContext extends JsonObject = {},
48
+ TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {},
49
+ > implements IORouterLike<TEvents>
50
+ {
51
+ private _rooms = new Map<string, IORoom<TPlatform, TAuthorize, TContext, TEvents>>();
52
+
53
+ readonly _authorize: TAuthorize | null = null;
54
+ readonly _context: TContext = {} as TContext;
55
+ readonly _crdt: { doc: (value: any) => AbstractCrdtDocFactory<any> };
56
+ readonly _debug: boolean;
57
+ readonly _listeners: PluvIOListeners<TPlatform>;
58
+ readonly _platform: TPlatform;
59
+ readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
60
+ readonly _version: string = __PLUV_VERSION as any;
61
+
62
+ public get _events() {
63
+ return this._router._events;
64
+ }
65
+
66
+ constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TEvents>) {
67
+ const {
68
+ authorize,
69
+ context,
70
+ crdt = noop,
71
+ debug = false,
72
+ onRoomDeleted,
73
+ onStorageUpdated,
74
+ platform,
75
+ router = new PluvRouter<TPlatform, TAuthorize, TContext, TEvents>({} as TEvents),
76
+ } = options;
77
+
78
+ this._crdt = crdt;
79
+ this._debug = debug;
80
+ this._platform = platform;
81
+ this._router = router ?? null;
82
+
83
+ if (authorize) this._authorize = authorize;
84
+ if (context) this._context = context;
85
+
86
+ this._listeners = {
87
+ onRoomDeleted: (event) => onRoomDeleted?.(event),
88
+ onStorageUpdated: (event) => onStorageUpdated?.(event),
89
+ };
90
+ }
91
+
92
+ public async createToken(
93
+ params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>,
94
+ ): Promise<string> {
95
+ if (!this._authorize) {
96
+ throw new Error("IO does not specify authorize during initialization.");
97
+ }
98
+
99
+ const ioAuthorize =
100
+ typeof this._authorize === "function" ? this._authorize(params) : (this._authorize as { secret: string });
101
+
102
+ const secret = ioAuthorize.secret;
103
+
104
+ return await authorize({
105
+ platform: this._platform,
106
+ secret,
107
+ }).encode(params);
108
+ }
109
+
110
+ public getRoom(room: string, options: GetRoomOptions<TPlatform>): IORoom<TPlatform, TAuthorize, TContext, TEvents> {
111
+ const { debug, ...platformRoomContext } = options;
112
+
113
+ this._purgeEmptyRooms();
114
+
115
+ if (!/^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$/i.test(room)) {
116
+ throw new Error("Unsupported room name");
117
+ }
118
+
119
+ const platform = this._platform;
120
+ const oldRoom = this._rooms.get(room);
121
+
122
+ if (oldRoom) return oldRoom;
123
+
124
+ const roomContext = {
125
+ ...this._context,
126
+ ...platformRoomContext,
127
+ } as TContext & InferPlatformRoomContextType<TPlatform>;
128
+
129
+ const newRoom = new IORoom<TPlatform, TAuthorize, TContext, TEvents>(room, {
130
+ authorize: this._authorize ?? undefined,
131
+ context: roomContext,
132
+ crdt: this._crdt,
133
+ debug: debug ?? this._debug,
134
+ onDestroy: ({ encodedState, room }) => {
135
+ this._logDebug(`${colors.blue("Deleting empty room:")} ${room}`);
136
+
137
+ const roomContext = {
138
+ room,
139
+ encodedState,
140
+ ...platformRoomContext,
141
+ } as IORoomListenerEvent<TPlatform> & InferPlatformRoomContextType<TPlatform>;
142
+
143
+ this._rooms.delete(room);
144
+ this._listeners.onRoomDeleted(roomContext);
145
+
146
+ if (this._debug) {
147
+ const rooms = Array.from(this._rooms.keys());
148
+
149
+ this._logDebug(`${colors.blue("Deleted room:")} ${room}`);
150
+ this._logDebug(`${colors.blue("Rooms available:")} ${rooms.join(", ")}`);
151
+ }
152
+ },
153
+ platform,
154
+ router: this._router,
155
+ });
156
+
157
+ this._rooms.set(room, newRoom);
158
+
159
+ if (this._debug) {
160
+ const rooms = Array.from(this._rooms.keys());
161
+
162
+ this._logDebug(`${colors.blue("Created room:")} ${room}`);
163
+ this._logDebug(`${colors.blue("Rooms available:")} ${rooms.join(", ")}`);
164
+ }
165
+
166
+ return newRoom;
167
+ }
168
+
169
+ private _logDebug(...data: any[]): void {
170
+ this._debug && console.log(...data);
171
+ }
172
+
173
+ private _purgeEmptyRooms(): void {
174
+ const rooms = Array.from(this._rooms.entries());
175
+
176
+ rooms.forEach(([id, room]) => {
177
+ if (room.getSize()) return;
178
+
179
+ this._rooms.delete(id);
180
+ });
181
+ }
182
+ }
package/src/PubSub.ts CHANGED
@@ -10,15 +10,9 @@ export class PubSub extends AbstractPubSub {
10
10
  // Map of roomName to subscription ids
11
11
  private _subscriptionsRefs = new Map<string, readonly number[]>();
12
12
  // Map of
13
- private _unsubscriptions = new Map<
14
- number,
15
- [roomName: string, unsubscribe: () => void]
16
- >();
17
-
18
- public async publish(
19
- roomName: string,
20
- payload: IOPubSubEventMessage<any>,
21
- ): Promise<void> {
13
+ private _unsubscriptions = new Map<number, [roomName: string, unsubscribe: () => void]>();
14
+
15
+ public async publish(roomName: string, payload: IOPubSubEventMessage<any>): Promise<void> {
22
16
  const subject = this._subjects.get(roomName);
23
17
 
24
18
  if (!subject) return;
@@ -26,10 +20,7 @@ export class PubSub extends AbstractPubSub {
26
20
  Promise.resolve(subject.next(payload));
27
21
  }
28
22
 
29
- public subscribe(
30
- roomName: string,
31
- onMessage: (message: IOPubSubEventMessage<any>) => void,
32
- ): Promise<number> {
23
+ public subscribe(roomName: string, onMessage: (message: IOPubSubEventMessage<any>) => void): Promise<number> {
33
24
  const id = this._currentSubscriptionId++;
34
25
  const refs = this._subscriptionsRefs.get(roomName) ?? [];
35
26
 
@@ -46,8 +37,7 @@ export class PubSub extends AbstractPubSub {
46
37
  }
47
38
 
48
39
  public unsubscribe(subscriptionId: number): void {
49
- const [roomName, unsubscribe] =
50
- this._unsubscriptions.get(subscriptionId) ?? [];
40
+ const [roomName, unsubscribe] = this._unsubscriptions.get(subscriptionId) ?? [];
51
41
 
52
42
  if (!roomName || !unsubscribe) return;
53
43
 
@@ -67,9 +57,7 @@ export class PubSub extends AbstractPubSub {
67
57
 
68
58
  this._subscriptionsRefs.set(
69
59
  roomName,
70
- index === -1
71
- ? refs
72
- : [...refs.slice(0, index), ...refs.slice(index + 1)],
60
+ index === -1 ? refs : [...refs.slice(0, index), ...refs.slice(index + 1)],
73
61
  );
74
62
 
75
63
  unsubscribe();
package/src/authorize.ts CHANGED
@@ -1,21 +1,12 @@
1
1
  import hkdf from "@panva/hkdf";
2
2
  import type { BaseUser } from "@pluv/types";
3
3
  import { EncryptJWT, jwtDecrypt } from "jose";
4
- import type {
5
- AbstractPlatform,
6
- InferPlatformRoomContextType,
7
- } from "./AbstractPlatform";
4
+ import type { AbstractPlatform, InferPlatformRoomContextType } from "./AbstractPlatform";
8
5
 
9
6
  const DEFAULT_MAX_AGE_MS = 60_000;
10
7
 
11
8
  export const getEncryptionKey = async (secret: string): Promise<Uint8Array> => {
12
- return await hkdf(
13
- "sha256",
14
- secret,
15
- "",
16
- "Pluv.io Generated Encryption Key",
17
- 32,
18
- );
9
+ return await hkdf("sha256", secret, "", "Pluv.io Generated Encryption Key", 32);
19
10
  };
20
11
 
21
12
  export interface JWT<TUser extends BaseUser> {
@@ -24,10 +15,7 @@ export interface JWT<TUser extends BaseUser> {
24
15
  user: TUser;
25
16
  }
26
17
 
27
- export type JWTEncodeParams<
28
- TUser extends BaseUser,
29
- TPlatform extends AbstractPlatform,
30
- > = {
18
+ export type JWTEncodeParams<TUser extends BaseUser, TPlatform extends AbstractPlatform> = {
31
19
  maxAge?: number;
32
20
  room: string;
33
21
  user: TUser;
@@ -50,10 +38,7 @@ const now = () => (Date.now() / 1_000) | 0;
50
38
  export const authorize = (params: AuthorizeParams) => {
51
39
  const { platform, secret } = params;
52
40
 
53
- const encode = async <
54
- TUser extends BaseUser,
55
- TPlatform extends AbstractPlatform,
56
- >(
41
+ const encode = async <TUser extends BaseUser, TPlatform extends AbstractPlatform>(
57
42
  encodeParams: JWTEncodeParams<TUser, TPlatform>,
58
43
  ): Promise<string> => {
59
44
  const { maxAge = DEFAULT_MAX_AGE_MS, room, user } = encodeParams;
@@ -74,9 +59,7 @@ export const authorize = (params: AuthorizeParams) => {
74
59
  return token.toString();
75
60
  };
76
61
 
77
- const decode = async <TUser extends BaseUser>(
78
- jwt: string,
79
- ): Promise<JWT<TUser> | null> => {
62
+ const decode = async <TUser extends BaseUser>(jwt: string): Promise<JWT<TUser> | null> => {
80
63
  const encryptionSecret = await getEncryptionKey(secret);
81
64
 
82
65
  const { payload } = await jwtDecrypt(jwt, encryptionSecret, {
package/src/createIO.ts CHANGED
@@ -1,17 +1,8 @@
1
1
  import type { AbstractCrdtDocFactory } from "@pluv/crdt";
2
- import type {
3
- BaseClientEventRecord,
4
- BaseIOEventRecord,
5
- BaseUser,
6
- IOAuthorize,
7
- JsonObject,
8
- } from "@pluv/types";
9
- import type {
10
- AbstractPlatform,
11
- InferPlatformRoomContextType,
12
- } from "./AbstractPlatform";
13
- import type { GetInitialStorageFn, PluvIOListeners } from "./PluvIO";
2
+ import type { BaseUser, IOAuthorize, JsonObject } from "@pluv/types";
3
+ import type { AbstractPlatform, InferPlatformRoomContextType } from "./AbstractPlatform";
14
4
  import { PluvIO } from "./PluvIO";
5
+ import type { GetInitialStorageFn, PluvIOListeners } from "./types";
15
6
 
16
7
  export type CreateIOParams<
17
8
  TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
@@ -19,11 +10,7 @@ export type CreateIOParams<
19
10
  TAuthorizeUser extends BaseUser = BaseUser,
20
11
  TAuthorizeRequired extends boolean = false,
21
12
  > = Partial<PluvIOListeners<TPlatform>> & {
22
- authorize?: IOAuthorize<
23
- TAuthorizeUser,
24
- TAuthorizeRequired,
25
- InferPlatformRoomContextType<TPlatform>
26
- >;
13
+ authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformRoomContextType<TPlatform>>;
27
14
  context?: TContext;
28
15
  crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any> };
29
16
  debug?: boolean;
@@ -37,44 +24,18 @@ export const createIO = <
37
24
  TAuthorizeUser extends BaseUser = BaseUser,
38
25
  TAuthorizeRequired extends boolean = false,
39
26
  >(
40
- params: CreateIOParams<
41
- TPlatform,
42
- TContext,
43
- TAuthorizeUser,
44
- TAuthorizeRequired
45
- >,
27
+ params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>,
46
28
  ): PluvIO<
47
29
  TPlatform,
48
- IOAuthorize<
49
- TAuthorizeUser,
50
- TAuthorizeRequired,
51
- InferPlatformRoomContextType<TPlatform>
52
- >,
53
- TContext,
54
- BaseClientEventRecord,
55
- BaseIOEventRecord<IOAuthorize<TAuthorizeUser, TAuthorizeRequired>>
30
+ IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformRoomContextType<TPlatform>>,
31
+ TContext
56
32
  > => {
57
- const {
58
- authorize,
59
- context,
60
- crdt,
61
- debug,
62
- getInitialStorage,
63
- onRoomDeleted,
64
- onStorageUpdated,
65
- platform,
66
- } = params;
33
+ const { authorize, context, crdt, debug, getInitialStorage, onRoomDeleted, onStorageUpdated, platform } = params;
67
34
 
68
35
  return new PluvIO<
69
36
  TPlatform,
70
- IOAuthorize<
71
- TAuthorizeUser,
72
- TAuthorizeRequired,
73
- InferPlatformRoomContextType<TPlatform>
74
- >,
75
- TContext,
76
- BaseClientEventRecord,
77
- BaseIOEventRecord<IOAuthorize<TAuthorizeUser, TAuthorizeRequired>>
37
+ IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformRoomContextType<TPlatform>>,
38
+ TContext
78
39
  >({
79
40
  authorize,
80
41
  context,
package/src/index.ts CHANGED
@@ -1,9 +1,4 @@
1
- export type {
2
- BaseUser,
3
- EventMessage,
4
- EventRecord,
5
- IOEventMessage,
6
- } from "@pluv/types";
1
+ export type { BaseUser, EventMessage, EventRecord, IOEventMessage } from "@pluv/types";
7
2
  export { AbstractPersistance } from "./AbstractPersistance";
8
3
  export { AbstractPlatform } from "./AbstractPlatform";
9
4
  export type {
@@ -28,12 +23,13 @@ export type {
28
23
  } from "./AbstractWebSocket";
29
24
  export type { IORoom } from "./IORoom";
30
25
  export { PluvIO } from "./PluvIO";
31
- export type { GetRoomOptions, InferIORoom, PluvIOConfig } from "./PluvIO";
32
- export type {
33
- AuthorizeModule,
34
- AuthorizeParams,
35
- JWT,
36
- JWTEncodeParams,
37
- } from "./authorize";
26
+ export type { PluvIOConfig, ServerConfig } from "./PluvIO";
27
+ export { PluvProcedure } from "./PluvProcedure";
28
+ export type { PluvProcedureConfig } from "./PluvProcedure";
29
+ export { PluvRouter } from "./PluvRouter";
30
+ export type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
31
+ export { PluvServer } from "./PluvServer";
32
+ export type { GetRoomOptions, InferIORoom, PluvServerConfig } from "./PluvServer";
33
+ export type { AuthorizeModule, AuthorizeParams, JWT, JWTEncodeParams } from "./authorize";
38
34
  export { createIO } from "./createIO";
39
35
  export type { CreateIOParams } from "./createIO";